Skip to content

Commit 4123fb3

Browse files
committed
fix conflicts
Signed-off-by: jinge90 <[email protected]>
2 parents 9b117ee + f4f83d9 commit 4123fb3

File tree

13,035 files changed

+632384
-883342
lines changed

Some content is hidden

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

13,035 files changed

+632384
-883342
lines changed

.github/workflows/sycl_linux_build_and_test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ jobs:
151151
cmake --build $GITHUB_WORKSPACE/build --target install-llvm-cov
152152
cmake --build $GITHUB_WORKSPACE/build --target install-llvm-profdata
153153
cmake --build $GITHUB_WORKSPACE/build --target install-compiler-rt
154-
# TODO this should be resolved in CMakeLists.txt
155-
cmake --build $GITHUB_WORKSPACE/build --target install-lld || echo "skipped"
156154
157155
- name: Pack toolchain
158156
run: tar -cJf llvm_sycl.tar.xz -C $GITHUB_WORKSPACE/build/install .

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/BinaryContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,14 @@ class BinaryContext {
498498
/// to function \p BF.
499499
std::string generateJumpTableName(const BinaryFunction &BF, uint64_t Address);
500500

501+
/// Free memory used by jump table offsets
502+
void clearJumpTableOffsets() {
503+
for (auto &JTI : JumpTables) {
504+
JumpTable &JT = *JTI.second;
505+
JumpTable::OffsetsType Temp;
506+
Temp.swap(JT.OffsetEntries);
507+
}
508+
}
501509
/// Return true if the array of bytes represents a valid code padding.
502510
bool hasValidCodePadding(const BinaryFunction &BF);
503511

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/Core/MCPlusBuilder.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,14 @@ class MCPlusBuilder {
10461046
/// Return handler and action info for invoke instruction if present.
10471047
Optional<MCPlus::MCLandingPad> getEHInfo(const MCInst &Inst) const;
10481048

1049-
// Add handler and action info for call instruction.
1049+
/// Add handler and action info for call instruction.
10501050
void addEHInfo(MCInst &Inst, const MCPlus::MCLandingPad &LP);
10511051

1052+
/// Update exception-handling info for the invoke instruction \p Inst.
1053+
/// Return true on success and false otherwise, e.g. if the instruction is
1054+
/// not an invoke.
1055+
bool updateEHInfo(MCInst &Inst, const MCPlus::MCLandingPad &LP);
1056+
10521057
/// Return non-negative GNU_args_size associated with the instruction
10531058
/// or -1 if there's no associated info.
10541059
int64_t getGnuArgsSize(const MCInst &Inst) const;

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: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +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;
30+
31+
/// Create trampoline landing pads for exception handling code to guarantee
32+
/// that every landing pad is placed in the same function fragment as the
33+
/// corresponding thrower block. The trampoline landing pad, when created,
34+
/// will redirect the execution to the real landing pad in a different
35+
/// fragment.
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;
3344

3445
std::atomic<uint64_t> SplitBytesHot{0ull};
3546
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: 48 additions & 42 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"
@@ -764,12 +763,31 @@ BinaryFunction *BinaryContext::createBinaryFunction(
764763
const MCSymbol *
765764
BinaryContext::getOrCreateJumpTable(BinaryFunction &Function, uint64_t Address,
766765
JumpTable::JumpTableType Type) {
766+
auto isFragmentOf = [](BinaryFunction *Fragment, BinaryFunction *Parent) {
767+
return (Fragment->isFragment() && Fragment->isParentFragment(Parent));
768+
};
769+
767770
if (JumpTable *JT = getJumpTableContainingAddress(Address)) {
768771
assert(JT->Type == Type && "jump table types have to match");
769-
assert(JT->Parent == &Function &&
772+
bool HasMultipleParents = isFragmentOf(JT->Parent, &Function) ||
773+
isFragmentOf(&Function, JT->Parent);
774+
assert((JT->Parent == &Function || HasMultipleParents) &&
770775
"cannot re-use jump table of a different function");
771776
assert(Address == JT->getAddress() && "unexpected non-empty jump table");
772777

778+
// Flush OffsetEntries with INVALID_OFFSET if multiple parents
779+
// Duplicate the entry for the parent function for easy access
780+
if (HasMultipleParents) {
781+
if (opts::Verbosity > 2) {
782+
outs() << "BOLT-WARNING: Multiple fragments access same jump table: "
783+
<< JT->Parent->getPrintName() << "; " << Function.getPrintName()
784+
<< "\n";
785+
}
786+
constexpr uint64_t INVALID_OFFSET = std::numeric_limits<uint64_t>::max();
787+
for (unsigned I = 0; I < JT->OffsetEntries.size(); ++I)
788+
JT->OffsetEntries[I] = INVALID_OFFSET;
789+
Function.JumpTables.emplace(Address, JT);
790+
}
773791
return JT->getFirstLabel();
774792
}
775793

@@ -1040,10 +1058,9 @@ void BinaryContext::generateSymbolHashes() {
10401058

10411059
// First check if a non-anonymous alias exists and move it to the front.
10421060
if (BD.getSymbols().size() > 1) {
1043-
auto Itr = std::find_if(BD.getSymbols().begin(), BD.getSymbols().end(),
1044-
[&](const MCSymbol *Symbol) {
1045-
return !isInternalSymbolName(Symbol->getName());
1046-
});
1061+
auto Itr = llvm::find_if(BD.getSymbols(), [&](const MCSymbol *Symbol) {
1062+
return !isInternalSymbolName(Symbol->getName());
1063+
});
10471064
if (Itr != BD.getSymbols().end()) {
10481065
size_t Idx = std::distance(BD.getSymbols().begin(), Itr);
10491066
std::swap(BD.getSymbols()[0], BD.getSymbols()[Idx]);
@@ -1205,8 +1222,7 @@ void BinaryContext::foldFunction(BinaryFunction &ChildBF,
12051222
ChildBF.getSymbols().clear();
12061223

12071224
// Move other names the child function is known under.
1208-
std::move(ChildBF.Aliases.begin(), ChildBF.Aliases.end(),
1209-
std::back_inserter(ParentBF.Aliases));
1225+
llvm::move(ChildBF.Aliases, std::back_inserter(ParentBF.Aliases));
12101226
ChildBF.Aliases.clear();
12111227

12121228
if (HasRelocations) {
@@ -1373,32 +1389,29 @@ unsigned BinaryContext::addDebugFilenameToUnit(const uint32_t DestCUID,
13731389

13741390
std::vector<BinaryFunction *> BinaryContext::getSortedFunctions() {
13751391
std::vector<BinaryFunction *> SortedFunctions(BinaryFunctions.size());
1376-
std::transform(BinaryFunctions.begin(), BinaryFunctions.end(),
1377-
SortedFunctions.begin(),
1378-
[](std::pair<const uint64_t, BinaryFunction> &BFI) {
1379-
return &BFI.second;
1380-
});
1381-
1382-
std::stable_sort(SortedFunctions.begin(), SortedFunctions.end(),
1383-
[](const BinaryFunction *A, const BinaryFunction *B) {
1384-
if (A->hasValidIndex() && B->hasValidIndex()) {
1385-
return A->getIndex() < B->getIndex();
1386-
}
1387-
return A->hasValidIndex();
1388-
});
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+
});
13891404
return SortedFunctions;
13901405
}
13911406

13921407
std::vector<BinaryFunction *> BinaryContext::getAllBinaryFunctions() {
13931408
std::vector<BinaryFunction *> AllFunctions;
13941409
AllFunctions.reserve(BinaryFunctions.size() + InjectedBinaryFunctions.size());
1395-
std::transform(BinaryFunctions.begin(), BinaryFunctions.end(),
1396-
std::back_inserter(AllFunctions),
1397-
[](std::pair<const uint64_t, BinaryFunction> &BFI) {
1398-
return &BFI.second;
1399-
});
1400-
std::copy(InjectedBinaryFunctions.begin(), InjectedBinaryFunctions.end(),
1401-
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));
14021415

14031416
return AllFunctions;
14041417
}
@@ -1471,21 +1484,15 @@ void BinaryContext::preprocessDebugInfo() {
14711484
ContainsDwarfLegacy |= CU->getVersion() < 5;
14721485
}
14731486

1474-
if (ContainsDwarf5 && ContainsDwarfLegacy)
1475-
llvm::errs() << "BOLT-WARNING: BOLT does not support mix mode binary with "
1476-
"DWARF5 and DWARF{2,3,4}.\n";
1477-
1478-
std::sort(AllRanges.begin(), AllRanges.end());
1487+
llvm::sort(AllRanges);
14791488
for (auto &KV : BinaryFunctions) {
14801489
const uint64_t FunctionAddress = KV.first;
14811490
BinaryFunction &Function = KV.second;
14821491

1483-
auto It = std::partition_point(
1484-
AllRanges.begin(), AllRanges.end(),
1485-
[=](CURange R) { return R.HighPC <= FunctionAddress; });
1486-
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)
14871495
Function.setDWARFUnit(It->Unit);
1488-
}
14891496
}
14901497

14911498
// Discover units with debug info that needs to be updated.
@@ -2199,8 +2206,7 @@ DebugAddressRangesVector BinaryContext::translateModuleAddressRanges(
21992206
break;
22002207
const DebugAddressRangesVector FunctionRanges =
22012208
Function.getOutputAddressRanges();
2202-
std::move(std::begin(FunctionRanges), std::end(FunctionRanges),
2203-
std::back_inserter(OutputRanges));
2209+
llvm::move(FunctionRanges, std::back_inserter(OutputRanges));
22042210
std::advance(BFI, 1);
22052211
}
22062212
}

0 commit comments

Comments
 (0)