Skip to content

Commit 1e0cdfd

Browse files
authored
Merge branch 'main' into loop_unroll_zero
2 parents d2cbfcb + 971237d commit 1e0cdfd

File tree

1,143 files changed

+35032
-16193
lines changed

Some content is hidden

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

1,143 files changed

+35032
-16193
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ clang/test/AST/Interp/ @tbaederr
115115
/mlir/**/LLVMIR/**/BasicPtxBuilderInterface* @grypp
116116
/mlir/**/NVVM*/ @grypp
117117

118+
# MLIR Python Bindings
119+
/mlir/test/python/ @makslevental @stellaraccident
120+
/mlir/python/ @makslevental @stellaraccident
121+
118122
# BOLT
119123
/bolt/ @aaupov @maksfb @rafaelauler @ayermolo @dcci
120124

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/Profile/BoltAddressTranslation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ class BoltAddressTranslation {
149149
/// entries in function address translation map.
150150
APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems);
151151

152-
/// Calculate the number of equal offsets (output = input) in the beginning
153-
/// of the function.
154-
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;
155155

156156
std::map<uint64_t, MapTy> Maps;
157157

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ MarkerSymType BinaryContext::getMarkerType(const SymbolRef &Symbol) const {
18801880
// For aarch64 and riscv, the ABI defines mapping symbols so we identify data
18811881
// in the code section (see IHI0056B). $x identifies a symbol starting code or
18821882
// the end of a data chunk inside code, $d identifies start of data.
1883-
if ((!isAArch64() && !isRISCV()) || ELFSymbolRef(Symbol).getSize())
1883+
if (isX86() || ELFSymbolRef(Symbol).getSize())
18841884
return MarkerSymType::NONE;
18851885

18861886
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
}

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@ APInt BoltAddressTranslation::calculateBranchEntriesBitMask(MapTy &Map,
153153
return BitMask;
154154
}
155155

