Skip to content

Commit 425dbd7

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW16 2024)
LLVM: llvm/llvm-project@af7a82f SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@e1f7ebee5ed8b90
2 parents 4a1d030 + 3ce9126 commit 425dbd7

File tree

2,782 files changed

+106684
-54332
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,782 files changed

+106684
-54332
lines changed

.ci/generate-buildkite-pipeline-premerge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function add-dependencies() {
108108
compiler-rt|libc|openmp)
109109
echo clang lld
110110
;;
111-
flang|lldb)
111+
flang|lldb|libclc)
112112
for p in llvm clang; do
113113
echo $p
114114
done

.github/new-prs-labeler.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
ClangIR:
2+
- clang/include/clang/CIR/**/*
3+
- clang/lib/CIR/**/*
4+
- clang/tools/cir-*/**/*
5+
- clang/test/CIR/**/*
6+
17
clang:dataflow:
28
- clang/include/clang/Analysis/FlowSensitive/**/*
39
- clang/lib/Analysis/FlowSensitive/**/*
@@ -938,3 +944,6 @@ openmp:libomptarget:
938944

939945
bazel:
940946
- utils/bazel/**
947+
948+
offload:
949+
- offload/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
name: "Check code formatting"
2+
3+
permissions:
4+
contents: read
5+
26
on:
37
pull_request:
48
branches:

bolt/docs/BAT.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ Hot indices are delta encoded, implicitly starting at zero.
8181
| `FuncHash` | 8b | Function hash for input function | Hot |
8282
| `NumBlocks` | ULEB128 | Number of basic blocks in the original function | Hot |
8383
| `NumSecEntryPoints` | ULEB128 | Number of secondary entry points in the original function | Hot |
84+
| `ColdInputSkew` | ULEB128 | Skew to apply to all input offsets | Cold |
8485
| `NumEntries` | ULEB128 | Number of address translation entries for a function | Both |
85-
| `EqualElems` | ULEB128 | Number of equal offsets in the beginning of a function | Hot |
86-
| `BranchEntries` | Bitmask, `alignTo(EqualElems, 8)` bits | If `EqualElems` is non-zero, bitmask denoting entries with `BRANCHENTRY` bit | Hot |
86+
| `EqualElems` | ULEB128 | Number of equal offsets in the beginning of a function | Both |
87+
| `BranchEntries` | Bitmask, `alignTo(EqualElems, 8)` bits | If `EqualElems` is non-zero, bitmask denoting entries with `BRANCHENTRY` bit | Both |
8788

8889
Function header is followed by *Address Translation Table* with `NumEntries`
8990
total entries, and *Secondary Entry Points* table with `NumSecEntryPoints`
@@ -99,8 +100,8 @@ entry is encoded. Input offsets implicitly start at zero.
99100
| `BBHash` | Optional, 8b | Basic block hash in input binary | BB |
100101
| `BBIdx` | Optional, Delta, ULEB128 | Basic block index in input binary | BB |
101102

102-
For hot fragments, the table omits the first `EqualElems` input offsets
103-
where the input offset equals output offset.
103+
The table omits the first `EqualElems` input offsets where the input offset
104+
equals output offset.
104105

105106
`BRANCHENTRY` bit denotes whether a given offset pair is a control flow source
106107
(branch or call instruction). If not set, it signifies a control flow target

bolt/include/bolt/Core/BinaryData.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class BinaryData {
107107
std::vector<MCSymbol *> &getSymbols() { return Symbols; }
108108

109109
bool hasName(StringRef Name) const;
110-
bool hasNameRegex(StringRef Name) const;
111110
bool nameStartsWith(StringRef Prefix) const;
112111

113112
bool hasSymbol(const MCSymbol *Symbol) const {

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,8 @@ class BinaryFunction {
14021402

14031403
/// Return true if the function has CFI instructions
14041404
bool hasCFI() const {
1405-
return !FrameInstructions.empty() || !CIEFrameInstructions.empty();
1405+
return !FrameInstructions.empty() || !CIEFrameInstructions.empty() ||
1406+
IsInjected;
14061407
}
14071408

14081409
/// Return unique number associated with the function.

bolt/include/bolt/Profile/BoltAddressTranslation.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ class BoltAddressTranslation {
119119
/// True if a given \p Address is a function with translation table entry.
120120
bool isBATFunction(uint64_t Address) const { return Maps.count(Address); }
121121

122-
/// Returns branch offsets grouped by containing basic block in a given
123-
/// function.
124-
std::unordered_map<uint32_t, std::vector<uint32_t>>
125-
getBFBranches(uint64_t FuncOutputAddress) const;
126-
127122
/// For a given \p Symbol in the output binary and known \p InputOffset
128123
/// return a corresponding pair of parent BinaryFunction and secondary entry
129124
/// point in it.
@@ -154,9 +149,9 @@ class BoltAddressTranslation {
154149
/// entries in function address translation map.
155150
APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems);
156151

157-
/// Calculate the number of equal offsets (output = input) in the beginning
158-
/// of the function.
159-
size_t getNumEqualOffsets(const MapTy &Map) const;
152+
/// Calculate the number of equal offsets (output = input - skew) in the
153+
/// beginning of the function.
154+
size_t getNumEqualOffsets(const MapTy &Map, uint32_t Skew) const;
160155

161156
std::map<uint64_t, MapTy> Maps;
162157

@@ -193,7 +188,7 @@ class BoltAddressTranslation {
193188
EntryTy(unsigned Index, size_t Hash) : Index(Index), Hash(Hash) {}
194189
};
195190

196-
std::unordered_map<uint32_t, EntryTy> Map;
191+
std::map<uint32_t, EntryTy> Map;
197192
const EntryTy &getEntry(uint32_t BBInputOffset) const {
198193
auto It = Map.find(BBInputOffset);
199194
assert(It != Map.end());
@@ -218,6 +213,10 @@ class BoltAddressTranslation {
218213
}
219214

220215
size_t getNumBasicBlocks() const { return Map.size(); }
216+
217+
auto begin() const { return Map.begin(); }
218+
auto end() const { return Map.end(); }
219+
auto upper_bound(uint32_t Offset) const { return Map.upper_bound(Offset); }
221220
};
222221

223222
/// Map function output address to its hash and basic blocks hash map.

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ class DataAggregator : public DataReader {
225225
/// Aggregation statistics
226226
uint64_t NumInvalidTraces{0};
227227
uint64_t NumLongRangeTraces{0};
228+
/// Specifies how many samples were recorded in cold areas if we are dealing
229+
/// with profiling data collected in a bolted binary. For LBRs, incremented
230+
/// for the source of the branch to avoid counting cold activity twice (one
231+
/// for source and another for destination).
228232
uint64_t NumColdSamples{0};
229233

230234
/// Looks into system PATH for Linux Perf and set up the aggregator to use it
@@ -245,14 +249,12 @@ class DataAggregator : public DataReader {
245249
/// disassembled BinaryFunctions
246250
BinaryFunction *getBinaryFunctionContainingAddress(uint64_t Address) const;
247251

252+
/// Perform BAT translation for a given \p Func and return the parent
253+
/// BinaryFunction or nullptr.
254+
BinaryFunction *getBATParentFunction(const BinaryFunction &Func) const;
255+
248256
/// Retrieve the location name to be used for samples recorded in \p Func.
249-
/// If doing BAT translation, link cold parts to the hot part names (used by
250-
/// the original binary). \p Count specifies how many samples were recorded
251-
/// at that location, so we can tally total activity in cold areas if we are
252-
/// dealing with profiling data collected in a bolted binary. For LBRs,
253-
/// \p Count should only be used for the source of the branch to avoid
254-
/// counting cold activity twice (one for source and another for destination).
255-
StringRef getLocationName(BinaryFunction &Func, uint64_t Count);
257+
StringRef getLocationName(const BinaryFunction &Func) const;
256258

257259
/// Semantic actions - parser hooks to interpret parsed perf samples
258260
/// Register a sample (non-LBR mode), i.e. a new hit at \p Address
@@ -467,9 +469,6 @@ class DataAggregator : public DataReader {
467469
std::error_code writeBATYAML(BinaryContext &BC,
468470
StringRef OutputFilename) const;
469471

470-
/// Fixup profile collected on BOLTed binary, namely handle split functions.
471-
void fixupBATProfile(BinaryContext &BC);
472-
473472
/// Filter out binaries based on PID
474473
void filterBinaryMMapInfo();
475474

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,6 @@ class RewriteInstance {
368368
/// rewritten binary.
369369
void patchBuildID();
370370

371-
/// Return file offset corresponding to a given virtual address.
372-
uint64_t getFileOffsetFor(uint64_t Address) {
373-
assert(Address >= NewTextSegmentAddress &&
374-
"address in not in the new text segment");
375-
return Address - NewTextSegmentAddress + NewTextSegmentOffset;
376-
}
377-
378371
/// Return file offset corresponding to a virtual \p Address.
379372
/// Return 0 if the address has no mapping in the file, including being
380373
/// part of .bss section.
@@ -398,9 +391,6 @@ class RewriteInstance {
398391
/// Return true if the section holds debug information.
399392
static bool isDebugSection(StringRef SectionName);
400393

401-
/// Return true if the section holds linux kernel symbol information.
402-
static bool isKSymtabSection(StringRef SectionName);
403-
404394
/// Adds Debug section to overwrite.
405395
static void addToDebugSectionsToOverwrite(const char *Section) {
406396
DebugSectionsToOverwrite.emplace_back(Section);

bolt/lib/Core/BinaryContext.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ bool BinaryContext::analyzeJumpTable(const uint64_t Address,
555555
const uint64_t NextJTAddress,
556556
JumpTable::AddressesType *EntriesAsAddress,
557557
bool *HasEntryInFragment) const {
558+
// Target address of __builtin_unreachable.
559+
const uint64_t UnreachableAddress = BF.getAddress() + BF.getSize();
560+
558561
// Is one of the targets __builtin_unreachable?
559562
bool HasUnreachable = false;
560563

@@ -564,9 +567,15 @@ bool BinaryContext::analyzeJumpTable(const uint64_t Address,
564567
// Number of targets other than __builtin_unreachable.
565568
uint64_t NumRealEntries = 0;
566569

567-
auto addEntryAddress = [&](uint64_t EntryAddress) {
568-
if (EntriesAsAddress)
569-
EntriesAsAddress->emplace_back(EntryAddress);
570+
// Size of the jump table without trailing __builtin_unreachable entries.
571+
size_t TrimmedSize = 0;
572+
573+
auto addEntryAddress = [&](uint64_t EntryAddress, bool Unreachable = false) {
574+
if (!EntriesAsAddress)
575+
return;
576+
EntriesAsAddress->emplace_back(EntryAddress);
577+
if (!Unreachable)
578+
TrimmedSize = EntriesAsAddress->size();
570579
};
571580

572581
ErrorOr<const BinarySection &> Section = getSectionForAddress(Address);
@@ -618,8 +627,8 @@ bool BinaryContext::analyzeJumpTable(const uint64_t Address,
618627
: *getPointerAtAddress(EntryAddress);
619628

620629
// __builtin_unreachable() case.
621-
if (Value == BF.getAddress() + BF.getSize()) {
622-
addEntryAddress(Value);
630+
if (Value == UnreachableAddress) {
631+
addEntryAddress(Value, /*Unreachable*/ true);
623632
HasUnreachable = true;
624633
LLVM_DEBUG(dbgs() << formatv("OK: {0:x} __builtin_unreachable\n", Value));
625634
continue;
@@ -673,6 +682,13 @@ bool BinaryContext::analyzeJumpTable(const uint64_t Address,
673682
addEntryAddress(Value);
674683
}
675684

