SB_RUN_PASS(psi_ops, 1);
SB_RUN_PASS(liveness, 0);
+
+ sh->dce_flags = DF_REMOVE_DEAD | DF_EXPAND;
SB_RUN_PASS(dce_cleanup, 0);
SB_RUN_PASS(def_use, 0);
SB_RUN_PASS(gvn, 1);
- SB_RUN_PASS(liveness, 0);
+ SB_RUN_PASS(def_use, 1);
+
+ sh->dce_flags = DF_REMOVE_DEAD | DF_REMOVE_UNUSED;
SB_RUN_PASS(dce_cleanup, 1);
- SB_RUN_PASS(def_use, 0);
SB_RUN_PASS(ra_split, 0);
SB_RUN_PASS(def_use, 0);
sh->compute_interferences = true;
SB_RUN_PASS(liveness, 0);
+ sh->dce_flags = DF_REMOVE_DEAD;
+ SB_RUN_PASS(dce_cleanup, 1);
+
SB_RUN_PASS(ra_coalesce, 1);
SB_RUN_PASS(ra_init, 1);
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;
}
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)
+ n.remove();
}
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)
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))
v = NULL;
+ else
+ alive = true;
}
+
+ return alive;
}
} // namespace r600_sb
class dce_cleanup : public vpass {
using vpass::visit;
+ bool remove_unused;
+
public:
- dce_cleanup(shader &s) : vpass(s) {}
+ dce_cleanup(shader &s) : vpass(s),
+ remove_unused(s.dce_flags & DF_REMOVE_UNUSED) {}
virtual bool visit(node &n, bool enter);
virtual bool visit(alu_group_node &n, bool enter);
private:
void cleanup_dst(node &n);
- void cleanup_dst_vec(vvec &vv);
+ bool cleanup_dst_vec(vvec &vv);
};
RCF_PREALLOC = (1 << 4)
};
+enum dce_flags {
+ DF_REMOVE_DEAD = (1 << 0),
+ DF_REMOVE_UNUSED = (1 << 1),
+ DF_EXPAND = (1 << 2),
+};
+
+inline dce_flags operator |(dce_flags l, dce_flags r) {
+ return (dce_flags)((unsigned)l|(unsigned)r);
+}
+
inline chunk_flags operator |(chunk_flags l, chunk_flags r) {
return (chunk_flags)((unsigned)l|(unsigned)r);
}
unsigned ngpr, nstack;
+ unsigned dce_flags;
+
shader(sb_context &sctx, shader_target t, unsigned id);
~shader();