make opcode an enum and cleanup a bunch of code so that
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Fri, 15 Aug 1986 10:13:19 +0000 (02:13 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Fri, 15 Aug 1986 10:13:19 +0000 (02:13 -0800)
dbx is more useful (i.e. can step over part of a line of code); add
tempreg and has[[23]ops macros; force clr to check acc when writing dest

SCCS-vsn: old/pcc/c2.tahoe/Makefile 1.3
SCCS-vsn: old/pcc/c2.tahoe/c2.h 1.3
SCCS-vsn: old/pcc/c2.tahoe/c20.c 1.4
SCCS-vsn: old/pcc/c2.tahoe/c21.c 1.4
SCCS-vsn: old/pcc/c2.tahoe/c22.c 1.6
SCCS-vsn: old/pcc/c2.tahoe/c23.c 1.3

usr/src/old/pcc/c2.tahoe/Makefile
usr/src/old/pcc/c2.tahoe/c2.h
usr/src/old/pcc/c2.tahoe/c20.c
usr/src/old/pcc/c2.tahoe/c21.c
usr/src/old/pcc/c2.tahoe/c22.c
usr/src/old/pcc/c2.tahoe/c23.c

index 6f78177..72d2f8f 100644 (file)
@@ -1,4 +1,4 @@
-#      Makefile        1.2     86/07/31
+#      Makefile        1.3     86/08/14
 #
 DESTDIR=
 CFLAGS=        -O
 #
 DESTDIR=
 CFLAGS=        -O
index a0eb2f6..8ba5214 100644 (file)
@@ -1,88 +1,26 @@
-/*     c2.h    1.2     86/07/27        */
+/*     c2.h    1.3     86/08/14        */
 
 /*
  * Header for object code improver
  */
 
 /* tokens */
 
 /*
  * Header for object code improver
  */
 
 /* tokens */
-#define JBR    1
-#define CBR    2
-#define JMP    3
-#define LABEL  4
-#define DLABEL 5
-#define EROU   6
-#define JSW    7
-#define MOV    8
-#define CLR    9
-#define INC    10
-#define DEC    11
-#define TST    12
-#define PUSH   13
-#define CVT    14
-#define MOVZ   15
-#define CMP    16
-#define ADD    17
-#define SUB    18
-#define BIT    19
-#define AND    20
-#define OR     21
-#define XOR    22
-#define COM    23
-#define NEG    24
-#define EMUL   25
-#define MUL    26
-#define DIV    27
-#define EDIV   28
-#define SHAL   29
-#define SHAR   30
-#define SHL    31
-#define SHR    32
-#define CALLF  33
-#define CALLS  34
-#define CASE   35
-#define ADDA   36
-#define SUBA   37
-#define AOBLEQ 38
-#define AOBLSS 39
-#define MOVA   40
-#define PUSHA  41
-#define LDF    42
-#define LNF    43
-#define STF    44
-#define CMPF   45
-#define CMPF2  46
-#define TSTF   47
-#define PUSHD  48
-#define CVLF   49
-#define CVFL   50
-#define LDFD   51
-#define CVDF   52
-#define NEGF   53
-#define ADDF   54
-#define SUBF   55
-#define MULF   56
-#define DIVF   57
-#define SINF   58
-#define COSF   59
-#define ATANF  60
-#define LOGF   61
-#define SQRTF  62
-#define EXPF   63
-#define MOVBLK 64
-#define MFPR   65
-#define MTPR   66
-#define PROBE  67
-#define MOVO   68
-#define TEXT   69
-#define DATA   70
-#define BSS    71
-#define ALIGN  72
-#define END    73
-#define LGEN   74
-#define WGEN   75
-#define SET    76
-#define LCOMM  77
-#define COMM   78
+typedef        enum {
+       NIL,
+       JBR, CBR, JMP, LABEL, DLABEL, EROU, JSW,
+       MOV, CLR, INC, DEC, TST, PUSH, CVT, MOVZ,
+       CMP, ADD, SUB, BIT, AND, OR, XOR, COM,
+       NEG, EMUL, MUL, DIV, EDIV, SHAL, SHAR,
+       SHL, SHR, CALLF, CALLS, CASE, ADDA, SUBA,
+       AOBLEQ, AOBLSS, MOVA, PUSHA, LDF, LNF, STF,
+       CMPF, CMPF2, TSTF, PUSHD, CVLF, CVFL, LDFD,
+       CVDF, NEGF, ADDF, SUBF, MULF, DIVF, SINF,
+       COSF, ATANF, LOGF, SQRTF, EXPF, MOVBLK,
+       MFPR, MTPR, PROBE, MOVO, TEXT, DATA, BSS,
+       ALIGN, END, LGEN, WGEN, SET, LCOMM, COMM
+} OpCode;
+
+#define        ord(e)  ((int)(e))
 
 #define        JEQ     0
 #define        JNE     1
 
 #define        JEQ     0
 #define        JNE     1
@@ -96,9 +34,9 @@
 #define        JLO     10
 #define        JHI     11
 
 #define        JLO     10
 #define        JHI     11
 
-#define JBC 12
-#define JBS 13
-#define RET 14
+#define        JBC     12
+#define        JBS     13
+#define        RET     14
 
 #define        BYTE    1
 #define        WORD    2
 
 #define        BYTE    1
 #define        WORD    2
 #define OPB    9
 #define OPX    10
 
 #define OPB    9
 #define OPX    10
 
+#define        has2ops(p)      (((p)->subop>>4) == OP2)
+#define        has3ops(p)      (((p)->subop>>4) == OP3)
+
 /* #define T(a,b) (a|((b)<<8)) NUXI problems */
 #define U(a,b) (a|((b)<<4))
 
 /* #define T(a,b) (a|((b)<<8)) NUXI problems */
 #define U(a,b) (a|((b)<<4))
 
 
 struct optab {
        char    opstring[7];
 
 struct optab {
        char    opstring[7];
-       char    opcod;
+       OpCode  opcod;
        unsigned char   subopcod;
 } optab[];
 
 struct node {
        unsigned char   subopcod;
 } optab[];
 
 struct node {
-       char    op;
+       OpCode  op;
        unsigned char   subop;
        short   refc;
        struct  node    *forw;
        unsigned char   subop;
        short   refc;
        struct  node    *forw;
@@ -136,7 +77,7 @@ struct node {
 };
 
 struct intleavetab  {
 };
 
 struct intleavetab  {
-       char            op;
+       OpCode          op;
        unsigned char   subop;
        int             intleavect;
 } intltab[];
        unsigned char   subop;
        int             intleavect;
 } intltab[];
@@ -193,6 +134,8 @@ char        ccloc[C2_ASIZE];
 #define MAXAOBDISP     5000
 
 #define NUSE 6
 #define MAXAOBDISP     5000
 
 #define NUSE 6
+#define        tempreg(s,r)    ((unsigned)((r)=isreg(s)) < NUSE)
+
 struct node *uses[NUSE + 7]; /* for backwards flow analysis */
 struct node *useacc; /* same for acc */
 char *lastrand; /* last operand of instruction */
 struct node *uses[NUSE + 7]; /* for backwards flow analysis */
 struct node *useacc; /* same for acc */
 char *lastrand; /* last operand of instruction */
index 37e2202..637d8ea 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)c20.c      1.3 (Berkeley/CCI) %G%";
+static char sccsid[] = "@(#)c20.c      1.4 (Berkeley/CCI) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -447,7 +447,7 @@ oplook()
        register char *p,*p2;
        register int t;
        char tempop[20];
        register char *p,*p2;
        register int t;
        char tempop[20];
-       static struct optab OPNULL={"",0,0};
+       static struct optab OPNULL={"",NIL,0};
 
        for (p=line, p2=tempop; *p && !isspace(*p); *p2++= *p++); *p2=0; p2=p;
        while (isspace(*p2)) ++p2; curlp=p2;
 
        for (p=line, p2=tempop; *p && !isspace(*p); *p2++= *p++); *p2=0; p2=p;
        while (isspace(*p2)) ++p2; curlp=p2;
@@ -548,7 +548,7 @@ iterate()
                        while ((p1=p->forw)!=0 && p1->op!=LABEL && p1->op!=DLABEL
                                && p1->op!=EROU && p1->op!=END
                                && p1->op!=ALIGN
                        while ((p1=p->forw)!=0 && p1->op!=LABEL && p1->op!=DLABEL
                                && p1->op!=EROU && p1->op!=END
                                && p1->op!=ALIGN
-                               && p1->op!=0 && p1->op!=DATA) {
+                               && p1->op!=NIL && p1->op!=DATA) {
                                nchange++;
                                iaftbr++;
                                if (p1->ref)
                                nchange++;
                                iaftbr++;
                                if (p1->ref)
index 2d933ae..dfffe7c 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)c21.c      1.3 (Berkeley/CCI) %G%";
+static char sccsid[] = "@(#)c21.c      1.4 (Berkeley/CCI) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -14,7 +14,7 @@ int bitsize[] = {0,8,16,32,64,32,64}; /* index by type codes */
 
 redun3(p) register struct node *p; {
 /* check for 3 addr instr which should be 2 addr */
 
 redun3(p) register struct node *p; {
 /* check for 3 addr instr which should be 2 addr */
-       if (OP3==((p->subop>>4)&0xF)) {
+       if (has3ops(p)) {
                if (equstr(regs[RT1],regs[RT3])
                  && (p->op==ADD || p->op==MUL || p->op==AND || p->op==OR || p->op==XOR)) {
                        register char *t=regs[RT1]; regs[RT1]=regs[RT2]; regs[RT2]=t;
                if (equstr(regs[RT1],regs[RT3])
                  && (p->op==ADD || p->op==MUL || p->op==AND || p->op==OR || p->op==XOR)) {
                        register char *t=regs[RT1]; regs[RT1]=regs[RT2]; regs[RT2]=t;
@@ -56,18 +56,18 @@ bmove() {
                }
        else if((cp1=p->code, *cp1++)=='$' &&
         (*cp1=='0' || *cp1=='1' || *cp1++=='-' && *cp1=='1') && cp1[1]==',') {
                }
        else if((cp1=p->code, *cp1++)=='$' &&
         (*cp1=='0' || *cp1=='1' || *cp1++=='-' && *cp1=='1') && cp1[1]==',') {
-               switch((p->code[1]<<8)|p->op) {
-               case (('0'<<8)|ADD):
-               case (('0'<<8)|SUB):
-               case (('-'<<8)|AND):
-               case (('0'<<8)|OR):
-               case (('0'<<8)|XOR):
-               case (('1'<<8)|MUL):
-               case (('1'<<8)|DIV):
-               case (('0'<<8)|SHAL):
-               case (('0'<<8)|SHAR):
-               case (('0'<<8)|SHL):
-               case (('0'<<8)|SHR):
+               switch((p->code[1]<<8)|ord(p->op)) {
+               case (('0'<<8)|ord(ADD)):
+               case (('0'<<8)|ord(SUB)):
+               case (('-'<<8)|ord(AND)):
+               case (('0'<<8)|ord(OR)):
+               case (('0'<<8)|ord(XOR)):
+               case (('1'<<8)|ord(MUL)):
+               case (('1'<<8)|ord(DIV)):
+               case (('0'<<8)|ord(SHAL)):
+               case (('0'<<8)|ord(SHAR)):
+               case (('0'<<8)|ord(SHL)):
+               case (('0'<<8)|ord(SHR)):
                        if(r == OP2) {
                                if(p->forw->op!=CBR) {
                                        delnode(p); redunm++; continue;
                        if(r == OP2) {
                                if(p->forw->op!=CBR) {
                                        delnode(p); redunm++; continue;
@@ -82,8 +82,8 @@ bmove() {
                                p = p->forw; redunm++; continue;
                        }
                        break;
                                p = p->forw; redunm++; continue;
                        }
                        break;
-               case (('0'<<8)|MUL):
-               case (('0'<<8)|AND):
+               case (('0'<<8)|ord(MUL)):
+               case (('0'<<8)|ord(AND)):
                        p->op=CLR; p->subop&=0xF; p->pop=0;
                        while(*p->code++ != ',');
                        if(r == OP3)
                        p->op=CLR; p->subop&=0xF; p->pop=0;
                        while(*p->code++ != ',');
                        if(r == OP3)
@@ -100,7 +100,7 @@ bmove() {
        case CALLS:
        case CALLF:
                clearuse(); goto std;
        case CALLS:
        case CALLF:
                clearuse(); goto std;
-       case 0:
+       case NIL:
                clearuse(); break;
        case CVT:
                { long n;
                clearuse(); break;
        case CVT:
                { long n;
@@ -131,7 +131,7 @@ bmove() {
        case ADD:
                if ((p->subop&0xF)!=LONG) goto std; cp1=p->code;
                if (*cp1++!='$') goto std; splitrand(p);
        case ADD:
                if ((p->subop&0xF)!=LONG) goto std; cp1=p->code;
                if (*cp1++!='$') goto std; splitrand(p);
-               if (isstatic(cp1) && (r=isreg(regs[RT2]))>=0 && r<NUSE && uses[r]==p->forw)
+               if (isstatic(cp1) && tempreg(regs[RT2],r) && uses[r]==p->forw)
                {
                        /* address comp:
                        **      addl2   $_foo,r0  \     movab   _foo[r0],bar
                {
                        /* address comp:
                        **      addl2   $_foo,r0  \     movab   _foo[r0],bar
@@ -223,8 +223,7 @@ bmove() {
                        if(isreg(regs[RT1]) < 0) goto std; /* alignment */
                        if (regs[RT2][0] != '$') goto std;
                        if (getnum(&regs[RT2][1]) != 1) goto std;
                        if(isreg(regs[RT1]) < 0) goto std; /* alignment */
                        if (regs[RT2][0] != '$') goto std;
                        if (getnum(&regs[RT2][1]) != 1) goto std;
-                       r = isreg(regs[RT3]);
-                       if (r < 0 || r >= NUSE) goto std;
+                       if (!tempreg(regs[RT3],r)) goto std;
                        if ((pf = p->forw)->op != BIT && pf->op!=AND) goto std;
                        if (uses[r] && uses[r] != pf) goto std;
                        splitrand(pf);
                        if ((pf = p->forw)->op != BIT && pf->op!=AND) goto std;
                        if (uses[r] && uses[r] != pf) goto std;
                        splitrand(pf);
@@ -247,7 +246,7 @@ bmove() {
                if ((shcnt = getnum(&regs[RT1][1])) < 1 || shcnt > 2) goto std;
                if ((shfrom = isreg(regs[RT2])) >= 0)
                        regfrom = copy(regs[RT2]);
                if ((shcnt = getnum(&regs[RT1][1])) < 1 || shcnt > 2) goto std;
                if ((shfrom = isreg(regs[RT2])) >= 0)
                        regfrom = copy(regs[RT2]);
-               if ((shto = isreg(regs[RT3])) >= 0 && shto<NUSE)
+               if (tempreg(regs[RT3],shto))
                {
                        int     regnum;
 
                {
                        int     regnum;
 
@@ -331,8 +330,7 @@ ashadd:
 
                splitrand(p);
                if(isreg(regs[RT1]) < 0) goto std; /* alignment */
 
                splitrand(p);
                if(isreg(regs[RT1]) < 0) goto std; /* alignment */
-               extreg = isreg(regs[RT3]);
-               if (extreg < 0 || extreg >= NUSE) goto std;
+               if (!tempreg(regs[RT3],extreg)) goto std;
                if ((pf = p->forw)->op != BIT) goto std;
                if (uses[extreg] && uses[extreg] != pf) goto std;
                splitrand(pf);
                if ((pf = p->forw)->op != BIT) goto std;
                if (uses[extreg] && uses[extreg] != pf) goto std;
                splitrand(pf);
@@ -538,7 +536,7 @@ ashadd:
 char *
 byondrd(p) register struct node *p; {
 /* return pointer to register which is "beyond last read/modify operand" */
 char *
 byondrd(p) register struct node *p; {
 /* return pointer to register which is "beyond last read/modify operand" */
-       if (OP2==(p->subop>>4)) return(regs[RT3]);
+       if (has2ops(p)) return(regs[RT3]);
        switch (p->op) {
                case MFPR:
                case PUSHA:
        switch (p->op) {
                case MFPR:
                case PUSHA:
@@ -566,175 +564,226 @@ byondrd(p) register struct node *p; {
 
 struct node *
 bflow(p)
 
 struct node *
 bflow(p)
-register struct node *p;
+       register struct node *p;
 {
        register char *cp1,*cp2,**preg;
        register int r, fr, dblflg=0;
        int flow= -1;
        struct node *olduse=0, *olduse1=0;
 
 {
        register char *cp1,*cp2,**preg;
        register int r, fr, dblflg=0;
        int flow= -1;
        struct node *olduse=0, *olduse1=0;
 
-       if(p->subop==QUAD || p->subop==DOUBLE || (p->subop&0xF0)==DOUBLE<<4)
+       if (p->subop==QUAD || p->subop==DOUBLE || (p->subop&0xF0)==DOUBLE<<4)
                dblflg |= 1;    /* double dest */
                dblflg |= 1;    /* double dest */
-       if((p->subop&0xF)==DOUBLE || p->subop==QUAD)
+       if ((p->subop&0xF)==DOUBLE || p->subop==QUAD)
                dblflg |= 2;    /* double src */
        splitrand(p);
                dblflg |= 2;    /* double src */
        splitrand(p);
-       if (p->op!=PUSH
+       if (p->op!=PUSH &&
 #ifndef EMOD
 #ifndef EMOD
-       && p->op!=EDIV
+       p->op!=EDIV &&
 #endif EMOD
 #endif EMOD
-       && p->op!=EMUL
-       && p->subop && 0<=(r=isreg(lastrand)) && r<NUSE && uses[r]==p->forw) {
-       if (equtype(p->subop,regs[r][0])
-       || ((p->op==CVT || p->op==MOVZ || p->op==CVFL)
-                        && 0xf&regs[r][0] && compat(0xf&(p->subop>>4),regs[r][0]))
-       || p->op==MOVA && compat(LONG, regs[r][0])) {
+       p->op!=EMUL &&
+       p->subop && tempreg(lastrand,r) && uses[r]==p->forw) {
+       if (equtype(p->subop,regs[r][0]) ||
+           ((p->op==CVT || p->op==MOVZ || p->op==CVFL) &&
+            (regs[r][0]&0xf) && compat((p->subop>>4)&0xf,regs[r][0])) ||
+           p->op==MOVA && compat(LONG, regs[r][0])) {
                register int r2;
                register int r2;
-               if (regs[r][1]!=0) {/* send directly to destination */
+
+               if (regs[r][1]!=0) {    /* send directly to destination */
                        if (p->op==INC || p->op==DEC) {
                        if (p->op==INC || p->op==DEC) {
-                               if (p->op==DEC) p->op=SUB; else p->op=ADD;
-                               p->subop=(OP2<<4)+(p->subop&0xF); /* use 2 now, convert to 3 later */
+                               p->op = (p->op==DEC) ? SUB : ADD;
+                               /* use 2 now, convert to 3 later */
+                               p->subop=(OP2<<4)+(p->subop&0xF);
                                p->pop=0;
                                p->pop=0;
-                               cp1=lastrand; cp2=regs[RT2]; while (*cp2++= *cp1++); /* copy reg */
+                               cp1=lastrand; cp2=regs[RT2];
+                               while (*cp2++= *cp1++)  /* copy reg */
+                                       ;
                                cp1=lastrand; *cp1++='$'; *cp1++='1'; *cp1=0;
                        }
                        cp1=regs[r]+1; cp2=lastrand;
                                cp1=lastrand; *cp1++='$'; *cp1++='1'; *cp1=0;
                        }
                        cp1=regs[r]+1; cp2=lastrand;
-                       if (OP2==(p->subop>>4)) {/* use 3 operand form of instruction */
+                       if (has2ops(p)) {
+                               /* use 3 operand form of instruction */
                                p->pop=0;
                                p->pop=0;
-                               p->subop += (OP3-OP2)<<4; lastrand=cp2=regs[RT3];
+                               p->subop += (OP3-OP2)<<4;
+                               lastrand = cp2 = regs[RT3];
                        }
                        }
-                       while (*cp2++= *cp1++);
+                       while (*cp2++= *cp1++)
+                               ;
                        if (p->op==MOVA && p->forw->op==PUSH) {
                                p->op=PUSHA;
                                *regs[RT2]=0; p->pop=0;
                        if (p->op==MOVA && p->forw->op==PUSH) {
                                p->op=PUSHA;
                                *regs[RT2]=0; p->pop=0;
-                       } else if ((p->op==MOV || p->op==CVT) && p->forw->op==PUSH) {
+                       } else if ((p->op==MOV || p->op==CVT) &&
+                           p->forw->op==PUSH) {
                                p->op=PUSH; p->subop &= 0xF;
                                *regs[RT2]=0; p->pop=0;
                        }
                        delnode(p->forw);
                                p->op=PUSH; p->subop &= 0xF;
                                *regs[RT2]=0; p->pop=0;
                        }
                        delnode(p->forw);
-                       if (0<=(r2=isreg(lastrand)) && r2<NUSE) {
-                               uses[r2]=uses[r]; uses[r]=0;
-                       }
+                       if (tempreg(lastrand,r2))
+                               uses[r2]=uses[r], uses[r]=0;
                        redun3(p);
                        newcode(p); redunm++; flow=r;
                        redun3(p);
                        newcode(p); redunm++; flow=r;
-               } else if (p->op==MOV) {
-                       /* superfluous fetch */
+               } else if (p->op==MOV) {        /* superfluous fetch */
                        int nmatch;
                        char src[C2_ASIZE];
        movit:
                        int nmatch;
                        char src[C2_ASIZE];
        movit:
-                       cp2=src; cp1=regs[RT1]; while (*cp2++= *cp1++);
+                       for (cp2=src, cp1=regs[RT1]; *cp2++= *cp1++;)
+                               ;
                        splitrand(p->forw);
                        if (p->forw->op != INC && p->forw->op != DEC)
                                lastrand=byondrd(p->forw);
                        nmatch=0;
                        for (preg=regs+RT1;*preg!=lastrand;preg++)
                                if (r==isreg(*preg)) {
                        splitrand(p->forw);
                        if (p->forw->op != INC && p->forw->op != DEC)
                                lastrand=byondrd(p->forw);
                        nmatch=0;
                        for (preg=regs+RT1;*preg!=lastrand;preg++)
                                if (r==isreg(*preg)) {
-                               cp2= *preg; cp1=src; while (*cp2++= *cp1++); ++nmatch;
+                                       cp2= *preg; cp1=src;
+                                       while (*cp2++= *cp1++)
+                                               ;
+                                       ++nmatch;
                                }
                        if (nmatch==1) {
                                }
                        if (nmatch==1) {
-                               if (OP2==(p->forw->subop>>4) && equstr(src,regs[RT2])) {
+                               if (has2ops(p->forw) && equstr(src,regs[RT2])) {
                                        p->forw->pop=0;
                                        p->forw->pop=0;
-                                       p->forw->subop += (OP3-OP2)<<4; cp1=regs[RT3];
-                                       *cp1++='r'; *cp1++=r+'0'; *cp1=0;
-                               }
-                               delnode(p); p=p->forw;
-                               if (0<=(r2=isreg(src)) && r2<NUSE) {
-                                       uses[r2]=uses[r]; uses[r]=0;
+                                       p->forw->subop += (OP3-OP2)<<4;
+                                       cp1=regs[RT3];
+                                       *cp1++ = 'r'; *cp1++ = r+'0'; *cp1=0;
                                }
                                }
+                               delnode(p);
+                               p=p->forw;
+                               if (tempreg(src,r2))
+                                       uses[r2]=uses[r], uses[r]=0;
                                redun3(p);
                                newcode(p); redunm++; flow=r;
                                redun3(p);
                                newcode(p); redunm++; flow=r;
-                       } else splitrand(p);
+                       } else
+                               splitrand(p);
                }
                }
-       } else if (p->op==MOV && (p->forw->op==CVT || p->forw->op==MOVZ)
-               && p->forw->subop&0xf   /* if base or index, then forget it */
-               && compat(p->subop,p->forw->subop) && !indexa(cp1=regs[RT1]))
-                       goto movit;
+       } else if (p->op==MOV && (p->forw->op==CVT || p->forw->op==MOVZ) &&
+           p->forw->subop&0xf &&       /* if base or index, then forget it */
+           compat(p->subop,p->forw->subop) && !indexa(cp1=regs[RT1]))
+               goto movit;
        }
        /* adjust 'lastrand' past any 'read' or 'modify' operands. */
        lastrand=byondrd(p);
        /* a 'write' clobbers the register. */
        }
        /* adjust 'lastrand' past any 'read' or 'modify' operands. */
        lastrand=byondrd(p);
        /* a 'write' clobbers the register. */
-       if (0<=(r=isreg(lastrand)) && r<NUSE
-       || OP2==(p->subop>>4) && 0<=(r=isreg(regs[RT2])) && r<NUSE && uses[r]==0) {
-               /* writing a dead register is useless, but watch side effects */
+       if (tempreg(lastrand,r) ||
+           (has2ops(p) && tempreg(regs[RT2],r) && uses[r]==0)) {
+               /*
+                * Writing a dead register is useless,
+                * but watch side effects
+                */
                switch (p->op) {
 #ifndef EMOD
                case EDIV:
 #endif EMOD
                case EMUL:
                switch (p->op) {
 #ifndef EMOD
                case EDIV:
 #endif EMOD
                case EMUL:
-               case AOBLEQ: case AOBLSS: break;
+               case AOBLEQ: case AOBLSS:
+                       break;
                default:
                default:
+                       /*
+                        * If no direct uses, check for
+                        * use of condition codes
+                        */
                        if (uses[r]==0 && ((dblflg&1)==0 || uses[r+1]==0)) {
                        if (uses[r]==0 && ((dblflg&1)==0 || uses[r+1]==0)) {
-                       /* no direct uses, check for use of condition codes */
-                               register struct node *q=p;
-                               while ((q=nonlab(q->forw))->op==JBR && q->subop==0) q=q->ref;   /* cc unused, unchanged */
-                               if (q->op!=CBR && q->op!=ADDA && q->op!=SUBA) {/* ... and destroyed */
+                               register struct node *q = p;
+
+                               while ((q = nonlab(q->forw))->op==JBR &&
+                                   q->subop==0)
+                                       q=q->ref; /* cc unused, unchanged */
+                               if (q->op!=CBR && q->op!=ADDA && q->op!=SUBA) {
+                                       /* ... and destroyed */
                                        preg=regs+RT1;
                                        preg=regs+RT1;
-                                       while (cp1= *preg++) {
-                                               if ((cp1==lastrand)  &&
-                                                   (p->op != CLR) &&
-                                                   (p->op != CVFL)) 
-                                               {redunm++; delnode(p); return(p->forw);}
-                                               if (equstr(cp1,lastrand)) break;
+                                       while (cp1 = *preg++) {
+                                               if (cp1==lastrand &&
+                                                   p->op != CLR &&
+                                                   p->op != CVFL) {
+                                                       redunm++;
+                                                       delnode(p);
+                                                       return(p->forw);
+                                               }
+                                               if (equstr(cp1,lastrand))
+                                                       break;
                                        }
                                }
                        }
                        flow=r;
                }
        }
                                        }
                                }
                        }
                        flow=r;
                }
        }
-       if (0<=(r=flow)) {
-               olduse=uses[r]; uses[r]=0; *(short *)(regs[r])=0;
+       if ((r=flow) >= 0) {
+               olduse=uses[r], uses[r]=0;
+               *(short *)(regs[r])=0;
                /* if r0 destroyed, dont keep r1 */
                /* if r0 destroyed, dont keep r1 */
-               if(dblflg&1) {
-                       olduse1=uses[++r]; uses[r]=0; *(short *)(regs[r])=0;
+               if (dblflg&1) {
+                       olduse1=uses[++r], uses[r]=0;
+                       *(short *)(regs[r])=0;
                }
        }
        /* now look for 'read' or 'modify' (read & write) uses */
        preg=regs+RT1; 
        while (*(cp1= *preg++)) {
                /* check for  r  */
                }
        }
        /* now look for 'read' or 'modify' (read & write) uses */
        preg=regs+RT1; 
        while (*(cp1= *preg++)) {
                /* check for  r  */
-               if (lastrand!=cp1 && 0<=(r=isreg(cp1)) && r<NUSE && (uses[r]==0)){
-                       uses[r]=p; cp2=regs[r]; *cp2++=p->subop;
-                       if((p->op==SHAL || p->op==SHAR || p->op==SHL || p->op==SHR)
-                                && cp1==regs[RT1]) cp2[-1]=BYTE;
-                       if(p->op==CBR && (p->subop==JBC || p->subop==JBS)) cp2[-1]=LONG;
-                       if(p->op==MOVA && cp1==regs[RT2]) cp2[-1]=LONG;
+               if (lastrand!=cp1 && tempreg(cp1,r) && uses[r]==0) {
+                       uses[r]=p;
+                       cp2=regs[r]; *cp2++=p->subop;
+                       if ((p->op==SHAL || p->op==SHAR ||
+                           p->op==SHL || p->op==SHR) &&
+                           cp1==regs[RT1])
+                               cp2[-1] = BYTE;
+                       if (p->op==CBR && (p->subop==JBC || p->subop==JBS))
+                               cp2[-1] = LONG;
+                       if (p->op==MOVA && cp1==regs[RT2])
+                               cp2[-1]=LONG;
                        /* ediv/emod's 2nd operand is quad */
                        /* ediv/emod's 2nd operand is quad */
-                       if(((p->op==EDIV
+                       if (((p->op==EDIV
 #ifdef EMOD
 #ifdef EMOD
-                       || p->op==EMOD
+                          || p->op==EMOD
 #endif EMOD
 #endif EMOD
-                       ) && cp1==regs[RT2] || (dblflg&2))
-                        && ++r<NUSE && uses[r]==0) {
+                          ) && cp1==regs[RT2] || (dblflg&2)) &&
+                          ++r<NUSE && uses[r]==0) {
                                *cp2=0;
                                *cp2=0;
-                               uses[r]=p; cp2=regs[r]; *cp2++=p->subop;
+                               uses[r]=p;
+                               cp2=regs[r]; *cp2++=p->subop;
                        }
                        }
-                       if(p->op==MOV || p->op==PUSH || p->op==CVT ||
-                        p->op==MOVZ || p->op==COM || p->op==NEG || p->op==STF) {
-                               if (p->op==PUSH) cp1="-(sp)";
-                               else {
+                       if (p->op==MOV || p->op==PUSH || p->op==CVT ||
+                           p->op==MOVZ || p->op==COM || p->op==NEG ||
+                           p->op==STF) {
+                               if (p->op!=PUSH) {
                                        cp1=regs[RT2];
                                        cp1=regs[RT2];
-                                       if (0<=(r=isreg(cp1)) && r<NUSE) {
-                                               /* reincarnation!! */
-                                       /* as in  addl2 r0,r1;  movl r1,r0;  ret  */
-                                               if(uses[r]==0)
+                                       if (tempreg(cp1,r)) {
+                                               /*
+                                                * reincarnation!!
+                                                * (as in  addl2 r0,r1;
+                                                *  movl r1,r0;  ret)
+                                                */
+                                               if (uses[r]==0)
                                                        uses[r]=olduse;
                                                        uses[r]=olduse;
-                                               if((dblflg&1) && uses[r+1]==0)
+                                               if ((dblflg&1) && uses[r+1]==0)
                                                        uses[r+1]=olduse1;
                                        }
                                                        uses[r+1]=olduse1;
                                        }
-                                       if (p->op!=MOV) cp1=0;
-                               }
-                               if (cp1) while (*cp2++= *cp1++);
-                               else *cp2=0;
-                       } else *cp2=0;
+                                       if (p->op!=MOV)
+                                               cp1=0;
+                               } else
+                                       cp1="-(sp)";
+                               if (cp1)
+                                       while (*cp2++= *cp1++)
+                                               ;
+                               else
+                                       *cp2=0;
+                       } else
+                               *cp2=0;
                        continue;
                }
                /* check for (r),[r] */
                        continue;
                }
                /* check for (r),[r] */
-               do if (*cp1=='(' || *cp1=='[') {/* get register number */
-                       char t;
-                       cp2= ++cp1; while (*++cp1!=')' && *cp1!=']'); t= *cp1; *cp1=0;
-                       if (0<=(r=isreg(cp2)) && r<NUSE && (uses[r]==0 || uses[r]==p)) {
-                               uses[r]=p; regs[r][0]=(*--cp2=='[' ? OPX<<4 : OPB<<4);
+               do {
+                       if (*cp1=='(' || *cp1=='[') { /* get register number */
+                               char t;
+                               for (cp2= ++cp1; *++cp1!=')' && *cp1!=']';)
+                                       ;
+                               t= *cp1; *cp1=0;
+                               if (tempreg(cp2,r) &&
+                                   (uses[r]==0 || uses[r]==p)) {
+                                       uses[r]=p;
+                                       regs[r][0] =
+                                           (*--cp2=='[' ? OPX<<4 : OPB<<4);
+                               }
+                               *cp1=t;
                        }
                        }
-                       *cp1=t;
                } while (*++cp1);
        }
 #ifdef MOVAFASTER
                } while (*++cp1);
        }
 #ifdef MOVAFASTER
@@ -760,7 +809,7 @@ register struct node *p;
                }
        }
 #endif MOVAFASTER
                }
        }
 #endif MOVAFASTER
-       return(p);
+       return (p);
 }
 
 /* try to eliminate STF's */
 }
 
 /* try to eliminate STF's */
@@ -771,7 +820,7 @@ register struct node *q;
        register struct node *p;
        register int r;
 
        register struct node *p;
        register int r;
 
-       if(!(q->op==STF && ((r=isreg(q->code))<NUSE) && r>=0))
+       if(q->op!=STF || !tempreg(q->code,r))
                return(q);
        if(uses[r]) {
                /* see if anyone destroys acc between us */
                return(q);
        if(uses[r]) {
                /* see if anyone destroys acc between us */
index 8b4b769..75a3fbc 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)c22.c      1.5 (Berkeley/CCI) %G%";
+static char sccsid[] = "@(#)c22.c      1.6 (Berkeley/CCI) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -65,19 +65,22 @@ rmove()
                r = isreg(regs[RT1]);
                r1 = isreg(regs[RT2]);
                dest(regs[RT2],p->subop, 1);
                r = isreg(regs[RT1]);
                r1 = isreg(regs[RT2]);
                dest(regs[RT2],p->subop, 1);
-               if ((regs[ACC][0]) && equstr(regs[RT2],regs[ACC]+1)) {
-                *(short *)(regs[ACC]) = 0;}
-
+               if ((regs[ACC][0]) && equstr(regs[RT2],regs[ACC]+1))
+                       *(short *)(regs[ACC]) = 0;
                if (r>=0) {
                        if (r1>=0) {
                                if (r == r1 && p->forw->op!=CBR) {
                if (r>=0) {
                        if (r1>=0) {
                                if (r == r1 && p->forw->op!=CBR) {
-                                       delnode(p); redunm++; nchange++; break;
+                                       delnode(p); redunm++; nchange++;
+                                       break;
                                }
                                if(regs[r][0])
                                        savereg(r1, regs[r]+1, p->subop);
                                }
                                if(regs[r][0])
                                        savereg(r1, regs[r]+1, p->subop);
-                       } else savereg(r, regs[RT2], p->subop);
-               } else if (r1>=0) savereg(r1, regs[RT1], p->subop);
-               else setcon(regs[RT1], regs[RT2], p->subop);
+                       } else
+                               savereg(r, regs[RT2], p->subop);
+               } else if (r1>=0)
+                       savereg(r1, regs[RT1], p->subop);
+               else
+                       setcon(regs[RT1], regs[RT2], p->subop);
                break;
 
 /* .rx,.wx or .rx,.rx,.wx */
                break;
 
 /* .rx,.wx or .rx,.rx,.wx */
@@ -114,16 +117,20 @@ rmove()
                        nst++; nchange++; break;
                }
                savereg(ACC, p->code, p->subop);
                        nst++; nchange++; break;
                }
                savereg(ACC, p->code, p->subop);
-       case CLR:
        case INC:
        case DEC:
        case CVFL:
                dest(p->code,p->subop, 1);
        case INC:
        case DEC:
        case CVFL:
                dest(p->code,p->subop, 1);
-               if (p->op==CLR)
-                       if ((r = isreg(p->code)) >= 0)
-                               savereg(r, "$0", p->subop);
-                       else
-                               setcon("$0", p->code, p->subop);
+               break;
+
+       case CLR:
+               dest(p->code,p->subop, 1);
+               if ((regs[ACC][0]) && equstr(p->code,regs[ACC]+1))
+                       *(short *)(regs[ACC]) = 0;
+               if ((r = isreg(p->code)) < 0)
+                       setcon("$0", p->code, p->subop);
+               else
+                       savereg(r, "$0", p->subop);
                break;
 
 /* .rx */
                break;
 
 /* .rx */
@@ -324,7 +331,7 @@ register struct node *p1, *p2;
 
        if (p1->op != p2->op || p1->subop != p2->subop)
                return(0);
 
        if (p1->op != p2->op || p1->subop != p2->subop)
                return(0);
-       if (p1->op>0 && p1->op<MOV)
+       if (p1->op != NIL && ord(p1->op) < ord(MOV))
                return(0);
        if (p1->op==MOVA && p1->labno!=p2->labno) return(0);
        cp1 = p1->code;
                return(0);
        if (p1->op==MOVA && p1->labno!=p2->labno) return(0);
        cp1 = p1->code;
@@ -778,7 +785,7 @@ struct intleavetab intltab[] = {
        LDFD,   U(FLOAT,DOUBLE),0, 
        CVDF,   U(DOUBLE,FLOAT),0,
        NEGF,   FLOAT,          0,
        LDFD,   U(FLOAT,DOUBLE),0, 
        CVDF,   U(DOUBLE,FLOAT),0,
        NEGF,   FLOAT,          0,
-       0,      0,              0};
+       NIL,    0,              0};
 
 interleave()
 {
 
 interleave()
 {
@@ -789,7 +796,7 @@ interleave()
        int count;
        for (p= first.forw; p!=0; p = p->forw){
                count = 0;
        int count;
        for (p= first.forw; p!=0; p = p->forw){
                count = 0;
-               for  (t =intltab; t->op != 0; t++){
+               for  (t =intltab; t->op != NIL; t++){
                        if (t->op == p->op && t->subop == p->subop){
                        count = t->intleavect;
                        break;
                        if (t->op == p->op && t->subop == p->subop){
                        count = t->intleavect;
                        break;
@@ -833,25 +840,25 @@ struct node *p, *p1;
        p1->back = p;
 }
 
        p1->back = p;
 }
 
-int termop[] = {
+OpCode termop[] = {
        JBR, CBR, JMP, LABEL, DLABEL, EROU, JSW, TST, CMP, BIT,
        CALLF, CALLS, CASE, AOBLEQ, AOBLSS, CMPF, CMPF2, TSTF, MOVBLK, MFPR,
        MTPR, PROBE, MOVO, TEXT, DATA, BSS, ALIGN, END, LGEN, SET,
        JBR, CBR, JMP, LABEL, DLABEL, EROU, JSW, TST, CMP, BIT,
        CALLF, CALLS, CASE, AOBLEQ, AOBLSS, CMPF, CMPF2, TSTF, MOVBLK, MFPR,
        MTPR, PROBE, MOVO, TEXT, DATA, BSS, ALIGN, END, LGEN, SET,
-       LCOMM, COMM, 0
-       }; 
+       LCOMM, COMM, NIL
+}; 
 
 sideeffect(p,p1)
 struct node *p, *p1;
 {
        register struct node *q;
        register int r;
 
 sideeffect(p,p1)
 struct node *p, *p1;
 {
        register struct node *q;
        register int r;
-       register int *t;
+       register OpCode *t;
        register char *cp;
        int i;
 
        register char *cp;
        int i;
 
-       if (p1->op == 0) return(1);  /*  special instructions */
+       if (p1->op == NIL) return(1);  /*  special instructions */
 
 
-       for (t = termop; *t!=0; t++){
+       for (t = termop; *t!=NIL; t++){
                if (*t == p1->op) return(1);
        }
        if ((p1->forw != NULL) && (p1->forw->op == CBR))
                if (*t == p1->op) return(1);
        }
        if ((p1->forw != NULL) && (p1->forw->op == CBR))
@@ -875,8 +882,7 @@ struct node *p, *p1;
                if (q->op == STF || q->op == CVFL || q->op == CVLF) 
                   {
                    if (equstr(q->code, regs[RT1])) return(1);
                if (q->op == STF || q->op == CVFL || q->op == CVLF) 
                   {
                    if (equstr(q->code, regs[RT1])) return(1);
-               if (OP3 == ((p1->subop >> 4)&0xF) || p1->op == EMUL 
-               || p1->op == EDIV)
+               if (has3ops(p1) || p1->op == EMUL || p1->op == EDIV)
                    if (equstr(q->code, regs[RT2]))
                       return(1);
                /*  handle the case  std -56(fp) pushl -60(fp) pushl
                    if (equstr(q->code, regs[RT2]))
                       return(1);
                /*  handle the case  std -56(fp) pushl -60(fp) pushl
index c66fae5..a8371c3 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)c23.c      1.2 (Berkeley/CCI) %G%";
+static char sccsid[] = "@(#)c23.c      1.3 (Berkeley/CCI) %G%";
 #endif
 
 #include "c2.h"
 #endif
 
 #include "c2.h"
@@ -200,37 +200,37 @@ readonly struct optab optab[] = {
 "mfpr",MFPR,LONG,
 "mtpr",MTPR,LONG,
 "probe",PROBE,BYTE,
 "mfpr",MFPR,LONG,
 "mtpr",MTPR,LONG,
 "probe",PROBE,BYTE,
-"adwc",0,0,
+"adwc",NIL,0,
 "movob",MOVO,BYTE,
 "movow",MOVO,WORD,
 "movob",MOVO,BYTE,
 "movow",MOVO,WORD,
-"bbssi",0,0,
-"bicpsw",0,0,
-"bispsw",0,0,
-"bpt",0,0,
-"btcs",0,0,
-"cmps2",0,0,
-"cmps3",0,0,
-"emul",0,0,
-"ffc",0,0,
-"ffs",0,0,
-"halt",0,0,
-"insque",0,0,
-"kcall",0,0,
-"ldpctx",0,0,
-"loadr",0,0,
-"movpsl",0,0,
-"movs2",0,0,
-"movs3",0,0,
-"nop",0,0,
-"rei",0,0,
-"remque",0,0,
-"sbwc",0,0,
-"storer",0,0,
-"svpctx",0,0,
-"sinf",0,0,
-"cosf",0,0,
-"atanf",0,0,
-"logf",0,0,
-"sqrtf",0,0,
-"expf",0,0,
-0,0,0};
+"bbssi",NIL,0,
+"bicpsw",NIL,0,
+"bispsw",NIL,0,
+"bpt",NIL,0,
+"btcs",NIL,0,
+"cmps2",NIL,0,
+"cmps3",NIL,0,
+"emul",NIL,0,
+"ffc",NIL,0,
+"ffs",NIL,0,
+"halt",NIL,0,
+"insque",NIL,0,
+"kcall",NIL,0,
+"ldpctx",NIL,0,
+"loadr",NIL,0,
+"movpsl",NIL,0,
+"movs2",NIL,0,
+"movs3",NIL,0,
+"nop",NIL,0,
+"rei",NIL,0,
+"remque",NIL,0,
+"sbwc",NIL,0,
+"storer",NIL,0,
+"svpctx",NIL,0,
+"sinf",NIL,0,
+"cosf",NIL,0,
+"atanf",NIL,0,
+"logf",NIL,0,
+"sqrtf",NIL,0,
+"expf",NIL,0,
+{0}};