Skip to content

Commit 64a50b8

Browse files
committed
Merge branch 'main' into amd-trunk-dev
2 parents 5508148 + 53d89ef commit 64a50b8

File tree

2,747 files changed

+138457
-66462
lines changed

Some content is hidden

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

2,747 files changed

+138457
-66462
lines changed

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/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/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" : "")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This test checks that tentative code layout for cold blocks always runs.
2+
# It commonly happens when using lite mode with split functions.
3+
4+
# REQUIRES: system-linux, asserts
5+
6+
# RUN: %clang %cflags -o %t %s
7+
# RUN: %clang %s %cflags -Wl,-q -o %t
8+
# RUN: link_fdata --no-lbr %s %t %t.fdata
9+
# RUN: llvm-bolt %t -o %t.bolt --data %t.fdata -split-functions \
10+
# RUN: -debug 2>&1 | FileCheck %s
11+
12+
.text
13+
.globl foo
14+
.type foo, %function
15+
foo:
16+
.entry_bb:
17+
# FDATA: 1 foo #.entry_bb# 10
18+
cmp x0, #0
19+
b.eq .Lcold_bb1
20+
ret
21+
.Lcold_bb1:
22+
ret
23+
24+
## Force relocation mode.
25+
.reloc 0, R_AARCH64_NONE
26+
27+
# CHECK: foo{{.*}} cold tentative: {{.*}}

bolt/tools/driver/llvm-bolt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ int main(int argc, char **argv) {
202202

203203
ToolName = argv[0];
204204

205-
if (llvm::sys::path::filename(ToolName) == "perf2bolt")
205+
if (llvm::sys::path::filename(ToolName).starts_with("perf2bolt"))
206206
perf2boltMode(argc, argv);
207-
else if (llvm::sys::path::filename(ToolName) == "llvm-boltdiff")
207+
else if (llvm::sys::path::filename(ToolName).starts_with("llvm-boltdiff"))
208208
boltDiffMode(argc, argv);
209209
else
210210
boltMode(argc, argv);

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ Example usage for a project using a compile commands database:
300300
llvm::StringMap<std::vector<StringRef>> USRToBitcode;
301301
Executor->get()->getToolResults()->forEachResult(
302302
[&](StringRef Key, StringRef Value) {
303-
auto R = USRToBitcode.try_emplace(Key, std::vector<StringRef>());
304-
R.first->second.emplace_back(Value);
303+
USRToBitcode[Key].emplace_back(Value);
305304
});
306305

307306
// Collects all Infos according to their unique USR value. This map is added

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ ClangTidyASTConsumerFactory::createASTConsumer(
458458
if (!AnalyzerOptions.CheckersAndPackages.empty()) {
459459
setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
460460
AnalyzerOptions.AnalysisDiagOpt = PD_NONE;
461-
AnalyzerOptions.eagerlyAssumeBinOpBifurcation = true;
462461
std::unique_ptr<ento::AnalysisASTConsumer> AnalysisConsumer =
463462
ento::CreateAnalysisConsumer(Compiler);
464463
AnalysisConsumer->AddDiagnosticConsumer(

0 commit comments

Comments
 (0)