[llvm] undo breaking changes from "Reduce AsmPrinterHandlers virt. fn calls" without reverting the performance gains (PR #122297)
Jameson Nash via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 13 11:55:32 PST 2025
https://github.com/vtjnash updated https://github.com/llvm/llvm-project/pull/122297
>From 01480ddd13d76f45772c44466fec3684f4347c65 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash at gmail.com>
Date: Thu, 9 Jan 2025 15:06:56 +0000
Subject: [PATCH 1/3] undo breaking changes from "Reduce AsmPrinterHandlers
virt. fn calls" without reverting the performance gains
As foreshadowed by the author's comment before merging
https://github.com/llvm/llvm-project/pull/96785#discussion_r1660779772,
this turned out to be pretty awkward for user handlers, since overriding
DebugHandlerBase itself adds a lot of undesirable hidden state and
assumptions, which segfault if we overload it wrong. Add an extra
hierarchy in the class structure so that we keep the performance gains
from splitting up the basic EH handles, without needing to break the API
from LLVM v18.
---
llvm/include/llvm/CodeGen/AsmPrinter.h | 13 +++--
llvm/include/llvm/CodeGen/AsmPrinterHandler.h | 21 +++++++-
llvm/include/llvm/CodeGen/DebugHandlerBase.h | 28 ++++------
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 14 ++---
llvm/lib/CodeGen/AsmPrinter/EHStreamer.h | 2 +-
.../CodeGen/AsmPrinter/PseudoProbePrinter.h | 2 +-
llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h | 2 +-
.../unittests/CodeGen/AsmPrinterDwarfTest.cpp | 53 ++-----------------
8 files changed, 46 insertions(+), 89 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h
index c9a88d7b1c015c..e3e75f6f463c64 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -33,6 +33,7 @@
namespace llvm {
class AddrLabelMap;
+class AsmBasicPrinterHandler;
class AsmPrinterHandler;
class BasicBlock;
class BlockAddress;
@@ -187,13 +188,13 @@ class AsmPrinter : public MachineFunctionPass {
/// For dso_local functions, the current $local alias for the function.
MCSymbol *CurrentFnBeginLocal = nullptr;
- /// A vector of all debug/EH info emitters we should use. This vector
+ /// A vector of all EH info emitters we should use. This vector
/// maintains ownership of the emitters.
- SmallVector<std::unique_ptr<AsmPrinterHandler>, 2> Handlers;
- size_t NumUserHandlers = 0;
+ SmallVector<std::unique_ptr<AsmBasicPrinterHandler>, 2> Handlers;
- /// Debuginfo handler. Protected so that targets can add their own.
- SmallVector<std::unique_ptr<DebugHandlerBase>, 1> DebugHandlers;
+ // A vector of all Debuginfo emitters we should use. Protected so that
+ // targets can add their own.
+ SmallVector<std::unique_ptr<AsmPrinterHandler>, 1> DebugHandlers;
size_t NumUserDebugHandlers = 0;
StackMaps SM;
@@ -527,8 +528,6 @@ class AsmPrinter : public MachineFunctionPass {
void addAsmPrinterHandler(std::unique_ptr<AsmPrinterHandler> Handler);
- void addDebugHandler(std::unique_ptr<DebugHandlerBase> Handler);
-
// Targets can, or in the case of EmitInstruction, must implement these to
// customize output.
diff --git a/llvm/include/llvm/CodeGen/AsmPrinterHandler.h b/llvm/include/llvm/CodeGen/AsmPrinterHandler.h
index ed73e618431ded..daf8793f4ddaf6 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinterHandler.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinterHandler.h
@@ -30,9 +30,9 @@ typedef MCSymbol *ExceptionSymbolProvider(AsmPrinter *Asm,
/// Collects and handles AsmPrinter objects required to build debug
/// or EH information.
-class AsmPrinterHandler {
+class AsmBasicPrinterHandler {
public:
- virtual ~AsmPrinterHandler();
+ virtual ~AsmBasicPrinterHandler();
virtual void beginModule(Module *M) {}
@@ -70,6 +70,23 @@ class AsmPrinterHandler {
virtual void endFunclet() {}
};
+class AsmPrinterHandler : public AsmBasicPrinterHandler {
+public:
+ virtual ~AsmPrinterHandler();
+
+ /// For symbols that have a size designated (e.g. common symbols),
+ /// this tracks that size.
+ virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) {}
+
+ /// Process beginning of an instruction.
+ virtual void beginInstruction(const MachineInstr *MI) = 0;
+
+ /// Process end of an instruction.
+ virtual void endInstruction() = 0;
+
+ virtual void beginCodeAlignment(const MachineBasicBlock &MBB) {}
+};
+
} // End of namespace llvm
#endif
diff --git a/llvm/include/llvm/CodeGen/DebugHandlerBase.h b/llvm/include/llvm/CodeGen/DebugHandlerBase.h
index d39e7e68cb2558..f669bd311ff564 100644
--- a/llvm/include/llvm/CodeGen/DebugHandlerBase.h
+++ b/llvm/include/llvm/CodeGen/DebugHandlerBase.h
@@ -50,14 +50,10 @@ struct DbgVariableLocation {
/// Base class for debug information backends. Common functionality related to
/// tracking which variables and scopes are alive at a given PC live here.
-class DebugHandlerBase {
+class DebugHandlerBase : public AsmPrinterHandler {
protected:
DebugHandlerBase(AsmPrinter *A);
-public:
- virtual ~DebugHandlerBase();
-
-protected:
/// Target of debug info emission.
AsmPrinter *Asm = nullptr;
@@ -120,24 +116,20 @@ class DebugHandlerBase {
private:
InstructionOrdering InstOrdering;
+ // AsmPrinterHandler overrides.
public:
- /// For symbols that have a size designated (e.g. common symbols),
- /// this tracks that size. Only used by DWARF.
- virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) {}
-
- virtual void beginModule(Module *M);
- virtual void endModule() = 0;
+ virtual ~DebugHandlerBase() override;
- virtual void beginInstruction(const MachineInstr *MI);
- virtual void endInstruction();
+ void beginModule(Module *M) override;
- void beginFunction(const MachineFunction *MF);
- void endFunction(const MachineFunction *MF);
+ void beginInstruction(const MachineInstr *MI) override;
+ void endInstruction() override;
- void beginBasicBlockSection(const MachineBasicBlock &MBB);
- void endBasicBlockSection(const MachineBasicBlock &MBB);
+ void beginFunction(const MachineFunction *MF) override;
+ void endFunction(const MachineFunction *MF) override;
- virtual void beginCodeAlignment(const MachineBasicBlock &MBB) {}
+ void beginBasicBlockSection(const MachineBasicBlock &MBB) override;
+ void endBasicBlockSection(const MachineBasicBlock &MBB) override;
/// Return Label preceding the instruction.
MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3ba45900e45691..5c952be3bce5ca 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -392,7 +392,7 @@ AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer> Streamer)
}
AsmPrinter::~AsmPrinter() {
- assert(!DD && Handlers.size() == NumUserHandlers &&
+ assert(!DD && DebugHandlers.size() == NumUserDebugHandlers &&
"Debug/EH info didn't get finalized");
}
@@ -2591,7 +2591,7 @@ bool AsmPrinter::doFinalization(Module &M) {
// This deletes all the ephemeral handlers that AsmPrinter added, while
// keeping all the user-added handlers alive until the AsmPrinter is
// destroyed.
- Handlers.erase(Handlers.begin() + NumUserHandlers, Handlers.end());
+ Handlers.clear();
DebugHandlers.erase(DebugHandlers.begin() + NumUserDebugHandlers,
DebugHandlers.end());
DD = nullptr;
@@ -4411,19 +4411,15 @@ void AsmPrinter::emitStackMaps() {
void AsmPrinter::addAsmPrinterHandler(
std::unique_ptr<AsmPrinterHandler> Handler) {
- Handlers.insert(Handlers.begin(), std::move(Handler));
- NumUserHandlers++;
-}
-
-void AsmPrinter::addDebugHandler(std::unique_ptr<DebugHandlerBase> Handler) {
DebugHandlers.insert(DebugHandlers.begin(), std::move(Handler));
NumUserDebugHandlers++;
}
-/// Pin vtable to this file.
+/// Pin vtables to this file.
+AsmBasicPrinterHandler::~AsmBasicPrinterHandler() = default;
AsmPrinterHandler::~AsmPrinterHandler() = default;
-void AsmPrinterHandler::markFunctionEnd() {}
+void AsmBasicPrinterHandler::markFunctionEnd() {}
// In the binary's "xray_instr_map" section, an array of these function entries
// describes each instrumentation point. When XRay patches your code, the index
diff --git a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.h b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.h
index 705a61fb827f37..93d13f3e6b2036 100644
--- a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.h
+++ b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.h
@@ -27,7 +27,7 @@ class MCSymbol;
template <typename T> class SmallVectorImpl;
/// Emits exception handling directives.
-class LLVM_LIBRARY_VISIBILITY EHStreamer : public AsmPrinterHandler {
+class LLVM_LIBRARY_VISIBILITY EHStreamer : public AsmBasicPrinterHandler {
protected:
/// Target of directive emission.
AsmPrinter *Asm;
diff --git a/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h b/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h
index 35461e53fbf19d..47fcbce2560272 100644
--- a/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h
+++ b/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h
@@ -14,7 +14,7 @@
#define LLVM_LIB_CODEGEN_ASMPRINTER_PSEUDOPROBEPRINTER_H
#include "llvm/ADT/DenseMap.h"
-#include "llvm/CodeGen/AsmPrinterHandler.h"
+#include "llvm/CodeGen/AsmPrinter.h"
namespace llvm {
diff --git a/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h b/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h
index f94acc912483d5..9402c22a1b545b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h
+++ b/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h
@@ -20,7 +20,7 @@
namespace llvm {
-class LLVM_LIBRARY_VISIBILITY WinCFGuard : public AsmPrinterHandler {
+class LLVM_LIBRARY_VISIBILITY WinCFGuard : public AsmBasicPrinterHandler {
/// Target of directive emission.
AsmPrinter *Asm;
std::vector<const MCSymbol *> LongjmpTargets;
diff --git a/llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp b/llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp
index dc738d85547bbc..6c08173f786223 100644
--- a/llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp
+++ b/llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp
@@ -384,10 +384,13 @@ class AsmPrinterHandlerTest : public AsmPrinterFixtureBase {
public:
TestHandler(AsmPrinterHandlerTest &Test) : Test(Test) {}
virtual ~TestHandler() {}
+ virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {}
virtual void beginModule(Module *M) override { Test.BeginCount++; }
virtual void endModule() override { Test.EndCount++; }
virtual void beginFunction(const MachineFunction *MF) override {}
virtual void endFunction(const MachineFunction *MF) override {}
+ virtual void beginInstruction(const MachineInstr *MI) override {}
+ virtual void endInstruction() override {}
};
protected:
@@ -424,54 +427,4 @@ TEST_F(AsmPrinterHandlerTest, Basic) {
ASSERT_EQ(EndCount, 3);
}
-class AsmPrinterDebugHandlerTest : public AsmPrinterFixtureBase {
- class TestDebugHandler : public DebugHandlerBase {
- AsmPrinterDebugHandlerTest &Test;
-
- public:
- TestDebugHandler(AsmPrinterDebugHandlerTest &Test, AsmPrinter *AP)
- : DebugHandlerBase(AP), Test(Test) {}
- virtual ~TestDebugHandler() {}
- virtual void beginModule(Module *M) override { Test.BeginCount++; }
- virtual void endModule() override { Test.EndCount++; }
- virtual void beginFunctionImpl(const MachineFunction *MF) override {}
- virtual void endFunctionImpl(const MachineFunction *MF) override {}
- virtual void beginInstruction(const MachineInstr *MI) override {}
- virtual void endInstruction() override {}
- };
-
-protected:
- bool init(const std::string &TripleStr, unsigned DwarfVersion,
- dwarf::DwarfFormat DwarfFormat) {
- if (!AsmPrinterFixtureBase::init(TripleStr, DwarfVersion, DwarfFormat))
- return false;
-
- auto *AP = TestPrinter->getAP();
- AP->addDebugHandler(std::make_unique<TestDebugHandler>(*this, AP));
- TargetMachine *TM = &AP->TM;
- legacy::PassManager PM;
- PM.add(new MachineModuleInfoWrapperPass(TM));
- PM.add(TestPrinter->releaseAP()); // Takes ownership of destroying AP
- LLVMContext Context;
- std::unique_ptr<Module> M(new Module("TestModule", Context));
- M->setDataLayout(TM->createDataLayout());
- PM.run(*M);
- // Now check that we can run it twice.
- AP->addDebugHandler(std::make_unique<TestDebugHandler>(*this, AP));
- PM.run(*M);
- return true;
- }
-
- int BeginCount = 0;
- int EndCount = 0;
-};
-
-TEST_F(AsmPrinterDebugHandlerTest, Basic) {
- if (!init("x86_64-pc-linux", /*DwarfVersion=*/4, dwarf::DWARF32))
- GTEST_SKIP();
-
- ASSERT_EQ(BeginCount, 3);
- ASSERT_EQ(EndCount, 3);
-}
-
} // end namespace
>From 822b5cc8fa042090f748bc7135c3e6f3bc87e72f Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash at gmail.com>
Date: Thu, 9 Jan 2025 19:21:19 +0000
Subject: [PATCH 2/3] revert most of the rest, but still expected to be without
performance difference
---
llvm/include/llvm/CodeGen/AsmPrinter.h | 16 +++--
llvm/include/llvm/CodeGen/AsmPrinterHandler.h | 23 +++----
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 64 ++++++++++---------
llvm/lib/CodeGen/AsmPrinter/EHStreamer.h | 2 +-
llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h | 4 +-
llvm/lib/Target/BPF/BPFAsmPrinter.cpp | 2 +-
6 files changed, 55 insertions(+), 56 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h
index e3e75f6f463c64..13e31225e5ce24 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -33,7 +33,6 @@
namespace llvm {
class AddrLabelMap;
-class AsmBasicPrinterHandler;
class AsmPrinterHandler;
class BasicBlock;
class BlockAddress;
@@ -45,6 +44,7 @@ class DebugHandlerBase;
class DIE;
class DIEAbbrev;
class DwarfDebug;
+class EHStreamer;
class GCMetadataPrinter;
class GCStrategy;
class GlobalAlias;
@@ -188,14 +188,16 @@ class AsmPrinter : public MachineFunctionPass {
/// For dso_local functions, the current $local alias for the function.
MCSymbol *CurrentFnBeginLocal = nullptr;
- /// A vector of all EH info emitters we should use. This vector
- /// maintains ownership of the emitters.
- SmallVector<std::unique_ptr<AsmBasicPrinterHandler>, 2> Handlers;
+ /// A handle to the EH info emitter (if present)
+ SmallVector<std::unique_ptr<AsmPrinterHandler>, 1>
+ EHHandlers; // only for EHHandler subtypes, but some c++ compilers will
+ // incorrectly warn us if we declare that
// A vector of all Debuginfo emitters we should use. Protected so that
- // targets can add their own.
- SmallVector<std::unique_ptr<AsmPrinterHandler>, 1> DebugHandlers;
- size_t NumUserDebugHandlers = 0;
+ // targets can add their own. This vector maintains ownership of the
+ // emitters.
+ SmallVector<std::unique_ptr<AsmPrinterHandler>, 2> Handlers;
+ size_t NumUserHandlers = 0;
StackMaps SM;
diff --git a/llvm/include/llvm/CodeGen/AsmPrinterHandler.h b/llvm/include/llvm/CodeGen/AsmPrinterHandler.h
index daf8793f4ddaf6..bf3f6c53027a71 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinterHandler.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinterHandler.h
@@ -30,9 +30,9 @@ typedef MCSymbol *ExceptionSymbolProvider(AsmPrinter *Asm,
/// Collects and handles AsmPrinter objects required to build debug
/// or EH information.
-class AsmBasicPrinterHandler {
+class AsmPrinterHandler {
public:
- virtual ~AsmBasicPrinterHandler();
+ virtual ~AsmPrinterHandler();
virtual void beginModule(Module *M) {}
@@ -64,27 +64,22 @@ class AsmBasicPrinterHandler {
/// immediately prior to markFunctionEnd.
virtual void endBasicBlockSection(const MachineBasicBlock &MBB) {}
- /// Emit target-specific EH funclet machinery.
- virtual void beginFunclet(const MachineBasicBlock &MBB,
- MCSymbol *Sym = nullptr) {}
- virtual void endFunclet() {}
-};
-
-class AsmPrinterHandler : public AsmBasicPrinterHandler {
-public:
- virtual ~AsmPrinterHandler();
-
/// For symbols that have a size designated (e.g. common symbols),
/// this tracks that size.
virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) {}
/// Process beginning of an instruction.
- virtual void beginInstruction(const MachineInstr *MI) = 0;
+ virtual void beginInstruction(const MachineInstr *MI) {}
/// Process end of an instruction.
- virtual void endInstruction() = 0;
+ virtual void endInstruction() {}
virtual void beginCodeAlignment(const MachineBasicBlock &MBB) {}
+
+ /// Emit target-specific EH funclet machinery.
+ virtual void beginFunclet(const MachineBasicBlock &MBB,
+ MCSymbol *Sym = nullptr) {}
+ virtual void endFunclet() {}
};
} // End of namespace llvm
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 5c952be3bce5ca..8ac66cd186ca70 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -392,7 +392,7 @@ AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer> Streamer)
}
AsmPrinter::~AsmPrinter() {
- assert(!DD && DebugHandlers.size() == NumUserDebugHandlers &&
+ assert(!DD && Handlers.size() == NumUserHandlers &&
"Debug/EH info didn't get finalized");
}
@@ -561,11 +561,11 @@ bool AsmPrinter::doInitialization(Module &M) {
if (MAI->doesSupportDebugInformation()) {
bool EmitCodeView = M.getCodeViewFlag();
if (EmitCodeView && TM.getTargetTriple().isOSWindows())
- DebugHandlers.push_back(std::make_unique<CodeViewDebug>(this));
+ Handlers.push_back(std::make_unique<CodeViewDebug>(this));
if (!EmitCodeView || M.getDwarfVersion()) {
if (hasDebugInfo()) {
DD = new DwarfDebug(this);
- DebugHandlers.push_back(std::unique_ptr<DwarfDebug>(DD));
+ Handlers.push_back(std::unique_ptr<DwarfDebug>(DD));
}
}
}
@@ -632,12 +632,12 @@ bool AsmPrinter::doInitialization(Module &M) {
// Emit tables for any value of cfguard flag (i.e. cfguard=1 or cfguard=2).
if (mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("cfguard")))
- Handlers.push_back(std::make_unique<WinCFGuard>(this));
+ EHHandlers.push_back(std::make_unique<WinCFGuard>(this));
- for (auto &Handler : DebugHandlers)
- Handler->beginModule(&M);
for (auto &Handler : Handlers)
Handler->beginModule(&M);
+ for (auto &Handler : EHHandlers)
+ Handler->beginModule(&M);
return false;
}
@@ -784,7 +784,7 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
// sections and expected to be contiguous (e.g. ObjC metadata).
const Align Alignment = getGVAlignment(GV, DL);
- for (auto &Handler : DebugHandlers)
+ for (auto &Handler : Handlers)
Handler->setSymbolSize(GVSym, Size);
// Handle common symbols
@@ -1054,14 +1054,14 @@ void AsmPrinter::emitFunctionHeader() {
}
// Emit pre-function debug and/or EH information.
- for (auto &Handler : DebugHandlers) {
+ for (auto &Handler : Handlers) {
Handler->beginFunction(MF);
Handler->beginBasicBlockSection(MF->front());
}
- for (auto &Handler : Handlers)
+ for (auto &Handler : EHHandlers) {
Handler->beginFunction(MF);
- for (auto &Handler : Handlers)
Handler->beginBasicBlockSection(MF->front());
+ }
// Emit the prologue data.
if (F.hasPrologueData())
@@ -1836,7 +1836,7 @@ void AsmPrinter::emitFunctionBody() {
if (MDNode *MD = MI.getPCSections())
emitPCSectionsLabel(*MF, *MD);
- for (auto &Handler : DebugHandlers)
+ for (auto &Handler : Handlers)
Handler->beginInstruction(&MI);
if (isVerbose())
@@ -1952,7 +1952,7 @@ void AsmPrinter::emitFunctionBody() {
if (MCSymbol *S = MI.getPostInstrSymbol())
OutStreamer->emitLabel(S);
- for (auto &Handler : DebugHandlers)
+ for (auto &Handler : Handlers)
Handler->endInstruction();
}
@@ -2089,12 +2089,12 @@ void AsmPrinter::emitFunctionBody() {
// Call endBasicBlockSection on the last block now, if it wasn't already
// called.
if (!MF->back().isEndSection()) {
- for (auto &Handler : DebugHandlers)
- Handler->endBasicBlockSection(MF->back());
for (auto &Handler : Handlers)
Handler->endBasicBlockSection(MF->back());
+ for (auto &Handler : EHHandlers)
+ Handler->endBasicBlockSection(MF->back());
}
- for (auto &Handler : Handlers)
+ for (auto &Handler : EHHandlers)
Handler->markFunctionEnd();
// Update the end label of the entry block's section.
MBBSectionRanges[MF->front().getSectionID()].EndLabel = CurrentFnEnd;
@@ -2103,10 +2103,10 @@ void AsmPrinter::emitFunctionBody() {
emitJumpTableInfo();
// Emit post-function debug and/or EH information.
- for (auto &Handler : DebugHandlers)
- Handler->endFunction(MF);
for (auto &Handler : Handlers)
Handler->endFunction(MF);
+ for (auto &Handler : EHHandlers)
+ Handler->endFunction(MF);
// Emit section containing BB address offsets and their metadata, when
// BB labels are requested for this function. Skip empty functions.
@@ -2583,17 +2583,16 @@ bool AsmPrinter::doFinalization(Module &M) {
emitGlobalIFunc(M, IFunc);
// Finalize debug and EH information.
- for (auto &Handler : DebugHandlers)
- Handler->endModule();
for (auto &Handler : Handlers)
Handler->endModule();
+ for (auto &Handler : EHHandlers)
+ Handler->endModule();
// This deletes all the ephemeral handlers that AsmPrinter added, while
// keeping all the user-added handlers alive until the AsmPrinter is
// destroyed.
- Handlers.clear();
- DebugHandlers.erase(DebugHandlers.begin() + NumUserDebugHandlers,
- DebugHandlers.end());
+ EHHandlers.clear();
+ Handlers.erase(Handlers.begin() + NumUserHandlers, Handlers.end());
DD = nullptr;
// If the target wants to know about weak references, print them all.
@@ -4196,6 +4195,10 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
Handler->endFunclet();
Handler->beginFunclet(MBB);
}
+ for (auto &Handler : EHHandlers) {
+ Handler->endFunclet();
+ Handler->beginFunclet(MBB);
+ }
}
// Switch to a new section if this basic block must begin a section. The
@@ -4208,7 +4211,7 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
CurrentSectionBeginSym = MBB.getSymbol();
}
- for (auto &Handler : DebugHandlers)
+ for (auto &Handler : Handlers)
Handler->beginCodeAlignment(MBB);
// Emit an alignment directive for this block, if needed.
@@ -4268,10 +4271,10 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
// if it begins a section (Entry block call is handled separately, next to
// beginFunction).
if (MBB.isBeginSection() && !MBB.isEntryBlock()) {
- for (auto &Handler : DebugHandlers)
- Handler->beginBasicBlockSection(MBB);
for (auto &Handler : Handlers)
Handler->beginBasicBlockSection(MBB);
+ for (auto &Handler : EHHandlers)
+ Handler->beginBasicBlockSection(MBB);
}
}
@@ -4279,10 +4282,10 @@ void AsmPrinter::emitBasicBlockEnd(const MachineBasicBlock &MBB) {
// Check if CFI information needs to be updated for this MBB with basic block
// sections.
if (MBB.isEndSection()) {
- for (auto &Handler : DebugHandlers)
- Handler->endBasicBlockSection(MBB);
for (auto &Handler : Handlers)
Handler->endBasicBlockSection(MBB);
+ for (auto &Handler : EHHandlers)
+ Handler->endBasicBlockSection(MBB);
}
}
@@ -4411,15 +4414,14 @@ void AsmPrinter::emitStackMaps() {
void AsmPrinter::addAsmPrinterHandler(
std::unique_ptr<AsmPrinterHandler> Handler) {
- DebugHandlers.insert(DebugHandlers.begin(), std::move(Handler));
- NumUserDebugHandlers++;
+ Handlers.insert(Handlers.begin(), std::move(Handler));
+ NumUserHandlers++;
}
/// Pin vtables to this file.
-AsmBasicPrinterHandler::~AsmBasicPrinterHandler() = default;
AsmPrinterHandler::~AsmPrinterHandler() = default;
-void AsmBasicPrinterHandler::markFunctionEnd() {}
+void AsmPrinterHandler::markFunctionEnd() {}
// In the binary's "xray_instr_map" section, an array of these function entries
// describes each instrumentation point. When XRay patches your code, the index
diff --git a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.h b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.h
index 93d13f3e6b2036..705a61fb827f37 100644
--- a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.h
+++ b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.h
@@ -27,7 +27,7 @@ class MCSymbol;
template <typename T> class SmallVectorImpl;
/// Emits exception handling directives.
-class LLVM_LIBRARY_VISIBILITY EHStreamer : public AsmBasicPrinterHandler {
+class LLVM_LIBRARY_VISIBILITY EHStreamer : public AsmPrinterHandler {
protected:
/// Target of directive emission.
AsmPrinter *Asm;
diff --git a/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h b/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h
index 9402c22a1b545b..be2c04c091a366 100644
--- a/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h
+++ b/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h
@@ -14,13 +14,13 @@
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WINCFGUARD_H
#define LLVM_LIB_CODEGEN_ASMPRINTER_WINCFGUARD_H
-#include "llvm/CodeGen/AsmPrinterHandler.h"
+#include "EHStreamer.h"
#include "llvm/Support/Compiler.h"
#include <vector>
namespace llvm {
-class LLVM_LIBRARY_VISIBILITY WinCFGuard : public AsmBasicPrinterHandler {
+class LLVM_LIBRARY_VISIBILITY WinCFGuard : public AsmPrinterHandler {
/// Target of directive emission.
AsmPrinter *Asm;
std::vector<const MCSymbol *> LongjmpTargets;
diff --git a/llvm/lib/Target/BPF/BPFAsmPrinter.cpp b/llvm/lib/Target/BPF/BPFAsmPrinter.cpp
index ab03a4e56ea076..b3c27a3d1d6faf 100644
--- a/llvm/lib/Target/BPF/BPFAsmPrinter.cpp
+++ b/llvm/lib/Target/BPF/BPFAsmPrinter.cpp
@@ -60,7 +60,7 @@ bool BPFAsmPrinter::doInitialization(Module &M) {
// Only emit BTF when debuginfo available.
if (MAI->doesSupportDebugInformation() && !M.debug_compile_units().empty()) {
BTF = new BTFDebug(this);
- DebugHandlers.push_back(std::unique_ptr<BTFDebug>(BTF));
+ Handlers.push_back(std::unique_ptr<BTFDebug>(BTF));
}
return false;
>From a92ddf5696932297e4b3fafd5142eefc506c3c96 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash at gmail.com>
Date: Mon, 13 Jan 2025 19:55:19 +0000
Subject: [PATCH 3/3] fixup! revert most of the rest, but still expected to be
without performance difference
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 8ac66cd186ca70..541cd02edc6164 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2094,6 +2094,8 @@ void AsmPrinter::emitFunctionBody() {
for (auto &Handler : EHHandlers)
Handler->endBasicBlockSection(MF->back());
}
+ for (auto &Handler : Handlers)
+ Handler->markFunctionEnd();
for (auto &Handler : EHHandlers)
Handler->markFunctionEnd();
// Update the end label of the entry block's section.
More information about the llvm-commits
mailing list