glsl: add several EmitNo* options, and MaxUnrollIterations

This increases the chance that GLSL programs will actually work.

Note that continues and returns are not yet lowered, so linking
will just fail if not supported.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 3dbec5d..400203d 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -685,7 +685,7 @@
 }
 
 bool
-do_common_optimization(exec_list *ir, bool linked)
+do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations)
 {
    GLboolean progress = GL_FALSE;
 
@@ -718,7 +718,7 @@
 
    loop_state *ls = analyze_loop_variables(ir);
    progress = set_loop_controls(ir, ls) || progress;
-   progress = unroll_loops(ir, ls) || progress;
+   progress = unroll_loops(ir, ls, max_unroll_iterations) || progress;
    delete ls;
 
    return progress;
diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h
index 33f4bc7..df25673 100644
--- a/src/glsl/ir_optimization.h
+++ b/src/glsl/ir_optimization.h
@@ -28,7 +28,7 @@
  * Prototypes for optimization passes to be called by the compiler and drivers.
  */
 
-bool do_common_optimization(exec_list *ir, bool linked);
+bool do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations);
 
 bool do_algebraic(exec_list *instructions);
 bool do_constant_folding(exec_list *instructions);
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 78f3a74..c2c6621 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -1471,7 +1471,7 @@
     * some of that unused.
     */
    for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) {
-      while (do_common_optimization(prog->_LinkedShaders[i]->ir, true))
+      while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, 32))
 	 ;
    }
 
diff --git a/src/glsl/loop_analysis.h b/src/glsl/loop_analysis.h
index 893dd46..7b0511f 100644
--- a/src/glsl/loop_analysis.h
+++ b/src/glsl/loop_analysis.h
@@ -57,7 +57,7 @@
 
 
 extern bool
-unroll_loops(exec_list *instructions, loop_state *ls);
+unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations);
 
 
 /**
diff --git a/src/glsl/loop_unroll.cpp b/src/glsl/loop_unroll.cpp
index e204251..80f9217 100644
--- a/src/glsl/loop_unroll.cpp
+++ b/src/glsl/loop_unroll.cpp
@@ -27,10 +27,11 @@
 
 class loop_unroll_visitor : public ir_hierarchical_visitor {
 public:
-   loop_unroll_visitor(loop_state *state)
+   loop_unroll_visitor(loop_state *state, unsigned max_iterations)
    {
       this->state = state;
       this->progress = false;
+      this->max_iterations = max_iterations;
    }
 
    virtual ir_visitor_status visit_leave(ir_loop *ir);
@@ -38,6 +39,7 @@
    loop_state *state;
 
    bool progress;
+   unsigned max_iterations;
 };
 
 
@@ -62,7 +64,7 @@
 
    /* Don't try to unroll loops that have zillions of iterations either.
     */
-   if (ls->max_iterations > 32)
+   if (ls->max_iterations > max_iterations)
       return visit_continue;
 
    if (ls->num_loop_jumps > 0)
@@ -90,9 +92,9 @@
 
 
 bool
-unroll_loops(exec_list *instructions, loop_state *ls)
+unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations)
 {
-   loop_unroll_visitor v(ls);
+   loop_unroll_visitor v(ls, max_iterations);
 
    v.run(instructions);
 
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index 2a7a713..94c14a5 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -215,7 +215,7 @@
 
 	 loop_state *ls = analyze_loop_variables(shader->ir);
 	 progress = set_loop_controls(shader->ir, ls) || progress;
-	 progress = unroll_loops(shader->ir, ls) || progress;
+	 progress = unroll_loops(shader->ir, ls, 32) || progress;
 	 delete ls;
       } while (progress);