Make constant folding descend into if statements.
authorEric Anholt <eric@anholt.net>
Tue, 6 Apr 2010 18:52:09 +0000 (11:52 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 6 Apr 2010 18:52:09 +0000 (11:52 -0700)
glsl_parser_extras.cpp
ir.cpp
ir.h
ir_constant_folding.cpp

index 84a3fd907154bcbd7d633e28fa6b58d551907904..538d77c663cd20dbcf2f70d102aea9354af25768 100644 (file)
@@ -651,10 +651,8 @@ main(int argc, char **argv)
    /* Optimization passes */
    if (!state.error) {
       /* Constant folding */
-      foreach_iter(exec_list_iterator, iter, instructions) {
-        ir_constant_folding_visitor v;
-        ((ir_instruction *)iter.get())->accept(& v);
-      }
+      ir_constant_folding_visitor constant_folding;
+      visit_exec_list(&instructions, &constant_folding);
    }
 
    /* Print out the resulting IR */
diff --git a/ir.cpp b/ir.cpp
index 0708e492850f48b9359d09a9cbda71e5d8b5411e..99a966e1540c39a776852aac644f68a130d5f5d7 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -24,6 +24,7 @@
 #include "main/imports.h"
 #include "main/simple_list.h"
 #include "ir.h"
+#include "ir_visitor.h"
 #include "glsl_types.h"
 
 ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs,
@@ -367,3 +368,12 @@ ir_call::get_error_instruction()
    call->type = glsl_type::error_type;
    return call;
 }
+
+void
+visit_exec_list(exec_list *list, ir_visitor *visitor)
+{
+   foreach_iter(exec_list_iterator, iter, *list) {
+      ((ir_instruction *)iter.get())->accept(visitor);
+   }
+}
+
diff --git a/ir.h b/ir.h
index a515d9a7d0af58bb397f525284eace59440603c1..adc1405572497b1c19351cbbac5afd0e68ba04c5 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -607,6 +607,8 @@ public:
    } value;
 };
 
+void
+visit_exec_list(exec_list *list, ir_visitor *visitor);
 
 extern void
 _mesa_glsl_initialize_variables(exec_list *instructions,
index eabdc240ad34a3b4dbae7c75a67e3b1e55f7d53b..af6674c3f6e74ef48284ff9133b1ede1a27e68cc 100644 (file)
@@ -141,4 +141,7 @@ ir_constant_folding_visitor::visit(ir_if *ir)
       ir->condition = const_val;
    else
       ir->condition->accept(this);
+
+   visit_exec_list(&ir->then_instructions, this);
+   visit_exec_list(&ir->else_instructions, this);
 }