1 /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header declares the C interface to libLLVMExecutionEngine.o, which *|
11 |* implements various analyses of the LLVM IR. *|
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. *|
17 \*===----------------------------------------------------------------------===*/
19 #ifndef LLVM_C_EXECUTIONENGINE_H
20 #define LLVM_C_EXECUTIONENGINE_H
22 #include "llvm-c/ExternC.h"
23 #include "llvm-c/Target.h"
24 #include "llvm-c/TargetMachine.h"
25 #include "llvm-c/Types.h"
30 * @defgroup LLVMCExecutionEngine Execution Engine
36 void LLVMLinkInMCJIT(void);
37 void LLVMLinkInInterpreter(void);
39 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
40 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
41 typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
43 struct LLVMMCJITCompilerOptions {
45 LLVMCodeModel CodeModel;
46 LLVMBool NoFramePointerElim;
47 LLVMBool EnableFastISel;
48 LLVMMCJITMemoryManagerRef MCJMM;
51 /*===-- Operations on generic values --------------------------------------===*/
53 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
57 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
59 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
61 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
63 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
66 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
68 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
70 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
72 /*===-- Operations on execution engines -----------------------------------===*/
74 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
78 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
82 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
87 void LLVMInitializeMCJITCompilerOptions(
88 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
91 * Create an MCJIT execution engine for a module, with the given options. It is
92 * the responsibility of the caller to ensure that all fields in Options up to
93 * the given SizeOfOptions are initialized. It is correct to pass a smaller
94 * value of SizeOfOptions that omits some fields. The canonical way of using
97 * LLVMMCJITCompilerOptions options;
98 * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
99 * ... fill in those options you care about
100 * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
103 * Note that this is also correct, though possibly suboptimal:
105 * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
107 LLVMBool LLVMCreateMCJITCompilerForModule(
108 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
109 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
112 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
114 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
116 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
118 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
119 unsigned ArgC, const char * const *ArgV,
120 const char * const *EnvP);
122 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
124 LLVMGenericValueRef *Args);
126 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
128 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
130 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
131 LLVMModuleRef *OutMod, char **OutError);
133 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
134 LLVMValueRef *OutFn);
136 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
139 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
141 LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
143 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
146 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
148 uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
150 uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
152 /*===-- Operations on memory managers -------------------------------------===*/
154 typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
155 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
156 const char *SectionName);
157 typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
158 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
159 const char *SectionName, LLVMBool IsReadOnly);
160 typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(
161 void *Opaque, char **ErrMsg);
162 typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
165 * Create a simple custom MCJIT memory manager. This memory manager can
166 * intercept allocations in a module-oblivious way. This will return NULL
167 * if any of the passed functions are NULL.
169 * @param Opaque An opaque client object to pass back to the callbacks.
170 * @param AllocateCodeSection Allocate a block of memory for executable code.
171 * @param AllocateDataSection Allocate a block of memory for data.
172 * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
173 * success, 1 on error.
175 LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
177 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
178 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
179 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
180 LLVMMemoryManagerDestroyCallback Destroy);
182 void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
184 /*===-- JIT Event Listener functions -------------------------------------===*/
186 LLVMJITEventListenerRef LLVMCreateGDBRegistrationListener(void);
187 LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void);
188 LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void);
189 LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void);