LLVM 22.0.0git
MaterializationUnit.h
Go to the documentation of this file.
1//===---- MaterializationUnit.h -- Materialization Black Box ----*- 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// MaterializationUnit class and related types and operations.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_MATERIALIZATIONUNIT_H
14#define LLVM_EXECUTIONENGINE_ORC_MATERIALIZATIONUNIT_H
15
16#include "llvm/ADT/StringRef.h"
20
21namespace llvm::orc {
22
23class MaterializationResponsibility;
24
25/// A MaterializationUnit represents a set of symbol definitions that can
26/// be materialized as a group, or individually discarded (when
27/// overriding definitions are encountered).
28///
29/// MaterializationUnits are used when providing lazy definitions of symbols to
30/// JITDylibs. The JITDylib will call materialize when the address of a symbol
31/// is requested via the lookup method. The JITDylib will call discard if a
32/// stronger definition is added or already present.
34 friend class ExecutionSession;
35 friend class JITDylib;
36
37public:
38 static char ID;
39
40 struct Interface {
41 Interface() = default;
42 Interface(SymbolFlagsMap InitalSymbolFlags, SymbolStringPtr InitSymbol)
43 : SymbolFlags(std::move(InitalSymbolFlags)),
44 InitSymbol(std::move(InitSymbol)) {
45 assert((!this->InitSymbol || this->SymbolFlags.count(this->InitSymbol)) &&
46 "If set, InitSymbol should appear in InitialSymbolFlags map");
47 }
48
51 };
52
54 : SymbolFlags(std::move(I.SymbolFlags)),
55 InitSymbol(std::move(I.InitSymbol)) {}
56 virtual ~MaterializationUnit() = default;
57
58 /// Return the name of this materialization unit. Useful for debugging
59 /// output.
60 virtual StringRef getName() const = 0;
61
62 /// Return the set of symbols that this source provides.
63 const SymbolFlagsMap &getSymbols() const { return SymbolFlags; }
64
65 /// Returns the initialization symbol for this MaterializationUnit (if any).
66 const SymbolStringPtr &getInitializerSymbol() const { return InitSymbol; }
67
68 /// Implementations of this method should materialize all symbols
69 /// in the materialzation unit, except for those that have been
70 /// previously discarded.
71 virtual void
72 materialize(std::unique_ptr<MaterializationResponsibility> R) = 0;
73
74 /// Called by JITDylibs to notify MaterializationUnits that the given symbol
75 /// has been overridden.
76 void doDiscard(const JITDylib &JD, const SymbolStringPtr &Name) {
77 SymbolFlags.erase(Name);
78 if (InitSymbol == Name) {
79 DEBUG_WITH_TYPE("orc", {
80 dbgs() << "In " << getName() << ": discarding init symbol \""
81 << *Name << "\"\n";
82 });
83 InitSymbol = nullptr;
84 }
85 discard(JD, std::move(Name));
86 }
87
88protected:
91
92private:
93 virtual void anchor();
94
95 /// Implementations of this method should discard the given symbol
96 /// from the source (e.g. if the source is an LLVM IR Module and the
97 /// symbol is a function, delete the function body or mark it available
98 /// externally).
99 virtual void discard(const JITDylib &JD, const SymbolStringPtr &Name) = 0;
100};
101
102} // namespace llvm::orc
103
104#endif // LLVM_EXECUTIONENGINE_ORC_MATERIALIZATIONUNIT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition: Compiler.h:213
std::string Name
#define I(x, y, z)
Definition: MD5.cpp:58
static StringRef getName(Value *V)
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition: Debug.h:77
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
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
virtual StringRef getName() const =0
Return the name of this materialization unit.
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
virtual void materialize(std::unique_ptr< MaterializationResponsibility > R)=0
Implementations of this method should materialize all symbols in the materialzation unit,...
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
void doDiscard(const JITDylib &JD, const SymbolStringPtr &Name)
Called by JITDylibs to notify MaterializationUnits that the given symbol has been overridden.
virtual ~MaterializationUnit()=default
Pointer to a pooled string representing a symbol name.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
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
Interface(SymbolFlagsMap InitalSymbolFlags, SymbolStringPtr InitSymbol)