libqbe/lisc/main.c

147 lines
2.4 KiB
C
Raw Normal View History

2015-07-16 03:25:12 -04:00
#include "lisc.h"
2015-07-22 04:50:52 -04:00
char debug['Z'+1] = {
2015-07-22 06:33:10 -04:00
['S'] = 0, /* spiller */
2015-07-29 16:09:58 -04:00
['R'] = 0, /* reg. allocator */
2015-07-22 04:50:52 -04:00
};
void
dumpts(Bits *b, Tmp *tmp, FILE *f)
2015-07-16 03:25:12 -04:00
{
int t;
2015-07-22 04:50:52 -04:00
fprintf(f, "[");
2015-07-22 06:33:10 -04:00
for (t=0; t<BITS*NBit; t++)
2015-07-16 03:25:12 -04:00
if (BGET(*b, t))
fprintf(f, " %s", tmp[t].name);
2015-07-22 04:50:52 -04:00
fprintf(f, " ]\n");
2015-07-16 03:25:12 -04:00
}
int
main(int ac, char *av[])
{
int opt, pr;
Fn *fn;
fn = parse(stdin);
2015-07-16 03:25:12 -04:00
pr = 1;
opt = 0;
if (ac > 1 && av[1][0] == '-')
opt = av[1][1];
switch (opt) {
case 'f': {
int t, ntmp;
2015-07-16 03:25:12 -04:00
fprintf(stderr, "[Testing SSA Reconstruction:");
fillpreds(fn);
for (ntmp=fn->ntmp, t=0; t<ntmp; t++) {
fprintf(stderr, " %s", fn->tmp[t].name);
ssafix(fn, t);
2015-07-16 03:25:12 -04:00
}
fprintf(stderr, "]\n");
break;
}
case 'r': {
int n;
fprintf(stderr, "[Testing RPO]\n");
2015-07-27 14:34:22 -04:00
RPODump:
2015-07-16 03:25:12 -04:00
fillrpo(fn);
assert(fn->rpo[0] == fn->start);
for (n=0;; n++)
if (n == fn->nblk-1) {
fn->rpo[n]->link = 0;
break;
} else
fn->rpo[n]->link = fn->rpo[n+1];
break;
}
case 'l': {
Blk *b;
fprintf(stderr, "[Testing Liveness]\n");
fillrpo(fn);
filllive(fn);
for (b=fn->start; b; b=b->link) {
printf("> Block %s\n", b->name);
2015-07-22 04:50:52 -04:00
printf("\t in: ");
dumpts(&b->in, fn->tmp, stdout);
2015-07-22 04:50:52 -04:00
printf("\tout: ");
dumpts(&b->out, fn->tmp, stdout);
printf("\tnlive: %d\n", b->nlive);
2015-07-16 03:25:12 -04:00
}
pr = 0;
break;
}
2015-07-24 09:32:26 -04:00
case 'i': {
fprintf(stderr, "[Testing Instruction Selection]\n");
isel(fn);
break;
}
2015-07-21 19:04:13 -04:00
case 's': {
Blk *b;
fprintf(stderr, "[Testing Spilling]\n");
2015-07-22 06:33:10 -04:00
debug['S'] = 1;
2015-07-24 09:32:26 -04:00
isel(fn);
2015-07-21 19:04:13 -04:00
fillrpo(fn);
2015-07-22 03:00:03 -04:00
fillpreds(fn);
2015-07-21 19:04:13 -04:00
filllive(fn);
fillcost(fn);
spill(fn);
2015-07-22 06:33:10 -04:00
printf("> Block information:\n");
2015-07-21 19:04:13 -04:00
for (b=fn->start; b; b=b->link) {
2015-07-22 05:30:59 -04:00
printf("\t%-10s (% 5d) ",
b->name, b->loop);
dumpts(&b->out, fn->tmp, stdout);
2015-07-21 19:04:13 -04:00
}
2015-07-24 09:32:26 -04:00
printf("\n");
2015-07-27 14:34:22 -04:00
break;
}
case 'a': {
fprintf(stderr, "[Testing Register Allocation]\n");
debug['R'] = 1;
isel(fn);
fillrpo(fn);
fillpreds(fn);
filllive(fn);
fillcost(fn);
spill(fn);
rega(fn);
goto RPODump;
2015-07-21 19:04:13 -04:00
}
2015-07-28 22:40:50 -04:00
case 'e': {
int n;
fprintf(stderr, "[Testing Code Emission]\n");
2015-07-29 16:09:58 -04:00
isel(fn);
2015-07-28 22:40:50 -04:00
fillrpo(fn);
fillpreds(fn);
filllive(fn);
fillcost(fn);
spill(fn);
rega(fn);
fillrpo(fn);
assert(fn->rpo[0] == fn->start);
for (n=0;; n++)
if (n == fn->nblk-1) {
fn->rpo[n]->link = 0;
break;
} else
fn->rpo[n]->link = fn->rpo[n+1];
emitfn(fn, stdout);
2015-07-28 22:40:50 -04:00
pr = 0;
break;
}
2015-07-16 03:25:12 -04:00
default:
break;
}
if (pr)
printfn(fn, stdout);
exit(0);
2015-07-16 03:25:12 -04:00
}