Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20080927073522

Diff

Diff from 1.9 to:

Annotations

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

Annotated File View

ragge
1.9
1 /*      $Id: order.c,v 1.9 2008/09/27 07:35:22 ragge Exp $    */
gmcgarry
1.2
2 /*
3  * Copyright (c) 2007 Gregory McGarry (g.mcgarry@ieee.org).
4  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
gmcgarry
1.1
30 /*
31  *  Machine-dependent code-generation strategy (pass 2).
32  */
33
34 #include <assert.h>
35 #include <string.h>
36
37 #include "pass2.h"
38
39 /*
40  * Check size of offset in OREG.  Called by oregok() to see if an
41  * OREG can be generated.
42  */
43 int
gmcgarry
1.8
44 notoff(TWORD tyint rCONSZ offchar *cp)
gmcgarry
1.1
45 {
46         if (cp && cp[0]) return 1;
gmcgarry
1.8
47         if (DEUNSIGN(ty) == INT || ty == UCHAR)
48                 return !(off < 4096 && off > -4096);
49         else
50                 return !(off < 256 && off > -256);
gmcgarry
1.1
51 }
52
53 /*
54  * Generate instructions for an OREG.  Why is this routine MD?
55  * Called by swmatch().
56  */
57 void
58 offstar(NODE *pint shape)
59 {
60         NODE *r;
61
62         if (isreg(p))
63                 return/* Is already OREG */
64
65         r = p->n_right;
66         ifp->n_op == PLUS || p->n_op == MINUS ){
67                 ifr->n_op == ICON ){
68                         if (isreg(p->n_left) == 0)
69                                 (void)geninsn(p->n_leftINAREG);
70                         /* Converted in ormake() */
71                         return;
72                 }
73                 /* usually for arraying indexing: */
74                 if (r->n_op == LS && r->n_right->n_op == ICON &&
75                     r->n_right->n_lval == 2 && p->n_op == PLUS) {
76                         if (isreg(p->n_left) == 0)
77                                 (void)geninsn(p->n_leftINAREG);
78                         if (isreg(r->n_left) == 0)
79                                 (void)geninsn(r->n_leftINAREG);
80                         return;
81                 }
82         }
83         (void)geninsn(pINAREG);
84 }
85
86 /*
gmcgarry
1.6
87  * Unable to convert to OREG (notoff() returned failure).  Output
88  * suitable instructions to replace OREG.
gmcgarry
1.1
89  */
90 void
91 myormake(NODE *q)
92 {
ragge
1.4
93         NODE *p, *r;
94
95         if (x2debug)
96                 printf("myormake(%p)\n"q);
97
98         p = q->n_left;
gmcgarry
1.7
99
100         /*
101          * This handles failed OREGs conversions, due to the offset
102          * being too large for an OREG.
103          */
104         if ((p->n_op == PLUS || p->n_op == MINUS) && p->n_right->n_op == ICON) {
105                 if (isreg(p->n_left) == 0)
106                         (void)geninsn(p->n_leftINAREG);
107                 if (isreg(p->n_right) == 0)
108                         (void)geninsn(p->n_rightINAREG);
109                 (void)geninsn(pINAREG);
110         } else if (p->n_op == REG) {
111                 q->n_op = OREG;
112                 q->n_lval = p->n_lval;
113                 q->n_rval = p->n_rval;
114                 tfree(p);
115         } else if (p->n_op == PLUS && (r = p->n_right)->n_op == LS &&
ragge
1.4
116             r->n_right->n_op == ICON && r->n_right->n_lval == 2 &&
117             p->n_left->n_op == REG && r->n_left->n_op == REG) {
118                 q->n_op = OREG;
119                 q->n_lval = 0;
120                 q->n_rval = R2PACK(p->n_left->n_rvalr->n_left->n_rval,
121                                    r->n_right->n_lval);
122                 tfree(p);
123         }
gmcgarry
1.1
124 }
125
126 /*
127  * Check to if the UMUL node can be converted into an OREG.
128  */
129 int
ragge
1.9
130 shumul(NODE *pint shape)
gmcgarry
1.1
131 {
132         /* Turns currently anything into OREG */
ragge
1.9
133         if (shape & SOREG)
134                 return SROREG;
135         return SRNOPE;
gmcgarry
1.1
136 }
137
138 /*
139  * Rewrite operations on binary operators (like +, -, etc...).
140  * Called as a result of a failed table lookup.
141  *
142  * Return nonzero to retry table search on new tree, or zero to fail.
143  */
144 int
145 setbin(NODE *p)
146 {
147         return 0;
148
149 }
150
151 /*
152  * Rewrite assignment operations.
153  * Called as a result of a failed table lookup.
154  *
155  * Return nonzero to retry table search on new tree, or zero to fail.
156  */
157 int
158 setasg(NODE *pint cookie)
159 {
160         return 0;
161 }
162
163 /*
164  * Rewrite UMUL operation.
165  * Called as a result of a failed table lookup.
166  *
167  * Return nonzero to retry table search on new tree, or zero to fail.
168  */
169 int
170 setuni(NODE *pint cookie)
171 {
172         return 0;
173 }
174
175 /*
176  * Special handling of some instruction register allocation.
177  *
gmcgarry
1.2
178  * Called as a result of specifying NSPECIAL in the table.
gmcgarry
1.1
179  */
180 struct rspecial *
181 nspecial(struct optab *q)
182 {
gmcgarry
1.2
183
gmcgarry
1.1
184         switch (q->op) {
185
gmcgarry
1.2
186 #if !defined(ARM_HAS_FPA) && !defined(ARM_HAS_VFP)
187         case UMINUS:
188         case SCONV:
189                 if (q->lshape == SBREG && q->rshape == SAREG) {
190                         static struct rspecial s[] = {
191                                 { NLEFTR0R1 },
192                                 { NRESR0 },
193                                 { 0 }
194                         };
195                         return s;
196                 } else if (q->lshape == SAREG && q->rshape == SBREG) {
197                         static struct rspecial s[] = {
198                                 { NLEFTR0 },
199                                 { NRESR0R1 },
200                                 { 0 }
201                         };
202                         return s;
203                 } else if (q->lshape == SAREG && q->rshape == SAREG) {
204                         static struct rspecial s[] = {
205                                 { NLEFTR0 },
206                                 { NRESR0 },
207                                 { 0 }
208                         };
209                         return s;
210                 } else if (q->lshape == SBREG && q->rshape == SBREG) {
211                         static struct rspecial s[] = {
212                                 { NLEFTR0R1 },
213                                 { NRESR0R1 },
214                                 { 0 }
215                         };
216                         return s;
217                 }
218
219         case OPLOG:
220                 if (q->lshape == SBREG) {
221                         static struct rspecial s[] = {
222                                 { NLEFTR0R1 },
223                                 { NRIGHTR2R3 },
224                                 { NRESR0 },
225                                 { 0 }
226                         };
227                         return s;
228                 } else if (q->lshape == SAREG) {
229                         static struct rspecial s[] = {
230                                 { NLEFTR0 },
231                                 { NRIGHTR1 },
232                                 { NRESR0 },
233                                 { 0 }
234                         };
235                         return s;
236                 }
237         case PLUS:
238         case MINUS:
239         case MUL:
240 #endif
gmcgarry
1.1
241         case MOD:
242         case DIV:
gmcgarry
1.2
243                 if (q->lshape == SBREG) {
244                         static struct rspecial s[] = {
245                                 { NLEFTR0R1 },
246                                 { NRIGHTR2R3 },
247                                 { NRESR0R1 },
248                                 { 0 }
249                         };
250                         return s;
251                 } else if (q->lshape == SAREG) {
252                         static struct rspecial s[] = {
253                                 { NLEFTR0 },
254                                 { NRIGHTR1 },
255                                 { NRESR0 },
256                                 { 0 }
257                         };
258                         return s;
259                 }
260         case LS:
261         case RS:
262                 if (q->lshape == SBREG) {
263                         static struct rspecial s[] = {
264                                 { NLEFTR0R1 },
265                                 { NRIGHTR2 },
266                                 { NRESR0R1 },
267                                 { 0 }
268                         };
269                         return s;
270                 } else if (q->lshape == SAREG) {
gmcgarry
1.1
271                         static struct rspecial s[] = {
272                                 { NLEFTR0 },
273                                 { NRIGHTR1 },
274                                 { NRESR0 },
gmcgarry
1.2
275                                 { 0 }
gmcgarry
1.1
276                         };
277                         return s;
278                 }
279         case STASG:
280                 {
281                         static struct rspecial s[] = {
282                                 { NEVERR0 },
283                                 { NRIGHTR1 },
284                                 { NEVERR2 },
285                                 { 0 } };
286                         return s;
287                 }
288                 break;
289
290         default:
291                 break;
292         }
293
gmcgarry
1.2
294 #ifdef PCC_DEBUG
295         comperr("nspecial entry %d [0x%x]: %s"q - tableq->opq->cstring);
296 #endif
gmcgarry
1.1
297         return 0/* XXX gcc */
298 }
299
300 /*
301  * Set evaluation order of a binary node ('+','-', '*', '/', etc) if it
302  * differs from default.
303  */
304 int
305 setorder(NODE *p)
306 {
307         return 0;
308 }
309
310 /*
311  * Set registers "live" at function calls (like arguments in registers).
312  * This is for liveness analysis of registers.
313  */
314 int *
315 livecall(NODE *p)
316 {
317         static int r[] = { R3R2R1R0, -1 };
318         int num = 1;
319
gmcgarry
1.2
320         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
gmcgarry
1.1
321                 return &r[4-0];
322
gmcgarry
1.2
323         for (p = p->n_rightp->n_op == CMp = p->n_left)
324                 num += szty(p->n_right->n_type);
325         num += szty(p->n_right->n_type);
326
327         num = (num > 4 ? 4 : num);
gmcgarry
1.1
328
329         return &r[4 - num];
330 }
gmcgarry
1.3
331
332 /*
333  * Signal whether the instruction is acceptable for this target.
334  */
335 int
336 acceptable(struct optab *op)
337 {
gmcgarry
1.5
338         return features(op->visit & 0xffff0000);
gmcgarry
1.3
339 }
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-22 11:39 +0100