blob: cf3565c217ea4026e4fd1b3d31d930f8456f22a6 [file] [log] [blame]
Gordon Henriksen2e855e62007-12-23 16:59:28 +00001/*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattner7ed47a12007-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 Henriksen2e855e62007-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 Tryzelaar7c1483b2008-03-27 00:27:14 +000023#include "llvm-c/Target.h"
Filip Pizlo0e1327e2013-05-01 22:58:00 +000024#include "llvm-c/TargetMachine.h"
Gordon Henriksen2e855e62007-12-23 16:59:28 +000025
26#ifdef __cplusplus
27extern "C" {
28#endif
29
Gregory Szorc6244b512012-03-21 03:54:29 +000030/**
31 * @defgroup LLVMCExecutionEngine Execution Engine
32 * @ingroup LLVMC
33 *
34 * @{
35 */
36
Bob Wilsone46161f2009-06-24 21:09:18 +000037void LLVMLinkInJIT(void);
Andrew Kaylord2755af2013-04-29 17:49:40 +000038void LLVMLinkInMCJIT(void);
Bob Wilsone46161f2009-06-24 21:09:18 +000039void LLVMLinkInInterpreter(void);
40
Gordon Henriksen2e855e62007-12-23 16:59:28 +000041typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
42typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
Filip Pizlo6cfed362013-05-22 02:46:43 +000043typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
Gordon Henriksen2e855e62007-12-23 16:59:28 +000044
Andrew Kaylord2755af2013-04-29 17:49:40 +000045struct LLVMMCJITCompilerOptions {
46 unsigned OptLevel;
Filip Pizlo0e1327e2013-05-01 22:58:00 +000047 LLVMCodeModel CodeModel;
Andrew Kaylord2755af2013-04-29 17:49:40 +000048 LLVMBool NoFramePointerElim;
Filip Pizlo0e1327e2013-05-01 22:58:00 +000049 LLVMBool EnableFastISel;
Filip Pizlo6cfed362013-05-22 02:46:43 +000050 LLVMMCJITMemoryManagerRef MCJMM;
Andrew Kaylord2755af2013-04-29 17:49:40 +000051};
52
Gordon Henriksen2e855e62007-12-23 16:59:28 +000053/*===-- Operations on generic values --------------------------------------===*/
54
55LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
56 unsigned long long N,
Chris Lattnerd686c8e2010-01-09 22:27:07 +000057 LLVMBool IsSigned);
Gordon Henriksen2e855e62007-12-23 16:59:28 +000058
59LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
60
61LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
62
63unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
64
65unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
Chris Lattnerd686c8e2010-01-09 22:27:07 +000066 LLVMBool IsSigned);
Gordon Henriksen2e855e62007-12-23 16:59:28 +000067
68void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
69
70double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
71
72void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
73
74/*===-- Operations on execution engines -----------------------------------===*/
75
Erick Tryzelaardf7df072010-03-02 23:58:54 +000076LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
77 LLVMModuleRef M,
78 char **OutError);
79
80LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
81 LLVMModuleRef M,
82 char **OutError);
83
84LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
85 LLVMModuleRef M,
86 unsigned OptLevel,
87 char **OutError);
88
Filip Pizlo0e1327e2013-05-01 22:58:00 +000089void LLVMInitializeMCJITCompilerOptions(
90 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
91
Andrew Kaylord2755af2013-04-29 17:49:40 +000092/**
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
Filip Pizlo0e1327e2013-05-01 22:58:00 +000095 * 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:
Andrew Kaylord2755af2013-04-29 17:49:40 +000098 *
99 * LLVMMCJITCompilerOptions options;
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000100 * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
Andrew Kaylord2755af2013-04-29 17:49:40 +0000101 * ... fill in those options you care about
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000102 * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
103 * &error);
Andrew Kaylord2755af2013-04-29 17:49:40 +0000104 *
105 * Note that this is also correct, though possibly suboptimal:
106 *
107 * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
108 */
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000109LLVMBool LLVMCreateMCJITCompilerForModule(
110 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
111 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
112 char **OutError);
Andrew Kaylord2755af2013-04-29 17:49:40 +0000113
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000114/** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
Chris Lattnerd686c8e2010-01-09 22:27:07 +0000115LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
116 LLVMModuleProviderRef MP,
117 char **OutError);
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000118
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000119/** Deprecated: Use LLVMCreateInterpreterForModule instead. */
Chris Lattnerd686c8e2010-01-09 22:27:07 +0000120LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
121 LLVMModuleProviderRef MP,
122 char **OutError);
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000123
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000124/** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
Chris Lattnerd686c8e2010-01-09 22:27:07 +0000125LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
126 LLVMModuleProviderRef MP,
127 unsigned OptLevel,
128 char **OutError);
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000129
130void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
131
132void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
133
134void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
135
136int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
137 unsigned ArgC, const char * const *ArgV,
138 const char * const *EnvP);
139
140LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
141 unsigned NumArgs,
142 LLVMGenericValueRef *Args);
143
144void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
145
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000146void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
147
148/** Deprecated: Use LLVMAddModule instead. */
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000149void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
150
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000151LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
152 LLVMModuleRef *OutMod, char **OutError);
153
154/** Deprecated: Use LLVMRemoveModule instead. */
Chris Lattnerd686c8e2010-01-09 22:27:07 +0000155LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
156 LLVMModuleProviderRef MP,
157 LLVMModuleRef *OutMod, char **OutError);
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000158
Chris Lattnerd686c8e2010-01-09 22:27:07 +0000159LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
160 LLVMValueRef *OutFn);
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000161
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000162void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
163 LLVMValueRef Fn);
Duncan Sandsd90fee92010-07-19 09:33:13 +0000164
Erick Tryzelaar7c1483b2008-03-27 00:27:14 +0000165LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
166
Gordon Henriksen54227f62008-06-20 02:16:11 +0000167void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
168 void* Addr);
169
Chris Lattner1e42c5b2009-01-21 18:11:10 +0000170void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
171
Filip Pizlo6cfed362013-05-22 02:46:43 +0000172/*===-- Operations on memory managers -------------------------------------===*/
173
Anders Waldenborg5be81232013-09-30 19:11:32 +0000174typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(void *Opaque,
175 uintptr_t Size, unsigned Alignment,
176 unsigned SectionID);
177typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(void *Opaque,
178 uintptr_t Size, unsigned Alignment,
179 unsigned SectionID, LLVMBool IsReadOnly);
180typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(void *Opaque, char **ErrMsg);
181typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
182
Filip Pizlo6cfed362013-05-22 02:46:43 +0000183/**
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 */
194LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
195 void *Opaque,
Anders Waldenborg5be81232013-09-30 19:11:32 +0000196 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
197 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
198 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
199 LLVMMemoryManagerDestroyCallback Destory);
Filip Pizlo6cfed362013-05-22 02:46:43 +0000200
201void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
202
Gregory Szorc6244b512012-03-21 03:54:29 +0000203/**
204 * @}
205 */
206
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000207#ifdef __cplusplus
Eric Christopher3e397312013-04-22 22:47:22 +0000208}
Evan Cheng9313da52013-04-04 17:40:53 +0000209#endif /* defined(__cplusplus) */
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000210
211#endif