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