Skip to content

Commit 9016d84

Browse files
committed
Merge commit '25b5e5c4e9a39a86ca3c1a05ad6eae33771ab052' into cast_cmp
2 parents 7483e99 + 25b5e5c commit 9016d84

File tree

1,105 files changed

+61742
-32013
lines changed

Some content is hidden

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

1,105 files changed

+61742
-32013
lines changed

.github/workflows/release-binaries.yml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,52 @@ jobs:
5757
fi
5858
bash .github/workflows/set-release-binary-outputs.sh "${{ github.actor }}" "$tag" "$upload"
5959
60+
# Try to get around the 6 hour timeout by first running a job to fill
61+
# the build cache.
62+
fill-cache:
63+
name: "Fill Cache ${{ matrix.os }}"
64+
needs: prepare
65+
runs-on: ${{ matrix.os }}
66+
strategy:
67+
matrix:
68+
os:
69+
- ubuntu-22.04
70+
steps:
71+
- name: Checkout LLVM
72+
uses: actions/checkout@v4
73+
with:
74+
ref: ${{ inputs.tag || github.ref_name }}
75+
76+
- name: Install Ninja
77+
uses: llvm/actions/install-ninja@main
78+
79+
- name: Setup sccache
80+
uses: hendrikmuhs/ccache-action@v1
81+
with:
82+
max-size: 250M
83+
key: sccache-${{ matrix.os }}-release
84+
variant: sccache
85+
86+
- name: Build Clang
87+
run: |
88+
cmake -G Ninja -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_BUILD_TYPE=Release -DCMAKE_ENABLE_ASSERTIONS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DLLVM_ENABLE_PROJECTS=clang -S llvm -B build
89+
ninja -v -C build
90+
91+
6092
build-binaries:
6193
name: ${{ matrix.target.triple }}
6294
permissions:
6395
contents: write # To upload assets to release.
64-
needs: prepare
96+
needs:
97+
- prepare
98+
- fill-cache
6599
runs-on: ${{ matrix.target.runs-on }}
66100
strategy:
67101
fail-fast: false
68102
matrix:
69103
target:
70104
- triple: x86_64-linux-gnu-ubuntu-22.04
105+
os: ubuntu-22.04
71106
runs-on: ubuntu-22.04-16x64
72107
debian-build-deps: >
73108
chrpath
@@ -81,6 +116,14 @@ jobs:
81116
ref: ${{ needs.prepare.outputs.ref }}
82117
path: ${{ needs.prepare.outputs.build-dir }}/llvm-project
83118

