[llvm-branch-commits] [llvm] CodeGen: Remove MachineModuleInfo reference from MachineFunction (PR #100357)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jul 24 11:31:12 PDT 2024
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/100357
>From 8aff4bdfa99b782379a5383af548c4250605ed63 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sat, 20 Jul 2024 14:24:23 +0400
Subject: [PATCH 1/3] 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.
---
llvm/include/llvm/CodeGen/AsmPrinter.h | 6 ++++++
llvm/include/llvm/CodeGen/MachineFunction.h | 18 ++++++++----------
llvm/include/llvm/CodeGen/MachineModuleInfo.h | 6 ------
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 17 ++++++++---------
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 4 ++--
.../CodeGen/AsmPrinter/DebugHandlerBase.cpp | 4 ++--
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 2 +-
llvm/lib/CodeGen/MachineFunction.cpp | 12 ++++++------
llvm/lib/CodeGen/MachineFunctionAnalysis.cpp | 2 +-
llvm/lib/CodeGen/MachineModuleInfo.cpp | 5 +----
.../SelectionDAG/SelectionDAGBuilder.cpp | 6 +++---
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 4 +---
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 12 ++++++------
llvm/tools/llvm-reduce/ReducerWorkItem.cpp | 2 +-
.../CodeGen/AArch64SelectionDAGTest.cpp | 4 ++--
llvm/unittests/CodeGen/InstrRefLDVTest.cpp | 2 +-
llvm/unittests/CodeGen/MFCommon.inc | 3 ++-
.../SelectionDAGAddressAnalysisTest.cpp | 2 +-
.../CodeGen/SelectionDAGPatternMatchTest.cpp | 2 +-
.../AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp | 3 ++-
llvm/unittests/Target/AMDGPU/PALMetadata.cpp | 2 +-
.../Target/RISCV/RISCVInstrInfoTest.cpp | 2 +-
22 files changed, 57 insertions(+), 63 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h
index f57be39076a78..36d1b47973870 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -225,6 +225,9 @@ class AsmPrinter : public MachineFunctionPass {
/// split stack prologue.
bool HasNoSplitStack = false;
+ /// True if debugging information is available in this module.
+ bool DbgInfoAvailable = false;
+
protected:
explicit AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
@@ -430,6 +433,9 @@ class AsmPrinter : public MachineFunctionPass {
/// Get the CFISection type for the module.
CFISection getModuleCFISectionType() const { return ModuleCFISection; }
+ /// Returns true if valid debug info is present.
+ bool hasDebugInfo() const { return DbgInfoAvailable; }
+
bool needsSEHMoves();
/// Since emitting CFI unwind information is entangled with supporting the
diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index 6e7292abeddbb..142570b9ce551 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -260,7 +260,6 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
const LLVMTargetMachine &Target;
const TargetSubtargetInfo *STI;
MCContext &Ctx;
- MachineModuleInfo &MMI;
// RegInfo - Information about each register in use in the function.
MachineRegisterInfo *RegInfo;
@@ -395,15 +394,15 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
/// \}
- /// Clear all the members of this MachineFunction, but the ones used
- /// to initialize again the MachineFunction.
- /// More specifically, this deallocates all the dynamically allocated
- /// objects and get rid of all the XXXInfo data structure, but keep
- /// unchanged the references to Fn, Target, MMI, and FunctionNumber.
+ /// Clear all the members of this MachineFunction, but the ones used to
+ /// initialize again the MachineFunction. More specifically, this deallocates
+ /// all the dynamically allocated objects and get rid of all the XXXInfo data
+ /// structure, but keep unchanged the references to Fn, Target, and
+ /// FunctionNumber.
void clear();
/// Allocate and initialize the different members.
/// In particular, the XXXInfo data structure.
- /// \pre Fn, Target, MMI, and FunctionNumber are properly set.
+ /// \pre Fn, Target, and FunctionNumber are properly set.
void init();
public:
@@ -632,8 +631,8 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
const static unsigned int DebugOperandMemNumber;
MachineFunction(Function &F, const LLVMTargetMachine &Target,
- const TargetSubtargetInfo &STI, unsigned FunctionNum,
- MachineModuleInfo &MMI);
+ const TargetSubtargetInfo &STI, MCContext &Ctx,
+ unsigned FunctionNum);
MachineFunction(const MachineFunction &) = delete;
MachineFunction &operator=(const MachineFunction &) = delete;
~MachineFunction();
@@ -665,7 +664,6 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
GISelChangeObserver *getObserver() const { return Observer; }
- MachineModuleInfo &getMMI() const { return MMI; }
MCContext &getContext() const { return Ctx; }
/// Returns the Section this function belongs to.
diff --git a/llvm/include/llvm/CodeGen/MachineModuleInfo.h b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
index 97b439c726b0a..b39db93b021b5 100644
--- a/llvm/include/llvm/CodeGen/MachineModuleInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
@@ -113,9 +113,6 @@ class MachineModuleInfo {
// -g. At this moment, there's no way to specify that some CFI directives
// go into .eh_frame only, while others go into .debug_frame only.
- /// True if debugging information is available in this module.
- bool DbgInfoAvailable = false;
-
/// True if this module is being built for windows/msvc, and uses floating
/// point. This is used to emit an undefined reference to _fltused.
bool UsesMSVCFloatingPoint = false;
@@ -186,9 +183,6 @@ class MachineModuleInfo {
return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
}
- /// Returns true if valid debug info is present.
- bool hasDebugInfo() const { return DbgInfoAvailable; }
-
bool usesMSVCFloatingPoint() const { return UsesMSVCFloatingPoint; }
void setUsesMSVCFloatingPoint(bool b) { UsesMSVCFloatingPoint = b; }
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 2297b27ffdc07..5ce53619d6519 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -436,6 +436,7 @@ bool AsmPrinter::doInitialization(Module &M) {
MMI = MMIWP ? &MMIWP->getMMI() : nullptr;
HasSplitStack = false;
HasNoSplitStack = false;
+ DbgInfoAvailable = !M.debug_compile_units().empty();
AddrLabelSymbols = nullptr;
@@ -541,8 +542,7 @@ bool AsmPrinter::doInitialization(Module &M) {
if (EmitCodeView && TM.getTargetTriple().isOSWindows())
DebugHandlers.push_back(std::make_unique<CodeViewDebug>(this));
if (!EmitCodeView || M.getDwarfVersion()) {
- assert(MMI && "MMI could not be nullptr here!");
- if (MMI->hasDebugInfo()) {
+ if (hasDebugInfo()) {
DD = new DwarfDebug(this);
DebugHandlers.push_back(std::unique_ptr<DwarfDebug>(DD));
}
@@ -1278,7 +1278,7 @@ AsmPrinter::getFunctionCFISectionType(const Function &F) const {
return CFISection::EH;
assert(MMI != nullptr && "Invalid machine module info");
- if (MMI->hasDebugInfo() || TM.Options.ForceDwarfFrameSection)
+ if (hasDebugInfo() || TM.Options.ForceDwarfFrameSection)
return CFISection::Debug;
return CFISection::None;
@@ -1669,11 +1669,10 @@ void AsmPrinter::emitPCSections(const MachineFunction &MF) {
}
/// Returns true if function begin and end labels should be emitted.
-static bool needFuncLabels(const MachineFunction &MF,
- const MachineModuleInfo &MMI) {
+static bool needFuncLabels(const MachineFunction &MF, const AsmPrinter &Asm) {
if (!MF.getLandingPads().empty() || MF.hasEHFunclets() ||
- MMI.hasDebugInfo() ||
- MF.getFunction().hasMetadata(LLVMContext::MD_pcsections))
+ MF.getFunction().hasMetadata(LLVMContext::MD_pcsections) ||
+ Asm.hasDebugInfo())
return true;
// We might emit an EH table that uses function begin and end labels even if
@@ -1944,7 +1943,7 @@ void AsmPrinter::emitFunctionBody() {
// are automatically sized.
bool EmitFunctionSize = MAI->hasDotTypeDotSizeDirective() && !TT.isWasm();
- if (needFuncLabels(*MF, *MMI) || EmitFunctionSize) {
+ if (EmitFunctionSize || needFuncLabels(*MF, *this)) {
// Create a symbol for the end of function.
CurrentFnEnd = createTempSymbol("func_end");
OutStreamer->emitLabel(CurrentFnEnd);
@@ -2588,7 +2587,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
if (F.hasFnAttribute("patchable-function-entry") ||
F.hasFnAttribute("function-instrument") ||
F.hasFnAttribute("xray-instruction-threshold") ||
- needFuncLabels(MF, *MMI) || NeedsLocalForSize ||
+ needFuncLabels(MF, *this) || NeedsLocalForSize ||
MF.getTarget().Options.EmitStackSizeSection ||
MF.getTarget().Options.BBAddrMap || MF.hasBBLabels()) {
CurrentFnBegin = createTempSymbol("func_begin");
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index dddc08b3bc016..7700ffd6da803 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -613,7 +613,7 @@ static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
void CodeViewDebug::beginModule(Module *M) {
// If module doesn't have named metadata anchors or COFF debug section
// is not available, skip any debug info related stuff.
- if (!MMI->hasDebugInfo() ||
+ if (!Asm->hasDebugInfo() ||
!Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) {
Asm = nullptr;
return;
@@ -636,7 +636,7 @@ void CodeViewDebug::beginModule(Module *M) {
}
void CodeViewDebug::endModule() {
- if (!Asm || !MMI->hasDebugInfo())
+ if (!Asm || !Asm->hasDebugInfo())
return;
// The COFF .debug$S section consists of several subsections, each starting
diff --git a/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp b/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
index ed99eb3c459e5..de2263c57493b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
@@ -351,7 +351,7 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
}
void DebugHandlerBase::beginInstruction(const MachineInstr *MI) {
- if (!Asm || !MMI->hasDebugInfo())
+ if (!Asm || !Asm->hasDebugInfo())
return;
assert(CurMI == nullptr);
@@ -377,7 +377,7 @@ void DebugHandlerBase::beginInstruction(const MachineInstr *MI) {
}
void DebugHandlerBase::endInstruction() {
- if (!Asm || !MMI->hasDebugInfo())
+ if (!Asm || !Asm->hasDebugInfo())
return;
assert(CurMI != nullptr);
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index fbce7e92b7781..ac4d0f21de60b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1434,7 +1434,7 @@ void DwarfDebug::endModule() {
// If we aren't actually generating debug info (check beginModule -
// conditionalized on the presence of the llvm.dbg.cu metadata node)
- if (!Asm || !MMI->hasDebugInfo())
+ if (!Asm || !Asm->hasDebugInfo())
return;
// Finalize the debug info for the module.
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index 7f6a75208d253..f067f78be946d 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -162,9 +162,9 @@ static inline Align getFnStackAlignment(const TargetSubtargetInfo *STI,
}
MachineFunction::MachineFunction(Function &F, const LLVMTargetMachine &Target,
- const TargetSubtargetInfo &STI,
- unsigned FunctionNum, MachineModuleInfo &mmi)
- : F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {
+ const TargetSubtargetInfo &STI, MCContext &Ctx,
+ unsigned FunctionNum)
+ : F(F), Target(Target), STI(&STI), Ctx(Ctx) {
FunctionNumber = FunctionNum;
init();
}
@@ -654,9 +654,9 @@ void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {
/// True if this function needs frame moves for debug or exceptions.
bool MachineFunction::needsFrameMoves() const {
- return getMMI().hasDebugInfo() ||
- getTarget().Options.ForceDwarfFrameSection ||
- F.needsUnwindTableEntry();
+ return getTarget().Options.ForceDwarfFrameSection ||
+ F.needsUnwindTableEntry() ||
+ !F.getParent()->debug_compile_units().empty();
}
namespace llvm {
diff --git a/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp b/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp
index 24eb360723dad..e7a4d6d61e211 100644
--- a/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp
+++ b/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp
@@ -37,7 +37,7 @@ MachineFunctionAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
.getCachedResult<MachineModuleAnalysis>(*F.getParent())
->getMMI();
auto MF = std::make_unique<MachineFunction>(
- F, *TM, STI, Context.generateMachineFunctionNum(F), MMI);
+ F, *TM, STI, MMI.getContext(), Context.generateMachineFunctionNum(F));
MF->initTargetMachineFunctionInfo(STI);
// MRI callback for target specific initializations.
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp
index 883d870736490..12dec288b3ce2 100644
--- a/llvm/lib/CodeGen/MachineModuleInfo.cpp
+++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp
@@ -39,7 +39,6 @@ void MachineModuleInfo::initialize() {
CurCallSite = 0;
NextFnNum = 0;
UsesMSVCFloatingPoint = false;
- DbgInfoAvailable = false;
}
void MachineModuleInfo::finalize() {
@@ -100,7 +99,7 @@ MachineFunction &MachineModuleInfo::getOrCreateMachineFunction(Function &F) {
if (I.second) {
// No pre-existing machine function, create a new one.
const TargetSubtargetInfo &STI = *TM.getSubtargetImpl(F);
- MF = new MachineFunction(F, TM, STI, NextFnNum++, *this);
+ MF = new MachineFunction(F, TM, STI, getContext(), NextFnNum++);
MF->initTargetMachineFunctionInfo(STI);
// MRI callback for target specific initializations.
@@ -220,7 +219,6 @@ bool MachineModuleInfoWrapperPass::doInitialization(Module &M) {
Ctx.diagnose(
DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, LocCookie));
});
- MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
return false;
}
@@ -245,6 +243,5 @@ MachineModuleAnalysis::run(Module &M, ModuleAnalysisManager &) {
Ctx.diagnose(
DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, LocCookie));
});
- MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
return Result(MMI);
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 1791f1b503379..57a483a5a57ce 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -8619,7 +8619,7 @@ SDValue SelectionDAGBuilder::lowerStartEH(SDValue Chain,
const BasicBlock *EHPadBB,
MCSymbol *&BeginLabel) {
MachineFunction &MF = DAG.getMachineFunction();
- MachineModuleInfo &MMI = MF.getMMI();
+ MachineModuleInfo *MMI = DAG.getMMI();
// Insert a label before the invoke call to mark the try range. This can be
// used to detect deletion of the invoke via the MachineModuleInfo.
@@ -8627,13 +8627,13 @@ SDValue SelectionDAGBuilder::lowerStartEH(SDValue Chain,
// For SjLj, keep track of which landing pads go with which invokes
// so as to maintain the ordering of pads in the LSDA.
- unsigned CallSiteIndex = MMI.getCurrentCallSite();
+ unsigned CallSiteIndex = MMI->getCurrentCallSite();
if (CallSiteIndex) {
MF.setCallSiteBeginLabel(BeginLabel, CallSiteIndex);
LPadToCallSiteMap[FuncInfo.MBBMap[EHPadBB]].push_back(CallSiteIndex);
// Now that the call site is handled, stop tracking it.
- MMI.setCurrentCallSite(0);
+ MMI->setCurrentCallSite(0);
}
return DAG.getEHLabel(getCurSDLoc(), Chain, BeginLabel);
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index b4eba07afe7c5..d7197a7923eaf 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -928,8 +928,6 @@ void NVPTXAsmPrinter::emitHeader(Module &M, raw_ostream &O,
}
bool NVPTXAsmPrinter::doFinalization(Module &M) {
- bool HasDebugInfo = MMI && MMI->hasDebugInfo();
-
// If we did not emit any functions, then the global declarations have not
// yet been emitted.
if (!GlobalsEmitted) {
@@ -945,7 +943,7 @@ bool NVPTXAsmPrinter::doFinalization(Module &M) {
auto *TS =
static_cast<NVPTXTargetStreamer *>(OutStreamer->getTargetStreamer());
// Close the last emitted section
- if (HasDebugInfo) {
+ if (hasDebugInfo()) {
TS->closeLastSection();
// Emit empty .debug_loc section for better support of the empty files.
OutStreamer->emitRawText("\t.section\t.debug_loc\t{\t}");
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 0e2811f87c817..dcde86388dcd9 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -3137,11 +3137,11 @@ void PPCAIXAsmPrinter::emitInstruction(const MachineInstr *MI) {
break;
MCSymbol *TempSym = OutContext.createNamedTempSymbol();
OutStreamer->emitLabel(TempSym);
- OutStreamer->emitXCOFFExceptDirective(CurrentFnSym, TempSym,
- LangMO.getImm(), ReasonMO.getImm(),
- Subtarget->isPPC64() ? MI->getMF()->getInstructionCount() * 8 :
- MI->getMF()->getInstructionCount() * 4,
- MMI->hasDebugInfo());
+ OutStreamer->emitXCOFFExceptDirective(
+ CurrentFnSym, TempSym, LangMO.getImm(), ReasonMO.getImm(),
+ Subtarget->isPPC64() ? MI->getMF()->getInstructionCount() * 8
+ : MI->getMF()->getInstructionCount() * 4,
+ hasDebugInfo());
break;
}
case PPC::GETtlsMOD32AIX:
@@ -3199,7 +3199,7 @@ void PPCAIXAsmPrinter::emitInstruction(const MachineInstr *MI) {
bool PPCAIXAsmPrinter::doFinalization(Module &M) {
// Do streamer related finalization for DWARF.
- if (!MAI->usesDwarfFileAndLocDirectives() && MMI->hasDebugInfo())
+ if (!MAI->usesDwarfFileAndLocDirectives() && hasDebugInfo())
OutStreamer->doFinalizationAtSectionEnd(
OutStreamer->getContext().getObjectFileInfo()->getTextSection());
diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index 629996d74194e..3d36d80f82315 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -232,7 +232,7 @@ static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF,
MachineModuleInfo &DestMMI) {
auto DstMF = std::make_unique<MachineFunction>(
SrcMF->getFunction(), SrcMF->getTarget(), SrcMF->getSubtarget(),
- SrcMF->getFunctionNumber(), DestMMI);
+ SrcMF->getContext(), SrcMF->getFunctionNumber());
DenseMap<MachineBasicBlock *, MachineBasicBlock *> Src2DstMBB;
auto *SrcMRI = &SrcMF->getRegInfo();
diff --git a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
index 877793a28b769..79e27c7ced61f 100644
--- a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
+++ b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
@@ -61,8 +61,8 @@ class AArch64SelectionDAGTest : public testing::Test {
MachineModuleInfo MMI(TM.get());
- MF = std::make_unique<MachineFunction>(*F, *TM, *TM->getSubtargetImpl(*F), 0,
- MMI);
+ MF = std::make_unique<MachineFunction>(*F, *TM, *TM->getSubtargetImpl(*F),
+ MMI.getContext(), 0);
DAG = std::make_unique<SelectionDAG>(*TM, CodeGenOptLevel::None);
if (!DAG)
diff --git a/llvm/unittests/CodeGen/InstrRefLDVTest.cpp b/llvm/unittests/CodeGen/InstrRefLDVTest.cpp
index 28cfb3046bd47..d5365d9c79492 100644
--- a/llvm/unittests/CodeGen/InstrRefLDVTest.cpp
+++ b/llvm/unittests/CodeGen/InstrRefLDVTest.cpp
@@ -94,7 +94,7 @@ class InstrRefLDVTest : public testing::Test {
const TargetSubtargetInfo &STI = *Machine->getSubtargetImpl(*F);
MF = std::make_unique<MachineFunction>(*F, (LLVMTargetMachine &)*Machine,
- STI, FunctionNum, *MMI);
+ STI, MMI->getContext(), FunctionNum);
// Create metadata: CU, subprogram, some blocks and an inline function
// scope.
diff --git a/llvm/unittests/CodeGen/MFCommon.inc b/llvm/unittests/CodeGen/MFCommon.inc
index 1997e80522975..d464a16f636cf 100644
--- a/llvm/unittests/CodeGen/MFCommon.inc
+++ b/llvm/unittests/CodeGen/MFCommon.inc
@@ -135,6 +135,7 @@ std::unique_ptr<MachineFunction> createMachineFunction(LLVMContext &Ctx,
MachineModuleInfo MMI(TM);
const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(*F);
- return std::make_unique<MachineFunction>(*F, *TM, STI, FunctionNum, MMI);
+ return std::make_unique<MachineFunction>(*F, *TM, STI, MMI.getContext(),
+ FunctionNum);
}
diff --git a/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp b/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp
index ef30bd491d352..c89e5a45ab014 100644
--- a/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp
@@ -72,7 +72,7 @@ class SelectionDAGAddressAnalysisTest : public testing::Test {
MachineModuleInfo MMI(TM.get());
MF = std::make_unique<MachineFunction>(*F, *TM, *TM->getSubtargetImpl(*F),
- 0, MMI);
+ MMI.getContext(), 0);
DAG = std::make_unique<SelectionDAG>(*TM, CodeGenOptLevel::None);
if (!DAG)
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index e318f467bbf27..eadb0e26ba3b2 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -71,7 +71,7 @@ class SelectionDAGPatternMatchTest : public testing::Test {
MachineModuleInfo MMI(TM.get());
MF = std::make_unique<MachineFunction>(*F, *TM, *TM->getSubtargetImpl(*F),
- 0, MMI);
+ MMI.getContext(), 0);
DAG = std::make_unique<SelectionDAG>(*TM, CodeGenOptLevel::None);
if (!DAG)
diff --git a/llvm/unittests/Target/AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp b/llvm/unittests/Target/AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp
index ece288aaf06a0..5ac4edae5f0df 100644
--- a/llvm/unittests/Target/AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp
+++ b/llvm/unittests/Target/AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp
@@ -29,7 +29,8 @@ TEST(AMDGPU, ExecMayBeModifiedBeforeAnyUse) {
auto *F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &Mod);
MachineModuleInfo MMI(TM.get());
- auto MF = std::make_unique<MachineFunction>(*F, *TM, ST, 42, MMI);
+ auto MF =
+ std::make_unique<MachineFunction>(*F, *TM, ST, MMI.getContext(), 42);
auto *BB = MF->CreateMachineBasicBlock();
MF->push_back(BB);
diff --git a/llvm/unittests/Target/AMDGPU/PALMetadata.cpp b/llvm/unittests/Target/AMDGPU/PALMetadata.cpp
index 7d4f3836088ab..86aa4753a2123 100644
--- a/llvm/unittests/Target/AMDGPU/PALMetadata.cpp
+++ b/llvm/unittests/Target/AMDGPU/PALMetadata.cpp
@@ -62,7 +62,7 @@ class PALMetadata : public testing::Test {
TM->getTargetCPU(),
TM->getTargetFeatureString(), *TM);
- MF = std::make_unique<MachineFunction>(*F, *TM, *ST, 1, *MMI);
+ MF = std::make_unique<MachineFunction>(*F, *TM, *ST, MMI->getContext(), 1);
}
};
diff --git a/llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp b/llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp
index 62cfda435a047..fe711619c6320 100644
--- a/llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp
+++ b/llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp
@@ -63,7 +63,7 @@ class RISCVInstrInfoTest : public testing::TestWithParam<const char *> {
TM->getTargetFeatureString(),
TM->getTargetTriple().isArch64Bit() ? "lp64" : "ilp32", 0, 0, *TM);
- MF = std::make_unique<MachineFunction>(*F, *TM, *ST, 42, *MMI);
+ MF = std::make_unique<MachineFunction>(*F, *TM, *ST, MMI->getContext(), 42);
}
};
>From be8107a30337f763308a07a8a4f7a8483b41ac6b Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 24 Jul 2024 19:38:19 +0400
Subject: [PATCH 2/3] Remove forward declare of MachineModuleInfo
---
llvm/include/llvm/CodeGen/MIRPrinter.h | 1 +
llvm/include/llvm/CodeGen/MachineFunction.h | 1 -
llvm/include/llvm/CodeGen/SelectionDAG.h | 1 +
llvm/include/llvm/CodeGen/TargetInstrInfo.h | 1 +
4 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/CodeGen/MIRPrinter.h b/llvm/include/llvm/CodeGen/MIRPrinter.h
index e98ef72243b8d..85bd674c56a60 100644
--- a/llvm/include/llvm/CodeGen/MIRPrinter.h
+++ b/llvm/include/llvm/CodeGen/MIRPrinter.h
@@ -21,6 +21,7 @@ namespace llvm {
class MachineBasicBlock;
class MachineFunction;
+class MachineModuleInfo;
class Module;
template <typename T> class SmallVectorImpl;
diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index 142570b9ce551..a325941d68edb 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -59,7 +59,6 @@ class MachineConstantPool;
class MachineFrameInfo;
class MachineFunction;
class MachineJumpTableInfo;
-class MachineModuleInfo;
class MachineRegisterInfo;
class MCContext;
class MCInstrDesc;
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index 24eab7b408675..6a80c8c7216f6 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -76,6 +76,7 @@ struct KnownBits;
class LLVMContext;
class MachineBasicBlock;
class MachineConstantPoolValue;
+class MachineModuleInfo;
class MCSymbol;
class OptimizationRemarkEmitter;
class ProfileSummaryInfo;
diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
index 54f71c9d221ad..882cadea22369 100644
--- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -46,6 +46,7 @@ class LiveIntervals;
class LiveVariables;
class MachineLoop;
class MachineMemOperand;
+class MachineModuleInfo;
class MachineRegisterInfo;
class MCAsmInfo;
class MCInst;
>From 35d1a903c5af6209f0346626efe69f441a762b88 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 24 Jul 2024 22:28:17 +0400
Subject: [PATCH 3/3] Address comments
---
llvm/include/llvm/CodeGen/MachineFunction.h | 4 ++--
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 7 +++----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index a325941d68edb..e1d03fe6b92c1 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -395,8 +395,8 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
/// Clear all the members of this MachineFunction, but the ones used to
/// initialize again the MachineFunction. More specifically, this deallocates
- /// all the dynamically allocated objects and get rid of all the XXXInfo data
- /// structure, but keep unchanged the references to Fn, Target, and
+ /// all the dynamically allocated objects and get rids of all the XXXInfo data
+ /// structure, but keeps unchanged the references to Fn, Target, and
/// FunctionNumber.
void clear();
/// Allocate and initialize the different members.
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 5ce53619d6519..4e35664e7458d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1277,7 +1277,6 @@ AsmPrinter::getFunctionCFISectionType(const Function &F) const {
if (MAI->usesCFIWithoutEH() && F.hasUWTable())
return CFISection::EH;
- assert(MMI != nullptr && "Invalid machine module info");
if (hasDebugInfo() || TM.Options.ForceDwarfFrameSection)
return CFISection::Debug;
@@ -1670,9 +1669,9 @@ void AsmPrinter::emitPCSections(const MachineFunction &MF) {
/// Returns true if function begin and end labels should be emitted.
static bool needFuncLabels(const MachineFunction &MF, const AsmPrinter &Asm) {
- if (!MF.getLandingPads().empty() || MF.hasEHFunclets() ||
- MF.getFunction().hasMetadata(LLVMContext::MD_pcsections) ||
- Asm.hasDebugInfo())
+ if (Asm.hasDebugInfo() || !MF.getLandingPads().empty() ||
+ MF.hasEHFunclets() ||
+ MF.getFunction().hasMetadata(LLVMContext::MD_pcsections))
return true;
// We might emit an EH table that uses function begin and end labels even if
More information about the llvm-branch-commits
mailing list