Line 21... |
Line 21... |
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <stdarg.h>
|
#include <stdarg.h>
|
#include <assert.h>
|
#include <assert.h>
|
|
#include <ctype.h>
|
#include "sim-config.h"
|
#include "sim-config.h"
|
#include "cuc.h"
|
#include "cuc.h"
|
#include "insn.h"
|
#include "insn.h"
|
#include "profiler.h"
|
#include "profiler.h"
|
#include "opcode/or32.h"
|
#include "opcode/or32.h"
|
Line 67... |
Line 68... |
cse (func);
|
cse (func);
|
if (cuc_debug >= 3) print_cuc_bb (func, "AFTER_CSE");
|
if (cuc_debug >= 3) print_cuc_bb (func, "AFTER_CSE");
|
remove_dead (func);
|
remove_dead (func);
|
if (cuc_debug >= 5) print_cuc_bb (func, "AFTER_DEAD");
|
if (cuc_debug >= 5) print_cuc_bb (func, "AFTER_DEAD");
|
remove_trivial_regs (func);
|
remove_trivial_regs (func);
|
|
set_io (func);
|
if (cuc_debug >= 2) print_cuc_bb (func, "AFTER_TRIVIAL");
|
if (cuc_debug >= 2) print_cuc_bb (func, "AFTER_TRIVIAL");
|
add_latches (func);
|
add_latches (func);
|
if (cuc_debug >= 1) print_cuc_bb (func, "AFTER_LATCHES");
|
if (cuc_debug >= 1) print_cuc_bb (func, "AFTER_LATCHES");
|
set_io (func);
|
set_io (func);
|
add_memory_dep (func, func->memory_order);
|
add_memory_dep (func, func->memory_order);
|
Line 161... |
Line 163... |
cse (func);
|
cse (func);
|
if (cuc_debug >= 3) print_cuc_bb (func, "AFTER_CSE");
|
if (cuc_debug >= 3) print_cuc_bb (func, "AFTER_CSE");
|
remove_dead (func);
|
remove_dead (func);
|
if (cuc_debug >= 5) print_cuc_bb (func, "AFTER_DEAD");
|
if (cuc_debug >= 5) print_cuc_bb (func, "AFTER_DEAD");
|
remove_trivial_regs (func);
|
remove_trivial_regs (func);
|
|
set_io (func);
|
if (cuc_debug >= 2) print_cuc_bb (func, "AFTER_TRIVIAL");
|
if (cuc_debug >= 2) print_cuc_bb (func, "AFTER_TRIVIAL");
|
|
|
#if 0
|
#if 0
|
csm (func);
|
csm (func);
|
#endif
|
#endif
|
assert (saved = dup_func (func));
|
assert (saved = dup_func (func));
|
|
|
timings.preroll = timings.unroll = 1;
|
timings.preroll = timings.unroll = 1;
|
timings.nshared = 0;
|
timings.nshared = 0;
|
add_latches (func);
|
add_latches (func);
|
set_io (func);
|
|
|
|
if (cuc_debug >= 1) print_cuc_bb (func, "AFTER_LATCHES");
|
if (cuc_debug >= 1) print_cuc_bb (func, "AFTER_LATCHES");
|
analyse_timings (func, &timings);
|
analyse_timings (func, &timings);
|
add_memory_dep (func, func->memory_order);
|
add_memory_dep (func, func->memory_order);
|
if (cuc_debug >= 7) print_cuc_bb (func, "AFTER_MEMORY_DEP");
|
if (cuc_debug >= 7) print_cuc_bb (func, "AFTER_MEMORY_DEP");
|
Line 216... |
Line 218... |
j = 1;
|
j = 1;
|
|
|
do {
|
do {
|
pt = cpt;
|
pt = cpt;
|
cpt = preunroll_bb (tmp1, saved, &t[nt++], b, ++j, i);
|
cpt = preunroll_bb (tmp1, saved, &t[nt++], b, ++j, i);
|
} while (j <= MAX_PREROLL && pt->new_time >= cpt->new_time);
|
} while (j <= MAX_PREROLL && pt->new_time > cpt->new_time);
|
i++;
|
i++;
|
ut = cut;
|
ut = cut;
|
cut = preunroll_bb (tmp1, saved, &t[nt++], b, 1, i);
|
cut = preunroll_bb (tmp1, saved, &t[nt++], b, 1, i);
|
} while (i <= MAX_UNROLL && ut->new_time >= cut->new_time);
|
} while (i <= MAX_UNROLL && ut->new_time > cut->new_time);
|
|
|
/* Sort the timings */
|
/* Sort the timings */
|
#if 0
|
#if 0
|
if (cuc_debug >= 3)
|
if (cuc_debug >= 3)
|
for (i = 0; i < nt; i++) printf ("%i:%i,%i: %icyc\n",
|
for (i = 0; i < nt; i++) printf ("%i:%i,%i: %icyc\n",
|
Line 351... |
Line 353... |
}
|
}
|
}
|
}
|
}
|
}
|
|
|
/* Generates a function, based on specified parameters */
|
/* Generates a function, based on specified parameters */
|
cuc_func *generate_function (cuc_func *rf, char *name)
|
cuc_func *generate_function (cuc_func *rf, char *name, char *cut_filename)
|
{
|
{
|
int b, i, j;
|
int b, i, j;
|
char tmp[256];
|
char tmp[256];
|
cuc_timings tt;
|
cuc_timings tt;
|
cuc_func *f;
|
cuc_func *f;
|
assert (f = dup_func (rf));
|
assert (f = dup_func (rf));
|
|
|
|
if (cuc_debug >= 2) print_cuc_bb (f, "BEFORE_GENERATE");
|
log ("Generating function %s.\n", name);
|
log ("Generating function %s.\n", name);
|
printf ("Generating function %s.\n", name);
|
printf ("Generating function %s.\n", name);
|
|
|
if (cuc_debug >= 2) print_cuc_bb (f, "BEFORE_GENERATE");
|
|
add_latches (f);
|
|
set_io (f);
|
|
if (cuc_debug >= 1) print_cuc_bb (f, "AFTER_LATCHES");
|
|
|
|
format_func_options (tmp, rf);
|
format_func_options (tmp, rf);
|
if (strlen (tmp)) printf ("Applying options: %s\n", tmp);
|
if (strlen (tmp)) printf ("Applying options: %s\n", tmp);
|
else printf ("Using basic options.\n");
|
else printf ("Using basic options.\n");
|
|
|
/* Generate function as specified by options */
|
/* Generate function as specified by options */
|
Line 388... |
Line 386... |
st = &rf->bb[b].tim[rf->bb[b].selected_tim];
|
st = &rf->bb[b].tim[rf->bb[b].selected_tim];
|
if (!st->nshared) continue;
|
if (!st->nshared) continue;
|
assert (0);
|
assert (0);
|
//csm_gen (f, rf, st->nshared, st->shared);
|
//csm_gen (f, rf, st->nshared, st->shared);
|
}
|
}
|
|
add_latches (f);
|
|
if (cuc_debug >= 1) print_cuc_bb (f, "AFTER_LATCHES");
|
analyse_timings (f, &tt);
|
analyse_timings (f, &tt);
|
add_memory_dep (f, f->memory_order);
|
add_memory_dep (f, f->memory_order);
|
if (cuc_debug >= 7) print_cuc_bb (f, "AFTER_MEMORY_DEP");
|
if (cuc_debug >= 7) print_cuc_bb (f, "AFTER_MEMORY_DEP");
|
add_data_dep (f);
|
add_data_dep (f);
|
if (cuc_debug >= 8) print_cuc_bb (f, "AFTER_DATA_DEP");
|
if (cuc_debug >= 8) print_cuc_bb (f, "AFTER_DATA_DEP");
|
schedule_memory (f, f->memory_order);
|
schedule_memory (f, f->memory_order);
|
if (cuc_debug >= 7) print_cuc_bb (f, "AFTER_SCHEDULE_MEM");
|
if (cuc_debug >= 7) print_cuc_bb (f, "AFTER_SCHEDULE_MEM");
|
output_verilog (f, name);
|
|
|
sprintf (tmp, "%s%s", cut_filename, name);
|
|
output_verilog (f, tmp);
|
return f;
|
return f;
|
}
|
}
|
|
|
/* Calculates required time, based on selected options */
|
/* Calculates required time, based on selected options */
|
int calc_cycles (cuc_func *f)
|
int calc_cycles (cuc_func *f)
|
Line 520... |
Line 522... |
|
|
void main_cuc (char *filename)
|
void main_cuc (char *filename)
|
{
|
{
|
int i, j;
|
int i, j;
|
char tmp1[256];
|
char tmp1[256];
|
|
char filename_cut[256];
|
|
for (i = 0; i < 256; i++) {
|
|
if (isalpha(filename[i])) filename_cut[i] = filename[i];
|
|
else {
|
|
filename_cut[i] = '\0';
|
|
break;
|
|
}
|
|
}
|
|
|
printf ("Entering OpenRISC Custom Unit Compiler command prompt\n");
|
printf ("Entering OpenRISC Custom Unit Compiler command prompt\n");
|
printf ("Using profile file \"%s\" and memory profile file \"%s\".\n", config.sim.prof_fn, config.sim.mprof_fn);
|
printf ("Using profile file \"%s\" and memory profile file \"%s\".\n", config.sim.prof_fn, config.sim.mprof_fn);
|
sprintf (tmp1, "%s.log", filename);
|
sprintf (tmp1, "%s.log", filename_cut);
|
printf ("Analyzing. (log file \"%s\").\n", tmp1);
|
printf ("Analyzing. (log file \"%s\").\n", tmp1);
|
assert (flog = fopen (tmp1, "wt+"));
|
assert (flog = fopen (tmp1, "wt+"));
|
|
|
/* Loads in the specified timings table */
|
/* Loads in the specified timings table */
|
printf ("Using timings from \"%s\" at %s\n",config.cuc.timings_fn,
|
printf ("Using timings from \"%s\" at %s\n",config.cuc.timings_fn,
|
Line 630... |
Line 640... |
/* generate command */
|
/* generate command */
|
} else if (strcmp (tmp1, "g") == 0 || strcmp (tmp1, "generate") == 0) {
|
} else if (strcmp (tmp1, "g") == 0 || strcmp (tmp1, "generate") == 0) {
|
/* check for function dependencies */
|
/* check for function dependencies */
|
for (i = 0; i < prof_nfuncs; i++)
|
for (i = 0; i < prof_nfuncs; i++)
|
if (func[i]) func[i]->tmp = func_v[i];
|
if (func[i]) func[i]->tmp = func_v[i];
|
for (i = 0; i < prof_nfuncs; i++)
|
for (i = 0; i < prof_nfuncs; i++) if (func[i])
|
for (j = 0; j < func[i]->nfdeps; j++)
|
for (j = 0; j < func[i]->nfdeps; j++)
|
if (!func[i]->fdeps[j] || !func[i]->fdeps[j]->tmp) {
|
if (!func[i]->fdeps[j] || !func[i]->fdeps[j]->tmp) {
|
printf ("Function %s must be selected for translation (required by %s)\n",
|
printf ("Function %s must be selected for translation (required by %s)\n",
|
prof_func[j].name, prof_func[i].name);
|
prof_func[j].name, prof_func[i].name);
|
goto wait_command;
|
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, filename_cut);
|
|
generate_main (prof_nfuncs, func, filename_cut);
|
|
|
/* select command */
|
/* select command */
|
} else if (strncmp (tmp1, "s", 1) == 0 || strncmp (tmp1, "select", 6) == 0) {
|
} 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;
|
Line 679... |
Line 690... |
printf ("Invalid option.\n");
|
printf ("Invalid option.\n");
|
}
|
}
|
} else printf ("Invalid function.\n");
|
} else printf ("Invalid function.\n");
|
}
|
}
|
|
|
|
/* selectall command */
|
|
} else if (strcmp (tmp1, "sa") == 0 || strcmp (tmp1, "selectall") == 0) {
|
|
char tmp[50], ch;
|
|
int p, o, b, f;
|
|
for (f = 0; f < prof_nfuncs; f++) if (func[f]) {
|
|
func_v[f] = 1;
|
|
printf ("Function %s selected for translation.\n", prof_func[f].name);
|
|
}
|
|
|
/* unselect command */
|
/* unselect command */
|
} else if (strncmp (tmp1, "u", 1) == 0 || strncmp (tmp1, "unselect", 8) == 0) {
|
} 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);
|