Mesa (master): glsl: Use ir_builder more in opt_algebraic.

Eric Anholt anholt at kemper.freedesktop.org
Mon Oct 28 21:16:43 UTC 2013


Module: Mesa
Branch: master
Commit: 3a0fdf2ab6ab9c66c50645409d8f79bcd6f8ed1b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3a0fdf2ab6ab9c66c50645409d8f79bcd6f8ed1b

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Oct 24 15:03:45 2013 -0700

glsl: Use ir_builder more in opt_algebraic.

While ir_builder is slightly less efficient, we're only increasing the
work when there's actual optimization being done, and it's way more
readable code.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Matt Turner <mattst88 at gmail.com>

---

 src/glsl/opt_algebraic.cpp |   40 ++++++++++------------------------------
 1 files changed, 10 insertions(+), 30 deletions(-)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 8d02cad..2e33dfe 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -219,10 +219,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       switch (op_expr[0]->operation) {
       case ir_unop_abs:
       case ir_unop_neg:
-         return new(mem_ctx) ir_expression(ir_unop_abs,
-                                           ir->type,
-                                           op_expr[0]->operands[0],
-                                           NULL);
+         return abs(op_expr[0]->operands[0]);
       default:
          break;
       }
@@ -285,12 +282,8 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       break;
 
    case ir_binop_sub:
-      if (is_vec_zero(op_const[0])) {
-	 return new(mem_ctx) ir_expression(ir_unop_neg,
-					   ir->operands[1]->type,
-					   ir->operands[1],
-					   NULL);
-      }
+      if (is_vec_zero(op_const[0]))
+	 return neg(ir->operands[1]);
       if (is_vec_zero(op_const[1]))
 	 return ir->operands[0];
       break;
@@ -304,18 +297,10 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1]))
 	 return ir_constant::zero(ir, ir->type);
 
-      if (is_vec_negative_one(op_const[0])) {
-         return new(mem_ctx) ir_expression(ir_unop_neg,
-                                           ir->operands[1]->type,
-                                           ir->operands[1],
-                                           NULL);
-      }
-      if (is_vec_negative_one(op_const[1])) {
-         return new(mem_ctx) ir_expression(ir_unop_neg,
-                                           ir->operands[0]->type,
-                                           ir->operands[0],
-                                           NULL);
-      }
+      if (is_vec_negative_one(op_const[0]))
+         return neg(ir->operands[1]);
+      if (is_vec_negative_one(op_const[1]))
+         return neg(ir->operands[0]);
 
 
       /* Reassociate multiplication of constants so that we can do
@@ -386,11 +371,9 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       } else if (is_vec_zero(op_const[1])) {
 	 return ir->operands[0];
       } else if (is_vec_one(op_const[0])) {
-	 return new(mem_ctx) ir_expression(ir_unop_logic_not, ir->type,
-					   ir->operands[1], NULL);
+	 return logic_not(ir->operands[1]);
       } else if (is_vec_one(op_const[1])) {
-	 return new(mem_ctx) ir_expression(ir_unop_logic_not, ir->type,
-					   ir->operands[0], NULL);
+	 return logic_not(ir->operands[0]);
       }
       break;
 
@@ -428,10 +411,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
 
       /* As far as we know, all backends are OK with rsq. */
       if (op_expr[0] && op_expr[0]->operation == ir_unop_sqrt) {
-	 return new(mem_ctx) ir_expression(ir_unop_rsq,
-					   op_expr[0]->operands[0]->type,
-					   op_expr[0]->operands[0],
-					   NULL);
+	 return rsq(op_expr[0]->operands[0]);
       }
 
       break;




More information about the mesa-commit mailing list