blob: e8ebef9ab15d8a709046c167a18e80813288ede4 [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
Erick Tryzelaar7c1483b2008-03-27 00:27:14 +000022#include "llvm-c/Target.h"
Filip Pizlo0e1327e2013-05-01 22:58:00 +000023#include "llvm-c/TargetMachine.h"
Chandler Carruthe3e43d92017-06-06 11:49:48 +000024#include "llvm-c/Types.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
Andrew Kaylord2755af2013-04-29 17:49:40 +000037void LLVMLinkInMCJIT(void);
Bob Wilsone46161f2009-06-24 21:09:18 +000038void LLVMLinkInInterpreter(void);
39
Gordon Henriksen2e855e62007-12-23 16:59:28 +000040typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
41typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
Filip Pizlo6cfed362013-05-22 02:46:43 +000042typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
Gordon Henriksen2e855e62007-12-23 16:59:28 +000043
Andrew Kaylord2755af2013-04-29 17:49:40 +000044struct LLVMMCJITCompilerOptions {
45 unsigned OptLevel;
Filip Pizlo0e1327e2013-05-01 22:58:00 +000046 LLVMCodeModel CodeModel;
Andrew Kaylord2755af2013-04-29 17:49:40 +000047 LLVMBool NoFramePointerElim;
Filip Pizlo0e1327e2013-05-01 22:58:00 +000048 LLVMBool EnableFastISel;
Filip Pizlo6cfed362013-05-22 02:46:43 +000049 LLVMMCJITMemoryManagerRef MCJMM;
Andrew Kaylord2755af2013-04-29 17:49:40 +000050};
51
Gordon Henriksen2e855e62007-12-23 16:59:28 +000052/*===-- Operations on generic values --------------------------------------===*/
53
54LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
55 unsigned long long N,
Chris Lattnerd686c8e2010-01-09 22:27:07 +000056 LLVMBool IsSigned);
Gordon Henriksen2e855e62007-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 Lattnerd686c8e2010-01-09 22:27:07 +000065 LLVMBool IsSigned);
Gordon Henriksen2e855e62007-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 Tryzelaardf7df072010-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 Pizlo0e1327e2013-05-01 22:58:00 +000088void LLVMInitializeMCJITCompilerOptions(
89 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
90
Andrew Kaylord2755af2013-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 Pizlo0e1327e2013-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 Kaylord2755af2013-04-29 17:49:40 +000097 *
98 * LLVMMCJITCompilerOptions options;
Filip Pizlo0e1327e2013-05-01 22:58:00 +000099 * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
Andrew Kaylord2755af2013-04-29 17:49:40 +0000100 * ... fill in those options you care about
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000101 * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
102 * &error);
Andrew Kaylord2755af2013-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 Pizlo0e1327e2013-05-01 22:58:00 +0000108LLVMBool LLVMCreateMCJITCompilerForModule(
109 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
110 struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
111 char **OutError);
Andrew Kaylord2755af2013-04-29 17:49:40 +0000112
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000113void 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
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000129void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
130
Erick Tryzelaardf7df072010-03-02 23:58:54 +0000131LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
132 LLVMModuleRef *OutMod, char **OutError);
133
Chris Lattnerd686c8e2010-01-09 22:27:07 +0000134LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
135 LLVMValueRef *OutFn);
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000136
Filip Pizlo0e1327e2013-05-01 22:58:00 +0000137void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
138 LLVMValueRef Fn);
Duncan Sandsd90fee92010-07-19 09:33:13 +0000139
Erick Tryzelaar7c1483b2008-03-27 00:27:14 +0000140LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
Juergen Ributzka9ce88db2014-01-23 19:23:28 +0000141LLVMTargetMachineRef
142LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
Erick Tryzelaar7c1483b2008-03-27 00:27:14 +0000143
Gordon Henriksen54227f62008-06-20 02:16:11 +0000144void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
145 void* Addr);
146
Chris Lattner1e42c5b2009-01-21 18:11:10 +0000147void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
148
Peter Zotov7bfc61d2014-12-22 18:53:11 +0000149uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
150
151uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
152
Filip Pizlo6cfed362013-05-22 02:46:43 +0000153/*===-- Operations on memory managers -------------------------------------===*/
154
Filip Pizlo6eb43d22013-10-02 00:59:25 +0000155typedef 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);
Anders Waldenborg5be81232013-09-30 19:11:32 +0000163typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
164
Filip Pizlo6cfed362013-05-22 02:46:43 +0000165/**
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,
Anders Waldenborg5be81232013-09-30 19:11:32 +0000178 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
179 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
180 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
Benjamin Kramer135fe6a2013-10-22 15:18:03 +0000181 LLVMMemoryManagerDestroyCallback Destroy);
Filip Pizlo6cfed362013-05-22 02:46:43 +0000182
183void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
184
Andres Freundf501bf32018-05-24 21:32:54 +0000185/*===-- JIT Event Listener functions -------------------------------------===*/
186
187LLVMJITEventListenerRef LLVMCreateGDBRegistrationListener(void);
188LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void);
Alex Denisov180fb862018-11-02 09:57:24 +0000189LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void);
Andres Freundc4c8d7b2018-07-24 00:54:06 +0000190LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void);
Andres Freundf501bf32018-05-24 21:32:54 +0000191
Gregory Szorc6244b512012-03-21 03:54:29 +0000192/**
193 * @}
194 */
195
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000196#ifdef __cplusplus
NAKAMURA Takumie21c3132013-10-23 17:56:29 +0000197}
Evan Cheng9313da52013-04-04 17:40:53 +0000198#endif /* defined(__cplusplus) */
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000199
200#endif