update pmov test to work with new regalloc

This commit is contained in:
Quentin Carbonneaux 2016-03-25 10:56:02 -04:00
parent 087b7bf978
commit 87dfb081d6

View file

@ -1,11 +1,11 @@
/*% cc -O3 -std=c99 -Wall -DTEST_PMOV -o # % /*% rm -f rega.o main.o && cc -g -std=c99 -Wall -DTEST_PMOV -o # % *.o
* *
* This is a test framwork for the dopm() function * This is a test framwork for the dopm() function
* in rega.c, use it when you want to modify it or * in rega.c, use it when you want to modify it or
* all the parallel move functions. * all the parallel move functions.
* *
* You might need to decrease NReg to see it * You might need to decrease NIReg to see it
* terminate, I used NReg == 7 at most. * terminate, I used NIReg == 7 at most.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -16,7 +16,7 @@ static void assert_test(char *, int), fail(void), iexec(int *);
#include "../rega.c" #include "../rega.c"
static RMap mbeg; static RMap mbeg;
static Ins ins[NReg], *ip; static Ins ins[NIReg], *ip;
static Blk dummyb = { .ins = ins }; static Blk dummyb = { .ins = ins };
int int
@ -25,29 +25,31 @@ main()
Ins *i1; Ins *i1;
unsigned long long tm, rm, cnt; unsigned long long tm, rm, cnt;
RMap mend; RMap mend;
int reg[NReg], val[NReg+1]; int reg[NIReg], val[NIReg+1];
int t, i, r, nr; int t, i, r, nr;
tmp = (Tmp[Tmp0+NReg]){{0}}; tmp = (Tmp[Tmp0+NIReg]){{{0}}};
for (t=0; t<Tmp0+NReg; t++) for (t=0; t<Tmp0+NIReg; t++)
if (t < Tmp0) if (t >= Tmp0) {
tmp[t] = (Tmp){.type = TReg}; tmp[t].cls = Kw;
else { tmp[t].hint.r = -1;
tmp[t].type = TLong; tmp[t].hint.m = 0;
tmp[t].hint = -1; tmp[t].slot = -1;
sprintf(tmp[t].name, "tmp%d", t-Tmp0+1); sprintf(tmp[t].name, "tmp%d", t-Tmp0+1);
} }
bsinit(mbeg.b, Tmp0+NIReg);
bsinit(mend.b, Tmp0+NIReg);
cnt = 0; cnt = 0;
for (tm = 0; tm < 1ull << (2*NReg); tm++) { for (tm = 0; tm < 1ull << (2*NIReg); tm++) {
mbeg.n = 0; mbeg.n = 0;
mbeg.b = (Bits){{0}}; bszero(mbeg.b);
ip = ins; ip = ins;
/* find what temporaries are in copy and /* find what temporaries are in copy and
* wether or not they are in register * wether or not they are in register
*/ */
for (t=0; t<NReg; t++) for (t=0; t<NIReg; t++)
switch ((tm >> (2*t)) & 3) { switch ((tm >> (2*t)) & 3) {
case 0: case 0:
/* not in copy, not in reg */ /* not in copy, not in reg */
@ -58,11 +60,11 @@ main()
break; break;
case 2: case 2:
/* in copy, not in reg */ /* in copy, not in reg */
*ip++ = (Ins){OCopy, TMP(Tmp0+t), {R, R}}; *ip++ = (Ins){OCopy, TMP(Tmp0+t), {R, R}, Kw};
break; break;
case 3: case 3:
/* in copy, in reg */ /* in copy, in reg */
*ip++ = (Ins){OCopy, TMP(Tmp0+t), {R, R}}; *ip++ = (Ins){OCopy, TMP(Tmp0+t), {R, R}, Kw};
radd(&mbeg, Tmp0+t, t+1); radd(&mbeg, Tmp0+t, t+1);
break; break;
} }
@ -89,7 +91,7 @@ main()
/* compile the parallel move /* compile the parallel move
*/ */
mend = mbeg; rcopy(&mend, &mbeg);
dopm(&dummyb, ip-1, &mend); dopm(&dummyb, ip-1, &mend);
cnt++; cnt++;
@ -103,11 +105,11 @@ main()
r = i1->arg[0].val; r = i1->arg[0].val;
assert(rfree(&mend, r) == r); assert(rfree(&mend, r) == r);
t = i1->to.val; t = i1->to.val;
assert(!BGET(mend.b, t)); assert(!bshas(mend.b, t));
} }
for (i=0; i<mend.n; i++) { for (i=0; i<mend.n; i++) {
t = mend.t[i]; t = mend.t[i];
assert(BGET(mbeg.b, t)); assert(bshas(mbeg.b, t));
t -= Tmp0; t -= Tmp0;
assert(((tm >> (2*t)) & 3) == 1); assert(((tm >> (2*t)) & 3) == 1);
} }
@ -117,7 +119,7 @@ main()
* value, and that all live variables's * value, and that all live variables's
* content got preserved * content got preserved
*/ */
for (i=1; i<=NReg; i++) for (i=1; i<=NIReg; i++)
val[i] = i; val[i] = i;
iexec(val); iexec(val);
for (i1=ins; i1<ip; i1++) { for (i1=ins; i1<ip; i1++) {
@ -139,8 +141,8 @@ main()
rm &= ~(1ull<<r); rm &= ~(1ull<<r);
do do
r++; r++;
while (r <= NReg && (rm & (1ull<<r))); while (r <= NIReg && (rm & (1ull<<r)));
if (r == NReg+1) { if (r == NIReg+1) {
if (i == 0) if (i == 0)
goto Nxt; goto Nxt;
i--; i--;
@ -151,7 +153,7 @@ main()
} }
} }
for (; i<nr; i++) for (; i<nr; i++)
for (r=1; r<=NReg; r++) for (r=1; r<=NIReg; r++)
if (!(rm & (1ull<<r))) { if (!(rm & (1ull<<r))) {
rm |= (1ull<<r); rm |= (1ull<<r);
reg[i] = r; reg[i] = r;
@ -170,7 +172,7 @@ main()
#define validr(r) \ #define validr(r) \
rtype(r) == RTmp && \ rtype(r) == RTmp && \
r.val > 0 && \ r.val > 0 && \
r.val <= NReg r.val <= NIReg
static void static void
iexec(int val[]) iexec(int val[])
@ -209,7 +211,8 @@ replay()
RMap mend; RMap mend;
re = 1; re = 1;
mend = mbeg; bsinit(mend.b, Tmp0+NIReg);
rcopy(&mend, &mbeg);
dopm(&dummyb, ip-1, &mend); dopm(&dummyb, ip-1, &mend);
} }
@ -231,7 +234,7 @@ fail()
tmp[i1->to.val].name, tmp[i1->to.val].name,
i1->arg[0].val); i1->arg[0].val);
replay(); replay();
exit(1); abort();
} }
static void static void
@ -240,25 +243,10 @@ assert_test(char *s, int x)
if (x) if (x)
return; return;
if (re) if (re)
exit(1); abort();
printf("!assertion failure: %s\n", s); printf("!assertion failure: %s\n", s);
fail(); fail();
} }
void diag(char *s)
{
if (re)
exit(1);
printf("!diag failure: %s\n", s);
fail();
}
/* symbols required by the linker */ /* symbols required by the linker */
char debug['Z'+1]; char debug['Z'+1];
Ins insb[NIns], *curi;
void *alloc(size_t n)
{ return calloc(n, 1); }
Blk *blocka()
{ printf("!blocka\n"); exit(1); }