Debian Codegraph @

arch/aarch64/order.c

raw symbols SCIP
1 /* $Id: order.c,v 1.1 2020/06/13 14:55:53 ragge Exp $ */
2 /*
3 * Copyright (c) 2020 Puresoftware Ltd.
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 /*
19 * Machine-dependent code-generation strategy (pass 2).
20 */
21
22 #include <assert.h>
23 #include <string.h>
24
25 #include "pass2.h"
26
27 /*
28 * Check size of offset in OREG. Called by oregok() to see if an
29 * OREG can be generated.
30 */
31 int
32 notoff(TWORD ty, int r, CONSZ off, char *cp)
33 {
34 if (cp && cp[0]) return 1;
35 if (DEUNSIGN(ty) == INT || ty == UCHAR)
36 return !(off < 4096 && off > -4096);
37 else
38 return !(off < 256 && off > -256);
39 }
40
41 /*
42 * Generate instructions for an OREG. Why is this routine MD?
43 * Called by swmatch().
44 */
45 void
46 offstar(NODE *p, int shape)
47 {
48 NODE *r;
49
50 if (isreg(p))
51 return; /* Is already OREG */
52
53 r = p->n_right;
54 if( p->n_op == PLUS || p->n_op == MINUS ){
55 if( r->n_op == ICON ){
56 if (isreg(p->n_left) == 0)
57 (void)geninsn(p->n_left, INAREG);
58 /* Converted in ormake() */
59 return;
60 }
61 /* usually for arraying indexing: */
62 if (r->n_op == LS && r->n_right->n_op == ICON &&
63 getlval(r->n_right) == 2 && p->n_op == PLUS) {
64 if (isreg(p->n_left) == 0)
65 (void)geninsn(p->n_left, INAREG);
66 if (isreg(r->n_left) == 0)
67 (void)geninsn(r->n_left, INAREG);
68 return;
69 }
70 }
71 (void)geninsn(p, INAREG);
72 }
73
74 /*
75 * Unable to convert to OREG (notoff() returned failure). Output
76 * suitable instructions to replace OREG.
77 */
78 void
79 myormake(NODE *q)
80 {
81 NODE *p, *r;
82
83 if (x2debug)
84 printf("myormake(%p)\n", q);
85
86 p = q->n_left;
87
88 /*
89 * This handles failed OREGs conversions, due to the offset
90 * being too large for an OREG.
91 */
92 if ((p->n_op == PLUS || p->n_op == MINUS) && p->n_right->n_op == ICON) {
93 if (isreg(p->n_left) == 0)
94 (void)geninsn(p->n_left, INAREG);
95 if (isreg(p->n_right) == 0)
96 (void)geninsn(p->n_right, INAREG);
97 (void)geninsn(p, INAREG);
98 } else if (p->n_op == REG) {
99 q->n_op = OREG;
100 setlval(q, getlval(p));
101 q->n_rval = p->n_rval;
102 tfree(p);
103 } else if (p->n_op == PLUS && (r = p->n_right)->n_op == LS &&
104 r->n_right->n_op == ICON && getlval(r->n_right) == 2 &&
105 p->n_left->n_op == REG && r->n_left->n_op == REG) {
106 q->n_op = OREG;
107 setlval(q, 0);
108 q->n_rval = R2PACK(p->n_left->n_rval, r->n_left->n_rval,
109 getlval(r->n_right));
110 tfree(p);
111 }
112 }
113
114 /*
115 * Check to if the UMUL node can be converted into an OREG.
116 */
117 int
118 shumul(NODE *p, int shape)
119 {
120 /* Turns currently anything into OREG */
121 if (shape & SOREG)
122 return SROREG;
123 return SRNOPE;
124 }
125
126 /*
127 * Rewrite operations on binary operators (like +, -, etc...).
128 * Called as a result of a failed table lookup.
129 *
130 * Return nonzero to retry table search on new tree, or zero to fail.
131 */
132 int
133 setbin(NODE *p)
134 {
135 return 0;
136
137 }
138
139 /*
140 * Rewrite assignment operations.
141 * Called as a result of a failed table lookup.
142 *
143 * Return nonzero to retry table search on new tree, or zero to fail.
144 */
145 int
146 setasg(NODE *p, int cookie)
147 {
148 return 0;
149 }
150
151 /*
152 * Rewrite UMUL operation.
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 setuni(NODE *p, int cookie)
159 {
160 return 0;
161 }
162
163 /*
164 * Special handling of some instruction register allocation.
165 *
166 * Called as a result of specifying NSPECIAL in the table.
167 */
168 struct rspecial *
169 nspecial(struct optab *q)
170 {
171
172 switch (q->op) {
173 #if !defined(ARM_HAS_FPA) && !defined(ARM_HAS_VFP)
174 case UMINUS:
175 case SCONV:
176 if (q->lshape == SBREG && q->rshape == SAREG) {
177 static struct rspecial s[] = {
178 { NLEFT, R16 },
179 { NRES, R0 },
180 { 0 }
181 };
182 return s;
183 } else if (q->lshape == SAREG && q->rshape == SBREG) {
184 static struct rspecial s[] = {
185 { NLEFT, R0 },
186 { NRES, R16 },
187 { 0 }
188 };
189 return s;
190 } else if (q->lshape == SAREG && q->rshape == SAREG) {
191 static struct rspecial s[] = {
192 { NLEFT, R0 },
193 { NRES, R0 },
194 { 0 }
195 };
196 return s;
197 } else if (q->lshape == SBREG && q->rshape == SBREG) {
198 static struct rspecial s[] = {
199 { NLEFT, R16 },
200 { NRES, R16 },
201 { 0 }
202 };
203 return s;
204 }
205
206 case OPLOG:
207 if (q->lshape == SBREG) {
208 static struct rspecial s[] = {
209 { NLEFT, R16 },
210 { NRIGHT, R18 },
211 { NRES, R0 },
212 { 0 }
213 };
214 return s;
215 } else if (q->lshape == SAREG) {
216 static struct rspecial s[] = {
217 { NLEFT, R0 },
218 { NRIGHT, R1 },
219 { NRES, R0 },
220 { 0 }
221 };
222 return s;
223 }
224 case PLUS:
225 case MINUS:
226 case MUL:
227 #endif
228 case MOD:
229 case DIV:
230 if (q->lshape == SBREG) {
231 static struct rspecial s[] = {
232 { NLEFT, R16 },
233 { NRIGHT, R18 },
234 { NRES, R16 },
235 { 0 }
236 };
237 return s;
238 } else if (q->lshape == SAREG) {
239 static struct rspecial s[] = {
240 { NLEFT, R0 },
241 { NRIGHT, R1 },
242 { NRES, R0 },
243 { 0 }
244 };
245 return s;
246 }
247 case LS:
248 case RS:
249 if (q->lshape == SBREG) {
250 static struct rspecial s[] = {
251 { NLEFT, R16 },
252 { NRIGHT, R2 },
253 { NRES, R16 },
254 { 0 }
255 };
256 return s;
257 } else if (q->lshape == SAREG) {
258 static struct rspecial s[] = {
259 { NLEFT, R0 },
260 { NRIGHT, R1 },
261 { NRES, R0 },
262 { 0 }
263 };
264 return s;
265 }
266 case STASG:
267 {
268 static struct rspecial s[] = {
269 { NEVER, R0 },
270 { NRIGHT, R1 },
271 { NEVER, R2 },
272 { 0 } };
273 return s;
274 }
275 break;
276
277 default:
278 break;
279 }
280
281 #ifdef PCC_DEBUG
282 comperr("nspecial entry %d [0x%x]: %s", q - table, q->op, q->cstring);
283 #endif
284 return 0; /* XXX gcc */
285 }
286
287 /*
288 * Set evaluation order of a binary node ('+','-', '*', '/', etc) if it
289 * differs from default.
290 */
291 int
292 setorder(NODE *p)
293 {
294 return 0;
295 }
296
297 /*
298 * Set registers "live" at function calls (like arguments in registers).
299 * This is for liveness analysis of registers.
300 */
301 int *
302 livecall(NODE *p)
303 {
304 static int r[] = { R3, R2, R1, R0, -1 };
305 int num = 1;
306
307 if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
308 return &r[4-0];
309
310 for (p = p->n_right; p->n_op == CM; p = p->n_left)
311 num += szty(p->n_right->n_type);
312 num += szty(p->n_right->n_type);
313
314 num = (num > 4 ? 4 : num);
315
316 return &r[4 - num];
317 }
318
319 /*
320 * Signal whether the instruction is acceptable for this target.
321 */
322 int
323 acceptable(struct optab *op)
324 {
325 return features(op->visit & 0xffff0000);
326 }