685+
// Trim direct/normal jump table to exclude trailing unreachable entries that
686+
// can collide with a function address.
687+
if (Type == JumpTable::JTT_NORMAL && EntriesAsAddress &&
688+
TrimmedSize != EntriesAsAddress->size() &&
689+
getBinaryFunctionAtAddress(UnreachableAddress))
690+
EntriesAsAddress->resize(TrimmedSize);
691+
676692
// It's a jump table if the number of real entries is more than 1, or there's
677693
// one real entry and one or more special targets. If there are only multiple
678694
// special targets, then it's not a jump table.
@@ -1864,7 +1880,7 @@ MarkerSymType BinaryContext::getMarkerType(const SymbolRef &Symbol) const {
18641880
// For aarch64 and riscv, the ABI defines mapping symbols so we identify data
18651881
// in the code section (see IHI0056B). $x identifies a symbol starting code or
18661882
// the end of a data chunk inside code, $d identifies start of data.
1867-
if ((!isAArch64() && !isRISCV()) || ELFSymbolRef(Symbol).getSize())
1883+
if (isX86() || ELFSymbolRef(Symbol).getSize())
18681884
return MarkerSymType::NONE;
18691885

18701886
Expected<StringRef> NameOrError = Symbol.getName();

bolt/lib/Core/BinaryData.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ bool BinaryData::hasName(StringRef Name) const {
5555
return false;
5656
}
5757

58-
bool BinaryData::hasNameRegex(StringRef NameRegex) const {
59-
Regex MatchName(NameRegex);
60-
for (const MCSymbol *Symbol : Symbols)
61-
if (MatchName.match(Symbol->getName()))
62-
return true;
63-
return false;
64-
}
65-
6658
bool BinaryData::nameStartsWith(StringRef Prefix) const {
6759
for (const MCSymbol *Symbol : Symbols)
6860
if (Symbol->getName().starts_with(Prefix))

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
512512

513513
// Emit sized NOPs via MCAsmBackend::writeNopData() interface on x86.
514514
// This is a workaround for invalid NOPs handling by asm/disasm layer.
515-
if (BC.MIB->isNoop(Instr) && BC.isX86()) {
515+
if (BC.isX86() && BC.MIB->isNoop(Instr)) {
516516
if (std::optional<uint32_t> Size = BC.MIB->getSize(Instr)) {
517517
SmallString<15> Code;
518518
raw_svector_ostream VecOS(Code);

bolt/lib/Core/Relocation.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,21 +1064,19 @@ MCBinaryExpr::Opcode Relocation::getComposeOpcodeFor(uint64_t Type) {
10641064
}
10651065
}
10661066

1067-
#define ELF_RELOC(name, value) #name,
1068-
10691067
void Relocation::print(raw_ostream &OS) const {
1070-
static const char *X86RelocNames[] = {
1071-
#include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
1072-
};
1073-
static const char *AArch64RelocNames[] = {
1074-
#include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
1075-
};
10761068
switch (Arch) {
10771069
default:
10781070
OS << "RType:" << Twine::utohexstr(Type);
10791071
break;
10801072

10811073
case Triple::aarch64:
1074+
static const char *const AArch64RelocNames[] = {
1075+
#define ELF_RELOC(name, value) #name,
1076+
#include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
1077+
#undef ELF_RELOC
1078+
};
1079+
assert(Type < ArrayRef(AArch64RelocNames).size());
10821080
OS << AArch64RelocNames[Type];
10831081
break;
10841082

@@ -1088,16 +1086,22 @@ void Relocation::print(raw_ostream &OS) const {
10881086
switch (Type) {
10891087
default:
10901088
llvm_unreachable("illegal RISC-V relocation");
1091-
#undef ELF_RELOC
10921089
#define ELF_RELOC(name, value) \
10931090
case value: \
10941091
OS << #name; \
10951092
break;
10961093
#include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
1094+
#undef ELF_RELOC
10971095
}
10981096
break;
10991097

11001098
case Triple::x86_64:
1099+
static const char *const X86RelocNames[] = {
1100+
#define ELF_RELOC(name, value) #name,
1101+
#include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
1102+
#undef ELF_RELOC
1103+
};
1104+
assert(Type < ArrayRef(X86RelocNames).size());
11011105
OS << X86RelocNames[Type];
11021106
break;
11031107
}

0 commit comments

Comments
 (0)