Path: blob/main/contrib/llvm-project/llvm/include/llvm-c/ExecutionEngine.h
35233 views
/*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\1|* *|2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|3|* Exceptions. *|4|* See https://llvm.org/LICENSE.txt for license information. *|5|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|6|* *|7|*===----------------------------------------------------------------------===*|8|* *|9|* This header declares the C interface to libLLVMExecutionEngine.o, which *|10|* implements various analyses of the LLVM IR. *|11|* *|12|* Many exotic languages can interoperate with C code but have a harder time *|13|* with C++ due to name mangling. So in addition to C, this interface enables *|14|* tools written in such languages. *|15|* *|16\*===----------------------------------------------------------------------===*/1718#ifndef LLVM_C_EXECUTIONENGINE_H19#define LLVM_C_EXECUTIONENGINE_H2021#include "llvm-c/ExternC.h"22#include "llvm-c/Target.h"23#include "llvm-c/TargetMachine.h"24#include "llvm-c/Types.h"2526LLVM_C_EXTERN_C_BEGIN2728/**29* @defgroup LLVMCExecutionEngine Execution Engine30* @ingroup LLVMC31*32* @{33*/3435void LLVMLinkInMCJIT(void);36void LLVMLinkInInterpreter(void);3738typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;39typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;40typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;4142struct LLVMMCJITCompilerOptions {43unsigned OptLevel;44LLVMCodeModel CodeModel;45LLVMBool NoFramePointerElim;46LLVMBool EnableFastISel;47LLVMMCJITMemoryManagerRef MCJMM;48};4950/*===-- Operations on generic values --------------------------------------===*/5152LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,53unsigned long long N,54LLVMBool IsSigned);5556LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);5758LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);5960unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);6162unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,63LLVMBool IsSigned);6465void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);6667double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);6869void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);7071/*===-- Operations on execution engines -----------------------------------===*/7273LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,74LLVMModuleRef M,75char **OutError);7677LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,78LLVMModuleRef M,79char **OutError);8081LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,82LLVMModuleRef M,83unsigned OptLevel,84char **OutError);8586void LLVMInitializeMCJITCompilerOptions(87struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);8889/**90* Create an MCJIT execution engine for a module, with the given options. It is91* the responsibility of the caller to ensure that all fields in Options up to92* the given SizeOfOptions are initialized. It is correct to pass a smaller93* value of SizeOfOptions that omits some fields. The canonical way of using94* this is:95*96* LLVMMCJITCompilerOptions options;97* LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));98* ... fill in those options you care about99* LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),100* &error);101*102* Note that this is also correct, though possibly suboptimal:103*104* LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);105*/106LLVMBool LLVMCreateMCJITCompilerForModule(107LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,108struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,109char **OutError);110111void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);112113void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);114115void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);116117int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,118unsigned ArgC, const char * const *ArgV,119const char * const *EnvP);120121LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,122unsigned NumArgs,123LLVMGenericValueRef *Args);124125void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);126127void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);128129LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,130LLVMModuleRef *OutMod, char **OutError);131132LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,133LLVMValueRef *OutFn);134135void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,136LLVMValueRef Fn);137138LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);139LLVMTargetMachineRef140LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);141142void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,143void* Addr);144145void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);146147uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);148149uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);150151/// Returns true on error, false on success. If true is returned then the error152/// message is copied to OutStr and cleared in the ExecutionEngine instance.153LLVMBool LLVMExecutionEngineGetErrMsg(LLVMExecutionEngineRef EE,154char **OutError);155156/*===-- Operations on memory managers -------------------------------------===*/157158typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(159void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,160const char *SectionName);161typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(162void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,163const char *SectionName, LLVMBool IsReadOnly);164typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(165void *Opaque, char **ErrMsg);166typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);167168/**169* Create a simple custom MCJIT memory manager. This memory manager can170* intercept allocations in a module-oblivious way. This will return NULL171* if any of the passed functions are NULL.172*173* @param Opaque An opaque client object to pass back to the callbacks.174* @param AllocateCodeSection Allocate a block of memory for executable code.175* @param AllocateDataSection Allocate a block of memory for data.176* @param FinalizeMemory Set page permissions and flush cache. Return 0 on177* success, 1 on error.178*/179LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(180void *Opaque,181LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,182LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,183LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,184LLVMMemoryManagerDestroyCallback Destroy);185186void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);187188/*===-- JIT Event Listener functions -------------------------------------===*/189190LLVMJITEventListenerRef LLVMCreateGDBRegistrationListener(void);191LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void);192LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void);193LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void);194195/**196* @}197*/198199LLVM_C_EXTERN_C_END200201#endif202203204