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

Matin Raayai via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 7 07:57:58 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;
----------------
matinraayai wrote:

Originally I intended to only have a single version, but the main issue I found was that creating a `MachineModuleInfo` requires any client of `TargetMachine::addPassesToEmitFile` and `TargetMachine::addPassesToEmitMC` to be linked against `CodeGen`, which it might not be something they want to do. __This only applies to targets that implement codegen, however. All other out-of-tree non-codegen targets are not affected__.

I will change to my originally intended design if you think it's acceptable to force all `TargetMachine` clients to link against `CodeGen`.


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


More information about the llvm-commits mailing list