Skip to content

Commit 7e81e63

Browse files
committed
Merge branch 'main' into fold-icmp-eq-zext-eq-self
2 parents 2285a2c + 0d7947b commit 7e81e63

File tree

1,504 files changed

+59295
-25216
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,504 files changed

+59295
-25216
lines changed

.ci/generate-buildkite-pipeline-premerge

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ set -o pipefail
2222

2323
# Environment variables script works with:
2424
# List of files affected by this commit
25-
: ${MODIFIED_FILES:=$(git diff --name-only main...HEAD)}
25+
: ${MODIFIED_FILES:=$(git diff --name-only HEAD~1)}
2626
# Filter rules for generic windows tests
2727
: ${WINDOWS_AGENTS:='{"queue": "windows"}'}
2828
# Filter rules for generic linux tests

.github/CODEOWNERS

+28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1+
# This file lists reviewers that are auto-assigned when a pull request modifies
2+
# certain files or directories. If you add yourself to this file, you commit to
3+
# reviewing a large fraction of pull requests in the relevant area.
4+
#
5+
# The GitHub "code owners" mechanism is used exclusively to auto-assign
6+
# reviewers and does not carry significance beyond that. It is not necessary
7+
# to receive an approval from a "code owner" in particular -- any LLVM project
8+
# member can approve pull requests.
9+
#
10+
# Note that GitHub's concept of "code owner" is independent from LLVM's own
11+
# "code owner" concept, they merely happen to share terminology. See
12+
# https://llvm.org/docs/DeveloperPolicy.html#code-owners, as well as the
13+
# CODE_OWNERS.txt files in the respective subproject directories.
14+
115
/libcxx/ @llvm/reviewers-libcxx
216
/libcxxabi/ @llvm/reviewers-libcxxabi
317
/libunwind/ @llvm/reviewers-libunwind
418
/runtimes/ @llvm/reviewers-libcxx
19+
20+
/llvm/lib/Analysis/BasicAliasAnalysis.cpp @nikic
21+
/llvm/lib/Analysis/InstructionSimplify.cpp @nikic
22+
/llvm/lib/Analysis/LazyValueInfo.cpp @nikic
23+
/llvm/lib/Analysis/ScalarEvolution.cpp @nikic
24+
/llvm/lib/Analysis/ValueTracking.cpp @nikic
25+
/llvm/lib/IR/ConstantRange.cpp @nikic
26+
/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @nikic
27+
/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @nikic
28+
/llvm/lib/Transforms/InstCombine/ @nikic
29+
30+
/clang/test/CXX/drs/ @Endilll
31+
/clang/www/cxx_dr_status.html @Endilll
32+
/clang/www/make_cxx_dr_status @Endilll

.github/workflows/llvm-tests.yml

+3
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,17 @@ jobs:
170170
uses: actions/download-artifact@v3
171171
with:
172172
name: build-baseline
173+
path: build-baseline
173174
- name: Download latest
174175
uses: actions/download-artifact@v3
175176
with:
176177
name: build-latest
178+
path: build-latest
177179
- name: Download symbol list
178180
uses: actions/download-artifact@v3
179181
with:
180182
name: symbol-list
183+
path: symbol-list
181184

182185
- name: Install abi-compliance-checker
183186
run: sudo apt-get install abi-compliance-checker

.github/workflows/release-binaries.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
matrix:
6969
target:
7070
- triple: x86_64-linux-gnu-ubuntu-22.04
71-
runs-on: ubuntu-22.04-8x32
71+
runs-on: ubuntu-22.04-16x64
7272
debian-build-deps: >
7373
chrpath
7474
gcc-multilib

bolt/include/bolt/Core/BinaryContext.h

+9
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,15 @@ class BinaryContext {
871871
return nullptr;
872872
}
873873

