Skip to content

Commit 086aa55

Browse files
authored
Merge branch 'main' into crc_pattern_matcher
2 parents fe84df1 + 64f7822 commit 086aa55

File tree

4,784 files changed

+396871
-84857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,784 files changed

+396871
-84857
lines changed

.github/workflows/release-tasks.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,36 @@ jobs:
7575
git config user.name "llvmbot"
7676
git commit -a -m "Add ${{ steps.validate-tag.outputs.release-version }} documentation"
7777
git push https://${{ secrets.WWW_RELEASES_TOKEN }}@github.com/${{ github.repository_owner }}/www-releases main:main
78+
79+
release-lit:
80+
runs-on: ubuntu-latest
81+
if: github.repository == 'llvm/llvm-project'
82+
steps:
83+
- name: Checkout LLVM
84+
uses: actions/checkout@v3
85+
86+
- name: Install dependencies
87+
run: apt-get install -y python3-setuptools
88+
89+
- name: Test lit
90+
run: |
91+
cd llvm/utils/lit
92+
python3 lit.py tests
93+
94+
- name: Package lit
95+
run: |
96+
cd llvm/utils/lit
97+
# Remove 'dev' suffix from lit version.
98+
sed -i "s/ + 'dev'//g" lit/__init__.py
99+
python3 setup.py sdist
100+
101+
- name: Upload lit to test.pypi.org
102+
uses: pypa/gh-action-pypi-publish@release/v1
103+
with:
104+
password: ${{ secrets.LLVM_LIT_TEST_PYPI_API_TOKEN }}
105+
repository-url: https://test.pypi.org/legacy/
106+
107+
- name: Upload lit to pypi.org
108+
uses: pypa/gh-action-pypi-publish@release/v1
109+
with:
110+
password: ${{ secrets.LLVM_LIT_PYPI_API_TOKEN }}

