Debian Codegraph @

arch/sparc64/local2.c

raw symbols SCIP
1 /* $Id: local2.c,v 1.28 2016/09/26 16:45:42 ragge Exp $ */
2
3 /*
4 * Copyright (c) 2008 David Crawshaw <[email protected]>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include "pass1.h"
20 #include "pass2.h"
21
22
23 char *
24 rnames[] = {
25 /* "\%g0", always zero, removed due to 31-element class limit */
26 "\%g1", "\%g2", "\%g3", "\%g4", "\%g5", "\%g6", "\%g7",
27 "\%o0", "\%o1", "\%o2", "\%o3", "\%o4", "\%o5", "\%o6", "\%o7",
28 "\%l0", "\%l1", "\%l2", "\%l3", "\%l4", "\%l5", "\%l6", "\%l7",
29 "\%i0", "\%i1", "\%i2", "\%i3", "\%i4", "\%i5", "\%i6", "\%i7",
30
31 "\%f0", "\%f1", "\%f2", "\%f3", "\%f4", "\%f5", "\%f6", "\%f7",
32 "\%f8", "\%f9", "\%f10", "\%f11", "\%f12", "\%f13", "\%f14", "\%f15",
33 "\%f16", "\%f17", "\%f18", "\%f19", "\%f20", "\%f21", "\%f22", "\%f23",
34 "\%f24", "\%f25", "\%f26", "\%f27", "\%f28", "\%f29", "\%f30",
35 /*, "\%f31" XXX removed due to 31-element class limit */
36
37 "\%f0", "\%f2", "\%f4", "\%f6", "\%f8", "\%f10", "\%f12", "\%f14",
38 "\%f16", "\%f18", "\%f20", "\%f22", "\%f24", "\%f26", "\%f28", "\%f30",
39
40 "\%sp", "\%fp",
41 };
42
43 void
44 deflab(int label)
45 {
46 printf(LABFMT ":\n", label);
47 }
48
49 void
50 prologue(struct interpass_prolog *ipp)
51 {
52 int i, stack;
53
54 stack = V9RESERVE + V9STEP(p2maxautooff);
55
56 for (i = p2env.p_regs[0]; i; i >>= 1)
57 if (i & 1)
58 stack += 16;
59
60 /* TODO printf("\t.proc %d\n"); */
61 if (SIMM13(stack))
62 printf("\tsave %%sp,-%d,%%sp\n", stack);
63 else {
64 printf("\tsetx -%d,%%g4,%%g1\n", stack);
65 printf("\tsave %%sp,%%g1,%%sp\n");
66 }
67 }
68
69 void
70 eoftn(struct interpass_prolog *ipp)
71 {
72 printf("\tret\n");
73 printf("\trestore\n");
74 printf("\t.type %s,#function\n", ipp->ipp_name);
75 printf("\t.size %s,(.-%s)\n", ipp->ipp_name, ipp->ipp_name);
76 }
77
78 void
79 hopcode(int f, int o)
80 {
81 char *str;
82
83 switch (o) {
84 case EQ: str = "brz"; break;
85 case NE: str = "brnz"; break;
86 case ULE:
87 case LE: str = "brlez"; break;
88 case ULT:
89 case LT: str = "brlz"; break;
90 case UGE:
91 case GE: str = "brgez"; break;
92 case UGT:
93 case GT: str = "brgz"; break;
94 case PLUS: str = "add"; break;
95 case MINUS: str = "sub"; break;
96 case AND: str = "and"; break;
97 case OR: str = "or"; break;
98 case ER: str = "xor"; break;
99 default:
100 comperr("unknown hopcode: %d (with %c)", o, f);
101 return;
102 }
103
104 printf("%s%c", str, f);
105 }
106
107 int
108 tlen(NODE *p)
109 {
110 switch (p->n_type) {
111 case CHAR:
112 case UCHAR:
113 return 1;
114 case SHORT:
115 case USHORT:
116 return (SZSHORT / SZCHAR);
117 case FLOAT:
118 return (SZFLOAT / SZCHAR);
119 case DOUBLE:
120 return (SZDOUBLE / SZCHAR);
121 case INT:
122 case UNSIGNED:
123 return (SZINT / SZCHAR);
124 case LONG:
125 case ULONG:
126 case LONGLONG:
127 case ULONGLONG:
128 return SZLONGLONG / SZCHAR;
129 default:
130 if (!ISPTR(p->n_type))
131 comperr("tlen type unknown: %d");
132 return SZPOINT(p->n_type) / SZCHAR;
133 }
134 }
135
136 void
137 zzzcode(NODE * p, int c)
138 {
139 char *str;
140 NODE *l, *r;
141 int sz;
142 l = p->n_left;
143 r = p->n_right;
144
145 switch (c) {
146
147 case 'A': /* Add const. */
148 if (ISPTR(l->n_type) && l->n_rval == FP)
149 r->n_lval += V9BIAS;
150
151 if (SIMM13(r->n_lval))
152 expand(p, 0, "\tadd AL,AR,A1\t\t! add const\n");
153 else
154 expand(p, 0, "\tsetx AR,A3,A2\t\t! add const\n"
155 "\tadd AL,A2,A1\n");
156 break;
157 case 'B': /* Subtract const. */
158 if (ISPTR(l->n_type) && l->n_rval == FP)
159 r->n_lval -= V9BIAS;
160
161 if (SIMM13(r->n_lval))
162 expand(p, 0, "\tsub AL,AR,A1\t\t! subtract const\n");
163 else
164 expand(p, 0, "\tsetx AR,A3,A2\t\t! subtract const\n"
165 "\tsub AL,A2,A1\n");
166 break;
167 case 'C': /* Load constant to register. */
168 if (ISPTR(p->n_type))
169 expand(p, 0,
170 "\tsethi %h44(AL),A1\t\t! load label\n"
171 "\tor A1,%m44(AL),A1\n"
172 "\tsllx A1,12,A1\n"
173 "\tor A1,%l44(AL),A1\n");
174 else if (SIMM13(p->n_lval))
175 expand(p, 0, "\tor %g0,AL,A1\t\t\t! load const\n");
176 else
177 expand(p, 0, "\tsetx AL,A2,A1\t\t! load const\n");
178 break;
179 case 'F': /* Floating-point comparison, cf. hopcode(). */
180 switch (p->n_op) {
181 case EQ: str = "fbe"; break;
182 case NE: str = "fbne"; break;
183 case ULE:
184 case LE: str = "fbule"; break;
185 case ULT:
186 case LT: str = "fbul"; break;
187 case UGE:
188 case GE: str = "fbuge"; break;
189 case UGT:
190 case GT: str = "fbug"; break;
191 /* XXX
192 case PLUS: str = "add"; break;
193 case MINUS: str = "sub"; break;
194 case AND: str = "and"; break;
195 case OR: str = "or"; break;
196 case ER: str = "xor"; break;*/
197 default:
198 comperr("unknown float code: %d", p->n_op);
199 return;
200 }
201 printf(str);
202 break;
203
204 case 'Q': /* Structure assignment. */
205 /* TODO Check if p->n_stsize is small and use a few ldx's
206 to move the struct instead of memcpy. The equiv.
207 could be done on all the architectures. */
208 sz = attr_find(p->n_ap, ATTR_P2STRUCT)->iarg(0);
209 if (l->n_rval != O0)
210 printf("\tmov %s,%s\n", rnames[l->n_rval], rnames[O0]);
211 if (SIMM13(sz))
212 printf("\tor %%g0,%d,%%o2\n", sz);
213 else
214 printf("\tsetx %d,%%g1,%%o2\n", sz);
215 printf("\tcall memcpy\t\t\t! struct assign (dest, src, len)\n");
216 printf("\tnop\n");
217 break;
218 default:
219 cerror("unknown zzzcode call: %c", c);
220 }
221 }
222
223 int
224 rewfld(NODE * p)
225 {
226 return (1);
227 }
228
229 int
230 fldexpand(NODE *p, int cookie, char **cp)
231 {
232 printf("XXX fldexpand called\n"); /* XXX */
233 return 1;
234 }
235
236 int
237 flshape(NODE * p)
238 {
239 return SRREG;
240 }
241
242 int
243 shtemp(NODE * p)
244 {
245 return 0;
246 }
247
248
249 void
250 adrcon(CONSZ val)
251 {
252 }
253
254 void
255 conput(FILE * fp, NODE * p)
256 {
257 if (p->n_op != ICON) {
258 comperr("conput got bad op: %s", copst(p->n_op));
259 return;
260 }
261
262 if (p->n_name[0] != '\0') {
263 fprintf(fp, "%s", p->n_name);
264 if (p->n_lval > 0)
265 fprintf(fp, "+");
266 if (p->n_lval)
267 fprintf(fp, CONFMT, p->n_lval);
268 } else
269 fprintf(fp, CONFMT, p->n_lval);
270 }
271
272 void
273 insput(NODE * p)
274 {
275 comperr("insput");
276 }
277
278 void
279 upput(NODE *p, int size)
280 {
281 comperr("upput");
282 }
283
284 void
285 adrput(FILE * io, NODE * p)
286 {
287 int64_t off;
288
289 if (p->n_op == FLD) {
290 printf("adrput a FLD\n");
291 p = p->n_left;
292 }
293
294 if (p->n_op == UMUL && p->n_right == 0)
295 p = p->n_left;
296
297 off = p->n_lval;
298
299 switch (p->n_op) {
300 case NAME:
301 if (p->n_name[0] != '\0')
302 fputs(p->n_name, io);
303 if (off > 0)
304 fprintf(io, "+");
305 if (off != 0)
306 fprintf(io, CONFMT, (long long int)off);
307 return;
308 case OREG:
309 fprintf(io, "%s", rnames[p->n_rval]);
310 if (p->n_rval == FP)
311 off += V9BIAS;
312 if (p->n_rval == SP)
313 off += V9BIAS + V9RESERVE;
314 if (off > 0)
315 fprintf(io, "+");
316 if (off)
317 fprintf(io, CONFMT, (CONSZ)off);
318 return;
319 case ICON:
320 /* addressable value of the constant */
321 conput(io, p);
322 return;
323 case REG:
324 fputs(rnames[p->n_rval], io);
325 return;
326 case FUNARG:
327 /* We do something odd and store the stack offset in n_rval. */
328 fprintf(io, "%d", V9BIAS + V9RESERVE + p->n_rval);
329 return;
330 default:
331 comperr("bad address, %s, node %p", copst(p->n_op), p);
332 return;
333 }
334 }
335
336 void
337 cbgen(int o, int lab)
338 {
339 }
340
341 void
342 myreader(struct interpass * ipole)
343 {
344 }
345
346 void
347 mycanon(NODE * p)
348 {
349 }
350
351 void
352 myoptim(struct interpass * ipole)
353 {
354 }
355
356 void
357 rmove(int s, int d, TWORD t)
358 {
359 printf("\t");
360
361 if (t == FLOAT) printf("fmovs");
362 else if (t == DOUBLE) printf("fmovd");
363 else printf("mov");
364
365 printf(" %s,%s\t\t\t! rmove()\n", rnames[s], rnames[d]);
366 }
367
368 int
369 gclass(TWORD t)
370 {
371 if (t == FLOAT)
372 return CLASSB;
373 if (t == DOUBLE)
374 return CLASSC;
375 return CLASSA;
376 }
377
378 void
379 lastcall(NODE *p)
380 {
381 }
382
383 int
384 special(NODE *p, int shape)
385 {
386 return SRNOPE;
387 }
388
389 void mflags(char *str)
390 {
391 }
392
393 int
394 COLORMAP(int c, int *r)
395 {
396 int num=0;
397
398 switch (c) {
399 case CLASSA:
400 num += r[CLASSA];
401 return num < 32;
402 case CLASSB:
403 num += r[CLASSB];
404 num += 2*r[CLASSC];
405 return num < 32;;
406 case CLASSC:
407 num += r[CLASSC];
408 num += 2*r[CLASSB];
409 return num < 17;
410 case CLASSD:
411 return 0;
412 default:
413 comperr("COLORMAP: unknown class: %d", c);
414 return 0;
415 }
416 }
417 /*
418 * Do something target-dependent for xasm arguments.
419 * Supposed to find target-specific constraints and rewrite them.
420 */
421 int
422 myxasm(struct interpass *ip, NODE *p)
423 {
424 return 0;
425 }