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