]> granicus.if.org Git - llvm/commitdiff
LLVMTargetMachine: Add functions to create MIModuleInfo/MIFunction; NFC
authorMatthias Braun <matze@braunis.de>
Tue, 10 May 2016 01:32:40 +0000 (01:32 +0000)
committerMatthias Braun <matze@braunis.de>
Tue, 10 May 2016 01:32:40 +0000 (01:32 +0000)
Add convenience function to create MachineModuleInfo and
MachineFunctionAnalysis passes and add them to a pass manager.

Despite factoring out some shared code in
LiveIntervalTest/LLVMTargetMachine this will be used by my upcoming llc
change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269002 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetMachine.h
lib/CodeGen/LLVMTargetMachine.cpp
unittests/MI/LiveIntervalTest.cpp

index c41ba0069fa8fc074be897bd84ab98d83f5ff851..fff905aedd5eee39d3cdb2014b9b97a5f5a9e192 100644 (file)
@@ -29,6 +29,7 @@ class InstrItineraryData;
 class GlobalValue;
 class Mangler;
 class MachineFunctionInitializer;
+class MachineModuleInfo;
 class MCAsmInfo;
 class MCCodeGenInfo;
 class MCContext;
@@ -303,6 +304,13 @@ public:
   bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
                          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;
 };
 
 } // End llvm namespace
index ea113c894cfb1c44e3d0cce71031ce40980132fe..46a0494ca0673cfa2bdb4d01ce753a4220d8e5c2 100644 (file)
@@ -91,6 +91,20 @@ 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));
+}
+
 /// addPassesToX helper drives creation and initialization of TargetPassConfig.
 static MCContext *
 addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
@@ -125,14 +139,8 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
 
   PassConfig->addISelPrepare();
 
-  // Install a MachineModuleInfo class, which is an immutable pass that holds
-  // all the per-module stuff we're generating, including MCContext.
-  MachineModuleInfo *MMI = new MachineModuleInfo(
-      *TM->getMCAsmInfo(), *TM->getMCRegisterInfo(), TM->getObjFileLowering());
-  PM.add(MMI);
-
-  // Set up a MachineFunction for the rest of CodeGen to work on.
-  PM.add(new MachineFunctionAnalysis(*TM, MFInitializer));
+  MachineModuleInfo &MMI = TM->addMachineModuleInfo(PM);
+  TM->addMachineFunctionAnalysis(PM, MFInitializer);
 
   // Enable FastISel with -fast, but allow that to be overridden.
   TM->setO0WantsFastISel(EnableFastISelOption != cl::BOU_FALSE);
@@ -160,7 +168,7 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
 
   PassConfig->setInitialized();
 
-  return &MMI->getContext();
+  return &MMI.getContext();
 }
 
 bool LLVMTargetMachine::addPassesToEmitFile(
index afd3b51793b2f807b1a5e02d63040d9112251c52..b74908411dafdada207cf0b944d0a6014f6f71e5 100644 (file)
@@ -3,8 +3,6 @@
 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
 #include "llvm/CodeGen/MIRParser/MIRParser.h"
 #include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/MachineFunctionAnalysis.h"
-#include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -69,12 +67,9 @@ std::unique_ptr<Module> parseMIR(LLVMContext &Context,
   if (!F)
     return nullptr;
 
-  MachineModuleInfo *MMI = new MachineModuleInfo(
-      *TM.getMCAsmInfo(), *TM.getMCRegisterInfo(), nullptr);
-  PM.add(MMI);
-
-  MachineFunctionAnalysis *MFA = new MachineFunctionAnalysis(TM, MIR.get());
-  PM.add(MFA);
+  const LLVMTargetMachine &LLVMTM = static_cast<const LLVMTargetMachine&>(TM);
+  LLVMTM.addMachineModuleInfo(PM);
+  LLVMTM.addMachineFunctionAnalysis(PM, MIR.get());
 
   return M;
 }