[llvm] [NewPM][CodeGen] Add `MachineFunctionAnalysis` (PR #88610)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 13 03:02:40 PDT 2024
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/88610
>From 4584ad3a574427f4fc27edd244b11b5240e11c6e Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 12 Apr 2024 20:26:51 +0800
Subject: [PATCH] [NewPM][CodeGen] Add `MachineFunctionAnalysis`
---
.../llvm/CodeGen/MIRParser/MIRParser.h | 9 ++++
.../llvm/CodeGen/MachineFunctionAnalysis.h | 52 +++++++++++++++++++
llvm/include/llvm/CodeGen/MachineModuleInfo.h | 4 ++
.../include/llvm/CodeGen/MachinePassManager.h | 3 ++
llvm/lib/CodeGen/CMakeLists.txt | 1 +
llvm/lib/CodeGen/FreeMachineFunction.cpp | 9 ++--
llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 48 ++++++++++++-----
llvm/lib/CodeGen/MachineFunctionAnalysis.cpp | 38 ++++++++++++++
llvm/lib/CodeGen/MachinePassManager.cpp | 38 ++++++++------
llvm/lib/Passes/PassBuilder.cpp | 1 +
llvm/lib/Passes/PassRegistry.def | 3 ++
llvm/lib/Passes/StandardInstrumentations.cpp | 8 ---
llvm/tools/llc/NewPMDriver.cpp | 4 +-
llvm/unittests/CodeGen/PassManagerTest.cpp | 2 +-
.../MIR/PassBuilderCallbacksTest.cpp | 11 ++--
15 files changed, 180 insertions(+), 51 deletions(-)
create mode 100644 llvm/include/llvm/CodeGen/MachineFunctionAnalysis.h
create mode 100644 llvm/lib/CodeGen/MachineFunctionAnalysis.cpp
diff --git a/llvm/include/llvm/CodeGen/MIRParser/MIRParser.h b/llvm/include/llvm/CodeGen/MIRParser/MIRParser.h
index e1606e7c0ea72d..b805e17e7ec990 100644
--- a/llvm/include/llvm/CodeGen/MIRParser/MIRParser.h
+++ b/llvm/include/llvm/CodeGen/MIRParser/MIRParser.h
@@ -34,6 +34,9 @@ class MachineModuleInfo;
class SMDiagnostic;
class StringRef;
+template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
+using ModuleAnalysisManager = AnalysisManager<Module>;
+
typedef llvm::function_ref<std::optional<std::string>(StringRef, StringRef)>
DataLayoutCallbackTy;
@@ -60,6 +63,12 @@ class MIRParser {
///
/// \returns true if an error occurred.
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI);
+
+ /// Parses MachineFunctions in the MIR file and add them to the given
+ /// MachineModuleInfo \p MMI.
+ ///
+ /// \returns true if an error occurred.
+ bool parseMachineFunctions(Module &M, ModuleAnalysisManager &MAM);
};
/// This function is the main interface to the MIR serialization format parser.
diff --git a/llvm/include/llvm/CodeGen/MachineFunctionAnalysis.h b/llvm/include/llvm/CodeGen/MachineFunctionAnalysis.h
new file mode 100644
index 00000000000000..fe000f75896eba
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/MachineFunctionAnalysis.h
@@ -0,0 +1,52 @@
+//===- llvm/CodeGen/MachineFunctionAnalysis.h -------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the MachineFunctionAnalysis class.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_MACHINEFUNCTIONANALYSIS
+#define LLVM_CODEGEN_MACHINEFUNCTIONANALYSIS
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+class MachineFunction;
+class LLVMTargetMachine;
+
+class MachineFunctionAnalysis
+ : public AnalysisInfoMixin<MachineFunctionAnalysis> {
+ friend AnalysisInfoMixin<MachineFunctionAnalysis>;
+
+ static AnalysisKey Key;
+
+ const LLVMTargetMachine *TM;
+
+public:
+ class Result {
+ std::unique_ptr<MachineFunction> MF;
+
+ public:
+ Result(std::unique_ptr<MachineFunction> MF) : MF(std::move(MF)) {}
+ MachineFunction &getMF() { return *MF; };
+ bool invalidate(Function &, const PreservedAnalyses &PA,
+ FunctionAnalysisManager::Invalidator &) {
+ // Unless it is invalidated explicitly, it should remain preserved.
+ auto PAC = PA.getChecker<MachineFunctionAnalysis>();
+ return !PAC.preservedWhenStateless();
+ }
+ };
+
+ MachineFunctionAnalysis(const LLVMTargetMachine *TM) : TM(TM){};
+ Result run(Function &F, FunctionAnalysisManager &FAM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_MACHINEFUNCTIONANALYSIS
diff --git a/llvm/include/llvm/CodeGen/MachineModuleInfo.h b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
index 5f66d1ada0d082..92ea3c902ce95e 100644
--- a/llvm/include/llvm/CodeGen/MachineModuleInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
@@ -147,10 +147,14 @@ class MachineModuleInfo {
/// Returns the MachineFunction constructed for the IR function \p F.
/// Creates a new MachineFunction if none exists yet.
+ /// NOTE: New pass manager clients shall not use this method to get
+ /// the `MachineFunction`, use `MachineFunctionAnalysis` instead.
MachineFunction &getOrCreateMachineFunction(Function &F);
/// \brief Returns the MachineFunction associated to IR function \p F if there
/// is one, otherwise nullptr.
+ /// NOTE: New pass manager clients shall not use this method to get
+ /// the `MachineFunction`, use `MachineFunctionAnalysis` instead.
MachineFunction *getMachineFunction(const Function &F) const;
/// Delete the MachineFunction \p MF and reset the link in the IR Function to
diff --git a/llvm/include/llvm/CodeGen/MachinePassManager.h b/llvm/include/llvm/CodeGen/MachinePassManager.h
index 4f0b6ba2b1e738..ad63793b264d85 100644
--- a/llvm/include/llvm/CodeGen/MachinePassManager.h
+++ b/llvm/include/llvm/CodeGen/MachinePassManager.h
@@ -76,6 +76,9 @@ struct MachinePassModel
#endif
auto PA = this->Pass.run(IR, AM);
+ // We should preserve all IR analyses.
+ PA.template preserveSet<AllAnalysesOn<Module>>();
+ PA.template preserveSet<AllAnalysesOn<Function>>();
if constexpr (is_detected<has_get_set_properties_t, PassT>::value)
IR.getProperties().set(PassT::getSetProperties());
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index 2c24de60edd43e..86d6f36094f6d7 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -120,6 +120,7 @@ add_llvm_component_library(LLVMCodeGen
MachineDominators.cpp
MachineFrameInfo.cpp
MachineFunction.cpp
+ MachineFunctionAnalysis.cpp
MachineFunctionPass.cpp
MachineFunctionPrinterPass.cpp
MachineFunctionSplitter.cpp
diff --git a/llvm/lib/CodeGen/FreeMachineFunction.cpp b/llvm/lib/CodeGen/FreeMachineFunction.cpp
index f38f3e63a3f37a..5a12bd95312b45 100644
--- a/llvm/lib/CodeGen/FreeMachineFunction.cpp
+++ b/llvm/lib/CodeGen/FreeMachineFunction.cpp
@@ -8,6 +8,7 @@
#include "llvm/CodeGen/FreeMachineFunction.h"
#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionAnalysis.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
using namespace llvm;
@@ -15,8 +16,8 @@ using namespace llvm;
PreservedAnalyses
FreeMachineFunctionPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
- auto &MMI = MF.getMMI();
- MFAM.invalidate(MF, PreservedAnalyses::none());
- MMI.deleteMachineFunctionFor(MF.getFunction()); // MF is dangling now.
- return PreservedAnalyses::none();
+ PreservedAnalyses PA = PreservedAnalyses::none();
+ PA.abandon<MachineFunctionAnalysis>();
+ PA.preserve<FunctionAnalysisManagerMachineFunctionProxy>();
+ return PA;
}
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index 4d9a8dc5602ba6..b65fc8cf5099b8 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -21,6 +21,7 @@
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionAnalysis.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetFrameLowering.h"
@@ -97,13 +98,15 @@ class MIRParserImpl {
/// Create an empty function with the given name.
Function *createDummyFunction(StringRef Name, Module &M);
- bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI);
+ bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI,
+ ModuleAnalysisManager *FAM = nullptr);
/// Parse the machine function in the current YAML document.
///
///
/// Return true if an error occurred.
- bool parseMachineFunction(Module &M, MachineModuleInfo &MMI);
+ bool parseMachineFunction(Module &M, MachineModuleInfo &MMI,
+ ModuleAnalysisManager *FAM);
/// Initialize the machine function to the state that's described in the MIR
/// file.
@@ -275,13 +278,14 @@ MIRParserImpl::parseIRModule(DataLayoutCallbackTy DataLayoutCallback) {
return M;
}
-bool MIRParserImpl::parseMachineFunctions(Module &M, MachineModuleInfo &MMI) {
+bool MIRParserImpl::parseMachineFunctions(Module &M, MachineModuleInfo &MMI,
+ ModuleAnalysisManager *MAM) {
if (NoMIRDocuments)
return false;
// Parse the machine functions.
do {
- if (parseMachineFunction(M, MMI))
+ if (parseMachineFunction(M, MMI, MAM))
return true;
In.nextDocument();
} while (In.setCurrentDocument());
@@ -303,7 +307,8 @@ Function *MIRParserImpl::createDummyFunction(StringRef Name, Module &M) {
return F;
}
-bool MIRParserImpl::parseMachineFunction(Module &M, MachineModuleInfo &MMI) {
+bool MIRParserImpl::parseMachineFunction(Module &M, MachineModuleInfo &MMI,
+ ModuleAnalysisManager *MAM) {
// Parse the yaml.
yaml::MachineFunction YamlMF;
yaml::EmptyContext Ctx;
@@ -327,14 +332,28 @@ bool MIRParserImpl::parseMachineFunction(Module &M, MachineModuleInfo &MMI) {
"' isn't defined in the provided LLVM IR");
}
}
- if (MMI.getMachineFunction(*F) != nullptr)
- return error(Twine("redefinition of machine function '") + FunctionName +
- "'");
- // Create the MachineFunction.
- MachineFunction &MF = MMI.getOrCreateMachineFunction(*F);
- if (initializeMachineFunction(YamlMF, MF))
- return true;
+ if (!MAM) {
+ if (MMI.getMachineFunction(*F) != nullptr)
+ return error(Twine("redefinition of machine function '") + FunctionName +
+ "'");
+
+ // Create the MachineFunction.
+ MachineFunction &MF = MMI.getOrCreateMachineFunction(*F);
+ if (initializeMachineFunction(YamlMF, MF))
+ return true;
+ } else {
+ auto &FAM =
+ MAM->getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+ if (FAM.getCachedResult<MachineFunctionAnalysis>(*F))
+ return error(Twine("redefinition of machine function '") + FunctionName +
+ "'");
+
+ // Create the MachineFunction.
+ MachineFunction &MF = FAM.getResult<MachineFunctionAnalysis>(*F).getMF();
+ if (initializeMachineFunction(YamlMF, MF))
+ return true;
+ }
return false;
}
@@ -1101,6 +1120,11 @@ bool MIRParser::parseMachineFunctions(Module &M, MachineModuleInfo &MMI) {
return Impl->parseMachineFunctions(M, MMI);
}
+bool MIRParser::parseMachineFunctions(Module &M, ModuleAnalysisManager &MAM) {
+ auto &MMI = MAM.getResult<MachineModuleAnalysis>(M).getMMI();
+ return Impl->parseMachineFunctions(M, MMI, &MAM);
+}
+
std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(
StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
std::function<void(Function &)> ProcessIRFunction) {
diff --git a/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp b/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp
new file mode 100644
index 00000000000000..79749fdf600ddb
--- /dev/null
+++ b/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp
@@ -0,0 +1,38 @@
+//===- MachineFunctionAnalysis.cpp ----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the definitions of the MachineFunctionAnalysis members.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/MachineFunctionAnalysis.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/Target/TargetMachine.h"
+
+using namespace llvm;
+
+AnalysisKey MachineFunctionAnalysis::Key;
+
+MachineFunctionAnalysis::Result
+MachineFunctionAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
+ /// Next unique number available for a MachineFunction.
+ static unsigned NextFnNum = 0;
+
+ const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(F);
+ auto &MMI = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F)
+ .getCachedResult<MachineModuleAnalysis>(*F.getParent())
+ ->getMMI();
+ auto MF = std::make_unique<MachineFunction>(F, *TM, STI, NextFnNum++, MMI);
+ MF->initTargetMachineFunctionInfo(STI);
+
+ // MRI callback for target specific initializations.
+ TM->registerMachineRegisterInfoCallback(*MF);
+
+ return Result(std::move(MF));
+}
diff --git a/llvm/lib/CodeGen/MachinePassManager.cpp b/llvm/lib/CodeGen/MachinePassManager.cpp
index 2763193b2c306b..8e68d8249cf971 100644
--- a/llvm/lib/CodeGen/MachinePassManager.cpp
+++ b/llvm/lib/CodeGen/MachinePassManager.cpp
@@ -11,7 +11,9 @@
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/MachinePassManager.h"
+#include "llvm/CodeGen/FreeMachineFunction.h"
#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionAnalysis.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/IR/PassManagerImpl.h"
@@ -71,7 +73,9 @@ bool MachineFunctionAnalysisManagerModuleProxy::Result::invalidate(
PreservedAnalyses
ModuleToMachineFunctionPassAdaptor::run(Module &M, ModuleAnalysisManager &AM) {
- auto &MMI = AM.getResult<MachineModuleAnalysis>(M).getMMI();
+ // Ensure we have a MachineModuleInfo
+ AM.getResult<MachineModuleAnalysis>(M).getMMI();
+ auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
MachineFunctionAnalysisManager &MFAM =
AM.getResult<MachineFunctionAnalysisManagerModuleProxy>(M).getManager();
PassInstrumentation PI = AM.getResult<PassInstrumentationAnalysis>(M);
@@ -82,19 +86,20 @@ ModuleToMachineFunctionPassAdaptor::run(Module &M, ModuleAnalysisManager &AM) {
if (F.isDeclaration() || F.hasAvailableExternallyLinkage())
continue;
- MachineFunction &MF = MMI.getOrCreateMachineFunction(F);
+ MachineFunction &MF = FAM.getResult<MachineFunctionAnalysis>(F).getMF();
if (!PI.runBeforePass<MachineFunction>(*Pass, MF))
continue;
PreservedAnalyses PassPA = Pass->run(MF, MFAM);
- if (MMI.getMachineFunction(F)) {
- MFAM.invalidate(MF, PassPA);
+ MFAM.invalidate(MF, PassPA);
+ if (Pass->name() != FreeMachineFunctionPass::name()) {
PI.runAfterPass(*Pass, MF, PassPA);
+ PA.intersect(std::move(PassPA));
} else {
- MFAM.clear(MF, F.getName());
- PI.runAfterPassInvalidated<MachineFunction>(*Pass, PassPA);
+ PA.intersect(std::move(PassPA));
+ FAM.invalidate(F, PA);
+ PI.runAfterPassInvalidated<MachineFunction>(*Pass, PA);
}
- PA.intersect(std::move(PassPA));
}
return PA;
@@ -112,25 +117,24 @@ PreservedAnalyses
PassManager<MachineFunction>::run(MachineFunction &MF,
AnalysisManager<MachineFunction> &MFAM) {
PassInstrumentation PI = MFAM.getResult<PassInstrumentationAnalysis>(MF);
- Function &F = MF.getFunction();
- MachineModuleInfo &MMI =
- MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF)
- .getCachedResult<MachineModuleAnalysis>(*F.getParent())
- ->getMMI();
+ FunctionAnalysisManager &FAM =
+ MFAM.getResult<FunctionAnalysisManagerMachineFunctionProxy>(MF)
+ .getManager();
PreservedAnalyses PA = PreservedAnalyses::all();
for (auto &Pass : Passes) {
if (!PI.runBeforePass<MachineFunction>(*Pass, MF))
continue;
PreservedAnalyses PassPA = Pass->run(MF, MFAM);
- if (MMI.getMachineFunction(F)) {
- MFAM.invalidate(MF, PassPA);
+ MFAM.invalidate(MF, PassPA);
+ if (Pass->name() != FreeMachineFunctionPass::name()) {
PI.runAfterPass(*Pass, MF, PassPA);
+ PA.intersect(std::move(PassPA));
} else {
- MFAM.clear(MF, F.getName());
- PI.runAfterPassInvalidated<MachineFunction>(*Pass, PassPA);
+ PA.intersect(std::move(PassPA));
+ FAM.invalidate(MF.getFunction(), PA);
+ PI.runAfterPassInvalidated<MachineFunction>(*Pass, PA);
}
- PA.intersect(std::move(PassPA));
}
return PA;
}
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 8d408ca2363a98..77a07da9778d99 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -92,6 +92,7 @@
#include "llvm/CodeGen/JMCInstrumenter.h"
#include "llvm/CodeGen/LowerEmuTLS.h"
#include "llvm/CodeGen/MIRPrinter.h"
+#include "llvm/CodeGen/MachineFunctionAnalysis.h"
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/SafeStack.h"
#include "llvm/CodeGen/SelectOptimize.h"
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index d15f58d7adfae4..66b8388ee10d97 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -258,6 +258,9 @@ FUNCTION_ANALYSIS("gc-function", GCFunctionAnalysis())
FUNCTION_ANALYSIS("inliner-size-estimator", InlineSizeEstimatorAnalysis())
FUNCTION_ANALYSIS("lazy-value-info", LazyValueAnalysis())
FUNCTION_ANALYSIS("loops", LoopAnalysis())
+FUNCTION_ANALYSIS(
+ "machine-function-info",
+ MachineFunctionAnalysis(static_cast<const LLVMTargetMachine *>(TM)))
FUNCTION_ANALYSIS("memdep", MemoryDependenceAnalysis())
FUNCTION_ANALYSIS("memoryssa", MemorySSAAnalysis())
FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index c18b462258623d..63490c83e85f05 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -297,14 +297,6 @@ void unwrapAndPrint(raw_ostream &OS, Any IR) {
auto *M = unwrapModule(IR);
assert(M && "should have unwrapped module");
printIR(OS, M);
-
- if (const auto *MF = unwrapIR<MachineFunction>(IR)) {
- auto &MMI = MF->getMMI();
- for (const auto &F : *M) {
- if (auto *MF = MMI.getMachineFunction(F))
- MF->print(OS);
- }
- }
return;
}
diff --git a/llvm/tools/llc/NewPMDriver.cpp b/llvm/tools/llc/NewPMDriver.cpp
index 6ae1b8db5e115c..e36e77bbd1ad70 100644
--- a/llvm/tools/llc/NewPMDriver.cpp
+++ b/llvm/tools/llc/NewPMDriver.cpp
@@ -121,10 +121,10 @@ int llvm::compileModuleWithNewPM(
registerCodeGenCallback(PIC, LLVMTM);
LoopAnalysisManager LAM;
+ MachineFunctionAnalysisManager MFAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
- MachineFunctionAnalysisManager MFAM;
PassBuilder PB(Target.get(), PipelineTuningOptions(), std::nullopt, &PIC);
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
@@ -155,7 +155,7 @@ int llvm::compileModuleWithNewPM(
MFPM.addPass(FreeMachineFunctionPass());
MPM.addPass(createModuleToMachineFunctionPassAdaptor(std::move(MFPM)));
- if (MIR->parseMachineFunctions(*M, MMI))
+ if (MIR->parseMachineFunctions(*M, MAM))
return 1;
} else {
ExitOnErr(LLVMTM.buildCodeGenPipeline(
diff --git a/llvm/unittests/CodeGen/PassManagerTest.cpp b/llvm/unittests/CodeGen/PassManagerTest.cpp
index 4283eb01a9c8f2..3ba0d9349a46de 100644
--- a/llvm/unittests/CodeGen/PassManagerTest.cpp
+++ b/llvm/unittests/CodeGen/PassManagerTest.cpp
@@ -176,10 +176,10 @@ TEST_F(PassManagerTest, Basic) {
MachineModuleInfo MMI(LLVMTM);
LoopAnalysisManager LAM;
+ MachineFunctionAnalysisManager MFAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
- MachineFunctionAnalysisManager MFAM;
PassBuilder PB(TM.get());
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
diff --git a/llvm/unittests/MIR/PassBuilderCallbacksTest.cpp b/llvm/unittests/MIR/PassBuilderCallbacksTest.cpp
index 6fd4e54a929f40..082ff6c3f67ed0 100644
--- a/llvm/unittests/MIR/PassBuilderCallbacksTest.cpp
+++ b/llvm/unittests/MIR/PassBuilderCallbacksTest.cpp
@@ -316,7 +316,7 @@ class MachineFunctionCallbacksTest : public testing::Test {
static std::unique_ptr<Module> parseMIR(StringRef MIRCode,
LLVMContext &Context,
TargetMachine &TM,
- MachineModuleInfo &MMI) {
+ ModuleAnalysisManager &MAM) {
SMDiagnostic Diagnostic;
std::unique_ptr<MemoryBuffer> MBuffer = MemoryBuffer::getMemBuffer(MIRCode);
std::unique_ptr<MIRParser> MIR =
@@ -330,7 +330,7 @@ class MachineFunctionCallbacksTest : public testing::Test {
Mod->setModuleIdentifier("module");
Mod->setDataLayout(TM.createDataLayout());
- [[maybe_unused]] bool Ret = MIR->parseMachineFunctions(*Mod, MMI);
+ [[maybe_unused]] bool Ret = MIR->parseMachineFunctions(*Mod, MAM);
assert(!Ret);
return Mod;
@@ -355,7 +355,6 @@ class MachineFunctionCallbacksTest : public testing::Test {
GTEST_SKIP();
MMI = std::make_unique<MachineModuleInfo>(TM.get());
- M = parseMIR(MIRString, Context, *TM, *MMI);
PB = std::make_unique<PassBuilder>(TM.get(), PipelineTuningOptions(),
std::nullopt, &PIC);
@@ -399,6 +398,7 @@ class MachineFunctionCallbacksTest : public testing::Test {
PB->registerMachineFunctionAnalyses(MFAM);
PB->crossRegisterProxies(LAM, FAM, CGAM, MAM, &MFAM);
MAM.registerPass([&] { return MachineModuleAnalysis(*MMI); });
+ M = parseMIR(MIRString, Context, *TM, MAM);
}
};
@@ -554,9 +554,6 @@ TEST_F(MachineFunctionCallbacksTest, InstrumentedFreeMFPass2) {
EXPECT_CALL(CallbacksHandle, runAfterPassInvalidated(
HasNameRegex("FreeMachineFunctionPass"), _))
.InSequence(PISequence);
- EXPECT_CALL(CallbacksHandle,
- runAfterPassInvalidated(HasNameRegex("PassManager"), _))
- .InSequence(PISequence);
// runAfterPass should not be called since the MachineFunction is no longer
// valid after FreeMachineFunctionPass.
@@ -564,7 +561,7 @@ TEST_F(MachineFunctionCallbacksTest, InstrumentedFreeMFPass2) {
runAfterPass(HasNameRegex("FreeMachineFunctionPass"), _, _))
.Times(0);
EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("PassManager"), _, _))
- .Times(0);
+ .Times(1);
MachineFunctionPassManager MFPM;
MFPM.addPass(FreeMachineFunctionPass());
More information about the llvm-commits
mailing list