Skip to content

Commit 3d2849b

Browse files
committed
[ORC] Move MaterializationUnit from Core.h into its own header. NFC.
Continuing Core.h clean-up.
1 parent 81613dd commit 3d2849b

File tree

2 files changed

+106
-78
lines changed

2 files changed

+106
-78
lines changed

llvm/include/llvm/ExecutionEngine/Orc/Core.h

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ExecutionEngine/JITSymbol.h"
2222
#include "llvm/ExecutionEngine/Orc/CoreContainers.h"
2323
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
24+
#include "llvm/ExecutionEngine/Orc/MaterializationUnit.h"
2425
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
2526
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
2627
#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
@@ -40,7 +41,6 @@ namespace orc {
4041
// Forward declare some classes.
4142
class AsynchronousSymbolQuery;
4243
class ExecutionSession;
43-
class MaterializationUnit;
4444
class MaterializationResponsibility;
4545
class JITDylib;
4646
class ResourceTracker;
@@ -666,83 +666,6 @@ class MaterializationResponsibility {
666666
SymbolStringPtr InitSymbol;
667667
};
668668

669-
/// A MaterializationUnit represents a set of symbol definitions that can
670-
/// be materialized as a group, or individually discarded (when
671-
/// overriding definitions are encountered).
672-
///
673-
/// MaterializationUnits are used when providing lazy definitions of symbols to
674-
/// JITDylibs. The JITDylib will call materialize when the address of a symbol
675-
/// is requested via the lookup method. The JITDylib will call discard if a
676-
/// stronger definition is added or already present.
677-
class MaterializationUnit {
678-
friend class ExecutionSession;
679-
friend class JITDylib;
680-
681-
public:
682-
static char ID;
683-
684-
struct Interface {
685-
Interface() = default;
686-
Interface(SymbolFlagsMap InitalSymbolFlags, SymbolStringPtr InitSymbol)
687-
: SymbolFlags(std::move(InitalSymbolFlags)),
688-
InitSymbol(std::move(InitSymbol)) {
689-
assert((!this->InitSymbol || this->SymbolFlags.count(this->InitSymbol)) &&
690-
"If set, InitSymbol should appear in InitialSymbolFlags map");
691-
}
692-
693-
SymbolFlagsMap SymbolFlags;
694-
SymbolStringPtr InitSymbol;
695-
};
696-
697-
MaterializationUnit(Interface I)
698-
: SymbolFlags(std::move(I.SymbolFlags)),
699-
InitSymbol(std::move(I.InitSymbol)) {}
700-
virtual ~MaterializationUnit() = default;
701-
702-
/// Return the name of this materialization unit. Useful for debugging
703-
/// output.
704-
virtual StringRef getName() const = 0;
705-
706-
/// Return the set of symbols that this source provides.
707-
const SymbolFlagsMap &getSymbols() const { return SymbolFlags; }
708-
709-
/// Returns the initialization symbol for this MaterializationUnit (if any).
710-
const SymbolStringPtr &getInitializerSymbol() const { return InitSymbol; }
711-
712-
/// Implementations of this method should materialize all symbols
713-
/// in the materialzation unit, except for those that have been
714-
/// previously discarded.
715-
virtual void
716-
materialize(std::unique_ptr<MaterializationResponsibility> R) = 0;
717-
718-
/// Called by JITDylibs to notify MaterializationUnits that the given symbol
719-
/// has been overridden.
720-
void doDiscard(const JITDylib &JD, const SymbolStringPtr &Name) {
721-
SymbolFlags.erase(Name);
722-
if (InitSymbol == Name) {
723-
DEBUG_WITH_TYPE("orc", {
724-
dbgs() << "In " << getName() << ": discarding init symbol \""
725-
<< *Name << "\"\n";
726-
});
727-
InitSymbol = nullptr;
728-
}
729-
discard(JD, std::move(Name));
730-
}
731-
732-
protected:
733-
SymbolFlagsMap SymbolFlags;
734-
SymbolStringPtr InitSymbol;
735-
736-
private:
737-
virtual void anchor();
738-
739-
/// Implementations of this method should discard the given symbol
740-
/// from the source (e.g. if the source is an LLVM IR Module and the
741-
/// symbol is a function, delete the function body or mark it available
742-
/// externally).
743-
virtual void discard(const JITDylib &JD, const SymbolStringPtr &Name) = 0;
744-
};
745-
746669
/// A MaterializationUnit implementation for pre-existing absolute symbols.
747670
///
748671
/// All symbols will be resolved and marked ready as soon as the unit is
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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"
17+
#include "llvm/ExecutionEngine/Orc/CoreContainers.h"
18+
#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
19+
20+
namespace llvm {
21+
namespace orc {
22+
23+
class 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.
33+
class MaterializationUnit {
34+
friend class ExecutionSession;
35+
friend class JITDylib;
36+
37+
public:
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+
49+
SymbolFlagsMap SymbolFlags;
50+
SymbolStringPtr InitSymbol;
51+
};
52+
53+
MaterializationUnit(Interface I)
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+
88+
protected:
89+
SymbolFlagsMap SymbolFlags;
90+
SymbolStringPtr InitSymbol;
91+
92+
private:
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+
} // End namespace orc
103+
} // End namespace llvm
104+
105+
#endif // LLVM_EXECUTIONENGINE_ORC_MATERIALIZATIONUNIT_H

0 commit comments

Comments
 (0)