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