LLJIT.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. * A function for constructing an ObjectLinkingLayer instance to be used
  37. * by an LLJIT instance.
  38. *
  39. * Clients can call LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator to
  40. * set the creator function to use when constructing an LLJIT instance.
  41. * This can be used to override the default linking layer implementation
  42. * that would otherwise be chosen by LLJITBuilder.
  43. *
  44. * Object linking layers returned by this function will become owned by the
  45. * LLJIT instance. The client is not responsible for managing their lifetimes
  46. * after the function returns.
  47. */
  48. typedef LLVMOrcObjectLayerRef (
  49. *LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction)(
  50. void *Ctx, LLVMOrcExecutionSessionRef ES, const char *Triple);
  51. /**
  52. * A reference to an orc::LLJITBuilder instance.
  53. */
  54. typedef struct LLVMOrcOpaqueLLJITBuilder *LLVMOrcLLJITBuilderRef;
  55. /**
  56. * A reference to an orc::LLJIT instance.
  57. */
  58. typedef struct LLVMOrcOpaqueLLJIT *LLVMOrcLLJITRef;
  59. /**
  60. * Create an LLVMOrcLLJITBuilder.
  61. *
  62. * The client owns the resulting LLJITBuilder and should dispose of it using
  63. * LLVMOrcDisposeLLJITBuilder once they are done with it.
  64. */
  65. LLVMOrcLLJITBuilderRef LLVMOrcCreateLLJITBuilder(void);
  66. /**
  67. * Dispose of an LLVMOrcLLJITBuilderRef. This should only be called if ownership
  68. * has not been passed to LLVMOrcCreateLLJIT (e.g. because some error prevented
  69. * that function from being called).
  70. */
  71. void LLVMOrcDisposeLLJITBuilder(LLVMOrcLLJITBuilderRef Builder);
  72. /**
  73. * Set the JITTargetMachineBuilder to be used when constructing the LLJIT
  74. * instance. Calling this function is optional: if it is not called then the
  75. * LLJITBuilder will use JITTargeTMachineBuilder::detectHost to construct a
  76. * JITTargetMachineBuilder.
  77. */
  78. void LLVMOrcLLJITBuilderSetJITTargetMachineBuilder(
  79. LLVMOrcLLJITBuilderRef Builder, LLVMOrcJITTargetMachineBuilderRef JTMB);
  80. /**
  81. * Set an ObjectLinkingLayer creator function for this LLJIT instance.
  82. */
  83. void LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator(
  84. LLVMOrcLLJITBuilderRef Builder,
  85. LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction F, void *Ctx);
  86. /**
  87. * Create an LLJIT instance from an LLJITBuilder.
  88. *
  89. * This operation takes ownership of the Builder argument: clients should not
  90. * dispose of the builder after calling this function (even if the function
  91. * returns an error). If a null Builder argument is provided then a
  92. * default-constructed LLJITBuilder will be used.
  93. *
  94. * On success the resulting LLJIT instance is uniquely owned by the client and
  95. * automatically manages the memory of all JIT'd code and all modules that are
  96. * transferred to it (e.g. via LLVMOrcLLJITAddLLVMIRModule). Disposing of the
  97. * LLJIT instance will free all memory managed by the JIT, including JIT'd code
  98. * and not-yet compiled modules.
  99. */
  100. LLVMErrorRef LLVMOrcCreateLLJIT(LLVMOrcLLJITRef *Result,
  101. LLVMOrcLLJITBuilderRef Builder);
  102. /**
  103. * Dispose of an LLJIT instance.
  104. */
  105. LLVMErrorRef LLVMOrcDisposeLLJIT(LLVMOrcLLJITRef J);
  106. /**
  107. * Get a reference to the ExecutionSession for this LLJIT instance.
  108. *
  109. * The ExecutionSession is owned by the LLJIT instance. The client is not
  110. * responsible for managing its memory.
  111. */
  112. LLVMOrcExecutionSessionRef LLVMOrcLLJITGetExecutionSession(LLVMOrcLLJITRef J);
  113. /**
  114. * Return a reference to the Main JITDylib.
  115. *
  116. * The JITDylib is owned by the LLJIT instance. The client is not responsible
  117. * for managing its memory.
  118. */
  119. LLVMOrcJITDylibRef LLVMOrcLLJITGetMainJITDylib(LLVMOrcLLJITRef J);
  120. /**
  121. * Return the target triple for this LLJIT instance. This string is owned by
  122. * the LLJIT instance and should not be freed by the client.
  123. */
  124. const char *LLVMOrcLLJITGetTripleString(LLVMOrcLLJITRef J);
  125. /**
  126. * Returns the global prefix character according to the LLJIT's DataLayout.
  127. */
  128. char LLVMOrcLLJITGetGlobalPrefix(LLVMOrcLLJITRef J);
  129. /**
  130. * Mangles the given string according to the LLJIT instance's DataLayout, then
  131. * interns the result in the SymbolStringPool and returns a reference to the
  132. * pool entry. Clients should call LLVMOrcReleaseSymbolStringPoolEntry to
  133. * decrement the ref-count on the pool entry once they are finished with this
  134. * value.
  135. */
  136. LLVMOrcSymbolStringPoolEntryRef
  137. LLVMOrcLLJITMangleAndIntern(LLVMOrcLLJITRef J, const char *UnmangledName);
  138. /**
  139. * Add a buffer representing an object file to the given JITDylib in the given
  140. * LLJIT instance. This operation transfers ownership of the buffer to the
  141. * LLJIT instance. The buffer should not be disposed of or referenced once this
  142. * function returns.
  143. *
  144. * Resources associated with the given object will be tracked by the given
  145. * JITDylib's default resource tracker.
  146. */
  147. LLVMErrorRef LLVMOrcLLJITAddObjectFile(LLVMOrcLLJITRef J, LLVMOrcJITDylibRef JD,
  148. LLVMMemoryBufferRef ObjBuffer);
  149. /**
  150. * Add a buffer representing an object file to the given ResourceTracker's
  151. * JITDylib in the given LLJIT instance. This operation transfers ownership of
  152. * the buffer to the LLJIT instance. The buffer should not be disposed of or
  153. * referenced once this function returns.
  154. *
  155. * Resources associated with the given object will be tracked by ResourceTracker
  156. * RT.
  157. */
  158. LLVMErrorRef LLVMOrcLLJITAddObjectFileWithRT(LLVMOrcLLJITRef J,
  159. LLVMOrcResourceTrackerRef RT,
  160. LLVMMemoryBufferRef ObjBuffer);
  161. /**
  162. * Add an IR module to the given JITDylib in the given LLJIT instance. This
  163. * operation transfers ownership of the TSM argument to the LLJIT instance.
  164. * The TSM argument should not be disposed of or referenced once this
  165. * function returns.
  166. *
  167. * Resources associated with the given Module will be tracked by the given
  168. * JITDylib's default resource tracker.
  169. */
  170. LLVMErrorRef LLVMOrcLLJITAddLLVMIRModule(LLVMOrcLLJITRef J,
  171. LLVMOrcJITDylibRef JD,
  172. LLVMOrcThreadSafeModuleRef TSM);
  173. /**
  174. * Add an IR module to the given ResourceTracker's JITDylib in the given LLJIT
  175. * instance. This operation transfers ownership of the TSM argument to the LLJIT
  176. * instance. The TSM argument should not be disposed of or referenced once this
  177. * function returns.
  178. *
  179. * Resources associated with the given Module will be tracked by ResourceTracker
  180. * RT.
  181. */
  182. LLVMErrorRef LLVMOrcLLJITAddLLVMIRModuleWithRT(LLVMOrcLLJITRef J,
  183. LLVMOrcResourceTrackerRef JD,
  184. LLVMOrcThreadSafeModuleRef TSM);
  185. /**
  186. * Look up the given symbol in the main JITDylib of the given LLJIT instance.
  187. *
  188. * This operation does not take ownership of the Name argument.
  189. */
  190. LLVMErrorRef LLVMOrcLLJITLookup(LLVMOrcLLJITRef J,
  191. LLVMOrcJITTargetAddress *Result,
  192. const char *Name);
  193. LLVM_C_EXTERN_C_END
  194. #endif /* LLVM_C_LLJIT_H */
  195. #ifdef __GNUC__
  196. #pragma GCC diagnostic pop
  197. #endif