Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.2
 
1.3
 
MAIN:ragge:20030531103446
 
optim.c
_>55 # include "pass1.h"
 66 
 77 # define SWAP(p,q) {sp=p; p=q; q=sp;}
<>8 -# define RCON(p) (p->in.right->in.op==ICON)
 9 -# define RO(p) p->in.right->in.op
 10 -# define RV(p) p->in.right->tn.lval
 11 -# define LCON(p) (p->in.left->in.op==ICON)
 12 -# define LO(p) p->in.left->in.op
 13 -# define LV(p) p->in.left->tn.lval
  8+# define RCON(p) (p->n_right->n_op==ICON)
  9+# define RO(p) p->n_right->n_op
  10+# define RV(p) p->n_right->n_lval
  11+# define LCON(p) (p->n_left->n_op==ICON)
  12+# define LO(p) p->n_left->n_op
  13+# define LV(p) p->n_left->n_lval
1414 
 1515         /* is p a constant without a name */
<>16 -# define nncon(p)       ((p)->in.op == ICON && (p)->tn.rval == NONAME)
  16+# define nncon(p)       ((p)->n_op == ICON && (p)->n_rval == NONAME)
1717 
 1818 int oflag = 0;
 1919 
     
 !
2323 NODE *
 2424 fortarg(NODE *p)
 2525 {
<>26 -        if( p->in.op == CM ){
 27 -                p->in.left = fortarg( p->in.left );
 28 -                p->in.right = fortarg( p->in.right );
  26+        if( p->n_op == CM ){
  27+                p->n_left = fortarg( p->n_left );
  28+                p->n_right = fortarg( p->n_right );
2929                 return(p);
 3030         }
 3131 
<>32 -        while( ISPTR(p->in.type) ){
  32+        while( ISPTR(p->n_type) ){
3333                 p = buildtree( UNARY MUL, p, NIL );
 3434         }
 3535         return( optim(p) );
     
 !
5050         int i;
 5151         TWORD t;
 5252 
<>53 -        if( (t=BTYPE(p->in.type))==ENUMTY || t==MOETY ) econvert(p);
  53+        if( (t=BTYPE(p->n_type))==ENUMTY || t==MOETY ) econvert(p);
5454         if( oflag ) return(p);
<>55 -        ty = optype( o=p->in.op);
  55+        ty = optype( o=p->n_op);
5656         if( ty == LTYPE ) return(p);
 5757 
<>58 -        if( ty == BITYPE ) p->in.right = optim(p->in.right);
 59 -        p->in.left = optim(p->in.left);
  58+        if( ty == BITYPE ) p->n_right = optim(p->n_right);
  59+        p->n_left = optim(p->n_left);
6060 
 6161         /* collect constants */
 6262 
     
 !
6767                 return( clocal(p) );
 6868 
 6969         case FORTCALL:
<>70 -                p->in.right = fortarg( p->in.right );
  70+                p->n_right = fortarg( p->n_right );
7171                 break;
 7272 
 7373         case UNARY AND:
<>74 -                if( LO(p) != NAME || !andable(p->in.left) ) return(p);
  74+                if( LO(p) != NAME || !andable(p->n_left) ) return(p);
7575 
 7676                 LO(p) = ICON;
 7777 
 7878                 setuleft:
 7979                 /* paint over the type of the left hand side with the type of the top */
<>80 -                p->in.left->in.type = p->in.type;
 81 -                p->in.left->fn.cdim = p->fn.cdim;
 82 -                p->in.left->fn.csiz = p->fn.csiz;
 83 -                p->in.op = FREE;
 84 -                return( p->in.left );
  80+                p->n_left->n_type = p->n_type;
  81+                p->n_left->n_cdim = p->n_cdim;
  82+                p->n_left->n_csiz = p->n_csiz;
  83+                p->n_op = FREE;
  84+                return( p->n_left );
8585 
 8686         case UNARY MUL:
 8787                 if( LO(p) != ICON ) break;
 8888                 LO(p) = NAME;
 8989                 goto setuleft;
 9090 
 9191         case MINUS:
<>92 -                if( !nncon(p->in.right) ) break;
  92+                if( !nncon(p->n_right) ) break;
9393                 RV(p) = -RV(p);
<>94 -                o = p->in.op = PLUS;
  94+                o = p->n_op = PLUS;
9595 
 9696         case MUL:
 9797         case PLUS:
     
 !
100100         case ER:
 101101                 /* commutative ops; for now, just collect constants */
 102102                 /* someday, do it right */
<>103 -                if( nncon(p->in.left) || ( LCON(p) && !RCON(p) ) ) SWAP( p->in.left, p->in.right );
  103+                if( nncon(p->n_left) || ( LCON(p) && !RCON(p) ) ) SWAP( p->n_left, p->n_right );
104104                 /* make ops tower to the left, not the right */
 105105                 if( RO(p) == o ){
 106106                         NODE *t1, *t2, *t3;
<>107 -                        t1 = p->in.left;
 108 -                        sp = p->in.right;
 109 -                        t2 = sp->in.left;
 110 -                        t3 = sp->in.right;
  107+                        t1 = p->n_left;
  108+                        sp = p->n_right;
  109+                        t2 = sp->n_left;
  110+                        t3 = sp->n_right;
111111                         /* now, put together again */
<>112 -                        p->in.left = sp;
 113 -                        sp->in.left = t1;
 114 -                        sp->in.right = t2;
 115 -                        p->in.right = t3;
  112+                        p->n_left = sp;
  113+                        sp->n_left = t1;
  114+                        sp->n_right = t2;
  115+                        p->n_right = t3;
116116                         }
<>117 -                if(o == PLUS && LO(p) == MINUS && RCON(p) && RCON(p->in.left) &&
 118 -                   conval(p->in.right, MINUS, p->in.left->in.right)){
  117+                if(o == PLUS && LO(p) == MINUS && RCON(p) && RCON(p->n_left) &&
  118+                   conval(p->n_right, MINUS, p->n_left->n_right)){
119119                         zapleft:
<>120 -                        RO(p->in.left) = FREE;
  120+                        RO(p->n_left) = FREE;
121121                         LO(p) = FREE;
<>122 -                        p->in.left = p->in.left->in.left;
  122+                        p->n_left = p->n_left->n_left;
123123                 }
<>124 -                if( RCON(p) && LO(p)==o && RCON(p->in.left) &&
 125 -                    conval( p->in.right, o, p->in.left->in.right ) ){
  124+                if( RCON(p) && LO(p)==o && RCON(p->n_left) &&
  125+                    conval( p->n_right, o, p->n_left->n_right ) ){
126126                         goto zapleft;
 127127                         }
 128128                 else if( LCON(p) && RCON(p) &&
<>129 -                         conval( p->in.left, o, p->in.right ) ){
  129+                         conval( p->n_left, o, p->n_right ) ){
130130                         zapright:
 131131                         RO(p) = FREE;
<>132 -                        p->in.left = makety( p->in.left, p->in.type, p->fn.cdim, p->fn.csiz );
 133 -                        p->in.op = FREE;
 134 -                        return( clocal( p->in.left ) );
  132+                        p->n_left = makety(p->n_left, p->n_type, p->n_cdim, p->n_csiz );
  133+                        p->n_op = FREE;
  134+                        return( clocal( p->n_left ) );
135135                         }
 136136                 /* FALL THROUGH */
 137137 
 138138         case ASG MUL:
 139139                 /* change muls to adds or shifts */
 140140 
 141141                 if( (o == MUL || o == ASG MUL) &&
<>142 -                    nncon(p->in.right) && (i=ispow2(RV(p)))>=0){
  142+                    nncon(p->n_right) && (i=ispow2(RV(p)))>=0){
143143                         if( i == 0 ) /* multiplication by 1 */
 144144                                 goto zapright;
 145145                         /* c2 will turn 'i << 1' into 'i + i' for us */
 146146                         else {
<>147 -                                p->in.op = (asgop(o) ? ASG LS : LS);
 148 -                                o = p->in.op;
 149 -                                p->in.right->in.type = p->in.right->fn.csiz = INT;
  147+                                p->n_op = (asgop(o) ? ASG LS : LS);
  148+                                o = p->n_op;
  149+                                p->n_right->n_type = p->n_right->n_csiz = INT;
150150                                 RV(p) = i;
 151151                                 }
 152152                         }
 153153 
 154154                 /* change +'s of negative consts back to - */
<>155 -                if( o==PLUS && nncon(p->in.right) && RV(p)<0 ){
  155+                if( o==PLUS && nncon(p->n_right) && RV(p)<0 ){
156156                         RV(p) = -RV(p);
<>157 -                        o = p->in.op = MINUS;
  157+                        o = p->n_op = MINUS;
158158                         }
 159159                 /* FALL THROUGH */
 160160         case ASG AND:
     
 !
163163         case RS:
 164164         case LS:
 165165                 /* Operations with zero */
<>166 -                if( nncon(p->in.right) && RV(p) == 0 ) {
  166+                if( nncon(p->n_right) && RV(p) == 0 ) {
167167                         if( o == MUL || o == ASG MUL ||
 168168                             o == AND || o == ASG AND ) {
 169169                                 if( asgop(o) )
<>170 -                                        p->in.op = ASSIGN;
  170+                                        p->n_op = ASSIGN;
171171                                 else if( optype(LO(p)) == LTYPE ) {
<>172 -                                        p->in.op = FREE;
  172+                                        p->n_op = FREE;
173173                                         LO(p) = FREE;
<>174 -                                        p = p->in.right;
  174+                                        p = p->n_right;
175175                                         }
 176176                                 else
<>177 -                                        p->in.op = COMOP; /* side effects */
  177+                                        p->n_op = COMOP; /* side effects */
178178                                 }
 179179                         else if( o == PLUS || o == MINUS ||
 180180                                  o == ASG PLUS || o == ASG MINUS ||
     
 !
188188 
 189189         case ASG RS:
 190190         case ASG LS:
<>191 -                if( !ISUNSIGNED(p->in.left->in.type) )
  191+                if( !ISUNSIGNED(p->n_left->n_type) )
192192                         break;
<>193 -                if( p->in.right->in.op == ICON &&
 194 -                    p->in.right->tn.lval < 0 ) {
  193+                if( p->n_right->n_op == ICON &&
  194+                    p->n_right->n_lval < 0 ) {
195195                         /*
 196196                          * Technically negative shifts are illegal
 197197                          * but we can support them, at least with
 198198                          * constants; you take potluck with variables.
 199199                          */
<>200 -                        p->in.right->tn.lval = -p->in.right->tn.lval;
  200+                        p->n_right->n_lval = -p->n_right->n_lval;
201201                         switch( o ){
<>202 -                        case LS:        p->in.op = RS; break;
 203 -                        case ASG LS:    p->in.op = ASG RS; break;
 204 -                        case RS:        p->in.op = LS; break;
 205 -                        case ASG RS:    p->in.op = ASG LS; break;
  202+                        case LS:        p->n_op = RS; break;
  203+                        case ASG LS:    p->n_op = ASG RS; break;
  204+                        case RS:        p->n_op = LS; break;
  205+                        case ASG RS:    p->n_op = ASG LS; break;
206206                                 }
 207207                         }
 208208                 break;
 209209 
 210210         case ASG DIV:
 211211         case DIV:
<>212 -                if( nncon( p->in.right ) ){
  212+                if( nncon( p->n_right ) ){
213213                         if( RV(p) == 0 ) uerror("division by zero");
 214214                         else if( RV(p) == 1 ) goto zapright;
 215215                         /* Unsigned division by a power of two */
 216216                         else if( (i=ispow2(RV(p)))>=0 &&
<>217 -                                 (ISUNSIGNED(p->in.left->in.type) ||
 218 -                                  ISUNSIGNED(p->in.right->in.type)) ){
 219 -                                p->in.op = (asgop(o) ? ASG RS : RS);
 220 -                                p->in.right->in.type = p->in.right->fn.csiz = INT;
  217+                                 (ISUNSIGNED(p->n_left->n_type) ||
  218+                                  ISUNSIGNED(p->n_right->n_type)) ){
  219+                                p->n_op = (asgop(o) ? ASG RS : RS);
  220+                                p->n_right->n_type = p->n_right->n_csiz = INT;
221221                                 RV(p) = i;
 222222                                 }
 223223                         }
 224224                 break;
 225225 
 226226         case ASG MOD:
 227227         case MOD:
<>228 -                if( nncon(p->in.right) ){
  228+                if( nncon(p->n_right) ){
229229                         if( RV(p) == 0 ) uerror("modulus of zero");
 230230                         else if( RV(p) == 1 ){ /* mod by one gives zero */
 231231                                 RV(p) = 0;
 232232                                 if( asgop(o) )
<>233 -                                        p->in.op = ASSIGN;
  233+                                        p->n_op = ASSIGN;
234234                                 else if( optype(LO(p)) == LTYPE ) {
<>235 -                                        p->in.op = FREE;
  235+                                        p->n_op = FREE;
236236                                         LO(p) = FREE;
<>237 -                                        p = p->in.right;
  237+                                        p = p->n_right;
238238                                         }
 239239                                 else
<>240 -                                        p->in.op = COMOP; /* side effects */
  240+                                        p->n_op = COMOP; /* side effects */
241241                                 }
 242242                         else if ((i=ispow2(RV(p)))>=0 &&
<>243 -                                 (ISUNSIGNED(p->in.left->in.type) ||
 244 -                                  ISUNSIGNED(p->in.right->in.type)) ){
  243+                                 (ISUNSIGNED(p->n_left->n_type) ||
  244+                                  ISUNSIGNED(p->n_right->n_type)) ){
245245                                 /* Unsigned mod by a power of two */
<>246 -                                p->in.op = (asgop(o) ? ASG AND : AND);
  246+                                p->n_op = (asgop(o) ? ASG AND : AND);
247247                                 RV(p)--;
 248248                                 }
 249249                         }
     
 !
263263 
 264264                 /* exchange operands */
 265265 
<>266 -                sp = p->in.left;
 267 -                p->in.left = p->in.right;
 268 -                p->in.right = sp;
 269 -                p->in.op = revrel[p->in.op - EQ ];
  266+                sp = p->n_left;
  267+                p->n_left = p->n_right;
  268+                p->n_right = sp;
  269+                p->n_op = revrel[p->n_op - EQ ];
<_270270                 break;
 271271 
 272272                 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-09-19 23:54 +0200