1 /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
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/Core.h"
23 #include "llvm-c/Target.h"
24 #include "llvm-c/TargetMachine.h"
31 * @defgroup LLVMCExecutionEngine Execution Engine
37 void LLVMLinkInMCJIT(void);
38 void LLVMLinkInInterpreter(void);
40 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
41 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
42 typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
44 struct LLVMMCJITCompilerOptions {
46 LLVMCodeModel CodeModel;
47 LLVMBool NoFramePointerElim;
48 LLVMBool EnableFastISel;
49 LLVMMCJITMemoryManagerRef MCJMM;
52 /*===-- Operations on generic values --------------------------------------===*/
54 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
58 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
60 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
62 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
64 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
67 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
69 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
71 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
73 /*===-- Operations on execution engines -----------------------------------===*/
75 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
79 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
83 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
88 void LLVMInitializeMCJITCompilerOptions(
89 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
92 * Create an MCJIT execution engine for a module, with the given options. It is
93 * the responsibility of the caller to ensure that all fields in Options up to
94 * the given SizeOfOptions are initialized. It is correct to pass a smaller
95 * value of SizeOfOptions that omits some fields. The canonical way of using
98 * LLVMMCJITCompilerOptions options;
99 * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
100 * ... fill in those options you care about
101 * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
104 * Note that this is also correct, though possibly suboptimal:
106 * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
108 LLVMBool LLVMCreateMCJITCompilerForModule(
109 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
110 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
113 /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
114 LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
115 LLVMModuleProviderRef MP,
118 /** Deprecated: Use LLVMCreateInterpreterForModule instead. */
119 LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
120 LLVMModuleProviderRef MP,
123 /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
124 LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
125 LLVMModuleProviderRef MP,
129 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
131 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
133 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
135 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
136 unsigned ArgC, const char * const *ArgV,
137 const char * const *EnvP);
139 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
141 LLVMGenericValueRef *Args);
143 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
145 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
147 /** Deprecated: Use LLVMAddModule instead. */
148 void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
150 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
151 LLVMModuleRef *OutMod, char **OutError);
153 /** Deprecated: Use LLVMRemoveModule instead. */
154 LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
155 LLVMModuleProviderRef MP,
156 LLVMModuleRef *OutMod, char **OutError);
158 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
159 LLVMValueRef *OutFn);
161 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
164 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
166 LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
168 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
171 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
173 uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
175 uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
177 /*===-- Operations on memory managers -------------------------------------===*/
179 typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
180 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
181 const char *SectionName);
182 typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
183 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
184 const char *SectionName, LLVMBool IsReadOnly);
185 typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(
186 void *Opaque, char **ErrMsg);
187 typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
190 * Create a simple custom MCJIT memory manager. This memory manager can
191 * intercept allocations in a module-oblivious way. This will return NULL
192 * if any of the passed functions are NULL.
194 * @param Opaque An opaque client object to pass back to the callbacks.
195 * @param AllocateCodeSection Allocate a block of memory for executable code.
196 * @param AllocateDataSection Allocate a block of memory for data.
197 * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
198 * success, 1 on error.
200 LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
202 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
203 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
204 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
205 LLVMMemoryManagerDestroyCallback Destroy);
207 void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
215 #endif /* defined(__cplusplus) */