OSDN Git Service

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