Skip to content

Commit

Permalink
Merge branch 'main' into fold-icmp-eq-zext-eq-self
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Oct 6, 2023
2 parents 2285a2c + 0d7947b commit 7e81e63
Show file tree
Hide file tree
Showing 1,504 changed files with 59,295 additions and 25,216 deletions.
2 changes: 1 addition & 1 deletion .ci/generate-buildkite-pipeline-premerge
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set -o pipefail

# Environment variables script works with:
# List of files affected by this commit
: ${MODIFIED_FILES:=$(git diff --name-only main...HEAD)}
: ${MODIFIED_FILES:=$(git diff --name-only HEAD~1)}
# Filter rules for generic windows tests
: ${WINDOWS_AGENTS:='{"queue": "windows"}'}
# Filter rules for generic linux tests
Expand Down
28 changes: 28 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
# This file lists reviewers that are auto-assigned when a pull request modifies
# certain files or directories. If you add yourself to this file, you commit to
# reviewing a large fraction of pull requests in the relevant area.
#
# The GitHub "code owners" mechanism is used exclusively to auto-assign
# reviewers and does not carry significance beyond that. It is not necessary
# to receive an approval from a "code owner" in particular -- any LLVM project
# member can approve pull requests.
#
# Note that GitHub's concept of "code owner" is independent from LLVM's own
# "code owner" concept, they merely happen to share terminology. See
# https://llvm.org/docs/DeveloperPolicy.html#code-owners, as well as the
# CODE_OWNERS.txt files in the respective subproject directories.

/libcxx/ @llvm/reviewers-libcxx
/libcxxabi/ @llvm/reviewers-libcxxabi
/libunwind/ @llvm/reviewers-libunwind
/runtimes/ @llvm/reviewers-libcxx

/llvm/lib/Analysis/BasicAliasAnalysis.cpp @nikic
/llvm/lib/Analysis/InstructionSimplify.cpp @nikic
/llvm/lib/Analysis/LazyValueInfo.cpp @nikic
/llvm/lib/Analysis/ScalarEvolution.cpp @nikic
/llvm/lib/Analysis/ValueTracking.cpp @nikic
/llvm/lib/IR/ConstantRange.cpp @nikic
/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @nikic
/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @nikic
/llvm/lib/Transforms/InstCombine/ @nikic

/clang/test/CXX/drs/ @Endilll
/clang/www/cxx_dr_status.html @Endilll
/clang/www/make_cxx_dr_status @Endilll
3 changes: 3 additions & 0 deletions .github/workflows/llvm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,17 @@ jobs:
uses: actions/download-artifact@v3
with:
name: build-baseline
path: build-baseline
- name: Download latest
uses: actions/download-artifact@v3
with:
name: build-latest
path: build-latest
- name: Download symbol list
uses: actions/download-artifact@v3
with:
name: symbol-list
path: symbol-list

- name: Install abi-compliance-checker
run: sudo apt-get install abi-compliance-checker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
matrix:
target:
- triple: x86_64-linux-gnu-ubuntu-22.04
runs-on: ubuntu-22.04-8x32
runs-on: ubuntu-22.04-16x64
debian-build-deps: >
chrpath
gcc-multilib
Expand Down
9 changes: 9 additions & 0 deletions bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,15 @@ class BinaryContext {
return nullptr;
}

/// Retrieves a reference to ELF's _GLOBAL_OFFSET_TABLE_ symbol, which points
/// at GOT, or null if it is not present in the input binary symtab.
BinaryData *getGOTSymbol();

/// Checks if symbol name refers to ELF's _GLOBAL_OFFSET_TABLE_ symbol
bool isGOTSymbol(StringRef SymName) const {
return SymName == "_GLOBAL_OFFSET_TABLE_";
}