874+
/// Retrieves a reference to ELF's _GLOBAL_OFFSET_TABLE_ symbol, which points
875+
/// at GOT, or null if it is not present in the input binary symtab.
876+
BinaryData *getGOTSymbol();
877+
878+
/// Checks if symbol name refers to ELF's _GLOBAL_OFFSET_TABLE_ symbol
879+
bool isGOTSymbol(StringRef SymName) const {
880+
return SymName == "_GLOBAL_OFFSET_TABLE_";
881+
}
882+
874883
/// Return true if \p SymbolName was generated internally and was not present
875884
/// in the input binary.
876885
bool isInternalSymbolName(const StringRef Name) {

bolt/include/bolt/Core/MCPlus.h

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class MCAnnotation {
6666
kTailCall, /// Tail call.
6767
kConditionalTailCall, /// CTC.
6868
kOffset, /// Offset in the function.
69+
kLabel, /// MCSymbol pointing to this instruction.
6970
kGeneric /// First generic annotation.
7071
};
7172

bolt/include/bolt/Core/MCPlusBuilder.h

+16-5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class MCPlusBuilder {
160160
const MCInstrAnalysis *Analysis;
161161
const MCInstrInfo *Info;
162162
const MCRegisterInfo *RegInfo;
163+
const MCSubtargetInfo *STI;
163164

164165
/// Map annotation name into an annotation index.
165166
StringMap<uint64_t> AnnotationNameIndexMap;
@@ -331,8 +332,8 @@ class MCPlusBuilder {
331332

332333
public:
333334
MCPlusBuilder(const MCInstrAnalysis *Analysis, const MCInstrInfo *Info,
334-
const MCRegisterInfo *RegInfo)
335-
: Analysis(Analysis), Info(Info), RegInfo(RegInfo) {
335+
const MCRegisterInfo *RegInfo, const MCSubtargetInfo *STI)
336+
: Analysis(Analysis), Info(Info), RegInfo(RegInfo), STI(STI) {
336337
// Initialize the default annotation allocator with id 0
337338
AnnotationAllocators.emplace(0, AnnotationAllocator());
338339
MaxAllocatorId++;
@@ -1179,6 +1180,13 @@ class MCPlusBuilder {
11791180
/// Remove offset annotation.
11801181
bool clearOffset(MCInst &Inst);
11811182

1183+
/// Return the label of \p Inst, if available.
1184+
std::optional<MCSymbol *> getLabel(const MCInst &Inst) const;
1185+
1186+
/// Set the label of \p Inst. This label will be emitted right before \p Inst
1187+
/// is emitted to MCStreamer.
1188+
bool setLabel(MCInst &Inst, MCSymbol *Label);
1189+
11821190
/// Return MCSymbol that represents a target of this instruction at a given
11831191
/// operand number \p OpNum. If there's no symbol associated with
11841192
/// the operand - return nullptr.
@@ -2079,15 +2087,18 @@ class MCPlusBuilder {
20792087

20802088
MCPlusBuilder *createX86MCPlusBuilder(const MCInstrAnalysis *,
20812089
const MCInstrInfo *,
2082-
const MCRegisterInfo *);
2090+
const MCRegisterInfo *,
2091+
const MCSubtargetInfo *);
20832092

20842093
MCPlusBuilder *createAArch64MCPlusBuilder(const MCInstrAnalysis *,
20852094
const MCInstrInfo *,
2086-
const MCRegisterInfo *);
2095+
const MCRegisterInfo *,
2096+
const MCSubtargetInfo *);
20872097

20882098
MCPlusBuilder *createRISCVMCPlusBuilder(const MCInstrAnalysis *,
20892099
const MCInstrInfo *,
2090-
const MCRegisterInfo *);
2100+
const MCRegisterInfo *,
2101+
const MCSubtargetInfo *);
20912102

20922103
} // namespace bolt
20932104
} // namespace llvm

bolt/include/bolt/Core/Relocation.h

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct Relocation {
8484

8585
/// Special relocation type that allows the linker to modify the instruction.
8686
static bool isX86GOTPCRELX(uint64_t Type);
87+
static bool isX86GOTPC64(uint64_t Type);
8788

8889
/// Return true if relocation type is NONE
8990
static bool isNone(uint64_t Type);
@@ -97,6 +98,10 @@ struct Relocation {
9798
/// Return true if relocation type is for thread local storage.
9899
static bool isTLS(uint64_t Type);
99100

101+
/// Return true of relocation type is for referencing a specific instruction
102+
/// (as opposed to a function, basic block, etc).
103+
static bool isInstructionReference(uint64_t Type);
104+
100105
/// Return code for a NONE relocation
101106
static uint64_t getNone();
102107

bolt/include/bolt/Rewrite/RewriteInstance.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ class RewriteInstance {
584584
MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
585585
const MCInstrAnalysis *Analysis,
586586
const MCInstrInfo *Info,
587-
const MCRegisterInfo *RegInfo);
587+
const MCRegisterInfo *RegInfo,
588+
const MCSubtargetInfo *STI);
588589

589590
} // namespace bolt
590591
} // namespace llvm

