Skip to content

Commit 832e088

Browse files
committed
Fixed remaining issues with MMI/MMIWP constructions.
1 parent 8715ed6 commit 832e088

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,9 @@ static std::unique_ptr<MemoryBuffer> codegenModule(Module &TheModule,
331331
{
332332
raw_svector_ostream OS(OutputBuffer);
333333
legacy::PassManager PM;
334-
std::unique_ptr<MachineModuleInfo> MMI = TM.createMachineModuleInfo();
335334

336-
// Setup the codegen pipeline.
335+
// Setup the codegen now.
337336
if (TM.addPassesToEmitFile(PM, OS, nullptr, CodeGenFileType::ObjectFile,
338-
MMI.get(),
339337
/* DisableVerify */ true))
340338
report_fatal_error("Failed to setup codegen");
341339

llvm/tools/llc/llc.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

llvm/tools/llvm-exegesis/lib/Assembler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ createModule(const std::unique_ptr<LLVMContext> &Context, const DataLayout &DL)
233233
BitVector getFunctionReservedRegs(const TargetMachine &TM) {
234234
std::unique_ptr<LLVMContext> Context = std::make_unique<LLVMContext>();
235235
std::unique_ptr<Module> Module = createModule(Context, TM.createDataLayout());
236-
auto MMIWP = std::make_unique<MachineModuleInfoWrapperPass>(&TM);
237-
MachineFunction &MF = createVoidVoidPtrMachineFunction(
238-
FunctionID, Module.get(), &MMIWP->getMMI());
236+
auto MMI = std::make_unique<MachineModuleInfo>(&TM);
237+
MachineFunction &MF =
238+
createVoidVoidPtrMachineFunction(FunctionID, Module.get(), MMI.get());
239239
// Saving reserved registers for client.
240240
return MF.getSubtarget().getRegisterInfo()->getReservedRegs(MF);
241241
}
@@ -248,7 +248,7 @@ Error assembleToStream(const ExegesisTarget &ET,
248248
auto Context = std::make_unique<LLVMContext>();
249249
std::unique_ptr<Module> Module =
250250
createModule(Context, TM->createDataLayout());
251-
auto MMIWP = std::make_unique<MachineModuleInfoWrapperPass>(TM.get());
251+
auto MMIWP = std::make_unique<OwningMachineModuleInfoWrapperPass>(*TM);
252252
MachineFunction &MF = createVoidVoidPtrMachineFunction(
253253
FunctionID, Module.get(), &MMIWP.get()->getMMI());
254254
MF.ensureAlignment(kFunctionAlignment);

0 commit comments

Comments
 (0)