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/Target.h"
23#include "llvm-c/TargetMachine.h"
24#include "llvm-c/Types.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/**
31 * @defgroup LLVMCExecutionEngine Execution Engine
32 * @ingroup LLVMC
33 *
34 * @{
35 */
36
37void LLVMLinkInMCJIT(void);
38void LLVMLinkInInterpreter(void);
39
40typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
41typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
42typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
43
44struct LLVMMCJITCompilerOptions {
45 unsigned OptLevel;
46 LLVMCodeModel CodeModel;
47 LLVMBool NoFramePointerElim;
48 LLVMBool EnableFastISel;
49 LLVMMCJITMemoryManagerRef MCJMM;
50};
51
52/*===-- Operations on generic values --------------------------------------===*/
53
54LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
55 unsigned long long N,
56 LLVMBool IsSigned);
57
58LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
59
60LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
61
62unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
63
64unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
65 LLVMBool IsSigned);
66
67void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
68
69double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
70
71void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
72
73/*===-- Operations on execution engines -----------------------------------===*/
74
75LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
76 LLVMModuleRef M,
77 char **OutError);
78
79LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
80 LLVMModuleRef M,
81 char **OutError);
82
83LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
84 LLVMModuleRef M,
85 unsigned OptLevel,
86 char **OutError);
87
88void LLVMInitializeMCJITCompilerOptions(
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 */
108LLVMBool LLVMCreateMCJITCompilerForModule(
109 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
110 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
111 char **OutError);
112
113void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
114
115void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
116
117void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
118
119int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
120 unsigned ArgC, const char * const *ArgV,
121 const char * const *EnvP);
122
123LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
124 unsigned NumArgs,
125 LLVMGenericValueRef *Args);
126
127void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
128
129void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
130
131LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
132 LLVMModuleRef *OutMod, char **OutError);
133
134LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
135 LLVMValueRef *OutFn);
136
137void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
138 LLVMValueRef Fn);
139
140LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
141LLVMTargetMachineRef
142LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
143
144void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
145 void* Addr);
146
147void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
148
149uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
150
151uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
152
153/*===-- Operations on memory managers -------------------------------------===*/
154
155typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
156 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
157 const char *SectionName);
158typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
159 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
160 const char *SectionName, LLVMBool IsReadOnly);
161typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(
162 void *Opaque, char **ErrMsg);
163typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
164
165/**
166 * Create a simple custom MCJIT memory manager. This memory manager can
167 * intercept allocations in a module-oblivious way. This will return NULL
168 * if any of the passed functions are NULL.
169 *
170 * @param Opaque An opaque client object to pass back to the callbacks.
171 * @param AllocateCodeSection Allocate a block of memory for executable code.
172 * @param AllocateDataSection Allocate a block of memory for data.
173 * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
174 * success, 1 on error.
175 */
176LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
177 void *Opaque,
178 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
179 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
180 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
181 LLVMMemoryManagerDestroyCallback Destroy);
182
183void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
184
185/*===-- JIT Event Listener functions -------------------------------------===*/
186
187LLVMJITEventListenerRef LLVMCreateGDBRegistrationListener(void);
188LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void);
189LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void);
190LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void);
191
192/**
193 * @}
194 */
195
196#ifdef __cplusplus
197}
198#endif /* defined(__cplusplus) */
199
200#endif
201