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:
parent
35cb47328a
commit
092292683c
4 changed files with 100 additions and 63 deletions
|
@ -62,8 +62,8 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost
|
|||
int inscoerc=0;
|
||||
int procarg[2];
|
||||
#ifdef ALLOW_NEXTEM
|
||||
int paniced;
|
||||
char *savebp;
|
||||
static int paniced;
|
||||
char *savebp = 0;
|
||||
#endif
|
||||
state_t state;
|
||||
#define SAVEST savestatus(&state)
|
||||
|
@ -128,7 +128,7 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost
|
|||
#ifndef ALLOW_NEXTEM
|
||||
bp = nextem(toplevel);
|
||||
#else
|
||||
paniced=0;
|
||||
if (toplevel) paniced=0;
|
||||
savebp = nextem(toplevel);
|
||||
panic:
|
||||
bp = savebp;
|
||||
|
@ -171,9 +171,18 @@ if (Debug)
|
|||
if (dist<mindistance) {
|
||||
if(dist==0)
|
||||
goto gotit;
|
||||
#ifdef ALLOW_NEXTEM
|
||||
if (! paniced) {
|
||||
#endif
|
||||
npos=0;
|
||||
mindistance = dist;
|
||||
#ifdef ALLOW_NEXTEM
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef ALLOW_NEXTEM
|
||||
if (dist < MAXINT)
|
||||
#endif
|
||||
pos[npos++] = cindex;
|
||||
}
|
||||
}
|
||||
|
@ -198,8 +207,9 @@ if (Debug)
|
|||
RESTST;
|
||||
}
|
||||
FREEST;
|
||||
if (totalcost+mincost>costlimit)
|
||||
if (totalcost+mincost>costlimit) {
|
||||
BROKE();
|
||||
}
|
||||
} else {
|
||||
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]);
|
||||
#ifndef ALLOW_NEXTEM
|
||||
assert(!toplevel);
|
||||
BROKE();
|
||||
#else
|
||||
assert(!(toplevel&&paniced));
|
||||
goto normalfailed;
|
||||
if (paniced) goto normalfailed;
|
||||
#endif
|
||||
BROKE();
|
||||
}
|
||||
if (cp->c3_prop<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;
|
||||
for (; tup != 0; tup = ntup) {
|
||||
#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[1],
|
||||
tup->p_rar[2],
|
||||
tup->p_rar[3]);
|
||||
fprintf(stderr, "totalcost = %u, costlimit = %u, mincost = %u\n",
|
||||
totalcost, costlimit, mincost);
|
||||
}
|
||||
#endif
|
||||
ntup = tup->p_next;
|
||||
for (i=0,t=0;i<nregneeded && t<mincost; 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 ) {
|
||||
#ifndef NDEBUG
|
||||
if (Debug>2)
|
||||
|
@ -415,17 +431,7 @@ normalfailed: if (stackpad!=tokpatlen) {
|
|||
goto nextmatch;
|
||||
}
|
||||
totalcost += mincost;
|
||||
#ifndef ALLOW_NEXTEM
|
||||
BROKE();
|
||||
#else
|
||||
if (toplevel && !paniced) {
|
||||
stackheight=0;
|
||||
paniced++;
|
||||
DEBUG("PANIC!");
|
||||
goto panic;
|
||||
} else
|
||||
BROKE();
|
||||
#endif
|
||||
BROKE();
|
||||
}
|
||||
for (i=0;i<nregneeded;i++)
|
||||
totalcost += docoerc(regtp[i],regcp[i],ply,toplevel,besttup->p_rar[i]);
|
||||
|
@ -826,13 +832,25 @@ normalfailed: if (stackpad!=tokpatlen) {
|
|||
case DO_RETURN:
|
||||
DEBUG("RETURN");
|
||||
assert(origcp!=startupcode);
|
||||
doreturn:
|
||||
#ifndef NDEBUG
|
||||
level--;
|
||||
#endif
|
||||
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() {
|
||||
|
|
|
@ -29,6 +29,9 @@ struct reginfo {
|
|||
#if MAXMEMBERS!=0
|
||||
int r_members[MAXMEMBERS]; /* register contained within this reg */
|
||||
short r_clash[REGSETSIZE]; /* set of clashing registers */
|
||||
int r_iclash; /* index in clashlist; other represen-
|
||||
tation of r_clash
|
||||
*/
|
||||
#endif
|
||||
int r_refcount; /* Times in use */
|
||||
token_t r_contents; /* Current contents */
|
||||
|
|
|
@ -22,9 +22,9 @@ unsigned costcalc();
|
|||
|
||||
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
|
||||
register move_p mp;
|
||||
register unsigned t;
|
||||
unsigned t;
|
||||
register struct reginfo *rp;
|
||||
tkdef_p tdp;
|
||||
register byte *tdpb;
|
||||
int i;
|
||||
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[tp1->t_att[0].ar].r_contents.t_token!=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 {
|
||||
if (eqtoken(&machregs[tp2->t_att[0].ar].r_contents,tp1))
|
||||
return(0);
|
||||
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;
|
||||
}
|
||||
}
|
||||
erasereg(tp2->t_att[0].ar);
|
||||
} else if (tp1->t_token == -1) {
|
||||
if (eqtoken(tp2,&machregs[tp1->t_att[0].ar].r_contents))
|
||||
return(0);
|
||||
machregs[tp1->t_att[0].ar].r_contents = *tp2;
|
||||
}
|
||||
/*
|
||||
* 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);
|
||||
tokpatlen -= 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);
|
||||
}
|
||||
|
||||
|
@ -101,10 +104,7 @@ setcc(tp) token_p tp; {
|
|||
|
||||
test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; {
|
||||
register test_p mp;
|
||||
register unsigned t;
|
||||
register struct reginfo *rp;
|
||||
tkdef_p tdp;
|
||||
int i;
|
||||
unsigned t;
|
||||
unsigned codegen();
|
||||
|
||||
if (cocoreg.t_token!=0) {
|
||||
|
|
|
@ -59,30 +59,33 @@ getrefcount(regno) {
|
|||
}
|
||||
|
||||
erasereg(regno) {
|
||||
register struct reginfo *rp;
|
||||
register struct reginfo *rp = &machregs[regno];
|
||||
register int i;
|
||||
|
||||
rp = &machregs[regno];
|
||||
#if MAXMEMBERS==0
|
||||
rp->r_contents.t_token = 0;
|
||||
for (i=0;i<TOKENSIZE;i++)
|
||||
rp->r_contents.t_att[i].aw = 0;
|
||||
|
||||
#if MAXMEMBERS==0
|
||||
awayreg(regno);
|
||||
#else
|
||||
for (rp=machregs+1;rp<machregs+NREGS;rp++)
|
||||
if (rp->r_clash[regno>>4]&(1<<(regno&017))) {
|
||||
rp->r_contents.t_token = 0;
|
||||
for (i=0;i<TOKENSIZE;i++)
|
||||
rp->r_contents.t_att[i].aw = 0;
|
||||
awayreg(rp-machregs);
|
||||
}
|
||||
extern short clashlist[];
|
||||
register short *sp = &clashlist[rp->r_iclash];
|
||||
|
||||
rp->r_contents.t_token = 0;
|
||||
while (*sp) {
|
||||
rp = &machregs[*sp];
|
||||
rp->r_contents.t_token = 0;
|
||||
for (i=0;i<TOKENSIZE;i++)
|
||||
rp->r_contents.t_att[i].aw = 0;
|
||||
awayreg(*sp++);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
awayreg(regno) {
|
||||
register struct reginfo *rp;
|
||||
register tkdef_p tdp;
|
||||
register byte *tdpb;
|
||||
register i;
|
||||
|
||||
/* Now erase recursively all registers containing
|
||||
|
@ -90,14 +93,27 @@ awayreg(regno) {
|
|||
*/
|
||||
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
||||
if (rp->r_contents.t_token == -1) {
|
||||
if (rp->r_contents.t_att[0].ar == regno)
|
||||
erasereg(rp-machregs);
|
||||
if (rp->r_contents.t_att[0].ar == regno) {
|
||||
/* 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;
|
||||
}
|
||||
} else if (rp->r_contents.t_token > 0) {
|
||||
tdp= & tokens[rp->r_contents.t_token];
|
||||
tdpb= & (tokens[rp->r_contents.t_token].t_type[0]);
|
||||
for (i=0;i<TOKENSIZE;i++)
|
||||
if (tdp->t_type[i] == EV_REG &&
|
||||
if (*tdpb++ == EV_REG &&
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +153,7 @@ inctcount(regno) {
|
|||
chkregs() {
|
||||
register struct reginfo *rp;
|
||||
register token_p tp;
|
||||
register tkdef_p tdp;
|
||||
register byte *tdpb;
|
||||
int i;
|
||||
|
||||
for (rp=machregs+1;rp<machregs+NREGS;rp++) {
|
||||
|
@ -147,9 +163,9 @@ chkregs() {
|
|||
if (tp->t_token == -1)
|
||||
inctcount(tp->t_att[0].ar);
|
||||
else {
|
||||
tdp = &tokens[tp->t_token];
|
||||
tdpb = &(tokens[tp->t_token].t_type[0]);
|
||||
for (i=0;i<TOKENSIZE;i++)
|
||||
if (tdp->t_type[i]==EV_REG)
|
||||
if (*tdpb++==EV_REG)
|
||||
inctcount(tp->t_att[i].ar);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue