]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/sparc/sparc.c
2015-06-17 Andrew MacLeod <amacleod@redhat.com>
[thirdparty/gcc.git] / gcc / config / sparc / sparc.c
1 /* Subroutines for insn-output.c for SPARC.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
4 64-bit SPARC-V9 support by Michael Tiemann, Jim Wilson, and Doug Evans,
5 at Cygnus Support.
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "alias.h"
28 #include "symtab.h"
29 #include "tree.h"
30 #include "fold-const.h"
31 #include "stringpool.h"
32 #include "stor-layout.h"
33 #include "calls.h"
34 #include "varasm.h"
35 #include "rtl.h"
36 #include "regs.h"
37 #include "hard-reg-set.h"
38 #include "insn-config.h"
39 #include "insn-codes.h"
40 #include "conditions.h"
41 #include "output.h"
42 #include "insn-attr.h"
43 #include "flags.h"
44 #include "function.h"
45 #include "except.h"
46 #include "expmed.h"
47 #include "dojump.h"
48 #include "explow.h"
49 #include "emit-rtl.h"
50 #include "stmt.h"
51 #include "expr.h"
52 #include "optabs.h"
53 #include "recog.h"
54 #include "diagnostic-core.h"
55 #include "tm_p.h"
56 #include "debug.h"
57 #include "target.h"
58 #include "target-def.h"
59 #include "common/common-target.h"
60 #include "predict.h"
61 #include "dominance.h"
62 #include "cfg.h"
63 #include "cfgrtl.h"
64 #include "cfganal.h"
65 #include "lcm.h"
66 #include "cfgbuild.h"
67 #include "cfgcleanup.h"
68 #include "basic-block.h"
69 #include "tree-ssa-alias.h"
70 #include "internal-fn.h"
71 #include "gimple-fold.h"
72 #include "tree-eh.h"
73 #include "gimple-expr.h"
74 #include "gimple.h"
75 #include "gimplify.h"
76 #include "langhooks.h"
77 #include "reload.h"
78 #include "params.h"
79 #include "df.h"
80 #include "opts.h"
81 #include "tree-pass.h"
82 #include "context.h"
83 #include "builtins.h"
84 #include "rtl-iter.h"
85
86 /* Processor costs */
87
88 struct processor_costs {
89 /* Integer load */
90 const int int_load;
91
92 /* Integer signed load */
93 const int int_sload;
94
95 /* Integer zeroed load */
96 const int int_zload;
97
98 /* Float load */
99 const int float_load;
100
101 /* fmov, fneg, fabs */
102 const int float_move;
103
104 /* fadd, fsub */
105 const int float_plusminus;
106
107 /* fcmp */
108 const int float_cmp;
109
110 /* fmov, fmovr */
111 const int float_cmove;
112
113 /* fmul */
114 const int float_mul;
115
116 /* fdivs */
117 const int float_div_sf;
118
119 /* fdivd */
120 const int float_div_df;
121
122 /* fsqrts */
123 const int float_sqrt_sf;
124
125 /* fsqrtd */
126 const int float_sqrt_df;
127
128 /* umul/smul */
129 const int int_mul;
130
131 /* mulX */
132 const int int_mulX;
133
134 /* integer multiply cost for each bit set past the most
135 significant 3, so the formula for multiply cost becomes:
136
137 if (rs1 < 0)
138 highest_bit = highest_clear_bit(rs1);
139 else
140 highest_bit = highest_set_bit(rs1);
141 if (highest_bit < 3)
142 highest_bit = 3;
143 cost = int_mul{,X} + ((highest_bit - 3) / int_mul_bit_factor);
144
145 A value of zero indicates that the multiply costs is fixed,
146 and not variable. */
147 const int int_mul_bit_factor;
148
149 /* udiv/sdiv */
150 const int int_div;
151
152 /* divX */
153 const int int_divX;
154
155 /* movcc, movr */
156 const int int_cmove;
157
158 /* penalty for shifts, due to scheduling rules etc. */
159 const int shift_penalty;
160 };
161
162 static const
163 struct processor_costs cypress_costs = {
164 COSTS_N_INSNS (2), /* int load */
165 COSTS_N_INSNS (2), /* int signed load */
166 COSTS_N_INSNS (2), /* int zeroed load */
167 COSTS_N_INSNS (2), /* float load */
168 COSTS_N_INSNS (5), /* fmov, fneg, fabs */
169 COSTS_N_INSNS (5), /* fadd, fsub */
170 COSTS_N_INSNS (1), /* fcmp */
171 COSTS_N_INSNS (1), /* fmov, fmovr */
172 COSTS_N_INSNS (7), /* fmul */
173 COSTS_N_INSNS (37), /* fdivs */
174 COSTS_N_INSNS (37), /* fdivd */
175 COSTS_N_INSNS (63), /* fsqrts */
176 COSTS_N_INSNS (63), /* fsqrtd */
177 COSTS_N_INSNS (1), /* imul */
178 COSTS_N_INSNS (1), /* imulX */
179 0, /* imul bit factor */
180 COSTS_N_INSNS (1), /* idiv */
181 COSTS_N_INSNS (1), /* idivX */
182 COSTS_N_INSNS (1), /* movcc/movr */
183 0, /* shift penalty */
184 };
185
186 static const
187 struct processor_costs supersparc_costs = {
188 COSTS_N_INSNS (1), /* int load */
189 COSTS_N_INSNS (1), /* int signed load */
190 COSTS_N_INSNS (1), /* int zeroed load */
191 COSTS_N_INSNS (0), /* float load */
192 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
193 COSTS_N_INSNS (3), /* fadd, fsub */
194 COSTS_N_INSNS (3), /* fcmp */
195 COSTS_N_INSNS (1), /* fmov, fmovr */
196 COSTS_N_INSNS (3), /* fmul */
197 COSTS_N_INSNS (6), /* fdivs */
198 COSTS_N_INSNS (9), /* fdivd */
199 COSTS_N_INSNS (12), /* fsqrts */
200 COSTS_N_INSNS (12), /* fsqrtd */
201 COSTS_N_INSNS (4), /* imul */
202 COSTS_N_INSNS (4), /* imulX */
203 0, /* imul bit factor */
204 COSTS_N_INSNS (4), /* idiv */
205 COSTS_N_INSNS (4), /* idivX */
206 COSTS_N_INSNS (1), /* movcc/movr */
207 1, /* shift penalty */
208 };
209
210 static const
211 struct processor_costs hypersparc_costs = {
212 COSTS_N_INSNS (1), /* int load */
213 COSTS_N_INSNS (1), /* int signed load */
214 COSTS_N_INSNS (1), /* int zeroed load */
215 COSTS_N_INSNS (1), /* float load */
216 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
217 COSTS_N_INSNS (1), /* fadd, fsub */
218 COSTS_N_INSNS (1), /* fcmp */
219 COSTS_N_INSNS (1), /* fmov, fmovr */
220 COSTS_N_INSNS (1), /* fmul */
221 COSTS_N_INSNS (8), /* fdivs */
222 COSTS_N_INSNS (12), /* fdivd */
223 COSTS_N_INSNS (17), /* fsqrts */
224 COSTS_N_INSNS (17), /* fsqrtd */
225 COSTS_N_INSNS (17), /* imul */
226 COSTS_N_INSNS (17), /* imulX */
227 0, /* imul bit factor */
228 COSTS_N_INSNS (17), /* idiv */
229 COSTS_N_INSNS (17), /* idivX */
230 COSTS_N_INSNS (1), /* movcc/movr */
231 0, /* shift penalty */
232 };
233
234 static const
235 struct processor_costs leon_costs = {
236 COSTS_N_INSNS (1), /* int load */
237 COSTS_N_INSNS (1), /* int signed load */
238 COSTS_N_INSNS (1), /* int zeroed load */
239 COSTS_N_INSNS (1), /* float load */
240 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
241 COSTS_N_INSNS (1), /* fadd, fsub */
242 COSTS_N_INSNS (1), /* fcmp */
243 COSTS_N_INSNS (1), /* fmov, fmovr */
244 COSTS_N_INSNS (1), /* fmul */
245 COSTS_N_INSNS (15), /* fdivs */
246 COSTS_N_INSNS (15), /* fdivd */
247 COSTS_N_INSNS (23), /* fsqrts */
248 COSTS_N_INSNS (23), /* fsqrtd */
249 COSTS_N_INSNS (5), /* imul */
250 COSTS_N_INSNS (5), /* imulX */
251 0, /* imul bit factor */
252 COSTS_N_INSNS (5), /* idiv */
253 COSTS_N_INSNS (5), /* idivX */
254 COSTS_N_INSNS (1), /* movcc/movr */
255 0, /* shift penalty */
256 };
257
258 static const
259 struct processor_costs leon3_costs = {
260 COSTS_N_INSNS (1), /* int load */
261 COSTS_N_INSNS (1), /* int signed load */
262 COSTS_N_INSNS (1), /* int zeroed load */
263 COSTS_N_INSNS (1), /* float load */
264 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
265 COSTS_N_INSNS (1), /* fadd, fsub */
266 COSTS_N_INSNS (1), /* fcmp */
267 COSTS_N_INSNS (1), /* fmov, fmovr */
268 COSTS_N_INSNS (1), /* fmul */
269 COSTS_N_INSNS (14), /* fdivs */
270 COSTS_N_INSNS (15), /* fdivd */
271 COSTS_N_INSNS (22), /* fsqrts */
272 COSTS_N_INSNS (23), /* fsqrtd */
273 COSTS_N_INSNS (5), /* imul */
274 COSTS_N_INSNS (5), /* imulX */
275 0, /* imul bit factor */
276 COSTS_N_INSNS (35), /* idiv */
277 COSTS_N_INSNS (35), /* idivX */
278 COSTS_N_INSNS (1), /* movcc/movr */
279 0, /* shift penalty */
280 };
281
282 static const
283 struct processor_costs sparclet_costs = {
284 COSTS_N_INSNS (3), /* int load */
285 COSTS_N_INSNS (3), /* int signed load */
286 COSTS_N_INSNS (1), /* int zeroed load */
287 COSTS_N_INSNS (1), /* float load */
288 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
289 COSTS_N_INSNS (1), /* fadd, fsub */
290 COSTS_N_INSNS (1), /* fcmp */
291 COSTS_N_INSNS (1), /* fmov, fmovr */
292 COSTS_N_INSNS (1), /* fmul */
293 COSTS_N_INSNS (1), /* fdivs */
294 COSTS_N_INSNS (1), /* fdivd */
295 COSTS_N_INSNS (1), /* fsqrts */
296 COSTS_N_INSNS (1), /* fsqrtd */
297 COSTS_N_INSNS (5), /* imul */
298 COSTS_N_INSNS (5), /* imulX */
299 0, /* imul bit factor */
300 COSTS_N_INSNS (5), /* idiv */
301 COSTS_N_INSNS (5), /* idivX */
302 COSTS_N_INSNS (1), /* movcc/movr */
303 0, /* shift penalty */
304 };
305
306 static const
307 struct processor_costs ultrasparc_costs = {
308 COSTS_N_INSNS (2), /* int load */
309 COSTS_N_INSNS (3), /* int signed load */
310 COSTS_N_INSNS (2), /* int zeroed load */
311 COSTS_N_INSNS (2), /* float load */
312 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
313 COSTS_N_INSNS (4), /* fadd, fsub */
314 COSTS_N_INSNS (1), /* fcmp */
315 COSTS_N_INSNS (2), /* fmov, fmovr */
316 COSTS_N_INSNS (4), /* fmul */
317 COSTS_N_INSNS (13), /* fdivs */
318 COSTS_N_INSNS (23), /* fdivd */
319 COSTS_N_INSNS (13), /* fsqrts */
320 COSTS_N_INSNS (23), /* fsqrtd */
321 COSTS_N_INSNS (4), /* imul */
322 COSTS_N_INSNS (4), /* imulX */
323 2, /* imul bit factor */
324 COSTS_N_INSNS (37), /* idiv */
325 COSTS_N_INSNS (68), /* idivX */
326 COSTS_N_INSNS (2), /* movcc/movr */
327 2, /* shift penalty */
328 };
329
330 static const
331 struct processor_costs ultrasparc3_costs = {
332 COSTS_N_INSNS (2), /* int load */
333 COSTS_N_INSNS (3), /* int signed load */
334 COSTS_N_INSNS (3), /* int zeroed load */
335 COSTS_N_INSNS (2), /* float load */
336 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
337 COSTS_N_INSNS (4), /* fadd, fsub */
338 COSTS_N_INSNS (5), /* fcmp */
339 COSTS_N_INSNS (3), /* fmov, fmovr */
340 COSTS_N_INSNS (4), /* fmul */
341 COSTS_N_INSNS (17), /* fdivs */
342 COSTS_N_INSNS (20), /* fdivd */
343 COSTS_N_INSNS (20), /* fsqrts */
344 COSTS_N_INSNS (29), /* fsqrtd */
345 COSTS_N_INSNS (6), /* imul */
346 COSTS_N_INSNS (6), /* imulX */
347 0, /* imul bit factor */
348 COSTS_N_INSNS (40), /* idiv */
349 COSTS_N_INSNS (71), /* idivX */
350 COSTS_N_INSNS (2), /* movcc/movr */
351 0, /* shift penalty */
352 };
353
354 static const
355 struct processor_costs niagara_costs = {
356 COSTS_N_INSNS (3), /* int load */
357 COSTS_N_INSNS (3), /* int signed load */
358 COSTS_N_INSNS (3), /* int zeroed load */
359 COSTS_N_INSNS (9), /* float load */
360 COSTS_N_INSNS (8), /* fmov, fneg, fabs */
361 COSTS_N_INSNS (8), /* fadd, fsub */
362 COSTS_N_INSNS (26), /* fcmp */
363 COSTS_N_INSNS (8), /* fmov, fmovr */
364 COSTS_N_INSNS (29), /* fmul */
365 COSTS_N_INSNS (54), /* fdivs */
366 COSTS_N_INSNS (83), /* fdivd */
367 COSTS_N_INSNS (100), /* fsqrts - not implemented in hardware */
368 COSTS_N_INSNS (100), /* fsqrtd - not implemented in hardware */
369 COSTS_N_INSNS (11), /* imul */
370 COSTS_N_INSNS (11), /* imulX */
371 0, /* imul bit factor */
372 COSTS_N_INSNS (72), /* idiv */
373 COSTS_N_INSNS (72), /* idivX */
374 COSTS_N_INSNS (1), /* movcc/movr */
375 0, /* shift penalty */
376 };
377
378 static const
379 struct processor_costs niagara2_costs = {
380 COSTS_N_INSNS (3), /* int load */
381 COSTS_N_INSNS (3), /* int signed load */
382 COSTS_N_INSNS (3), /* int zeroed load */
383 COSTS_N_INSNS (3), /* float load */
384 COSTS_N_INSNS (6), /* fmov, fneg, fabs */
385 COSTS_N_INSNS (6), /* fadd, fsub */
386 COSTS_N_INSNS (6), /* fcmp */
387 COSTS_N_INSNS (6), /* fmov, fmovr */
388 COSTS_N_INSNS (6), /* fmul */
389 COSTS_N_INSNS (19), /* fdivs */
390 COSTS_N_INSNS (33), /* fdivd */
391 COSTS_N_INSNS (19), /* fsqrts */
392 COSTS_N_INSNS (33), /* fsqrtd */
393 COSTS_N_INSNS (5), /* imul */
394 COSTS_N_INSNS (5), /* imulX */
395 0, /* imul bit factor */
396 COSTS_N_INSNS (26), /* idiv, average of 12 - 41 cycle range */
397 COSTS_N_INSNS (26), /* idivX, average of 12 - 41 cycle range */
398 COSTS_N_INSNS (1), /* movcc/movr */
399 0, /* shift penalty */
400 };
401
402 static const
403 struct processor_costs niagara3_costs = {
404 COSTS_N_INSNS (3), /* int load */
405 COSTS_N_INSNS (3), /* int signed load */
406 COSTS_N_INSNS (3), /* int zeroed load */
407 COSTS_N_INSNS (3), /* float load */
408 COSTS_N_INSNS (9), /* fmov, fneg, fabs */
409 COSTS_N_INSNS (9), /* fadd, fsub */
410 COSTS_N_INSNS (9), /* fcmp */
411 COSTS_N_INSNS (9), /* fmov, fmovr */
412 COSTS_N_INSNS (9), /* fmul */
413 COSTS_N_INSNS (23), /* fdivs */
414 COSTS_N_INSNS (37), /* fdivd */
415 COSTS_N_INSNS (23), /* fsqrts */
416 COSTS_N_INSNS (37), /* fsqrtd */
417 COSTS_N_INSNS (9), /* imul */
418 COSTS_N_INSNS (9), /* imulX */
419 0, /* imul bit factor */
420 COSTS_N_INSNS (31), /* idiv, average of 17 - 45 cycle range */
421 COSTS_N_INSNS (30), /* idivX, average of 16 - 44 cycle range */
422 COSTS_N_INSNS (1), /* movcc/movr */
423 0, /* shift penalty */
424 };
425
426 static const
427 struct processor_costs niagara4_costs = {
428 COSTS_N_INSNS (5), /* int load */
429 COSTS_N_INSNS (5), /* int signed load */
430 COSTS_N_INSNS (5), /* int zeroed load */
431 COSTS_N_INSNS (5), /* float load */
432 COSTS_N_INSNS (11), /* fmov, fneg, fabs */
433 COSTS_N_INSNS (11), /* fadd, fsub */
434 COSTS_N_INSNS (11), /* fcmp */
435 COSTS_N_INSNS (11), /* fmov, fmovr */
436 COSTS_N_INSNS (11), /* fmul */
437 COSTS_N_INSNS (24), /* fdivs */
438 COSTS_N_INSNS (37), /* fdivd */
439 COSTS_N_INSNS (24), /* fsqrts */
440 COSTS_N_INSNS (37), /* fsqrtd */
441 COSTS_N_INSNS (12), /* imul */
442 COSTS_N_INSNS (12), /* imulX */
443 0, /* imul bit factor */
444 COSTS_N_INSNS (50), /* idiv, average of 41 - 60 cycle range */
445 COSTS_N_INSNS (35), /* idivX, average of 26 - 44 cycle range */
446 COSTS_N_INSNS (1), /* movcc/movr */
447 0, /* shift penalty */
448 };
449
450 static const struct processor_costs *sparc_costs = &cypress_costs;
451
452 #ifdef HAVE_AS_RELAX_OPTION
453 /* If 'as' and 'ld' are relaxing tail call insns into branch always, use
454 "or %o7,%g0,X; call Y; or X,%g0,%o7" always, so that it can be optimized.
455 With sethi/jmp, neither 'as' nor 'ld' has an easy way how to find out if
456 somebody does not branch between the sethi and jmp. */
457 #define LEAF_SIBCALL_SLOT_RESERVED_P 1
458 #else
459 #define LEAF_SIBCALL_SLOT_RESERVED_P \
460 ((TARGET_ARCH64 && !TARGET_CM_MEDLOW) || flag_pic)
461 #endif
462
463 /* Vector to say how input registers are mapped to output registers.
464 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
465 eliminate it. You must use -fomit-frame-pointer to get that. */
466 char leaf_reg_remap[] =
467 { 0, 1, 2, 3, 4, 5, 6, 7,
468 -1, -1, -1, -1, -1, -1, 14, -1,
469 -1, -1, -1, -1, -1, -1, -1, -1,
470 8, 9, 10, 11, 12, 13, -1, 15,
471
472 32, 33, 34, 35, 36, 37, 38, 39,
473 40, 41, 42, 43, 44, 45, 46, 47,
474 48, 49, 50, 51, 52, 53, 54, 55,
475 56, 57, 58, 59, 60, 61, 62, 63,
476 64, 65, 66, 67, 68, 69, 70, 71,
477 72, 73, 74, 75, 76, 77, 78, 79,
478 80, 81, 82, 83, 84, 85, 86, 87,
479 88, 89, 90, 91, 92, 93, 94, 95,
480 96, 97, 98, 99, 100, 101, 102};
481
482 /* Vector, indexed by hard register number, which contains 1
483 for a register that is allowable in a candidate for leaf
484 function treatment. */
485 char sparc_leaf_regs[] =
486 { 1, 1, 1, 1, 1, 1, 1, 1,
487 0, 0, 0, 0, 0, 0, 1, 0,
488 0, 0, 0, 0, 0, 0, 0, 0,
489 1, 1, 1, 1, 1, 1, 0, 1,
490 1, 1, 1, 1, 1, 1, 1, 1,
491 1, 1, 1, 1, 1, 1, 1, 1,
492 1, 1, 1, 1, 1, 1, 1, 1,
493 1, 1, 1, 1, 1, 1, 1, 1,
494 1, 1, 1, 1, 1, 1, 1, 1,
495 1, 1, 1, 1, 1, 1, 1, 1,
496 1, 1, 1, 1, 1, 1, 1, 1,
497 1, 1, 1, 1, 1, 1, 1, 1,
498 1, 1, 1, 1, 1, 1, 1};
499
500 struct GTY(()) machine_function
501 {
502 /* Size of the frame of the function. */
503 HOST_WIDE_INT frame_size;
504
505 /* Size of the frame of the function minus the register window save area
506 and the outgoing argument area. */
507 HOST_WIDE_INT apparent_frame_size;
508
509 /* Register we pretend the frame pointer is allocated to. Normally, this
510 is %fp, but if we are in a leaf procedure, this is (%sp + offset). We
511 record "offset" separately as it may be too big for (reg + disp). */
512 rtx frame_base_reg;
513 HOST_WIDE_INT frame_base_offset;
514
515 /* Number of global or FP registers to be saved (as 4-byte quantities). */
516 int n_global_fp_regs;
517
518 /* True if the current function is leaf and uses only leaf regs,
519 so that the SPARC leaf function optimization can be applied.
520 Private version of crtl->uses_only_leaf_regs, see
521 sparc_expand_prologue for the rationale. */
522 int leaf_function_p;
523
524 /* True if the prologue saves local or in registers. */
525 bool save_local_in_regs_p;
526
527 /* True if the data calculated by sparc_expand_prologue are valid. */
528 bool prologue_data_valid_p;
529 };
530
531 #define sparc_frame_size cfun->machine->frame_size
532 #define sparc_apparent_frame_size cfun->machine->apparent_frame_size
533 #define sparc_frame_base_reg cfun->machine->frame_base_reg
534 #define sparc_frame_base_offset cfun->machine->frame_base_offset
535 #define sparc_n_global_fp_regs cfun->machine->n_global_fp_regs
536 #define sparc_leaf_function_p cfun->machine->leaf_function_p
537 #define sparc_save_local_in_regs_p cfun->machine->save_local_in_regs_p
538 #define sparc_prologue_data_valid_p cfun->machine->prologue_data_valid_p
539
540 /* 1 if the next opcode is to be specially indented. */
541 int sparc_indent_opcode = 0;
542
543 static void sparc_option_override (void);
544 static void sparc_init_modes (void);
545 static void scan_record_type (const_tree, int *, int *, int *);
546 static int function_arg_slotno (const CUMULATIVE_ARGS *, machine_mode,
547 const_tree, bool, bool, int *, int *);
548
549 static int supersparc_adjust_cost (rtx_insn *, rtx, rtx_insn *, int);
550 static int hypersparc_adjust_cost (rtx_insn *, rtx, rtx_insn *, int);
551
552 static void sparc_emit_set_const32 (rtx, rtx);
553 static void sparc_emit_set_const64 (rtx, rtx);
554 static void sparc_output_addr_vec (rtx);
555 static void sparc_output_addr_diff_vec (rtx);
556 static void sparc_output_deferred_case_vectors (void);
557 static bool sparc_legitimate_address_p (machine_mode, rtx, bool);
558 static bool sparc_legitimate_constant_p (machine_mode, rtx);
559 static rtx sparc_builtin_saveregs (void);
560 static int epilogue_renumber (rtx *, int);
561 static bool sparc_assemble_integer (rtx, unsigned int, int);
562 static int set_extends (rtx_insn *);
563 static void sparc_asm_function_prologue (FILE *, HOST_WIDE_INT);
564 static void sparc_asm_function_epilogue (FILE *, HOST_WIDE_INT);
565 #ifdef TARGET_SOLARIS
566 static void sparc_solaris_elf_asm_named_section (const char *, unsigned int,
567 tree) ATTRIBUTE_UNUSED;
568 #endif
569 static int sparc_adjust_cost (rtx_insn *, rtx, rtx_insn *, int);
570 static int sparc_issue_rate (void);
571 static void sparc_sched_init (FILE *, int, int);
572 static int sparc_use_sched_lookahead (void);
573
574 static void emit_soft_tfmode_libcall (const char *, int, rtx *);
575 static void emit_soft_tfmode_binop (enum rtx_code, rtx *);
576 static void emit_soft_tfmode_unop (enum rtx_code, rtx *);
577 static void emit_soft_tfmode_cvt (enum rtx_code, rtx *);
578 static void emit_hard_tfmode_operation (enum rtx_code, rtx *);
579
580 static bool sparc_function_ok_for_sibcall (tree, tree);
581 static void sparc_init_libfuncs (void);
582 static void sparc_init_builtins (void);
583 static void sparc_fpu_init_builtins (void);
584 static void sparc_vis_init_builtins (void);
585 static tree sparc_builtin_decl (unsigned, bool);
586 static rtx sparc_expand_builtin (tree, rtx, rtx, machine_mode, int);
587 static tree sparc_fold_builtin (tree, int, tree *, bool);
588 static void sparc_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
589 HOST_WIDE_INT, tree);
590 static bool sparc_can_output_mi_thunk (const_tree, HOST_WIDE_INT,
591 HOST_WIDE_INT, const_tree);
592 static struct machine_function * sparc_init_machine_status (void);
593 static bool sparc_cannot_force_const_mem (machine_mode, rtx);
594 static rtx sparc_tls_get_addr (void);
595 static rtx sparc_tls_got (void);
596 static int sparc_register_move_cost (machine_mode,
597 reg_class_t, reg_class_t);
598 static bool sparc_rtx_costs (rtx, int, int, int, int *, bool);
599 static rtx sparc_function_value (const_tree, const_tree, bool);
600 static rtx sparc_libcall_value (machine_mode, const_rtx);
601 static bool sparc_function_value_regno_p (const unsigned int);
602 static rtx sparc_struct_value_rtx (tree, int);
603 static machine_mode sparc_promote_function_mode (const_tree, machine_mode,
604 int *, const_tree, int);
605 static bool sparc_return_in_memory (const_tree, const_tree);
606 static bool sparc_strict_argument_naming (cumulative_args_t);
607 static void sparc_va_start (tree, rtx);
608 static tree sparc_gimplify_va_arg (tree, tree, gimple_seq *, gimple_seq *);
609 static bool sparc_vector_mode_supported_p (machine_mode);
610 static bool sparc_tls_referenced_p (rtx);
611 static rtx sparc_legitimize_tls_address (rtx);
612 static rtx sparc_legitimize_pic_address (rtx, rtx);
613 static rtx sparc_legitimize_address (rtx, rtx, machine_mode);
614 static rtx sparc_delegitimize_address (rtx);
615 static bool sparc_mode_dependent_address_p (const_rtx, addr_space_t);
616 static bool sparc_pass_by_reference (cumulative_args_t,
617 machine_mode, const_tree, bool);
618 static void sparc_function_arg_advance (cumulative_args_t,
619 machine_mode, const_tree, bool);
620 static rtx sparc_function_arg_1 (cumulative_args_t,
621 machine_mode, const_tree, bool, bool);
622 static rtx sparc_function_arg (cumulative_args_t,
623 machine_mode, const_tree, bool);
624 static rtx sparc_function_incoming_arg (cumulative_args_t,
625 machine_mode, const_tree, bool);
626 static unsigned int sparc_function_arg_boundary (machine_mode,
627 const_tree);
628 static int sparc_arg_partial_bytes (cumulative_args_t,
629 machine_mode, tree, bool);
630 static void sparc_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
631 static void sparc_file_end (void);
632 static bool sparc_frame_pointer_required (void);
633 static bool sparc_can_eliminate (const int, const int);
634 static rtx sparc_builtin_setjmp_frame_value (void);
635 static void sparc_conditional_register_usage (void);
636 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
637 static const char *sparc_mangle_type (const_tree);
638 #endif
639 static void sparc_trampoline_init (rtx, tree, rtx);
640 static machine_mode sparc_preferred_simd_mode (machine_mode);
641 static reg_class_t sparc_preferred_reload_class (rtx x, reg_class_t rclass);
642 static bool sparc_print_operand_punct_valid_p (unsigned char);
643 static void sparc_print_operand (FILE *, rtx, int);
644 static void sparc_print_operand_address (FILE *, rtx);
645 static reg_class_t sparc_secondary_reload (bool, rtx, reg_class_t,
646 machine_mode,
647 secondary_reload_info *);
648 static machine_mode sparc_cstore_mode (enum insn_code icode);
649 static void sparc_atomic_assign_expand_fenv (tree *, tree *, tree *);
650 \f
651 #ifdef SUBTARGET_ATTRIBUTE_TABLE
652 /* Table of valid machine attributes. */
653 static const struct attribute_spec sparc_attribute_table[] =
654 {
655 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
656 do_diagnostic } */
657 SUBTARGET_ATTRIBUTE_TABLE,
658 { NULL, 0, 0, false, false, false, NULL, false }
659 };
660 #endif
661 \f
662 /* Option handling. */
663
664 /* Parsed value. */
665 enum cmodel sparc_cmodel;
666
667 char sparc_hard_reg_printed[8];
668
669 /* Initialize the GCC target structure. */
670
671 /* The default is to use .half rather than .short for aligned HI objects. */
672 #undef TARGET_ASM_ALIGNED_HI_OP
673 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
674
675 #undef TARGET_ASM_UNALIGNED_HI_OP
676 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
677 #undef TARGET_ASM_UNALIGNED_SI_OP
678 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
679 #undef TARGET_ASM_UNALIGNED_DI_OP
680 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
681
682 /* The target hook has to handle DI-mode values. */
683 #undef TARGET_ASM_INTEGER
684 #define TARGET_ASM_INTEGER sparc_assemble_integer
685
686 #undef TARGET_ASM_FUNCTION_PROLOGUE
687 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
688 #undef TARGET_ASM_FUNCTION_EPILOGUE
689 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
690
691 #undef TARGET_SCHED_ADJUST_COST
692 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
693 #undef TARGET_SCHED_ISSUE_RATE
694 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
695 #undef TARGET_SCHED_INIT
696 #define TARGET_SCHED_INIT sparc_sched_init
697 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
698 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
699
700 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
701 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
702
703 #undef TARGET_INIT_LIBFUNCS
704 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
705
706 #undef TARGET_LEGITIMIZE_ADDRESS
707 #define TARGET_LEGITIMIZE_ADDRESS sparc_legitimize_address
708 #undef TARGET_DELEGITIMIZE_ADDRESS
709 #define TARGET_DELEGITIMIZE_ADDRESS sparc_delegitimize_address
710 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
711 #define TARGET_MODE_DEPENDENT_ADDRESS_P sparc_mode_dependent_address_p
712
713 #undef TARGET_INIT_BUILTINS
714 #define TARGET_INIT_BUILTINS sparc_init_builtins
715 #undef TARGET_BUILTIN_DECL
716 #define TARGET_BUILTIN_DECL sparc_builtin_decl
717 #undef TARGET_EXPAND_BUILTIN
718 #define TARGET_EXPAND_BUILTIN sparc_expand_builtin
719 #undef TARGET_FOLD_BUILTIN
720 #define TARGET_FOLD_BUILTIN sparc_fold_builtin
721
722 #if TARGET_TLS
723 #undef TARGET_HAVE_TLS
724 #define TARGET_HAVE_TLS true
725 #endif
726
727 #undef TARGET_CANNOT_FORCE_CONST_MEM
728 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
729
730 #undef TARGET_ASM_OUTPUT_MI_THUNK
731 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
732 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
733 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
734
735 #undef TARGET_RTX_COSTS
736 #define TARGET_RTX_COSTS sparc_rtx_costs
737 #undef TARGET_ADDRESS_COST
738 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
739 #undef TARGET_REGISTER_MOVE_COST
740 #define TARGET_REGISTER_MOVE_COST sparc_register_move_cost
741
742 #undef TARGET_PROMOTE_FUNCTION_MODE
743 #define TARGET_PROMOTE_FUNCTION_MODE sparc_promote_function_mode
744
745 #undef TARGET_FUNCTION_VALUE
746 #define TARGET_FUNCTION_VALUE sparc_function_value
747 #undef TARGET_LIBCALL_VALUE
748 #define TARGET_LIBCALL_VALUE sparc_libcall_value
749 #undef TARGET_FUNCTION_VALUE_REGNO_P
750 #define TARGET_FUNCTION_VALUE_REGNO_P sparc_function_value_regno_p
751
752 #undef TARGET_STRUCT_VALUE_RTX
753 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
754 #undef TARGET_RETURN_IN_MEMORY
755 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
756 #undef TARGET_MUST_PASS_IN_STACK
757 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
758 #undef TARGET_PASS_BY_REFERENCE
759 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
760 #undef TARGET_ARG_PARTIAL_BYTES
761 #define TARGET_ARG_PARTIAL_BYTES sparc_arg_partial_bytes
762 #undef TARGET_FUNCTION_ARG_ADVANCE
763 #define TARGET_FUNCTION_ARG_ADVANCE sparc_function_arg_advance
764 #undef TARGET_FUNCTION_ARG
765 #define TARGET_FUNCTION_ARG sparc_function_arg
766 #undef TARGET_FUNCTION_INCOMING_ARG
767 #define TARGET_FUNCTION_INCOMING_ARG sparc_function_incoming_arg
768 #undef TARGET_FUNCTION_ARG_BOUNDARY
769 #define TARGET_FUNCTION_ARG_BOUNDARY sparc_function_arg_boundary
770
771 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
772 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
773 #undef TARGET_STRICT_ARGUMENT_NAMING
774 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
775
776 #undef TARGET_EXPAND_BUILTIN_VA_START
777 #define TARGET_EXPAND_BUILTIN_VA_START sparc_va_start
778 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
779 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
780
781 #undef TARGET_VECTOR_MODE_SUPPORTED_P
782 #define TARGET_VECTOR_MODE_SUPPORTED_P sparc_vector_mode_supported_p
783
784 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
785 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE sparc_preferred_simd_mode
786
787 #ifdef SUBTARGET_INSERT_ATTRIBUTES
788 #undef TARGET_INSERT_ATTRIBUTES
789 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
790 #endif
791
792 #ifdef SUBTARGET_ATTRIBUTE_TABLE
793 #undef TARGET_ATTRIBUTE_TABLE
794 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
795 #endif
796
797 #undef TARGET_OPTION_OVERRIDE
798 #define TARGET_OPTION_OVERRIDE sparc_option_override
799
800 #if TARGET_GNU_TLS && defined(HAVE_AS_SPARC_UA_PCREL)
801 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
802 #define TARGET_ASM_OUTPUT_DWARF_DTPREL sparc_output_dwarf_dtprel
803 #endif
804
805 #undef TARGET_ASM_FILE_END
806 #define TARGET_ASM_FILE_END sparc_file_end
807
808 #undef TARGET_FRAME_POINTER_REQUIRED
809 #define TARGET_FRAME_POINTER_REQUIRED sparc_frame_pointer_required
810
811 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
812 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE sparc_builtin_setjmp_frame_value
813
814 #undef TARGET_CAN_ELIMINATE
815 #define TARGET_CAN_ELIMINATE sparc_can_eliminate
816
817 #undef TARGET_PREFERRED_RELOAD_CLASS
818 #define TARGET_PREFERRED_RELOAD_CLASS sparc_preferred_reload_class
819
820 #undef TARGET_SECONDARY_RELOAD
821 #define TARGET_SECONDARY_RELOAD sparc_secondary_reload
822
823 #undef TARGET_CONDITIONAL_REGISTER_USAGE
824 #define TARGET_CONDITIONAL_REGISTER_USAGE sparc_conditional_register_usage
825
826 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
827 #undef TARGET_MANGLE_TYPE
828 #define TARGET_MANGLE_TYPE sparc_mangle_type
829 #endif
830
831 #undef TARGET_LEGITIMATE_ADDRESS_P
832 #define TARGET_LEGITIMATE_ADDRESS_P sparc_legitimate_address_p
833
834 #undef TARGET_LEGITIMATE_CONSTANT_P
835 #define TARGET_LEGITIMATE_CONSTANT_P sparc_legitimate_constant_p
836
837 #undef TARGET_TRAMPOLINE_INIT
838 #define TARGET_TRAMPOLINE_INIT sparc_trampoline_init
839
840 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
841 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P sparc_print_operand_punct_valid_p
842 #undef TARGET_PRINT_OPERAND
843 #define TARGET_PRINT_OPERAND sparc_print_operand
844 #undef TARGET_PRINT_OPERAND_ADDRESS
845 #define TARGET_PRINT_OPERAND_ADDRESS sparc_print_operand_address
846
847 /* The value stored by LDSTUB. */
848 #undef TARGET_ATOMIC_TEST_AND_SET_TRUEVAL
849 #define TARGET_ATOMIC_TEST_AND_SET_TRUEVAL 0xff
850
851 #undef TARGET_CSTORE_MODE
852 #define TARGET_CSTORE_MODE sparc_cstore_mode
853
854 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
855 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV sparc_atomic_assign_expand_fenv
856
857 struct gcc_target targetm = TARGET_INITIALIZER;
858
859 /* Return the memory reference contained in X if any, zero otherwise. */
860
861 static rtx
862 mem_ref (rtx x)
863 {
864 if (GET_CODE (x) == SIGN_EXTEND || GET_CODE (x) == ZERO_EXTEND)
865 x = XEXP (x, 0);
866
867 if (MEM_P (x))
868 return x;
869
870 return NULL_RTX;
871 }
872
873 /* We use a machine specific pass to enable workarounds for errata.
874 We need to have the (essentially) final form of the insn stream in order
875 to properly detect the various hazards. Therefore, this machine specific
876 pass runs as late as possible. The pass is inserted in the pass pipeline
877 at the end of sparc_option_override. */
878
879 static unsigned int
880 sparc_do_work_around_errata (void)
881 {
882 rtx_insn *insn, *next;
883
884 /* Force all instructions to be split into their final form. */
885 split_all_insns_noflow ();
886
887 /* Now look for specific patterns in the insn stream. */
888 for (insn = get_insns (); insn; insn = next)
889 {
890 bool insert_nop = false;
891 rtx set;
892
893 /* Look into the instruction in a delay slot. */
894 if (NONJUMP_INSN_P (insn))
895 if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
896 insn = seq->insn (1);
897
898 /* Look for a single-word load into an odd-numbered FP register. */
899 if (sparc_fix_at697f
900 && NONJUMP_INSN_P (insn)
901 && (set = single_set (insn)) != NULL_RTX
902 && GET_MODE_SIZE (GET_MODE (SET_SRC (set))) == 4
903 && MEM_P (SET_SRC (set))
904 && REG_P (SET_DEST (set))
905 && REGNO (SET_DEST (set)) > 31
906 && REGNO (SET_DEST (set)) % 2 != 0)
907 {
908 /* The wrong dependency is on the enclosing double register. */
909 const unsigned int x = REGNO (SET_DEST (set)) - 1;
910 unsigned int src1, src2, dest;
911 int code;
912
913 next = next_active_insn (insn);
914 if (!next)
915 break;
916 /* If the insn is a branch, then it cannot be problematic. */
917 if (!NONJUMP_INSN_P (next) || GET_CODE (PATTERN (next)) == SEQUENCE)
918 continue;
919
920 extract_insn (next);
921 code = INSN_CODE (next);
922
923 switch (code)
924 {
925 case CODE_FOR_adddf3:
926 case CODE_FOR_subdf3:
927 case CODE_FOR_muldf3:
928 case CODE_FOR_divdf3:
929 dest = REGNO (recog_data.operand[0]);
930 src1 = REGNO (recog_data.operand[1]);
931 src2 = REGNO (recog_data.operand[2]);
932 if (src1 != src2)
933 {
934 /* Case [1-4]:
935 ld [address], %fx+1
936 FPOPd %f{x,y}, %f{y,x}, %f{x,y} */
937 if ((src1 == x || src2 == x)
938 && (dest == src1 || dest == src2))
939 insert_nop = true;
940 }
941 else
942 {
943 /* Case 5:
944 ld [address], %fx+1
945 FPOPd %fx, %fx, %fx */
946 if (src1 == x
947 && dest == src1
948 && (code == CODE_FOR_adddf3 || code == CODE_FOR_muldf3))
949 insert_nop = true;
950 }
951 break;
952
953 case CODE_FOR_sqrtdf2:
954 dest = REGNO (recog_data.operand[0]);
955 src1 = REGNO (recog_data.operand[1]);
956 /* Case 6:
957 ld [address], %fx+1
958 fsqrtd %fx, %fx */
959 if (src1 == x && dest == src1)
960 insert_nop = true;
961 break;
962
963 default:
964 break;
965 }
966 }
967
968 /* Look for a single-word load into an integer register. */
969 else if (sparc_fix_ut699
970 && NONJUMP_INSN_P (insn)
971 && (set = single_set (insn)) != NULL_RTX
972 && GET_MODE_SIZE (GET_MODE (SET_SRC (set))) <= 4
973 && mem_ref (SET_SRC (set)) != NULL_RTX
974 && REG_P (SET_DEST (set))
975 && REGNO (SET_DEST (set)) < 32)
976 {
977 /* There is no problem if the second memory access has a data
978 dependency on the first single-cycle load. */
979 rtx x = SET_DEST (set);
980
981 next = next_active_insn (insn);
982 if (!next)
983 break;
984 /* If the insn is a branch, then it cannot be problematic. */
985 if (!NONJUMP_INSN_P (next) || GET_CODE (PATTERN (next)) == SEQUENCE)
986 continue;
987
988 /* Look for a second memory access to/from an integer register. */
989 if ((set = single_set (next)) != NULL_RTX)
990 {
991 rtx src = SET_SRC (set);
992 rtx dest = SET_DEST (set);
993 rtx mem;
994
995 /* LDD is affected. */
996 if ((mem = mem_ref (src)) != NULL_RTX
997 && REG_P (dest)
998 && REGNO (dest) < 32
999 && !reg_mentioned_p (x, XEXP (mem, 0)))
1000 insert_nop = true;
1001
1002 /* STD is *not* affected. */
1003 else if (MEM_P (dest)
1004 && GET_MODE_SIZE (GET_MODE (dest)) <= 4
1005 && (src == CONST0_RTX (GET_MODE (dest))
1006 || (REG_P (src)
1007 && REGNO (src) < 32
1008 && REGNO (src) != REGNO (x)))
1009 && !reg_mentioned_p (x, XEXP (dest, 0)))
1010 insert_nop = true;
1011 }
1012 }
1013
1014 /* Look for a single-word load/operation into an FP register. */
1015 else if (sparc_fix_ut699
1016 && NONJUMP_INSN_P (insn)
1017 && (set = single_set (insn)) != NULL_RTX
1018 && GET_MODE_SIZE (GET_MODE (SET_SRC (set))) == 4
1019 && REG_P (SET_DEST (set))
1020 && REGNO (SET_DEST (set)) > 31)
1021 {
1022 /* Number of instructions in the problematic window. */
1023 const int n_insns = 4;
1024 /* The problematic combination is with the sibling FP register. */
1025 const unsigned int x = REGNO (SET_DEST (set));
1026 const unsigned int y = x ^ 1;
1027 rtx_insn *after;
1028 int i;
1029
1030 next = next_active_insn (insn);
1031 if (!next)
1032 break;
1033 /* If the insn is a branch, then it cannot be problematic. */
1034 if (!NONJUMP_INSN_P (next) || GET_CODE (PATTERN (next)) == SEQUENCE)
1035 continue;
1036
1037 /* Look for a second load/operation into the sibling FP register. */
1038 if (!((set = single_set (next)) != NULL_RTX
1039 && GET_MODE_SIZE (GET_MODE (SET_SRC (set))) == 4
1040 && REG_P (SET_DEST (set))
1041 && REGNO (SET_DEST (set)) == y))
1042 continue;
1043
1044 /* Look for a (possible) store from the FP register in the next N
1045 instructions, but bail out if it is again modified or if there
1046 is a store from the sibling FP register before this store. */
1047 for (after = next, i = 0; i < n_insns; i++)
1048 {
1049 bool branch_p;
1050
1051 after = next_active_insn (after);
1052 if (!after)
1053 break;
1054
1055 /* This is a branch with an empty delay slot. */
1056 if (!NONJUMP_INSN_P (after))
1057 {
1058 if (++i == n_insns)
1059 break;
1060 branch_p = true;
1061 after = NULL;
1062 }
1063 /* This is a branch with a filled delay slot. */
1064 else if (rtx_sequence *seq =
1065 dyn_cast <rtx_sequence *> (PATTERN (after)))
1066 {
1067 if (++i == n_insns)
1068 break;
1069 branch_p = true;
1070 after = seq->insn (1);
1071 }
1072 /* This is a regular instruction. */
1073 else
1074 branch_p = false;
1075
1076 if (after && (set = single_set (after)) != NULL_RTX)
1077 {
1078 const rtx src = SET_SRC (set);
1079 const rtx dest = SET_DEST (set);
1080 const unsigned int size = GET_MODE_SIZE (GET_MODE (dest));
1081
1082 /* If the FP register is again modified before the store,
1083 then the store isn't affected. */
1084 if (REG_P (dest)
1085 && (REGNO (dest) == x
1086 || (REGNO (dest) == y && size == 8)))
1087 break;
1088
1089 if (MEM_P (dest) && REG_P (src))
1090 {
1091 /* If there is a store from the sibling FP register
1092 before the store, then the store is not affected. */
1093 if (REGNO (src) == y || (REGNO (src) == x && size == 8))
1094 break;
1095
1096 /* Otherwise, the store is affected. */
1097 if (REGNO (src) == x && size == 4)
1098 {
1099 insert_nop = true;
1100 break;
1101 }
1102 }
1103 }
1104
1105 /* If we have a branch in the first M instructions, then we
1106 cannot see the (M+2)th instruction so we play safe. */
1107 if (branch_p && i <= (n_insns - 2))
1108 {
1109 insert_nop = true;
1110 break;
1111 }
1112 }
1113 }
1114
1115 else
1116 next = NEXT_INSN (insn);
1117
1118 if (insert_nop)
1119 emit_insn_before (gen_nop (), next);
1120 }
1121
1122 return 0;
1123 }
1124
1125 namespace {
1126
1127 const pass_data pass_data_work_around_errata =
1128 {
1129 RTL_PASS, /* type */
1130 "errata", /* name */
1131 OPTGROUP_NONE, /* optinfo_flags */
1132 TV_MACH_DEP, /* tv_id */
1133 0, /* properties_required */
1134 0, /* properties_provided */
1135 0, /* properties_destroyed */
1136 0, /* todo_flags_start */
1137 0, /* todo_flags_finish */
1138 };
1139
1140 class pass_work_around_errata : public rtl_opt_pass
1141 {
1142 public:
1143 pass_work_around_errata(gcc::context *ctxt)
1144 : rtl_opt_pass(pass_data_work_around_errata, ctxt)
1145 {}
1146
1147 /* opt_pass methods: */
1148 virtual bool gate (function *)
1149 {
1150 /* The only errata we handle are those of the AT697F and UT699. */
1151 return sparc_fix_at697f != 0 || sparc_fix_ut699 != 0;
1152 }
1153
1154 virtual unsigned int execute (function *)
1155 {
1156 return sparc_do_work_around_errata ();
1157 }
1158
1159 }; // class pass_work_around_errata
1160
1161 } // anon namespace
1162
1163 rtl_opt_pass *
1164 make_pass_work_around_errata (gcc::context *ctxt)
1165 {
1166 return new pass_work_around_errata (ctxt);
1167 }
1168
1169 /* Helpers for TARGET_DEBUG_OPTIONS. */
1170 static void
1171 dump_target_flag_bits (const int flags)
1172 {
1173 if (flags & MASK_64BIT)
1174 fprintf (stderr, "64BIT ");
1175 if (flags & MASK_APP_REGS)
1176 fprintf (stderr, "APP_REGS ");
1177 if (flags & MASK_FASTER_STRUCTS)
1178 fprintf (stderr, "FASTER_STRUCTS ");
1179 if (flags & MASK_FLAT)
1180 fprintf (stderr, "FLAT ");
1181 if (flags & MASK_FMAF)
1182 fprintf (stderr, "FMAF ");
1183 if (flags & MASK_FPU)
1184 fprintf (stderr, "FPU ");
1185 if (flags & MASK_HARD_QUAD)
1186 fprintf (stderr, "HARD_QUAD ");
1187 if (flags & MASK_POPC)
1188 fprintf (stderr, "POPC ");
1189 if (flags & MASK_PTR64)
1190 fprintf (stderr, "PTR64 ");
1191 if (flags & MASK_STACK_BIAS)
1192 fprintf (stderr, "STACK_BIAS ");
1193 if (flags & MASK_UNALIGNED_DOUBLES)
1194 fprintf (stderr, "UNALIGNED_DOUBLES ");
1195 if (flags & MASK_V8PLUS)
1196 fprintf (stderr, "V8PLUS ");
1197 if (flags & MASK_VIS)
1198 fprintf (stderr, "VIS ");
1199 if (flags & MASK_VIS2)
1200 fprintf (stderr, "VIS2 ");
1201 if (flags & MASK_VIS3)
1202 fprintf (stderr, "VIS3 ");
1203 if (flags & MASK_CBCOND)
1204 fprintf (stderr, "CBCOND ");
1205 if (flags & MASK_DEPRECATED_V8_INSNS)
1206 fprintf (stderr, "DEPRECATED_V8_INSNS ");
1207 if (flags & MASK_SPARCLET)
1208 fprintf (stderr, "SPARCLET ");
1209 if (flags & MASK_SPARCLITE)
1210 fprintf (stderr, "SPARCLITE ");
1211 if (flags & MASK_V8)
1212 fprintf (stderr, "V8 ");
1213 if (flags & MASK_V9)
1214 fprintf (stderr, "V9 ");
1215 }
1216
1217 static void
1218 dump_target_flags (const char *prefix, const int flags)
1219 {
1220 fprintf (stderr, "%s: (%08x) [ ", prefix, flags);
1221 dump_target_flag_bits (flags);
1222 fprintf(stderr, "]\n");
1223 }
1224
1225 /* Validate and override various options, and do some machine dependent
1226 initialization. */
1227
1228 static void
1229 sparc_option_override (void)
1230 {
1231 static struct code_model {
1232 const char *const name;
1233 const enum cmodel value;
1234 } const cmodels[] = {
1235 { "32", CM_32 },
1236 { "medlow", CM_MEDLOW },
1237 { "medmid", CM_MEDMID },
1238 { "medany", CM_MEDANY },
1239 { "embmedany", CM_EMBMEDANY },
1240 { NULL, (enum cmodel) 0 }
1241 };
1242 const struct code_model *cmodel;
1243 /* Map TARGET_CPU_DEFAULT to value for -m{cpu,tune}=. */
1244 static struct cpu_default {
1245 const int cpu;
1246 const enum processor_type processor;
1247 } const cpu_default[] = {
1248 /* There must be one entry here for each TARGET_CPU value. */
1249 { TARGET_CPU_sparc, PROCESSOR_CYPRESS },
1250 { TARGET_CPU_v8, PROCESSOR_V8 },
1251 { TARGET_CPU_supersparc, PROCESSOR_SUPERSPARC },
1252 { TARGET_CPU_hypersparc, PROCESSOR_HYPERSPARC },
1253 { TARGET_CPU_leon, PROCESSOR_LEON },
1254 { TARGET_CPU_leon3, PROCESSOR_LEON3 },
1255 { TARGET_CPU_leon3v7, PROCESSOR_LEON3V7 },
1256 { TARGET_CPU_sparclite, PROCESSOR_F930 },
1257 { TARGET_CPU_sparclite86x, PROCESSOR_SPARCLITE86X },
1258 { TARGET_CPU_sparclet, PROCESSOR_TSC701 },
1259 { TARGET_CPU_v9, PROCESSOR_V9 },
1260 { TARGET_CPU_ultrasparc, PROCESSOR_ULTRASPARC },
1261 { TARGET_CPU_ultrasparc3, PROCESSOR_ULTRASPARC3 },
1262 { TARGET_CPU_niagara, PROCESSOR_NIAGARA },
1263 { TARGET_CPU_niagara2, PROCESSOR_NIAGARA2 },
1264 { TARGET_CPU_niagara3, PROCESSOR_NIAGARA3 },
1265 { TARGET_CPU_niagara4, PROCESSOR_NIAGARA4 },
1266 { -1, PROCESSOR_V7 }
1267 };
1268 const struct cpu_default *def;
1269 /* Table of values for -m{cpu,tune}=. This must match the order of
1270 the enum processor_type in sparc-opts.h. */
1271 static struct cpu_table {
1272 const char *const name;
1273 const int disable;
1274 const int enable;
1275 } const cpu_table[] = {
1276 { "v7", MASK_ISA, 0 },
1277 { "cypress", MASK_ISA, 0 },
1278 { "v8", MASK_ISA, MASK_V8 },
1279 /* TI TMS390Z55 supersparc */
1280 { "supersparc", MASK_ISA, MASK_V8 },
1281 { "hypersparc", MASK_ISA, MASK_V8|MASK_FPU },
1282 { "leon", MASK_ISA, MASK_V8|MASK_LEON|MASK_FPU },
1283 { "leon3", MASK_ISA, MASK_V8|MASK_LEON3|MASK_FPU },
1284 { "leon3v7", MASK_ISA, MASK_LEON3|MASK_FPU },
1285 { "sparclite", MASK_ISA, MASK_SPARCLITE },
1286 /* The Fujitsu MB86930 is the original sparclite chip, with no FPU. */
1287 { "f930", MASK_ISA|MASK_FPU, MASK_SPARCLITE },
1288 /* The Fujitsu MB86934 is the recent sparclite chip, with an FPU. */
1289 { "f934", MASK_ISA, MASK_SPARCLITE|MASK_FPU },
1290 { "sparclite86x", MASK_ISA|MASK_FPU, MASK_SPARCLITE },
1291 { "sparclet", MASK_ISA, MASK_SPARCLET },
1292 /* TEMIC sparclet */
1293 { "tsc701", MASK_ISA, MASK_SPARCLET },
1294 { "v9", MASK_ISA, MASK_V9 },
1295 /* UltraSPARC I, II, IIi */
1296 { "ultrasparc", MASK_ISA,
1297 /* Although insns using %y are deprecated, it is a clear win. */
1298 MASK_V9|MASK_DEPRECATED_V8_INSNS },
1299 /* UltraSPARC III */
1300 /* ??? Check if %y issue still holds true. */
1301 { "ultrasparc3", MASK_ISA,
1302 MASK_V9|MASK_DEPRECATED_V8_INSNS|MASK_VIS2 },
1303 /* UltraSPARC T1 */
1304 { "niagara", MASK_ISA,
1305 MASK_V9|MASK_DEPRECATED_V8_INSNS },
1306 /* UltraSPARC T2 */
1307 { "niagara2", MASK_ISA,
1308 MASK_V9|MASK_POPC|MASK_VIS2 },
1309 /* UltraSPARC T3 */
1310 { "niagara3", MASK_ISA,
1311 MASK_V9|MASK_POPC|MASK_VIS2|MASK_VIS3|MASK_FMAF },
1312 /* UltraSPARC T4 */
1313 { "niagara4", MASK_ISA,
1314 MASK_V9|MASK_POPC|MASK_VIS2|MASK_VIS3|MASK_FMAF|MASK_CBCOND },
1315 };
1316 const struct cpu_table *cpu;
1317 unsigned int i;
1318 int fpu;
1319
1320 if (sparc_debug_string != NULL)
1321 {
1322 const char *q;
1323 char *p;
1324
1325 p = ASTRDUP (sparc_debug_string);
1326 while ((q = strtok (p, ",")) != NULL)
1327 {
1328 bool invert;
1329 int mask;
1330
1331 p = NULL;
1332 if (*q == '!')
1333 {
1334 invert = true;
1335 q++;
1336 }
1337 else
1338 invert = false;
1339
1340 if (! strcmp (q, "all"))
1341 mask = MASK_DEBUG_ALL;
1342 else if (! strcmp (q, "options"))
1343 mask = MASK_DEBUG_OPTIONS;
1344 else
1345 error ("unknown -mdebug-%s switch", q);
1346
1347 if (invert)
1348 sparc_debug &= ~mask;
1349 else
1350 sparc_debug |= mask;
1351 }
1352 }
1353
1354 if (TARGET_DEBUG_OPTIONS)
1355 {
1356 dump_target_flags("Initial target_flags", target_flags);
1357 dump_target_flags("target_flags_explicit", target_flags_explicit);
1358 }
1359
1360 #ifdef SUBTARGET_OVERRIDE_OPTIONS
1361 SUBTARGET_OVERRIDE_OPTIONS;
1362 #endif
1363
1364 #ifndef SPARC_BI_ARCH
1365 /* Check for unsupported architecture size. */
1366 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
1367 error ("%s is not supported by this configuration",
1368 DEFAULT_ARCH32_P ? "-m64" : "-m32");
1369 #endif
1370
1371 /* We force all 64bit archs to use 128 bit long double */
1372 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
1373 {
1374 error ("-mlong-double-64 not allowed with -m64");
1375 target_flags |= MASK_LONG_DOUBLE_128;
1376 }
1377
1378 /* Code model selection. */
1379 sparc_cmodel = SPARC_DEFAULT_CMODEL;
1380
1381 #ifdef SPARC_BI_ARCH
1382 if (TARGET_ARCH32)
1383 sparc_cmodel = CM_32;
1384 #endif
1385
1386 if (sparc_cmodel_string != NULL)
1387 {
1388 if (TARGET_ARCH64)
1389 {
1390 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
1391 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
1392 break;
1393 if (cmodel->name == NULL)
1394 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
1395 else
1396 sparc_cmodel = cmodel->value;
1397 }
1398 else
1399 error ("-mcmodel= is not supported on 32 bit systems");
1400 }
1401
1402 /* Check that -fcall-saved-REG wasn't specified for out registers. */
1403 for (i = 8; i < 16; i++)
1404 if (!call_used_regs [i])
1405 {
1406 error ("-fcall-saved-REG is not supported for out registers");
1407 call_used_regs [i] = 1;
1408 }
1409
1410 fpu = target_flags & MASK_FPU; /* save current -mfpu status */
1411
1412 /* Set the default CPU. */
1413 if (!global_options_set.x_sparc_cpu_and_features)
1414 {
1415 for (def = &cpu_default[0]; def->cpu != -1; ++def)
1416 if (def->cpu == TARGET_CPU_DEFAULT)
1417 break;
1418 gcc_assert (def->cpu != -1);
1419 sparc_cpu_and_features = def->processor;
1420 }
1421
1422 if (!global_options_set.x_sparc_cpu)
1423 sparc_cpu = sparc_cpu_and_features;
1424
1425 cpu = &cpu_table[(int) sparc_cpu_and_features];
1426
1427 if (TARGET_DEBUG_OPTIONS)
1428 {
1429 fprintf (stderr, "sparc_cpu_and_features: %s\n", cpu->name);
1430 fprintf (stderr, "sparc_cpu: %s\n",
1431 cpu_table[(int) sparc_cpu].name);
1432 dump_target_flags ("cpu->disable", cpu->disable);
1433 dump_target_flags ("cpu->enable", cpu->enable);
1434 }
1435
1436 target_flags &= ~cpu->disable;
1437 target_flags |= (cpu->enable
1438 #ifndef HAVE_AS_FMAF_HPC_VIS3
1439 & ~(MASK_FMAF | MASK_VIS3)
1440 #endif
1441 #ifndef HAVE_AS_SPARC4
1442 & ~MASK_CBCOND
1443 #endif
1444 #ifndef HAVE_AS_LEON
1445 & ~(MASK_LEON | MASK_LEON3)
1446 #endif
1447 );
1448
1449 /* If -mfpu or -mno-fpu was explicitly used, don't override with
1450 the processor default. */
1451 if (target_flags_explicit & MASK_FPU)
1452 target_flags = (target_flags & ~MASK_FPU) | fpu;
1453
1454 /* -mvis2 implies -mvis */
1455 if (TARGET_VIS2)
1456 target_flags |= MASK_VIS;
1457
1458 /* -mvis3 implies -mvis2 and -mvis */
1459 if (TARGET_VIS3)
1460 target_flags |= MASK_VIS2 | MASK_VIS;
1461
1462 /* Don't allow -mvis, -mvis2, -mvis3, or -mfmaf if FPU is
1463 disabled. */
1464 if (! TARGET_FPU)
1465 target_flags &= ~(MASK_VIS | MASK_VIS2 | MASK_VIS3 | MASK_FMAF);
1466
1467 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
1468 are available.
1469 -m64 also implies v9. */
1470 if (TARGET_VIS || TARGET_ARCH64)
1471 {
1472 target_flags |= MASK_V9;
1473 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
1474 }
1475
1476 /* -mvis also implies -mv8plus on 32-bit */
1477 if (TARGET_VIS && ! TARGET_ARCH64)
1478 target_flags |= MASK_V8PLUS;
1479
1480 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
1481 if (TARGET_V9 && TARGET_ARCH32)
1482 target_flags |= MASK_DEPRECATED_V8_INSNS;
1483
1484 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
1485 if (! TARGET_V9 || TARGET_ARCH64)
1486 target_flags &= ~MASK_V8PLUS;
1487
1488 /* Don't use stack biasing in 32 bit mode. */
1489 if (TARGET_ARCH32)
1490 target_flags &= ~MASK_STACK_BIAS;
1491
1492 /* Supply a default value for align_functions. */
1493 if (align_functions == 0
1494 && (sparc_cpu == PROCESSOR_ULTRASPARC
1495 || sparc_cpu == PROCESSOR_ULTRASPARC3
1496 || sparc_cpu == PROCESSOR_NIAGARA
1497 || sparc_cpu == PROCESSOR_NIAGARA2
1498 || sparc_cpu == PROCESSOR_NIAGARA3
1499 || sparc_cpu == PROCESSOR_NIAGARA4))
1500 align_functions = 32;
1501
1502 /* Validate PCC_STRUCT_RETURN. */
1503 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
1504 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
1505
1506 /* Only use .uaxword when compiling for a 64-bit target. */
1507 if (!TARGET_ARCH64)
1508 targetm.asm_out.unaligned_op.di = NULL;
1509
1510 /* Do various machine dependent initializations. */
1511 sparc_init_modes ();
1512
1513 /* Set up function hooks. */
1514 init_machine_status = sparc_init_machine_status;
1515
1516 switch (sparc_cpu)
1517 {
1518 case PROCESSOR_V7:
1519 case PROCESSOR_CYPRESS:
1520 sparc_costs = &cypress_costs;
1521 break;
1522 case PROCESSOR_V8:
1523 case PROCESSOR_SPARCLITE:
1524 case PROCESSOR_SUPERSPARC:
1525 sparc_costs = &supersparc_costs;
1526 break;
1527 case PROCESSOR_F930:
1528 case PROCESSOR_F934:
1529 case PROCESSOR_HYPERSPARC:
1530 case PROCESSOR_SPARCLITE86X:
1531 sparc_costs = &hypersparc_costs;
1532 break;
1533 case PROCESSOR_LEON:
1534 sparc_costs = &leon_costs;
1535 break;
1536 case PROCESSOR_LEON3:
1537 case PROCESSOR_LEON3V7:
1538 sparc_costs = &leon3_costs;
1539 break;
1540 case PROCESSOR_SPARCLET:
1541 case PROCESSOR_TSC701:
1542 sparc_costs = &sparclet_costs;
1543 break;
1544 case PROCESSOR_V9:
1545 case PROCESSOR_ULTRASPARC:
1546 sparc_costs = &ultrasparc_costs;
1547 break;
1548 case PROCESSOR_ULTRASPARC3:
1549 sparc_costs = &ultrasparc3_costs;
1550 break;
1551 case PROCESSOR_NIAGARA:
1552 sparc_costs = &niagara_costs;
1553 break;
1554 case PROCESSOR_NIAGARA2:
1555 sparc_costs = &niagara2_costs;
1556 break;
1557 case PROCESSOR_NIAGARA3:
1558 sparc_costs = &niagara3_costs;
1559 break;
1560 case PROCESSOR_NIAGARA4:
1561 sparc_costs = &niagara4_costs;
1562 break;
1563 case PROCESSOR_NATIVE:
1564 gcc_unreachable ();
1565 };
1566
1567 if (sparc_memory_model == SMM_DEFAULT)
1568 {
1569 /* Choose the memory model for the operating system. */
1570 enum sparc_memory_model_type os_default = SUBTARGET_DEFAULT_MEMORY_MODEL;
1571 if (os_default != SMM_DEFAULT)
1572 sparc_memory_model = os_default;
1573 /* Choose the most relaxed model for the processor. */
1574 else if (TARGET_V9)
1575 sparc_memory_model = SMM_RMO;
1576 else if (TARGET_LEON3)
1577 sparc_memory_model = SMM_TSO;
1578 else if (TARGET_LEON)
1579 sparc_memory_model = SMM_SC;
1580 else if (TARGET_V8)
1581 sparc_memory_model = SMM_PSO;
1582 else
1583 sparc_memory_model = SMM_SC;
1584 }
1585
1586 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
1587 if (!(target_flags_explicit & MASK_LONG_DOUBLE_128))
1588 target_flags |= MASK_LONG_DOUBLE_128;
1589 #endif
1590
1591 if (TARGET_DEBUG_OPTIONS)
1592 dump_target_flags ("Final target_flags", target_flags);
1593
1594 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
1595 ((sparc_cpu == PROCESSOR_ULTRASPARC
1596 || sparc_cpu == PROCESSOR_NIAGARA
1597 || sparc_cpu == PROCESSOR_NIAGARA2
1598 || sparc_cpu == PROCESSOR_NIAGARA3
1599 || sparc_cpu == PROCESSOR_NIAGARA4)
1600 ? 2
1601 : (sparc_cpu == PROCESSOR_ULTRASPARC3
1602 ? 8 : 3)),
1603 global_options.x_param_values,
1604 global_options_set.x_param_values);
1605 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
1606 ((sparc_cpu == PROCESSOR_ULTRASPARC
1607 || sparc_cpu == PROCESSOR_ULTRASPARC3
1608 || sparc_cpu == PROCESSOR_NIAGARA
1609 || sparc_cpu == PROCESSOR_NIAGARA2
1610 || sparc_cpu == PROCESSOR_NIAGARA3
1611 || sparc_cpu == PROCESSOR_NIAGARA4)
1612 ? 64 : 32),
1613 global_options.x_param_values,
1614 global_options_set.x_param_values);
1615
1616 /* Disable save slot sharing for call-clobbered registers by default.
1617 The IRA sharing algorithm works on single registers only and this
1618 pessimizes for double floating-point registers. */
1619 if (!global_options_set.x_flag_ira_share_save_slots)
1620 flag_ira_share_save_slots = 0;
1621
1622 /* We register a machine specific pass to work around errata, if any.
1623 The pass mut be scheduled as late as possible so that we have the
1624 (essentially) final form of the insn stream to work on.
1625 Registering the pass must be done at start up. It's convenient to
1626 do it here. */
1627 opt_pass *errata_pass = make_pass_work_around_errata (g);
1628 struct register_pass_info insert_pass_work_around_errata =
1629 {
1630 errata_pass, /* pass */
1631 "dbr", /* reference_pass_name */
1632 1, /* ref_pass_instance_number */
1633 PASS_POS_INSERT_AFTER /* po_op */
1634 };
1635 register_pass (&insert_pass_work_around_errata);
1636 }
1637 \f
1638 /* Miscellaneous utilities. */
1639
1640 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
1641 or branch on register contents instructions. */
1642
1643 int
1644 v9_regcmp_p (enum rtx_code code)
1645 {
1646 return (code == EQ || code == NE || code == GE || code == LT
1647 || code == LE || code == GT);
1648 }
1649
1650 /* Nonzero if OP is a floating point constant which can
1651 be loaded into an integer register using a single
1652 sethi instruction. */
1653
1654 int
1655 fp_sethi_p (rtx op)
1656 {
1657 if (GET_CODE (op) == CONST_DOUBLE)
1658 {
1659 REAL_VALUE_TYPE r;
1660 long i;
1661
1662 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
1663 REAL_VALUE_TO_TARGET_SINGLE (r, i);
1664 return !SPARC_SIMM13_P (i) && SPARC_SETHI_P (i);
1665 }
1666
1667 return 0;
1668 }
1669
1670 /* Nonzero if OP is a floating point constant which can
1671 be loaded into an integer register using a single
1672 mov instruction. */
1673
1674 int
1675 fp_mov_p (rtx op)
1676 {
1677 if (GET_CODE (op) == CONST_DOUBLE)
1678 {
1679 REAL_VALUE_TYPE r;
1680 long i;
1681
1682 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
1683 REAL_VALUE_TO_TARGET_SINGLE (r, i);
1684 return SPARC_SIMM13_P (i);
1685 }
1686
1687 return 0;
1688 }
1689
1690 /* Nonzero if OP is a floating point constant which can
1691 be loaded into an integer register using a high/losum
1692 instruction sequence. */
1693
1694 int
1695 fp_high_losum_p (rtx op)
1696 {
1697 /* The constraints calling this should only be in
1698 SFmode move insns, so any constant which cannot
1699 be moved using a single insn will do. */
1700 if (GET_CODE (op) == CONST_DOUBLE)
1701 {
1702 REAL_VALUE_TYPE r;
1703 long i;
1704
1705 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
1706 REAL_VALUE_TO_TARGET_SINGLE (r, i);
1707 return !SPARC_SIMM13_P (i) && !SPARC_SETHI_P (i);
1708 }
1709
1710 return 0;
1711 }
1712
1713 /* Return true if the address of LABEL can be loaded by means of the
1714 mov{si,di}_pic_label_ref patterns in PIC mode. */
1715
1716 static bool
1717 can_use_mov_pic_label_ref (rtx label)
1718 {
1719 /* VxWorks does not impose a fixed gap between segments; the run-time
1720 gap can be different from the object-file gap. We therefore can't
1721 assume X - _GLOBAL_OFFSET_TABLE_ is a link-time constant unless we
1722 are absolutely sure that X is in the same segment as the GOT.
1723 Unfortunately, the flexibility of linker scripts means that we
1724 can't be sure of that in general, so assume that GOT-relative
1725 accesses are never valid on VxWorks. */
1726 if (TARGET_VXWORKS_RTP)
1727 return false;
1728
1729 /* Similarly, if the label is non-local, it might end up being placed
1730 in a different section than the current one; now mov_pic_label_ref
1731 requires the label and the code to be in the same section. */
1732 if (LABEL_REF_NONLOCAL_P (label))
1733 return false;
1734
1735 /* Finally, if we are reordering basic blocks and partition into hot
1736 and cold sections, this might happen for any label. */
1737 if (flag_reorder_blocks_and_partition)
1738 return false;
1739
1740 return true;
1741 }
1742
1743 /* Expand a move instruction. Return true if all work is done. */
1744
1745 bool
1746 sparc_expand_move (machine_mode mode, rtx *operands)
1747 {
1748 /* Handle sets of MEM first. */
1749 if (GET_CODE (operands[0]) == MEM)
1750 {
1751 /* 0 is a register (or a pair of registers) on SPARC. */
1752 if (register_or_zero_operand (operands[1], mode))
1753 return false;
1754
1755 if (!reload_in_progress)
1756 {
1757 operands[0] = validize_mem (operands[0]);
1758 operands[1] = force_reg (mode, operands[1]);
1759 }
1760 }
1761
1762 /* Fixup TLS cases. */
1763 if (TARGET_HAVE_TLS
1764 && CONSTANT_P (operands[1])
1765 && sparc_tls_referenced_p (operands [1]))
1766 {
1767 operands[1] = sparc_legitimize_tls_address (operands[1]);
1768 return false;
1769 }
1770
1771 /* Fixup PIC cases. */
1772 if (flag_pic && CONSTANT_P (operands[1]))
1773 {
1774 if (pic_address_needs_scratch (operands[1]))
1775 operands[1] = sparc_legitimize_pic_address (operands[1], NULL_RTX);
1776
1777 /* We cannot use the mov{si,di}_pic_label_ref patterns in all cases. */
1778 if (GET_CODE (operands[1]) == LABEL_REF
1779 && can_use_mov_pic_label_ref (operands[1]))
1780 {
1781 if (mode == SImode)
1782 {
1783 emit_insn (gen_movsi_pic_label_ref (operands[0], operands[1]));
1784 return true;
1785 }
1786
1787 if (mode == DImode)
1788 {
1789 gcc_assert (TARGET_ARCH64);
1790 emit_insn (gen_movdi_pic_label_ref (operands[0], operands[1]));
1791 return true;
1792 }
1793 }
1794
1795 if (symbolic_operand (operands[1], mode))
1796 {
1797 operands[1]
1798 = sparc_legitimize_pic_address (operands[1],
1799 reload_in_progress
1800 ? operands[0] : NULL_RTX);
1801 return false;
1802 }
1803 }
1804
1805 /* If we are trying to toss an integer constant into FP registers,
1806 or loading a FP or vector constant, force it into memory. */
1807 if (CONSTANT_P (operands[1])
1808 && REG_P (operands[0])
1809 && (SPARC_FP_REG_P (REGNO (operands[0]))
1810 || SCALAR_FLOAT_MODE_P (mode)
1811 || VECTOR_MODE_P (mode)))
1812 {
1813 /* emit_group_store will send such bogosity to us when it is
1814 not storing directly into memory. So fix this up to avoid
1815 crashes in output_constant_pool. */
1816 if (operands [1] == const0_rtx)
1817 operands[1] = CONST0_RTX (mode);
1818
1819 /* We can clear or set to all-ones FP registers if TARGET_VIS, and
1820 always other regs. */
1821 if ((TARGET_VIS || REGNO (operands[0]) < SPARC_FIRST_FP_REG)
1822 && (const_zero_operand (operands[1], mode)
1823 || const_all_ones_operand (operands[1], mode)))
1824 return false;
1825
1826 if (REGNO (operands[0]) < SPARC_FIRST_FP_REG
1827 /* We are able to build any SF constant in integer registers
1828 with at most 2 instructions. */
1829 && (mode == SFmode
1830 /* And any DF constant in integer registers. */
1831 || (mode == DFmode
1832 && ! can_create_pseudo_p ())))
1833 return false;
1834
1835 operands[1] = force_const_mem (mode, operands[1]);
1836 if (!reload_in_progress)
1837 operands[1] = validize_mem (operands[1]);
1838 return false;
1839 }
1840
1841 /* Accept non-constants and valid constants unmodified. */
1842 if (!CONSTANT_P (operands[1])
1843 || GET_CODE (operands[1]) == HIGH
1844 || input_operand (operands[1], mode))
1845 return false;
1846
1847 switch (mode)
1848 {
1849 case QImode:
1850 /* All QImode constants require only one insn, so proceed. */
1851 break;
1852
1853 case HImode:
1854 case SImode:
1855 sparc_emit_set_const32 (operands[0], operands[1]);
1856 return true;
1857
1858 case DImode:
1859 /* input_operand should have filtered out 32-bit mode. */
1860 sparc_emit_set_const64 (operands[0], operands[1]);
1861 return true;
1862
1863 case TImode:
1864 {
1865 rtx high, low;
1866 /* TImode isn't available in 32-bit mode. */
1867 split_double (operands[1], &high, &low);
1868 emit_insn (gen_movdi (operand_subword (operands[0], 0, 0, TImode),
1869 high));
1870 emit_insn (gen_movdi (operand_subword (operands[0], 1, 0, TImode),
1871 low));
1872 }
1873 return true;
1874
1875 default:
1876 gcc_unreachable ();
1877 }
1878
1879 return false;
1880 }
1881
1882 /* Load OP1, a 32-bit constant, into OP0, a register.
1883 We know it can't be done in one insn when we get
1884 here, the move expander guarantees this. */
1885
1886 static void
1887 sparc_emit_set_const32 (rtx op0, rtx op1)
1888 {
1889 machine_mode mode = GET_MODE (op0);
1890 rtx temp = op0;
1891
1892 if (can_create_pseudo_p ())
1893 temp = gen_reg_rtx (mode);
1894
1895 if (GET_CODE (op1) == CONST_INT)
1896 {
1897 gcc_assert (!small_int_operand (op1, mode)
1898 && !const_high_operand (op1, mode));
1899
1900 /* Emit them as real moves instead of a HIGH/LO_SUM,
1901 this way CSE can see everything and reuse intermediate
1902 values if it wants. */
1903 emit_insn (gen_rtx_SET (temp, GEN_INT (INTVAL (op1)
1904 & ~(HOST_WIDE_INT) 0x3ff)));
1905
1906 emit_insn (gen_rtx_SET (op0,
1907 gen_rtx_IOR (mode, temp,
1908 GEN_INT (INTVAL (op1) & 0x3ff))));
1909 }
1910 else
1911 {
1912 /* A symbol, emit in the traditional way. */
1913 emit_insn (gen_rtx_SET (temp, gen_rtx_HIGH (mode, op1)));
1914 emit_insn (gen_rtx_SET (op0, gen_rtx_LO_SUM (mode, temp, op1)));
1915 }
1916 }
1917
1918 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
1919 If TEMP is nonzero, we are forbidden to use any other scratch
1920 registers. Otherwise, we are allowed to generate them as needed.
1921
1922 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
1923 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
1924
1925 void
1926 sparc_emit_set_symbolic_const64 (rtx op0, rtx op1, rtx temp)
1927 {
1928 rtx temp1, temp2, temp3, temp4, temp5;
1929 rtx ti_temp = 0;
1930
1931 if (temp && GET_MODE (temp) == TImode)
1932 {
1933 ti_temp = temp;
1934 temp = gen_rtx_REG (DImode, REGNO (temp));
1935 }
1936
1937 /* SPARC-V9 code-model support. */
1938 switch (sparc_cmodel)
1939 {
1940 case CM_MEDLOW:
1941 /* The range spanned by all instructions in the object is less
1942 than 2^31 bytes (2GB) and the distance from any instruction
1943 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1944 than 2^31 bytes (2GB).
1945
1946 The executable must be in the low 4TB of the virtual address
1947 space.
1948
1949 sethi %hi(symbol), %temp1
1950 or %temp1, %lo(symbol), %reg */
1951 if (temp)
1952 temp1 = temp; /* op0 is allowed. */
1953 else
1954 temp1 = gen_reg_rtx (DImode);
1955
1956 emit_insn (gen_rtx_SET (temp1, gen_rtx_HIGH (DImode, op1)));
1957 emit_insn (gen_rtx_SET (op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1958 break;
1959
1960 case CM_MEDMID:
1961 /* The range spanned by all instructions in the object is less
1962 than 2^31 bytes (2GB) and the distance from any instruction
1963 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1964 than 2^31 bytes (2GB).
1965
1966 The executable must be in the low 16TB of the virtual address
1967 space.
1968
1969 sethi %h44(symbol), %temp1
1970 or %temp1, %m44(symbol), %temp2
1971 sllx %temp2, 12, %temp3
1972 or %temp3, %l44(symbol), %reg */
1973 if (temp)
1974 {
1975 temp1 = op0;
1976 temp2 = op0;
1977 temp3 = temp; /* op0 is allowed. */
1978 }
1979 else
1980 {
1981 temp1 = gen_reg_rtx (DImode);
1982 temp2 = gen_reg_rtx (DImode);
1983 temp3 = gen_reg_rtx (DImode);
1984 }
1985
1986 emit_insn (gen_seth44 (temp1, op1));
1987 emit_insn (gen_setm44 (temp2, temp1, op1));
1988 emit_insn (gen_rtx_SET (temp3,
1989 gen_rtx_ASHIFT (DImode, temp2, GEN_INT (12))));
1990 emit_insn (gen_setl44 (op0, temp3, op1));
1991 break;
1992
1993 case CM_MEDANY:
1994 /* The range spanned by all instructions in the object is less
1995 than 2^31 bytes (2GB) and the distance from any instruction
1996 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1997 than 2^31 bytes (2GB).
1998
1999 The executable can be placed anywhere in the virtual address
2000 space.
2001
2002 sethi %hh(symbol), %temp1
2003 sethi %lm(symbol), %temp2
2004 or %temp1, %hm(symbol), %temp3
2005 sllx %temp3, 32, %temp4
2006 or %temp4, %temp2, %temp5
2007 or %temp5, %lo(symbol), %reg */
2008 if (temp)
2009 {
2010 /* It is possible that one of the registers we got for operands[2]
2011 might coincide with that of operands[0] (which is why we made
2012 it TImode). Pick the other one to use as our scratch. */
2013 if (rtx_equal_p (temp, op0))
2014 {
2015 gcc_assert (ti_temp);
2016 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
2017 }
2018 temp1 = op0;
2019 temp2 = temp; /* op0 is _not_ allowed, see above. */
2020 temp3 = op0;
2021 temp4 = op0;
2022 temp5 = op0;
2023 }
2024 else
2025 {
2026 temp1 = gen_reg_rtx (DImode);
2027 temp2 = gen_reg_rtx (DImode);
2028 temp3 = gen_reg_rtx (DImode);
2029 temp4 = gen_reg_rtx (DImode);
2030 temp5 = gen_reg_rtx (DImode);
2031 }
2032
2033 emit_insn (gen_sethh (temp1, op1));
2034 emit_insn (gen_setlm (temp2, op1));
2035 emit_insn (gen_sethm (temp3, temp1, op1));
2036 emit_insn (gen_rtx_SET (temp4,
2037 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
2038 emit_insn (gen_rtx_SET (temp5, gen_rtx_PLUS (DImode, temp4, temp2)));
2039 emit_insn (gen_setlo (op0, temp5, op1));
2040 break;
2041
2042 case CM_EMBMEDANY:
2043 /* Old old old backwards compatibility kruft here.
2044 Essentially it is MEDLOW with a fixed 64-bit
2045 virtual base added to all data segment addresses.
2046 Text-segment stuff is computed like MEDANY, we can't
2047 reuse the code above because the relocation knobs
2048 look different.
2049
2050 Data segment: sethi %hi(symbol), %temp1
2051 add %temp1, EMBMEDANY_BASE_REG, %temp2
2052 or %temp2, %lo(symbol), %reg */
2053 if (data_segment_operand (op1, GET_MODE (op1)))
2054 {
2055 if (temp)
2056 {
2057 temp1 = temp; /* op0 is allowed. */
2058 temp2 = op0;
2059 }
2060 else
2061 {
2062 temp1 = gen_reg_rtx (DImode);
2063 temp2 = gen_reg_rtx (DImode);
2064 }
2065
2066 emit_insn (gen_embmedany_sethi (temp1, op1));
2067 emit_insn (gen_embmedany_brsum (temp2, temp1));
2068 emit_insn (gen_embmedany_losum (op0, temp2, op1));
2069 }
2070
2071 /* Text segment: sethi %uhi(symbol), %temp1
2072 sethi %hi(symbol), %temp2
2073 or %temp1, %ulo(symbol), %temp3
2074 sllx %temp3, 32, %temp4
2075 or %temp4, %temp2, %temp5
2076 or %temp5, %lo(symbol), %reg */
2077 else
2078 {
2079 if (temp)
2080 {
2081 /* It is possible that one of the registers we got for operands[2]
2082 might coincide with that of operands[0] (which is why we made
2083 it TImode). Pick the other one to use as our scratch. */
2084 if (rtx_equal_p (temp, op0))
2085 {
2086 gcc_assert (ti_temp);
2087 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
2088 }
2089 temp1 = op0;
2090 temp2 = temp; /* op0 is _not_ allowed, see above. */
2091 temp3 = op0;
2092 temp4 = op0;
2093 temp5 = op0;
2094 }
2095 else
2096 {
2097 temp1 = gen_reg_rtx (DImode);
2098 temp2 = gen_reg_rtx (DImode);
2099 temp3 = gen_reg_rtx (DImode);
2100 temp4 = gen_reg_rtx (DImode);
2101 temp5 = gen_reg_rtx (DImode);
2102 }
2103
2104 emit_insn (gen_embmedany_textuhi (temp1, op1));
2105 emit_insn (gen_embmedany_texthi (temp2, op1));
2106 emit_insn (gen_embmedany_textulo (temp3, temp1, op1));
2107 emit_insn (gen_rtx_SET (temp4,
2108 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
2109 emit_insn (gen_rtx_SET (temp5, gen_rtx_PLUS (DImode, temp4, temp2)));
2110 emit_insn (gen_embmedany_textlo (op0, temp5, op1));
2111 }
2112 break;
2113
2114 default:
2115 gcc_unreachable ();
2116 }
2117 }
2118
2119 #if HOST_BITS_PER_WIDE_INT == 32
2120 static void
2121 sparc_emit_set_const64 (rtx op0 ATTRIBUTE_UNUSED, rtx op1 ATTRIBUTE_UNUSED)
2122 {
2123 gcc_unreachable ();
2124 }
2125 #else
2126 /* These avoid problems when cross compiling. If we do not
2127 go through all this hair then the optimizer will see
2128 invalid REG_EQUAL notes or in some cases none at all. */
2129 static rtx gen_safe_HIGH64 (rtx, HOST_WIDE_INT);
2130 static rtx gen_safe_SET64 (rtx, HOST_WIDE_INT);
2131 static rtx gen_safe_OR64 (rtx, HOST_WIDE_INT);
2132 static rtx gen_safe_XOR64 (rtx, HOST_WIDE_INT);
2133
2134 /* The optimizer is not to assume anything about exactly
2135 which bits are set for a HIGH, they are unspecified.
2136 Unfortunately this leads to many missed optimizations
2137 during CSE. We mask out the non-HIGH bits, and matches
2138 a plain movdi, to alleviate this problem. */
2139 static rtx
2140 gen_safe_HIGH64 (rtx dest, HOST_WIDE_INT val)
2141 {
2142 return gen_rtx_SET (dest, GEN_INT (val & ~(HOST_WIDE_INT)0x3ff));
2143 }
2144
2145 static rtx
2146 gen_safe_SET64 (rtx dest, HOST_WIDE_INT val)
2147 {
2148 return gen_rtx_SET (dest, GEN_INT (val));
2149 }
2150
2151 static rtx
2152 gen_safe_OR64 (rtx src, HOST_WIDE_INT val)
2153 {
2154 return gen_rtx_IOR (DImode, src, GEN_INT (val));
2155 }
2156
2157 static rtx
2158 gen_safe_XOR64 (rtx src, HOST_WIDE_INT val)
2159 {
2160 return gen_rtx_XOR (DImode, src, GEN_INT (val));
2161 }
2162
2163 /* Worker routines for 64-bit constant formation on arch64.
2164 One of the key things to be doing in these emissions is
2165 to create as many temp REGs as possible. This makes it
2166 possible for half-built constants to be used later when
2167 such values are similar to something required later on.
2168 Without doing this, the optimizer cannot see such
2169 opportunities. */
2170
2171 static void sparc_emit_set_const64_quick1 (rtx, rtx,
2172 unsigned HOST_WIDE_INT, int);
2173
2174 static void
2175 sparc_emit_set_const64_quick1 (rtx op0, rtx temp,
2176 unsigned HOST_WIDE_INT low_bits, int is_neg)
2177 {
2178 unsigned HOST_WIDE_INT high_bits;
2179
2180 if (is_neg)
2181 high_bits = (~low_bits) & 0xffffffff;
2182 else
2183 high_bits = low_bits;
2184
2185 emit_insn (gen_safe_HIGH64 (temp, high_bits));
2186 if (!is_neg)
2187 {
2188 emit_insn (gen_rtx_SET (op0, gen_safe_OR64 (temp, (high_bits & 0x3ff))));
2189 }
2190 else
2191 {
2192 /* If we are XOR'ing with -1, then we should emit a one's complement
2193 instead. This way the combiner will notice logical operations
2194 such as ANDN later on and substitute. */
2195 if ((low_bits & 0x3ff) == 0x3ff)
2196 {
2197 emit_insn (gen_rtx_SET (op0, gen_rtx_NOT (DImode, temp)));
2198 }
2199 else
2200 {
2201 emit_insn (gen_rtx_SET (op0,
2202 gen_safe_XOR64 (temp,
2203 (-(HOST_WIDE_INT)0x400
2204 | (low_bits & 0x3ff)))));
2205 }
2206 }
2207 }
2208
2209 static void sparc_emit_set_const64_quick2 (rtx, rtx, unsigned HOST_WIDE_INT,
2210 unsigned HOST_WIDE_INT, int);
2211
2212 static void
2213 sparc_emit_set_const64_quick2 (rtx op0, rtx temp,
2214 unsigned HOST_WIDE_INT high_bits,
2215 unsigned HOST_WIDE_INT low_immediate,
2216 int shift_count)
2217 {
2218 rtx temp2 = op0;
2219
2220 if ((high_bits & 0xfffffc00) != 0)
2221 {
2222 emit_insn (gen_safe_HIGH64 (temp, high_bits));
2223 if ((high_bits & ~0xfffffc00) != 0)
2224 emit_insn (gen_rtx_SET (op0,
2225 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
2226 else
2227 temp2 = temp;
2228 }
2229 else
2230 {
2231 emit_insn (gen_safe_SET64 (temp, high_bits));
2232 temp2 = temp;
2233 }
2234
2235 /* Now shift it up into place. */
2236 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, temp2,
2237 GEN_INT (shift_count))));
2238
2239 /* If there is a low immediate part piece, finish up by
2240 putting that in as well. */
2241 if (low_immediate != 0)
2242 emit_insn (gen_rtx_SET (op0, gen_safe_OR64 (op0, low_immediate)));
2243 }
2244
2245 static void sparc_emit_set_const64_longway (rtx, rtx, unsigned HOST_WIDE_INT,
2246 unsigned HOST_WIDE_INT);
2247
2248 /* Full 64-bit constant decomposition. Even though this is the
2249 'worst' case, we still optimize a few things away. */
2250 static void
2251 sparc_emit_set_const64_longway (rtx op0, rtx temp,
2252 unsigned HOST_WIDE_INT high_bits,
2253 unsigned HOST_WIDE_INT low_bits)
2254 {
2255 rtx sub_temp = op0;
2256
2257 if (can_create_pseudo_p ())
2258 sub_temp = gen_reg_rtx (DImode);
2259
2260 if ((high_bits & 0xfffffc00) != 0)
2261 {
2262 emit_insn (gen_safe_HIGH64 (temp, high_bits));
2263 if ((high_bits & ~0xfffffc00) != 0)
2264 emit_insn (gen_rtx_SET (sub_temp,
2265 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
2266 else
2267 sub_temp = temp;
2268 }
2269 else
2270 {
2271 emit_insn (gen_safe_SET64 (temp, high_bits));
2272 sub_temp = temp;
2273 }
2274
2275 if (can_create_pseudo_p ())
2276 {
2277 rtx temp2 = gen_reg_rtx (DImode);
2278 rtx temp3 = gen_reg_rtx (DImode);
2279 rtx temp4 = gen_reg_rtx (DImode);
2280
2281 emit_insn (gen_rtx_SET (temp4, gen_rtx_ASHIFT (DImode, sub_temp,
2282 GEN_INT (32))));
2283
2284 emit_insn (gen_safe_HIGH64 (temp2, low_bits));
2285 if ((low_bits & ~0xfffffc00) != 0)
2286 {
2287 emit_insn (gen_rtx_SET (temp3,
2288 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
2289 emit_insn (gen_rtx_SET (op0, gen_rtx_PLUS (DImode, temp4, temp3)));
2290 }
2291 else
2292 {
2293 emit_insn (gen_rtx_SET (op0, gen_rtx_PLUS (DImode, temp4, temp2)));
2294 }
2295 }
2296 else
2297 {
2298 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
2299 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
2300 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
2301 int to_shift = 12;
2302
2303 /* We are in the middle of reload, so this is really
2304 painful. However we do still make an attempt to
2305 avoid emitting truly stupid code. */
2306 if (low1 != const0_rtx)
2307 {
2308 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, sub_temp,
2309 GEN_INT (to_shift))));
2310 emit_insn (gen_rtx_SET (op0, gen_rtx_IOR (DImode, op0, low1)));
2311 sub_temp = op0;
2312 to_shift = 12;
2313 }
2314 else
2315 {
2316 to_shift += 12;
2317 }
2318 if (low2 != const0_rtx)
2319 {
2320 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, sub_temp,
2321 GEN_INT (to_shift))));
2322 emit_insn (gen_rtx_SET (op0, gen_rtx_IOR (DImode, op0, low2)));
2323 sub_temp = op0;
2324 to_shift = 8;
2325 }
2326 else
2327 {
2328 to_shift += 8;
2329 }
2330 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, sub_temp,
2331 GEN_INT (to_shift))));
2332 if (low3 != const0_rtx)
2333 emit_insn (gen_rtx_SET (op0, gen_rtx_IOR (DImode, op0, low3)));
2334 /* phew... */
2335 }
2336 }
2337
2338 /* Analyze a 64-bit constant for certain properties. */
2339 static void analyze_64bit_constant (unsigned HOST_WIDE_INT,
2340 unsigned HOST_WIDE_INT,
2341 int *, int *, int *);
2342
2343 static void
2344 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits,
2345 unsigned HOST_WIDE_INT low_bits,
2346 int *hbsp, int *lbsp, int *abbasp)
2347 {
2348 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
2349 int i;
2350
2351 lowest_bit_set = highest_bit_set = -1;
2352 i = 0;
2353 do
2354 {
2355 if ((lowest_bit_set == -1)
2356 && ((low_bits >> i) & 1))
2357 lowest_bit_set = i;
2358 if ((highest_bit_set == -1)
2359 && ((high_bits >> (32 - i - 1)) & 1))
2360 highest_bit_set = (64 - i - 1);
2361 }
2362 while (++i < 32
2363 && ((highest_bit_set == -1)
2364 || (lowest_bit_set == -1)));
2365 if (i == 32)
2366 {
2367 i = 0;
2368 do
2369 {
2370 if ((lowest_bit_set == -1)
2371 && ((high_bits >> i) & 1))
2372 lowest_bit_set = i + 32;
2373 if ((highest_bit_set == -1)
2374 && ((low_bits >> (32 - i - 1)) & 1))
2375 highest_bit_set = 32 - i - 1;
2376 }
2377 while (++i < 32
2378 && ((highest_bit_set == -1)
2379 || (lowest_bit_set == -1)));
2380 }
2381 /* If there are no bits set this should have gone out
2382 as one instruction! */
2383 gcc_assert (lowest_bit_set != -1 && highest_bit_set != -1);
2384 all_bits_between_are_set = 1;
2385 for (i = lowest_bit_set; i <= highest_bit_set; i++)
2386 {
2387 if (i < 32)
2388 {
2389 if ((low_bits & (1 << i)) != 0)
2390 continue;
2391 }
2392 else
2393 {
2394 if ((high_bits & (1 << (i - 32))) != 0)
2395 continue;
2396 }
2397 all_bits_between_are_set = 0;
2398 break;
2399 }
2400 *hbsp = highest_bit_set;
2401 *lbsp = lowest_bit_set;
2402 *abbasp = all_bits_between_are_set;
2403 }
2404
2405 static int const64_is_2insns (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2406
2407 static int
2408 const64_is_2insns (unsigned HOST_WIDE_INT high_bits,
2409 unsigned HOST_WIDE_INT low_bits)
2410 {
2411 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
2412
2413 if (high_bits == 0
2414 || high_bits == 0xffffffff)
2415 return 1;
2416
2417 analyze_64bit_constant (high_bits, low_bits,
2418 &highest_bit_set, &lowest_bit_set,
2419 &all_bits_between_are_set);
2420
2421 if ((highest_bit_set == 63
2422 || lowest_bit_set == 0)
2423 && all_bits_between_are_set != 0)
2424 return 1;
2425
2426 if ((highest_bit_set - lowest_bit_set) < 21)
2427 return 1;
2428
2429 return 0;
2430 }
2431
2432 static unsigned HOST_WIDE_INT create_simple_focus_bits (unsigned HOST_WIDE_INT,
2433 unsigned HOST_WIDE_INT,
2434 int, int);
2435
2436 static unsigned HOST_WIDE_INT
2437 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits,
2438 unsigned HOST_WIDE_INT low_bits,
2439 int lowest_bit_set, int shift)
2440 {
2441 HOST_WIDE_INT hi, lo;
2442
2443 if (lowest_bit_set < 32)
2444 {
2445 lo = (low_bits >> lowest_bit_set) << shift;
2446 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
2447 }
2448 else
2449 {
2450 lo = 0;
2451 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
2452 }
2453 gcc_assert (! (hi & lo));
2454 return (hi | lo);
2455 }
2456
2457 /* Here we are sure to be arch64 and this is an integer constant
2458 being loaded into a register. Emit the most efficient
2459 insn sequence possible. Detection of all the 1-insn cases
2460 has been done already. */
2461 static void
2462 sparc_emit_set_const64 (rtx op0, rtx op1)
2463 {
2464 unsigned HOST_WIDE_INT high_bits, low_bits;
2465 int lowest_bit_set, highest_bit_set;
2466 int all_bits_between_are_set;
2467 rtx temp = 0;
2468
2469 /* Sanity check that we know what we are working with. */
2470 gcc_assert (TARGET_ARCH64
2471 && (GET_CODE (op0) == SUBREG
2472 || (REG_P (op0) && ! SPARC_FP_REG_P (REGNO (op0)))));
2473
2474 if (! can_create_pseudo_p ())
2475 temp = op0;
2476
2477 if (GET_CODE (op1) != CONST_INT)
2478 {
2479 sparc_emit_set_symbolic_const64 (op0, op1, temp);
2480 return;
2481 }
2482
2483 if (! temp)
2484 temp = gen_reg_rtx (DImode);
2485
2486 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
2487 low_bits = (INTVAL (op1) & 0xffffffff);
2488
2489 /* low_bits bits 0 --> 31
2490 high_bits bits 32 --> 63 */
2491
2492 analyze_64bit_constant (high_bits, low_bits,
2493 &highest_bit_set, &lowest_bit_set,
2494 &all_bits_between_are_set);
2495
2496 /* First try for a 2-insn sequence. */
2497
2498 /* These situations are preferred because the optimizer can
2499 * do more things with them:
2500 * 1) mov -1, %reg
2501 * sllx %reg, shift, %reg
2502 * 2) mov -1, %reg
2503 * srlx %reg, shift, %reg
2504 * 3) mov some_small_const, %reg
2505 * sllx %reg, shift, %reg
2506 */
2507 if (((highest_bit_set == 63
2508 || lowest_bit_set == 0)
2509 && all_bits_between_are_set != 0)
2510 || ((highest_bit_set - lowest_bit_set) < 12))
2511 {
2512 HOST_WIDE_INT the_const = -1;
2513 int shift = lowest_bit_set;
2514
2515 if ((highest_bit_set != 63
2516 && lowest_bit_set != 0)
2517 || all_bits_between_are_set == 0)
2518 {
2519 the_const =
2520 create_simple_focus_bits (high_bits, low_bits,
2521 lowest_bit_set, 0);
2522 }
2523 else if (lowest_bit_set == 0)
2524 shift = -(63 - highest_bit_set);
2525
2526 gcc_assert (SPARC_SIMM13_P (the_const));
2527 gcc_assert (shift != 0);
2528
2529 emit_insn (gen_safe_SET64 (temp, the_const));
2530 if (shift > 0)
2531 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, temp,
2532 GEN_INT (shift))));
2533 else if (shift < 0)
2534 emit_insn (gen_rtx_SET (op0, gen_rtx_LSHIFTRT (DImode, temp,
2535 GEN_INT (-shift))));
2536 return;
2537 }
2538
2539 /* Now a range of 22 or less bits set somewhere.
2540 * 1) sethi %hi(focus_bits), %reg
2541 * sllx %reg, shift, %reg
2542 * 2) sethi %hi(focus_bits), %reg
2543 * srlx %reg, shift, %reg
2544 */
2545 if ((highest_bit_set - lowest_bit_set) < 21)
2546 {
2547 unsigned HOST_WIDE_INT focus_bits =
2548 create_simple_focus_bits (high_bits, low_bits,
2549 lowest_bit_set, 10);
2550
2551 gcc_assert (SPARC_SETHI_P (focus_bits));
2552 gcc_assert (lowest_bit_set != 10);
2553
2554 emit_insn (gen_safe_HIGH64 (temp, focus_bits));
2555
2556 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
2557 if (lowest_bit_set < 10)
2558 emit_insn (gen_rtx_SET (op0,
2559 gen_rtx_LSHIFTRT (DImode, temp,
2560 GEN_INT (10 - lowest_bit_set))));
2561 else if (lowest_bit_set > 10)
2562 emit_insn (gen_rtx_SET (op0,
2563 gen_rtx_ASHIFT (DImode, temp,
2564 GEN_INT (lowest_bit_set - 10))));
2565 return;
2566 }
2567
2568 /* 1) sethi %hi(low_bits), %reg
2569 * or %reg, %lo(low_bits), %reg
2570 * 2) sethi %hi(~low_bits), %reg
2571 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
2572 */
2573 if (high_bits == 0
2574 || high_bits == 0xffffffff)
2575 {
2576 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
2577 (high_bits == 0xffffffff));
2578 return;
2579 }
2580
2581 /* Now, try 3-insn sequences. */
2582
2583 /* 1) sethi %hi(high_bits), %reg
2584 * or %reg, %lo(high_bits), %reg
2585 * sllx %reg, 32, %reg
2586 */
2587 if (low_bits == 0)
2588 {
2589 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
2590 return;
2591 }
2592
2593 /* We may be able to do something quick
2594 when the constant is negated, so try that. */
2595 if (const64_is_2insns ((~high_bits) & 0xffffffff,
2596 (~low_bits) & 0xfffffc00))
2597 {
2598 /* NOTE: The trailing bits get XOR'd so we need the
2599 non-negated bits, not the negated ones. */
2600 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
2601
2602 if ((((~high_bits) & 0xffffffff) == 0
2603 && ((~low_bits) & 0x80000000) == 0)
2604 || (((~high_bits) & 0xffffffff) == 0xffffffff
2605 && ((~low_bits) & 0x80000000) != 0))
2606 {
2607 unsigned HOST_WIDE_INT fast_int = (~low_bits & 0xffffffff);
2608
2609 if ((SPARC_SETHI_P (fast_int)
2610 && (~high_bits & 0xffffffff) == 0)
2611 || SPARC_SIMM13_P (fast_int))
2612 emit_insn (gen_safe_SET64 (temp, fast_int));
2613 else
2614 sparc_emit_set_const64 (temp, GEN_INT (fast_int));
2615 }
2616 else
2617 {
2618 rtx negated_const;
2619 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2620 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2621 sparc_emit_set_const64 (temp, negated_const);
2622 }
2623
2624 /* If we are XOR'ing with -1, then we should emit a one's complement
2625 instead. This way the combiner will notice logical operations
2626 such as ANDN later on and substitute. */
2627 if (trailing_bits == 0x3ff)
2628 {
2629 emit_insn (gen_rtx_SET (op0, gen_rtx_NOT (DImode, temp)));
2630 }
2631 else
2632 {
2633 emit_insn (gen_rtx_SET (op0,
2634 gen_safe_XOR64 (temp,
2635 (-0x400 | trailing_bits))));
2636 }
2637 return;
2638 }
2639
2640 /* 1) sethi %hi(xxx), %reg
2641 * or %reg, %lo(xxx), %reg
2642 * sllx %reg, yyy, %reg
2643 *
2644 * ??? This is just a generalized version of the low_bits==0
2645 * thing above, FIXME...
2646 */
2647 if ((highest_bit_set - lowest_bit_set) < 32)
2648 {
2649 unsigned HOST_WIDE_INT focus_bits =
2650 create_simple_focus_bits (high_bits, low_bits,
2651 lowest_bit_set, 0);
2652
2653 /* We can't get here in this state. */
2654 gcc_assert (highest_bit_set >= 32 && lowest_bit_set < 32);
2655
2656 /* So what we know is that the set bits straddle the
2657 middle of the 64-bit word. */
2658 sparc_emit_set_const64_quick2 (op0, temp,
2659 focus_bits, 0,
2660 lowest_bit_set);
2661 return;
2662 }
2663
2664 /* 1) sethi %hi(high_bits), %reg
2665 * or %reg, %lo(high_bits), %reg
2666 * sllx %reg, 32, %reg
2667 * or %reg, low_bits, %reg
2668 */
2669 if (SPARC_SIMM13_P(low_bits)
2670 && ((int)low_bits > 0))
2671 {
2672 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2673 return;
2674 }
2675
2676 /* The easiest way when all else fails, is full decomposition. */
2677 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2678 }
2679 #endif /* HOST_BITS_PER_WIDE_INT == 32 */
2680
2681 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2682 return the mode to be used for the comparison. For floating-point,
2683 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2684 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2685 processing is needed. */
2686
2687 machine_mode
2688 select_cc_mode (enum rtx_code op, rtx x, rtx y ATTRIBUTE_UNUSED)
2689 {
2690 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2691 {
2692 switch (op)
2693 {
2694 case EQ:
2695 case NE:
2696 case UNORDERED:
2697 case ORDERED:
2698 case UNLT:
2699 case UNLE:
2700 case UNGT:
2701 case UNGE:
2702 case UNEQ:
2703 case LTGT:
2704 return CCFPmode;
2705
2706 case LT:
2707 case LE:
2708 case GT:
2709 case GE:
2710 return CCFPEmode;
2711
2712 default:
2713 gcc_unreachable ();
2714 }
2715 }
2716 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2717 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2718 {
2719 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2720 return CCX_NOOVmode;
2721 else
2722 return CC_NOOVmode;
2723 }
2724 else
2725 {
2726 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2727 return CCXmode;
2728 else
2729 return CCmode;
2730 }
2731 }
2732
2733 /* Emit the compare insn and return the CC reg for a CODE comparison
2734 with operands X and Y. */
2735
2736 static rtx
2737 gen_compare_reg_1 (enum rtx_code code, rtx x, rtx y)
2738 {
2739 machine_mode mode;
2740 rtx cc_reg;
2741
2742 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
2743 return x;
2744
2745 mode = SELECT_CC_MODE (code, x, y);
2746
2747 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2748 fcc regs (cse can't tell they're really call clobbered regs and will
2749 remove a duplicate comparison even if there is an intervening function
2750 call - it will then try to reload the cc reg via an int reg which is why
2751 we need the movcc patterns). It is possible to provide the movcc
2752 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2753 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2754 to tell cse that CCFPE mode registers (even pseudos) are call
2755 clobbered. */
2756
2757 /* ??? This is an experiment. Rather than making changes to cse which may
2758 or may not be easy/clean, we do our own cse. This is possible because
2759 we will generate hard registers. Cse knows they're call clobbered (it
2760 doesn't know the same thing about pseudos). If we guess wrong, no big
2761 deal, but if we win, great! */
2762
2763 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2764 #if 1 /* experiment */
2765 {
2766 int reg;
2767 /* We cycle through the registers to ensure they're all exercised. */
2768 static int next_fcc_reg = 0;
2769 /* Previous x,y for each fcc reg. */
2770 static rtx prev_args[4][2];
2771
2772 /* Scan prev_args for x,y. */
2773 for (reg = 0; reg < 4; reg++)
2774 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2775 break;
2776 if (reg == 4)
2777 {
2778 reg = next_fcc_reg;
2779 prev_args[reg][0] = x;
2780 prev_args[reg][1] = y;
2781 next_fcc_reg = (next_fcc_reg + 1) & 3;
2782 }
2783 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2784 }
2785 #else
2786 cc_reg = gen_reg_rtx (mode);
2787 #endif /* ! experiment */
2788 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2789 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2790 else
2791 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2792
2793 /* We shouldn't get there for TFmode if !TARGET_HARD_QUAD. If we do, this
2794 will only result in an unrecognizable insn so no point in asserting. */
2795 emit_insn (gen_rtx_SET (cc_reg, gen_rtx_COMPARE (mode, x, y)));
2796
2797 return cc_reg;
2798 }
2799
2800
2801 /* Emit the compare insn and return the CC reg for the comparison in CMP. */
2802
2803 rtx
2804 gen_compare_reg (rtx cmp)
2805 {
2806 return gen_compare_reg_1 (GET_CODE (cmp), XEXP (cmp, 0), XEXP (cmp, 1));
2807 }
2808
2809 /* This function is used for v9 only.
2810 DEST is the target of the Scc insn.
2811 CODE is the code for an Scc's comparison.
2812 X and Y are the values we compare.
2813
2814 This function is needed to turn
2815
2816 (set (reg:SI 110)
2817 (gt (reg:CCX 100 %icc)
2818 (const_int 0)))
2819 into
2820 (set (reg:SI 110)
2821 (gt:DI (reg:CCX 100 %icc)
2822 (const_int 0)))
2823
2824 IE: The instruction recognizer needs to see the mode of the comparison to
2825 find the right instruction. We could use "gt:DI" right in the
2826 define_expand, but leaving it out allows us to handle DI, SI, etc. */
2827
2828 static int
2829 gen_v9_scc (rtx dest, enum rtx_code compare_code, rtx x, rtx y)
2830 {
2831 if (! TARGET_ARCH64
2832 && (GET_MODE (x) == DImode
2833 || GET_MODE (dest) == DImode))
2834 return 0;
2835
2836 /* Try to use the movrCC insns. */
2837 if (TARGET_ARCH64
2838 && GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2839 && y == const0_rtx
2840 && v9_regcmp_p (compare_code))
2841 {
2842 rtx op0 = x;
2843 rtx temp;
2844
2845 /* Special case for op0 != 0. This can be done with one instruction if
2846 dest == x. */
2847
2848 if (compare_code == NE
2849 && GET_MODE (dest) == DImode
2850 && rtx_equal_p (op0, dest))
2851 {
2852 emit_insn (gen_rtx_SET (dest,
2853 gen_rtx_IF_THEN_ELSE (DImode,
2854 gen_rtx_fmt_ee (compare_code, DImode,
2855 op0, const0_rtx),
2856 const1_rtx,
2857 dest)));
2858 return 1;
2859 }
2860
2861 if (reg_overlap_mentioned_p (dest, op0))
2862 {
2863 /* Handle the case where dest == x.
2864 We "early clobber" the result. */
2865 op0 = gen_reg_rtx (GET_MODE (x));
2866 emit_move_insn (op0, x);
2867 }
2868
2869 emit_insn (gen_rtx_SET (dest, const0_rtx));
2870 if (GET_MODE (op0) != DImode)
2871 {
2872 temp = gen_reg_rtx (DImode);
2873 convert_move (temp, op0, 0);
2874 }
2875 else
2876 temp = op0;
2877 emit_insn (gen_rtx_SET (dest,
2878 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2879 gen_rtx_fmt_ee (compare_code, DImode,
2880 temp, const0_rtx),
2881 const1_rtx,
2882 dest)));
2883 return 1;
2884 }
2885 else
2886 {
2887 x = gen_compare_reg_1 (compare_code, x, y);
2888 y = const0_rtx;
2889
2890 gcc_assert (GET_MODE (x) != CC_NOOVmode
2891 && GET_MODE (x) != CCX_NOOVmode);
2892
2893 emit_insn (gen_rtx_SET (dest, const0_rtx));
2894 emit_insn (gen_rtx_SET (dest,
2895 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2896 gen_rtx_fmt_ee (compare_code,
2897 GET_MODE (x), x, y),
2898 const1_rtx, dest)));
2899 return 1;
2900 }
2901 }
2902
2903
2904 /* Emit an scc insn. For seq, sne, sgeu, and sltu, we can do this
2905 without jumps using the addx/subx instructions. */
2906
2907 bool
2908 emit_scc_insn (rtx operands[])
2909 {
2910 rtx tem;
2911 rtx x;
2912 rtx y;
2913 enum rtx_code code;
2914
2915 /* The quad-word fp compare library routines all return nonzero to indicate
2916 true, which is different from the equivalent libgcc routines, so we must
2917 handle them specially here. */
2918 if (GET_MODE (operands[2]) == TFmode && ! TARGET_HARD_QUAD)
2919 {
2920 operands[1] = sparc_emit_float_lib_cmp (operands[2], operands[3],
2921 GET_CODE (operands[1]));
2922 operands[2] = XEXP (operands[1], 0);
2923 operands[3] = XEXP (operands[1], 1);
2924 }
2925
2926 code = GET_CODE (operands[1]);
2927 x = operands[2];
2928 y = operands[3];
2929
2930 /* For seq/sne on v9 we use the same code as v8 (the addx/subx method has
2931 more applications). The exception to this is "reg != 0" which can
2932 be done in one instruction on v9 (so we do it). */
2933 if (code == EQ)
2934 {
2935 if (GET_MODE (x) == SImode)
2936 {
2937 rtx pat;
2938 if (TARGET_ARCH64)
2939 pat = gen_seqsidi_special (operands[0], x, y);
2940 else
2941 pat = gen_seqsisi_special (operands[0], x, y);
2942 emit_insn (pat);
2943 return true;
2944 }
2945 else if (GET_MODE (x) == DImode)
2946 {
2947 rtx pat = gen_seqdi_special (operands[0], x, y);
2948 emit_insn (pat);
2949 return true;
2950 }
2951 }
2952
2953 if (code == NE)
2954 {
2955 if (GET_MODE (x) == SImode)
2956 {
2957 rtx pat;
2958 if (TARGET_ARCH64)
2959 pat = gen_snesidi_special (operands[0], x, y);
2960 else
2961 pat = gen_snesisi_special (operands[0], x, y);
2962 emit_insn (pat);
2963 return true;
2964 }
2965 else if (GET_MODE (x) == DImode)
2966 {
2967 rtx pat;
2968 if (TARGET_VIS3)
2969 pat = gen_snedi_special_vis3 (operands[0], x, y);
2970 else
2971 pat = gen_snedi_special (operands[0], x, y);
2972 emit_insn (pat);
2973 return true;
2974 }
2975 }
2976
2977 if (TARGET_V9
2978 && TARGET_ARCH64
2979 && GET_MODE (x) == DImode
2980 && !(TARGET_VIS3
2981 && (code == GTU || code == LTU))
2982 && gen_v9_scc (operands[0], code, x, y))
2983 return true;
2984
2985 /* We can do LTU and GEU using the addx/subx instructions too. And
2986 for GTU/LEU, if both operands are registers swap them and fall
2987 back to the easy case. */
2988 if (code == GTU || code == LEU)
2989 {
2990 if ((GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
2991 && (GET_CODE (y) == REG || GET_CODE (y) == SUBREG))
2992 {
2993 tem = x;
2994 x = y;
2995 y = tem;
2996 code = swap_condition (code);
2997 }
2998 }
2999
3000 if (code == LTU
3001 || (!TARGET_VIS3 && code == GEU))
3002 {
3003 emit_insn (gen_rtx_SET (operands[0],
3004 gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
3005 gen_compare_reg_1 (code, x, y),
3006 const0_rtx)));
3007 return true;
3008 }
3009
3010 /* All the posibilities to use addx/subx based sequences has been
3011 exhausted, try for a 3 instruction sequence using v9 conditional
3012 moves. */
3013 if (TARGET_V9 && gen_v9_scc (operands[0], code, x, y))
3014 return true;
3015
3016 /* Nope, do branches. */
3017 return false;
3018 }
3019
3020 /* Emit a conditional jump insn for the v9 architecture using comparison code
3021 CODE and jump target LABEL.
3022 This function exists to take advantage of the v9 brxx insns. */
3023
3024 static void
3025 emit_v9_brxx_insn (enum rtx_code code, rtx op0, rtx label)
3026 {
3027 emit_jump_insn (gen_rtx_SET (pc_rtx,
3028 gen_rtx_IF_THEN_ELSE (VOIDmode,
3029 gen_rtx_fmt_ee (code, GET_MODE (op0),
3030 op0, const0_rtx),
3031 gen_rtx_LABEL_REF (VOIDmode, label),
3032 pc_rtx)));
3033 }
3034
3035 /* Emit a conditional jump insn for the UA2011 architecture using
3036 comparison code CODE and jump target LABEL. This function exists
3037 to take advantage of the UA2011 Compare and Branch insns. */
3038
3039 static void
3040 emit_cbcond_insn (enum rtx_code code, rtx op0, rtx op1, rtx label)
3041 {
3042 rtx if_then_else;
3043
3044 if_then_else = gen_rtx_IF_THEN_ELSE (VOIDmode,
3045 gen_rtx_fmt_ee(code, GET_MODE(op0),
3046 op0, op1),
3047 gen_rtx_LABEL_REF (VOIDmode, label),
3048 pc_rtx);
3049
3050 emit_jump_insn (gen_rtx_SET (pc_rtx, if_then_else));
3051 }
3052
3053 void
3054 emit_conditional_branch_insn (rtx operands[])
3055 {
3056 /* The quad-word fp compare library routines all return nonzero to indicate
3057 true, which is different from the equivalent libgcc routines, so we must
3058 handle them specially here. */
3059 if (GET_MODE (operands[1]) == TFmode && ! TARGET_HARD_QUAD)
3060 {
3061 operands[0] = sparc_emit_float_lib_cmp (operands[1], operands[2],
3062 GET_CODE (operands[0]));
3063 operands[1] = XEXP (operands[0], 0);
3064 operands[2] = XEXP (operands[0], 1);
3065 }
3066
3067 /* If we can tell early on that the comparison is against a constant
3068 that won't fit in the 5-bit signed immediate field of a cbcond,
3069 use one of the other v9 conditional branch sequences. */
3070 if (TARGET_CBCOND
3071 && GET_CODE (operands[1]) == REG
3072 && (GET_MODE (operands[1]) == SImode
3073 || (TARGET_ARCH64 && GET_MODE (operands[1]) == DImode))
3074 && (GET_CODE (operands[2]) != CONST_INT
3075 || SPARC_SIMM5_P (INTVAL (operands[2]))))
3076 {
3077 emit_cbcond_insn (GET_CODE (operands[0]), operands[1], operands[2], operands[3]);
3078 return;
3079 }
3080
3081 if (TARGET_ARCH64 && operands[2] == const0_rtx
3082 && GET_CODE (operands[1]) == REG
3083 && GET_MODE (operands[1]) == DImode)
3084 {
3085 emit_v9_brxx_insn (GET_CODE (operands[0]), operands[1], operands[3]);
3086 return;
3087 }
3088
3089 operands[1] = gen_compare_reg (operands[0]);
3090 operands[2] = const0_rtx;
3091 operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]), VOIDmode,
3092 operands[1], operands[2]);
3093 emit_jump_insn (gen_cbranchcc4 (operands[0], operands[1], operands[2],
3094 operands[3]));
3095 }
3096
3097
3098 /* Generate a DFmode part of a hard TFmode register.
3099 REG is the TFmode hard register, LOW is 1 for the
3100 low 64bit of the register and 0 otherwise.
3101 */
3102 rtx
3103 gen_df_reg (rtx reg, int low)
3104 {
3105 int regno = REGNO (reg);
3106
3107 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
3108 regno += (TARGET_ARCH64 && SPARC_INT_REG_P (regno)) ? 1 : 2;
3109 return gen_rtx_REG (DFmode, regno);
3110 }
3111 \f
3112 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
3113 Unlike normal calls, TFmode operands are passed by reference. It is
3114 assumed that no more than 3 operands are required. */
3115
3116 static void
3117 emit_soft_tfmode_libcall (const char *func_name, int nargs, rtx *operands)
3118 {
3119 rtx ret_slot = NULL, arg[3], func_sym;
3120 int i;
3121
3122 /* We only expect to be called for conversions, unary, and binary ops. */
3123 gcc_assert (nargs == 2 || nargs == 3);
3124
3125 for (i = 0; i < nargs; ++i)
3126 {
3127 rtx this_arg = operands[i];
3128 rtx this_slot;
3129
3130 /* TFmode arguments and return values are passed by reference. */
3131 if (GET_MODE (this_arg) == TFmode)
3132 {
3133 int force_stack_temp;
3134
3135 force_stack_temp = 0;
3136 if (TARGET_BUGGY_QP_LIB && i == 0)
3137 force_stack_temp = 1;
3138
3139 if (GET_CODE (this_arg) == MEM
3140 && ! force_stack_temp)
3141 {
3142 tree expr = MEM_EXPR (this_arg);
3143 if (expr)
3144 mark_addressable (expr);
3145 this_arg = XEXP (this_arg, 0);
3146 }
3147 else if (CONSTANT_P (this_arg)
3148 && ! force_stack_temp)
3149 {
3150 this_slot = force_const_mem (TFmode, this_arg);
3151 this_arg = XEXP (this_slot, 0);
3152 }
3153 else
3154 {
3155 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode));
3156
3157 /* Operand 0 is the return value. We'll copy it out later. */
3158 if (i > 0)
3159 emit_move_insn (this_slot, this_arg);
3160 else
3161 ret_slot = this_slot;
3162
3163 this_arg = XEXP (this_slot, 0);
3164 }
3165 }
3166
3167 arg[i] = this_arg;
3168 }
3169
3170 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
3171
3172 if (GET_MODE (operands[0]) == TFmode)
3173 {
3174 if (nargs == 2)
3175 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
3176 arg[0], GET_MODE (arg[0]),
3177 arg[1], GET_MODE (arg[1]));
3178 else
3179 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
3180 arg[0], GET_MODE (arg[0]),
3181 arg[1], GET_MODE (arg[1]),
3182 arg[2], GET_MODE (arg[2]));
3183
3184 if (ret_slot)
3185 emit_move_insn (operands[0], ret_slot);
3186 }
3187 else
3188 {
3189 rtx ret;
3190
3191 gcc_assert (nargs == 2);
3192
3193 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
3194 GET_MODE (operands[0]), 1,
3195 arg[1], GET_MODE (arg[1]));
3196
3197 if (ret != operands[0])
3198 emit_move_insn (operands[0], ret);
3199 }
3200 }
3201
3202 /* Expand soft-float TFmode calls to sparc abi routines. */
3203
3204 static void
3205 emit_soft_tfmode_binop (enum rtx_code code, rtx *operands)
3206 {
3207 const char *func;
3208
3209 switch (code)
3210 {
3211 case PLUS:
3212 func = "_Qp_add";
3213 break;
3214 case MINUS:
3215 func = "_Qp_sub";
3216 break;
3217 case MULT:
3218 func = "_Qp_mul";
3219 break;
3220 case DIV:
3221 func = "_Qp_div";
3222 break;
3223 default:
3224 gcc_unreachable ();
3225 }
3226
3227 emit_soft_tfmode_libcall (func, 3, operands);
3228 }
3229
3230 static void
3231 emit_soft_tfmode_unop (enum rtx_code code, rtx *operands)
3232 {
3233 const char *func;
3234
3235 gcc_assert (code == SQRT);
3236 func = "_Qp_sqrt";
3237
3238 emit_soft_tfmode_libcall (func, 2, operands);
3239 }
3240
3241 static void
3242 emit_soft_tfmode_cvt (enum rtx_code code, rtx *operands)
3243 {
3244 const char *func;
3245
3246 switch (code)
3247 {
3248 case FLOAT_EXTEND:
3249 switch (GET_MODE (operands[1]))
3250 {
3251 case SFmode:
3252 func = "_Qp_stoq";
3253 break;
3254 case DFmode:
3255 func = "_Qp_dtoq";
3256 break;
3257 default:
3258 gcc_unreachable ();
3259 }
3260 break;
3261
3262 case FLOAT_TRUNCATE:
3263 switch (GET_MODE (operands[0]))
3264 {
3265 case SFmode:
3266 func = "_Qp_qtos";
3267 break;
3268 case DFmode:
3269 func = "_Qp_qtod";
3270 break;
3271 default:
3272 gcc_unreachable ();
3273 }
3274 break;
3275
3276 case FLOAT:
3277 switch (GET_MODE (operands[1]))
3278 {
3279 case SImode:
3280 func = "_Qp_itoq";
3281 if (TARGET_ARCH64)
3282 operands[1] = gen_rtx_SIGN_EXTEND (DImode, operands[1]);
3283 break;
3284 case DImode:
3285 func = "_Qp_xtoq";
3286 break;
3287 default:
3288 gcc_unreachable ();
3289 }
3290 break;
3291
3292 case UNSIGNED_FLOAT:
3293 switch (GET_MODE (operands[1]))
3294 {
3295 case SImode:
3296 func = "_Qp_uitoq";
3297 if (TARGET_ARCH64)
3298 operands[1] = gen_rtx_ZERO_EXTEND (DImode, operands[1]);
3299 break;
3300 case DImode:
3301 func = "_Qp_uxtoq";
3302 break;
3303 default:
3304 gcc_unreachable ();
3305 }
3306 break;
3307
3308 case FIX:
3309 switch (GET_MODE (operands[0]))
3310 {
3311 case SImode:
3312 func = "_Qp_qtoi";
3313 break;
3314 case DImode:
3315 func = "_Qp_qtox";
3316 break;
3317 default:
3318 gcc_unreachable ();
3319 }
3320 break;
3321
3322 case UNSIGNED_FIX:
3323 switch (GET_MODE (operands[0]))
3324 {
3325 case SImode:
3326 func = "_Qp_qtoui";
3327 break;
3328 case DImode:
3329 func = "_Qp_qtoux";
3330 break;
3331 default:
3332 gcc_unreachable ();
3333 }
3334 break;
3335
3336 default:
3337 gcc_unreachable ();
3338 }
3339
3340 emit_soft_tfmode_libcall (func, 2, operands);
3341 }
3342
3343 /* Expand a hard-float tfmode operation. All arguments must be in
3344 registers. */
3345
3346 static void
3347 emit_hard_tfmode_operation (enum rtx_code code, rtx *operands)
3348 {
3349 rtx op, dest;
3350
3351 if (GET_RTX_CLASS (code) == RTX_UNARY)
3352 {
3353 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
3354 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
3355 }
3356 else
3357 {
3358 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
3359 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
3360 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
3361 operands[1], operands[2]);
3362 }
3363
3364 if (register_operand (operands[0], VOIDmode))
3365 dest = operands[0];
3366 else
3367 dest = gen_reg_rtx (GET_MODE (operands[0]));
3368
3369 emit_insn (gen_rtx_SET (dest, op));
3370
3371 if (dest != operands[0])
3372 emit_move_insn (operands[0], dest);
3373 }
3374
3375 void
3376 emit_tfmode_binop (enum rtx_code code, rtx *operands)
3377 {
3378 if (TARGET_HARD_QUAD)
3379 emit_hard_tfmode_operation (code, operands);
3380 else
3381 emit_soft_tfmode_binop (code, operands);
3382 }
3383
3384 void
3385 emit_tfmode_unop (enum rtx_code code, rtx *operands)
3386 {
3387 if (TARGET_HARD_QUAD)
3388 emit_hard_tfmode_operation (code, operands);
3389 else
3390 emit_soft_tfmode_unop (code, operands);
3391 }
3392
3393 void
3394 emit_tfmode_cvt (enum rtx_code code, rtx *operands)
3395 {
3396 if (TARGET_HARD_QUAD)
3397 emit_hard_tfmode_operation (code, operands);
3398 else
3399 emit_soft_tfmode_cvt (code, operands);
3400 }
3401 \f
3402 /* Return nonzero if a branch/jump/call instruction will be emitting
3403 nop into its delay slot. */
3404
3405 int
3406 empty_delay_slot (rtx_insn *insn)
3407 {
3408 rtx seq;
3409
3410 /* If no previous instruction (should not happen), return true. */
3411 if (PREV_INSN (insn) == NULL)
3412 return 1;
3413
3414 seq = NEXT_INSN (PREV_INSN (insn));
3415 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
3416 return 0;
3417
3418 return 1;
3419 }
3420
3421 /* Return nonzero if we should emit a nop after a cbcond instruction.
3422 The cbcond instruction does not have a delay slot, however there is
3423 a severe performance penalty if a control transfer appears right
3424 after a cbcond. Therefore we emit a nop when we detect this
3425 situation. */
3426
3427 int
3428 emit_cbcond_nop (rtx insn)
3429 {
3430 rtx next = next_active_insn (insn);
3431
3432 if (!next)
3433 return 1;
3434
3435 if (NONJUMP_INSN_P (next)
3436 && GET_CODE (PATTERN (next)) == SEQUENCE)
3437 next = XVECEXP (PATTERN (next), 0, 0);
3438 else if (CALL_P (next)
3439 && GET_CODE (PATTERN (next)) == PARALLEL)
3440 {
3441 rtx delay = XVECEXP (PATTERN (next), 0, 1);
3442
3443 if (GET_CODE (delay) == RETURN)
3444 {
3445 /* It's a sibling call. Do not emit the nop if we're going
3446 to emit something other than the jump itself as the first
3447 instruction of the sibcall sequence. */
3448 if (sparc_leaf_function_p || TARGET_FLAT)
3449 return 0;
3450 }
3451 }
3452
3453 if (NONJUMP_INSN_P (next))
3454 return 0;
3455
3456 return 1;
3457 }
3458
3459 /* Return nonzero if TRIAL can go into the call delay slot. */
3460
3461 int
3462 eligible_for_call_delay (rtx_insn *trial)
3463 {
3464 rtx pat;
3465
3466 if (get_attr_in_branch_delay (trial) == IN_BRANCH_DELAY_FALSE)
3467 return 0;
3468
3469 /* Binutils allows
3470 call __tls_get_addr, %tgd_call (foo)
3471 add %l7, %o0, %o0, %tgd_add (foo)
3472 while Sun as/ld does not. */
3473 if (TARGET_GNU_TLS || !TARGET_TLS)
3474 return 1;
3475
3476 pat = PATTERN (trial);
3477
3478 /* We must reject tgd_add{32|64}, i.e.
3479 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSGD)))
3480 and tldm_add{32|64}, i.e.
3481 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSLDM)))
3482 for Sun as/ld. */
3483 if (GET_CODE (pat) == SET
3484 && GET_CODE (SET_SRC (pat)) == PLUS)
3485 {
3486 rtx unspec = XEXP (SET_SRC (pat), 1);
3487
3488 if (GET_CODE (unspec) == UNSPEC
3489 && (XINT (unspec, 1) == UNSPEC_TLSGD
3490 || XINT (unspec, 1) == UNSPEC_TLSLDM))
3491 return 0;
3492 }
3493
3494 return 1;
3495 }
3496
3497 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
3498 instruction. RETURN_P is true if the v9 variant 'return' is to be
3499 considered in the test too.
3500
3501 TRIAL must be a SET whose destination is a REG appropriate for the
3502 'restore' instruction or, if RETURN_P is true, for the 'return'
3503 instruction. */
3504
3505 static int
3506 eligible_for_restore_insn (rtx trial, bool return_p)
3507 {
3508 rtx pat = PATTERN (trial);
3509 rtx src = SET_SRC (pat);
3510 bool src_is_freg = false;
3511 rtx src_reg;
3512
3513 /* Since we now can do moves between float and integer registers when
3514 VIS3 is enabled, we have to catch this case. We can allow such
3515 moves when doing a 'return' however. */
3516 src_reg = src;
3517 if (GET_CODE (src_reg) == SUBREG)
3518 src_reg = SUBREG_REG (src_reg);
3519 if (GET_CODE (src_reg) == REG
3520 && SPARC_FP_REG_P (REGNO (src_reg)))
3521 src_is_freg = true;
3522
3523 /* The 'restore src,%g0,dest' pattern for word mode and below. */
3524 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3525 && arith_operand (src, GET_MODE (src))
3526 && ! src_is_freg)
3527 {
3528 if (TARGET_ARCH64)
3529 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3530 else
3531 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
3532 }
3533
3534 /* The 'restore src,%g0,dest' pattern for double-word mode. */
3535 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3536 && arith_double_operand (src, GET_MODE (src))
3537 && ! src_is_freg)
3538 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3539
3540 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
3541 else if (! TARGET_FPU && register_operand (src, SFmode))
3542 return 1;
3543
3544 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
3545 else if (! TARGET_FPU && TARGET_ARCH64 && register_operand (src, DFmode))
3546 return 1;
3547
3548 /* If we have the 'return' instruction, anything that does not use
3549 local or output registers and can go into a delay slot wins. */
3550 else if (return_p && TARGET_V9 && !epilogue_renumber (&pat, 1))
3551 return 1;
3552
3553 /* The 'restore src1,src2,dest' pattern for SImode. */
3554 else if (GET_CODE (src) == PLUS
3555 && register_operand (XEXP (src, 0), SImode)
3556 && arith_operand (XEXP (src, 1), SImode))
3557 return 1;
3558
3559 /* The 'restore src1,src2,dest' pattern for DImode. */
3560 else if (GET_CODE (src) == PLUS
3561 && register_operand (XEXP (src, 0), DImode)
3562 && arith_double_operand (XEXP (src, 1), DImode))
3563 return 1;
3564
3565 /* The 'restore src1,%lo(src2),dest' pattern. */
3566 else if (GET_CODE (src) == LO_SUM
3567 && ! TARGET_CM_MEDMID
3568 && ((register_operand (XEXP (src, 0), SImode)
3569 && immediate_operand (XEXP (src, 1), SImode))
3570 || (TARGET_ARCH64
3571 && register_operand (XEXP (src, 0), DImode)
3572 && immediate_operand (XEXP (src, 1), DImode))))
3573 return 1;
3574
3575 /* The 'restore src,src,dest' pattern. */
3576 else if (GET_CODE (src) == ASHIFT
3577 && (register_operand (XEXP (src, 0), SImode)
3578 || register_operand (XEXP (src, 0), DImode))
3579 && XEXP (src, 1) == const1_rtx)
3580 return 1;
3581
3582 return 0;
3583 }
3584
3585 /* Return nonzero if TRIAL can go into the function return's delay slot. */
3586
3587 int
3588 eligible_for_return_delay (rtx_insn *trial)
3589 {
3590 int regno;
3591 rtx pat;
3592
3593 /* If the function uses __builtin_eh_return, the eh_return machinery
3594 occupies the delay slot. */
3595 if (crtl->calls_eh_return)
3596 return 0;
3597
3598 if (get_attr_in_branch_delay (trial) == IN_BRANCH_DELAY_FALSE)
3599 return 0;
3600
3601 /* In the case of a leaf or flat function, anything can go into the slot. */
3602 if (sparc_leaf_function_p || TARGET_FLAT)
3603 return 1;
3604
3605 if (!NONJUMP_INSN_P (trial))
3606 return 0;
3607
3608 pat = PATTERN (trial);
3609 if (GET_CODE (pat) == PARALLEL)
3610 {
3611 int i;
3612
3613 if (! TARGET_V9)
3614 return 0;
3615 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
3616 {
3617 rtx expr = XVECEXP (pat, 0, i);
3618 if (GET_CODE (expr) != SET)
3619 return 0;
3620 if (GET_CODE (SET_DEST (expr)) != REG)
3621 return 0;
3622 regno = REGNO (SET_DEST (expr));
3623 if (regno >= 8 && regno < 24)
3624 return 0;
3625 }
3626 return !epilogue_renumber (&pat, 1);
3627 }
3628
3629 if (GET_CODE (pat) != SET)
3630 return 0;
3631
3632 if (GET_CODE (SET_DEST (pat)) != REG)
3633 return 0;
3634
3635 regno = REGNO (SET_DEST (pat));
3636
3637 /* Otherwise, only operations which can be done in tandem with
3638 a `restore' or `return' insn can go into the delay slot. */
3639 if (regno >= 8 && regno < 24)
3640 return 0;
3641
3642 /* If this instruction sets up floating point register and we have a return
3643 instruction, it can probably go in. But restore will not work
3644 with FP_REGS. */
3645 if (! SPARC_INT_REG_P (regno))
3646 return TARGET_V9 && !epilogue_renumber (&pat, 1);
3647
3648 return eligible_for_restore_insn (trial, true);
3649 }
3650
3651 /* Return nonzero if TRIAL can go into the sibling call's delay slot. */
3652
3653 int
3654 eligible_for_sibcall_delay (rtx_insn *trial)
3655 {
3656 rtx pat;
3657
3658 if (get_attr_in_branch_delay (trial) == IN_BRANCH_DELAY_FALSE)
3659 return 0;
3660
3661 if (!NONJUMP_INSN_P (trial))
3662 return 0;
3663
3664 pat = PATTERN (trial);
3665
3666 if (sparc_leaf_function_p || TARGET_FLAT)
3667 {
3668 /* If the tail call is done using the call instruction,
3669 we have to restore %o7 in the delay slot. */
3670 if (LEAF_SIBCALL_SLOT_RESERVED_P)
3671 return 0;
3672
3673 /* %g1 is used to build the function address */
3674 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
3675 return 0;
3676
3677 return 1;
3678 }
3679
3680 if (GET_CODE (pat) != SET)
3681 return 0;
3682
3683 /* Otherwise, only operations which can be done in tandem with
3684 a `restore' insn can go into the delay slot. */
3685 if (GET_CODE (SET_DEST (pat)) != REG
3686 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24)
3687 || ! SPARC_INT_REG_P (REGNO (SET_DEST (pat))))
3688 return 0;
3689
3690 /* If it mentions %o7, it can't go in, because sibcall will clobber it
3691 in most cases. */
3692 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
3693 return 0;
3694
3695 return eligible_for_restore_insn (trial, false);
3696 }
3697 \f
3698 /* Determine if it's legal to put X into the constant pool. This
3699 is not possible if X contains the address of a symbol that is
3700 not constant (TLS) or not known at final link time (PIC). */
3701
3702 static bool
3703 sparc_cannot_force_const_mem (machine_mode mode, rtx x)
3704 {
3705 switch (GET_CODE (x))
3706 {
3707 case CONST_INT:
3708 case CONST_DOUBLE:
3709 case CONST_VECTOR:
3710 /* Accept all non-symbolic constants. */
3711 return false;
3712
3713 case LABEL_REF:
3714 /* Labels are OK iff we are non-PIC. */
3715 return flag_pic != 0;
3716
3717 case SYMBOL_REF:
3718 /* 'Naked' TLS symbol references are never OK,
3719 non-TLS symbols are OK iff we are non-PIC. */
3720 if (SYMBOL_REF_TLS_MODEL (x))
3721 return true;
3722 else
3723 return flag_pic != 0;
3724
3725 case CONST:
3726 return sparc_cannot_force_const_mem (mode, XEXP (x, 0));
3727 case PLUS:
3728 case MINUS:
3729 return sparc_cannot_force_const_mem (mode, XEXP (x, 0))
3730 || sparc_cannot_force_const_mem (mode, XEXP (x, 1));
3731 case UNSPEC:
3732 return true;
3733 default:
3734 gcc_unreachable ();
3735 }
3736 }
3737 \f
3738 /* Global Offset Table support. */
3739 static GTY(()) rtx got_helper_rtx = NULL_RTX;
3740 static GTY(()) rtx global_offset_table_rtx = NULL_RTX;
3741
3742 /* Return the SYMBOL_REF for the Global Offset Table. */
3743
3744 static GTY(()) rtx sparc_got_symbol = NULL_RTX;
3745
3746 static rtx
3747 sparc_got (void)
3748 {
3749 if (!sparc_got_symbol)
3750 sparc_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3751
3752 return sparc_got_symbol;
3753 }
3754
3755 /* Ensure that we are not using patterns that are not OK with PIC. */
3756
3757 int
3758 check_pic (int i)
3759 {
3760 rtx op;
3761
3762 switch (flag_pic)
3763 {
3764 case 1:
3765 op = recog_data.operand[i];
3766 gcc_assert (GET_CODE (op) != SYMBOL_REF
3767 && (GET_CODE (op) != CONST
3768 || (GET_CODE (XEXP (op, 0)) == MINUS
3769 && XEXP (XEXP (op, 0), 0) == sparc_got ()
3770 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST)));
3771 case 2:
3772 default:
3773 return 1;
3774 }
3775 }
3776
3777 /* Return true if X is an address which needs a temporary register when
3778 reloaded while generating PIC code. */
3779
3780 int
3781 pic_address_needs_scratch (rtx x)
3782 {
3783 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
3784 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3785 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
3786 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3787 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
3788 return 1;
3789
3790 return 0;
3791 }
3792
3793 /* Determine if a given RTX is a valid constant. We already know this
3794 satisfies CONSTANT_P. */
3795
3796 static bool
3797 sparc_legitimate_constant_p (machine_mode mode, rtx x)
3798 {
3799 switch (GET_CODE (x))
3800 {
3801 case CONST:
3802 case SYMBOL_REF:
3803 if (sparc_tls_referenced_p (x))
3804 return false;
3805 break;
3806
3807 case CONST_DOUBLE:
3808 if (GET_MODE (x) == VOIDmode)
3809 return true;
3810
3811 /* Floating point constants are generally not ok.
3812 The only exception is 0.0 and all-ones in VIS. */
3813 if (TARGET_VIS
3814 && SCALAR_FLOAT_MODE_P (mode)
3815 && (const_zero_operand (x, mode)
3816 || const_all_ones_operand (x, mode)))
3817 return true;
3818
3819 return false;
3820
3821 case CONST_VECTOR:
3822 /* Vector constants are generally not ok.
3823 The only exception is 0 or -1 in VIS. */
3824 if (TARGET_VIS
3825 && (const_zero_operand (x, mode)
3826 || const_all_ones_operand (x, mode)))
3827 return true;
3828
3829 return false;
3830
3831 default:
3832 break;
3833 }
3834
3835 return true;
3836 }
3837
3838 /* Determine if a given RTX is a valid constant address. */
3839
3840 bool
3841 constant_address_p (rtx x)
3842 {
3843 switch (GET_CODE (x))
3844 {
3845 case LABEL_REF:
3846 case CONST_INT:
3847 case HIGH:
3848 return true;
3849
3850 case CONST:
3851 if (flag_pic && pic_address_needs_scratch (x))
3852 return false;
3853 return sparc_legitimate_constant_p (Pmode, x);
3854
3855 case SYMBOL_REF:
3856 return !flag_pic && sparc_legitimate_constant_p (Pmode, x);
3857
3858 default:
3859 return false;
3860 }
3861 }
3862
3863 /* Nonzero if the constant value X is a legitimate general operand
3864 when generating PIC code. It is given that flag_pic is on and
3865 that X satisfies CONSTANT_P or is a CONST_DOUBLE. */
3866
3867 bool
3868 legitimate_pic_operand_p (rtx x)
3869 {
3870 if (pic_address_needs_scratch (x))
3871 return false;
3872 if (sparc_tls_referenced_p (x))
3873 return false;
3874 return true;
3875 }
3876
3877 #define RTX_OK_FOR_OFFSET_P(X, MODE) \
3878 (CONST_INT_P (X) \
3879 && INTVAL (X) >= -0x1000 \
3880 && INTVAL (X) <= (0x1000 - GET_MODE_SIZE (MODE)))
3881
3882 #define RTX_OK_FOR_OLO10_P(X, MODE) \
3883 (CONST_INT_P (X) \
3884 && INTVAL (X) >= -0x1000 \
3885 && INTVAL (X) <= (0xc00 - GET_MODE_SIZE (MODE)))
3886
3887 /* Handle the TARGET_LEGITIMATE_ADDRESS_P target hook.
3888
3889 On SPARC, the actual legitimate addresses must be REG+REG or REG+SMALLINT
3890 ordinarily. This changes a bit when generating PIC. */
3891
3892 static bool
3893 sparc_legitimate_address_p (machine_mode mode, rtx addr, bool strict)
3894 {
3895 rtx rs1 = NULL, rs2 = NULL, imm1 = NULL;
3896
3897 if (REG_P (addr) || GET_CODE (addr) == SUBREG)
3898 rs1 = addr;
3899 else if (GET_CODE (addr) == PLUS)
3900 {
3901 rs1 = XEXP (addr, 0);
3902 rs2 = XEXP (addr, 1);
3903
3904 /* Canonicalize. REG comes first, if there are no regs,
3905 LO_SUM comes first. */
3906 if (!REG_P (rs1)
3907 && GET_CODE (rs1) != SUBREG
3908 && (REG_P (rs2)
3909 || GET_CODE (rs2) == SUBREG
3910 || (GET_CODE (rs2) == LO_SUM && GET_CODE (rs1) != LO_SUM)))
3911 {
3912 rs1 = XEXP (addr, 1);
3913 rs2 = XEXP (addr, 0);
3914 }
3915
3916 if ((flag_pic == 1
3917 && rs1 == pic_offset_table_rtx
3918 && !REG_P (rs2)
3919 && GET_CODE (rs2) != SUBREG
3920 && GET_CODE (rs2) != LO_SUM
3921 && GET_CODE (rs2) != MEM
3922 && !(GET_CODE (rs2) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs2))
3923 && (! symbolic_operand (rs2, VOIDmode) || mode == Pmode)
3924 && (GET_CODE (rs2) != CONST_INT || SMALL_INT (rs2)))
3925 || ((REG_P (rs1)
3926 || GET_CODE (rs1) == SUBREG)
3927 && RTX_OK_FOR_OFFSET_P (rs2, mode)))
3928 {
3929 imm1 = rs2;
3930 rs2 = NULL;
3931 }
3932 else if ((REG_P (rs1) || GET_CODE (rs1) == SUBREG)
3933 && (REG_P (rs2) || GET_CODE (rs2) == SUBREG))
3934 {
3935 /* We prohibit REG + REG for TFmode when there are no quad move insns
3936 and we consequently need to split. We do this because REG+REG
3937 is not an offsettable address. If we get the situation in reload
3938 where source and destination of a movtf pattern are both MEMs with
3939 REG+REG address, then only one of them gets converted to an
3940 offsettable address. */
3941 if (mode == TFmode
3942 && ! (TARGET_ARCH64 && TARGET_HARD_QUAD))
3943 return 0;
3944
3945 /* Likewise for TImode, but in all cases. */
3946 if (mode == TImode)
3947 return 0;
3948
3949 /* We prohibit REG + REG on ARCH32 if not optimizing for
3950 DFmode/DImode because then mem_min_alignment is likely to be zero
3951 after reload and the forced split would lack a matching splitter
3952 pattern. */
3953 if (TARGET_ARCH32 && !optimize
3954 && (mode == DFmode || mode == DImode))
3955 return 0;
3956 }
3957 else if (USE_AS_OFFSETABLE_LO10
3958 && GET_CODE (rs1) == LO_SUM
3959 && TARGET_ARCH64
3960 && ! TARGET_CM_MEDMID
3961 && RTX_OK_FOR_OLO10_P (rs2, mode))
3962 {
3963 rs2 = NULL;
3964 imm1 = XEXP (rs1, 1);
3965 rs1 = XEXP (rs1, 0);
3966 if (!CONSTANT_P (imm1)
3967 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
3968 return 0;
3969 }
3970 }
3971 else if (GET_CODE (addr) == LO_SUM)
3972 {
3973 rs1 = XEXP (addr, 0);
3974 imm1 = XEXP (addr, 1);
3975
3976 if (!CONSTANT_P (imm1)
3977 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
3978 return 0;
3979
3980 /* We can't allow TFmode in 32-bit mode, because an offset greater
3981 than the alignment (8) may cause the LO_SUM to overflow. */
3982 if (mode == TFmode && TARGET_ARCH32)
3983 return 0;
3984 }
3985 else if (GET_CODE (addr) == CONST_INT && SMALL_INT (addr))
3986 return 1;
3987 else
3988 return 0;
3989
3990 if (GET_CODE (rs1) == SUBREG)
3991 rs1 = SUBREG_REG (rs1);
3992 if (!REG_P (rs1))
3993 return 0;
3994
3995 if (rs2)
3996 {
3997 if (GET_CODE (rs2) == SUBREG)
3998 rs2 = SUBREG_REG (rs2);
3999 if (!REG_P (rs2))
4000 return 0;
4001 }
4002
4003 if (strict)
4004 {
4005 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1))
4006 || (rs2 && !REGNO_OK_FOR_BASE_P (REGNO (rs2))))
4007 return 0;
4008 }
4009 else
4010 {
4011 if ((! SPARC_INT_REG_P (REGNO (rs1))
4012 && REGNO (rs1) != FRAME_POINTER_REGNUM
4013 && REGNO (rs1) < FIRST_PSEUDO_REGISTER)
4014 || (rs2
4015 && (! SPARC_INT_REG_P (REGNO (rs2))
4016 && REGNO (rs2) != FRAME_POINTER_REGNUM
4017 && REGNO (rs2) < FIRST_PSEUDO_REGISTER)))
4018 return 0;
4019 }
4020 return 1;
4021 }
4022
4023 /* Return the SYMBOL_REF for the tls_get_addr function. */
4024
4025 static GTY(()) rtx sparc_tls_symbol = NULL_RTX;
4026
4027 static rtx
4028 sparc_tls_get_addr (void)
4029 {
4030 if (!sparc_tls_symbol)
4031 sparc_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_addr");
4032
4033 return sparc_tls_symbol;
4034 }
4035
4036 /* Return the Global Offset Table to be used in TLS mode. */
4037
4038 static rtx
4039 sparc_tls_got (void)
4040 {
4041 /* In PIC mode, this is just the PIC offset table. */
4042 if (flag_pic)
4043 {
4044 crtl->uses_pic_offset_table = 1;
4045 return pic_offset_table_rtx;
4046 }
4047
4048 /* In non-PIC mode, Sun as (unlike GNU as) emits PC-relative relocations for
4049 the GOT symbol with the 32-bit ABI, so we reload the GOT register. */
4050 if (TARGET_SUN_TLS && TARGET_ARCH32)
4051 {
4052 load_got_register ();
4053 return global_offset_table_rtx;
4054 }
4055
4056 /* In all other cases, we load a new pseudo with the GOT symbol. */
4057 return copy_to_reg (sparc_got ());
4058 }
4059
4060 /* Return true if X contains a thread-local symbol. */
4061
4062 static bool
4063 sparc_tls_referenced_p (rtx x)
4064 {
4065 if (!TARGET_HAVE_TLS)
4066 return false;
4067
4068 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
4069 x = XEXP (XEXP (x, 0), 0);
4070
4071 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x))
4072 return true;
4073
4074 /* That's all we handle in sparc_legitimize_tls_address for now. */
4075 return false;
4076 }
4077
4078 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
4079 this (thread-local) address. */
4080
4081 static rtx
4082 sparc_legitimize_tls_address (rtx addr)
4083 {
4084 rtx temp1, temp2, temp3, ret, o0, got;
4085 rtx_insn *insn;
4086
4087 gcc_assert (can_create_pseudo_p ());
4088
4089 if (GET_CODE (addr) == SYMBOL_REF)
4090 switch (SYMBOL_REF_TLS_MODEL (addr))
4091 {
4092 case TLS_MODEL_GLOBAL_DYNAMIC:
4093 start_sequence ();
4094 temp1 = gen_reg_rtx (SImode);
4095 temp2 = gen_reg_rtx (SImode);
4096 ret = gen_reg_rtx (Pmode);
4097 o0 = gen_rtx_REG (Pmode, 8);
4098 got = sparc_tls_got ();
4099 emit_insn (gen_tgd_hi22 (temp1, addr));
4100 emit_insn (gen_tgd_lo10 (temp2, temp1, addr));
4101 if (TARGET_ARCH32)
4102 {
4103 emit_insn (gen_tgd_add32 (o0, got, temp2, addr));
4104 insn = emit_call_insn (gen_tgd_call32 (o0, sparc_tls_get_addr (),
4105 addr, const1_rtx));
4106 }
4107 else
4108 {
4109 emit_insn (gen_tgd_add64 (o0, got, temp2, addr));
4110 insn = emit_call_insn (gen_tgd_call64 (o0, sparc_tls_get_addr (),
4111 addr, const1_rtx));
4112 }
4113 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), o0);
4114 insn = get_insns ();
4115 end_sequence ();
4116 emit_libcall_block (insn, ret, o0, addr);
4117 break;
4118
4119 case TLS_MODEL_LOCAL_DYNAMIC:
4120 start_sequence ();
4121 temp1 = gen_reg_rtx (SImode);
4122 temp2 = gen_reg_rtx (SImode);
4123 temp3 = gen_reg_rtx (Pmode);
4124 ret = gen_reg_rtx (Pmode);
4125 o0 = gen_rtx_REG (Pmode, 8);
4126 got = sparc_tls_got ();
4127 emit_insn (gen_tldm_hi22 (temp1));
4128 emit_insn (gen_tldm_lo10 (temp2, temp1));
4129 if (TARGET_ARCH32)
4130 {
4131 emit_insn (gen_tldm_add32 (o0, got, temp2));
4132 insn = emit_call_insn (gen_tldm_call32 (o0, sparc_tls_get_addr (),
4133 const1_rtx));
4134 }
4135 else
4136 {
4137 emit_insn (gen_tldm_add64 (o0, got, temp2));
4138 insn = emit_call_insn (gen_tldm_call64 (o0, sparc_tls_get_addr (),
4139 const1_rtx));
4140 }
4141 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), o0);
4142 insn = get_insns ();
4143 end_sequence ();
4144 emit_libcall_block (insn, temp3, o0,
4145 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
4146 UNSPEC_TLSLD_BASE));
4147 temp1 = gen_reg_rtx (SImode);
4148 temp2 = gen_reg_rtx (SImode);
4149 emit_insn (gen_tldo_hix22 (temp1, addr));
4150 emit_insn (gen_tldo_lox10 (temp2, temp1, addr));
4151 if (TARGET_ARCH32)
4152 emit_insn (gen_tldo_add32 (ret, temp3, temp2, addr));
4153 else
4154 emit_insn (gen_tldo_add64 (ret, temp3, temp2, addr));
4155 break;
4156
4157 case TLS_MODEL_INITIAL_EXEC:
4158 temp1 = gen_reg_rtx (SImode);
4159 temp2 = gen_reg_rtx (SImode);
4160 temp3 = gen_reg_rtx (Pmode);
4161 got = sparc_tls_got ();
4162 emit_insn (gen_tie_hi22 (temp1, addr));
4163 emit_insn (gen_tie_lo10 (temp2, temp1, addr));
4164 if (TARGET_ARCH32)
4165 emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
4166 else
4167 emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
4168 if (TARGET_SUN_TLS)
4169 {
4170 ret = gen_reg_rtx (Pmode);
4171 if (TARGET_ARCH32)
4172 emit_insn (gen_tie_add32 (ret, gen_rtx_REG (Pmode, 7),
4173 temp3, addr));
4174 else
4175 emit_insn (gen_tie_add64 (ret, gen_rtx_REG (Pmode, 7),
4176 temp3, addr));
4177 }
4178 else
4179 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp3);
4180 break;
4181
4182 case TLS_MODEL_LOCAL_EXEC:
4183 temp1 = gen_reg_rtx (Pmode);
4184 temp2 = gen_reg_rtx (Pmode);
4185 if (TARGET_ARCH32)
4186 {
4187 emit_insn (gen_tle_hix22_sp32 (temp1, addr));
4188 emit_insn (gen_tle_lox10_sp32 (temp2, temp1, addr));
4189 }
4190 else
4191 {
4192 emit_insn (gen_tle_hix22_sp64 (temp1, addr));
4193 emit_insn (gen_tle_lox10_sp64 (temp2, temp1, addr));
4194 }
4195 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp2);
4196 break;
4197
4198 default:
4199 gcc_unreachable ();
4200 }
4201
4202 else if (GET_CODE (addr) == CONST)
4203 {
4204 rtx base, offset;
4205
4206 gcc_assert (GET_CODE (XEXP (addr, 0)) == PLUS);
4207
4208 base = sparc_legitimize_tls_address (XEXP (XEXP (addr, 0), 0));
4209 offset = XEXP (XEXP (addr, 0), 1);
4210
4211 base = force_operand (base, NULL_RTX);
4212 if (!(GET_CODE (offset) == CONST_INT && SMALL_INT (offset)))
4213 offset = force_reg (Pmode, offset);
4214 ret = gen_rtx_PLUS (Pmode, base, offset);
4215 }
4216
4217 else
4218 gcc_unreachable (); /* for now ... */
4219
4220 return ret;
4221 }
4222
4223 /* Legitimize PIC addresses. If the address is already position-independent,
4224 we return ORIG. Newly generated position-independent addresses go into a
4225 reg. This is REG if nonzero, otherwise we allocate register(s) as
4226 necessary. */
4227
4228 static rtx
4229 sparc_legitimize_pic_address (rtx orig, rtx reg)
4230 {
4231 bool gotdata_op = false;
4232
4233 if (GET_CODE (orig) == SYMBOL_REF
4234 /* See the comment in sparc_expand_move. */
4235 || (GET_CODE (orig) == LABEL_REF && !can_use_mov_pic_label_ref (orig)))
4236 {
4237 rtx pic_ref, address;
4238 rtx_insn *insn;
4239
4240 if (reg == 0)
4241 {
4242 gcc_assert (can_create_pseudo_p ());
4243 reg = gen_reg_rtx (Pmode);
4244 }
4245
4246 if (flag_pic == 2)
4247 {
4248 /* If not during reload, allocate another temp reg here for loading
4249 in the address, so that these instructions can be optimized
4250 properly. */
4251 rtx temp_reg = (! can_create_pseudo_p ()
4252 ? reg : gen_reg_rtx (Pmode));
4253
4254 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
4255 won't get confused into thinking that these two instructions
4256 are loading in the true address of the symbol. If in the
4257 future a PIC rtx exists, that should be used instead. */
4258 if (TARGET_ARCH64)
4259 {
4260 emit_insn (gen_movdi_high_pic (temp_reg, orig));
4261 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
4262 }
4263 else
4264 {
4265 emit_insn (gen_movsi_high_pic (temp_reg, orig));
4266 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
4267 }
4268 address = temp_reg;
4269 gotdata_op = true;
4270 }
4271 else
4272 address = orig;
4273
4274 crtl->uses_pic_offset_table = 1;
4275 if (gotdata_op)
4276 {
4277 if (TARGET_ARCH64)
4278 insn = emit_insn (gen_movdi_pic_gotdata_op (reg,
4279 pic_offset_table_rtx,
4280 address, orig));
4281 else
4282 insn = emit_insn (gen_movsi_pic_gotdata_op (reg,
4283 pic_offset_table_rtx,
4284 address, orig));
4285 }
4286 else
4287 {
4288 pic_ref
4289 = gen_const_mem (Pmode,
4290 gen_rtx_PLUS (Pmode,
4291 pic_offset_table_rtx, address));
4292 insn = emit_move_insn (reg, pic_ref);
4293 }
4294
4295 /* Put a REG_EQUAL note on this insn, so that it can be optimized
4296 by loop. */
4297 set_unique_reg_note (insn, REG_EQUAL, orig);
4298 return reg;
4299 }
4300 else if (GET_CODE (orig) == CONST)
4301 {
4302 rtx base, offset;
4303
4304 if (GET_CODE (XEXP (orig, 0)) == PLUS
4305 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
4306 return orig;
4307
4308 if (reg == 0)
4309 {
4310 gcc_assert (can_create_pseudo_p ());
4311 reg = gen_reg_rtx (Pmode);
4312 }
4313
4314 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
4315 base = sparc_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), reg);
4316 offset = sparc_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
4317 base == reg ? NULL_RTX : reg);
4318
4319 if (GET_CODE (offset) == CONST_INT)
4320 {
4321 if (SMALL_INT (offset))
4322 return plus_constant (Pmode, base, INTVAL (offset));
4323 else if (can_create_pseudo_p ())
4324 offset = force_reg (Pmode, offset);
4325 else
4326 /* If we reach here, then something is seriously wrong. */
4327 gcc_unreachable ();
4328 }
4329 return gen_rtx_PLUS (Pmode, base, offset);
4330 }
4331 else if (GET_CODE (orig) == LABEL_REF)
4332 /* ??? We ought to be checking that the register is live instead, in case
4333 it is eliminated. */
4334 crtl->uses_pic_offset_table = 1;
4335
4336 return orig;
4337 }
4338
4339 /* Try machine-dependent ways of modifying an illegitimate address X
4340 to be legitimate. If we find one, return the new, valid address.
4341
4342 OLDX is the address as it was before break_out_memory_refs was called.
4343 In some cases it is useful to look at this to decide what needs to be done.
4344
4345 MODE is the mode of the operand pointed to by X.
4346
4347 On SPARC, change REG+N into REG+REG, and REG+(X*Y) into REG+REG. */
4348
4349 static rtx
4350 sparc_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
4351 machine_mode mode)
4352 {
4353 rtx orig_x = x;
4354
4355 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT)
4356 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
4357 force_operand (XEXP (x, 0), NULL_RTX));
4358 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == MULT)
4359 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
4360 force_operand (XEXP (x, 1), NULL_RTX));
4361 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS)
4362 x = gen_rtx_PLUS (Pmode, force_operand (XEXP (x, 0), NULL_RTX),
4363 XEXP (x, 1));
4364 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == PLUS)
4365 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
4366 force_operand (XEXP (x, 1), NULL_RTX));
4367
4368 if (x != orig_x && sparc_legitimate_address_p (mode, x, FALSE))
4369 return x;
4370
4371 if (sparc_tls_referenced_p (x))
4372 x = sparc_legitimize_tls_address (x);
4373 else if (flag_pic)
4374 x = sparc_legitimize_pic_address (x, NULL_RTX);
4375 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 1)))
4376 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
4377 copy_to_mode_reg (Pmode, XEXP (x, 1)));
4378 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 0)))
4379 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
4380 copy_to_mode_reg (Pmode, XEXP (x, 0)));
4381 else if (GET_CODE (x) == SYMBOL_REF
4382 || GET_CODE (x) == CONST
4383 || GET_CODE (x) == LABEL_REF)
4384 x = copy_to_suggested_reg (x, NULL_RTX, Pmode);
4385
4386 return x;
4387 }
4388
4389 /* Delegitimize an address that was legitimized by the above function. */
4390
4391 static rtx
4392 sparc_delegitimize_address (rtx x)
4393 {
4394 x = delegitimize_mem_from_attrs (x);
4395
4396 if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 1)) == UNSPEC)
4397 switch (XINT (XEXP (x, 1), 1))
4398 {
4399 case UNSPEC_MOVE_PIC:
4400 case UNSPEC_TLSLE:
4401 x = XVECEXP (XEXP (x, 1), 0, 0);
4402 gcc_assert (GET_CODE (x) == SYMBOL_REF);
4403 break;
4404 default:
4405 break;
4406 }
4407
4408 /* This is generated by mov{si,di}_pic_label_ref in PIC mode. */
4409 if (GET_CODE (x) == MINUS
4410 && REG_P (XEXP (x, 0))
4411 && REGNO (XEXP (x, 0)) == PIC_OFFSET_TABLE_REGNUM
4412 && GET_CODE (XEXP (x, 1)) == LO_SUM
4413 && GET_CODE (XEXP (XEXP (x, 1), 1)) == UNSPEC
4414 && XINT (XEXP (XEXP (x, 1), 1), 1) == UNSPEC_MOVE_PIC_LABEL)
4415 {
4416 x = XVECEXP (XEXP (XEXP (x, 1), 1), 0, 0);
4417 gcc_assert (GET_CODE (x) == LABEL_REF);
4418 }
4419
4420 return x;
4421 }
4422
4423 /* SPARC implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
4424 replace the input X, or the original X if no replacement is called for.
4425 The output parameter *WIN is 1 if the calling macro should goto WIN,
4426 0 if it should not.
4427
4428 For SPARC, we wish to handle addresses by splitting them into
4429 HIGH+LO_SUM pairs, retaining the LO_SUM in the memory reference.
4430 This cuts the number of extra insns by one.
4431
4432 Do nothing when generating PIC code and the address is a symbolic
4433 operand or requires a scratch register. */
4434
4435 rtx
4436 sparc_legitimize_reload_address (rtx x, machine_mode mode,
4437 int opnum, int type,
4438 int ind_levels ATTRIBUTE_UNUSED, int *win)
4439 {
4440 /* Decompose SImode constants into HIGH+LO_SUM. */
4441 if (CONSTANT_P (x)
4442 && (mode != TFmode || TARGET_ARCH64)
4443 && GET_MODE (x) == SImode
4444 && GET_CODE (x) != LO_SUM
4445 && GET_CODE (x) != HIGH
4446 && sparc_cmodel <= CM_MEDLOW
4447 && !(flag_pic
4448 && (symbolic_operand (x, Pmode) || pic_address_needs_scratch (x))))
4449 {
4450 x = gen_rtx_LO_SUM (GET_MODE (x), gen_rtx_HIGH (GET_MODE (x), x), x);
4451 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
4452 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
4453 opnum, (enum reload_type)type);
4454 *win = 1;
4455 return x;
4456 }
4457
4458 /* We have to recognize what we have already generated above. */
4459 if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == HIGH)
4460 {
4461 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
4462 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
4463 opnum, (enum reload_type)type);
4464 *win = 1;
4465 return x;
4466 }
4467
4468 *win = 0;
4469 return x;
4470 }
4471
4472 /* Return true if ADDR (a legitimate address expression)
4473 has an effect that depends on the machine mode it is used for.
4474
4475 In PIC mode,
4476
4477 (mem:HI [%l7+a])
4478
4479 is not equivalent to
4480
4481 (mem:QI [%l7+a]) (mem:QI [%l7+a+1])
4482
4483 because [%l7+a+1] is interpreted as the address of (a+1). */
4484
4485
4486 static bool
4487 sparc_mode_dependent_address_p (const_rtx addr,
4488 addr_space_t as ATTRIBUTE_UNUSED)
4489 {
4490 if (flag_pic && GET_CODE (addr) == PLUS)
4491 {
4492 rtx op0 = XEXP (addr, 0);
4493 rtx op1 = XEXP (addr, 1);
4494 if (op0 == pic_offset_table_rtx
4495 && symbolic_operand (op1, VOIDmode))
4496 return true;
4497 }
4498
4499 return false;
4500 }
4501
4502 #ifdef HAVE_GAS_HIDDEN
4503 # define USE_HIDDEN_LINKONCE 1
4504 #else
4505 # define USE_HIDDEN_LINKONCE 0
4506 #endif
4507
4508 static void
4509 get_pc_thunk_name (char name[32], unsigned int regno)
4510 {
4511 const char *reg_name = reg_names[regno];
4512
4513 /* Skip the leading '%' as that cannot be used in a
4514 symbol name. */
4515 reg_name += 1;
4516
4517 if (USE_HIDDEN_LINKONCE)
4518 sprintf (name, "__sparc_get_pc_thunk.%s", reg_name);
4519 else
4520 ASM_GENERATE_INTERNAL_LABEL (name, "LADDPC", regno);
4521 }
4522
4523 /* Wrapper around the load_pcrel_sym{si,di} patterns. */
4524
4525 static rtx
4526 gen_load_pcrel_sym (rtx op0, rtx op1, rtx op2, rtx op3)
4527 {
4528 int orig_flag_pic = flag_pic;
4529 rtx insn;
4530
4531 /* The load_pcrel_sym{si,di} patterns require absolute addressing. */
4532 flag_pic = 0;
4533 if (TARGET_ARCH64)
4534 insn = gen_load_pcrel_symdi (op0, op1, op2, op3);
4535 else
4536 insn = gen_load_pcrel_symsi (op0, op1, op2, op3);
4537 flag_pic = orig_flag_pic;
4538
4539 return insn;
4540 }
4541
4542 /* Emit code to load the GOT register. */
4543
4544 void
4545 load_got_register (void)
4546 {
4547 /* In PIC mode, this will retrieve pic_offset_table_rtx. */
4548 if (!global_offset_table_rtx)
4549 global_offset_table_rtx = gen_rtx_REG (Pmode, GLOBAL_OFFSET_TABLE_REGNUM);
4550
4551 if (TARGET_VXWORKS_RTP)
4552 emit_insn (gen_vxworks_load_got ());
4553 else
4554 {
4555 /* The GOT symbol is subject to a PC-relative relocation so we need a
4556 helper function to add the PC value and thus get the final value. */
4557 if (!got_helper_rtx)
4558 {
4559 char name[32];
4560 get_pc_thunk_name (name, GLOBAL_OFFSET_TABLE_REGNUM);
4561 got_helper_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
4562 }
4563
4564 emit_insn (gen_load_pcrel_sym (global_offset_table_rtx, sparc_got (),
4565 got_helper_rtx,
4566 GEN_INT (GLOBAL_OFFSET_TABLE_REGNUM)));
4567 }
4568
4569 /* Need to emit this whether or not we obey regdecls,
4570 since setjmp/longjmp can cause life info to screw up.
4571 ??? In the case where we don't obey regdecls, this is not sufficient
4572 since we may not fall out the bottom. */
4573 emit_use (global_offset_table_rtx);
4574 }
4575
4576 /* Emit a call instruction with the pattern given by PAT. ADDR is the
4577 address of the call target. */
4578
4579 void
4580 sparc_emit_call_insn (rtx pat, rtx addr)
4581 {
4582 rtx_insn *insn;
4583
4584 insn = emit_call_insn (pat);
4585
4586 /* The PIC register is live on entry to VxWorks PIC PLT entries. */
4587 if (TARGET_VXWORKS_RTP
4588 && flag_pic
4589 && GET_CODE (addr) == SYMBOL_REF
4590 && (SYMBOL_REF_DECL (addr)
4591 ? !targetm.binds_local_p (SYMBOL_REF_DECL (addr))
4592 : !SYMBOL_REF_LOCAL_P (addr)))
4593 {
4594 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
4595 crtl->uses_pic_offset_table = 1;
4596 }
4597 }
4598 \f
4599 /* Return 1 if RTX is a MEM which is known to be aligned to at
4600 least a DESIRED byte boundary. */
4601
4602 int
4603 mem_min_alignment (rtx mem, int desired)
4604 {
4605 rtx addr, base, offset;
4606
4607 /* If it's not a MEM we can't accept it. */
4608 if (GET_CODE (mem) != MEM)
4609 return 0;
4610
4611 /* Obviously... */
4612 if (!TARGET_UNALIGNED_DOUBLES
4613 && MEM_ALIGN (mem) / BITS_PER_UNIT >= (unsigned)desired)
4614 return 1;
4615
4616 /* ??? The rest of the function predates MEM_ALIGN so
4617 there is probably a bit of redundancy. */
4618 addr = XEXP (mem, 0);
4619 base = offset = NULL_RTX;
4620 if (GET_CODE (addr) == PLUS)
4621 {
4622 if (GET_CODE (XEXP (addr, 0)) == REG)
4623 {
4624 base = XEXP (addr, 0);
4625
4626 /* What we are saying here is that if the base
4627 REG is aligned properly, the compiler will make
4628 sure any REG based index upon it will be so
4629 as well. */
4630 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
4631 offset = XEXP (addr, 1);
4632 else
4633 offset = const0_rtx;
4634 }
4635 }
4636 else if (GET_CODE (addr) == REG)
4637 {
4638 base = addr;
4639 offset = const0_rtx;
4640 }
4641
4642 if (base != NULL_RTX)
4643 {
4644 int regno = REGNO (base);
4645
4646 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
4647 {
4648 /* Check if the compiler has recorded some information
4649 about the alignment of the base REG. If reload has
4650 completed, we already matched with proper alignments.
4651 If not running global_alloc, reload might give us
4652 unaligned pointer to local stack though. */
4653 if (((cfun != 0
4654 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
4655 || (optimize && reload_completed))
4656 && (INTVAL (offset) & (desired - 1)) == 0)
4657 return 1;
4658 }
4659 else
4660 {
4661 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
4662 return 1;
4663 }
4664 }
4665 else if (! TARGET_UNALIGNED_DOUBLES
4666 || CONSTANT_P (addr)
4667 || GET_CODE (addr) == LO_SUM)
4668 {
4669 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
4670 is true, in which case we can only assume that an access is aligned if
4671 it is to a constant address, or the address involves a LO_SUM. */
4672 return 1;
4673 }
4674
4675 /* An obviously unaligned address. */
4676 return 0;
4677 }
4678
4679 \f
4680 /* Vectors to keep interesting information about registers where it can easily
4681 be got. We used to use the actual mode value as the bit number, but there
4682 are more than 32 modes now. Instead we use two tables: one indexed by
4683 hard register number, and one indexed by mode. */
4684
4685 /* The purpose of sparc_mode_class is to shrink the range of modes so that
4686 they all fit (as bit numbers) in a 32-bit word (again). Each real mode is
4687 mapped into one sparc_mode_class mode. */
4688
4689 enum sparc_mode_class {
4690 H_MODE, S_MODE, D_MODE, T_MODE, O_MODE,
4691 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
4692 CC_MODE, CCFP_MODE
4693 };
4694
4695 /* Modes for single-word and smaller quantities. */
4696 #define S_MODES \
4697 ((1 << (int) H_MODE) | (1 << (int) S_MODE) | (1 << (int) SF_MODE))
4698
4699 /* Modes for double-word and smaller quantities. */
4700 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
4701
4702 /* Modes for quad-word and smaller quantities. */
4703 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
4704
4705 /* Modes for 8-word and smaller quantities. */
4706 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
4707
4708 /* Modes for single-float quantities. */
4709 #define SF_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
4710
4711 /* Modes for double-float and smaller quantities. */
4712 #define DF_MODES (SF_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
4713
4714 /* Modes for quad-float and smaller quantities. */
4715 #define TF_MODES (DF_MODES | (1 << (int) TF_MODE))
4716
4717 /* Modes for quad-float pairs and smaller quantities. */
4718 #define OF_MODES (TF_MODES | (1 << (int) OF_MODE))
4719
4720 /* Modes for double-float only quantities. */
4721 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
4722
4723 /* Modes for quad-float and double-float only quantities. */
4724 #define TF_MODES_NO_S (DF_MODES_NO_S | (1 << (int) TF_MODE))
4725
4726 /* Modes for quad-float pairs and double-float only quantities. */
4727 #define OF_MODES_NO_S (TF_MODES_NO_S | (1 << (int) OF_MODE))
4728
4729 /* Modes for condition codes. */
4730 #define CC_MODES (1 << (int) CC_MODE)
4731 #define CCFP_MODES (1 << (int) CCFP_MODE)
4732
4733 /* Value is 1 if register/mode pair is acceptable on sparc.
4734
4735 The funny mixture of D and T modes is because integer operations
4736 do not specially operate on tetra quantities, so non-quad-aligned
4737 registers can hold quadword quantities (except %o4 and %i4 because
4738 they cross fixed registers).
4739
4740 ??? Note that, despite the settings, non-double-aligned parameter
4741 registers can hold double-word quantities in 32-bit mode. */
4742
4743 /* This points to either the 32 bit or the 64 bit version. */
4744 const int *hard_regno_mode_classes;
4745
4746 static const int hard_32bit_mode_classes[] = {
4747 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
4748 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
4749 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
4750 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
4751
4752 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4753 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4754 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4755 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
4756
4757 /* FP regs f32 to f63. Only the even numbered registers actually exist,
4758 and none can hold SFmode/SImode values. */
4759 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4760 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4761 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4762 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4763
4764 /* %fcc[0123] */
4765 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
4766
4767 /* %icc, %sfp, %gsr */
4768 CC_MODES, 0, D_MODES
4769 };
4770
4771 static const int hard_64bit_mode_classes[] = {
4772 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4773 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4774 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4775 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4776
4777 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4778 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4779 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4780 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
4781
4782 /* FP regs f32 to f63. Only the even numbered registers actually exist,
4783 and none can hold SFmode/SImode values. */
4784 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4785 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4786 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4787 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4788
4789 /* %fcc[0123] */
4790 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
4791
4792 /* %icc, %sfp, %gsr */
4793 CC_MODES, 0, D_MODES
4794 };
4795
4796 int sparc_mode_class [NUM_MACHINE_MODES];
4797
4798 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
4799
4800 static void
4801 sparc_init_modes (void)
4802 {
4803 int i;
4804
4805 for (i = 0; i < NUM_MACHINE_MODES; i++)
4806 {
4807 machine_mode m = (machine_mode) i;
4808 unsigned int size = GET_MODE_SIZE (m);
4809
4810 switch (GET_MODE_CLASS (m))
4811 {
4812 case MODE_INT:
4813 case MODE_PARTIAL_INT:
4814 case MODE_COMPLEX_INT:
4815 if (size < 4)
4816 sparc_mode_class[i] = 1 << (int) H_MODE;
4817 else if (size == 4)
4818 sparc_mode_class[i] = 1 << (int) S_MODE;
4819 else if (size == 8)
4820 sparc_mode_class[i] = 1 << (int) D_MODE;
4821 else if (size == 16)
4822 sparc_mode_class[i] = 1 << (int) T_MODE;
4823 else if (size == 32)
4824 sparc_mode_class[i] = 1 << (int) O_MODE;
4825 else
4826 sparc_mode_class[i] = 0;
4827 break;
4828 case MODE_VECTOR_INT:
4829 if (size == 4)
4830 sparc_mode_class[i] = 1 << (int) SF_MODE;
4831 else if (size == 8)
4832 sparc_mode_class[i] = 1 << (int) DF_MODE;
4833 else
4834 sparc_mode_class[i] = 0;
4835 break;
4836 case MODE_FLOAT:
4837 case MODE_COMPLEX_FLOAT:
4838 if (size == 4)
4839 sparc_mode_class[i] = 1 << (int) SF_MODE;
4840 else if (size == 8)
4841 sparc_mode_class[i] = 1 << (int) DF_MODE;
4842 else if (size == 16)
4843 sparc_mode_class[i] = 1 << (int) TF_MODE;
4844 else if (size == 32)
4845 sparc_mode_class[i] = 1 << (int) OF_MODE;
4846 else
4847 sparc_mode_class[i] = 0;
4848 break;
4849 case MODE_CC:
4850 if (m == CCFPmode || m == CCFPEmode)
4851 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
4852 else
4853 sparc_mode_class[i] = 1 << (int) CC_MODE;
4854 break;
4855 default:
4856 sparc_mode_class[i] = 0;
4857 break;
4858 }
4859 }
4860
4861 if (TARGET_ARCH64)
4862 hard_regno_mode_classes = hard_64bit_mode_classes;
4863 else
4864 hard_regno_mode_classes = hard_32bit_mode_classes;
4865
4866 /* Initialize the array used by REGNO_REG_CLASS. */
4867 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4868 {
4869 if (i < 16 && TARGET_V8PLUS)
4870 sparc_regno_reg_class[i] = I64_REGS;
4871 else if (i < 32 || i == FRAME_POINTER_REGNUM)
4872 sparc_regno_reg_class[i] = GENERAL_REGS;
4873 else if (i < 64)
4874 sparc_regno_reg_class[i] = FP_REGS;
4875 else if (i < 96)
4876 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
4877 else if (i < 100)
4878 sparc_regno_reg_class[i] = FPCC_REGS;
4879 else
4880 sparc_regno_reg_class[i] = NO_REGS;
4881 }
4882 }
4883 \f
4884 /* Return whether REGNO, a global or FP register, must be saved/restored. */
4885
4886 static inline bool
4887 save_global_or_fp_reg_p (unsigned int regno,
4888 int leaf_function ATTRIBUTE_UNUSED)
4889 {
4890 return !call_used_regs[regno] && df_regs_ever_live_p (regno);
4891 }
4892
4893 /* Return whether the return address register (%i7) is needed. */
4894
4895 static inline bool
4896 return_addr_reg_needed_p (int leaf_function)
4897 {
4898 /* If it is live, for example because of __builtin_return_address (0). */
4899 if (df_regs_ever_live_p (RETURN_ADDR_REGNUM))
4900 return true;
4901
4902 /* Otherwise, it is needed as save register if %o7 is clobbered. */
4903 if (!leaf_function
4904 /* Loading the GOT register clobbers %o7. */
4905 || crtl->uses_pic_offset_table
4906 || df_regs_ever_live_p (INCOMING_RETURN_ADDR_REGNUM))
4907 return true;
4908
4909 return false;
4910 }
4911
4912 /* Return whether REGNO, a local or in register, must be saved/restored. */
4913
4914 static bool
4915 save_local_or_in_reg_p (unsigned int regno, int leaf_function)
4916 {
4917 /* General case: call-saved registers live at some point. */
4918 if (!call_used_regs[regno] && df_regs_ever_live_p (regno))
4919 return true;
4920
4921 /* Frame pointer register (%fp) if needed. */
4922 if (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
4923 return true;
4924
4925 /* Return address register (%i7) if needed. */
4926 if (regno == RETURN_ADDR_REGNUM && return_addr_reg_needed_p (leaf_function))
4927 return true;
4928
4929 /* GOT register (%l7) if needed. */
4930 if (regno == PIC_OFFSET_TABLE_REGNUM && crtl->uses_pic_offset_table)
4931 return true;
4932
4933 /* If the function accesses prior frames, the frame pointer and the return
4934 address of the previous frame must be saved on the stack. */
4935 if (crtl->accesses_prior_frames
4936 && (regno == HARD_FRAME_POINTER_REGNUM || regno == RETURN_ADDR_REGNUM))
4937 return true;
4938
4939 return false;
4940 }
4941
4942 /* Compute the frame size required by the function. This function is called
4943 during the reload pass and also by sparc_expand_prologue. */
4944
4945 HOST_WIDE_INT
4946 sparc_compute_frame_size (HOST_WIDE_INT size, int leaf_function)
4947 {
4948 HOST_WIDE_INT frame_size, apparent_frame_size;
4949 int args_size, n_global_fp_regs = 0;
4950 bool save_local_in_regs_p = false;
4951 unsigned int i;
4952
4953 /* If the function allocates dynamic stack space, the dynamic offset is
4954 computed early and contains REG_PARM_STACK_SPACE, so we need to cope. */
4955 if (leaf_function && !cfun->calls_alloca)
4956 args_size = 0;
4957 else
4958 args_size = crtl->outgoing_args_size + REG_PARM_STACK_SPACE (cfun->decl);
4959
4960 /* Calculate space needed for global registers. */
4961 if (TARGET_ARCH64)
4962 for (i = 0; i < 8; i++)
4963 if (save_global_or_fp_reg_p (i, 0))
4964 n_global_fp_regs += 2;
4965 else
4966 for (i = 0; i < 8; i += 2)
4967 if (save_global_or_fp_reg_p (i, 0) || save_global_or_fp_reg_p (i + 1, 0))
4968 n_global_fp_regs += 2;
4969
4970 /* In the flat window model, find out which local and in registers need to
4971 be saved. We don't reserve space in the current frame for them as they
4972 will be spilled into the register window save area of the caller's frame.
4973 However, as soon as we use this register window save area, we must create
4974 that of the current frame to make it the live one. */
4975 if (TARGET_FLAT)
4976 for (i = 16; i < 32; i++)
4977 if (save_local_or_in_reg_p (i, leaf_function))
4978 {
4979 save_local_in_regs_p = true;
4980 break;
4981 }
4982
4983 /* Calculate space needed for FP registers. */
4984 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
4985 if (save_global_or_fp_reg_p (i, 0) || save_global_or_fp_reg_p (i + 1, 0))
4986 n_global_fp_regs += 2;
4987
4988 if (size == 0
4989 && n_global_fp_regs == 0
4990 && args_size == 0
4991 && !save_local_in_regs_p)
4992 frame_size = apparent_frame_size = 0;
4993 else
4994 {
4995 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
4996 apparent_frame_size = (size - STARTING_FRAME_OFFSET + 7) & -8;
4997 apparent_frame_size += n_global_fp_regs * 4;
4998
4999 /* We need to add the size of the outgoing argument area. */
5000 frame_size = apparent_frame_size + ((args_size + 7) & -8);
5001
5002 /* And that of the register window save area. */
5003 frame_size += FIRST_PARM_OFFSET (cfun->decl);
5004
5005 /* Finally, bump to the appropriate alignment. */
5006 frame_size = SPARC_STACK_ALIGN (frame_size);
5007 }
5008
5009 /* Set up values for use in prologue and epilogue. */
5010 sparc_frame_size = frame_size;
5011 sparc_apparent_frame_size = apparent_frame_size;
5012 sparc_n_global_fp_regs = n_global_fp_regs;
5013 sparc_save_local_in_regs_p = save_local_in_regs_p;
5014
5015 return frame_size;
5016 }
5017
5018 /* Implement the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */
5019
5020 int
5021 sparc_initial_elimination_offset (int to)
5022 {
5023 int offset;
5024
5025 if (to == STACK_POINTER_REGNUM)
5026 offset = sparc_compute_frame_size (get_frame_size (), crtl->is_leaf);
5027 else
5028 offset = 0;
5029
5030 offset += SPARC_STACK_BIAS;
5031 return offset;
5032 }
5033
5034 /* Output any necessary .register pseudo-ops. */
5035
5036 void
5037 sparc_output_scratch_registers (FILE *file ATTRIBUTE_UNUSED)
5038 {
5039 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
5040 int i;
5041
5042 if (TARGET_ARCH32)
5043 return;
5044
5045 /* Check if %g[2367] were used without
5046 .register being printed for them already. */
5047 for (i = 2; i < 8; i++)
5048 {
5049 if (df_regs_ever_live_p (i)
5050 && ! sparc_hard_reg_printed [i])
5051 {
5052 sparc_hard_reg_printed [i] = 1;
5053 /* %g7 is used as TLS base register, use #ignore
5054 for it instead of #scratch. */
5055 fprintf (file, "\t.register\t%%g%d, #%s\n", i,
5056 i == 7 ? "ignore" : "scratch");
5057 }
5058 if (i == 3) i = 5;
5059 }
5060 #endif
5061 }
5062
5063 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
5064
5065 #if PROBE_INTERVAL > 4096
5066 #error Cannot use indexed addressing mode for stack probing
5067 #endif
5068
5069 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
5070 inclusive. These are offsets from the current stack pointer.
5071
5072 Note that we don't use the REG+REG addressing mode for the probes because
5073 of the stack bias in 64-bit mode. And it doesn't really buy us anything
5074 so the advantages of having a single code win here. */
5075
5076 static void
5077 sparc_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
5078 {
5079 rtx g1 = gen_rtx_REG (Pmode, 1);
5080
5081 /* See if we have a constant small number of probes to generate. If so,
5082 that's the easy case. */
5083 if (size <= PROBE_INTERVAL)
5084 {
5085 emit_move_insn (g1, GEN_INT (first));
5086 emit_insn (gen_rtx_SET (g1,
5087 gen_rtx_MINUS (Pmode, stack_pointer_rtx, g1)));
5088 emit_stack_probe (plus_constant (Pmode, g1, -size));
5089 }
5090
5091 /* The run-time loop is made up of 10 insns in the generic case while the
5092 compile-time loop is made up of 4+2*(n-2) insns for n # of intervals. */
5093 else if (size <= 5 * PROBE_INTERVAL)
5094 {
5095 HOST_WIDE_INT i;
5096
5097 emit_move_insn (g1, GEN_INT (first + PROBE_INTERVAL));
5098 emit_insn (gen_rtx_SET (g1,
5099 gen_rtx_MINUS (Pmode, stack_pointer_rtx, g1)));
5100 emit_stack_probe (g1);
5101
5102 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 2 until
5103 it exceeds SIZE. If only two probes are needed, this will not
5104 generate any code. Then probe at FIRST + SIZE. */
5105 for (i = 2 * PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
5106 {
5107 emit_insn (gen_rtx_SET (g1,
5108 plus_constant (Pmode, g1, -PROBE_INTERVAL)));
5109 emit_stack_probe (g1);
5110 }
5111
5112 emit_stack_probe (plus_constant (Pmode, g1,
5113 (i - PROBE_INTERVAL) - size));
5114 }
5115
5116 /* Otherwise, do the same as above, but in a loop. Note that we must be
5117 extra careful with variables wrapping around because we might be at
5118 the very top (or the very bottom) of the address space and we have
5119 to be able to handle this case properly; in particular, we use an
5120 equality test for the loop condition. */
5121 else
5122 {
5123 HOST_WIDE_INT rounded_size;
5124 rtx g4 = gen_rtx_REG (Pmode, 4);
5125
5126 emit_move_insn (g1, GEN_INT (first));
5127
5128
5129 /* Step 1: round SIZE to the previous multiple of the interval. */
5130
5131 rounded_size = size & -PROBE_INTERVAL;
5132 emit_move_insn (g4, GEN_INT (rounded_size));
5133
5134
5135 /* Step 2: compute initial and final value of the loop counter. */
5136
5137 /* TEST_ADDR = SP + FIRST. */
5138 emit_insn (gen_rtx_SET (g1,
5139 gen_rtx_MINUS (Pmode, stack_pointer_rtx, g1)));
5140
5141 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
5142 emit_insn (gen_rtx_SET (g4, gen_rtx_MINUS (Pmode, g1, g4)));
5143
5144
5145 /* Step 3: the loop
5146
5147 while (TEST_ADDR != LAST_ADDR)
5148 {
5149 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
5150 probe at TEST_ADDR
5151 }
5152
5153 probes at FIRST + N * PROBE_INTERVAL for values of N from 1
5154 until it is equal to ROUNDED_SIZE. */
5155
5156 if (TARGET_ARCH64)
5157 emit_insn (gen_probe_stack_rangedi (g1, g1, g4));
5158 else
5159 emit_insn (gen_probe_stack_rangesi (g1, g1, g4));
5160
5161
5162 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
5163 that SIZE is equal to ROUNDED_SIZE. */
5164
5165 if (size != rounded_size)
5166 emit_stack_probe (plus_constant (Pmode, g4, rounded_size - size));
5167 }
5168
5169 /* Make sure nothing is scheduled before we are done. */
5170 emit_insn (gen_blockage ());
5171 }
5172
5173 /* Probe a range of stack addresses from REG1 to REG2 inclusive. These are
5174 absolute addresses. */
5175
5176 const char *
5177 output_probe_stack_range (rtx reg1, rtx reg2)
5178 {
5179 static int labelno = 0;
5180 char loop_lab[32], end_lab[32];
5181 rtx xops[2];
5182
5183 ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
5184 ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
5185
5186 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
5187
5188 /* Jump to END_LAB if TEST_ADDR == LAST_ADDR. */
5189 xops[0] = reg1;
5190 xops[1] = reg2;
5191 output_asm_insn ("cmp\t%0, %1", xops);
5192 if (TARGET_ARCH64)
5193 fputs ("\tbe,pn\t%xcc,", asm_out_file);
5194 else
5195 fputs ("\tbe\t", asm_out_file);
5196 assemble_name_raw (asm_out_file, end_lab);
5197 fputc ('\n', asm_out_file);
5198
5199 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
5200 xops[1] = GEN_INT (-PROBE_INTERVAL);
5201 output_asm_insn (" add\t%0, %1, %0", xops);
5202
5203 /* Probe at TEST_ADDR and branch. */
5204 if (TARGET_ARCH64)
5205 fputs ("\tba,pt\t%xcc,", asm_out_file);
5206 else
5207 fputs ("\tba\t", asm_out_file);
5208 assemble_name_raw (asm_out_file, loop_lab);
5209 fputc ('\n', asm_out_file);
5210 xops[1] = GEN_INT (SPARC_STACK_BIAS);
5211 output_asm_insn (" st\t%%g0, [%0+%1]", xops);
5212
5213 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
5214
5215 return "";
5216 }
5217
5218 /* Emit code to save/restore registers from LOW to HIGH at BASE+OFFSET as
5219 needed. LOW is supposed to be double-word aligned for 32-bit registers.
5220 SAVE_P decides whether a register must be saved/restored. ACTION_TRUE
5221 is the action to be performed if SAVE_P returns true and ACTION_FALSE
5222 the action to be performed if it returns false. Return the new offset. */
5223
5224 typedef bool (*sorr_pred_t) (unsigned int, int);
5225 typedef enum { SORR_NONE, SORR_ADVANCE, SORR_SAVE, SORR_RESTORE } sorr_act_t;
5226
5227 static int
5228 emit_save_or_restore_regs (unsigned int low, unsigned int high, rtx base,
5229 int offset, int leaf_function, sorr_pred_t save_p,
5230 sorr_act_t action_true, sorr_act_t action_false)
5231 {
5232 unsigned int i;
5233 rtx mem;
5234 rtx_insn *insn;
5235
5236 if (TARGET_ARCH64 && high <= 32)
5237 {
5238 int fp_offset = -1;
5239
5240 for (i = low; i < high; i++)
5241 {
5242 if (save_p (i, leaf_function))
5243 {
5244 mem = gen_frame_mem (DImode, plus_constant (Pmode,
5245 base, offset));
5246 if (action_true == SORR_SAVE)
5247 {
5248 insn = emit_move_insn (mem, gen_rtx_REG (DImode, i));
5249 RTX_FRAME_RELATED_P (insn) = 1;
5250 }
5251 else /* action_true == SORR_RESTORE */
5252 {
5253 /* The frame pointer must be restored last since its old
5254 value may be used as base address for the frame. This
5255 is problematic in 64-bit mode only because of the lack
5256 of double-word load instruction. */
5257 if (i == HARD_FRAME_POINTER_REGNUM)
5258 fp_offset = offset;
5259 else
5260 emit_move_insn (gen_rtx_REG (DImode, i), mem);
5261 }
5262 offset += 8;
5263 }
5264 else if (action_false == SORR_ADVANCE)
5265 offset += 8;
5266 }
5267
5268 if (fp_offset >= 0)
5269 {
5270 mem = gen_frame_mem (DImode, plus_constant (Pmode, base, fp_offset));
5271 emit_move_insn (hard_frame_pointer_rtx, mem);
5272 }
5273 }
5274 else
5275 {
5276 for (i = low; i < high; i += 2)
5277 {
5278 bool reg0 = save_p (i, leaf_function);
5279 bool reg1 = save_p (i + 1, leaf_function);
5280 machine_mode mode;
5281 int regno;
5282
5283 if (reg0 && reg1)
5284 {
5285 mode = SPARC_INT_REG_P (i) ? DImode : DFmode;
5286 regno = i;
5287 }
5288 else if (reg0)
5289 {
5290 mode = SPARC_INT_REG_P (i) ? SImode : SFmode;
5291 regno = i;
5292 }
5293 else if (reg1)
5294 {
5295 mode = SPARC_INT_REG_P (i) ? SImode : SFmode;
5296 regno = i + 1;
5297 offset += 4;
5298 }
5299 else
5300 {
5301 if (action_false == SORR_ADVANCE)
5302 offset += 8;
5303 continue;
5304 }
5305
5306 mem = gen_frame_mem (mode, plus_constant (Pmode, base, offset));
5307 if (action_true == SORR_SAVE)
5308 {
5309 insn = emit_move_insn (mem, gen_rtx_REG (mode, regno));
5310 RTX_FRAME_RELATED_P (insn) = 1;
5311 if (mode == DImode)
5312 {
5313 rtx set1, set2;
5314 mem = gen_frame_mem (SImode, plus_constant (Pmode, base,
5315 offset));
5316 set1 = gen_rtx_SET (mem, gen_rtx_REG (SImode, regno));
5317 RTX_FRAME_RELATED_P (set1) = 1;
5318 mem
5319 = gen_frame_mem (SImode, plus_constant (Pmode, base,
5320 offset + 4));
5321 set2 = gen_rtx_SET (mem, gen_rtx_REG (SImode, regno + 1));
5322 RTX_FRAME_RELATED_P (set2) = 1;
5323 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
5324 gen_rtx_PARALLEL (VOIDmode,
5325 gen_rtvec (2, set1, set2)));
5326 }
5327 }
5328 else /* action_true == SORR_RESTORE */
5329 emit_move_insn (gen_rtx_REG (mode, regno), mem);
5330
5331 /* Always preserve double-word alignment. */
5332 offset = (offset + 8) & -8;
5333 }
5334 }
5335
5336 return offset;
5337 }
5338
5339 /* Emit code to adjust BASE to OFFSET. Return the new base. */
5340
5341 static rtx
5342 emit_adjust_base_to_offset (rtx base, int offset)
5343 {
5344 /* ??? This might be optimized a little as %g1 might already have a
5345 value close enough that a single add insn will do. */
5346 /* ??? Although, all of this is probably only a temporary fix because
5347 if %g1 can hold a function result, then sparc_expand_epilogue will
5348 lose (the result will be clobbered). */
5349 rtx new_base = gen_rtx_REG (Pmode, 1);
5350 emit_move_insn (new_base, GEN_INT (offset));
5351 emit_insn (gen_rtx_SET (new_base, gen_rtx_PLUS (Pmode, base, new_base)));
5352 return new_base;
5353 }
5354
5355 /* Emit code to save/restore call-saved global and FP registers. */
5356
5357 static void
5358 emit_save_or_restore_global_fp_regs (rtx base, int offset, sorr_act_t action)
5359 {
5360 if (offset < -4096 || offset + sparc_n_global_fp_regs * 4 > 4095)
5361 {
5362 base = emit_adjust_base_to_offset (base, offset);
5363 offset = 0;
5364 }
5365
5366 offset
5367 = emit_save_or_restore_regs (0, 8, base, offset, 0,
5368 save_global_or_fp_reg_p, action, SORR_NONE);
5369 emit_save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, 0,
5370 save_global_or_fp_reg_p, action, SORR_NONE);
5371 }
5372
5373 /* Emit code to save/restore call-saved local and in registers. */
5374
5375 static void
5376 emit_save_or_restore_local_in_regs (rtx base, int offset, sorr_act_t action)
5377 {
5378 if (offset < -4096 || offset + 16 * UNITS_PER_WORD > 4095)
5379 {
5380 base = emit_adjust_base_to_offset (base, offset);
5381 offset = 0;
5382 }
5383
5384 emit_save_or_restore_regs (16, 32, base, offset, sparc_leaf_function_p,
5385 save_local_or_in_reg_p, action, SORR_ADVANCE);
5386 }
5387
5388 /* Emit a window_save insn. */
5389
5390 static rtx_insn *
5391 emit_window_save (rtx increment)
5392 {
5393 rtx_insn *insn = emit_insn (gen_window_save (increment));
5394 RTX_FRAME_RELATED_P (insn) = 1;
5395
5396 /* The incoming return address (%o7) is saved in %i7. */
5397 add_reg_note (insn, REG_CFA_REGISTER,
5398 gen_rtx_SET (gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM),
5399 gen_rtx_REG (Pmode,
5400 INCOMING_RETURN_ADDR_REGNUM)));
5401
5402 /* The window save event. */
5403 add_reg_note (insn, REG_CFA_WINDOW_SAVE, const0_rtx);
5404
5405 /* The CFA is %fp, the hard frame pointer. */
5406 add_reg_note (insn, REG_CFA_DEF_CFA,
5407 plus_constant (Pmode, hard_frame_pointer_rtx,
5408 INCOMING_FRAME_SP_OFFSET));
5409
5410 return insn;
5411 }
5412
5413 /* Generate an increment for the stack pointer. */
5414
5415 static rtx
5416 gen_stack_pointer_inc (rtx increment)
5417 {
5418 return gen_rtx_SET (stack_pointer_rtx,
5419 gen_rtx_PLUS (Pmode,
5420 stack_pointer_rtx,
5421 increment));
5422 }
5423
5424 /* Expand the function prologue. The prologue is responsible for reserving
5425 storage for the frame, saving the call-saved registers and loading the
5426 GOT register if needed. */
5427
5428 void
5429 sparc_expand_prologue (void)
5430 {
5431 HOST_WIDE_INT size;
5432 rtx_insn *insn;
5433
5434 /* Compute a snapshot of crtl->uses_only_leaf_regs. Relying
5435 on the final value of the flag means deferring the prologue/epilogue
5436 expansion until just before the second scheduling pass, which is too
5437 late to emit multiple epilogues or return insns.
5438
5439 Of course we are making the assumption that the value of the flag
5440 will not change between now and its final value. Of the three parts
5441 of the formula, only the last one can reasonably vary. Let's take a
5442 closer look, after assuming that the first two ones are set to true
5443 (otherwise the last value is effectively silenced).
5444
5445 If only_leaf_regs_used returns false, the global predicate will also
5446 be false so the actual frame size calculated below will be positive.
5447 As a consequence, the save_register_window insn will be emitted in
5448 the instruction stream; now this insn explicitly references %fp
5449 which is not a leaf register so only_leaf_regs_used will always
5450 return false subsequently.
5451
5452 If only_leaf_regs_used returns true, we hope that the subsequent
5453 optimization passes won't cause non-leaf registers to pop up. For
5454 example, the regrename pass has special provisions to not rename to
5455 non-leaf registers in a leaf function. */
5456 sparc_leaf_function_p
5457 = optimize > 0 && crtl->is_leaf && only_leaf_regs_used ();
5458
5459 size = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p);
5460
5461 if (flag_stack_usage_info)
5462 current_function_static_stack_size = size;
5463
5464 if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
5465 {
5466 if (crtl->is_leaf && !cfun->calls_alloca)
5467 {
5468 if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
5469 sparc_emit_probe_stack_range (STACK_CHECK_PROTECT,
5470 size - STACK_CHECK_PROTECT);
5471 }
5472 else if (size > 0)
5473 sparc_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
5474 }
5475
5476 if (size == 0)
5477 ; /* do nothing. */
5478 else if (sparc_leaf_function_p)
5479 {
5480 rtx size_int_rtx = GEN_INT (-size);
5481
5482 if (size <= 4096)
5483 insn = emit_insn (gen_stack_pointer_inc (size_int_rtx));
5484 else if (size <= 8192)
5485 {
5486 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-4096)));
5487 RTX_FRAME_RELATED_P (insn) = 1;
5488
5489 /* %sp is still the CFA register. */
5490 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (4096 - size)));
5491 }
5492 else
5493 {
5494 rtx size_rtx = gen_rtx_REG (Pmode, 1);
5495 emit_move_insn (size_rtx, size_int_rtx);
5496 insn = emit_insn (gen_stack_pointer_inc (size_rtx));
5497 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
5498 gen_stack_pointer_inc (size_int_rtx));
5499 }
5500
5501 RTX_FRAME_RELATED_P (insn) = 1;
5502 }
5503 else
5504 {
5505 rtx size_int_rtx = GEN_INT (-size);
5506
5507 if (size <= 4096)
5508 emit_window_save (size_int_rtx);
5509 else if (size <= 8192)
5510 {
5511 emit_window_save (GEN_INT (-4096));
5512
5513 /* %sp is not the CFA register anymore. */
5514 emit_insn (gen_stack_pointer_inc (GEN_INT (4096 - size)));
5515
5516 /* Make sure no %fp-based store is issued until after the frame is
5517 established. The offset between the frame pointer and the stack
5518 pointer is calculated relative to the value of the stack pointer
5519 at the end of the function prologue, and moving instructions that
5520 access the stack via the frame pointer between the instructions
5521 that decrement the stack pointer could result in accessing the
5522 register window save area, which is volatile. */
5523 emit_insn (gen_frame_blockage ());
5524 }
5525 else
5526 {
5527 rtx size_rtx = gen_rtx_REG (Pmode, 1);
5528 emit_move_insn (size_rtx, size_int_rtx);
5529 emit_window_save (size_rtx);
5530 }
5531 }
5532
5533 if (sparc_leaf_function_p)
5534 {
5535 sparc_frame_base_reg = stack_pointer_rtx;
5536 sparc_frame_base_offset = size + SPARC_STACK_BIAS;
5537 }
5538 else
5539 {
5540 sparc_frame_base_reg = hard_frame_pointer_rtx;
5541 sparc_frame_base_offset = SPARC_STACK_BIAS;
5542 }
5543
5544 if (sparc_n_global_fp_regs > 0)
5545 emit_save_or_restore_global_fp_regs (sparc_frame_base_reg,
5546 sparc_frame_base_offset
5547 - sparc_apparent_frame_size,
5548 SORR_SAVE);
5549
5550 /* Load the GOT register if needed. */
5551 if (crtl->uses_pic_offset_table)
5552 load_got_register ();
5553
5554 /* Advertise that the data calculated just above are now valid. */
5555 sparc_prologue_data_valid_p = true;
5556 }
5557
5558 /* Expand the function prologue. The prologue is responsible for reserving
5559 storage for the frame, saving the call-saved registers and loading the
5560 GOT register if needed. */
5561
5562 void
5563 sparc_flat_expand_prologue (void)
5564 {
5565 HOST_WIDE_INT size;
5566 rtx_insn *insn;
5567
5568 sparc_leaf_function_p = optimize > 0 && crtl->is_leaf;
5569
5570 size = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p);
5571
5572 if (flag_stack_usage_info)
5573 current_function_static_stack_size = size;
5574
5575 if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
5576 {
5577 if (crtl->is_leaf && !cfun->calls_alloca)
5578 {
5579 if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
5580 sparc_emit_probe_stack_range (STACK_CHECK_PROTECT,
5581 size - STACK_CHECK_PROTECT);
5582 }
5583 else if (size > 0)
5584 sparc_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
5585 }
5586
5587 if (sparc_save_local_in_regs_p)
5588 emit_save_or_restore_local_in_regs (stack_pointer_rtx, SPARC_STACK_BIAS,
5589 SORR_SAVE);
5590
5591 if (size == 0)
5592 ; /* do nothing. */
5593 else
5594 {
5595 rtx size_int_rtx, size_rtx;
5596
5597 size_rtx = size_int_rtx = GEN_INT (-size);
5598
5599 /* We establish the frame (i.e. decrement the stack pointer) first, even
5600 if we use a frame pointer, because we cannot clobber any call-saved
5601 registers, including the frame pointer, if we haven't created a new
5602 register save area, for the sake of compatibility with the ABI. */
5603 if (size <= 4096)
5604 insn = emit_insn (gen_stack_pointer_inc (size_int_rtx));
5605 else if (size <= 8192 && !frame_pointer_needed)
5606 {
5607 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-4096)));
5608 RTX_FRAME_RELATED_P (insn) = 1;
5609 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (4096 - size)));
5610 }
5611 else
5612 {
5613 size_rtx = gen_rtx_REG (Pmode, 1);
5614 emit_move_insn (size_rtx, size_int_rtx);
5615 insn = emit_insn (gen_stack_pointer_inc (size_rtx));
5616 add_reg_note (insn, REG_CFA_ADJUST_CFA,
5617 gen_stack_pointer_inc (size_int_rtx));
5618 }
5619 RTX_FRAME_RELATED_P (insn) = 1;
5620
5621 /* Ensure nothing is scheduled until after the frame is established. */
5622 emit_insn (gen_blockage ());
5623
5624 if (frame_pointer_needed)
5625 {
5626 insn = emit_insn (gen_rtx_SET (hard_frame_pointer_rtx,
5627 gen_rtx_MINUS (Pmode,
5628 stack_pointer_rtx,
5629 size_rtx)));
5630 RTX_FRAME_RELATED_P (insn) = 1;
5631
5632 add_reg_note (insn, REG_CFA_ADJUST_CFA,
5633 gen_rtx_SET (hard_frame_pointer_rtx,
5634 plus_constant (Pmode, stack_pointer_rtx,
5635 size)));
5636 }
5637
5638 if (return_addr_reg_needed_p (sparc_leaf_function_p))
5639 {
5640 rtx o7 = gen_rtx_REG (Pmode, INCOMING_RETURN_ADDR_REGNUM);
5641 rtx i7 = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
5642
5643 insn = emit_move_insn (i7, o7);
5644 RTX_FRAME_RELATED_P (insn) = 1;
5645
5646 add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (i7, o7));
5647
5648 /* Prevent this instruction from ever being considered dead,
5649 even if this function has no epilogue. */
5650 emit_use (i7);
5651 }
5652 }
5653
5654 if (frame_pointer_needed)
5655 {
5656 sparc_frame_base_reg = hard_frame_pointer_rtx;
5657 sparc_frame_base_offset = SPARC_STACK_BIAS;
5658 }
5659 else
5660 {
5661 sparc_frame_base_reg = stack_pointer_rtx;
5662 sparc_frame_base_offset = size + SPARC_STACK_BIAS;
5663 }
5664
5665 if (sparc_n_global_fp_regs > 0)
5666 emit_save_or_restore_global_fp_regs (sparc_frame_base_reg,
5667 sparc_frame_base_offset
5668 - sparc_apparent_frame_size,
5669 SORR_SAVE);
5670
5671 /* Load the GOT register if needed. */
5672 if (crtl->uses_pic_offset_table)
5673 load_got_register ();
5674
5675 /* Advertise that the data calculated just above are now valid. */
5676 sparc_prologue_data_valid_p = true;
5677 }
5678
5679 /* This function generates the assembly code for function entry, which boils
5680 down to emitting the necessary .register directives. */
5681
5682 static void
5683 sparc_asm_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
5684 {
5685 /* Check that the assumption we made in sparc_expand_prologue is valid. */
5686 if (!TARGET_FLAT)
5687 gcc_assert (sparc_leaf_function_p == crtl->uses_only_leaf_regs);
5688
5689 sparc_output_scratch_registers (file);
5690 }
5691
5692 /* Expand the function epilogue, either normal or part of a sibcall.
5693 We emit all the instructions except the return or the call. */
5694
5695 void
5696 sparc_expand_epilogue (bool for_eh)
5697 {
5698 HOST_WIDE_INT size = sparc_frame_size;
5699
5700 if (sparc_n_global_fp_regs > 0)
5701 emit_save_or_restore_global_fp_regs (sparc_frame_base_reg,
5702 sparc_frame_base_offset
5703 - sparc_apparent_frame_size,
5704 SORR_RESTORE);
5705
5706 if (size == 0 || for_eh)
5707 ; /* do nothing. */
5708 else if (sparc_leaf_function_p)
5709 {
5710 if (size <= 4096)
5711 emit_insn (gen_stack_pointer_inc (GEN_INT (size)));
5712 else if (size <= 8192)
5713 {
5714 emit_insn (gen_stack_pointer_inc (GEN_INT (4096)));
5715 emit_insn (gen_stack_pointer_inc (GEN_INT (size - 4096)));
5716 }
5717 else
5718 {
5719 rtx reg = gen_rtx_REG (Pmode, 1);
5720 emit_move_insn (reg, GEN_INT (size));
5721 emit_insn (gen_stack_pointer_inc (reg));
5722 }
5723 }
5724 }
5725
5726 /* Expand the function epilogue, either normal or part of a sibcall.
5727 We emit all the instructions except the return or the call. */
5728
5729 void
5730 sparc_flat_expand_epilogue (bool for_eh)
5731 {
5732 HOST_WIDE_INT size = sparc_frame_size;
5733
5734 if (sparc_n_global_fp_regs > 0)
5735 emit_save_or_restore_global_fp_regs (sparc_frame_base_reg,
5736 sparc_frame_base_offset
5737 - sparc_apparent_frame_size,
5738 SORR_RESTORE);
5739
5740 /* If we have a frame pointer, we'll need both to restore it before the
5741 frame is destroyed and use its current value in destroying the frame.
5742 Since we don't have an atomic way to do that in the flat window model,
5743 we save the current value into a temporary register (%g1). */
5744 if (frame_pointer_needed && !for_eh)
5745 emit_move_insn (gen_rtx_REG (Pmode, 1), hard_frame_pointer_rtx);
5746
5747 if (return_addr_reg_needed_p (sparc_leaf_function_p))
5748 emit_move_insn (gen_rtx_REG (Pmode, INCOMING_RETURN_ADDR_REGNUM),
5749 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM));
5750
5751 if (sparc_save_local_in_regs_p)
5752 emit_save_or_restore_local_in_regs (sparc_frame_base_reg,
5753 sparc_frame_base_offset,
5754 SORR_RESTORE);
5755
5756 if (size == 0 || for_eh)
5757 ; /* do nothing. */
5758 else if (frame_pointer_needed)
5759 {
5760 /* Make sure the frame is destroyed after everything else is done. */
5761 emit_insn (gen_blockage ());
5762
5763 emit_move_insn (stack_pointer_rtx, gen_rtx_REG (Pmode, 1));
5764 }
5765 else
5766 {
5767 /* Likewise. */
5768 emit_insn (gen_blockage ());
5769
5770 if (size <= 4096)
5771 emit_insn (gen_stack_pointer_inc (GEN_INT (size)));
5772 else if (size <= 8192)
5773 {
5774 emit_insn (gen_stack_pointer_inc (GEN_INT (4096)));
5775 emit_insn (gen_stack_pointer_inc (GEN_INT (size - 4096)));
5776 }
5777 else
5778 {
5779 rtx reg = gen_rtx_REG (Pmode, 1);
5780 emit_move_insn (reg, GEN_INT (size));
5781 emit_insn (gen_stack_pointer_inc (reg));
5782 }
5783 }
5784 }
5785
5786 /* Return true if it is appropriate to emit `return' instructions in the
5787 body of a function. */
5788
5789 bool
5790 sparc_can_use_return_insn_p (void)
5791 {
5792 return sparc_prologue_data_valid_p
5793 && sparc_n_global_fp_regs == 0
5794 && TARGET_FLAT
5795 ? (sparc_frame_size == 0 && !sparc_save_local_in_regs_p)
5796 : (sparc_frame_size == 0 || !sparc_leaf_function_p);
5797 }
5798
5799 /* This function generates the assembly code for function exit. */
5800
5801 static void
5802 sparc_asm_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
5803 {
5804 /* If the last two instructions of a function are "call foo; dslot;"
5805 the return address might point to the first instruction in the next
5806 function and we have to output a dummy nop for the sake of sane
5807 backtraces in such cases. This is pointless for sibling calls since
5808 the return address is explicitly adjusted. */
5809
5810 rtx insn, last_real_insn;
5811
5812 insn = get_last_insn ();
5813
5814 last_real_insn = prev_real_insn (insn);
5815 if (last_real_insn
5816 && NONJUMP_INSN_P (last_real_insn)
5817 && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE)
5818 last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0);
5819
5820 if (last_real_insn
5821 && CALL_P (last_real_insn)
5822 && !SIBLING_CALL_P (last_real_insn))
5823 fputs("\tnop\n", file);
5824
5825 sparc_output_deferred_case_vectors ();
5826 }
5827
5828 /* Output a 'restore' instruction. */
5829
5830 static void
5831 output_restore (rtx pat)
5832 {
5833 rtx operands[3];
5834
5835 if (! pat)
5836 {
5837 fputs ("\t restore\n", asm_out_file);
5838 return;
5839 }
5840
5841 gcc_assert (GET_CODE (pat) == SET);
5842
5843 operands[0] = SET_DEST (pat);
5844 pat = SET_SRC (pat);
5845
5846 switch (GET_CODE (pat))
5847 {
5848 case PLUS:
5849 operands[1] = XEXP (pat, 0);
5850 operands[2] = XEXP (pat, 1);
5851 output_asm_insn (" restore %r1, %2, %Y0", operands);
5852 break;
5853 case LO_SUM:
5854 operands[1] = XEXP (pat, 0);
5855 operands[2] = XEXP (pat, 1);
5856 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
5857 break;
5858 case ASHIFT:
5859 operands[1] = XEXP (pat, 0);
5860 gcc_assert (XEXP (pat, 1) == const1_rtx);
5861 output_asm_insn (" restore %r1, %r1, %Y0", operands);
5862 break;
5863 default:
5864 operands[1] = pat;
5865 output_asm_insn (" restore %%g0, %1, %Y0", operands);
5866 break;
5867 }
5868 }
5869
5870 /* Output a return. */
5871
5872 const char *
5873 output_return (rtx_insn *insn)
5874 {
5875 if (crtl->calls_eh_return)
5876 {
5877 /* If the function uses __builtin_eh_return, the eh_return
5878 machinery occupies the delay slot. */
5879 gcc_assert (!final_sequence);
5880
5881 if (flag_delayed_branch)
5882 {
5883 if (!TARGET_FLAT && TARGET_V9)
5884 fputs ("\treturn\t%i7+8\n", asm_out_file);
5885 else
5886 {
5887 if (!TARGET_FLAT)
5888 fputs ("\trestore\n", asm_out_file);
5889
5890 fputs ("\tjmp\t%o7+8\n", asm_out_file);
5891 }
5892
5893 fputs ("\t add\t%sp, %g1, %sp\n", asm_out_file);
5894 }
5895 else
5896 {
5897 if (!TARGET_FLAT)
5898 fputs ("\trestore\n", asm_out_file);
5899
5900 fputs ("\tadd\t%sp, %g1, %sp\n", asm_out_file);
5901 fputs ("\tjmp\t%o7+8\n\t nop\n", asm_out_file);
5902 }
5903 }
5904 else if (sparc_leaf_function_p || TARGET_FLAT)
5905 {
5906 /* This is a leaf or flat function so we don't have to bother restoring
5907 the register window, which frees us from dealing with the convoluted
5908 semantics of restore/return. We simply output the jump to the
5909 return address and the insn in the delay slot (if any). */
5910
5911 return "jmp\t%%o7+%)%#";
5912 }
5913 else
5914 {
5915 /* This is a regular function so we have to restore the register window.
5916 We may have a pending insn for the delay slot, which will be either
5917 combined with the 'restore' instruction or put in the delay slot of
5918 the 'return' instruction. */
5919
5920 if (final_sequence)
5921 {
5922 rtx delay, pat;
5923
5924 delay = NEXT_INSN (insn);
5925 gcc_assert (delay);
5926
5927 pat = PATTERN (delay);
5928
5929 if (TARGET_V9 && ! epilogue_renumber (&pat, 1))
5930 {
5931 epilogue_renumber (&pat, 0);
5932 return "return\t%%i7+%)%#";
5933 }
5934 else
5935 {
5936 output_asm_insn ("jmp\t%%i7+%)", NULL);
5937 output_restore (pat);
5938 PATTERN (delay) = gen_blockage ();
5939 INSN_CODE (delay) = -1;
5940 }
5941 }
5942 else
5943 {
5944 /* The delay slot is empty. */
5945 if (TARGET_V9)
5946 return "return\t%%i7+%)\n\t nop";
5947 else if (flag_delayed_branch)
5948 return "jmp\t%%i7+%)\n\t restore";
5949 else
5950 return "restore\n\tjmp\t%%o7+%)\n\t nop";
5951 }
5952 }
5953
5954 return "";
5955 }
5956
5957 /* Output a sibling call. */
5958
5959 const char *
5960 output_sibcall (rtx_insn *insn, rtx call_operand)
5961 {
5962 rtx operands[1];
5963
5964 gcc_assert (flag_delayed_branch);
5965
5966 operands[0] = call_operand;
5967
5968 if (sparc_leaf_function_p || TARGET_FLAT)
5969 {
5970 /* This is a leaf or flat function so we don't have to bother restoring
5971 the register window. We simply output the jump to the function and
5972 the insn in the delay slot (if any). */
5973
5974 gcc_assert (!(LEAF_SIBCALL_SLOT_RESERVED_P && final_sequence));
5975
5976 if (final_sequence)
5977 output_asm_insn ("sethi\t%%hi(%a0), %%g1\n\tjmp\t%%g1 + %%lo(%a0)%#",
5978 operands);
5979 else
5980 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
5981 it into branch if possible. */
5982 output_asm_insn ("or\t%%o7, %%g0, %%g1\n\tcall\t%a0, 0\n\t or\t%%g1, %%g0, %%o7",
5983 operands);
5984 }
5985 else
5986 {
5987 /* This is a regular function so we have to restore the register window.
5988 We may have a pending insn for the delay slot, which will be combined
5989 with the 'restore' instruction. */
5990
5991 output_asm_insn ("call\t%a0, 0", operands);
5992
5993 if (final_sequence)
5994 {
5995 rtx_insn *delay = NEXT_INSN (insn);
5996 gcc_assert (delay);
5997
5998 output_restore (PATTERN (delay));
5999
6000 PATTERN (delay) = gen_blockage ();
6001 INSN_CODE (delay) = -1;
6002 }
6003 else
6004 output_restore (NULL_RTX);
6005 }
6006
6007 return "";
6008 }
6009 \f
6010 /* Functions for handling argument passing.
6011
6012 For 32-bit, the first 6 args are normally in registers and the rest are
6013 pushed. Any arg that starts within the first 6 words is at least
6014 partially passed in a register unless its data type forbids.
6015
6016 For 64-bit, the argument registers are laid out as an array of 16 elements
6017 and arguments are added sequentially. The first 6 int args and up to the
6018 first 16 fp args (depending on size) are passed in regs.
6019
6020 Slot Stack Integral Float Float in structure Double Long Double
6021 ---- ----- -------- ----- ------------------ ------ -----------
6022 15 [SP+248] %f31 %f30,%f31 %d30
6023 14 [SP+240] %f29 %f28,%f29 %d28 %q28
6024 13 [SP+232] %f27 %f26,%f27 %d26
6025 12 [SP+224] %f25 %f24,%f25 %d24 %q24
6026 11 [SP+216] %f23 %f22,%f23 %d22
6027 10 [SP+208] %f21 %f20,%f21 %d20 %q20
6028 9 [SP+200] %f19 %f18,%f19 %d18
6029 8 [SP+192] %f17 %f16,%f17 %d16 %q16
6030 7 [SP+184] %f15 %f14,%f15 %d14
6031 6 [SP+176] %f13 %f12,%f13 %d12 %q12
6032 5 [SP+168] %o5 %f11 %f10,%f11 %d10
6033 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
6034 3 [SP+152] %o3 %f7 %f6,%f7 %d6
6035 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
6036 1 [SP+136] %o1 %f3 %f2,%f3 %d2
6037 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
6038
6039 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
6040
6041 Integral arguments are always passed as 64-bit quantities appropriately
6042 extended.
6043
6044 Passing of floating point values is handled as follows.
6045 If a prototype is in scope:
6046 If the value is in a named argument (i.e. not a stdarg function or a
6047 value not part of the `...') then the value is passed in the appropriate
6048 fp reg.
6049 If the value is part of the `...' and is passed in one of the first 6
6050 slots then the value is passed in the appropriate int reg.
6051 If the value is part of the `...' and is not passed in one of the first 6
6052 slots then the value is passed in memory.
6053 If a prototype is not in scope:
6054 If the value is one of the first 6 arguments the value is passed in the
6055 appropriate integer reg and the appropriate fp reg.
6056 If the value is not one of the first 6 arguments the value is passed in
6057 the appropriate fp reg and in memory.
6058
6059
6060 Summary of the calling conventions implemented by GCC on the SPARC:
6061
6062 32-bit ABI:
6063 size argument return value
6064
6065 small integer <4 int. reg. int. reg.
6066 word 4 int. reg. int. reg.
6067 double word 8 int. reg. int. reg.
6068
6069 _Complex small integer <8 int. reg. int. reg.
6070 _Complex word 8 int. reg. int. reg.
6071 _Complex double word 16 memory int. reg.
6072
6073 vector integer <=8 int. reg. FP reg.
6074 vector integer >8 memory memory
6075
6076 float 4 int. reg. FP reg.
6077 double 8 int. reg. FP reg.
6078 long double 16 memory memory
6079
6080 _Complex float 8 memory FP reg.
6081 _Complex double 16 memory FP reg.
6082 _Complex long double 32 memory FP reg.
6083
6084 vector float any memory memory
6085
6086 aggregate any memory memory
6087
6088
6089
6090 64-bit ABI:
6091 size argument return value
6092
6093 small integer <8 int. reg. int. reg.
6094 word 8 int. reg. int. reg.
6095 double word 16 int. reg. int. reg.
6096
6097 _Complex small integer <16 int. reg. int. reg.
6098 _Complex word 16 int. reg. int. reg.
6099 _Complex double word 32 memory int. reg.
6100
6101 vector integer <=16 FP reg. FP reg.
6102 vector integer 16<s<=32 memory FP reg.
6103 vector integer >32 memory memory
6104
6105 float 4 FP reg. FP reg.
6106 double 8 FP reg. FP reg.
6107 long double 16 FP reg. FP reg.
6108
6109 _Complex float 8 FP reg. FP reg.
6110 _Complex double 16 FP reg. FP reg.
6111 _Complex long double 32 memory FP reg.
6112
6113 vector float <=16 FP reg. FP reg.
6114 vector float 16<s<=32 memory FP reg.
6115 vector float >32 memory memory
6116
6117 aggregate <=16 reg. reg.
6118 aggregate 16<s<=32 memory reg.
6119 aggregate >32 memory memory
6120
6121
6122
6123 Note #1: complex floating-point types follow the extended SPARC ABIs as
6124 implemented by the Sun compiler.
6125
6126 Note #2: integral vector types follow the scalar floating-point types
6127 conventions to match what is implemented by the Sun VIS SDK.
6128
6129 Note #3: floating-point vector types follow the aggregate types
6130 conventions. */
6131
6132
6133 /* Maximum number of int regs for args. */
6134 #define SPARC_INT_ARG_MAX 6
6135 /* Maximum number of fp regs for args. */
6136 #define SPARC_FP_ARG_MAX 16
6137
6138 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
6139
6140 /* Handle the INIT_CUMULATIVE_ARGS macro.
6141 Initialize a variable CUM of type CUMULATIVE_ARGS
6142 for a call to a function whose data type is FNTYPE.
6143 For a library call, FNTYPE is 0. */
6144
6145 void
6146 init_cumulative_args (struct sparc_args *cum, tree fntype,
6147 rtx libname ATTRIBUTE_UNUSED,
6148 tree fndecl ATTRIBUTE_UNUSED)
6149 {
6150 cum->words = 0;
6151 cum->prototype_p = fntype && prototype_p (fntype);
6152 cum->libcall_p = fntype == 0;
6153 }
6154
6155 /* Handle promotion of pointer and integer arguments. */
6156
6157 static machine_mode
6158 sparc_promote_function_mode (const_tree type,
6159 machine_mode mode,
6160 int *punsignedp,
6161 const_tree fntype ATTRIBUTE_UNUSED,
6162 int for_return ATTRIBUTE_UNUSED)
6163 {
6164 if (type != NULL_TREE && POINTER_TYPE_P (type))
6165 {
6166 *punsignedp = POINTERS_EXTEND_UNSIGNED;
6167 return Pmode;
6168 }
6169
6170 /* Integral arguments are passed as full words, as per the ABI. */
6171 if (GET_MODE_CLASS (mode) == MODE_INT
6172 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
6173 return word_mode;
6174
6175 return mode;
6176 }
6177
6178 /* Handle the TARGET_STRICT_ARGUMENT_NAMING target hook. */
6179
6180 static bool
6181 sparc_strict_argument_naming (cumulative_args_t ca ATTRIBUTE_UNUSED)
6182 {
6183 return TARGET_ARCH64 ? true : false;
6184 }
6185
6186 /* Scan the record type TYPE and return the following predicates:
6187 - INTREGS_P: the record contains at least one field or sub-field
6188 that is eligible for promotion in integer registers.
6189 - FP_REGS_P: the record contains at least one field or sub-field
6190 that is eligible for promotion in floating-point registers.
6191 - PACKED_P: the record contains at least one field that is packed.
6192
6193 Sub-fields are not taken into account for the PACKED_P predicate. */
6194
6195 static void
6196 scan_record_type (const_tree type, int *intregs_p, int *fpregs_p,
6197 int *packed_p)
6198 {
6199 tree field;
6200
6201 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6202 {
6203 if (TREE_CODE (field) == FIELD_DECL)
6204 {
6205 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
6206 scan_record_type (TREE_TYPE (field), intregs_p, fpregs_p, 0);
6207 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
6208 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
6209 && TARGET_FPU)
6210 *fpregs_p = 1;
6211 else
6212 *intregs_p = 1;
6213
6214 if (packed_p && DECL_PACKED (field))
6215 *packed_p = 1;
6216 }
6217 }
6218 }
6219
6220 /* Compute the slot number to pass an argument in.
6221 Return the slot number or -1 if passing on the stack.
6222
6223 CUM is a variable of type CUMULATIVE_ARGS which gives info about
6224 the preceding args and about the function being called.
6225 MODE is the argument's machine mode.
6226 TYPE is the data type of the argument (as a tree).
6227 This is null for libcalls where that information may
6228 not be available.
6229 NAMED is nonzero if this argument is a named parameter
6230 (otherwise it is an extra parameter matching an ellipsis).
6231 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
6232 *PREGNO records the register number to use if scalar type.
6233 *PPADDING records the amount of padding needed in words. */
6234
6235 static int
6236 function_arg_slotno (const struct sparc_args *cum, machine_mode mode,
6237 const_tree type, bool named, bool incoming_p,
6238 int *pregno, int *ppadding)
6239 {
6240 int regbase = (incoming_p
6241 ? SPARC_INCOMING_INT_ARG_FIRST
6242 : SPARC_OUTGOING_INT_ARG_FIRST);
6243 int slotno = cum->words;
6244 enum mode_class mclass;
6245 int regno;
6246
6247 *ppadding = 0;
6248
6249 if (type && TREE_ADDRESSABLE (type))
6250 return -1;
6251
6252 if (TARGET_ARCH32
6253 && mode == BLKmode
6254 && type
6255 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
6256 return -1;
6257
6258 /* For SPARC64, objects requiring 16-byte alignment get it. */
6259 if (TARGET_ARCH64
6260 && (type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode)) >= 128
6261 && (slotno & 1) != 0)
6262 slotno++, *ppadding = 1;
6263
6264 mclass = GET_MODE_CLASS (mode);
6265 if (type && TREE_CODE (type) == VECTOR_TYPE)
6266 {
6267 /* Vector types deserve special treatment because they are
6268 polymorphic wrt their mode, depending upon whether VIS
6269 instructions are enabled. */
6270 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6271 {
6272 /* The SPARC port defines no floating-point vector modes. */
6273 gcc_assert (mode == BLKmode);
6274 }
6275 else
6276 {
6277 /* Integral vector types should either have a vector
6278 mode or an integral mode, because we are guaranteed
6279 by pass_by_reference that their size is not greater
6280 than 16 bytes and TImode is 16-byte wide. */
6281 gcc_assert (mode != BLKmode);
6282
6283 /* Vector integers are handled like floats according to
6284 the Sun VIS SDK. */
6285 mclass = MODE_FLOAT;
6286 }
6287 }
6288
6289 switch (mclass)
6290 {
6291 case MODE_FLOAT:
6292 case MODE_COMPLEX_FLOAT:
6293 case MODE_VECTOR_INT:
6294 if (TARGET_ARCH64 && TARGET_FPU && named)
6295 {
6296 if (slotno >= SPARC_FP_ARG_MAX)
6297 return -1;
6298 regno = SPARC_FP_ARG_FIRST + slotno * 2;
6299 /* Arguments filling only one single FP register are
6300 right-justified in the outer double FP register. */
6301 if (GET_MODE_SIZE (mode) <= 4)
6302 regno++;
6303 break;
6304 }
6305 /* fallthrough */
6306
6307 case MODE_INT:
6308 case MODE_COMPLEX_INT:
6309 if (slotno >= SPARC_INT_ARG_MAX)
6310 return -1;
6311 regno = regbase + slotno;
6312 break;
6313
6314 case MODE_RANDOM:
6315 if (mode == VOIDmode)
6316 /* MODE is VOIDmode when generating the actual call. */
6317 return -1;
6318
6319 gcc_assert (mode == BLKmode);
6320
6321 if (TARGET_ARCH32
6322 || !type
6323 || (TREE_CODE (type) != VECTOR_TYPE
6324 && TREE_CODE (type) != RECORD_TYPE))
6325 {
6326 if (slotno >= SPARC_INT_ARG_MAX)
6327 return -1;
6328 regno = regbase + slotno;
6329 }
6330 else /* TARGET_ARCH64 && type */
6331 {
6332 int intregs_p = 0, fpregs_p = 0, packed_p = 0;
6333
6334 /* First see what kinds of registers we would need. */
6335 if (TREE_CODE (type) == VECTOR_TYPE)
6336 fpregs_p = 1;
6337 else
6338 scan_record_type (type, &intregs_p, &fpregs_p, &packed_p);
6339
6340 /* The ABI obviously doesn't specify how packed structures
6341 are passed. These are defined to be passed in int regs
6342 if possible, otherwise memory. */
6343 if (packed_p || !named)
6344 fpregs_p = 0, intregs_p = 1;
6345
6346 /* If all arg slots are filled, then must pass on stack. */
6347 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
6348 return -1;
6349
6350 /* If there are only int args and all int arg slots are filled,
6351 then must pass on stack. */
6352 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
6353 return -1;
6354
6355 /* Note that even if all int arg slots are filled, fp members may
6356 still be passed in regs if such regs are available.
6357 *PREGNO isn't set because there may be more than one, it's up
6358 to the caller to compute them. */
6359 return slotno;
6360 }
6361 break;
6362
6363 default :
6364 gcc_unreachable ();
6365 }
6366
6367 *pregno = regno;
6368 return slotno;
6369 }
6370
6371 /* Handle recursive register counting for structure field layout. */
6372
6373 struct function_arg_record_value_parms
6374 {
6375 rtx ret; /* return expression being built. */
6376 int slotno; /* slot number of the argument. */
6377 int named; /* whether the argument is named. */
6378 int regbase; /* regno of the base register. */
6379 int stack; /* 1 if part of the argument is on the stack. */
6380 int intoffset; /* offset of the first pending integer field. */
6381 unsigned int nregs; /* number of words passed in registers. */
6382 };
6383
6384 static void function_arg_record_value_3
6385 (HOST_WIDE_INT, struct function_arg_record_value_parms *);
6386 static void function_arg_record_value_2
6387 (const_tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
6388 static void function_arg_record_value_1
6389 (const_tree, HOST_WIDE_INT, struct function_arg_record_value_parms *, bool);
6390 static rtx function_arg_record_value (const_tree, machine_mode, int, int, int);
6391 static rtx function_arg_union_value (int, machine_mode, int, int);
6392
6393 /* A subroutine of function_arg_record_value. Traverse the structure
6394 recursively and determine how many registers will be required. */
6395
6396 static void
6397 function_arg_record_value_1 (const_tree type, HOST_WIDE_INT startbitpos,
6398 struct function_arg_record_value_parms *parms,
6399 bool packed_p)
6400 {
6401 tree field;
6402
6403 /* We need to compute how many registers are needed so we can
6404 allocate the PARALLEL but before we can do that we need to know
6405 whether there are any packed fields. The ABI obviously doesn't
6406 specify how structures are passed in this case, so they are
6407 defined to be passed in int regs if possible, otherwise memory,
6408 regardless of whether there are fp values present. */
6409
6410 if (! packed_p)
6411 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
6412 {
6413 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
6414 {
6415 packed_p = true;
6416 break;
6417 }
6418 }
6419
6420 /* Compute how many registers we need. */
6421 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6422 {
6423 if (TREE_CODE (field) == FIELD_DECL)
6424 {
6425 HOST_WIDE_INT bitpos = startbitpos;
6426
6427 if (DECL_SIZE (field) != 0)
6428 {
6429 if (integer_zerop (DECL_SIZE (field)))
6430 continue;
6431
6432 if (tree_fits_uhwi_p (bit_position (field)))
6433 bitpos += int_bit_position (field);
6434 }
6435
6436 /* ??? FIXME: else assume zero offset. */
6437
6438 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
6439 function_arg_record_value_1 (TREE_TYPE (field),
6440 bitpos,
6441 parms,
6442 packed_p);
6443 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
6444 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
6445 && TARGET_FPU
6446 && parms->named
6447 && ! packed_p)
6448 {
6449 if (parms->intoffset != -1)
6450 {
6451 unsigned int startbit, endbit;
6452 int intslots, this_slotno;
6453
6454 startbit = parms->intoffset & -BITS_PER_WORD;
6455 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
6456
6457 intslots = (endbit - startbit) / BITS_PER_WORD;
6458 this_slotno = parms->slotno + parms->intoffset
6459 / BITS_PER_WORD;
6460
6461 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
6462 {
6463 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
6464 /* We need to pass this field on the stack. */
6465 parms->stack = 1;
6466 }
6467
6468 parms->nregs += intslots;
6469 parms->intoffset = -1;
6470 }
6471
6472 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
6473 If it wasn't true we wouldn't be here. */
6474 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
6475 && DECL_MODE (field) == BLKmode)
6476 parms->nregs += TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
6477 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
6478 parms->nregs += 2;
6479 else
6480 parms->nregs += 1;
6481 }
6482 else
6483 {
6484 if (parms->intoffset == -1)
6485 parms->intoffset = bitpos;
6486 }
6487 }
6488 }
6489 }
6490
6491 /* A subroutine of function_arg_record_value. Assign the bits of the
6492 structure between parms->intoffset and bitpos to integer registers. */
6493
6494 static void
6495 function_arg_record_value_3 (HOST_WIDE_INT bitpos,
6496 struct function_arg_record_value_parms *parms)
6497 {
6498 machine_mode mode;
6499 unsigned int regno;
6500 unsigned int startbit, endbit;
6501 int this_slotno, intslots, intoffset;
6502 rtx reg;
6503
6504 if (parms->intoffset == -1)
6505 return;
6506
6507 intoffset = parms->intoffset;
6508 parms->intoffset = -1;
6509
6510 startbit = intoffset & -BITS_PER_WORD;
6511 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
6512 intslots = (endbit - startbit) / BITS_PER_WORD;
6513 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
6514
6515 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
6516 if (intslots <= 0)
6517 return;
6518
6519 /* If this is the trailing part of a word, only load that much into
6520 the register. Otherwise load the whole register. Note that in
6521 the latter case we may pick up unwanted bits. It's not a problem
6522 at the moment but may wish to revisit. */
6523
6524 if (intoffset % BITS_PER_WORD != 0)
6525 mode = smallest_mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
6526 MODE_INT);
6527 else
6528 mode = word_mode;
6529
6530 intoffset /= BITS_PER_UNIT;
6531 do
6532 {
6533 regno = parms->regbase + this_slotno;
6534 reg = gen_rtx_REG (mode, regno);
6535 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
6536 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
6537
6538 this_slotno += 1;
6539 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
6540 mode = word_mode;
6541 parms->nregs += 1;
6542 intslots -= 1;
6543 }
6544 while (intslots > 0);
6545 }
6546
6547 /* A subroutine of function_arg_record_value. Traverse the structure
6548 recursively and assign bits to floating point registers. Track which
6549 bits in between need integer registers; invoke function_arg_record_value_3
6550 to make that happen. */
6551
6552 static void
6553 function_arg_record_value_2 (const_tree type, HOST_WIDE_INT startbitpos,
6554 struct function_arg_record_value_parms *parms,
6555 bool packed_p)
6556 {
6557 tree field;
6558
6559 if (! packed_p)
6560 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6561 {
6562 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
6563 {
6564 packed_p = true;
6565 break;
6566 }
6567 }
6568
6569 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6570 {
6571 if (TREE_CODE (field) == FIELD_DECL)
6572 {
6573 HOST_WIDE_INT bitpos = startbitpos;
6574
6575 if (DECL_SIZE (field) != 0)
6576 {
6577 if (integer_zerop (DECL_SIZE (field)))
6578 continue;
6579
6580 if (tree_fits_uhwi_p (bit_position (field)))
6581 bitpos += int_bit_position (field);
6582 }
6583
6584 /* ??? FIXME: else assume zero offset. */
6585
6586 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
6587 function_arg_record_value_2 (TREE_TYPE (field),
6588 bitpos,
6589 parms,
6590 packed_p);
6591 else if ((FLOAT_TYPE_P (TREE_TYPE (field))
6592 || TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
6593 && TARGET_FPU
6594 && parms->named
6595 && ! packed_p)
6596 {
6597 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
6598 int regno, nregs, pos;
6599 machine_mode mode = DECL_MODE (field);
6600 rtx reg;
6601
6602 function_arg_record_value_3 (bitpos, parms);
6603
6604 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE
6605 && mode == BLKmode)
6606 {
6607 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
6608 nregs = TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
6609 }
6610 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
6611 {
6612 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
6613 nregs = 2;
6614 }
6615 else
6616 nregs = 1;
6617
6618 regno = SPARC_FP_ARG_FIRST + this_slotno * 2;
6619 if (GET_MODE_SIZE (mode) <= 4 && (bitpos & 32) != 0)
6620 regno++;
6621 reg = gen_rtx_REG (mode, regno);
6622 pos = bitpos / BITS_PER_UNIT;
6623 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
6624 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
6625 parms->nregs += 1;
6626 while (--nregs > 0)
6627 {
6628 regno += GET_MODE_SIZE (mode) / 4;
6629 reg = gen_rtx_REG (mode, regno);
6630 pos += GET_MODE_SIZE (mode);
6631 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
6632 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
6633 parms->nregs += 1;
6634 }
6635 }
6636 else
6637 {
6638 if (parms->intoffset == -1)
6639 parms->intoffset = bitpos;
6640 }
6641 }
6642 }
6643 }
6644
6645 /* Used by function_arg and sparc_function_value_1 to implement the complex
6646 conventions of the 64-bit ABI for passing and returning structures.
6647 Return an expression valid as a return value for the FUNCTION_ARG
6648 and TARGET_FUNCTION_VALUE.
6649
6650 TYPE is the data type of the argument (as a tree).
6651 This is null for libcalls where that information may
6652 not be available.
6653 MODE is the argument's machine mode.
6654 SLOTNO is the index number of the argument's slot in the parameter array.
6655 NAMED is nonzero if this argument is a named parameter
6656 (otherwise it is an extra parameter matching an ellipsis).
6657 REGBASE is the regno of the base register for the parameter array. */
6658
6659 static rtx
6660 function_arg_record_value (const_tree type, machine_mode mode,
6661 int slotno, int named, int regbase)
6662 {
6663 HOST_WIDE_INT typesize = int_size_in_bytes (type);
6664 struct function_arg_record_value_parms parms;
6665 unsigned int nregs;
6666
6667 parms.ret = NULL_RTX;
6668 parms.slotno = slotno;
6669 parms.named = named;
6670 parms.regbase = regbase;
6671 parms.stack = 0;
6672
6673 /* Compute how many registers we need. */
6674 parms.nregs = 0;
6675 parms.intoffset = 0;
6676 function_arg_record_value_1 (type, 0, &parms, false);
6677
6678 /* Take into account pending integer fields. */
6679 if (parms.intoffset != -1)
6680 {
6681 unsigned int startbit, endbit;
6682 int intslots, this_slotno;
6683
6684 startbit = parms.intoffset & -BITS_PER_WORD;
6685 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
6686 intslots = (endbit - startbit) / BITS_PER_WORD;
6687 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
6688
6689 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
6690 {
6691 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
6692 /* We need to pass this field on the stack. */
6693 parms.stack = 1;
6694 }
6695
6696 parms.nregs += intslots;
6697 }
6698 nregs = parms.nregs;
6699
6700 /* Allocate the vector and handle some annoying special cases. */
6701 if (nregs == 0)
6702 {
6703 /* ??? Empty structure has no value? Duh? */
6704 if (typesize <= 0)
6705 {
6706 /* Though there's nothing really to store, return a word register
6707 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
6708 leads to breakage due to the fact that there are zero bytes to
6709 load. */
6710 return gen_rtx_REG (mode, regbase);
6711 }
6712 else
6713 {
6714 /* ??? C++ has structures with no fields, and yet a size. Give up
6715 for now and pass everything back in integer registers. */
6716 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6717 }
6718 if (nregs + slotno > SPARC_INT_ARG_MAX)
6719 nregs = SPARC_INT_ARG_MAX - slotno;
6720 }
6721 gcc_assert (nregs != 0);
6722
6723 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (parms.stack + nregs));
6724
6725 /* If at least one field must be passed on the stack, generate
6726 (parallel [(expr_list (nil) ...) ...]) so that all fields will
6727 also be passed on the stack. We can't do much better because the
6728 semantics of TARGET_ARG_PARTIAL_BYTES doesn't handle the case
6729 of structures for which the fields passed exclusively in registers
6730 are not at the beginning of the structure. */
6731 if (parms.stack)
6732 XVECEXP (parms.ret, 0, 0)
6733 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
6734
6735 /* Fill in the entries. */
6736 parms.nregs = 0;
6737 parms.intoffset = 0;
6738 function_arg_record_value_2 (type, 0, &parms, false);
6739 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
6740
6741 gcc_assert (parms.nregs == nregs);
6742
6743 return parms.ret;
6744 }
6745
6746 /* Used by function_arg and sparc_function_value_1 to implement the conventions
6747 of the 64-bit ABI for passing and returning unions.
6748 Return an expression valid as a return value for the FUNCTION_ARG
6749 and TARGET_FUNCTION_VALUE.
6750
6751 SIZE is the size in bytes of the union.
6752 MODE is the argument's machine mode.
6753 REGNO is the hard register the union will be passed in. */
6754
6755 static rtx
6756 function_arg_union_value (int size, machine_mode mode, int slotno,
6757 int regno)
6758 {
6759 int nwords = ROUND_ADVANCE (size), i;
6760 rtx regs;
6761
6762 /* See comment in previous function for empty structures. */
6763 if (nwords == 0)
6764 return gen_rtx_REG (mode, regno);
6765
6766 if (slotno == SPARC_INT_ARG_MAX - 1)
6767 nwords = 1;
6768
6769 regs = gen_rtx_PARALLEL (mode, rtvec_alloc (nwords));
6770
6771 for (i = 0; i < nwords; i++)
6772 {
6773 /* Unions are passed left-justified. */
6774 XVECEXP (regs, 0, i)
6775 = gen_rtx_EXPR_LIST (VOIDmode,
6776 gen_rtx_REG (word_mode, regno),
6777 GEN_INT (UNITS_PER_WORD * i));
6778 regno++;
6779 }
6780
6781 return regs;
6782 }
6783
6784 /* Used by function_arg and sparc_function_value_1 to implement the conventions
6785 for passing and returning BLKmode vectors.
6786 Return an expression valid as a return value for the FUNCTION_ARG
6787 and TARGET_FUNCTION_VALUE.
6788
6789 SIZE is the size in bytes of the vector.
6790 REGNO is the FP hard register the vector will be passed in. */
6791
6792 static rtx
6793 function_arg_vector_value (int size, int regno)
6794 {
6795 const int nregs = MAX (1, size / 8);
6796 rtx regs = gen_rtx_PARALLEL (BLKmode, rtvec_alloc (nregs));
6797
6798 if (size < 8)
6799 XVECEXP (regs, 0, 0)
6800 = gen_rtx_EXPR_LIST (VOIDmode,
6801 gen_rtx_REG (SImode, regno),
6802 const0_rtx);
6803 else
6804 for (int i = 0; i < nregs; i++)
6805 XVECEXP (regs, 0, i)
6806 = gen_rtx_EXPR_LIST (VOIDmode,
6807 gen_rtx_REG (DImode, regno + 2*i),
6808 GEN_INT (i*8));
6809
6810 return regs;
6811 }
6812
6813 /* Determine where to put an argument to a function.
6814 Value is zero to push the argument on the stack,
6815 or a hard register in which to store the argument.
6816
6817 CUM is a variable of type CUMULATIVE_ARGS which gives info about
6818 the preceding args and about the function being called.
6819 MODE is the argument's machine mode.
6820 TYPE is the data type of the argument (as a tree).
6821 This is null for libcalls where that information may
6822 not be available.
6823 NAMED is true if this argument is a named parameter
6824 (otherwise it is an extra parameter matching an ellipsis).
6825 INCOMING_P is false for TARGET_FUNCTION_ARG, true for
6826 TARGET_FUNCTION_INCOMING_ARG. */
6827
6828 static rtx
6829 sparc_function_arg_1 (cumulative_args_t cum_v, machine_mode mode,
6830 const_tree type, bool named, bool incoming_p)
6831 {
6832 const CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
6833
6834 int regbase = (incoming_p
6835 ? SPARC_INCOMING_INT_ARG_FIRST
6836 : SPARC_OUTGOING_INT_ARG_FIRST);
6837 int slotno, regno, padding;
6838 enum mode_class mclass = GET_MODE_CLASS (mode);
6839
6840 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
6841 &regno, &padding);
6842 if (slotno == -1)
6843 return 0;
6844
6845 /* Vector types deserve special treatment because they are polymorphic wrt
6846 their mode, depending upon whether VIS instructions are enabled. */
6847 if (type && TREE_CODE (type) == VECTOR_TYPE)
6848 {
6849 HOST_WIDE_INT size = int_size_in_bytes (type);
6850 gcc_assert ((TARGET_ARCH32 && size <= 8)
6851 || (TARGET_ARCH64 && size <= 16));
6852
6853 if (mode == BLKmode)
6854 return function_arg_vector_value (size, SPARC_FP_ARG_FIRST + 2*slotno);
6855
6856 mclass = MODE_FLOAT;
6857 }
6858
6859 if (TARGET_ARCH32)
6860 return gen_rtx_REG (mode, regno);
6861
6862 /* Structures up to 16 bytes in size are passed in arg slots on the stack
6863 and are promoted to registers if possible. */
6864 if (type && TREE_CODE (type) == RECORD_TYPE)
6865 {
6866 HOST_WIDE_INT size = int_size_in_bytes (type);
6867 gcc_assert (size <= 16);
6868
6869 return function_arg_record_value (type, mode, slotno, named, regbase);
6870 }
6871
6872 /* Unions up to 16 bytes in size are passed in integer registers. */
6873 else if (type && TREE_CODE (type) == UNION_TYPE)
6874 {
6875 HOST_WIDE_INT size = int_size_in_bytes (type);
6876 gcc_assert (size <= 16);
6877
6878 return function_arg_union_value (size, mode, slotno, regno);
6879 }
6880
6881 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
6882 but also have the slot allocated for them.
6883 If no prototype is in scope fp values in register slots get passed
6884 in two places, either fp regs and int regs or fp regs and memory. */
6885 else if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
6886 && SPARC_FP_REG_P (regno))
6887 {
6888 rtx reg = gen_rtx_REG (mode, regno);
6889 if (cum->prototype_p || cum->libcall_p)
6890 {
6891 /* "* 2" because fp reg numbers are recorded in 4 byte
6892 quantities. */
6893 #if 0
6894 /* ??? This will cause the value to be passed in the fp reg and
6895 in the stack. When a prototype exists we want to pass the
6896 value in the reg but reserve space on the stack. That's an
6897 optimization, and is deferred [for a bit]. */
6898 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
6899 return gen_rtx_PARALLEL (mode,
6900 gen_rtvec (2,
6901 gen_rtx_EXPR_LIST (VOIDmode,
6902 NULL_RTX, const0_rtx),
6903 gen_rtx_EXPR_LIST (VOIDmode,
6904 reg, const0_rtx)));
6905 else
6906 #else
6907 /* ??? It seems that passing back a register even when past
6908 the area declared by REG_PARM_STACK_SPACE will allocate
6909 space appropriately, and will not copy the data onto the
6910 stack, exactly as we desire.
6911
6912 This is due to locate_and_pad_parm being called in
6913 expand_call whenever reg_parm_stack_space > 0, which
6914 while beneficial to our example here, would seem to be
6915 in error from what had been intended. Ho hum... -- r~ */
6916 #endif
6917 return reg;
6918 }
6919 else
6920 {
6921 rtx v0, v1;
6922
6923 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
6924 {
6925 int intreg;
6926
6927 /* On incoming, we don't need to know that the value
6928 is passed in %f0 and %i0, and it confuses other parts
6929 causing needless spillage even on the simplest cases. */
6930 if (incoming_p)
6931 return reg;
6932
6933 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
6934 + (regno - SPARC_FP_ARG_FIRST) / 2);
6935
6936 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
6937 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
6938 const0_rtx);
6939 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
6940 }
6941 else
6942 {
6943 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
6944 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
6945 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
6946 }
6947 }
6948 }
6949
6950 /* All other aggregate types are passed in an integer register in a mode
6951 corresponding to the size of the type. */
6952 else if (type && AGGREGATE_TYPE_P (type))
6953 {
6954 HOST_WIDE_INT size = int_size_in_bytes (type);
6955 gcc_assert (size <= 16);
6956
6957 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
6958 }
6959
6960 return gen_rtx_REG (mode, regno);
6961 }
6962
6963 /* Handle the TARGET_FUNCTION_ARG target hook. */
6964
6965 static rtx
6966 sparc_function_arg (cumulative_args_t cum, machine_mode mode,
6967 const_tree type, bool named)
6968 {
6969 return sparc_function_arg_1 (cum, mode, type, named, false);
6970 }
6971
6972 /* Handle the TARGET_FUNCTION_INCOMING_ARG target hook. */
6973
6974 static rtx
6975 sparc_function_incoming_arg (cumulative_args_t cum, machine_mode mode,
6976 const_tree type, bool named)
6977 {
6978 return sparc_function_arg_1 (cum, mode, type, named, true);
6979 }
6980
6981 /* For sparc64, objects requiring 16 byte alignment are passed that way. */
6982
6983 static unsigned int
6984 sparc_function_arg_boundary (machine_mode mode, const_tree type)
6985 {
6986 return ((TARGET_ARCH64
6987 && (GET_MODE_ALIGNMENT (mode) == 128
6988 || (type && TYPE_ALIGN (type) == 128)))
6989 ? 128
6990 : PARM_BOUNDARY);
6991 }
6992
6993 /* For an arg passed partly in registers and partly in memory,
6994 this is the number of bytes of registers used.
6995 For args passed entirely in registers or entirely in memory, zero.
6996
6997 Any arg that starts in the first 6 regs but won't entirely fit in them
6998 needs partial registers on v8. On v9, structures with integer
6999 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
7000 values that begin in the last fp reg [where "last fp reg" varies with the
7001 mode] will be split between that reg and memory. */
7002
7003 static int
7004 sparc_arg_partial_bytes (cumulative_args_t cum, machine_mode mode,
7005 tree type, bool named)
7006 {
7007 int slotno, regno, padding;
7008
7009 /* We pass false for incoming_p here, it doesn't matter. */
7010 slotno = function_arg_slotno (get_cumulative_args (cum), mode, type, named,
7011 false, &regno, &padding);
7012
7013 if (slotno == -1)
7014 return 0;
7015
7016 if (TARGET_ARCH32)
7017 {
7018 if ((slotno + (mode == BLKmode
7019 ? ROUND_ADVANCE (int_size_in_bytes (type))
7020 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
7021 > SPARC_INT_ARG_MAX)
7022 return (SPARC_INT_ARG_MAX - slotno) * UNITS_PER_WORD;
7023 }
7024 else
7025 {
7026 /* We are guaranteed by pass_by_reference that the size of the
7027 argument is not greater than 16 bytes, so we only need to return
7028 one word if the argument is partially passed in registers. */
7029
7030 if (type && AGGREGATE_TYPE_P (type))
7031 {
7032 int size = int_size_in_bytes (type);
7033
7034 if (size > UNITS_PER_WORD
7035 && slotno == SPARC_INT_ARG_MAX - 1)
7036 return UNITS_PER_WORD;
7037 }
7038 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
7039 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
7040 && ! (TARGET_FPU && named)))
7041 {
7042 /* The complex types are passed as packed types. */
7043 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
7044 && slotno == SPARC_INT_ARG_MAX - 1)
7045 return UNITS_PER_WORD;
7046 }
7047 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
7048 {
7049 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
7050 > SPARC_FP_ARG_MAX)
7051 return UNITS_PER_WORD;
7052 }
7053 }
7054
7055 return 0;
7056 }
7057
7058 /* Handle the TARGET_PASS_BY_REFERENCE target hook.
7059 Specify whether to pass the argument by reference. */
7060
7061 static bool
7062 sparc_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED,
7063 machine_mode mode, const_tree type,
7064 bool named ATTRIBUTE_UNUSED)
7065 {
7066 if (TARGET_ARCH32)
7067 /* Original SPARC 32-bit ABI says that structures and unions,
7068 and quad-precision floats are passed by reference. For Pascal,
7069 also pass arrays by reference. All other base types are passed
7070 in registers.
7071
7072 Extended ABI (as implemented by the Sun compiler) says that all
7073 complex floats are passed by reference. Pass complex integers
7074 in registers up to 8 bytes. More generally, enforce the 2-word
7075 cap for passing arguments in registers.
7076
7077 Vector ABI (as implemented by the Sun VIS SDK) says that vector
7078 integers are passed like floats of the same size, that is in
7079 registers up to 8 bytes. Pass all vector floats by reference
7080 like structure and unions. */
7081 return ((type && (AGGREGATE_TYPE_P (type) || VECTOR_FLOAT_TYPE_P (type)))
7082 || mode == SCmode
7083 /* Catch CDImode, TFmode, DCmode and TCmode. */
7084 || GET_MODE_SIZE (mode) > 8
7085 || (type
7086 && TREE_CODE (type) == VECTOR_TYPE
7087 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
7088 else
7089 /* Original SPARC 64-bit ABI says that structures and unions
7090 smaller than 16 bytes are passed in registers, as well as
7091 all other base types.
7092
7093 Extended ABI (as implemented by the Sun compiler) says that
7094 complex floats are passed in registers up to 16 bytes. Pass
7095 all complex integers in registers up to 16 bytes. More generally,
7096 enforce the 2-word cap for passing arguments in registers.
7097
7098 Vector ABI (as implemented by the Sun VIS SDK) says that vector
7099 integers are passed like floats of the same size, that is in
7100 registers (up to 16 bytes). Pass all vector floats like structure
7101 and unions. */
7102 return ((type
7103 && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == VECTOR_TYPE)
7104 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16)
7105 /* Catch CTImode and TCmode. */
7106 || GET_MODE_SIZE (mode) > 16);
7107 }
7108
7109 /* Handle the TARGET_FUNCTION_ARG_ADVANCE hook.
7110 Update the data in CUM to advance over an argument
7111 of mode MODE and data type TYPE.
7112 TYPE is null for libcalls where that information may not be available. */
7113
7114 static void
7115 sparc_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
7116 const_tree type, bool named)
7117 {
7118 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7119 int regno, padding;
7120
7121 /* We pass false for incoming_p here, it doesn't matter. */
7122 function_arg_slotno (cum, mode, type, named, false, &regno, &padding);
7123
7124 /* If argument requires leading padding, add it. */
7125 cum->words += padding;
7126
7127 if (TARGET_ARCH32)
7128 {
7129 cum->words += (mode != BLKmode
7130 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
7131 : ROUND_ADVANCE (int_size_in_bytes (type)));
7132 }
7133 else
7134 {
7135 if (type && AGGREGATE_TYPE_P (type))
7136 {
7137 int size = int_size_in_bytes (type);
7138
7139 if (size <= 8)
7140 ++cum->words;
7141 else if (size <= 16)
7142 cum->words += 2;
7143 else /* passed by reference */
7144 ++cum->words;
7145 }
7146 else
7147 {
7148 cum->words += (mode != BLKmode
7149 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
7150 : ROUND_ADVANCE (int_size_in_bytes (type)));
7151 }
7152 }
7153 }
7154
7155 /* Handle the FUNCTION_ARG_PADDING macro.
7156 For the 64 bit ABI structs are always stored left shifted in their
7157 argument slot. */
7158
7159 enum direction
7160 function_arg_padding (machine_mode mode, const_tree type)
7161 {
7162 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
7163 return upward;
7164
7165 /* Fall back to the default. */
7166 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
7167 }
7168
7169 /* Handle the TARGET_RETURN_IN_MEMORY target hook.
7170 Specify whether to return the return value in memory. */
7171
7172 static bool
7173 sparc_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
7174 {
7175 if (TARGET_ARCH32)
7176 /* Original SPARC 32-bit ABI says that structures and unions,
7177 and quad-precision floats are returned in memory. All other
7178 base types are returned in registers.
7179
7180 Extended ABI (as implemented by the Sun compiler) says that
7181 all complex floats are returned in registers (8 FP registers
7182 at most for '_Complex long double'). Return all complex integers
7183 in registers (4 at most for '_Complex long long').
7184
7185 Vector ABI (as implemented by the Sun VIS SDK) says that vector
7186 integers are returned like floats of the same size, that is in
7187 registers up to 8 bytes and in memory otherwise. Return all
7188 vector floats in memory like structure and unions; note that
7189 they always have BLKmode like the latter. */
7190 return (TYPE_MODE (type) == BLKmode
7191 || TYPE_MODE (type) == TFmode
7192 || (TREE_CODE (type) == VECTOR_TYPE
7193 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
7194 else
7195 /* Original SPARC 64-bit ABI says that structures and unions
7196 smaller than 32 bytes are returned in registers, as well as
7197 all other base types.
7198
7199 Extended ABI (as implemented by the Sun compiler) says that all
7200 complex floats are returned in registers (8 FP registers at most
7201 for '_Complex long double'). Return all complex integers in
7202 registers (4 at most for '_Complex TItype').
7203
7204 Vector ABI (as implemented by the Sun VIS SDK) says that vector
7205 integers are returned like floats of the same size, that is in
7206 registers. Return all vector floats like structure and unions;
7207 note that they always have BLKmode like the latter. */
7208 return (TYPE_MODE (type) == BLKmode
7209 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 32);
7210 }
7211
7212 /* Handle the TARGET_STRUCT_VALUE target hook.
7213 Return where to find the structure return value address. */
7214
7215 static rtx
7216 sparc_struct_value_rtx (tree fndecl, int incoming)
7217 {
7218 if (TARGET_ARCH64)
7219 return 0;
7220 else
7221 {
7222 rtx mem;
7223
7224 if (incoming)
7225 mem = gen_frame_mem (Pmode, plus_constant (Pmode, frame_pointer_rtx,
7226 STRUCT_VALUE_OFFSET));
7227 else
7228 mem = gen_frame_mem (Pmode, plus_constant (Pmode, stack_pointer_rtx,
7229 STRUCT_VALUE_OFFSET));
7230
7231 /* Only follow the SPARC ABI for fixed-size structure returns.
7232 Variable size structure returns are handled per the normal
7233 procedures in GCC. This is enabled by -mstd-struct-return */
7234 if (incoming == 2
7235 && sparc_std_struct_return
7236 && TYPE_SIZE_UNIT (TREE_TYPE (fndecl))
7237 && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (fndecl))) == INTEGER_CST)
7238 {
7239 /* We must check and adjust the return address, as it is
7240 optional as to whether the return object is really
7241 provided. */
7242 rtx ret_reg = gen_rtx_REG (Pmode, 31);
7243 rtx scratch = gen_reg_rtx (SImode);
7244 rtx_code_label *endlab = gen_label_rtx ();
7245
7246 /* Calculate the return object size */
7247 tree size = TYPE_SIZE_UNIT (TREE_TYPE (fndecl));
7248 rtx size_rtx = GEN_INT (TREE_INT_CST_LOW (size) & 0xfff);
7249 /* Construct a temporary return value */
7250 rtx temp_val
7251 = assign_stack_local (Pmode, TREE_INT_CST_LOW (size), 0);
7252
7253 /* Implement SPARC 32-bit psABI callee return struct checking:
7254
7255 Fetch the instruction where we will return to and see if
7256 it's an unimp instruction (the most significant 10 bits
7257 will be zero). */
7258 emit_move_insn (scratch, gen_rtx_MEM (SImode,
7259 plus_constant (Pmode,
7260 ret_reg, 8)));
7261 /* Assume the size is valid and pre-adjust */
7262 emit_insn (gen_add3_insn (ret_reg, ret_reg, GEN_INT (4)));
7263 emit_cmp_and_jump_insns (scratch, size_rtx, EQ, const0_rtx, SImode,
7264 0, endlab);
7265 emit_insn (gen_sub3_insn (ret_reg, ret_reg, GEN_INT (4)));
7266 /* Write the address of the memory pointed to by temp_val into
7267 the memory pointed to by mem */
7268 emit_move_insn (mem, XEXP (temp_val, 0));
7269 emit_label (endlab);
7270 }
7271
7272 return mem;
7273 }
7274 }
7275
7276 /* Handle TARGET_FUNCTION_VALUE, and TARGET_LIBCALL_VALUE target hook.
7277 For v9, function return values are subject to the same rules as arguments,
7278 except that up to 32 bytes may be returned in registers. */
7279
7280 static rtx
7281 sparc_function_value_1 (const_tree type, machine_mode mode,
7282 bool outgoing)
7283 {
7284 /* Beware that the two values are swapped here wrt function_arg. */
7285 int regbase = (outgoing
7286 ? SPARC_INCOMING_INT_ARG_FIRST
7287 : SPARC_OUTGOING_INT_ARG_FIRST);
7288 enum mode_class mclass = GET_MODE_CLASS (mode);
7289 int regno;
7290
7291 /* Vector types deserve special treatment because they are polymorphic wrt
7292 their mode, depending upon whether VIS instructions are enabled. */
7293 if (type && TREE_CODE (type) == VECTOR_TYPE)
7294 {
7295 HOST_WIDE_INT size = int_size_in_bytes (type);
7296 gcc_assert ((TARGET_ARCH32 && size <= 8)
7297 || (TARGET_ARCH64 && size <= 32));
7298
7299 if (mode == BLKmode)
7300 return function_arg_vector_value (size, SPARC_FP_ARG_FIRST);
7301
7302 mclass = MODE_FLOAT;
7303 }
7304
7305 if (TARGET_ARCH64 && type)
7306 {
7307 /* Structures up to 32 bytes in size are returned in registers. */
7308 if (TREE_CODE (type) == RECORD_TYPE)
7309 {
7310 HOST_WIDE_INT size = int_size_in_bytes (type);
7311 gcc_assert (size <= 32);
7312
7313 return function_arg_record_value (type, mode, 0, 1, regbase);
7314 }
7315
7316 /* Unions up to 32 bytes in size are returned in integer registers. */
7317 else if (TREE_CODE (type) == UNION_TYPE)
7318 {
7319 HOST_WIDE_INT size = int_size_in_bytes (type);
7320 gcc_assert (size <= 32);
7321
7322 return function_arg_union_value (size, mode, 0, regbase);
7323 }
7324
7325 /* Objects that require it are returned in FP registers. */
7326 else if (mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
7327 ;
7328
7329 /* All other aggregate types are returned in an integer register in a
7330 mode corresponding to the size of the type. */
7331 else if (AGGREGATE_TYPE_P (type))
7332 {
7333 /* All other aggregate types are passed in an integer register
7334 in a mode corresponding to the size of the type. */
7335 HOST_WIDE_INT size = int_size_in_bytes (type);
7336 gcc_assert (size <= 32);
7337
7338 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
7339
7340 /* ??? We probably should have made the same ABI change in
7341 3.4.0 as the one we made for unions. The latter was
7342 required by the SCD though, while the former is not
7343 specified, so we favored compatibility and efficiency.
7344
7345 Now we're stuck for aggregates larger than 16 bytes,
7346 because OImode vanished in the meantime. Let's not
7347 try to be unduly clever, and simply follow the ABI
7348 for unions in that case. */
7349 if (mode == BLKmode)
7350 return function_arg_union_value (size, mode, 0, regbase);
7351 else
7352 mclass = MODE_INT;
7353 }
7354
7355 /* We should only have pointer and integer types at this point. This
7356 must match sparc_promote_function_mode. */
7357 else if (mclass == MODE_INT && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
7358 mode = word_mode;
7359 }
7360
7361 /* We should only have pointer and integer types at this point. This must
7362 match sparc_promote_function_mode. */
7363 else if (TARGET_ARCH32
7364 && mclass == MODE_INT
7365 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
7366 mode = word_mode;
7367
7368 if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT) && TARGET_FPU)
7369 regno = SPARC_FP_ARG_FIRST;
7370 else
7371 regno = regbase;
7372
7373 return gen_rtx_REG (mode, regno);
7374 }
7375
7376 /* Handle TARGET_FUNCTION_VALUE.
7377 On the SPARC, the value is found in the first "output" register, but the
7378 called function leaves it in the first "input" register. */
7379
7380 static rtx
7381 sparc_function_value (const_tree valtype,
7382 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
7383 bool outgoing)
7384 {
7385 return sparc_function_value_1 (valtype, TYPE_MODE (valtype), outgoing);
7386 }
7387
7388 /* Handle TARGET_LIBCALL_VALUE. */
7389
7390 static rtx
7391 sparc_libcall_value (machine_mode mode,
7392 const_rtx fun ATTRIBUTE_UNUSED)
7393 {
7394 return sparc_function_value_1 (NULL_TREE, mode, false);
7395 }
7396
7397 /* Handle FUNCTION_VALUE_REGNO_P.
7398 On the SPARC, the first "output" reg is used for integer values, and the
7399 first floating point register is used for floating point values. */
7400
7401 static bool
7402 sparc_function_value_regno_p (const unsigned int regno)
7403 {
7404 return (regno == 8 || regno == 32);
7405 }
7406
7407 /* Do what is necessary for `va_start'. We look at the current function
7408 to determine if stdarg or varargs is used and return the address of
7409 the first unnamed parameter. */
7410
7411 static rtx
7412 sparc_builtin_saveregs (void)
7413 {
7414 int first_reg = crtl->args.info.words;
7415 rtx address;
7416 int regno;
7417
7418 for (regno = first_reg; regno < SPARC_INT_ARG_MAX; regno++)
7419 emit_move_insn (gen_rtx_MEM (word_mode,
7420 gen_rtx_PLUS (Pmode,
7421 frame_pointer_rtx,
7422 GEN_INT (FIRST_PARM_OFFSET (0)
7423 + (UNITS_PER_WORD
7424 * regno)))),
7425 gen_rtx_REG (word_mode,
7426 SPARC_INCOMING_INT_ARG_FIRST + regno));
7427
7428 address = gen_rtx_PLUS (Pmode,
7429 frame_pointer_rtx,
7430 GEN_INT (FIRST_PARM_OFFSET (0)
7431 + UNITS_PER_WORD * first_reg));
7432
7433 return address;
7434 }
7435
7436 /* Implement `va_start' for stdarg. */
7437
7438 static void
7439 sparc_va_start (tree valist, rtx nextarg)
7440 {
7441 nextarg = expand_builtin_saveregs ();
7442 std_expand_builtin_va_start (valist, nextarg);
7443 }
7444
7445 /* Implement `va_arg' for stdarg. */
7446
7447 static tree
7448 sparc_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
7449 gimple_seq *post_p)
7450 {
7451 HOST_WIDE_INT size, rsize, align;
7452 tree addr, incr;
7453 bool indirect;
7454 tree ptrtype = build_pointer_type (type);
7455
7456 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
7457 {
7458 indirect = true;
7459 size = rsize = UNITS_PER_WORD;
7460 align = 0;
7461 }
7462 else
7463 {
7464 indirect = false;
7465 size = int_size_in_bytes (type);
7466 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
7467 align = 0;
7468
7469 if (TARGET_ARCH64)
7470 {
7471 /* For SPARC64, objects requiring 16-byte alignment get it. */
7472 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
7473 align = 2 * UNITS_PER_WORD;
7474
7475 /* SPARC-V9 ABI states that structures up to 16 bytes in size
7476 are left-justified in their slots. */
7477 if (AGGREGATE_TYPE_P (type))
7478 {
7479 if (size == 0)
7480 size = rsize = UNITS_PER_WORD;
7481 else
7482 size = rsize;
7483 }
7484 }
7485 }
7486
7487 incr = valist;
7488 if (align)
7489 {
7490 incr = fold_build_pointer_plus_hwi (incr, align - 1);
7491 incr = fold_convert (sizetype, incr);
7492 incr = fold_build2 (BIT_AND_EXPR, sizetype, incr,
7493 size_int (-align));
7494 incr = fold_convert (ptr_type_node, incr);
7495 }
7496
7497 gimplify_expr (&incr, pre_p, post_p, is_gimple_val, fb_rvalue);
7498 addr = incr;
7499
7500 if (BYTES_BIG_ENDIAN && size < rsize)
7501 addr = fold_build_pointer_plus_hwi (incr, rsize - size);
7502
7503 if (indirect)
7504 {
7505 addr = fold_convert (build_pointer_type (ptrtype), addr);
7506 addr = build_va_arg_indirect_ref (addr);
7507 }
7508
7509 /* If the address isn't aligned properly for the type, we need a temporary.
7510 FIXME: This is inefficient, usually we can do this in registers. */
7511 else if (align == 0 && TYPE_ALIGN (type) > BITS_PER_WORD)
7512 {
7513 tree tmp = create_tmp_var (type, "va_arg_tmp");
7514 tree dest_addr = build_fold_addr_expr (tmp);
7515 tree copy = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY),
7516 3, dest_addr, addr, size_int (rsize));
7517 TREE_ADDRESSABLE (tmp) = 1;
7518 gimplify_and_add (copy, pre_p);
7519 addr = dest_addr;
7520 }
7521
7522 else
7523 addr = fold_convert (ptrtype, addr);
7524
7525 incr = fold_build_pointer_plus_hwi (incr, rsize);
7526 gimplify_assign (valist, incr, post_p);
7527
7528 return build_va_arg_indirect_ref (addr);
7529 }
7530 \f
7531 /* Implement the TARGET_VECTOR_MODE_SUPPORTED_P target hook.
7532 Specify whether the vector mode is supported by the hardware. */
7533
7534 static bool
7535 sparc_vector_mode_supported_p (machine_mode mode)
7536 {
7537 return TARGET_VIS && VECTOR_MODE_P (mode) ? true : false;
7538 }
7539 \f
7540 /* Implement the TARGET_VECTORIZE_PREFERRED_SIMD_MODE target hook. */
7541
7542 static machine_mode
7543 sparc_preferred_simd_mode (machine_mode mode)
7544 {
7545 if (TARGET_VIS)
7546 switch (mode)
7547 {
7548 case SImode:
7549 return V2SImode;
7550 case HImode:
7551 return V4HImode;
7552 case QImode:
7553 return V8QImode;
7554
7555 default:;
7556 }
7557
7558 return word_mode;
7559 }
7560 \f
7561 /* Return the string to output an unconditional branch to LABEL, which is
7562 the operand number of the label.
7563
7564 DEST is the destination insn (i.e. the label), INSN is the source. */
7565
7566 const char *
7567 output_ubranch (rtx dest, rtx_insn *insn)
7568 {
7569 static char string[64];
7570 bool v9_form = false;
7571 int delta;
7572 char *p;
7573
7574 /* Even if we are trying to use cbcond for this, evaluate
7575 whether we can use V9 branches as our backup plan. */
7576
7577 delta = 5000000;
7578 if (INSN_ADDRESSES_SET_P ())
7579 delta = (INSN_ADDRESSES (INSN_UID (dest))
7580 - INSN_ADDRESSES (INSN_UID (insn)));
7581
7582 /* Leave some instructions for "slop". */
7583 if (TARGET_V9 && delta >= -260000 && delta < 260000)
7584 v9_form = true;
7585
7586 if (TARGET_CBCOND)
7587 {
7588 bool emit_nop = emit_cbcond_nop (insn);
7589 bool far = false;
7590 const char *rval;
7591
7592 if (delta < -500 || delta > 500)
7593 far = true;
7594
7595 if (far)
7596 {
7597 if (v9_form)
7598 rval = "ba,a,pt\t%%xcc, %l0";
7599 else
7600 rval = "b,a\t%l0";
7601 }
7602 else
7603 {
7604 if (emit_nop)
7605 rval = "cwbe\t%%g0, %%g0, %l0\n\tnop";
7606 else
7607 rval = "cwbe\t%%g0, %%g0, %l0";
7608 }
7609 return rval;
7610 }
7611
7612 if (v9_form)
7613 strcpy (string, "ba%*,pt\t%%xcc, ");
7614 else
7615 strcpy (string, "b%*\t");
7616
7617 p = strchr (string, '\0');
7618 *p++ = '%';
7619 *p++ = 'l';
7620 *p++ = '0';
7621 *p++ = '%';
7622 *p++ = '(';
7623 *p = '\0';
7624
7625 return string;
7626 }
7627
7628 /* Return the string to output a conditional branch to LABEL, which is
7629 the operand number of the label. OP is the conditional expression.
7630 XEXP (OP, 0) is assumed to be a condition code register (integer or
7631 floating point) and its mode specifies what kind of comparison we made.
7632
7633 DEST is the destination insn (i.e. the label), INSN is the source.
7634
7635 REVERSED is nonzero if we should reverse the sense of the comparison.
7636
7637 ANNUL is nonzero if we should generate an annulling branch. */
7638
7639 const char *
7640 output_cbranch (rtx op, rtx dest, int label, int reversed, int annul,
7641 rtx_insn *insn)
7642 {
7643 static char string[64];
7644 enum rtx_code code = GET_CODE (op);
7645 rtx cc_reg = XEXP (op, 0);
7646 machine_mode mode = GET_MODE (cc_reg);
7647 const char *labelno, *branch;
7648 int spaces = 8, far;
7649 char *p;
7650
7651 /* v9 branches are limited to +-1MB. If it is too far away,
7652 change
7653
7654 bne,pt %xcc, .LC30
7655
7656 to
7657
7658 be,pn %xcc, .+12
7659 nop
7660 ba .LC30
7661
7662 and
7663
7664 fbne,a,pn %fcc2, .LC29
7665
7666 to
7667
7668 fbe,pt %fcc2, .+16
7669 nop
7670 ba .LC29 */
7671
7672 far = TARGET_V9 && (get_attr_length (insn) >= 3);
7673 if (reversed ^ far)
7674 {
7675 /* Reversal of FP compares takes care -- an ordered compare
7676 becomes an unordered compare and vice versa. */
7677 if (mode == CCFPmode || mode == CCFPEmode)
7678 code = reverse_condition_maybe_unordered (code);
7679 else
7680 code = reverse_condition (code);
7681 }
7682
7683 /* Start by writing the branch condition. */
7684 if (mode == CCFPmode || mode == CCFPEmode)
7685 {
7686 switch (code)
7687 {
7688 case NE:
7689 branch = "fbne";
7690 break;
7691 case EQ:
7692 branch = "fbe";
7693 break;
7694 case GE:
7695 branch = "fbge";
7696 break;
7697 case GT:
7698 branch = "fbg";
7699 break;
7700 case LE:
7701 branch = "fble";
7702 break;
7703 case LT:
7704 branch = "fbl";
7705 break;
7706 case UNORDERED:
7707 branch = "fbu";
7708 break;
7709 case ORDERED:
7710 branch = "fbo";
7711 break;
7712 case UNGT:
7713 branch = "fbug";
7714 break;
7715 case UNLT:
7716 branch = "fbul";
7717 break;
7718 case UNEQ:
7719 branch = "fbue";
7720 break;
7721 case UNGE:
7722 branch = "fbuge";
7723 break;
7724 case UNLE:
7725 branch = "fbule";
7726 break;
7727 case LTGT:
7728 branch = "fblg";
7729 break;
7730
7731 default:
7732 gcc_unreachable ();
7733 }
7734
7735 /* ??? !v9: FP branches cannot be preceded by another floating point
7736 insn. Because there is currently no concept of pre-delay slots,
7737 we can fix this only by always emitting a nop before a floating
7738 point branch. */
7739
7740 string[0] = '\0';
7741 if (! TARGET_V9)
7742 strcpy (string, "nop\n\t");
7743 strcat (string, branch);
7744 }
7745 else
7746 {
7747 switch (code)
7748 {
7749 case NE:
7750 branch = "bne";
7751 break;
7752 case EQ:
7753 branch = "be";
7754 break;
7755 case GE:
7756 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
7757 branch = "bpos";
7758 else
7759 branch = "bge";
7760 break;
7761 case GT:
7762 branch = "bg";
7763 break;
7764 case LE:
7765 branch = "ble";
7766 break;
7767 case LT:
7768 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
7769 branch = "bneg";
7770 else
7771 branch = "bl";
7772 break;
7773 case GEU:
7774 branch = "bgeu";
7775 break;
7776 case GTU:
7777 branch = "bgu";
7778 break;
7779 case LEU:
7780 branch = "bleu";
7781 break;
7782 case LTU:
7783 branch = "blu";
7784 break;
7785
7786 default:
7787 gcc_unreachable ();
7788 }
7789 strcpy (string, branch);
7790 }
7791 spaces -= strlen (branch);
7792 p = strchr (string, '\0');
7793
7794 /* Now add the annulling, the label, and a possible noop. */
7795 if (annul && ! far)
7796 {
7797 strcpy (p, ",a");
7798 p += 2;
7799 spaces -= 2;
7800 }
7801
7802 if (TARGET_V9)
7803 {
7804 rtx note;
7805 int v8 = 0;
7806
7807 if (! far && insn && INSN_ADDRESSES_SET_P ())
7808 {
7809 int delta = (INSN_ADDRESSES (INSN_UID (dest))
7810 - INSN_ADDRESSES (INSN_UID (insn)));
7811 /* Leave some instructions for "slop". */
7812 if (delta < -260000 || delta >= 260000)
7813 v8 = 1;
7814 }
7815
7816 if (mode == CCFPmode || mode == CCFPEmode)
7817 {
7818 static char v9_fcc_labelno[] = "%%fccX, ";
7819 /* Set the char indicating the number of the fcc reg to use. */
7820 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
7821 labelno = v9_fcc_labelno;
7822 if (v8)
7823 {
7824 gcc_assert (REGNO (cc_reg) == SPARC_FCC_REG);
7825 labelno = "";
7826 }
7827 }
7828 else if (mode == CCXmode || mode == CCX_NOOVmode)
7829 {
7830 labelno = "%%xcc, ";
7831 gcc_assert (! v8);
7832 }
7833 else
7834 {
7835 labelno = "%%icc, ";
7836 if (v8)
7837 labelno = "";
7838 }
7839
7840 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
7841 {
7842 strcpy (p,
7843 ((XINT (note, 0) >= REG_BR_PROB_BASE / 2) ^ far)
7844 ? ",pt" : ",pn");
7845 p += 3;
7846 spaces -= 3;
7847 }
7848 }
7849 else
7850 labelno = "";
7851
7852 if (spaces > 0)
7853 *p++ = '\t';
7854 else
7855 *p++ = ' ';
7856 strcpy (p, labelno);
7857 p = strchr (p, '\0');
7858 if (far)
7859 {
7860 strcpy (p, ".+12\n\t nop\n\tb\t");
7861 /* Skip the next insn if requested or
7862 if we know that it will be a nop. */
7863 if (annul || ! final_sequence)
7864 p[3] = '6';
7865 p += 14;
7866 }
7867 *p++ = '%';
7868 *p++ = 'l';
7869 *p++ = label + '0';
7870 *p++ = '%';
7871 *p++ = '#';
7872 *p = '\0';
7873
7874 return string;
7875 }
7876
7877 /* Emit a library call comparison between floating point X and Y.
7878 COMPARISON is the operator to compare with (EQ, NE, GT, etc).
7879 Return the new operator to be used in the comparison sequence.
7880
7881 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
7882 values as arguments instead of the TFmode registers themselves,
7883 that's why we cannot call emit_float_lib_cmp. */
7884
7885 rtx
7886 sparc_emit_float_lib_cmp (rtx x, rtx y, enum rtx_code comparison)
7887 {
7888 const char *qpfunc;
7889 rtx slot0, slot1, result, tem, tem2, libfunc;
7890 machine_mode mode;
7891 enum rtx_code new_comparison;
7892
7893 switch (comparison)
7894 {
7895 case EQ:
7896 qpfunc = (TARGET_ARCH64 ? "_Qp_feq" : "_Q_feq");
7897 break;
7898
7899 case NE:
7900 qpfunc = (TARGET_ARCH64 ? "_Qp_fne" : "_Q_fne");
7901 break;
7902
7903 case GT:
7904 qpfunc = (TARGET_ARCH64 ? "_Qp_fgt" : "_Q_fgt");
7905 break;
7906
7907 case GE:
7908 qpfunc = (TARGET_ARCH64 ? "_Qp_fge" : "_Q_fge");
7909 break;
7910
7911 case LT:
7912 qpfunc = (TARGET_ARCH64 ? "_Qp_flt" : "_Q_flt");
7913 break;
7914
7915 case LE:
7916 qpfunc = (TARGET_ARCH64 ? "_Qp_fle" : "_Q_fle");
7917 break;
7918
7919 case ORDERED:
7920 case UNORDERED:
7921 case UNGT:
7922 case UNLT:
7923 case UNEQ:
7924 case UNGE:
7925 case UNLE:
7926 case LTGT:
7927 qpfunc = (TARGET_ARCH64 ? "_Qp_cmp" : "_Q_cmp");
7928 break;
7929
7930 default:
7931 gcc_unreachable ();
7932 }
7933
7934 if (TARGET_ARCH64)
7935 {
7936 if (MEM_P (x))
7937 {
7938 tree expr = MEM_EXPR (x);
7939 if (expr)
7940 mark_addressable (expr);
7941 slot0 = x;
7942 }
7943 else
7944 {
7945 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode));
7946 emit_move_insn (slot0, x);
7947 }
7948
7949 if (MEM_P (y))
7950 {
7951 tree expr = MEM_EXPR (y);
7952 if (expr)
7953 mark_addressable (expr);
7954 slot1 = y;
7955 }
7956 else
7957 {
7958 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode));
7959 emit_move_insn (slot1, y);
7960 }
7961
7962 libfunc = gen_rtx_SYMBOL_REF (Pmode, qpfunc);
7963 emit_library_call (libfunc, LCT_NORMAL,
7964 DImode, 2,
7965 XEXP (slot0, 0), Pmode,
7966 XEXP (slot1, 0), Pmode);
7967 mode = DImode;
7968 }
7969 else
7970 {
7971 libfunc = gen_rtx_SYMBOL_REF (Pmode, qpfunc);
7972 emit_library_call (libfunc, LCT_NORMAL,
7973 SImode, 2,
7974 x, TFmode, y, TFmode);
7975 mode = SImode;
7976 }
7977
7978
7979 /* Immediately move the result of the libcall into a pseudo
7980 register so reload doesn't clobber the value if it needs
7981 the return register for a spill reg. */
7982 result = gen_reg_rtx (mode);
7983 emit_move_insn (result, hard_libcall_value (mode, libfunc));
7984
7985 switch (comparison)
7986 {
7987 default:
7988 return gen_rtx_NE (VOIDmode, result, const0_rtx);
7989 case ORDERED:
7990 case UNORDERED:
7991 new_comparison = (comparison == UNORDERED ? EQ : NE);
7992 return gen_rtx_fmt_ee (new_comparison, VOIDmode, result, GEN_INT(3));
7993 case UNGT:
7994 case UNGE:
7995 new_comparison = (comparison == UNGT ? GT : NE);
7996 return gen_rtx_fmt_ee (new_comparison, VOIDmode, result, const1_rtx);
7997 case UNLE:
7998 return gen_rtx_NE (VOIDmode, result, const2_rtx);
7999 case UNLT:
8000 tem = gen_reg_rtx (mode);
8001 if (TARGET_ARCH32)
8002 emit_insn (gen_andsi3 (tem, result, const1_rtx));
8003 else
8004 emit_insn (gen_anddi3 (tem, result, const1_rtx));
8005 return gen_rtx_NE (VOIDmode, tem, const0_rtx);
8006 case UNEQ:
8007 case LTGT:
8008 tem = gen_reg_rtx (mode);
8009 if (TARGET_ARCH32)
8010 emit_insn (gen_addsi3 (tem, result, const1_rtx));
8011 else
8012 emit_insn (gen_adddi3 (tem, result, const1_rtx));
8013 tem2 = gen_reg_rtx (mode);
8014 if (TARGET_ARCH32)
8015 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
8016 else
8017 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
8018 new_comparison = (comparison == UNEQ ? EQ : NE);
8019 return gen_rtx_fmt_ee (new_comparison, VOIDmode, tem2, const0_rtx);
8020 }
8021
8022 gcc_unreachable ();
8023 }
8024
8025 /* Generate an unsigned DImode to FP conversion. This is the same code
8026 optabs would emit if we didn't have TFmode patterns. */
8027
8028 void
8029 sparc_emit_floatunsdi (rtx *operands, machine_mode mode)
8030 {
8031 rtx i0, i1, f0, in, out;
8032
8033 out = operands[0];
8034 in = force_reg (DImode, operands[1]);
8035 rtx_code_label *neglab = gen_label_rtx ();
8036 rtx_code_label *donelab = gen_label_rtx ();
8037 i0 = gen_reg_rtx (DImode);
8038 i1 = gen_reg_rtx (DImode);
8039 f0 = gen_reg_rtx (mode);
8040
8041 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
8042
8043 emit_insn (gen_rtx_SET (out, gen_rtx_FLOAT (mode, in)));
8044 emit_jump_insn (gen_jump (donelab));
8045 emit_barrier ();
8046
8047 emit_label (neglab);
8048
8049 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
8050 emit_insn (gen_anddi3 (i1, in, const1_rtx));
8051 emit_insn (gen_iordi3 (i0, i0, i1));
8052 emit_insn (gen_rtx_SET (f0, gen_rtx_FLOAT (mode, i0)));
8053 emit_insn (gen_rtx_SET (out, gen_rtx_PLUS (mode, f0, f0)));
8054
8055 emit_label (donelab);
8056 }
8057
8058 /* Generate an FP to unsigned DImode conversion. This is the same code
8059 optabs would emit if we didn't have TFmode patterns. */
8060
8061 void
8062 sparc_emit_fixunsdi (rtx *operands, machine_mode mode)
8063 {
8064 rtx i0, i1, f0, in, out, limit;
8065
8066 out = operands[0];
8067 in = force_reg (mode, operands[1]);
8068 rtx_code_label *neglab = gen_label_rtx ();
8069 rtx_code_label *donelab = gen_label_rtx ();
8070 i0 = gen_reg_rtx (DImode);
8071 i1 = gen_reg_rtx (DImode);
8072 limit = gen_reg_rtx (mode);
8073 f0 = gen_reg_rtx (mode);
8074
8075 emit_move_insn (limit,
8076 CONST_DOUBLE_FROM_REAL_VALUE (
8077 REAL_VALUE_ATOF ("9223372036854775808.0", mode), mode));
8078 emit_cmp_and_jump_insns (in, limit, GE, NULL_RTX, mode, 0, neglab);
8079
8080 emit_insn (gen_rtx_SET (out,
8081 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, in))));
8082 emit_jump_insn (gen_jump (donelab));
8083 emit_barrier ();
8084
8085 emit_label (neglab);
8086
8087 emit_insn (gen_rtx_SET (f0, gen_rtx_MINUS (mode, in, limit)));
8088 emit_insn (gen_rtx_SET (i0,
8089 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, f0))));
8090 emit_insn (gen_movdi (i1, const1_rtx));
8091 emit_insn (gen_ashldi3 (i1, i1, GEN_INT (63)));
8092 emit_insn (gen_xordi3 (out, i0, i1));
8093
8094 emit_label (donelab);
8095 }
8096
8097 /* Return the string to output a compare and branch instruction to DEST.
8098 DEST is the destination insn (i.e. the label), INSN is the source,
8099 and OP is the conditional expression. */
8100
8101 const char *
8102 output_cbcond (rtx op, rtx dest, rtx_insn *insn)
8103 {
8104 machine_mode mode = GET_MODE (XEXP (op, 0));
8105 enum rtx_code code = GET_CODE (op);
8106 const char *cond_str, *tmpl;
8107 int far, emit_nop, len;
8108 static char string[64];
8109 char size_char;
8110
8111 /* Compare and Branch is limited to +-2KB. If it is too far away,
8112 change
8113
8114 cxbne X, Y, .LC30
8115
8116 to
8117
8118 cxbe X, Y, .+16
8119 nop
8120 ba,pt xcc, .LC30
8121 nop */
8122
8123 len = get_attr_length (insn);
8124
8125 far = len == 4;
8126 emit_nop = len == 2;
8127
8128 if (far)
8129 code = reverse_condition (code);
8130
8131 size_char = ((mode == SImode) ? 'w' : 'x');
8132
8133 switch (code)
8134 {
8135 case NE:
8136 cond_str = "ne";
8137 break;
8138
8139 case EQ:
8140 cond_str = "e";
8141 break;
8142
8143 case GE:
8144 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
8145 cond_str = "pos";
8146 else
8147 cond_str = "ge";
8148 break;
8149
8150 case GT:
8151 cond_str = "g";
8152 break;
8153
8154 case LE:
8155 cond_str = "le";
8156 break;
8157
8158 case LT:
8159 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
8160 cond_str = "neg";
8161 else
8162 cond_str = "l";
8163 break;
8164
8165 case GEU:
8166 cond_str = "cc";
8167 break;
8168
8169 case GTU:
8170 cond_str = "gu";
8171 break;
8172
8173 case LEU:
8174 cond_str = "leu";
8175 break;
8176
8177 case LTU:
8178 cond_str = "cs";
8179 break;
8180
8181 default:
8182 gcc_unreachable ();
8183 }
8184
8185 if (far)
8186 {
8187 int veryfar = 1, delta;
8188
8189 if (INSN_ADDRESSES_SET_P ())
8190 {
8191 delta = (INSN_ADDRESSES (INSN_UID (dest))
8192 - INSN_ADDRESSES (INSN_UID (insn)));
8193 /* Leave some instructions for "slop". */
8194 if (delta >= -260000 && delta < 260000)
8195 veryfar = 0;
8196 }
8197
8198 if (veryfar)
8199 tmpl = "c%cb%s\t%%1, %%2, .+16\n\tnop\n\tb\t%%3\n\tnop";
8200 else
8201 tmpl = "c%cb%s\t%%1, %%2, .+16\n\tnop\n\tba,pt\t%%%%xcc, %%3\n\tnop";
8202 }
8203 else
8204 {
8205 if (emit_nop)
8206 tmpl = "c%cb%s\t%%1, %%2, %%3\n\tnop";
8207 else
8208 tmpl = "c%cb%s\t%%1, %%2, %%3";
8209 }
8210
8211 snprintf (string, sizeof(string), tmpl, size_char, cond_str);
8212
8213 return string;
8214 }
8215
8216 /* Return the string to output a conditional branch to LABEL, testing
8217 register REG. LABEL is the operand number of the label; REG is the
8218 operand number of the reg. OP is the conditional expression. The mode
8219 of REG says what kind of comparison we made.
8220
8221 DEST is the destination insn (i.e. the label), INSN is the source.
8222
8223 REVERSED is nonzero if we should reverse the sense of the comparison.
8224
8225 ANNUL is nonzero if we should generate an annulling branch. */
8226
8227 const char *
8228 output_v9branch (rtx op, rtx dest, int reg, int label, int reversed,
8229 int annul, rtx_insn *insn)
8230 {
8231 static char string[64];
8232 enum rtx_code code = GET_CODE (op);
8233 machine_mode mode = GET_MODE (XEXP (op, 0));
8234 rtx note;
8235 int far;
8236 char *p;
8237
8238 /* branch on register are limited to +-128KB. If it is too far away,
8239 change
8240
8241 brnz,pt %g1, .LC30
8242
8243 to
8244
8245 brz,pn %g1, .+12
8246 nop
8247 ba,pt %xcc, .LC30
8248
8249 and
8250
8251 brgez,a,pn %o1, .LC29
8252
8253 to
8254
8255 brlz,pt %o1, .+16
8256 nop
8257 ba,pt %xcc, .LC29 */
8258
8259 far = get_attr_length (insn) >= 3;
8260
8261 /* If not floating-point or if EQ or NE, we can just reverse the code. */
8262 if (reversed ^ far)
8263 code = reverse_condition (code);
8264
8265 /* Only 64 bit versions of these instructions exist. */
8266 gcc_assert (mode == DImode);
8267
8268 /* Start by writing the branch condition. */
8269
8270 switch (code)
8271 {
8272 case NE:
8273 strcpy (string, "brnz");
8274 break;
8275
8276 case EQ:
8277 strcpy (string, "brz");
8278 break;
8279
8280 case GE:
8281 strcpy (string, "brgez");
8282 break;
8283
8284 case LT:
8285 strcpy (string, "brlz");
8286 break;
8287
8288 case LE:
8289 strcpy (string, "brlez");
8290 break;
8291
8292 case GT:
8293 strcpy (string, "brgz");
8294 break;
8295
8296 default:
8297 gcc_unreachable ();
8298 }
8299
8300 p = strchr (string, '\0');
8301
8302 /* Now add the annulling, reg, label, and nop. */
8303 if (annul && ! far)
8304 {
8305 strcpy (p, ",a");
8306 p += 2;
8307 }
8308
8309 if (insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
8310 {
8311 strcpy (p,
8312 ((XINT (note, 0) >= REG_BR_PROB_BASE / 2) ^ far)
8313 ? ",pt" : ",pn");
8314 p += 3;
8315 }
8316
8317 *p = p < string + 8 ? '\t' : ' ';
8318 p++;
8319 *p++ = '%';
8320 *p++ = '0' + reg;
8321 *p++ = ',';
8322 *p++ = ' ';
8323 if (far)
8324 {
8325 int veryfar = 1, delta;
8326
8327 if (INSN_ADDRESSES_SET_P ())
8328 {
8329 delta = (INSN_ADDRESSES (INSN_UID (dest))
8330 - INSN_ADDRESSES (INSN_UID (insn)));
8331 /* Leave some instructions for "slop". */
8332 if (delta >= -260000 && delta < 260000)
8333 veryfar = 0;
8334 }
8335
8336 strcpy (p, ".+12\n\t nop\n\t");
8337 /* Skip the next insn if requested or
8338 if we know that it will be a nop. */
8339 if (annul || ! final_sequence)
8340 p[3] = '6';
8341 p += 12;
8342 if (veryfar)
8343 {
8344 strcpy (p, "b\t");
8345 p += 2;
8346 }
8347 else
8348 {
8349 strcpy (p, "ba,pt\t%%xcc, ");
8350 p += 13;
8351 }
8352 }
8353 *p++ = '%';
8354 *p++ = 'l';
8355 *p++ = '0' + label;
8356 *p++ = '%';
8357 *p++ = '#';
8358 *p = '\0';
8359
8360 return string;
8361 }
8362
8363 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
8364 Such instructions cannot be used in the delay slot of return insn on v9.
8365 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
8366 */
8367
8368 static int
8369 epilogue_renumber (register rtx *where, int test)
8370 {
8371 register const char *fmt;
8372 register int i;
8373 register enum rtx_code code;
8374
8375 if (*where == 0)
8376 return 0;
8377
8378 code = GET_CODE (*where);
8379
8380 switch (code)
8381 {
8382 case REG:
8383 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
8384 return 1;
8385 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
8386 *where = gen_rtx_REG (GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
8387 case SCRATCH:
8388 case CC0:
8389 case PC:
8390 case CONST_INT:
8391 case CONST_DOUBLE:
8392 return 0;
8393
8394 /* Do not replace the frame pointer with the stack pointer because
8395 it can cause the delayed instruction to load below the stack.
8396 This occurs when instructions like:
8397
8398 (set (reg/i:SI 24 %i0)
8399 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
8400 (const_int -20 [0xffffffec])) 0))
8401
8402 are in the return delayed slot. */
8403 case PLUS:
8404 if (GET_CODE (XEXP (*where, 0)) == REG
8405 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
8406 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
8407 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
8408 return 1;
8409 break;
8410
8411 case MEM:
8412 if (SPARC_STACK_BIAS
8413 && GET_CODE (XEXP (*where, 0)) == REG
8414 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
8415 return 1;
8416 break;
8417
8418 default:
8419 break;
8420 }
8421
8422 fmt = GET_RTX_FORMAT (code);
8423
8424 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
8425 {
8426 if (fmt[i] == 'E')
8427 {
8428 register int j;
8429 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
8430 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
8431 return 1;
8432 }
8433 else if (fmt[i] == 'e'
8434 && epilogue_renumber (&(XEXP (*where, i)), test))
8435 return 1;
8436 }
8437 return 0;
8438 }
8439 \f
8440 /* Leaf functions and non-leaf functions have different needs. */
8441
8442 static const int
8443 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
8444
8445 static const int
8446 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
8447
8448 static const int *const reg_alloc_orders[] = {
8449 reg_leaf_alloc_order,
8450 reg_nonleaf_alloc_order};
8451
8452 void
8453 order_regs_for_local_alloc (void)
8454 {
8455 static int last_order_nonleaf = 1;
8456
8457 if (df_regs_ever_live_p (15) != last_order_nonleaf)
8458 {
8459 last_order_nonleaf = !last_order_nonleaf;
8460 memcpy ((char *) reg_alloc_order,
8461 (const char *) reg_alloc_orders[last_order_nonleaf],
8462 FIRST_PSEUDO_REGISTER * sizeof (int));
8463 }
8464 }
8465 \f
8466 /* Return 1 if REG and MEM are legitimate enough to allow the various
8467 mem<-->reg splits to be run. */
8468
8469 int
8470 sparc_splitdi_legitimate (rtx reg, rtx mem)
8471 {
8472 /* Punt if we are here by mistake. */
8473 gcc_assert (reload_completed);
8474
8475 /* We must have an offsettable memory reference. */
8476 if (! offsettable_memref_p (mem))
8477 return 0;
8478
8479 /* If we have legitimate args for ldd/std, we do not want
8480 the split to happen. */
8481 if ((REGNO (reg) % 2) == 0
8482 && mem_min_alignment (mem, 8))
8483 return 0;
8484
8485 /* Success. */
8486 return 1;
8487 }
8488
8489 /* Like sparc_splitdi_legitimate but for REG <--> REG moves. */
8490
8491 int
8492 sparc_split_regreg_legitimate (rtx reg1, rtx reg2)
8493 {
8494 int regno1, regno2;
8495
8496 if (GET_CODE (reg1) == SUBREG)
8497 reg1 = SUBREG_REG (reg1);
8498 if (GET_CODE (reg1) != REG)
8499 return 0;
8500 regno1 = REGNO (reg1);
8501
8502 if (GET_CODE (reg2) == SUBREG)
8503 reg2 = SUBREG_REG (reg2);
8504 if (GET_CODE (reg2) != REG)
8505 return 0;
8506 regno2 = REGNO (reg2);
8507
8508 if (SPARC_INT_REG_P (regno1) && SPARC_INT_REG_P (regno2))
8509 return 1;
8510
8511 if (TARGET_VIS3)
8512 {
8513 if ((SPARC_INT_REG_P (regno1) && SPARC_FP_REG_P (regno2))
8514 || (SPARC_FP_REG_P (regno1) && SPARC_INT_REG_P (regno2)))
8515 return 1;
8516 }
8517
8518 return 0;
8519 }
8520
8521 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
8522 This makes them candidates for using ldd and std insns.
8523
8524 Note reg1 and reg2 *must* be hard registers. */
8525
8526 int
8527 registers_ok_for_ldd_peep (rtx reg1, rtx reg2)
8528 {
8529 /* We might have been passed a SUBREG. */
8530 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
8531 return 0;
8532
8533 if (REGNO (reg1) % 2 != 0)
8534 return 0;
8535
8536 /* Integer ldd is deprecated in SPARC V9 */
8537 if (TARGET_V9 && SPARC_INT_REG_P (REGNO (reg1)))
8538 return 0;
8539
8540 return (REGNO (reg1) == REGNO (reg2) - 1);
8541 }
8542
8543 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
8544 an ldd or std insn.
8545
8546 This can only happen when addr1 and addr2, the addresses in mem1
8547 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
8548 addr1 must also be aligned on a 64-bit boundary.
8549
8550 Also iff dependent_reg_rtx is not null it should not be used to
8551 compute the address for mem1, i.e. we cannot optimize a sequence
8552 like:
8553 ld [%o0], %o0
8554 ld [%o0 + 4], %o1
8555 to
8556 ldd [%o0], %o0
8557 nor:
8558 ld [%g3 + 4], %g3
8559 ld [%g3], %g2
8560 to
8561 ldd [%g3], %g2
8562
8563 But, note that the transformation from:
8564 ld [%g2 + 4], %g3
8565 ld [%g2], %g2
8566 to
8567 ldd [%g2], %g2
8568 is perfectly fine. Thus, the peephole2 patterns always pass us
8569 the destination register of the first load, never the second one.
8570
8571 For stores we don't have a similar problem, so dependent_reg_rtx is
8572 NULL_RTX. */
8573
8574 int
8575 mems_ok_for_ldd_peep (rtx mem1, rtx mem2, rtx dependent_reg_rtx)
8576 {
8577 rtx addr1, addr2;
8578 unsigned int reg1;
8579 HOST_WIDE_INT offset1;
8580
8581 /* The mems cannot be volatile. */
8582 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
8583 return 0;
8584
8585 /* MEM1 should be aligned on a 64-bit boundary. */
8586 if (MEM_ALIGN (mem1) < 64)
8587 return 0;
8588
8589 addr1 = XEXP (mem1, 0);
8590 addr2 = XEXP (mem2, 0);
8591
8592 /* Extract a register number and offset (if used) from the first addr. */
8593 if (GET_CODE (addr1) == PLUS)
8594 {
8595 /* If not a REG, return zero. */
8596 if (GET_CODE (XEXP (addr1, 0)) != REG)
8597 return 0;
8598 else
8599 {
8600 reg1 = REGNO (XEXP (addr1, 0));
8601 /* The offset must be constant! */
8602 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
8603 return 0;
8604 offset1 = INTVAL (XEXP (addr1, 1));
8605 }
8606 }
8607 else if (GET_CODE (addr1) != REG)
8608 return 0;
8609 else
8610 {
8611 reg1 = REGNO (addr1);
8612 /* This was a simple (mem (reg)) expression. Offset is 0. */
8613 offset1 = 0;
8614 }
8615
8616 /* Make sure the second address is a (mem (plus (reg) (const_int). */
8617 if (GET_CODE (addr2) != PLUS)
8618 return 0;
8619
8620 if (GET_CODE (XEXP (addr2, 0)) != REG
8621 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
8622 return 0;
8623
8624 if (reg1 != REGNO (XEXP (addr2, 0)))
8625 return 0;
8626
8627 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
8628 return 0;
8629
8630 /* The first offset must be evenly divisible by 8 to ensure the
8631 address is 64 bit aligned. */
8632 if (offset1 % 8 != 0)
8633 return 0;
8634
8635 /* The offset for the second addr must be 4 more than the first addr. */
8636 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
8637 return 0;
8638
8639 /* All the tests passed. addr1 and addr2 are valid for ldd and std
8640 instructions. */
8641 return 1;
8642 }
8643
8644 /* Return the widened memory access made of MEM1 and MEM2 in MODE. */
8645
8646 rtx
8647 widen_mem_for_ldd_peep (rtx mem1, rtx mem2, machine_mode mode)
8648 {
8649 rtx x = widen_memory_access (mem1, mode, 0);
8650 MEM_NOTRAP_P (x) = MEM_NOTRAP_P (mem1) && MEM_NOTRAP_P (mem2);
8651 return x;
8652 }
8653
8654 /* Return 1 if reg is a pseudo, or is the first register in
8655 a hard register pair. This makes it suitable for use in
8656 ldd and std insns. */
8657
8658 int
8659 register_ok_for_ldd (rtx reg)
8660 {
8661 /* We might have been passed a SUBREG. */
8662 if (!REG_P (reg))
8663 return 0;
8664
8665 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
8666 return (REGNO (reg) % 2 == 0);
8667
8668 return 1;
8669 }
8670
8671 /* Return 1 if OP, a MEM, has an address which is known to be
8672 aligned to an 8-byte boundary. */
8673
8674 int
8675 memory_ok_for_ldd (rtx op)
8676 {
8677 /* In 64-bit mode, we assume that the address is word-aligned. */
8678 if (TARGET_ARCH32 && !mem_min_alignment (op, 8))
8679 return 0;
8680
8681 if (! can_create_pseudo_p ()
8682 && !strict_memory_address_p (Pmode, XEXP (op, 0)))
8683 return 0;
8684
8685 return 1;
8686 }
8687 \f
8688 /* Implement TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
8689
8690 static bool
8691 sparc_print_operand_punct_valid_p (unsigned char code)
8692 {
8693 if (code == '#'
8694 || code == '*'
8695 || code == '('
8696 || code == ')'
8697 || code == '_'
8698 || code == '&')
8699 return true;
8700
8701 return false;
8702 }
8703
8704 /* Implement TARGET_PRINT_OPERAND.
8705 Print operand X (an rtx) in assembler syntax to file FILE.
8706 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
8707 For `%' followed by punctuation, CODE is the punctuation and X is null. */
8708
8709 static void
8710 sparc_print_operand (FILE *file, rtx x, int code)
8711 {
8712 switch (code)
8713 {
8714 case '#':
8715 /* Output an insn in a delay slot. */
8716 if (final_sequence)
8717 sparc_indent_opcode = 1;
8718 else
8719 fputs ("\n\t nop", file);
8720 return;
8721 case '*':
8722 /* Output an annul flag if there's nothing for the delay slot and we
8723 are optimizing. This is always used with '(' below.
8724 Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
8725 this is a dbx bug. So, we only do this when optimizing.
8726 On UltraSPARC, a branch in a delay slot causes a pipeline flush.
8727 Always emit a nop in case the next instruction is a branch. */
8728 if (! final_sequence && (optimize && (int)sparc_cpu < PROCESSOR_V9))
8729 fputs (",a", file);
8730 return;
8731 case '(':
8732 /* Output a 'nop' if there's nothing for the delay slot and we are
8733 not optimizing. This is always used with '*' above. */
8734 if (! final_sequence && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
8735 fputs ("\n\t nop", file);
8736 else if (final_sequence)
8737 sparc_indent_opcode = 1;
8738 return;
8739 case ')':
8740 /* Output the right displacement from the saved PC on function return.
8741 The caller may have placed an "unimp" insn immediately after the call
8742 so we have to account for it. This insn is used in the 32-bit ABI
8743 when calling a function that returns a non zero-sized structure. The
8744 64-bit ABI doesn't have it. Be careful to have this test be the same
8745 as that for the call. The exception is when sparc_std_struct_return
8746 is enabled, the psABI is followed exactly and the adjustment is made
8747 by the code in sparc_struct_value_rtx. The call emitted is the same
8748 when sparc_std_struct_return is enabled. */
8749 if (!TARGET_ARCH64
8750 && cfun->returns_struct
8751 && !sparc_std_struct_return
8752 && DECL_SIZE (DECL_RESULT (current_function_decl))
8753 && TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl)))
8754 == INTEGER_CST
8755 && !integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))))
8756 fputs ("12", file);
8757 else
8758 fputc ('8', file);
8759 return;
8760 case '_':
8761 /* Output the Embedded Medium/Anywhere code model base register. */
8762 fputs (EMBMEDANY_BASE_REG, file);
8763 return;
8764 case '&':
8765 /* Print some local dynamic TLS name. */
8766 if (const char *name = get_some_local_dynamic_name ())
8767 assemble_name (file, name);
8768 else
8769 output_operand_lossage ("'%%&' used without any "
8770 "local dynamic TLS references");
8771 return;
8772
8773 case 'Y':
8774 /* Adjust the operand to take into account a RESTORE operation. */
8775 if (GET_CODE (x) == CONST_INT)
8776 break;
8777 else if (GET_CODE (x) != REG)
8778 output_operand_lossage ("invalid %%Y operand");
8779 else if (REGNO (x) < 8)
8780 fputs (reg_names[REGNO (x)], file);
8781 else if (REGNO (x) >= 24 && REGNO (x) < 32)
8782 fputs (reg_names[REGNO (x)-16], file);
8783 else
8784 output_operand_lossage ("invalid %%Y operand");
8785 return;
8786 case 'L':
8787 /* Print out the low order register name of a register pair. */
8788 if (WORDS_BIG_ENDIAN)
8789 fputs (reg_names[REGNO (x)+1], file);
8790 else
8791 fputs (reg_names[REGNO (x)], file);
8792 return;
8793 case 'H':
8794 /* Print out the high order register name of a register pair. */
8795 if (WORDS_BIG_ENDIAN)
8796 fputs (reg_names[REGNO (x)], file);
8797 else
8798 fputs (reg_names[REGNO (x)+1], file);
8799 return;
8800 case 'R':
8801 /* Print out the second register name of a register pair or quad.
8802 I.e., R (%o0) => %o1. */
8803 fputs (reg_names[REGNO (x)+1], file);
8804 return;
8805 case 'S':
8806 /* Print out the third register name of a register quad.
8807 I.e., S (%o0) => %o2. */
8808 fputs (reg_names[REGNO (x)+2], file);
8809 return;
8810 case 'T':
8811 /* Print out the fourth register name of a register quad.
8812 I.e., T (%o0) => %o3. */
8813 fputs (reg_names[REGNO (x)+3], file);
8814 return;
8815 case 'x':
8816 /* Print a condition code register. */
8817 if (REGNO (x) == SPARC_ICC_REG)
8818 {
8819 /* We don't handle CC[X]_NOOVmode because they're not supposed
8820 to occur here. */
8821 if (GET_MODE (x) == CCmode)
8822 fputs ("%icc", file);
8823 else if (GET_MODE (x) == CCXmode)
8824 fputs ("%xcc", file);
8825 else
8826 gcc_unreachable ();
8827 }
8828 else
8829 /* %fccN register */
8830 fputs (reg_names[REGNO (x)], file);
8831 return;
8832 case 'm':
8833 /* Print the operand's address only. */
8834 output_address (XEXP (x, 0));
8835 return;
8836 case 'r':
8837 /* In this case we need a register. Use %g0 if the
8838 operand is const0_rtx. */
8839 if (x == const0_rtx
8840 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
8841 {
8842 fputs ("%g0", file);
8843 return;
8844 }
8845 else
8846 break;
8847
8848 case 'A':
8849 switch (GET_CODE (x))
8850 {
8851 case IOR: fputs ("or", file); break;
8852 case AND: fputs ("and", file); break;
8853 case XOR: fputs ("xor", file); break;
8854 default: output_operand_lossage ("invalid %%A operand");
8855 }
8856 return;
8857
8858 case 'B':
8859 switch (GET_CODE (x))
8860 {
8861 case IOR: fputs ("orn", file); break;
8862 case AND: fputs ("andn", file); break;
8863 case XOR: fputs ("xnor", file); break;
8864 default: output_operand_lossage ("invalid %%B operand");
8865 }
8866 return;
8867
8868 /* This is used by the conditional move instructions. */
8869 case 'C':
8870 {
8871 enum rtx_code rc = GET_CODE (x);
8872
8873 switch (rc)
8874 {
8875 case NE: fputs ("ne", file); break;
8876 case EQ: fputs ("e", file); break;
8877 case GE: fputs ("ge", file); break;
8878 case GT: fputs ("g", file); break;
8879 case LE: fputs ("le", file); break;
8880 case LT: fputs ("l", file); break;
8881 case GEU: fputs ("geu", file); break;
8882 case GTU: fputs ("gu", file); break;
8883 case LEU: fputs ("leu", file); break;
8884 case LTU: fputs ("lu", file); break;
8885 case LTGT: fputs ("lg", file); break;
8886 case UNORDERED: fputs ("u", file); break;
8887 case ORDERED: fputs ("o", file); break;
8888 case UNLT: fputs ("ul", file); break;
8889 case UNLE: fputs ("ule", file); break;
8890 case UNGT: fputs ("ug", file); break;
8891 case UNGE: fputs ("uge", file); break;
8892 case UNEQ: fputs ("ue", file); break;
8893 default: output_operand_lossage ("invalid %%C operand");
8894 }
8895 return;
8896 }
8897
8898 /* This are used by the movr instruction pattern. */
8899 case 'D':
8900 {
8901 enum rtx_code rc = GET_CODE (x);
8902 switch (rc)
8903 {
8904 case NE: fputs ("ne", file); break;
8905 case EQ: fputs ("e", file); break;
8906 case GE: fputs ("gez", file); break;
8907 case LT: fputs ("lz", file); break;
8908 case LE: fputs ("lez", file); break;
8909 case GT: fputs ("gz", file); break;
8910 default: output_operand_lossage ("invalid %%D operand");
8911 }
8912 return;
8913 }
8914
8915 case 'b':
8916 {
8917 /* Print a sign-extended character. */
8918 int i = trunc_int_for_mode (INTVAL (x), QImode);
8919 fprintf (file, "%d", i);
8920 return;
8921 }
8922
8923 case 'f':
8924 /* Operand must be a MEM; write its address. */
8925 if (GET_CODE (x) != MEM)
8926 output_operand_lossage ("invalid %%f operand");
8927 output_address (XEXP (x, 0));
8928 return;
8929
8930 case 's':
8931 {
8932 /* Print a sign-extended 32-bit value. */
8933 HOST_WIDE_INT i;
8934 if (GET_CODE(x) == CONST_INT)
8935 i = INTVAL (x);
8936 else if (GET_CODE(x) == CONST_DOUBLE)
8937 i = CONST_DOUBLE_LOW (x);
8938 else
8939 {
8940 output_operand_lossage ("invalid %%s operand");
8941 return;
8942 }
8943 i = trunc_int_for_mode (i, SImode);
8944 fprintf (file, HOST_WIDE_INT_PRINT_DEC, i);
8945 return;
8946 }
8947
8948 case 0:
8949 /* Do nothing special. */
8950 break;
8951
8952 default:
8953 /* Undocumented flag. */
8954 output_operand_lossage ("invalid operand output code");
8955 }
8956
8957 if (GET_CODE (x) == REG)
8958 fputs (reg_names[REGNO (x)], file);
8959 else if (GET_CODE (x) == MEM)
8960 {
8961 fputc ('[', file);
8962 /* Poor Sun assembler doesn't understand absolute addressing. */
8963 if (CONSTANT_P (XEXP (x, 0)))
8964 fputs ("%g0+", file);
8965 output_address (XEXP (x, 0));
8966 fputc (']', file);
8967 }
8968 else if (GET_CODE (x) == HIGH)
8969 {
8970 fputs ("%hi(", file);
8971 output_addr_const (file, XEXP (x, 0));
8972 fputc (')', file);
8973 }
8974 else if (GET_CODE (x) == LO_SUM)
8975 {
8976 sparc_print_operand (file, XEXP (x, 0), 0);
8977 if (TARGET_CM_MEDMID)
8978 fputs ("+%l44(", file);
8979 else
8980 fputs ("+%lo(", file);
8981 output_addr_const (file, XEXP (x, 1));
8982 fputc (')', file);
8983 }
8984 else if (GET_CODE (x) == CONST_DOUBLE
8985 && (GET_MODE (x) == VOIDmode
8986 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
8987 {
8988 if (CONST_DOUBLE_HIGH (x) == 0)
8989 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
8990 else if (CONST_DOUBLE_HIGH (x) == -1
8991 && CONST_DOUBLE_LOW (x) < 0)
8992 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
8993 else
8994 output_operand_lossage ("long long constant not a valid immediate operand");
8995 }
8996 else if (GET_CODE (x) == CONST_DOUBLE)
8997 output_operand_lossage ("floating point constant not a valid immediate operand");
8998 else { output_addr_const (file, x); }
8999 }
9000
9001 /* Implement TARGET_PRINT_OPERAND_ADDRESS. */
9002
9003 static void
9004 sparc_print_operand_address (FILE *file, rtx x)
9005 {
9006 register rtx base, index = 0;
9007 int offset = 0;
9008 register rtx addr = x;
9009
9010 if (REG_P (addr))
9011 fputs (reg_names[REGNO (addr)], file);
9012 else if (GET_CODE (addr) == PLUS)
9013 {
9014 if (CONST_INT_P (XEXP (addr, 0)))
9015 offset = INTVAL (XEXP (addr, 0)), base = XEXP (addr, 1);
9016 else if (CONST_INT_P (XEXP (addr, 1)))
9017 offset = INTVAL (XEXP (addr, 1)), base = XEXP (addr, 0);
9018 else
9019 base = XEXP (addr, 0), index = XEXP (addr, 1);
9020 if (GET_CODE (base) == LO_SUM)
9021 {
9022 gcc_assert (USE_AS_OFFSETABLE_LO10
9023 && TARGET_ARCH64
9024 && ! TARGET_CM_MEDMID);
9025 output_operand (XEXP (base, 0), 0);
9026 fputs ("+%lo(", file);
9027 output_address (XEXP (base, 1));
9028 fprintf (file, ")+%d", offset);
9029 }
9030 else
9031 {
9032 fputs (reg_names[REGNO (base)], file);
9033 if (index == 0)
9034 fprintf (file, "%+d", offset);
9035 else if (REG_P (index))
9036 fprintf (file, "+%s", reg_names[REGNO (index)]);
9037 else if (GET_CODE (index) == SYMBOL_REF
9038 || GET_CODE (index) == LABEL_REF
9039 || GET_CODE (index) == CONST)
9040 fputc ('+', file), output_addr_const (file, index);
9041 else gcc_unreachable ();
9042 }
9043 }
9044 else if (GET_CODE (addr) == MINUS
9045 && GET_CODE (XEXP (addr, 1)) == LABEL_REF)
9046 {
9047 output_addr_const (file, XEXP (addr, 0));
9048 fputs ("-(", file);
9049 output_addr_const (file, XEXP (addr, 1));
9050 fputs ("-.)", file);
9051 }
9052 else if (GET_CODE (addr) == LO_SUM)
9053 {
9054 output_operand (XEXP (addr, 0), 0);
9055 if (TARGET_CM_MEDMID)
9056 fputs ("+%l44(", file);
9057 else
9058 fputs ("+%lo(", file);
9059 output_address (XEXP (addr, 1));
9060 fputc (')', file);
9061 }
9062 else if (flag_pic
9063 && GET_CODE (addr) == CONST
9064 && GET_CODE (XEXP (addr, 0)) == MINUS
9065 && GET_CODE (XEXP (XEXP (addr, 0), 1)) == CONST
9066 && GET_CODE (XEXP (XEXP (XEXP (addr, 0), 1), 0)) == MINUS
9067 && XEXP (XEXP (XEXP (XEXP (addr, 0), 1), 0), 1) == pc_rtx)
9068 {
9069 addr = XEXP (addr, 0);
9070 output_addr_const (file, XEXP (addr, 0));
9071 /* Group the args of the second CONST in parenthesis. */
9072 fputs ("-(", file);
9073 /* Skip past the second CONST--it does nothing for us. */
9074 output_addr_const (file, XEXP (XEXP (addr, 1), 0));
9075 /* Close the parenthesis. */
9076 fputc (')', file);
9077 }
9078 else
9079 {
9080 output_addr_const (file, addr);
9081 }
9082 }
9083 \f
9084 /* Target hook for assembling integer objects. The sparc version has
9085 special handling for aligned DI-mode objects. */
9086
9087 static bool
9088 sparc_assemble_integer (rtx x, unsigned int size, int aligned_p)
9089 {
9090 /* ??? We only output .xword's for symbols and only then in environments
9091 where the assembler can handle them. */
9092 if (aligned_p && size == 8
9093 && (GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE))
9094 {
9095 if (TARGET_V9)
9096 {
9097 assemble_integer_with_op ("\t.xword\t", x);
9098 return true;
9099 }
9100 else
9101 {
9102 assemble_aligned_integer (4, const0_rtx);
9103 assemble_aligned_integer (4, x);
9104 return true;
9105 }
9106 }
9107 return default_assemble_integer (x, size, aligned_p);
9108 }
9109 \f
9110 /* Return the value of a code used in the .proc pseudo-op that says
9111 what kind of result this function returns. For non-C types, we pick
9112 the closest C type. */
9113
9114 #ifndef SHORT_TYPE_SIZE
9115 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
9116 #endif
9117
9118 #ifndef INT_TYPE_SIZE
9119 #define INT_TYPE_SIZE BITS_PER_WORD
9120 #endif
9121
9122 #ifndef LONG_TYPE_SIZE
9123 #define LONG_TYPE_SIZE BITS_PER_WORD
9124 #endif
9125
9126 #ifndef LONG_LONG_TYPE_SIZE
9127 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
9128 #endif
9129
9130 #ifndef FLOAT_TYPE_SIZE
9131 #define FLOAT_TYPE_SIZE BITS_PER_WORD
9132 #endif
9133
9134 #ifndef DOUBLE_TYPE_SIZE
9135 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
9136 #endif
9137
9138 #ifndef LONG_DOUBLE_TYPE_SIZE
9139 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
9140 #endif
9141
9142 unsigned long
9143 sparc_type_code (register tree type)
9144 {
9145 register unsigned long qualifiers = 0;
9146 register unsigned shift;
9147
9148 /* Only the first 30 bits of the qualifier are valid. We must refrain from
9149 setting more, since some assemblers will give an error for this. Also,
9150 we must be careful to avoid shifts of 32 bits or more to avoid getting
9151 unpredictable results. */
9152
9153 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
9154 {
9155 switch (TREE_CODE (type))
9156 {
9157 case ERROR_MARK:
9158 return qualifiers;
9159
9160 case ARRAY_TYPE:
9161 qualifiers |= (3 << shift);
9162 break;
9163
9164 case FUNCTION_TYPE:
9165 case METHOD_TYPE:
9166 qualifiers |= (2 << shift);
9167 break;
9168
9169 case POINTER_TYPE:
9170 case REFERENCE_TYPE:
9171 case OFFSET_TYPE:
9172 qualifiers |= (1 << shift);
9173 break;
9174
9175 case RECORD_TYPE:
9176 return (qualifiers | 8);
9177
9178 case UNION_TYPE:
9179 case QUAL_UNION_TYPE:
9180 return (qualifiers | 9);
9181
9182 case ENUMERAL_TYPE:
9183 return (qualifiers | 10);
9184
9185 case VOID_TYPE:
9186 return (qualifiers | 16);
9187
9188 case INTEGER_TYPE:
9189 /* If this is a range type, consider it to be the underlying
9190 type. */
9191 if (TREE_TYPE (type) != 0)
9192 break;
9193
9194 /* Carefully distinguish all the standard types of C,
9195 without messing up if the language is not C. We do this by
9196 testing TYPE_PRECISION and TYPE_UNSIGNED. The old code used to
9197 look at both the names and the above fields, but that's redundant.
9198 Any type whose size is between two C types will be considered
9199 to be the wider of the two types. Also, we do not have a
9200 special code to use for "long long", so anything wider than
9201 long is treated the same. Note that we can't distinguish
9202 between "int" and "long" in this code if they are the same
9203 size, but that's fine, since neither can the assembler. */
9204
9205 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
9206 return (qualifiers | (TYPE_UNSIGNED (type) ? 12 : 2));
9207
9208 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
9209 return (qualifiers | (TYPE_UNSIGNED (type) ? 13 : 3));
9210
9211 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
9212 return (qualifiers | (TYPE_UNSIGNED (type) ? 14 : 4));
9213
9214 else
9215 return (qualifiers | (TYPE_UNSIGNED (type) ? 15 : 5));
9216
9217 case REAL_TYPE:
9218 /* If this is a range type, consider it to be the underlying
9219 type. */
9220 if (TREE_TYPE (type) != 0)
9221 break;
9222
9223 /* Carefully distinguish all the standard types of C,
9224 without messing up if the language is not C. */
9225
9226 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
9227 return (qualifiers | 6);
9228
9229 else
9230 return (qualifiers | 7);
9231
9232 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
9233 /* ??? We need to distinguish between double and float complex types,
9234 but I don't know how yet because I can't reach this code from
9235 existing front-ends. */
9236 return (qualifiers | 7); /* Who knows? */
9237
9238 case VECTOR_TYPE:
9239 case BOOLEAN_TYPE: /* Boolean truth value type. */
9240 case LANG_TYPE:
9241 case NULLPTR_TYPE:
9242 return qualifiers;
9243
9244 default:
9245 gcc_unreachable (); /* Not a type! */
9246 }
9247 }
9248
9249 return qualifiers;
9250 }
9251 \f
9252 /* Nested function support. */
9253
9254 /* Emit RTL insns to initialize the variable parts of a trampoline.
9255 FNADDR is an RTX for the address of the function's pure code.
9256 CXT is an RTX for the static chain value for the function.
9257
9258 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
9259 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
9260 (to store insns). This is a bit excessive. Perhaps a different
9261 mechanism would be better here.
9262
9263 Emit enough FLUSH insns to synchronize the data and instruction caches. */
9264
9265 static void
9266 sparc32_initialize_trampoline (rtx m_tramp, rtx fnaddr, rtx cxt)
9267 {
9268 /* SPARC 32-bit trampoline:
9269
9270 sethi %hi(fn), %g1
9271 sethi %hi(static), %g2
9272 jmp %g1+%lo(fn)
9273 or %g2, %lo(static), %g2
9274
9275 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
9276 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
9277 */
9278
9279 emit_move_insn
9280 (adjust_address (m_tramp, SImode, 0),
9281 expand_binop (SImode, ior_optab,
9282 expand_shift (RSHIFT_EXPR, SImode, fnaddr, 10, 0, 1),
9283 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
9284 NULL_RTX, 1, OPTAB_DIRECT));
9285
9286 emit_move_insn
9287 (adjust_address (m_tramp, SImode, 4),
9288 expand_binop (SImode, ior_optab,
9289 expand_shift (RSHIFT_EXPR, SImode, cxt, 10, 0, 1),
9290 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
9291 NULL_RTX, 1, OPTAB_DIRECT));
9292
9293 emit_move_insn
9294 (adjust_address (m_tramp, SImode, 8),
9295 expand_binop (SImode, ior_optab,
9296 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
9297 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
9298 NULL_RTX, 1, OPTAB_DIRECT));
9299
9300 emit_move_insn
9301 (adjust_address (m_tramp, SImode, 12),
9302 expand_binop (SImode, ior_optab,
9303 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
9304 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
9305 NULL_RTX, 1, OPTAB_DIRECT));
9306
9307 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
9308 aligned on a 16 byte boundary so one flush clears it all. */
9309 emit_insn (gen_flushsi (validize_mem (adjust_address (m_tramp, SImode, 0))));
9310 if (sparc_cpu != PROCESSOR_ULTRASPARC
9311 && sparc_cpu != PROCESSOR_ULTRASPARC3
9312 && sparc_cpu != PROCESSOR_NIAGARA
9313 && sparc_cpu != PROCESSOR_NIAGARA2
9314 && sparc_cpu != PROCESSOR_NIAGARA3
9315 && sparc_cpu != PROCESSOR_NIAGARA4)
9316 emit_insn (gen_flushsi (validize_mem (adjust_address (m_tramp, SImode, 8))));
9317
9318 /* Call __enable_execute_stack after writing onto the stack to make sure
9319 the stack address is accessible. */
9320 #ifdef HAVE_ENABLE_EXECUTE_STACK
9321 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
9322 LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
9323 #endif
9324
9325 }
9326
9327 /* The 64-bit version is simpler because it makes more sense to load the
9328 values as "immediate" data out of the trampoline. It's also easier since
9329 we can read the PC without clobbering a register. */
9330
9331 static void
9332 sparc64_initialize_trampoline (rtx m_tramp, rtx fnaddr, rtx cxt)
9333 {
9334 /* SPARC 64-bit trampoline:
9335
9336 rd %pc, %g1
9337 ldx [%g1+24], %g5
9338 jmp %g5
9339 ldx [%g1+16], %g5
9340 +16 bytes data
9341 */
9342
9343 emit_move_insn (adjust_address (m_tramp, SImode, 0),
9344 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
9345 emit_move_insn (adjust_address (m_tramp, SImode, 4),
9346 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
9347 emit_move_insn (adjust_address (m_tramp, SImode, 8),
9348 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
9349 emit_move_insn (adjust_address (m_tramp, SImode, 12),
9350 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
9351 emit_move_insn (adjust_address (m_tramp, DImode, 16), cxt);
9352 emit_move_insn (adjust_address (m_tramp, DImode, 24), fnaddr);
9353 emit_insn (gen_flushdi (validize_mem (adjust_address (m_tramp, DImode, 0))));
9354
9355 if (sparc_cpu != PROCESSOR_ULTRASPARC
9356 && sparc_cpu != PROCESSOR_ULTRASPARC3
9357 && sparc_cpu != PROCESSOR_NIAGARA
9358 && sparc_cpu != PROCESSOR_NIAGARA2
9359 && sparc_cpu != PROCESSOR_NIAGARA3
9360 && sparc_cpu != PROCESSOR_NIAGARA4)
9361 emit_insn (gen_flushdi (validize_mem (adjust_address (m_tramp, DImode, 8))));
9362
9363 /* Call __enable_execute_stack after writing onto the stack to make sure
9364 the stack address is accessible. */
9365 #ifdef HAVE_ENABLE_EXECUTE_STACK
9366 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
9367 LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
9368 #endif
9369 }
9370
9371 /* Worker for TARGET_TRAMPOLINE_INIT. */
9372
9373 static void
9374 sparc_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
9375 {
9376 rtx fnaddr = force_reg (Pmode, XEXP (DECL_RTL (fndecl), 0));
9377 cxt = force_reg (Pmode, cxt);
9378 if (TARGET_ARCH64)
9379 sparc64_initialize_trampoline (m_tramp, fnaddr, cxt);
9380 else
9381 sparc32_initialize_trampoline (m_tramp, fnaddr, cxt);
9382 }
9383 \f
9384 /* Adjust the cost of a scheduling dependency. Return the new cost of
9385 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
9386
9387 static int
9388 supersparc_adjust_cost (rtx_insn *insn, rtx link, rtx_insn *dep_insn, int cost)
9389 {
9390 enum attr_type insn_type;
9391
9392 if (! recog_memoized (insn))
9393 return 0;
9394
9395 insn_type = get_attr_type (insn);
9396
9397 if (REG_NOTE_KIND (link) == 0)
9398 {
9399 /* Data dependency; DEP_INSN writes a register that INSN reads some
9400 cycles later. */
9401
9402 /* if a load, then the dependence must be on the memory address;
9403 add an extra "cycle". Note that the cost could be two cycles
9404 if the reg was written late in an instruction group; we ca not tell
9405 here. */
9406 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
9407 return cost + 3;
9408
9409 /* Get the delay only if the address of the store is the dependence. */
9410 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
9411 {
9412 rtx pat = PATTERN(insn);
9413 rtx dep_pat = PATTERN (dep_insn);
9414
9415 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
9416 return cost; /* This should not happen! */
9417
9418 /* The dependency between the two instructions was on the data that
9419 is being stored. Assume that this implies that the address of the
9420 store is not dependent. */
9421 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
9422 return cost;
9423
9424 return cost + 3; /* An approximation. */
9425 }
9426
9427 /* A shift instruction cannot receive its data from an instruction
9428 in the same cycle; add a one cycle penalty. */
9429 if (insn_type == TYPE_SHIFT)
9430 return cost + 3; /* Split before cascade into shift. */
9431 }
9432 else
9433 {
9434 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
9435 INSN writes some cycles later. */
9436
9437 /* These are only significant for the fpu unit; writing a fp reg before
9438 the fpu has finished with it stalls the processor. */
9439
9440 /* Reusing an integer register causes no problems. */
9441 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
9442 return 0;
9443 }
9444
9445 return cost;
9446 }
9447
9448 static int
9449 hypersparc_adjust_cost (rtx_insn *insn, rtx link, rtx_insn *dep_insn, int cost)
9450 {
9451 enum attr_type insn_type, dep_type;
9452 rtx pat = PATTERN(insn);
9453 rtx dep_pat = PATTERN (dep_insn);
9454
9455 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
9456 return cost;
9457
9458 insn_type = get_attr_type (insn);
9459 dep_type = get_attr_type (dep_insn);
9460
9461 switch (REG_NOTE_KIND (link))
9462 {
9463 case 0:
9464 /* Data dependency; DEP_INSN writes a register that INSN reads some
9465 cycles later. */
9466
9467 switch (insn_type)
9468 {
9469 case TYPE_STORE:
9470 case TYPE_FPSTORE:
9471 /* Get the delay iff the address of the store is the dependence. */
9472 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
9473 return cost;
9474
9475 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
9476 return cost;
9477 return cost + 3;
9478
9479 case TYPE_LOAD:
9480 case TYPE_SLOAD:
9481 case TYPE_FPLOAD:
9482 /* If a load, then the dependence must be on the memory address. If
9483 the addresses aren't equal, then it might be a false dependency */
9484 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
9485 {
9486 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
9487 || GET_CODE (SET_DEST (dep_pat)) != MEM
9488 || GET_CODE (SET_SRC (pat)) != MEM
9489 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
9490 XEXP (SET_SRC (pat), 0)))
9491 return cost + 2;
9492
9493 return cost + 8;
9494 }
9495 break;
9496
9497 case TYPE_BRANCH:
9498 /* Compare to branch latency is 0. There is no benefit from
9499 separating compare and branch. */
9500 if (dep_type == TYPE_COMPARE)
9501 return 0;
9502 /* Floating point compare to branch latency is less than
9503 compare to conditional move. */
9504 if (dep_type == TYPE_FPCMP)
9505 return cost - 1;
9506 break;
9507 default:
9508 break;
9509 }
9510 break;
9511
9512 case REG_DEP_ANTI:
9513 /* Anti-dependencies only penalize the fpu unit. */
9514 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
9515 return 0;
9516 break;
9517
9518 default:
9519 break;
9520 }
9521
9522 return cost;
9523 }
9524
9525 static int
9526 sparc_adjust_cost(rtx_insn *insn, rtx link, rtx_insn *dep, int cost)
9527 {
9528 switch (sparc_cpu)
9529 {
9530 case PROCESSOR_SUPERSPARC:
9531 cost = supersparc_adjust_cost (insn, link, dep, cost);
9532 break;
9533 case PROCESSOR_HYPERSPARC:
9534 case PROCESSOR_SPARCLITE86X:
9535 cost = hypersparc_adjust_cost (insn, link, dep, cost);
9536 break;
9537 default:
9538 break;
9539 }
9540 return cost;
9541 }
9542
9543 static void
9544 sparc_sched_init (FILE *dump ATTRIBUTE_UNUSED,
9545 int sched_verbose ATTRIBUTE_UNUSED,
9546 int max_ready ATTRIBUTE_UNUSED)
9547 {}
9548
9549 static int
9550 sparc_use_sched_lookahead (void)
9551 {
9552 if (sparc_cpu == PROCESSOR_NIAGARA
9553 || sparc_cpu == PROCESSOR_NIAGARA2
9554 || sparc_cpu == PROCESSOR_NIAGARA3)
9555 return 0;
9556 if (sparc_cpu == PROCESSOR_NIAGARA4)
9557 return 2;
9558 if (sparc_cpu == PROCESSOR_ULTRASPARC
9559 || sparc_cpu == PROCESSOR_ULTRASPARC3)
9560 return 4;
9561 if ((1 << sparc_cpu) &
9562 ((1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
9563 (1 << PROCESSOR_SPARCLITE86X)))
9564 return 3;
9565 return 0;
9566 }
9567
9568 static int
9569 sparc_issue_rate (void)
9570 {
9571 switch (sparc_cpu)
9572 {
9573 case PROCESSOR_NIAGARA:
9574 case PROCESSOR_NIAGARA2:
9575 case PROCESSOR_NIAGARA3:
9576 default:
9577 return 1;
9578 case PROCESSOR_NIAGARA4:
9579 case PROCESSOR_V9:
9580 /* Assume V9 processors are capable of at least dual-issue. */
9581 return 2;
9582 case PROCESSOR_SUPERSPARC:
9583 return 3;
9584 case PROCESSOR_HYPERSPARC:
9585 case PROCESSOR_SPARCLITE86X:
9586 return 2;
9587 case PROCESSOR_ULTRASPARC:
9588 case PROCESSOR_ULTRASPARC3:
9589 return 4;
9590 }
9591 }
9592
9593 static int
9594 set_extends (rtx_insn *insn)
9595 {
9596 register rtx pat = PATTERN (insn);
9597
9598 switch (GET_CODE (SET_SRC (pat)))
9599 {
9600 /* Load and some shift instructions zero extend. */
9601 case MEM:
9602 case ZERO_EXTEND:
9603 /* sethi clears the high bits */
9604 case HIGH:
9605 /* LO_SUM is used with sethi. sethi cleared the high
9606 bits and the values used with lo_sum are positive */
9607 case LO_SUM:
9608 /* Store flag stores 0 or 1 */
9609 case LT: case LTU:
9610 case GT: case GTU:
9611 case LE: case LEU:
9612 case GE: case GEU:
9613 case EQ:
9614 case NE:
9615 return 1;
9616 case AND:
9617 {
9618 rtx op0 = XEXP (SET_SRC (pat), 0);
9619 rtx op1 = XEXP (SET_SRC (pat), 1);
9620 if (GET_CODE (op1) == CONST_INT)
9621 return INTVAL (op1) >= 0;
9622 if (GET_CODE (op0) != REG)
9623 return 0;
9624 if (sparc_check_64 (op0, insn) == 1)
9625 return 1;
9626 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
9627 }
9628 case IOR:
9629 case XOR:
9630 {
9631 rtx op0 = XEXP (SET_SRC (pat), 0);
9632 rtx op1 = XEXP (SET_SRC (pat), 1);
9633 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
9634 return 0;
9635 if (GET_CODE (op1) == CONST_INT)
9636 return INTVAL (op1) >= 0;
9637 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
9638 }
9639 case LSHIFTRT:
9640 return GET_MODE (SET_SRC (pat)) == SImode;
9641 /* Positive integers leave the high bits zero. */
9642 case CONST_DOUBLE:
9643 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
9644 case CONST_INT:
9645 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
9646 case ASHIFTRT:
9647 case SIGN_EXTEND:
9648 return - (GET_MODE (SET_SRC (pat)) == SImode);
9649 case REG:
9650 return sparc_check_64 (SET_SRC (pat), insn);
9651 default:
9652 return 0;
9653 }
9654 }
9655
9656 /* We _ought_ to have only one kind per function, but... */
9657 static GTY(()) rtx sparc_addr_diff_list;
9658 static GTY(()) rtx sparc_addr_list;
9659
9660 void
9661 sparc_defer_case_vector (rtx lab, rtx vec, int diff)
9662 {
9663 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
9664 if (diff)
9665 sparc_addr_diff_list
9666 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
9667 else
9668 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
9669 }
9670
9671 static void
9672 sparc_output_addr_vec (rtx vec)
9673 {
9674 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
9675 int idx, vlen = XVECLEN (body, 0);
9676
9677 #ifdef ASM_OUTPUT_ADDR_VEC_START
9678 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
9679 #endif
9680
9681 #ifdef ASM_OUTPUT_CASE_LABEL
9682 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
9683 NEXT_INSN (lab));
9684 #else
9685 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
9686 #endif
9687
9688 for (idx = 0; idx < vlen; idx++)
9689 {
9690 ASM_OUTPUT_ADDR_VEC_ELT
9691 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
9692 }
9693
9694 #ifdef ASM_OUTPUT_ADDR_VEC_END
9695 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
9696 #endif
9697 }
9698
9699 static void
9700 sparc_output_addr_diff_vec (rtx vec)
9701 {
9702 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
9703 rtx base = XEXP (XEXP (body, 0), 0);
9704 int idx, vlen = XVECLEN (body, 1);
9705
9706 #ifdef ASM_OUTPUT_ADDR_VEC_START
9707 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
9708 #endif
9709
9710 #ifdef ASM_OUTPUT_CASE_LABEL
9711 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
9712 NEXT_INSN (lab));
9713 #else
9714 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
9715 #endif
9716
9717 for (idx = 0; idx < vlen; idx++)
9718 {
9719 ASM_OUTPUT_ADDR_DIFF_ELT
9720 (asm_out_file,
9721 body,
9722 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
9723 CODE_LABEL_NUMBER (base));
9724 }
9725
9726 #ifdef ASM_OUTPUT_ADDR_VEC_END
9727 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
9728 #endif
9729 }
9730
9731 static void
9732 sparc_output_deferred_case_vectors (void)
9733 {
9734 rtx t;
9735 int align;
9736
9737 if (sparc_addr_list == NULL_RTX
9738 && sparc_addr_diff_list == NULL_RTX)
9739 return;
9740
9741 /* Align to cache line in the function's code section. */
9742 switch_to_section (current_function_section ());
9743
9744 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
9745 if (align > 0)
9746 ASM_OUTPUT_ALIGN (asm_out_file, align);
9747
9748 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
9749 sparc_output_addr_vec (XEXP (t, 0));
9750 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
9751 sparc_output_addr_diff_vec (XEXP (t, 0));
9752
9753 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
9754 }
9755
9756 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
9757 unknown. Return 1 if the high bits are zero, -1 if the register is
9758 sign extended. */
9759 int
9760 sparc_check_64 (rtx x, rtx_insn *insn)
9761 {
9762 /* If a register is set only once it is safe to ignore insns this
9763 code does not know how to handle. The loop will either recognize
9764 the single set and return the correct value or fail to recognize
9765 it and return 0. */
9766 int set_once = 0;
9767 rtx y = x;
9768
9769 gcc_assert (GET_CODE (x) == REG);
9770
9771 if (GET_MODE (x) == DImode)
9772 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
9773
9774 if (flag_expensive_optimizations
9775 && df && DF_REG_DEF_COUNT (REGNO (y)) == 1)
9776 set_once = 1;
9777
9778 if (insn == 0)
9779 {
9780 if (set_once)
9781 insn = get_last_insn_anywhere ();
9782 else
9783 return 0;
9784 }
9785
9786 while ((insn = PREV_INSN (insn)))
9787 {
9788 switch (GET_CODE (insn))
9789 {
9790 case JUMP_INSN:
9791 case NOTE:
9792 break;
9793 case CODE_LABEL:
9794 case CALL_INSN:
9795 default:
9796 if (! set_once)
9797 return 0;
9798 break;
9799 case INSN:
9800 {
9801 rtx pat = PATTERN (insn);
9802 if (GET_CODE (pat) != SET)
9803 return 0;
9804 if (rtx_equal_p (x, SET_DEST (pat)))
9805 return set_extends (insn);
9806 if (y && rtx_equal_p (y, SET_DEST (pat)))
9807 return set_extends (insn);
9808 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
9809 return 0;
9810 }
9811 }
9812 }
9813 return 0;
9814 }
9815
9816 /* Output a wide shift instruction in V8+ mode. INSN is the instruction,
9817 OPERANDS are its operands and OPCODE is the mnemonic to be used. */
9818
9819 const char *
9820 output_v8plus_shift (rtx_insn *insn, rtx *operands, const char *opcode)
9821 {
9822 static char asm_code[60];
9823
9824 /* The scratch register is only required when the destination
9825 register is not a 64-bit global or out register. */
9826 if (which_alternative != 2)
9827 operands[3] = operands[0];
9828
9829 /* We can only shift by constants <= 63. */
9830 if (GET_CODE (operands[2]) == CONST_INT)
9831 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
9832
9833 if (GET_CODE (operands[1]) == CONST_INT)
9834 {
9835 output_asm_insn ("mov\t%1, %3", operands);
9836 }
9837 else
9838 {
9839 output_asm_insn ("sllx\t%H1, 32, %3", operands);
9840 if (sparc_check_64 (operands[1], insn) <= 0)
9841 output_asm_insn ("srl\t%L1, 0, %L1", operands);
9842 output_asm_insn ("or\t%L1, %3, %3", operands);
9843 }
9844
9845 strcpy (asm_code, opcode);
9846
9847 if (which_alternative != 2)
9848 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
9849 else
9850 return
9851 strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
9852 }
9853 \f
9854 /* Output rtl to increment the profiler label LABELNO
9855 for profiling a function entry. */
9856
9857 void
9858 sparc_profile_hook (int labelno)
9859 {
9860 char buf[32];
9861 rtx lab, fun;
9862
9863 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
9864 if (NO_PROFILE_COUNTERS)
9865 {
9866 emit_library_call (fun, LCT_NORMAL, VOIDmode, 0);
9867 }
9868 else
9869 {
9870 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
9871 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9872 emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lab, Pmode);
9873 }
9874 }
9875 \f
9876 #ifdef TARGET_SOLARIS
9877 /* Solaris implementation of TARGET_ASM_NAMED_SECTION. */
9878
9879 static void
9880 sparc_solaris_elf_asm_named_section (const char *name, unsigned int flags,
9881 tree decl ATTRIBUTE_UNUSED)
9882 {
9883 if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
9884 {
9885 solaris_elf_asm_comdat_section (name, flags, decl);
9886 return;
9887 }
9888
9889 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
9890
9891 if (!(flags & SECTION_DEBUG))
9892 fputs (",#alloc", asm_out_file);
9893 if (flags & SECTION_WRITE)
9894 fputs (",#write", asm_out_file);
9895 if (flags & SECTION_TLS)
9896 fputs (",#tls", asm_out_file);
9897 if (flags & SECTION_CODE)
9898 fputs (",#execinstr", asm_out_file);
9899
9900 /* Sun as only supports #nobits/#progbits since Solaris 10. */
9901 if (HAVE_AS_SPARC_NOBITS)
9902 {
9903 if (flags & SECTION_BSS)
9904 fputs (",#nobits", asm_out_file);
9905 else
9906 fputs (",#progbits", asm_out_file);
9907 }
9908
9909 fputc ('\n', asm_out_file);
9910 }
9911 #endif /* TARGET_SOLARIS */
9912
9913 /* We do not allow indirect calls to be optimized into sibling calls.
9914
9915 We cannot use sibling calls when delayed branches are disabled
9916 because they will likely require the call delay slot to be filled.
9917
9918 Also, on SPARC 32-bit we cannot emit a sibling call when the
9919 current function returns a structure. This is because the "unimp
9920 after call" convention would cause the callee to return to the
9921 wrong place. The generic code already disallows cases where the
9922 function being called returns a structure.
9923
9924 It may seem strange how this last case could occur. Usually there
9925 is code after the call which jumps to epilogue code which dumps the
9926 return value into the struct return area. That ought to invalidate
9927 the sibling call right? Well, in the C++ case we can end up passing
9928 the pointer to the struct return area to a constructor (which returns
9929 void) and then nothing else happens. Such a sibling call would look
9930 valid without the added check here.
9931
9932 VxWorks PIC PLT entries require the global pointer to be initialized
9933 on entry. We therefore can't emit sibling calls to them. */
9934 static bool
9935 sparc_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
9936 {
9937 return (decl
9938 && flag_delayed_branch
9939 && (TARGET_ARCH64 || ! cfun->returns_struct)
9940 && !(TARGET_VXWORKS_RTP
9941 && flag_pic
9942 && !targetm.binds_local_p (decl)));
9943 }
9944 \f
9945 /* libfunc renaming. */
9946
9947 static void
9948 sparc_init_libfuncs (void)
9949 {
9950 if (TARGET_ARCH32)
9951 {
9952 /* Use the subroutines that Sun's library provides for integer
9953 multiply and divide. The `*' prevents an underscore from
9954 being prepended by the compiler. .umul is a little faster
9955 than .mul. */
9956 set_optab_libfunc (smul_optab, SImode, "*.umul");
9957 set_optab_libfunc (sdiv_optab, SImode, "*.div");
9958 set_optab_libfunc (udiv_optab, SImode, "*.udiv");
9959 set_optab_libfunc (smod_optab, SImode, "*.rem");
9960 set_optab_libfunc (umod_optab, SImode, "*.urem");
9961
9962 /* TFmode arithmetic. These names are part of the SPARC 32bit ABI. */
9963 set_optab_libfunc (add_optab, TFmode, "_Q_add");
9964 set_optab_libfunc (sub_optab, TFmode, "_Q_sub");
9965 set_optab_libfunc (neg_optab, TFmode, "_Q_neg");
9966 set_optab_libfunc (smul_optab, TFmode, "_Q_mul");
9967 set_optab_libfunc (sdiv_optab, TFmode, "_Q_div");
9968
9969 /* We can define the TFmode sqrt optab only if TARGET_FPU. This
9970 is because with soft-float, the SFmode and DFmode sqrt
9971 instructions will be absent, and the compiler will notice and
9972 try to use the TFmode sqrt instruction for calls to the
9973 builtin function sqrt, but this fails. */
9974 if (TARGET_FPU)
9975 set_optab_libfunc (sqrt_optab, TFmode, "_Q_sqrt");
9976
9977 set_optab_libfunc (eq_optab, TFmode, "_Q_feq");
9978 set_optab_libfunc (ne_optab, TFmode, "_Q_fne");
9979 set_optab_libfunc (gt_optab, TFmode, "_Q_fgt");
9980 set_optab_libfunc (ge_optab, TFmode, "_Q_fge");
9981 set_optab_libfunc (lt_optab, TFmode, "_Q_flt");
9982 set_optab_libfunc (le_optab, TFmode, "_Q_fle");
9983
9984 set_conv_libfunc (sext_optab, TFmode, SFmode, "_Q_stoq");
9985 set_conv_libfunc (sext_optab, TFmode, DFmode, "_Q_dtoq");
9986 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_Q_qtos");
9987 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_Q_qtod");
9988
9989 set_conv_libfunc (sfix_optab, SImode, TFmode, "_Q_qtoi");
9990 set_conv_libfunc (ufix_optab, SImode, TFmode, "_Q_qtou");
9991 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_Q_itoq");
9992 set_conv_libfunc (ufloat_optab, TFmode, SImode, "_Q_utoq");
9993
9994 if (DITF_CONVERSION_LIBFUNCS)
9995 {
9996 set_conv_libfunc (sfix_optab, DImode, TFmode, "_Q_qtoll");
9997 set_conv_libfunc (ufix_optab, DImode, TFmode, "_Q_qtoull");
9998 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_Q_lltoq");
9999 set_conv_libfunc (ufloat_optab, TFmode, DImode, "_Q_ulltoq");
10000 }
10001
10002 if (SUN_CONVERSION_LIBFUNCS)
10003 {
10004 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftoll");
10005 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoull");
10006 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtoll");
10007 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoull");
10008 }
10009 }
10010 if (TARGET_ARCH64)
10011 {
10012 /* In the SPARC 64bit ABI, SImode multiply and divide functions
10013 do not exist in the library. Make sure the compiler does not
10014 emit calls to them by accident. (It should always use the
10015 hardware instructions.) */
10016 set_optab_libfunc (smul_optab, SImode, 0);
10017 set_optab_libfunc (sdiv_optab, SImode, 0);
10018 set_optab_libfunc (udiv_optab, SImode, 0);
10019 set_optab_libfunc (smod_optab, SImode, 0);
10020 set_optab_libfunc (umod_optab, SImode, 0);
10021
10022 if (SUN_INTEGER_MULTIPLY_64)
10023 {
10024 set_optab_libfunc (smul_optab, DImode, "__mul64");
10025 set_optab_libfunc (sdiv_optab, DImode, "__div64");
10026 set_optab_libfunc (udiv_optab, DImode, "__udiv64");
10027 set_optab_libfunc (smod_optab, DImode, "__rem64");
10028 set_optab_libfunc (umod_optab, DImode, "__urem64");
10029 }
10030
10031 if (SUN_CONVERSION_LIBFUNCS)
10032 {
10033 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftol");
10034 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoul");
10035 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtol");
10036 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoul");
10037 }
10038 }
10039 }
10040 \f
10041 /* SPARC builtins. */
10042 enum sparc_builtins
10043 {
10044 /* FPU builtins. */
10045 SPARC_BUILTIN_LDFSR,
10046 SPARC_BUILTIN_STFSR,
10047
10048 /* VIS 1.0 builtins. */
10049 SPARC_BUILTIN_FPACK16,
10050 SPARC_BUILTIN_FPACK32,
10051 SPARC_BUILTIN_FPACKFIX,
10052 SPARC_BUILTIN_FEXPAND,
10053 SPARC_BUILTIN_FPMERGE,
10054 SPARC_BUILTIN_FMUL8X16,
10055 SPARC_BUILTIN_FMUL8X16AU,
10056 SPARC_BUILTIN_FMUL8X16AL,
10057 SPARC_BUILTIN_FMUL8SUX16,
10058 SPARC_BUILTIN_FMUL8ULX16,
10059 SPARC_BUILTIN_FMULD8SUX16,
10060 SPARC_BUILTIN_FMULD8ULX16,
10061 SPARC_BUILTIN_FALIGNDATAV4HI,
10062 SPARC_BUILTIN_FALIGNDATAV8QI,
10063 SPARC_BUILTIN_FALIGNDATAV2SI,
10064 SPARC_BUILTIN_FALIGNDATADI,
10065 SPARC_BUILTIN_WRGSR,
10066 SPARC_BUILTIN_RDGSR,
10067 SPARC_BUILTIN_ALIGNADDR,
10068 SPARC_BUILTIN_ALIGNADDRL,
10069 SPARC_BUILTIN_PDIST,
10070 SPARC_BUILTIN_EDGE8,
10071 SPARC_BUILTIN_EDGE8L,
10072 SPARC_BUILTIN_EDGE16,
10073 SPARC_BUILTIN_EDGE16L,
10074 SPARC_BUILTIN_EDGE32,
10075 SPARC_BUILTIN_EDGE32L,
10076 SPARC_BUILTIN_FCMPLE16,
10077 SPARC_BUILTIN_FCMPLE32,
10078 SPARC_BUILTIN_FCMPNE16,
10079 SPARC_BUILTIN_FCMPNE32,
10080 SPARC_BUILTIN_FCMPGT16,
10081 SPARC_BUILTIN_FCMPGT32,
10082 SPARC_BUILTIN_FCMPEQ16,
10083 SPARC_BUILTIN_FCMPEQ32,
10084 SPARC_BUILTIN_FPADD16,
10085 SPARC_BUILTIN_FPADD16S,
10086 SPARC_BUILTIN_FPADD32,
10087 SPARC_BUILTIN_FPADD32S,
10088 SPARC_BUILTIN_FPSUB16,
10089 SPARC_BUILTIN_FPSUB16S,
10090 SPARC_BUILTIN_FPSUB32,
10091 SPARC_BUILTIN_FPSUB32S,
10092 SPARC_BUILTIN_ARRAY8,
10093 SPARC_BUILTIN_ARRAY16,
10094 SPARC_BUILTIN_ARRAY32,
10095
10096 /* VIS 2.0 builtins. */
10097 SPARC_BUILTIN_EDGE8N,
10098 SPARC_BUILTIN_EDGE8LN,
10099 SPARC_BUILTIN_EDGE16N,
10100 SPARC_BUILTIN_EDGE16LN,
10101 SPARC_BUILTIN_EDGE32N,
10102 SPARC_BUILTIN_EDGE32LN,
10103 SPARC_BUILTIN_BMASK,
10104 SPARC_BUILTIN_BSHUFFLEV4HI,
10105 SPARC_BUILTIN_BSHUFFLEV8QI,
10106 SPARC_BUILTIN_BSHUFFLEV2SI,
10107 SPARC_BUILTIN_BSHUFFLEDI,
10108
10109 /* VIS 3.0 builtins. */
10110 SPARC_BUILTIN_CMASK8,
10111 SPARC_BUILTIN_CMASK16,
10112 SPARC_BUILTIN_CMASK32,
10113 SPARC_BUILTIN_FCHKSM16,
10114 SPARC_BUILTIN_FSLL16,
10115 SPARC_BUILTIN_FSLAS16,
10116 SPARC_BUILTIN_FSRL16,
10117 SPARC_BUILTIN_FSRA16,
10118 SPARC_BUILTIN_FSLL32,
10119 SPARC_BUILTIN_FSLAS32,
10120 SPARC_BUILTIN_FSRL32,
10121 SPARC_BUILTIN_FSRA32,
10122 SPARC_BUILTIN_PDISTN,
10123 SPARC_BUILTIN_FMEAN16,
10124 SPARC_BUILTIN_FPADD64,
10125 SPARC_BUILTIN_FPSUB64,
10126 SPARC_BUILTIN_FPADDS16,
10127 SPARC_BUILTIN_FPADDS16S,
10128 SPARC_BUILTIN_FPSUBS16,
10129 SPARC_BUILTIN_FPSUBS16S,
10130 SPARC_BUILTIN_FPADDS32,
10131 SPARC_BUILTIN_FPADDS32S,
10132 SPARC_BUILTIN_FPSUBS32,
10133 SPARC_BUILTIN_FPSUBS32S,
10134 SPARC_BUILTIN_FUCMPLE8,
10135 SPARC_BUILTIN_FUCMPNE8,
10136 SPARC_BUILTIN_FUCMPGT8,
10137 SPARC_BUILTIN_FUCMPEQ8,
10138 SPARC_BUILTIN_FHADDS,
10139 SPARC_BUILTIN_FHADDD,
10140 SPARC_BUILTIN_FHSUBS,
10141 SPARC_BUILTIN_FHSUBD,
10142 SPARC_BUILTIN_FNHADDS,
10143 SPARC_BUILTIN_FNHADDD,
10144 SPARC_BUILTIN_UMULXHI,
10145 SPARC_BUILTIN_XMULX,
10146 SPARC_BUILTIN_XMULXHI,
10147
10148 SPARC_BUILTIN_MAX
10149 };
10150
10151 static GTY (()) tree sparc_builtins[(int) SPARC_BUILTIN_MAX];
10152 static enum insn_code sparc_builtins_icode[(int) SPARC_BUILTIN_MAX];
10153
10154 /* Add a SPARC builtin function with NAME, ICODE, CODE and TYPE. Return the
10155 function decl or NULL_TREE if the builtin was not added. */
10156
10157 static tree
10158 def_builtin (const char *name, enum insn_code icode, enum sparc_builtins code,
10159 tree type)
10160 {
10161 tree t
10162 = add_builtin_function (name, type, code, BUILT_IN_MD, NULL, NULL_TREE);
10163
10164 if (t)
10165 {
10166 sparc_builtins[code] = t;
10167 sparc_builtins_icode[code] = icode;
10168 }
10169
10170 return t;
10171 }
10172
10173 /* Likewise, but also marks the function as "const". */
10174
10175 static tree
10176 def_builtin_const (const char *name, enum insn_code icode,
10177 enum sparc_builtins code, tree type)
10178 {
10179 tree t = def_builtin (name, icode, code, type);
10180
10181 if (t)
10182 TREE_READONLY (t) = 1;
10183
10184 return t;
10185 }
10186
10187 /* Implement the TARGET_INIT_BUILTINS target hook.
10188 Create builtin functions for special SPARC instructions. */
10189
10190 static void
10191 sparc_init_builtins (void)
10192 {
10193 if (TARGET_FPU)
10194 sparc_fpu_init_builtins ();
10195
10196 if (TARGET_VIS)
10197 sparc_vis_init_builtins ();
10198 }
10199
10200 /* Create builtin functions for FPU instructions. */
10201
10202 static void
10203 sparc_fpu_init_builtins (void)
10204 {
10205 tree ftype
10206 = build_function_type_list (void_type_node,
10207 build_pointer_type (unsigned_type_node), 0);
10208 def_builtin ("__builtin_load_fsr", CODE_FOR_ldfsr,
10209 SPARC_BUILTIN_LDFSR, ftype);
10210 def_builtin ("__builtin_store_fsr", CODE_FOR_stfsr,
10211 SPARC_BUILTIN_STFSR, ftype);
10212 }
10213
10214 /* Create builtin functions for VIS instructions. */
10215
10216 static void
10217 sparc_vis_init_builtins (void)
10218 {
10219 tree v4qi = build_vector_type (unsigned_intQI_type_node, 4);
10220 tree v8qi = build_vector_type (unsigned_intQI_type_node, 8);
10221 tree v4hi = build_vector_type (intHI_type_node, 4);
10222 tree v2hi = build_vector_type (intHI_type_node, 2);
10223 tree v2si = build_vector_type (intSI_type_node, 2);
10224 tree v1si = build_vector_type (intSI_type_node, 1);
10225
10226 tree v4qi_ftype_v4hi = build_function_type_list (v4qi, v4hi, 0);
10227 tree v8qi_ftype_v2si_v8qi = build_function_type_list (v8qi, v2si, v8qi, 0);
10228 tree v2hi_ftype_v2si = build_function_type_list (v2hi, v2si, 0);
10229 tree v4hi_ftype_v4qi = build_function_type_list (v4hi, v4qi, 0);
10230 tree v8qi_ftype_v4qi_v4qi = build_function_type_list (v8qi, v4qi, v4qi, 0);
10231 tree v4hi_ftype_v4qi_v4hi = build_function_type_list (v4hi, v4qi, v4hi, 0);
10232 tree v4hi_ftype_v4qi_v2hi = build_function_type_list (v4hi, v4qi, v2hi, 0);
10233 tree v2si_ftype_v4qi_v2hi = build_function_type_list (v2si, v4qi, v2hi, 0);
10234 tree v4hi_ftype_v8qi_v4hi = build_function_type_list (v4hi, v8qi, v4hi, 0);
10235 tree v4hi_ftype_v4hi_v4hi = build_function_type_list (v4hi, v4hi, v4hi, 0);
10236 tree v2si_ftype_v2si_v2si = build_function_type_list (v2si, v2si, v2si, 0);
10237 tree v8qi_ftype_v8qi_v8qi = build_function_type_list (v8qi, v8qi, v8qi, 0);
10238 tree v2hi_ftype_v2hi_v2hi = build_function_type_list (v2hi, v2hi, v2hi, 0);
10239 tree v1si_ftype_v1si_v1si = build_function_type_list (v1si, v1si, v1si, 0);
10240 tree di_ftype_v8qi_v8qi_di = build_function_type_list (intDI_type_node,
10241 v8qi, v8qi,
10242 intDI_type_node, 0);
10243 tree di_ftype_v8qi_v8qi = build_function_type_list (intDI_type_node,
10244 v8qi, v8qi, 0);
10245 tree si_ftype_v8qi_v8qi = build_function_type_list (intSI_type_node,
10246 v8qi, v8qi, 0);
10247 tree di_ftype_di_di = build_function_type_list (intDI_type_node,
10248 intDI_type_node,
10249 intDI_type_node, 0);
10250 tree si_ftype_si_si = build_function_type_list (intSI_type_node,
10251 intSI_type_node,
10252 intSI_type_node, 0);
10253 tree ptr_ftype_ptr_si = build_function_type_list (ptr_type_node,
10254 ptr_type_node,
10255 intSI_type_node, 0);
10256 tree ptr_ftype_ptr_di = build_function_type_list (ptr_type_node,
10257 ptr_type_node,
10258 intDI_type_node, 0);
10259 tree si_ftype_ptr_ptr = build_function_type_list (intSI_type_node,
10260 ptr_type_node,
10261 ptr_type_node, 0);
10262 tree di_ftype_ptr_ptr = build_function_type_list (intDI_type_node,
10263 ptr_type_node,
10264 ptr_type_node, 0);
10265 tree si_ftype_v4hi_v4hi = build_function_type_list (intSI_type_node,
10266 v4hi, v4hi, 0);
10267 tree si_ftype_v2si_v2si = build_function_type_list (intSI_type_node,
10268 v2si, v2si, 0);
10269 tree di_ftype_v4hi_v4hi = build_function_type_list (intDI_type_node,
10270 v4hi, v4hi, 0);
10271 tree di_ftype_v2si_v2si = build_function_type_list (intDI_type_node,
10272 v2si, v2si, 0);
10273 tree void_ftype_di = build_function_type_list (void_type_node,
10274 intDI_type_node, 0);
10275 tree di_ftype_void = build_function_type_list (intDI_type_node,
10276 void_type_node, 0);
10277 tree void_ftype_si = build_function_type_list (void_type_node,
10278 intSI_type_node, 0);
10279 tree sf_ftype_sf_sf = build_function_type_list (float_type_node,
10280 float_type_node,
10281 float_type_node, 0);
10282 tree df_ftype_df_df = build_function_type_list (double_type_node,
10283 double_type_node,
10284 double_type_node, 0);
10285
10286 /* Packing and expanding vectors. */
10287 def_builtin ("__builtin_vis_fpack16", CODE_FOR_fpack16_vis,
10288 SPARC_BUILTIN_FPACK16, v4qi_ftype_v4hi);
10289 def_builtin ("__builtin_vis_fpack32", CODE_FOR_fpack32_vis,
10290 SPARC_BUILTIN_FPACK32, v8qi_ftype_v2si_v8qi);
10291 def_builtin ("__builtin_vis_fpackfix", CODE_FOR_fpackfix_vis,
10292 SPARC_BUILTIN_FPACKFIX, v2hi_ftype_v2si);
10293 def_builtin_const ("__builtin_vis_fexpand", CODE_FOR_fexpand_vis,
10294 SPARC_BUILTIN_FEXPAND, v4hi_ftype_v4qi);
10295 def_builtin_const ("__builtin_vis_fpmerge", CODE_FOR_fpmerge_vis,
10296 SPARC_BUILTIN_FPMERGE, v8qi_ftype_v4qi_v4qi);
10297
10298 /* Multiplications. */
10299 def_builtin_const ("__builtin_vis_fmul8x16", CODE_FOR_fmul8x16_vis,
10300 SPARC_BUILTIN_FMUL8X16, v4hi_ftype_v4qi_v4hi);
10301 def_builtin_const ("__builtin_vis_fmul8x16au", CODE_FOR_fmul8x16au_vis,
10302 SPARC_BUILTIN_FMUL8X16AU, v4hi_ftype_v4qi_v2hi);
10303 def_builtin_const ("__builtin_vis_fmul8x16al", CODE_FOR_fmul8x16al_vis,
10304 SPARC_BUILTIN_FMUL8X16AL, v4hi_ftype_v4qi_v2hi);
10305 def_builtin_const ("__builtin_vis_fmul8sux16", CODE_FOR_fmul8sux16_vis,
10306 SPARC_BUILTIN_FMUL8SUX16, v4hi_ftype_v8qi_v4hi);
10307 def_builtin_const ("__builtin_vis_fmul8ulx16", CODE_FOR_fmul8ulx16_vis,
10308 SPARC_BUILTIN_FMUL8ULX16, v4hi_ftype_v8qi_v4hi);
10309 def_builtin_const ("__builtin_vis_fmuld8sux16", CODE_FOR_fmuld8sux16_vis,
10310 SPARC_BUILTIN_FMULD8SUX16, v2si_ftype_v4qi_v2hi);
10311 def_builtin_const ("__builtin_vis_fmuld8ulx16", CODE_FOR_fmuld8ulx16_vis,
10312 SPARC_BUILTIN_FMULD8ULX16, v2si_ftype_v4qi_v2hi);
10313
10314 /* Data aligning. */
10315 def_builtin ("__builtin_vis_faligndatav4hi", CODE_FOR_faligndatav4hi_vis,
10316 SPARC_BUILTIN_FALIGNDATAV4HI, v4hi_ftype_v4hi_v4hi);
10317 def_builtin ("__builtin_vis_faligndatav8qi", CODE_FOR_faligndatav8qi_vis,
10318 SPARC_BUILTIN_FALIGNDATAV8QI, v8qi_ftype_v8qi_v8qi);
10319 def_builtin ("__builtin_vis_faligndatav2si", CODE_FOR_faligndatav2si_vis,
10320 SPARC_BUILTIN_FALIGNDATAV2SI, v2si_ftype_v2si_v2si);
10321 def_builtin ("__builtin_vis_faligndatadi", CODE_FOR_faligndatav1di_vis,
10322 SPARC_BUILTIN_FALIGNDATADI, di_ftype_di_di);
10323
10324 def_builtin ("__builtin_vis_write_gsr", CODE_FOR_wrgsr_vis,
10325 SPARC_BUILTIN_WRGSR, void_ftype_di);
10326 def_builtin ("__builtin_vis_read_gsr", CODE_FOR_rdgsr_vis,
10327 SPARC_BUILTIN_RDGSR, di_ftype_void);
10328
10329 if (TARGET_ARCH64)
10330 {
10331 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrdi_vis,
10332 SPARC_BUILTIN_ALIGNADDR, ptr_ftype_ptr_di);
10333 def_builtin ("__builtin_vis_alignaddrl", CODE_FOR_alignaddrldi_vis,
10334 SPARC_BUILTIN_ALIGNADDRL, ptr_ftype_ptr_di);
10335 }
10336 else
10337 {
10338 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrsi_vis,
10339 SPARC_BUILTIN_ALIGNADDR, ptr_ftype_ptr_si);
10340 def_builtin ("__builtin_vis_alignaddrl", CODE_FOR_alignaddrlsi_vis,
10341 SPARC_BUILTIN_ALIGNADDRL, ptr_ftype_ptr_si);
10342 }
10343
10344 /* Pixel distance. */
10345 def_builtin_const ("__builtin_vis_pdist", CODE_FOR_pdist_vis,
10346 SPARC_BUILTIN_PDIST, di_ftype_v8qi_v8qi_di);
10347
10348 /* Edge handling. */
10349 if (TARGET_ARCH64)
10350 {
10351 def_builtin_const ("__builtin_vis_edge8", CODE_FOR_edge8di_vis,
10352 SPARC_BUILTIN_EDGE8, di_ftype_ptr_ptr);
10353 def_builtin_const ("__builtin_vis_edge8l", CODE_FOR_edge8ldi_vis,
10354 SPARC_BUILTIN_EDGE8L, di_ftype_ptr_ptr);
10355 def_builtin_const ("__builtin_vis_edge16", CODE_FOR_edge16di_vis,
10356 SPARC_BUILTIN_EDGE16, di_ftype_ptr_ptr);
10357 def_builtin_const ("__builtin_vis_edge16l", CODE_FOR_edge16ldi_vis,
10358 SPARC_BUILTIN_EDGE16L, di_ftype_ptr_ptr);
10359 def_builtin_const ("__builtin_vis_edge32", CODE_FOR_edge32di_vis,
10360 SPARC_BUILTIN_EDGE32, di_ftype_ptr_ptr);
10361 def_builtin_const ("__builtin_vis_edge32l", CODE_FOR_edge32ldi_vis,
10362 SPARC_BUILTIN_EDGE32L, di_ftype_ptr_ptr);
10363 }
10364 else
10365 {
10366 def_builtin_const ("__builtin_vis_edge8", CODE_FOR_edge8si_vis,
10367 SPARC_BUILTIN_EDGE8, si_ftype_ptr_ptr);
10368 def_builtin_const ("__builtin_vis_edge8l", CODE_FOR_edge8lsi_vis,
10369 SPARC_BUILTIN_EDGE8L, si_ftype_ptr_ptr);
10370 def_builtin_const ("__builtin_vis_edge16", CODE_FOR_edge16si_vis,
10371 SPARC_BUILTIN_EDGE16, si_ftype_ptr_ptr);
10372 def_builtin_const ("__builtin_vis_edge16l", CODE_FOR_edge16lsi_vis,
10373 SPARC_BUILTIN_EDGE16L, si_ftype_ptr_ptr);
10374 def_builtin_const ("__builtin_vis_edge32", CODE_FOR_edge32si_vis,
10375 SPARC_BUILTIN_EDGE32, si_ftype_ptr_ptr);
10376 def_builtin_const ("__builtin_vis_edge32l", CODE_FOR_edge32lsi_vis,
10377 SPARC_BUILTIN_EDGE32L, si_ftype_ptr_ptr);
10378 }
10379
10380 /* Pixel compare. */
10381 if (TARGET_ARCH64)
10382 {
10383 def_builtin_const ("__builtin_vis_fcmple16", CODE_FOR_fcmple16di_vis,
10384 SPARC_BUILTIN_FCMPLE16, di_ftype_v4hi_v4hi);
10385 def_builtin_const ("__builtin_vis_fcmple32", CODE_FOR_fcmple32di_vis,
10386 SPARC_BUILTIN_FCMPLE32, di_ftype_v2si_v2si);
10387 def_builtin_const ("__builtin_vis_fcmpne16", CODE_FOR_fcmpne16di_vis,
10388 SPARC_BUILTIN_FCMPNE16, di_ftype_v4hi_v4hi);
10389 def_builtin_const ("__builtin_vis_fcmpne32", CODE_FOR_fcmpne32di_vis,
10390 SPARC_BUILTIN_FCMPNE32, di_ftype_v2si_v2si);
10391 def_builtin_const ("__builtin_vis_fcmpgt16", CODE_FOR_fcmpgt16di_vis,
10392 SPARC_BUILTIN_FCMPGT16, di_ftype_v4hi_v4hi);
10393 def_builtin_const ("__builtin_vis_fcmpgt32", CODE_FOR_fcmpgt32di_vis,
10394 SPARC_BUILTIN_FCMPGT32, di_ftype_v2si_v2si);
10395 def_builtin_const ("__builtin_vis_fcmpeq16", CODE_FOR_fcmpeq16di_vis,
10396 SPARC_BUILTIN_FCMPEQ16, di_ftype_v4hi_v4hi);
10397 def_builtin_const ("__builtin_vis_fcmpeq32", CODE_FOR_fcmpeq32di_vis,
10398 SPARC_BUILTIN_FCMPEQ32, di_ftype_v2si_v2si);
10399 }
10400 else
10401 {
10402 def_builtin_const ("__builtin_vis_fcmple16", CODE_FOR_fcmple16si_vis,
10403 SPARC_BUILTIN_FCMPLE16, si_ftype_v4hi_v4hi);
10404 def_builtin_const ("__builtin_vis_fcmple32", CODE_FOR_fcmple32si_vis,
10405 SPARC_BUILTIN_FCMPLE32, si_ftype_v2si_v2si);
10406 def_builtin_const ("__builtin_vis_fcmpne16", CODE_FOR_fcmpne16si_vis,
10407 SPARC_BUILTIN_FCMPNE16, si_ftype_v4hi_v4hi);
10408 def_builtin_const ("__builtin_vis_fcmpne32", CODE_FOR_fcmpne32si_vis,
10409 SPARC_BUILTIN_FCMPNE32, si_ftype_v2si_v2si);
10410 def_builtin_const ("__builtin_vis_fcmpgt16", CODE_FOR_fcmpgt16si_vis,
10411 SPARC_BUILTIN_FCMPGT16, si_ftype_v4hi_v4hi);
10412 def_builtin_const ("__builtin_vis_fcmpgt32", CODE_FOR_fcmpgt32si_vis,
10413 SPARC_BUILTIN_FCMPGT32, si_ftype_v2si_v2si);
10414 def_builtin_const ("__builtin_vis_fcmpeq16", CODE_FOR_fcmpeq16si_vis,
10415 SPARC_BUILTIN_FCMPEQ16, si_ftype_v4hi_v4hi);
10416 def_builtin_const ("__builtin_vis_fcmpeq32", CODE_FOR_fcmpeq32si_vis,
10417 SPARC_BUILTIN_FCMPEQ32, si_ftype_v2si_v2si);
10418 }
10419
10420 /* Addition and subtraction. */
10421 def_builtin_const ("__builtin_vis_fpadd16", CODE_FOR_addv4hi3,
10422 SPARC_BUILTIN_FPADD16, v4hi_ftype_v4hi_v4hi);
10423 def_builtin_const ("__builtin_vis_fpadd16s", CODE_FOR_addv2hi3,
10424 SPARC_BUILTIN_FPADD16S, v2hi_ftype_v2hi_v2hi);
10425 def_builtin_const ("__builtin_vis_fpadd32", CODE_FOR_addv2si3,
10426 SPARC_BUILTIN_FPADD32, v2si_ftype_v2si_v2si);
10427 def_builtin_const ("__builtin_vis_fpadd32s", CODE_FOR_addv1si3,
10428 SPARC_BUILTIN_FPADD32S, v1si_ftype_v1si_v1si);
10429 def_builtin_const ("__builtin_vis_fpsub16", CODE_FOR_subv4hi3,
10430 SPARC_BUILTIN_FPSUB16, v4hi_ftype_v4hi_v4hi);
10431 def_builtin_const ("__builtin_vis_fpsub16s", CODE_FOR_subv2hi3,
10432 SPARC_BUILTIN_FPSUB16S, v2hi_ftype_v2hi_v2hi);
10433 def_builtin_const ("__builtin_vis_fpsub32", CODE_FOR_subv2si3,
10434 SPARC_BUILTIN_FPSUB32, v2si_ftype_v2si_v2si);
10435 def_builtin_const ("__builtin_vis_fpsub32s", CODE_FOR_subv1si3,
10436 SPARC_BUILTIN_FPSUB32S, v1si_ftype_v1si_v1si);
10437
10438 /* Three-dimensional array addressing. */
10439 if (TARGET_ARCH64)
10440 {
10441 def_builtin_const ("__builtin_vis_array8", CODE_FOR_array8di_vis,
10442 SPARC_BUILTIN_ARRAY8, di_ftype_di_di);
10443 def_builtin_const ("__builtin_vis_array16", CODE_FOR_array16di_vis,
10444 SPARC_BUILTIN_ARRAY16, di_ftype_di_di);
10445 def_builtin_const ("__builtin_vis_array32", CODE_FOR_array32di_vis,
10446 SPARC_BUILTIN_ARRAY32, di_ftype_di_di);
10447 }
10448 else
10449 {
10450 def_builtin_const ("__builtin_vis_array8", CODE_FOR_array8si_vis,
10451 SPARC_BUILTIN_ARRAY8, si_ftype_si_si);
10452 def_builtin_const ("__builtin_vis_array16", CODE_FOR_array16si_vis,
10453 SPARC_BUILTIN_ARRAY16, si_ftype_si_si);
10454 def_builtin_const ("__builtin_vis_array32", CODE_FOR_array32si_vis,
10455 SPARC_BUILTIN_ARRAY32, si_ftype_si_si);
10456 }
10457
10458 if (TARGET_VIS2)
10459 {
10460 /* Edge handling. */
10461 if (TARGET_ARCH64)
10462 {
10463 def_builtin_const ("__builtin_vis_edge8n", CODE_FOR_edge8ndi_vis,
10464 SPARC_BUILTIN_EDGE8N, di_ftype_ptr_ptr);
10465 def_builtin_const ("__builtin_vis_edge8ln", CODE_FOR_edge8lndi_vis,
10466 SPARC_BUILTIN_EDGE8LN, di_ftype_ptr_ptr);
10467 def_builtin_const ("__builtin_vis_edge16n", CODE_FOR_edge16ndi_vis,
10468 SPARC_BUILTIN_EDGE16N, di_ftype_ptr_ptr);
10469 def_builtin_const ("__builtin_vis_edge16ln", CODE_FOR_edge16lndi_vis,
10470 SPARC_BUILTIN_EDGE16LN, di_ftype_ptr_ptr);
10471 def_builtin_const ("__builtin_vis_edge32n", CODE_FOR_edge32ndi_vis,
10472 SPARC_BUILTIN_EDGE32N, di_ftype_ptr_ptr);
10473 def_builtin_const ("__builtin_vis_edge32ln", CODE_FOR_edge32lndi_vis,
10474 SPARC_BUILTIN_EDGE32LN, di_ftype_ptr_ptr);
10475 }
10476 else
10477 {
10478 def_builtin_const ("__builtin_vis_edge8n", CODE_FOR_edge8nsi_vis,
10479 SPARC_BUILTIN_EDGE8N, si_ftype_ptr_ptr);
10480 def_builtin_const ("__builtin_vis_edge8ln", CODE_FOR_edge8lnsi_vis,
10481 SPARC_BUILTIN_EDGE8LN, si_ftype_ptr_ptr);
10482 def_builtin_const ("__builtin_vis_edge16n", CODE_FOR_edge16nsi_vis,
10483 SPARC_BUILTIN_EDGE16N, si_ftype_ptr_ptr);
10484 def_builtin_const ("__builtin_vis_edge16ln", CODE_FOR_edge16lnsi_vis,
10485 SPARC_BUILTIN_EDGE16LN, si_ftype_ptr_ptr);
10486 def_builtin_const ("__builtin_vis_edge32n", CODE_FOR_edge32nsi_vis,
10487 SPARC_BUILTIN_EDGE32N, si_ftype_ptr_ptr);
10488 def_builtin_const ("__builtin_vis_edge32ln", CODE_FOR_edge32lnsi_vis,
10489 SPARC_BUILTIN_EDGE32LN, si_ftype_ptr_ptr);
10490 }
10491
10492 /* Byte mask and shuffle. */
10493 if (TARGET_ARCH64)
10494 def_builtin ("__builtin_vis_bmask", CODE_FOR_bmaskdi_vis,
10495 SPARC_BUILTIN_BMASK, di_ftype_di_di);
10496 else
10497 def_builtin ("__builtin_vis_bmask", CODE_FOR_bmasksi_vis,
10498 SPARC_BUILTIN_BMASK, si_ftype_si_si);
10499 def_builtin ("__builtin_vis_bshufflev4hi", CODE_FOR_bshufflev4hi_vis,
10500 SPARC_BUILTIN_BSHUFFLEV4HI, v4hi_ftype_v4hi_v4hi);
10501 def_builtin ("__builtin_vis_bshufflev8qi", CODE_FOR_bshufflev8qi_vis,
10502 SPARC_BUILTIN_BSHUFFLEV8QI, v8qi_ftype_v8qi_v8qi);
10503 def_builtin ("__builtin_vis_bshufflev2si", CODE_FOR_bshufflev2si_vis,
10504 SPARC_BUILTIN_BSHUFFLEV2SI, v2si_ftype_v2si_v2si);
10505 def_builtin ("__builtin_vis_bshuffledi", CODE_FOR_bshufflev1di_vis,
10506 SPARC_BUILTIN_BSHUFFLEDI, di_ftype_di_di);
10507 }
10508
10509 if (TARGET_VIS3)
10510 {
10511 if (TARGET_ARCH64)
10512 {
10513 def_builtin ("__builtin_vis_cmask8", CODE_FOR_cmask8di_vis,
10514 SPARC_BUILTIN_CMASK8, void_ftype_di);
10515 def_builtin ("__builtin_vis_cmask16", CODE_FOR_cmask16di_vis,
10516 SPARC_BUILTIN_CMASK16, void_ftype_di);
10517 def_builtin ("__builtin_vis_cmask32", CODE_FOR_cmask32di_vis,
10518 SPARC_BUILTIN_CMASK32, void_ftype_di);
10519 }
10520 else
10521 {
10522 def_builtin ("__builtin_vis_cmask8", CODE_FOR_cmask8si_vis,
10523 SPARC_BUILTIN_CMASK8, void_ftype_si);
10524 def_builtin ("__builtin_vis_cmask16", CODE_FOR_cmask16si_vis,
10525 SPARC_BUILTIN_CMASK16, void_ftype_si);
10526 def_builtin ("__builtin_vis_cmask32", CODE_FOR_cmask32si_vis,
10527 SPARC_BUILTIN_CMASK32, void_ftype_si);
10528 }
10529
10530 def_builtin_const ("__builtin_vis_fchksm16", CODE_FOR_fchksm16_vis,
10531 SPARC_BUILTIN_FCHKSM16, v4hi_ftype_v4hi_v4hi);
10532
10533 def_builtin_const ("__builtin_vis_fsll16", CODE_FOR_vashlv4hi3,
10534 SPARC_BUILTIN_FSLL16, v4hi_ftype_v4hi_v4hi);
10535 def_builtin_const ("__builtin_vis_fslas16", CODE_FOR_vssashlv4hi3,
10536 SPARC_BUILTIN_FSLAS16, v4hi_ftype_v4hi_v4hi);
10537 def_builtin_const ("__builtin_vis_fsrl16", CODE_FOR_vlshrv4hi3,
10538 SPARC_BUILTIN_FSRL16, v4hi_ftype_v4hi_v4hi);
10539 def_builtin_const ("__builtin_vis_fsra16", CODE_FOR_vashrv4hi3,
10540 SPARC_BUILTIN_FSRA16, v4hi_ftype_v4hi_v4hi);
10541 def_builtin_const ("__builtin_vis_fsll32", CODE_FOR_vashlv2si3,
10542 SPARC_BUILTIN_FSLL32, v2si_ftype_v2si_v2si);
10543 def_builtin_const ("__builtin_vis_fslas32", CODE_FOR_vssashlv2si3,
10544 SPARC_BUILTIN_FSLAS32, v2si_ftype_v2si_v2si);
10545 def_builtin_const ("__builtin_vis_fsrl32", CODE_FOR_vlshrv2si3,
10546 SPARC_BUILTIN_FSRL32, v2si_ftype_v2si_v2si);
10547 def_builtin_const ("__builtin_vis_fsra32", CODE_FOR_vashrv2si3,
10548 SPARC_BUILTIN_FSRA32, v2si_ftype_v2si_v2si);
10549
10550 if (TARGET_ARCH64)
10551 def_builtin_const ("__builtin_vis_pdistn", CODE_FOR_pdistndi_vis,
10552 SPARC_BUILTIN_PDISTN, di_ftype_v8qi_v8qi);
10553 else
10554 def_builtin_const ("__builtin_vis_pdistn", CODE_FOR_pdistnsi_vis,
10555 SPARC_BUILTIN_PDISTN, si_ftype_v8qi_v8qi);
10556
10557 def_builtin_const ("__builtin_vis_fmean16", CODE_FOR_fmean16_vis,
10558 SPARC_BUILTIN_FMEAN16, v4hi_ftype_v4hi_v4hi);
10559 def_builtin_const ("__builtin_vis_fpadd64", CODE_FOR_fpadd64_vis,
10560 SPARC_BUILTIN_FPADD64, di_ftype_di_di);
10561 def_builtin_const ("__builtin_vis_fpsub64", CODE_FOR_fpsub64_vis,
10562 SPARC_BUILTIN_FPSUB64, di_ftype_di_di);
10563
10564 def_builtin_const ("__builtin_vis_fpadds16", CODE_FOR_ssaddv4hi3,
10565 SPARC_BUILTIN_FPADDS16, v4hi_ftype_v4hi_v4hi);
10566 def_builtin_const ("__builtin_vis_fpadds16s", CODE_FOR_ssaddv2hi3,
10567 SPARC_BUILTIN_FPADDS16S, v2hi_ftype_v2hi_v2hi);
10568 def_builtin_const ("__builtin_vis_fpsubs16", CODE_FOR_sssubv4hi3,
10569 SPARC_BUILTIN_FPSUBS16, v4hi_ftype_v4hi_v4hi);
10570 def_builtin_const ("__builtin_vis_fpsubs16s", CODE_FOR_sssubv2hi3,
10571 SPARC_BUILTIN_FPSUBS16S, v2hi_ftype_v2hi_v2hi);
10572 def_builtin_const ("__builtin_vis_fpadds32", CODE_FOR_ssaddv2si3,
10573 SPARC_BUILTIN_FPADDS32, v2si_ftype_v2si_v2si);
10574 def_builtin_const ("__builtin_vis_fpadds32s", CODE_FOR_ssaddv1si3,
10575 SPARC_BUILTIN_FPADDS32S, v1si_ftype_v1si_v1si);
10576 def_builtin_const ("__builtin_vis_fpsubs32", CODE_FOR_sssubv2si3,
10577 SPARC_BUILTIN_FPSUBS32, v2si_ftype_v2si_v2si);
10578 def_builtin_const ("__builtin_vis_fpsubs32s", CODE_FOR_sssubv1si3,
10579 SPARC_BUILTIN_FPSUBS32S, v1si_ftype_v1si_v1si);
10580
10581 if (TARGET_ARCH64)
10582 {
10583 def_builtin_const ("__builtin_vis_fucmple8", CODE_FOR_fucmple8di_vis,
10584 SPARC_BUILTIN_FUCMPLE8, di_ftype_v8qi_v8qi);
10585 def_builtin_const ("__builtin_vis_fucmpne8", CODE_FOR_fucmpne8di_vis,
10586 SPARC_BUILTIN_FUCMPNE8, di_ftype_v8qi_v8qi);
10587 def_builtin_const ("__builtin_vis_fucmpgt8", CODE_FOR_fucmpgt8di_vis,
10588 SPARC_BUILTIN_FUCMPGT8, di_ftype_v8qi_v8qi);
10589 def_builtin_const ("__builtin_vis_fucmpeq8", CODE_FOR_fucmpeq8di_vis,
10590 SPARC_BUILTIN_FUCMPEQ8, di_ftype_v8qi_v8qi);
10591 }
10592 else
10593 {
10594 def_builtin_const ("__builtin_vis_fucmple8", CODE_FOR_fucmple8si_vis,
10595 SPARC_BUILTIN_FUCMPLE8, si_ftype_v8qi_v8qi);
10596 def_builtin_const ("__builtin_vis_fucmpne8", CODE_FOR_fucmpne8si_vis,
10597 SPARC_BUILTIN_FUCMPNE8, si_ftype_v8qi_v8qi);
10598 def_builtin_const ("__builtin_vis_fucmpgt8", CODE_FOR_fucmpgt8si_vis,
10599 SPARC_BUILTIN_FUCMPGT8, si_ftype_v8qi_v8qi);
10600 def_builtin_const ("__builtin_vis_fucmpeq8", CODE_FOR_fucmpeq8si_vis,
10601 SPARC_BUILTIN_FUCMPEQ8, si_ftype_v8qi_v8qi);
10602 }
10603
10604 def_builtin_const ("__builtin_vis_fhadds", CODE_FOR_fhaddsf_vis,
10605 SPARC_BUILTIN_FHADDS, sf_ftype_sf_sf);
10606 def_builtin_const ("__builtin_vis_fhaddd", CODE_FOR_fhadddf_vis,
10607 SPARC_BUILTIN_FHADDD, df_ftype_df_df);
10608 def_builtin_const ("__builtin_vis_fhsubs", CODE_FOR_fhsubsf_vis,
10609 SPARC_BUILTIN_FHSUBS, sf_ftype_sf_sf);
10610 def_builtin_const ("__builtin_vis_fhsubd", CODE_FOR_fhsubdf_vis,
10611 SPARC_BUILTIN_FHSUBD, df_ftype_df_df);
10612 def_builtin_const ("__builtin_vis_fnhadds", CODE_FOR_fnhaddsf_vis,
10613 SPARC_BUILTIN_FNHADDS, sf_ftype_sf_sf);
10614 def_builtin_const ("__builtin_vis_fnhaddd", CODE_FOR_fnhadddf_vis,
10615 SPARC_BUILTIN_FNHADDD, df_ftype_df_df);
10616
10617 def_builtin_const ("__builtin_vis_umulxhi", CODE_FOR_umulxhi_vis,
10618 SPARC_BUILTIN_UMULXHI, di_ftype_di_di);
10619 def_builtin_const ("__builtin_vis_xmulx", CODE_FOR_xmulx_vis,
10620 SPARC_BUILTIN_XMULX, di_ftype_di_di);
10621 def_builtin_const ("__builtin_vis_xmulxhi", CODE_FOR_xmulxhi_vis,
10622 SPARC_BUILTIN_XMULXHI, di_ftype_di_di);
10623 }
10624 }
10625
10626 /* Implement TARGET_BUILTIN_DECL hook. */
10627
10628 static tree
10629 sparc_builtin_decl (unsigned code, bool initialize_p ATTRIBUTE_UNUSED)
10630 {
10631 if (code >= SPARC_BUILTIN_MAX)
10632 return error_mark_node;
10633
10634 return sparc_builtins[code];
10635 }
10636
10637 /* Implemented TARGET_EXPAND_BUILTIN hook. */
10638
10639 static rtx
10640 sparc_expand_builtin (tree exp, rtx target,
10641 rtx subtarget ATTRIBUTE_UNUSED,
10642 machine_mode tmode ATTRIBUTE_UNUSED,
10643 int ignore ATTRIBUTE_UNUSED)
10644 {
10645 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
10646 enum sparc_builtins code = (enum sparc_builtins) DECL_FUNCTION_CODE (fndecl);
10647 enum insn_code icode = sparc_builtins_icode[code];
10648 bool nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node;
10649 call_expr_arg_iterator iter;
10650 int arg_count = 0;
10651 rtx pat, op[4];
10652 tree arg;
10653
10654 if (nonvoid)
10655 {
10656 machine_mode tmode = insn_data[icode].operand[0].mode;
10657 if (!target
10658 || GET_MODE (target) != tmode
10659 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
10660 op[0] = gen_reg_rtx (tmode);
10661 else
10662 op[0] = target;
10663 }
10664
10665 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
10666 {
10667 const struct insn_operand_data *insn_op;
10668 int idx;
10669
10670 if (arg == error_mark_node)
10671 return NULL_RTX;
10672
10673 arg_count++;
10674 idx = arg_count - !nonvoid;
10675 insn_op = &insn_data[icode].operand[idx];
10676 op[arg_count] = expand_normal (arg);
10677
10678 if (code == SPARC_BUILTIN_LDFSR || code == SPARC_BUILTIN_STFSR)
10679 {
10680 if (!address_operand (op[arg_count], SImode))
10681 {
10682 op[arg_count] = convert_memory_address (Pmode, op[arg_count]);
10683 op[arg_count] = copy_addr_to_reg (op[arg_count]);
10684 }
10685 op[arg_count] = gen_rtx_MEM (SImode, op[arg_count]);
10686 }
10687
10688 else if (insn_op->mode == V1DImode
10689 && GET_MODE (op[arg_count]) == DImode)
10690 op[arg_count] = gen_lowpart (V1DImode, op[arg_count]);
10691
10692 else if (insn_op->mode == V1SImode
10693 && GET_MODE (op[arg_count]) == SImode)
10694 op[arg_count] = gen_lowpart (V1SImode, op[arg_count]);
10695
10696 if (! (*insn_data[icode].operand[idx].predicate) (op[arg_count],
10697 insn_op->mode))
10698 op[arg_count] = copy_to_mode_reg (insn_op->mode, op[arg_count]);
10699 }
10700
10701 switch (arg_count)
10702 {
10703 case 0:
10704 pat = GEN_FCN (icode) (op[0]);
10705 break;
10706 case 1:
10707 if (nonvoid)
10708 pat = GEN_FCN (icode) (op[0], op[1]);
10709 else
10710 pat = GEN_FCN (icode) (op[1]);
10711 break;
10712 case 2:
10713 pat = GEN_FCN (icode) (op[0], op[1], op[2]);
10714 break;
10715 case 3:
10716 pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]);
10717 break;
10718 default:
10719 gcc_unreachable ();
10720 }
10721
10722 if (!pat)
10723 return NULL_RTX;
10724
10725 emit_insn (pat);
10726
10727 return (nonvoid ? op[0] : const0_rtx);
10728 }
10729
10730 /* Return the upper 16 bits of the 8x16 multiplication. */
10731
10732 static int
10733 sparc_vis_mul8x16 (int e8, int e16)
10734 {
10735 return (e8 * e16 + 128) / 256;
10736 }
10737
10738 /* Multiply the VECTOR_CSTs CST0 and CST1 as specified by FNCODE and put
10739 the result into the array N_ELTS, whose elements are of INNER_TYPE. */
10740
10741 static void
10742 sparc_handle_vis_mul8x16 (tree *n_elts, enum sparc_builtins fncode,
10743 tree inner_type, tree cst0, tree cst1)
10744 {
10745 unsigned i, num = VECTOR_CST_NELTS (cst0);
10746 int scale;
10747
10748 switch (fncode)
10749 {
10750 case SPARC_BUILTIN_FMUL8X16:
10751 for (i = 0; i < num; ++i)
10752 {
10753 int val
10754 = sparc_vis_mul8x16 (TREE_INT_CST_LOW (VECTOR_CST_ELT (cst0, i)),
10755 TREE_INT_CST_LOW (VECTOR_CST_ELT (cst1, i)));
10756 n_elts[i] = build_int_cst (inner_type, val);
10757 }
10758 break;
10759
10760 case SPARC_BUILTIN_FMUL8X16AU:
10761 scale = TREE_INT_CST_LOW (VECTOR_CST_ELT (cst1, 0));
10762
10763 for (i = 0; i < num; ++i)
10764 {
10765 int val
10766 = sparc_vis_mul8x16 (TREE_INT_CST_LOW (VECTOR_CST_ELT (cst0, i)),
10767 scale);
10768 n_elts[i] = build_int_cst (inner_type, val);
10769 }
10770 break;
10771
10772 case SPARC_BUILTIN_FMUL8X16AL:
10773 scale = TREE_INT_CST_LOW (VECTOR_CST_ELT (cst1, 1));
10774
10775 for (i = 0; i < num; ++i)
10776 {
10777 int val
10778 = sparc_vis_mul8x16 (TREE_INT_CST_LOW (VECTOR_CST_ELT (cst0, i)),
10779 scale);
10780 n_elts[i] = build_int_cst (inner_type, val);
10781 }
10782 break;
10783
10784 default:
10785 gcc_unreachable ();
10786 }
10787 }
10788
10789 /* Implement TARGET_FOLD_BUILTIN hook.
10790
10791 Fold builtin functions for SPARC intrinsics. If IGNORE is true the
10792 result of the function call is ignored. NULL_TREE is returned if the
10793 function could not be folded. */
10794
10795 static tree
10796 sparc_fold_builtin (tree fndecl, int n_args ATTRIBUTE_UNUSED,
10797 tree *args, bool ignore)
10798 {
10799 enum sparc_builtins code = (enum sparc_builtins) DECL_FUNCTION_CODE (fndecl);
10800 tree rtype = TREE_TYPE (TREE_TYPE (fndecl));
10801 tree arg0, arg1, arg2;
10802
10803 if (ignore)
10804 switch (code)
10805 {
10806 case SPARC_BUILTIN_LDFSR:
10807 case SPARC_BUILTIN_STFSR:
10808 case SPARC_BUILTIN_ALIGNADDR:
10809 case SPARC_BUILTIN_WRGSR:
10810 case SPARC_BUILTIN_BMASK:
10811 case SPARC_BUILTIN_CMASK8:
10812 case SPARC_BUILTIN_CMASK16:
10813 case SPARC_BUILTIN_CMASK32:
10814 break;
10815
10816 default:
10817 return build_zero_cst (rtype);
10818 }
10819
10820 switch (code)
10821 {
10822 case SPARC_BUILTIN_FEXPAND:
10823 arg0 = args[0];
10824 STRIP_NOPS (arg0);
10825
10826 if (TREE_CODE (arg0) == VECTOR_CST)
10827 {
10828 tree inner_type = TREE_TYPE (rtype);
10829 tree *n_elts;
10830 unsigned i;
10831
10832 n_elts = XALLOCAVEC (tree, VECTOR_CST_NELTS (arg0));
10833 for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
10834 n_elts[i] = build_int_cst (inner_type,
10835 TREE_INT_CST_LOW
10836 (VECTOR_CST_ELT (arg0, i)) << 4);
10837 return build_vector (rtype, n_elts);
10838 }
10839 break;
10840
10841 case SPARC_BUILTIN_FMUL8X16:
10842 case SPARC_BUILTIN_FMUL8X16AU:
10843 case SPARC_BUILTIN_FMUL8X16AL:
10844 arg0 = args[0];
10845 arg1 = args[1];
10846 STRIP_NOPS (arg0);
10847 STRIP_NOPS (arg1);
10848
10849 if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)
10850 {
10851 tree inner_type = TREE_TYPE (rtype);
10852 tree *n_elts = XALLOCAVEC (tree, VECTOR_CST_NELTS (arg0));
10853 sparc_handle_vis_mul8x16 (n_elts, code, inner_type, arg0, arg1);
10854 return build_vector (rtype, n_elts);
10855 }
10856 break;
10857
10858 case SPARC_BUILTIN_FPMERGE:
10859 arg0 = args[0];
10860 arg1 = args[1];
10861 STRIP_NOPS (arg0);
10862 STRIP_NOPS (arg1);
10863
10864 if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)
10865 {
10866 tree *n_elts = XALLOCAVEC (tree, 2 * VECTOR_CST_NELTS (arg0));
10867 unsigned i;
10868 for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
10869 {
10870 n_elts[2*i] = VECTOR_CST_ELT (arg0, i);
10871 n_elts[2*i+1] = VECTOR_CST_ELT (arg1, i);
10872 }
10873
10874 return build_vector (rtype, n_elts);
10875 }
10876 break;
10877
10878 case SPARC_BUILTIN_PDIST:
10879 case SPARC_BUILTIN_PDISTN:
10880 arg0 = args[0];
10881 arg1 = args[1];
10882 STRIP_NOPS (arg0);
10883 STRIP_NOPS (arg1);
10884 if (code == SPARC_BUILTIN_PDIST)
10885 {
10886 arg2 = args[2];
10887 STRIP_NOPS (arg2);
10888 }
10889 else
10890 arg2 = integer_zero_node;
10891
10892 if (TREE_CODE (arg0) == VECTOR_CST
10893 && TREE_CODE (arg1) == VECTOR_CST
10894 && TREE_CODE (arg2) == INTEGER_CST)
10895 {
10896 bool overflow = false;
10897 widest_int result = wi::to_widest (arg2);
10898 widest_int tmp;
10899 unsigned i;
10900
10901 for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
10902 {
10903 tree e0 = VECTOR_CST_ELT (arg0, i);
10904 tree e1 = VECTOR_CST_ELT (arg1, i);
10905
10906 bool neg1_ovf, neg2_ovf, add1_ovf, add2_ovf;
10907
10908 tmp = wi::neg (wi::to_widest (e1), &neg1_ovf);
10909 tmp = wi::add (wi::to_widest (e0), tmp, SIGNED, &add1_ovf);
10910 if (wi::neg_p (tmp))
10911 tmp = wi::neg (tmp, &neg2_ovf);
10912 else
10913 neg2_ovf = false;
10914 result = wi::add (result, tmp, SIGNED, &add2_ovf);
10915 overflow |= neg1_ovf | neg2_ovf | add1_ovf | add2_ovf;
10916 }
10917
10918 gcc_assert (!overflow);
10919
10920 return wide_int_to_tree (rtype, result);
10921 }
10922
10923 default:
10924 break;
10925 }
10926
10927 return NULL_TREE;
10928 }
10929 \f
10930 /* ??? This duplicates information provided to the compiler by the
10931 ??? scheduler description. Some day, teach genautomata to output
10932 ??? the latencies and then CSE will just use that. */
10933
10934 static bool
10935 sparc_rtx_costs (rtx x, int code, int outer_code, int opno ATTRIBUTE_UNUSED,
10936 int *total, bool speed ATTRIBUTE_UNUSED)
10937 {
10938 machine_mode mode = GET_MODE (x);
10939 bool float_mode_p = FLOAT_MODE_P (mode);
10940
10941 switch (code)
10942 {
10943 case CONST_INT:
10944 if (INTVAL (x) < 0x1000 && INTVAL (x) >= -0x1000)
10945 {
10946 *total = 0;
10947 return true;
10948 }
10949 /* FALLTHRU */
10950
10951 case HIGH:
10952 *total = 2;
10953 return true;
10954
10955 case CONST:
10956 case LABEL_REF:
10957 case SYMBOL_REF:
10958 *total = 4;
10959 return true;
10960
10961 case CONST_DOUBLE:
10962 if (GET_MODE (x) == VOIDmode
10963 && ((CONST_DOUBLE_HIGH (x) == 0
10964 && CONST_DOUBLE_LOW (x) < 0x1000)
10965 || (CONST_DOUBLE_HIGH (x) == -1
10966 && CONST_DOUBLE_LOW (x) < 0
10967 && CONST_DOUBLE_LOW (x) >= -0x1000)))
10968 *total = 0;
10969 else
10970 *total = 8;
10971 return true;
10972
10973 case MEM:
10974 /* If outer-code was a sign or zero extension, a cost
10975 of COSTS_N_INSNS (1) was already added in. This is
10976 why we are subtracting it back out. */
10977 if (outer_code == ZERO_EXTEND)
10978 {
10979 *total = sparc_costs->int_zload - COSTS_N_INSNS (1);
10980 }
10981 else if (outer_code == SIGN_EXTEND)
10982 {
10983 *total = sparc_costs->int_sload - COSTS_N_INSNS (1);
10984 }
10985 else if (float_mode_p)
10986 {
10987 *total = sparc_costs->float_load;
10988 }
10989 else
10990 {
10991 *total = sparc_costs->int_load;
10992 }
10993
10994 return true;
10995
10996 case PLUS:
10997 case MINUS:
10998 if (float_mode_p)
10999 *total = sparc_costs->float_plusminus;
11000 else
11001 *total = COSTS_N_INSNS (1);
11002 return false;
11003
11004 case FMA:
11005 {
11006 rtx sub;
11007
11008 gcc_assert (float_mode_p);
11009 *total = sparc_costs->float_mul;
11010
11011 sub = XEXP (x, 0);
11012 if (GET_CODE (sub) == NEG)
11013 sub = XEXP (sub, 0);
11014 *total += rtx_cost (sub, FMA, 0, speed);
11015
11016 sub = XEXP (x, 2);
11017 if (GET_CODE (sub) == NEG)
11018 sub = XEXP (sub, 0);
11019 *total += rtx_cost (sub, FMA, 2, speed);
11020 return true;
11021 }
11022
11023 case MULT:
11024 if (float_mode_p)
11025 *total = sparc_costs->float_mul;
11026 else if (TARGET_ARCH32 && !TARGET_HARD_MUL)
11027 *total = COSTS_N_INSNS (25);
11028 else
11029 {
11030 int bit_cost;
11031
11032 bit_cost = 0;
11033 if (sparc_costs->int_mul_bit_factor)
11034 {
11035 int nbits;
11036
11037 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
11038 {
11039 unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
11040 for (nbits = 0; value != 0; value &= value - 1)
11041 nbits++;
11042 }
11043 else if (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
11044 && GET_MODE (XEXP (x, 1)) == VOIDmode)
11045 {
11046 rtx x1 = XEXP (x, 1);
11047 unsigned HOST_WIDE_INT value1 = CONST_DOUBLE_LOW (x1);
11048 unsigned HOST_WIDE_INT value2 = CONST_DOUBLE_HIGH (x1);
11049
11050 for (nbits = 0; value1 != 0; value1 &= value1 - 1)
11051 nbits++;
11052 for (; value2 != 0; value2 &= value2 - 1)
11053 nbits++;
11054 }
11055 else
11056 nbits = 7;
11057
11058 if (nbits < 3)
11059 nbits = 3;
11060 bit_cost = (nbits - 3) / sparc_costs->int_mul_bit_factor;
11061 bit_cost = COSTS_N_INSNS (bit_cost);
11062 }
11063
11064 if (mode == DImode || !TARGET_HARD_MUL)
11065 *total = sparc_costs->int_mulX + bit_cost;
11066 else
11067 *total = sparc_costs->int_mul + bit_cost;
11068 }
11069 return false;
11070
11071 case ASHIFT:
11072 case ASHIFTRT:
11073 case LSHIFTRT:
11074 *total = COSTS_N_INSNS (1) + sparc_costs->shift_penalty;
11075 return false;
11076
11077 case DIV:
11078 case UDIV:
11079 case MOD:
11080 case UMOD:
11081 if (float_mode_p)
11082 {
11083 if (mode == DFmode)
11084 *total = sparc_costs->float_div_df;
11085 else
11086 *total = sparc_costs->float_div_sf;
11087 }
11088 else
11089 {
11090 if (mode == DImode)
11091 *total = sparc_costs->int_divX;
11092 else
11093 *total = sparc_costs->int_div;
11094 }
11095 return false;
11096
11097 case NEG:
11098 if (! float_mode_p)
11099 {
11100 *total = COSTS_N_INSNS (1);
11101 return false;
11102 }
11103 /* FALLTHRU */
11104
11105 case ABS:
11106 case FLOAT:
11107 case UNSIGNED_FLOAT:
11108 case FIX:
11109 case UNSIGNED_FIX:
11110 case FLOAT_EXTEND:
11111 case FLOAT_TRUNCATE:
11112 *total = sparc_costs->float_move;
11113 return false;
11114
11115 case SQRT:
11116 if (mode == DFmode)
11117 *total = sparc_costs->float_sqrt_df;
11118 else
11119 *total = sparc_costs->float_sqrt_sf;
11120 return false;
11121
11122 case COMPARE:
11123 if (float_mode_p)
11124 *total = sparc_costs->float_cmp;
11125 else
11126 *total = COSTS_N_INSNS (1);
11127 return false;
11128
11129 case IF_THEN_ELSE:
11130 if (float_mode_p)
11131 *total = sparc_costs->float_cmove;
11132 else
11133 *total = sparc_costs->int_cmove;
11134 return false;
11135
11136 case IOR:
11137 /* Handle the NAND vector patterns. */
11138 if (sparc_vector_mode_supported_p (GET_MODE (x))
11139 && GET_CODE (XEXP (x, 0)) == NOT
11140 && GET_CODE (XEXP (x, 1)) == NOT)
11141 {
11142 *total = COSTS_N_INSNS (1);
11143 return true;
11144 }
11145 else
11146 return false;
11147
11148 default:
11149 return false;
11150 }
11151 }
11152
11153 /* Return true if CLASS is either GENERAL_REGS or I64_REGS. */
11154
11155 static inline bool
11156 general_or_i64_p (reg_class_t rclass)
11157 {
11158 return (rclass == GENERAL_REGS || rclass == I64_REGS);
11159 }
11160
11161 /* Implement TARGET_REGISTER_MOVE_COST. */
11162
11163 static int
11164 sparc_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
11165 reg_class_t from, reg_class_t to)
11166 {
11167 bool need_memory = false;
11168
11169 if (from == FPCC_REGS || to == FPCC_REGS)
11170 need_memory = true;
11171 else if ((FP_REG_CLASS_P (from) && general_or_i64_p (to))
11172 || (general_or_i64_p (from) && FP_REG_CLASS_P (to)))
11173 {
11174 if (TARGET_VIS3)
11175 {
11176 int size = GET_MODE_SIZE (mode);
11177 if (size == 8 || size == 4)
11178 {
11179 if (! TARGET_ARCH32 || size == 4)
11180 return 4;
11181 else
11182 return 6;
11183 }
11184 }
11185 need_memory = true;
11186 }
11187
11188 if (need_memory)
11189 {
11190 if (sparc_cpu == PROCESSOR_ULTRASPARC
11191 || sparc_cpu == PROCESSOR_ULTRASPARC3
11192 || sparc_cpu == PROCESSOR_NIAGARA
11193 || sparc_cpu == PROCESSOR_NIAGARA2
11194 || sparc_cpu == PROCESSOR_NIAGARA3
11195 || sparc_cpu == PROCESSOR_NIAGARA4)
11196 return 12;
11197
11198 return 6;
11199 }
11200
11201 return 2;
11202 }
11203
11204 /* Emit the sequence of insns SEQ while preserving the registers REG and REG2.
11205 This is achieved by means of a manual dynamic stack space allocation in
11206 the current frame. We make the assumption that SEQ doesn't contain any
11207 function calls, with the possible exception of calls to the GOT helper. */
11208
11209 static void
11210 emit_and_preserve (rtx seq, rtx reg, rtx reg2)
11211 {
11212 /* We must preserve the lowest 16 words for the register save area. */
11213 HOST_WIDE_INT offset = 16*UNITS_PER_WORD;
11214 /* We really need only 2 words of fresh stack space. */
11215 HOST_WIDE_INT size = SPARC_STACK_ALIGN (offset + 2*UNITS_PER_WORD);
11216
11217 rtx slot
11218 = gen_rtx_MEM (word_mode, plus_constant (Pmode, stack_pointer_rtx,
11219 SPARC_STACK_BIAS + offset));
11220
11221 emit_insn (gen_stack_pointer_inc (GEN_INT (-size)));
11222 emit_insn (gen_rtx_SET (slot, reg));
11223 if (reg2)
11224 emit_insn (gen_rtx_SET (adjust_address (slot, word_mode, UNITS_PER_WORD),
11225 reg2));
11226 emit_insn (seq);
11227 if (reg2)
11228 emit_insn (gen_rtx_SET (reg2,
11229 adjust_address (slot, word_mode, UNITS_PER_WORD)));
11230 emit_insn (gen_rtx_SET (reg, slot));
11231 emit_insn (gen_stack_pointer_inc (GEN_INT (size)));
11232 }
11233
11234 /* Output the assembler code for a thunk function. THUNK_DECL is the
11235 declaration for the thunk function itself, FUNCTION is the decl for
11236 the target function. DELTA is an immediate constant offset to be
11237 added to THIS. If VCALL_OFFSET is nonzero, the word at address
11238 (*THIS + VCALL_OFFSET) should be additionally added to THIS. */
11239
11240 static void
11241 sparc_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
11242 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
11243 tree function)
11244 {
11245 rtx this_rtx, funexp;
11246 rtx_insn *insn;
11247 unsigned int int_arg_first;
11248
11249 reload_completed = 1;
11250 epilogue_completed = 1;
11251
11252 emit_note (NOTE_INSN_PROLOGUE_END);
11253
11254 if (TARGET_FLAT)
11255 {
11256 sparc_leaf_function_p = 1;
11257
11258 int_arg_first = SPARC_OUTGOING_INT_ARG_FIRST;
11259 }
11260 else if (flag_delayed_branch)
11261 {
11262 /* We will emit a regular sibcall below, so we need to instruct
11263 output_sibcall that we are in a leaf function. */
11264 sparc_leaf_function_p = crtl->uses_only_leaf_regs = 1;
11265
11266 /* This will cause final.c to invoke leaf_renumber_regs so we
11267 must behave as if we were in a not-yet-leafified function. */
11268 int_arg_first = SPARC_INCOMING_INT_ARG_FIRST;
11269 }
11270 else
11271 {
11272 /* We will emit the sibcall manually below, so we will need to
11273 manually spill non-leaf registers. */
11274 sparc_leaf_function_p = crtl->uses_only_leaf_regs = 0;
11275
11276 /* We really are in a leaf function. */
11277 int_arg_first = SPARC_OUTGOING_INT_ARG_FIRST;
11278 }
11279
11280 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
11281 returns a structure, the structure return pointer is there instead. */
11282 if (TARGET_ARCH64
11283 && aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
11284 this_rtx = gen_rtx_REG (Pmode, int_arg_first + 1);
11285 else
11286 this_rtx = gen_rtx_REG (Pmode, int_arg_first);
11287
11288 /* Add DELTA. When possible use a plain add, otherwise load it into
11289 a register first. */
11290 if (delta)
11291 {
11292 rtx delta_rtx = GEN_INT (delta);
11293
11294 if (! SPARC_SIMM13_P (delta))
11295 {
11296 rtx scratch = gen_rtx_REG (Pmode, 1);
11297 emit_move_insn (scratch, delta_rtx);
11298 delta_rtx = scratch;
11299 }
11300
11301 /* THIS_RTX += DELTA. */
11302 emit_insn (gen_add2_insn (this_rtx, delta_rtx));
11303 }
11304
11305 /* Add the word at address (*THIS_RTX + VCALL_OFFSET). */
11306 if (vcall_offset)
11307 {
11308 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
11309 rtx scratch = gen_rtx_REG (Pmode, 1);
11310
11311 gcc_assert (vcall_offset < 0);
11312
11313 /* SCRATCH = *THIS_RTX. */
11314 emit_move_insn (scratch, gen_rtx_MEM (Pmode, this_rtx));
11315
11316 /* Prepare for adding VCALL_OFFSET. The difficulty is that we
11317 may not have any available scratch register at this point. */
11318 if (SPARC_SIMM13_P (vcall_offset))
11319 ;
11320 /* This is the case if ARCH64 (unless -ffixed-g5 is passed). */
11321 else if (! fixed_regs[5]
11322 /* The below sequence is made up of at least 2 insns,
11323 while the default method may need only one. */
11324 && vcall_offset < -8192)
11325 {
11326 rtx scratch2 = gen_rtx_REG (Pmode, 5);
11327 emit_move_insn (scratch2, vcall_offset_rtx);
11328 vcall_offset_rtx = scratch2;
11329 }
11330 else
11331 {
11332 rtx increment = GEN_INT (-4096);
11333
11334 /* VCALL_OFFSET is a negative number whose typical range can be
11335 estimated as -32768..0 in 32-bit mode. In almost all cases
11336 it is therefore cheaper to emit multiple add insns than
11337 spilling and loading the constant into a register (at least
11338 6 insns). */
11339 while (! SPARC_SIMM13_P (vcall_offset))
11340 {
11341 emit_insn (gen_add2_insn (scratch, increment));
11342 vcall_offset += 4096;
11343 }
11344 vcall_offset_rtx = GEN_INT (vcall_offset); /* cannot be 0 */
11345 }
11346
11347 /* SCRATCH = *(*THIS_RTX + VCALL_OFFSET). */
11348 emit_move_insn (scratch, gen_rtx_MEM (Pmode,
11349 gen_rtx_PLUS (Pmode,
11350 scratch,
11351 vcall_offset_rtx)));
11352
11353 /* THIS_RTX += *(*THIS_RTX + VCALL_OFFSET). */
11354 emit_insn (gen_add2_insn (this_rtx, scratch));
11355 }
11356
11357 /* Generate a tail call to the target function. */
11358 if (! TREE_USED (function))
11359 {
11360 assemble_external (function);
11361 TREE_USED (function) = 1;
11362 }
11363 funexp = XEXP (DECL_RTL (function), 0);
11364
11365 if (flag_delayed_branch)
11366 {
11367 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
11368 insn = emit_call_insn (gen_sibcall (funexp));
11369 SIBLING_CALL_P (insn) = 1;
11370 }
11371 else
11372 {
11373 /* The hoops we have to jump through in order to generate a sibcall
11374 without using delay slots... */
11375 rtx spill_reg, seq, scratch = gen_rtx_REG (Pmode, 1);
11376
11377 if (flag_pic)
11378 {
11379 spill_reg = gen_rtx_REG (word_mode, 15); /* %o7 */
11380 start_sequence ();
11381 load_got_register (); /* clobbers %o7 */
11382 scratch = sparc_legitimize_pic_address (funexp, scratch);
11383 seq = get_insns ();
11384 end_sequence ();
11385 emit_and_preserve (seq, spill_reg, pic_offset_table_rtx);
11386 }
11387 else if (TARGET_ARCH32)
11388 {
11389 emit_insn (gen_rtx_SET (scratch,
11390 gen_rtx_HIGH (SImode, funexp)));
11391 emit_insn (gen_rtx_SET (scratch,
11392 gen_rtx_LO_SUM (SImode, scratch, funexp)));
11393 }
11394 else /* TARGET_ARCH64 */
11395 {
11396 switch (sparc_cmodel)
11397 {
11398 case CM_MEDLOW:
11399 case CM_MEDMID:
11400 /* The destination can serve as a temporary. */
11401 sparc_emit_set_symbolic_const64 (scratch, funexp, scratch);
11402 break;
11403
11404 case CM_MEDANY:
11405 case CM_EMBMEDANY:
11406 /* The destination cannot serve as a temporary. */
11407 spill_reg = gen_rtx_REG (DImode, 15); /* %o7 */
11408 start_sequence ();
11409 sparc_emit_set_symbolic_const64 (scratch, funexp, spill_reg);
11410 seq = get_insns ();
11411 end_sequence ();
11412 emit_and_preserve (seq, spill_reg, 0);
11413 break;
11414
11415 default:
11416 gcc_unreachable ();
11417 }
11418 }
11419
11420 emit_jump_insn (gen_indirect_jump (scratch));
11421 }
11422
11423 emit_barrier ();
11424
11425 /* Run just enough of rest_of_compilation to get the insns emitted.
11426 There's not really enough bulk here to make other passes such as
11427 instruction scheduling worth while. Note that use_thunk calls
11428 assemble_start_function and assemble_end_function. */
11429 insn = get_insns ();
11430 shorten_branches (insn);
11431 final_start_function (insn, file, 1);
11432 final (insn, file, 1);
11433 final_end_function ();
11434
11435 reload_completed = 0;
11436 epilogue_completed = 0;
11437 }
11438
11439 /* Return true if sparc_output_mi_thunk would be able to output the
11440 assembler code for the thunk function specified by the arguments
11441 it is passed, and false otherwise. */
11442 static bool
11443 sparc_can_output_mi_thunk (const_tree thunk_fndecl ATTRIBUTE_UNUSED,
11444 HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
11445 HOST_WIDE_INT vcall_offset,
11446 const_tree function ATTRIBUTE_UNUSED)
11447 {
11448 /* Bound the loop used in the default method above. */
11449 return (vcall_offset >= -32768 || ! fixed_regs[5]);
11450 }
11451
11452 /* How to allocate a 'struct machine_function'. */
11453
11454 static struct machine_function *
11455 sparc_init_machine_status (void)
11456 {
11457 return ggc_cleared_alloc<machine_function> ();
11458 }
11459
11460 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
11461 We need to emit DTP-relative relocations. */
11462
11463 static void
11464 sparc_output_dwarf_dtprel (FILE *file, int size, rtx x)
11465 {
11466 switch (size)
11467 {
11468 case 4:
11469 fputs ("\t.word\t%r_tls_dtpoff32(", file);
11470 break;
11471 case 8:
11472 fputs ("\t.xword\t%r_tls_dtpoff64(", file);
11473 break;
11474 default:
11475 gcc_unreachable ();
11476 }
11477 output_addr_const (file, x);
11478 fputs (")", file);
11479 }
11480
11481 /* Do whatever processing is required at the end of a file. */
11482
11483 static void
11484 sparc_file_end (void)
11485 {
11486 /* If we need to emit the special GOT helper function, do so now. */
11487 if (got_helper_rtx)
11488 {
11489 const char *name = XSTR (got_helper_rtx, 0);
11490 const char *reg_name = reg_names[GLOBAL_OFFSET_TABLE_REGNUM];
11491 #ifdef DWARF2_UNWIND_INFO
11492 bool do_cfi;
11493 #endif
11494
11495 if (USE_HIDDEN_LINKONCE)
11496 {
11497 tree decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
11498 get_identifier (name),
11499 build_function_type_list (void_type_node,
11500 NULL_TREE));
11501 DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
11502 NULL_TREE, void_type_node);
11503 TREE_PUBLIC (decl) = 1;
11504 TREE_STATIC (decl) = 1;
11505 make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
11506 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
11507 DECL_VISIBILITY_SPECIFIED (decl) = 1;
11508 resolve_unique_section (decl, 0, flag_function_sections);
11509 allocate_struct_function (decl, true);
11510 cfun->is_thunk = 1;
11511 current_function_decl = decl;
11512 init_varasm_status ();
11513 assemble_start_function (decl, name);
11514 }
11515 else
11516 {
11517 const int align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
11518 switch_to_section (text_section);
11519 if (align > 0)
11520 ASM_OUTPUT_ALIGN (asm_out_file, align);
11521 ASM_OUTPUT_LABEL (asm_out_file, name);
11522 }
11523
11524 #ifdef DWARF2_UNWIND_INFO
11525 do_cfi = dwarf2out_do_cfi_asm ();
11526 if (do_cfi)
11527 fprintf (asm_out_file, "\t.cfi_startproc\n");
11528 #endif
11529 if (flag_delayed_branch)
11530 fprintf (asm_out_file, "\tjmp\t%%o7+8\n\t add\t%%o7, %s, %s\n",
11531 reg_name, reg_name);
11532 else
11533 fprintf (asm_out_file, "\tadd\t%%o7, %s, %s\n\tjmp\t%%o7+8\n\t nop\n",
11534 reg_name, reg_name);
11535 #ifdef DWARF2_UNWIND_INFO
11536 if (do_cfi)
11537 fprintf (asm_out_file, "\t.cfi_endproc\n");
11538 #endif
11539 }
11540
11541 if (NEED_INDICATE_EXEC_STACK)
11542 file_end_indicate_exec_stack ();
11543
11544 #ifdef TARGET_SOLARIS
11545 solaris_file_end ();
11546 #endif
11547 }
11548
11549 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
11550 /* Implement TARGET_MANGLE_TYPE. */
11551
11552 static const char *
11553 sparc_mangle_type (const_tree type)
11554 {
11555 if (!TARGET_64BIT
11556 && TYPE_MAIN_VARIANT (type) == long_double_type_node
11557 && TARGET_LONG_DOUBLE_128)
11558 return "g";
11559
11560 /* For all other types, use normal C++ mangling. */
11561 return NULL;
11562 }
11563 #endif
11564
11565 /* Expand a membar instruction for various use cases. Both the LOAD_STORE
11566 and BEFORE_AFTER arguments of the form X_Y. They are two-bit masks where
11567 bit 0 indicates that X is true, and bit 1 indicates Y is true. */
11568
11569 void
11570 sparc_emit_membar_for_model (enum memmodel model,
11571 int load_store, int before_after)
11572 {
11573 /* Bits for the MEMBAR mmask field. */
11574 const int LoadLoad = 1;
11575 const int StoreLoad = 2;
11576 const int LoadStore = 4;
11577 const int StoreStore = 8;
11578
11579 int mm = 0, implied = 0;
11580
11581 switch (sparc_memory_model)
11582 {
11583 case SMM_SC:
11584 /* Sequential Consistency. All memory transactions are immediately
11585 visible in sequential execution order. No barriers needed. */
11586 implied = LoadLoad | StoreLoad | LoadStore | StoreStore;
11587 break;
11588
11589 case SMM_TSO:
11590 /* Total Store Ordering: all memory transactions with store semantics
11591 are followed by an implied StoreStore. */
11592 implied |= StoreStore;
11593
11594 /* If we're not looking for a raw barrer (before+after), then atomic
11595 operations get the benefit of being both load and store. */
11596 if (load_store == 3 && before_after == 1)
11597 implied |= StoreLoad;
11598 /* FALLTHRU */
11599
11600 case SMM_PSO:
11601 /* Partial Store Ordering: all memory transactions with load semantics
11602 are followed by an implied LoadLoad | LoadStore. */
11603 implied |= LoadLoad | LoadStore;
11604
11605 /* If we're not looking for a raw barrer (before+after), then atomic
11606 operations get the benefit of being both load and store. */
11607 if (load_store == 3 && before_after == 2)
11608 implied |= StoreLoad | StoreStore;
11609 /* FALLTHRU */
11610
11611 case SMM_RMO:
11612 /* Relaxed Memory Ordering: no implicit bits. */
11613 break;
11614
11615 default:
11616 gcc_unreachable ();
11617 }
11618
11619 if (before_after & 1)
11620 {
11621 if (is_mm_release (model) || is_mm_acq_rel (model)
11622 || is_mm_seq_cst (model))
11623 {
11624 if (load_store & 1)
11625 mm |= LoadLoad | StoreLoad;
11626 if (load_store & 2)
11627 mm |= LoadStore | StoreStore;
11628 }
11629 }
11630 if (before_after & 2)
11631 {
11632 if (is_mm_acquire (model) || is_mm_acq_rel (model)
11633 || is_mm_seq_cst (model))
11634 {
11635 if (load_store & 1)
11636 mm |= LoadLoad | LoadStore;
11637 if (load_store & 2)
11638 mm |= StoreLoad | StoreStore;
11639 }
11640 }
11641
11642 /* Remove the bits implied by the system memory model. */
11643 mm &= ~implied;
11644
11645 /* For raw barriers (before+after), always emit a barrier.
11646 This will become a compile-time barrier if needed. */
11647 if (mm || before_after == 3)
11648 emit_insn (gen_membar (GEN_INT (mm)));
11649 }
11650
11651 /* Expand code to perform a 8 or 16-bit compare and swap by doing 32-bit
11652 compare and swap on the word containing the byte or half-word. */
11653
11654 static void
11655 sparc_expand_compare_and_swap_12 (rtx bool_result, rtx result, rtx mem,
11656 rtx oldval, rtx newval)
11657 {
11658 rtx addr1 = force_reg (Pmode, XEXP (mem, 0));
11659 rtx addr = gen_reg_rtx (Pmode);
11660 rtx off = gen_reg_rtx (SImode);
11661 rtx oldv = gen_reg_rtx (SImode);
11662 rtx newv = gen_reg_rtx (SImode);
11663 rtx oldvalue = gen_reg_rtx (SImode);
11664 rtx newvalue = gen_reg_rtx (SImode);
11665 rtx res = gen_reg_rtx (SImode);
11666 rtx resv = gen_reg_rtx (SImode);
11667 rtx memsi, val, mask, cc;
11668
11669 emit_insn (gen_rtx_SET (addr, gen_rtx_AND (Pmode, addr1, GEN_INT (-4))));
11670
11671 if (Pmode != SImode)
11672 addr1 = gen_lowpart (SImode, addr1);
11673 emit_insn (gen_rtx_SET (off, gen_rtx_AND (SImode, addr1, GEN_INT (3))));
11674
11675 memsi = gen_rtx_MEM (SImode, addr);
11676 set_mem_alias_set (memsi, ALIAS_SET_MEMORY_BARRIER);
11677 MEM_VOLATILE_P (memsi) = MEM_VOLATILE_P (mem);
11678
11679 val = copy_to_reg (memsi);
11680
11681 emit_insn (gen_rtx_SET (off,
11682 gen_rtx_XOR (SImode, off,
11683 GEN_INT (GET_MODE (mem) == QImode
11684 ? 3 : 2))));
11685
11686 emit_insn (gen_rtx_SET (off, gen_rtx_ASHIFT (SImode, off, GEN_INT (3))));
11687
11688 if (GET_MODE (mem) == QImode)
11689 mask = force_reg (SImode, GEN_INT (0xff));
11690 else
11691 mask = force_reg (SImode, GEN_INT (0xffff));
11692
11693 emit_insn (gen_rtx_SET (mask, gen_rtx_ASHIFT (SImode, mask, off)));
11694
11695 emit_insn (gen_rtx_SET (val,
11696 gen_rtx_AND (SImode, gen_rtx_NOT (SImode, mask),
11697 val)));
11698
11699 oldval = gen_lowpart (SImode, oldval);
11700 emit_insn (gen_rtx_SET (oldv, gen_rtx_ASHIFT (SImode, oldval, off)));
11701
11702 newval = gen_lowpart_common (SImode, newval);
11703 emit_insn (gen_rtx_SET (newv, gen_rtx_ASHIFT (SImode, newval, off)));
11704
11705 emit_insn (gen_rtx_SET (oldv, gen_rtx_AND (SImode, oldv, mask)));
11706
11707 emit_insn (gen_rtx_SET (newv, gen_rtx_AND (SImode, newv, mask)));
11708
11709 rtx_code_label *end_label = gen_label_rtx ();
11710 rtx_code_label *loop_label = gen_label_rtx ();
11711 emit_label (loop_label);
11712
11713 emit_insn (gen_rtx_SET (oldvalue, gen_rtx_IOR (SImode, oldv, val)));
11714
11715 emit_insn (gen_rtx_SET (newvalue, gen_rtx_IOR (SImode, newv, val)));
11716
11717 emit_move_insn (bool_result, const1_rtx);
11718
11719 emit_insn (gen_atomic_compare_and_swapsi_1 (res, memsi, oldvalue, newvalue));
11720
11721 emit_cmp_and_jump_insns (res, oldvalue, EQ, NULL, SImode, 0, end_label);
11722
11723 emit_insn (gen_rtx_SET (resv,
11724 gen_rtx_AND (SImode, gen_rtx_NOT (SImode, mask),
11725 res)));
11726
11727 emit_move_insn (bool_result, const0_rtx);
11728
11729 cc = gen_compare_reg_1 (NE, resv, val);
11730 emit_insn (gen_rtx_SET (val, resv));
11731
11732 /* Use cbranchcc4 to separate the compare and branch! */
11733 emit_jump_insn (gen_cbranchcc4 (gen_rtx_NE (VOIDmode, cc, const0_rtx),
11734 cc, const0_rtx, loop_label));
11735
11736 emit_label (end_label);
11737
11738 emit_insn (gen_rtx_SET (res, gen_rtx_AND (SImode, res, mask)));
11739
11740 emit_insn (gen_rtx_SET (res, gen_rtx_LSHIFTRT (SImode, res, off)));
11741
11742 emit_move_insn (result, gen_lowpart (GET_MODE (result), res));
11743 }
11744
11745 /* Expand code to perform a compare-and-swap. */
11746
11747 void
11748 sparc_expand_compare_and_swap (rtx operands[])
11749 {
11750 rtx bval, retval, mem, oldval, newval;
11751 machine_mode mode;
11752 enum memmodel model;
11753
11754 bval = operands[0];
11755 retval = operands[1];
11756 mem = operands[2];
11757 oldval = operands[3];
11758 newval = operands[4];
11759 model = (enum memmodel) INTVAL (operands[6]);
11760 mode = GET_MODE (mem);
11761
11762 sparc_emit_membar_for_model (model, 3, 1);
11763
11764 if (reg_overlap_mentioned_p (retval, oldval))
11765 oldval = copy_to_reg (oldval);
11766
11767 if (mode == QImode || mode == HImode)
11768 sparc_expand_compare_and_swap_12 (bval, retval, mem, oldval, newval);
11769 else
11770 {
11771 rtx (*gen) (rtx, rtx, rtx, rtx);
11772 rtx x;
11773
11774 if (mode == SImode)
11775 gen = gen_atomic_compare_and_swapsi_1;
11776 else
11777 gen = gen_atomic_compare_and_swapdi_1;
11778 emit_insn (gen (retval, mem, oldval, newval));
11779
11780 x = emit_store_flag (bval, EQ, retval, oldval, mode, 1, 1);
11781 if (x != bval)
11782 convert_move (bval, x, 1);
11783 }
11784
11785 sparc_emit_membar_for_model (model, 3, 2);
11786 }
11787
11788 void
11789 sparc_expand_vec_perm_bmask (machine_mode vmode, rtx sel)
11790 {
11791 rtx t_1, t_2, t_3;
11792
11793 sel = gen_lowpart (DImode, sel);
11794 switch (vmode)
11795 {
11796 case V2SImode:
11797 /* inp = xxxxxxxAxxxxxxxB */
11798 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (16),
11799 NULL_RTX, 1, OPTAB_DIRECT);
11800 /* t_1 = ....xxxxxxxAxxx. */
11801 sel = expand_simple_binop (SImode, AND, gen_lowpart (SImode, sel),
11802 GEN_INT (3), NULL_RTX, 1, OPTAB_DIRECT);
11803 t_1 = expand_simple_binop (SImode, AND, gen_lowpart (SImode, t_1),
11804 GEN_INT (0x30000), NULL_RTX, 1, OPTAB_DIRECT);
11805 /* sel = .......B */
11806 /* t_1 = ...A.... */
11807 sel = expand_simple_binop (SImode, IOR, sel, t_1, sel, 1, OPTAB_DIRECT);
11808 /* sel = ...A...B */
11809 sel = expand_mult (SImode, sel, GEN_INT (0x4444), sel, 1);
11810 /* sel = AAAABBBB * 4 */
11811 t_1 = force_reg (SImode, GEN_INT (0x01230123));
11812 /* sel = { A*4, A*4+1, A*4+2, ... } */
11813 break;
11814
11815 case V4HImode:
11816 /* inp = xxxAxxxBxxxCxxxD */
11817 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (8),
11818 NULL_RTX, 1, OPTAB_DIRECT);
11819 t_2 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (16),
11820 NULL_RTX, 1, OPTAB_DIRECT);
11821 t_3 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (24),
11822 NULL_RTX, 1, OPTAB_DIRECT);
11823 /* t_1 = ..xxxAxxxBxxxCxx */
11824 /* t_2 = ....xxxAxxxBxxxC */
11825 /* t_3 = ......xxxAxxxBxx */
11826 sel = expand_simple_binop (SImode, AND, gen_lowpart (SImode, sel),
11827 GEN_INT (0x07),
11828 NULL_RTX, 1, OPTAB_DIRECT);
11829 t_1 = expand_simple_binop (SImode, AND, gen_lowpart (SImode, t_1),
11830 GEN_INT (0x0700),
11831 NULL_RTX, 1, OPTAB_DIRECT);
11832 t_2 = expand_simple_binop (SImode, AND, gen_lowpart (SImode, t_2),
11833 GEN_INT (0x070000),
11834 NULL_RTX, 1, OPTAB_DIRECT);
11835 t_3 = expand_simple_binop (SImode, AND, gen_lowpart (SImode, t_3),
11836 GEN_INT (0x07000000),
11837 NULL_RTX, 1, OPTAB_DIRECT);
11838 /* sel = .......D */
11839 /* t_1 = .....C.. */
11840 /* t_2 = ...B.... */
11841 /* t_3 = .A...... */
11842 sel = expand_simple_binop (SImode, IOR, sel, t_1, sel, 1, OPTAB_DIRECT);
11843 t_2 = expand_simple_binop (SImode, IOR, t_2, t_3, t_2, 1, OPTAB_DIRECT);
11844 sel = expand_simple_binop (SImode, IOR, sel, t_2, sel, 1, OPTAB_DIRECT);
11845 /* sel = .A.B.C.D */
11846 sel = expand_mult (SImode, sel, GEN_INT (0x22), sel, 1);
11847 /* sel = AABBCCDD * 2 */
11848 t_1 = force_reg (SImode, GEN_INT (0x01010101));
11849 /* sel = { A*2, A*2+1, B*2, B*2+1, ... } */
11850 break;
11851
11852 case V8QImode:
11853 /* input = xAxBxCxDxExFxGxH */
11854 sel = expand_simple_binop (DImode, AND, sel,
11855 GEN_INT ((HOST_WIDE_INT)0x0f0f0f0f << 32
11856 | 0x0f0f0f0f),
11857 NULL_RTX, 1, OPTAB_DIRECT);
11858 /* sel = .A.B.C.D.E.F.G.H */
11859 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (4),
11860 NULL_RTX, 1, OPTAB_DIRECT);
11861 /* t_1 = ..A.B.C.D.E.F.G. */
11862 sel = expand_simple_binop (DImode, IOR, sel, t_1,
11863 NULL_RTX, 1, OPTAB_DIRECT);
11864 /* sel = .AABBCCDDEEFFGGH */
11865 sel = expand_simple_binop (DImode, AND, sel,
11866 GEN_INT ((HOST_WIDE_INT)0xff00ff << 32
11867 | 0xff00ff),
11868 NULL_RTX, 1, OPTAB_DIRECT);
11869 /* sel = ..AB..CD..EF..GH */
11870 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (8),
11871 NULL_RTX, 1, OPTAB_DIRECT);
11872 /* t_1 = ....AB..CD..EF.. */
11873 sel = expand_simple_binop (DImode, IOR, sel, t_1,
11874 NULL_RTX, 1, OPTAB_DIRECT);
11875 /* sel = ..ABABCDCDEFEFGH */
11876 sel = expand_simple_binop (DImode, AND, sel,
11877 GEN_INT ((HOST_WIDE_INT)0xffff << 32 | 0xffff),
11878 NULL_RTX, 1, OPTAB_DIRECT);
11879 /* sel = ....ABCD....EFGH */
11880 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (16),
11881 NULL_RTX, 1, OPTAB_DIRECT);
11882 /* t_1 = ........ABCD.... */
11883 sel = gen_lowpart (SImode, sel);
11884 t_1 = gen_lowpart (SImode, t_1);
11885 break;
11886
11887 default:
11888 gcc_unreachable ();
11889 }
11890
11891 /* Always perform the final addition/merge within the bmask insn. */
11892 emit_insn (gen_bmasksi_vis (gen_rtx_REG (SImode, 0), sel, t_1));
11893 }
11894
11895 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
11896
11897 static bool
11898 sparc_frame_pointer_required (void)
11899 {
11900 /* If the stack pointer is dynamically modified in the function, it cannot
11901 serve as the frame pointer. */
11902 if (cfun->calls_alloca)
11903 return true;
11904
11905 /* If the function receives nonlocal gotos, it needs to save the frame
11906 pointer in the nonlocal_goto_save_area object. */
11907 if (cfun->has_nonlocal_label)
11908 return true;
11909
11910 /* In flat mode, that's it. */
11911 if (TARGET_FLAT)
11912 return false;
11913
11914 /* Otherwise, the frame pointer is required if the function isn't leaf. */
11915 return !(crtl->is_leaf && only_leaf_regs_used ());
11916 }
11917
11918 /* The way this is structured, we can't eliminate SFP in favor of SP
11919 if the frame pointer is required: we want to use the SFP->HFP elimination
11920 in that case. But the test in update_eliminables doesn't know we are
11921 assuming below that we only do the former elimination. */
11922
11923 static bool
11924 sparc_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
11925 {
11926 return to == HARD_FRAME_POINTER_REGNUM || !sparc_frame_pointer_required ();
11927 }
11928
11929 /* Return the hard frame pointer directly to bypass the stack bias. */
11930
11931 static rtx
11932 sparc_builtin_setjmp_frame_value (void)
11933 {
11934 return hard_frame_pointer_rtx;
11935 }
11936
11937 /* If !TARGET_FPU, then make the fp registers and fp cc regs fixed so that
11938 they won't be allocated. */
11939
11940 static void
11941 sparc_conditional_register_usage (void)
11942 {
11943 if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
11944 {
11945 fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
11946 call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
11947 }
11948 /* If the user has passed -f{fixed,call-{used,saved}}-g5 */
11949 /* then honor it. */
11950 if (TARGET_ARCH32 && fixed_regs[5])
11951 fixed_regs[5] = 1;
11952 else if (TARGET_ARCH64 && fixed_regs[5] == 2)
11953 fixed_regs[5] = 0;
11954 if (! TARGET_V9)
11955 {
11956 int regno;
11957 for (regno = SPARC_FIRST_V9_FP_REG;
11958 regno <= SPARC_LAST_V9_FP_REG;
11959 regno++)
11960 fixed_regs[regno] = 1;
11961 /* %fcc0 is used by v8 and v9. */
11962 for (regno = SPARC_FIRST_V9_FCC_REG + 1;
11963 regno <= SPARC_LAST_V9_FCC_REG;
11964 regno++)
11965 fixed_regs[regno] = 1;
11966 }
11967 if (! TARGET_FPU)
11968 {
11969 int regno;
11970 for (regno = 32; regno < SPARC_LAST_V9_FCC_REG; regno++)
11971 fixed_regs[regno] = 1;
11972 }
11973 /* If the user has passed -f{fixed,call-{used,saved}}-g2 */
11974 /* then honor it. Likewise with g3 and g4. */
11975 if (fixed_regs[2] == 2)
11976 fixed_regs[2] = ! TARGET_APP_REGS;
11977 if (fixed_regs[3] == 2)
11978 fixed_regs[3] = ! TARGET_APP_REGS;
11979 if (TARGET_ARCH32 && fixed_regs[4] == 2)
11980 fixed_regs[4] = ! TARGET_APP_REGS;
11981 else if (TARGET_CM_EMBMEDANY)
11982 fixed_regs[4] = 1;
11983 else if (fixed_regs[4] == 2)
11984 fixed_regs[4] = 0;
11985 if (TARGET_FLAT)
11986 {
11987 int regno;
11988 /* Disable leaf functions. */
11989 memset (sparc_leaf_regs, 0, FIRST_PSEUDO_REGISTER);
11990 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11991 leaf_reg_remap [regno] = regno;
11992 }
11993 if (TARGET_VIS)
11994 global_regs[SPARC_GSR_REG] = 1;
11995 }
11996
11997 /* Implement TARGET_PREFERRED_RELOAD_CLASS:
11998
11999 - We can't load constants into FP registers.
12000 - We can't load FP constants into integer registers when soft-float,
12001 because there is no soft-float pattern with a r/F constraint.
12002 - We can't load FP constants into integer registers for TFmode unless
12003 it is 0.0L, because there is no movtf pattern with a r/F constraint.
12004 - Try and reload integer constants (symbolic or otherwise) back into
12005 registers directly, rather than having them dumped to memory. */
12006
12007 static reg_class_t
12008 sparc_preferred_reload_class (rtx x, reg_class_t rclass)
12009 {
12010 machine_mode mode = GET_MODE (x);
12011 if (CONSTANT_P (x))
12012 {
12013 if (FP_REG_CLASS_P (rclass)
12014 || rclass == GENERAL_OR_FP_REGS
12015 || rclass == GENERAL_OR_EXTRA_FP_REGS
12016 || (GET_MODE_CLASS (mode) == MODE_FLOAT && ! TARGET_FPU)
12017 || (mode == TFmode && ! const_zero_operand (x, mode)))
12018 return NO_REGS;
12019
12020 if (GET_MODE_CLASS (mode) == MODE_INT)
12021 return GENERAL_REGS;
12022
12023 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12024 {
12025 if (! FP_REG_CLASS_P (rclass)
12026 || !(const_zero_operand (x, mode)
12027 || const_all_ones_operand (x, mode)))
12028 return NO_REGS;
12029 }
12030 }
12031
12032 if (TARGET_VIS3
12033 && ! TARGET_ARCH64
12034 && (rclass == EXTRA_FP_REGS
12035 || rclass == GENERAL_OR_EXTRA_FP_REGS))
12036 {
12037 int regno = true_regnum (x);
12038
12039 if (SPARC_INT_REG_P (regno))
12040 return (rclass == EXTRA_FP_REGS
12041 ? FP_REGS : GENERAL_OR_FP_REGS);
12042 }
12043
12044 return rclass;
12045 }
12046
12047 /* Output a wide multiply instruction in V8+ mode. INSN is the instruction,
12048 OPERANDS are its operands and OPCODE is the mnemonic to be used. */
12049
12050 const char *
12051 output_v8plus_mult (rtx_insn *insn, rtx *operands, const char *opcode)
12052 {
12053 char mulstr[32];
12054
12055 gcc_assert (! TARGET_ARCH64);
12056
12057 if (sparc_check_64 (operands[1], insn) <= 0)
12058 output_asm_insn ("srl\t%L1, 0, %L1", operands);
12059 if (which_alternative == 1)
12060 output_asm_insn ("sllx\t%H1, 32, %H1", operands);
12061 if (GET_CODE (operands[2]) == CONST_INT)
12062 {
12063 if (which_alternative == 1)
12064 {
12065 output_asm_insn ("or\t%L1, %H1, %H1", operands);
12066 sprintf (mulstr, "%s\t%%H1, %%2, %%L0", opcode);
12067 output_asm_insn (mulstr, operands);
12068 return "srlx\t%L0, 32, %H0";
12069 }
12070 else
12071 {
12072 output_asm_insn ("sllx\t%H1, 32, %3", operands);
12073 output_asm_insn ("or\t%L1, %3, %3", operands);
12074 sprintf (mulstr, "%s\t%%3, %%2, %%3", opcode);
12075 output_asm_insn (mulstr, operands);
12076 output_asm_insn ("srlx\t%3, 32, %H0", operands);
12077 return "mov\t%3, %L0";
12078 }
12079 }
12080 else if (rtx_equal_p (operands[1], operands[2]))
12081 {
12082 if (which_alternative == 1)
12083 {
12084 output_asm_insn ("or\t%L1, %H1, %H1", operands);
12085 sprintf (mulstr, "%s\t%%H1, %%H1, %%L0", opcode);
12086 output_asm_insn (mulstr, operands);
12087 return "srlx\t%L0, 32, %H0";
12088 }
12089 else
12090 {
12091 output_asm_insn ("sllx\t%H1, 32, %3", operands);
12092 output_asm_insn ("or\t%L1, %3, %3", operands);
12093 sprintf (mulstr, "%s\t%%3, %%3, %%3", opcode);
12094 output_asm_insn (mulstr, operands);
12095 output_asm_insn ("srlx\t%3, 32, %H0", operands);
12096 return "mov\t%3, %L0";
12097 }
12098 }
12099 if (sparc_check_64 (operands[2], insn) <= 0)
12100 output_asm_insn ("srl\t%L2, 0, %L2", operands);
12101 if (which_alternative == 1)
12102 {
12103 output_asm_insn ("or\t%L1, %H1, %H1", operands);
12104 output_asm_insn ("sllx\t%H2, 32, %L1", operands);
12105 output_asm_insn ("or\t%L2, %L1, %L1", operands);
12106 sprintf (mulstr, "%s\t%%H1, %%L1, %%L0", opcode);
12107 output_asm_insn (mulstr, operands);
12108 return "srlx\t%L0, 32, %H0";
12109 }
12110 else
12111 {
12112 output_asm_insn ("sllx\t%H1, 32, %3", operands);
12113 output_asm_insn ("sllx\t%H2, 32, %4", operands);
12114 output_asm_insn ("or\t%L1, %3, %3", operands);
12115 output_asm_insn ("or\t%L2, %4, %4", operands);
12116 sprintf (mulstr, "%s\t%%3, %%4, %%3", opcode);
12117 output_asm_insn (mulstr, operands);
12118 output_asm_insn ("srlx\t%3, 32, %H0", operands);
12119 return "mov\t%3, %L0";
12120 }
12121 }
12122
12123 /* Subroutine of sparc_expand_vector_init. Emit code to initialize
12124 all fields of TARGET to ELT by means of VIS2 BSHUFFLE insn. MODE
12125 and INNER_MODE are the modes describing TARGET. */
12126
12127 static void
12128 vector_init_bshuffle (rtx target, rtx elt, machine_mode mode,
12129 machine_mode inner_mode)
12130 {
12131 rtx t1, final_insn, sel;
12132 int bmask;
12133
12134 t1 = gen_reg_rtx (mode);
12135
12136 elt = convert_modes (SImode, inner_mode, elt, true);
12137 emit_move_insn (gen_lowpart(SImode, t1), elt);
12138
12139 switch (mode)
12140 {
12141 case V2SImode:
12142 final_insn = gen_bshufflev2si_vis (target, t1, t1);
12143 bmask = 0x45674567;
12144 break;
12145 case V4HImode:
12146 final_insn = gen_bshufflev4hi_vis (target, t1, t1);
12147 bmask = 0x67676767;
12148 break;
12149 case V8QImode:
12150 final_insn = gen_bshufflev8qi_vis (target, t1, t1);
12151 bmask = 0x77777777;
12152 break;
12153 default:
12154 gcc_unreachable ();
12155 }
12156
12157 sel = force_reg (SImode, GEN_INT (bmask));
12158 emit_insn (gen_bmasksi_vis (gen_rtx_REG (SImode, 0), sel, const0_rtx));
12159 emit_insn (final_insn);
12160 }
12161
12162 /* Subroutine of sparc_expand_vector_init. Emit code to initialize
12163 all fields of TARGET to ELT in V8QI by means of VIS FPMERGE insn. */
12164
12165 static void
12166 vector_init_fpmerge (rtx target, rtx elt)
12167 {
12168 rtx t1, t2, t2_low, t3, t3_low;
12169
12170 t1 = gen_reg_rtx (V4QImode);
12171 elt = convert_modes (SImode, QImode, elt, true);
12172 emit_move_insn (gen_lowpart (SImode, t1), elt);
12173
12174 t2 = gen_reg_rtx (V8QImode);
12175 t2_low = gen_lowpart (V4QImode, t2);
12176 emit_insn (gen_fpmerge_vis (t2, t1, t1));
12177
12178 t3 = gen_reg_rtx (V8QImode);
12179 t3_low = gen_lowpart (V4QImode, t3);
12180 emit_insn (gen_fpmerge_vis (t3, t2_low, t2_low));
12181
12182 emit_insn (gen_fpmerge_vis (target, t3_low, t3_low));
12183 }
12184
12185 /* Subroutine of sparc_expand_vector_init. Emit code to initialize
12186 all fields of TARGET to ELT in V4HI by means of VIS FALIGNDATA insn. */
12187
12188 static void
12189 vector_init_faligndata (rtx target, rtx elt)
12190 {
12191 rtx t1 = gen_reg_rtx (V4HImode);
12192 int i;
12193
12194 elt = convert_modes (SImode, HImode, elt, true);
12195 emit_move_insn (gen_lowpart (SImode, t1), elt);
12196
12197 emit_insn (gen_alignaddrsi_vis (gen_reg_rtx (SImode),
12198 force_reg (SImode, GEN_INT (6)),
12199 const0_rtx));
12200
12201 for (i = 0; i < 4; i++)
12202 emit_insn (gen_faligndatav4hi_vis (target, t1, target));
12203 }
12204
12205 /* Emit code to initialize TARGET to values for individual fields VALS. */
12206
12207 void
12208 sparc_expand_vector_init (rtx target, rtx vals)
12209 {
12210 const machine_mode mode = GET_MODE (target);
12211 const machine_mode inner_mode = GET_MODE_INNER (mode);
12212 const int n_elts = GET_MODE_NUNITS (mode);
12213 int i, n_var = 0;
12214 bool all_same;
12215 rtx mem;
12216
12217 all_same = true;
12218 for (i = 0; i < n_elts; i++)
12219 {
12220 rtx x = XVECEXP (vals, 0, i);
12221 if (!CONSTANT_P (x))
12222 n_var++;
12223
12224 if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
12225 all_same = false;
12226 }
12227
12228 if (n_var == 0)
12229 {
12230 emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
12231 return;
12232 }
12233
12234 if (GET_MODE_SIZE (inner_mode) == GET_MODE_SIZE (mode))
12235 {
12236 if (GET_MODE_SIZE (inner_mode) == 4)
12237 {
12238 emit_move_insn (gen_lowpart (SImode, target),
12239 gen_lowpart (SImode, XVECEXP (vals, 0, 0)));
12240 return;
12241 }
12242 else if (GET_MODE_SIZE (inner_mode) == 8)
12243 {
12244 emit_move_insn (gen_lowpart (DImode, target),
12245 gen_lowpart (DImode, XVECEXP (vals, 0, 0)));
12246 return;
12247 }
12248 }
12249 else if (GET_MODE_SIZE (inner_mode) == GET_MODE_SIZE (word_mode)
12250 && GET_MODE_SIZE (mode) == 2 * GET_MODE_SIZE (word_mode))
12251 {
12252 emit_move_insn (gen_highpart (word_mode, target),
12253 gen_lowpart (word_mode, XVECEXP (vals, 0, 0)));
12254 emit_move_insn (gen_lowpart (word_mode, target),
12255 gen_lowpart (word_mode, XVECEXP (vals, 0, 1)));
12256 return;
12257 }
12258
12259 if (all_same && GET_MODE_SIZE (mode) == 8)
12260 {
12261 if (TARGET_VIS2)
12262 {
12263 vector_init_bshuffle (target, XVECEXP (vals, 0, 0), mode, inner_mode);
12264 return;
12265 }
12266 if (mode == V8QImode)
12267 {
12268 vector_init_fpmerge (target, XVECEXP (vals, 0, 0));
12269 return;
12270 }
12271 if (mode == V4HImode)
12272 {
12273 vector_init_faligndata (target, XVECEXP (vals, 0, 0));
12274 return;
12275 }
12276 }
12277
12278 mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
12279 for (i = 0; i < n_elts; i++)
12280 emit_move_insn (adjust_address_nv (mem, inner_mode,
12281 i * GET_MODE_SIZE (inner_mode)),
12282 XVECEXP (vals, 0, i));
12283 emit_move_insn (target, mem);
12284 }
12285
12286 /* Implement TARGET_SECONDARY_RELOAD. */
12287
12288 static reg_class_t
12289 sparc_secondary_reload (bool in_p, rtx x, reg_class_t rclass_i,
12290 machine_mode mode, secondary_reload_info *sri)
12291 {
12292 enum reg_class rclass = (enum reg_class) rclass_i;
12293
12294 sri->icode = CODE_FOR_nothing;
12295 sri->extra_cost = 0;
12296
12297 /* We need a temporary when loading/storing a HImode/QImode value
12298 between memory and the FPU registers. This can happen when combine puts
12299 a paradoxical subreg in a float/fix conversion insn. */
12300 if (FP_REG_CLASS_P (rclass)
12301 && (mode == HImode || mode == QImode)
12302 && (GET_CODE (x) == MEM
12303 || ((GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
12304 && true_regnum (x) == -1)))
12305 return GENERAL_REGS;
12306
12307 /* On 32-bit we need a temporary when loading/storing a DFmode value
12308 between unaligned memory and the upper FPU registers. */
12309 if (TARGET_ARCH32
12310 && rclass == EXTRA_FP_REGS
12311 && mode == DFmode
12312 && GET_CODE (x) == MEM
12313 && ! mem_min_alignment (x, 8))
12314 return FP_REGS;
12315
12316 if (((TARGET_CM_MEDANY
12317 && symbolic_operand (x, mode))
12318 || (TARGET_CM_EMBMEDANY
12319 && text_segment_operand (x, mode)))
12320 && ! flag_pic)
12321 {
12322 if (in_p)
12323 sri->icode = direct_optab_handler (reload_in_optab, mode);
12324 else
12325 sri->icode = direct_optab_handler (reload_out_optab, mode);
12326 return NO_REGS;
12327 }
12328
12329 if (TARGET_VIS3 && TARGET_ARCH32)
12330 {
12331 int regno = true_regnum (x);
12332
12333 /* When using VIS3 fp<-->int register moves, on 32-bit we have
12334 to move 8-byte values in 4-byte pieces. This only works via
12335 FP_REGS, and not via EXTRA_FP_REGS. Therefore if we try to
12336 move between EXTRA_FP_REGS and GENERAL_REGS, we will need
12337 an FP_REGS intermediate move. */
12338 if ((rclass == EXTRA_FP_REGS && SPARC_INT_REG_P (regno))
12339 || ((general_or_i64_p (rclass)
12340 || rclass == GENERAL_OR_FP_REGS)
12341 && SPARC_FP_REG_P (regno)))
12342 {
12343 sri->extra_cost = 2;
12344 return FP_REGS;
12345 }
12346 }
12347
12348 return NO_REGS;
12349 }
12350
12351 /* Emit code to conditionally move either OPERANDS[2] or OPERANDS[3] into
12352 OPERANDS[0] in MODE. OPERANDS[1] is the operator of the condition. */
12353
12354 bool
12355 sparc_expand_conditional_move (machine_mode mode, rtx *operands)
12356 {
12357 enum rtx_code rc = GET_CODE (operands[1]);
12358 machine_mode cmp_mode;
12359 rtx cc_reg, dst, cmp;
12360
12361 cmp = operands[1];
12362 if (GET_MODE (XEXP (cmp, 0)) == DImode && !TARGET_ARCH64)
12363 return false;
12364
12365 if (GET_MODE (XEXP (cmp, 0)) == TFmode && !TARGET_HARD_QUAD)
12366 cmp = sparc_emit_float_lib_cmp (XEXP (cmp, 0), XEXP (cmp, 1), rc);
12367
12368 cmp_mode = GET_MODE (XEXP (cmp, 0));
12369 rc = GET_CODE (cmp);
12370
12371 dst = operands[0];
12372 if (! rtx_equal_p (operands[2], dst)
12373 && ! rtx_equal_p (operands[3], dst))
12374 {
12375 if (reg_overlap_mentioned_p (dst, cmp))
12376 dst = gen_reg_rtx (mode);
12377
12378 emit_move_insn (dst, operands[3]);
12379 }
12380 else if (operands[2] == dst)
12381 {
12382 operands[2] = operands[3];
12383
12384 if (GET_MODE_CLASS (cmp_mode) == MODE_FLOAT)
12385 rc = reverse_condition_maybe_unordered (rc);
12386 else
12387 rc = reverse_condition (rc);
12388 }
12389
12390 if (XEXP (cmp, 1) == const0_rtx
12391 && GET_CODE (XEXP (cmp, 0)) == REG
12392 && cmp_mode == DImode
12393 && v9_regcmp_p (rc))
12394 cc_reg = XEXP (cmp, 0);
12395 else
12396 cc_reg = gen_compare_reg_1 (rc, XEXP (cmp, 0), XEXP (cmp, 1));
12397
12398 cmp = gen_rtx_fmt_ee (rc, GET_MODE (cc_reg), cc_reg, const0_rtx);
12399
12400 emit_insn (gen_rtx_SET (dst,
12401 gen_rtx_IF_THEN_ELSE (mode, cmp, operands[2], dst)));
12402
12403 if (dst != operands[0])
12404 emit_move_insn (operands[0], dst);
12405
12406 return true;
12407 }
12408
12409 /* Emit code to conditionally move a combination of OPERANDS[1] and OPERANDS[2]
12410 into OPERANDS[0] in MODE, depending on the outcome of the comparison of
12411 OPERANDS[4] and OPERANDS[5]. OPERANDS[3] is the operator of the condition.
12412 FCODE is the machine code to be used for OPERANDS[3] and CCODE the machine
12413 code to be used for the condition mask. */
12414
12415 void
12416 sparc_expand_vcond (machine_mode mode, rtx *operands, int ccode, int fcode)
12417 {
12418 rtx mask, cop0, cop1, fcmp, cmask, bshuf, gsr;
12419 enum rtx_code code = GET_CODE (operands[3]);
12420
12421 mask = gen_reg_rtx (Pmode);
12422 cop0 = operands[4];
12423 cop1 = operands[5];
12424 if (code == LT || code == GE)
12425 {
12426 rtx t;
12427
12428 code = swap_condition (code);
12429 t = cop0; cop0 = cop1; cop1 = t;
12430 }
12431
12432 gsr = gen_rtx_REG (DImode, SPARC_GSR_REG);
12433
12434 fcmp = gen_rtx_UNSPEC (Pmode,
12435 gen_rtvec (1, gen_rtx_fmt_ee (code, mode, cop0, cop1)),
12436 fcode);
12437
12438 cmask = gen_rtx_UNSPEC (DImode,
12439 gen_rtvec (2, mask, gsr),
12440 ccode);
12441
12442 bshuf = gen_rtx_UNSPEC (mode,
12443 gen_rtvec (3, operands[1], operands[2], gsr),
12444 UNSPEC_BSHUFFLE);
12445
12446 emit_insn (gen_rtx_SET (mask, fcmp));
12447 emit_insn (gen_rtx_SET (gsr, cmask));
12448
12449 emit_insn (gen_rtx_SET (operands[0], bshuf));
12450 }
12451
12452 /* On sparc, any mode which naturally allocates into the float
12453 registers should return 4 here. */
12454
12455 unsigned int
12456 sparc_regmode_natural_size (machine_mode mode)
12457 {
12458 int size = UNITS_PER_WORD;
12459
12460 if (TARGET_ARCH64)
12461 {
12462 enum mode_class mclass = GET_MODE_CLASS (mode);
12463
12464 if (mclass == MODE_FLOAT || mclass == MODE_VECTOR_INT)
12465 size = 4;
12466 }
12467
12468 return size;
12469 }
12470
12471 /* Return TRUE if it is a good idea to tie two pseudo registers
12472 when one has mode MODE1 and one has mode MODE2.
12473 If HARD_REGNO_MODE_OK could produce different values for MODE1 and MODE2,
12474 for any hard reg, then this must be FALSE for correct output.
12475
12476 For V9 we have to deal with the fact that only the lower 32 floating
12477 point registers are 32-bit addressable. */
12478
12479 bool
12480 sparc_modes_tieable_p (machine_mode mode1, machine_mode mode2)
12481 {
12482 enum mode_class mclass1, mclass2;
12483 unsigned short size1, size2;
12484
12485 if (mode1 == mode2)
12486 return true;
12487
12488 mclass1 = GET_MODE_CLASS (mode1);
12489 mclass2 = GET_MODE_CLASS (mode2);
12490 if (mclass1 != mclass2)
12491 return false;
12492
12493 if (! TARGET_V9)
12494 return true;
12495
12496 /* Classes are the same and we are V9 so we have to deal with upper
12497 vs. lower floating point registers. If one of the modes is a
12498 4-byte mode, and the other is not, we have to mark them as not
12499 tieable because only the lower 32 floating point register are
12500 addressable 32-bits at a time.
12501
12502 We can't just test explicitly for SFmode, otherwise we won't
12503 cover the vector mode cases properly. */
12504
12505 if (mclass1 != MODE_FLOAT && mclass1 != MODE_VECTOR_INT)
12506 return true;
12507
12508 size1 = GET_MODE_SIZE (mode1);
12509 size2 = GET_MODE_SIZE (mode2);
12510 if ((size1 > 4 && size2 == 4)
12511 || (size2 > 4 && size1 == 4))
12512 return false;
12513
12514 return true;
12515 }
12516
12517 /* Implement TARGET_CSTORE_MODE. */
12518
12519 static machine_mode
12520 sparc_cstore_mode (enum insn_code icode ATTRIBUTE_UNUSED)
12521 {
12522 return (TARGET_ARCH64 ? DImode : SImode);
12523 }
12524
12525 /* Return the compound expression made of T1 and T2. */
12526
12527 static inline tree
12528 compound_expr (tree t1, tree t2)
12529 {
12530 return build2 (COMPOUND_EXPR, void_type_node, t1, t2);
12531 }
12532
12533 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV hook. */
12534
12535 static void
12536 sparc_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
12537 {
12538 if (!TARGET_FPU)
12539 return;
12540
12541 const unsigned HOST_WIDE_INT accrued_exception_mask = 0x1f << 5;
12542 const unsigned HOST_WIDE_INT trap_enable_mask = 0x1f << 23;
12543
12544 /* We generate the equivalent of feholdexcept (&fenv_var):
12545
12546 unsigned int fenv_var;
12547 __builtin_store_fsr (&fenv_var);
12548
12549 unsigned int tmp1_var;
12550 tmp1_var = fenv_var & ~(accrued_exception_mask | trap_enable_mask);
12551
12552 __builtin_load_fsr (&tmp1_var); */
12553
12554 tree fenv_var = create_tmp_var (unsigned_type_node);
12555 mark_addressable (fenv_var);
12556 tree fenv_addr = build_fold_addr_expr (fenv_var);
12557 tree stfsr = sparc_builtins[SPARC_BUILTIN_STFSR];
12558 tree hold_stfsr = build_call_expr (stfsr, 1, fenv_addr);
12559
12560 tree tmp1_var = create_tmp_var (unsigned_type_node);
12561 mark_addressable (tmp1_var);
12562 tree masked_fenv_var
12563 = build2 (BIT_AND_EXPR, unsigned_type_node, fenv_var,
12564 build_int_cst (unsigned_type_node,
12565 ~(accrued_exception_mask | trap_enable_mask)));
12566 tree hold_mask
12567 = build2 (MODIFY_EXPR, void_type_node, tmp1_var, masked_fenv_var);
12568
12569 tree tmp1_addr = build_fold_addr_expr (tmp1_var);
12570 tree ldfsr = sparc_builtins[SPARC_BUILTIN_LDFSR];
12571 tree hold_ldfsr = build_call_expr (ldfsr, 1, tmp1_addr);
12572
12573 *hold = compound_expr (compound_expr (hold_stfsr, hold_mask), hold_ldfsr);
12574
12575 /* We reload the value of tmp1_var to clear the exceptions:
12576
12577 __builtin_load_fsr (&tmp1_var); */
12578
12579 *clear = build_call_expr (ldfsr, 1, tmp1_addr);
12580
12581 /* We generate the equivalent of feupdateenv (&fenv_var):
12582
12583 unsigned int tmp2_var;
12584 __builtin_store_fsr (&tmp2_var);
12585
12586 __builtin_load_fsr (&fenv_var);
12587
12588 if (SPARC_LOW_FE_EXCEPT_VALUES)
12589 tmp2_var >>= 5;
12590 __atomic_feraiseexcept ((int) tmp2_var); */
12591
12592 tree tmp2_var = create_tmp_var (unsigned_type_node);
12593 mark_addressable (tmp2_var);
12594 tree tmp3_addr = build_fold_addr_expr (tmp2_var);
12595 tree update_stfsr = build_call_expr (stfsr, 1, tmp3_addr);
12596
12597 tree update_ldfsr = build_call_expr (ldfsr, 1, fenv_addr);
12598
12599 tree atomic_feraiseexcept
12600 = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
12601 tree update_call
12602 = build_call_expr (atomic_feraiseexcept, 1,
12603 fold_convert (integer_type_node, tmp2_var));
12604
12605 if (SPARC_LOW_FE_EXCEPT_VALUES)
12606 {
12607 tree shifted_tmp2_var
12608 = build2 (RSHIFT_EXPR, unsigned_type_node, tmp2_var,
12609 build_int_cst (unsigned_type_node, 5));
12610 tree update_shift
12611 = build2 (MODIFY_EXPR, void_type_node, tmp2_var, shifted_tmp2_var);
12612 update_call = compound_expr (update_shift, update_call);
12613 }
12614
12615 *update
12616 = compound_expr (compound_expr (update_stfsr, update_ldfsr), update_call);
12617 }
12618
12619 #include "gt-sparc.h"