Add a TargetMachine local MCRegisterInfo and MCInstrInfo so that
authorEric Christopher <echristo@gmail.com>
Wed, 18 Mar 2015 20:37:36 +0000 (20:37 +0000)
committerEric Christopher <echristo@gmail.com>
Wed, 18 Mar 2015 20:37:36 +0000 (20:37 +0000)
they can be used without a subtarget in constructing subtarget
independent passes.

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

include/llvm/Target/TargetMachine.h
lib/CodeGen/LLVMTargetMachine.cpp
lib/Target/TargetMachine.cpp

index 7691b3fd505bac102b1b9339f0cf69c949efa8aa..460b758a1e3f6461c90a572a50cb9ba7be64fca2 100644 (file)
@@ -30,6 +30,8 @@ class Mangler;
 class MCAsmInfo;
 class MCCodeGenInfo;
 class MCContext;
+class MCInstrInfo;
+class MCRegisterInfo;
 class MCSymbol;
 class Target;
 class DataLayout;
@@ -86,6 +88,8 @@ protected: // Can only create subclasses.
   /// AsmInfo - Contains target specific asm information.
   ///
   const MCAsmInfo *AsmInfo;
+  const MCRegisterInfo *MRI;
+  const MCInstrInfo *MII;
 
   unsigned RequireStructuredCFG : 1;
 
@@ -134,6 +138,8 @@ public:
   /// getMCAsmInfo - Return target specific asm information.
   ///
   const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
+  const MCRegisterInfo *getMCRegisterInfo() const { return MRI; }
+  const MCInstrInfo *getMCInstrInfo() const { return MII; }
 
   /// getIntrinsicInfo - If intrinsic information is available, return it.  If
   /// not, return null.
index a1cdca43c8666ea6b528d342e6c4d3217125ec86..ac2618c7eb30f776f4b979fa02d1070eb3a81e06 100644 (file)
@@ -47,8 +47,10 @@ EnableFastISelOption("fast-isel", cl::Hidden,
   cl::desc("Enable the \"fast\" instruction selector"));
 
 void LLVMTargetMachine::initAsmInfo() {
-  MCAsmInfo *TmpAsmInfo = TheTarget.createMCAsmInfo(
-      *getSubtargetImpl()->getRegisterInfo(), getTargetTriple());
+  MRI = TheTarget.createMCRegInfo(getTargetTriple());
+  MII = TheTarget.createMCInstrInfo();
+
+  MCAsmInfo *TmpAsmInfo = TheTarget.createMCAsmInfo(*MRI, getTargetTriple());
   // TargetSelect.h moved to a different directory between LLVM 2.9 and 3.0,
   // and if the old one gets included then MCAsmInfo will be NULL and
   // we'll crash later.
@@ -164,15 +166,15 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
 
   const MCSubtargetInfo &STI = getSubtarget<MCSubtargetInfo>();
   const MCAsmInfo &MAI = *getMCAsmInfo();
-  const MCRegisterInfo &MRI = *getSubtargetImpl()->getRegisterInfo();
-  const MCInstrInfo &MII = *getSubtargetImpl()->getInstrInfo();
+  const MCRegisterInfo &MRI = *getMCRegisterInfo();
+  const MCInstrInfo &MII = *getMCInstrInfo();
+
   std::unique_ptr<MCStreamer> AsmStreamer;
 
   switch (FileType) {
   case CGFT_AssemblyFile: {
-    MCInstPrinter *InstPrinter =
-      getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI,
-                                      MII, MRI, STI);
+    MCInstPrinter *InstPrinter = getTarget().createMCInstPrinter(
+        MAI.getAssemblerDialect(), MAI, MII, MRI, STI);
 
     // Create a code emitter if asked to show the encoding.
     MCCodeEmitter *MCE = nullptr;
@@ -239,8 +241,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM,
 
   // Create the code emitter for the target if it exists.  If not, .o file
   // emission fails.
-  const MCRegisterInfo &MRI = *getSubtargetImpl()->getRegisterInfo();
-  const MCSubtargetInfo &STI = getSubtarget<MCSubtargetInfo>();
+  const MCRegisterInfo &MRI = *getMCRegisterInfo();
   MCCodeEmitter *MCE = getTarget().createMCCodeEmitter(
       *getSubtargetImpl()->getInstrInfo(), MRI, *Ctx);
   MCAsmBackend *MAB = getTarget().createMCAsmBackend(MRI, getTargetTriple(),
@@ -249,6 +250,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM,
     return true;
 
   Triple T(getTargetTriple());
+  const MCSubtargetInfo &STI = getSubtarget<MCSubtargetInfo>();
   std::unique_ptr<MCStreamer> AsmStreamer(getTarget().createMCObjectStreamer(
       T, *Ctx, *MAB, Out, MCE, STI, Options.MCOptions.MCRelaxAll));
 
index 56e7e8b24bdb5b5e33b7f656ebab7317afa393e9..0913af3d7d23e04a9e413598f0b14362728cba32 100644 (file)
@@ -40,12 +40,14 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString,
                              StringRef TT, StringRef CPU, StringRef FS,
                              const TargetOptions &Options)
     : TheTarget(T), DL(DataLayoutString), TargetTriple(TT), TargetCPU(CPU),
-      TargetFS(FS), CodeGenInfo(nullptr), AsmInfo(nullptr),
-      RequireStructuredCFG(false), Options(Options) {}
+      TargetFS(FS), CodeGenInfo(nullptr), AsmInfo(nullptr), MII(nullptr),
+      MRI(nullptr), RequireStructuredCFG(false), Options(Options) {}
 
 TargetMachine::~TargetMachine() {
   delete CodeGenInfo;
   delete AsmInfo;
+  delete MII;
+  delete MRI;
 }
 
 /// \brief Reset the target options based on the function's attributes.