Refactor whole-variable assigment checking into member function
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 26 May 2010 18:32:52 +0000 (11:32 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 26 May 2010 22:23:25 +0000 (15:23 -0700)
ir.h
ir_copy_propagation.cpp
ir_dead_code_local.cpp

diff --git a/ir.h b/ir.h
index 2e6a194..306ec8c 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -95,6 +95,21 @@ public:
       return NULL;
    }
 
+
+   /**
+    * If an r-value is a reference to a whole variable, get that variable
+    *
+    * \return
+    * Pointer to a variable that is completely dereferenced by the r-value.  If
+    * the r-value is not a dereference or the dereference does not access the
+    * entire variable (i.e., it's just one array element, struct field), \c NULL
+    * is returned.
+    */
+   virtual ir_variable *whole_variable_referenced()
+   {
+      return NULL;
+   }
+
 protected:
    ir_rvalue()
    {
@@ -827,6 +842,17 @@ public:
       return this->var;
    }
 
+   virtual ir_variable *whole_variable_referenced()
+   {
+      /* ir_dereference_variable objects always dereference the entire
+       * variable.  However, if this dereference is dereferenced by anything
+       * else, the complete deferefernce chain is not a whole-variable
+       * dereference.  This method should only be called on the top most
+       * ir_rvalue in a dereference chain.
+       */
+      return this->var;
+   }
+
    virtual void accept(ir_visitor *v)
    {
       v->visit(this);
index e395fa9..82172d2 100644 (file)
@@ -267,18 +267,13 @@ add_copy(ir_assignment *ir, exec_list *acp)
         return;
    }
 
-   ir_dereference *lhs_deref = ir->lhs->as_dereference();
-   if (!lhs_deref || lhs_deref->mode != ir_dereference::ir_reference_variable)
-      return;
-   ir_variable *lhs_var = lhs_deref->variable_referenced();
-
-   ir_dereference *rhs_deref = ir->rhs->as_dereference();
-   if (!rhs_deref || rhs_deref->mode != ir_dereference::ir_reference_variable)
-      return;
-   ir_variable *rhs_var = rhs_deref->variable_referenced();
-
-   entry = new acp_entry(lhs_var, rhs_var);
-   acp->push_tail(entry);
+   ir_variable *lhs_var = ir->lhs->whole_variable_referenced();
+   ir_variable *rhs_var = ir->rhs->whole_variable_referenced();
+
+   if ((lhs_var != NULL) && (rhs_var != NULL)) {
+      entry = new acp_entry(lhs_var, rhs_var);
+      acp->push_tail(entry);
+   }
 }
 
 static void
index 9ac209d..e83b300 100644 (file)
@@ -139,10 +139,7 @@ process_assignment(ir_assignment *ir, exec_list *assignments)
    }
 
    /* Now, check if we did a whole-variable assignment. */
-   ir_dereference *lhs_deref = ir->lhs->as_dereference();
-   if (always_assign &&
-       lhs_deref &&
-       lhs_deref->mode == ir_dereference::ir_reference_variable) {
+   if (always_assign && (ir->lhs->whole_variable_referenced() != NULL)) {
       /* We did a whole-variable assignment.  So, any instruction in
        * the assignment list with the same LHS is dead.
        */