1*e8d8bef9SDimitry Andric /*===----------- llvm-c/LLJIT.h - OrcV2 LLJIT C bindings --------*- C++ -*-===*\ 2*e8d8bef9SDimitry Andric |* *| 3*e8d8bef9SDimitry Andric |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 4*e8d8bef9SDimitry Andric |* Exceptions. *| 5*e8d8bef9SDimitry Andric |* See https://llvm.org/LICENSE.txt for license information. *| 6*e8d8bef9SDimitry Andric |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 7*e8d8bef9SDimitry Andric |* *| 8*e8d8bef9SDimitry Andric |*===----------------------------------------------------------------------===*| 9*e8d8bef9SDimitry Andric |* *| 10*e8d8bef9SDimitry Andric |* This header declares the C interface to the LLJIT class in *| 11*e8d8bef9SDimitry Andric |* libLLVMOrcJIT.a, which provides a simple MCJIT-like ORC JIT. *| 12*e8d8bef9SDimitry Andric |* *| 13*e8d8bef9SDimitry Andric |* Many exotic languages can interoperate with C code but have a harder time *| 14*e8d8bef9SDimitry Andric |* with C++ due to name mangling. So in addition to C, this interface enables *| 15*e8d8bef9SDimitry Andric |* tools written in such languages. *| 16*e8d8bef9SDimitry Andric |* *| 17*e8d8bef9SDimitry Andric |* Note: This interface is experimental. It is *NOT* stable, and may be *| 18*e8d8bef9SDimitry Andric |* changed without warning. Only C API usage documentation is *| 19*e8d8bef9SDimitry Andric |* provided. See the C++ documentation for all higher level ORC API *| 20*e8d8bef9SDimitry Andric |* details. *| 21*e8d8bef9SDimitry Andric |* *| 22*e8d8bef9SDimitry Andric \*===----------------------------------------------------------------------===*/ 23*e8d8bef9SDimitry Andric 24*e8d8bef9SDimitry Andric #ifndef LLVM_C_LLJIT_H 25*e8d8bef9SDimitry Andric #define LLVM_C_LLJIT_H 26*e8d8bef9SDimitry Andric 27*e8d8bef9SDimitry Andric #include "llvm-c/Error.h" 28*e8d8bef9SDimitry Andric #include "llvm-c/Orc.h" 29*e8d8bef9SDimitry Andric #include "llvm-c/TargetMachine.h" 30*e8d8bef9SDimitry Andric #include "llvm-c/Types.h" 31*e8d8bef9SDimitry Andric 32*e8d8bef9SDimitry Andric LLVM_C_EXTERN_C_BEGIN 33*e8d8bef9SDimitry Andric 34*e8d8bef9SDimitry Andric /** 35*e8d8bef9SDimitry Andric * A function for constructing an ObjectLinkingLayer instance to be used 36*e8d8bef9SDimitry Andric * by an LLJIT instance. 37*e8d8bef9SDimitry Andric * 38*e8d8bef9SDimitry Andric * Clients can call LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator to 39*e8d8bef9SDimitry Andric * set the creator function to use when constructing an LLJIT instance. 40*e8d8bef9SDimitry Andric * This can be used to override the default linking layer implementation 41*e8d8bef9SDimitry Andric * that would otherwise be chosen by LLJITBuilder. 42*e8d8bef9SDimitry Andric * 43*e8d8bef9SDimitry Andric * Object linking layers returned by this function will become owned by the 44*e8d8bef9SDimitry Andric * LLJIT instance. The client is not responsible for managing their lifetimes 45*e8d8bef9SDimitry Andric * after the function returns. 46*e8d8bef9SDimitry Andric */ 47*e8d8bef9SDimitry Andric typedef LLVMOrcObjectLayerRef ( 48*e8d8bef9SDimitry Andric *LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction)( 49*e8d8bef9SDimitry Andric void *Ctx, LLVMOrcExecutionSessionRef ES, const char *Triple); 50*e8d8bef9SDimitry Andric 51*e8d8bef9SDimitry Andric /** 52*e8d8bef9SDimitry Andric * A reference to an orc::LLJITBuilder instance. 53*e8d8bef9SDimitry Andric */ 54*e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueLLJITBuilder *LLVMOrcLLJITBuilderRef; 55*e8d8bef9SDimitry Andric 56*e8d8bef9SDimitry Andric /** 57*e8d8bef9SDimitry Andric * A reference to an orc::LLJIT instance. 58*e8d8bef9SDimitry Andric */ 59*e8d8bef9SDimitry Andric typedef struct LLVMOrcOpaqueLLJIT *LLVMOrcLLJITRef; 60*e8d8bef9SDimitry Andric 61*e8d8bef9SDimitry Andric /** 62*e8d8bef9SDimitry Andric * Create an LLVMOrcLLJITBuilder. 63*e8d8bef9SDimitry Andric * 64*e8d8bef9SDimitry Andric * The client owns the resulting LLJITBuilder and should dispose of it using 65*e8d8bef9SDimitry Andric * LLVMOrcDisposeLLJITBuilder once they are done with it. 66*e8d8bef9SDimitry Andric */ 67*e8d8bef9SDimitry Andric LLVMOrcLLJITBuilderRef LLVMOrcCreateLLJITBuilder(void); 68*e8d8bef9SDimitry Andric 69*e8d8bef9SDimitry Andric /** 70*e8d8bef9SDimitry Andric * Dispose of an LLVMOrcLLJITBuilderRef. This should only be called if ownership 71*e8d8bef9SDimitry Andric * has not been passed to LLVMOrcCreateLLJIT (e.g. because some error prevented 72*e8d8bef9SDimitry Andric * that function from being called). 73*e8d8bef9SDimitry Andric */ 74*e8d8bef9SDimitry Andric void LLVMOrcDisposeLLJITBuilder(LLVMOrcLLJITBuilderRef Builder); 75*e8d8bef9SDimitry Andric 76*e8d8bef9SDimitry Andric /** 77*e8d8bef9SDimitry Andric * Set the JITTargetMachineBuilder to be used when constructing the LLJIT 78*e8d8bef9SDimitry Andric * instance. Calling this function is optional: if it is not called then the 79*e8d8bef9SDimitry Andric * LLJITBuilder will use JITTargeTMachineBuilder::detectHost to construct a 80*e8d8bef9SDimitry Andric * JITTargetMachineBuilder. 81*e8d8bef9SDimitry Andric */ 82*e8d8bef9SDimitry Andric void LLVMOrcLLJITBuilderSetJITTargetMachineBuilder( 83*e8d8bef9SDimitry Andric LLVMOrcLLJITBuilderRef Builder, LLVMOrcJITTargetMachineBuilderRef JTMB); 84*e8d8bef9SDimitry Andric 85*e8d8bef9SDimitry Andric /** 86*e8d8bef9SDimitry Andric * Set an ObjectLinkingLayer creator function for this LLJIT instance. 87*e8d8bef9SDimitry Andric */ 88*e8d8bef9SDimitry Andric void LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator( 89*e8d8bef9SDimitry Andric LLVMOrcLLJITBuilderRef Builder, 90*e8d8bef9SDimitry Andric LLVMOrcLLJITBuilderObjectLinkingLayerCreatorFunction F, void *Ctx); 91*e8d8bef9SDimitry Andric 92*e8d8bef9SDimitry Andric /** 93*e8d8bef9SDimitry Andric * Create an LLJIT instance from an LLJITBuilder. 94*e8d8bef9SDimitry Andric * 95*e8d8bef9SDimitry Andric * This operation takes ownership of the Builder argument: clients should not 96*e8d8bef9SDimitry Andric * dispose of the builder after calling this function (even if the function 97*e8d8bef9SDimitry Andric * returns an error). If a null Builder argument is provided then a 98*e8d8bef9SDimitry Andric * default-constructed LLJITBuilder will be used. 99*e8d8bef9SDimitry Andric * 100*e8d8bef9SDimitry Andric * On success the resulting LLJIT instance is uniquely owned by the client and 101*e8d8bef9SDimitry Andric * automatically manages the memory of all JIT'd code and all modules that are 102*e8d8bef9SDimitry Andric * transferred to it (e.g. via LLVMOrcLLJITAddLLVMIRModule). Disposing of the 103*e8d8bef9SDimitry Andric * LLJIT instance will free all memory managed by the JIT, including JIT'd code 104*e8d8bef9SDimitry Andric * and not-yet compiled modules. 105*e8d8bef9SDimitry Andric */ 106*e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcCreateLLJIT(LLVMOrcLLJITRef *Result, 107*e8d8bef9SDimitry Andric LLVMOrcLLJITBuilderRef Builder); 108*e8d8bef9SDimitry Andric 109*e8d8bef9SDimitry Andric /** 110*e8d8bef9SDimitry Andric * Dispose of an LLJIT instance. 111*e8d8bef9SDimitry Andric */ 112*e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcDisposeLLJIT(LLVMOrcLLJITRef J); 113*e8d8bef9SDimitry Andric 114*e8d8bef9SDimitry Andric /** 115*e8d8bef9SDimitry Andric * Get a reference to the ExecutionSession for this LLJIT instance. 116*e8d8bef9SDimitry Andric * 117*e8d8bef9SDimitry Andric * The ExecutionSession is owned by the LLJIT instance. The client is not 118*e8d8bef9SDimitry Andric * responsible for managing its memory. 119*e8d8bef9SDimitry Andric */ 120*e8d8bef9SDimitry Andric LLVMOrcExecutionSessionRef LLVMOrcLLJITGetExecutionSession(LLVMOrcLLJITRef J); 121*e8d8bef9SDimitry Andric 122*e8d8bef9SDimitry Andric /** 123*e8d8bef9SDimitry Andric * Return a reference to the Main JITDylib. 124*e8d8bef9SDimitry Andric * 125*e8d8bef9SDimitry Andric * The JITDylib is owned by the LLJIT instance. The client is not responsible 126*e8d8bef9SDimitry Andric * for managing its memory. 127*e8d8bef9SDimitry Andric */ 128*e8d8bef9SDimitry Andric LLVMOrcJITDylibRef LLVMOrcLLJITGetMainJITDylib(LLVMOrcLLJITRef J); 129*e8d8bef9SDimitry Andric 130*e8d8bef9SDimitry Andric /** 131*e8d8bef9SDimitry Andric * Return the target triple for this LLJIT instance. This string is owned by 132*e8d8bef9SDimitry Andric * the LLJIT instance and should not be freed by the client. 133*e8d8bef9SDimitry Andric */ 134*e8d8bef9SDimitry Andric const char *LLVMOrcLLJITGetTripleString(LLVMOrcLLJITRef J); 135*e8d8bef9SDimitry Andric 136*e8d8bef9SDimitry Andric /** 137*e8d8bef9SDimitry Andric * Returns the global prefix character according to the LLJIT's DataLayout. 138*e8d8bef9SDimitry Andric */ 139*e8d8bef9SDimitry Andric char LLVMOrcLLJITGetGlobalPrefix(LLVMOrcLLJITRef J); 140*e8d8bef9SDimitry Andric 141*e8d8bef9SDimitry Andric /** 142*e8d8bef9SDimitry Andric * Mangles the given string according to the LLJIT instance's DataLayout, then 143*e8d8bef9SDimitry Andric * interns the result in the SymbolStringPool and returns a reference to the 144*e8d8bef9SDimitry Andric * pool entry. Clients should call LLVMOrcReleaseSymbolStringPoolEntry to 145*e8d8bef9SDimitry Andric * decrement the ref-count on the pool entry once they are finished with this 146*e8d8bef9SDimitry Andric * value. 147*e8d8bef9SDimitry Andric */ 148*e8d8bef9SDimitry Andric LLVMOrcSymbolStringPoolEntryRef 149*e8d8bef9SDimitry Andric LLVMOrcLLJITMangleAndIntern(LLVMOrcLLJITRef J, const char *UnmangledName); 150*e8d8bef9SDimitry Andric 151*e8d8bef9SDimitry Andric /** 152*e8d8bef9SDimitry Andric * Add a buffer representing an object file to the given JITDylib in the given 153*e8d8bef9SDimitry Andric * LLJIT instance. This operation transfers ownership of the buffer to the 154*e8d8bef9SDimitry Andric * LLJIT instance. The buffer should not be disposed of or referenced once this 155*e8d8bef9SDimitry Andric * function returns. 156*e8d8bef9SDimitry Andric * 157*e8d8bef9SDimitry Andric * Resources associated with the given object will be tracked by the given 158*e8d8bef9SDimitry Andric * JITDylib's default resource tracker. 159*e8d8bef9SDimitry Andric */ 160*e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcLLJITAddObjectFile(LLVMOrcLLJITRef J, LLVMOrcJITDylibRef JD, 161*e8d8bef9SDimitry Andric LLVMMemoryBufferRef ObjBuffer); 162*e8d8bef9SDimitry Andric 163*e8d8bef9SDimitry Andric /** 164*e8d8bef9SDimitry Andric * Add a buffer representing an object file to the given ResourceTracker's 165*e8d8bef9SDimitry Andric * JITDylib in the given LLJIT instance. This operation transfers ownership of 166*e8d8bef9SDimitry Andric * the buffer to the LLJIT instance. The buffer should not be disposed of or 167*e8d8bef9SDimitry Andric * referenced once this function returns. 168*e8d8bef9SDimitry Andric * 169*e8d8bef9SDimitry Andric * Resources associated with the given object will be tracked by ResourceTracker 170*e8d8bef9SDimitry Andric * RT. 171*e8d8bef9SDimitry Andric */ 172*e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcLLJITAddObjectFileWithRT(LLVMOrcLLJITRef J, 173*e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef RT, 174*e8d8bef9SDimitry Andric LLVMMemoryBufferRef ObjBuffer); 175*e8d8bef9SDimitry Andric 176*e8d8bef9SDimitry Andric /** 177*e8d8bef9SDimitry Andric * Add an IR module to the given JITDylib in the given LLJIT instance. This 178*e8d8bef9SDimitry Andric * operation transfers ownership of the TSM argument to the LLJIT instance. 179*e8d8bef9SDimitry Andric * The TSM argument should not be disposed of or referenced once this 180*e8d8bef9SDimitry Andric * function returns. 181*e8d8bef9SDimitry Andric * 182*e8d8bef9SDimitry Andric * Resources associated with the given Module will be tracked by the given 183*e8d8bef9SDimitry Andric * JITDylib's default resource tracker. 184*e8d8bef9SDimitry Andric */ 185*e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcLLJITAddLLVMIRModule(LLVMOrcLLJITRef J, 186*e8d8bef9SDimitry Andric LLVMOrcJITDylibRef JD, 187*e8d8bef9SDimitry Andric LLVMOrcThreadSafeModuleRef TSM); 188*e8d8bef9SDimitry Andric 189*e8d8bef9SDimitry Andric /** 190*e8d8bef9SDimitry Andric * Add an IR module to the given ResourceTracker's JITDylib in the given LLJIT 191*e8d8bef9SDimitry Andric * instance. This operation transfers ownership of the TSM argument to the LLJIT 192*e8d8bef9SDimitry Andric * instance. The TSM argument should not be disposed of or referenced once this 193*e8d8bef9SDimitry Andric * function returns. 194*e8d8bef9SDimitry Andric * 195*e8d8bef9SDimitry Andric * Resources associated with the given Module will be tracked by ResourceTracker 196*e8d8bef9SDimitry Andric * RT. 197*e8d8bef9SDimitry Andric */ 198*e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcLLJITAddLLVMIRModuleWithRT(LLVMOrcLLJITRef J, 199*e8d8bef9SDimitry Andric LLVMOrcResourceTrackerRef JD, 200*e8d8bef9SDimitry Andric LLVMOrcThreadSafeModuleRef TSM); 201*e8d8bef9SDimitry Andric 202*e8d8bef9SDimitry Andric /** 203*e8d8bef9SDimitry Andric * Look up the given symbol in the main JITDylib of the given LLJIT instance. 204*e8d8bef9SDimitry Andric * 205*e8d8bef9SDimitry Andric * This operation does not take ownership of the Name argument. 206*e8d8bef9SDimitry Andric */ 207*e8d8bef9SDimitry Andric LLVMErrorRef LLVMOrcLLJITLookup(LLVMOrcLLJITRef J, 208*e8d8bef9SDimitry Andric LLVMOrcJITTargetAddress *Result, 209*e8d8bef9SDimitry Andric const char *Name); 210*e8d8bef9SDimitry Andric 211*e8d8bef9SDimitry Andric LLVM_C_EXTERN_C_END 212*e8d8bef9SDimitry Andric 213*e8d8bef9SDimitry Andric #endif /* LLVM_C_LLJIT_H */ 214