Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20080927073522

Diff

Diff from 1.54 to:

Annotations

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

Annotated File View

ragge
1.54
1 /*      $Id: order.c,v 1.54 2008/09/27 07:35:22 ragge Exp $     */
ragge
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
30 # include "pass2.h"
31
ragge
1.31
32 #include <string.h>
33
ragge
1.1
34 int canaddr(NODE *);
35
36 /* is it legal to make an OREG or NAME entry which has an
37  * offset of off, (from a register of r), if the
38  * resulting thing had type t */
39 int
40 notoff(TWORD tint rCONSZ offchar *cp)
41 {
42         return(0);  /* YES */
43 }
44
ragge
1.12
45 /*
46  * Turn a UMUL-referenced node into OREG.
ragge
1.29
47  * Be careful about register classes, this is a place where classes change.
ragge
1.12
48  */
ragge
1.40
49 void
ragge
1.27
50 offstar(NODE *pint shape)
ragge
1.1
51 {
ragge
1.44
52         NODE *r;
53
ragge
1.1
54         if (x2debug)
55                 printf("offstar(%p)\n"p);
56
ragge
1.40
57         if (isreg(p))
58                 return/* Is already OREG */
59
ragge
1.44
60         r = p->n_right;
ragge
1.1
61         ifp->n_op == PLUS || p->n_op == MINUS ){
ragge
1.44
62                 ifr->n_op == ICON ){
63                         if (isreg(p->n_left) == 0)
64                                 (void)geninsn(p->n_leftINAREG);
65                         /* Converted in ormake() */
66                         return;
67                 }
68                 if (r->n_op == LS && r->n_right->n_op == ICON &&
69                     r->n_right->n_lval == 2 && p->n_op == PLUS) {
ragge
1.40
70                         if (isreg(p->n_left) == 0)
71                                 (void)geninsn(p->n_leftINAREG);
ragge
1.44
72                         if (isreg(r->n_left) == 0)
73                                 (void)geninsn(r->n_leftINAREG);
ragge
1.40
74                         return;
ragge
1.1
75                 }
76         }
ragge
1.29
77         (void)geninsn(pINAREG);
ragge
1.1
78 }
79
80 /*
ragge
1.44
81  * Do the actual conversion of offstar-found OREGs into real OREGs.
82  */
83 void
84 myormake(NODE *q)
85 {
86         NODE *p, *r;
87
88         if (x2debug)
89                 printf("myormake(%p)\n"q);
90
91         p = q->n_left;
92         if (p->n_op == PLUS && (r = p->n_right)->n_op == LS &&
93             r->n_right->n_op == ICON && r->n_right->n_lval == 2 &&
ragge
1.46
94             p->n_left->n_op == REG && r->n_left->n_op == REG) {
ragge
1.44
95                 q->n_op = OREG;
96                 q->n_lval = 0;
97                 q->n_rval = R2PACK(p->n_left->n_rvalr->n_left->n_rval0);
98                 tfree(p);
99         }
100 }
101
102 /*
ragge
1.12
103  * Shape matches for UMUL.  Cooperates with offstar().
104  */
105 int
ragge
1.54
106 shumul(NODE *pint shape)
ragge
1.12
107 {
108
109         if (x2debug)
110                 printf("shumul(%p)\n"p);
111
ragge
1.40
112         /* Turns currently anything into OREG on x86 */
ragge
1.54
113         if (shape & SOREG)
114                 return SROREG;
115         return SRNOPE;
ragge
1.12
116 }
117
118 /*
ragge
1.1
119  * Rewrite operations on binary operators (like +, -, etc...).
120  * Called as a result of table lookup.
121  */
122 int
123 setbin(NODE *p)
124 {
ragge
1.4
125
126         if (x2debug)
127                 printf("setbin(%p)\n"p);
ragge
1.10
128         return 0;
ragge
1.4
129
ragge
1.1
130 }
131
132 /* setup for assignment operator */
133 int
ragge
1.10
134 setasg(NODE *pint cookie)
ragge
1.1
135 {
136         if (x2debug)
137                 printf("setasg(%p)\n"p);
ragge
1.10
138         return(0);
ragge
1.1
139 }
140
ragge
1.10
141 /* setup for unary operator */
ragge
1.1
142 int
ragge
1.10
143 setuni(NODE *pint cookie)
ragge
1.1
144 {
ragge
1.10
145         return 0;
ragge
1.1
146 }
147
ragge
1.24
148 /*
149  * Special handling of some instruction register allocation.
150  */
ragge
1.26
151 struct rspecial *
152 nspecial(struct optab *q)
ragge
1.24
153 {
154         switch (q->op) {
ragge
1.47
155         case OPLOG:
156                 {
157                         static struct rspecial s[] = { { NEVEREAX }, { 0 } };
158                         return s;
159                 }
160
ragge
1.36
161         case STASG:
ragge
1.34
162         case STARG:
163                 {
164                         static struct rspecial s[] = {
165                                 { NEVEREAX }, { NEVEREDX },
166                                 { NEVERECX }, { 0 } };
167                         return s;
168                 }
169
ragge
1.28
170         case SCONV:
ragge
1.33
171                 if ((q->ltype & (TINT|TUNSIGNED|TSHORT|TUSHORT)) && 
ragge
1.28
172                     q->rtype == (TCHAR|TUCHAR)) {
173                         static struct rspecial s[] = { 
174                                 { NOLEFTESI }, { NOLEFTEDI }, { 0 } };
175                         return s;
ragge
1.50
176                 } else if ((q->ltype & TINT) &&
177                     q->rtype == (TLONGLONG|TULONGLONG)) {
ragge
1.30
178                         static struct rspecial s[] = {
179                                 { NLEFTEAX }, { NRESEAXEDX },
180                                 { NEVEREAX }, { NEVEREDX }, { 0 } };
181                         return s;
ragge
1.33
182                 } else if (q->ltype == TSHORT &&
183                     q->rtype == (TLONGLONG|TULONGLONG)) {
184                         static struct rspecial s[] = {
ragge
1.42
185                                 { NRESEAXEDX },
ragge
1.33
186                                 { NEVEREAX }, { NEVEREDX }, { 0 } };
187                         return s;
188                 } else if (q->ltype == TCHAR &&
189                     q->rtype == (TLONGLONG|TULONGLONG)) {
190                         static struct rspecial s[] = {
191                                 { NRESEAXEDX },
192                                 { NEVEREAX }, { NEVEREDX }, { 0 } };
193                         return s;
ragge
1.28
194                 }
195                 break;
ragge
1.24
196         case DIV:
ragge
1.29
197                 if (q->lshape == SBREG) {
198                         static struct rspecial s[] = {
199                                 { NEVERAL }, { NEVERAH },
ragge
1.32
200                                 { NLEFTAL }, { NRESAL },
ragge
1.37
201                                 { NORIGHTAH }, { NORIGHTAL }, { 0 } };
ragge
1.29
202                                 return s;
ragge
1.34
203                 } else if (q->lshape == SAREG) {
ragge
1.28
204                         static struct rspecial s[] = {
205                                 { NEVEREAX }, { NEVEREDX },
ragge
1.32
206                                 { NLEFTEAX }, { NRESEAX },
ragge
1.37
207                                 { NORIGHTEDX }, { NORIGHTEAX }, { 0 } };
ragge
1.28
208                         return s;
ragge
1.34
209                 } else if (q->lshape & SCREG) {
210                         static struct rspecial s[] = {
211                                 { NEVEREAX }, { NEVEREDX },
212                                 { NEVERECX }, { NRESEAXEDX }, { 0 } };
213                         return s;
ragge
1.28
214                 }
215                 break;
ragge
1.24
216         case MOD:
ragge
1.29
217                 if (q->lshape == SBREG) {
218                         static struct rspecial s[] = {
219                                 { NEVERAL }, { NEVERAH },
ragge
1.32
220                                 { NLEFTAL }, { NRESAH },
ragge
1.37
221                                 { NORIGHTAH }, { NORIGHTAL }, { 0 } };
ragge
1.29
222                         return s;
ragge
1.34
223                 } else if (q->lshape == SAREG) {
ragge
1.28
224                         static struct rspecial s[] = {
225                                 { NEVEREAX }, { NEVEREDX },
ragge
1.32
226                                 { NLEFTEAX }, { NRESEDX },
ragge
1.37
227                                 { NORIGHTEDX }, { NORIGHTEAX }, { 0 } };
ragge
1.28
228                         return s;
ragge
1.34
229                 } else if (q->lshape & SCREG) {
230                         static struct rspecial s[] = {
231                                 { NEVEREAX }, { NEVEREDX },
232                                 { NEVERECX }, { NRESEAXEDX }, { 0 } };
233                         return s;
ragge
1.28
234                 }
235                 break;
ragge
1.29
236         case MUL:
ragge
1.34
237                 if (q->lshape == SBREG) {
ragge
1.29
238                         static struct rspecial s[] = {
239                                 { NEVERAL }, { NEVERAH },
240                                 { NLEFTAL }, { NRESAL }, { 0 } };
241                         return s;
ragge
1.34
242                 } else if (q->lshape & SCREG) {
243                         static struct rspecial s[] = {
244                                 { NEVEREAX }, { NEVEREDX },
245                                 { NEVERECX }, { NRESEAXEDX }, { 0 } };
246                         return s;
ragge
1.29
247                 }
248                 break;
249         case LS:
250         case RS:
ragge
1.35
251                 if (q->visit & (INAREG|INBREG)) {
ragge
1.29
252                         static struct rspecial s[] = {
ragge
1.49
253                                 { NRIGHTCL }, { NOLEFTECX }, { 0 } };
ragge
1.29
254                         return s;
ragge
1.35
255                 } else if (q->visit & INCREG) {
256                         static struct rspecial s[] = {
257                                 { NEVEREAX }, { NEVEREDX },
258                                 { NEVERECX }, { NRESEAXEDX }, { 0 } };
259                         return s;
ragge
1.25
260                 }
ragge
1.29
261                 break;
262
ragge
1.24
263         default:
ragge
1.28
264                 break;
ragge
1.24
265         }
ragge
1.28
266         comperr("nspecial entry %d"q - table);
ragge
1.26
267         return 0/* XXX gcc */
ragge
1.24
268 }
ragge
1.43
269
270 /*
271  * Set evaluation order of a binary node if it differs from default.
272  */
273 int
274 setorder(NODE *p)
275 {
ragge
1.47
276         return 0/* nothing differs on x86 */
ragge
1.43
277 }
ragge
1.51
278
279 /*
280  * set registers in calling conventions live.
281  */
282 int *
283 livecall(NODE *p)
284 {
ragge
1.53
285         static int r[] = { EAXEBX, -1 };
286         int off = 1;
ragge
1.51
287
ragge
1.53
288 #ifdef TLS
289         if (p->n_left->n_op == ICON &&
290             strcmp(p->n_left->n_name"___tls_get_addr@PLT") == 0)
291                 off--;
292 #endif
293
294         return kflag ? &r[off] : &r[2];
ragge
1.51
295 }
gmcgarry
1.52
296
297 /*
298  * Signal whether the instruction is acceptable for this target.
299  */
300 int
301 acceptable(struct optab *op)
302 {
303         return 1;
304 }
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-10-31 08:01 +0100