LLVM API Documentation

c/ExecutionEngine.h
Go to the documentation of this file.
00001 /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
00002 |*                                                                            *|
00003 |*                     The LLVM Compiler Infrastructure                       *|
00004 |*                                                                            *|
00005 |* This file is distributed under the University of Illinois Open Source      *|
00006 |* License. See LICENSE.TXT for details.                                      *|
00007 |*                                                                            *|
00008 |*===----------------------------------------------------------------------===*|
00009 |*                                                                            *|
00010 |* This header declares the C interface to libLLVMExecutionEngine.o, which    *|
00011 |* implements various analyses of the LLVM IR.                                *|
00012 |*                                                                            *|
00013 |* Many exotic languages can interoperate with C code but have a harder time  *|
00014 |* with C++ due to name mangling. So in addition to C, this interface enables *|
00015 |* tools written in such languages.                                           *|
00016 |*                                                                            *|
00017 \*===----------------------------------------------------------------------===*/
00018 
00019 #ifndef LLVM_C_EXECUTIONENGINE_H
00020 #define LLVM_C_EXECUTIONENGINE_H
00021 
00022 #include "llvm-c/Core.h"
00023 #include "llvm-c/Target.h"
00024 #include "llvm-c/TargetMachine.h"
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 /**
00031  * @defgroup LLVMCExecutionEngine Execution Engine
00032  * @ingroup LLVMC
00033  *
00034  * @{
00035  */
00036 
00037 void LLVMLinkInMCJIT(void);
00038 void LLVMLinkInInterpreter(void);
00039 
00040 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
00041 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
00042 typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
00043 
00044 struct LLVMMCJITCompilerOptions {
00045   unsigned OptLevel;
00046   LLVMCodeModel CodeModel;
00047   LLVMBool NoFramePointerElim;
00048   LLVMBool EnableFastISel;
00049   LLVMMCJITMemoryManagerRef MCJMM;
00050 };
00051 
00052 /*===-- Operations on generic values --------------------------------------===*/
00053 
00054 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
00055                                                 unsigned long long N,
00056                                                 LLVMBool IsSigned);
00057 
00058 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
00059 
00060 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
00061 
00062 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
00063 
00064 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
00065                                          LLVMBool IsSigned);
00066 
00067 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
00068 
00069 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
00070 
00071 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
00072 
00073 /*===-- Operations on execution engines -----------------------------------===*/
00074 
00075 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
00076                                             LLVMModuleRef M,
00077                                             char **OutError);
00078 
00079 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
00080                                         LLVMModuleRef M,
00081                                         char **OutError);
00082 
00083 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
00084                                         LLVMModuleRef M,
00085                                         unsigned OptLevel,
00086                                         char **OutError);
00087 
00088 void LLVMInitializeMCJITCompilerOptions(
00089   struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
00090 
00091 /**
00092  * Create an MCJIT execution engine for a module, with the given options. It is
00093  * the responsibility of the caller to ensure that all fields in Options up to
00094  * the given SizeOfOptions are initialized. It is correct to pass a smaller
00095  * value of SizeOfOptions that omits some fields. The canonical way of using
00096  * this is:
00097  *
00098  * LLVMMCJITCompilerOptions options;
00099  * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
00100  * ... fill in those options you care about
00101  * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
00102  *                                  &error);
00103  *
00104  * Note that this is also correct, though possibly suboptimal:
00105  *
00106  * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
00107  */
00108 LLVMBool LLVMCreateMCJITCompilerForModule(
00109   LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
00110   struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
00111   char **OutError);
00112 
00113 /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
00114 LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
00115                                    LLVMModuleProviderRef MP,
00116                                    char **OutError);
00117 
00118 /** Deprecated: Use LLVMCreateInterpreterForModule instead. */
00119 LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
00120                                LLVMModuleProviderRef MP,
00121                                char **OutError);
00122 
00123 /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
00124 LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
00125                                LLVMModuleProviderRef MP,
00126                                unsigned OptLevel,
00127                                char **OutError);
00128 
00129 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
00130 
00131 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
00132 
00133 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
00134 
00135 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
00136                           unsigned ArgC, const char * const *ArgV,
00137                           const char * const *EnvP);
00138 
00139 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
00140                                     unsigned NumArgs,
00141                                     LLVMGenericValueRef *Args);
00142 
00143 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
00144 
00145 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
00146 
00147 /** Deprecated: Use LLVMAddModule instead. */
00148 void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
00149 
00150 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
00151                           LLVMModuleRef *OutMod, char **OutError);
00152 
00153 /** Deprecated: Use LLVMRemoveModule instead. */
00154 LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
00155                                   LLVMModuleProviderRef MP,
00156                                   LLVMModuleRef *OutMod, char **OutError);
00157 
00158 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
00159                           LLVMValueRef *OutFn);
00160 
00161 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
00162                                      LLVMValueRef Fn);
00163 
00164 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
00165 LLVMTargetMachineRef
00166 LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
00167 
00168 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
00169                           void* Addr);
00170 
00171 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
00172 
00173 /*===-- Operations on memory managers -------------------------------------===*/
00174 
00175 typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
00176   void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
00177   const char *SectionName);
00178 typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
00179   void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
00180   const char *SectionName, LLVMBool IsReadOnly);
00181 typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(
00182   void *Opaque, char **ErrMsg);
00183 typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
00184 
00185 /**
00186  * Create a simple custom MCJIT memory manager. This memory manager can
00187  * intercept allocations in a module-oblivious way. This will return NULL
00188  * if any of the passed functions are NULL.
00189  *
00190  * @param Opaque An opaque client object to pass back to the callbacks.
00191  * @param AllocateCodeSection Allocate a block of memory for executable code.
00192  * @param AllocateDataSection Allocate a block of memory for data.
00193  * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
00194  *   success, 1 on error.
00195  */
00196 LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
00197   void *Opaque,
00198   LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
00199   LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
00200   LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
00201   LLVMMemoryManagerDestroyCallback Destroy);
00202 
00203 void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
00204 
00205 /**
00206  * @}
00207  */
00208 
00209 #ifdef __cplusplus
00210 }
00211 #endif /* defined(__cplusplus) */
00212 
00213 #endif