LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 LLVMLinkInJIT(void);
38 void LLVMLinkInMCJIT(void);
39 void LLVMLinkInInterpreter(void);
40 
41 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
42 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
43 typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
44 
46  unsigned OptLevel;
50  LLVMMCJITMemoryManagerRef MCJMM;
51 };
52 
53 /*===-- Operations on generic values --------------------------------------===*/
54 
55 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
56  unsigned long long N,
57  LLVMBool IsSigned);
58 
59 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
60 
61 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
62 
63 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
64 
65 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
66  LLVMBool IsSigned);
67 
68 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
69 
70 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
71 
72 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
73 
74 /*===-- Operations on execution engines -----------------------------------===*/
75 
76 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
77  LLVMModuleRef M,
78  char **OutError);
79 
80 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
81  LLVMModuleRef M,
82  char **OutError);
83 
84 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
85  LLVMModuleRef M,
86  unsigned OptLevel,
87  char **OutError);
88 
90  struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
91 
92 /**
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
97  * this is:
98  *
99  * LLVMMCJITCompilerOptions options;
100  * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
101  * ... fill in those options you care about
102  * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
103  * &error);
104  *
105  * Note that this is also correct, though possibly suboptimal:
106  *
107  * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
108  */
110  LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
111  struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
112  char **OutError);
113 
114 /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
115 LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
117  char **OutError);
118 
119 /** Deprecated: Use LLVMCreateInterpreterForModule instead. */
120 LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
122  char **OutError);
123 
124 /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
125 LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
127  unsigned OptLevel,
128  char **OutError);
129 
130 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
131 
132 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
133 
134 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
135 
136 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
137  unsigned ArgC, const char * const *ArgV,
138  const char * const *EnvP);
139 
140 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
141  unsigned NumArgs,
142  LLVMGenericValueRef *Args);
143 
144 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
145 
146 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
147 
148 /** Deprecated: Use LLVMAddModule instead. */
149 void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
150 
151 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
152  LLVMModuleRef *OutMod, char **OutError);
153 
154 /** Deprecated: Use LLVMRemoveModule instead. */
155 LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
157  LLVMModuleRef *OutMod, char **OutError);
158 
159 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
160  LLVMValueRef *OutFn);
161 
162 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
163  LLVMValueRef Fn);
164 
165 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
166 
167 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
168  void* Addr);
169 
170 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
171 
172 /*===-- Operations on memory managers -------------------------------------===*/
173 
174 typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
175  void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
176  const char *SectionName);
177 typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
178  void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
179  const char *SectionName, LLVMBool IsReadOnly);
181  void *Opaque, char **ErrMsg);
182 typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
183 
184 /**
185  * Create a simple custom MCJIT memory manager. This memory manager can
186  * intercept allocations in a module-oblivious way. This will return NULL
187  * if any of the passed functions are NULL.
188  *
189  * @param Opaque An opaque client object to pass back to the callbacks.
190  * @param AllocateCodeSection Allocate a block of memory for executable code.
191  * @param AllocateDataSection Allocate a block of memory for data.
192  * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
193  * success, 1 on error.
194  */
195 LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
196  void *Opaque,
201 
202 void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
203 
204 /**
205  * @}
206  */
207 
208 #ifdef __cplusplus
209 }
210 #endif /* defined(__cplusplus) */
211 
212 #endif
LLVMBool(* LLVMMemoryManagerFinalizeMemoryCallback)(void *Opaque, char **ErrMsg)
struct LLVMOpaqueType * LLVMTypeRef
Definition: Core.h:87
LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N)
void LLVMInitializeMCJITCompilerOptions(struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions)
void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP)
LLVMMCJITMemoryManagerRef MCJMM
struct LLVMOpaqueExecutionEngine * LLVMExecutionEngineRef
int LLVMBool
Definition: Core.h:65
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)
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: Target.h:42
LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP, LLVMModuleRef *OutMod, char **OutError)
LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT, LLVMModuleProviderRef MP, unsigned OptLevel, char **OutError)
double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal)
void LLVMLinkInJIT(void)
Definition: JIT.cpp:67
void * LLVMGenericValueToPointer(LLVMGenericValueRef GenVal)
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P)
void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, void *Addr)
LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp, LLVMModuleProviderRef MP, char **OutError)
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Definition: Core.h:115
void(* LLVMMemoryManagerDestroyCallback)(void *Opaque)
LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(void *Opaque, LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection, LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection, LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory, LLVMMemoryManagerDestroyCallback Destroy)
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:39
LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, unsigned long long N, LLVMBool IsSigned)
LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE)
void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM)
void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE)
struct LLVMOpaqueValue * LLVMValueRef
Definition: Core.h:94
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)
unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal, LLVMBool IsSigned)
#define N
LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE, LLVMModuleProviderRef MP, char **OutError)
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
Definition: Core.h:80
unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef)
LLVMBool LLVMCreateMCJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions, char **OutError)
void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F)
struct LLVMOpaqueGenericValue * LLVMGenericValueRef
LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, LLVMValueRef *OutFn)
LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, LLVMModuleRef *OutMod, char **OutError)