Skip to content

Commit 284f0ef

Browse files
committed
CodeGen: Remove MachineModuleInfo reference from MachineFunction
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 1e3fdb2 commit 284f0ef

22 files changed

+57
-63
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/MachineFunction.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
260260
const LLVMTargetMachine &Target;
261261
const TargetSubtargetInfo *STI;
262262
MCContext &Ctx;
263-
MachineModuleInfo &MMI;
264263

265264
// RegInfo - Information about each register in use in the function.
266265
MachineRegisterInfo *RegInfo;
@@ -395,15 +394,15 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
395394

396395
/// \}
397396

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.
397+
/// Clear all the members of this MachineFunction, but the ones used to
398+
/// initialize again the MachineFunction. More specifically, this deallocates
399+
/// all the dynamically allocated objects and get rid of all the XXXInfo data
400+
/// structure, but keep unchanged the references to Fn, Target, and
401+
/// FunctionNumber.
403402
void clear();
404403
/// Allocate and initialize the different members.
405404
/// In particular, the XXXInfo data structure.
406-
/// \pre Fn, Target, MMI, and FunctionNumber are properly set.
405+
/// \pre Fn, Target, and FunctionNumber are properly set.
407406
void init();
408407

409408
public:
@@ -632,8 +631,8 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
632631
const static unsigned int DebugOperandMemNumber;
633632

634633
MachineFunction(Function &F, const LLVMTargetMachine &Target,
635-
const TargetSubtargetInfo &STI, unsigned FunctionNum,
636-
MachineModuleInfo &MMI);
634+
const TargetSubtargetInfo &STI, MCContext &Ctx,
635+
unsigned FunctionNum);
637636
MachineFunction(const MachineFunction &) = delete;
638637
MachineFunction &operator=(const MachineFunction &) = delete;
639638
~MachineFunction();
@@ -665,7 +664,6 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
665664

666665
GISelChangeObserver *getObserver() const { return Observer; }
667666

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

