LLVM  11.0.0git
OrcBindings.h
Go to the documentation of this file.
1 /*===----------- llvm-c/OrcBindings.h - Orc Lib C Iface ---------*- C++ -*-===*\
2 |* *|
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 |* Exceptions. *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This header declares the C interface to libLLVMOrcJIT.a, which implements *|
11 |* JIT compilation of LLVM IR. *|
12 |* *|
13 |* Many exotic languages can interoperate with C code but have a harder time *|
14 |* with C++ due to name mangling. So in addition to C, this interface enables *|
15 |* tools written in such languages. *|
16 |* *|
17 |* Note: This interface is experimental. It is *NOT* stable, and may be *|
18 |* changed without warning. *|
19 |* *|
20 \*===----------------------------------------------------------------------===*/
21 
22 #ifndef LLVM_C_ORCBINDINGS_H
23 #define LLVM_C_ORCBINDINGS_H
24 
25 #include "llvm-c/Error.h"
26 #include "llvm-c/ExternC.h"
27 #include "llvm-c/Object.h"
28 #include "llvm-c/TargetMachine.h"
29 
31 
32 typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
33 typedef uint64_t LLVMOrcModuleHandle;
34 typedef uint64_t LLVMOrcTargetAddress;
35 typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name, void *LookupCtx);
36 typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
37  void *CallbackCtx);
38 
39 /**
40  * Create an ORC JIT stack.
41  *
42  * The client owns the resulting stack, and must call OrcDisposeInstance(...)
43  * to destroy it and free its memory. The JIT stack will take ownership of the
44  * TargetMachine, which will be destroyed when the stack is destroyed. The
45  * client should not attempt to dispose of the Target Machine, or it will result
46  * in a double-free.
47  */
49 
50 /**
51  * Get the error message for the most recent error (if any).
52  *
53  * This message is owned by the ORC JIT Stack and will be freed when the stack
54  * is disposed of by LLVMOrcDisposeInstance.
55  */
56 const char *LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack);
57 
58 /**
59  * Mangle the given symbol.
60  * Memory will be allocated for MangledSymbol to hold the result. The client
61  */
62 void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol,
63  const char *Symbol);
64 
65 /**
66  * Dispose of a mangled symbol.
67  */
68 void LLVMOrcDisposeMangledSymbol(char *MangledSymbol);
69 
70 /**
71  * Create a lazy compile callback.
72  */
74  LLVMOrcJITStackRef JITStack, LLVMOrcTargetAddress *RetAddr,
75  LLVMOrcLazyCompileCallbackFn Callback, void *CallbackCtx);
76 
77 /**
78  * Create a named indirect call stub.
79  */
81  const char *StubName,
82  LLVMOrcTargetAddress InitAddr);
83 
84 /**
85  * Set the pointer for the given indirect stub.
86  */
88  const char *StubName,
89  LLVMOrcTargetAddress NewAddr);
90 
91 /**
92  * Add module to be eagerly compiled.
93  */
95  LLVMOrcModuleHandle *RetHandle,
96  LLVMModuleRef Mod,
97  LLVMOrcSymbolResolverFn SymbolResolver,
98  void *SymbolResolverCtx);
99 
100 /**
101  * Add module to be lazily compiled one function at a time.
102  */
104  LLVMOrcModuleHandle *RetHandle,
105  LLVMModuleRef Mod,
106  LLVMOrcSymbolResolverFn SymbolResolver,
107  void *SymbolResolverCtx);
108 
109 /**
110  * Add an object file.
111  *
112  * This method takes ownership of the given memory buffer and attempts to add
113  * it to the JIT as an object file.
114  * Clients should *not* dispose of the 'Obj' argument: the JIT will manage it
115  * from this call onwards.
116  */
118  LLVMOrcModuleHandle *RetHandle,
120  LLVMOrcSymbolResolverFn SymbolResolver,
121  void *SymbolResolverCtx);
122 
123 /**
124  * Remove a module set from the JIT.
125  *
126  * This works for all modules that can be added via OrcAdd*, including object
127  * files.
128  */
131 
132 /**
133  * Get symbol address from JIT instance.
134  */
136  LLVMOrcTargetAddress *RetAddr,
137  const char *SymbolName);
138 
139 /**
140  * Get symbol address from JIT instance, searching only the specified
141  * handle.
142  */
144  LLVMOrcTargetAddress *RetAddr,
146  const char *SymbolName);
147 
148 /**
149  * Dispose of an ORC JIT stack.
150  */
152 
153 /**
154  * Register a JIT Event Listener.
155  *
156  * A NULL listener is ignored.
157  */
159 
160 /**
161  * Unegister a JIT Event Listener.
162  *
163  * A NULL listener is ignored.
164  */
166 
168 
169 #endif /* LLVM_C_ORCBINDINGS_H */
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM)
Create an ORC JIT stack.
LLVMErrorRef LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack, const char *StubName, LLVMOrcTargetAddress NewAddr)
Set the pointer for the given indirect stub.
LLVMErrorRef LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle *RetHandle, LLVMMemoryBufferRef Obj, LLVMOrcSymbolResolverFn SymbolResolver, void *SymbolResolverCtx)
Add an object file.
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
Definition: Types.h:48
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void LLVMOrcRegisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L)
Register a JIT Event Listener.
typedefLLVM_C_EXTERN_C_BEGIN struct LLVMOrcOpaqueJITStack * LLVMOrcJITStackRef
Definition: OrcBindings.h:32
LLVMErrorRef LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack, LLVMOrcTargetAddress *RetAddr, LLVMOrcModuleHandle H, const char *SymbolName)
Get symbol address from JIT instance, searching only the specified handle.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
void LLVMOrcDisposeMangledSymbol(char *MangledSymbol)
Dispose of a mangled symbol.
LLVMErrorRef LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle *RetHandle, LLVMModuleRef Mod, LLVMOrcSymbolResolverFn SymbolResolver, void *SymbolResolverCtx)
Add module to be lazily compiled one function at a time.
LLVMErrorRef LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H)
Remove a module set from the JIT.
uint64_t LLVMOrcTargetAddress
Definition: OrcBindings.h:34
struct LLVMOpaqueError * LLVMErrorRef
Opaque reference to an error instance.
Definition: Error.h:26
void LLVMOrcUnregisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L)
Unegister a JIT Event Listener.
LLVMErrorRef LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack, LLVMOrcTargetAddress *RetAddr, LLVMOrcLazyCompileCallbackFn Callback, void *CallbackCtx)
Create a lazy compile callback.
void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol, const char *Symbol)
Mangle the given symbol.
#define H(x, y, z)
Definition: MD5.cpp:58
typedefLLVM_C_EXTERN_C_BEGIN struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
Definition: TargetMachine.h:28
uint64_t LLVMOrcModuleHandle
Definition: OrcBindings.h:33
uint64_t(* LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack, void *CallbackCtx)
Definition: OrcBindings.h:36
LLVMErrorRef LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle *RetHandle, LLVMModuleRef Mod, LLVMOrcSymbolResolverFn SymbolResolver, void *SymbolResolverCtx)
Add module to be eagerly compiled.
LLVMErrorRef LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack, const char *StubName, LLVMOrcTargetAddress InitAddr)
Create a named indirect call stub.
uint64_t(* LLVMOrcSymbolResolverFn)(const char *Name, void *LookupCtx)
Definition: OrcBindings.h:35
LLVMErrorRef LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack)
Dispose of an ORC JIT stack.
LLVMErrorRef LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack, LLVMOrcTargetAddress *RetAddr, const char *SymbolName)
Get symbol address from JIT instance.
#define LLVM_C_EXTERN_C_END
Definition: ExternC.h:36
#define LLVM_C_EXTERN_C_BEGIN
Definition: ExternC.h:35
const char * LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack)
Get the error message for the most recent error (if any).
struct LLVMOpaqueJITEventListener * LLVMJITEventListenerRef
Definition: Types.h:163