bolt/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ set(BOLT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
44
set(BOLT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
55
set(CMAKE_CXX_STANDARD 17)
66

7+
# Add path for custom modules.
8+
list(INSERT CMAKE_MODULE_PATH 0 "${BOLT_SOURCE_DIR}/cmake/modules")
9+
710
# Determine default set of targets to build -- the intersection of
811
# those BOLT supports and those LLVM is targeting.
912
set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86")
@@ -111,6 +114,15 @@ endif()
111114

112115
find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")
113116

117+
include(AddBOLT)
118+
119+
option(BOLT_BUILD_TOOLS
120+
"Build the BOLT tools. If OFF, just generate build targets." ON)
121+
122+
add_custom_target(bolt)
123+
set_target_properties(bolt PROPERTIES FOLDER "BOLT")
124+
add_llvm_install_targets(install-bolt DEPENDS bolt COMPONENT bolt)
125+
114126
include_directories(
115127
${CMAKE_CURRENT_SOURCE_DIR}/include
116128
${CMAKE_CURRENT_BINARY_DIR}/include

bolt/cmake/modules/AddBOLT.cmake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
include(GNUInstallDirs)
2+
include(LLVMDistributionSupport)
3+
4+
macro(add_bolt_executable name)
5+
add_llvm_executable(${name} ${ARGN})
6+
set_target_properties(${name} PROPERTIES FOLDER "BOLT")
7+
endmacro()
8+
9+
macro(add_bolt_tool name)
10+
if (NOT BOLT_BUILD_TOOLS)
11+
set(EXCLUDE_FROM_ALL ON)
12+
endif()
13+
14+
add_bolt_executable(${name} ${ARGN})
15+
16+
if (BOLT_BUILD_TOOLS)
17+
get_target_export_arg(${name} BOLT export_to_bolttargets)
18+
install(TARGETS ${name}
19+
${export_to_bolttargets}
20+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
21+
COMPONENT bolt)
22+
23+
if(NOT LLVM_ENABLE_IDE)
24+
add_llvm_install_targets(install-${name}
25+
DEPENDS ${name}
26+
COMPONENT bolt)
27+
endif()
28+
set_property(GLOBAL APPEND PROPERTY BOLT_EXPORTS ${name})
29+
endif()
30+
endmacro()
31+
32+
macro(add_bolt_tool_symlink name dest)
33+
llvm_add_tool_symlink(BOLT ${name} ${dest} ALWAYS_GENERATE)
34+
# Always generate install targets
35+
llvm_install_symlink(BOLT ${name} ${dest} ALWAYS_GENERATE COMPONENT bolt)
36+
endmacro()

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ class BinaryFunction {
384384
/// Indicates the type of profile the function is using.
385385
uint16_t ProfileFlags{PF_NONE};
386386

387+
/// True if the function's input profile data has been inaccurate but has
388+
/// been adjusted by the profile inference algorithm.
389+
bool HasInferredProfile{false};
390+
387391
/// For functions with mismatched profile we store all call profile
388392
/// information at a function level (as opposed to tying it to
389393
/// specific call sites).
@@ -1566,6 +1570,12 @@ class BinaryFunction {
15661570
/// Return flags describing a profile for this function.
15671571
uint16_t getProfileFlags() const { return ProfileFlags; }
15681572

1573+
/// Return true if the function's input profile data has been inaccurate but
1574+
/// has been corrected by the profile inference algorithm.
1575+
bool hasInferredProfile() const { return HasInferredProfile; }
1576+
1577+
void setHasInferredProfile(bool Inferred) { HasInferredProfile = Inferred; }
1578+
15691579
void addCFIInstruction(uint64_t Offset, MCCFIInstruction &&Inst) {
15701580
assert(!Instructions.empty());
15711581

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ class DataAggregator : public DataReader {
199199
/// execution order.
200200
///
201201
/// Return true if the trace is valid, false otherwise.
202-
bool recordTrace(
203-
BinaryFunction &BF, const LBREntry &First, const LBREntry &Second,
204-
uint64_t Count = 1,
205-
SmallVector<std::pair<uint64_t, uint64_t>, 16> *Branches = nullptr) const;
202+
bool
203+
recordTrace(BinaryFunction &BF, const LBREntry &First, const LBREntry &Second,
204+
uint64_t Count,
205+
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const;
206206

207207
/// Return a vector of offsets corresponding to a trace in a function
208208
/// (see recordTrace() above).

bolt/include/bolt/Profile/YAMLProfileReader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class YAMLProfileReader : public ProfileReaderBase {
7070
bool parseFunctionProfile(BinaryFunction &Function,
7171
const yaml::bolt::BinaryFunctionProfile &YamlBF);
7272

73+
/// Infer function profile from stale data (collected on older binaries).
74+
bool inferStaleProfile(BinaryFunction &Function,
75+
const yaml::bolt::BinaryFunctionProfile &YamlBF);
76+
7377
/// Initialize maps for profile matching.
7478
void buildNameMaps(std::map<uint64_t, BinaryFunction> &Functions);
7579

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,14 +3611,6 @@ size_t BinaryFunction::computeHash(bool UseDFS,
36113611
return Hash = std::hash<std::string>{}(HashString);
36123612
}
36133613

3614-
void BinaryFunction::computeBlockHashes() const {
3615-
for (const BinaryBasicBlock *BB : BasicBlocks) {
3616-
std::string Hash =
3617-
hashBlock(BC, *BB, [](const MCOperand &Op) { return std::string(); });
3618-
BB->setHash(std::hash<std::string>{}(Hash));
3619-
}
3620-
}
3621-
36223614
void BinaryFunction::insertBasicBlocks(
36233615
BinaryBasicBlock *Start,
36243616
std::vector<std::unique_ptr<BinaryBasicBlock>> &&NewBBs,
@@ -4509,7 +4501,7 @@ void BinaryFunction::addRelocation(uint64_t Address, MCSymbol *Symbol,
45094501
"address is outside of the function");
45104502
uint64_t Offset = Address - getAddress();
45114503
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: addRelocation in "
4512-
<< formatv("{0}@{1:x} against {2}\n", this, Offset,
4504+
<< formatv("{0}@{1:x} against {2}\n", *this, Offset,
45134505
Symbol->getName()));
45144506
bool IsCI = BC.isAArch64() && isInConstantIsland(Address);
45154507
std::map<uint64_t, Relocation> &Rels =

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,10 +1341,13 @@ void PrintProfileStats::runOnFunctions(BinaryContext &BC) {
13411341
void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
13421342
uint64_t NumRegularFunctions = 0;
13431343
uint64_t NumStaleProfileFunctions = 0;
1344+
uint64_t NumAllStaleFunctions = 0;
1345+
uint64_t NumInferredFunctions = 0;
13441346
uint64_t NumNonSimpleProfiledFunctions = 0;
13451347
uint64_t NumUnknownControlFlowFunctions = 0;
13461348
uint64_t TotalSampleCount = 0;
13471349
uint64_t StaleSampleCount = 0;
1350+
uint64_t InferredSampleCount = 0;
13481351
std::vector<const BinaryFunction *> ProfiledFunctions;
13491352
const char *StaleFuncsHeader = "BOLT-INFO: Functions with stale profile:\n";
13501353
for (auto &BFI : BC.getBinaryFunctions()) {
@@ -1379,6 +1382,11 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
13791382

13801383
if (Function.hasValidProfile()) {
13811384
ProfiledFunctions.push_back(&Function);
1385+
if (Function.hasInferredProfile()) {
1386+
++NumInferredFunctions;
1387+
InferredSampleCount += SampleCount;
1388+
++NumAllStaleFunctions;
1389+
}
13821390
} else {
13831391
if (opts::ReportStaleFuncs) {
13841392
outs() << StaleFuncsHeader;
@@ -1387,6 +1395,7 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
13871395
}
13881396
++NumStaleProfileFunctions;
13891397
StaleSampleCount += SampleCount;
1398+
++NumAllStaleFunctions;
13901399
}
13911400
}
13921401
BC.NumProfiledFuncs = ProfiledFunctions.size();
@@ -1433,6 +1442,16 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
14331442
exit(1);
14341443
}
14351444
}
1445+
if (NumInferredFunctions) {
1446+
outs() << format("BOLT-INFO: inferred profile for %d (%.2f%% of profiled, "
1447+
"%.2f%% of stale) functions responsible for %.2f%% samples"
1448+
" (%zu out of %zu)\n",
1449+
NumInferredFunctions,
1450+
100.0 * NumInferredFunctions / NumAllProfiledFunctions,
1451+
100.0 * NumInferredFunctions / NumAllStaleFunctions,
1452+
100.0 * InferredSampleCount / TotalSampleCount,
1453+
InferredSampleCount, TotalSampleCount);
1454+
}
14361455

14371456
if (const uint64_t NumUnusedObjects = BC.getNumUnusedProfiledObjects()) {
14381457
outs() << "BOLT-INFO: profile for " << NumUnusedObjects

bolt/lib/Profile/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ add_llvm_library(LLVMBOLTProfile
44
DataReader.cpp
55
Heatmap.cpp
66
ProfileReaderBase.cpp
7+
StaleProfileMatching.cpp
78
YAMLProfileReader.cpp
89
YAMLProfileWriter.cpp
910

1011
DISABLE_LLVM_LINK_LLVM_DYLIB
1112

1213
LINK_COMPONENTS
1314
Support
15+
TransformUtils
1416
)
1517

1618
target_link_libraries(LLVMBOLTProfile

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,7 @@ void DataAggregator::launchPerfProcess(StringRef Name, PerfProcessInfo &PPI,
216216
outs() << "PERF2BOLT: spawning perf job to read " << Name << '\n';
217217
Argv.push_back(PerfPath.data());
218218

219-
char *WritableArgsString = strdup(ArgsString);
220-
char *Str = WritableArgsString;
221-
do {
222-
Argv.push_back(Str);
223-
while (*Str && *Str != ' ')
224-
++Str;
225-
if (!*Str)
226-
break;
227-
*Str++ = 0;
228-
} while (true);
229-
219+
StringRef(ArgsString).split(Argv, ' ');
230220
Argv.push_back("-f");
231221
Argv.push_back("-i");
232222
Argv.push_back(Filename.c_str());
@@ -266,8 +256,6 @@ void DataAggregator::launchPerfProcess(StringRef Name, PerfProcessInfo &PPI,
266256
else
267257
PPI.PI = sys::ExecuteNoWait(PerfPath.data(), Argv, /*envp*/ std::nullopt,
268258
Redirects);
269-
270-
free(WritableArgsString);
271259
}
272260

273261
void DataAggregator::processFileBuildID(StringRef FileBuildID) {
@@ -777,7 +765,8 @@ bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
777765
if (!FromFunc && !ToFunc)
778766
return false;
779767

780-
if (FromFunc == ToFunc) {
768+
// Treat recursive control transfers as inter-branches.
769+
if (FromFunc == ToFunc && (To != ToFunc->getAddress())) {
781770
recordBranch(*FromFunc, From - FromFunc->getAddress(),
782771
To - FromFunc->getAddress(), Count, Mispreds);
783772
return doIntraBranch(*FromFunc, From, To, Count, Mispreds);
@@ -791,23 +780,23 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
791780
BinaryFunction *FromFunc = getBinaryFunctionContainingAddress(First.To);
792781
BinaryFunction *ToFunc = getBinaryFunctionContainingAddress(Second.From);
793782
if (!FromFunc || !ToFunc) {
794-
LLVM_DEBUG(
795-
dbgs() << "Out of range trace starting in " << FromFunc->getPrintName()
796-
<< " @ " << Twine::utohexstr(First.To - FromFunc->getAddress())
797-
<< " and ending in " << ToFunc->getPrintName() << " @ "
798-
<< ToFunc->getPrintName() << " @ "
799-
<< Twine::utohexstr(Second.From - ToFunc->getAddress()) << '\n');
783+
LLVM_DEBUG({
784+
dbgs() << "Out of range trace starting in " << FromFunc->getPrintName()
785+
<< formatv(" @ {0:x}", First.To - FromFunc->getAddress())
786+
<< " and ending in " << ToFunc->getPrintName()
787+
<< formatv(" @ {0:x}\n", Second.From - ToFunc->getAddress());
788+
});
800789
NumLongRangeTraces += Count;
801790
return false;
802791
}
803792
if (FromFunc != ToFunc) {
804793
NumInvalidTraces += Count;
805-
LLVM_DEBUG(
806-
dbgs() << "Invalid trace starting in " << FromFunc->getPrintName()
807-
<< " @ " << Twine::utohexstr(First.To - FromFunc->getAddress())
808-
<< " and ending in " << ToFunc->getPrintName() << " @ "
809-
<< ToFunc->getPrintName() << " @ "
810-
<< Twine::utohexstr(Second.From - ToFunc->getAddress()) << '\n');
794+
LLVM_DEBUG({
795+
dbgs() << "Invalid trace starting in " << FromFunc->getPrintName()
796+
<< formatv(" @ {0:x}", First.To - FromFunc->getAddress())
797+
<< " and ending in " << ToFunc->getPrintName()
798+
<< formatv(" @ {0:x}\n", Second.From - ToFunc->getAddress());
799+
});
811800
return false;
812801
}
813802

@@ -838,11 +827,9 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
838827
}
839828

840829
bool DataAggregator::recordTrace(
841-
BinaryFunction &BF,
842-
const LBREntry &FirstLBR,
843-
const LBREntry &SecondLBR,
830+
BinaryFunction &BF, const LBREntry &FirstLBR, const LBREntry &SecondLBR,
844831
uint64_t Count,
845-
SmallVector<std::pair<uint64_t, uint64_t>, 16> *Branches) const {
832+
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const {
846833
BinaryContext &BC = BF.getBinaryContext();
847834

848835
if (!BF.isSimple())
@@ -902,24 +889,27 @@ bool DataAggregator::recordTrace(
902889
return false;
903890
}
904891

905-
// Record fall-through jumps
906-
BinaryBasicBlock::BinaryBranchInfo &BI = BB->getBranchInfo(*NextBB);
907-
BI.Count += Count;
908-
909-
if (Branches) {
910-
const MCInst *Instr = BB->getLastNonPseudoInstr();
911-
uint64_t Offset = 0;
912-
if (Instr)
913-
Offset = BC.MIB->getOffsetWithDefault(*Instr, 0);
914-
else
915-
Offset = BB->getOffset();
892+
const MCInst *Instr = BB->getLastNonPseudoInstr();
893+
uint64_t Offset = 0;
894+
if (Instr)
895+
Offset = BC.MIB->getOffsetWithDefault(*Instr, 0);
896+
else
897+
Offset = BB->getOffset();
916898

917-
Branches->emplace_back(Offset, NextBB->getOffset());
918-
}
899+
Branches.emplace_back(Offset, NextBB->getOffset());
919900

920901
BB = NextBB;
921902
}
922903

904+
// Record fall-through jumps
905+
for (const auto &[FromOffset, ToOffset] : Branches) {
906+
BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset(FromOffset);
907+
BinaryBasicBlock *ToBB = BF.getBasicBlockAtOffset(ToOffset);
908+
assert(FromBB && ToBB);
909+
BinaryBasicBlock::BinaryBranchInfo &BI = FromBB->getBranchInfo(*ToBB);
910+
BI.Count += Count;
911+
}
912+
923913
return true;
924914
}
925915

@@ -930,7 +920,7 @@ DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
930920
uint64_t Count) const {
931921
SmallVector<std::pair<uint64_t, uint64_t>, 16> Res;
932922

933-
if (!recordTrace(BF, FirstLBR, SecondLBR, Count, &Res))
923+
if (!recordTrace(BF, FirstLBR, SecondLBR, Count, Res))
934924
return std::nullopt;
935925

936926
return Res;
@@ -1977,6 +1967,8 @@ std::error_code DataAggregator::parseMMapEvents() {
19771967
std::pair<StringRef, MMapInfo> FileMMapInfo = FileMMapInfoRes.get();
19781968
if (FileMMapInfo.second.PID == -1)
19791969
continue;
1970+
if (FileMMapInfo.first.equals("(deleted)"))
1971+
continue;
19801972

19811973
// Consider only the first mapping of the file for any given PID
19821974
auto Range = GlobalMMapInfo.equal_range(FileMMapInfo.first);

0 commit comments

Comments
 (0)