LLVM 20.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"
19
20namespace llvm::orc {
21
22class MaterializationResponsibility;
23
24/// A MaterializationUnit represents a set of symbol definitions that can
25/// be materialized as a group, or individually discarded (when
26/// overriding definitions are encountered).
27///
28/// MaterializationUnits are used when providing lazy definitions of symbols to
29/// JITDylibs. The JITDylib will call materialize when the address of a symbol
30/// is requested via the lookup method. The JITDylib will call discard if a
31/// stronger definition is added or already present.
33 friend class ExecutionSession;
34 friend class JITDylib;
35
36public:
37 static char ID;
38
39 struct Interface {
40 Interface() = default;
42 : SymbolFlags(std::move(InitalSymbolFlags)),
44 assert((!this->InitSymbol || this->SymbolFlags.count(this->InitSymbol)) &&
45 "If set, InitSymbol should appear in InitialSymbolFlags map");
46 }
47
50 };
51
55 virtual ~MaterializationUnit() = default;
56
57 /// Return the name of this materialization unit. Useful for debugging
58 /// output.
59 virtual StringRef getName() const = 0;
60
61 /// Return the set of symbols that this source provides.
62 const SymbolFlagsMap &getSymbols() const { return SymbolFlags; }
63
64 /// Returns the initialization symbol for this MaterializationUnit (if any).
66
67 /// Implementations of this method should materialize all symbols
68 /// in the materialzation unit, except for those that have been
69 /// previously discarded.
70 virtual void
71 materialize(std::unique_ptr<MaterializationResponsibility> R) = 0;
72
73 /// Called by JITDylibs to notify MaterializationUnits that the given symbol
74 /// has been overridden.
75 void doDiscard(const JITDylib &JD, const SymbolStringPtr &Name) {
77 if (InitSymbol == Name) {
78 DEBUG_WITH_TYPE("orc", {
79 dbgs() << "In " << getName() << ": discarding init symbol \""
80 << *Name << "\"\n";
81 });
82 InitSymbol = nullptr;
83 }
84 discard(JD, std::move(Name));
85 }
86
87protected:
90
91private:
92 virtual void anchor();
93
94 /// Implementations of this method should discard the given symbol
95 /// from the source (e.g. if the source is an LLVM IR Module and the
96 /// symbol is a function, delete the function body or mark it available
97 /// externally).
98 virtual void discard(const JITDylib &JD, const SymbolStringPtr &Name) = 0;
99};
100
101} // namespace llvm::orc
102
103#endif // LLVM_EXECUTIONENGINE_ORC_MATERIALIZATIONUNIT_H
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition: Debug.h:64
std::string Name
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool erase(const KeyT &Val)
Definition: DenseMap.h:321
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:152
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
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.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
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
Interface(SymbolFlagsMap InitalSymbolFlags, SymbolStringPtr InitSymbol)