10b57cec5SDimitry Andric /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\ 20b57cec5SDimitry Andric |* *| 30b57cec5SDimitry Andric |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 40b57cec5SDimitry Andric |* Exceptions. *| 50b57cec5SDimitry Andric |* See https://llvm.org/LICENSE.txt for license information. *| 60b57cec5SDimitry Andric |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 70b57cec5SDimitry Andric |* *| 80b57cec5SDimitry Andric |*===----------------------------------------------------------------------===*| 90b57cec5SDimitry Andric |* *| 100b57cec5SDimitry Andric |* This header declares the C interface to libLLVMExecutionEngine.o, which *| 110b57cec5SDimitry Andric |* implements various analyses of the LLVM IR. *| 120b57cec5SDimitry Andric |* *| 130b57cec5SDimitry Andric |* Many exotic languages can interoperate with C code but have a harder time *| 140b57cec5SDimitry Andric |* with C++ due to name mangling. So in addition to C, this interface enables *| 150b57cec5SDimitry Andric |* tools written in such languages. *| 160b57cec5SDimitry Andric |* *| 170b57cec5SDimitry Andric \*===----------------------------------------------------------------------===*/ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric #ifndef LLVM_C_EXECUTIONENGINE_H 200b57cec5SDimitry Andric #define LLVM_C_EXECUTIONENGINE_H 210b57cec5SDimitry Andric 22480093f4SDimitry Andric #include "llvm-c/ExternC.h" 230b57cec5SDimitry Andric #include "llvm-c/Target.h" 240b57cec5SDimitry Andric #include "llvm-c/TargetMachine.h" 250b57cec5SDimitry Andric #include "llvm-c/Types.h" 260b57cec5SDimitry Andric 27480093f4SDimitry Andric LLVM_C_EXTERN_C_BEGIN 280b57cec5SDimitry Andric 290b57cec5SDimitry Andric /** 300b57cec5SDimitry Andric * @defgroup LLVMCExecutionEngine Execution Engine 310b57cec5SDimitry Andric * @ingroup LLVMC 320b57cec5SDimitry Andric * 330b57cec5SDimitry Andric * @{ 340b57cec5SDimitry Andric */ 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric void LLVMLinkInMCJIT(void); 370b57cec5SDimitry Andric void LLVMLinkInInterpreter(void); 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef; 400b57cec5SDimitry Andric typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef; 410b57cec5SDimitry Andric typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef; 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric struct LLVMMCJITCompilerOptions { 440b57cec5SDimitry Andric unsigned OptLevel; 450b57cec5SDimitry Andric LLVMCodeModel CodeModel; 460b57cec5SDimitry Andric LLVMBool NoFramePointerElim; 470b57cec5SDimitry Andric LLVMBool EnableFastISel; 480b57cec5SDimitry Andric LLVMMCJITMemoryManagerRef MCJMM; 490b57cec5SDimitry Andric }; 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric /*===-- Operations on generic values --------------------------------------===*/ 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, 540b57cec5SDimitry Andric unsigned long long N, 550b57cec5SDimitry Andric LLVMBool IsSigned); 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P); 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N); 600b57cec5SDimitry Andric 610b57cec5SDimitry Andric unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef); 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal, 640b57cec5SDimitry Andric LLVMBool IsSigned); 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal); 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal); 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal); 710b57cec5SDimitry Andric 720b57cec5SDimitry Andric /*===-- Operations on execution engines -----------------------------------===*/ 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, 750b57cec5SDimitry Andric LLVMModuleRef M, 760b57cec5SDimitry Andric char **OutError); 770b57cec5SDimitry Andric 780b57cec5SDimitry Andric LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, 790b57cec5SDimitry Andric LLVMModuleRef M, 800b57cec5SDimitry Andric char **OutError); 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, 830b57cec5SDimitry Andric LLVMModuleRef M, 840b57cec5SDimitry Andric unsigned OptLevel, 850b57cec5SDimitry Andric char **OutError); 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric void LLVMInitializeMCJITCompilerOptions( 880b57cec5SDimitry Andric struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions); 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric /** 910b57cec5SDimitry Andric * Create an MCJIT execution engine for a module, with the given options. It is 920b57cec5SDimitry Andric * the responsibility of the caller to ensure that all fields in Options up to 930b57cec5SDimitry Andric * the given SizeOfOptions are initialized. It is correct to pass a smaller 940b57cec5SDimitry Andric * value of SizeOfOptions that omits some fields. The canonical way of using 950b57cec5SDimitry Andric * this is: 960b57cec5SDimitry Andric * 970b57cec5SDimitry Andric * LLVMMCJITCompilerOptions options; 980b57cec5SDimitry Andric * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options)); 990b57cec5SDimitry Andric * ... fill in those options you care about 1000b57cec5SDimitry Andric * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options), 1010b57cec5SDimitry Andric * &error); 1020b57cec5SDimitry Andric * 1030b57cec5SDimitry Andric * Note that this is also correct, though possibly suboptimal: 1040b57cec5SDimitry Andric * 1050b57cec5SDimitry Andric * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error); 1060b57cec5SDimitry Andric */ 1070b57cec5SDimitry Andric LLVMBool LLVMCreateMCJITCompilerForModule( 1080b57cec5SDimitry Andric LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, 1090b57cec5SDimitry Andric struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions, 1100b57cec5SDimitry Andric char **OutError); 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE); 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE); 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE); 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, 1190b57cec5SDimitry Andric unsigned ArgC, const char * const *ArgV, 1200b57cec5SDimitry Andric const char * const *EnvP); 1210b57cec5SDimitry Andric 1220b57cec5SDimitry Andric LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, 1230b57cec5SDimitry Andric unsigned NumArgs, 1240b57cec5SDimitry Andric LLVMGenericValueRef *Args); 1250b57cec5SDimitry Andric 1260b57cec5SDimitry Andric void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F); 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andric void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M); 1290b57cec5SDimitry Andric 1300b57cec5SDimitry Andric LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, 1310b57cec5SDimitry Andric LLVMModuleRef *OutMod, char **OutError); 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andric LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, 1340b57cec5SDimitry Andric LLVMValueRef *OutFn); 1350b57cec5SDimitry Andric 1360b57cec5SDimitry Andric void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, 1370b57cec5SDimitry Andric LLVMValueRef Fn); 1380b57cec5SDimitry Andric 1390b57cec5SDimitry Andric LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE); 1400b57cec5SDimitry Andric LLVMTargetMachineRef 1410b57cec5SDimitry Andric LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE); 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andric void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, 1440b57cec5SDimitry Andric void* Addr); 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andric void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global); 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andric uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name); 1490b57cec5SDimitry Andric 1500b57cec5SDimitry Andric uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name); 1510b57cec5SDimitry Andric 152*5ffd83dbSDimitry Andric /// Returns true on error, false on success. If true is returned then the error 153*5ffd83dbSDimitry Andric /// message is copied to OutStr and cleared in the ExecutionEngine instance. 154*5ffd83dbSDimitry Andric LLVMBool LLVMExecutionEngineGetErrMsg(LLVMExecutionEngineRef EE, 155*5ffd83dbSDimitry Andric char **OutError); 156*5ffd83dbSDimitry Andric 1570b57cec5SDimitry Andric /*===-- Operations on memory managers -------------------------------------===*/ 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andric typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)( 1600b57cec5SDimitry Andric void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, 1610b57cec5SDimitry Andric const char *SectionName); 1620b57cec5SDimitry Andric typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)( 1630b57cec5SDimitry Andric void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, 1640b57cec5SDimitry Andric const char *SectionName, LLVMBool IsReadOnly); 1650b57cec5SDimitry Andric typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)( 1660b57cec5SDimitry Andric void *Opaque, char **ErrMsg); 1670b57cec5SDimitry Andric typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque); 1680b57cec5SDimitry Andric 1690b57cec5SDimitry Andric /** 1700b57cec5SDimitry Andric * Create a simple custom MCJIT memory manager. This memory manager can 1710b57cec5SDimitry Andric * intercept allocations in a module-oblivious way. This will return NULL 1720b57cec5SDimitry Andric * if any of the passed functions are NULL. 1730b57cec5SDimitry Andric * 1740b57cec5SDimitry Andric * @param Opaque An opaque client object to pass back to the callbacks. 1750b57cec5SDimitry Andric * @param AllocateCodeSection Allocate a block of memory for executable code. 1760b57cec5SDimitry Andric * @param AllocateDataSection Allocate a block of memory for data. 1770b57cec5SDimitry Andric * @param FinalizeMemory Set page permissions and flush cache. Return 0 on 1780b57cec5SDimitry Andric * success, 1 on error. 1790b57cec5SDimitry Andric */ 1800b57cec5SDimitry Andric LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager( 1810b57cec5SDimitry Andric void *Opaque, 1820b57cec5SDimitry Andric LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection, 1830b57cec5SDimitry Andric LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection, 1840b57cec5SDimitry Andric LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory, 1850b57cec5SDimitry Andric LLVMMemoryManagerDestroyCallback Destroy); 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM); 1880b57cec5SDimitry Andric 1890b57cec5SDimitry Andric /*===-- JIT Event Listener functions -------------------------------------===*/ 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andric LLVMJITEventListenerRef LLVMCreateGDBRegistrationListener(void); 1920b57cec5SDimitry Andric LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void); 1930b57cec5SDimitry Andric LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void); 1940b57cec5SDimitry Andric LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void); 1950b57cec5SDimitry Andric 1960b57cec5SDimitry Andric /** 1970b57cec5SDimitry Andric * @} 1980b57cec5SDimitry Andric */ 1990b57cec5SDimitry Andric 200480093f4SDimitry Andric LLVM_C_EXTERN_C_END 2010b57cec5SDimitry Andric 2020b57cec5SDimitry Andric #endif 203