* config.gcc (sparc*-*-solaris2*): Adjust.
[official-gcc.git] / gcc / config / sparc / sparc.c
blobc5638ccd2aae6123c49c63dddcde4c7b8917dd92
1 /* Subroutines for insn-output.c for SPARC.
2 Copyright (C) 1987-2016 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.
7 This file is part of GCC.
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.
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.
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/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "backend.h"
27 #include "target.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "memmodel.h"
31 #include "gimple.h"
32 #include "df.h"
33 #include "tm_p.h"
34 #include "stringpool.h"
35 #include "expmed.h"
36 #include "optabs.h"
37 #include "regs.h"
38 #include "emit-rtl.h"
39 #include "recog.h"
40 #include "diagnostic-core.h"
41 #include "alias.h"
42 #include "fold-const.h"
43 #include "stor-layout.h"
44 #include "calls.h"
45 #include "varasm.h"
46 #include "output.h"
47 #include "insn-attr.h"
48 #include "explow.h"
49 #include "expr.h"
50 #include "debug.h"
51 #include "common/common-target.h"
52 #include "gimplify.h"
53 #include "langhooks.h"
54 #include "reload.h"
55 #include "params.h"
56 #include "tree-pass.h"
57 #include "context.h"
58 #include "builtins.h"
60 /* This file should be included last. */
61 #include "target-def.h"
63 /* Processor costs */
65 struct processor_costs {
66 /* Integer load */
67 const int int_load;
69 /* Integer signed load */
70 const int int_sload;
72 /* Integer zeroed load */
73 const int int_zload;
75 /* Float load */
76 const int float_load;
78 /* fmov, fneg, fabs */
79 const int float_move;
81 /* fadd, fsub */
82 const int float_plusminus;
84 /* fcmp */
85 const int float_cmp;
87 /* fmov, fmovr */
88 const int float_cmove;
90 /* fmul */
91 const int float_mul;
93 /* fdivs */
94 const int float_div_sf;
96 /* fdivd */
97 const int float_div_df;
99 /* fsqrts */
100 const int float_sqrt_sf;
102 /* fsqrtd */
103 const int float_sqrt_df;
105 /* umul/smul */
106 const int int_mul;
108 /* mulX */
109 const int int_mulX;
111 /* integer multiply cost for each bit set past the most
112 significant 3, so the formula for multiply cost becomes:
114 if (rs1 < 0)
115 highest_bit = highest_clear_bit(rs1);
116 else
117 highest_bit = highest_set_bit(rs1);
118 if (highest_bit < 3)
119 highest_bit = 3;
120 cost = int_mul{,X} + ((highest_bit - 3) / int_mul_bit_factor);
122 A value of zero indicates that the multiply costs is fixed,
123 and not variable. */
124 const int int_mul_bit_factor;
126 /* udiv/sdiv */
127 const int int_div;
129 /* divX */
130 const int int_divX;
132 /* movcc, movr */
133 const int int_cmove;
135 /* penalty for shifts, due to scheduling rules etc. */
136 const int shift_penalty;
139 static const
140 struct processor_costs cypress_costs = {
141 COSTS_N_INSNS (2), /* int load */
142 COSTS_N_INSNS (2), /* int signed load */
143 COSTS_N_INSNS (2), /* int zeroed load */
144 COSTS_N_INSNS (2), /* float load */
145 COSTS_N_INSNS (5), /* fmov, fneg, fabs */
146 COSTS_N_INSNS (5), /* fadd, fsub */
147 COSTS_N_INSNS (1), /* fcmp */
148 COSTS_N_INSNS (1), /* fmov, fmovr */
149 COSTS_N_INSNS (7), /* fmul */
150 COSTS_N_INSNS (37), /* fdivs */
151 COSTS_N_INSNS (37), /* fdivd */
152 COSTS_N_INSNS (63), /* fsqrts */
153 COSTS_N_INSNS (63), /* fsqrtd */
154 COSTS_N_INSNS (1), /* imul */
155 COSTS_N_INSNS (1), /* imulX */
156 0, /* imul bit factor */
157 COSTS_N_INSNS (1), /* idiv */
158 COSTS_N_INSNS (1), /* idivX */
159 COSTS_N_INSNS (1), /* movcc/movr */
160 0, /* shift penalty */
163 static const
164 struct processor_costs supersparc_costs = {
165 COSTS_N_INSNS (1), /* int load */
166 COSTS_N_INSNS (1), /* int signed load */
167 COSTS_N_INSNS (1), /* int zeroed load */
168 COSTS_N_INSNS (0), /* float load */
169 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
170 COSTS_N_INSNS (3), /* fadd, fsub */
171 COSTS_N_INSNS (3), /* fcmp */
172 COSTS_N_INSNS (1), /* fmov, fmovr */
173 COSTS_N_INSNS (3), /* fmul */
174 COSTS_N_INSNS (6), /* fdivs */
175 COSTS_N_INSNS (9), /* fdivd */
176 COSTS_N_INSNS (12), /* fsqrts */
177 COSTS_N_INSNS (12), /* fsqrtd */
178 COSTS_N_INSNS (4), /* imul */
179 COSTS_N_INSNS (4), /* imulX */
180 0, /* imul bit factor */
181 COSTS_N_INSNS (4), /* idiv */
182 COSTS_N_INSNS (4), /* idivX */
183 COSTS_N_INSNS (1), /* movcc/movr */
184 1, /* shift penalty */
187 static const
188 struct processor_costs hypersparc_costs = {
189 COSTS_N_INSNS (1), /* int load */
190 COSTS_N_INSNS (1), /* int signed load */
191 COSTS_N_INSNS (1), /* int zeroed load */
192 COSTS_N_INSNS (1), /* float load */
193 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
194 COSTS_N_INSNS (1), /* fadd, fsub */
195 COSTS_N_INSNS (1), /* fcmp */
196 COSTS_N_INSNS (1), /* fmov, fmovr */
197 COSTS_N_INSNS (1), /* fmul */
198 COSTS_N_INSNS (8), /* fdivs */
199 COSTS_N_INSNS (12), /* fdivd */
200 COSTS_N_INSNS (17), /* fsqrts */
201 COSTS_N_INSNS (17), /* fsqrtd */
202 COSTS_N_INSNS (17), /* imul */
203 COSTS_N_INSNS (17), /* imulX */
204 0, /* imul bit factor */
205 COSTS_N_INSNS (17), /* idiv */
206 COSTS_N_INSNS (17), /* idivX */
207 COSTS_N_INSNS (1), /* movcc/movr */
208 0, /* shift penalty */
211 static const
212 struct processor_costs leon_costs = {
213 COSTS_N_INSNS (1), /* int load */
214 COSTS_N_INSNS (1), /* int signed load */
215 COSTS_N_INSNS (1), /* int zeroed load */
216 COSTS_N_INSNS (1), /* float load */
217 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
218 COSTS_N_INSNS (1), /* fadd, fsub */
219 COSTS_N_INSNS (1), /* fcmp */
220 COSTS_N_INSNS (1), /* fmov, fmovr */
221 COSTS_N_INSNS (1), /* fmul */
222 COSTS_N_INSNS (15), /* fdivs */
223 COSTS_N_INSNS (15), /* fdivd */
224 COSTS_N_INSNS (23), /* fsqrts */
225 COSTS_N_INSNS (23), /* fsqrtd */
226 COSTS_N_INSNS (5), /* imul */
227 COSTS_N_INSNS (5), /* imulX */
228 0, /* imul bit factor */
229 COSTS_N_INSNS (5), /* idiv */
230 COSTS_N_INSNS (5), /* idivX */
231 COSTS_N_INSNS (1), /* movcc/movr */
232 0, /* shift penalty */
235 static const
236 struct processor_costs leon3_costs = {
237 COSTS_N_INSNS (1), /* int load */
238 COSTS_N_INSNS (1), /* int signed load */
239 COSTS_N_INSNS (1), /* int zeroed load */
240 COSTS_N_INSNS (1), /* float load */
241 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
242 COSTS_N_INSNS (1), /* fadd, fsub */
243 COSTS_N_INSNS (1), /* fcmp */
244 COSTS_N_INSNS (1), /* fmov, fmovr */
245 COSTS_N_INSNS (1), /* fmul */
246 COSTS_N_INSNS (14), /* fdivs */
247 COSTS_N_INSNS (15), /* fdivd */
248 COSTS_N_INSNS (22), /* fsqrts */
249 COSTS_N_INSNS (23), /* fsqrtd */
250 COSTS_N_INSNS (5), /* imul */
251 COSTS_N_INSNS (5), /* imulX */
252 0, /* imul bit factor */
253 COSTS_N_INSNS (35), /* idiv */
254 COSTS_N_INSNS (35), /* idivX */
255 COSTS_N_INSNS (1), /* movcc/movr */
256 0, /* shift penalty */
259 static const
260 struct processor_costs sparclet_costs = {
261 COSTS_N_INSNS (3), /* int load */
262 COSTS_N_INSNS (3), /* int signed load */
263 COSTS_N_INSNS (1), /* int zeroed load */
264 COSTS_N_INSNS (1), /* float load */
265 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
266 COSTS_N_INSNS (1), /* fadd, fsub */
267 COSTS_N_INSNS (1), /* fcmp */
268 COSTS_N_INSNS (1), /* fmov, fmovr */
269 COSTS_N_INSNS (1), /* fmul */
270 COSTS_N_INSNS (1), /* fdivs */
271 COSTS_N_INSNS (1), /* fdivd */
272 COSTS_N_INSNS (1), /* fsqrts */
273 COSTS_N_INSNS (1), /* fsqrtd */
274 COSTS_N_INSNS (5), /* imul */
275 COSTS_N_INSNS (5), /* imulX */
276 0, /* imul bit factor */
277 COSTS_N_INSNS (5), /* idiv */
278 COSTS_N_INSNS (5), /* idivX */
279 COSTS_N_INSNS (1), /* movcc/movr */
280 0, /* shift penalty */
283 static const
284 struct processor_costs ultrasparc_costs = {
285 COSTS_N_INSNS (2), /* int load */
286 COSTS_N_INSNS (3), /* int signed load */
287 COSTS_N_INSNS (2), /* int zeroed load */
288 COSTS_N_INSNS (2), /* float load */
289 COSTS_N_INSNS (1), /* fmov, fneg, fabs */
290 COSTS_N_INSNS (4), /* fadd, fsub */
291 COSTS_N_INSNS (1), /* fcmp */
292 COSTS_N_INSNS (2), /* fmov, fmovr */
293 COSTS_N_INSNS (4), /* fmul */
294 COSTS_N_INSNS (13), /* fdivs */
295 COSTS_N_INSNS (23), /* fdivd */
296 COSTS_N_INSNS (13), /* fsqrts */
297 COSTS_N_INSNS (23), /* fsqrtd */
298 COSTS_N_INSNS (4), /* imul */
299 COSTS_N_INSNS (4), /* imulX */
300 2, /* imul bit factor */
301 COSTS_N_INSNS (37), /* idiv */
302 COSTS_N_INSNS (68), /* idivX */
303 COSTS_N_INSNS (2), /* movcc/movr */
304 2, /* shift penalty */
307 static const
308 struct processor_costs ultrasparc3_costs = {
309 COSTS_N_INSNS (2), /* int load */
310 COSTS_N_INSNS (3), /* int signed load */
311 COSTS_N_INSNS (3), /* int zeroed load */
312 COSTS_N_INSNS (2), /* float load */
313 COSTS_N_INSNS (3), /* fmov, fneg, fabs */
314 COSTS_N_INSNS (4), /* fadd, fsub */
315 COSTS_N_INSNS (5), /* fcmp */
316 COSTS_N_INSNS (3), /* fmov, fmovr */
317 COSTS_N_INSNS (4), /* fmul */
318 COSTS_N_INSNS (17), /* fdivs */
319 COSTS_N_INSNS (20), /* fdivd */
320 COSTS_N_INSNS (20), /* fsqrts */
321 COSTS_N_INSNS (29), /* fsqrtd */
322 COSTS_N_INSNS (6), /* imul */
323 COSTS_N_INSNS (6), /* imulX */
324 0, /* imul bit factor */
325 COSTS_N_INSNS (40), /* idiv */
326 COSTS_N_INSNS (71), /* idivX */
327 COSTS_N_INSNS (2), /* movcc/movr */
328 0, /* shift penalty */
331 static const
332 struct processor_costs niagara_costs = {
333 COSTS_N_INSNS (3), /* int load */
334 COSTS_N_INSNS (3), /* int signed load */
335 COSTS_N_INSNS (3), /* int zeroed load */
336 COSTS_N_INSNS (9), /* float load */
337 COSTS_N_INSNS (8), /* fmov, fneg, fabs */
338 COSTS_N_INSNS (8), /* fadd, fsub */
339 COSTS_N_INSNS (26), /* fcmp */
340 COSTS_N_INSNS (8), /* fmov, fmovr */
341 COSTS_N_INSNS (29), /* fmul */
342 COSTS_N_INSNS (54), /* fdivs */
343 COSTS_N_INSNS (83), /* fdivd */
344 COSTS_N_INSNS (100), /* fsqrts - not implemented in hardware */
345 COSTS_N_INSNS (100), /* fsqrtd - not implemented in hardware */
346 COSTS_N_INSNS (11), /* imul */
347 COSTS_N_INSNS (11), /* imulX */
348 0, /* imul bit factor */
349 COSTS_N_INSNS (72), /* idiv */
350 COSTS_N_INSNS (72), /* idivX */
351 COSTS_N_INSNS (1), /* movcc/movr */
352 0, /* shift penalty */
355 static const
356 struct processor_costs niagara2_costs = {
357 COSTS_N_INSNS (3), /* int load */
358 COSTS_N_INSNS (3), /* int signed load */
359 COSTS_N_INSNS (3), /* int zeroed load */
360 COSTS_N_INSNS (3), /* float load */
361 COSTS_N_INSNS (6), /* fmov, fneg, fabs */
362 COSTS_N_INSNS (6), /* fadd, fsub */
363 COSTS_N_INSNS (6), /* fcmp */
364 COSTS_N_INSNS (6), /* fmov, fmovr */
365 COSTS_N_INSNS (6), /* fmul */
366 COSTS_N_INSNS (19), /* fdivs */
367 COSTS_N_INSNS (33), /* fdivd */
368 COSTS_N_INSNS (19), /* fsqrts */
369 COSTS_N_INSNS (33), /* fsqrtd */
370 COSTS_N_INSNS (5), /* imul */
371 COSTS_N_INSNS (5), /* imulX */
372 0, /* imul bit factor */
373 COSTS_N_INSNS (26), /* idiv, average of 12 - 41 cycle range */
374 COSTS_N_INSNS (26), /* idivX, average of 12 - 41 cycle range */
375 COSTS_N_INSNS (1), /* movcc/movr */
376 0, /* shift penalty */
379 static const
380 struct processor_costs niagara3_costs = {
381 COSTS_N_INSNS (3), /* int load */
382 COSTS_N_INSNS (3), /* int signed load */
383 COSTS_N_INSNS (3), /* int zeroed load */
384 COSTS_N_INSNS (3), /* float load */
385 COSTS_N_INSNS (9), /* fmov, fneg, fabs */
386 COSTS_N_INSNS (9), /* fadd, fsub */
387 COSTS_N_INSNS (9), /* fcmp */
388 COSTS_N_INSNS (9), /* fmov, fmovr */
389 COSTS_N_INSNS (9), /* fmul */
390 COSTS_N_INSNS (23), /* fdivs */
391 COSTS_N_INSNS (37), /* fdivd */
392 COSTS_N_INSNS (23), /* fsqrts */
393 COSTS_N_INSNS (37), /* fsqrtd */
394 COSTS_N_INSNS (9), /* imul */
395 COSTS_N_INSNS (9), /* imulX */
396 0, /* imul bit factor */
397 COSTS_N_INSNS (31), /* idiv, average of 17 - 45 cycle range */
398 COSTS_N_INSNS (30), /* idivX, average of 16 - 44 cycle range */
399 COSTS_N_INSNS (1), /* movcc/movr */
400 0, /* shift penalty */
403 static const
404 struct processor_costs niagara4_costs = {
405 COSTS_N_INSNS (5), /* int load */
406 COSTS_N_INSNS (5), /* int signed load */
407 COSTS_N_INSNS (5), /* int zeroed load */
408 COSTS_N_INSNS (5), /* float load */
409 COSTS_N_INSNS (11), /* fmov, fneg, fabs */
410 COSTS_N_INSNS (11), /* fadd, fsub */
411 COSTS_N_INSNS (11), /* fcmp */
412 COSTS_N_INSNS (11), /* fmov, fmovr */
413 COSTS_N_INSNS (11), /* fmul */
414 COSTS_N_INSNS (24), /* fdivs */
415 COSTS_N_INSNS (37), /* fdivd */
416 COSTS_N_INSNS (24), /* fsqrts */
417 COSTS_N_INSNS (37), /* fsqrtd */
418 COSTS_N_INSNS (12), /* imul */
419 COSTS_N_INSNS (12), /* imulX */
420 0, /* imul bit factor */
421 COSTS_N_INSNS (50), /* idiv, average of 41 - 60 cycle range */
422 COSTS_N_INSNS (35), /* idivX, average of 26 - 44 cycle range */
423 COSTS_N_INSNS (1), /* movcc/movr */
424 0, /* shift penalty */
427 static const
428 struct processor_costs niagara7_costs = {
429 COSTS_N_INSNS (5), /* int load */
430 COSTS_N_INSNS (5), /* int signed load */
431 COSTS_N_INSNS (5), /* int zeroed load */
432 COSTS_N_INSNS (5), /* float load */
433 COSTS_N_INSNS (11), /* fmov, fneg, fabs */
434 COSTS_N_INSNS (11), /* fadd, fsub */
435 COSTS_N_INSNS (11), /* fcmp */
436 COSTS_N_INSNS (11), /* fmov, fmovr */
437 COSTS_N_INSNS (11), /* fmul */
438 COSTS_N_INSNS (24), /* fdivs */
439 COSTS_N_INSNS (37), /* fdivd */
440 COSTS_N_INSNS (24), /* fsqrts */
441 COSTS_N_INSNS (37), /* fsqrtd */
442 COSTS_N_INSNS (12), /* imul */
443 COSTS_N_INSNS (12), /* imulX */
444 0, /* imul bit factor */
445 COSTS_N_INSNS (51), /* idiv, average of 42 - 61 cycle range */
446 COSTS_N_INSNS (35), /* idivX, average of 26 - 44 cycle range */
447 COSTS_N_INSNS (1), /* movcc/movr */
448 0, /* shift penalty */
451 static const struct processor_costs *sparc_costs = &cypress_costs;
453 #ifdef HAVE_AS_RELAX_OPTION
454 /* If 'as' and 'ld' are relaxing tail call insns into branch always, use
455 "or %o7,%g0,X; call Y; or X,%g0,%o7" always, so that it can be optimized.
456 With sethi/jmp, neither 'as' nor 'ld' has an easy way how to find out if
457 somebody does not branch between the sethi and jmp. */
458 #define LEAF_SIBCALL_SLOT_RESERVED_P 1
459 #else
460 #define LEAF_SIBCALL_SLOT_RESERVED_P \
461 ((TARGET_ARCH64 && !TARGET_CM_MEDLOW) || flag_pic)
462 #endif
464 /* Vector to say how input registers are mapped to output registers.
465 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
466 eliminate it. You must use -fomit-frame-pointer to get that. */
467 char leaf_reg_remap[] =
468 { 0, 1, 2, 3, 4, 5, 6, 7,
469 -1, -1, -1, -1, -1, -1, 14, -1,
470 -1, -1, -1, -1, -1, -1, -1, -1,
471 8, 9, 10, 11, 12, 13, -1, 15,
473 32, 33, 34, 35, 36, 37, 38, 39,
474 40, 41, 42, 43, 44, 45, 46, 47,
475 48, 49, 50, 51, 52, 53, 54, 55,
476 56, 57, 58, 59, 60, 61, 62, 63,
477 64, 65, 66, 67, 68, 69, 70, 71,
478 72, 73, 74, 75, 76, 77, 78, 79,
479 80, 81, 82, 83, 84, 85, 86, 87,
480 88, 89, 90, 91, 92, 93, 94, 95,
481 96, 97, 98, 99, 100, 101, 102};
483 /* Vector, indexed by hard register number, which contains 1
484 for a register that is allowable in a candidate for leaf
485 function treatment. */
486 char sparc_leaf_regs[] =
487 { 1, 1, 1, 1, 1, 1, 1, 1,
488 0, 0, 0, 0, 0, 0, 1, 0,
489 0, 0, 0, 0, 0, 0, 0, 0,
490 1, 1, 1, 1, 1, 1, 0, 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, 1,
499 1, 1, 1, 1, 1, 1, 1};
501 struct GTY(()) machine_function
503 /* Size of the frame of the function. */
504 HOST_WIDE_INT frame_size;
506 /* Size of the frame of the function minus the register window save area
507 and the outgoing argument area. */
508 HOST_WIDE_INT apparent_frame_size;
510 /* Register we pretend the frame pointer is allocated to. Normally, this
511 is %fp, but if we are in a leaf procedure, this is (%sp + offset). We
512 record "offset" separately as it may be too big for (reg + disp). */
513 rtx frame_base_reg;
514 HOST_WIDE_INT frame_base_offset;
516 /* Number of global or FP registers to be saved (as 4-byte quantities). */
517 int n_global_fp_regs;
519 /* True if the current function is leaf and uses only leaf regs,
520 so that the SPARC leaf function optimization can be applied.
521 Private version of crtl->uses_only_leaf_regs, see
522 sparc_expand_prologue for the rationale. */
523 int leaf_function_p;
525 /* True if the prologue saves local or in registers. */
526 bool save_local_in_regs_p;
528 /* True if the data calculated by sparc_expand_prologue are valid. */
529 bool prologue_data_valid_p;
532 #define sparc_frame_size cfun->machine->frame_size
533 #define sparc_apparent_frame_size cfun->machine->apparent_frame_size
534 #define sparc_frame_base_reg cfun->machine->frame_base_reg
535 #define sparc_frame_base_offset cfun->machine->frame_base_offset
536 #define sparc_n_global_fp_regs cfun->machine->n_global_fp_regs
537 #define sparc_leaf_function_p cfun->machine->leaf_function_p
538 #define sparc_save_local_in_regs_p cfun->machine->save_local_in_regs_p
539 #define sparc_prologue_data_valid_p cfun->machine->prologue_data_valid_p
541 /* 1 if the next opcode is to be specially indented. */
542 int sparc_indent_opcode = 0;
544 static void sparc_option_override (void);
545 static void sparc_init_modes (void);
546 static int function_arg_slotno (const CUMULATIVE_ARGS *, machine_mode,
547 const_tree, bool, bool, int *, int *);
549 static int supersparc_adjust_cost (rtx_insn *, int, rtx_insn *, int);
550 static int hypersparc_adjust_cost (rtx_insn *, int, rtx_insn *, int);
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 *, int, rtx_insn *, int, unsigned 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);
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 *);
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, machine_mode, 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 *, machine_mode, 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 static bool sparc_fixed_condition_code_regs (unsigned int *, unsigned int *);
652 #ifdef SUBTARGET_ATTRIBUTE_TABLE
653 /* Table of valid machine attributes. */
654 static const struct attribute_spec sparc_attribute_table[] =
656 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
657 do_diagnostic } */
658 SUBTARGET_ATTRIBUTE_TABLE,
659 { NULL, 0, 0, false, false, false, NULL, false }
661 #endif
663 /* Option handling. */
665 /* Parsed value. */
666 enum cmodel sparc_cmodel;
668 char sparc_hard_reg_printed[8];
670 /* Initialize the GCC target structure. */
672 /* The default is to use .half rather than .short for aligned HI objects. */
673 #undef TARGET_ASM_ALIGNED_HI_OP
674 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
676 #undef TARGET_ASM_UNALIGNED_HI_OP
677 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
678 #undef TARGET_ASM_UNALIGNED_SI_OP
679 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
680 #undef TARGET_ASM_UNALIGNED_DI_OP
681 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
683 /* The target hook has to handle DI-mode values. */
684 #undef TARGET_ASM_INTEGER
685 #define TARGET_ASM_INTEGER sparc_assemble_integer
687 #undef TARGET_ASM_FUNCTION_PROLOGUE
688 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_asm_function_prologue
689 #undef TARGET_ASM_FUNCTION_EPILOGUE
690 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_asm_function_epilogue
692 #undef TARGET_SCHED_ADJUST_COST
693 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
694 #undef TARGET_SCHED_ISSUE_RATE
695 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
696 #undef TARGET_SCHED_INIT
697 #define TARGET_SCHED_INIT sparc_sched_init
698 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
699 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
701 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
702 #define TARGET_FUNCTION_OK_FOR_SIBCALL sparc_function_ok_for_sibcall
704 #undef TARGET_INIT_LIBFUNCS
705 #define TARGET_INIT_LIBFUNCS sparc_init_libfuncs
707 #undef TARGET_LEGITIMIZE_ADDRESS
708 #define TARGET_LEGITIMIZE_ADDRESS sparc_legitimize_address
709 #undef TARGET_DELEGITIMIZE_ADDRESS
710 #define TARGET_DELEGITIMIZE_ADDRESS sparc_delegitimize_address
711 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
712 #define TARGET_MODE_DEPENDENT_ADDRESS_P sparc_mode_dependent_address_p
714 #undef TARGET_INIT_BUILTINS
715 #define TARGET_INIT_BUILTINS sparc_init_builtins
716 #undef TARGET_BUILTIN_DECL
717 #define TARGET_BUILTIN_DECL sparc_builtin_decl
718 #undef TARGET_EXPAND_BUILTIN
719 #define TARGET_EXPAND_BUILTIN sparc_expand_builtin
720 #undef TARGET_FOLD_BUILTIN
721 #define TARGET_FOLD_BUILTIN sparc_fold_builtin
723 #if TARGET_TLS
724 #undef TARGET_HAVE_TLS
725 #define TARGET_HAVE_TLS true
726 #endif
728 #undef TARGET_CANNOT_FORCE_CONST_MEM
729 #define TARGET_CANNOT_FORCE_CONST_MEM sparc_cannot_force_const_mem
731 #undef TARGET_ASM_OUTPUT_MI_THUNK
732 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
733 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
734 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
736 #undef TARGET_RTX_COSTS
737 #define TARGET_RTX_COSTS sparc_rtx_costs
738 #undef TARGET_ADDRESS_COST
739 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
740 #undef TARGET_REGISTER_MOVE_COST
741 #define TARGET_REGISTER_MOVE_COST sparc_register_move_cost
743 #undef TARGET_PROMOTE_FUNCTION_MODE
744 #define TARGET_PROMOTE_FUNCTION_MODE sparc_promote_function_mode
746 #undef TARGET_FUNCTION_VALUE
747 #define TARGET_FUNCTION_VALUE sparc_function_value
748 #undef TARGET_LIBCALL_VALUE
749 #define TARGET_LIBCALL_VALUE sparc_libcall_value
750 #undef TARGET_FUNCTION_VALUE_REGNO_P
751 #define TARGET_FUNCTION_VALUE_REGNO_P sparc_function_value_regno_p
753 #undef TARGET_STRUCT_VALUE_RTX
754 #define TARGET_STRUCT_VALUE_RTX sparc_struct_value_rtx
755 #undef TARGET_RETURN_IN_MEMORY
756 #define TARGET_RETURN_IN_MEMORY sparc_return_in_memory
757 #undef TARGET_MUST_PASS_IN_STACK
758 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
759 #undef TARGET_PASS_BY_REFERENCE
760 #define TARGET_PASS_BY_REFERENCE sparc_pass_by_reference
761 #undef TARGET_ARG_PARTIAL_BYTES
762 #define TARGET_ARG_PARTIAL_BYTES sparc_arg_partial_bytes
763 #undef TARGET_FUNCTION_ARG_ADVANCE
764 #define TARGET_FUNCTION_ARG_ADVANCE sparc_function_arg_advance
765 #undef TARGET_FUNCTION_ARG
766 #define TARGET_FUNCTION_ARG sparc_function_arg
767 #undef TARGET_FUNCTION_INCOMING_ARG
768 #define TARGET_FUNCTION_INCOMING_ARG sparc_function_incoming_arg
769 #undef TARGET_FUNCTION_ARG_BOUNDARY
770 #define TARGET_FUNCTION_ARG_BOUNDARY sparc_function_arg_boundary
772 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
773 #define TARGET_EXPAND_BUILTIN_SAVEREGS sparc_builtin_saveregs
774 #undef TARGET_STRICT_ARGUMENT_NAMING
775 #define TARGET_STRICT_ARGUMENT_NAMING sparc_strict_argument_naming
777 #undef TARGET_EXPAND_BUILTIN_VA_START
778 #define TARGET_EXPAND_BUILTIN_VA_START sparc_va_start
779 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
780 #define TARGET_GIMPLIFY_VA_ARG_EXPR sparc_gimplify_va_arg
782 #undef TARGET_VECTOR_MODE_SUPPORTED_P
783 #define TARGET_VECTOR_MODE_SUPPORTED_P sparc_vector_mode_supported_p
785 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
786 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE sparc_preferred_simd_mode
788 #ifdef SUBTARGET_INSERT_ATTRIBUTES
789 #undef TARGET_INSERT_ATTRIBUTES
790 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
791 #endif
793 #ifdef SUBTARGET_ATTRIBUTE_TABLE
794 #undef TARGET_ATTRIBUTE_TABLE
795 #define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
796 #endif
798 #undef TARGET_OPTION_OVERRIDE
799 #define TARGET_OPTION_OVERRIDE sparc_option_override
801 #ifdef TARGET_THREAD_SSP_OFFSET
802 #undef TARGET_STACK_PROTECT_GUARD
803 #define TARGET_STACK_PROTECT_GUARD hook_tree_void_null
804 #endif
806 #if TARGET_GNU_TLS && defined(HAVE_AS_SPARC_UA_PCREL)
807 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
808 #define TARGET_ASM_OUTPUT_DWARF_DTPREL sparc_output_dwarf_dtprel
809 #endif
811 #undef TARGET_ASM_FILE_END
812 #define TARGET_ASM_FILE_END sparc_file_end
814 #undef TARGET_FRAME_POINTER_REQUIRED
815 #define TARGET_FRAME_POINTER_REQUIRED sparc_frame_pointer_required
817 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
818 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE sparc_builtin_setjmp_frame_value
820 #undef TARGET_CAN_ELIMINATE
821 #define TARGET_CAN_ELIMINATE sparc_can_eliminate
823 #undef TARGET_PREFERRED_RELOAD_CLASS
824 #define TARGET_PREFERRED_RELOAD_CLASS sparc_preferred_reload_class
826 #undef TARGET_SECONDARY_RELOAD
827 #define TARGET_SECONDARY_RELOAD sparc_secondary_reload
829 #undef TARGET_CONDITIONAL_REGISTER_USAGE
830 #define TARGET_CONDITIONAL_REGISTER_USAGE sparc_conditional_register_usage
832 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
833 #undef TARGET_MANGLE_TYPE
834 #define TARGET_MANGLE_TYPE sparc_mangle_type
835 #endif
837 #undef TARGET_LRA_P
838 #define TARGET_LRA_P hook_bool_void_false
840 #undef TARGET_LEGITIMATE_ADDRESS_P
841 #define TARGET_LEGITIMATE_ADDRESS_P sparc_legitimate_address_p
843 #undef TARGET_LEGITIMATE_CONSTANT_P
844 #define TARGET_LEGITIMATE_CONSTANT_P sparc_legitimate_constant_p
846 #undef TARGET_TRAMPOLINE_INIT
847 #define TARGET_TRAMPOLINE_INIT sparc_trampoline_init
849 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
850 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P sparc_print_operand_punct_valid_p
851 #undef TARGET_PRINT_OPERAND
852 #define TARGET_PRINT_OPERAND sparc_print_operand
853 #undef TARGET_PRINT_OPERAND_ADDRESS
854 #define TARGET_PRINT_OPERAND_ADDRESS sparc_print_operand_address
856 /* The value stored by LDSTUB. */
857 #undef TARGET_ATOMIC_TEST_AND_SET_TRUEVAL
858 #define TARGET_ATOMIC_TEST_AND_SET_TRUEVAL 0xff
860 #undef TARGET_CSTORE_MODE
861 #define TARGET_CSTORE_MODE sparc_cstore_mode
863 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
864 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV sparc_atomic_assign_expand_fenv
866 #undef TARGET_FIXED_CONDITION_CODE_REGS
867 #define TARGET_FIXED_CONDITION_CODE_REGS sparc_fixed_condition_code_regs
869 #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
870 #define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 1
872 struct gcc_target targetm = TARGET_INITIALIZER;
874 /* Return the memory reference contained in X if any, zero otherwise. */
876 static rtx
877 mem_ref (rtx x)
879 if (GET_CODE (x) == SIGN_EXTEND || GET_CODE (x) == ZERO_EXTEND)
880 x = XEXP (x, 0);
882 if (MEM_P (x))
883 return x;
885 return NULL_RTX;
888 /* We use a machine specific pass to enable workarounds for errata.
890 We need to have the (essentially) final form of the insn stream in order
891 to properly detect the various hazards. Therefore, this machine specific
892 pass runs as late as possible. */
894 static unsigned int
895 sparc_do_work_around_errata (void)
897 rtx_insn *insn, *next;
899 /* Force all instructions to be split into their final form. */
900 split_all_insns_noflow ();
902 /* Now look for specific patterns in the insn stream. */
903 for (insn = get_insns (); insn; insn = next)
905 bool insert_nop = false;
906 rtx set;
908 /* Look into the instruction in a delay slot. */
909 if (NONJUMP_INSN_P (insn))
910 if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
911 insn = seq->insn (1);
913 /* Look for a single-word load into an odd-numbered FP register. */
914 if (sparc_fix_at697f
915 && NONJUMP_INSN_P (insn)
916 && (set = single_set (insn)) != NULL_RTX
917 && GET_MODE_SIZE (GET_MODE (SET_SRC (set))) == 4
918 && MEM_P (SET_SRC (set))
919 && REG_P (SET_DEST (set))
920 && REGNO (SET_DEST (set)) > 31
921 && REGNO (SET_DEST (set)) % 2 != 0)
923 /* The wrong dependency is on the enclosing double register. */
924 const unsigned int x = REGNO (SET_DEST (set)) - 1;
925 unsigned int src1, src2, dest;
926 int code;
928 next = next_active_insn (insn);
929 if (!next)
930 break;
931 /* If the insn is a branch, then it cannot be problematic. */
932 if (!NONJUMP_INSN_P (next) || GET_CODE (PATTERN (next)) == SEQUENCE)
933 continue;
935 extract_insn (next);
936 code = INSN_CODE (next);
938 switch (code)
940 case CODE_FOR_adddf3:
941 case CODE_FOR_subdf3:
942 case CODE_FOR_muldf3:
943 case CODE_FOR_divdf3:
944 dest = REGNO (recog_data.operand[0]);
945 src1 = REGNO (recog_data.operand[1]);
946 src2 = REGNO (recog_data.operand[2]);
947 if (src1 != src2)
949 /* Case [1-4]:
950 ld [address], %fx+1
951 FPOPd %f{x,y}, %f{y,x}, %f{x,y} */
952 if ((src1 == x || src2 == x)
953 && (dest == src1 || dest == src2))
954 insert_nop = true;
956 else
958 /* Case 5:
959 ld [address], %fx+1
960 FPOPd %fx, %fx, %fx */
961 if (src1 == x
962 && dest == src1
963 && (code == CODE_FOR_adddf3 || code == CODE_FOR_muldf3))
964 insert_nop = true;
966 break;
968 case CODE_FOR_sqrtdf2:
969 dest = REGNO (recog_data.operand[0]);
970 src1 = REGNO (recog_data.operand[1]);
971 /* Case 6:
972 ld [address], %fx+1
973 fsqrtd %fx, %fx */
974 if (src1 == x && dest == src1)
975 insert_nop = true;
976 break;
978 default:
979 break;
983 /* Look for a single-word load into an integer register. */
984 else if (sparc_fix_ut699
985 && NONJUMP_INSN_P (insn)
986 && (set = single_set (insn)) != NULL_RTX
987 && GET_MODE_SIZE (GET_MODE (SET_SRC (set))) <= 4
988 && mem_ref (SET_SRC (set)) != NULL_RTX
989 && REG_P (SET_DEST (set))
990 && REGNO (SET_DEST (set)) < 32)
992 /* There is no problem if the second memory access has a data
993 dependency on the first single-cycle load. */
994 rtx x = SET_DEST (set);
996 next = next_active_insn (insn);
997 if (!next)
998 break;
999 /* If the insn is a branch, then it cannot be problematic. */
1000 if (!NONJUMP_INSN_P (next) || GET_CODE (PATTERN (next)) == SEQUENCE)
1001 continue;
1003 /* Look for a second memory access to/from an integer register. */
1004 if ((set = single_set (next)) != NULL_RTX)
1006 rtx src = SET_SRC (set);
1007 rtx dest = SET_DEST (set);
1008 rtx mem;
1010 /* LDD is affected. */
1011 if ((mem = mem_ref (src)) != NULL_RTX
1012 && REG_P (dest)
1013 && REGNO (dest) < 32
1014 && !reg_mentioned_p (x, XEXP (mem, 0)))
1015 insert_nop = true;
1017 /* STD is *not* affected. */
1018 else if (MEM_P (dest)
1019 && GET_MODE_SIZE (GET_MODE (dest)) <= 4
1020 && (src == CONST0_RTX (GET_MODE (dest))
1021 || (REG_P (src)
1022 && REGNO (src) < 32
1023 && REGNO (src) != REGNO (x)))
1024 && !reg_mentioned_p (x, XEXP (dest, 0)))
1025 insert_nop = true;
1029 /* Look for a single-word load/operation into an FP register. */
1030 else if (sparc_fix_ut699
1031 && NONJUMP_INSN_P (insn)
1032 && (set = single_set (insn)) != NULL_RTX
1033 && GET_MODE_SIZE (GET_MODE (SET_SRC (set))) == 4
1034 && REG_P (SET_DEST (set))
1035 && REGNO (SET_DEST (set)) > 31)
1037 /* Number of instructions in the problematic window. */
1038 const int n_insns = 4;
1039 /* The problematic combination is with the sibling FP register. */
1040 const unsigned int x = REGNO (SET_DEST (set));
1041 const unsigned int y = x ^ 1;
1042 rtx_insn *after;
1043 int i;
1045 next = next_active_insn (insn);
1046 if (!next)
1047 break;
1048 /* If the insn is a branch, then it cannot be problematic. */
1049 if (!NONJUMP_INSN_P (next) || GET_CODE (PATTERN (next)) == SEQUENCE)
1050 continue;
1052 /* Look for a second load/operation into the sibling FP register. */
1053 if (!((set = single_set (next)) != NULL_RTX
1054 && GET_MODE_SIZE (GET_MODE (SET_SRC (set))) == 4
1055 && REG_P (SET_DEST (set))
1056 && REGNO (SET_DEST (set)) == y))
1057 continue;
1059 /* Look for a (possible) store from the FP register in the next N
1060 instructions, but bail out if it is again modified or if there
1061 is a store from the sibling FP register before this store. */
1062 for (after = next, i = 0; i < n_insns; i++)
1064 bool branch_p;
1066 after = next_active_insn (after);
1067 if (!after)
1068 break;
1070 /* This is a branch with an empty delay slot. */
1071 if (!NONJUMP_INSN_P (after))
1073 if (++i == n_insns)
1074 break;
1075 branch_p = true;
1076 after = NULL;
1078 /* This is a branch with a filled delay slot. */
1079 else if (rtx_sequence *seq =
1080 dyn_cast <rtx_sequence *> (PATTERN (after)))
1082 if (++i == n_insns)
1083 break;
1084 branch_p = true;
1085 after = seq->insn (1);
1087 /* This is a regular instruction. */
1088 else
1089 branch_p = false;
1091 if (after && (set = single_set (after)) != NULL_RTX)
1093 const rtx src = SET_SRC (set);
1094 const rtx dest = SET_DEST (set);
1095 const unsigned int size = GET_MODE_SIZE (GET_MODE (dest));
1097 /* If the FP register is again modified before the store,
1098 then the store isn't affected. */
1099 if (REG_P (dest)
1100 && (REGNO (dest) == x
1101 || (REGNO (dest) == y && size == 8)))
1102 break;
1104 if (MEM_P (dest) && REG_P (src))
1106 /* If there is a store from the sibling FP register
1107 before the store, then the store is not affected. */
1108 if (REGNO (src) == y || (REGNO (src) == x && size == 8))
1109 break;
1111 /* Otherwise, the store is affected. */
1112 if (REGNO (src) == x && size == 4)
1114 insert_nop = true;
1115 break;
1120 /* If we have a branch in the first M instructions, then we
1121 cannot see the (M+2)th instruction so we play safe. */
1122 if (branch_p && i <= (n_insns - 2))
1124 insert_nop = true;
1125 break;
1130 else
1131 next = NEXT_INSN (insn);
1133 if (insert_nop)
1134 emit_insn_before (gen_nop (), next);
1137 return 0;
1140 namespace {
1142 const pass_data pass_data_work_around_errata =
1144 RTL_PASS, /* type */
1145 "errata", /* name */
1146 OPTGROUP_NONE, /* optinfo_flags */
1147 TV_MACH_DEP, /* tv_id */
1148 0, /* properties_required */
1149 0, /* properties_provided */
1150 0, /* properties_destroyed */
1151 0, /* todo_flags_start */
1152 0, /* todo_flags_finish */
1155 class pass_work_around_errata : public rtl_opt_pass
1157 public:
1158 pass_work_around_errata(gcc::context *ctxt)
1159 : rtl_opt_pass(pass_data_work_around_errata, ctxt)
1162 /* opt_pass methods: */
1163 virtual bool gate (function *)
1165 /* The only errata we handle are those of the AT697F and UT699. */
1166 return sparc_fix_at697f != 0 || sparc_fix_ut699 != 0;
1169 virtual unsigned int execute (function *)
1171 return sparc_do_work_around_errata ();
1174 }; // class pass_work_around_errata
1176 } // anon namespace
1178 rtl_opt_pass *
1179 make_pass_work_around_errata (gcc::context *ctxt)
1181 return new pass_work_around_errata (ctxt);
1184 /* Helpers for TARGET_DEBUG_OPTIONS. */
1185 static void
1186 dump_target_flag_bits (const int flags)
1188 if (flags & MASK_64BIT)
1189 fprintf (stderr, "64BIT ");
1190 if (flags & MASK_APP_REGS)
1191 fprintf (stderr, "APP_REGS ");
1192 if (flags & MASK_FASTER_STRUCTS)
1193 fprintf (stderr, "FASTER_STRUCTS ");
1194 if (flags & MASK_FLAT)
1195 fprintf (stderr, "FLAT ");
1196 if (flags & MASK_FMAF)
1197 fprintf (stderr, "FMAF ");
1198 if (flags & MASK_FPU)
1199 fprintf (stderr, "FPU ");
1200 if (flags & MASK_HARD_QUAD)
1201 fprintf (stderr, "HARD_QUAD ");
1202 if (flags & MASK_POPC)
1203 fprintf (stderr, "POPC ");
1204 if (flags & MASK_PTR64)
1205 fprintf (stderr, "PTR64 ");
1206 if (flags & MASK_STACK_BIAS)
1207 fprintf (stderr, "STACK_BIAS ");
1208 if (flags & MASK_UNALIGNED_DOUBLES)
1209 fprintf (stderr, "UNALIGNED_DOUBLES ");
1210 if (flags & MASK_V8PLUS)
1211 fprintf (stderr, "V8PLUS ");
1212 if (flags & MASK_VIS)
1213 fprintf (stderr, "VIS ");
1214 if (flags & MASK_VIS2)
1215 fprintf (stderr, "VIS2 ");
1216 if (flags & MASK_VIS3)
1217 fprintf (stderr, "VIS3 ");
1218 if (flags & MASK_VIS4)
1219 fprintf (stderr, "VIS4 ");
1220 if (flags & MASK_CBCOND)
1221 fprintf (stderr, "CBCOND ");
1222 if (flags & MASK_DEPRECATED_V8_INSNS)
1223 fprintf (stderr, "DEPRECATED_V8_INSNS ");
1224 if (flags & MASK_SPARCLET)
1225 fprintf (stderr, "SPARCLET ");
1226 if (flags & MASK_SPARCLITE)
1227 fprintf (stderr, "SPARCLITE ");
1228 if (flags & MASK_V8)
1229 fprintf (stderr, "V8 ");
1230 if (flags & MASK_V9)
1231 fprintf (stderr, "V9 ");
1234 static void
1235 dump_target_flags (const char *prefix, const int flags)
1237 fprintf (stderr, "%s: (%08x) [ ", prefix, flags);
1238 dump_target_flag_bits (flags);
1239 fprintf(stderr, "]\n");
1242 /* Validate and override various options, and do some machine dependent
1243 initialization. */
1245 static void
1246 sparc_option_override (void)
1248 static struct code_model {
1249 const char *const name;
1250 const enum cmodel value;
1251 } const cmodels[] = {
1252 { "32", CM_32 },
1253 { "medlow", CM_MEDLOW },
1254 { "medmid", CM_MEDMID },
1255 { "medany", CM_MEDANY },
1256 { "embmedany", CM_EMBMEDANY },
1257 { NULL, (enum cmodel) 0 }
1259 const struct code_model *cmodel;
1260 /* Map TARGET_CPU_DEFAULT to value for -m{cpu,tune}=. */
1261 static struct cpu_default {
1262 const int cpu;
1263 const enum processor_type processor;
1264 } const cpu_default[] = {
1265 /* There must be one entry here for each TARGET_CPU value. */
1266 { TARGET_CPU_sparc, PROCESSOR_CYPRESS },
1267 { TARGET_CPU_v8, PROCESSOR_V8 },
1268 { TARGET_CPU_supersparc, PROCESSOR_SUPERSPARC },
1269 { TARGET_CPU_hypersparc, PROCESSOR_HYPERSPARC },
1270 { TARGET_CPU_leon, PROCESSOR_LEON },
1271 { TARGET_CPU_leon3, PROCESSOR_LEON3 },
1272 { TARGET_CPU_leon3v7, PROCESSOR_LEON3V7 },
1273 { TARGET_CPU_sparclite, PROCESSOR_F930 },
1274 { TARGET_CPU_sparclite86x, PROCESSOR_SPARCLITE86X },
1275 { TARGET_CPU_sparclet, PROCESSOR_TSC701 },
1276 { TARGET_CPU_v9, PROCESSOR_V9 },
1277 { TARGET_CPU_ultrasparc, PROCESSOR_ULTRASPARC },
1278 { TARGET_CPU_ultrasparc3, PROCESSOR_ULTRASPARC3 },
1279 { TARGET_CPU_niagara, PROCESSOR_NIAGARA },
1280 { TARGET_CPU_niagara2, PROCESSOR_NIAGARA2 },
1281 { TARGET_CPU_niagara3, PROCESSOR_NIAGARA3 },
1282 { TARGET_CPU_niagara4, PROCESSOR_NIAGARA4 },
1283 { TARGET_CPU_niagara7, PROCESSOR_NIAGARA7 },
1284 { -1, PROCESSOR_V7 }
1286 const struct cpu_default *def;
1287 /* Table of values for -m{cpu,tune}=. This must match the order of
1288 the enum processor_type in sparc-opts.h. */
1289 static struct cpu_table {
1290 const char *const name;
1291 const int disable;
1292 const int enable;
1293 } const cpu_table[] = {
1294 { "v7", MASK_ISA, 0 },
1295 { "cypress", MASK_ISA, 0 },
1296 { "v8", MASK_ISA, MASK_V8 },
1297 /* TI TMS390Z55 supersparc */
1298 { "supersparc", MASK_ISA, MASK_V8 },
1299 { "hypersparc", MASK_ISA, MASK_V8|MASK_FPU },
1300 { "leon", MASK_ISA, MASK_V8|MASK_LEON|MASK_FPU },
1301 { "leon3", MASK_ISA, MASK_V8|MASK_LEON3|MASK_FPU },
1302 { "leon3v7", MASK_ISA, MASK_LEON3|MASK_FPU },
1303 { "sparclite", MASK_ISA, MASK_SPARCLITE },
1304 /* The Fujitsu MB86930 is the original sparclite chip, with no FPU. */
1305 { "f930", MASK_ISA|MASK_FPU, MASK_SPARCLITE },
1306 /* The Fujitsu MB86934 is the recent sparclite chip, with an FPU. */
1307 { "f934", MASK_ISA, MASK_SPARCLITE|MASK_FPU },
1308 { "sparclite86x", MASK_ISA|MASK_FPU, MASK_SPARCLITE },
1309 { "sparclet", MASK_ISA, MASK_SPARCLET },
1310 /* TEMIC sparclet */
1311 { "tsc701", MASK_ISA, MASK_SPARCLET },
1312 { "v9", MASK_ISA, MASK_V9 },
1313 /* UltraSPARC I, II, IIi */
1314 { "ultrasparc", MASK_ISA,
1315 /* Although insns using %y are deprecated, it is a clear win. */
1316 MASK_V9|MASK_DEPRECATED_V8_INSNS },
1317 /* UltraSPARC III */
1318 /* ??? Check if %y issue still holds true. */
1319 { "ultrasparc3", MASK_ISA,
1320 MASK_V9|MASK_DEPRECATED_V8_INSNS|MASK_VIS2 },
1321 /* UltraSPARC T1 */
1322 { "niagara", MASK_ISA,
1323 MASK_V9|MASK_DEPRECATED_V8_INSNS },
1324 /* UltraSPARC T2 */
1325 { "niagara2", MASK_ISA,
1326 MASK_V9|MASK_POPC|MASK_VIS2 },
1327 /* UltraSPARC T3 */
1328 { "niagara3", MASK_ISA,
1329 MASK_V9|MASK_POPC|MASK_VIS3|MASK_FMAF },
1330 /* UltraSPARC T4 */
1331 { "niagara4", MASK_ISA,
1332 MASK_V9|MASK_POPC|MASK_VIS3|MASK_FMAF|MASK_CBCOND },
1333 /* UltraSPARC M7 */
1334 { "niagara7", MASK_ISA,
1335 MASK_V9|MASK_POPC|MASK_VIS4|MASK_FMAF|MASK_CBCOND|MASK_SUBXC }
1337 const struct cpu_table *cpu;
1338 unsigned int i;
1339 int fpu;
1341 if (sparc_debug_string != NULL)
1343 const char *q;
1344 char *p;
1346 p = ASTRDUP (sparc_debug_string);
1347 while ((q = strtok (p, ",")) != NULL)
1349 bool invert;
1350 int mask;
1352 p = NULL;
1353 if (*q == '!')
1355 invert = true;
1356 q++;
1358 else
1359 invert = false;
1361 if (! strcmp (q, "all"))
1362 mask = MASK_DEBUG_ALL;
1363 else if (! strcmp (q, "options"))
1364 mask = MASK_DEBUG_OPTIONS;
1365 else
1366 error ("unknown -mdebug-%s switch", q);
1368 if (invert)
1369 sparc_debug &= ~mask;
1370 else
1371 sparc_debug |= mask;
1375 if (TARGET_DEBUG_OPTIONS)
1377 dump_target_flags("Initial target_flags", target_flags);
1378 dump_target_flags("target_flags_explicit", target_flags_explicit);
1381 #ifdef SUBTARGET_OVERRIDE_OPTIONS
1382 SUBTARGET_OVERRIDE_OPTIONS;
1383 #endif
1385 #ifndef SPARC_BI_ARCH
1386 /* Check for unsupported architecture size. */
1387 if (!TARGET_64BIT != DEFAULT_ARCH32_P)
1388 error ("%s is not supported by this configuration",
1389 DEFAULT_ARCH32_P ? "-m64" : "-m32");
1390 #endif
1392 /* We force all 64bit archs to use 128 bit long double */
1393 if (TARGET_ARCH64 && !TARGET_LONG_DOUBLE_128)
1395 error ("-mlong-double-64 not allowed with -m64");
1396 target_flags |= MASK_LONG_DOUBLE_128;
1399 /* Code model selection. */
1400 sparc_cmodel = SPARC_DEFAULT_CMODEL;
1402 #ifdef SPARC_BI_ARCH
1403 if (TARGET_ARCH32)
1404 sparc_cmodel = CM_32;
1405 #endif
1407 if (sparc_cmodel_string != NULL)
1409 if (TARGET_ARCH64)
1411 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
1412 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
1413 break;
1414 if (cmodel->name == NULL)
1415 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
1416 else
1417 sparc_cmodel = cmodel->value;
1419 else
1420 error ("-mcmodel= is not supported on 32 bit systems");
1423 /* Check that -fcall-saved-REG wasn't specified for out registers. */
1424 for (i = 8; i < 16; i++)
1425 if (!call_used_regs [i])
1427 error ("-fcall-saved-REG is not supported for out registers");
1428 call_used_regs [i] = 1;
1431 fpu = target_flags & MASK_FPU; /* save current -mfpu status */
1433 /* Set the default CPU. */
1434 if (!global_options_set.x_sparc_cpu_and_features)
1436 for (def = &cpu_default[0]; def->cpu != -1; ++def)
1437 if (def->cpu == TARGET_CPU_DEFAULT)
1438 break;
1439 gcc_assert (def->cpu != -1);
1440 sparc_cpu_and_features = def->processor;
1443 if (!global_options_set.x_sparc_cpu)
1444 sparc_cpu = sparc_cpu_and_features;
1446 cpu = &cpu_table[(int) sparc_cpu_and_features];
1448 if (TARGET_DEBUG_OPTIONS)
1450 fprintf (stderr, "sparc_cpu_and_features: %s\n", cpu->name);
1451 fprintf (stderr, "sparc_cpu: %s\n",
1452 cpu_table[(int) sparc_cpu].name);
1453 dump_target_flags ("cpu->disable", cpu->disable);
1454 dump_target_flags ("cpu->enable", cpu->enable);
1457 target_flags &= ~cpu->disable;
1458 target_flags |= (cpu->enable
1459 #ifndef HAVE_AS_FMAF_HPC_VIS3
1460 & ~(MASK_FMAF | MASK_VIS3)
1461 #endif
1462 #ifndef HAVE_AS_SPARC4
1463 & ~MASK_CBCOND
1464 #endif
1465 #ifndef HAVE_AS_SPARC5_VIS4
1466 & ~(MASK_VIS4 | MASK_SUBXC)
1467 #endif
1468 #ifndef HAVE_AS_LEON
1469 & ~(MASK_LEON | MASK_LEON3)
1470 #endif
1473 /* If -mfpu or -mno-fpu was explicitly used, don't override with
1474 the processor default. */
1475 if (target_flags_explicit & MASK_FPU)
1476 target_flags = (target_flags & ~MASK_FPU) | fpu;
1478 /* -mvis2 implies -mvis */
1479 if (TARGET_VIS2)
1480 target_flags |= MASK_VIS;
1482 /* -mvis3 implies -mvis2 and -mvis */
1483 if (TARGET_VIS3)
1484 target_flags |= MASK_VIS2 | MASK_VIS;
1486 /* -mvis4 implies -mvis3, -mvis2 and -mvis */
1487 if (TARGET_VIS4)
1488 target_flags |= MASK_VIS3 | MASK_VIS2 | MASK_VIS;
1490 /* Don't allow -mvis, -mvis2, -mvis3, -mvis4 or -mfmaf if FPU is
1491 disabled. */
1492 if (! TARGET_FPU)
1493 target_flags &= ~(MASK_VIS | MASK_VIS2 | MASK_VIS3 | MASK_VIS4
1494 | MASK_FMAF);
1496 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
1497 are available.
1498 -m64 also implies v9. */
1499 if (TARGET_VIS || TARGET_ARCH64)
1501 target_flags |= MASK_V9;
1502 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
1505 /* -mvis also implies -mv8plus on 32-bit */
1506 if (TARGET_VIS && ! TARGET_ARCH64)
1507 target_flags |= MASK_V8PLUS;
1509 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
1510 if (TARGET_V9 && TARGET_ARCH32)
1511 target_flags |= MASK_DEPRECATED_V8_INSNS;
1513 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
1514 if (! TARGET_V9 || TARGET_ARCH64)
1515 target_flags &= ~MASK_V8PLUS;
1517 /* Don't use stack biasing in 32 bit mode. */
1518 if (TARGET_ARCH32)
1519 target_flags &= ~MASK_STACK_BIAS;
1521 /* Supply a default value for align_functions. */
1522 if (align_functions == 0
1523 && (sparc_cpu == PROCESSOR_ULTRASPARC
1524 || sparc_cpu == PROCESSOR_ULTRASPARC3
1525 || sparc_cpu == PROCESSOR_NIAGARA
1526 || sparc_cpu == PROCESSOR_NIAGARA2
1527 || sparc_cpu == PROCESSOR_NIAGARA3
1528 || sparc_cpu == PROCESSOR_NIAGARA4
1529 || sparc_cpu == PROCESSOR_NIAGARA7))
1530 align_functions = 32;
1532 /* Validate PCC_STRUCT_RETURN. */
1533 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
1534 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
1536 /* Only use .uaxword when compiling for a 64-bit target. */
1537 if (!TARGET_ARCH64)
1538 targetm.asm_out.unaligned_op.di = NULL;
1540 /* Do various machine dependent initializations. */
1541 sparc_init_modes ();
1543 /* Set up function hooks. */
1544 init_machine_status = sparc_init_machine_status;
1546 switch (sparc_cpu)
1548 case PROCESSOR_V7:
1549 case PROCESSOR_CYPRESS:
1550 sparc_costs = &cypress_costs;
1551 break;
1552 case PROCESSOR_V8:
1553 case PROCESSOR_SPARCLITE:
1554 case PROCESSOR_SUPERSPARC:
1555 sparc_costs = &supersparc_costs;
1556 break;
1557 case PROCESSOR_F930:
1558 case PROCESSOR_F934:
1559 case PROCESSOR_HYPERSPARC:
1560 case PROCESSOR_SPARCLITE86X:
1561 sparc_costs = &hypersparc_costs;
1562 break;
1563 case PROCESSOR_LEON:
1564 sparc_costs = &leon_costs;
1565 break;
1566 case PROCESSOR_LEON3:
1567 case PROCESSOR_LEON3V7:
1568 sparc_costs = &leon3_costs;
1569 break;
1570 case PROCESSOR_SPARCLET:
1571 case PROCESSOR_TSC701:
1572 sparc_costs = &sparclet_costs;
1573 break;
1574 case PROCESSOR_V9:
1575 case PROCESSOR_ULTRASPARC:
1576 sparc_costs = &ultrasparc_costs;
1577 break;
1578 case PROCESSOR_ULTRASPARC3:
1579 sparc_costs = &ultrasparc3_costs;
1580 break;
1581 case PROCESSOR_NIAGARA:
1582 sparc_costs = &niagara_costs;
1583 break;
1584 case PROCESSOR_NIAGARA2:
1585 sparc_costs = &niagara2_costs;
1586 break;
1587 case PROCESSOR_NIAGARA3:
1588 sparc_costs = &niagara3_costs;
1589 break;
1590 case PROCESSOR_NIAGARA4:
1591 sparc_costs = &niagara4_costs;
1592 break;
1593 case PROCESSOR_NIAGARA7:
1594 sparc_costs = &niagara7_costs;
1595 break;
1596 case PROCESSOR_NATIVE:
1597 gcc_unreachable ();
1600 if (sparc_memory_model == SMM_DEFAULT)
1602 /* Choose the memory model for the operating system. */
1603 enum sparc_memory_model_type os_default = SUBTARGET_DEFAULT_MEMORY_MODEL;
1604 if (os_default != SMM_DEFAULT)
1605 sparc_memory_model = os_default;
1606 /* Choose the most relaxed model for the processor. */
1607 else if (TARGET_V9)
1608 sparc_memory_model = SMM_RMO;
1609 else if (TARGET_LEON3)
1610 sparc_memory_model = SMM_TSO;
1611 else if (TARGET_LEON)
1612 sparc_memory_model = SMM_SC;
1613 else if (TARGET_V8)
1614 sparc_memory_model = SMM_PSO;
1615 else
1616 sparc_memory_model = SMM_SC;
1619 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
1620 if (!(target_flags_explicit & MASK_LONG_DOUBLE_128))
1621 target_flags |= MASK_LONG_DOUBLE_128;
1622 #endif
1624 if (TARGET_DEBUG_OPTIONS)
1625 dump_target_flags ("Final target_flags", target_flags);
1627 /* PARAM_SIMULTANEOUS_PREFETCHES is the number of prefetches that
1628 can run at the same time. More important, it is the threshold
1629 defining when additional prefetches will be dropped by the
1630 hardware.
1632 The UltraSPARC-III features a documented prefetch queue with a
1633 size of 8. Additional prefetches issued in the cpu are
1634 dropped.
1636 Niagara processors are different. In these processors prefetches
1637 are handled much like regular loads. The L1 miss buffer is 32
1638 entries, but prefetches start getting affected when 30 entries
1639 become occupied. That occupation could be a mix of regular loads
1640 and prefetches though. And that buffer is shared by all threads.
1641 Once the threshold is reached, if the core is running a single
1642 thread the prefetch will retry. If more than one thread is
1643 running, the prefetch will be dropped.
1645 All this makes it very difficult to determine how many
1646 simultaneous prefetches can be issued simultaneously, even in a
1647 single-threaded program. Experimental results show that setting
1648 this parameter to 32 works well when the number of threads is not
1649 high. */
1650 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
1651 ((sparc_cpu == PROCESSOR_ULTRASPARC
1652 || sparc_cpu == PROCESSOR_NIAGARA
1653 || sparc_cpu == PROCESSOR_NIAGARA2
1654 || sparc_cpu == PROCESSOR_NIAGARA3
1655 || sparc_cpu == PROCESSOR_NIAGARA4)
1657 : (sparc_cpu == PROCESSOR_ULTRASPARC3
1658 ? 8 : (sparc_cpu == PROCESSOR_NIAGARA7
1659 ? 32 : 3))),
1660 global_options.x_param_values,
1661 global_options_set.x_param_values);
1663 /* For PARAM_L1_CACHE_LINE_SIZE we use the default 32 bytes (see
1664 params.def), so no maybe_set_param_value is needed.
1666 The Oracle SPARC Architecture (previously the UltraSPARC
1667 Architecture) specification states that when a PREFETCH[A]
1668 instruction is executed an implementation-specific amount of data
1669 is prefetched, and that it is at least 64 bytes long (aligned to
1670 at least 64 bytes).
1672 However, this is not correct. The M7 (and implementations prior
1673 to that) does not guarantee a 64B prefetch into a cache if the
1674 line size is smaller. A single cache line is all that is ever
1675 prefetched. So for the M7, where the L1D$ has 32B lines and the
1676 L2D$ and L3 have 64B lines, a prefetch will prefetch 64B into the
1677 L2 and L3, but only 32B are brought into the L1D$. (Assuming it
1678 is a read_n prefetch, which is the only type which allocates to
1679 the L1.) */
1681 /* PARAM_L1_CACHE_SIZE is the size of the L1D$ (most SPARC chips use
1682 Hardvard level-1 caches) in kilobytes. Both UltraSPARC and
1683 Niagara processors feature a L1D$ of 16KB. */
1684 maybe_set_param_value (PARAM_L1_CACHE_SIZE,
1685 ((sparc_cpu == PROCESSOR_ULTRASPARC
1686 || sparc_cpu == PROCESSOR_ULTRASPARC3
1687 || sparc_cpu == PROCESSOR_NIAGARA
1688 || sparc_cpu == PROCESSOR_NIAGARA2
1689 || sparc_cpu == PROCESSOR_NIAGARA3
1690 || sparc_cpu == PROCESSOR_NIAGARA4
1691 || sparc_cpu == PROCESSOR_NIAGARA7)
1692 ? 16 : 64),
1693 global_options.x_param_values,
1694 global_options_set.x_param_values);
1697 /* PARAM_L2_CACHE_SIZE is the size fo the L2 in kilobytes. Note
1698 that 512 is the default in params.def. */
1699 maybe_set_param_value (PARAM_L2_CACHE_SIZE,
1700 (sparc_cpu == PROCESSOR_NIAGARA4
1701 ? 128 : (sparc_cpu == PROCESSOR_NIAGARA7
1702 ? 256 : 512)),
1703 global_options.x_param_values,
1704 global_options_set.x_param_values);
1707 /* Disable save slot sharing for call-clobbered registers by default.
1708 The IRA sharing algorithm works on single registers only and this
1709 pessimizes for double floating-point registers. */
1710 if (!global_options_set.x_flag_ira_share_save_slots)
1711 flag_ira_share_save_slots = 0;
1714 /* Miscellaneous utilities. */
1716 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
1717 or branch on register contents instructions. */
1720 v9_regcmp_p (enum rtx_code code)
1722 return (code == EQ || code == NE || code == GE || code == LT
1723 || code == LE || code == GT);
1726 /* Nonzero if OP is a floating point constant which can
1727 be loaded into an integer register using a single
1728 sethi instruction. */
1731 fp_sethi_p (rtx op)
1733 if (GET_CODE (op) == CONST_DOUBLE)
1735 long i;
1737 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (op), i);
1738 return !SPARC_SIMM13_P (i) && SPARC_SETHI_P (i);
1741 return 0;
1744 /* Nonzero if OP is a floating point constant which can
1745 be loaded into an integer register using a single
1746 mov instruction. */
1749 fp_mov_p (rtx op)
1751 if (GET_CODE (op) == CONST_DOUBLE)
1753 long i;
1755 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (op), i);
1756 return SPARC_SIMM13_P (i);
1759 return 0;
1762 /* Nonzero if OP is a floating point constant which can
1763 be loaded into an integer register using a high/losum
1764 instruction sequence. */
1767 fp_high_losum_p (rtx op)
1769 /* The constraints calling this should only be in
1770 SFmode move insns, so any constant which cannot
1771 be moved using a single insn will do. */
1772 if (GET_CODE (op) == CONST_DOUBLE)
1774 long i;
1776 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (op), i);
1777 return !SPARC_SIMM13_P (i) && !SPARC_SETHI_P (i);
1780 return 0;
1783 /* Return true if the address of LABEL can be loaded by means of the
1784 mov{si,di}_pic_label_ref patterns in PIC mode. */
1786 static bool
1787 can_use_mov_pic_label_ref (rtx label)
1789 /* VxWorks does not impose a fixed gap between segments; the run-time
1790 gap can be different from the object-file gap. We therefore can't
1791 assume X - _GLOBAL_OFFSET_TABLE_ is a link-time constant unless we
1792 are absolutely sure that X is in the same segment as the GOT.
1793 Unfortunately, the flexibility of linker scripts means that we
1794 can't be sure of that in general, so assume that GOT-relative
1795 accesses are never valid on VxWorks. */
1796 if (TARGET_VXWORKS_RTP)
1797 return false;
1799 /* Similarly, if the label is non-local, it might end up being placed
1800 in a different section than the current one; now mov_pic_label_ref
1801 requires the label and the code to be in the same section. */
1802 if (LABEL_REF_NONLOCAL_P (label))
1803 return false;
1805 /* Finally, if we are reordering basic blocks and partition into hot
1806 and cold sections, this might happen for any label. */
1807 if (flag_reorder_blocks_and_partition)
1808 return false;
1810 return true;
1813 /* Expand a move instruction. Return true if all work is done. */
1815 bool
1816 sparc_expand_move (machine_mode mode, rtx *operands)
1818 /* Handle sets of MEM first. */
1819 if (GET_CODE (operands[0]) == MEM)
1821 /* 0 is a register (or a pair of registers) on SPARC. */
1822 if (register_or_zero_operand (operands[1], mode))
1823 return false;
1825 if (!reload_in_progress)
1827 operands[0] = validize_mem (operands[0]);
1828 operands[1] = force_reg (mode, operands[1]);
1832 /* Fixup TLS cases. */
1833 if (TARGET_HAVE_TLS
1834 && CONSTANT_P (operands[1])
1835 && sparc_tls_referenced_p (operands [1]))
1837 operands[1] = sparc_legitimize_tls_address (operands[1]);
1838 return false;
1841 /* Fixup PIC cases. */
1842 if (flag_pic && CONSTANT_P (operands[1]))
1844 if (pic_address_needs_scratch (operands[1]))
1845 operands[1] = sparc_legitimize_pic_address (operands[1], NULL_RTX);
1847 /* We cannot use the mov{si,di}_pic_label_ref patterns in all cases. */
1848 if (GET_CODE (operands[1]) == LABEL_REF
1849 && can_use_mov_pic_label_ref (operands[1]))
1851 if (mode == SImode)
1853 emit_insn (gen_movsi_pic_label_ref (operands[0], operands[1]));
1854 return true;
1857 if (mode == DImode)
1859 gcc_assert (TARGET_ARCH64);
1860 emit_insn (gen_movdi_pic_label_ref (operands[0], operands[1]));
1861 return true;
1865 if (symbolic_operand (operands[1], mode))
1867 operands[1]
1868 = sparc_legitimize_pic_address (operands[1],
1869 reload_in_progress
1870 ? operands[0] : NULL_RTX);
1871 return false;
1875 /* If we are trying to toss an integer constant into FP registers,
1876 or loading a FP or vector constant, force it into memory. */
1877 if (CONSTANT_P (operands[1])
1878 && REG_P (operands[0])
1879 && (SPARC_FP_REG_P (REGNO (operands[0]))
1880 || SCALAR_FLOAT_MODE_P (mode)
1881 || VECTOR_MODE_P (mode)))
1883 /* emit_group_store will send such bogosity to us when it is
1884 not storing directly into memory. So fix this up to avoid
1885 crashes in output_constant_pool. */
1886 if (operands [1] == const0_rtx)
1887 operands[1] = CONST0_RTX (mode);
1889 /* We can clear or set to all-ones FP registers if TARGET_VIS, and
1890 always other regs. */
1891 if ((TARGET_VIS || REGNO (operands[0]) < SPARC_FIRST_FP_REG)
1892 && (const_zero_operand (operands[1], mode)
1893 || const_all_ones_operand (operands[1], mode)))
1894 return false;
1896 if (REGNO (operands[0]) < SPARC_FIRST_FP_REG
1897 /* We are able to build any SF constant in integer registers
1898 with at most 2 instructions. */
1899 && (mode == SFmode
1900 /* And any DF constant in integer registers. */
1901 || (mode == DFmode
1902 && ! can_create_pseudo_p ())))
1903 return false;
1905 operands[1] = force_const_mem (mode, operands[1]);
1906 if (!reload_in_progress)
1907 operands[1] = validize_mem (operands[1]);
1908 return false;
1911 /* Accept non-constants and valid constants unmodified. */
1912 if (!CONSTANT_P (operands[1])
1913 || GET_CODE (operands[1]) == HIGH
1914 || input_operand (operands[1], mode))
1915 return false;
1917 switch (mode)
1919 case QImode:
1920 /* All QImode constants require only one insn, so proceed. */
1921 break;
1923 case HImode:
1924 case SImode:
1925 sparc_emit_set_const32 (operands[0], operands[1]);
1926 return true;
1928 case DImode:
1929 /* input_operand should have filtered out 32-bit mode. */
1930 sparc_emit_set_const64 (operands[0], operands[1]);
1931 return true;
1933 case TImode:
1935 rtx high, low;
1936 /* TImode isn't available in 32-bit mode. */
1937 split_double (operands[1], &high, &low);
1938 emit_insn (gen_movdi (operand_subword (operands[0], 0, 0, TImode),
1939 high));
1940 emit_insn (gen_movdi (operand_subword (operands[0], 1, 0, TImode),
1941 low));
1943 return true;
1945 default:
1946 gcc_unreachable ();
1949 return false;
1952 /* Load OP1, a 32-bit constant, into OP0, a register.
1953 We know it can't be done in one insn when we get
1954 here, the move expander guarantees this. */
1956 static void
1957 sparc_emit_set_const32 (rtx op0, rtx op1)
1959 machine_mode mode = GET_MODE (op0);
1960 rtx temp = op0;
1962 if (can_create_pseudo_p ())
1963 temp = gen_reg_rtx (mode);
1965 if (GET_CODE (op1) == CONST_INT)
1967 gcc_assert (!small_int_operand (op1, mode)
1968 && !const_high_operand (op1, mode));
1970 /* Emit them as real moves instead of a HIGH/LO_SUM,
1971 this way CSE can see everything and reuse intermediate
1972 values if it wants. */
1973 emit_insn (gen_rtx_SET (temp, GEN_INT (INTVAL (op1)
1974 & ~(HOST_WIDE_INT) 0x3ff)));
1976 emit_insn (gen_rtx_SET (op0,
1977 gen_rtx_IOR (mode, temp,
1978 GEN_INT (INTVAL (op1) & 0x3ff))));
1980 else
1982 /* A symbol, emit in the traditional way. */
1983 emit_insn (gen_rtx_SET (temp, gen_rtx_HIGH (mode, op1)));
1984 emit_insn (gen_rtx_SET (op0, gen_rtx_LO_SUM (mode, temp, op1)));
1988 /* Load OP1, a symbolic 64-bit constant, into OP0, a DImode register.
1989 If TEMP is nonzero, we are forbidden to use any other scratch
1990 registers. Otherwise, we are allowed to generate them as needed.
1992 Note that TEMP may have TImode if the code model is TARGET_CM_MEDANY
1993 or TARGET_CM_EMBMEDANY (see the reload_indi and reload_outdi patterns). */
1995 void
1996 sparc_emit_set_symbolic_const64 (rtx op0, rtx op1, rtx temp)
1998 rtx temp1, temp2, temp3, temp4, temp5;
1999 rtx ti_temp = 0;
2001 if (temp && GET_MODE (temp) == TImode)
2003 ti_temp = temp;
2004 temp = gen_rtx_REG (DImode, REGNO (temp));
2007 /* SPARC-V9 code-model support. */
2008 switch (sparc_cmodel)
2010 case CM_MEDLOW:
2011 /* The range spanned by all instructions in the object is less
2012 than 2^31 bytes (2GB) and the distance from any instruction
2013 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
2014 than 2^31 bytes (2GB).
2016 The executable must be in the low 4TB of the virtual address
2017 space.
2019 sethi %hi(symbol), %temp1
2020 or %temp1, %lo(symbol), %reg */
2021 if (temp)
2022 temp1 = temp; /* op0 is allowed. */
2023 else
2024 temp1 = gen_reg_rtx (DImode);
2026 emit_insn (gen_rtx_SET (temp1, gen_rtx_HIGH (DImode, op1)));
2027 emit_insn (gen_rtx_SET (op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
2028 break;
2030 case CM_MEDMID:
2031 /* The range spanned by all instructions in the object is less
2032 than 2^31 bytes (2GB) and the distance from any instruction
2033 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
2034 than 2^31 bytes (2GB).
2036 The executable must be in the low 16TB of the virtual address
2037 space.
2039 sethi %h44(symbol), %temp1
2040 or %temp1, %m44(symbol), %temp2
2041 sllx %temp2, 12, %temp3
2042 or %temp3, %l44(symbol), %reg */
2043 if (temp)
2045 temp1 = op0;
2046 temp2 = op0;
2047 temp3 = temp; /* op0 is allowed. */
2049 else
2051 temp1 = gen_reg_rtx (DImode);
2052 temp2 = gen_reg_rtx (DImode);
2053 temp3 = gen_reg_rtx (DImode);
2056 emit_insn (gen_seth44 (temp1, op1));
2057 emit_insn (gen_setm44 (temp2, temp1, op1));
2058 emit_insn (gen_rtx_SET (temp3,
2059 gen_rtx_ASHIFT (DImode, temp2, GEN_INT (12))));
2060 emit_insn (gen_setl44 (op0, temp3, op1));
2061 break;
2063 case CM_MEDANY:
2064 /* The range spanned by all instructions in the object is less
2065 than 2^31 bytes (2GB) and the distance from any instruction
2066 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
2067 than 2^31 bytes (2GB).
2069 The executable can be placed anywhere in the virtual address
2070 space.
2072 sethi %hh(symbol), %temp1
2073 sethi %lm(symbol), %temp2
2074 or %temp1, %hm(symbol), %temp3
2075 sllx %temp3, 32, %temp4
2076 or %temp4, %temp2, %temp5
2077 or %temp5, %lo(symbol), %reg */
2078 if (temp)
2080 /* It is possible that one of the registers we got for operands[2]
2081 might coincide with that of operands[0] (which is why we made
2082 it TImode). Pick the other one to use as our scratch. */
2083 if (rtx_equal_p (temp, op0))
2085 gcc_assert (ti_temp);
2086 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
2088 temp1 = op0;
2089 temp2 = temp; /* op0 is _not_ allowed, see above. */
2090 temp3 = op0;
2091 temp4 = op0;
2092 temp5 = op0;
2094 else
2096 temp1 = gen_reg_rtx (DImode);
2097 temp2 = gen_reg_rtx (DImode);
2098 temp3 = gen_reg_rtx (DImode);
2099 temp4 = gen_reg_rtx (DImode);
2100 temp5 = gen_reg_rtx (DImode);
2103 emit_insn (gen_sethh (temp1, op1));
2104 emit_insn (gen_setlm (temp2, op1));
2105 emit_insn (gen_sethm (temp3, temp1, op1));
2106 emit_insn (gen_rtx_SET (temp4,
2107 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
2108 emit_insn (gen_rtx_SET (temp5, gen_rtx_PLUS (DImode, temp4, temp2)));
2109 emit_insn (gen_setlo (op0, temp5, op1));
2110 break;
2112 case CM_EMBMEDANY:
2113 /* Old old old backwards compatibility kruft here.
2114 Essentially it is MEDLOW with a fixed 64-bit
2115 virtual base added to all data segment addresses.
2116 Text-segment stuff is computed like MEDANY, we can't
2117 reuse the code above because the relocation knobs
2118 look different.
2120 Data segment: sethi %hi(symbol), %temp1
2121 add %temp1, EMBMEDANY_BASE_REG, %temp2
2122 or %temp2, %lo(symbol), %reg */
2123 if (data_segment_operand (op1, GET_MODE (op1)))
2125 if (temp)
2127 temp1 = temp; /* op0 is allowed. */
2128 temp2 = op0;
2130 else
2132 temp1 = gen_reg_rtx (DImode);
2133 temp2 = gen_reg_rtx (DImode);
2136 emit_insn (gen_embmedany_sethi (temp1, op1));
2137 emit_insn (gen_embmedany_brsum (temp2, temp1));
2138 emit_insn (gen_embmedany_losum (op0, temp2, op1));
2141 /* Text segment: sethi %uhi(symbol), %temp1
2142 sethi %hi(symbol), %temp2
2143 or %temp1, %ulo(symbol), %temp3
2144 sllx %temp3, 32, %temp4
2145 or %temp4, %temp2, %temp5
2146 or %temp5, %lo(symbol), %reg */
2147 else
2149 if (temp)
2151 /* It is possible that one of the registers we got for operands[2]
2152 might coincide with that of operands[0] (which is why we made
2153 it TImode). Pick the other one to use as our scratch. */
2154 if (rtx_equal_p (temp, op0))
2156 gcc_assert (ti_temp);
2157 temp = gen_rtx_REG (DImode, REGNO (temp) + 1);
2159 temp1 = op0;
2160 temp2 = temp; /* op0 is _not_ allowed, see above. */
2161 temp3 = op0;
2162 temp4 = op0;
2163 temp5 = op0;
2165 else
2167 temp1 = gen_reg_rtx (DImode);
2168 temp2 = gen_reg_rtx (DImode);
2169 temp3 = gen_reg_rtx (DImode);
2170 temp4 = gen_reg_rtx (DImode);
2171 temp5 = gen_reg_rtx (DImode);
2174 emit_insn (gen_embmedany_textuhi (temp1, op1));
2175 emit_insn (gen_embmedany_texthi (temp2, op1));
2176 emit_insn (gen_embmedany_textulo (temp3, temp1, op1));
2177 emit_insn (gen_rtx_SET (temp4,
2178 gen_rtx_ASHIFT (DImode, temp3, GEN_INT (32))));
2179 emit_insn (gen_rtx_SET (temp5, gen_rtx_PLUS (DImode, temp4, temp2)));
2180 emit_insn (gen_embmedany_textlo (op0, temp5, op1));
2182 break;
2184 default:
2185 gcc_unreachable ();
2189 /* These avoid problems when cross compiling. If we do not
2190 go through all this hair then the optimizer will see
2191 invalid REG_EQUAL notes or in some cases none at all. */
2192 static rtx gen_safe_HIGH64 (rtx, HOST_WIDE_INT);
2193 static rtx gen_safe_SET64 (rtx, HOST_WIDE_INT);
2194 static rtx gen_safe_OR64 (rtx, HOST_WIDE_INT);
2195 static rtx gen_safe_XOR64 (rtx, HOST_WIDE_INT);
2197 /* The optimizer is not to assume anything about exactly
2198 which bits are set for a HIGH, they are unspecified.
2199 Unfortunately this leads to many missed optimizations
2200 during CSE. We mask out the non-HIGH bits, and matches
2201 a plain movdi, to alleviate this problem. */
2202 static rtx
2203 gen_safe_HIGH64 (rtx dest, HOST_WIDE_INT val)
2205 return gen_rtx_SET (dest, GEN_INT (val & ~(HOST_WIDE_INT)0x3ff));
2208 static rtx
2209 gen_safe_SET64 (rtx dest, HOST_WIDE_INT val)
2211 return gen_rtx_SET (dest, GEN_INT (val));
2214 static rtx
2215 gen_safe_OR64 (rtx src, HOST_WIDE_INT val)
2217 return gen_rtx_IOR (DImode, src, GEN_INT (val));
2220 static rtx
2221 gen_safe_XOR64 (rtx src, HOST_WIDE_INT val)
2223 return gen_rtx_XOR (DImode, src, GEN_INT (val));
2226 /* Worker routines for 64-bit constant formation on arch64.
2227 One of the key things to be doing in these emissions is
2228 to create as many temp REGs as possible. This makes it
2229 possible for half-built constants to be used later when
2230 such values are similar to something required later on.
2231 Without doing this, the optimizer cannot see such
2232 opportunities. */
2234 static void sparc_emit_set_const64_quick1 (rtx, rtx,
2235 unsigned HOST_WIDE_INT, int);
2237 static void
2238 sparc_emit_set_const64_quick1 (rtx op0, rtx temp,
2239 unsigned HOST_WIDE_INT low_bits, int is_neg)
2241 unsigned HOST_WIDE_INT high_bits;
2243 if (is_neg)
2244 high_bits = (~low_bits) & 0xffffffff;
2245 else
2246 high_bits = low_bits;
2248 emit_insn (gen_safe_HIGH64 (temp, high_bits));
2249 if (!is_neg)
2251 emit_insn (gen_rtx_SET (op0, gen_safe_OR64 (temp, (high_bits & 0x3ff))));
2253 else
2255 /* If we are XOR'ing with -1, then we should emit a one's complement
2256 instead. This way the combiner will notice logical operations
2257 such as ANDN later on and substitute. */
2258 if ((low_bits & 0x3ff) == 0x3ff)
2260 emit_insn (gen_rtx_SET (op0, gen_rtx_NOT (DImode, temp)));
2262 else
2264 emit_insn (gen_rtx_SET (op0,
2265 gen_safe_XOR64 (temp,
2266 (-(HOST_WIDE_INT)0x400
2267 | (low_bits & 0x3ff)))));
2272 static void sparc_emit_set_const64_quick2 (rtx, rtx, unsigned HOST_WIDE_INT,
2273 unsigned HOST_WIDE_INT, int);
2275 static void
2276 sparc_emit_set_const64_quick2 (rtx op0, rtx temp,
2277 unsigned HOST_WIDE_INT high_bits,
2278 unsigned HOST_WIDE_INT low_immediate,
2279 int shift_count)
2281 rtx temp2 = op0;
2283 if ((high_bits & 0xfffffc00) != 0)
2285 emit_insn (gen_safe_HIGH64 (temp, high_bits));
2286 if ((high_bits & ~0xfffffc00) != 0)
2287 emit_insn (gen_rtx_SET (op0,
2288 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
2289 else
2290 temp2 = temp;
2292 else
2294 emit_insn (gen_safe_SET64 (temp, high_bits));
2295 temp2 = temp;
2298 /* Now shift it up into place. */
2299 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, temp2,
2300 GEN_INT (shift_count))));
2302 /* If there is a low immediate part piece, finish up by
2303 putting that in as well. */
2304 if (low_immediate != 0)
2305 emit_insn (gen_rtx_SET (op0, gen_safe_OR64 (op0, low_immediate)));
2308 static void sparc_emit_set_const64_longway (rtx, rtx, unsigned HOST_WIDE_INT,
2309 unsigned HOST_WIDE_INT);
2311 /* Full 64-bit constant decomposition. Even though this is the
2312 'worst' case, we still optimize a few things away. */
2313 static void
2314 sparc_emit_set_const64_longway (rtx op0, rtx temp,
2315 unsigned HOST_WIDE_INT high_bits,
2316 unsigned HOST_WIDE_INT low_bits)
2318 rtx sub_temp = op0;
2320 if (can_create_pseudo_p ())
2321 sub_temp = gen_reg_rtx (DImode);
2323 if ((high_bits & 0xfffffc00) != 0)
2325 emit_insn (gen_safe_HIGH64 (temp, high_bits));
2326 if ((high_bits & ~0xfffffc00) != 0)
2327 emit_insn (gen_rtx_SET (sub_temp,
2328 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
2329 else
2330 sub_temp = temp;
2332 else
2334 emit_insn (gen_safe_SET64 (temp, high_bits));
2335 sub_temp = temp;
2338 if (can_create_pseudo_p ())
2340 rtx temp2 = gen_reg_rtx (DImode);
2341 rtx temp3 = gen_reg_rtx (DImode);
2342 rtx temp4 = gen_reg_rtx (DImode);
2344 emit_insn (gen_rtx_SET (temp4, gen_rtx_ASHIFT (DImode, sub_temp,
2345 GEN_INT (32))));
2347 emit_insn (gen_safe_HIGH64 (temp2, low_bits));
2348 if ((low_bits & ~0xfffffc00) != 0)
2350 emit_insn (gen_rtx_SET (temp3,
2351 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
2352 emit_insn (gen_rtx_SET (op0, gen_rtx_PLUS (DImode, temp4, temp3)));
2354 else
2356 emit_insn (gen_rtx_SET (op0, gen_rtx_PLUS (DImode, temp4, temp2)));
2359 else
2361 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
2362 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
2363 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
2364 int to_shift = 12;
2366 /* We are in the middle of reload, so this is really
2367 painful. However we do still make an attempt to
2368 avoid emitting truly stupid code. */
2369 if (low1 != const0_rtx)
2371 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, sub_temp,
2372 GEN_INT (to_shift))));
2373 emit_insn (gen_rtx_SET (op0, gen_rtx_IOR (DImode, op0, low1)));
2374 sub_temp = op0;
2375 to_shift = 12;
2377 else
2379 to_shift += 12;
2381 if (low2 != const0_rtx)
2383 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, sub_temp,
2384 GEN_INT (to_shift))));
2385 emit_insn (gen_rtx_SET (op0, gen_rtx_IOR (DImode, op0, low2)));
2386 sub_temp = op0;
2387 to_shift = 8;
2389 else
2391 to_shift += 8;
2393 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, sub_temp,
2394 GEN_INT (to_shift))));
2395 if (low3 != const0_rtx)
2396 emit_insn (gen_rtx_SET (op0, gen_rtx_IOR (DImode, op0, low3)));
2397 /* phew... */
2401 /* Analyze a 64-bit constant for certain properties. */
2402 static void analyze_64bit_constant (unsigned HOST_WIDE_INT,
2403 unsigned HOST_WIDE_INT,
2404 int *, int *, int *);
2406 static void
2407 analyze_64bit_constant (unsigned HOST_WIDE_INT high_bits,
2408 unsigned HOST_WIDE_INT low_bits,
2409 int *hbsp, int *lbsp, int *abbasp)
2411 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
2412 int i;
2414 lowest_bit_set = highest_bit_set = -1;
2415 i = 0;
2418 if ((lowest_bit_set == -1)
2419 && ((low_bits >> i) & 1))
2420 lowest_bit_set = i;
2421 if ((highest_bit_set == -1)
2422 && ((high_bits >> (32 - i - 1)) & 1))
2423 highest_bit_set = (64 - i - 1);
2425 while (++i < 32
2426 && ((highest_bit_set == -1)
2427 || (lowest_bit_set == -1)));
2428 if (i == 32)
2430 i = 0;
2433 if ((lowest_bit_set == -1)
2434 && ((high_bits >> i) & 1))
2435 lowest_bit_set = i + 32;
2436 if ((highest_bit_set == -1)
2437 && ((low_bits >> (32 - i - 1)) & 1))
2438 highest_bit_set = 32 - i - 1;
2440 while (++i < 32
2441 && ((highest_bit_set == -1)
2442 || (lowest_bit_set == -1)));
2444 /* If there are no bits set this should have gone out
2445 as one instruction! */
2446 gcc_assert (lowest_bit_set != -1 && highest_bit_set != -1);
2447 all_bits_between_are_set = 1;
2448 for (i = lowest_bit_set; i <= highest_bit_set; i++)
2450 if (i < 32)
2452 if ((low_bits & (1 << i)) != 0)
2453 continue;
2455 else
2457 if ((high_bits & (1 << (i - 32))) != 0)
2458 continue;
2460 all_bits_between_are_set = 0;
2461 break;
2463 *hbsp = highest_bit_set;
2464 *lbsp = lowest_bit_set;
2465 *abbasp = all_bits_between_are_set;
2468 static int const64_is_2insns (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2470 static int
2471 const64_is_2insns (unsigned HOST_WIDE_INT high_bits,
2472 unsigned HOST_WIDE_INT low_bits)
2474 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
2476 if (high_bits == 0
2477 || high_bits == 0xffffffff)
2478 return 1;
2480 analyze_64bit_constant (high_bits, low_bits,
2481 &highest_bit_set, &lowest_bit_set,
2482 &all_bits_between_are_set);
2484 if ((highest_bit_set == 63
2485 || lowest_bit_set == 0)
2486 && all_bits_between_are_set != 0)
2487 return 1;
2489 if ((highest_bit_set - lowest_bit_set) < 21)
2490 return 1;
2492 return 0;
2495 static unsigned HOST_WIDE_INT create_simple_focus_bits (unsigned HOST_WIDE_INT,
2496 unsigned HOST_WIDE_INT,
2497 int, int);
2499 static unsigned HOST_WIDE_INT
2500 create_simple_focus_bits (unsigned HOST_WIDE_INT high_bits,
2501 unsigned HOST_WIDE_INT low_bits,
2502 int lowest_bit_set, int shift)
2504 HOST_WIDE_INT hi, lo;
2506 if (lowest_bit_set < 32)
2508 lo = (low_bits >> lowest_bit_set) << shift;
2509 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
2511 else
2513 lo = 0;
2514 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
2516 gcc_assert (! (hi & lo));
2517 return (hi | lo);
2520 /* Here we are sure to be arch64 and this is an integer constant
2521 being loaded into a register. Emit the most efficient
2522 insn sequence possible. Detection of all the 1-insn cases
2523 has been done already. */
2524 static void
2525 sparc_emit_set_const64 (rtx op0, rtx op1)
2527 unsigned HOST_WIDE_INT high_bits, low_bits;
2528 int lowest_bit_set, highest_bit_set;
2529 int all_bits_between_are_set;
2530 rtx temp = 0;
2532 /* Sanity check that we know what we are working with. */
2533 gcc_assert (TARGET_ARCH64
2534 && (GET_CODE (op0) == SUBREG
2535 || (REG_P (op0) && ! SPARC_FP_REG_P (REGNO (op0)))));
2537 if (! can_create_pseudo_p ())
2538 temp = op0;
2540 if (GET_CODE (op1) != CONST_INT)
2542 sparc_emit_set_symbolic_const64 (op0, op1, temp);
2543 return;
2546 if (! temp)
2547 temp = gen_reg_rtx (DImode);
2549 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
2550 low_bits = (INTVAL (op1) & 0xffffffff);
2552 /* low_bits bits 0 --> 31
2553 high_bits bits 32 --> 63 */
2555 analyze_64bit_constant (high_bits, low_bits,
2556 &highest_bit_set, &lowest_bit_set,
2557 &all_bits_between_are_set);
2559 /* First try for a 2-insn sequence. */
2561 /* These situations are preferred because the optimizer can
2562 * do more things with them:
2563 * 1) mov -1, %reg
2564 * sllx %reg, shift, %reg
2565 * 2) mov -1, %reg
2566 * srlx %reg, shift, %reg
2567 * 3) mov some_small_const, %reg
2568 * sllx %reg, shift, %reg
2570 if (((highest_bit_set == 63
2571 || lowest_bit_set == 0)
2572 && all_bits_between_are_set != 0)
2573 || ((highest_bit_set - lowest_bit_set) < 12))
2575 HOST_WIDE_INT the_const = -1;
2576 int shift = lowest_bit_set;
2578 if ((highest_bit_set != 63
2579 && lowest_bit_set != 0)
2580 || all_bits_between_are_set == 0)
2582 the_const =
2583 create_simple_focus_bits (high_bits, low_bits,
2584 lowest_bit_set, 0);
2586 else if (lowest_bit_set == 0)
2587 shift = -(63 - highest_bit_set);
2589 gcc_assert (SPARC_SIMM13_P (the_const));
2590 gcc_assert (shift != 0);
2592 emit_insn (gen_safe_SET64 (temp, the_const));
2593 if (shift > 0)
2594 emit_insn (gen_rtx_SET (op0, gen_rtx_ASHIFT (DImode, temp,
2595 GEN_INT (shift))));
2596 else if (shift < 0)
2597 emit_insn (gen_rtx_SET (op0, gen_rtx_LSHIFTRT (DImode, temp,
2598 GEN_INT (-shift))));
2599 return;
2602 /* Now a range of 22 or less bits set somewhere.
2603 * 1) sethi %hi(focus_bits), %reg
2604 * sllx %reg, shift, %reg
2605 * 2) sethi %hi(focus_bits), %reg
2606 * srlx %reg, shift, %reg
2608 if ((highest_bit_set - lowest_bit_set) < 21)
2610 unsigned HOST_WIDE_INT focus_bits =
2611 create_simple_focus_bits (high_bits, low_bits,
2612 lowest_bit_set, 10);
2614 gcc_assert (SPARC_SETHI_P (focus_bits));
2615 gcc_assert (lowest_bit_set != 10);
2617 emit_insn (gen_safe_HIGH64 (temp, focus_bits));
2619 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
2620 if (lowest_bit_set < 10)
2621 emit_insn (gen_rtx_SET (op0,
2622 gen_rtx_LSHIFTRT (DImode, temp,
2623 GEN_INT (10 - lowest_bit_set))));
2624 else if (lowest_bit_set > 10)
2625 emit_insn (gen_rtx_SET (op0,
2626 gen_rtx_ASHIFT (DImode, temp,
2627 GEN_INT (lowest_bit_set - 10))));
2628 return;
2631 /* 1) sethi %hi(low_bits), %reg
2632 * or %reg, %lo(low_bits), %reg
2633 * 2) sethi %hi(~low_bits), %reg
2634 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
2636 if (high_bits == 0
2637 || high_bits == 0xffffffff)
2639 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
2640 (high_bits == 0xffffffff));
2641 return;
2644 /* Now, try 3-insn sequences. */
2646 /* 1) sethi %hi(high_bits), %reg
2647 * or %reg, %lo(high_bits), %reg
2648 * sllx %reg, 32, %reg
2650 if (low_bits == 0)
2652 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
2653 return;
2656 /* We may be able to do something quick
2657 when the constant is negated, so try that. */
2658 if (const64_is_2insns ((~high_bits) & 0xffffffff,
2659 (~low_bits) & 0xfffffc00))
2661 /* NOTE: The trailing bits get XOR'd so we need the
2662 non-negated bits, not the negated ones. */
2663 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
2665 if ((((~high_bits) & 0xffffffff) == 0
2666 && ((~low_bits) & 0x80000000) == 0)
2667 || (((~high_bits) & 0xffffffff) == 0xffffffff
2668 && ((~low_bits) & 0x80000000) != 0))
2670 unsigned HOST_WIDE_INT fast_int = (~low_bits & 0xffffffff);
2672 if ((SPARC_SETHI_P (fast_int)
2673 && (~high_bits & 0xffffffff) == 0)
2674 || SPARC_SIMM13_P (fast_int))
2675 emit_insn (gen_safe_SET64 (temp, fast_int));
2676 else
2677 sparc_emit_set_const64 (temp, GEN_INT (fast_int));
2679 else
2681 rtx negated_const;
2682 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2683 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2684 sparc_emit_set_const64 (temp, negated_const);
2687 /* If we are XOR'ing with -1, then we should emit a one's complement
2688 instead. This way the combiner will notice logical operations
2689 such as ANDN later on and substitute. */
2690 if (trailing_bits == 0x3ff)
2692 emit_insn (gen_rtx_SET (op0, gen_rtx_NOT (DImode, temp)));
2694 else
2696 emit_insn (gen_rtx_SET (op0,
2697 gen_safe_XOR64 (temp,
2698 (-0x400 | trailing_bits))));
2700 return;
2703 /* 1) sethi %hi(xxx), %reg
2704 * or %reg, %lo(xxx), %reg
2705 * sllx %reg, yyy, %reg
2707 * ??? This is just a generalized version of the low_bits==0
2708 * thing above, FIXME...
2710 if ((highest_bit_set - lowest_bit_set) < 32)
2712 unsigned HOST_WIDE_INT focus_bits =
2713 create_simple_focus_bits (high_bits, low_bits,
2714 lowest_bit_set, 0);
2716 /* We can't get here in this state. */
2717 gcc_assert (highest_bit_set >= 32 && lowest_bit_set < 32);
2719 /* So what we know is that the set bits straddle the
2720 middle of the 64-bit word. */
2721 sparc_emit_set_const64_quick2 (op0, temp,
2722 focus_bits, 0,
2723 lowest_bit_set);
2724 return;
2727 /* 1) sethi %hi(high_bits), %reg
2728 * or %reg, %lo(high_bits), %reg
2729 * sllx %reg, 32, %reg
2730 * or %reg, low_bits, %reg
2732 if (SPARC_SIMM13_P (low_bits) && ((int)low_bits > 0))
2734 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2735 return;
2738 /* The easiest way when all else fails, is full decomposition. */
2739 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2742 /* Implement TARGET_FIXED_CONDITION_CODE_REGS. */
2744 static bool
2745 sparc_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
2747 *p1 = SPARC_ICC_REG;
2748 *p2 = SPARC_FCC_REG;
2749 return true;
2752 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2753 return the mode to be used for the comparison. For floating-point,
2754 CCFP[E]mode is used. CCNZmode should be used when the first operand
2755 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2756 processing is needed. */
2758 machine_mode
2759 select_cc_mode (enum rtx_code op, rtx x, rtx y)
2761 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2763 switch (op)
2765 case EQ:
2766 case NE:
2767 case UNORDERED:
2768 case ORDERED:
2769 case UNLT:
2770 case UNLE:
2771 case UNGT:
2772 case UNGE:
2773 case UNEQ:
2774 case LTGT:
2775 return CCFPmode;
2777 case LT:
2778 case LE:
2779 case GT:
2780 case GE:
2781 return CCFPEmode;
2783 default:
2784 gcc_unreachable ();
2787 else if ((GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2788 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2789 && y == const0_rtx)
2791 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2792 return CCXNZmode;
2793 else
2794 return CCNZmode;
2796 else
2798 /* This is for the cmp<mode>_sne pattern. */
2799 if (GET_CODE (x) == NOT && y == constm1_rtx)
2801 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2802 return CCXCmode;
2803 else
2804 return CCCmode;
2807 /* This is for the [u]addvdi4_sp32 and [u]subvdi4_sp32 patterns. */
2808 if (!TARGET_ARCH64 && GET_MODE (x) == DImode)
2810 if (GET_CODE (y) == UNSPEC
2811 && (XINT (y, 1) == UNSPEC_ADDV
2812 || XINT (y, 1) == UNSPEC_SUBV
2813 || XINT (y, 1) == UNSPEC_NEGV))
2814 return CCVmode;
2815 else
2816 return CCCmode;
2819 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2820 return CCXmode;
2821 else
2822 return CCmode;
2826 /* Emit the compare insn and return the CC reg for a CODE comparison
2827 with operands X and Y. */
2829 static rtx
2830 gen_compare_reg_1 (enum rtx_code code, rtx x, rtx y)
2832 machine_mode mode;
2833 rtx cc_reg;
2835 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
2836 return x;
2838 mode = SELECT_CC_MODE (code, x, y);
2840 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2841 fcc regs (cse can't tell they're really call clobbered regs and will
2842 remove a duplicate comparison even if there is an intervening function
2843 call - it will then try to reload the cc reg via an int reg which is why
2844 we need the movcc patterns). It is possible to provide the movcc
2845 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2846 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2847 to tell cse that CCFPE mode registers (even pseudos) are call
2848 clobbered. */
2850 /* ??? This is an experiment. Rather than making changes to cse which may
2851 or may not be easy/clean, we do our own cse. This is possible because
2852 we will generate hard registers. Cse knows they're call clobbered (it
2853 doesn't know the same thing about pseudos). If we guess wrong, no big
2854 deal, but if we win, great! */
2856 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2857 #if 1 /* experiment */
2859 int reg;
2860 /* We cycle through the registers to ensure they're all exercised. */
2861 static int next_fcc_reg = 0;
2862 /* Previous x,y for each fcc reg. */
2863 static rtx prev_args[4][2];
2865 /* Scan prev_args for x,y. */
2866 for (reg = 0; reg < 4; reg++)
2867 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2868 break;
2869 if (reg == 4)
2871 reg = next_fcc_reg;
2872 prev_args[reg][0] = x;
2873 prev_args[reg][1] = y;
2874 next_fcc_reg = (next_fcc_reg + 1) & 3;
2876 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2878 #else
2879 cc_reg = gen_reg_rtx (mode);
2880 #endif /* ! experiment */
2881 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2882 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2883 else
2884 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2886 /* We shouldn't get there for TFmode if !TARGET_HARD_QUAD. If we do, this
2887 will only result in an unrecognizable insn so no point in asserting. */
2888 emit_insn (gen_rtx_SET (cc_reg, gen_rtx_COMPARE (mode, x, y)));
2890 return cc_reg;
2894 /* Emit the compare insn and return the CC reg for the comparison in CMP. */
2897 gen_compare_reg (rtx cmp)
2899 return gen_compare_reg_1 (GET_CODE (cmp), XEXP (cmp, 0), XEXP (cmp, 1));
2902 /* This function is used for v9 only.
2903 DEST is the target of the Scc insn.
2904 CODE is the code for an Scc's comparison.
2905 X and Y are the values we compare.
2907 This function is needed to turn
2909 (set (reg:SI 110)
2910 (gt (reg:CCX 100 %icc)
2911 (const_int 0)))
2912 into
2913 (set (reg:SI 110)
2914 (gt:DI (reg:CCX 100 %icc)
2915 (const_int 0)))
2917 IE: The instruction recognizer needs to see the mode of the comparison to
2918 find the right instruction. We could use "gt:DI" right in the
2919 define_expand, but leaving it out allows us to handle DI, SI, etc. */
2921 static int
2922 gen_v9_scc (rtx dest, enum rtx_code compare_code, rtx x, rtx y)
2924 if (! TARGET_ARCH64
2925 && (GET_MODE (x) == DImode
2926 || GET_MODE (dest) == DImode))
2927 return 0;
2929 /* Try to use the movrCC insns. */
2930 if (TARGET_ARCH64
2931 && GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2932 && y == const0_rtx
2933 && v9_regcmp_p (compare_code))
2935 rtx op0 = x;
2936 rtx temp;
2938 /* Special case for op0 != 0. This can be done with one instruction if
2939 dest == x. */
2941 if (compare_code == NE
2942 && GET_MODE (dest) == DImode
2943 && rtx_equal_p (op0, dest))
2945 emit_insn (gen_rtx_SET (dest,
2946 gen_rtx_IF_THEN_ELSE (DImode,
2947 gen_rtx_fmt_ee (compare_code, DImode,
2948 op0, const0_rtx),
2949 const1_rtx,
2950 dest)));
2951 return 1;
2954 if (reg_overlap_mentioned_p (dest, op0))
2956 /* Handle the case where dest == x.
2957 We "early clobber" the result. */
2958 op0 = gen_reg_rtx (GET_MODE (x));
2959 emit_move_insn (op0, x);
2962 emit_insn (gen_rtx_SET (dest, const0_rtx));
2963 if (GET_MODE (op0) != DImode)
2965 temp = gen_reg_rtx (DImode);
2966 convert_move (temp, op0, 0);
2968 else
2969 temp = op0;
2970 emit_insn (gen_rtx_SET (dest,
2971 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2972 gen_rtx_fmt_ee (compare_code, DImode,
2973 temp, const0_rtx),
2974 const1_rtx,
2975 dest)));
2976 return 1;
2978 else
2980 x = gen_compare_reg_1 (compare_code, x, y);
2981 y = const0_rtx;
2983 emit_insn (gen_rtx_SET (dest, const0_rtx));
2984 emit_insn (gen_rtx_SET (dest,
2985 gen_rtx_IF_THEN_ELSE (GET_MODE (dest),
2986 gen_rtx_fmt_ee (compare_code,
2987 GET_MODE (x), x, y),
2988 const1_rtx, dest)));
2989 return 1;
2994 /* Emit an scc insn. For seq, sne, sgeu, and sltu, we can do this
2995 without jumps using the addx/subx instructions. */
2997 bool
2998 emit_scc_insn (rtx operands[])
3000 rtx tem, x, y;
3001 enum rtx_code code;
3002 machine_mode mode;
3004 /* The quad-word fp compare library routines all return nonzero to indicate
3005 true, which is different from the equivalent libgcc routines, so we must
3006 handle them specially here. */
3007 if (GET_MODE (operands[2]) == TFmode && ! TARGET_HARD_QUAD)
3009 operands[1] = sparc_emit_float_lib_cmp (operands[2], operands[3],
3010 GET_CODE (operands[1]));
3011 operands[2] = XEXP (operands[1], 0);
3012 operands[3] = XEXP (operands[1], 1);
3015 code = GET_CODE (operands[1]);
3016 x = operands[2];
3017 y = operands[3];
3018 mode = GET_MODE (x);
3020 /* For seq/sne on v9 we use the same code as v8 (the addx/subx method has
3021 more applications). The exception to this is "reg != 0" which can
3022 be done in one instruction on v9 (so we do it). */
3023 if ((code == EQ || code == NE) && (mode == SImode || mode == DImode))
3025 if (y != const0_rtx)
3026 x = force_reg (mode, gen_rtx_XOR (mode, x, y));
3028 rtx pat = gen_rtx_SET (operands[0],
3029 gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
3030 x, const0_rtx));
3032 /* If we can use addx/subx or addxc, add a clobber for CC. */
3033 if (mode == SImode || (code == NE && TARGET_VIS3))
3035 rtx clobber
3036 = gen_rtx_CLOBBER (VOIDmode,
3037 gen_rtx_REG (mode == SImode ? CCmode : CCXmode,
3038 SPARC_ICC_REG));
3039 pat = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, pat, clobber));
3042 emit_insn (pat);
3043 return true;
3046 /* We can do LTU in DImode using the addxc instruction with VIS3. */
3047 if (TARGET_ARCH64
3048 && mode == DImode
3049 && !((code == LTU || code == GTU) && TARGET_VIS3)
3050 && gen_v9_scc (operands[0], code, x, y))
3051 return true;
3053 /* We can do LTU and GEU using the addx/subx instructions too. And
3054 for GTU/LEU, if both operands are registers swap them and fall
3055 back to the easy case. */
3056 if (code == GTU || code == LEU)
3058 if ((GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
3059 && (GET_CODE (y) == REG || GET_CODE (y) == SUBREG))
3061 tem = x;
3062 x = y;
3063 y = tem;
3064 code = swap_condition (code);
3068 if (code == LTU || code == GEU)
3070 emit_insn (gen_rtx_SET (operands[0],
3071 gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
3072 gen_compare_reg_1 (code, x, y),
3073 const0_rtx)));
3074 return true;
3077 /* All the posibilities to use addx/subx based sequences has been
3078 exhausted, try for a 3 instruction sequence using v9 conditional
3079 moves. */
3080 if (TARGET_V9 && gen_v9_scc (operands[0], code, x, y))
3081 return true;
3083 /* Nope, do branches. */
3084 return false;
3087 /* Emit a conditional jump insn for the v9 architecture using comparison code
3088 CODE and jump target LABEL.
3089 This function exists to take advantage of the v9 brxx insns. */
3091 static void
3092 emit_v9_brxx_insn (enum rtx_code code, rtx op0, rtx label)
3094 emit_jump_insn (gen_rtx_SET (pc_rtx,
3095 gen_rtx_IF_THEN_ELSE (VOIDmode,
3096 gen_rtx_fmt_ee (code, GET_MODE (op0),
3097 op0, const0_rtx),
3098 gen_rtx_LABEL_REF (VOIDmode, label),
3099 pc_rtx)));
3102 /* Emit a conditional jump insn for the UA2011 architecture using
3103 comparison code CODE and jump target LABEL. This function exists
3104 to take advantage of the UA2011 Compare and Branch insns. */
3106 static void
3107 emit_cbcond_insn (enum rtx_code code, rtx op0, rtx op1, rtx label)
3109 rtx if_then_else;
3111 if_then_else = gen_rtx_IF_THEN_ELSE (VOIDmode,
3112 gen_rtx_fmt_ee(code, GET_MODE(op0),
3113 op0, op1),
3114 gen_rtx_LABEL_REF (VOIDmode, label),
3115 pc_rtx);
3117 emit_jump_insn (gen_rtx_SET (pc_rtx, if_then_else));
3120 void
3121 emit_conditional_branch_insn (rtx operands[])
3123 /* The quad-word fp compare library routines all return nonzero to indicate
3124 true, which is different from the equivalent libgcc routines, so we must
3125 handle them specially here. */
3126 if (GET_MODE (operands[1]) == TFmode && ! TARGET_HARD_QUAD)
3128 operands[0] = sparc_emit_float_lib_cmp (operands[1], operands[2],
3129 GET_CODE (operands[0]));
3130 operands[1] = XEXP (operands[0], 0);
3131 operands[2] = XEXP (operands[0], 1);
3134 /* If we can tell early on that the comparison is against a constant
3135 that won't fit in the 5-bit signed immediate field of a cbcond,
3136 use one of the other v9 conditional branch sequences. */
3137 if (TARGET_CBCOND
3138 && GET_CODE (operands[1]) == REG
3139 && (GET_MODE (operands[1]) == SImode
3140 || (TARGET_ARCH64 && GET_MODE (operands[1]) == DImode))
3141 && (GET_CODE (operands[2]) != CONST_INT
3142 || SPARC_SIMM5_P (INTVAL (operands[2]))))
3144 emit_cbcond_insn (GET_CODE (operands[0]), operands[1], operands[2], operands[3]);
3145 return;
3148 if (TARGET_ARCH64 && operands[2] == const0_rtx
3149 && GET_CODE (operands[1]) == REG
3150 && GET_MODE (operands[1]) == DImode)
3152 emit_v9_brxx_insn (GET_CODE (operands[0]), operands[1], operands[3]);
3153 return;
3156 operands[1] = gen_compare_reg (operands[0]);
3157 operands[2] = const0_rtx;
3158 operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]), VOIDmode,
3159 operands[1], operands[2]);
3160 emit_jump_insn (gen_cbranchcc4 (operands[0], operands[1], operands[2],
3161 operands[3]));
3165 /* Generate a DFmode part of a hard TFmode register.
3166 REG is the TFmode hard register, LOW is 1 for the
3167 low 64bit of the register and 0 otherwise.
3170 gen_df_reg (rtx reg, int low)
3172 int regno = REGNO (reg);
3174 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
3175 regno += (TARGET_ARCH64 && SPARC_INT_REG_P (regno)) ? 1 : 2;
3176 return gen_rtx_REG (DFmode, regno);
3179 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
3180 Unlike normal calls, TFmode operands are passed by reference. It is
3181 assumed that no more than 3 operands are required. */
3183 static void
3184 emit_soft_tfmode_libcall (const char *func_name, int nargs, rtx *operands)
3186 rtx ret_slot = NULL, arg[3], func_sym;
3187 int i;
3189 /* We only expect to be called for conversions, unary, and binary ops. */
3190 gcc_assert (nargs == 2 || nargs == 3);
3192 for (i = 0; i < nargs; ++i)
3194 rtx this_arg = operands[i];
3195 rtx this_slot;
3197 /* TFmode arguments and return values are passed by reference. */
3198 if (GET_MODE (this_arg) == TFmode)
3200 int force_stack_temp;
3202 force_stack_temp = 0;
3203 if (TARGET_BUGGY_QP_LIB && i == 0)
3204 force_stack_temp = 1;
3206 if (GET_CODE (this_arg) == MEM
3207 && ! force_stack_temp)
3209 tree expr = MEM_EXPR (this_arg);
3210 if (expr)
3211 mark_addressable (expr);
3212 this_arg = XEXP (this_arg, 0);
3214 else if (CONSTANT_P (this_arg)
3215 && ! force_stack_temp)
3217 this_slot = force_const_mem (TFmode, this_arg);
3218 this_arg = XEXP (this_slot, 0);
3220 else
3222 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode));
3224 /* Operand 0 is the return value. We'll copy it out later. */
3225 if (i > 0)
3226 emit_move_insn (this_slot, this_arg);
3227 else
3228 ret_slot = this_slot;
3230 this_arg = XEXP (this_slot, 0);
3234 arg[i] = this_arg;
3237 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
3239 if (GET_MODE (operands[0]) == TFmode)
3241 if (nargs == 2)
3242 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
3243 arg[0], GET_MODE (arg[0]),
3244 arg[1], GET_MODE (arg[1]));
3245 else
3246 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
3247 arg[0], GET_MODE (arg[0]),
3248 arg[1], GET_MODE (arg[1]),
3249 arg[2], GET_MODE (arg[2]));
3251 if (ret_slot)
3252 emit_move_insn (operands[0], ret_slot);
3254 else
3256 rtx ret;
3258 gcc_assert (nargs == 2);
3260 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
3261 GET_MODE (operands[0]), 1,
3262 arg[1], GET_MODE (arg[1]));
3264 if (ret != operands[0])
3265 emit_move_insn (operands[0], ret);
3269 /* Expand soft-float TFmode calls to sparc abi routines. */
3271 static void
3272 emit_soft_tfmode_binop (enum rtx_code code, rtx *operands)
3274 const char *func;
3276 switch (code)
3278 case PLUS:
3279 func = "_Qp_add";
3280 break;
3281 case MINUS:
3282 func = "_Qp_sub";
3283 break;
3284 case MULT:
3285 func = "_Qp_mul";
3286 break;
3287 case DIV:
3288 func = "_Qp_div";
3289 break;
3290 default:
3291 gcc_unreachable ();
3294 emit_soft_tfmode_libcall (func, 3, operands);
3297 static void
3298 emit_soft_tfmode_unop (enum rtx_code code, rtx *operands)
3300 const char *func;
3302 gcc_assert (code == SQRT);
3303 func = "_Qp_sqrt";
3305 emit_soft_tfmode_libcall (func, 2, operands);
3308 static void
3309 emit_soft_tfmode_cvt (enum rtx_code code, rtx *operands)
3311 const char *func;
3313 switch (code)
3315 case FLOAT_EXTEND:
3316 switch (GET_MODE (operands[1]))
3318 case SFmode:
3319 func = "_Qp_stoq";
3320 break;
3321 case DFmode:
3322 func = "_Qp_dtoq";
3323 break;
3324 default:
3325 gcc_unreachable ();
3327 break;
3329 case FLOAT_TRUNCATE:
3330 switch (GET_MODE (operands[0]))
3332 case SFmode:
3333 func = "_Qp_qtos";
3334 break;
3335 case DFmode:
3336 func = "_Qp_qtod";
3337 break;
3338 default:
3339 gcc_unreachable ();
3341 break;
3343 case FLOAT:
3344 switch (GET_MODE (operands[1]))
3346 case SImode:
3347 func = "_Qp_itoq";
3348 if (TARGET_ARCH64)
3349 operands[1] = gen_rtx_SIGN_EXTEND (DImode, operands[1]);
3350 break;
3351 case DImode:
3352 func = "_Qp_xtoq";
3353 break;
3354 default:
3355 gcc_unreachable ();
3357 break;
3359 case UNSIGNED_FLOAT:
3360 switch (GET_MODE (operands[1]))
3362 case SImode:
3363 func = "_Qp_uitoq";
3364 if (TARGET_ARCH64)
3365 operands[1] = gen_rtx_ZERO_EXTEND (DImode, operands[1]);
3366 break;
3367 case DImode:
3368 func = "_Qp_uxtoq";
3369 break;
3370 default:
3371 gcc_unreachable ();
3373 break;
3375 case FIX:
3376 switch (GET_MODE (operands[0]))
3378 case SImode:
3379 func = "_Qp_qtoi";
3380 break;
3381 case DImode:
3382 func = "_Qp_qtox";
3383 break;
3384 default:
3385 gcc_unreachable ();
3387 break;
3389 case UNSIGNED_FIX:
3390 switch (GET_MODE (operands[0]))
3392 case SImode:
3393 func = "_Qp_qtoui";
3394 break;
3395 case DImode:
3396 func = "_Qp_qtoux";
3397 break;
3398 default:
3399 gcc_unreachable ();
3401 break;
3403 default:
3404 gcc_unreachable ();
3407 emit_soft_tfmode_libcall (func, 2, operands);
3410 /* Expand a hard-float tfmode operation. All arguments must be in
3411 registers. */
3413 static void
3414 emit_hard_tfmode_operation (enum rtx_code code, rtx *operands)
3416 rtx op, dest;
3418 if (GET_RTX_CLASS (code) == RTX_UNARY)
3420 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
3421 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
3423 else
3425 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
3426 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
3427 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
3428 operands[1], operands[2]);
3431 if (register_operand (operands[0], VOIDmode))
3432 dest = operands[0];
3433 else
3434 dest = gen_reg_rtx (GET_MODE (operands[0]));
3436 emit_insn (gen_rtx_SET (dest, op));
3438 if (dest != operands[0])
3439 emit_move_insn (operands[0], dest);
3442 void
3443 emit_tfmode_binop (enum rtx_code code, rtx *operands)
3445 if (TARGET_HARD_QUAD)
3446 emit_hard_tfmode_operation (code, operands);
3447 else
3448 emit_soft_tfmode_binop (code, operands);
3451 void
3452 emit_tfmode_unop (enum rtx_code code, rtx *operands)
3454 if (TARGET_HARD_QUAD)
3455 emit_hard_tfmode_operation (code, operands);
3456 else
3457 emit_soft_tfmode_unop (code, operands);
3460 void
3461 emit_tfmode_cvt (enum rtx_code code, rtx *operands)
3463 if (TARGET_HARD_QUAD)
3464 emit_hard_tfmode_operation (code, operands);
3465 else
3466 emit_soft_tfmode_cvt (code, operands);
3469 /* Return nonzero if a branch/jump/call instruction will be emitting
3470 nop into its delay slot. */
3473 empty_delay_slot (rtx_insn *insn)
3475 rtx seq;
3477 /* If no previous instruction (should not happen), return true. */
3478 if (PREV_INSN (insn) == NULL)
3479 return 1;
3481 seq = NEXT_INSN (PREV_INSN (insn));
3482 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
3483 return 0;
3485 return 1;
3488 /* Return nonzero if we should emit a nop after a cbcond instruction.
3489 The cbcond instruction does not have a delay slot, however there is
3490 a severe performance penalty if a control transfer appears right
3491 after a cbcond. Therefore we emit a nop when we detect this
3492 situation. */
3495 emit_cbcond_nop (rtx_insn *insn)
3497 rtx next = next_active_insn (insn);
3499 if (!next)
3500 return 1;
3502 if (NONJUMP_INSN_P (next)
3503 && GET_CODE (PATTERN (next)) == SEQUENCE)
3504 next = XVECEXP (PATTERN (next), 0, 0);
3505 else if (CALL_P (next)
3506 && GET_CODE (PATTERN (next)) == PARALLEL)
3508 rtx delay = XVECEXP (PATTERN (next), 0, 1);
3510 if (GET_CODE (delay) == RETURN)
3512 /* It's a sibling call. Do not emit the nop if we're going
3513 to emit something other than the jump itself as the first
3514 instruction of the sibcall sequence. */
3515 if (sparc_leaf_function_p || TARGET_FLAT)
3516 return 0;
3520 if (NONJUMP_INSN_P (next))
3521 return 0;
3523 return 1;
3526 /* Return nonzero if TRIAL can go into the call delay slot. */
3529 eligible_for_call_delay (rtx_insn *trial)
3531 rtx pat;
3533 if (get_attr_in_branch_delay (trial) == IN_BRANCH_DELAY_FALSE)
3534 return 0;
3536 /* Binutils allows
3537 call __tls_get_addr, %tgd_call (foo)
3538 add %l7, %o0, %o0, %tgd_add (foo)
3539 while Sun as/ld does not. */
3540 if (TARGET_GNU_TLS || !TARGET_TLS)
3541 return 1;
3543 pat = PATTERN (trial);
3545 /* We must reject tgd_add{32|64}, i.e.
3546 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSGD)))
3547 and tldm_add{32|64}, i.e.
3548 (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSLDM)))
3549 for Sun as/ld. */
3550 if (GET_CODE (pat) == SET
3551 && GET_CODE (SET_SRC (pat)) == PLUS)
3553 rtx unspec = XEXP (SET_SRC (pat), 1);
3555 if (GET_CODE (unspec) == UNSPEC
3556 && (XINT (unspec, 1) == UNSPEC_TLSGD
3557 || XINT (unspec, 1) == UNSPEC_TLSLDM))
3558 return 0;
3561 return 1;
3564 /* Return nonzero if TRIAL, an insn, can be combined with a 'restore'
3565 instruction. RETURN_P is true if the v9 variant 'return' is to be
3566 considered in the test too.
3568 TRIAL must be a SET whose destination is a REG appropriate for the
3569 'restore' instruction or, if RETURN_P is true, for the 'return'
3570 instruction. */
3572 static int
3573 eligible_for_restore_insn (rtx trial, bool return_p)
3575 rtx pat = PATTERN (trial);
3576 rtx src = SET_SRC (pat);
3577 bool src_is_freg = false;
3578 rtx src_reg;
3580 /* Since we now can do moves between float and integer registers when
3581 VIS3 is enabled, we have to catch this case. We can allow such
3582 moves when doing a 'return' however. */
3583 src_reg = src;
3584 if (GET_CODE (src_reg) == SUBREG)
3585 src_reg = SUBREG_REG (src_reg);
3586 if (GET_CODE (src_reg) == REG
3587 && SPARC_FP_REG_P (REGNO (src_reg)))
3588 src_is_freg = true;
3590 /* The 'restore src,%g0,dest' pattern for word mode and below. */
3591 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3592 && arith_operand (src, GET_MODE (src))
3593 && ! src_is_freg)
3595 if (TARGET_ARCH64)
3596 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3597 else
3598 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
3601 /* The 'restore src,%g0,dest' pattern for double-word mode. */
3602 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3603 && arith_double_operand (src, GET_MODE (src))
3604 && ! src_is_freg)
3605 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3607 /* The 'restore src,%g0,dest' pattern for float if no FPU. */
3608 else if (! TARGET_FPU && register_operand (src, SFmode))
3609 return 1;
3611 /* The 'restore src,%g0,dest' pattern for double if no FPU. */
3612 else if (! TARGET_FPU && TARGET_ARCH64 && register_operand (src, DFmode))
3613 return 1;
3615 /* If we have the 'return' instruction, anything that does not use
3616 local or output registers and can go into a delay slot wins. */
3617 else if (return_p && TARGET_V9 && !epilogue_renumber (&pat, 1))
3618 return 1;
3620 /* The 'restore src1,src2,dest' pattern for SImode. */
3621 else if (GET_CODE (src) == PLUS
3622 && register_operand (XEXP (src, 0), SImode)
3623 && arith_operand (XEXP (src, 1), SImode))
3624 return 1;
3626 /* The 'restore src1,src2,dest' pattern for DImode. */
3627 else if (GET_CODE (src) == PLUS
3628 && register_operand (XEXP (src, 0), DImode)
3629 && arith_double_operand (XEXP (src, 1), DImode))
3630 return 1;
3632 /* The 'restore src1,%lo(src2),dest' pattern. */
3633 else if (GET_CODE (src) == LO_SUM
3634 && ! TARGET_CM_MEDMID
3635 && ((register_operand (XEXP (src, 0), SImode)
3636 && immediate_operand (XEXP (src, 1), SImode))
3637 || (TARGET_ARCH64
3638 && register_operand (XEXP (src, 0), DImode)
3639 && immediate_operand (XEXP (src, 1), DImode))))
3640 return 1;
3642 /* The 'restore src,src,dest' pattern. */
3643 else if (GET_CODE (src) == ASHIFT
3644 && (register_operand (XEXP (src, 0), SImode)
3645 || register_operand (XEXP (src, 0), DImode))
3646 && XEXP (src, 1) == const1_rtx)
3647 return 1;
3649 return 0;
3652 /* Return nonzero if TRIAL can go into the function return's delay slot. */
3655 eligible_for_return_delay (rtx_insn *trial)
3657 int regno;
3658 rtx pat;
3660 /* If the function uses __builtin_eh_return, the eh_return machinery
3661 occupies the delay slot. */
3662 if (crtl->calls_eh_return)
3663 return 0;
3665 if (get_attr_in_branch_delay (trial) == IN_BRANCH_DELAY_FALSE)
3666 return 0;
3668 /* In the case of a leaf or flat function, anything can go into the slot. */
3669 if (sparc_leaf_function_p || TARGET_FLAT)
3670 return 1;
3672 if (!NONJUMP_INSN_P (trial))
3673 return 0;
3675 pat = PATTERN (trial);
3676 if (GET_CODE (pat) == PARALLEL)
3678 int i;
3680 if (! TARGET_V9)
3681 return 0;
3682 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
3684 rtx expr = XVECEXP (pat, 0, i);
3685 if (GET_CODE (expr) != SET)
3686 return 0;
3687 if (GET_CODE (SET_DEST (expr)) != REG)
3688 return 0;
3689 regno = REGNO (SET_DEST (expr));
3690 if (regno >= 8 && regno < 24)
3691 return 0;
3693 return !epilogue_renumber (&pat, 1);
3696 if (GET_CODE (pat) != SET)
3697 return 0;
3699 if (GET_CODE (SET_DEST (pat)) != REG)
3700 return 0;
3702 regno = REGNO (SET_DEST (pat));
3704 /* Otherwise, only operations which can be done in tandem with
3705 a `restore' or `return' insn can go into the delay slot. */
3706 if (regno >= 8 && regno < 24)
3707 return 0;
3709 /* If this instruction sets up floating point register and we have a return
3710 instruction, it can probably go in. But restore will not work
3711 with FP_REGS. */
3712 if (! SPARC_INT_REG_P (regno))
3713 return TARGET_V9 && !epilogue_renumber (&pat, 1);
3715 return eligible_for_restore_insn (trial, true);
3718 /* Return nonzero if TRIAL can go into the sibling call's delay slot. */
3721 eligible_for_sibcall_delay (rtx_insn *trial)
3723 rtx pat;
3725 if (get_attr_in_branch_delay (trial) == IN_BRANCH_DELAY_FALSE)
3726 return 0;
3728 if (!NONJUMP_INSN_P (trial))
3729 return 0;
3731 pat = PATTERN (trial);
3733 if (sparc_leaf_function_p || TARGET_FLAT)
3735 /* If the tail call is done using the call instruction,
3736 we have to restore %o7 in the delay slot. */
3737 if (LEAF_SIBCALL_SLOT_RESERVED_P)
3738 return 0;
3740 /* %g1 is used to build the function address */
3741 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
3742 return 0;
3744 return 1;
3747 if (GET_CODE (pat) != SET)
3748 return 0;
3750 /* Otherwise, only operations which can be done in tandem with
3751 a `restore' insn can go into the delay slot. */
3752 if (GET_CODE (SET_DEST (pat)) != REG
3753 || (REGNO (SET_DEST (pat)) >= 8 && REGNO (SET_DEST (pat)) < 24)
3754 || ! SPARC_INT_REG_P (REGNO (SET_DEST (pat))))
3755 return 0;
3757 /* If it mentions %o7, it can't go in, because sibcall will clobber it
3758 in most cases. */
3759 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
3760 return 0;
3762 return eligible_for_restore_insn (trial, false);
3765 /* Determine if it's legal to put X into the constant pool. This
3766 is not possible if X contains the address of a symbol that is
3767 not constant (TLS) or not known at final link time (PIC). */
3769 static bool
3770 sparc_cannot_force_const_mem (machine_mode mode, rtx x)
3772 switch (GET_CODE (x))
3774 case CONST_INT:
3775 case CONST_WIDE_INT:
3776 case CONST_DOUBLE:
3777 case CONST_VECTOR:
3778 /* Accept all non-symbolic constants. */
3779 return false;
3781 case LABEL_REF:
3782 /* Labels are OK iff we are non-PIC. */
3783 return flag_pic != 0;
3785 case SYMBOL_REF:
3786 /* 'Naked' TLS symbol references are never OK,
3787 non-TLS symbols are OK iff we are non-PIC. */
3788 if (SYMBOL_REF_TLS_MODEL (x))
3789 return true;
3790 else
3791 return flag_pic != 0;
3793 case CONST:
3794 return sparc_cannot_force_const_mem (mode, XEXP (x, 0));
3795 case PLUS:
3796 case MINUS:
3797 return sparc_cannot_force_const_mem (mode, XEXP (x, 0))
3798 || sparc_cannot_force_const_mem (mode, XEXP (x, 1));
3799 case UNSPEC:
3800 return true;
3801 default:
3802 gcc_unreachable ();
3806 /* Global Offset Table support. */
3807 static GTY(()) rtx got_helper_rtx = NULL_RTX;
3808 static GTY(()) rtx global_offset_table_rtx = NULL_RTX;
3810 /* Return the SYMBOL_REF for the Global Offset Table. */
3812 static GTY(()) rtx sparc_got_symbol = NULL_RTX;
3814 static rtx
3815 sparc_got (void)
3817 if (!sparc_got_symbol)
3818 sparc_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3820 return sparc_got_symbol;
3823 /* Ensure that we are not using patterns that are not OK with PIC. */
3826 check_pic (int i)
3828 rtx op;
3830 switch (flag_pic)
3832 case 1:
3833 op = recog_data.operand[i];
3834 gcc_assert (GET_CODE (op) != SYMBOL_REF
3835 && (GET_CODE (op) != CONST
3836 || (GET_CODE (XEXP (op, 0)) == MINUS
3837 && XEXP (XEXP (op, 0), 0) == sparc_got ()
3838 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST)));
3839 /* fallthrough */
3840 case 2:
3841 default:
3842 return 1;
3846 /* Return true if X is an address which needs a temporary register when
3847 reloaded while generating PIC code. */
3850 pic_address_needs_scratch (rtx x)
3852 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
3853 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3854 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
3855 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3856 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
3857 return 1;
3859 return 0;
3862 /* Determine if a given RTX is a valid constant. We already know this
3863 satisfies CONSTANT_P. */
3865 static bool
3866 sparc_legitimate_constant_p (machine_mode mode, rtx x)
3868 switch (GET_CODE (x))
3870 case CONST:
3871 case SYMBOL_REF:
3872 if (sparc_tls_referenced_p (x))
3873 return false;
3874 break;
3876 case CONST_DOUBLE:
3877 /* Floating point constants are generally not ok.
3878 The only exception is 0.0 and all-ones in VIS. */
3879 if (TARGET_VIS
3880 && SCALAR_FLOAT_MODE_P (mode)
3881 && (const_zero_operand (x, mode)
3882 || const_all_ones_operand (x, mode)))
3883 return true;
3885 return false;
3887 case CONST_VECTOR:
3888 /* Vector constants are generally not ok.
3889 The only exception is 0 or -1 in VIS. */
3890 if (TARGET_VIS
3891 && (const_zero_operand (x, mode)
3892 || const_all_ones_operand (x, mode)))
3893 return true;
3895 return false;
3897 default:
3898 break;
3901 return true;
3904 /* Determine if a given RTX is a valid constant address. */
3906 bool
3907 constant_address_p (rtx x)
3909 switch (GET_CODE (x))
3911 case LABEL_REF:
3912 case CONST_INT:
3913 case HIGH:
3914 return true;
3916 case CONST:
3917 if (flag_pic && pic_address_needs_scratch (x))
3918 return false;
3919 return sparc_legitimate_constant_p (Pmode, x);
3921 case SYMBOL_REF:
3922 return !flag_pic && sparc_legitimate_constant_p (Pmode, x);
3924 default:
3925 return false;
3929 /* Nonzero if the constant value X is a legitimate general operand
3930 when generating PIC code. It is given that flag_pic is on and
3931 that X satisfies CONSTANT_P. */
3933 bool
3934 legitimate_pic_operand_p (rtx x)
3936 if (pic_address_needs_scratch (x))
3937 return false;
3938 if (sparc_tls_referenced_p (x))
3939 return false;
3940 return true;
3943 #define RTX_OK_FOR_OFFSET_P(X, MODE) \
3944 (CONST_INT_P (X) \
3945 && INTVAL (X) >= -0x1000 \
3946 && INTVAL (X) <= (0x1000 - GET_MODE_SIZE (MODE)))
3948 #define RTX_OK_FOR_OLO10_P(X, MODE) \
3949 (CONST_INT_P (X) \
3950 && INTVAL (X) >= -0x1000 \
3951 && INTVAL (X) <= (0xc00 - GET_MODE_SIZE (MODE)))
3953 /* Handle the TARGET_LEGITIMATE_ADDRESS_P target hook.
3955 On SPARC, the actual legitimate addresses must be REG+REG or REG+SMALLINT
3956 ordinarily. This changes a bit when generating PIC. */
3958 static bool
3959 sparc_legitimate_address_p (machine_mode mode, rtx addr, bool strict)
3961 rtx rs1 = NULL, rs2 = NULL, imm1 = NULL;
3963 if (REG_P (addr) || GET_CODE (addr) == SUBREG)
3964 rs1 = addr;
3965 else if (GET_CODE (addr) == PLUS)
3967 rs1 = XEXP (addr, 0);
3968 rs2 = XEXP (addr, 1);
3970 /* Canonicalize. REG comes first, if there are no regs,
3971 LO_SUM comes first. */
3972 if (!REG_P (rs1)
3973 && GET_CODE (rs1) != SUBREG
3974 && (REG_P (rs2)
3975 || GET_CODE (rs2) == SUBREG
3976 || (GET_CODE (rs2) == LO_SUM && GET_CODE (rs1) != LO_SUM)))
3978 rs1 = XEXP (addr, 1);
3979 rs2 = XEXP (addr, 0);
3982 if ((flag_pic == 1
3983 && rs1 == pic_offset_table_rtx
3984 && !REG_P (rs2)
3985 && GET_CODE (rs2) != SUBREG
3986 && GET_CODE (rs2) != LO_SUM
3987 && GET_CODE (rs2) != MEM
3988 && !(GET_CODE (rs2) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs2))
3989 && (! symbolic_operand (rs2, VOIDmode) || mode == Pmode)
3990 && (GET_CODE (rs2) != CONST_INT || SMALL_INT (rs2)))
3991 || ((REG_P (rs1)
3992 || GET_CODE (rs1) == SUBREG)
3993 && RTX_OK_FOR_OFFSET_P (rs2, mode)))
3995 imm1 = rs2;
3996 rs2 = NULL;
3998 else if ((REG_P (rs1) || GET_CODE (rs1) == SUBREG)
3999 && (REG_P (rs2) || GET_CODE (rs2) == SUBREG))
4001 /* We prohibit REG + REG for TFmode when there are no quad move insns
4002 and we consequently need to split. We do this because REG+REG
4003 is not an offsettable address. If we get the situation in reload
4004 where source and destination of a movtf pattern are both MEMs with
4005 REG+REG address, then only one of them gets converted to an
4006 offsettable address. */
4007 if (mode == TFmode
4008 && ! (TARGET_ARCH64 && TARGET_HARD_QUAD))
4009 return 0;
4011 /* Likewise for TImode, but in all cases. */
4012 if (mode == TImode)
4013 return 0;
4015 /* We prohibit REG + REG on ARCH32 if not optimizing for
4016 DFmode/DImode because then mem_min_alignment is likely to be zero
4017 after reload and the forced split would lack a matching splitter
4018 pattern. */
4019 if (TARGET_ARCH32 && !optimize
4020 && (mode == DFmode || mode == DImode))
4021 return 0;
4023 else if (USE_AS_OFFSETABLE_LO10
4024 && GET_CODE (rs1) == LO_SUM
4025 && TARGET_ARCH64
4026 && ! TARGET_CM_MEDMID
4027 && RTX_OK_FOR_OLO10_P (rs2, mode))
4029 rs2 = NULL;
4030 imm1 = XEXP (rs1, 1);
4031 rs1 = XEXP (rs1, 0);
4032 if (!CONSTANT_P (imm1)
4033 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
4034 return 0;
4037 else if (GET_CODE (addr) == LO_SUM)
4039 rs1 = XEXP (addr, 0);
4040 imm1 = XEXP (addr, 1);
4042 if (!CONSTANT_P (imm1)
4043 || (GET_CODE (rs1) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (rs1)))
4044 return 0;
4046 /* We can't allow TFmode in 32-bit mode, because an offset greater
4047 than the alignment (8) may cause the LO_SUM to overflow. */
4048 if (mode == TFmode && TARGET_ARCH32)
4049 return 0;
4051 /* During reload, accept the HIGH+LO_SUM construct generated by
4052 sparc_legitimize_reload_address. */
4053 if (reload_in_progress
4054 && GET_CODE (rs1) == HIGH
4055 && XEXP (rs1, 0) == imm1)
4056 return 1;
4058 else if (GET_CODE (addr) == CONST_INT && SMALL_INT (addr))
4059 return 1;
4060 else
4061 return 0;
4063 if (GET_CODE (rs1) == SUBREG)
4064 rs1 = SUBREG_REG (rs1);
4065 if (!REG_P (rs1))
4066 return 0;
4068 if (rs2)
4070 if (GET_CODE (rs2) == SUBREG)
4071 rs2 = SUBREG_REG (rs2);
4072 if (!REG_P (rs2))
4073 return 0;
4076 if (strict)
4078 if (!REGNO_OK_FOR_BASE_P (REGNO (rs1))
4079 || (rs2 && !REGNO_OK_FOR_BASE_P (REGNO (rs2))))
4080 return 0;
4082 else
4084 if ((! SPARC_INT_REG_P (REGNO (rs1))
4085 && REGNO (rs1) != FRAME_POINTER_REGNUM
4086 && REGNO (rs1) < FIRST_PSEUDO_REGISTER)
4087 || (rs2
4088 && (! SPARC_INT_REG_P (REGNO (rs2))
4089 && REGNO (rs2) != FRAME_POINTER_REGNUM
4090 && REGNO (rs2) < FIRST_PSEUDO_REGISTER)))
4091 return 0;
4093 return 1;
4096 /* Return the SYMBOL_REF for the tls_get_addr function. */
4098 static GTY(()) rtx sparc_tls_symbol = NULL_RTX;
4100 static rtx
4101 sparc_tls_get_addr (void)
4103 if (!sparc_tls_symbol)
4104 sparc_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, "__tls_get_addr");
4106 return sparc_tls_symbol;
4109 /* Return the Global Offset Table to be used in TLS mode. */
4111 static rtx
4112 sparc_tls_got (void)
4114 /* In PIC mode, this is just the PIC offset table. */
4115 if (flag_pic)
4117 crtl->uses_pic_offset_table = 1;
4118 return pic_offset_table_rtx;
4121 /* In non-PIC mode, Sun as (unlike GNU as) emits PC-relative relocations for
4122 the GOT symbol with the 32-bit ABI, so we reload the GOT register. */
4123 if (TARGET_SUN_TLS && TARGET_ARCH32)
4125 load_got_register ();
4126 return global_offset_table_rtx;
4129 /* In all other cases, we load a new pseudo with the GOT symbol. */
4130 return copy_to_reg (sparc_got ());
4133 /* Return true if X contains a thread-local symbol. */
4135 static bool
4136 sparc_tls_referenced_p (rtx x)
4138 if (!TARGET_HAVE_TLS)
4139 return false;
4141 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
4142 x = XEXP (XEXP (x, 0), 0);
4144 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x))
4145 return true;
4147 /* That's all we handle in sparc_legitimize_tls_address for now. */
4148 return false;
4151 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
4152 this (thread-local) address. */
4154 static rtx
4155 sparc_legitimize_tls_address (rtx addr)
4157 rtx temp1, temp2, temp3, ret, o0, got;
4158 rtx_insn *insn;
4160 gcc_assert (can_create_pseudo_p ());
4162 if (GET_CODE (addr) == SYMBOL_REF)
4163 switch (SYMBOL_REF_TLS_MODEL (addr))
4165 case TLS_MODEL_GLOBAL_DYNAMIC:
4166 start_sequence ();
4167 temp1 = gen_reg_rtx (SImode);
4168 temp2 = gen_reg_rtx (SImode);
4169 ret = gen_reg_rtx (Pmode);
4170 o0 = gen_rtx_REG (Pmode, 8);
4171 got = sparc_tls_got ();
4172 emit_insn (gen_tgd_hi22 (temp1, addr));
4173 emit_insn (gen_tgd_lo10 (temp2, temp1, addr));
4174 if (TARGET_ARCH32)
4176 emit_insn (gen_tgd_add32 (o0, got, temp2, addr));
4177 insn = emit_call_insn (gen_tgd_call32 (o0, sparc_tls_get_addr (),
4178 addr, const1_rtx));
4180 else
4182 emit_insn (gen_tgd_add64 (o0, got, temp2, addr));
4183 insn = emit_call_insn (gen_tgd_call64 (o0, sparc_tls_get_addr (),
4184 addr, const1_rtx));
4186 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), o0);
4187 insn = get_insns ();
4188 end_sequence ();
4189 emit_libcall_block (insn, ret, o0, addr);
4190 break;
4192 case TLS_MODEL_LOCAL_DYNAMIC:
4193 start_sequence ();
4194 temp1 = gen_reg_rtx (SImode);
4195 temp2 = gen_reg_rtx (SImode);
4196 temp3 = gen_reg_rtx (Pmode);
4197 ret = gen_reg_rtx (Pmode);
4198 o0 = gen_rtx_REG (Pmode, 8);
4199 got = sparc_tls_got ();
4200 emit_insn (gen_tldm_hi22 (temp1));
4201 emit_insn (gen_tldm_lo10 (temp2, temp1));
4202 if (TARGET_ARCH32)
4204 emit_insn (gen_tldm_add32 (o0, got, temp2));
4205 insn = emit_call_insn (gen_tldm_call32 (o0, sparc_tls_get_addr (),
4206 const1_rtx));
4208 else
4210 emit_insn (gen_tldm_add64 (o0, got, temp2));
4211 insn = emit_call_insn (gen_tldm_call64 (o0, sparc_tls_get_addr (),
4212 const1_rtx));
4214 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), o0);
4215 insn = get_insns ();
4216 end_sequence ();
4217 emit_libcall_block (insn, temp3, o0,
4218 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
4219 UNSPEC_TLSLD_BASE));
4220 temp1 = gen_reg_rtx (SImode);
4221 temp2 = gen_reg_rtx (SImode);
4222 emit_insn (gen_tldo_hix22 (temp1, addr));
4223 emit_insn (gen_tldo_lox10 (temp2, temp1, addr));
4224 if (TARGET_ARCH32)
4225 emit_insn (gen_tldo_add32 (ret, temp3, temp2, addr));
4226 else
4227 emit_insn (gen_tldo_add64 (ret, temp3, temp2, addr));
4228 break;
4230 case TLS_MODEL_INITIAL_EXEC:
4231 temp1 = gen_reg_rtx (SImode);
4232 temp2 = gen_reg_rtx (SImode);
4233 temp3 = gen_reg_rtx (Pmode);
4234 got = sparc_tls_got ();
4235 emit_insn (gen_tie_hi22 (temp1, addr));
4236 emit_insn (gen_tie_lo10 (temp2, temp1, addr));
4237 if (TARGET_ARCH32)
4238 emit_insn (gen_tie_ld32 (temp3, got, temp2, addr));
4239 else
4240 emit_insn (gen_tie_ld64 (temp3, got, temp2, addr));
4241 if (TARGET_SUN_TLS)
4243 ret = gen_reg_rtx (Pmode);
4244 if (TARGET_ARCH32)
4245 emit_insn (gen_tie_add32 (ret, gen_rtx_REG (Pmode, 7),
4246 temp3, addr));
4247 else
4248 emit_insn (gen_tie_add64 (ret, gen_rtx_REG (Pmode, 7),
4249 temp3, addr));
4251 else
4252 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp3);
4253 break;
4255 case TLS_MODEL_LOCAL_EXEC:
4256 temp1 = gen_reg_rtx (Pmode);
4257 temp2 = gen_reg_rtx (Pmode);
4258 if (TARGET_ARCH32)
4260 emit_insn (gen_tle_hix22_sp32 (temp1, addr));
4261 emit_insn (gen_tle_lox10_sp32 (temp2, temp1, addr));
4263 else
4265 emit_insn (gen_tle_hix22_sp64 (temp1, addr));
4266 emit_insn (gen_tle_lox10_sp64 (temp2, temp1, addr));
4268 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, 7), temp2);
4269 break;
4271 default:
4272 gcc_unreachable ();
4275 else if (GET_CODE (addr) == CONST)
4277 rtx base, offset;
4279 gcc_assert (GET_CODE (XEXP (addr, 0)) == PLUS);
4281 base = sparc_legitimize_tls_address (XEXP (XEXP (addr, 0), 0));
4282 offset = XEXP (XEXP (addr, 0), 1);
4284 base = force_operand (base, NULL_RTX);
4285 if (!(GET_CODE (offset) == CONST_INT && SMALL_INT (offset)))
4286 offset = force_reg (Pmode, offset);
4287 ret = gen_rtx_PLUS (Pmode, base, offset);
4290 else
4291 gcc_unreachable (); /* for now ... */
4293 return ret;
4296 /* Legitimize PIC addresses. If the address is already position-independent,
4297 we return ORIG. Newly generated position-independent addresses go into a
4298 reg. This is REG if nonzero, otherwise we allocate register(s) as
4299 necessary. */
4301 static rtx
4302 sparc_legitimize_pic_address (rtx orig, rtx reg)
4304 bool gotdata_op = false;
4306 if (GET_CODE (orig) == SYMBOL_REF
4307 /* See the comment in sparc_expand_move. */
4308 || (GET_CODE (orig) == LABEL_REF && !can_use_mov_pic_label_ref (orig)))
4310 rtx pic_ref, address;
4311 rtx_insn *insn;
4313 if (reg == 0)
4315 gcc_assert (can_create_pseudo_p ());
4316 reg = gen_reg_rtx (Pmode);
4319 if (flag_pic == 2)
4321 /* If not during reload, allocate another temp reg here for loading
4322 in the address, so that these instructions can be optimized
4323 properly. */
4324 rtx temp_reg = (! can_create_pseudo_p ()
4325 ? reg : gen_reg_rtx (Pmode));
4327 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
4328 won't get confused into thinking that these two instructions
4329 are loading in the true address of the symbol. If in the
4330 future a PIC rtx exists, that should be used instead. */
4331 if (TARGET_ARCH64)
4333 emit_insn (gen_movdi_high_pic (temp_reg, orig));
4334 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
4336 else
4338 emit_insn (gen_movsi_high_pic (temp_reg, orig));
4339 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
4341 address = temp_reg;
4342 gotdata_op = true;
4344 else
4345 address = orig;
4347 crtl->uses_pic_offset_table = 1;
4348 if (gotdata_op)
4350 if (TARGET_ARCH64)
4351 insn = emit_insn (gen_movdi_pic_gotdata_op (reg,
4352 pic_offset_table_rtx,
4353 address, orig));
4354 else
4355 insn = emit_insn (gen_movsi_pic_gotdata_op (reg,
4356 pic_offset_table_rtx,
4357 address, orig));
4359 else
4361 pic_ref
4362 = gen_const_mem (Pmode,
4363 gen_rtx_PLUS (Pmode,
4364 pic_offset_table_rtx, address));
4365 insn = emit_move_insn (reg, pic_ref);
4368 /* Put a REG_EQUAL note on this insn, so that it can be optimized
4369 by loop. */
4370 set_unique_reg_note (insn, REG_EQUAL, orig);
4371 return reg;
4373 else if (GET_CODE (orig) == CONST)
4375 rtx base, offset;
4377 if (GET_CODE (XEXP (orig, 0)) == PLUS
4378 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
4379 return orig;
4381 if (reg == 0)
4383 gcc_assert (can_create_pseudo_p ());
4384 reg = gen_reg_rtx (Pmode);
4387 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
4388 base = sparc_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), reg);
4389 offset = sparc_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
4390 base == reg ? NULL_RTX : reg);
4392 if (GET_CODE (offset) == CONST_INT)
4394 if (SMALL_INT (offset))
4395 return plus_constant (Pmode, base, INTVAL (offset));
4396 else if (can_create_pseudo_p ())
4397 offset = force_reg (Pmode, offset);
4398 else
4399 /* If we reach here, then something is seriously wrong. */
4400 gcc_unreachable ();
4402 return gen_rtx_PLUS (Pmode, base, offset);
4404 else if (GET_CODE (orig) == LABEL_REF)
4405 /* ??? We ought to be checking that the register is live instead, in case
4406 it is eliminated. */
4407 crtl->uses_pic_offset_table = 1;
4409 return orig;
4412 /* Try machine-dependent ways of modifying an illegitimate address X
4413 to be legitimate. If we find one, return the new, valid address.
4415 OLDX is the address as it was before break_out_memory_refs was called.
4416 In some cases it is useful to look at this to decide what needs to be done.
4418 MODE is the mode of the operand pointed to by X.
4420 On SPARC, change REG+N into REG+REG, and REG+(X*Y) into REG+REG. */
4422 static rtx
4423 sparc_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
4424 machine_mode mode)
4426 rtx orig_x = x;
4428 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT)
4429 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
4430 force_operand (XEXP (x, 0), NULL_RTX));
4431 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == MULT)
4432 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
4433 force_operand (XEXP (x, 1), NULL_RTX));
4434 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS)
4435 x = gen_rtx_PLUS (Pmode, force_operand (XEXP (x, 0), NULL_RTX),
4436 XEXP (x, 1));
4437 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == PLUS)
4438 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
4439 force_operand (XEXP (x, 1), NULL_RTX));
4441 if (x != orig_x && sparc_legitimate_address_p (mode, x, FALSE))
4442 return x;
4444 if (sparc_tls_referenced_p (x))
4445 x = sparc_legitimize_tls_address (x);
4446 else if (flag_pic)
4447 x = sparc_legitimize_pic_address (x, NULL_RTX);
4448 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 1)))
4449 x = gen_rtx_PLUS (Pmode, XEXP (x, 0),
4450 copy_to_mode_reg (Pmode, XEXP (x, 1)));
4451 else if (GET_CODE (x) == PLUS && CONSTANT_ADDRESS_P (XEXP (x, 0)))
4452 x = gen_rtx_PLUS (Pmode, XEXP (x, 1),
4453 copy_to_mode_reg (Pmode, XEXP (x, 0)));
4454 else if (GET_CODE (x) == SYMBOL_REF
4455 || GET_CODE (x) == CONST
4456 || GET_CODE (x) == LABEL_REF)
4457 x = copy_to_suggested_reg (x, NULL_RTX, Pmode);
4459 return x;
4462 /* Delegitimize an address that was legitimized by the above function. */
4464 static rtx
4465 sparc_delegitimize_address (rtx x)
4467 x = delegitimize_mem_from_attrs (x);
4469 if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 1)) == UNSPEC)
4470 switch (XINT (XEXP (x, 1), 1))
4472 case UNSPEC_MOVE_PIC:
4473 case UNSPEC_TLSLE:
4474 x = XVECEXP (XEXP (x, 1), 0, 0);
4475 gcc_assert (GET_CODE (x) == SYMBOL_REF);
4476 break;
4477 default:
4478 break;
4481 /* This is generated by mov{si,di}_pic_label_ref in PIC mode. */
4482 if (GET_CODE (x) == MINUS
4483 && REG_P (XEXP (x, 0))
4484 && REGNO (XEXP (x, 0)) == PIC_OFFSET_TABLE_REGNUM
4485 && GET_CODE (XEXP (x, 1)) == LO_SUM
4486 && GET_CODE (XEXP (XEXP (x, 1), 1)) == UNSPEC
4487 && XINT (XEXP (XEXP (x, 1), 1), 1) == UNSPEC_MOVE_PIC_LABEL)
4489 x = XVECEXP (XEXP (XEXP (x, 1), 1), 0, 0);
4490 gcc_assert (GET_CODE (x) == LABEL_REF);
4493 return x;
4496 /* SPARC implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
4497 replace the input X, or the original X if no replacement is called for.
4498 The output parameter *WIN is 1 if the calling macro should goto WIN,
4499 0 if it should not.
4501 For SPARC, we wish to handle addresses by splitting them into
4502 HIGH+LO_SUM pairs, retaining the LO_SUM in the memory reference.
4503 This cuts the number of extra insns by one.
4505 Do nothing when generating PIC code and the address is a symbolic
4506 operand or requires a scratch register. */
4509 sparc_legitimize_reload_address (rtx x, machine_mode mode,
4510 int opnum, int type,
4511 int ind_levels ATTRIBUTE_UNUSED, int *win)
4513 /* Decompose SImode constants into HIGH+LO_SUM. */
4514 if (CONSTANT_P (x)
4515 && (mode != TFmode || TARGET_ARCH64)
4516 && GET_MODE (x) == SImode
4517 && GET_CODE (x) != LO_SUM
4518 && GET_CODE (x) != HIGH
4519 && sparc_cmodel <= CM_MEDLOW
4520 && !(flag_pic
4521 && (symbolic_operand (x, Pmode) || pic_address_needs_scratch (x))))
4523 x = gen_rtx_LO_SUM (GET_MODE (x), gen_rtx_HIGH (GET_MODE (x), x), x);
4524 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
4525 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
4526 opnum, (enum reload_type)type);
4527 *win = 1;
4528 return x;
4531 /* We have to recognize what we have already generated above. */
4532 if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == HIGH)
4534 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
4535 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
4536 opnum, (enum reload_type)type);
4537 *win = 1;
4538 return x;
4541 *win = 0;
4542 return x;
4545 /* Return true if ADDR (a legitimate address expression)
4546 has an effect that depends on the machine mode it is used for.
4548 In PIC mode,
4550 (mem:HI [%l7+a])
4552 is not equivalent to
4554 (mem:QI [%l7+a]) (mem:QI [%l7+a+1])
4556 because [%l7+a+1] is interpreted as the address of (a+1). */
4559 static bool
4560 sparc_mode_dependent_address_p (const_rtx addr,
4561 addr_space_t as ATTRIBUTE_UNUSED)
4563 if (flag_pic && GET_CODE (addr) == PLUS)
4565 rtx op0 = XEXP (addr, 0);
4566 rtx op1 = XEXP (addr, 1);
4567 if (op0 == pic_offset_table_rtx
4568 && symbolic_operand (op1, VOIDmode))
4569 return true;
4572 return false;
4575 #ifdef HAVE_GAS_HIDDEN
4576 # define USE_HIDDEN_LINKONCE 1
4577 #else
4578 # define USE_HIDDEN_LINKONCE 0
4579 #endif
4581 static void
4582 get_pc_thunk_name (char name[32], unsigned int regno)
4584 const char *reg_name = reg_names[regno];
4586 /* Skip the leading '%' as that cannot be used in a
4587 symbol name. */
4588 reg_name += 1;
4590 if (USE_HIDDEN_LINKONCE)
4591 sprintf (name, "__sparc_get_pc_thunk.%s", reg_name);
4592 else
4593 ASM_GENERATE_INTERNAL_LABEL (name, "LADDPC", regno);
4596 /* Wrapper around the load_pcrel_sym{si,di} patterns. */
4598 static rtx
4599 gen_load_pcrel_sym (rtx op0, rtx op1, rtx op2, rtx op3)
4601 int orig_flag_pic = flag_pic;
4602 rtx insn;
4604 /* The load_pcrel_sym{si,di} patterns require absolute addressing. */
4605 flag_pic = 0;
4606 if (TARGET_ARCH64)
4607 insn = gen_load_pcrel_symdi (op0, op1, op2, op3);
4608 else
4609 insn = gen_load_pcrel_symsi (op0, op1, op2, op3);
4610 flag_pic = orig_flag_pic;
4612 return insn;
4615 /* Emit code to load the GOT register. */
4617 void
4618 load_got_register (void)
4620 /* In PIC mode, this will retrieve pic_offset_table_rtx. */
4621 if (!global_offset_table_rtx)
4622 global_offset_table_rtx = gen_rtx_REG (Pmode, GLOBAL_OFFSET_TABLE_REGNUM);
4624 if (TARGET_VXWORKS_RTP)
4625 emit_insn (gen_vxworks_load_got ());
4626 else
4628 /* The GOT symbol is subject to a PC-relative relocation so we need a
4629 helper function to add the PC value and thus get the final value. */
4630 if (!got_helper_rtx)
4632 char name[32];
4633 get_pc_thunk_name (name, GLOBAL_OFFSET_TABLE_REGNUM);
4634 got_helper_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
4637 emit_insn (gen_load_pcrel_sym (global_offset_table_rtx, sparc_got (),
4638 got_helper_rtx,
4639 GEN_INT (GLOBAL_OFFSET_TABLE_REGNUM)));
4642 /* Need to emit this whether or not we obey regdecls,
4643 since setjmp/longjmp can cause life info to screw up.
4644 ??? In the case where we don't obey regdecls, this is not sufficient
4645 since we may not fall out the bottom. */
4646 emit_use (global_offset_table_rtx);
4649 /* Emit a call instruction with the pattern given by PAT. ADDR is the
4650 address of the call target. */
4652 void
4653 sparc_emit_call_insn (rtx pat, rtx addr)
4655 rtx_insn *insn;
4657 insn = emit_call_insn (pat);
4659 /* The PIC register is live on entry to VxWorks PIC PLT entries. */
4660 if (TARGET_VXWORKS_RTP
4661 && flag_pic
4662 && GET_CODE (addr) == SYMBOL_REF
4663 && (SYMBOL_REF_DECL (addr)
4664 ? !targetm.binds_local_p (SYMBOL_REF_DECL (addr))
4665 : !SYMBOL_REF_LOCAL_P (addr)))
4667 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
4668 crtl->uses_pic_offset_table = 1;
4672 /* Return 1 if RTX is a MEM which is known to be aligned to at
4673 least a DESIRED byte boundary. */
4676 mem_min_alignment (rtx mem, int desired)
4678 rtx addr, base, offset;
4680 /* If it's not a MEM we can't accept it. */
4681 if (GET_CODE (mem) != MEM)
4682 return 0;
4684 /* Obviously... */
4685 if (!TARGET_UNALIGNED_DOUBLES
4686 && MEM_ALIGN (mem) / BITS_PER_UNIT >= (unsigned)desired)
4687 return 1;
4689 /* ??? The rest of the function predates MEM_ALIGN so
4690 there is probably a bit of redundancy. */
4691 addr = XEXP (mem, 0);
4692 base = offset = NULL_RTX;
4693 if (GET_CODE (addr) == PLUS)
4695 if (GET_CODE (XEXP (addr, 0)) == REG)
4697 base = XEXP (addr, 0);
4699 /* What we are saying here is that if the base
4700 REG is aligned properly, the compiler will make
4701 sure any REG based index upon it will be so
4702 as well. */
4703 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
4704 offset = XEXP (addr, 1);
4705 else
4706 offset = const0_rtx;
4709 else if (GET_CODE (addr) == REG)
4711 base = addr;
4712 offset = const0_rtx;
4715 if (base != NULL_RTX)
4717 int regno = REGNO (base);
4719 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
4721 /* Check if the compiler has recorded some information
4722 about the alignment of the base REG. If reload has
4723 completed, we already matched with proper alignments.
4724 If not running global_alloc, reload might give us
4725 unaligned pointer to local stack though. */
4726 if (((cfun != 0
4727 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
4728 || (optimize && reload_completed))
4729 && (INTVAL (offset) & (desired - 1)) == 0)
4730 return 1;
4732 else
4734 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
4735 return 1;
4738 else if (! TARGET_UNALIGNED_DOUBLES
4739 || CONSTANT_P (addr)
4740 || GET_CODE (addr) == LO_SUM)
4742 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
4743 is true, in which case we can only assume that an access is aligned if
4744 it is to a constant address, or the address involves a LO_SUM. */
4745 return 1;
4748 /* An obviously unaligned address. */
4749 return 0;
4753 /* Vectors to keep interesting information about registers where it can easily
4754 be got. We used to use the actual mode value as the bit number, but there
4755 are more than 32 modes now. Instead we use two tables: one indexed by
4756 hard register number, and one indexed by mode. */
4758 /* The purpose of sparc_mode_class is to shrink the range of modes so that
4759 they all fit (as bit numbers) in a 32-bit word (again). Each real mode is
4760 mapped into one sparc_mode_class mode. */
4762 enum sparc_mode_class {
4763 H_MODE, S_MODE, D_MODE, T_MODE, O_MODE,
4764 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
4765 CC_MODE, CCFP_MODE
4768 /* Modes for single-word and smaller quantities. */
4769 #define S_MODES \
4770 ((1 << (int) H_MODE) | (1 << (int) S_MODE) | (1 << (int) SF_MODE))
4772 /* Modes for double-word and smaller quantities. */
4773 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
4775 /* Modes for quad-word and smaller quantities. */
4776 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
4778 /* Modes for 8-word and smaller quantities. */
4779 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
4781 /* Modes for single-float quantities. */
4782 #define SF_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
4784 /* Modes for double-float and smaller quantities. */
4785 #define DF_MODES (SF_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
4787 /* Modes for quad-float and smaller quantities. */
4788 #define TF_MODES (DF_MODES | (1 << (int) TF_MODE))
4790 /* Modes for quad-float pairs and smaller quantities. */
4791 #define OF_MODES (TF_MODES | (1 << (int) OF_MODE))
4793 /* Modes for double-float only quantities. */
4794 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
4796 /* Modes for quad-float and double-float only quantities. */
4797 #define TF_MODES_NO_S (DF_MODES_NO_S | (1 << (int) TF_MODE))
4799 /* Modes for quad-float pairs and double-float only quantities. */
4800 #define OF_MODES_NO_S (TF_MODES_NO_S | (1 << (int) OF_MODE))
4802 /* Modes for condition codes. */
4803 #define CC_MODES (1 << (int) CC_MODE)
4804 #define CCFP_MODES (1 << (int) CCFP_MODE)
4806 /* Value is 1 if register/mode pair is acceptable on sparc.
4808 The funny mixture of D and T modes is because integer operations
4809 do not specially operate on tetra quantities, so non-quad-aligned
4810 registers can hold quadword quantities (except %o4 and %i4 because
4811 they cross fixed registers).
4813 ??? Note that, despite the settings, non-double-aligned parameter
4814 registers can hold double-word quantities in 32-bit mode. */
4816 /* This points to either the 32 bit or the 64 bit version. */
4817 const int *hard_regno_mode_classes;
4819 static const int hard_32bit_mode_classes[] = {
4820 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
4821 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
4822 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
4823 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
4825 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4826 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4827 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4828 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
4830 /* FP regs f32 to f63. Only the even numbered registers actually exist,
4831 and none can hold SFmode/SImode values. */
4832 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4833 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4834 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4835 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4837 /* %fcc[0123] */
4838 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
4840 /* %icc, %sfp, %gsr */
4841 CC_MODES, 0, D_MODES
4844 static const int hard_64bit_mode_classes[] = {
4845 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4846 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4847 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4848 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
4850 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4851 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4852 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
4853 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
4855 /* FP regs f32 to f63. Only the even numbered registers actually exist,
4856 and none can hold SFmode/SImode values. */
4857 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4858 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4859 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4860 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
4862 /* %fcc[0123] */
4863 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
4865 /* %icc, %sfp, %gsr */
4866 CC_MODES, 0, D_MODES
4869 int sparc_mode_class [NUM_MACHINE_MODES];
4871 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
4873 static void
4874 sparc_init_modes (void)
4876 int i;
4878 for (i = 0; i < NUM_MACHINE_MODES; i++)
4880 machine_mode m = (machine_mode) i;
4881 unsigned int size = GET_MODE_SIZE (m);
4883 switch (GET_MODE_CLASS (m))
4885 case MODE_INT:
4886 case MODE_PARTIAL_INT:
4887 case MODE_COMPLEX_INT:
4888 if (size < 4)
4889 sparc_mode_class[i] = 1 << (int) H_MODE;
4890 else if (size == 4)
4891 sparc_mode_class[i] = 1 << (int) S_MODE;
4892 else if (size == 8)
4893 sparc_mode_class[i] = 1 << (int) D_MODE;
4894 else if (size == 16)
4895 sparc_mode_class[i] = 1 << (int) T_MODE;
4896 else if (size == 32)
4897 sparc_mode_class[i] = 1 << (int) O_MODE;
4898 else
4899 sparc_mode_class[i] = 0;
4900 break;
4901 case MODE_VECTOR_INT:
4902 if (size == 4)
4903 sparc_mode_class[i] = 1 << (int) SF_MODE;
4904 else if (size == 8)
4905 sparc_mode_class[i] = 1 << (int) DF_MODE;
4906 else
4907 sparc_mode_class[i] = 0;
4908 break;
4909 case MODE_FLOAT:
4910 case MODE_COMPLEX_FLOAT:
4911 if (size == 4)
4912 sparc_mode_class[i] = 1 << (int) SF_MODE;
4913 else if (size == 8)
4914 sparc_mode_class[i] = 1 << (int) DF_MODE;
4915 else if (size == 16)
4916 sparc_mode_class[i] = 1 << (int) TF_MODE;
4917 else if (size == 32)
4918 sparc_mode_class[i] = 1 << (int) OF_MODE;
4919 else
4920 sparc_mode_class[i] = 0;
4921 break;
4922 case MODE_CC:
4923 if (m == CCFPmode || m == CCFPEmode)
4924 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
4925 else
4926 sparc_mode_class[i] = 1 << (int) CC_MODE;
4927 break;
4928 default:
4929 sparc_mode_class[i] = 0;
4930 break;
4934 if (TARGET_ARCH64)
4935 hard_regno_mode_classes = hard_64bit_mode_classes;
4936 else
4937 hard_regno_mode_classes = hard_32bit_mode_classes;
4939 /* Initialize the array used by REGNO_REG_CLASS. */
4940 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4942 if (i < 16 && TARGET_V8PLUS)
4943 sparc_regno_reg_class[i] = I64_REGS;
4944 else if (i < 32 || i == FRAME_POINTER_REGNUM)
4945 sparc_regno_reg_class[i] = GENERAL_REGS;
4946 else if (i < 64)
4947 sparc_regno_reg_class[i] = FP_REGS;
4948 else if (i < 96)
4949 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
4950 else if (i < 100)
4951 sparc_regno_reg_class[i] = FPCC_REGS;
4952 else
4953 sparc_regno_reg_class[i] = NO_REGS;
4957 /* Return whether REGNO, a global or FP register, must be saved/restored. */
4959 static inline bool
4960 save_global_or_fp_reg_p (unsigned int regno,
4961 int leaf_function ATTRIBUTE_UNUSED)
4963 return !call_used_regs[regno] && df_regs_ever_live_p (regno);
4966 /* Return whether the return address register (%i7) is needed. */
4968 static inline bool
4969 return_addr_reg_needed_p (int leaf_function)
4971 /* If it is live, for example because of __builtin_return_address (0). */
4972 if (df_regs_ever_live_p (RETURN_ADDR_REGNUM))
4973 return true;
4975 /* Otherwise, it is needed as save register if %o7 is clobbered. */
4976 if (!leaf_function
4977 /* Loading the GOT register clobbers %o7. */
4978 || crtl->uses_pic_offset_table
4979 || df_regs_ever_live_p (INCOMING_RETURN_ADDR_REGNUM))
4980 return true;
4982 return false;
4985 /* Return whether REGNO, a local or in register, must be saved/restored. */
4987 static bool
4988 save_local_or_in_reg_p (unsigned int regno, int leaf_function)
4990 /* General case: call-saved registers live at some point. */
4991 if (!call_used_regs[regno] && df_regs_ever_live_p (regno))
4992 return true;
4994 /* Frame pointer register (%fp) if needed. */
4995 if (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
4996 return true;
4998 /* Return address register (%i7) if needed. */
4999 if (regno == RETURN_ADDR_REGNUM && return_addr_reg_needed_p (leaf_function))
5000 return true;
5002 /* GOT register (%l7) if needed. */
5003 if (regno == PIC_OFFSET_TABLE_REGNUM && crtl->uses_pic_offset_table)
5004 return true;
5006 /* If the function accesses prior frames, the frame pointer and the return
5007 address of the previous frame must be saved on the stack. */
5008 if (crtl->accesses_prior_frames
5009 && (regno == HARD_FRAME_POINTER_REGNUM || regno == RETURN_ADDR_REGNUM))
5010 return true;
5012 return false;
5015 /* Compute the frame size required by the function. This function is called
5016 during the reload pass and also by sparc_expand_prologue. */
5018 HOST_WIDE_INT
5019 sparc_compute_frame_size (HOST_WIDE_INT size, int leaf_function)
5021 HOST_WIDE_INT frame_size, apparent_frame_size;
5022 int args_size, n_global_fp_regs = 0;
5023 bool save_local_in_regs_p = false;
5024 unsigned int i;
5026 /* If the function allocates dynamic stack space, the dynamic offset is
5027 computed early and contains REG_PARM_STACK_SPACE, so we need to cope. */
5028 if (leaf_function && !cfun->calls_alloca)
5029 args_size = 0;
5030 else
5031 args_size = crtl->outgoing_args_size + REG_PARM_STACK_SPACE (cfun->decl);
5033 /* Calculate space needed for global registers. */
5034 if (TARGET_ARCH64)
5036 for (i = 0; i < 8; i++)
5037 if (save_global_or_fp_reg_p (i, 0))
5038 n_global_fp_regs += 2;
5040 else
5042 for (i = 0; i < 8; i += 2)
5043 if (save_global_or_fp_reg_p (i, 0)
5044 || save_global_or_fp_reg_p (i + 1, 0))
5045 n_global_fp_regs += 2;
5048 /* In the flat window model, find out which local and in registers need to
5049 be saved. We don't reserve space in the current frame for them as they
5050 will be spilled into the register window save area of the caller's frame.
5051 However, as soon as we use this register window save area, we must create
5052 that of the current frame to make it the live one. */
5053 if (TARGET_FLAT)
5054 for (i = 16; i < 32; i++)
5055 if (save_local_or_in_reg_p (i, leaf_function))
5057 save_local_in_regs_p = true;
5058 break;
5061 /* Calculate space needed for FP registers. */
5062 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
5063 if (save_global_or_fp_reg_p (i, 0) || save_global_or_fp_reg_p (i + 1, 0))
5064 n_global_fp_regs += 2;
5066 if (size == 0
5067 && n_global_fp_regs == 0
5068 && args_size == 0
5069 && !save_local_in_regs_p)
5070 frame_size = apparent_frame_size = 0;
5071 else
5073 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
5074 apparent_frame_size = ROUND_UP (size - STARTING_FRAME_OFFSET, 8);
5075 apparent_frame_size += n_global_fp_regs * 4;
5077 /* We need to add the size of the outgoing argument area. */
5078 frame_size = apparent_frame_size + ROUND_UP (args_size, 8);
5080 /* And that of the register window save area. */
5081 frame_size += FIRST_PARM_OFFSET (cfun->decl);
5083 /* Finally, bump to the appropriate alignment. */
5084 frame_size = SPARC_STACK_ALIGN (frame_size);
5087 /* Set up values for use in prologue and epilogue. */
5088 sparc_frame_size = frame_size;
5089 sparc_apparent_frame_size = apparent_frame_size;
5090 sparc_n_global_fp_regs = n_global_fp_regs;
5091 sparc_save_local_in_regs_p = save_local_in_regs_p;
5093 return frame_size;
5096 /* Implement the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */
5099 sparc_initial_elimination_offset (int to)
5101 int offset;
5103 if (to == STACK_POINTER_REGNUM)
5104 offset = sparc_compute_frame_size (get_frame_size (), crtl->is_leaf);
5105 else
5106 offset = 0;
5108 offset += SPARC_STACK_BIAS;
5109 return offset;
5112 /* Output any necessary .register pseudo-ops. */
5114 void
5115 sparc_output_scratch_registers (FILE *file ATTRIBUTE_UNUSED)
5117 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
5118 int i;
5120 if (TARGET_ARCH32)
5121 return;
5123 /* Check if %g[2367] were used without
5124 .register being printed for them already. */
5125 for (i = 2; i < 8; i++)
5127 if (df_regs_ever_live_p (i)
5128 && ! sparc_hard_reg_printed [i])
5130 sparc_hard_reg_printed [i] = 1;
5131 /* %g7 is used as TLS base register, use #ignore
5132 for it instead of #scratch. */
5133 fprintf (file, "\t.register\t%%g%d, #%s\n", i,
5134 i == 7 ? "ignore" : "scratch");
5136 if (i == 3) i = 5;
5138 #endif
5141 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
5143 #if PROBE_INTERVAL > 4096
5144 #error Cannot use indexed addressing mode for stack probing
5145 #endif
5147 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
5148 inclusive. These are offsets from the current stack pointer.
5150 Note that we don't use the REG+REG addressing mode for the probes because
5151 of the stack bias in 64-bit mode. And it doesn't really buy us anything
5152 so the advantages of having a single code win here. */
5154 static void
5155 sparc_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
5157 rtx g1 = gen_rtx_REG (Pmode, 1);
5159 /* See if we have a constant small number of probes to generate. If so,
5160 that's the easy case. */
5161 if (size <= PROBE_INTERVAL)
5163 emit_move_insn (g1, GEN_INT (first));
5164 emit_insn (gen_rtx_SET (g1,
5165 gen_rtx_MINUS (Pmode, stack_pointer_rtx, g1)));
5166 emit_stack_probe (plus_constant (Pmode, g1, -size));
5169 /* The run-time loop is made up of 9 insns in the generic case while the
5170 compile-time loop is made up of 4+2*(n-2) insns for n # of intervals. */
5171 else if (size <= 4 * PROBE_INTERVAL)
5173 HOST_WIDE_INT i;
5175 emit_move_insn (g1, GEN_INT (first + PROBE_INTERVAL));
5176 emit_insn (gen_rtx_SET (g1,
5177 gen_rtx_MINUS (Pmode, stack_pointer_rtx, g1)));
5178 emit_stack_probe (g1);
5180 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 2 until
5181 it exceeds SIZE. If only two probes are needed, this will not
5182 generate any code. Then probe at FIRST + SIZE. */
5183 for (i = 2 * PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
5185 emit_insn (gen_rtx_SET (g1,
5186 plus_constant (Pmode, g1, -PROBE_INTERVAL)));
5187 emit_stack_probe (g1);
5190 emit_stack_probe (plus_constant (Pmode, g1,
5191 (i - PROBE_INTERVAL) - size));
5194 /* Otherwise, do the same as above, but in a loop. Note that we must be
5195 extra careful with variables wrapping around because we might be at
5196 the very top (or the very bottom) of the address space and we have
5197 to be able to handle this case properly; in particular, we use an
5198 equality test for the loop condition. */
5199 else
5201 HOST_WIDE_INT rounded_size;
5202 rtx g4 = gen_rtx_REG (Pmode, 4);
5204 emit_move_insn (g1, GEN_INT (first));
5207 /* Step 1: round SIZE to the previous multiple of the interval. */
5209 rounded_size = ROUND_DOWN (size, PROBE_INTERVAL);
5210 emit_move_insn (g4, GEN_INT (rounded_size));
5213 /* Step 2: compute initial and final value of the loop counter. */
5215 /* TEST_ADDR = SP + FIRST. */
5216 emit_insn (gen_rtx_SET (g1,
5217 gen_rtx_MINUS (Pmode, stack_pointer_rtx, g1)));
5219 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
5220 emit_insn (gen_rtx_SET (g4, gen_rtx_MINUS (Pmode, g1, g4)));
5223 /* Step 3: the loop
5225 while (TEST_ADDR != LAST_ADDR)
5227 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
5228 probe at TEST_ADDR
5231 probes at FIRST + N * PROBE_INTERVAL for values of N from 1
5232 until it is equal to ROUNDED_SIZE. */
5234 if (TARGET_ARCH64)
5235 emit_insn (gen_probe_stack_rangedi (g1, g1, g4));
5236 else
5237 emit_insn (gen_probe_stack_rangesi (g1, g1, g4));
5240 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
5241 that SIZE is equal to ROUNDED_SIZE. */
5243 if (size != rounded_size)
5244 emit_stack_probe (plus_constant (Pmode, g4, rounded_size - size));
5247 /* Make sure nothing is scheduled before we are done. */
5248 emit_insn (gen_blockage ());
5251 /* Probe a range of stack addresses from REG1 to REG2 inclusive. These are
5252 absolute addresses. */
5254 const char *
5255 output_probe_stack_range (rtx reg1, rtx reg2)
5257 static int labelno = 0;
5258 char loop_lab[32];
5259 rtx xops[2];
5261 ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++);
5263 /* Loop. */
5264 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
5266 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
5267 xops[0] = reg1;
5268 xops[1] = GEN_INT (-PROBE_INTERVAL);
5269 output_asm_insn ("add\t%0, %1, %0", xops);
5271 /* Test if TEST_ADDR == LAST_ADDR. */
5272 xops[1] = reg2;
5273 output_asm_insn ("cmp\t%0, %1", xops);
5275 /* Probe at TEST_ADDR and branch. */
5276 if (TARGET_ARCH64)
5277 fputs ("\tbne,pt\t%xcc,", asm_out_file);
5278 else
5279 fputs ("\tbne\t", asm_out_file);
5280 assemble_name_raw (asm_out_file, loop_lab);
5281 fputc ('\n', asm_out_file);
5282 xops[1] = GEN_INT (SPARC_STACK_BIAS);
5283 output_asm_insn (" st\t%%g0, [%0+%1]", xops);
5285 return "";
5288 /* Emit code to save/restore registers from LOW to HIGH at BASE+OFFSET as
5289 needed. LOW is supposed to be double-word aligned for 32-bit registers.
5290 SAVE_P decides whether a register must be saved/restored. ACTION_TRUE
5291 is the action to be performed if SAVE_P returns true and ACTION_FALSE
5292 the action to be performed if it returns false. Return the new offset. */
5294 typedef bool (*sorr_pred_t) (unsigned int, int);
5295 typedef enum { SORR_NONE, SORR_ADVANCE, SORR_SAVE, SORR_RESTORE } sorr_act_t;
5297 static int
5298 emit_save_or_restore_regs (unsigned int low, unsigned int high, rtx base,
5299 int offset, int leaf_function, sorr_pred_t save_p,
5300 sorr_act_t action_true, sorr_act_t action_false)
5302 unsigned int i;
5303 rtx mem;
5304 rtx_insn *insn;
5306 if (TARGET_ARCH64 && high <= 32)
5308 int fp_offset = -1;
5310 for (i = low; i < high; i++)
5312 if (save_p (i, leaf_function))
5314 mem = gen_frame_mem (DImode, plus_constant (Pmode,
5315 base, offset));
5316 if (action_true == SORR_SAVE)
5318 insn = emit_move_insn (mem, gen_rtx_REG (DImode, i));
5319 RTX_FRAME_RELATED_P (insn) = 1;
5321 else /* action_true == SORR_RESTORE */
5323 /* The frame pointer must be restored last since its old
5324 value may be used as base address for the frame. This
5325 is problematic in 64-bit mode only because of the lack
5326 of double-word load instruction. */
5327 if (i == HARD_FRAME_POINTER_REGNUM)
5328 fp_offset = offset;
5329 else
5330 emit_move_insn (gen_rtx_REG (DImode, i), mem);
5332 offset += 8;
5334 else if (action_false == SORR_ADVANCE)
5335 offset += 8;
5338 if (fp_offset >= 0)
5340 mem = gen_frame_mem (DImode, plus_constant (Pmode, base, fp_offset));
5341 emit_move_insn (hard_frame_pointer_rtx, mem);
5344 else
5346 for (i = low; i < high; i += 2)
5348 bool reg0 = save_p (i, leaf_function);
5349 bool reg1 = save_p (i + 1, leaf_function);
5350 machine_mode mode;
5351 int regno;
5353 if (reg0 && reg1)
5355 mode = SPARC_INT_REG_P (i) ? DImode : DFmode;
5356 regno = i;
5358 else if (reg0)
5360 mode = SPARC_INT_REG_P (i) ? SImode : SFmode;
5361 regno = i;
5363 else if (reg1)
5365 mode = SPARC_INT_REG_P (i) ? SImode : SFmode;
5366 regno = i + 1;
5367 offset += 4;
5369 else
5371 if (action_false == SORR_ADVANCE)
5372 offset += 8;
5373 continue;
5376 mem = gen_frame_mem (mode, plus_constant (Pmode, base, offset));
5377 if (action_true == SORR_SAVE)
5379 insn = emit_move_insn (mem, gen_rtx_REG (mode, regno));
5380 RTX_FRAME_RELATED_P (insn) = 1;
5381 if (mode == DImode)
5383 rtx set1, set2;
5384 mem = gen_frame_mem (SImode, plus_constant (Pmode, base,
5385 offset));
5386 set1 = gen_rtx_SET (mem, gen_rtx_REG (SImode, regno));
5387 RTX_FRAME_RELATED_P (set1) = 1;
5389 = gen_frame_mem (SImode, plus_constant (Pmode, base,
5390 offset + 4));
5391 set2 = gen_rtx_SET (mem, gen_rtx_REG (SImode, regno + 1));
5392 RTX_FRAME_RELATED_P (set2) = 1;
5393 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
5394 gen_rtx_PARALLEL (VOIDmode,
5395 gen_rtvec (2, set1, set2)));
5398 else /* action_true == SORR_RESTORE */
5399 emit_move_insn (gen_rtx_REG (mode, regno), mem);
5401 /* Bump and round down to double word
5402 in case we already bumped by 4. */
5403 offset = ROUND_DOWN (offset + 8, 8);
5407 return offset;
5410 /* Emit code to adjust BASE to OFFSET. Return the new base. */
5412 static rtx
5413 emit_adjust_base_to_offset (rtx base, int offset)
5415 /* ??? This might be optimized a little as %g1 might already have a
5416 value close enough that a single add insn will do. */
5417 /* ??? Although, all of this is probably only a temporary fix because
5418 if %g1 can hold a function result, then sparc_expand_epilogue will
5419 lose (the result will be clobbered). */
5420 rtx new_base = gen_rtx_REG (Pmode, 1);
5421 emit_move_insn (new_base, GEN_INT (offset));
5422 emit_insn (gen_rtx_SET (new_base, gen_rtx_PLUS (Pmode, base, new_base)));
5423 return new_base;
5426 /* Emit code to save/restore call-saved global and FP registers. */
5428 static void
5429 emit_save_or_restore_global_fp_regs (rtx base, int offset, sorr_act_t action)
5431 if (offset < -4096 || offset + sparc_n_global_fp_regs * 4 > 4095)
5433 base = emit_adjust_base_to_offset (base, offset);
5434 offset = 0;
5437 offset
5438 = emit_save_or_restore_regs (0, 8, base, offset, 0,
5439 save_global_or_fp_reg_p, action, SORR_NONE);
5440 emit_save_or_restore_regs (32, TARGET_V9 ? 96 : 64, base, offset, 0,
5441 save_global_or_fp_reg_p, action, SORR_NONE);
5444 /* Emit code to save/restore call-saved local and in registers. */
5446 static void
5447 emit_save_or_restore_local_in_regs (rtx base, int offset, sorr_act_t action)
5449 if (offset < -4096 || offset + 16 * UNITS_PER_WORD > 4095)
5451 base = emit_adjust_base_to_offset (base, offset);
5452 offset = 0;
5455 emit_save_or_restore_regs (16, 32, base, offset, sparc_leaf_function_p,
5456 save_local_or_in_reg_p, action, SORR_ADVANCE);
5459 /* Emit a window_save insn. */
5461 static rtx_insn *
5462 emit_window_save (rtx increment)
5464 rtx_insn *insn = emit_insn (gen_window_save (increment));
5465 RTX_FRAME_RELATED_P (insn) = 1;
5467 /* The incoming return address (%o7) is saved in %i7. */
5468 add_reg_note (insn, REG_CFA_REGISTER,
5469 gen_rtx_SET (gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM),
5470 gen_rtx_REG (Pmode,
5471 INCOMING_RETURN_ADDR_REGNUM)));
5473 /* The window save event. */
5474 add_reg_note (insn, REG_CFA_WINDOW_SAVE, const0_rtx);
5476 /* The CFA is %fp, the hard frame pointer. */
5477 add_reg_note (insn, REG_CFA_DEF_CFA,
5478 plus_constant (Pmode, hard_frame_pointer_rtx,
5479 INCOMING_FRAME_SP_OFFSET));
5481 return insn;
5484 /* Generate an increment for the stack pointer. */
5486 static rtx
5487 gen_stack_pointer_inc (rtx increment)
5489 return gen_rtx_SET (stack_pointer_rtx,
5490 gen_rtx_PLUS (Pmode,
5491 stack_pointer_rtx,
5492 increment));
5495 /* Expand the function prologue. The prologue is responsible for reserving
5496 storage for the frame, saving the call-saved registers and loading the
5497 GOT register if needed. */
5499 void
5500 sparc_expand_prologue (void)
5502 HOST_WIDE_INT size;
5503 rtx_insn *insn;
5505 /* Compute a snapshot of crtl->uses_only_leaf_regs. Relying
5506 on the final value of the flag means deferring the prologue/epilogue
5507 expansion until just before the second scheduling pass, which is too
5508 late to emit multiple epilogues or return insns.
5510 Of course we are making the assumption that the value of the flag
5511 will not change between now and its final value. Of the three parts
5512 of the formula, only the last one can reasonably vary. Let's take a
5513 closer look, after assuming that the first two ones are set to true
5514 (otherwise the last value is effectively silenced).
5516 If only_leaf_regs_used returns false, the global predicate will also
5517 be false so the actual frame size calculated below will be positive.
5518 As a consequence, the save_register_window insn will be emitted in
5519 the instruction stream; now this insn explicitly references %fp
5520 which is not a leaf register so only_leaf_regs_used will always
5521 return false subsequently.
5523 If only_leaf_regs_used returns true, we hope that the subsequent
5524 optimization passes won't cause non-leaf registers to pop up. For
5525 example, the regrename pass has special provisions to not rename to
5526 non-leaf registers in a leaf function. */
5527 sparc_leaf_function_p
5528 = optimize > 0 && crtl->is_leaf && only_leaf_regs_used ();
5530 size = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p);
5532 if (flag_stack_usage_info)
5533 current_function_static_stack_size = size;
5535 if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
5537 if (crtl->is_leaf && !cfun->calls_alloca)
5539 if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
5540 sparc_emit_probe_stack_range (STACK_CHECK_PROTECT,
5541 size - STACK_CHECK_PROTECT);
5543 else if (size > 0)
5544 sparc_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
5547 if (size == 0)
5548 ; /* do nothing. */
5549 else if (sparc_leaf_function_p)
5551 rtx size_int_rtx = GEN_INT (-size);
5553 if (size <= 4096)
5554 insn = emit_insn (gen_stack_pointer_inc (size_int_rtx));
5555 else if (size <= 8192)
5557 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-4096)));
5558 RTX_FRAME_RELATED_P (insn) = 1;
5560 /* %sp is still the CFA register. */
5561 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (4096 - size)));
5563 else
5565 rtx size_rtx = gen_rtx_REG (Pmode, 1);
5566 emit_move_insn (size_rtx, size_int_rtx);
5567 insn = emit_insn (gen_stack_pointer_inc (size_rtx));
5568 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
5569 gen_stack_pointer_inc (size_int_rtx));
5572 RTX_FRAME_RELATED_P (insn) = 1;
5574 else
5576 rtx size_int_rtx = GEN_INT (-size);
5578 if (size <= 4096)
5579 emit_window_save (size_int_rtx);
5580 else if (size <= 8192)
5582 emit_window_save (GEN_INT (-4096));
5584 /* %sp is not the CFA register anymore. */
5585 emit_insn (gen_stack_pointer_inc (GEN_INT (4096 - size)));
5587 /* Make sure no %fp-based store is issued until after the frame is
5588 established. The offset between the frame pointer and the stack
5589 pointer is calculated relative to the value of the stack pointer
5590 at the end of the function prologue, and moving instructions that
5591 access the stack via the frame pointer between the instructions
5592 that decrement the stack pointer could result in accessing the
5593 register window save area, which is volatile. */
5594 emit_insn (gen_frame_blockage ());
5596 else
5598 rtx size_rtx = gen_rtx_REG (Pmode, 1);
5599 emit_move_insn (size_rtx, size_int_rtx);
5600 emit_window_save (size_rtx);
5604 if (sparc_leaf_function_p)
5606 sparc_frame_base_reg = stack_pointer_rtx;
5607 sparc_frame_base_offset = size + SPARC_STACK_BIAS;
5609 else
5611 sparc_frame_base_reg = hard_frame_pointer_rtx;
5612 sparc_frame_base_offset = SPARC_STACK_BIAS;
5615 if (sparc_n_global_fp_regs > 0)
5616 emit_save_or_restore_global_fp_regs (sparc_frame_base_reg,
5617 sparc_frame_base_offset
5618 - sparc_apparent_frame_size,
5619 SORR_SAVE);
5621 /* Load the GOT register if needed. */
5622 if (crtl->uses_pic_offset_table)
5623 load_got_register ();
5625 /* Advertise that the data calculated just above are now valid. */
5626 sparc_prologue_data_valid_p = true;
5629 /* Expand the function prologue. The prologue is responsible for reserving
5630 storage for the frame, saving the call-saved registers and loading the
5631 GOT register if needed. */
5633 void
5634 sparc_flat_expand_prologue (void)
5636 HOST_WIDE_INT size;
5637 rtx_insn *insn;
5639 sparc_leaf_function_p = optimize > 0 && crtl->is_leaf;
5641 size = sparc_compute_frame_size (get_frame_size(), sparc_leaf_function_p);
5643 if (flag_stack_usage_info)
5644 current_function_static_stack_size = size;
5646 if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
5648 if (crtl->is_leaf && !cfun->calls_alloca)
5650 if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
5651 sparc_emit_probe_stack_range (STACK_CHECK_PROTECT,
5652 size - STACK_CHECK_PROTECT);
5654 else if (size > 0)
5655 sparc_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
5658 if (sparc_save_local_in_regs_p)
5659 emit_save_or_restore_local_in_regs (stack_pointer_rtx, SPARC_STACK_BIAS,
5660 SORR_SAVE);
5662 if (size == 0)
5663 ; /* do nothing. */
5664 else
5666 rtx size_int_rtx, size_rtx;
5668 size_rtx = size_int_rtx = GEN_INT (-size);
5670 /* We establish the frame (i.e. decrement the stack pointer) first, even
5671 if we use a frame pointer, because we cannot clobber any call-saved
5672 registers, including the frame pointer, if we haven't created a new
5673 register save area, for the sake of compatibility with the ABI. */
5674 if (size <= 4096)
5675 insn = emit_insn (gen_stack_pointer_inc (size_int_rtx));
5676 else if (size <= 8192 && !frame_pointer_needed)
5678 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (-4096)));
5679 RTX_FRAME_RELATED_P (insn) = 1;
5680 insn = emit_insn (gen_stack_pointer_inc (GEN_INT (4096 - size)));
5682 else
5684 size_rtx = gen_rtx_REG (Pmode, 1);
5685 emit_move_insn (size_rtx, size_int_rtx);
5686 insn = emit_insn (gen_stack_pointer_inc (size_rtx));
5687 add_reg_note (insn, REG_CFA_ADJUST_CFA,
5688 gen_stack_pointer_inc (size_int_rtx));
5690 RTX_FRAME_RELATED_P (insn) = 1;
5692 /* Ensure nothing is scheduled until after the frame is established. */
5693 emit_insn (gen_blockage ());
5695 if (frame_pointer_needed)
5697 insn = emit_insn (gen_rtx_SET (hard_frame_pointer_rtx,
5698 gen_rtx_MINUS (Pmode,
5699 stack_pointer_rtx,
5700 size_rtx)));
5701 RTX_FRAME_RELATED_P (insn) = 1;
5703 add_reg_note (insn, REG_CFA_ADJUST_CFA,
5704 gen_rtx_SET (hard_frame_pointer_rtx,
5705 plus_constant (Pmode, stack_pointer_rtx,
5706 size)));
5709 if (return_addr_reg_needed_p (sparc_leaf_function_p))
5711 rtx o7 = gen_rtx_REG (Pmode, INCOMING_RETURN_ADDR_REGNUM);
5712 rtx i7 = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
5714 insn = emit_move_insn (i7, o7);
5715 RTX_FRAME_RELATED_P (insn) = 1;
5717 add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (i7, o7));
5719 /* Prevent this instruction from ever being considered dead,
5720 even if this function has no epilogue. */
5721 emit_use (i7);
5725 if (frame_pointer_needed)
5727 sparc_frame_base_reg = hard_frame_pointer_rtx;
5728 sparc_frame_base_offset = SPARC_STACK_BIAS;
5730 else
5732 sparc_frame_base_reg = stack_pointer_rtx;
5733 sparc_frame_base_offset = size + SPARC_STACK_BIAS;
5736 if (sparc_n_global_fp_regs > 0)
5737 emit_save_or_restore_global_fp_regs (sparc_frame_base_reg,
5738 sparc_frame_base_offset
5739 - sparc_apparent_frame_size,
5740 SORR_SAVE);
5742 /* Load the GOT register if needed. */
5743 if (crtl->uses_pic_offset_table)
5744 load_got_register ();
5746 /* Advertise that the data calculated just above are now valid. */
5747 sparc_prologue_data_valid_p = true;
5750 /* This function generates the assembly code for function entry, which boils
5751 down to emitting the necessary .register directives. */
5753 static void
5754 sparc_asm_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
5756 /* Check that the assumption we made in sparc_expand_prologue is valid. */
5757 if (!TARGET_FLAT)
5758 gcc_assert (sparc_leaf_function_p == crtl->uses_only_leaf_regs);
5760 sparc_output_scratch_registers (file);
5763 /* Expand the function epilogue, either normal or part of a sibcall.
5764 We emit all the instructions except the return or the call. */
5766 void
5767 sparc_expand_epilogue (bool for_eh)
5769 HOST_WIDE_INT size = sparc_frame_size;
5771 if (sparc_n_global_fp_regs > 0)
5772 emit_save_or_restore_global_fp_regs (sparc_frame_base_reg,
5773 sparc_frame_base_offset
5774 - sparc_apparent_frame_size,
5775 SORR_RESTORE);
5777 if (size == 0 || for_eh)
5778 ; /* do nothing. */
5779 else if (sparc_leaf_function_p)
5781 if (size <= 4096)
5782 emit_insn (gen_stack_pointer_inc (GEN_INT (size)));
5783 else if (size <= 8192)
5785 emit_insn (gen_stack_pointer_inc (GEN_INT (4096)));
5786 emit_insn (gen_stack_pointer_inc (GEN_INT (size - 4096)));
5788 else
5790 rtx reg = gen_rtx_REG (Pmode, 1);
5791 emit_move_insn (reg, GEN_INT (size));
5792 emit_insn (gen_stack_pointer_inc (reg));
5797 /* Expand the function epilogue, either normal or part of a sibcall.
5798 We emit all the instructions except the return or the call. */
5800 void
5801 sparc_flat_expand_epilogue (bool for_eh)
5803 HOST_WIDE_INT size = sparc_frame_size;
5805 if (sparc_n_global_fp_regs > 0)
5806 emit_save_or_restore_global_fp_regs (sparc_frame_base_reg,
5807 sparc_frame_base_offset
5808 - sparc_apparent_frame_size,
5809 SORR_RESTORE);
5811 /* If we have a frame pointer, we'll need both to restore it before the
5812 frame is destroyed and use its current value in destroying the frame.
5813 Since we don't have an atomic way to do that in the flat window model,
5814 we save the current value into a temporary register (%g1). */
5815 if (frame_pointer_needed && !for_eh)
5816 emit_move_insn (gen_rtx_REG (Pmode, 1), hard_frame_pointer_rtx);
5818 if (return_addr_reg_needed_p (sparc_leaf_function_p))
5819 emit_move_insn (gen_rtx_REG (Pmode, INCOMING_RETURN_ADDR_REGNUM),
5820 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM));
5822 if (sparc_save_local_in_regs_p)
5823 emit_save_or_restore_local_in_regs (sparc_frame_base_reg,
5824 sparc_frame_base_offset,
5825 SORR_RESTORE);
5827 if (size == 0 || for_eh)
5828 ; /* do nothing. */
5829 else if (frame_pointer_needed)
5831 /* Make sure the frame is destroyed after everything else is done. */
5832 emit_insn (gen_blockage ());
5834 emit_move_insn (stack_pointer_rtx, gen_rtx_REG (Pmode, 1));
5836 else
5838 /* Likewise. */
5839 emit_insn (gen_blockage ());
5841 if (size <= 4096)
5842 emit_insn (gen_stack_pointer_inc (GEN_INT (size)));
5843 else if (size <= 8192)
5845 emit_insn (gen_stack_pointer_inc (GEN_INT (4096)));
5846 emit_insn (gen_stack_pointer_inc (GEN_INT (size - 4096)));
5848 else
5850 rtx reg = gen_rtx_REG (Pmode, 1);
5851 emit_move_insn (reg, GEN_INT (size));
5852 emit_insn (gen_stack_pointer_inc (reg));
5857 /* Return true if it is appropriate to emit `return' instructions in the
5858 body of a function. */
5860 bool
5861 sparc_can_use_return_insn_p (void)
5863 return sparc_prologue_data_valid_p
5864 && sparc_n_global_fp_regs == 0
5865 && TARGET_FLAT
5866 ? (sparc_frame_size == 0 && !sparc_save_local_in_regs_p)
5867 : (sparc_frame_size == 0 || !sparc_leaf_function_p);
5870 /* This function generates the assembly code for function exit. */
5872 static void
5873 sparc_asm_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
5875 /* If the last two instructions of a function are "call foo; dslot;"
5876 the return address might point to the first instruction in the next
5877 function and we have to output a dummy nop for the sake of sane
5878 backtraces in such cases. This is pointless for sibling calls since
5879 the return address is explicitly adjusted. */
5881 rtx_insn *insn = get_last_insn ();
5883 rtx last_real_insn = prev_real_insn (insn);
5884 if (last_real_insn
5885 && NONJUMP_INSN_P (last_real_insn)
5886 && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE)
5887 last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0);
5889 if (last_real_insn
5890 && CALL_P (last_real_insn)
5891 && !SIBLING_CALL_P (last_real_insn))
5892 fputs("\tnop\n", file);
5894 sparc_output_deferred_case_vectors ();
5897 /* Output a 'restore' instruction. */
5899 static void
5900 output_restore (rtx pat)
5902 rtx operands[3];
5904 if (! pat)
5906 fputs ("\t restore\n", asm_out_file);
5907 return;
5910 gcc_assert (GET_CODE (pat) == SET);
5912 operands[0] = SET_DEST (pat);
5913 pat = SET_SRC (pat);
5915 switch (GET_CODE (pat))
5917 case PLUS:
5918 operands[1] = XEXP (pat, 0);
5919 operands[2] = XEXP (pat, 1);
5920 output_asm_insn (" restore %r1, %2, %Y0", operands);
5921 break;
5922 case LO_SUM:
5923 operands[1] = XEXP (pat, 0);
5924 operands[2] = XEXP (pat, 1);
5925 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
5926 break;
5927 case ASHIFT:
5928 operands[1] = XEXP (pat, 0);
5929 gcc_assert (XEXP (pat, 1) == const1_rtx);
5930 output_asm_insn (" restore %r1, %r1, %Y0", operands);
5931 break;
5932 default:
5933 operands[1] = pat;
5934 output_asm_insn (" restore %%g0, %1, %Y0", operands);
5935 break;
5939 /* Output a return. */
5941 const char *
5942 output_return (rtx_insn *insn)
5944 if (crtl->calls_eh_return)
5946 /* If the function uses __builtin_eh_return, the eh_return
5947 machinery occupies the delay slot. */
5948 gcc_assert (!final_sequence);
5950 if (flag_delayed_branch)
5952 if (!TARGET_FLAT && TARGET_V9)
5953 fputs ("\treturn\t%i7+8\n", asm_out_file);
5954 else
5956 if (!TARGET_FLAT)
5957 fputs ("\trestore\n", asm_out_file);
5959 fputs ("\tjmp\t%o7+8\n", asm_out_file);
5962 fputs ("\t add\t%sp, %g1, %sp\n", asm_out_file);
5964 else
5966 if (!TARGET_FLAT)
5967 fputs ("\trestore\n", asm_out_file);
5969 fputs ("\tadd\t%sp, %g1, %sp\n", asm_out_file);
5970 fputs ("\tjmp\t%o7+8\n\t nop\n", asm_out_file);
5973 else if (sparc_leaf_function_p || TARGET_FLAT)
5975 /* This is a leaf or flat function so we don't have to bother restoring
5976 the register window, which frees us from dealing with the convoluted
5977 semantics of restore/return. We simply output the jump to the
5978 return address and the insn in the delay slot (if any). */
5980 return "jmp\t%%o7+%)%#";
5982 else
5984 /* This is a regular function so we have to restore the register window.
5985 We may have a pending insn for the delay slot, which will be either
5986 combined with the 'restore' instruction or put in the delay slot of
5987 the 'return' instruction. */
5989 if (final_sequence)
5991 rtx delay, pat;
5993 delay = NEXT_INSN (insn);
5994 gcc_assert (delay);
5996 pat = PATTERN (delay);
5998 if (TARGET_V9 && ! epilogue_renumber (&pat, 1))
6000 epilogue_renumber (&pat, 0);
6001 return "return\t%%i7+%)%#";
6003 else
6005 output_asm_insn ("jmp\t%%i7+%)", NULL);
6006 output_restore (pat);
6007 PATTERN (delay) = gen_blockage ();
6008 INSN_CODE (delay) = -1;
6011 else
6013 /* The delay slot is empty. */
6014 if (TARGET_V9)
6015 return "return\t%%i7+%)\n\t nop";
6016 else if (flag_delayed_branch)
6017 return "jmp\t%%i7+%)\n\t restore";
6018 else
6019 return "restore\n\tjmp\t%%o7+%)\n\t nop";
6023 return "";
6026 /* Output a sibling call. */
6028 const char *
6029 output_sibcall (rtx_insn *insn, rtx call_operand)
6031 rtx operands[1];
6033 gcc_assert (flag_delayed_branch);
6035 operands[0] = call_operand;
6037 if (sparc_leaf_function_p || TARGET_FLAT)
6039 /* This is a leaf or flat function so we don't have to bother restoring
6040 the register window. We simply output the jump to the function and
6041 the insn in the delay slot (if any). */
6043 gcc_assert (!(LEAF_SIBCALL_SLOT_RESERVED_P && final_sequence));
6045 if (final_sequence)
6046 output_asm_insn ("sethi\t%%hi(%a0), %%g1\n\tjmp\t%%g1 + %%lo(%a0)%#",
6047 operands);
6048 else
6049 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
6050 it into branch if possible. */
6051 output_asm_insn ("or\t%%o7, %%g0, %%g1\n\tcall\t%a0, 0\n\t or\t%%g1, %%g0, %%o7",
6052 operands);
6054 else
6056 /* This is a regular function so we have to restore the register window.
6057 We may have a pending insn for the delay slot, which will be combined
6058 with the 'restore' instruction. */
6060 output_asm_insn ("call\t%a0, 0", operands);
6062 if (final_sequence)
6064 rtx_insn *delay = NEXT_INSN (insn);
6065 gcc_assert (delay);
6067 output_restore (PATTERN (delay));
6069 PATTERN (delay) = gen_blockage ();
6070 INSN_CODE (delay) = -1;
6072 else
6073 output_restore (NULL_RTX);
6076 return "";
6079 /* Functions for handling argument passing.
6081 For 32-bit, the first 6 args are normally in registers and the rest are
6082 pushed. Any arg that starts within the first 6 words is at least
6083 partially passed in a register unless its data type forbids.
6085 For 64-bit, the argument registers are laid out as an array of 16 elements
6086 and arguments are added sequentially. The first 6 int args and up to the
6087 first 16 fp args (depending on size) are passed in regs.
6089 Slot Stack Integral Float Float in structure Double Long Double
6090 ---- ----- -------- ----- ------------------ ------ -----------
6091 15 [SP+248] %f31 %f30,%f31 %d30
6092 14 [SP+240] %f29 %f28,%f29 %d28 %q28
6093 13 [SP+232] %f27 %f26,%f27 %d26
6094 12 [SP+224] %f25 %f24,%f25 %d24 %q24
6095 11 [SP+216] %f23 %f22,%f23 %d22
6096 10 [SP+208] %f21 %f20,%f21 %d20 %q20
6097 9 [SP+200] %f19 %f18,%f19 %d18
6098 8 [SP+192] %f17 %f16,%f17 %d16 %q16
6099 7 [SP+184] %f15 %f14,%f15 %d14
6100 6 [SP+176] %f13 %f12,%f13 %d12 %q12
6101 5 [SP+168] %o5 %f11 %f10,%f11 %d10
6102 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
6103 3 [SP+152] %o3 %f7 %f6,%f7 %d6
6104 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
6105 1 [SP+136] %o1 %f3 %f2,%f3 %d2
6106 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
6108 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
6110 Integral arguments are always passed as 64-bit quantities appropriately
6111 extended.
6113 Passing of floating point values is handled as follows.
6114 If a prototype is in scope:
6115 If the value is in a named argument (i.e. not a stdarg function or a
6116 value not part of the `...') then the value is passed in the appropriate
6117 fp reg.
6118 If the value is part of the `...' and is passed in one of the first 6
6119 slots then the value is passed in the appropriate int reg.
6120 If the value is part of the `...' and is not passed in one of the first 6
6121 slots then the value is passed in memory.
6122 If a prototype is not in scope:
6123 If the value is one of the first 6 arguments the value is passed in the
6124 appropriate integer reg and the appropriate fp reg.
6125 If the value is not one of the first 6 arguments the value is passed in
6126 the appropriate fp reg and in memory.
6129 Summary of the calling conventions implemented by GCC on the SPARC:
6131 32-bit ABI:
6132 size argument return value
6134 small integer <4 int. reg. int. reg.
6135 word 4 int. reg. int. reg.
6136 double word 8 int. reg. int. reg.
6138 _Complex small integer <8 int. reg. int. reg.
6139 _Complex word 8 int. reg. int. reg.
6140 _Complex double word 16 memory int. reg.
6142 vector integer <=8 int. reg. FP reg.
6143 vector integer >8 memory memory
6145 float 4 int. reg. FP reg.
6146 double 8 int. reg. FP reg.
6147 long double 16 memory memory
6149 _Complex float 8 memory FP reg.
6150 _Complex double 16 memory FP reg.
6151 _Complex long double 32 memory FP reg.
6153 vector float any memory memory
6155 aggregate any memory memory
6159 64-bit ABI:
6160 size argument return value
6162 small integer <8 int. reg. int. reg.
6163 word 8 int. reg. int. reg.
6164 double word 16 int. reg. int. reg.
6166 _Complex small integer <16 int. reg. int. reg.
6167 _Complex word 16 int. reg. int. reg.
6168 _Complex double word 32 memory int. reg.
6170 vector integer <=16 FP reg. FP reg.
6171 vector integer 16<s<=32 memory FP reg.
6172 vector integer >32 memory memory
6174 float 4 FP reg. FP reg.
6175 double 8 FP reg. FP reg.
6176 long double 16 FP reg. FP reg.
6178 _Complex float 8 FP reg. FP reg.
6179 _Complex double 16 FP reg. FP reg.
6180 _Complex long double 32 memory FP reg.
6182 vector float <=16 FP reg. FP reg.
6183 vector float 16<s<=32 memory FP reg.
6184 vector float >32 memory memory
6186 aggregate <=16 reg. reg.
6187 aggregate 16<s<=32 memory reg.
6188 aggregate >32 memory memory
6192 Note #1: complex floating-point types follow the extended SPARC ABIs as
6193 implemented by the Sun compiler.
6195 Note #2: integral vector types follow the scalar floating-point types
6196 conventions to match what is implemented by the Sun VIS SDK.
6198 Note #3: floating-point vector types follow the aggregate types
6199 conventions. */
6202 /* Maximum number of int regs for args. */
6203 #define SPARC_INT_ARG_MAX 6
6204 /* Maximum number of fp regs for args. */
6205 #define SPARC_FP_ARG_MAX 16
6206 /* Number of words (partially) occupied for a given size in units. */
6207 #define CEIL_NWORDS(SIZE) CEIL((SIZE), UNITS_PER_WORD)
6209 /* Handle the INIT_CUMULATIVE_ARGS macro.
6210 Initialize a variable CUM of type CUMULATIVE_ARGS
6211 for a call to a function whose data type is FNTYPE.
6212 For a library call, FNTYPE is 0. */
6214 void
6215 init_cumulative_args (struct sparc_args *cum, tree fntype, rtx, tree)
6217 cum->words = 0;
6218 cum->prototype_p = fntype && prototype_p (fntype);
6219 cum->libcall_p = !fntype;
6222 /* Handle promotion of pointer and integer arguments. */
6224 static machine_mode
6225 sparc_promote_function_mode (const_tree type, machine_mode mode,
6226 int *punsignedp, const_tree, int)
6228 if (type && POINTER_TYPE_P (type))
6230 *punsignedp = POINTERS_EXTEND_UNSIGNED;
6231 return Pmode;
6234 /* Integral arguments are passed as full words, as per the ABI. */
6235 if (GET_MODE_CLASS (mode) == MODE_INT
6236 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
6237 return word_mode;
6239 return mode;
6242 /* Handle the TARGET_STRICT_ARGUMENT_NAMING target hook. */
6244 static bool
6245 sparc_strict_argument_naming (cumulative_args_t ca ATTRIBUTE_UNUSED)
6247 return TARGET_ARCH64 ? true : false;
6250 /* Traverse the record TYPE recursively and call FUNC on its fields.
6251 NAMED is true if this is for a named parameter. DATA is passed
6252 to FUNC for each field. OFFSET is the starting position and
6253 PACKED is true if we are inside a packed record. */
6255 template <typename T, void Func (const_tree, HOST_WIDE_INT, bool, T*)>
6256 static void
6257 traverse_record_type (const_tree type, bool named, T *data,
6258 HOST_WIDE_INT offset = 0, bool packed = false)
6260 /* The ABI obviously doesn't specify how packed structures are passed.
6261 These are passed in integer regs if possible, otherwise memory. */
6262 if (!packed)
6263 for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6264 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
6266 packed = true;
6267 break;
6270 /* Walk the real fields, but skip those with no size or a zero size.
6271 ??? Fields with variable offset are handled as having zero offset. */
6272 for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6273 if (TREE_CODE (field) == FIELD_DECL)
6275 if (!DECL_SIZE (field) || integer_zerop (DECL_SIZE (field)))
6276 continue;
6278 HOST_WIDE_INT bitpos = offset;
6279 if (TREE_CODE (DECL_FIELD_OFFSET (field)) == INTEGER_CST)
6280 bitpos += int_bit_position (field);
6282 tree field_type = TREE_TYPE (field);
6283 if (TREE_CODE (field_type) == RECORD_TYPE)
6284 traverse_record_type<T, Func> (field_type, named, data, bitpos,
6285 packed);
6286 else
6288 const bool fp_type
6289 = FLOAT_TYPE_P (field_type) || VECTOR_TYPE_P (field_type);
6290 Func (field, bitpos, fp_type && named && !packed && TARGET_FPU,
6291 data);
6296 /* Handle recursive register classifying for structure layout. */
6298 typedef struct
6300 bool fp_regs; /* true if field eligible to FP registers. */
6301 bool fp_regs_in_first_word; /* true if such field in first word. */
6302 } classify_data_t;
6304 /* A subroutine of function_arg_slotno. Classify the field. */
6306 inline void
6307 classify_registers (const_tree, HOST_WIDE_INT bitpos, bool fp,
6308 classify_data_t *data)
6310 if (fp)
6312 data->fp_regs = true;
6313 if (bitpos < BITS_PER_WORD)
6314 data->fp_regs_in_first_word = true;
6318 /* Compute the slot number to pass an argument in.
6319 Return the slot number or -1 if passing on the stack.
6321 CUM is a variable of type CUMULATIVE_ARGS which gives info about
6322 the preceding args and about the function being called.
6323 MODE is the argument's machine mode.
6324 TYPE is the data type of the argument (as a tree).
6325 This is null for libcalls where that information may
6326 not be available.
6327 NAMED is nonzero if this argument is a named parameter
6328 (otherwise it is an extra parameter matching an ellipsis).
6329 INCOMING is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
6330 *PREGNO records the register number to use if scalar type.
6331 *PPADDING records the amount of padding needed in words. */
6333 static int
6334 function_arg_slotno (const struct sparc_args *cum, machine_mode mode,
6335 const_tree type, bool named, bool incoming,
6336 int *pregno, int *ppadding)
6338 int regbase = (incoming
6339 ? SPARC_INCOMING_INT_ARG_FIRST
6340 : SPARC_OUTGOING_INT_ARG_FIRST);
6341 int slotno = cum->words;
6342 enum mode_class mclass;
6343 int regno;
6345 *ppadding = 0;
6347 if (type && TREE_ADDRESSABLE (type))
6348 return -1;
6350 if (TARGET_ARCH32
6351 && mode == BLKmode
6352 && type
6353 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
6354 return -1;
6356 /* For SPARC64, objects requiring 16-byte alignment get it. */
6357 if (TARGET_ARCH64
6358 && (type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode)) >= 128
6359 && (slotno & 1) != 0)
6360 slotno++, *ppadding = 1;
6362 mclass = GET_MODE_CLASS (mode);
6363 if (type && TREE_CODE (type) == VECTOR_TYPE)
6365 /* Vector types deserve special treatment because they are
6366 polymorphic wrt their mode, depending upon whether VIS
6367 instructions are enabled. */
6368 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6370 /* The SPARC port defines no floating-point vector modes. */
6371 gcc_assert (mode == BLKmode);
6373 else
6375 /* Integral vector types should either have a vector
6376 mode or an integral mode, because we are guaranteed
6377 by pass_by_reference that their size is not greater
6378 than 16 bytes and TImode is 16-byte wide. */
6379 gcc_assert (mode != BLKmode);
6381 /* Vector integers are handled like floats according to
6382 the Sun VIS SDK. */
6383 mclass = MODE_FLOAT;
6387 switch (mclass)
6389 case MODE_FLOAT:
6390 case MODE_COMPLEX_FLOAT:
6391 case MODE_VECTOR_INT:
6392 if (TARGET_ARCH64 && TARGET_FPU && named)
6394 /* If all arg slots are filled, then must pass on stack. */
6395 if (slotno >= SPARC_FP_ARG_MAX)
6396 return -1;
6398 regno = SPARC_FP_ARG_FIRST + slotno * 2;
6399 /* Arguments filling only one single FP register are
6400 right-justified in the outer double FP register. */
6401 if (GET_MODE_SIZE (mode) <= 4)
6402 regno++;
6403 break;
6405 /* fallthrough */
6407 case MODE_INT:
6408 case MODE_COMPLEX_INT:
6409 /* If all arg slots are filled, then must pass on stack. */
6410 if (slotno >= SPARC_INT_ARG_MAX)
6411 return -1;
6413 regno = regbase + slotno;
6414 break;
6416 case MODE_RANDOM:
6417 if (mode == VOIDmode)
6418 /* MODE is VOIDmode when generating the actual call. */
6419 return -1;
6421 gcc_assert (mode == BLKmode);
6423 if (TARGET_ARCH32
6424 || !type
6425 || (TREE_CODE (type) != RECORD_TYPE
6426 && TREE_CODE (type) != VECTOR_TYPE))
6428 /* If all arg slots are filled, then must pass on stack. */
6429 if (slotno >= SPARC_INT_ARG_MAX)
6430 return -1;
6432 regno = regbase + slotno;
6434 else /* TARGET_ARCH64 && type */
6436 /* If all arg slots are filled, then must pass on stack. */
6437 if (slotno >= SPARC_FP_ARG_MAX)
6438 return -1;
6440 if (TREE_CODE (type) == RECORD_TYPE)
6442 classify_data_t data = { false, false };
6443 traverse_record_type<classify_data_t, classify_registers>
6444 (type, named, &data);
6446 if (data.fp_regs)
6448 /* If all FP slots are filled except for the last one and
6449 there is no FP field in the first word, then must pass
6450 on stack. */
6451 if (slotno >= SPARC_FP_ARG_MAX - 1
6452 && !data.fp_regs_in_first_word)
6453 return -1;
6455 else
6457 /* If all int slots are filled, then must pass on stack. */
6458 if (slotno >= SPARC_INT_ARG_MAX)
6459 return -1;
6463 /* PREGNO isn't set since both int and FP regs can be used. */
6464 return slotno;
6466 break;
6468 default :
6469 gcc_unreachable ();
6472 *pregno = regno;
6473 return slotno;
6476 /* Handle recursive register counting/assigning for structure layout. */
6478 typedef struct
6480 int slotno; /* slot number of the argument. */
6481 int regbase; /* regno of the base register. */
6482 int intoffset; /* offset of the first pending integer field. */
6483 int nregs; /* number of words passed in registers. */
6484 bool stack; /* true if part of the argument is on the stack. */
6485 rtx ret; /* return expression being built. */
6486 } assign_data_t;
6488 /* A subroutine of function_arg_record_value. Compute the number of integer
6489 registers to be assigned between PARMS->intoffset and BITPOS. Return
6490 true if at least one integer register is assigned or false otherwise. */
6492 static bool
6493 compute_int_layout (HOST_WIDE_INT bitpos, assign_data_t *data, int *pnregs)
6495 if (data->intoffset < 0)
6496 return false;
6498 const int intoffset = data->intoffset;
6499 data->intoffset = -1;
6501 const int this_slotno = data->slotno + intoffset / BITS_PER_WORD;
6502 const unsigned int startbit = ROUND_DOWN (intoffset, BITS_PER_WORD);
6503 const unsigned int endbit = ROUND_UP (bitpos, BITS_PER_WORD);
6504 int nregs = (endbit - startbit) / BITS_PER_WORD;
6506 if (nregs > 0 && nregs > SPARC_INT_ARG_MAX - this_slotno)
6508 nregs = SPARC_INT_ARG_MAX - this_slotno;
6510 /* We need to pass this field (partly) on the stack. */
6511 data->stack = 1;
6514 if (nregs <= 0)
6515 return false;
6517 *pnregs = nregs;
6518 return true;
6521 /* A subroutine of function_arg_record_value. Compute the number and the mode
6522 of the FP registers to be assigned for FIELD. Return true if at least one
6523 FP register is assigned or false otherwise. */
6525 static bool
6526 compute_fp_layout (const_tree field, HOST_WIDE_INT bitpos,
6527 assign_data_t *data,
6528 int *pnregs, machine_mode *pmode)
6530 const int this_slotno = data->slotno + bitpos / BITS_PER_WORD;
6531 machine_mode mode = DECL_MODE (field);
6532 int nregs, nslots;
6534 /* Slots are counted as words while regs are counted as having the size of
6535 the (inner) mode. */
6536 if (TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE && mode == BLKmode)
6538 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
6539 nregs = TYPE_VECTOR_SUBPARTS (TREE_TYPE (field));
6541 else if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
6543 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
6544 nregs = 2;
6546 else
6547 nregs = 1;
6549 nslots = CEIL_NWORDS (nregs * GET_MODE_SIZE (mode));
6551 if (nslots > SPARC_FP_ARG_MAX - this_slotno)
6553 nslots = SPARC_FP_ARG_MAX - this_slotno;
6554 nregs = (nslots * UNITS_PER_WORD) / GET_MODE_SIZE (mode);
6556 /* We need to pass this field (partly) on the stack. */
6557 data->stack = 1;
6559 if (nregs <= 0)
6560 return false;
6563 *pnregs = nregs;
6564 *pmode = mode;
6565 return true;
6568 /* A subroutine of function_arg_record_value. Count the number of registers
6569 to be assigned for FIELD and between PARMS->intoffset and BITPOS. */
6571 inline void
6572 count_registers (const_tree field, HOST_WIDE_INT bitpos, bool fp,
6573 assign_data_t *data)
6575 if (fp)
6577 int nregs;
6578 machine_mode mode;
6580 if (compute_int_layout (bitpos, data, &nregs))
6581 data->nregs += nregs;
6583 if (compute_fp_layout (field, bitpos, data, &nregs, &mode))
6584 data->nregs += nregs;
6586 else
6588 if (data->intoffset < 0)
6589 data->intoffset = bitpos;
6593 /* A subroutine of function_arg_record_value. Assign the bits of the
6594 structure between PARMS->intoffset and BITPOS to integer registers. */
6596 static void
6597 assign_int_registers (HOST_WIDE_INT bitpos, assign_data_t *data)
6599 int intoffset = data->intoffset;
6600 machine_mode mode;
6601 int nregs;
6603 if (!compute_int_layout (bitpos, data, &nregs))
6604 return;
6606 /* If this is the trailing part of a word, only load that much into
6607 the register. Otherwise load the whole register. Note that in
6608 the latter case we may pick up unwanted bits. It's not a problem
6609 at the moment but may wish to revisit. */
6610 if (intoffset % BITS_PER_WORD != 0)
6611 mode = smallest_mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
6612 MODE_INT);
6613 else
6614 mode = word_mode;
6616 const int this_slotno = data->slotno + intoffset / BITS_PER_WORD;
6617 unsigned int regno = data->regbase + this_slotno;
6618 intoffset /= BITS_PER_UNIT;
6622 rtx reg = gen_rtx_REG (mode, regno);
6623 XVECEXP (data->ret, 0, data->stack + data->nregs)
6624 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
6625 data->nregs += 1;
6626 mode = word_mode;
6627 regno += 1;
6628 intoffset = (intoffset | (UNITS_PER_WORD - 1)) + 1;
6630 while (--nregs > 0);
6633 /* A subroutine of function_arg_record_value. Assign FIELD at position
6634 BITPOS to FP registers. */
6636 static void
6637 assign_fp_registers (const_tree field, HOST_WIDE_INT bitpos,
6638 assign_data_t *data)
6640 int nregs;
6641 machine_mode mode;
6643 if (!compute_fp_layout (field, bitpos, data, &nregs, &mode))
6644 return;
6646 const int this_slotno = data->slotno + bitpos / BITS_PER_WORD;
6647 int regno = SPARC_FP_ARG_FIRST + this_slotno * 2;
6648 if (GET_MODE_SIZE (mode) <= 4 && (bitpos & 32) != 0)
6649 regno++;
6650 int pos = bitpos / BITS_PER_UNIT;
6654 rtx reg = gen_rtx_REG (mode, regno);
6655 XVECEXP (data->ret, 0, data->stack + data->nregs)
6656 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (pos));
6657 data->nregs += 1;
6658 regno += GET_MODE_SIZE (mode) / 4;
6659 pos += GET_MODE_SIZE (mode);
6661 while (--nregs > 0);
6664 /* A subroutine of function_arg_record_value. Assign FIELD and the bits of
6665 the structure between PARMS->intoffset and BITPOS to registers. */
6667 inline void
6668 assign_registers (const_tree field, HOST_WIDE_INT bitpos, bool fp,
6669 assign_data_t *data)
6671 if (fp)
6673 assign_int_registers (bitpos, data);
6675 assign_fp_registers (field, bitpos, data);
6677 else
6679 if (data->intoffset < 0)
6680 data->intoffset = bitpos;
6684 /* Used by function_arg and sparc_function_value_1 to implement the complex
6685 conventions of the 64-bit ABI for passing and returning structures.
6686 Return an expression valid as a return value for the FUNCTION_ARG
6687 and TARGET_FUNCTION_VALUE.
6689 TYPE is the data type of the argument (as a tree).
6690 This is null for libcalls where that information may
6691 not be available.
6692 MODE is the argument's machine mode.
6693 SLOTNO is the index number of the argument's slot in the parameter array.
6694 NAMED is true if this argument is a named parameter
6695 (otherwise it is an extra parameter matching an ellipsis).
6696 REGBASE is the regno of the base register for the parameter array. */
6698 static rtx
6699 function_arg_record_value (const_tree type, machine_mode mode,
6700 int slotno, bool named, int regbase)
6702 HOST_WIDE_INT typesize = int_size_in_bytes (type);
6703 assign_data_t data;
6704 int nregs;
6706 data.slotno = slotno;
6707 data.regbase = regbase;
6709 /* Count how many registers we need. */
6710 data.nregs = 0;
6711 data.intoffset = 0;
6712 data.stack = false;
6713 traverse_record_type<assign_data_t, count_registers> (type, named, &data);
6715 /* Take into account pending integer fields. */
6716 if (compute_int_layout (typesize * BITS_PER_UNIT, &data, &nregs))
6717 data.nregs += nregs;
6719 /* Allocate the vector and handle some annoying special cases. */
6720 nregs = data.nregs;
6722 if (nregs == 0)
6724 /* ??? Empty structure has no value? Duh? */
6725 if (typesize <= 0)
6727 /* Though there's nothing really to store, return a word register
6728 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
6729 leads to breakage due to the fact that there are zero bytes to
6730 load. */
6731 return gen_rtx_REG (mode, regbase);
6734 /* ??? C++ has structures with no fields, and yet a size. Give up
6735 for now and pass everything back in integer registers. */
6736 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6737 if (nregs + slotno > SPARC_INT_ARG_MAX)
6738 nregs = SPARC_INT_ARG_MAX - slotno;
6741 gcc_assert (nregs > 0);
6743 data.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (data.stack + nregs));
6745 /* If at least one field must be passed on the stack, generate
6746 (parallel [(expr_list (nil) ...) ...]) so that all fields will
6747 also be passed on the stack. We can't do much better because the
6748 semantics of TARGET_ARG_PARTIAL_BYTES doesn't handle the case
6749 of structures for which the fields passed exclusively in registers
6750 are not at the beginning of the structure. */
6751 if (data.stack)
6752 XVECEXP (data.ret, 0, 0)
6753 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
6755 /* Assign the registers. */
6756 data.nregs = 0;
6757 data.intoffset = 0;
6758 traverse_record_type<assign_data_t, assign_registers> (type, named, &data);
6760 /* Assign pending integer fields. */
6761 assign_int_registers (typesize * BITS_PER_UNIT, &data);
6763 gcc_assert (data.nregs == nregs);
6765 return data.ret;
6768 /* Used by function_arg and sparc_function_value_1 to implement the conventions
6769 of the 64-bit ABI for passing and returning unions.
6770 Return an expression valid as a return value for the FUNCTION_ARG
6771 and TARGET_FUNCTION_VALUE.
6773 SIZE is the size in bytes of the union.
6774 MODE is the argument's machine mode.
6775 REGNO is the hard register the union will be passed in. */
6777 static rtx
6778 function_arg_union_value (int size, machine_mode mode, int slotno,
6779 int regno)
6781 int nwords = CEIL_NWORDS (size), i;
6782 rtx regs;
6784 /* See comment in previous function for empty structures. */
6785 if (nwords == 0)
6786 return gen_rtx_REG (mode, regno);
6788 if (slotno == SPARC_INT_ARG_MAX - 1)
6789 nwords = 1;
6791 regs = gen_rtx_PARALLEL (mode, rtvec_alloc (nwords));
6793 for (i = 0; i < nwords; i++)
6795 /* Unions are passed left-justified. */
6796 XVECEXP (regs, 0, i)
6797 = gen_rtx_EXPR_LIST (VOIDmode,
6798 gen_rtx_REG (word_mode, regno),
6799 GEN_INT (UNITS_PER_WORD * i));
6800 regno++;
6803 return regs;
6806 /* Used by function_arg and sparc_function_value_1 to implement the conventions
6807 for passing and returning BLKmode vectors.
6808 Return an expression valid as a return value for the FUNCTION_ARG
6809 and TARGET_FUNCTION_VALUE.
6811 SIZE is the size in bytes of the vector.
6812 REGNO is the FP hard register the vector will be passed in. */
6814 static rtx
6815 function_arg_vector_value (int size, int regno)
6817 const int nregs = MAX (1, size / 8);
6818 rtx regs = gen_rtx_PARALLEL (BLKmode, rtvec_alloc (nregs));
6820 if (size < 8)
6821 XVECEXP (regs, 0, 0)
6822 = gen_rtx_EXPR_LIST (VOIDmode,
6823 gen_rtx_REG (SImode, regno),
6824 const0_rtx);
6825 else
6826 for (int i = 0; i < nregs; i++)
6827 XVECEXP (regs, 0, i)
6828 = gen_rtx_EXPR_LIST (VOIDmode,
6829 gen_rtx_REG (DImode, regno + 2*i),
6830 GEN_INT (i*8));
6832 return regs;
6835 /* Determine where to put an argument to a function.
6836 Value is zero to push the argument on the stack,
6837 or a hard register in which to store the argument.
6839 CUM is a variable of type CUMULATIVE_ARGS which gives info about
6840 the preceding args and about the function being called.
6841 MODE is the argument's machine mode.
6842 TYPE is the data type of the argument (as a tree).
6843 This is null for libcalls where that information may
6844 not be available.
6845 NAMED is true if this argument is a named parameter
6846 (otherwise it is an extra parameter matching an ellipsis).
6847 INCOMING_P is false for TARGET_FUNCTION_ARG, true for
6848 TARGET_FUNCTION_INCOMING_ARG. */
6850 static rtx
6851 sparc_function_arg_1 (cumulative_args_t cum_v, machine_mode mode,
6852 const_tree type, bool named, bool incoming)
6854 const CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
6856 int regbase = (incoming
6857 ? SPARC_INCOMING_INT_ARG_FIRST
6858 : SPARC_OUTGOING_INT_ARG_FIRST);
6859 int slotno, regno, padding;
6860 enum mode_class mclass = GET_MODE_CLASS (mode);
6862 slotno = function_arg_slotno (cum, mode, type, named, incoming,
6863 &regno, &padding);
6864 if (slotno == -1)
6865 return 0;
6867 /* Vector types deserve special treatment because they are polymorphic wrt
6868 their mode, depending upon whether VIS instructions are enabled. */
6869 if (type && TREE_CODE (type) == VECTOR_TYPE)
6871 HOST_WIDE_INT size = int_size_in_bytes (type);
6872 gcc_assert ((TARGET_ARCH32 && size <= 8)
6873 || (TARGET_ARCH64 && size <= 16));
6875 if (mode == BLKmode)
6876 return function_arg_vector_value (size, SPARC_FP_ARG_FIRST + 2*slotno);
6878 mclass = MODE_FLOAT;
6881 if (TARGET_ARCH32)
6882 return gen_rtx_REG (mode, regno);
6884 /* Structures up to 16 bytes in size are passed in arg slots on the stack
6885 and are promoted to registers if possible. */
6886 if (type && TREE_CODE (type) == RECORD_TYPE)
6888 HOST_WIDE_INT size = int_size_in_bytes (type);
6889 gcc_assert (size <= 16);
6891 return function_arg_record_value (type, mode, slotno, named, regbase);
6894 /* Unions up to 16 bytes in size are passed in integer registers. */
6895 else if (type && TREE_CODE (type) == UNION_TYPE)
6897 HOST_WIDE_INT size = int_size_in_bytes (type);
6898 gcc_assert (size <= 16);
6900 return function_arg_union_value (size, mode, slotno, regno);
6903 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
6904 but also have the slot allocated for them.
6905 If no prototype is in scope fp values in register slots get passed
6906 in two places, either fp regs and int regs or fp regs and memory. */
6907 else if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
6908 && SPARC_FP_REG_P (regno))
6910 rtx reg = gen_rtx_REG (mode, regno);
6911 if (cum->prototype_p || cum->libcall_p)
6912 return reg;
6913 else
6915 rtx v0, v1;
6917 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
6919 int intreg;
6921 /* On incoming, we don't need to know that the value
6922 is passed in %f0 and %i0, and it confuses other parts
6923 causing needless spillage even on the simplest cases. */
6924 if (incoming)
6925 return reg;
6927 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
6928 + (regno - SPARC_FP_ARG_FIRST) / 2);
6930 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
6931 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
6932 const0_rtx);
6933 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
6935 else
6937 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
6938 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
6939 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
6944 /* All other aggregate types are passed in an integer register in a mode
6945 corresponding to the size of the type. */
6946 else if (type && AGGREGATE_TYPE_P (type))
6948 HOST_WIDE_INT size = int_size_in_bytes (type);
6949 gcc_assert (size <= 16);
6951 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
6954 return gen_rtx_REG (mode, regno);
6957 /* Handle the TARGET_FUNCTION_ARG target hook. */
6959 static rtx
6960 sparc_function_arg (cumulative_args_t cum, machine_mode mode,
6961 const_tree type, bool named)
6963 return sparc_function_arg_1 (cum, mode, type, named, false);
6966 /* Handle the TARGET_FUNCTION_INCOMING_ARG target hook. */
6968 static rtx
6969 sparc_function_incoming_arg (cumulative_args_t cum, machine_mode mode,
6970 const_tree type, bool named)
6972 return sparc_function_arg_1 (cum, mode, type, named, true);
6975 /* For sparc64, objects requiring 16 byte alignment are passed that way. */
6977 static unsigned int
6978 sparc_function_arg_boundary (machine_mode mode, const_tree type)
6980 return ((TARGET_ARCH64
6981 && (GET_MODE_ALIGNMENT (mode) == 128
6982 || (type && TYPE_ALIGN (type) == 128)))
6983 ? 128
6984 : PARM_BOUNDARY);
6987 /* For an arg passed partly in registers and partly in memory,
6988 this is the number of bytes of registers used.
6989 For args passed entirely in registers or entirely in memory, zero.
6991 Any arg that starts in the first 6 regs but won't entirely fit in them
6992 needs partial registers on v8. On v9, structures with integer
6993 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
6994 values that begin in the last fp reg [where "last fp reg" varies with the
6995 mode] will be split between that reg and memory. */
6997 static int
6998 sparc_arg_partial_bytes (cumulative_args_t cum, machine_mode mode,
6999 tree type, bool named)
7001 int slotno, regno, padding;
7003 /* We pass false for incoming here, it doesn't matter. */
7004 slotno = function_arg_slotno (get_cumulative_args (cum), mode, type, named,
7005 false, &regno, &padding);
7007 if (slotno == -1)
7008 return 0;
7010 if (TARGET_ARCH32)
7012 if ((slotno + (mode == BLKmode
7013 ? CEIL_NWORDS (int_size_in_bytes (type))
7014 : CEIL_NWORDS (GET_MODE_SIZE (mode))))
7015 > SPARC_INT_ARG_MAX)
7016 return (SPARC_INT_ARG_MAX - slotno) * UNITS_PER_WORD;
7018 else
7020 /* We are guaranteed by pass_by_reference that the size of the
7021 argument is not greater than 16 bytes, so we only need to return
7022 one word if the argument is partially passed in registers. */
7024 if (type && AGGREGATE_TYPE_P (type))
7026 int size = int_size_in_bytes (type);
7028 if (size > UNITS_PER_WORD
7029 && (slotno == SPARC_INT_ARG_MAX - 1
7030 || slotno == SPARC_FP_ARG_MAX - 1))
7031 return UNITS_PER_WORD;
7033 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
7034 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
7035 && ! (TARGET_FPU && named)))
7037 /* The complex types are passed as packed types. */
7038 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
7039 && slotno == SPARC_INT_ARG_MAX - 1)
7040 return UNITS_PER_WORD;
7042 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
7044 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
7045 > SPARC_FP_ARG_MAX)
7046 return UNITS_PER_WORD;
7050 return 0;
7053 /* Handle the TARGET_PASS_BY_REFERENCE target hook.
7054 Specify whether to pass the argument by reference. */
7056 static bool
7057 sparc_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED,
7058 machine_mode mode, const_tree type,
7059 bool named ATTRIBUTE_UNUSED)
7061 if (TARGET_ARCH32)
7062 /* Original SPARC 32-bit ABI says that structures and unions,
7063 and quad-precision floats are passed by reference. For Pascal,
7064 also pass arrays by reference. All other base types are passed
7065 in registers.
7067 Extended ABI (as implemented by the Sun compiler) says that all
7068 complex floats are passed by reference. Pass complex integers
7069 in registers up to 8 bytes. More generally, enforce the 2-word
7070 cap for passing arguments in registers.
7072 Vector ABI (as implemented by the Sun VIS SDK) says that vector
7073 integers are passed like floats of the same size, that is in
7074 registers up to 8 bytes. Pass all vector floats by reference
7075 like structure and unions. */
7076 return ((type && (AGGREGATE_TYPE_P (type) || VECTOR_FLOAT_TYPE_P (type)))
7077 || mode == SCmode
7078 /* Catch CDImode, TFmode, DCmode and TCmode. */
7079 || GET_MODE_SIZE (mode) > 8
7080 || (type
7081 && TREE_CODE (type) == VECTOR_TYPE
7082 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
7083 else
7084 /* Original SPARC 64-bit ABI says that structures and unions
7085 smaller than 16 bytes are passed in registers, as well as
7086 all other base types.
7088 Extended ABI (as implemented by the Sun compiler) says that
7089 complex floats are passed in registers up to 16 bytes. Pass
7090 all complex integers in registers up to 16 bytes. More generally,
7091 enforce the 2-word cap for passing arguments in registers.
7093 Vector ABI (as implemented by the Sun VIS SDK) says that vector
7094 integers are passed like floats of the same size, that is in
7095 registers (up to 16 bytes). Pass all vector floats like structure
7096 and unions. */
7097 return ((type
7098 && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == VECTOR_TYPE)
7099 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16)
7100 /* Catch CTImode and TCmode. */
7101 || GET_MODE_SIZE (mode) > 16);
7104 /* Handle the TARGET_FUNCTION_ARG_ADVANCE hook.
7105 Update the data in CUM to advance over an argument
7106 of mode MODE and data type TYPE.
7107 TYPE is null for libcalls where that information may not be available. */
7109 static void
7110 sparc_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
7111 const_tree type, bool named)
7113 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7114 int regno, padding;
7116 /* We pass false for incoming here, it doesn't matter. */
7117 function_arg_slotno (cum, mode, type, named, false, &regno, &padding);
7119 /* If argument requires leading padding, add it. */
7120 cum->words += padding;
7122 if (TARGET_ARCH32)
7123 cum->words += (mode == BLKmode
7124 ? CEIL_NWORDS (int_size_in_bytes (type))
7125 : CEIL_NWORDS (GET_MODE_SIZE (mode)));
7126 else
7128 if (type && AGGREGATE_TYPE_P (type))
7130 int size = int_size_in_bytes (type);
7132 if (size <= 8)
7133 ++cum->words;
7134 else if (size <= 16)
7135 cum->words += 2;
7136 else /* passed by reference */
7137 ++cum->words;
7139 else
7140 cum->words += (mode == BLKmode
7141 ? CEIL_NWORDS (int_size_in_bytes (type))
7142 : CEIL_NWORDS (GET_MODE_SIZE (mode)));
7146 /* Handle the FUNCTION_ARG_PADDING macro.
7147 For the 64 bit ABI structs are always stored left shifted in their
7148 argument slot. */
7150 enum direction
7151 function_arg_padding (machine_mode mode, const_tree type)
7153 if (TARGET_ARCH64 && type && AGGREGATE_TYPE_P (type))
7154 return upward;
7156 /* Fall back to the default. */
7157 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
7160 /* Handle the TARGET_RETURN_IN_MEMORY target hook.
7161 Specify whether to return the return value in memory. */
7163 static bool
7164 sparc_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
7166 if (TARGET_ARCH32)
7167 /* Original SPARC 32-bit ABI says that structures and unions,
7168 and quad-precision floats are returned in memory. All other
7169 base types are returned in registers.
7171 Extended ABI (as implemented by the Sun compiler) says that
7172 all complex floats are returned in registers (8 FP registers
7173 at most for '_Complex long double'). Return all complex integers
7174 in registers (4 at most for '_Complex long long').
7176 Vector ABI (as implemented by the Sun VIS SDK) says that vector
7177 integers are returned like floats of the same size, that is in
7178 registers up to 8 bytes and in memory otherwise. Return all
7179 vector floats in memory like structure and unions; note that
7180 they always have BLKmode like the latter. */
7181 return (TYPE_MODE (type) == BLKmode
7182 || TYPE_MODE (type) == TFmode
7183 || (TREE_CODE (type) == VECTOR_TYPE
7184 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8));
7185 else
7186 /* Original SPARC 64-bit ABI says that structures and unions
7187 smaller than 32 bytes are returned in registers, as well as
7188 all other base types.
7190 Extended ABI (as implemented by the Sun compiler) says that all
7191 complex floats are returned in registers (8 FP registers at most
7192 for '_Complex long double'). Return all complex integers in
7193 registers (4 at most for '_Complex TItype').
7195 Vector ABI (as implemented by the Sun VIS SDK) says that vector
7196 integers are returned like floats of the same size, that is in
7197 registers. Return all vector floats like structure and unions;
7198 note that they always have BLKmode like the latter. */
7199 return (TYPE_MODE (type) == BLKmode
7200 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 32);
7203 /* Handle the TARGET_STRUCT_VALUE target hook.
7204 Return where to find the structure return value address. */
7206 static rtx
7207 sparc_struct_value_rtx (tree fndecl, int incoming)
7209 if (TARGET_ARCH64)
7210 return 0;
7211 else
7213 rtx mem;
7215 if (incoming)
7216 mem = gen_frame_mem (Pmode, plus_constant (Pmode, frame_pointer_rtx,
7217 STRUCT_VALUE_OFFSET));
7218 else
7219 mem = gen_frame_mem (Pmode, plus_constant (Pmode, stack_pointer_rtx,
7220 STRUCT_VALUE_OFFSET));
7222 /* Only follow the SPARC ABI for fixed-size structure returns.
7223 Variable size structure returns are handled per the normal
7224 procedures in GCC. This is enabled by -mstd-struct-return */
7225 if (incoming == 2
7226 && sparc_std_struct_return
7227 && TYPE_SIZE_UNIT (TREE_TYPE (fndecl))
7228 && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (fndecl))) == INTEGER_CST)
7230 /* We must check and adjust the return address, as it is optional
7231 as to whether the return object is really provided. */
7232 rtx ret_reg = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
7233 rtx scratch = gen_reg_rtx (SImode);
7234 rtx_code_label *endlab = gen_label_rtx ();
7236 /* Calculate the return object size. */
7237 tree size = TYPE_SIZE_UNIT (TREE_TYPE (fndecl));
7238 rtx size_rtx = GEN_INT (TREE_INT_CST_LOW (size) & 0xfff);
7239 /* Construct a temporary return value. */
7240 rtx temp_val
7241 = assign_stack_local (Pmode, TREE_INT_CST_LOW (size), 0);
7243 /* Implement SPARC 32-bit psABI callee return struct checking:
7245 Fetch the instruction where we will return to and see if
7246 it's an unimp instruction (the most significant 10 bits
7247 will be zero). */
7248 emit_move_insn (scratch, gen_rtx_MEM (SImode,
7249 plus_constant (Pmode,
7250 ret_reg, 8)));
7251 /* Assume the size is valid and pre-adjust. */
7252 emit_insn (gen_add3_insn (ret_reg, ret_reg, GEN_INT (4)));
7253 emit_cmp_and_jump_insns (scratch, size_rtx, EQ, const0_rtx, SImode,
7254 0, endlab);
7255 emit_insn (gen_sub3_insn (ret_reg, ret_reg, GEN_INT (4)));
7256 /* Write the address of the memory pointed to by temp_val into
7257 the memory pointed to by mem. */
7258 emit_move_insn (mem, XEXP (temp_val, 0));
7259 emit_label (endlab);
7262 return mem;
7266 /* Handle TARGET_FUNCTION_VALUE, and TARGET_LIBCALL_VALUE target hook.
7267 For v9, function return values are subject to the same rules as arguments,
7268 except that up to 32 bytes may be returned in registers. */
7270 static rtx
7271 sparc_function_value_1 (const_tree type, machine_mode mode,
7272 bool outgoing)
7274 /* Beware that the two values are swapped here wrt function_arg. */
7275 int regbase = (outgoing
7276 ? SPARC_INCOMING_INT_ARG_FIRST
7277 : SPARC_OUTGOING_INT_ARG_FIRST);
7278 enum mode_class mclass = GET_MODE_CLASS (mode);
7279 int regno;
7281 /* Vector types deserve special treatment because they are polymorphic wrt
7282 their mode, depending upon whether VIS instructions are enabled. */
7283 if (type && TREE_CODE (type) == VECTOR_TYPE)
7285 HOST_WIDE_INT size = int_size_in_bytes (type);
7286 gcc_assert ((TARGET_ARCH32 && size <= 8)
7287 || (TARGET_ARCH64 && size <= 32));
7289 if (mode == BLKmode)
7290 return function_arg_vector_value (size, SPARC_FP_ARG_FIRST);
7292 mclass = MODE_FLOAT;
7295 if (TARGET_ARCH64 && type)
7297 /* Structures up to 32 bytes in size are returned in registers. */
7298 if (TREE_CODE (type) == RECORD_TYPE)
7300 HOST_WIDE_INT size = int_size_in_bytes (type);
7301 gcc_assert (size <= 32);
7303 return function_arg_record_value (type, mode, 0, 1, regbase);
7306 /* Unions up to 32 bytes in size are returned in integer registers. */
7307 else if (TREE_CODE (type) == UNION_TYPE)
7309 HOST_WIDE_INT size = int_size_in_bytes (type);
7310 gcc_assert (size <= 32);
7312 return function_arg_union_value (size, mode, 0, regbase);
7315 /* Objects that require it are returned in FP registers. */
7316 else if (mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT)
7319 /* All other aggregate types are returned in an integer register in a
7320 mode corresponding to the size of the type. */
7321 else if (AGGREGATE_TYPE_P (type))
7323 /* All other aggregate types are passed in an integer register
7324 in a mode corresponding to the size of the type. */
7325 HOST_WIDE_INT size = int_size_in_bytes (type);
7326 gcc_assert (size <= 32);
7328 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
7330 /* ??? We probably should have made the same ABI change in
7331 3.4.0 as the one we made for unions. The latter was
7332 required by the SCD though, while the former is not
7333 specified, so we favored compatibility and efficiency.
7335 Now we're stuck for aggregates larger than 16 bytes,
7336 because OImode vanished in the meantime. Let's not
7337 try to be unduly clever, and simply follow the ABI
7338 for unions in that case. */
7339 if (mode == BLKmode)
7340 return function_arg_union_value (size, mode, 0, regbase);
7341 else
7342 mclass = MODE_INT;
7345 /* We should only have pointer and integer types at this point. This
7346 must match sparc_promote_function_mode. */
7347 else if (mclass == MODE_INT && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
7348 mode = word_mode;
7351 /* We should only have pointer and integer types at this point, except with
7352 -freg-struct-return. This must match sparc_promote_function_mode. */
7353 else if (TARGET_ARCH32
7354 && !(type && AGGREGATE_TYPE_P (type))
7355 && mclass == MODE_INT
7356 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
7357 mode = word_mode;
7359 if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT) && TARGET_FPU)
7360 regno = SPARC_FP_ARG_FIRST;
7361 else
7362 regno = regbase;
7364 return gen_rtx_REG (mode, regno);
7367 /* Handle TARGET_FUNCTION_VALUE.
7368 On the SPARC, the value is found in the first "output" register, but the
7369 called function leaves it in the first "input" register. */
7371 static rtx
7372 sparc_function_value (const_tree valtype,
7373 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
7374 bool outgoing)
7376 return sparc_function_value_1 (valtype, TYPE_MODE (valtype), outgoing);
7379 /* Handle TARGET_LIBCALL_VALUE. */
7381 static rtx
7382 sparc_libcall_value (machine_mode mode,
7383 const_rtx fun ATTRIBUTE_UNUSED)
7385 return sparc_function_value_1 (NULL_TREE, mode, false);
7388 /* Handle FUNCTION_VALUE_REGNO_P.
7389 On the SPARC, the first "output" reg is used for integer values, and the
7390 first floating point register is used for floating point values. */
7392 static bool
7393 sparc_function_value_regno_p (const unsigned int regno)
7395 return (regno == 8 || (TARGET_FPU && regno == 32));
7398 /* Do what is necessary for `va_start'. We look at the current function
7399 to determine if stdarg or varargs is used and return the address of
7400 the first unnamed parameter. */
7402 static rtx
7403 sparc_builtin_saveregs (void)
7405 int first_reg = crtl->args.info.words;
7406 rtx address;
7407 int regno;
7409 for (regno = first_reg; regno < SPARC_INT_ARG_MAX; regno++)
7410 emit_move_insn (gen_rtx_MEM (word_mode,
7411 gen_rtx_PLUS (Pmode,
7412 frame_pointer_rtx,
7413 GEN_INT (FIRST_PARM_OFFSET (0)
7414 + (UNITS_PER_WORD
7415 * regno)))),
7416 gen_rtx_REG (word_mode,
7417 SPARC_INCOMING_INT_ARG_FIRST + regno));
7419 address = gen_rtx_PLUS (Pmode,
7420 frame_pointer_rtx,
7421 GEN_INT (FIRST_PARM_OFFSET (0)
7422 + UNITS_PER_WORD * first_reg));
7424 return address;
7427 /* Implement `va_start' for stdarg. */
7429 static void
7430 sparc_va_start (tree valist, rtx nextarg)
7432 nextarg = expand_builtin_saveregs ();
7433 std_expand_builtin_va_start (valist, nextarg);
7436 /* Implement `va_arg' for stdarg. */
7438 static tree
7439 sparc_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
7440 gimple_seq *post_p)
7442 HOST_WIDE_INT size, rsize, align;
7443 tree addr, incr;
7444 bool indirect;
7445 tree ptrtype = build_pointer_type (type);
7447 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
7449 indirect = true;
7450 size = rsize = UNITS_PER_WORD;
7451 align = 0;
7453 else
7455 indirect = false;
7456 size = int_size_in_bytes (type);
7457 rsize = ROUND_UP (size, UNITS_PER_WORD);
7458 align = 0;
7460 if (TARGET_ARCH64)
7462 /* For SPARC64, objects requiring 16-byte alignment get it. */
7463 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
7464 align = 2 * UNITS_PER_WORD;
7466 /* SPARC-V9 ABI states that structures up to 16 bytes in size
7467 are left-justified in their slots. */
7468 if (AGGREGATE_TYPE_P (type))
7470 if (size == 0)
7471 size = rsize = UNITS_PER_WORD;
7472 else
7473 size = rsize;
7478 incr = valist;
7479 if (align)
7481 incr = fold_build_pointer_plus_hwi (incr, align - 1);
7482 incr = fold_convert (sizetype, incr);
7483 incr = fold_build2 (BIT_AND_EXPR, sizetype, incr,
7484 size_int (-align));
7485 incr = fold_convert (ptr_type_node, incr);
7488 gimplify_expr (&incr, pre_p, post_p, is_gimple_val, fb_rvalue);
7489 addr = incr;
7491 if (BYTES_BIG_ENDIAN && size < rsize)
7492 addr = fold_build_pointer_plus_hwi (incr, rsize - size);
7494 if (indirect)
7496 addr = fold_convert (build_pointer_type (ptrtype), addr);
7497 addr = build_va_arg_indirect_ref (addr);
7500 /* If the address isn't aligned properly for the type, we need a temporary.
7501 FIXME: This is inefficient, usually we can do this in registers. */
7502 else if (align == 0 && TYPE_ALIGN (type) > BITS_PER_WORD)
7504 tree tmp = create_tmp_var (type, "va_arg_tmp");
7505 tree dest_addr = build_fold_addr_expr (tmp);
7506 tree copy = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY),
7507 3, dest_addr, addr, size_int (rsize));
7508 TREE_ADDRESSABLE (tmp) = 1;
7509 gimplify_and_add (copy, pre_p);
7510 addr = dest_addr;
7513 else
7514 addr = fold_convert (ptrtype, addr);
7516 incr = fold_build_pointer_plus_hwi (incr, rsize);
7517 gimplify_assign (valist, incr, post_p);
7519 return build_va_arg_indirect_ref (addr);
7522 /* Implement the TARGET_VECTOR_MODE_SUPPORTED_P target hook.
7523 Specify whether the vector mode is supported by the hardware. */
7525 static bool
7526 sparc_vector_mode_supported_p (machine_mode mode)
7528 return TARGET_VIS && VECTOR_MODE_P (mode) ? true : false;
7531 /* Implement the TARGET_VECTORIZE_PREFERRED_SIMD_MODE target hook. */
7533 static machine_mode
7534 sparc_preferred_simd_mode (machine_mode mode)
7536 if (TARGET_VIS)
7537 switch (mode)
7539 case SImode:
7540 return V2SImode;
7541 case HImode:
7542 return V4HImode;
7543 case QImode:
7544 return V8QImode;
7546 default:;
7549 return word_mode;
7552 /* Return the string to output an unconditional branch to LABEL, which is
7553 the operand number of the label.
7555 DEST is the destination insn (i.e. the label), INSN is the source. */
7557 const char *
7558 output_ubranch (rtx dest, rtx_insn *insn)
7560 static char string[64];
7561 bool v9_form = false;
7562 int delta;
7563 char *p;
7565 /* Even if we are trying to use cbcond for this, evaluate
7566 whether we can use V9 branches as our backup plan. */
7568 delta = 5000000;
7569 if (INSN_ADDRESSES_SET_P ())
7570 delta = (INSN_ADDRESSES (INSN_UID (dest))
7571 - INSN_ADDRESSES (INSN_UID (insn)));
7573 /* Leave some instructions for "slop". */
7574 if (TARGET_V9 && delta >= -260000 && delta < 260000)
7575 v9_form = true;
7577 if (TARGET_CBCOND)
7579 bool emit_nop = emit_cbcond_nop (insn);
7580 bool far = false;
7581 const char *rval;
7583 if (delta < -500 || delta > 500)
7584 far = true;
7586 if (far)
7588 if (v9_form)
7589 rval = "ba,a,pt\t%%xcc, %l0";
7590 else
7591 rval = "b,a\t%l0";
7593 else
7595 if (emit_nop)
7596 rval = "cwbe\t%%g0, %%g0, %l0\n\tnop";
7597 else
7598 rval = "cwbe\t%%g0, %%g0, %l0";
7600 return rval;
7603 if (v9_form)
7604 strcpy (string, "ba%*,pt\t%%xcc, ");
7605 else
7606 strcpy (string, "b%*\t");
7608 p = strchr (string, '\0');
7609 *p++ = '%';
7610 *p++ = 'l';
7611 *p++ = '0';
7612 *p++ = '%';
7613 *p++ = '(';
7614 *p = '\0';
7616 return string;
7619 /* Return the string to output a conditional branch to LABEL, which is
7620 the operand number of the label. OP is the conditional expression.
7621 XEXP (OP, 0) is assumed to be a condition code register (integer or
7622 floating point) and its mode specifies what kind of comparison we made.
7624 DEST is the destination insn (i.e. the label), INSN is the source.
7626 REVERSED is nonzero if we should reverse the sense of the comparison.
7628 ANNUL is nonzero if we should generate an annulling branch. */
7630 const char *
7631 output_cbranch (rtx op, rtx dest, int label, int reversed, int annul,
7632 rtx_insn *insn)
7634 static char string[64];
7635 enum rtx_code code = GET_CODE (op);
7636 rtx cc_reg = XEXP (op, 0);
7637 machine_mode mode = GET_MODE (cc_reg);
7638 const char *labelno, *branch;
7639 int spaces = 8, far;
7640 char *p;
7642 /* v9 branches are limited to +-1MB. If it is too far away,
7643 change
7645 bne,pt %xcc, .LC30
7649 be,pn %xcc, .+12
7651 ba .LC30
7655 fbne,a,pn %fcc2, .LC29
7659 fbe,pt %fcc2, .+16
7661 ba .LC29 */
7663 far = TARGET_V9 && (get_attr_length (insn) >= 3);
7664 if (reversed ^ far)
7666 /* Reversal of FP compares takes care -- an ordered compare
7667 becomes an unordered compare and vice versa. */
7668 if (mode == CCFPmode || mode == CCFPEmode)
7669 code = reverse_condition_maybe_unordered (code);
7670 else
7671 code = reverse_condition (code);
7674 /* Start by writing the branch condition. */
7675 if (mode == CCFPmode || mode == CCFPEmode)
7677 switch (code)
7679 case NE:
7680 branch = "fbne";
7681 break;
7682 case EQ:
7683 branch = "fbe";
7684 break;
7685 case GE:
7686 branch = "fbge";
7687 break;
7688 case GT:
7689 branch = "fbg";
7690 break;
7691 case LE:
7692 branch = "fble";
7693 break;
7694 case LT:
7695 branch = "fbl";
7696 break;
7697 case UNORDERED:
7698 branch = "fbu";
7699 break;
7700 case ORDERED:
7701 branch = "fbo";
7702 break;
7703 case UNGT:
7704 branch = "fbug";
7705 break;
7706 case UNLT:
7707 branch = "fbul";
7708 break;
7709 case UNEQ:
7710 branch = "fbue";
7711 break;
7712 case UNGE:
7713 branch = "fbuge";
7714 break;
7715 case UNLE:
7716 branch = "fbule";
7717 break;
7718 case LTGT:
7719 branch = "fblg";
7720 break;
7721 default:
7722 gcc_unreachable ();
7725 /* ??? !v9: FP branches cannot be preceded by another floating point
7726 insn. Because there is currently no concept of pre-delay slots,
7727 we can fix this only by always emitting a nop before a floating
7728 point branch. */
7730 string[0] = '\0';
7731 if (! TARGET_V9)
7732 strcpy (string, "nop\n\t");
7733 strcat (string, branch);
7735 else
7737 switch (code)
7739 case NE:
7740 if (mode == CCVmode || mode == CCXVmode)
7741 branch = "bvs";
7742 else
7743 branch = "bne";
7744 break;
7745 case EQ:
7746 if (mode == CCVmode || mode == CCXVmode)
7747 branch = "bvc";
7748 else
7749 branch = "be";
7750 break;
7751 case GE:
7752 if (mode == CCNZmode || mode == CCXNZmode)
7753 branch = "bpos";
7754 else
7755 branch = "bge";
7756 break;
7757 case GT:
7758 branch = "bg";
7759 break;
7760 case LE:
7761 branch = "ble";
7762 break;
7763 case LT:
7764 if (mode == CCNZmode || mode == CCXNZmode)
7765 branch = "bneg";
7766 else
7767 branch = "bl";
7768 break;
7769 case GEU:
7770 branch = "bgeu";
7771 break;
7772 case GTU:
7773 branch = "bgu";
7774 break;
7775 case LEU:
7776 branch = "bleu";
7777 break;
7778 case LTU:
7779 branch = "blu";
7780 break;
7781 default:
7782 gcc_unreachable ();
7784 strcpy (string, branch);
7786 spaces -= strlen (branch);
7787 p = strchr (string, '\0');
7789 /* Now add the annulling, the label, and a possible noop. */
7790 if (annul && ! far)
7792 strcpy (p, ",a");
7793 p += 2;
7794 spaces -= 2;
7797 if (TARGET_V9)
7799 rtx note;
7800 int v8 = 0;
7802 if (! far && insn && INSN_ADDRESSES_SET_P ())
7804 int delta = (INSN_ADDRESSES (INSN_UID (dest))
7805 - INSN_ADDRESSES (INSN_UID (insn)));
7806 /* Leave some instructions for "slop". */
7807 if (delta < -260000 || delta >= 260000)
7808 v8 = 1;
7811 switch (mode)
7813 case CCmode:
7814 case CCNZmode:
7815 case CCCmode:
7816 case CCVmode:
7817 labelno = "%%icc, ";
7818 if (v8)
7819 labelno = "";
7820 break;
7821 case CCXmode:
7822 case CCXNZmode:
7823 case CCXCmode:
7824 case CCXVmode:
7825 labelno = "%%xcc, ";
7826 gcc_assert (!v8);
7827 break;
7828 case CCFPmode:
7829 case CCFPEmode:
7831 static char v9_fcc_labelno[] = "%%fccX, ";
7832 /* Set the char indicating the number of the fcc reg to use. */
7833 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
7834 labelno = v9_fcc_labelno;
7835 if (v8)
7837 gcc_assert (REGNO (cc_reg) == SPARC_FCC_REG);
7838 labelno = "";
7841 break;
7842 default:
7843 gcc_unreachable ();
7846 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
7848 strcpy (p,
7849 ((XINT (note, 0) >= REG_BR_PROB_BASE / 2) ^ far)
7850 ? ",pt" : ",pn");
7851 p += 3;
7852 spaces -= 3;
7855 else
7856 labelno = "";
7858 if (spaces > 0)
7859 *p++ = '\t';
7860 else
7861 *p++ = ' ';
7862 strcpy (p, labelno);
7863 p = strchr (p, '\0');
7864 if (far)
7866 strcpy (p, ".+12\n\t nop\n\tb\t");
7867 /* Skip the next insn if requested or
7868 if we know that it will be a nop. */
7869 if (annul || ! final_sequence)
7870 p[3] = '6';
7871 p += 14;
7873 *p++ = '%';
7874 *p++ = 'l';
7875 *p++ = label + '0';
7876 *p++ = '%';
7877 *p++ = '#';
7878 *p = '\0';
7880 return string;
7883 /* Emit a library call comparison between floating point X and Y.
7884 COMPARISON is the operator to compare with (EQ, NE, GT, etc).
7885 Return the new operator to be used in the comparison sequence.
7887 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
7888 values as arguments instead of the TFmode registers themselves,
7889 that's why we cannot call emit_float_lib_cmp. */
7892 sparc_emit_float_lib_cmp (rtx x, rtx y, enum rtx_code comparison)
7894 const char *qpfunc;
7895 rtx slot0, slot1, result, tem, tem2, libfunc;
7896 machine_mode mode;
7897 enum rtx_code new_comparison;
7899 switch (comparison)
7901 case EQ:
7902 qpfunc = (TARGET_ARCH64 ? "_Qp_feq" : "_Q_feq");
7903 break;
7905 case NE:
7906 qpfunc = (TARGET_ARCH64 ? "_Qp_fne" : "_Q_fne");
7907 break;
7909 case GT:
7910 qpfunc = (TARGET_ARCH64 ? "_Qp_fgt" : "_Q_fgt");
7911 break;
7913 case GE:
7914 qpfunc = (TARGET_ARCH64 ? "_Qp_fge" : "_Q_fge");
7915 break;
7917 case LT:
7918 qpfunc = (TARGET_ARCH64 ? "_Qp_flt" : "_Q_flt");
7919 break;
7921 case LE:
7922 qpfunc = (TARGET_ARCH64 ? "_Qp_fle" : "_Q_fle");
7923 break;
7925 case ORDERED:
7926 case UNORDERED:
7927 case UNGT:
7928 case UNLT:
7929 case UNEQ:
7930 case UNGE:
7931 case UNLE:
7932 case LTGT:
7933 qpfunc = (TARGET_ARCH64 ? "_Qp_cmp" : "_Q_cmp");
7934 break;
7936 default:
7937 gcc_unreachable ();
7940 if (TARGET_ARCH64)
7942 if (MEM_P (x))
7944 tree expr = MEM_EXPR (x);
7945 if (expr)
7946 mark_addressable (expr);
7947 slot0 = x;
7949 else
7951 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode));
7952 emit_move_insn (slot0, x);
7955 if (MEM_P (y))
7957 tree expr = MEM_EXPR (y);
7958 if (expr)
7959 mark_addressable (expr);
7960 slot1 = y;
7962 else
7964 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode));
7965 emit_move_insn (slot1, y);
7968 libfunc = gen_rtx_SYMBOL_REF (Pmode, qpfunc);
7969 emit_library_call (libfunc, LCT_NORMAL,
7970 DImode, 2,
7971 XEXP (slot0, 0), Pmode,
7972 XEXP (slot1, 0), Pmode);
7973 mode = DImode;
7975 else
7977 libfunc = gen_rtx_SYMBOL_REF (Pmode, qpfunc);
7978 emit_library_call (libfunc, LCT_NORMAL,
7979 SImode, 2,
7980 x, TFmode, y, TFmode);
7981 mode = SImode;
7985 /* Immediately move the result of the libcall into a pseudo
7986 register so reload doesn't clobber the value if it needs
7987 the return register for a spill reg. */
7988 result = gen_reg_rtx (mode);
7989 emit_move_insn (result, hard_libcall_value (mode, libfunc));
7991 switch (comparison)
7993 default:
7994 return gen_rtx_NE (VOIDmode, result, const0_rtx);
7995 case ORDERED:
7996 case UNORDERED:
7997 new_comparison = (comparison == UNORDERED ? EQ : NE);
7998 return gen_rtx_fmt_ee (new_comparison, VOIDmode, result, GEN_INT(3));
7999 case UNGT:
8000 case UNGE:
8001 new_comparison = (comparison == UNGT ? GT : NE);
8002 return gen_rtx_fmt_ee (new_comparison, VOIDmode, result, const1_rtx);
8003 case UNLE:
8004 return gen_rtx_NE (VOIDmode, result, const2_rtx);
8005 case UNLT:
8006 tem = gen_reg_rtx (mode);
8007 if (TARGET_ARCH32)
8008 emit_insn (gen_andsi3 (tem, result, const1_rtx));
8009 else
8010 emit_insn (gen_anddi3 (tem, result, const1_rtx));
8011 return gen_rtx_NE (VOIDmode, tem, const0_rtx);
8012 case UNEQ:
8013 case LTGT:
8014 tem = gen_reg_rtx (mode);
8015 if (TARGET_ARCH32)
8016 emit_insn (gen_addsi3 (tem, result, const1_rtx));
8017 else
8018 emit_insn (gen_adddi3 (tem, result, const1_rtx));
8019 tem2 = gen_reg_rtx (mode);
8020 if (TARGET_ARCH32)
8021 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
8022 else
8023 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
8024 new_comparison = (comparison == UNEQ ? EQ : NE);
8025 return gen_rtx_fmt_ee (new_comparison, VOIDmode, tem2, const0_rtx);
8028 gcc_unreachable ();
8031 /* Generate an unsigned DImode to FP conversion. This is the same code
8032 optabs would emit if we didn't have TFmode patterns. */
8034 void
8035 sparc_emit_floatunsdi (rtx *operands, machine_mode mode)
8037 rtx i0, i1, f0, in, out;
8039 out = operands[0];
8040 in = force_reg (DImode, operands[1]);
8041 rtx_code_label *neglab = gen_label_rtx ();
8042 rtx_code_label *donelab = gen_label_rtx ();
8043 i0 = gen_reg_rtx (DImode);
8044 i1 = gen_reg_rtx (DImode);
8045 f0 = gen_reg_rtx (mode);
8047 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
8049 emit_insn (gen_rtx_SET (out, gen_rtx_FLOAT (mode, in)));
8050 emit_jump_insn (gen_jump (donelab));
8051 emit_barrier ();
8053 emit_label (neglab);
8055 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
8056 emit_insn (gen_anddi3 (i1, in, const1_rtx));
8057 emit_insn (gen_iordi3 (i0, i0, i1));
8058 emit_insn (gen_rtx_SET (f0, gen_rtx_FLOAT (mode, i0)));
8059 emit_insn (gen_rtx_SET (out, gen_rtx_PLUS (mode, f0, f0)));
8061 emit_label (donelab);
8064 /* Generate an FP to unsigned DImode conversion. This is the same code
8065 optabs would emit if we didn't have TFmode patterns. */
8067 void
8068 sparc_emit_fixunsdi (rtx *operands, machine_mode mode)
8070 rtx i0, i1, f0, in, out, limit;
8072 out = operands[0];
8073 in = force_reg (mode, operands[1]);
8074 rtx_code_label *neglab = gen_label_rtx ();
8075 rtx_code_label *donelab = gen_label_rtx ();
8076 i0 = gen_reg_rtx (DImode);
8077 i1 = gen_reg_rtx (DImode);
8078 limit = gen_reg_rtx (mode);
8079 f0 = gen_reg_rtx (mode);
8081 emit_move_insn (limit,
8082 const_double_from_real_value (
8083 REAL_VALUE_ATOF ("9223372036854775808.0", mode), mode));
8084 emit_cmp_and_jump_insns (in, limit, GE, NULL_RTX, mode, 0, neglab);
8086 emit_insn (gen_rtx_SET (out,
8087 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, in))));
8088 emit_jump_insn (gen_jump (donelab));
8089 emit_barrier ();
8091 emit_label (neglab);
8093 emit_insn (gen_rtx_SET (f0, gen_rtx_MINUS (mode, in, limit)));
8094 emit_insn (gen_rtx_SET (i0,
8095 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, f0))));
8096 emit_insn (gen_movdi (i1, const1_rtx));
8097 emit_insn (gen_ashldi3 (i1, i1, GEN_INT (63)));
8098 emit_insn (gen_xordi3 (out, i0, i1));
8100 emit_label (donelab);
8103 /* Return the string to output a compare and branch instruction to DEST.
8104 DEST is the destination insn (i.e. the label), INSN is the source,
8105 and OP is the conditional expression. */
8107 const char *
8108 output_cbcond (rtx op, rtx dest, rtx_insn *insn)
8110 machine_mode mode = GET_MODE (XEXP (op, 0));
8111 enum rtx_code code = GET_CODE (op);
8112 const char *cond_str, *tmpl;
8113 int far, emit_nop, len;
8114 static char string[64];
8115 char size_char;
8117 /* Compare and Branch is limited to +-2KB. If it is too far away,
8118 change
8120 cxbne X, Y, .LC30
8124 cxbe X, Y, .+16
8126 ba,pt xcc, .LC30
8127 nop */
8129 len = get_attr_length (insn);
8131 far = len == 4;
8132 emit_nop = len == 2;
8134 if (far)
8135 code = reverse_condition (code);
8137 size_char = ((mode == SImode) ? 'w' : 'x');
8139 switch (code)
8141 case NE:
8142 cond_str = "ne";
8143 break;
8145 case EQ:
8146 cond_str = "e";
8147 break;
8149 case GE:
8150 cond_str = "ge";
8151 break;
8153 case GT:
8154 cond_str = "g";
8155 break;
8157 case LE:
8158 cond_str = "le";
8159 break;
8161 case LT:
8162 cond_str = "l";
8163 break;
8165 case GEU:
8166 cond_str = "cc";
8167 break;
8169 case GTU:
8170 cond_str = "gu";
8171 break;
8173 case LEU:
8174 cond_str = "leu";
8175 break;
8177 case LTU:
8178 cond_str = "cs";
8179 break;
8181 default:
8182 gcc_unreachable ();
8185 if (far)
8187 int veryfar = 1, delta;
8189 if (INSN_ADDRESSES_SET_P ())
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;
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";
8203 else
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";
8211 snprintf (string, sizeof(string), tmpl, size_char, cond_str);
8213 return string;
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.
8221 DEST is the destination insn (i.e. the label), INSN is the source.
8223 REVERSED is nonzero if we should reverse the sense of the comparison.
8225 ANNUL is nonzero if we should generate an annulling branch. */
8227 const char *
8228 output_v9branch (rtx op, rtx dest, int reg, int label, int reversed,
8229 int annul, rtx_insn *insn)
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;
8238 /* branch on register are limited to +-128KB. If it is too far away,
8239 change
8241 brnz,pt %g1, .LC30
8245 brz,pn %g1, .+12
8247 ba,pt %xcc, .LC30
8251 brgez,a,pn %o1, .LC29
8255 brlz,pt %o1, .+16
8257 ba,pt %xcc, .LC29 */
8259 far = get_attr_length (insn) >= 3;
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);
8265 /* Only 64 bit versions of these instructions exist. */
8266 gcc_assert (mode == DImode);
8268 /* Start by writing the branch condition. */
8270 switch (code)
8272 case NE:
8273 strcpy (string, "brnz");
8274 break;
8276 case EQ:
8277 strcpy (string, "brz");
8278 break;
8280 case GE:
8281 strcpy (string, "brgez");
8282 break;
8284 case LT:
8285 strcpy (string, "brlz");
8286 break;
8288 case LE:
8289 strcpy (string, "brlez");
8290 break;
8292 case GT:
8293 strcpy (string, "brgz");
8294 break;
8296 default:
8297 gcc_unreachable ();
8300 p = strchr (string, '\0');
8302 /* Now add the annulling, reg, label, and nop. */
8303 if (annul && ! far)
8305 strcpy (p, ",a");
8306 p += 2;
8309 if (insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
8311 strcpy (p,
8312 ((XINT (note, 0) >= REG_BR_PROB_BASE / 2) ^ far)
8313 ? ",pt" : ",pn");
8314 p += 3;
8317 *p = p < string + 8 ? '\t' : ' ';
8318 p++;
8319 *p++ = '%';
8320 *p++ = '0' + reg;
8321 *p++ = ',';
8322 *p++ = ' ';
8323 if (far)
8325 int veryfar = 1, delta;
8327 if (INSN_ADDRESSES_SET_P ())
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;
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)
8344 strcpy (p, "b\t");
8345 p += 2;
8347 else
8349 strcpy (p, "ba,pt\t%%xcc, ");
8350 p += 13;
8353 *p++ = '%';
8354 *p++ = 'l';
8355 *p++ = '0' + label;
8356 *p++ = '%';
8357 *p++ = '#';
8358 *p = '\0';
8360 return string;
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.
8368 static int
8369 epilogue_renumber (register rtx *where, int test)
8371 register const char *fmt;
8372 register int i;
8373 register enum rtx_code code;
8375 if (*where == 0)
8376 return 0;
8378 code = GET_CODE (*where);
8380 switch (code)
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 /* fallthrough */
8388 case SCRATCH:
8389 case CC0:
8390 case PC:
8391 case CONST_INT:
8392 case CONST_WIDE_INT:
8393 case CONST_DOUBLE:
8394 return 0;
8396 /* Do not replace the frame pointer with the stack pointer because
8397 it can cause the delayed instruction to load below the stack.
8398 This occurs when instructions like:
8400 (set (reg/i:SI 24 %i0)
8401 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
8402 (const_int -20 [0xffffffec])) 0))
8404 are in the return delayed slot. */
8405 case PLUS:
8406 if (GET_CODE (XEXP (*where, 0)) == REG
8407 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
8408 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
8409 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
8410 return 1;
8411 break;
8413 case MEM:
8414 if (SPARC_STACK_BIAS
8415 && GET_CODE (XEXP (*where, 0)) == REG
8416 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
8417 return 1;
8418 break;
8420 default:
8421 break;
8424 fmt = GET_RTX_FORMAT (code);
8426 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
8428 if (fmt[i] == 'E')
8430 register int j;
8431 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
8432 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
8433 return 1;
8435 else if (fmt[i] == 'e'
8436 && epilogue_renumber (&(XEXP (*where, i)), test))
8437 return 1;
8439 return 0;
8442 /* Leaf functions and non-leaf functions have different needs. */
8444 static const int
8445 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
8447 static const int
8448 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
8450 static const int *const reg_alloc_orders[] = {
8451 reg_leaf_alloc_order,
8452 reg_nonleaf_alloc_order};
8454 void
8455 order_regs_for_local_alloc (void)
8457 static int last_order_nonleaf = 1;
8459 if (df_regs_ever_live_p (15) != last_order_nonleaf)
8461 last_order_nonleaf = !last_order_nonleaf;
8462 memcpy ((char *) reg_alloc_order,
8463 (const char *) reg_alloc_orders[last_order_nonleaf],
8464 FIRST_PSEUDO_REGISTER * sizeof (int));
8468 /* Return 1 if REG and MEM are legitimate enough to allow the various
8469 mem<-->reg splits to be run. */
8472 sparc_splitdi_legitimate (rtx reg, rtx mem)
8474 /* Punt if we are here by mistake. */
8475 gcc_assert (reload_completed);
8477 /* We must have an offsettable memory reference. */
8478 if (! offsettable_memref_p (mem))
8479 return 0;
8481 /* If we have legitimate args for ldd/std, we do not want
8482 the split to happen. */
8483 if ((REGNO (reg) % 2) == 0
8484 && mem_min_alignment (mem, 8))
8485 return 0;
8487 /* Success. */
8488 return 1;
8491 /* Like sparc_splitdi_legitimate but for REG <--> REG moves. */
8494 sparc_split_regreg_legitimate (rtx reg1, rtx reg2)
8496 int regno1, regno2;
8498 if (GET_CODE (reg1) == SUBREG)
8499 reg1 = SUBREG_REG (reg1);
8500 if (GET_CODE (reg1) != REG)
8501 return 0;
8502 regno1 = REGNO (reg1);
8504 if (GET_CODE (reg2) == SUBREG)
8505 reg2 = SUBREG_REG (reg2);
8506 if (GET_CODE (reg2) != REG)
8507 return 0;
8508 regno2 = REGNO (reg2);
8510 if (SPARC_INT_REG_P (regno1) && SPARC_INT_REG_P (regno2))
8511 return 1;
8513 if (TARGET_VIS3)
8515 if ((SPARC_INT_REG_P (regno1) && SPARC_FP_REG_P (regno2))
8516 || (SPARC_FP_REG_P (regno1) && SPARC_INT_REG_P (regno2)))
8517 return 1;
8520 return 0;
8523 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
8524 This makes them candidates for using ldd and std insns.
8526 Note reg1 and reg2 *must* be hard registers. */
8529 registers_ok_for_ldd_peep (rtx reg1, rtx reg2)
8531 /* We might have been passed a SUBREG. */
8532 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
8533 return 0;
8535 if (REGNO (reg1) % 2 != 0)
8536 return 0;
8538 /* Integer ldd is deprecated in SPARC V9 */
8539 if (TARGET_V9 && SPARC_INT_REG_P (REGNO (reg1)))
8540 return 0;
8542 return (REGNO (reg1) == REGNO (reg2) - 1);
8545 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
8546 an ldd or std insn.
8548 This can only happen when addr1 and addr2, the addresses in mem1
8549 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
8550 addr1 must also be aligned on a 64-bit boundary.
8552 Also iff dependent_reg_rtx is not null it should not be used to
8553 compute the address for mem1, i.e. we cannot optimize a sequence
8554 like:
8555 ld [%o0], %o0
8556 ld [%o0 + 4], %o1
8558 ldd [%o0], %o0
8559 nor:
8560 ld [%g3 + 4], %g3
8561 ld [%g3], %g2
8563 ldd [%g3], %g2
8565 But, note that the transformation from:
8566 ld [%g2 + 4], %g3
8567 ld [%g2], %g2
8569 ldd [%g2], %g2
8570 is perfectly fine. Thus, the peephole2 patterns always pass us
8571 the destination register of the first load, never the second one.
8573 For stores we don't have a similar problem, so dependent_reg_rtx is
8574 NULL_RTX. */
8577 mems_ok_for_ldd_peep (rtx mem1, rtx mem2, rtx dependent_reg_rtx)
8579 rtx addr1, addr2;
8580 unsigned int reg1;
8581 HOST_WIDE_INT offset1;
8583 /* The mems cannot be volatile. */
8584 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
8585 return 0;
8587 /* MEM1 should be aligned on a 64-bit boundary. */
8588 if (MEM_ALIGN (mem1) < 64)
8589 return 0;
8591 addr1 = XEXP (mem1, 0);
8592 addr2 = XEXP (mem2, 0);
8594 /* Extract a register number and offset (if used) from the first addr. */
8595 if (GET_CODE (addr1) == PLUS)
8597 /* If not a REG, return zero. */
8598 if (GET_CODE (XEXP (addr1, 0)) != REG)
8599 return 0;
8600 else
8602 reg1 = REGNO (XEXP (addr1, 0));
8603 /* The offset must be constant! */
8604 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
8605 return 0;
8606 offset1 = INTVAL (XEXP (addr1, 1));
8609 else if (GET_CODE (addr1) != REG)
8610 return 0;
8611 else
8613 reg1 = REGNO (addr1);
8614 /* This was a simple (mem (reg)) expression. Offset is 0. */
8615 offset1 = 0;
8618 /* Make sure the second address is a (mem (plus (reg) (const_int). */
8619 if (GET_CODE (addr2) != PLUS)
8620 return 0;
8622 if (GET_CODE (XEXP (addr2, 0)) != REG
8623 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
8624 return 0;
8626 if (reg1 != REGNO (XEXP (addr2, 0)))
8627 return 0;
8629 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
8630 return 0;
8632 /* The first offset must be evenly divisible by 8 to ensure the
8633 address is 64 bit aligned. */
8634 if (offset1 % 8 != 0)
8635 return 0;
8637 /* The offset for the second addr must be 4 more than the first addr. */
8638 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
8639 return 0;
8641 /* All the tests passed. addr1 and addr2 are valid for ldd and std
8642 instructions. */
8643 return 1;
8646 /* Return the widened memory access made of MEM1 and MEM2 in MODE. */
8649 widen_mem_for_ldd_peep (rtx mem1, rtx mem2, machine_mode mode)
8651 rtx x = widen_memory_access (mem1, mode, 0);
8652 MEM_NOTRAP_P (x) = MEM_NOTRAP_P (mem1) && MEM_NOTRAP_P (mem2);
8653 return x;
8656 /* Return 1 if reg is a pseudo, or is the first register in
8657 a hard register pair. This makes it suitable for use in
8658 ldd and std insns. */
8661 register_ok_for_ldd (rtx reg)
8663 /* We might have been passed a SUBREG. */
8664 if (!REG_P (reg))
8665 return 0;
8667 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
8668 return (REGNO (reg) % 2 == 0);
8670 return 1;
8673 /* Return 1 if OP, a MEM, has an address which is known to be
8674 aligned to an 8-byte boundary. */
8677 memory_ok_for_ldd (rtx op)
8679 /* In 64-bit mode, we assume that the address is word-aligned. */
8680 if (TARGET_ARCH32 && !mem_min_alignment (op, 8))
8681 return 0;
8683 if (! can_create_pseudo_p ()
8684 && !strict_memory_address_p (Pmode, XEXP (op, 0)))
8685 return 0;
8687 return 1;
8690 /* Implement TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
8692 static bool
8693 sparc_print_operand_punct_valid_p (unsigned char code)
8695 if (code == '#'
8696 || code == '*'
8697 || code == '('
8698 || code == ')'
8699 || code == '_'
8700 || code == '&')
8701 return true;
8703 return false;
8706 /* Implement TARGET_PRINT_OPERAND.
8707 Print operand X (an rtx) in assembler syntax to file FILE.
8708 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
8709 For `%' followed by punctuation, CODE is the punctuation and X is null. */
8711 static void
8712 sparc_print_operand (FILE *file, rtx x, int code)
8714 const char *s;
8716 switch (code)
8718 case '#':
8719 /* Output an insn in a delay slot. */
8720 if (final_sequence)
8721 sparc_indent_opcode = 1;
8722 else
8723 fputs ("\n\t nop", file);
8724 return;
8725 case '*':
8726 /* Output an annul flag if there's nothing for the delay slot and we
8727 are optimizing. This is always used with '(' below.
8728 Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
8729 this is a dbx bug. So, we only do this when optimizing.
8730 On UltraSPARC, a branch in a delay slot causes a pipeline flush.
8731 Always emit a nop in case the next instruction is a branch. */
8732 if (! final_sequence && (optimize && (int)sparc_cpu < PROCESSOR_V9))
8733 fputs (",a", file);
8734 return;
8735 case '(':
8736 /* Output a 'nop' if there's nothing for the delay slot and we are
8737 not optimizing. This is always used with '*' above. */
8738 if (! final_sequence && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
8739 fputs ("\n\t nop", file);
8740 else if (final_sequence)
8741 sparc_indent_opcode = 1;
8742 return;
8743 case ')':
8744 /* Output the right displacement from the saved PC on function return.
8745 The caller may have placed an "unimp" insn immediately after the call
8746 so we have to account for it. This insn is used in the 32-bit ABI
8747 when calling a function that returns a non zero-sized structure. The
8748 64-bit ABI doesn't have it. Be careful to have this test be the same
8749 as that for the call. The exception is when sparc_std_struct_return
8750 is enabled, the psABI is followed exactly and the adjustment is made
8751 by the code in sparc_struct_value_rtx. The call emitted is the same
8752 when sparc_std_struct_return is enabled. */
8753 if (!TARGET_ARCH64
8754 && cfun->returns_struct
8755 && !sparc_std_struct_return
8756 && DECL_SIZE (DECL_RESULT (current_function_decl))
8757 && TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl)))
8758 == INTEGER_CST
8759 && !integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))))
8760 fputs ("12", file);
8761 else
8762 fputc ('8', file);
8763 return;
8764 case '_':
8765 /* Output the Embedded Medium/Anywhere code model base register. */
8766 fputs (EMBMEDANY_BASE_REG, file);
8767 return;
8768 case '&':
8769 /* Print some local dynamic TLS name. */
8770 if (const char *name = get_some_local_dynamic_name ())
8771 assemble_name (file, name);
8772 else
8773 output_operand_lossage ("'%%&' used without any "
8774 "local dynamic TLS references");
8775 return;
8777 case 'Y':
8778 /* Adjust the operand to take into account a RESTORE operation. */
8779 if (GET_CODE (x) == CONST_INT)
8780 break;
8781 else if (GET_CODE (x) != REG)
8782 output_operand_lossage ("invalid %%Y operand");
8783 else if (REGNO (x) < 8)
8784 fputs (reg_names[REGNO (x)], file);
8785 else if (REGNO (x) >= 24 && REGNO (x) < 32)
8786 fputs (reg_names[REGNO (x)-16], file);
8787 else
8788 output_operand_lossage ("invalid %%Y operand");
8789 return;
8790 case 'L':
8791 /* Print out the low order register name of a register pair. */
8792 if (WORDS_BIG_ENDIAN)
8793 fputs (reg_names[REGNO (x)+1], file);
8794 else
8795 fputs (reg_names[REGNO (x)], file);
8796 return;
8797 case 'H':
8798 /* Print out the high order register name of a register pair. */
8799 if (WORDS_BIG_ENDIAN)
8800 fputs (reg_names[REGNO (x)], file);
8801 else
8802 fputs (reg_names[REGNO (x)+1], file);
8803 return;
8804 case 'R':
8805 /* Print out the second register name of a register pair or quad.
8806 I.e., R (%o0) => %o1. */
8807 fputs (reg_names[REGNO (x)+1], file);
8808 return;
8809 case 'S':
8810 /* Print out the third register name of a register quad.
8811 I.e., S (%o0) => %o2. */
8812 fputs (reg_names[REGNO (x)+2], file);
8813 return;
8814 case 'T':
8815 /* Print out the fourth register name of a register quad.
8816 I.e., T (%o0) => %o3. */
8817 fputs (reg_names[REGNO (x)+3], file);
8818 return;
8819 case 'x':
8820 /* Print a condition code register. */
8821 if (REGNO (x) == SPARC_ICC_REG)
8823 switch (GET_MODE (x))
8825 case CCmode:
8826 case CCNZmode:
8827 case CCCmode:
8828 case CCVmode:
8829 s = "%icc";
8830 break;
8831 case CCXmode:
8832 case CCXNZmode:
8833 case CCXCmode:
8834 case CCXVmode:
8835 s = "%xcc";
8836 break;
8837 default:
8838 gcc_unreachable ();
8840 fputs (s, file);
8842 else
8843 /* %fccN register */
8844 fputs (reg_names[REGNO (x)], file);
8845 return;
8846 case 'm':
8847 /* Print the operand's address only. */
8848 output_address (GET_MODE (x), XEXP (x, 0));
8849 return;
8850 case 'r':
8851 /* In this case we need a register. Use %g0 if the
8852 operand is const0_rtx. */
8853 if (x == const0_rtx
8854 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
8856 fputs ("%g0", file);
8857 return;
8859 else
8860 break;
8862 case 'A':
8863 switch (GET_CODE (x))
8865 case IOR:
8866 s = "or";
8867 break;
8868 case AND:
8869 s = "and";
8870 break;
8871 case XOR:
8872 s = "xor";
8873 break;
8874 default:
8875 output_operand_lossage ("invalid %%A operand");
8876 s = "";
8877 break;
8879 fputs (s, file);
8880 return;
8882 case 'B':
8883 switch (GET_CODE (x))
8885 case IOR:
8886 s = "orn";
8887 break;
8888 case AND:
8889 s = "andn";
8890 break;
8891 case XOR:
8892 s = "xnor";
8893 break;
8894 default:
8895 output_operand_lossage ("invalid %%B operand");
8896 s = "";
8897 break;
8899 fputs (s, file);
8900 return;
8902 /* This is used by the conditional move instructions. */
8903 case 'C':
8905 machine_mode mode = GET_MODE (XEXP (x, 0));
8906 switch (GET_CODE (x))
8908 case NE:
8909 if (mode == CCVmode || mode == CCXVmode)
8910 s = "vs";
8911 else
8912 s = "ne";
8913 break;
8914 case EQ:
8915 if (mode == CCVmode || mode == CCXVmode)
8916 s = "vc";
8917 else
8918 s = "e";
8919 break;
8920 case GE:
8921 if (mode == CCNZmode || mode == CCXNZmode)
8922 s = "pos";
8923 else
8924 s = "ge";
8925 break;
8926 case GT:
8927 s = "g";
8928 break;
8929 case LE:
8930 s = "le";
8931 break;
8932 case LT:
8933 if (mode == CCNZmode || mode == CCXNZmode)
8934 s = "neg";
8935 else
8936 s = "l";
8937 break;
8938 case GEU:
8939 s = "geu";
8940 break;
8941 case GTU:
8942 s = "gu";
8943 break;
8944 case LEU:
8945 s = "leu";
8946 break;
8947 case LTU:
8948 s = "lu";
8949 break;
8950 case LTGT:
8951 s = "lg";
8952 break;
8953 case UNORDERED:
8954 s = "u";
8955 break;
8956 case ORDERED:
8957 s = "o";
8958 break;
8959 case UNLT:
8960 s = "ul";
8961 break;
8962 case UNLE:
8963 s = "ule";
8964 break;
8965 case UNGT:
8966 s = "ug";
8967 break;
8968 case UNGE:
8969 s = "uge"
8970 ; break;
8971 case UNEQ:
8972 s = "ue";
8973 break;
8974 default:
8975 output_operand_lossage ("invalid %%C operand");
8976 s = "";
8977 break;
8979 fputs (s, file);
8980 return;
8983 /* This are used by the movr instruction pattern. */
8984 case 'D':
8986 switch (GET_CODE (x))
8988 case NE:
8989 s = "ne";
8990 break;
8991 case EQ:
8992 s = "e";
8993 break;
8994 case GE:
8995 s = "gez";
8996 break;
8997 case LT:
8998 s = "lz";
8999 break;
9000 case LE:
9001 s = "lez";
9002 break;
9003 case GT:
9004 s = "gz";
9005 break;
9006 default:
9007 output_operand_lossage ("invalid %%D operand");
9008 s = "";
9009 break;
9011 fputs (s, file);
9012 return;
9015 case 'b':
9017 /* Print a sign-extended character. */
9018 int i = trunc_int_for_mode (INTVAL (x), QImode);
9019 fprintf (file, "%d", i);
9020 return;
9023 case 'f':
9024 /* Operand must be a MEM; write its address. */
9025 if (GET_CODE (x) != MEM)
9026 output_operand_lossage ("invalid %%f operand");
9027 output_address (GET_MODE (x), XEXP (x, 0));
9028 return;
9030 case 's':
9032 /* Print a sign-extended 32-bit value. */
9033 HOST_WIDE_INT i;
9034 if (GET_CODE(x) == CONST_INT)
9035 i = INTVAL (x);
9036 else
9038 output_operand_lossage ("invalid %%s operand");
9039 return;
9041 i = trunc_int_for_mode (i, SImode);
9042 fprintf (file, HOST_WIDE_INT_PRINT_DEC, i);
9043 return;
9046 case 0:
9047 /* Do nothing special. */
9048 break;
9050 default:
9051 /* Undocumented flag. */
9052 output_operand_lossage ("invalid operand output code");
9055 if (GET_CODE (x) == REG)
9056 fputs (reg_names[REGNO (x)], file);
9057 else if (GET_CODE (x) == MEM)
9059 fputc ('[', file);
9060 /* Poor Sun assembler doesn't understand absolute addressing. */
9061 if (CONSTANT_P (XEXP (x, 0)))
9062 fputs ("%g0+", file);
9063 output_address (GET_MODE (x), XEXP (x, 0));
9064 fputc (']', file);
9066 else if (GET_CODE (x) == HIGH)
9068 fputs ("%hi(", file);
9069 output_addr_const (file, XEXP (x, 0));
9070 fputc (')', file);
9072 else if (GET_CODE (x) == LO_SUM)
9074 sparc_print_operand (file, XEXP (x, 0), 0);
9075 if (TARGET_CM_MEDMID)
9076 fputs ("+%l44(", file);
9077 else
9078 fputs ("+%lo(", file);
9079 output_addr_const (file, XEXP (x, 1));
9080 fputc (')', file);
9082 else if (GET_CODE (x) == CONST_DOUBLE)
9083 output_operand_lossage ("floating-point constant not a valid immediate operand");
9084 else
9085 output_addr_const (file, x);
9088 /* Implement TARGET_PRINT_OPERAND_ADDRESS. */
9090 static void
9091 sparc_print_operand_address (FILE *file, machine_mode /*mode*/, rtx x)
9093 register rtx base, index = 0;
9094 int offset = 0;
9095 register rtx addr = x;
9097 if (REG_P (addr))
9098 fputs (reg_names[REGNO (addr)], file);
9099 else if (GET_CODE (addr) == PLUS)
9101 if (CONST_INT_P (XEXP (addr, 0)))
9102 offset = INTVAL (XEXP (addr, 0)), base = XEXP (addr, 1);
9103 else if (CONST_INT_P (XEXP (addr, 1)))
9104 offset = INTVAL (XEXP (addr, 1)), base = XEXP (addr, 0);
9105 else
9106 base = XEXP (addr, 0), index = XEXP (addr, 1);
9107 if (GET_CODE (base) == LO_SUM)
9109 gcc_assert (USE_AS_OFFSETABLE_LO10
9110 && TARGET_ARCH64
9111 && ! TARGET_CM_MEDMID);
9112 output_operand (XEXP (base, 0), 0);
9113 fputs ("+%lo(", file);
9114 output_address (VOIDmode, XEXP (base, 1));
9115 fprintf (file, ")+%d", offset);
9117 else
9119 fputs (reg_names[REGNO (base)], file);
9120 if (index == 0)
9121 fprintf (file, "%+d", offset);
9122 else if (REG_P (index))
9123 fprintf (file, "+%s", reg_names[REGNO (index)]);
9124 else if (GET_CODE (index) == SYMBOL_REF
9125 || GET_CODE (index) == LABEL_REF
9126 || GET_CODE (index) == CONST)
9127 fputc ('+', file), output_addr_const (file, index);
9128 else gcc_unreachable ();
9131 else if (GET_CODE (addr) == MINUS
9132 && GET_CODE (XEXP (addr, 1)) == LABEL_REF)
9134 output_addr_const (file, XEXP (addr, 0));
9135 fputs ("-(", file);
9136 output_addr_const (file, XEXP (addr, 1));
9137 fputs ("-.)", file);
9139 else if (GET_CODE (addr) == LO_SUM)
9141 output_operand (XEXP (addr, 0), 0);
9142 if (TARGET_CM_MEDMID)
9143 fputs ("+%l44(", file);
9144 else
9145 fputs ("+%lo(", file);
9146 output_address (VOIDmode, XEXP (addr, 1));
9147 fputc (')', file);
9149 else if (flag_pic
9150 && GET_CODE (addr) == CONST
9151 && GET_CODE (XEXP (addr, 0)) == MINUS
9152 && GET_CODE (XEXP (XEXP (addr, 0), 1)) == CONST
9153 && GET_CODE (XEXP (XEXP (XEXP (addr, 0), 1), 0)) == MINUS
9154 && XEXP (XEXP (XEXP (XEXP (addr, 0), 1), 0), 1) == pc_rtx)
9156 addr = XEXP (addr, 0);
9157 output_addr_const (file, XEXP (addr, 0));
9158 /* Group the args of the second CONST in parenthesis. */
9159 fputs ("-(", file);
9160 /* Skip past the second CONST--it does nothing for us. */
9161 output_addr_const (file, XEXP (XEXP (addr, 1), 0));
9162 /* Close the parenthesis. */
9163 fputc (')', file);
9165 else
9167 output_addr_const (file, addr);
9171 /* Target hook for assembling integer objects. The sparc version has
9172 special handling for aligned DI-mode objects. */
9174 static bool
9175 sparc_assemble_integer (rtx x, unsigned int size, int aligned_p)
9177 /* ??? We only output .xword's for symbols and only then in environments
9178 where the assembler can handle them. */
9179 if (aligned_p && size == 8 && GET_CODE (x) != CONST_INT)
9181 if (TARGET_V9)
9183 assemble_integer_with_op ("\t.xword\t", x);
9184 return true;
9186 else
9188 assemble_aligned_integer (4, const0_rtx);
9189 assemble_aligned_integer (4, x);
9190 return true;
9193 return default_assemble_integer (x, size, aligned_p);
9196 /* Return the value of a code used in the .proc pseudo-op that says
9197 what kind of result this function returns. For non-C types, we pick
9198 the closest C type. */
9200 #ifndef SHORT_TYPE_SIZE
9201 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
9202 #endif
9204 #ifndef INT_TYPE_SIZE
9205 #define INT_TYPE_SIZE BITS_PER_WORD
9206 #endif
9208 #ifndef LONG_TYPE_SIZE
9209 #define LONG_TYPE_SIZE BITS_PER_WORD
9210 #endif
9212 #ifndef LONG_LONG_TYPE_SIZE
9213 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
9214 #endif
9216 #ifndef FLOAT_TYPE_SIZE
9217 #define FLOAT_TYPE_SIZE BITS_PER_WORD
9218 #endif
9220 #ifndef DOUBLE_TYPE_SIZE
9221 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
9222 #endif
9224 #ifndef LONG_DOUBLE_TYPE_SIZE
9225 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
9226 #endif
9228 unsigned long
9229 sparc_type_code (register tree type)
9231 register unsigned long qualifiers = 0;
9232 register unsigned shift;
9234 /* Only the first 30 bits of the qualifier are valid. We must refrain from
9235 setting more, since some assemblers will give an error for this. Also,
9236 we must be careful to avoid shifts of 32 bits or more to avoid getting
9237 unpredictable results. */
9239 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
9241 switch (TREE_CODE (type))
9243 case ERROR_MARK:
9244 return qualifiers;
9246 case ARRAY_TYPE:
9247 qualifiers |= (3 << shift);
9248 break;
9250 case FUNCTION_TYPE:
9251 case METHOD_TYPE:
9252 qualifiers |= (2 << shift);
9253 break;
9255 case POINTER_TYPE:
9256 case REFERENCE_TYPE:
9257 case OFFSET_TYPE:
9258 qualifiers |= (1 << shift);
9259 break;
9261 case RECORD_TYPE:
9262 return (qualifiers | 8);
9264 case UNION_TYPE:
9265 case QUAL_UNION_TYPE:
9266 return (qualifiers | 9);
9268 case ENUMERAL_TYPE:
9269 return (qualifiers | 10);
9271 case VOID_TYPE:
9272 return (qualifiers | 16);
9274 case INTEGER_TYPE:
9275 /* If this is a range type, consider it to be the underlying
9276 type. */
9277 if (TREE_TYPE (type) != 0)
9278 break;
9280 /* Carefully distinguish all the standard types of C,
9281 without messing up if the language is not C. We do this by
9282 testing TYPE_PRECISION and TYPE_UNSIGNED. The old code used to
9283 look at both the names and the above fields, but that's redundant.
9284 Any type whose size is between two C types will be considered
9285 to be the wider of the two types. Also, we do not have a
9286 special code to use for "long long", so anything wider than
9287 long is treated the same. Note that we can't distinguish
9288 between "int" and "long" in this code if they are the same
9289 size, but that's fine, since neither can the assembler. */
9291 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
9292 return (qualifiers | (TYPE_UNSIGNED (type) ? 12 : 2));
9294 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
9295 return (qualifiers | (TYPE_UNSIGNED (type) ? 13 : 3));
9297 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
9298 return (qualifiers | (TYPE_UNSIGNED (type) ? 14 : 4));
9300 else
9301 return (qualifiers | (TYPE_UNSIGNED (type) ? 15 : 5));
9303 case REAL_TYPE:
9304 /* If this is a range type, consider it to be the underlying
9305 type. */
9306 if (TREE_TYPE (type) != 0)
9307 break;
9309 /* Carefully distinguish all the standard types of C,
9310 without messing up if the language is not C. */
9312 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
9313 return (qualifiers | 6);
9315 else
9316 return (qualifiers | 7);
9318 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
9319 /* ??? We need to distinguish between double and float complex types,
9320 but I don't know how yet because I can't reach this code from
9321 existing front-ends. */
9322 return (qualifiers | 7); /* Who knows? */
9324 case VECTOR_TYPE:
9325 case BOOLEAN_TYPE: /* Boolean truth value type. */
9326 case LANG_TYPE:
9327 case NULLPTR_TYPE:
9328 return qualifiers;
9330 default:
9331 gcc_unreachable (); /* Not a type! */
9335 return qualifiers;
9338 /* Nested function support. */
9340 /* Emit RTL insns to initialize the variable parts of a trampoline.
9341 FNADDR is an RTX for the address of the function's pure code.
9342 CXT is an RTX for the static chain value for the function.
9344 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
9345 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
9346 (to store insns). This is a bit excessive. Perhaps a different
9347 mechanism would be better here.
9349 Emit enough FLUSH insns to synchronize the data and instruction caches. */
9351 static void
9352 sparc32_initialize_trampoline (rtx m_tramp, rtx fnaddr, rtx cxt)
9354 /* SPARC 32-bit trampoline:
9356 sethi %hi(fn), %g1
9357 sethi %hi(static), %g2
9358 jmp %g1+%lo(fn)
9359 or %g2, %lo(static), %g2
9361 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
9362 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
9365 emit_move_insn
9366 (adjust_address (m_tramp, SImode, 0),
9367 expand_binop (SImode, ior_optab,
9368 expand_shift (RSHIFT_EXPR, SImode, fnaddr, 10, 0, 1),
9369 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
9370 NULL_RTX, 1, OPTAB_DIRECT));
9372 emit_move_insn
9373 (adjust_address (m_tramp, SImode, 4),
9374 expand_binop (SImode, ior_optab,
9375 expand_shift (RSHIFT_EXPR, SImode, cxt, 10, 0, 1),
9376 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
9377 NULL_RTX, 1, OPTAB_DIRECT));
9379 emit_move_insn
9380 (adjust_address (m_tramp, SImode, 8),
9381 expand_binop (SImode, ior_optab,
9382 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
9383 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
9384 NULL_RTX, 1, OPTAB_DIRECT));
9386 emit_move_insn
9387 (adjust_address (m_tramp, SImode, 12),
9388 expand_binop (SImode, ior_optab,
9389 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
9390 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
9391 NULL_RTX, 1, OPTAB_DIRECT));
9393 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
9394 aligned on a 16 byte boundary so one flush clears it all. */
9395 emit_insn (gen_flushsi (validize_mem (adjust_address (m_tramp, SImode, 0))));
9396 if (sparc_cpu != PROCESSOR_ULTRASPARC
9397 && sparc_cpu != PROCESSOR_ULTRASPARC3
9398 && sparc_cpu != PROCESSOR_NIAGARA
9399 && sparc_cpu != PROCESSOR_NIAGARA2
9400 && sparc_cpu != PROCESSOR_NIAGARA3
9401 && sparc_cpu != PROCESSOR_NIAGARA4
9402 && sparc_cpu != PROCESSOR_NIAGARA7)
9403 emit_insn (gen_flushsi (validize_mem (adjust_address (m_tramp, SImode, 8))));
9405 /* Call __enable_execute_stack after writing onto the stack to make sure
9406 the stack address is accessible. */
9407 #ifdef HAVE_ENABLE_EXECUTE_STACK
9408 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
9409 LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
9410 #endif
9414 /* The 64-bit version is simpler because it makes more sense to load the
9415 values as "immediate" data out of the trampoline. It's also easier since
9416 we can read the PC without clobbering a register. */
9418 static void
9419 sparc64_initialize_trampoline (rtx m_tramp, rtx fnaddr, rtx cxt)
9421 /* SPARC 64-bit trampoline:
9423 rd %pc, %g1
9424 ldx [%g1+24], %g5
9425 jmp %g5
9426 ldx [%g1+16], %g5
9427 +16 bytes data
9430 emit_move_insn (adjust_address (m_tramp, SImode, 0),
9431 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
9432 emit_move_insn (adjust_address (m_tramp, SImode, 4),
9433 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
9434 emit_move_insn (adjust_address (m_tramp, SImode, 8),
9435 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
9436 emit_move_insn (adjust_address (m_tramp, SImode, 12),
9437 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
9438 emit_move_insn (adjust_address (m_tramp, DImode, 16), cxt);
9439 emit_move_insn (adjust_address (m_tramp, DImode, 24), fnaddr);
9440 emit_insn (gen_flushdi (validize_mem (adjust_address (m_tramp, DImode, 0))));
9442 if (sparc_cpu != PROCESSOR_ULTRASPARC
9443 && sparc_cpu != PROCESSOR_ULTRASPARC3
9444 && sparc_cpu != PROCESSOR_NIAGARA
9445 && sparc_cpu != PROCESSOR_NIAGARA2
9446 && sparc_cpu != PROCESSOR_NIAGARA3
9447 && sparc_cpu != PROCESSOR_NIAGARA4
9448 && sparc_cpu != PROCESSOR_NIAGARA7)
9449 emit_insn (gen_flushdi (validize_mem (adjust_address (m_tramp, DImode, 8))));
9451 /* Call __enable_execute_stack after writing onto the stack to make sure
9452 the stack address is accessible. */
9453 #ifdef HAVE_ENABLE_EXECUTE_STACK
9454 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
9455 LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
9456 #endif
9459 /* Worker for TARGET_TRAMPOLINE_INIT. */
9461 static void
9462 sparc_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
9464 rtx fnaddr = force_reg (Pmode, XEXP (DECL_RTL (fndecl), 0));
9465 cxt = force_reg (Pmode, cxt);
9466 if (TARGET_ARCH64)
9467 sparc64_initialize_trampoline (m_tramp, fnaddr, cxt);
9468 else
9469 sparc32_initialize_trampoline (m_tramp, fnaddr, cxt);
9472 /* Adjust the cost of a scheduling dependency. Return the new cost of
9473 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
9475 static int
9476 supersparc_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep_insn,
9477 int cost)
9479 enum attr_type insn_type;
9481 if (recog_memoized (insn) < 0)
9482 return cost;
9484 insn_type = get_attr_type (insn);
9486 if (dep_type == 0)
9488 /* Data dependency; DEP_INSN writes a register that INSN reads some
9489 cycles later. */
9491 /* if a load, then the dependence must be on the memory address;
9492 add an extra "cycle". Note that the cost could be two cycles
9493 if the reg was written late in an instruction group; we ca not tell
9494 here. */
9495 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
9496 return cost + 3;
9498 /* Get the delay only if the address of the store is the dependence. */
9499 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
9501 rtx pat = PATTERN(insn);
9502 rtx dep_pat = PATTERN (dep_insn);
9504 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
9505 return cost; /* This should not happen! */
9507 /* The dependency between the two instructions was on the data that
9508 is being stored. Assume that this implies that the address of the
9509 store is not dependent. */
9510 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
9511 return cost;
9513 return cost + 3; /* An approximation. */
9516 /* A shift instruction cannot receive its data from an instruction
9517 in the same cycle; add a one cycle penalty. */
9518 if (insn_type == TYPE_SHIFT)
9519 return cost + 3; /* Split before cascade into shift. */
9521 else
9523 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
9524 INSN writes some cycles later. */
9526 /* These are only significant for the fpu unit; writing a fp reg before
9527 the fpu has finished with it stalls the processor. */
9529 /* Reusing an integer register causes no problems. */
9530 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
9531 return 0;
9534 return cost;
9537 static int
9538 hypersparc_adjust_cost (rtx_insn *insn, int dtype, rtx_insn *dep_insn,
9539 int cost)
9541 enum attr_type insn_type, dep_type;
9542 rtx pat = PATTERN(insn);
9543 rtx dep_pat = PATTERN (dep_insn);
9545 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
9546 return cost;
9548 insn_type = get_attr_type (insn);
9549 dep_type = get_attr_type (dep_insn);
9551 switch (dtype)
9553 case 0:
9554 /* Data dependency; DEP_INSN writes a register that INSN reads some
9555 cycles later. */
9557 switch (insn_type)
9559 case TYPE_STORE:
9560 case TYPE_FPSTORE:
9561 /* Get the delay iff the address of the store is the dependence. */
9562 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
9563 return cost;
9565 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
9566 return cost;
9567 return cost + 3;
9569 case TYPE_LOAD:
9570 case TYPE_SLOAD:
9571 case TYPE_FPLOAD:
9572 /* If a load, then the dependence must be on the memory address. If
9573 the addresses aren't equal, then it might be a false dependency */
9574 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
9576 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
9577 || GET_CODE (SET_DEST (dep_pat)) != MEM
9578 || GET_CODE (SET_SRC (pat)) != MEM
9579 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
9580 XEXP (SET_SRC (pat), 0)))
9581 return cost + 2;
9583 return cost + 8;
9585 break;
9587 case TYPE_BRANCH:
9588 /* Compare to branch latency is 0. There is no benefit from
9589 separating compare and branch. */
9590 if (dep_type == TYPE_COMPARE)
9591 return 0;
9592 /* Floating point compare to branch latency is less than
9593 compare to conditional move. */
9594 if (dep_type == TYPE_FPCMP)
9595 return cost - 1;
9596 break;
9597 default:
9598 break;
9600 break;
9602 case REG_DEP_ANTI:
9603 /* Anti-dependencies only penalize the fpu unit. */
9604 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
9605 return 0;
9606 break;
9608 default:
9609 break;
9612 return cost;
9615 static int
9616 sparc_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep, int cost,
9617 unsigned int)
9619 switch (sparc_cpu)
9621 case PROCESSOR_SUPERSPARC:
9622 cost = supersparc_adjust_cost (insn, dep_type, dep, cost);
9623 break;
9624 case PROCESSOR_HYPERSPARC:
9625 case PROCESSOR_SPARCLITE86X:
9626 cost = hypersparc_adjust_cost (insn, dep_type, dep, cost);
9627 break;
9628 default:
9629 break;
9631 return cost;
9634 static void
9635 sparc_sched_init (FILE *dump ATTRIBUTE_UNUSED,
9636 int sched_verbose ATTRIBUTE_UNUSED,
9637 int max_ready ATTRIBUTE_UNUSED)
9640 static int
9641 sparc_use_sched_lookahead (void)
9643 if (sparc_cpu == PROCESSOR_NIAGARA
9644 || sparc_cpu == PROCESSOR_NIAGARA2
9645 || sparc_cpu == PROCESSOR_NIAGARA3)
9646 return 0;
9647 if (sparc_cpu == PROCESSOR_NIAGARA4
9648 || sparc_cpu == PROCESSOR_NIAGARA7)
9649 return 2;
9650 if (sparc_cpu == PROCESSOR_ULTRASPARC
9651 || sparc_cpu == PROCESSOR_ULTRASPARC3)
9652 return 4;
9653 if ((1 << sparc_cpu) &
9654 ((1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
9655 (1 << PROCESSOR_SPARCLITE86X)))
9656 return 3;
9657 return 0;
9660 static int
9661 sparc_issue_rate (void)
9663 switch (sparc_cpu)
9665 case PROCESSOR_NIAGARA:
9666 case PROCESSOR_NIAGARA2:
9667 case PROCESSOR_NIAGARA3:
9668 default:
9669 return 1;
9670 case PROCESSOR_NIAGARA4:
9671 case PROCESSOR_NIAGARA7:
9672 case PROCESSOR_V9:
9673 /* Assume V9 processors are capable of at least dual-issue. */
9674 return 2;
9675 case PROCESSOR_SUPERSPARC:
9676 return 3;
9677 case PROCESSOR_HYPERSPARC:
9678 case PROCESSOR_SPARCLITE86X:
9679 return 2;
9680 case PROCESSOR_ULTRASPARC:
9681 case PROCESSOR_ULTRASPARC3:
9682 return 4;
9686 static int
9687 set_extends (rtx_insn *insn)
9689 register rtx pat = PATTERN (insn);
9691 switch (GET_CODE (SET_SRC (pat)))
9693 /* Load and some shift instructions zero extend. */
9694 case MEM:
9695 case ZERO_EXTEND:
9696 /* sethi clears the high bits */
9697 case HIGH:
9698 /* LO_SUM is used with sethi. sethi cleared the high
9699 bits and the values used with lo_sum are positive */
9700 case LO_SUM:
9701 /* Store flag stores 0 or 1 */
9702 case LT: case LTU:
9703 case GT: case GTU:
9704 case LE: case LEU:
9705 case GE: case GEU:
9706 case EQ:
9707 case NE:
9708 return 1;
9709 case AND:
9711 rtx op0 = XEXP (SET_SRC (pat), 0);
9712 rtx op1 = XEXP (SET_SRC (pat), 1);
9713 if (GET_CODE (op1) == CONST_INT)
9714 return INTVAL (op1) >= 0;
9715 if (GET_CODE (op0) != REG)
9716 return 0;
9717 if (sparc_check_64 (op0, insn) == 1)
9718 return 1;
9719 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
9721 case IOR:
9722 case XOR:
9724 rtx op0 = XEXP (SET_SRC (pat), 0);
9725 rtx op1 = XEXP (SET_SRC (pat), 1);
9726 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
9727 return 0;
9728 if (GET_CODE (op1) == CONST_INT)
9729 return INTVAL (op1) >= 0;
9730 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
9732 case LSHIFTRT:
9733 return GET_MODE (SET_SRC (pat)) == SImode;
9734 /* Positive integers leave the high bits zero. */
9735 case CONST_INT:
9736 return !(INTVAL (SET_SRC (pat)) & 0x80000000);
9737 case ASHIFTRT:
9738 case SIGN_EXTEND:
9739 return - (GET_MODE (SET_SRC (pat)) == SImode);
9740 case REG:
9741 return sparc_check_64 (SET_SRC (pat), insn);
9742 default:
9743 return 0;
9747 /* We _ought_ to have only one kind per function, but... */
9748 static GTY(()) rtx sparc_addr_diff_list;
9749 static GTY(()) rtx sparc_addr_list;
9751 void
9752 sparc_defer_case_vector (rtx lab, rtx vec, int diff)
9754 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
9755 if (diff)
9756 sparc_addr_diff_list
9757 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
9758 else
9759 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
9762 static void
9763 sparc_output_addr_vec (rtx vec)
9765 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
9766 int idx, vlen = XVECLEN (body, 0);
9768 #ifdef ASM_OUTPUT_ADDR_VEC_START
9769 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
9770 #endif
9772 #ifdef ASM_OUTPUT_CASE_LABEL
9773 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
9774 NEXT_INSN (lab));
9775 #else
9776 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
9777 #endif
9779 for (idx = 0; idx < vlen; idx++)
9781 ASM_OUTPUT_ADDR_VEC_ELT
9782 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
9785 #ifdef ASM_OUTPUT_ADDR_VEC_END
9786 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
9787 #endif
9790 static void
9791 sparc_output_addr_diff_vec (rtx vec)
9793 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
9794 rtx base = XEXP (XEXP (body, 0), 0);
9795 int idx, vlen = XVECLEN (body, 1);
9797 #ifdef ASM_OUTPUT_ADDR_VEC_START
9798 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
9799 #endif
9801 #ifdef ASM_OUTPUT_CASE_LABEL
9802 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
9803 NEXT_INSN (lab));
9804 #else
9805 (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
9806 #endif
9808 for (idx = 0; idx < vlen; idx++)
9810 ASM_OUTPUT_ADDR_DIFF_ELT
9811 (asm_out_file,
9812 body,
9813 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
9814 CODE_LABEL_NUMBER (base));
9817 #ifdef ASM_OUTPUT_ADDR_VEC_END
9818 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
9819 #endif
9822 static void
9823 sparc_output_deferred_case_vectors (void)
9825 rtx t;
9826 int align;
9828 if (sparc_addr_list == NULL_RTX
9829 && sparc_addr_diff_list == NULL_RTX)
9830 return;
9832 /* Align to cache line in the function's code section. */
9833 switch_to_section (current_function_section ());
9835 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
9836 if (align > 0)
9837 ASM_OUTPUT_ALIGN (asm_out_file, align);
9839 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
9840 sparc_output_addr_vec (XEXP (t, 0));
9841 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
9842 sparc_output_addr_diff_vec (XEXP (t, 0));
9844 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
9847 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
9848 unknown. Return 1 if the high bits are zero, -1 if the register is
9849 sign extended. */
9851 sparc_check_64 (rtx x, rtx_insn *insn)
9853 /* If a register is set only once it is safe to ignore insns this
9854 code does not know how to handle. The loop will either recognize
9855 the single set and return the correct value or fail to recognize
9856 it and return 0. */
9857 int set_once = 0;
9858 rtx y = x;
9860 gcc_assert (GET_CODE (x) == REG);
9862 if (GET_MODE (x) == DImode)
9863 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
9865 if (flag_expensive_optimizations
9866 && df && DF_REG_DEF_COUNT (REGNO (y)) == 1)
9867 set_once = 1;
9869 if (insn == 0)
9871 if (set_once)
9872 insn = get_last_insn_anywhere ();
9873 else
9874 return 0;
9877 while ((insn = PREV_INSN (insn)))
9879 switch (GET_CODE (insn))
9881 case JUMP_INSN:
9882 case NOTE:
9883 break;
9884 case CODE_LABEL:
9885 case CALL_INSN:
9886 default:
9887 if (! set_once)
9888 return 0;
9889 break;
9890 case INSN:
9892 rtx pat = PATTERN (insn);
9893 if (GET_CODE (pat) != SET)
9894 return 0;
9895 if (rtx_equal_p (x, SET_DEST (pat)))
9896 return set_extends (insn);
9897 if (y && rtx_equal_p (y, SET_DEST (pat)))
9898 return set_extends (insn);
9899 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
9900 return 0;
9904 return 0;
9907 /* Output a wide shift instruction in V8+ mode. INSN is the instruction,
9908 OPERANDS are its operands and OPCODE is the mnemonic to be used. */
9910 const char *
9911 output_v8plus_shift (rtx_insn *insn, rtx *operands, const char *opcode)
9913 static char asm_code[60];
9915 /* The scratch register is only required when the destination
9916 register is not a 64-bit global or out register. */
9917 if (which_alternative != 2)
9918 operands[3] = operands[0];
9920 /* We can only shift by constants <= 63. */
9921 if (GET_CODE (operands[2]) == CONST_INT)
9922 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
9924 if (GET_CODE (operands[1]) == CONST_INT)
9926 output_asm_insn ("mov\t%1, %3", operands);
9928 else
9930 output_asm_insn ("sllx\t%H1, 32, %3", operands);
9931 if (sparc_check_64 (operands[1], insn) <= 0)
9932 output_asm_insn ("srl\t%L1, 0, %L1", operands);
9933 output_asm_insn ("or\t%L1, %3, %3", operands);
9936 strcpy (asm_code, opcode);
9938 if (which_alternative != 2)
9939 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
9940 else
9941 return
9942 strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
9945 /* Output rtl to increment the profiler label LABELNO
9946 for profiling a function entry. */
9948 void
9949 sparc_profile_hook (int labelno)
9951 char buf[32];
9952 rtx lab, fun;
9954 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
9955 if (NO_PROFILE_COUNTERS)
9957 emit_library_call (fun, LCT_NORMAL, VOIDmode, 0);
9959 else
9961 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
9962 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9963 emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lab, Pmode);
9967 #ifdef TARGET_SOLARIS
9968 /* Solaris implementation of TARGET_ASM_NAMED_SECTION. */
9970 static void
9971 sparc_solaris_elf_asm_named_section (const char *name, unsigned int flags,
9972 tree decl ATTRIBUTE_UNUSED)
9974 if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
9976 solaris_elf_asm_comdat_section (name, flags, decl);
9977 return;
9980 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
9982 if (!(flags & SECTION_DEBUG))
9983 fputs (",#alloc", asm_out_file);
9984 if (flags & SECTION_WRITE)
9985 fputs (",#write", asm_out_file);
9986 if (flags & SECTION_TLS)
9987 fputs (",#tls", asm_out_file);
9988 if (flags & SECTION_CODE)
9989 fputs (",#execinstr", asm_out_file);
9991 if (flags & SECTION_NOTYPE)
9993 else if (flags & SECTION_BSS)
9994 fputs (",#nobits", asm_out_file);
9995 else
9996 fputs (",#progbits", asm_out_file);
9998 fputc ('\n', asm_out_file);
10000 #endif /* TARGET_SOLARIS */
10002 /* We do not allow indirect calls to be optimized into sibling calls.
10004 We cannot use sibling calls when delayed branches are disabled
10005 because they will likely require the call delay slot to be filled.
10007 Also, on SPARC 32-bit we cannot emit a sibling call when the
10008 current function returns a structure. This is because the "unimp
10009 after call" convention would cause the callee to return to the
10010 wrong place. The generic code already disallows cases where the
10011 function being called returns a structure.
10013 It may seem strange how this last case could occur. Usually there
10014 is code after the call which jumps to epilogue code which dumps the
10015 return value into the struct return area. That ought to invalidate
10016 the sibling call right? Well, in the C++ case we can end up passing
10017 the pointer to the struct return area to a constructor (which returns
10018 void) and then nothing else happens. Such a sibling call would look
10019 valid without the added check here.
10021 VxWorks PIC PLT entries require the global pointer to be initialized
10022 on entry. We therefore can't emit sibling calls to them. */
10023 static bool
10024 sparc_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
10026 return (decl
10027 && flag_delayed_branch
10028 && (TARGET_ARCH64 || ! cfun->returns_struct)
10029 && !(TARGET_VXWORKS_RTP
10030 && flag_pic
10031 && !targetm.binds_local_p (decl)));
10034 /* libfunc renaming. */
10036 static void
10037 sparc_init_libfuncs (void)
10039 if (TARGET_ARCH32)
10041 /* Use the subroutines that Sun's library provides for integer
10042 multiply and divide. The `*' prevents an underscore from
10043 being prepended by the compiler. .umul is a little faster
10044 than .mul. */
10045 set_optab_libfunc (smul_optab, SImode, "*.umul");
10046 set_optab_libfunc (sdiv_optab, SImode, "*.div");
10047 set_optab_libfunc (udiv_optab, SImode, "*.udiv");
10048 set_optab_libfunc (smod_optab, SImode, "*.rem");
10049 set_optab_libfunc (umod_optab, SImode, "*.urem");
10051 /* TFmode arithmetic. These names are part of the SPARC 32bit ABI. */
10052 set_optab_libfunc (add_optab, TFmode, "_Q_add");
10053 set_optab_libfunc (sub_optab, TFmode, "_Q_sub");
10054 set_optab_libfunc (neg_optab, TFmode, "_Q_neg");
10055 set_optab_libfunc (smul_optab, TFmode, "_Q_mul");
10056 set_optab_libfunc (sdiv_optab, TFmode, "_Q_div");
10058 /* We can define the TFmode sqrt optab only if TARGET_FPU. This
10059 is because with soft-float, the SFmode and DFmode sqrt
10060 instructions will be absent, and the compiler will notice and
10061 try to use the TFmode sqrt instruction for calls to the
10062 builtin function sqrt, but this fails. */
10063 if (TARGET_FPU)
10064 set_optab_libfunc (sqrt_optab, TFmode, "_Q_sqrt");
10066 set_optab_libfunc (eq_optab, TFmode, "_Q_feq");
10067 set_optab_libfunc (ne_optab, TFmode, "_Q_fne");
10068 set_optab_libfunc (gt_optab, TFmode, "_Q_fgt");
10069 set_optab_libfunc (ge_optab, TFmode, "_Q_fge");
10070 set_optab_libfunc (lt_optab, TFmode, "_Q_flt");
10071 set_optab_libfunc (le_optab, TFmode, "_Q_fle");
10073 set_conv_libfunc (sext_optab, TFmode, SFmode, "_Q_stoq");
10074 set_conv_libfunc (sext_optab, TFmode, DFmode, "_Q_dtoq");
10075 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_Q_qtos");
10076 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_Q_qtod");
10078 set_conv_libfunc (sfix_optab, SImode, TFmode, "_Q_qtoi");
10079 set_conv_libfunc (ufix_optab, SImode, TFmode, "_Q_qtou");
10080 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_Q_itoq");
10081 set_conv_libfunc (ufloat_optab, TFmode, SImode, "_Q_utoq");
10083 if (DITF_CONVERSION_LIBFUNCS)
10085 set_conv_libfunc (sfix_optab, DImode, TFmode, "_Q_qtoll");
10086 set_conv_libfunc (ufix_optab, DImode, TFmode, "_Q_qtoull");
10087 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_Q_lltoq");
10088 set_conv_libfunc (ufloat_optab, TFmode, DImode, "_Q_ulltoq");
10091 if (SUN_CONVERSION_LIBFUNCS)
10093 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftoll");
10094 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoull");
10095 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtoll");
10096 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoull");
10099 if (TARGET_ARCH64)
10101 /* In the SPARC 64bit ABI, SImode multiply and divide functions
10102 do not exist in the library. Make sure the compiler does not
10103 emit calls to them by accident. (It should always use the
10104 hardware instructions.) */
10105 set_optab_libfunc (smul_optab, SImode, 0);
10106 set_optab_libfunc (sdiv_optab, SImode, 0);
10107 set_optab_libfunc (udiv_optab, SImode, 0);
10108 set_optab_libfunc (smod_optab, SImode, 0);
10109 set_optab_libfunc (umod_optab, SImode, 0);
10111 if (SUN_INTEGER_MULTIPLY_64)
10113 set_optab_libfunc (smul_optab, DImode, "__mul64");
10114 set_optab_libfunc (sdiv_optab, DImode, "__div64");
10115 set_optab_libfunc (udiv_optab, DImode, "__udiv64");
10116 set_optab_libfunc (smod_optab, DImode, "__rem64");
10117 set_optab_libfunc (umod_optab, DImode, "__urem64");
10120 if (SUN_CONVERSION_LIBFUNCS)
10122 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftol");
10123 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoul");
10124 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtol");
10125 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoul");
10130 /* SPARC builtins. */
10131 enum sparc_builtins
10133 /* FPU builtins. */
10134 SPARC_BUILTIN_LDFSR,
10135 SPARC_BUILTIN_STFSR,
10137 /* VIS 1.0 builtins. */
10138 SPARC_BUILTIN_FPACK16,
10139 SPARC_BUILTIN_FPACK32,
10140 SPARC_BUILTIN_FPACKFIX,
10141 SPARC_BUILTIN_FEXPAND,
10142 SPARC_BUILTIN_FPMERGE,
10143 SPARC_BUILTIN_FMUL8X16,
10144 SPARC_BUILTIN_FMUL8X16AU,
10145 SPARC_BUILTIN_FMUL8X16AL,
10146 SPARC_BUILTIN_FMUL8SUX16,
10147 SPARC_BUILTIN_FMUL8ULX16,
10148 SPARC_BUILTIN_FMULD8SUX16,
10149 SPARC_BUILTIN_FMULD8ULX16,
10150 SPARC_BUILTIN_FALIGNDATAV4HI,
10151 SPARC_BUILTIN_FALIGNDATAV8QI,
10152 SPARC_BUILTIN_FALIGNDATAV2SI,
10153 SPARC_BUILTIN_FALIGNDATADI,
10154 SPARC_BUILTIN_WRGSR,
10155 SPARC_BUILTIN_RDGSR,
10156 SPARC_BUILTIN_ALIGNADDR,
10157 SPARC_BUILTIN_ALIGNADDRL,
10158 SPARC_BUILTIN_PDIST,
10159 SPARC_BUILTIN_EDGE8,
10160 SPARC_BUILTIN_EDGE8L,
10161 SPARC_BUILTIN_EDGE16,
10162 SPARC_BUILTIN_EDGE16L,
10163 SPARC_BUILTIN_EDGE32,
10164 SPARC_BUILTIN_EDGE32L,
10165 SPARC_BUILTIN_FCMPLE16,
10166 SPARC_BUILTIN_FCMPLE32,
10167 SPARC_BUILTIN_FCMPNE16,
10168 SPARC_BUILTIN_FCMPNE32,
10169 SPARC_BUILTIN_FCMPGT16,
10170 SPARC_BUILTIN_FCMPGT32,
10171 SPARC_BUILTIN_FCMPEQ16,
10172 SPARC_BUILTIN_FCMPEQ32,
10173 SPARC_BUILTIN_FPADD16,
10174 SPARC_BUILTIN_FPADD16S,
10175 SPARC_BUILTIN_FPADD32,
10176 SPARC_BUILTIN_FPADD32S,
10177 SPARC_BUILTIN_FPSUB16,
10178 SPARC_BUILTIN_FPSUB16S,
10179 SPARC_BUILTIN_FPSUB32,
10180 SPARC_BUILTIN_FPSUB32S,
10181 SPARC_BUILTIN_ARRAY8,
10182 SPARC_BUILTIN_ARRAY16,
10183 SPARC_BUILTIN_ARRAY32,
10185 /* VIS 2.0 builtins. */
10186 SPARC_BUILTIN_EDGE8N,
10187 SPARC_BUILTIN_EDGE8LN,
10188 SPARC_BUILTIN_EDGE16N,
10189 SPARC_BUILTIN_EDGE16LN,
10190 SPARC_BUILTIN_EDGE32N,
10191 SPARC_BUILTIN_EDGE32LN,
10192 SPARC_BUILTIN_BMASK,
10193 SPARC_BUILTIN_BSHUFFLEV4HI,
10194 SPARC_BUILTIN_BSHUFFLEV8QI,
10195 SPARC_BUILTIN_BSHUFFLEV2SI,
10196 SPARC_BUILTIN_BSHUFFLEDI,
10198 /* VIS 3.0 builtins. */
10199 SPARC_BUILTIN_CMASK8,
10200 SPARC_BUILTIN_CMASK16,
10201 SPARC_BUILTIN_CMASK32,
10202 SPARC_BUILTIN_FCHKSM16,
10203 SPARC_BUILTIN_FSLL16,
10204 SPARC_BUILTIN_FSLAS16,
10205 SPARC_BUILTIN_FSRL16,
10206 SPARC_BUILTIN_FSRA16,
10207 SPARC_BUILTIN_FSLL32,
10208 SPARC_BUILTIN_FSLAS32,
10209 SPARC_BUILTIN_FSRL32,
10210 SPARC_BUILTIN_FSRA32,
10211 SPARC_BUILTIN_PDISTN,
10212 SPARC_BUILTIN_FMEAN16,
10213 SPARC_BUILTIN_FPADD64,
10214 SPARC_BUILTIN_FPSUB64,
10215 SPARC_BUILTIN_FPADDS16,
10216 SPARC_BUILTIN_FPADDS16S,
10217 SPARC_BUILTIN_FPSUBS16,
10218 SPARC_BUILTIN_FPSUBS16S,
10219 SPARC_BUILTIN_FPADDS32,
10220 SPARC_BUILTIN_FPADDS32S,
10221 SPARC_BUILTIN_FPSUBS32,
10222 SPARC_BUILTIN_FPSUBS32S,
10223 SPARC_BUILTIN_FUCMPLE8,
10224 SPARC_BUILTIN_FUCMPNE8,
10225 SPARC_BUILTIN_FUCMPGT8,
10226 SPARC_BUILTIN_FUCMPEQ8,
10227 SPARC_BUILTIN_FHADDS,
10228 SPARC_BUILTIN_FHADDD,
10229 SPARC_BUILTIN_FHSUBS,
10230 SPARC_BUILTIN_FHSUBD,
10231 SPARC_BUILTIN_FNHADDS,
10232 SPARC_BUILTIN_FNHADDD,
10233 SPARC_BUILTIN_UMULXHI,
10234 SPARC_BUILTIN_XMULX,
10235 SPARC_BUILTIN_XMULXHI,
10237 /* VIS 4.0 builtins. */
10238 SPARC_BUILTIN_FPADD8,
10239 SPARC_BUILTIN_FPADDS8,
10240 SPARC_BUILTIN_FPADDUS8,
10241 SPARC_BUILTIN_FPADDUS16,
10242 SPARC_BUILTIN_FPCMPLE8,
10243 SPARC_BUILTIN_FPCMPGT8,
10244 SPARC_BUILTIN_FPCMPULE16,
10245 SPARC_BUILTIN_FPCMPUGT16,
10246 SPARC_BUILTIN_FPCMPULE32,
10247 SPARC_BUILTIN_FPCMPUGT32,
10248 SPARC_BUILTIN_FPMAX8,
10249 SPARC_BUILTIN_FPMAX16,
10250 SPARC_BUILTIN_FPMAX32,
10251 SPARC_BUILTIN_FPMAXU8,
10252 SPARC_BUILTIN_FPMAXU16,
10253 SPARC_BUILTIN_FPMAXU32,
10254 SPARC_BUILTIN_FPMIN8,
10255 SPARC_BUILTIN_FPMIN16,
10256 SPARC_BUILTIN_FPMIN32,
10257 SPARC_BUILTIN_FPMINU8,
10258 SPARC_BUILTIN_FPMINU16,
10259 SPARC_BUILTIN_FPMINU32,
10260 SPARC_BUILTIN_FPSUB8,
10261 SPARC_BUILTIN_FPSUBS8,
10262 SPARC_BUILTIN_FPSUBUS8,
10263 SPARC_BUILTIN_FPSUBUS16,
10265 SPARC_BUILTIN_MAX
10268 static GTY (()) tree sparc_builtins[(int) SPARC_BUILTIN_MAX];
10269 static enum insn_code sparc_builtins_icode[(int) SPARC_BUILTIN_MAX];
10271 /* Add a SPARC builtin function with NAME, ICODE, CODE and TYPE. Return the
10272 function decl or NULL_TREE if the builtin was not added. */
10274 static tree
10275 def_builtin (const char *name, enum insn_code icode, enum sparc_builtins code,
10276 tree type)
10278 tree t
10279 = add_builtin_function (name, type, code, BUILT_IN_MD, NULL, NULL_TREE);
10281 if (t)
10283 sparc_builtins[code] = t;
10284 sparc_builtins_icode[code] = icode;
10287 return t;
10290 /* Likewise, but also marks the function as "const". */
10292 static tree
10293 def_builtin_const (const char *name, enum insn_code icode,
10294 enum sparc_builtins code, tree type)
10296 tree t = def_builtin (name, icode, code, type);
10298 if (t)
10299 TREE_READONLY (t) = 1;
10301 return t;
10304 /* Implement the TARGET_INIT_BUILTINS target hook.
10305 Create builtin functions for special SPARC instructions. */
10307 static void
10308 sparc_init_builtins (void)
10310 if (TARGET_FPU)
10311 sparc_fpu_init_builtins ();
10313 if (TARGET_VIS)
10314 sparc_vis_init_builtins ();
10317 /* Create builtin functions for FPU instructions. */
10319 static void
10320 sparc_fpu_init_builtins (void)
10322 tree ftype
10323 = build_function_type_list (void_type_node,
10324 build_pointer_type (unsigned_type_node), 0);
10325 def_builtin ("__builtin_load_fsr", CODE_FOR_ldfsr,
10326 SPARC_BUILTIN_LDFSR, ftype);
10327 def_builtin ("__builtin_store_fsr", CODE_FOR_stfsr,
10328 SPARC_BUILTIN_STFSR, ftype);
10331 /* Create builtin functions for VIS instructions. */
10333 static void
10334 sparc_vis_init_builtins (void)
10336 tree v4qi = build_vector_type (unsigned_intQI_type_node, 4);
10337 tree v8qi = build_vector_type (unsigned_intQI_type_node, 8);
10338 tree v4hi = build_vector_type (intHI_type_node, 4);
10339 tree v2hi = build_vector_type (intHI_type_node, 2);
10340 tree v2si = build_vector_type (intSI_type_node, 2);
10341 tree v1si = build_vector_type (intSI_type_node, 1);
10343 tree v4qi_ftype_v4hi = build_function_type_list (v4qi, v4hi, 0);
10344 tree v8qi_ftype_v2si_v8qi = build_function_type_list (v8qi, v2si, v8qi, 0);
10345 tree v2hi_ftype_v2si = build_function_type_list (v2hi, v2si, 0);
10346 tree v4hi_ftype_v4qi = build_function_type_list (v4hi, v4qi, 0);
10347 tree v8qi_ftype_v4qi_v4qi = build_function_type_list (v8qi, v4qi, v4qi, 0);
10348 tree v4hi_ftype_v4qi_v4hi = build_function_type_list (v4hi, v4qi, v4hi, 0);
10349 tree v4hi_ftype_v4qi_v2hi = build_function_type_list (v4hi, v4qi, v2hi, 0);
10350 tree v2si_ftype_v4qi_v2hi = build_function_type_list (v2si, v4qi, v2hi, 0);
10351 tree v4hi_ftype_v8qi_v4hi = build_function_type_list (v4hi, v8qi, v4hi, 0);
10352 tree v4hi_ftype_v4hi_v4hi = build_function_type_list (v4hi, v4hi, v4hi, 0);
10353 tree v2si_ftype_v2si_v2si = build_function_type_list (v2si, v2si, v2si, 0);
10354 tree v8qi_ftype_v8qi_v8qi = build_function_type_list (v8qi, v8qi, v8qi, 0);
10355 tree v2hi_ftype_v2hi_v2hi = build_function_type_list (v2hi, v2hi, v2hi, 0);
10356 tree v1si_ftype_v1si_v1si = build_function_type_list (v1si, v1si, v1si, 0);
10357 tree di_ftype_v8qi_v8qi_di = build_function_type_list (intDI_type_node,
10358 v8qi, v8qi,
10359 intDI_type_node, 0);
10360 tree di_ftype_v8qi_v8qi = build_function_type_list (intDI_type_node,
10361 v8qi, v8qi, 0);
10362 tree si_ftype_v8qi_v8qi = build_function_type_list (intSI_type_node,
10363 v8qi, v8qi, 0);
10364 tree di_ftype_di_di = build_function_type_list (intDI_type_node,
10365 intDI_type_node,
10366 intDI_type_node, 0);
10367 tree si_ftype_si_si = build_function_type_list (intSI_type_node,
10368 intSI_type_node,
10369 intSI_type_node, 0);
10370 tree ptr_ftype_ptr_si = build_function_type_list (ptr_type_node,
10371 ptr_type_node,
10372 intSI_type_node, 0);
10373 tree ptr_ftype_ptr_di = build_function_type_list (ptr_type_node,
10374 ptr_type_node,
10375 intDI_type_node, 0);
10376 tree si_ftype_ptr_ptr = build_function_type_list (intSI_type_node,
10377 ptr_type_node,
10378 ptr_type_node, 0);
10379 tree di_ftype_ptr_ptr = build_function_type_list (intDI_type_node,
10380 ptr_type_node,
10381 ptr_type_node, 0);
10382 tree si_ftype_v4hi_v4hi = build_function_type_list (intSI_type_node,
10383 v4hi, v4hi, 0);
10384 tree si_ftype_v2si_v2si = build_function_type_list (intSI_type_node,
10385 v2si, v2si, 0);
10386 tree di_ftype_v4hi_v4hi = build_function_type_list (intDI_type_node,
10387 v4hi, v4hi, 0);
10388 tree di_ftype_v2si_v2si = build_function_type_list (intDI_type_node,
10389 v2si, v2si, 0);
10390 tree void_ftype_di = build_function_type_list (void_type_node,
10391 intDI_type_node, 0);
10392 tree di_ftype_void = build_function_type_list (intDI_type_node,
10393 void_type_node, 0);
10394 tree void_ftype_si = build_function_type_list (void_type_node,
10395 intSI_type_node, 0);
10396 tree sf_ftype_sf_sf = build_function_type_list (float_type_node,
10397 float_type_node,
10398 float_type_node, 0);
10399 tree df_ftype_df_df = build_function_type_list (double_type_node,
10400 double_type_node,
10401 double_type_node, 0);
10403 /* Packing and expanding vectors. */
10404 def_builtin ("__builtin_vis_fpack16", CODE_FOR_fpack16_vis,
10405 SPARC_BUILTIN_FPACK16, v4qi_ftype_v4hi);
10406 def_builtin ("__builtin_vis_fpack32", CODE_FOR_fpack32_vis,
10407 SPARC_BUILTIN_FPACK32, v8qi_ftype_v2si_v8qi);
10408 def_builtin ("__builtin_vis_fpackfix", CODE_FOR_fpackfix_vis,
10409 SPARC_BUILTIN_FPACKFIX, v2hi_ftype_v2si);
10410 def_builtin_const ("__builtin_vis_fexpand", CODE_FOR_fexpand_vis,
10411 SPARC_BUILTIN_FEXPAND, v4hi_ftype_v4qi);
10412 def_builtin_const ("__builtin_vis_fpmerge", CODE_FOR_fpmerge_vis,
10413 SPARC_BUILTIN_FPMERGE, v8qi_ftype_v4qi_v4qi);
10415 /* Multiplications. */
10416 def_builtin_const ("__builtin_vis_fmul8x16", CODE_FOR_fmul8x16_vis,
10417 SPARC_BUILTIN_FMUL8X16, v4hi_ftype_v4qi_v4hi);
10418 def_builtin_const ("__builtin_vis_fmul8x16au", CODE_FOR_fmul8x16au_vis,
10419 SPARC_BUILTIN_FMUL8X16AU, v4hi_ftype_v4qi_v2hi);
10420 def_builtin_const ("__builtin_vis_fmul8x16al", CODE_FOR_fmul8x16al_vis,
10421 SPARC_BUILTIN_FMUL8X16AL, v4hi_ftype_v4qi_v2hi);
10422 def_builtin_const ("__builtin_vis_fmul8sux16", CODE_FOR_fmul8sux16_vis,
10423 SPARC_BUILTIN_FMUL8SUX16, v4hi_ftype_v8qi_v4hi);
10424 def_builtin_const ("__builtin_vis_fmul8ulx16", CODE_FOR_fmul8ulx16_vis,
10425 SPARC_BUILTIN_FMUL8ULX16, v4hi_ftype_v8qi_v4hi);
10426 def_builtin_const ("__builtin_vis_fmuld8sux16", CODE_FOR_fmuld8sux16_vis,
10427 SPARC_BUILTIN_FMULD8SUX16, v2si_ftype_v4qi_v2hi);
10428 def_builtin_const ("__builtin_vis_fmuld8ulx16", CODE_FOR_fmuld8ulx16_vis,
10429 SPARC_BUILTIN_FMULD8ULX16, v2si_ftype_v4qi_v2hi);
10431 /* Data aligning. */
10432 def_builtin ("__builtin_vis_faligndatav4hi", CODE_FOR_faligndatav4hi_vis,
10433 SPARC_BUILTIN_FALIGNDATAV4HI, v4hi_ftype_v4hi_v4hi);
10434 def_builtin ("__builtin_vis_faligndatav8qi", CODE_FOR_faligndatav8qi_vis,
10435 SPARC_BUILTIN_FALIGNDATAV8QI, v8qi_ftype_v8qi_v8qi);
10436 def_builtin ("__builtin_vis_faligndatav2si", CODE_FOR_faligndatav2si_vis,
10437 SPARC_BUILTIN_FALIGNDATAV2SI, v2si_ftype_v2si_v2si);
10438 def_builtin ("__builtin_vis_faligndatadi", CODE_FOR_faligndatav1di_vis,
10439 SPARC_BUILTIN_FALIGNDATADI, di_ftype_di_di);
10441 def_builtin ("__builtin_vis_write_gsr", CODE_FOR_wrgsr_vis,
10442 SPARC_BUILTIN_WRGSR, void_ftype_di);
10443 def_builtin ("__builtin_vis_read_gsr", CODE_FOR_rdgsr_vis,
10444 SPARC_BUILTIN_RDGSR, di_ftype_void);
10446 if (TARGET_ARCH64)
10448 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrdi_vis,
10449 SPARC_BUILTIN_ALIGNADDR, ptr_ftype_ptr_di);
10450 def_builtin ("__builtin_vis_alignaddrl", CODE_FOR_alignaddrldi_vis,
10451 SPARC_BUILTIN_ALIGNADDRL, ptr_ftype_ptr_di);
10453 else
10455 def_builtin ("__builtin_vis_alignaddr", CODE_FOR_alignaddrsi_vis,
10456 SPARC_BUILTIN_ALIGNADDR, ptr_ftype_ptr_si);
10457 def_builtin ("__builtin_vis_alignaddrl", CODE_FOR_alignaddrlsi_vis,
10458 SPARC_BUILTIN_ALIGNADDRL, ptr_ftype_ptr_si);
10461 /* Pixel distance. */
10462 def_builtin_const ("__builtin_vis_pdist", CODE_FOR_pdist_vis,
10463 SPARC_BUILTIN_PDIST, di_ftype_v8qi_v8qi_di);
10465 /* Edge handling. */
10466 if (TARGET_ARCH64)
10468 def_builtin_const ("__builtin_vis_edge8", CODE_FOR_edge8di_vis,
10469 SPARC_BUILTIN_EDGE8, di_ftype_ptr_ptr);
10470 def_builtin_const ("__builtin_vis_edge8l", CODE_FOR_edge8ldi_vis,
10471 SPARC_BUILTIN_EDGE8L, di_ftype_ptr_ptr);
10472 def_builtin_const ("__builtin_vis_edge16", CODE_FOR_edge16di_vis,
10473 SPARC_BUILTIN_EDGE16, di_ftype_ptr_ptr);
10474 def_builtin_const ("__builtin_vis_edge16l", CODE_FOR_edge16ldi_vis,
10475 SPARC_BUILTIN_EDGE16L, di_ftype_ptr_ptr);
10476 def_builtin_const ("__builtin_vis_edge32", CODE_FOR_edge32di_vis,
10477 SPARC_BUILTIN_EDGE32, di_ftype_ptr_ptr);
10478 def_builtin_const ("__builtin_vis_edge32l", CODE_FOR_edge32ldi_vis,
10479 SPARC_BUILTIN_EDGE32L, di_ftype_ptr_ptr);
10481 else
10483 def_builtin_const ("__builtin_vis_edge8", CODE_FOR_edge8si_vis,
10484 SPARC_BUILTIN_EDGE8, si_ftype_ptr_ptr);
10485 def_builtin_const ("__builtin_vis_edge8l", CODE_FOR_edge8lsi_vis,
10486 SPARC_BUILTIN_EDGE8L, si_ftype_ptr_ptr);
10487 def_builtin_const ("__builtin_vis_edge16", CODE_FOR_edge16si_vis,
10488 SPARC_BUILTIN_EDGE16, si_ftype_ptr_ptr);
10489 def_builtin_const ("__builtin_vis_edge16l", CODE_FOR_edge16lsi_vis,
10490 SPARC_BUILTIN_EDGE16L, si_ftype_ptr_ptr);
10491 def_builtin_const ("__builtin_vis_edge32", CODE_FOR_edge32si_vis,
10492 SPARC_BUILTIN_EDGE32, si_ftype_ptr_ptr);
10493 def_builtin_const ("__builtin_vis_edge32l", CODE_FOR_edge32lsi_vis,
10494 SPARC_BUILTIN_EDGE32L, si_ftype_ptr_ptr);
10497 /* Pixel compare. */
10498 if (TARGET_ARCH64)
10500 def_builtin_const ("__builtin_vis_fcmple16", CODE_FOR_fcmple16di_vis,
10501 SPARC_BUILTIN_FCMPLE16, di_ftype_v4hi_v4hi);
10502 def_builtin_const ("__builtin_vis_fcmple32", CODE_FOR_fcmple32di_vis,
10503 SPARC_BUILTIN_FCMPLE32, di_ftype_v2si_v2si);
10504 def_builtin_const ("__builtin_vis_fcmpne16", CODE_FOR_fcmpne16di_vis,
10505 SPARC_BUILTIN_FCMPNE16, di_ftype_v4hi_v4hi);
10506 def_builtin_const ("__builtin_vis_fcmpne32", CODE_FOR_fcmpne32di_vis,
10507 SPARC_BUILTIN_FCMPNE32, di_ftype_v2si_v2si);
10508 def_builtin_const ("__builtin_vis_fcmpgt16", CODE_FOR_fcmpgt16di_vis,
10509 SPARC_BUILTIN_FCMPGT16, di_ftype_v4hi_v4hi);
10510 def_builtin_const ("__builtin_vis_fcmpgt32", CODE_FOR_fcmpgt32di_vis,
10511 SPARC_BUILTIN_FCMPGT32, di_ftype_v2si_v2si);
10512 def_builtin_const ("__builtin_vis_fcmpeq16", CODE_FOR_fcmpeq16di_vis,
10513 SPARC_BUILTIN_FCMPEQ16, di_ftype_v4hi_v4hi);
10514 def_builtin_const ("__builtin_vis_fcmpeq32", CODE_FOR_fcmpeq32di_vis,
10515 SPARC_BUILTIN_FCMPEQ32, di_ftype_v2si_v2si);
10517 else
10519 def_builtin_const ("__builtin_vis_fcmple16", CODE_FOR_fcmple16si_vis,
10520 SPARC_BUILTIN_FCMPLE16, si_ftype_v4hi_v4hi);
10521 def_builtin_const ("__builtin_vis_fcmple32", CODE_FOR_fcmple32si_vis,
10522 SPARC_BUILTIN_FCMPLE32, si_ftype_v2si_v2si);
10523 def_builtin_const ("__builtin_vis_fcmpne16", CODE_FOR_fcmpne16si_vis,
10524 SPARC_BUILTIN_FCMPNE16, si_ftype_v4hi_v4hi);
10525 def_builtin_const ("__builtin_vis_fcmpne32", CODE_FOR_fcmpne32si_vis,
10526 SPARC_BUILTIN_FCMPNE32, si_ftype_v2si_v2si);
10527 def_builtin_const ("__builtin_vis_fcmpgt16", CODE_FOR_fcmpgt16si_vis,
10528 SPARC_BUILTIN_FCMPGT16, si_ftype_v4hi_v4hi);
10529 def_builtin_const ("__builtin_vis_fcmpgt32", CODE_FOR_fcmpgt32si_vis,
10530 SPARC_BUILTIN_FCMPGT32, si_ftype_v2si_v2si);
10531 def_builtin_const ("__builtin_vis_fcmpeq16", CODE_FOR_fcmpeq16si_vis,
10532 SPARC_BUILTIN_FCMPEQ16, si_ftype_v4hi_v4hi);
10533 def_builtin_const ("__builtin_vis_fcmpeq32", CODE_FOR_fcmpeq32si_vis,
10534 SPARC_BUILTIN_FCMPEQ32, si_ftype_v2si_v2si);
10537 /* Addition and subtraction. */
10538 def_builtin_const ("__builtin_vis_fpadd16", CODE_FOR_addv4hi3,
10539 SPARC_BUILTIN_FPADD16, v4hi_ftype_v4hi_v4hi);
10540 def_builtin_const ("__builtin_vis_fpadd16s", CODE_FOR_addv2hi3,
10541 SPARC_BUILTIN_FPADD16S, v2hi_ftype_v2hi_v2hi);
10542 def_builtin_const ("__builtin_vis_fpadd32", CODE_FOR_addv2si3,
10543 SPARC_BUILTIN_FPADD32, v2si_ftype_v2si_v2si);
10544 def_builtin_const ("__builtin_vis_fpadd32s", CODE_FOR_addv1si3,
10545 SPARC_BUILTIN_FPADD32S, v1si_ftype_v1si_v1si);
10546 def_builtin_const ("__builtin_vis_fpsub16", CODE_FOR_subv4hi3,
10547 SPARC_BUILTIN_FPSUB16, v4hi_ftype_v4hi_v4hi);
10548 def_builtin_const ("__builtin_vis_fpsub16s", CODE_FOR_subv2hi3,
10549 SPARC_BUILTIN_FPSUB16S, v2hi_ftype_v2hi_v2hi);
10550 def_builtin_const ("__builtin_vis_fpsub32", CODE_FOR_subv2si3,
10551 SPARC_BUILTIN_FPSUB32, v2si_ftype_v2si_v2si);
10552 def_builtin_const ("__builtin_vis_fpsub32s", CODE_FOR_subv1si3,
10553 SPARC_BUILTIN_FPSUB32S, v1si_ftype_v1si_v1si);
10555 /* Three-dimensional array addressing. */
10556 if (TARGET_ARCH64)
10558 def_builtin_const ("__builtin_vis_array8", CODE_FOR_array8di_vis,
10559 SPARC_BUILTIN_ARRAY8, di_ftype_di_di);
10560 def_builtin_const ("__builtin_vis_array16", CODE_FOR_array16di_vis,
10561 SPARC_BUILTIN_ARRAY16, di_ftype_di_di);
10562 def_builtin_const ("__builtin_vis_array32", CODE_FOR_array32di_vis,
10563 SPARC_BUILTIN_ARRAY32, di_ftype_di_di);
10565 else
10567 def_builtin_const ("__builtin_vis_array8", CODE_FOR_array8si_vis,
10568 SPARC_BUILTIN_ARRAY8, si_ftype_si_si);
10569 def_builtin_const ("__builtin_vis_array16", CODE_FOR_array16si_vis,
10570 SPARC_BUILTIN_ARRAY16, si_ftype_si_si);
10571 def_builtin_const ("__builtin_vis_array32", CODE_FOR_array32si_vis,
10572 SPARC_BUILTIN_ARRAY32, si_ftype_si_si);
10575 if (TARGET_VIS2)
10577 /* Edge handling. */
10578 if (TARGET_ARCH64)
10580 def_builtin_const ("__builtin_vis_edge8n", CODE_FOR_edge8ndi_vis,
10581 SPARC_BUILTIN_EDGE8N, di_ftype_ptr_ptr);
10582 def_builtin_const ("__builtin_vis_edge8ln", CODE_FOR_edge8lndi_vis,
10583 SPARC_BUILTIN_EDGE8LN, di_ftype_ptr_ptr);
10584 def_builtin_const ("__builtin_vis_edge16n", CODE_FOR_edge16ndi_vis,
10585 SPARC_BUILTIN_EDGE16N, di_ftype_ptr_ptr);
10586 def_builtin_const ("__builtin_vis_edge16ln", CODE_FOR_edge16lndi_vis,
10587 SPARC_BUILTIN_EDGE16LN, di_ftype_ptr_ptr);
10588 def_builtin_const ("__builtin_vis_edge32n", CODE_FOR_edge32ndi_vis,
10589 SPARC_BUILTIN_EDGE32N, di_ftype_ptr_ptr);
10590 def_builtin_const ("__builtin_vis_edge32ln", CODE_FOR_edge32lndi_vis,
10591 SPARC_BUILTIN_EDGE32LN, di_ftype_ptr_ptr);
10593 else
10595 def_builtin_const ("__builtin_vis_edge8n", CODE_FOR_edge8nsi_vis,
10596 SPARC_BUILTIN_EDGE8N, si_ftype_ptr_ptr);
10597 def_builtin_const ("__builtin_vis_edge8ln", CODE_FOR_edge8lnsi_vis,
10598 SPARC_BUILTIN_EDGE8LN, si_ftype_ptr_ptr);
10599 def_builtin_const ("__builtin_vis_edge16n", CODE_FOR_edge16nsi_vis,
10600 SPARC_BUILTIN_EDGE16N, si_ftype_ptr_ptr);
10601 def_builtin_const ("__builtin_vis_edge16ln", CODE_FOR_edge16lnsi_vis,
10602 SPARC_BUILTIN_EDGE16LN, si_ftype_ptr_ptr);
10603 def_builtin_const ("__builtin_vis_edge32n", CODE_FOR_edge32nsi_vis,
10604 SPARC_BUILTIN_EDGE32N, si_ftype_ptr_ptr);
10605 def_builtin_const ("__builtin_vis_edge32ln", CODE_FOR_edge32lnsi_vis,
10606 SPARC_BUILTIN_EDGE32LN, si_ftype_ptr_ptr);
10609 /* Byte mask and shuffle. */
10610 if (TARGET_ARCH64)
10611 def_builtin ("__builtin_vis_bmask", CODE_FOR_bmaskdi_vis,
10612 SPARC_BUILTIN_BMASK, di_ftype_di_di);
10613 else
10614 def_builtin ("__builtin_vis_bmask", CODE_FOR_bmasksi_vis,
10615 SPARC_BUILTIN_BMASK, si_ftype_si_si);
10616 def_builtin ("__builtin_vis_bshufflev4hi", CODE_FOR_bshufflev4hi_vis,
10617 SPARC_BUILTIN_BSHUFFLEV4HI, v4hi_ftype_v4hi_v4hi);
10618 def_builtin ("__builtin_vis_bshufflev8qi", CODE_FOR_bshufflev8qi_vis,
10619 SPARC_BUILTIN_BSHUFFLEV8QI, v8qi_ftype_v8qi_v8qi);
10620 def_builtin ("__builtin_vis_bshufflev2si", CODE_FOR_bshufflev2si_vis,
10621 SPARC_BUILTIN_BSHUFFLEV2SI, v2si_ftype_v2si_v2si);
10622 def_builtin ("__builtin_vis_bshuffledi", CODE_FOR_bshufflev1di_vis,
10623 SPARC_BUILTIN_BSHUFFLEDI, di_ftype_di_di);
10626 if (TARGET_VIS3)
10628 if (TARGET_ARCH64)
10630 def_builtin ("__builtin_vis_cmask8", CODE_FOR_cmask8di_vis,
10631 SPARC_BUILTIN_CMASK8, void_ftype_di);
10632 def_builtin ("__builtin_vis_cmask16", CODE_FOR_cmask16di_vis,
10633 SPARC_BUILTIN_CMASK16, void_ftype_di);
10634 def_builtin ("__builtin_vis_cmask32", CODE_FOR_cmask32di_vis,
10635 SPARC_BUILTIN_CMASK32, void_ftype_di);
10637 else
10639 def_builtin ("__builtin_vis_cmask8", CODE_FOR_cmask8si_vis,
10640 SPARC_BUILTIN_CMASK8, void_ftype_si);
10641 def_builtin ("__builtin_vis_cmask16", CODE_FOR_cmask16si_vis,
10642 SPARC_BUILTIN_CMASK16, void_ftype_si);
10643 def_builtin ("__builtin_vis_cmask32", CODE_FOR_cmask32si_vis,
10644 SPARC_BUILTIN_CMASK32, void_ftype_si);
10647 def_builtin_const ("__builtin_vis_fchksm16", CODE_FOR_fchksm16_vis,
10648 SPARC_BUILTIN_FCHKSM16, v4hi_ftype_v4hi_v4hi);
10650 def_builtin_const ("__builtin_vis_fsll16", CODE_FOR_vashlv4hi3,
10651 SPARC_BUILTIN_FSLL16, v4hi_ftype_v4hi_v4hi);
10652 def_builtin_const ("__builtin_vis_fslas16", CODE_FOR_vssashlv4hi3,
10653 SPARC_BUILTIN_FSLAS16, v4hi_ftype_v4hi_v4hi);
10654 def_builtin_const ("__builtin_vis_fsrl16", CODE_FOR_vlshrv4hi3,
10655 SPARC_BUILTIN_FSRL16, v4hi_ftype_v4hi_v4hi);
10656 def_builtin_const ("__builtin_vis_fsra16", CODE_FOR_vashrv4hi3,
10657 SPARC_BUILTIN_FSRA16, v4hi_ftype_v4hi_v4hi);
10658 def_builtin_const ("__builtin_vis_fsll32", CODE_FOR_vashlv2si3,
10659 SPARC_BUILTIN_FSLL32, v2si_ftype_v2si_v2si);
10660 def_builtin_const ("__builtin_vis_fslas32", CODE_FOR_vssashlv2si3,
10661 SPARC_BUILTIN_FSLAS32, v2si_ftype_v2si_v2si);
10662 def_builtin_const ("__builtin_vis_fsrl32", CODE_FOR_vlshrv2si3,
10663 SPARC_BUILTIN_FSRL32, v2si_ftype_v2si_v2si);
10664 def_builtin_const ("__builtin_vis_fsra32", CODE_FOR_vashrv2si3,
10665 SPARC_BUILTIN_FSRA32, v2si_ftype_v2si_v2si);
10667 if (TARGET_ARCH64)
10668 def_builtin_const ("__builtin_vis_pdistn", CODE_FOR_pdistndi_vis,
10669 SPARC_BUILTIN_PDISTN, di_ftype_v8qi_v8qi);
10670 else
10671 def_builtin_const ("__builtin_vis_pdistn", CODE_FOR_pdistnsi_vis,
10672 SPARC_BUILTIN_PDISTN, si_ftype_v8qi_v8qi);
10674 def_builtin_const ("__builtin_vis_fmean16", CODE_FOR_fmean16_vis,
10675 SPARC_BUILTIN_FMEAN16, v4hi_ftype_v4hi_v4hi);
10676 def_builtin_const ("__builtin_vis_fpadd64", CODE_FOR_fpadd64_vis,
10677 SPARC_BUILTIN_FPADD64, di_ftype_di_di);
10678 def_builtin_const ("__builtin_vis_fpsub64", CODE_FOR_fpsub64_vis,
10679 SPARC_BUILTIN_FPSUB64, di_ftype_di_di);
10681 def_builtin_const ("__builtin_vis_fpadds16", CODE_FOR_ssaddv4hi3,
10682 SPARC_BUILTIN_FPADDS16, v4hi_ftype_v4hi_v4hi);
10683 def_builtin_const ("__builtin_vis_fpadds16s", CODE_FOR_ssaddv2hi3,
10684 SPARC_BUILTIN_FPADDS16S, v2hi_ftype_v2hi_v2hi);
10685 def_builtin_const ("__builtin_vis_fpsubs16", CODE_FOR_sssubv4hi3,
10686 SPARC_BUILTIN_FPSUBS16, v4hi_ftype_v4hi_v4hi);
10687 def_builtin_const ("__builtin_vis_fpsubs16s", CODE_FOR_sssubv2hi3,
10688 SPARC_BUILTIN_FPSUBS16S, v2hi_ftype_v2hi_v2hi);
10689 def_builtin_const ("__builtin_vis_fpadds32", CODE_FOR_ssaddv2si3,
10690 SPARC_BUILTIN_FPADDS32, v2si_ftype_v2si_v2si);
10691 def_builtin_const ("__builtin_vis_fpadds32s", CODE_FOR_ssaddv1si3,
10692 SPARC_BUILTIN_FPADDS32S, v1si_ftype_v1si_v1si);
10693 def_builtin_const ("__builtin_vis_fpsubs32", CODE_FOR_sssubv2si3,
10694 SPARC_BUILTIN_FPSUBS32, v2si_ftype_v2si_v2si);
10695 def_builtin_const ("__builtin_vis_fpsubs32s", CODE_FOR_sssubv1si3,
10696 SPARC_BUILTIN_FPSUBS32S, v1si_ftype_v1si_v1si);
10698 if (TARGET_ARCH64)
10700 def_builtin_const ("__builtin_vis_fucmple8", CODE_FOR_fucmple8di_vis,
10701 SPARC_BUILTIN_FUCMPLE8, di_ftype_v8qi_v8qi);
10702 def_builtin_const ("__builtin_vis_fucmpne8", CODE_FOR_fucmpne8di_vis,
10703 SPARC_BUILTIN_FUCMPNE8, di_ftype_v8qi_v8qi);
10704 def_builtin_const ("__builtin_vis_fucmpgt8", CODE_FOR_fucmpgt8di_vis,
10705 SPARC_BUILTIN_FUCMPGT8, di_ftype_v8qi_v8qi);
10706 def_builtin_const ("__builtin_vis_fucmpeq8", CODE_FOR_fucmpeq8di_vis,
10707 SPARC_BUILTIN_FUCMPEQ8, di_ftype_v8qi_v8qi);
10709 else
10711 def_builtin_const ("__builtin_vis_fucmple8", CODE_FOR_fucmple8si_vis,
10712 SPARC_BUILTIN_FUCMPLE8, si_ftype_v8qi_v8qi);
10713 def_builtin_const ("__builtin_vis_fucmpne8", CODE_FOR_fucmpne8si_vis,
10714 SPARC_BUILTIN_FUCMPNE8, si_ftype_v8qi_v8qi);
10715 def_builtin_const ("__builtin_vis_fucmpgt8", CODE_FOR_fucmpgt8si_vis,
10716 SPARC_BUILTIN_FUCMPGT8, si_ftype_v8qi_v8qi);
10717 def_builtin_const ("__builtin_vis_fucmpeq8", CODE_FOR_fucmpeq8si_vis,
10718 SPARC_BUILTIN_FUCMPEQ8, si_ftype_v8qi_v8qi);
10721 def_builtin_const ("__builtin_vis_fhadds", CODE_FOR_fhaddsf_vis,
10722 SPARC_BUILTIN_FHADDS, sf_ftype_sf_sf);
10723 def_builtin_const ("__builtin_vis_fhaddd", CODE_FOR_fhadddf_vis,
10724 SPARC_BUILTIN_FHADDD, df_ftype_df_df);
10725 def_builtin_const ("__builtin_vis_fhsubs", CODE_FOR_fhsubsf_vis,
10726 SPARC_BUILTIN_FHSUBS, sf_ftype_sf_sf);
10727 def_builtin_const ("__builtin_vis_fhsubd", CODE_FOR_fhsubdf_vis,
10728 SPARC_BUILTIN_FHSUBD, df_ftype_df_df);
10729 def_builtin_const ("__builtin_vis_fnhadds", CODE_FOR_fnhaddsf_vis,
10730 SPARC_BUILTIN_FNHADDS, sf_ftype_sf_sf);
10731 def_builtin_const ("__builtin_vis_fnhaddd", CODE_FOR_fnhadddf_vis,
10732 SPARC_BUILTIN_FNHADDD, df_ftype_df_df);
10734 def_builtin_const ("__builtin_vis_umulxhi", CODE_FOR_umulxhi_vis,
10735 SPARC_BUILTIN_UMULXHI, di_ftype_di_di);
10736 def_builtin_const ("__builtin_vis_xmulx", CODE_FOR_xmulx_vis,
10737 SPARC_BUILTIN_XMULX, di_ftype_di_di);
10738 def_builtin_const ("__builtin_vis_xmulxhi", CODE_FOR_xmulxhi_vis,
10739 SPARC_BUILTIN_XMULXHI, di_ftype_di_di);
10742 if (TARGET_VIS4)
10744 def_builtin_const ("__builtin_vis_fpadd8", CODE_FOR_addv8qi3,
10745 SPARC_BUILTIN_FPADD8, v8qi_ftype_v8qi_v8qi);
10746 def_builtin_const ("__builtin_vis_fpadds8", CODE_FOR_ssaddv8qi3,
10747 SPARC_BUILTIN_FPADDS8, v8qi_ftype_v8qi_v8qi);
10748 def_builtin_const ("__builtin_vis_fpaddus8", CODE_FOR_usaddv8qi3,
10749 SPARC_BUILTIN_FPADDUS8, v8qi_ftype_v8qi_v8qi);
10750 def_builtin_const ("__builtin_vis_fpaddus16", CODE_FOR_usaddv4hi3,
10751 SPARC_BUILTIN_FPADDUS16, v4hi_ftype_v4hi_v4hi);
10754 if (TARGET_ARCH64)
10756 def_builtin_const ("__builtin_vis_fpcmple8", CODE_FOR_fpcmple8di_vis,
10757 SPARC_BUILTIN_FPCMPLE8, di_ftype_v8qi_v8qi);
10758 def_builtin_const ("__builtin_vis_fpcmpgt8", CODE_FOR_fpcmpgt8di_vis,
10759 SPARC_BUILTIN_FPCMPGT8, di_ftype_v8qi_v8qi);
10760 def_builtin_const ("__builtin_vis_fpcmpule16", CODE_FOR_fpcmpule16di_vis,
10761 SPARC_BUILTIN_FPCMPULE16, di_ftype_v4hi_v4hi);
10762 def_builtin_const ("__builtin_vis_fpcmpugt16", CODE_FOR_fpcmpugt16di_vis,
10763 SPARC_BUILTIN_FPCMPUGT16, di_ftype_v4hi_v4hi);
10764 def_builtin_const ("__builtin_vis_fpcmpule32", CODE_FOR_fpcmpule32di_vis,
10765 SPARC_BUILTIN_FPCMPULE32, di_ftype_v2si_v2si);
10766 def_builtin_const ("__builtin_vis_fpcmpugt32", CODE_FOR_fpcmpugt32di_vis,
10767 SPARC_BUILTIN_FPCMPUGT32, di_ftype_v2si_v2si);
10769 else
10771 def_builtin_const ("__builtin_vis_fpcmple8", CODE_FOR_fpcmple8si_vis,
10772 SPARC_BUILTIN_FPCMPLE8, si_ftype_v8qi_v8qi);
10773 def_builtin_const ("__builtin_vis_fpcmpgt8", CODE_FOR_fpcmpgt8si_vis,
10774 SPARC_BUILTIN_FPCMPGT8, si_ftype_v8qi_v8qi);
10775 def_builtin_const ("__builtin_vis_fpcmpule16", CODE_FOR_fpcmpule16si_vis,
10776 SPARC_BUILTIN_FPCMPULE16, si_ftype_v4hi_v4hi);
10777 def_builtin_const ("__builtin_vis_fpcmpugt16", CODE_FOR_fpcmpugt16si_vis,
10778 SPARC_BUILTIN_FPCMPUGT16, si_ftype_v4hi_v4hi);
10779 def_builtin_const ("__builtin_vis_fpcmpule32", CODE_FOR_fpcmpule32si_vis,
10780 SPARC_BUILTIN_FPCMPULE32, di_ftype_v2si_v2si);
10781 def_builtin_const ("__builtin_vis_fpcmpugt32", CODE_FOR_fpcmpugt32si_vis,
10782 SPARC_BUILTIN_FPCMPUGT32, di_ftype_v2si_v2si);
10785 def_builtin_const ("__builtin_vis_fpmax8", CODE_FOR_maxv8qi3,
10786 SPARC_BUILTIN_FPMAX8, v8qi_ftype_v8qi_v8qi);
10787 def_builtin_const ("__builtin_vis_fpmax16", CODE_FOR_maxv4hi3,
10788 SPARC_BUILTIN_FPMAX16, v4hi_ftype_v4hi_v4hi);
10789 def_builtin_const ("__builtin_vis_fpmax32", CODE_FOR_maxv2si3,
10790 SPARC_BUILTIN_FPMAX32, v2si_ftype_v2si_v2si);
10791 def_builtin_const ("__builtin_vis_fpmaxu8", CODE_FOR_maxuv8qi3,
10792 SPARC_BUILTIN_FPMAXU8, v8qi_ftype_v8qi_v8qi);
10793 def_builtin_const ("__builtin_vis_fpmaxu16", CODE_FOR_maxuv4hi3,
10794 SPARC_BUILTIN_FPMAXU16, v4hi_ftype_v4hi_v4hi);
10795 def_builtin_const ("__builtin_vis_fpmaxu32", CODE_FOR_maxuv2si3,
10796 SPARC_BUILTIN_FPMAXU32, v2si_ftype_v2si_v2si);
10797 def_builtin_const ("__builtin_vis_fpmin8", CODE_FOR_minv8qi3,
10798 SPARC_BUILTIN_FPMIN8, v8qi_ftype_v8qi_v8qi);
10799 def_builtin_const ("__builtin_vis_fpmin16", CODE_FOR_minv4hi3,
10800 SPARC_BUILTIN_FPMIN16, v4hi_ftype_v4hi_v4hi);
10801 def_builtin_const ("__builtin_vis_fpmin32", CODE_FOR_minv2si3,
10802 SPARC_BUILTIN_FPMIN32, v2si_ftype_v2si_v2si);
10803 def_builtin_const ("__builtin_vis_fpminu8", CODE_FOR_minuv8qi3,
10804 SPARC_BUILTIN_FPMINU8, v8qi_ftype_v8qi_v8qi);
10805 def_builtin_const ("__builtin_vis_fpminu16", CODE_FOR_minuv4hi3,
10806 SPARC_BUILTIN_FPMINU16, v4hi_ftype_v4hi_v4hi);
10807 def_builtin_const ("__builtin_vis_fpminu32", CODE_FOR_minuv2si3,
10808 SPARC_BUILTIN_FPMINU32, v2si_ftype_v2si_v2si);
10809 def_builtin_const ("__builtin_vis_fpsub8", CODE_FOR_subv8qi3,
10810 SPARC_BUILTIN_FPSUB8, v8qi_ftype_v8qi_v8qi);
10811 def_builtin_const ("__builtin_vis_fpsubs8", CODE_FOR_sssubv8qi3,
10812 SPARC_BUILTIN_FPSUBS8, v8qi_ftype_v8qi_v8qi);
10813 def_builtin_const ("__builtin_vis_fpsubus8", CODE_FOR_ussubv8qi3,
10814 SPARC_BUILTIN_FPSUBUS8, v8qi_ftype_v8qi_v8qi);
10815 def_builtin_const ("__builtin_vis_fpsubus16", CODE_FOR_ussubv4hi3,
10816 SPARC_BUILTIN_FPSUBUS16, v4hi_ftype_v4hi_v4hi);
10820 /* Implement TARGET_BUILTIN_DECL hook. */
10822 static tree
10823 sparc_builtin_decl (unsigned code, bool initialize_p ATTRIBUTE_UNUSED)
10825 if (code >= SPARC_BUILTIN_MAX)
10826 return error_mark_node;
10828 return sparc_builtins[code];
10831 /* Implemented TARGET_EXPAND_BUILTIN hook. */
10833 static rtx
10834 sparc_expand_builtin (tree exp, rtx target,
10835 rtx subtarget ATTRIBUTE_UNUSED,
10836 machine_mode tmode ATTRIBUTE_UNUSED,
10837 int ignore ATTRIBUTE_UNUSED)
10839 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
10840 enum sparc_builtins code = (enum sparc_builtins) DECL_FUNCTION_CODE (fndecl);
10841 enum insn_code icode = sparc_builtins_icode[code];
10842 bool nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node;
10843 call_expr_arg_iterator iter;
10844 int arg_count = 0;
10845 rtx pat, op[4];
10846 tree arg;
10848 if (nonvoid)
10850 machine_mode tmode = insn_data[icode].operand[0].mode;
10851 if (!target
10852 || GET_MODE (target) != tmode
10853 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
10854 op[0] = gen_reg_rtx (tmode);
10855 else
10856 op[0] = target;
10859 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
10861 const struct insn_operand_data *insn_op;
10862 int idx;
10864 if (arg == error_mark_node)
10865 return NULL_RTX;
10867 arg_count++;
10868 idx = arg_count - !nonvoid;
10869 insn_op = &insn_data[icode].operand[idx];
10870 op[arg_count] = expand_normal (arg);
10872 if (code == SPARC_BUILTIN_LDFSR || code == SPARC_BUILTIN_STFSR)
10874 if (!address_operand (op[arg_count], SImode))
10876 op[arg_count] = convert_memory_address (Pmode, op[arg_count]);
10877 op[arg_count] = copy_addr_to_reg (op[arg_count]);
10879 op[arg_count] = gen_rtx_MEM (SImode, op[arg_count]);
10882 else if (insn_op->mode == V1DImode
10883 && GET_MODE (op[arg_count]) == DImode)
10884 op[arg_count] = gen_lowpart (V1DImode, op[arg_count]);
10886 else if (insn_op->mode == V1SImode
10887 && GET_MODE (op[arg_count]) == SImode)
10888 op[arg_count] = gen_lowpart (V1SImode, op[arg_count]);
10890 if (! (*insn_data[icode].operand[idx].predicate) (op[arg_count],
10891 insn_op->mode))
10892 op[arg_count] = copy_to_mode_reg (insn_op->mode, op[arg_count]);
10895 switch (arg_count)
10897 case 0:
10898 pat = GEN_FCN (icode) (op[0]);
10899 break;
10900 case 1:
10901 if (nonvoid)
10902 pat = GEN_FCN (icode) (op[0], op[1]);
10903 else
10904 pat = GEN_FCN (icode) (op[1]);
10905 break;
10906 case 2:
10907 pat = GEN_FCN (icode) (op[0], op[1], op[2]);
10908 break;
10909 case 3:
10910 pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]);
10911 break;
10912 default:
10913 gcc_unreachable ();
10916 if (!pat)
10917 return NULL_RTX;
10919 emit_insn (pat);
10921 return (nonvoid ? op[0] : const0_rtx);
10924 /* Return the upper 16 bits of the 8x16 multiplication. */
10926 static int
10927 sparc_vis_mul8x16 (int e8, int e16)
10929 return (e8 * e16 + 128) / 256;
10932 /* Multiply the VECTOR_CSTs CST0 and CST1 as specified by FNCODE and put
10933 the result into the array N_ELTS, whose elements are of INNER_TYPE. */
10935 static void
10936 sparc_handle_vis_mul8x16 (tree *n_elts, enum sparc_builtins fncode,
10937 tree inner_type, tree cst0, tree cst1)
10939 unsigned i, num = VECTOR_CST_NELTS (cst0);
10940 int scale;
10942 switch (fncode)
10944 case SPARC_BUILTIN_FMUL8X16:
10945 for (i = 0; i < num; ++i)
10947 int val
10948 = sparc_vis_mul8x16 (TREE_INT_CST_LOW (VECTOR_CST_ELT (cst0, i)),
10949 TREE_INT_CST_LOW (VECTOR_CST_ELT (cst1, i)));
10950 n_elts[i] = build_int_cst (inner_type, val);
10952 break;
10954 case SPARC_BUILTIN_FMUL8X16AU:
10955 scale = TREE_INT_CST_LOW (VECTOR_CST_ELT (cst1, 0));
10957 for (i = 0; i < num; ++i)
10959 int val
10960 = sparc_vis_mul8x16 (TREE_INT_CST_LOW (VECTOR_CST_ELT (cst0, i)),
10961 scale);
10962 n_elts[i] = build_int_cst (inner_type, val);
10964 break;
10966 case SPARC_BUILTIN_FMUL8X16AL:
10967 scale = TREE_INT_CST_LOW (VECTOR_CST_ELT (cst1, 1));
10969 for (i = 0; i < num; ++i)
10971 int val
10972 = sparc_vis_mul8x16 (TREE_INT_CST_LOW (VECTOR_CST_ELT (cst0, i)),
10973 scale);
10974 n_elts[i] = build_int_cst (inner_type, val);
10976 break;
10978 default:
10979 gcc_unreachable ();
10983 /* Implement TARGET_FOLD_BUILTIN hook.
10985 Fold builtin functions for SPARC intrinsics. If IGNORE is true the
10986 result of the function call is ignored. NULL_TREE is returned if the
10987 function could not be folded. */
10989 static tree
10990 sparc_fold_builtin (tree fndecl, int n_args ATTRIBUTE_UNUSED,
10991 tree *args, bool ignore)
10993 enum sparc_builtins code = (enum sparc_builtins) DECL_FUNCTION_CODE (fndecl);
10994 tree rtype = TREE_TYPE (TREE_TYPE (fndecl));
10995 tree arg0, arg1, arg2;
10997 if (ignore)
10998 switch (code)
11000 case SPARC_BUILTIN_LDFSR:
11001 case SPARC_BUILTIN_STFSR:
11002 case SPARC_BUILTIN_ALIGNADDR:
11003 case SPARC_BUILTIN_WRGSR:
11004 case SPARC_BUILTIN_BMASK:
11005 case SPARC_BUILTIN_CMASK8:
11006 case SPARC_BUILTIN_CMASK16:
11007 case SPARC_BUILTIN_CMASK32:
11008 break;
11010 default:
11011 return build_zero_cst (rtype);
11014 switch (code)
11016 case SPARC_BUILTIN_FEXPAND:
11017 arg0 = args[0];
11018 STRIP_NOPS (arg0);
11020 if (TREE_CODE (arg0) == VECTOR_CST)
11022 tree inner_type = TREE_TYPE (rtype);
11023 tree *n_elts;
11024 unsigned i;
11026 n_elts = XALLOCAVEC (tree, VECTOR_CST_NELTS (arg0));
11027 for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
11028 n_elts[i] = build_int_cst (inner_type,
11029 TREE_INT_CST_LOW
11030 (VECTOR_CST_ELT (arg0, i)) << 4);
11031 return build_vector (rtype, n_elts);
11033 break;
11035 case SPARC_BUILTIN_FMUL8X16:
11036 case SPARC_BUILTIN_FMUL8X16AU:
11037 case SPARC_BUILTIN_FMUL8X16AL:
11038 arg0 = args[0];
11039 arg1 = args[1];
11040 STRIP_NOPS (arg0);
11041 STRIP_NOPS (arg1);
11043 if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)
11045 tree inner_type = TREE_TYPE (rtype);
11046 tree *n_elts = XALLOCAVEC (tree, VECTOR_CST_NELTS (arg0));
11047 sparc_handle_vis_mul8x16 (n_elts, code, inner_type, arg0, arg1);
11048 return build_vector (rtype, n_elts);
11050 break;
11052 case SPARC_BUILTIN_FPMERGE:
11053 arg0 = args[0];
11054 arg1 = args[1];
11055 STRIP_NOPS (arg0);
11056 STRIP_NOPS (arg1);
11058 if (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST)
11060 tree *n_elts = XALLOCAVEC (tree, 2 * VECTOR_CST_NELTS (arg0));
11061 unsigned i;
11062 for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
11064 n_elts[2*i] = VECTOR_CST_ELT (arg0, i);
11065 n_elts[2*i+1] = VECTOR_CST_ELT (arg1, i);
11068 return build_vector (rtype, n_elts);
11070 break;
11072 case SPARC_BUILTIN_PDIST:
11073 case SPARC_BUILTIN_PDISTN:
11074 arg0 = args[0];
11075 arg1 = args[1];
11076 STRIP_NOPS (arg0);
11077 STRIP_NOPS (arg1);
11078 if (code == SPARC_BUILTIN_PDIST)
11080 arg2 = args[2];
11081 STRIP_NOPS (arg2);
11083 else
11084 arg2 = integer_zero_node;
11086 if (TREE_CODE (arg0) == VECTOR_CST
11087 && TREE_CODE (arg1) == VECTOR_CST
11088 && TREE_CODE (arg2) == INTEGER_CST)
11090 bool overflow = false;
11091 widest_int result = wi::to_widest (arg2);
11092 widest_int tmp;
11093 unsigned i;
11095 for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
11097 tree e0 = VECTOR_CST_ELT (arg0, i);
11098 tree e1 = VECTOR_CST_ELT (arg1, i);
11100 bool neg1_ovf, neg2_ovf, add1_ovf, add2_ovf;
11102 tmp = wi::neg (wi::to_widest (e1), &neg1_ovf);
11103 tmp = wi::add (wi::to_widest (e0), tmp, SIGNED, &add1_ovf);
11104 if (wi::neg_p (tmp))
11105 tmp = wi::neg (tmp, &neg2_ovf);
11106 else
11107 neg2_ovf = false;
11108 result = wi::add (result, tmp, SIGNED, &add2_ovf);
11109 overflow |= neg1_ovf | neg2_ovf | add1_ovf | add2_ovf;
11112 gcc_assert (!overflow);
11114 return wide_int_to_tree (rtype, result);
11117 default:
11118 break;
11121 return NULL_TREE;
11124 /* ??? This duplicates information provided to the compiler by the
11125 ??? scheduler description. Some day, teach genautomata to output
11126 ??? the latencies and then CSE will just use that. */
11128 static bool
11129 sparc_rtx_costs (rtx x, machine_mode mode, int outer_code,
11130 int opno ATTRIBUTE_UNUSED,
11131 int *total, bool speed ATTRIBUTE_UNUSED)
11133 int code = GET_CODE (x);
11134 bool float_mode_p = FLOAT_MODE_P (mode);
11136 switch (code)
11138 case CONST_INT:
11139 if (SMALL_INT (x))
11140 *total = 0;
11141 else
11142 *total = 2;
11143 return true;
11145 case CONST_WIDE_INT:
11146 *total = 0;
11147 if (!SPARC_SIMM13_P (CONST_WIDE_INT_ELT (x, 0)))
11148 *total += 2;
11149 if (!SPARC_SIMM13_P (CONST_WIDE_INT_ELT (x, 1)))
11150 *total += 2;
11151 return true;
11153 case HIGH:
11154 *total = 2;
11155 return true;
11157 case CONST:
11158 case LABEL_REF:
11159 case SYMBOL_REF:
11160 *total = 4;
11161 return true;
11163 case CONST_DOUBLE:
11164 *total = 8;
11165 return true;
11167 case MEM:
11168 /* If outer-code was a sign or zero extension, a cost
11169 of COSTS_N_INSNS (1) was already added in. This is
11170 why we are subtracting it back out. */
11171 if (outer_code == ZERO_EXTEND)
11173 *total = sparc_costs->int_zload - COSTS_N_INSNS (1);
11175 else if (outer_code == SIGN_EXTEND)
11177 *total = sparc_costs->int_sload - COSTS_N_INSNS (1);
11179 else if (float_mode_p)
11181 *total = sparc_costs->float_load;
11183 else
11185 *total = sparc_costs->int_load;
11188 return true;
11190 case PLUS:
11191 case MINUS:
11192 if (float_mode_p)
11193 *total = sparc_costs->float_plusminus;
11194 else
11195 *total = COSTS_N_INSNS (1);
11196 return false;
11198 case FMA:
11200 rtx sub;
11202 gcc_assert (float_mode_p);
11203 *total = sparc_costs->float_mul;
11205 sub = XEXP (x, 0);
11206 if (GET_CODE (sub) == NEG)
11207 sub = XEXP (sub, 0);
11208 *total += rtx_cost (sub, mode, FMA, 0, speed);
11210 sub = XEXP (x, 2);
11211 if (GET_CODE (sub) == NEG)
11212 sub = XEXP (sub, 0);
11213 *total += rtx_cost (sub, mode, FMA, 2, speed);
11214 return true;
11217 case MULT:
11218 if (float_mode_p)
11219 *total = sparc_costs->float_mul;
11220 else if (TARGET_ARCH32 && !TARGET_HARD_MUL)
11221 *total = COSTS_N_INSNS (25);
11222 else
11224 int bit_cost;
11226 bit_cost = 0;
11227 if (sparc_costs->int_mul_bit_factor)
11229 int nbits;
11231 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
11233 unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
11234 for (nbits = 0; value != 0; value &= value - 1)
11235 nbits++;
11237 else
11238 nbits = 7;
11240 if (nbits < 3)
11241 nbits = 3;
11242 bit_cost = (nbits - 3) / sparc_costs->int_mul_bit_factor;
11243 bit_cost = COSTS_N_INSNS (bit_cost);
11246 if (mode == DImode || !TARGET_HARD_MUL)
11247 *total = sparc_costs->int_mulX + bit_cost;
11248 else
11249 *total = sparc_costs->int_mul + bit_cost;
11251 return false;
11253 case ASHIFT:
11254 case ASHIFTRT:
11255 case LSHIFTRT:
11256 *total = COSTS_N_INSNS (1) + sparc_costs->shift_penalty;
11257 return false;
11259 case DIV:
11260 case UDIV:
11261 case MOD:
11262 case UMOD:
11263 if (float_mode_p)
11265 if (mode == DFmode)
11266 *total = sparc_costs->float_div_df;
11267 else
11268 *total = sparc_costs->float_div_sf;
11270 else
11272 if (mode == DImode)
11273 *total = sparc_costs->int_divX;
11274 else
11275 *total = sparc_costs->int_div;
11277 return false;
11279 case NEG:
11280 if (! float_mode_p)
11282 *total = COSTS_N_INSNS (1);
11283 return false;
11285 /* FALLTHRU */
11287 case ABS:
11288 case FLOAT:
11289 case UNSIGNED_FLOAT:
11290 case FIX:
11291 case UNSIGNED_FIX:
11292 case FLOAT_EXTEND:
11293 case FLOAT_TRUNCATE:
11294 *total = sparc_costs->float_move;
11295 return false;
11297 case SQRT:
11298 if (mode == DFmode)
11299 *total = sparc_costs->float_sqrt_df;
11300 else
11301 *total = sparc_costs->float_sqrt_sf;
11302 return false;
11304 case COMPARE:
11305 if (float_mode_p)
11306 *total = sparc_costs->float_cmp;
11307 else
11308 *total = COSTS_N_INSNS (1);
11309 return false;
11311 case IF_THEN_ELSE:
11312 if (float_mode_p)
11313 *total = sparc_costs->float_cmove;
11314 else
11315 *total = sparc_costs->int_cmove;
11316 return false;
11318 case IOR:
11319 /* Handle the NAND vector patterns. */
11320 if (sparc_vector_mode_supported_p (mode)
11321 && GET_CODE (XEXP (x, 0)) == NOT
11322 && GET_CODE (XEXP (x, 1)) == NOT)
11324 *total = COSTS_N_INSNS (1);
11325 return true;
11327 else
11328 return false;
11330 default:
11331 return false;
11335 /* Return true if CLASS is either GENERAL_REGS or I64_REGS. */
11337 static inline bool
11338 general_or_i64_p (reg_class_t rclass)
11340 return (rclass == GENERAL_REGS || rclass == I64_REGS);
11343 /* Implement TARGET_REGISTER_MOVE_COST. */
11345 static int
11346 sparc_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
11347 reg_class_t from, reg_class_t to)
11349 bool need_memory = false;
11351 /* This helps postreload CSE to eliminate redundant comparisons. */
11352 if (from == NO_REGS || to == NO_REGS)
11353 return 100;
11355 if (from == FPCC_REGS || to == FPCC_REGS)
11356 need_memory = true;
11357 else if ((FP_REG_CLASS_P (from) && general_or_i64_p (to))
11358 || (general_or_i64_p (from) && FP_REG_CLASS_P (to)))
11360 if (TARGET_VIS3)
11362 int size = GET_MODE_SIZE (mode);
11363 if (size == 8 || size == 4)
11365 if (! TARGET_ARCH32 || size == 4)
11366 return 4;
11367 else
11368 return 6;
11371 need_memory = true;
11374 if (need_memory)
11376 if (sparc_cpu == PROCESSOR_ULTRASPARC
11377 || sparc_cpu == PROCESSOR_ULTRASPARC3
11378 || sparc_cpu == PROCESSOR_NIAGARA
11379 || sparc_cpu == PROCESSOR_NIAGARA2
11380 || sparc_cpu == PROCESSOR_NIAGARA3
11381 || sparc_cpu == PROCESSOR_NIAGARA4
11382 || sparc_cpu == PROCESSOR_NIAGARA7)
11383 return 12;
11385 return 6;
11388 return 2;
11391 /* Emit the sequence of insns SEQ while preserving the registers REG and REG2.
11392 This is achieved by means of a manual dynamic stack space allocation in
11393 the current frame. We make the assumption that SEQ doesn't contain any
11394 function calls, with the possible exception of calls to the GOT helper. */
11396 static void
11397 emit_and_preserve (rtx seq, rtx reg, rtx reg2)
11399 /* We must preserve the lowest 16 words for the register save area. */
11400 HOST_WIDE_INT offset = 16*UNITS_PER_WORD;
11401 /* We really need only 2 words of fresh stack space. */
11402 HOST_WIDE_INT size = SPARC_STACK_ALIGN (offset + 2*UNITS_PER_WORD);
11404 rtx slot
11405 = gen_rtx_MEM (word_mode, plus_constant (Pmode, stack_pointer_rtx,
11406 SPARC_STACK_BIAS + offset));
11408 emit_insn (gen_stack_pointer_inc (GEN_INT (-size)));
11409 emit_insn (gen_rtx_SET (slot, reg));
11410 if (reg2)
11411 emit_insn (gen_rtx_SET (adjust_address (slot, word_mode, UNITS_PER_WORD),
11412 reg2));
11413 emit_insn (seq);
11414 if (reg2)
11415 emit_insn (gen_rtx_SET (reg2,
11416 adjust_address (slot, word_mode, UNITS_PER_WORD)));
11417 emit_insn (gen_rtx_SET (reg, slot));
11418 emit_insn (gen_stack_pointer_inc (GEN_INT (size)));
11421 /* Output the assembler code for a thunk function. THUNK_DECL is the
11422 declaration for the thunk function itself, FUNCTION is the decl for
11423 the target function. DELTA is an immediate constant offset to be
11424 added to THIS. If VCALL_OFFSET is nonzero, the word at address
11425 (*THIS + VCALL_OFFSET) should be additionally added to THIS. */
11427 static void
11428 sparc_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
11429 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
11430 tree function)
11432 rtx this_rtx, funexp;
11433 rtx_insn *insn;
11434 unsigned int int_arg_first;
11436 reload_completed = 1;
11437 epilogue_completed = 1;
11439 emit_note (NOTE_INSN_PROLOGUE_END);
11441 if (TARGET_FLAT)
11443 sparc_leaf_function_p = 1;
11445 int_arg_first = SPARC_OUTGOING_INT_ARG_FIRST;
11447 else if (flag_delayed_branch)
11449 /* We will emit a regular sibcall below, so we need to instruct
11450 output_sibcall that we are in a leaf function. */
11451 sparc_leaf_function_p = crtl->uses_only_leaf_regs = 1;
11453 /* This will cause final.c to invoke leaf_renumber_regs so we
11454 must behave as if we were in a not-yet-leafified function. */
11455 int_arg_first = SPARC_INCOMING_INT_ARG_FIRST;
11457 else
11459 /* We will emit the sibcall manually below, so we will need to
11460 manually spill non-leaf registers. */
11461 sparc_leaf_function_p = crtl->uses_only_leaf_regs = 0;
11463 /* We really are in a leaf function. */
11464 int_arg_first = SPARC_OUTGOING_INT_ARG_FIRST;
11467 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
11468 returns a structure, the structure return pointer is there instead. */
11469 if (TARGET_ARCH64
11470 && aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
11471 this_rtx = gen_rtx_REG (Pmode, int_arg_first + 1);
11472 else
11473 this_rtx = gen_rtx_REG (Pmode, int_arg_first);
11475 /* Add DELTA. When possible use a plain add, otherwise load it into
11476 a register first. */
11477 if (delta)
11479 rtx delta_rtx = GEN_INT (delta);
11481 if (! SPARC_SIMM13_P (delta))
11483 rtx scratch = gen_rtx_REG (Pmode, 1);
11484 emit_move_insn (scratch, delta_rtx);
11485 delta_rtx = scratch;
11488 /* THIS_RTX += DELTA. */
11489 emit_insn (gen_add2_insn (this_rtx, delta_rtx));
11492 /* Add the word at address (*THIS_RTX + VCALL_OFFSET). */
11493 if (vcall_offset)
11495 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
11496 rtx scratch = gen_rtx_REG (Pmode, 1);
11498 gcc_assert (vcall_offset < 0);
11500 /* SCRATCH = *THIS_RTX. */
11501 emit_move_insn (scratch, gen_rtx_MEM (Pmode, this_rtx));
11503 /* Prepare for adding VCALL_OFFSET. The difficulty is that we
11504 may not have any available scratch register at this point. */
11505 if (SPARC_SIMM13_P (vcall_offset))
11507 /* This is the case if ARCH64 (unless -ffixed-g5 is passed). */
11508 else if (! fixed_regs[5]
11509 /* The below sequence is made up of at least 2 insns,
11510 while the default method may need only one. */
11511 && vcall_offset < -8192)
11513 rtx scratch2 = gen_rtx_REG (Pmode, 5);
11514 emit_move_insn (scratch2, vcall_offset_rtx);
11515 vcall_offset_rtx = scratch2;
11517 else
11519 rtx increment = GEN_INT (-4096);
11521 /* VCALL_OFFSET is a negative number whose typical range can be
11522 estimated as -32768..0 in 32-bit mode. In almost all cases
11523 it is therefore cheaper to emit multiple add insns than
11524 spilling and loading the constant into a register (at least
11525 6 insns). */
11526 while (! SPARC_SIMM13_P (vcall_offset))
11528 emit_insn (gen_add2_insn (scratch, increment));
11529 vcall_offset += 4096;
11531 vcall_offset_rtx = GEN_INT (vcall_offset); /* cannot be 0 */
11534 /* SCRATCH = *(*THIS_RTX + VCALL_OFFSET). */
11535 emit_move_insn (scratch, gen_rtx_MEM (Pmode,
11536 gen_rtx_PLUS (Pmode,
11537 scratch,
11538 vcall_offset_rtx)));
11540 /* THIS_RTX += *(*THIS_RTX + VCALL_OFFSET). */
11541 emit_insn (gen_add2_insn (this_rtx, scratch));
11544 /* Generate a tail call to the target function. */
11545 if (! TREE_USED (function))
11547 assemble_external (function);
11548 TREE_USED (function) = 1;
11550 funexp = XEXP (DECL_RTL (function), 0);
11552 if (flag_delayed_branch)
11554 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
11555 insn = emit_call_insn (gen_sibcall (funexp));
11556 SIBLING_CALL_P (insn) = 1;
11558 else
11560 /* The hoops we have to jump through in order to generate a sibcall
11561 without using delay slots... */
11562 rtx spill_reg, seq, scratch = gen_rtx_REG (Pmode, 1);
11564 if (flag_pic)
11566 spill_reg = gen_rtx_REG (word_mode, 15); /* %o7 */
11567 start_sequence ();
11568 load_got_register (); /* clobbers %o7 */
11569 scratch = sparc_legitimize_pic_address (funexp, scratch);
11570 seq = get_insns ();
11571 end_sequence ();
11572 emit_and_preserve (seq, spill_reg, pic_offset_table_rtx);
11574 else if (TARGET_ARCH32)
11576 emit_insn (gen_rtx_SET (scratch,
11577 gen_rtx_HIGH (SImode, funexp)));
11578 emit_insn (gen_rtx_SET (scratch,
11579 gen_rtx_LO_SUM (SImode, scratch, funexp)));
11581 else /* TARGET_ARCH64 */
11583 switch (sparc_cmodel)
11585 case CM_MEDLOW:
11586 case CM_MEDMID:
11587 /* The destination can serve as a temporary. */
11588 sparc_emit_set_symbolic_const64 (scratch, funexp, scratch);
11589 break;
11591 case CM_MEDANY:
11592 case CM_EMBMEDANY:
11593 /* The destination cannot serve as a temporary. */
11594 spill_reg = gen_rtx_REG (DImode, 15); /* %o7 */
11595 start_sequence ();
11596 sparc_emit_set_symbolic_const64 (scratch, funexp, spill_reg);
11597 seq = get_insns ();
11598 end_sequence ();
11599 emit_and_preserve (seq, spill_reg, 0);
11600 break;
11602 default:
11603 gcc_unreachable ();
11607 emit_jump_insn (gen_indirect_jump (scratch));
11610 emit_barrier ();
11612 /* Run just enough of rest_of_compilation to get the insns emitted.
11613 There's not really enough bulk here to make other passes such as
11614 instruction scheduling worth while. Note that use_thunk calls
11615 assemble_start_function and assemble_end_function. */
11616 insn = get_insns ();
11617 shorten_branches (insn);
11618 final_start_function (insn, file, 1);
11619 final (insn, file, 1);
11620 final_end_function ();
11622 reload_completed = 0;
11623 epilogue_completed = 0;
11626 /* Return true if sparc_output_mi_thunk would be able to output the
11627 assembler code for the thunk function specified by the arguments
11628 it is passed, and false otherwise. */
11629 static bool
11630 sparc_can_output_mi_thunk (const_tree thunk_fndecl ATTRIBUTE_UNUSED,
11631 HOST_WIDE_INT delta ATTRIBUTE_UNUSED,
11632 HOST_WIDE_INT vcall_offset,
11633 const_tree function ATTRIBUTE_UNUSED)
11635 /* Bound the loop used in the default method above. */
11636 return (vcall_offset >= -32768 || ! fixed_regs[5]);
11639 /* How to allocate a 'struct machine_function'. */
11641 static struct machine_function *
11642 sparc_init_machine_status (void)
11644 return ggc_cleared_alloc<machine_function> ();
11647 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
11648 We need to emit DTP-relative relocations. */
11650 static void
11651 sparc_output_dwarf_dtprel (FILE *file, int size, rtx x)
11653 switch (size)
11655 case 4:
11656 fputs ("\t.word\t%r_tls_dtpoff32(", file);
11657 break;
11658 case 8:
11659 fputs ("\t.xword\t%r_tls_dtpoff64(", file);
11660 break;
11661 default:
11662 gcc_unreachable ();
11664 output_addr_const (file, x);
11665 fputs (")", file);
11668 /* Do whatever processing is required at the end of a file. */
11670 static void
11671 sparc_file_end (void)
11673 /* If we need to emit the special GOT helper function, do so now. */
11674 if (got_helper_rtx)
11676 const char *name = XSTR (got_helper_rtx, 0);
11677 const char *reg_name = reg_names[GLOBAL_OFFSET_TABLE_REGNUM];
11678 #ifdef DWARF2_UNWIND_INFO
11679 bool do_cfi;
11680 #endif
11682 if (USE_HIDDEN_LINKONCE)
11684 tree decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
11685 get_identifier (name),
11686 build_function_type_list (void_type_node,
11687 NULL_TREE));
11688 DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
11689 NULL_TREE, void_type_node);
11690 TREE_PUBLIC (decl) = 1;
11691 TREE_STATIC (decl) = 1;
11692 make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
11693 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
11694 DECL_VISIBILITY_SPECIFIED (decl) = 1;
11695 resolve_unique_section (decl, 0, flag_function_sections);
11696 allocate_struct_function (decl, true);
11697 cfun->is_thunk = 1;
11698 current_function_decl = decl;
11699 init_varasm_status ();
11700 assemble_start_function (decl, name);
11702 else
11704 const int align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
11705 switch_to_section (text_section);
11706 if (align > 0)
11707 ASM_OUTPUT_ALIGN (asm_out_file, align);
11708 ASM_OUTPUT_LABEL (asm_out_file, name);
11711 #ifdef DWARF2_UNWIND_INFO
11712 do_cfi = dwarf2out_do_cfi_asm ();
11713 if (do_cfi)
11714 fprintf (asm_out_file, "\t.cfi_startproc\n");
11715 #endif
11716 if (flag_delayed_branch)
11717 fprintf (asm_out_file, "\tjmp\t%%o7+8\n\t add\t%%o7, %s, %s\n",
11718 reg_name, reg_name);
11719 else
11720 fprintf (asm_out_file, "\tadd\t%%o7, %s, %s\n\tjmp\t%%o7+8\n\t nop\n",
11721 reg_name, reg_name);
11722 #ifdef DWARF2_UNWIND_INFO
11723 if (do_cfi)
11724 fprintf (asm_out_file, "\t.cfi_endproc\n");
11725 #endif
11728 if (NEED_INDICATE_EXEC_STACK)
11729 file_end_indicate_exec_stack ();
11731 #ifdef TARGET_SOLARIS
11732 solaris_file_end ();
11733 #endif
11736 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
11737 /* Implement TARGET_MANGLE_TYPE. */
11739 static const char *
11740 sparc_mangle_type (const_tree type)
11742 if (TARGET_ARCH32
11743 && TYPE_MAIN_VARIANT (type) == long_double_type_node
11744 && TARGET_LONG_DOUBLE_128)
11745 return "g";
11747 /* For all other types, use normal C++ mangling. */
11748 return NULL;
11750 #endif
11752 /* Expand a membar instruction for various use cases. Both the LOAD_STORE
11753 and BEFORE_AFTER arguments of the form X_Y. They are two-bit masks where
11754 bit 0 indicates that X is true, and bit 1 indicates Y is true. */
11756 void
11757 sparc_emit_membar_for_model (enum memmodel model,
11758 int load_store, int before_after)
11760 /* Bits for the MEMBAR mmask field. */
11761 const int LoadLoad = 1;
11762 const int StoreLoad = 2;
11763 const int LoadStore = 4;
11764 const int StoreStore = 8;
11766 int mm = 0, implied = 0;
11768 switch (sparc_memory_model)
11770 case SMM_SC:
11771 /* Sequential Consistency. All memory transactions are immediately
11772 visible in sequential execution order. No barriers needed. */
11773 implied = LoadLoad | StoreLoad | LoadStore | StoreStore;
11774 break;
11776 case SMM_TSO:
11777 /* Total Store Ordering: all memory transactions with store semantics
11778 are followed by an implied StoreStore. */
11779 implied |= StoreStore;
11781 /* If we're not looking for a raw barrer (before+after), then atomic
11782 operations get the benefit of being both load and store. */
11783 if (load_store == 3 && before_after == 1)
11784 implied |= StoreLoad;
11785 /* FALLTHRU */
11787 case SMM_PSO:
11788 /* Partial Store Ordering: all memory transactions with load semantics
11789 are followed by an implied LoadLoad | LoadStore. */
11790 implied |= LoadLoad | LoadStore;
11792 /* If we're not looking for a raw barrer (before+after), then atomic
11793 operations get the benefit of being both load and store. */
11794 if (load_store == 3 && before_after == 2)
11795 implied |= StoreLoad | StoreStore;
11796 /* FALLTHRU */
11798 case SMM_RMO:
11799 /* Relaxed Memory Ordering: no implicit bits. */
11800 break;
11802 default:
11803 gcc_unreachable ();
11806 if (before_after & 1)
11808 if (is_mm_release (model) || is_mm_acq_rel (model)
11809 || is_mm_seq_cst (model))
11811 if (load_store & 1)
11812 mm |= LoadLoad | StoreLoad;
11813 if (load_store & 2)
11814 mm |= LoadStore | StoreStore;
11817 if (before_after & 2)
11819 if (is_mm_acquire (model) || is_mm_acq_rel (model)
11820 || is_mm_seq_cst (model))
11822 if (load_store & 1)
11823 mm |= LoadLoad | LoadStore;
11824 if (load_store & 2)
11825 mm |= StoreLoad | StoreStore;
11829 /* Remove the bits implied by the system memory model. */
11830 mm &= ~implied;
11832 /* For raw barriers (before+after), always emit a barrier.
11833 This will become a compile-time barrier if needed. */
11834 if (mm || before_after == 3)
11835 emit_insn (gen_membar (GEN_INT (mm)));
11838 /* Expand code to perform a 8 or 16-bit compare and swap by doing 32-bit
11839 compare and swap on the word containing the byte or half-word. */
11841 static void
11842 sparc_expand_compare_and_swap_12 (rtx bool_result, rtx result, rtx mem,
11843 rtx oldval, rtx newval)
11845 rtx addr1 = force_reg (Pmode, XEXP (mem, 0));
11846 rtx addr = gen_reg_rtx (Pmode);
11847 rtx off = gen_reg_rtx (SImode);
11848 rtx oldv = gen_reg_rtx (SImode);
11849 rtx newv = gen_reg_rtx (SImode);
11850 rtx oldvalue = gen_reg_rtx (SImode);
11851 rtx newvalue = gen_reg_rtx (SImode);
11852 rtx res = gen_reg_rtx (SImode);
11853 rtx resv = gen_reg_rtx (SImode);
11854 rtx memsi, val, mask, cc;
11856 emit_insn (gen_rtx_SET (addr, gen_rtx_AND (Pmode, addr1, GEN_INT (-4))));
11858 if (Pmode != SImode)
11859 addr1 = gen_lowpart (SImode, addr1);
11860 emit_insn (gen_rtx_SET (off, gen_rtx_AND (SImode, addr1, GEN_INT (3))));
11862 memsi = gen_rtx_MEM (SImode, addr);
11863 set_mem_alias_set (memsi, ALIAS_SET_MEMORY_BARRIER);
11864 MEM_VOLATILE_P (memsi) = MEM_VOLATILE_P (mem);
11866 val = copy_to_reg (memsi);
11868 emit_insn (gen_rtx_SET (off,
11869 gen_rtx_XOR (SImode, off,
11870 GEN_INT (GET_MODE (mem) == QImode
11871 ? 3 : 2))));
11873 emit_insn (gen_rtx_SET (off, gen_rtx_ASHIFT (SImode, off, GEN_INT (3))));
11875 if (GET_MODE (mem) == QImode)
11876 mask = force_reg (SImode, GEN_INT (0xff));
11877 else
11878 mask = force_reg (SImode, GEN_INT (0xffff));
11880 emit_insn (gen_rtx_SET (mask, gen_rtx_ASHIFT (SImode, mask, off)));
11882 emit_insn (gen_rtx_SET (val,
11883 gen_rtx_AND (SImode, gen_rtx_NOT (SImode, mask),
11884 val)));
11886 oldval = gen_lowpart (SImode, oldval);
11887 emit_insn (gen_rtx_SET (oldv, gen_rtx_ASHIFT (SImode, oldval, off)));
11889 newval = gen_lowpart_common (SImode, newval);
11890 emit_insn (gen_rtx_SET (newv, gen_rtx_ASHIFT (SImode, newval, off)));
11892 emit_insn (gen_rtx_SET (oldv, gen_rtx_AND (SImode, oldv, mask)));
11894 emit_insn (gen_rtx_SET (newv, gen_rtx_AND (SImode, newv, mask)));
11896 rtx_code_label *end_label = gen_label_rtx ();
11897 rtx_code_label *loop_label = gen_label_rtx ();
11898 emit_label (loop_label);
11900 emit_insn (gen_rtx_SET (oldvalue, gen_rtx_IOR (SImode, oldv, val)));
11902 emit_insn (gen_rtx_SET (newvalue, gen_rtx_IOR (SImode, newv, val)));
11904 emit_move_insn (bool_result, const1_rtx);
11906 emit_insn (gen_atomic_compare_and_swapsi_1 (res, memsi, oldvalue, newvalue));
11908 emit_cmp_and_jump_insns (res, oldvalue, EQ, NULL, SImode, 0, end_label);
11910 emit_insn (gen_rtx_SET (resv,
11911 gen_rtx_AND (SImode, gen_rtx_NOT (SImode, mask),
11912 res)));
11914 emit_move_insn (bool_result, const0_rtx);
11916 cc = gen_compare_reg_1 (NE, resv, val);
11917 emit_insn (gen_rtx_SET (val, resv));
11919 /* Use cbranchcc4 to separate the compare and branch! */
11920 emit_jump_insn (gen_cbranchcc4 (gen_rtx_NE (VOIDmode, cc, const0_rtx),
11921 cc, const0_rtx, loop_label));
11923 emit_label (end_label);
11925 emit_insn (gen_rtx_SET (res, gen_rtx_AND (SImode, res, mask)));
11927 emit_insn (gen_rtx_SET (res, gen_rtx_LSHIFTRT (SImode, res, off)));
11929 emit_move_insn (result, gen_lowpart (GET_MODE (result), res));
11932 /* Expand code to perform a compare-and-swap. */
11934 void
11935 sparc_expand_compare_and_swap (rtx operands[])
11937 rtx bval, retval, mem, oldval, newval;
11938 machine_mode mode;
11939 enum memmodel model;
11941 bval = operands[0];
11942 retval = operands[1];
11943 mem = operands[2];
11944 oldval = operands[3];
11945 newval = operands[4];
11946 model = (enum memmodel) INTVAL (operands[6]);
11947 mode = GET_MODE (mem);
11949 sparc_emit_membar_for_model (model, 3, 1);
11951 if (reg_overlap_mentioned_p (retval, oldval))
11952 oldval = copy_to_reg (oldval);
11954 if (mode == QImode || mode == HImode)
11955 sparc_expand_compare_and_swap_12 (bval, retval, mem, oldval, newval);
11956 else
11958 rtx (*gen) (rtx, rtx, rtx, rtx);
11959 rtx x;
11961 if (mode == SImode)
11962 gen = gen_atomic_compare_and_swapsi_1;
11963 else
11964 gen = gen_atomic_compare_and_swapdi_1;
11965 emit_insn (gen (retval, mem, oldval, newval));
11967 x = emit_store_flag (bval, EQ, retval, oldval, mode, 1, 1);
11968 if (x != bval)
11969 convert_move (bval, x, 1);
11972 sparc_emit_membar_for_model (model, 3, 2);
11975 void
11976 sparc_expand_vec_perm_bmask (machine_mode vmode, rtx sel)
11978 rtx t_1, t_2, t_3;
11980 sel = gen_lowpart (DImode, sel);
11981 switch (vmode)
11983 case V2SImode:
11984 /* inp = xxxxxxxAxxxxxxxB */
11985 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (16),
11986 NULL_RTX, 1, OPTAB_DIRECT);
11987 /* t_1 = ....xxxxxxxAxxx. */
11988 sel = expand_simple_binop (SImode, AND, gen_lowpart (SImode, sel),
11989 GEN_INT (3), NULL_RTX, 1, OPTAB_DIRECT);
11990 t_1 = expand_simple_binop (SImode, AND, gen_lowpart (SImode, t_1),
11991 GEN_INT (0x30000), NULL_RTX, 1, OPTAB_DIRECT);
11992 /* sel = .......B */
11993 /* t_1 = ...A.... */
11994 sel = expand_simple_binop (SImode, IOR, sel, t_1, sel, 1, OPTAB_DIRECT);
11995 /* sel = ...A...B */
11996 sel = expand_mult (SImode, sel, GEN_INT (0x4444), sel, 1);
11997 /* sel = AAAABBBB * 4 */
11998 t_1 = force_reg (SImode, GEN_INT (0x01230123));
11999 /* sel = { A*4, A*4+1, A*4+2, ... } */
12000 break;
12002 case V4HImode:
12003 /* inp = xxxAxxxBxxxCxxxD */
12004 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (8),
12005 NULL_RTX, 1, OPTAB_DIRECT);
12006 t_2 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (16),
12007 NULL_RTX, 1, OPTAB_DIRECT);
12008 t_3 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (24),
12009 NULL_RTX, 1, OPTAB_DIRECT);
12010 /* t_1 = ..xxxAxxxBxxxCxx */
12011 /* t_2 = ....xxxAxxxBxxxC */
12012 /* t_3 = ......xxxAxxxBxx */
12013 sel = expand_simple_binop (SImode, AND, gen_lowpart (SImode, sel),
12014 GEN_INT (0x07),
12015 NULL_RTX, 1, OPTAB_DIRECT);
12016 t_1 = expand_simple_binop (SImode, AND, gen_lowpart (SImode, t_1),
12017 GEN_INT (0x0700),
12018 NULL_RTX, 1, OPTAB_DIRECT);
12019 t_2 = expand_simple_binop (SImode, AND, gen_lowpart (SImode, t_2),
12020 GEN_INT (0x070000),
12021 NULL_RTX, 1, OPTAB_DIRECT);
12022 t_3 = expand_simple_binop (SImode, AND, gen_lowpart (SImode, t_3),
12023 GEN_INT (0x07000000),
12024 NULL_RTX, 1, OPTAB_DIRECT);
12025 /* sel = .......D */
12026 /* t_1 = .....C.. */
12027 /* t_2 = ...B.... */
12028 /* t_3 = .A...... */
12029 sel = expand_simple_binop (SImode, IOR, sel, t_1, sel, 1, OPTAB_DIRECT);
12030 t_2 = expand_simple_binop (SImode, IOR, t_2, t_3, t_2, 1, OPTAB_DIRECT);
12031 sel = expand_simple_binop (SImode, IOR, sel, t_2, sel, 1, OPTAB_DIRECT);
12032 /* sel = .A.B.C.D */
12033 sel = expand_mult (SImode, sel, GEN_INT (0x22), sel, 1);
12034 /* sel = AABBCCDD * 2 */
12035 t_1 = force_reg (SImode, GEN_INT (0x01010101));
12036 /* sel = { A*2, A*2+1, B*2, B*2+1, ... } */
12037 break;
12039 case V8QImode:
12040 /* input = xAxBxCxDxExFxGxH */
12041 sel = expand_simple_binop (DImode, AND, sel,
12042 GEN_INT ((HOST_WIDE_INT)0x0f0f0f0f << 32
12043 | 0x0f0f0f0f),
12044 NULL_RTX, 1, OPTAB_DIRECT);
12045 /* sel = .A.B.C.D.E.F.G.H */
12046 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (4),
12047 NULL_RTX, 1, OPTAB_DIRECT);
12048 /* t_1 = ..A.B.C.D.E.F.G. */
12049 sel = expand_simple_binop (DImode, IOR, sel, t_1,
12050 NULL_RTX, 1, OPTAB_DIRECT);
12051 /* sel = .AABBCCDDEEFFGGH */
12052 sel = expand_simple_binop (DImode, AND, sel,
12053 GEN_INT ((HOST_WIDE_INT)0xff00ff << 32
12054 | 0xff00ff),
12055 NULL_RTX, 1, OPTAB_DIRECT);
12056 /* sel = ..AB..CD..EF..GH */
12057 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (8),
12058 NULL_RTX, 1, OPTAB_DIRECT);
12059 /* t_1 = ....AB..CD..EF.. */
12060 sel = expand_simple_binop (DImode, IOR, sel, t_1,
12061 NULL_RTX, 1, OPTAB_DIRECT);
12062 /* sel = ..ABABCDCDEFEFGH */
12063 sel = expand_simple_binop (DImode, AND, sel,
12064 GEN_INT ((HOST_WIDE_INT)0xffff << 32 | 0xffff),
12065 NULL_RTX, 1, OPTAB_DIRECT);
12066 /* sel = ....ABCD....EFGH */
12067 t_1 = expand_simple_binop (DImode, LSHIFTRT, sel, GEN_INT (16),
12068 NULL_RTX, 1, OPTAB_DIRECT);
12069 /* t_1 = ........ABCD.... */
12070 sel = gen_lowpart (SImode, sel);
12071 t_1 = gen_lowpart (SImode, t_1);
12072 break;
12074 default:
12075 gcc_unreachable ();
12078 /* Always perform the final addition/merge within the bmask insn. */
12079 emit_insn (gen_bmasksi_vis (gen_reg_rtx (SImode), sel, t_1));
12082 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
12084 static bool
12085 sparc_frame_pointer_required (void)
12087 /* If the stack pointer is dynamically modified in the function, it cannot
12088 serve as the frame pointer. */
12089 if (cfun->calls_alloca)
12090 return true;
12092 /* If the function receives nonlocal gotos, it needs to save the frame
12093 pointer in the nonlocal_goto_save_area object. */
12094 if (cfun->has_nonlocal_label)
12095 return true;
12097 /* In flat mode, that's it. */
12098 if (TARGET_FLAT)
12099 return false;
12101 /* Otherwise, the frame pointer is required if the function isn't leaf. */
12102 return !(crtl->is_leaf && only_leaf_regs_used ());
12105 /* The way this is structured, we can't eliminate SFP in favor of SP
12106 if the frame pointer is required: we want to use the SFP->HFP elimination
12107 in that case. But the test in update_eliminables doesn't know we are
12108 assuming below that we only do the former elimination. */
12110 static bool
12111 sparc_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
12113 return to == HARD_FRAME_POINTER_REGNUM || !sparc_frame_pointer_required ();
12116 /* Return the hard frame pointer directly to bypass the stack bias. */
12118 static rtx
12119 sparc_builtin_setjmp_frame_value (void)
12121 return hard_frame_pointer_rtx;
12124 /* If !TARGET_FPU, then make the fp registers and fp cc regs fixed so that
12125 they won't be allocated. */
12127 static void
12128 sparc_conditional_register_usage (void)
12130 if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
12132 fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
12133 call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
12135 /* If the user has passed -f{fixed,call-{used,saved}}-g5 */
12136 /* then honor it. */
12137 if (TARGET_ARCH32 && fixed_regs[5])
12138 fixed_regs[5] = 1;
12139 else if (TARGET_ARCH64 && fixed_regs[5] == 2)
12140 fixed_regs[5] = 0;
12141 if (! TARGET_V9)
12143 int regno;
12144 for (regno = SPARC_FIRST_V9_FP_REG;
12145 regno <= SPARC_LAST_V9_FP_REG;
12146 regno++)
12147 fixed_regs[regno] = 1;
12148 /* %fcc0 is used by v8 and v9. */
12149 for (regno = SPARC_FIRST_V9_FCC_REG + 1;
12150 regno <= SPARC_LAST_V9_FCC_REG;
12151 regno++)
12152 fixed_regs[regno] = 1;
12154 if (! TARGET_FPU)
12156 int regno;
12157 for (regno = 32; regno < SPARC_LAST_V9_FCC_REG; regno++)
12158 fixed_regs[regno] = 1;
12160 /* If the user has passed -f{fixed,call-{used,saved}}-g2 */
12161 /* then honor it. Likewise with g3 and g4. */
12162 if (fixed_regs[2] == 2)
12163 fixed_regs[2] = ! TARGET_APP_REGS;
12164 if (fixed_regs[3] == 2)
12165 fixed_regs[3] = ! TARGET_APP_REGS;
12166 if (TARGET_ARCH32 && fixed_regs[4] == 2)
12167 fixed_regs[4] = ! TARGET_APP_REGS;
12168 else if (TARGET_CM_EMBMEDANY)
12169 fixed_regs[4] = 1;
12170 else if (fixed_regs[4] == 2)
12171 fixed_regs[4] = 0;
12172 if (TARGET_FLAT)
12174 int regno;
12175 /* Disable leaf functions. */
12176 memset (sparc_leaf_regs, 0, FIRST_PSEUDO_REGISTER);
12177 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
12178 leaf_reg_remap [regno] = regno;
12180 if (TARGET_VIS)
12181 global_regs[SPARC_GSR_REG] = 1;
12184 /* Implement TARGET_PREFERRED_RELOAD_CLASS:
12186 - We can't load constants into FP registers.
12187 - We can't load FP constants into integer registers when soft-float,
12188 because there is no soft-float pattern with a r/F constraint.
12189 - We can't load FP constants into integer registers for TFmode unless
12190 it is 0.0L, because there is no movtf pattern with a r/F constraint.
12191 - Try and reload integer constants (symbolic or otherwise) back into
12192 registers directly, rather than having them dumped to memory. */
12194 static reg_class_t
12195 sparc_preferred_reload_class (rtx x, reg_class_t rclass)
12197 machine_mode mode = GET_MODE (x);
12198 if (CONSTANT_P (x))
12200 if (FP_REG_CLASS_P (rclass)
12201 || rclass == GENERAL_OR_FP_REGS
12202 || rclass == GENERAL_OR_EXTRA_FP_REGS
12203 || (GET_MODE_CLASS (mode) == MODE_FLOAT && ! TARGET_FPU)
12204 || (mode == TFmode && ! const_zero_operand (x, mode)))
12205 return NO_REGS;
12207 if (GET_MODE_CLASS (mode) == MODE_INT)
12208 return GENERAL_REGS;
12210 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
12212 if (! FP_REG_CLASS_P (rclass)
12213 || !(const_zero_operand (x, mode)
12214 || const_all_ones_operand (x, mode)))
12215 return NO_REGS;
12219 if (TARGET_VIS3
12220 && ! TARGET_ARCH64
12221 && (rclass == EXTRA_FP_REGS
12222 || rclass == GENERAL_OR_EXTRA_FP_REGS))
12224 int regno = true_regnum (x);
12226 if (SPARC_INT_REG_P (regno))
12227 return (rclass == EXTRA_FP_REGS
12228 ? FP_REGS : GENERAL_OR_FP_REGS);
12231 return rclass;
12234 /* Output a wide multiply instruction in V8+ mode. INSN is the instruction,
12235 OPERANDS are its operands and OPCODE is the mnemonic to be used. */
12237 const char *
12238 output_v8plus_mult (rtx_insn *insn, rtx *operands, const char *opcode)
12240 char mulstr[32];
12242 gcc_assert (! TARGET_ARCH64);
12244 if (sparc_check_64 (operands[1], insn) <= 0)
12245 output_asm_insn ("srl\t%L1, 0, %L1", operands);
12246 if (which_alternative == 1)
12247 output_asm_insn ("sllx\t%H1, 32, %H1", operands);
12248 if (GET_CODE (operands[2]) == CONST_INT)
12250 if (which_alternative == 1)
12252 output_asm_insn ("or\t%L1, %H1, %H1", operands);
12253 sprintf (mulstr, "%s\t%%H1, %%2, %%L0", opcode);
12254 output_asm_insn (mulstr, operands);
12255 return "srlx\t%L0, 32, %H0";
12257 else
12259 output_asm_insn ("sllx\t%H1, 32, %3", operands);
12260 output_asm_insn ("or\t%L1, %3, %3", operands);
12261 sprintf (mulstr, "%s\t%%3, %%2, %%3", opcode);
12262 output_asm_insn (mulstr, operands);
12263 output_asm_insn ("srlx\t%3, 32, %H0", operands);
12264 return "mov\t%3, %L0";
12267 else if (rtx_equal_p (operands[1], operands[2]))
12269 if (which_alternative == 1)
12271 output_asm_insn ("or\t%L1, %H1, %H1", operands);
12272 sprintf (mulstr, "%s\t%%H1, %%H1, %%L0", opcode);
12273 output_asm_insn (mulstr, operands);
12274 return "srlx\t%L0, 32, %H0";
12276 else
12278 output_asm_insn ("sllx\t%H1, 32, %3", operands);
12279 output_asm_insn ("or\t%L1, %3, %3", operands);
12280 sprintf (mulstr, "%s\t%%3, %%3, %%3", opcode);
12281 output_asm_insn (mulstr, operands);
12282 output_asm_insn ("srlx\t%3, 32, %H0", operands);
12283 return "mov\t%3, %L0";
12286 if (sparc_check_64 (operands[2], insn) <= 0)
12287 output_asm_insn ("srl\t%L2, 0, %L2", operands);
12288 if (which_alternative == 1)
12290 output_asm_insn ("or\t%L1, %H1, %H1", operands);
12291 output_asm_insn ("sllx\t%H2, 32, %L1", operands);
12292 output_asm_insn ("or\t%L2, %L1, %L1", operands);
12293 sprintf (mulstr, "%s\t%%H1, %%L1, %%L0", opcode);
12294 output_asm_insn (mulstr, operands);
12295 return "srlx\t%L0, 32, %H0";
12297 else
12299 output_asm_insn ("sllx\t%H1, 32, %3", operands);
12300 output_asm_insn ("sllx\t%H2, 32, %4", operands);
12301 output_asm_insn ("or\t%L1, %3, %3", operands);
12302 output_asm_insn ("or\t%L2, %4, %4", operands);
12303 sprintf (mulstr, "%s\t%%3, %%4, %%3", opcode);
12304 output_asm_insn (mulstr, operands);
12305 output_asm_insn ("srlx\t%3, 32, %H0", operands);
12306 return "mov\t%3, %L0";
12310 /* Subroutine of sparc_expand_vector_init. Emit code to initialize
12311 all fields of TARGET to ELT by means of VIS2 BSHUFFLE insn. MODE
12312 and INNER_MODE are the modes describing TARGET. */
12314 static void
12315 vector_init_bshuffle (rtx target, rtx elt, machine_mode mode,
12316 machine_mode inner_mode)
12318 rtx t1, final_insn, sel;
12319 int bmask;
12321 t1 = gen_reg_rtx (mode);
12323 elt = convert_modes (SImode, inner_mode, elt, true);
12324 emit_move_insn (gen_lowpart(SImode, t1), elt);
12326 switch (mode)
12328 case V2SImode:
12329 final_insn = gen_bshufflev2si_vis (target, t1, t1);
12330 bmask = 0x45674567;
12331 break;
12332 case V4HImode:
12333 final_insn = gen_bshufflev4hi_vis (target, t1, t1);
12334 bmask = 0x67676767;
12335 break;
12336 case V8QImode:
12337 final_insn = gen_bshufflev8qi_vis (target, t1, t1);
12338 bmask = 0x77777777;
12339 break;
12340 default:
12341 gcc_unreachable ();
12344 sel = force_reg (SImode, GEN_INT (bmask));
12345 emit_insn (gen_bmasksi_vis (gen_reg_rtx (SImode), sel, const0_rtx));
12346 emit_insn (final_insn);
12349 /* Subroutine of sparc_expand_vector_init. Emit code to initialize
12350 all fields of TARGET to ELT in V8QI by means of VIS FPMERGE insn. */
12352 static void
12353 vector_init_fpmerge (rtx target, rtx elt)
12355 rtx t1, t2, t2_low, t3, t3_low;
12357 t1 = gen_reg_rtx (V4QImode);
12358 elt = convert_modes (SImode, QImode, elt, true);
12359 emit_move_insn (gen_lowpart (SImode, t1), elt);
12361 t2 = gen_reg_rtx (V8QImode);
12362 t2_low = gen_lowpart (V4QImode, t2);
12363 emit_insn (gen_fpmerge_vis (t2, t1, t1));
12365 t3 = gen_reg_rtx (V8QImode);
12366 t3_low = gen_lowpart (V4QImode, t3);
12367 emit_insn (gen_fpmerge_vis (t3, t2_low, t2_low));
12369 emit_insn (gen_fpmerge_vis (target, t3_low, t3_low));
12372 /* Subroutine of sparc_expand_vector_init. Emit code to initialize
12373 all fields of TARGET to ELT in V4HI by means of VIS FALIGNDATA insn. */
12375 static void
12376 vector_init_faligndata (rtx target, rtx elt)
12378 rtx t1 = gen_reg_rtx (V4HImode);
12379 int i;
12381 elt = convert_modes (SImode, HImode, elt, true);
12382 emit_move_insn (gen_lowpart (SImode, t1), elt);
12384 emit_insn (gen_alignaddrsi_vis (gen_reg_rtx (SImode),
12385 force_reg (SImode, GEN_INT (6)),
12386 const0_rtx));
12388 for (i = 0; i < 4; i++)
12389 emit_insn (gen_faligndatav4hi_vis (target, t1, target));
12392 /* Emit code to initialize TARGET to values for individual fields VALS. */
12394 void
12395 sparc_expand_vector_init (rtx target, rtx vals)
12397 const machine_mode mode = GET_MODE (target);
12398 const machine_mode inner_mode = GET_MODE_INNER (mode);
12399 const int n_elts = GET_MODE_NUNITS (mode);
12400 int i, n_var = 0;
12401 bool all_same = true;
12402 rtx mem;
12404 for (i = 0; i < n_elts; i++)
12406 rtx x = XVECEXP (vals, 0, i);
12407 if (!(CONST_SCALAR_INT_P (x) || CONST_DOUBLE_P (x) || CONST_FIXED_P (x)))
12408 n_var++;
12410 if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
12411 all_same = false;
12414 if (n_var == 0)
12416 emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
12417 return;
12420 if (GET_MODE_SIZE (inner_mode) == GET_MODE_SIZE (mode))
12422 if (GET_MODE_SIZE (inner_mode) == 4)
12424 emit_move_insn (gen_lowpart (SImode, target),
12425 gen_lowpart (SImode, XVECEXP (vals, 0, 0)));
12426 return;
12428 else if (GET_MODE_SIZE (inner_mode) == 8)
12430 emit_move_insn (gen_lowpart (DImode, target),
12431 gen_lowpart (DImode, XVECEXP (vals, 0, 0)));
12432 return;
12435 else if (GET_MODE_SIZE (inner_mode) == GET_MODE_SIZE (word_mode)
12436 && GET_MODE_SIZE (mode) == 2 * GET_MODE_SIZE (word_mode))
12438 emit_move_insn (gen_highpart (word_mode, target),
12439 gen_lowpart (word_mode, XVECEXP (vals, 0, 0)));
12440 emit_move_insn (gen_lowpart (word_mode, target),
12441 gen_lowpart (word_mode, XVECEXP (vals, 0, 1)));
12442 return;
12445 if (all_same && GET_MODE_SIZE (mode) == 8)
12447 if (TARGET_VIS2)
12449 vector_init_bshuffle (target, XVECEXP (vals, 0, 0), mode, inner_mode);
12450 return;
12452 if (mode == V8QImode)
12454 vector_init_fpmerge (target, XVECEXP (vals, 0, 0));
12455 return;
12457 if (mode == V4HImode)
12459 vector_init_faligndata (target, XVECEXP (vals, 0, 0));
12460 return;
12464 mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
12465 for (i = 0; i < n_elts; i++)
12466 emit_move_insn (adjust_address_nv (mem, inner_mode,
12467 i * GET_MODE_SIZE (inner_mode)),
12468 XVECEXP (vals, 0, i));
12469 emit_move_insn (target, mem);
12472 /* Implement TARGET_SECONDARY_RELOAD. */
12474 static reg_class_t
12475 sparc_secondary_reload (bool in_p, rtx x, reg_class_t rclass_i,
12476 machine_mode mode, secondary_reload_info *sri)
12478 enum reg_class rclass = (enum reg_class) rclass_i;
12480 sri->icode = CODE_FOR_nothing;
12481 sri->extra_cost = 0;
12483 /* We need a temporary when loading/storing a HImode/QImode value
12484 between memory and the FPU registers. This can happen when combine puts
12485 a paradoxical subreg in a float/fix conversion insn. */
12486 if (FP_REG_CLASS_P (rclass)
12487 && (mode == HImode || mode == QImode)
12488 && (GET_CODE (x) == MEM
12489 || ((GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
12490 && true_regnum (x) == -1)))
12491 return GENERAL_REGS;
12493 /* On 32-bit we need a temporary when loading/storing a DFmode value
12494 between unaligned memory and the upper FPU registers. */
12495 if (TARGET_ARCH32
12496 && rclass == EXTRA_FP_REGS
12497 && mode == DFmode
12498 && GET_CODE (x) == MEM
12499 && ! mem_min_alignment (x, 8))
12500 return FP_REGS;
12502 if (((TARGET_CM_MEDANY
12503 && symbolic_operand (x, mode))
12504 || (TARGET_CM_EMBMEDANY
12505 && text_segment_operand (x, mode)))
12506 && ! flag_pic)
12508 if (in_p)
12509 sri->icode = direct_optab_handler (reload_in_optab, mode);
12510 else
12511 sri->icode = direct_optab_handler (reload_out_optab, mode);
12512 return NO_REGS;
12515 if (TARGET_VIS3 && TARGET_ARCH32)
12517 int regno = true_regnum (x);
12519 /* When using VIS3 fp<-->int register moves, on 32-bit we have
12520 to move 8-byte values in 4-byte pieces. This only works via
12521 FP_REGS, and not via EXTRA_FP_REGS. Therefore if we try to
12522 move between EXTRA_FP_REGS and GENERAL_REGS, we will need
12523 an FP_REGS intermediate move. */
12524 if ((rclass == EXTRA_FP_REGS && SPARC_INT_REG_P (regno))
12525 || ((general_or_i64_p (rclass)
12526 || rclass == GENERAL_OR_FP_REGS)
12527 && SPARC_FP_REG_P (regno)))
12529 sri->extra_cost = 2;
12530 return FP_REGS;
12534 return NO_REGS;
12537 /* Emit code to conditionally move either OPERANDS[2] or OPERANDS[3] into
12538 OPERANDS[0] in MODE. OPERANDS[1] is the operator of the condition. */
12540 bool
12541 sparc_expand_conditional_move (machine_mode mode, rtx *operands)
12543 enum rtx_code rc = GET_CODE (operands[1]);
12544 machine_mode cmp_mode;
12545 rtx cc_reg, dst, cmp;
12547 cmp = operands[1];
12548 if (GET_MODE (XEXP (cmp, 0)) == DImode && !TARGET_ARCH64)
12549 return false;
12551 if (GET_MODE (XEXP (cmp, 0)) == TFmode && !TARGET_HARD_QUAD)
12552 cmp = sparc_emit_float_lib_cmp (XEXP (cmp, 0), XEXP (cmp, 1), rc);
12554 cmp_mode = GET_MODE (XEXP (cmp, 0));
12555 rc = GET_CODE (cmp);
12557 dst = operands[0];
12558 if (! rtx_equal_p (operands[2], dst)
12559 && ! rtx_equal_p (operands[3], dst))
12561 if (reg_overlap_mentioned_p (dst, cmp))
12562 dst = gen_reg_rtx (mode);
12564 emit_move_insn (dst, operands[3]);
12566 else if (operands[2] == dst)
12568 operands[2] = operands[3];
12570 if (GET_MODE_CLASS (cmp_mode) == MODE_FLOAT)
12571 rc = reverse_condition_maybe_unordered (rc);
12572 else
12573 rc = reverse_condition (rc);
12576 if (XEXP (cmp, 1) == const0_rtx
12577 && GET_CODE (XEXP (cmp, 0)) == REG
12578 && cmp_mode == DImode
12579 && v9_regcmp_p (rc))
12580 cc_reg = XEXP (cmp, 0);
12581 else
12582 cc_reg = gen_compare_reg_1 (rc, XEXP (cmp, 0), XEXP (cmp, 1));
12584 cmp = gen_rtx_fmt_ee (rc, GET_MODE (cc_reg), cc_reg, const0_rtx);
12586 emit_insn (gen_rtx_SET (dst,
12587 gen_rtx_IF_THEN_ELSE (mode, cmp, operands[2], dst)));
12589 if (dst != operands[0])
12590 emit_move_insn (operands[0], dst);
12592 return true;
12595 /* Emit code to conditionally move a combination of OPERANDS[1] and OPERANDS[2]
12596 into OPERANDS[0] in MODE, depending on the outcome of the comparison of
12597 OPERANDS[4] and OPERANDS[5]. OPERANDS[3] is the operator of the condition.
12598 FCODE is the machine code to be used for OPERANDS[3] and CCODE the machine
12599 code to be used for the condition mask. */
12601 void
12602 sparc_expand_vcond (machine_mode mode, rtx *operands, int ccode, int fcode)
12604 rtx mask, cop0, cop1, fcmp, cmask, bshuf, gsr;
12605 enum rtx_code code = GET_CODE (operands[3]);
12607 mask = gen_reg_rtx (Pmode);
12608 cop0 = operands[4];
12609 cop1 = operands[5];
12610 if (code == LT || code == GE)
12612 rtx t;
12614 code = swap_condition (code);
12615 t = cop0; cop0 = cop1; cop1 = t;
12618 gsr = gen_rtx_REG (DImode, SPARC_GSR_REG);
12620 fcmp = gen_rtx_UNSPEC (Pmode,
12621 gen_rtvec (1, gen_rtx_fmt_ee (code, mode, cop0, cop1)),
12622 fcode);
12624 cmask = gen_rtx_UNSPEC (DImode,
12625 gen_rtvec (2, mask, gsr),
12626 ccode);
12628 bshuf = gen_rtx_UNSPEC (mode,
12629 gen_rtvec (3, operands[1], operands[2], gsr),
12630 UNSPEC_BSHUFFLE);
12632 emit_insn (gen_rtx_SET (mask, fcmp));
12633 emit_insn (gen_rtx_SET (gsr, cmask));
12635 emit_insn (gen_rtx_SET (operands[0], bshuf));
12638 /* On sparc, any mode which naturally allocates into the float
12639 registers should return 4 here. */
12641 unsigned int
12642 sparc_regmode_natural_size (machine_mode mode)
12644 int size = UNITS_PER_WORD;
12646 if (TARGET_ARCH64)
12648 enum mode_class mclass = GET_MODE_CLASS (mode);
12650 if (mclass == MODE_FLOAT || mclass == MODE_VECTOR_INT)
12651 size = 4;
12654 return size;
12657 /* Return TRUE if it is a good idea to tie two pseudo registers
12658 when one has mode MODE1 and one has mode MODE2.
12659 If HARD_REGNO_MODE_OK could produce different values for MODE1 and MODE2,
12660 for any hard reg, then this must be FALSE for correct output.
12662 For V9 we have to deal with the fact that only the lower 32 floating
12663 point registers are 32-bit addressable. */
12665 bool
12666 sparc_modes_tieable_p (machine_mode mode1, machine_mode mode2)
12668 enum mode_class mclass1, mclass2;
12669 unsigned short size1, size2;
12671 if (mode1 == mode2)
12672 return true;
12674 mclass1 = GET_MODE_CLASS (mode1);
12675 mclass2 = GET_MODE_CLASS (mode2);
12676 if (mclass1 != mclass2)
12677 return false;
12679 if (! TARGET_V9)
12680 return true;
12682 /* Classes are the same and we are V9 so we have to deal with upper
12683 vs. lower floating point registers. If one of the modes is a
12684 4-byte mode, and the other is not, we have to mark them as not
12685 tieable because only the lower 32 floating point register are
12686 addressable 32-bits at a time.
12688 We can't just test explicitly for SFmode, otherwise we won't
12689 cover the vector mode cases properly. */
12691 if (mclass1 != MODE_FLOAT && mclass1 != MODE_VECTOR_INT)
12692 return true;
12694 size1 = GET_MODE_SIZE (mode1);
12695 size2 = GET_MODE_SIZE (mode2);
12696 if ((size1 > 4 && size2 == 4)
12697 || (size2 > 4 && size1 == 4))
12698 return false;
12700 return true;
12703 /* Implement TARGET_CSTORE_MODE. */
12705 static machine_mode
12706 sparc_cstore_mode (enum insn_code icode ATTRIBUTE_UNUSED)
12708 return (TARGET_ARCH64 ? DImode : SImode);
12711 /* Return the compound expression made of T1 and T2. */
12713 static inline tree
12714 compound_expr (tree t1, tree t2)
12716 return build2 (COMPOUND_EXPR, void_type_node, t1, t2);
12719 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV hook. */
12721 static void
12722 sparc_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
12724 if (!TARGET_FPU)
12725 return;
12727 const unsigned HOST_WIDE_INT accrued_exception_mask = 0x1f << 5;
12728 const unsigned HOST_WIDE_INT trap_enable_mask = 0x1f << 23;
12730 /* We generate the equivalent of feholdexcept (&fenv_var):
12732 unsigned int fenv_var;
12733 __builtin_store_fsr (&fenv_var);
12735 unsigned int tmp1_var;
12736 tmp1_var = fenv_var & ~(accrued_exception_mask | trap_enable_mask);
12738 __builtin_load_fsr (&tmp1_var); */
12740 tree fenv_var = create_tmp_var_raw (unsigned_type_node);
12741 TREE_ADDRESSABLE (fenv_var) = 1;
12742 tree fenv_addr = build_fold_addr_expr (fenv_var);
12743 tree stfsr = sparc_builtins[SPARC_BUILTIN_STFSR];
12744 tree hold_stfsr
12745 = build4 (TARGET_EXPR, unsigned_type_node, fenv_var,
12746 build_call_expr (stfsr, 1, fenv_addr), NULL_TREE, NULL_TREE);
12748 tree tmp1_var = create_tmp_var_raw (unsigned_type_node);
12749 TREE_ADDRESSABLE (tmp1_var) = 1;
12750 tree masked_fenv_var
12751 = build2 (BIT_AND_EXPR, unsigned_type_node, fenv_var,
12752 build_int_cst (unsigned_type_node,
12753 ~(accrued_exception_mask | trap_enable_mask)));
12754 tree hold_mask
12755 = build4 (TARGET_EXPR, unsigned_type_node, tmp1_var, masked_fenv_var,
12756 NULL_TREE, NULL_TREE);
12758 tree tmp1_addr = build_fold_addr_expr (tmp1_var);
12759 tree ldfsr = sparc_builtins[SPARC_BUILTIN_LDFSR];
12760 tree hold_ldfsr = build_call_expr (ldfsr, 1, tmp1_addr);
12762 *hold = compound_expr (compound_expr (hold_stfsr, hold_mask), hold_ldfsr);
12764 /* We reload the value of tmp1_var to clear the exceptions:
12766 __builtin_load_fsr (&tmp1_var); */
12768 *clear = build_call_expr (ldfsr, 1, tmp1_addr);
12770 /* We generate the equivalent of feupdateenv (&fenv_var):
12772 unsigned int tmp2_var;
12773 __builtin_store_fsr (&tmp2_var);
12775 __builtin_load_fsr (&fenv_var);
12777 if (SPARC_LOW_FE_EXCEPT_VALUES)
12778 tmp2_var >>= 5;
12779 __atomic_feraiseexcept ((int) tmp2_var); */
12781 tree tmp2_var = create_tmp_var_raw (unsigned_type_node);
12782 TREE_ADDRESSABLE (tmp2_var) = 1;
12783 tree tmp2_addr = build_fold_addr_expr (tmp2_var);
12784 tree update_stfsr
12785 = build4 (TARGET_EXPR, unsigned_type_node, tmp2_var,
12786 build_call_expr (stfsr, 1, tmp2_addr), NULL_TREE, NULL_TREE);
12788 tree update_ldfsr = build_call_expr (ldfsr, 1, fenv_addr);
12790 tree atomic_feraiseexcept
12791 = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
12792 tree update_call
12793 = build_call_expr (atomic_feraiseexcept, 1,
12794 fold_convert (integer_type_node, tmp2_var));
12796 if (SPARC_LOW_FE_EXCEPT_VALUES)
12798 tree shifted_tmp2_var
12799 = build2 (RSHIFT_EXPR, unsigned_type_node, tmp2_var,
12800 build_int_cst (unsigned_type_node, 5));
12801 tree update_shift
12802 = build2 (MODIFY_EXPR, void_type_node, tmp2_var, shifted_tmp2_var);
12803 update_call = compound_expr (update_shift, update_call);
12806 *update
12807 = compound_expr (compound_expr (update_stfsr, update_ldfsr), update_call);
12810 #include "gt-sparc.h"