Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:54

0001 //===-- ObjectLinkingLayer.h - JITLink-based jit linking layer --*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Contains the definition for an JITLink-based, in-process object linking
0010 // layer.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
0015 #define LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
0016 
0017 #include "llvm/ADT/STLExtras.h"
0018 #include "llvm/ADT/StringRef.h"
0019 #include "llvm/ExecutionEngine/Orc/Core.h"
0020 #include "llvm/ExecutionEngine/Orc/Layer.h"
0021 #include "llvm/ExecutionEngine/Orc/LinkGraphLinkingLayer.h"
0022 #include "llvm/Support/Error.h"
0023 
0024 #include <memory>
0025 
0026 namespace llvm {
0027 
0028 namespace jitlink {
0029 class EHFrameRegistrar;
0030 class LinkGraph;
0031 class Symbol;
0032 } // namespace jitlink
0033 
0034 namespace orc {
0035 
0036 /// An ObjectLayer implementation built on JITLink.
0037 ///
0038 /// Clients can use this class to add relocatable object files to an
0039 /// ExecutionSession, and it typically serves as the base layer (underneath
0040 /// a compiling layer like IRCompileLayer) for the rest of the JIT.
0041 class ObjectLinkingLayer : public LinkGraphLinkingLayer,
0042                            public RTTIExtends<ObjectLinkingLayer, ObjectLayer> {
0043 private:
0044   using BaseObjectLayer = RTTIExtends<ObjectLinkingLayer, ObjectLayer>;
0045 
0046 public:
0047   static char ID;
0048 
0049   using ReturnObjectBufferFunction =
0050       std::function<void(std::unique_ptr<MemoryBuffer>)>;
0051 
0052   /// Construct an ObjectLinkingLayer using the ExecutorProcessControl
0053   /// instance's memory manager.
0054   ObjectLinkingLayer(ExecutionSession &ES)
0055       : LinkGraphLinkingLayer(ES), BaseObjectLayer(ES) {}
0056 
0057   /// Construct an ObjectLinkingLayer using a custom memory manager.
0058   ObjectLinkingLayer(ExecutionSession &ES,
0059                      jitlink::JITLinkMemoryManager &MemMgr)
0060       : LinkGraphLinkingLayer(ES, MemMgr), BaseObjectLayer(ES) {}
0061 
0062   /// Construct an ObjectLinkingLayer. Takes ownership of the given
0063   /// JITLinkMemoryManager. This method is a temporary hack to simplify
0064   /// co-existence with RTDyldObjectLinkingLayer (which also owns its
0065   /// allocators).
0066   ObjectLinkingLayer(ExecutionSession &ES,
0067                      std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr)
0068       : LinkGraphLinkingLayer(ES, std::move(MemMgr)), BaseObjectLayer(ES) {}
0069 
0070   using LinkGraphLinkingLayer::getExecutionSession;
0071 
0072   /// Set an object buffer return function. By default object buffers are
0073   /// deleted once the JIT has linked them. If a return function is set then
0074   /// it will be called to transfer ownership of the buffer instead.
0075   void setReturnObjectBuffer(ReturnObjectBufferFunction ReturnObjectBuffer) {
0076     this->ReturnObjectBuffer = std::move(ReturnObjectBuffer);
0077   }
0078 
0079   using LinkGraphLinkingLayer::add;
0080   using LinkGraphLinkingLayer::emit;
0081 
0082   using ObjectLayer::add;
0083 
0084   /// Emit an object file.
0085   void emit(std::unique_ptr<MaterializationResponsibility> R,
0086             std::unique_ptr<MemoryBuffer> O) override;
0087 };
0088 
0089 } // end namespace orc
0090 } // end namespace llvm
0091 
0092 #endif // LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H