/// Return true if \p SymbolName was generated internally and was not present
/// in the input binary.
bool isInternalSymbolName(const StringRef Name) {
Expand Down
1 change: 1 addition & 0 deletions bolt/include/bolt/Core/MCPlus.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MCAnnotation {
kTailCall, /// Tail call.
kConditionalTailCall, /// CTC.
kOffset, /// Offset in the function.
kLabel, /// MCSymbol pointing to this instruction.
kGeneric /// First generic annotation.
};

Expand Down
21 changes: 16 additions & 5 deletions bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class MCPlusBuilder {
const MCInstrAnalysis *Analysis;
const MCInstrInfo *Info;
const MCRegisterInfo *RegInfo;
const MCSubtargetInfo *STI;

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

public:
MCPlusBuilder(const MCInstrAnalysis *Analysis, const MCInstrInfo *Info,
const MCRegisterInfo *RegInfo)
: Analysis(Analysis), Info(Info), RegInfo(RegInfo) {
const MCRegisterInfo *RegInfo, const MCSubtargetInfo *STI)
: Analysis(Analysis), Info(Info), RegInfo(RegInfo), STI(STI) {
// Initialize the default annotation allocator with id 0
AnnotationAllocators.emplace(0, AnnotationAllocator());
MaxAllocatorId++;
Expand Down Expand Up @@ -1179,6 +1180,13 @@ class MCPlusBuilder {
/// Remove offset annotation.
bool clearOffset(MCInst &Inst);

/// Return the label of \p Inst, if available.
std::optional<MCSymbol *> getLabel(const MCInst &Inst) const;

/// Set the label of \p Inst. This label will be emitted right before \p Inst
/// is emitted to MCStreamer.
bool setLabel(MCInst &Inst, MCSymbol *Label);

/// Return MCSymbol that represents a target of this instruction at a given
/// operand number \p OpNum. If there's no symbol associated with
/// the operand - return nullptr.
Expand Down Expand Up @@ -2079,15 +2087,18 @@ class MCPlusBuilder {

MCPlusBuilder *createX86MCPlusBuilder(const MCInstrAnalysis *,
const MCInstrInfo *,
const MCRegisterInfo *);
const MCRegisterInfo *,
const MCSubtargetInfo *);

MCPlusBuilder *createAArch64MCPlusBuilder(const MCInstrAnalysis *,
const MCInstrInfo *,
const MCRegisterInfo *);
const MCRegisterInfo *,
const MCSubtargetInfo *);

MCPlusBuilder *createRISCVMCPlusBuilder(const MCInstrAnalysis *,
const MCInstrInfo *,
const MCRegisterInfo *);
const MCRegisterInfo *,
const MCSubtargetInfo *);

} // namespace bolt
} // namespace llvm
Expand Down
5 changes: 5 additions & 0 deletions bolt/include/bolt/Core/Relocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct Relocation {

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

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

/// Return true of relocation type is for referencing a specific instruction
/// (as opposed to a function, basic block, etc).
static bool isInstructionReference(uint64_t Type);

/// Return code for a NONE relocation
static uint64_t getNone();

Expand Down
3 changes: 2 additions & 1 deletion bolt/include/bolt/Rewrite/RewriteInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ class RewriteInstance {
MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
const MCInstrAnalysis *Analysis,
const MCInstrInfo *Info,
const MCRegisterInfo *RegInfo);
const MCRegisterInfo *RegInfo,
const MCSubtargetInfo *STI);

} // namespace bolt
} // namespace llvm
Expand Down
27 changes: 27 additions & 0 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,31 @@ BinaryContext::getBinaryDataContainingAddressImpl(uint64_t Address) const {
return nullptr;
}

BinaryData *BinaryContext::getGOTSymbol() {
// First tries to find a global symbol with that name
BinaryData *GOTSymBD = getBinaryDataByName("_GLOBAL_OFFSET_TABLE_");
if (GOTSymBD)
return GOTSymBD;

// This symbol might be hidden from run-time link, so fetch the local
// definition if available.
GOTSymBD = getBinaryDataByName("_GLOBAL_OFFSET_TABLE_/1");
if (!GOTSymBD)
return nullptr;

// If the local symbol is not unique, fail
unsigned Index = 2;
SmallString<30> Storage;
while (const BinaryData *BD =
getBinaryDataByName(Twine("_GLOBAL_OFFSET_TABLE_/")
.concat(Twine(Index++))
.toStringRef(Storage)))
if (BD->getAddress() != GOTSymBD->getAddress())
return nullptr;

return GOTSymBD;
}

bool BinaryContext::setBinaryDataSize(uint64_t Address, uint64_t Size) {
auto NI = BinaryDataMap.find(Address);
assert(NI != BinaryDataMap.end());
Expand Down Expand Up @@ -1863,6 +1888,8 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
}
if (std::optional<uint32_t> Offset = MIB->getOffset(Instruction))
OS << " # Offset: " << *Offset;
if (auto Label = MIB->getLabel(Instruction))
OS << " # Label: " << **Label;

MIB->printAnnotations(Instruction, OS);

Expand Down
3 changes: 3 additions & 0 deletions bolt/lib/Core/BinaryEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
BB->getLocSyms().emplace_back(Offset, LocSym);
}

if (auto Label = BC.MIB->getLabel(Instr))
Streamer.emitLabel(*Label);

