aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <[email protected]>2014-05-05 15:29:36 +0800
committerTeddy <[email protected]>2014-05-05 15:29:36 +0800
commit9d9e53fc4f3205e42dbf2650a6675b3678311a94 (patch)
treeaf9c6e8957062470fc41b6fdecc1327582d01e8e
parent9d5a3d9e203572a1e33a3690c2fad5e03426e4c0 (diff)
very poor subexp opt
-rw-r--r--ssa.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/ssa.c b/ssa.c
index 79d7b1a..80f9021 100644
--- a/ssa.c
+++ b/ssa.c
@@ -1906,6 +1906,19 @@ void init_def(void) {
cinterv_union(pi->dest, pi->oprs[i]);
}
}
+ for (def = raw_defs; def; def = def->next)
+ {
+ COpr_t opr = def->opr;
+ opr->spill = cinterv_repr(opr);
+ }
+ /* coalescing */
+ for (p = entry; p; p = p->next)
+ {
+ CInst_t i, ih = p->insts;
+ for (i = ih->next; i != ih; i = i->next)
+ if (i->op == MOVE && i->dest->kind == TMP && i->src1->kind == TMP)
+ cinterv_union(i->dest, i->src1);
+ }
}
void print_intervals(void) {
@@ -2139,9 +2152,9 @@ void register_alloc(void) {
for (p = raw_defs; p; p = p->next)
{
COpr_t opr = p->opr;
- opr->spill = cinterv_repr(opr);
+/* opr->spill = cinterv_repr(opr); */
if (cinterv_repr(opr)->range)
- opr->reg = opr->spill->reg;
+ opr->reg = cinterv_repr(opr)->reg;
}
defs = NULL;
for (i = 0; i < dn; i++)
@@ -2405,7 +2418,7 @@ void subexp_elimination(void) {
}
else if (i->op == CALL)
{
- cexpmap_clear(cem);
+ /* cexpmap_clear(cem); */
continue;
}
copr_shortcut(&i->src1);
@@ -2437,6 +2450,33 @@ void subexp_elimination(void) {
cexpmap_destroy(cem);
}
+void deadcode_elimination() {
+ int i;
+ for (i = bcnt - 1; i >= 0; i--)
+ {
+ CBlock_t b = blks[vis[i]];
+ CInst_t i, ih = b->insts;
+ for (i = ih->next; i != ih; i = i->next)
+ {
+ if (i->src1) i->src1->dep = 1;
+ if (i->src2) i->src2->dep = 1;
+ if (i->op == WARR && i->dest) i->dest->dep = 1;
+ }
+ }
+ for (i = bcnt - 1; i >= 0; i--)
+ {
+ CBlock_t b = blks[vis[i]];
+ CInst_t i, ih = b->insts;
+ for (i = ih->next; i != ih; i = i->next)
+ if (i->op != CALL && i->dest && i->dest->kind == TMP && !i->dest->dep)
+ {
+ i->next->prev = i->prev;
+ i->prev->next = i->next;
+ free(i);
+ }
+ }
+}
+
void ssa_func(CType_t func) {
#define OPRS_ADD(_opr) \
do { \
@@ -2512,8 +2552,9 @@ void ssa_func(CType_t func) {
renaming_vars(oprs);
/* optimization on SSA */
const_propagation();
- subexp_elimination();
+/* subexp_elimination(); */
strength_reduction();
+ deadcode_elimination();
/* out of SSA */
mark_insts();
build_intervals();