[unroll] Merge the simplification and DCE estimation methods on the
authorChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 04:39:05 +0000 (04:39 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 04:39:05 +0000 (04:39 +0000)
UnrollAnalyzer.

Now they share a single worklist and have less implicit state between
them. There was no real benefit to separating these two things out.

I'm going to subsequently refactor things to share even more code.

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

lib/Transforms/Scalar/LoopUnrollPass.cpp

index 0d9e2d156524b09c66718888b9050fcad7ea2b8f..53d80f68e08051ffdb62f1cc812c9573c5119760 100644 (file)
@@ -453,10 +453,17 @@ public:
 
   // Given a list of loads that could be constant-folded (LoadBaseAddresses),
   // estimate number of optimized instructions after substituting the concrete
 
   // Given a list of loads that could be constant-folded (LoadBaseAddresses),
   // estimate number of optimized instructions after substituting the concrete
-  // values for the given Iteration.
-  // Fill in SimplifiedValues map for future use in DCE-estimation.
-  unsigned estimateNumberOfSimplifiedInstructions(unsigned Iteration) {
+  // values for the given Iteration. Also track how many instructions become
+  // dead through this process.
+  unsigned estimateNumberOfOptimizedInstructions(unsigned Iteration) {
+    // We keep a set vector for the worklist so that we don't wast space in the
+    // worklist queuing up the same instruction repeatedly. This can happen due
+    // to multiple operands being the same instruction or due to the same
+    // instruction being an operand of lots of things that end up dead or
+    // simplified.
     SmallSetVector<Instruction *, 8> Worklist;
     SmallSetVector<Instruction *, 8> Worklist;
+
+    // Clear the simplified values and counts for this iteration.
     SimplifiedValues.clear();
     CountedInstructions.clear();
     NumberOfOptimizedInstructions = 0;
     SimplifiedValues.clear();
     CountedInstructions.clear();
     NumberOfOptimizedInstructions = 0;
@@ -484,20 +491,10 @@ public:
       for (User *U : I->users())
         Worklist.insert(cast<Instruction>(U));
     }
       for (User *U : I->users())
         Worklist.insert(cast<Instruction>(U));
     }
-    return NumberOfOptimizedInstructions;
-  }
-
-  // Given a list of potentially simplifed instructions, estimate number of
-  // instructions that would become dead if we do perform the simplification.
-  unsigned estimateNumberOfDeadInstructions() {
-    NumberOfOptimizedInstructions = 0;
 
 
-    // We keep a set vector for the worklist so that we don't wast space in the
-    // worklist queuing up the same instruction repeatedly. This can happen due
-    // to multiple operands being the same instruction or due to the same
-    // instruction being an operand of lots of things that end up dead or
-    // simplified.
-    SmallSetVector<Instruction *, 8> Worklist;
+    // Now that we know the potentially simplifed instructions, estimate number
+    // of instructions that would become dead if we do perform the
+    // simplification.
 
     // The dead instructions are held in a separate set. This is used to
     // prevent us from re-examining instructions and make sure we only count
 
     // The dead instructions are held in a separate set. This is used to
     // prevent us from re-examining instructions and make sure we only count
@@ -567,11 +564,10 @@ approximateNumberOfOptimizedInstructions(const Loop *L, ScalarEvolution &SE,
   unsigned IterationsNumberForEstimate =
       std::min<unsigned>(UnrollMaxIterationsCountToAnalyze, TripCount);
   unsigned NumberOfOptimizedInstructions = 0;
   unsigned IterationsNumberForEstimate =
       std::min<unsigned>(UnrollMaxIterationsCountToAnalyze, TripCount);
   unsigned NumberOfOptimizedInstructions = 0;
-  for (unsigned i = 0; i < IterationsNumberForEstimate; ++i) {
+  for (unsigned i = 0; i < IterationsNumberForEstimate; ++i)
     NumberOfOptimizedInstructions +=
     NumberOfOptimizedInstructions +=
-        UA.estimateNumberOfSimplifiedInstructions(i);
-    NumberOfOptimizedInstructions += UA.estimateNumberOfDeadInstructions();
-  }
+        UA.estimateNumberOfOptimizedInstructions(i);
+
   NumberOfOptimizedInstructions *= TripCount / IterationsNumberForEstimate;
 
   return NumberOfOptimizedInstructions;
   NumberOfOptimizedInstructions *= TripCount / IterationsNumberForEstimate;
 
   return NumberOfOptimizedInstructions;