Skip to content

Commit 634979c

Browse files
authored
Merge branch 'main' into ronan/cxxfilt-quote
2 parents f4f4799 + 697a455 commit 634979c

File tree

3,977 files changed

+187514
-101689
lines changed

Some content is hidden

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

3,977 files changed

+187514
-101689
lines changed

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class DIEBuilder {
314314

315315
BC.errs()
316316
<< "BOLT-ERROR: unable to find TypeUnit for Type Unit at offset 0x"
317-
<< DU.getOffset() << "\n";
317+
<< Twine::utohexstr(DU.getOffset()) << "\n";
318318
return nullptr;
319319
}
320320

bolt/include/bolt/Profile/BoltAddressTranslation.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,13 @@ class BoltAddressTranslation {
141141
uint64_t FuncOutputAddress) const;
142142

143143
/// Write the serialized address translation table for a function.
144-
template <bool Cold>
145-
void writeMaps(std::map<uint64_t, MapTy> &Maps, uint64_t &PrevAddress,
146-
raw_ostream &OS);
144+
template <bool Cold> void writeMaps(uint64_t &PrevAddress, raw_ostream &OS);
147145

148146
/// Read the serialized address translation table for a function.
149147
/// Return a parse error if failed.
150148
template <bool Cold>
151-
void parseMaps(std::vector<uint64_t> &HotFuncs, uint64_t &PrevAddress,
152-
DataExtractor &DE, uint64_t &Offset, Error &Err);
149+
void parseMaps(uint64_t &PrevAddress, DataExtractor &DE, uint64_t &Offset,
150+
Error &Err);
153151

