Skip to content

[BOLT] Use Label annotation instead of EHLabel pseudo. NFCI. #70179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,6 @@ class MCPlusBuilder {
return false;
}

virtual bool isEHLabel(const MCInst &Inst) const {
return Inst.getOpcode() == TargetOpcode::EH_LABEL;
}

virtual bool isPop(const MCInst &Inst) const { return false; }

/// Return true if the instruction is used to terminate an indirect branch.
Expand Down Expand Up @@ -1740,15 +1736,6 @@ class MCPlusBuilder {
return false;
}

virtual bool createEHLabel(MCInst &Inst, const MCSymbol *Label,
MCContext *Ctx) const {
Inst.setOpcode(TargetOpcode::EH_LABEL);
Inst.clear();
Inst.addOperand(MCOperand::createExpr(
MCSymbolRefExpr::create(Label, MCSymbolRefExpr::VK_None, *Ctx)));
return true;
}

/// Extract a symbol and an addend out of the fixup value expression.
///
/// Only the following limited expression types are supported:
Expand Down
4 changes: 0 additions & 4 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1862,10 +1862,6 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
bool PrintMCInst, bool PrintMemData,
bool PrintRelocations,
StringRef Endl) const {
if (MIB->isEHLabel(Instruction)) {
OS << " EH_LABEL: " << *MIB->getTargetSymbol(Instruction) << Endl;
return;
}
OS << format(" %08" PRIx64 ": ", Offset);
if (MIB->isCFI(Instruction)) {
uint32_t Offset = Instruction.getOperand(0).getImm();
Expand Down
7 changes: 0 additions & 7 deletions bolt/lib/Core/BinaryEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,6 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
continue;

// Handle pseudo instructions.
if (BC.MIB->isEHLabel(Instr)) {
const MCSymbol *Label = BC.MIB->getTargetSymbol(Instr);
assert(Instr.getNumOperands() >= 1 && Label &&
"bad EH_LABEL instruction");
Streamer.emitLabel(const_cast<MCSymbol *>(Label));
continue;
}
if (BC.MIB->isCFI(Instr)) {
emitCFIInstruction(*BF.getCFIFor(Instr));
continue;
Expand Down
19 changes: 9 additions & 10 deletions bolt/lib/Core/Exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@ void BinaryFunction::updateEHRanges() {
const MCSymbol *StartRange = nullptr;

for (BinaryBasicBlock *const BB : FF) {
for (auto II = BB->begin(); II != BB->end(); ++II) {
if (!BC.MIB->isCall(*II))
for (MCInst &Instr : *BB) {
if (!BC.MIB->isCall(Instr))
continue;

// Instruction can throw an exception that should be handled.
const bool Throws = BC.MIB->isInvoke(*II);
const bool Throws = BC.MIB->isInvoke(Instr);

// Ignore the call if it's a continuation of a no-throw gap.
if (!Throws && !StartRange)
Expand All @@ -388,7 +388,7 @@ void BinaryFunction::updateEHRanges() {
const MCSymbol *LP = nullptr;
uint64_t Action = 0;
if (const std::optional<MCPlus::MCLandingPad> EHInfo =
BC.MIB->getEHInfo(*II))
BC.MIB->getEHInfo(Instr))
std::tie(LP, Action) = *EHInfo;

// No action if the exception handler has not changed.
Expand All @@ -397,16 +397,15 @@ void BinaryFunction::updateEHRanges() {
continue;

// Same symbol is used for the beginning and the end of the range.
const MCSymbol *EHSymbol;
MCInst EHLabel;
{
MCSymbol *EHSymbol;
if (auto InstrLabel = BC.MIB->getLabel(Instr)) {
EHSymbol = *InstrLabel;
} else {
std::unique_lock<llvm::sys::RWMutex> Lock(BC.CtxMutex);
EHSymbol = BC.Ctx->createNamedTempSymbol("EH");
BC.MIB->createEHLabel(EHLabel, EHSymbol, BC.Ctx.get());
BC.MIB->setLabel(Instr, EHSymbol);
}

II = std::next(BB->insertPseudoInstr(II, EHLabel));

// At this point we could be in one of the following states:
//
// I. Exception handler has changed and we need to close previous range
Expand Down
8 changes: 7 additions & 1 deletion bolt/lib/Passes/StokeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ void StokeInfo::checkInstr(const BinaryFunction &BF, StokeFuncInfo &FuncInfo) {
if (BB->empty())
continue;

// Skip function with exception handling.
if (BB->throw_size() || BB->lp_size()) {
FuncInfo.Omitted = true;
return;
}

for (const MCInst &It : *BB) {
if (MIB->isPseudo(It))
continue;
// skip function with exception handling yet
if (MIB->isEHLabel(It) || MIB->isInvoke(It)) {
if (MIB->isInvoke(It)) {
FuncInfo.Omitted = true;
return;
}
Expand Down
1 change: 0 additions & 1 deletion bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
default:
return false;
case RISCV::C_J:
case TargetOpcode::EH_LABEL:
OpNum = 0;
return true;
case RISCV::AUIPC:
Expand Down