173471bf0Spatrick /*===----------- llvm-c/LLJIT.h - OrcV2 LLJIT C bindings --------*- C++ -*-===*\ 273471bf0Spatrick |* *| 373471bf0Spatrick |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 473471bf0Spatrick |* Exceptions. *| 573471bf0Spatrick |* See https://llvm.org/LICENSE.txt for license information. *| 673471bf0Spatrick |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 773471bf0Spatrick |* *| 873471bf0Spatrick |*===----------------------------------------------------------------------===*| 973471bf0Spatrick |* *| 1073471bf0Spatrick |* This header declares the C interface to the LLJIT class in *| 1173471bf0Spatrick |* libLLVMOrcJIT.a, which provides a simple MCJIT-like ORC JIT. *| 1273471bf0Spatrick |* *| 1373471bf0Spatrick |* Many exotic languages can interoperate with C code but have a harder time *| 1473471bf0Spatrick |* with C++ due to name mangling. So in addition to C, this interface enables *| 1573471bf0Spatrick |* tools written in such languages. *| 1673471bf0Spatrick |* *| 1773471bf0Spatrick |* Note: This interface is experimental. It is *NOT* stable, and may be *| 1873471bf0Spatrick |* changed without warning. Only C API usage documentation is *| 1973471bf0Spatrick |* provided. See the C++ documentation for all higher level ORC API *| 2073471bf0Spatrick |* details. *| 2173471bf0Spatrick |* *| 2273471bf0Spatrick \*===----------------------------------------------------------------------===*/ 2373471bf0Spatrick 2473471bf0Spatrick #ifndef LLVM_C_LLJIT_H 2573471bf0Spatrick #define LLVM_C_LLJIT_H 2673471bf0Spatrick 2773471bf0Spatrick #include "llvm-c/Error.h" 2873471bf0Spatrick #include "llvm-c/Orc.h" 2973471bf0Spatrick #include "llvm-c/TargetMachine.h" 3073471bf0Spatrick #include "llvm-c/Types.h" 3173471bf0Spatrick 3273471bf0Spatrick LLVM_C_EXTERN_C_BEGIN 3373471bf0Spatrick 3473471bf0Spatrick /** 35*d415bd75Srobert * @defgroup LLVMCExecutionEngineLLJIT LLJIT 36*d415bd75Srobert * @ingroup LLVMCExecutionEngine 37*d415bd75Srobert * 38*d415bd75Srobert * @{ 39*d415bd75Srobert */ 40*d415bd75Srobert 41*d415bd75Srobert /** 4273471bf0Spatrick * A function for constructing an ObjectLinkingLayer instance to be used 4373471bf0Spatrick * by an LLJIT instance. 4473471bf0Spatrick * 4573471bf0Spatrick * Clients can call LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator to 4673471bf0Spatrick * set the creator function to use when constructing an LLJIT instance. 4773471bf0Spatrick * This can be used to override the default linking layer implementation 4873471bf0Spatrick * that would otherwise be chosen by LLJITBuilder. 4973471bf0Spatrick * 5073471bf0Spatrick * Object linking layers returned by this function will become owned by the 5173471bf0Spatrick * LLJIT instance. The client is not responsible for managing their lifetimes 5273471bf0Spatrick * after the function returns. 5373471bf0Spatrick */ 5473471bf0Spatrick typedef LLVMOrcObjectLayerRef ( 5573471bf0Spatrick *LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction)( 5673471bf0Spatrick void *Ctx, LLVMOrcExecutionSessionRef ES, const char *Triple); 5773471bf0Spatrick 5873471bf0Spatrick /** 5973471bf0Spatrick * A reference to an orc::LLJITBuilder instance. 6073471bf0Spatrick */ 6173471bf0Spatrick typedef struct LLVMOrcOpaqueLLJITBuilder *LLVMOrcLLJITBuilderRef; 6273471bf0Spatrick 6373471bf0Spatrick /** 6473471bf0Spatrick * A reference to an orc::LLJIT instance. 6573471bf0Spatrick */ 6673471bf0Spatrick typedef struct LLVMOrcOpaqueLLJIT *LLVMOrcLLJITRef; 6773471bf0Spatrick 6873471bf0Spatrick /** 6973471bf0Spatrick * Create an LLVMOrcLLJITBuilder. 7073471bf0Spatrick * 7173471bf0Spatrick * The client owns the resulting LLJITBuilder and should dispose of it using 7273471bf0Spatrick * LLVMOrcDisposeLLJITBuilder once they are done with it. 7373471bf0Spatrick */ 7473471bf0Spatrick LLVMOrcLLJITBuilderRef LLVMOrcCreateLLJITBuilder(void); 7573471bf0Spatrick 7673471bf0Spatrick /** 7773471bf0Spatrick * Dispose of an LLVMOrcLLJITBuilderRef. This should only be called if ownership 7873471bf0Spatrick * has not been passed to LLVMOrcCreateLLJIT (e.g. because some error prevented 7973471bf0Spatrick * that function from being called). 8073471bf0Spatrick */ 8173471bf0Spatrick void LLVMOrcDisposeLLJITBuilder(LLVMOrcLLJITBuilderRef Builder); 8273471bf0Spatrick 8373471bf0Spatrick /** 8473471bf0Spatrick * Set the JITTargetMachineBuilder to be used when constructing the LLJIT 8573471bf0Spatrick * instance. Calling this function is optional: if it is not called then the 8673471bf0Spatrick * LLJITBuilder will use JITTargeTMachineBuilder::detectHost to construct a 8773471bf0Spatrick * JITTargetMachineBuilder. 8873471bf0Spatrick * 8973471bf0Spatrick * This function takes ownership of the JTMB argument: clients should not 9073471bf0Spatrick * dispose of the JITTargetMachineBuilder after calling this function. 9173471bf0Spatrick */ 9273471bf0Spatrick void LLVMOrcLLJITBuilderSetJITTargetMachineBuilder( 9373471bf0Spatrick LLVMOrcLLJITBuilderRef Builder, LLVMOrcJITTargetMachineBuilderRef JTMB); 9473471bf0Spatrick 9573471bf0Spatrick /** 9673471bf0Spatrick * Set an ObjectLinkingLayer creator function for this LLJIT instance. 9773471bf0Spatrick */ 9873471bf0Spatrick void LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator( 9973471bf0Spatrick LLVMOrcLLJITBuilderRef Builder, 10073471bf0Spatrick LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction F, void *Ctx); 10173471bf0Spatrick 10273471bf0Spatrick /** 10373471bf0Spatrick * Create an LLJIT instance from an LLJITBuilder. 10473471bf0Spatrick * 10573471bf0Spatrick * This operation takes ownership of the Builder argument: clients should not 10673471bf0Spatrick * dispose of the builder after calling this function (even if the function 10773471bf0Spatrick * returns an error). If a null Builder argument is provided then a 10873471bf0Spatrick * default-constructed LLJITBuilder will be used. 10973471bf0Spatrick * 11073471bf0Spatrick * On success the resulting LLJIT instance is uniquely owned by the client and 11173471bf0Spatrick * automatically manages the memory of all JIT'd code and all modules that are 11273471bf0Spatrick * transferred to it (e.g. via LLVMOrcLLJITAddLLVMIRModule). Disposing of the 11373471bf0Spatrick * LLJIT instance will free all memory managed by the JIT, including JIT'd code 11473471bf0Spatrick * and not-yet compiled modules. 11573471bf0Spatrick */ 11673471bf0Spatrick LLVMErrorRef LLVMOrcCreateLLJIT(LLVMOrcLLJITRef *Result, 11773471bf0Spatrick LLVMOrcLLJITBuilderRef Builder); 11873471bf0Spatrick 11973471bf0Spatrick /** 12073471bf0Spatrick * Dispose of an LLJIT instance. 12173471bf0Spatrick */ 12273471bf0Spatrick LLVMErrorRef LLVMOrcDisposeLLJIT(LLVMOrcLLJITRef J); 12373471bf0Spatrick 12473471bf0Spatrick /** 12573471bf0Spatrick * Get a reference to the ExecutionSession for this LLJIT instance. 12673471bf0Spatrick * 12773471bf0Spatrick * The ExecutionSession is owned by the LLJIT instance. The client is not 12873471bf0Spatrick * responsible for managing its memory. 12973471bf0Spatrick */ 13073471bf0Spatrick LLVMOrcExecutionSessionRef LLVMOrcLLJITGetExecutionSession(LLVMOrcLLJITRef J); 13173471bf0Spatrick 13273471bf0Spatrick /** 13373471bf0Spatrick * Return a reference to the Main JITDylib. 13473471bf0Spatrick * 13573471bf0Spatrick * The JITDylib is owned by the LLJIT instance. The client is not responsible 13673471bf0Spatrick * for managing its memory. 13773471bf0Spatrick */ 13873471bf0Spatrick LLVMOrcJITDylibRef LLVMOrcLLJITGetMainJITDylib(LLVMOrcLLJITRef J); 13973471bf0Spatrick 14073471bf0Spatrick /** 14173471bf0Spatrick * Return the target triple for this LLJIT instance. This string is owned by 14273471bf0Spatrick * the LLJIT instance and should not be freed by the client. 14373471bf0Spatrick */ 14473471bf0Spatrick const char *LLVMOrcLLJITGetTripleString(LLVMOrcLLJITRef J); 14573471bf0Spatrick 14673471bf0Spatrick /** 14773471bf0Spatrick * Returns the global prefix character according to the LLJIT's DataLayout. 14873471bf0Spatrick */ 14973471bf0Spatrick char LLVMOrcLLJITGetGlobalPrefix(LLVMOrcLLJITRef J); 15073471bf0Spatrick 15173471bf0Spatrick /** 15273471bf0Spatrick * Mangles the given string according to the LLJIT instance's DataLayout, then 15373471bf0Spatrick * interns the result in the SymbolStringPool and returns a reference to the 15473471bf0Spatrick * pool entry. Clients should call LLVMOrcReleaseSymbolStringPoolEntry to 15573471bf0Spatrick * decrement the ref-count on the pool entry once they are finished with this 15673471bf0Spatrick * value. 15773471bf0Spatrick */ 15873471bf0Spatrick LLVMOrcSymbolStringPoolEntryRef 15973471bf0Spatrick LLVMOrcLLJITMangleAndIntern(LLVMOrcLLJITRef J, const char *UnmangledName); 16073471bf0Spatrick 16173471bf0Spatrick /** 16273471bf0Spatrick * Add a buffer representing an object file to the given JITDylib in the given 16373471bf0Spatrick * LLJIT instance. This operation transfers ownership of the buffer to the 16473471bf0Spatrick * LLJIT instance. The buffer should not be disposed of or referenced once this 16573471bf0Spatrick * function returns. 16673471bf0Spatrick * 16773471bf0Spatrick * Resources associated with the given object will be tracked by the given 16873471bf0Spatrick * JITDylib's default resource tracker. 16973471bf0Spatrick */ 17073471bf0Spatrick LLVMErrorRef LLVMOrcLLJITAddObjectFile(LLVMOrcLLJITRef J, LLVMOrcJITDylibRef JD, 17173471bf0Spatrick LLVMMemoryBufferRef ObjBuffer); 17273471bf0Spatrick 17373471bf0Spatrick /** 17473471bf0Spatrick * Add a buffer representing an object file to the given ResourceTracker's 17573471bf0Spatrick * JITDylib in the given LLJIT instance. This operation transfers ownership of 17673471bf0Spatrick * the buffer to the LLJIT instance. The buffer should not be disposed of or 17773471bf0Spatrick * referenced once this function returns. 17873471bf0Spatrick * 17973471bf0Spatrick * Resources associated with the given object will be tracked by ResourceTracker 18073471bf0Spatrick * RT. 18173471bf0Spatrick */ 18273471bf0Spatrick LLVMErrorRef LLVMOrcLLJITAddObjectFileWithRT(LLVMOrcLLJITRef J, 18373471bf0Spatrick LLVMOrcResourceTrackerRef RT, 18473471bf0Spatrick LLVMMemoryBufferRef ObjBuffer); 18573471bf0Spatrick 18673471bf0Spatrick /** 18773471bf0Spatrick * Add an IR module to the given JITDylib in the given LLJIT instance. This 18873471bf0Spatrick * operation transfers ownership of the TSM argument to the LLJIT instance. 18973471bf0Spatrick * The TSM argument should not be disposed of or referenced once this 19073471bf0Spatrick * function returns. 19173471bf0Spatrick * 19273471bf0Spatrick * Resources associated with the given Module will be tracked by the given 19373471bf0Spatrick * JITDylib's default resource tracker. 19473471bf0Spatrick */ 19573471bf0Spatrick LLVMErrorRef LLVMOrcLLJITAddLLVMIRModule(LLVMOrcLLJITRef J, 19673471bf0Spatrick LLVMOrcJITDylibRef JD, 19773471bf0Spatrick LLVMOrcThreadSafeModuleRef TSM); 19873471bf0Spatrick 19973471bf0Spatrick /** 20073471bf0Spatrick * Add an IR module to the given ResourceTracker's JITDylib in the given LLJIT 20173471bf0Spatrick * instance. This operation transfers ownership of the TSM argument to the LLJIT 20273471bf0Spatrick * instance. The TSM argument should not be disposed of or referenced once this 20373471bf0Spatrick * function returns. 20473471bf0Spatrick * 20573471bf0Spatrick * Resources associated with the given Module will be tracked by ResourceTracker 20673471bf0Spatrick * RT. 20773471bf0Spatrick */ 20873471bf0Spatrick LLVMErrorRef LLVMOrcLLJITAddLLVMIRModuleWithRT(LLVMOrcLLJITRef J, 20973471bf0Spatrick LLVMOrcResourceTrackerRef JD, 21073471bf0Spatrick LLVMOrcThreadSafeModuleRef TSM); 21173471bf0Spatrick 21273471bf0Spatrick /** 21373471bf0Spatrick * Look up the given symbol in the main JITDylib of the given LLJIT instance. 21473471bf0Spatrick * 21573471bf0Spatrick * This operation does not take ownership of the Name argument. 21673471bf0Spatrick */ 21773471bf0Spatrick LLVMErrorRef LLVMOrcLLJITLookup(LLVMOrcLLJITRef J, 21873471bf0Spatrick LLVMOrcExecutorAddress *Result, 21973471bf0Spatrick const char *Name); 22073471bf0Spatrick 22173471bf0Spatrick /** 22273471bf0Spatrick * Returns a non-owning reference to the LLJIT instance's object linking layer. 22373471bf0Spatrick */ 22473471bf0Spatrick LLVMOrcObjectLayerRef LLVMOrcLLJITGetObjLinkingLayer(LLVMOrcLLJITRef J); 22573471bf0Spatrick 22673471bf0Spatrick /** 22773471bf0Spatrick * Returns a non-owning reference to the LLJIT instance's object linking layer. 22873471bf0Spatrick */ 22973471bf0Spatrick LLVMOrcObjectTransformLayerRef 23073471bf0Spatrick LLVMOrcLLJITGetObjTransformLayer(LLVMOrcLLJITRef J); 23173471bf0Spatrick 23273471bf0Spatrick /** 23373471bf0Spatrick * Returns a non-owning reference to the LLJIT instance's IR transform layer. 23473471bf0Spatrick */ 23573471bf0Spatrick LLVMOrcIRTransformLayerRef LLVMOrcLLJITGetIRTransformLayer(LLVMOrcLLJITRef J); 23673471bf0Spatrick 23773471bf0Spatrick /** 23873471bf0Spatrick * Get the LLJIT instance's default data layout string. 23973471bf0Spatrick * 24073471bf0Spatrick * This string is owned by the LLJIT instance and does not need to be freed 24173471bf0Spatrick * by the caller. 24273471bf0Spatrick */ 24373471bf0Spatrick const char *LLVMOrcLLJITGetDataLayoutStr(LLVMOrcLLJITRef J); 24473471bf0Spatrick 245*d415bd75Srobert /** 246*d415bd75Srobert * @} 247*d415bd75Srobert */ 248*d415bd75Srobert 24973471bf0Spatrick LLVM_C_EXTERN_C_END 25073471bf0Spatrick 25173471bf0Spatrick #endif /* LLVM_C_LLJIT_H */ 252