modified to use a different 'panic' strategy, and use

new clash-table in tables.c when possible, and some other tuning
This commit is contained in:
ceriel 1988-03-31 10:14:48 +00:00
parent 35cb47328a
commit 092292683c
4 changed files with 100 additions and 63 deletions

View file

@ -62,8 +62,8 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost
int inscoerc=0; int inscoerc=0;
int procarg[2]; int procarg[2];
#ifdef ALLOW_NEXTEM #ifdef ALLOW_NEXTEM
int paniced; static int paniced;
char *savebp; char *savebp = 0;
#endif #endif
state_t state; state_t state;
#define SAVEST savestatus(&state) #define SAVEST savestatus(&state)
@ -128,7 +128,7 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost
#ifndef ALLOW_NEXTEM #ifndef ALLOW_NEXTEM
bp = nextem(toplevel); bp = nextem(toplevel);
#else #else
paniced=0; if (toplevel) paniced=0;
savebp = nextem(toplevel); savebp = nextem(toplevel);
panic: panic:
bp = savebp; bp = savebp;
@ -171,9 +171,18 @@ if (Debug)
if (dist<mindistance) { if (dist<mindistance) {
if(dist==0) if(dist==0)
goto gotit; goto gotit;
#ifdef ALLOW_NEXTEM
if (! paniced) {
#endif
npos=0; npos=0;
mindistance = dist; mindistance = dist;
#ifdef ALLOW_NEXTEM
} }
#endif
}
#ifdef ALLOW_NEXTEM
if (dist < MAXINT)
#endif
pos[npos++] = cindex; pos[npos++] = cindex;
} }
} }
@ -198,8 +207,9 @@ if (Debug)
RESTST; RESTST;
} }
FREEST; FREEST;
if (totalcost+mincost>costlimit) if (totalcost+mincost>costlimit) {
BROKE(); BROKE();
}
} else { } else {
cindex = pos[0]; cindex = pos[0];
} }
@ -344,11 +354,11 @@ if(Debug>1) fprintf(stderr,"Pattern too long, %d with only %d items on stack\n",
myfree(regls[j]); myfree(regls[j]);
#ifndef ALLOW_NEXTEM #ifndef ALLOW_NEXTEM
assert(!toplevel); assert(!toplevel);
BROKE();
#else #else
assert(!(toplevel&&paniced)); assert(!(toplevel&&paniced));
goto normalfailed; if (paniced) goto normalfailed;
#endif #endif
BROKE();
} }
if (cp->c3_prop<0) { if (cp->c3_prop<0) {
totalcost+=docoerc(tp,cp,ply,toplevel,0); totalcost+=docoerc(tp,cp,ply,toplevel,0);
@ -372,15 +382,21 @@ if(Debug>1) fprintf(stderr,"Pattern too long, %d with only %d items on stack\n",
besttup=0; besttup=0;
for (; tup != 0; tup = ntup) { for (; tup != 0; tup = ntup) {
#ifndef NDEBUG #ifndef NDEBUG
if(Debug>1) fprintf(stderr,"Next tuple %d,%d,%d,%d\n", if(Debug>1) { fprintf(stderr,"Next tuple %d,%d,%d,%d\n",
tup->p_rar[0], tup->p_rar[0],
tup->p_rar[1], tup->p_rar[1],
tup->p_rar[2], tup->p_rar[2],
tup->p_rar[3]); tup->p_rar[3]);
fprintf(stderr, "totalcost = %u, costlimit = %u, mincost = %u\n",
totalcost, costlimit, mincost);
}
#endif #endif
ntup = tup->p_next; ntup = tup->p_next;
for (i=0,t=0;i<nregneeded && t<mincost; i++) for (i=0,t=0;i<nregneeded && t<mincost; i++)
t += docoerc(regtp[i],regcp[i],ply,FALSE,tup->p_rar[i]); t += docoerc(regtp[i],regcp[i],ply,FALSE,tup->p_rar[i]);
#ifndef NDEBUG
if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
#endif
if ( t<mincost && tokpatlen<=stackheight ) { if ( t<mincost && tokpatlen<=stackheight ) {
#ifndef NDEBUG #ifndef NDEBUG
if (Debug>2) if (Debug>2)
@ -415,17 +431,7 @@ normalfailed: if (stackpad!=tokpatlen) {
goto nextmatch; goto nextmatch;
} }
totalcost += mincost; totalcost += mincost;
#ifndef ALLOW_NEXTEM
BROKE(); BROKE();
#else
if (toplevel && !paniced) {
stackheight=0;
paniced++;
DEBUG("PANIC!");
goto panic;
} else
BROKE();
#endif
} }
for (i=0;i<nregneeded;i++) for (i=0;i<nregneeded;i++)
totalcost += docoerc(regtp[i],regcp[i],ply,toplevel,besttup->p_rar[i]); totalcost += docoerc(regtp[i],regcp[i],ply,toplevel,besttup->p_rar[i]);
@ -826,13 +832,25 @@ normalfailed: if (stackpad!=tokpatlen) {
case DO_RETURN: case DO_RETURN:
DEBUG("RETURN"); DEBUG("RETURN");
assert(origcp!=startupcode); assert(origcp!=startupcode);
doreturn:
#ifndef NDEBUG #ifndef NDEBUG
level--; level--;
#endif #endif
return(totalcost); return(totalcost);
} }
} }
doreturn:
#ifdef ALLOW_NEXTEM
if (toplevel && totalcost == INFINITY && ! paniced) {
totalcost += stackupto(&fakestack[stackheight-1], ply, toplevel);
paniced = 1;
DEBUG("PANIC!");
goto panic;
}
#endif
#ifndef NDEBUG
level--;
#endif
return(totalcost);
} }
readcodebytes() { readcodebytes() {

View file

@ -29,6 +29,9 @@ struct reginfo {
#if MAXMEMBERS!=0 #if MAXMEMBERS!=0
int r_members[MAXMEMBERS]; /* register contained within this reg */ int r_members[MAXMEMBERS]; /* register contained within this reg */
short r_clash[REGSETSIZE]; /* set of clashing registers */ short r_clash[REGSETSIZE]; /* set of clashing registers */
int r_iclash; /* index in clashlist; other represen-
tation of r_clash
*/
#endif #endif
int r_refcount; /* Times in use */ int r_refcount; /* Times in use */
token_t r_contents; /* Current contents */ token_t r_contents; /* Current contents */

View file

@ -22,9 +22,9 @@ unsigned costcalc();
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; { move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
register move_p mp; register move_p mp;
register unsigned t; unsigned t;
register struct reginfo *rp; register struct reginfo *rp;
tkdef_p tdp; register byte *tdpb;
int i; int i;
unsigned codegen(); unsigned codegen();
@ -36,32 +36,14 @@ move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
&machregs[tp2->t_att[0].ar].r_contents) && &machregs[tp2->t_att[0].ar].r_contents) &&
machregs[tp1->t_att[0].ar].r_contents.t_token!=0) machregs[tp1->t_att[0].ar].r_contents.t_token!=0)
return(0); return(0);
erasereg(tp2->t_att[0].ar);
machregs[tp2->t_att[0].ar].r_contents =
machregs[tp1->t_att[0].ar].r_contents ;
} else { } else {
if (eqtoken(&machregs[tp2->t_att[0].ar].r_contents,tp1)) if (eqtoken(&machregs[tp2->t_att[0].ar].r_contents,tp1))
return(0); return(0);
}
erasereg(tp2->t_att[0].ar); erasereg(tp2->t_att[0].ar);
machregs[tp2->t_att[0].ar].r_contents = *tp1;
}
for (rp=machregs+1;rp<machregs+NREGS;rp++) {
if (rp->r_contents.t_token == 0)
continue;
assert(rp->r_contents.t_token > 0);
tdp = &tokens[rp->r_contents.t_token];
for (i=0;i<TOKENSIZE;i++)
if (tdp->t_type[i] == EV_REG &&
clash(rp->r_contents.t_att[i].ar,tp2->t_att[0].ar)) {
erasereg(rp-machregs);
break;
}
}
} else if (tp1->t_token == -1) { } else if (tp1->t_token == -1) {
if (eqtoken(tp2,&machregs[tp1->t_att[0].ar].r_contents)) if (eqtoken(tp2,&machregs[tp1->t_att[0].ar].r_contents))
return(0); return(0);
machregs[tp1->t_att[0].ar].r_contents = *tp2;
} }
/* /*
* If we arrive here the move must really be executed * If we arrive here the move must really be executed
@ -89,6 +71,27 @@ move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
t = codegen(&coderules[mp->m_cindex],ply,toplevel,maxcost,0); t = codegen(&coderules[mp->m_cindex],ply,toplevel,maxcost,0);
tokpatlen -= 2; tokpatlen -= 2;
stackheight -= 2; stackheight -= 2;
if (tp2->t_token == -1) {
rp = &machregs[tp2->t_att[0].ar];
if (tp1->t_token == -1) {
rp->r_contents =
machregs[tp1->t_att[0].ar].r_contents ;
}
else rp->r_contents = *tp1;
if (rp->r_contents.t_token > 0) {
tdpb = &(tokens[rp->r_contents.t_token].t_type[0]);
for (i=0;i<TOKENSIZE;i++)
if (*tdpb++ == EV_REG &&
clash(rp->r_contents.t_att[i].ar,tp2->t_att[0].ar)) {
rp->r_contents.t_token = 0;
for (i = 0; i < TOKENSIZE; i++)
rp->r_contents.t_att[i].aw = 0;
break;
}
}
}
else if (tp1->t_token == -1)
machregs[tp1->t_att[0].ar].r_contents = *tp2;
return(t); return(t);
} }
@ -101,10 +104,7 @@ setcc(tp) token_p tp; {
test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; { test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; {
register test_p mp; register test_p mp;
register unsigned t; unsigned t;
register struct reginfo *rp;
tkdef_p tdp;
int i;
unsigned codegen(); unsigned codegen();
if (cocoreg.t_token!=0) { if (cocoreg.t_token!=0) {

View file

@ -59,30 +59,33 @@ getrefcount(regno) {
} }
erasereg(regno) { erasereg(regno) {
register struct reginfo *rp; register struct reginfo *rp = &machregs[regno];
register int i; register int i;
rp = &machregs[regno]; #if MAXMEMBERS==0
rp->r_contents.t_token = 0; rp->r_contents.t_token = 0;
for (i=0;i<TOKENSIZE;i++) for (i=0;i<TOKENSIZE;i++)
rp->r_contents.t_att[i].aw = 0; rp->r_contents.t_att[i].aw = 0;
#if MAXMEMBERS==0
awayreg(regno); awayreg(regno);
#else #else
for (rp=machregs+1;rp<machregs+NREGS;rp++) extern short clashlist[];
if (rp->r_clash[regno>>4]&(1<<(regno&017))) { register short *sp = &clashlist[rp->r_iclash];
rp->r_contents.t_token = 0;
while (*sp) {
rp = &machregs[*sp];
rp->r_contents.t_token = 0; rp->r_contents.t_token = 0;
for (i=0;i<TOKENSIZE;i++) for (i=0;i<TOKENSIZE;i++)
rp->r_contents.t_att[i].aw = 0; rp->r_contents.t_att[i].aw = 0;
awayreg(rp-machregs); awayreg(*sp++);
} }
#endif #endif
} }
awayreg(regno) { awayreg(regno) {
register struct reginfo *rp; register struct reginfo *rp;
register tkdef_p tdp; register byte *tdpb;
register i; register i;
/* Now erase recursively all registers containing /* Now erase recursively all registers containing
@ -90,14 +93,27 @@ awayreg(regno) {
*/ */
for (rp=machregs;rp<machregs+NREGS;rp++) { for (rp=machregs;rp<machregs+NREGS;rp++) {
if (rp->r_contents.t_token == -1) { if (rp->r_contents.t_token == -1) {
if (rp->r_contents.t_att[0].ar == regno) if (rp->r_contents.t_att[0].ar == regno) {
erasereg(rp-machregs); /* erasereg(rp-machregs);
} else if (rp->r_contents.t_token > 0) { replaced by the following three
tdp= & tokens[rp->r_contents.t_token]; lines
*/
rp->r_contents.t_token = 0;
for (i=0;i<TOKENSIZE;i++) for (i=0;i<TOKENSIZE;i++)
if (tdp->t_type[i] == EV_REG && rp->r_contents.t_att[i].aw = 0;
}
} else if (rp->r_contents.t_token > 0) {
tdpb= & (tokens[rp->r_contents.t_token].t_type[0]);
for (i=0;i<TOKENSIZE;i++)
if (*tdpb++ == EV_REG &&
rp->r_contents.t_att[i].ar == regno) { rp->r_contents.t_att[i].ar == regno) {
erasereg(rp-machregs); /* erasereg(rp-machregs);
replaced by the following three
lines
*/
rp->r_contents.t_token = 0;
for (i=0;i<TOKENSIZE;i++)
rp->r_contents.t_att[i].aw = 0;
break; break;
} }
} }
@ -137,7 +153,7 @@ inctcount(regno) {
chkregs() { chkregs() {
register struct reginfo *rp; register struct reginfo *rp;
register token_p tp; register token_p tp;
register tkdef_p tdp; register byte *tdpb;
int i; int i;
for (rp=machregs+1;rp<machregs+NREGS;rp++) { for (rp=machregs+1;rp<machregs+NREGS;rp++) {
@ -147,9 +163,9 @@ chkregs() {
if (tp->t_token == -1) if (tp->t_token == -1)
inctcount(tp->t_att[0].ar); inctcount(tp->t_att[0].ar);
else { else {
tdp = &tokens[tp->t_token]; tdpb = &(tokens[tp->t_token].t_type[0]);
for (i=0;i<TOKENSIZE;i++) for (i=0;i<TOKENSIZE;i++)
if (tdp->t_type[i]==EV_REG) if (*tdpb++==EV_REG)
inctcount(tp->t_att[i].ar); inctcount(tp->t_att[i].ar);
} }
} }