[DAGCombiner] Add target hook function to decide folding (mul (add x, c1), c2)
[llvm-project.git] / llvm / include / llvm-c / Orc.h
blob1790afbcecc774314f0253afba8964aa0b391ecb
1 /*===---------------- llvm-c/Orc.h - OrcV2 C bindings -----------*- C++ -*-===*\
2 |* *|
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 |* Exceptions. *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This header declares the C interface to libLLVMOrcJIT.a, which implements *|
11 |* JIT compilation of LLVM IR. Minimal documentation of C API specific issues *|
12 |* (especially memory ownership rules) is provided. Core Orc concepts are *|
13 |* documented in llvm/docs/ORCv2.rst and APIs are documented in the C++ *|
14 |* headers *|
15 |* *|
16 |* Many exotic languages can interoperate with C code but have a harder time *|
17 |* with C++ due to name mangling. So in addition to C, this interface enables *|
18 |* tools written in such languages. *|
19 |* *|
20 |* Note: This interface is experimental. It is *NOT* stable, and may be *|
21 |* changed without warning. Only C API usage documentation is *|
22 |* provided. See the C++ documentation for all higher level ORC API *|
23 |* details. *|
24 |* *|
25 \*===----------------------------------------------------------------------===*/
27 #ifndef LLVM_C_ORC_H
28 #define LLVM_C_ORC_H
30 #include "llvm-c/Error.h"
31 #include "llvm-c/TargetMachine.h"
32 #include "llvm-c/Types.h"
34 LLVM_C_EXTERN_C_BEGIN
36 /**
37 * Represents an address in the executor process.
39 typedef uint64_t LLVMOrcJITTargetAddress;
41 /**
42 * Represents an address in the executor process.
44 typedef uint64_t LLVMOrcExecutorAddress;
46 /**
47 * Represents generic linkage flags for a symbol definition.
49 typedef enum {
50 LLVMJITSymbolGenericFlagsExported = 1U << 0,
51 LLVMJITSymbolGenericFlagsWeak = 1U << 1,
52 LLVMJITSymbolGenericFlagsCallable = 1U << 2,
53 LLVMJITSymbolGenericFlagsMaterializationSideEffectsOnly = 1U << 3
54 } LLVMJITSymbolGenericFlags;
56 /**
57 * Represents target specific flags for a symbol definition.
59 typedef uint8_t LLVMJITSymbolTargetFlags;
61 /**
62 * Represents the linkage flags for a symbol definition.
64 typedef struct {
65 uint8_t GenericFlags;
66 uint8_t TargetFlags;
67 } LLVMJITSymbolFlags;
69 /**
70 * Represents an evaluated symbol address and flags.
72 typedef struct {
73 LLVMOrcExecutorAddress Address;
74 LLVMJITSymbolFlags Flags;
75 } LLVMJITEvaluatedSymbol;
77 /**
78 * A reference to an orc::ExecutionSession instance.
80 typedef struct LLVMOrcOpaqueExecutionSession *LLVMOrcExecutionSessionRef;
82 /**
83 * Error reporter function.
85 typedef void (*LLVMOrcErrorReporterFunction)(void *Ctx, LLVMErrorRef Err);
87 /**
88 * A reference to an orc::SymbolStringPool.
90 typedef struct LLVMOrcOpaqueSymbolStringPool *LLVMOrcSymbolStringPoolRef;
92 /**
93 * A reference to an orc::SymbolStringPool table entry.
95 typedef struct LLVMOrcOpaqueSymbolStringPoolEntry
96 *LLVMOrcSymbolStringPoolEntryRef;
98 /**
99 * Represents a pair of a symbol name and LLVMJITSymbolFlags.
101 typedef struct {
102 LLVMOrcSymbolStringPoolEntryRef Name;
103 LLVMJITSymbolFlags Flags;
104 } LLVMOrcCSymbolFlagsMapPair;
107 * Represents a list of (SymbolStringPtr, JITSymbolFlags) pairs that can be used
108 * to construct a SymbolFlagsMap.
110 typedef LLVMOrcCSymbolFlagsMapPair *LLVMOrcCSymbolFlagsMapPairs;
113 * Represents a pair of a symbol name and an evaluated symbol.
115 typedef struct {
116 LLVMOrcSymbolStringPoolEntryRef Name;
117 LLVMJITEvaluatedSymbol Sym;
118 } LLVMJITCSymbolMapPair;
121 * Represents a list of (SymbolStringPtr, JITEvaluatedSymbol) pairs that can be
122 * used to construct a SymbolMap.
124 typedef LLVMJITCSymbolMapPair *LLVMOrcCSymbolMapPairs;
127 * Represents a SymbolAliasMapEntry
129 typedef struct {
130 LLVMOrcSymbolStringPoolEntryRef Name;
131 LLVMJITSymbolFlags Flags;
132 } LLVMOrcCSymbolAliasMapEntry;
135 * Represents a pair of a symbol name and SymbolAliasMapEntry.
137 typedef struct {
138 LLVMOrcSymbolStringPoolEntryRef Name;
139 LLVMOrcCSymbolAliasMapEntry Entry;
140 } LLVMOrcCSymbolAliasMapPair;
143 * Represents a list of (SymbolStringPtr, (SymbolStringPtr, JITSymbolFlags))
144 * pairs that can be used to construct a SymbolFlagsMap.
146 typedef LLVMOrcCSymbolAliasMapPair *LLVMOrcCSymbolAliasMapPairs;
149 * A reference to an orc::JITDylib instance.
151 typedef struct LLVMOrcOpaqueJITDylib *LLVMOrcJITDylibRef;
154 * Represents a list of LLVMOrcSymbolStringPoolEntryRef and the associated
155 * length.
157 typedef struct {
158 LLVMOrcSymbolStringPoolEntryRef *Symbols;
159 size_t Length;
160 } LLVMOrcCSymbolsList;
163 * Represents a pair of a JITDylib and LLVMOrcCSymbolsList.
165 typedef struct {
166 LLVMOrcJITDylibRef JD;
167 LLVMOrcCSymbolsList Names;
168 } LLVMOrcCDependenceMapPair;
171 * Represents a list of (JITDylibRef, (LLVMOrcSymbolStringPoolEntryRef*,
172 * size_t)) pairs that can be used to construct a SymbolDependenceMap.
174 typedef LLVMOrcCDependenceMapPair *LLVMOrcCDependenceMapPairs;
177 * Lookup kind. This can be used by definition generators when deciding whether
178 * to produce a definition for a requested symbol.
180 * This enum should be kept in sync with llvm::orc::LookupKind.
182 typedef enum {
183 LLVMOrcLookupKindStatic,
184 LLVMOrcLookupKindDLSym
185 } LLVMOrcLookupKind;
188 * JITDylib lookup flags. This can be used by definition generators when
189 * deciding whether to produce a definition for a requested symbol.
191 * This enum should be kept in sync with llvm::orc::JITDylibLookupFlags.
193 typedef enum {
194 LLVMOrcJITDylibLookupFlagsMatchExportedSymbolsOnly,
195 LLVMOrcJITDylibLookupFlagsMatchAllSymbols
196 } LLVMOrcJITDylibLookupFlags;
199 * Symbol lookup flags for lookup sets. This should be kept in sync with
200 * llvm::orc::SymbolLookupFlags.
202 typedef enum {
203 LLVMOrcSymbolLookupFlagsRequiredSymbol,
204 LLVMOrcSymbolLookupFlagsWeaklyReferencedSymbol
205 } LLVMOrcSymbolLookupFlags;
208 * An element type for a symbol lookup set.
210 typedef struct {
211 LLVMOrcSymbolStringPoolEntryRef Name;
212 LLVMOrcSymbolLookupFlags LookupFlags;
213 } LLVMOrcCLookupSetElement;
216 * A set of symbols to look up / generate.
218 * The list is terminated with an element containing a null pointer for the
219 * Name field.
221 * If a client creates an instance of this type then they are responsible for
222 * freeing it, and for ensuring that all strings have been retained over the
223 * course of its life. Clients receiving a copy from a callback are not
224 * responsible for managing lifetime or retain counts.
226 typedef LLVMOrcCLookupSetElement *LLVMOrcCLookupSet;
229 * A reference to a uniquely owned orc::MaterializationUnit instance.
231 typedef struct LLVMOrcOpaqueMaterializationUnit *LLVMOrcMaterializationUnitRef;
234 * A reference to a uniquely owned orc::MaterializationResponsibility instance.
236 * Ownership must be passed to a lower-level layer in a JIT stack.
238 typedef struct LLVMOrcOpaqueMaterializationResponsibility
239 *LLVMOrcMaterializationResponsibilityRef;
242 * A MaterializationUnit materialize callback.
244 * Ownership of the Ctx and MR arguments passes to the callback which must
245 * adhere to the LLVMOrcMaterializationResponsibilityRef contract (see comment
246 * for that type).
248 * If this callback is called then the LLVMOrcMaterializationUnitDestroy
249 * callback will NOT be called.
251 typedef void (*LLVMOrcMaterializationUnitMaterializeFunction)(
252 void *Ctx, LLVMOrcMaterializationResponsibilityRef MR);
255 * A MaterializationUnit discard callback.
257 * Ownership of JD and Symbol remain with the caller: These arguments should
258 * not be disposed of or released.
260 typedef void (*LLVMOrcMaterializationUnitDiscardFunction)(
261 void *Ctx, LLVMOrcJITDylibRef JD, LLVMOrcSymbolStringPoolEntryRef Symbol);
264 * A MaterializationUnit destruction callback.
266 * If a custom MaterializationUnit is destroyed before its Materialize
267 * function is called then this function will be called to provide an
268 * opportunity for the underlying program representation to be destroyed.
270 typedef void (*LLVMOrcMaterializationUnitDestroyFunction)(void *Ctx);
273 * A reference to an orc::ResourceTracker instance.
275 typedef struct LLVMOrcOpaqueResourceTracker *LLVMOrcResourceTrackerRef;
278 * A reference to an orc::DefinitionGenerator.
280 typedef struct LLVMOrcOpaqueDefinitionGenerator
281 *LLVMOrcDefinitionGeneratorRef;
284 * An opaque lookup state object. Instances of this type can be captured to
285 * suspend a lookup while a custom generator function attempts to produce a
286 * definition.
288 * If a client captures a lookup state object then they must eventually call
289 * LLVMOrcLookupStateContinueLookup to restart the lookup. This is required
290 * in order to release memory allocated for the lookup state, even if errors
291 * have occurred while the lookup was suspended (if these errors have made the
292 * lookup impossible to complete then it will issue its own error before
293 * destruction).
295 typedef struct LLVMOrcOpaqueLookupState *LLVMOrcLookupStateRef;
298 * A custom generator function. This can be used to create a custom generator
299 * object using LLVMOrcCreateCustomCAPIDefinitionGenerator. The resulting
300 * object can be attached to a JITDylib, via LLVMOrcJITDylibAddGenerator, to
301 * receive callbacks when lookups fail to match existing definitions.
303 * GeneratorObj will contain the address of the custom generator object.
305 * Ctx will contain the context object passed to
306 * LLVMOrcCreateCustomCAPIDefinitionGenerator.
308 * LookupState will contain a pointer to an LLVMOrcLookupStateRef object. This
309 * can optionally be modified to make the definition generation process
310 * asynchronous: If the LookupStateRef value is copied, and the original
311 * LLVMOrcLookupStateRef set to null, the lookup will be suspended. Once the
312 * asynchronous definition process has been completed clients must call
313 * LLVMOrcLookupStateContinueLookup to continue the lookup (this should be
314 * done unconditionally, even if errors have occurred in the mean time, to
315 * free the lookup state memory and notify the query object of the failures).
316 * If LookupState is captured this function must return LLVMErrorSuccess.
318 * The Kind argument can be inspected to determine the lookup kind (e.g.
319 * as-if-during-static-link, or as-if-during-dlsym).
321 * The JD argument specifies which JITDylib the definitions should be generated
322 * into.
324 * The JDLookupFlags argument can be inspected to determine whether the original
325 * lookup included non-exported symobls.
327 * Finally, the LookupSet argument contains the set of symbols that could not
328 * be found in JD already (the set of generation candidates).
330 typedef LLVMErrorRef (*LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction)(
331 LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
332 LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind,
333 LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags,
334 LLVMOrcCLookupSet LookupSet, size_t LookupSetSize);
337 * Predicate function for SymbolStringPoolEntries.
339 typedef int (*LLVMOrcSymbolPredicate)(void *Ctx,
340 LLVMOrcSymbolStringPoolEntryRef Sym);
343 * A reference to an orc::ThreadSafeContext instance.
345 typedef struct LLVMOrcOpaqueThreadSafeContext *LLVMOrcThreadSafeContextRef;
348 * A reference to an orc::ThreadSafeModule instance.
350 typedef struct LLVMOrcOpaqueThreadSafeModule *LLVMOrcThreadSafeModuleRef;
353 * A function for inspecting/mutating IR modules, suitable for use with
354 * LLVMOrcThreadSafeModuleWithModuleDo.
356 typedef LLVMErrorRef (*LLVMOrcGenericIRModuleOperationFunction)(
357 void *Ctx, LLVMModuleRef M);
360 * A reference to an orc::JITTargetMachineBuilder instance.
362 typedef struct LLVMOrcOpaqueJITTargetMachineBuilder
363 *LLVMOrcJITTargetMachineBuilderRef;
366 * A reference to an orc::ObjectLayer instance.
368 typedef struct LLVMOrcOpaqueObjectLayer *LLVMOrcObjectLayerRef;
371 * A reference to an orc::ObjectLinkingLayer instance.
373 typedef struct LLVMOrcOpaqueObjectLinkingLayer *LLVMOrcObjectLinkingLayerRef;
376 * A reference to an orc::IRTransformLayer instance.
378 typedef struct LLVMOrcOpaqueIRTransformLayer *LLVMOrcIRTransformLayerRef;
381 * A function for applying transformations as part of an transform layer.
383 * Implementations of this type are responsible for managing the lifetime
384 * of the Module pointed to by ModInOut: If the LLVMModuleRef value is
385 * overwritten then the function is responsible for disposing of the incoming
386 * module. If the module is simply accessed/mutated in-place then ownership
387 * returns to the caller and the function does not need to do any lifetime
388 * management.
390 * Clients can call LLVMOrcLLJITGetIRTransformLayer to obtain the transform
391 * layer of a LLJIT instance, and use LLVMOrcIRTransformLayerSetTransform
392 * to set the function. This can be used to override the default transform
393 * layer.
395 typedef LLVMErrorRef (*LLVMOrcIRTransformLayerTransformFunction)(
396 void *Ctx, LLVMOrcThreadSafeModuleRef *ModInOut,
397 LLVMOrcMaterializationResponsibilityRef MR);
400 * A reference to an orc::ObjectTransformLayer instance.
402 typedef struct LLVMOrcOpaqueObjectTransformLayer
403 *LLVMOrcObjectTransformLayerRef;
406 * A function for applying transformations to an object file buffer.
408 * Implementations of this type are responsible for managing the lifetime
409 * of the memory buffer pointed to by ObjInOut: If the LLVMMemoryBufferRef
410 * value is overwritten then the function is responsible for disposing of the
411 * incoming buffer. If the buffer is simply accessed/mutated in-place then
412 * ownership returns to the caller and the function does not need to do any
413 * lifetime management.
415 * The transform is allowed to return an error, in which case the ObjInOut
416 * buffer should be disposed of and set to null.
418 typedef LLVMErrorRef (*LLVMOrcObjectTransformLayerTransformFunction)(
419 void *Ctx, LLVMMemoryBufferRef *ObjInOut);
422 * A reference to an orc::IndirectStubsManager instance.
424 typedef struct LLVMOrcOpaqueIndirectStubsManager
425 *LLVMOrcIndirectStubsManagerRef;
428 * A reference to an orc::LazyCallThroughManager instance.
430 typedef struct LLVMOrcOpaqueLazyCallThroughManager
431 *LLVMOrcLazyCallThroughManagerRef;
434 * A reference to an orc::DumpObjects object.
436 * Can be used to dump object files to disk with unique names. Useful as an
437 * ObjectTransformLayer transform.
439 typedef struct LLVMOrcOpaqueDumpObjects *LLVMOrcDumpObjectsRef;
442 * Attach a custom error reporter function to the ExecutionSession.
444 * The error reporter will be called to deliver failure notices that can not be
445 * directly reported to a caller. For example, failure to resolve symbols in
446 * the JIT linker is typically reported via the error reporter (callers
447 * requesting definitions from the JIT will typically be delivered a
448 * FailureToMaterialize error instead).
450 void LLVMOrcExecutionSessionSetErrorReporter(
451 LLVMOrcExecutionSessionRef ES, LLVMOrcErrorReporterFunction ReportError,
452 void *Ctx);
455 * Return a reference to the SymbolStringPool for an ExecutionSession.
457 * Ownership of the pool remains with the ExecutionSession: The caller is
458 * not required to free the pool.
460 LLVMOrcSymbolStringPoolRef
461 LLVMOrcExecutionSessionGetSymbolStringPool(LLVMOrcExecutionSessionRef ES);
464 * Clear all unreferenced symbol string pool entries.
466 * This can be called at any time to release unused entries in the
467 * ExecutionSession's string pool. Since it locks the pool (preventing
468 * interning of any new strings) it is recommended that it only be called
469 * infrequently, ideally when the caller has reason to believe that some
470 * entries will have become unreferenced, e.g. after removing a module or
471 * closing a JITDylib.
473 void LLVMOrcSymbolStringPoolClearDeadEntries(LLVMOrcSymbolStringPoolRef SSP);
476 * Intern a string in the ExecutionSession's SymbolStringPool and return a
477 * reference to it. This increments the ref-count of the pool entry, and the
478 * returned value should be released once the client is done with it by
479 * calling LLVMOrReleaseSymbolStringPoolEntry.
481 * Since strings are uniqued within the SymbolStringPool
482 * LLVMOrcSymbolStringPoolEntryRefs can be compared by value to test string
483 * equality.
485 * Note that this function does not perform linker-mangling on the string.
487 LLVMOrcSymbolStringPoolEntryRef
488 LLVMOrcExecutionSessionIntern(LLVMOrcExecutionSessionRef ES, const char *Name);
491 * Increments the ref-count for a SymbolStringPool entry.
493 void LLVMOrcRetainSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S);
496 * Reduces the ref-count for of a SymbolStringPool entry.
498 void LLVMOrcReleaseSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S);
500 const char *LLVMOrcSymbolStringPoolEntryStr(LLVMOrcSymbolStringPoolEntryRef S);
503 * Reduces the ref-count of a ResourceTracker.
505 void LLVMOrcReleaseResourceTracker(LLVMOrcResourceTrackerRef RT);
508 * Transfers tracking of all resources associated with resource tracker SrcRT
509 * to resource tracker DstRT.
511 void LLVMOrcResourceTrackerTransferTo(LLVMOrcResourceTrackerRef SrcRT,
512 LLVMOrcResourceTrackerRef DstRT);
515 * Remove all resources associated with the given tracker. See
516 * ResourceTracker::remove().
518 LLVMErrorRef LLVMOrcResourceTrackerRemove(LLVMOrcResourceTrackerRef RT);
521 * Dispose of a JITDylib::DefinitionGenerator. This should only be called if
522 * ownership has not been passed to a JITDylib (e.g. because some error
523 * prevented the client from calling LLVMOrcJITDylibAddGenerator).
525 void LLVMOrcDisposeDefinitionGenerator(LLVMOrcDefinitionGeneratorRef DG);
528 * Dispose of a MaterializationUnit.
530 void LLVMOrcDisposeMaterializationUnit(LLVMOrcMaterializationUnitRef MU);
533 * Create a custom MaterializationUnit.
535 * Name is a name for this MaterializationUnit to be used for identification
536 * and logging purposes (e.g. if this MaterializationUnit produces an
537 * object buffer then the name of that buffer will be derived from this name).
539 * The Syms list contains the names and linkages of the symbols provided by this
540 * unit. This function takes ownership of the elements of the Syms array. The
541 * Name fields of the array elements are taken to have been retained for this
542 * function. The client should *not* release the elements of the array, but is
543 * still responsible for destroyingthe array itself.
545 * The InitSym argument indicates whether or not this MaterializationUnit
546 * contains static initializers. If three are no static initializers (the common
547 * case) then this argument should be null. If there are static initializers
548 * then InitSym should be set to a unique name that also appears in the Syms
549 * list with the LLVMJITSymbolGenericFlagsMaterializationSideEffectsOnly flag
550 * set. This function takes ownership of the InitSym, which should have been
551 * retained twice on behalf of this function: once for the Syms entry and once
552 * for InitSym. If clients wish to use the InitSym value after this function
553 * returns they must retain it once more for themselves.
555 * If any of the symbols in the Syms list is looked up then the Materialize
556 * function will be called.
558 * If any of the symbols in the Syms list is overridden then the Discard
559 * function will be called.
561 * The caller owns the underling MaterializationUnit and is responsible for
562 * either passing it to a JITDylib (via LLVMOrcJITDylibDefine) or disposing
563 * of it by calling LLVMOrcDisposeMaterializationUnit.
565 LLVMOrcMaterializationUnitRef LLVMOrcCreateCustomMaterializationUnit(
566 const char *Name, void *Ctx, LLVMOrcCSymbolFlagsMapPairs Syms,
567 size_t NumSyms, LLVMOrcSymbolStringPoolEntryRef InitSym,
568 LLVMOrcMaterializationUnitMaterializeFunction Materialize,
569 LLVMOrcMaterializationUnitDiscardFunction Discard,
570 LLVMOrcMaterializationUnitDestroyFunction Destroy);
573 * Create a MaterializationUnit to define the given symbols as pointing to
574 * the corresponding raw addresses.
576 * This function takes ownership of the elements of the Syms array. The Name
577 * fields of the array elements are taken to have been retained for this
578 * function. This allows the following pattern...
580 * size_t NumPairs;
581 * LLVMOrcCSymbolMapPairs Sym;
582 * -- Build Syms array --
583 * LLVMOrcMaterializationUnitRef MU =
584 * LLVMOrcAbsoluteSymbols(Syms, NumPairs);
586 * ... without requiring cleanup of the elements of the Sym array afterwards.
588 * The client is still responsible for deleting the Sym array itself.
590 * If a client wishes to reuse elements of the Sym array after this call they
591 * must explicitly retain each of the elements for themselves.
593 LLVMOrcMaterializationUnitRef
594 LLVMOrcAbsoluteSymbols(LLVMOrcCSymbolMapPairs Syms, size_t NumPairs);
597 * Create a MaterializationUnit to define lazy re-expots. These are callable
598 * entry points that call through to the given symbols.
600 * This function takes ownership of the CallableAliases array. The Name
601 * fields of the array elements are taken to have been retained for this
602 * function. This allows the following pattern...
604 * size_t NumPairs;
605 * LLVMOrcCSymbolAliasMapPairs CallableAliases;
606 * -- Build CallableAliases array --
607 * LLVMOrcMaterializationUnitRef MU =
608 * LLVMOrcLazyReexports(LCTM, ISM, JD, CallableAliases, NumPairs);
610 * ... without requiring cleanup of the elements of the CallableAliases array afterwards.
612 * The client is still responsible for deleting the CallableAliases array itself.
614 * If a client wishes to reuse elements of the CallableAliases array after this call they
615 * must explicitly retain each of the elements for themselves.
617 LLVMOrcMaterializationUnitRef LLVMOrcLazyReexports(
618 LLVMOrcLazyCallThroughManagerRef LCTM, LLVMOrcIndirectStubsManagerRef ISM,
619 LLVMOrcJITDylibRef SourceRef, LLVMOrcCSymbolAliasMapPairs CallableAliases,
620 size_t NumPairs);
621 // TODO: ImplSymbolMad SrcJDLoc
624 * Disposes of the passed MaterializationResponsibility object.
626 * This should only be done after the symbols covered by the object have either
627 * been resolved and emitted (via
628 * LLVMOrcMaterializationResponsibilityNotifyResolved and
629 * LLVMOrcMaterializationResponsibilityNotifyEmitted) or failed (via
630 * LLVMOrcMaterializationResponsibilityFailMaterialization).
632 void LLVMOrcDisposeMaterializationResponsibility(
633 LLVMOrcMaterializationResponsibilityRef MR);
636 * Returns the target JITDylib that these symbols are being materialized into.
638 LLVMOrcJITDylibRef LLVMOrcMaterializationResponsibilityGetTargetDylib(
639 LLVMOrcMaterializationResponsibilityRef MR);
642 * Returns the ExecutionSession for this MaterializationResponsibility.
644 LLVMOrcExecutionSessionRef
645 LLVMOrcMaterializationResponsibilityGetExecutionSession(
646 LLVMOrcMaterializationResponsibilityRef MR);
649 * Returns the symbol flags map for this responsibility instance.
651 * The length of the array is returned in NumPairs and the caller is responsible
652 * for the returned memory and needs to call LLVMOrcDisposeCSymbolFlagsMap.
654 * To use the returned symbols beyond the livetime of the
655 * MaterializationResponsibility requires the caller to retain the symbols
656 * explicitly.
658 LLVMOrcCSymbolFlagsMapPairs LLVMOrcMaterializationResponsibilityGetSymbols(
659 LLVMOrcMaterializationResponsibilityRef MR, size_t *NumPairs);
662 * Disposes of the passed LLVMOrcCSymbolFlagsMap.
664 * Does not release the entries themselves.
666 void LLVMOrcDisposeCSymbolFlagsMap(LLVMOrcCSymbolFlagsMapPairs Pairs);
669 * Returns the initialization pseudo-symbol, if any. This symbol will also
670 * be present in the SymbolFlagsMap for this MaterializationResponsibility
671 * object.
673 * The returned symbol is not retained over any mutating operation of the
674 * MaterializationResponsbility or beyond the lifetime thereof.
676 LLVMOrcSymbolStringPoolEntryRef
677 LLVMOrcMaterializationResponsibilityGetInitializerSymbol(
678 LLVMOrcMaterializationResponsibilityRef MR);
681 * Returns the names of any symbols covered by this
682 * MaterializationResponsibility object that have queries pending. This
683 * information can be used to return responsibility for unrequested symbols
684 * back to the JITDylib via the delegate method.
686 LLVMOrcSymbolStringPoolEntryRef *
687 LLVMOrcMaterializationResponsibilityGetRequestedSymbols(
688 LLVMOrcMaterializationResponsibilityRef MR, size_t *NumSymbols);
691 * Disposes of the passed LLVMOrcSymbolStringPoolEntryRef* .
693 * Does not release the symbols themselves.
695 void LLVMOrcDisposeSymbols(LLVMOrcSymbolStringPoolEntryRef *Symbols);
698 * Notifies the target JITDylib that the given symbols have been resolved.
699 * This will update the given symbols' addresses in the JITDylib, and notify
700 * any pending queries on the given symbols of their resolution. The given
701 * symbols must be ones covered by this MaterializationResponsibility
702 * instance. Individual calls to this method may resolve a subset of the
703 * symbols, but all symbols must have been resolved prior to calling emit.
705 * This method will return an error if any symbols being resolved have been
706 * moved to the error state due to the failure of a dependency. If this
707 * method returns an error then clients should log it and call
708 * LLVMOrcMaterializationResponsibilityFailMaterialization. If no dependencies
709 * have been registered for the symbols covered by this
710 * MaterializationResponsibiility then this method is guaranteed to return
711 * LLVMErrorSuccess.
713 LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyResolved(
714 LLVMOrcMaterializationResponsibilityRef MR, LLVMOrcCSymbolMapPairs Symbols,
715 size_t NumPairs);
718 * Notifies the target JITDylib (and any pending queries on that JITDylib)
719 * that all symbols covered by this MaterializationResponsibility instance
720 * have been emitted.
722 * This method will return an error if any symbols being resolved have been
723 * moved to the error state due to the failure of a dependency. If this
724 * method returns an error then clients should log it and call
725 * LLVMOrcMaterializationResponsibilityFailMaterialization.
726 * If no dependencies have been registered for the symbols covered by this
727 * MaterializationResponsibiility then this method is guaranteed to return
728 * LLVMErrorSuccess.
730 LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyEmitted(
731 LLVMOrcMaterializationResponsibilityRef MR);
734 * Attempt to claim responsibility for new definitions. This method can be
735 * used to claim responsibility for symbols that are added to a
736 * materialization unit during the compilation process (e.g. literal pool
737 * symbols). Symbol linkage rules are the same as for symbols that are
738 * defined up front: duplicate strong definitions will result in errors.
739 * Duplicate weak definitions will be discarded (in which case they will
740 * not be added to this responsibility instance).
742 * This method can be used by materialization units that want to add
743 * additional symbols at materialization time (e.g. stubs, compile
744 * callbacks, metadata)
746 LLVMErrorRef LLVMOrcMaterializationResponsibilityDefineMaterializing(
747 LLVMOrcMaterializationResponsibilityRef MR,
748 LLVMOrcCSymbolFlagsMapPairs Pairs, size_t NumPairs);
751 * Notify all not-yet-emitted covered by this MaterializationResponsibility
752 * instance that an error has occurred.
753 * This will remove all symbols covered by this MaterializationResponsibilty
754 * from the target JITDylib, and send an error to any queries waiting on
755 * these symbols.
757 void LLVMOrcMaterializationResponsibilityFailMaterialization(
758 LLVMOrcMaterializationResponsibilityRef MR);
761 * Transfers responsibility to the given MaterializationUnit for all
762 * symbols defined by that MaterializationUnit. This allows
763 * materializers to break up work based on run-time information (e.g.
764 * by introspecting which symbols have actually been looked up and
765 * materializing only those).
767 LLVMErrorRef LLVMOrcMaterializationResponsibilityReplace(
768 LLVMOrcMaterializationResponsibilityRef MR,
769 LLVMOrcMaterializationUnitRef MU);
772 * Delegates responsibility for the given symbols to the returned
773 * materialization responsibility. Useful for breaking up work between
774 * threads, or different kinds of materialization processes.
776 * The caller retains responsibility of the the passed
777 * MaterializationResponsibility.
779 LLVMErrorRef LLVMOrcMaterializationResponsibilityDelegate(
780 LLVMOrcMaterializationResponsibilityRef MR,
781 LLVMOrcSymbolStringPoolEntryRef *Symbols, size_t NumSymbols,
782 LLVMOrcMaterializationResponsibilityRef *Result);
785 * Adds dependencies to a symbol that the MaterializationResponsibility is
786 * responsible for.
788 * This function takes ownership of Dependencies struct. The Names
789 * array have been retained for this function. This allows the following
790 * pattern...
792 * LLVMOrcSymbolStringPoolEntryRef Names[] = {...};
793 * LLVMOrcCDependenceMapPair Dependence = {JD, {Names, sizeof(Names)}}
794 * LLVMOrcMaterializationResponsibilityAddDependencies(JD, Name, &Dependence,
795 * 1);
797 * ... without requiring cleanup of the elements of the Names array afterwards.
799 * The client is still responsible for deleting the Dependencies.Names array
800 * itself.
802 void LLVMOrcMaterializationResponsibilityAddDependencies(
803 LLVMOrcMaterializationResponsibilityRef MR,
804 LLVMOrcSymbolStringPoolEntryRef Name,
805 LLVMOrcCDependenceMapPairs Dependencies, size_t NumPairs);
808 * Adds dependencies to all symbols that the MaterializationResponsibility is
809 * responsible for. See LLVMOrcMaterializationResponsibilityAddDependencies for
810 * notes about memory responsibility.
812 void LLVMOrcMaterializationResponsibilityAddDependenciesForAll(
813 LLVMOrcMaterializationResponsibilityRef MR,
814 LLVMOrcCDependenceMapPairs Dependencies, size_t NumPairs);
817 * Create a "bare" JITDylib.
819 * The client is responsible for ensuring that the JITDylib's name is unique,
820 * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first.
822 * This call does not install any library code or symbols into the newly
823 * created JITDylib. The client is responsible for all configuration.
825 LLVMOrcJITDylibRef
826 LLVMOrcExecutionSessionCreateBareJITDylib(LLVMOrcExecutionSessionRef ES,
827 const char *Name);
830 * Create a JITDylib.
832 * The client is responsible for ensuring that the JITDylib's name is unique,
833 * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first.
835 * If a Platform is attached to the ExecutionSession then
836 * Platform::setupJITDylib will be called to install standard platform symbols
837 * (e.g. standard library interposes). If no Platform is installed then this
838 * call is equivalent to LLVMExecutionSessionRefCreateBareJITDylib and will
839 * always return success.
841 LLVMErrorRef
842 LLVMOrcExecutionSessionCreateJITDylib(LLVMOrcExecutionSessionRef ES,
843 LLVMOrcJITDylibRef *Result,
844 const char *Name);
847 * Returns the JITDylib with the given name, or NULL if no such JITDylib
848 * exists.
850 LLVMOrcJITDylibRef
851 LLVMOrcExecutionSessionGetJITDylibByName(LLVMOrcExecutionSessionRef ES,
852 const char *Name);
855 * Return a reference to a newly created resource tracker associated with JD.
856 * The tracker is returned with an initial ref-count of 1, and must be released
857 * with LLVMOrcReleaseResourceTracker when no longer needed.
859 LLVMOrcResourceTrackerRef
860 LLVMOrcJITDylibCreateResourceTracker(LLVMOrcJITDylibRef JD);
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.
867 LLVMOrcResourceTrackerRef
868 LLVMOrcJITDylibGetDefaultResourceTracker(LLVMOrcJITDylibRef JD);
871 * Add the given MaterializationUnit to the given JITDylib.
873 * If this operation succeeds then JITDylib JD will take ownership of MU.
874 * If the operation fails then ownership remains with the caller who should
875 * call LLVMOrcDisposeMaterializationUnit to destroy it.
877 LLVMErrorRef LLVMOrcJITDylibDefine(LLVMOrcJITDylibRef JD,
878 LLVMOrcMaterializationUnitRef MU);
881 * Calls remove on all trackers associated with this JITDylib, see
882 * JITDylib::clear().
884 LLVMErrorRef LLVMOrcJITDylibClear(LLVMOrcJITDylibRef JD);
887 * Add a DefinitionGenerator to the given JITDylib.
889 * The JITDylib will take ownership of the given generator: The client is no
890 * longer responsible for managing its memory.
892 void LLVMOrcJITDylibAddGenerator(LLVMOrcJITDylibRef JD,
893 LLVMOrcDefinitionGeneratorRef DG);
896 * Create a custom generator.
898 LLVMOrcDefinitionGeneratorRef LLVMOrcCreateCustomCAPIDefinitionGenerator(
899 LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction F, void *Ctx);
902 * Get a DynamicLibrarySearchGenerator that will reflect process symbols into
903 * the JITDylib. On success the resulting generator is owned by the client.
904 * Ownership is typically transferred by adding the instance to a JITDylib
905 * using LLVMOrcJITDylibAddGenerator,
907 * The GlobalPrefix argument specifies the character that appears on the front
908 * of linker-mangled symbols for the target platform (e.g. '_' on MachO).
909 * If non-null, this character will be stripped from the start of all symbol
910 * strings before passing the remaining substring to dlsym.
912 * The optional Filter and Ctx arguments can be used to supply a symbol name
913 * filter: Only symbols for which the filter returns true will be visible to
914 * JIT'd code. If the Filter argument is null then all process symbols will
915 * be visible to JIT'd code. Note that the symbol name passed to the Filter
916 * function is the full mangled symbol: The client is responsible for stripping
917 * the global prefix if present.
919 LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess(
920 LLVMOrcDefinitionGeneratorRef *Result, char GlobalPrefx,
921 LLVMOrcSymbolPredicate Filter, void *FilterCtx);
924 * Create a ThreadSafeContext containing a new LLVMContext.
926 * Ownership of the underlying ThreadSafeContext data is shared: Clients
927 * can and should dispose of their ThreadSafeContext as soon as they no longer
928 * need to refer to it directly. Other references (e.g. from ThreadSafeModules)
929 * will keep the data alive as long as it is needed.
931 LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void);
934 * Get a reference to the wrapped LLVMContext.
936 LLVMContextRef
937 LLVMOrcThreadSafeContextGetContext(LLVMOrcThreadSafeContextRef TSCtx);
940 * Dispose of a ThreadSafeContext.
942 void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx);
945 * Create a ThreadSafeModule wrapper around the given LLVM module. This takes
946 * ownership of the M argument which should not be disposed of or referenced
947 * after this function returns.
949 * Ownership of the ThreadSafeModule is unique: If it is transferred to the JIT
950 * (e.g. by LLVMOrcLLJITAddLLVMIRModule) then the client is no longer
951 * responsible for it. If it is not transferred to the JIT then the client
952 * should call LLVMOrcDisposeThreadSafeModule to dispose of it.
954 LLVMOrcThreadSafeModuleRef
955 LLVMOrcCreateNewThreadSafeModule(LLVMModuleRef M,
956 LLVMOrcThreadSafeContextRef TSCtx);
959 * Dispose of a ThreadSafeModule. This should only be called if ownership has
960 * not been passed to LLJIT (e.g. because some error prevented the client from
961 * adding this to the JIT).
963 void LLVMOrcDisposeThreadSafeModule(LLVMOrcThreadSafeModuleRef TSM);
966 * Apply the given function to the module contained in this ThreadSafeModule.
968 LLVMErrorRef
969 LLVMOrcThreadSafeModuleWithModuleDo(LLVMOrcThreadSafeModuleRef TSM,
970 LLVMOrcGenericIRModuleOperationFunction F,
971 void *Ctx);
974 * Create a JITTargetMachineBuilder by detecting the host.
976 * On success the client owns the resulting JITTargetMachineBuilder. It must be
977 * passed to a consuming operation (e.g.
978 * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling
979 * LLVMOrcDisposeJITTargetMachineBuilder.
981 LLVMErrorRef LLVMOrcJITTargetMachineBuilderDetectHost(
982 LLVMOrcJITTargetMachineBuilderRef *Result);
985 * Create a JITTargetMachineBuilder from the given TargetMachine template.
987 * This operation takes ownership of the given TargetMachine and destroys it
988 * before returing. The resulting JITTargetMachineBuilder is owned by the client
989 * and must be passed to a consuming operation (e.g.
990 * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling
991 * LLVMOrcDisposeJITTargetMachineBuilder.
993 LLVMOrcJITTargetMachineBuilderRef
994 LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(LLVMTargetMachineRef TM);
997 * Dispose of a JITTargetMachineBuilder.
999 void LLVMOrcDisposeJITTargetMachineBuilder(
1000 LLVMOrcJITTargetMachineBuilderRef JTMB);
1003 * Returns the target triple for the given JITTargetMachineBuilder as a string.
1005 * The caller owns the resulting string as must dispose of it by calling
1006 * LLVMDisposeMessage
1008 char *LLVMOrcJITTargetMachineBuilderGetTargetTriple(
1009 LLVMOrcJITTargetMachineBuilderRef JTMB);
1012 * Sets the target triple for the given JITTargetMachineBuilder to the given
1013 * string.
1015 void LLVMOrcJITTargetMachineBuilderSetTargetTriple(
1016 LLVMOrcJITTargetMachineBuilderRef JTMB, const char *TargetTriple);
1019 * Add an object to an ObjectLayer to the given JITDylib.
1021 * Adds a buffer representing an object file to the given JITDylib using the
1022 * given ObjectLayer instance. This operation transfers ownership of the buffer
1023 * to the ObjectLayer instance. The buffer should not be disposed of or
1024 * referenced once this function returns.
1026 * Resources associated with the given object will be tracked by the given
1027 * JITDylib's default ResourceTracker.
1029 LLVMErrorRef LLVMOrcObjectLayerAddObjectFile(LLVMOrcObjectLayerRef ObjLayer,
1030 LLVMOrcJITDylibRef JD,
1031 LLVMMemoryBufferRef ObjBuffer);
1034 * Add an object to an ObjectLayer using the given ResourceTracker.
1036 * Adds a buffer representing an object file to the given ResourceTracker's
1037 * JITDylib using the given ObjectLayer instance. This operation transfers
1038 * ownership of the buffer to the ObjectLayer instance. The buffer should not
1039 * be disposed of or referenced once this function returns.
1041 * Resources associated with the given object will be tracked by
1042 * ResourceTracker RT.
1044 LLVMErrorRef
1045 LLVMOrcObjectLayerAddObjectFileWithRT(LLVMOrcObjectLayerRef ObjLayer,
1046 LLVMOrcResourceTrackerRef RT,
1047 LLVMMemoryBufferRef ObjBuffer);
1050 * Emit an object buffer to an ObjectLayer.
1052 * Ownership of the responsibility object and object buffer pass to this
1053 * function. The client is not responsible for cleanup.
1055 void LLVMOrcObjectLayerEmit(LLVMOrcObjectLayerRef ObjLayer,
1056 LLVMOrcMaterializationResponsibilityRef R,
1057 LLVMMemoryBufferRef ObjBuffer);
1060 * Dispose of an ObjectLayer.
1062 void LLVMOrcDisposeObjectLayer(LLVMOrcObjectLayerRef ObjLayer);
1064 void LLVMOrcIRTransformLayerEmit(LLVMOrcIRTransformLayerRef IRTransformLayer,
1065 LLVMOrcMaterializationResponsibilityRef MR,
1066 LLVMOrcThreadSafeModuleRef TSM);
1069 * Set the transform function of the provided transform layer, passing through a
1070 * pointer to user provided context.
1072 void LLVMOrcIRTransformLayerSetTransform(
1073 LLVMOrcIRTransformLayerRef IRTransformLayer,
1074 LLVMOrcIRTransformLayerTransformFunction TransformFunction, void *Ctx);
1077 * Set the transform function on an LLVMOrcObjectTransformLayer.
1079 void LLVMOrcObjectTransformLayerSetTransform(
1080 LLVMOrcObjectTransformLayerRef ObjTransformLayer,
1081 LLVMOrcObjectTransformLayerTransformFunction TransformFunction, void *Ctx);
1084 * Create a LocalIndirectStubsManager from the given target triple.
1086 * The resulting IndirectStubsManager is owned by the client
1087 * and must be disposed of by calling LLVMOrcDisposeDisposeIndirectStubsManager.
1089 LLVMOrcIndirectStubsManagerRef
1090 LLVMOrcCreateLocalIndirectStubsManager(const char *TargetTriple);
1093 * Dispose of an IndirectStubsManager.
1095 void LLVMOrcDisposeIndirectStubsManager(LLVMOrcIndirectStubsManagerRef ISM);
1097 LLVMErrorRef LLVMOrcCreateLocalLazyCallThroughManager(
1098 const char *TargetTriple, LLVMOrcExecutionSessionRef ES,
1099 LLVMOrcJITTargetAddress ErrorHandlerAddr,
1100 LLVMOrcLazyCallThroughManagerRef *LCTM);
1103 * Dispose of an LazyCallThroughManager.
1105 void LLVMOrcDisposeLazyCallThroughManager(
1106 LLVMOrcLazyCallThroughManagerRef LCTM);
1109 * Create a DumpObjects instance.
1111 * DumpDir specifies the path to write dumped objects to. DumpDir may be empty
1112 * in which case files will be dumped to the working directory.
1114 * IdentifierOverride specifies a file name stem to use when dumping objects.
1115 * If empty then each MemoryBuffer's identifier will be used (with a .o suffix
1116 * added if not already present). If an identifier override is supplied it will
1117 * be used instead, along with an incrementing counter (since all buffers will
1118 * use the same identifier, the resulting files will be named <ident>.o,
1119 * <ident>.2.o, <ident>.3.o, and so on). IdentifierOverride should not contain
1120 * an extension, as a .o suffix will be added by DumpObjects.
1122 LLVMOrcDumpObjectsRef LLVMOrcCreateDumpObjects(const char *DumpDir,
1123 const char *IdentifierOverride);
1126 * Dispose of a DumpObjects instance.
1128 void LLVMOrcDisposeDumpObjects(LLVMOrcDumpObjectsRef DumpObjects);
1131 * Dump the contents of the given MemoryBuffer.
1133 LLVMErrorRef LLVMOrcDumpObjects_CallOperator(LLVMOrcDumpObjectsRef DumpObjects,
1134 LLVMMemoryBufferRef *ObjBuffer);
1136 LLVM_C_EXTERN_C_END
1138 #endif /* LLVM_C_ORC_H */