Line 423... |
Line 423... |
}
|
}
|
}
|
}
|
cuc_check (f);
|
cuc_check (f);
|
}
|
}
|
|
|
|
/* Does simplification on blocks A, B, C:
|
|
A->B->C, A->C to just A->B->C */
|
|
static void simplify_bb (cuc_func *f, int pred, int s1, int s2, int neg)
|
|
{
|
|
cuc_insn *last;
|
|
int i;
|
|
if (cuc_debug >= 3) print_cuc_bb (f, "BEFORE_SIMPLIFY");
|
|
cucdebug (3, "simplify %x->%x->%x (%i)\n", pred, s1, s2, neg);
|
|
assert (s2 != pred); /* Shouldn't occur => stupid */
|
|
f->bb[pred].next[1] = -1;
|
|
f->bb[pred].next[0] = s1;
|
|
|
|
if (f->bb[s2].prev[0] == pred) {
|
|
f->bb[s2].prev[0] = f->bb[s2].prev[1];
|
|
f->bb[s2].prev[1] = -1;
|
|
} else if (f->bb[s2].prev[1] == pred) {
|
|
f->bb[s2].prev[1] = -1;
|
|
} else assert (0);
|
|
|
|
last = &f->bb[pred].insn[f->bb[pred].ninsn - 1];
|
|
assert (last->type & IT_BRANCH);
|
|
for (i = 0; i < f->bb[s2].ninsn; i++) {
|
|
cuc_insn *ii= &f->bb[s2].insn[i];
|
|
if (ii->index == II_LRBB) {
|
|
change_insn_type (ii, II_CMOV);
|
|
ii->type = IT_COND;
|
|
ii->op[1] = neg ? 0 : 1; ii->opt[1] = OPT_CONST;
|
|
ii->op[2] = neg ? 1 : 0; ii->opt[2] = OPT_CONST;
|
|
ii->op[3] = last->op[1]; ii->opt[3] = last->opt[1];
|
|
}
|
|
}
|
|
change_insn_type (last, II_NOP);
|
|
if (cuc_debug >= 3) print_cuc_bb (f, "AFTER_SIMPLIFY");
|
|
}
|
|
|
/* type == 0; keep predecessor condition
|
/* type == 0; keep predecessor condition
|
* type == 1; keep successor condition
|
* type == 1; keep successor condition
|
* type == 2; join loop unrolled blocks */
|
* type == 2; join loop unrolled blocks */
|
static void join_bb (cuc_func *f, int pred, int succ, int type)
|
static void join_bb (cuc_func *f, int pred, int succ, int type)
|
{
|
{
|
Line 764... |
Line 799... |
join_bb (f, p, i, 2);
|
join_bb (f, p, i, 2);
|
modified = 1;
|
modified = 1;
|
goto remove_lrbb;
|
goto remove_lrbb;
|
}
|
}
|
}
|
}
|
|
|
|
/* BB simplify:
|
|
1. a block has exactly 2 successors A and B
|
|
2. A has exactly one successor -- B
|
|
3. A has no memory accesses
|
|
to:
|
|
flow always goes though A, LRBB is replaced by current block conditional
|
|
*/
|
|
for (i = 0; i < f->num_bb; i++) if (!(f->bb[i].type & BB_DEAD))
|
|
if (f->bb[i].next[0] >= 0 && f->bb[i].next[0] != BBID_END
|
|
&& f->bb[i].next[1] >= 0 && f->bb[i].next[1] != BBID_END) {
|
|
int a = f->bb[i].next[0];
|
|
int b = f->bb[i].next[1];
|
|
int neg = 0;
|
|
/* Exchange? */
|
|
if (f->bb[b].next[0] == a && f->bb[b].next[1] < 0) {
|
|
int t = a;
|
|
a = b;
|
|
b = t;
|
|
neg = 1;
|
|
}
|
|
/* Do the simplification if possible */
|
|
if (f->bb[a].next[0] == b && f->bb[a].next[1] < 0
|
|
&& f->bb[a].nmemory == 0) {
|
|
simplify_bb (f, i, a, b, neg);
|
|
modified = 1;
|
|
goto remove_lrbb;
|
|
}
|
|
}
|
|
|
return modified;
|
return modified;
|
}
|
}
|
|
|
/* Removes BBs marked as dead */
|
/* Removes BBs marked as dead */
|
int remove_dead_bb (cuc_func *f)
|
int remove_dead_bb (cuc_func *f)
|