Line 114... |
Line 114... |
|
|
func->orig_time = orig_time;
|
func->orig_time = orig_time;
|
func->start_addr = start_addr;
|
func->start_addr = start_addr;
|
func->end_addr = end_addr;
|
func->end_addr = end_addr;
|
func->memory_order = memory_order;
|
func->memory_order = memory_order;
|
|
func->nfdeps = 0;
|
|
func->fdeps = NULL;
|
|
|
sprintf (tmp1, "%s.bin", module_name);
|
sprintf (tmp1, "%s.bin", module_name);
|
cucdebug (2, "Loading %s.bin\n", module_name);
|
cucdebug (2, "Loading %s.bin\n", module_name);
|
if (cuc_load (tmp1)) {
|
if (cuc_load (tmp1)) {
|
free (func);
|
free (func);
|
Line 447... |
Line 449... |
}
|
}
|
|
|
static cuc_func *func[MAX_FUNCS];
|
static cuc_func *func[MAX_FUNCS];
|
static int func_v[MAX_FUNCS];
|
static int func_v[MAX_FUNCS];
|
|
|
|
/* Detects function dependencies and removes */
|
|
static void set_func_deps ()
|
|
{
|
|
int f, b, i, j;
|
|
restart:
|
|
for (f = 0; f < prof_nfuncs - 1; f++) if (func[f]) {
|
|
int fused[MAX_FUNCS] = {0};
|
|
int c;
|
|
for (b = 0; b < func[f]->num_bb; b++)
|
|
for (i = 0; i < func[f]->bb[b].ninsn; i++) {
|
|
cuc_insn *ii = &func[f]->bb[b].insn[i];
|
|
if (ii->index == II_CALL) {
|
|
assert (ii->opt[0] == OPT_CONST);
|
|
for (j = 0; j < prof_nfuncs - 1; j++)
|
|
if (func[j] && func[j]->start_addr == ii->op[0]) break;
|
|
if (j >= prof_nfuncs - 1) {
|
|
log ("%s is calling unknown function, address %08x\n",
|
|
prof_func[f].name, ii->op[0]);
|
|
debug (1, "%s is calling unknown function, address %08x\n",
|
|
prof_func[f].name, ii->op[0]);
|
|
free_func (func[f]);
|
|
func[f] = NULL;
|
|
goto restart;
|
|
} else if (f == j) {
|
|
log ("%s is recursive, ignoring\n", prof_func[f].name);
|
|
debug (1, "%s is recursive, ignoring\n", prof_func[f].name);
|
|
free_func (func[f]);
|
|
func[f] = NULL;
|
|
goto restart;
|
|
} else fused[j]++;
|
|
}
|
|
}
|
|
for (i = 0; i < MAX_FUNCS; i++) if (fused[i]) c++;
|
|
if (func[f]->nfdeps) free (func[f]->fdeps);
|
|
func[f]->nfdeps = c;
|
|
func[f]->fdeps = (cuc_func **) malloc (sizeof (cuc_func *) * c);
|
|
for (i = 0, j = 0; i < MAX_FUNCS; i++)
|
|
if (fused[i]) func[f]->fdeps[j++] = func[i];
|
|
}
|
|
|
|
/* Detect loops */
|
|
{
|
|
int change;
|
|
for (f = 0; f < MAX_FUNCS; f++) if (func[f]) func[f]->tmp = 0;
|
|
do {
|
|
change = 0;
|
|
for (f = 0; f < MAX_FUNCS; f++) if (func[f] && !func[f]->tmp) {
|
|
int o = 1;
|
|
for (i = 0; i < func[f]->nfdeps; i++)
|
|
if (!func[f]->fdeps[i]->tmp) {o = 0; break;}
|
|
if (o) {
|
|
func[f]->tmp = 1;
|
|
change = 1;
|
|
}
|
|
}
|
|
} while (change);
|
|
|
|
change = 0;
|
|
for (f = 0; f < MAX_FUNCS; f++) if (func[f] && !func[f]->tmp) {
|
|
free_func (func[f]);
|
|
func[f] = NULL;
|
|
change = 1;
|
|
}
|
|
if (change) goto restart;
|
|
}
|
|
}
|
|
|
void main_cuc (char *filename)
|
void main_cuc (char *filename)
|
{
|
{
|
int i, j;
|
int i, j;
|
char tmp1[256];
|
char tmp1[256];
|
|
|
Line 492... |
Line 561... |
printf ("Testing function %s (%08x - %08x)\n", prof_func[i].name, start_addr, end_addr);
|
printf ("Testing function %s (%08x - %08x)\n", prof_func[i].name, start_addr, end_addr);
|
func[i] = analyse_function (prof_func[i].name, orig_time, start_addr,
|
func[i] = analyse_function (prof_func[i].name, orig_time, start_addr,
|
end_addr, config.cuc.memory_order);
|
end_addr, config.cuc.memory_order);
|
func_v[i] = 0;
|
func_v[i] = 0;
|
}
|
}
|
|
set_func_deps ();
|
|
|
while (1) {
|
while (1) {
|
char *s;
|
char *s;
|
|
wait_command:
|
printf ("(cuc) ");
|
printf ("(cuc) ");
|
fflush (stdout);
|
fflush (stdout);
|
fgets(tmp1, sizeof tmp1, stdin);
|
fgets(tmp1, sizeof tmp1, stdin);
|
for (s = tmp1; *s != '\0' && *s != '\n' && *s != '\r'; s++);
|
for (s = tmp1; *s != '\0' && *s != '\n' && *s != '\r'; s++);
|
*s = '\0';
|
*s = '\0';
|
|
|
|
/* quit command */
|
if (strcmp (tmp1, "q") == 0 || strcmp (tmp1, "quit") == 0) {
|
if (strcmp (tmp1, "q") == 0 || strcmp (tmp1, "quit") == 0) {
|
break;
|
break;
|
|
|
|
/* profile command */
|
} else if (strcmp (tmp1, "p") == 0 || strcmp (tmp1, "profile") == 0) {
|
} else if (strcmp (tmp1, "p") == 0 || strcmp (tmp1, "profile") == 0) {
|
int ntime = 0;
|
int ntime = 0;
|
int size = 0;
|
int size = 0;
|
printf ("-----------------------------------------------------------------------------\n");
|
printf ("-----------------------------------------------------------------------------\n");
|
printf ("|function name |calls|avg cycles |old%| max. f. | impr. f.| options |\n");
|
printf ("|function name |calls|avg cycles |old%| max. f. | impr. f.| options |\n");
|
Line 544... |
Line 618... |
for (i = 0; i < prof_nfuncs; i++)
|
for (i = 0; i < prof_nfuncs; i++)
|
prof_func[i].cum_cycles = -prof_func[i].cum_cycles;
|
prof_func[i].cum_cycles = -prof_func[i].cum_cycles;
|
printf ("-----------------------------------------------------------------------------\n");
|
printf ("-----------------------------------------------------------------------------\n");
|
printf ("Total %i cycles (was %i), total added gates = %i. Speed factor %.1f\n",
|
printf ("Total %i cycles (was %i), total added gates = %i. Speed factor %.1f\n",
|
ntime, prof_cycles, size, 1. * prof_cycles / ntime);
|
ntime, prof_cycles, size, 1. * prof_cycles / ntime);
|
} else if (strncmp (tmp1, "d", 1) == 0 || strncmp (tmp1, "debug", 5) == 0) {
|
|
/* debug command */
|
/* debug command */
|
|
} else if (strncmp (tmp1, "d", 1) == 0 || strncmp (tmp1, "debug", 5) == 0) {
|
sscanf (tmp1, "%*s %i", &cuc_debug);
|
sscanf (tmp1, "%*s %i", &cuc_debug);
|
if (cuc_debug < 0) cuc_debug = 0;
|
if (cuc_debug < 0) cuc_debug = 0;
|
if (cuc_debug > 9) cuc_debug = 9;
|
if (cuc_debug > 9) cuc_debug = 9;
|
} else if (strcmp (tmp1, "g") == 0 || strcmp (tmp1, "generate") == 0) {
|
|
/* generate command */
|
/* generate command */
|
|
} else if (strcmp (tmp1, "g") == 0 || strcmp (tmp1, "generate") == 0) {
|
|
/* check for function dependencies */
|
|
for (i = 0; i < prof_nfuncs; i++)
|
|
if (func[i]) func[i]->tmp = func_v[i];
|
|
for (i = 0; i < prof_nfuncs; i++)
|
|
for (j = 0; j < func[i]->nfdeps; j++)
|
|
if (!func[i]->fdeps[j] || !func[i]->fdeps[j]->tmp) {
|
|
printf ("Function %s must be selected for translation (required by %s)\n",
|
|
prof_func[j].name, prof_func[i].name);
|
|
goto wait_command;
|
|
}
|
for (i = 0; i < prof_nfuncs; i++)
|
for (i = 0; i < prof_nfuncs; i++)
|
if (func[i] && func_v[i]) generate_function (func[i], prof_func[i].name);
|
if (func[i] && func_v[i]) generate_function (func[i], prof_func[i].name);
|
} else if (strncmp (tmp1, "s", 1) == 0 || strncmp (tmp1, "select", 6) == 0) {
|
|
/* select command */
|
/* select command */
|
|
} else if (strncmp (tmp1, "s", 1) == 0 || strncmp (tmp1, "select", 6) == 0) {
|
char tmp[50], ch;
|
char tmp[50], ch;
|
int p, o, b, f;
|
int p, o, b, f;
|
p = sscanf (tmp1, "%*s %s %i%c", tmp, &b, &ch);
|
p = sscanf (tmp1, "%*s %s %i%c", tmp, &b, &ch);
|
if (p < 1) printf ("Invalid parameters.\n");
|
if (p < 1) printf ("Invalid parameters.\n");
|
else {
|
else {
|
Line 585... |
Line 672... |
if (func[f]->bb[b].tim[o].nshared) {
|
if (func[f]->bb[b].tim[o].nshared) {
|
printf ("Option has shared instructions: ");
|
printf ("Option has shared instructions: ");
|
print_shared (func[f], func[f]->bb[b].tim[o].shared, func[f]->bb[b].tim[o].nshared);
|
print_shared (func[f], func[f]->bb[b].tim[o].shared, func[f]->bb[b].tim[o].nshared);
|
printf ("\n");
|
printf ("\n");
|
}
|
}
|
continue;
|
goto wait_command;
|
invalid_option:
|
invalid_option:
|
printf ("Invalid option.\n");
|
printf ("Invalid option.\n");
|
}
|
}
|
} else printf ("Invalid function.\n");
|
} else printf ("Invalid function.\n");
|
}
|
}
|
} else if (strncmp (tmp1, "u", 1) == 0 || strncmp (tmp1, "unselect", 8) == 0) {
|
|
/* unselect command */
|
/* unselect command */
|
|
} else if (strncmp (tmp1, "u", 1) == 0 || strncmp (tmp1, "unselect", 8) == 0) {
|
char tmp[50], ch;
|
char tmp[50], ch;
|
int p, o, b, f;
|
int p, o, b, f;
|
p = sscanf (tmp1, "%*s %s %i%c", tmp, &b, &ch);
|
p = sscanf (tmp1, "%*s %s %i%c", tmp, &b, &ch);
|
if (p < 1) printf ("Invalid parameters.\n");
|
if (p < 1) printf ("Invalid parameters.\n");
|
else {
|
else {
|
Line 619... |
Line 707... |
/* select an option */
|
/* select an option */
|
func[f]->bb[b].selected_tim = -1;
|
func[f]->bb[b].selected_tim = -1;
|
}
|
}
|
} else printf ("Invalid function.\n");
|
} else printf ("Invalid function.\n");
|
}
|
}
|
|
|
|
/* options command */
|
} else if (strcmp (tmp1, "o") == 0 || strcmp (tmp1, "options") == 0) {
|
} else if (strcmp (tmp1, "o") == 0 || strcmp (tmp1, "options") == 0) {
|
int any = 0;
|
int any = 0;
|
/* options command */
|
|
printf ("Available options:\n");
|
printf ("Available options:\n");
|
for (i = 0; i < prof_nfuncs; i++)
|
for (i = 0; i < prof_nfuncs; i++)
|
if (func[i]) {
|
if (func[i]) {
|
options_cmd (i, func[i]);
|
options_cmd (i, func[i]);
|
any = 1;
|
any = 1;
|
}
|
}
|
if (any) printf ("-----------------------------------------------------------------------------\n");
|
if (any) printf ("-----------------------------------------------------------------------------\n");
|
else printf ("Sorry. No available options.\n");
|
else printf ("Sorry. No available options.\n");
|
} else if (strcmp (tmp1, "") == 0) {
|
|
/* Ignore empty string */
|
/* Ignore empty string */
|
} else {
|
} else if (strcmp (tmp1, "") == 0) {
|
|
|
/* help command */
|
/* help command */
|
|
} else {
|
if (strcmp (tmp1, "h") != 0 && strcmp (tmp1, "help") != 0)
|
if (strcmp (tmp1, "h") != 0 && strcmp (tmp1, "help") != 0)
|
printf ("Unknown command.\n");
|
printf ("Unknown command.\n");
|
printf ("OpenRISC Custom Unit Compiler command prompt\n");
|
printf ("OpenRISC Custom Unit Compiler command prompt\n");
|
printf ("Available commands:\n");
|
printf ("Available commands:\n");
|
printf (" h | help displays this help\n");
|
printf (" h | help displays this help\n");
|