[llvm] Add A Version Of `MachineModuleInfoWrapperPass` That Does Not Own Its Underlying `MachineModuleInfo` (PR #134554)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 6 20:23:19 PDT 2025


================
@@ -167,22 +163,51 @@ class MachineModuleInfo {
   /// \}
 }; // End class MachineModuleInfo
 
+/// \brief Interface for pass that provide access to \c MachineModuleInfo
+/// being worked on
 class MachineModuleInfoWrapperPass : public ImmutablePass {
-  MachineModuleInfo MMI;
 
 public:
   static char ID; // Pass identification, replacement for typeid
-  explicit MachineModuleInfoWrapperPass(const TargetMachine *TM = nullptr);
-
-  explicit MachineModuleInfoWrapperPass(const TargetMachine *TM,
-                                        MCContext *ExtContext);
+  MachineModuleInfoWrapperPass();
 
   // Initialization and Finalization
   bool doInitialization(Module &) override;
   bool doFinalization(Module &) override;
 
-  MachineModuleInfo &getMMI() { return MMI; }
-  const MachineModuleInfo &getMMI() const { return MMI; }
+  virtual MachineModuleInfo &getMMI() = 0;
+  virtual const MachineModuleInfo &getMMI() const = 0;
+};
+
+/// \brief a version of \c MachineModuleInfoWrapperPass that manages the
+/// lifetime of its \c MachineModuleInfo
+class OwningMachineModuleInfoWrapperPass : public MachineModuleInfoWrapperPass {
+  MachineModuleInfo MMI;
----------------
arsenm wrote:

I think we should not have different versions of the pass. We should change wholly change the ownership mode for the pass to not own it.

(Also I've been thinking we should rename MachineModuleInfo. It's really more of a "MachineFunctionMap" or something)

https://github.com/llvm/llvm-project/pull/134554


More information about the llvm-commits mailing list