Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20140818150747

Diff

Diff from 1.62 to:

Annotations

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

Annotated File View

ragge
1.62
1 /*      $Id: order.c,v 1.62 2014/08/18 15:07:47 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.55
162                 {
163                         static struct rspecial s[] = {
ragge
1.62
164                                 { NEVEREDI }, { NEVERESI },
ragge
1.57
165                                 { NRIGHTESI }, { NOLEFTESI },
ragge
1.55
166                                 { NOLEFTECX }, { NORIGHTECX },
167                                 { NEVERECX }, { 0 } };
168                         return s;
169                 }
170
ragge
1.34
171         case STARG:
172                 {
173                         static struct rspecial s[] = {
ragge
1.60
174                                 { NEVEREDI }, { NEVERECX },
175                                 { NLEFTESI }, { 0 } };
ragge
1.34
176                         return s;
177                 }
178
ragge
1.28
179         case SCONV:
ragge
1.33
180                 if ((q->ltype & (TINT|TUNSIGNED|TSHORT|TUSHORT)) && 
ragge
1.28
181                     q->rtype == (TCHAR|TUCHAR)) {
182                         static struct rspecial s[] = { 
183                                 { NOLEFTESI }, { NOLEFTEDI }, { 0 } };
184                         return s;
ragge
1.50
185                 } else if ((q->ltype & TINT) &&
186                     q->rtype == (TLONGLONG|TULONGLONG)) {
ragge
1.30
187                         static struct rspecial s[] = {
188                                 { NLEFTEAX }, { NRESEAXEDX },
189                                 { NEVEREAX }, { NEVEREDX }, { 0 } };
190                         return s;
ragge
1.33
191                 } else if (q->ltype == TSHORT &&
192                     q->rtype == (TLONGLONG|TULONGLONG)) {
193                         static struct rspecial s[] = {
ragge
1.42
194                                 { NRESEAXEDX },
ragge
1.33
195                                 { NEVEREAX }, { NEVEREDX }, { 0 } };
196                         return s;
197                 } else if (q->ltype == TCHAR &&
198                     q->rtype == (TLONGLONG|TULONGLONG)) {
199                         static struct rspecial s[] = {
200                                 { NRESEAXEDX },
201                                 { NEVEREAX }, { NEVEREDX }, { 0 } };
202                         return s;
ragge
1.28
203                 }
204                 break;
ragge
1.24
205         case DIV:
ragge
1.29
206                 if (q->lshape == SBREG) {
207                         static struct rspecial s[] = {
208                                 { NEVERAL }, { NEVERAH },
ragge
1.32
209                                 { NLEFTAL }, { NRESAL },
ragge
1.37
210                                 { NORIGHTAH }, { NORIGHTAL }, { 0 } };
ragge
1.29
211                                 return s;
ragge
1.34
212                 } else if (q->lshape == SAREG) {
ragge
1.28
213                         static struct rspecial s[] = {
214                                 { NEVEREAX }, { NEVEREDX },
ragge
1.32
215                                 { NLEFTEAX }, { NRESEAX },
ragge
1.37
216                                 { NORIGHTEDX }, { NORIGHTEAX }, { 0 } };
ragge
1.28
217                         return s;
ragge
1.34
218                 } else if (q->lshape & SCREG) {
219                         static struct rspecial s[] = {
220                                 { NEVEREAX }, { NEVEREDX },
221                                 { NEVERECX }, { NRESEAXEDX }, { 0 } };
222                         return s;
ragge
1.28
223                 }
224                 break;
ragge
1.24
225         case MOD:
ragge
1.29
226                 if (q->lshape == SBREG) {
227                         static struct rspecial s[] = {
228                                 { NEVERAL }, { NEVERAH },
ragge
1.32
229                                 { NLEFTAL }, { NRESAH },
ragge
1.37
230                                 { NORIGHTAH }, { NORIGHTAL }, { 0 } };
ragge
1.29
231                         return s;
ragge
1.34
232                 } else if (q->lshape == SAREG) {
ragge
1.28
233                         static struct rspecial s[] = {
234                                 { NEVEREAX }, { NEVEREDX },
ragge
1.32
235                                 { NLEFTEAX }, { NRESEDX },
ragge
1.37
236                                 { NORIGHTEDX }, { NORIGHTEAX }, { 0 } };
ragge
1.28
237                         return s;
ragge
1.34
238                 } else if (q->lshape & SCREG) {
239                         static struct rspecial s[] = {
240                                 { NEVEREAX }, { NEVEREDX },
241                                 { NEVERECX }, { NRESEAXEDX }, { 0 } };
242                         return s;
ragge
1.28
243                 }
244                 break;
ragge
1.29
245         case MUL:
ragge
1.34
246                 if (q->lshape == SBREG) {
ragge
1.29
247                         static struct rspecial s[] = {
248                                 { NEVERAL }, { NEVERAH },
249                                 { NLEFTAL }, { NRESAL }, { 0 } };
250                         return s;
ragge
1.34
251                 } else if (q->lshape & SCREG) {
252                         static struct rspecial s[] = {
ragge
1.59
253                                 { NLEFTEAXEDX }, { NRIGHTECXESI },
254                                 { NEVERESI }, { NRESEAXEDX }, { 0 } };
ragge
1.34
255                         return s;
ragge
1.29
256                 }
257                 break;
258         case LS:
259         case RS:
ragge
1.35
260                 if (q->visit & (INAREG|INBREG)) {
ragge
1.29
261                         static struct rspecial s[] = {
ragge
1.49
262                                 { NRIGHTCL }, { NOLEFTECX }, { 0 } };
ragge
1.29
263                         return s;
ragge
1.35
264                 } else if (q->visit & INCREG) {
265                         static struct rspecial s[] = {
ragge
1.58
266                                 { NLEFTEAXEDX }, { NRIGHTCL },
267                                 { NRESEAXEDX }, { 0 } };
ragge
1.35
268                         return s;
ragge
1.25
269                 }
ragge
1.29
270                 break;
271
ragge
1.24
272         default:
ragge
1.28
273                 break;
ragge
1.24
274         }
ragge
1.28
275         comperr("nspecial entry %d"q - table);
ragge
1.26
276         return 0/* XXX gcc */
ragge
1.24
277 }
ragge
1.43
278
279 /*
280  * Set evaluation order of a binary node if it differs from default.
281  */
282 int
283 setorder(NODE *p)
284 {
ragge
1.47
285         return 0/* nothing differs on x86 */
ragge
1.43
286 }
ragge
1.51
287
288 /*
289  * set registers in calling conventions live.
290  */
291 int *
292 livecall(NODE *p)
293 {
ragge
1.53
294         static int r[] = { EAXEBX, -1 };
295         int off = 1;
ragge
1.51
296
ragge
1.53
297 #ifdef TLS
298         if (p->n_left->n_op == ICON &&
299             strcmp(p->n_left->n_name"___tls_get_addr@PLT") == 0)
300                 off--;
301 #endif
302
303         return kflag ? &r[off] : &r[2];
ragge
1.51
304 }
gmcgarry
1.52
305
306 /*
307  * Signal whether the instruction is acceptable for this target.
308  */
309 int
310 acceptable(struct optab *op)
311 {
312         return 1;
313 }
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 05:03 +0100