Streamer.emitInstruction(Instr, *BC.STI);
LastIsPrefix = BC.MIB->isPrefix(Instr);
}
Expand Down
37 changes: 33 additions & 4 deletions bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,13 @@ bool BinaryFunction::disassemble() {
// basic block.
Labels[0] = Ctx->createNamedTempSymbol("BB0");

// Map offsets in the function to a label that should always point to the
// corresponding instruction. This is used for labels that shouldn't point to
// the start of a basic block but always to a specific instruction. This is
// used, for example, on RISC-V where %pcrel_lo relocations point to the
// corresponding %pcrel_hi.
LabelsMapType InstructionLabels;

uint64_t Size = 0; // instruction size
for (uint64_t Offset = 0; Offset < getSize(); Offset += Size) {
MCInst Instruction;
Expand Down Expand Up @@ -1329,9 +1336,23 @@ bool BinaryFunction::disassemble() {
ItrE = Relocations.lower_bound(Offset + Size);
Itr != ItrE; ++Itr) {
const Relocation &Relocation = Itr->second;
MCSymbol *Symbol = Relocation.Symbol;

if (Relocation::isInstructionReference(Relocation.Type)) {
uint64_t RefOffset = Relocation.Value - getAddress();
LabelsMapType::iterator LI = InstructionLabels.find(RefOffset);

if (LI == InstructionLabels.end()) {
Symbol = BC.Ctx->createNamedTempSymbol();
InstructionLabels.emplace(RefOffset, Symbol);
} else {
Symbol = LI->second;
}
}

int64_t Value = Relocation.Value;
const bool Result = BC.MIB->replaceImmWithSymbolRef(
Instruction, Relocation.Symbol, Relocation.Addend, Ctx.get(), Value,
Instruction, Symbol, Relocation.Addend, Ctx.get(), Value,
Relocation.Type);
(void)Result;
assert(Result && "cannot replace immediate with relocation");
Expand Down Expand Up @@ -1366,6 +1387,13 @@ bool BinaryFunction::disassemble() {
addInstruction(Offset, std::move(Instruction));
}

for (auto [Offset, Label] : InstructionLabels) {
InstrMapType::iterator II = Instructions.find(Offset);
assert(II != Instructions.end() && "reference to non-existing instruction");

BC.MIB->setLabel(II->second, Label);
}

// Reset symbolizer for the disassembler.
BC.SymbolicDisAsm->setSymbolizer(nullptr);

Expand Down Expand Up @@ -1761,7 +1789,8 @@ bool BinaryFunction::postProcessIndirectBranches(
uint64_t LastJT = 0;
uint16_t LastJTIndexReg = BC.MIB->getNoRegister();
for (BinaryBasicBlock &BB : blocks()) {
for (MCInst &Instr : BB) {
for (BinaryBasicBlock::iterator II = BB.begin(); II != BB.end(); ++II) {
MCInst &Instr = *II;
if (!BC.MIB->isIndirectBranch(Instr))
continue;

Expand Down Expand Up @@ -1789,7 +1818,7 @@ bool BinaryFunction::postProcessIndirectBranches(
const MCExpr *DispExpr;
MCInst *PCRelBaseInstr;
IndirectBranchType Type = BC.MIB->analyzeIndirectBranch(
Instr, BB.begin(), BB.end(), PtrSize, MemLocInstr, BaseRegNum,
Instr, BB.begin(), II, PtrSize, MemLocInstr, BaseRegNum,
IndexRegNum, DispValue, DispExpr, PCRelBaseInstr);
if (Type != IndirectBranchType::UNKNOWN || MemLocInstr != nullptr)
continue;
Expand Down Expand Up @@ -4488,7 +4517,7 @@ void BinaryFunction::addRelocation(uint64_t Address, MCSymbol *Symbol,
uint64_t Offset = Address - getAddress();
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: addRelocation in "
<< formatv("{0}@{1:x} against {2}\n", *this, Offset,
Symbol->getName()));
(Symbol ? Symbol->getName() : "<undef>")));
bool IsCI = BC.isAArch64() && isInConstantIsland(Address);
std::map<uint64_t, Relocation> &Rels =
IsCI ? Islands->Relocations : Relocations;
Expand Down
3 changes: 2 additions & 1 deletion bolt/lib/Core/DebugData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ void DebugAddrWriterDwarf5::update(DIEBuilder &DIEBlder, DWARFUnit &CU) {
const endianness Endian =
BC->DwCtx->isLittleEndian() ? support::little : support::big;
const DWARFSection &AddrSec = BC->DwCtx->getDWARFObj().getAddrSection();
DWARFDataExtractor AddrData(BC->DwCtx->getDWARFObj(), AddrSec, Endian, 0);
DWARFDataExtractor AddrData(BC->DwCtx->getDWARFObj(), AddrSec,
Endian == support::little, 0);
DWARFDebugAddrTable AddrTable;
DIDumpOptions DumpOpts;
constexpr uint32_t HeaderSize = 8;
Expand Down
11 changes: 11 additions & 0 deletions bolt/lib/Core/MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ bool MCPlusBuilder::clearOffset(MCInst &Inst) {
return true;
}

std::optional<MCSymbol *> MCPlusBuilder::getLabel(const MCInst &Inst) const {
if (auto Label = tryGetAnnotationAs<MCSymbol *>(Inst, MCAnnotation::kLabel))
return *Label;
return std::nullopt;
}

bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label) {
getOrCreateAnnotationAs<MCSymbol *>(Inst, MCAnnotation::kLabel) = Label;
return true;
}

bool MCPlusBuilder::hasAnnotation(const MCInst &Inst, unsigned Index) const {
const MCInst *AnnotationInst = getAnnotationInst(Inst);
if (!AnnotationInst)
Expand Down
Loading

0 comments on commit 7e81e63

Please sign in to comment.