ExecutionEngine.h 8.7 KB

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