LLJIT.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. /*===----------- llvm-c/LLJIT.h - OrcV2 LLJIT C bindings --------*- 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 the LLJIT class in *|
  16. |* libLLVMOrcJIT.a, which provides a simple MCJIT-like ORC JIT. *|
  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. |* Note: This interface is experimental. It is *NOT* stable, and may be *|
  23. |* changed without warning. Only C API usage documentation is *|
  24. |* provided. See the C++ documentation for all higher level ORC API *|
  25. |* details. *|
  26. |* *|
  27. \*===----------------------------------------------------------------------===*/
  28. #ifndef LLVM_C_LLJIT_H
  29. #define LLVM_C_LLJIT_H
  30. #include "llvm-c/Error.h"
  31. #include "llvm-c/Orc.h"
  32. #include "llvm-c/TargetMachine.h"
  33. #include "llvm-c/Types.h"
  34. LLVM_C_EXTERN_C_BEGIN
  35. /**
  36. * @defgroup LLVMCExecutionEngineLLJIT LLJIT
  37. * @ingroup LLVMCExecutionEngine
  38. *
  39. * @{
  40. */
  41. /**
  42. * A function for constructing an ObjectLinkingLayer instance to be used
  43. * by an LLJIT instance.
  44. *
  45. * Clients can call LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator to
  46. * set the creator function to use when constructing an LLJIT instance.
  47. * This can be used to override the default linking layer implementation
  48. * that would otherwise be chosen by LLJITBuilder.
  49. *
  50. * Object linking layers returned by this function will become owned by the
  51. * LLJIT instance. The client is not responsible for managing their lifetimes
  52. * after the function returns.
  53. */
  54. typedef LLVMOrcObjectLayerRef (
  55. *LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction)(
  56. void *Ctx, LLVMOrcExecutionSessionRef ES, const char *Triple);
  57. /**
  58. * A reference to an orc::LLJITBuilder instance.
  59. */
  60. typedef struct LLVMOrcOpaqueLLJITBuilder *LLVMOrcLLJITBuilderRef;
  61. /**
  62. * A reference to an orc::LLJIT instance.
  63. */
  64. typedef struct LLVMOrcOpaqueLLJIT *LLVMOrcLLJITRef;
  65. /**
  66. * Create an LLVMOrcLLJITBuilder.
  67. *
  68. * The client owns the resulting LLJITBuilder and should dispose of it using
  69. * LLVMOrcDisposeLLJITBuilder once they are done with it.
  70. */
  71. LLVMOrcLLJITBuilderRef LLVMOrcCreateLLJITBuilder(void);
  72. /**
  73. * Dispose of an LLVMOrcLLJITBuilderRef. This should only be called if ownership
  74. * has not been passed to LLVMOrcCreateLLJIT (e.g. because some error prevented
  75. * that function from being called).
  76. */
  77. void LLVMOrcDisposeLLJITBuilder(LLVMOrcLLJITBuilderRef Builder);
  78. /**
  79. * Set the JITTargetMachineBuilder to be used when constructing the LLJIT
  80. * instance. Calling this function is optional: if it is not called then the
  81. * LLJITBuilder will use JITTargeTMachineBuilder::detectHost to construct a
  82. * JITTargetMachineBuilder.
  83. *
  84. * This function takes ownership of the JTMB argument: clients should not
  85. * dispose of the JITTargetMachineBuilder after calling this function.
  86. */
  87. void LLVMOrcLLJITBuilderSetJITTargetMachineBuilder(
  88. LLVMOrcLLJITBuilderRef Builder, LLVMOrcJITTargetMachineBuilderRef JTMB);
  89. /**
  90. * Set an ObjectLinkingLayer creator function for this LLJIT instance.
  91. */
  92. void LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator(
  93. LLVMOrcLLJITBuilderRef Builder,
  94. LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction F, void *Ctx);
  95. /**
  96. * Create an LLJIT instance from an LLJITBuilder.
  97. *
  98. * This operation takes ownership of the Builder argument: clients should not
  99. * dispose of the builder after calling this function (even if the function
  100. * returns an error). If a null Builder argument is provided then a
  101. * default-constructed LLJITBuilder will be used.
  102. *
  103. * On success the resulting LLJIT instance is uniquely owned by the client and
  104. * automatically manages the memory of all JIT'd code and all modules that are
  105. * transferred to it (e.g. via LLVMOrcLLJITAddLLVMIRModule). Disposing of the
  106. * LLJIT instance will free all memory managed by the JIT, including JIT'd code
  107. * and not-yet compiled modules.
  108. */
  109. LLVMErrorRef LLVMOrcCreateLLJIT(LLVMOrcLLJITRef *Result,
  110. LLVMOrcLLJITBuilderRef Builder);
  111. /**
  112. * Dispose of an LLJIT instance.
  113. */
  114. LLVMErrorRef LLVMOrcDisposeLLJIT(LLVMOrcLLJITRef J);
  115. /**
  116. * Get a reference to the ExecutionSession for this LLJIT instance.
  117. *
  118. * The ExecutionSession is owned by the LLJIT instance. The client is not
  119. * responsible for managing its memory.
  120. */
  121. LLVMOrcExecutionSessionRef LLVMOrcLLJITGetExecutionSession(LLVMOrcLLJITRef J);
  122. /**
  123. * Return a reference to the Main JITDylib.
  124. *
  125. * The JITDylib is owned by the LLJIT instance. The client is not responsible
  126. * for managing its memory.
  127. */
  128. LLVMOrcJITDylibRef LLVMOrcLLJITGetMainJITDylib(LLVMOrcLLJITRef J);
  129. /**
  130. * Return the target triple for this LLJIT instance. This string is owned by
  131. * the LLJIT instance and should not be freed by the client.
  132. */
  133. const char *LLVMOrcLLJITGetTripleString(LLVMOrcLLJITRef J);
  134. /**
  135. * Returns the global prefix character according to the LLJIT's DataLayout.
  136. */
  137. char LLVMOrcLLJITGetGlobalPrefix(LLVMOrcLLJITRef J);
  138. /**
  139. * Mangles the given string according to the LLJIT instance's DataLayout, then
  140. * interns the result in the SymbolStringPool and returns a reference to the
  141. * pool entry. Clients should call LLVMOrcReleaseSymbolStringPoolEntry to
  142. * decrement the ref-count on the pool entry once they are finished with this
  143. * value.
  144. */
  145. LLVMOrcSymbolStringPoolEntryRef
  146. LLVMOrcLLJITMangleAndIntern(LLVMOrcLLJITRef J, const char *UnmangledName);
  147. /**
  148. * Add a buffer representing an object file to the given JITDylib in the given
  149. * LLJIT instance. This operation transfers ownership of the buffer to the
  150. * LLJIT instance. The buffer should not be disposed of or referenced once this
  151. * function returns.
  152. *
  153. * Resources associated with the given object will be tracked by the given
  154. * JITDylib's default resource tracker.
  155. */
  156. LLVMErrorRef LLVMOrcLLJITAddObjectFile(LLVMOrcLLJITRef J, LLVMOrcJITDylibRef JD,
  157. LLVMMemoryBufferRef ObjBuffer);
  158. /**
  159. * Add a buffer representing an object file to the given ResourceTracker's
  160. * JITDylib in the given LLJIT instance. This operation transfers ownership of
  161. * the buffer to the LLJIT instance. The buffer should not be disposed of or
  162. * referenced once this function returns.
  163. *
  164. * Resources associated with the given object will be tracked by ResourceTracker
  165. * RT.
  166. */
  167. LLVMErrorRef LLVMOrcLLJITAddObjectFileWithRT(LLVMOrcLLJITRef J,
  168. LLVMOrcResourceTrackerRef RT,
  169. LLVMMemoryBufferRef ObjBuffer);
  170. /**
  171. * Add an IR module to the given JITDylib in the given LLJIT instance. This
  172. * operation transfers ownership of the TSM argument to the LLJIT instance.
  173. * The TSM argument should not be disposed of or referenced once this
  174. * function returns.
  175. *
  176. * Resources associated with the given Module will be tracked by the given
  177. * JITDylib's default resource tracker.
  178. */
  179. LLVMErrorRef LLVMOrcLLJITAddLLVMIRModule(LLVMOrcLLJITRef J,
  180. LLVMOrcJITDylibRef JD,
  181. LLVMOrcThreadSafeModuleRef TSM);
  182. /**
  183. * Add an IR module to the given ResourceTracker's JITDylib in the given LLJIT
  184. * instance. This operation transfers ownership of the TSM argument to the LLJIT
  185. * instance. The TSM argument should not be disposed of or referenced once this
  186. * function returns.
  187. *
  188. * Resources associated with the given Module will be tracked by ResourceTracker
  189. * RT.
  190. */
  191. LLVMErrorRef LLVMOrcLLJITAddLLVMIRModuleWithRT(LLVMOrcLLJITRef J,
  192. LLVMOrcResourceTrackerRef JD,
  193. LLVMOrcThreadSafeModuleRef TSM);
  194. /**
  195. * Look up the given symbol in the main JITDylib of the given LLJIT instance.
  196. *
  197. * This operation does not take ownership of the Name argument.
  198. */
  199. LLVMErrorRef LLVMOrcLLJITLookup(LLVMOrcLLJITRef J,
  200. LLVMOrcExecutorAddress *Result,
  201. const char *Name);
  202. /**
  203. * Returns a non-owning reference to the LLJIT instance's object linking layer.
  204. */
  205. LLVMOrcObjectLayerRef LLVMOrcLLJITGetObjLinkingLayer(LLVMOrcLLJITRef J);
  206. /**
  207. * Returns a non-owning reference to the LLJIT instance's object linking layer.
  208. */
  209. LLVMOrcObjectTransformLayerRef
  210. LLVMOrcLLJITGetObjTransformLayer(LLVMOrcLLJITRef J);
  211. /**
  212. * Returns a non-owning reference to the LLJIT instance's IR transform layer.
  213. */
  214. LLVMOrcIRTransformLayerRef LLVMOrcLLJITGetIRTransformLayer(LLVMOrcLLJITRef J);
  215. /**
  216. * Get the LLJIT instance's default data layout string.
  217. *
  218. * This string is owned by the LLJIT instance and does not need to be freed
  219. * by the caller.
  220. */
  221. const char *LLVMOrcLLJITGetDataLayoutStr(LLVMOrcLLJITRef J);
  222. /**
  223. * @}
  224. */
  225. LLVM_C_EXTERN_C_END
  226. #endif /* LLVM_C_LLJIT_H */
  227. #ifdef __GNUC__
  228. #pragma GCC diagnostic pop
  229. #endif