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 /** 185*0fca6ea1SDimitry Andric * A set of symbols that share dependencies. 186*0fca6ea1SDimitry Andric */ 187*0fca6ea1SDimitry Andric typedef struct { 188*0fca6ea1SDimitry Andric LLVMOrcCSymbolsList Symbols; 189*0fca6ea1SDimitry Andric LLVMOrcCDependenceMapPairs Dependencies; 190*0fca6ea1SDimitry Andric size_t NumDependencies; 191*0fca6ea1SDimitry Andric } LLVMOrcCSymbolDependenceGroup; 192*0fca6ea1SDimitry Andric 193*0fca6ea1SDimitry Andric /** 194e8d8bef9SDimitry Andric * Lookup kind. This can be used by definition generators when deciding whether 195e8d8bef9SDimitry Andric * to produce a definition for a requested symbol. 196e8d8bef9SDimitry Andric * 197e8d8bef9SDimitry Andric * This enum should be kept in sync with llvm::orc::LookupKind. 198e8d8bef9SDimitry Andric */ 199e8d8bef9SDimitry Andric typedef enum { 200e8d8bef9SDimitry Andric LLVMOrcLookupKindStatic, 201e8d8bef9SDimitry Andric LLVMOrcLookupKindDLSym 202e8d8bef9SDimitry Andric } LLVMOrcLookupKind; 203e8d8bef9SDimitry Andric 204e8d8bef9SDimitry Andric /** 205e8d8bef9SDimitry Andric * JITDylib lookup flags. This can be used by definition generators when 206e8d8bef9SDimitry Andric * deciding whether to produce a definition for a requested symbol. 207e8d8bef9SDimitry Andric * 208e8d8bef9SDimitry Andric * This enum should be kept in sync with llvm::orc::JITDylibLookupFlags. 209e8d8bef9SDimitry Andric */ 210e8d8bef9SDimitry Andric typedef enum { 211e8d8bef9SDimitry Andric LLVMOrcJITDylibLookupFlagsMatchExportedSymbolsOnly, 212e8d8bef9SDimitry Andric LLVMOrcJITDylibLookupFlagsMatchAllSymbols 213e8d8bef9SDimitry Andric } LLVMOrcJITDylibLookupFlags; 214e8d8bef9SDimitry Andric 215e8d8bef9SDimitry Andric /** 21681ad6265SDimitry Andric * An element type for a JITDylib search order. 21781ad6265SDimitry Andric */ 21881ad6265SDimitry Andric typedef struct { 21981ad6265SDimitry Andric LLVMOrcJITDylibRef JD; 22081ad6265SDimitry Andric LLVMOrcJITDylibLookupFlags JDLookupFlags; 22181ad6265SDimitry Andric } LLVMOrcCJITDylibSearchOrderElement; 22281ad6265SDimitry Andric 22381ad6265SDimitry Andric /** 22481ad6265SDimitry Andric * A JITDylib search order. 22581ad6265SDimitry Andric * 22681ad6265SDimitry Andric * The list is terminated with an element containing a null pointer for the JD 22781ad6265SDimitry Andric * field. 22881ad6265SDimitry Andric */ 22981ad6265SDimitry Andric typedef LLVMOrcCJITDylibSearchOrderElement *LLVMOrcCJITDylibSearchOrder; 23081ad6265SDimitry Andric 23181ad6265SDimitry Andric /** 232e8d8bef9SDimitry Andric * Symbol lookup flags for lookup sets. This should be kept in sync with 233e8d8bef9SDimitry Andric * llvm::orc::SymbolLookupFlags. 234e8d8bef9SDimitry Andric */ 235e8d8bef9SDimitry Andric typedef enum { 236e8d8bef9SDimitry Andric LLVMOrcSymbolLookupFlagsRequiredSymbol, 237e8d8bef9SDimitry Andric LLVMOrcSymbolLookupFlagsWeaklyReferencedSymbol 238e8d8bef9SDimitry Andric } LLVMOrcSymbolLookupFlags; 239e8d8bef9SDimitry Andric 240e8d8bef9SDimitry Andric /** 241e8d8bef9SDimitry Andric * An element type for a symbol lookup set. 242e8d8bef9SDimitry Andric */ 243e8d8bef9SDimitry Andric typedef struct { 244e8d8bef9SDimitry Andric LLVMOrcSymbolStringPoolEntryRef Name; 245e8d8bef9SDimitry Andric LLVMOrcSymbolLookupFlags LookupFlags; 246e8d8bef9SDimitry Andric } LLVMOrcCLookupSetElement; 247e8d8bef9SDimitry Andric 248e8d8bef9SDimitry Andric /** 249e8d8bef9SDimitry Andric * A set of symbols to look up / generate. 250e8d8bef9SDimitry Andric * 251e8d8bef9SDimitry Andric * The list is terminated with an element containing a null pointer for the 252e8d8bef9SDimitry Andric * Name field. 253e8d8bef9SDimitry Andric * 254e8d8bef9SDimitry Andric * If a client creates an instance of this type then they are responsible for 255e8d8bef9SDimitry Andric * freeing it, and for ensuring that all strings have been retained over the 256e8d8bef9SDimitry Andric * course of its life. Clients receiving a copy from a callback are not 257e8d8bef9SDimitry Andric * responsible for managing lifetime or retain counts. 258e8d8bef9SDimitry Andric */ 259e8d8bef9SDimitry Andric typedef LLVMOrcCLookupSetElement *LLVMOrcCLookupSet; 260e8d8bef9SDimitry Andric 261e8d8bef9SDimitry Andric /** 262fe6060f1SDimitry Andric * A reference to a uniquely owned orc::MaterializationUnit instance. 263e8d8bef9SDimitry Andric */ 264e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueMaterializationUnit *LLVMOrcMaterializationUnitRef; 265e8d8bef9SDimitry Andric 266e8d8bef9SDimitry Andric /** 267fe6060f1SDimitry Andric * A reference to a uniquely owned orc::MaterializationResponsibility instance. 268fe6060f1SDimitry Andric * 269fe6060f1SDimitry Andric * Ownership must be passed to a lower-level layer in a JIT stack. 2705ffd83dbSDimitry Andric */ 271fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueMaterializationResponsibility 272fe6060f1SDimitry Andric *LLVMOrcMaterializationResponsibilityRef; 273fe6060f1SDimitry Andric 274fe6060f1SDimitry Andric /** 275fe6060f1SDimitry Andric * A MaterializationUnit materialize callback. 276fe6060f1SDimitry Andric * 277fe6060f1SDimitry Andric * Ownership of the Ctx and MR arguments passes to the callback which must 278fe6060f1SDimitry Andric * adhere to the LLVMOrcMaterializationResponsibilityRef contract (see comment 279fe6060f1SDimitry Andric * for that type). 280fe6060f1SDimitry Andric * 281fe6060f1SDimitry Andric * If this callback is called then the LLVMOrcMaterializationUnitDestroy 282fe6060f1SDimitry Andric * callback will NOT be called. 283fe6060f1SDimitry Andric */ 284fe6060f1SDimitry Andric typedef void (*LLVMOrcMaterializationUnitMaterializeFunction)( 285fe6060f1SDimitry Andric void *Ctx, LLVMOrcMaterializationResponsibilityRef MR); 286fe6060f1SDimitry Andric 287fe6060f1SDimitry Andric /** 288fe6060f1SDimitry Andric * A MaterializationUnit discard callback. 289fe6060f1SDimitry Andric * 290fe6060f1SDimitry Andric * Ownership of JD and Symbol remain with the caller: These arguments should 291fe6060f1SDimitry Andric * not be disposed of or released. 292fe6060f1SDimitry Andric */ 293fe6060f1SDimitry Andric typedef void (*LLVMOrcMaterializationUnitDiscardFunction)( 294fe6060f1SDimitry Andric void *Ctx, LLVMOrcJITDylibRef JD, LLVMOrcSymbolStringPoolEntryRef Symbol); 295fe6060f1SDimitry Andric 296fe6060f1SDimitry Andric /** 297fe6060f1SDimitry Andric * A MaterializationUnit destruction callback. 298fe6060f1SDimitry Andric * 299fe6060f1SDimitry Andric * If a custom MaterializationUnit is destroyed before its Materialize 300fe6060f1SDimitry Andric * function is called then this function will be called to provide an 301fe6060f1SDimitry Andric * opportunity for the underlying program representation to be destroyed. 302fe6060f1SDimitry Andric */ 303fe6060f1SDimitry Andric typedef void (*LLVMOrcMaterializationUnitDestroyFunction)(void *Ctx); 3045ffd83dbSDimitry Andric 3055ffd83dbSDimitry Andric /** 306e8d8bef9SDimitry Andric * A reference to an orc::ResourceTracker instance. 3075ffd83dbSDimitry Andric */ 308e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueResourceTracker *LLVMOrcResourceTrackerRef; 309e8d8bef9SDimitry Andric 310e8d8bef9SDimitry Andric /** 311e8d8bef9SDimitry Andric * A reference to an orc::DefinitionGenerator. 312e8d8bef9SDimitry Andric */ 313e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueDefinitionGenerator 314e8d8bef9SDimitry Andric *LLVMOrcDefinitionGeneratorRef; 315e8d8bef9SDimitry Andric 316e8d8bef9SDimitry Andric /** 317e8d8bef9SDimitry Andric * An opaque lookup state object. Instances of this type can be captured to 318e8d8bef9SDimitry Andric * suspend a lookup while a custom generator function attempts to produce a 319e8d8bef9SDimitry Andric * definition. 320e8d8bef9SDimitry Andric * 321e8d8bef9SDimitry Andric * If a client captures a lookup state object then they must eventually call 322e8d8bef9SDimitry Andric * LLVMOrcLookupStateContinueLookup to restart the lookup. This is required 323e8d8bef9SDimitry Andric * in order to release memory allocated for the lookup state, even if errors 324e8d8bef9SDimitry Andric * have occurred while the lookup was suspended (if these errors have made the 325e8d8bef9SDimitry Andric * lookup impossible to complete then it will issue its own error before 326e8d8bef9SDimitry Andric * destruction). 327e8d8bef9SDimitry Andric */ 328e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueLookupState *LLVMOrcLookupStateRef; 329e8d8bef9SDimitry Andric 330e8d8bef9SDimitry Andric /** 331e8d8bef9SDimitry Andric * A custom generator function. This can be used to create a custom generator 332e8d8bef9SDimitry Andric * object using LLVMOrcCreateCustomCAPIDefinitionGenerator. The resulting 333e8d8bef9SDimitry Andric * object can be attached to a JITDylib, via LLVMOrcJITDylibAddGenerator, to 334e8d8bef9SDimitry Andric * receive callbacks when lookups fail to match existing definitions. 335e8d8bef9SDimitry Andric * 336e8d8bef9SDimitry Andric * GeneratorObj will contain the address of the custom generator object. 337e8d8bef9SDimitry Andric * 338e8d8bef9SDimitry Andric * Ctx will contain the context object passed to 339e8d8bef9SDimitry Andric * LLVMOrcCreateCustomCAPIDefinitionGenerator. 340e8d8bef9SDimitry Andric * 341e8d8bef9SDimitry Andric * LookupState will contain a pointer to an LLVMOrcLookupStateRef object. This 342e8d8bef9SDimitry Andric * can optionally be modified to make the definition generation process 343e8d8bef9SDimitry Andric * asynchronous: If the LookupStateRef value is copied, and the original 344e8d8bef9SDimitry Andric * LLVMOrcLookupStateRef set to null, the lookup will be suspended. Once the 345e8d8bef9SDimitry Andric * asynchronous definition process has been completed clients must call 346e8d8bef9SDimitry Andric * LLVMOrcLookupStateContinueLookup to continue the lookup (this should be 347e8d8bef9SDimitry Andric * done unconditionally, even if errors have occurred in the mean time, to 348fe6060f1SDimitry Andric * free the lookup state memory and notify the query object of the failures). 349fe6060f1SDimitry Andric * If LookupState is captured this function must return LLVMErrorSuccess. 350e8d8bef9SDimitry Andric * 351e8d8bef9SDimitry Andric * The Kind argument can be inspected to determine the lookup kind (e.g. 352e8d8bef9SDimitry Andric * as-if-during-static-link, or as-if-during-dlsym). 353e8d8bef9SDimitry Andric * 354e8d8bef9SDimitry Andric * The JD argument specifies which JITDylib the definitions should be generated 355e8d8bef9SDimitry Andric * into. 356e8d8bef9SDimitry Andric * 357e8d8bef9SDimitry Andric * The JDLookupFlags argument can be inspected to determine whether the original 3585f757f3fSDimitry Andric * lookup included non-exported symbols. 359e8d8bef9SDimitry Andric * 360e8d8bef9SDimitry Andric * Finally, the LookupSet argument contains the set of symbols that could not 361e8d8bef9SDimitry Andric * be found in JD already (the set of generation candidates). 362e8d8bef9SDimitry Andric */ 363e8d8bef9SDimitry Andric typedef LLVMErrorRef (*LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction)( 364e8d8bef9SDimitry Andric LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx, 365e8d8bef9SDimitry Andric LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind, 366e8d8bef9SDimitry Andric LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags, 367e8d8bef9SDimitry Andric LLVMOrcCLookupSet LookupSet, size_t LookupSetSize); 3685ffd83dbSDimitry Andric 3695ffd83dbSDimitry Andric /** 37081ad6265SDimitry Andric * Disposer for a custom generator. 37181ad6265SDimitry Andric * 37281ad6265SDimitry Andric * Will be called by ORC when the JITDylib that the generator is attached to 37381ad6265SDimitry Andric * is destroyed. 37481ad6265SDimitry Andric */ 37581ad6265SDimitry Andric typedef void (*LLVMOrcDisposeCAPIDefinitionGeneratorFunction)(void *Ctx); 37681ad6265SDimitry Andric 37781ad6265SDimitry Andric /** 3785ffd83dbSDimitry Andric * Predicate function for SymbolStringPoolEntries. 3795ffd83dbSDimitry Andric */ 380e8d8bef9SDimitry Andric typedef int (*LLVMOrcSymbolPredicate)(void *Ctx, 381e8d8bef9SDimitry Andric LLVMOrcSymbolStringPoolEntryRef Sym); 3825ffd83dbSDimitry Andric 3835ffd83dbSDimitry Andric /** 3845ffd83dbSDimitry Andric * A reference to an orc::ThreadSafeContext instance. 3855ffd83dbSDimitry Andric */ 3865ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueThreadSafeContext *LLVMOrcThreadSafeContextRef; 3875ffd83dbSDimitry Andric 3885ffd83dbSDimitry Andric /** 3895ffd83dbSDimitry Andric * A reference to an orc::ThreadSafeModule instance. 3905ffd83dbSDimitry Andric */ 3915ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueThreadSafeModule *LLVMOrcThreadSafeModuleRef; 3925ffd83dbSDimitry Andric 3935ffd83dbSDimitry Andric /** 394fe6060f1SDimitry Andric * A function for inspecting/mutating IR modules, suitable for use with 395fe6060f1SDimitry Andric * LLVMOrcThreadSafeModuleWithModuleDo. 396fe6060f1SDimitry Andric */ 397fe6060f1SDimitry Andric typedef LLVMErrorRef (*LLVMOrcGenericIRModuleOperationFunction)( 398fe6060f1SDimitry Andric void *Ctx, LLVMModuleRef M); 399fe6060f1SDimitry Andric 400fe6060f1SDimitry Andric /** 4015ffd83dbSDimitry Andric * A reference to an orc::JITTargetMachineBuilder instance. 4025ffd83dbSDimitry Andric */ 4035ffd83dbSDimitry Andric typedef struct LLVMOrcOpaqueJITTargetMachineBuilder 4045ffd83dbSDimitry Andric *LLVMOrcJITTargetMachineBuilderRef; 4055ffd83dbSDimitry Andric 4065ffd83dbSDimitry Andric /** 407e8d8bef9SDimitry Andric * A reference to an orc::ObjectLayer instance. 4085ffd83dbSDimitry Andric */ 409e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueObjectLayer *LLVMOrcObjectLayerRef; 4105ffd83dbSDimitry Andric 4115ffd83dbSDimitry Andric /** 412fe6060f1SDimitry Andric * A reference to an orc::ObjectLinkingLayer instance. 413fe6060f1SDimitry Andric */ 414fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueObjectLinkingLayer *LLVMOrcObjectLinkingLayerRef; 415fe6060f1SDimitry Andric 416fe6060f1SDimitry Andric /** 417fe6060f1SDimitry Andric * A reference to an orc::IRTransformLayer instance. 418fe6060f1SDimitry Andric */ 419fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueIRTransformLayer *LLVMOrcIRTransformLayerRef; 420fe6060f1SDimitry Andric 421fe6060f1SDimitry Andric /** 422fe6060f1SDimitry Andric * A function for applying transformations as part of an transform layer. 423fe6060f1SDimitry Andric * 424fe6060f1SDimitry Andric * Implementations of this type are responsible for managing the lifetime 425fe6060f1SDimitry Andric * of the Module pointed to by ModInOut: If the LLVMModuleRef value is 426fe6060f1SDimitry Andric * overwritten then the function is responsible for disposing of the incoming 427fe6060f1SDimitry Andric * module. If the module is simply accessed/mutated in-place then ownership 428fe6060f1SDimitry Andric * returns to the caller and the function does not need to do any lifetime 429fe6060f1SDimitry Andric * management. 430fe6060f1SDimitry Andric * 431fe6060f1SDimitry Andric * Clients can call LLVMOrcLLJITGetIRTransformLayer to obtain the transform 432fe6060f1SDimitry Andric * layer of a LLJIT instance, and use LLVMOrcIRTransformLayerSetTransform 433fe6060f1SDimitry Andric * to set the function. This can be used to override the default transform 434fe6060f1SDimitry Andric * layer. 435fe6060f1SDimitry Andric */ 436fe6060f1SDimitry Andric typedef LLVMErrorRef (*LLVMOrcIRTransformLayerTransformFunction)( 437fe6060f1SDimitry Andric void *Ctx, LLVMOrcThreadSafeModuleRef *ModInOut, 438fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 439fe6060f1SDimitry Andric 440fe6060f1SDimitry Andric /** 441fe6060f1SDimitry Andric * A reference to an orc::ObjectTransformLayer instance. 442fe6060f1SDimitry Andric */ 443fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueObjectTransformLayer 444fe6060f1SDimitry Andric *LLVMOrcObjectTransformLayerRef; 445fe6060f1SDimitry Andric 446fe6060f1SDimitry Andric /** 447fe6060f1SDimitry Andric * A function for applying transformations to an object file buffer. 448fe6060f1SDimitry Andric * 449fe6060f1SDimitry Andric * Implementations of this type are responsible for managing the lifetime 450fe6060f1SDimitry Andric * of the memory buffer pointed to by ObjInOut: If the LLVMMemoryBufferRef 451fe6060f1SDimitry Andric * value is overwritten then the function is responsible for disposing of the 452fe6060f1SDimitry Andric * incoming buffer. If the buffer is simply accessed/mutated in-place then 453fe6060f1SDimitry Andric * ownership returns to the caller and the function does not need to do any 454fe6060f1SDimitry Andric * lifetime management. 455fe6060f1SDimitry Andric * 456fe6060f1SDimitry Andric * The transform is allowed to return an error, in which case the ObjInOut 457fe6060f1SDimitry Andric * buffer should be disposed of and set to null. 458fe6060f1SDimitry Andric */ 459fe6060f1SDimitry Andric typedef LLVMErrorRef (*LLVMOrcObjectTransformLayerTransformFunction)( 460fe6060f1SDimitry Andric void *Ctx, LLVMMemoryBufferRef *ObjInOut); 461fe6060f1SDimitry Andric 462fe6060f1SDimitry Andric /** 463fe6060f1SDimitry Andric * A reference to an orc::IndirectStubsManager instance. 464fe6060f1SDimitry Andric */ 465fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueIndirectStubsManager 466fe6060f1SDimitry Andric *LLVMOrcIndirectStubsManagerRef; 467fe6060f1SDimitry Andric 468fe6060f1SDimitry Andric /** 469fe6060f1SDimitry Andric * A reference to an orc::LazyCallThroughManager instance. 470fe6060f1SDimitry Andric */ 471fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueLazyCallThroughManager 472fe6060f1SDimitry Andric *LLVMOrcLazyCallThroughManagerRef; 473fe6060f1SDimitry Andric 474fe6060f1SDimitry Andric /** 475fe6060f1SDimitry Andric * A reference to an orc::DumpObjects object. 476fe6060f1SDimitry Andric * 477fe6060f1SDimitry Andric * Can be used to dump object files to disk with unique names. Useful as an 478fe6060f1SDimitry Andric * ObjectTransformLayer transform. 479fe6060f1SDimitry Andric */ 480fe6060f1SDimitry Andric typedef struct LLVMOrcOpaqueDumpObjects *LLVMOrcDumpObjectsRef; 481fe6060f1SDimitry Andric 482fe6060f1SDimitry Andric /** 483e8d8bef9SDimitry Andric * Attach a custom error reporter function to the ExecutionSession. 484e8d8bef9SDimitry Andric * 485e8d8bef9SDimitry Andric * The error reporter will be called to deliver failure notices that can not be 486e8d8bef9SDimitry Andric * directly reported to a caller. For example, failure to resolve symbols in 487e8d8bef9SDimitry Andric * the JIT linker is typically reported via the error reporter (callers 488e8d8bef9SDimitry Andric * requesting definitions from the JIT will typically be delivered a 489e8d8bef9SDimitry Andric * FailureToMaterialize error instead). 4905ffd83dbSDimitry Andric */ 491e8d8bef9SDimitry Andric void LLVMOrcExecutionSessionSetErrorReporter( 492e8d8bef9SDimitry Andric LLVMOrcExecutionSessionRef ES, LLVMOrcErrorReporterFunction ReportError, 493e8d8bef9SDimitry Andric void *Ctx); 494e8d8bef9SDimitry Andric 495e8d8bef9SDimitry Andric /** 496e8d8bef9SDimitry Andric * Return a reference to the SymbolStringPool for an ExecutionSession. 497e8d8bef9SDimitry Andric * 498e8d8bef9SDimitry Andric * Ownership of the pool remains with the ExecutionSession: The caller is 499e8d8bef9SDimitry Andric * not required to free the pool. 500e8d8bef9SDimitry Andric */ 501e8d8bef9SDimitry Andric LLVMOrcSymbolStringPoolRef 502e8d8bef9SDimitry Andric LLVMOrcExecutionSessionGetSymbolStringPool(LLVMOrcExecutionSessionRef ES); 503e8d8bef9SDimitry Andric 504e8d8bef9SDimitry Andric /** 505e8d8bef9SDimitry Andric * Clear all unreferenced symbol string pool entries. 506e8d8bef9SDimitry Andric * 507e8d8bef9SDimitry Andric * This can be called at any time to release unused entries in the 508e8d8bef9SDimitry Andric * ExecutionSession's string pool. Since it locks the pool (preventing 509e8d8bef9SDimitry Andric * interning of any new strings) it is recommended that it only be called 510e8d8bef9SDimitry Andric * infrequently, ideally when the caller has reason to believe that some 511e8d8bef9SDimitry Andric * entries will have become unreferenced, e.g. after removing a module or 512e8d8bef9SDimitry Andric * closing a JITDylib. 513e8d8bef9SDimitry Andric */ 514e8d8bef9SDimitry Andric void LLVMOrcSymbolStringPoolClearDeadEntries(LLVMOrcSymbolStringPoolRef SSP); 5155ffd83dbSDimitry Andric 5165ffd83dbSDimitry Andric /** 5175ffd83dbSDimitry Andric * Intern a string in the ExecutionSession's SymbolStringPool and return a 5185ffd83dbSDimitry Andric * reference to it. This increments the ref-count of the pool entry, and the 5195ffd83dbSDimitry Andric * returned value should be released once the client is done with it by 5205f757f3fSDimitry Andric * calling LLVMOrcReleaseSymbolStringPoolEntry. 5215ffd83dbSDimitry Andric * 5225ffd83dbSDimitry Andric * Since strings are uniqued within the SymbolStringPool 5235ffd83dbSDimitry Andric * LLVMOrcSymbolStringPoolEntryRefs can be compared by value to test string 5245ffd83dbSDimitry Andric * equality. 5255ffd83dbSDimitry Andric * 5265ffd83dbSDimitry Andric * Note that this function does not perform linker-mangling on the string. 5275ffd83dbSDimitry Andric */ 5285ffd83dbSDimitry Andric LLVMOrcSymbolStringPoolEntryRef 5295ffd83dbSDimitry Andric LLVMOrcExecutionSessionIntern(LLVMOrcExecutionSessionRef ES, const char *Name); 5305ffd83dbSDimitry Andric 5315ffd83dbSDimitry Andric /** 53281ad6265SDimitry Andric * Callback type for ExecutionSession lookups. 53381ad6265SDimitry Andric * 53481ad6265SDimitry Andric * If Err is LLVMErrorSuccess then Result will contain a pointer to a 53581ad6265SDimitry Andric * list of ( SymbolStringPtr, JITEvaluatedSymbol ) pairs of length NumPairs. 53681ad6265SDimitry Andric * 53781ad6265SDimitry Andric * If Err is a failure value then Result and Ctx are undefined and should 53881ad6265SDimitry Andric * not be accessed. The Callback is responsible for handling the error 53981ad6265SDimitry Andric * value (e.g. by calling LLVMGetErrorMessage + LLVMDisposeErrorMessage). 54081ad6265SDimitry Andric * 54181ad6265SDimitry Andric * The caller retains ownership of the Result array and will release all 54281ad6265SDimitry Andric * contained symbol names. Clients are responsible for retaining any symbol 54381ad6265SDimitry Andric * names that they wish to hold after the function returns. 54481ad6265SDimitry Andric */ 54581ad6265SDimitry Andric typedef void (*LLVMOrcExecutionSessionLookupHandleResultFunction)( 54681ad6265SDimitry Andric LLVMErrorRef Err, LLVMOrcCSymbolMapPairs Result, size_t NumPairs, 54781ad6265SDimitry Andric void *Ctx); 54881ad6265SDimitry Andric 54981ad6265SDimitry Andric /** 55081ad6265SDimitry Andric * Look up symbols in an execution session. 55181ad6265SDimitry Andric * 55281ad6265SDimitry Andric * This is a wrapper around the general ExecutionSession::lookup function. 55381ad6265SDimitry Andric * 55481ad6265SDimitry Andric * The SearchOrder argument contains a list of (JITDylibs, JITDylibSearchFlags) 55581ad6265SDimitry Andric * pairs that describe the search order. The JITDylibs will be searched in the 55681ad6265SDimitry Andric * given order to try to find the symbols in the Symbols argument. 55781ad6265SDimitry Andric * 55881ad6265SDimitry Andric * The Symbols argument should contain a null-terminated array of 55981ad6265SDimitry Andric * (SymbolStringPtr, SymbolLookupFlags) pairs describing the symbols to be 56081ad6265SDimitry Andric * searched for. This function takes ownership of the elements of the Symbols 56181ad6265SDimitry Andric * array. The Name fields of the Symbols elements are taken to have been 56281ad6265SDimitry Andric * retained by the client for this function. The client should *not* release the 56381ad6265SDimitry Andric * Name fields, but are still responsible for destroying the array itself. 56481ad6265SDimitry Andric * 56581ad6265SDimitry Andric * The HandleResult function will be called once all searched for symbols have 56681ad6265SDimitry Andric * been found, or an error occurs. The HandleResult function will be passed an 56781ad6265SDimitry Andric * LLVMErrorRef indicating success or failure, and (on success) a 56881ad6265SDimitry Andric * null-terminated LLVMOrcCSymbolMapPairs array containing the function result, 56981ad6265SDimitry Andric * and the Ctx value passed to the lookup function. 57081ad6265SDimitry Andric * 57181ad6265SDimitry Andric * The client is fully responsible for managing the lifetime of the Ctx object. 57281ad6265SDimitry Andric * A common idiom is to allocate the context prior to the lookup and deallocate 57381ad6265SDimitry Andric * it in the handler. 57481ad6265SDimitry Andric * 57581ad6265SDimitry Andric * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE! 57681ad6265SDimitry Andric */ 57781ad6265SDimitry Andric void LLVMOrcExecutionSessionLookup( 57881ad6265SDimitry Andric LLVMOrcExecutionSessionRef ES, LLVMOrcLookupKind K, 57981ad6265SDimitry Andric LLVMOrcCJITDylibSearchOrder SearchOrder, size_t SearchOrderSize, 58081ad6265SDimitry Andric LLVMOrcCLookupSet Symbols, size_t SymbolsSize, 58181ad6265SDimitry Andric LLVMOrcExecutionSessionLookupHandleResultFunction HandleResult, void *Ctx); 58281ad6265SDimitry Andric 58381ad6265SDimitry Andric /** 584e8d8bef9SDimitry Andric * Increments the ref-count for a SymbolStringPool entry. 585e8d8bef9SDimitry Andric */ 586e8d8bef9SDimitry Andric void LLVMOrcRetainSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S); 587e8d8bef9SDimitry Andric 588e8d8bef9SDimitry Andric /** 5895ffd83dbSDimitry Andric * Reduces the ref-count for of a SymbolStringPool entry. 5905ffd83dbSDimitry Andric */ 5915ffd83dbSDimitry Andric void LLVMOrcReleaseSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S); 5925ffd83dbSDimitry Andric 59381ad6265SDimitry Andric /** 59481ad6265SDimitry Andric * Return the c-string for the given symbol. This string will remain valid until 59581ad6265SDimitry Andric * the entry is freed (once all LLVMOrcSymbolStringPoolEntryRefs have been 59681ad6265SDimitry Andric * released). 59781ad6265SDimitry Andric */ 598e8d8bef9SDimitry Andric const char *LLVMOrcSymbolStringPoolEntryStr(LLVMOrcSymbolStringPoolEntryRef S); 599e8d8bef9SDimitry Andric 600e8d8bef9SDimitry Andric /** 601e8d8bef9SDimitry Andric * Reduces the ref-count of a ResourceTracker. 602e8d8bef9SDimitry Andric */ 603e8d8bef9SDimitry Andric void LLVMOrcReleaseResourceTracker(LLVMOrcResourceTrackerRef RT); 604e8d8bef9SDimitry Andric 605e8d8bef9SDimitry Andric /** 606e8d8bef9SDimitry Andric * Transfers tracking of all resources associated with resource tracker SrcRT 607e8d8bef9SDimitry Andric * to resource tracker DstRT. 608e8d8bef9SDimitry Andric */ 609e8d8bef9SDimitry Andric void LLVMOrcResourceTrackerTransferTo(LLVMOrcResourceTrackerRef SrcRT, 610e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef DstRT); 611e8d8bef9SDimitry Andric 612e8d8bef9SDimitry Andric /** 613e8d8bef9SDimitry Andric * Remove all resources associated with the given tracker. See 614e8d8bef9SDimitry Andric * ResourceTracker::remove(). 615e8d8bef9SDimitry Andric */ 616e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcResourceTrackerRemove(LLVMOrcResourceTrackerRef RT); 617e8d8bef9SDimitry Andric 6185ffd83dbSDimitry Andric /** 6195ffd83dbSDimitry Andric * Dispose of a JITDylib::DefinitionGenerator. This should only be called if 6205ffd83dbSDimitry Andric * ownership has not been passed to a JITDylib (e.g. because some error 6215ffd83dbSDimitry Andric * prevented the client from calling LLVMOrcJITDylibAddGenerator). 6225ffd83dbSDimitry Andric */ 623d409305fSDimitry Andric void LLVMOrcDisposeDefinitionGenerator(LLVMOrcDefinitionGeneratorRef DG); 6245ffd83dbSDimitry Andric 6255ffd83dbSDimitry Andric /** 626e8d8bef9SDimitry Andric * Dispose of a MaterializationUnit. 627e8d8bef9SDimitry Andric */ 628e8d8bef9SDimitry Andric void LLVMOrcDisposeMaterializationUnit(LLVMOrcMaterializationUnitRef MU); 629e8d8bef9SDimitry Andric 630e8d8bef9SDimitry Andric /** 631fe6060f1SDimitry Andric * Create a custom MaterializationUnit. 632fe6060f1SDimitry Andric * 633fe6060f1SDimitry Andric * Name is a name for this MaterializationUnit to be used for identification 634fe6060f1SDimitry Andric * and logging purposes (e.g. if this MaterializationUnit produces an 635fe6060f1SDimitry Andric * object buffer then the name of that buffer will be derived from this name). 636fe6060f1SDimitry Andric * 637fe6060f1SDimitry Andric * The Syms list contains the names and linkages of the symbols provided by this 638fe6060f1SDimitry Andric * unit. This function takes ownership of the elements of the Syms array. The 639fe6060f1SDimitry Andric * Name fields of the array elements are taken to have been retained for this 640fe6060f1SDimitry Andric * function. The client should *not* release the elements of the array, but is 641fe6060f1SDimitry Andric * still responsible for destroying the array itself. 642fe6060f1SDimitry Andric * 643fe6060f1SDimitry Andric * The InitSym argument indicates whether or not this MaterializationUnit 644fe6060f1SDimitry Andric * contains static initializers. If three are no static initializers (the common 645fe6060f1SDimitry Andric * case) then this argument should be null. If there are static initializers 646fe6060f1SDimitry Andric * then InitSym should be set to a unique name that also appears in the Syms 647fe6060f1SDimitry Andric * list with the LLVMJITSymbolGenericFlagsMaterializationSideEffectsOnly flag 648fe6060f1SDimitry Andric * set. This function takes ownership of the InitSym, which should have been 649fe6060f1SDimitry Andric * retained twice on behalf of this function: once for the Syms entry and once 650fe6060f1SDimitry Andric * for InitSym. If clients wish to use the InitSym value after this function 651fe6060f1SDimitry Andric * returns they must retain it once more for themselves. 652fe6060f1SDimitry Andric * 653fe6060f1SDimitry Andric * If any of the symbols in the Syms list is looked up then the Materialize 654fe6060f1SDimitry Andric * function will be called. 655fe6060f1SDimitry Andric * 656fe6060f1SDimitry Andric * If any of the symbols in the Syms list is overridden then the Discard 657fe6060f1SDimitry Andric * function will be called. 658fe6060f1SDimitry Andric * 659fe6060f1SDimitry Andric * The caller owns the underling MaterializationUnit and is responsible for 660fe6060f1SDimitry Andric * either passing it to a JITDylib (via LLVMOrcJITDylibDefine) or disposing 661fe6060f1SDimitry Andric * of it by calling LLVMOrcDisposeMaterializationUnit. 662fe6060f1SDimitry Andric */ 663fe6060f1SDimitry Andric LLVMOrcMaterializationUnitRef LLVMOrcCreateCustomMaterializationUnit( 664fe6060f1SDimitry Andric const char *Name, void *Ctx, LLVMOrcCSymbolFlagsMapPairs Syms, 665fe6060f1SDimitry Andric size_t NumSyms, LLVMOrcSymbolStringPoolEntryRef InitSym, 666fe6060f1SDimitry Andric LLVMOrcMaterializationUnitMaterializeFunction Materialize, 667fe6060f1SDimitry Andric LLVMOrcMaterializationUnitDiscardFunction Discard, 668fe6060f1SDimitry Andric LLVMOrcMaterializationUnitDestroyFunction Destroy); 669fe6060f1SDimitry Andric 670fe6060f1SDimitry Andric /** 671e8d8bef9SDimitry Andric * Create a MaterializationUnit to define the given symbols as pointing to 672e8d8bef9SDimitry Andric * the corresponding raw addresses. 673fe6060f1SDimitry Andric * 674fe6060f1SDimitry Andric * This function takes ownership of the elements of the Syms array. The Name 675fe6060f1SDimitry Andric * fields of the array elements are taken to have been retained for this 676fe6060f1SDimitry Andric * function. This allows the following pattern... 677fe6060f1SDimitry Andric * 678fe6060f1SDimitry Andric * size_t NumPairs; 679fe6060f1SDimitry Andric * LLVMOrcCSymbolMapPairs Sym; 680fe6060f1SDimitry Andric * -- Build Syms array -- 681fe6060f1SDimitry Andric * LLVMOrcMaterializationUnitRef MU = 682fe6060f1SDimitry Andric * LLVMOrcAbsoluteSymbols(Syms, NumPairs); 683fe6060f1SDimitry Andric * 684fe6060f1SDimitry Andric * ... without requiring cleanup of the elements of the Sym array afterwards. 685fe6060f1SDimitry Andric * 686fe6060f1SDimitry Andric * The client is still responsible for deleting the Sym array itself. 687fe6060f1SDimitry Andric * 688fe6060f1SDimitry Andric * If a client wishes to reuse elements of the Sym array after this call they 689fe6060f1SDimitry Andric * must explicitly retain each of the elements for themselves. 690e8d8bef9SDimitry Andric */ 691e8d8bef9SDimitry Andric LLVMOrcMaterializationUnitRef 692e8d8bef9SDimitry Andric LLVMOrcAbsoluteSymbols(LLVMOrcCSymbolMapPairs Syms, size_t NumPairs); 693e8d8bef9SDimitry Andric 694e8d8bef9SDimitry Andric /** 695fe6060f1SDimitry Andric * Create a MaterializationUnit to define lazy re-expots. These are callable 696fe6060f1SDimitry Andric * entry points that call through to the given symbols. 697fe6060f1SDimitry Andric * 698fe6060f1SDimitry Andric * This function takes ownership of the CallableAliases array. The Name 699fe6060f1SDimitry Andric * fields of the array elements are taken to have been retained for this 700fe6060f1SDimitry Andric * function. This allows the following pattern... 701fe6060f1SDimitry Andric * 702fe6060f1SDimitry Andric * size_t NumPairs; 703fe6060f1SDimitry Andric * LLVMOrcCSymbolAliasMapPairs CallableAliases; 704fe6060f1SDimitry Andric * -- Build CallableAliases array -- 705fe6060f1SDimitry Andric * LLVMOrcMaterializationUnitRef MU = 706fe6060f1SDimitry Andric * LLVMOrcLazyReexports(LCTM, ISM, JD, CallableAliases, NumPairs); 707fe6060f1SDimitry Andric * 708fe6060f1SDimitry Andric * ... without requiring cleanup of the elements of the CallableAliases array afterwards. 709fe6060f1SDimitry Andric * 710fe6060f1SDimitry Andric * The client is still responsible for deleting the CallableAliases array itself. 711fe6060f1SDimitry Andric * 712fe6060f1SDimitry Andric * If a client wishes to reuse elements of the CallableAliases array after this call they 713fe6060f1SDimitry Andric * must explicitly retain each of the elements for themselves. 714fe6060f1SDimitry Andric */ 715fe6060f1SDimitry Andric LLVMOrcMaterializationUnitRef LLVMOrcLazyReexports( 716fe6060f1SDimitry Andric LLVMOrcLazyCallThroughManagerRef LCTM, LLVMOrcIndirectStubsManagerRef ISM, 717fe6060f1SDimitry Andric LLVMOrcJITDylibRef SourceRef, LLVMOrcCSymbolAliasMapPairs CallableAliases, 718fe6060f1SDimitry Andric size_t NumPairs); 719fe6060f1SDimitry Andric // TODO: ImplSymbolMad SrcJDLoc 720fe6060f1SDimitry Andric 721fe6060f1SDimitry Andric /** 722fe6060f1SDimitry Andric * Disposes of the passed MaterializationResponsibility object. 723fe6060f1SDimitry Andric * 724fe6060f1SDimitry Andric * This should only be done after the symbols covered by the object have either 725fe6060f1SDimitry Andric * been resolved and emitted (via 726fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityNotifyResolved and 727fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityNotifyEmitted) or failed (via 728fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityFailMaterialization). 729fe6060f1SDimitry Andric */ 730fe6060f1SDimitry Andric void LLVMOrcDisposeMaterializationResponsibility( 731fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 732fe6060f1SDimitry Andric 733fe6060f1SDimitry Andric /** 734fe6060f1SDimitry Andric * Returns the target JITDylib that these symbols are being materialized into. 735fe6060f1SDimitry Andric */ 736fe6060f1SDimitry Andric LLVMOrcJITDylibRef LLVMOrcMaterializationResponsibilityGetTargetDylib( 737fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 738fe6060f1SDimitry Andric 739fe6060f1SDimitry Andric /** 740fe6060f1SDimitry Andric * Returns the ExecutionSession for this MaterializationResponsibility. 741fe6060f1SDimitry Andric */ 742fe6060f1SDimitry Andric LLVMOrcExecutionSessionRef 743fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityGetExecutionSession( 744fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 745fe6060f1SDimitry Andric 746fe6060f1SDimitry Andric /** 747fe6060f1SDimitry Andric * Returns the symbol flags map for this responsibility instance. 748fe6060f1SDimitry Andric * 749fe6060f1SDimitry Andric * The length of the array is returned in NumPairs and the caller is responsible 750fe6060f1SDimitry Andric * for the returned memory and needs to call LLVMOrcDisposeCSymbolFlagsMap. 751fe6060f1SDimitry Andric * 752fe6060f1SDimitry Andric * To use the returned symbols beyond the livetime of the 753fe6060f1SDimitry Andric * MaterializationResponsibility requires the caller to retain the symbols 754fe6060f1SDimitry Andric * explicitly. 755fe6060f1SDimitry Andric */ 756fe6060f1SDimitry Andric LLVMOrcCSymbolFlagsMapPairs LLVMOrcMaterializationResponsibilityGetSymbols( 757fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, size_t *NumPairs); 758fe6060f1SDimitry Andric 759fe6060f1SDimitry Andric /** 760fe6060f1SDimitry Andric * Disposes of the passed LLVMOrcCSymbolFlagsMap. 761fe6060f1SDimitry Andric * 762fe6060f1SDimitry Andric * Does not release the entries themselves. 763fe6060f1SDimitry Andric */ 764fe6060f1SDimitry Andric void LLVMOrcDisposeCSymbolFlagsMap(LLVMOrcCSymbolFlagsMapPairs Pairs); 765fe6060f1SDimitry Andric 766fe6060f1SDimitry Andric /** 767fe6060f1SDimitry Andric * Returns the initialization pseudo-symbol, if any. This symbol will also 768fe6060f1SDimitry Andric * be present in the SymbolFlagsMap for this MaterializationResponsibility 769fe6060f1SDimitry Andric * object. 770fe6060f1SDimitry Andric * 771fe6060f1SDimitry Andric * The returned symbol is not retained over any mutating operation of the 772fe6060f1SDimitry Andric * MaterializationResponsbility or beyond the lifetime thereof. 773fe6060f1SDimitry Andric */ 774fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef 775fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityGetInitializerSymbol( 776fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 777fe6060f1SDimitry Andric 778fe6060f1SDimitry Andric /** 779fe6060f1SDimitry Andric * Returns the names of any symbols covered by this 780fe6060f1SDimitry Andric * MaterializationResponsibility object that have queries pending. This 781fe6060f1SDimitry Andric * information can be used to return responsibility for unrequested symbols 782fe6060f1SDimitry Andric * back to the JITDylib via the delegate method. 783fe6060f1SDimitry Andric */ 784fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef * 785fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityGetRequestedSymbols( 786fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, size_t *NumSymbols); 787fe6060f1SDimitry Andric 788fe6060f1SDimitry Andric /** 789fe6060f1SDimitry Andric * Disposes of the passed LLVMOrcSymbolStringPoolEntryRef* . 790fe6060f1SDimitry Andric * 791fe6060f1SDimitry Andric * Does not release the symbols themselves. 792fe6060f1SDimitry Andric */ 793fe6060f1SDimitry Andric void LLVMOrcDisposeSymbols(LLVMOrcSymbolStringPoolEntryRef *Symbols); 794fe6060f1SDimitry Andric 79581ad6265SDimitry Andric /** 796fe6060f1SDimitry Andric * Notifies the target JITDylib that the given symbols have been resolved. 797fe6060f1SDimitry Andric * This will update the given symbols' addresses in the JITDylib, and notify 798fe6060f1SDimitry Andric * any pending queries on the given symbols of their resolution. The given 799fe6060f1SDimitry Andric * symbols must be ones covered by this MaterializationResponsibility 800fe6060f1SDimitry Andric * instance. Individual calls to this method may resolve a subset of the 801fe6060f1SDimitry Andric * symbols, but all symbols must have been resolved prior to calling emit. 802fe6060f1SDimitry Andric * 803fe6060f1SDimitry Andric * This method will return an error if any symbols being resolved have been 804fe6060f1SDimitry Andric * moved to the error state due to the failure of a dependency. If this 805fe6060f1SDimitry Andric * method returns an error then clients should log it and call 806fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityFailMaterialization. If no dependencies 807fe6060f1SDimitry Andric * have been registered for the symbols covered by this 8085f757f3fSDimitry Andric * MaterializationResponsibility then this method is guaranteed to return 809fe6060f1SDimitry Andric * LLVMErrorSuccess. 810fe6060f1SDimitry Andric */ 811fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyResolved( 812fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, LLVMOrcCSymbolMapPairs Symbols, 813fe6060f1SDimitry Andric size_t NumPairs); 814fe6060f1SDimitry Andric 815fe6060f1SDimitry Andric /** 816fe6060f1SDimitry Andric * Notifies the target JITDylib (and any pending queries on that JITDylib) 817fe6060f1SDimitry Andric * that all symbols covered by this MaterializationResponsibility instance 818fe6060f1SDimitry Andric * have been emitted. 819fe6060f1SDimitry Andric * 820*0fca6ea1SDimitry Andric * This function takes ownership of the symbols in the Dependencies struct. 821*0fca6ea1SDimitry Andric * This allows the following pattern... 822*0fca6ea1SDimitry Andric * 823*0fca6ea1SDimitry Andric * LLVMOrcSymbolStringPoolEntryRef Names[] = {...}; 824*0fca6ea1SDimitry Andric * LLVMOrcCDependenceMapPair Dependence = {JD, {Names, sizeof(Names)}} 825*0fca6ea1SDimitry Andric * LLVMOrcMaterializationResponsibilityAddDependencies(JD, Name, &Dependence, 826*0fca6ea1SDimitry Andric * 1); 827*0fca6ea1SDimitry Andric * 828*0fca6ea1SDimitry Andric * ... without requiring cleanup of the elements of the Names array afterwards. 829*0fca6ea1SDimitry Andric * 830*0fca6ea1SDimitry Andric * The client is still responsible for deleting the Dependencies.Names arrays, 831*0fca6ea1SDimitry Andric * and the Dependencies array itself. 832*0fca6ea1SDimitry Andric * 833fe6060f1SDimitry Andric * This method will return an error if any symbols being resolved have been 834fe6060f1SDimitry Andric * moved to the error state due to the failure of a dependency. If this 835fe6060f1SDimitry Andric * method returns an error then clients should log it and call 836fe6060f1SDimitry Andric * LLVMOrcMaterializationResponsibilityFailMaterialization. 837fe6060f1SDimitry Andric * If no dependencies have been registered for the symbols covered by this 8385f757f3fSDimitry Andric * MaterializationResponsibility then this method is guaranteed to return 839fe6060f1SDimitry Andric * LLVMErrorSuccess. 840fe6060f1SDimitry Andric */ 841fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyEmitted( 842*0fca6ea1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 843*0fca6ea1SDimitry Andric LLVMOrcCSymbolDependenceGroup *SymbolDepGroups, size_t NumSymbolDepGroups); 844fe6060f1SDimitry Andric 845fe6060f1SDimitry Andric /** 846fe6060f1SDimitry Andric * Attempt to claim responsibility for new definitions. This method can be 847fe6060f1SDimitry Andric * used to claim responsibility for symbols that are added to a 848fe6060f1SDimitry Andric * materialization unit during the compilation process (e.g. literal pool 849fe6060f1SDimitry Andric * symbols). Symbol linkage rules are the same as for symbols that are 850fe6060f1SDimitry Andric * defined up front: duplicate strong definitions will result in errors. 851fe6060f1SDimitry Andric * Duplicate weak definitions will be discarded (in which case they will 852fe6060f1SDimitry Andric * not be added to this responsibility instance). 853fe6060f1SDimitry Andric * 854fe6060f1SDimitry Andric * This method can be used by materialization units that want to add 855fe6060f1SDimitry Andric * additional symbols at materialization time (e.g. stubs, compile 856fe6060f1SDimitry Andric * callbacks, metadata) 857fe6060f1SDimitry Andric */ 858fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityDefineMaterializing( 859fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 860fe6060f1SDimitry Andric LLVMOrcCSymbolFlagsMapPairs Pairs, size_t NumPairs); 861fe6060f1SDimitry Andric 862fe6060f1SDimitry Andric /** 863fe6060f1SDimitry Andric * Notify all not-yet-emitted covered by this MaterializationResponsibility 864fe6060f1SDimitry Andric * instance that an error has occurred. 8655f757f3fSDimitry Andric * This will remove all symbols covered by this MaterializationResponsibility 866fe6060f1SDimitry Andric * from the target JITDylib, and send an error to any queries waiting on 867fe6060f1SDimitry Andric * these symbols. 868fe6060f1SDimitry Andric */ 869fe6060f1SDimitry Andric void LLVMOrcMaterializationResponsibilityFailMaterialization( 870fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR); 871fe6060f1SDimitry Andric 872fe6060f1SDimitry Andric /** 873fe6060f1SDimitry Andric * Transfers responsibility to the given MaterializationUnit for all 874fe6060f1SDimitry Andric * symbols defined by that MaterializationUnit. This allows 875fe6060f1SDimitry Andric * materializers to break up work based on run-time information (e.g. 876fe6060f1SDimitry Andric * by introspecting which symbols have actually been looked up and 877fe6060f1SDimitry Andric * materializing only those). 878fe6060f1SDimitry Andric */ 879fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityReplace( 880fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 881fe6060f1SDimitry Andric LLVMOrcMaterializationUnitRef MU); 882fe6060f1SDimitry Andric 883fe6060f1SDimitry Andric /** 884fe6060f1SDimitry Andric * Delegates responsibility for the given symbols to the returned 885fe6060f1SDimitry Andric * materialization responsibility. Useful for breaking up work between 886fe6060f1SDimitry Andric * threads, or different kinds of materialization processes. 887fe6060f1SDimitry Andric * 888fe6060f1SDimitry Andric * The caller retains responsibility of the the passed 889fe6060f1SDimitry Andric * MaterializationResponsibility. 890fe6060f1SDimitry Andric */ 891fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcMaterializationResponsibilityDelegate( 892fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 893fe6060f1SDimitry Andric LLVMOrcSymbolStringPoolEntryRef *Symbols, size_t NumSymbols, 894fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef *Result); 895fe6060f1SDimitry Andric 896fe6060f1SDimitry Andric /** 897e8d8bef9SDimitry Andric * Create a "bare" JITDylib. 898e8d8bef9SDimitry Andric * 899e8d8bef9SDimitry Andric * The client is responsible for ensuring that the JITDylib's name is unique, 900e8d8bef9SDimitry Andric * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first. 901e8d8bef9SDimitry Andric * 902e8d8bef9SDimitry Andric * This call does not install any library code or symbols into the newly 903e8d8bef9SDimitry Andric * created JITDylib. The client is responsible for all configuration. 904e8d8bef9SDimitry Andric */ 905e8d8bef9SDimitry Andric LLVMOrcJITDylibRef 906e8d8bef9SDimitry Andric LLVMOrcExecutionSessionCreateBareJITDylib(LLVMOrcExecutionSessionRef ES, 907e8d8bef9SDimitry Andric const char *Name); 908e8d8bef9SDimitry Andric 909e8d8bef9SDimitry Andric /** 910e8d8bef9SDimitry Andric * Create a JITDylib. 911e8d8bef9SDimitry Andric * 912e8d8bef9SDimitry Andric * The client is responsible for ensuring that the JITDylib's name is unique, 913e8d8bef9SDimitry Andric * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first. 914e8d8bef9SDimitry Andric * 915e8d8bef9SDimitry Andric * If a Platform is attached to the ExecutionSession then 916e8d8bef9SDimitry Andric * Platform::setupJITDylib will be called to install standard platform symbols 917e8d8bef9SDimitry Andric * (e.g. standard library interposes). If no Platform is installed then this 918e8d8bef9SDimitry Andric * call is equivalent to LLVMExecutionSessionRefCreateBareJITDylib and will 919e8d8bef9SDimitry Andric * always return success. 920e8d8bef9SDimitry Andric */ 921e8d8bef9SDimitry Andric LLVMErrorRef 922e8d8bef9SDimitry Andric LLVMOrcExecutionSessionCreateJITDylib(LLVMOrcExecutionSessionRef ES, 923e8d8bef9SDimitry Andric LLVMOrcJITDylibRef *Result, 924e8d8bef9SDimitry Andric const char *Name); 925e8d8bef9SDimitry Andric 926e8d8bef9SDimitry Andric /** 927e8d8bef9SDimitry Andric * Returns the JITDylib with the given name, or NULL if no such JITDylib 928e8d8bef9SDimitry Andric * exists. 929e8d8bef9SDimitry Andric */ 930d409305fSDimitry Andric LLVMOrcJITDylibRef 931d409305fSDimitry Andric LLVMOrcExecutionSessionGetJITDylibByName(LLVMOrcExecutionSessionRef ES, 932d409305fSDimitry Andric const char *Name); 933e8d8bef9SDimitry Andric 934e8d8bef9SDimitry Andric /** 935e8d8bef9SDimitry Andric * Return a reference to a newly created resource tracker associated with JD. 936e8d8bef9SDimitry Andric * The tracker is returned with an initial ref-count of 1, and must be released 937e8d8bef9SDimitry Andric * with LLVMOrcReleaseResourceTracker when no longer needed. 938e8d8bef9SDimitry Andric */ 939e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef 940e8d8bef9SDimitry Andric LLVMOrcJITDylibCreateResourceTracker(LLVMOrcJITDylibRef JD); 941e8d8bef9SDimitry Andric 942e8d8bef9SDimitry Andric /** 943e8d8bef9SDimitry Andric * Return a reference to the default resource tracker for the given JITDylib. 944e8d8bef9SDimitry Andric * This operation will increase the retain count of the tracker: Clients should 945e8d8bef9SDimitry Andric * call LLVMOrcReleaseResourceTracker when the result is no longer needed. 946e8d8bef9SDimitry Andric */ 947e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef 948e8d8bef9SDimitry Andric LLVMOrcJITDylibGetDefaultResourceTracker(LLVMOrcJITDylibRef JD); 949e8d8bef9SDimitry Andric 950e8d8bef9SDimitry Andric /** 951e8d8bef9SDimitry Andric * Add the given MaterializationUnit to the given JITDylib. 952e8d8bef9SDimitry Andric * 953e8d8bef9SDimitry Andric * If this operation succeeds then JITDylib JD will take ownership of MU. 954e8d8bef9SDimitry Andric * If the operation fails then ownership remains with the caller who should 955e8d8bef9SDimitry Andric * call LLVMOrcDisposeMaterializationUnit to destroy it. 956e8d8bef9SDimitry Andric */ 957e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcJITDylibDefine(LLVMOrcJITDylibRef JD, 958e8d8bef9SDimitry Andric LLVMOrcMaterializationUnitRef MU); 959e8d8bef9SDimitry Andric 960e8d8bef9SDimitry Andric /** 961e8d8bef9SDimitry Andric * Calls remove on all trackers associated with this JITDylib, see 962e8d8bef9SDimitry Andric * JITDylib::clear(). 963e8d8bef9SDimitry Andric */ 964e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcJITDylibClear(LLVMOrcJITDylibRef JD); 965e8d8bef9SDimitry Andric 966e8d8bef9SDimitry Andric /** 967e8d8bef9SDimitry Andric * Add a DefinitionGenerator to the given JITDylib. 9685ffd83dbSDimitry Andric * 9695ffd83dbSDimitry Andric * The JITDylib will take ownership of the given generator: The client is no 9705ffd83dbSDimitry Andric * longer responsible for managing its memory. 9715ffd83dbSDimitry Andric */ 9725ffd83dbSDimitry Andric void LLVMOrcJITDylibAddGenerator(LLVMOrcJITDylibRef JD, 973e8d8bef9SDimitry Andric LLVMOrcDefinitionGeneratorRef DG); 974e8d8bef9SDimitry Andric 975e8d8bef9SDimitry Andric /** 976e8d8bef9SDimitry Andric * Create a custom generator. 97781ad6265SDimitry Andric * 97881ad6265SDimitry Andric * The F argument will be used to implement the DefinitionGenerator's 97981ad6265SDimitry Andric * tryToGenerate method (see 98081ad6265SDimitry Andric * LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction). 98181ad6265SDimitry Andric * 98281ad6265SDimitry Andric * Ctx is a context object that will be passed to F. This argument is 98381ad6265SDimitry Andric * permitted to be null. 98481ad6265SDimitry Andric * 98581ad6265SDimitry Andric * Dispose is the disposal function for Ctx. This argument is permitted to be 98681ad6265SDimitry Andric * null (in which case the client is responsible for the lifetime of Ctx). 987e8d8bef9SDimitry Andric */ 988e8d8bef9SDimitry Andric LLVMOrcDefinitionGeneratorRef LLVMOrcCreateCustomCAPIDefinitionGenerator( 98981ad6265SDimitry Andric LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction F, void *Ctx, 99081ad6265SDimitry Andric LLVMOrcDisposeCAPIDefinitionGeneratorFunction Dispose); 99181ad6265SDimitry Andric 99281ad6265SDimitry Andric /** 99381ad6265SDimitry Andric * Continue a lookup that was suspended in a generator (see 99481ad6265SDimitry Andric * LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction). 99581ad6265SDimitry Andric */ 99681ad6265SDimitry Andric void LLVMOrcLookupStateContinueLookup(LLVMOrcLookupStateRef S, 99781ad6265SDimitry Andric LLVMErrorRef Err); 9985ffd83dbSDimitry Andric 9995ffd83dbSDimitry Andric /** 10005ffd83dbSDimitry Andric * Get a DynamicLibrarySearchGenerator that will reflect process symbols into 10015ffd83dbSDimitry Andric * the JITDylib. On success the resulting generator is owned by the client. 10025ffd83dbSDimitry Andric * Ownership is typically transferred by adding the instance to a JITDylib 10035ffd83dbSDimitry Andric * using LLVMOrcJITDylibAddGenerator, 10045ffd83dbSDimitry Andric * 10055ffd83dbSDimitry Andric * The GlobalPrefix argument specifies the character that appears on the front 10065ffd83dbSDimitry Andric * of linker-mangled symbols for the target platform (e.g. '_' on MachO). 10075ffd83dbSDimitry Andric * If non-null, this character will be stripped from the start of all symbol 10085ffd83dbSDimitry Andric * strings before passing the remaining substring to dlsym. 10095ffd83dbSDimitry Andric * 10105ffd83dbSDimitry Andric * The optional Filter and Ctx arguments can be used to supply a symbol name 10115ffd83dbSDimitry Andric * filter: Only symbols for which the filter returns true will be visible to 10125ffd83dbSDimitry Andric * JIT'd code. If the Filter argument is null then all process symbols will 10135ffd83dbSDimitry Andric * be visible to JIT'd code. Note that the symbol name passed to the Filter 10145ffd83dbSDimitry Andric * function is the full mangled symbol: The client is responsible for stripping 10155ffd83dbSDimitry Andric * the global prefix if present. 10165ffd83dbSDimitry Andric */ 10175ffd83dbSDimitry Andric LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess( 1018e8d8bef9SDimitry Andric LLVMOrcDefinitionGeneratorRef *Result, char GlobalPrefx, 10195ffd83dbSDimitry Andric LLVMOrcSymbolPredicate Filter, void *FilterCtx); 10205ffd83dbSDimitry Andric 10215ffd83dbSDimitry Andric /** 1022349cc55cSDimitry Andric * Get a LLVMOrcCreateDynamicLibararySearchGeneratorForPath that will reflect 1023349cc55cSDimitry Andric * library symbols into the JITDylib. On success the resulting generator is 1024349cc55cSDimitry Andric * owned by the client. Ownership is typically transferred by adding the 1025349cc55cSDimitry Andric * instance to a JITDylib using LLVMOrcJITDylibAddGenerator, 1026349cc55cSDimitry Andric * 1027349cc55cSDimitry Andric * The GlobalPrefix argument specifies the character that appears on the front 1028349cc55cSDimitry Andric * of linker-mangled symbols for the target platform (e.g. '_' on MachO). 1029349cc55cSDimitry Andric * If non-null, this character will be stripped from the start of all symbol 1030349cc55cSDimitry Andric * strings before passing the remaining substring to dlsym. 1031349cc55cSDimitry Andric * 1032349cc55cSDimitry Andric * The optional Filter and Ctx arguments can be used to supply a symbol name 1033349cc55cSDimitry Andric * filter: Only symbols for which the filter returns true will be visible to 1034349cc55cSDimitry Andric * JIT'd code. If the Filter argument is null then all library symbols will 1035349cc55cSDimitry Andric * be visible to JIT'd code. Note that the symbol name passed to the Filter 1036349cc55cSDimitry Andric * function is the full mangled symbol: The client is responsible for stripping 1037349cc55cSDimitry Andric * the global prefix if present. 1038349cc55cSDimitry Andric * 1039349cc55cSDimitry Andric * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE! 1040349cc55cSDimitry Andric * 1041349cc55cSDimitry Andric */ 1042349cc55cSDimitry Andric LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForPath( 1043349cc55cSDimitry Andric LLVMOrcDefinitionGeneratorRef *Result, const char *FileName, 1044349cc55cSDimitry Andric char GlobalPrefix, LLVMOrcSymbolPredicate Filter, void *FilterCtx); 1045349cc55cSDimitry Andric 1046349cc55cSDimitry Andric /** 1047349cc55cSDimitry Andric * Get a LLVMOrcCreateStaticLibrarySearchGeneratorForPath that will reflect 1048349cc55cSDimitry Andric * static library symbols into the JITDylib. On success the resulting 1049349cc55cSDimitry Andric * generator is owned by the client. Ownership is typically transferred by 1050349cc55cSDimitry Andric * adding the instance to a JITDylib using LLVMOrcJITDylibAddGenerator, 1051349cc55cSDimitry Andric * 1052349cc55cSDimitry Andric * Call with the optional TargetTriple argument will succeed if the file at 1053349cc55cSDimitry Andric * the given path is a static library or a MachO universal binary containing a 1054349cc55cSDimitry Andric * static library that is compatible with the given triple. Otherwise it will 1055349cc55cSDimitry Andric * return an error. 1056349cc55cSDimitry Andric * 1057349cc55cSDimitry Andric * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE! 1058349cc55cSDimitry Andric * 1059349cc55cSDimitry Andric */ 1060349cc55cSDimitry Andric LLVMErrorRef LLVMOrcCreateStaticLibrarySearchGeneratorForPath( 1061349cc55cSDimitry Andric LLVMOrcDefinitionGeneratorRef *Result, LLVMOrcObjectLayerRef ObjLayer, 1062349cc55cSDimitry Andric const char *FileName, const char *TargetTriple); 1063349cc55cSDimitry Andric 1064349cc55cSDimitry Andric /** 10655ffd83dbSDimitry Andric * Create a ThreadSafeContext containing a new LLVMContext. 10665ffd83dbSDimitry Andric * 10675ffd83dbSDimitry Andric * Ownership of the underlying ThreadSafeContext data is shared: Clients 10685ffd83dbSDimitry Andric * can and should dispose of their ThreadSafeContext as soon as they no longer 1069e8d8bef9SDimitry Andric * need to refer to it directly. Other references (e.g. from ThreadSafeModules) 10705ffd83dbSDimitry Andric * will keep the data alive as long as it is needed. 10715ffd83dbSDimitry Andric */ 10725ffd83dbSDimitry Andric LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void); 10735ffd83dbSDimitry Andric 10745ffd83dbSDimitry Andric /** 10755ffd83dbSDimitry Andric * Get a reference to the wrapped LLVMContext. 10765ffd83dbSDimitry Andric */ 10775ffd83dbSDimitry Andric LLVMContextRef 10785ffd83dbSDimitry Andric LLVMOrcThreadSafeContextGetContext(LLVMOrcThreadSafeContextRef TSCtx); 10795ffd83dbSDimitry Andric 10805ffd83dbSDimitry Andric /** 10815ffd83dbSDimitry Andric * Dispose of a ThreadSafeContext. 10825ffd83dbSDimitry Andric */ 10835ffd83dbSDimitry Andric void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx); 10845ffd83dbSDimitry Andric 10855ffd83dbSDimitry Andric /** 10865ffd83dbSDimitry Andric * Create a ThreadSafeModule wrapper around the given LLVM module. This takes 10875ffd83dbSDimitry Andric * ownership of the M argument which should not be disposed of or referenced 10885ffd83dbSDimitry Andric * after this function returns. 10895ffd83dbSDimitry Andric * 10905ffd83dbSDimitry Andric * Ownership of the ThreadSafeModule is unique: If it is transferred to the JIT 1091e8d8bef9SDimitry Andric * (e.g. by LLVMOrcLLJITAddLLVMIRModule) then the client is no longer 10925ffd83dbSDimitry Andric * responsible for it. If it is not transferred to the JIT then the client 10935ffd83dbSDimitry Andric * should call LLVMOrcDisposeThreadSafeModule to dispose of it. 10945ffd83dbSDimitry Andric */ 10955ffd83dbSDimitry Andric LLVMOrcThreadSafeModuleRef 10965ffd83dbSDimitry Andric LLVMOrcCreateNewThreadSafeModule(LLVMModuleRef M, 10975ffd83dbSDimitry Andric LLVMOrcThreadSafeContextRef TSCtx); 10985ffd83dbSDimitry Andric 10995ffd83dbSDimitry Andric /** 11005ffd83dbSDimitry Andric * Dispose of a ThreadSafeModule. This should only be called if ownership has 11015ffd83dbSDimitry Andric * not been passed to LLJIT (e.g. because some error prevented the client from 11025ffd83dbSDimitry Andric * adding this to the JIT). 11035ffd83dbSDimitry Andric */ 11045ffd83dbSDimitry Andric void LLVMOrcDisposeThreadSafeModule(LLVMOrcThreadSafeModuleRef TSM); 11055ffd83dbSDimitry Andric 11065ffd83dbSDimitry Andric /** 1107fe6060f1SDimitry Andric * Apply the given function to the module contained in this ThreadSafeModule. 1108fe6060f1SDimitry Andric */ 1109fe6060f1SDimitry Andric LLVMErrorRef 1110fe6060f1SDimitry Andric LLVMOrcThreadSafeModuleWithModuleDo(LLVMOrcThreadSafeModuleRef TSM, 1111fe6060f1SDimitry Andric LLVMOrcGenericIRModuleOperationFunction F, 1112fe6060f1SDimitry Andric void *Ctx); 1113fe6060f1SDimitry Andric 1114fe6060f1SDimitry Andric /** 11155ffd83dbSDimitry Andric * Create a JITTargetMachineBuilder by detecting the host. 11165ffd83dbSDimitry Andric * 11175ffd83dbSDimitry Andric * On success the client owns the resulting JITTargetMachineBuilder. It must be 1118fe6060f1SDimitry Andric * passed to a consuming operation (e.g. 1119fe6060f1SDimitry Andric * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling 1120fe6060f1SDimitry Andric * LLVMOrcDisposeJITTargetMachineBuilder. 11215ffd83dbSDimitry Andric */ 11225ffd83dbSDimitry Andric LLVMErrorRef LLVMOrcJITTargetMachineBuilderDetectHost( 11235ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderRef *Result); 11245ffd83dbSDimitry Andric 11255ffd83dbSDimitry Andric /** 11265ffd83dbSDimitry Andric * Create a JITTargetMachineBuilder from the given TargetMachine template. 11275ffd83dbSDimitry Andric * 11285ffd83dbSDimitry Andric * This operation takes ownership of the given TargetMachine and destroys it 11295ffd83dbSDimitry Andric * before returing. The resulting JITTargetMachineBuilder is owned by the client 1130fe6060f1SDimitry Andric * and must be passed to a consuming operation (e.g. 1131fe6060f1SDimitry Andric * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling 1132fe6060f1SDimitry Andric * LLVMOrcDisposeJITTargetMachineBuilder. 11335ffd83dbSDimitry Andric */ 11345ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderRef 11355ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(LLVMTargetMachineRef TM); 11365ffd83dbSDimitry Andric 11375ffd83dbSDimitry Andric /** 11385ffd83dbSDimitry Andric * Dispose of a JITTargetMachineBuilder. 11395ffd83dbSDimitry Andric */ 11405ffd83dbSDimitry Andric void LLVMOrcDisposeJITTargetMachineBuilder( 11415ffd83dbSDimitry Andric LLVMOrcJITTargetMachineBuilderRef JTMB); 11425ffd83dbSDimitry Andric 11435ffd83dbSDimitry Andric /** 1144fe6060f1SDimitry Andric * Returns the target triple for the given JITTargetMachineBuilder as a string. 1145fe6060f1SDimitry Andric * 1146fe6060f1SDimitry Andric * The caller owns the resulting string as must dispose of it by calling 1147fe6060f1SDimitry Andric * LLVMDisposeMessage 1148fe6060f1SDimitry Andric */ 1149fe6060f1SDimitry Andric char *LLVMOrcJITTargetMachineBuilderGetTargetTriple( 1150fe6060f1SDimitry Andric LLVMOrcJITTargetMachineBuilderRef JTMB); 1151fe6060f1SDimitry Andric 1152fe6060f1SDimitry Andric /** 1153fe6060f1SDimitry Andric * Sets the target triple for the given JITTargetMachineBuilder to the given 1154fe6060f1SDimitry Andric * string. 1155fe6060f1SDimitry Andric */ 1156fe6060f1SDimitry Andric void LLVMOrcJITTargetMachineBuilderSetTargetTriple( 1157fe6060f1SDimitry Andric LLVMOrcJITTargetMachineBuilderRef JTMB, const char *TargetTriple); 1158fe6060f1SDimitry Andric 1159fe6060f1SDimitry Andric /** 1160fe6060f1SDimitry Andric * Add an object to an ObjectLayer to the given JITDylib. 1161fe6060f1SDimitry Andric * 1162fe6060f1SDimitry Andric * Adds a buffer representing an object file to the given JITDylib using the 1163fe6060f1SDimitry Andric * given ObjectLayer instance. This operation transfers ownership of the buffer 1164fe6060f1SDimitry Andric * to the ObjectLayer instance. The buffer should not be disposed of or 1165fe6060f1SDimitry Andric * referenced once this function returns. 1166fe6060f1SDimitry Andric * 1167fe6060f1SDimitry Andric * Resources associated with the given object will be tracked by the given 1168fe6060f1SDimitry Andric * JITDylib's default ResourceTracker. 1169fe6060f1SDimitry Andric */ 1170fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcObjectLayerAddObjectFile(LLVMOrcObjectLayerRef ObjLayer, 1171fe6060f1SDimitry Andric LLVMOrcJITDylibRef JD, 1172fe6060f1SDimitry Andric LLVMMemoryBufferRef ObjBuffer); 1173fe6060f1SDimitry Andric 1174fe6060f1SDimitry Andric /** 1175fe6060f1SDimitry Andric * Add an object to an ObjectLayer using the given ResourceTracker. 1176fe6060f1SDimitry Andric * 1177fe6060f1SDimitry Andric * Adds a buffer representing an object file to the given ResourceTracker's 1178fe6060f1SDimitry Andric * JITDylib using the given ObjectLayer instance. This operation transfers 1179fe6060f1SDimitry Andric * ownership of the buffer to the ObjectLayer instance. The buffer should not 1180fe6060f1SDimitry Andric * be disposed of or referenced once this function returns. 1181fe6060f1SDimitry Andric * 1182fe6060f1SDimitry Andric * Resources associated with the given object will be tracked by 1183fe6060f1SDimitry Andric * ResourceTracker RT. 1184fe6060f1SDimitry Andric */ 1185fe6060f1SDimitry Andric LLVMErrorRef 1186fe6060f1SDimitry Andric LLVMOrcObjectLayerAddObjectFileWithRT(LLVMOrcObjectLayerRef ObjLayer, 1187fe6060f1SDimitry Andric LLVMOrcResourceTrackerRef RT, 1188fe6060f1SDimitry Andric LLVMMemoryBufferRef ObjBuffer); 1189fe6060f1SDimitry Andric 1190fe6060f1SDimitry Andric /** 1191fe6060f1SDimitry Andric * Emit an object buffer to an ObjectLayer. 1192fe6060f1SDimitry Andric * 1193fe6060f1SDimitry Andric * Ownership of the responsibility object and object buffer pass to this 1194fe6060f1SDimitry Andric * function. The client is not responsible for cleanup. 1195fe6060f1SDimitry Andric */ 1196fe6060f1SDimitry Andric void LLVMOrcObjectLayerEmit(LLVMOrcObjectLayerRef ObjLayer, 1197fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef R, 1198fe6060f1SDimitry Andric LLVMMemoryBufferRef ObjBuffer); 1199fe6060f1SDimitry Andric 1200fe6060f1SDimitry Andric /** 1201e8d8bef9SDimitry Andric * Dispose of an ObjectLayer. 12025ffd83dbSDimitry Andric */ 1203e8d8bef9SDimitry Andric void LLVMOrcDisposeObjectLayer(LLVMOrcObjectLayerRef ObjLayer); 12045ffd83dbSDimitry Andric 1205fe6060f1SDimitry Andric void LLVMOrcIRTransformLayerEmit(LLVMOrcIRTransformLayerRef IRTransformLayer, 1206fe6060f1SDimitry Andric LLVMOrcMaterializationResponsibilityRef MR, 1207fe6060f1SDimitry Andric LLVMOrcThreadSafeModuleRef TSM); 1208fe6060f1SDimitry Andric 1209fe6060f1SDimitry Andric /** 1210fe6060f1SDimitry Andric * Set the transform function of the provided transform layer, passing through a 1211fe6060f1SDimitry Andric * pointer to user provided context. 1212fe6060f1SDimitry Andric */ 1213fe6060f1SDimitry Andric void LLVMOrcIRTransformLayerSetTransform( 1214fe6060f1SDimitry Andric LLVMOrcIRTransformLayerRef IRTransformLayer, 1215fe6060f1SDimitry Andric LLVMOrcIRTransformLayerTransformFunction TransformFunction, void *Ctx); 1216fe6060f1SDimitry Andric 1217fe6060f1SDimitry Andric /** 1218fe6060f1SDimitry Andric * Set the transform function on an LLVMOrcObjectTransformLayer. 1219fe6060f1SDimitry Andric */ 1220fe6060f1SDimitry Andric void LLVMOrcObjectTransformLayerSetTransform( 1221fe6060f1SDimitry Andric LLVMOrcObjectTransformLayerRef ObjTransformLayer, 1222fe6060f1SDimitry Andric LLVMOrcObjectTransformLayerTransformFunction TransformFunction, void *Ctx); 1223fe6060f1SDimitry Andric 1224fe6060f1SDimitry Andric /** 1225fe6060f1SDimitry Andric * Create a LocalIndirectStubsManager from the given target triple. 1226fe6060f1SDimitry Andric * 1227fe6060f1SDimitry Andric * The resulting IndirectStubsManager is owned by the client 1228fe6060f1SDimitry Andric * and must be disposed of by calling LLVMOrcDisposeDisposeIndirectStubsManager. 1229fe6060f1SDimitry Andric */ 1230fe6060f1SDimitry Andric LLVMOrcIndirectStubsManagerRef 1231fe6060f1SDimitry Andric LLVMOrcCreateLocalIndirectStubsManager(const char *TargetTriple); 1232fe6060f1SDimitry Andric 1233fe6060f1SDimitry Andric /** 1234fe6060f1SDimitry Andric * Dispose of an IndirectStubsManager. 1235fe6060f1SDimitry Andric */ 1236fe6060f1SDimitry Andric void LLVMOrcDisposeIndirectStubsManager(LLVMOrcIndirectStubsManagerRef ISM); 1237fe6060f1SDimitry Andric 1238fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcCreateLocalLazyCallThroughManager( 1239fe6060f1SDimitry Andric const char *TargetTriple, LLVMOrcExecutionSessionRef ES, 1240fe6060f1SDimitry Andric LLVMOrcJITTargetAddress ErrorHandlerAddr, 1241fe6060f1SDimitry Andric LLVMOrcLazyCallThroughManagerRef *LCTM); 1242fe6060f1SDimitry Andric 1243fe6060f1SDimitry Andric /** 1244fe6060f1SDimitry Andric * Dispose of an LazyCallThroughManager. 1245fe6060f1SDimitry Andric */ 1246fe6060f1SDimitry Andric void LLVMOrcDisposeLazyCallThroughManager( 1247fe6060f1SDimitry Andric LLVMOrcLazyCallThroughManagerRef LCTM); 1248fe6060f1SDimitry Andric 1249fe6060f1SDimitry Andric /** 1250fe6060f1SDimitry Andric * Create a DumpObjects instance. 1251fe6060f1SDimitry Andric * 1252fe6060f1SDimitry Andric * DumpDir specifies the path to write dumped objects to. DumpDir may be empty 1253fe6060f1SDimitry Andric * in which case files will be dumped to the working directory. 1254fe6060f1SDimitry Andric * 1255fe6060f1SDimitry Andric * IdentifierOverride specifies a file name stem to use when dumping objects. 1256fe6060f1SDimitry Andric * If empty then each MemoryBuffer's identifier will be used (with a .o suffix 1257fe6060f1SDimitry Andric * added if not already present). If an identifier override is supplied it will 1258fe6060f1SDimitry Andric * be used instead, along with an incrementing counter (since all buffers will 1259fe6060f1SDimitry Andric * use the same identifier, the resulting files will be named <ident>.o, 1260fe6060f1SDimitry Andric * <ident>.2.o, <ident>.3.o, and so on). IdentifierOverride should not contain 1261fe6060f1SDimitry Andric * an extension, as a .o suffix will be added by DumpObjects. 1262fe6060f1SDimitry Andric */ 1263fe6060f1SDimitry Andric LLVMOrcDumpObjectsRef LLVMOrcCreateDumpObjects(const char *DumpDir, 1264fe6060f1SDimitry Andric const char *IdentifierOverride); 1265fe6060f1SDimitry Andric 1266fe6060f1SDimitry Andric /** 1267fe6060f1SDimitry Andric * Dispose of a DumpObjects instance. 1268fe6060f1SDimitry Andric */ 1269fe6060f1SDimitry Andric void LLVMOrcDisposeDumpObjects(LLVMOrcDumpObjectsRef DumpObjects); 1270fe6060f1SDimitry Andric 1271fe6060f1SDimitry Andric /** 1272fe6060f1SDimitry Andric * Dump the contents of the given MemoryBuffer. 1273fe6060f1SDimitry Andric */ 1274fe6060f1SDimitry Andric LLVMErrorRef LLVMOrcDumpObjects_CallOperator(LLVMOrcDumpObjectsRef DumpObjects, 1275fe6060f1SDimitry Andric LLVMMemoryBufferRef *ObjBuffer); 1276fe6060f1SDimitry Andric 1277349cc55cSDimitry Andric /** 1278349cc55cSDimitry Andric * @} 1279349cc55cSDimitry Andric */ 1280349cc55cSDimitry Andric 12815ffd83dbSDimitry Andric LLVM_C_EXTERN_C_END 12825ffd83dbSDimitry Andric 12835ffd83dbSDimitry Andric #endif /* LLVM_C_ORC_H */ 1284