Path: blob/main/contrib/llvm-project/llvm/include/llvm-c/LLJIT.h
35233 views
/*===----------- llvm-c/LLJIT.h - OrcV2 LLJIT C bindings ----------*- C -*-===*\1|* *|2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|3|* Exceptions. *|4|* See https://llvm.org/LICENSE.txt for license information. *|5|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|6|* *|7|*===----------------------------------------------------------------------===*|8|* *|9|* This header declares the C interface to the LLJIT class in *|10|* libLLVMOrcJIT.a, which provides a simple MCJIT-like ORC JIT. *|11|* *|12|* Many exotic languages can interoperate with C code but have a harder time *|13|* with C++ due to name mangling. So in addition to C, this interface enables *|14|* tools written in such languages. *|15|* *|16|* Note: This interface is experimental. It is *NOT* stable, and may be *|17|* changed without warning. Only C API usage documentation is *|18|* provided. See the C++ documentation for all higher level ORC API *|19|* details. *|20|* *|21\*===----------------------------------------------------------------------===*/2223#ifndef LLVM_C_LLJIT_H24#define LLVM_C_LLJIT_H2526#include "llvm-c/Error.h"27#include "llvm-c/Orc.h"28#include "llvm-c/TargetMachine.h"29#include "llvm-c/Types.h"3031LLVM_C_EXTERN_C_BEGIN3233/**34* @defgroup LLVMCExecutionEngineLLJIT LLJIT35* @ingroup LLVMCExecutionEngine36*37* @{38*/3940/**41* A function for constructing an ObjectLinkingLayer instance to be used42* by an LLJIT instance.43*44* Clients can call LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator to45* set the creator function to use when constructing an LLJIT instance.46* This can be used to override the default linking layer implementation47* that would otherwise be chosen by LLJITBuilder.48*49* Object linking layers returned by this function will become owned by the50* LLJIT instance. The client is not responsible for managing their lifetimes51* after the function returns.52*/53typedef LLVMOrcObjectLayerRef (54*LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction)(55void *Ctx, LLVMOrcExecutionSessionRef ES, const char *Triple);5657/**58* A reference to an orc::LLJITBuilder instance.59*/60typedef struct LLVMOrcOpaqueLLJITBuilder *LLVMOrcLLJITBuilderRef;6162/**63* A reference to an orc::LLJIT instance.64*/65typedef struct LLVMOrcOpaqueLLJIT *LLVMOrcLLJITRef;6667/**68* Create an LLVMOrcLLJITBuilder.69*70* The client owns the resulting LLJITBuilder and should dispose of it using71* LLVMOrcDisposeLLJITBuilder once they are done with it.72*/73LLVMOrcLLJITBuilderRef LLVMOrcCreateLLJITBuilder(void);7475/**76* Dispose of an LLVMOrcLLJITBuilderRef. This should only be called if ownership77* has not been passed to LLVMOrcCreateLLJIT (e.g. because some error prevented78* that function from being called).79*/80void LLVMOrcDisposeLLJITBuilder(LLVMOrcLLJITBuilderRef Builder);8182/**83* Set the JITTargetMachineBuilder to be used when constructing the LLJIT84* instance. Calling this function is optional: if it is not called then the85* LLJITBuilder will use JITTargeTMachineBuilder::detectHost to construct a86* JITTargetMachineBuilder.87*88* This function takes ownership of the JTMB argument: clients should not89* dispose of the JITTargetMachineBuilder after calling this function.90*/91void LLVMOrcLLJITBuilderSetJITTargetMachineBuilder(92LLVMOrcLLJITBuilderRef Builder, LLVMOrcJITTargetMachineBuilderRef JTMB);9394/**95* Set an ObjectLinkingLayer creator function for this LLJIT instance.96*/97void LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator(98LLVMOrcLLJITBuilderRef Builder,99LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction F, void *Ctx);100101/**102* Create an LLJIT instance from an LLJITBuilder.103*104* This operation takes ownership of the Builder argument: clients should not105* dispose of the builder after calling this function (even if the function106* returns an error). If a null Builder argument is provided then a107* default-constructed LLJITBuilder will be used.108*109* On success the resulting LLJIT instance is uniquely owned by the client and110* automatically manages the memory of all JIT'd code and all modules that are111* transferred to it (e.g. via LLVMOrcLLJITAddLLVMIRModule). Disposing of the112* LLJIT instance will free all memory managed by the JIT, including JIT'd code113* and not-yet compiled modules.114*/115LLVMErrorRef LLVMOrcCreateLLJIT(LLVMOrcLLJITRef *Result,116LLVMOrcLLJITBuilderRef Builder);117118/**119* Dispose of an LLJIT instance.120*/121LLVMErrorRef LLVMOrcDisposeLLJIT(LLVMOrcLLJITRef J);122123/**124* Get a reference to the ExecutionSession for this LLJIT instance.125*126* The ExecutionSession is owned by the LLJIT instance. The client is not127* responsible for managing its memory.128*/129LLVMOrcExecutionSessionRef LLVMOrcLLJITGetExecutionSession(LLVMOrcLLJITRef J);130131/**132* Return a reference to the Main JITDylib.133*134* The JITDylib is owned by the LLJIT instance. The client is not responsible135* for managing its memory.136*/137LLVMOrcJITDylibRef LLVMOrcLLJITGetMainJITDylib(LLVMOrcLLJITRef J);138139/**140* Return the target triple for this LLJIT instance. This string is owned by141* the LLJIT instance and should not be freed by the client.142*/143const char *LLVMOrcLLJITGetTripleString(LLVMOrcLLJITRef J);144145/**146* Returns the global prefix character according to the LLJIT's DataLayout.147*/148char LLVMOrcLLJITGetGlobalPrefix(LLVMOrcLLJITRef J);149150/**151* Mangles the given string according to the LLJIT instance's DataLayout, then152* interns the result in the SymbolStringPool and returns a reference to the153* pool entry. Clients should call LLVMOrcReleaseSymbolStringPoolEntry to154* decrement the ref-count on the pool entry once they are finished with this155* value.156*/157LLVMOrcSymbolStringPoolEntryRef158LLVMOrcLLJITMangleAndIntern(LLVMOrcLLJITRef J, const char *UnmangledName);159160/**161* Add a buffer representing an object file to the given JITDylib in the given162* LLJIT instance. This operation transfers ownership of the buffer to the163* LLJIT instance. The buffer should not be disposed of or referenced once this164* function returns.165*166* Resources associated with the given object will be tracked by the given167* JITDylib's default resource tracker.168*/169LLVMErrorRef LLVMOrcLLJITAddObjectFile(LLVMOrcLLJITRef J, LLVMOrcJITDylibRef JD,170LLVMMemoryBufferRef ObjBuffer);171172/**173* Add a buffer representing an object file to the given ResourceTracker's174* JITDylib in the given LLJIT instance. This operation transfers ownership of175* the buffer to the LLJIT instance. The buffer should not be disposed of or176* referenced once this function returns.177*178* Resources associated with the given object will be tracked by ResourceTracker179* RT.180*/181LLVMErrorRef LLVMOrcLLJITAddObjectFileWithRT(LLVMOrcLLJITRef J,182LLVMOrcResourceTrackerRef RT,183LLVMMemoryBufferRef ObjBuffer);184185/**186* Add an IR module to the given JITDylib in the given LLJIT instance. This187* operation transfers ownership of the TSM argument to the LLJIT instance.188* The TSM argument should not be disposed of or referenced once this189* function returns.190*191* Resources associated with the given Module will be tracked by the given192* JITDylib's default resource tracker.193*/194LLVMErrorRef LLVMOrcLLJITAddLLVMIRModule(LLVMOrcLLJITRef J,195LLVMOrcJITDylibRef JD,196LLVMOrcThreadSafeModuleRef TSM);197198/**199* Add an IR module to the given ResourceTracker's JITDylib in the given LLJIT200* instance. This operation transfers ownership of the TSM argument to the LLJIT201* instance. The TSM argument should not be disposed of or referenced once this202* function returns.203*204* Resources associated with the given Module will be tracked by ResourceTracker205* RT.206*/207LLVMErrorRef LLVMOrcLLJITAddLLVMIRModuleWithRT(LLVMOrcLLJITRef J,208LLVMOrcResourceTrackerRef JD,209LLVMOrcThreadSafeModuleRef TSM);210211/**212* Look up the given symbol in the main JITDylib of the given LLJIT instance.213*214* This operation does not take ownership of the Name argument.215*/216LLVMErrorRef LLVMOrcLLJITLookup(LLVMOrcLLJITRef J,217LLVMOrcExecutorAddress *Result,218const char *Name);219220/**221* Returns a non-owning reference to the LLJIT instance's object linking layer.222*/223LLVMOrcObjectLayerRef LLVMOrcLLJITGetObjLinkingLayer(LLVMOrcLLJITRef J);224225/**226* Returns a non-owning reference to the LLJIT instance's object linking layer.227*/228LLVMOrcObjectTransformLayerRef229LLVMOrcLLJITGetObjTransformLayer(LLVMOrcLLJITRef J);230231/**232* Returns a non-owning reference to the LLJIT instance's IR transform layer.233*/234LLVMOrcIRTransformLayerRef LLVMOrcLLJITGetIRTransformLayer(LLVMOrcLLJITRef J);235236/**237* Get the LLJIT instance's default data layout string.238*239* This string is owned by the LLJIT instance and does not need to be freed240* by the caller.241*/242const char *LLVMOrcLLJITGetDataLayoutStr(LLVMOrcLLJITRef J);243244/**245* @}246*/247248LLVM_C_EXTERN_C_END249250#endif /* LLVM_C_LLJIT_H */251252253