[Mesa-dev] [PATCH 4/6] glsl: Pass gl_shader_compiler_optimizations to unroll_loops().

Kenneth Graunke kenneth at whitecape.org
Tue Apr 8 20:51:52 PDT 2014


Loop unrolling will need to know a few more options in the future.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/glsl_parser_extras.cpp |  2 +-
 src/glsl/loop_analysis.h        |  3 ++-
 src/glsl/loop_unroll.cpp        | 20 +++++++++++++-------
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 1fcd5f8..03c2a97 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1542,7 +1542,7 @@ do_common_optimization(exec_list *ir, bool linked,
    loop_state *ls = analyze_loop_variables(ir);
    if (ls->loop_found) {
       progress = set_loop_controls(ir, ls) || progress;
-      progress = unroll_loops(ir, ls, options->MaxUnrollIterations) || progress;
+      progress = unroll_loops(ir, ls, options) || progress;
    }
    delete ls;
 
diff --git a/src/glsl/loop_analysis.h b/src/glsl/loop_analysis.h
index f841042..295dc79 100644
--- a/src/glsl/loop_analysis.h
+++ b/src/glsl/loop_analysis.h
@@ -53,7 +53,8 @@ set_loop_controls(exec_list *instructions, loop_state *ls);
 
 
 extern bool
-unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations);
+unroll_loops(exec_list *instructions, loop_state *ls,
+             const struct gl_shader_compiler_options *options);
 
 ir_rvalue *
 find_initial_value(ir_loop *loop, ir_variable *var);
diff --git a/src/glsl/loop_unroll.cpp b/src/glsl/loop_unroll.cpp
index 789655e..11680b3 100644
--- a/src/glsl/loop_unroll.cpp
+++ b/src/glsl/loop_unroll.cpp
@@ -25,15 +25,18 @@
 #include "loop_analysis.h"
 #include "ir_hierarchical_visitor.h"
 
+#include "main/mtypes.h"
+
 namespace {
 
 class loop_unroll_visitor : public ir_hierarchical_visitor {
 public:
-   loop_unroll_visitor(loop_state *state, unsigned max_iterations)
+   loop_unroll_visitor(loop_state *state,
+                       const struct gl_shader_compiler_options *options)
    {
       this->state = state;
       this->progress = false;
-      this->max_iterations = max_iterations;
+      this->options = options;
    }
 
    virtual ir_visitor_status visit_leave(ir_loop *ir);
@@ -45,7 +48,7 @@ public:
    loop_state *state;
 
    bool progress;
-   unsigned max_iterations;
+   const struct gl_shader_compiler_options *options;
 };
 
 } /* anonymous namespace */
@@ -244,16 +247,18 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
 
    iterations = ls->limiting_terminator->iterations;
 
+   const int max_iterations = options->MaxUnrollIterations;
+
    /* Don't try to unroll loops that have zillions of iterations either.
     */
-   if (iterations > (int) max_iterations)
+   if (iterations > max_iterations)
       return visit_continue;
 
    /* Don't try to unroll nested loops and loops with a huge body.
     */
    loop_unroll_count count(&ir->body_instructions);
 
-   if (count.fail || count.nodes * iterations > (int)max_iterations * 5)
+   if (count.fail || count.nodes * iterations > max_iterations * 5)
       return visit_continue;
 
    /* Note: the limiting terminator contributes 1 to ls->num_loop_jumps.
@@ -338,9 +343,10 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
 
 
 bool
-unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations)
+unroll_loops(exec_list *instructions, loop_state *ls,
+             const struct gl_shader_compiler_options *options)
 {
-   loop_unroll_visitor v(ls, max_iterations);
+   loop_unroll_visitor v(ls, options);
 
    v.run(instructions);
 
-- 
1.9.1



More information about the mesa-dev mailing list