diff options
author | Kenneth Graunke <[email protected]> | 2016-04-29 14:40:26 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2016-05-15 23:59:20 -0700 |
commit | 329fe93210ce8f603f831ebd8431786d12cd1057 (patch) | |
tree | ede5b4b2a66fe4cce14aa0e3204e7feea0533351 /src/compiler/glsl/opt_constant_folding.cpp | |
parent | 3bf27a9a002fd5c23937e4e34aff35c94824008f (diff) |
glsl: Consolidate duplicate copies of constant folding.
We could probably clean this up more (maybe make it a method), but at
least there's only one copy of this code now, and that's a start.
No change in shader-db.
Signed-off-by: Kenneth Graunke <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/compiler/glsl/opt_constant_folding.cpp')
-rw-r--r-- | src/compiler/glsl/opt_constant_folding.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/compiler/glsl/opt_constant_folding.cpp b/src/compiler/glsl/opt_constant_folding.cpp index de13c9e068e..0ea53a5ed1b 100644 --- a/src/compiler/glsl/opt_constant_folding.cpp +++ b/src/compiler/glsl/opt_constant_folding.cpp @@ -61,11 +61,11 @@ public: } /* 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 @@ -76,20 +76,28 @@ ir_constant_folding_visitor::handle_rvalue(ir_rvalue **rvalue) 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 |