[llvm] [CodeGen] Fix `MachineModuleInfo`'s move constructor to be more safe with `MCContext` ownership. (PR #104834)

Matin Raayai via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 08:48:00 PDT 2024


matinraayai wrote:

> The main issue that's unclear to me for the proposed approach is that who will now be the owner of the `MCContext` if we change the API for `llvm::MachineModuleInfo` to just take a reference to `MCContext`. And if `llvm::MachineModuleInfoWrapperPass` no longer maintain the lifetime of `llvm::MachineModuleInfo`, then who is going to do that?

Both will have to be explicitly managed by the user of the pipeline, just like the `llvm::LLVMContext` and `llvm::Module` are.

In MC-related use cases AFAIK (i.e. MC disassembler, MC AsmParsing, LLVM Bolt, etc) `llvm::MCContext` is explicitly created and manged. What I suggested here just extends this to this particular case here.

As for how MMI will be managed, the new PM driver seems to be initializing and managing it on its own, as it can be
seen here in LLC:
https://github.com/llvm/llvm-project/blob/90a8e5a7ac52d05c2331f0f3d1461fcab6b7d520/llvm/tools/llc/NewPMDriver.cpp#L111

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


More information about the llvm-commits mailing list