BSD 4 development
[unix-history] / usr / src / cmd / mip / optim.c
index 7beaa7d..c5b449b 100644 (file)
@@ -1,12 +1,13 @@
+static char *sccsid ="%W% (Berkeley) %G%";
 # include "mfile1"
 
 # define SWAP(p,q) {sp=p; p=q; q=sp;}
 # include "mfile1"
 
 # define SWAP(p,q) {sp=p; p=q; q=sp;}
-# define RCON(p) (p->right->op==ICON)
-# define RO(p) p->right->op
-# define RV(p) p->right->lval
-# define LCON(p) (p->left->op==ICON)
-# define LO(p) p->left->op
-# define LV(p) p->left->lval
+# define RCON(p) (p->in.right->in.op==ICON)
+# define RO(p) p->in.right->in.op
+# define RV(p) p->in.right->tn.lval
+# define LCON(p) (p->in.left->in.op==ICON)
+# define LO(p) p->in.left->in.op
+# define LV(p) p->in.left->tn.lval
 
 int oflag = 0;
 
 
 int oflag = 0;
 
@@ -14,13 +15,13 @@ NODE *
 fortarg( p ) NODE *p; {
        /* fortran function arguments */
 
 fortarg( p ) NODE *p; {
        /* fortran function arguments */
 
-       if( p->op == CM ){
-               p->left = fortarg( p->left );
-               p->right = fortarg( p->right );
+       if( p->in.op == CM ){
+               p->in.left = fortarg( p->in.left );
+               p->in.right = fortarg( p->in.right );
                return(p);
                }
 
                return(p);
                }
 
-       while( ISPTR(p->type) ){
+       while( ISPTR(p->in.type) ){
                p = buildtree( UNARY MUL, p, NIL );
                }
        return( optim(p) );
                p = buildtree( UNARY MUL, p, NIL );
                }
        return( optim(p) );
@@ -37,13 +38,13 @@ optim(p) register NODE *p; {
        int i;
        TWORD t;
 
        int i;
        TWORD t;
 
-       if( (t=BTYPE(p->type))==ENUMTY || t==MOETY ) econvert(p);
+       if( (t=BTYPE(p->in.type))==ENUMTY || t==MOETY ) econvert(p);
        if( oflag ) return(p);
        if( oflag ) return(p);
-       ty = optype( o=p->op);
+       ty = optype( o=p->in.op);
        if( ty == LTYPE ) return(p);
 
        if( ty == LTYPE ) return(p);
 
-       if( ty == BITYPE ) p->right = optim(p->right);
-       p->left = optim(p->left);
+       if( ty == BITYPE ) p->in.right = optim(p->in.right);
+       p->in.left = optim(p->in.left);
 
        /* collect constants */
 
 
        /* collect constants */
 
@@ -54,23 +55,23 @@ optim(p) register NODE *p; {
                return( clocal(p) );
 
        case FORTCALL:
                return( clocal(p) );
 
        case FORTCALL:
-               p->right = fortarg( p->right );
+               p->in.right = fortarg( p->in.right );
                break;
 
        case UNARY AND:
                if( LO(p) != NAME ) cerror( "& error" );
 
                break;
 
        case UNARY AND:
                if( LO(p) != NAME ) cerror( "& error" );
 
-               if( !andable(p->left) ) return(p);
+               if( !andable(p->in.left) ) return(p);
 
                LO(p) = ICON;
 
                setuleft:
                /* paint over the type of the left hand side with the type of the top */
 
                LO(p) = ICON;
 
                setuleft:
                /* paint over the type of the left hand side with the type of the top */
-               p->left->type = p->type;
-               p->left->cdim = p->cdim;
-               p->left->csiz = p->csiz;
-               p->op = FREE;
-               return( p->left );
+               p->in.left->in.type = p->in.type;
+               p->in.left->fn.cdim = p->fn.cdim;
+               p->in.left->fn.csiz = p->fn.csiz;
+               p->in.op = FREE;
+               return( p->in.left );
 
        case UNARY MUL:
                if( LO(p) != ICON ) break;
 
        case UNARY MUL:
                if( LO(p) != ICON ) break;
@@ -78,9 +79,9 @@ optim(p) register NODE *p; {
                goto setuleft;
 
        case MINUS:
                goto setuleft;
 
        case MINUS:
-               if( !nncon(p->right) ) break;
+               if( !nncon(p->in.right) ) break;
                RV(p) = -RV(p);
                RV(p) = -RV(p);
-               o = p->op = PLUS;
+               o = p->in.op = PLUS;
 
        case MUL:
        case PLUS:
 
        case MUL:
        case PLUS:
@@ -89,58 +90,58 @@ optim(p) register NODE *p; {
        case ER:
                /* commutative ops; for now, just collect constants */
                /* someday, do it right */
        case ER:
                /* commutative ops; for now, just collect constants */
                /* someday, do it right */
-               if( nncon(p->left) || ( LCON(p) && !RCON(p) ) ) SWAP( p->left, p->right );
+               if( nncon(p->in.left) || ( LCON(p) && !RCON(p) ) ) SWAP( p->in.left, p->in.right );
                /* make ops tower to the left, not the right */
                if( RO(p) == o ){
                        NODE *t1, *t2, *t3;
                /* make ops tower to the left, not the right */
                if( RO(p) == o ){
                        NODE *t1, *t2, *t3;
-                       t1 = p->left;
-                       sp = p->right;
-                       t2 = sp->left;
-                       t3 = sp->right;
+                       t1 = p->in.left;
+                       sp = p->in.right;
+                       t2 = sp->in.left;
+                       t3 = sp->in.right;
                        /* now, put together again */
                        /* now, put together again */
-                       p->left = sp;
-                       sp->left = t1;
-                       sp->right = t2;
-                       p->right = t3;
+                       p->in.left = sp;
+                       sp->in.left = t1;
+                       sp->in.right = t2;
+                       p->in.right = t3;
                        }
                        }
-               if(o == PLUS && LO(p) == MINUS && RCON(p) && RCON(p->left) &&
-                 conval(p->right, MINUS, p->left->right)){
+               if(o == PLUS && LO(p) == MINUS && RCON(p) && RCON(p->in.left) &&
+                 conval(p->in.right, MINUS, p->in.left->in.right)){
                        zapleft:
                        zapleft:
-                       RO(p->left) = FREE;
+                       RO(p->in.left) = FREE;
                        LO(p) = FREE;
                        LO(p) = FREE;
-                       p->left = p->left->left;
+                       p->in.left = p->in.left->in.left;
                }
                }
-               if( RCON(p) && LO(p)==o && RCON(p->left) && conval( p->right, o, p->left->right ) ){
+               if( RCON(p) && LO(p)==o && RCON(p->in.left) && conval( p->in.right, o, p->in.left->in.right ) ){
                        goto zapleft;
                        }
                        goto zapleft;
                        }
-               else if( LCON(p) && RCON(p) && conval( p->left, o, p->right ) ){
+               else if( LCON(p) && RCON(p) && conval( p->in.left, o, p->in.right ) ){
                        zapright:
                        RO(p) = FREE;
                        zapright:
                        RO(p) = FREE;
-                       p->left = makety( p->left, p->type, p->cdim, p->csiz );
-                       p->op = FREE;
-                       return( clocal( p->left ) );
+                       p->in.left = makety( p->in.left, p->in.type, p->fn.cdim, p->fn.csiz );
+                       p->in.op = FREE;
+                       return( clocal( p->in.left ) );
                        }
 
                /* change muls to shifts */
 
                        }
 
                /* change muls to shifts */
 
-               if( o==MUL && nncon(p->right) && (i=ispow2(RV(p)))>=0){
+               if( o==MUL && nncon(p->in.right) && (i=ispow2(RV(p)))>=0){
                        if( i == 0 ){ /* multiplication by 1 */
                                goto zapright;
                                }
                        if( i == 0 ){ /* multiplication by 1 */
                                goto zapright;
                                }
-                       o = p->op = LS;
-                       p->right->type = p->right->csiz = INT;
+                       o = p->in.op = LS;
+                       p->in.right->in.type = p->in.right->fn.csiz = INT;
                        RV(p) = i;
                        }
 
                /* change +'s of negative consts back to - */
                        RV(p) = i;
                        }
 
                /* change +'s of negative consts back to - */
-               if( o==PLUS && nncon(p->right) && RV(p)<0 ){
+               if( o==PLUS && nncon(p->in.right) && RV(p)<0 ){
                        RV(p) = -RV(p);
                        RV(p) = -RV(p);
-                       o = p->op = MINUS;
+                       o = p->in.op = MINUS;
                        }
                break;
 
        case DIV:
                        }
                break;
 
        case DIV:
-               if( nncon( p->right ) && p->right->lval == 1 ) goto zapright;
+               if( nncon( p->in.right ) && p->in.right->tn.lval == 1 ) goto zapright;
                break;
 
        case EQ:
                break;
 
        case EQ:
@@ -157,10 +158,10 @@ optim(p) register NODE *p; {
 
                /* exchange operands */
 
 
                /* exchange operands */
 
-               sp = p->left;
-               p->left = p->right;
-               p->right = sp;
-               p->op = revrel[p->op - EQ ];
+               sp = p->in.left;
+               p->in.left = p->in.right;
+               p->in.right = sp;
+               p->in.op = revrel[p->in.op - EQ ];
                break;
 
                }
                break;
 
                }
@@ -177,5 +178,5 @@ ispow2( c ) CONSZ c; {
 
 nncon( p ) NODE *p; {
        /* is p a constant without a name */
 
 nncon( p ) NODE *p; {
        /* is p a constant without a name */
-       return( p->op == ICON && p->rval == NONAME );
+       return( p->in.op == ICON && p->tn.rval == NONAME );
        }
        }