ExecutionEngine.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
  7. |* *|
  8. |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
  9. |* Exceptions. *|
  10. |* See https://llvm.org/LICENSE.txt for license information. *|
  11. |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
  12. |* *|
  13. |*===----------------------------------------------------------------------===*|
  14. |* *|
  15. |* This header declares the C interface to libLLVMExecutionEngine.o, which *|
  16. |* implements various analyses of the LLVM IR. *|
  17. |* *|
  18. |* Many exotic languages can interoperate with C code but have a harder time *|
  19. |* with C++ due to name mangling. So in addition to C, this interface enables *|
  20. |* tools written in such languages. *|
  21. |* *|
  22. \*===----------------------------------------------------------------------===*/
  23. #ifndef LLVM_C_EXECUTIONENGINE_H
  24. #define LLVM_C_EXECUTIONENGINE_H
  25. #include "llvm-c/ExternC.h"
  26. #include "llvm-c/Target.h"
  27. #include "llvm-c/TargetMachine.h"
  28. #include "llvm-c/Types.h"
  29. LLVM_C_EXTERN_C_BEGIN
  30. /**
  31. * @defgroup LLVMCExecutionEngine Execution Engine
  32. * @ingroup LLVMC
  33. *
  34. * @{
  35. */
  36. void LLVMLinkInMCJIT(void);
  37. void LLVMLinkInInterpreter(void);
  38. typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
  39. typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
  40. typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
  41. struct LLVMMCJITCompilerOptions {
  42. unsigned OptLevel;
  43. LLVMCodeModel CodeModel;
  44. LLVMBool NoFramePointerElim;
  45. LLVMBool EnableFastISel;
  46. LLVMMCJITMemoryManagerRef MCJMM;
  47. };
  48. /*===-- Operations on generic values --------------------------------------===*/
  49. LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
  50. unsigned long long N,
  51. LLVMBool IsSigned);
  52. LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
  53. LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
  54. unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
  55. unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
  56. LLVMBool IsSigned);
  57. void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
  58. double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
  59. void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
  60. /*===-- Operations on execution engines -----------------------------------===*/
  61. LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
  62. LLVMModuleRef M,
  63. char **OutError);
  64. LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
  65. LLVMModuleRef M,
  66. char **OutError);
  67. LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
  68. LLVMModuleRef M,
  69. unsigned OptLevel,
  70. char **OutError);
  71. void LLVMInitializeMCJITCompilerOptions(
  72. struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
  73. /**
  74. * Create an MCJIT execution engine for a module, with the given options. It is
  75. * the responsibility of the caller to ensure that all fields in Options up to
  76. * the given SizeOfOptions are initialized. It is correct to pass a smaller
  77. * value of SizeOfOptions that omits some fields. The canonical way of using
  78. * this is:
  79. *
  80. * LLVMMCJITCompilerOptions options;
  81. * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
  82. * ... fill in those options you care about
  83. * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
  84. * &error);
  85. *
  86. * Note that this is also correct, though possibly suboptimal:
  87. *
  88. * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
  89. */
  90. LLVMBool LLVMCreateMCJITCompilerForModule(
  91. LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
  92. struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
  93. char **OutError);
  94. void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
  95. void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
  96. void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
  97. int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
  98. unsigned ArgC, const char * const *ArgV,
  99. const char * const *EnvP);
  100. LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
  101. unsigned NumArgs,
  102. LLVMGenericValueRef *Args);
  103. void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
  104. void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
  105. LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
  106. LLVMModuleRef *OutMod, char **OutError);
  107. LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
  108. LLVMValueRef *OutFn);
  109. void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
  110. LLVMValueRef Fn);
  111. LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
  112. LLVMTargetMachineRef
  113. LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
  114. void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
  115. void* Addr);
  116. void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
  117. uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
  118. uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
  119. /// Returns true on error, false on success. If true is returned then the error
  120. /// message is copied to OutStr and cleared in the ExecutionEngine instance.
  121. LLVMBool LLVMExecutionEngineGetErrMsg(LLVMExecutionEngineRef EE,
  122. char **OutError);
  123. /*===-- Operations on memory managers -------------------------------------===*/
  124. typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
  125. void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
  126. const char *SectionName);
  127. typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
  128. void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
  129. const char *SectionName, LLVMBool IsReadOnly);
  130. typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(
  131. void *Opaque, char **ErrMsg);
  132. typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
  133. /**
  134. * Create a simple custom MCJIT memory manager. This memory manager can
  135. * intercept allocations in a module-oblivious way. This will return NULL
  136. * if any of the passed functions are NULL.
  137. *
  138. * @param Opaque An opaque client object to pass back to the callbacks.
  139. * @param AllocateCodeSection Allocate a block of memory for executable code.
  140. * @param AllocateDataSection Allocate a block of memory for data.
  141. * @param FinalizeMemory Set page permissions and flush cache. Return 0 on
  142. * success, 1 on error.
  143. */
  144. LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
  145. void *Opaque,
  146. LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
  147. LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
  148. LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
  149. LLVMMemoryManagerDestroyCallback Destroy);
  150. void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
  151. /*===-- JIT Event Listener functions -------------------------------------===*/
  152. LLVMJITEventListenerRef LLVMCreateGDBRegistrationListener(void);
  153. LLVMJITEventListenerRef LLVMCreateIntelJITEventListener(void);
  154. LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void);
  155. LLVMJITEventListenerRef LLVMCreatePerfJITEventListener(void);
  156. /**
  157. * @}
  158. */
  159. LLVM_C_EXTERN_C_END
  160. #endif
  161. #ifdef __GNUC__
  162. #pragma GCC diagnostic pop
  163. #endif