[Mesa-dev] [RFC PATCH 08/10] glsl/loops: Get rid of loop_variable_state::max_iterations.

Paul Berry stereotype441 at gmail.com
Sat Nov 30 08:38:17 PST 2013


This value is now redundant with
loop_variable_state::limiting_terminator->iterations and
ir_loop::normative_bound.
---
 src/glsl/loop_analysis.h   | 10 ----------
 src/glsl/loop_controls.cpp | 41 ++++++++++++++++-------------------------
 src/glsl/loop_unroll.cpp   |  6 +++---
 3 files changed, 19 insertions(+), 38 deletions(-)

diff --git a/src/glsl/loop_analysis.h b/src/glsl/loop_analysis.h
index 0208890..ae98056 100644
--- a/src/glsl/loop_analysis.h
+++ b/src/glsl/loop_analysis.h
@@ -119,15 +119,6 @@ public:
    hash_table *var_hash;
 
    /**
-    * Maximum number of loop iterations.
-    *
-    * If this value is negative, then the loop may be infinite.  This actually
-    * means that analysis was unable to determine an upper bound on the number
-    * of loop iterations.
-    */
-   int max_iterations;
-
-   /**
     * Number of ir_loop_jump instructions that operate on this loop
     */
    unsigned num_loop_jumps;
@@ -139,7 +130,6 @@ public:
 
    loop_variable_state()
    {
-      this->max_iterations = -1;
       this->num_loop_jumps = 0;
       this->contains_calls = false;
       this->var_hash = hash_table_ctor(0, hash_table_pointer_hash,
diff --git a/src/glsl/loop_controls.cpp b/src/glsl/loop_controls.cpp
index a14ea6b..9e32ff5 100644
--- a/src/glsl/loop_controls.cpp
+++ b/src/glsl/loop_controls.cpp
@@ -183,24 +183,23 @@ loop_control_visitor::visit_leave(ir_loop *ir)
       return visit_continue;
    }
 
-   /* Figure out how many times the loop will run based on the iteration count
-    * annotations made by loop analysis, and give the loop a normative bound
-    * if possible.
-    */
-   unsigned max_iterations =
-      ls->max_iterations < 0 ? INT_MAX : ls->max_iterations;
-
-   if (ir->normative_bound >= 0)
-      max_iterations = ir->normative_bound;
+   if (ls->limiting_terminator != NULL) {
+      /* If the limiting terminator has an iteration count of zero, then we've
+       * proven that the loop cannot run, so delete it.
+       */
+      int iterations = ls->limiting_terminator->iterations;
+      if (iterations == 0) {
+         ir->remove();
+         this->progress = true;
+         return visit_continue;
+      }
 
-   /* If the limiting terminator has a lower iteration count than we'd
-    * previously inferred for this loop, then make the new iteration count the
-    * normative bound for this loop.
-    */
-   if (ls->limiting_terminator != NULL &&
-       (unsigned) ls->limiting_terminator->iterations < max_iterations) {
-      ir->normative_bound = ls->limiting_terminator->iterations;
-      max_iterations = ls->limiting_terminator->iterations;
+      /* If the limiting terminator has a lower iteration count than the
+       * normative loop bound (if any), then make this a normatively bounded
+       * loop with the new iteration count.
+       */
+      if (ir->normative_bound < 0 || iterations < ir->normative_bound)
+         ir->normative_bound = iterations;
    }
 
    /* Remove the conditional break statements associated with all terminators
@@ -221,14 +220,6 @@ loop_control_visitor::visit_leave(ir_loop *ir)
       this->progress = true;
    }
 
-   /* If we have proven the one of the loop exit conditions is satisifed before
-    * running the loop once, remove the loop.
-    */
-   if (max_iterations == 0)
-      ir->remove();
-   else
-      ls->max_iterations = max_iterations;
-
    return visit_continue;
 }
 
diff --git a/src/glsl/loop_unroll.cpp b/src/glsl/loop_unroll.cpp
index e100916..9472bc5 100644
--- a/src/glsl/loop_unroll.cpp
+++ b/src/glsl/loop_unroll.cpp
@@ -236,14 +236,14 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
       return visit_continue;
    }
 
-   iterations = ls->max_iterations;
-
    /* Don't try to unroll loops where the number of iterations is not known
     * at compile-time.
     */
-   if (iterations < 0)
+   if (ir->normative_bound < 0)
       return visit_continue;
 
+   iterations = ir->normative_bound;
+
    /* Don't try to unroll loops that have zillions of iterations either.
     */
    if (iterations > (int) max_iterations)
-- 
1.8.4.2



More information about the mesa-dev mailing list