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