119+
- name: Setup sccache
120+
uses: hendrikmuhs/ccache-action@v1
121+
with:
122+
max-size: 250M
123+
key: sccache-${{ matrix.target.os }}-release
124+
save: false
125+
variant: sccache
126+
84127
- name: Install Brew build dependencies
85128
if: matrix.target.brew-build-deps != ''
86129
run: brew install ${{ matrix.target.brew-build-deps }}
@@ -102,7 +145,8 @@ jobs:
102145
-triple ${{ matrix.target.triple }} \
103146
-use-ninja \
104147
-no-checkout \
105-
-no-test-suite
148+
-no-test-suite \
149+
-configure-flags "-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
106150
107151
- name: Upload binaries
108152
if: ${{ always() && needs.prepare.outputs.upload == 'true' }}

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,9 @@ class BinaryContext {
12301230
///
12311231
/// Return the pair where the first size is for the main part, and the second
12321232
/// size is for the cold one.
1233+
/// Modify BinaryBasicBlock::OutputAddressRange for each basic block in the
1234+
/// function in place so that BinaryBasicBlock::getOutputSize() gives the
1235+
/// emitted size of the basic block.
12331236
std::pair<size_t, size_t> calculateEmittedSize(BinaryFunction &BF,
12341237
bool FixBranches = true);
12351238

@@ -1290,6 +1293,9 @@ class BinaryContext {
12901293
/// Return true if the function should be emitted to the output file.
12911294
bool shouldEmit(const BinaryFunction &Function) const;
12921295

1296+
/// Dump the assembly representation of MCInst to debug output.
1297+
void dump(const MCInst &Inst) const;
1298+
12931299
/// Print the string name for a CFI operation.
12941300
static void printCFI(raw_ostream &OS, const MCCFIInstruction &Inst);
12951301

bolt/lib/Core/BinaryContext.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,15 @@ bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {
17381738
return HasRelocations || Function.isSimple();
17391739
}
17401740

1741+
void BinaryContext::dump(const MCInst &Inst) const {
1742+
if (LLVM_UNLIKELY(!InstPrinter)) {
1743+
dbgs() << "Cannot dump for InstPrinter is not initialized.\n";
1744+
return;
1745+
}
1746+
InstPrinter->printInst(&Inst, 0, "", *STI, dbgs());
1747+
dbgs() << "\n";
1748+
}
1749+
17411750
void BinaryContext::printCFI(raw_ostream &OS, const MCCFIInstruction &Inst) {
17421751
uint32_t Operation = Inst.getOperation();
17431752
switch (Operation) {
@@ -2322,14 +2331,36 @@ BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) {
23222331
MCAsmLayout Layout(Assembler);
23232332
Assembler.layout(Layout);
23242333

2334+
// Obtain fragment sizes.
2335+
std::vector<uint64_t> FragmentSizes;
2336+
// Main fragment size.
23252337
const uint64_t HotSize =
23262338
Layout.getSymbolOffset(*EndLabel) - Layout.getSymbolOffset(*StartLabel);
2327-
const uint64_t ColdSize =
2328-
std::accumulate(SplitLabels.begin(), SplitLabels.end(), 0ULL,
2329-
[&](const uint64_t Accu, const LabelRange &Labels) {
2330-
return Accu + Layout.getSymbolOffset(*Labels.second) -
2331-
Layout.getSymbolOffset(*Labels.first);
2332-
});
2339+
FragmentSizes.push_back(HotSize);
2340+
// Split fragment sizes.
2341+
uint64_t ColdSize = 0;
2342+
for (const auto &Labels : SplitLabels) {
2343+
uint64_t Size = Layout.getSymbolOffset(*Labels.second) -
2344+
Layout.getSymbolOffset(*Labels.first);
2345+
FragmentSizes.push_back(Size);
2346+
ColdSize += Size;
2347+
}
2348+
2349+
// Populate new start and end offsets of each basic block.
2350+
uint64_t FragmentIndex = 0;
2351+
for (FunctionFragment &FF : BF.getLayout().fragments()) {
2352+
BinaryBasicBlock *PrevBB = nullptr;
2353+
for (BinaryBasicBlock *BB : FF) {
2354+
const uint64_t BBStartOffset = Layout.getSymbolOffset(*(BB->getLabel()));
2355+
BB->setOutputStartAddress(BBStartOffset);
2356+
if (PrevBB)
2357+
PrevBB->setOutputEndAddress(BBStartOffset);
2358+
PrevBB = BB;
2359+
}
2360+
if (PrevBB)
2361+
PrevBB->setOutputEndAddress(FragmentSizes[FragmentIndex]);
2362+
FragmentIndex++;
2363+
}
23332364

23342365
// Clean-up the effect of the code emission.
23352366
for (const MCSymbol &Symbol : Assembler.symbols()) {

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ cl::opt<bool>
108108
cl::desc("try to preserve basic block alignment"),
109109
cl::cat(BoltOptCategory));
110110

111+
static cl::opt<bool> PrintOutputAddressRange(
112+
"print-output-address-range",
113+
cl::desc(
114+
"print output address range for each basic block in the function when"
115+
"BinaryFunction::print is called"),
116+
cl::Hidden, cl::cat(BoltOptCategory));
117+
111118
cl::opt<bool>
112119
PrintDynoStats("dyno-stats",
113120
cl::desc("print execution info based on profile"),
@@ -510,6 +517,11 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
510517
OS << BB->getName() << " (" << BB->size()
511518
<< " instructions, align : " << BB->getAlignment() << ")\n";
512519

520+
if (opts::PrintOutputAddressRange)
521+
OS << formatv(" Output Address Range: [{0:x}, {1:x}) ({2} bytes)\n",
522+
BB->getOutputAddressRange().first,
523+
BB->getOutputAddressRange().second, BB->getOutputSize());
524+
513525
if (isEntryPoint(*BB)) {
514526
if (MCSymbol *EntrySymbol = getSecondaryEntryPointSymbol(*BB))
515527
OS << " Secondary Entry Point: " << EntrySymbol->getName() << '\n';

bolt/lib/Core/Exceptions.cpp

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,18 @@ void BinaryFunction::parseLSDA(ArrayRef<uint8_t> LSDASectionData,
112112
uint64_t Offset = getLSDAAddress() - LSDASectionAddress;
113113
assert(Data.isValidOffset(Offset) && "wrong LSDA address");
114114

115-
uint8_t LPStartEncoding = Data.getU8(&Offset);
116-
uint64_t LPStart = 0;
117-
// Convert to offset if LPStartEncoding is typed absptr DW_EH_PE_absptr
118-
if (std::optional<uint64_t> MaybeLPStart = Data.getEncodedPointer(
119-
&Offset, LPStartEncoding, Offset + LSDASectionAddress))
120-
LPStart = (LPStartEncoding && 0xFF == 0) ? *MaybeLPStart
121-
: *MaybeLPStart - Address;
115+
const uint8_t LPStartEncoding = Data.getU8(&Offset);
116+
uint64_t LPStart = Address;
117+
if (LPStartEncoding != dwarf::DW_EH_PE_omit) {
118+
std::optional<uint64_t> MaybeLPStart = Data.getEncodedPointer(
119+
&Offset, LPStartEncoding, Offset + LSDASectionAddress);
120+
if (!MaybeLPStart) {
121+
errs() << "BOLT-ERROR: unsupported LPStartEncoding: "
122+
<< (unsigned)LPStartEncoding << '\n';
123+
exit(1);
124+
}
125+
LPStart = *MaybeLPStart;
126+
}
122127

123128
const uint8_t TTypeEncoding = Data.getU8(&Offset);
124129
LSDATypeEncoding = TTypeEncoding;
@@ -175,38 +180,38 @@ void BinaryFunction::parseLSDA(ArrayRef<uint8_t> LSDASectionData,
175180
uint64_t LandingPad = *Data.getEncodedPointer(
176181
&CallSitePtr, CallSiteEncoding, CallSitePtr + LSDASectionAddress);
177182
uint64_t ActionEntry = Data.getULEB128(&CallSitePtr);
178-
179-
uint64_t LPOffset = LPStart + LandingPad;
180-
uint64_t LPAddress = Address + LPOffset;
181-
182-
// Verify if landing pad code is located outside current function
183-
// Support landing pad to builtin_unreachable
184-
if (LPAddress < Address || LPAddress > Address + getSize()) {
185-
BinaryFunction *Fragment =
186-
BC.getBinaryFunctionContainingAddress(LPAddress);
187-
assert(Fragment != nullptr &&
188-
"BOLT-ERROR: cannot find landing pad fragment");
189-
BC.addInterproceduralReference(this, Fragment->getAddress());
190-
BC.processInterproceduralReferences();
191-
assert(isParentOrChildOf(*Fragment) &&
192-
"BOLT-ERROR: cannot have landing pads in different functions");
193-
setHasIndirectTargetToSplitFragment(true);
194-
BC.addFragmentsToSkip(this);
195-
return;
196-
}
183+
if (LandingPad)
184+
LandingPad += LPStart;
197185

198186
if (opts::PrintExceptions) {
199187
outs() << "Call Site: [0x" << Twine::utohexstr(RangeBase + Start)
200188
<< ", 0x" << Twine::utohexstr(RangeBase + Start + Length)
201-
<< "); landing pad: 0x" << Twine::utohexstr(LPOffset)
189+
<< "); landing pad: 0x" << Twine::utohexstr(LandingPad)
202190
<< "; action entry: 0x" << Twine::utohexstr(ActionEntry) << "\n";
203191
outs() << " current offset is " << (CallSitePtr - CallSiteTableStart)
204192
<< '\n';
205193
}
206194

207195
// Create a handler entry if necessary.
208196
MCSymbol *LPSymbol = nullptr;
209-
if (LPOffset) {
197+
if (LandingPad) {
198+
// Verify if landing pad code is located outside current function
199+
// Support landing pad to builtin_unreachable
200+
if (LandingPad < Address || LandingPad > Address + getSize()) {
201+
BinaryFunction *Fragment =
202+
BC.getBinaryFunctionContainingAddress(LandingPad);
203+
assert(Fragment != nullptr &&
204+
"BOLT-ERROR: cannot find landing pad fragment");
205+
BC.addInterproceduralReference(this, Fragment->getAddress());
206+
BC.processInterproceduralReferences();
207+
assert(isParentOrChildOf(*Fragment) &&
208+
"BOLT-ERROR: cannot have landing pads in different functions");
209+
setHasIndirectTargetToSplitFragment(true);
210+
BC.addFragmentsToSkip(this);
211+
return;
212+
}
213+
214+
const uint64_t LPOffset = LandingPad - getAddress();
210215
if (!getInstructionAtOffset(LPOffset)) {
211216
if (opts::Verbosity >= 1)
212217
errs() << "BOLT-WARNING: landing pad " << Twine::utohexstr(LPOffset)

bolt/lib/Passes/ValidateInternalCalls.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,16 @@ bool ValidateInternalCalls::analyzeFunction(BinaryFunction &Function) const {
281281
LLVM_DEBUG({
282282
dbgs() << "Detected out-of-range PIC reference in " << Function
283283
<< "\nReturn address load: ";
284-
BC.InstPrinter->printInst(TargetInst, 0, "", *BC.STI, dbgs());
285-
dbgs() << "\nUse: ";
286-
BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
287-
dbgs() << "\n";
284+
BC.dump(*TargetInst);
285+
dbgs() << "Use: ";
286+
BC.dump(Use);
288287
Function.dump();
289288
});
290289
return false;
291290
}
292291
LLVM_DEBUG({
293292
dbgs() << "Validated access: ";
294-
BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
295-
dbgs() << "\n";
293+
BC.dump(Use);
296294
});
297295
}
298296
if (!UseDetected) {

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static llvm::cl::opt<bool>
3131
llvm::cl::opt<bool> ProfileUseDFS("profile-use-dfs",
3232
cl::desc("use DFS order for YAML profile"),
3333
cl::Hidden, cl::cat(BoltOptCategory));
34-
}
34+
} // namespace opts
3535

3636
namespace llvm {
3737
namespace bolt {
@@ -354,7 +354,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
354354
matchProfileToFunction(YamlBF, Function);
355355
}
356356

357-
for (auto &[CommonName, LTOProfiles]: LTOCommonNameMap) {
357+
for (const auto &[CommonName, LTOProfiles] : LTOCommonNameMap) {
358358
if (!LTOCommonNameFunctionMap.contains(CommonName))
359359
continue;
360360
std::unordered_set<BinaryFunction *> &Functions =

0 commit comments

Comments
 (0)