blob: 947f7c78e38d1b8aa52b4b564492a8806e151bbd [file] [log] [blame]
Daniel Dunbar6aec2982010-11-17 16:06:43 +00001//===-- MCJIT.h - Class definition for the MCJIT ----------------*- C++ -*-===//
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#ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_H
11#define LLVM_LIB_EXECUTIONENGINE_MCJIT_H
12
Jim Grosbach31649e62011-03-18 22:48:41 +000013#include "llvm/PassManager.h"
Daniel Dunbar6aec2982010-11-17 16:06:43 +000014#include "llvm/ExecutionEngine/ExecutionEngine.h"
Jim Grosbachf9229102011-03-22 01:06:42 +000015#include "llvm/ExecutionEngine/RuntimeDyld.h"
Jim Grosbach31649e62011-03-18 22:48:41 +000016#include "llvm/ADT/SmallVector.h"
17#include "llvm/Support/raw_ostream.h"
Daniel Dunbar6aec2982010-11-17 16:06:43 +000018
19namespace llvm {
20
Jim Grosbach31649e62011-03-18 22:48:41 +000021// FIXME: This makes all kinds of horrible assumptions for the time being,
22// like only having one module, not needing to worry about multi-threading,
23// blah blah. Purely in get-it-up-and-limping mode for now.
24
Daniel Dunbar6aec2982010-11-17 16:06:43 +000025class MCJIT : public ExecutionEngine {
Jim Grosbach31649e62011-03-18 22:48:41 +000026 MCJIT(Module *M, TargetMachine *tm, TargetJITInfo &tji,
Daniel Dunbar6aec2982010-11-17 16:06:43 +000027 JITMemoryManager *JMM, CodeGenOpt::Level OptLevel,
28 bool AllocateGVsWithCode);
Jim Grosbach31649e62011-03-18 22:48:41 +000029
30 TargetMachine *TM;
31 MCContext *Ctx;
32
33 // FIXME: These may need moved to a separate 'jitstate' member like the
34 // non-MC JIT does for multithreading and such. Just keep them here for now.
35 PassManager PM;
36 Module *M;
37 // FIXME: This really doesn't belong here.
38 SmallVector<char, 4096> Buffer; // Working buffer into which we JIT.
39 raw_svector_ostream OS;
40
Jim Grosbachf9229102011-03-22 01:06:42 +000041 RuntimeDyld Dyld;
42
Daniel Dunbar6aec2982010-11-17 16:06:43 +000043public:
44 ~MCJIT();
45
46 /// @name ExecutionEngine interface implementation
47 /// @{
48
49 virtual void *getPointerToBasicBlock(BasicBlock *BB);
50
51 virtual void *getPointerToFunction(Function *F);
52
53 virtual void *recompileAndRelinkFunction(Function *F);
54
55 virtual void freeMachineCodeForFunction(Function *F);
56
57 virtual GenericValue runFunction(Function *F,
58 const std::vector<GenericValue> &ArgValues);
59
60 /// @}
61 /// @name (Private) Registration Interfaces
62 /// @{
63
64 static void Register() {
65 MCJITCtor = createJIT;
66 }
67
68 // FIXME: This routine is scheduled for termination. Do not use it.
69 static TargetMachine *selectTarget(Module *M,
70 StringRef MArch,
71 StringRef MCPU,
72 const SmallVectorImpl<std::string>& MAttrs,
73 std::string *Err);
74
75 static ExecutionEngine *createJIT(Module *M,
76 std::string *ErrorStr,
77 JITMemoryManager *JMM,
78 CodeGenOpt::Level OptLevel,
79 bool GVsWithCode,
80 CodeModel::Model CMM,
81 StringRef MArch,
82 StringRef MCPU,
83 const SmallVectorImpl<std::string>& MAttrs);
84
85 // @}
86};
87
88} // End llvm namespace
89
90#endif