OrcEE.h 4.6 KB

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