blob: eb3ecabfa8a8c1ffda2e5f1064806263450e1a00 [file] [log] [blame]
Gordon Henriksen2a8cd892007-12-23 16:59:28 +00001/*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen2a8cd892007-12-23 16:59:28 +00007|* *|
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"
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +000023#include "llvm-c/Target.h"
Filip Pizlo85e0d272013-05-01 22:58:00 +000024#include "llvm-c/TargetMachine.h"
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000025
26#ifdef __cplusplus
27extern "C" {
28#endif
29
Gregory Szorc34c863a2012-03-21 03:54:29 +000030/**
31 * @defgroup LLVMCExecutionEngine Execution Engine
32 * @ingroup LLVMC
33 *
34 * @{
35 */
36
Andrew Kaylor31be5ef2013-04-29 17:49:40 +000037void LLVMLinkInMCJIT(void);
Bob Wilsona1d3e662009-06-24 21:09:18 +000038void LLVMLinkInInterpreter(void);
39
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000040typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
41typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +000042typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000043
Andrew Kaylor31be5ef2013-04-29 17:49:40 +000044struct LLVMMCJITCompilerOptions {
45 unsigned OptLevel;
Filip Pizlo85e0d272013-05-01 22:58:00 +000046 LLVMCodeModel CodeModel;
Andrew Kaylor31be5ef2013-04-29 17:49:40 +000047 LLVMBool NoFramePointerElim;
Filip Pizlo85e0d272013-05-01 22:58:00 +000048 LLVMBool EnableFastISel;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +000049 LLVMMCJITMemoryManagerRef MCJMM;
Andrew Kaylor31be5ef2013-04-29 17:49:40 +000050};
51
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000052/*===-- Operations on generic values --------------------------------------===*/
53
54LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
55 unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +000056 LLVMBool IsSigned);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000057
58LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
59
60LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
61
62unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
63
64unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
Chris Lattner25963c62010-01-09 22:27:07 +000065 LLVMBool IsSigned);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000066
67void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
68
69double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
70
71void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
72
73/*===-- Operations on execution engines -----------------------------------===*/
74
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +000075LLVMBool 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
Filip Pizlo85e0d272013-05-01 22:58:00 +000088void LLVMInitializeMCJITCompilerOptions(
89 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
90
Andrew Kaylor31be5ef2013-04-29 17:49:40 +000091/**
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
Filip Pizlo85e0d272013-05-01 22:58:00 +000094 * 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:
Andrew Kaylor31be5ef2013-04-29 17:49:40 +000097 *
98 * LLVMMCJITCompilerOptions options;
Filip Pizlo85e0d272013-05-01 22:58:00 +000099 * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000100 * ... fill in those options you care about
Filip Pizlo85e0d272013-05-01 22:58:00 +0000101 * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
102 * &error);
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000103 *
104 * Note that this is also correct, though possibly suboptimal:
105 *
106 * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
107 */
Filip Pizlo85e0d272013-05-01 22:58:00 +0000108LLVMBool LLVMCreateMCJITCompilerForModule(
109 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
110 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
111 char **OutError);
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000112
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000113/** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
Chris Lattner25963c62010-01-09 22:27:07 +0000114LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
115 LLVMModuleProviderRef MP,
116 char **OutError);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000117
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000118/** Deprecated: Use LLVMCreateInterpreterForModule instead. */
Chris Lattner25963c62010-01-09 22:27:07 +0000119LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
120 LLVMModuleProviderRef MP,
121 char **OutError);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000122
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000123/** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
Chris Lattner25963c62010-01-09 22:27:07 +0000124LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
125 LLVMModuleProviderRef MP,
126 unsigned OptLevel,
127 char **OutError);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000128
129void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
130
131void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
132
133void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
134
135int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
136 unsigned ArgC, const char * const *ArgV,
137 const char * const *EnvP);
138
139LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
140 unsigned NumArgs,
141 LLVMGenericValueRef *Args);
142
143void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
144
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000145void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
146
147/** Deprecated: Use LLVMAddModule instead. */
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000148void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
149
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000150LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
151 LLVMModuleRef *OutMod, char **OutError);
152
153/** Deprecated: Use LLVMRemoveModule instead. */
Chris Lattner25963c62010-01-09 22:27:07 +0000154LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
155 LLVMModuleProviderRef MP,
156 LLVMModuleRef *OutMod, char **OutError);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000157
Chris Lattner25963c62010-01-09 22:27:07 +0000158LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
159 LLVMValueRef *OutFn);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000160
Filip Pizlo85e0d272013-05-01 22:58:00 +0000161void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
162 LLVMValueRef Fn);
Duncan Sands330134b2010-07-19 09:33:13 +0000163
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000164LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
Juergen Ributzka5fe955c2014-01-23 19:23:28 +0000165LLVMTargetMachineRef
166LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000167
Gordon Henriksen9f337542008-06-20 02:16:11 +0000168void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
169 void* Addr);
170
Chris Lattner41b43da2009-01-21 18:11:10 +0000171void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
172
Peter Zotovc433cd72014-12-22 18:53:11 +0000173uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
174
175uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
176
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000177/*===-- Operations on memory managers -------------------------------------===*/
178
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000179typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
180 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
181 const char *SectionName);
182typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
183 void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
184 const char *SectionName, LLVMBool IsReadOnly);
185typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(
186 void *Opaque, char **ErrMsg);
Anders Waldenborg9515b312013-09-30 19:11:32 +0000187typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
188
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000189/**
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 */
200LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
201 void *Opaque,
Anders Waldenborg9515b312013-09-30 19:11:32 +0000202 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
203 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
204 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
Benjamin Kramer57f30bc2013-10-22 15:18:03 +0000205 LLVMMemoryManagerDestroyCallback Destroy);
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000206
207void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
208
Gregory Szorc34c863a2012-03-21 03:54:29 +0000209/**
210 * @}
211 */
212
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000213#ifdef __cplusplus
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000214}
Evan Cheng2e254d02013-04-04 17:40:53 +0000215#endif /* defined(__cplusplus) */
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000216
217#endif