Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:01

0001 /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
0002 |*                                                                            *|
0003 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
0004 |* Exceptions.                                                                *|
0005 |* See https://llvm.org/LICENSE.txt for license information.                  *|
0006 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
0007 |*                                                                            *|
0008 |*===----------------------------------------------------------------------===*|
0009 |*                                                                            *|
0010 |* This header declares the C interface to libLLVMExecutionEngine.o, which    *|
0011 |* implements various analyses of the LLVM IR.                                *|
0012 |*                                                                            *|
0013 |* Many exotic languages can interoperate with C code but have a harder time  *|
0014 |* with C++ due to name mangling. So in addition to C, this interface enables *|
0015 |* tools written in such languages.                                           *|
0016 |*                                                                            *|
0017 \*===----------------------------------------------------------------------===*/
0018 
0019 #ifndef LLVM_C_EXECUTIONENGINE_H
0020 #define LLVM_C_EXECUTIONENGINE_H
0021 
0022 #include "llvm-c/ExternC.h"
0023 #include "llvm-c/Target.h"
0024 #include "llvm-c/TargetMachine.h"
0025 #include "llvm-c/Types.h"
0026 
0027 LLVM_C_EXTERN_C_BEGIN
0028 
0029 /**
0030  * @defgroup LLVMCExecutionEngine Execution Engine
0031  * @ingroup LLVMC
0032  *
0033  * @{
0034  */
0035 
0036 void LLVMLinkInMCJIT(void);
0037 void LLVMLinkInInterpreter(void);
0038 
0039 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
0040 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
0041 typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
0042 
0043 struct LLVMMCJITCompilerOptions {
0044   unsigned OptLevel;
0045   LLVMCodeModel CodeModel;
0046   LLVMBool NoFramePointerElim;
0047   LLVMBool EnableFastISel;
0048   LLVMMCJITMemoryManagerRef MCJMM;
0049 };
0050 
0051 /*===-- Operations on generic values --------------------------------------===*/
0052 
0053 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
0054                                                 unsigned long long N,
0055                                                 LLVMBool IsSigned);
0056 
0057 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
0058 
0059 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
0060 
0061 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
0062 
0063 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
0064                                          LLVMBool IsSigned);
0065 
0066 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
0067 
0068 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
0069 
0070 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
0071 
0072 /*===-- Operations on execution engines -----------------------------------===*/
0073 
0074 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
0075                                             LLVMModuleRef M,
0076                                             char **OutError);
0077 
0078 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
0079                                         LLVMModuleRef M,
0080                                         char **OutError);
0081 
0082 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
0083                                         LLVMModuleRef M,
0084                                         unsigned OptLevel,
0085                                         char **OutError);
0086 
0087 void LLVMInitializeMCJITCompilerOptions(
0088   struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
0089 
0090 /**
0091  * Create an MCJIT execution engine for a module, with the given options. It is
0092  * the responsibility of the caller to ensure that all fields in Options up to
0093  * the given SizeOfOptions are initialized. It is correct to pass a smaller
0094  * value of SizeOfOptions that omits some fields. The canonical way of using
0095  * this is:
0096  *
0097  * LLVMMCJITCompilerOptions options;
0098  * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
0099  * ... fill in those options you care about
0100  * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
0101  *                                  &error);
0102  *
0103  * Note that this is also correct, though possibly suboptimal:
0104  *
0105  * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
0106  */
0107 LLVMBool LLVMCreateMCJITCompilerForModule(
0108   LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
0109   struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
0110   char **OutError);
0111 
0112 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
0113 
0114 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
0115 
0116 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
0117 
0118 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
0119                           unsigned ArgC, const char * const *ArgV,
0120                           const char * const *EnvP);
0121 
0122 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
0123                                     unsigned NumArgs,
0124                                     LLVMGenericValueRef *Args);
0125 
0126 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
0127 
0128 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
0129 
0130 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
0131                           LLVMModuleRef *OutMod, char **OutError);
0132 
0133 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
0134                           LLVMValueRef *OutFn);
0135 
0136 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
0137                                      LLVMValueRef Fn);
0138 
0139 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
0140 LLVMTargetMachineRef
0141 LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
0142 
0143 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
0144                           void* Addr);
0145 
0146 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
0147 
0148 uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
0149 
0150 uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
0151 
0152 /// Returns true on error, false on success. If true is returned then the error
0153 /// message is copied to OutStr and cleared in the ExecutionEngine instance.
0154 LLVMBool LLVMExecutionEngineGetErrMsg(LLVMExecutionEngineRef EE,
0155                                       char **OutError);
0156 
0157 /*===-- Operations on memory managers -------------------------------------===*/
0158 
0159 typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
0160   void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
0161   const char *SectionName);
0162 typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
0163   void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
0164   const char *SectionName, LLVMBool IsReadOnly);
0165 typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(
0166   void *Opaque, char **ErrMsg);
0167 typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
0168 
0169 /**
0170  * Create a simple custom MCJIT memory manager. This memory manager can
0171  * intercept allocations in a module-oblivious way. This will return NULL
0172  * if any of the passed functions are NULL.
0173  *
0174  * @param Opaque An opaque client object to pass back to the callbacks.
0175  * @param AllocateCodeSection Allocate a block of memory for executable code.
0176  * @param AllocateDataSection Allocate a block of memory for data.
0177  * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
0178  *   success, 1 on error.
0179  */
0180 LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
0181   void *Opaque,
0182   LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
0183   LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
0184   LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
0185   LLVMMemoryManagerDestroyCallback Destroy);
0186 
0187 void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
0188 
0189 /*===-- JIT Event Listener functions -------------------------------------===*/
0190 
0191 LLVMJITEventListenerRef LLVMCreateGDBRegistrationListener(void);
0192 LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void);
0193 LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void);
0194 LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void);
0195 
0196 /**
0197  * @}
0198  */
0199 
0200 LLVM_C_EXTERN_C_END
0201 
0202 #endif