Orc.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. /*===---------------- llvm-c/Orc.h - OrcV2 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 libLLVMOrcJIT.a, which implements *|
  16. |* JIT compilation of LLVM IR. Minimal documentation of C API specific issues *|
  17. |* (especially memory ownership rules) is provided. Core Orc concepts are *|
  18. |* documented in llvm/docs/ORCv2.rst and APIs are documented in the C++ *|
  19. |* headers *|
  20. |* *|
  21. |* Many exotic languages can interoperate with C code but have a harder time *|
  22. |* with C++ due to name mangling. So in addition to C, this interface enables *|
  23. |* tools written in such languages. *|
  24. |* *|
  25. |* Note: This interface is experimental. It is *NOT* stable, and may be *|
  26. |* changed without warning. Only C API usage documentation is *|
  27. |* provided. See the C++ documentation for all higher level ORC API *|
  28. |* details. *|
  29. |* *|
  30. \*===----------------------------------------------------------------------===*/
  31. #ifndef LLVM_C_ORC_H
  32. #define LLVM_C_ORC_H
  33. #include "llvm-c/Error.h"
  34. #include "llvm-c/TargetMachine.h"
  35. #include "llvm-c/Types.h"
  36. LLVM_C_EXTERN_C_BEGIN
  37. /**
  38. * @defgroup LLVMCExecutionEngineORC On-Request-Compilation
  39. * @ingroup LLVMCExecutionEngine
  40. *
  41. * @{
  42. */
  43. /**
  44. * Represents an address in the executor process.
  45. */
  46. typedef uint64_t LLVMOrcJITTargetAddress;
  47. /**
  48. * Represents an address in the executor process.
  49. */
  50. typedef uint64_t LLVMOrcExecutorAddress;
  51. /**
  52. * Represents generic linkage flags for a symbol definition.
  53. */
  54. typedef enum {
  55. LLVMJITSymbolGenericFlagsExported = 1U << 0,
  56. LLVMJITSymbolGenericFlagsWeak = 1U << 1,
  57. LLVMJITSymbolGenericFlagsCallable = 1U << 2,
  58. LLVMJITSymbolGenericFlagsMaterializationSideEffectsOnly = 1U << 3
  59. } LLVMJITSymbolGenericFlags;
  60. /**
  61. * Represents target specific flags for a symbol definition.
  62. */
  63. typedef uint8_t LLVMJITSymbolTargetFlags;
  64. /**
  65. * Represents the linkage flags for a symbol definition.
  66. */
  67. typedef struct {
  68. uint8_t GenericFlags;
  69. uint8_t TargetFlags;
  70. } LLVMJITSymbolFlags;
  71. /**
  72. * Represents an evaluated symbol address and flags.
  73. */
  74. typedef struct {
  75. LLVMOrcExecutorAddress Address;
  76. LLVMJITSymbolFlags Flags;
  77. } LLVMJITEvaluatedSymbol;
  78. /**
  79. * A reference to an orc::ExecutionSession instance.
  80. */
  81. typedef struct LLVMOrcOpaqueExecutionSession *LLVMOrcExecutionSessionRef;
  82. /**
  83. * Error reporter function.
  84. */
  85. typedef void (*LLVMOrcErrorReporterFunction)(void *Ctx, LLVMErrorRef Err);
  86. /**
  87. * A reference to an orc::SymbolStringPool.
  88. */
  89. typedef struct LLVMOrcOpaqueSymbolStringPool *LLVMOrcSymbolStringPoolRef;
  90. /**
  91. * A reference to an orc::SymbolStringPool table entry.
  92. */
  93. typedef struct LLVMOrcOpaqueSymbolStringPoolEntry
  94. *LLVMOrcSymbolStringPoolEntryRef;
  95. /**
  96. * Represents a pair of a symbol name and LLVMJITSymbolFlags.
  97. */
  98. typedef struct {
  99. LLVMOrcSymbolStringPoolEntryRef Name;
  100. LLVMJITSymbolFlags Flags;
  101. } LLVMOrcCSymbolFlagsMapPair;
  102. /**
  103. * Represents a list of (SymbolStringPtr, JITSymbolFlags) pairs that can be used
  104. * to construct a SymbolFlagsMap.
  105. */
  106. typedef LLVMOrcCSymbolFlagsMapPair *LLVMOrcCSymbolFlagsMapPairs;
  107. /**
  108. * Represents a pair of a symbol name and an evaluated symbol.
  109. */
  110. typedef struct {
  111. LLVMOrcSymbolStringPoolEntryRef Name;
  112. LLVMJITEvaluatedSymbol Sym;
  113. } LLVMJITCSymbolMapPair;
  114. /**
  115. * Represents a list of (SymbolStringPtr, JITEvaluatedSymbol) pairs that can be
  116. * used to construct a SymbolMap.
  117. */
  118. typedef LLVMJITCSymbolMapPair *LLVMOrcCSymbolMapPairs;
  119. /**
  120. * Represents a SymbolAliasMapEntry
  121. */
  122. typedef struct {
  123. LLVMOrcSymbolStringPoolEntryRef Name;
  124. LLVMJITSymbolFlags Flags;
  125. } LLVMOrcCSymbolAliasMapEntry;
  126. /**
  127. * Represents a pair of a symbol name and SymbolAliasMapEntry.
  128. */
  129. typedef struct {
  130. LLVMOrcSymbolStringPoolEntryRef Name;
  131. LLVMOrcCSymbolAliasMapEntry Entry;
  132. } LLVMOrcCSymbolAliasMapPair;
  133. /**
  134. * Represents a list of (SymbolStringPtr, (SymbolStringPtr, JITSymbolFlags))
  135. * pairs that can be used to construct a SymbolFlagsMap.
  136. */
  137. typedef LLVMOrcCSymbolAliasMapPair *LLVMOrcCSymbolAliasMapPairs;
  138. /**
  139. * A reference to an orc::JITDylib instance.
  140. */
  141. typedef struct LLVMOrcOpaqueJITDylib *LLVMOrcJITDylibRef;
  142. /**
  143. * Represents a list of LLVMOrcSymbolStringPoolEntryRef and the associated
  144. * length.
  145. */
  146. typedef struct {
  147. LLVMOrcSymbolStringPoolEntryRef *Symbols;
  148. size_t Length;
  149. } LLVMOrcCSymbolsList;
  150. /**
  151. * Represents a pair of a JITDylib and LLVMOrcCSymbolsList.
  152. */
  153. typedef struct {
  154. LLVMOrcJITDylibRef JD;
  155. LLVMOrcCSymbolsList Names;
  156. } LLVMOrcCDependenceMapPair;
  157. /**
  158. * Represents a list of (JITDylibRef, (LLVMOrcSymbolStringPoolEntryRef*,
  159. * size_t)) pairs that can be used to construct a SymbolDependenceMap.
  160. */
  161. typedef LLVMOrcCDependenceMapPair *LLVMOrcCDependenceMapPairs;
  162. /**
  163. * Lookup kind. This can be used by definition generators when deciding whether
  164. * to produce a definition for a requested symbol.
  165. *
  166. * This enum should be kept in sync with llvm::orc::LookupKind.
  167. */
  168. typedef enum {
  169. LLVMOrcLookupKindStatic,
  170. LLVMOrcLookupKindDLSym
  171. } LLVMOrcLookupKind;
  172. /**
  173. * JITDylib lookup flags. This can be used by definition generators when
  174. * deciding whether to produce a definition for a requested symbol.
  175. *
  176. * This enum should be kept in sync with llvm::orc::JITDylibLookupFlags.
  177. */
  178. typedef enum {
  179. LLVMOrcJITDylibLookupFlagsMatchExportedSymbolsOnly,
  180. LLVMOrcJITDylibLookupFlagsMatchAllSymbols
  181. } LLVMOrcJITDylibLookupFlags;
  182. /**
  183. * Symbol lookup flags for lookup sets. This should be kept in sync with
  184. * llvm::orc::SymbolLookupFlags.
  185. */
  186. typedef enum {
  187. LLVMOrcSymbolLookupFlagsRequiredSymbol,
  188. LLVMOrcSymbolLookupFlagsWeaklyReferencedSymbol
  189. } LLVMOrcSymbolLookupFlags;
  190. /**
  191. * An element type for a symbol lookup set.
  192. */
  193. typedef struct {
  194. LLVMOrcSymbolStringPoolEntryRef Name;
  195. LLVMOrcSymbolLookupFlags LookupFlags;
  196. } LLVMOrcCLookupSetElement;
  197. /**
  198. * A set of symbols to look up / generate.
  199. *
  200. * The list is terminated with an element containing a null pointer for the
  201. * Name field.
  202. *
  203. * If a client creates an instance of this type then they are responsible for
  204. * freeing it, and for ensuring that all strings have been retained over the
  205. * course of its life. Clients receiving a copy from a callback are not
  206. * responsible for managing lifetime or retain counts.
  207. */
  208. typedef LLVMOrcCLookupSetElement *LLVMOrcCLookupSet;
  209. /**
  210. * A reference to a uniquely owned orc::MaterializationUnit instance.
  211. */
  212. typedef struct LLVMOrcOpaqueMaterializationUnit *LLVMOrcMaterializationUnitRef;
  213. /**
  214. * A reference to a uniquely owned orc::MaterializationResponsibility instance.
  215. *
  216. * Ownership must be passed to a lower-level layer in a JIT stack.
  217. */
  218. typedef struct LLVMOrcOpaqueMaterializationResponsibility
  219. *LLVMOrcMaterializationResponsibilityRef;
  220. /**
  221. * A MaterializationUnit materialize callback.
  222. *
  223. * Ownership of the Ctx and MR arguments passes to the callback which must
  224. * adhere to the LLVMOrcMaterializationResponsibilityRef contract (see comment
  225. * for that type).
  226. *
  227. * If this callback is called then the LLVMOrcMaterializationUnitDestroy
  228. * callback will NOT be called.
  229. */
  230. typedef void (*LLVMOrcMaterializationUnitMaterializeFunction)(
  231. void *Ctx, LLVMOrcMaterializationResponsibilityRef MR);
  232. /**
  233. * A MaterializationUnit discard callback.
  234. *
  235. * Ownership of JD and Symbol remain with the caller: These arguments should
  236. * not be disposed of or released.
  237. */
  238. typedef void (*LLVMOrcMaterializationUnitDiscardFunction)(
  239. void *Ctx, LLVMOrcJITDylibRef JD, LLVMOrcSymbolStringPoolEntryRef Symbol);
  240. /**
  241. * A MaterializationUnit destruction callback.
  242. *
  243. * If a custom MaterializationUnit is destroyed before its Materialize
  244. * function is called then this function will be called to provide an
  245. * opportunity for the underlying program representation to be destroyed.
  246. */
  247. typedef void (*LLVMOrcMaterializationUnitDestroyFunction)(void *Ctx);
  248. /**
  249. * A reference to an orc::ResourceTracker instance.
  250. */
  251. typedef struct LLVMOrcOpaqueResourceTracker *LLVMOrcResourceTrackerRef;
  252. /**
  253. * A reference to an orc::DefinitionGenerator.
  254. */
  255. typedef struct LLVMOrcOpaqueDefinitionGenerator
  256. *LLVMOrcDefinitionGeneratorRef;
  257. /**
  258. * An opaque lookup state object. Instances of this type can be captured to
  259. * suspend a lookup while a custom generator function attempts to produce a
  260. * definition.
  261. *
  262. * If a client captures a lookup state object then they must eventually call
  263. * LLVMOrcLookupStateContinueLookup to restart the lookup. This is required
  264. * in order to release memory allocated for the lookup state, even if errors
  265. * have occurred while the lookup was suspended (if these errors have made the
  266. * lookup impossible to complete then it will issue its own error before
  267. * destruction).
  268. */
  269. typedef struct LLVMOrcOpaqueLookupState *LLVMOrcLookupStateRef;
  270. /**
  271. * A custom generator function. This can be used to create a custom generator
  272. * object using LLVMOrcCreateCustomCAPIDefinitionGenerator. The resulting
  273. * object can be attached to a JITDylib, via LLVMOrcJITDylibAddGenerator, to
  274. * receive callbacks when lookups fail to match existing definitions.
  275. *
  276. * GeneratorObj will contain the address of the custom generator object.
  277. *
  278. * Ctx will contain the context object passed to
  279. * LLVMOrcCreateCustomCAPIDefinitionGenerator.
  280. *
  281. * LookupState will contain a pointer to an LLVMOrcLookupStateRef object. This
  282. * can optionally be modified to make the definition generation process
  283. * asynchronous: If the LookupStateRef value is copied, and the original
  284. * LLVMOrcLookupStateRef set to null, the lookup will be suspended. Once the
  285. * asynchronous definition process has been completed clients must call
  286. * LLVMOrcLookupStateContinueLookup to continue the lookup (this should be
  287. * done unconditionally, even if errors have occurred in the mean time, to
  288. * free the lookup state memory and notify the query object of the failures).
  289. * If LookupState is captured this function must return LLVMErrorSuccess.
  290. *
  291. * The Kind argument can be inspected to determine the lookup kind (e.g.
  292. * as-if-during-static-link, or as-if-during-dlsym).
  293. *
  294. * The JD argument specifies which JITDylib the definitions should be generated
  295. * into.
  296. *
  297. * The JDLookupFlags argument can be inspected to determine whether the original
  298. * lookup included non-exported symobls.
  299. *
  300. * Finally, the LookupSet argument contains the set of symbols that could not
  301. * be found in JD already (the set of generation candidates).
  302. */
  303. typedef LLVMErrorRef (*LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction)(
  304. LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
  305. LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind,
  306. LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags,
  307. LLVMOrcCLookupSet LookupSet, size_t LookupSetSize);
  308. /**
  309. * Predicate function for SymbolStringPoolEntries.
  310. */
  311. typedef int (*LLVMOrcSymbolPredicate)(void *Ctx,
  312. LLVMOrcSymbolStringPoolEntryRef Sym);
  313. /**
  314. * A reference to an orc::ThreadSafeContext instance.
  315. */
  316. typedef struct LLVMOrcOpaqueThreadSafeContext *LLVMOrcThreadSafeContextRef;
  317. /**
  318. * A reference to an orc::ThreadSafeModule instance.
  319. */
  320. typedef struct LLVMOrcOpaqueThreadSafeModule *LLVMOrcThreadSafeModuleRef;
  321. /**
  322. * A function for inspecting/mutating IR modules, suitable for use with
  323. * LLVMOrcThreadSafeModuleWithModuleDo.
  324. */
  325. typedef LLVMErrorRef (*LLVMOrcGenericIRModuleOperationFunction)(
  326. void *Ctx, LLVMModuleRef M);
  327. /**
  328. * A reference to an orc::JITTargetMachineBuilder instance.
  329. */
  330. typedef struct LLVMOrcOpaqueJITTargetMachineBuilder
  331. *LLVMOrcJITTargetMachineBuilderRef;
  332. /**
  333. * A reference to an orc::ObjectLayer instance.
  334. */
  335. typedef struct LLVMOrcOpaqueObjectLayer *LLVMOrcObjectLayerRef;
  336. /**
  337. * A reference to an orc::ObjectLinkingLayer instance.
  338. */
  339. typedef struct LLVMOrcOpaqueObjectLinkingLayer *LLVMOrcObjectLinkingLayerRef;
  340. /**
  341. * A reference to an orc::IRTransformLayer instance.
  342. */
  343. typedef struct LLVMOrcOpaqueIRTransformLayer *LLVMOrcIRTransformLayerRef;
  344. /**
  345. * A function for applying transformations as part of an transform layer.
  346. *
  347. * Implementations of this type are responsible for managing the lifetime
  348. * of the Module pointed to by ModInOut: If the LLVMModuleRef value is
  349. * overwritten then the function is responsible for disposing of the incoming
  350. * module. If the module is simply accessed/mutated in-place then ownership
  351. * returns to the caller and the function does not need to do any lifetime
  352. * management.
  353. *
  354. * Clients can call LLVMOrcLLJITGetIRTransformLayer to obtain the transform
  355. * layer of a LLJIT instance, and use LLVMOrcIRTransformLayerSetTransform
  356. * to set the function. This can be used to override the default transform
  357. * layer.
  358. */
  359. typedef LLVMErrorRef (*LLVMOrcIRTransformLayerTransformFunction)(
  360. void *Ctx, LLVMOrcThreadSafeModuleRef *ModInOut,
  361. LLVMOrcMaterializationResponsibilityRef MR);
  362. /**
  363. * A reference to an orc::ObjectTransformLayer instance.
  364. */
  365. typedef struct LLVMOrcOpaqueObjectTransformLayer
  366. *LLVMOrcObjectTransformLayerRef;
  367. /**
  368. * A function for applying transformations to an object file buffer.
  369. *
  370. * Implementations of this type are responsible for managing the lifetime
  371. * of the memory buffer pointed to by ObjInOut: If the LLVMMemoryBufferRef
  372. * value is overwritten then the function is responsible for disposing of the
  373. * incoming buffer. If the buffer is simply accessed/mutated in-place then
  374. * ownership returns to the caller and the function does not need to do any
  375. * lifetime management.
  376. *
  377. * The transform is allowed to return an error, in which case the ObjInOut
  378. * buffer should be disposed of and set to null.
  379. */
  380. typedef LLVMErrorRef (*LLVMOrcObjectTransformLayerTransformFunction)(
  381. void *Ctx, LLVMMemoryBufferRef *ObjInOut);
  382. /**
  383. * A reference to an orc::IndirectStubsManager instance.
  384. */
  385. typedef struct LLVMOrcOpaqueIndirectStubsManager
  386. *LLVMOrcIndirectStubsManagerRef;
  387. /**
  388. * A reference to an orc::LazyCallThroughManager instance.
  389. */
  390. typedef struct LLVMOrcOpaqueLazyCallThroughManager
  391. *LLVMOrcLazyCallThroughManagerRef;
  392. /**
  393. * A reference to an orc::DumpObjects object.
  394. *
  395. * Can be used to dump object files to disk with unique names. Useful as an
  396. * ObjectTransformLayer transform.
  397. */
  398. typedef struct LLVMOrcOpaqueDumpObjects *LLVMOrcDumpObjectsRef;
  399. /**
  400. * Attach a custom error reporter function to the ExecutionSession.
  401. *
  402. * The error reporter will be called to deliver failure notices that can not be
  403. * directly reported to a caller. For example, failure to resolve symbols in
  404. * the JIT linker is typically reported via the error reporter (callers
  405. * requesting definitions from the JIT will typically be delivered a
  406. * FailureToMaterialize error instead).
  407. */
  408. void LLVMOrcExecutionSessionSetErrorReporter(
  409. LLVMOrcExecutionSessionRef ES, LLVMOrcErrorReporterFunction ReportError,
  410. void *Ctx);
  411. /**
  412. * Return a reference to the SymbolStringPool for an ExecutionSession.
  413. *
  414. * Ownership of the pool remains with the ExecutionSession: The caller is
  415. * not required to free the pool.
  416. */
  417. LLVMOrcSymbolStringPoolRef
  418. LLVMOrcExecutionSessionGetSymbolStringPool(LLVMOrcExecutionSessionRef ES);
  419. /**
  420. * Clear all unreferenced symbol string pool entries.
  421. *
  422. * This can be called at any time to release unused entries in the
  423. * ExecutionSession's string pool. Since it locks the pool (preventing
  424. * interning of any new strings) it is recommended that it only be called
  425. * infrequently, ideally when the caller has reason to believe that some
  426. * entries will have become unreferenced, e.g. after removing a module or
  427. * closing a JITDylib.
  428. */
  429. void LLVMOrcSymbolStringPoolClearDeadEntries(LLVMOrcSymbolStringPoolRef SSP);
  430. /**
  431. * Intern a string in the ExecutionSession's SymbolStringPool and return a
  432. * reference to it. This increments the ref-count of the pool entry, and the
  433. * returned value should be released once the client is done with it by
  434. * calling LLVMOrReleaseSymbolStringPoolEntry.
  435. *
  436. * Since strings are uniqued within the SymbolStringPool
  437. * LLVMOrcSymbolStringPoolEntryRefs can be compared by value to test string
  438. * equality.
  439. *
  440. * Note that this function does not perform linker-mangling on the string.
  441. */
  442. LLVMOrcSymbolStringPoolEntryRef
  443. LLVMOrcExecutionSessionIntern(LLVMOrcExecutionSessionRef ES, const char *Name);
  444. /**
  445. * Increments the ref-count for a SymbolStringPool entry.
  446. */
  447. void LLVMOrcRetainSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S);
  448. /**
  449. * Reduces the ref-count for of a SymbolStringPool entry.
  450. */
  451. void LLVMOrcReleaseSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S);
  452. const char *LLVMOrcSymbolStringPoolEntryStr(LLVMOrcSymbolStringPoolEntryRef S);
  453. /**
  454. * Reduces the ref-count of a ResourceTracker.
  455. */
  456. void LLVMOrcReleaseResourceTracker(LLVMOrcResourceTrackerRef RT);
  457. /**
  458. * Transfers tracking of all resources associated with resource tracker SrcRT
  459. * to resource tracker DstRT.
  460. */
  461. void LLVMOrcResourceTrackerTransferTo(LLVMOrcResourceTrackerRef SrcRT,
  462. LLVMOrcResourceTrackerRef DstRT);
  463. /**
  464. * Remove all resources associated with the given tracker. See
  465. * ResourceTracker::remove().
  466. */
  467. LLVMErrorRef LLVMOrcResourceTrackerRemove(LLVMOrcResourceTrackerRef RT);
  468. /**
  469. * Dispose of a JITDylib::DefinitionGenerator. This should only be called if
  470. * ownership has not been passed to a JITDylib (e.g. because some error
  471. * prevented the client from calling LLVMOrcJITDylibAddGenerator).
  472. */
  473. void LLVMOrcDisposeDefinitionGenerator(LLVMOrcDefinitionGeneratorRef DG);
  474. /**
  475. * Dispose of a MaterializationUnit.
  476. */
  477. void LLVMOrcDisposeMaterializationUnit(LLVMOrcMaterializationUnitRef MU);
  478. /**
  479. * Create a custom MaterializationUnit.
  480. *
  481. * Name is a name for this MaterializationUnit to be used for identification
  482. * and logging purposes (e.g. if this MaterializationUnit produces an
  483. * object buffer then the name of that buffer will be derived from this name).
  484. *
  485. * The Syms list contains the names and linkages of the symbols provided by this
  486. * unit. This function takes ownership of the elements of the Syms array. The
  487. * Name fields of the array elements are taken to have been retained for this
  488. * function. The client should *not* release the elements of the array, but is
  489. * still responsible for destroyingthe array itself.
  490. *
  491. * The InitSym argument indicates whether or not this MaterializationUnit
  492. * contains static initializers. If three are no static initializers (the common
  493. * case) then this argument should be null. If there are static initializers
  494. * then InitSym should be set to a unique name that also appears in the Syms
  495. * list with the LLVMJITSymbolGenericFlagsMaterializationSideEffectsOnly flag
  496. * set. This function takes ownership of the InitSym, which should have been
  497. * retained twice on behalf of this function: once for the Syms entry and once
  498. * for InitSym. If clients wish to use the InitSym value after this function
  499. * returns they must retain it once more for themselves.
  500. *
  501. * If any of the symbols in the Syms list is looked up then the Materialize
  502. * function will be called.
  503. *
  504. * If any of the symbols in the Syms list is overridden then the Discard
  505. * function will be called.
  506. *
  507. * The caller owns the underling MaterializationUnit and is responsible for
  508. * either passing it to a JITDylib (via LLVMOrcJITDylibDefine) or disposing
  509. * of it by calling LLVMOrcDisposeMaterializationUnit.
  510. */
  511. LLVMOrcMaterializationUnitRef LLVMOrcCreateCustomMaterializationUnit(
  512. const char *Name, void *Ctx, LLVMOrcCSymbolFlagsMapPairs Syms,
  513. size_t NumSyms, LLVMOrcSymbolStringPoolEntryRef InitSym,
  514. LLVMOrcMaterializationUnitMaterializeFunction Materialize,
  515. LLVMOrcMaterializationUnitDiscardFunction Discard,
  516. LLVMOrcMaterializationUnitDestroyFunction Destroy);
  517. /**
  518. * Create a MaterializationUnit to define the given symbols as pointing to
  519. * the corresponding raw addresses.
  520. *
  521. * This function takes ownership of the elements of the Syms array. The Name
  522. * fields of the array elements are taken to have been retained for this
  523. * function. This allows the following pattern...
  524. *
  525. * size_t NumPairs;
  526. * LLVMOrcCSymbolMapPairs Sym;
  527. * -- Build Syms array --
  528. * LLVMOrcMaterializationUnitRef MU =
  529. * LLVMOrcAbsoluteSymbols(Syms, NumPairs);
  530. *
  531. * ... without requiring cleanup of the elements of the Sym array afterwards.
  532. *
  533. * The client is still responsible for deleting the Sym array itself.
  534. *
  535. * If a client wishes to reuse elements of the Sym array after this call they
  536. * must explicitly retain each of the elements for themselves.
  537. */
  538. LLVMOrcMaterializationUnitRef
  539. LLVMOrcAbsoluteSymbols(LLVMOrcCSymbolMapPairs Syms, size_t NumPairs);
  540. /**
  541. * Create a MaterializationUnit to define lazy re-expots. These are callable
  542. * entry points that call through to the given symbols.
  543. *
  544. * This function takes ownership of the CallableAliases array. The Name
  545. * fields of the array elements are taken to have been retained for this
  546. * function. This allows the following pattern...
  547. *
  548. * size_t NumPairs;
  549. * LLVMOrcCSymbolAliasMapPairs CallableAliases;
  550. * -- Build CallableAliases array --
  551. * LLVMOrcMaterializationUnitRef MU =
  552. * LLVMOrcLazyReexports(LCTM, ISM, JD, CallableAliases, NumPairs);
  553. *
  554. * ... without requiring cleanup of the elements of the CallableAliases array afterwards.
  555. *
  556. * The client is still responsible for deleting the CallableAliases array itself.
  557. *
  558. * If a client wishes to reuse elements of the CallableAliases array after this call they
  559. * must explicitly retain each of the elements for themselves.
  560. */
  561. LLVMOrcMaterializationUnitRef LLVMOrcLazyReexports(
  562. LLVMOrcLazyCallThroughManagerRef LCTM, LLVMOrcIndirectStubsManagerRef ISM,
  563. LLVMOrcJITDylibRef SourceRef, LLVMOrcCSymbolAliasMapPairs CallableAliases,
  564. size_t NumPairs);
  565. // TODO: ImplSymbolMad SrcJDLoc
  566. /**
  567. * Disposes of the passed MaterializationResponsibility object.
  568. *
  569. * This should only be done after the symbols covered by the object have either
  570. * been resolved and emitted (via
  571. * LLVMOrcMaterializationResponsibilityNotifyResolved and
  572. * LLVMOrcMaterializationResponsibilityNotifyEmitted) or failed (via
  573. * LLVMOrcMaterializationResponsibilityFailMaterialization).
  574. */
  575. void LLVMOrcDisposeMaterializationResponsibility(
  576. LLVMOrcMaterializationResponsibilityRef MR);
  577. /**
  578. * Returns the target JITDylib that these symbols are being materialized into.
  579. */
  580. LLVMOrcJITDylibRef LLVMOrcMaterializationResponsibilityGetTargetDylib(
  581. LLVMOrcMaterializationResponsibilityRef MR);
  582. /**
  583. * Returns the ExecutionSession for this MaterializationResponsibility.
  584. */
  585. LLVMOrcExecutionSessionRef
  586. LLVMOrcMaterializationResponsibilityGetExecutionSession(
  587. LLVMOrcMaterializationResponsibilityRef MR);
  588. /**
  589. * Returns the symbol flags map for this responsibility instance.
  590. *
  591. * The length of the array is returned in NumPairs and the caller is responsible
  592. * for the returned memory and needs to call LLVMOrcDisposeCSymbolFlagsMap.
  593. *
  594. * To use the returned symbols beyond the livetime of the
  595. * MaterializationResponsibility requires the caller to retain the symbols
  596. * explicitly.
  597. */
  598. LLVMOrcCSymbolFlagsMapPairs LLVMOrcMaterializationResponsibilityGetSymbols(
  599. LLVMOrcMaterializationResponsibilityRef MR, size_t *NumPairs);
  600. /**
  601. * Disposes of the passed LLVMOrcCSymbolFlagsMap.
  602. *
  603. * Does not release the entries themselves.
  604. */
  605. void LLVMOrcDisposeCSymbolFlagsMap(LLVMOrcCSymbolFlagsMapPairs Pairs);
  606. /**
  607. * Returns the initialization pseudo-symbol, if any. This symbol will also
  608. * be present in the SymbolFlagsMap for this MaterializationResponsibility
  609. * object.
  610. *
  611. * The returned symbol is not retained over any mutating operation of the
  612. * MaterializationResponsbility or beyond the lifetime thereof.
  613. */
  614. LLVMOrcSymbolStringPoolEntryRef
  615. LLVMOrcMaterializationResponsibilityGetInitializerSymbol(
  616. LLVMOrcMaterializationResponsibilityRef MR);
  617. /**
  618. * Returns the names of any symbols covered by this
  619. * MaterializationResponsibility object that have queries pending. This
  620. * information can be used to return responsibility for unrequested symbols
  621. * back to the JITDylib via the delegate method.
  622. */
  623. LLVMOrcSymbolStringPoolEntryRef *
  624. LLVMOrcMaterializationResponsibilityGetRequestedSymbols(
  625. LLVMOrcMaterializationResponsibilityRef MR, size_t *NumSymbols);
  626. /**
  627. * Disposes of the passed LLVMOrcSymbolStringPoolEntryRef* .
  628. *
  629. * Does not release the symbols themselves.
  630. */
  631. void LLVMOrcDisposeSymbols(LLVMOrcSymbolStringPoolEntryRef *Symbols);
  632. /*
  633. * Notifies the target JITDylib that the given symbols have been resolved.
  634. * This will update the given symbols' addresses in the JITDylib, and notify
  635. * any pending queries on the given symbols of their resolution. The given
  636. * symbols must be ones covered by this MaterializationResponsibility
  637. * instance. Individual calls to this method may resolve a subset of the
  638. * symbols, but all symbols must have been resolved prior to calling emit.
  639. *
  640. * This method will return an error if any symbols being resolved have been
  641. * moved to the error state due to the failure of a dependency. If this
  642. * method returns an error then clients should log it and call
  643. * LLVMOrcMaterializationResponsibilityFailMaterialization. If no dependencies
  644. * have been registered for the symbols covered by this
  645. * MaterializationResponsibiility then this method is guaranteed to return
  646. * LLVMErrorSuccess.
  647. */
  648. LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyResolved(
  649. LLVMOrcMaterializationResponsibilityRef MR, LLVMOrcCSymbolMapPairs Symbols,
  650. size_t NumPairs);
  651. /**
  652. * Notifies the target JITDylib (and any pending queries on that JITDylib)
  653. * that all symbols covered by this MaterializationResponsibility instance
  654. * have been emitted.
  655. *
  656. * This method will return an error if any symbols being resolved have been
  657. * moved to the error state due to the failure of a dependency. If this
  658. * method returns an error then clients should log it and call
  659. * LLVMOrcMaterializationResponsibilityFailMaterialization.
  660. * If no dependencies have been registered for the symbols covered by this
  661. * MaterializationResponsibiility then this method is guaranteed to return
  662. * LLVMErrorSuccess.
  663. */
  664. LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyEmitted(
  665. LLVMOrcMaterializationResponsibilityRef MR);
  666. /**
  667. * Attempt to claim responsibility for new definitions. This method can be
  668. * used to claim responsibility for symbols that are added to a
  669. * materialization unit during the compilation process (e.g. literal pool
  670. * symbols). Symbol linkage rules are the same as for symbols that are
  671. * defined up front: duplicate strong definitions will result in errors.
  672. * Duplicate weak definitions will be discarded (in which case they will
  673. * not be added to this responsibility instance).
  674. *
  675. * This method can be used by materialization units that want to add
  676. * additional symbols at materialization time (e.g. stubs, compile
  677. * callbacks, metadata)
  678. */
  679. LLVMErrorRef LLVMOrcMaterializationResponsibilityDefineMaterializing(
  680. LLVMOrcMaterializationResponsibilityRef MR,
  681. LLVMOrcCSymbolFlagsMapPairs Pairs, size_t NumPairs);
  682. /**
  683. * Notify all not-yet-emitted covered by this MaterializationResponsibility
  684. * instance that an error has occurred.
  685. * This will remove all symbols covered by this MaterializationResponsibilty
  686. * from the target JITDylib, and send an error to any queries waiting on
  687. * these symbols.
  688. */
  689. void LLVMOrcMaterializationResponsibilityFailMaterialization(
  690. LLVMOrcMaterializationResponsibilityRef MR);
  691. /**
  692. * Transfers responsibility to the given MaterializationUnit for all
  693. * symbols defined by that MaterializationUnit. This allows
  694. * materializers to break up work based on run-time information (e.g.
  695. * by introspecting which symbols have actually been looked up and
  696. * materializing only those).
  697. */
  698. LLVMErrorRef LLVMOrcMaterializationResponsibilityReplace(
  699. LLVMOrcMaterializationResponsibilityRef MR,
  700. LLVMOrcMaterializationUnitRef MU);
  701. /**
  702. * Delegates responsibility for the given symbols to the returned
  703. * materialization responsibility. Useful for breaking up work between
  704. * threads, or different kinds of materialization processes.
  705. *
  706. * The caller retains responsibility of the the passed
  707. * MaterializationResponsibility.
  708. */
  709. LLVMErrorRef LLVMOrcMaterializationResponsibilityDelegate(
  710. LLVMOrcMaterializationResponsibilityRef MR,
  711. LLVMOrcSymbolStringPoolEntryRef *Symbols, size_t NumSymbols,
  712. LLVMOrcMaterializationResponsibilityRef *Result);
  713. /**
  714. * Adds dependencies to a symbol that the MaterializationResponsibility is
  715. * responsible for.
  716. *
  717. * This function takes ownership of Dependencies struct. The Names
  718. * array have been retained for this function. This allows the following
  719. * pattern...
  720. *
  721. * LLVMOrcSymbolStringPoolEntryRef Names[] = {...};
  722. * LLVMOrcCDependenceMapPair Dependence = {JD, {Names, sizeof(Names)}}
  723. * LLVMOrcMaterializationResponsibilityAddDependencies(JD, Name, &Dependence,
  724. * 1);
  725. *
  726. * ... without requiring cleanup of the elements of the Names array afterwards.
  727. *
  728. * The client is still responsible for deleting the Dependencies.Names array
  729. * itself.
  730. */
  731. void LLVMOrcMaterializationResponsibilityAddDependencies(
  732. LLVMOrcMaterializationResponsibilityRef MR,
  733. LLVMOrcSymbolStringPoolEntryRef Name,
  734. LLVMOrcCDependenceMapPairs Dependencies, size_t NumPairs);
  735. /**
  736. * Adds dependencies to all symbols that the MaterializationResponsibility is
  737. * responsible for. See LLVMOrcMaterializationResponsibilityAddDependencies for
  738. * notes about memory responsibility.
  739. */
  740. void LLVMOrcMaterializationResponsibilityAddDependenciesForAll(
  741. LLVMOrcMaterializationResponsibilityRef MR,
  742. LLVMOrcCDependenceMapPairs Dependencies, size_t NumPairs);
  743. /**
  744. * Create a "bare" JITDylib.
  745. *
  746. * The client is responsible for ensuring that the JITDylib's name is unique,
  747. * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first.
  748. *
  749. * This call does not install any library code or symbols into the newly
  750. * created JITDylib. The client is responsible for all configuration.
  751. */
  752. LLVMOrcJITDylibRef
  753. LLVMOrcExecutionSessionCreateBareJITDylib(LLVMOrcExecutionSessionRef ES,
  754. const char *Name);
  755. /**
  756. * Create a JITDylib.
  757. *
  758. * The client is responsible for ensuring that the JITDylib's name is unique,
  759. * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first.
  760. *
  761. * If a Platform is attached to the ExecutionSession then
  762. * Platform::setupJITDylib will be called to install standard platform symbols
  763. * (e.g. standard library interposes). If no Platform is installed then this
  764. * call is equivalent to LLVMExecutionSessionRefCreateBareJITDylib and will
  765. * always return success.
  766. */
  767. LLVMErrorRef
  768. LLVMOrcExecutionSessionCreateJITDylib(LLVMOrcExecutionSessionRef ES,
  769. LLVMOrcJITDylibRef *Result,
  770. const char *Name);
  771. /**
  772. * Returns the JITDylib with the given name, or NULL if no such JITDylib
  773. * exists.
  774. */
  775. LLVMOrcJITDylibRef
  776. LLVMOrcExecutionSessionGetJITDylibByName(LLVMOrcExecutionSessionRef ES,
  777. const char *Name);
  778. /**
  779. * Return a reference to a newly created resource tracker associated with JD.
  780. * The tracker is returned with an initial ref-count of 1, and must be released
  781. * with LLVMOrcReleaseResourceTracker when no longer needed.
  782. */
  783. LLVMOrcResourceTrackerRef
  784. LLVMOrcJITDylibCreateResourceTracker(LLVMOrcJITDylibRef JD);
  785. /**
  786. * Return a reference to the default resource tracker for the given JITDylib.
  787. * This operation will increase the retain count of the tracker: Clients should
  788. * call LLVMOrcReleaseResourceTracker when the result is no longer needed.
  789. */
  790. LLVMOrcResourceTrackerRef
  791. LLVMOrcJITDylibGetDefaultResourceTracker(LLVMOrcJITDylibRef JD);
  792. /**
  793. * Add the given MaterializationUnit to the given JITDylib.
  794. *
  795. * If this operation succeeds then JITDylib JD will take ownership of MU.
  796. * If the operation fails then ownership remains with the caller who should
  797. * call LLVMOrcDisposeMaterializationUnit to destroy it.
  798. */
  799. LLVMErrorRef LLVMOrcJITDylibDefine(LLVMOrcJITDylibRef JD,
  800. LLVMOrcMaterializationUnitRef MU);
  801. /**
  802. * Calls remove on all trackers associated with this JITDylib, see
  803. * JITDylib::clear().
  804. */
  805. LLVMErrorRef LLVMOrcJITDylibClear(LLVMOrcJITDylibRef JD);
  806. /**
  807. * Add a DefinitionGenerator to the given JITDylib.
  808. *
  809. * The JITDylib will take ownership of the given generator: The client is no
  810. * longer responsible for managing its memory.
  811. */
  812. void LLVMOrcJITDylibAddGenerator(LLVMOrcJITDylibRef JD,
  813. LLVMOrcDefinitionGeneratorRef DG);
  814. /**
  815. * Create a custom generator.
  816. */
  817. LLVMOrcDefinitionGeneratorRef LLVMOrcCreateCustomCAPIDefinitionGenerator(
  818. LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction F, void *Ctx);
  819. /**
  820. * Get a DynamicLibrarySearchGenerator that will reflect process symbols into
  821. * the JITDylib. On success the resulting generator is owned by the client.
  822. * Ownership is typically transferred by adding the instance to a JITDylib
  823. * using LLVMOrcJITDylibAddGenerator,
  824. *
  825. * The GlobalPrefix argument specifies the character that appears on the front
  826. * of linker-mangled symbols for the target platform (e.g. '_' on MachO).
  827. * If non-null, this character will be stripped from the start of all symbol
  828. * strings before passing the remaining substring to dlsym.
  829. *
  830. * The optional Filter and Ctx arguments can be used to supply a symbol name
  831. * filter: Only symbols for which the filter returns true will be visible to
  832. * JIT'd code. If the Filter argument is null then all process symbols will
  833. * be visible to JIT'd code. Note that the symbol name passed to the Filter
  834. * function is the full mangled symbol: The client is responsible for stripping
  835. * the global prefix if present.
  836. */
  837. LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess(
  838. LLVMOrcDefinitionGeneratorRef *Result, char GlobalPrefx,
  839. LLVMOrcSymbolPredicate Filter, void *FilterCtx);
  840. /**
  841. * Get a LLVMOrcCreateDynamicLibararySearchGeneratorForPath that will reflect
  842. * library symbols into the JITDylib. On success the resulting generator is
  843. * owned by the client. Ownership is typically transferred by adding the
  844. * instance to a JITDylib using LLVMOrcJITDylibAddGenerator,
  845. *
  846. * The GlobalPrefix argument specifies the character that appears on the front
  847. * of linker-mangled symbols for the target platform (e.g. '_' on MachO).
  848. * If non-null, this character will be stripped from the start of all symbol
  849. * strings before passing the remaining substring to dlsym.
  850. *
  851. * The optional Filter and Ctx arguments can be used to supply a symbol name
  852. * filter: Only symbols for which the filter returns true will be visible to
  853. * JIT'd code. If the Filter argument is null then all library symbols will
  854. * be visible to JIT'd code. Note that the symbol name passed to the Filter
  855. * function is the full mangled symbol: The client is responsible for stripping
  856. * the global prefix if present.
  857. *
  858. * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE!
  859. *
  860. */
  861. LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForPath(
  862. LLVMOrcDefinitionGeneratorRef *Result, const char *FileName,
  863. char GlobalPrefix, LLVMOrcSymbolPredicate Filter, void *FilterCtx);
  864. /**
  865. * Get a LLVMOrcCreateStaticLibrarySearchGeneratorForPath that will reflect
  866. * static library symbols into the JITDylib. On success the resulting
  867. * generator is owned by the client. Ownership is typically transferred by
  868. * adding the instance to a JITDylib using LLVMOrcJITDylibAddGenerator,
  869. *
  870. * Call with the optional TargetTriple argument will succeed if the file at
  871. * the given path is a static library or a MachO universal binary containing a
  872. * static library that is compatible with the given triple. Otherwise it will
  873. * return an error.
  874. *
  875. * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE!
  876. *
  877. */
  878. LLVMErrorRef LLVMOrcCreateStaticLibrarySearchGeneratorForPath(
  879. LLVMOrcDefinitionGeneratorRef *Result, LLVMOrcObjectLayerRef ObjLayer,
  880. const char *FileName, const char *TargetTriple);
  881. /**
  882. * Create a ThreadSafeContext containing a new LLVMContext.
  883. *
  884. * Ownership of the underlying ThreadSafeContext data is shared: Clients
  885. * can and should dispose of their ThreadSafeContext as soon as they no longer
  886. * need to refer to it directly. Other references (e.g. from ThreadSafeModules)
  887. * will keep the data alive as long as it is needed.
  888. */
  889. LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void);
  890. /**
  891. * Get a reference to the wrapped LLVMContext.
  892. */
  893. LLVMContextRef
  894. LLVMOrcThreadSafeContextGetContext(LLVMOrcThreadSafeContextRef TSCtx);
  895. /**
  896. * Dispose of a ThreadSafeContext.
  897. */
  898. void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx);
  899. /**
  900. * Create a ThreadSafeModule wrapper around the given LLVM module. This takes
  901. * ownership of the M argument which should not be disposed of or referenced
  902. * after this function returns.
  903. *
  904. * Ownership of the ThreadSafeModule is unique: If it is transferred to the JIT
  905. * (e.g. by LLVMOrcLLJITAddLLVMIRModule) then the client is no longer
  906. * responsible for it. If it is not transferred to the JIT then the client
  907. * should call LLVMOrcDisposeThreadSafeModule to dispose of it.
  908. */
  909. LLVMOrcThreadSafeModuleRef
  910. LLVMOrcCreateNewThreadSafeModule(LLVMModuleRef M,
  911. LLVMOrcThreadSafeContextRef TSCtx);
  912. /**
  913. * Dispose of a ThreadSafeModule. This should only be called if ownership has
  914. * not been passed to LLJIT (e.g. because some error prevented the client from
  915. * adding this to the JIT).
  916. */
  917. void LLVMOrcDisposeThreadSafeModule(LLVMOrcThreadSafeModuleRef TSM);
  918. /**
  919. * Apply the given function to the module contained in this ThreadSafeModule.
  920. */
  921. LLVMErrorRef
  922. LLVMOrcThreadSafeModuleWithModuleDo(LLVMOrcThreadSafeModuleRef TSM,
  923. LLVMOrcGenericIRModuleOperationFunction F,
  924. void *Ctx);
  925. /**
  926. * Create a JITTargetMachineBuilder by detecting the host.
  927. *
  928. * On success the client owns the resulting JITTargetMachineBuilder. It must be
  929. * passed to a consuming operation (e.g.
  930. * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling
  931. * LLVMOrcDisposeJITTargetMachineBuilder.
  932. */
  933. LLVMErrorRef LLVMOrcJITTargetMachineBuilderDetectHost(
  934. LLVMOrcJITTargetMachineBuilderRef *Result);
  935. /**
  936. * Create a JITTargetMachineBuilder from the given TargetMachine template.
  937. *
  938. * This operation takes ownership of the given TargetMachine and destroys it
  939. * before returing. The resulting JITTargetMachineBuilder is owned by the client
  940. * and must be passed to a consuming operation (e.g.
  941. * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling
  942. * LLVMOrcDisposeJITTargetMachineBuilder.
  943. */
  944. LLVMOrcJITTargetMachineBuilderRef
  945. LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(LLVMTargetMachineRef TM);
  946. /**
  947. * Dispose of a JITTargetMachineBuilder.
  948. */
  949. void LLVMOrcDisposeJITTargetMachineBuilder(
  950. LLVMOrcJITTargetMachineBuilderRef JTMB);
  951. /**
  952. * Returns the target triple for the given JITTargetMachineBuilder as a string.
  953. *
  954. * The caller owns the resulting string as must dispose of it by calling
  955. * LLVMDisposeMessage
  956. */
  957. char *LLVMOrcJITTargetMachineBuilderGetTargetTriple(
  958. LLVMOrcJITTargetMachineBuilderRef JTMB);
  959. /**
  960. * Sets the target triple for the given JITTargetMachineBuilder to the given
  961. * string.
  962. */
  963. void LLVMOrcJITTargetMachineBuilderSetTargetTriple(
  964. LLVMOrcJITTargetMachineBuilderRef JTMB, const char *TargetTriple);
  965. /**
  966. * Add an object to an ObjectLayer to the given JITDylib.
  967. *
  968. * Adds a buffer representing an object file to the given JITDylib using the
  969. * given ObjectLayer instance. This operation transfers ownership of the buffer
  970. * to the ObjectLayer instance. The buffer should not be disposed of or
  971. * referenced once this function returns.
  972. *
  973. * Resources associated with the given object will be tracked by the given
  974. * JITDylib's default ResourceTracker.
  975. */
  976. LLVMErrorRef LLVMOrcObjectLayerAddObjectFile(LLVMOrcObjectLayerRef ObjLayer,
  977. LLVMOrcJITDylibRef JD,
  978. LLVMMemoryBufferRef ObjBuffer);
  979. /**
  980. * Add an object to an ObjectLayer using the given ResourceTracker.
  981. *
  982. * Adds a buffer representing an object file to the given ResourceTracker's
  983. * JITDylib using the given ObjectLayer instance. This operation transfers
  984. * ownership of the buffer to the ObjectLayer instance. The buffer should not
  985. * be disposed of or referenced once this function returns.
  986. *
  987. * Resources associated with the given object will be tracked by
  988. * ResourceTracker RT.
  989. */
  990. LLVMErrorRef
  991. LLVMOrcObjectLayerAddObjectFileWithRT(LLVMOrcObjectLayerRef ObjLayer,
  992. LLVMOrcResourceTrackerRef RT,
  993. LLVMMemoryBufferRef ObjBuffer);
  994. /**
  995. * Emit an object buffer to an ObjectLayer.
  996. *
  997. * Ownership of the responsibility object and object buffer pass to this
  998. * function. The client is not responsible for cleanup.
  999. */
  1000. void LLVMOrcObjectLayerEmit(LLVMOrcObjectLayerRef ObjLayer,
  1001. LLVMOrcMaterializationResponsibilityRef R,
  1002. LLVMMemoryBufferRef ObjBuffer);
  1003. /**
  1004. * Dispose of an ObjectLayer.
  1005. */
  1006. void LLVMOrcDisposeObjectLayer(LLVMOrcObjectLayerRef ObjLayer);
  1007. void LLVMOrcIRTransformLayerEmit(LLVMOrcIRTransformLayerRef IRTransformLayer,
  1008. LLVMOrcMaterializationResponsibilityRef MR,
  1009. LLVMOrcThreadSafeModuleRef TSM);
  1010. /**
  1011. * Set the transform function of the provided transform layer, passing through a
  1012. * pointer to user provided context.
  1013. */
  1014. void LLVMOrcIRTransformLayerSetTransform(
  1015. LLVMOrcIRTransformLayerRef IRTransformLayer,
  1016. LLVMOrcIRTransformLayerTransformFunction TransformFunction, void *Ctx);
  1017. /**
  1018. * Set the transform function on an LLVMOrcObjectTransformLayer.
  1019. */
  1020. void LLVMOrcObjectTransformLayerSetTransform(
  1021. LLVMOrcObjectTransformLayerRef ObjTransformLayer,
  1022. LLVMOrcObjectTransformLayerTransformFunction TransformFunction, void *Ctx);
  1023. /**
  1024. * Create a LocalIndirectStubsManager from the given target triple.
  1025. *
  1026. * The resulting IndirectStubsManager is owned by the client
  1027. * and must be disposed of by calling LLVMOrcDisposeDisposeIndirectStubsManager.
  1028. */
  1029. LLVMOrcIndirectStubsManagerRef
  1030. LLVMOrcCreateLocalIndirectStubsManager(const char *TargetTriple);
  1031. /**
  1032. * Dispose of an IndirectStubsManager.
  1033. */
  1034. void LLVMOrcDisposeIndirectStubsManager(LLVMOrcIndirectStubsManagerRef ISM);
  1035. LLVMErrorRef LLVMOrcCreateLocalLazyCallThroughManager(
  1036. const char *TargetTriple, LLVMOrcExecutionSessionRef ES,
  1037. LLVMOrcJITTargetAddress ErrorHandlerAddr,
  1038. LLVMOrcLazyCallThroughManagerRef *LCTM);
  1039. /**
  1040. * Dispose of an LazyCallThroughManager.
  1041. */
  1042. void LLVMOrcDisposeLazyCallThroughManager(
  1043. LLVMOrcLazyCallThroughManagerRef LCTM);
  1044. /**
  1045. * Create a DumpObjects instance.
  1046. *
  1047. * DumpDir specifies the path to write dumped objects to. DumpDir may be empty
  1048. * in which case files will be dumped to the working directory.
  1049. *
  1050. * IdentifierOverride specifies a file name stem to use when dumping objects.
  1051. * If empty then each MemoryBuffer's identifier will be used (with a .o suffix
  1052. * added if not already present). If an identifier override is supplied it will
  1053. * be used instead, along with an incrementing counter (since all buffers will
  1054. * use the same identifier, the resulting files will be named <ident>.o,
  1055. * <ident>.2.o, <ident>.3.o, and so on). IdentifierOverride should not contain
  1056. * an extension, as a .o suffix will be added by DumpObjects.
  1057. */
  1058. LLVMOrcDumpObjectsRef LLVMOrcCreateDumpObjects(const char *DumpDir,
  1059. const char *IdentifierOverride);
  1060. /**
  1061. * Dispose of a DumpObjects instance.
  1062. */
  1063. void LLVMOrcDisposeDumpObjects(LLVMOrcDumpObjectsRef DumpObjects);
  1064. /**
  1065. * Dump the contents of the given MemoryBuffer.
  1066. */
  1067. LLVMErrorRef LLVMOrcDumpObjects_CallOperator(LLVMOrcDumpObjectsRef DumpObjects,
  1068. LLVMMemoryBufferRef *ObjBuffer);
  1069. /**
  1070. * @}
  1071. */
  1072. LLVM_C_EXTERN_C_END
  1073. #endif /* LLVM_C_ORC_H */
  1074. #ifdef __GNUC__
  1075. #pragma GCC diagnostic pop
  1076. #endif