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 /** 37349cc55cSDimitry Andric * @defgroup LLVMCExecutionEngineORC On-Request-Compilation 38349cc55cSDimitry Andric * @ingroup LLVMCExecutionEngine 39349cc55cSDimitry Andric * 40349cc55cSDimitry Andric * @{ 41349cc55cSDimitry Andric */ 42349cc55cSDimitry Andric 43349cc55cSDimitry Andric /** 44fe6060f1SDimitry Andric * Represents an address in the executor process. 455ffd83dbSDimitry Andric */ 465ffd83dbSDimitry Andric typedef uint64_t LLVMOrcJITTargetAddress; 475ffd83dbSDimitry Andric 485ffd83dbSDimitry Andric /** 49fe6060f1SDimitry Andric * Represents an address in the executor process. 50fe6060f1SDimitry Andric */ 51fe6060f1SDimitry Andric typedef uint64_t LLVMOrcExecutorAddress; 52fe6060f1SDimitry Andric 53fe6060f1SDimitry Andric /** 54e8d8bef9SDimitry Andric * Represents generic linkage flags for a symbol definition. 55e8d8bef9SDimitry Andric */ 56e8d8bef9SDimitry Andric typedef enum { 5781ad6265SDimitry Andric LLVMJITSymbolGenericFlagsNone = 0, 58e8d8bef9SDimitry Andric LLVMJITSymbolGenericFlagsExported = 1U << 0, 59fe6060f1SDimitry Andric LLVMJITSymbolGenericFlagsWeak = 1U << 1, 60fe6060f1SDimitry Andric LLVMJITSymbolGenericFlagsCallable = 1U << 2, 61fe6060f1SDimitry Andric LLVMJITSymbolGenericFlagsMaterializationSideEffectsOnly = 1U << 3 62e8d8bef9SDimitry Andric } LLVMJITSymbolGenericFlags; 63e8d8bef9SDimitry Andric 64e8d8bef9SDimitry Andric /** 65e8d8bef9SDimitry Andric * Represents target specific flags for a symbol definition. 66e8d8bef9SDimitry Andric */ 67fe6060f1SDimitry Andric typedef uint8_t LLVMJITSymbolTargetFlags; 68e8d8bef9SDimitry Andric 69e8d8bef9SDimitry Andric /** 70e8d8bef9SDimitry Andric * Represents the linkage flags for a symbol definition. 71e8d8bef9SDimitry Andric */ 72e8d8bef9SDimitry Andric typedef struct { 73e8d8bef9SDimitry Andric uint8_t GenericFlags; 74e8d8bef9SDimitry Andric uint8_t TargetFlags; 75e8d8bef9SDimitry Andric } LLVMJITSymbolFlags; 76e8d8bef9SDimitry Andric 77e8d8bef9SDimitry Andric /** 78e8d8bef9SDimitry Andric * Represents an evaluated symbol address and flags. 79e8d8bef9SDimitry Andric */ 80e8d8bef9SDimitry Andric typedef struct { 81fe6060f1SDimitry Andric LLVMOrcExecutorAddress Address; 82e8d8bef9SDimitry Andric LLVMJITSymbolFlags Flags; 83e8d8bef9SDimitry Andric } LLVMJITEvaluatedSymbol; 84e8d8bef9SDimitry Andric 85e8d8bef9SDimitry Andric /** 865ffd83dbSDimitry Andric * A reference to an orc::ExecutionSession instance. 875ffd83dbSDimitry Andric */ 885ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueExecutionSession *LLVMOrcExecutionSessionRef; 895ffd83dbSDimitry Andric 905ffd83dbSDimitry Andric /** 91e8d8bef9SDimitry Andric * Error reporter function. 92e8d8bef9SDimitry Andric */ 93e8d8bef9SDimitry Andric typedef void (*LLVMOrcErrorReporterFunction)(void *Ctx, LLVMErrorRef Err); 94e8d8bef9SDimitry Andric 95e8d8bef9SDimitry Andric /** 96e8d8bef9SDimitry Andric * A reference to an orc::SymbolStringPool. 97e8d8bef9SDimitry Andric */ 98e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueSymbolStringPool *LLVMOrcSymbolStringPoolRef; 99e8d8bef9SDimitry Andric 100e8d8bef9SDimitry Andric /** 1015ffd83dbSDimitry Andric * A reference to an orc::SymbolStringPool table entry. 1025ffd83dbSDimitry Andric */ 103e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueSymbolStringPoolEntry 1045ffd83dbSDimitry Andric *LLVMOrcSymbolStringPoolEntryRef; 1055ffd83dbSDimitry Andric 1065ffd83dbSDimitry Andric /** 107fe6060f1SDimitry Andric * Represents a pair of a symbol name and LLVMJITSymbolFlags. 108fe6060f1SDimitry Andric */ 109fe6060f1SDimitry Andric typedef struct { 110fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef Name; 111fe6060f1SDimitry Andric LLVMJITSymbolFlags Flags; 112fe6060f1SDimitry Andric } LLVMOrcCSymbolFlagsMapPair; 113fe6060f1SDimitry Andric 114fe6060f1SDimitry Andric /** 115fe6060f1SDimitry Andric * Represents a list of (SymbolStringPtr, JITSymbolFlags) pairs that can be used 116fe6060f1SDimitry Andric * to construct a SymbolFlagsMap. 117fe6060f1SDimitry Andric */ 118fe6060f1SDimitry Andric typedef LLVMOrcCSymbolFlagsMapPair *LLVMOrcCSymbolFlagsMapPairs; 119fe6060f1SDimitry Andric 120fe6060f1SDimitry Andric /** 121e8d8bef9SDimitry Andric * Represents a pair of a symbol name and an evaluated symbol. 122e8d8bef9SDimitry Andric */ 123e8d8bef9SDimitry Andric typedef struct { 124e8d8bef9SDimitry Andric LLVMOrcSymbolStringPoolEntryRef Name; 125e8d8bef9SDimitry Andric LLVMJITEvaluatedSymbol Sym; 12681ad6265SDimitry Andric } LLVMOrcCSymbolMapPair; 127e8d8bef9SDimitry Andric 128e8d8bef9SDimitry Andric /** 129e8d8bef9SDimitry Andric * Represents a list of (SymbolStringPtr, JITEvaluatedSymbol) pairs that can be 130e8d8bef9SDimitry Andric * used to construct a SymbolMap. 131e8d8bef9SDimitry Andric */ 13281ad6265SDimitry Andric typedef LLVMOrcCSymbolMapPair *LLVMOrcCSymbolMapPairs; 133e8d8bef9SDimitry Andric 134e8d8bef9SDimitry Andric /** 135fe6060f1SDimitry Andric * Represents a SymbolAliasMapEntry 136fe6060f1SDimitry Andric */ 137fe6060f1SDimitry Andric typedef struct { 138fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef Name; 139fe6060f1SDimitry Andric LLVMJITSymbolFlags Flags; 140fe6060f1SDimitry Andric } LLVMOrcCSymbolAliasMapEntry; 141fe6060f1SDimitry Andric 142fe6060f1SDimitry Andric /** 143fe6060f1SDimitry Andric * Represents a pair of a symbol name and SymbolAliasMapEntry. 144fe6060f1SDimitry Andric */ 145fe6060f1SDimitry Andric typedef struct { 146fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef Name; 147fe6060f1SDimitry Andric LLVMOrcCSymbolAliasMapEntry Entry; 148fe6060f1SDimitry Andric } LLVMOrcCSymbolAliasMapPair; 149fe6060f1SDimitry Andric 150fe6060f1SDimitry Andric /** 151fe6060f1SDimitry Andric * Represents a list of (SymbolStringPtr, (SymbolStringPtr, JITSymbolFlags)) 152fe6060f1SDimitry Andric * pairs that can be used to construct a SymbolFlagsMap. 153fe6060f1SDimitry Andric */ 154fe6060f1SDimitry Andric typedef LLVMOrcCSymbolAliasMapPair *LLVMOrcCSymbolAliasMapPairs; 155fe6060f1SDimitry Andric 156fe6060f1SDimitry Andric /** 157fe6060f1SDimitry Andric * A reference to an orc::JITDylib instance. 158fe6060f1SDimitry Andric */ 159fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueJITDylib *LLVMOrcJITDylibRef; 160fe6060f1SDimitry Andric 161fe6060f1SDimitry Andric /** 162fe6060f1SDimitry Andric * Represents a list of LLVMOrcSymbolStringPoolEntryRef and the associated 163fe6060f1SDimitry Andric * length. 164fe6060f1SDimitry Andric */ 165fe6060f1SDimitry Andric typedef struct { 166fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef *Symbols; 167fe6060f1SDimitry Andric size_t Length; 168fe6060f1SDimitry Andric } LLVMOrcCSymbolsList; 169fe6060f1SDimitry Andric 170fe6060f1SDimitry Andric /** 171fe6060f1SDimitry Andric * Represents a pair of a JITDylib and LLVMOrcCSymbolsList. 172fe6060f1SDimitry Andric */ 173fe6060f1SDimitry Andric typedef struct { 174fe6060f1SDimitry Andric LLVMOrcJITDylibRef JD; 175fe6060f1SDimitry Andric LLVMOrcCSymbolsList Names; 176fe6060f1SDimitry Andric } LLVMOrcCDependenceMapPair; 177fe6060f1SDimitry Andric 178fe6060f1SDimitry Andric /** 179fe6060f1SDimitry Andric * Represents a list of (JITDylibRef, (LLVMOrcSymbolStringPoolEntryRef*, 180fe6060f1SDimitry Andric * size_t)) pairs that can be used to construct a SymbolDependenceMap. 181fe6060f1SDimitry Andric */ 182fe6060f1SDimitry Andric typedef LLVMOrcCDependenceMapPair *LLVMOrcCDependenceMapPairs; 183fe6060f1SDimitry Andric 184fe6060f1SDimitry Andric /** 185e8d8bef9SDimitry Andric * Lookup kind. This can be used by definition generators when deciding whether 186e8d8bef9SDimitry Andric * to produce a definition for a requested symbol. 187e8d8bef9SDimitry Andric * 188e8d8bef9SDimitry Andric * This enum should be kept in sync with llvm::orc::LookupKind. 189e8d8bef9SDimitry Andric */ 190e8d8bef9SDimitry Andric typedef enum { 191e8d8bef9SDimitry Andric LLVMOrcLookupKindStatic, 192e8d8bef9SDimitry Andric LLVMOrcLookupKindDLSym 193e8d8bef9SDimitry Andric } LLVMOrcLookupKind; 194e8d8bef9SDimitry Andric 195e8d8bef9SDimitry Andric /** 196e8d8bef9SDimitry Andric * JITDylib lookup flags. This can be used by definition generators when 197e8d8bef9SDimitry Andric * deciding whether to produce a definition for a requested symbol. 198e8d8bef9SDimitry Andric * 199e8d8bef9SDimitry Andric * This enum should be kept in sync with llvm::orc::JITDylibLookupFlags. 200e8d8bef9SDimitry Andric */ 201e8d8bef9SDimitry Andric typedef enum { 202e8d8bef9SDimitry Andric LLVMOrcJITDylibLookupFlagsMatchExportedSymbolsOnly, 203e8d8bef9SDimitry Andric LLVMOrcJITDylibLookupFlagsMatchAllSymbols 204e8d8bef9SDimitry Andric } LLVMOrcJITDylibLookupFlags; 205e8d8bef9SDimitry Andric 206e8d8bef9SDimitry Andric /** 20781ad6265SDimitry Andric * An element type for a JITDylib search order. 20881ad6265SDimitry Andric */ 20981ad6265SDimitry Andric typedef struct { 21081ad6265SDimitry Andric LLVMOrcJITDylibRef JD; 21181ad6265SDimitry Andric LLVMOrcJITDylibLookupFlags JDLookupFlags; 21281ad6265SDimitry Andric } LLVMOrcCJITDylibSearchOrderElement; 21381ad6265SDimitry Andric 21481ad6265SDimitry Andric /** 21581ad6265SDimitry Andric * A JITDylib search order. 21681ad6265SDimitry Andric * 21781ad6265SDimitry Andric * The list is terminated with an element containing a null pointer for the JD 21881ad6265SDimitry Andric * field. 21981ad6265SDimitry Andric */ 22081ad6265SDimitry Andric typedef LLVMOrcCJITDylibSearchOrderElement *LLVMOrcCJITDylibSearchOrder; 22181ad6265SDimitry Andric 22281ad6265SDimitry Andric /** 223e8d8bef9SDimitry Andric * Symbol lookup flags for lookup sets. This should be kept in sync with 224e8d8bef9SDimitry Andric * llvm::orc::SymbolLookupFlags. 225e8d8bef9SDimitry Andric */ 226e8d8bef9SDimitry Andric typedef enum { 227e8d8bef9SDimitry Andric LLVMOrcSymbolLookupFlagsRequiredSymbol, 228e8d8bef9SDimitry Andric LLVMOrcSymbolLookupFlagsWeaklyReferencedSymbol 229e8d8bef9SDimitry Andric } LLVMOrcSymbolLookupFlags; 230e8d8bef9SDimitry Andric 231e8d8bef9SDimitry Andric /** 232e8d8bef9SDimitry Andric * An element type for a symbol lookup set. 233e8d8bef9SDimitry Andric */ 234e8d8bef9SDimitry Andric typedef struct { 235e8d8bef9SDimitry Andric LLVMOrcSymbolStringPoolEntryRef Name; 236e8d8bef9SDimitry Andric LLVMOrcSymbolLookupFlags LookupFlags; 237e8d8bef9SDimitry Andric } LLVMOrcCLookupSetElement; 238e8d8bef9SDimitry Andric 239e8d8bef9SDimitry Andric /** 240e8d8bef9SDimitry Andric * A set of symbols to look up / generate. 241e8d8bef9SDimitry Andric * 242e8d8bef9SDimitry Andric * The list is terminated with an element containing a null pointer for the 243e8d8bef9SDimitry Andric * Name field. 244e8d8bef9SDimitry Andric * 245e8d8bef9SDimitry Andric * If a client creates an instance of this type then they are responsible for 246e8d8bef9SDimitry Andric * freeing it, and for ensuring that all strings have been retained over the 247e8d8bef9SDimitry Andric * course of its life. Clients receiving a copy from a callback are not 248e8d8bef9SDimitry Andric * responsible for managing lifetime or retain counts. 249e8d8bef9SDimitry Andric */ 250e8d8bef9SDimitry Andric typedef LLVMOrcCLookupSetElement *LLVMOrcCLookupSet; 251e8d8bef9SDimitry Andric 252e8d8bef9SDimitry Andric /** 253fe6060f1SDimitry Andric * A reference to a uniquely owned orc::MaterializationUnit instance. 254e8d8bef9SDimitry Andric */ 255e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueMaterializationUnit *LLVMOrcMaterializationUnitRef; 256e8d8bef9SDimitry Andric 257e8d8bef9SDimitry Andric /** 258fe6060f1SDimitry Andric * A reference to a uniquely owned orc::MaterializationResponsibility instance. 259fe6060f1SDimitry Andric * 260fe6060f1SDimitry Andric * Ownership must be passed to a lower-level layer in a JIT stack. 2615ffd83dbSDimitry Andric */ 262fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueMaterializationResponsibility 263fe6060f1SDimitry Andric *LLVMOrcMaterializationResponsibilityRef; 264fe6060f1SDimitry Andric 265fe6060f1SDimitry Andric /** 266fe6060f1SDimitry Andric * A MaterializationUnit materialize callback. 267fe6060f1SDimitry Andric * 268fe6060f1SDimitry Andric * Ownership of the Ctx and MR arguments passes to the callback which must 269fe6060f1SDimitry Andric * adhere to the LLVMOrcMaterializationResponsibilityRef contract (see comment 270fe6060f1SDimitry Andric * for that type). 271fe6060f1SDimitry Andric * 272fe6060f1SDimitry Andric * If this callback is called then the LLVMOrcMaterializationUnitDestroy 273fe6060f1SDimitry Andric * callback will NOT be called. 274fe6060f1SDimitry Andric */ 275fe6060f1SDimitry Andric typedef void (*LLVMOrcMaterializationUnitMaterializeFunction)( 276fe6060f1SDimitry Andric void *Ctx, LLVMOrcMaterializationResponsibilityRef MR); 277fe6060f1SDimitry Andric 278fe6060f1SDimitry Andric /** 279fe6060f1SDimitry Andric * A MaterializationUnit discard callback. 280fe6060f1SDimitry Andric * 281fe6060f1SDimitry Andric * Ownership of JD and Symbol remain with the caller: These arguments should 282fe6060f1SDimitry Andric * not be disposed of or released. 283fe6060f1SDimitry Andric */ 284fe6060f1SDimitry Andric typedef void (*LLVMOrcMaterializationUnitDiscardFunction)( 285fe6060f1SDimitry Andric void *Ctx, LLVMOrcJITDylibRef JD, LLVMOrcSymbolStringPoolEntryRef Symbol); 286fe6060f1SDimitry Andric 287fe6060f1SDimitry Andric /** 288fe6060f1SDimitry Andric * A MaterializationUnit destruction callback. 289fe6060f1SDimitry Andric * 290fe6060f1SDimitry Andric * If a custom MaterializationUnit is destroyed before its Materialize 291fe6060f1SDimitry Andric * function is called then this function will be called to provide an 292fe6060f1SDimitry Andric * opportunity for the underlying program representation to be destroyed. 293fe6060f1SDimitry Andric */ 294fe6060f1SDimitry Andric typedef void (*LLVMOrcMaterializationUnitDestroyFunction)(void *Ctx); 2955ffd83dbSDimitry Andric 2965ffd83dbSDimitry Andric /** 297e8d8bef9SDimitry Andric * A reference to an orc::ResourceTracker instance. 2985ffd83dbSDimitry Andric */ 299e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueResourceTracker *LLVMOrcResourceTrackerRef; 300e8d8bef9SDimitry Andric 301e8d8bef9SDimitry Andric /** 302e8d8bef9SDimitry Andric * A reference to an orc::DefinitionGenerator. 303e8d8bef9SDimitry Andric */ 304e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueDefinitionGenerator 305e8d8bef9SDimitry Andric *LLVMOrcDefinitionGeneratorRef; 306e8d8bef9SDimitry Andric 307e8d8bef9SDimitry Andric /** 308e8d8bef9SDimitry Andric * An opaque lookup state object. Instances of this type can be captured to 309e8d8bef9SDimitry Andric * suspend a lookup while a custom generator function attempts to produce a 310e8d8bef9SDimitry Andric * definition. 311e8d8bef9SDimitry Andric * 312e8d8bef9SDimitry Andric * If a client captures a lookup state object then they must eventually call 313e8d8bef9SDimitry Andric * LLVMOrcLookupStateContinueLookup to restart the lookup. This is required 314e8d8bef9SDimitry Andric * in order to release memory allocated for the lookup state, even if errors 315e8d8bef9SDimitry Andric * have occurred while the lookup was suspended (if these errors have made the 316e8d8bef9SDimitry Andric * lookup impossible to complete then it will issue its own error before 317e8d8bef9SDimitry Andric * destruction). 318e8d8bef9SDimitry Andric */ 319e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueLookupState *LLVMOrcLookupStateRef; 320e8d8bef9SDimitry Andric 321e8d8bef9SDimitry Andric /** 322e8d8bef9SDimitry Andric * A custom generator function. This can be used to create a custom generator 323e8d8bef9SDimitry Andric * object using LLVMOrcCreateCustomCAPIDefinitionGenerator. The resulting 324e8d8bef9SDimitry Andric * object can be attached to a JITDylib, via LLVMOrcJITDylibAddGenerator, to 325e8d8bef9SDimitry Andric * receive callbacks when lookups fail to match existing definitions. 326e8d8bef9SDimitry Andric * 327e8d8bef9SDimitry Andric * GeneratorObj will contain the address of the custom generator object. 328e8d8bef9SDimitry Andric * 329e8d8bef9SDimitry Andric * Ctx will contain the context object passed to 330e8d8bef9SDimitry Andric * LLVMOrcCreateCustomCAPIDefinitionGenerator. 331e8d8bef9SDimitry Andric * 332e8d8bef9SDimitry Andric * LookupState will contain a pointer to an LLVMOrcLookupStateRef object. This 333e8d8bef9SDimitry Andric * can optionally be modified to make the definition generation process 334e8d8bef9SDimitry Andric * asynchronous: If the LookupStateRef value is copied, and the original 335e8d8bef9SDimitry Andric * LLVMOrcLookupStateRef set to null, the lookup will be suspended. Once the 336e8d8bef9SDimitry Andric * asynchronous definition process has been completed clients must call 337e8d8bef9SDimitry Andric * LLVMOrcLookupStateContinueLookup to continue the lookup (this should be 338e8d8bef9SDimitry Andric * done unconditionally, even if errors have occurred in the mean time, to 339fe6060f1SDimitry Andric * free the lookup state memory and notify the query object of the failures). 340fe6060f1SDimitry Andric * If LookupState is captured this function must return LLVMErrorSuccess. 341e8d8bef9SDimitry Andric * 342e8d8bef9SDimitry Andric * The Kind argument can be inspected to determine the lookup kind (e.g. 343e8d8bef9SDimitry Andric * as-if-during-static-link, or as-if-during-dlsym). 344e8d8bef9SDimitry Andric * 345e8d8bef9SDimitry Andric * The JD argument specifies which JITDylib the definitions should be generated 346e8d8bef9SDimitry Andric * into. 347e8d8bef9SDimitry Andric * 348e8d8bef9SDimitry Andric * The JDLookupFlags argument can be inspected to determine whether the original 349*5f757f3fSDimitry Andric * lookup included non-exported symbols. 350e8d8bef9SDimitry Andric * 351e8d8bef9SDimitry Andric * Finally, the LookupSet argument contains the set of symbols that could not 352e8d8bef9SDimitry Andric * be found in JD already (the set of generation candidates). 353e8d8bef9SDimitry Andric */ 354e8d8bef9SDimitry Andric typedef LLVMErrorRef (*LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction)( 355e8d8bef9SDimitry Andric LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx, 356e8d8bef9SDimitry Andric LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind, 357e8d8bef9SDimitry Andric LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags, 358e8d8bef9SDimitry Andric LLVMOrcCLookupSet LookupSet, size_t LookupSetSize); 3595ffd83dbSDimitry Andric 3605ffd83dbSDimitry Andric /** 36181ad6265SDimitry Andric * Disposer for a custom generator. 36281ad6265SDimitry Andric * 36381ad6265SDimitry Andric * Will be called by ORC when the JITDylib that the generator is attached to 36481ad6265SDimitry Andric * is destroyed. 36581ad6265SDimitry Andric */ 36681ad6265SDimitry Andric typedef void (*LLVMOrcDisposeCAPIDefinitionGeneratorFunction)(void *Ctx); 36781ad6265SDimitry Andric 36881ad6265SDimitry Andric /** 3695ffd83dbSDimitry Andric * Predicate function for SymbolStringPoolEntries. 3705ffd83dbSDimitry Andric */ 371e8d8bef9SDimitry Andric typedef int (*LLVMOrcSymbolPredicate)(void *Ctx, 372e8d8bef9SDimitry Andric LLVMOrcSymbolStringPoolEntryRef Sym); 3735ffd83dbSDimitry Andric 3745ffd83dbSDimitry Andric /** 3755ffd83dbSDimitry Andric * A reference to an orc::ThreadSafeContext instance. 3765ffd83dbSDimitry Andric */ 3775ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueThreadSafeContext *LLVMOrcThreadSafeContextRef; 3785ffd83dbSDimitry Andric 3795ffd83dbSDimitry Andric /** 3805ffd83dbSDimitry Andric * A reference to an orc::ThreadSafeModule instance. 3815ffd83dbSDimitry Andric */ 3825ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueThreadSafeModule *LLVMOrcThreadSafeModuleRef; 3835ffd83dbSDimitry Andric 3845ffd83dbSDimitry Andric /** 385fe6060f1SDimitry Andric * A function for inspecting/mutating IR modules, suitable for use with 386fe6060f1SDimitry Andric * LLVMOrcThreadSafeModuleWithModuleDo. 387fe6060f1SDimitry Andric */ 388fe6060f1SDimitry Andric typedef LLVMErrorRef (*LLVMOrcGenericIRModuleOperationFunction)( 389fe6060f1SDimitry Andric void *Ctx, LLVMModuleRef M); 390fe6060f1SDimitry Andric 391fe6060f1SDimitry Andric /** 3925ffd83dbSDimitry Andric * A reference to an orc::JITTargetMachineBuilder instance. 3935ffd83dbSDimitry Andric */ 3945ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueJITTargetMachineBuilder 3955ffd83dbSDimitry Andric *LLVMOrcJITTargetMachineBuilderRef; 3965ffd83dbSDimitry Andric 3975ffd83dbSDimitry Andric /** 398e8d8bef9SDimitry Andric * A reference to an orc::ObjectLayer instance. 3995ffd83dbSDimitry Andric */ 400e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueObjectLayer *LLVMOrcObjectLayerRef; 4015ffd83dbSDimitry Andric 4025ffd83dbSDimitry Andric /** 403fe6060f1SDimitry Andric * A reference to an orc::ObjectLinkingLayer instance. 404fe6060f1SDimitry Andric */ 405fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueObjectLinkingLayer *LLVMOrcObjectLinkingLayerRef; 406fe6060f1SDimitry Andric 407fe6060f1SDimitry Andric /** 408fe6060f1SDimitry Andric * A reference to an orc::IRTransformLayer instance. 409fe6060f1SDimitry Andric */ 410fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueIRTransformLayer *LLVMOrcIRTransformLayerRef; 411fe6060f1SDimitry Andric 412fe6060f1SDimitry Andric /** 413fe6060f1SDimitry Andric * A function for applying transformations as part of an transform layer. 414fe6060f1SDimitry Andric * 415fe6060f1SDimitry Andric * Implementations of this type are responsible for managing the lifetime 416fe6060f1SDimitry Andric * of the Module pointed to by ModInOut: If the LLVMModuleRef value is 417fe6060f1SDimitry Andric * overwritten then the function is responsible for disposing of the incoming 418fe6060f1SDimitry Andric * module. If the module is simply accessed/mutated in-place then ownership 419fe6060f1SDimitry Andric * returns to the caller and the function does not need to do any lifetime 420fe6060f1SDimitry Andric * management. 421fe6060f1SDimitry Andric * 422fe6060f1SDimitry Andric * Clients can call LLVMOrcLLJITGetIRTransformLayer to obtain the transform 423fe6060f1SDimitry Andric * layer of a LLJIT instance, and use LLVMOrcIRTransformLayerSetTransform 424fe6060f1SDimitry Andric * to set the function. This can be used to override the default transform 425fe6060f1SDimitry Andric * layer. 426fe6060f1SDimitry Andric */ 427fe6060f1SDimitry Andric typedef LLVMErrorRef (*LLVMOrcIRTransformLayerTransformFunction)( 428fe6060f1SDimitry Andric void *Ctx, LLVMOrcThreadSafeModuleRef *ModInOut, 429fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 430fe6060f1SDimitry Andric 431fe6060f1SDimitry Andric /** 432fe6060f1SDimitry Andric * A reference to an orc::ObjectTransformLayer instance. 433fe6060f1SDimitry Andric */ 434fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueObjectTransformLayer 435fe6060f1SDimitry Andric *LLVMOrcObjectTransformLayerRef; 436fe6060f1SDimitry Andric 437fe6060f1SDimitry Andric /** 438fe6060f1SDimitry Andric * A function for applying transformations to an object file buffer. 439fe6060f1SDimitry Andric * 440fe6060f1SDimitry Andric * Implementations of this type are responsible for managing the lifetime 441fe6060f1SDimitry Andric * of the memory buffer pointed to by ObjInOut: If the LLVMMemoryBufferRef 442fe6060f1SDimitry Andric * value is overwritten then the function is responsible for disposing of the 443fe6060f1SDimitry Andric * incoming buffer. If the buffer is simply accessed/mutated in-place then 444fe6060f1SDimitry Andric * ownership returns to the caller and the function does not need to do any 445fe6060f1SDimitry Andric * lifetime management. 446fe6060f1SDimitry Andric * 447fe6060f1SDimitry Andric * The transform is allowed to return an error, in which case the ObjInOut 448fe6060f1SDimitry Andric * buffer should be disposed of and set to null. 449fe6060f1SDimitry Andric */ 450fe6060f1SDimitry Andric typedef LLVMErrorRef (*LLVMOrcObjectTransformLayerTransformFunction)( 451fe6060f1SDimitry Andric void *Ctx, LLVMMemoryBufferRef *ObjInOut); 452fe6060f1SDimitry Andric 453fe6060f1SDimitry Andric /** 454fe6060f1SDimitry Andric * A reference to an orc::IndirectStubsManager instance. 455fe6060f1SDimitry Andric */ 456fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueIndirectStubsManager 457fe6060f1SDimitry Andric *LLVMOrcIndirectStubsManagerRef; 458fe6060f1SDimitry Andric 459fe6060f1SDimitry Andric /** 460fe6060f1SDimitry Andric * A reference to an orc::LazyCallThroughManager instance. 461fe6060f1SDimitry Andric */ 462fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueLazyCallThroughManager 463fe6060f1SDimitry Andric *LLVMOrcLazyCallThroughManagerRef; 464fe6060f1SDimitry Andric 465fe6060f1SDimitry Andric /** 466fe6060f1SDimitry Andric * A reference to an orc::DumpObjects object. 467fe6060f1SDimitry Andric * 468fe6060f1SDimitry Andric * Can be used to dump object files to disk with unique names. Useful as an 469fe6060f1SDimitry Andric * ObjectTransformLayer transform. 470fe6060f1SDimitry Andric */ 471fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueDumpObjects *LLVMOrcDumpObjectsRef; 472fe6060f1SDimitry Andric 473fe6060f1SDimitry Andric /** 474e8d8bef9SDimitry Andric * Attach a custom error reporter function to the ExecutionSession. 475e8d8bef9SDimitry Andric * 476e8d8bef9SDimitry Andric * The error reporter will be called to deliver failure notices that can not be 477e8d8bef9SDimitry Andric * directly reported to a caller. For example, failure to resolve symbols in 478e8d8bef9SDimitry Andric * the JIT linker is typically reported via the error reporter (callers 479e8d8bef9SDimitry Andric * requesting definitions from the JIT will typically be delivered a 480e8d8bef9SDimitry Andric * FailureToMaterialize error instead). 4815ffd83dbSDimitry Andric */ 482e8d8bef9SDimitry Andric void LLVMOrcExecutionSessionSetErrorReporter( 483e8d8bef9SDimitry Andric LLVMOrcExecutionSessionRef ES, LLVMOrcErrorReporterFunction ReportError, 484e8d8bef9SDimitry Andric void *Ctx); 485e8d8bef9SDimitry Andric 486e8d8bef9SDimitry Andric /** 487e8d8bef9SDimitry Andric * Return a reference to the SymbolStringPool for an ExecutionSession. 488e8d8bef9SDimitry Andric * 489e8d8bef9SDimitry Andric * Ownership of the pool remains with the ExecutionSession: The caller is 490e8d8bef9SDimitry Andric * not required to free the pool. 491e8d8bef9SDimitry Andric */ 492e8d8bef9SDimitry Andric LLVMOrcSymbolStringPoolRef 493e8d8bef9SDimitry Andric LLVMOrcExecutionSessionGetSymbolStringPool(LLVMOrcExecutionSessionRef ES); 494e8d8bef9SDimitry Andric 495e8d8bef9SDimitry Andric /** 496e8d8bef9SDimitry Andric * Clear all unreferenced symbol string pool entries. 497e8d8bef9SDimitry Andric * 498e8d8bef9SDimitry Andric * This can be called at any time to release unused entries in the 499e8d8bef9SDimitry Andric * ExecutionSession's string pool. Since it locks the pool (preventing 500e8d8bef9SDimitry Andric * interning of any new strings) it is recommended that it only be called 501e8d8bef9SDimitry Andric * infrequently, ideally when the caller has reason to believe that some 502e8d8bef9SDimitry Andric * entries will have become unreferenced, e.g. after removing a module or 503e8d8bef9SDimitry Andric * closing a JITDylib. 504e8d8bef9SDimitry Andric */ 505e8d8bef9SDimitry Andric void LLVMOrcSymbolStringPoolClearDeadEntries(LLVMOrcSymbolStringPoolRef SSP); 5065ffd83dbSDimitry Andric 5075ffd83dbSDimitry Andric /** 5085ffd83dbSDimitry Andric * Intern a string in the ExecutionSession's SymbolStringPool and return a 5095ffd83dbSDimitry Andric * reference to it. This increments the ref-count of the pool entry, and the 5105ffd83dbSDimitry Andric * returned value should be released once the client is done with it by 511*5f757f3fSDimitry Andric * calling LLVMOrcReleaseSymbolStringPoolEntry. 5125ffd83dbSDimitry Andric * 5135ffd83dbSDimitry Andric * Since strings are uniqued within the SymbolStringPool 5145ffd83dbSDimitry Andric * LLVMOrcSymbolStringPoolEntryRefs can be compared by value to test string 5155ffd83dbSDimitry Andric * equality. 5165ffd83dbSDimitry Andric * 5175ffd83dbSDimitry Andric * Note that this function does not perform linker-mangling on the string. 5185ffd83dbSDimitry Andric */ 5195ffd83dbSDimitry Andric LLVMOrcSymbolStringPoolEntryRef 5205ffd83dbSDimitry Andric LLVMOrcExecutionSessionIntern(LLVMOrcExecutionSessionRef ES, const char *Name); 5215ffd83dbSDimitry Andric 5225ffd83dbSDimitry Andric /** 52381ad6265SDimitry Andric * Callback type for ExecutionSession lookups. 52481ad6265SDimitry Andric * 52581ad6265SDimitry Andric * If Err is LLVMErrorSuccess then Result will contain a pointer to a 52681ad6265SDimitry Andric * list of ( SymbolStringPtr, JITEvaluatedSymbol ) pairs of length NumPairs. 52781ad6265SDimitry Andric * 52881ad6265SDimitry Andric * If Err is a failure value then Result and Ctx are undefined and should 52981ad6265SDimitry Andric * not be accessed. The Callback is responsible for handling the error 53081ad6265SDimitry Andric * value (e.g. by calling LLVMGetErrorMessage + LLVMDisposeErrorMessage). 53181ad6265SDimitry Andric * 53281ad6265SDimitry Andric * The caller retains ownership of the Result array and will release all 53381ad6265SDimitry Andric * contained symbol names. Clients are responsible for retaining any symbol 53481ad6265SDimitry Andric * names that they wish to hold after the function returns. 53581ad6265SDimitry Andric */ 53681ad6265SDimitry Andric typedef void (*LLVMOrcExecutionSessionLookupHandleResultFunction)( 53781ad6265SDimitry Andric LLVMErrorRef Err, LLVMOrcCSymbolMapPairs Result, size_t NumPairs, 53881ad6265SDimitry Andric void *Ctx); 53981ad6265SDimitry Andric 54081ad6265SDimitry Andric /** 54181ad6265SDimitry Andric * Look up symbols in an execution session. 54281ad6265SDimitry Andric * 54381ad6265SDimitry Andric * This is a wrapper around the general ExecutionSession::lookup function. 54481ad6265SDimitry Andric * 54581ad6265SDimitry Andric * The SearchOrder argument contains a list of (JITDylibs, JITDylibSearchFlags) 54681ad6265SDimitry Andric * pairs that describe the search order. The JITDylibs will be searched in the 54781ad6265SDimitry Andric * given order to try to find the symbols in the Symbols argument. 54881ad6265SDimitry Andric * 54981ad6265SDimitry Andric * The Symbols argument should contain a null-terminated array of 55081ad6265SDimitry Andric * (SymbolStringPtr, SymbolLookupFlags) pairs describing the symbols to be 55181ad6265SDimitry Andric * searched for. This function takes ownership of the elements of the Symbols 55281ad6265SDimitry Andric * array. The Name fields of the Symbols elements are taken to have been 55381ad6265SDimitry Andric * retained by the client for this function. The client should *not* release the 55481ad6265SDimitry Andric * Name fields, but are still responsible for destroying the array itself. 55581ad6265SDimitry Andric * 55681ad6265SDimitry Andric * The HandleResult function will be called once all searched for symbols have 55781ad6265SDimitry Andric * been found, or an error occurs. The HandleResult function will be passed an 55881ad6265SDimitry Andric * LLVMErrorRef indicating success or failure, and (on success) a 55981ad6265SDimitry Andric * null-terminated LLVMOrcCSymbolMapPairs array containing the function result, 56081ad6265SDimitry Andric * and the Ctx value passed to the lookup function. 56181ad6265SDimitry Andric * 56281ad6265SDimitry Andric * The client is fully responsible for managing the lifetime of the Ctx object. 56381ad6265SDimitry Andric * A common idiom is to allocate the context prior to the lookup and deallocate 56481ad6265SDimitry Andric * it in the handler. 56581ad6265SDimitry Andric * 56681ad6265SDimitry Andric * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE! 56781ad6265SDimitry Andric */ 56881ad6265SDimitry Andric void LLVMOrcExecutionSessionLookup( 56981ad6265SDimitry Andric LLVMOrcExecutionSessionRef ES, LLVMOrcLookupKind K, 57081ad6265SDimitry Andric LLVMOrcCJITDylibSearchOrder SearchOrder, size_t SearchOrderSize, 57181ad6265SDimitry Andric LLVMOrcCLookupSet Symbols, size_t SymbolsSize, 57281ad6265SDimitry Andric LLVMOrcExecutionSessionLookupHandleResultFunction HandleResult, void *Ctx); 57381ad6265SDimitry Andric 57481ad6265SDimitry Andric /** 575e8d8bef9SDimitry Andric * Increments the ref-count for a SymbolStringPool entry. 576e8d8bef9SDimitry Andric */ 577e8d8bef9SDimitry Andric void LLVMOrcRetainSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S); 578e8d8bef9SDimitry Andric 579e8d8bef9SDimitry Andric /** 5805ffd83dbSDimitry Andric * Reduces the ref-count for of a SymbolStringPool entry. 5815ffd83dbSDimitry Andric */ 5825ffd83dbSDimitry Andric void LLVMOrcReleaseSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S); 5835ffd83dbSDimitry Andric 58481ad6265SDimitry Andric /** 58581ad6265SDimitry Andric * Return the c-string for the given symbol. This string will remain valid until 58681ad6265SDimitry Andric * the entry is freed (once all LLVMOrcSymbolStringPoolEntryRefs have been 58781ad6265SDimitry Andric * released). 58881ad6265SDimitry Andric */ 589e8d8bef9SDimitry Andric const char *LLVMOrcSymbolStringPoolEntryStr(LLVMOrcSymbolStringPoolEntryRef S); 590e8d8bef9SDimitry Andric 591e8d8bef9SDimitry Andric /** 592e8d8bef9SDimitry Andric * Reduces the ref-count of a ResourceTracker. 593e8d8bef9SDimitry Andric */ 594e8d8bef9SDimitry Andric void LLVMOrcReleaseResourceTracker(LLVMOrcResourceTrackerRef RT); 595e8d8bef9SDimitry Andric 596e8d8bef9SDimitry Andric /** 597e8d8bef9SDimitry Andric * Transfers tracking of all resources associated with resource tracker SrcRT 598e8d8bef9SDimitry Andric * to resource tracker DstRT. 599e8d8bef9SDimitry Andric */ 600e8d8bef9SDimitry Andric void LLVMOrcResourceTrackerTransferTo(LLVMOrcResourceTrackerRef SrcRT, 601e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef DstRT); 602e8d8bef9SDimitry Andric 603e8d8bef9SDimitry Andric /** 604e8d8bef9SDimitry Andric * Remove all resources associated with the given tracker. See 605e8d8bef9SDimitry Andric * ResourceTracker::remove(). 606e8d8bef9SDimitry Andric */ 607e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcResourceTrackerRemove(LLVMOrcResourceTrackerRef RT); 608e8d8bef9SDimitry Andric 6095ffd83dbSDimitry Andric /** 6105ffd83dbSDimitry Andric * Dispose of a JITDylib::DefinitionGenerator. This should only be called if 6115ffd83dbSDimitry Andric * ownership has not been passed to a JITDylib (e.g. because some error 6125ffd83dbSDimitry Andric * prevented the client from calling LLVMOrcJITDylibAddGenerator). 6135ffd83dbSDimitry Andric */ 614d409305fSDimitry Andric void LLVMOrcDisposeDefinitionGenerator(LLVMOrcDefinitionGeneratorRef DG); 6155ffd83dbSDimitry Andric 6165ffd83dbSDimitry Andric /** 617e8d8bef9SDimitry Andric * Dispose of a MaterializationUnit. 618e8d8bef9SDimitry Andric */ 619e8d8bef9SDimitry Andric void LLVMOrcDisposeMaterializationUnit(LLVMOrcMaterializationUnitRef MU); 620e8d8bef9SDimitry Andric 621e8d8bef9SDimitry Andric /** 622fe6060f1SDimitry Andric * Create a custom MaterializationUnit. 623fe6060f1SDimitry Andric * 624fe6060f1SDimitry Andric * Name is a name for this MaterializationUnit to be used for identification 625fe6060f1SDimitry Andric * and logging purposes (e.g. if this MaterializationUnit produces an 626fe6060f1SDimitry Andric * object buffer then the name of that buffer will be derived from this name). 627fe6060f1SDimitry Andric * 628fe6060f1SDimitry Andric * The Syms list contains the names and linkages of the symbols provided by this 629fe6060f1SDimitry Andric * unit. This function takes ownership of the elements of the Syms array. The 630fe6060f1SDimitry Andric * Name fields of the array elements are taken to have been retained for this 631fe6060f1SDimitry Andric * function. The client should *not* release the elements of the array, but is 632fe6060f1SDimitry Andric * still responsible for destroying the array itself. 633fe6060f1SDimitry Andric * 634fe6060f1SDimitry Andric * The InitSym argument indicates whether or not this MaterializationUnit 635fe6060f1SDimitry Andric * contains static initializers. If three are no static initializers (the common 636fe6060f1SDimitry Andric * case) then this argument should be null. If there are static initializers 637fe6060f1SDimitry Andric * then InitSym should be set to a unique name that also appears in the Syms 638fe6060f1SDimitry Andric * list with the LLVMJITSymbolGenericFlagsMaterializationSideEffectsOnly flag 639fe6060f1SDimitry Andric * set. This function takes ownership of the InitSym, which should have been 640fe6060f1SDimitry Andric * retained twice on behalf of this function: once for the Syms entry and once 641fe6060f1SDimitry Andric * for InitSym. If clients wish to use the InitSym value after this function 642fe6060f1SDimitry Andric * returns they must retain it once more for themselves. 643fe6060f1SDimitry Andric * 644fe6060f1SDimitry Andric * If any of the symbols in the Syms list is looked up then the Materialize 645fe6060f1SDimitry Andric * function will be called. 646fe6060f1SDimitry Andric * 647fe6060f1SDimitry Andric * If any of the symbols in the Syms list is overridden then the Discard 648fe6060f1SDimitry Andric * function will be called. 649fe6060f1SDimitry Andric * 650fe6060f1SDimitry Andric * The caller owns the underling MaterializationUnit and is responsible for 651fe6060f1SDimitry Andric * either passing it to a JITDylib (via LLVMOrcJITDylibDefine) or disposing 652fe6060f1SDimitry Andric * of it by calling LLVMOrcDisposeMaterializationUnit. 653fe6060f1SDimitry Andric */ 654fe6060f1SDimitry Andric LLVMOrcMaterializationUnitRef LLVMOrcCreateCustomMaterializationUnit( 655fe6060f1SDimitry Andric const char *Name, void *Ctx, LLVMOrcCSymbolFlagsMapPairs Syms, 656fe6060f1SDimitry Andric size_t NumSyms, LLVMOrcSymbolStringPoolEntryRef InitSym, 657fe6060f1SDimitry Andric LLVMOrcMaterializationUnitMaterializeFunction Materialize, 658fe6060f1SDimitry Andric LLVMOrcMaterializationUnitDiscardFunction Discard, 659fe6060f1SDimitry Andric LLVMOrcMaterializationUnitDestroyFunction Destroy); 660fe6060f1SDimitry Andric 661fe6060f1SDimitry Andric /** 662e8d8bef9SDimitry Andric * Create a MaterializationUnit to define the given symbols as pointing to 663e8d8bef9SDimitry Andric * the corresponding raw addresses. 664fe6060f1SDimitry Andric * 665fe6060f1SDimitry Andric * This function takes ownership of the elements of the Syms array. The Name 666fe6060f1SDimitry Andric * fields of the array elements are taken to have been retained for this 667fe6060f1SDimitry Andric * function. This allows the following pattern... 668fe6060f1SDimitry Andric * 669fe6060f1SDimitry Andric * size_t NumPairs; 670fe6060f1SDimitry Andric * LLVMOrcCSymbolMapPairs Sym; 671fe6060f1SDimitry Andric * -- Build Syms array -- 672fe6060f1SDimitry Andric * LLVMOrcMaterializationUnitRef MU = 673fe6060f1SDimitry Andric * LLVMOrcAbsoluteSymbols(Syms, NumPairs); 674fe6060f1SDimitry Andric * 675fe6060f1SDimitry Andric * ... without requiring cleanup of the elements of the Sym array afterwards. 676fe6060f1SDimitry Andric * 677fe6060f1SDimitry Andric * The client is still responsible for deleting the Sym array itself. 678fe6060f1SDimitry Andric * 679fe6060f1SDimitry Andric * If a client wishes to reuse elements of the Sym array after this call they 680fe6060f1SDimitry Andric * must explicitly retain each of the elements for themselves. 681e8d8bef9SDimitry Andric */ 682e8d8bef9SDimitry Andric LLVMOrcMaterializationUnitRef 683e8d8bef9SDimitry Andric LLVMOrcAbsoluteSymbols(LLVMOrcCSymbolMapPairs Syms, size_t NumPairs); 684e8d8bef9SDimitry Andric 685e8d8bef9SDimitry Andric /** 686fe6060f1SDimitry Andric * Create a MaterializationUnit to define lazy re-expots. These are callable 687fe6060f1SDimitry Andric * entry points that call through to the given symbols. 688fe6060f1SDimitry Andric * 689fe6060f1SDimitry Andric * This function takes ownership of the CallableAliases array. The Name 690fe6060f1SDimitry Andric * fields of the array elements are taken to have been retained for this 691fe6060f1SDimitry Andric * function. This allows the following pattern... 692fe6060f1SDimitry Andric * 693fe6060f1SDimitry Andric * size_t NumPairs; 694fe6060f1SDimitry Andric * LLVMOrcCSymbolAliasMapPairs CallableAliases; 695fe6060f1SDimitry Andric * -- Build CallableAliases array -- 696fe6060f1SDimitry Andric * LLVMOrcMaterializationUnitRef MU = 697fe6060f1SDimitry Andric * LLVMOrcLazyReexports(LCTM, ISM, JD, CallableAliases, NumPairs); 698fe6060f1SDimitry Andric * 699fe6060f1SDimitry Andric * ... without requiring cleanup of the elements of the CallableAliases array afterwards. 700fe6060f1SDimitry Andric * 701fe6060f1SDimitry Andric * The client is still responsible for deleting the CallableAliases array itself. 702fe6060f1SDimitry Andric * 703fe6060f1SDimitry Andric * If a client wishes to reuse elements of the CallableAliases array after this call they 704fe6060f1SDimitry Andric * must explicitly retain each of the elements for themselves. 705fe6060f1SDimitry Andric */ 706fe6060f1SDimitry Andric LLVMOrcMaterializationUnitRef LLVMOrcLazyReexports( 707fe6060f1SDimitry Andric LLVMOrcLazyCallThroughManagerRef LCTM, LLVMOrcIndirectStubsManagerRef ISM, 708fe6060f1SDimitry Andric LLVMOrcJITDylibRef SourceRef, LLVMOrcCSymbolAliasMapPairs CallableAliases, 709fe6060f1SDimitry Andric size_t NumPairs); 710fe6060f1SDimitry Andric // TODO: ImplSymbolMad SrcJDLoc 711fe6060f1SDimitry Andric 712fe6060f1SDimitry Andric /** 713fe6060f1SDimitry Andric * Disposes of the passed MaterializationResponsibility object. 714fe6060f1SDimitry Andric * 715fe6060f1SDimitry Andric * This should only be done after the symbols covered by the object have either 716fe6060f1SDimitry Andric * been resolved and emitted (via 717fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityNotifyResolved and 718fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityNotifyEmitted) or failed (via 719fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityFailMaterialization). 720fe6060f1SDimitry Andric */ 721fe6060f1SDimitry Andric void LLVMOrcDisposeMaterializationResponsibility( 722fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 723fe6060f1SDimitry Andric 724fe6060f1SDimitry Andric /** 725fe6060f1SDimitry Andric * Returns the target JITDylib that these symbols are being materialized into. 726fe6060f1SDimitry Andric */ 727fe6060f1SDimitry Andric LLVMOrcJITDylibRef LLVMOrcMaterializationResponsibilityGetTargetDylib( 728fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 729fe6060f1SDimitry Andric 730fe6060f1SDimitry Andric /** 731fe6060f1SDimitry Andric * Returns the ExecutionSession for this MaterializationResponsibility. 732fe6060f1SDimitry Andric */ 733fe6060f1SDimitry Andric LLVMOrcExecutionSessionRef 734fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityGetExecutionSession( 735fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 736fe6060f1SDimitry Andric 737fe6060f1SDimitry Andric /** 738fe6060f1SDimitry Andric * Returns the symbol flags map for this responsibility instance. 739fe6060f1SDimitry Andric * 740fe6060f1SDimitry Andric * The length of the array is returned in NumPairs and the caller is responsible 741fe6060f1SDimitry Andric * for the returned memory and needs to call LLVMOrcDisposeCSymbolFlagsMap. 742fe6060f1SDimitry Andric * 743fe6060f1SDimitry Andric * To use the returned symbols beyond the livetime of the 744fe6060f1SDimitry Andric * MaterializationResponsibility requires the caller to retain the symbols 745fe6060f1SDimitry Andric * explicitly. 746fe6060f1SDimitry Andric */ 747fe6060f1SDimitry Andric LLVMOrcCSymbolFlagsMapPairs LLVMOrcMaterializationResponsibilityGetSymbols( 748fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, size_t *NumPairs); 749fe6060f1SDimitry Andric 750fe6060f1SDimitry Andric /** 751fe6060f1SDimitry Andric * Disposes of the passed LLVMOrcCSymbolFlagsMap. 752fe6060f1SDimitry Andric * 753fe6060f1SDimitry Andric * Does not release the entries themselves. 754fe6060f1SDimitry Andric */ 755fe6060f1SDimitry Andric void LLVMOrcDisposeCSymbolFlagsMap(LLVMOrcCSymbolFlagsMapPairs Pairs); 756fe6060f1SDimitry Andric 757fe6060f1SDimitry Andric /** 758fe6060f1SDimitry Andric * Returns the initialization pseudo-symbol, if any. This symbol will also 759fe6060f1SDimitry Andric * be present in the SymbolFlagsMap for this MaterializationResponsibility 760fe6060f1SDimitry Andric * object. 761fe6060f1SDimitry Andric * 762fe6060f1SDimitry Andric * The returned symbol is not retained over any mutating operation of the 763fe6060f1SDimitry Andric * MaterializationResponsbility or beyond the lifetime thereof. 764fe6060f1SDimitry Andric */ 765fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef 766fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityGetInitializerSymbol( 767fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 768fe6060f1SDimitry Andric 769fe6060f1SDimitry Andric /** 770fe6060f1SDimitry Andric * Returns the names of any symbols covered by this 771fe6060f1SDimitry Andric * MaterializationResponsibility object that have queries pending. This 772fe6060f1SDimitry Andric * information can be used to return responsibility for unrequested symbols 773fe6060f1SDimitry Andric * back to the JITDylib via the delegate method. 774fe6060f1SDimitry Andric */ 775fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef * 776fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityGetRequestedSymbols( 777fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, size_t *NumSymbols); 778fe6060f1SDimitry Andric 779fe6060f1SDimitry Andric /** 780fe6060f1SDimitry Andric * Disposes of the passed LLVMOrcSymbolStringPoolEntryRef* . 781fe6060f1SDimitry Andric * 782fe6060f1SDimitry Andric * Does not release the symbols themselves. 783fe6060f1SDimitry Andric */ 784fe6060f1SDimitry Andric void LLVMOrcDisposeSymbols(LLVMOrcSymbolStringPoolEntryRef *Symbols); 785fe6060f1SDimitry Andric 78681ad6265SDimitry Andric /** 787fe6060f1SDimitry Andric * Notifies the target JITDylib that the given symbols have been resolved. 788fe6060f1SDimitry Andric * This will update the given symbols' addresses in the JITDylib, and notify 789fe6060f1SDimitry Andric * any pending queries on the given symbols of their resolution. The given 790fe6060f1SDimitry Andric * symbols must be ones covered by this MaterializationResponsibility 791fe6060f1SDimitry Andric * instance. Individual calls to this method may resolve a subset of the 792fe6060f1SDimitry Andric * symbols, but all symbols must have been resolved prior to calling emit. 793fe6060f1SDimitry Andric * 794fe6060f1SDimitry Andric * This method will return an error if any symbols being resolved have been 795fe6060f1SDimitry Andric * moved to the error state due to the failure of a dependency. If this 796fe6060f1SDimitry Andric * method returns an error then clients should log it and call 797fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityFailMaterialization. If no dependencies 798fe6060f1SDimitry Andric * have been registered for the symbols covered by this 799*5f757f3fSDimitry Andric * MaterializationResponsibility then this method is guaranteed to return 800fe6060f1SDimitry Andric * LLVMErrorSuccess. 801fe6060f1SDimitry Andric */ 802fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyResolved( 803fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, LLVMOrcCSymbolMapPairs Symbols, 804fe6060f1SDimitry Andric size_t NumPairs); 805fe6060f1SDimitry Andric 806fe6060f1SDimitry Andric /** 807fe6060f1SDimitry Andric * Notifies the target JITDylib (and any pending queries on that JITDylib) 808fe6060f1SDimitry Andric * that all symbols covered by this MaterializationResponsibility instance 809fe6060f1SDimitry Andric * have been emitted. 810fe6060f1SDimitry Andric * 811fe6060f1SDimitry Andric * This method will return an error if any symbols being resolved have been 812fe6060f1SDimitry Andric * moved to the error state due to the failure of a dependency. If this 813fe6060f1SDimitry Andric * method returns an error then clients should log it and call 814fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityFailMaterialization. 815fe6060f1SDimitry Andric * If no dependencies have been registered for the symbols covered by this 816*5f757f3fSDimitry Andric * MaterializationResponsibility then this method is guaranteed to return 817fe6060f1SDimitry Andric * LLVMErrorSuccess. 818fe6060f1SDimitry Andric */ 819fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyEmitted( 820fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 821fe6060f1SDimitry Andric 822fe6060f1SDimitry Andric /** 823fe6060f1SDimitry Andric * Attempt to claim responsibility for new definitions. This method can be 824fe6060f1SDimitry Andric * used to claim responsibility for symbols that are added to a 825fe6060f1SDimitry Andric * materialization unit during the compilation process (e.g. literal pool 826fe6060f1SDimitry Andric * symbols). Symbol linkage rules are the same as for symbols that are 827fe6060f1SDimitry Andric * defined up front: duplicate strong definitions will result in errors. 828fe6060f1SDimitry Andric * Duplicate weak definitions will be discarded (in which case they will 829fe6060f1SDimitry Andric * not be added to this responsibility instance). 830fe6060f1SDimitry Andric * 831fe6060f1SDimitry Andric * This method can be used by materialization units that want to add 832fe6060f1SDimitry Andric * additional symbols at materialization time (e.g. stubs, compile 833fe6060f1SDimitry Andric * callbacks, metadata) 834fe6060f1SDimitry Andric */ 835fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityDefineMaterializing( 836fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 837fe6060f1SDimitry Andric LLVMOrcCSymbolFlagsMapPairs Pairs, size_t NumPairs); 838fe6060f1SDimitry Andric 839fe6060f1SDimitry Andric /** 840fe6060f1SDimitry Andric * Notify all not-yet-emitted covered by this MaterializationResponsibility 841fe6060f1SDimitry Andric * instance that an error has occurred. 842*5f757f3fSDimitry Andric * This will remove all symbols covered by this MaterializationResponsibility 843fe6060f1SDimitry Andric * from the target JITDylib, and send an error to any queries waiting on 844fe6060f1SDimitry Andric * these symbols. 845fe6060f1SDimitry Andric */ 846fe6060f1SDimitry Andric void LLVMOrcMaterializationResponsibilityFailMaterialization( 847fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 848fe6060f1SDimitry Andric 849fe6060f1SDimitry Andric /** 850fe6060f1SDimitry Andric * Transfers responsibility to the given MaterializationUnit for all 851fe6060f1SDimitry Andric * symbols defined by that MaterializationUnit. This allows 852fe6060f1SDimitry Andric * materializers to break up work based on run-time information (e.g. 853fe6060f1SDimitry Andric * by introspecting which symbols have actually been looked up and 854fe6060f1SDimitry Andric * materializing only those). 855fe6060f1SDimitry Andric */ 856fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityReplace( 857fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 858fe6060f1SDimitry Andric LLVMOrcMaterializationUnitRef MU); 859fe6060f1SDimitry Andric 860fe6060f1SDimitry Andric /** 861fe6060f1SDimitry Andric * Delegates responsibility for the given symbols to the returned 862fe6060f1SDimitry Andric * materialization responsibility. Useful for breaking up work between 863fe6060f1SDimitry Andric * threads, or different kinds of materialization processes. 864fe6060f1SDimitry Andric * 865fe6060f1SDimitry Andric * The caller retains responsibility of the the passed 866fe6060f1SDimitry Andric * MaterializationResponsibility. 867fe6060f1SDimitry Andric */ 868fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityDelegate( 869fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 870fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef *Symbols, size_t NumSymbols, 871fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef *Result); 872fe6060f1SDimitry Andric 873fe6060f1SDimitry Andric /** 874fe6060f1SDimitry Andric * Adds dependencies to a symbol that the MaterializationResponsibility is 875fe6060f1SDimitry Andric * responsible for. 876fe6060f1SDimitry Andric * 877fe6060f1SDimitry Andric * This function takes ownership of Dependencies struct. The Names 878fe6060f1SDimitry Andric * array have been retained for this function. This allows the following 879fe6060f1SDimitry Andric * pattern... 880fe6060f1SDimitry Andric * 881fe6060f1SDimitry Andric * LLVMOrcSymbolStringPoolEntryRef Names[] = {...}; 882fe6060f1SDimitry Andric * LLVMOrcCDependenceMapPair Dependence = {JD, {Names, sizeof(Names)}} 883fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityAddDependencies(JD, Name, &Dependence, 884fe6060f1SDimitry Andric * 1); 885fe6060f1SDimitry Andric * 886fe6060f1SDimitry Andric * ... without requiring cleanup of the elements of the Names array afterwards. 887fe6060f1SDimitry Andric * 888fe6060f1SDimitry Andric * The client is still responsible for deleting the Dependencies.Names array 889fe6060f1SDimitry Andric * itself. 890fe6060f1SDimitry Andric */ 891fe6060f1SDimitry Andric void LLVMOrcMaterializationResponsibilityAddDependencies( 892fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 893fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef Name, 894fe6060f1SDimitry Andric LLVMOrcCDependenceMapPairs Dependencies, size_t NumPairs); 895fe6060f1SDimitry Andric 896fe6060f1SDimitry Andric /** 897fe6060f1SDimitry Andric * Adds dependencies to all symbols that the MaterializationResponsibility is 898fe6060f1SDimitry Andric * responsible for. See LLVMOrcMaterializationResponsibilityAddDependencies for 899fe6060f1SDimitry Andric * notes about memory responsibility. 900fe6060f1SDimitry Andric */ 901fe6060f1SDimitry Andric void LLVMOrcMaterializationResponsibilityAddDependenciesForAll( 902fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 903fe6060f1SDimitry Andric LLVMOrcCDependenceMapPairs Dependencies, size_t NumPairs); 904fe6060f1SDimitry Andric 905fe6060f1SDimitry Andric /** 906e8d8bef9SDimitry Andric * Create a "bare" JITDylib. 907e8d8bef9SDimitry Andric * 908e8d8bef9SDimitry Andric * The client is responsible for ensuring that the JITDylib's name is unique, 909e8d8bef9SDimitry Andric * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first. 910e8d8bef9SDimitry Andric * 911e8d8bef9SDimitry Andric * This call does not install any library code or symbols into the newly 912e8d8bef9SDimitry Andric * created JITDylib. The client is responsible for all configuration. 913e8d8bef9SDimitry Andric */ 914e8d8bef9SDimitry Andric LLVMOrcJITDylibRef 915e8d8bef9SDimitry Andric LLVMOrcExecutionSessionCreateBareJITDylib(LLVMOrcExecutionSessionRef ES, 916e8d8bef9SDimitry Andric const char *Name); 917e8d8bef9SDimitry Andric 918e8d8bef9SDimitry Andric /** 919e8d8bef9SDimitry Andric * Create a JITDylib. 920e8d8bef9SDimitry Andric * 921e8d8bef9SDimitry Andric * The client is responsible for ensuring that the JITDylib's name is unique, 922e8d8bef9SDimitry Andric * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first. 923e8d8bef9SDimitry Andric * 924e8d8bef9SDimitry Andric * If a Platform is attached to the ExecutionSession then 925e8d8bef9SDimitry Andric * Platform::setupJITDylib will be called to install standard platform symbols 926e8d8bef9SDimitry Andric * (e.g. standard library interposes). If no Platform is installed then this 927e8d8bef9SDimitry Andric * call is equivalent to LLVMExecutionSessionRefCreateBareJITDylib and will 928e8d8bef9SDimitry Andric * always return success. 929e8d8bef9SDimitry Andric */ 930e8d8bef9SDimitry Andric LLVMErrorRef 931e8d8bef9SDimitry Andric LLVMOrcExecutionSessionCreateJITDylib(LLVMOrcExecutionSessionRef ES, 932e8d8bef9SDimitry Andric LLVMOrcJITDylibRef *Result, 933e8d8bef9SDimitry Andric const char *Name); 934e8d8bef9SDimitry Andric 935e8d8bef9SDimitry Andric /** 936e8d8bef9SDimitry Andric * Returns the JITDylib with the given name, or NULL if no such JITDylib 937e8d8bef9SDimitry Andric * exists. 938e8d8bef9SDimitry Andric */ 939d409305fSDimitry Andric LLVMOrcJITDylibRef 940d409305fSDimitry Andric LLVMOrcExecutionSessionGetJITDylibByName(LLVMOrcExecutionSessionRef ES, 941d409305fSDimitry Andric const char *Name); 942e8d8bef9SDimitry Andric 943e8d8bef9SDimitry Andric /** 944e8d8bef9SDimitry Andric * Return a reference to a newly created resource tracker associated with JD. 945e8d8bef9SDimitry Andric * The tracker is returned with an initial ref-count of 1, and must be released 946e8d8bef9SDimitry Andric * with LLVMOrcReleaseResourceTracker when no longer needed. 947e8d8bef9SDimitry Andric */ 948e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef 949e8d8bef9SDimitry Andric LLVMOrcJITDylibCreateResourceTracker(LLVMOrcJITDylibRef JD); 950e8d8bef9SDimitry Andric 951e8d8bef9SDimitry Andric /** 952e8d8bef9SDimitry Andric * Return a reference to the default resource tracker for the given JITDylib. 953e8d8bef9SDimitry Andric * This operation will increase the retain count of the tracker: Clients should 954e8d8bef9SDimitry Andric * call LLVMOrcReleaseResourceTracker when the result is no longer needed. 955e8d8bef9SDimitry Andric */ 956e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef 957e8d8bef9SDimitry Andric LLVMOrcJITDylibGetDefaultResourceTracker(LLVMOrcJITDylibRef JD); 958e8d8bef9SDimitry Andric 959e8d8bef9SDimitry Andric /** 960e8d8bef9SDimitry Andric * Add the given MaterializationUnit to the given JITDylib. 961e8d8bef9SDimitry Andric * 962e8d8bef9SDimitry Andric * If this operation succeeds then JITDylib JD will take ownership of MU. 963e8d8bef9SDimitry Andric * If the operation fails then ownership remains with the caller who should 964e8d8bef9SDimitry Andric * call LLVMOrcDisposeMaterializationUnit to destroy it. 965e8d8bef9SDimitry Andric */ 966e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcJITDylibDefine(LLVMOrcJITDylibRef JD, 967e8d8bef9SDimitry Andric LLVMOrcMaterializationUnitRef MU); 968e8d8bef9SDimitry Andric 969e8d8bef9SDimitry Andric /** 970e8d8bef9SDimitry Andric * Calls remove on all trackers associated with this JITDylib, see 971e8d8bef9SDimitry Andric * JITDylib::clear(). 972e8d8bef9SDimitry Andric */ 973e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcJITDylibClear(LLVMOrcJITDylibRef JD); 974e8d8bef9SDimitry Andric 975e8d8bef9SDimitry Andric /** 976e8d8bef9SDimitry Andric * Add a DefinitionGenerator to the given JITDylib. 9775ffd83dbSDimitry Andric * 9785ffd83dbSDimitry Andric * The JITDylib will take ownership of the given generator: The client is no 9795ffd83dbSDimitry Andric * longer responsible for managing its memory. 9805ffd83dbSDimitry Andric */ 9815ffd83dbSDimitry Andric void LLVMOrcJITDylibAddGenerator(LLVMOrcJITDylibRef JD, 982e8d8bef9SDimitry Andric LLVMOrcDefinitionGeneratorRef DG); 983e8d8bef9SDimitry Andric 984e8d8bef9SDimitry Andric /** 985e8d8bef9SDimitry Andric * Create a custom generator. 98681ad6265SDimitry Andric * 98781ad6265SDimitry Andric * The F argument will be used to implement the DefinitionGenerator's 98881ad6265SDimitry Andric * tryToGenerate method (see 98981ad6265SDimitry Andric * LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction). 99081ad6265SDimitry Andric * 99181ad6265SDimitry Andric * Ctx is a context object that will be passed to F. This argument is 99281ad6265SDimitry Andric * permitted to be null. 99381ad6265SDimitry Andric * 99481ad6265SDimitry Andric * Dispose is the disposal function for Ctx. This argument is permitted to be 99581ad6265SDimitry Andric * null (in which case the client is responsible for the lifetime of Ctx). 996e8d8bef9SDimitry Andric */ 997e8d8bef9SDimitry Andric LLVMOrcDefinitionGeneratorRef LLVMOrcCreateCustomCAPIDefinitionGenerator( 99881ad6265SDimitry Andric LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction F, void *Ctx, 99981ad6265SDimitry Andric LLVMOrcDisposeCAPIDefinitionGeneratorFunction Dispose); 100081ad6265SDimitry Andric 100181ad6265SDimitry Andric /** 100281ad6265SDimitry Andric * Continue a lookup that was suspended in a generator (see 100381ad6265SDimitry Andric * LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction). 100481ad6265SDimitry Andric */ 100581ad6265SDimitry Andric void LLVMOrcLookupStateContinueLookup(LLVMOrcLookupStateRef S, 100681ad6265SDimitry Andric LLVMErrorRef Err); 10075ffd83dbSDimitry Andric 10085ffd83dbSDimitry Andric /** 10095ffd83dbSDimitry Andric * Get a DynamicLibrarySearchGenerator that will reflect process symbols into 10105ffd83dbSDimitry Andric * the JITDylib. On success the resulting generator is owned by the client. 10115ffd83dbSDimitry Andric * Ownership is typically transferred by adding the instance to a JITDylib 10125ffd83dbSDimitry Andric * using LLVMOrcJITDylibAddGenerator, 10135ffd83dbSDimitry Andric * 10145ffd83dbSDimitry Andric * The GlobalPrefix argument specifies the character that appears on the front 10155ffd83dbSDimitry Andric * of linker-mangled symbols for the target platform (e.g. '_' on MachO). 10165ffd83dbSDimitry Andric * If non-null, this character will be stripped from the start of all symbol 10175ffd83dbSDimitry Andric * strings before passing the remaining substring to dlsym. 10185ffd83dbSDimitry Andric * 10195ffd83dbSDimitry Andric * The optional Filter and Ctx arguments can be used to supply a symbol name 10205ffd83dbSDimitry Andric * filter: Only symbols for which the filter returns true will be visible to 10215ffd83dbSDimitry Andric * JIT'd code. If the Filter argument is null then all process symbols will 10225ffd83dbSDimitry Andric * be visible to JIT'd code. Note that the symbol name passed to the Filter 10235ffd83dbSDimitry Andric * function is the full mangled symbol: The client is responsible for stripping 10245ffd83dbSDimitry Andric * the global prefix if present. 10255ffd83dbSDimitry Andric */ 10265ffd83dbSDimitry Andric LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess( 1027e8d8bef9SDimitry Andric LLVMOrcDefinitionGeneratorRef *Result, char GlobalPrefx, 10285ffd83dbSDimitry Andric LLVMOrcSymbolPredicate Filter, void *FilterCtx); 10295ffd83dbSDimitry Andric 10305ffd83dbSDimitry Andric /** 1031349cc55cSDimitry Andric * Get a LLVMOrcCreateDynamicLibararySearchGeneratorForPath that will reflect 1032349cc55cSDimitry Andric * library symbols into the JITDylib. On success the resulting generator is 1033349cc55cSDimitry Andric * owned by the client. Ownership is typically transferred by adding the 1034349cc55cSDimitry Andric * instance to a JITDylib using LLVMOrcJITDylibAddGenerator, 1035349cc55cSDimitry Andric * 1036349cc55cSDimitry Andric * The GlobalPrefix argument specifies the character that appears on the front 1037349cc55cSDimitry Andric * of linker-mangled symbols for the target platform (e.g. '_' on MachO). 1038349cc55cSDimitry Andric * If non-null, this character will be stripped from the start of all symbol 1039349cc55cSDimitry Andric * strings before passing the remaining substring to dlsym. 1040349cc55cSDimitry Andric * 1041349cc55cSDimitry Andric * The optional Filter and Ctx arguments can be used to supply a symbol name 1042349cc55cSDimitry Andric * filter: Only symbols for which the filter returns true will be visible to 1043349cc55cSDimitry Andric * JIT'd code. If the Filter argument is null then all library symbols will 1044349cc55cSDimitry Andric * be visible to JIT'd code. Note that the symbol name passed to the Filter 1045349cc55cSDimitry Andric * function is the full mangled symbol: The client is responsible for stripping 1046349cc55cSDimitry Andric * the global prefix if present. 1047349cc55cSDimitry Andric * 1048349cc55cSDimitry Andric * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE! 1049349cc55cSDimitry Andric * 1050349cc55cSDimitry Andric */ 1051349cc55cSDimitry Andric LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForPath( 1052349cc55cSDimitry Andric LLVMOrcDefinitionGeneratorRef *Result, const char *FileName, 1053349cc55cSDimitry Andric char GlobalPrefix, LLVMOrcSymbolPredicate Filter, void *FilterCtx); 1054349cc55cSDimitry Andric 1055349cc55cSDimitry Andric /** 1056349cc55cSDimitry Andric * Get a LLVMOrcCreateStaticLibrarySearchGeneratorForPath that will reflect 1057349cc55cSDimitry Andric * static library symbols into the JITDylib. On success the resulting 1058349cc55cSDimitry Andric * generator is owned by the client. Ownership is typically transferred by 1059349cc55cSDimitry Andric * adding the instance to a JITDylib using LLVMOrcJITDylibAddGenerator, 1060349cc55cSDimitry Andric * 1061349cc55cSDimitry Andric * Call with the optional TargetTriple argument will succeed if the file at 1062349cc55cSDimitry Andric * the given path is a static library or a MachO universal binary containing a 1063349cc55cSDimitry Andric * static library that is compatible with the given triple. Otherwise it will 1064349cc55cSDimitry Andric * return an error. 1065349cc55cSDimitry Andric * 1066349cc55cSDimitry Andric * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE! 1067349cc55cSDimitry Andric * 1068349cc55cSDimitry Andric */ 1069349cc55cSDimitry Andric LLVMErrorRef LLVMOrcCreateStaticLibrarySearchGeneratorForPath( 1070349cc55cSDimitry Andric LLVMOrcDefinitionGeneratorRef *Result, LLVMOrcObjectLayerRef ObjLayer, 1071349cc55cSDimitry Andric const char *FileName, const char *TargetTriple); 1072349cc55cSDimitry Andric 1073349cc55cSDimitry Andric /** 10745ffd83dbSDimitry Andric * Create a ThreadSafeContext containing a new LLVMContext. 10755ffd83dbSDimitry Andric * 10765ffd83dbSDimitry Andric * Ownership of the underlying ThreadSafeContext data is shared: Clients 10775ffd83dbSDimitry Andric * can and should dispose of their ThreadSafeContext as soon as they no longer 1078e8d8bef9SDimitry Andric * need to refer to it directly. Other references (e.g. from ThreadSafeModules) 10795ffd83dbSDimitry Andric * will keep the data alive as long as it is needed. 10805ffd83dbSDimitry Andric */ 10815ffd83dbSDimitry Andric LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void); 10825ffd83dbSDimitry Andric 10835ffd83dbSDimitry Andric /** 10845ffd83dbSDimitry Andric * Get a reference to the wrapped LLVMContext. 10855ffd83dbSDimitry Andric */ 10865ffd83dbSDimitry Andric LLVMContextRef 10875ffd83dbSDimitry Andric LLVMOrcThreadSafeContextGetContext(LLVMOrcThreadSafeContextRef TSCtx); 10885ffd83dbSDimitry Andric 10895ffd83dbSDimitry Andric /** 10905ffd83dbSDimitry Andric * Dispose of a ThreadSafeContext. 10915ffd83dbSDimitry Andric */ 10925ffd83dbSDimitry Andric void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx); 10935ffd83dbSDimitry Andric 10945ffd83dbSDimitry Andric /** 10955ffd83dbSDimitry Andric * Create a ThreadSafeModule wrapper around the given LLVM module. This takes 10965ffd83dbSDimitry Andric * ownership of the M argument which should not be disposed of or referenced 10975ffd83dbSDimitry Andric * after this function returns. 10985ffd83dbSDimitry Andric * 10995ffd83dbSDimitry Andric * Ownership of the ThreadSafeModule is unique: If it is transferred to the JIT 1100e8d8bef9SDimitry Andric * (e.g. by LLVMOrcLLJITAddLLVMIRModule) then the client is no longer 11015ffd83dbSDimitry Andric * responsible for it. If it is not transferred to the JIT then the client 11025ffd83dbSDimitry Andric * should call LLVMOrcDisposeThreadSafeModule to dispose of it. 11035ffd83dbSDimitry Andric */ 11045ffd83dbSDimitry Andric LLVMOrcThreadSafeModuleRef 11055ffd83dbSDimitry Andric LLVMOrcCreateNewThreadSafeModule(LLVMModuleRef M, 11065ffd83dbSDimitry Andric LLVMOrcThreadSafeContextRef TSCtx); 11075ffd83dbSDimitry Andric 11085ffd83dbSDimitry Andric /** 11095ffd83dbSDimitry Andric * Dispose of a ThreadSafeModule. This should only be called if ownership has 11105ffd83dbSDimitry Andric * not been passed to LLJIT (e.g. because some error prevented the client from 11115ffd83dbSDimitry Andric * adding this to the JIT). 11125ffd83dbSDimitry Andric */ 11135ffd83dbSDimitry Andric void LLVMOrcDisposeThreadSafeModule(LLVMOrcThreadSafeModuleRef TSM); 11145ffd83dbSDimitry Andric 11155ffd83dbSDimitry Andric /** 1116fe6060f1SDimitry Andric * Apply the given function to the module contained in this ThreadSafeModule. 1117fe6060f1SDimitry Andric */ 1118fe6060f1SDimitry Andric LLVMErrorRef 1119fe6060f1SDimitry Andric LLVMOrcThreadSafeModuleWithModuleDo(LLVMOrcThreadSafeModuleRef TSM, 1120fe6060f1SDimitry Andric LLVMOrcGenericIRModuleOperationFunction F, 1121fe6060f1SDimitry Andric void *Ctx); 1122fe6060f1SDimitry Andric 1123fe6060f1SDimitry Andric /** 11245ffd83dbSDimitry Andric * Create a JITTargetMachineBuilder by detecting the host. 11255ffd83dbSDimitry Andric * 11265ffd83dbSDimitry Andric * On success the client owns the resulting JITTargetMachineBuilder. It must be 1127fe6060f1SDimitry Andric * passed to a consuming operation (e.g. 1128fe6060f1SDimitry Andric * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling 1129fe6060f1SDimitry Andric * LLVMOrcDisposeJITTargetMachineBuilder. 11305ffd83dbSDimitry Andric */ 11315ffd83dbSDimitry Andric LLVMErrorRef LLVMOrcJITTargetMachineBuilderDetectHost( 11325ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderRef *Result); 11335ffd83dbSDimitry Andric 11345ffd83dbSDimitry Andric /** 11355ffd83dbSDimitry Andric * Create a JITTargetMachineBuilder from the given TargetMachine template. 11365ffd83dbSDimitry Andric * 11375ffd83dbSDimitry Andric * This operation takes ownership of the given TargetMachine and destroys it 11385ffd83dbSDimitry Andric * before returing. The resulting JITTargetMachineBuilder is owned by the client 1139fe6060f1SDimitry Andric * and must be passed to a consuming operation (e.g. 1140fe6060f1SDimitry Andric * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling 1141fe6060f1SDimitry Andric * LLVMOrcDisposeJITTargetMachineBuilder. 11425ffd83dbSDimitry Andric */ 11435ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderRef 11445ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(LLVMTargetMachineRef TM); 11455ffd83dbSDimitry Andric 11465ffd83dbSDimitry Andric /** 11475ffd83dbSDimitry Andric * Dispose of a JITTargetMachineBuilder. 11485ffd83dbSDimitry Andric */ 11495ffd83dbSDimitry Andric void LLVMOrcDisposeJITTargetMachineBuilder( 11505ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderRef JTMB); 11515ffd83dbSDimitry Andric 11525ffd83dbSDimitry Andric /** 1153fe6060f1SDimitry Andric * Returns the target triple for the given JITTargetMachineBuilder as a string. 1154fe6060f1SDimitry Andric * 1155fe6060f1SDimitry Andric * The caller owns the resulting string as must dispose of it by calling 1156fe6060f1SDimitry Andric * LLVMDisposeMessage 1157fe6060f1SDimitry Andric */ 1158fe6060f1SDimitry Andric char *LLVMOrcJITTargetMachineBuilderGetTargetTriple( 1159fe6060f1SDimitry Andric LLVMOrcJITTargetMachineBuilderRef JTMB); 1160fe6060f1SDimitry Andric 1161fe6060f1SDimitry Andric /** 1162fe6060f1SDimitry Andric * Sets the target triple for the given JITTargetMachineBuilder to the given 1163fe6060f1SDimitry Andric * string. 1164fe6060f1SDimitry Andric */ 1165fe6060f1SDimitry Andric void LLVMOrcJITTargetMachineBuilderSetTargetTriple( 1166fe6060f1SDimitry Andric LLVMOrcJITTargetMachineBuilderRef JTMB, const char *TargetTriple); 1167fe6060f1SDimitry Andric 1168fe6060f1SDimitry Andric /** 1169fe6060f1SDimitry Andric * Add an object to an ObjectLayer to the given JITDylib. 1170fe6060f1SDimitry Andric * 1171fe6060f1SDimitry Andric * Adds a buffer representing an object file to the given JITDylib using the 1172fe6060f1SDimitry Andric * given ObjectLayer instance. This operation transfers ownership of the buffer 1173fe6060f1SDimitry Andric * to the ObjectLayer instance. The buffer should not be disposed of or 1174fe6060f1SDimitry Andric * referenced once this function returns. 1175fe6060f1SDimitry Andric * 1176fe6060f1SDimitry Andric * Resources associated with the given object will be tracked by the given 1177fe6060f1SDimitry Andric * JITDylib's default ResourceTracker. 1178fe6060f1SDimitry Andric */ 1179fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcObjectLayerAddObjectFile(LLVMOrcObjectLayerRef ObjLayer, 1180fe6060f1SDimitry Andric LLVMOrcJITDylibRef JD, 1181fe6060f1SDimitry Andric LLVMMemoryBufferRef ObjBuffer); 1182fe6060f1SDimitry Andric 1183fe6060f1SDimitry Andric /** 1184fe6060f1SDimitry Andric * Add an object to an ObjectLayer using the given ResourceTracker. 1185fe6060f1SDimitry Andric * 1186fe6060f1SDimitry Andric * Adds a buffer representing an object file to the given ResourceTracker's 1187fe6060f1SDimitry Andric * JITDylib using the given ObjectLayer instance. This operation transfers 1188fe6060f1SDimitry Andric * ownership of the buffer to the ObjectLayer instance. The buffer should not 1189fe6060f1SDimitry Andric * be disposed of or referenced once this function returns. 1190fe6060f1SDimitry Andric * 1191fe6060f1SDimitry Andric * Resources associated with the given object will be tracked by 1192fe6060f1SDimitry Andric * ResourceTracker RT. 1193fe6060f1SDimitry Andric */ 1194fe6060f1SDimitry Andric LLVMErrorRef 1195fe6060f1SDimitry Andric LLVMOrcObjectLayerAddObjectFileWithRT(LLVMOrcObjectLayerRef ObjLayer, 1196fe6060f1SDimitry Andric LLVMOrcResourceTrackerRef RT, 1197fe6060f1SDimitry Andric LLVMMemoryBufferRef ObjBuffer); 1198fe6060f1SDimitry Andric 1199fe6060f1SDimitry Andric /** 1200fe6060f1SDimitry Andric * Emit an object buffer to an ObjectLayer. 1201fe6060f1SDimitry Andric * 1202fe6060f1SDimitry Andric * Ownership of the responsibility object and object buffer pass to this 1203fe6060f1SDimitry Andric * function. The client is not responsible for cleanup. 1204fe6060f1SDimitry Andric */ 1205fe6060f1SDimitry Andric void LLVMOrcObjectLayerEmit(LLVMOrcObjectLayerRef ObjLayer, 1206fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef R, 1207fe6060f1SDimitry Andric LLVMMemoryBufferRef ObjBuffer); 1208fe6060f1SDimitry Andric 1209fe6060f1SDimitry Andric /** 1210e8d8bef9SDimitry Andric * Dispose of an ObjectLayer. 12115ffd83dbSDimitry Andric */ 1212e8d8bef9SDimitry Andric void LLVMOrcDisposeObjectLayer(LLVMOrcObjectLayerRef ObjLayer); 12135ffd83dbSDimitry Andric 1214fe6060f1SDimitry Andric void LLVMOrcIRTransformLayerEmit(LLVMOrcIRTransformLayerRef IRTransformLayer, 1215fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 1216fe6060f1SDimitry Andric LLVMOrcThreadSafeModuleRef TSM); 1217fe6060f1SDimitry Andric 1218fe6060f1SDimitry Andric /** 1219fe6060f1SDimitry Andric * Set the transform function of the provided transform layer, passing through a 1220fe6060f1SDimitry Andric * pointer to user provided context. 1221fe6060f1SDimitry Andric */ 1222fe6060f1SDimitry Andric void LLVMOrcIRTransformLayerSetTransform( 1223fe6060f1SDimitry Andric LLVMOrcIRTransformLayerRef IRTransformLayer, 1224fe6060f1SDimitry Andric LLVMOrcIRTransformLayerTransformFunction TransformFunction, void *Ctx); 1225fe6060f1SDimitry Andric 1226fe6060f1SDimitry Andric /** 1227fe6060f1SDimitry Andric * Set the transform function on an LLVMOrcObjectTransformLayer. 1228fe6060f1SDimitry Andric */ 1229fe6060f1SDimitry Andric void LLVMOrcObjectTransformLayerSetTransform( 1230fe6060f1SDimitry Andric LLVMOrcObjectTransformLayerRef ObjTransformLayer, 1231fe6060f1SDimitry Andric LLVMOrcObjectTransformLayerTransformFunction TransformFunction, void *Ctx); 1232fe6060f1SDimitry Andric 1233fe6060f1SDimitry Andric /** 1234fe6060f1SDimitry Andric * Create a LocalIndirectStubsManager from the given target triple. 1235fe6060f1SDimitry Andric * 1236fe6060f1SDimitry Andric * The resulting IndirectStubsManager is owned by the client 1237fe6060f1SDimitry Andric * and must be disposed of by calling LLVMOrcDisposeDisposeIndirectStubsManager. 1238fe6060f1SDimitry Andric */ 1239fe6060f1SDimitry Andric LLVMOrcIndirectStubsManagerRef 1240fe6060f1SDimitry Andric LLVMOrcCreateLocalIndirectStubsManager(const char *TargetTriple); 1241fe6060f1SDimitry Andric 1242fe6060f1SDimitry Andric /** 1243fe6060f1SDimitry Andric * Dispose of an IndirectStubsManager. 1244fe6060f1SDimitry Andric */ 1245fe6060f1SDimitry Andric void LLVMOrcDisposeIndirectStubsManager(LLVMOrcIndirectStubsManagerRef ISM); 1246fe6060f1SDimitry Andric 1247fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcCreateLocalLazyCallThroughManager( 1248fe6060f1SDimitry Andric const char *TargetTriple, LLVMOrcExecutionSessionRef ES, 1249fe6060f1SDimitry Andric LLVMOrcJITTargetAddress ErrorHandlerAddr, 1250fe6060f1SDimitry Andric LLVMOrcLazyCallThroughManagerRef *LCTM); 1251fe6060f1SDimitry Andric 1252fe6060f1SDimitry Andric /** 1253fe6060f1SDimitry Andric * Dispose of an LazyCallThroughManager. 1254fe6060f1SDimitry Andric */ 1255fe6060f1SDimitry Andric void LLVMOrcDisposeLazyCallThroughManager( 1256fe6060f1SDimitry Andric LLVMOrcLazyCallThroughManagerRef LCTM); 1257fe6060f1SDimitry Andric 1258fe6060f1SDimitry Andric /** 1259fe6060f1SDimitry Andric * Create a DumpObjects instance. 1260fe6060f1SDimitry Andric * 1261fe6060f1SDimitry Andric * DumpDir specifies the path to write dumped objects to. DumpDir may be empty 1262fe6060f1SDimitry Andric * in which case files will be dumped to the working directory. 1263fe6060f1SDimitry Andric * 1264fe6060f1SDimitry Andric * IdentifierOverride specifies a file name stem to use when dumping objects. 1265fe6060f1SDimitry Andric * If empty then each MemoryBuffer's identifier will be used (with a .o suffix 1266fe6060f1SDimitry Andric * added if not already present). If an identifier override is supplied it will 1267fe6060f1SDimitry Andric * be used instead, along with an incrementing counter (since all buffers will 1268fe6060f1SDimitry Andric * use the same identifier, the resulting files will be named <ident>.o, 1269fe6060f1SDimitry Andric * <ident>.2.o, <ident>.3.o, and so on). IdentifierOverride should not contain 1270fe6060f1SDimitry Andric * an extension, as a .o suffix will be added by DumpObjects. 1271fe6060f1SDimitry Andric */ 1272fe6060f1SDimitry Andric LLVMOrcDumpObjectsRef LLVMOrcCreateDumpObjects(const char *DumpDir, 1273fe6060f1SDimitry Andric const char *IdentifierOverride); 1274fe6060f1SDimitry Andric 1275fe6060f1SDimitry Andric /** 1276fe6060f1SDimitry Andric * Dispose of a DumpObjects instance. 1277fe6060f1SDimitry Andric */ 1278fe6060f1SDimitry Andric void LLVMOrcDisposeDumpObjects(LLVMOrcDumpObjectsRef DumpObjects); 1279fe6060f1SDimitry Andric 1280fe6060f1SDimitry Andric /** 1281fe6060f1SDimitry Andric * Dump the contents of the given MemoryBuffer. 1282fe6060f1SDimitry Andric */ 1283fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcDumpObjects_CallOperator(LLVMOrcDumpObjectsRef DumpObjects, 1284fe6060f1SDimitry Andric LLVMMemoryBufferRef *ObjBuffer); 1285fe6060f1SDimitry Andric 1286349cc55cSDimitry Andric /** 1287349cc55cSDimitry Andric * @} 1288349cc55cSDimitry Andric */ 1289349cc55cSDimitry Andric 12905ffd83dbSDimitry Andric LLVM_C_EXTERN_C_END 12915ffd83dbSDimitry Andric 12925ffd83dbSDimitry Andric #endif /* LLVM_C_ORC_H */ 1293