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 LLVMLinkInJIT(void);
38 void LLVMLinkInMCJIT(void);
39 void LLVMLinkInInterpreter(void);
41 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
42 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
43 typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
45 struct LLVMMCJITCompilerOptions {
47 LLVMCodeModel CodeModel;
48 LLVMBool NoFramePointerElim;
49 LLVMBool EnableFastISel;
50 LLVMMCJITMemoryManagerRef MCJMM;
53 /*===-- Operations on generic values --------------------------------------===*/
55 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
59 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
61 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
63 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
65 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
68 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
70 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
72 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
74 /*===-- Operations on execution engines -----------------------------------===*/
76 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
80 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
84 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
89 void LLVMInitializeMCJITCompilerOptions(
90 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
93 * Create an MCJIT execution engine for a module, with the given options. It is
94 * the responsibility of the caller to ensure that all fields in Options up to
95 * the given SizeOfOptions are initialized. It is correct to pass a smaller
96 * value of SizeOfOptions that omits some fields. The canonical way of using
99 * LLVMMCJITCompilerOptions options;
100 * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
101 * ... fill in those options you care about
102 * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
105 * Note that this is also correct, though possibly suboptimal:
107 * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
109 LLVMBool LLVMCreateMCJITCompilerForModule(
110 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
111 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
114 /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
115 LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
116 LLVMModuleProviderRef MP,
119 /** Deprecated: Use LLVMCreateInterpreterForModule instead. */
120 LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
121 LLVMModuleProviderRef MP,
124 /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
125 LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
126 LLVMModuleProviderRef MP,
130 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
132 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
134 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
136 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
137 unsigned ArgC, const char * const *ArgV,
138 const char * const *EnvP);
140 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
142 LLVMGenericValueRef *Args);
144 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
146 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
148 /** Deprecated: Use LLVMAddModule instead. */
149 void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
151 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
152 LLVMModuleRef *OutMod, char **OutError);
154 /** Deprecated: Use LLVMRemoveModule instead. */
155 LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
156 LLVMModuleProviderRef MP,
157 LLVMModuleRef *OutMod, char **OutError);
159 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
160 LLVMValueRef *OutFn);
162 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
165 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
167 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
170 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
172 /*===-- Operations on memory managers -------------------------------------===*/
175 * Create a simple custom MCJIT memory manager. This memory manager can
176 * intercept allocations in a module-oblivious way. This will return NULL
177 * if any of the passed functions are NULL.
179 * @param Opaque An opaque client object to pass back to the callbacks.
180 * @param AllocateCodeSection Allocate a block of memory for executable code.
181 * @param AllocateDataSection Allocate a block of memory for data.
182 * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
183 * success, 1 on error.
185 LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
187 uint8_t *(*AllocateCodeSection)(void *Opaque,
188 uintptr_t Size, unsigned Alignment,
190 uint8_t *(*AllocateDataSection)(void *Opaque,
191 uintptr_t Size, unsigned Alignment,
192 unsigned SectionID, LLVMBool IsReadOnly),
193 LLVMBool (*FinalizeMemory)(void *Opaque, char **ErrMsg),
194 void (*Destroy)(void *Opaque));
196 void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
204 #endif /* defined(__cplusplus) */