Merge System into Support.
[oota-llvm.git] / lib / ExecutionEngine / MCJIT / MCJIT.cpp
1 //===-- JIT.cpp - MC-based Just-in-Time Compiler --------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "MCJIT.h"
11 #include "llvm/ExecutionEngine/GenericValue.h"
12 #include "llvm/ExecutionEngine/MCJIT.h"
13 #include "llvm/Support/ErrorHandling.h"
14 #include "llvm/Support/DynamicLibrary.h"
15
16 using namespace llvm;
17
18 namespace {
19
20 static struct RegisterJIT {
21   RegisterJIT() { MCJIT::Register(); }
22 } JITRegistrator;
23
24 }
25
26 extern "C" void LLVMLinkInMCJIT() {
27 }
28
29 ExecutionEngine *MCJIT::createJIT(Module *M,
30                                   std::string *ErrorStr,
31                                   JITMemoryManager *JMM,
32                                   CodeGenOpt::Level OptLevel,
33                                   bool GVsWithCode,
34                                   CodeModel::Model CMM,
35                                   StringRef MArch,
36                                   StringRef MCPU,
37                                   const SmallVectorImpl<std::string>& MAttrs) {
38   // Try to register the program as a source of symbols to resolve against.
39   //
40   // FIXME: Don't do this here.
41   sys::DynamicLibrary::LoadLibraryPermanently(0, NULL);
42
43   // Pick a target either via -march or by guessing the native arch.
44   //
45   // FIXME: This should be lifted out of here, it isn't something which should
46   // be part of the JIT policy, rather the burden for this selection should be
47   // pushed to clients.
48   TargetMachine *TM = MCJIT::selectTarget(M, MArch, MCPU, MAttrs, ErrorStr);
49   if (!TM || (ErrorStr && ErrorStr->length() > 0)) return 0;
50   TM->setCodeModel(CMM);
51
52   // If the target supports JIT code generation, create the JIT.
53   if (TargetJITInfo *TJ = TM->getJITInfo())
54     return new MCJIT(M, *TM, *TJ, JMM, OptLevel, GVsWithCode);
55
56   if (ErrorStr)
57     *ErrorStr = "target does not support JIT code generation";
58   return 0;
59 }
60
61 MCJIT::MCJIT(Module *M, TargetMachine &tm, TargetJITInfo &tji,
62              JITMemoryManager *JMM, CodeGenOpt::Level OptLevel,
63              bool AllocateGVsWithCode)
64   : ExecutionEngine(M) {
65 }
66
67 MCJIT::~MCJIT() {
68 }
69
70 void *MCJIT::getPointerToBasicBlock(BasicBlock *BB) {
71   report_fatal_error("not yet implemented");
72   return 0;
73 }
74
75 void *MCJIT::getPointerToFunction(Function *F) {
76   report_fatal_error("not yet implemented");
77   return 0;
78 }
79
80 void *MCJIT::recompileAndRelinkFunction(Function *F) {
81   report_fatal_error("not yet implemented");
82 }
83
84 void MCJIT::freeMachineCodeForFunction(Function *F) {
85   report_fatal_error("not yet implemented");
86 }
87
88 GenericValue MCJIT::runFunction(Function *F,
89                                 const std::vector<GenericValue> &ArgValues) {
90   report_fatal_error("not yet implemented");
91   return GenericValue();
92 }