[llvm] Reland "SelectionDAG: Avoid using MachineFunction::getMMI" (PR #99779)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 23 21:58:43 PDT 2024
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/99779
>From 3d11cc0d62c28ea95c8097ed9e160730efe00a7a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 22 Jul 2024 21:02:26 +0400
Subject: [PATCH] Reapply "SelectionDAG: Avoid using MachineFunction::getMMI"
(#99777)
This reverts commit 98c0e55d9d31ea0a7b8a1e5395257f10a6a27cc6.
Folds in new PM fix from #99754.
---
llvm/include/llvm/CodeGen/SelectionDAG.h | 9 ++++++---
llvm/include/llvm/CodeGen/SelectionDAGISel.h | 1 +
.../llvm/Passes/MachinePassRegistry.def | 1 +
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 3 ++-
.../SelectionDAG/SelectionDAGBuilder.cpp | 6 +++---
.../CodeGen/SelectionDAG/SelectionDAGISel.cpp | 18 ++++++++++++------
.../CodeGen/AArch64SelectionDAGTest.cpp | 3 ++-
.../SelectionDAGAddressAnalysisTest.cpp | 3 ++-
.../CodeGen/SelectionDAGPatternMatchTest.cpp | 3 ++-
9 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index 16ec65f2e7daa..24eab7b408675 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -245,6 +245,7 @@ class SelectionDAG {
ProfileSummaryInfo *PSI = nullptr;
BlockFrequencyInfo *BFI = nullptr;
+ MachineModuleInfo *MMI = nullptr;
/// List of non-single value types.
FoldingSet<SDVTListNode> VTListMap;
@@ -459,14 +460,15 @@ class SelectionDAG {
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE,
Pass *PassPtr, const TargetLibraryInfo *LibraryInfo,
UniformityInfo *UA, ProfileSummaryInfo *PSIin,
- BlockFrequencyInfo *BFIin, FunctionVarLocs const *FnVarLocs);
+ BlockFrequencyInfo *BFIin, MachineModuleInfo &MMI,
+ FunctionVarLocs const *FnVarLocs);
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE,
MachineFunctionAnalysisManager &AM,
const TargetLibraryInfo *LibraryInfo, UniformityInfo *UA,
ProfileSummaryInfo *PSIin, BlockFrequencyInfo *BFIin,
- FunctionVarLocs const *FnVarLocs) {
- init(NewMF, NewORE, nullptr, LibraryInfo, UA, PSIin, BFIin, FnVarLocs);
+ MachineModuleInfo &MMI, FunctionVarLocs const *FnVarLocs) {
+ init(NewMF, NewORE, nullptr, LibraryInfo, UA, PSIin, BFIin, MMI, FnVarLocs);
MFAM = &AM;
}
@@ -500,6 +502,7 @@ class SelectionDAG {
OptimizationRemarkEmitter &getORE() const { return *ORE; }
ProfileSummaryInfo *getPSI() const { return PSI; }
BlockFrequencyInfo *getBFI() const { return BFI; }
+ MachineModuleInfo *getMMI() const { return MMI; }
FlagInserter *getFlagInserter() { return Inserter; }
void setFlagInserter(FlagInserter *FI) { Inserter = FI; }
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
index aa0efa5d9bf5d..fc0590b1a1b69 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -48,6 +48,7 @@ class SelectionDAGISel {
std::unique_ptr<FunctionLoweringInfo> FuncInfo;
SwiftErrorValueTracking *SwiftError;
MachineFunction *MF;
+ MachineModuleInfo *MMI;
MachineRegisterInfo *RegInfo;
SelectionDAG *CurDAG;
std::unique_ptr<SelectionDAGBuilder> SDB;
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index 03f0782de6fed..e702721c299a8 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -17,6 +17,7 @@
#define MODULE_ANALYSIS(NAME, CREATE_PASS)
#endif
MODULE_ANALYSIS("collector-metadata", CollectorMetadataAnalysis())
+MODULE_ANALYSIS("machine-module-info", MachineModuleAnalysis())
MODULE_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
#undef MODULE_ANALYSIS
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index d420edc8f2060..bbc44a4716405 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -1333,7 +1333,7 @@ void SelectionDAG::init(MachineFunction &NewMF,
OptimizationRemarkEmitter &NewORE, Pass *PassPtr,
const TargetLibraryInfo *LibraryInfo,
UniformityInfo *NewUA, ProfileSummaryInfo *PSIin,
- BlockFrequencyInfo *BFIin,
+ BlockFrequencyInfo *BFIin, MachineModuleInfo &MMIin,
FunctionVarLocs const *VarLocs) {
MF = &NewMF;
SDAGISelPass = PassPtr;
@@ -1345,6 +1345,7 @@ void SelectionDAG::init(MachineFunction &NewMF,
UA = NewUA;
PSI = PSIin;
BFI = BFIin;
+ MMI = &MMIin;
FnVarLocs = VarLocs;
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 548be3c272421..1791f1b503379 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -6707,11 +6707,11 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
getValue(I.getArgOperand(0))));
return;
case Intrinsic::eh_sjlj_callsite: {
- MachineModuleInfo &MMI = DAG.getMachineFunction().getMMI();
ConstantInt *CI = cast<ConstantInt>(I.getArgOperand(0));
- assert(MMI.getCurrentCallSite() == 0 && "Overlapping call sites!");
+ assert(DAG.getMMI()->getCurrentCallSite() == 0 &&
+ "Overlapping call sites!");
- MMI.setCurrentCallSite(CI->getZExtValue());
+ DAG.getMMI()->setCurrentCallSite(CI->getZExtValue());
return;
}
case Intrinsic::eh_sjlj_functioncontext: {
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index df3d207d85d35..401d23b22adcd 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -509,7 +509,10 @@ void SelectionDAGISel::initializeAnalysisResults(
FnVarLocs = &FAM.getResult<DebugAssignmentTrackingAnalysis>(Fn);
auto *UA = FAM.getCachedResult<UniformityInfoAnalysis>(Fn);
- CurDAG->init(*MF, *ORE, MFAM, LibInfo, UA, PSI, BFI, FnVarLocs);
+ MachineModuleInfo &MMI =
+ MAMP.getCachedResult<MachineModuleAnalysis>(*Fn.getParent())->getMMI();
+
+ CurDAG->init(*MF, *ORE, MFAM, LibInfo, UA, PSI, BFI, MMI, FnVarLocs);
// Now get the optional analyzes if we want to.
// This is based on the possibly changed OptLevel (after optnone is taken
@@ -562,7 +565,11 @@ void SelectionDAGISel::initializeAnalysisResults(MachineFunctionPass &MFP) {
UniformityInfo *UA = nullptr;
if (auto *UAPass = MFP.getAnalysisIfAvailable<UniformityInfoWrapperPass>())
UA = &UAPass->getUniformityInfo();
- CurDAG->init(*MF, *ORE, &MFP, LibInfo, UA, PSI, BFI, FnVarLocs);
+
+ MachineModuleInfo &MMI =
+ MFP.getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
+
+ CurDAG->init(*MF, *ORE, &MFP, LibInfo, UA, PSI, BFI, MMI, FnVarLocs);
// Now get the optional analyzes if we want to.
// This is based on the possibly changed OptLevel (after optnone is taken
@@ -796,7 +803,7 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
}
// Determine if floating point is used for msvc
- computeUsesMSVCFloatingPoint(TM.getTargetTriple(), Fn, MF->getMMI());
+ computeUsesMSVCFloatingPoint(TM.getTargetTriple(), Fn, *CurDAG->getMMI());
// Release function-specific state. SDB and CurDAG are already cleared
// at this point.
@@ -1443,7 +1450,6 @@ bool SelectionDAGISel::PrepareEHLandingPad() {
// Mark and Report IPToState for each Block under IsEHa
void SelectionDAGISel::reportIPToStateForBlocks(MachineFunction *MF) {
- MachineModuleInfo &MMI = MF->getMMI();
llvm::WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo();
if (!EHInfo)
return;
@@ -1458,8 +1464,8 @@ void SelectionDAGISel::reportIPToStateForBlocks(MachineFunction *MF) {
continue;
// Insert EH Labels
- MCSymbol *BeginLabel = MMI.getContext().createTempSymbol();
- MCSymbol *EndLabel = MMI.getContext().createTempSymbol();
+ MCSymbol *BeginLabel = MF->getContext().createTempSymbol();
+ MCSymbol *EndLabel = MF->getContext().createTempSymbol();
EHInfo->addIPToStateRange(State, BeginLabel, EndLabel);
BuildMI(MBB, MBBb, SDB->getCurDebugLoc(),
TII->get(TargetOpcode::EH_LABEL))
diff --git a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
index cc574b5887efc..877793a28b769 100644
--- a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
+++ b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
@@ -68,7 +68,8 @@ class AArch64SelectionDAGTest : public testing::Test {
if (!DAG)
report_fatal_error("DAG?");
OptimizationRemarkEmitter ORE(F);
- DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
+ DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, MMI,
+ nullptr);
}
TargetLoweringBase::LegalizeTypeAction getTypeAction(EVT VT) {
diff --git a/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp b/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp
index 88c4dbc2eec78..ef30bd491d352 100644
--- a/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp
@@ -78,7 +78,8 @@ class SelectionDAGAddressAnalysisTest : public testing::Test {
if (!DAG)
report_fatal_error("DAG?");
OptimizationRemarkEmitter ORE(F);
- DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
+ DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, MMI,
+ nullptr);
}
TargetLoweringBase::LegalizeTypeAction getTypeAction(EVT VT) {
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index a3d5e5f94b610..e318f467bbf27 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -77,7 +77,8 @@ class SelectionDAGPatternMatchTest : public testing::Test {
if (!DAG)
report_fatal_error("DAG?");
OptimizationRemarkEmitter ORE(F);
- DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
+ DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, MMI,
+ nullptr);
}
TargetLoweringBase::LegalizeTypeAction getTypeAction(EVT VT) {
More information about the llvm-commits
mailing list