From 092292683c439c78b24983c7f0bdc086f5d024f6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 31 Mar 1988 10:14:48 +0000 Subject: [PATCH] modified to use a different 'panic' strategy, and use new clash-table in tables.c when possible, and some other tuning --- mach/proto/ncg/codegen.c | 56 ++++++++++++++++++++++++++-------------- mach/proto/ncg/data.h | 3 +++ mach/proto/ncg/move.c | 50 +++++++++++++++++------------------ mach/proto/ncg/reg.c | 54 ++++++++++++++++++++++++-------------- 4 files changed, 100 insertions(+), 63 deletions(-) diff --git a/mach/proto/ncg/codegen.c b/mach/proto/ncg/codegen.c index b281153aa..7157656f2 100644 --- a/mach/proto/ncg/codegen.c +++ b/mach/proto/ncg/codegen.c @@ -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 (distcostlimit) + 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;ip_rar[i]); +#ifndef NDEBUG +if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t); +#endif if ( t2) @@ -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;ip_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() { diff --git a/mach/proto/ncg/data.h b/mach/proto/ncg/data.h index 09be71515..625c84a79 100644 --- a/mach/proto/ncg/data.h +++ b/mach/proto/ncg/data.h @@ -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 */ diff --git a/mach/proto/ncg/move.c b/mach/proto/ncg/move.c index 7994e5f0e..49ab81da2 100644 --- a/mach/proto/ncg/move.c +++ b/mach/proto/ncg/move.c @@ -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;rpr_contents.t_token == 0) - continue; - assert(rp->r_contents.t_token > 0); - tdp = &tokens[rp->r_contents.t_token]; - for (i=0;it_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;ir_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) { diff --git a/mach/proto/ncg/reg.c b/mach/proto/ncg/reg.c index eb7c6d1c4..861b9419b 100644 --- a/mach/proto/ncg/reg.c +++ b/mach/proto/ncg/reg.c @@ -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;ir_contents.t_att[i].aw = 0; -#if MAXMEMBERS==0 awayreg(regno); #else - for (rp=machregs+1;rpr_clash[regno>>4]&(1<<(regno&017))) { - rp->r_contents.t_token = 0; - for (i=0;ir_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;ir_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;rpr_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;ir_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;it_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;ir_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;rpt_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;it_type[i]==EV_REG) + if (*tdpb++==EV_REG) inctcount(tp->t_att[i].ar); } } -- 2.34.1