xref: /freebsd-src/contrib/llvm-project/llvm/include/llvm-c/OrcEE.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1e8d8bef9SDimitry Andric /*===-- llvm-c/OrcEE.h - OrcV2 C bindings ExecutionEngine utils -*- C++ -*-===*\
2e8d8bef9SDimitry Andric |*                                                                            *|
3e8d8bef9SDimitry Andric |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
4e8d8bef9SDimitry Andric |* Exceptions.                                                                *|
5e8d8bef9SDimitry Andric |* See https://llvm.org/LICENSE.txt for license information.                  *|
6e8d8bef9SDimitry Andric |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
7e8d8bef9SDimitry Andric |*                                                                            *|
8e8d8bef9SDimitry Andric |*===----------------------------------------------------------------------===*|
9e8d8bef9SDimitry Andric |*                                                                            *|
10e8d8bef9SDimitry Andric |* This header declares the C interface to ExecutionEngine based utils, e.g.  *|
11e8d8bef9SDimitry Andric |* RTDyldObjectLinkingLayer (based on RuntimeDyld) in Orc.                    *|
12e8d8bef9SDimitry Andric |*                                                                            *|
13e8d8bef9SDimitry Andric |* Many exotic languages can interoperate with C code but have a harder time  *|
14e8d8bef9SDimitry Andric |* with C++ due to name mangling. So in addition to C, this interface enables *|
15e8d8bef9SDimitry Andric |* tools written in such languages.                                           *|
16e8d8bef9SDimitry Andric |*                                                                            *|
17e8d8bef9SDimitry Andric |* Note: This interface is experimental. It is *NOT* stable, and may be       *|
18e8d8bef9SDimitry Andric |*       changed without warning. Only C API usage documentation is           *|
19e8d8bef9SDimitry Andric |*       provided. See the C++ documentation for all higher level ORC API     *|
20e8d8bef9SDimitry Andric |*       details.                                                             *|
21e8d8bef9SDimitry Andric |*                                                                            *|
22e8d8bef9SDimitry Andric \*===----------------------------------------------------------------------===*/
23e8d8bef9SDimitry Andric 
24e8d8bef9SDimitry Andric #ifndef LLVM_C_ORCEE_H
25e8d8bef9SDimitry Andric #define LLVM_C_ORCEE_H
26e8d8bef9SDimitry Andric 
27e8d8bef9SDimitry Andric #include "llvm-c/Error.h"
28e8d8bef9SDimitry Andric #include "llvm-c/ExecutionEngine.h"
29e8d8bef9SDimitry Andric #include "llvm-c/Orc.h"
30e8d8bef9SDimitry Andric #include "llvm-c/TargetMachine.h"
31e8d8bef9SDimitry Andric #include "llvm-c/Types.h"
32e8d8bef9SDimitry Andric 
33e8d8bef9SDimitry Andric LLVM_C_EXTERN_C_BEGIN
34e8d8bef9SDimitry Andric 
35*bdd1243dSDimitry Andric typedef void *(*LLVMMemoryManagerCreateContextCallback)(void *CtxCtx);
36*bdd1243dSDimitry Andric typedef void (*LLVMMemoryManagerNotifyTerminatingCallback)(void *CtxCtx);
37*bdd1243dSDimitry Andric 
38e8d8bef9SDimitry Andric /**
39349cc55cSDimitry Andric  * @defgroup LLVMCExecutionEngineORCEE ExecutionEngine-based ORC Utils
40349cc55cSDimitry Andric  * @ingroup LLVMCExecutionEngine
41349cc55cSDimitry Andric  *
42349cc55cSDimitry Andric  * @{
43349cc55cSDimitry Andric  */
44349cc55cSDimitry Andric 
45349cc55cSDimitry Andric /**
46e8d8bef9SDimitry Andric  * Create a RTDyldObjectLinkingLayer instance using the standard
47e8d8bef9SDimitry Andric  * SectionMemoryManager for memory management.
48e8d8bef9SDimitry Andric  */
49e8d8bef9SDimitry Andric LLVMOrcObjectLayerRef
50e8d8bef9SDimitry Andric LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(
51e8d8bef9SDimitry Andric     LLVMOrcExecutionSessionRef ES);
52e8d8bef9SDimitry Andric 
53e8d8bef9SDimitry Andric /**
54*bdd1243dSDimitry Andric  * Create a RTDyldObjectLinkingLayer instance using MCJIT-memory-manager-like
55*bdd1243dSDimitry Andric  * callbacks.
56*bdd1243dSDimitry Andric  *
57*bdd1243dSDimitry Andric  * This is intended to simplify transitions for existing MCJIT clients. The
58*bdd1243dSDimitry Andric  * callbacks used are similar (but not identical) to the callbacks for
59*bdd1243dSDimitry Andric  * LLVMCreateSimpleMCJITMemoryManager: Unlike MCJIT, RTDyldObjectLinkingLayer
60*bdd1243dSDimitry Andric  * will create a new memory manager for each object linked by calling the given
61*bdd1243dSDimitry Andric  * CreateContext callback. This allows for code removal by destroying each
62*bdd1243dSDimitry Andric  * allocator individually. Every allocator will be destroyed (if it has not been
63*bdd1243dSDimitry Andric  * already) at RTDyldObjectLinkingLayer destruction time, and the
64*bdd1243dSDimitry Andric  * NotifyTerminating callback will be called to indicate that no further
65*bdd1243dSDimitry Andric  * allocation contexts will be created.
66*bdd1243dSDimitry Andric  *
67*bdd1243dSDimitry Andric  * To implement MCJIT-like behavior clients can implement CreateContext,
68*bdd1243dSDimitry Andric  * NotifyTerminating, and Destroy as:
69*bdd1243dSDimitry Andric  *
70*bdd1243dSDimitry Andric  *   void *CreateContext(void *CtxCtx) { return CtxCtx; }
71*bdd1243dSDimitry Andric  *   void NotifyTerminating(void *CtxCtx) { MyOriginalDestroy(CtxCtx); }
72*bdd1243dSDimitry Andric  *   void Destroy(void *Ctx) { }
73*bdd1243dSDimitry Andric  *
74*bdd1243dSDimitry Andric  * This scheme simply reuses the CreateContextCtx pointer as the one-and-only
75*bdd1243dSDimitry Andric  * allocation context.
76*bdd1243dSDimitry Andric  */
77*bdd1243dSDimitry Andric LLVMOrcObjectLayerRef
78*bdd1243dSDimitry Andric LLVMOrcCreateRTDyldObjectLinkingLayerWithMCJITMemoryManagerLikeCallbacks(
79*bdd1243dSDimitry Andric     LLVMOrcExecutionSessionRef ES, void *CreateContextCtx,
80*bdd1243dSDimitry Andric     LLVMMemoryManagerCreateContextCallback CreateContext,
81*bdd1243dSDimitry Andric     LLVMMemoryManagerNotifyTerminatingCallback NotifyTerminating,
82*bdd1243dSDimitry Andric     LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
83*bdd1243dSDimitry Andric     LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
84*bdd1243dSDimitry Andric     LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
85*bdd1243dSDimitry Andric     LLVMMemoryManagerDestroyCallback Destroy);
86*bdd1243dSDimitry Andric 
87*bdd1243dSDimitry Andric /**
88e8d8bef9SDimitry Andric  * Add the given listener to the given RTDyldObjectLinkingLayer.
89e8d8bef9SDimitry Andric  *
90e8d8bef9SDimitry Andric  * Note: Layer must be an RTDyldObjectLinkingLayer instance or
91e8d8bef9SDimitry Andric  * behavior is undefined.
92e8d8bef9SDimitry Andric  */
93e8d8bef9SDimitry Andric void LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(
94e8d8bef9SDimitry Andric     LLVMOrcObjectLayerRef RTDyldObjLinkingLayer,
95e8d8bef9SDimitry Andric     LLVMJITEventListenerRef Listener);
96e8d8bef9SDimitry Andric 
97349cc55cSDimitry Andric /**
98349cc55cSDimitry Andric  * @}
99349cc55cSDimitry Andric  */
100349cc55cSDimitry Andric 
101e8d8bef9SDimitry Andric LLVM_C_EXTERN_C_END
102e8d8bef9SDimitry Andric 
103e8d8bef9SDimitry Andric #endif /* LLVM_C_ORCEE_H */
104