Skip to content

Commit d3b5b59

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW25)
LLVM: llvm/llvm-project@af35be5 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@9823690 Community has started to refactor some code assuming opaque pointer only, however the SPIRV component used in sycl is not ready to enable the opaque pointer by default, so we have to revert some of the commit by guarding them within macro INTEL_SYCL_OPAQUEPOINTER_READY, and keep both version of the code. The old code should be removed once we enable opaque pointer by default.
2 parents 9ec2e53 + 635f861 commit d3b5b59

File tree

6,244 files changed

+1076515
-693299
lines changed

Some content is hidden

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

6,244 files changed

+1076515
-693299
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ dd3c26a045c081620375a878159f536758baba6e
5555
f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c
5656
2238dcc39358353cac21df75c3c3286ab20b8f53
5757
f9008e6366c2496b1ca1785b891d5578174ad63e
58+
59+
# [libc++][NFC] Apply clang-format on large parts of the code base
60+
5aa03b648b827128d439f705cd7d57d59673741d

bolt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ list(INSERT CMAKE_MODULE_PATH 0 "${BOLT_SOURCE_DIR}/cmake/modules")
99

1010
# Determine default set of targets to build -- the intersection of
1111
# those BOLT supports and those LLVM is targeting.
12-
set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86")
12+
set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86;RISCV")
1313
set(BOLT_TARGETS_TO_BUILD_default)
1414
foreach (tgt ${BOLT_TARGETS_TO_BUILD_all})
1515
if (tgt IN_LIST LLVM_TARGETS_TO_BUILD)

