LLVM 22.0.0git
ExecutionEngine.h
Go to the documentation of this file.
1/*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
2|* *|
3|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4|* Exceptions. *|
5|* See https://llvm.org/LICENSE.txt for license information. *|
6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
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/ExternC.h"
23#include "llvm-c/Target.h"
25#include "llvm-c/Types.h"
26#include "llvm-c/Visibility.h"
27
29
30/**
31 * @defgroup LLVMCExecutionEngine Execution Engine
32 * @ingroup LLVMC
33 *
34 * @{
35 */
36
37/**
38 * Empty function used to force the linker to link MCJIT.
39 * Has no effect when called on a pre-built library (dylib interface).
40 */
42/**
43 * Empty function used to force the linker to link the LLVM interpreter.
44 * Has no effect when called on a pre-built library (dylib interface).
45 */
47
48typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
49typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
50typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
51
53 unsigned OptLevel;
58};
59
60/*===-- Operations on generic values --------------------------------------===*/
61
63 unsigned long long N,
64 LLVMBool IsSigned);
65
67
69 double N);
70
72
74 LLVMBool IsSigned);
75
77
79 LLVMGenericValueRef GenVal);
80
82
83/*===-- Operations on execution engines -----------------------------------===*/
84
86 LLVMExecutionEngineRef *OutEE, LLVMModuleRef M, char **OutError);
87
89 LLVMExecutionEngineRef *OutInterp, LLVMModuleRef M, char **OutError);
90
93 unsigned OptLevel, char **OutError);
94
95LLVM_C_ABI void
97 size_t SizeOfOptions);
98
99/**
100 * Create an MCJIT execution engine for a module, with the given options. It is
101 * the responsibility of the caller to ensure that all fields in Options up to
102 * the given SizeOfOptions are initialized. It is correct to pass a smaller
103 * value of SizeOfOptions that omits some fields. The canonical way of using
104 * this is:
105 *
106 * LLVMMCJITCompilerOptions options;
107 * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
108 * ... fill in those options you care about
109 * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
110 * &error);
111 *
112 * Note that this is also correct, though possibly suboptimal:
113 *
114 * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
115 */
118 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
119 char **OutError);
120
122
124
126
128 unsigned ArgC, const char *const *ArgV,
129 const char *const *EnvP);
130
132 LLVMValueRef F, unsigned NumArgs,
133 LLVMGenericValueRef *Args);
134
137
139
141 LLVMModuleRef *OutMod, char **OutError);
142
144 const char *Name, LLVMValueRef *OutFn);
145
147 LLVMValueRef Fn);
148
153
155 LLVMValueRef Global, void *Addr);
156
158 LLVMValueRef Global);
159
161 const char *Name);
162
164 const char *Name);
165
166/// Returns true on error, false on success. If true is returned then the error
167/// message is copied to OutStr and cleared in the ExecutionEngine instance.
169 char **OutError);
170
171/*===-- Operations on memory managers -------------------------------------===*/
172
173typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
174 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
175 const char *SectionName);
176typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
177 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
178 const char *SectionName, LLVMBool IsReadOnly);
180 void *Opaque, char **ErrMsg);
181typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
182
183/**
184 * Create a simple custom MCJIT memory manager. This memory manager can
185 * intercept allocations in a module-oblivious way. This will return NULL
186 * if any of the passed functions are NULL.
187 *
188 * @param Opaque An opaque client object to pass back to the callbacks.
189 * @param AllocateCodeSection Allocate a block of memory for executable code.
190 * @param AllocateDataSection Allocate a block of memory for data.
191 * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
192 * success, 1 on error.
193 */
195 void *Opaque,
200
202
203/*===-- JIT Event Listener functions -------------------------------------===*/
204
209
210/**
211 * @}
212 */
213
215
216#endif
uint64_t Addr
std::string Name
uint64_t Size
#define LLVM_C_EXTERN_C_BEGIN
Definition: ExternC.h:35
#define LLVM_C_EXTERN_C_END
Definition: ExternC.h:36
static LVOptions Options
Definition: LVOptions.cpp:25
#define F(x, y, z)
Definition: MD5.cpp:55
#define P(N)
#define LLVM_C_ABI
LLVM_C_ABI is the export/visibility macro used to mark symbols declared in llvm-c as exported when bu...
Definition: Visibility.h:40
LLVM_C_ABI uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name)
LLVM_C_ABI void * LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, LLVMValueRef Fn)
LLVM_C_ABI void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, void *Addr)
LLVM_C_ABI 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.
LLVM_C_ABI LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void)
LLVM_C_ABI LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned NumArgs, LLVMGenericValueRef *Args)
LLVM_C_ABI LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void)
LLVM_C_ABI LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void)
LLVM_C_ABI unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal, LLVMBool IsSigned)
LLVM_C_ABI void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F)
LLVM_C_ABI void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM)
LLVM_C_ABI void LLVMLinkInInterpreter(void)
Empty function used to force the linker to link the LLVM interpreter.
Definition: Interpreter.cpp:30
LLVM_C_ABI LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, LLVMModuleRef M, char **OutError)
struct LLVMOpaqueMCJITMemoryManager * LLVMMCJITMemoryManagerRef
LLVM_C_ABI void * LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global)
void(* LLVMMemoryManagerDestroyCallback)(void *Opaque)
LLVM_C_ABI uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name)
struct LLVMOpaqueExecutionEngine * LLVMExecutionEngineRef
LLVM_C_ABI LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, unsigned long long N, LLVMBool IsSigned)
LLVM_C_ABI int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, unsigned ArgC, const char *const *ArgV, const char *const *EnvP)
LLVM_C_ABI LLVMTargetMachineRef LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE)
LLVM_C_ABI void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE)
LLVM_C_ABI double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal)
LLVM_C_ABI LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, LLVMModuleRef *OutMod, char **OutError)
LLVM_C_ABI void LLVMLinkInMCJIT(void)
Empty function used to force the linker to link MCJIT.
Definition: MCJIT.cpp:40
LLVM_C_ABI LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE)
LLVM_C_ABI void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal)
LLVM_C_ABI LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, LLVMModuleRef M, char **OutError)
struct LLVMOpaqueGenericValue * LLVMGenericValueRef
LLVMBool(* LLVMMemoryManagerFinalizeMemoryCallback)(void *Opaque, char **ErrMsg)
LLVM_C_ABI LLVMBool LLVMExecutionEngineGetErrMsg(LLVMExecutionEngineRef EE, char **OutError)
Returns true on error, false on success.
LLVM_C_ABI void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE)
LLVM_C_ABI void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M)
LLVM_C_ABI void LLVMInitializeMCJITCompilerOptions(struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions)
LLVM_C_ABI LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, LLVMValueRef *OutFn)
uint8_t *(* LLVMMemoryManagerAllocateDataSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName, LLVMBool IsReadOnly)
LLVM_C_ABI LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P)
LLVM_C_ABI unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef)
LLVM_C_ABI void * LLVMGenericValueToPointer(LLVMGenericValueRef GenVal)
LLVM_C_ABI LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(void *Opaque, LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection, LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection, LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory, LLVMMemoryManagerDestroyCallback Destroy)
Create a simple custom MCJIT memory manager.
uint8_t *(* LLVMMemoryManagerAllocateCodeSectionCallback)(void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID, const char *SectionName)
LLVM_C_ABI LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M, unsigned OptLevel, char **OutError)
LLVM_C_ABI LLVMJITEventListenerRef LLVMCreateGDBRegistrationListener(void)
LLVM_C_ABI void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE)
LLVM_C_ABI LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N)
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
int LLVMBool
Definition: Types.h:28
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: Types.h:68
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
struct LLVMOpaqueJITEventListener * LLVMJITEventListenerRef
Definition: Types.h:165
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
Definition: TargetMachine.h:36
LLVMCodeModel
Definition: TargetMachine.h:56
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: Target.h:38
#define N
LLVMMCJITMemoryManagerRef MCJMM