Orc.h 48 KB

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