[unroll] Make range based for loops a bit more explicit and more
authorChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 02:45:17 +0000 (02:45 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 02:45:17 +0000 (02:45 +0000)
readable.

The biggest thing that was causing me problems is recognizing the
references vs. poniters here. I also found that for maps naming the loop
variable as KeyValue helps make it obvious why you don't actually use it
directly. Finally, using 'auto' instead of 'User *' doesn't seem like
a good tradeoff. Much like with the other cases, I like to know its
a pointer, and 'User' is just as long and tells the reader a lot more.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229033 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopUnrollPass.cpp

index aabdf065a6335ed086af42eb428f9e210542a31c..66e59f3b9fb0287fc0686acd507ca27a951aa876 100644 (file)
@@ -461,13 +461,13 @@ public:
     NumberOfOptimizedInstructions = 0;
 
     // We start by adding all loads to the worklist.
-    for (auto LoadDescr : LoadBaseAddresses) {
+    for (auto &LoadDescr : LoadBaseAddresses) {
       LoadInst *LI = LoadDescr.first;
       SimplifiedValues[LI] = computeLoadValue(LI, Iteration);
       if (CountedInstructions.insert(LI).second)
         NumberOfOptimizedInstructions += TTI.getUserCost(LI);
 
-      for (auto U : LI->users()) {
+      for (User *U : LI->users()) {
         Instruction *UI = dyn_cast<Instruction>(U);
         if (!UI)
           continue;
@@ -484,7 +484,7 @@ public:
       Instruction *I = Worklist.pop_back_val();
       if (!visit(I))
         continue;
-      for (auto U : I->users()) {
+      for (User *U : I->users()) {
         Instruction *UI = dyn_cast<Instruction>(U);
         if (!UI)
           continue;
@@ -504,8 +504,8 @@ public:
     SmallPtrSet<Instruction *, 16> DeadInstructions;
 
     // Start by initializing worklist with simplified instructions.
-    for (auto Folded : SimplifiedValues)
-      if (auto FoldedInst = dyn_cast<Instruction>(Folded.first)) {
+    for (auto &FoldedKeyValue : SimplifiedValues)
+      if (auto *FoldedInst = dyn_cast<Instruction>(FoldedKeyValue.first)) {
         Worklist.push_back(FoldedInst);
         DeadInstructions.insert(FoldedInst);
       }
@@ -516,7 +516,7 @@ public:
     while (!Worklist.empty()) {
       Instruction *FoldedInst = Worklist.pop_back_val();
       for (Value *Op : FoldedInst->operands()) {
-        if (auto I = dyn_cast<Instruction>(Op)) {
+        if (auto *I = dyn_cast<Instruction>(Op)) {
           if (!L->contains(I))
             continue;
           if (SimplifiedValues[I])
@@ -524,7 +524,7 @@ public:
           if (I->getNumUses() == 0)
             continue;
           bool AllUsersFolded = true;
-          for (auto U : I->users()) {
+          for (User *U : I->users()) {
             Instruction *UI = dyn_cast<Instruction>(U);
             if (!SimplifiedValues[UI] && !DeadInstructions.count(UI)) {
               AllUsersFolded = false;