[unroll] Extract the code to enqueue operansd for the worklist in the
authorChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 03:49:41 +0000 (03:49 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 03:49:41 +0000 (03:49 +0000)
unroll analysis into a lambda and call it. That's much simpler than
duplicating all the code.

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

lib/Transforms/Scalar/LoopUnrollPass.cpp

index e4771dbc89b70bda4a07c25508990c3647bfaa7b..63d3cc6f628353af4318e7058880e921c09893e7 100644 (file)
@@ -509,6 +509,15 @@ public:
     // worklist.
     SmallPtrSet<Instruction *, 4> OperandSet;
 
+    // Lambda to enque operands onto the worklist.
+    auto EnqueueOperands = [&](Instruction &I) {
+      OperandSet.clear();
+      for (auto *Op : I.operand_values())
+        if (auto *OpI = dyn_cast<Instruction>(Op))
+          if (OperandSet.insert(OpI).second)
+            Worklist.push_back(OpI);
+    };
+
     // Start by initializing worklist with simplified instructions.
     for (auto &FoldedKeyValue : SimplifiedValues)
       if (auto *FoldedInst = dyn_cast<Instruction>(FoldedKeyValue.first)) {
@@ -516,11 +525,7 @@ public:
 
         // Add each instruction operand of this dead instruction to the
         // worklist.
-        OperandSet.clear();
-        for (auto *Op : FoldedInst->operand_values())
-          if (auto *OpI = dyn_cast<Instruction>(Op))
-            if (OperandSet.insert(OpI).second)
-              Worklist.push_back(OpI);
+        EnqueueOperands(*FoldedInst);
       }
 
     // If a definition of an insn is only used by simplified or dead
@@ -545,11 +550,7 @@ public:
       if (AllUsersFolded) {
         NumberOfOptimizedInstructions += TTI.getUserCost(I);
         DeadInstructions.insert(I);
-        OperandSet.clear();
-        for (auto *Op : I->operand_values())
-          if (auto *OpI = dyn_cast<Instruction>(Op))
-            if (OperandSet.insert(OpI).second)
-              Worklist.push_back(OpI);
+        EnqueueOperands(*I);
       }
     }
     return NumberOfOptimizedInstructions;