@@ -208,20 +208,22 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,
208208 return std::move (AsmStreamer);
209209}
210210
211- std::unique_ptr<MachineModuleInfo>
212- CodeGenTargetMachineImpl::createMachineModuleInfo () const override {
213- return std::make_unique<MachineModuleInfo>(this );
214- }
215-
216211bool CodeGenTargetMachineImpl::addPassesToEmitFile (
217212 PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
218- CodeGenFileType FileType, MachineModuleInfo *MMI, bool DisableVerify) {
219- // Check if MMI is nullptr, or if MMI pointer is valid but the target
220- // machine of the MMI is not the same as this target machine
221- if (!MMI || &MMI->getTarget () != this )
222- return true ;
213+ CodeGenFileType FileType, bool DisableVerify, MachineModuleInfo *MMI) {
223214 // Add the wrapper pass for MMI
224- auto *MMIWP = new MachineModuleInfoWrapperPass (MMI);
215+ MachineModuleInfoWrapperPass *MMIWP;
216+ if (MMI) {
217+ MMIWP = new NonOwningMachineModuleInfoWrapperPass (*MMI);
218+ } else {
219+ MMIWP = new OwningMachineModuleInfoWrapperPass (*this );
220+ MMI = &MMIWP->getMMI ();
221+ }
222+ // Check (for the case of externally-managed MMI) if the TM of MMI is
223+ // the same as this target machine
224+ if (&MMI->getTarget () != this )
225+ return true ;
226+
225227 TargetPassConfig *PassConfig =
226228 addPassesToGenerateCode (*this , PM, DisableVerify, *MMIWP);
227229 if (!PassConfig)
@@ -240,21 +242,22 @@ bool CodeGenTargetMachineImpl::addPassesToEmitFile(
240242 return false ;
241243}
242244
243- // / addPassesToEmitMC - Add passes to the specified pass manager to get
244- // / machine code emitted with the MCJIT. This method returns true if machine
245- // / code is not supported. It fills the MCContext Ctx pointer which can be
246- // / used to build custom MCStreamer.
247- // /
248245bool CodeGenTargetMachineImpl::addPassesToEmitMC (PassManagerBase &PM,
249246 raw_pwrite_stream &Out,
250- MachineModuleInfo *MMI,
251- bool DisableVerify) {
252- // Check if MMI is nullptr, or if MMI pointer is valid but the target
253- // machine of the MMI is not the same as this target machine
254- if (!MMI || &MMI->getTarget () != this )
247+ bool DisableVerify,
248+ MachineModuleInfo *MMI) {
249+ // Add the wrapper pass for MMI
250+ MachineModuleInfoWrapperPass *MMIWP;
251+ if (MMI) {
252+ MMIWP = new NonOwningMachineModuleInfoWrapperPass (*MMI);
253+ } else {
254+ MMIWP = new OwningMachineModuleInfoWrapperPass (*this );
255+ MMI = &MMIWP->getMMI ();
256+ }
257+ // Check (for the case of externally-managed MMI) if the TM of MMI is
258+ // the same as this target machine
259+ if (&MMI->getTarget () != this )
255260 return true ;
256- // Add common CodeGen passes.
257- MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass (MMI);
258261 TargetPassConfig *PassConfig =
259262 addPassesToGenerateCode (*this , PM, DisableVerify, *MMIWP);
260263 if (!PassConfig)
0 commit comments