Debian Codegraph @

arch/i86/order.c

raw symbols SCIP
1 /* $Id: order.c,v 1.4 2018/11/13 17:47:32 ragge Exp $ */
2 /*
3 * Copyright (c) 2003 Anders Magnusson ([email protected]).
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
32 #include <string.h>
33
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 t, int r, CONSZ off, char *cp)
41 {
42 return(0); /* YES */
43 }
44
45 /*
46 * Turn a UMUL-referenced node into OREG.
47 * Be careful about register classes, this is a place where classes change.
48 */
49 void
50 offstar(NODE *p, int shape)
51 {
52 NODE *r;
53
54 if (x2debug)
55 printf("offstar(%p)\n", p);
56
57 if (isreg(p))
58 return; /* Is already OREG */
59
60 r = p->n_right;
61 if( p->n_op == PLUS || p->n_op == MINUS ){
62 if( r->n_op == ICON ){
63 if (isreg(p->n_left) == 0)
64 (void)geninsn(p->n_left, INAREG);
65 /* Converted in ormake() */
66 return;
67 }
68 if (r->n_op == LS && r->n_right->n_op == ICON &&
69 getlval(r->n_right) == 2 && p->n_op == PLUS) {
70 if (isreg(p->n_left) == 0)
71 (void)geninsn(p->n_left, INAREG);
72 if (isreg(r->n_left) == 0)
73 (void)geninsn(r->n_left, INAREG);
74 return;
75 }
76 }
77 (void)geninsn(p, INAREG);
78 }
79
80 /*
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 && getlval(r->n_right) == 2 &&
94 p->n_left->n_op == REG && r->n_left->n_op == REG) {
95 q->n_op = OREG;
96 setlval(q, 0);
97 q->n_rval = R2PACK(p->n_left->n_rval, r->n_left->n_rval, 0);
98 tfree(p);
99 }
100 }
101
102 /*
103 * Shape matches for UMUL. Cooperates with offstar().
104 */
105 int
106 shumul(NODE *p, int shape)
107 {
108
109 if (x2debug)
110 printf("shumul(%p)\n", p);
111
112 /* Turns currently anything into OREG on x86 */
113 if (shape & SOREG)
114 return SROREG;
115 return SRNOPE;
116 }
117
118 /*
119 * Rewrite operations on binary operators (like +, -, etc...).
120 * Called as a result of table lookup.
121 */
122 int
123 setbin(NODE *p)
124 {
125
126 if (x2debug)
127 printf("setbin(%p)\n", p);
128 return 0;
129
130 }
131
132 /* setup for assignment operator */
133 int
134 setasg(NODE *p, int cookie)
135 {
136 if (x2debug)
137 printf("setasg(%p)\n", p);
138 return(0);
139 }
140
141 /* setup for unary operator */
142 int
143 setuni(NODE *p, int cookie)
144 {
145 return 0;
146 }
147
148 /*
149 * Special handling of some instruction register allocation.
150 *
151 * FIXME: review 32bit specials, a lot can go as we use helpers
152 */
153 struct rspecial *
154 nspecial(struct optab *q)
155 {
156 switch (q->op) {
157 case OPLOG:
158 {
159 static struct rspecial s[] = { { NEVER, AX }, { 0 } };
160 return s;
161 }
162
163 case STASG:
164 {
165 static struct rspecial s[] = {
166 { NEVER, DI },
167 { NRIGHT, SI }, { NOLEFT, SI },
168 { NOLEFT, CX }, { NORIGHT, CX },
169 { NEVER, CX }, { 0 } };
170 return s;
171 }
172
173 case STARG:
174 {
175 static struct rspecial s[] = {
176 { NEVER, DI }, { NEVER, CX },
177 { NLEFT, SI }, { 0 } };
178 return s;
179 }
180
181 case SCONV:
182 /* Force signed conversions into al/ax to use cbw */
183 if ((q->ltype & TCHAR) &&
184 q->rtype == (TINT|TUNSIGNED)) {
185 static struct rspecial s[] = {
186 { NLEFT, AL }, { NRES, AX },
187 { NEVER, AX }, { NEVER, AH}, {NEVER, AL },
188 { 0 } };
189 return s;
190 }
191 /* FIXME: do we need this rule with and based moves ? */
192 /* Force signed unconversions to avoid si and di */
193 if ((q->ltype & TUCHAR) &&
194 q->rtype == (TINT|TUNSIGNED)) {
195 static struct rspecial s[] = {
196 { NEVER, SI }, { NEVER, DI },
197 { 0 } };
198 return s;
199 } else if ((q->ltype & (TINT|TUNSIGNED)) &&
200 q->rtype == (TCHAR|TUCHAR)) {
201 static struct rspecial s[] = {
202 { NOLEFT, SI }, { NOLEFT, DI }, { 0 } };
203 return s;
204 /* Need to be able to use cwd */
205 } else if ((q->ltype & (TINT|TSHORT)) &&
206 q->rtype == (TLONG|TULONG)) {
207 static struct rspecial s[] = {
208 { NLEFT, AX }, { NRES, AXDX },
209 { NEVER, AX }, { NEVER, DX },
210 { 0 } };
211 return s;
212 /* Need to be use cbw cwd */
213 } else if (q->ltype == TCHAR &&
214 q->rtype == (TLONG|TULONG)) {
215 static struct rspecial s[] = {
216 { NRES, AXDX }, { NLEFT, AL },
217 { NEVER, AX }, { NEVER, DX },
218 { NEVER, AH }, { NEVER, AL },
219 { 0 } };
220 return s;
221 }
222 break;
223 case DIV:
224 if (q->lshape == SBREG) {
225 static struct rspecial s[] = {
226 { NEVER, AL }, { NEVER, AH },
227 { NLEFT, AL }, { NRES, AL },
228 { NORIGHT, AH }, { NORIGHT, AL }, { 0 } };
229 return s;
230 } else if (q->lshape == SAREG) {
231 static struct rspecial s[] = {
232 { NEVER, AX }, { NEVER, DX },
233 { NLEFT, AX }, { NRES, AX },
234 { NORIGHT, DX }, { NORIGHT, AX }, { 0 } };
235 return s;
236 }
237 /* using helpers */
238 else if (q->lshape & SCREG) {
239 static struct rspecial s[] = {
240 { NEVER, AX }, { NEVER, DX },
241 { NEVER, CX }, { NRES, AXDX }, { 0 } };
242 return s;
243 }
244 break;
245 case MOD:
246 if (q->lshape == SBREG) {
247 static struct rspecial s[] = {
248 { NEVER, AL }, { NEVER, AH },
249 { NLEFT, AL }, { NRES, AH },
250 { NORIGHT, AH }, { NORIGHT, AL }, { 0 } };
251 return s;
252 } else if (q->lshape == SAREG) {
253 static struct rspecial s[] = {
254 { NEVER, AX }, { NEVER, DX },
255 { NLEFT, AX }, { NRES, DX },
256 { NORIGHT, DX }, { NORIGHT, AX }, { 0 } };
257 return s;
258 } else if (q->lshape & SCREG) {
259 static struct rspecial s[] = {
260 { NEVER, AX }, { NEVER, DX },
261 { NEVER, CX }, { NRES, AXDX }, { 0 } };
262 return s;
263 }
264 break;
265 case MUL:
266 if (q->lshape == SAREG) {
267 static struct rspecial s[] = {
268 { NEVER, AX }, { NEVER, DX },
269 { NLEFT, AX }, { NRES, AX },
270 { NORIGHT, DX }, {NORIGHT, AX },
271 { 0 } };
272 return s;
273 }
274 if (q->lshape == SBREG) {
275 static struct rspecial s[] = {
276 { NEVER, AL }, { NEVER, AH },
277 { NLEFT, AL }, { NRES, AL }, { 0 } };
278 return s;
279 } else if (q->lshape & SCREG) {
280 static struct rspecial s[] = {
281 { NEVER, AX }, { NEVER, DX },
282 { NEVER, CX }, { NRES, AXDX }, { 0 } };
283 return s;
284 }
285 break;
286 case LS:
287 case RS:
288 if (q->visit & (INAREG|INBREG)) {
289 static struct rspecial s[] = {
290 { NRIGHT, CL }, { NOLEFT, CX }, { 0 } };
291 return s;
292 } else if (q->visit & INCREG) {
293 static struct rspecial s[] = {
294 { NLEFT, AXDX }, { NRIGHT, CL },
295 { NRES, AXDX }, { 0 } };
296 return s;
297 }
298 break;
299
300 default:
301 break;
302 }
303 comperr("nspecial entry %d", q - table);
304 return 0; /* XXX gcc */
305 }
306
307 /*
308 * Set evaluation order of a binary node if it differs from default.
309 */
310 int
311 setorder(NODE *p)
312 {
313 return 0; /* nothing differs on x86 */
314 }
315
316 /*
317 * set registers in calling conventions live.
318 */
319 int *
320 livecall(NODE *p)
321 {
322 static int r[] = { AX, BX, -1 };
323 int off = 1;
324 return kflag ? &r[off] : &r[2];
325 }
326
327 /*
328 * Signal whether the instruction is acceptable for this target.
329 */
330 int
331 acceptable(struct optab *op)
332 {
333 return 1;
334 }