Skip to content

Commit 63e1647

Browse files
authored
CodeGen: Remove MachineModuleInfo reference from MachineFunction (#100357)
This avoids another unserializable field. Move the DbgInfoAvailable field into the AsmPrinter, which is only really a cache/convenience bit for checking a direct IR module metadata check.
1 parent 4ce3993 commit 63e1647

24 files changed

+57
-62
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ class AsmPrinter : public MachineFunctionPass {
225225
/// split stack prologue.
226226
bool HasNoSplitStack = false;
227227

228+
/// True if debugging information is available in this module.
229+
bool DbgInfoAvailable = false;
230+
228231
protected:
229232
explicit AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
230233

@@ -430,6 +433,9 @@ class AsmPrinter : public MachineFunctionPass {
430433
/// Get the CFISection type for the module.
431434
CFISection getModuleCFISectionType() const { return ModuleCFISection; }
432435

436+
/// Returns true if valid debug info is present.
437+
bool hasDebugInfo() const { return DbgInfoAvailable; }
438+
433439
bool needsSEHMoves();
434440

435441
/// Since emitting CFI unwind information is entangled with supporting the

llvm/include/llvm/CodeGen/MIRPrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace llvm {
2121

2222
class MachineBasicBlock;
2323
class MachineFunction;
24+
class MachineModuleInfo;
2425
class Module;
2526
template <typename T> class SmallVectorImpl;
2627

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class MachineConstantPool;
5959
class MachineFrameInfo;
6060
class MachineFunction;
6161
class MachineJumpTableInfo;
62-
class MachineModuleInfo;
6362
class MachineRegisterInfo;
6463
class MCContext;
6564
class MCInstrDesc;
@@ -260,7 +259,6 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
260259
const LLVMTargetMachine &Target;
261260
const TargetSubtargetInfo *STI;
262261
MCContext &Ctx;
263-
MachineModuleInfo &MMI;
264262

265263
// RegInfo - Information about each register in use in the function.
266264
MachineRegisterInfo *RegInfo;
@@ -395,15 +393,15 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
395393

396394
/// \}
397395

398-
/// Clear all the members of this MachineFunction, but the ones used
399-
/// to initialize again the MachineFunction.
400-
/// More specifically, this deallocates all the dynamically allocated
401-
/// objects and get rid of all the XXXInfo data structure, but keep
402-
/// unchanged the references to Fn, Target, MMI, and FunctionNumber.
396+
/// Clear all the members of this MachineFunction, but the ones used to
397+
/// initialize again the MachineFunction. More specifically, this deallocates
398+
/// all the dynamically allocated objects and get rids of all the XXXInfo data
399+
/// structure, but keeps unchanged the references to Fn, Target, and
400+
/// FunctionNumber.
403401
void clear();
404402
/// Allocate and initialize the different members.
405403
/// In particular, the XXXInfo data structure.
406-
/// \pre Fn, Target, MMI, and FunctionNumber are properly set.
404+
/// \pre Fn, Target, and FunctionNumber are properly set.
407405
void init();
408406

409407
public:
@@ -632,8 +630,8 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
632630
const static unsigned int DebugOperandMemNumber;
633631

634632
MachineFunction(Function &F, const LLVMTargetMachine &Target,
635-
const TargetSubtargetInfo &STI, unsigned FunctionNum,
636-
MachineModuleInfo &MMI);
633+
const TargetSubtargetInfo &STI, MCContext &Ctx,
634+
unsigned FunctionNum);
637635
MachineFunction(const MachineFunction &) = delete;
638636
MachineFunction &operator=(const MachineFunction &) = delete;
639637
~MachineFunction();
@@ -665,7 +663,6 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
665663

666664
GISelChangeObserver *getObserver() const { return Observer; }
667665

668-
MachineModuleInfo &getMMI() const { return MMI; }
669666
MCContext &getContext() const { return Ctx; }
670667

671668
/// Returns the Section this function belongs to.

llvm/include/llvm/CodeGen/MachineModuleInfo.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ class MachineModuleInfo {
9999
/// want.
100100
MachineModuleInfoImpl *ObjFileMMI;
101101

102-
/// True if debugging information is available in this module.
103-
bool DbgInfoAvailable = false;
104-
105102
/// Maps IR Functions to their corresponding MachineFunctions.
106103
DenseMap<const Function*, std::unique_ptr<MachineFunction>> MachineFunctions;
107104
/// Next unique number available for a MachineFunction.
@@ -168,9 +165,6 @@ class MachineModuleInfo {
168165
return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
169166
}
170167

171-
/// Returns true if valid debug info is present.
172-
bool hasDebugInfo() const { return DbgInfoAvailable; }
173-
174168
/// \}
175169
}; // End class MachineModuleInfo
176170

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct KnownBits;
7676
class LLVMContext;
7777
class MachineBasicBlock;
7878
class MachineConstantPoolValue;
79+
class MachineModuleInfo;
7980
class MCSymbol;
8081
class OptimizationRemarkEmitter;
8182
class ProfileSummaryInfo;

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class LiveIntervals;
4646
class LiveVariables;
4747
class MachineLoop;
4848
class MachineMemOperand;
49+
class MachineModuleInfo;
4950
class MachineRegisterInfo;
5051
class MCAsmInfo;
5152
class MCInst;

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ bool AsmPrinter::doInitialization(Module &M) {
436436
MMI = MMIWP ? &MMIWP->getMMI() : nullptr;
437437
HasSplitStack = false;
438438
HasNoSplitStack = false;
439+
DbgInfoAvailable = !M.debug_compile_units().empty();
439440

440441
AddrLabelSymbols = nullptr;
441442

@@ -541,8 +542,7 @@ bool AsmPrinter::doInitialization(Module &M) {
541542
if (EmitCodeView && TM.getTargetTriple().isOSWindows())
542543
DebugHandlers.push_back(std::make_unique<CodeViewDebug>(this));
543544
if (!EmitCodeView || M.getDwarfVersion()) {
544-
assert(MMI && "MMI could not be nullptr here!");
545-
if (MMI->hasDebugInfo()) {
545+
if (hasDebugInfo()) {
546546
DD = new DwarfDebug(this);
547547
DebugHandlers.push_back(std::unique_ptr<DwarfDebug>(DD));
548548
}
@@ -1277,8 +1277,7 @@ AsmPrinter::getFunctionCFISectionType(const Function &F) const {
12771277
if (MAI->usesCFIWithoutEH() && F.hasUWTable())
12781278
return CFISection::EH;
12791279

1280-
assert(MMI != nullptr && "Invalid machine module info");
1281-
if (MMI->hasDebugInfo() || TM.Options.ForceDwarfFrameSection)
1280+
if (hasDebugInfo() || TM.Options.ForceDwarfFrameSection)
12821281
return CFISection::Debug;
12831282

12841283
return CFISection::None;
@@ -1669,10 +1668,9 @@ void AsmPrinter::emitPCSections(const MachineFunction &MF) {
16691668
}
16701669

16711670
/// Returns true if function begin and end labels should be emitted.
1672-
static bool needFuncLabels(const MachineFunction &MF,
1673-
const MachineModuleInfo &MMI) {
1674-
if (!MF.getLandingPads().empty() || MF.hasEHFunclets() ||
1675-
MMI.hasDebugInfo() ||
1671+
static bool needFuncLabels(const MachineFunction &MF, const AsmPrinter &Asm) {
1672+
if (Asm.hasDebugInfo() || !MF.getLandingPads().empty() ||
1673+
MF.hasEHFunclets() ||
16761674
MF.getFunction().hasMetadata(LLVMContext::MD_pcsections))
16771675
return true;
16781676

@@ -1944,7 +1942,7 @@ void AsmPrinter::emitFunctionBody() {
19441942
// are automatically sized.
19451943
bool EmitFunctionSize = MAI->hasDotTypeDotSizeDirective() && !TT.isWasm();
19461944

1947-
if (needFuncLabels(*MF, *MMI) || EmitFunctionSize) {
1945+
if (EmitFunctionSize || needFuncLabels(*MF, *this)) {
19481946
// Create a symbol for the end of function.
19491947
CurrentFnEnd = createTempSymbol("func_end");
19501948
OutStreamer->emitLabel(CurrentFnEnd);
@@ -2588,7 +2586,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
25882586
if (F.hasFnAttribute("patchable-function-entry") ||
25892587
F.hasFnAttribute("function-instrument") ||
25902588
F.hasFnAttribute("xray-instruction-threshold") ||
2591-
needFuncLabels(MF, *MMI) || NeedsLocalForSize ||
2589+
needFuncLabels(MF, *this) || NeedsLocalForSize ||
25922590
MF.getTarget().Options.EmitStackSizeSection ||
25932591
MF.getTarget().Options.BBAddrMap || MF.hasBBLabels()) {
25942592
CurrentFnBegin = createTempSymbol("func_begin");

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
613613
void CodeViewDebug::beginModule(Module *M) {
614614
// If module doesn't have named metadata anchors or COFF debug section
615615
// is not available, skip any debug info related stuff.
616-
if (!MMI->hasDebugInfo() ||
616+
if (!Asm->hasDebugInfo() ||
617617
!Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) {
618618
Asm = nullptr;
619619
return;
@@ -636,7 +636,7 @@ void CodeViewDebug::beginModule(Module *M) {
636636
}
637637

638638
void CodeViewDebug::endModule() {
639-
if (!Asm || !MMI->hasDebugInfo())
639+
if (!Asm || !Asm->hasDebugInfo())
640640
return;
641641

642642
// The COFF .debug$S section consists of several subsections, each starting

llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
351351
}
352352

353353
void DebugHandlerBase::beginInstruction(const MachineInstr *MI) {
354-
if (!Asm || !MMI->hasDebugInfo())
354+
if (!Asm || !Asm->hasDebugInfo())
355355
return;
356356

357357
assert(CurMI == nullptr);
@@ -377,7 +377,7 @@ void DebugHandlerBase::beginInstruction(const MachineInstr *MI) {
377377
}
378378

379379
void DebugHandlerBase::endInstruction() {
380-
if (!Asm || !MMI->hasDebugInfo())
380+
if (!Asm || !Asm->hasDebugInfo())
381381
return;
382382

383383
assert(CurMI != nullptr);

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ void DwarfDebug::endModule() {
14341434

14351435
// If we aren't actually generating debug info (check beginModule -
14361436
// conditionalized on the presence of the llvm.dbg.cu metadata node)
1437-
if (!Asm || !MMI->hasDebugInfo())
1437+
if (!Asm || !Asm->hasDebugInfo())
14381438
return;
14391439

14401440
// Finalize the debug info for the module.

0 commit comments

Comments
 (0)