Skip to content

Commit 822b5cc

Browse files
committed
revert most of the rest, but still expected to be without performance difference
1 parent 01480dd commit 822b5cc

File tree

6 files changed

+55
-56
lines changed

6 files changed

+55
-56
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
namespace llvm {
3434

3535
class AddrLabelMap;
36-
class AsmBasicPrinterHandler;
3736
class AsmPrinterHandler;
3837
class BasicBlock;
3938
class BlockAddress;
@@ -45,6 +44,7 @@ class DebugHandlerBase;
4544
class DIE;
4645
class DIEAbbrev;
4746
class DwarfDebug;
47+
class EHStreamer;
4848
class GCMetadataPrinter;
4949
class GCStrategy;
5050
class GlobalAlias;
@@ -188,14 +188,16 @@ class AsmPrinter : public MachineFunctionPass {
188188
/// For dso_local functions, the current $local alias for the function.
189189
MCSymbol *CurrentFnBeginLocal = nullptr;
190190

191-
/// A vector of all EH info emitters we should use. This vector
192-
/// maintains ownership of the emitters.
193-
SmallVector<std::unique_ptr<AsmBasicPrinterHandler>, 2> Handlers;
191+
/// A handle to the EH info emitter (if present)
192+
SmallVector<std::unique_ptr<AsmPrinterHandler>, 1>
193+
EHHandlers; // only for EHHandler subtypes, but some c++ compilers will
194+
// incorrectly warn us if we declare that
194195

195196
// A vector of all Debuginfo emitters we should use. Protected so that
196-
// targets can add their own.
197-
SmallVector<std::unique_ptr<AsmPrinterHandler>, 1> DebugHandlers;
198-
size_t NumUserDebugHandlers = 0;
197+
// targets can add their own. This vector maintains ownership of the
198+
// emitters.
199+
SmallVector<std::unique_ptr<AsmPrinterHandler>, 2> Handlers;
200+
size_t NumUserHandlers = 0;
199201

200202
StackMaps SM;
201203

llvm/include/llvm/CodeGen/AsmPrinterHandler.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ typedef MCSymbol *ExceptionSymbolProvider(AsmPrinter *Asm,
3030

3131
/// Collects and handles AsmPrinter objects required to build debug
3232
/// or EH information.
33-
class AsmBasicPrinterHandler {
33+
class AsmPrinterHandler {
3434
public:
35-
virtual ~AsmBasicPrinterHandler();
35+
virtual ~AsmPrinterHandler();
3636

3737
virtual void beginModule(Module *M) {}
3838

@@ -64,27 +64,22 @@ class AsmBasicPrinterHandler {
6464
/// immediately prior to markFunctionEnd.
6565
virtual void endBasicBlockSection(const MachineBasicBlock &MBB) {}
6666

67-
/// Emit target-specific EH funclet machinery.
68-
virtual void beginFunclet(const MachineBasicBlock &MBB,
69-
MCSymbol *Sym = nullptr) {}
70-
virtual void endFunclet() {}
71-
};
72-
73-
class AsmPrinterHandler : public AsmBasicPrinterHandler {
74-
public:
75-
virtual ~AsmPrinterHandler();
76-
7767
/// For symbols that have a size designated (e.g. common symbols),
7868
/// this tracks that size.
7969
virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) {}
8070

8171
/// Process beginning of an instruction.
82-
virtual void beginInstruction(const MachineInstr *MI) = 0;
72+
virtual void beginInstruction(const MachineInstr *MI) {}
8373

8474
/// Process end of an instruction.
85-
virtual void endInstruction() = 0;
75+
virtual void endInstruction() {}
8676

8777
virtual void beginCodeAlignment(const MachineBasicBlock &MBB) {}
78+
79+
/// Emit target-specific EH funclet machinery.
80+
virtual void beginFunclet(const MachineBasicBlock &MBB,
81+
MCSymbol *Sym = nullptr) {}
82+
virtual void endFunclet() {}
8883
};
8984

9085
} // End of namespace llvm

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer> Streamer)
392392
}
393393

394394
AsmPrinter::~AsmPrinter() {
395-
assert(!DD && DebugHandlers.size() == NumUserDebugHandlers &&
395+
assert(!DD && Handlers.size() == NumUserHandlers &&
396396
"Debug/EH info didn't get finalized");
397397
}
398398

@@ -561,11 +561,11 @@ bool AsmPrinter::doInitialization(Module &M) {
561561
if (MAI->doesSupportDebugInformation()) {
562562
bool EmitCodeView = M.getCodeViewFlag();
563563
if (EmitCodeView && TM.getTargetTriple().isOSWindows())
564-
DebugHandlers.push_back(std::make_unique<CodeViewDebug>(this));
564+
Handlers.push_back(std::make_unique<CodeViewDebug>(this));
565565
if (!EmitCodeView || M.getDwarfVersion()) {
566566
if (hasDebugInfo()) {
567567
DD = new DwarfDebug(this);
568-
DebugHandlers.push_back(std::unique_ptr<DwarfDebug>(DD));
568+
Handlers.push_back(std::unique_ptr<DwarfDebug>(DD));
569569
}
570570
}
571571
}
@@ -632,12 +632,12 @@ bool AsmPrinter::doInitialization(Module &M) {
632632

633633
// Emit tables for any value of cfguard flag (i.e. cfguard=1 or cfguard=2).
634634
if (mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("cfguard")))
635-
Handlers.push_back(std::make_unique<WinCFGuard>(this));
635+
EHHandlers.push_back(std::make_unique<WinCFGuard>(this));
636636

637-
for (auto &Handler : DebugHandlers)
638-
Handler->beginModule(&M);
639637
for (auto &Handler : Handlers)
640638
Handler->beginModule(&M);
639+
for (auto &Handler : EHHandlers)
640+
Handler->beginModule(&M);
641641

642642
return false;
643643
}
@@ -784,7 +784,7 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
784784
// sections and expected to be contiguous (e.g. ObjC metadata).
785785
const Align Alignment = getGVAlignment(GV, DL);
786786

787-
for (auto &Handler : DebugHandlers)
787+
for (auto &Handler : Handlers)
788788
Handler->setSymbolSize(GVSym, Size);
789789

790790
// Handle common symbols
@@ -1054,14 +1054,14 @@ void AsmPrinter::emitFunctionHeader() {
10541054
}
10551055

10561056
// Emit pre-function debug and/or EH information.
1057-
for (auto &Handler : DebugHandlers) {
1057+
for (auto &Handler : Handlers) {
10581058
Handler->beginFunction(MF);
10591059
Handler->beginBasicBlockSection(MF->front());
10601060
}
1061-
for (auto &Handler : Handlers)
1061+
for (auto &Handler : EHHandlers) {
10621062
Handler->beginFunction(MF);
1063-
for (auto &Handler : Handlers)
10641063
Handler->beginBasicBlockSection(MF->front());
1064+
}
10651065

10661066
// Emit the prologue data.
10671067
if (F.hasPrologueData())
@@ -1836,7 +1836,7 @@ void AsmPrinter::emitFunctionBody() {
18361836
if (MDNode *MD = MI.getPCSections())
18371837
emitPCSectionsLabel(*MF, *MD);
18381838

1839-
for (auto &Handler : DebugHandlers)
1839+
for (auto &Handler : Handlers)
18401840
Handler->beginInstruction(&MI);
18411841

18421842
if (isVerbose())
@@ -1952,7 +1952,7 @@ void AsmPrinter::emitFunctionBody() {
19521952
if (MCSymbol *S = MI.getPostInstrSymbol())
19531953
OutStreamer->emitLabel(S);
19541954

1955-
for (auto &Handler : DebugHandlers)
1955+
for (auto &Handler : Handlers)
19561956
Handler->endInstruction();
19571957
}
19581958

@@ -2089,12 +2089,12 @@ void AsmPrinter::emitFunctionBody() {
20892089
// Call endBasicBlockSection on the last block now, if it wasn't already
20902090
// called.
20912091
if (!MF->back().isEndSection()) {
2092-
for (auto &Handler : DebugHandlers)
2093-
Handler->endBasicBlockSection(MF->back());
20942092
for (auto &Handler : Handlers)
20952093
Handler->endBasicBlockSection(MF->back());
2094+
for (auto &Handler : EHHandlers)
2095+
Handler->endBasicBlockSection(MF->back());
20962096
}
2097-
for (auto &Handler : Handlers)
2097+
for (auto &Handler : EHHandlers)
20982098
Handler->markFunctionEnd();
20992099
// Update the end label of the entry block's section.
21002100
MBBSectionRanges[MF->front().getSectionID()].EndLabel = CurrentFnEnd;
@@ -2103,10 +2103,10 @@ void AsmPrinter::emitFunctionBody() {
21032103
emitJumpTableInfo();
21042104

21052105
// Emit post-function debug and/or EH information.
2106-
for (auto &Handler : DebugHandlers)
2107-
Handler->endFunction(MF);
21082106
for (auto &Handler : Handlers)
21092107
Handler->endFunction(MF);
2108+
for (auto &Handler : EHHandlers)
2109+
Handler->endFunction(MF);
21102110

21112111
// Emit section containing BB address offsets and their metadata, when
21122112
// BB labels are requested for this function. Skip empty functions.
@@ -2583,17 +2583,16 @@ bool AsmPrinter::doFinalization(Module &M) {
25832583
emitGlobalIFunc(M, IFunc);
25842584

25852585
// Finalize debug and EH information.
2586-
for (auto &Handler : DebugHandlers)
2587-
Handler->endModule();
25882586
for (auto &Handler : Handlers)
25892587
Handler->endModule();
2588+
for (auto &Handler : EHHandlers)
2589+
Handler->endModule();
25902590

25912591
// This deletes all the ephemeral handlers that AsmPrinter added, while
25922592
// keeping all the user-added handlers alive until the AsmPrinter is
25932593
// destroyed.
2594-
Handlers.clear();
2595-
DebugHandlers.erase(DebugHandlers.begin() + NumUserDebugHandlers,
2596-
DebugHandlers.end());
2594+
EHHandlers.clear();
2595+
Handlers.erase(Handlers.begin() + NumUserHandlers, Handlers.end());
25972596
DD = nullptr;
25982597

25992598
// If the target wants to know about weak references, print them all.
@@ -4196,6 +4195,10 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
41964195
Handler->endFunclet();
41974196
Handler->beginFunclet(MBB);
41984197
}
4198+
for (auto &Handler : EHHandlers) {
4199+
Handler->endFunclet();
4200+
Handler->beginFunclet(MBB);
4201+
}
41994202
}
42004203

42014204
// Switch to a new section if this basic block must begin a section. The
@@ -4208,7 +4211,7 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
42084211
CurrentSectionBeginSym = MBB.getSymbol();
42094212
}
42104213

4211-
for (auto &Handler : DebugHandlers)
4214+
for (auto &Handler : Handlers)
42124215
Handler->beginCodeAlignment(MBB);
42134216

42144217
// Emit an alignment directive for this block, if needed.
@@ -4268,21 +4271,21 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
42684271
// if it begins a section (Entry block call is handled separately, next to
42694272
// beginFunction).
42704273
if (MBB.isBeginSection() && !MBB.isEntryBlock()) {
4271-
for (auto &Handler : DebugHandlers)
4272-
Handler->beginBasicBlockSection(MBB);
42734274
for (auto &Handler : Handlers)
42744275
Handler->beginBasicBlockSection(MBB);
4276+
for (auto &Handler : EHHandlers)
4277+
Handler->beginBasicBlockSection(MBB);
42754278
}
42764279
}
42774280

42784281
void AsmPrinter::emitBasicBlockEnd(const MachineBasicBlock &MBB) {
42794282
// Check if CFI information needs to be updated for this MBB with basic block
42804283
// sections.
42814284
if (MBB.isEndSection()) {
4282-
for (auto &Handler : DebugHandlers)
4283-
Handler->endBasicBlockSection(MBB);
42844285
for (auto &Handler : Handlers)
42854286
Handler->endBasicBlockSection(MBB);
4287+
for (auto &Handler : EHHandlers)
4288+
Handler->endBasicBlockSection(MBB);
42864289
}
42874290
}
42884291

@@ -4411,15 +4414,14 @@ void AsmPrinter::emitStackMaps() {
44114414

44124415
void AsmPrinter::addAsmPrinterHandler(
44134416
std::unique_ptr<AsmPrinterHandler> Handler) {
4414-
DebugHandlers.insert(DebugHandlers.begin(), std::move(Handler));
4415-
NumUserDebugHandlers++;
4417+
Handlers.insert(Handlers.begin(), std::move(Handler));
4418+
NumUserHandlers++;
44164419
}
44174420

44184421
/// Pin vtables to this file.
4419-
AsmBasicPrinterHandler::~AsmBasicPrinterHandler() = default;
44204422
AsmPrinterHandler::~AsmPrinterHandler() = default;
44214423

4422-
void AsmBasicPrinterHandler::markFunctionEnd() {}
4424+
void AsmPrinterHandler::markFunctionEnd() {}
44234425

44244426
// In the binary's "xray_instr_map" section, an array of these function entries
44254427
// describes each instrumentation point. When XRay patches your code, the index

llvm/lib/CodeGen/AsmPrinter/EHStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MCSymbol;
2727
template <typename T> class SmallVectorImpl;
2828

2929
/// Emits exception handling directives.
30-
class LLVM_LIBRARY_VISIBILITY EHStreamer : public AsmBasicPrinterHandler {
30+
class LLVM_LIBRARY_VISIBILITY EHStreamer : public AsmPrinterHandler {
3131
protected:
3232
/// Target of directive emission.
3333
AsmPrinter *Asm;

llvm/lib/CodeGen/AsmPrinter/WinCFGuard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WINCFGUARD_H
1515
#define LLVM_LIB_CODEGEN_ASMPRINTER_WINCFGUARD_H
1616

17-
#include "llvm/CodeGen/AsmPrinterHandler.h"
17+
#include "EHStreamer.h"
1818
#include "llvm/Support/Compiler.h"
1919
#include <vector>
2020

2121
namespace llvm {
2222

23-
class LLVM_LIBRARY_VISIBILITY WinCFGuard : public AsmBasicPrinterHandler {
23+
class LLVM_LIBRARY_VISIBILITY WinCFGuard : public AsmPrinterHandler {
2424
/// Target of directive emission.
2525
AsmPrinter *Asm;
2626
std::vector<const MCSymbol *> LongjmpTargets;

llvm/lib/Target/BPF/BPFAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool BPFAsmPrinter::doInitialization(Module &M) {
6060
// Only emit BTF when debuginfo available.
6161
if (MAI->doesSupportDebugInformation() && !M.debug_compile_units().empty()) {
6262
BTF = new BTFDebug(this);
63-
DebugHandlers.push_back(std::unique_ptr<BTFDebug>(BTF));
63+
Handlers.push_back(std::unique_ptr<BTFDebug>(BTF));
6464
}
6565

6666
return false;

0 commit comments

Comments
 (0)