Skip to content

Commit 3cbd819

Browse files
Merge remote-tracking branch 'origin/sycl' into move-includes
2 parents e6cc0fb + 25c34bf commit 3cbd819

File tree

6,361 files changed

+386432
-714521
lines changed

Some content is hidden

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

6,361 files changed

+386432
-714521
lines changed

bolt/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Once you have `perf.fdata` ready, you can use it for optimizations with
180180
BOLT. Assuming your environment is setup to include the right path, execute
181181
`llvm-bolt`:
182182
```
183-
$ llvm-bolt <executable> -o <executable>.bolt -data=perf.fdata -reorder-blocks=ext-tsp -reorder-functions=hfsort -split-functions=2 -split-all-cold -split-eh -dyno-stats
183+
$ llvm-bolt <executable> -o <executable>.bolt -data=perf.fdata -reorder-blocks=ext-tsp -reorder-functions=hfsort -split-functions -split-all-cold -split-eh -dyno-stats
184184
```
185185

186186
If you do need an updated debug info, then add `-update-debug-sections` option

bolt/docs/OptimizingClang.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Notice that we are passing `clang-7` to `perf2bolt` which is the real binary tha
6464
the generated profile:
6565
```bash
6666
$ llvm-bolt $CPATH/clang-7 -o $CPATH/clang-7.bolt -b clang-7.yaml \
67-
-reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions=3 \
67+
-reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions \
6868
-split-all-cold -dyno-stats -icf=1 -use-gnu-stack
6969
```
7070
The output will look similar to the one below:

