r600/sb: use different stacks for tracking lds and queue usage.
[mesa.git] / src / gallium / drivers / r600 / sb / sb_dce_cleanup.cpp
index f879395f67c8327ddeddcaadcc92500ca03449e4..abae2bf69d7e4f59a938146de1c055aa285deed4 100644 (file)
 
 namespace r600_sb {
 
+int dce_cleanup::run() {
+       int r;
+
+       // Run cleanup for as long as there are unused nodes.
+       do {
+               nodes_changed = false;
+               r = vpass::run();
+       } while (r == 0 && nodes_changed);
+
+       return r;
+}
+
 bool dce_cleanup::visit(node& n, bool enter) {
        if (enter) {
        } else {
@@ -56,7 +68,8 @@ bool dce_cleanup::visit(cf_node& n, bool enter) {
                else
                        cleanup_dst(n);
        } else {
-               if (n.bc.op_ptr->flags & (CF_CLAUSE | CF_BRANCH | CF_LOOP))
+               if ((sh.dce_flags & DF_EXPAND) &&
+                               (n.bc.op_ptr->flags & (CF_CLAUSE | CF_BRANCH | CF_LOOP)))
                        n.expand();
        }
        return true;
@@ -107,19 +120,31 @@ bool dce_cleanup::visit(region_node& n, bool enter) {
 }
 
 void dce_cleanup::cleanup_dst(node& n) {
-       cleanup_dst_vec(n.dst);
+       if (!cleanup_dst_vec(n.dst) && remove_unused &&
+                       !n.dst.empty() && !(n.flags & NF_DONT_KILL) && n.parent)
+       {
+               // Delete use references to the removed node from the src values.
+               for (vvec::iterator I = n.src.begin(), E = n.src.end(); I != E; ++I) {
+                       value* v = *I;
+                       if (v && v->def && v->uses.size())
+                       {
+                               v->remove_use(&n);
+                       }
+               }
+               n.remove();
+               nodes_changed = true;
+       }
 }
 
 bool dce_cleanup::visit(container_node& n, bool enter) {
-       if (enter) {
+       if (enter)
                cleanup_dst(n);
-       } else {
-
-       }
        return true;
 }
 
-void dce_cleanup::cleanup_dst_vec(vvec& vv) {
+bool dce_cleanup::cleanup_dst_vec(vvec& vv) {
+       bool alive = false;
+
        for (vvec::iterator I = vv.begin(), E = vv.end(); I != E; ++I) {
                value* &v = *I;
                if (!v)
@@ -128,9 +153,13 @@ void dce_cleanup::cleanup_dst_vec(vvec& vv) {
                if (v->gvn_source && v->gvn_source->is_dead())
                        v->gvn_source = NULL;
 
-               if (v->is_dead())
+               if (v->is_dead() || (remove_unused && !v->is_rel() && !v->uses.size()))
                        v = NULL;
+               else
+                       alive = true;
        }
+
+       return alive;
 }
 
 } // namespace r600_sb