156-
size_t BoltAddressTranslation::getNumEqualOffsets(const MapTy &Map) const {
156+
size_t BoltAddressTranslation::getNumEqualOffsets(const MapTy &Map,
157+
uint32_t Skew) const {
157158
size_t EqualOffsets = 0;
158159
for (const std::pair<const uint32_t, uint32_t> &KeyVal : Map) {
159160
const uint32_t OutputOffset = KeyVal.first;
160161
const uint32_t InputOffset = KeyVal.second >> 1;
161-
if (OutputOffset == InputOffset)
162+
if (OutputOffset == InputOffset - Skew)
162163
++EqualOffsets;
163164
else
164165
break;
@@ -196,12 +197,17 @@ void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
196197
SecondaryEntryPointsMap.count(Address)
197198
? SecondaryEntryPointsMap[Address].size()
198199
: 0;
200+
uint32_t Skew = 0;
199201
if (Cold) {
200202
auto HotEntryIt = Maps.find(ColdPartSource[Address]);
201203
assert(HotEntryIt != Maps.end());
202204
size_t HotIndex = std::distance(Maps.begin(), HotEntryIt);
203205
encodeULEB128(HotIndex - PrevIndex, OS);
204206
PrevIndex = HotIndex;
207+
// Skew of all input offsets for cold fragments is simply the first input
208+
// offset.
209+
Skew = Map.begin()->second >> 1;
210+
encodeULEB128(Skew, OS);
205211
} else {
206212
// Function hash
207213
size_t BFHash = getBFHash(HotInputAddress);
@@ -217,24 +223,21 @@ void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
217223
<< '\n');
218224
}
219225
encodeULEB128(NumEntries, OS);
220-
// For hot fragments only: encode the number of equal offsets
221-
// (output = input) in the beginning of the function. Only encode one offset
222-
// in these cases.
223-
const size_t EqualElems = Cold ? 0 : getNumEqualOffsets(Map);
224-
if (!Cold) {
225-
encodeULEB128(EqualElems, OS);
226-
if (EqualElems) {
227-
const size_t BranchEntriesBytes = alignTo(EqualElems, 8) / 8;
228-
APInt BranchEntries = calculateBranchEntriesBitMask(Map, EqualElems);
229-
OS.write(reinterpret_cast<const char *>(BranchEntries.getRawData()),
230-
BranchEntriesBytes);
231-
LLVM_DEBUG({
232-
dbgs() << "BranchEntries: ";
233-
SmallString<8> BitMaskStr;
234-
BranchEntries.toString(BitMaskStr, 2, false);
235-
dbgs() << BitMaskStr << '\n';
236-
});
237-
}
226+
// Encode the number of equal offsets (output = input - skew) in the
227+
// beginning of the function. Only encode one offset in these cases.
228+
const size_t EqualElems = getNumEqualOffsets(Map, Skew);
229+
encodeULEB128(EqualElems, OS);
230+
if (EqualElems) {
231+
const size_t BranchEntriesBytes = alignTo(EqualElems, 8) / 8;
232+
APInt BranchEntries = calculateBranchEntriesBitMask(Map, EqualElems);
233+
OS.write(reinterpret_cast<const char *>(BranchEntries.getRawData()),
234+
BranchEntriesBytes);
235+
LLVM_DEBUG({
236+
dbgs() << "BranchEntries: ";
237+
SmallString<8> BitMaskStr;
238+
BranchEntries.toString(BitMaskStr, 2, false);
239+
dbgs() << BitMaskStr << '\n';
240+
});
238241
}
239242
const BBHashMapTy &BBHashMap = getBBHashMap(HotInputAddress);
240243
size_t Index = 0;
@@ -315,10 +318,12 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
315318
uint64_t HotAddress = Cold ? 0 : Address;
316319
PrevAddress = Address;
317320
uint32_t SecondaryEntryPoints = 0;
321+
uint64_t ColdInputSkew = 0;
318322
if (Cold) {
319323
HotIndex += DE.getULEB128(&Offset, &Err);
320324
HotAddress = HotFuncs[HotIndex];
321325
ColdPartSource.emplace(Address, HotAddress);
326+
ColdInputSkew = DE.getULEB128(&Offset, &Err);
322327
} else {
323328
HotFuncs.push_back(Address);
324329
// Function hash
@@ -339,28 +344,25 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
339344
getULEB128Size(SecondaryEntryPoints)));
340345
}
341346
const uint32_t NumEntries = DE.getULEB128(&Offset, &Err);
342-
// Equal offsets, hot fragments only.
343-
size_t EqualElems = 0;
347+
// Equal offsets.
348+
const size_t EqualElems = DE.getULEB128(&Offset, &Err);
344349
APInt BEBitMask;
345-
if (!Cold) {
346-
EqualElems = DE.getULEB128(&Offset, &Err);
347-
LLVM_DEBUG(dbgs() << formatv("Equal offsets: {0}, {1} bytes\n",
348-
EqualElems, getULEB128Size(EqualElems)));
349-
if (EqualElems) {
350-
const size_t BranchEntriesBytes = alignTo(EqualElems, 8) / 8;
351-
BEBitMask = APInt(alignTo(EqualElems, 8), 0);
352-
LoadIntFromMemory(
353-
BEBitMask,
354-
reinterpret_cast<const uint8_t *>(
355-
DE.getBytes(&Offset, BranchEntriesBytes, &Err).data()),
356-
BranchEntriesBytes);
357-
LLVM_DEBUG({
358-
dbgs() << "BEBitMask: ";
359-
SmallString<8> BitMaskStr;
360-
BEBitMask.toString(BitMaskStr, 2, false);
361-
dbgs() << BitMaskStr << ", " << BranchEntriesBytes << " bytes\n";
362-
});
363-
}
350+
LLVM_DEBUG(dbgs() << formatv("Equal offsets: {0}, {1} bytes\n", EqualElems,
351+
getULEB128Size(EqualElems)));
352+
if (EqualElems) {
353+
const size_t BranchEntriesBytes = alignTo(EqualElems, 8) / 8;
354+
BEBitMask = APInt(alignTo(EqualElems, 8), 0);
355+
LoadIntFromMemory(
356+
BEBitMask,
357+
reinterpret_cast<const uint8_t *>(
358+
DE.getBytes(&Offset, BranchEntriesBytes, &Err).data()),
359+
BranchEntriesBytes);
360+
LLVM_DEBUG({
361+
dbgs() << "BEBitMask: ";
362+
SmallString<8> BitMaskStr;
363+
BEBitMask.toString(BitMaskStr, 2, false);
364+
dbgs() << BitMaskStr << ", " << BranchEntriesBytes << " bytes\n";
365+
});
364366
}
365367
MapTy Map;
366368

@@ -375,7 +377,7 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
375377
PrevAddress = OutputAddress;
376378
int64_t InputDelta = 0;
377379
if (J < EqualElems) {
378-
InputOffset = (OutputOffset << 1) | BEBitMask[J];
380+
InputOffset = ((OutputOffset + ColdInputSkew) << 1) | BEBitMask[J];
379381
} else {
380382
InputDelta = DE.getSLEB128(&Offset, &Err);
381383
InputOffset += InputDelta;

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,9 @@ void RewriteInstance::disassemblePLT() {
16701670
return disassemblePLTSectionAArch64(Section);
16711671
if (BC->isRISCV())
16721672
return disassemblePLTSectionRISCV(Section);
1673-
return disassemblePLTSectionX86(Section, EntrySize);
1673+
if (BC->isX86())
1674+
return disassemblePLTSectionX86(Section, EntrySize);
1675+
llvm_unreachable("Unmplemented PLT");
16741676
};
16751677

16761678
for (BinarySection &Section : BC->allocatableSections()) {
@@ -2605,7 +2607,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
26052607
const bool IsToCode = ReferencedSection && ReferencedSection->isText();
26062608

26072609
// Special handling of PC-relative relocations.
2608-
if (!IsAArch64 && !BC->isRISCV() && Relocation::isPCRelative(RType)) {
2610+
if (BC->isX86() && Relocation::isPCRelative(RType)) {
26092611
if (!IsFromCode && IsToCode) {
26102612
// PC-relative relocations from data to code are tricky since the
26112613
// original information is typically lost after linking, even with
@@ -2859,15 +2861,14 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
28592861
BC->isRISCV())
28602862
ForceRelocation = true;
28612863

2862-
if (IsFromCode) {
2864+
if (IsFromCode)
28632865
ContainingBF->addRelocation(Rel.getOffset(), ReferencedSymbol, RType,
28642866
Addend, ExtractedValue);
2865-
} else if (IsToCode || ForceRelocation) {
2867+
else if (IsToCode || ForceRelocation)
28662868
BC->addRelocation(Rel.getOffset(), ReferencedSymbol, RType, Addend,
28672869
ExtractedValue);
2868-
} else {
2870+
else
28692871
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: ignoring relocation from data to data\n");
2870-
}
28712872
}
28722873

28732874
void RewriteInstance::selectFunctionsToProcess() {
@@ -5766,10 +5767,3 @@ bool RewriteInstance::isDebugSection(StringRef SectionName) {
57665767

57675768
return false;
57685769
}
5769-
5770-
bool RewriteInstance::isKSymtabSection(StringRef SectionName) {
5771-
if (SectionName.starts_with("__ksymtab"))
5772-
return true;
5773-
5774-
return false;
5775-
}

bolt/test/X86/bolt-address-translation.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# CHECK: BOLT: 3 out of 7 functions were overwritten.
3838
# CHECK: BOLT-INFO: Wrote 6 BAT maps
3939
# CHECK: BOLT-INFO: Wrote 3 function and 58 basic block hashes
40-
# CHECK: BOLT-INFO: BAT section size (bytes): 924
40+
# CHECK: BOLT-INFO: BAT section size (bytes): 928
4141
#
4242
# usqrt mappings (hot part). We match against any key (left side containing
4343
# the bolted binary offsets) because BOLT may change where it puts instructions

clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@ namespace clang::tidy::linuxkernel {
1717
/// linux/err.h. Also checks to see if code uses the results from functions that
1818
/// directly return a value from one of these error functions.
1919
///
20-
/// This is important in the Linux kernel because ERR_PTR, PTR_ERR, IS_ERR,
21-
/// IS_ERR_OR_NULL, ERR_CAST, and PTR_ERR_OR_ZERO return values must be checked,
22-
/// since positive pointers and negative error codes are being used in the same
23-
/// context. These functions are marked with
24-
/// __attribute__((warn_unused_result)), but some kernel versions do not have
25-
/// this warning enabled for clang.
26-
///
2720
/// For the user-facing documentation see:
28-
/// http://clang.llvm.org/extra/clang-tidy/checks/linuxkernel/must-use-errs.html
21+
/// http://clang.llvm.org/extra/clang-tidy/checks/linuxkernel/must-check-errs.html
2922
class MustCheckErrsCheck : public ClangTidyCheck {
3023
public:
3124
MustCheckErrsCheck(StringRef Name, ClangTidyContext *Context)

clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/Support/FormatVariadic.h"
3030
#include "llvm/Support/MathExtras.h"
3131
#include <array>
32+
#include <cmath>
3233
#include <cstdint>
3334
#include <cstdlib>
3435
#include <initializer_list>

0 commit comments

Comments
 (0)