LLVM 20.0.0git
ObjectLinkingLayer.h
Go to the documentation of this file.
1//===-- ObjectLinkingLayer.h - JITLink-based jit linking layer --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Contains the definition for an JITLink-based, in-process object linking
10// layer.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
15#define LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
16
17#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/Error.h"
23
24#include <memory>
25
26namespace llvm {
27
28namespace jitlink {
29class EHFrameRegistrar;
30class LinkGraph;
31class Symbol;
32} // namespace jitlink
33
34namespace orc {
35
36/// An ObjectLayer implementation built on JITLink.
37///
38/// Clients can use this class to add relocatable object files to an
39/// ExecutionSession, and it typically serves as the base layer (underneath
40/// a compiling layer like IRCompileLayer) for the rest of the JIT.
42 public RTTIExtends<ObjectLinkingLayer, ObjectLayer> {
43private:
45
46public:
47 static char ID;
48
50 std::function<void(std::unique_ptr<MemoryBuffer>)>;
51
52 /// Construct an ObjectLinkingLayer using the ExecutorProcessControl
53 /// instance's memory manager.
56
57 /// Construct an ObjectLinkingLayer using a custom memory manager.
60 : LinkGraphLinkingLayer(ES, MemMgr), BaseObjectLayer(ES) {}
61
62 /// Construct an ObjectLinkingLayer. Takes ownership of the given
63 /// JITLinkMemoryManager. This method is a temporary hack to simplify
64 /// co-existence with RTDyldObjectLinkingLayer (which also owns its
65 /// allocators).
67 std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr)
68 : LinkGraphLinkingLayer(ES, std::move(MemMgr)), BaseObjectLayer(ES) {}
69
71
72 /// Set an object buffer return function. By default object buffers are
73 /// deleted once the JIT has linked them. If a return function is set then
74 /// it will be called to transfer ownership of the buffer instead.
76 this->ReturnObjectBuffer = std::move(ReturnObjectBuffer);
77 }
78
81
82 using ObjectLayer::add;
83
84 /// Emit an object file.
85 void emit(std::unique_ptr<MaterializationResponsibility> R,
86 std::unique_ptr<MemoryBuffer> O) override;
87};
88
89} // end namespace orc
90} // end namespace llvm
91
92#endif // LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
This file contains some templates that are useful if you are working with the STL at all.
Inheritance utility for extensible RTTI.
An ExecutionSession represents a running JIT program.
Definition: Core.h:1339
ExecutionSession & getExecutionSession()
virtual Error add(ResourceTrackerSP RT, std::unique_ptr< jitlink::LinkGraph > G, MaterializationUnit::Interface I)
Adds a LinkGraph to the JITDylib for the given ResourceTracker.
LinkGraphLinkingLayer links LinkGraphs into the Executor using JITLink.
void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< jitlink::LinkGraph > G) override
Emit a LinkGraph.
std::function< void(std::unique_ptr< MemoryBuffer >)> ReturnObjectBuffer
virtual Error add(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > O, MaterializationUnit::Interface I)
Adds a MaterializationUnit for the object file in the given memory buffer to the JITDylib for the giv...
Definition: Layer.cpp:170
An ObjectLayer implementation built on JITLink.
void setReturnObjectBuffer(ReturnObjectBufferFunction ReturnObjectBuffer)
Set an object buffer return function.
ObjectLinkingLayer(ExecutionSession &ES)
Construct an ObjectLinkingLayer using the ExecutorProcessControl instance's memory manager.
std::function< void(std::unique_ptr< MemoryBuffer >)> ReturnObjectBufferFunction
void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< MemoryBuffer > O) override
Emit an object file.
ObjectLinkingLayer(ExecutionSession &ES, jitlink::JITLinkMemoryManager &MemMgr)
Construct an ObjectLinkingLayer using a custom memory manager.
ObjectLinkingLayer(ExecutionSession &ES, std::unique_ptr< jitlink::JITLinkMemoryManager > MemMgr)
Construct an ObjectLinkingLayer.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858