bolt/CODE_OWNERS.TXT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ D: DWARF support
2020
N: Vladislav Khmelevsky
2121
2222
D: AArch64 backend
23+
24+
N: Job Noorman
25+
26+
D: RISC-V backend

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ using namespace object;
5959
namespace bolt {
6060

6161
class BinaryFunction;
62-
class ExecutableFileMemoryManager;
6362

6463
/// Information on loadable part of the file.
6564
struct SegmentInfo {
@@ -313,10 +312,6 @@ class BinaryContext {
313312
FilterIterator<binary_data_const_iterator>;
314313
using FilteredBinaryDataIterator = FilterIterator<binary_data_iterator>;
315314

316-
/// Memory manager for sections and segments. Used to communicate with ORC
317-
/// among other things.
318-
std::shared_ptr<ExecutableFileMemoryManager> EFMM;
319-
320315
StringRef getFilename() const { return Filename; }
321316
void setFilename(StringRef Name) { Filename = std::string(Name); }
322317

@@ -727,6 +722,8 @@ class BinaryContext {
727722
TheTriple->getArch() == llvm::Triple::x86_64;
728723
}
729724

725+
bool isRISCV() const { return TheTriple->getArch() == llvm::Triple::riscv64; }
726+
730727
// AArch64-specific functions to check if symbol is used to delimit
731728
// code/data in .text. Code is marked by $x, data by $d.
732729
MarkerSymType getMarkerType(const SymbolRef &Symbol) const;
@@ -845,13 +842,11 @@ class BinaryContext {
845842
/// Return BinaryData for the given \p Name or nullptr if no
846843
/// global symbol with that name exists.
847844
const BinaryData *getBinaryDataByName(StringRef Name) const {
848-
auto Itr = GlobalSymbols.find(Name);
849-
return Itr != GlobalSymbols.end() ? Itr->second : nullptr;
845+
return GlobalSymbols.lookup(Name);
850846
}
851847

852848
BinaryData *getBinaryDataByName(StringRef Name) {
853-
auto Itr = GlobalSymbols.find(Name);
854-
return Itr != GlobalSymbols.end() ? Itr->second : nullptr;
849+
return GlobalSymbols.lookup(Name);
855850
}
856851

857852
/// Return registered PLT entry BinaryData with the given \p Name
@@ -1165,7 +1160,7 @@ class BinaryContext {
11651160

11661161
/// Return a dynamic relocation registered at a given \p Address, or nullptr
11671162
/// if there is no dynamic relocation at such address.
1168-
const Relocation *getDynamicRelocationAt(uint64_t Address);
1163+
const Relocation *getDynamicRelocationAt(uint64_t Address) const;
11691164

11701165
/// Remove registered relocation at a given \p Address.
11711166
bool removeRelocationAt(uint64_t Address);

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ class BinaryFunction {
384384
/// Indicates the type of profile the function is using.
385385
uint16_t ProfileFlags{PF_NONE};
386386

387+
/// True if the function's input profile data has been inaccurate but has
388+
/// been adjusted by the profile inference algorithm.
389+
bool HasInferredProfile{false};
390+
387391
/// For functions with mismatched profile we store all call profile
388392
/// information at a function level (as opposed to tying it to
389393
/// specific call sites).
@@ -1124,11 +1128,7 @@ class BinaryFunction {
11241128
/// secondary entry point into the function, then return a global symbol
11251129
/// that represents the secondary entry point. Otherwise return nullptr.
11261130
MCSymbol *getSecondaryEntryPointSymbol(const MCSymbol *BBLabel) const {
1127-
auto I = SecondaryEntryPoints.find(BBLabel);
1128-
if (I == SecondaryEntryPoints.end())
1129-
return nullptr;
1130-
1131-
return I->second;
1131+
return SecondaryEntryPoints.lookup(BBLabel);
11321132
}
11331133

11341134
/// If the basic block serves as a secondary entry point to the function,
@@ -1566,6 +1566,12 @@ class BinaryFunction {
15661566
/// Return flags describing a profile for this function.
15671567
uint16_t getProfileFlags() const { return ProfileFlags; }
15681568

1569+
/// Return true if the function's input profile data has been inaccurate but
1570+
/// has been corrected by the profile inference algorithm.
1571+
bool hasInferredProfile() const { return HasInferredProfile; }
1572+
1573+
void setHasInferredProfile(bool Inferred) { HasInferredProfile = Inferred; }
1574+
15691575
void addCFIInstruction(uint64_t Offset, MCCFIInstruction &&Inst) {
15701576
assert(!Instructions.empty());
15711577

@@ -2040,9 +2046,11 @@ class BinaryFunction {
20402046
void handleAArch64IndirectCall(MCInst &Instruction, const uint64_t Offset);
20412047

20422048
/// Scan function for references to other functions. In relocation mode,
2043-
/// add relocations for external references.
2049+
/// add relocations for external references. In non-relocation mode, detect
2050+
/// and mark new entry points.
20442051
///
2045-
/// Return true on success.
2052+
/// Return true on success. False if the disassembly failed or relocations
2053+
/// could not be created.
20462054
bool scanExternalRefs();
20472055

20482056
/// Return the size of a data object located at \p Offset in the function.

bolt/include/bolt/Core/BinarySection.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ class BinarySection {
5656
unsigned Alignment; // alignment in bytes (must be > 0)
5757
unsigned ELFType; // ELF section type
5858
unsigned ELFFlags; // ELF section flags
59+
bool IsRelro{false}; // GNU RELRO section (read-only after relocation)
5960

6061
// Relocations associated with this section. Relocation offsets are
6162
// wrt. to the original section address and size.
62-
using RelocationSetType = std::set<Relocation, std::less<>>;
63+
using RelocationSetType = std::multiset<Relocation, std::less<>>;
6364
RelocationSetType Relocations;
6465

6566
// Dynamic relocations associated with this section. Relocation offsets are
@@ -90,7 +91,7 @@ class BinarySection {
9091
uint64_t OutputFileOffset{0}; // File offset in the rewritten binary file.
9192
StringRef OutputContents; // Rewritten section contents.
9293
const uint64_t SectionNumber; // Order in which the section was created.
93-
unsigned SectionID{-1u}; // Unique ID used for address mapping.
94+
std::string SectionID; // Unique ID used for address mapping.
9495
// Set by ExecutableFileMemoryManager.
9596
uint32_t Index{0}; // Section index in the output file.
9697
mutable bool IsReordered{false}; // Have the contents been reordered?
@@ -287,6 +288,8 @@ class BinarySection {
287288
}
288289
bool isReordered() const { return IsReordered; }
289290
bool isAnonymous() const { return IsAnonymous; }
291+
bool isRelro() const { return IsRelro; }
292+
void setRelro() { IsRelro = true; }
290293
unsigned getELFType() const { return ELFType; }
291294
unsigned getELFFlags() const { return ELFFlags; }
292295

@@ -345,7 +348,8 @@ class BinarySection {
345348
bool removeRelocationAt(uint64_t Offset) {
346349
auto Itr = Relocations.find(Offset);
347350
if (Itr != Relocations.end()) {
348-
Relocations.erase(Itr);
351+
auto End = Relocations.upper_bound(Offset);
352+
Relocations.erase(Itr, End);
349353
return true;
350354
}
351355
return false;
@@ -430,18 +434,18 @@ class BinarySection {
430434
}
431435
uint64_t getOutputAddress() const { return OutputAddress; }
432436
uint64_t getOutputFileOffset() const { return OutputFileOffset; }
433-
unsigned getSectionID() const {
437+
StringRef getSectionID() const {
434438
assert(hasValidSectionID() && "trying to use uninitialized section id");
435439
return SectionID;
436440
}
437-
bool hasValidSectionID() const { return SectionID != -1u; }
441+
bool hasValidSectionID() const { return !SectionID.empty(); }
438442
bool hasValidIndex() { return Index != 0; }
439443
uint32_t getIndex() const { return Index; }
440444

441445
// mutation
442446
void setOutputAddress(uint64_t Address) { OutputAddress = Address; }
443447
void setOutputFileOffset(uint64_t Offset) { OutputFileOffset = Offset; }
444-
void setSectionID(unsigned ID) {
448+
void setSectionID(StringRef ID) {
445449
assert(!hasValidSectionID() && "trying to set section id twice");
446450
SectionID = ID;
447451
}

bolt/include/bolt/Core/Linker.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===- bolt/Core/Linker.h - BOLTLinker interface ----------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file contains the interface BOLT uses for linking.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef BOLT_CORE_LINKER_H
14+
#define BOLT_CORE_LINKER_H
15+
16+
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/Support/MemoryBufferRef.h"
18+
19+
#include <cstdint>
20+
#include <functional>
21+
#include <optional>
22+
23+
namespace llvm {
24+
namespace bolt {
25+
26+
class BinarySection;
27+
28+
class BOLTLinker {
29+
public:
30+
using SectionMapper =
31+
std::function<void(const BinarySection &Section, uint64_t Address)>;
32+
using SectionsMapper = std::function<void(SectionMapper)>;
33+
34+
virtual ~BOLTLinker() = default;
35+
36+
/// Load and link \p Obj. \p MapSections will be called before the object is
37+
/// linked to allow section addresses to be remapped. When called, the address
38+
/// of a section can be changed by calling the passed SectionMapper.
39+
virtual void loadObject(MemoryBufferRef Obj, SectionsMapper MapSections) = 0;
40+
41+
/// Return the address of a symbol or std::nullopt if it cannot be found.
42+
virtual std::optional<uint64_t> lookupSymbol(StringRef Name) const = 0;
43+
};
44+
45+
} // namespace bolt
46+
} // namespace llvm
47+
48+
#endif // BOLT_CORE_LINKER_H

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,12 @@ class MCPlusBuilder {
336336
initSizeMap();
337337
}
338338

339-
/// Create and return target-specific MC symbolizer for the \p Function.
339+
/// Create and return a target-specific MC symbolizer for the \p Function.
340+
/// When \p CreateNewSymbols is set, the symbolizer can create new symbols
341+
/// e.g. for jump table references.
340342
virtual std::unique_ptr<MCSymbolizer>
341-
createTargetSymbolizer(BinaryFunction &Function) const {
343+
createTargetSymbolizer(BinaryFunction &Function,
344+
bool CreateNewSymbols = true) const {
342345
return nullptr;
343346
}
344347

@@ -431,7 +434,7 @@ class MCPlusBuilder {
431434
}
432435

433436
/// Check whether we support inverting this branch
434-
virtual bool isUnsupportedBranch(unsigned Opcode) const { return false; }
437+
virtual bool isUnsupportedBranch(const MCInst &Inst) const { return false; }
435438

436439
/// Return true of the instruction is of pseudo kind.
437440
bool isPseudo(const MCInst &Inst) const {
@@ -630,6 +633,12 @@ class MCPlusBuilder {
630633
return false;
631634
}
632635

636+
/// Returns true if First/Second is a AUIPC/JALR call pair.
637+
virtual bool isRISCVCall(const MCInst &First, const MCInst &Second) const {
638+
llvm_unreachable("not implemented");
639+
return false;
640+
}
641+
633642
/// If non-zero, this is used to fill the executable space with instructions
634643
/// that will trap. Defaults to 0.
635644
virtual unsigned getTrapFillValue() const { return 0; }
@@ -2029,6 +2038,10 @@ MCPlusBuilder *createAArch64MCPlusBuilder(const MCInstrAnalysis *,
20292038
const MCInstrInfo *,
20302039
const MCRegisterInfo *);
20312040

2041+
MCPlusBuilder *createRISCVMCPlusBuilder(const MCInstrAnalysis *,
2042+
const MCInstrInfo *,
2043+
const MCRegisterInfo *);
2044+
20322045
} // namespace bolt
20332046
} // namespace llvm
20342047

bolt/include/bolt/Core/Relocation.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
#ifndef BOLT_CORE_RELOCATION_H
1515
#define BOLT_CORE_RELOCATION_H
1616

17+
#include "llvm/MC/MCExpr.h"
18+
#include "llvm/MC/MCStreamer.h"
1719
#include "llvm/TargetParser/Triple.h"
1820

1921
namespace llvm {
20-
class MCStreamer;
2122
class MCSymbol;
2223
class raw_ostream;
2324

@@ -122,8 +123,36 @@ struct Relocation {
122123
/// responsible for setting the position correctly.
123124
size_t emit(MCStreamer *Streamer) const;
124125

126+
/// Emit a group of composed relocations. All relocations must have the same
127+
/// offset. If std::distance(Begin, End) == 1, this is equivalent to
128+
/// Begin->emit(Streamer).
129+
template <typename RelocIt>
130+
static size_t emit(RelocIt Begin, RelocIt End, MCStreamer *Streamer) {
131+
if (Begin == End)
132+
return 0;
133+
134+
const MCExpr *Value = nullptr;
135+
136+
for (auto RI = Begin; RI != End; ++RI) {
137+
assert(RI->Offset == Begin->Offset &&
138+
"emitting composed relocations with different offsets");
139+
Value = RI->createExpr(Streamer, Value);
140+
}
141+
142+
assert(Value && "failed to create relocation value");
143+
auto Size = std::prev(End)->getSize();
144+
Streamer->emitValue(Value, Size);
145+
return Size;
146+
}
147+
125148
/// Print a relocation to \p OS.
126149
void print(raw_ostream &OS) const;
150+
151+
private:
152+
const MCExpr *createExpr(MCStreamer *Streamer) const;
153+
const MCExpr *createExpr(MCStreamer *Streamer,
154+
const MCExpr *RetainedValue) const;
155+
static MCBinaryExpr::Opcode getComposeOpcodeFor(uint64_t Type);
127156
};
128157

129158
/// Relocation ordering by offset.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===- bolt/Passes/FixRISCVCallsPass.h --------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file declares the FixRISCVCallsPass class, which sets the JALR immediate
10+
// to 0 for AUIPC/JALR pairs with a R_RISCV_CALL(_PLT) relocation. This is
11+
// necessary since MC expects it to be zero in order to or-in fixups.
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef BOLT_PASSES_FIXRISCVCALLSPASS_H
15+
#define BOLT_PASSES_FIXRISCVCALLSPASS_H
16+
17+
#include "bolt/Passes/BinaryPasses.h"
18+
19+
namespace llvm {
20+
namespace bolt {
21+
22+
class FixRISCVCallsPass : public BinaryFunctionPass {
23+
void runOnFunction(BinaryFunction &Function);
24+
25+
public:
26+
explicit FixRISCVCallsPass(const cl::opt<bool> &PrintPass)
27+
: BinaryFunctionPass(PrintPass) {}
28+
29+
const char *getName() const override { return "fix-riscv-calls"; }
30+
31+
/// Pass entry point
32+
void runOnFunctions(BinaryContext &BC) override;
33+
};
34+
35+
} // namespace bolt
36+
} // namespace llvm
37+
38+
#endif

bolt/include/bolt/Profile/YAMLProfileReader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class YAMLProfileReader : public ProfileReaderBase {
7070
bool parseFunctionProfile(BinaryFunction &Function,
7171
const yaml::bolt::BinaryFunctionProfile &YamlBF);
7272

73+
/// Infer function profile from stale data (collected on older binaries).
74+
bool inferStaleProfile(BinaryFunction &Function,
75+
const yaml::bolt::BinaryFunctionProfile &YamlBF);
76+
7377
/// Initialize maps for profile matching.
7478
void buildNameMaps(std::map<uint64_t, BinaryFunction> &Functions);
7579

0 commit comments

Comments
 (0)