1097a140dSpatrick /*===---------------- llvm-c/Orc.h - OrcV2 C bindings -----------*- C++ -*-===*\ 2097a140dSpatrick |* *| 3097a140dSpatrick |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 4097a140dSpatrick |* Exceptions. *| 5097a140dSpatrick |* See https://llvm.org/LICENSE.txt for license information. *| 6097a140dSpatrick |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 7097a140dSpatrick |* *| 8097a140dSpatrick |*===----------------------------------------------------------------------===*| 9097a140dSpatrick |* *| 10097a140dSpatrick |* This header declares the C interface to libLLVMOrcJIT.a, which implements *| 11097a140dSpatrick |* JIT compilation of LLVM IR. Minimal documentation of C API specific issues *| 12097a140dSpatrick |* (especially memory ownership rules) is provided. Core Orc concepts are *| 13097a140dSpatrick |* documented in llvm/docs/ORCv2.rst and APIs are documented in the C++ *| 14097a140dSpatrick |* headers *| 15097a140dSpatrick |* *| 16097a140dSpatrick |* Many exotic languages can interoperate with C code but have a harder time *| 17097a140dSpatrick |* with C++ due to name mangling. So in addition to C, this interface enables *| 18097a140dSpatrick |* tools written in such languages. *| 19097a140dSpatrick |* *| 20097a140dSpatrick |* Note: This interface is experimental. It is *NOT* stable, and may be *| 21097a140dSpatrick |* changed without warning. Only C API usage documentation is *| 22097a140dSpatrick |* provided. See the C++ documentation for all higher level ORC API *| 23097a140dSpatrick |* details. *| 24097a140dSpatrick |* *| 25097a140dSpatrick \*===----------------------------------------------------------------------===*/ 26097a140dSpatrick 27097a140dSpatrick #ifndef LLVM_C_ORC_H 28097a140dSpatrick #define LLVM_C_ORC_H 29097a140dSpatrick 30097a140dSpatrick #include "llvm-c/Error.h" 31097a140dSpatrick #include "llvm-c/TargetMachine.h" 32097a140dSpatrick #include "llvm-c/Types.h" 33097a140dSpatrick 34097a140dSpatrick LLVM_C_EXTERN_C_BEGIN 35097a140dSpatrick 36097a140dSpatrick /** 37*d415bd75Srobert * @defgroup LLVMCExecutionEngineORC On-Request-Compilation 38*d415bd75Srobert * @ingroup LLVMCExecutionEngine 39*d415bd75Srobert * 40*d415bd75Srobert * @{ 41*d415bd75Srobert */ 42*d415bd75Srobert 43*d415bd75Srobert /** 4473471bf0Spatrick * Represents an address in the executor process. 45097a140dSpatrick */ 46097a140dSpatrick typedef uint64_t LLVMOrcJITTargetAddress; 47097a140dSpatrick 48097a140dSpatrick /** 4973471bf0Spatrick * Represents an address in the executor process. 5073471bf0Spatrick */ 5173471bf0Spatrick typedef uint64_t LLVMOrcExecutorAddress; 5273471bf0Spatrick 5373471bf0Spatrick /** 5473471bf0Spatrick * Represents generic linkage flags for a symbol definition. 5573471bf0Spatrick */ 5673471bf0Spatrick typedef enum { 57*d415bd75Srobert LLVMJITSymbolGenericFlagsNone = 0, 5873471bf0Spatrick LLVMJITSymbolGenericFlagsExported = 1U << 0, 5973471bf0Spatrick LLVMJITSymbolGenericFlagsWeak = 1U << 1, 6073471bf0Spatrick LLVMJITSymbolGenericFlagsCallable = 1U << 2, 6173471bf0Spatrick LLVMJITSymbolGenericFlagsMaterializationSideEffectsOnly = 1U << 3 6273471bf0Spatrick } LLVMJITSymbolGenericFlags; 6373471bf0Spatrick 6473471bf0Spatrick /** 6573471bf0Spatrick * Represents target specific flags for a symbol definition. 6673471bf0Spatrick */ 6773471bf0Spatrick typedef uint8_t LLVMJITSymbolTargetFlags; 6873471bf0Spatrick 6973471bf0Spatrick /** 7073471bf0Spatrick * Represents the linkage flags for a symbol definition. 7173471bf0Spatrick */ 7273471bf0Spatrick typedef struct { 7373471bf0Spatrick uint8_t GenericFlags; 7473471bf0Spatrick uint8_t TargetFlags; 7573471bf0Spatrick } LLVMJITSymbolFlags; 7673471bf0Spatrick 7773471bf0Spatrick /** 7873471bf0Spatrick * Represents an evaluated symbol address and flags. 7973471bf0Spatrick */ 8073471bf0Spatrick typedef struct { 8173471bf0Spatrick LLVMOrcExecutorAddress Address; 8273471bf0Spatrick LLVMJITSymbolFlags Flags; 8373471bf0Spatrick } LLVMJITEvaluatedSymbol; 8473471bf0Spatrick 8573471bf0Spatrick /** 86097a140dSpatrick * A reference to an orc::ExecutionSession instance. 87097a140dSpatrick */ 88097a140dSpatrick typedef struct LLVMOrcOpaqueExecutionSession *LLVMOrcExecutionSessionRef; 89097a140dSpatrick 90097a140dSpatrick /** 9173471bf0Spatrick * Error reporter function. 9273471bf0Spatrick */ 9373471bf0Spatrick typedef void (*LLVMOrcErrorReporterFunction)(void *Ctx, LLVMErrorRef Err); 9473471bf0Spatrick 9573471bf0Spatrick /** 9673471bf0Spatrick * A reference to an orc::SymbolStringPool. 9773471bf0Spatrick */ 9873471bf0Spatrick typedef struct LLVMOrcOpaqueSymbolStringPool *LLVMOrcSymbolStringPoolRef; 9973471bf0Spatrick 10073471bf0Spatrick /** 101097a140dSpatrick * A reference to an orc::SymbolStringPool table entry. 102097a140dSpatrick */ 10373471bf0Spatrick typedef struct LLVMOrcOpaqueSymbolStringPoolEntry 104097a140dSpatrick *LLVMOrcSymbolStringPoolEntryRef; 105097a140dSpatrick 106097a140dSpatrick /** 10773471bf0Spatrick * Represents a pair of a symbol name and LLVMJITSymbolFlags. 10873471bf0Spatrick */ 10973471bf0Spatrick typedef struct { 11073471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef Name; 11173471bf0Spatrick LLVMJITSymbolFlags Flags; 11273471bf0Spatrick } LLVMOrcCSymbolFlagsMapPair; 11373471bf0Spatrick 11473471bf0Spatrick /** 11573471bf0Spatrick * Represents a list of (SymbolStringPtr, JITSymbolFlags) pairs that can be used 11673471bf0Spatrick * to construct a SymbolFlagsMap. 11773471bf0Spatrick */ 11873471bf0Spatrick typedef LLVMOrcCSymbolFlagsMapPair *LLVMOrcCSymbolFlagsMapPairs; 11973471bf0Spatrick 12073471bf0Spatrick /** 12173471bf0Spatrick * Represents a pair of a symbol name and an evaluated symbol. 12273471bf0Spatrick */ 12373471bf0Spatrick typedef struct { 12473471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef Name; 12573471bf0Spatrick LLVMJITEvaluatedSymbol Sym; 126*d415bd75Srobert } LLVMOrcCSymbolMapPair; 12773471bf0Spatrick 12873471bf0Spatrick /** 12973471bf0Spatrick * Represents a list of (SymbolStringPtr, JITEvaluatedSymbol) pairs that can be 13073471bf0Spatrick * used to construct a SymbolMap. 13173471bf0Spatrick */ 132*d415bd75Srobert typedef LLVMOrcCSymbolMapPair *LLVMOrcCSymbolMapPairs; 13373471bf0Spatrick 13473471bf0Spatrick /** 13573471bf0Spatrick * Represents a SymbolAliasMapEntry 13673471bf0Spatrick */ 13773471bf0Spatrick typedef struct { 13873471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef Name; 13973471bf0Spatrick LLVMJITSymbolFlags Flags; 14073471bf0Spatrick } LLVMOrcCSymbolAliasMapEntry; 14173471bf0Spatrick 14273471bf0Spatrick /** 14373471bf0Spatrick * Represents a pair of a symbol name and SymbolAliasMapEntry. 14473471bf0Spatrick */ 14573471bf0Spatrick typedef struct { 14673471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef Name; 14773471bf0Spatrick LLVMOrcCSymbolAliasMapEntry Entry; 14873471bf0Spatrick } LLVMOrcCSymbolAliasMapPair; 14973471bf0Spatrick 15073471bf0Spatrick /** 15173471bf0Spatrick * Represents a list of (SymbolStringPtr, (SymbolStringPtr, JITSymbolFlags)) 15273471bf0Spatrick * pairs that can be used to construct a SymbolFlagsMap. 15373471bf0Spatrick */ 15473471bf0Spatrick typedef LLVMOrcCSymbolAliasMapPair *LLVMOrcCSymbolAliasMapPairs; 15573471bf0Spatrick 15673471bf0Spatrick /** 157097a140dSpatrick * A reference to an orc::JITDylib instance. 158097a140dSpatrick */ 159097a140dSpatrick typedef struct LLVMOrcOpaqueJITDylib *LLVMOrcJITDylibRef; 160097a140dSpatrick 161097a140dSpatrick /** 16273471bf0Spatrick * Represents a list of LLVMOrcSymbolStringPoolEntryRef and the associated 16373471bf0Spatrick * length. 164097a140dSpatrick */ 16573471bf0Spatrick typedef struct { 16673471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef *Symbols; 16773471bf0Spatrick size_t Length; 16873471bf0Spatrick } LLVMOrcCSymbolsList; 16973471bf0Spatrick 17073471bf0Spatrick /** 17173471bf0Spatrick * Represents a pair of a JITDylib and LLVMOrcCSymbolsList. 17273471bf0Spatrick */ 17373471bf0Spatrick typedef struct { 17473471bf0Spatrick LLVMOrcJITDylibRef JD; 17573471bf0Spatrick LLVMOrcCSymbolsList Names; 17673471bf0Spatrick } LLVMOrcCDependenceMapPair; 17773471bf0Spatrick 17873471bf0Spatrick /** 17973471bf0Spatrick * Represents a list of (JITDylibRef, (LLVMOrcSymbolStringPoolEntryRef*, 18073471bf0Spatrick * size_t)) pairs that can be used to construct a SymbolDependenceMap. 18173471bf0Spatrick */ 18273471bf0Spatrick typedef LLVMOrcCDependenceMapPair *LLVMOrcCDependenceMapPairs; 18373471bf0Spatrick 18473471bf0Spatrick /** 18573471bf0Spatrick * Lookup kind. This can be used by definition generators when deciding whether 18673471bf0Spatrick * to produce a definition for a requested symbol. 18773471bf0Spatrick * 18873471bf0Spatrick * This enum should be kept in sync with llvm::orc::LookupKind. 18973471bf0Spatrick */ 19073471bf0Spatrick typedef enum { 19173471bf0Spatrick LLVMOrcLookupKindStatic, 19273471bf0Spatrick LLVMOrcLookupKindDLSym 19373471bf0Spatrick } LLVMOrcLookupKind; 19473471bf0Spatrick 19573471bf0Spatrick /** 19673471bf0Spatrick * JITDylib lookup flags. This can be used by definition generators when 19773471bf0Spatrick * deciding whether to produce a definition for a requested symbol. 19873471bf0Spatrick * 19973471bf0Spatrick * This enum should be kept in sync with llvm::orc::JITDylibLookupFlags. 20073471bf0Spatrick */ 20173471bf0Spatrick typedef enum { 20273471bf0Spatrick LLVMOrcJITDylibLookupFlagsMatchExportedSymbolsOnly, 20373471bf0Spatrick LLVMOrcJITDylibLookupFlagsMatchAllSymbols 20473471bf0Spatrick } LLVMOrcJITDylibLookupFlags; 20573471bf0Spatrick 20673471bf0Spatrick /** 207*d415bd75Srobert * An element type for a JITDylib search order. 208*d415bd75Srobert */ 209*d415bd75Srobert typedef struct { 210*d415bd75Srobert LLVMOrcJITDylibRef JD; 211*d415bd75Srobert LLVMOrcJITDylibLookupFlags JDLookupFlags; 212*d415bd75Srobert } LLVMOrcCJITDylibSearchOrderElement; 213*d415bd75Srobert 214*d415bd75Srobert /** 215*d415bd75Srobert * A JITDylib search order. 216*d415bd75Srobert * 217*d415bd75Srobert * The list is terminated with an element containing a null pointer for the JD 218*d415bd75Srobert * field. 219*d415bd75Srobert */ 220*d415bd75Srobert typedef LLVMOrcCJITDylibSearchOrderElement *LLVMOrcCJITDylibSearchOrder; 221*d415bd75Srobert 222*d415bd75Srobert /** 22373471bf0Spatrick * Symbol lookup flags for lookup sets. This should be kept in sync with 22473471bf0Spatrick * llvm::orc::SymbolLookupFlags. 22573471bf0Spatrick */ 22673471bf0Spatrick typedef enum { 22773471bf0Spatrick LLVMOrcSymbolLookupFlagsRequiredSymbol, 22873471bf0Spatrick LLVMOrcSymbolLookupFlagsWeaklyReferencedSymbol 22973471bf0Spatrick } LLVMOrcSymbolLookupFlags; 23073471bf0Spatrick 23173471bf0Spatrick /** 23273471bf0Spatrick * An element type for a symbol lookup set. 23373471bf0Spatrick */ 23473471bf0Spatrick typedef struct { 23573471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef Name; 23673471bf0Spatrick LLVMOrcSymbolLookupFlags LookupFlags; 23773471bf0Spatrick } LLVMOrcCLookupSetElement; 23873471bf0Spatrick 23973471bf0Spatrick /** 24073471bf0Spatrick * A set of symbols to look up / generate. 24173471bf0Spatrick * 24273471bf0Spatrick * The list is terminated with an element containing a null pointer for the 24373471bf0Spatrick * Name field. 24473471bf0Spatrick * 24573471bf0Spatrick * If a client creates an instance of this type then they are responsible for 24673471bf0Spatrick * freeing it, and for ensuring that all strings have been retained over the 24773471bf0Spatrick * course of its life. Clients receiving a copy from a callback are not 24873471bf0Spatrick * responsible for managing lifetime or retain counts. 24973471bf0Spatrick */ 25073471bf0Spatrick typedef LLVMOrcCLookupSetElement *LLVMOrcCLookupSet; 25173471bf0Spatrick 25273471bf0Spatrick /** 25373471bf0Spatrick * A reference to a uniquely owned orc::MaterializationUnit instance. 25473471bf0Spatrick */ 25573471bf0Spatrick typedef struct LLVMOrcOpaqueMaterializationUnit *LLVMOrcMaterializationUnitRef; 25673471bf0Spatrick 25773471bf0Spatrick /** 25873471bf0Spatrick * A reference to a uniquely owned orc::MaterializationResponsibility instance. 25973471bf0Spatrick * 26073471bf0Spatrick * Ownership must be passed to a lower-level layer in a JIT stack. 26173471bf0Spatrick */ 26273471bf0Spatrick typedef struct LLVMOrcOpaqueMaterializationResponsibility 26373471bf0Spatrick *LLVMOrcMaterializationResponsibilityRef; 26473471bf0Spatrick 26573471bf0Spatrick /** 26673471bf0Spatrick * A MaterializationUnit materialize callback. 26773471bf0Spatrick * 26873471bf0Spatrick * Ownership of the Ctx and MR arguments passes to the callback which must 26973471bf0Spatrick * adhere to the LLVMOrcMaterializationResponsibilityRef contract (see comment 27073471bf0Spatrick * for that type). 27173471bf0Spatrick * 27273471bf0Spatrick * If this callback is called then the LLVMOrcMaterializationUnitDestroy 27373471bf0Spatrick * callback will NOT be called. 27473471bf0Spatrick */ 27573471bf0Spatrick typedef void (*LLVMOrcMaterializationUnitMaterializeFunction)( 27673471bf0Spatrick void *Ctx, LLVMOrcMaterializationResponsibilityRef MR); 27773471bf0Spatrick 27873471bf0Spatrick /** 27973471bf0Spatrick * A MaterializationUnit discard callback. 28073471bf0Spatrick * 28173471bf0Spatrick * Ownership of JD and Symbol remain with the caller: These arguments should 28273471bf0Spatrick * not be disposed of or released. 28373471bf0Spatrick */ 28473471bf0Spatrick typedef void (*LLVMOrcMaterializationUnitDiscardFunction)( 28573471bf0Spatrick void *Ctx, LLVMOrcJITDylibRef JD, LLVMOrcSymbolStringPoolEntryRef Symbol); 28673471bf0Spatrick 28773471bf0Spatrick /** 28873471bf0Spatrick * A MaterializationUnit destruction callback. 28973471bf0Spatrick * 29073471bf0Spatrick * If a custom MaterializationUnit is destroyed before its Materialize 29173471bf0Spatrick * function is called then this function will be called to provide an 29273471bf0Spatrick * opportunity for the underlying program representation to be destroyed. 29373471bf0Spatrick */ 29473471bf0Spatrick typedef void (*LLVMOrcMaterializationUnitDestroyFunction)(void *Ctx); 29573471bf0Spatrick 29673471bf0Spatrick /** 29773471bf0Spatrick * A reference to an orc::ResourceTracker instance. 29873471bf0Spatrick */ 29973471bf0Spatrick typedef struct LLVMOrcOpaqueResourceTracker *LLVMOrcResourceTrackerRef; 30073471bf0Spatrick 30173471bf0Spatrick /** 30273471bf0Spatrick * A reference to an orc::DefinitionGenerator. 30373471bf0Spatrick */ 30473471bf0Spatrick typedef struct LLVMOrcOpaqueDefinitionGenerator 30573471bf0Spatrick *LLVMOrcDefinitionGeneratorRef; 30673471bf0Spatrick 30773471bf0Spatrick /** 30873471bf0Spatrick * An opaque lookup state object. Instances of this type can be captured to 30973471bf0Spatrick * suspend a lookup while a custom generator function attempts to produce a 31073471bf0Spatrick * definition. 31173471bf0Spatrick * 31273471bf0Spatrick * If a client captures a lookup state object then they must eventually call 31373471bf0Spatrick * LLVMOrcLookupStateContinueLookup to restart the lookup. This is required 31473471bf0Spatrick * in order to release memory allocated for the lookup state, even if errors 31573471bf0Spatrick * have occurred while the lookup was suspended (if these errors have made the 31673471bf0Spatrick * lookup impossible to complete then it will issue its own error before 31773471bf0Spatrick * destruction). 31873471bf0Spatrick */ 31973471bf0Spatrick typedef struct LLVMOrcOpaqueLookupState *LLVMOrcLookupStateRef; 32073471bf0Spatrick 32173471bf0Spatrick /** 32273471bf0Spatrick * A custom generator function. This can be used to create a custom generator 32373471bf0Spatrick * object using LLVMOrcCreateCustomCAPIDefinitionGenerator. The resulting 32473471bf0Spatrick * object can be attached to a JITDylib, via LLVMOrcJITDylibAddGenerator, to 32573471bf0Spatrick * receive callbacks when lookups fail to match existing definitions. 32673471bf0Spatrick * 32773471bf0Spatrick * GeneratorObj will contain the address of the custom generator object. 32873471bf0Spatrick * 32973471bf0Spatrick * Ctx will contain the context object passed to 33073471bf0Spatrick * LLVMOrcCreateCustomCAPIDefinitionGenerator. 33173471bf0Spatrick * 33273471bf0Spatrick * LookupState will contain a pointer to an LLVMOrcLookupStateRef object. This 33373471bf0Spatrick * can optionally be modified to make the definition generation process 33473471bf0Spatrick * asynchronous: If the LookupStateRef value is copied, and the original 33573471bf0Spatrick * LLVMOrcLookupStateRef set to null, the lookup will be suspended. Once the 33673471bf0Spatrick * asynchronous definition process has been completed clients must call 33773471bf0Spatrick * LLVMOrcLookupStateContinueLookup to continue the lookup (this should be 33873471bf0Spatrick * done unconditionally, even if errors have occurred in the mean time, to 33973471bf0Spatrick * free the lookup state memory and notify the query object of the failures). 34073471bf0Spatrick * If LookupState is captured this function must return LLVMErrorSuccess. 34173471bf0Spatrick * 34273471bf0Spatrick * The Kind argument can be inspected to determine the lookup kind (e.g. 34373471bf0Spatrick * as-if-during-static-link, or as-if-during-dlsym). 34473471bf0Spatrick * 34573471bf0Spatrick * The JD argument specifies which JITDylib the definitions should be generated 34673471bf0Spatrick * into. 34773471bf0Spatrick * 34873471bf0Spatrick * The JDLookupFlags argument can be inspected to determine whether the original 34973471bf0Spatrick * lookup included non-exported symobls. 35073471bf0Spatrick * 35173471bf0Spatrick * Finally, the LookupSet argument contains the set of symbols that could not 35273471bf0Spatrick * be found in JD already (the set of generation candidates). 35373471bf0Spatrick */ 35473471bf0Spatrick typedef LLVMErrorRef (*LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction)( 35573471bf0Spatrick LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx, 35673471bf0Spatrick LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind, 35773471bf0Spatrick LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags, 35873471bf0Spatrick LLVMOrcCLookupSet LookupSet, size_t LookupSetSize); 359097a140dSpatrick 360097a140dSpatrick /** 361*d415bd75Srobert * Disposer for a custom generator. 362*d415bd75Srobert * 363*d415bd75Srobert * Will be called by ORC when the JITDylib that the generator is attached to 364*d415bd75Srobert * is destroyed. 365*d415bd75Srobert */ 366*d415bd75Srobert typedef void (*LLVMOrcDisposeCAPIDefinitionGeneratorFunction)(void *Ctx); 367*d415bd75Srobert 368*d415bd75Srobert /** 369097a140dSpatrick * Predicate function for SymbolStringPoolEntries. 370097a140dSpatrick */ 37173471bf0Spatrick typedef int (*LLVMOrcSymbolPredicate)(void *Ctx, 37273471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef Sym); 373097a140dSpatrick 374097a140dSpatrick /** 375097a140dSpatrick * A reference to an orc::ThreadSafeContext instance. 376097a140dSpatrick */ 377097a140dSpatrick typedef struct LLVMOrcOpaqueThreadSafeContext *LLVMOrcThreadSafeContextRef; 378097a140dSpatrick 379097a140dSpatrick /** 380097a140dSpatrick * A reference to an orc::ThreadSafeModule instance. 381097a140dSpatrick */ 382097a140dSpatrick typedef struct LLVMOrcOpaqueThreadSafeModule *LLVMOrcThreadSafeModuleRef; 383097a140dSpatrick 384097a140dSpatrick /** 38573471bf0Spatrick * A function for inspecting/mutating IR modules, suitable for use with 38673471bf0Spatrick * LLVMOrcThreadSafeModuleWithModuleDo. 38773471bf0Spatrick */ 38873471bf0Spatrick typedef LLVMErrorRef (*LLVMOrcGenericIRModuleOperationFunction)( 38973471bf0Spatrick void *Ctx, LLVMModuleRef M); 39073471bf0Spatrick 39173471bf0Spatrick /** 392097a140dSpatrick * A reference to an orc::JITTargetMachineBuilder instance. 393097a140dSpatrick */ 394097a140dSpatrick typedef struct LLVMOrcOpaqueJITTargetMachineBuilder 395097a140dSpatrick *LLVMOrcJITTargetMachineBuilderRef; 396097a140dSpatrick 397097a140dSpatrick /** 39873471bf0Spatrick * A reference to an orc::ObjectLayer instance. 399097a140dSpatrick */ 40073471bf0Spatrick typedef struct LLVMOrcOpaqueObjectLayer *LLVMOrcObjectLayerRef; 401097a140dSpatrick 402097a140dSpatrick /** 40373471bf0Spatrick * A reference to an orc::ObjectLinkingLayer instance. 404097a140dSpatrick */ 40573471bf0Spatrick typedef struct LLVMOrcOpaqueObjectLinkingLayer *LLVMOrcObjectLinkingLayerRef; 40673471bf0Spatrick 40773471bf0Spatrick /** 40873471bf0Spatrick * A reference to an orc::IRTransformLayer instance. 40973471bf0Spatrick */ 41073471bf0Spatrick typedef struct LLVMOrcOpaqueIRTransformLayer *LLVMOrcIRTransformLayerRef; 41173471bf0Spatrick 41273471bf0Spatrick /** 41373471bf0Spatrick * A function for applying transformations as part of an transform layer. 41473471bf0Spatrick * 41573471bf0Spatrick * Implementations of this type are responsible for managing the lifetime 41673471bf0Spatrick * of the Module pointed to by ModInOut: If the LLVMModuleRef value is 41773471bf0Spatrick * overwritten then the function is responsible for disposing of the incoming 41873471bf0Spatrick * module. If the module is simply accessed/mutated in-place then ownership 41973471bf0Spatrick * returns to the caller and the function does not need to do any lifetime 42073471bf0Spatrick * management. 42173471bf0Spatrick * 42273471bf0Spatrick * Clients can call LLVMOrcLLJITGetIRTransformLayer to obtain the transform 42373471bf0Spatrick * layer of a LLJIT instance, and use LLVMOrcIRTransformLayerSetTransform 42473471bf0Spatrick * to set the function. This can be used to override the default transform 42573471bf0Spatrick * layer. 42673471bf0Spatrick */ 42773471bf0Spatrick typedef LLVMErrorRef (*LLVMOrcIRTransformLayerTransformFunction)( 42873471bf0Spatrick void *Ctx, LLVMOrcThreadSafeModuleRef *ModInOut, 42973471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR); 43073471bf0Spatrick 43173471bf0Spatrick /** 43273471bf0Spatrick * A reference to an orc::ObjectTransformLayer instance. 43373471bf0Spatrick */ 43473471bf0Spatrick typedef struct LLVMOrcOpaqueObjectTransformLayer 43573471bf0Spatrick *LLVMOrcObjectTransformLayerRef; 43673471bf0Spatrick 43773471bf0Spatrick /** 43873471bf0Spatrick * A function for applying transformations to an object file buffer. 43973471bf0Spatrick * 44073471bf0Spatrick * Implementations of this type are responsible for managing the lifetime 44173471bf0Spatrick * of the memory buffer pointed to by ObjInOut: If the LLVMMemoryBufferRef 44273471bf0Spatrick * value is overwritten then the function is responsible for disposing of the 44373471bf0Spatrick * incoming buffer. If the buffer is simply accessed/mutated in-place then 44473471bf0Spatrick * ownership returns to the caller and the function does not need to do any 44573471bf0Spatrick * lifetime management. 44673471bf0Spatrick * 44773471bf0Spatrick * The transform is allowed to return an error, in which case the ObjInOut 44873471bf0Spatrick * buffer should be disposed of and set to null. 44973471bf0Spatrick */ 45073471bf0Spatrick typedef LLVMErrorRef (*LLVMOrcObjectTransformLayerTransformFunction)( 45173471bf0Spatrick void *Ctx, LLVMMemoryBufferRef *ObjInOut); 45273471bf0Spatrick 45373471bf0Spatrick /** 45473471bf0Spatrick * A reference to an orc::IndirectStubsManager instance. 45573471bf0Spatrick */ 45673471bf0Spatrick typedef struct LLVMOrcOpaqueIndirectStubsManager 45773471bf0Spatrick *LLVMOrcIndirectStubsManagerRef; 45873471bf0Spatrick 45973471bf0Spatrick /** 46073471bf0Spatrick * A reference to an orc::LazyCallThroughManager instance. 46173471bf0Spatrick */ 46273471bf0Spatrick typedef struct LLVMOrcOpaqueLazyCallThroughManager 46373471bf0Spatrick *LLVMOrcLazyCallThroughManagerRef; 46473471bf0Spatrick 46573471bf0Spatrick /** 46673471bf0Spatrick * A reference to an orc::DumpObjects object. 46773471bf0Spatrick * 46873471bf0Spatrick * Can be used to dump object files to disk with unique names. Useful as an 46973471bf0Spatrick * ObjectTransformLayer transform. 47073471bf0Spatrick */ 47173471bf0Spatrick typedef struct LLVMOrcOpaqueDumpObjects *LLVMOrcDumpObjectsRef; 47273471bf0Spatrick 47373471bf0Spatrick /** 47473471bf0Spatrick * Attach a custom error reporter function to the ExecutionSession. 47573471bf0Spatrick * 47673471bf0Spatrick * The error reporter will be called to deliver failure notices that can not be 47773471bf0Spatrick * directly reported to a caller. For example, failure to resolve symbols in 47873471bf0Spatrick * the JIT linker is typically reported via the error reporter (callers 47973471bf0Spatrick * requesting definitions from the JIT will typically be delivered a 48073471bf0Spatrick * FailureToMaterialize error instead). 48173471bf0Spatrick */ 48273471bf0Spatrick void LLVMOrcExecutionSessionSetErrorReporter( 48373471bf0Spatrick LLVMOrcExecutionSessionRef ES, LLVMOrcErrorReporterFunction ReportError, 48473471bf0Spatrick void *Ctx); 48573471bf0Spatrick 48673471bf0Spatrick /** 48773471bf0Spatrick * Return a reference to the SymbolStringPool for an ExecutionSession. 48873471bf0Spatrick * 48973471bf0Spatrick * Ownership of the pool remains with the ExecutionSession: The caller is 49073471bf0Spatrick * not required to free the pool. 49173471bf0Spatrick */ 49273471bf0Spatrick LLVMOrcSymbolStringPoolRef 49373471bf0Spatrick LLVMOrcExecutionSessionGetSymbolStringPool(LLVMOrcExecutionSessionRef ES); 49473471bf0Spatrick 49573471bf0Spatrick /** 49673471bf0Spatrick * Clear all unreferenced symbol string pool entries. 49773471bf0Spatrick * 49873471bf0Spatrick * This can be called at any time to release unused entries in the 49973471bf0Spatrick * ExecutionSession's string pool. Since it locks the pool (preventing 50073471bf0Spatrick * interning of any new strings) it is recommended that it only be called 50173471bf0Spatrick * infrequently, ideally when the caller has reason to believe that some 50273471bf0Spatrick * entries will have become unreferenced, e.g. after removing a module or 50373471bf0Spatrick * closing a JITDylib. 50473471bf0Spatrick */ 50573471bf0Spatrick void LLVMOrcSymbolStringPoolClearDeadEntries(LLVMOrcSymbolStringPoolRef SSP); 506097a140dSpatrick 507097a140dSpatrick /** 508097a140dSpatrick * Intern a string in the ExecutionSession's SymbolStringPool and return a 509097a140dSpatrick * reference to it. This increments the ref-count of the pool entry, and the 510097a140dSpatrick * returned value should be released once the client is done with it by 511097a140dSpatrick * calling LLVMOrReleaseSymbolStringPoolEntry. 512097a140dSpatrick * 513097a140dSpatrick * Since strings are uniqued within the SymbolStringPool 514097a140dSpatrick * LLVMOrcSymbolStringPoolEntryRefs can be compared by value to test string 515097a140dSpatrick * equality. 516097a140dSpatrick * 517097a140dSpatrick * Note that this function does not perform linker-mangling on the string. 518097a140dSpatrick */ 519097a140dSpatrick LLVMOrcSymbolStringPoolEntryRef 520097a140dSpatrick LLVMOrcExecutionSessionIntern(LLVMOrcExecutionSessionRef ES, const char *Name); 521097a140dSpatrick 522097a140dSpatrick /** 523*d415bd75Srobert * Callback type for ExecutionSession lookups. 524*d415bd75Srobert * 525*d415bd75Srobert * If Err is LLVMErrorSuccess then Result will contain a pointer to a 526*d415bd75Srobert * list of ( SymbolStringPtr, JITEvaluatedSymbol ) pairs of length NumPairs. 527*d415bd75Srobert * 528*d415bd75Srobert * If Err is a failure value then Result and Ctx are undefined and should 529*d415bd75Srobert * not be accessed. The Callback is responsible for handling the error 530*d415bd75Srobert * value (e.g. by calling LLVMGetErrorMessage + LLVMDisposeErrorMessage). 531*d415bd75Srobert * 532*d415bd75Srobert * The caller retains ownership of the Result array and will release all 533*d415bd75Srobert * contained symbol names. Clients are responsible for retaining any symbol 534*d415bd75Srobert * names that they wish to hold after the function returns. 535*d415bd75Srobert */ 536*d415bd75Srobert typedef void (*LLVMOrcExecutionSessionLookupHandleResultFunction)( 537*d415bd75Srobert LLVMErrorRef Err, LLVMOrcCSymbolMapPairs Result, size_t NumPairs, 538*d415bd75Srobert void *Ctx); 539*d415bd75Srobert 540*d415bd75Srobert /** 541*d415bd75Srobert * Look up symbols in an execution session. 542*d415bd75Srobert * 543*d415bd75Srobert * This is a wrapper around the general ExecutionSession::lookup function. 544*d415bd75Srobert * 545*d415bd75Srobert * The SearchOrder argument contains a list of (JITDylibs, JITDylibSearchFlags) 546*d415bd75Srobert * pairs that describe the search order. The JITDylibs will be searched in the 547*d415bd75Srobert * given order to try to find the symbols in the Symbols argument. 548*d415bd75Srobert * 549*d415bd75Srobert * The Symbols argument should contain a null-terminated array of 550*d415bd75Srobert * (SymbolStringPtr, SymbolLookupFlags) pairs describing the symbols to be 551*d415bd75Srobert * searched for. This function takes ownership of the elements of the Symbols 552*d415bd75Srobert * array. The Name fields of the Symbols elements are taken to have been 553*d415bd75Srobert * retained by the client for this function. The client should *not* release the 554*d415bd75Srobert * Name fields, but are still responsible for destroying the array itself. 555*d415bd75Srobert * 556*d415bd75Srobert * The HandleResult function will be called once all searched for symbols have 557*d415bd75Srobert * been found, or an error occurs. The HandleResult function will be passed an 558*d415bd75Srobert * LLVMErrorRef indicating success or failure, and (on success) a 559*d415bd75Srobert * null-terminated LLVMOrcCSymbolMapPairs array containing the function result, 560*d415bd75Srobert * and the Ctx value passed to the lookup function. 561*d415bd75Srobert * 562*d415bd75Srobert * The client is fully responsible for managing the lifetime of the Ctx object. 563*d415bd75Srobert * A common idiom is to allocate the context prior to the lookup and deallocate 564*d415bd75Srobert * it in the handler. 565*d415bd75Srobert * 566*d415bd75Srobert * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE! 567*d415bd75Srobert */ 568*d415bd75Srobert void LLVMOrcExecutionSessionLookup( 569*d415bd75Srobert LLVMOrcExecutionSessionRef ES, LLVMOrcLookupKind K, 570*d415bd75Srobert LLVMOrcCJITDylibSearchOrder SearchOrder, size_t SearchOrderSize, 571*d415bd75Srobert LLVMOrcCLookupSet Symbols, size_t SymbolsSize, 572*d415bd75Srobert LLVMOrcExecutionSessionLookupHandleResultFunction HandleResult, void *Ctx); 573*d415bd75Srobert 574*d415bd75Srobert /** 57573471bf0Spatrick * Increments the ref-count for a SymbolStringPool entry. 57673471bf0Spatrick */ 57773471bf0Spatrick void LLVMOrcRetainSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S); 57873471bf0Spatrick 57973471bf0Spatrick /** 580097a140dSpatrick * Reduces the ref-count for of a SymbolStringPool entry. 581097a140dSpatrick */ 582097a140dSpatrick void LLVMOrcReleaseSymbolStringPoolEntry(LLVMOrcSymbolStringPoolEntryRef S); 583097a140dSpatrick 584*d415bd75Srobert /** 585*d415bd75Srobert * Return the c-string for the given symbol. This string will remain valid until 586*d415bd75Srobert * the entry is freed (once all LLVMOrcSymbolStringPoolEntryRefs have been 587*d415bd75Srobert * released). 588*d415bd75Srobert */ 58973471bf0Spatrick const char *LLVMOrcSymbolStringPoolEntryStr(LLVMOrcSymbolStringPoolEntryRef S); 59073471bf0Spatrick 59173471bf0Spatrick /** 59273471bf0Spatrick * Reduces the ref-count of a ResourceTracker. 59373471bf0Spatrick */ 59473471bf0Spatrick void LLVMOrcReleaseResourceTracker(LLVMOrcResourceTrackerRef RT); 59573471bf0Spatrick 59673471bf0Spatrick /** 59773471bf0Spatrick * Transfers tracking of all resources associated with resource tracker SrcRT 59873471bf0Spatrick * to resource tracker DstRT. 59973471bf0Spatrick */ 60073471bf0Spatrick void LLVMOrcResourceTrackerTransferTo(LLVMOrcResourceTrackerRef SrcRT, 60173471bf0Spatrick LLVMOrcResourceTrackerRef DstRT); 60273471bf0Spatrick 60373471bf0Spatrick /** 60473471bf0Spatrick * Remove all resources associated with the given tracker. See 60573471bf0Spatrick * ResourceTracker::remove(). 60673471bf0Spatrick */ 60773471bf0Spatrick LLVMErrorRef LLVMOrcResourceTrackerRemove(LLVMOrcResourceTrackerRef RT); 60873471bf0Spatrick 609097a140dSpatrick /** 610097a140dSpatrick * Dispose of a JITDylib::DefinitionGenerator. This should only be called if 611097a140dSpatrick * ownership has not been passed to a JITDylib (e.g. because some error 612097a140dSpatrick * prevented the client from calling LLVMOrcJITDylibAddGenerator). 613097a140dSpatrick */ 61473471bf0Spatrick void LLVMOrcDisposeDefinitionGenerator(LLVMOrcDefinitionGeneratorRef DG); 615097a140dSpatrick 616097a140dSpatrick /** 61773471bf0Spatrick * Dispose of a MaterializationUnit. 61873471bf0Spatrick */ 61973471bf0Spatrick void LLVMOrcDisposeMaterializationUnit(LLVMOrcMaterializationUnitRef MU); 62073471bf0Spatrick 62173471bf0Spatrick /** 62273471bf0Spatrick * Create a custom MaterializationUnit. 62373471bf0Spatrick * 62473471bf0Spatrick * Name is a name for this MaterializationUnit to be used for identification 62573471bf0Spatrick * and logging purposes (e.g. if this MaterializationUnit produces an 62673471bf0Spatrick * object buffer then the name of that buffer will be derived from this name). 62773471bf0Spatrick * 62873471bf0Spatrick * The Syms list contains the names and linkages of the symbols provided by this 62973471bf0Spatrick * unit. This function takes ownership of the elements of the Syms array. The 63073471bf0Spatrick * Name fields of the array elements are taken to have been retained for this 63173471bf0Spatrick * function. The client should *not* release the elements of the array, but is 63273471bf0Spatrick * still responsible for destroying the array itself. 63373471bf0Spatrick * 63473471bf0Spatrick * The InitSym argument indicates whether or not this MaterializationUnit 63573471bf0Spatrick * contains static initializers. If three are no static initializers (the common 63673471bf0Spatrick * case) then this argument should be null. If there are static initializers 63773471bf0Spatrick * then InitSym should be set to a unique name that also appears in the Syms 63873471bf0Spatrick * list with the LLVMJITSymbolGenericFlagsMaterializationSideEffectsOnly flag 63973471bf0Spatrick * set. This function takes ownership of the InitSym, which should have been 64073471bf0Spatrick * retained twice on behalf of this function: once for the Syms entry and once 64173471bf0Spatrick * for InitSym. If clients wish to use the InitSym value after this function 64273471bf0Spatrick * returns they must retain it once more for themselves. 64373471bf0Spatrick * 64473471bf0Spatrick * If any of the symbols in the Syms list is looked up then the Materialize 64573471bf0Spatrick * function will be called. 64673471bf0Spatrick * 64773471bf0Spatrick * If any of the symbols in the Syms list is overridden then the Discard 64873471bf0Spatrick * function will be called. 64973471bf0Spatrick * 65073471bf0Spatrick * The caller owns the underling MaterializationUnit and is responsible for 65173471bf0Spatrick * either passing it to a JITDylib (via LLVMOrcJITDylibDefine) or disposing 65273471bf0Spatrick * of it by calling LLVMOrcDisposeMaterializationUnit. 65373471bf0Spatrick */ 65473471bf0Spatrick LLVMOrcMaterializationUnitRef LLVMOrcCreateCustomMaterializationUnit( 65573471bf0Spatrick const char *Name, void *Ctx, LLVMOrcCSymbolFlagsMapPairs Syms, 65673471bf0Spatrick size_t NumSyms, LLVMOrcSymbolStringPoolEntryRef InitSym, 65773471bf0Spatrick LLVMOrcMaterializationUnitMaterializeFunction Materialize, 65873471bf0Spatrick LLVMOrcMaterializationUnitDiscardFunction Discard, 65973471bf0Spatrick LLVMOrcMaterializationUnitDestroyFunction Destroy); 66073471bf0Spatrick 66173471bf0Spatrick /** 66273471bf0Spatrick * Create a MaterializationUnit to define the given symbols as pointing to 66373471bf0Spatrick * the corresponding raw addresses. 66473471bf0Spatrick * 66573471bf0Spatrick * This function takes ownership of the elements of the Syms array. The Name 66673471bf0Spatrick * fields of the array elements are taken to have been retained for this 66773471bf0Spatrick * function. This allows the following pattern... 66873471bf0Spatrick * 66973471bf0Spatrick * size_t NumPairs; 67073471bf0Spatrick * LLVMOrcCSymbolMapPairs Sym; 67173471bf0Spatrick * -- Build Syms array -- 67273471bf0Spatrick * LLVMOrcMaterializationUnitRef MU = 67373471bf0Spatrick * LLVMOrcAbsoluteSymbols(Syms, NumPairs); 67473471bf0Spatrick * 67573471bf0Spatrick * ... without requiring cleanup of the elements of the Sym array afterwards. 67673471bf0Spatrick * 67773471bf0Spatrick * The client is still responsible for deleting the Sym array itself. 67873471bf0Spatrick * 67973471bf0Spatrick * If a client wishes to reuse elements of the Sym array after this call they 68073471bf0Spatrick * must explicitly retain each of the elements for themselves. 68173471bf0Spatrick */ 68273471bf0Spatrick LLVMOrcMaterializationUnitRef 68373471bf0Spatrick LLVMOrcAbsoluteSymbols(LLVMOrcCSymbolMapPairs Syms, size_t NumPairs); 68473471bf0Spatrick 68573471bf0Spatrick /** 68673471bf0Spatrick * Create a MaterializationUnit to define lazy re-expots. These are callable 68773471bf0Spatrick * entry points that call through to the given symbols. 68873471bf0Spatrick * 68973471bf0Spatrick * This function takes ownership of the CallableAliases array. The Name 69073471bf0Spatrick * fields of the array elements are taken to have been retained for this 69173471bf0Spatrick * function. This allows the following pattern... 69273471bf0Spatrick * 69373471bf0Spatrick * size_t NumPairs; 69473471bf0Spatrick * LLVMOrcCSymbolAliasMapPairs CallableAliases; 69573471bf0Spatrick * -- Build CallableAliases array -- 69673471bf0Spatrick * LLVMOrcMaterializationUnitRef MU = 69773471bf0Spatrick * LLVMOrcLazyReexports(LCTM, ISM, JD, CallableAliases, NumPairs); 69873471bf0Spatrick * 69973471bf0Spatrick * ... without requiring cleanup of the elements of the CallableAliases array afterwards. 70073471bf0Spatrick * 70173471bf0Spatrick * The client is still responsible for deleting the CallableAliases array itself. 70273471bf0Spatrick * 70373471bf0Spatrick * If a client wishes to reuse elements of the CallableAliases array after this call they 70473471bf0Spatrick * must explicitly retain each of the elements for themselves. 70573471bf0Spatrick */ 70673471bf0Spatrick LLVMOrcMaterializationUnitRef LLVMOrcLazyReexports( 70773471bf0Spatrick LLVMOrcLazyCallThroughManagerRef LCTM, LLVMOrcIndirectStubsManagerRef ISM, 70873471bf0Spatrick LLVMOrcJITDylibRef SourceRef, LLVMOrcCSymbolAliasMapPairs CallableAliases, 70973471bf0Spatrick size_t NumPairs); 71073471bf0Spatrick // TODO: ImplSymbolMad SrcJDLoc 71173471bf0Spatrick 71273471bf0Spatrick /** 71373471bf0Spatrick * Disposes of the passed MaterializationResponsibility object. 71473471bf0Spatrick * 71573471bf0Spatrick * This should only be done after the symbols covered by the object have either 71673471bf0Spatrick * been resolved and emitted (via 71773471bf0Spatrick * LLVMOrcMaterializationResponsibilityNotifyResolved and 71873471bf0Spatrick * LLVMOrcMaterializationResponsibilityNotifyEmitted) or failed (via 71973471bf0Spatrick * LLVMOrcMaterializationResponsibilityFailMaterialization). 72073471bf0Spatrick */ 72173471bf0Spatrick void LLVMOrcDisposeMaterializationResponsibility( 72273471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR); 72373471bf0Spatrick 72473471bf0Spatrick /** 72573471bf0Spatrick * Returns the target JITDylib that these symbols are being materialized into. 72673471bf0Spatrick */ 72773471bf0Spatrick LLVMOrcJITDylibRef LLVMOrcMaterializationResponsibilityGetTargetDylib( 72873471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR); 72973471bf0Spatrick 73073471bf0Spatrick /** 73173471bf0Spatrick * Returns the ExecutionSession for this MaterializationResponsibility. 73273471bf0Spatrick */ 73373471bf0Spatrick LLVMOrcExecutionSessionRef 73473471bf0Spatrick LLVMOrcMaterializationResponsibilityGetExecutionSession( 73573471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR); 73673471bf0Spatrick 73773471bf0Spatrick /** 73873471bf0Spatrick * Returns the symbol flags map for this responsibility instance. 73973471bf0Spatrick * 74073471bf0Spatrick * The length of the array is returned in NumPairs and the caller is responsible 74173471bf0Spatrick * for the returned memory and needs to call LLVMOrcDisposeCSymbolFlagsMap. 74273471bf0Spatrick * 74373471bf0Spatrick * To use the returned symbols beyond the livetime of the 74473471bf0Spatrick * MaterializationResponsibility requires the caller to retain the symbols 74573471bf0Spatrick * explicitly. 74673471bf0Spatrick */ 74773471bf0Spatrick LLVMOrcCSymbolFlagsMapPairs LLVMOrcMaterializationResponsibilityGetSymbols( 74873471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR, size_t *NumPairs); 74973471bf0Spatrick 75073471bf0Spatrick /** 75173471bf0Spatrick * Disposes of the passed LLVMOrcCSymbolFlagsMap. 75273471bf0Spatrick * 75373471bf0Spatrick * Does not release the entries themselves. 75473471bf0Spatrick */ 75573471bf0Spatrick void LLVMOrcDisposeCSymbolFlagsMap(LLVMOrcCSymbolFlagsMapPairs Pairs); 75673471bf0Spatrick 75773471bf0Spatrick /** 75873471bf0Spatrick * Returns the initialization pseudo-symbol, if any. This symbol will also 75973471bf0Spatrick * be present in the SymbolFlagsMap for this MaterializationResponsibility 76073471bf0Spatrick * object. 76173471bf0Spatrick * 76273471bf0Spatrick * The returned symbol is not retained over any mutating operation of the 76373471bf0Spatrick * MaterializationResponsbility or beyond the lifetime thereof. 76473471bf0Spatrick */ 76573471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef 76673471bf0Spatrick LLVMOrcMaterializationResponsibilityGetInitializerSymbol( 76773471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR); 76873471bf0Spatrick 76973471bf0Spatrick /** 77073471bf0Spatrick * Returns the names of any symbols covered by this 77173471bf0Spatrick * MaterializationResponsibility object that have queries pending. This 77273471bf0Spatrick * information can be used to return responsibility for unrequested symbols 77373471bf0Spatrick * back to the JITDylib via the delegate method. 77473471bf0Spatrick */ 77573471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef * 77673471bf0Spatrick LLVMOrcMaterializationResponsibilityGetRequestedSymbols( 77773471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR, size_t *NumSymbols); 77873471bf0Spatrick 77973471bf0Spatrick /** 78073471bf0Spatrick * Disposes of the passed LLVMOrcSymbolStringPoolEntryRef* . 78173471bf0Spatrick * 78273471bf0Spatrick * Does not release the symbols themselves. 78373471bf0Spatrick */ 78473471bf0Spatrick void LLVMOrcDisposeSymbols(LLVMOrcSymbolStringPoolEntryRef *Symbols); 78573471bf0Spatrick 786*d415bd75Srobert /** 78773471bf0Spatrick * Notifies the target JITDylib that the given symbols have been resolved. 78873471bf0Spatrick * This will update the given symbols' addresses in the JITDylib, and notify 78973471bf0Spatrick * any pending queries on the given symbols of their resolution. The given 79073471bf0Spatrick * symbols must be ones covered by this MaterializationResponsibility 79173471bf0Spatrick * instance. Individual calls to this method may resolve a subset of the 79273471bf0Spatrick * symbols, but all symbols must have been resolved prior to calling emit. 79373471bf0Spatrick * 79473471bf0Spatrick * This method will return an error if any symbols being resolved have been 79573471bf0Spatrick * moved to the error state due to the failure of a dependency. If this 79673471bf0Spatrick * method returns an error then clients should log it and call 79773471bf0Spatrick * LLVMOrcMaterializationResponsibilityFailMaterialization. If no dependencies 79873471bf0Spatrick * have been registered for the symbols covered by this 79973471bf0Spatrick * MaterializationResponsibiility then this method is guaranteed to return 80073471bf0Spatrick * LLVMErrorSuccess. 80173471bf0Spatrick */ 80273471bf0Spatrick LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyResolved( 80373471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR, LLVMOrcCSymbolMapPairs Symbols, 80473471bf0Spatrick size_t NumPairs); 80573471bf0Spatrick 80673471bf0Spatrick /** 80773471bf0Spatrick * Notifies the target JITDylib (and any pending queries on that JITDylib) 80873471bf0Spatrick * that all symbols covered by this MaterializationResponsibility instance 80973471bf0Spatrick * have been emitted. 81073471bf0Spatrick * 81173471bf0Spatrick * This method will return an error if any symbols being resolved have been 81273471bf0Spatrick * moved to the error state due to the failure of a dependency. If this 81373471bf0Spatrick * method returns an error then clients should log it and call 81473471bf0Spatrick * LLVMOrcMaterializationResponsibilityFailMaterialization. 81573471bf0Spatrick * If no dependencies have been registered for the symbols covered by this 81673471bf0Spatrick * MaterializationResponsibiility then this method is guaranteed to return 81773471bf0Spatrick * LLVMErrorSuccess. 81873471bf0Spatrick */ 81973471bf0Spatrick LLVMErrorRef LLVMOrcMaterializationResponsibilityNotifyEmitted( 82073471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR); 82173471bf0Spatrick 82273471bf0Spatrick /** 82373471bf0Spatrick * Attempt to claim responsibility for new definitions. This method can be 82473471bf0Spatrick * used to claim responsibility for symbols that are added to a 82573471bf0Spatrick * materialization unit during the compilation process (e.g. literal pool 82673471bf0Spatrick * symbols). Symbol linkage rules are the same as for symbols that are 82773471bf0Spatrick * defined up front: duplicate strong definitions will result in errors. 82873471bf0Spatrick * Duplicate weak definitions will be discarded (in which case they will 82973471bf0Spatrick * not be added to this responsibility instance). 83073471bf0Spatrick * 83173471bf0Spatrick * This method can be used by materialization units that want to add 83273471bf0Spatrick * additional symbols at materialization time (e.g. stubs, compile 83373471bf0Spatrick * callbacks, metadata) 83473471bf0Spatrick */ 83573471bf0Spatrick LLVMErrorRef LLVMOrcMaterializationResponsibilityDefineMaterializing( 83673471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR, 83773471bf0Spatrick LLVMOrcCSymbolFlagsMapPairs Pairs, size_t NumPairs); 83873471bf0Spatrick 83973471bf0Spatrick /** 84073471bf0Spatrick * Notify all not-yet-emitted covered by this MaterializationResponsibility 84173471bf0Spatrick * instance that an error has occurred. 84273471bf0Spatrick * This will remove all symbols covered by this MaterializationResponsibilty 84373471bf0Spatrick * from the target JITDylib, and send an error to any queries waiting on 84473471bf0Spatrick * these symbols. 84573471bf0Spatrick */ 84673471bf0Spatrick void LLVMOrcMaterializationResponsibilityFailMaterialization( 84773471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR); 84873471bf0Spatrick 84973471bf0Spatrick /** 85073471bf0Spatrick * Transfers responsibility to the given MaterializationUnit for all 85173471bf0Spatrick * symbols defined by that MaterializationUnit. This allows 85273471bf0Spatrick * materializers to break up work based on run-time information (e.g. 85373471bf0Spatrick * by introspecting which symbols have actually been looked up and 85473471bf0Spatrick * materializing only those). 85573471bf0Spatrick */ 85673471bf0Spatrick LLVMErrorRef LLVMOrcMaterializationResponsibilityReplace( 85773471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR, 85873471bf0Spatrick LLVMOrcMaterializationUnitRef MU); 85973471bf0Spatrick 86073471bf0Spatrick /** 86173471bf0Spatrick * Delegates responsibility for the given symbols to the returned 86273471bf0Spatrick * materialization responsibility. Useful for breaking up work between 86373471bf0Spatrick * threads, or different kinds of materialization processes. 86473471bf0Spatrick * 86573471bf0Spatrick * The caller retains responsibility of the the passed 86673471bf0Spatrick * MaterializationResponsibility. 86773471bf0Spatrick */ 86873471bf0Spatrick LLVMErrorRef LLVMOrcMaterializationResponsibilityDelegate( 86973471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR, 87073471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef *Symbols, size_t NumSymbols, 87173471bf0Spatrick LLVMOrcMaterializationResponsibilityRef *Result); 87273471bf0Spatrick 87373471bf0Spatrick /** 87473471bf0Spatrick * Adds dependencies to a symbol that the MaterializationResponsibility is 87573471bf0Spatrick * responsible for. 87673471bf0Spatrick * 87773471bf0Spatrick * This function takes ownership of Dependencies struct. The Names 87873471bf0Spatrick * array have been retained for this function. This allows the following 87973471bf0Spatrick * pattern... 88073471bf0Spatrick * 88173471bf0Spatrick * LLVMOrcSymbolStringPoolEntryRef Names[] = {...}; 88273471bf0Spatrick * LLVMOrcCDependenceMapPair Dependence = {JD, {Names, sizeof(Names)}} 88373471bf0Spatrick * LLVMOrcMaterializationResponsibilityAddDependencies(JD, Name, &Dependence, 88473471bf0Spatrick * 1); 88573471bf0Spatrick * 88673471bf0Spatrick * ... without requiring cleanup of the elements of the Names array afterwards. 88773471bf0Spatrick * 88873471bf0Spatrick * The client is still responsible for deleting the Dependencies.Names array 88973471bf0Spatrick * itself. 89073471bf0Spatrick */ 89173471bf0Spatrick void LLVMOrcMaterializationResponsibilityAddDependencies( 89273471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR, 89373471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef Name, 89473471bf0Spatrick LLVMOrcCDependenceMapPairs Dependencies, size_t NumPairs); 89573471bf0Spatrick 89673471bf0Spatrick /** 89773471bf0Spatrick * Adds dependencies to all symbols that the MaterializationResponsibility is 89873471bf0Spatrick * responsible for. See LLVMOrcMaterializationResponsibilityAddDependencies for 89973471bf0Spatrick * notes about memory responsibility. 90073471bf0Spatrick */ 90173471bf0Spatrick void LLVMOrcMaterializationResponsibilityAddDependenciesForAll( 90273471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR, 90373471bf0Spatrick LLVMOrcCDependenceMapPairs Dependencies, size_t NumPairs); 90473471bf0Spatrick 90573471bf0Spatrick /** 90673471bf0Spatrick * Create a "bare" JITDylib. 90773471bf0Spatrick * 90873471bf0Spatrick * The client is responsible for ensuring that the JITDylib's name is unique, 90973471bf0Spatrick * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first. 91073471bf0Spatrick * 91173471bf0Spatrick * This call does not install any library code or symbols into the newly 91273471bf0Spatrick * created JITDylib. The client is responsible for all configuration. 91373471bf0Spatrick */ 91473471bf0Spatrick LLVMOrcJITDylibRef 91573471bf0Spatrick LLVMOrcExecutionSessionCreateBareJITDylib(LLVMOrcExecutionSessionRef ES, 91673471bf0Spatrick const char *Name); 91773471bf0Spatrick 91873471bf0Spatrick /** 91973471bf0Spatrick * Create a JITDylib. 92073471bf0Spatrick * 92173471bf0Spatrick * The client is responsible for ensuring that the JITDylib's name is unique, 92273471bf0Spatrick * e.g. by calling LLVMOrcExecutionSessionGetJTIDylibByName first. 92373471bf0Spatrick * 92473471bf0Spatrick * If a Platform is attached to the ExecutionSession then 92573471bf0Spatrick * Platform::setupJITDylib will be called to install standard platform symbols 92673471bf0Spatrick * (e.g. standard library interposes). If no Platform is installed then this 92773471bf0Spatrick * call is equivalent to LLVMExecutionSessionRefCreateBareJITDylib and will 92873471bf0Spatrick * always return success. 92973471bf0Spatrick */ 93073471bf0Spatrick LLVMErrorRef 93173471bf0Spatrick LLVMOrcExecutionSessionCreateJITDylib(LLVMOrcExecutionSessionRef ES, 93273471bf0Spatrick LLVMOrcJITDylibRef *Result, 93373471bf0Spatrick const char *Name); 93473471bf0Spatrick 93573471bf0Spatrick /** 93673471bf0Spatrick * Returns the JITDylib with the given name, or NULL if no such JITDylib 93773471bf0Spatrick * exists. 93873471bf0Spatrick */ 93973471bf0Spatrick LLVMOrcJITDylibRef 94073471bf0Spatrick LLVMOrcExecutionSessionGetJITDylibByName(LLVMOrcExecutionSessionRef ES, 94173471bf0Spatrick const char *Name); 94273471bf0Spatrick 94373471bf0Spatrick /** 94473471bf0Spatrick * Return a reference to a newly created resource tracker associated with JD. 94573471bf0Spatrick * The tracker is returned with an initial ref-count of 1, and must be released 94673471bf0Spatrick * with LLVMOrcReleaseResourceTracker when no longer needed. 94773471bf0Spatrick */ 94873471bf0Spatrick LLVMOrcResourceTrackerRef 94973471bf0Spatrick LLVMOrcJITDylibCreateResourceTracker(LLVMOrcJITDylibRef JD); 95073471bf0Spatrick 95173471bf0Spatrick /** 95273471bf0Spatrick * Return a reference to the default resource tracker for the given JITDylib. 95373471bf0Spatrick * This operation will increase the retain count of the tracker: Clients should 95473471bf0Spatrick * call LLVMOrcReleaseResourceTracker when the result is no longer needed. 95573471bf0Spatrick */ 95673471bf0Spatrick LLVMOrcResourceTrackerRef 95773471bf0Spatrick LLVMOrcJITDylibGetDefaultResourceTracker(LLVMOrcJITDylibRef JD); 95873471bf0Spatrick 95973471bf0Spatrick /** 96073471bf0Spatrick * Add the given MaterializationUnit to the given JITDylib. 96173471bf0Spatrick * 96273471bf0Spatrick * If this operation succeeds then JITDylib JD will take ownership of MU. 96373471bf0Spatrick * If the operation fails then ownership remains with the caller who should 96473471bf0Spatrick * call LLVMOrcDisposeMaterializationUnit to destroy it. 96573471bf0Spatrick */ 96673471bf0Spatrick LLVMErrorRef LLVMOrcJITDylibDefine(LLVMOrcJITDylibRef JD, 96773471bf0Spatrick LLVMOrcMaterializationUnitRef MU); 96873471bf0Spatrick 96973471bf0Spatrick /** 97073471bf0Spatrick * Calls remove on all trackers associated with this JITDylib, see 97173471bf0Spatrick * JITDylib::clear(). 97273471bf0Spatrick */ 97373471bf0Spatrick LLVMErrorRef LLVMOrcJITDylibClear(LLVMOrcJITDylibRef JD); 97473471bf0Spatrick 97573471bf0Spatrick /** 97673471bf0Spatrick * Add a DefinitionGenerator to the given JITDylib. 977097a140dSpatrick * 978097a140dSpatrick * The JITDylib will take ownership of the given generator: The client is no 979097a140dSpatrick * longer responsible for managing its memory. 980097a140dSpatrick */ 981097a140dSpatrick void LLVMOrcJITDylibAddGenerator(LLVMOrcJITDylibRef JD, 98273471bf0Spatrick LLVMOrcDefinitionGeneratorRef DG); 98373471bf0Spatrick 98473471bf0Spatrick /** 98573471bf0Spatrick * Create a custom generator. 986*d415bd75Srobert * 987*d415bd75Srobert * The F argument will be used to implement the DefinitionGenerator's 988*d415bd75Srobert * tryToGenerate method (see 989*d415bd75Srobert * LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction). 990*d415bd75Srobert * 991*d415bd75Srobert * Ctx is a context object that will be passed to F. This argument is 992*d415bd75Srobert * permitted to be null. 993*d415bd75Srobert * 994*d415bd75Srobert * Dispose is the disposal function for Ctx. This argument is permitted to be 995*d415bd75Srobert * null (in which case the client is responsible for the lifetime of Ctx). 99673471bf0Spatrick */ 99773471bf0Spatrick LLVMOrcDefinitionGeneratorRef LLVMOrcCreateCustomCAPIDefinitionGenerator( 998*d415bd75Srobert LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction F, void *Ctx, 999*d415bd75Srobert LLVMOrcDisposeCAPIDefinitionGeneratorFunction Dispose); 1000*d415bd75Srobert 1001*d415bd75Srobert /** 1002*d415bd75Srobert * Continue a lookup that was suspended in a generator (see 1003*d415bd75Srobert * LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction). 1004*d415bd75Srobert */ 1005*d415bd75Srobert void LLVMOrcLookupStateContinueLookup(LLVMOrcLookupStateRef S, 1006*d415bd75Srobert LLVMErrorRef Err); 1007097a140dSpatrick 1008097a140dSpatrick /** 1009097a140dSpatrick * Get a DynamicLibrarySearchGenerator that will reflect process symbols into 1010097a140dSpatrick * the JITDylib. On success the resulting generator is owned by the client. 1011097a140dSpatrick * Ownership is typically transferred by adding the instance to a JITDylib 1012097a140dSpatrick * using LLVMOrcJITDylibAddGenerator, 1013097a140dSpatrick * 1014097a140dSpatrick * The GlobalPrefix argument specifies the character that appears on the front 1015097a140dSpatrick * of linker-mangled symbols for the target platform (e.g. '_' on MachO). 1016097a140dSpatrick * If non-null, this character will be stripped from the start of all symbol 1017097a140dSpatrick * strings before passing the remaining substring to dlsym. 1018097a140dSpatrick * 1019097a140dSpatrick * The optional Filter and Ctx arguments can be used to supply a symbol name 1020097a140dSpatrick * filter: Only symbols for which the filter returns true will be visible to 1021097a140dSpatrick * JIT'd code. If the Filter argument is null then all process symbols will 1022097a140dSpatrick * be visible to JIT'd code. Note that the symbol name passed to the Filter 1023097a140dSpatrick * function is the full mangled symbol: The client is responsible for stripping 1024097a140dSpatrick * the global prefix if present. 1025097a140dSpatrick */ 1026097a140dSpatrick LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess( 102773471bf0Spatrick LLVMOrcDefinitionGeneratorRef *Result, char GlobalPrefx, 1028097a140dSpatrick LLVMOrcSymbolPredicate Filter, void *FilterCtx); 1029097a140dSpatrick 1030097a140dSpatrick /** 1031*d415bd75Srobert * Get a LLVMOrcCreateDynamicLibararySearchGeneratorForPath that will reflect 1032*d415bd75Srobert * library symbols into the JITDylib. On success the resulting generator is 1033*d415bd75Srobert * owned by the client. Ownership is typically transferred by adding the 1034*d415bd75Srobert * instance to a JITDylib using LLVMOrcJITDylibAddGenerator, 1035*d415bd75Srobert * 1036*d415bd75Srobert * The GlobalPrefix argument specifies the character that appears on the front 1037*d415bd75Srobert * of linker-mangled symbols for the target platform (e.g. '_' on MachO). 1038*d415bd75Srobert * If non-null, this character will be stripped from the start of all symbol 1039*d415bd75Srobert * strings before passing the remaining substring to dlsym. 1040*d415bd75Srobert * 1041*d415bd75Srobert * The optional Filter and Ctx arguments can be used to supply a symbol name 1042*d415bd75Srobert * filter: Only symbols for which the filter returns true will be visible to 1043*d415bd75Srobert * JIT'd code. If the Filter argument is null then all library symbols will 1044*d415bd75Srobert * be visible to JIT'd code. Note that the symbol name passed to the Filter 1045*d415bd75Srobert * function is the full mangled symbol: The client is responsible for stripping 1046*d415bd75Srobert * the global prefix if present. 1047*d415bd75Srobert * 1048*d415bd75Srobert * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE! 1049*d415bd75Srobert * 1050*d415bd75Srobert */ 1051*d415bd75Srobert LLVMErrorRef LLVMOrcCreateDynamicLibrarySearchGeneratorForPath( 1052*d415bd75Srobert LLVMOrcDefinitionGeneratorRef *Result, const char *FileName, 1053*d415bd75Srobert char GlobalPrefix, LLVMOrcSymbolPredicate Filter, void *FilterCtx); 1054*d415bd75Srobert 1055*d415bd75Srobert /** 1056*d415bd75Srobert * Get a LLVMOrcCreateStaticLibrarySearchGeneratorForPath that will reflect 1057*d415bd75Srobert * static library symbols into the JITDylib. On success the resulting 1058*d415bd75Srobert * generator is owned by the client. Ownership is typically transferred by 1059*d415bd75Srobert * adding the instance to a JITDylib using LLVMOrcJITDylibAddGenerator, 1060*d415bd75Srobert * 1061*d415bd75Srobert * Call with the optional TargetTriple argument will succeed if the file at 1062*d415bd75Srobert * the given path is a static library or a MachO universal binary containing a 1063*d415bd75Srobert * static library that is compatible with the given triple. Otherwise it will 1064*d415bd75Srobert * return an error. 1065*d415bd75Srobert * 1066*d415bd75Srobert * THIS API IS EXPERIMENTAL AND LIKELY TO CHANGE IN THE NEAR FUTURE! 1067*d415bd75Srobert * 1068*d415bd75Srobert */ 1069*d415bd75Srobert LLVMErrorRef LLVMOrcCreateStaticLibrarySearchGeneratorForPath( 1070*d415bd75Srobert LLVMOrcDefinitionGeneratorRef *Result, LLVMOrcObjectLayerRef ObjLayer, 1071*d415bd75Srobert const char *FileName, const char *TargetTriple); 1072*d415bd75Srobert 1073*d415bd75Srobert /** 1074097a140dSpatrick * Create a ThreadSafeContext containing a new LLVMContext. 1075097a140dSpatrick * 1076097a140dSpatrick * Ownership of the underlying ThreadSafeContext data is shared: Clients 1077097a140dSpatrick * can and should dispose of their ThreadSafeContext as soon as they no longer 107873471bf0Spatrick * need to refer to it directly. Other references (e.g. from ThreadSafeModules) 1079097a140dSpatrick * will keep the data alive as long as it is needed. 1080097a140dSpatrick */ 1081097a140dSpatrick LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void); 1082097a140dSpatrick 1083097a140dSpatrick /** 1084097a140dSpatrick * Get a reference to the wrapped LLVMContext. 1085097a140dSpatrick */ 1086097a140dSpatrick LLVMContextRef 1087097a140dSpatrick LLVMOrcThreadSafeContextGetContext(LLVMOrcThreadSafeContextRef TSCtx); 1088097a140dSpatrick 1089097a140dSpatrick /** 1090097a140dSpatrick * Dispose of a ThreadSafeContext. 1091097a140dSpatrick */ 1092097a140dSpatrick void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx); 1093097a140dSpatrick 1094097a140dSpatrick /** 1095097a140dSpatrick * Create a ThreadSafeModule wrapper around the given LLVM module. This takes 1096097a140dSpatrick * ownership of the M argument which should not be disposed of or referenced 1097097a140dSpatrick * after this function returns. 1098097a140dSpatrick * 1099097a140dSpatrick * Ownership of the ThreadSafeModule is unique: If it is transferred to the JIT 110073471bf0Spatrick * (e.g. by LLVMOrcLLJITAddLLVMIRModule) then the client is no longer 1101097a140dSpatrick * responsible for it. If it is not transferred to the JIT then the client 1102097a140dSpatrick * should call LLVMOrcDisposeThreadSafeModule to dispose of it. 1103097a140dSpatrick */ 1104097a140dSpatrick LLVMOrcThreadSafeModuleRef 1105097a140dSpatrick LLVMOrcCreateNewThreadSafeModule(LLVMModuleRef M, 1106097a140dSpatrick LLVMOrcThreadSafeContextRef TSCtx); 1107097a140dSpatrick 1108097a140dSpatrick /** 1109097a140dSpatrick * Dispose of a ThreadSafeModule. This should only be called if ownership has 1110097a140dSpatrick * not been passed to LLJIT (e.g. because some error prevented the client from 1111097a140dSpatrick * adding this to the JIT). 1112097a140dSpatrick */ 1113097a140dSpatrick void LLVMOrcDisposeThreadSafeModule(LLVMOrcThreadSafeModuleRef TSM); 1114097a140dSpatrick 1115097a140dSpatrick /** 111673471bf0Spatrick * Apply the given function to the module contained in this ThreadSafeModule. 111773471bf0Spatrick */ 111873471bf0Spatrick LLVMErrorRef 111973471bf0Spatrick LLVMOrcThreadSafeModuleWithModuleDo(LLVMOrcThreadSafeModuleRef TSM, 112073471bf0Spatrick LLVMOrcGenericIRModuleOperationFunction F, 112173471bf0Spatrick void *Ctx); 112273471bf0Spatrick 112373471bf0Spatrick /** 1124097a140dSpatrick * Create a JITTargetMachineBuilder by detecting the host. 1125097a140dSpatrick * 1126097a140dSpatrick * On success the client owns the resulting JITTargetMachineBuilder. It must be 112773471bf0Spatrick * passed to a consuming operation (e.g. 112873471bf0Spatrick * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling 112973471bf0Spatrick * LLVMOrcDisposeJITTargetMachineBuilder. 1130097a140dSpatrick */ 1131097a140dSpatrick LLVMErrorRef LLVMOrcJITTargetMachineBuilderDetectHost( 1132097a140dSpatrick LLVMOrcJITTargetMachineBuilderRef *Result); 1133097a140dSpatrick 1134097a140dSpatrick /** 1135097a140dSpatrick * Create a JITTargetMachineBuilder from the given TargetMachine template. 1136097a140dSpatrick * 1137097a140dSpatrick * This operation takes ownership of the given TargetMachine and destroys it 1138097a140dSpatrick * before returing. The resulting JITTargetMachineBuilder is owned by the client 113973471bf0Spatrick * and must be passed to a consuming operation (e.g. 114073471bf0Spatrick * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling 114173471bf0Spatrick * LLVMOrcDisposeJITTargetMachineBuilder. 1142097a140dSpatrick */ 1143097a140dSpatrick LLVMOrcJITTargetMachineBuilderRef 1144097a140dSpatrick LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(LLVMTargetMachineRef TM); 1145097a140dSpatrick 1146097a140dSpatrick /** 1147097a140dSpatrick * Dispose of a JITTargetMachineBuilder. 1148097a140dSpatrick */ 1149097a140dSpatrick void LLVMOrcDisposeJITTargetMachineBuilder( 1150097a140dSpatrick LLVMOrcJITTargetMachineBuilderRef JTMB); 1151097a140dSpatrick 1152097a140dSpatrick /** 115373471bf0Spatrick * Returns the target triple for the given JITTargetMachineBuilder as a string. 1154097a140dSpatrick * 115573471bf0Spatrick * The caller owns the resulting string as must dispose of it by calling 115673471bf0Spatrick * LLVMDisposeMessage 1157097a140dSpatrick */ 115873471bf0Spatrick char *LLVMOrcJITTargetMachineBuilderGetTargetTriple( 115973471bf0Spatrick LLVMOrcJITTargetMachineBuilderRef JTMB); 1160097a140dSpatrick 1161097a140dSpatrick /** 116273471bf0Spatrick * Sets the target triple for the given JITTargetMachineBuilder to the given 116373471bf0Spatrick * string. 1164097a140dSpatrick */ 116573471bf0Spatrick void LLVMOrcJITTargetMachineBuilderSetTargetTriple( 116673471bf0Spatrick LLVMOrcJITTargetMachineBuilderRef JTMB, const char *TargetTriple); 1167097a140dSpatrick 1168097a140dSpatrick /** 116973471bf0Spatrick * Add an object to an ObjectLayer to the given JITDylib. 1170097a140dSpatrick * 117173471bf0Spatrick * Adds a buffer representing an object file to the given JITDylib using the 117273471bf0Spatrick * given ObjectLayer instance. This operation transfers ownership of the buffer 117373471bf0Spatrick * to the ObjectLayer instance. The buffer should not be disposed of or 117473471bf0Spatrick * referenced once this function returns. 1175097a140dSpatrick * 117673471bf0Spatrick * Resources associated with the given object will be tracked by the given 117773471bf0Spatrick * JITDylib's default ResourceTracker. 1178097a140dSpatrick */ 117973471bf0Spatrick LLVMErrorRef LLVMOrcObjectLayerAddObjectFile(LLVMOrcObjectLayerRef ObjLayer, 118073471bf0Spatrick LLVMOrcJITDylibRef JD, 1181097a140dSpatrick LLVMMemoryBufferRef ObjBuffer); 1182097a140dSpatrick 1183097a140dSpatrick /** 118473471bf0Spatrick * Add an object to an ObjectLayer using the given ResourceTracker. 1185097a140dSpatrick * 118673471bf0Spatrick * Adds a buffer representing an object file to the given ResourceTracker's 118773471bf0Spatrick * JITDylib using the given ObjectLayer instance. This operation transfers 118873471bf0Spatrick * ownership of the buffer to the ObjectLayer instance. The buffer should not 118973471bf0Spatrick * be disposed of or referenced once this function returns. 119073471bf0Spatrick * 119173471bf0Spatrick * Resources associated with the given object will be tracked by 119273471bf0Spatrick * ResourceTracker RT. 1193097a140dSpatrick */ 119473471bf0Spatrick LLVMErrorRef 119573471bf0Spatrick LLVMOrcObjectLayerAddObjectFileWithRT(LLVMOrcObjectLayerRef ObjLayer, 119673471bf0Spatrick LLVMOrcResourceTrackerRef RT, 119773471bf0Spatrick LLVMMemoryBufferRef ObjBuffer); 119873471bf0Spatrick 119973471bf0Spatrick /** 120073471bf0Spatrick * Emit an object buffer to an ObjectLayer. 120173471bf0Spatrick * 120273471bf0Spatrick * Ownership of the responsibility object and object buffer pass to this 120373471bf0Spatrick * function. The client is not responsible for cleanup. 120473471bf0Spatrick */ 120573471bf0Spatrick void LLVMOrcObjectLayerEmit(LLVMOrcObjectLayerRef ObjLayer, 120673471bf0Spatrick LLVMOrcMaterializationResponsibilityRef R, 120773471bf0Spatrick LLVMMemoryBufferRef ObjBuffer); 120873471bf0Spatrick 120973471bf0Spatrick /** 121073471bf0Spatrick * Dispose of an ObjectLayer. 121173471bf0Spatrick */ 121273471bf0Spatrick void LLVMOrcDisposeObjectLayer(LLVMOrcObjectLayerRef ObjLayer); 121373471bf0Spatrick 121473471bf0Spatrick void LLVMOrcIRTransformLayerEmit(LLVMOrcIRTransformLayerRef IRTransformLayer, 121573471bf0Spatrick LLVMOrcMaterializationResponsibilityRef MR, 121673471bf0Spatrick LLVMOrcThreadSafeModuleRef TSM); 121773471bf0Spatrick 121873471bf0Spatrick /** 121973471bf0Spatrick * Set the transform function of the provided transform layer, passing through a 122073471bf0Spatrick * pointer to user provided context. 122173471bf0Spatrick */ 122273471bf0Spatrick void LLVMOrcIRTransformLayerSetTransform( 122373471bf0Spatrick LLVMOrcIRTransformLayerRef IRTransformLayer, 122473471bf0Spatrick LLVMOrcIRTransformLayerTransformFunction TransformFunction, void *Ctx); 122573471bf0Spatrick 122673471bf0Spatrick /** 122773471bf0Spatrick * Set the transform function on an LLVMOrcObjectTransformLayer. 122873471bf0Spatrick */ 122973471bf0Spatrick void LLVMOrcObjectTransformLayerSetTransform( 123073471bf0Spatrick LLVMOrcObjectTransformLayerRef ObjTransformLayer, 123173471bf0Spatrick LLVMOrcObjectTransformLayerTransformFunction TransformFunction, void *Ctx); 123273471bf0Spatrick 123373471bf0Spatrick /** 123473471bf0Spatrick * Create a LocalIndirectStubsManager from the given target triple. 123573471bf0Spatrick * 123673471bf0Spatrick * The resulting IndirectStubsManager is owned by the client 123773471bf0Spatrick * and must be disposed of by calling LLVMOrcDisposeDisposeIndirectStubsManager. 123873471bf0Spatrick */ 123973471bf0Spatrick LLVMOrcIndirectStubsManagerRef 124073471bf0Spatrick LLVMOrcCreateLocalIndirectStubsManager(const char *TargetTriple); 124173471bf0Spatrick 124273471bf0Spatrick /** 124373471bf0Spatrick * Dispose of an IndirectStubsManager. 124473471bf0Spatrick */ 124573471bf0Spatrick void LLVMOrcDisposeIndirectStubsManager(LLVMOrcIndirectStubsManagerRef ISM); 124673471bf0Spatrick 124773471bf0Spatrick LLVMErrorRef LLVMOrcCreateLocalLazyCallThroughManager( 124873471bf0Spatrick const char *TargetTriple, LLVMOrcExecutionSessionRef ES, 124973471bf0Spatrick LLVMOrcJITTargetAddress ErrorHandlerAddr, 125073471bf0Spatrick LLVMOrcLazyCallThroughManagerRef *LCTM); 125173471bf0Spatrick 125273471bf0Spatrick /** 125373471bf0Spatrick * Dispose of an LazyCallThroughManager. 125473471bf0Spatrick */ 125573471bf0Spatrick void LLVMOrcDisposeLazyCallThroughManager( 125673471bf0Spatrick LLVMOrcLazyCallThroughManagerRef LCTM); 125773471bf0Spatrick 125873471bf0Spatrick /** 125973471bf0Spatrick * Create a DumpObjects instance. 126073471bf0Spatrick * 126173471bf0Spatrick * DumpDir specifies the path to write dumped objects to. DumpDir may be empty 126273471bf0Spatrick * in which case files will be dumped to the working directory. 126373471bf0Spatrick * 126473471bf0Spatrick * IdentifierOverride specifies a file name stem to use when dumping objects. 126573471bf0Spatrick * If empty then each MemoryBuffer's identifier will be used (with a .o suffix 126673471bf0Spatrick * added if not already present). If an identifier override is supplied it will 126773471bf0Spatrick * be used instead, along with an incrementing counter (since all buffers will 126873471bf0Spatrick * use the same identifier, the resulting files will be named <ident>.o, 126973471bf0Spatrick * <ident>.2.o, <ident>.3.o, and so on). IdentifierOverride should not contain 127073471bf0Spatrick * an extension, as a .o suffix will be added by DumpObjects. 127173471bf0Spatrick */ 127273471bf0Spatrick LLVMOrcDumpObjectsRef LLVMOrcCreateDumpObjects(const char *DumpDir, 127373471bf0Spatrick const char *IdentifierOverride); 127473471bf0Spatrick 127573471bf0Spatrick /** 127673471bf0Spatrick * Dispose of a DumpObjects instance. 127773471bf0Spatrick */ 127873471bf0Spatrick void LLVMOrcDisposeDumpObjects(LLVMOrcDumpObjectsRef DumpObjects); 127973471bf0Spatrick 128073471bf0Spatrick /** 128173471bf0Spatrick * Dump the contents of the given MemoryBuffer. 128273471bf0Spatrick */ 128373471bf0Spatrick LLVMErrorRef LLVMOrcDumpObjects_CallOperator(LLVMOrcDumpObjectsRef DumpObjects, 128473471bf0Spatrick LLVMMemoryBufferRef *ObjBuffer); 1285097a140dSpatrick 1286*d415bd75Srobert /** 1287*d415bd75Srobert * @} 1288*d415bd75Srobert */ 1289*d415bd75Srobert 1290097a140dSpatrick LLVM_C_EXTERN_C_END 1291097a140dSpatrick 1292097a140dSpatrick #endif /* LLVM_C_ORC_H */ 1293