1 /* Subroutines for insn-output.c for Sun SPARC.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 64-bit SPARC-V9 support by Michael Tiemann, Jim Wilson, and Doug Evans,
6 at Cygnus Support.
7
8 This file is part of GNU CC.
9
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
24
25 #include "config.h"
26 #include "system.h"
27 #include "tree.h"
28 #include "rtl.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "real.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "output.h"
35 #include "insn-attr.h"
36 #include "flags.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "optabs.h"
40 #include "libfuncs.h"
41 #include "recog.h"
42 #include "toplev.h"
43 #include "ggc.h"
44 #include "tm_p.h"
45 #include "debug.h"
46 #include "target.h"
47 #include "target-def.h"
48
49 /* 1 if the caller has placed an "unimp" insn immediately after the call.
50 This is used in v8 code when calling a function that returns a structure.
51 v9 doesn't have this. Be careful to have this test be the same as that
52 used on the call. */
53
54 #define SKIP_CALLERS_UNIMP_P \
55 (!TARGET_ARCH64 && current_function_returns_struct \
56 && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))) \
57 && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl))) \
58 == INTEGER_CST))
59
60 /* Global variables for machine-dependent things. */
61
62 /* Size of frame. Need to know this to emit return insns from leaf procedures.
63 ACTUAL_FSIZE is set by compute_frame_size() which is called during the
64 reload pass. This is important as the value is later used in insn
65 scheduling (to see what can go in a delay slot).
66 APPARENT_FSIZE is the size of the stack less the register save area and less
67 the outgoing argument area. It is used when saving call preserved regs. */
68 static int apparent_fsize;
69 static int actual_fsize;
70
71 /* Number of live general or floating point registers needed to be
72 saved (as 4-byte quantities). */
73 static int num_gfregs;
74
75 /* Save the operands last given to a compare for use when we
76 generate a scc or bcc insn. */
77 rtx sparc_compare_op0, sparc_compare_op1;
78
79 /* Coordinate with the md file wrt special insns created by
80 sparc_nonflat_function_epilogue. */
81 bool sparc_emitting_epilogue;
82
83 /* Vector to say how input registers are mapped to output registers.
84 HARD_FRAME_POINTER_REGNUM cannot be remapped by this function to
85 eliminate it. You must use -fomit-frame-pointer to get that. */
86 char leaf_reg_remap[] =
87 { 0, 1, 2, 3, 4, 5, 6, 7,
88 -1, -1, -1, -1, -1, -1, 14, -1,
89 -1, -1, -1, -1, -1, -1, -1, -1,
90 8, 9, 10, 11, 12, 13, -1, 15,
91
92 32, 33, 34, 35, 36, 37, 38, 39,
93 40, 41, 42, 43, 44, 45, 46, 47,
94 48, 49, 50, 51, 52, 53, 54, 55,
95 56, 57, 58, 59, 60, 61, 62, 63,
96 64, 65, 66, 67, 68, 69, 70, 71,
97 72, 73, 74, 75, 76, 77, 78, 79,
98 80, 81, 82, 83, 84, 85, 86, 87,
99 88, 89, 90, 91, 92, 93, 94, 95,
100 96, 97, 98, 99, 100};
101
102 /* Vector, indexed by hard register number, which contains 1
103 for a register that is allowable in a candidate for leaf
104 function treatment. */
105 char sparc_leaf_regs[] =
106 { 1, 1, 1, 1, 1, 1, 1, 1,
107 0, 0, 0, 0, 0, 0, 1, 0,
108 0, 0, 0, 0, 0, 0, 0, 0,
109 1, 1, 1, 1, 1, 1, 0, 1,
110 1, 1, 1, 1, 1, 1, 1, 1,
111 1, 1, 1, 1, 1, 1, 1, 1,
112 1, 1, 1, 1, 1, 1, 1, 1,
113 1, 1, 1, 1, 1, 1, 1, 1,
114 1, 1, 1, 1, 1, 1, 1, 1,
115 1, 1, 1, 1, 1, 1, 1, 1,
116 1, 1, 1, 1, 1, 1, 1, 1,
117 1, 1, 1, 1, 1, 1, 1, 1,
118 1, 1, 1, 1, 1};
119
120 /* Name of where we pretend to think the frame pointer points.
121 Normally, this is "%fp", but if we are in a leaf procedure,
122 this is "%sp+something". We record "something" separately as it may be
123 too big for reg+constant addressing. */
124
125 static const char *frame_base_name;
126 static int frame_base_offset;
127
128 static void sparc_init_modes PARAMS ((void));
129 static int save_regs PARAMS ((FILE *, int, int, const char *,
130 int, int, int));
131 static int restore_regs PARAMS ((FILE *, int, int, const char *, int, int));
132 static void build_big_number PARAMS ((FILE *, int, const char *));
133 static int function_arg_slotno PARAMS ((const CUMULATIVE_ARGS *,
134 enum machine_mode, tree, int, int,
135 int *, int *));
136
137 static int supersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
138 static int hypersparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
139
140 static void sparc_output_addr_vec PARAMS ((rtx));
141 static void sparc_output_addr_diff_vec PARAMS ((rtx));
142 static void sparc_output_deferred_case_vectors PARAMS ((void));
143 static int check_return_regs PARAMS ((rtx));
144 static int epilogue_renumber PARAMS ((rtx *, int));
145 static bool sparc_assemble_integer PARAMS ((rtx, unsigned int, int));
146 static int set_extends PARAMS ((rtx));
147 static void output_restore_regs PARAMS ((FILE *, int));
148 static void sparc_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
149 static void sparc_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
150 static void sparc_flat_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
151 static void sparc_flat_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
152 static void sparc_nonflat_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT,
153 int));
154 static void sparc_nonflat_function_prologue PARAMS ((FILE *, HOST_WIDE_INT,
155 int));
156 #ifdef OBJECT_FORMAT_ELF
157 static void sparc_elf_asm_named_section PARAMS ((const char *, unsigned int));
158 #endif
159 static void sparc_aout_select_section PARAMS ((tree, int,
160 unsigned HOST_WIDE_INT))
161 ATTRIBUTE_UNUSED;
162 static void sparc_aout_select_rtx_section PARAMS ((enum machine_mode, rtx,
163 unsigned HOST_WIDE_INT))
164 ATTRIBUTE_UNUSED;
165
166 static int sparc_adjust_cost PARAMS ((rtx, rtx, rtx, int));
167 static int sparc_issue_rate PARAMS ((void));
168 static void sparc_sched_init PARAMS ((FILE *, int, int));
169 static int sparc_use_dfa_pipeline_interface PARAMS ((void));
170 static int sparc_use_sched_lookahead PARAMS ((void));
171
172 static void emit_soft_tfmode_libcall PARAMS ((const char *, int, rtx *));
173 static void emit_soft_tfmode_binop PARAMS ((enum rtx_code, rtx *));
174 static void emit_soft_tfmode_unop PARAMS ((enum rtx_code, rtx *));
175 static void emit_soft_tfmode_cvt PARAMS ((enum rtx_code, rtx *));
176 static void emit_hard_tfmode_operation PARAMS ((enum rtx_code, rtx *));
177
178 static void sparc_encode_section_info PARAMS ((tree, int));
179 static void sparc_output_mi_thunk PARAMS ((FILE *, tree, HOST_WIDE_INT,
180 HOST_WIDE_INT, tree));
181 static bool sparc_can_output_mi_thunk PARAMS ((tree, HOST_WIDE_INT,
182 HOST_WIDE_INT, tree));
183
184 /* Option handling. */
185
186 /* Code model option as passed by user. */
187 const char *sparc_cmodel_string;
188 /* Parsed value. */
189 enum cmodel sparc_cmodel;
190
191 char sparc_hard_reg_printed[8];
192
193 struct sparc_cpu_select sparc_select[] =
194 {
195 /* switch name, tune arch */
196 { (char *)0, "default", 1, 1 },
197 { (char *)0, "-mcpu=", 1, 1 },
198 { (char *)0, "-mtune=", 1, 0 },
199 { 0, 0, 0, 0 }
200 };
201
202 /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */
203 enum processor_type sparc_cpu;
204
205 /* Initialize the GCC target structure. */
206
207 /* The sparc default is to use .half rather than .short for aligned
208 HI objects. Use .word instead of .long on non-ELF systems. */
209 #undef TARGET_ASM_ALIGNED_HI_OP
210 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
211 #ifndef OBJECT_FORMAT_ELF
212 #undef TARGET_ASM_ALIGNED_SI_OP
213 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
214 #endif
215
216 #undef TARGET_ASM_UNALIGNED_HI_OP
217 #define TARGET_ASM_UNALIGNED_HI_OP "\t.uahalf\t"
218 #undef TARGET_ASM_UNALIGNED_SI_OP
219 #define TARGET_ASM_UNALIGNED_SI_OP "\t.uaword\t"
220 #undef TARGET_ASM_UNALIGNED_DI_OP
221 #define TARGET_ASM_UNALIGNED_DI_OP "\t.uaxword\t"
222
223 /* The target hook has to handle DI-mode values. */
224 #undef TARGET_ASM_INTEGER
225 #define TARGET_ASM_INTEGER sparc_assemble_integer
226
227 #undef TARGET_ASM_FUNCTION_PROLOGUE
228 #define TARGET_ASM_FUNCTION_PROLOGUE sparc_output_function_prologue
229 #undef TARGET_ASM_FUNCTION_EPILOGUE
230 #define TARGET_ASM_FUNCTION_EPILOGUE sparc_output_function_epilogue
231
232 #undef TARGET_SCHED_ADJUST_COST
233 #define TARGET_SCHED_ADJUST_COST sparc_adjust_cost
234 #undef TARGET_SCHED_ISSUE_RATE
235 #define TARGET_SCHED_ISSUE_RATE sparc_issue_rate
236 #undef TARGET_SCHED_INIT
237 #define TARGET_SCHED_INIT sparc_sched_init
238 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
239 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE sparc_use_dfa_pipeline_interface
240 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
241 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD sparc_use_sched_lookahead
242
243 #undef TARGET_ENCODE_SECTION_INFO
244 #define TARGET_ENCODE_SECTION_INFO sparc_encode_section_info
245
246 #undef TARGET_ASM_OUTPUT_MI_THUNK
247 #define TARGET_ASM_OUTPUT_MI_THUNK sparc_output_mi_thunk
248 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
249 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK sparc_can_output_mi_thunk
250
251 struct gcc_target targetm = TARGET_INITIALIZER;
252
253 /* Validate and override various options, and do some machine dependent
254 initialization. */
255
256 void
sparc_override_options()257 sparc_override_options ()
258 {
259 static struct code_model {
260 const char *const name;
261 const int value;
262 } const cmodels[] = {
263 { "32", CM_32 },
264 { "medlow", CM_MEDLOW },
265 { "medmid", CM_MEDMID },
266 { "medany", CM_MEDANY },
267 { "embmedany", CM_EMBMEDANY },
268 { 0, 0 }
269 };
270 const struct code_model *cmodel;
271 /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */
272 static struct cpu_default {
273 const int cpu;
274 const char *const name;
275 } const cpu_default[] = {
276 /* There must be one entry here for each TARGET_CPU value. */
277 { TARGET_CPU_sparc, "cypress" },
278 { TARGET_CPU_sparclet, "tsc701" },
279 { TARGET_CPU_sparclite, "f930" },
280 { TARGET_CPU_v8, "v8" },
281 { TARGET_CPU_hypersparc, "hypersparc" },
282 { TARGET_CPU_sparclite86x, "sparclite86x" },
283 { TARGET_CPU_supersparc, "supersparc" },
284 { TARGET_CPU_v9, "v9" },
285 { TARGET_CPU_ultrasparc, "ultrasparc" },
286 { TARGET_CPU_ultrasparc3, "ultrasparc3" },
287 { 0, 0 }
288 };
289 const struct cpu_default *def;
290 /* Table of values for -m{cpu,tune}=. */
291 static struct cpu_table {
292 const char *const name;
293 const enum processor_type processor;
294 const int disable;
295 const int enable;
296 } const cpu_table[] = {
297 { "v7", PROCESSOR_V7, MASK_ISA, 0 },
298 { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 },
299 { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 },
300 /* TI TMS390Z55 supersparc */
301 { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
302 { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
303 /* The Fujitsu MB86930 is the original sparclite chip, with no fpu.
304 The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */
305 { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
306 { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU },
307 { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
308 { "sparclite86x", PROCESSOR_SPARCLITE86X, MASK_ISA|MASK_FPU,
309 MASK_SPARCLITE },
310 { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET },
311 /* TEMIC sparclet */
312 { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET },
313 { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 },
314 /* TI ultrasparc I, II, IIi */
315 { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9
316 /* Although insns using %y are deprecated, it is a clear win on current
317 ultrasparcs. */
318 |MASK_DEPRECATED_V8_INSNS},
319 /* TI ultrasparc III */
320 /* ??? Check if %y issue still holds true in ultra3. */
321 { "ultrasparc3", PROCESSOR_ULTRASPARC3, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
322 { 0, 0, 0, 0 }
323 };
324 const struct cpu_table *cpu;
325 const struct sparc_cpu_select *sel;
326 int fpu;
327
328 #ifndef SPARC_BI_ARCH
329 /* Check for unsupported architecture size. */
330 if (! TARGET_64BIT != DEFAULT_ARCH32_P)
331 error ("%s is not supported by this configuration",
332 DEFAULT_ARCH32_P ? "-m64" : "-m32");
333 #endif
334
335 /* We force all 64bit archs to use 128 bit long double */
336 if (TARGET_64BIT && ! TARGET_LONG_DOUBLE_128)
337 {
338 error ("-mlong-double-64 not allowed with -m64");
339 target_flags |= MASK_LONG_DOUBLE_128;
340 }
341
342 /* Code model selection. */
343 sparc_cmodel = SPARC_DEFAULT_CMODEL;
344
345 #ifdef SPARC_BI_ARCH
346 if (TARGET_ARCH32)
347 sparc_cmodel = CM_32;
348 #endif
349
350 if (sparc_cmodel_string != NULL)
351 {
352 if (TARGET_ARCH64)
353 {
354 for (cmodel = &cmodels[0]; cmodel->name; cmodel++)
355 if (strcmp (sparc_cmodel_string, cmodel->name) == 0)
356 break;
357 if (cmodel->name == NULL)
358 error ("bad value (%s) for -mcmodel= switch", sparc_cmodel_string);
359 else
360 sparc_cmodel = cmodel->value;
361 }
362 else
363 error ("-mcmodel= is not supported on 32 bit systems");
364 }
365
366 fpu = TARGET_FPU; /* save current -mfpu status */
367
368 /* Set the default CPU. */
369 for (def = &cpu_default[0]; def->name; ++def)
370 if (def->cpu == TARGET_CPU_DEFAULT)
371 break;
372 if (! def->name)
373 abort ();
374 sparc_select[0].string = def->name;
375
376 for (sel = &sparc_select[0]; sel->name; ++sel)
377 {
378 if (sel->string)
379 {
380 for (cpu = &cpu_table[0]; cpu->name; ++cpu)
381 if (! strcmp (sel->string, cpu->name))
382 {
383 if (sel->set_tune_p)
384 sparc_cpu = cpu->processor;
385
386 if (sel->set_arch_p)
387 {
388 target_flags &= ~cpu->disable;
389 target_flags |= cpu->enable;
390 }
391 break;
392 }
393
394 if (! cpu->name)
395 error ("bad value (%s) for %s switch", sel->string, sel->name);
396 }
397 }
398
399 /* If -mfpu or -mno-fpu was explicitly used, don't override with
400 the processor default. Clear MASK_FPU_SET to avoid confusing
401 the reverse mapping from switch values to names. */
402 if (TARGET_FPU_SET)
403 {
404 target_flags = (target_flags & ~MASK_FPU) | fpu;
405 target_flags &= ~MASK_FPU_SET;
406 }
407
408 /* Don't allow -mvis if FPU is disabled. */
409 if (! TARGET_FPU)
410 target_flags &= ~MASK_VIS;
411
412 /* -mvis assumes UltraSPARC+, so we are sure v9 instructions
413 are available.
414 -m64 also implies v9. */
415 if (TARGET_VIS || TARGET_ARCH64)
416 {
417 target_flags |= MASK_V9;
418 target_flags &= ~(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE);
419 }
420
421 /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */
422 if (TARGET_V9 && TARGET_ARCH32)
423 target_flags |= MASK_DEPRECATED_V8_INSNS;
424
425 /* V8PLUS requires V9, makes no sense in 64 bit mode. */
426 if (! TARGET_V9 || TARGET_ARCH64)
427 target_flags &= ~MASK_V8PLUS;
428
429 /* Don't use stack biasing in 32 bit mode. */
430 if (TARGET_ARCH32)
431 target_flags &= ~MASK_STACK_BIAS;
432
433 /* Supply a default value for align_functions. */
434 if (align_functions == 0
435 && (sparc_cpu == PROCESSOR_ULTRASPARC
436 || sparc_cpu == PROCESSOR_ULTRASPARC3))
437 align_functions = 32;
438
439 /* Validate PCC_STRUCT_RETURN. */
440 if (flag_pcc_struct_return == DEFAULT_PCC_STRUCT_RETURN)
441 flag_pcc_struct_return = (TARGET_ARCH64 ? 0 : 1);
442
443 /* Only use .uaxword when compiling for a 64-bit target. */
444 if (!TARGET_ARCH64)
445 targetm.asm_out.unaligned_op.di = NULL;
446
447 /* Do various machine dependent initializations. */
448 sparc_init_modes ();
449 }
450
451 /* Miscellaneous utilities. */
452
453 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
454 or branch on register contents instructions. */
455
456 int
v9_regcmp_p(code)457 v9_regcmp_p (code)
458 enum rtx_code code;
459 {
460 return (code == EQ || code == NE || code == GE || code == LT
461 || code == LE || code == GT);
462 }
463
464
465 /* Operand constraints. */
466
467 /* Return nonzero only if OP is a register of mode MODE,
468 or const0_rtx. */
469
470 int
reg_or_0_operand(op,mode)471 reg_or_0_operand (op, mode)
472 rtx op;
473 enum machine_mode mode;
474 {
475 if (register_operand (op, mode))
476 return 1;
477 if (op == const0_rtx)
478 return 1;
479 if (GET_MODE (op) == VOIDmode && GET_CODE (op) == CONST_DOUBLE
480 && CONST_DOUBLE_HIGH (op) == 0
481 && CONST_DOUBLE_LOW (op) == 0)
482 return 1;
483 if (fp_zero_operand (op, mode))
484 return 1;
485 return 0;
486 }
487
488 /* Return nonzero only if OP is const1_rtx. */
489
490 int
const1_operand(op,mode)491 const1_operand (op, mode)
492 rtx op;
493 enum machine_mode mode ATTRIBUTE_UNUSED;
494 {
495 return op == const1_rtx;
496 }
497
498 /* Nonzero if OP is a floating point value with value 0.0. */
499
500 int
fp_zero_operand(op,mode)501 fp_zero_operand (op, mode)
502 rtx op;
503 enum machine_mode mode;
504 {
505 if (GET_MODE_CLASS (GET_MODE (op)) != MODE_FLOAT)
506 return 0;
507 return op == CONST0_RTX (mode);
508 }
509
510 /* Nonzero if OP is a register operand in floating point register. */
511
512 int
fp_register_operand(op,mode)513 fp_register_operand (op, mode)
514 rtx op;
515 enum machine_mode mode;
516 {
517 if (! register_operand (op, mode))
518 return 0;
519 if (GET_CODE (op) == SUBREG)
520 op = SUBREG_REG (op);
521 return GET_CODE (op) == REG && SPARC_FP_REG_P (REGNO (op));
522 }
523
524 /* Nonzero if OP is a floating point constant which can
525 be loaded into an integer register using a single
526 sethi instruction. */
527
528 int
fp_sethi_p(op)529 fp_sethi_p (op)
530 rtx op;
531 {
532 if (GET_CODE (op) == CONST_DOUBLE)
533 {
534 REAL_VALUE_TYPE r;
535 long i;
536
537 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
538 if (REAL_VALUES_EQUAL (r, dconst0) &&
539 ! REAL_VALUE_MINUS_ZERO (r))
540 return 0;
541 REAL_VALUE_TO_TARGET_SINGLE (r, i);
542 if (SPARC_SETHI_P (i))
543 return 1;
544 }
545
546 return 0;
547 }
548
549 /* Nonzero if OP is a floating point constant which can
550 be loaded into an integer register using a single
551 mov instruction. */
552
553 int
fp_mov_p(op)554 fp_mov_p (op)
555 rtx op;
556 {
557 if (GET_CODE (op) == CONST_DOUBLE)
558 {
559 REAL_VALUE_TYPE r;
560 long i;
561
562 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
563 if (REAL_VALUES_EQUAL (r, dconst0) &&
564 ! REAL_VALUE_MINUS_ZERO (r))
565 return 0;
566 REAL_VALUE_TO_TARGET_SINGLE (r, i);
567 if (SPARC_SIMM13_P (i))
568 return 1;
569 }
570
571 return 0;
572 }
573
574 /* Nonzero if OP is a floating point constant which can
575 be loaded into an integer register using a high/losum
576 instruction sequence. */
577
578 int
fp_high_losum_p(op)579 fp_high_losum_p (op)
580 rtx op;
581 {
582 /* The constraints calling this should only be in
583 SFmode move insns, so any constant which cannot
584 be moved using a single insn will do. */
585 if (GET_CODE (op) == CONST_DOUBLE)
586 {
587 REAL_VALUE_TYPE r;
588 long i;
589
590 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
591 if (REAL_VALUES_EQUAL (r, dconst0) &&
592 ! REAL_VALUE_MINUS_ZERO (r))
593 return 0;
594 REAL_VALUE_TO_TARGET_SINGLE (r, i);
595 if (! SPARC_SETHI_P (i)
596 && ! SPARC_SIMM13_P (i))
597 return 1;
598 }
599
600 return 0;
601 }
602
603 /* Nonzero if OP is an integer register. */
604
605 int
intreg_operand(op,mode)606 intreg_operand (op, mode)
607 rtx op;
608 enum machine_mode mode ATTRIBUTE_UNUSED;
609 {
610 return (register_operand (op, SImode)
611 || (TARGET_ARCH64 && register_operand (op, DImode)));
612 }
613
614 /* Nonzero if OP is a floating point condition code register. */
615
616 int
fcc_reg_operand(op,mode)617 fcc_reg_operand (op, mode)
618 rtx op;
619 enum machine_mode mode;
620 {
621 /* This can happen when recog is called from combine. Op may be a MEM.
622 Fail instead of calling abort in this case. */
623 if (GET_CODE (op) != REG)
624 return 0;
625
626 if (mode != VOIDmode && mode != GET_MODE (op))
627 return 0;
628 if (mode == VOIDmode
629 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
630 return 0;
631
632 #if 0 /* ??? ==> 1 when %fcc0-3 are pseudos first. See gen_compare_reg(). */
633 if (reg_renumber == 0)
634 return REGNO (op) >= FIRST_PSEUDO_REGISTER;
635 return REGNO_OK_FOR_CCFP_P (REGNO (op));
636 #else
637 return (unsigned) REGNO (op) - SPARC_FIRST_V9_FCC_REG < 4;
638 #endif
639 }
640
641 /* Nonzero if OP is a floating point condition code fcc0 register. */
642
643 int
fcc0_reg_operand(op,mode)644 fcc0_reg_operand (op, mode)
645 rtx op;
646 enum machine_mode mode;
647 {
648 /* This can happen when recog is called from combine. Op may be a MEM.
649 Fail instead of calling abort in this case. */
650 if (GET_CODE (op) != REG)
651 return 0;
652
653 if (mode != VOIDmode && mode != GET_MODE (op))
654 return 0;
655 if (mode == VOIDmode
656 && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode))
657 return 0;
658
659 return REGNO (op) == SPARC_FCC_REG;
660 }
661
662 /* Nonzero if OP is an integer or floating point condition code register. */
663
664 int
icc_or_fcc_reg_operand(op,mode)665 icc_or_fcc_reg_operand (op, mode)
666 rtx op;
667 enum machine_mode mode;
668 {
669 if (GET_CODE (op) == REG && REGNO (op) == SPARC_ICC_REG)
670 {
671 if (mode != VOIDmode && mode != GET_MODE (op))
672 return 0;
673 if (mode == VOIDmode
674 && GET_MODE (op) != CCmode && GET_MODE (op) != CCXmode)
675 return 0;
676 return 1;
677 }
678
679 return fcc_reg_operand (op, mode);
680 }
681
682 /* Nonzero if OP can appear as the dest of a RESTORE insn. */
683 int
restore_operand(op,mode)684 restore_operand (op, mode)
685 rtx op;
686 enum machine_mode mode;
687 {
688 return (GET_CODE (op) == REG && GET_MODE (op) == mode
689 && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32)));
690 }
691
692 /* Call insn on SPARC can take a PC-relative constant address, or any regular
693 memory address. */
694
695 int
call_operand(op,mode)696 call_operand (op, mode)
697 rtx op;
698 enum machine_mode mode;
699 {
700 if (GET_CODE (op) != MEM)
701 abort ();
702 op = XEXP (op, 0);
703 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
704 }
705
706 int
call_operand_address(op,mode)707 call_operand_address (op, mode)
708 rtx op;
709 enum machine_mode mode;
710 {
711 return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
712 }
713
714 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
715 reference and a constant. */
716
717 int
symbolic_operand(op,mode)718 symbolic_operand (op, mode)
719 register rtx op;
720 enum machine_mode mode;
721 {
722 enum machine_mode omode = GET_MODE (op);
723
724 if (omode != mode && omode != VOIDmode && mode != VOIDmode)
725 return 0;
726
727 switch (GET_CODE (op))
728 {
729 case SYMBOL_REF:
730 case LABEL_REF:
731 return 1;
732
733 case CONST:
734 op = XEXP (op, 0);
735 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
736 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
737 && GET_CODE (XEXP (op, 1)) == CONST_INT);
738
739 default:
740 return 0;
741 }
742 }
743
744 /* Return truth value of statement that OP is a symbolic memory
745 operand of mode MODE. */
746
747 int
symbolic_memory_operand(op,mode)748 symbolic_memory_operand (op, mode)
749 rtx op;
750 enum machine_mode mode ATTRIBUTE_UNUSED;
751 {
752 if (GET_CODE (op) == SUBREG)
753 op = SUBREG_REG (op);
754 if (GET_CODE (op) != MEM)
755 return 0;
756 op = XEXP (op, 0);
757 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
758 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
759 }
760
761 /* Return truth value of statement that OP is a LABEL_REF of mode MODE. */
762
763 int
label_ref_operand(op,mode)764 label_ref_operand (op, mode)
765 rtx op;
766 enum machine_mode mode;
767 {
768 if (GET_CODE (op) != LABEL_REF)
769 return 0;
770 if (GET_MODE (op) != mode)
771 return 0;
772 return 1;
773 }
774
775 /* Return 1 if the operand is an argument used in generating pic references
776 in either the medium/low or medium/anywhere code models of sparc64. */
777
778 int
sp64_medium_pic_operand(op,mode)779 sp64_medium_pic_operand (op, mode)
780 rtx op;
781 enum machine_mode mode ATTRIBUTE_UNUSED;
782 {
783 /* Check for (const (minus (symbol_ref:GOT)
784 (const (minus (label) (pc))))). */
785 if (GET_CODE (op) != CONST)
786 return 0;
787 op = XEXP (op, 0);
788 if (GET_CODE (op) != MINUS)
789 return 0;
790 if (GET_CODE (XEXP (op, 0)) != SYMBOL_REF)
791 return 0;
792 /* ??? Ensure symbol is GOT. */
793 if (GET_CODE (XEXP (op, 1)) != CONST)
794 return 0;
795 if (GET_CODE (XEXP (XEXP (op, 1), 0)) != MINUS)
796 return 0;
797 return 1;
798 }
799
800 /* Return 1 if the operand is a data segment reference. This includes
801 the readonly data segment, or in other words anything but the text segment.
802 This is needed in the medium/anywhere code model on v9. These values
803 are accessed with EMBMEDANY_BASE_REG. */
804
805 int
data_segment_operand(op,mode)806 data_segment_operand (op, mode)
807 rtx op;
808 enum machine_mode mode ATTRIBUTE_UNUSED;
809 {
810 switch (GET_CODE (op))
811 {
812 case SYMBOL_REF :
813 return ! SYMBOL_REF_FLAG (op);
814 case PLUS :
815 /* Assume canonical format of symbol + constant.
816 Fall through. */
817 case CONST :
818 return data_segment_operand (XEXP (op, 0), VOIDmode);
819 default :
820 return 0;
821 }
822 }
823
824 /* Return 1 if the operand is a text segment reference.
825 This is needed in the medium/anywhere code model on v9. */
826
827 int
text_segment_operand(op,mode)828 text_segment_operand (op, mode)
829 rtx op;
830 enum machine_mode mode ATTRIBUTE_UNUSED;
831 {
832 switch (GET_CODE (op))
833 {
834 case LABEL_REF :
835 return 1;
836 case SYMBOL_REF :
837 return SYMBOL_REF_FLAG (op);
838 case PLUS :
839 /* Assume canonical format of symbol + constant.
840 Fall through. */
841 case CONST :
842 return text_segment_operand (XEXP (op, 0), VOIDmode);
843 default :
844 return 0;
845 }
846 }
847
848 /* Return 1 if the operand is either a register or a memory operand that is
849 not symbolic. */
850
851 int
reg_or_nonsymb_mem_operand(op,mode)852 reg_or_nonsymb_mem_operand (op, mode)
853 register rtx op;
854 enum machine_mode mode;
855 {
856 if (register_operand (op, mode))
857 return 1;
858
859 if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
860 return 1;
861
862 return 0;
863 }
864
865 int
splittable_symbolic_memory_operand(op,mode)866 splittable_symbolic_memory_operand (op, mode)
867 rtx op;
868 enum machine_mode mode ATTRIBUTE_UNUSED;
869 {
870 if (GET_CODE (op) != MEM)
871 return 0;
872 if (! symbolic_operand (XEXP (op, 0), Pmode))
873 return 0;
874 return 1;
875 }
876
877 int
splittable_immediate_memory_operand(op,mode)878 splittable_immediate_memory_operand (op, mode)
879 rtx op;
880 enum machine_mode mode ATTRIBUTE_UNUSED;
881 {
882 if (GET_CODE (op) != MEM)
883 return 0;
884 if (! immediate_operand (XEXP (op, 0), Pmode))
885 return 0;
886 return 1;
887 }
888
889 /* Return truth value of whether OP is EQ or NE. */
890
891 int
eq_or_neq(op,mode)892 eq_or_neq (op, mode)
893 rtx op;
894 enum machine_mode mode ATTRIBUTE_UNUSED;
895 {
896 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
897 }
898
899 /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
900 or LTU for non-floating-point. We handle those specially. */
901
902 int
normal_comp_operator(op,mode)903 normal_comp_operator (op, mode)
904 rtx op;
905 enum machine_mode mode ATTRIBUTE_UNUSED;
906 {
907 enum rtx_code code = GET_CODE (op);
908
909 if (GET_RTX_CLASS (code) != '<')
910 return 0;
911
912 if (GET_MODE (XEXP (op, 0)) == CCFPmode
913 || GET_MODE (XEXP (op, 0)) == CCFPEmode)
914 return 1;
915
916 return (code != NE && code != EQ && code != GEU && code != LTU);
917 }
918
919 /* Return 1 if this is a comparison operator. This allows the use of
920 MATCH_OPERATOR to recognize all the branch insns. */
921
922 int
noov_compare_op(op,mode)923 noov_compare_op (op, mode)
924 register rtx op;
925 enum machine_mode mode ATTRIBUTE_UNUSED;
926 {
927 enum rtx_code code = GET_CODE (op);
928
929 if (GET_RTX_CLASS (code) != '<')
930 return 0;
931
932 if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode
933 || GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
934 /* These are the only branches which work with CC_NOOVmode. */
935 return (code == EQ || code == NE || code == GE || code == LT);
936 return 1;
937 }
938
939 /* Return 1 if this is a 64-bit comparison operator. This allows the use of
940 MATCH_OPERATOR to recognize all the branch insns. */
941
942 int
noov_compare64_op(op,mode)943 noov_compare64_op (op, mode)
944 register rtx op;
945 enum machine_mode mode ATTRIBUTE_UNUSED;
946 {
947 enum rtx_code code = GET_CODE (op);
948
949 if (! TARGET_V9)
950 return 0;
951
952 if (GET_RTX_CLASS (code) != '<')
953 return 0;
954
955 if (GET_MODE (XEXP (op, 0)) == CCX_NOOVmode)
956 /* These are the only branches which work with CCX_NOOVmode. */
957 return (code == EQ || code == NE || code == GE || code == LT);
958 return (GET_MODE (XEXP (op, 0)) == CCXmode);
959 }
960
961 /* Nonzero if OP is a comparison operator suitable for use in v9
962 conditional move or branch on register contents instructions. */
963
964 int
v9_regcmp_op(op,mode)965 v9_regcmp_op (op, mode)
966 register rtx op;
967 enum machine_mode mode ATTRIBUTE_UNUSED;
968 {
969 enum rtx_code code = GET_CODE (op);
970
971 if (GET_RTX_CLASS (code) != '<')
972 return 0;
973
974 return v9_regcmp_p (code);
975 }
976
977 /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */
978
979 int
extend_op(op,mode)980 extend_op (op, mode)
981 rtx op;
982 enum machine_mode mode ATTRIBUTE_UNUSED;
983 {
984 return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
985 }
986
987 /* Return nonzero if OP is an operator of mode MODE which can set
988 the condition codes explicitly. We do not include PLUS and MINUS
989 because these require CC_NOOVmode, which we handle explicitly. */
990
991 int
cc_arithop(op,mode)992 cc_arithop (op, mode)
993 rtx op;
994 enum machine_mode mode ATTRIBUTE_UNUSED;
995 {
996 if (GET_CODE (op) == AND
997 || GET_CODE (op) == IOR
998 || GET_CODE (op) == XOR)
999 return 1;
1000
1001 return 0;
1002 }
1003
1004 /* Return nonzero if OP is an operator of mode MODE which can bitwise
1005 complement its second operand and set the condition codes explicitly. */
1006
1007 int
cc_arithopn(op,mode)1008 cc_arithopn (op, mode)
1009 rtx op;
1010 enum machine_mode mode ATTRIBUTE_UNUSED;
1011 {
1012 /* XOR is not here because combine canonicalizes (xor (not ...) ...)
1013 and (xor ... (not ...)) to (not (xor ...)). */
1014 return (GET_CODE (op) == AND
1015 || GET_CODE (op) == IOR);
1016 }
1017
1018 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1019 signed 13 bit immediate field. This is an acceptable SImode operand for
1020 most 3 address instructions. */
1021
1022 int
arith_operand(op,mode)1023 arith_operand (op, mode)
1024 rtx op;
1025 enum machine_mode mode;
1026 {
1027 if (register_operand (op, mode))
1028 return 1;
1029 if (GET_CODE (op) != CONST_INT)
1030 return 0;
1031 return SMALL_INT32 (op);
1032 }
1033
1034 /* Return true if OP is a constant 4096 */
1035
1036 int
arith_4096_operand(op,mode)1037 arith_4096_operand (op, mode)
1038 rtx op;
1039 enum machine_mode mode ATTRIBUTE_UNUSED;
1040 {
1041 if (GET_CODE (op) != CONST_INT)
1042 return 0;
1043 else
1044 return INTVAL (op) == 4096;
1045 }
1046
1047 /* Return true if OP is suitable as second operand for add/sub */
1048
1049 int
arith_add_operand(op,mode)1050 arith_add_operand (op, mode)
1051 rtx op;
1052 enum machine_mode mode;
1053 {
1054 return arith_operand (op, mode) || arith_4096_operand (op, mode);
1055 }
1056
1057 /* Return true if OP is a CONST_INT or a CONST_DOUBLE which can fit in the
1058 immediate field of OR and XOR instructions. Used for 64-bit
1059 constant formation patterns. */
1060 int
const64_operand(op,mode)1061 const64_operand (op, mode)
1062 rtx op;
1063 enum machine_mode mode ATTRIBUTE_UNUSED;
1064 {
1065 return ((GET_CODE (op) == CONST_INT
1066 && SPARC_SIMM13_P (INTVAL (op)))
1067 #if HOST_BITS_PER_WIDE_INT != 64
1068 || (GET_CODE (op) == CONST_DOUBLE
1069 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1070 && (CONST_DOUBLE_HIGH (op) ==
1071 ((CONST_DOUBLE_LOW (op) & 0x80000000) != 0 ?
1072 (HOST_WIDE_INT)-1 : 0)))
1073 #endif
1074 );
1075 }
1076
1077 /* The same, but only for sethi instructions. */
1078 int
const64_high_operand(op,mode)1079 const64_high_operand (op, mode)
1080 rtx op;
1081 enum machine_mode mode;
1082 {
1083 return ((GET_CODE (op) == CONST_INT
1084 && (INTVAL (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1085 && SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1086 )
1087 || (GET_CODE (op) == CONST_DOUBLE
1088 && CONST_DOUBLE_HIGH (op) == 0
1089 && (CONST_DOUBLE_LOW (op) & ~(HOST_WIDE_INT)0x3ff) != 0
1090 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op))));
1091 }
1092
1093 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1094 signed 11 bit immediate field. This is an acceptable SImode operand for
1095 the movcc instructions. */
1096
1097 int
arith11_operand(op,mode)1098 arith11_operand (op, mode)
1099 rtx op;
1100 enum machine_mode mode;
1101 {
1102 return (register_operand (op, mode)
1103 || (GET_CODE (op) == CONST_INT && SPARC_SIMM11_P (INTVAL (op))));
1104 }
1105
1106 /* Return true if OP is a register, or is a CONST_INT that can fit in a
1107 signed 10 bit immediate field. This is an acceptable SImode operand for
1108 the movrcc instructions. */
1109
1110 int
arith10_operand(op,mode)1111 arith10_operand (op, mode)
1112 rtx op;
1113 enum machine_mode mode;
1114 {
1115 return (register_operand (op, mode)
1116 || (GET_CODE (op) == CONST_INT && SPARC_SIMM10_P (INTVAL (op))));
1117 }
1118
1119 /* Return true if OP is a register, is a CONST_INT that fits in a 13 bit
1120 immediate field, or is a CONST_DOUBLE whose both parts fit in a 13 bit
1121 immediate field.
1122 v9: Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1123 can fit in a 13 bit immediate field. This is an acceptable DImode operand
1124 for most 3 address instructions. */
1125
1126 int
arith_double_operand(op,mode)1127 arith_double_operand (op, mode)
1128 rtx op;
1129 enum machine_mode mode;
1130 {
1131 return (register_operand (op, mode)
1132 || (GET_CODE (op) == CONST_INT && SMALL_INT (op))
1133 || (! TARGET_ARCH64
1134 && GET_CODE (op) == CONST_DOUBLE
1135 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1136 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_HIGH (op) + 0x1000) < 0x2000)
1137 || (TARGET_ARCH64
1138 && GET_CODE (op) == CONST_DOUBLE
1139 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
1140 && ((CONST_DOUBLE_HIGH (op) == -1
1141 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
1142 || (CONST_DOUBLE_HIGH (op) == 0
1143 && (CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
1144 }
1145
1146 /* Return true if OP is a constant 4096 for DImode on ARCH64 */
1147
1148 int
arith_double_4096_operand(op,mode)1149 arith_double_4096_operand (op, mode)
1150 rtx op;
1151 enum machine_mode mode ATTRIBUTE_UNUSED;
1152 {
1153 return (TARGET_ARCH64 &&
1154 ((GET_CODE (op) == CONST_INT && INTVAL (op) == 4096) ||
1155 (GET_CODE (op) == CONST_DOUBLE &&
1156 CONST_DOUBLE_LOW (op) == 4096 &&
1157 CONST_DOUBLE_HIGH (op) == 0)));
1158 }
1159
1160 /* Return true if OP is suitable as second operand for add/sub in DImode */
1161
1162 int
arith_double_add_operand(op,mode)1163 arith_double_add_operand (op, mode)
1164 rtx op;
1165 enum machine_mode mode;
1166 {
1167 return arith_double_operand (op, mode) || arith_double_4096_operand (op, mode);
1168 }
1169
1170 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1171 can fit in an 11 bit immediate field. This is an acceptable DImode
1172 operand for the movcc instructions. */
1173 /* ??? Replace with arith11_operand? */
1174
1175 int
arith11_double_operand(op,mode)1176 arith11_double_operand (op, mode)
1177 rtx op;
1178 enum machine_mode mode;
1179 {
1180 return (register_operand (op, mode)
1181 || (GET_CODE (op) == CONST_DOUBLE
1182 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1183 && (unsigned HOST_WIDE_INT) (CONST_DOUBLE_LOW (op) + 0x400) < 0x800
1184 && ((CONST_DOUBLE_HIGH (op) == -1
1185 && (CONST_DOUBLE_LOW (op) & 0x400) == 0x400)
1186 || (CONST_DOUBLE_HIGH (op) == 0
1187 && (CONST_DOUBLE_LOW (op) & 0x400) == 0)))
1188 || (GET_CODE (op) == CONST_INT
1189 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1190 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x400) < 0x800));
1191 }
1192
1193 /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
1194 can fit in an 10 bit immediate field. This is an acceptable DImode
1195 operand for the movrcc instructions. */
1196 /* ??? Replace with arith10_operand? */
1197
1198 int
arith10_double_operand(op,mode)1199 arith10_double_operand (op, mode)
1200 rtx op;
1201 enum machine_mode mode;
1202 {
1203 return (register_operand (op, mode)
1204 || (GET_CODE (op) == CONST_DOUBLE
1205 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1206 && (unsigned) (CONST_DOUBLE_LOW (op) + 0x200) < 0x400
1207 && ((CONST_DOUBLE_HIGH (op) == -1
1208 && (CONST_DOUBLE_LOW (op) & 0x200) == 0x200)
1209 || (CONST_DOUBLE_HIGH (op) == 0
1210 && (CONST_DOUBLE_LOW (op) & 0x200) == 0)))
1211 || (GET_CODE (op) == CONST_INT
1212 && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
1213 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x200) < 0x400));
1214 }
1215
1216 /* Return truth value of whether OP is an integer which fits the
1217 range constraining immediate operands in most three-address insns,
1218 which have a 13 bit immediate field. */
1219
1220 int
small_int(op,mode)1221 small_int (op, mode)
1222 rtx op;
1223 enum machine_mode mode ATTRIBUTE_UNUSED;
1224 {
1225 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
1226 }
1227
1228 int
small_int_or_double(op,mode)1229 small_int_or_double (op, mode)
1230 rtx op;
1231 enum machine_mode mode ATTRIBUTE_UNUSED;
1232 {
1233 return ((GET_CODE (op) == CONST_INT && SMALL_INT (op))
1234 || (GET_CODE (op) == CONST_DOUBLE
1235 && CONST_DOUBLE_HIGH (op) == 0
1236 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))));
1237 }
1238
1239 /* Recognize operand values for the umul instruction. That instruction sign
1240 extends immediate values just like all other sparc instructions, but
1241 interprets the extended result as an unsigned number. */
1242
1243 int
uns_small_int(op,mode)1244 uns_small_int (op, mode)
1245 rtx op;
1246 enum machine_mode mode ATTRIBUTE_UNUSED;
1247 {
1248 #if HOST_BITS_PER_WIDE_INT > 32
1249 /* All allowed constants will fit a CONST_INT. */
1250 return (GET_CODE (op) == CONST_INT
1251 && ((INTVAL (op) >= 0 && INTVAL (op) < 0x1000)
1252 || (INTVAL (op) >= 0xFFFFF000
1253 && INTVAL (op) <= 0xFFFFFFFF)));
1254 #else
1255 return ((GET_CODE (op) == CONST_INT && (unsigned) INTVAL (op) < 0x1000)
1256 || (GET_CODE (op) == CONST_DOUBLE
1257 && CONST_DOUBLE_HIGH (op) == 0
1258 && (unsigned) CONST_DOUBLE_LOW (op) - 0xFFFFF000 < 0x1000));
1259 #endif
1260 }
1261
1262 int
uns_arith_operand(op,mode)1263 uns_arith_operand (op, mode)
1264 rtx op;
1265 enum machine_mode mode;
1266 {
1267 return register_operand (op, mode) || uns_small_int (op, mode);
1268 }
1269
1270 /* Return truth value of statement that OP is a call-clobbered register. */
1271 int
clobbered_register(op,mode)1272 clobbered_register (op, mode)
1273 rtx op;
1274 enum machine_mode mode ATTRIBUTE_UNUSED;
1275 {
1276 return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
1277 }
1278
1279 /* Return 1 if OP is a valid operand for the source of a move insn. */
1280
1281 int
input_operand(op,mode)1282 input_operand (op, mode)
1283 rtx op;
1284 enum machine_mode mode;
1285 {
1286 /* If both modes are non-void they must be the same. */
1287 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1288 return 0;
1289
1290 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
1291 if (GET_CODE (op) == CONST && GET_CODE (XEXP (op, 0)) == CONSTANT_P_RTX)
1292 return 1;
1293
1294 /* Allow any one instruction integer constant, and all CONST_INT
1295 variants when we are working in DImode and !arch64. */
1296 if (GET_MODE_CLASS (mode) == MODE_INT
1297 && ((GET_CODE (op) == CONST_INT
1298 && (SPARC_SETHI_P (INTVAL (op) & GET_MODE_MASK (mode))
1299 || SPARC_SIMM13_P (INTVAL (op))
1300 || (mode == DImode
1301 && ! TARGET_ARCH64)))
1302 || (TARGET_ARCH64
1303 && GET_CODE (op) == CONST_DOUBLE
1304 && ((CONST_DOUBLE_HIGH (op) == 0
1305 && SPARC_SETHI_P (CONST_DOUBLE_LOW (op)))
1306 ||
1307 #if HOST_BITS_PER_WIDE_INT == 64
1308 (CONST_DOUBLE_HIGH (op) == 0
1309 && SPARC_SIMM13_P (CONST_DOUBLE_LOW (op)))
1310 #else
1311 (SPARC_SIMM13_P (CONST_DOUBLE_LOW (op))
1312 && (((CONST_DOUBLE_LOW (op) & 0x80000000) == 0
1313 && CONST_DOUBLE_HIGH (op) == 0)
1314 || (CONST_DOUBLE_HIGH (op) == -1
1315 && CONST_DOUBLE_LOW (op) & 0x80000000) != 0))
1316 #endif
1317 ))))
1318 return 1;
1319
1320 /* If !arch64 and this is a DImode const, allow it so that
1321 the splits can be generated. */
1322 if (! TARGET_ARCH64
1323 && mode == DImode
1324 && GET_CODE (op) == CONST_DOUBLE)
1325 return 1;
1326
1327 if (register_operand (op, mode))
1328 return 1;
1329
1330 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1331 && GET_CODE (op) == CONST_DOUBLE)
1332 return 1;
1333
1334 /* If this is a SUBREG, look inside so that we handle
1335 paradoxical ones. */
1336 if (GET_CODE (op) == SUBREG)
1337 op = SUBREG_REG (op);
1338
1339 /* Check for valid MEM forms. */
1340 if (GET_CODE (op) == MEM)
1341 {
1342 rtx inside = XEXP (op, 0);
1343
1344 if (GET_CODE (inside) == LO_SUM)
1345 {
1346 /* We can't allow these because all of the splits
1347 (eventually as they trickle down into DFmode
1348 splits) require offsettable memory references. */
1349 if (! TARGET_V9
1350 && GET_MODE (op) == TFmode)
1351 return 0;
1352
1353 return (register_operand (XEXP (inside, 0), Pmode)
1354 && CONSTANT_P (XEXP (inside, 1)));
1355 }
1356 return memory_address_p (mode, inside);
1357 }
1358
1359 return 0;
1360 }
1361
1362 /* Return 1 if OP is valid for the lhs of a compare insn. */
1363
1364 int
compare_operand(op,mode)1365 compare_operand (op, mode)
1366 rtx op;
1367 enum machine_mode mode;
1368 {
1369 if (GET_CODE (op) == ZERO_EXTRACT)
1370 return (register_operand (XEXP (op, 0), mode)
1371 && small_int_or_double (XEXP (op, 1), mode)
1372 && small_int_or_double (XEXP (op, 2), mode)
1373 /* This matches cmp_zero_extract. */
1374 && ((mode == SImode
1375 && ((GET_CODE (XEXP (op, 2)) == CONST_INT
1376 && INTVAL (XEXP (op, 2)) > 19)
1377 || (GET_CODE (XEXP (op, 2)) == CONST_DOUBLE
1378 && CONST_DOUBLE_LOW (XEXP (op, 2)) > 19)))
1379 /* This matches cmp_zero_extract_sp64. */
1380 || (mode == DImode
1381 && TARGET_ARCH64
1382 && ((GET_CODE (XEXP (op, 2)) == CONST_INT
1383 && INTVAL (XEXP (op, 2)) > 51)
1384 || (GET_CODE (XEXP (op, 2)) == CONST_DOUBLE
1385 && CONST_DOUBLE_LOW (XEXP (op, 2)) > 51)))));
1386 else
1387 return register_operand (op, mode);
1388 }
1389
1390
1391 /* We know it can't be done in one insn when we get here,
1392 the movsi expander guarentees this. */
1393 void
sparc_emit_set_const32(op0,op1)1394 sparc_emit_set_const32 (op0, op1)
1395 rtx op0;
1396 rtx op1;
1397 {
1398 enum machine_mode mode = GET_MODE (op0);
1399 rtx temp;
1400
1401 if (GET_CODE (op1) == CONST_INT)
1402 {
1403 HOST_WIDE_INT value = INTVAL (op1);
1404
1405 if (SPARC_SETHI_P (value & GET_MODE_MASK (mode))
1406 || SPARC_SIMM13_P (value))
1407 abort ();
1408 }
1409
1410 /* Full 2-insn decomposition is needed. */
1411 if (reload_in_progress || reload_completed)
1412 temp = op0;
1413 else
1414 temp = gen_reg_rtx (mode);
1415
1416 if (GET_CODE (op1) == CONST_INT)
1417 {
1418 /* Emit them as real moves instead of a HIGH/LO_SUM,
1419 this way CSE can see everything and reuse intermediate
1420 values if it wants. */
1421 if (TARGET_ARCH64
1422 && HOST_BITS_PER_WIDE_INT != 64
1423 && (INTVAL (op1) & 0x80000000) != 0)
1424 emit_insn (gen_rtx_SET
1425 (VOIDmode, temp,
1426 immed_double_const (INTVAL (op1) & ~(HOST_WIDE_INT)0x3ff,
1427 0, DImode)));
1428 else
1429 emit_insn (gen_rtx_SET (VOIDmode, temp,
1430 GEN_INT (INTVAL (op1)
1431 & ~(HOST_WIDE_INT)0x3ff)));
1432
1433 emit_insn (gen_rtx_SET (VOIDmode,
1434 op0,
1435 gen_rtx_IOR (mode, temp,
1436 GEN_INT (INTVAL (op1) & 0x3ff))));
1437 }
1438 else
1439 {
1440 /* A symbol, emit in the traditional way. */
1441 emit_insn (gen_rtx_SET (VOIDmode, temp,
1442 gen_rtx_HIGH (mode, op1)));
1443 emit_insn (gen_rtx_SET (VOIDmode,
1444 op0, gen_rtx_LO_SUM (mode, temp, op1)));
1445
1446 }
1447 }
1448
1449
1450 /* SPARC-v9 code-model support. */
1451 void
sparc_emit_set_symbolic_const64(op0,op1,temp1)1452 sparc_emit_set_symbolic_const64 (op0, op1, temp1)
1453 rtx op0;
1454 rtx op1;
1455 rtx temp1;
1456 {
1457 rtx ti_temp1 = 0;
1458
1459 if (temp1 && GET_MODE (temp1) == TImode)
1460 {
1461 ti_temp1 = temp1;
1462 temp1 = gen_rtx_REG (DImode, REGNO (temp1));
1463 }
1464
1465 switch (sparc_cmodel)
1466 {
1467 case CM_MEDLOW:
1468 /* The range spanned by all instructions in the object is less
1469 than 2^31 bytes (2GB) and the distance from any instruction
1470 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1471 than 2^31 bytes (2GB).
1472
1473 The executable must be in the low 4TB of the virtual address
1474 space.
1475
1476 sethi %hi(symbol), %temp
1477 or %temp, %lo(symbol), %reg */
1478 emit_insn (gen_rtx_SET (VOIDmode, temp1, gen_rtx_HIGH (DImode, op1)));
1479 emit_insn (gen_rtx_SET (VOIDmode, op0, gen_rtx_LO_SUM (DImode, temp1, op1)));
1480 break;
1481
1482 case CM_MEDMID:
1483 /* The range spanned by all instructions in the object is less
1484 than 2^31 bytes (2GB) and the distance from any instruction
1485 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1486 than 2^31 bytes (2GB).
1487
1488 The executable must be in the low 16TB of the virtual address
1489 space.
1490
1491 sethi %h44(symbol), %temp1
1492 or %temp1, %m44(symbol), %temp2
1493 sllx %temp2, 12, %temp3
1494 or %temp3, %l44(symbol), %reg */
1495 emit_insn (gen_seth44 (op0, op1));
1496 emit_insn (gen_setm44 (op0, op0, op1));
1497 emit_insn (gen_rtx_SET (VOIDmode, temp1,
1498 gen_rtx_ASHIFT (DImode, op0, GEN_INT (12))));
1499 emit_insn (gen_setl44 (op0, temp1, op1));
1500 break;
1501
1502 case CM_MEDANY:
1503 /* The range spanned by all instructions in the object is less
1504 than 2^31 bytes (2GB) and the distance from any instruction
1505 to the location of the label _GLOBAL_OFFSET_TABLE_ is less
1506 than 2^31 bytes (2GB).
1507
1508 The executable can be placed anywhere in the virtual address
1509 space.
1510
1511 sethi %hh(symbol), %temp1
1512 sethi %lm(symbol), %temp2
1513 or %temp1, %hm(symbol), %temp3
1514 or %temp2, %lo(symbol), %temp4
1515 sllx %temp3, 32, %temp5
1516 or %temp4, %temp5, %reg */
1517
1518 /* It is possible that one of the registers we got for operands[2]
1519 might coincide with that of operands[0] (which is why we made
1520 it TImode). Pick the other one to use as our scratch. */
1521 if (rtx_equal_p (temp1, op0))
1522 {
1523 if (ti_temp1)
1524 temp1 = gen_rtx_REG (DImode, REGNO (temp1) + 1);
1525 else
1526 abort();
1527 }
1528
1529 emit_insn (gen_sethh (op0, op1));
1530 emit_insn (gen_setlm (temp1, op1));
1531 emit_insn (gen_sethm (op0, op0, op1));
1532 emit_insn (gen_rtx_SET (VOIDmode, op0,
1533 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1534 emit_insn (gen_rtx_SET (VOIDmode, op0,
1535 gen_rtx_PLUS (DImode, op0, temp1)));
1536 emit_insn (gen_setlo (op0, op0, op1));
1537 break;
1538
1539 case CM_EMBMEDANY:
1540 /* Old old old backwards compatibility kruft here.
1541 Essentially it is MEDLOW with a fixed 64-bit
1542 virtual base added to all data segment addresses.
1543 Text-segment stuff is computed like MEDANY, we can't
1544 reuse the code above because the relocation knobs
1545 look different.
1546
1547 Data segment: sethi %hi(symbol), %temp1
1548 or %temp1, %lo(symbol), %temp2
1549 add %temp2, EMBMEDANY_BASE_REG, %reg
1550
1551 Text segment: sethi %uhi(symbol), %temp1
1552 sethi %hi(symbol), %temp2
1553 or %temp1, %ulo(symbol), %temp3
1554 or %temp2, %lo(symbol), %temp4
1555 sllx %temp3, 32, %temp5
1556 or %temp4, %temp5, %reg */
1557 if (data_segment_operand (op1, GET_MODE (op1)))
1558 {
1559 emit_insn (gen_embmedany_sethi (temp1, op1));
1560 emit_insn (gen_embmedany_brsum (op0, temp1));
1561 emit_insn (gen_embmedany_losum (op0, op0, op1));
1562 }
1563 else
1564 {
1565 /* It is possible that one of the registers we got for operands[2]
1566 might coincide with that of operands[0] (which is why we made
1567 it TImode). Pick the other one to use as our scratch. */
1568 if (rtx_equal_p (temp1, op0))
1569 {
1570 if (ti_temp1)
1571 temp1 = gen_rtx_REG (DImode, REGNO (temp1) + 1);
1572 else
1573 abort();
1574 }
1575
1576 emit_insn (gen_embmedany_textuhi (op0, op1));
1577 emit_insn (gen_embmedany_texthi (temp1, op1));
1578 emit_insn (gen_embmedany_textulo (op0, op0, op1));
1579 emit_insn (gen_rtx_SET (VOIDmode, op0,
1580 gen_rtx_ASHIFT (DImode, op0, GEN_INT (32))));
1581 emit_insn (gen_rtx_SET (VOIDmode, op0,
1582 gen_rtx_PLUS (DImode, op0, temp1)));
1583 emit_insn (gen_embmedany_textlo (op0, op0, op1));
1584 }
1585 break;
1586
1587 default:
1588 abort();
1589 }
1590 }
1591
1592 /* These avoid problems when cross compiling. If we do not
1593 go through all this hair then the optimizer will see
1594 invalid REG_EQUAL notes or in some cases none at all. */
1595 static void sparc_emit_set_safe_HIGH64 PARAMS ((rtx, HOST_WIDE_INT));
1596 static rtx gen_safe_SET64 PARAMS ((rtx, HOST_WIDE_INT));
1597 static rtx gen_safe_OR64 PARAMS ((rtx, HOST_WIDE_INT));
1598 static rtx gen_safe_XOR64 PARAMS ((rtx, HOST_WIDE_INT));
1599
1600 #if HOST_BITS_PER_WIDE_INT == 64
1601 #define GEN_HIGHINT64(__x) GEN_INT ((__x) & ~(HOST_WIDE_INT)0x3ff)
1602 #define GEN_INT64(__x) GEN_INT (__x)
1603 #else
1604 #define GEN_HIGHINT64(__x) \
1605 immed_double_const ((__x) & ~(HOST_WIDE_INT)0x3ff, 0, DImode)
1606 #define GEN_INT64(__x) \
1607 immed_double_const ((__x) & 0xffffffff, \
1608 ((__x) & 0x80000000 ? -1 : 0), DImode)
1609 #endif
1610
1611 /* The optimizer is not to assume anything about exactly
1612 which bits are set for a HIGH, they are unspecified.
1613 Unfortunately this leads to many missed optimizations
1614 during CSE. We mask out the non-HIGH bits, and matches
1615 a plain movdi, to alleviate this problem. */
1616 static void
sparc_emit_set_safe_HIGH64(dest,val)1617 sparc_emit_set_safe_HIGH64 (dest, val)
1618 rtx dest;
1619 HOST_WIDE_INT val;
1620 {
1621 emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_HIGHINT64 (val)));
1622 }
1623
1624 static rtx
gen_safe_SET64(dest,val)1625 gen_safe_SET64 (dest, val)
1626 rtx dest;
1627 HOST_WIDE_INT val;
1628 {
1629 return gen_rtx_SET (VOIDmode, dest, GEN_INT64 (val));
1630 }
1631
1632 static rtx
gen_safe_OR64(src,val)1633 gen_safe_OR64 (src, val)
1634 rtx src;
1635 HOST_WIDE_INT val;
1636 {
1637 return gen_rtx_IOR (DImode, src, GEN_INT64 (val));
1638 }
1639
1640 static rtx
gen_safe_XOR64(src,val)1641 gen_safe_XOR64 (src, val)
1642 rtx src;
1643 HOST_WIDE_INT val;
1644 {
1645 return gen_rtx_XOR (DImode, src, GEN_INT64 (val));
1646 }
1647
1648 /* Worker routines for 64-bit constant formation on arch64.
1649 One of the key things to be doing in these emissions is
1650 to create as many temp REGs as possible. This makes it
1651 possible for half-built constants to be used later when
1652 such values are similar to something required later on.
1653 Without doing this, the optimizer cannot see such
1654 opportunities. */
1655
1656 static void sparc_emit_set_const64_quick1
1657 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, int));
1658
1659 static void
sparc_emit_set_const64_quick1(op0,temp,low_bits,is_neg)1660 sparc_emit_set_const64_quick1 (op0, temp, low_bits, is_neg)
1661 rtx op0;
1662 rtx temp;
1663 unsigned HOST_WIDE_INT low_bits;
1664 int is_neg;
1665 {
1666 unsigned HOST_WIDE_INT high_bits;
1667
1668 if (is_neg)
1669 high_bits = (~low_bits) & 0xffffffff;
1670 else
1671 high_bits = low_bits;
1672
1673 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1674 if (!is_neg)
1675 {
1676 emit_insn (gen_rtx_SET (VOIDmode, op0,
1677 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1678 }
1679 else
1680 {
1681 /* If we are XOR'ing with -1, then we should emit a one's complement
1682 instead. This way the combiner will notice logical operations
1683 such as ANDN later on and substitute. */
1684 if ((low_bits & 0x3ff) == 0x3ff)
1685 {
1686 emit_insn (gen_rtx_SET (VOIDmode, op0,
1687 gen_rtx_NOT (DImode, temp)));
1688 }
1689 else
1690 {
1691 emit_insn (gen_rtx_SET (VOIDmode, op0,
1692 gen_safe_XOR64 (temp,
1693 (-(HOST_WIDE_INT)0x400
1694 | (low_bits & 0x3ff)))));
1695 }
1696 }
1697 }
1698
1699 static void sparc_emit_set_const64_quick2
1700 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT,
1701 unsigned HOST_WIDE_INT, int));
1702
1703 static void
sparc_emit_set_const64_quick2(op0,temp,high_bits,low_immediate,shift_count)1704 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_immediate, shift_count)
1705 rtx op0;
1706 rtx temp;
1707 unsigned HOST_WIDE_INT high_bits;
1708 unsigned HOST_WIDE_INT low_immediate;
1709 int shift_count;
1710 {
1711 rtx temp2 = op0;
1712
1713 if ((high_bits & 0xfffffc00) != 0)
1714 {
1715 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1716 if ((high_bits & ~0xfffffc00) != 0)
1717 emit_insn (gen_rtx_SET (VOIDmode, op0,
1718 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1719 else
1720 temp2 = temp;
1721 }
1722 else
1723 {
1724 emit_insn (gen_safe_SET64 (temp, high_bits));
1725 temp2 = temp;
1726 }
1727
1728 /* Now shift it up into place. */
1729 emit_insn (gen_rtx_SET (VOIDmode, op0,
1730 gen_rtx_ASHIFT (DImode, temp2,
1731 GEN_INT (shift_count))));
1732
1733 /* If there is a low immediate part piece, finish up by
1734 putting that in as well. */
1735 if (low_immediate != 0)
1736 emit_insn (gen_rtx_SET (VOIDmode, op0,
1737 gen_safe_OR64 (op0, low_immediate)));
1738 }
1739
1740 static void sparc_emit_set_const64_longway
1741 PARAMS ((rtx, rtx, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1742
1743 /* Full 64-bit constant decomposition. Even though this is the
1744 'worst' case, we still optimize a few things away. */
1745 static void
sparc_emit_set_const64_longway(op0,temp,high_bits,low_bits)1746 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits)
1747 rtx op0;
1748 rtx temp;
1749 unsigned HOST_WIDE_INT high_bits;
1750 unsigned HOST_WIDE_INT low_bits;
1751 {
1752 rtx sub_temp;
1753
1754 if (reload_in_progress || reload_completed)
1755 sub_temp = op0;
1756 else
1757 sub_temp = gen_reg_rtx (DImode);
1758
1759 if ((high_bits & 0xfffffc00) != 0)
1760 {
1761 sparc_emit_set_safe_HIGH64 (temp, high_bits);
1762 if ((high_bits & ~0xfffffc00) != 0)
1763 emit_insn (gen_rtx_SET (VOIDmode,
1764 sub_temp,
1765 gen_safe_OR64 (temp, (high_bits & 0x3ff))));
1766 else
1767 sub_temp = temp;
1768 }
1769 else
1770 {
1771 emit_insn (gen_safe_SET64 (temp, high_bits));
1772 sub_temp = temp;
1773 }
1774
1775 if (!reload_in_progress && !reload_completed)
1776 {
1777 rtx temp2 = gen_reg_rtx (DImode);
1778 rtx temp3 = gen_reg_rtx (DImode);
1779 rtx temp4 = gen_reg_rtx (DImode);
1780
1781 emit_insn (gen_rtx_SET (VOIDmode, temp4,
1782 gen_rtx_ASHIFT (DImode, sub_temp,
1783 GEN_INT (32))));
1784
1785 sparc_emit_set_safe_HIGH64 (temp2, low_bits);
1786 if ((low_bits & ~0xfffffc00) != 0)
1787 {
1788 emit_insn (gen_rtx_SET (VOIDmode, temp3,
1789 gen_safe_OR64 (temp2, (low_bits & 0x3ff))));
1790 emit_insn (gen_rtx_SET (VOIDmode, op0,
1791 gen_rtx_PLUS (DImode, temp4, temp3)));
1792 }
1793 else
1794 {
1795 emit_insn (gen_rtx_SET (VOIDmode, op0,
1796 gen_rtx_PLUS (DImode, temp4, temp2)));
1797 }
1798 }
1799 else
1800 {
1801 rtx low1 = GEN_INT ((low_bits >> (32 - 12)) & 0xfff);
1802 rtx low2 = GEN_INT ((low_bits >> (32 - 12 - 12)) & 0xfff);
1803 rtx low3 = GEN_INT ((low_bits >> (32 - 12 - 12 - 8)) & 0x0ff);
1804 int to_shift = 12;
1805
1806 /* We are in the middle of reload, so this is really
1807 painful. However we do still make an attempt to
1808 avoid emitting truly stupid code. */
1809 if (low1 != const0_rtx)
1810 {
1811 emit_insn (gen_rtx_SET (VOIDmode, op0,
1812 gen_rtx_ASHIFT (DImode, sub_temp,
1813 GEN_INT (to_shift))));
1814 emit_insn (gen_rtx_SET (VOIDmode, op0,
1815 gen_rtx_IOR (DImode, op0, low1)));
1816 sub_temp = op0;
1817 to_shift = 12;
1818 }
1819 else
1820 {
1821 to_shift += 12;
1822 }
1823 if (low2 != const0_rtx)
1824 {
1825 emit_insn (gen_rtx_SET (VOIDmode, op0,
1826 gen_rtx_ASHIFT (DImode, sub_temp,
1827 GEN_INT (to_shift))));
1828 emit_insn (gen_rtx_SET (VOIDmode, op0,
1829 gen_rtx_IOR (DImode, op0, low2)));
1830 sub_temp = op0;
1831 to_shift = 8;
1832 }
1833 else
1834 {
1835 to_shift += 8;
1836 }
1837 emit_insn (gen_rtx_SET (VOIDmode, op0,
1838 gen_rtx_ASHIFT (DImode, sub_temp,
1839 GEN_INT (to_shift))));
1840 if (low3 != const0_rtx)
1841 emit_insn (gen_rtx_SET (VOIDmode, op0,
1842 gen_rtx_IOR (DImode, op0, low3)));
1843 /* phew... */
1844 }
1845 }
1846
1847 /* Analyze a 64-bit constant for certain properties. */
1848 static void analyze_64bit_constant
1849 PARAMS ((unsigned HOST_WIDE_INT,
1850 unsigned HOST_WIDE_INT,
1851 int *, int *, int *));
1852
1853 static void
analyze_64bit_constant(high_bits,low_bits,hbsp,lbsp,abbasp)1854 analyze_64bit_constant (high_bits, low_bits, hbsp, lbsp, abbasp)
1855 unsigned HOST_WIDE_INT high_bits, low_bits;
1856 int *hbsp, *lbsp, *abbasp;
1857 {
1858 int lowest_bit_set, highest_bit_set, all_bits_between_are_set;
1859 int i;
1860
1861 lowest_bit_set = highest_bit_set = -1;
1862 i = 0;
1863 do
1864 {
1865 if ((lowest_bit_set == -1)
1866 && ((low_bits >> i) & 1))
1867 lowest_bit_set = i;
1868 if ((highest_bit_set == -1)
1869 && ((high_bits >> (32 - i - 1)) & 1))
1870 highest_bit_set = (64 - i - 1);
1871 }
1872 while (++i < 32
1873 && ((highest_bit_set == -1)
1874 || (lowest_bit_set == -1)));
1875 if (i == 32)
1876 {
1877 i = 0;
1878 do
1879 {
1880 if ((lowest_bit_set == -1)
1881 && ((high_bits >> i) & 1))
1882 lowest_bit_set = i + 32;
1883 if ((highest_bit_set == -1)
1884 && ((low_bits >> (32 - i - 1)) & 1))
1885 highest_bit_set = 32 - i - 1;
1886 }
1887 while (++i < 32
1888 && ((highest_bit_set == -1)
1889 || (lowest_bit_set == -1)));
1890 }
1891 /* If there are no bits set this should have gone out
1892 as one instruction! */
1893 if (lowest_bit_set == -1
1894 || highest_bit_set == -1)
1895 abort ();
1896 all_bits_between_are_set = 1;
1897 for (i = lowest_bit_set; i <= highest_bit_set; i++)
1898 {
1899 if (i < 32)
1900 {
1901 if ((low_bits & (1 << i)) != 0)
1902 continue;
1903 }
1904 else
1905 {
1906 if ((high_bits & (1 << (i - 32))) != 0)
1907 continue;
1908 }
1909 all_bits_between_are_set = 0;
1910 break;
1911 }
1912 *hbsp = highest_bit_set;
1913 *lbsp = lowest_bit_set;
1914 *abbasp = all_bits_between_are_set;
1915 }
1916
1917 static int const64_is_2insns
1918 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT));
1919
1920 static int
const64_is_2insns(high_bits,low_bits)1921 const64_is_2insns (high_bits, low_bits)
1922 unsigned HOST_WIDE_INT high_bits, low_bits;
1923 {
1924 int highest_bit_set, lowest_bit_set, all_bits_between_are_set;
1925
1926 if (high_bits == 0
1927 || high_bits == 0xffffffff)
1928 return 1;
1929
1930 analyze_64bit_constant (high_bits, low_bits,
1931 &highest_bit_set, &lowest_bit_set,
1932 &all_bits_between_are_set);
1933
1934 if ((highest_bit_set == 63
1935 || lowest_bit_set == 0)
1936 && all_bits_between_are_set != 0)
1937 return 1;
1938
1939 if ((highest_bit_set - lowest_bit_set) < 21)
1940 return 1;
1941
1942 return 0;
1943 }
1944
1945 static unsigned HOST_WIDE_INT create_simple_focus_bits
1946 PARAMS ((unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
1947 int, int));
1948
1949 static unsigned HOST_WIDE_INT
create_simple_focus_bits(high_bits,low_bits,lowest_bit_set,shift)1950 create_simple_focus_bits (high_bits, low_bits, lowest_bit_set, shift)
1951 unsigned HOST_WIDE_INT high_bits, low_bits;
1952 int lowest_bit_set, shift;
1953 {
1954 HOST_WIDE_INT hi, lo;
1955
1956 if (lowest_bit_set < 32)
1957 {
1958 lo = (low_bits >> lowest_bit_set) << shift;
1959 hi = ((high_bits << (32 - lowest_bit_set)) << shift);
1960 }
1961 else
1962 {
1963 lo = 0;
1964 hi = ((high_bits >> (lowest_bit_set - 32)) << shift);
1965 }
1966 if (hi & lo)
1967 abort ();
1968 return (hi | lo);
1969 }
1970
1971 /* Here we are sure to be arch64 and this is an integer constant
1972 being loaded into a register. Emit the most efficient
1973 insn sequence possible. Detection of all the 1-insn cases
1974 has been done already. */
1975 void
sparc_emit_set_const64(op0,op1)1976 sparc_emit_set_const64 (op0, op1)
1977 rtx op0;
1978 rtx op1;
1979 {
1980 unsigned HOST_WIDE_INT high_bits, low_bits;
1981 int lowest_bit_set, highest_bit_set;
1982 int all_bits_between_are_set;
1983 rtx temp;
1984
1985 /* Sanity check that we know what we are working with. */
1986 if (! TARGET_ARCH64)
1987 abort ();
1988
1989 if (GET_CODE (op0) != SUBREG)
1990 {
1991 if (GET_CODE (op0) != REG
1992 || (REGNO (op0) >= SPARC_FIRST_FP_REG
1993 && REGNO (op0) <= SPARC_LAST_V9_FP_REG))
1994 abort ();
1995 }
1996
1997 if (reload_in_progress || reload_completed)
1998 temp = op0;
1999 else
2000 temp = gen_reg_rtx (DImode);
2001
2002 if (GET_CODE (op1) != CONST_DOUBLE
2003 && GET_CODE (op1) != CONST_INT)
2004 {
2005 sparc_emit_set_symbolic_const64 (op0, op1, temp);
2006 return;
2007 }
2008
2009 if (GET_CODE (op1) == CONST_DOUBLE)
2010 {
2011 #if HOST_BITS_PER_WIDE_INT == 64
2012 high_bits = (CONST_DOUBLE_LOW (op1) >> 32) & 0xffffffff;
2013 low_bits = CONST_DOUBLE_LOW (op1) & 0xffffffff;
2014 #else
2015 high_bits = CONST_DOUBLE_HIGH (op1);
2016 low_bits = CONST_DOUBLE_LOW (op1);
2017 #endif
2018 }
2019 else
2020 {
2021 #if HOST_BITS_PER_WIDE_INT == 64
2022 high_bits = ((INTVAL (op1) >> 32) & 0xffffffff);
2023 low_bits = (INTVAL (op1) & 0xffffffff);
2024 #else
2025 high_bits = ((INTVAL (op1) < 0) ?
2026 0xffffffff :
2027 0x00000000);
2028 low_bits = INTVAL (op1);
2029 #endif
2030 }
2031
2032 /* low_bits bits 0 --> 31
2033 high_bits bits 32 --> 63 */
2034
2035 analyze_64bit_constant (high_bits, low_bits,
2036 &highest_bit_set, &lowest_bit_set,
2037 &all_bits_between_are_set);
2038
2039 /* First try for a 2-insn sequence. */
2040
2041 /* These situations are preferred because the optimizer can
2042 * do more things with them:
2043 * 1) mov -1, %reg
2044 * sllx %reg, shift, %reg
2045 * 2) mov -1, %reg
2046 * srlx %reg, shift, %reg
2047 * 3) mov some_small_const, %reg
2048 * sllx %reg, shift, %reg
2049 */
2050 if (((highest_bit_set == 63
2051 || lowest_bit_set == 0)
2052 && all_bits_between_are_set != 0)
2053 || ((highest_bit_set - lowest_bit_set) < 12))
2054 {
2055 HOST_WIDE_INT the_const = -1;
2056 int shift = lowest_bit_set;
2057
2058 if ((highest_bit_set != 63
2059 && lowest_bit_set != 0)
2060 || all_bits_between_are_set == 0)
2061 {
2062 the_const =
2063 create_simple_focus_bits (high_bits, low_bits,
2064 lowest_bit_set, 0);
2065 }
2066 else if (lowest_bit_set == 0)
2067 shift = -(63 - highest_bit_set);
2068
2069 if (! SPARC_SIMM13_P (the_const))
2070 abort ();
2071
2072 emit_insn (gen_safe_SET64 (temp, the_const));
2073 if (shift > 0)
2074 emit_insn (gen_rtx_SET (VOIDmode,
2075 op0,
2076 gen_rtx_ASHIFT (DImode,
2077 temp,
2078 GEN_INT (shift))));
2079 else if (shift < 0)
2080 emit_insn (gen_rtx_SET (VOIDmode,
2081 op0,
2082 gen_rtx_LSHIFTRT (DImode,
2083 temp,
2084 GEN_INT (-shift))));
2085 else
2086 abort ();
2087 return;
2088 }
2089
2090 /* Now a range of 22 or less bits set somewhere.
2091 * 1) sethi %hi(focus_bits), %reg
2092 * sllx %reg, shift, %reg
2093 * 2) sethi %hi(focus_bits), %reg
2094 * srlx %reg, shift, %reg
2095 */
2096 if ((highest_bit_set - lowest_bit_set) < 21)
2097 {
2098 unsigned HOST_WIDE_INT focus_bits =
2099 create_simple_focus_bits (high_bits, low_bits,
2100 lowest_bit_set, 10);
2101
2102 if (! SPARC_SETHI_P (focus_bits))
2103 abort ();
2104
2105 sparc_emit_set_safe_HIGH64 (temp, focus_bits);
2106
2107 /* If lowest_bit_set == 10 then a sethi alone could have done it. */
2108 if (lowest_bit_set < 10)
2109 emit_insn (gen_rtx_SET (VOIDmode,
2110 op0,
2111 gen_rtx_LSHIFTRT (DImode, temp,
2112 GEN_INT (10 - lowest_bit_set))));
2113 else if (lowest_bit_set > 10)
2114 emit_insn (gen_rtx_SET (VOIDmode,
2115 op0,
2116 gen_rtx_ASHIFT (DImode, temp,
2117 GEN_INT (lowest_bit_set - 10))));
2118 else
2119 abort ();
2120 return;
2121 }
2122
2123 /* 1) sethi %hi(low_bits), %reg
2124 * or %reg, %lo(low_bits), %reg
2125 * 2) sethi %hi(~low_bits), %reg
2126 * xor %reg, %lo(-0x400 | (low_bits & 0x3ff)), %reg
2127 */
2128 if (high_bits == 0
2129 || high_bits == 0xffffffff)
2130 {
2131 sparc_emit_set_const64_quick1 (op0, temp, low_bits,
2132 (high_bits == 0xffffffff));
2133 return;
2134 }
2135
2136 /* Now, try 3-insn sequences. */
2137
2138 /* 1) sethi %hi(high_bits), %reg
2139 * or %reg, %lo(high_bits), %reg
2140 * sllx %reg, 32, %reg
2141 */
2142 if (low_bits == 0)
2143 {
2144 sparc_emit_set_const64_quick2 (op0, temp, high_bits, 0, 32);
2145 return;
2146 }
2147
2148 /* We may be able to do something quick
2149 when the constant is negated, so try that. */
2150 if (const64_is_2insns ((~high_bits) & 0xffffffff,
2151 (~low_bits) & 0xfffffc00))
2152 {
2153 /* NOTE: The trailing bits get XOR'd so we need the
2154 non-negated bits, not the negated ones. */
2155 unsigned HOST_WIDE_INT trailing_bits = low_bits & 0x3ff;
2156
2157 if ((((~high_bits) & 0xffffffff) == 0
2158 && ((~low_bits) & 0x80000000) == 0)
2159 || (((~high_bits) & 0xffffffff) == 0xffffffff
2160 && ((~low_bits) & 0x80000000) != 0))
2161 {
2162 int fast_int = (~low_bits & 0xffffffff);
2163
2164 if ((SPARC_SETHI_P (fast_int)
2165 && (~high_bits & 0xffffffff) == 0)
2166 || SPARC_SIMM13_P (fast_int))
2167 emit_insn (gen_safe_SET64 (temp, fast_int));
2168 else
2169 sparc_emit_set_const64 (temp, GEN_INT64 (fast_int));
2170 }
2171 else
2172 {
2173 rtx negated_const;
2174 #if HOST_BITS_PER_WIDE_INT == 64
2175 negated_const = GEN_INT (((~low_bits) & 0xfffffc00) |
2176 (((HOST_WIDE_INT)((~high_bits) & 0xffffffff))<<32));
2177 #else
2178 negated_const = immed_double_const ((~low_bits) & 0xfffffc00,
2179 (~high_bits) & 0xffffffff,
2180 DImode);
2181 #endif
2182 sparc_emit_set_const64 (temp, negated_const);
2183 }
2184
2185 /* If we are XOR'ing with -1, then we should emit a one's complement
2186 instead. This way the combiner will notice logical operations
2187 such as ANDN later on and substitute. */
2188 if (trailing_bits == 0x3ff)
2189 {
2190 emit_insn (gen_rtx_SET (VOIDmode, op0,
2191 gen_rtx_NOT (DImode, temp)));
2192 }
2193 else
2194 {
2195 emit_insn (gen_rtx_SET (VOIDmode,
2196 op0,
2197 gen_safe_XOR64 (temp,
2198 (-0x400 | trailing_bits))));
2199 }
2200 return;
2201 }
2202
2203 /* 1) sethi %hi(xxx), %reg
2204 * or %reg, %lo(xxx), %reg
2205 * sllx %reg, yyy, %reg
2206 *
2207 * ??? This is just a generalized version of the low_bits==0
2208 * thing above, FIXME...
2209 */
2210 if ((highest_bit_set - lowest_bit_set) < 32)
2211 {
2212 unsigned HOST_WIDE_INT focus_bits =
2213 create_simple_focus_bits (high_bits, low_bits,
2214 lowest_bit_set, 0);
2215
2216 /* We can't get here in this state. */
2217 if (highest_bit_set < 32
2218 || lowest_bit_set >= 32)
2219 abort ();
2220
2221 /* So what we know is that the set bits straddle the
2222 middle of the 64-bit word. */
2223 sparc_emit_set_const64_quick2 (op0, temp,
2224 focus_bits, 0,
2225 lowest_bit_set);
2226 return;
2227 }
2228
2229 /* 1) sethi %hi(high_bits), %reg
2230 * or %reg, %lo(high_bits), %reg
2231 * sllx %reg, 32, %reg
2232 * or %reg, low_bits, %reg
2233 */
2234 if (SPARC_SIMM13_P(low_bits)
2235 && ((int)low_bits > 0))
2236 {
2237 sparc_emit_set_const64_quick2 (op0, temp, high_bits, low_bits, 32);
2238 return;
2239 }
2240
2241 /* The easiest way when all else fails, is full decomposition. */
2242 #if 0
2243 printf ("sparc_emit_set_const64: Hard constant [%08lx%08lx] neg[%08lx%08lx]\n",
2244 high_bits, low_bits, ~high_bits, ~low_bits);
2245 #endif
2246 sparc_emit_set_const64_longway (op0, temp, high_bits, low_bits);
2247 }
2248
2249 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
2250 return the mode to be used for the comparison. For floating-point,
2251 CCFP[E]mode is used. CC_NOOVmode should be used when the first operand
2252 is a PLUS, MINUS, NEG, or ASHIFT. CCmode should be used when no special
2253 processing is needed. */
2254
2255 enum machine_mode
select_cc_mode(op,x,y)2256 select_cc_mode (op, x, y)
2257 enum rtx_code op;
2258 rtx x;
2259 rtx y ATTRIBUTE_UNUSED;
2260 {
2261 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2262 {
2263 switch (op)
2264 {
2265 case EQ:
2266 case NE:
2267 case UNORDERED:
2268 case ORDERED:
2269 case UNLT:
2270 case UNLE:
2271 case UNGT:
2272 case UNGE:
2273 case UNEQ:
2274 case LTGT:
2275 return CCFPmode;
2276
2277 case LT:
2278 case LE:
2279 case GT:
2280 case GE:
2281 return CCFPEmode;
2282
2283 default:
2284 abort ();
2285 }
2286 }
2287 else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
2288 || GET_CODE (x) == NEG || GET_CODE (x) == ASHIFT)
2289 {
2290 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2291 return CCX_NOOVmode;
2292 else
2293 return CC_NOOVmode;
2294 }
2295 else
2296 {
2297 if (TARGET_ARCH64 && GET_MODE (x) == DImode)
2298 return CCXmode;
2299 else
2300 return CCmode;
2301 }
2302 }
2303
2304 /* X and Y are two things to compare using CODE. Emit the compare insn and
2305 return the rtx for the cc reg in the proper mode. */
2306
2307 rtx
gen_compare_reg(code,x,y)2308 gen_compare_reg (code, x, y)
2309 enum rtx_code code;
2310 rtx x, y;
2311 {
2312 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
2313 rtx cc_reg;
2314
2315 /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
2316 fcc regs (cse can't tell they're really call clobbered regs and will
2317 remove a duplicate comparison even if there is an intervening function
2318 call - it will then try to reload the cc reg via an int reg which is why
2319 we need the movcc patterns). It is possible to provide the movcc
2320 patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two
2321 registers (say %g1,%g5) and it takes about 6 insns. A better fix would be
2322 to tell cse that CCFPE mode registers (even pseudos) are call
2323 clobbered. */
2324
2325 /* ??? This is an experiment. Rather than making changes to cse which may
2326 or may not be easy/clean, we do our own cse. This is possible because
2327 we will generate hard registers. Cse knows they're call clobbered (it
2328 doesn't know the same thing about pseudos). If we guess wrong, no big
2329 deal, but if we win, great! */
2330
2331 if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2332 #if 1 /* experiment */
2333 {
2334 int reg;
2335 /* We cycle through the registers to ensure they're all exercised. */
2336 static int next_fcc_reg = 0;
2337 /* Previous x,y for each fcc reg. */
2338 static rtx prev_args[4][2];
2339
2340 /* Scan prev_args for x,y. */
2341 for (reg = 0; reg < 4; reg++)
2342 if (prev_args[reg][0] == x && prev_args[reg][1] == y)
2343 break;
2344 if (reg == 4)
2345 {
2346 reg = next_fcc_reg;
2347 prev_args[reg][0] = x;
2348 prev_args[reg][1] = y;
2349 next_fcc_reg = (next_fcc_reg + 1) & 3;
2350 }
2351 cc_reg = gen_rtx_REG (mode, reg + SPARC_FIRST_V9_FCC_REG);
2352 }
2353 #else
2354 cc_reg = gen_reg_rtx (mode);
2355 #endif /* ! experiment */
2356 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2357 cc_reg = gen_rtx_REG (mode, SPARC_FCC_REG);
2358 else
2359 cc_reg = gen_rtx_REG (mode, SPARC_ICC_REG);
2360
2361 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2362 gen_rtx_COMPARE (mode, x, y)));
2363
2364 return cc_reg;
2365 }
2366
2367 /* This function is used for v9 only.
2368 CODE is the code for an Scc's comparison.
2369 OPERANDS[0] is the target of the Scc insn.
2370 OPERANDS[1] is the value we compare against const0_rtx (which hasn't
2371 been generated yet).
2372
2373 This function is needed to turn
2374
2375 (set (reg:SI 110)
2376 (gt (reg:CCX 100 %icc)
2377 (const_int 0)))
2378 into
2379 (set (reg:SI 110)
2380 (gt:DI (reg:CCX 100 %icc)
2381 (const_int 0)))
2382
2383 IE: The instruction recognizer needs to see the mode of the comparison to
2384 find the right instruction. We could use "gt:DI" right in the
2385 define_expand, but leaving it out allows us to handle DI, SI, etc.
2386
2387 We refer to the global sparc compare operands sparc_compare_op0 and
2388 sparc_compare_op1. */
2389
2390 int
gen_v9_scc(compare_code,operands)2391 gen_v9_scc (compare_code, operands)
2392 enum rtx_code compare_code;
2393 register rtx *operands;
2394 {
2395 rtx temp, op0, op1;
2396
2397 if (! TARGET_ARCH64
2398 && (GET_MODE (sparc_compare_op0) == DImode
2399 || GET_MODE (operands[0]) == DImode))
2400 return 0;
2401
2402 op0 = sparc_compare_op0;
2403 op1 = sparc_compare_op1;
2404
2405 /* Try to use the movrCC insns. */
2406 if (TARGET_ARCH64
2407 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
2408 && op1 == const0_rtx
2409 && v9_regcmp_p (compare_code))
2410 {
2411 /* Special case for op0 != 0. This can be done with one instruction if
2412 operands[0] == sparc_compare_op0. */
2413
2414 if (compare_code == NE
2415 && GET_MODE (operands[0]) == DImode
2416 && rtx_equal_p (op0, operands[0]))
2417 {
2418 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2419 gen_rtx_IF_THEN_ELSE (DImode,
2420 gen_rtx_fmt_ee (compare_code, DImode,
2421 op0, const0_rtx),
2422 const1_rtx,
2423 operands[0])));
2424 return 1;
2425 }
2426
2427 if (reg_overlap_mentioned_p (operands[0], op0))
2428 {
2429 /* Handle the case where operands[0] == sparc_compare_op0.
2430 We "early clobber" the result. */
2431 op0 = gen_reg_rtx (GET_MODE (sparc_compare_op0));
2432 emit_move_insn (op0, sparc_compare_op0);
2433 }
2434
2435 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2436 if (GET_MODE (op0) != DImode)
2437 {
2438 temp = gen_reg_rtx (DImode);
2439 convert_move (temp, op0, 0);
2440 }
2441 else
2442 temp = op0;
2443 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2444 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2445 gen_rtx_fmt_ee (compare_code, DImode,
2446 temp, const0_rtx),
2447 const1_rtx,
2448 operands[0])));
2449 return 1;
2450 }
2451 else
2452 {
2453 operands[1] = gen_compare_reg (compare_code, op0, op1);
2454
2455 switch (GET_MODE (operands[1]))
2456 {
2457 case CCmode :
2458 case CCXmode :
2459 case CCFPEmode :
2460 case CCFPmode :
2461 break;
2462 default :
2463 abort ();
2464 }
2465 emit_insn (gen_rtx_SET (VOIDmode, operands[0], const0_rtx));
2466 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2467 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2468 gen_rtx_fmt_ee (compare_code,
2469 GET_MODE (operands[1]),
2470 operands[1], const0_rtx),
2471 const1_rtx, operands[0])));
2472 return 1;
2473 }
2474 }
2475
2476 /* Emit a conditional jump insn for the v9 architecture using comparison code
2477 CODE and jump target LABEL.
2478 This function exists to take advantage of the v9 brxx insns. */
2479
2480 void
emit_v9_brxx_insn(code,op0,label)2481 emit_v9_brxx_insn (code, op0, label)
2482 enum rtx_code code;
2483 rtx op0, label;
2484 {
2485 emit_jump_insn (gen_rtx_SET (VOIDmode,
2486 pc_rtx,
2487 gen_rtx_IF_THEN_ELSE (VOIDmode,
2488 gen_rtx_fmt_ee (code, GET_MODE (op0),
2489 op0, const0_rtx),
2490 gen_rtx_LABEL_REF (VOIDmode, label),
2491 pc_rtx)));
2492 }
2493
2494 /* Generate a DFmode part of a hard TFmode register.
2495 REG is the TFmode hard register, LOW is 1 for the
2496 low 64bit of the register and 0 otherwise.
2497 */
2498 rtx
gen_df_reg(reg,low)2499 gen_df_reg (reg, low)
2500 rtx reg;
2501 int low;
2502 {
2503 int regno = REGNO (reg);
2504
2505 if ((WORDS_BIG_ENDIAN == 0) ^ (low != 0))
2506 regno += (TARGET_ARCH64 && regno < 32) ? 1 : 2;
2507 return gen_rtx_REG (DFmode, regno);
2508 }
2509
2510 /* Generate a call to FUNC with OPERANDS. Operand 0 is the return value.
2511 Unlike normal calls, TFmode operands are passed by reference. It is
2512 assumed that no more than 3 operands are required. */
2513
2514 static void
emit_soft_tfmode_libcall(func_name,nargs,operands)2515 emit_soft_tfmode_libcall (func_name, nargs, operands)
2516 const char *func_name;
2517 int nargs;
2518 rtx *operands;
2519 {
2520 rtx ret_slot = NULL, arg[3], func_sym;
2521 int i;
2522
2523 /* We only expect to be called for conversions, unary, and binary ops. */
2524 if (nargs < 2 || nargs > 3)
2525 abort ();
2526
2527 for (i = 0; i < nargs; ++i)
2528 {
2529 rtx this_arg = operands[i];
2530 rtx this_slot;
2531
2532 /* TFmode arguments and return values are passed by reference. */
2533 if (GET_MODE (this_arg) == TFmode)
2534 {
2535 int force_stack_temp;
2536
2537 force_stack_temp = 0;
2538 if (TARGET_BUGGY_QP_LIB && i == 0)
2539 force_stack_temp = 1;
2540
2541 if (GET_CODE (this_arg) == MEM
2542 && ! force_stack_temp)
2543 this_arg = XEXP (this_arg, 0);
2544 else if (CONSTANT_P (this_arg)
2545 && ! force_stack_temp)
2546 {
2547 this_slot = force_const_mem (TFmode, this_arg);
2548 this_arg = XEXP (this_slot, 0);
2549 }
2550 else
2551 {
2552 this_slot = assign_stack_temp (TFmode, GET_MODE_SIZE (TFmode), 0);
2553
2554 /* Operand 0 is the return value. We'll copy it out later. */
2555 if (i > 0)
2556 emit_move_insn (this_slot, this_arg);
2557 else
2558 ret_slot = this_slot;
2559
2560 this_arg = XEXP (this_slot, 0);
2561 }
2562 }
2563
2564 arg[i] = this_arg;
2565 }
2566
2567 func_sym = gen_rtx_SYMBOL_REF (Pmode, func_name);
2568
2569 if (GET_MODE (operands[0]) == TFmode)
2570 {
2571 if (nargs == 2)
2572 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 2,
2573 arg[0], GET_MODE (arg[0]),
2574 arg[1], GET_MODE (arg[1]));
2575 else
2576 emit_library_call (func_sym, LCT_NORMAL, VOIDmode, 3,
2577 arg[0], GET_MODE (arg[0]),
2578 arg[1], GET_MODE (arg[1]),
2579 arg[2], GET_MODE (arg[2]));
2580
2581 if (ret_slot)
2582 emit_move_insn (operands[0], ret_slot);
2583 }
2584 else
2585 {
2586 rtx ret;
2587
2588 if (nargs != 2)
2589 abort ();
2590
2591 ret = emit_library_call_value (func_sym, operands[0], LCT_NORMAL,
2592 GET_MODE (operands[0]), 1,
2593 arg[1], GET_MODE (arg[1]));
2594
2595 if (ret != operands[0])
2596 emit_move_insn (operands[0], ret);
2597 }
2598 }
2599
2600 /* Expand soft-float TFmode calls to sparc abi routines. */
2601
2602 static void
emit_soft_tfmode_binop(code,operands)2603 emit_soft_tfmode_binop (code, operands)
2604 enum rtx_code code;
2605 rtx *operands;
2606 {
2607 const char *func;
2608
2609 switch (code)
2610 {
2611 case PLUS:
2612 func = "_Qp_add";
2613 break;
2614 case MINUS:
2615 func = "_Qp_sub";
2616 break;
2617 case MULT:
2618 func = "_Qp_mul";
2619 break;
2620 case DIV:
2621 func = "_Qp_div";
2622 break;
2623 default:
2624 abort ();
2625 }
2626
2627 emit_soft_tfmode_libcall (func, 3, operands);
2628 }
2629
2630 static void
emit_soft_tfmode_unop(code,operands)2631 emit_soft_tfmode_unop (code, operands)
2632 enum rtx_code code;
2633 rtx *operands;
2634 {
2635 const char *func;
2636
2637 switch (code)
2638 {
2639 case SQRT:
2640 func = "_Qp_sqrt";
2641 break;
2642 default:
2643 abort ();
2644 }
2645
2646 emit_soft_tfmode_libcall (func, 2, operands);
2647 }
2648
2649 static void
emit_soft_tfmode_cvt(code,operands)2650 emit_soft_tfmode_cvt (code, operands)
2651 enum rtx_code code;
2652 rtx *operands;
2653 {
2654 const char *func;
2655
2656 switch (code)
2657 {
2658 case FLOAT_EXTEND:
2659 switch (GET_MODE (operands[1]))
2660 {
2661 case SFmode:
2662 func = "_Qp_stoq";
2663 break;
2664 case DFmode:
2665 func = "_Qp_dtoq";
2666 break;
2667 default:
2668 abort ();
2669 }
2670 break;
2671
2672 case FLOAT_TRUNCATE:
2673 switch (GET_MODE (operands[0]))
2674 {
2675 case SFmode:
2676 func = "_Qp_qtos";
2677 break;
2678 case DFmode:
2679 func = "_Qp_qtod";
2680 break;
2681 default:
2682 abort ();
2683 }
2684 break;
2685
2686 case FLOAT:
2687 switch (GET_MODE (operands[1]))
2688 {
2689 case SImode:
2690 func = "_Qp_itoq";
2691 break;
2692 case DImode:
2693 func = "_Qp_xtoq";
2694 break;
2695 default:
2696 abort ();
2697 }
2698 break;
2699
2700 case UNSIGNED_FLOAT:
2701 switch (GET_MODE (operands[1]))
2702 {
2703 case SImode:
2704 func = "_Qp_uitoq";
2705 break;
2706 case DImode:
2707 func = "_Qp_uxtoq";
2708 break;
2709 default:
2710 abort ();
2711 }
2712 break;
2713
2714 case FIX:
2715 switch (GET_MODE (operands[0]))
2716 {
2717 case SImode:
2718 func = "_Qp_qtoi";
2719 break;
2720 case DImode:
2721 func = "_Qp_qtox";
2722 break;
2723 default:
2724 abort ();
2725 }
2726 break;
2727
2728 case UNSIGNED_FIX:
2729 switch (GET_MODE (operands[0]))
2730 {
2731 case SImode:
2732 func = "_Qp_qtoui";
2733 break;
2734 case DImode:
2735 func = "_Qp_qtoux";
2736 break;
2737 default:
2738 abort ();
2739 }
2740 break;
2741
2742 default:
2743 abort ();
2744 }
2745
2746 emit_soft_tfmode_libcall (func, 2, operands);
2747 }
2748
2749 /* Expand a hard-float tfmode operation. All arguments must be in
2750 registers. */
2751
2752 static void
emit_hard_tfmode_operation(code,operands)2753 emit_hard_tfmode_operation (code, operands)
2754 enum rtx_code code;
2755 rtx *operands;
2756 {
2757 rtx op, dest;
2758
2759 if (GET_RTX_CLASS (code) == '1')
2760 {
2761 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2762 op = gen_rtx_fmt_e (code, GET_MODE (operands[0]), operands[1]);
2763 }
2764 else
2765 {
2766 operands[1] = force_reg (GET_MODE (operands[1]), operands[1]);
2767 operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
2768 op = gen_rtx_fmt_ee (code, GET_MODE (operands[0]),
2769 operands[1], operands[2]);
2770 }
2771
2772 if (register_operand (operands[0], VOIDmode))
2773 dest = operands[0];
2774 else
2775 dest = gen_reg_rtx (GET_MODE (operands[0]));
2776
2777 emit_insn (gen_rtx_SET (VOIDmode, dest, op));
2778
2779 if (dest != operands[0])
2780 emit_move_insn (operands[0], dest);
2781 }
2782
2783 void
emit_tfmode_binop(code,operands)2784 emit_tfmode_binop (code, operands)
2785 enum rtx_code code;
2786 rtx *operands;
2787 {
2788 if (TARGET_HARD_QUAD)
2789 emit_hard_tfmode_operation (code, operands);
2790 else
2791 emit_soft_tfmode_binop (code, operands);
2792 }
2793
2794 void
emit_tfmode_unop(code,operands)2795 emit_tfmode_unop (code, operands)
2796 enum rtx_code code;
2797 rtx *operands;
2798 {
2799 if (TARGET_HARD_QUAD)
2800 emit_hard_tfmode_operation (code, operands);
2801 else
2802 emit_soft_tfmode_unop (code, operands);
2803 }
2804
2805 void
emit_tfmode_cvt(code,operands)2806 emit_tfmode_cvt (code, operands)
2807 enum rtx_code code;
2808 rtx *operands;
2809 {
2810 if (TARGET_HARD_QUAD)
2811 emit_hard_tfmode_operation (code, operands);
2812 else
2813 emit_soft_tfmode_cvt (code, operands);
2814 }
2815
2816 /* Return nonzero if a return peephole merging return with
2817 setting of output register is ok. */
2818 int
leaf_return_peephole_ok()2819 leaf_return_peephole_ok ()
2820 {
2821 return (actual_fsize == 0);
2822 }
2823
2824 /* Return nonzero if a branch/jump/call instruction will be emitting
2825 nop into its delay slot. */
2826
2827 int
empty_delay_slot(insn)2828 empty_delay_slot (insn)
2829 rtx insn;
2830 {
2831 rtx seq;
2832
2833 /* If no previous instruction (should not happen), return true. */
2834 if (PREV_INSN (insn) == NULL)
2835 return 1;
2836
2837 seq = NEXT_INSN (PREV_INSN (insn));
2838 if (GET_CODE (PATTERN (seq)) == SEQUENCE)
2839 return 0;
2840
2841 return 1;
2842 }
2843
2844 /* Return nonzero if TRIAL can go into the function epilogue's
2845 delay slot. SLOT is the slot we are trying to fill. */
2846
2847 int
eligible_for_epilogue_delay(trial,slot)2848 eligible_for_epilogue_delay (trial, slot)
2849 rtx trial;
2850 int slot;
2851 {
2852 rtx pat, src;
2853
2854 if (slot >= 1)
2855 return 0;
2856
2857 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2858 return 0;
2859
2860 if (get_attr_length (trial) != 1)
2861 return 0;
2862
2863 /* If there are any call-saved registers, we should scan TRIAL if it
2864 does not reference them. For now just make it easy. */
2865 if (num_gfregs)
2866 return 0;
2867
2868 /* If the function uses __builtin_eh_return, the eh_return machinery
2869 occupies the delay slot. */
2870 if (current_function_calls_eh_return)
2871 return 0;
2872
2873 /* In the case of a true leaf function, anything can go into the delay slot.
2874 A delay slot only exists however if the frame size is zero, otherwise
2875 we will put an insn to adjust the stack after the return. */
2876 if (current_function_uses_only_leaf_regs)
2877 {
2878 if (leaf_return_peephole_ok ())
2879 return ((get_attr_in_uncond_branch_delay (trial)
2880 == IN_BRANCH_DELAY_TRUE));
2881 return 0;
2882 }
2883
2884 pat = PATTERN (trial);
2885
2886 /* Otherwise, only operations which can be done in tandem with
2887 a `restore' or `return' insn can go into the delay slot. */
2888 if (GET_CODE (SET_DEST (pat)) != REG
2889 || REGNO (SET_DEST (pat)) < 24)
2890 return 0;
2891
2892 /* If this instruction sets up floating point register and we have a return
2893 instruction, it can probably go in. But restore will not work
2894 with FP_REGS. */
2895 if (REGNO (SET_DEST (pat)) >= 32)
2896 {
2897 if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2898 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2899 return 1;
2900 return 0;
2901 }
2902
2903 /* The set of insns matched here must agree precisely with the set of
2904 patterns paired with a RETURN in sparc.md. */
2905
2906 src = SET_SRC (pat);
2907
2908 /* This matches "*return_[qhs]i" or even "*return_di" on TARGET_ARCH64. */
2909 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2910 && arith_operand (src, GET_MODE (src)))
2911 {
2912 if (TARGET_ARCH64)
2913 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2914 else
2915 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
2916 }
2917
2918 /* This matches "*return_di". */
2919 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
2920 && arith_double_operand (src, GET_MODE (src)))
2921 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
2922
2923 /* This matches "*return_sf_no_fpu". */
2924 else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode)
2925 && register_operand (src, SFmode))
2926 return 1;
2927
2928 /* If we have return instruction, anything that does not use
2929 local or output registers and can go into a delay slot wins. */
2930 else if (TARGET_V9 && ! epilogue_renumber (&pat, 1)
2931 && (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE))
2932 return 1;
2933
2934 /* This matches "*return_addsi". */
2935 else if (GET_CODE (src) == PLUS
2936 && arith_operand (XEXP (src, 0), SImode)
2937 && arith_operand (XEXP (src, 1), SImode)
2938 && (register_operand (XEXP (src, 0), SImode)
2939 || register_operand (XEXP (src, 1), SImode)))
2940 return 1;
2941
2942 /* This matches "*return_adddi". */
2943 else if (GET_CODE (src) == PLUS
2944 && arith_double_operand (XEXP (src, 0), DImode)
2945 && arith_double_operand (XEXP (src, 1), DImode)
2946 && (register_operand (XEXP (src, 0), DImode)
2947 || register_operand (XEXP (src, 1), DImode)))
2948 return 1;
2949
2950 /* This can match "*return_losum_[sd]i".
2951 Catch only some cases, so that return_losum* don't have
2952 to be too big. */
2953 else if (GET_CODE (src) == LO_SUM
2954 && ! TARGET_CM_MEDMID
2955 && ((register_operand (XEXP (src, 0), SImode)
2956 && immediate_operand (XEXP (src, 1), SImode))
2957 || (TARGET_ARCH64
2958 && register_operand (XEXP (src, 0), DImode)
2959 && immediate_operand (XEXP (src, 1), DImode))))
2960 return 1;
2961
2962 /* sll{,x} reg,1,reg2 is add reg,reg,reg2 as well. */
2963 else if (GET_CODE (src) == ASHIFT
2964 && (register_operand (XEXP (src, 0), SImode)
2965 || register_operand (XEXP (src, 0), DImode))
2966 && XEXP (src, 1) == const1_rtx)
2967 return 1;
2968
2969 return 0;
2970 }
2971
2972 /* Return nonzero if TRIAL can go into the sibling call
2973 delay slot. */
2974
2975 int
eligible_for_sibcall_delay(trial)2976 eligible_for_sibcall_delay (trial)
2977 rtx trial;
2978 {
2979 rtx pat, src;
2980
2981 if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET)
2982 return 0;
2983
2984 if (get_attr_length (trial) != 1)
2985 return 0;
2986
2987 pat = PATTERN (trial);
2988
2989 if (current_function_uses_only_leaf_regs)
2990 {
2991 /* If the tail call is done using the call instruction,
2992 we have to restore %o7 in the delay slot. */
2993 if ((TARGET_ARCH64 && ! TARGET_CM_MEDLOW) || flag_pic)
2994 return 0;
2995
2996 /* %g1 is used to build the function address */
2997 if (reg_mentioned_p (gen_rtx_REG (Pmode, 1), pat))
2998 return 0;
2999
3000 return 1;
3001 }
3002
3003 /* Otherwise, only operations which can be done in tandem with
3004 a `restore' insn can go into the delay slot. */
3005 if (GET_CODE (SET_DEST (pat)) != REG
3006 || REGNO (SET_DEST (pat)) < 24
3007 || REGNO (SET_DEST (pat)) >= 32)
3008 return 0;
3009
3010 /* If it mentions %o7, it can't go in, because sibcall will clobber it
3011 in most cases. */
3012 if (reg_mentioned_p (gen_rtx_REG (Pmode, 15), pat))
3013 return 0;
3014
3015 src = SET_SRC (pat);
3016
3017 if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3018 && arith_operand (src, GET_MODE (src)))
3019 {
3020 if (TARGET_ARCH64)
3021 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3022 else
3023 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
3024 }
3025
3026 else if (GET_MODE_CLASS (GET_MODE (src)) != MODE_FLOAT
3027 && arith_double_operand (src, GET_MODE (src)))
3028 return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
3029
3030 else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode)
3031 && register_operand (src, SFmode))
3032 return 1;
3033
3034 else if (GET_CODE (src) == PLUS
3035 && arith_operand (XEXP (src, 0), SImode)
3036 && arith_operand (XEXP (src, 1), SImode)
3037 && (register_operand (XEXP (src, 0), SImode)
3038 || register_operand (XEXP (src, 1), SImode)))
3039 return 1;
3040
3041 else if (GET_CODE (src) == PLUS
3042 && arith_double_operand (XEXP (src, 0), DImode)
3043 && arith_double_operand (XEXP (src, 1), DImode)
3044 && (register_operand (XEXP (src, 0), DImode)
3045 || register_operand (XEXP (src, 1), DImode)))
3046 return 1;
3047
3048 else if (GET_CODE (src) == LO_SUM
3049 && ! TARGET_CM_MEDMID
3050 && ((register_operand (XEXP (src, 0), SImode)
3051 && immediate_operand (XEXP (src, 1), SImode))
3052 || (TARGET_ARCH64
3053 && register_operand (XEXP (src, 0), DImode)
3054 && immediate_operand (XEXP (src, 1), DImode))))
3055 return 1;
3056
3057 else if (GET_CODE (src) == ASHIFT
3058 && (register_operand (XEXP (src, 0), SImode)
3059 || register_operand (XEXP (src, 0), DImode))
3060 && XEXP (src, 1) == const1_rtx)
3061 return 1;
3062
3063 return 0;
3064 }
3065
3066 static int
check_return_regs(x)3067 check_return_regs (x)
3068 rtx x;
3069 {
3070 switch (GET_CODE (x))
3071 {
3072 case REG:
3073 return IN_OR_GLOBAL_P (x);
3074
3075 case CONST_INT:
3076 case CONST_DOUBLE:
3077 case CONST:
3078 case SYMBOL_REF:
3079 case LABEL_REF:
3080 return 1;
3081
3082 case SET:
3083 case IOR:
3084 case AND:
3085 case XOR:
3086 case PLUS:
3087 case MINUS:
3088 if (check_return_regs (XEXP (x, 1)) == 0)
3089 return 0;
3090 case NOT:
3091 case NEG:
3092 case MEM:
3093 return check_return_regs (XEXP (x, 0));
3094
3095 default:
3096 return 0;
3097 }
3098
3099 }
3100
3101 int
short_branch(uid1,uid2)3102 short_branch (uid1, uid2)
3103 int uid1, uid2;
3104 {
3105 int delta = INSN_ADDRESSES (uid1) - INSN_ADDRESSES (uid2);
3106
3107 /* Leave a few words of "slop". */
3108 if (delta >= -1023 && delta <= 1022)
3109 return 1;
3110
3111 return 0;
3112 }
3113
3114 /* Return nonzero if REG is not used after INSN.
3115 We assume REG is a reload reg, and therefore does
3116 not live past labels or calls or jumps. */
3117 int
reg_unused_after(reg,insn)3118 reg_unused_after (reg, insn)
3119 rtx reg;
3120 rtx insn;
3121 {
3122 enum rtx_code code, prev_code = UNKNOWN;
3123
3124 while ((insn = NEXT_INSN (insn)))
3125 {
3126 if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
3127 return 1;
3128
3129 code = GET_CODE (insn);
3130 if (GET_CODE (insn) == CODE_LABEL)
3131 return 1;
3132
3133 if (GET_RTX_CLASS (code) == 'i')
3134 {
3135 rtx set = single_set (insn);
3136 int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
3137 if (set && in_src)
3138 return 0;
3139 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
3140 return 1;
3141 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
3142 return 0;
3143 }
3144 prev_code = code;
3145 }
3146 return 1;
3147 }
3148
3149 /* The table we use to reference PIC data. */
3150 static GTY(()) rtx global_offset_table;
3151
3152 /* The function we use to get at it. */
3153 static GTY(()) rtx get_pc_symbol;
3154 static char get_pc_symbol_name[256];
3155
3156 /* Ensure that we are not using patterns that are not OK with PIC. */
3157
3158 int
check_pic(i)3159 check_pic (i)
3160 int i;
3161 {
3162 switch (flag_pic)
3163 {
3164 case 1:
3165 if (GET_CODE (recog_data.operand[i]) == SYMBOL_REF
3166 || (GET_CODE (recog_data.operand[i]) == CONST
3167 && ! (GET_CODE (XEXP (recog_data.operand[i], 0)) == MINUS
3168 && (XEXP (XEXP (recog_data.operand[i], 0), 0)
3169 == global_offset_table)
3170 && (GET_CODE (XEXP (XEXP (recog_data.operand[i], 0), 1))
3171 == CONST))))
3172 abort ();
3173 case 2:
3174 default:
3175 return 1;
3176 }
3177 }
3178
3179 /* Return true if X is an address which needs a temporary register when
3180 reloaded while generating PIC code. */
3181
3182 int
pic_address_needs_scratch(x)3183 pic_address_needs_scratch (x)
3184 rtx x;
3185 {
3186 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
3187 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3188 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
3189 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3190 && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
3191 return 1;
3192
3193 return 0;
3194 }
3195
3196 /* Legitimize PIC addresses. If the address is already position-independent,
3197 we return ORIG. Newly generated position-independent addresses go into a
3198 reg. This is REG if nonzero, otherwise we allocate register(s) as
3199 necessary. */
3200
3201 rtx
legitimize_pic_address(orig,mode,reg)3202 legitimize_pic_address (orig, mode, reg)
3203 rtx orig;
3204 enum machine_mode mode ATTRIBUTE_UNUSED;
3205 rtx reg;
3206 {
3207 if (GET_CODE (orig) == SYMBOL_REF)
3208 {
3209 rtx pic_ref, address;
3210 rtx insn;
3211
3212 if (reg == 0)
3213 {
3214 if (reload_in_progress || reload_completed)
3215 abort ();
3216 else
3217 reg = gen_reg_rtx (Pmode);
3218 }
3219
3220 if (flag_pic == 2)
3221 {
3222 /* If not during reload, allocate another temp reg here for loading
3223 in the address, so that these instructions can be optimized
3224 properly. */
3225 rtx temp_reg = ((reload_in_progress || reload_completed)
3226 ? reg : gen_reg_rtx (Pmode));
3227
3228 /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
3229 won't get confused into thinking that these two instructions
3230 are loading in the true address of the symbol. If in the
3231 future a PIC rtx exists, that should be used instead. */
3232 if (Pmode == SImode)
3233 {
3234 emit_insn (gen_movsi_high_pic (temp_reg, orig));
3235 emit_insn (gen_movsi_lo_sum_pic (temp_reg, temp_reg, orig));
3236 }
3237 else
3238 {
3239 emit_insn (gen_movdi_high_pic (temp_reg, orig));
3240 emit_insn (gen_movdi_lo_sum_pic (temp_reg, temp_reg, orig));
3241 }
3242 address = temp_reg;
3243 }
3244 else
3245 address = orig;
3246
3247 pic_ref = gen_rtx_MEM (Pmode,
3248 gen_rtx_PLUS (Pmode,
3249 pic_offset_table_rtx, address));
3250 current_function_uses_pic_offset_table = 1;
3251 RTX_UNCHANGING_P (pic_ref) = 1;
3252 insn = emit_move_insn (reg, pic_ref);
3253 /* Put a REG_EQUAL note on this insn, so that it can be optimized
3254 by loop. */
3255 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig,
3256 REG_NOTES (insn));
3257 return reg;
3258 }
3259 else if (GET_CODE (orig) == CONST)
3260 {
3261 rtx base, offset;
3262
3263 if (GET_CODE (XEXP (orig, 0)) == PLUS
3264 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
3265 return orig;
3266
3267 if (reg == 0)
3268 {
3269 if (reload_in_progress || reload_completed)
3270 abort ();
3271 else
3272 reg = gen_reg_rtx (Pmode);
3273 }
3274
3275 if (GET_CODE (XEXP (orig, 0)) == PLUS)
3276 {
3277 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
3278 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
3279 base == reg ? 0 : reg);
3280 }
3281 else
3282 abort ();
3283
3284 if (GET_CODE (offset) == CONST_INT)
3285 {
3286 if (SMALL_INT (offset))
3287 return plus_constant (base, INTVAL (offset));
3288 else if (! reload_in_progress && ! reload_completed)
3289 offset = force_reg (Pmode, offset);
3290 else
3291 /* If we reach here, then something is seriously wrong. */
3292 abort ();
3293 }
3294 return gen_rtx_PLUS (Pmode, base, offset);
3295 }
3296 else if (GET_CODE (orig) == LABEL_REF)
3297 /* ??? Why do we do this? */
3298 /* Now movsi_pic_label_ref uses it, but we ought to be checking that
3299 the register is live instead, in case it is eliminated. */
3300 current_function_uses_pic_offset_table = 1;
3301
3302 return orig;
3303 }
3304
3305 /* Emit special PIC prologues. */
3306
3307 void
load_pic_register()3308 load_pic_register ()
3309 {
3310 /* Labels to get the PC in the prologue of this function. */
3311 int orig_flag_pic = flag_pic;
3312
3313 if (! flag_pic)
3314 abort ();
3315
3316 /* If we haven't emitted the special get_pc helper function, do so now. */
3317 if (get_pc_symbol_name[0] == 0)
3318 {
3319 int align;
3320
3321 ASM_GENERATE_INTERNAL_LABEL (get_pc_symbol_name, "LGETPC", 0);
3322 text_section ();
3323
3324 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
3325 if (align > 0)
3326 ASM_OUTPUT_ALIGN (asm_out_file, align);
3327 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LGETPC", 0);
3328 fputs ("\tretl\n\tadd\t%o7, %l7, %l7\n", asm_out_file);
3329 }
3330
3331 /* Initialize every time through, since we can't easily
3332 know this to be permanent. */
3333 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3334 get_pc_symbol = gen_rtx_SYMBOL_REF (Pmode, get_pc_symbol_name);
3335 flag_pic = 0;
3336
3337 emit_insn (gen_get_pc (pic_offset_table_rtx, global_offset_table,
3338 get_pc_symbol));
3339
3340 flag_pic = orig_flag_pic;
3341
3342 /* Need to emit this whether or not we obey regdecls,
3343 since setjmp/longjmp can cause life info to screw up.
3344 ??? In the case where we don't obey regdecls, this is not sufficient
3345 since we may not fall out the bottom. */
3346 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3347 }
3348
3349 /* Return 1 if RTX is a MEM which is known to be aligned to at
3350 least a DESIRED byte boundary. */
3351
3352 int
mem_min_alignment(mem,desired)3353 mem_min_alignment (mem, desired)
3354 rtx mem;
3355 int desired;
3356 {
3357 rtx addr, base, offset;
3358
3359 /* If it's not a MEM we can't accept it. */
3360 if (GET_CODE (mem) != MEM)
3361 return 0;
3362
3363 addr = XEXP (mem, 0);
3364 base = offset = NULL_RTX;
3365 if (GET_CODE (addr) == PLUS)
3366 {
3367 if (GET_CODE (XEXP (addr, 0)) == REG)
3368 {
3369 base = XEXP (addr, 0);
3370
3371 /* What we are saying here is that if the base
3372 REG is aligned properly, the compiler will make
3373 sure any REG based index upon it will be so
3374 as well. */
3375 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3376 offset = XEXP (addr, 1);
3377 else
3378 offset = const0_rtx;
3379 }
3380 }
3381 else if (GET_CODE (addr) == REG)
3382 {
3383 base = addr;
3384 offset = const0_rtx;
3385 }
3386
3387 if (base != NULL_RTX)
3388 {
3389 int regno = REGNO (base);
3390
3391 if (regno != HARD_FRAME_POINTER_REGNUM && regno != STACK_POINTER_REGNUM)
3392 {
3393 /* Check if the compiler has recorded some information
3394 about the alignment of the base REG. If reload has
3395 completed, we already matched with proper alignments.
3396 If not running global_alloc, reload might give us
3397 unaligned pointer to local stack though. */
3398 if (((cfun != 0
3399 && REGNO_POINTER_ALIGN (regno) >= desired * BITS_PER_UNIT)
3400 || (optimize && reload_completed))
3401 && (INTVAL (offset) & (desired - 1)) == 0)
3402 return 1;
3403 }
3404 else
3405 {
3406 if (((INTVAL (offset) - SPARC_STACK_BIAS) & (desired - 1)) == 0)
3407 return 1;
3408 }
3409 }
3410 else if (! TARGET_UNALIGNED_DOUBLES
3411 || CONSTANT_P (addr)
3412 || GET_CODE (addr) == LO_SUM)
3413 {
3414 /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
3415 is true, in which case we can only assume that an access is aligned if
3416 it is to a constant address, or the address involves a LO_SUM. */
3417 return 1;
3418 }
3419
3420 /* An obviously unaligned address. */
3421 return 0;
3422 }
3423
3424
3425 /* Vectors to keep interesting information about registers where it can easily
3426 be got. We used to use the actual mode value as the bit number, but there
3427 are more than 32 modes now. Instead we use two tables: one indexed by
3428 hard register number, and one indexed by mode. */
3429
3430 /* The purpose of sparc_mode_class is to shrink the range of modes so that
3431 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
3432 mapped into one sparc_mode_class mode. */
3433
3434 enum sparc_mode_class {
3435 S_MODE, D_MODE, T_MODE, O_MODE,
3436 SF_MODE, DF_MODE, TF_MODE, OF_MODE,
3437 CC_MODE, CCFP_MODE
3438 };
3439
3440 /* Modes for single-word and smaller quantities. */
3441 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
3442
3443 /* Modes for double-word and smaller quantities. */
3444 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
3445
3446 /* Modes for quad-word and smaller quantities. */
3447 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
3448
3449 /* Modes for 8-word and smaller quantities. */
3450 #define O_MODES (T_MODES | (1 << (int) O_MODE) | (1 << (int) OF_MODE))
3451
3452 /* Modes for single-float quantities. We must allow any single word or
3453 smaller quantity. This is because the fix/float conversion instructions
3454 take integer inputs/outputs from the float registers. */
3455 #define SF_MODES (S_MODES)
3456
3457 /* Modes for double-float and smaller quantities. */
3458 #define DF_MODES (S_MODES | D_MODES)
3459
3460 /* Modes for double-float only quantities. */
3461 #define DF_MODES_NO_S ((1 << (int) D_MODE) | (1 << (int) DF_MODE))
3462
3463 /* Modes for quad-float only quantities. */
3464 #define TF_ONLY_MODES (1 << (int) TF_MODE)
3465
3466 /* Modes for quad-float and smaller quantities. */
3467 #define TF_MODES (DF_MODES | TF_ONLY_MODES)
3468
3469 /* Modes for quad-float and double-float quantities. */
3470 #define TF_MODES_NO_S (DF_MODES_NO_S | TF_ONLY_MODES)
3471
3472 /* Modes for quad-float pair only quantities. */
3473 #define OF_ONLY_MODES (1 << (int) OF_MODE)
3474
3475 /* Modes for quad-float pairs and smaller quantities. */
3476 #define OF_MODES (TF_MODES | OF_ONLY_MODES)
3477
3478 #define OF_MODES_NO_S (TF_MODES_NO_S | OF_ONLY_MODES)
3479
3480 /* Modes for condition codes. */
3481 #define CC_MODES (1 << (int) CC_MODE)
3482 #define CCFP_MODES (1 << (int) CCFP_MODE)
3483
3484 /* Value is 1 if register/mode pair is acceptable on sparc.
3485 The funny mixture of D and T modes is because integer operations
3486 do not specially operate on tetra quantities, so non-quad-aligned
3487 registers can hold quadword quantities (except %o4 and %i4 because
3488 they cross fixed registers). */
3489
3490 /* This points to either the 32 bit or the 64 bit version. */
3491 const int *hard_regno_mode_classes;
3492
3493 static const int hard_32bit_mode_classes[] = {
3494 S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3495 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3496 T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
3497 T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
3498
3499 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3500 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3501 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3502 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3503
3504 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3505 and none can hold SFmode/SImode values. */
3506 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3507 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3508 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3509 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3510
3511 /* %fcc[0123] */
3512 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3513
3514 /* %icc */
3515 CC_MODES
3516 };
3517
3518 static const int hard_64bit_mode_classes[] = {
3519 D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3520 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3521 T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3522 O_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
3523
3524 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3525 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3526 OF_MODES, SF_MODES, DF_MODES, SF_MODES, OF_MODES, SF_MODES, DF_MODES, SF_MODES,
3527 OF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
3528
3529 /* FP regs f32 to f63. Only the even numbered registers actually exist,
3530 and none can hold SFmode/SImode values. */
3531 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3532 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3533 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, OF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3534 OF_MODES_NO_S, 0, DF_MODES_NO_S, 0, TF_MODES_NO_S, 0, DF_MODES_NO_S, 0,
3535
3536 /* %fcc[0123] */
3537 CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES,
3538
3539 /* %icc */
3540 CC_MODES
3541 };
3542
3543 int sparc_mode_class [NUM_MACHINE_MODES];
3544
3545 enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER];
3546
3547 static void
sparc_init_modes()3548 sparc_init_modes ()
3549 {
3550 int i;
3551
3552 for (i = 0; i < NUM_MACHINE_MODES; i++)
3553 {
3554 switch (GET_MODE_CLASS (i))
3555 {
3556 case MODE_INT:
3557 case MODE_PARTIAL_INT:
3558 case MODE_COMPLEX_INT:
3559 if (GET_MODE_SIZE (i) <= 4)
3560 sparc_mode_class[i] = 1 << (int) S_MODE;
3561 else if (GET_MODE_SIZE (i) == 8)
3562 sparc_mode_class[i] = 1 << (int) D_MODE;
3563 else if (GET_MODE_SIZE (i) == 16)
3564 sparc_mode_class[i] = 1 << (int) T_MODE;
3565 else if (GET_MODE_SIZE (i) == 32)
3566 sparc_mode_class[i] = 1 << (int) O_MODE;
3567 else
3568 sparc_mode_class[i] = 0;
3569 break;
3570 case MODE_FLOAT:
3571 case MODE_COMPLEX_FLOAT:
3572 if (GET_MODE_SIZE (i) <= 4)
3573 sparc_mode_class[i] = 1 << (int) SF_MODE;
3574 else if (GET_MODE_SIZE (i) == 8)
3575 sparc_mode_class[i] = 1 << (int) DF_MODE;
3576 else if (GET_MODE_SIZE (i) == 16)
3577 sparc_mode_class[i] = 1 << (int) TF_MODE;
3578 else if (GET_MODE_SIZE (i) == 32)
3579 sparc_mode_class[i] = 1 << (int) OF_MODE;
3580 else
3581 sparc_mode_class[i] = 0;
3582 break;
3583 case MODE_CC:
3584 default:
3585 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
3586 we must explicitly check for them here. */
3587 if (i == (int) CCFPmode || i == (int) CCFPEmode)
3588 sparc_mode_class[i] = 1 << (int) CCFP_MODE;
3589 else if (i == (int) CCmode || i == (int) CC_NOOVmode
3590 || i == (int) CCXmode || i == (int) CCX_NOOVmode)
3591 sparc_mode_class[i] = 1 << (int) CC_MODE;
3592 else
3593 sparc_mode_class[i] = 0;
3594 break;
3595 }
3596 }
3597
3598 if (TARGET_ARCH64)
3599 hard_regno_mode_classes = hard_64bit_mode_classes;
3600 else
3601 hard_regno_mode_classes = hard_32bit_mode_classes;
3602
3603 /* Initialize the array used by REGNO_REG_CLASS. */
3604 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3605 {
3606 if (i < 16 && TARGET_V8PLUS)
3607 sparc_regno_reg_class[i] = I64_REGS;
3608 else if (i < 32 || i == FRAME_POINTER_REGNUM)
3609 sparc_regno_reg_class[i] = GENERAL_REGS;
3610 else if (i < 64)
3611 sparc_regno_reg_class[i] = FP_REGS;
3612 else if (i < 96)
3613 sparc_regno_reg_class[i] = EXTRA_FP_REGS;
3614 else if (i < 100)
3615 sparc_regno_reg_class[i] = FPCC_REGS;
3616 else
3617 sparc_regno_reg_class[i] = NO_REGS;
3618 }
3619 }
3620
3621 /* Save non call used registers from LOW to HIGH at BASE+OFFSET.
3622 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3623 v9 int regs as it simplifies the code. */
3624
3625 static int
save_regs(file,low,high,base,offset,n_regs,real_offset)3626 save_regs (file, low, high, base, offset, n_regs, real_offset)
3627 FILE *file;
3628 int low, high;
3629 const char *base;
3630 int offset;
3631 int n_regs;
3632 int real_offset;
3633 {
3634 int i;
3635
3636 if (TARGET_ARCH64 && high <= 32)
3637 {
3638 for (i = low; i < high; i++)
3639 {
3640 if (regs_ever_live[i] && ! call_used_regs[i])
3641 {
3642 fprintf (file, "\tstx\t%s, [%s+%d]\n",
3643 reg_names[i], base, offset + 4 * n_regs);
3644 if (dwarf2out_do_frame ())
3645 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3646 n_regs += 2;
3647 }
3648 }
3649 }
3650 else
3651 {
3652 for (i = low; i < high; i += 2)
3653 {
3654 if (regs_ever_live[i] && ! call_used_regs[i])
3655 {
3656 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3657 {
3658 fprintf (file, "\tstd\t%s, [%s+%d]\n",
3659 reg_names[i], base, offset + 4 * n_regs);
3660 if (dwarf2out_do_frame ())
3661 {
3662 char *l = dwarf2out_cfi_label ();
3663 dwarf2out_reg_save (l, i, real_offset + 4 * n_regs);
3664 dwarf2out_reg_save (l, i+1, real_offset + 4 * n_regs + 4);
3665 }
3666 n_regs += 2;
3667 }
3668 else
3669 {
3670 fprintf (file, "\tst\t%s, [%s+%d]\n",
3671 reg_names[i], base, offset + 4 * n_regs);
3672 if (dwarf2out_do_frame ())
3673 dwarf2out_reg_save ("", i, real_offset + 4 * n_regs);
3674 n_regs += 2;
3675 }
3676 }
3677 else
3678 {
3679 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3680 {
3681 fprintf (file, "\tst\t%s, [%s+%d]\n",
3682 reg_names[i+1], base, offset + 4 * n_regs + 4);
3683 if (dwarf2out_do_frame ())
3684 dwarf2out_reg_save ("", i + 1, real_offset + 4 * n_regs + 4);
3685 n_regs += 2;
3686 }
3687 }
3688 }
3689 }
3690 return n_regs;
3691 }
3692
3693 /* Restore non call used registers from LOW to HIGH at BASE+OFFSET.
3694
3695 N_REGS is the number of 4-byte regs saved thus far. This applies even to
3696 v9 int regs as it simplifies the code. */
3697
3698 static int
restore_regs(file,low,high,base,offset,n_regs)3699 restore_regs (file, low, high, base, offset, n_regs)
3700 FILE *file;
3701 int low, high;
3702 const char *base;
3703 int offset;
3704 int n_regs;
3705 {
3706 int i;
3707
3708 if (TARGET_ARCH64 && high <= 32)
3709 {
3710 for (i = low; i < high; i++)
3711 {
3712 if (regs_ever_live[i] && ! call_used_regs[i])
3713 fprintf (file, "\tldx\t[%s+%d], %s\n",
3714 base, offset + 4 * n_regs, reg_names[i]),
3715 n_regs += 2;
3716 }
3717 }
3718 else
3719 {
3720 for (i = low; i < high; i += 2)
3721 {
3722 if (regs_ever_live[i] && ! call_used_regs[i])
3723 if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3724 fprintf (file, "\tldd\t[%s+%d], %s\n",
3725 base, offset + 4 * n_regs, reg_names[i]),
3726 n_regs += 2;
3727 else
3728 fprintf (file, "\tld\t[%s+%d], %s\n",
3729 base, offset + 4 * n_regs, reg_names[i]),
3730 n_regs += 2;
3731 else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
3732 fprintf (file, "\tld\t[%s+%d], %s\n",
3733 base, offset + 4 * n_regs + 4, reg_names[i+1]),
3734 n_regs += 2;
3735 }
3736 }
3737 return n_regs;
3738 }
3739
3740 /* Compute the frame size required by the function. This function is called
3741 during the reload pass and also by output_function_prologue(). */
3742
3743 int
compute_frame_size(size,leaf_function)3744 compute_frame_size (size, leaf_function)
3745 int size;
3746 int leaf_function;
3747 {
3748 int n_regs = 0, i;
3749 int outgoing_args_size = (current_function_outgoing_args_size
3750 + REG_PARM_STACK_SPACE (current_function_decl));
3751
3752 /* N_REGS is the number of 4-byte regs saved thus far. This applies
3753 even to v9 int regs to be consistent with save_regs/restore_regs. */
3754
3755 if (TARGET_ARCH64)
3756 {
3757 for (i = 0; i < 8; i++)
3758 if (regs_ever_live[i] && ! call_used_regs[i])
3759 n_regs += 2;
3760 }
3761 else
3762 {
3763 for (i = 0; i < 8; i += 2)
3764 if ((regs_ever_live[i] && ! call_used_regs[i])
3765 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3766 n_regs += 2;
3767 }
3768
3769 for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
3770 if ((regs_ever_live[i] && ! call_used_regs[i])
3771 || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
3772 n_regs += 2;
3773
3774 /* Set up values for use in `function_epilogue'. */
3775 num_gfregs = n_regs;
3776
3777 if (leaf_function && n_regs == 0
3778 && size == 0 && current_function_outgoing_args_size == 0)
3779 {
3780 actual_fsize = apparent_fsize = 0;
3781 }
3782 else
3783 {
3784 /* We subtract STARTING_FRAME_OFFSET, remember it's negative. */
3785 apparent_fsize = (size - STARTING_FRAME_OFFSET + 7) & -8;
3786 apparent_fsize += n_regs * 4;
3787 actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
3788 }
3789
3790 /* Make sure nothing can clobber our register windows.
3791 If a SAVE must be done, or there is a stack-local variable,
3792 the register window area must be allocated.
3793 ??? For v8 we apparently need an additional 8 bytes of reserved space. */
3794 if (leaf_function == 0 || size > 0)
3795 actual_fsize += (16 * UNITS_PER_WORD) + (TARGET_ARCH64 ? 0 : 8);
3796
3797 return SPARC_STACK_ALIGN (actual_fsize);
3798 }
3799
3800 /* Build a (32 bit) big number in a register. */
3801 /* ??? We may be able to use the set macro here too. */
3802
3803 static void
build_big_number(file,num,reg)3804 build_big_number (file, num, reg)
3805 FILE *file;
3806 int num;
3807 const char *reg;
3808 {
3809 if (num >= 0 || ! TARGET_ARCH64)
3810 {
3811 fprintf (file, "\tsethi\t%%hi(%d), %s\n", num, reg);
3812 if ((num & 0x3ff) != 0)
3813 fprintf (file, "\tor\t%s, %%lo(%d), %s\n", reg, num, reg);
3814 }
3815 else /* num < 0 && TARGET_ARCH64 */
3816 {
3817 /* Sethi does not sign extend, so we must use a little trickery
3818 to use it for negative numbers. Invert the constant before
3819 loading it in, then use xor immediate to invert the loaded bits
3820 (along with the upper 32 bits) to the desired constant. This
3821 works because the sethi and immediate fields overlap. */
3822 int asize = num;
3823 int inv = ~asize;
3824 int low = -0x400 + (asize & 0x3FF);
3825
3826 fprintf (file, "\tsethi\t%%hi(%d), %s\n\txor\t%s, %d, %s\n",
3827 inv, reg, reg, low, reg);
3828 }
3829 }
3830
3831 /* Output any necessary .register pseudo-ops. */
3832 void
sparc_output_scratch_registers(file)3833 sparc_output_scratch_registers (file)
3834 FILE *file ATTRIBUTE_UNUSED;
3835 {
3836 #ifdef HAVE_AS_REGISTER_PSEUDO_OP
3837 int i;
3838
3839 if (TARGET_ARCH32)
3840 return;
3841
3842 /* Check if %g[2367] were used without
3843 .register being printed for them already. */
3844 for (i = 2; i < 8; i++)
3845 {
3846 if (regs_ever_live [i]
3847 && ! sparc_hard_reg_printed [i])
3848 {
3849 sparc_hard_reg_printed [i] = 1;
3850 fprintf (file, "\t.register\t%%g%d, #scratch\n", i);
3851 }
3852 if (i == 3) i = 5;
3853 }
3854 #endif
3855 }
3856
3857 /* This function generates the assembly code for function entry.
3858 FILE is a stdio stream to output the code to.
3859 SIZE is an int: how many units of temporary storage to allocate.
3860 Refer to the array `regs_ever_live' to determine which registers
3861 to save; `regs_ever_live[I]' is nonzero if register number I
3862 is ever used in the function. This macro is responsible for
3863 knowing which registers should not be saved even if used. */
3864
3865 /* On SPARC, move-double insns between fpu and cpu need an 8-byte block
3866 of memory. If any fpu reg is used in the function, we allocate
3867 such a block here, at the bottom of the frame, just in case it's needed.
3868
3869 If this function is a leaf procedure, then we may choose not
3870 to do a "save" insn. The decision about whether or not
3871 to do this is made in regclass.c. */
3872
3873 static void
sparc_output_function_prologue(file,size)3874 sparc_output_function_prologue (file, size)
3875 FILE *file;
3876 HOST_WIDE_INT size;
3877 {
3878 if (warn_stack_larger_than &&
3879 SPARC_STACK_ALIGN (size) > stack_larger_than_size)
3880 warning ("stack usage is %d bytes", SPARC_STACK_ALIGN (size));
3881
3882 if (TARGET_FLAT)
3883 sparc_flat_function_prologue (file, size);
3884 else
3885 sparc_nonflat_function_prologue (file, size,
3886 current_function_uses_only_leaf_regs);
3887 }
3888
3889 /* Output code for the function prologue. */
3890
3891 static void
sparc_nonflat_function_prologue(file,size,leaf_function)3892 sparc_nonflat_function_prologue (file, size, leaf_function)
3893 FILE *file;
3894 HOST_WIDE_INT size;
3895 int leaf_function;
3896 {
3897 sparc_output_scratch_registers (file);
3898
3899 /* Need to use actual_fsize, since we are also allocating
3900 space for our callee (and our own register save area). */
3901 actual_fsize = compute_frame_size (size, leaf_function);
3902
3903 if (leaf_function)
3904 {
3905 frame_base_name = "%sp";
3906 frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
3907 }
3908 else
3909 {
3910 frame_base_name = "%fp";
3911 frame_base_offset = SPARC_STACK_BIAS;
3912 }
3913
3914 /* This is only for the human reader. */
3915 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
3916
3917 if (actual_fsize == 0)
3918 /* do nothing. */ ;
3919 else if (! leaf_function)
3920 {
3921 if (actual_fsize <= 4096)
3922 fprintf (file, "\tsave\t%%sp, -%d, %%sp\n", actual_fsize);
3923 else if (actual_fsize <= 8192)
3924 {
3925 fprintf (file, "\tsave\t%%sp, -4096, %%sp\n");
3926 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3927 }
3928 else
3929 {
3930 build_big_number (file, -actual_fsize, "%g1");
3931 fprintf (file, "\tsave\t%%sp, %%g1, %%sp\n");
3932 }
3933 }
3934 else /* leaf function */
3935 {
3936 if (actual_fsize <= 4096)
3937 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize);
3938 else if (actual_fsize <= 8192)
3939 {
3940 fprintf (file, "\tadd\t%%sp, -4096, %%sp\n");
3941 fprintf (file, "\tadd\t%%sp, -%d, %%sp\n", actual_fsize - 4096);
3942 }
3943 else
3944 {
3945 build_big_number (file, -actual_fsize, "%g1");
3946 fprintf (file, "\tadd\t%%sp, %%g1, %%sp\n");
3947 }
3948 }
3949
3950 if (dwarf2out_do_frame () && actual_fsize)
3951 {
3952 char *label = dwarf2out_cfi_label ();
3953
3954 /* The canonical frame address refers to the top of the frame. */
3955 dwarf2out_def_cfa (label, (leaf_function ? STACK_POINTER_REGNUM
3956 : HARD_FRAME_POINTER_REGNUM),
3957 frame_base_offset);
3958
3959 if (! leaf_function)
3960 {
3961 /* Note the register window save. This tells the unwinder that
3962 it needs to restore the window registers from the previous
3963 frame's window save area at 0(cfa). */
3964 dwarf2out_window_save (label);
3965
3966 /* The return address (-8) is now in %i7. */
3967 dwarf2out_return_reg (label, 31);
3968 }
3969 }
3970
3971 /* If doing anything with PIC, do it now. */
3972 if (! flag_pic)
3973 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
3974
3975 /* Call saved registers are saved just above the outgoing argument area. */
3976 if (num_gfregs)
3977 {
3978 int offset, real_offset, n_regs;
3979 const char *base;
3980
3981 real_offset = -apparent_fsize;
3982 offset = -apparent_fsize + frame_base_offset;
3983 if (offset < -4096 || offset + num_gfregs * 4 > 4096)
3984 {
3985 /* ??? This might be optimized a little as %g1 might already have a
3986 value close enough that a single add insn will do. */
3987 /* ??? Although, all of this is probably only a temporary fix
3988 because if %g1 can hold a function result, then
3989 output_function_epilogue will lose (the result will get
3990 clobbered). */
3991 build_big_number (file, offset, "%g1");
3992 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
3993 base = "%g1";
3994 offset = 0;
3995 }
3996 else
3997 {
3998 base = frame_base_name;
3999 }
4000
4001 n_regs = save_regs (file, 0, 8, base, offset, 0, real_offset);
4002 save_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs,
4003 real_offset);
4004 }
4005 }
4006
4007 /* Output code to restore any call saved registers. */
4008
4009 static void
output_restore_regs(file,leaf_function)4010 output_restore_regs (file, leaf_function)
4011 FILE *file;
4012 int leaf_function ATTRIBUTE_UNUSED;
4013 {
4014 int offset, n_regs;
4015 const char *base;
4016
4017 offset = -apparent_fsize + frame_base_offset;
4018 if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/)
4019 {
4020 build_big_number (file, offset, "%g1");
4021 fprintf (file, "\tadd\t%s, %%g1, %%g1\n", frame_base_name);
4022 base = "%g1";
4023 offset = 0;
4024 }
4025 else
4026 {
4027 base = frame_base_name;
4028 }
4029
4030 n_regs = restore_regs (file, 0, 8, base, offset, 0);
4031 restore_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs);
4032 }
4033
4034 /* This function generates the assembly code for function exit,
4035 on machines that need it.
4036
4037 The function epilogue should not depend on the current stack pointer!
4038 It should use the frame pointer only. This is mandatory because
4039 of alloca; we also take advantage of it to omit stack adjustments
4040 before returning. */
4041
4042 static void
sparc_output_function_epilogue(file,size)4043 sparc_output_function_epilogue (file, size)
4044 FILE *file;
4045 HOST_WIDE_INT size;
4046 {
4047 if (TARGET_FLAT)
4048 sparc_flat_function_epilogue (file, size);
4049 else
4050 sparc_nonflat_function_epilogue (file, size,
4051 current_function_uses_only_leaf_regs);
4052 }
4053
4054 /* Output code for the function epilogue. */
4055
4056 static void
sparc_nonflat_function_epilogue(file,size,leaf_function)4057 sparc_nonflat_function_epilogue (file, size, leaf_function)
4058 FILE *file;
4059 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
4060 int leaf_function;
4061 {
4062 const char *ret;
4063
4064 if (current_function_epilogue_delay_list == 0)
4065 {
4066 /* If code does not drop into the epilogue, we need
4067 do nothing except output pending case vectors.
4068
4069 We have to still output a dummy nop for the sake of
4070 sane backtraces. Otherwise, if the last two instructions
4071 of a function were call foo; dslot; this can make the return
4072 PC of foo (ie. address of call instruction plus 8) point to
4073 the first instruction in the next function. */
4074 rtx insn, last_real_insn;
4075
4076 insn = get_last_insn ();
4077
4078 last_real_insn = prev_real_insn (insn);
4079 if (last_real_insn
4080 && GET_CODE (last_real_insn) == INSN
4081 && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE)
4082 last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0);
4083
4084 if (last_real_insn && GET_CODE (last_real_insn) == CALL_INSN)
4085 fputs("\tnop\n", file);
4086
4087 if (GET_CODE (insn) == NOTE)
4088 insn = prev_nonnote_insn (insn);
4089 if (insn && GET_CODE (insn) == BARRIER)
4090 goto output_vectors;
4091 }
4092
4093 if (num_gfregs)
4094 output_restore_regs (file, leaf_function);
4095
4096 /* Work out how to skip the caller's unimp instruction if required. */
4097 if (leaf_function)
4098 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%o7+12" : "retl");
4099 else
4100 ret = (SKIP_CALLERS_UNIMP_P ? "jmp\t%i7+12" : "ret");
4101
4102 if (! leaf_function)
4103 {
4104 if (current_function_calls_eh_return)
4105 {
4106 if (current_function_epilogue_delay_list)
4107 abort ();
4108 if (SKIP_CALLERS_UNIMP_P)
4109 abort ();
4110
4111 fputs ("\trestore\n\tretl\n\tadd\t%sp, %g1, %sp\n", file);
4112 }
4113 /* If we wound up with things in our delay slot, flush them here. */
4114 else if (current_function_epilogue_delay_list)
4115 {
4116 rtx delay = PATTERN (XEXP (current_function_epilogue_delay_list, 0));
4117
4118 if (TARGET_V9 && ! epilogue_renumber (&delay, 1))
4119 {
4120 epilogue_renumber (&delay, 0);
4121 fputs (SKIP_CALLERS_UNIMP_P
4122 ? "\treturn\t%i7+12\n"
4123 : "\treturn\t%i7+8\n", file);
4124 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
4125 file, 1, 0, 0);
4126 }
4127 else
4128 {
4129 rtx insn, src;
4130
4131 if (GET_CODE (delay) != SET)
4132 abort();
4133
4134 src = SET_SRC (delay);
4135 if (GET_CODE (src) == ASHIFT)
4136 {
4137 if (XEXP (src, 1) != const1_rtx)
4138 abort();
4139 SET_SRC (delay)
4140 = gen_rtx_PLUS (GET_MODE (src), XEXP (src, 0),
4141 XEXP (src, 0));
4142 }
4143
4144 insn = gen_rtx_PARALLEL (VOIDmode,
4145 gen_rtvec (2, delay,
4146 gen_rtx_RETURN (VOIDmode)));
4147 insn = emit_jump_insn (insn);
4148
4149 sparc_emitting_epilogue = true;
4150 final_scan_insn (insn, file, 1, 0, 1);
4151 sparc_emitting_epilogue = false;
4152 }
4153 }
4154 else if (TARGET_V9 && ! SKIP_CALLERS_UNIMP_P)
4155 fputs ("\treturn\t%i7+8\n\tnop\n", file);
4156 else
4157 fprintf (file, "\t%s\n\trestore\n", ret);
4158 }
4159 /* All of the following cases are for leaf functions. */
4160 else if (current_function_calls_eh_return)
4161 abort ();
4162 else if (current_function_epilogue_delay_list)
4163 {
4164 /* eligible_for_epilogue_delay_slot ensures that if this is a
4165 leaf function, then we will only have insn in the delay slot
4166 if the frame size is zero, thus no adjust for the stack is
4167 needed here. */
4168 if (actual_fsize != 0)
4169 abort ();
4170 fprintf (file, "\t%s\n", ret);
4171 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
4172 file, 1, 0, 1);
4173 }
4174 /* Output 'nop' instead of 'sub %sp,-0,%sp' when no frame, so as to
4175 avoid generating confusing assembly language output. */
4176 else if (actual_fsize == 0)
4177 fprintf (file, "\t%s\n\tnop\n", ret);
4178 else if (actual_fsize <= 4096)
4179 fprintf (file, "\t%s\n\tsub\t%%sp, -%d, %%sp\n", ret, actual_fsize);
4180 else if (actual_fsize <= 8192)
4181 fprintf (file, "\tsub\t%%sp, -4096, %%sp\n\t%s\n\tsub\t%%sp, -%d, %%sp\n",
4182 ret, actual_fsize - 4096);
4183 else if ((actual_fsize & 0x3ff) == 0)
4184 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
4185 actual_fsize, ret);
4186 else
4187 fprintf (file, "\tsethi\t%%hi(%d), %%g1\n\tor\t%%g1, %%lo(%d), %%g1\n\t%s\n\tadd\t%%sp, %%g1, %%sp\n",
4188 actual_fsize, actual_fsize, ret);
4189
4190 output_vectors:
4191 sparc_output_deferred_case_vectors ();
4192 }
4193
4194 /* Output a sibling call. */
4195
4196 const char *
output_sibcall(insn,call_operand)4197 output_sibcall (insn, call_operand)
4198 rtx insn, call_operand;
4199 {
4200 int leaf_regs = current_function_uses_only_leaf_regs;
4201 rtx operands[3];
4202 int delay_slot = dbr_sequence_length () > 0;
4203
4204 if (num_gfregs)
4205 {
4206 /* Call to restore global regs might clobber
4207 the delay slot. Instead of checking for this
4208 output the delay slot now. */
4209 if (delay_slot)
4210 {
4211 rtx delay = NEXT_INSN (insn);
4212
4213 if (! delay)
4214 abort ();
4215
4216 final_scan_insn (delay, asm_out_file, 1, 0, 1);
4217 PATTERN (delay) = gen_blockage ();
4218 INSN_CODE (delay) = -1;
4219 delay_slot = 0;
4220 }
4221 output_restore_regs (asm_out_file, leaf_regs);
4222 }
4223
4224 operands[0] = call_operand;
4225
4226 if (leaf_regs)
4227 {
4228 #ifdef HAVE_AS_RELAX_OPTION
4229 /* If as and ld are relaxing tail call insns into branch always,
4230 use or %o7,%g0,X; call Y; or X,%g0,%o7 always, so that it can
4231 be optimized. With sethi/jmpl as nor ld has no easy way how to
4232 find out if somebody does not branch between the sethi and jmpl. */
4233 int spare_slot = 0;
4234 #else
4235 int spare_slot = ((TARGET_ARCH32 || TARGET_CM_MEDLOW) && ! flag_pic);
4236 #endif
4237 int size = 0;
4238
4239 if ((actual_fsize || ! spare_slot) && delay_slot)
4240 {
4241 rtx delay = NEXT_INSN (insn);
4242
4243 if (! delay)
4244 abort ();
4245
4246 final_scan_insn (delay, asm_out_file, 1, 0, 1);
4247 PATTERN (delay) = gen_blockage ();
4248 INSN_CODE (delay) = -1;
4249 delay_slot = 0;
4250 }
4251 if (actual_fsize)
4252 {
4253 if (actual_fsize <= 4096)
4254 size = actual_fsize;
4255 else if (actual_fsize <= 8192)
4256 {
4257 fputs ("\tsub\t%sp, -4096, %sp\n", asm_out_file);
4258 size = actual_fsize - 4096;
4259 }
4260 else if ((actual_fsize & 0x3ff) == 0)
4261 fprintf (asm_out_file,
4262 "\tsethi\t%%hi(%d), %%g1\n\tadd\t%%sp, %%g1, %%sp\n",
4263 actual_fsize);
4264 else
4265 {
4266 fprintf (asm_out_file,
4267 "\tsethi\t%%hi(%d), %%g1\n\tor\t%%g1, %%lo(%d), %%g1\n",
4268 actual_fsize, actual_fsize);
4269 fputs ("\tadd\t%%sp, %%g1, %%sp\n", asm_out_file);
4270 }
4271 }
4272 if (spare_slot)
4273 {
4274 output_asm_insn ("sethi\t%%hi(%a0), %%g1", operands);
4275 output_asm_insn ("jmpl\t%%g1 + %%lo(%a0), %%g0", operands);
4276 if (size)
4277 fprintf (asm_out_file, "\t sub\t%%sp, -%d, %%sp\n", size);
4278 else if (! delay_slot)
4279 fputs ("\t nop\n", asm_out_file);
4280 }
4281 else
4282 {
4283 if (size)
4284 fprintf (asm_out_file, "\tsub\t%%sp, -%d, %%sp\n", size);
4285 /* Use or with rs2 %%g0 instead of mov, so that as/ld can optimize
4286 it into branch if possible. */
4287 output_asm_insn ("or\t%%o7, %%g0, %%g1", operands);
4288 output_asm_insn ("call\t%a0, 0", operands);
4289 output_asm_insn (" or\t%%g1, %%g0, %%o7", operands);
4290 }
4291 return "";
4292 }
4293
4294 output_asm_insn ("call\t%a0, 0", operands);
4295 if (delay_slot)
4296 {
4297 rtx delay = NEXT_INSN (insn), pat;
4298
4299 if (! delay)
4300 abort ();
4301
4302 pat = PATTERN (delay);
4303 if (GET_CODE (pat) != SET)
4304 abort ();
4305
4306 operands[0] = SET_DEST (pat);
4307 pat = SET_SRC (pat);
4308 switch (GET_CODE (pat))
4309 {
4310 case PLUS:
4311 operands[1] = XEXP (pat, 0);
4312 operands[2] = XEXP (pat, 1);
4313 output_asm_insn (" restore %r1, %2, %Y0", operands);
4314 break;
4315 case LO_SUM:
4316 operands[1] = XEXP (pat, 0);
4317 operands[2] = XEXP (pat, 1);
4318 output_asm_insn (" restore %r1, %%lo(%a2), %Y0", operands);
4319 break;
4320 case ASHIFT:
4321 operands[1] = XEXP (pat, 0);
4322 output_asm_insn (" restore %r1, %r1, %Y0", operands);
4323 break;
4324 default:
4325 operands[1] = pat;
4326 output_asm_insn (" restore %%g0, %1, %Y0", operands);
4327 break;
4328 }
4329 PATTERN (delay) = gen_blockage ();
4330 INSN_CODE (delay) = -1;
4331 }
4332 else
4333 fputs ("\t restore\n", asm_out_file);
4334 return "";
4335 }
4336
4337 /* Functions for handling argument passing.
4338
4339 For v8 the first six args are normally in registers and the rest are
4340 pushed. Any arg that starts within the first 6 words is at least
4341 partially passed in a register unless its data type forbids.
4342
4343 For v9, the argument registers are laid out as an array of 16 elements
4344 and arguments are added sequentially. The first 6 int args and up to the
4345 first 16 fp args (depending on size) are passed in regs.
4346
4347 Slot Stack Integral Float Float in structure Double Long Double
4348 ---- ----- -------- ----- ------------------ ------ -----------
4349 15 [SP+248] %f31 %f30,%f31 %d30
4350 14 [SP+240] %f29 %f28,%f29 %d28 %q28
4351 13 [SP+232] %f27 %f26,%f27 %d26
4352 12 [SP+224] %f25 %f24,%f25 %d24 %q24
4353 11 [SP+216] %f23 %f22,%f23 %d22
4354 10 [SP+208] %f21 %f20,%f21 %d20 %q20
4355 9 [SP+200] %f19 %f18,%f19 %d18
4356 8 [SP+192] %f17 %f16,%f17 %d16 %q16
4357 7 [SP+184] %f15 %f14,%f15 %d14
4358 6 [SP+176] %f13 %f12,%f13 %d12 %q12
4359 5 [SP+168] %o5 %f11 %f10,%f11 %d10
4360 4 [SP+160] %o4 %f9 %f8,%f9 %d8 %q8
4361 3 [SP+152] %o3 %f7 %f6,%f7 %d6
4362 2 [SP+144] %o2 %f5 %f4,%f5 %d4 %q4
4363 1 [SP+136] %o1 %f3 %f2,%f3 %d2
4364 0 [SP+128] %o0 %f1 %f0,%f1 %d0 %q0
4365
4366 Here SP = %sp if -mno-stack-bias or %sp+stack_bias otherwise.
4367
4368 Integral arguments are always passed as 64 bit quantities appropriately
4369 extended.
4370
4371 Passing of floating point values is handled as follows.
4372 If a prototype is in scope:
4373 If the value is in a named argument (i.e. not a stdarg function or a
4374 value not part of the `...') then the value is passed in the appropriate
4375 fp reg.
4376 If the value is part of the `...' and is passed in one of the first 6
4377 slots then the value is passed in the appropriate int reg.
4378 If the value is part of the `...' and is not passed in one of the first 6
4379 slots then the value is passed in memory.
4380 If a prototype is not in scope:
4381 If the value is one of the first 6 arguments the value is passed in the
4382 appropriate integer reg and the appropriate fp reg.
4383 If the value is not one of the first 6 arguments the value is passed in
4384 the appropriate fp reg and in memory.
4385 */
4386
4387 /* Maximum number of int regs for args. */
4388 #define SPARC_INT_ARG_MAX 6
4389 /* Maximum number of fp regs for args. */
4390 #define SPARC_FP_ARG_MAX 16
4391
4392 #define ROUND_ADVANCE(SIZE) (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
4393
4394 /* Handle the INIT_CUMULATIVE_ARGS macro.
4395 Initialize a variable CUM of type CUMULATIVE_ARGS
4396 for a call to a function whose data type is FNTYPE.
4397 For a library call, FNTYPE is 0. */
4398
4399 void
init_cumulative_args(cum,fntype,libname,indirect)4400 init_cumulative_args (cum, fntype, libname, indirect)
4401 CUMULATIVE_ARGS *cum;
4402 tree fntype;
4403 rtx libname ATTRIBUTE_UNUSED;
4404 int indirect ATTRIBUTE_UNUSED;
4405 {
4406 cum->words = 0;
4407 cum->prototype_p = fntype && TYPE_ARG_TYPES (fntype);
4408 cum->libcall_p = fntype == 0;
4409 }
4410
4411 /* Compute the slot number to pass an argument in.
4412 Returns the slot number or -1 if passing on the stack.
4413
4414 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4415 the preceding args and about the function being called.
4416 MODE is the argument's machine mode.
4417 TYPE is the data type of the argument (as a tree).
4418 This is null for libcalls where that information may
4419 not be available.
4420 NAMED is nonzero if this argument is a named parameter
4421 (otherwise it is an extra parameter matching an ellipsis).
4422 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG.
4423 *PREGNO records the register number to use if scalar type.
4424 *PPADDING records the amount of padding needed in words. */
4425
4426 static int
function_arg_slotno(cum,mode,type,named,incoming_p,pregno,ppadding)4427 function_arg_slotno (cum, mode, type, named, incoming_p, pregno, ppadding)
4428 const CUMULATIVE_ARGS *cum;
4429 enum machine_mode mode;
4430 tree type;
4431 int named;
4432 int incoming_p;
4433 int *pregno;
4434 int *ppadding;
4435 {
4436 int regbase = (incoming_p
4437 ? SPARC_INCOMING_INT_ARG_FIRST
4438 : SPARC_OUTGOING_INT_ARG_FIRST);
4439 int slotno = cum->words;
4440 int regno;
4441
4442 *ppadding = 0;
4443
4444 if (type != 0 && TREE_ADDRESSABLE (type))
4445 return -1;
4446 if (TARGET_ARCH32
4447 && type != 0 && mode == BLKmode
4448 && TYPE_ALIGN (type) % PARM_BOUNDARY != 0)
4449 return -1;
4450
4451 switch (mode)
4452 {
4453 case VOIDmode :
4454 /* MODE is VOIDmode when generating the actual call.
4455 See emit_call_1. */
4456 return -1;
4457
4458 case QImode : case CQImode :
4459 case HImode : case CHImode :
4460 case SImode : case CSImode :
4461 case DImode : case CDImode :
4462 case TImode : case CTImode :
4463 if (slotno >= SPARC_INT_ARG_MAX)
4464 return -1;
4465 regno = regbase + slotno;
4466 break;
4467
4468 case SFmode : case SCmode :
4469 case DFmode : case DCmode :
4470 case TFmode : case TCmode :
4471 if (TARGET_ARCH32)
4472 {
4473 if (slotno >= SPARC_INT_ARG_MAX)
4474 return -1;
4475 regno = regbase + slotno;
4476 }
4477 else
4478 {
4479 if ((mode == TFmode || mode == TCmode)
4480 && (slotno & 1) != 0)
4481 slotno++, *ppadding = 1;
4482 if (TARGET_FPU && named)
4483 {
4484 if (slotno >= SPARC_FP_ARG_MAX)
4485 return -1;
4486 regno = SPARC_FP_ARG_FIRST + slotno * 2;
4487 if (mode == SFmode)
4488 regno++;
4489 }
4490 else
4491 {
4492 if (slotno >= SPARC_INT_ARG_MAX)
4493 return -1;
4494 regno = regbase + slotno;
4495 }
4496 }
4497 break;
4498
4499 case BLKmode :
4500 /* For sparc64, objects requiring 16 byte alignment get it. */
4501 if (TARGET_ARCH64)
4502 {
4503 if (type && TYPE_ALIGN (type) == 128 && (slotno & 1) != 0)
4504 slotno++, *ppadding = 1;
4505 }
4506
4507 if (TARGET_ARCH32
4508 || (type && TREE_CODE (type) == UNION_TYPE))
4509 {
4510 if (slotno >= SPARC_INT_ARG_MAX)
4511 return -1;
4512 regno = regbase + slotno;
4513 }
4514 else
4515 {
4516 tree field;
4517 int intregs_p = 0, fpregs_p = 0;
4518 /* The ABI obviously doesn't specify how packed
4519 structures are passed. These are defined to be passed
4520 in int regs if possible, otherwise memory. */
4521 int packed_p = 0;
4522
4523 /* First see what kinds of registers we need. */
4524 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4525 {
4526 if (TREE_CODE (field) == FIELD_DECL)
4527 {
4528 if (TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4529 && TARGET_FPU)
4530 fpregs_p = 1;
4531 else
4532 intregs_p = 1;
4533 if (DECL_PACKED (field))
4534 packed_p = 1;
4535 }
4536 }
4537 if (packed_p || !named)
4538 fpregs_p = 0, intregs_p = 1;
4539
4540 /* If all arg slots are filled, then must pass on stack. */
4541 if (fpregs_p && slotno >= SPARC_FP_ARG_MAX)
4542 return -1;
4543 /* If there are only int args and all int arg slots are filled,
4544 then must pass on stack. */
4545 if (!fpregs_p && intregs_p && slotno >= SPARC_INT_ARG_MAX)
4546 return -1;
4547 /* Note that even if all int arg slots are filled, fp members may
4548 still be passed in regs if such regs are available.
4549 *PREGNO isn't set because there may be more than one, it's up
4550 to the caller to compute them. */
4551 return slotno;
4552 }
4553 break;
4554
4555 default :
4556 abort ();
4557 }
4558
4559 *pregno = regno;
4560 return slotno;
4561 }
4562
4563 /* Handle recursive register counting for structure field layout. */
4564
4565 struct function_arg_record_value_parms
4566 {
4567 rtx ret; /* return expression being built. */
4568 int slotno; /* slot number of the argument. */
4569 int named; /* whether the argument is named. */
4570 int regbase; /* regno of the base register. */
4571 int stack; /* 1 if part of the argument is on the stack. */
4572 int intoffset; /* offset of the pending integer field. */
4573 unsigned int nregs; /* number of words passed in registers. */
4574 };
4575
4576 static void function_arg_record_value_3
4577 PARAMS ((HOST_WIDE_INT, struct function_arg_record_value_parms *));
4578 static void function_arg_record_value_2
4579 PARAMS ((tree, HOST_WIDE_INT,
4580 struct function_arg_record_value_parms *));
4581 static void function_arg_record_value_1
4582 PARAMS ((tree, HOST_WIDE_INT,
4583 struct function_arg_record_value_parms *));
4584 static rtx function_arg_record_value
4585 PARAMS ((tree, enum machine_mode, int, int, int));
4586
4587 /* A subroutine of function_arg_record_value. Traverse the structure
4588 recusively and determine how many registers will be required. */
4589
4590 static void
function_arg_record_value_1(type,startbitpos,parms)4591 function_arg_record_value_1 (type, startbitpos, parms)
4592 tree type;
4593 HOST_WIDE_INT startbitpos;
4594 struct function_arg_record_value_parms *parms;
4595 {
4596 tree field;
4597
4598 /* The ABI obviously doesn't specify how packed structures are
4599 passed. These are defined to be passed in int regs if possible,
4600 otherwise memory. */
4601 int packed_p = 0;
4602
4603 /* We need to compute how many registers are needed so we can
4604 allocate the PARALLEL but before we can do that we need to know
4605 whether there are any packed fields. If there are, int regs are
4606 used regardless of whether there are fp values present. */
4607 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4608 {
4609 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4610 {
4611 packed_p = 1;
4612 break;
4613 }
4614 }
4615
4616 /* Compute how many registers we need. */
4617 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4618 {
4619 if (TREE_CODE (field) == FIELD_DECL)
4620 {
4621 HOST_WIDE_INT bitpos = startbitpos;
4622
4623 if (DECL_SIZE (field) != 0
4624 && host_integerp (bit_position (field), 1))
4625 bitpos += int_bit_position (field);
4626
4627 /* ??? FIXME: else assume zero offset. */
4628
4629 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4630 function_arg_record_value_1 (TREE_TYPE (field), bitpos, parms);
4631 else if ((TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4632 || (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE
4633 && (TREE_CODE (TREE_TYPE (TREE_TYPE (field)))
4634 == REAL_TYPE)))
4635 && TARGET_FPU
4636 && ! packed_p
4637 && parms->named)
4638 {
4639 if (parms->intoffset != -1)
4640 {
4641 int intslots, this_slotno;
4642
4643 intslots = (bitpos - parms->intoffset + BITS_PER_WORD - 1)
4644 / BITS_PER_WORD;
4645 this_slotno = parms->slotno + parms->intoffset
4646 / BITS_PER_WORD;
4647
4648 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
4649 {
4650 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
4651 /* We need to pass this field on the stack. */
4652 parms->stack = 1;
4653 }
4654
4655 parms->nregs += intslots;
4656 parms->intoffset = -1;
4657 }
4658
4659 /* There's no need to check this_slotno < SPARC_FP_ARG MAX.
4660 If it wasn't true we wouldn't be here. */
4661 parms->nregs += 1;
4662 if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
4663 parms->nregs += 1;
4664 }
4665 else
4666 {
4667 if (parms->intoffset == -1)
4668 parms->intoffset = bitpos;
4669 }
4670 }
4671 }
4672 }
4673
4674 /* A subroutine of function_arg_record_value. Assign the bits of the
4675 structure between parms->intoffset and bitpos to integer registers. */
4676
4677 static void
function_arg_record_value_3(bitpos,parms)4678 function_arg_record_value_3 (bitpos, parms)
4679 HOST_WIDE_INT bitpos;
4680 struct function_arg_record_value_parms *parms;
4681 {
4682 enum machine_mode mode;
4683 unsigned int regno;
4684 unsigned int startbit, endbit;
4685 int this_slotno, intslots, intoffset;
4686 rtx reg;
4687
4688 if (parms->intoffset == -1)
4689 return;
4690
4691 intoffset = parms->intoffset;
4692 parms->intoffset = -1;
4693
4694 startbit = intoffset & -BITS_PER_WORD;
4695 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4696 intslots = (endbit - startbit) / BITS_PER_WORD;
4697 this_slotno = parms->slotno + intoffset / BITS_PER_WORD;
4698
4699 intslots = MIN (intslots, SPARC_INT_ARG_MAX - this_slotno);
4700 if (intslots <= 0)
4701 return;
4702
4703 /* If this is the trailing part of a word, only load that much into
4704 the register. Otherwise load the whole register. Note that in
4705 the latter case we may pick up unwanted bits. It's not a problem
4706 at the moment but may wish to revisit. */
4707
4708 if (intoffset % BITS_PER_WORD != 0)
4709 mode = mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
4710 MODE_INT, 0);
4711 else
4712 mode = word_mode;
4713
4714 intoffset /= BITS_PER_UNIT;
4715 do
4716 {
4717 regno = parms->regbase + this_slotno;
4718 reg = gen_rtx_REG (mode, regno);
4719 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
4720 = gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
4721
4722 this_slotno += 1;
4723 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
4724 parms->nregs += 1;
4725 intslots -= 1;
4726 }
4727 while (intslots > 0);
4728 }
4729
4730 /* A subroutine of function_arg_record_value. Traverse the structure
4731 recursively and assign bits to floating point registers. Track which
4732 bits in between need integer registers; invoke function_arg_record_value_3
4733 to make that happen. */
4734
4735 static void
function_arg_record_value_2(type,startbitpos,parms)4736 function_arg_record_value_2 (type, startbitpos, parms)
4737 tree type;
4738 HOST_WIDE_INT startbitpos;
4739 struct function_arg_record_value_parms *parms;
4740 {
4741 tree field;
4742 int packed_p = 0;
4743
4744 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4745 {
4746 if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
4747 {
4748 packed_p = 1;
4749 break;
4750 }
4751 }
4752
4753 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4754 {
4755 if (TREE_CODE (field) == FIELD_DECL)
4756 {
4757 HOST_WIDE_INT bitpos = startbitpos;
4758
4759 if (DECL_SIZE (field) != 0
4760 && host_integerp (bit_position (field), 1))
4761 bitpos += int_bit_position (field);
4762
4763 /* ??? FIXME: else assume zero offset. */
4764
4765 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
4766 function_arg_record_value_2 (TREE_TYPE (field), bitpos, parms);
4767 else if ((TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
4768 || (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE
4769 && (TREE_CODE (TREE_TYPE (TREE_TYPE (field)))
4770 == REAL_TYPE)))
4771 && TARGET_FPU
4772 && ! packed_p
4773 && parms->named)
4774 {
4775 int this_slotno = parms->slotno + bitpos / BITS_PER_WORD;
4776 int regno;
4777 enum machine_mode mode = DECL_MODE (field);
4778 rtx reg;
4779
4780 function_arg_record_value_3 (bitpos, parms);
4781 regno = SPARC_FP_ARG_FIRST + this_slotno * 2
4782 + ((mode == SFmode || mode == SCmode)
4783 && (bitpos & 32) != 0);
4784 switch (mode)
4785 {
4786 case SCmode: mode = SFmode; break;
4787 case DCmode: mode = DFmode; break;
4788 case TCmode: mode = TFmode; break;
4789 default: break;
4790 }
4791 reg = gen_rtx_REG (mode, regno);
4792 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
4793 = gen_rtx_EXPR_LIST (VOIDmode, reg,
4794 GEN_INT (bitpos / BITS_PER_UNIT));
4795 parms->nregs += 1;
4796 if (TREE_CODE (TREE_TYPE (field)) == COMPLEX_TYPE)
4797 {
4798 regno += GET_MODE_SIZE (mode) / 4;
4799 reg = gen_rtx_REG (mode, regno);
4800 XVECEXP (parms->ret, 0, parms->stack + parms->nregs)
4801 = gen_rtx_EXPR_LIST (VOIDmode, reg,
4802 GEN_INT ((bitpos + GET_MODE_BITSIZE (mode))
4803 / BITS_PER_UNIT));
4804 parms->nregs += 1;
4805 }
4806 }
4807 else
4808 {
4809 if (parms->intoffset == -1)
4810 parms->intoffset = bitpos;
4811 }
4812 }
4813 }
4814 }
4815
4816 /* Used by function_arg and function_value to implement the complex
4817 conventions of the 64-bit ABI for passing and returning structures.
4818 Return an expression valid as a return value for the two macros
4819 FUNCTION_ARG and FUNCTION_VALUE.
4820
4821 TYPE is the data type of the argument (as a tree).
4822 This is null for libcalls where that information may
4823 not be available.
4824 MODE is the argument's machine mode.
4825 SLOTNO is the index number of the argument's slot in the parameter array.
4826 NAMED is nonzero if this argument is a named parameter
4827 (otherwise it is an extra parameter matching an ellipsis).
4828 REGBASE is the regno of the base register for the parameter array. */
4829
4830 static rtx
function_arg_record_value(type,mode,slotno,named,regbase)4831 function_arg_record_value (type, mode, slotno, named, regbase)
4832 tree type;
4833 enum machine_mode mode;
4834 int slotno, named, regbase;
4835 {
4836 HOST_WIDE_INT typesize = int_size_in_bytes (type);
4837 struct function_arg_record_value_parms parms;
4838 unsigned int nregs;
4839
4840 parms.ret = NULL_RTX;
4841 parms.slotno = slotno;
4842 parms.named = named;
4843 parms.regbase = regbase;
4844 parms.stack = 0;
4845
4846 /* Compute how many registers we need. */
4847 parms.nregs = 0;
4848 parms.intoffset = 0;
4849 function_arg_record_value_1 (type, 0, &parms);
4850
4851 if (parms.intoffset != -1)
4852 {
4853 unsigned int startbit, endbit;
4854 int intslots, this_slotno;
4855
4856 startbit = parms.intoffset & -BITS_PER_WORD;
4857 endbit = (typesize*BITS_PER_UNIT + BITS_PER_WORD - 1) & -BITS_PER_WORD;
4858 intslots = (endbit - startbit) / BITS_PER_WORD;
4859 this_slotno = slotno + parms.intoffset / BITS_PER_WORD;
4860
4861 if (intslots > 0 && intslots > SPARC_INT_ARG_MAX - this_slotno)
4862 {
4863 intslots = MAX (0, SPARC_INT_ARG_MAX - this_slotno);
4864 /* We need to pass this field on the stack. */
4865 parms.stack = 1;
4866 }
4867
4868 parms.nregs += intslots;
4869 }
4870 nregs = parms.nregs;
4871
4872 /* Allocate the vector and handle some annoying special cases. */
4873 if (nregs == 0)
4874 {
4875 /* ??? Empty structure has no value? Duh? */
4876 if (typesize <= 0)
4877 {
4878 /* Though there's nothing really to store, return a word register
4879 anyway so the rest of gcc doesn't go nuts. Returning a PARALLEL
4880 leads to breakage due to the fact that there are zero bytes to
4881 load. */
4882 return gen_rtx_REG (mode, regbase);
4883 }
4884 else
4885 {
4886 /* ??? C++ has structures with no fields, and yet a size. Give up
4887 for now and pass everything back in integer registers. */
4888 nregs = (typesize + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4889 }
4890 if (nregs + slotno > SPARC_INT_ARG_MAX)
4891 nregs = SPARC_INT_ARG_MAX - slotno;
4892 }
4893 if (nregs == 0)
4894 abort ();
4895
4896 parms.ret = gen_rtx_PARALLEL (mode, rtvec_alloc (parms.stack + nregs));
4897
4898 /* If at least one field must be passed on the stack, generate
4899 (parallel [(expr_list (nil) ...) ...]) so that all fields will
4900 also be passed on the stack. We can't do much better because the
4901 semantics of FUNCTION_ARG_PARTIAL_NREGS doesn't handle the case
4902 of structures for which the fields passed exclusively in registers
4903 are not at the beginning of the structure. */
4904 if (parms.stack)
4905 XVECEXP (parms.ret, 0, 0)
4906 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4907
4908 /* Fill in the entries. */
4909 parms.nregs = 0;
4910 parms.intoffset = 0;
4911 function_arg_record_value_2 (type, 0, &parms);
4912 function_arg_record_value_3 (typesize * BITS_PER_UNIT, &parms);
4913
4914 if (parms.nregs != nregs)
4915 abort ();
4916
4917 return parms.ret;
4918 }
4919
4920 /* Handle the FUNCTION_ARG macro.
4921 Determine where to put an argument to a function.
4922 Value is zero to push the argument on the stack,
4923 or a hard register in which to store the argument.
4924
4925 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4926 the preceding args and about the function being called.
4927 MODE is the argument's machine mode.
4928 TYPE is the data type of the argument (as a tree).
4929 This is null for libcalls where that information may
4930 not be available.
4931 NAMED is nonzero if this argument is a named parameter
4932 (otherwise it is an extra parameter matching an ellipsis).
4933 INCOMING_P is zero for FUNCTION_ARG, nonzero for FUNCTION_INCOMING_ARG. */
4934
4935 rtx
function_arg(cum,mode,type,named,incoming_p)4936 function_arg (cum, mode, type, named, incoming_p)
4937 const CUMULATIVE_ARGS *cum;
4938 enum machine_mode mode;
4939 tree type;
4940 int named;
4941 int incoming_p;
4942 {
4943 int regbase = (incoming_p
4944 ? SPARC_INCOMING_INT_ARG_FIRST
4945 : SPARC_OUTGOING_INT_ARG_FIRST);
4946 int slotno, regno, padding;
4947 rtx reg;
4948
4949 slotno = function_arg_slotno (cum, mode, type, named, incoming_p,
4950 ®no, &padding);
4951
4952 if (slotno == -1)
4953 return 0;
4954
4955 if (TARGET_ARCH32)
4956 {
4957 reg = gen_rtx_REG (mode, regno);
4958 return reg;
4959 }
4960
4961 /* v9 fp args in reg slots beyond the int reg slots get passed in regs
4962 but also have the slot allocated for them.
4963 If no prototype is in scope fp values in register slots get passed
4964 in two places, either fp regs and int regs or fp regs and memory. */
4965 if ((GET_MODE_CLASS (mode) == MODE_FLOAT
4966 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
4967 && SPARC_FP_REG_P (regno))
4968 {
4969 reg = gen_rtx_REG (mode, regno);
4970 if (cum->prototype_p || cum->libcall_p)
4971 {
4972 /* "* 2" because fp reg numbers are recorded in 4 byte
4973 quantities. */
4974 #if 0
4975 /* ??? This will cause the value to be passed in the fp reg and
4976 in the stack. When a prototype exists we want to pass the
4977 value in the reg but reserve space on the stack. That's an
4978 optimization, and is deferred [for a bit]. */
4979 if ((regno - SPARC_FP_ARG_FIRST) >= SPARC_INT_ARG_MAX * 2)
4980 return gen_rtx_PARALLEL (mode,
4981 gen_rtvec (2,
4982 gen_rtx_EXPR_LIST (VOIDmode,
4983 NULL_RTX, const0_rtx),
4984 gen_rtx_EXPR_LIST (VOIDmode,
4985 reg, const0_rtx)));
4986 else
4987 #else
4988 /* ??? It seems that passing back a register even when past
4989 the area declared by REG_PARM_STACK_SPACE will allocate
4990 space appropriately, and will not copy the data onto the
4991 stack, exactly as we desire.
4992
4993 This is due to locate_and_pad_parm being called in
4994 expand_call whenever reg_parm_stack_space > 0, which
4995 while benefical to our example here, would seem to be
4996 in error from what had been intended. Ho hum... -- r~ */
4997 #endif
4998 return reg;
4999 }
5000 else
5001 {
5002 rtx v0, v1;
5003
5004 if ((regno - SPARC_FP_ARG_FIRST) < SPARC_INT_ARG_MAX * 2)
5005 {
5006 int intreg;
5007
5008 /* On incoming, we don't need to know that the value
5009 is passed in %f0 and %i0, and it confuses other parts
5010 causing needless spillage even on the simplest cases. */
5011 if (incoming_p)
5012 return reg;
5013
5014 intreg = (SPARC_OUTGOING_INT_ARG_FIRST
5015 + (regno - SPARC_FP_ARG_FIRST) / 2);
5016
5017 v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5018 v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg),
5019 const0_rtx);
5020 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5021 }
5022 else
5023 {
5024 v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
5025 v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
5026 return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1));
5027 }
5028 }
5029 }
5030 else if (type && TREE_CODE (type) == RECORD_TYPE)
5031 {
5032 /* Structures up to 16 bytes in size are passed in arg slots on the
5033 stack and are promoted to registers where possible. */
5034
5035 if (int_size_in_bytes (type) > 16)
5036 abort (); /* shouldn't get here */
5037
5038 return function_arg_record_value (type, mode, slotno, named, regbase);
5039 }
5040 else if (type && TREE_CODE (type) == UNION_TYPE)
5041 {
5042 enum machine_mode mode;
5043 int bytes = int_size_in_bytes (type);
5044
5045 if (bytes > 16)
5046 abort ();
5047
5048 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
5049 reg = gen_rtx_REG (mode, regno);
5050 }
5051 else
5052 {
5053 /* Scalar or complex int. */
5054 reg = gen_rtx_REG (mode, regno);
5055 }
5056
5057 return reg;
5058 }
5059
5060 /* Handle the FUNCTION_ARG_PARTIAL_NREGS macro.
5061 For an arg passed partly in registers and partly in memory,
5062 this is the number of registers used.
5063 For args passed entirely in registers or entirely in memory, zero.
5064
5065 Any arg that starts in the first 6 regs but won't entirely fit in them
5066 needs partial registers on v8. On v9, structures with integer
5067 values in arg slots 5,6 will be passed in %o5 and SP+176, and complex fp
5068 values that begin in the last fp reg [where "last fp reg" varies with the
5069 mode] will be split between that reg and memory. */
5070
5071 int
function_arg_partial_nregs(cum,mode,type,named)5072 function_arg_partial_nregs (cum, mode, type, named)
5073 const CUMULATIVE_ARGS *cum;
5074 enum machine_mode mode;
5075 tree type;
5076 int named;
5077 {
5078 int slotno, regno, padding;
5079
5080 /* We pass 0 for incoming_p here, it doesn't matter. */
5081 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5082
5083 if (slotno == -1)
5084 return 0;
5085
5086 if (TARGET_ARCH32)
5087 {
5088 if ((slotno + (mode == BLKmode
5089 ? ROUND_ADVANCE (int_size_in_bytes (type))
5090 : ROUND_ADVANCE (GET_MODE_SIZE (mode))))
5091 > NPARM_REGS (SImode))
5092 return NPARM_REGS (SImode) - slotno;
5093 return 0;
5094 }
5095 else
5096 {
5097 if (type && AGGREGATE_TYPE_P (type))
5098 {
5099 int size = int_size_in_bytes (type);
5100 int align = TYPE_ALIGN (type);
5101
5102 if (align == 16)
5103 slotno += slotno & 1;
5104 if (size > 8 && size <= 16
5105 && slotno == SPARC_INT_ARG_MAX - 1)
5106 return 1;
5107 }
5108 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
5109 || (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5110 && ! TARGET_FPU))
5111 {
5112 if (GET_MODE_ALIGNMENT (mode) == 128)
5113 {
5114 slotno += slotno & 1;
5115 if (slotno == SPARC_INT_ARG_MAX - 2)
5116 return 1;
5117 }
5118 else
5119 {
5120 if (slotno == SPARC_INT_ARG_MAX - 1)
5121 return 1;
5122 }
5123 }
5124 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
5125 {
5126 if (GET_MODE_ALIGNMENT (mode) == 128)
5127 slotno += slotno & 1;
5128 if ((slotno + GET_MODE_SIZE (mode) / UNITS_PER_WORD)
5129 > SPARC_FP_ARG_MAX)
5130 return 1;
5131 }
5132 return 0;
5133 }
5134 }
5135
5136 /* Handle the FUNCTION_ARG_PASS_BY_REFERENCE macro.
5137 !v9: The SPARC ABI stipulates passing struct arguments (of any size) and
5138 quad-precision floats by invisible reference.
5139 v9: Aggregates greater than 16 bytes are passed by reference.
5140 For Pascal, also pass arrays by reference. */
5141
5142 int
function_arg_pass_by_reference(cum,mode,type,named)5143 function_arg_pass_by_reference (cum, mode, type, named)
5144 const CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
5145 enum machine_mode mode;
5146 tree type;
5147 int named ATTRIBUTE_UNUSED;
5148 {
5149 if (TARGET_ARCH32)
5150 {
5151 return ((type && AGGREGATE_TYPE_P (type))
5152 || mode == TFmode || mode == TCmode);
5153 }
5154 else
5155 {
5156 return ((type && TREE_CODE (type) == ARRAY_TYPE)
5157 /* Consider complex values as aggregates, so care for TCmode. */
5158 || GET_MODE_SIZE (mode) > 16
5159 || (type
5160 && AGGREGATE_TYPE_P (type)
5161 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 16));
5162 }
5163 }
5164
5165 /* Handle the FUNCTION_ARG_ADVANCE macro.
5166 Update the data in CUM to advance over an argument
5167 of mode MODE and data type TYPE.
5168 TYPE is null for libcalls where that information may not be available. */
5169
5170 void
function_arg_advance(cum,mode,type,named)5171 function_arg_advance (cum, mode, type, named)
5172 CUMULATIVE_ARGS *cum;
5173 enum machine_mode mode;
5174 tree type;
5175 int named;
5176 {
5177 int slotno, regno, padding;
5178
5179 /* We pass 0 for incoming_p here, it doesn't matter. */
5180 slotno = function_arg_slotno (cum, mode, type, named, 0, ®no, &padding);
5181
5182 /* If register required leading padding, add it. */
5183 if (slotno != -1)
5184 cum->words += padding;
5185
5186 if (TARGET_ARCH32)
5187 {
5188 cum->words += (mode != BLKmode
5189 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5190 : ROUND_ADVANCE (int_size_in_bytes (type)));
5191 }
5192 else
5193 {
5194 if (type && AGGREGATE_TYPE_P (type))
5195 {
5196 int size = int_size_in_bytes (type);
5197
5198 if (size <= 8)
5199 ++cum->words;
5200 else if (size <= 16)
5201 cum->words += 2;
5202 else /* passed by reference */
5203 ++cum->words;
5204 }
5205 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
5206 {
5207 cum->words += 2;
5208 }
5209 else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
5210 {
5211 cum->words += GET_MODE_SIZE (mode) / UNITS_PER_WORD;
5212 }
5213 else
5214 {
5215 cum->words += (mode != BLKmode
5216 ? ROUND_ADVANCE (GET_MODE_SIZE (mode))
5217 : ROUND_ADVANCE (int_size_in_bytes (type)));
5218 }
5219 }
5220 }
5221
5222 /* Handle the FUNCTION_ARG_PADDING macro.
5223 For the 64 bit ABI structs are always stored left shifted in their
5224 argument slot. */
5225
5226 enum direction
function_arg_padding(mode,type)5227 function_arg_padding (mode, type)
5228 enum machine_mode mode;
5229 tree type;
5230 {
5231 if (TARGET_ARCH64 && type != 0 && AGGREGATE_TYPE_P (type))
5232 return upward;
5233
5234 /* This is the default definition. */
5235 return (! BYTES_BIG_ENDIAN
5236 ? upward
5237 : ((mode == BLKmode
5238 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
5239 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
5240 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
5241 ? downward : upward));
5242 }
5243
5244 /* Handle FUNCTION_VALUE, FUNCTION_OUTGOING_VALUE, and LIBCALL_VALUE macros.
5245 For v9, function return values are subject to the same rules as arguments,
5246 except that up to 32-bytes may be returned in registers. */
5247
5248 rtx
function_value(type,mode,incoming_p)5249 function_value (type, mode, incoming_p)
5250 tree type;
5251 enum machine_mode mode;
5252 int incoming_p;
5253 {
5254 int regno;
5255 int regbase = (incoming_p
5256 ? SPARC_OUTGOING_INT_ARG_FIRST
5257 : SPARC_INCOMING_INT_ARG_FIRST);
5258
5259 if (TARGET_ARCH64 && type)
5260 {
5261 if (TREE_CODE (type) == RECORD_TYPE)
5262 {
5263 /* Structures up to 32 bytes in size are passed in registers,
5264 promoted to fp registers where possible. */
5265
5266 if (int_size_in_bytes (type) > 32)
5267 abort (); /* shouldn't get here */
5268
5269 return function_arg_record_value (type, mode, 0, 1, regbase);
5270 }
5271 else if (AGGREGATE_TYPE_P (type))
5272 {
5273 /* All other aggregate types are passed in an integer register
5274 in a mode corresponding to the size of the type. */
5275 HOST_WIDE_INT bytes = int_size_in_bytes (type);
5276
5277 if (bytes > 32)
5278 abort ();
5279
5280 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 0);
5281 }
5282 }
5283
5284 if (TARGET_ARCH64
5285 && GET_MODE_CLASS (mode) == MODE_INT
5286 && GET_MODE_SIZE (mode) < UNITS_PER_WORD
5287 && type && ! AGGREGATE_TYPE_P (type))
5288 mode = DImode;
5289
5290 if (incoming_p)
5291 regno = BASE_RETURN_VALUE_REG (mode);
5292 else
5293 regno = BASE_OUTGOING_VALUE_REG (mode);
5294
5295 return gen_rtx_REG (mode, regno);
5296 }
5297
5298 /* Do what is necessary for `va_start'. We look at the current function
5299 to determine if stdarg or varargs is used and return the address of
5300 the first unnamed parameter. */
5301
5302 rtx
sparc_builtin_saveregs()5303 sparc_builtin_saveregs ()
5304 {
5305 int first_reg = current_function_args_info.words;
5306 rtx address;
5307 int regno;
5308
5309 for (regno = first_reg; regno < NPARM_REGS (word_mode); regno++)
5310 emit_move_insn (gen_rtx_MEM (word_mode,
5311 gen_rtx_PLUS (Pmode,
5312 frame_pointer_rtx,
5313 GEN_INT (FIRST_PARM_OFFSET (0)
5314 + (UNITS_PER_WORD
5315 * regno)))),
5316 gen_rtx_REG (word_mode,
5317 BASE_INCOMING_ARG_REG (word_mode) + regno));
5318
5319 address = gen_rtx_PLUS (Pmode,
5320 frame_pointer_rtx,
5321 GEN_INT (FIRST_PARM_OFFSET (0)
5322 + UNITS_PER_WORD * first_reg));
5323
5324 return address;
5325 }
5326
5327 /* Implement `va_start' for varargs and stdarg. */
5328
5329 void
sparc_va_start(valist,nextarg)5330 sparc_va_start (valist, nextarg)
5331 tree valist;
5332 rtx nextarg;
5333 {
5334 nextarg = expand_builtin_saveregs ();
5335 std_expand_builtin_va_start (valist, nextarg);
5336 }
5337
5338 /* Implement `va_arg'. */
5339
5340 rtx
sparc_va_arg(valist,type)5341 sparc_va_arg (valist, type)
5342 tree valist, type;
5343 {
5344 HOST_WIDE_INT size, rsize, align;
5345 tree addr, incr;
5346 rtx addr_rtx;
5347 int indirect = 0;
5348
5349 /* Round up sizeof(type) to a word. */
5350 size = int_size_in_bytes (type);
5351 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
5352 align = 0;
5353
5354 if (TARGET_ARCH64)
5355 {
5356 if (TYPE_ALIGN (type) >= 2 * (unsigned) BITS_PER_WORD)
5357 align = 2 * UNITS_PER_WORD;
5358
5359 if (AGGREGATE_TYPE_P (type))
5360 {
5361 if ((unsigned HOST_WIDE_INT) size > 16)
5362 {
5363 indirect = 1;
5364 size = rsize = UNITS_PER_WORD;
5365 }
5366 /* SPARC v9 ABI states that structures up to 8 bytes in size are
5367 given one 8 byte slot. */
5368 else if (size == 0)
5369 size = rsize = UNITS_PER_WORD;
5370 else
5371 size = rsize;
5372 }
5373 }
5374 else
5375 {
5376 if (AGGREGATE_TYPE_P (type)
5377 || TYPE_MODE (type) == TFmode
5378 || TYPE_MODE (type) == TCmode)
5379 {
5380 indirect = 1;
5381 size = rsize = UNITS_PER_WORD;
5382 }
5383 }
5384
5385 incr = valist;
5386 if (align)
5387 {
5388 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
5389 build_int_2 (align - 1, 0)));
5390 incr = fold (build (BIT_AND_EXPR, ptr_type_node, incr,
5391 build_int_2 (-align, -1)));
5392 }
5393
5394 addr = incr = save_expr (incr);
5395 if (BYTES_BIG_ENDIAN && size < rsize)
5396 {
5397 addr = fold (build (PLUS_EXPR, ptr_type_node, incr,
5398 build_int_2 (rsize - size, 0)));
5399 }
5400 incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
5401 build_int_2 (rsize, 0)));
5402
5403 incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
5404 TREE_SIDE_EFFECTS (incr) = 1;
5405 expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
5406
5407 addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
5408
5409 /* If the address isn't aligned properly for the type,
5410 we may need to copy to a temporary.
5411 FIXME: This is inefficient. Usually we can do this
5412 in registers. */
5413 if (align == 0
5414 && TYPE_ALIGN (type) > BITS_PER_WORD
5415 && !indirect)
5416 {
5417 /* FIXME: We really need to specify that the temporary is live
5418 for the whole function because expand_builtin_va_arg wants
5419 the alias set to be get_varargs_alias_set (), but in this
5420 case the alias set is that for TYPE and if the memory gets
5421 reused it will be reused with alias set TYPE. */
5422 rtx tmp = assign_temp (type, 0, 1, 0);
5423 rtx dest_addr;
5424
5425 addr_rtx = force_reg (Pmode, addr_rtx);
5426 addr_rtx = gen_rtx_MEM (BLKmode, addr_rtx);
5427 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
5428 set_mem_align (addr_rtx, BITS_PER_WORD);
5429 tmp = shallow_copy_rtx (tmp);
5430 PUT_MODE (tmp, BLKmode);
5431 set_mem_alias_set (tmp, 0);
5432
5433 dest_addr = emit_block_move (tmp, addr_rtx, GEN_INT (rsize),
5434 BLOCK_OP_NORMAL);
5435 if (dest_addr != NULL_RTX)
5436 addr_rtx = dest_addr;
5437 else
5438 addr_rtx = XCEXP (tmp, 0, MEM);
5439 }
5440
5441 if (indirect)
5442 {
5443 addr_rtx = force_reg (Pmode, addr_rtx);
5444 addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
5445 set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
5446 }
5447
5448 return addr_rtx;
5449 }
5450
5451 /* Return the string to output an unconditional branch to LABEL, which is
5452 the operand number of the label.
5453
5454 DEST is the destination insn (i.e. the label), INSN is the source. */
5455
5456 const char *
output_ubranch(dest,label,insn)5457 output_ubranch (dest, label, insn)
5458 rtx dest;
5459 int label;
5460 rtx insn;
5461 {
5462 static char string[64];
5463 bool noop = false;
5464 char *p;
5465
5466 /* TurboSPARC is reported to have problems with
5467 with
5468 foo: b,a foo
5469 i.e. an empty loop with the annul bit set. The workaround is to use
5470 foo: b foo; nop
5471 instead. */
5472
5473 if (! TARGET_V9 && flag_delayed_branch
5474 && (INSN_ADDRESSES (INSN_UID (dest))
5475 == INSN_ADDRESSES (INSN_UID (insn))))
5476 {
5477 strcpy (string, "b\t");
5478 noop = true;
5479 }
5480 else
5481 {
5482 bool v9_form = false;
5483
5484 if (TARGET_V9 && INSN_ADDRESSES_SET_P ())
5485 {
5486 int delta = (INSN_ADDRESSES (INSN_UID (dest))
5487 - INSN_ADDRESSES (INSN_UID (insn)));
5488 /* Leave some instructions for "slop". */
5489 if (delta >= -260000 && delta < 260000)
5490 v9_form = true;
5491 }
5492
5493 if (v9_form)
5494 strcpy (string, "ba%*,pt\t%%xcc, ");
5495 else
5496 strcpy (string, "b%*\t");
5497 }
5498
5499 p = strchr (string, '\0');
5500 *p++ = '%';
5501 *p++ = 'l';
5502 *p++ = '0' + label;
5503 *p++ = '%';
5504 if (noop)
5505 *p++ = '#';
5506 else
5507 *p++ = '(';
5508 *p = '\0';
5509
5510 return string;
5511 }
5512
5513 /* Return the string to output a conditional branch to LABEL, which is
5514 the operand number of the label. OP is the conditional expression.
5515 XEXP (OP, 0) is assumed to be a condition code register (integer or
5516 floating point) and its mode specifies what kind of comparison we made.
5517
5518 DEST is the destination insn (i.e. the label), INSN is the source.
5519
5520 REVERSED is nonzero if we should reverse the sense of the comparison.
5521
5522 ANNUL is nonzero if we should generate an annulling branch.
5523
5524 NOOP is nonzero if we have to follow this branch by a noop. */
5525
5526 char *
output_cbranch(op,dest,label,reversed,annul,noop,insn)5527 output_cbranch (op, dest, label, reversed, annul, noop, insn)
5528 rtx op, dest;
5529 int label;
5530 int reversed, annul, noop;
5531 rtx insn;
5532 {
5533 static char string[50];
5534 enum rtx_code code = GET_CODE (op);
5535 rtx cc_reg = XEXP (op, 0);
5536 enum machine_mode mode = GET_MODE (cc_reg);
5537 const char *labelno, *branch;
5538 int spaces = 8, far;
5539 char *p;
5540
5541 /* v9 branches are limited to +-1MB. If it is too far away,
5542 change
5543
5544 bne,pt %xcc, .LC30
5545
5546 to
5547
5548 be,pn %xcc, .+12
5549 nop
5550 ba .LC30
5551
5552 and
5553
5554 fbne,a,pn %fcc2, .LC29
5555
5556 to
5557
5558 fbe,pt %fcc2, .+16
5559 nop
5560 ba .LC29 */
5561
5562 far = TARGET_V9 && (get_attr_length (insn) >= 3);
5563 if (reversed ^ far)
5564 {
5565 /* Reversal of FP compares takes care -- an ordered compare
5566 becomes an unordered compare and vice versa. */
5567 if (mode == CCFPmode || mode == CCFPEmode)
5568 code = reverse_condition_maybe_unordered (code);
5569 else
5570 code = reverse_condition (code);
5571 }
5572
5573 /* Start by writing the branch condition. */
5574 if (mode == CCFPmode || mode == CCFPEmode)
5575 {
5576 switch (code)
5577 {
5578 case NE:
5579 branch = "fbne";
5580 break;
5581 case EQ:
5582 branch = "fbe";
5583 break;
5584 case GE:
5585 branch = "fbge";
5586 break;
5587 case GT:
5588 branch = "fbg";
5589 break;
5590 case LE:
5591 branch = "fble";
5592 break;
5593 case LT:
5594 branch = "fbl";
5595 break;
5596 case UNORDERED:
5597 branch = "fbu";
5598 break;
5599 case ORDERED:
5600 branch = "fbo";
5601 break;
5602 case UNGT:
5603 branch = "fbug";
5604 break;
5605 case UNLT:
5606 branch = "fbul";
5607 break;
5608 case UNEQ:
5609 branch = "fbue";
5610 break;
5611 case UNGE:
5612 branch = "fbuge";
5613 break;
5614 case UNLE:
5615 branch = "fbule";
5616 break;
5617 case LTGT:
5618 branch = "fblg";
5619 break;
5620
5621 default:
5622 abort ();
5623 }
5624
5625 /* ??? !v9: FP branches cannot be preceded by another floating point
5626 insn. Because there is currently no concept of pre-delay slots,
5627 we can fix this only by always emitting a nop before a floating
5628 point branch. */
5629
5630 string[0] = '\0';
5631 if (! TARGET_V9)
5632 strcpy (string, "nop\n\t");
5633 strcat (string, branch);
5634 }
5635 else
5636 {
5637 switch (code)
5638 {
5639 case NE:
5640 branch = "bne";
5641 break;
5642 case EQ:
5643 branch = "be";
5644 break;
5645 case GE:
5646 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5647 branch = "bpos";
5648 else
5649 branch = "bge";
5650 break;
5651 case GT:
5652 branch = "bg";
5653 break;
5654 case LE:
5655 branch = "ble";
5656 break;
5657 case LT:
5658 if (mode == CC_NOOVmode || mode == CCX_NOOVmode)
5659 branch = "bneg";
5660 else
5661 branch = "bl";
5662 break;
5663 case GEU:
5664 branch = "bgeu";
5665 break;
5666 case GTU:
5667 branch = "bgu";
5668 break;
5669 case LEU:
5670 branch = "bleu";
5671 break;
5672 case LTU:
5673 branch = "blu";
5674 break;
5675
5676 default:
5677 abort ();
5678 }
5679 strcpy (string, branch);
5680 }
5681 spaces -= strlen (branch);
5682 p = strchr (string, '\0');
5683
5684 /* Now add the annulling, the label, and a possible noop. */
5685 if (annul && ! far)
5686 {
5687 strcpy (p, ",a");
5688 p += 2;
5689 spaces -= 2;
5690 }
5691
5692 if (TARGET_V9)
5693 {
5694 rtx note;
5695 int v8 = 0;
5696
5697 if (! far && insn && INSN_ADDRESSES_SET_P ())
5698 {
5699 int delta = (INSN_ADDRESSES (INSN_UID (dest))
5700 - INSN_ADDRESSES (INSN_UID (insn)));
5701 /* Leave some instructions for "slop". */
5702 if (delta < -260000 || delta >= 260000)
5703 v8 = 1;
5704 }
5705
5706 if (mode == CCFPmode || mode == CCFPEmode)
5707 {
5708 static char v9_fcc_labelno[] = "%%fccX, ";
5709 /* Set the char indicating the number of the fcc reg to use. */
5710 v9_fcc_labelno[5] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0';
5711 labelno = v9_fcc_labelno;
5712 if (v8)
5713 {
5714 if (REGNO (cc_reg) == SPARC_FCC_REG)
5715 labelno = "";
5716 else
5717 abort ();
5718 }
5719 }
5720 else if (mode == CCXmode || mode == CCX_NOOVmode)
5721 {
5722 labelno = "%%xcc, ";
5723 if (v8)
5724 abort ();
5725 }
5726 else
5727 {
5728 labelno = "%%icc, ";
5729 if (v8)
5730 labelno = "";
5731 }
5732
5733 if (*labelno && insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
5734 {
5735 strcpy (p,
5736 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
5737 ? ",pt" : ",pn");
5738 p += 3;
5739 spaces -= 3;
5740 }
5741 }
5742 else
5743 labelno = "";
5744
5745 if (spaces > 0)
5746 *p++ = '\t';
5747 else
5748 *p++ = ' ';
5749 strcpy (p, labelno);
5750 p = strchr (p, '\0');
5751 if (far)
5752 {
5753 strcpy (p, ".+12\n\tnop\n\tb\t");
5754 if (annul || noop)
5755 p[3] = '6';
5756 p += 13;
5757 }
5758 *p++ = '%';
5759 *p++ = 'l';
5760 /* Set the char indicating the number of the operand containing the
5761 label_ref. */
5762 *p++ = label + '0';
5763 *p = '\0';
5764 if (noop)
5765 strcpy (p, "\n\tnop");
5766
5767 return string;
5768 }
5769
5770 /* Emit a library call comparison between floating point X and Y.
5771 COMPARISON is the rtl operator to compare with (EQ, NE, GT, etc.).
5772 TARGET_ARCH64 uses _Qp_* functions, which use pointers to TFmode
5773 values as arguments instead of the TFmode registers themselves,
5774 that's why we cannot call emit_float_lib_cmp. */
5775 void
sparc_emit_float_lib_cmp(x,y,comparison)5776 sparc_emit_float_lib_cmp (x, y, comparison)
5777 rtx x, y;
5778 enum rtx_code comparison;
5779 {
5780 const char *qpfunc;
5781 rtx slot0, slot1, result, tem, tem2;
5782 enum machine_mode mode;
5783
5784 switch (comparison)
5785 {
5786 case EQ:
5787 qpfunc = (TARGET_ARCH64) ? "_Qp_feq" : "_Q_feq";
5788 break;
5789
5790 case NE:
5791 qpfunc = (TARGET_ARCH64) ? "_Qp_fne" : "_Q_fne";
5792 break;
5793
5794 case GT:
5795 qpfunc = (TARGET_ARCH64) ? "_Qp_fgt" : "_Q_fgt";
5796 break;
5797
5798 case GE:
5799 qpfunc = (TARGET_ARCH64) ? "_Qp_fge" : "_Q_fge";
5800 break;
5801
5802 case LT:
5803 qpfunc = (TARGET_ARCH64) ? "_Qp_flt" : "_Q_flt";
5804 break;
5805
5806 case LE:
5807 qpfunc = (TARGET_ARCH64) ? "_Qp_fle" : "_Q_fle";
5808 break;
5809
5810 case ORDERED:
5811 case UNORDERED:
5812 case UNGT:
5813 case UNLT:
5814 case UNEQ:
5815 case UNGE:
5816 case UNLE:
5817 case LTGT:
5818 qpfunc = (TARGET_ARCH64) ? "_Qp_cmp" : "_Q_cmp";
5819 break;
5820
5821 default:
5822 abort();
5823 break;
5824 }
5825
5826 if (TARGET_ARCH64)
5827 {
5828 if (GET_CODE (x) != MEM)
5829 {
5830 slot0 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5831 emit_insn (gen_rtx_SET (VOIDmode, slot0, x));
5832 }
5833 else
5834 slot0 = x;
5835
5836 if (GET_CODE (y) != MEM)
5837 {
5838 slot1 = assign_stack_temp (TFmode, GET_MODE_SIZE(TFmode), 0);
5839 emit_insn (gen_rtx_SET (VOIDmode, slot1, y));
5840 }
5841 else
5842 slot1 = y;
5843
5844 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
5845 DImode, 2,
5846 XEXP (slot0, 0), Pmode,
5847 XEXP (slot1, 0), Pmode);
5848
5849 mode = DImode;
5850 }
5851 else
5852 {
5853 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, qpfunc), LCT_NORMAL,
5854 SImode, 2,
5855 x, TFmode, y, TFmode);
5856
5857 mode = SImode;
5858 }
5859
5860
5861 /* Immediately move the result of the libcall into a pseudo
5862 register so reload doesn't clobber the value if it needs
5863 the return register for a spill reg. */
5864 result = gen_reg_rtx (mode);
5865 emit_move_insn (result, hard_libcall_value (mode));
5866
5867 switch (comparison)
5868 {
5869 default:
5870 emit_cmp_insn (result, const0_rtx, NE, NULL_RTX, mode, 0);
5871 break;
5872 case ORDERED:
5873 case UNORDERED:
5874 emit_cmp_insn (result, GEN_INT(3), comparison == UNORDERED ? EQ : NE,
5875 NULL_RTX, mode, 0);
5876 break;
5877 case UNGT:
5878 case UNGE:
5879 emit_cmp_insn (result, const1_rtx,
5880 comparison == UNGT ? GT : NE, NULL_RTX, mode, 0);
5881 break;
5882 case UNLE:
5883 emit_cmp_insn (result, const2_rtx, NE, NULL_RTX, mode, 0);
5884 break;
5885 case UNLT:
5886 tem = gen_reg_rtx (mode);
5887 if (TARGET_ARCH32)
5888 emit_insn (gen_andsi3 (tem, result, const1_rtx));
5889 else
5890 emit_insn (gen_anddi3 (tem, result, const1_rtx));
5891 emit_cmp_insn (tem, const0_rtx, NE, NULL_RTX, mode, 0);
5892 break;
5893 case UNEQ:
5894 case LTGT:
5895 tem = gen_reg_rtx (mode);
5896 if (TARGET_ARCH32)
5897 emit_insn (gen_addsi3 (tem, result, const1_rtx));
5898 else
5899 emit_insn (gen_adddi3 (tem, result, const1_rtx));
5900 tem2 = gen_reg_rtx (mode);
5901 if (TARGET_ARCH32)
5902 emit_insn (gen_andsi3 (tem2, tem, const2_rtx));
5903 else
5904 emit_insn (gen_anddi3 (tem2, tem, const2_rtx));
5905 emit_cmp_insn (tem2, const0_rtx, comparison == UNEQ ? EQ : NE,
5906 NULL_RTX, mode, 0);
5907 break;
5908 }
5909 }
5910
5911 /* Generate an unsigned DImode to FP conversion. This is the same code
5912 optabs would emit if we didn't have TFmode patterns. */
5913
5914 void
sparc_emit_floatunsdi(operands,mode)5915 sparc_emit_floatunsdi (operands, mode)
5916 rtx operands[2];
5917 enum machine_mode mode;
5918 {
5919 rtx neglab, donelab, i0, i1, f0, in, out;
5920
5921 out = operands[0];
5922 in = force_reg (DImode, operands[1]);
5923 neglab = gen_label_rtx ();
5924 donelab = gen_label_rtx ();
5925 i0 = gen_reg_rtx (DImode);
5926 i1 = gen_reg_rtx (DImode);
5927 f0 = gen_reg_rtx (mode);
5928
5929 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
5930
5931 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
5932 emit_jump_insn (gen_jump (donelab));
5933 emit_barrier ();
5934
5935 emit_label (neglab);
5936
5937 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
5938 emit_insn (gen_anddi3 (i1, in, const1_rtx));
5939 emit_insn (gen_iordi3 (i0, i0, i1));
5940 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
5941 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
5942
5943 emit_label (donelab);
5944 }
5945
5946 /* Generate an FP to unsigned DImode conversion. This is the same code
5947 optabs would emit if we didn't have TFmode patterns. */
5948
5949 void
sparc_emit_fixunsdi(rtx * operands,enum machine_mode mode)5950 sparc_emit_fixunsdi (rtx *operands, enum machine_mode mode)
5951 {
5952 rtx neglab, donelab, i0, i1, f0, in, out, limit;
5953
5954 out = operands[0];
5955 in = force_reg (mode, operands[1]);
5956 neglab = gen_label_rtx ();
5957 donelab = gen_label_rtx ();
5958 i0 = gen_reg_rtx (DImode);
5959 i1 = gen_reg_rtx (DImode);
5960 limit = gen_reg_rtx (mode);
5961 f0 = gen_reg_rtx (mode);
5962
5963 emit_move_insn (limit,
5964 CONST_DOUBLE_FROM_REAL_VALUE (
5965 REAL_VALUE_ATOF ("9223372036854775808.0", mode), mode));
5966 emit_cmp_and_jump_insns (in, limit, GE, NULL_RTX, mode, 0, neglab);
5967
5968 emit_insn (gen_rtx_SET (VOIDmode,
5969 out,
5970 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, in))));
5971 emit_jump_insn (gen_jump (donelab));
5972 emit_barrier ();
5973
5974 emit_label (neglab);
5975
5976 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_MINUS (mode, in, limit)));
5977 emit_insn (gen_rtx_SET (VOIDmode,
5978 i0,
5979 gen_rtx_FIX (DImode, gen_rtx_FIX (mode, f0))));
5980 emit_insn (gen_movdi (i1, const1_rtx));
5981 emit_insn (gen_ashldi3 (i1, i1, GEN_INT (63)));
5982 emit_insn (gen_xordi3 (out, i0, i1));
5983
5984 emit_label (donelab);
5985 }
5986
5987 /* Return the string to output a conditional branch to LABEL, testing
5988 register REG. LABEL is the operand number of the label; REG is the
5989 operand number of the reg. OP is the conditional expression. The mode
5990 of REG says what kind of comparison we made.
5991
5992 DEST is the destination insn (i.e. the label), INSN is the source.
5993
5994 REVERSED is nonzero if we should reverse the sense of the comparison.
5995
5996 ANNUL is nonzero if we should generate an annulling branch.
5997
5998 NOOP is nonzero if we have to follow this branch by a noop. */
5999
6000 char *
output_v9branch(op,dest,reg,label,reversed,annul,noop,insn)6001 output_v9branch (op, dest, reg, label, reversed, annul, noop, insn)
6002 rtx op, dest;
6003 int reg, label;
6004 int reversed, annul, noop;
6005 rtx insn;
6006 {
6007 static char string[50];
6008 enum rtx_code code = GET_CODE (op);
6009 enum machine_mode mode = GET_MODE (XEXP (op, 0));
6010 rtx note;
6011 int far;
6012 char *p;
6013
6014 /* branch on register are limited to +-128KB. If it is too far away,
6015 change
6016
6017 brnz,pt %g1, .LC30
6018
6019 to
6020
6021 brz,pn %g1, .+12
6022 nop
6023 ba,pt %xcc, .LC30
6024
6025 and
6026
6027 brgez,a,pn %o1, .LC29
6028
6029 to
6030
6031 brlz,pt %o1, .+16
6032 nop
6033 ba,pt %xcc, .LC29 */
6034
6035 far = get_attr_length (insn) >= 3;
6036
6037 /* If not floating-point or if EQ or NE, we can just reverse the code. */
6038 if (reversed ^ far)
6039 code = reverse_condition (code);
6040
6041 /* Only 64 bit versions of these instructions exist. */
6042 if (mode != DImode)
6043 abort ();
6044
6045 /* Start by writing the branch condition. */
6046
6047 switch (code)
6048 {
6049 case NE:
6050 strcpy (string, "brnz");
6051 break;
6052
6053 case EQ:
6054 strcpy (string, "brz");
6055 break;
6056
6057 case GE:
6058 strcpy (string, "brgez");
6059 break;
6060
6061 case LT:
6062 strcpy (string, "brlz");
6063 break;
6064
6065 case LE:
6066 strcpy (string, "brlez");
6067 break;
6068
6069 case GT:
6070 strcpy (string, "brgz");
6071 break;
6072
6073 default:
6074 abort ();
6075 }
6076
6077 p = strchr (string, '\0');
6078
6079 /* Now add the annulling, reg, label, and nop. */
6080 if (annul && ! far)
6081 {
6082 strcpy (p, ",a");
6083 p += 2;
6084 }
6085
6086 if (insn && (note = find_reg_note (insn, REG_BR_PROB, NULL_RTX)))
6087 {
6088 strcpy (p,
6089 ((INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2) ^ far)
6090 ? ",pt" : ",pn");
6091 p += 3;
6092 }
6093
6094 *p = p < string + 8 ? '\t' : ' ';
6095 p++;
6096 *p++ = '%';
6097 *p++ = '0' + reg;
6098 *p++ = ',';
6099 *p++ = ' ';
6100 if (far)
6101 {
6102 int veryfar = 1, delta;
6103
6104 if (INSN_ADDRESSES_SET_P ())
6105 {
6106 delta = (INSN_ADDRESSES (INSN_UID (dest))
6107 - INSN_ADDRESSES (INSN_UID (insn)));
6108 /* Leave some instructions for "slop". */
6109 if (delta >= -260000 && delta < 260000)
6110 veryfar = 0;
6111 }
6112
6113 strcpy (p, ".+12\n\tnop\n\t");
6114 if (annul || noop)
6115 p[3] = '6';
6116 p += 11;
6117 if (veryfar)
6118 {
6119 strcpy (p, "b\t");
6120 p += 2;
6121 }
6122 else
6123 {
6124 strcpy (p, "ba,pt\t%%xcc, ");
6125 p += 13;
6126 }
6127 }
6128 *p++ = '%';
6129 *p++ = 'l';
6130 *p++ = '0' + label;
6131 *p = '\0';
6132
6133 if (noop)
6134 strcpy (p, "\n\tnop");
6135
6136 return string;
6137 }
6138
6139 /* Return 1, if any of the registers of the instruction are %l[0-7] or %o[0-7].
6140 Such instructions cannot be used in the delay slot of return insn on v9.
6141 If TEST is 0, also rename all %i[0-7] registers to their %o[0-7] counterparts.
6142 */
6143
6144 static int
epilogue_renumber(where,test)6145 epilogue_renumber (where, test)
6146 register rtx *where;
6147 int test;
6148 {
6149 register const char *fmt;
6150 register int i;
6151 register enum rtx_code code;
6152
6153 if (*where == 0)
6154 return 0;
6155
6156 code = GET_CODE (*where);
6157
6158 switch (code)
6159 {
6160 case REG:
6161 if (REGNO (*where) >= 8 && REGNO (*where) < 24) /* oX or lX */
6162 return 1;
6163 if (! test && REGNO (*where) >= 24 && REGNO (*where) < 32)
6164 *where = gen_rtx (REG, GET_MODE (*where), OUTGOING_REGNO (REGNO(*where)));
6165 case SCRATCH:
6166 case CC0:
6167 case PC:
6168 case CONST_INT:
6169 case CONST_DOUBLE:
6170 return 0;
6171
6172 /* Do not replace the frame pointer with the stack pointer because
6173 it can cause the delayed instruction to load below the stack.
6174 This occurs when instructions like:
6175
6176 (set (reg/i:SI 24 %i0)
6177 (mem/f:SI (plus:SI (reg/f:SI 30 %fp)
6178 (const_int -20 [0xffffffec])) 0))
6179
6180 are in the return delayed slot. */
6181 case PLUS:
6182 if (GET_CODE (XEXP (*where, 0)) == REG
6183 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM
6184 && (GET_CODE (XEXP (*where, 1)) != CONST_INT
6185 || INTVAL (XEXP (*where, 1)) < SPARC_STACK_BIAS))
6186 return 1;
6187 break;
6188
6189 case MEM:
6190 if (SPARC_STACK_BIAS
6191 && GET_CODE (XEXP (*where, 0)) == REG
6192 && REGNO (XEXP (*where, 0)) == HARD_FRAME_POINTER_REGNUM)
6193 return 1;
6194 break;
6195
6196 default:
6197 break;
6198 }
6199
6200 fmt = GET_RTX_FORMAT (code);
6201
6202 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6203 {
6204 if (fmt[i] == 'E')
6205 {
6206 register int j;
6207 for (j = XVECLEN (*where, i) - 1; j >= 0; j--)
6208 if (epilogue_renumber (&(XVECEXP (*where, i, j)), test))
6209 return 1;
6210 }
6211 else if (fmt[i] == 'e'
6212 && epilogue_renumber (&(XEXP (*where, i)), test))
6213 return 1;
6214 }
6215 return 0;
6216 }
6217
6218 /* Leaf functions and non-leaf functions have different needs. */
6219
6220 static const int
6221 reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
6222
6223 static const int
6224 reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
6225
6226 static const int *const reg_alloc_orders[] = {
6227 reg_leaf_alloc_order,
6228 reg_nonleaf_alloc_order};
6229
6230 void
order_regs_for_local_alloc()6231 order_regs_for_local_alloc ()
6232 {
6233 static int last_order_nonleaf = 1;
6234
6235 if (regs_ever_live[15] != last_order_nonleaf)
6236 {
6237 last_order_nonleaf = !last_order_nonleaf;
6238 memcpy ((char *) reg_alloc_order,
6239 (const char *) reg_alloc_orders[last_order_nonleaf],
6240 FIRST_PSEUDO_REGISTER * sizeof (int));
6241 }
6242 }
6243
6244 /* Return 1 if REG and MEM are legitimate enough to allow the various
6245 mem<-->reg splits to be run. */
6246
6247 int
sparc_splitdi_legitimate(reg,mem)6248 sparc_splitdi_legitimate (reg, mem)
6249 rtx reg;
6250 rtx mem;
6251 {
6252 /* Punt if we are here by mistake. */
6253 if (! reload_completed)
6254 abort ();
6255
6256 /* We must have an offsettable memory reference. */
6257 if (! offsettable_memref_p (mem))
6258 return 0;
6259
6260 /* If we have legitimate args for ldd/std, we do not want
6261 the split to happen. */
6262 if ((REGNO (reg) % 2) == 0
6263 && mem_min_alignment (mem, 8))
6264 return 0;
6265
6266 /* Success. */
6267 return 1;
6268 }
6269
6270 /* Return 1 if x and y are some kind of REG and they refer to
6271 different hard registers. This test is guarenteed to be
6272 run after reload. */
6273
6274 int
sparc_absnegfloat_split_legitimate(x,y)6275 sparc_absnegfloat_split_legitimate (x, y)
6276 rtx x, y;
6277 {
6278 if (GET_CODE (x) != REG)
6279 return 0;
6280 if (GET_CODE (y) != REG)
6281 return 0;
6282 if (REGNO (x) == REGNO (y))
6283 return 0;
6284 return 1;
6285 }
6286
6287 /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
6288 This makes them candidates for using ldd and std insns.
6289
6290 Note reg1 and reg2 *must* be hard registers. */
6291
6292 int
registers_ok_for_ldd_peep(reg1,reg2)6293 registers_ok_for_ldd_peep (reg1, reg2)
6294 rtx reg1, reg2;
6295 {
6296 /* We might have been passed a SUBREG. */
6297 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
6298 return 0;
6299
6300 if (REGNO (reg1) % 2 != 0)
6301 return 0;
6302
6303 /* Integer ldd is deprecated in SPARC V9 */
6304 if (TARGET_V9 && REGNO (reg1) < 32)
6305 return 0;
6306
6307 return (REGNO (reg1) == REGNO (reg2) - 1);
6308 }
6309
6310 /* Return 1 if the addresses in mem1 and mem2 are suitable for use in
6311 an ldd or std insn.
6312
6313 This can only happen when addr1 and addr2, the addresses in mem1
6314 and mem2, are consecutive memory locations (addr1 + 4 == addr2).
6315 addr1 must also be aligned on a 64-bit boundary.
6316
6317 Also iff dependent_reg_rtx is not null it should not be used to
6318 compute the address for mem1, i.e. we cannot optimize a sequence
6319 like:
6320 ld [%o0], %o0
6321 ld [%o0 + 4], %o1
6322 to
6323 ldd [%o0], %o0
6324 nor:
6325 ld [%g3 + 4], %g3
6326 ld [%g3], %g2
6327 to
6328 ldd [%g3], %g2
6329
6330 But, note that the transformation from:
6331 ld [%g2 + 4], %g3
6332 ld [%g2], %g2
6333 to
6334 ldd [%g2], %g2
6335 is perfectly fine. Thus, the peephole2 patterns always pass us
6336 the destination register of the first load, never the second one.
6337
6338 For stores we don't have a similar problem, so dependent_reg_rtx is
6339 NULL_RTX. */
6340
6341 int
mems_ok_for_ldd_peep(mem1,mem2,dependent_reg_rtx)6342 mems_ok_for_ldd_peep (mem1, mem2, dependent_reg_rtx)
6343 rtx mem1, mem2, dependent_reg_rtx;
6344 {
6345 rtx addr1, addr2;
6346 unsigned int reg1;
6347 int offset1;
6348
6349 /* The mems cannot be volatile. */
6350 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
6351 return 0;
6352
6353 /* MEM1 should be aligned on a 64-bit boundary. */
6354 if (MEM_ALIGN (mem1) < 64)
6355 return 0;
6356
6357 addr1 = XEXP (mem1, 0);
6358 addr2 = XEXP (mem2, 0);
6359
6360 /* Extract a register number and offset (if used) from the first addr. */
6361 if (GET_CODE (addr1) == PLUS)
6362 {
6363 /* If not a REG, return zero. */
6364 if (GET_CODE (XEXP (addr1, 0)) != REG)
6365 return 0;
6366 else
6367 {
6368 reg1 = REGNO (XEXP (addr1, 0));
6369 /* The offset must be constant! */
6370 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
6371 return 0;
6372 offset1 = INTVAL (XEXP (addr1, 1));
6373 }
6374 }
6375 else if (GET_CODE (addr1) != REG)
6376 return 0;
6377 else
6378 {
6379 reg1 = REGNO (addr1);
6380 /* This was a simple (mem (reg)) expression. Offset is 0. */
6381 offset1 = 0;
6382 }
6383
6384 /* Make sure the second address is a (mem (plus (reg) (const_int). */
6385 if (GET_CODE (addr2) != PLUS)
6386 return 0;
6387
6388 if (GET_CODE (XEXP (addr2, 0)) != REG
6389 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
6390 return 0;
6391
6392 if (reg1 != REGNO (XEXP (addr2, 0)))
6393 return 0;
6394
6395 if (dependent_reg_rtx != NULL_RTX && reg1 == REGNO (dependent_reg_rtx))
6396 return 0;
6397
6398 /* The first offset must be evenly divisible by 8 to ensure the
6399 address is 64 bit aligned. */
6400 if (offset1 % 8 != 0)
6401 return 0;
6402
6403 /* The offset for the second addr must be 4 more than the first addr. */
6404 if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
6405 return 0;
6406
6407 /* All the tests passed. addr1 and addr2 are valid for ldd and std
6408 instructions. */
6409 return 1;
6410 }
6411
6412 /* Return 1 if reg is a pseudo, or is the first register in
6413 a hard register pair. This makes it a candidate for use in
6414 ldd and std insns. */
6415
6416 int
register_ok_for_ldd(reg)6417 register_ok_for_ldd (reg)
6418 rtx reg;
6419 {
6420 /* We might have been passed a SUBREG. */
6421 if (GET_CODE (reg) != REG)
6422 return 0;
6423
6424 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
6425 return (REGNO (reg) % 2 == 0);
6426 else
6427 return 1;
6428 }
6429
6430 /* Print operand X (an rtx) in assembler syntax to file FILE.
6431 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
6432 For `%' followed by punctuation, CODE is the punctuation and X is null. */
6433
6434 void
print_operand(file,x,code)6435 print_operand (file, x, code)
6436 FILE *file;
6437 rtx x;
6438 int code;
6439 {
6440 switch (code)
6441 {
6442 case '#':
6443 /* Output a 'nop' if there's nothing for the delay slot. */
6444 if (dbr_sequence_length () == 0)
6445 fputs ("\n\t nop", file);
6446 return;
6447 case '*':
6448 /* Output an annul flag if there's nothing for the delay slot and we
6449 are optimizing. This is always used with '(' below. */
6450 /* Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
6451 this is a dbx bug. So, we only do this when optimizing. */
6452 /* On UltraSPARC, a branch in a delay slot causes a pipeline flush.
6453 Always emit a nop in case the next instruction is a branch. */
6454 if (dbr_sequence_length () == 0
6455 && (optimize && (int)sparc_cpu < PROCESSOR_V9))
6456 fputs (",a", file);
6457 return;
6458 case '(':
6459 /* Output a 'nop' if there's nothing for the delay slot and we are
6460 not optimizing. This is always used with '*' above. */
6461 if (dbr_sequence_length () == 0
6462 && ! (optimize && (int)sparc_cpu < PROCESSOR_V9))
6463 fputs ("\n\t nop", file);
6464 return;
6465 case '_':
6466 /* Output the Embedded Medium/Anywhere code model base register. */
6467 fputs (EMBMEDANY_BASE_REG, file);
6468 return;
6469 case '@':
6470 /* Print out what we are using as the frame pointer. This might
6471 be %fp, or might be %sp+offset. */
6472 /* ??? What if offset is too big? Perhaps the caller knows it isn't? */
6473 fprintf (file, "%s+%d", frame_base_name, frame_base_offset);
6474 return;
6475 case 'Y':
6476 /* Adjust the operand to take into account a RESTORE operation. */
6477 if (GET_CODE (x) == CONST_INT)
6478 break;
6479 else if (GET_CODE (x) != REG)
6480 output_operand_lossage ("invalid %%Y operand");
6481 else if (REGNO (x) < 8)
6482 fputs (reg_names[REGNO (x)], file);
6483 else if (REGNO (x) >= 24 && REGNO (x) < 32)
6484 fputs (reg_names[REGNO (x)-16], file);
6485 else
6486 output_operand_lossage ("invalid %%Y operand");
6487 return;
6488 case 'L':
6489 /* Print out the low order register name of a register pair. */
6490 if (WORDS_BIG_ENDIAN)
6491 fputs (reg_names[REGNO (x)+1], file);
6492 else
6493 fputs (reg_names[REGNO (x)], file);
6494 return;
6495 case 'H':
6496 /* Print out the high order register name of a register pair. */
6497 if (WORDS_BIG_ENDIAN)
6498 fputs (reg_names[REGNO (x)], file);
6499 else
6500 fputs (reg_names[REGNO (x)+1], file);
6501 return;
6502 case 'R':
6503 /* Print out the second register name of a register pair or quad.
6504 I.e., R (%o0) => %o1. */
6505 fputs (reg_names[REGNO (x)+1], file);
6506 return;
6507 case 'S':
6508 /* Print out the third register name of a register quad.
6509 I.e., S (%o0) => %o2. */
6510 fputs (reg_names[REGNO (x)+2], file);
6511 return;
6512 case 'T':
6513 /* Print out the fourth register name of a register quad.
6514 I.e., T (%o0) => %o3. */
6515 fputs (reg_names[REGNO (x)+3], file);
6516 return;
6517 case 'x':
6518 /* Print a condition code register. */
6519 if (REGNO (x) == SPARC_ICC_REG)
6520 {
6521 /* We don't handle CC[X]_NOOVmode because they're not supposed
6522 to occur here. */
6523 if (GET_MODE (x) == CCmode)
6524 fputs ("%icc", file);
6525 else if (GET_MODE (x) == CCXmode)
6526 fputs ("%xcc", file);
6527 else
6528 abort ();
6529 }
6530 else
6531 /* %fccN register */
6532 fputs (reg_names[REGNO (x)], file);
6533 return;
6534 case 'm':
6535 /* Print the operand's address only. */
6536 output_address (XEXP (x, 0));
6537 return;
6538 case 'r':
6539 /* In this case we need a register. Use %g0 if the
6540 operand is const0_rtx. */
6541 if (x == const0_rtx
6542 || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
6543 {
6544 fputs ("%g0", file);
6545 return;
6546 }
6547 else
6548 break;
6549
6550 case 'A':
6551 switch (GET_CODE (x))
6552 {
6553 case IOR: fputs ("or", file); break;
6554 case AND: fputs ("and", file); break;
6555 case XOR: fputs ("xor", file); break;
6556 default: output_operand_lossage ("invalid %%A operand");
6557 }
6558 return;
6559
6560 case 'B':
6561 switch (GET_CODE (x))
6562 {
6563 case IOR: fputs ("orn", file); break;
6564 case AND: fputs ("andn", file); break;
6565 case XOR: fputs ("xnor", file); break;
6566 default: output_operand_lossage ("invalid %%B operand");
6567 }
6568 return;
6569
6570 /* These are used by the conditional move instructions. */
6571 case 'c' :
6572 case 'C':
6573 {
6574 enum rtx_code rc = GET_CODE (x);
6575
6576 if (code == 'c')
6577 {
6578 enum machine_mode mode = GET_MODE (XEXP (x, 0));
6579 if (mode == CCFPmode || mode == CCFPEmode)
6580 rc = reverse_condition_maybe_unordered (GET_CODE (x));
6581 else
6582 rc = reverse_condition (GET_CODE (x));
6583 }
6584 switch (rc)
6585 {
6586 case NE: fputs ("ne", file); break;
6587 case EQ: fputs ("e", file); break;
6588 case GE: fputs ("ge", file); break;
6589 case GT: fputs ("g", file); break;
6590 case LE: fputs ("le", file); break;
6591 case LT: fputs ("l", file); break;
6592 case GEU: fputs ("geu", file); break;
6593 case GTU: fputs ("gu", file); break;
6594 case LEU: fputs ("leu", file); break;
6595 case LTU: fputs ("lu", file); break;
6596 case LTGT: fputs ("lg", file); break;
6597 case UNORDERED: fputs ("u", file); break;
6598 case ORDERED: fputs ("o", file); break;
6599 case UNLT: fputs ("ul", file); break;
6600 case UNLE: fputs ("ule", file); break;
6601 case UNGT: fputs ("ug", file); break;
6602 case UNGE: fputs ("uge", file); break;
6603 case UNEQ: fputs ("ue", file); break;
6604 default: output_operand_lossage (code == 'c'
6605 ? "invalid %%c operand"
6606 : "invalid %%C operand");
6607 }
6608 return;
6609 }
6610
6611 /* These are used by the movr instruction pattern. */
6612 case 'd':
6613 case 'D':
6614 {
6615 enum rtx_code rc = (code == 'd'
6616 ? reverse_condition (GET_CODE (x))
6617 : GET_CODE (x));
6618 switch (rc)
6619 {
6620 case NE: fputs ("ne", file); break;
6621 case EQ: fputs ("e", file); break;
6622 case GE: fputs ("gez", file); break;
6623 case LT: fputs ("lz", file); break;
6624 case LE: fputs ("lez", file); break;
6625 case GT: fputs ("gz", file); break;
6626 default: output_operand_lossage (code == 'd'
6627 ? "invalid %%d operand"
6628 : "invalid %%D operand");
6629 }
6630 return;
6631 }
6632
6633 case 'b':
6634 {
6635 /* Print a sign-extended character. */
6636 int i = trunc_int_for_mode (INTVAL (x), QImode);
6637 fprintf (file, "%d", i);
6638 return;
6639 }
6640
6641 case 'f':
6642 /* Operand must be a MEM; write its address. */
6643 if (GET_CODE (x) != MEM)
6644 output_operand_lossage ("invalid %%f operand");
6645 output_address (XEXP (x, 0));
6646 return;
6647
6648 case 's':
6649 {
6650 /* Print a sign-extended 32-bit value. */
6651 HOST_WIDE_INT i;
6652 if (GET_CODE(x) == CONST_INT)
6653 i = INTVAL (x);
6654 else if (GET_CODE(x) == CONST_DOUBLE)
6655 i = CONST_DOUBLE_LOW (x);
6656 else
6657 {
6658 output_operand_lossage ("invalid %%s operand");
6659 return;
6660 }
6661 i = trunc_int_for_mode (i, SImode);
6662 fprintf (file, HOST_WIDE_INT_PRINT_DEC, i);
6663 return;
6664 }
6665
6666 case 0:
6667 /* Do nothing special. */
6668 break;
6669
6670 default:
6671 /* Undocumented flag. */
6672 output_operand_lossage ("invalid operand output code");
6673 }
6674
6675 if (GET_CODE (x) == REG)
6676 fputs (reg_names[REGNO (x)], file);
6677 else if (GET_CODE (x) == MEM)
6678 {
6679 fputc ('[', file);
6680 /* Poor Sun assembler doesn't understand absolute addressing. */
6681 if (CONSTANT_P (XEXP (x, 0)))
6682 fputs ("%g0+", file);
6683 output_address (XEXP (x, 0));
6684 fputc (']', file);
6685 }
6686 else if (GET_CODE (x) == HIGH)
6687 {
6688 fputs ("%hi(", file);
6689 output_addr_const (file, XEXP (x, 0));
6690 fputc (')', file);
6691 }
6692 else if (GET_CODE (x) == LO_SUM)
6693 {
6694 print_operand (file, XEXP (x, 0), 0);
6695 if (TARGET_CM_MEDMID)
6696 fputs ("+%l44(", file);
6697 else
6698 fputs ("+%lo(", file);
6699 output_addr_const (file, XEXP (x, 1));
6700 fputc (')', file);
6701 }
6702 else if (GET_CODE (x) == CONST_DOUBLE
6703 && (GET_MODE (x) == VOIDmode
6704 || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
6705 {
6706 if (CONST_DOUBLE_HIGH (x) == 0)
6707 fprintf (file, "%u", (unsigned int) CONST_DOUBLE_LOW (x));
6708 else if (CONST_DOUBLE_HIGH (x) == -1
6709 && CONST_DOUBLE_LOW (x) < 0)
6710 fprintf (file, "%d", (int) CONST_DOUBLE_LOW (x));
6711 else
6712 output_operand_lossage ("long long constant not a valid immediate operand");
6713 }
6714 else if (GET_CODE (x) == CONST_DOUBLE)
6715 output_operand_lossage ("floating point constant not a valid immediate operand");
6716 else { output_addr_const (file, x); }
6717 }
6718
6719 /* Target hook for assembling integer objects. The sparc version has
6720 special handling for aligned DI-mode objects. */
6721
6722 static bool
sparc_assemble_integer(x,size,aligned_p)6723 sparc_assemble_integer (x, size, aligned_p)
6724 rtx x;
6725 unsigned int size;
6726 int aligned_p;
6727 {
6728 /* ??? We only output .xword's for symbols and only then in environments
6729 where the assembler can handle them. */
6730 if (aligned_p && size == 8
6731 && (GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE))
6732 {
6733 if (TARGET_V9)
6734 {
6735 assemble_integer_with_op ("\t.xword\t", x);
6736 return true;
6737 }
6738 else
6739 {
6740 assemble_aligned_integer (4, const0_rtx);
6741 assemble_aligned_integer (4, x);
6742 return true;
6743 }
6744 }
6745 return default_assemble_integer (x, size, aligned_p);
6746 }
6747
6748 /* Return the value of a code used in the .proc pseudo-op that says
6749 what kind of result this function returns. For non-C types, we pick
6750 the closest C type. */
6751
6752 #ifndef SHORT_TYPE_SIZE
6753 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
6754 #endif
6755
6756 #ifndef INT_TYPE_SIZE
6757 #define INT_TYPE_SIZE BITS_PER_WORD
6758 #endif
6759
6760 #ifndef LONG_TYPE_SIZE
6761 #define LONG_TYPE_SIZE BITS_PER_WORD
6762 #endif
6763
6764 #ifndef LONG_LONG_TYPE_SIZE
6765 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
6766 #endif
6767
6768 #ifndef FLOAT_TYPE_SIZE
6769 #define FLOAT_TYPE_SIZE BITS_PER_WORD
6770 #endif
6771
6772 #ifndef DOUBLE_TYPE_SIZE
6773 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6774 #endif
6775
6776 #ifndef LONG_DOUBLE_TYPE_SIZE
6777 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
6778 #endif
6779
6780 unsigned long
sparc_type_code(type)6781 sparc_type_code (type)
6782 register tree type;
6783 {
6784 register unsigned long qualifiers = 0;
6785 register unsigned shift;
6786
6787 /* Only the first 30 bits of the qualifier are valid. We must refrain from
6788 setting more, since some assemblers will give an error for this. Also,
6789 we must be careful to avoid shifts of 32 bits or more to avoid getting
6790 unpredictable results. */
6791
6792 for (shift = 6; shift < 30; shift += 2, type = TREE_TYPE (type))
6793 {
6794 switch (TREE_CODE (type))
6795 {
6796 case ERROR_MARK:
6797 return qualifiers;
6798
6799 case ARRAY_TYPE:
6800 qualifiers |= (3 << shift);
6801 break;
6802
6803 case FUNCTION_TYPE:
6804 case METHOD_TYPE:
6805 qualifiers |= (2 << shift);
6806 break;
6807
6808 case POINTER_TYPE:
6809 case REFERENCE_TYPE:
6810 case OFFSET_TYPE:
6811 qualifiers |= (1 << shift);
6812 break;
6813
6814 case RECORD_TYPE:
6815 return (qualifiers | 8);
6816
6817 case UNION_TYPE:
6818 case QUAL_UNION_TYPE:
6819 return (qualifiers | 9);
6820
6821 case ENUMERAL_TYPE:
6822 return (qualifiers | 10);
6823
6824 case VOID_TYPE:
6825 return (qualifiers | 16);
6826
6827 case INTEGER_TYPE:
6828 /* If this is a range type, consider it to be the underlying
6829 type. */
6830 if (TREE_TYPE (type) != 0)
6831 break;
6832
6833 /* Carefully distinguish all the standard types of C,
6834 without messing up if the language is not C. We do this by
6835 testing TYPE_PRECISION and TREE_UNSIGNED. The old code used to
6836 look at both the names and the above fields, but that's redundant.
6837 Any type whose size is between two C types will be considered
6838 to be the wider of the two types. Also, we do not have a
6839 special code to use for "long long", so anything wider than
6840 long is treated the same. Note that we can't distinguish
6841 between "int" and "long" in this code if they are the same
6842 size, but that's fine, since neither can the assembler. */
6843
6844 if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
6845 return (qualifiers | (TREE_UNSIGNED (type) ? 12 : 2));
6846
6847 else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
6848 return (qualifiers | (TREE_UNSIGNED (type) ? 13 : 3));
6849
6850 else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
6851 return (qualifiers | (TREE_UNSIGNED (type) ? 14 : 4));
6852
6853 else
6854 return (qualifiers | (TREE_UNSIGNED (type) ? 15 : 5));
6855
6856 case REAL_TYPE:
6857 /* If this is a range type, consider it to be the underlying
6858 type. */
6859 if (TREE_TYPE (type) != 0)
6860 break;
6861
6862 /* Carefully distinguish all the standard types of C,
6863 without messing up if the language is not C. */
6864
6865 if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
6866 return (qualifiers | 6);
6867
6868 else
6869 return (qualifiers | 7);
6870
6871 case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */
6872 /* ??? We need to distinguish between double and float complex types,
6873 but I don't know how yet because I can't reach this code from
6874 existing front-ends. */
6875 return (qualifiers | 7); /* Who knows? */
6876
6877 case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */
6878 case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */
6879 case FILE_TYPE: /* GNU Pascal FILE type. */
6880 case SET_TYPE: /* GNU Pascal SET type. */
6881 case LANG_TYPE: /* ? */
6882 return qualifiers;
6883
6884 default:
6885 abort (); /* Not a type! */
6886 }
6887 }
6888
6889 return qualifiers;
6890 }
6891
6892 /* Nested function support. */
6893
6894 /* Emit RTL insns to initialize the variable parts of a trampoline.
6895 FNADDR is an RTX for the address of the function's pure code.
6896 CXT is an RTX for the static chain value for the function.
6897
6898 This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
6899 (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
6900 (to store insns). This is a bit excessive. Perhaps a different
6901 mechanism would be better here.
6902
6903 Emit enough FLUSH insns to synchronize the data and instruction caches. */
6904
6905 void
sparc_initialize_trampoline(tramp,fnaddr,cxt)6906 sparc_initialize_trampoline (tramp, fnaddr, cxt)
6907 rtx tramp, fnaddr, cxt;
6908 {
6909 /* SPARC 32-bit trampoline:
6910
6911 sethi %hi(fn), %g1
6912 sethi %hi(static), %g2
6913 jmp %g1+%lo(fn)
6914 or %g2, %lo(static), %g2
6915
6916 SETHI i,r = 00rr rrr1 00ii iiii iiii iiii iiii iiii
6917 JMPL r+i,d = 10dd ddd1 1100 0rrr rr1i iiii iiii iiii
6918 */
6919
6920 emit_move_insn
6921 (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
6922 expand_binop (SImode, ior_optab,
6923 expand_shift (RSHIFT_EXPR, SImode, fnaddr,
6924 size_int (10), 0, 1),
6925 GEN_INT (trunc_int_for_mode (0x03000000, SImode)),
6926 NULL_RTX, 1, OPTAB_DIRECT));
6927
6928 emit_move_insn
6929 (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6930 expand_binop (SImode, ior_optab,
6931 expand_shift (RSHIFT_EXPR, SImode, cxt,
6932 size_int (10), 0, 1),
6933 GEN_INT (trunc_int_for_mode (0x05000000, SImode)),
6934 NULL_RTX, 1, OPTAB_DIRECT));
6935
6936 emit_move_insn
6937 (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6938 expand_binop (SImode, ior_optab,
6939 expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
6940 GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
6941 NULL_RTX, 1, OPTAB_DIRECT));
6942
6943 emit_move_insn
6944 (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6945 expand_binop (SImode, ior_optab,
6946 expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
6947 GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
6948 NULL_RTX, 1, OPTAB_DIRECT));
6949
6950 /* On UltraSPARC a flush flushes an entire cache line. The trampoline is
6951 aligned on a 16 byte boundary so one flush clears it all. */
6952 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
6953 if (sparc_cpu != PROCESSOR_ULTRASPARC
6954 && sparc_cpu != PROCESSOR_ULTRASPARC3)
6955 emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
6956 plus_constant (tramp, 8)))));
6957
6958 /* Call __enable_execute_stack after writing onto the stack to make sure
6959 the stack address is accessible. */
6960 #ifdef TRANSFER_FROM_TRAMPOLINE
6961 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
6962 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
6963 #endif
6964
6965 }
6966
6967 /* The 64-bit version is simpler because it makes more sense to load the
6968 values as "immediate" data out of the trampoline. It's also easier since
6969 we can read the PC without clobbering a register. */
6970
6971 void
sparc64_initialize_trampoline(tramp,fnaddr,cxt)6972 sparc64_initialize_trampoline (tramp, fnaddr, cxt)
6973 rtx tramp, fnaddr, cxt;
6974 {
6975 /* SPARC 64-bit trampoline:
6976
6977 rd %pc, %g1
6978 ldx [%g1+24], %g5
6979 jmp %g5
6980 ldx [%g1+16], %g5
6981 +16 bytes data
6982 */
6983
6984 emit_move_insn (gen_rtx_MEM (SImode, tramp),
6985 GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
6986 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
6987 GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
6988 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
6989 GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
6990 emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
6991 GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
6992 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
6993 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
6994 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
6995
6996 if (sparc_cpu != PROCESSOR_ULTRASPARC
6997 && sparc_cpu != PROCESSOR_ULTRASPARC3)
6998 emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
6999
7000 /* Call __enable_execute_stack after writing onto the stack to make sure
7001 the stack address is accessible. */
7002 #ifdef TRANSFER_FROM_TRAMPOLINE
7003 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__enable_execute_stack"),
7004 LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
7005 #endif
7006 }
7007
7008 /* Subroutines to support a flat (single) register window calling
7009 convention. */
7010
7011 /* Single-register window sparc stack frames look like:
7012
7013 Before call After call
7014 +-----------------------+ +-----------------------+
7015 high | | | |
7016 mem | caller's temps. | | caller's temps. |
7017 | | | |
7018 +-----------------------+ +-----------------------+
7019 | | | |
7020 | arguments on stack. | | arguments on stack. |
7021 | | | |
7022 +-----------------------+FP+92->+-----------------------+
7023 | 6 words to save | | 6 words to save |
7024 | arguments passed | | arguments passed |
7025 | in registers, even | | in registers, even |
7026 | if not passed. | | if not passed. |
7027 SP+68->+-----------------------+FP+68->+-----------------------+
7028 | 1 word struct addr | | 1 word struct addr |
7029 +-----------------------+FP+64->+-----------------------+
7030 | | | |
7031 | 16 word reg save area | | 16 word reg save area |
7032 | | | |
7033 SP->+-----------------------+ FP->+-----------------------+
7034 | 4 word area for |
7035 | fp/alu reg moves |
7036 FP-16->+-----------------------+
7037 | |
7038 | local variables |
7039 | |
7040 +-----------------------+
7041 | |
7042 | fp register save |
7043 | |
7044 +-----------------------+
7045 | |
7046 | gp register save |
7047 | |
7048 +-----------------------+
7049 | |
7050 | alloca allocations |
7051 | |
7052 +-----------------------+
7053 | |
7054 | arguments on stack |
7055 | |
7056 SP+92->+-----------------------+
7057 | 6 words to save |
7058 | arguments passed |
7059 | in registers, even |
7060 low | if not passed. |
7061 memory SP+68->+-----------------------+
7062 | 1 word struct addr |
7063 SP+64->+-----------------------+
7064 | |
7065 I 16 word reg save area |
7066 | |
7067 SP->+-----------------------+ */
7068
7069 /* Structure to be filled in by sparc_flat_compute_frame_size with register
7070 save masks, and offsets for the current function. */
7071
7072 struct sparc_frame_info
7073 {
7074 unsigned long total_size; /* # bytes that the entire frame takes up. */
7075 unsigned long var_size; /* # bytes that variables take up. */
7076 unsigned long args_size; /* # bytes that outgoing arguments take up. */
7077 unsigned long extra_size; /* # bytes of extra gunk. */
7078 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
7079 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
7080 unsigned long gmask; /* Mask of saved gp registers. */
7081 unsigned long fmask; /* Mask of saved fp registers. */
7082 unsigned long reg_offset; /* Offset from new sp to store regs. */
7083 int initialized; /* Nonzero if frame size already calculated. */
7084 };
7085
7086 /* Current frame information calculated by sparc_flat_compute_frame_size. */
7087 struct sparc_frame_info current_frame_info;
7088
7089 /* Zero structure to initialize current_frame_info. */
7090 struct sparc_frame_info zero_frame_info;
7091
7092 /* Tell prologue and epilogue if register REGNO should be saved / restored. */
7093
7094 #define RETURN_ADDR_REGNUM 15
7095 #define HARD_FRAME_POINTER_MASK (1 << (HARD_FRAME_POINTER_REGNUM))
7096 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
7097
7098 #define MUST_SAVE_REGISTER(regno) \
7099 ((regs_ever_live[regno] && !call_used_regs[regno]) \
7100 || (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed) \
7101 || (regno == RETURN_ADDR_REGNUM && regs_ever_live[RETURN_ADDR_REGNUM]))
7102
7103 /* Return the bytes needed to compute the frame pointer from the current
7104 stack pointer. */
7105
7106 unsigned long
sparc_flat_compute_frame_size(size)7107 sparc_flat_compute_frame_size (size)
7108 int size; /* # of var. bytes allocated. */
7109 {
7110 int regno;
7111 unsigned long total_size; /* # bytes that the entire frame takes up. */
7112 unsigned long var_size; /* # bytes that variables take up. */
7113 unsigned long args_size; /* # bytes that outgoing arguments take up. */
7114 unsigned long extra_size; /* # extra bytes. */
7115 unsigned int gp_reg_size; /* # bytes needed to store gp regs. */
7116 unsigned int fp_reg_size; /* # bytes needed to store fp regs. */
7117 unsigned long gmask; /* Mask of saved gp registers. */
7118 unsigned long fmask; /* Mask of saved fp registers. */
7119 unsigned long reg_offset; /* Offset to register save area. */
7120 int need_aligned_p; /* 1 if need the save area 8 byte aligned. */
7121
7122 /* This is the size of the 16 word reg save area, 1 word struct addr
7123 area, and 4 word fp/alu register copy area. */
7124 extra_size = -STARTING_FRAME_OFFSET + FIRST_PARM_OFFSET(0);
7125 var_size = size;
7126 gp_reg_size = 0;
7127 fp_reg_size = 0;
7128 gmask = 0;
7129 fmask = 0;
7130 reg_offset = 0;
7131 need_aligned_p = 0;
7132
7133 args_size = 0;
7134 if (!leaf_function_p ())
7135 {
7136 /* Also include the size needed for the 6 parameter registers. */
7137 args_size = current_function_outgoing_args_size + 24;
7138 }
7139 total_size = var_size + args_size;
7140
7141 /* Calculate space needed for gp registers. */
7142 for (regno = 1; regno <= 31; regno++)
7143 {
7144 if (MUST_SAVE_REGISTER (regno))
7145 {
7146 /* If we need to save two regs in a row, ensure there's room to bump
7147 up the address to align it to a doubleword boundary. */
7148 if ((regno & 0x1) == 0 && MUST_SAVE_REGISTER (regno+1))
7149 {
7150 if (gp_reg_size % 8 != 0)
7151 gp_reg_size += 4;
7152 gp_reg_size += 2 * UNITS_PER_WORD;
7153 gmask |= 3 << regno;
7154 regno++;
7155 need_aligned_p = 1;
7156 }
7157 else
7158 {
7159 gp_reg_size += UNITS_PER_WORD;
7160 gmask |= 1 << regno;
7161 }
7162 }
7163 }
7164
7165 /* Calculate space needed for fp registers. */
7166 for (regno = 32; regno <= 63; regno++)
7167 {
7168 if (regs_ever_live[regno] && !call_used_regs[regno])
7169 {
7170 fp_reg_size += UNITS_PER_WORD;
7171 fmask |= 1 << (regno - 32);
7172 }
7173 }
7174
7175 if (gmask || fmask)
7176 {
7177 int n;
7178 reg_offset = FIRST_PARM_OFFSET(0) + args_size;
7179 /* Ensure save area is 8 byte aligned if we need it. */
7180 n = reg_offset % 8;
7181 if (need_aligned_p && n != 0)
7182 {
7183 total_size += 8 - n;
7184 reg_offset += 8 - n;
7185 }
7186 total_size += gp_reg_size + fp_reg_size;
7187 }
7188
7189 /* If we must allocate a stack frame at all, we must also allocate
7190 room for register window spillage, so as to be binary compatible
7191 with libraries and operating systems that do not use -mflat. */
7192 if (total_size > 0)
7193 total_size += extra_size;
7194 else
7195 extra_size = 0;
7196
7197 total_size = SPARC_STACK_ALIGN (total_size);
7198
7199 /* Save other computed information. */
7200 current_frame_info.total_size = total_size;
7201 current_frame_info.var_size = var_size;
7202 current_frame_info.args_size = args_size;
7203 current_frame_info.extra_size = extra_size;
7204 current_frame_info.gp_reg_size = gp_reg_size;
7205 current_frame_info.fp_reg_size = fp_reg_size;
7206 current_frame_info.gmask = gmask;
7207 current_frame_info.fmask = fmask;
7208 current_frame_info.reg_offset = reg_offset;
7209 current_frame_info.initialized = reload_completed;
7210
7211 /* Ok, we're done. */
7212 return total_size;
7213 }
7214
7215 /* Save/restore registers in GMASK and FMASK at register BASE_REG plus offset
7216 OFFSET.
7217
7218 BASE_REG must be 8 byte aligned. This allows us to test OFFSET for
7219 appropriate alignment and use DOUBLEWORD_OP when we can. We assume
7220 [BASE_REG+OFFSET] will always be a valid address.
7221
7222 WORD_OP is either "st" for save, "ld" for restore.
7223 DOUBLEWORD_OP is either "std" for save, "ldd" for restore. */
7224
7225 void
sparc_flat_save_restore(file,base_reg,offset,gmask,fmask,word_op,doubleword_op,base_offset)7226 sparc_flat_save_restore (file, base_reg, offset, gmask, fmask, word_op,
7227 doubleword_op, base_offset)
7228 FILE *file;
7229 const char *base_reg;
7230 unsigned int offset;
7231 unsigned long gmask;
7232 unsigned long fmask;
7233 const char *word_op;
7234 const char *doubleword_op;
7235 unsigned long base_offset;
7236 {
7237 int regno;
7238
7239 if (gmask == 0 && fmask == 0)
7240 return;
7241
7242 /* Save registers starting from high to low. We've already saved the
7243 previous frame pointer and previous return address for the debugger's
7244 sake. The debugger allows us to not need a nop in the epilog if at least
7245 one register is reloaded in addition to return address. */
7246
7247 if (gmask)
7248 {
7249 for (regno = 1; regno <= 31; regno++)
7250 {
7251 if ((gmask & (1L << regno)) != 0)
7252 {
7253 if ((regno & 0x1) == 0 && ((gmask & (1L << (regno+1))) != 0))
7254 {
7255 /* We can save two registers in a row. If we're not at a
7256 double word boundary, move to one.
7257 sparc_flat_compute_frame_size ensures there's room to do
7258 this. */
7259 if (offset % 8 != 0)
7260 offset += UNITS_PER_WORD;
7261
7262 if (word_op[0] == 's')
7263 {
7264 fprintf (file, "\t%s\t%s, [%s+%d]\n",
7265 doubleword_op, reg_names[regno],
7266 base_reg, offset);
7267 if (dwarf2out_do_frame ())
7268 {
7269 char *l = dwarf2out_cfi_label ();
7270 dwarf2out_reg_save (l, regno, offset + base_offset);
7271 dwarf2out_reg_save
7272 (l, regno+1, offset+base_offset + UNITS_PER_WORD);
7273 }
7274 }
7275 else
7276 fprintf (file, "\t%s\t[%s+%d], %s\n",
7277 doubleword_op, base_reg, offset,
7278 reg_names[regno]);
7279
7280 offset += 2 * UNITS_PER_WORD;
7281 regno++;
7282 }
7283 else
7284 {
7285 if (word_op[0] == 's')
7286 {
7287 fprintf (file, "\t%s\t%s, [%s+%d]\n",
7288 word_op, reg_names[regno],
7289 base_reg, offset);
7290 if (dwarf2out_do_frame ())
7291 dwarf2out_reg_save ("", regno, offset + base_offset);
7292 }
7293 else
7294 fprintf (file, "\t%s\t[%s+%d], %s\n",
7295 word_op, base_reg, offset, reg_names[regno]);
7296
7297 offset += UNITS_PER_WORD;
7298 }
7299 }
7300 }
7301 }
7302
7303 if (fmask)
7304 {
7305 for (regno = 32; regno <= 63; regno++)
7306 {
7307 if ((fmask & (1L << (regno - 32))) != 0)
7308 {
7309 if (word_op[0] == 's')
7310 {
7311 fprintf (file, "\t%s\t%s, [%s+%d]\n",
7312 word_op, reg_names[regno],
7313 base_reg, offset);
7314 if (dwarf2out_do_frame ())
7315 dwarf2out_reg_save ("", regno, offset + base_offset);
7316 }
7317 else
7318 fprintf (file, "\t%s\t[%s+%d], %s\n",
7319 word_op, base_reg, offset, reg_names[regno]);
7320
7321 offset += UNITS_PER_WORD;
7322 }
7323 }
7324 }
7325 }
7326
7327 /* Set up the stack and frame (if desired) for the function. */
7328
7329 static void
sparc_flat_function_prologue(file,size)7330 sparc_flat_function_prologue (file, size)
7331 FILE *file;
7332 HOST_WIDE_INT size;
7333 {
7334 const char *sp_str = reg_names[STACK_POINTER_REGNUM];
7335 unsigned long gmask = current_frame_info.gmask;
7336
7337 sparc_output_scratch_registers (file);
7338
7339 /* This is only for the human reader. */
7340 fprintf (file, "\t%s#PROLOGUE# 0\n", ASM_COMMENT_START);
7341 fprintf (file, "\t%s# vars= %ld, regs= %d/%d, args= %d, extra= %ld\n",
7342 ASM_COMMENT_START,
7343 current_frame_info.var_size,
7344 current_frame_info.gp_reg_size / 4,
7345 current_frame_info.fp_reg_size / 4,
7346 current_function_outgoing_args_size,
7347 current_frame_info.extra_size);
7348
7349 size = SPARC_STACK_ALIGN (size);
7350 size = (! current_frame_info.initialized
7351 ? sparc_flat_compute_frame_size (size)
7352 : current_frame_info.total_size);
7353
7354 /* These cases shouldn't happen. Catch them now. */
7355 if (size == 0 && (gmask || current_frame_info.fmask))
7356 abort ();
7357
7358 /* Allocate our stack frame by decrementing %sp.
7359 At present, the only algorithm gdb can use to determine if this is a
7360 flat frame is if we always set %i7 if we set %sp. This can be optimized
7361 in the future by putting in some sort of debugging information that says
7362 this is a `flat' function. However, there is still the case of debugging
7363 code without such debugging information (including cases where most fns
7364 have such info, but there is one that doesn't). So, always do this now
7365 so we don't get a lot of code out there that gdb can't handle.
7366 If the frame pointer isn't needn't then that's ok - gdb won't be able to
7367 distinguish us from a non-flat function but there won't (and shouldn't)
7368 be any differences anyway. The return pc is saved (if necessary) right
7369 after %i7 so gdb won't have to look too far to find it. */
7370 if (size > 0)
7371 {
7372 unsigned int reg_offset = current_frame_info.reg_offset;
7373 const char *const fp_str = reg_names[HARD_FRAME_POINTER_REGNUM];
7374 static const char *const t1_str = "%g1";
7375
7376 /* Things get a little tricky if local variables take up more than ~4096
7377 bytes and outgoing arguments take up more than ~4096 bytes. When that
7378 happens, the register save area can't be accessed from either end of
7379 the frame. Handle this by decrementing %sp to the start of the gp
7380 register save area, save the regs, update %i7, and then set %sp to its
7381 final value. Given that we only have one scratch register to play
7382 with it is the cheapest solution, and it helps gdb out as it won't
7383 slow down recognition of flat functions.
7384 Don't change the order of insns emitted here without checking with
7385 the gdb folk first. */
7386
7387 /* Is the entire register save area offsettable from %sp? */
7388 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
7389 {
7390 if (size <= 4096)
7391 {
7392 fprintf (file, "\tadd\t%s, %d, %s\n",
7393 sp_str, (int) -size, sp_str);
7394 if (gmask & HARD_FRAME_POINTER_MASK)
7395 {
7396 fprintf (file, "\tst\t%s, [%s+%d]\n",
7397 fp_str, sp_str, reg_offset);
7398 fprintf (file, "\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
7399 sp_str, (int) -size, fp_str, ASM_COMMENT_START);
7400 reg_offset += 4;
7401 }
7402 }
7403 else
7404 {
7405 fprintf (file, "\tset\t");
7406 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
7407 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
7408 t1_str, sp_str, t1_str, sp_str);
7409 if (gmask & HARD_FRAME_POINTER_MASK)
7410 {
7411 fprintf (file, "\tst\t%s, [%s+%d]\n",
7412 fp_str, sp_str, reg_offset);
7413 fprintf (file, "\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
7414 sp_str, t1_str, fp_str, ASM_COMMENT_START);
7415 reg_offset += 4;
7416 }
7417 }
7418 if (dwarf2out_do_frame ())
7419 {
7420 char *l = dwarf2out_cfi_label ();
7421 if (gmask & HARD_FRAME_POINTER_MASK)
7422 {
7423 dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM,
7424 reg_offset - 4 - size);
7425 dwarf2out_def_cfa (l, HARD_FRAME_POINTER_REGNUM, 0);
7426 }
7427 else
7428 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size);
7429 }
7430 if (gmask & RETURN_ADDR_MASK)
7431 {
7432 fprintf (file, "\tst\t%s, [%s+%d]\n",
7433 reg_names[RETURN_ADDR_REGNUM], sp_str, reg_offset);
7434 if (dwarf2out_do_frame ())
7435 dwarf2out_return_save ("", reg_offset - size);
7436 reg_offset += 4;
7437 }
7438 sparc_flat_save_restore (file, sp_str, reg_offset,
7439 gmask & ~(HARD_FRAME_POINTER_MASK | RETURN_ADDR_MASK),
7440 current_frame_info.fmask,
7441 "st", "std", -size);
7442 }
7443 else
7444 {
7445 /* Subtract %sp in two steps, but make sure there is always a
7446 64 byte register save area, and %sp is properly aligned. */
7447 /* Amount to decrement %sp by, the first time. */
7448 unsigned HOST_WIDE_INT size1 = ((size - reg_offset + 64) + 15) & -16;
7449 /* Offset to register save area from %sp. */
7450 unsigned HOST_WIDE_INT offset = size1 - (size - reg_offset);
7451
7452 if (size1 <= 4096)
7453 {
7454 fprintf (file, "\tadd\t%s, %d, %s\n",
7455 sp_str, (int) -size1, sp_str);
7456 if (gmask & HARD_FRAME_POINTER_MASK)
7457 {
7458 fprintf (file, "\tst\t%s, [%s+%d]\n\tsub\t%s, %d, %s\t%s# set up frame pointer\n",
7459 fp_str, sp_str, (int) offset, sp_str, (int) -size1,
7460 fp_str, ASM_COMMENT_START);
7461 offset += 4;
7462 }
7463 }
7464 else
7465 {
7466 fprintf (file, "\tset\t");
7467 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size1);
7468 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
7469 t1_str, sp_str, t1_str, sp_str);
7470 if (gmask & HARD_FRAME_POINTER_MASK)
7471 {
7472 fprintf (file, "\tst\t%s, [%s+%d]\n\tadd\t%s, %s, %s\t%s# set up frame pointer\n",
7473 fp_str, sp_str, (int) offset, sp_str, t1_str,
7474 fp_str, ASM_COMMENT_START);
7475 offset += 4;
7476 }
7477 }
7478 if (dwarf2out_do_frame ())
7479 {
7480 char *l = dwarf2out_cfi_label ();
7481 if (gmask & HARD_FRAME_POINTER_MASK)
7482 {
7483 dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM,
7484 offset - 4 - size1);
7485 dwarf2out_def_cfa (l, HARD_FRAME_POINTER_REGNUM, 0);
7486 }
7487 else
7488 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size1);
7489 }
7490 if (gmask & RETURN_ADDR_MASK)
7491 {
7492 fprintf (file, "\tst\t%s, [%s+%d]\n",
7493 reg_names[RETURN_ADDR_REGNUM], sp_str, (int) offset);
7494 if (dwarf2out_do_frame ())
7495 /* offset - size1 == reg_offset - size
7496 if reg_offset were updated above like offset. */
7497 dwarf2out_return_save ("", offset - size1);
7498 offset += 4;
7499 }
7500 sparc_flat_save_restore (file, sp_str, offset,
7501 gmask & ~(HARD_FRAME_POINTER_MASK | RETURN_ADDR_MASK),
7502 current_frame_info.fmask,
7503 "st", "std", -size1);
7504 fprintf (file, "\tset\t");
7505 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size - size1);
7506 fprintf (file, ", %s\n\tsub\t%s, %s, %s\n",
7507 t1_str, sp_str, t1_str, sp_str);
7508 if (dwarf2out_do_frame ())
7509 if (! (gmask & HARD_FRAME_POINTER_MASK))
7510 dwarf2out_def_cfa ("", STACK_POINTER_REGNUM, size);
7511 }
7512 }
7513
7514 fprintf (file, "\t%s#PROLOGUE# 1\n", ASM_COMMENT_START);
7515 }
7516
7517 /* Do any necessary cleanup after a function to restore stack, frame,
7518 and regs. */
7519
7520 static void
sparc_flat_function_epilogue(file,size)7521 sparc_flat_function_epilogue (file, size)
7522 FILE *file;
7523 HOST_WIDE_INT size;
7524 {
7525 rtx epilogue_delay = current_function_epilogue_delay_list;
7526 int noepilogue = FALSE;
7527
7528 /* This is only for the human reader. */
7529 fprintf (file, "\t%s#EPILOGUE#\n", ASM_COMMENT_START);
7530
7531 /* The epilogue does not depend on any registers, but the stack
7532 registers, so we assume that if we have 1 pending nop, it can be
7533 ignored, and 2 it must be filled (2 nops occur for integer
7534 multiply and divide). */
7535
7536 size = SPARC_STACK_ALIGN (size);
7537 size = (!current_frame_info.initialized
7538 ? sparc_flat_compute_frame_size (size)
7539 : current_frame_info.total_size);
7540
7541 if (size == 0 && epilogue_delay == 0)
7542 {
7543 rtx insn = get_last_insn ();
7544
7545 /* If the last insn was a BARRIER, we don't have to write any code
7546 because a jump (aka return) was put there. */
7547 if (GET_CODE (insn) == NOTE)
7548 insn = prev_nonnote_insn (insn);
7549 if (insn && GET_CODE (insn) == BARRIER)
7550 noepilogue = TRUE;
7551 }
7552
7553 if (!noepilogue)
7554 {
7555 unsigned HOST_WIDE_INT reg_offset = current_frame_info.reg_offset;
7556 unsigned HOST_WIDE_INT size1;
7557 const char *const sp_str = reg_names[STACK_POINTER_REGNUM];
7558 const char *const fp_str = reg_names[HARD_FRAME_POINTER_REGNUM];
7559 static const char *const t1_str = "%g1";
7560
7561 /* In the reload sequence, we don't need to fill the load delay
7562 slots for most of the loads, also see if we can fill the final
7563 delay slot if not otherwise filled by the reload sequence. */
7564
7565 if (size > 4095)
7566 {
7567 fprintf (file, "\tset\t");
7568 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
7569 fprintf (file, ", %s\n", t1_str);
7570 }
7571
7572 if (frame_pointer_needed)
7573 {
7574 if (size > 4095)
7575 fprintf (file,"\tsub\t%s, %s, %s\t\t%s# sp not trusted here\n",
7576 fp_str, t1_str, sp_str, ASM_COMMENT_START);
7577 else
7578 fprintf (file,"\tsub\t%s, %d, %s\t\t%s# sp not trusted here\n",
7579 fp_str, (int) size, sp_str, ASM_COMMENT_START);
7580 }
7581
7582 /* Is the entire register save area offsettable from %sp? */
7583 if (reg_offset < 4096 - 64 * (unsigned) UNITS_PER_WORD)
7584 {
7585 size1 = 0;
7586 }
7587 else
7588 {
7589 /* Restore %sp in two steps, but make sure there is always a
7590 64 byte register save area, and %sp is properly aligned. */
7591 /* Amount to increment %sp by, the first time. */
7592 size1 = ((reg_offset - 64 - 16) + 15) & -16;
7593 /* Offset to register save area from %sp. */
7594 reg_offset = size1 - reg_offset;
7595
7596 fprintf (file, "\tset\t");
7597 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size1);
7598 fprintf (file, ", %s\n\tadd\t%s, %s, %s\n",
7599 t1_str, sp_str, t1_str, sp_str);
7600 }
7601
7602 /* We must restore the frame pointer and return address reg first
7603 because they are treated specially by the prologue output code. */
7604 if (current_frame_info.gmask & HARD_FRAME_POINTER_MASK)
7605 {
7606 fprintf (file, "\tld\t[%s+%d], %s\n",
7607 sp_str, (int) reg_offset, fp_str);
7608 reg_offset += 4;
7609 }
7610 if (current_frame_info.gmask & RETURN_ADDR_MASK)
7611 {
7612 fprintf (file, "\tld\t[%s+%d], %s\n",
7613 sp_str, (int) reg_offset, reg_names[RETURN_ADDR_REGNUM]);
7614 reg_offset += 4;
7615 }
7616
7617 /* Restore any remaining saved registers. */
7618 sparc_flat_save_restore (file, sp_str, reg_offset,
7619 current_frame_info.gmask & ~(HARD_FRAME_POINTER_MASK | RETURN_ADDR_MASK),
7620 current_frame_info.fmask,
7621 "ld", "ldd", 0);
7622
7623 /* If we had to increment %sp in two steps, record it so the second
7624 restoration in the epilogue finishes up. */
7625 if (size1 > 0)
7626 {
7627 size -= size1;
7628 if (size > 4095)
7629 {
7630 fprintf (file, "\tset\t");
7631 fprintf (file, HOST_WIDE_INT_PRINT_DEC, size);
7632 fprintf (file, ", %s\n", t1_str);
7633 }
7634 }
7635
7636 if (current_function_returns_struct)
7637 fprintf (file, "\tjmp\t%%o7+12\n");
7638 else
7639 fprintf (file, "\tretl\n");
7640
7641 /* If the only register saved is the return address, we need a
7642 nop, unless we have an instruction to put into it. Otherwise
7643 we don't since reloading multiple registers doesn't reference
7644 the register being loaded. */
7645
7646 if (epilogue_delay)
7647 {
7648 if (size)
7649 abort ();
7650 final_scan_insn (XEXP (epilogue_delay, 0), file, 1, -2, 1);
7651 }
7652
7653 else if (size > 4095)
7654 fprintf (file, "\tadd\t%s, %s, %s\n", sp_str, t1_str, sp_str);
7655
7656 else if (size > 0)
7657 fprintf (file, "\tadd\t%s, %d, %s\n", sp_str, (int) size, sp_str);
7658
7659 else
7660 fprintf (file, "\tnop\n");
7661 }
7662
7663 /* Reset state info for each function. */
7664 current_frame_info = zero_frame_info;
7665
7666 sparc_output_deferred_case_vectors ();
7667 }
7668
7669 /* Define the number of delay slots needed for the function epilogue.
7670
7671 On the sparc, we need a slot if either no stack has been allocated,
7672 or the only register saved is the return register. */
7673
7674 int
sparc_flat_epilogue_delay_slots()7675 sparc_flat_epilogue_delay_slots ()
7676 {
7677 if (!current_frame_info.initialized)
7678 (void) sparc_flat_compute_frame_size (get_frame_size ());
7679
7680 if (current_frame_info.total_size == 0)
7681 return 1;
7682
7683 return 0;
7684 }
7685
7686 /* Return true if TRIAL is a valid insn for the epilogue delay slot.
7687 Any single length instruction which doesn't reference the stack or frame
7688 pointer is OK. */
7689
7690 int
sparc_flat_eligible_for_epilogue_delay(trial,slot)7691 sparc_flat_eligible_for_epilogue_delay (trial, slot)
7692 rtx trial;
7693 int slot ATTRIBUTE_UNUSED;
7694 {
7695 rtx pat = PATTERN (trial);
7696
7697 if (get_attr_length (trial) != 1)
7698 return 0;
7699
7700 if (! reg_mentioned_p (stack_pointer_rtx, pat)
7701 && ! reg_mentioned_p (frame_pointer_rtx, pat))
7702 return 1;
7703
7704 return 0;
7705 }
7706
7707 /* Adjust the cost of a scheduling dependency. Return the new cost of
7708 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
7709
7710 static int
supersparc_adjust_cost(insn,link,dep_insn,cost)7711 supersparc_adjust_cost (insn, link, dep_insn, cost)
7712 rtx insn;
7713 rtx link;
7714 rtx dep_insn;
7715 int cost;
7716 {
7717 enum attr_type insn_type;
7718
7719 if (! recog_memoized (insn))
7720 return 0;
7721
7722 insn_type = get_attr_type (insn);
7723
7724 if (REG_NOTE_KIND (link) == 0)
7725 {
7726 /* Data dependency; DEP_INSN writes a register that INSN reads some
7727 cycles later. */
7728
7729 /* if a load, then the dependence must be on the memory address;
7730 add an extra "cycle". Note that the cost could be two cycles
7731 if the reg was written late in an instruction group; we ca not tell
7732 here. */
7733 if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
7734 return cost + 3;
7735
7736 /* Get the delay only if the address of the store is the dependence. */
7737 if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
7738 {
7739 rtx pat = PATTERN(insn);
7740 rtx dep_pat = PATTERN (dep_insn);
7741
7742 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7743 return cost; /* This should not happen! */
7744
7745 /* The dependency between the two instructions was on the data that
7746 is being stored. Assume that this implies that the address of the
7747 store is not dependent. */
7748 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7749 return cost;
7750
7751 return cost + 3; /* An approximation. */
7752 }
7753
7754 /* A shift instruction cannot receive its data from an instruction
7755 in the same cycle; add a one cycle penalty. */
7756 if (insn_type == TYPE_SHIFT)
7757 return cost + 3; /* Split before cascade into shift. */
7758 }
7759 else
7760 {
7761 /* Anti- or output- dependency; DEP_INSN reads/writes a register that
7762 INSN writes some cycles later. */
7763
7764 /* These are only significant for the fpu unit; writing a fp reg before
7765 the fpu has finished with it stalls the processor. */
7766
7767 /* Reusing an integer register causes no problems. */
7768 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7769 return 0;
7770 }
7771
7772 return cost;
7773 }
7774
7775 static int
hypersparc_adjust_cost(insn,link,dep_insn,cost)7776 hypersparc_adjust_cost (insn, link, dep_insn, cost)
7777 rtx insn;
7778 rtx link;
7779 rtx dep_insn;
7780 int cost;
7781 {
7782 enum attr_type insn_type, dep_type;
7783 rtx pat = PATTERN(insn);
7784 rtx dep_pat = PATTERN (dep_insn);
7785
7786 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
7787 return cost;
7788
7789 insn_type = get_attr_type (insn);
7790 dep_type = get_attr_type (dep_insn);
7791
7792 switch (REG_NOTE_KIND (link))
7793 {
7794 case 0:
7795 /* Data dependency; DEP_INSN writes a register that INSN reads some
7796 cycles later. */
7797
7798 switch (insn_type)
7799 {
7800 case TYPE_STORE:
7801 case TYPE_FPSTORE:
7802 /* Get the delay iff the address of the store is the dependence. */
7803 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
7804 return cost;
7805
7806 if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
7807 return cost;
7808 return cost + 3;
7809
7810 case TYPE_LOAD:
7811 case TYPE_SLOAD:
7812 case TYPE_FPLOAD:
7813 /* If a load, then the dependence must be on the memory address. If
7814 the addresses aren't equal, then it might be a false dependency */
7815 if (dep_type == TYPE_STORE || dep_type == TYPE_FPSTORE)
7816 {
7817 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET
7818 || GET_CODE (SET_DEST (dep_pat)) != MEM
7819 || GET_CODE (SET_SRC (pat)) != MEM
7820 || ! rtx_equal_p (XEXP (SET_DEST (dep_pat), 0),
7821 XEXP (SET_SRC (pat), 0)))
7822 return cost + 2;
7823
7824 return cost + 8;
7825 }
7826 break;
7827
7828 case TYPE_BRANCH:
7829 /* Compare to branch latency is 0. There is no benefit from
7830 separating compare and branch. */
7831 if (dep_type == TYPE_COMPARE)
7832 return 0;
7833 /* Floating point compare to branch latency is less than
7834 compare to conditional move. */
7835 if (dep_type == TYPE_FPCMP)
7836 return cost - 1;
7837 break;
7838 default:
7839 break;
7840 }
7841 break;
7842
7843 case REG_DEP_ANTI:
7844 /* Anti-dependencies only penalize the fpu unit. */
7845 if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
7846 return 0;
7847 break;
7848
7849 default:
7850 break;
7851 }
7852
7853 return cost;
7854 }
7855
7856 static int
sparc_adjust_cost(insn,link,dep,cost)7857 sparc_adjust_cost(insn, link, dep, cost)
7858 rtx insn;
7859 rtx link;
7860 rtx dep;
7861 int cost;
7862 {
7863 switch (sparc_cpu)
7864 {
7865 case PROCESSOR_SUPERSPARC:
7866 cost = supersparc_adjust_cost (insn, link, dep, cost);
7867 break;
7868 case PROCESSOR_HYPERSPARC:
7869 case PROCESSOR_SPARCLITE86X:
7870 cost = hypersparc_adjust_cost (insn, link, dep, cost);
7871 break;
7872 default:
7873 break;
7874 }
7875 return cost;
7876 }
7877
7878 static void
sparc_sched_init(dump,sched_verbose,max_ready)7879 sparc_sched_init (dump, sched_verbose, max_ready)
7880 FILE *dump ATTRIBUTE_UNUSED;
7881 int sched_verbose ATTRIBUTE_UNUSED;
7882 int max_ready ATTRIBUTE_UNUSED;
7883 {
7884 }
7885
7886 static int
sparc_use_dfa_pipeline_interface()7887 sparc_use_dfa_pipeline_interface ()
7888 {
7889 if ((1 << sparc_cpu) &
7890 ((1 << PROCESSOR_ULTRASPARC) | (1 << PROCESSOR_CYPRESS) |
7891 (1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
7892 (1 << PROCESSOR_SPARCLITE86X) | (1 << PROCESSOR_TSC701) |
7893 (1 << PROCESSOR_ULTRASPARC3)))
7894 return 1;
7895 return 0;
7896 }
7897
7898 static int
sparc_use_sched_lookahead()7899 sparc_use_sched_lookahead ()
7900 {
7901 if (sparc_cpu == PROCESSOR_ULTRASPARC
7902 || sparc_cpu == PROCESSOR_ULTRASPARC3)
7903 return 4;
7904 if ((1 << sparc_cpu) &
7905 ((1 << PROCESSOR_SUPERSPARC) | (1 << PROCESSOR_HYPERSPARC) |
7906 (1 << PROCESSOR_SPARCLITE86X)))
7907 return 3;
7908 return 0;
7909 }
7910
7911 static int
sparc_issue_rate()7912 sparc_issue_rate ()
7913 {
7914 switch (sparc_cpu)
7915 {
7916 default:
7917 return 1;
7918 case PROCESSOR_V9:
7919 /* Assume V9 processors are capable of at least dual-issue. */
7920 return 2;
7921 case PROCESSOR_SUPERSPARC:
7922 return 3;
7923 case PROCESSOR_HYPERSPARC:
7924 case PROCESSOR_SPARCLITE86X:
7925 return 2;
7926 case PROCESSOR_ULTRASPARC:
7927 case PROCESSOR_ULTRASPARC3:
7928 return 4;
7929 }
7930 }
7931
7932 static int
set_extends(insn)7933 set_extends (insn)
7934 rtx insn;
7935 {
7936 register rtx pat = PATTERN (insn);
7937
7938 switch (GET_CODE (SET_SRC (pat)))
7939 {
7940 /* Load and some shift instructions zero extend. */
7941 case MEM:
7942 case ZERO_EXTEND:
7943 /* sethi clears the high bits */
7944 case HIGH:
7945 /* LO_SUM is used with sethi. sethi cleared the high
7946 bits and the values used with lo_sum are positive */
7947 case LO_SUM:
7948 /* Store flag stores 0 or 1 */
7949 case LT: case LTU:
7950 case GT: case GTU:
7951 case LE: case LEU:
7952 case GE: case GEU:
7953 case EQ:
7954 case NE:
7955 return 1;
7956 case AND:
7957 {
7958 rtx op0 = XEXP (SET_SRC (pat), 0);
7959 rtx op1 = XEXP (SET_SRC (pat), 1);
7960 if (GET_CODE (op1) == CONST_INT)
7961 return INTVAL (op1) >= 0;
7962 if (GET_CODE (op0) != REG)
7963 return 0;
7964 if (sparc_check_64 (op0, insn) == 1)
7965 return 1;
7966 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7967 }
7968 case IOR:
7969 case XOR:
7970 {
7971 rtx op0 = XEXP (SET_SRC (pat), 0);
7972 rtx op1 = XEXP (SET_SRC (pat), 1);
7973 if (GET_CODE (op0) != REG || sparc_check_64 (op0, insn) <= 0)
7974 return 0;
7975 if (GET_CODE (op1) == CONST_INT)
7976 return INTVAL (op1) >= 0;
7977 return (GET_CODE (op1) == REG && sparc_check_64 (op1, insn) == 1);
7978 }
7979 case LSHIFTRT:
7980 return GET_MODE (SET_SRC (pat)) == SImode;
7981 /* Positive integers leave the high bits zero. */
7982 case CONST_DOUBLE:
7983 return ! (CONST_DOUBLE_LOW (SET_SRC (pat)) & 0x80000000);
7984 case CONST_INT:
7985 return ! (INTVAL (SET_SRC (pat)) & 0x80000000);
7986 case ASHIFTRT:
7987 case SIGN_EXTEND:
7988 return - (GET_MODE (SET_SRC (pat)) == SImode);
7989 case REG:
7990 return sparc_check_64 (SET_SRC (pat), insn);
7991 default:
7992 return 0;
7993 }
7994 }
7995
7996 /* We _ought_ to have only one kind per function, but... */
7997 static GTY(()) rtx sparc_addr_diff_list;
7998 static GTY(()) rtx sparc_addr_list;
7999
8000 void
sparc_defer_case_vector(lab,vec,diff)8001 sparc_defer_case_vector (lab, vec, diff)
8002 rtx lab, vec;
8003 int diff;
8004 {
8005 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
8006 if (diff)
8007 sparc_addr_diff_list
8008 = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_diff_list);
8009 else
8010 sparc_addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, sparc_addr_list);
8011 }
8012
8013 static void
sparc_output_addr_vec(vec)8014 sparc_output_addr_vec (vec)
8015 rtx vec;
8016 {
8017 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8018 int idx, vlen = XVECLEN (body, 0);
8019
8020 #ifdef ASM_OUTPUT_ADDR_VEC_START
8021 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8022 #endif
8023
8024 #ifdef ASM_OUTPUT_CASE_LABEL
8025 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8026 NEXT_INSN (lab));
8027 #else
8028 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8029 #endif
8030
8031 for (idx = 0; idx < vlen; idx++)
8032 {
8033 ASM_OUTPUT_ADDR_VEC_ELT
8034 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
8035 }
8036
8037 #ifdef ASM_OUTPUT_ADDR_VEC_END
8038 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8039 #endif
8040 }
8041
8042 static void
sparc_output_addr_diff_vec(vec)8043 sparc_output_addr_diff_vec (vec)
8044 rtx vec;
8045 {
8046 rtx lab = XEXP (vec, 0), body = XEXP (vec, 1);
8047 rtx base = XEXP (XEXP (body, 0), 0);
8048 int idx, vlen = XVECLEN (body, 1);
8049
8050 #ifdef ASM_OUTPUT_ADDR_VEC_START
8051 ASM_OUTPUT_ADDR_VEC_START (asm_out_file);
8052 #endif
8053
8054 #ifdef ASM_OUTPUT_CASE_LABEL
8055 ASM_OUTPUT_CASE_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab),
8056 NEXT_INSN (lab));
8057 #else
8058 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
8059 #endif
8060
8061 for (idx = 0; idx < vlen; idx++)
8062 {
8063 ASM_OUTPUT_ADDR_DIFF_ELT
8064 (asm_out_file,
8065 body,
8066 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
8067 CODE_LABEL_NUMBER (base));
8068 }
8069
8070 #ifdef ASM_OUTPUT_ADDR_VEC_END
8071 ASM_OUTPUT_ADDR_VEC_END (asm_out_file);
8072 #endif
8073 }
8074
8075 static void
sparc_output_deferred_case_vectors()8076 sparc_output_deferred_case_vectors ()
8077 {
8078 rtx t;
8079 int align;
8080
8081 if (sparc_addr_list == NULL_RTX
8082 && sparc_addr_diff_list == NULL_RTX)
8083 return;
8084
8085 /* Align to cache line in the function's code section. */
8086 function_section (current_function_decl);
8087
8088 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
8089 if (align > 0)
8090 ASM_OUTPUT_ALIGN (asm_out_file, align);
8091
8092 for (t = sparc_addr_list; t ; t = XEXP (t, 1))
8093 sparc_output_addr_vec (XEXP (t, 0));
8094 for (t = sparc_addr_diff_list; t ; t = XEXP (t, 1))
8095 sparc_output_addr_diff_vec (XEXP (t, 0));
8096
8097 sparc_addr_list = sparc_addr_diff_list = NULL_RTX;
8098 }
8099
8100 /* Return 0 if the high 32 bits of X (the low word of X, if DImode) are
8101 unknown. Return 1 if the high bits are zero, -1 if the register is
8102 sign extended. */
8103 int
sparc_check_64(x,insn)8104 sparc_check_64 (x, insn)
8105 rtx x, insn;
8106 {
8107 /* If a register is set only once it is safe to ignore insns this
8108 code does not know how to handle. The loop will either recognize
8109 the single set and return the correct value or fail to recognize
8110 it and return 0. */
8111 int set_once = 0;
8112 rtx y = x;
8113
8114 if (GET_CODE (x) != REG)
8115 abort ();
8116
8117 if (GET_MODE (x) == DImode)
8118 y = gen_rtx_REG (SImode, REGNO (x) + WORDS_BIG_ENDIAN);
8119
8120 if (flag_expensive_optimizations
8121 && REG_N_SETS (REGNO (y)) == 1)
8122 set_once = 1;
8123
8124 if (insn == 0)
8125 {
8126 if (set_once)
8127 insn = get_last_insn_anywhere ();
8128 else
8129 return 0;
8130 }
8131
8132 while ((insn = PREV_INSN (insn)))
8133 {
8134 switch (GET_CODE (insn))
8135 {
8136 case JUMP_INSN:
8137 case NOTE:
8138 break;
8139 case CODE_LABEL:
8140 case CALL_INSN:
8141 default:
8142 if (! set_once)
8143 return 0;
8144 break;
8145 case INSN:
8146 {
8147 rtx pat = PATTERN (insn);
8148 if (GET_CODE (pat) != SET)
8149 return 0;
8150 if (rtx_equal_p (x, SET_DEST (pat)))
8151 return set_extends (insn);
8152 if (y && rtx_equal_p (y, SET_DEST (pat)))
8153 return set_extends (insn);
8154 if (reg_overlap_mentioned_p (SET_DEST (pat), y))
8155 return 0;
8156 }
8157 }
8158 }
8159 return 0;
8160 }
8161
8162 /* Returns assembly code to perform a DImode shift using
8163 a 64-bit global or out register on SPARC-V8+. */
8164 char *
sparc_v8plus_shift(operands,insn,opcode)8165 sparc_v8plus_shift (operands, insn, opcode)
8166 rtx *operands;
8167 rtx insn;
8168 const char *opcode;
8169 {
8170 static char asm_code[60];
8171
8172 /* The scratch register is only required when the destination
8173 register is not a 64-bit global or out register. */
8174 if (which_alternative != 2)
8175 operands[3] = operands[0];
8176
8177 /* We can only shift by constants <= 63. */
8178 if (GET_CODE (operands[2]) == CONST_INT)
8179 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
8180
8181 if (GET_CODE (operands[1]) == CONST_INT)
8182 {
8183 output_asm_insn ("mov\t%1, %3", operands);
8184 }
8185 else
8186 {
8187 output_asm_insn ("sllx\t%H1, 32, %3", operands);
8188 if (sparc_check_64 (operands[1], insn) <= 0)
8189 output_asm_insn ("srl\t%L1, 0, %L1", operands);
8190 output_asm_insn ("or\t%L1, %3, %3", operands);
8191 }
8192
8193 strcpy(asm_code, opcode);
8194
8195 if (which_alternative != 2)
8196 return strcat (asm_code, "\t%0, %2, %L0\n\tsrlx\t%L0, 32, %H0");
8197 else
8198 return strcat (asm_code, "\t%3, %2, %3\n\tsrlx\t%3, 32, %H0\n\tmov\t%3, %L0");
8199 }
8200
8201 /* Output rtl to increment the profiler label LABELNO
8202 for profiling a function entry. */
8203
8204 void
sparc_profile_hook(labelno)8205 sparc_profile_hook (labelno)
8206 int labelno;
8207 {
8208 char buf[32];
8209 rtx lab, fun;
8210
8211 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
8212 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
8213 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_FUNCTION);
8214
8215 emit_library_call (fun, LCT_NORMAL, VOIDmode, 1, lab, Pmode);
8216 }
8217
8218 #ifdef OBJECT_FORMAT_ELF
8219 static void
sparc_elf_asm_named_section(name,flags)8220 sparc_elf_asm_named_section (name, flags)
8221 const char *name;
8222 unsigned int flags;
8223 {
8224 if (flags & SECTION_MERGE)
8225 {
8226 /* entsize cannot be expressed in this section attributes
8227 encoding style. */
8228 default_elf_asm_named_section (name, flags);
8229 return;
8230 }
8231
8232 fprintf (asm_out_file, "\t.section\t\"%s\"", name);
8233
8234 if (!(flags & SECTION_DEBUG))
8235 fputs (",#alloc", asm_out_file);
8236 if (flags & SECTION_WRITE)
8237 fputs (",#write", asm_out_file);
8238 if (flags & SECTION_CODE)
8239 fputs (",#execinstr", asm_out_file);
8240
8241 /* ??? Handle SECTION_BSS. */
8242
8243 fputc ('\n', asm_out_file);
8244 }
8245 #endif /* OBJECT_FORMAT_ELF */
8246
8247 /* ??? Similar to the standard section selection, but force reloc-y-ness
8248 if SUNOS4_SHARED_LIBRARIES. Unclear why this helps (as opposed to
8249 pretending PIC always on), but that's what the old code did. */
8250
8251 static void
sparc_aout_select_section(t,reloc,align)8252 sparc_aout_select_section (t, reloc, align)
8253 tree t;
8254 int reloc;
8255 unsigned HOST_WIDE_INT align;
8256 {
8257 default_select_section (t, reloc | SUNOS4_SHARED_LIBRARIES, align);
8258 }
8259
8260 /* Use text section for a constant unless we need more alignment than
8261 that offers. */
8262
8263 static void
sparc_aout_select_rtx_section(mode,x,align)8264 sparc_aout_select_rtx_section (mode, x, align)
8265 enum machine_mode mode;
8266 rtx x;
8267 unsigned HOST_WIDE_INT align;
8268 {
8269 if (align <= MAX_TEXT_ALIGN
8270 && ! (flag_pic && (symbolic_operand (x, mode)
8271 || SUNOS4_SHARED_LIBRARIES)))
8272 readonly_data_section ();
8273 else
8274 data_section ();
8275 }
8276
8277 int
sparc_extra_constraint_check(op,c,strict)8278 sparc_extra_constraint_check (op, c, strict)
8279 rtx op;
8280 int c;
8281 int strict;
8282 {
8283 int reload_ok_mem;
8284
8285 if (TARGET_ARCH64
8286 && (c == 'T' || c == 'U'))
8287 return 0;
8288
8289 switch (c)
8290 {
8291 case 'Q':
8292 return fp_sethi_p (op);
8293
8294 case 'R':
8295 return fp_mov_p (op);
8296
8297 case 'S':
8298 return fp_high_losum_p (op);
8299
8300 case 'U':
8301 if (! strict
8302 || (GET_CODE (op) == REG
8303 && (REGNO (op) < FIRST_PSEUDO_REGISTER
8304 || reg_renumber[REGNO (op)] >= 0)))
8305 return register_ok_for_ldd (op);
8306
8307 return 0;
8308
8309 case 'W':
8310 case 'T':
8311 break;
8312
8313 default:
8314 return 0;
8315 }
8316
8317 /* Our memory extra constraints have to emulate the
8318 behavior of 'm' and 'o' in order for reload to work
8319 correctly. */
8320 if (GET_CODE (op) == MEM)
8321 {
8322 reload_ok_mem = 0;
8323 if ((TARGET_ARCH64 || mem_min_alignment (op, 8))
8324 && (! strict
8325 || strict_memory_address_p (Pmode, XEXP (op, 0))))
8326 reload_ok_mem = 1;
8327 }
8328 else
8329 {
8330 reload_ok_mem = (reload_in_progress
8331 && GET_CODE (op) == REG
8332 && REGNO (op) >= FIRST_PSEUDO_REGISTER
8333 && reg_renumber [REGNO (op)] < 0);
8334 }
8335
8336 return reload_ok_mem;
8337 }
8338
8339 /* ??? This duplicates information provided to the compiler by the
8340 ??? scheduler description. Some day, teach genautomata to output
8341 ??? the latencies and then CSE will just use that. */
8342
8343 int
sparc_rtx_costs(x,code,outer_code)8344 sparc_rtx_costs (x, code, outer_code)
8345 rtx x;
8346 enum rtx_code code, outer_code;
8347 {
8348 switch (code)
8349 {
8350 case PLUS: case MINUS: case ABS: case NEG:
8351 case FLOAT: case UNSIGNED_FLOAT:
8352 case FIX: case UNSIGNED_FIX:
8353 case FLOAT_EXTEND: case FLOAT_TRUNCATE:
8354 if (FLOAT_MODE_P (GET_MODE (x)))
8355 {
8356 switch (sparc_cpu)
8357 {
8358 case PROCESSOR_ULTRASPARC:
8359 case PROCESSOR_ULTRASPARC3:
8360 return COSTS_N_INSNS (4);
8361
8362 case PROCESSOR_SUPERSPARC:
8363 return COSTS_N_INSNS (3);
8364
8365 case PROCESSOR_CYPRESS:
8366 return COSTS_N_INSNS (5);
8367
8368 case PROCESSOR_HYPERSPARC:
8369 case PROCESSOR_SPARCLITE86X:
8370 default:
8371 return COSTS_N_INSNS (1);
8372 }
8373 }
8374
8375 return COSTS_N_INSNS (1);
8376
8377 case SQRT:
8378 switch (sparc_cpu)
8379 {
8380 case PROCESSOR_ULTRASPARC:
8381 if (GET_MODE (x) == SFmode)
8382 return COSTS_N_INSNS (13);
8383 else
8384 return COSTS_N_INSNS (23);
8385
8386 case PROCESSOR_ULTRASPARC3:
8387 if (GET_MODE (x) == SFmode)
8388 return COSTS_N_INSNS (20);
8389 else
8390 return COSTS_N_INSNS (29);
8391
8392 case PROCESSOR_SUPERSPARC:
8393 return COSTS_N_INSNS (12);
8394
8395 case PROCESSOR_CYPRESS:
8396 return COSTS_N_INSNS (63);
8397
8398 case PROCESSOR_HYPERSPARC:
8399 case PROCESSOR_SPARCLITE86X:
8400 return COSTS_N_INSNS (17);
8401
8402 default:
8403 return COSTS_N_INSNS (30);
8404 }
8405
8406 case COMPARE:
8407 if (FLOAT_MODE_P (GET_MODE (x)))
8408 {
8409 switch (sparc_cpu)
8410 {
8411 case PROCESSOR_ULTRASPARC:
8412 case PROCESSOR_ULTRASPARC3:
8413 return COSTS_N_INSNS (1);
8414
8415 case PROCESSOR_SUPERSPARC:
8416 return COSTS_N_INSNS (3);
8417
8418 case PROCESSOR_CYPRESS:
8419 return COSTS_N_INSNS (5);
8420
8421 case PROCESSOR_HYPERSPARC:
8422 case PROCESSOR_SPARCLITE86X:
8423 default:
8424 return COSTS_N_INSNS (1);
8425 }
8426 }
8427
8428 /* ??? Maybe mark integer compares as zero cost on
8429 ??? all UltraSPARC processors because the result
8430 ??? can be bypassed to a branch in the same group. */
8431
8432 return COSTS_N_INSNS (1);
8433
8434 case MULT:
8435 if (FLOAT_MODE_P (GET_MODE (x)))
8436 {
8437 switch (sparc_cpu)
8438 {
8439 case PROCESSOR_ULTRASPARC:
8440 case PROCESSOR_ULTRASPARC3:
8441 return COSTS_N_INSNS (4);
8442
8443 case PROCESSOR_SUPERSPARC:
8444 return COSTS_N_INSNS (3);
8445
8446 case PROCESSOR_CYPRESS:
8447 return COSTS_N_INSNS (7);
8448
8449 case PROCESSOR_HYPERSPARC:
8450 case PROCESSOR_SPARCLITE86X:
8451 return COSTS_N_INSNS (1);
8452
8453 default:
8454 return COSTS_N_INSNS (5);
8455 }
8456 }
8457
8458 /* The latency is actually variable for Ultra-I/II
8459 And if one of the inputs have a known constant
8460 value, we could calculate this precisely.
8461
8462 However, for that to be useful we would need to
8463 add some machine description changes which would
8464 make sure small constants ended up in rs1 of the
8465 multiply instruction. This is because the multiply
8466 latency is determined by the number of clear (or
8467 set if the value is negative) bits starting from
8468 the most significant bit of the first input.
8469
8470 The algorithm for computing num_cycles of a multiply
8471 on Ultra-I/II is:
8472
8473 if (rs1 < 0)
8474 highest_bit = highest_clear_bit(rs1);
8475 else
8476 highest_bit = highest_set_bit(rs1);
8477 if (num_bits < 3)
8478 highest_bit = 3;
8479 num_cycles = 4 + ((highest_bit - 3) / 2);
8480
8481 If we did that we would have to also consider register
8482 allocation issues that would result from forcing such
8483 a value into a register.
8484
8485 There are other similar tricks we could play if we
8486 knew, for example, that one input was an array index.
8487
8488 Since we do not play any such tricks currently the
8489 safest thing to do is report the worst case latency. */
8490 if (sparc_cpu == PROCESSOR_ULTRASPARC)
8491 return (GET_MODE (x) == DImode ?
8492 COSTS_N_INSNS (34) : COSTS_N_INSNS (19));
8493
8494 /* Multiply latency on Ultra-III, fortunately, is constant. */
8495 if (sparc_cpu == PROCESSOR_ULTRASPARC3)
8496 return COSTS_N_INSNS (6);
8497
8498 if (sparc_cpu == PROCESSOR_HYPERSPARC
8499 || sparc_cpu == PROCESSOR_SPARCLITE86X)
8500 return COSTS_N_INSNS (17);
8501
8502 return (TARGET_HARD_MUL
8503 ? COSTS_N_INSNS (5)
8504 : COSTS_N_INSNS (25));
8505
8506 case DIV:
8507 case UDIV:
8508 case MOD:
8509 case UMOD:
8510 if (FLOAT_MODE_P (GET_MODE (x)))
8511 {
8512 switch (sparc_cpu)
8513 {
8514 case PROCESSOR_ULTRASPARC:
8515 if (GET_MODE (x) == SFmode)
8516 return COSTS_N_INSNS (13);
8517 else
8518 return COSTS_N_INSNS (23);
8519
8520 case PROCESSOR_ULTRASPARC3:
8521 if (GET_MODE (x) == SFmode)
8522 return COSTS_N_INSNS (17);
8523 else
8524 return COSTS_N_INSNS (20);
8525
8526 case PROCESSOR_SUPERSPARC:
8527 if (GET_MODE (x) == SFmode)
8528 return COSTS_N_INSNS (6);
8529 else
8530 return COSTS_N_INSNS (9);
8531
8532 case PROCESSOR_HYPERSPARC:
8533 case PROCESSOR_SPARCLITE86X:
8534 if (GET_MODE (x) == SFmode)
8535 return COSTS_N_INSNS (8);
8536 else
8537 return COSTS_N_INSNS (12);
8538
8539 default:
8540 return COSTS_N_INSNS (7);
8541 }
8542 }
8543
8544 if (sparc_cpu == PROCESSOR_ULTRASPARC)
8545 return (GET_MODE (x) == DImode ?
8546 COSTS_N_INSNS (68) : COSTS_N_INSNS (37));
8547 if (sparc_cpu == PROCESSOR_ULTRASPARC3)
8548 return (GET_MODE (x) == DImode ?
8549 COSTS_N_INSNS (71) : COSTS_N_INSNS (40));
8550 return COSTS_N_INSNS (25);
8551
8552 case IF_THEN_ELSE:
8553 /* Conditional moves. */
8554 switch (sparc_cpu)
8555 {
8556 case PROCESSOR_ULTRASPARC:
8557 return COSTS_N_INSNS (2);
8558
8559 case PROCESSOR_ULTRASPARC3:
8560 if (FLOAT_MODE_P (GET_MODE (x)))
8561 return COSTS_N_INSNS (3);
8562 else
8563 return COSTS_N_INSNS (2);
8564
8565 default:
8566 return COSTS_N_INSNS (1);
8567 }
8568
8569 case MEM:
8570 /* If outer-code is SIGN/ZERO extension we have to subtract
8571 out COSTS_N_INSNS (1) from whatever we return in determining
8572 the cost. */
8573 switch (sparc_cpu)
8574 {
8575 case PROCESSOR_ULTRASPARC:
8576 if (outer_code == ZERO_EXTEND)
8577 return COSTS_N_INSNS (1);
8578 else
8579 return COSTS_N_INSNS (2);
8580
8581 case PROCESSOR_ULTRASPARC3:
8582 if (outer_code == ZERO_EXTEND)
8583 {
8584 if (GET_MODE (x) == QImode
8585 || GET_MODE (x) == HImode
8586 || outer_code == SIGN_EXTEND)
8587 return COSTS_N_INSNS (2);
8588 else
8589 return COSTS_N_INSNS (1);
8590 }
8591 else
8592 {
8593 /* This handles sign extension (3 cycles)
8594 and everything else (2 cycles). */
8595 return COSTS_N_INSNS (2);
8596 }
8597
8598 case PROCESSOR_SUPERSPARC:
8599 if (FLOAT_MODE_P (GET_MODE (x))
8600 || outer_code == ZERO_EXTEND
8601 || outer_code == SIGN_EXTEND)
8602 return COSTS_N_INSNS (0);
8603 else
8604 return COSTS_N_INSNS (1);
8605
8606 case PROCESSOR_TSC701:
8607 if (outer_code == ZERO_EXTEND
8608 || outer_code == SIGN_EXTEND)
8609 return COSTS_N_INSNS (2);
8610 else
8611 return COSTS_N_INSNS (3);
8612
8613 case PROCESSOR_CYPRESS:
8614 if (outer_code == ZERO_EXTEND
8615 || outer_code == SIGN_EXTEND)
8616 return COSTS_N_INSNS (1);
8617 else
8618 return COSTS_N_INSNS (2);
8619
8620 case PROCESSOR_HYPERSPARC:
8621 case PROCESSOR_SPARCLITE86X:
8622 default:
8623 if (outer_code == ZERO_EXTEND
8624 || outer_code == SIGN_EXTEND)
8625 return COSTS_N_INSNS (0);
8626 else
8627 return COSTS_N_INSNS (1);
8628 }
8629
8630 case CONST_INT:
8631 if (INTVAL (x) < 0x1000 && INTVAL (x) >= -0x1000)
8632 return 0;
8633
8634 /* fallthru */
8635 case HIGH:
8636 return 2;
8637
8638 case CONST:
8639 case LABEL_REF:
8640 case SYMBOL_REF:
8641 return 4;
8642
8643 case CONST_DOUBLE:
8644 if (GET_MODE (x) == DImode)
8645 if ((XINT (x, 3) == 0
8646 && (unsigned) XINT (x, 2) < 0x1000)
8647 || (XINT (x, 3) == -1
8648 && XINT (x, 2) < 0
8649 && XINT (x, 2) >= -0x1000))
8650 return 0;
8651 return 8;
8652
8653 default:
8654 abort();
8655 };
8656 }
8657
8658 /* If we are referencing a function make the SYMBOL_REF special. In
8659 the Embedded Medium/Anywhere code model, %g4 points to the data
8660 segment so we must not add it to function addresses. */
8661
8662 static void
sparc_encode_section_info(decl,first)8663 sparc_encode_section_info (decl, first)
8664 tree decl;
8665 int first ATTRIBUTE_UNUSED;
8666 {
8667 if (TARGET_CM_EMBMEDANY && TREE_CODE (decl) == FUNCTION_DECL)
8668 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
8669 }
8670
8671 /* Output the assembler code for a thunk function. THUNK_DECL is the
8672 declaration for the thunk function itself, FUNCTION is the decl for
8673 the target function. DELTA is an immediate constant offset to be
8674 added to THIS. If VCALL_OFFSET is nonzero, the word at address
8675 (*THIS + VCALL_OFFSET) should be additionally added to THIS. */
8676
8677 static void
sparc_output_mi_thunk(file,thunk_fndecl,delta,vcall_offset,function)8678 sparc_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function)
8679 FILE *file;
8680 tree thunk_fndecl ATTRIBUTE_UNUSED;
8681 HOST_WIDE_INT delta;
8682 HOST_WIDE_INT vcall_offset;
8683 tree function;
8684 {
8685 rtx this, insn, funexp;
8686
8687 reload_completed = 1;
8688 no_new_pseudos = 1;
8689 current_function_uses_only_leaf_regs = 1;
8690
8691 emit_note (NULL, NOTE_INSN_PROLOGUE_END);
8692
8693 /* Find the "this" pointer. Normally in %o0, but in ARCH64 if the function
8694 returns a structure, the structure return pointer is there instead. */
8695 if (TARGET_ARCH64 && aggregate_value_p (TREE_TYPE (TREE_TYPE (function))))
8696 this = gen_rtx_REG (Pmode, SPARC_INCOMING_INT_ARG_FIRST + 1);
8697 else
8698 this = gen_rtx_REG (Pmode, SPARC_INCOMING_INT_ARG_FIRST);
8699
8700 /* Add DELTA. When possible use a plain add, otherwise load it into
8701 a register first. */
8702 if (delta)
8703 {
8704 rtx delta_rtx = GEN_INT (delta);
8705
8706 if (! SPARC_SIMM13_P (delta))
8707 {
8708 rtx scratch = gen_rtx_REG (Pmode, 1);
8709 emit_move_insn (scratch, delta_rtx);
8710 delta_rtx = scratch;
8711 }
8712
8713 /* THIS += DELTA. */
8714 emit_insn (gen_add2_insn (this, delta_rtx));
8715 }
8716
8717 /* Add the word at address (*THIS + VCALL_OFFSET). */
8718 if (vcall_offset)
8719 {
8720 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
8721 rtx scratch = gen_rtx_REG (Pmode, 1);
8722
8723 if (vcall_offset >= 0)
8724 abort ();
8725
8726 /* SCRATCH = *THIS. */
8727 emit_move_insn (scratch, gen_rtx_MEM (Pmode, this));
8728
8729 /* Prepare for adding VCALL_OFFSET. The difficulty is that we
8730 may not have any available scratch register at this point. */
8731 if (SPARC_SIMM13_P (vcall_offset))
8732 ;
8733 /* This is the case if ARCH64 (unless -ffixed-g5 is passed). */
8734 else if (! fixed_regs[5]
8735 /* The below sequence is made up of at least 2 insns,
8736 while the default method may need only one. */
8737 && vcall_offset < -8192)
8738 {
8739 rtx scratch2 = gen_rtx_REG (Pmode, 5);
8740 emit_move_insn (scratch2, vcall_offset_rtx);
8741 vcall_offset_rtx = scratch2;
8742 }
8743 else
8744 {
8745 rtx increment = GEN_INT (-4096);
8746
8747 /* VCALL_OFFSET is a negative number whose typical range can be
8748 estimated as -32768..0 in 32-bit mode. In almost all cases
8749 it is therefore cheaper to emit multiple add insns than
8750 spilling and loading the constant into a register (at least
8751 6 insns). */
8752 while (! SPARC_SIMM13_P (vcall_offset))
8753 {
8754 emit_insn (gen_add2_insn (scratch, increment));
8755 vcall_offset += 4096;
8756 }
8757 vcall_offset_rtx = GEN_INT (vcall_offset); /* cannot be 0 */
8758 }
8759
8760 /* SCRATCH = *(*THIS + VCALL_OFFSET). */
8761 emit_move_insn (scratch, gen_rtx_MEM (Pmode,
8762 gen_rtx_PLUS (Pmode,
8763 scratch,
8764 vcall_offset_rtx)));
8765
8766 /* THIS += *(*THIS + VCALL_OFFSET). */
8767 emit_insn (gen_add2_insn (this, scratch));
8768 }
8769
8770 /* Generate a tail call to the target function. */
8771 if (! TREE_USED (function))
8772 {
8773 assemble_external (function);
8774 TREE_USED (function) = 1;
8775 }
8776 funexp = XEXP (DECL_RTL (function), 0);
8777 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
8778 insn = emit_call_insn (gen_sibcall (funexp));
8779 SIBLING_CALL_P (insn) = 1;
8780 emit_barrier ();
8781
8782 /* Run just enough of rest_of_compilation to get the insns emitted.
8783 There's not really enough bulk here to make other passes such as
8784 instruction scheduling worth while. Note that use_thunk calls
8785 assemble_start_function and assemble_end_function. */
8786 insn = get_insns ();
8787 shorten_branches (insn);
8788 final_start_function (insn, file, 1);
8789 final (insn, file, 1, 0);
8790 final_end_function ();
8791
8792 reload_completed = 0;
8793 no_new_pseudos = 0;
8794 }
8795
8796 /* Return true if sparc_output_mi_thunk would be able to output the
8797 assembler code for the thunk function specified by the arguments
8798 it is passed, and false otherwise. */
8799 static bool
sparc_can_output_mi_thunk(thunk_fndecl,delta,vcall_offset,function)8800 sparc_can_output_mi_thunk (thunk_fndecl, delta, vcall_offset, function)
8801 tree thunk_fndecl ATTRIBUTE_UNUSED;
8802 HOST_WIDE_INT delta ATTRIBUTE_UNUSED;
8803 HOST_WIDE_INT vcall_offset;
8804 tree function ATTRIBUTE_UNUSED;
8805 {
8806 /* Bound the loop used in the default method above. */
8807 return (vcall_offset >= -32768 || ! fixed_regs[5]);
8808 }
8809
8810 #include "gt-sparc.h"
8811