ExecutionEngine.h 8.2 KB

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