[ORC] Move symbol-scanning and discard from BasicIRLayerMaterializationUnit in
authorLang Hames <lhames@gmail.com>
Tue, 22 May 2018 16:15:38 +0000 (16:15 +0000)
committerLang Hames <lhames@gmail.com>
Tue, 22 May 2018 16:15:38 +0000 (16:15 +0000)
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

llvm/include/llvm/ExecutionEngine/Orc/Layer.h
llvm/lib/ExecutionEngine/Orc/Layer.cpp

index 5aef5a2..fc8c5ad 100644 (file)
@@ -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 {
index 2bb7b90..346dde4 100644 (file)
@@ -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() {}