[ORC] Switch the object layer API from addObjectSet to addObject (singular), and
move the ObjectCache from the IRCompileLayer to SimpleCompiler.

This is the first in a series of patches aimed at cleaning up and improving the
robustness and performance of the ORC APIs.

llvm-svn: 306058
diff --git a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
index 8878451..7c821bc 100644
--- a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
@@ -63,7 +63,7 @@
     bool &DebugSeen;
   };
 
-  RTDyldObjectLinkingLayer<> ObjLayer;
+  RTDyldObjectLinkingLayer ObjLayer;
 
   LLVMContext Context;
   auto M = llvm::make_unique<Module>("", Context);
@@ -85,9 +85,9 @@
   if (!TM)
     return;
 
-  auto OwningObj = SimpleCompiler(*TM)(*M);
-  std::vector<object::ObjectFile*> Objs;
-  Objs.push_back(OwningObj.getBinary());
+  auto Obj =
+    std::make_shared<object::OwningBinary<object::ObjectFile>>(
+      SimpleCompiler(*TM)(*M));
 
   bool DebugSectionSeen = false;
   auto SMMW =
@@ -103,21 +103,21 @@
 
   {
     // Test with ProcessAllSections = false (the default).
-    auto H = ObjLayer.addObjectSet(Objs, SMMW, &*Resolver);
+    auto H = ObjLayer.addObject(Obj, SMMW, &*Resolver);
     ObjLayer.emitAndFinalize(H);
     EXPECT_EQ(DebugSectionSeen, false)
       << "Unexpected debug info section";
-    ObjLayer.removeObjectSet(H);
+    ObjLayer.removeObject(H);
   }
 
   {
     // Test with ProcessAllSections = true.
     ObjLayer.setProcessAllSections(true);
-    auto H = ObjLayer.addObjectSet(Objs, SMMW, &*Resolver);
+    auto H = ObjLayer.addObject(Obj, SMMW, &*Resolver);
     ObjLayer.emitAndFinalize(H);
     EXPECT_EQ(DebugSectionSeen, true)
       << "Expected debug info section not seen";
-    ObjLayer.removeObjectSet(H);
+    ObjLayer.removeObject(H);
   }
 }
 
@@ -125,7 +125,7 @@
   if (!TM)
     return;
 
-  RTDyldObjectLinkingLayer<> ObjLayer;
+  RTDyldObjectLinkingLayer ObjLayer;
   SimpleCompiler Compile(*TM);
 
   // Create a pair of modules that will trigger recursive finalization:
@@ -151,9 +151,9 @@
     Builder.CreateRet(FourtyTwo);
   }
 
-  auto Obj1 = Compile(*MB1.getModule());
-  std::vector<object::ObjectFile*> Obj1Set;
-  Obj1Set.push_back(Obj1.getBinary());
+  auto Obj1 =
+    std::make_shared<object::OwningBinary<object::ObjectFile>>(
+      Compile(*MB1.getModule()));
 
   ModuleBuilder MB2(Context, "", "dummy");
   {
@@ -164,9 +164,9 @@
     IRBuilder<> Builder(FooEntry);
     Builder.CreateRet(Builder.CreateCall(BarDecl));
   }
-  auto Obj2 = Compile(*MB2.getModule());
-  std::vector<object::ObjectFile*> Obj2Set;
-  Obj2Set.push_back(Obj2.getBinary());
+  auto Obj2 =
+    std::make_shared<object::OwningBinary<object::ObjectFile>>(
+      Compile(*MB2.getModule()));
 
   auto Resolver =
     createLambdaResolver(
@@ -180,10 +180,10 @@
       });
 
   auto SMMW = std::make_shared<SectionMemoryManagerWrapper>();
-  ObjLayer.addObjectSet(std::move(Obj1Set), SMMW, &*Resolver);
-  auto H = ObjLayer.addObjectSet(std::move(Obj2Set), SMMW, &*Resolver);
+  ObjLayer.addObject(std::move(Obj1), SMMW, &*Resolver);
+  auto H = ObjLayer.addObject(std::move(Obj2), SMMW, &*Resolver);
   ObjLayer.emitAndFinalize(H);
-  ObjLayer.removeObjectSet(H);
+  ObjLayer.removeObject(H);
   
   // Finalization of module 2 should trigger finalization of module 1.
   // Verify that finalize on SMMW is only called once.
@@ -195,7 +195,7 @@
   if (!TM)
     return;
 
-  RTDyldObjectLinkingLayer<> ObjLayer;
+  RTDyldObjectLinkingLayer ObjLayer;
   SimpleCompiler Compile(*TM);
 
   // Create a pair of unrelated modules:
@@ -222,9 +222,9 @@
     Builder.CreateRet(FourtyTwo);
   }
 
-  auto Obj1 = Compile(*MB1.getModule());
-  std::vector<object::ObjectFile*> Obj1Set;
-  Obj1Set.push_back(Obj1.getBinary());
+  auto Obj1 =
+    std::make_shared<object::OwningBinary<object::ObjectFile>>(
+      Compile(*MB1.getModule()));
 
   ModuleBuilder MB2(Context, "", "dummy");
   {
@@ -236,16 +236,16 @@
     Value *Seven = ConstantInt::getSigned(Int32Ty, 7);
     Builder.CreateRet(Seven);
   }
-  auto Obj2 = Compile(*MB2.getModule());
-  std::vector<object::ObjectFile*> Obj2Set;
-  Obj2Set.push_back(Obj2.getBinary());
+  auto Obj2 =
+    std::make_shared<object::OwningBinary<object::ObjectFile>>(
+      Compile(*MB2.getModule()));
 
   auto SMMW = std::make_shared<SectionMemoryManagerWrapper>();
   NullResolver NR;
-  auto H = ObjLayer.addObjectSet(std::move(Obj1Set), SMMW, &NR);
-  ObjLayer.addObjectSet(std::move(Obj2Set), SMMW, &NR);
+  auto H = ObjLayer.addObject(std::move(Obj1), SMMW, &NR);
+  ObjLayer.addObject(std::move(Obj2), SMMW, &NR);
   ObjLayer.emitAndFinalize(H);
-  ObjLayer.removeObjectSet(H);
+  ObjLayer.removeObject(H);
   
   // Only one call to needsToReserveAllocationSpace should have been made.
   EXPECT_EQ(SMMW->NeedsToReserveAllocationSpaceCount, 1)