blob: f1e9dab250bf720578bd650ec89c871876bd9423 [file] [log] [blame]
Daniel Dunbar6aec2982010-11-17 16:06:43 +00001//===-- 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"
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000014#include "llvm/Support/DynamicLibrary.h"
Daniel Dunbar6aec2982010-11-17 16:06:43 +000015
16using namespace llvm;
17
18namespace {
19
20static struct RegisterJIT {
21 RegisterJIT() { MCJIT::Register(); }
22} JITRegistrator;
23
24}
25
26extern "C" void LLVMLinkInMCJIT() {
27}
28
29ExecutionEngine *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
61MCJIT::MCJIT(Module *M, TargetMachine &tm, TargetJITInfo &tji,
62 JITMemoryManager *JMM, CodeGenOpt::Level OptLevel,
63 bool AllocateGVsWithCode)
64 : ExecutionEngine(M) {
65}
66
67MCJIT::~MCJIT() {
68}
69
70void *MCJIT::getPointerToBasicBlock(BasicBlock *BB) {
71 report_fatal_error("not yet implemented");
72 return 0;
73}
74
75void *MCJIT::getPointerToFunction(Function *F) {
76 report_fatal_error("not yet implemented");
77 return 0;
78}
79
80void *MCJIT::recompileAndRelinkFunction(Function *F) {
81 report_fatal_error("not yet implemented");
82}
83
84void MCJIT::freeMachineCodeForFunction(Function *F) {
85 report_fatal_error("not yet implemented");
86}
87
88GenericValue MCJIT::runFunction(Function *F,
89 const std::vector<GenericValue> &ArgValues) {
90 report_fatal_error("not yet implemented");
91 return GenericValue();
92}