Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 1 | /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\ |
| 2 | |* *| |
| 3 | |* The LLVM Compiler Infrastructure *| |
| 4 | |* *| |
Chris Lattner | e9cc742 | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | |* This file is distributed under the University of Illinois Open Source *| |
| 6 | |* License. See LICENSE.TXT for details. *| |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 7 | |* *| |
| 8 | |*===----------------------------------------------------------------------===*| |
| 9 | |* *| |
| 10 | |* This header declares the C interface to libLLVMExecutionEngine.o, which *| |
| 11 | |* implements various analyses of the LLVM IR. *| |
| 12 | |* *| |
| 13 | |* Many exotic languages can interoperate with C code but have a harder time *| |
| 14 | |* with C++ due to name mangling. So in addition to C, this interface enables *| |
| 15 | |* tools written in such languages. *| |
| 16 | |* *| |
| 17 | \*===----------------------------------------------------------------------===*/ |
| 18 | |
| 19 | #ifndef LLVM_C_EXECUTIONENGINE_H |
| 20 | #define LLVM_C_EXECUTIONENGINE_H |
| 21 | |
| 22 | #include "llvm-c/Core.h" |
Erick Tryzelaar | 8ac07c2 | 2008-03-27 00:27:14 +0000 | [diff] [blame] | 23 | #include "llvm-c/Target.h" |
Filip Pizlo | 85e0d27 | 2013-05-01 22:58:00 +0000 | [diff] [blame] | 24 | #include "llvm-c/TargetMachine.h" |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 25 | |
| 26 | #ifdef __cplusplus |
| 27 | extern "C" { |
| 28 | #endif |
| 29 | |
Gregory Szorc | 34c863a | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 30 | /** |
| 31 | * @defgroup LLVMCExecutionEngine Execution Engine |
| 32 | * @ingroup LLVMC |
| 33 | * |
| 34 | * @{ |
| 35 | */ |
| 36 | |
Andrew Kaylor | 31be5ef | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 37 | void LLVMLinkInMCJIT(void); |
Bob Wilson | a1d3e66 | 2009-06-24 21:09:18 +0000 | [diff] [blame] | 38 | void LLVMLinkInInterpreter(void); |
| 39 | |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 40 | typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef; |
| 41 | typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef; |
Filip Pizlo | 3fdbaff | 2013-05-22 02:46:43 +0000 | [diff] [blame] | 42 | typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef; |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 43 | |
Andrew Kaylor | 31be5ef | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 44 | struct LLVMMCJITCompilerOptions { |
| 45 | unsigned OptLevel; |
Filip Pizlo | 85e0d27 | 2013-05-01 22:58:00 +0000 | [diff] [blame] | 46 | LLVMCodeModel CodeModel; |
Andrew Kaylor | 31be5ef | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 47 | LLVMBool NoFramePointerElim; |
Filip Pizlo | 85e0d27 | 2013-05-01 22:58:00 +0000 | [diff] [blame] | 48 | LLVMBool EnableFastISel; |
Filip Pizlo | 3fdbaff | 2013-05-22 02:46:43 +0000 | [diff] [blame] | 49 | LLVMMCJITMemoryManagerRef MCJMM; |
Andrew Kaylor | 31be5ef | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 52 | /*===-- Operations on generic values --------------------------------------===*/ |
| 53 | |
| 54 | LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, |
| 55 | unsigned long long N, |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 56 | LLVMBool IsSigned); |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 57 | |
| 58 | LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P); |
| 59 | |
| 60 | LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N); |
| 61 | |
| 62 | unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef); |
| 63 | |
| 64 | unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal, |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 65 | LLVMBool IsSigned); |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 66 | |
| 67 | void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal); |
| 68 | |
| 69 | double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal); |
| 70 | |
| 71 | void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal); |
| 72 | |
| 73 | /*===-- Operations on execution engines -----------------------------------===*/ |
| 74 | |
Erick Tryzelaar | ad0e0cb | 2010-03-02 23:58:54 +0000 | [diff] [blame] | 75 | LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, |
| 76 | LLVMModuleRef M, |
| 77 | char **OutError); |
| 78 | |
| 79 | LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, |
| 80 | LLVMModuleRef M, |
| 81 | char **OutError); |
| 82 | |
| 83 | LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, |
| 84 | LLVMModuleRef M, |
| 85 | unsigned OptLevel, |
| 86 | char **OutError); |
| 87 | |
Filip Pizlo | 85e0d27 | 2013-05-01 22:58:00 +0000 | [diff] [blame] | 88 | void LLVMInitializeMCJITCompilerOptions( |
| 89 | struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions); |
| 90 | |
Andrew Kaylor | 31be5ef | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 91 | /** |
| 92 | * Create an MCJIT execution engine for a module, with the given options. It is |
| 93 | * the responsibility of the caller to ensure that all fields in Options up to |
Filip Pizlo | 85e0d27 | 2013-05-01 22:58:00 +0000 | [diff] [blame] | 94 | * the given SizeOfOptions are initialized. It is correct to pass a smaller |
| 95 | * value of SizeOfOptions that omits some fields. The canonical way of using |
| 96 | * this is: |
Andrew Kaylor | 31be5ef | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 97 | * |
| 98 | * LLVMMCJITCompilerOptions options; |
Filip Pizlo | 85e0d27 | 2013-05-01 22:58:00 +0000 | [diff] [blame] | 99 | * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options)); |
Andrew Kaylor | 31be5ef | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 100 | * ... fill in those options you care about |
Filip Pizlo | 85e0d27 | 2013-05-01 22:58:00 +0000 | [diff] [blame] | 101 | * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options), |
| 102 | * &error); |
Andrew Kaylor | 31be5ef | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 103 | * |
| 104 | * Note that this is also correct, though possibly suboptimal: |
| 105 | * |
| 106 | * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error); |
| 107 | */ |
Filip Pizlo | 85e0d27 | 2013-05-01 22:58:00 +0000 | [diff] [blame] | 108 | LLVMBool LLVMCreateMCJITCompilerForModule( |
| 109 | LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, |
| 110 | struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions, |
| 111 | char **OutError); |
Andrew Kaylor | 31be5ef | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 112 | |
Erick Tryzelaar | ad0e0cb | 2010-03-02 23:58:54 +0000 | [diff] [blame] | 113 | /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */ |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 114 | LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE, |
| 115 | LLVMModuleProviderRef MP, |
| 116 | char **OutError); |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 117 | |
Erick Tryzelaar | ad0e0cb | 2010-03-02 23:58:54 +0000 | [diff] [blame] | 118 | /** Deprecated: Use LLVMCreateInterpreterForModule instead. */ |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 119 | LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp, |
| 120 | LLVMModuleProviderRef MP, |
| 121 | char **OutError); |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 122 | |
Erick Tryzelaar | ad0e0cb | 2010-03-02 23:58:54 +0000 | [diff] [blame] | 123 | /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */ |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 124 | LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT, |
| 125 | LLVMModuleProviderRef MP, |
| 126 | unsigned OptLevel, |
| 127 | char **OutError); |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 128 | |
| 129 | void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE); |
| 130 | |
| 131 | void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE); |
| 132 | |
| 133 | void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE); |
| 134 | |
| 135 | int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, |
| 136 | unsigned ArgC, const char * const *ArgV, |
| 137 | const char * const *EnvP); |
| 138 | |
| 139 | LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, |
| 140 | unsigned NumArgs, |
| 141 | LLVMGenericValueRef *Args); |
| 142 | |
| 143 | void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F); |
| 144 | |
Erick Tryzelaar | ad0e0cb | 2010-03-02 23:58:54 +0000 | [diff] [blame] | 145 | void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M); |
| 146 | |
| 147 | /** Deprecated: Use LLVMAddModule instead. */ |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 148 | void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP); |
| 149 | |
Erick Tryzelaar | ad0e0cb | 2010-03-02 23:58:54 +0000 | [diff] [blame] | 150 | LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, |
| 151 | LLVMModuleRef *OutMod, char **OutError); |
| 152 | |
| 153 | /** Deprecated: Use LLVMRemoveModule instead. */ |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 154 | LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE, |
| 155 | LLVMModuleProviderRef MP, |
| 156 | LLVMModuleRef *OutMod, char **OutError); |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 157 | |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 158 | LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, |
| 159 | LLVMValueRef *OutFn); |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 160 | |
Filip Pizlo | 85e0d27 | 2013-05-01 22:58:00 +0000 | [diff] [blame] | 161 | void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, |
| 162 | LLVMValueRef Fn); |
Duncan Sands | 330134b | 2010-07-19 09:33:13 +0000 | [diff] [blame] | 163 | |
Erick Tryzelaar | 8ac07c2 | 2008-03-27 00:27:14 +0000 | [diff] [blame] | 164 | LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE); |
Juergen Ributzka | 5fe955c | 2014-01-23 19:23:28 +0000 | [diff] [blame] | 165 | LLVMTargetMachineRef |
| 166 | LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE); |
Erick Tryzelaar | 8ac07c2 | 2008-03-27 00:27:14 +0000 | [diff] [blame] | 167 | |
Gordon Henriksen | 9f33754 | 2008-06-20 02:16:11 +0000 | [diff] [blame] | 168 | void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, |
| 169 | void* Addr); |
| 170 | |
Chris Lattner | 41b43da | 2009-01-21 18:11:10 +0000 | [diff] [blame] | 171 | void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global); |
| 172 | |
Peter Zotov | c433cd7 | 2014-12-22 18:53:11 +0000 | [diff] [blame^] | 173 | uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name); |
| 174 | |
| 175 | uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name); |
| 176 | |
Filip Pizlo | 3fdbaff | 2013-05-22 02:46:43 +0000 | [diff] [blame] | 177 | /*===-- Operations on memory managers -------------------------------------===*/ |
| 178 | |
Filip Pizlo | 7aa695e0 | 2013-10-02 00:59:25 +0000 | [diff] [blame] | 179 | typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)( |
| 180 | void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, |
| 181 | const char *SectionName); |
| 182 | typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)( |
| 183 | void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, |
| 184 | const char *SectionName, LLVMBool IsReadOnly); |
| 185 | typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)( |
| 186 | void *Opaque, char **ErrMsg); |
Anders Waldenborg | 9515b31 | 2013-09-30 19:11:32 +0000 | [diff] [blame] | 187 | typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque); |
| 188 | |
Filip Pizlo | 3fdbaff | 2013-05-22 02:46:43 +0000 | [diff] [blame] | 189 | /** |
| 190 | * Create a simple custom MCJIT memory manager. This memory manager can |
| 191 | * intercept allocations in a module-oblivious way. This will return NULL |
| 192 | * if any of the passed functions are NULL. |
| 193 | * |
| 194 | * @param Opaque An opaque client object to pass back to the callbacks. |
| 195 | * @param AllocateCodeSection Allocate a block of memory for executable code. |
| 196 | * @param AllocateDataSection Allocate a block of memory for data. |
| 197 | * @param FinalizeMemory Set page permissions and flush cache. Return 0 on |
| 198 | * success, 1 on error. |
| 199 | */ |
| 200 | LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager( |
| 201 | void *Opaque, |
Anders Waldenborg | 9515b31 | 2013-09-30 19:11:32 +0000 | [diff] [blame] | 202 | LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection, |
| 203 | LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection, |
| 204 | LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory, |
Benjamin Kramer | 57f30bc | 2013-10-22 15:18:03 +0000 | [diff] [blame] | 205 | LLVMMemoryManagerDestroyCallback Destroy); |
Filip Pizlo | 3fdbaff | 2013-05-22 02:46:43 +0000 | [diff] [blame] | 206 | |
| 207 | void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM); |
| 208 | |
Gregory Szorc | 34c863a | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 209 | /** |
| 210 | * @} |
| 211 | */ |
| 212 | |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 213 | #ifdef __cplusplus |
NAKAMURA Takumi | a3a8135 | 2013-10-23 17:56:29 +0000 | [diff] [blame] | 214 | } |
Evan Cheng | 2e254d0 | 2013-04-04 17:40:53 +0000 | [diff] [blame] | 215 | #endif /* defined(__cplusplus) */ |
Gordon Henriksen | 2a8cd89 | 2007-12-23 16:59:28 +0000 | [diff] [blame] | 216 | |
| 217 | #endif |