Skip to content

Commit 801c4bd

Browse files
committed
Merge branch 'main' into users/kparzysz/spr/m10-grainsize
2 parents 43f008a + 82b4379 commit 801c4bd

File tree

1,186 files changed

+58500
-12792
lines changed

Some content is hidden

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

1,186 files changed

+58500
-12792
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,19 @@ inline raw_ostream &operator<<(raw_ostream &OS,
24072407
return OS;
24082408
}
24092409

2410+
/// Compare function by index if it is valid, fall back to the original address
2411+
/// otherwise.
2412+
inline bool compareBinaryFunctionByIndex(const BinaryFunction *A,
2413+
const BinaryFunction *B) {
2414+
if (A->hasValidIndex() && B->hasValidIndex())
2415+
return A->getIndex() < B->getIndex();
2416+
if (A->hasValidIndex() && !B->hasValidIndex())
2417+
return true;
2418+
if (!A->hasValidIndex() && B->hasValidIndex())
2419+
return false;
2420+
return A->getAddress() < B->getAddress();
2421+
}
2422+
24102423
} // namespace bolt
24112424

24122425
// GraphTraits specializations for function basic block graphs (CFGs)

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ class DataAggregator : public DataReader {
170170
std::string BuildIDBinaryName;
171171

172172
/// Memory map info for a single file as recorded in perf.data
173-
/// When a binary has multiple text segments, the Size is computed as the
174-
/// difference of the last address of these segments from the BaseAddress.
175-
/// The base addresses of all text segments must be the same.
176173
struct MMapInfo {
177174
uint64_t BaseAddress{0}; /// Base address of the mapped binary.
178175
uint64_t MMapAddress{0}; /// Address of the executable segment.
@@ -496,11 +493,6 @@ class DataAggregator : public DataReader {
496493
/// and return a file name matching a given \p FileBuildID.
497494
std::optional<StringRef> getFileNameForBuildID(StringRef FileBuildID);
498495

499-
/// Get a constant reference to the parsed binary mmap entries.
500-
const std::unordered_map<uint64_t, MMapInfo> &getBinaryMMapInfo() {
501-
return BinaryMMapInfo;
502-
}
503-
504496
friend class YAMLProfileWriter;
505497
};
506498
} // namespace bolt

bolt/lib/Core/BinaryContext.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,13 +1607,7 @@ std::vector<BinaryFunction *> BinaryContext::getSortedFunctions() {
16071607
SortedFunctions.begin(),
16081608
[](BinaryFunction &BF) { return &BF; });
16091609

1610-
llvm::stable_sort(SortedFunctions,
1611-
[](const BinaryFunction *A, const BinaryFunction *B) {
1612-
if (A->hasValidIndex() && B->hasValidIndex()) {
1613-
return A->getIndex() < B->getIndex();
1614-
}
1615-
return A->hasValidIndex();
1616-
});
1610+
llvm::stable_sort(SortedFunctions, compareBinaryFunctionByIndex);
16171611
return SortedFunctions;
16181612
}
16191613

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,7 @@ bool BinaryFunction::isForwardCall(const MCSymbol *CalleeSymbol) const {
385385
if (CalleeBF) {
386386
if (CalleeBF->isInjected())
387387
return true;
388-
389-
if (hasValidIndex() && CalleeBF->hasValidIndex()) {
390-
return getIndex() < CalleeBF->getIndex();
391-
} else if (hasValidIndex() && !CalleeBF->hasValidIndex()) {
392-
return true;
393-
} else if (!hasValidIndex() && CalleeBF->hasValidIndex()) {
394-
return false;
395-
} else {
396-
return getAddress() < CalleeBF->getAddress();
397-
}
388+
return compareBinaryFunctionByIndex(this, CalleeBF);
398389
} else {
399390
// Absolute symbol.
400391
ErrorOr<uint64_t> CalleeAddressOrError = BC.getSymbolValue(*CalleeSymbol);

bolt/lib/Passes/ReorderFunctions.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,7 @@ Error ReorderFunctions::runOnFunctions(BinaryContext &BC) {
473473
[](BinaryFunction &BF) { return &BF; });
474474

475475
// Sort functions by index.
476-
llvm::stable_sort(SortedFunctions,
477-
[](const BinaryFunction *A, const BinaryFunction *B) {
478-
if (A->hasValidIndex() && B->hasValidIndex())
479-
return A->getIndex() < B->getIndex();
480-
if (A->hasValidIndex() && !B->hasValidIndex())
481-
return true;
482-
if (!A->hasValidIndex() && B->hasValidIndex())
483-
return false;
484-
return A->getAddress() < B->getAddress();
485-
});
476+
llvm::stable_sort(SortedFunctions, compareBinaryFunctionByIndex);
486477

487478
for (const BinaryFunction *Func : SortedFunctions) {
488479
if (!Func->hasValidIndex())

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ cl::opt<bool> ReadPreAggregated(
9595
"pa", cl::desc("skip perf and read data from a pre-aggregated file format"),
9696
cl::cat(AggregatorCategory));
9797

98-
cl::opt<std::string>
99-
ReadPerfEvents("perf-script-events",
100-
cl::desc("skip perf event collection by supplying a "
101-
"perf-script output in a textual format"),
102-
cl::ReallyHidden, cl::init(""), cl::cat(AggregatorCategory));
103-
10498
static cl::opt<bool>
10599
TimeAggregator("time-aggr",
106100
cl::desc("time BOLT aggregator"),
@@ -173,9 +167,8 @@ void DataAggregator::findPerfExecutable() {
173167
void DataAggregator::start() {
174168
outs() << "PERF2BOLT: Starting data aggregation job for " << Filename << "\n";
175169

176-
// Don't launch perf for pre-aggregated files or when perf input is specified
177-
// by the user.
178-
if (opts::ReadPreAggregated || !opts::ReadPerfEvents.empty())
170+
// Don't launch perf for pre-aggregated files
171+
if (opts::ReadPreAggregated)
179172
return;
180173

181174
findPerfExecutable();
@@ -471,13 +464,6 @@ void DataAggregator::filterBinaryMMapInfo() {
471464

472465
int DataAggregator::prepareToParse(StringRef Name, PerfProcessInfo &Process,
473466
PerfProcessErrorCallbackTy Callback) {
474-
if (!opts::ReadPerfEvents.empty()) {
475-
outs() << "PERF2BOLT: using pre-processed perf events for '" << Name
476-
<< "' (perf-script-events)\n";
477-
ParsingBuf = opts::ReadPerfEvents;
478-
return 0;
479-
}
480-
481467
std::string Error;
482468
outs() << "PERF2BOLT: waiting for perf " << Name
483469
<< " collection to finish...\n";
@@ -2070,6 +2056,15 @@ std::error_code DataAggregator::parseMMapEvents() {
20702056
if (FileMMapInfo.first == "(deleted)")
20712057
continue;
20722058

2059+
// Consider only the first mapping of the file for any given PID
2060+
auto Range = GlobalMMapInfo.equal_range(FileMMapInfo.first);
2061+
bool PIDExists = llvm::any_of(make_range(Range), [&](const auto &MI) {
2062+
return MI.second.PID == FileMMapInfo.second.PID;
2063+
});
2064+
2065+
if (PIDExists)
2066+
continue;
2067+
20732068
GlobalMMapInfo.insert(FileMMapInfo);
20742069
}
20752070

@@ -2121,22 +2116,12 @@ std::error_code DataAggregator::parseMMapEvents() {
21212116
<< " using file offset 0x" << Twine::utohexstr(MMapInfo.Offset)
21222117
<< ". Ignoring profile data for this mapping\n";
21232118
continue;
2119+
} else {
2120+
MMapInfo.BaseAddress = *BaseAddress;
21242121
}
2125-
MMapInfo.BaseAddress = *BaseAddress;
21262122
}
21272123

2128-
// Try to add MMapInfo to the map and update its size. Large binaries may
2129-
// span to multiple text segments, so the mapping is inserted only on the
2130-
// first occurrence.
2131-
if (!BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo)).second)
2132-
assert(MMapInfo.BaseAddress == BinaryMMapInfo[MMapInfo.PID].BaseAddress &&
2133-
"Base address on multiple segment mappings should match");
2134-
2135-
// Update mapping size.
2136-
const uint64_t EndAddress = MMapInfo.MMapAddress + MMapInfo.Size;
2137-
const uint64_t Size = EndAddress - BinaryMMapInfo[MMapInfo.PID].BaseAddress;
2138-
if (Size > BinaryMMapInfo[MMapInfo.PID].Size)
2139-
BinaryMMapInfo[MMapInfo.PID].Size = Size;
2124+
BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo));
21402125
}
21412126

21422127
if (BinaryMMapInfo.empty()) {

bolt/test/AArch64/data-at-0-offset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang %cflags -O2 -fPIE -Wl,-q -pie %s -o %t.exe
1+
// RUN: %clang %cflags -O2 -fPIE -std=gnu99 -Wl,-q -pie %s -o %t.exe
22
// RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
33
// CHECK-NOT: BOLT-WARNING: unable to disassemble instruction at offset
44

bolt/test/AArch64/double_jump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// A contrived example to test the double jump removal peephole.
22

3-
// RUN: %clang %cflags -O0 %s -o %t.exe
3+
// RUN: %clangxx %cxxflags -O0 %s -o %t.exe
44
// RUN: llvm-bolt %t.exe -o %t.bolt --peepholes=double-jumps | \
55
// RUN: FileCheck %s -check-prefix=CHECKBOLT
66
// RUN: llvm-objdump --no-print-imm-hex -d %t.bolt | FileCheck %s

bolt/test/R_ABS.pic.lld.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* with libc available.
77
* REQUIRES: system-linux
88
*
9-
* RUN: %clang %cflags -fPIC -shared %s -o %t.so -Wl,-q -fuse-ld=lld
9+
* RUN: %clangxx %cxxflags -fPIC -shared %s -o %t.so -Wl,-q -fuse-ld=lld
1010
* RUN: llvm-bolt %t.so -o %t.so.bolt --relocs
1111
*/
1212

bolt/test/X86/double-jump.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## correctly on Windows e.g. subshell execution
55
REQUIRES: shell
66

7-
RUN: %clang %cflags %p/Inputs/double_jump.cpp -o %t.exe
7+
RUN: %clangxx %cxxflags %p/Inputs/double_jump.cpp -o %t.exe
88
RUN: (llvm-bolt %t.exe --peepholes=double-jumps \
99
RUN: --eliminate-unreachable -o %t 2>&1 \
1010
RUN: && llvm-objdump -d %t --print-imm-hex --no-show-raw-insn) | FileCheck %s

0 commit comments

Comments
 (0)