Mesa (master): glsl: Make ir_algebraic new expressions allocate out of the parent.

Eric Anholt anholt at kemper.freedesktop.org
Tue Aug 17 20:56:28 UTC 2010


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

Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 17 13:27:44 2010 -0700

glsl: Make ir_algebraic new expressions allocate out of the parent.

This could reduce the amount of memory used by a shader tree after
optimization, and increases consistency with other passes.

---

 src/glsl/ir_algebraic.cpp |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/src/glsl/ir_algebraic.cpp b/src/glsl/ir_algebraic.cpp
index a66c820..0092eea 100644
--- a/src/glsl/ir_algebraic.cpp
+++ b/src/glsl/ir_algebraic.cpp
@@ -43,6 +43,7 @@ public:
    ir_algebraic_visitor()
    {
       this->progress = false;
+      this->mem_ctx = NULL;
    }
 
    virtual ~ir_algebraic_visitor()
@@ -59,6 +60,8 @@ public:
 			     int op1,
 			     ir_expression *ir2,
 			     int op2);
+
+   void *mem_ctx;
    bool progress;
 };
 
@@ -231,6 +234,9 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       op_expr[i] = ir->operands[i]->as_expression();
    }
 
+   if (this->mem_ctx == NULL)
+      this->mem_ctx = talloc_parent(ir);
+
    switch (ir->operation) {
    case ir_unop_logic_not: {
       enum ir_expression_operation new_op = ir_unop_logic_not;
@@ -254,10 +260,10 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
 
       if (new_op != ir_unop_logic_not) {
 	 this->progress = true;
-	 return new(ir) ir_expression(new_op,
-				      ir->type,
-				      op_expr[0]->operands[0],
-				      op_expr[0]->operands[1]);
+	 return new(mem_ctx) ir_expression(new_op,
+					   ir->type,
+					   op_expr[0]->operands[0],
+					   op_expr[0]->operands[1]);
       }
 
       break;
@@ -287,10 +293,10 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
    case ir_binop_sub:
       if (is_vec_zero(op_const[0])) {
 	 this->progress = true;
-	 return new(ir) ir_expression(ir_unop_neg,
-				      ir->type,
-				      ir->operands[1],
-				      NULL);
+	 return new(mem_ctx) ir_expression(ir_unop_neg,
+					   ir->type,
+					   ir->operands[1],
+					   NULL);
       }
       if (is_vec_zero(op_const[1])) {
 	 this->progress = true;
@@ -328,10 +334,10 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
    case ir_binop_div:
       if (is_vec_one(op_const[0]) && ir->type->base_type == GLSL_TYPE_FLOAT) {
 	 this->progress = true;
-	 return new(ir) ir_expression(ir_unop_rcp,
-				      ir->type,
-				      ir->operands[1],
-				      NULL);
+	 return new(mem_ctx) ir_expression(ir_unop_rcp,
+					   ir->type,
+					   ir->operands[1],
+					   NULL);
       }
       if (is_vec_one(op_const[1])) {
 	 this->progress = true;
@@ -353,10 +359,10 @@ 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) {
 	 this->progress = true;
-	 return new(ir) ir_expression(ir_unop_rsq,
-				      ir->type,
-				      op_expr[0]->operands[0],
-				      NULL);
+	 return new(mem_ctx) ir_expression(ir_unop_rsq,
+					   ir->type,
+					   op_expr[0]->operands[0],
+					   NULL);
       }
 
       break;




More information about the mesa-commit mailing list