bolt/lib/Core/BinaryContext.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,31 @@ BinaryContext::getBinaryDataContainingAddressImpl(uint64_t Address) const {
10261026
return nullptr;
10271027
}
10281028

1029+
BinaryData *BinaryContext::getGOTSymbol() {
1030+
// First tries to find a global symbol with that name
1031+
BinaryData *GOTSymBD = getBinaryDataByName("_GLOBAL_OFFSET_TABLE_");
1032+
if (GOTSymBD)
1033+
return GOTSymBD;
1034+
1035+
// This symbol might be hidden from run-time link, so fetch the local
1036+
// definition if available.
1037+
GOTSymBD = getBinaryDataByName("_GLOBAL_OFFSET_TABLE_/1");
1038+
if (!GOTSymBD)
1039+
return nullptr;
1040+
1041+
// If the local symbol is not unique, fail
1042+
unsigned Index = 2;
1043+
SmallString<30> Storage;
1044+
while (const BinaryData *BD =
1045+
getBinaryDataByName(Twine("_GLOBAL_OFFSET_TABLE_/")
1046+
.concat(Twine(Index++))
1047+
.toStringRef(Storage)))
1048+
if (BD->getAddress() != GOTSymBD->getAddress())
1049+
return nullptr;
1050+
1051+
return GOTSymBD;
1052+
}
1053+
10291054
bool BinaryContext::setBinaryDataSize(uint64_t Address, uint64_t Size) {
10301055
auto NI = BinaryDataMap.find(Address);
10311056
assert(NI != BinaryDataMap.end());
@@ -1863,6 +1888,8 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
18631888
}
18641889
if (std::optional<uint32_t> Offset = MIB->getOffset(Instruction))
18651890
OS << " # Offset: " << *Offset;
1891+
if (auto Label = MIB->getLabel(Instruction))
1892+
OS << " # Label: " << **Label;
18661893

18671894
MIB->printAnnotations(Instruction, OS);
18681895

bolt/lib/Core/BinaryEmitter.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
498498
BB->getLocSyms().emplace_back(Offset, LocSym);
499499
}
500500

501+
if (auto Label = BC.MIB->getLabel(Instr))
502+
Streamer.emitLabel(*Label);
503+
501504
Streamer.emitInstruction(Instr, *BC.STI);
502505
LastIsPrefix = BC.MIB->isPrefix(Instr);
503506
}

bolt/lib/Core/BinaryFunction.cpp

