[ORC] Make the VModuleKey optional, propagate it via MaterializationUnit and
MaterializationResponsibility.

VModuleKeys are intended to enable selective removal of modules from a JIT
session, however for a wide variety of use cases selective removal is not
needed and introduces unnecessary overhead. As of this commit, the default
constructed VModuleKey value is reserved as a "do not track" value, and
becomes the default when adding a new module to the JIT.

This commit also changes the propagation of VModuleKeys. They were passed
alongside the MaterializationResponsibity instance in XXLayer::emit methods,
but are now propagated as part of the MaterializationResponsibility instance
itself (and as part of MaterializationUnit when stored in a JITDylib).
Associating VModuleKeys with MaterializationUnits in this way should allow
for a thread-safe module removal mechanism in the future, even when a module
is in the process of being compiled, by having the
MaterializationResponsibility object check in on its VModuleKey's state
before commiting its results to the JITDylib.

llvm-svn: 344643
diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h
index 284a1e3..e76d2fa 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h
@@ -97,7 +97,7 @@
       orc::SymbolFlagsMap SymbolFlags, MaterializeFunction Materialize,
       DiscardFunction Discard = DiscardFunction(),
       DestructorFunction Destructor = DestructorFunction())
-      : MaterializationUnit(std::move(SymbolFlags)),
+      : MaterializationUnit(std::move(SymbolFlags), orc::VModuleKey()),
         Materialize(std::move(Materialize)), Discard(std::move(Discard)),
         Destructor(std::move(Destructor)) {}
 
diff --git a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
index 75ccfc9..1660670 100644
--- a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
@@ -54,7 +54,7 @@
   auto &JD = ES.createJITDylib("main");
   auto Foo = ES.intern("foo");
 
-  RTDyldObjectLinkingLayer ObjLayer(ES, [&DebugSectionSeen](VModuleKey) {
+  RTDyldObjectLinkingLayer ObjLayer(ES, [&DebugSectionSeen]() {
     return llvm::make_unique<MemoryManagerWrapper>(DebugSectionSeen);
   });
 
@@ -65,8 +65,7 @@
   auto OnReadyDoNothing = [](Error Err) { cantFail(std::move(Err)); };
 
   ObjLayer.setProcessAllSections(ProcessAllSections);
-  auto K = ES.allocateVModule();
-  cantFail(ObjLayer.add(JD, K, std::move(Obj)));
+  cantFail(ObjLayer.add(JD, std::move(Obj), ES.allocateVModule()));
   ES.lookup({&JD}, {Foo}, OnResolveDoNothing, OnReadyDoNothing,
             NoDependenciesToRegister);
   return DebugSectionSeen;
@@ -152,12 +151,12 @@
   auto &JD = ES.createJITDylib("main");
   auto Foo = ES.intern("foo");
   RTDyldObjectLinkingLayer ObjLayer(
-      ES, [](VModuleKey) { return llvm::make_unique<SectionMemoryManager>(); });
+      ES, []() { return llvm::make_unique<SectionMemoryManager>(); });
   IRCompileLayer CompileLayer(ES, ObjLayer, FunkySimpleCompiler(*TM));
 
   ObjLayer.setOverrideObjectFlagsWithResponsibilityFlags(true);
 
-  cantFail(CompileLayer.add(JD, ES.allocateVModule(), std::move(M)));
+  cantFail(CompileLayer.add(JD, std::move(M), ES.allocateVModule()));
   ES.lookup({&JD}, {Foo}, [](Expected<SymbolMap> R) { cantFail(std::move(R)); },
             [](Error Err) { cantFail(std::move(Err)); },
             NoDependenciesToRegister);
@@ -214,12 +213,12 @@
   auto &JD = ES.createJITDylib("main");
   auto Foo = ES.intern("foo");
   RTDyldObjectLinkingLayer ObjLayer(
-      ES, [](VModuleKey) { return llvm::make_unique<SectionMemoryManager>(); });
+      ES, []() { return llvm::make_unique<SectionMemoryManager>(); });
   IRCompileLayer CompileLayer(ES, ObjLayer, FunkySimpleCompiler(*TM));
 
   ObjLayer.setAutoClaimResponsibilityForObjectSymbols(true);
 
-  cantFail(CompileLayer.add(JD, ES.allocateVModule(), std::move(M)));
+  cantFail(CompileLayer.add(JD, std::move(M), ES.allocateVModule()));
   ES.lookup({&JD}, {Foo}, [](Expected<SymbolMap> R) { cantFail(std::move(R)); },
             [](Error Err) { cantFail(std::move(Err)); },
             NoDependenciesToRegister);