forked from OSchip/llvm-project
[ORC] Move symbol-scanning and discard from BasicIRLayerMaterializationUnit in
to a base class (IRMaterializationUnit). The new class, IRMaterializationUnit, provides a convenient base for any client that wants to write a materializer for LLVM IR. llvm-svn: 332993
This commit is contained in:
parent
dd5fb8f03f
commit
5261aa9f91
|
@ -46,19 +46,29 @@ private:
|
|||
ExecutionSession &ES;
|
||||
};
|
||||
|
||||
class BasicIRLayerMaterializationUnit : public MaterializationUnit {
|
||||
class IRMaterializationUnit : public MaterializationUnit {
|
||||
public:
|
||||
IRMaterializationUnit(ExecutionSession &ES, std::unique_ptr<Module> M);
|
||||
|
||||
protected:
|
||||
std::unique_ptr<Module> M;
|
||||
|
||||
private:
|
||||
void discard(const VSO &V, SymbolStringPtr Name) override;
|
||||
|
||||
std::map<SymbolStringPtr, GlobalValue *> Discardable;
|
||||
};
|
||||
|
||||
class BasicIRLayerMaterializationUnit : public IRMaterializationUnit {
|
||||
public:
|
||||
BasicIRLayerMaterializationUnit(IRLayer &L, VModuleKey K,
|
||||
std::unique_ptr<Module> M);
|
||||
|
||||
private:
|
||||
|
||||
void materialize(MaterializationResponsibility R) override;
|
||||
void discard(const VSO &V, SymbolStringPtr Name) override;
|
||||
|
||||
IRLayer &L;
|
||||
VModuleKey K;
|
||||
std::unique_ptr<Module> M;
|
||||
std::map<SymbolStringPtr, GlobalValue *> Discardable;
|
||||
};
|
||||
|
||||
class ObjectLayer {
|
||||
|
|
|
@ -35,12 +35,10 @@ Error IRLayer::add(VSO &V, VModuleKey K, std::unique_ptr<Module> M) {
|
|||
*this, std::move(K), std::move(M)));
|
||||
}
|
||||
|
||||
BasicIRLayerMaterializationUnit::BasicIRLayerMaterializationUnit(
|
||||
IRLayer &L, VModuleKey K, std::unique_ptr<Module> M)
|
||||
: MaterializationUnit(SymbolFlagsMap()), L(L), K(std::move(K)),
|
||||
M(std::move(M)) {
|
||||
IRMaterializationUnit::IRMaterializationUnit(ExecutionSession &ES,
|
||||
std::unique_ptr<Module> M)
|
||||
: MaterializationUnit(SymbolFlagsMap()), M(std::move(M)) {
|
||||
|
||||
auto &ES = L.getExecutionSession();
|
||||
MangleAndInterner Mangle(ES, this->M->getDataLayout());
|
||||
for (auto &G : this->M->global_values()) {
|
||||
if (G.hasName() && !G.isDeclaration() &&
|
||||
|
@ -53,13 +51,7 @@ BasicIRLayerMaterializationUnit::BasicIRLayerMaterializationUnit(
|
|||
}
|
||||
}
|
||||
|
||||
void BasicIRLayerMaterializationUnit::materialize(
|
||||
MaterializationResponsibility R) {
|
||||
L.emit(std::move(R), std::move(K), std::move(M));
|
||||
}
|
||||
|
||||
void BasicIRLayerMaterializationUnit::discard(const VSO &V,
|
||||
SymbolStringPtr Name) {
|
||||
void IRMaterializationUnit::discard(const VSO &V, SymbolStringPtr Name) {
|
||||
auto I = Discardable.find(Name);
|
||||
assert(I != Discardable.end() &&
|
||||
"Symbol not provided by this MU, or previously discarded");
|
||||
|
@ -67,6 +59,16 @@ void BasicIRLayerMaterializationUnit::discard(const VSO &V,
|
|||
Discardable.erase(I);
|
||||
}
|
||||
|
||||
BasicIRLayerMaterializationUnit::BasicIRLayerMaterializationUnit(
|
||||
IRLayer &L, VModuleKey K, std::unique_ptr<Module> M)
|
||||
: IRMaterializationUnit(L.getExecutionSession(), std::move(M)),
|
||||
L(L), K(std::move(K)) {}
|
||||
|
||||
void BasicIRLayerMaterializationUnit::materialize(
|
||||
MaterializationResponsibility R) {
|
||||
L.emit(std::move(R), std::move(K), std::move(M));
|
||||
}
|
||||
|
||||
ObjectLayer::ObjectLayer(ExecutionSession &ES) : ES(ES) {}
|
||||
|
||||
ObjectLayer::~ObjectLayer() {}
|
||||
|
|
Loading…
Reference in New Issue