Skip to content

Commit

Permalink
LLVM and SPIRV-LLVM-Translator pulldown (WW48)
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-sycl committed Dec 1, 2023
2 parents ea6a3a3 + 522cefd commit caaad39
Show file tree
Hide file tree
Showing 2,749 changed files with 112,029 additions and 79,792 deletions.
3 changes: 2 additions & 1 deletion .ci/monolithic-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ cmake -S ${MONOREPO_ROOT}/llvm -B ${BUILD_DIR} \
-D LLVM_ENABLE_LLD=ON \
-D CMAKE_CXX_FLAGS=-gmlt \
-D BOLT_CLANG_EXE=/usr/bin/clang \
-D LLVM_CCACHE_BUILD=ON
-D LLVM_CCACHE_BUILD=ON \
-D MLIR_ENABLE_BINDINGS_PYTHON=ON

echo "--- ninja"
# Targets are not escaped as they are passed as separate arguments.
Expand Down
3 changes: 2 additions & 1 deletion .ci/monolithic-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ cmake -S ${MONOREPO_ROOT}/llvm -B ${BUILD_DIR} \
-D LLVM_LIT_ARGS="-v --xunit-xml-output ${BUILD_DIR}/test-results.xml" \
-D COMPILER_RT_BUILD_ORC=OFF \
-D CMAKE_C_COMPILER_LAUNCHER=sccache \
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache \
-D MLIR_ENABLE_BINDINGS_PYTHON=ON

echo "--- ninja"
# Targets are not escaped as they are passed as separate arguments.
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
paths:
- 'llvm/docs/**'
- 'clang/docs/**'
- 'clang/include/clang/Basic/AttrDocs.td'
- 'clang/include/clang/Driver/ClangOptionDocs.td'
- 'clang/include/clang/Basic/DiagnosticDocs.td'
- 'clang-tools-extra/docs/**'
- 'lldb/docs/**'
- 'libunwind/docs/**'
Expand All @@ -29,6 +32,9 @@ on:
paths:
- 'llvm/docs/**'
- 'clang/docs/**'
- 'clang/include/clang/Basic/AttrDocs.td'
- 'clang/include/clang/Driver/ClangOptionDocs.td'
- 'clang/include/clang/Basic/DiagnosticDocs.td'
- 'clang-tools-extra/docs/**'
- 'lldb/docs/**'
- 'libunwind/docs/**'
Expand Down Expand Up @@ -64,6 +70,9 @@ jobs:
- 'llvm/docs/**'
clang:
- 'clang/docs/**'
- 'clang/include/clang/Basic/AttrDocs.td'
- 'clang/include/clang/Driver/ClangOptionDocs.td'
- 'clang/include/clang/Basic/DiagnosticDocs.td'
clang-tools-extra:
- 'clang-tools-extra/docs/**'
lldb:
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/libcxx-build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ on:
- 'runtimes/**'
- 'cmake/**'
- '.github/workflows/libcxx-build-and-test.yaml'
schedule:
# Run nightly at 8 AM UTC (or roughly 3 AM eastern)
- cron: '0 3 * * *'

permissions:
contents: read # Default everything to read-only

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
Expand Down Expand Up @@ -157,7 +163,11 @@ jobs:
'generic-no-unicode',
'generic-no-wide-characters',
'generic-static',
'generic-with_llvm_unwinder'
'generic-with_llvm_unwinder',
# TODO Find a better place for the benchmark and bootstrapping builds to live. They're either very expensive
# or don't provide much value since the benchmark run results are too noise on the bots.
'benchmarks',
'bootstrapping-build'
]
machine: [ 'libcxx-runners-8' ]
std_modules: [ 'OFF' ]
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/pr-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ jobs:
path: code-format-tools

- name: "Listed files"
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "Formatting files:"
echo "${{ steps.changed-files.outputs.all_changed_files }}"
echo "$CHANGED_FILES"
- name: Install clang-format
uses: aminya/setup-cpp@v1
Expand Down
17 changes: 0 additions & 17 deletions .github/workflows/sync-release-repo.yml

This file was deleted.

