xref: /aosp_15_r20/external/llvm/include/llvm-c/OrcBindings.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker /*===----------- llvm-c/OrcBindings.h - Orc Lib C Iface ---------*- C++ -*-===*\
2*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
3*9880d681SAndroid Build Coastguard Worker |*                     The LLVM Compiler Infrastructure                       *|
4*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
5*9880d681SAndroid Build Coastguard Worker |* This file is distributed under the University of Illinois Open Source      *|
6*9880d681SAndroid Build Coastguard Worker |* License. See LICENSE.TXT for details.                                      *|
7*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
8*9880d681SAndroid Build Coastguard Worker |*===----------------------------------------------------------------------===*|
9*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
10*9880d681SAndroid Build Coastguard Worker |* This header declares the C interface to libLLVMOrcJIT.a, which implements  *|
11*9880d681SAndroid Build Coastguard Worker |* JIT compilation of LLVM IR.                                                *|
12*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
13*9880d681SAndroid Build Coastguard Worker |* Many exotic languages can interoperate with C code but have a harder time  *|
14*9880d681SAndroid Build Coastguard Worker |* with C++ due to name mangling. So in addition to C, this interface enables *|
15*9880d681SAndroid Build Coastguard Worker |* tools written in such languages.                                           *|
16*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
17*9880d681SAndroid Build Coastguard Worker |* Note: This interface is experimental. It is *NOT* stable, and may be       *|
18*9880d681SAndroid Build Coastguard Worker |*       changed without warning.                                             *|
19*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
20*9880d681SAndroid Build Coastguard Worker \*===----------------------------------------------------------------------===*/
21*9880d681SAndroid Build Coastguard Worker 
22*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_C_ORCBINDINGS_H
23*9880d681SAndroid Build Coastguard Worker #define LLVM_C_ORCBINDINGS_H
24*9880d681SAndroid Build Coastguard Worker 
25*9880d681SAndroid Build Coastguard Worker #include "llvm-c/Object.h"
26*9880d681SAndroid Build Coastguard Worker #include "llvm-c/TargetMachine.h"
27*9880d681SAndroid Build Coastguard Worker 
28*9880d681SAndroid Build Coastguard Worker #ifdef __cplusplus
29*9880d681SAndroid Build Coastguard Worker extern "C" {
30*9880d681SAndroid Build Coastguard Worker #endif
31*9880d681SAndroid Build Coastguard Worker 
32*9880d681SAndroid Build Coastguard Worker typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
33*9880d681SAndroid Build Coastguard Worker typedef uint32_t LLVMOrcModuleHandle;
34*9880d681SAndroid Build Coastguard Worker typedef uint64_t LLVMOrcTargetAddress;
35*9880d681SAndroid Build Coastguard Worker typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name, void *LookupCtx);
36*9880d681SAndroid Build Coastguard Worker typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
37*9880d681SAndroid Build Coastguard Worker                                                  void *CallbackCtx);
38*9880d681SAndroid Build Coastguard Worker 
39*9880d681SAndroid Build Coastguard Worker typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode;
40*9880d681SAndroid Build Coastguard Worker 
41*9880d681SAndroid Build Coastguard Worker /**
42*9880d681SAndroid Build Coastguard Worker  * Create an ORC JIT stack.
43*9880d681SAndroid Build Coastguard Worker  *
44*9880d681SAndroid Build Coastguard Worker  * The client owns the resulting stack, and must call OrcDisposeInstance(...)
45*9880d681SAndroid Build Coastguard Worker  * to destroy it and free its memory. The JIT stack will take ownership of the
46*9880d681SAndroid Build Coastguard Worker  * TargetMachine, which will be destroyed when the stack is destroyed. The
47*9880d681SAndroid Build Coastguard Worker  * client should not attempt to dispose of the Target Machine, or it will result
48*9880d681SAndroid Build Coastguard Worker  * in a double-free.
49*9880d681SAndroid Build Coastguard Worker  */
50*9880d681SAndroid Build Coastguard Worker LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM);
51*9880d681SAndroid Build Coastguard Worker 
52*9880d681SAndroid Build Coastguard Worker /**
53*9880d681SAndroid Build Coastguard Worker  * Get the error message for the most recent error (if any).
54*9880d681SAndroid Build Coastguard Worker  *
55*9880d681SAndroid Build Coastguard Worker  * This message is owned by the ORC JIT Stack and will be freed when the stack
56*9880d681SAndroid Build Coastguard Worker  * is disposed of by LLVMOrcDisposeInstance.
57*9880d681SAndroid Build Coastguard Worker  */
58*9880d681SAndroid Build Coastguard Worker const char *LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack);
59*9880d681SAndroid Build Coastguard Worker 
60*9880d681SAndroid Build Coastguard Worker /**
61*9880d681SAndroid Build Coastguard Worker  * Mangle the given symbol.
62*9880d681SAndroid Build Coastguard Worker  * Memory will be allocated for MangledSymbol to hold the result. The client
63*9880d681SAndroid Build Coastguard Worker  */
64*9880d681SAndroid Build Coastguard Worker void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol,
65*9880d681SAndroid Build Coastguard Worker                              const char *Symbol);
66*9880d681SAndroid Build Coastguard Worker 
67*9880d681SAndroid Build Coastguard Worker /**
68*9880d681SAndroid Build Coastguard Worker  * Dispose of a mangled symbol.
69*9880d681SAndroid Build Coastguard Worker  */
70*9880d681SAndroid Build Coastguard Worker void LLVMOrcDisposeMangledSymbol(char *MangledSymbol);
71*9880d681SAndroid Build Coastguard Worker 
72*9880d681SAndroid Build Coastguard Worker /**
73*9880d681SAndroid Build Coastguard Worker  * Create a lazy compile callback.
74*9880d681SAndroid Build Coastguard Worker  */
75*9880d681SAndroid Build Coastguard Worker LLVMOrcTargetAddress
76*9880d681SAndroid Build Coastguard Worker LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack,
77*9880d681SAndroid Build Coastguard Worker                                  LLVMOrcLazyCompileCallbackFn Callback,
78*9880d681SAndroid Build Coastguard Worker                                  void *CallbackCtx);
79*9880d681SAndroid Build Coastguard Worker 
80*9880d681SAndroid Build Coastguard Worker /**
81*9880d681SAndroid Build Coastguard Worker  * Create a named indirect call stub.
82*9880d681SAndroid Build Coastguard Worker  */
83*9880d681SAndroid Build Coastguard Worker LLVMOrcErrorCode LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
84*9880d681SAndroid Build Coastguard Worker                                            const char *StubName,
85*9880d681SAndroid Build Coastguard Worker                                            LLVMOrcTargetAddress InitAddr);
86*9880d681SAndroid Build Coastguard Worker 
87*9880d681SAndroid Build Coastguard Worker /**
88*9880d681SAndroid Build Coastguard Worker  * Set the pointer for the given indirect stub.
89*9880d681SAndroid Build Coastguard Worker  */
90*9880d681SAndroid Build Coastguard Worker LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
91*9880d681SAndroid Build Coastguard Worker                                                const char *StubName,
92*9880d681SAndroid Build Coastguard Worker                                                LLVMOrcTargetAddress NewAddr);
93*9880d681SAndroid Build Coastguard Worker 
94*9880d681SAndroid Build Coastguard Worker /**
95*9880d681SAndroid Build Coastguard Worker  * Add module to be eagerly compiled.
96*9880d681SAndroid Build Coastguard Worker  */
97*9880d681SAndroid Build Coastguard Worker LLVMOrcModuleHandle
98*9880d681SAndroid Build Coastguard Worker LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
99*9880d681SAndroid Build Coastguard Worker                             LLVMOrcSymbolResolverFn SymbolResolver,
100*9880d681SAndroid Build Coastguard Worker                             void *SymbolResolverCtx);
101*9880d681SAndroid Build Coastguard Worker 
102*9880d681SAndroid Build Coastguard Worker /**
103*9880d681SAndroid Build Coastguard Worker  * Add module to be lazily compiled one function at a time.
104*9880d681SAndroid Build Coastguard Worker  */
105*9880d681SAndroid Build Coastguard Worker LLVMOrcModuleHandle
106*9880d681SAndroid Build Coastguard Worker LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
107*9880d681SAndroid Build Coastguard Worker                            LLVMOrcSymbolResolverFn SymbolResolver,
108*9880d681SAndroid Build Coastguard Worker                            void *SymbolResolverCtx);
109*9880d681SAndroid Build Coastguard Worker 
110*9880d681SAndroid Build Coastguard Worker /**
111*9880d681SAndroid Build Coastguard Worker  * Add an object file.
112*9880d681SAndroid Build Coastguard Worker  */
113*9880d681SAndroid Build Coastguard Worker LLVMOrcModuleHandle LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
114*9880d681SAndroid Build Coastguard Worker                                          LLVMObjectFileRef Obj,
115*9880d681SAndroid Build Coastguard Worker                                          LLVMOrcSymbolResolverFn SymbolResolver,
116*9880d681SAndroid Build Coastguard Worker                                          void *SymbolResolverCtx);
117*9880d681SAndroid Build Coastguard Worker 
118*9880d681SAndroid Build Coastguard Worker /**
119*9880d681SAndroid Build Coastguard Worker  * Remove a module set from the JIT.
120*9880d681SAndroid Build Coastguard Worker  *
121*9880d681SAndroid Build Coastguard Worker  * This works for all modules that can be added via OrcAdd*, including object
122*9880d681SAndroid Build Coastguard Worker  * files.
123*9880d681SAndroid Build Coastguard Worker  */
124*9880d681SAndroid Build Coastguard Worker void LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H);
125*9880d681SAndroid Build Coastguard Worker 
126*9880d681SAndroid Build Coastguard Worker /**
127*9880d681SAndroid Build Coastguard Worker  * Get symbol address from JIT instance.
128*9880d681SAndroid Build Coastguard Worker  */
129*9880d681SAndroid Build Coastguard Worker LLVMOrcTargetAddress LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
130*9880d681SAndroid Build Coastguard Worker                                              const char *SymbolName);
131*9880d681SAndroid Build Coastguard Worker 
132*9880d681SAndroid Build Coastguard Worker /**
133*9880d681SAndroid Build Coastguard Worker  * Dispose of an ORC JIT stack.
134*9880d681SAndroid Build Coastguard Worker  */
135*9880d681SAndroid Build Coastguard Worker void LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
136*9880d681SAndroid Build Coastguard Worker 
137*9880d681SAndroid Build Coastguard Worker #ifdef __cplusplus
138*9880d681SAndroid Build Coastguard Worker }
139*9880d681SAndroid Build Coastguard Worker #endif /* extern "C" */
140*9880d681SAndroid Build Coastguard Worker 
141*9880d681SAndroid Build Coastguard Worker #endif /* LLVM_C_ORCBINDINGS_H */
142