LLVM 22.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
19#include "llvm/Support/Error.h"
21
22#include <atomic>
23#include <memory>
24
25namespace llvm::orc {
26
28public:
30
31 virtual ~LinkGraphLayer();
32
34
35 /// Adds a LinkGraph to the JITDylib for the given ResourceTracker.
36 virtual Error add(ResourceTrackerSP RT, std::unique_ptr<jitlink::LinkGraph> G,
38
39 /// Adds a LinkGraph to the JITDylib for the given ResourceTracker. The
40 /// interface for the graph will be built using getLinkGraphInterface.
41 Error add(ResourceTrackerSP RT, std::unique_ptr<jitlink::LinkGraph> G) {
42 auto LGI = getInterface(*G);
43 return add(std::move(RT), std::move(G), std::move(LGI));
44 }
45
46 /// Adds a LinkGraph to the given JITDylib.
47 Error add(JITDylib &JD, std::unique_ptr<jitlink::LinkGraph> G,
49 return add(JD.getDefaultResourceTracker(), std::move(G), std::move(I));
50 }
51
52 /// Adds a LinkGraph to the given JITDylib. The interface for the object will
53 /// be built using getLinkGraphInterface.
54 Error add(JITDylib &JD, std::unique_ptr<jitlink::LinkGraph> G) {
55 return add(JD.getDefaultResourceTracker(), std::move(G));
56 }
57
58 /// Emit should materialize the given IR.
59 virtual void emit(std::unique_ptr<MaterializationResponsibility> R,
60 std::unique_ptr<jitlink::LinkGraph> G) = 0;
61
62 /// Get the interface for the given LinkGraph.
64
65 /// Get the JITSymbolFlags for the given symbol.
66 static JITSymbolFlags getJITSymbolFlagsForSymbol(jitlink::Symbol &Sym);
67
68private:
70 std::atomic<uint64_t> Counter{0};
71};
72
73/// MaterializationUnit for wrapping LinkGraphs.
75public:
77 std::unique_ptr<jitlink::LinkGraph> G,
79 : MaterializationUnit(I), LGLayer(LGLayer), G(std::move(G)) {}
80
82 std::unique_ptr<jitlink::LinkGraph> G)
83 : MaterializationUnit(LGLayer.getInterface(*G)), LGLayer(LGLayer),
84 G(std::move(G)) {}
85
86 StringRef getName() const override;
87
88 void materialize(std::unique_ptr<MaterializationResponsibility> MR) override {
89 LGLayer.emit(std::move(MR), std::move(G));
90 }
91
92private:
93 void discard(const JITDylib &JD, const SymbolStringPtr &Name) override;
94
95 LinkGraphLayer &LGLayer;
96 std::unique_ptr<jitlink::LinkGraph> G;
97};
98
100 std::unique_ptr<jitlink::LinkGraph> G,
102 auto &JD = RT->getJITDylib();
103
104 return JD.define(std::make_unique<LinkGraphMaterializationUnit>(
105 *this, std::move(G), std::move(I)),
106 std::move(RT));
107}
108
109} // end namespace llvm::orc
110
111#endif // LLVM_EXECUTIONENGINE_ORC_LINKGRAPHLAYER_H
#define LLVM_ABI
Definition: Compiler.h:213
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
static StringRef getName(Value *V)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Flags for symbols in the JIT.
Definition: JITSymbol.h:75
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
An ExecutionSession represents a running JIT program.
Definition: Core.h:1355
Represents a JIT'd dynamic library.
Definition: Core.h:902
LLVM_ABI ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
Definition: Core.cpp:671
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.
Error add(JITDylib &JD, std::unique_ptr< jitlink::LinkGraph > G)
Adds a LinkGraph to the given JITDylib.
MaterializationUnit for wrapping LinkGraphs.
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:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856