From c3b2e80b9d7615190bb5d50f17d6524c2fd8d66d Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 24 Aug 2016 00:42:05 +0000 Subject: [PATCH] MachineModuleInfo: Avoid dummy constructor, use INITIALIZE_TM_PASS Change this pass constructor to just accept a const TargetMachine * and use INITIALIZE_TM_PASS, that way we can get rid of the dummy constructor. The pass will still fail when calling the default constructor leading to TM == nullptr, this is no different than before but is more in line what other codegen passes are doing and avoids the dummy constructor. llvm-svn: 279598 --- llvm/include/llvm/CodeGen/MachineModuleInfo.h | 4 +--- llvm/include/llvm/Target/TargetMachine.h | 3 --- llvm/lib/CodeGen/LLVMTargetMachine.cpp | 14 +++----------- llvm/lib/CodeGen/MachineModuleInfo.cpp | 20 +++++++------------- llvm/tools/llc/llc.cpp | 2 +- llvm/unittests/MI/LiveIntervalTest.cpp | 2 +- 6 files changed, 13 insertions(+), 32 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineModuleInfo.h b/llvm/include/llvm/CodeGen/MachineModuleInfo.h index f095876..74c1437 100644 --- a/llvm/include/llvm/CodeGen/MachineModuleInfo.h +++ b/llvm/include/llvm/CodeGen/MachineModuleInfo.h @@ -200,10 +200,8 @@ public: typedef SmallVector VariableDbgInfoMapTy; VariableDbgInfoMapTy VariableDbgInfos; - MachineModuleInfo(); // DUMMY CONSTRUCTOR, DO NOT CALL. // Real constructor. - MachineModuleInfo(const MCAsmInfo &MAI, const MCRegisterInfo &MRI, - const MCObjectFileInfo *MOFI); + explicit MachineModuleInfo(const TargetMachine *TM = nullptr); ~MachineModuleInfo() override; // Initialization and Finalization diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h index 563fef9..4772f1d 100644 --- a/llvm/include/llvm/Target/TargetMachine.h +++ b/llvm/include/llvm/Target/TargetMachine.h @@ -313,9 +313,6 @@ public: raw_pwrite_stream &OS, bool DisableVerify = true) override; - /// Add MachineModuleInfo pass to pass manager. - MachineModuleInfo &addMachineModuleInfo(PassManagerBase &PM) const; - /// Add MachineFunctionAnalysis pass to pass manager. void addMachineFunctionAnalysis(PassManagerBase &PM, MachineFunctionInitializer *MFInitializer) const; diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp index 9ed61c6..448bfaa 100644 --- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp +++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp @@ -102,15 +102,6 @@ TargetIRAnalysis LLVMTargetMachine::getTargetIRAnalysis() { }); } -MachineModuleInfo & -LLVMTargetMachine::addMachineModuleInfo(PassManagerBase &PM) const { - MachineModuleInfo *MMI = new MachineModuleInfo(*getMCAsmInfo(), - *getMCRegisterInfo(), - getObjFileLowering()); - PM.add(MMI); - return *MMI; -} - void LLVMTargetMachine::addMachineFunctionAnalysis(PassManagerBase &PM, MachineFunctionInitializer *MFInitializer) const { PM.add(new MachineFunctionAnalysis(*this, MFInitializer)); @@ -150,7 +141,8 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM, PassConfig->addISelPrepare(); - MachineModuleInfo &MMI = TM->addMachineModuleInfo(PM); + MachineModuleInfo *MMI = new MachineModuleInfo(TM); + PM.add(MMI); TM->addMachineFunctionAnalysis(PM, MFInitializer); // Enable FastISel with -fast, but allow that to be overridden. @@ -189,7 +181,7 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM, PassConfig->setInitialized(); - return &MMI.getContext(); + return &MMI->getContext(); } bool LLVMTargetMachine::addPassesToEmitFile( diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp index 244e3fb..c2721e1 100644 --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -23,12 +23,14 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/Target/TargetMachine.h" using namespace llvm; using namespace llvm::dwarf; // Handle the Pass registration stuff necessary to use DataLayout's. -INITIALIZE_PASS(MachineModuleInfo, "machinemoduleinfo", - "Machine Module Information", false, false) +INITIALIZE_TM_PASS(MachineModuleInfo, "machinemoduleinfo", + "Machine Module Information", false, false) char MachineModuleInfo::ID = 0; // Out of line virtual method. @@ -186,20 +188,12 @@ void MMIAddrLabelMapCallbackPtr::allUsesReplacedWith(Value *V2) { //===----------------------------------------------------------------------===// -MachineModuleInfo::MachineModuleInfo(const MCAsmInfo &MAI, - const MCRegisterInfo &MRI, - const MCObjectFileInfo *MOFI) - : ImmutablePass(ID), Context(&MAI, &MRI, MOFI, nullptr, false) { +MachineModuleInfo::MachineModuleInfo(const TargetMachine *TM) + : ImmutablePass(ID), Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(), + TM->getObjFileLowering(), nullptr, false) { initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry()); } -MachineModuleInfo::MachineModuleInfo() - : ImmutablePass(ID), Context(nullptr, nullptr, nullptr) { - llvm_unreachable("This MachineModuleInfo constructor should never be called, " - "MMI should always be explicitly constructed by " - "LLVMTargetMachine"); -} - MachineModuleInfo::~MachineModuleInfo() { } diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 250d276..4c65457 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -450,7 +450,7 @@ static int compileModule(char **argv, LLVMContext &Context) { LLVMTargetMachine &LLVMTM = static_cast(*Target); TargetPassConfig &TPC = *LLVMTM.createPassConfig(PM); PM.add(&TPC); - LLVMTM.addMachineModuleInfo(PM); + PM.add(new MachineModuleInfo(&LLVMTM)); LLVMTM.addMachineFunctionAnalysis(PM, MIR.get()); TPC.printAndVerify(""); diff --git a/llvm/unittests/MI/LiveIntervalTest.cpp b/llvm/unittests/MI/LiveIntervalTest.cpp index 12c3ad6..9f594e5 100644 --- a/llvm/unittests/MI/LiveIntervalTest.cpp +++ b/llvm/unittests/MI/LiveIntervalTest.cpp @@ -69,8 +69,8 @@ std::unique_ptr parseMIR(LLVMContext &Context, if (!F) return nullptr; + PM.add(new MachineModuleInfo(&TM)); const LLVMTargetMachine &LLVMTM = static_cast(TM); - LLVMTM.addMachineModuleInfo(PM); LLVMTM.addMachineFunctionAnalysis(PM, MIR.get()); return M; -- 2.7.4