Skip to content

Commit e356af4

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.4 [skip ci]
2 parents 8ba2a33 + 1022636 commit e356af4

File tree

3,027 files changed

+342273
-141008
lines changed

Some content is hidden

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

3,027 files changed

+342273
-141008
lines changed

.ci/generate-buildkite-pipeline-premerge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function add-dependencies() {
9191
echo "${project}"
9292
case ${project} in
9393
bolt)
94-
for p in lld llvm; do
94+
for p in clang lld llvm; do
9595
echo $p
9696
done
9797
;;

.ci/monolithic-linux.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
4848
-D LLVM_LIT_ARGS="-v --xunit-xml-output ${BUILD_DIR}/test-results.xml --timeout=1200 --time-tests" \
4949
-D LLVM_ENABLE_LLD=ON \
5050
-D CMAKE_CXX_FLAGS=-gmlt \
51-
-D BOLT_CLANG_EXE=/usr/bin/clang \
5251
-D LLVM_CCACHE_BUILD=ON \
5352
-D MLIR_ENABLE_BINDINGS_PYTHON=ON
5453

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
clang/lib/AST/Interp/ @tbaederr
3636
clang/test/AST/Interp/ @tbaederr
3737

38+
/clang/include/clang/CIR @lanza @bcardosolopes
39+
/clang/lib/CIR @lanza @bcardosolopes
40+
/clang/tools/cir-* @lanza @bcardosolopes
41+
3842
/lldb/ @JDevlieghere
3943

4044
# MLIR Interfaces.

.github/new-prs-labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
BOLT:
2+
- bolt/**/*
3+
14
ClangIR:
25
- clang/include/clang/CIR/**/*
36
- clang/lib/CIR/**/*
@@ -467,6 +470,7 @@ backend:m68k:
467470

