================ @@ -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 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits