Skip to content

Commit 4242df1

Browse files
committed
Revert "make the AsmPrinterHandler array public"
I messed up one of the tests.
1 parent 24b5266 commit 4242df1

File tree

12 files changed

+66
-142
lines changed

12 files changed

+66
-142
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,6 @@ class AsmPrinter : public MachineFunctionPass {
139139
using GOTEquivUsePair = std::pair<const GlobalVariable *, unsigned>;
140140
MapVector<const MCSymbol *, GOTEquivUsePair> GlobalGOTEquivs;
141141

142-
/// struct HandlerInfo and Handlers permit users or target extended
143-
/// AsmPrinter to add their own handlers.
144-
struct HandlerInfo {
145-
std::unique_ptr<AsmPrinterHandler> Handler;
146-
const char *TimerName;
147-
const char *TimerDescription;
148-
const char *TimerGroupName;
149-
const char *TimerGroupDescription;
150-
151-
HandlerInfo(std::unique_ptr<AsmPrinterHandler> Handler,
152-
const char *TimerName, const char *TimerDescription,
153-
const char *TimerGroupName, const char *TimerGroupDescription)
154-
: Handler(std::move(Handler)), TimerName(TimerName),
155-
TimerDescription(TimerDescription), TimerGroupName(TimerGroupName),
156-
TimerGroupDescription(TimerGroupDescription) {}
157-
};
158-
159142
private:
160143
MCSymbol *CurrentFnEnd = nullptr;
161144

@@ -179,10 +162,26 @@ class AsmPrinter : public MachineFunctionPass {
179162
protected:
180163
MCSymbol *CurrentFnBegin = nullptr;
181164

165+
/// Protected struct HandlerInfo and Handlers permit target extended
166+
/// AsmPrinter adds their own handlers.
167+
struct HandlerInfo {
168+
std::unique_ptr<AsmPrinterHandler> Handler;
169+
const char *TimerName;
170+
const char *TimerDescription;
171+
const char *TimerGroupName;
172+
const char *TimerGroupDescription;
173+
174+
HandlerInfo(std::unique_ptr<AsmPrinterHandler> Handler,
175+
const char *TimerName, const char *TimerDescription,
176+
const char *TimerGroupName, const char *TimerGroupDescription)
177+
: Handler(std::move(Handler)), TimerName(TimerName),
178+
TimerDescription(TimerDescription), TimerGroupName(TimerGroupName),
179+
TimerGroupDescription(TimerGroupDescription) {}
180+
};
181+
182182
/// A vector of all debug/EH info emitters we should use. This vector
183183
/// maintains ownership of the emitters.
184-
std::vector<HandlerInfo> Handlers;
185-
size_t NumUserHandlers = 0;
184+
SmallVector<HandlerInfo, 1> Handlers;
186185

187186
public:
188187
struct SrcMgrDiagInfo {
@@ -447,11 +446,6 @@ class AsmPrinter : public MachineFunctionPass {
447446
// Overridable Hooks
448447
//===------------------------------------------------------------------===//
449448

450-
void addAsmPrinterHandler(HandlerInfo Handler) {
451-
Handlers.insert(Handlers.begin(), std::move(Handler));
452-
NumUserHandlers++;
453-
}
454-
455449
// Targets can, or in the case of EmitInstruction, must implement these to
456450
// customize output.
457451

llvm/include/llvm/CodeGen/AsmPrinterHandler.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class MachineBasicBlock;
2323
class MachineFunction;
2424
class MachineInstr;
2525
class MCSymbol;
26-
class Module;
2726

2827
typedef MCSymbol *ExceptionSymbolProvider(AsmPrinter *Asm,
2928
const MachineBasicBlock *MBB);
@@ -38,8 +37,6 @@ class AsmPrinterHandler {
3837
/// this tracks that size.
3938
virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) = 0;
4039

41-
virtual void beginModule(Module *M) {}
42-
4340
/// Emit all sections that should come after the content.
4441
virtual void endModule() = 0;
4542

@@ -78,7 +75,6 @@ class AsmPrinterHandler {
7875
/// Process end of a basic block during basic block sections.
7976
virtual void endBasicBlock(const MachineBasicBlock &MBB) {}
8077
};
81-
8278
} // End of namespace llvm
8379

8480
#endif

llvm/include/llvm/CodeGen/DebugHandlerBase.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ class DebugHandlerBase : public AsmPrinterHandler {
115115

116116
// AsmPrinterHandler overrides.
117117
public:
118-
void beginModule(Module *M) override;
119-
120118
void beginInstruction(const MachineInstr *MI) override;
121119
void endInstruction() override;
122120

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer> Streamer)
188188
}
189189

190190
AsmPrinter::~AsmPrinter() {
191-
assert(!DD && Handlers.size() == NumUserHandlers &&
192-
"Debug/EH info didn't get finalized");
191+
assert(!DD && Handlers.empty() && "Debug/EH info didn't get finalized");
193192

194193
if (GCMetadataPrinters) {
195194
gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
@@ -253,9 +252,6 @@ bool AsmPrinter::doInitialization(Module &M) {
253252
auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
254253
MMI = MMIWP ? &MMIWP->getMMI() : nullptr;
255254

256-
if (!M.debug_compile_units().empty())
257-
MMI->setDebugInfoAvailability(true);
258-
259255
// Initialize TargetLoweringObjectFile.
260256
const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
261257
.Initialize(OutContext, TM);
@@ -317,7 +313,8 @@ bool AsmPrinter::doInitialization(Module &M) {
317313
CodeViewLineTablesGroupDescription);
318314
}
319315
if (!EmitCodeView || M.getDwarfVersion()) {
320-
DD = new DwarfDebug(this);
316+
DD = new DwarfDebug(this, &M);
317+
DD->beginModule();
321318
Handlers.emplace_back(std::unique_ptr<DwarfDebug>(DD), DbgTimerName,
322319
DbgTimerDescription, DWARFGroupName,
323320
DWARFGroupDescription);
@@ -382,13 +379,6 @@ bool AsmPrinter::doInitialization(Module &M) {
382379
Handlers.emplace_back(std::make_unique<WinCFGuard>(this), CFGuardName,
383380
CFGuardDescription, DWARFGroupName,
384381
DWARFGroupDescription);
385-
386-
for (const HandlerInfo &HI : Handlers) {
387-
NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
388-
HI.TimerGroupDescription, TimePassesIsEnabled);
389-
HI.Handler->beginModule(&M);
390-
}
391-
392382
return false;
393383
}
394384

@@ -1120,6 +1110,8 @@ void AsmPrinter::emitFunctionBody() {
11201110
// Emit target-specific gunk before the function body.
11211111
emitFunctionBodyStart();
11221112

1113+
bool ShouldPrintDebugScopes = MMI->hasDebugInfo();
1114+
11231115
if (isVerbose()) {
11241116
// Get MachineDominatorTree or compute it on the fly if it's unavailable
11251117
MDT = getAnalysisIfAvailable<MachineDominatorTree>();
@@ -1157,10 +1149,13 @@ void AsmPrinter::emitFunctionBody() {
11571149
if (MCSymbol *S = MI.getPreInstrSymbol())
11581150
OutStreamer->emitLabel(S);
11591151

1160-
for (const HandlerInfo &HI : Handlers) {
1161-
NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
1162-
HI.TimerGroupDescription, TimePassesIsEnabled);
1163-
HI.Handler->beginInstruction(&MI);
1152+
if (ShouldPrintDebugScopes) {
1153+
for (const HandlerInfo &HI : Handlers) {
1154+
NamedRegionTimer T(HI.TimerName, HI.TimerDescription,
1155+
HI.TimerGroupName, HI.TimerGroupDescription,
1156+
TimePassesIsEnabled);
1157+
HI.Handler->beginInstruction(&MI);
1158+
}
11641159
}
11651160

11661161
if (isVerbose())
@@ -1214,10 +1209,13 @@ void AsmPrinter::emitFunctionBody() {
12141209
if (MCSymbol *S = MI.getPostInstrSymbol())
12151210
OutStreamer->emitLabel(S);
12161211

1217-
for (const HandlerInfo &HI : Handlers) {
1218-
NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
1219-
HI.TimerGroupDescription, TimePassesIsEnabled);
1220-
HI.Handler->endInstruction();
1212+
if (ShouldPrintDebugScopes) {
1213+
for (const HandlerInfo &HI : Handlers) {
1214+
NamedRegionTimer T(HI.TimerName, HI.TimerDescription,
1215+
HI.TimerGroupName, HI.TimerGroupDescription,
1216+
TimePassesIsEnabled);
1217+
HI.Handler->endInstruction();
1218+
}
12211219
}
12221220
}
12231221

@@ -1639,11 +1637,7 @@ bool AsmPrinter::doFinalization(Module &M) {
16391637
HI.TimerGroupDescription, TimePassesIsEnabled);
16401638
HI.Handler->endModule();
16411639
}
1642-
1643-
// This deletes all the ephemeral handlers that AsmPrinter added, while
1644-
// keeping all the user-added handlers alive until the AsmPrinter is
1645-
// destroyed.
1646-
Handlers.erase(Handlers.begin() + NumUserHandlers, Handlers.end());
1640+
Handlers.clear();
16471641
DD = nullptr;
16481642

16491643
// If the target wants to know about weak references, print them all.

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ CodeViewDebug::CodeViewDebug(AsmPrinter *AP)
141141
if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") ||
142142
!AP->getObjFileLowering().getCOFFDebugSymbolsSection()) {
143143
Asm = nullptr;
144+
MMI->setDebugInfoAvailability(false);
144145
return;
145146
}
146147
// Tell MMI that we have debug info.
@@ -563,6 +564,8 @@ void CodeViewDebug::endModule() {
563564
if (!Asm || !MMI->hasDebugInfo())
564565
return;
565566

567+
assert(Asm != nullptr);
568+
566569
// The COFF .debug$S section consists of several subsections, each starting
567570
// with a 4-byte control code (e.g. 0xF1, 0xF2, etc) and then a 4-byte length
568571
// of the payload followed by the payload itself. The subsections are 4-byte

llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ DbgVariableLocation::extractFromMachineInstruction(
9191

9292
DebugHandlerBase::DebugHandlerBase(AsmPrinter *A) : Asm(A), MMI(Asm->MMI) {}
9393

94-
void DebugHandlerBase::beginModule(Module *M) {
95-
if (M->debug_compile_units().empty())
96-
Asm = nullptr;
97-
}
98-
9994
// Each LexicalScope has first instruction and last instruction to mark
10095
// beginning and end of a scope respectively. Create an inverse map that list
10196
// scopes starts (and ends) with an instruction. One instruction may start (or
@@ -281,7 +276,7 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
281276
}
282277

283278
void DebugHandlerBase::beginInstruction(const MachineInstr *MI) {
284-
if (!Asm || !MMI->hasDebugInfo())
279+
if (!MMI->hasDebugInfo())
285280
return;
286281

287282
assert(CurMI == nullptr);
@@ -307,7 +302,7 @@ void DebugHandlerBase::beginInstruction(const MachineInstr *MI) {
307302
}
308303

309304
void DebugHandlerBase::endInstruction() {
310-
if (!Asm || !MMI->hasDebugInfo())
305+
if (!MMI->hasDebugInfo())
311306
return;
312307

313308
assert(CurMI != nullptr);
@@ -339,7 +334,7 @@ void DebugHandlerBase::endInstruction() {
339334
}
340335

341336
void DebugHandlerBase::endFunction(const MachineFunction *MF) {
342-
if (Asm && hasDebugInfo(MMI, MF))
337+
if (hasDebugInfo(MMI, MF))
343338
endFunctionImpl(MF);
344339
DbgValues.clear();
345340
DbgLabels.clear();

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ static cl::opt<LinkageNameOption>
148148
"Abstract subprograms")),
149149
cl::init(DefaultLinkageNames));
150150

151+
static const char *const DWARFGroupName = "dwarf";
152+
static const char *const DWARFGroupDescription = "DWARF Emission";
153+
static const char *const DbgTimerName = "writer";
154+
static const char *const DbgTimerDescription = "DWARF Debug Writer";
151155
static constexpr unsigned ULEB128PadSize = 4;
152156

153157
void DebugLocDwarfExpression::emitOp(uint8_t Op, const char *Comment) {
@@ -326,7 +330,7 @@ static AccelTableKind computeAccelTableKind(unsigned DwarfVersion,
326330
return AccelTableKind::None;
327331
}
328332

329-
DwarfDebug::DwarfDebug(AsmPrinter *A)
333+
DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
330334
: DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()),
331335
InfoHolder(A, "info_string", DIEValueAllocator),
332336
SkeletonHolder(A, "skel_string", DIEValueAllocator),
@@ -1107,17 +1111,21 @@ sortGlobalExprs(SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
11071111
// Emit all Dwarf sections that should come prior to the content. Create
11081112
// global DIEs and emit initial debug info sections. This is invoked by
11091113
// the target AsmPrinter.
1110-
void DwarfDebug::beginModule(Module *M) {
1111-
DebugHandlerBase::beginModule(M);
1112-
1113-
if (!Asm || !MMI->hasDebugInfo() || DisableDebugInfoPrinting)
1114+
void DwarfDebug::beginModule() {
1115+
NamedRegionTimer T(DbgTimerName, DbgTimerDescription, DWARFGroupName,
1116+
DWARFGroupDescription, TimePassesIsEnabled);
1117+
if (DisableDebugInfoPrinting) {
1118+
MMI->setDebugInfoAvailability(false);
11141119
return;
1120+
}
1121+
1122+
const Module *M = MMI->getModule();
11151123

11161124
unsigned NumDebugCUs = std::distance(M->debug_compile_units_begin(),
11171125
M->debug_compile_units_end());
1118-
assert(NumDebugCUs > 0 && "Asm unexpectedly initialized");
1119-
assert(MMI->hasDebugInfo() &&
1120-
"DebugInfoAvailabilty unexpectedly not initialized");
1126+
// Tell MMI whether we have debug info.
1127+
assert(MMI->hasDebugInfo() == (NumDebugCUs > 0) &&
1128+
"DebugInfoAvailabilty initialized unexpectedly");
11211129
SingleCU = NumDebugCUs == 1;
11221130
DenseMap<DIGlobalVariable *, SmallVector<DwarfCompileUnit::GlobalExpr, 1>>
11231131
GVMap;
@@ -1380,7 +1388,7 @@ void DwarfDebug::endModule() {
13801388
// If we aren't actually generating debug info (check beginModule -
13811389
// conditionalized on !DisableDebugInfoPrinting and the presence of the
13821390
// llvm.dbg.cu metadata node)
1383-
if (!Asm || !MMI->hasDebugInfo() || DisableDebugInfoPrinting)
1391+
if (!MMI->hasDebugInfo())
13841392
return;
13851393

13861394
// Finalize the debug info for the module.
@@ -1891,8 +1899,7 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
18911899
}
18921900

18931901
DebugHandlerBase::beginInstruction(MI);
1894-
if (!CurMI)
1895-
return;
1902+
assert(CurMI);
18961903

18971904
if (NoDebug)
18981905
return;

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,13 @@ class DwarfDebug : public DebugHandlerBase {
621621
//===--------------------------------------------------------------------===//
622622
// Main entry points.
623623
//
624-
DwarfDebug(AsmPrinter *A);
624+
DwarfDebug(AsmPrinter *A, Module *M);
625625

626626
~DwarfDebug() override;
627627

628628
/// Emit all Dwarf sections that should come prior to the
629629
/// content.
630-
void beginModule(Module *M) override;
630+
void beginModule();
631631

632632
/// Emit all Dwarf sections that should come after the content.
633633
void endModule() override;

llvm/lib/CodeGen/MachineModuleInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ char MachineModuleInfoWrapperPass::ID = 0;
304304
bool MachineModuleInfoWrapperPass::doInitialization(Module &M) {
305305
MMI.initialize();
306306
MMI.TheModule = &M;
307-
MMI.DbgInfoAvailable = false;
307+
MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
308308
return false;
309309
}
310310

@@ -319,6 +319,6 @@ MachineModuleInfo MachineModuleAnalysis::run(Module &M,
319319
ModuleAnalysisManager &) {
320320
MachineModuleInfo MMI(TM);
321321
MMI.TheModule = &M;
322-
MMI.DbgInfoAvailable = false;
322+
MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
323323
return MMI;
324324
}

llvm/lib/Target/BPF/BTFDebug.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,9 +1076,6 @@ void BTFDebug::beginInstruction(const MachineInstr *MI) {
10761076
}
10771077
}
10781078

1079-
if (!CurMI) // no debug info
1080-
return;
1081-
10821079
// Skip this instruction if no DebugLoc or the DebugLoc
10831080
// is the same as the previous instruction.
10841081
const DebugLoc &DL = MI->getDebugLoc();

0 commit comments

Comments
 (0)