Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20080927073522

Diff

Diff from 1.7 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/arch/powerpc/order.c

Annotated File View

ragge
1.7
1 /*      $Id: order.c,v 1.7 2008/09/27 07:35:23 ragge Exp $      */
gmcgarry
1.1
2 /*
3  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #include <assert.h>
30
31 # include "pass2.h"
32
33 #include <string.h>
34
35 int canaddr(NODE *);
36
gmcgarry
1.6
37 /*
38  * Check size of offset in OREG.  Called by oregok() to see if an
39  * OREG can be generated.
40  *
41  * returns 0 if it can, 1 otherwise.
42  */
gmcgarry
1.1
43 int
44 notoff(TWORD tint rCONSZ offchar *cp)
45 {
gmcgarry
1.6
46 #if 0
47         if (off >= 32767 || off <= -32768)
48                 printf("; notoff %lld TOO BIG!\n"off);
49 #endif
gmcgarry
1.2
50         if (cp && cp[0]) return 1;
gmcgarry
1.6
51         return (off >= 32768 || off <= -32769);
gmcgarry
1.1
52 }
53
54 /*
gmcgarry
1.6
55  * Generate instructions for an OREG.
56  * Called by swmatch().
gmcgarry
1.1
57  */
58 void
59 offstar(NODE *pint shape)
60 {
61         NODE *r;
62
63         if (x2debug)
64                 printf("offstar(%p)\n"p);
65
66         if (isreg(p))
67                 return/* Is already OREG */
68
69         r = p->n_right;
70         ifp->n_op == PLUS || p->n_op == MINUS ){
71                 ifr->n_op == ICON ){
72                         if (isreg(p->n_left) == 0)
73                                 (void)geninsn(p->n_leftINAREG);
74                         /* Converted in ormake() */
75                         return;
76                 }
77         }
78         (void)geninsn(pINAREG);
79 }
80
81 /*
gmcgarry
1.6
82  * Unable to convert to OREG (notoff() returned failure).  Output
83  * suitable instructions to replace OREG.
gmcgarry
1.1
84  */
85 void
86 myormake(NODE *q)
87 {
gmcgarry
1.6
88         NODE *p;
gmcgarry
1.1
89
90         if (x2debug)
91                 printf("myormake(%p)\n"q);
92
gmcgarry
1.2
93         p = q->n_left;
94
gmcgarry
1.6
95         /*
96          * This handles failed OREGs conversions, due to the offset
97          * being too large for an OREG.
98          */
gmcgarry
1.1
99         if ((p->n_op == PLUS || p->n_op == MINUS) && p->n_right->n_op == ICON) {
100                 if (isreg(p->n_left) == 0)
101                         (void)geninsn(p->n_leftINAREG);
102                 if (isreg(p->n_right) == 0)
103                         (void)geninsn(p->n_rightINAREG);
104                 (void)geninsn(pINAREG);
105         } else if (p->n_op == REG) {
106                 q->n_op = OREG;
107                 q->n_lval = p->n_lval;
108                 q->n_rval = p->n_rval;
109                 tfree(p);
110         }
111 }
112
113 /*
114  * Shape matches for UMUL.  Cooperates with offstar().
115  */
116 int
ragge
1.7
117 shumul(NODE *pint shape)
gmcgarry
1.1
118 {
119
120         if (x2debug)
121                 printf("shumul(%p)\n"p);
122
123         /* Turns currently anything into OREG on x86 */
ragge
1.7
124         if (shape & SOREG)
125                 return SROREG;
126         return SRNOPE;
gmcgarry
1.1
127 }
128
129 /*
130  * Rewrite operations on binary operators (like +, -, etc...).
131  * Called as a result of table lookup.
132  */
133 int
134 setbin(NODE *p)
135 {
136
137         if (x2debug)
138                 printf("setbin(%p)\n"p);
139         return 0;
140
141 }
142
143 /* setup for assignment operator */
144 int
145 setasg(NODE *pint cookie)
146 {
147         if (x2debug)
148                 printf("setasg(%p)\n"p);
149         return(0);
150 }
151
152 /* setup for unary operator */
153 int
154 setuni(NODE *pint cookie)
155 {
156         return 0;
157 }
158
159 /*
160  * Special handling of some instruction register allocation.
161  */
162 struct rspecial *
163 nspecial(struct optab *q)
164 {
165         if (x2debug)
166                 printf("nspecial: op=%d, visit=0x%x: %s"q->opq->visitq->cstring);
167
168         switch (q->op) {
169
gmcgarry
1.6
170         /* soft-float stuff */
171         case RS:
172         case LS:
173                 if (q->lshape == SBREG) {
174                         static struct rspecial s[] = {
175                                 { NLEFTR3R4 },
176                                 { NRIGHTR5 },
177                                 { NRESR3R4 },
178                                 { 0 },
179                         };
180                         return s;
181                 } else if (q->lshape == SAREG) {
182                         static struct rspecial s[] = {
183                                 { NLEFTR3 },
184                                 { NRIGHTR4 },
185                                 { NRESR3 },
186                                 { 0 },
187                         };
188                         return s;
189                 }
190
191                 cerror("nspecial LS/RS");
192                 break;
193
194         case UMINUS:
195         case SCONV:
196                 if (q->lshape == SBREG && q->rshape == SAREG) {
197                         static struct rspecial s[] = {
198                                 { NLEFTR3R4 },
199                                 { NRESR3 },
200                                 { 0 }
201                         };
202                         return s;
203                 } else if (q->lshape == SAREG && q->rshape == SBREG) {
204                         static struct rspecial s[] = {
205                                 { NLEFTR3 },
206                                 { NRESR3R4 },
207                                 { 0 }
208                         };
209                         return s;
210                 } else if (q->lshape == SAREG && q->rshape == SAREG) {
211                         static struct rspecial s[] = {
212                                 { NLEFTR3 },
213                                 { NRESR3 },
214                                 { 0 }
215                         };
216                         return s;
217                 } else if (q->lshape == SBREG && q->rshape == SBREG) {
218                         static struct rspecial s[] = {
219                                 { NLEFTR3R4 },
220                                 { NRESR3R4 },
221                                 { 0 }
222                         };
223                         return s;
224                 } else if (q->lshape == SCREG && q->rshape == SBREG) {
225                         static struct rspecial s[] = {
226                                 { NLEFTF1 },
227                                 { NEVERF0 }, /* stomped on */
228                                 { NRESR3R4 },
229                                 { 0 }
230                         };
231                         return s;
232                 } else if (q->lshape == SBREG && q->rshape == SCREG) {
233                         static struct rspecial s[] = {
234                                 { NLEFTR3R4 },
235                                 { NEVERF0 }, /* stomped on */
236                                 { NRESF1 },
237                                 { 0 }
238                         };
239                         return s;
240                 } else {
241                         static struct rspecial s[] = {
242                                 { NOLEFTR0 },
243                                 { 0 } };
244                         return s;
245                 }
246
247                 break;
248
249         case OPLOG:
250                 if (q->lshape == SBREG) {
251                         static struct rspecial s[] = {
252                                 { NLEFTR3R4 },
253                                 { NRIGHTR5R6 },
254                                 { NRESR3 },
255                                 { 0 }
256                         };
257                         return s;
258                 } else if (q->lshape == SAREG) {
259                         static struct rspecial s[] = {
260                                 { NLEFTR3 },
261                                 { NRIGHTR4 },
262                                 { NRESR3 },
263                                 { 0 }
264                         };
265                         return s;
266                 }
267
268                 cerror("nspecial oplog");
269                 break;
270
271         case PLUS:
272         case MINUS:
273         case MUL:
274         case DIV:
275         case MOD:
276                 if (q->lshape == SBREG && 
277                     (q->ltype & (TDOUBLE|TLDOUBLE|TLONGLONG|TULONGLONG))) {
278                         static struct rspecial s[] = {
279                                 { NLEFTR3R4 },
280                                 { NRIGHTR5R6 },
281                                 { NRESR3R4 },
282                                 { 0 }
283                         };
284                         return s;
285                 } else if (q->lshape == SAREG && q->ltype & TFLOAT) {
286                         static struct rspecial s[] = {
287                                 { NLEFTR3 },
288                                 { NRIGHTR4 },
289                                 { NRESR3 },
290                                 { 0 }
291                         };
292                         return s;
293                 } else if (q->lshape == SAREG) {
294                         static struct rspecial s[] = {
295                                 { NOLEFTR0 },
296                                 { 0 } };
297                         return s;
298                 }
299
300                 cerror("nspecial mul");
301                 break;
302
gmcgarry
1.4
303         case STASG:
304                 {
305                         static struct rspecial s[] = {
306                                 { NEVERR3 },
307                                 { NRIGHTR4 },
308                                 { NEVERR5 },
309                                 { 0 } };
310                         return s;
311                 }
312                 break;
313
gmcgarry
1.1
314         case OPLTYPE:
315                 {
316                         if (q->visit & SAREG) {
317                                 static struct rspecial s[] = {
318                                         { NEVERR0 },
319 //                                      { NRES, R3 }, // hack - i don't know why
320                                         { 0 } };
321                                 return s;
322                         }
323                 }
324                 break;
325
326         case ASSIGN:
327                 if (q->lshape & SNAME) {
328                         static struct rspecial s[] = {
329                                 { NEVERR0 },
330                                 { 0 } };
331                         return s;
332                 } else if (q->rshape & SNAME) {
333                         static struct rspecial s[] = {
334                                 { NOLEFTR0 },
335                                 { 0 } };
336                         return s;
337                 } else if (q->lshape & SOREG) {
338                         static struct rspecial s[] = {
339                                 { NOLEFTR0 },
340                                 { 0 } };
341                         return s;
342                 } else if (q->rshape & SOREG) {
343                         static struct rspecial s[] = {
344                                 { NORIGHTR0 },
345                                 { 0 } };
346                         return s;
347                 }
348                 /* fallthough */
349
350         case UMUL:
351         case AND:
352         case OR:
353         case ER:
354                 {
355                         static struct rspecial s[] = {
356                                 { NOLEFTR0 },
357                                 { 0 } };
358                         return s;
359                 }
360
361         default:
362                 break;
363         }
364
gmcgarry
1.4
365         comperr("nspecial entry %d: %s"q - tableq->cstring);
gmcgarry
1.1
366         return 0/* XXX gcc */
367 }
368
369 /*
370  * Set evaluation order of a binary node if it differs from default.
371  */
372 int
373 setorder(NODE *p)
374 {
375         return 0/* nothing differs on x86 */
376 }
gmcgarry
1.6
377
ragge
1.3
378 /*
379  * Set registers "live" at function calls (like arguments in registers).
380  * This is for liveness analysis of registers.
381  */
382 int *
383 livecall(NODE *p)
384 {
gmcgarry
1.6
385         static int r[] = { R10R9R8R7R6R5R4R3R30R31, -1 };
386         int num = 1;
387
388         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
389                 return &r[8-0];
390
391         for (p = p->n_rightp->n_op == CMp = p->n_left)
392                 num += szty(p->n_right->n_type);
393         num += szty(p->n_right->n_type);
394
395         num = (num > 8 ? 8 : num);
ragge
1.3
396
gmcgarry
1.6
397         return &r[8 - num];
ragge
1.3
398 }
399
gmcgarry
1.5
400 /*
401  * Signal whether the instruction is acceptable for this target.
402  */
403 int
404 acceptable(struct optab *op)
405 {
gmcgarry
1.6
406         if ((op->visit & FEATURE_PIC) != 0)
407                 return (kflag != 0);
408         return features(op->visit & 0xffff0000);
gmcgarry
1.5
409 }
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-11-01 06:26 +0100