[llvm-branch-commits] [llvm] [NewPM] Introduce MFAnalysisGetter for a common analysis getter (PR #116166)
Christudasan Devadasan via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 14 00:09:03 PST 2024
================
@@ -236,6 +238,82 @@ using MachineFunctionPassManager = PassManager<MachineFunction>;
/// preserve.
PreservedAnalyses getMachineFunctionPassPreservedAnalyses();
+/// For migrating to new pass manager
+/// Provides a common interface to fetch analyses instead of doing it twice in
+/// the *LegacyPass::runOnMachineFunction and NPM Pass::run.
+///
+/// NPM analyses must have the LegacyWrapper type to indicate which legacy
+/// analysis to run. Legacy wrapper analyses must have `getResult()` method.
+/// This can be added on a needs-to basis.
+///
+/// Outer analyses passes(Module or Function) can also be requested through
+/// `getAnalysis` or `getCachedAnalysis`.
+class MFAnalysisGetter {
+private:
+ Pass *LegacyPass = nullptr;
+ MachineFunctionAnalysisManager *MFAM = nullptr;
+
+ template <typename T>
+ using type_of_run =
+ typename function_traits<decltype(&T::run)>::template arg_t<0>;
+
+ template <typename T>
+ static constexpr bool IsFunctionAnalysis =
+ std::is_same_v<Function &, type_of_run<T>>;
+
+ template <typename T>
+ static constexpr bool IsModuleAnalysis =
+ std::is_same_v<Module &, type_of_run<T>>;
+
+public:
+ MFAnalysisGetter(Pass *LegacyPass) : LegacyPass(LegacyPass) {}
+ MFAnalysisGetter(MachineFunctionAnalysisManager *MFAM) : MFAM(MFAM) {}
+
+ /// Outer analyses requested from NPM will be cached results and can be null
+ template <typename AnalysisT>
+ typename AnalysisT::Result *getAnalysis(MachineFunction &MF) {
+ if (MFAM) {
+ // need a proxy to get the result for outer analyses
----------------
cdevadas wrote:
Capitalize the first character.
https://github.com/llvm/llvm-project/pull/116166
More information about the llvm-branch-commits
mailing list