bolt/include/bolt/Core/BinaryBasicBlock.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,12 @@ class BinaryBasicBlock {
634634

635635
/// Test if BB is a predecessor of this block.
636636
bool isPredecessor(const BinaryBasicBlock *BB) const {
637-
auto Itr = std::find(Predecessors.begin(), Predecessors.end(), BB);
638-
return Itr != Predecessors.end();
637+
return llvm::is_contained(Predecessors, BB);
639638
}
640639

641640
/// Test if BB is a successor of this block.
642641
bool isSuccessor(const BinaryBasicBlock *BB) const {
643-
auto Itr = std::find(Successors.begin(), Successors.end(), BB);
644-
return Itr != Successors.end();
642+
return llvm::is_contained(Successors, BB);
645643
}
646644

647645
/// Test if this BB has a valid execution count.

bolt/include/bolt/Core/BinaryData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class BinaryData {
112112
bool nameStartsWith(StringRef Prefix) const;
113113

114114
bool hasSymbol(const MCSymbol *Symbol) const {
115-
return std::find(Symbols.begin(), Symbols.end(), Symbol) != Symbols.end();
115+
return llvm::is_contained(Symbols, Symbol);
116116
}
117117

118118
bool isAbsolute() const;

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,8 @@ class BinaryFunction {
716716
BB->setOffset(Offset);
717717

718718
BasicBlockOffsets.emplace_back(Offset, BB);
719-
assert(std::is_sorted(BasicBlockOffsets.begin(), BasicBlockOffsets.end(),
720-
CompareBasicBlockOffsets()) &&
721-
std::is_sorted(begin(), end()));
719+
assert(llvm::is_sorted(BasicBlockOffsets, CompareBasicBlockOffsets()) &&
720+
llvm::is_sorted(blocks()));
722721

723722
return BB;
724723
}
@@ -888,8 +887,9 @@ class BinaryFunction {
888887

889888
/// Update layout of basic blocks used for output.
890889
void updateBasicBlockLayout(BasicBlockOrderType &NewLayout) {
891-
BasicBlocksPreviousLayout = BasicBlocksLayout;
890+
assert(NewLayout.size() == BasicBlocks.size() && "Layout size mismatch.");
892891

892+
BasicBlocksPreviousLayout = BasicBlocksLayout;
893893
if (NewLayout != BasicBlocksLayout) {
894894
ModifiedLayout = true;
895895
BasicBlocksLayout.clear();

bolt/include/bolt/Core/DynoStats.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ DynoStats getDynoStats(const BinaryFunction &BF);
146146

147147
/// Return program-wide dynostats.
148148
template <typename FuncsType>
149-
inline DynoStats getDynoStats(const FuncsType &Funcs) {
150-
bool IsAArch64 = Funcs.begin()->second.getBinaryContext().isAArch64();
149+
inline DynoStats getDynoStats(const FuncsType &Funcs, bool IsAArch64) {
151150
DynoStats dynoStats(IsAArch64);
152151
for (auto &BFI : Funcs) {
153152
auto &BF = BFI.second;
@@ -160,16 +159,16 @@ inline DynoStats getDynoStats(const FuncsType &Funcs) {
160159
/// Call a function with optional before and after dynostats printing.
161160
template <typename FnType, typename FuncsType>
162161
inline void callWithDynoStats(FnType &&Func, const FuncsType &Funcs,
163-
StringRef Phase, const bool Flag) {
164-
bool IsAArch64 = Funcs.begin()->second.getBinaryContext().isAArch64();
162+
StringRef Phase, const bool Flag,
163+
bool IsAArch64) {
165164
DynoStats DynoStatsBefore(IsAArch64);
166165
if (Flag)
167-
DynoStatsBefore = getDynoStats(Funcs);
166+
DynoStatsBefore = getDynoStats(Funcs, IsAArch64);
168167

169168
Func();
170169

171170
if (Flag) {
172-
const DynoStats DynoStatsAfter = getDynoStats(Funcs);
171+
const DynoStats DynoStatsAfter = getDynoStats(Funcs, IsAArch64);
173172
const bool Changed = (DynoStatsAfter != DynoStatsBefore);
174173
outs() << "BOLT-INFO: program-wide dynostats after running " << Phase
175174
<< (Changed ? "" : " (no change)") << ":\n\n"

bolt/include/bolt/Passes/BinaryPasses.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class DynoStatsPrintPass : public BinaryFunctionPass {
7171
bool shouldPrint(const BinaryFunction &BF) const override { return false; }
7272

7373
void runOnFunctions(BinaryContext &BC) override {
74-
const DynoStats NewDynoStats = getDynoStats(BC.getBinaryFunctions());
74+
const DynoStats NewDynoStats =
75+
getDynoStats(BC.getBinaryFunctions(), BC.isAArch64());
7576
const bool Changed = (NewDynoStats != PrevDynoStats);
7677
outs() << "BOLT-INFO: program-wide dynostats " << Title
7778
<< (Changed ? "" : " (no change)") << ":\n\n"

bolt/include/bolt/Passes/SplitFunctions.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,29 @@ namespace bolt {
1818

1919
/// Split function code in multiple parts.
2020
class SplitFunctions : public BinaryFunctionPass {
21-
public:
22-
/// Settings for splitting function bodies into hot/cold partitions.
23-
enum SplittingType : char {
24-
ST_NONE = 0, /// Do not split functions.
25-
ST_LARGE, /// In non-relocation mode, only split functions that
26-
/// are too large to fit into the original space.
27-
ST_ALL, /// Split all functions.
28-
};
29-
3021
private:
3122
/// Split function body into fragments.
32-
void splitFunction(BinaryFunction &Function);
23+
template <typename SplitStrategy>
24+
void splitFunction(BinaryFunction &Function, SplitStrategy Strategy = {});
25+
26+
/// Map basic block labels to their trampoline block labels.
27+
using TrampolineSetType = DenseMap<const MCSymbol *, const MCSymbol *>;
28+
29+
using BasicBlockOrderType = BinaryFunction::BasicBlockOrderType;
3330

3431
/// Create trampoline landing pads for exception handling code to guarantee
3532
/// that every landing pad is placed in the same function fragment as the
3633
/// corresponding thrower block. The trampoline landing pad, when created,
3734
/// will redirect the execution to the real landing pad in a different
3835
/// fragment.
39-
void createEHTrampolines(BinaryFunction &Function) const;
36+
TrampolineSetType createEHTrampolines(BinaryFunction &Function) const;
37+
38+
/// Merge trampolines into \p Layout without trampolines. The merge will place
39+
/// a trampoline immediately before its destination. Used to revert the effect
40+
/// of trampolines after createEHTrampolines().
41+
BasicBlockOrderType
42+
mergeEHTrampolines(BinaryFunction &BF, BasicBlockOrderType &Layout,
43+
const TrampolineSetType &Trampolines) const;
4044

4145
std::atomic<uint64_t> SplitBytesHot{0ull};
4246
std::atomic<uint64_t> SplitBytesCold{0ull};

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ class DWARFRewriter {
3838

3939
/// Stores and serializes information that will be put into the
4040
/// .debug_ranges DWARF section.
41-
std::unique_ptr<DebugRangesSectionWriter> RangesSectionWriter;
41+
std::unique_ptr<DebugRangesSectionWriter> LegacyRangesSectionWriter;
42+
43+
/// Stores and serializes information that will be put into the
44+
/// .debug_rnglists DWARF section.
45+
std::unique_ptr<DebugRangeListsSectionWriter> RangeListsSectionWriter;
4246

4347
/// Stores and serializes information that will be put into the
4448
/// .debug_aranges DWARF section.

bolt/lib/Core/BinaryBasicBlock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ BinaryBasicBlock::getBranchStats(const BinaryBasicBlock *Succ) const {
544544
}
545545

546546
if (TotalCount > 0) {
547-
auto Itr = std::find(Successors.begin(), Successors.end(), Succ);
547+
auto Itr = llvm::find(Successors, Succ);
548548
assert(Itr != Successors.end());
549549
const BinaryBranchInfo &BI = BranchInfo[Itr - Successors.begin()];
550550
if (BI.Count && BI.Count != COUNT_NO_PROFILE) {

bolt/lib/Core/BinaryContext.cpp

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,8 @@ void BinaryContext::skipMarkedFragments() {
718718
BF->setSimple(false);
719719
BF->setHasSplitJumpTable(true);
720720

721-
std::for_each(BF->Fragments.begin(), BF->Fragments.end(), addToWorklist);
722-
std::for_each(BF->ParentFragments.begin(), BF->ParentFragments.end(),
723-
addToWorklist);
721+
llvm::for_each(BF->Fragments, addToWorklist);
722+
llvm::for_each(BF->ParentFragments, addToWorklist);
724723
}
725724
if (!FragmentsToSkip.empty())
726725
errs() << "BOLT-WARNING: skipped " << FragmentsToSkip.size() << " function"
@@ -1059,10 +1058,9 @@ void BinaryContext::generateSymbolHashes() {
10591058

10601059
// First check if a non-anonymous alias exists and move it to the front.
10611060
if (BD.getSymbols().size() > 1) {
1062-
auto Itr = std::find_if(BD.getSymbols().begin(), BD.getSymbols().end(),
1063-
[&](const MCSymbol *Symbol) {
1064-
return !isInternalSymbolName(Symbol->getName());
1065-
});
1061+
auto Itr = llvm::find_if(BD.getSymbols(), [&](const MCSymbol *Symbol) {
1062+
return !isInternalSymbolName(Symbol->getName());
1063+
});
10661064
if (Itr != BD.getSymbols().end()) {
10671065
size_t Idx = std::distance(BD.getSymbols().begin(), Itr);
10681066
std::swap(BD.getSymbols()[0], BD.getSymbols()[Idx]);
@@ -1224,8 +1222,7 @@ void BinaryContext::foldFunction(BinaryFunction &ChildBF,
12241222
ChildBF.getSymbols().clear();
12251223

12261224
// Move other names the child function is known under.
1227-
std::move(ChildBF.Aliases.begin(), ChildBF.Aliases.end(),
1228-
std::back_inserter(ParentBF.Aliases));
1225+
llvm::move(ChildBF.Aliases, std::back_inserter(ParentBF.Aliases));
12291226
ChildBF.Aliases.clear();
12301227

12311228
if (HasRelocations) {
@@ -1392,32 +1389,29 @@ unsigned BinaryContext::addDebugFilenameToUnit(const uint32_t DestCUID,
13921389

13931390
std::vector<BinaryFunction *> BinaryContext::getSortedFunctions() {
13941391
std::vector<BinaryFunction *> SortedFunctions(BinaryFunctions.size());
1395-
std::transform(BinaryFunctions.begin(), BinaryFunctions.end(),
1396-
SortedFunctions.begin(),
1397-
[](std::pair<const uint64_t, BinaryFunction> &BFI) {
1398-
return &BFI.second;
1399-
});
1400-
1401-
std::stable_sort(SortedFunctions.begin(), SortedFunctions.end(),
1402-
[](const BinaryFunction *A, const BinaryFunction *B) {
1403-
if (A->hasValidIndex() && B->hasValidIndex()) {
1404-
return A->getIndex() < B->getIndex();
1405-
}
1406-
return A->hasValidIndex();
1407-
});
1392+
llvm::transform(BinaryFunctions, SortedFunctions.begin(),
1393+
[](std::pair<const uint64_t, BinaryFunction> &BFI) {
1394+
return &BFI.second;
1395+
});
1396+
1397+
llvm::stable_sort(SortedFunctions,
1398+
[](const BinaryFunction *A, const BinaryFunction *B) {
1399+
if (A->hasValidIndex() && B->hasValidIndex()) {
1400+
return A->getIndex() < B->getIndex();
1401+
}
1402+
return A->hasValidIndex();
1403+
});
14081404
return SortedFunctions;
14091405
}
14101406

14111407
std::vector<BinaryFunction *> BinaryContext::getAllBinaryFunctions() {
14121408
std::vector<BinaryFunction *> AllFunctions;
14131409
AllFunctions.reserve(BinaryFunctions.size() + InjectedBinaryFunctions.size());
1414-
std::transform(BinaryFunctions.begin(), BinaryFunctions.end(),
1415-
std::back_inserter(AllFunctions),
1416-
[](std::pair<const uint64_t, BinaryFunction> &BFI) {
1417-
return &BFI.second;
1418-
});
1419-
std::copy(InjectedBinaryFunctions.begin(), InjectedBinaryFunctions.end(),
1420-
std::back_inserter(AllFunctions));
1410+
llvm::transform(BinaryFunctions, std::back_inserter(AllFunctions),
1411+
[](std::pair<const uint64_t, BinaryFunction> &BFI) {
1412+
return &BFI.second;
1413+
});
1414+
llvm::copy(InjectedBinaryFunctions, std::back_inserter(AllFunctions));
14211415

14221416
return AllFunctions;
14231417
}
@@ -1490,21 +1484,15 @@ void BinaryContext::preprocessDebugInfo() {
14901484
ContainsDwarfLegacy |= CU->getVersion() < 5;
14911485
}
14921486

1493-
if (ContainsDwarf5 && ContainsDwarfLegacy)
1494-
llvm::errs() << "BOLT-WARNING: BOLT does not support mix mode binary with "
1495-
"DWARF5 and DWARF{2,3,4}.\n";
1496-
1497-
std::sort(AllRanges.begin(), AllRanges.end());
1487+
llvm::sort(AllRanges);
14981488
for (auto &KV : BinaryFunctions) {
14991489
const uint64_t FunctionAddress = KV.first;
15001490
BinaryFunction &Function = KV.second;
15011491

1502-
auto It = std::partition_point(
1503-
AllRanges.begin(), AllRanges.end(),
1504-
[=](CURange R) { return R.HighPC <= FunctionAddress; });
1505-
if (It != AllRanges.end() && It->LowPC <= FunctionAddress) {
1492+
auto It = llvm::partition_point(
1493+
AllRanges, [=](CURange R) { return R.HighPC <= FunctionAddress; });
1494+
if (It != AllRanges.end() && It->LowPC <= FunctionAddress)
15061495
Function.setDWARFUnit(It->Unit);
1507-
}
15081496
}
15091497

15101498
// Discover units with debug info that needs to be updated.
@@ -2218,8 +2206,7 @@ DebugAddressRangesVector BinaryContext::translateModuleAddressRanges(
22182206
break;
22192207
const DebugAddressRangesVector FunctionRanges =
22202208
Function.getOutputAddressRanges();
2221-
std::move(std::begin(FunctionRanges), std::end(FunctionRanges),
2222-
std::back_inserter(OutputRanges));
2209+
llvm::move(FunctionRanges, std::back_inserter(OutputRanges));
22232210
std::advance(BFI, 1);
22242211
}
22252212
}

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) {
333333
// Only write CIE CFI insns that LLVM will not already emit
334334
const std::vector<MCCFIInstruction> &FrameInstrs =
335335
MAI->getInitialFrameState();
336-
if (std::find(FrameInstrs.begin(), FrameInstrs.end(), CFIInstr) ==
337-
FrameInstrs.end())
336+
if (!llvm::is_contained(FrameInstrs, CFIInstr))
338337
emitCFIInstruction(CFIInstr);
339338
}
340339
}
@@ -1087,7 +1086,7 @@ void BinaryEmitter::emitDebugLineInfoForUnprocessedCUs() {
10871086

10881087
StmtListOffsets.push_back(*StmtList);
10891088
}
1090-
std::sort(StmtListOffsets.begin(), StmtListOffsets.end());
1089+
llvm::sort(StmtListOffsets);
10911090

10921091
// For each CU that was not processed, emit its line info as a binary blob.
10931092
for (const std::unique_ptr<DWARFUnit> &CU : BC.DwCtx->compile_units()) {
@@ -1105,8 +1104,7 @@ void BinaryEmitter::emitDebugLineInfoForUnprocessedCUs() {
11051104

11061105
// Statement list ends where the next unit contribution begins, or at the
11071106
// end of the section.
1108-
auto It =
1109-
std::upper_bound(StmtListOffsets.begin(), StmtListOffsets.end(), Begin);
1107+
auto It = llvm::upper_bound(StmtListOffsets, Begin);
11101108
const uint64_t End =
11111109
It == StmtListOffsets.end() ? DebugLineContents.size() : *It;
11121110

0 commit comments

Comments
 (0)