468471
libc++:
469472
- libcxx/**
473+
- .github/workflows/libcxx-*
470474

471475
libc++abi:
472476
- libcxxabi/**

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "bolt/Core/JumpTable.h"
2121
#include "bolt/Core/MCPlusBuilder.h"
2222
#include "bolt/RuntimeLibs/RuntimeLibrary.h"
23+
#include "llvm/ADT/AddressRanges.h"
2324
#include "llvm/ADT/ArrayRef.h"
2425
#include "llvm/ADT/StringMap.h"
2526
#include "llvm/ADT/iterator.h"
@@ -726,6 +727,9 @@ class BinaryContext {
726727
uint64_t OldTextSectionOffset{0};
727728
uint64_t OldTextSectionSize{0};
728729

730+
/// Area in the input binary reserved for BOLT.
731+
AddressRange BOLTReserved;
732+
729733
/// Address of the code/function that is executed before any other code in
730734
/// the binary.
731735
std::optional<uint64_t> StartFunctionAddress;

bolt/include/bolt/Passes/BinaryPasses.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ class PrintProfileStats : public BinaryFunctionPass {
400400
/// dyno stats categories.
401401
class PrintProgramStats : public BinaryFunctionPass {
402402
public:
403-
explicit PrintProgramStats(const cl::opt<bool> &PrintPass)
404-
: BinaryFunctionPass(PrintPass) {}
403+
explicit PrintProgramStats() : BinaryFunctionPass(false) {}
405404

406405
const char *getName() const override { return "print-stats"; }
407406
bool shouldPrint(const BinaryFunction &) const override { return false; }

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,8 @@ class DataAggregator : public DataReader {
198198
/// A trace is region of code executed between two LBR entries supplied in
199199
/// execution order.
200200
///
201-
/// Return true if the trace is valid, false otherwise.
202-
bool
203-
recordTrace(BinaryFunction &BF, const LBREntry &First, const LBREntry &Second,
204-
uint64_t Count,
205-
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const;
206-
207201
/// Return a vector of offsets corresponding to a trace in a function
208-
/// (see recordTrace() above).
202+
/// if the trace is valid, std::nullopt otherwise.
209203
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
210204
getFallthroughsInTrace(BinaryFunction &BF, const LBREntry &First,
211205
const LBREntry &Second, uint64_t Count = 1) const;

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ class RewriteInstance {
9797
/// from meta data in the file.
9898
void discoverFileObjects();
9999

100+
/// Check if the input binary has a space reserved for BOLT and use it for new
101+
/// section allocations if found.
102+
void discoverBOLTReserved();
103+
100104
/// Check whether we should use DT_FINI or DT_FINI_ARRAY for instrumentation.
101105
/// DT_FINI is preferred; DT_FINI_ARRAY is only used when no DT_FINI entry was
102106
/// found.
@@ -422,10 +426,18 @@ class RewriteInstance {
422426
/// Section name used for extra BOLT code in addition to .text.
423427
static StringRef getBOLTTextSectionName() { return ".bolt.text"; }
424428

429+
/// Symbol markers for BOLT reserved area.
430+
static StringRef getBOLTReservedStart() { return "__bolt_reserved_start"; }
431+
static StringRef getBOLTReservedEnd() { return "__bolt_reserved_end"; }
432+
425433
/// Common section names.
426434
static StringRef getEHFrameSectionName() { return ".eh_frame"; }
435+
static StringRef getEHFrameHdrSectionName() { return ".eh_frame_hdr"; }
427436
static StringRef getRelaDynSectionName() { return ".rela.dyn"; }
428437

438+
/// FILE symbol name used for local fragments of global functions.
439+
static StringRef getBOLTFileSymbolName() { return "bolt-pseudo.o"; }
440+
429441
/// An instance of the input binary we are processing, externally owned.
430442
llvm::object::ELFObjectFileBase *InputFile;
431443

@@ -490,6 +502,9 @@ class RewriteInstance {
490502
/// Store all non-zero symbols in this map for a quick address lookup.
491503
std::map<uint64_t, llvm::object::SymbolRef> FileSymRefs;
492504

505+
/// FILE symbols used for disambiguating split function parents.
506+
std::vector<ELFSymbolRef> FileSymbols;
507+
493508
std::unique_ptr<DWARFRewriter> DebugInfoRewriter;
494509

495510
std::unique_ptr<BoltAddressTranslation> BAT;

bolt/include/bolt/Utils/NameResolver.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,23 @@ class NameResolver {
2828
static constexpr char Sep = '/';
2929

3030
public:
31-
/// Return unique version of the \p Name in the form "Name<Sep><Number>".
31+
/// Return the number of uniquified versions of a given \p Name.
32+
uint64_t getUniquifiedNameCount(StringRef Name) const {
33+
if (Counters.contains(Name))
34+
return Counters.at(Name);
35+
return 0;
36+
}
37+
38+
/// Return unique version of the \p Name in the form "Name<Sep><ID>".
39+
std::string getUniqueName(StringRef Name, const uint64_t ID) const {
40+
return (Name + Twine(Sep) + Twine(ID)).str();
41+
}
42+
43+
/// Register new version of \p Name and return unique version in the form
44+
/// "Name<Sep><Number>".
3245
std::string uniquify(StringRef Name) {
3346
const uint64_t ID = ++Counters[Name];
34-
return (Name + Twine(Sep) + Twine(ID)).str();
47+
return getUniqueName(Name, ID);
3548
}
3649

3750
/// For uniquified \p Name, return the original form (that may no longer be

bolt/lib/Passes/SplitFunctions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,12 @@ Error SplitFunctions::runOnFunctions(BinaryContext &BC) {
715715
if (!opts::SplitFunctions)
716716
return Error::success();
717717

718+
if (BC.IsLinuxKernel && BC.BOLTReserved.empty()) {
719+
BC.errs() << "BOLT-ERROR: split functions require reserved space in the "
720+
"Linux kernel binary\n";
721+
exit(1);
722+
}
723+
718724
// If split strategy is not CDSplit, then a second run of the pass is not
719725
// needed after function reordering.
720726
if (BC.HasFinalizedFunctionOrder &&
@@ -829,6 +835,13 @@ void SplitFunctions::splitFunction(BinaryFunction &BF, SplitStrategy &S) {
829835
}
830836
}
831837
}
838+
839+
// Outlining blocks with dynamic branches is not supported yet.
840+
if (BC.IsLinuxKernel) {
841+
if (llvm::any_of(
842+
*BB, [&](MCInst &Inst) { return BC.MIB->isDynamicBranch(Inst); }))
843+
BB->setCanOutline(false);
844+
}
832845
}
833846

834847
BF.getLayout().updateLayoutIndices();

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "bolt/Profile/DataAggregator.h"
1515
#include "bolt/Core/BinaryContext.h"
1616
#include "bolt/Core/BinaryFunction.h"
17+
#include "bolt/Passes/BinaryPasses.h"
1718
#include "bolt/Profile/BoltAddressTranslation.h"
1819
#include "bolt/Profile/Heatmap.h"
1920
#include "bolt/Profile/YAMLProfileWriter.h"
@@ -611,6 +612,7 @@ Error DataAggregator::readProfile(BinaryContext &BC) {
611612
if (std::error_code EC = writeBATYAML(BC, opts::SaveProfile))
612613
report_error("cannot create output data file", EC);
613614
}
615+
BC.logBOLTErrorsAndQuitOnFatal(PrintProgramStats().runOnFunctions(BC));
614616
}
615617

616618
return Error::success();
@@ -859,14 +861,17 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
859861
return true;
860862
}
861863

862-
bool DataAggregator::recordTrace(
863-
BinaryFunction &BF, const LBREntry &FirstLBR, const LBREntry &SecondLBR,
864-
uint64_t Count,
865-
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const {
864+
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
865+
DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
866+
const LBREntry &FirstLBR,
867+
const LBREntry &SecondLBR,
868+
uint64_t Count) const {
869+
SmallVector<std::pair<uint64_t, uint64_t>, 16> Branches;
870+
866871
BinaryContext &BC = BF.getBinaryContext();
867872

868873
if (!BF.isSimple())
869-
return false;
874+
return std::nullopt;
870875

871876
assert(BF.hasCFG() && "can only record traces in CFG state");
872877

@@ -875,13 +880,13 @@ bool DataAggregator::recordTrace(
875880
const uint64_t To = SecondLBR.From - BF.getAddress();
876881

877882
if (From > To)
878-
return false;
883+
return std::nullopt;
879884

880885
const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset(From);
881886
const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset(To);
882887

883888
if (!FromBB || !ToBB)
884-
return false;
889+
return std::nullopt;
885890

886891
// Adjust FromBB if the first LBR is a return from the last instruction in
887892
// the previous block (that instruction should be a call).
@@ -905,7 +910,7 @@ bool DataAggregator::recordTrace(
905910
// within the same basic block, e.g. when two call instructions are in the
906911
// same block. In this case we skip the processing.
907912
if (FromBB == ToBB)
908-
return true;
913+
return Branches;
909914

910915
// Process blocks in the original layout order.
911916
BinaryBasicBlock *BB = BF.getLayout().getBlock(FromBB->getIndex());
@@ -919,7 +924,7 @@ bool DataAggregator::recordTrace(
919924
LLVM_DEBUG(dbgs() << "no fall-through for the trace:\n"
920925
<< " " << FirstLBR << '\n'
921926
<< " " << SecondLBR << '\n');
922-
return false;
927+
return std::nullopt;
923928
}
924929

925930
const MCInst *Instr = BB->getLastNonPseudoInstr();
@@ -943,20 +948,7 @@ bool DataAggregator::recordTrace(
943948
BI.Count += Count;
944949
}
945950

946-
return true;
947-
}
948-
949-
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
950-
DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
951-
const LBREntry &FirstLBR,
952-
const LBREntry &SecondLBR,
953-
uint64_t Count) const {
954-
SmallVector<std::pair<uint64_t, uint64_t>, 16> Res;
955-
956-
if (!recordTrace(BF, FirstLBR, SecondLBR, Count, Res))
957-
return std::nullopt;
958-
959-
return Res;
951+
return Branches;
960952
}
961953

962954
bool DataAggregator::recordEntry(BinaryFunction &BF, uint64_t To, bool Mispred,

bolt/lib/Rewrite/BinaryPassManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
356356
// order they're registered.
357357

358358
// Run this pass first to use stats for the original functions.
359-
Manager.registerPass(std::make_unique<PrintProgramStats>(NeverPrint));
359+
Manager.registerPass(std::make_unique<PrintProgramStats>());
360360

361361
if (opts::PrintProfileStats)
362362
Manager.registerPass(std::make_unique<PrintProfileStats>(NeverPrint));

bolt/lib/Rewrite/BoltDiff.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class RewriteInstanceDiff {
292292
}
293293
}
294294
}
295-
PrintProgramStats PPS(opts::NeverPrint);
295+
PrintProgramStats PPS;
296296
outs() << "* BOLT-DIFF: Starting print program stats pass for binary 1\n";
297297
RI1.BC->logBOLTErrorsAndQuitOnFatal(PPS.runOnFunctions(*RI1.BC));
298298
outs() << "* BOLT-DIFF: Starting print program stats pass for binary 2\n";

0 commit comments

Comments
 (0)