Const-correct and prevent a copy of a SmallPtrSet.
[oota-llvm.git] / lib / Transforms / Utils / LCSSA.cpp
index 18717de6ae2eb1754fca9c19af326302f6df2db4..51a3d9c1fcedda5b664571e5f4e6d3469e85d79d 100644 (file)
@@ -27,7 +27,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define DEBUG_TYPE "lcssa"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Statistic.h"
@@ -44,6 +43,8 @@
 #include "llvm/Transforms/Utils/SSAUpdater.h"
 using namespace llvm;
 
+#define DEBUG_TYPE "lcssa"
+
 STATISTIC(NumLCSSA, "Number of live out of a loop variables");
 
 /// Return true if the specified block is in the list.
@@ -65,15 +66,14 @@ static bool processInstruction(Loop &L, Instruction &Inst, DominatorTree &DT,
 
   BasicBlock *InstBB = Inst.getParent();
 
-  for (Value::use_iterator UI = Inst.use_begin(), E = Inst.use_end(); UI != E;
-       ++UI) {
-    User *U = *UI;
-    BasicBlock *UserBB = cast<Instruction>(U)->getParent();
-    if (PHINode *PN = dyn_cast<PHINode>(U))
-      UserBB = PN->getIncomingBlock(UI);
+  for (Use &U : Inst.uses()) {
+    Instruction *User = cast<Instruction>(U.getUser());
+    BasicBlock *UserBB = User->getParent();
+    if (PHINode *PN = dyn_cast<PHINode>(User))
+      UserBB = PN->getIncomingBlock(U);
 
     if (InstBB != UserBB && !L.contains(UserBB))
-      UsesToRewrite.push_back(&UI.getUse());
+      UsesToRewrite.push_back(&U);
   }
 
   // If there are no uses outside the loop, exit with no change.
@@ -208,8 +208,8 @@ bool llvm::formLCSSA(Loop &L, DominatorTree &DT, ScalarEvolution *SE) {
       // Reject two common cases fast: instructions with no uses (like stores)
       // and instructions with one use that is in the same block as this.
       if (I->use_empty() ||
-          (I->hasOneUse() && I->use_back()->getParent() == BB &&
-           !isa<PHINode>(I->use_back())))
+          (I->hasOneUse() && I->user_back()->getParent() == BB &&
+           !isa<PHINode>(I->user_back())))
         continue;
 
       Changed |= processInstruction(L, *I, DT, ExitBlocks, PredCache);
@@ -268,8 +268,6 @@ struct LCSSA : public FunctionPass {
   }
 
 private:
-  bool processLoop(Loop &L);
-
   void verifyAnalysis() const override;
 };
 }