Rip JIT specific stuff out of TargetMachine, as per PR176


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10542 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index c5a70ea..dc9f7a1 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -80,19 +80,20 @@
   // Allocate a target...
   TargetMachine *Target = TargetMachineAllocator(*MP->getModule());
   assert(Target && "Could not allocate target machine!");
-  
-  // Create the virtual machine object...
-  return new VM(MP, Target);
+
+  // If the target supports JIT code generation, return a new JIT now.
+  if (TargetJITInfo *TJ = Target->getJITInfo())
+    return new VM(MP, *Target, *TJ);
+  return 0;
 }
 
-VM::VM(ModuleProvider *MP, TargetMachine *tm) : ExecutionEngine(MP), TM(*tm),
-  PM(MP)
-{
+VM::VM(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji)
+  : ExecutionEngine(MP), TM(tm), TJI(tji), PM(MP) {
   setTargetData(TM.getTargetData());
 
   // Initialize MCE
   MCE = createEmitter(*this);
-
+  
   setupPassManager();
 
   emitGlobals();
diff --git a/lib/ExecutionEngine/JIT/JIT.h b/lib/ExecutionEngine/JIT/JIT.h
index dc82067..35f7223 100644
--- a/lib/ExecutionEngine/JIT/JIT.h
+++ b/lib/ExecutionEngine/JIT/JIT.h
@@ -24,15 +24,18 @@
 class GlobalValue;
 class Constant;
 class TargetMachine;
+class TargetJITInfo;
 class MachineCodeEmitter;
 
 class VM : public ExecutionEngine {
   TargetMachine &TM;       // The current target we are compiling to
+  TargetJITInfo &TJI;      // The JITInfo for the target we are compiling to
+  
   FunctionPassManager PM;  // Passes to compile a function
   MachineCodeEmitter *MCE; // MCE object
 
+  VM(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji);
 public:
-  VM(ModuleProvider *MP, TargetMachine *tm);
   ~VM();
 
   /// create - Create an return a new JIT compiler if there is one available
diff --git a/lib/ExecutionEngine/JIT/VM.cpp b/lib/ExecutionEngine/JIT/VM.cpp
index 29ffa30..5dffa5c 100644
--- a/lib/ExecutionEngine/JIT/VM.cpp
+++ b/lib/ExecutionEngine/JIT/VM.cpp
@@ -18,6 +18,7 @@
 #include "llvm/CodeGen/MachineCodeEmitter.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetJITInfo.h"
 using namespace llvm;
 
 VM::~VM() {
@@ -30,11 +31,7 @@
 ///
 void VM::setupPassManager() {
   // Compile LLVM Code down to machine code in the intermediate representation
-  if (TM.addPassesToJITCompile(PM)) {
-    std::cerr << "lli: target '" << TM.getName()
-              << "' doesn't support JIT compilation!\n";
-    abort();
-  }
+  TJI.addPassesToJITCompile(PM);
 
   // Turn the machine code intermediate representation into bytes in memory that
   // may be executed.
@@ -87,7 +84,7 @@
   if (I != GlobalAddress.end()) return I->second;
 
   // If the target supports "stubs" for functions, get a stub now.
-  if (void *Ptr = TM.getJITStubForFunction(F, *MCE))
+  if (void *Ptr = TJI.getJITStubForFunction(F, *MCE))
     return Ptr;
 
   // Otherwise, if the target doesn't support it, just codegen the function.
@@ -112,6 +109,6 @@
   MachineFunction::destruct(F);
   runJITOnFunction(F);
   assert(Addr && "Code generation didn't add function to GlobalAddress table!");
-  TM.replaceMachineCodeForFunction(OldAddr, Addr);
+  TJI.replaceMachineCodeForFunction(OldAddr, Addr);
   return Addr;
 }
diff --git a/lib/ExecutionEngine/JIT/VM.h b/lib/ExecutionEngine/JIT/VM.h
index dc82067..35f7223 100644
--- a/lib/ExecutionEngine/JIT/VM.h
+++ b/lib/ExecutionEngine/JIT/VM.h
@@ -24,15 +24,18 @@
 class GlobalValue;
 class Constant;
 class TargetMachine;
+class TargetJITInfo;
 class MachineCodeEmitter;
 
 class VM : public ExecutionEngine {
   TargetMachine &TM;       // The current target we are compiling to
+  TargetJITInfo &TJI;      // The JITInfo for the target we are compiling to
+  
   FunctionPassManager PM;  // Passes to compile a function
   MachineCodeEmitter *MCE; // MCE object
 
+  VM(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji);
 public:
-  VM(ModuleProvider *MP, TargetMachine *tm);
   ~VM();
 
   /// create - Create an return a new JIT compiler if there is one available