matinraayai wrote: > > @aeubanks @arsenm after looking into this in more detail, I realized that > > the `getContext` method of `MMI` is heavily used in the `AsmPrinter` to > > create symbols. Also not having it makes it harder for the `MMI` to create > > machine functions using `getOrCreateMachineFunction`. > > The AsmPrinter is just an ordinary ModulePass. The initialization can just > set a MMI member?
I agree that separating `MCContext` from `MMI` is not an issue for `AsmPrinter`; But I don't see a way to do that with `MachineModuleInfo::getOrCreateMachineFunction`, besides making it take an explicit `MCContext` argument here: ```c++ MachineFunction &MachineModuleInfo::getOrCreateMachineFunction(Function &F, MCContext &MCCtx) { // Shortcut for the common case where a sequence of MachineFunctionPasses // all query for the same Function. if (LastRequest == &F) return *LastResult; auto I = MachineFunctions.insert( std::make_pair(&F, std::unique_ptr<MachineFunction>())); MachineFunction *MF; if (I.second) { // No pre-existing machine function, create a new one. const TargetSubtargetInfo &STI = *TM.getSubtargetImpl(F); MF = new MachineFunction(F, TM, STI, MCCtx, NextFnNum++); MF->initTargetMachineFunctionInfo(STI); // MRI callback for target specific initializations. TM.registerMachineRegisterInfoCallback(*MF); // Update the set entry. I.first->second.reset(MF); } else { MF = I.first->second.get(); } LastRequest = &F; LastResult = MF; return *MF; } ``` Also the constructor for MMI sets the context's object file info here: ```c++ MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM) : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(), TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(), nullptr, &TM->Options.MCOptions, false) { Context.setObjectFileInfo(TM->getObjFileLowering()); initialize(); } ``` Again, for both these cases, it's possible to remove the `MCContext` from `MMI`; However doing so will make it harder to use in my opinion. https://github.com/llvm/llvm-project/pull/105541 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits