1193323Sed/*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
2193323Sed|*                                                                            *|
3193323Sed|*                     The LLVM Compiler Infrastructure                       *|
4193323Sed|*                                                                            *|
5193323Sed|* This file is distributed under the University of Illinois Open Source      *|
6193323Sed|* License. See LICENSE.TXT for details.                                      *|
7193323Sed|*                                                                            *|
8193323Sed|*===----------------------------------------------------------------------===*|
9193323Sed|*                                                                            *|
10193323Sed|* This header declares the C interface to libLLVMExecutionEngine.o, which    *|
11193323Sed|* implements various analyses of the LLVM IR.                                *|
12193323Sed|*                                                                            *|
13193323Sed|* Many exotic languages can interoperate with C code but have a harder time  *|
14193323Sed|* with C++ due to name mangling. So in addition to C, this interface enables *|
15193323Sed|* tools written in such languages.                                           *|
16193323Sed|*                                                                            *|
17193323Sed\*===----------------------------------------------------------------------===*/
18193323Sed
19193323Sed#ifndef LLVM_C_EXECUTIONENGINE_H
20193323Sed#define LLVM_C_EXECUTIONENGINE_H
21193323Sed
22296417Sdim#include "llvm-c/Types.h"
23193323Sed#include "llvm-c/Target.h"
24251662Sdim#include "llvm-c/TargetMachine.h"
25193323Sed
26193323Sed#ifdef __cplusplus
27193323Sedextern "C" {
28193323Sed#endif
29193323Sed
30234353Sdim/**
31234353Sdim * @defgroup LLVMCExecutionEngine Execution Engine
32234353Sdim * @ingroup LLVMC
33234353Sdim *
34234353Sdim * @{
35234353Sdim */
36234353Sdim
37251662Sdimvoid LLVMLinkInMCJIT(void);
38195098Sedvoid LLVMLinkInInterpreter(void);
39195098Sed
40193323Sedtypedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
41193323Sedtypedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
42261991Sdimtypedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
43193323Sed
44251662Sdimstruct LLVMMCJITCompilerOptions {
45251662Sdim  unsigned OptLevel;
46251662Sdim  LLVMCodeModel CodeModel;
47251662Sdim  LLVMBool NoFramePointerElim;
48251662Sdim  LLVMBool EnableFastISel;
49261991Sdim  LLVMMCJITMemoryManagerRef MCJMM;
50251662Sdim};
51251662Sdim
52193323Sed/*===-- Operations on generic values --------------------------------------===*/
53193323Sed
54193323SedLLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
55193323Sed                                                unsigned long long N,
56202375Srdivacky                                                LLVMBool IsSigned);
57193323Sed
58193323SedLLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
59193323Sed
60193323SedLLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
61193323Sed
62193323Sedunsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
63193323Sed
64193323Sedunsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
65202375Srdivacky                                         LLVMBool IsSigned);
66193323Sed
67193323Sedvoid *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
68193323Sed
69193323Seddouble LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
70193323Sed
71193323Sedvoid LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
72193323Sed
73193323Sed/*===-- Operations on execution engines -----------------------------------===*/
74193323Sed
75204642SrdivackyLLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
76204642Srdivacky                                            LLVMModuleRef M,
77204642Srdivacky                                            char **OutError);
78204642Srdivacky
79204642SrdivackyLLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
80204642Srdivacky                                        LLVMModuleRef M,
81204642Srdivacky                                        char **OutError);
82204642Srdivacky
83204642SrdivackyLLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
84204642Srdivacky                                        LLVMModuleRef M,
85204642Srdivacky                                        unsigned OptLevel,
86204642Srdivacky                                        char **OutError);
87204642Srdivacky
88251662Sdimvoid LLVMInitializeMCJITCompilerOptions(
89251662Sdim  struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
90251662Sdim
91251662Sdim/**
92251662Sdim * Create an MCJIT execution engine for a module, with the given options. It is
93251662Sdim * the responsibility of the caller to ensure that all fields in Options up to
94251662Sdim * the given SizeOfOptions are initialized. It is correct to pass a smaller
95251662Sdim * value of SizeOfOptions that omits some fields. The canonical way of using
96251662Sdim * this is:
97251662Sdim *
98251662Sdim * LLVMMCJITCompilerOptions options;
99251662Sdim * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
100251662Sdim * ... fill in those options you care about
101251662Sdim * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
102251662Sdim *                                  &error);
103251662Sdim *
104251662Sdim * Note that this is also correct, though possibly suboptimal:
105251662Sdim *
106251662Sdim * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
107251662Sdim */
108251662SdimLLVMBool LLVMCreateMCJITCompilerForModule(
109251662Sdim  LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
110251662Sdim  struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
111251662Sdim  char **OutError);
112251662Sdim
113193323Sedvoid LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
114193323Sed
115193323Sedvoid LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
116193323Sed
117193323Sedvoid LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
118193323Sed
119193323Sedint LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
120193323Sed                          unsigned ArgC, const char * const *ArgV,
121193323Sed                          const char * const *EnvP);
122193323Sed
123193323SedLLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
124193323Sed                                    unsigned NumArgs,
125193323Sed                                    LLVMGenericValueRef *Args);
126193323Sed
127193323Sedvoid LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
128193323Sed
129204642Srdivackyvoid LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
130204642Srdivacky
131204642SrdivackyLLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
132204642Srdivacky                          LLVMModuleRef *OutMod, char **OutError);
133204642Srdivacky
134202375SrdivackyLLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
135202375Srdivacky                          LLVMValueRef *OutFn);
136193323Sed
137251662Sdimvoid *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
138251662Sdim                                     LLVMValueRef Fn);
139212904Sdim
140193323SedLLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
141276479SdimLLVMTargetMachineRef
142276479SdimLLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
143193323Sed
144193323Sedvoid LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
145193323Sed                          void* Addr);
146193323Sed
147193323Sedvoid *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
148193323Sed
149280031Sdimuint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
150280031Sdim
151280031Sdimuint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
152280031Sdim
153261991Sdim/*===-- Operations on memory managers -------------------------------------===*/
154261991Sdim
155261991Sdimtypedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
156261991Sdim  void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
157261991Sdim  const char *SectionName);
158261991Sdimtypedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
159261991Sdim  void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
160261991Sdim  const char *SectionName, LLVMBool IsReadOnly);
161261991Sdimtypedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(
162261991Sdim  void *Opaque, char **ErrMsg);
163261991Sdimtypedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
164261991Sdim
165234353Sdim/**
166261991Sdim * Create a simple custom MCJIT memory manager. This memory manager can
167261991Sdim * intercept allocations in a module-oblivious way. This will return NULL
168261991Sdim * if any of the passed functions are NULL.
169261991Sdim *
170261991Sdim * @param Opaque An opaque client object to pass back to the callbacks.
171261991Sdim * @param AllocateCodeSection Allocate a block of memory for executable code.
172261991Sdim * @param AllocateDataSection Allocate a block of memory for data.
173261991Sdim * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
174261991Sdim *   success, 1 on error.
175261991Sdim */
176261991SdimLLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
177261991Sdim  void *Opaque,
178261991Sdim  LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
179261991Sdim  LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
180261991Sdim  LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
181261991Sdim  LLVMMemoryManagerDestroyCallback Destroy);
182261991Sdim
183261991Sdimvoid LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
184261991Sdim
185261991Sdim/**
186234353Sdim * @}
187234353Sdim */
188234353Sdim
189193323Sed#ifdef __cplusplus
190261991Sdim}
191193323Sed#endif /* defined(__cplusplus) */
192193323Sed
193193323Sed#endif
194