[LoopInfo] Make LoopBase and Loop destructors non-public

Summary:
See comment for why I think this is a good idea.

This change also:

 - Removes an SCEV test case.  The SCEV test was not testing anything useful (most of it was `#if 0` ed out) and it would need to be updated to deal with a private ~Loop::Loop.
 - Updates the loop pass manager test case to deal with a private ~Loop::Loop.
 - Renames markAsRemoved to markAsErased to contrast with removeLoop, via the usual remove vs. erase idiom we already have for instructions and basic blocks.

Reviewers: chandlerc

Subscribers: mehdi_amini, mcrosier, llvm-commits

Differential Revision: https://reviews.llvm.org/D37996

llvm-svn: 313695
diff --git a/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp b/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
index 0e5780e..31b3cea 100644
--- a/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
+++ b/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
@@ -1374,9 +1374,8 @@
   // to isolate ourselves from the rest of LLVM and for simplicity. Here we can
   // egregiously cheat based on knowledge of the test case. For example, we
   // have no PHI nodes and there is always a single i-dom.
-  auto RemoveLoop = [](Loop &L, BasicBlock &IDomBB,
-                             LoopStandardAnalysisResults &AR,
-                             LPMUpdater &Updater) {
+  auto EraseLoop = [](Loop &L, BasicBlock &IDomBB,
+                      LoopStandardAnalysisResults &AR, LPMUpdater &Updater) {
     assert(L.empty() && "Can only delete leaf loops with this routine!");
     SmallVector<BasicBlock *, 4> LoopBBs(L.block_begin(), L.block_end());
     Updater.markLoopAsDeleted(L);
@@ -1394,10 +1393,7 @@
     for (BasicBlock *LoopBB : LoopBBs)
       LoopBB->eraseFromParent();
 
-    if (Loop *ParentL = L.getParentLoop())
-      return ParentL->removeChildLoop(find(*ParentL, &L));
-
-    return AR.LI.removeLoop(find(AR.LI, &L));
+    AR.LI.markAsErased(&L);
   };
 
   // Build up the pass managers.
@@ -1442,7 +1438,7 @@
                      LoopStandardAnalysisResults &AR, LPMUpdater &Updater) {
             Loop *ParentL = L.getParentLoop();
             AR.SE.forgetLoop(&L);
-            delete RemoveLoop(L, Loop01PHBB, AR, Updater);
+            EraseLoop(L, Loop01PHBB, AR, Updater);
             ParentL->verifyLoop();
             return PreservedAnalyses::all();
           }));
@@ -1469,10 +1465,8 @@
       .WillRepeatedly(Invoke(getLoopAnalysisResult));
 
   // Run the loop pipeline again. This time we delete the last loop, which
-  // contains a nested loop within it, and we reuse its inner loop object to
-  // insert a new loop into the nest. This makes sure that we don't reuse
-  // cached analysis results for loop objects when removed just because their
-  // pointers match, and that we can handle nested loop deletion.
+  // contains a nested loop within it and insert a new loop into the nest. This
+  // makes sure we can handle nested loop deletion.
   AddLoopPipelineAndVerificationPasses();
   EXPECT_CALL(MLPHandle, run(HasName("loop.0.0"), _, _, _))
       .Times(3)
@@ -1489,16 +1483,16 @@
       .WillOnce(
           Invoke([&](Loop &L, LoopAnalysisManager &AM,
                      LoopStandardAnalysisResults &AR, LPMUpdater &Updater) {
-            // Remove the inner loop first but retain it to reuse later.
             AR.SE.forgetLoop(*L.begin());
-            auto *OldL = RemoveLoop(**L.begin(), Loop020PHBB, AR, Updater);
+            EraseLoop(**L.begin(), Loop020PHBB, AR, Updater);
 
             auto *ParentL = L.getParentLoop();
             AR.SE.forgetLoop(&L);
-            delete RemoveLoop(L, Loop02PHBB, AR, Updater);
+            EraseLoop(L, Loop02PHBB, AR, Updater);
 
-            // Now insert a new sibling loop, reusing a loop pointer.
-            ParentL->addChildLoop(OldL);
+            // Now insert a new sibling loop.
+            auto *NewSibling = new Loop;
+            ParentL->addChildLoop(NewSibling);
             NewLoop03PHBB =
                 BasicBlock::Create(Context, "loop.0.3.ph", &F, &Loop0LatchBB);
             auto *NewLoop03BB =
@@ -1515,10 +1509,10 @@
                                            AR.DT[NewLoop03BB]);
             AR.DT.verifyDomTree();
             ParentL->addBasicBlockToLoop(NewLoop03PHBB, AR.LI);
-            OldL->addBasicBlockToLoop(NewLoop03BB, AR.LI);
-            OldL->verifyLoop();
+            NewSibling->addBasicBlockToLoop(NewLoop03BB, AR.LI);
+            NewSibling->verifyLoop();
             ParentL->verifyLoop();
-            Updater.addSiblingLoops({OldL});
+            Updater.addSiblingLoops({NewSibling});
             return PreservedAnalyses::all();
           }));
 
@@ -1550,7 +1544,7 @@
           Invoke([&](Loop &L, LoopAnalysisManager &AM,
                      LoopStandardAnalysisResults &AR, LPMUpdater &Updater) {
             AR.SE.forgetLoop(&L);
-            delete RemoveLoop(L, Loop00PHBB, AR, Updater);
+            EraseLoop(L, Loop00PHBB, AR, Updater);
             return PreservedAnalyses::all();
           }));
 
@@ -1561,7 +1555,7 @@
           Invoke([&](Loop &L, LoopAnalysisManager &AM,
                      LoopStandardAnalysisResults &AR, LPMUpdater &Updater) {
             AR.SE.forgetLoop(&L);
-            delete RemoveLoop(L, *NewLoop03PHBB, AR, Updater);
+            EraseLoop(L, *NewLoop03PHBB, AR, Updater);
             return PreservedAnalyses::all();
           }));
 
@@ -1572,7 +1566,7 @@
           Invoke([&](Loop &L, LoopAnalysisManager &AM,
                      LoopStandardAnalysisResults &AR, LPMUpdater &Updater) {
             AR.SE.forgetLoop(&L);
-            delete RemoveLoop(L, EntryBB, AR, Updater);
+            EraseLoop(L, EntryBB, AR, Updater);
             return PreservedAnalyses::all();
           }));