@@ -671,16 +671,14 @@ static int compileModule(char **argv, LLVMContext &Context) {
671671 }
672672
673673 const char *argv0 = argv[0 ];
674- MachineModuleInfoWrapperPass *MMIWP =
675- new MachineModuleInfoWrapperPass (Target.get ());
674+ MachineModuleInfo MMI (Target.get ());
676675
677676 // Construct a custom pass pipeline that starts after instruction
678677 // selection.
679678 if (!getRunPassNames ().empty ()) {
680679 if (!MIR) {
681680 WithColor::error (errs (), argv[0 ])
682681 << " run-pass is for .mir file only.\n " ;
683- delete MMIWP;
684682 return 1 ;
685683 }
686684 TargetPassConfig *PTPC = Target->createPassConfig (PM);
@@ -690,13 +688,12 @@ static int compileModule(char **argv, LLVMContext &Context) {
690688 << " run-pass cannot be used with "
691689 << TPC.getLimitedCodeGenPipelineReason () << " .\n " ;
692690 delete PTPC;
693- delete MMIWP;
694691 return 1 ;
695692 }
696693
697694 TPC.setDisableVerify (NoVerify);
698695 PM.add (&TPC);
699- PM.add (MMIWP );
696+ PM.add (new NonOwningMachineModuleInfoWrapperPass (MMI) );
700697 TPC.printAndVerify (" " );
701698 for (const std::string &RunPassName : getRunPassNames ()) {
702699 if (addPass (PM, argv0, RunPassName, TPC))
@@ -707,15 +704,14 @@ static int compileModule(char **argv, LLVMContext &Context) {
707704 PM.add (createFreeMachineFunctionPass ());
708705 } else if (Target->addPassesToEmitFile (
709706 PM, *OS, DwoOut ? &DwoOut->os () : nullptr ,
710- codegen::getFileType (), NoVerify, MMIWP )) {
707+ codegen::getFileType (), NoVerify, &MMI )) {
711708 reportError (" target does not support generation of this file type" );
712709 }
713710
714711 const_cast <TargetLoweringObjectFile *>(Target->getObjFileLowering ())
715- ->Initialize (MMIWP-> getMMI () .getContext (), *Target);
712+ ->Initialize (MMI .getContext (), *Target);
716713 if (MIR) {
717- assert (MMIWP && " Forgot to create MMIWP?" );
718- if (MIR->parseMachineFunctions (*M, MMIWP->getMMI ()))
714+ if (MIR->parseMachineFunctions (*M, MMI))
719715 return 1 ;
720716 }
721717
0 commit comments