LLVM  3.7.0
c/ExecutionEngine.h
Go to the documentation of this file.
1 /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
2 |* *|
3 |* The LLVM Compiler Infrastructure *|
4 |* *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
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/Core.h"
23 #include "llvm-c/Target.h"
24 #include "llvm-c/TargetMachine.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /**
31  * @defgroup LLVMCExecutionEngine Execution Engine
32  * @ingroup LLVMC
33  *
34  * @{
35  */
36 
37 void LLVMLinkInMCJIT(void);
38 void LLVMLinkInInterpreter(void);
39 
40 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
41 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
42 typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
43 
45  unsigned OptLevel;
49  LLVMMCJITMemoryManagerRef MCJMM;
50 };
51 
52 /*===-- Operations on generic values --------------------------------------===*/
53 
54 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
55  unsigned long long N,
56  LLVMBool IsSigned);
57 
58 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
59 
60 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
61 
62 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
63 
64 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
65  LLVMBool IsSigned);
66 
67 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
68 
69 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
70 
71 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
72 
73 /*===-- Operations on execution engines -----------------------------------===*/
74 
75 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
76  LLVMModuleRef M,
77  char **OutError);
78 
79 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
80  LLVMModuleRef M,
81  char **OutError);
82 
83 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
84  LLVMModuleRef M,
85  unsigned OptLevel,
86  char **OutError);
87 
89  struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
90 
91 /**
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
96  * this is:
97  *
98  * LLVMMCJITCompilerOptions options;
99  * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
100  * ... fill in those options you care about
101  * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
102  * &error);
103  *
104  * Note that this is also correct, though possibly suboptimal:
105  *
106  * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
107  */
109  LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
110  struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
111  char **OutError);
112 
113 /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
114 LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
116  char **OutError);
117 
118 /** Deprecated: Use LLVMCreateInterpreterForModule instead. */
119 LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
121  char **OutError);
122 
123 /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
124 LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
126  unsigned OptLevel,
127  char **OutError);
128 
129 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
130 
131 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
132 
133 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
134 
135 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
136  unsigned ArgC, const char * const *ArgV,
137  const char * const *EnvP);
138 
139 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
140  unsigned NumArgs,
141  LLVMGenericValueRef *Args);
142 
143 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
144 
145 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
146 
147 /** Deprecated: Use LLVMAddModule instead. */
148 void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
149 
150 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
151  LLVMModuleRef *OutMod, char **OutError);
152 
153 /** Deprecated: Use LLVMRemoveModule instead. */
154 LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
156  LLVMModuleRef *OutMod, char **OutError);
157 
158 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
159  LLVMValueRef *OutFn);
160 
161 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
162  LLVMValueRef Fn);
163 
164 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
166 LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
167 
168 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
169  void* Addr);
170 
171 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
172 
173 uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
174 
175 uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
176 
177 /*===-- Operations on memory managers -------------------------------------===*/
178 
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);
186  void *Opaque, char **ErrMsg);
187 typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
188 
189 /**
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.
193  *
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.
199  */
200 LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
201  void *Opaque,
206 
207 void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
208 
209 /**
210  * @}
211  */
212 
213 #ifdef __cplusplus
214 }
215 #endif /* defined(__cplusplus) */
216 
217 #endif
LLVMBool(* LLVMMemoryManagerFinalizeMemoryCallback)(void *Opaque, char **ErrMsg)
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: Core.h:85
LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N)
void LLVMInitializeMCJITCompilerOptions(struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions)
void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP)
Deprecated: Use LLVMAddModule instead.
LLVMMCJITMemoryManagerRef MCJMM
struct LLVMOpaqueExecutionEngine * LLVMExecutionEngineRef
void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE)
void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal)
void * LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, LLVMValueRef Fn)
F(f)
LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, unsigned OptLevel, char **OutError)
LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP, LLVMModuleRef *OutMod, char **OutError)
Deprecated: Use LLVMRemoveModule instead.
LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT, LLVMModuleProviderRef MP, unsigned OptLevel, char **OutError)
Deprecated: Use LLVMCreateJITCompilerForModule instead.
double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal)
void * LLVMGenericValueToPointer(LLVMGenericValueRef GenVal)
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P)
void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, void *Addr)
LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp, LLVMModuleProviderRef MP, char **OutError)
Deprecated: Use LLVMCreateInterpreterForModule instead.
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Interface used to provide a module to JIT or interpreter.
Definition: Core.h:113
void(* LLVMMemoryManagerDestroyCallback)(void *Opaque)
uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name)
LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(void *Opaque, LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection, LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection, LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory, LLVMMemoryManagerDestroyCallback Destroy)
Create a simple custom MCJIT memory manager.
int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned ArgC, const char *const *ArgV, const char *const *EnvP)
#define P(N)
LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, LLVMModuleRef M, char **OutError)
LLVMCodeModel
void LLVMLinkInMCJIT(void)
Definition: MCJIT.cpp:42
LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, unsigned long long N, LLVMBool IsSigned)
LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE)
void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM)
void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE)
int LLVMBool
Definition: Support.h:29
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Core.h:92
void * LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global)
uint8_t *(* LLVMMemoryManagerAllocateDataSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName, LLVMBool IsReadOnly)
LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, LLVMModuleRef M, char **OutError)
void LLVMLinkInInterpreter(void)
Definition: Interpreter.cpp:31
void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE)
void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M)
uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name)
unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal, LLVMBool IsSigned)
LLVMTargetMachineRef LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE)
#define N
LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE, LLVMModuleProviderRef MP, char **OutError)
Deprecated: Use LLVMCreateExecutionEngineForModule instead.
LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned NumArgs, LLVMGenericValueRef *Args)
uint8_t *(* LLVMMemoryManagerAllocateCodeSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName)
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Core.h:78
unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef)
LLVMBool LLVMCreateMCJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions, char **OutError)
Create an MCJIT execution engine for a module, with the given options.
void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F)
struct LLVMOpaqueGenericValue * LLVMGenericValueRef
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: DataLayout.h:32
LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, LLVMValueRef *OutFn)
LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, LLVMModuleRef *OutMod, char **OutError)