671669
/// 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
@@ -113,9 +113,6 @@ class MachineModuleInfo {
113113
// -g. At this moment, there's no way to specify that some CFI directives
114114
// go into .eh_frame only, while others go into .debug_frame only.
115115

116-
/// True if debugging information is available in this module.
117-
bool DbgInfoAvailable = false;
118-
119116
/// True if this module is being built for windows/msvc, and uses floating
120117
/// point. This is used to emit an undefined reference to _fltused.
121118
bool UsesMSVCFloatingPoint = false;
@@ -186,9 +183,6 @@ class MachineModuleInfo {
186183
return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
187184
}
188185

189-
/// Returns true if valid debug info is present.
190-
bool hasDebugInfo() const { return DbgInfoAvailable; }
191-
192186
bool usesMSVCFloatingPoint() const { return UsesMSVCFloatingPoint; }
193187

194188
void setUsesMSVCFloatingPoint(bool b) { UsesMSVCFloatingPoint = b; }

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 8 additions & 9 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
}
@@ -1278,7 +1278,7 @@ AsmPrinter::getFunctionCFISectionType(const Function &F) const {
12781278
return CFISection::EH;
12791279

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

12841284
return CFISection::None;
@@ -1669,11 +1669,10 @@ void AsmPrinter::emitPCSections(const MachineFunction &MF) {
16691669
}
16701670

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

16791678
// We might emit an EH table that uses function begin and end labels even if
@@ -1944,7 +1943,7 @@ void AsmPrinter::emitFunctionBody() {
19441943
// are automatically sized.
19451944
bool EmitFunctionSize = MAI->hasDotTypeDotSizeDirective() && !TT.isWasm();
19461945

1947-
if (needFuncLabels(*MF, *MMI) || EmitFunctionSize) {
1946+
if (EmitFunctionSize || needFuncLabels(*MF, *this)) {
19481947
// Create a symbol for the end of function.
19491948
CurrentFnEnd = createTempSymbol("func_end");
19501949
OutStreamer->emitLabel(CurrentFnEnd);
@@ -2588,7 +2587,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
25882587
if (F.hasFnAttribute("patchable-function-entry") ||
25892588
F.hasFnAttribute("function-instrument") ||
25902589
F.hasFnAttribute("xray-instruction-threshold") ||
2591-
needFuncLabels(MF, *MMI) || NeedsLocalForSize ||
2590+
needFuncLabels(MF, *this) || NeedsLocalForSize ||
25922591
MF.getTarget().Options.EmitStackSizeSection ||
25932592
MF.getTarget().Options.BBAddrMap || MF.hasBBLabels()) {
25942593
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.

llvm/lib/CodeGen/MachineFunction.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ static inline Align getFnStackAlignment(const TargetSubtargetInfo *STI,
162162
}
163163

164164
MachineFunction::MachineFunction(Function &F, const LLVMTargetMachine &Target,
165-
const TargetSubtargetInfo &STI,
166-
unsigned FunctionNum, MachineModuleInfo &mmi)
167-
: F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {
165+
const TargetSubtargetInfo &STI, MCContext &Ctx,
166+
unsigned FunctionNum)
167+
: F(F), Target(Target), STI(&STI), Ctx(Ctx) {
168168
FunctionNumber = FunctionNum;
169169
init();
170170
}
@@ -654,9 +654,9 @@ void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {
654654

655655
/// True if this function needs frame moves for debug or exceptions.
656656
bool MachineFunction::needsFrameMoves() const {
657-
return getMMI().hasDebugInfo() ||
658-
getTarget().Options.ForceDwarfFrameSection ||
659-
F.needsUnwindTableEntry();
657+
return getTarget().Options.ForceDwarfFrameSection ||
658+
F.needsUnwindTableEntry() ||
659+
!F.getParent()->debug_compile_units().empty();
660660
}
661661

662662
namespace llvm {

llvm/lib/CodeGen/MachineFunctionAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ MachineFunctionAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
3737
.getCachedResult<MachineModuleAnalysis>(*F.getParent())
3838
->getMMI();
3939
auto MF = std::make_unique<MachineFunction>(
40-
F, *TM, STI, Context.generateMachineFunctionNum(F), MMI);
40+
F, *TM, STI, MMI.getContext(), Context.generateMachineFunctionNum(F));
4141
MF->initTargetMachineFunctionInfo(STI);
4242

4343
// MRI callback for target specific initializations.

llvm/lib/CodeGen/MachineModuleInfo.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ void MachineModuleInfo::initialize() {
3939
CurCallSite = 0;
4040
NextFnNum = 0;
4141
UsesMSVCFloatingPoint = false;
42-
DbgInfoAvailable = false;
4342
}
4443

4544
void MachineModuleInfo::finalize() {
@@ -100,7 +99,7 @@ MachineFunction &MachineModuleInfo::getOrCreateMachineFunction(Function &F) {
10099
if (I.second) {
101100
// No pre-existing machine function, create a new one.
102101
const TargetSubtargetInfo &STI = *TM.getSubtargetImpl(F);
103-
MF = new MachineFunction(F, TM, STI, NextFnNum++, *this);
102+
MF = new MachineFunction(F, TM, STI, getContext(), NextFnNum++);
104103
MF->initTargetMachineFunctionInfo(STI);
105104

106105
// MRI callback for target specific initializations.
@@ -220,7 +219,6 @@ bool MachineModuleInfoWrapperPass::doInitialization(Module &M) {
220219
Ctx.diagnose(
221220
DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, LocCookie));
222221
});
223-
MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
224222
return false;
225223
}
226224

@@ -245,6 +243,5 @@ MachineModuleAnalysis::run(Module &M, ModuleAnalysisManager &) {
245243
Ctx.diagnose(
246244
DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, LocCookie));
247245
});
248-
MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
249246
return Result(MMI);
250247
}

0 commit comments

Comments
 (0)