Line 162... |
Line 162... |
f->bb[f->num_bb].ntim = 0;
|
f->bb[f->num_bb].ntim = 0;
|
f->num_bb++;
|
f->num_bb++;
|
assert (f->num_bb < MAX_BB);
|
assert (f->num_bb < MAX_BB);
|
}
|
}
|
}
|
}
|
if (DEBUG > 3) print_cuc_bb (f, "AFTER_INIT");
|
if (cuc_debug >= 3) print_cuc_bb (f, "AFTER_INIT");
|
|
|
/* Build forward connections between BBs */
|
/* Build forward connections between BBs */
|
for (i = 0; i < f->num_bb; i++)
|
for (i = 0; i < f->num_bb; i++)
|
if (insn[f->bb[i].last].type & IT_BRANCH) {
|
if (insn[f->bb[i].last].type & IT_BRANCH) {
|
int j;
|
int j;
|
Line 189... |
Line 189... |
} else {
|
} else {
|
f->bb[i].next[0] = i + 1;
|
f->bb[i].next[0] = i + 1;
|
if (++f->bb[i + 1].tmp > 2) eb++;
|
if (++f->bb[i + 1].tmp > 2) eb++;
|
}
|
}
|
|
|
if (DEBUG > 3) print_cuc_bb (f, "AFTER_NEXT");
|
if (cuc_debug >= 3) print_cuc_bb (f, "AFTER_NEXT");
|
|
|
/* Build backward connections, but first insert artificial blocks
|
/* Build backward connections, but first insert artificial blocks
|
* to handle more than 2 connections */
|
* to handle more than 2 connections */
|
debug (6, "artificial %i %i\n", f->num_bb, eb);
|
cucdebug (6, "artificial %i %i\n", f->num_bb, eb);
|
end_bb = f->num_bb + eb;
|
end_bb = f->num_bb + eb;
|
for (i = f->num_bb - 1; i >= 0; i--) {
|
for (i = f->num_bb - 1; i >= 0; i--) {
|
j = f->bb[i].tmp;
|
j = f->bb[i].tmp;
|
if (f->bb[i].tmp > 2) f->bb[i].tmp = -f->bb[i].tmp;
|
if (f->bb[i].tmp > 2) f->bb[i].tmp = -f->bb[i].tmp;
|
f->bb[--end_bb] = f->bb[i];
|
f->bb[--end_bb] = f->bb[i];
|
Line 217... |
Line 217... |
/* relocate jump instructions */
|
/* relocate jump instructions */
|
for (i = 0; i < num_insn; i++)
|
for (i = 0; i < num_insn; i++)
|
for (j = 0; j < MAX_OPERANDS; j++)
|
for (j = 0; j < MAX_OPERANDS; j++)
|
if (insn[i].opt[j] & OPT_BB)
|
if (insn[i].opt[j] & OPT_BB)
|
insn[i].op[j] = reloc[insn[i].op[j]];
|
insn[i].op[j] = reloc[insn[i].op[j]];
|
if (DEBUG > 3) print_cuc_bb (f, "AFTER_INSERT-reloc");
|
if (cuc_debug >= 3) print_cuc_bb (f, "AFTER_INSERT-reloc");
|
for (i = 0; i < f->num_bb; i++) {
|
for (i = 0; i < f->num_bb; i++) {
|
if (f->bb[i].next[0] >= 0) {
|
if (f->bb[i].next[0] >= 0) {
|
int t = reloc[f->bb[i].next[0]];
|
int t = reloc[f->bb[i].next[0]];
|
if (f->bb[t].tmp < 0) {
|
if (f->bb[t].tmp < 0) {
|
f->bb[t].tmp = -f->bb[t].tmp;
|
f->bb[t].tmp = -f->bb[t].tmp;
|
Line 238... |
Line 238... |
f->bb[i].next[1] = t;
|
f->bb[i].next[1] = t;
|
}
|
}
|
/* artificial blocks do not have relocations, hardcode them */
|
/* artificial blocks do not have relocations, hardcode them */
|
if (f->bb[i].last < 0) f->bb[i].next[0] = i + 1;
|
if (f->bb[i].last < 0) f->bb[i].next[0] = i + 1;
|
}
|
}
|
if (DEBUG > 3) print_cuc_bb (f, "AFTER_INSERT");
|
if (cuc_debug >= 3) print_cuc_bb (f, "AFTER_INSERT");
|
|
|
/* Uncoditional branched do not continue to next block */
|
/* Uncoditional branched do not continue to next block */
|
for (i = 0; i < f->num_bb; i++) {
|
for (i = 0; i < f->num_bb; i++) {
|
cuc_insn *ii;
|
cuc_insn *ii;
|
if (f->bb[i].last < 0) continue;
|
if (f->bb[i].last < 0) continue;
|
Line 252... |
Line 252... |
change_insn_type (ii, II_NOP);
|
change_insn_type (ii, II_NOP);
|
if (f->bb[i].next[1] == i + 1) f->bb[i].next[0] = f->bb[i].next[1];
|
if (f->bb[i].next[1] == i + 1) f->bb[i].next[0] = f->bb[i].next[1];
|
f->bb[i].next[1] = -1;
|
f->bb[i].next[1] = -1;
|
}
|
}
|
}
|
}
|
if (DEBUG > 3) print_cuc_bb (f, "AFTER_UNCOND_JUMP");
|
if (cuc_debug >= 3) print_cuc_bb (f, "AFTER_UNCOND_JUMP");
|
|
|
/* Add backward connections */
|
/* Add backward connections */
|
for (i = 0; i < f->num_bb; i++)
|
for (i = 0; i < f->num_bb; i++)
|
f->bb[i].prev[0] = f->bb[i].prev[1] = -1;
|
f->bb[i].prev[0] = f->bb[i].prev[1] = -1;
|
|
|
Line 276... |
Line 276... |
assert (f->bb[t].prev[1] < 0);
|
assert (f->bb[t].prev[1] < 0);
|
f->bb[t].prev[1] = i;
|
f->bb[t].prev[1] = i;
|
}
|
}
|
}
|
}
|
}
|
}
|
if (DEBUG > 3) print_cuc_bb (f, "AFTER_PREV");
|
if (cuc_debug >= 3) print_cuc_bb (f, "AFTER_PREV");
|
}
|
}
|
|
|
/* Build basic blocks */
|
/* Build basic blocks */
|
void build_bb (cuc_func *f)
|
void build_bb (cuc_func *f)
|
{
|
{
|
Line 457... |
Line 457... |
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
if (DEBUG > 3) print_cuc_bb (f, "join");
|
if (cuc_debug >= 3) print_cuc_bb (f, "join");
|
}
|
}
|
|
|
/* Optimize basic blocks */
|
/* Optimize basic blocks */
|
void optimize_bb (cuc_func *f)
|
void optimize_bb (cuc_func *f)
|
{
|
{
|
Line 471... |
Line 471... |
for (i = 0; i < f->num_bb; i++) if (!(f->bb[i].type & BB_DEAD)) {
|
for (i = 0; i < f->num_bb; i++) if (!(f->bb[i].type & BB_DEAD)) {
|
if (f->bb[i].prev[0] >= 0 && f->bb[i].prev[1] < 0) { /* exactly one predecessor */
|
if (f->bb[i].prev[0] >= 0 && f->bb[i].prev[1] < 0) { /* exactly one predecessor */
|
for (j = 0; j < f->bb[i].ninsn; j++)
|
for (j = 0; j < f->bb[i].ninsn; j++)
|
if (f->bb[i].insn[j].index == II_LRBB) {
|
if (f->bb[i].insn[j].index == II_LRBB) {
|
cuc_insn *t;
|
cuc_insn *t;
|
debug (4, "-lrbb %i.%i\n", i, j);
|
cucdebug (4, "-lrbb %i.%i\n", i, j);
|
|
|
/* Change to add LRBB, 0, 0 */
|
/* Change to add LRBB, 0, 0 */
|
change_insn_type (&f->bb[i].insn[j], II_ADD);
|
change_insn_type (&f->bb[i].insn[j], II_ADD);
|
f->bb[i].insn[j].type &= ~IT_VOLATILE;
|
f->bb[i].insn[j].type &= ~IT_VOLATILE;
|
t = &f->bb[f->bb[i].prev[0]].insn[f->bb[f->bb[i].prev[0]].ninsn - 1];
|
t = &f->bb[f->bb[i].prev[0]].insn[f->bb[f->bb[i].prev[0]].ninsn - 1];
|
Line 635... |
Line 635... |
if (tmp == 0) break; /* We already have the best one */
|
if (tmp == 0) break; /* We already have the best one */
|
}
|
}
|
}
|
}
|
b = minb;
|
b = minb;
|
f->bb[b].tmp = 1; /* Mark visited */
|
f->bb[b].tmp = 1; /* Mark visited */
|
debug (3, "minb %i min %i\n", minb, min);
|
cucdebug (3, "minb %i min %i\n", minb, min);
|
if (min) { /* We just broke the loop */
|
if (min) { /* We just broke the loop */
|
f->bb[b].type |= BB_INLOOP;
|
f->bb[b].type |= BB_INLOOP;
|
}
|
}
|
}
|
}
|
|
|
Line 809... |
Line 809... |
}
|
}
|
//printf ("\n");
|
//printf ("\n");
|
} while (r == bufsize);
|
} while (r == bufsize);
|
//printf ("\n");
|
//printf ("\n");
|
|
|
|
f->num_runs = f->bb[0].cnt;
|
fclose (fi);
|
fclose (fi);
|
fclose (fo);
|
fclose (fo);
|
free (buf);
|
free (buf);
|
free (bb_end);
|
free (bb_end);
|
free (bb_start);
|
free (bb_start);
|