summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-04-06 11:52:09 -0700
committerEric Anholt <eric@anholt.net>2010-04-06 11:52:09 -0700
commit70b74928a220aff024664714877defb0caedf33f (patch)
tree25654ba34cbf54d81ae0ec3aa8dfb8e68e6ee4a5
parente5a9e70cde3dda27dca045b12c5a818215b1a449 (diff)
Make constant folding descend into if statements.
-rw-r--r--glsl_parser_extras.cpp6
-rw-r--r--ir.cpp10
-rw-r--r--ir.h2
-rw-r--r--ir_constant_folding.cpp3
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 */
diff --git a/ir.cpp b/ir.cpp
index 0708e49285..99a966e154 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 a515d9a7d0..adc1405572 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 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);
}