[llvm] [BOLT] Use Label annotation instead of EHLabel pseudo. NFCI. (PR #70179)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 25 01:33:56 PDT 2023
https://github.com/maksfb created https://github.com/llvm/llvm-project/pull/70179
When we need to attach EH label to an instruction, we can now use Label annotation instead of EHLabel pseudo instruction.
>From 6ed276f43d24a482c37c67d6918a2accd30dcc79 Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Wed, 25 Oct 2023 01:25:48 -0700
Subject: [PATCH] [BOLT] Use Label annotation instead of EHLabel pseudo. NFCI.
When we need to attach EH label to an instruction, we can now use Label
annotation instead of EHLabel pseudo instruction.
---
bolt/include/bolt/Core/MCPlusBuilder.h | 13 -------------
bolt/lib/Core/BinaryContext.cpp | 4 ----
bolt/lib/Core/BinaryEmitter.cpp | 7 -------
bolt/lib/Core/Exceptions.cpp | 19 +++++++++----------
bolt/lib/Passes/StokeInfo.cpp | 8 +++++++-
5 files changed, 16 insertions(+), 35 deletions(-)
diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h
index d136c627bc5cc10..6354f42b7f3492a 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -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.
@@ -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:
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index 8e2331db3e33032..cdfcd46b5270959 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -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();
diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp
index de80a99a74ed080..6088216a84adedc 100644
--- a/bolt/lib/Core/BinaryEmitter.cpp
+++ b/bolt/lib/Core/BinaryEmitter.cpp
@@ -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;
diff --git a/bolt/lib/Core/Exceptions.cpp b/bolt/lib/Core/Exceptions.cpp
index 667f1757e13d710..f8e07f2fa171f77 100644
--- a/bolt/lib/Core/Exceptions.cpp
+++ b/bolt/lib/Core/Exceptions.cpp
@@ -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)
@@ -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.
@@ -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
diff --git a/bolt/lib/Passes/StokeInfo.cpp b/bolt/lib/Passes/StokeInfo.cpp
index 57e5a08113dd0f1..419ba236e1342b0 100644
--- a/bolt/lib/Passes/StokeInfo.cpp
+++ b/bolt/lib/Passes/StokeInfo.cpp
@@ -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;
}
More information about the llvm-commits
mailing list