const struct gl_shader_compiler_options *options,
bool native_integers);
+bool ir_constant_fold(ir_rvalue **rvalue);
+
bool do_rebalance_tree(exec_list *instructions);
bool do_algebraic(exec_list *instructions, bool native_integers,
const struct gl_shader_compiler_options *options);
} /* unnamed namespace */
-void
-ir_constant_folding_visitor::handle_rvalue(ir_rvalue **rvalue)
+bool
+ir_constant_fold(ir_rvalue **rvalue)
{
if (*rvalue == NULL || (*rvalue)->ir_type == ir_type_constant)
- return;
+ return false;
/* Note that we do rvalue visitoring on leaving. So if an
* expression has a non-constant operand, no need to go looking
if (expr) {
for (unsigned int i = 0; i < expr->get_num_operands(); i++) {
if (!expr->operands[i]->as_constant())
- return;
+ return false;
}
}
/* Ditto for swizzles. */
ir_swizzle *swiz = (*rvalue)->as_swizzle();
if (swiz && !swiz->val->as_constant())
- return;
+ return false;
ir_constant *constant = (*rvalue)->constant_expression_value();
if (constant) {
*rvalue = constant;
- this->progress = true;
+ return true;
}
+ return false;
+}
+
+void
+ir_constant_folding_visitor::handle_rvalue(ir_rvalue **rvalue)
+{
+ if (ir_constant_fold(rvalue))
+ this->progress = true;
}
ir_visitor_status
void
-ir_constant_propagation_visitor::constant_folding(ir_rvalue **rvalue) {
-
- if (*rvalue == NULL || (*rvalue)->ir_type == ir_type_constant)
- return;
-
- /* Note that we visit rvalues one leaving. So if an expression has a
- * non-constant operand, no need to go looking down it to find if it's
- * constant. This cuts the time of this pass down drastically.
- */
- ir_expression *expr = (*rvalue)->as_expression();
- if (expr) {
- for (unsigned int i = 0; i < expr->get_num_operands(); i++) {
- if (!expr->operands[i]->as_constant())
- return;
- }
- }
-
- /* Ditto for swizzles. */
- ir_swizzle *swiz = (*rvalue)->as_swizzle();
- if (swiz && !swiz->val->as_constant())
- return;
-
- ir_constant *constant = (*rvalue)->constant_expression_value();
- if (constant) {
- *rvalue = constant;
+ir_constant_propagation_visitor::constant_folding(ir_rvalue **rvalue)
+{
+ if (ir_constant_fold(rvalue))
this->progress = true;
- }
}
void