xref: /freebsd/contrib/llvm-project/llvm/include/llvm-c/Orc.h (revision d409305fa3838fb39b38c26fc085fb729b8766d5)
15ffd83dbSDimitry Andric /*===---------------- llvm-c/Orc.h - OrcV2 C bindings -----------*- C++ -*-===*\
25ffd83dbSDimitry Andric |*                                                                            *|
35ffd83dbSDimitry Andric |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
45ffd83dbSDimitry Andric |* Exceptions.                                                                *|
55ffd83dbSDimitry Andric |* See https://llvm.org/LICENSE.txt for license information.                  *|
65ffd83dbSDimitry Andric |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
75ffd83dbSDimitry Andric |*                                                                            *|
85ffd83dbSDimitry Andric |*===----------------------------------------------------------------------===*|
95ffd83dbSDimitry Andric |*                                                                            *|
105ffd83dbSDimitry Andric |* This header declares the C interface to libLLVMOrcJIT.a, which implements  *|
115ffd83dbSDimitry Andric |* JIT compilation of LLVM IR. Minimal documentation of C API specific issues *|
125ffd83dbSDimitry Andric |* (especially memory ownership rules) is provided. Core Orc concepts are     *|
135ffd83dbSDimitry Andric |* documented in llvm/docs/ORCv2.rst and APIs are documented in the C++       *|
145ffd83dbSDimitry Andric |* headers                                                                    *|
155ffd83dbSDimitry Andric |*                                                                            *|
165ffd83dbSDimitry Andric |* Many exotic languages can interoperate with C code but have a harder time  *|
175ffd83dbSDimitry Andric |* with C++ due to name mangling. So in addition to C, this interface enables *|
185ffd83dbSDimitry Andric |* tools written in such languages.                                           *|
195ffd83dbSDimitry Andric |*                                                                            *|
205ffd83dbSDimitry Andric |* Note: This interface is experimental. It is *NOT* stable, and may be       *|
215ffd83dbSDimitry Andric |*       changed without warning. Only C API usage documentation is           *|
225ffd83dbSDimitry Andric |*       provided. See the C++ documentation for all higher level ORC API     *|
235ffd83dbSDimitry Andric |*       details.                                                             *|
245ffd83dbSDimitry Andric |*                                                                            *|
255ffd83dbSDimitry Andric \*===----------------------------------------------------------------------===*/
265ffd83dbSDimitry Andric 
275ffd83dbSDimitry Andric #ifndef LLVM_C_ORC_H
285ffd83dbSDimitry Andric #define LLVM_C_ORC_H
295ffd83dbSDimitry Andric 
305ffd83dbSDimitry Andric #include "llvm-c/Error.h"
315ffd83dbSDimitry Andric #include "llvm-c/TargetMachine.h"
325ffd83dbSDimitry Andric #include "llvm-c/Types.h"
335ffd83dbSDimitry Andric 
345ffd83dbSDimitry Andric LLVM_C_EXTERN_C_BEGIN
355ffd83dbSDimitry Andric 
365ffd83dbSDimitry Andric /**
375ffd83dbSDimitry Andric  * Represents an address in the target process.
385ffd83dbSDimitry Andric  */
395ffd83dbSDimitry Andric typedef uint64_t LLVMOrcJITTargetAddress;
405ffd83dbSDimitry Andric 
415ffd83dbSDimitry Andric /**
42e8d8bef9SDimitry Andric  * Represents generic linkage flags for a symbol definition.
43e8d8bef9SDimitry Andric  */
44e8d8bef9SDimitry Andric typedef enum {
45e8d8bef9SDimitry Andric   LLVMJITSymbolGenericFlagsExported = 1U << 0,
46e8d8bef9SDimitry Andric   LLVMJITSymbolGenericFlagsWeak = 1U << 1
47e8d8bef9SDimitry Andric } LLVMJITSymbolGenericFlags;
48e8d8bef9SDimitry Andric 
49e8d8bef9SDimitry Andric /**
50e8d8bef9SDimitry Andric  * Represents target specific flags for a symbol definition.
51e8d8bef9SDimitry Andric  */
52e8d8bef9SDimitry Andric typedef uint8_t LLVMJITTargetSymbolFlags;
53e8d8bef9SDimitry Andric 
54e8d8bef9SDimitry Andric /**
55e8d8bef9SDimitry Andric  * Represents the linkage flags for a symbol definition.
56e8d8bef9SDimitry Andric  */
57e8d8bef9SDimitry Andric typedef struct {
58e8d8bef9SDimitry Andric   uint8_t GenericFlags;
59e8d8bef9SDimitry Andric   uint8_t TargetFlags;
60e8d8bef9SDimitry Andric } LLVMJITSymbolFlags;
61e8d8bef9SDimitry Andric 
62e8d8bef9SDimitry Andric /**
63e8d8bef9SDimitry Andric  * Represents an evaluated symbol address and flags.
64e8d8bef9SDimitry Andric  */
65e8d8bef9SDimitry Andric typedef struct {
66e8d8bef9SDimitry Andric   LLVMOrcJITTargetAddress Address;
67e8d8bef9SDimitry Andric   LLVMJITSymbolFlags Flags;
68e8d8bef9SDimitry Andric } LLVMJITEvaluatedSymbol;
69e8d8bef9SDimitry Andric 
70e8d8bef9SDimitry Andric /**
715ffd83dbSDimitry Andric  * A reference to an orc::ExecutionSession instance.
725ffd83dbSDimitry Andric  */
735ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueExecutionSession *LLVMOrcExecutionSessionRef;
745ffd83dbSDimitry Andric 
755ffd83dbSDimitry Andric /**
76e8d8bef9SDimitry Andric  * Error reporter function.
77e8d8bef9SDimitry Andric  */
78e8d8bef9SDimitry Andric typedef void (*LLVMOrcErrorReporterFunction)(void *Ctx, LLVMErrorRef Err);
79e8d8bef9SDimitry Andric 
80e8d8bef9SDimitry Andric /**
81e8d8bef9SDimitry Andric  * A reference to an orc::SymbolStringPool.
82e8d8bef9SDimitry Andric  */
83e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueSymbolStringPool *LLVMOrcSymbolStringPoolRef;
84e8d8bef9SDimitry Andric 
85e8d8bef9SDimitry Andric /**
865ffd83dbSDimitry Andric  * A reference to an orc::SymbolStringPool table entry.
875ffd83dbSDimitry Andric  */
88e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueSymbolStringPoolEntry
895ffd83dbSDimitry Andric     *LLVMOrcSymbolStringPoolEntryRef;
905ffd83dbSDimitry Andric 
915ffd83dbSDimitry Andric /**
92e8d8bef9SDimitry Andric  * Represents a pair of a symbol name and an evaluated symbol.
93e8d8bef9SDimitry Andric  */
94e8d8bef9SDimitry Andric typedef struct {
95e8d8bef9SDimitry Andric   LLVMOrcSymbolStringPoolEntryRef Name;
96e8d8bef9SDimitry Andric   LLVMJITEvaluatedSymbol Sym;
97e8d8bef9SDimitry Andric } LLVMJITCSymbolMapPair;
98e8d8bef9SDimitry Andric 
99e8d8bef9SDimitry Andric /**
100e8d8bef9SDimitry Andric  * Represents a list of (SymbolStringPtr, JITEvaluatedSymbol) pairs that can be
101e8d8bef9SDimitry Andric  * used to construct a SymbolMap.
102e8d8bef9SDimitry Andric  */
103e8d8bef9SDimitry Andric typedef LLVMJITCSymbolMapPair *LLVMOrcCSymbolMapPairs;
104e8d8bef9SDimitry Andric 
105e8d8bef9SDimitry Andric /**
106e8d8bef9SDimitry Andric  * Lookup kind. This can be used by definition generators when deciding whether
107e8d8bef9SDimitry Andric  * to produce a definition for a requested symbol.
108e8d8bef9SDimitry Andric  *
109e8d8bef9SDimitry Andric  * This enum should be kept in sync with llvm::orc::LookupKind.
110e8d8bef9SDimitry Andric  */
111e8d8bef9SDimitry Andric typedef enum {
112e8d8bef9SDimitry Andric   LLVMOrcLookupKindStatic,
113e8d8bef9SDimitry Andric   LLVMOrcLookupKindDLSym
114e8d8bef9SDimitry Andric } LLVMOrcLookupKind;
115e8d8bef9SDimitry Andric 
116e8d8bef9SDimitry Andric /**
117e8d8bef9SDimitry Andric  * JITDylib lookup flags. This can be used by definition generators when
118e8d8bef9SDimitry Andric  * deciding whether to produce a definition for a requested symbol.
119e8d8bef9SDimitry Andric  *
120e8d8bef9SDimitry Andric  * This enum should be kept in sync with llvm::orc::JITDylibLookupFlags.
121e8d8bef9SDimitry Andric  */
122e8d8bef9SDimitry Andric typedef enum {
123e8d8bef9SDimitry Andric   LLVMOrcJITDylibLookupFlagsMatchExportedSymbolsOnly,
124e8d8bef9SDimitry Andric   LLVMOrcJITDylibLookupFlagsMatchAllSymbols
125e8d8bef9SDimitry Andric } LLVMOrcJITDylibLookupFlags;
126e8d8bef9SDimitry Andric 
127e8d8bef9SDimitry Andric /**
128e8d8bef9SDimitry Andric  * Symbol lookup flags for lookup sets. This should be kept in sync with
129e8d8bef9SDimitry Andric  * llvm::orc::SymbolLookupFlags.
130e8d8bef9SDimitry Andric  */
131e8d8bef9SDimitry Andric typedef enum {
132e8d8bef9SDimitry Andric   LLVMOrcSymbolLookupFlagsRequiredSymbol,
133e8d8bef9SDimitry Andric   LLVMOrcSymbolLookupFlagsWeaklyReferencedSymbol
134e8d8bef9SDimitry Andric } LLVMOrcSymbolLookupFlags;
135e8d8bef9SDimitry Andric 
136e8d8bef9SDimitry Andric /**
137e8d8bef9SDimitry Andric  * An element type for a symbol lookup set.
138e8d8bef9SDimitry Andric  */
139e8d8bef9SDimitry Andric typedef struct {
140e8d8bef9SDimitry Andric   LLVMOrcSymbolStringPoolEntryRef Name;
141e8d8bef9SDimitry Andric   LLVMOrcSymbolLookupFlags LookupFlags;
142e8d8bef9SDimitry Andric } LLVMOrcCLookupSetElement;
143e8d8bef9SDimitry Andric 
144e8d8bef9SDimitry Andric /**
145e8d8bef9SDimitry Andric  * A set of symbols to look up / generate.
146e8d8bef9SDimitry Andric  *
147e8d8bef9SDimitry Andric  * The list is terminated with an element containing a null pointer for the
148e8d8bef9SDimitry Andric  * Name field.
149e8d8bef9SDimitry Andric  *
150e8d8bef9SDimitry Andric  * If a client creates an instance of this type then they are responsible for
151e8d8bef9SDimitry Andric  * freeing it, and for ensuring that all strings have been retained over the
152e8d8bef9SDimitry Andric  * course of its life. Clients receiving a copy from a callback are not
153e8d8bef9SDimitry Andric  * responsible for managing lifetime or retain counts.
154e8d8bef9SDimitry Andric  */
155e8d8bef9SDimitry Andric typedef LLVMOrcCLookupSetElement *LLVMOrcCLookupSet;
156e8d8bef9SDimitry Andric 
157e8d8bef9SDimitry Andric /**
158e8d8bef9SDimitry Andric  * A reference to an orc::MaterializationUnit.
159e8d8bef9SDimitry Andric  */
160e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueMaterializationUnit *LLVMOrcMaterializationUnitRef;
161e8d8bef9SDimitry Andric 
162e8d8bef9SDimitry Andric /**
1635ffd83dbSDimitry Andric  * A reference to an orc::JITDylib instance.
1645ffd83dbSDimitry Andric  */
1655ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueJITDylib *LLVMOrcJITDylibRef;
1665ffd83dbSDimitry Andric 
1675ffd83dbSDimitry Andric /**
168e8d8bef9SDimitry Andric  * A reference to an orc::ResourceTracker instance.
1695ffd83dbSDimitry Andric  */
170e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueResourceTracker *LLVMOrcResourceTrackerRef;
171e8d8bef9SDimitry Andric 
172e8d8bef9SDimitry Andric /**
173e8d8bef9SDimitry Andric  * A reference to an orc::DefinitionGenerator.
174e8d8bef9SDimitry Andric  */
175e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueDefinitionGenerator
176e8d8bef9SDimitry Andric     *LLVMOrcDefinitionGeneratorRef;
177e8d8bef9SDimitry Andric 
178e8d8bef9SDimitry Andric /**
179e8d8bef9SDimitry Andric  * An opaque lookup state object. Instances of this type can be captured to
180e8d8bef9SDimitry Andric  * suspend a lookup while a custom generator function attempts to produce a
181e8d8bef9SDimitry Andric  * definition.
182e8d8bef9SDimitry Andric  *
183e8d8bef9SDimitry Andric  * If a client captures a lookup state object then they must eventually call
184e8d8bef9SDimitry Andric  * LLVMOrcLookupStateContinueLookup to restart the lookup. This is required
185e8d8bef9SDimitry Andric  * in order to release memory allocated for the lookup state, even if errors
186e8d8bef9SDimitry Andric  * have occurred while the lookup was suspended (if these errors have made the
187e8d8bef9SDimitry Andric  * lookup impossible to complete then it will issue its own error before
188e8d8bef9SDimitry Andric  * destruction).
189e8d8bef9SDimitry Andric  */
190e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueLookupState *LLVMOrcLookupStateRef;
191e8d8bef9SDimitry Andric 
192e8d8bef9SDimitry Andric /**
193e8d8bef9SDimitry Andric  * A custom generator function. This can be used to create a custom generator
194e8d8bef9SDimitry Andric  * object using LLVMOrcCreateCustomCAPIDefinitionGenerator. The resulting
195e8d8bef9SDimitry Andric  * object can be attached to a JITDylib, via LLVMOrcJITDylibAddGenerator, to
196e8d8bef9SDimitry Andric  * receive callbacks when lookups fail to match existing definitions.
197e8d8bef9SDimitry Andric  *
198e8d8bef9SDimitry Andric  * GeneratorObj will contain the address of the custom generator object.
199e8d8bef9SDimitry Andric  *
200e8d8bef9SDimitry Andric  * Ctx will contain the context object passed to
201e8d8bef9SDimitry Andric  * LLVMOrcCreateCustomCAPIDefinitionGenerator.
202e8d8bef9SDimitry Andric  *
203e8d8bef9SDimitry Andric  * LookupState will contain a pointer to an LLVMOrcLookupStateRef object. This
204e8d8bef9SDimitry Andric  * can optionally be modified to make the definition generation process
205e8d8bef9SDimitry Andric  * asynchronous: If the LookupStateRef value is copied, and the original
206e8d8bef9SDimitry Andric  * LLVMOrcLookupStateRef set to null, the lookup will be suspended. Once the
207e8d8bef9SDimitry Andric  * asynchronous definition process has been completed clients must call
208e8d8bef9SDimitry Andric  * LLVMOrcLookupStateContinueLookup to continue the lookup (this should be
209e8d8bef9SDimitry Andric  * done unconditionally, even if errors have occurred in the mean time, to
210e8d8bef9SDimitry Andric  * free the lookup state memory and notify the query object of the failures. If
211e8d8bef9SDimitry Andric  * LookupState is captured this function must return LLVMErrorSuccess.
212e8d8bef9SDimitry Andric  *
213e8d8bef9SDimitry Andric  * The Kind argument can be inspected to determine the lookup kind (e.g.
214e8d8bef9SDimitry Andric  * as-if-during-static-link, or as-if-during-dlsym).
215e8d8bef9SDimitry Andric  *
216e8d8bef9SDimitry Andric  * The JD argument specifies which JITDylib the definitions should be generated
217e8d8bef9SDimitry Andric  * into.
218e8d8bef9SDimitry Andric  *
219e8d8bef9SDimitry Andric  * The JDLookupFlags argument can be inspected to determine whether the original
220e8d8bef9SDimitry Andric  * lookup included non-exported symobls.
221e8d8bef9SDimitry Andric  *
222e8d8bef9SDimitry Andric  * Finally, the LookupSet argument contains the set of symbols that could not
223e8d8bef9SDimitry Andric  * be found in JD already (the set of generation candidates).
224e8d8bef9SDimitry Andric  */
225e8d8bef9SDimitry Andric typedef LLVMErrorRef (*LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction)(
226e8d8bef9SDimitry Andric     LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
227e8d8bef9SDimitry Andric     LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind,
228e8d8bef9SDimitry Andric     LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags,
229e8d8bef9SDimitry Andric     LLVMOrcCLookupSet LookupSet, size_t LookupSetSize);
2305ffd83dbSDimitry Andric 
2315ffd83dbSDimitry Andric /**
2325ffd83dbSDimitry Andric  * Predicate function for SymbolStringPoolEntries.
2335ffd83dbSDimitry Andric  */
234e8d8bef9SDimitry Andric typedef int (*LLVMOrcSymbolPredicate)(void *Ctx,
235e8d8bef9SDimitry Andric                                       LLVMOrcSymbolStringPoolEntryRef Sym);
2365ffd83dbSDimitry Andric 
2375ffd83dbSDimitry Andric /**
2385ffd83dbSDimitry Andric  * A reference to an orc::ThreadSafeContext instance.
2395ffd83dbSDimitry Andric  */
2405ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueThreadSafeContext *LLVMOrcThreadSafeContextRef;
2415ffd83dbSDimitry Andric 
2425ffd83dbSDimitry Andric /**
2435ffd83dbSDimitry Andric  * A reference to an orc::ThreadSafeModule instance.
2445ffd83dbSDimitry Andric  */
2455ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueThreadSafeModule *LLVMOrcThreadSafeModuleRef;
2465ffd83dbSDimitry Andric 
2475ffd83dbSDimitry Andric /**
2485ffd83dbSDimitry Andric  * A reference to an orc::JITTargetMachineBuilder instance.
2495ffd83dbSDimitry Andric  */
2505ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueJITTargetMachineBuilder
2515ffd83dbSDimitry Andric     *LLVMOrcJITTargetMachineBuilderRef;
2525ffd83dbSDimitry Andric 
2535ffd83dbSDimitry Andric /**
254e8d8bef9SDimitry Andric  * A reference to an orc::ObjectLayer instance.
2555ffd83dbSDimitry Andric  */
256e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueObjectLayer *LLVMOrcObjectLayerRef;
2575ffd83dbSDimitry Andric 
2585ffd83dbSDimitry Andric /**
259e8d8bef9SDimitry Andric  * Attach a custom error reporter function to the ExecutionSession.
260e8d8bef9SDimitry Andric  *
261e8d8bef9SDimitry Andric  * The error reporter will be called to deliver failure notices that can not be
262e8d8bef9SDimitry Andric  * directly reported to a caller. For example, failure to resolve symbols in
263e8d8bef9SDimitry Andric  * the JIT linker is typically reported via the error reporter (callers
264e8d8bef9SDimitry Andric  * requesting definitions from the JIT will typically be delivered a
265e8d8bef9SDimitry Andric  * FailureToMaterialize error instead).
2665ffd83dbSDimitry Andric  */
267e8d8bef9SDimitry Andric void LLVMOrcExecutionSessionSetErrorReporter(
268e8d8bef9SDimitry Andric     LLVMOrcExecutionSessionRef ES, LLVMOrcErrorReporterFunction ReportError,
269e8d8bef9SDimitry Andric     void *Ctx);
270e8d8bef9SDimitry Andric 
271e8d8bef9SDimitry Andric /**
272e8d8bef9SDimitry Andric  * Return a reference to the SymbolStringPool for an ExecutionSession.
273e8d8bef9SDimitry Andric  *
274e8d8bef9SDimitry Andric  * Ownership of the pool remains with the ExecutionSession: The caller is
275e8d8bef9SDimitry Andric  * not required to free the pool.
276e8d8bef9SDimitry Andric  */
277e8d8bef9SDimitry Andric LLVMOrcSymbolStringPoolRef
278e8d8bef9SDimitry Andric LLVMOrcExecutionSessionGetSymbolStringPool(LLVMOrcExecutionSessionRef ES);
279e8d8bef9SDimitry Andric 
280e8d8bef9SDimitry Andric /**
281e8d8bef9SDimitry Andric  * Clear all unreferenced symbol string pool entries.
282e8d8bef9SDimitry Andric  *
283e8d8bef9SDimitry Andric  * This can be called at any time to release unused entries in the
284e8d8bef9SDimitry Andric  * ExecutionSession's string pool. Since it locks the pool (preventing
285e8d8bef9SDimitry Andric  * interning of any new strings) it is recommended that it only be called
286e8d8bef9SDimitry Andric  * infrequently, ideally when the caller has reason to believe that some
287e8d8bef9SDimitry Andric  * entries will have become unreferenced, e.g. after removing a module or
288e8d8bef9SDimitry Andric  * closing a JITDylib.
289e8d8bef9SDimitry Andric  */
290e8d8bef9SDimitry Andric void LLVMOrcSymbolStringPoolClearDeadEntries(LLVMOrcSymbolStringPoolRef SSP);
2915ffd83dbSDimitry Andric 
2925ffd83dbSDimitry Andric /**
2935ffd83dbSDimitry Andric  * Intern a string in the ExecutionSession's SymbolStringPool and return a
2945ffd83dbSDimitry Andric  * reference to it. This increments the ref-count of the pool entry, and the
2955ffd83dbSDimitry Andric  * returned value should be released once the client is done with it by
2965ffd83dbSDimitry Andric  * calling LLVMOrReleaseSymbolStringPoolEntry.
2975ffd83dbSDimitry Andric  *
2985ffd83dbSDimitry Andric  * Since strings are uniqued within the SymbolStringPool
2995ffd83dbSDimitry Andric  * LLVMOrcSymbolStringPoolEntryRefs can be compared by value to test string
3005ffd83dbSDimitry Andric  * equality.
3015ffd83dbSDimitry Andric  *
3025ffd83dbSDimitry Andric  * Note that this function does not perform linker-mangling on the string.
3035ffd83dbSDimitry Andric  */
3045ffd83dbSDimitry Andric LLVMOrcSymbolStringPoolEntryRef
3055ffd83dbSDimitry Andric LLVMOrcExecutionSessionIntern(LLVMOrcExecutionSessionRef ES, const char *Name);
3065ffd83dbSDimitry Andric 
3075ffd83dbSDimitry Andric /**
308e8d8bef9SDimitry Andric  * Increments the ref-count for a SymbolStringPool entry.
309e8d8bef9SDimitry Andric  */
310e8d8bef9SDimitry Andric void LLVMOrcRetainSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S);
311e8d8bef9SDimitry Andric 
312e8d8bef9SDimitry Andric /**
3135ffd83dbSDimitry Andric  * Reduces the ref-count for of a SymbolStringPool entry.
3145ffd83dbSDimitry Andric  */
3155ffd83dbSDimitry Andric void LLVMOrcReleaseSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S);
3165ffd83dbSDimitry Andric 
317e8d8bef9SDimitry Andric const char *LLVMOrcSymbolStringPoolEntryStr(LLVMOrcSymbolStringPoolEntryRef S);
318e8d8bef9SDimitry Andric 
319e8d8bef9SDimitry Andric /**
320e8d8bef9SDimitry Andric  * Reduces the ref-count of a ResourceTracker.
321e8d8bef9SDimitry Andric  */
322e8d8bef9SDimitry Andric void LLVMOrcReleaseResourceTracker(LLVMOrcResourceTrackerRef RT);
323e8d8bef9SDimitry Andric 
324e8d8bef9SDimitry Andric /**
325e8d8bef9SDimitry Andric  * Transfers tracking of all resources associated with resource tracker SrcRT
326e8d8bef9SDimitry Andric  * to resource tracker DstRT.
327e8d8bef9SDimitry Andric  */
328e8d8bef9SDimitry Andric void LLVMOrcResourceTrackerTransferTo(LLVMOrcResourceTrackerRef SrcRT,
329e8d8bef9SDimitry Andric                                       LLVMOrcResourceTrackerRef DstRT);
330e8d8bef9SDimitry Andric 
331e8d8bef9SDimitry Andric /**
332e8d8bef9SDimitry Andric  * Remove all resources associated with the given tracker. See
333e8d8bef9SDimitry Andric  * ResourceTracker::remove().
334e8d8bef9SDimitry Andric  */
335e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcResourceTrackerRemove(LLVMOrcResourceTrackerRef RT);
336e8d8bef9SDimitry Andric 
3375ffd83dbSDimitry Andric /**
3385ffd83dbSDimitry Andric  * Dispose of a JITDylib::DefinitionGenerator. This should only be called if
3395ffd83dbSDimitry Andric  * ownership has not been passed to a JITDylib (e.g. because some error
3405ffd83dbSDimitry Andric  * prevented the client from calling LLVMOrcJITDylibAddGenerator).
3415ffd83dbSDimitry Andric  */
342*d409305fSDimitry Andric void LLVMOrcDisposeDefinitionGenerator(LLVMOrcDefinitionGeneratorRef DG);
3435ffd83dbSDimitry Andric 
3445ffd83dbSDimitry Andric /**
345e8d8bef9SDimitry Andric  * Dispose of a MaterializationUnit.
346e8d8bef9SDimitry Andric  */
347e8d8bef9SDimitry Andric void LLVMOrcDisposeMaterializationUnit(LLVMOrcMaterializationUnitRef MU);
348e8d8bef9SDimitry Andric 
349e8d8bef9SDimitry Andric /**
350e8d8bef9SDimitry Andric  * Create a MaterializationUnit to define the given symbols as pointing to
351e8d8bef9SDimitry Andric  * the corresponding raw addresses.
352e8d8bef9SDimitry Andric  */
353e8d8bef9SDimitry Andric LLVMOrcMaterializationUnitRef
354e8d8bef9SDimitry Andric LLVMOrcAbsoluteSymbols(LLVMOrcCSymbolMapPairs Syms, size_t NumPairs);
355e8d8bef9SDimitry Andric 
356e8d8bef9SDimitry Andric /**
357e8d8bef9SDimitry Andric  * Create a "bare" JITDylib.
358e8d8bef9SDimitry Andric  *
359e8d8bef9SDimitry Andric  * The client is responsible for ensuring that the JITDylib's name is unique,
360e8d8bef9SDimitry Andric  * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first.
361e8d8bef9SDimitry Andric  *
362e8d8bef9SDimitry Andric  * This call does not install any library code or symbols into the newly
363e8d8bef9SDimitry Andric  * created JITDylib. The client is responsible for all configuration.
364e8d8bef9SDimitry Andric  */
365e8d8bef9SDimitry Andric LLVMOrcJITDylibRef
366e8d8bef9SDimitry Andric LLVMOrcExecutionSessionCreateBareJITDylib(LLVMOrcExecutionSessionRef ES,
367e8d8bef9SDimitry Andric                                           const char *Name);
368e8d8bef9SDimitry Andric 
369e8d8bef9SDimitry Andric /**
370e8d8bef9SDimitry Andric  * Create a JITDylib.
371e8d8bef9SDimitry Andric  *
372e8d8bef9SDimitry Andric  * The client is responsible for ensuring that the JITDylib's name is unique,
373e8d8bef9SDimitry Andric  * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first.
374e8d8bef9SDimitry Andric  *
375e8d8bef9SDimitry Andric  * If a Platform is attached to the ExecutionSession then
376e8d8bef9SDimitry Andric  * Platform::setupJITDylib will be called to install standard platform symbols
377e8d8bef9SDimitry Andric  * (e.g. standard library interposes). If no Platform is installed then this
378e8d8bef9SDimitry Andric  * call is equivalent to LLVMExecutionSessionRefCreateBareJITDylib and will
379e8d8bef9SDimitry Andric  * always return success.
380e8d8bef9SDimitry Andric  */
381e8d8bef9SDimitry Andric LLVMErrorRef
382e8d8bef9SDimitry Andric LLVMOrcExecutionSessionCreateJITDylib(LLVMOrcExecutionSessionRef ES,
383e8d8bef9SDimitry Andric                                       LLVMOrcJITDylibRef *Result,
384e8d8bef9SDimitry Andric                                       const char *Name);
385e8d8bef9SDimitry Andric 
386e8d8bef9SDimitry Andric /**
387e8d8bef9SDimitry Andric  * Returns the JITDylib with the given name, or NULL if no such JITDylib
388e8d8bef9SDimitry Andric  * exists.
389e8d8bef9SDimitry Andric  */
390*d409305fSDimitry Andric LLVMOrcJITDylibRef
391*d409305fSDimitry Andric LLVMOrcExecutionSessionGetJITDylibByName(LLVMOrcExecutionSessionRef ES,
392*d409305fSDimitry Andric                                          const char *Name);
393e8d8bef9SDimitry Andric 
394e8d8bef9SDimitry Andric /**
395e8d8bef9SDimitry Andric  * Return a reference to a newly created resource tracker associated with JD.
396e8d8bef9SDimitry Andric  * The tracker is returned with an initial ref-count of 1, and must be released
397e8d8bef9SDimitry Andric  * with LLVMOrcReleaseResourceTracker when no longer needed.
398e8d8bef9SDimitry Andric  */
399e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef
400e8d8bef9SDimitry Andric LLVMOrcJITDylibCreateResourceTracker(LLVMOrcJITDylibRef JD);
401e8d8bef9SDimitry Andric 
402e8d8bef9SDimitry Andric /**
403e8d8bef9SDimitry Andric  * Return a reference to the default resource tracker for the given JITDylib.
404e8d8bef9SDimitry Andric  * This operation will increase the retain count of the tracker: Clients should
405e8d8bef9SDimitry Andric  * call LLVMOrcReleaseResourceTracker when the result is no longer needed.
406e8d8bef9SDimitry Andric  */
407e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef
408e8d8bef9SDimitry Andric LLVMOrcJITDylibGetDefaultResourceTracker(LLVMOrcJITDylibRef JD);
409e8d8bef9SDimitry Andric 
410e8d8bef9SDimitry Andric /**
411e8d8bef9SDimitry Andric  * Add the given MaterializationUnit to the given JITDylib.
412e8d8bef9SDimitry Andric  *
413e8d8bef9SDimitry Andric  * If this operation succeeds then JITDylib JD will take ownership of MU.
414e8d8bef9SDimitry Andric  * If the operation fails then ownership remains with the caller who should
415e8d8bef9SDimitry Andric  * call LLVMOrcDisposeMaterializationUnit to destroy it.
416e8d8bef9SDimitry Andric  */
417e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcJITDylibDefine(LLVMOrcJITDylibRef JD,
418e8d8bef9SDimitry Andric                                    LLVMOrcMaterializationUnitRef MU);
419e8d8bef9SDimitry Andric 
420e8d8bef9SDimitry Andric /**
421e8d8bef9SDimitry Andric  * Calls remove on all trackers associated with this JITDylib, see
422e8d8bef9SDimitry Andric  * JITDylib::clear().
423e8d8bef9SDimitry Andric  */
424e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcJITDylibClear(LLVMOrcJITDylibRef JD);
425e8d8bef9SDimitry Andric 
426e8d8bef9SDimitry Andric /**
427e8d8bef9SDimitry Andric  * Add a DefinitionGenerator to the given JITDylib.
4285ffd83dbSDimitry Andric  *
4295ffd83dbSDimitry Andric  * The JITDylib will take ownership of the given generator: The client is no
4305ffd83dbSDimitry Andric  * longer responsible for managing its memory.
4315ffd83dbSDimitry Andric  */
4325ffd83dbSDimitry Andric void LLVMOrcJITDylibAddGenerator(LLVMOrcJITDylibRef JD,
433e8d8bef9SDimitry Andric                                  LLVMOrcDefinitionGeneratorRef DG);
434e8d8bef9SDimitry Andric 
435e8d8bef9SDimitry Andric /**
436e8d8bef9SDimitry Andric  * Create a custom generator.
437e8d8bef9SDimitry Andric  */
438e8d8bef9SDimitry Andric LLVMOrcDefinitionGeneratorRef LLVMOrcCreateCustomCAPIDefinitionGenerator(
439e8d8bef9SDimitry Andric     LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction F, void *Ctx);
4405ffd83dbSDimitry Andric 
4415ffd83dbSDimitry Andric /**
4425ffd83dbSDimitry Andric  * Get a DynamicLibrarySearchGenerator that will reflect process symbols into
4435ffd83dbSDimitry Andric  * the JITDylib. On success the resulting generator is owned by the client.
4445ffd83dbSDimitry Andric  * Ownership is typically transferred by adding the instance to a JITDylib
4455ffd83dbSDimitry Andric  * using LLVMOrcJITDylibAddGenerator,
4465ffd83dbSDimitry Andric  *
4475ffd83dbSDimitry Andric  * The GlobalPrefix argument specifies the character that appears on the front
4485ffd83dbSDimitry Andric  * of linker-mangled symbols for the target platform (e.g. '_' on MachO).
4495ffd83dbSDimitry Andric  * If non-null, this character will be stripped from the start of all symbol
4505ffd83dbSDimitry Andric  * strings before passing the remaining substring to dlsym.
4515ffd83dbSDimitry Andric  *
4525ffd83dbSDimitry Andric  * The optional Filter and Ctx arguments can be used to supply a symbol name
4535ffd83dbSDimitry Andric  * filter: Only symbols for which the filter returns true will be visible to
4545ffd83dbSDimitry Andric  * JIT'd code. If the Filter argument is null then all process symbols will
4555ffd83dbSDimitry Andric  * be visible to JIT'd code. Note that the symbol name passed to the Filter
4565ffd83dbSDimitry Andric  * function is the full mangled symbol: The client is responsible for stripping
4575ffd83dbSDimitry Andric  * the global prefix if present.
4585ffd83dbSDimitry Andric  */
4595ffd83dbSDimitry Andric LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess(
460e8d8bef9SDimitry Andric     LLVMOrcDefinitionGeneratorRef *Result, char GlobalPrefx,
4615ffd83dbSDimitry Andric     LLVMOrcSymbolPredicate Filter, void *FilterCtx);
4625ffd83dbSDimitry Andric 
4635ffd83dbSDimitry Andric /**
4645ffd83dbSDimitry Andric  * Create a ThreadSafeContext containing a new LLVMContext.
4655ffd83dbSDimitry Andric  *
4665ffd83dbSDimitry Andric  * Ownership of the underlying ThreadSafeContext data is shared: Clients
4675ffd83dbSDimitry Andric  * can and should dispose of their ThreadSafeContext as soon as they no longer
468e8d8bef9SDimitry Andric  * need to refer to it directly. Other references (e.g. from ThreadSafeModules)
4695ffd83dbSDimitry Andric  * will keep the data alive as long as it is needed.
4705ffd83dbSDimitry Andric  */
4715ffd83dbSDimitry Andric LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void);
4725ffd83dbSDimitry Andric 
4735ffd83dbSDimitry Andric /**
4745ffd83dbSDimitry Andric  * Get a reference to the wrapped LLVMContext.
4755ffd83dbSDimitry Andric  */
4765ffd83dbSDimitry Andric LLVMContextRef
4775ffd83dbSDimitry Andric LLVMOrcThreadSafeContextGetContext(LLVMOrcThreadSafeContextRef TSCtx);
4785ffd83dbSDimitry Andric 
4795ffd83dbSDimitry Andric /**
4805ffd83dbSDimitry Andric  * Dispose of a ThreadSafeContext.
4815ffd83dbSDimitry Andric  */
4825ffd83dbSDimitry Andric void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx);
4835ffd83dbSDimitry Andric 
4845ffd83dbSDimitry Andric /**
4855ffd83dbSDimitry Andric  * Create a ThreadSafeModule wrapper around the given LLVM module. This takes
4865ffd83dbSDimitry Andric  * ownership of the M argument which should not be disposed of or referenced
4875ffd83dbSDimitry Andric  * after this function returns.
4885ffd83dbSDimitry Andric  *
4895ffd83dbSDimitry Andric  * Ownership of the ThreadSafeModule is unique: If it is transferred to the JIT
490e8d8bef9SDimitry Andric  * (e.g. by LLVMOrcLLJITAddLLVMIRModule) then the client is no longer
4915ffd83dbSDimitry Andric  * responsible for it. If it is not transferred to the JIT then the client
4925ffd83dbSDimitry Andric  * should call LLVMOrcDisposeThreadSafeModule to dispose of it.
4935ffd83dbSDimitry Andric  */
4945ffd83dbSDimitry Andric LLVMOrcThreadSafeModuleRef
4955ffd83dbSDimitry Andric LLVMOrcCreateNewThreadSafeModule(LLVMModuleRef M,
4965ffd83dbSDimitry Andric                                  LLVMOrcThreadSafeContextRef TSCtx);
4975ffd83dbSDimitry Andric 
4985ffd83dbSDimitry Andric /**
4995ffd83dbSDimitry Andric  * Dispose of a ThreadSafeModule. This should only be called if ownership has
5005ffd83dbSDimitry Andric  * not been passed to LLJIT (e.g. because some error prevented the client from
5015ffd83dbSDimitry Andric  * adding this to the JIT).
5025ffd83dbSDimitry Andric  */
5035ffd83dbSDimitry Andric void LLVMOrcDisposeThreadSafeModule(LLVMOrcThreadSafeModuleRef TSM);
5045ffd83dbSDimitry Andric 
5055ffd83dbSDimitry Andric /**
5065ffd83dbSDimitry Andric  * Create a JITTargetMachineBuilder by detecting the host.
5075ffd83dbSDimitry Andric  *
5085ffd83dbSDimitry Andric  * On success the client owns the resulting JITTargetMachineBuilder. It must be
5095ffd83dbSDimitry Andric  * passed to a consuming operation (e.g. LLVMOrcCreateLLJITBuilder) or disposed
5105ffd83dbSDimitry Andric  * of by calling LLVMOrcDisposeJITTargetMachineBuilder.
5115ffd83dbSDimitry Andric  */
5125ffd83dbSDimitry Andric LLVMErrorRef LLVMOrcJITTargetMachineBuilderDetectHost(
5135ffd83dbSDimitry Andric     LLVMOrcJITTargetMachineBuilderRef *Result);
5145ffd83dbSDimitry Andric 
5155ffd83dbSDimitry Andric /**
5165ffd83dbSDimitry Andric  * Create a JITTargetMachineBuilder from the given TargetMachine template.
5175ffd83dbSDimitry Andric  *
5185ffd83dbSDimitry Andric  * This operation takes ownership of the given TargetMachine and destroys it
5195ffd83dbSDimitry Andric  * before returing. The resulting JITTargetMachineBuilder is owned by the client
5205ffd83dbSDimitry Andric  * and must be passed to a consuming operation (e.g. LLVMOrcCreateLLJITBuilder)
5215ffd83dbSDimitry Andric  * or disposed of by calling LLVMOrcDisposeJITTargetMachineBuilder.
5225ffd83dbSDimitry Andric  */
5235ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderRef
5245ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(LLVMTargetMachineRef TM);
5255ffd83dbSDimitry Andric 
5265ffd83dbSDimitry Andric /**
5275ffd83dbSDimitry Andric  * Dispose of a JITTargetMachineBuilder.
5285ffd83dbSDimitry Andric  */
5295ffd83dbSDimitry Andric void LLVMOrcDisposeJITTargetMachineBuilder(
5305ffd83dbSDimitry Andric     LLVMOrcJITTargetMachineBuilderRef JTMB);
5315ffd83dbSDimitry Andric 
5325ffd83dbSDimitry Andric /**
533e8d8bef9SDimitry Andric  * Dispose of an ObjectLayer.
5345ffd83dbSDimitry Andric  */
535e8d8bef9SDimitry Andric void LLVMOrcDisposeObjectLayer(LLVMOrcObjectLayerRef ObjLayer);
5365ffd83dbSDimitry Andric 
5375ffd83dbSDimitry Andric LLVM_C_EXTERN_C_END
5385ffd83dbSDimitry Andric 
5395ffd83dbSDimitry Andric #endif /* LLVM_C_ORC_H */
540