Filter nested structs
[oota-llvm.git] / lib / Transforms / Utils / LoopSimplify.cpp
index cf0dd07cd0076e5440a9368c50cf948c66faa275..e25ff90b47798584280a6264df2f17b2a1da53dd 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 
 #define DEBUG_TYPE "loopsimplify"
 #include "llvm/Transforms/Scalar.h"
-#include "llvm/Constant.h"
+#include "llvm/Constants.h"
 #include "llvm/Instructions.h"
 #include "llvm/Function.h"
 #include "llvm/Type.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/Dominators.h"
-#include "llvm/Analysis/DominatorInternals.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Compiler.h"
@@ -159,12 +158,14 @@ bool LoopSimplify::runOnFunction(Function &F) {
     for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
       TI->getSuccessor(i)->removePredecessor(BB);
    
-    // Add a new unreachable instruction.
+    // Add a new unreachable instruction before the old terminator.
     new UnreachableInst(TI);
     
     // Delete the dead terminator.
-    if (AA) AA->deleteValue(&BB->back());
-    BB->getInstList().pop_back();
+    if (AA) AA->deleteValue(TI);
+    if (!TI->use_empty())
+      TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
+    TI->eraseFromParent();
     Changed |= true;
   }
   
@@ -379,7 +380,7 @@ void LoopSimplify::InsertPreheaderForLoop(Loop *L) {
 
   // We know that we have loop information to update... update it now.
   if (Loop *Parent = L->getParentLoop())
-    Parent->addBasicBlockToLoop(NewBB, *LI);
+    Parent->addBasicBlockToLoop(NewBB, LI->getBase());
 
   DT->splitBlock(NewBB);
   if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>())
@@ -411,7 +412,7 @@ BasicBlock *LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) {
   while (SuccLoop && !SuccLoop->contains(L->getHeader()))
     SuccLoop = SuccLoop->getParentLoop();
   if (SuccLoop)
-    SuccLoop->addBasicBlockToLoop(NewBB, *LI);
+    SuccLoop->addBasicBlockToLoop(NewBB, LI->getBase());
 
   // Update Dominator Information
   DT->splitBlock(NewBB);
@@ -557,7 +558,7 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
 
   // This block is going to be our new header block: add it to this loop and all
   // parent loops.
-  NewOuter->addBasicBlockToLoop(NewBB, *LI);
+  NewOuter->addBasicBlockToLoop(NewBB, LI->getBase());
 
   // L is now a subloop of our outer loop.
   NewOuter->addChildLoop(L);
@@ -692,7 +693,7 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) {
 
   // Update Loop Information - we know that this block is now in the current
   // loop and all parent loops.
-  L->addBasicBlockToLoop(BEBlock, *LI);
+  L->addBasicBlockToLoop(BEBlock, LI->getBase());
 
   // Update dominator information
   DT->splitBlock(BEBlock);