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