Skip to content

Commit 0df1546

Browse files
authored
[BOLT] Use Label annotation instead of EHLabel pseudo. NFCI. (llvm#70179)
When we need to attach EH label to an instruction, we can now use Label annotation instead of EHLabel pseudo instruction.
1 parent c6a198c commit 0df1546

File tree

6 files changed

+16
-36
lines changed

6 files changed

+16
-36
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,6 @@ class MCPlusBuilder {
557557
return false;
558558
}
559559

560-
virtual bool isEHLabel(const MCInst &Inst) const {
561-
return Inst.getOpcode() == TargetOpcode::EH_LABEL;
562-
}
563-
564560
virtual bool isPop(const MCInst &Inst) const { return false; }
565561

566562
/// Return true if the instruction is used to terminate an indirect branch.
@@ -1736,15 +1732,6 @@ class MCPlusBuilder {
17361732
return false;
17371733
}
17381734

1739-
virtual bool createEHLabel(MCInst &Inst, const MCSymbol *Label,
1740-
MCContext *Ctx) const {
1741-
Inst.setOpcode(TargetOpcode::EH_LABEL);
1742-
Inst.clear();
1743-
Inst.addOperand(MCOperand::createExpr(
1744-
MCSymbolRefExpr::create(Label, MCSymbolRefExpr::VK_None, *Ctx)));
1745-
return true;
1746-
}
1747-
17481735
/// Extract a symbol and an addend out of the fixup value expression.
17491736
///
17501737
/// Only the following limited expression types are supported:

bolt/lib/Core/BinaryContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,10 +1862,6 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
18621862
bool PrintMCInst, bool PrintMemData,
18631863
bool PrintRelocations,
18641864
StringRef Endl) const {
1865-
if (MIB->isEHLabel(Instruction)) {
1866-
OS << " EH_LABEL: " << *MIB->getTargetSymbol(Instruction) << Endl;
1867-
return;
1868-
}
18691865
OS << format(" %08" PRIx64 ": ", Offset);
18701866
if (MIB->isCFI(Instruction)) {
18711867
uint32_t Offset = Instruction.getOperand(0).getImm();

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,6 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
469469
continue;
470470

471471
// Handle pseudo instructions.
472-
if (BC.MIB->isEHLabel(Instr)) {
473-
const MCSymbol *Label = BC.MIB->getTargetSymbol(Instr);
474-
assert(Instr.getNumOperands() >= 1 && Label &&
475-
"bad EH_LABEL instruction");
476-
Streamer.emitLabel(const_cast<MCSymbol *>(Label));
477-
continue;
478-
}
479472
if (BC.MIB->isCFI(Instr)) {
480473
emitCFIInstruction(*BF.getCFIFor(Instr));
481474
continue;

bolt/lib/Core/Exceptions.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,12 @@ void BinaryFunction::updateEHRanges() {
373373
const MCSymbol *StartRange = nullptr;
374374

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

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

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

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

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

408-
II = std::next(BB->insertPseudoInstr(II, EHLabel));
409-
410409
// At this point we could be in one of the following states:
411410
//
412411
// I. Exception handler has changed and we need to close previous range

bolt/lib/Passes/StokeInfo.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ void StokeInfo::checkInstr(const BinaryFunction &BF, StokeFuncInfo &FuncInfo) {
5050
if (BB->empty())
5151
continue;
5252

53+
// Skip function with exception handling.
54+
if (BB->throw_size() || BB->lp_size()) {
55+
FuncInfo.Omitted = true;
56+
return;
57+
}
58+
5359
for (const MCInst &It : *BB) {
5460
if (MIB->isPseudo(It))
5561
continue;
5662
// skip function with exception handling yet
57-
if (MIB->isEHLabel(It) || MIB->isInvoke(It)) {
63+
if (MIB->isInvoke(It)) {
5864
FuncInfo.Omitted = true;
5965
return;
6066
}

bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
320320
default:
321321
return false;
322322
case RISCV::C_J:
323-
case TargetOpcode::EH_LABEL:
324323
OpNum = 0;
325324
return true;
326325
case RISCV::AUIPC:

0 commit comments

Comments
 (0)