Jim Grosbach | b572830 | 2011-04-04 23:20:40 +0000 | [diff] [blame] | 1 | //===-- MCJITMemoryManager.h - Definition for the Memory Manager ---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_MCJITMEMORYMANAGER_H |
| 11 | #define LLVM_LIB_EXECUTIONENGINE_MCJITMEMORYMANAGER_H |
| 12 | |
| 13 | #include "llvm/Module.h" |
| 14 | #include "llvm/ExecutionEngine/JITMemoryManager.h" |
| 15 | #include "llvm/ExecutionEngine/RuntimeDyld.h" |
| 16 | #include <assert.h> |
| 17 | |
| 18 | namespace llvm { |
| 19 | |
| 20 | // The MCJIT memory manager is a layer between the standard JITMemoryManager |
| 21 | // and the RuntimeDyld interface that maps objects, by name, onto their |
| 22 | // matching LLVM IR counterparts in the module(s) being compiled. |
| 23 | class MCJITMemoryManager : public RTDyldMemoryManager { |
| 24 | JITMemoryManager *JMM; |
| 25 | |
| 26 | // FIXME: Multiple modules. |
| 27 | Module *M; |
| 28 | public: |
| 29 | MCJITMemoryManager(JITMemoryManager *jmm) : JMM(jmm) {} |
| 30 | |
| 31 | // Allocate ActualSize bytes, or more, for the named function. Return |
| 32 | // a pointer to the allocated memory and update Size to reflect how much |
| 33 | // memory was acutally allocated. |
Jim Grosbach | c41ab78 | 2011-04-06 01:11:05 +0000 | [diff] [blame] | 34 | uint8_t *startFunctionBody(const char *Name, uintptr_t &Size) { |
Jim Grosbach | b572830 | 2011-04-04 23:20:40 +0000 | [diff] [blame] | 35 | Function *F = M->getFunction(Name); |
| 36 | assert(F && "No matching function in JIT IR Module!"); |
Jim Grosbach | c41ab78 | 2011-04-06 01:11:05 +0000 | [diff] [blame] | 37 | return JMM->startFunctionBody(F, Size); |
Jim Grosbach | b572830 | 2011-04-04 23:20:40 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // Mark the end of the function, including how much of the allocated |
| 41 | // memory was actually used. |
Jim Grosbach | c41ab78 | 2011-04-06 01:11:05 +0000 | [diff] [blame] | 42 | void endFunctionBody(const char *Name, uint8_t *FunctionStart, |
| 43 | uint8_t *FunctionEnd) { |
Jim Grosbach | b572830 | 2011-04-04 23:20:40 +0000 | [diff] [blame] | 44 | Function *F = M->getFunction(Name); |
| 45 | assert(F && "No matching function in JIT IR Module!"); |
Jim Grosbach | c41ab78 | 2011-04-06 01:11:05 +0000 | [diff] [blame] | 46 | JMM->endFunctionBody(F, FunctionStart, FunctionEnd); |
Jim Grosbach | b572830 | 2011-04-04 23:20:40 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | }; |
| 50 | |
| 51 | } // End llvm namespace |
| 52 | |
| 53 | #endif |