Skip to content

Commit caaad39

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW48)
LLVM: llvm/llvm-project@225648e SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@3770469
2 parents ea6a3a3 + 522cefd commit caaad39

File tree

2,749 files changed

+112029
-79792
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,749 files changed

+112029
-79792
lines changed

.ci/monolithic-linux.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ cmake -S ${MONOREPO_ROOT}/llvm -B ${BUILD_DIR} \
4949
-D LLVM_ENABLE_LLD=ON \
5050
-D CMAKE_CXX_FLAGS=-gmlt \
5151
-D BOLT_CLANG_EXE=/usr/bin/clang \
52-
-D LLVM_CCACHE_BUILD=ON
52+
-D LLVM_CCACHE_BUILD=ON \
53+
-D MLIR_ENABLE_BINDINGS_PYTHON=ON
5354

5455
echo "--- ninja"
5556
# Targets are not escaped as they are passed as separate arguments.

.ci/monolithic-windows.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ cmake -S ${MONOREPO_ROOT}/llvm -B ${BUILD_DIR} \
4848
-D LLVM_LIT_ARGS="-v --xunit-xml-output ${BUILD_DIR}/test-results.xml" \
4949
-D COMPILER_RT_BUILD_ORC=OFF \
5050
-D CMAKE_C_COMPILER_LAUNCHER=sccache \
51-
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache
51+
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache \
52+
-D MLIR_ENABLE_BINDINGS_PYTHON=ON
5253

5354
echo "--- ninja"
5455
# Targets are not escaped as they are passed as separate arguments.

.github/workflows/docs.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
paths:
1616
- 'llvm/docs/**'
1717
- 'clang/docs/**'
18+
- 'clang/include/clang/Basic/AttrDocs.td'
19+
- 'clang/include/clang/Driver/ClangOptionDocs.td'
20+
- 'clang/include/clang/Basic/DiagnosticDocs.td'
1821
- 'clang-tools-extra/docs/**'
1922
- 'lldb/docs/**'
2023
- 'libunwind/docs/**'
@@ -29,6 +32,9 @@ on:
2932
paths:
3033
- 'llvm/docs/**'
3134
- 'clang/docs/**'
35+
- 'clang/include/clang/Basic/AttrDocs.td'
36+
- 'clang/include/clang/Driver/ClangOptionDocs.td'
37+
- 'clang/include/clang/Basic/DiagnosticDocs.td'
3238
- 'clang-tools-extra/docs/**'
3339
- 'lldb/docs/**'
3440
- 'libunwind/docs/**'
@@ -64,6 +70,9 @@ jobs:
6470
- 'llvm/docs/**'
6571
clang:
6672
- 'clang/docs/**'
73+
- 'clang/include/clang/Basic/AttrDocs.td'
74+
- 'clang/include/clang/Driver/ClangOptionDocs.td'
75+
- 'clang/include/clang/Basic/DiagnosticDocs.td'
6776
clang-tools-extra:
6877
- 'clang-tools-extra/docs/**'
6978
lldb:

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ on:
2222
- 'runtimes/**'
2323
- 'cmake/**'
2424
- '.github/workflows/libcxx-build-and-test.yaml'
25+
schedule:
26+
# Run nightly at 8 AM UTC (or roughly 3 AM eastern)
27+
- cron: '0 3 * * *'
28+
29+
permissions:
30+
contents: read # Default everything to read-only
2531

2632
concurrency:
2733
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
@@ -157,7 +163,11 @@ jobs:
157163
'generic-no-unicode',
158164
'generic-no-wide-characters',
159165
'generic-static',
160-
'generic-with_llvm_unwinder'
166+
'generic-with_llvm_unwinder',
167+
# TODO Find a better place for the benchmark and bootstrapping builds to live. They're either very expensive
168+
# or don't provide much value since the benchmark run results are too noise on the bots.
169+
'benchmarks',
170+
'bootstrapping-build'
161171
]
162172
machine: [ 'libcxx-runners-8' ]
163173
std_modules: [ 'OFF' ]

.github/workflows/pr-code-format.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ jobs:
4040
path: code-format-tools
4141

4242
- name: "Listed files"
43+
env:
44+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
4345
run: |
4446
echo "Formatting files:"
45-
echo "${{ steps.changed-files.outputs.all_changed_files }}"
47+
echo "$CHANGED_FILES"
4648
4749
- name: Install clang-format
4850
uses: aminya/setup-cpp@v1

