@@ -208,20 +208,27 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,
208
208
return std::move (AsmStreamer);
209
209
}
210
210
211
+ std::unique_ptr<MachineModuleInfo>
212
+ CodeGenTargetMachineImpl::createMachineModuleInfo () const override {
213
+ return std::make_unique<MachineModuleInfo>(this );
214
+ }
215
+
211
216
bool CodeGenTargetMachineImpl::addPassesToEmitFile (
212
217
PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
213
- CodeGenFileType FileType, bool DisableVerify,
214
- MachineModuleInfoWrapperPass *MMIWP) {
215
- // Add common CodeGen passes.
216
- if (!MMIWP)
217
- MMIWP = new MachineModuleInfoWrapperPass (this );
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 ;
223
+ // Add the wrapper pass for MMI
224
+ auto *MMIWP = new MachineModuleInfoWrapperPass (MMI);
218
225
TargetPassConfig *PassConfig =
219
226
addPassesToGenerateCode (*this , PM, DisableVerify, *MMIWP);
220
227
if (!PassConfig)
221
228
return true ;
222
229
223
230
if (TargetPassConfig::willCompleteCodeGenPipeline ()) {
224
- if (addAsmPrinter (PM, Out, DwoOut, FileType, MMIWP-> getMMI (). getContext ()))
231
+ if (addAsmPrinter (PM, Out, DwoOut, FileType, MMI-> getContext ()))
225
232
return true ;
226
233
} else {
227
234
// MIR printing is redundant with -filetype=null.
@@ -239,19 +246,23 @@ bool CodeGenTargetMachineImpl::addPassesToEmitFile(
239
246
// / used to build custom MCStreamer.
240
247
// /
241
248
bool CodeGenTargetMachineImpl::addPassesToEmitMC (PassManagerBase &PM,
242
- MCContext *&Ctx,
243
249
raw_pwrite_stream &Out,
250
+ MachineModuleInfo *MMI,
244
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 )
255
+ return true ;
245
256
// Add common CodeGen passes.
246
- MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass (this );
257
+ MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass (MMI );
247
258
TargetPassConfig *PassConfig =
248
259
addPassesToGenerateCode (*this , PM, DisableVerify, *MMIWP);
249
260
if (!PassConfig)
250
261
return true ;
251
262
assert (TargetPassConfig::willCompleteCodeGenPipeline () &&
252
263
" Cannot emit MC with limited codegen pipeline" );
253
264
254
- Ctx = &MMIWP-> getMMI (). getContext ();
265
+ MCContext & Ctx = MMI-> getContext ();
255
266
// libunwind is unable to load compact unwind dynamically, so we must generate
256
267
// DWARF unwind info for the JIT.
257
268
Options.MCOptions .EmitDwarfUnwind = EmitDwarfUnwindType::Always;
@@ -261,7 +272,7 @@ bool CodeGenTargetMachineImpl::addPassesToEmitMC(PassManagerBase &PM,
261
272
const MCSubtargetInfo &STI = *getMCSubtargetInfo ();
262
273
const MCRegisterInfo &MRI = *getMCRegisterInfo ();
263
274
std::unique_ptr<MCCodeEmitter> MCE (
264
- getTarget ().createMCCodeEmitter (*getMCInstrInfo (), * Ctx));
275
+ getTarget ().createMCCodeEmitter (*getMCInstrInfo (), Ctx));
265
276
if (!MCE)
266
277
return true ;
267
278
MCAsmBackend *MAB =
@@ -271,7 +282,7 @@ bool CodeGenTargetMachineImpl::addPassesToEmitMC(PassManagerBase &PM,
271
282
272
283
const Triple &T = getTargetTriple ();
273
284
std::unique_ptr<MCStreamer> AsmStreamer (getTarget ().createMCObjectStreamer (
274
- T, * Ctx, std::unique_ptr<MCAsmBackend>(MAB), MAB->createObjectWriter (Out),
285
+ T, Ctx, std::unique_ptr<MCAsmBackend>(MAB), MAB->createObjectWriter (Out),
275
286
std::move (MCE), STI));
276
287
277
288
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
0 commit comments