+33-4
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,13 @@ bool BinaryFunction::disassemble() {
11731173
// basic block.
11741174
Labels[0] = Ctx->createNamedTempSymbol("BB0");
11751175

1176+
// Map offsets in the function to a label that should always point to the
1177+
// corresponding instruction. This is used for labels that shouldn't point to
1178+
// the start of a basic block but always to a specific instruction. This is
1179+
// used, for example, on RISC-V where %pcrel_lo relocations point to the
1180+
// corresponding %pcrel_hi.
1181+
LabelsMapType InstructionLabels;
1182+
11761183
uint64_t Size = 0; // instruction size
11771184
for (uint64_t Offset = 0; Offset < getSize(); Offset += Size) {
11781185
MCInst Instruction;
@@ -1329,9 +1336,23 @@ bool BinaryFunction::disassemble() {
13291336
ItrE = Relocations.lower_bound(Offset + Size);
13301337
Itr != ItrE; ++Itr) {
13311338
const Relocation &Relocation = Itr->second;
1339+
MCSymbol *Symbol = Relocation.Symbol;
1340+
1341+
if (Relocation::isInstructionReference(Relocation.Type)) {
1342+
uint64_t RefOffset = Relocation.Value - getAddress();
1343+
LabelsMapType::iterator LI = InstructionLabels.find(RefOffset);
1344+
1345+
if (LI == InstructionLabels.end()) {
1346+
Symbol = BC.Ctx->createNamedTempSymbol();
1347+
InstructionLabels.emplace(RefOffset, Symbol);
1348+
} else {
1349+
Symbol = LI->second;
1350+
}
1351+
}
1352+
13321353
int64_t Value = Relocation.Value;
13331354
const bool Result = BC.MIB->replaceImmWithSymbolRef(
1334-
Instruction, Relocation.Symbol, Relocation.Addend, Ctx.get(), Value,
1355+
Instruction, Symbol, Relocation.Addend, Ctx.get(), Value,
13351356
Relocation.Type);
13361357
(void)Result;
13371358
assert(Result && "cannot replace immediate with relocation");
@@ -1366,6 +1387,13 @@ bool BinaryFunction::disassemble() {
13661387
addInstruction(Offset, std::move(Instruction));
13671388
}
13681389

1390+
for (auto [Offset, Label] : InstructionLabels) {
1391+
InstrMapType::iterator II = Instructions.find(Offset);
1392+
assert(II != Instructions.end() && "reference to non-existing instruction");
1393+
1394+
BC.MIB->setLabel(II->second, Label);
1395+
}
1396+
13691397
// Reset symbolizer for the disassembler.
13701398
BC.SymbolicDisAsm->setSymbolizer(nullptr);
13711399

@@ -1761,7 +1789,8 @@ bool BinaryFunction::postProcessIndirectBranches(
17611789
uint64_t LastJT = 0;
17621790
uint16_t LastJTIndexReg = BC.MIB->getNoRegister();
17631791
for (BinaryBasicBlock &BB : blocks()) {
1764-
for (MCInst &Instr : BB) {
1792+
for (BinaryBasicBlock::iterator II = BB.begin(); II != BB.end(); ++II) {
1793+
MCInst &Instr = *II;
17651794
if (!BC.MIB->isIndirectBranch(Instr))
17661795
continue;
17671796

@@ -1789,7 +1818,7 @@ bool BinaryFunction::postProcessIndirectBranches(
17891818
const MCExpr *DispExpr;
17901819
MCInst *PCRelBaseInstr;
17911820
IndirectBranchType Type = BC.MIB->analyzeIndirectBranch(
1792-
Instr, BB.begin(), BB.end(), PtrSize, MemLocInstr, BaseRegNum,
1821+
Instr, BB.begin(), II, PtrSize, MemLocInstr, BaseRegNum,
17931822
IndexRegNum, DispValue, DispExpr, PCRelBaseInstr);
17941823
if (Type != IndirectBranchType::UNKNOWN || MemLocInstr != nullptr)
17951824
continue;
@@ -4488,7 +4517,7 @@ void BinaryFunction::addRelocation(uint64_t Address, MCSymbol *Symbol,
44884517
uint64_t Offset = Address - getAddress();
44894518
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: addRelocation in "
44904519
<< formatv("{0}@{1:x} against {2}\n", *this, Offset,
4491-
Symbol->getName()));
4520+
(Symbol ? Symbol->getName() : "<undef>")));
44924521
bool IsCI = BC.isAArch64() && isInConstantIsland(Address);
44934522
std::map<uint64_t, Relocation> &Rels =
44944523
IsCI ? Islands->Relocations : Relocations;

bolt/lib/Core/DebugData.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ void DebugAddrWriterDwarf5::update(DIEBuilder &DIEBlder, DWARFUnit &CU) {
495495
const endianness Endian =
496496
BC->DwCtx->isLittleEndian() ? support::little : support::big;
497497
const DWARFSection &AddrSec = BC->DwCtx->getDWARFObj().getAddrSection();
498-
DWARFDataExtractor AddrData(BC->DwCtx->getDWARFObj(), AddrSec, Endian, 0);
498+
DWARFDataExtractor AddrData(BC->DwCtx->getDWARFObj(), AddrSec,
499+
Endian == support::little, 0);
499500
DWARFDebugAddrTable AddrTable;
500501
DIDumpOptions DumpOpts;
501502
constexpr uint32_t HeaderSize = 8;

bolt/lib/Core/MCPlusBuilder.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,17 @@ bool MCPlusBuilder::clearOffset(MCInst &Inst) {
268268
return true;
269269
}
270270

271+
std::optional<MCSymbol *> MCPlusBuilder::getLabel(const MCInst &Inst) const {
272+
if (auto Label = tryGetAnnotationAs<MCSymbol *>(Inst, MCAnnotation::kLabel))
273+
return *Label;
274+
return std::nullopt;
275+
}
276+
277+
bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label) {
278+
getOrCreateAnnotationAs<MCSymbol *>(Inst, MCAnnotation::kLabel) = Label;
279+
return true;
280+
}
281+
271282
bool MCPlusBuilder::hasAnnotation(const MCInst &Inst, unsigned Index) const {
272283
const MCInst *AnnotationInst = getAnnotationInst(Inst);
273284
if (!AnnotationInst)

0 commit comments

Comments
 (0)