Skip to content

Commit 737685e

Browse files
committed
Migrated the remaining test files to the new MMIWP constructor.
1 parent e945366 commit 737685e

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

llvm/lib/Target/TargetMachineC.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm-c/Core.h"
1414
#include "llvm-c/TargetMachine.h"
1515
#include "llvm/Analysis/TargetTransformInfo.h"
16+
#include "llvm/CodeGen/MachineModuleInfo.h"
1617
#include "llvm/IR/DataLayout.h"
1718
#include "llvm/IR/LegacyPassManager.h"
1819
#include "llvm/IR/Module.h"
@@ -295,6 +296,7 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
295296
Module* Mod = unwrap(M);
296297

297298
legacy::PassManager pass;
299+
MachineModuleInfo MMI(static_cast<LLVMTargetMachine*>(TM));
298300

299301
std::string error;
300302

@@ -309,7 +311,7 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
309311
ft = CodeGenFileType::ObjectFile;
310312
break;
311313
}
312-
if (TM->addPassesToEmitFile(pass, OS, nullptr, ft)) {
314+
if (TM->addPassesToEmitFile(pass, MMI, OS, nullptr, ft)) {
313315
error = "TargetMachine can't emit a file of this type";
314316
*ErrorMessage = strdup(error.c_str());
315317
return true;

llvm/tools/llc/llc.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,13 @@ static int compileModule(char **argv, LLVMContext &Context) {
687687

688688
const char *argv0 = argv[0];
689689
LLVMTargetMachine &LLVMTM = static_cast<LLVMTargetMachine &>(*Target);
690-
MachineModuleInfoWrapperPass *MMIWP =
691-
new MachineModuleInfoWrapperPass(&LLVMTM);
690+
MachineModuleInfo MMI(&LLVMTM);
692691

693692
// Construct a custom pass pipeline that starts after instruction
694693
// selection.
695694
if (!getRunPassNames().empty()) {
695+
auto *MMIWP =
696+
new MachineModuleInfoWrapperPass(MMI);
696697
if (!MIR) {
697698
WithColor::warning(errs(), argv[0])
698699
<< "run-pass is for .mir file only.\n";
@@ -722,16 +723,15 @@ static int compileModule(char **argv, LLVMContext &Context) {
722723
PM.add(createPrintMIRPass(*OS));
723724
PM.add(createFreeMachineFunctionPass());
724725
} else if (Target->addPassesToEmitFile(
725-
PM, *OS, DwoOut ? &DwoOut->os() : nullptr,
726-
codegen::getFileType(), NoVerify, MMIWP)) {
726+
PM, MMI, *OS, DwoOut ? &DwoOut->os() : nullptr,
727+
codegen::getFileType(), NoVerify)) {
727728
reportError("target does not support generation of this file type");
728729
}
729730

730731
const_cast<TargetLoweringObjectFile *>(LLVMTM.getObjFileLowering())
731-
->Initialize(MMIWP->getMMI().getContext(), *Target);
732+
->Initialize(MMI.getContext(), *Target);
732733
if (MIR) {
733-
assert(MMIWP && "Forgot to create MMIWP?");
734-
if (MIR->parseMachineFunctions(*M, MMIWP->getMMI()))
734+
if (MIR->parseMachineFunctions(*M, MMI))
735735
return 1;
736736
}
737737

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ BitVector getFunctionReservedRegs(const TargetMachine &TM) {
234234
std::unique_ptr<Module> Module = createModule(Context, TM.createDataLayout());
235235
// TODO: This only works for targets implementing LLVMTargetMachine.
236236
const LLVMTargetMachine &LLVMTM = static_cast<const LLVMTargetMachine &>(TM);
237-
auto MMIWP = std::make_unique<MachineModuleInfoWrapperPass>(&LLVMTM);
237+
MachineModuleInfo MMI(&LLVMTM);
238238
MachineFunction &MF = createVoidVoidPtrMachineFunction(
239-
FunctionID, Module.get(), &MMIWP->getMMI());
239+
FunctionID, Module.get(), &MMI);
240240
// Saving reserved registers for client.
241241
return MF.getSubtarget().getRegisterInfo()->getReservedRegs(MF);
242242
}
@@ -249,9 +249,9 @@ Error assembleToStream(const ExegesisTarget &ET,
249249
auto Context = std::make_unique<LLVMContext>();
250250
std::unique_ptr<Module> Module =
251251
createModule(Context, TM->createDataLayout());
252-
auto MMIWP = std::make_unique<MachineModuleInfoWrapperPass>(TM.get());
252+
MachineModuleInfo MMI(TM.get());
253253
MachineFunction &MF = createVoidVoidPtrMachineFunction(
254-
FunctionID, Module.get(), &MMIWP.get()->getMMI());
254+
FunctionID, Module.get(), &MMI);
255255
MF.ensureAlignment(kFunctionAlignment);
256256

257257
// We need to instruct the passes that we're done with SSA and virtual
@@ -308,15 +308,15 @@ Error assembleToStream(const ExegesisTarget &ET,
308308
MF.getRegInfo().freezeReservedRegs();
309309

310310
// We create the pass manager, run the passes to populate AsmBuffer.
311-
MCContext &MCContext = MMIWP->getMMI().getContext();
311+
MCContext &MCContext = MMI.getContext();
312312
legacy::PassManager PM;
313313

314314
TargetLibraryInfoImpl TLII(Triple(Module->getTargetTriple()));
315315
PM.add(new TargetLibraryInfoWrapperPass(TLII));
316316

317317
TargetPassConfig *TPC = TM->createPassConfig(PM);
318318
PM.add(TPC);
319-
PM.add(MMIWP.release());
319+
PM.add(new llvm::MachineModuleInfoWrapperPass(MMI));
320320
TPC->printAndVerify("MachineFunctionGenerator::assemble");
321321
// Add target-specific passes.
322322
ET.addTargetSpecificPasses(PM);

llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/Bitcode/BitcodeReader.h"
1616
#include "llvm/Bitcode/BitcodeWriter.h"
1717
#include "llvm/CodeGen/CommandFlags.h"
18+
#include "llvm/CodeGen/MachineModuleInfo.h"
1819
#include "llvm/FuzzMutate/FuzzerCLI.h"
1920
#include "llvm/FuzzMutate/IRMutator.h"
2021
#include "llvm/FuzzMutate/Operations.h"
@@ -96,10 +97,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
9697

9798
// Build up a PM to do instruction selection.
9899
legacy::PassManager PM;
100+
MachineModuleInfo MMI(static_cast<LLVMTargetMachine*>(TM.get()));
99101
TargetLibraryInfoImpl TLII(TM->getTargetTriple());
100102
PM.add(new TargetLibraryInfoWrapperPass(TLII));
101103
raw_null_ostream OS;
102-
TM->addPassesToEmitFile(PM, OS, nullptr, CodeGenFileType::Null);
104+
TM->addPassesToEmitFile(PM, MMI, OS, nullptr, CodeGenFileType::Null);
103105
PM.run(*M);
104106

105107
return 0;

llvm/unittests/CodeGen/AMDGPUMetadataTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "llvm/CodeGen/MachineModuleInfo.h"
1516
#include "llvm/IR/LegacyPassManager.h"
1617
#include "llvm/IR/Module.h"
1718
#include "llvm/MC/TargetRegistry.h"
@@ -68,9 +69,10 @@ class AMDGPUSelectionDAGTest : public testing::Test {
6869
M->setDataLayout(TM->createDataLayout());
6970

7071
legacy::PassManager PM;
72+
MachineModuleInfo MMI(TM.get());
7173
PM.add(new AddMetadataPass(PalMDString));
7274
raw_svector_ostream OutStream(Elf);
73-
if (TM->addPassesToEmitFile(PM, OutStream, nullptr,
75+
if (TM->addPassesToEmitFile(PM, MMI, OutStream, nullptr,
7476
CodeGenFileType::ObjectFile))
7577
report_fatal_error("Target machine cannot emit a file of this type");
7678

llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ class AsmPrinterHandlerTest : public AsmPrinterFixtureBase {
400400
AP->addAsmPrinterHandler(std::make_unique<TestHandler>(*this));
401401
LLVMTargetMachine *LLVMTM = static_cast<LLVMTargetMachine *>(&AP->TM);
402402
legacy::PassManager PM;
403-
PM.add(new MachineModuleInfoWrapperPass(LLVMTM));
403+
MachineModuleInfo MMI(LLVMTM);
404+
PM.add(new MachineModuleInfoWrapperPass(MMI));
404405
PM.add(TestPrinter->releaseAP()); // Takes ownership of destroying AP
405406
LLVMContext Context;
406407
std::unique_ptr<Module> M(new Module("TestModule", Context));
@@ -450,7 +451,8 @@ class AsmPrinterDebugHandlerTest : public AsmPrinterFixtureBase {
450451
AP->addDebugHandler(std::make_unique<TestDebugHandler>(*this, AP));
451452
LLVMTargetMachine *LLVMTM = static_cast<LLVMTargetMachine *>(&AP->TM);
452453
legacy::PassManager PM;
453-
PM.add(new MachineModuleInfoWrapperPass(LLVMTM));
454+
MachineModuleInfo MMI;
455+
PM.add(new MachineModuleInfoWrapperPass(MMI));
454456
PM.add(TestPrinter->releaseAP()); // Takes ownership of destroying AP
455457
LLVMContext Context;
456458
std::unique_ptr<Module> M(new Module("TestModule", Context));

llvm/unittests/MI/LiveIntervalTest.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ std::unique_ptr<LLVMTargetMachine> createTargetMachine() {
5555
}
5656

5757
std::unique_ptr<Module> parseMIR(LLVMContext &Context,
58-
legacy::PassManagerBase &PM,
58+
MachineModuleInfo &MMI,
5959
std::unique_ptr<MIRParser> &MIR,
6060
const LLVMTargetMachine &TM,
6161
StringRef MIRCode) {
@@ -71,10 +71,8 @@ std::unique_ptr<Module> parseMIR(LLVMContext &Context,
7171

7272
M->setDataLayout(TM.createDataLayout());
7373

74-
MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass(&TM);
75-
if (MIR->parseMachineFunctions(*M, MMIWP->getMMI()))
74+
if (MIR->parseMachineFunctions(*M, MMI))
7675
return nullptr;
77-
PM.add(MMIWP);
7876

7977
return M;
8078
}
@@ -212,10 +210,13 @@ static void doTest(StringRef MIRFunc,
212210
return;
213211

214212
legacy::PassManager PM;
213+
MachineModuleInfo MMI(TM->get());
215214
std::unique_ptr<MIRParser> MIR;
216-
std::unique_ptr<Module> M = parseMIR(Context, PM, MIR, *TM, MIRFunc);
215+
std::unique_ptr<Module> M = parseMIR(Context, MMI, MIR, *TM, MIRFunc);
217216
ASSERT_TRUE(M);
218217

218+
PM.add(new MachineModuleInfoWrapperPass(MMI));
219+
219220
PM.add(new TestPassT<AnalysisType>(T, ShouldPass));
220221

221222
PM.run(*M);

0 commit comments

Comments
 (0)