glsl2: Allow copy / constant propagation into array indices
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 27 Aug 2010 23:22:36 +0000 (16:22 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 3 Sep 2010 18:55:22 +0000 (11:55 -0700)
src/glsl/ir_constant_propagation.cpp
src/glsl/ir_copy_propagation.cpp

index 76c1ce7013fe52ab003a5f22866ee1efaeb361b2..f7a0599f425e4f2dc5fe262925d8b4b603c591f0 100644 (file)
@@ -90,7 +90,7 @@ public:
    virtual ir_visitor_status visit_enter(class ir_loop *);
    virtual ir_visitor_status visit_enter(class ir_function_signature *);
    virtual ir_visitor_status visit_enter(class ir_function *);
-   virtual ir_visitor_status visit_enter(class ir_assignment *);
+   virtual ir_visitor_status visit_leave(class ir_assignment *);
    virtual ir_visitor_status visit_enter(class ir_call *);
    virtual ir_visitor_status visit_enter(class ir_if *);
 
@@ -119,7 +119,7 @@ public:
 void
 ir_constant_propagation_visitor::handle_rvalue(ir_rvalue **rvalue)
 {
-   if (!*rvalue)
+   if (this->in_assignee || !*rvalue)
       return;
 
    const glsl_type *type = (*rvalue)->type;
@@ -216,22 +216,16 @@ ir_constant_propagation_visitor::visit_enter(ir_function_signature *ir)
 }
 
 ir_visitor_status
-ir_constant_propagation_visitor::visit_enter(ir_assignment *ir)
+ir_constant_propagation_visitor::visit_leave(ir_assignment *ir)
 {
-   /* Inline accepting children, skipping the LHS. */
-   ir->rhs->accept(this);
-   handle_rvalue(&ir->rhs);
-
-   if (ir->condition) {
-      ir->condition->accept(this);
-      handle_rvalue(&ir->condition);
-   }
+   if (this->in_assignee)
+      return visit_continue;
 
    kill(ir->lhs->variable_referenced(), ir->write_mask);
 
    add_constant(ir);
 
-   return visit_continue_with_parent;
+   return visit_continue;
 }
 
 ir_visitor_status
index 6c211f0e70a5535f21329feac35bbe6729457f84..0fe8fa6c41959e8c3a7d0cac8e8844e964388e3f 100644 (file)
@@ -84,7 +84,7 @@ public:
    virtual ir_visitor_status visit_enter(class ir_loop *);
    virtual ir_visitor_status visit_enter(class ir_function_signature *);
    virtual ir_visitor_status visit_enter(class ir_function *);
-   virtual ir_visitor_status visit_enter(class ir_assignment *);
+   virtual ir_visitor_status visit_leave(class ir_assignment *);
    virtual ir_visitor_status visit_enter(class ir_call *);
    virtual ir_visitor_status visit_enter(class ir_if *);
 
@@ -132,30 +132,13 @@ ir_copy_propagation_visitor::visit_enter(ir_function_signature *ir)
 }
 
 ir_visitor_status
-ir_copy_propagation_visitor::visit_enter(ir_assignment *ir)
+ir_copy_propagation_visitor::visit_leave(ir_assignment *ir)
 {
-   ir_visitor_status s;
-
-   /* ir_assignment::accept(ir_hv *v), skipping the LHS so that we can
-    * avoid copy propagating into the LHS.
-    *
-    * Note that this means we won't copy propagate into the derefs of
-    * an array index.  Oh well.
-    */
-
-   s = ir->rhs->accept(this);
-   assert(s == visit_continue);
-
-   if (ir->condition) {
-      s = ir->condition->accept(this);
-      assert(s == visit_continue);
-   }
-
    kill(ir->lhs->variable_referenced());
 
    add_copy(ir);
 
-   return visit_continue_with_parent;
+   return visit_continue;
 }
 
 ir_visitor_status
@@ -175,6 +158,9 @@ ir_copy_propagation_visitor::visit_enter(ir_function *ir)
 ir_visitor_status
 ir_copy_propagation_visitor::visit(ir_dereference_variable *ir)
 {
+   if (this->in_assignee)
+      return visit_continue;
+
    ir_variable *var = ir->var;
 
    foreach_iter(exec_list_iterator, iter, *this->acp) {