Line 28... |
Line 28... |
#include "support/profile.h"
|
#include "support/profile.h"
|
|
|
/* prints out bb string */
|
/* prints out bb string */
|
void print_bb_num (int num)
|
void print_bb_num (int num)
|
{
|
{
|
if (num < 0) printf ("*");
|
if (num < 0) PRINTF ("*");
|
else if (num == BBID_END) printf ("END");
|
else if (num == BBID_END) PRINTF ("END");
|
else if (num == BBID_START) printf ("START");
|
else if (num == BBID_START) PRINTF ("START");
|
else printf ("%2x", num);
|
else PRINTF ("%2x", num);
|
}
|
}
|
|
|
/* Print out basic blocks */
|
/* Print out basic blocks */
|
void print_cuc_bb (cuc_func *f, char *s)
|
void print_cuc_bb (cuc_func *f, char *s)
|
{
|
{
|
int i;
|
int i;
|
printf ("------- %s -------\n", s);
|
PRINTF ("------- %s -------\n", s);
|
for (i = 0; i < f->num_bb; i++) {
|
for (i = 0; i < f->num_bb; i++) {
|
if (f->bb[i].insn) printf ("\n---- BB%-2x * %x ---- ", i, f->bb[i].cnt);
|
if (f->bb[i].insn) PRINTF ("\n---- BB%-2x * %x ---- ", i, f->bb[i].cnt);
|
else printf ("BB%-2x: %4x-%-4x", i, f->bb[i].first, f->bb[i].last);
|
else PRINTF ("BB%-2x: %4x-%-4x", i, f->bb[i].first, f->bb[i].last);
|
printf (" type %02x tmp %i ", f->bb[i].type, f->bb[i].tmp);
|
PRINTF (" type %02x tmp %i ", f->bb[i].type, f->bb[i].tmp);
|
printf ("next "); print_bb_num (f->bb[i].next[0]);
|
PRINTF ("next "); print_bb_num (f->bb[i].next[0]);
|
printf (" "); print_bb_num (f->bb[i].next[1]);
|
PRINTF (" "); print_bb_num (f->bb[i].next[1]);
|
printf (" prev "); print_bb_num (f->bb[i].prev[0]);
|
PRINTF (" prev "); print_bb_num (f->bb[i].prev[0]);
|
printf (" "); print_bb_num (f->bb[i].prev[1]);
|
PRINTF (" "); print_bb_num (f->bb[i].prev[1]);
|
printf ("\n");
|
PRINTF ("\n");
|
|
|
if (f->bb[i].insn) print_insns (f->bb[i].insn, f->bb[i].ninsn, 0);
|
if (f->bb[i].insn) print_insns (f->bb[i].insn, f->bb[i].ninsn, 0);
|
}
|
}
|
if (f->nmsched) {
|
if (f->nmsched) {
|
printf ("\nmsched: ");
|
PRINTF ("\nmsched: ");
|
for (i = 0; i < f->nmsched; i++)
|
for (i = 0; i < f->nmsched; i++)
|
printf ("%x ", f->msched[i]);
|
PRINTF ("%x ", f->msched[i]);
|
printf ("\n\n\n");
|
PRINTF ("\n\n\n");
|
} else printf ("\n");
|
} else PRINTF ("\n");
|
fflush (stdout);
|
fflush (stdout);
|
}
|
}
|
|
|
/* Copies src basic block into destination */
|
/* Copies src basic block into destination */
|
cuc_bb *cpy_bb (cuc_bb *dest, cuc_bb *src)
|
cuc_bb *cpy_bb (cuc_bb *dest, cuc_bb *src)
|
Line 608... |
Line 608... |
lrbb->type |= IT_COND;
|
lrbb->type |= IT_COND;
|
}
|
}
|
}
|
}
|
|
|
f->bb[succ].type = BB_DEAD;
|
f->bb[succ].type = BB_DEAD;
|
//printf (" %x %x %x %x %x\n", f->bb[pred].next[0], f->bb[pred].next[1], f->bb[succ].next[0], f->bb[succ].next[1], insn[ninsn - 1].type);
|
//PRINTF (" %x %x %x %x %x\n", f->bb[pred].next[0], f->bb[pred].next[1], f->bb[succ].next[0], f->bb[succ].next[1], insn[ninsn - 1].type);
|
/* remove branch instruction, if there is only one successor */
|
/* remove branch instruction, if there is only one successor */
|
if (f->bb[pred].next[1] < 0 && ninsn > 0 && insn[ninsn - 1].type & IT_BRANCH) {
|
if (f->bb[pred].next[1] < 0 && ninsn > 0 && insn[ninsn - 1].type & IT_BRANCH) {
|
assert (f->bb[pred].next[0] != pred); /* end BB, loop should not be possible */
|
assert (f->bb[pred].next[0] != pred); /* end BB, loop should not be possible */
|
change_insn_type (&insn[ninsn - 1], II_NOP);
|
change_insn_type (&insn[ninsn - 1], II_NOP);
|
}
|
}
|
Line 634... |
Line 634... |
/* Check if we are referencing successor BB -> relocate to second part of
|
/* Check if we are referencing successor BB -> relocate to second part of
|
the new block */
|
the new block */
|
if (REF_BB (f->bb[i].insn[j].op[k]) == succ) {
|
if (REF_BB (f->bb[i].insn[j].op[k]) == succ) {
|
int t = f->bb[i].insn[j].op[k];
|
int t = f->bb[i].insn[j].op[k];
|
int ndest = REF (pred, REF_I (t) + n1);
|
int ndest = REF (pred, REF_I (t) + n1);
|
//printf ("%x: %x %x\n", REF(i, j), t, ndest);
|
//PRINTF ("%x: %x %x\n", REF(i, j), t, ndest);
|
|
|
/* We've found a reference to succ. block, being removed, relocate */
|
/* We've found a reference to succ. block, being removed, relocate */
|
f->bb[i].insn[j].op[k] = ndest;
|
f->bb[i].insn[j].op[k] = ndest;
|
} else if (REF_BB(f->bb[i].insn[j].op[k]) == pred) {
|
} else if (REF_BB(f->bb[i].insn[j].op[k]) == pred) {
|
if (i != pred && reloc[REF_I(f->bb[i].insn[j].op[k])] >= 0) {
|
if (i != pred && reloc[REF_I(f->bb[i].insn[j].op[k])] >= 0) {
|
Line 821... |
Line 821... |
static int reg_dep_rec (cuc_func *f, int cur)
|
static int reg_dep_rec (cuc_func *f, int cur)
|
{
|
{
|
int i, j;
|
int i, j;
|
cuc_insn *insn = f->bb[cur].insn;
|
cuc_insn *insn = f->bb[cur].insn;
|
|
|
//printf ("\n %i", cur);
|
//PRINTF ("\n %i", cur);
|
/* Spread only, do not loop */
|
/* Spread only, do not loop */
|
if (f->bb[cur].tmp) return;
|
if (f->bb[cur].tmp) return;
|
f->bb[cur].tmp = 1;
|
f->bb[cur].tmp = 1;
|
//printf ("! ");
|
//PRINTF ("! ");
|
|
|
for (i = 0; i < f->bb[cur].ninsn; i++) {
|
for (i = 0; i < f->bb[cur].ninsn; i++) {
|
/* Check for destination operand(s) */
|
/* Check for destination operand(s) */
|
for (j = 0; j < MAX_OPERANDS; j++) if (insn[i].opt[j] & OPT_DEST)
|
for (j = 0; j < MAX_OPERANDS; j++) if (insn[i].opt[j] & OPT_DEST)
|
if ((insn[i].opt[j] & ~OPT_DEST) == OPT_REGISTER && (signed)insn[i].op[j] >= 0) {
|
if ((insn[i].opt[j] & ~OPT_DEST) == OPT_REGISTER && (signed)insn[i].op[j] >= 0) {
|
//printf ("%i:%i,%x ", insn[i].op[j], i, REF (cur, i));
|
//PRINTF ("%i:%i,%x ", insn[i].op[j], i, REF (cur, i));
|
assert (insn[i].op[j] > 0 && insn[i].op[j] < MAX_REGS); /* r0 should never be dest */
|
assert (insn[i].op[j] > 0 && insn[i].op[j] < MAX_REGS); /* r0 should never be dest */
|
f->bb[cur].last_used_reg[insn[i].op[j]] = REF (cur, i);
|
f->bb[cur].last_used_reg[insn[i].op[j]] = REF (cur, i);
|
}
|
}
|
}
|
}
|
|
|
Line 1097... |
Line 1097... |
assert (bb_start = (unsigned long *) malloc (sizeof (unsigned long) * f->num_bb));
|
assert (bb_start = (unsigned long *) malloc (sizeof (unsigned long) * f->num_bb));
|
assert (bb_end = (unsigned long *) malloc (sizeof (unsigned long) * f->num_bb));
|
assert (bb_end = (unsigned long *) malloc (sizeof (unsigned long) * f->num_bb));
|
for (b = 0; b < f->num_bb; b++) {
|
for (b = 0; b < f->num_bb; b++) {
|
bb_start[b] = f->start_addr + f->bb[b].first * 4;
|
bb_start[b] = f->start_addr + f->bb[b].first * 4;
|
bb_end[b] = f->start_addr + f->bb[b].last * 4;
|
bb_end[b] = f->start_addr + f->bb[b].last * 4;
|
//printf ("%i %x %x\n", b, bb_start[b], bb_end[b]);
|
//PRINTF ("%i %x %x\n", b, bb_start[b], bb_end[b]);
|
f->bb[0].cnt = 0;
|
f->bb[0].cnt = 0;
|
}
|
}
|
|
|
buf = (struct mprofentry_struct *) malloc (sizeof (struct mprofentry_struct) * bufsize);
|
buf = (struct mprofentry_struct *) malloc (sizeof (struct mprofentry_struct) * bufsize);
|
assert (buf);
|
assert (buf);
|
|
|
//printf ("BBSEQ:\n");
|
//PRINTF ("BBSEQ:\n");
|
do {
|
do {
|
r = fread (buf, sizeof (struct mprofentry_struct), bufsize, fi);
|
r = fread (buf, sizeof (struct mprofentry_struct), bufsize, fi);
|
//printf ("r%i : ", r);
|
//PRINTF ("r%i : ", r);
|
for (i = 0; i < r; i++) {
|
for (i = 0; i < r; i++) {
|
if (buf[i].type & MPROF_FETCH) {
|
if (buf[i].type & MPROF_FETCH) {
|
//printf ("%x, ", buf[i].addr);
|
//PRINTF ("%x, ", buf[i].addr);
|
if (buf[i].addr >= f->start_addr && buf[i].addr <= f->end_addr) {
|
if (buf[i].addr >= f->start_addr && buf[i].addr <= f->end_addr) {
|
assert (buf[i].type & MPROF_32);
|
assert (buf[i].type & MPROF_32);
|
prevaddr = addr;
|
prevaddr = addr;
|
addr = buf[i].addr;
|
addr = buf[i].addr;
|
for (b = 0; b < f->num_bb; b++)
|
for (b = 0; b < f->num_bb; b++)
|
Line 1125... |
Line 1125... |
} else curbb = -1;
|
} else curbb = -1;
|
|
|
#warning TODO: do not count interrupts
|
#warning TODO: do not count interrupts
|
if (curbb != prevbb && curbb >= 0) {
|
if (curbb != prevbb && curbb >= 0) {
|
fwrite (&curbb, sizeof (unsigned long), 1, fo);
|
fwrite (&curbb, sizeof (unsigned long), 1, fo);
|
//printf (" [%i] ", curbb);
|
//PRINTF (" [%i] ", curbb);
|
f->bb[curbb].cnt++;
|
f->bb[curbb].cnt++;
|
prevbb = curbb;
|
prevbb = curbb;
|
}
|
}
|
} else {
|
} else {
|
if (verify_memoryarea(buf[i].addr))
|
if (verify_memoryarea(buf[i].addr))
|
if (buf[i].type & MPROF_WRITE) mscnt++, mssum += cur_area->delayw;
|
if (buf[i].type & MPROF_WRITE) mscnt++, mssum += cur_area->delayw;
|
else mlcnt++, mlsum += cur_area->delayw;
|
else mlcnt++, mlsum += cur_area->delayw;
|
}
|
}
|
}
|
}
|
//printf ("\n");
|
//PRINTF ("\n");
|
} while (r == bufsize);
|
} while (r == bufsize);
|
//printf ("\n");
|
//PRINTF ("\n");
|
|
|
runtime.cuc.mdelay[0] = (1. * mlsum) / mlcnt;
|
runtime.cuc.mdelay[0] = (1. * mlsum) / mlcnt;
|
runtime.cuc.mdelay[1] = (1. * mlsum) / mlcnt;
|
runtime.cuc.mdelay[1] = (1. * mlsum) / mlcnt;
|
runtime.cuc.mdelay[2] = runtime.cuc.mdelay[3] = 1;
|
runtime.cuc.mdelay[2] = runtime.cuc.mdelay[3] = 1;
|
f->num_runs = f->bb[0].cnt;
|
f->num_runs = f->bb[0].cnt;
|
Line 1151... |
Line 1151... |
free (bb_end);
|
free (bb_end);
|
free (bb_start);
|
free (bb_start);
|
|
|
/* Initialize basic block relocations */
|
/* Initialize basic block relocations */
|
f->num_init_bb = f->num_bb;
|
f->num_init_bb = f->num_bb;
|
//printf ("num_init_bb = %i\n", f->num_init_bb);
|
//PRINTF ("num_init_bb = %i\n", f->num_init_bb);
|
assert (f->init_bb_reloc = (int *)malloc (sizeof (int) * f->num_init_bb));
|
assert (f->init_bb_reloc = (int *)malloc (sizeof (int) * f->num_init_bb));
|
for (b = 0; b < f->num_init_bb; b++) f->init_bb_reloc[b] = b;
|
for (b = 0; b < f->num_init_bb; b++) f->init_bb_reloc[b] = b;
|
}
|
}
|
|
|
/* Scans sequence of BBs and set counts for pre/unrolled loop for BB b */
|
/* Scans sequence of BBs and set counts for pre/unrolled loop for BB b */
|
Line 1213... |
Line 1213... |
cuc_func *n = dup_func (f);
|
cuc_func *n = dup_func (f);
|
cuc_bb *ob = &f->bb[b];
|
cuc_bb *ob = &f->bb[b];
|
cuc_insn *ii;
|
cuc_insn *ii;
|
|
|
assert (unroll > 1);
|
assert (unroll > 1);
|
//printf ("unroll BB%i x %i (num_bb %i)\n", b, unroll, n->num_bb);
|
//PRINTF ("unroll BB%i x %i (num_bb %i)\n", b, unroll, n->num_bb);
|
unroll--;
|
unroll--;
|
assert (n->num_bb + unroll * 2 < MAX_BB);
|
assert (n->num_bb + unroll * 2 < MAX_BB);
|
|
|
prevb = b;
|
prevb = b;
|
prevart_b = b;
|
prevart_b = b;
|
Line 1357... |
Line 1357... |
cuc_func *n = dup_func (f);
|
cuc_func *n = dup_func (f);
|
cuc_bb *ob = &f->bb[b];
|
cuc_bb *ob = &f->bb[b];
|
cuc_insn *ii;
|
cuc_insn *ii;
|
|
|
assert (preroll > 1);
|
assert (preroll > 1);
|
//printf ("preroll BB%i x %i (num_bb %i)\n", b, preroll, n->num_bb);
|
//PRINTF ("preroll BB%i x %i (num_bb %i)\n", b, preroll, n->num_bb);
|
preroll--;
|
preroll--;
|
assert (n->num_bb + preroll * 2 < MAX_BB);
|
assert (n->num_bb + preroll * 2 < MAX_BB);
|
|
|
prevb = b;
|
prevb = b;
|
prevart_b = b;
|
prevart_b = b;
|