Skip to content

Commit 4a240b7

Browse files
committed
Merge from 'main' to 'sycl-web' (133 commits)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaChecking.cpp
2 parents ac8329c + 781b135 commit 4a240b7

File tree

567 files changed

+14167
-6332
lines changed

Some content is hidden

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

567 files changed

+14167
-6332
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class BinaryContext {
359359
void setFileBuildID(StringRef ID) { FileBuildID = std::string(ID); }
360360

361361
bool hasSymbolsWithFileName() const { return HasSymbolsWithFileName; }
362-
void setHasSymbolsWithFileName(bool Value) { HasSymbolsWithFileName = true; }
362+
void setHasSymbolsWithFileName(bool Value) { HasSymbolsWithFileName = Value; }
363363

364364
/// Return true if relocations against symbol with a given name
365365
/// must be created.

bolt/include/bolt/Passes/MCF.h

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,14 @@
99
#ifndef BOLT_PASSES_MCF_H
1010
#define BOLT_PASSES_MCF_H
1111

12+
#include "bolt/Passes/BinaryPasses.h"
13+
#include "llvm/Support/CommandLine.h"
14+
1215
namespace llvm {
1316
namespace bolt {
1417

15-
class BinaryFunction;
1618
class DataflowInfoManager;
1719

18-
enum MCFCostFunction : char {
19-
MCF_DISABLE = 0,
20-
MCF_LINEAR,
21-
MCF_QUADRATIC,
22-
MCF_LOG,
23-
MCF_BLAMEFTS
24-
};
25-
2620
/// Implement the idea in "SamplePGO - The Power of Profile Guided Optimizations
2721
/// without the Usability Burden" by Diego Novillo to make basic block counts
2822
/// equal if we show that A dominates B, B post-dominates A and they are in the
@@ -31,23 +25,18 @@ void equalizeBBCounts(DataflowInfoManager &Info, BinaryFunction &BF);
3125

3226
/// Fill edge counts based on the basic block count. Used in nonLBR mode when
3327
/// we only have bb count.
34-
void estimateEdgeCounts(BinaryFunction &BF);
35-
36-
/// Entry point for computing a min-cost flow for the CFG with the goal
37-
/// of fixing the flow of the CFG edges, that is, making sure it obeys the
38-
/// flow-conservation equation SumInEdges = SumOutEdges.
39-
///
40-
/// To do this, we create an instance of the min-cost flow problem in a
41-
/// similar way as the one discussed in the work of Roy Levin "Completing
42-
/// Incomplete Edge Profile by Applying Minimum Cost Circulation Algorithms".
43-
/// We do a few things differently, though. We don't populate edge counts using
44-
/// weights coming from a static branch prediction technique and we don't
45-
/// use the same cost function.
46-
///
47-
/// If cost function BlameFTs is used, assign all remaining flow to
48-
/// fall-throughs. This is used when the sampling is based on taken branches
49-
/// that do not account for them.
50-
void solveMCF(BinaryFunction &BF, MCFCostFunction CostFunction);
28+
class EstimateEdgeCounts : public BinaryFunctionPass {
29+
void runOnFunction(BinaryFunction &BF);
30+
31+
public:
32+
explicit EstimateEdgeCounts(const cl::opt<bool> &PrintPass)
33+
: BinaryFunctionPass(PrintPass) {}
34+
35+
const char *getName() const override { return "estimate-edge-counts"; }
36+
37+
/// Pass entry point
38+
Error runOnFunctions(BinaryContext &BC) override;
39+
};
5140

5241
} // end namespace bolt
5342
} // end namespace llvm

bolt/include/bolt/Profile/BoltAddressTranslation.h

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class BoltAddressTranslation {
9090
std::error_code parse(raw_ostream &OS, StringRef Buf);
9191

9292
/// Dump the parsed address translation tables
93-
void dump(raw_ostream &OS);
93+
void dump(raw_ostream &OS) const;
9494

9595
/// If the maps are loaded in memory, perform the lookup to translate LBR
9696
/// addresses in function located at \p FuncAddress.
@@ -107,7 +107,12 @@ class BoltAddressTranslation {
107107

108108
/// If available, fetch the address of the hot part linked to the cold part
109109
/// at \p Address. Return 0 otherwise.
110-
uint64_t fetchParentAddress(uint64_t Address) const;
110+
uint64_t fetchParentAddress(uint64_t Address) const {
111+
auto Iter = ColdPartSource.find(Address);
112+
if (Iter == ColdPartSource.end())
113+
return 0;
114+
return Iter->second;
115+
}
111116

112117
/// True if the input binary has a translation table we can use to convert
113118
/// addresses when aggregating profile
@@ -132,7 +137,8 @@ class BoltAddressTranslation {
132137
/// emitted for the start of the BB. More entries may be emitted to cover
133138
/// the location of calls or any instruction that may change control flow.
134139
void writeEntriesForBB(MapTy &Map, const BinaryBasicBlock &BB,
135-
uint64_t FuncInputAddress, uint64_t FuncOutputAddress);
140+
uint64_t FuncInputAddress,
141+
uint64_t FuncOutputAddress) const;
136142

137143
/// Write the serialized address translation table for a function.
138144
template <bool Cold>
@@ -147,7 +153,7 @@ class BoltAddressTranslation {
147153

148154
/// Returns the bitmask with set bits corresponding to indices of BRANCHENTRY
149155
/// entries in function address translation map.
150-
APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems);
156+
APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems) const;
151157

152158
/// Calculate the number of equal offsets (output = input - skew) in the
153159
/// beginning of the function.
@@ -178,14 +184,9 @@ class BoltAddressTranslation {
178184
public:
179185
/// Map basic block input offset to a basic block index and hash pair.
180186
class BBHashMapTy {
181-
class EntryTy {
187+
struct EntryTy {
182188
unsigned Index;
183189
size_t Hash;
184-
185-
public:
186-
unsigned getBBIndex() const { return Index; }
187-
size_t getBBHash() const { return Hash; }
188-
EntryTy(unsigned Index, size_t Hash) : Index(Index), Hash(Hash) {}
189190
};
190191

191192
std::map<uint32_t, EntryTy> Map;
@@ -201,15 +202,15 @@ class BoltAddressTranslation {
201202
}
202203

203204
unsigned getBBIndex(uint32_t BBInputOffset) const {
204-
return getEntry(BBInputOffset).getBBIndex();
205+
return getEntry(BBInputOffset).Index;
205206
}
206207

207208
size_t getBBHash(uint32_t BBInputOffset) const {
208-
return getEntry(BBInputOffset).getBBHash();
209+
return getEntry(BBInputOffset).Hash;
209210
}
210211

211212
void addEntry(uint32_t BBInputOffset, unsigned BBIndex, size_t BBHash) {
212-
Map.emplace(BBInputOffset, EntryTy(BBIndex, BBHash));
213+
Map.emplace(BBInputOffset, EntryTy{BBIndex, BBHash});
213214
}
214215

215216
size_t getNumBasicBlocks() const { return Map.size(); }
@@ -221,14 +222,9 @@ class BoltAddressTranslation {
221222

222223
/// Map function output address to its hash and basic blocks hash map.
223224
class FuncHashesTy {
224-
class EntryTy {
225+
struct EntryTy {
225226
size_t Hash;
226227
BBHashMapTy BBHashMap;
227-
228-
public:
229-
size_t getBFHash() const { return Hash; }
230-
const BBHashMapTy &getBBHashMap() const { return BBHashMap; }
231-
EntryTy(size_t Hash) : Hash(Hash) {}
232228
};
233229

234230
std::unordered_map<uint64_t, EntryTy> Map;
@@ -240,23 +236,23 @@ class BoltAddressTranslation {
240236

241237
public:
242238
size_t getBFHash(uint64_t FuncOutputAddress) const {
243-
return getEntry(FuncOutputAddress).getBFHash();
239+
return getEntry(FuncOutputAddress).Hash;
244240
}
245241

246242
const BBHashMapTy &getBBHashMap(uint64_t FuncOutputAddress) const {
247-
return getEntry(FuncOutputAddress).getBBHashMap();
243+
return getEntry(FuncOutputAddress).BBHashMap;
248244
}
249245

250246
void addEntry(uint64_t FuncOutputAddress, size_t BFHash) {
251-
Map.emplace(FuncOutputAddress, EntryTy(BFHash));
247+
Map.emplace(FuncOutputAddress, EntryTy{BFHash, BBHashMapTy()});
252248
}
253249

254250
size_t getNumFunctions() const { return Map.size(); };
255251

256252
size_t getNumBasicBlocks() const {
257253
size_t NumBasicBlocks{0};
258254
for (auto &I : Map)
259-
NumBasicBlocks += I.second.getBBHashMap().getNumBasicBlocks();
255+
NumBasicBlocks += I.second.BBHashMap.getNumBasicBlocks();
260256
return NumBasicBlocks;
261257
}
262258
};
@@ -278,7 +274,9 @@ class BoltAddressTranslation {
278274

279275
/// Returns the number of basic blocks in a function.
280276
size_t getNumBasicBlocks(uint64_t OutputAddress) const {
281-
return NumBasicBlocksMap.at(OutputAddress);
277+
auto It = NumBasicBlocksMap.find(OutputAddress);
278+
assert(It != NumBasicBlocksMap.end());
279+
return It->second;
282280
}
283281

284282
private:

bolt/lib/Core/BinaryContext.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,13 @@ std::string BinaryContext::generateJumpTableName(const BinaryFunction &BF,
934934
uint64_t Offset = 0;
935935
if (const JumpTable *JT = BF.getJumpTableContainingAddress(Address)) {
936936
Offset = Address - JT->getAddress();
937-
auto Itr = JT->Labels.find(Offset);
938-
if (Itr != JT->Labels.end())
939-
return std::string(Itr->second->getName());
940-
Id = JumpTableIds.at(JT->getAddress());
937+
auto JTLabelsIt = JT->Labels.find(Offset);
938+
if (JTLabelsIt != JT->Labels.end())
939+
return std::string(JTLabelsIt->second->getName());
940+
941+
auto JTIdsIt = JumpTableIds.find(JT->getAddress());
942+
assert(JTIdsIt != JumpTableIds.end());
943+
Id = JTIdsIt->second;
941944
} else {
942945
Id = JumpTableIds[Address] = BF.JumpTables.size();
943946
}

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,9 @@ void BinaryEmitter::emitJumpTable(const JumpTable &JT, MCSection *HotSection,
813813
// determining its destination.
814814
std::map<MCSymbol *, uint64_t> LabelCounts;
815815
if (opts::JumpTables > JTS_SPLIT && !JT.Counts.empty()) {
816-
MCSymbol *CurrentLabel = JT.Labels.at(0);
816+
auto It = JT.Labels.find(0);
817+
assert(It != JT.Labels.end());
818+
MCSymbol *CurrentLabel = It->second;
817819
uint64_t CurrentLabelCount = 0;
818820
for (unsigned Index = 0; Index < JT.Entries.size(); ++Index) {
819821
auto LI = JT.Labels.find(Index * JT.EntrySize);

bolt/lib/Core/DynoStats.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ void DynoStats::print(raw_ostream &OS, const DynoStats *Other,
114114
for (auto &Stat : llvm::reverse(SortedHistogram)) {
115115
OS << format("%20s,%'18lld", Printer->getOpcodeName(Stat.second).data(),
116116
Stat.first * opts::DynoStatsScale);
117-
118-
MaxOpcodeHistogramTy MaxMultiMap = OpcodeHistogram.at(Stat.second).second;
117+
auto It = OpcodeHistogram.find(Stat.second);
118+
assert(It != OpcodeHistogram.end());
119+
MaxOpcodeHistogramTy MaxMultiMap = It->second.second;
119120
// Start with function name:BB offset with highest execution count.
120121
for (auto &Max : llvm::reverse(MaxMultiMap)) {
121122
OS << format(", %'18lld, ", Max.first * opts::DynoStatsScale)

bolt/lib/Passes/BinaryFunctionCallGraph.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ std::deque<BinaryFunction *> BinaryFunctionCallGraph::buildTraversalOrder() {
5656
std::stack<NodeId> Worklist;
5757

5858
for (BinaryFunction *Func : Funcs) {
59-
const NodeId Id = FuncToNodeId.at(Func);
59+
auto It = FuncToNodeId.find(Func);
60+
assert(It != FuncToNodeId.end());
61+
const NodeId Id = It->second;
6062
Worklist.push(Id);
6163
NodeStatus[Id] = NEW;
6264
}

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,23 +1563,28 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
15631563
const bool Ascending =
15641564
opts::DynoStatsSortOrderOpt == opts::DynoStatsSortOrder::Ascending;
15651565

1566-
if (SortAll) {
1567-
llvm::stable_sort(Functions,
1568-
[Ascending, &Stats](const BinaryFunction *A,
1569-
const BinaryFunction *B) {
1570-
return Ascending ? Stats.at(A) < Stats.at(B)
1571-
: Stats.at(B) < Stats.at(A);
1572-
});
1573-
} else {
1574-
llvm::stable_sort(
1575-
Functions, [Ascending, &Stats](const BinaryFunction *A,
1576-
const BinaryFunction *B) {
1577-
const DynoStats &StatsA = Stats.at(A);
1578-
const DynoStats &StatsB = Stats.at(B);
1579-
return Ascending ? StatsA.lessThan(StatsB, opts::PrintSortedBy)
1580-
: StatsB.lessThan(StatsA, opts::PrintSortedBy);
1581-
});
1582-
}
1566+
std::function<bool(const DynoStats &, const DynoStats &)>
1567+
DynoStatsComparator =
1568+
SortAll ? [](const DynoStats &StatsA,
1569+
const DynoStats &StatsB) { return StatsA < StatsB; }
1570+
: [](const DynoStats &StatsA, const DynoStats &StatsB) {
1571+
return StatsA.lessThan(StatsB, opts::PrintSortedBy);
1572+
};
1573+
1574+
llvm::stable_sort(Functions,
1575+
[Ascending, &Stats, DynoStatsComparator](
1576+
const BinaryFunction *A, const BinaryFunction *B) {
1577+
auto StatsItr = Stats.find(A);
1578+
assert(StatsItr != Stats.end());
1579+
const DynoStats &StatsA = StatsItr->second;
1580+
1581+
StatsItr = Stats.find(B);
1582+
assert(StatsItr != Stats.end());
1583+
const DynoStats &StatsB = StatsItr->second;
1584+
1585+
return Ascending ? DynoStatsComparator(StatsA, StatsB)
1586+
: DynoStatsComparator(StatsB, StatsA);
1587+
});
15831588

15841589
BC.outs() << "BOLT-INFO: top functions sorted by ";
15851590
if (SortAll) {

bolt/lib/Passes/CacheMetrics.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,20 @@ calcTSPScore(const std::vector<BinaryFunction *> &BinaryFunctions,
6767
for (BinaryBasicBlock *DstBB : SrcBB->successors()) {
6868
if (SrcBB != DstBB && BI->Count != BinaryBasicBlock::COUNT_NO_PROFILE) {
6969
JumpCount += BI->Count;
70-
if (BBAddr.at(SrcBB) + BBSize.at(SrcBB) == BBAddr.at(DstBB))
70+
71+
auto BBAddrIt = BBAddr.find(SrcBB);
72+
assert(BBAddrIt != BBAddr.end());
73+
uint64_t SrcBBAddr = BBAddrIt->second;
74+
75+
auto BBSizeIt = BBSize.find(SrcBB);
76+
assert(BBSizeIt != BBSize.end());
77+
uint64_t SrcBBSize = BBSizeIt->second;
78+
79+
BBAddrIt = BBAddr.find(DstBB);
80+
assert(BBAddrIt != BBAddr.end());
81+
uint64_t DstBBAddr = BBAddrIt->second;
82+
83+
if (SrcBBAddr + SrcBBSize == DstBBAddr)
7184
Score += BI->Count;
7285
}
7386
++BI;
@@ -149,29 +162,39 @@ double expectedCacheHitRatio(
149162
for (BinaryFunction *BF : BinaryFunctions) {
150163
if (BF->getLayout().block_empty())
151164
continue;
152-
const uint64_t Page =
153-
BBAddr.at(BF->getLayout().block_front()) / ITLBPageSize;
154-
PageSamples[Page] += FunctionSamples.at(BF);
165+
auto BBAddrIt = BBAddr.find(BF->getLayout().block_front());
166+
assert(BBAddrIt != BBAddr.end());
167+
const uint64_t Page = BBAddrIt->second / ITLBPageSize;
168+
169+
auto FunctionSamplesIt = FunctionSamples.find(BF);
170+
assert(FunctionSamplesIt != FunctionSamples.end());
171+
PageSamples[Page] += FunctionSamplesIt->second;
155172
}
156173

157174
// Computing the expected number of misses for every function
158175
double Misses = 0;
159176
for (BinaryFunction *BF : BinaryFunctions) {
160177
// Skip the function if it has no samples
161-
if (BF->getLayout().block_empty() || FunctionSamples.at(BF) == 0.0)
178+
auto FunctionSamplesIt = FunctionSamples.find(BF);
179+
assert(FunctionSamplesIt != FunctionSamples.end());
180+
double Samples = FunctionSamplesIt->second;
181+
if (BF->getLayout().block_empty() || Samples == 0.0)
162182
continue;
163-
double Samples = FunctionSamples.at(BF);
164-
const uint64_t Page =
165-
BBAddr.at(BF->getLayout().block_front()) / ITLBPageSize;
183+
184+
auto BBAddrIt = BBAddr.find(BF->getLayout().block_front());
185+
assert(BBAddrIt != BBAddr.end());
186+
const uint64_t Page = BBAddrIt->second / ITLBPageSize;
166187
// The probability that the page is not present in the cache
167188
const double MissProb =
168189
pow(1.0 - PageSamples[Page] / TotalSamples, ITLBEntries);
169190

170191
// Processing all callers of the function
171192
for (std::pair<BinaryFunction *, uint64_t> Pair : Calls[BF]) {
172193
BinaryFunction *SrcFunction = Pair.first;
173-
const uint64_t SrcPage =
174-
BBAddr.at(SrcFunction->getLayout().block_front()) / ITLBPageSize;
194+
195+
BBAddrIt = BBAddr.find(SrcFunction->getLayout().block_front());
196+
assert(BBAddrIt != BBAddr.end());
197+
const uint64_t SrcPage = BBAddrIt->second / ITLBPageSize;
175198
// Is this a 'long' or a 'short' call?
176199
if (Page != SrcPage) {
177200
// This is a miss

bolt/lib/Passes/Inliner.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ Inliner::inlineCall(BinaryBasicBlock &CallerBB,
355355
std::vector<BinaryBasicBlock *> Successors(BB.succ_size());
356356
llvm::transform(BB.successors(), Successors.begin(),
357357
[&InlinedBBMap](const BinaryBasicBlock *BB) {
358-
return InlinedBBMap.at(BB);
358+
auto It = InlinedBBMap.find(BB);
359+
assert(It != InlinedBBMap.end());
360+
return It->second;
359361
});
360362

361363
if (CallerFunction.hasValidProfile() && Callee.hasValidProfile())

0 commit comments

Comments
 (0)