[llvm] r279598 - MachineModuleInfo: Avoid dummy constructor, use INITIALIZE_TM_PASS

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 23 17:42:05 PDT 2016


Author: matze
Date: Tue Aug 23 19:42:05 2016
New Revision: 279598

URL: http://llvm.org/viewvc/llvm-project?rev=279598&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
    llvm/trunk/include/llvm/Target/TargetMachine.h
    llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
    llvm/trunk/tools/llc/llc.cpp
    llvm/trunk/unittests/MI/LiveIntervalTest.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h?rev=279598&r1=279597&r2=279598&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h Tue Aug 23 19:42:05 2016
@@ -200,10 +200,8 @@ public:
   typedef SmallVector<VariableDbgInfo, 4> 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

Modified: llvm/trunk/include/llvm/Target/TargetMachine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetMachine.h?rev=279598&r1=279597&r2=279598&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetMachine.h (original)
+++ llvm/trunk/include/llvm/Target/TargetMachine.h Tue Aug 23 19:42:05 2016
@@ -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;

Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=279598&r1=279597&r2=279598&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Tue Aug 23 19:42:05 2016
@@ -102,15 +102,6 @@ TargetIRAnalysis LLVMTargetMachine::getT
   });
 }
 
-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(LLVMTargetMachin
 
   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(LLVMTargetMachin
 
   PassConfig->setInitialized();
 
-  return &MMI.getContext();
+  return &MMI->getContext();
 }
 
 bool LLVMTargetMachine::addPassesToEmitFile(

Modified: llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp?rev=279598&r1=279597&r2=279598&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp Tue Aug 23 19:42:05 2016
@@ -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::allUses
 
 //===----------------------------------------------------------------------===//
 
-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() {
 }
 

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=279598&r1=279597&r2=279598&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Tue Aug 23 19:42:05 2016
@@ -450,7 +450,7 @@ static int compileModule(char **argv, LL
       LLVMTargetMachine &LLVMTM = static_cast<LLVMTargetMachine&>(*Target);
       TargetPassConfig &TPC = *LLVMTM.createPassConfig(PM);
       PM.add(&TPC);
-      LLVMTM.addMachineModuleInfo(PM);
+      PM.add(new MachineModuleInfo(&LLVMTM));
       LLVMTM.addMachineFunctionAnalysis(PM, MIR.get());
       TPC.printAndVerify("");
 

Modified: llvm/trunk/unittests/MI/LiveIntervalTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/MI/LiveIntervalTest.cpp?rev=279598&r1=279597&r2=279598&view=diff
==============================================================================
--- llvm/trunk/unittests/MI/LiveIntervalTest.cpp (original)
+++ llvm/trunk/unittests/MI/LiveIntervalTest.cpp Tue Aug 23 19:42:05 2016
@@ -69,8 +69,8 @@ std::unique_ptr<Module> parseMIR(LLVMCon
   if (!F)
     return nullptr;
 
+  PM.add(new MachineModuleInfo(&TM));
   const LLVMTargetMachine &LLVMTM = static_cast<const LLVMTargetMachine&>(TM);
-  LLVMTM.addMachineModuleInfo(PM);
   LLVMTM.addMachineFunctionAnalysis(PM, MIR.get());
 
   return M;




More information about the llvm-commits mailing list