From: Eric Anholt Date: Tue, 6 Apr 2010 18:52:09 +0000 (-0700) Subject: Make constant folding descend into if statements. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=70b74928a220aff024664714877defb0caedf33f;p=mesa.git Make constant folding descend into if statements. --- diff --git a/glsl_parser_extras.cpp b/glsl_parser_extras.cpp index 84a3fd90715..538d77c663c 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 */ diff --git a/ir.cpp b/ir.cpp index 0708e492850..99a966e1540 100644 --- 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 a515d9a7d0a..adc14055724 100644 --- 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, diff --git a/ir_constant_folding.cpp b/ir_constant_folding.cpp index eabdc240ad3..af6674c3f6e 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); }