[llvm] r336603 - [ORC] Rename MaterializationResponsibility::delegate to replace and add a new

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 9 13:54:36 PDT 2018


Author: lhames
Date: Mon Jul  9 13:54:36 2018
New Revision: 336603

URL: http://llvm.org/viewvc/llvm-project?rev=336603&view=rev
Log:
[ORC] Rename MaterializationResponsibility::delegate to replace and add a new
delegate method (and unit test).

The name 'replace' better captures what the old delegate method did: it
returned materialization responsibility for a set of symbols to the VSO.

The new delegate method delegates responsibility for a set of symbols to a new
MaterializationResponsibility instance. This can be used to split responsibility
between multiple threads, or multiple materialization methods.

Modified:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
    llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
    llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
    llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h?rev=336603&r1=336602&r2=336603&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h Mon Jul  9 13:54:36 2018
@@ -149,7 +149,12 @@ public:
   /// materializers to break up work based on run-time information (e.g.
   /// by introspecting which symbols have actually been looked up and
   /// materializing only those).
-  void delegate(std::unique_ptr<MaterializationUnit> MU);
+  void replace(std::unique_ptr<MaterializationUnit> MU);
+
+  /// Delegates responsibility for the given symbols to the returned
+  /// materialization responsibility. Useful for breaking up work between
+  /// threads, or different kinds of materialization processes.
+  MaterializationResponsibility delegate(const SymbolNameSet &Symbols);
 
   /// Add dependencies for the symbols in this dylib.
   void addDependencies(const SymbolDependenceMap &Dependencies);

Modified: llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp?rev=336603&r1=336602&r2=336603&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp Mon Jul  9 13:54:36 2018
@@ -68,7 +68,7 @@ static void extractAliases(Materializati
     }
   }
 
-  R.delegate(symbolAliases(std::move(Aliases)));
+  R.replace(symbolAliases(std::move(Aliases)));
 }
 
 static std::unique_ptr<Module>
@@ -199,7 +199,7 @@ private:
                  DelegatedSymbolToDefinition.size() &&
              "SymbolFlags and SymbolToDefinition should have the same number "
              "of entries");
-      R.delegate(llvm::make_unique<ExtractingIRMaterializationUnit>(
+      R.replace(llvm::make_unique<ExtractingIRMaterializationUnit>(
           std::move(M), std::move(DelegatedSymbolFlags),
           std::move(DelegatedSymbolToDefinition), Parent, BackingResolver));
     }

Modified: llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp?rev=336603&r1=336602&r2=336603&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp Mon Jul  9 13:54:36 2018
@@ -309,7 +309,7 @@ void MaterializationResponsibility::fail
   SymbolFlags.clear();
 }
 
-void MaterializationResponsibility::delegate(
+void MaterializationResponsibility::replace(
     std::unique_ptr<MaterializationUnit> MU) {
   for (auto &KV : MU->getSymbols())
     SymbolFlags.erase(KV.first);
@@ -317,6 +317,23 @@ void MaterializationResponsibility::dele
   V.replace(std::move(MU));
 }
 
+MaterializationResponsibility
+MaterializationResponsibility::delegate(const SymbolNameSet &Symbols) {
+  SymbolFlagsMap DelegatedFlags;
+
+  for (auto &Name : Symbols) {
+    auto I = SymbolFlags.find(Name);
+    assert(I != SymbolFlags.end() &&
+           "Symbol is not tracked by this MaterializationResponsibility "
+           "instance");
+
+    DelegatedFlags[Name] = std::move(I->second);
+    SymbolFlags.erase(I);
+  }
+
+  return MaterializationResponsibility(V, std::move(DelegatedFlags));
+}
+
 void MaterializationResponsibility::addDependencies(
     const SymbolDependenceMap &Dependencies) {
   V.addDependencies(SymbolFlags, Dependencies);

Modified: llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp?rev=336603&r1=336602&r2=336603&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp Mon Jul  9 13:54:36 2018
@@ -834,7 +834,7 @@ TEST(CoreAPIsTest, TestLookupWithThreade
 #endif
 }
 
-TEST(CoreAPIsTest, TestGetRequestedSymbolsAndDelegate) {
+TEST(CoreAPIsTest, TestGetRequestedSymbolsAndReplace) {
   ExecutionSession ES;
   auto Foo = ES.getSymbolStringPool().intern("foo");
   auto Bar = ES.getSymbolStringPool().intern("bar");
@@ -862,7 +862,7 @@ TEST(CoreAPIsTest, TestGetRequestedSymbo
               BarMaterialized = true;
             });
 
-        R.delegate(std::move(NewMU));
+        R.replace(std::move(NewMU));
 
         R.resolve(SymbolMap({{Foo, FooSym}}));
         R.finalize();
@@ -890,6 +890,40 @@ TEST(CoreAPIsTest, TestGetRequestedSymbo
   EXPECT_TRUE(BarMaterialized) << "Bar should be materialized now";
 }
 
+TEST(CoreAPIsTest, TestMaterializationResponsibilityDelegation) {
+  ExecutionSession ES;
+
+  auto Foo = ES.getSymbolStringPool().intern("Foo");
+  auto Bar = ES.getSymbolStringPool().intern("Bar");
+
+  JITEvaluatedSymbol FooSym(0xdeadbeef, JITSymbolFlags::Exported);
+  JITEvaluatedSymbol BarSym(0xcafef00d, JITSymbolFlags::Exported);
+
+  auto MU = llvm::make_unique<SimpleMaterializationUnit>(
+      SymbolFlagsMap({{Foo, FooSym.getFlags()}, {Bar, BarSym.getFlags()}}),
+      [&](MaterializationResponsibility R) {
+        auto R2 = R.delegate({Bar});
+
+        R.resolve({{Foo, FooSym}});
+        R.finalize();
+        R2.resolve({{Bar, BarSym}});
+        R2.finalize();
+      });
+
+  auto &V = ES.createVSO("V");
+  cantFail(V.define(MU));
+
+  auto Result = lookup({&V}, {Foo, Bar});
+
+  EXPECT_TRUE(!!Result) << "Result should be a success value";
+  EXPECT_EQ(Result->count(Foo), 1U) << "\"Foo\" entry missing";
+  EXPECT_EQ(Result->count(Bar), 1U) << "\"Bar\" entry missing";
+  EXPECT_EQ((*Result)[Foo].getAddress(), FooSym.getAddress())
+      << "Address mismatch for \"Foo\"";
+  EXPECT_EQ((*Result)[Bar].getAddress(), BarSym.getAddress())
+      << "Address mismatch for \"Bar\"";
+}
+
 TEST(CoreAPIsTest, TestMaterializeWeakSymbol) {
   // Confirm that once a weak definition is selected for materialization it is
   // treated as strong.




More information about the llvm-commits mailing list