.github/workflows/sync-release-repo.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ class BinaryContext {
611611
/// Indicates if the binary contains split functions.
612612
bool HasSplitFunctions{false};
613613

614+
/// Indicates if the function ordering of the binary is finalized.
615+
bool HasFinalizedFunctionOrder{false};
616+
614617
/// Is the binary always loaded at a fixed address. Shared objects and
615618
/// position-independent executables (PIEs) are examples of binaries that
616619
/// will have HasFixedLoadAddress set to false.
@@ -1230,6 +1233,9 @@ class BinaryContext {
12301233
///
12311234
/// Return the pair where the first size is for the main part, and the second
12321235
/// size is for the cold one.
1236+
/// Modify BinaryBasicBlock::OutputAddressRange for each basic block in the
1237+
/// function in place so that BinaryBasicBlock::getOutputSize() gives the
1238+
/// emitted size of the basic block.
12331239
std::pair<size_t, size_t> calculateEmittedSize(BinaryFunction &BF,
12341240
bool FixBranches = true);
12351241

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ class DIEBuilder {
273273
void buildCompileUnits(const std::vector<DWARFUnit *> &CUs);
274274
/// Preventing implicit conversions.
275275
template <class T> void buildCompileUnits(T) = delete;
276-
void buildBoth();
276+
/// Builds DWO Unit. For DWARF5 this includes the type units.
277+
void buildDWOUnit(DWARFUnit &U);
277278

278279
/// Returns DWARFUnitInfo for DWARFUnit
279280
DWARFUnitInfo &getUnitInfoByDwarfUnit(const DWARFUnit &DwarfUnit) {

bolt/include/bolt/Passes/SplitFunctions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ enum SplitFunctionsStrategy : char {
2323
/// Split each function into a hot and cold fragment using profiling
2424
/// information.
2525
Profile2 = 0,
26+
/// Split each function into a hot, warm, and cold fragment using
27+
/// profiling information.
28+
CDSplit,
2629
/// Split each function into a hot and cold fragment at a randomly chosen
2730
/// split point (ignoring any available profiling information).
2831
Random2,
@@ -40,7 +43,7 @@ class SplitStrategy {
4043

4144
virtual ~SplitStrategy() = default;
4245
virtual bool canSplit(const BinaryFunction &BF) = 0;
43-
virtual bool keepEmpty() = 0;
46+
virtual bool compactFragments() = 0;
4447
virtual void fragment(const BlockIt Start, const BlockIt End) = 0;
4548
};
4649

bolt/lib/Core/BinaryContext.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,14 +2331,36 @@ BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) {
23312331
MCAsmLayout Layout(Assembler);
23322332
Assembler.layout(Layout);
23332333

2334+
// Obtain fragment sizes.
2335+
std::vector<uint64_t> FragmentSizes;
2336+
// Main fragment size.
23342337
const uint64_t HotSize =
23352338
Layout.getSymbolOffset(*EndLabel) - Layout.getSymbolOffset(*StartLabel);
2336-
const uint64_t ColdSize =
2337-
std::accumulate(SplitLabels.begin(), SplitLabels.end(), 0ULL,
2338-
[&](const uint64_t Accu, const LabelRange &Labels) {
2339-
return Accu + Layout.getSymbolOffset(*Labels.second) -
2340-
Layout.getSymbolOffset(*Labels.first);
2341-
});
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+
}
23422364

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

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "llvm/Support/Regex.h"
4141
#include "llvm/Support/Timer.h"
4242
#include "llvm/Support/raw_ostream.h"
43+
#include "llvm/Support/xxhash.h"
4344
#include <functional>
4445
#include <limits>
4546
#include <numeric>
@@ -108,6 +109,13 @@ cl::opt<bool>
108109
cl::desc("try to preserve basic block alignment"),
109110
cl::cat(BoltOptCategory));
110111

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

521+
if (opts::PrintOutputAddressRange)
522+
OS << formatv(" Output Address Range: [{0:x}, {1:x}) ({2} bytes)\n",
523+
BB->getOutputAddressRange().first,
524+
BB->getOutputAddressRange().second, BB->getOutputSize());
525+
513526
if (isEntryPoint(*BB)) {
514527
if (MCSymbol *EntrySymbol = getSecondaryEntryPointSymbol(*BB))
515528
OS << " Secondary Entry Point: " << EntrySymbol->getName() << '\n';
@@ -3283,7 +3296,7 @@ void BinaryFunction::fixBranches() {
32833296
BB->eraseInstruction(BB->findInstruction(UncondBranch));
32843297

32853298
// Basic block that follows the current one in the final layout.
3286-
const BinaryBasicBlock *NextBB =
3299+
const BinaryBasicBlock *const NextBB =
32873300
Layout.getBasicBlockAfter(BB, /*IgnoreSplits=*/false);
32883301

32893302
if (BB->succ_size() == 1) {
@@ -3300,39 +3313,54 @@ void BinaryFunction::fixBranches() {
33003313
assert(CondBranch && "conditional branch expected");
33013314
const BinaryBasicBlock *TSuccessor = BB->getConditionalSuccessor(true);
33023315
const BinaryBasicBlock *FSuccessor = BB->getConditionalSuccessor(false);
3303-
// Check whether we support reversing this branch direction
3304-
const bool IsSupported = !MIB->isUnsupportedBranch(*CondBranch);
3305-
if (NextBB && NextBB == TSuccessor && IsSupported) {
3316+
3317+
// Eliminate unnecessary conditional branch.
3318+
if (TSuccessor == FSuccessor) {
3319+
BB->removeDuplicateConditionalSuccessor(CondBranch);
3320+
if (TSuccessor != NextBB)
3321+
BB->addBranchInstruction(TSuccessor);
3322+
continue;
3323+
}
3324+
3325+
// Reverse branch condition and swap successors.
3326+
auto swapSuccessors = [&]() {
3327+
if (MIB->isUnsupportedBranch(*CondBranch))
3328+
return false;
33063329
std::swap(TSuccessor, FSuccessor);
3307-
{
3308-
auto L = BC.scopeLock();
3309-
MIB->reverseBranchCondition(*CondBranch, TSuccessor->getLabel(), Ctx);
3310-
}
33113330
BB->swapConditionalSuccessors();
3312-
} else {
3331+
auto L = BC.scopeLock();
3332+
MIB->reverseBranchCondition(*CondBranch, TSuccessor->getLabel(), Ctx);
3333+
return true;
3334+
};
3335+
3336+
// Check whether the next block is a "taken" target and try to swap it
3337+
// with a "fall-through" target.
3338+
if (TSuccessor == NextBB && swapSuccessors())
3339+
continue;
3340+
3341+
// Update conditional branch destination if needed.
3342+
if (MIB->getTargetSymbol(*CondBranch) != TSuccessor->getLabel()) {
33133343
auto L = BC.scopeLock();
33143344
MIB->replaceBranchTarget(*CondBranch, TSuccessor->getLabel(), Ctx);
33153345
}
3316-
if (TSuccessor == FSuccessor)
3317-
BB->removeDuplicateConditionalSuccessor(CondBranch);
3318-
if (!NextBB ||
3319-
((NextBB != TSuccessor || !IsSupported) && NextBB != FSuccessor)) {
3320-
// If one of the branches is guaranteed to be "long" while the other
3321-
// could be "short", then prioritize short for "taken". This will
3322-
// generate a sequence 1 byte shorter on x86.
3323-
if (IsSupported && BC.isX86() &&
3324-
TSuccessor->getFragmentNum() != FSuccessor->getFragmentNum() &&
3325-
BB->getFragmentNum() != TSuccessor->getFragmentNum()) {
3326-
std::swap(TSuccessor, FSuccessor);
3327-
{
3328-
auto L = BC.scopeLock();
3329-
MIB->reverseBranchCondition(*CondBranch, TSuccessor->getLabel(),
3330-
Ctx);
3331-
}
3332-
BB->swapConditionalSuccessors();
3333-
}
3334-
BB->addBranchInstruction(FSuccessor);
3346+
3347+
// No need for the unconditional branch.
3348+
if (FSuccessor == NextBB)
3349+
continue;
3350+
3351+
if (BC.isX86()) {
3352+
// We are going to generate two branches. Check if their targets are in
3353+
// the same fragment as this block. If only one target is in the same
3354+
// fragment, make it the destination of the conditional branch. There
3355+
// is a chance it will be a short branch which takes 5 bytes fewer than
3356+
// a long conditional branch. For unconditional branch, the difference
3357+
// is 4 bytes.
3358+
if (BB->getFragmentNum() != TSuccessor->getFragmentNum() &&
3359+
BB->getFragmentNum() == FSuccessor->getFragmentNum())
3360+
swapSuccessors();
33353361
}
3362+
3363+
BB->addBranchInstruction(FSuccessor);
33363364
}
33373365
// Cases where the number of successors is 0 (block ends with a
33383366
// terminator) or more than 2 (switch table) don't require branch
@@ -3624,7 +3652,7 @@ size_t BinaryFunction::computeHash(bool UseDFS,
36243652
for (const BinaryBasicBlock *BB : Order)
36253653
HashString.append(hashBlock(BC, *BB, OperandHashFunc));
36263654

3627-
return Hash = std::hash<std::string>{}(HashString);
3655+
return Hash = llvm::xxh3_64bits(HashString);
36283656
}
36293657

36303658
void BinaryFunction::insertBasicBlocks(
@@ -4131,10 +4159,6 @@ void BinaryFunction::updateOutputValues(const BOLTLinker &Linker) {
41314159
if (!requiresAddressMap())
41324160
return;
41334161

4134-
// Output ranges should match the input if the body hasn't changed.
4135-
if (!isSimple() && !BC.HasRelocations)
4136-
return;
4137-
41384162
// AArch64 may have functions that only contains a constant island (no code).
41394163
if (getLayout().block_empty())
41404164
return;
@@ -4182,6 +4206,12 @@ void BinaryFunction::updateOutputValues(const BOLTLinker &Linker) {
41824206
? FF.getAddress() + FF.getImageSize()
41834207
: getOutputAddress() + getOutputSize());
41844208
}
4209+
4210+
// Reset output addresses for deleted blocks.
4211+
for (BinaryBasicBlock *BB : DeletedBasicBlocks) {
4212+
BB->setOutputStartAddress(0);
4213+
BB->setOutputEndAddress(0);
4214+
}
41854215
}
41864216

41874217
DebugAddressRangesVector BinaryFunction::getOutputAddressRanges() const {

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,6 @@ void DIEBuilder::buildTypeUnits(const bool Init) {
193193
if (Init)
194194
BuilderState.reset(new State());
195195

196-
unsigned int CUNum = getCUNum(DwarfContext, IsDWO);
197-
getState().CloneUnitCtxMap.resize(CUNum);
198-
DWARFContext::unit_iterator_range CU4TURanges =
199-
IsDWO ? DwarfContext->dwo_types_section_units()
200-
: DwarfContext->types_section_units();
201-
202196
const DWARFUnitIndex &TUIndex = DwarfContext->getTUIndex();
203197
if (!TUIndex.getRows().empty()) {
204198
for (auto &Row : TUIndex.getRows()) {
@@ -208,6 +202,11 @@ void DIEBuilder::buildTypeUnits(const bool Init) {
208202
true);
209203
}
210204
}
205+
const unsigned int CUNum = getCUNum(DwarfContext, IsDWO);
206+
getState().CloneUnitCtxMap.resize(CUNum);
207+
DWARFContext::unit_iterator_range CU4TURanges =
208+
IsDWO ? DwarfContext->dwo_types_section_units()
209+
: DwarfContext->types_section_units();
211210

212211
getState().Type = ProcessingType::DWARF4TUs;
213212
for (std::unique_ptr<DWARFUnit> &DU : CU4TURanges)
@@ -278,11 +277,13 @@ void DIEBuilder::buildCompileUnits(const std::vector<DWARFUnit *> &CUs) {
278277
constructFromUnit(*DU);
279278
}
280279

281-
void DIEBuilder::buildBoth() {
280+
void DIEBuilder::buildDWOUnit(DWARFUnit &U) {
282281
BuilderState.release();
283282
BuilderState = std::make_unique<State>();
284283
buildTypeUnits(false);
285-
buildCompileUnits(false);
284+
getState().Type = ProcessingType::CUs;
285+
registerUnit(U, false);
286+
constructFromUnit(U);
286287
}
287288

288289
DIE *DIEBuilder::constructDIEFast(DWARFDie &DDie, DWARFUnit &U,

0 commit comments

Comments
 (0)