154152
/// Returns the bitmask with set bits corresponding to indices of BRANCHENTRY
155153
/// entries in function address translation map.
@@ -161,6 +159,9 @@ class BoltAddressTranslation {
161159

162160
std::map<uint64_t, MapTy> Maps;
163161

162+
/// Ordered vector with addresses of hot functions.
163+
std::vector<uint64_t> HotFuncs;
164+
164165
/// Map a function to its basic blocks count
165166
std::unordered_map<uint64_t, size_t> NumBasicBlocksMap;
166167

bolt/lib/Core/BinaryContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,8 @@ bool BinaryContext::handleAArch64Veneer(uint64_t Address, bool MatchOnly) {
12941294
Veneer->getOrCreateLocalLabel(Address);
12951295
Veneer->setMaxSize(TotalSize);
12961296
Veneer->updateState(BinaryFunction::State::Disassembled);
1297-
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: handling veneer function at 0x" << Address
1298-
<< "\n");
1297+
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: handling veneer function at 0x"
1298+
<< Twine::utohexstr(Address) << "\n");
12991299
return true;
13001300
};
13011301

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,9 +3684,8 @@ BinaryFunction::BasicBlockListType BinaryFunction::dfs() const {
36843684
BinaryBasicBlock *BB = Stack.top();
36853685
Stack.pop();
36863686

3687-
if (Visited.find(BB) != Visited.end())
3687+
if (!Visited.insert(BB).second)
36883688
continue;
3689-
Visited.insert(BB);
36903689
DFS.push_back(BB);
36913690

36923691
for (BinaryBasicBlock *SuccBB : BB->landing_pads()) {
@@ -3879,11 +3878,8 @@ void BinaryFunction::disambiguateJumpTables(
38793878
JumpTable *JT = getJumpTable(Inst);
38803879
if (!JT)
38813880
continue;
3882-
auto Iter = JumpTables.find(JT);
3883-
if (Iter == JumpTables.end()) {
3884-
JumpTables.insert(JT);
3881+
if (JumpTables.insert(JT).second)
38853882
continue;
3886-
}
38873883
// This instruction is an indirect jump using a jump table, but it is
38883884
// using the same jump table of another jump. Try all our tricks to
38893885
// extract the jump table symbol and make it point to a new, duplicated JT

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ getDWOName(llvm::DWARFUnit &CU,
5757
"DW_AT_dwo_name/DW_AT_GNU_dwo_name does not exist.");
5858
if (DwarfOutputPath) {
5959
DWOName = std::string(sys::path::filename(DWOName));
60-
auto Iter = NameToIndexMap.find(DWOName);
61-
if (Iter == NameToIndexMap.end())
62-
Iter = NameToIndexMap.insert({DWOName, 0}).first;
63-
DWOName.append(std::to_string(Iter->second));
64-
++Iter->second;
60+
uint32_t &Index = NameToIndexMap[DWOName];
61+
DWOName.append(std::to_string(Index));
62+
++Index;
6563
}
6664
DWOName.append(".dwo");
6765
return DWOName;

bolt/lib/Passes/Instrumentation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ static bool hasAArch64ExclusiveMemop(
109109
BinaryBasicBlock *BB = BBQueue.front().first;
110110
bool IsLoad = BBQueue.front().second;
111111
BBQueue.pop();
112-
if (Visited.find(BB) != Visited.end())
112+
if (!Visited.insert(BB).second)
113113
continue;
114-
Visited.insert(BB);
115114

116115
for (const MCInst &Inst : *BB) {
117116
// Two loads one after another - skip whole function
@@ -126,8 +125,7 @@ static bool hasAArch64ExclusiveMemop(
126125
if (BC.MIB->isAArch64ExclusiveLoad(Inst))
127126
IsLoad = true;
128127

129-
if (IsLoad && BBToSkip.find(BB) == BBToSkip.end()) {
130-
BBToSkip.insert(BB);
128+
if (IsLoad && BBToSkip.insert(BB).second) {
131129
if (opts::Verbosity >= 2) {
132130
outs() << "BOLT-INSTRUMENTER: skip BB " << BB->getName()
133131
<< " due to exclusive instruction in function "

bolt/lib/Passes/LongJmp.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,8 @@ uint64_t LongJmpPass::tentativeLayoutRelocColdPart(
324324
uint64_t LongJmpPass::tentativeLayoutRelocMode(
325325
const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions,
326326
uint64_t DotAddress) {
327-
328327
// Compute hot cold frontier
329-
uint32_t LastHotIndex = -1u;
328+
int64_t LastHotIndex = -1u;
330329
uint32_t CurrentIndex = 0;
331330
if (opts::HotFunctionsAtEnd) {
332331
for (BinaryFunction *BF : SortedFunctions) {
@@ -351,19 +350,20 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
351350
// Hot
352351
CurrentIndex = 0;
353352
bool ColdLayoutDone = false;
353+
auto runColdLayout = [&]() {
354+
DotAddress = tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
355+
ColdLayoutDone = true;
356+
if (opts::HotFunctionsAtEnd)
357+
DotAddress = alignTo(DotAddress, opts::AlignText);
358+
};
354359
for (BinaryFunction *Func : SortedFunctions) {
355360
if (!BC.shouldEmit(*Func)) {
356361
HotAddresses[Func] = Func->getAddress();
357362
continue;
358363
}
359364

360-
if (!ColdLayoutDone && CurrentIndex >= LastHotIndex) {
361-
DotAddress =
362-
tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
363-
ColdLayoutDone = true;
364-
if (opts::HotFunctionsAtEnd)
365-
DotAddress = alignTo(DotAddress, opts::AlignText);
366-
}
365+
if (!ColdLayoutDone && CurrentIndex >= LastHotIndex)
366+
runColdLayout();
367367

368368
DotAddress = alignTo(DotAddress, Func->getMinAlignment());
369369
uint64_t Pad =
@@ -382,6 +382,11 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
382382
DotAddress += Func->estimateConstantIslandSize();
383383
++CurrentIndex;
384384
}
385+
386+
// Ensure that tentative code layout always runs for cold blocks.
387+
if (!ColdLayoutDone)
388+
runColdLayout();
389+
385390
// BBs
386391
for (BinaryFunction *Func : SortedFunctions)
387392
tentativeBBLayout(*Func);

bolt/lib/Passes/VeneerElimination.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ Error VeneerElimination::runOnFunctions(BinaryContext &BC) {
7373
continue;
7474

7575
const MCSymbol *TargetSymbol = BC.MIB->getTargetSymbol(Instr, 0);
76-
if (VeneerDestinations.find(TargetSymbol) == VeneerDestinations.end())
76+
auto It = VeneerDestinations.find(TargetSymbol);
77+
if (It == VeneerDestinations.end())
7778
continue;
7879

7980
VeneerCallers++;
80-
BC.MIB->replaceBranchTarget(Instr, VeneerDestinations[TargetSymbol],
81-
BC.Ctx.get());
81+
BC.MIB->replaceBranchTarget(Instr, It->second, BC.Ctx.get());
8282
}
8383
}
8484
}

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
143143

144144
// Output addresses are delta-encoded
145145
uint64_t PrevAddress = 0;
146-
writeMaps</*Cold=*/false>(Maps, PrevAddress, OS);
147-
writeMaps</*Cold=*/true>(Maps, PrevAddress, OS);
146+
writeMaps</*Cold=*/false>(PrevAddress, OS);
147+
writeMaps</*Cold=*/true>(PrevAddress, OS);
148148

149149
BC.outs() << "BOLT-INFO: Wrote " << Maps.size() << " BAT maps\n";
150150
BC.outs() << "BOLT-INFO: Wrote " << FuncHashes.getNumFunctions()
@@ -182,8 +182,7 @@ size_t BoltAddressTranslation::getNumEqualOffsets(const MapTy &Map,
182182
}
183183

184184
template <bool Cold>
185-
void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
186-
uint64_t &PrevAddress, raw_ostream &OS) {
185+
void BoltAddressTranslation::writeMaps(uint64_t &PrevAddress, raw_ostream &OS) {
187186
const uint32_t NumFuncs =
188187
llvm::count_if(llvm::make_first_range(Maps), [&](const uint64_t Address) {
189188
return Cold == ColdPartSource.count(Address);
@@ -213,16 +212,17 @@ void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
213212
: 0;
214213
uint32_t Skew = 0;
215214
if (Cold) {
216-
auto HotEntryIt = Maps.find(ColdPartSource[Address]);
217-
assert(HotEntryIt != Maps.end());
218-
size_t HotIndex = std::distance(Maps.begin(), HotEntryIt);
215+
auto HotEntryIt = llvm::lower_bound(HotFuncs, ColdPartSource[Address]);
216+
assert(HotEntryIt != HotFuncs.end());
217+
size_t HotIndex = std::distance(HotFuncs.begin(), HotEntryIt);
219218
encodeULEB128(HotIndex - PrevIndex, OS);
220219
PrevIndex = HotIndex;
221220
// Skew of all input offsets for cold fragments is simply the first input
222221
// offset.
223222
Skew = Map.begin()->second >> 1;
224223
encodeULEB128(Skew, OS);
225224
} else {
225+
HotFuncs.push_back(Address);
226226
// Function hash
227227
size_t BFHash = getBFHash(HotInputAddress);
228228
LLVM_DEBUG(dbgs() << "Hash: " << formatv("{0:x}\n", BFHash));
@@ -311,17 +311,15 @@ std::error_code BoltAddressTranslation::parse(raw_ostream &OS, StringRef Buf) {
311311
return make_error_code(llvm::errc::io_error);
312312

313313
Error Err(Error::success());
314-
std::vector<uint64_t> HotFuncs;
315314
uint64_t PrevAddress = 0;
316-
parseMaps</*Cold=*/false>(HotFuncs, PrevAddress, DE, Offset, Err);
317-
parseMaps</*Cold=*/true>(HotFuncs, PrevAddress, DE, Offset, Err);
315+
parseMaps</*Cold=*/false>(PrevAddress, DE, Offset, Err);
316+
parseMaps</*Cold=*/true>(PrevAddress, DE, Offset, Err);
318317
OS << "BOLT-INFO: Parsed " << Maps.size() << " BAT entries\n";
319318
return errorToErrorCode(std::move(Err));
320319
}
321320

322321
template <bool Cold>
323-
void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
324-
uint64_t &PrevAddress, DataExtractor &DE,
322+
void BoltAddressTranslation::parseMaps(uint64_t &PrevAddress, DataExtractor &DE,
325323
uint64_t &Offset, Error &Err) {
326324
const uint32_t NumFunctions = DE.getULEB128(&Offset, &Err);
327325
LLVM_DEBUG(dbgs() << "Parsing " << NumFunctions << (Cold ? " cold" : "")

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ void DWARFRewriter::updateDWARFObjectAddressRanges(
13621362
Die.getTag() == dwarf::DW_TAG_compile_unit)) {
13631363
if (opts::Verbosity >= 1)
13641364
errs() << "BOLT-WARNING: cannot update ranges for DIE in Unit offset 0x"
1365-
<< Unit.getOffset() << '\n';
1365+
<< Twine::utohexstr(Unit.getOffset()) << '\n';
13661366
}
13671367
}
13681368

0 commit comments

Comments
 (0)