diff options
author | Eric Anholt <eric@anholt.net> | 2010-04-06 11:52:09 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2010-04-06 11:52:09 -0700 |
commit | 70b74928a220aff024664714877defb0caedf33f (patch) | |
tree | 25654ba34cbf54d81ae0ec3aa8dfb8e68e6ee4a5 | |
parent | e5a9e70cde3dda27dca045b12c5a818215b1a449 (diff) |
Make constant folding descend into if statements.
-rw-r--r-- | glsl_parser_extras.cpp | 6 | ||||
-rw-r--r-- | ir.cpp | 10 | ||||
-rw-r--r-- | ir.h | 2 | ||||
-rw-r--r-- | ir_constant_folding.cpp | 3 |
4 files changed, 17 insertions, 4 deletions
diff --git a/glsl_parser_extras.cpp b/glsl_parser_extras.cpp index 84a3fd9071..538d77c663 100644 --- a/glsl_parser_extras.cpp +++ b/glsl_parser_extras.cpp @@ -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 */ @@ -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); + } +} + @@ -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, diff --git a/ir_constant_folding.cpp b/ir_constant_folding.cpp index eabdc240ad..af6674c3f6 100644 --- a/ir_constant_folding.cpp +++ b/ir_constant_folding.cpp @@ -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); } |