LLVM 20.0.0git
LinkGraphLayer.h
Go to the documentation of this file.
1//===- LinkGraphLayer.h - Add LinkGraphs to an ExecutionSession -*- 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// LinkGraphLayer and associated utilities.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_LINKGRAPHLAYER_H
14#define LLVM_EXECUTIONENGINE_ORC_LINKGRAPHLAYER_H
15
18#include "llvm/Support/Error.h"
20
21#include <atomic>
22#include <memory>
23
24namespace llvm::orc {
25
27public:
29
30 virtual ~LinkGraphLayer();
31
33
34 /// Adds a LinkGraph to the JITDylib for the given ResourceTracker.
35 virtual Error add(ResourceTrackerSP RT, std::unique_ptr<jitlink::LinkGraph> G,
37
38 /// Adds a LinkGraph to the JITDylib for the given ResourceTracker. The
39 /// interface for the graph will be built using getLinkGraphInterface.
40 Error add(ResourceTrackerSP RT, std::unique_ptr<jitlink::LinkGraph> G) {
41 auto LGI = getInterface(*G);
42 return add(std::move(RT), std::move(G), std::move(LGI));
43 }
44
45 /// Adds a LinkGraph to the given JITDylib.
46 Error add(JITDylib &JD, std::unique_ptr<jitlink::LinkGraph> G,
48 return add(JD.getDefaultResourceTracker(), std::move(G), std::move(I));
49 }
50
51 /// Adds a LinkGraph to the given JITDylib. The interface for the object will
52 /// be built using getLinkGraphInterface.
53 Error add(JITDylib &JD, std::unique_ptr<jitlink::LinkGraph> G) {
54 return add(JD.getDefaultResourceTracker(), std::move(G));
55 }
56
57 /// Emit should materialize the given IR.
58 virtual void emit(std::unique_ptr<MaterializationResponsibility> R,
59 std::unique_ptr<jitlink::LinkGraph> G) = 0;
60
61 /// Get the interface for the given LinkGraph.
63
64 /// Get the JITSymbolFlags for the given symbol.
66
67private:
69 std::atomic<uint64_t> Counter{0};
70};
71
72/// MaterializationUnit for wrapping LinkGraphs.
74public:
76 std::unique_ptr<jitlink::LinkGraph> G,
78 : MaterializationUnit(I), LGLayer(LGLayer), G(std::move(G)) {}
79
81 std::unique_ptr<jitlink::LinkGraph> G)
82 : MaterializationUnit(LGLayer.getInterface(*G)), LGLayer(LGLayer),
83 G(std::move(G)) {}
84
85 StringRef getName() const override;
86
87 void materialize(std::unique_ptr<MaterializationResponsibility> MR) override {
88 LGLayer.emit(std::move(MR), std::move(G));
89 }
90
91private:
92 void discard(const JITDylib &JD, const SymbolStringPtr &Name) override;
93
94 LinkGraphLayer &LGLayer;
95 std::unique_ptr<jitlink::LinkGraph> G;
96};
97
99 std::unique_ptr<jitlink::LinkGraph> G,
101 auto &JD = RT->getJITDylib();
102
103 return JD.define(std::make_unique<LinkGraphMaterializationUnit>(
104 *this, std::move(G), std::move(I)),
105 std::move(RT));
106}
107
108} // end namespace llvm::orc
109
110#endif // LLVM_EXECUTIONENGINE_ORC_LINKGRAPHLAYER_H
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Flags for symbols in the JIT.
Definition: JITSymbol.h:74
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
An ExecutionSession represents a running JIT program.
Definition: Core.h:1339
Represents a JIT'd dynamic library.
Definition: Core.h:897
ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
Definition: Core.cpp:672
LinkGraphLayer(ExecutionSession &ES)
ExecutionSession & getExecutionSession()
Error add(JITDylib &JD, std::unique_ptr< jitlink::LinkGraph > G, MaterializationUnit::Interface I)
Adds a LinkGraph to the given JITDylib.
virtual Error add(ResourceTrackerSP RT, std::unique_ptr< jitlink::LinkGraph > G, MaterializationUnit::Interface I)
Adds a LinkGraph to the JITDylib for the given ResourceTracker.
virtual void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< jitlink::LinkGraph > G)=0
Emit should materialize the given IR.
Error add(ResourceTrackerSP RT, std::unique_ptr< jitlink::LinkGraph > G)
Adds a LinkGraph to the JITDylib for the given ResourceTracker.
MaterializationUnit::Interface getInterface(jitlink::LinkGraph &G)
Get the interface for the given LinkGraph.
static JITSymbolFlags getJITSymbolFlagsForSymbol(jitlink::Symbol &Sym)
Get the JITSymbolFlags for the given symbol.
Error add(JITDylib &JD, std::unique_ptr< jitlink::LinkGraph > G)
Adds a LinkGraph to the given JITDylib.
MaterializationUnit for wrapping LinkGraphs.
StringRef getName() const override
Return the name of this materialization unit.
LinkGraphMaterializationUnit(LinkGraphLayer &LGLayer, std::unique_ptr< jitlink::LinkGraph > G)
void materialize(std::unique_ptr< MaterializationResponsibility > MR) override
Implementations of this method should materialize all symbols in the materialzation unit,...
LinkGraphMaterializationUnit(LinkGraphLayer &LGLayer, std::unique_ptr< jitlink::LinkGraph > G, Interface I)
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Pointer to a pooled string representing a symbol name.
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