1 /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- 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 |* 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" 23 #include "llvm-c/Target.h" 24 #include "llvm-c/TargetMachine.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /** 31 * @defgroup LLVMCExecutionEngine Execution Engine 32 * @ingroup LLVMC 33 * 34 * @{ 35 */ 36 37 void LLVMLinkInJIT(void); 38 void LLVMLinkInMCJIT(void); 39 void LLVMLinkInInterpreter(void); 40 41 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef; 42 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef; 43 typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef; 44 45 struct LLVMMCJITCompilerOptions { 46 unsigned OptLevel; 47 LLVMCodeModel CodeModel; 48 LLVMBool NoFramePointerElim; 49 LLVMBool EnableFastISel; 50 LLVMMCJITMemoryManagerRef MCJMM; 51 }; 52 53 /*===-- Operations on generic values --------------------------------------===*/ 54 55 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, 56 unsigned long long N, 57 LLVMBool IsSigned); 58 59 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P); 60 61 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N); 62 63 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef); 64 65 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal, 66 LLVMBool IsSigned); 67 68 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal); 69 70 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal); 71 72 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal); 73 74 /*===-- Operations on execution engines -----------------------------------===*/ 75 76 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, 77 LLVMModuleRef M, 78 char **OutError); 79 80 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, 81 LLVMModuleRef M, 82 char **OutError); 83 84 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, 85 LLVMModuleRef M, 86 unsigned OptLevel, 87 char **OutError); 88 89 void LLVMInitializeMCJITCompilerOptions( 90 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions); 91 92 /** 93 * Create an MCJIT execution engine for a module, with the given options. It is 94 * the responsibility of the caller to ensure that all fields in Options up to 95 * the given SizeOfOptions are initialized. It is correct to pass a smaller 96 * value of SizeOfOptions that omits some fields. The canonical way of using 97 * this is: 98 * 99 * LLVMMCJITCompilerOptions options; 100 * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options)); 101 * ... fill in those options you care about 102 * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options), 103 * &error); 104 * 105 * Note that this is also correct, though possibly suboptimal: 106 * 107 * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error); 108 */ 109 LLVMBool LLVMCreateMCJITCompilerForModule( 110 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, 111 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions, 112 char **OutError); 113 114 /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */ 115 LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE, 116 LLVMModuleProviderRef MP, 117 char **OutError); 118 119 /** Deprecated: Use LLVMCreateInterpreterForModule instead. */ 120 LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp, 121 LLVMModuleProviderRef MP, 122 char **OutError); 123 124 /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */ 125 LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT, 126 LLVMModuleProviderRef MP, 127 unsigned OptLevel, 128 char **OutError); 129 130 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE); 131 132 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE); 133 134 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE); 135 136 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, 137 unsigned ArgC, const char * const *ArgV, 138 const char * const *EnvP); 139 140 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, 141 unsigned NumArgs, 142 LLVMGenericValueRef *Args); 143 144 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F); 145 146 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M); 147 148 /** Deprecated: Use LLVMAddModule instead. */ 149 void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP); 150 151 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, 152 LLVMModuleRef *OutMod, char **OutError); 153 154 /** Deprecated: Use LLVMRemoveModule instead. */ 155 LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE, 156 LLVMModuleProviderRef MP, 157 LLVMModuleRef *OutMod, char **OutError); 158 159 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, 160 LLVMValueRef *OutFn); 161 162 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, 163 LLVMValueRef Fn); 164 165 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE); 166 167 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, 168 void* Addr); 169 170 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global); 171 172 /*===-- Operations on memory managers -------------------------------------===*/ 173 174 /** 175 * Create a simple custom MCJIT memory manager. This memory manager can 176 * intercept allocations in a module-oblivious way. This will return NULL 177 * if any of the passed functions are NULL. 178 * 179 * @param Opaque An opaque client object to pass back to the callbacks. 180 * @param AllocateCodeSection Allocate a block of memory for executable code. 181 * @param AllocateDataSection Allocate a block of memory for data. 182 * @param FinalizeMemory Set page permissions and flush cache. Return 0 on 183 * success, 1 on error. 184 */ 185 LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager( 186 void *Opaque, 187 uint8_t *(*AllocateCodeSection)(void *Opaque, 188 uintptr_t Size, unsigned Alignment, 189 unsigned SectionID), 190 uint8_t *(*AllocateDataSection)(void *Opaque, 191 uintptr_t Size, unsigned Alignment, 192 unsigned SectionID, LLVMBool IsReadOnly), 193 LLVMBool (*FinalizeMemory)(void *Opaque, char **ErrMsg), 194 void (*Destroy)(void *Opaque)); 195 196 void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM); 197 198 /** 199 * @} 200 */ 201 202 #ifdef __cplusplus 203 } 204 #endif /* defined(__cplusplus) */ 205 206 #endif 207