LLVM 23.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"
23#include "llvm/Support/Error.h"
24
25#include <memory>
26
27namespace llvm {
28
29namespace jitlink {
30class EHFrameRegistrar;
31class LinkGraph;
32class Symbol;
33} // namespace jitlink
34
35namespace orc {
36
37/// An ObjectLayer implementation built on JITLink.
38///
39/// Clients can use this class to add relocatable object files to an
40/// ExecutionSession, and it typically serves as the base layer (underneath
41/// a compiling layer like IRCompileLayer) for the rest of the JIT.
43 : public LinkGraphLinkingLayer,
44 public RTTIExtends<ObjectLinkingLayer, ObjectLayer> {
45private:
47
48public:
49 static char ID;
50
52 std::function<void(std::unique_ptr<MemoryBuffer>)>;
53
54 /// Construct an ObjectLinkingLayer.
57 : LinkGraphLinkingLayer(ES, MemMgr), BaseObjectLayer(ES) {}
58
59 /// Construct an ObjectLinkingLayer. Takes ownership of the given
60 /// JITLinkMemoryManager. This method is a temporary hack to simplify
61 /// co-existence with RTDyldObjectLinkingLayer (which also owns its
62 /// allocators).
64 std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr)
65 : LinkGraphLinkingLayer(ES, std::move(MemMgr)), BaseObjectLayer(ES) {}
66
68
69 /// Set an object buffer return function. By default object buffers are
70 /// deleted once the JIT has linked them. If a return function is set then
71 /// it will be called to transfer ownership of the buffer instead.
73 this->ReturnObjectBuffer = std::move(ReturnObjectBuffer);
74 }
75
78
79 using ObjectLayer::add;
80
81 /// Emit an object file.
82 void emit(std::unique_ptr<MaterializationResponsibility> R,
83 std::unique_ptr<MemoryBuffer> O) override;
84};
85
86} // end namespace orc
87} // end namespace llvm
88
89#endif // LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
#define LLVM_ABI
Definition Compiler.h:213
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:1355
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.
void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< jitlink::LinkGraph > G) override
Emit a LinkGraph.
LinkGraphLinkingLayer(ExecutionSession &ES, jitlink::JITLinkMemoryManager &MemMgr)
Construct a LinkGraphLinkingLayer.
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:171
std::function< void(std::unique_ptr< MemoryBuffer >)> ReturnObjectBufferFunction
void setReturnObjectBuffer(ReturnObjectBufferFunction ReturnObjectBuffer)
Set an object buffer return function.
ObjectLinkingLayer(ExecutionSession &ES, jitlink::JITLinkMemoryManager &MemMgr)
Construct an ObjectLinkingLayer.
ObjectLinkingLayer(ExecutionSession &ES, std::unique_ptr< jitlink::JITLinkMemoryManager > MemMgr)
Construct an ObjectLinkingLayer.
This is an optimization pass for GlobalISel generic memory operations.
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:1916
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870