6 changes: 6 additions & 0 deletions bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ class BinaryContext {
/// Indicates if the binary contains split functions.
bool HasSplitFunctions{false};

/// Indicates if the function ordering of the binary is finalized.
bool HasFinalizedFunctionOrder{false};

/// Is the binary always loaded at a fixed address. Shared objects and
/// position-independent executables (PIEs) are examples of binaries that
/// will have HasFixedLoadAddress set to false.
Expand Down Expand Up @@ -1230,6 +1233,9 @@ class BinaryContext {
///
/// Return the pair where the first size is for the main part, and the second
/// size is for the cold one.
/// Modify BinaryBasicBlock::OutputAddressRange for each basic block in the
/// function in place so that BinaryBasicBlock::getOutputSize() gives the
/// emitted size of the basic block.
std::pair<size_t, size_t> calculateEmittedSize(BinaryFunction &BF,
bool FixBranches = true);

Expand Down
3 changes: 2 additions & 1 deletion bolt/include/bolt/Core/DIEBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ class DIEBuilder {
void buildCompileUnits(const std::vector<DWARFUnit *> &CUs);
/// Preventing implicit conversions.
template <class T> void buildCompileUnits(T) = delete;
void buildBoth();
/// Builds DWO Unit. For DWARF5 this includes the type units.
void buildDWOUnit(DWARFUnit &U);

/// Returns DWARFUnitInfo for DWARFUnit
DWARFUnitInfo &getUnitInfoByDwarfUnit(const DWARFUnit &DwarfUnit) {
Expand Down
5 changes: 4 additions & 1 deletion bolt/include/bolt/Passes/SplitFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ enum SplitFunctionsStrategy : char {
/// Split each function into a hot and cold fragment using profiling
/// information.
Profile2 = 0,
/// Split each function into a hot, warm, and cold fragment using
/// profiling information.
CDSplit,
/// Split each function into a hot and cold fragment at a randomly chosen
/// split point (ignoring any available profiling information).
Random2,
Expand All @@ -40,7 +43,7 @@ class SplitStrategy {

virtual ~SplitStrategy() = default;
virtual bool canSplit(const BinaryFunction &BF) = 0;
virtual bool keepEmpty() = 0;
virtual bool compactFragments() = 0;
virtual void fragment(const BlockIt Start, const BlockIt End) = 0;
};

Expand Down
34 changes: 28 additions & 6 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2331,14 +2331,36 @@ BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) {
MCAsmLayout Layout(Assembler);
Assembler.layout(Layout);

// Obtain fragment sizes.
std::vector<uint64_t> FragmentSizes;
// Main fragment size.
const uint64_t HotSize =
Layout.getSymbolOffset(*EndLabel) - Layout.getSymbolOffset(*StartLabel);
const uint64_t ColdSize =
std::accumulate(SplitLabels.begin(), SplitLabels.end(), 0ULL,
[&](const uint64_t Accu, const LabelRange &Labels) {
return Accu + Layout.getSymbolOffset(*Labels.second) -
Layout.getSymbolOffset(*Labels.first);
});
FragmentSizes.push_back(HotSize);
// Split fragment sizes.
uint64_t ColdSize = 0;
for (const auto &Labels : SplitLabels) {
uint64_t Size = Layout.getSymbolOffset(*Labels.second) -
Layout.getSymbolOffset(*Labels.first);
FragmentSizes.push_back(Size);
ColdSize += Size;
}

// Populate new start and end offsets of each basic block.
uint64_t FragmentIndex = 0;
for (FunctionFragment &FF : BF.getLayout().fragments()) {
BinaryBasicBlock *PrevBB = nullptr;
for (BinaryBasicBlock *BB : FF) {
const uint64_t BBStartOffset = Layout.getSymbolOffset(*(BB->getLabel()));
BB->setOutputStartAddress(BBStartOffset);
if (PrevBB)
PrevBB->setOutputEndAddress(BBStartOffset);
PrevBB = BB;
}
if (PrevBB)
PrevBB->setOutputEndAddress(FragmentSizes[FragmentIndex]);
FragmentIndex++;
}

// Clean-up the effect of the code emission.
for (const MCSymbol &Symbol : Assembler.symbols()) {
Expand Down
96 changes: 63 additions & 33 deletions bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "llvm/Support/Regex.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/xxhash.h"
#include <functional>
#include <limits>
#include <numeric>
Expand Down Expand Up @@ -108,6 +109,13 @@ cl::opt<bool>
cl::desc("try to preserve basic block alignment"),
cl::cat(BoltOptCategory));

static cl::opt<bool> PrintOutputAddressRange(
"print-output-address-range",
cl::desc(
"print output address range for each basic block in the function when"
"BinaryFunction::print is called"),
cl::Hidden, cl::cat(BoltOptCategory));

cl::opt<bool>
PrintDynoStats("dyno-stats",
cl::desc("print execution info based on profile"),
Expand Down Expand Up @@ -510,6 +518,11 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
OS << BB->getName() << " (" << BB->size()
<< " instructions, align : " << BB->getAlignment() << ")\n";

if (opts::PrintOutputAddressRange)
OS << formatv(" Output Address Range: [{0:x}, {1:x}) ({2} bytes)\n",
BB->getOutputAddressRange().first,
BB->getOutputAddressRange().second, BB->getOutputSize());

if (isEntryPoint(*BB)) {
if (MCSymbol *EntrySymbol = getSecondaryEntryPointSymbol(*BB))
OS << " Secondary Entry Point: " << EntrySymbol->getName() << '\n';
Expand Down Expand Up @@ -3283,7 +3296,7 @@ void BinaryFunction::fixBranches() {
BB->eraseInstruction(BB->findInstruction(UncondBranch));

// Basic block that follows the current one in the final layout.
const BinaryBasicBlock *NextBB =
const BinaryBasicBlock *const NextBB =
Layout.getBasicBlockAfter(BB, /*IgnoreSplits=*/false);

if (BB->succ_size() == 1) {
Expand All @@ -3300,39 +3313,54 @@ void BinaryFunction::fixBranches() {
assert(CondBranch && "conditional branch expected");
const BinaryBasicBlock *TSuccessor = BB->getConditionalSuccessor(true);
const BinaryBasicBlock *FSuccessor = BB->getConditionalSuccessor(false);
// Check whether we support reversing this branch direction
const bool IsSupported = !MIB->isUnsupportedBranch(*CondBranch);
if (NextBB && NextBB == TSuccessor && IsSupported) {

// Eliminate unnecessary conditional branch.
if (TSuccessor == FSuccessor) {
BB->removeDuplicateConditionalSuccessor(CondBranch);
if (TSuccessor != NextBB)
BB->addBranchInstruction(TSuccessor);
continue;
}

// Reverse branch condition and swap successors.
auto swapSuccessors = [&]() {
if (MIB->isUnsupportedBranch(*CondBranch))
return false;
std::swap(TSuccessor, FSuccessor);
{
auto L = BC.scopeLock();
MIB->reverseBranchCondition(*CondBranch, TSuccessor->getLabel(), Ctx);
}
BB->swapConditionalSuccessors();
} else {
auto L = BC.scopeLock();
MIB->reverseBranchCondition(*CondBranch, TSuccessor->getLabel(), Ctx);
return true;
};

// Check whether the next block is a "taken" target and try to swap it
// with a "fall-through" target.
if (TSuccessor == NextBB && swapSuccessors())
continue;

// Update conditional branch destination if needed.
if (MIB->getTargetSymbol(*CondBranch) != TSuccessor->getLabel()) {
auto L = BC.scopeLock();
MIB->replaceBranchTarget(*CondBranch, TSuccessor->getLabel(), Ctx);
}
if (TSuccessor == FSuccessor)
BB->removeDuplicateConditionalSuccessor(CondBranch);
if (!NextBB ||
((NextBB != TSuccessor || !IsSupported) && NextBB != FSuccessor)) {
// If one of the branches is guaranteed to be "long" while the other
// could be "short", then prioritize short for "taken". This will
// generate a sequence 1 byte shorter on x86.
if (IsSupported && BC.isX86() &&
TSuccessor->getFragmentNum() != FSuccessor->getFragmentNum() &&
BB->getFragmentNum() != TSuccessor->getFragmentNum()) {
std::swap(TSuccessor, FSuccessor);
{
auto L = BC.scopeLock();
MIB->reverseBranchCondition(*CondBranch, TSuccessor->getLabel(),
Ctx);
}
BB->swapConditionalSuccessors();
}
BB->addBranchInstruction(FSuccessor);

// No need for the unconditional branch.
if (FSuccessor == NextBB)
continue;

if (BC.isX86()) {
// We are going to generate two branches. Check if their targets are in
// the same fragment as this block. If only one target is in the same
// fragment, make it the destination of the conditional branch. There
// is a chance it will be a short branch which takes 5 bytes fewer than
// a long conditional branch. For unconditional branch, the difference
// is 4 bytes.
if (BB->getFragmentNum() != TSuccessor->getFragmentNum() &&
BB->getFragmentNum() == FSuccessor->getFragmentNum())
swapSuccessors();
}

BB->addBranchInstruction(FSuccessor);
}
// Cases where the number of successors is 0 (block ends with a
// terminator) or more than 2 (switch table) don't require branch
Expand Down Expand Up @@ -3624,7 +3652,7 @@ size_t BinaryFunction::computeHash(bool UseDFS,
for (const BinaryBasicBlock *BB : Order)
HashString.append(hashBlock(BC, *BB, OperandHashFunc));

return Hash = std::hash<std::string>{}(HashString);
return Hash = llvm::xxh3_64bits(HashString);
}

void BinaryFunction::insertBasicBlocks(
Expand Down Expand Up @@ -4131,10 +4159,6 @@ void BinaryFunction::updateOutputValues(const BOLTLinker &Linker) {
if (!requiresAddressMap())
return;

// Output ranges should match the input if the body hasn't changed.
if (!isSimple() && !BC.HasRelocations)
return;

// AArch64 may have functions that only contains a constant island (no code).
if (getLayout().block_empty())
return;
Expand Down Expand Up @@ -4182,6 +4206,12 @@ void BinaryFunction::updateOutputValues(const BOLTLinker &Linker) {
? FF.getAddress() + FF.getImageSize()
: getOutputAddress() + getOutputSize());
}

// Reset output addresses for deleted blocks.
for (BinaryBasicBlock *BB : DeletedBasicBlocks) {
BB->setOutputStartAddress(0);
BB->setOutputEndAddress(0);
}
}

DebugAddressRangesVector BinaryFunction::getOutputAddressRanges() const {
Expand Down
17 changes: 9 additions & 8 deletions bolt/lib/Core/DIEBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,6 @@ void DIEBuilder::buildTypeUnits(const bool Init) {
if (Init)
BuilderState.reset(new State());

unsigned int CUNum = getCUNum(DwarfContext, IsDWO);
getState().CloneUnitCtxMap.resize(CUNum);
DWARFContext::unit_iterator_range CU4TURanges =
IsDWO ? DwarfContext->dwo_types_section_units()
: DwarfContext->types_section_units();

const DWARFUnitIndex &TUIndex = DwarfContext->getTUIndex();
if (!TUIndex.getRows().empty()) {
for (auto &Row : TUIndex.getRows()) {
Expand All @@ -208,6 +202,11 @@ void DIEBuilder::buildTypeUnits(const bool Init) {
true);
}
}
const unsigned int CUNum = getCUNum(DwarfContext, IsDWO);
getState().CloneUnitCtxMap.resize(CUNum);
DWARFContext::unit_iterator_range CU4TURanges =
IsDWO ? DwarfContext->dwo_types_section_units()
: DwarfContext->types_section_units();

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

void DIEBuilder::buildBoth() {
void DIEBuilder::buildDWOUnit(DWARFUnit &U) {
BuilderState.release();
BuilderState = std::make_unique<State>();
buildTypeUnits(false);
buildCompileUnits(false);
getState().Type = ProcessingType::CUs;
registerUnit(U, false);
constructFromUnit(U);
}

DIE *DIEBuilder::constructDIEFast(DWARFDie &DDie, DWARFUnit &U,
Expand Down
Loading

0 comments on commit caaad39

Please sign in to comment.