Daniel Dunbar | 6aec298 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 1 | //===-- 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 Grosbach | 31649e6 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 13 | #include "llvm/PassManager.h" |
Daniel Dunbar | 6aec298 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 14 | #include "llvm/ExecutionEngine/ExecutionEngine.h" |
Jim Grosbach | f922910 | 2011-03-22 01:06:42 +0000 | [diff] [blame] | 15 | #include "llvm/ExecutionEngine/RuntimeDyld.h" |
Jim Grosbach | 31649e6 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/SmallVector.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 6aec298 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
| 20 | |
Jim Grosbach | 31649e6 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 21 | // 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 Dunbar | 6aec298 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 25 | class MCJIT : public ExecutionEngine { |
Jim Grosbach | 31649e6 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 26 | MCJIT(Module *M, TargetMachine *tm, TargetJITInfo &tji, |
Dylan Noblesmith | 9ea4717 | 2011-12-12 04:20:36 +0000 | [diff] [blame] | 27 | RTDyldMemoryManager *MemMgr, bool AllocateGVsWithCode); |
Jim Grosbach | 31649e6 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 28 | |
| 29 | TargetMachine *TM; |
| 30 | MCContext *Ctx; |
Jim Grosbach | fcbe5b7 | 2011-04-04 23:04:39 +0000 | [diff] [blame] | 31 | RTDyldMemoryManager *MemMgr; |
Jim Grosbach | 31649e6 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 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 Grosbach | f922910 | 2011-03-22 01:06:42 +0000 | [diff] [blame] | 41 | RuntimeDyld Dyld; |
| 42 | |
Daniel Dunbar | 6aec298 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 43 | public: |
| 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 | |
Jim Grosbach | 34714a0 | 2011-03-22 18:05:27 +0000 | [diff] [blame] | 60 | /// getPointerToNamedFunction - This method returns the address of the |
| 61 | /// specified function by using the dlsym function call. As such it is only |
| 62 | /// useful for resolving library symbols, not code generated symbols. |
| 63 | /// |
| 64 | /// If AbortOnFailure is false and no function with the given name is |
| 65 | /// found, this function silently returns a null pointer. Otherwise, |
| 66 | /// it prints a message to stderr and aborts. |
| 67 | /// |
Danil Malyshev | 45a93d6 | 2012-01-05 21:16:14 +0000 | [diff] [blame^] | 68 | virtual void *getPointerToNamedFunction(const std::string &Name, |
| 69 | bool AbortOnFailure = true); |
Daniel Dunbar | 6aec298 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 70 | /// @} |
| 71 | /// @name (Private) Registration Interfaces |
| 72 | /// @{ |
| 73 | |
| 74 | static void Register() { |
| 75 | MCJITCtor = createJIT; |
| 76 | } |
| 77 | |
Daniel Dunbar | 6aec298 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 78 | static ExecutionEngine *createJIT(Module *M, |
| 79 | std::string *ErrorStr, |
| 80 | JITMemoryManager *JMM, |
Daniel Dunbar | 6aec298 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 81 | bool GVsWithCode, |
Dylan Noblesmith | c5b2858 | 2011-05-13 21:51:29 +0000 | [diff] [blame] | 82 | TargetMachine *TM); |
Daniel Dunbar | 6aec298 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 83 | |
| 84 | // @} |
| 85 | }; |
| 86 | |
| 87 | } // End llvm namespace |
| 88 | |
| 89 | #endif |