OSDN Git Service

* pa-protos.h (prefetch_operand): Delete.
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / pa.c
1 /* Subroutines for insn-output.c for HPPA.
2    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3    2002, 2003, 2004 Free Software Foundation, Inc.
4    Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-attr.h"
34 #include "flags.h"
35 #include "tree.h"
36 #include "output.h"
37 #include "except.h"
38 #include "expr.h"
39 #include "optabs.h"
40 #include "reload.h"
41 #include "integrate.h"
42 #include "function.h"
43 #include "toplev.h"
44 #include "ggc.h"
45 #include "recog.h"
46 #include "predict.h"
47 #include "tm_p.h"
48 #include "target.h"
49 #include "target-def.h"
50
51 /* Return nonzero if there is a bypass for the output of 
52    OUT_INSN and the fp store IN_INSN.  */
53 int
54 hppa_fpstore_bypass_p (rtx out_insn, rtx in_insn)
55 {
56   enum machine_mode store_mode;
57   enum machine_mode other_mode;
58   rtx set;
59
60   if (recog_memoized (in_insn) < 0
61       || get_attr_type (in_insn) != TYPE_FPSTORE
62       || recog_memoized (out_insn) < 0)
63     return 0;
64
65   store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
66
67   set = single_set (out_insn);
68   if (!set)
69     return 0;
70
71   other_mode = GET_MODE (SET_SRC (set));
72
73   return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
74 }
75   
76
77 #ifndef DO_FRAME_NOTES
78 #ifdef INCOMING_RETURN_ADDR_RTX
79 #define DO_FRAME_NOTES 1
80 #else
81 #define DO_FRAME_NOTES 0
82 #endif
83 #endif
84
85 static void copy_reg_pointer (rtx, rtx);
86 static void fix_range (const char *);
87 static int hppa_address_cost (rtx);
88 static bool hppa_rtx_costs (rtx, int, int, int *);
89 static inline rtx force_mode (enum machine_mode, rtx);
90 static void pa_reorg (void);
91 static void pa_combine_instructions (void);
92 static int pa_can_combine_p (rtx, rtx, rtx, int, rtx, rtx, rtx);
93 static int forward_branch_p (rtx);
94 static int shadd_constant_p (int);
95 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
96 static int compute_movmem_length (rtx);
97 static int compute_clrmem_length (rtx);
98 static bool pa_assemble_integer (rtx, unsigned int, int);
99 static void remove_useless_addtr_insns (int);
100 static void store_reg (int, HOST_WIDE_INT, int);
101 static void store_reg_modify (int, int, HOST_WIDE_INT);
102 static void load_reg (int, HOST_WIDE_INT, int);
103 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
104 static void pa_output_function_prologue (FILE *, HOST_WIDE_INT);
105 static void update_total_code_bytes (int);
106 static void pa_output_function_epilogue (FILE *, HOST_WIDE_INT);
107 static int pa_adjust_cost (rtx, rtx, rtx, int);
108 static int pa_adjust_priority (rtx, int);
109 static int pa_issue_rate (void);
110 static void pa_select_section (tree, int, unsigned HOST_WIDE_INT)
111      ATTRIBUTE_UNUSED;
112 static void pa_encode_section_info (tree, rtx, int);
113 static const char *pa_strip_name_encoding (const char *);
114 static bool pa_function_ok_for_sibcall (tree, tree);
115 static void pa_globalize_label (FILE *, const char *)
116      ATTRIBUTE_UNUSED;
117 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
118                                     HOST_WIDE_INT, tree);
119 #if !defined(USE_COLLECT2)
120 static void pa_asm_out_constructor (rtx, int);
121 static void pa_asm_out_destructor (rtx, int);
122 #endif
123 static void pa_init_builtins (void);
124 static rtx hppa_builtin_saveregs (void);
125 static tree hppa_gimplify_va_arg_expr (tree, tree, tree *, tree *);
126 static void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
127 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
128 static struct deferred_plabel *get_plabel (const char *)
129      ATTRIBUTE_UNUSED;
130 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
131 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
132 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
133 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
134 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
135 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
136 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
137 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
138 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
139 static void output_deferred_plabels (void);
140 #ifdef HPUX_LONG_DOUBLE_LIBRARY
141 static void pa_hpux_init_libfuncs (void);
142 #endif
143 static rtx pa_struct_value_rtx (tree, int);
144 static bool pa_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
145                                   tree, bool);
146 static int pa_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
147                                  tree, bool);
148 static struct machine_function * pa_init_machine_status (void);
149
150
151 /* Save the operands last given to a compare for use when we
152    generate a scc or bcc insn.  */
153 rtx hppa_compare_op0, hppa_compare_op1;
154 enum cmp_type hppa_branch_type;
155
156 /* Which architecture we are generating code for.  */
157 enum architecture_type pa_arch;
158
159 /* String to hold which architecture we are generating code for.  */
160 const char *pa_arch_string;
161
162 /* String used with the -mfixed-range= option.  */
163 const char *pa_fixed_range_string;
164
165 /* Which cpu we are scheduling for.  */
166 enum processor_type pa_cpu;
167
168 /* String to hold which cpu we are scheduling for.  */
169 const char *pa_cpu_string;
170
171 /* String used with the -munix= option.  */
172 const char *pa_unix_string;
173
174 /* The UNIX standard to use for predefines and linking.  */
175 int flag_pa_unix;
176
177 /* Counts for the number of callee-saved general and floating point
178    registers which were saved by the current function's prologue.  */
179 static int gr_saved, fr_saved;
180
181 static rtx find_addr_reg (rtx);
182
183 /* Keep track of the number of bytes we have output in the CODE subspace
184    during this compilation so we'll know when to emit inline long-calls.  */
185 unsigned long total_code_bytes;
186
187 /* The last address of the previous function plus the number of bytes in
188    associated thunks that have been output.  This is used to determine if
189    a thunk can use an IA-relative branch to reach its target function.  */
190 static int last_address;
191
192 /* Variables to handle plabels that we discover are necessary at assembly
193    output time.  They are output after the current function.  */
194 struct deferred_plabel GTY(())
195 {
196   rtx internal_label;
197   const char *name;
198 };
199 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
200   deferred_plabels;
201 static size_t n_deferred_plabels = 0;
202
203 \f
204 /* Initialize the GCC target structure.  */
205
206 #undef TARGET_ASM_ALIGNED_HI_OP
207 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
208 #undef TARGET_ASM_ALIGNED_SI_OP
209 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
210 #undef TARGET_ASM_ALIGNED_DI_OP
211 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
212 #undef TARGET_ASM_UNALIGNED_HI_OP
213 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
214 #undef TARGET_ASM_UNALIGNED_SI_OP
215 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
216 #undef TARGET_ASM_UNALIGNED_DI_OP
217 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
218 #undef TARGET_ASM_INTEGER
219 #define TARGET_ASM_INTEGER pa_assemble_integer
220
221 #undef TARGET_ASM_FUNCTION_PROLOGUE
222 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
223 #undef TARGET_ASM_FUNCTION_EPILOGUE
224 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
225
226 #undef TARGET_SCHED_ADJUST_COST
227 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
228 #undef TARGET_SCHED_ADJUST_PRIORITY
229 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
230 #undef TARGET_SCHED_ISSUE_RATE
231 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
232
233 #undef TARGET_ENCODE_SECTION_INFO
234 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
235 #undef TARGET_STRIP_NAME_ENCODING
236 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
237
238 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
239 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
240
241 #undef TARGET_ASM_OUTPUT_MI_THUNK
242 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
243 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
244 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
245
246 #undef TARGET_ASM_FILE_END
247 #define TARGET_ASM_FILE_END output_deferred_plabels
248
249 #if !defined(USE_COLLECT2)
250 #undef TARGET_ASM_CONSTRUCTOR
251 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
252 #undef TARGET_ASM_DESTRUCTOR
253 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
254 #endif
255
256 #undef TARGET_INIT_BUILTINS
257 #define TARGET_INIT_BUILTINS pa_init_builtins
258
259 #undef TARGET_RTX_COSTS
260 #define TARGET_RTX_COSTS hppa_rtx_costs
261 #undef TARGET_ADDRESS_COST
262 #define TARGET_ADDRESS_COST hppa_address_cost
263
264 #undef TARGET_MACHINE_DEPENDENT_REORG
265 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
266
267 #ifdef HPUX_LONG_DOUBLE_LIBRARY
268 #undef TARGET_INIT_LIBFUNCS
269 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
270 #endif
271
272 #undef TARGET_PROMOTE_FUNCTION_RETURN
273 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
274 #undef TARGET_PROMOTE_PROTOTYPES
275 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
276
277 #undef TARGET_STRUCT_VALUE_RTX
278 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
279 #undef TARGET_RETURN_IN_MEMORY
280 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
281 #undef TARGET_MUST_PASS_IN_STACK
282 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
283 #undef TARGET_PASS_BY_REFERENCE
284 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
285 #undef TARGET_CALLEE_COPIES
286 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
287 #undef TARGET_ARG_PARTIAL_BYTES
288 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
289
290 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
291 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
292 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
293 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
294
295 struct gcc_target targetm = TARGET_INITIALIZER;
296 \f
297 /* Parse the -mfixed-range= option string.  */
298
299 static void
300 fix_range (const char *const_str)
301 {
302   int i, first, last;
303   char *str, *dash, *comma;
304
305   /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
306      REG2 are either register names or register numbers.  The effect
307      of this option is to mark the registers in the range from REG1 to
308      REG2 as ``fixed'' so they won't be used by the compiler.  This is
309      used, e.g., to ensure that kernel mode code doesn't use f32-f127.  */
310
311   i = strlen (const_str);
312   str = (char *) alloca (i + 1);
313   memcpy (str, const_str, i + 1);
314
315   while (1)
316     {
317       dash = strchr (str, '-');
318       if (!dash)
319         {
320           warning ("value of -mfixed-range must have form REG1-REG2");
321           return;
322         }
323       *dash = '\0';
324
325       comma = strchr (dash + 1, ',');
326       if (comma)
327         *comma = '\0';
328
329       first = decode_reg_name (str);
330       if (first < 0)
331         {
332           warning ("unknown register name: %s", str);
333           return;
334         }
335
336       last = decode_reg_name (dash + 1);
337       if (last < 0)
338         {
339           warning ("unknown register name: %s", dash + 1);
340           return;
341         }
342
343       *dash = '-';
344
345       if (first > last)
346         {
347           warning ("%s-%s is an empty range", str, dash + 1);
348           return;
349         }
350
351       for (i = first; i <= last; ++i)
352         fixed_regs[i] = call_used_regs[i] = 1;
353
354       if (!comma)
355         break;
356
357       *comma = ',';
358       str = comma + 1;
359     }
360
361   /* Check if all floating point registers have been fixed.  */
362   for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
363     if (!fixed_regs[i])
364       break;
365
366   if (i > FP_REG_LAST)
367     target_flags |= MASK_DISABLE_FPREGS;
368 }
369
370 void
371 override_options (void)
372 {
373   if (pa_cpu_string == NULL)
374     pa_cpu_string = TARGET_SCHED_DEFAULT;
375
376   if (! strcmp (pa_cpu_string, "8000"))
377     {
378       pa_cpu_string = "8000";
379       pa_cpu = PROCESSOR_8000;
380     }
381   else if (! strcmp (pa_cpu_string, "7100"))
382     {
383       pa_cpu_string = "7100";
384       pa_cpu = PROCESSOR_7100;
385     }
386   else if (! strcmp (pa_cpu_string, "700"))
387     {
388       pa_cpu_string = "700";
389       pa_cpu = PROCESSOR_700;
390     }
391   else if (! strcmp (pa_cpu_string, "7100LC"))
392     {
393       pa_cpu_string = "7100LC";
394       pa_cpu = PROCESSOR_7100LC;
395     }
396   else if (! strcmp (pa_cpu_string, "7200"))
397     {
398       pa_cpu_string = "7200";
399       pa_cpu = PROCESSOR_7200;
400     }
401   else if (! strcmp (pa_cpu_string, "7300"))
402     {
403       pa_cpu_string = "7300";
404       pa_cpu = PROCESSOR_7300;
405     }
406   else
407     {
408       warning ("unknown -mschedule= option (%s).\nValid options are 700, 7100, 7100LC, 7200, 7300, and 8000\n", pa_cpu_string);
409     }
410
411   /* Set the instruction architecture.  */
412   if (pa_arch_string && ! strcmp (pa_arch_string, "1.0"))
413     {
414       pa_arch_string = "1.0";
415       pa_arch = ARCHITECTURE_10;
416       target_flags &= ~(MASK_PA_11 | MASK_PA_20);
417     }
418   else if (pa_arch_string && ! strcmp (pa_arch_string, "1.1"))
419     {
420       pa_arch_string = "1.1";
421       pa_arch = ARCHITECTURE_11;
422       target_flags &= ~MASK_PA_20;
423       target_flags |= MASK_PA_11;
424     }
425   else if (pa_arch_string && ! strcmp (pa_arch_string, "2.0"))
426     {
427       pa_arch_string = "2.0";
428       pa_arch = ARCHITECTURE_20;
429       target_flags |= MASK_PA_11 | MASK_PA_20;
430     }
431   else if (pa_arch_string)
432     {
433       warning ("unknown -march= option (%s).\nValid options are 1.0, 1.1, and 2.0\n", pa_arch_string);
434     }
435
436   if (TARGET_HPUX)
437     {
438       /* Set the default UNIX standard for HP-UX.  This affects the
439          predefines and startfiles used for the target.  */
440       if (pa_unix_string == NULL)
441         pa_unix_string
442           = TARGET_HPUX_11_11 ? "98" : (TARGET_HPUX_10_10 ? "95" : "93");
443
444       if (!strcmp (pa_unix_string, "93"))
445         flag_pa_unix = 1993;
446       else if (!strcmp (pa_unix_string, "95"))
447         flag_pa_unix = 1995;
448       else if (TARGET_HPUX_11_11)
449         {
450           if (!strcmp (pa_unix_string, "98"))
451             flag_pa_unix = 1998;
452           else
453             warning ("unknown -munix= option (%s).\n"
454                      "Valid options are 93, 95 and 98.\n",
455                      pa_unix_string);
456         }
457       else if (TARGET_HPUX_10_10)
458         warning ("unknown -munix= option (%s)."
459                  "\nValid options are 93 and 95.\n",
460                  pa_unix_string);
461       else
462         warning ("unknown -munix= option (%s).\nValid option is 93.\n",
463                  pa_unix_string);
464     }
465
466   if (pa_fixed_range_string)
467     fix_range (pa_fixed_range_string);
468
469   /* Unconditional branches in the delay slot are not compatible with dwarf2
470      call frame information.  There is no benefit in using this optimization
471      on PA8000 and later processors.  */
472   if (pa_cpu >= PROCESSOR_8000
473       || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
474       || flag_unwind_tables)
475     target_flags &= ~MASK_JUMP_IN_DELAY;
476
477   if (flag_pic && TARGET_PORTABLE_RUNTIME)
478     {
479       warning ("PIC code generation is not supported in the portable runtime model\n");
480     }
481
482   if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
483    {
484       warning ("PIC code generation is not compatible with fast indirect calls\n");
485    }
486
487   if (! TARGET_GAS && write_symbols != NO_DEBUG)
488     {
489       warning ("-g is only supported when using GAS on this processor,");
490       warning ("-g option disabled");
491       write_symbols = NO_DEBUG;
492     }
493
494   /* We only support the "big PIC" model now.  And we always generate PIC
495      code when in 64bit mode.  */
496   if (flag_pic == 1 || TARGET_64BIT)
497     flag_pic = 2;
498
499   /* We can't guarantee that .dword is available for 32-bit targets.  */
500   if (UNITS_PER_WORD == 4)
501     targetm.asm_out.aligned_op.di = NULL;
502
503   /* The unaligned ops are only available when using GAS.  */
504   if (!TARGET_GAS)
505     {
506       targetm.asm_out.unaligned_op.hi = NULL;
507       targetm.asm_out.unaligned_op.si = NULL;
508       targetm.asm_out.unaligned_op.di = NULL;
509     }
510
511   init_machine_status = pa_init_machine_status;
512 }
513
514 static void
515 pa_init_builtins (void)
516 {
517 #ifdef DONT_HAVE_FPUTC_UNLOCKED
518   built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
519   implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
520 #endif
521 }
522
523 /* Function to init struct machine_function.
524    This will be called, via a pointer variable,
525    from push_function_context.  */
526
527 static struct machine_function *
528 pa_init_machine_status (void)
529 {
530   return ggc_alloc_cleared (sizeof (machine_function));
531 }
532
533 /* If FROM is a probable pointer register, mark TO as a probable
534    pointer register with the same pointer alignment as FROM.  */
535
536 static void
537 copy_reg_pointer (rtx to, rtx from)
538 {
539   if (REG_POINTER (from))
540     mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
541 }
542
543 /* Return nonzero only if OP is a register of mode MODE,
544    or CONST0_RTX.  */
545 int
546 reg_or_0_operand (rtx op, enum machine_mode mode)
547 {
548   return (op == CONST0_RTX (mode) || register_operand (op, mode));
549 }
550
551 /* Return nonzero if OP is suitable for use in a call to a named
552    function.
553
554    For 2.5 try to eliminate either call_operand_address or
555    function_label_operand, they perform very similar functions.  */
556 int
557 call_operand_address (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
558 {
559   return (GET_MODE (op) == word_mode
560           && CONSTANT_P (op) && ! TARGET_PORTABLE_RUNTIME);
561 }
562
563 /* Return 1 if X contains a symbolic expression.  We know these
564    expressions will have one of a few well defined forms, so
565    we need only check those forms.  */
566 int
567 symbolic_expression_p (rtx x)
568 {
569
570   /* Strip off any HIGH.  */
571   if (GET_CODE (x) == HIGH)
572     x = XEXP (x, 0);
573
574   return (symbolic_operand (x, VOIDmode));
575 }
576
577 int
578 symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
579 {
580   switch (GET_CODE (op))
581     {
582     case SYMBOL_REF:
583     case LABEL_REF:
584       return 1;
585     case CONST:
586       op = XEXP (op, 0);
587       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
588                || GET_CODE (XEXP (op, 0)) == LABEL_REF)
589               && GET_CODE (XEXP (op, 1)) == CONST_INT);
590     default:
591       return 0;
592     }
593 }
594
595 /* Return truth value of statement that OP is a symbolic memory
596    operand of mode MODE.  */
597
598 int
599 symbolic_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
600 {
601   if (GET_CODE (op) == SUBREG)
602     op = SUBREG_REG (op);
603   if (GET_CODE (op) != MEM)
604     return 0;
605   op = XEXP (op, 0);
606   return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
607           || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
608 }
609
610 /* Return 1 if the operand is either a register, zero, or a memory operand
611    that is not symbolic.  */
612
613 int
614 reg_or_0_or_nonsymb_mem_operand (rtx op, enum machine_mode mode)
615 {
616   if (register_operand (op, mode))
617     return 1;
618
619   if (op == CONST0_RTX (mode))
620     return 1;
621
622   if (GET_CODE (op) == SUBREG)
623     op = SUBREG_REG (op);
624
625   if (GET_CODE (op) != MEM)
626     return 0;
627
628   /* Until problems with management of the REG_POINTER flag are resolved,
629      we need to delay creating move insns with unscaled indexed addresses
630      until CSE is not expected.  */
631   if (!TARGET_NO_SPACE_REGS
632       && !cse_not_expected
633       && GET_CODE (XEXP (op, 0)) == PLUS
634       && REG_P (XEXP (XEXP (op, 0), 0))
635       && REG_P (XEXP (XEXP (op, 0), 1)))
636     return 0;
637
638   return (!symbolic_memory_operand (op, mode)
639           && memory_address_p (mode, XEXP (op, 0)));
640 }
641
642 /* Return 1 if the operand is a register operand or a non-symbolic memory
643    operand after reload.  This predicate is used for branch patterns that
644    internally handle register reloading.  We need to accept non-symbolic
645    memory operands after reload to ensure that the pattern is still valid
646    if reload didn't find a hard register for the operand.  */
647
648 int
649 reg_before_reload_operand (rtx op, enum machine_mode mode)
650 {
651   /* Don't accept a SUBREG since it will need a reload.  */
652   if (GET_CODE (op) == SUBREG)
653     return 0;
654
655   if (register_operand (op, mode))
656     return 1;
657
658   if (reload_completed
659       && memory_operand (op, mode)
660       && !symbolic_memory_operand (op, mode))
661     return 1;
662
663   return 0;
664 }
665
666 /* Accept any constant that can be moved in one instruction into a
667    general register.  */
668 int
669 cint_ok_for_move (HOST_WIDE_INT intval)
670 {
671   /* OK if ldo, ldil, or zdepi, can be used.  */
672   return (CONST_OK_FOR_LETTER_P (intval, 'J')
673           || CONST_OK_FOR_LETTER_P (intval, 'N')
674           || CONST_OK_FOR_LETTER_P (intval, 'K'));
675 }
676
677 /* Return 1 iff OP is an indexed memory operand.  */
678 int
679 indexed_memory_operand (rtx op, enum machine_mode mode)
680 {
681   if (GET_MODE (op) != mode)
682     return 0;
683
684   /* Before reload, a (SUBREG (MEM...)) forces reloading into a register.  */
685   if (reload_completed && GET_CODE (op) == SUBREG)
686     op = SUBREG_REG (op);
687
688   if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
689     return 0;
690
691   op = XEXP (op, 0);
692
693   return (memory_address_p (mode, op) && IS_INDEX_ADDR_P (op));
694 }
695
696 /* Accept anything that can be used as a destination operand for a
697    move instruction.  We don't accept indexed memory operands since
698    they are supported only for floating point stores.  */
699 int
700 move_dest_operand (rtx op, enum machine_mode mode)
701 {
702   if (register_operand (op, mode))
703     return 1;
704
705   if (GET_MODE (op) != mode)
706     return 0;
707
708   if (GET_CODE (op) == SUBREG)
709     op = SUBREG_REG (op);
710
711   if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
712     return 0;
713
714   op = XEXP (op, 0);
715
716   return (memory_address_p (mode, op)
717           && !IS_INDEX_ADDR_P (op)
718           && !IS_LO_SUM_DLT_ADDR_P (op));
719 }
720
721 /* Accept anything that can be used as a source operand for a move
722    instruction.  */
723 int
724 move_src_operand (rtx op, enum machine_mode mode)
725 {
726   if (register_operand (op, mode))
727     return 1;
728
729   if (GET_CODE (op) == CONST_INT)
730     return cint_ok_for_move (INTVAL (op));
731
732   if (GET_MODE (op) != mode)
733     return 0;
734
735   if (GET_CODE (op) == SUBREG)
736     op = SUBREG_REG (op);
737
738   if (GET_CODE (op) != MEM)
739     return 0;
740
741   /* Until problems with management of the REG_POINTER flag are resolved,
742      we need to delay creating move insns with unscaled indexed addresses
743      until CSE is not expected.  */
744   if (!TARGET_NO_SPACE_REGS
745       && !cse_not_expected
746       && GET_CODE (XEXP (op, 0)) == PLUS
747       && REG_P (XEXP (XEXP (op, 0), 0))
748       && REG_P (XEXP (XEXP (op, 0), 1)))
749     return 0;
750
751   return memory_address_p (mode, XEXP (op, 0));
752 }
753
754 /* Accept anything that can be used as the source operand for a prefetch
755    instruction with a cache-control completer.  */
756 int
757 prefetch_cc_operand (rtx op, enum machine_mode mode)
758 {
759   if (GET_CODE (op) != MEM)
760     return 0;
761
762   op = XEXP (op, 0);
763
764   /* We must reject virtual registers as we don't allow REG+D.  */
765   if (op == virtual_incoming_args_rtx
766       || op == virtual_stack_vars_rtx
767       || op == virtual_stack_dynamic_rtx
768       || op == virtual_outgoing_args_rtx
769       || op == virtual_cfa_rtx)
770     return 0;
771
772   if (!REG_P (op) && !IS_INDEX_ADDR_P (op))
773     return 0;
774
775   /* Until problems with management of the REG_POINTER flag are resolved,
776      we need to delay creating prefetch insns with unscaled indexed addresses
777      until CSE is not expected.  */
778   if (!TARGET_NO_SPACE_REGS
779       && !cse_not_expected
780       && GET_CODE (op) == PLUS
781       && REG_P (XEXP (op, 0)))
782     return 0;
783
784   return memory_address_p (mode, op);
785 }
786
787 /* Accept anything that can be used as the source operand for a prefetch
788    instruction with no cache-control completer.  */
789 int
790 prefetch_nocc_operand (rtx op, enum machine_mode mode)
791 {
792   if (GET_CODE (op) != MEM)
793     return 0;
794
795   op = XEXP (op, 0);
796
797   /* Until problems with management of the REG_POINTER flag are resolved,
798      we need to delay creating prefetch insns with unscaled indexed addresses
799      until CSE is not expected.  */
800   if (!TARGET_NO_SPACE_REGS
801       && !cse_not_expected
802       && GET_CODE (op) == PLUS
803       && REG_P (XEXP (op, 0))
804       && REG_P (XEXP (op, 1)))
805     return 0;
806
807   return memory_address_p (mode, op);
808 }
809
810 /* Accept REG and any CONST_INT that can be moved in one instruction into a
811    general register.  */
812 int
813 reg_or_cint_move_operand (rtx op, enum machine_mode mode)
814 {
815   if (register_operand (op, mode))
816     return 1;
817
818   return (GET_CODE (op) == CONST_INT && cint_ok_for_move (INTVAL (op)));
819 }
820
821 int
822 pic_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
823 {
824   if (!flag_pic)
825     return 0;
826
827   switch (GET_CODE (op))
828     {
829     case LABEL_REF:
830       return 1;
831     case CONST:
832       op = XEXP (op, 0);
833       return (GET_CODE (XEXP (op, 0)) == LABEL_REF
834               && GET_CODE (XEXP (op, 1)) == CONST_INT);
835     default:
836       return 0;
837     }
838 }
839
840 int
841 fp_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
842 {
843   return reg_renumber && FP_REG_P (op);
844 }
845
846 \f
847
848 /* Return truth value of whether OP can be used as an operand in a
849    three operand arithmetic insn that accepts registers of mode MODE
850    or 14-bit signed integers.  */
851 int
852 arith_operand (rtx op, enum machine_mode mode)
853 {
854   return (register_operand (op, mode)
855           || (GET_CODE (op) == CONST_INT && INT_14_BITS (op)));
856 }
857
858 /* Return truth value of whether OP can be used as an operand in a
859    three operand arithmetic insn that accepts registers of mode MODE
860    or 11-bit signed integers.  */
861 int
862 arith11_operand (rtx op, enum machine_mode mode)
863 {
864   return (register_operand (op, mode)
865           || (GET_CODE (op) == CONST_INT && INT_11_BITS (op)));
866 }
867
868 /* Return truth value of whether OP can be used as an operand in a
869    adddi3 insn.  */
870 int
871 adddi3_operand (rtx op, enum machine_mode mode)
872 {
873   return (register_operand (op, mode)
874           || (GET_CODE (op) == CONST_INT
875               && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
876 }
877
878 /* A constant integer suitable for use in a PRE_MODIFY memory
879    reference.  */
880 int
881 pre_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
882 {
883   return (GET_CODE (op) == CONST_INT
884           && INTVAL (op) >= -0x2000 && INTVAL (op) < 0x10);
885 }
886
887 /* A constant integer suitable for use in a POST_MODIFY memory
888    reference.  */
889 int
890 post_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
891 {
892   return (GET_CODE (op) == CONST_INT
893           && INTVAL (op) < 0x2000 && INTVAL (op) >= -0x10);
894 }
895
896 int
897 arith_double_operand (rtx op, enum machine_mode mode)
898 {
899   return (register_operand (op, mode)
900           || (GET_CODE (op) == CONST_DOUBLE
901               && GET_MODE (op) == mode
902               && VAL_14_BITS_P (CONST_DOUBLE_LOW (op))
903               && ((CONST_DOUBLE_HIGH (op) >= 0)
904                   == ((CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
905 }
906
907 /* Return truth value of whether OP is an integer which fits the
908    range constraining immediate operands in three-address insns, or
909    is an integer register.  */
910
911 int
912 ireg_or_int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
913 {
914   return ((GET_CODE (op) == CONST_INT && INT_5_BITS (op))
915           || (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32));
916 }
917
918 /* Return nonzero if OP is an integer register, else return zero.  */
919 int
920 ireg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
921 {
922   return (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32);
923 }
924
925 /* Return truth value of whether OP is an integer which fits the
926    range constraining immediate operands in three-address insns.  */
927
928 int
929 int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
930 {
931   return (GET_CODE (op) == CONST_INT && INT_5_BITS (op));
932 }
933
934 int
935 uint5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
936 {
937   return (GET_CODE (op) == CONST_INT && INT_U5_BITS (op));
938 }
939
940 int
941 int11_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
942 {
943   return (GET_CODE (op) == CONST_INT && INT_11_BITS (op));
944 }
945
946 int
947 uint32_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
948 {
949 #if HOST_BITS_PER_WIDE_INT > 32
950   /* All allowed constants will fit a CONST_INT.  */
951   return (GET_CODE (op) == CONST_INT
952           && (INTVAL (op) >= 0 && INTVAL (op) < (HOST_WIDE_INT) 1 << 32));
953 #else
954   return (GET_CODE (op) == CONST_INT
955           || (GET_CODE (op) == CONST_DOUBLE
956               && CONST_DOUBLE_HIGH (op) == 0));
957 #endif
958 }
959
960 int
961 arith5_operand (rtx op, enum machine_mode mode)
962 {
963   return register_operand (op, mode) || int5_operand (op, mode);
964 }
965
966 /* True iff zdepi can be used to generate this CONST_INT.
967    zdepi first sign extends a 5 bit signed number to a given field
968    length, then places this field anywhere in a zero.  */
969 int
970 zdepi_cint_p (unsigned HOST_WIDE_INT x)
971 {
972   unsigned HOST_WIDE_INT lsb_mask, t;
973
974   /* This might not be obvious, but it's at least fast.
975      This function is critical; we don't have the time loops would take.  */
976   lsb_mask = x & -x;
977   t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
978   /* Return true iff t is a power of two.  */
979   return ((t & (t - 1)) == 0);
980 }
981
982 /* True iff depi or extru can be used to compute (reg & mask).
983    Accept bit pattern like these:
984    0....01....1
985    1....10....0
986    1..10..01..1  */
987 int
988 and_mask_p (unsigned HOST_WIDE_INT mask)
989 {
990   mask = ~mask;
991   mask += mask & -mask;
992   return (mask & (mask - 1)) == 0;
993 }
994
995 /* True iff depi or extru can be used to compute (reg & OP).  */
996 int
997 and_operand (rtx op, enum machine_mode mode)
998 {
999   return (register_operand (op, mode)
1000           || (GET_CODE (op) == CONST_INT && and_mask_p (INTVAL (op))));
1001 }
1002
1003 /* True iff depi can be used to compute (reg | MASK).  */
1004 int
1005 ior_mask_p (unsigned HOST_WIDE_INT mask)
1006 {
1007   mask += mask & -mask;
1008   return (mask & (mask - 1)) == 0;
1009 }
1010
1011 /* True iff depi can be used to compute (reg | OP).  */
1012 int
1013 ior_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1014 {
1015   return (GET_CODE (op) == CONST_INT && ior_mask_p (INTVAL (op)));
1016 }
1017
1018 int
1019 lhs_lshift_operand (rtx op, enum machine_mode mode)
1020 {
1021   return register_operand (op, mode) || lhs_lshift_cint_operand (op, mode);
1022 }
1023
1024 /* True iff OP is a CONST_INT of the forms 0...0xxxx or 0...01...1xxxx.
1025    Such values can be the left hand side x in (x << r), using the zvdepi
1026    instruction.  */
1027 int
1028 lhs_lshift_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1029 {
1030   unsigned HOST_WIDE_INT x;
1031   if (GET_CODE (op) != CONST_INT)
1032     return 0;
1033   x = INTVAL (op) >> 4;
1034   return (x & (x + 1)) == 0;
1035 }
1036
1037 int
1038 arith32_operand (rtx op, enum machine_mode mode)
1039 {
1040   return register_operand (op, mode) || GET_CODE (op) == CONST_INT;
1041 }
1042
1043 int
1044 pc_or_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1045 {
1046   return (GET_CODE (op) == PC || GET_CODE (op) == LABEL_REF);
1047 }
1048 \f
1049 /* Legitimize PIC addresses.  If the address is already
1050    position-independent, we return ORIG.  Newly generated
1051    position-independent addresses go to REG.  If we need more
1052    than one register, we lose.  */
1053
1054 rtx
1055 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
1056 {
1057   rtx pic_ref = orig;
1058
1059   /* Labels need special handling.  */
1060   if (pic_label_operand (orig, mode))
1061     {
1062       /* We do not want to go through the movXX expanders here since that
1063          would create recursion.
1064
1065          Nor do we really want to call a generator for a named pattern
1066          since that requires multiple patterns if we want to support
1067          multiple word sizes.
1068
1069          So instead we just emit the raw set, which avoids the movXX
1070          expanders completely.  */
1071       mark_reg_pointer (reg, BITS_PER_UNIT);
1072       emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
1073       current_function_uses_pic_offset_table = 1;
1074       return reg;
1075     }
1076   if (GET_CODE (orig) == SYMBOL_REF)
1077     {
1078       rtx insn, tmp_reg;
1079
1080       if (reg == 0)
1081         abort ();
1082
1083       /* Before reload, allocate a temporary register for the intermediate
1084          result.  This allows the sequence to be deleted when the final
1085          result is unused and the insns are trivially dead.  */
1086       tmp_reg = ((reload_in_progress || reload_completed)
1087                  ? reg : gen_reg_rtx (Pmode));
1088
1089       emit_move_insn (tmp_reg,
1090                       gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
1091                                     gen_rtx_HIGH (word_mode, orig)));
1092       pic_ref
1093         = gen_const_mem (Pmode,
1094                          gen_rtx_LO_SUM (Pmode, tmp_reg,
1095                                          gen_rtx_UNSPEC (Pmode,
1096                                                          gen_rtvec (1, orig),
1097                                                          UNSPEC_DLTIND14R)));
1098
1099       current_function_uses_pic_offset_table = 1;
1100       mark_reg_pointer (reg, BITS_PER_UNIT);
1101       insn = emit_move_insn (reg, pic_ref);
1102
1103       /* Put a REG_EQUAL note on this insn, so that it can be optimized.  */
1104       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig, REG_NOTES (insn));
1105
1106       return reg;
1107     }
1108   else if (GET_CODE (orig) == CONST)
1109     {
1110       rtx base;
1111
1112       if (GET_CODE (XEXP (orig, 0)) == PLUS
1113           && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1114         return orig;
1115
1116       if (reg == 0)
1117         abort ();
1118
1119       if (GET_CODE (XEXP (orig, 0)) == PLUS)
1120         {
1121           base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1122           orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1123                                          base == reg ? 0 : reg);
1124         }
1125       else
1126         abort ();
1127
1128       if (GET_CODE (orig) == CONST_INT)
1129         {
1130           if (INT_14_BITS (orig))
1131             return plus_constant (base, INTVAL (orig));
1132           orig = force_reg (Pmode, orig);
1133         }
1134       pic_ref = gen_rtx_PLUS (Pmode, base, orig);
1135       /* Likewise, should we set special REG_NOTEs here?  */
1136     }
1137
1138   return pic_ref;
1139 }
1140
1141 /* Try machine-dependent ways of modifying an illegitimate address
1142    to be legitimate.  If we find one, return the new, valid address.
1143    This macro is used in only one place: `memory_address' in explow.c.
1144
1145    OLDX is the address as it was before break_out_memory_refs was called.
1146    In some cases it is useful to look at this to decide what needs to be done.
1147
1148    MODE and WIN are passed so that this macro can use
1149    GO_IF_LEGITIMATE_ADDRESS.
1150
1151    It is always safe for this macro to do nothing.  It exists to recognize
1152    opportunities to optimize the output.
1153
1154    For the PA, transform:
1155
1156         memory(X + <large int>)
1157
1158    into:
1159
1160         if (<large int> & mask) >= 16
1161           Y = (<large int> & ~mask) + mask + 1  Round up.
1162         else
1163           Y = (<large int> & ~mask)             Round down.
1164         Z = X + Y
1165         memory (Z + (<large int> - Y));
1166
1167    This is for CSE to find several similar references, and only use one Z.
1168
1169    X can either be a SYMBOL_REF or REG, but because combine cannot
1170    perform a 4->2 combination we do nothing for SYMBOL_REF + D where
1171    D will not fit in 14 bits.
1172
1173    MODE_FLOAT references allow displacements which fit in 5 bits, so use
1174    0x1f as the mask.
1175
1176    MODE_INT references allow displacements which fit in 14 bits, so use
1177    0x3fff as the mask.
1178
1179    This relies on the fact that most mode MODE_FLOAT references will use FP
1180    registers and most mode MODE_INT references will use integer registers.
1181    (In the rare case of an FP register used in an integer MODE, we depend
1182    on secondary reloads to clean things up.)
1183
1184
1185    It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
1186    manner if Y is 2, 4, or 8.  (allows more shadd insns and shifted indexed
1187    addressing modes to be used).
1188
1189    Put X and Z into registers.  Then put the entire expression into
1190    a register.  */
1191
1192 rtx
1193 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1194                          enum machine_mode mode)
1195 {
1196   rtx orig = x;
1197
1198   /* We need to canonicalize the order of operands in unscaled indexed
1199      addresses since the code that checks if an address is valid doesn't
1200      always try both orders.  */
1201   if (!TARGET_NO_SPACE_REGS
1202       && GET_CODE (x) == PLUS
1203       && GET_MODE (x) == Pmode
1204       && REG_P (XEXP (x, 0))
1205       && REG_P (XEXP (x, 1))
1206       && REG_POINTER (XEXP (x, 0))
1207       && !REG_POINTER (XEXP (x, 1)))
1208     return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
1209
1210   if (flag_pic)
1211     return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
1212
1213   /* Strip off CONST.  */
1214   if (GET_CODE (x) == CONST)
1215     x = XEXP (x, 0);
1216
1217   /* Special case.  Get the SYMBOL_REF into a register and use indexing.
1218      That should always be safe.  */
1219   if (GET_CODE (x) == PLUS
1220       && GET_CODE (XEXP (x, 0)) == REG
1221       && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
1222     {
1223       rtx reg = force_reg (Pmode, XEXP (x, 1));
1224       return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
1225     }
1226
1227   /* Note we must reject symbols which represent function addresses
1228      since the assembler/linker can't handle arithmetic on plabels.  */
1229   if (GET_CODE (x) == PLUS
1230       && GET_CODE (XEXP (x, 1)) == CONST_INT
1231       && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1232            && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
1233           || GET_CODE (XEXP (x, 0)) == REG))
1234     {
1235       rtx int_part, ptr_reg;
1236       int newoffset;
1237       int offset = INTVAL (XEXP (x, 1));
1238       int mask;
1239
1240       mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
1241               ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
1242
1243       /* Choose which way to round the offset.  Round up if we
1244          are >= halfway to the next boundary.  */
1245       if ((offset & mask) >= ((mask + 1) / 2))
1246         newoffset = (offset & ~ mask) + mask + 1;
1247       else
1248         newoffset = (offset & ~ mask);
1249
1250       /* If the newoffset will not fit in 14 bits (ldo), then
1251          handling this would take 4 or 5 instructions (2 to load
1252          the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
1253          add the new offset and the SYMBOL_REF.)  Combine can
1254          not handle 4->2 or 5->2 combinations, so do not create
1255          them.  */
1256       if (! VAL_14_BITS_P (newoffset)
1257           && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
1258         {
1259           rtx const_part = plus_constant (XEXP (x, 0), newoffset);
1260           rtx tmp_reg
1261             = force_reg (Pmode,
1262                          gen_rtx_HIGH (Pmode, const_part));
1263           ptr_reg
1264             = force_reg (Pmode,
1265                          gen_rtx_LO_SUM (Pmode,
1266                                          tmp_reg, const_part));
1267         }
1268       else
1269         {
1270           if (! VAL_14_BITS_P (newoffset))
1271             int_part = force_reg (Pmode, GEN_INT (newoffset));
1272           else
1273             int_part = GEN_INT (newoffset);
1274
1275           ptr_reg = force_reg (Pmode,
1276                                gen_rtx_PLUS (Pmode,
1277                                              force_reg (Pmode, XEXP (x, 0)),
1278                                              int_part));
1279         }
1280       return plus_constant (ptr_reg, offset - newoffset);
1281     }
1282
1283   /* Handle (plus (mult (a) (shadd_constant)) (b)).  */
1284
1285   if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1286       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1287       && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
1288       && (OBJECT_P (XEXP (x, 1))
1289           || GET_CODE (XEXP (x, 1)) == SUBREG)
1290       && GET_CODE (XEXP (x, 1)) != CONST)
1291     {
1292       int val = INTVAL (XEXP (XEXP (x, 0), 1));
1293       rtx reg1, reg2;
1294
1295       reg1 = XEXP (x, 1);
1296       if (GET_CODE (reg1) != REG)
1297         reg1 = force_reg (Pmode, force_operand (reg1, 0));
1298
1299       reg2 = XEXP (XEXP (x, 0), 0);
1300       if (GET_CODE (reg2) != REG)
1301         reg2 = force_reg (Pmode, force_operand (reg2, 0));
1302
1303       return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1304                                              gen_rtx_MULT (Pmode,
1305                                                            reg2,
1306                                                            GEN_INT (val)),
1307                                              reg1));
1308     }
1309
1310   /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
1311
1312      Only do so for floating point modes since this is more speculative
1313      and we lose if it's an integer store.  */
1314   if (GET_CODE (x) == PLUS
1315       && GET_CODE (XEXP (x, 0)) == PLUS
1316       && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1317       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
1318       && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1319       && (mode == SFmode || mode == DFmode))
1320     {
1321
1322       /* First, try and figure out what to use as a base register.  */
1323       rtx reg1, reg2, base, idx, orig_base;
1324
1325       reg1 = XEXP (XEXP (x, 0), 1);
1326       reg2 = XEXP (x, 1);
1327       base = NULL_RTX;
1328       idx = NULL_RTX;
1329
1330       /* Make sure they're both regs.  If one was a SYMBOL_REF [+ const],
1331          then emit_move_sequence will turn on REG_POINTER so we'll know
1332          it's a base register below.  */
1333       if (GET_CODE (reg1) != REG)
1334         reg1 = force_reg (Pmode, force_operand (reg1, 0));
1335
1336       if (GET_CODE (reg2) != REG)
1337         reg2 = force_reg (Pmode, force_operand (reg2, 0));
1338
1339       /* Figure out what the base and index are.  */
1340
1341       if (GET_CODE (reg1) == REG
1342           && REG_POINTER (reg1))
1343         {
1344           base = reg1;
1345           orig_base = XEXP (XEXP (x, 0), 1);
1346           idx = gen_rtx_PLUS (Pmode,
1347                               gen_rtx_MULT (Pmode,
1348                                             XEXP (XEXP (XEXP (x, 0), 0), 0),
1349                                             XEXP (XEXP (XEXP (x, 0), 0), 1)),
1350                               XEXP (x, 1));
1351         }
1352       else if (GET_CODE (reg2) == REG
1353                && REG_POINTER (reg2))
1354         {
1355           base = reg2;
1356           orig_base = XEXP (x, 1);
1357           idx = XEXP (x, 0);
1358         }
1359
1360       if (base == 0)
1361         return orig;
1362
1363       /* If the index adds a large constant, try to scale the
1364          constant so that it can be loaded with only one insn.  */
1365       if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1366           && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1367                             / INTVAL (XEXP (XEXP (idx, 0), 1)))
1368           && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1369         {
1370           /* Divide the CONST_INT by the scale factor, then add it to A.  */
1371           int val = INTVAL (XEXP (idx, 1));
1372
1373           val /= INTVAL (XEXP (XEXP (idx, 0), 1));
1374           reg1 = XEXP (XEXP (idx, 0), 0);
1375           if (GET_CODE (reg1) != REG)
1376             reg1 = force_reg (Pmode, force_operand (reg1, 0));
1377
1378           reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1379
1380           /* We can now generate a simple scaled indexed address.  */
1381           return
1382             force_reg
1383               (Pmode, gen_rtx_PLUS (Pmode,
1384                                     gen_rtx_MULT (Pmode, reg1,
1385                                                   XEXP (XEXP (idx, 0), 1)),
1386                                     base));
1387         }
1388
1389       /* If B + C is still a valid base register, then add them.  */
1390       if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1391           && INTVAL (XEXP (idx, 1)) <= 4096
1392           && INTVAL (XEXP (idx, 1)) >= -4096)
1393         {
1394           int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1395           rtx reg1, reg2;
1396
1397           reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1398
1399           reg2 = XEXP (XEXP (idx, 0), 0);
1400           if (GET_CODE (reg2) != CONST_INT)
1401             reg2 = force_reg (Pmode, force_operand (reg2, 0));
1402
1403           return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1404                                                  gen_rtx_MULT (Pmode,
1405                                                                reg2,
1406                                                                GEN_INT (val)),
1407                                                  reg1));
1408         }
1409
1410       /* Get the index into a register, then add the base + index and
1411          return a register holding the result.  */
1412
1413       /* First get A into a register.  */
1414       reg1 = XEXP (XEXP (idx, 0), 0);
1415       if (GET_CODE (reg1) != REG)
1416         reg1 = force_reg (Pmode, force_operand (reg1, 0));
1417
1418       /* And get B into a register.  */
1419       reg2 = XEXP (idx, 1);
1420       if (GET_CODE (reg2) != REG)
1421         reg2 = force_reg (Pmode, force_operand (reg2, 0));
1422
1423       reg1 = force_reg (Pmode,
1424                         gen_rtx_PLUS (Pmode,
1425                                       gen_rtx_MULT (Pmode, reg1,
1426                                                     XEXP (XEXP (idx, 0), 1)),
1427                                       reg2));
1428
1429       /* Add the result to our base register and return.  */
1430       return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1431
1432     }
1433
1434   /* Uh-oh.  We might have an address for x[n-100000].  This needs
1435      special handling to avoid creating an indexed memory address
1436      with x-100000 as the base.
1437
1438      If the constant part is small enough, then it's still safe because
1439      there is a guard page at the beginning and end of the data segment.
1440
1441      Scaled references are common enough that we want to try and rearrange the
1442      terms so that we can use indexing for these addresses too.  Only
1443      do the optimization for floatint point modes.  */
1444
1445   if (GET_CODE (x) == PLUS
1446       && symbolic_expression_p (XEXP (x, 1)))
1447     {
1448       /* Ugly.  We modify things here so that the address offset specified
1449          by the index expression is computed first, then added to x to form
1450          the entire address.  */
1451
1452       rtx regx1, regx2, regy1, regy2, y;
1453
1454       /* Strip off any CONST.  */
1455       y = XEXP (x, 1);
1456       if (GET_CODE (y) == CONST)
1457         y = XEXP (y, 0);
1458
1459       if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1460         {
1461           /* See if this looks like
1462                 (plus (mult (reg) (shadd_const))
1463                       (const (plus (symbol_ref) (const_int))))
1464
1465              Where const_int is small.  In that case the const
1466              expression is a valid pointer for indexing.
1467
1468              If const_int is big, but can be divided evenly by shadd_const
1469              and added to (reg).  This allows more scaled indexed addresses.  */
1470           if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1471               && GET_CODE (XEXP (x, 0)) == MULT
1472               && GET_CODE (XEXP (y, 1)) == CONST_INT
1473               && INTVAL (XEXP (y, 1)) >= -4096
1474               && INTVAL (XEXP (y, 1)) <= 4095
1475               && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1476               && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1477             {
1478               int val = INTVAL (XEXP (XEXP (x, 0), 1));
1479               rtx reg1, reg2;
1480
1481               reg1 = XEXP (x, 1);
1482               if (GET_CODE (reg1) != REG)
1483                 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1484
1485               reg2 = XEXP (XEXP (x, 0), 0);
1486               if (GET_CODE (reg2) != REG)
1487                 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1488
1489               return force_reg (Pmode,
1490                                 gen_rtx_PLUS (Pmode,
1491                                               gen_rtx_MULT (Pmode,
1492                                                             reg2,
1493                                                             GEN_INT (val)),
1494                                               reg1));
1495             }
1496           else if ((mode == DFmode || mode == SFmode)
1497                    && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1498                    && GET_CODE (XEXP (x, 0)) == MULT
1499                    && GET_CODE (XEXP (y, 1)) == CONST_INT
1500                    && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1501                    && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1502                    && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1503             {
1504               regx1
1505                 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1506                                              / INTVAL (XEXP (XEXP (x, 0), 1))));
1507               regx2 = XEXP (XEXP (x, 0), 0);
1508               if (GET_CODE (regx2) != REG)
1509                 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1510               regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1511                                                         regx2, regx1));
1512               return
1513                 force_reg (Pmode,
1514                            gen_rtx_PLUS (Pmode,
1515                                          gen_rtx_MULT (Pmode, regx2,
1516                                                        XEXP (XEXP (x, 0), 1)),
1517                                          force_reg (Pmode, XEXP (y, 0))));
1518             }
1519           else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1520                    && INTVAL (XEXP (y, 1)) >= -4096
1521                    && INTVAL (XEXP (y, 1)) <= 4095)
1522             {
1523               /* This is safe because of the guard page at the
1524                  beginning and end of the data space.  Just
1525                  return the original address.  */
1526               return orig;
1527             }
1528           else
1529             {
1530               /* Doesn't look like one we can optimize.  */
1531               regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1532               regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1533               regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1534               regx1 = force_reg (Pmode,
1535                                  gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1536                                                  regx1, regy2));
1537               return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1538             }
1539         }
1540     }
1541
1542   return orig;
1543 }
1544
1545 /* For the HPPA, REG and REG+CONST is cost 0
1546    and addresses involving symbolic constants are cost 2.
1547
1548    PIC addresses are very expensive.
1549
1550    It is no coincidence that this has the same structure
1551    as GO_IF_LEGITIMATE_ADDRESS.  */
1552
1553 static int
1554 hppa_address_cost (rtx X)
1555 {
1556   switch (GET_CODE (X))
1557     {
1558     case REG:
1559     case PLUS:
1560     case LO_SUM:
1561       return 1;
1562     case HIGH:
1563       return 2;
1564     default:
1565       return 4;
1566     }
1567 }
1568
1569 /* Compute a (partial) cost for rtx X.  Return true if the complete
1570    cost has been computed, and false if subexpressions should be
1571    scanned.  In either case, *TOTAL contains the cost result.  */
1572
1573 static bool
1574 hppa_rtx_costs (rtx x, int code, int outer_code, int *total)
1575 {
1576   switch (code)
1577     {
1578     case CONST_INT:
1579       if (INTVAL (x) == 0)
1580         *total = 0;
1581       else if (INT_14_BITS (x))
1582         *total = 1;
1583       else
1584         *total = 2;
1585       return true;
1586
1587     case HIGH:
1588       *total = 2;
1589       return true;
1590
1591     case CONST:
1592     case LABEL_REF:
1593     case SYMBOL_REF:
1594       *total = 4;
1595       return true;
1596
1597     case CONST_DOUBLE:
1598       if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1599           && outer_code != SET)
1600         *total = 0;
1601       else
1602         *total = 8;
1603       return true;
1604
1605     case MULT:
1606       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1607         *total = COSTS_N_INSNS (3);
1608       else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1609         *total = COSTS_N_INSNS (8);
1610       else
1611         *total = COSTS_N_INSNS (20);
1612       return true;
1613
1614     case DIV:
1615       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1616         {
1617           *total = COSTS_N_INSNS (14);
1618           return true;
1619         }
1620       /* FALLTHRU */
1621
1622     case UDIV:
1623     case MOD:
1624     case UMOD:
1625       *total = COSTS_N_INSNS (60);
1626       return true;
1627
1628     case PLUS: /* this includes shNadd insns */
1629     case MINUS:
1630       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1631         *total = COSTS_N_INSNS (3);
1632       else
1633         *total = COSTS_N_INSNS (1);
1634       return true;
1635
1636     case ASHIFT:
1637     case ASHIFTRT:
1638     case LSHIFTRT:
1639       *total = COSTS_N_INSNS (1);
1640       return true;
1641
1642     default:
1643       return false;
1644     }
1645 }
1646
1647 /* Ensure mode of ORIG, a REG rtx, is MODE.  Returns either ORIG or a
1648    new rtx with the correct mode.  */
1649 static inline rtx
1650 force_mode (enum machine_mode mode, rtx orig)
1651 {
1652   if (mode == GET_MODE (orig))
1653     return orig;
1654
1655   if (REGNO (orig) >= FIRST_PSEUDO_REGISTER)
1656     abort ();
1657
1658   return gen_rtx_REG (mode, REGNO (orig));
1659 }
1660
1661 /* Emit insns to move operands[1] into operands[0].
1662
1663    Return 1 if we have written out everything that needs to be done to
1664    do the move.  Otherwise, return 0 and the caller will emit the move
1665    normally.
1666
1667    Note SCRATCH_REG may not be in the proper mode depending on how it
1668    will be used.  This routine is responsible for creating a new copy
1669    of SCRATCH_REG in the proper mode.  */
1670
1671 int
1672 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1673 {
1674   register rtx operand0 = operands[0];
1675   register rtx operand1 = operands[1];
1676   register rtx tem;
1677
1678   /* We can only handle indexed addresses in the destination operand
1679      of floating point stores.  Thus, we need to break out indexed
1680      addresses from the destination operand.  */
1681   if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1682     {
1683       /* This is only safe up to the beginning of life analysis.  */
1684       if (no_new_pseudos)
1685         abort ();
1686
1687       tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1688       operand0 = replace_equiv_address (operand0, tem);
1689     }
1690
1691   /* On targets with non-equivalent space registers, break out unscaled
1692      indexed addresses from the source operand before the final CSE.
1693      We have to do this because the REG_POINTER flag is not correctly
1694      carried through various optimization passes and CSE may substitute
1695      a pseudo without the pointer set for one with the pointer set.  As
1696      a result, we loose various opportunities to create insns with
1697      unscaled indexed addresses.  */
1698   if (!TARGET_NO_SPACE_REGS
1699       && !cse_not_expected
1700       && GET_CODE (operand1) == MEM
1701       && GET_CODE (XEXP (operand1, 0)) == PLUS
1702       && REG_P (XEXP (XEXP (operand1, 0), 0))
1703       && REG_P (XEXP (XEXP (operand1, 0), 1)))
1704     operand1
1705       = replace_equiv_address (operand1,
1706                                copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1707
1708   if (scratch_reg
1709       && reload_in_progress && GET_CODE (operand0) == REG
1710       && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1711     operand0 = reg_equiv_mem[REGNO (operand0)];
1712   else if (scratch_reg
1713            && reload_in_progress && GET_CODE (operand0) == SUBREG
1714            && GET_CODE (SUBREG_REG (operand0)) == REG
1715            && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1716     {
1717      /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1718         the code which tracks sets/uses for delete_output_reload.  */
1719       rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1720                                  reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1721                                  SUBREG_BYTE (operand0));
1722       operand0 = alter_subreg (&temp);
1723     }
1724
1725   if (scratch_reg
1726       && reload_in_progress && GET_CODE (operand1) == REG
1727       && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1728     operand1 = reg_equiv_mem[REGNO (operand1)];
1729   else if (scratch_reg
1730            && reload_in_progress && GET_CODE (operand1) == SUBREG
1731            && GET_CODE (SUBREG_REG (operand1)) == REG
1732            && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1733     {
1734      /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1735         the code which tracks sets/uses for delete_output_reload.  */
1736       rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1737                                  reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1738                                  SUBREG_BYTE (operand1));
1739       operand1 = alter_subreg (&temp);
1740     }
1741
1742   if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1743       && ((tem = find_replacement (&XEXP (operand0, 0)))
1744           != XEXP (operand0, 0)))
1745     operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
1746
1747   if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1748       && ((tem = find_replacement (&XEXP (operand1, 0)))
1749           != XEXP (operand1, 0)))
1750     operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
1751
1752   /* Handle secondary reloads for loads/stores of FP registers from
1753      REG+D addresses where D does not fit in 5 or 14 bits, including
1754      (subreg (mem (addr))) cases.  */
1755   if (scratch_reg
1756       && fp_reg_operand (operand0, mode)
1757       && ((GET_CODE (operand1) == MEM
1758            && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1759                                  XEXP (operand1, 0)))
1760           || ((GET_CODE (operand1) == SUBREG
1761                && GET_CODE (XEXP (operand1, 0)) == MEM
1762                && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1763                                       ? SFmode : DFmode),
1764                                      XEXP (XEXP (operand1, 0), 0))))))
1765     {
1766       if (GET_CODE (operand1) == SUBREG)
1767         operand1 = XEXP (operand1, 0);
1768
1769       /* SCRATCH_REG will hold an address and maybe the actual data.  We want
1770          it in WORD_MODE regardless of what mode it was originally given
1771          to us.  */
1772       scratch_reg = force_mode (word_mode, scratch_reg);
1773
1774       /* D might not fit in 14 bits either; for such cases load D into
1775          scratch reg.  */
1776       if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1777         {
1778           emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1779           emit_move_insn (scratch_reg,
1780                           gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1781                                           Pmode,
1782                                           XEXP (XEXP (operand1, 0), 0),
1783                                           scratch_reg));
1784         }
1785       else
1786         emit_move_insn (scratch_reg, XEXP (operand1, 0));
1787       emit_insn (gen_rtx_SET (VOIDmode, operand0,
1788                               gen_rtx_MEM (mode, scratch_reg)));
1789       return 1;
1790     }
1791   else if (scratch_reg
1792            && fp_reg_operand (operand1, mode)
1793            && ((GET_CODE (operand0) == MEM
1794                 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1795                                         ? SFmode : DFmode),
1796                                        XEXP (operand0, 0)))
1797                || ((GET_CODE (operand0) == SUBREG)
1798                    && GET_CODE (XEXP (operand0, 0)) == MEM
1799                    && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1800                                           ? SFmode : DFmode),
1801                                          XEXP (XEXP (operand0, 0), 0)))))
1802     {
1803       if (GET_CODE (operand0) == SUBREG)
1804         operand0 = XEXP (operand0, 0);
1805
1806       /* SCRATCH_REG will hold an address and maybe the actual data.  We want
1807          it in WORD_MODE regardless of what mode it was originally given
1808          to us.  */
1809       scratch_reg = force_mode (word_mode, scratch_reg);
1810
1811       /* D might not fit in 14 bits either; for such cases load D into
1812          scratch reg.  */
1813       if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1814         {
1815           emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1816           emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1817                                                                         0)),
1818                                                        Pmode,
1819                                                        XEXP (XEXP (operand0, 0),
1820                                                                    0),
1821                                                        scratch_reg));
1822         }
1823       else
1824         emit_move_insn (scratch_reg, XEXP (operand0, 0));
1825       emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
1826                               operand1));
1827       return 1;
1828     }
1829   /* Handle secondary reloads for loads of FP registers from constant
1830      expressions by forcing the constant into memory.
1831
1832      Use scratch_reg to hold the address of the memory location.
1833
1834      The proper fix is to change PREFERRED_RELOAD_CLASS to return
1835      NO_REGS when presented with a const_int and a register class
1836      containing only FP registers.  Doing so unfortunately creates
1837      more problems than it solves.   Fix this for 2.5.  */
1838   else if (scratch_reg
1839            && CONSTANT_P (operand1)
1840            && fp_reg_operand (operand0, mode))
1841     {
1842       rtx xoperands[2];
1843
1844       /* SCRATCH_REG will hold an address and maybe the actual data.  We want
1845          it in WORD_MODE regardless of what mode it was originally given
1846          to us.  */
1847       scratch_reg = force_mode (word_mode, scratch_reg);
1848
1849       /* Force the constant into memory and put the address of the
1850          memory location into scratch_reg.  */
1851       xoperands[0] = scratch_reg;
1852       xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
1853       emit_move_sequence (xoperands, Pmode, 0);
1854
1855       /* Now load the destination register.  */
1856       emit_insn (gen_rtx_SET (mode, operand0,
1857                               gen_rtx_MEM (mode, scratch_reg)));
1858       return 1;
1859     }
1860   /* Handle secondary reloads for SAR.  These occur when trying to load
1861      the SAR from memory, FP register, or with a constant.  */
1862   else if (scratch_reg
1863            && GET_CODE (operand0) == REG
1864            && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1865            && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1866            && (GET_CODE (operand1) == MEM
1867                || GET_CODE (operand1) == CONST_INT
1868                || (GET_CODE (operand1) == REG
1869                    && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1870     {
1871       /* D might not fit in 14 bits either; for such cases load D into
1872          scratch reg.  */
1873       if (GET_CODE (operand1) == MEM
1874           && !memory_address_p (Pmode, XEXP (operand1, 0)))
1875         {
1876           /* We are reloading the address into the scratch register, so we
1877              want to make sure the scratch register is a full register.  */
1878           scratch_reg = force_mode (word_mode, scratch_reg);
1879
1880           emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1881           emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1882                                                                         0)),
1883                                                        Pmode,
1884                                                        XEXP (XEXP (operand1, 0),
1885                                                        0),
1886                                                        scratch_reg));
1887
1888           /* Now we are going to load the scratch register from memory,
1889              we want to load it in the same width as the original MEM,
1890              which must be the same as the width of the ultimate destination,
1891              OPERAND0.  */
1892           scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1893
1894           emit_move_insn (scratch_reg, gen_rtx_MEM (GET_MODE (operand0),
1895                                                     scratch_reg));
1896         }
1897       else
1898         {
1899           /* We want to load the scratch register using the same mode as
1900              the ultimate destination.  */
1901           scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1902
1903           emit_move_insn (scratch_reg, operand1);
1904         }
1905
1906       /* And emit the insn to set the ultimate destination.  We know that
1907          the scratch register has the same mode as the destination at this
1908          point.  */
1909       emit_move_insn (operand0, scratch_reg);
1910       return 1;
1911     }
1912   /* Handle the most common case: storing into a register.  */
1913   else if (register_operand (operand0, mode))
1914     {
1915       if (register_operand (operand1, mode)
1916           || (GET_CODE (operand1) == CONST_INT
1917               && cint_ok_for_move (INTVAL (operand1)))
1918           || (operand1 == CONST0_RTX (mode))
1919           || (GET_CODE (operand1) == HIGH
1920               && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1921           /* Only `general_operands' can come here, so MEM is ok.  */
1922           || GET_CODE (operand1) == MEM)
1923         {
1924           /* Various sets are created during RTL generation which don't
1925              have the REG_POINTER flag correctly set.  After the CSE pass,
1926              instruction recognition can fail if we don't consistently
1927              set this flag when performing register copies.  This should
1928              also improve the opportunities for creating insns that use
1929              unscaled indexing.  */
1930           if (REG_P (operand0) && REG_P (operand1))
1931             {
1932               if (REG_POINTER (operand1)
1933                   && !REG_POINTER (operand0)
1934                   && !HARD_REGISTER_P (operand0))
1935                 copy_reg_pointer (operand0, operand1);
1936               else if (REG_POINTER (operand0)
1937                        && !REG_POINTER (operand1)
1938                        && !HARD_REGISTER_P (operand1))
1939                 copy_reg_pointer (operand1, operand0);
1940             }
1941           
1942           /* When MEMs are broken out, the REG_POINTER flag doesn't
1943              get set.  In some cases, we can set the REG_POINTER flag
1944              from the declaration for the MEM.  */
1945           if (REG_P (operand0)
1946               && GET_CODE (operand1) == MEM
1947               && !REG_POINTER (operand0))
1948             {
1949               tree decl = MEM_EXPR (operand1);
1950
1951               /* Set the register pointer flag and register alignment
1952                  if the declaration for this memory reference is a
1953                  pointer type.  Fortran indirect argument references
1954                  are ignored.  */
1955               if (decl
1956                   && !(flag_argument_noalias > 1
1957                        && TREE_CODE (decl) == INDIRECT_REF
1958                        && TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL))
1959                 {
1960                   tree type;
1961
1962                   /* If this is a COMPONENT_REF, use the FIELD_DECL from
1963                      tree operand 1.  */
1964                   if (TREE_CODE (decl) == COMPONENT_REF)
1965                     decl = TREE_OPERAND (decl, 1);
1966
1967                   type = TREE_TYPE (decl);
1968                   if (TREE_CODE (type) == ARRAY_TYPE)
1969                     type = get_inner_array_type (type);
1970
1971                   if (POINTER_TYPE_P (type))
1972                     {
1973                       int align;
1974
1975                       type = TREE_TYPE (type);
1976                       /* Using TYPE_ALIGN_OK is rather conservative as
1977                          only the ada frontend actually sets it.  */
1978                       align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1979                                : BITS_PER_UNIT);
1980                       mark_reg_pointer (operand0, align);
1981                     }
1982                 }
1983             }
1984
1985           emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1986           return 1;
1987         }
1988     }
1989   else if (GET_CODE (operand0) == MEM)
1990     {
1991       if (mode == DFmode && operand1 == CONST0_RTX (mode)
1992           && !(reload_in_progress || reload_completed))
1993         {
1994           rtx temp = gen_reg_rtx (DFmode);
1995
1996           emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1997           emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1998           return 1;
1999         }
2000       if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
2001         {
2002           /* Run this case quickly.  */
2003           emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
2004           return 1;
2005         }
2006       if (! (reload_in_progress || reload_completed))
2007         {
2008           operands[0] = validize_mem (operand0);
2009           operands[1] = operand1 = force_reg (mode, operand1);
2010         }
2011     }
2012
2013   /* Simplify the source if we need to.
2014      Note we do have to handle function labels here, even though we do
2015      not consider them legitimate constants.  Loop optimizations can
2016      call the emit_move_xxx with one as a source.  */
2017   if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
2018       || function_label_operand (operand1, mode)
2019       || (GET_CODE (operand1) == HIGH
2020           && symbolic_operand (XEXP (operand1, 0), mode)))
2021     {
2022       int ishighonly = 0;
2023
2024       if (GET_CODE (operand1) == HIGH)
2025         {
2026           ishighonly = 1;
2027           operand1 = XEXP (operand1, 0);
2028         }
2029       if (symbolic_operand (operand1, mode))
2030         {
2031           /* Argh.  The assembler and linker can't handle arithmetic
2032              involving plabels.
2033
2034              So we force the plabel into memory, load operand0 from
2035              the memory location, then add in the constant part.  */
2036           if ((GET_CODE (operand1) == CONST
2037                && GET_CODE (XEXP (operand1, 0)) == PLUS
2038                && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
2039               || function_label_operand (operand1, mode))
2040             {
2041               rtx temp, const_part;
2042
2043               /* Figure out what (if any) scratch register to use.  */
2044               if (reload_in_progress || reload_completed)
2045                 {
2046                   scratch_reg = scratch_reg ? scratch_reg : operand0;
2047                   /* SCRATCH_REG will hold an address and maybe the actual
2048                      data.  We want it in WORD_MODE regardless of what mode it
2049                      was originally given to us.  */
2050                   scratch_reg = force_mode (word_mode, scratch_reg);
2051                 }
2052               else if (flag_pic)
2053                 scratch_reg = gen_reg_rtx (Pmode);
2054
2055               if (GET_CODE (operand1) == CONST)
2056                 {
2057                   /* Save away the constant part of the expression.  */
2058                   const_part = XEXP (XEXP (operand1, 0), 1);
2059                   if (GET_CODE (const_part) != CONST_INT)
2060                     abort ();
2061
2062                   /* Force the function label into memory.  */
2063                   temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
2064                 }
2065               else
2066                 {
2067                   /* No constant part.  */
2068                   const_part = NULL_RTX;
2069
2070                   /* Force the function label into memory.  */
2071                   temp = force_const_mem (mode, operand1);
2072                 }
2073
2074
2075               /* Get the address of the memory location.  PIC-ify it if
2076                  necessary.  */
2077               temp = XEXP (temp, 0);
2078               if (flag_pic)
2079                 temp = legitimize_pic_address (temp, mode, scratch_reg);
2080
2081               /* Put the address of the memory location into our destination
2082                  register.  */
2083               operands[1] = temp;
2084               emit_move_sequence (operands, mode, scratch_reg);
2085
2086               /* Now load from the memory location into our destination
2087                  register.  */
2088               operands[1] = gen_rtx_MEM (Pmode, operands[0]);
2089               emit_move_sequence (operands, mode, scratch_reg);
2090
2091               /* And add back in the constant part.  */
2092               if (const_part != NULL_RTX)
2093                 expand_inc (operand0, const_part);
2094
2095               return 1;
2096             }
2097
2098           if (flag_pic)
2099             {
2100               rtx temp;
2101
2102               if (reload_in_progress || reload_completed)
2103                 {
2104                   temp = scratch_reg ? scratch_reg : operand0;
2105                   /* TEMP will hold an address and maybe the actual
2106                      data.  We want it in WORD_MODE regardless of what mode it
2107                      was originally given to us.  */
2108                   temp = force_mode (word_mode, temp);
2109                 }
2110               else
2111                 temp = gen_reg_rtx (Pmode);
2112
2113               /* (const (plus (symbol) (const_int))) must be forced to
2114                  memory during/after reload if the const_int will not fit
2115                  in 14 bits.  */
2116               if (GET_CODE (operand1) == CONST
2117                        && GET_CODE (XEXP (operand1, 0)) == PLUS
2118                        && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
2119                        && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
2120                        && (reload_completed || reload_in_progress)
2121                        && flag_pic)
2122                 {
2123                   operands[1] = force_const_mem (mode, operand1);
2124                   operands[1] = legitimize_pic_address (XEXP (operands[1], 0),
2125                                                         mode, temp);
2126                   operands[1] = gen_rtx_MEM (mode, operands[1]);
2127                   emit_move_sequence (operands, mode, temp);
2128                 }
2129               else
2130                 {
2131                   operands[1] = legitimize_pic_address (operand1, mode, temp);
2132                   if (REG_P (operand0) && REG_P (operands[1]))
2133                     copy_reg_pointer (operand0, operands[1]);
2134                   emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
2135                 }
2136             }
2137           /* On the HPPA, references to data space are supposed to use dp,
2138              register 27, but showing it in the RTL inhibits various cse
2139              and loop optimizations.  */
2140           else
2141             {
2142               rtx temp, set;
2143
2144               if (reload_in_progress || reload_completed)
2145                 {
2146                   temp = scratch_reg ? scratch_reg : operand0;
2147                   /* TEMP will hold an address and maybe the actual
2148                      data.  We want it in WORD_MODE regardless of what mode it
2149                      was originally given to us.  */
2150                   temp = force_mode (word_mode, temp);
2151                 }
2152               else
2153                 temp = gen_reg_rtx (mode);
2154
2155               /* Loading a SYMBOL_REF into a register makes that register
2156                  safe to be used as the base in an indexed address.
2157
2158                  Don't mark hard registers though.  That loses.  */
2159               if (GET_CODE (operand0) == REG
2160                   && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
2161                 mark_reg_pointer (operand0, BITS_PER_UNIT);
2162               if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
2163                 mark_reg_pointer (temp, BITS_PER_UNIT);
2164
2165               if (ishighonly)
2166                 set = gen_rtx_SET (mode, operand0, temp);
2167               else
2168                 set = gen_rtx_SET (VOIDmode,
2169                                    operand0,
2170                                    gen_rtx_LO_SUM (mode, temp, operand1));
2171
2172               emit_insn (gen_rtx_SET (VOIDmode,
2173                                       temp,
2174                                       gen_rtx_HIGH (mode, operand1)));
2175               emit_insn (set);
2176
2177             }
2178           return 1;
2179         }
2180       else if (GET_CODE (operand1) != CONST_INT
2181                || !cint_ok_for_move (INTVAL (operand1)))
2182         {
2183           rtx insn, temp;
2184           rtx op1 = operand1;
2185           HOST_WIDE_INT value = 0;
2186           HOST_WIDE_INT insv = 0;
2187           int insert = 0;
2188
2189           if (GET_CODE (operand1) == CONST_INT)
2190             value = INTVAL (operand1);
2191
2192           if (TARGET_64BIT
2193               && GET_CODE (operand1) == CONST_INT
2194               && HOST_BITS_PER_WIDE_INT > 32
2195               && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
2196             {
2197               HOST_WIDE_INT nval;
2198
2199               /* Extract the low order 32 bits of the value and sign extend.
2200                  If the new value is the same as the original value, we can
2201                  can use the original value as-is.  If the new value is
2202                  different, we use it and insert the most-significant 32-bits
2203                  of the original value into the final result.  */
2204               nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
2205                       ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
2206               if (value != nval)
2207                 {
2208 #if HOST_BITS_PER_WIDE_INT > 32
2209                   insv = value >= 0 ? value >> 32 : ~(~value >> 32);
2210 #endif
2211                   insert = 1;
2212                   value = nval;
2213                   operand1 = GEN_INT (nval);
2214                 }
2215             }
2216
2217           if (reload_in_progress || reload_completed)
2218             temp = scratch_reg ? scratch_reg : operand0;
2219           else
2220             temp = gen_reg_rtx (mode);
2221
2222           /* We don't directly split DImode constants on 32-bit targets
2223              because PLUS uses an 11-bit immediate and the insn sequence
2224              generated is not as efficient as the one using HIGH/LO_SUM.  */
2225           if (GET_CODE (operand1) == CONST_INT
2226               && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2227               && !insert)
2228             {
2229               /* Directly break constant into high and low parts.  This
2230                  provides better optimization opportunities because various
2231                  passes recognize constants split with PLUS but not LO_SUM.
2232                  We use a 14-bit signed low part except when the addition
2233                  of 0x4000 to the high part might change the sign of the
2234                  high part.  */
2235               HOST_WIDE_INT low = value & 0x3fff;
2236               HOST_WIDE_INT high = value & ~ 0x3fff;
2237
2238               if (low >= 0x2000)
2239                 {
2240                   if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
2241                     high += 0x2000;
2242                   else
2243                     high += 0x4000;
2244                 }
2245
2246               low = value - high;
2247
2248               emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
2249               operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2250             }
2251           else
2252             {
2253               emit_insn (gen_rtx_SET (VOIDmode, temp,
2254                                       gen_rtx_HIGH (mode, operand1)));
2255               operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
2256             }
2257
2258           insn = emit_move_insn (operands[0], operands[1]);
2259
2260           /* Now insert the most significant 32 bits of the value
2261              into the register.  When we don't have a second register
2262              available, it could take up to nine instructions to load
2263              a 64-bit integer constant.  Prior to reload, we force
2264              constants that would take more than three instructions
2265              to load to the constant pool.  During and after reload,
2266              we have to handle all possible values.  */
2267           if (insert)
2268             {
2269               /* Use a HIGH/LO_SUM/INSV sequence if we have a second
2270                  register and the value to be inserted is outside the
2271                  range that can be loaded with three depdi instructions.  */
2272               if (temp != operand0 && (insv >= 16384 || insv < -16384))
2273                 {
2274                   operand1 = GEN_INT (insv);
2275
2276                   emit_insn (gen_rtx_SET (VOIDmode, temp,
2277                                           gen_rtx_HIGH (mode, operand1)));
2278                   emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
2279                   emit_insn (gen_insv (operand0, GEN_INT (32),
2280                                        const0_rtx, temp));
2281                 }
2282               else
2283                 {
2284                   int len = 5, pos = 27;
2285
2286                   /* Insert the bits using the depdi instruction.  */
2287                   while (pos >= 0)
2288                     {
2289                       HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2290                       HOST_WIDE_INT sign = v5 < 0;
2291
2292                       /* Left extend the insertion.  */
2293                       insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2294                       while (pos > 0 && (insv & 1) == sign)
2295                         {
2296                           insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2297                           len += 1;
2298                           pos -= 1;
2299                         }
2300
2301                       emit_insn (gen_insv (operand0, GEN_INT (len),
2302                                            GEN_INT (pos), GEN_INT (v5)));
2303
2304                       len = pos > 0 && pos < 5 ? pos : 5;
2305                       pos -= len;
2306                     }
2307                 }
2308             }
2309
2310           REG_NOTES (insn)
2311             = gen_rtx_EXPR_LIST (REG_EQUAL, op1, REG_NOTES (insn));
2312
2313           return 1;
2314         }
2315     }
2316   /* Now have insn-emit do whatever it normally does.  */
2317   return 0;
2318 }
2319
2320 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2321    it will need a link/runtime reloc).  */
2322
2323 int
2324 reloc_needed (tree exp)
2325 {
2326   int reloc = 0;
2327
2328   switch (TREE_CODE (exp))
2329     {
2330     case ADDR_EXPR:
2331       return 1;
2332
2333     case PLUS_EXPR:
2334     case MINUS_EXPR:
2335       reloc = reloc_needed (TREE_OPERAND (exp, 0));
2336       reloc |= reloc_needed (TREE_OPERAND (exp, 1));
2337       break;
2338
2339     case NOP_EXPR:
2340     case CONVERT_EXPR:
2341     case NON_LVALUE_EXPR:
2342       reloc = reloc_needed (TREE_OPERAND (exp, 0));
2343       break;
2344
2345     case CONSTRUCTOR:
2346       {
2347         register tree link;
2348         for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2349           if (TREE_VALUE (link) != 0)
2350             reloc |= reloc_needed (TREE_VALUE (link));
2351       }
2352       break;
2353
2354     case ERROR_MARK:
2355       break;
2356
2357     default:
2358       break;
2359     }
2360   return reloc;
2361 }
2362
2363 /* Does operand (which is a symbolic_operand) live in text space?
2364    If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2365    will be true.  */
2366
2367 int
2368 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2369 {
2370   if (GET_CODE (operand) == CONST)
2371     operand = XEXP (XEXP (operand, 0), 0);
2372   if (flag_pic)
2373     {
2374       if (GET_CODE (operand) == SYMBOL_REF)
2375         return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2376     }
2377   else
2378     {
2379       if (GET_CODE (operand) == SYMBOL_REF)
2380         return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2381     }
2382   return 1;
2383 }
2384
2385 \f
2386 /* Return the best assembler insn template
2387    for moving operands[1] into operands[0] as a fullword.  */
2388 const char *
2389 singlemove_string (rtx *operands)
2390 {
2391   HOST_WIDE_INT intval;
2392
2393   if (GET_CODE (operands[0]) == MEM)
2394     return "stw %r1,%0";
2395   if (GET_CODE (operands[1]) == MEM)
2396     return "ldw %1,%0";
2397   if (GET_CODE (operands[1]) == CONST_DOUBLE)
2398     {
2399       long i;
2400       REAL_VALUE_TYPE d;
2401
2402       if (GET_MODE (operands[1]) != SFmode)
2403         abort ();
2404
2405       /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2406          bit pattern.  */
2407       REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2408       REAL_VALUE_TO_TARGET_SINGLE (d, i);
2409
2410       operands[1] = GEN_INT (i);
2411       /* Fall through to CONST_INT case.  */
2412     }
2413   if (GET_CODE (operands[1]) == CONST_INT)
2414     {
2415       intval = INTVAL (operands[1]);
2416
2417       if (VAL_14_BITS_P (intval))
2418         return "ldi %1,%0";
2419       else if ((intval & 0x7ff) == 0)
2420         return "ldil L'%1,%0";
2421       else if (zdepi_cint_p (intval))
2422         return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2423       else
2424         return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2425     }
2426   return "copy %1,%0";
2427 }
2428 \f
2429
2430 /* Compute position (in OP[1]) and width (in OP[2])
2431    useful for copying IMM to a register using the zdepi
2432    instructions.  Store the immediate value to insert in OP[0].  */
2433 static void
2434 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2435 {
2436   int lsb, len;
2437
2438   /* Find the least significant set bit in IMM.  */
2439   for (lsb = 0; lsb < 32; lsb++)
2440     {
2441       if ((imm & 1) != 0)
2442         break;
2443       imm >>= 1;
2444     }
2445
2446   /* Choose variants based on *sign* of the 5-bit field.  */
2447   if ((imm & 0x10) == 0)
2448     len = (lsb <= 28) ? 4 : 32 - lsb;
2449   else
2450     {
2451       /* Find the width of the bitstring in IMM.  */
2452       for (len = 5; len < 32; len++)
2453         {
2454           if ((imm & (1 << len)) == 0)
2455             break;
2456         }
2457
2458       /* Sign extend IMM as a 5-bit value.  */
2459       imm = (imm & 0xf) - 0x10;
2460     }
2461
2462   op[0] = imm;
2463   op[1] = 31 - lsb;
2464   op[2] = len;
2465 }
2466
2467 /* Compute position (in OP[1]) and width (in OP[2])
2468    useful for copying IMM to a register using the depdi,z
2469    instructions.  Store the immediate value to insert in OP[0].  */
2470 void
2471 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2472 {
2473   HOST_WIDE_INT lsb, len;
2474
2475   /* Find the least significant set bit in IMM.  */
2476   for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
2477     {
2478       if ((imm & 1) != 0)
2479         break;
2480       imm >>= 1;
2481     }
2482
2483   /* Choose variants based on *sign* of the 5-bit field.  */
2484   if ((imm & 0x10) == 0)
2485     len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
2486            ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
2487   else
2488     {
2489       /* Find the width of the bitstring in IMM.  */
2490       for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
2491         {
2492           if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2493             break;
2494         }
2495
2496       /* Sign extend IMM as a 5-bit value.  */
2497       imm = (imm & 0xf) - 0x10;
2498     }
2499
2500   op[0] = imm;
2501   op[1] = 63 - lsb;
2502   op[2] = len;
2503 }
2504
2505 /* Output assembler code to perform a doubleword move insn
2506    with operands OPERANDS.  */
2507
2508 const char *
2509 output_move_double (rtx *operands)
2510 {
2511   enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2512   rtx latehalf[2];
2513   rtx addreg0 = 0, addreg1 = 0;
2514
2515   /* First classify both operands.  */
2516
2517   if (REG_P (operands[0]))
2518     optype0 = REGOP;
2519   else if (offsettable_memref_p (operands[0]))
2520     optype0 = OFFSOP;
2521   else if (GET_CODE (operands[0]) == MEM)
2522     optype0 = MEMOP;
2523   else
2524     optype0 = RNDOP;
2525
2526   if (REG_P (operands[1]))
2527     optype1 = REGOP;
2528   else if (CONSTANT_P (operands[1]))
2529     optype1 = CNSTOP;
2530   else if (offsettable_memref_p (operands[1]))
2531     optype1 = OFFSOP;
2532   else if (GET_CODE (operands[1]) == MEM)
2533     optype1 = MEMOP;
2534   else
2535     optype1 = RNDOP;
2536
2537   /* Check for the cases that the operand constraints are not
2538      supposed to allow to happen.  Abort if we get one,
2539      because generating code for these cases is painful.  */
2540
2541   if (optype0 != REGOP && optype1 != REGOP)
2542     abort ();
2543
2544    /* Handle auto decrementing and incrementing loads and stores
2545      specifically, since the structure of the function doesn't work
2546      for them without major modification.  Do it better when we learn
2547      this port about the general inc/dec addressing of PA.
2548      (This was written by tege.  Chide him if it doesn't work.)  */
2549
2550   if (optype0 == MEMOP)
2551     {
2552       /* We have to output the address syntax ourselves, since print_operand
2553          doesn't deal with the addresses we want to use.  Fix this later.  */
2554
2555       rtx addr = XEXP (operands[0], 0);
2556       if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2557         {
2558           rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2559
2560           operands[0] = XEXP (addr, 0);
2561           if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2562             abort ();
2563
2564           if (!reg_overlap_mentioned_p (high_reg, addr))
2565             {
2566               /* No overlap between high target register and address
2567                  register.  (We do this in a non-obvious way to
2568                  save a register file writeback)  */
2569               if (GET_CODE (addr) == POST_INC)
2570                 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2571               return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2572             }
2573           else
2574             abort ();
2575         }
2576       else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2577         {
2578           rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2579
2580           operands[0] = XEXP (addr, 0);
2581           if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2582             abort ();
2583
2584           if (!reg_overlap_mentioned_p (high_reg, addr))
2585             {
2586               /* No overlap between high target register and address
2587                  register.  (We do this in a non-obvious way to
2588                  save a register file writeback)  */
2589               if (GET_CODE (addr) == PRE_INC)
2590                 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2591               return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2592             }
2593           else
2594             abort ();
2595         }
2596     }
2597   if (optype1 == MEMOP)
2598     {
2599       /* We have to output the address syntax ourselves, since print_operand
2600          doesn't deal with the addresses we want to use.  Fix this later.  */
2601
2602       rtx addr = XEXP (operands[1], 0);
2603       if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2604         {
2605           rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2606
2607           operands[1] = XEXP (addr, 0);
2608           if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2609             abort ();
2610
2611           if (!reg_overlap_mentioned_p (high_reg, addr))
2612             {
2613               /* No overlap between high target register and address
2614                  register.  (We do this in a non-obvious way to
2615                  save a register file writeback)  */
2616               if (GET_CODE (addr) == POST_INC)
2617                 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2618               return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2619             }
2620           else
2621             {
2622               /* This is an undefined situation.  We should load into the
2623                  address register *and* update that register.  Probably
2624                  we don't need to handle this at all.  */
2625               if (GET_CODE (addr) == POST_INC)
2626                 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2627               return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2628             }
2629         }
2630       else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2631         {
2632           rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2633
2634           operands[1] = XEXP (addr, 0);
2635           if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2636             abort ();
2637
2638           if (!reg_overlap_mentioned_p (high_reg, addr))
2639             {
2640               /* No overlap between high target register and address
2641                  register.  (We do this in a non-obvious way to
2642                  save a register file writeback)  */
2643               if (GET_CODE (addr) == PRE_INC)
2644                 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2645               return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2646             }
2647           else
2648             {
2649               /* This is an undefined situation.  We should load into the
2650                  address register *and* update that register.  Probably
2651                  we don't need to handle this at all.  */
2652               if (GET_CODE (addr) == PRE_INC)
2653                 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2654               return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2655             }
2656         }
2657       else if (GET_CODE (addr) == PLUS
2658                && GET_CODE (XEXP (addr, 0)) == MULT)
2659         {
2660           rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2661
2662           if (!reg_overlap_mentioned_p (high_reg, addr))
2663             {
2664               rtx xoperands[3];
2665
2666               xoperands[0] = high_reg;
2667               xoperands[1] = XEXP (addr, 1);
2668               xoperands[2] = XEXP (XEXP (addr, 0), 0);
2669               xoperands[3] = XEXP (XEXP (addr, 0), 1);
2670               output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2671                                xoperands);
2672               return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2673             }
2674           else
2675             {
2676               rtx xoperands[3];
2677
2678               xoperands[0] = high_reg;
2679               xoperands[1] = XEXP (addr, 1);
2680               xoperands[2] = XEXP (XEXP (addr, 0), 0);
2681               xoperands[3] = XEXP (XEXP (addr, 0), 1);
2682               output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2683                                xoperands);
2684               return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2685             }
2686         }
2687     }
2688
2689   /* If an operand is an unoffsettable memory ref, find a register
2690      we can increment temporarily to make it refer to the second word.  */
2691
2692   if (optype0 == MEMOP)
2693     addreg0 = find_addr_reg (XEXP (operands[0], 0));
2694
2695   if (optype1 == MEMOP)
2696     addreg1 = find_addr_reg (XEXP (operands[1], 0));
2697
2698   /* Ok, we can do one word at a time.
2699      Normally we do the low-numbered word first.
2700
2701      In either case, set up in LATEHALF the operands to use
2702      for the high-numbered word and in some cases alter the
2703      operands in OPERANDS to be suitable for the low-numbered word.  */
2704
2705   if (optype0 == REGOP)
2706     latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2707   else if (optype0 == OFFSOP)
2708     latehalf[0] = adjust_address (operands[0], SImode, 4);
2709   else
2710     latehalf[0] = operands[0];
2711
2712   if (optype1 == REGOP)
2713     latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2714   else if (optype1 == OFFSOP)
2715     latehalf[1] = adjust_address (operands[1], SImode, 4);
2716   else if (optype1 == CNSTOP)
2717     split_double (operands[1], &operands[1], &latehalf[1]);
2718   else
2719     latehalf[1] = operands[1];
2720
2721   /* If the first move would clobber the source of the second one,
2722      do them in the other order.
2723
2724      This can happen in two cases:
2725
2726         mem -> register where the first half of the destination register
2727         is the same register used in the memory's address.  Reload
2728         can create such insns.
2729
2730         mem in this case will be either register indirect or register
2731         indirect plus a valid offset.
2732
2733         register -> register move where REGNO(dst) == REGNO(src + 1)
2734         someone (Tim/Tege?) claimed this can happen for parameter loads.
2735
2736      Handle mem -> register case first.  */
2737   if (optype0 == REGOP
2738       && (optype1 == MEMOP || optype1 == OFFSOP)
2739       && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2740                             operands[1], 0))
2741     {
2742       /* Do the late half first.  */
2743       if (addreg1)
2744         output_asm_insn ("ldo 4(%0),%0", &addreg1);
2745       output_asm_insn (singlemove_string (latehalf), latehalf);
2746
2747       /* Then clobber.  */
2748       if (addreg1)
2749         output_asm_insn ("ldo -4(%0),%0", &addreg1);
2750       return singlemove_string (operands);
2751     }
2752
2753   /* Now handle register -> register case.  */
2754   if (optype0 == REGOP && optype1 == REGOP
2755       && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2756     {
2757       output_asm_insn (singlemove_string (latehalf), latehalf);
2758       return singlemove_string (operands);
2759     }
2760
2761   /* Normal case: do the two words, low-numbered first.  */
2762
2763   output_asm_insn (singlemove_string (operands), operands);
2764
2765   /* Make any unoffsettable addresses point at high-numbered word.  */
2766   if (addreg0)
2767     output_asm_insn ("ldo 4(%0),%0", &addreg0);
2768   if (addreg1)
2769     output_asm_insn ("ldo 4(%0),%0", &addreg1);
2770
2771   /* Do that word.  */
2772   output_asm_insn (singlemove_string (latehalf), latehalf);
2773
2774   /* Undo the adds we just did.  */
2775   if (addreg0)
2776     output_asm_insn ("ldo -4(%0),%0", &addreg0);
2777   if (addreg1)
2778     output_asm_insn ("ldo -4(%0),%0", &addreg1);
2779
2780   return "";
2781 }
2782 \f
2783 const char *
2784 output_fp_move_double (rtx *operands)
2785 {
2786   if (FP_REG_P (operands[0]))
2787     {
2788       if (FP_REG_P (operands[1])
2789           || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2790         output_asm_insn ("fcpy,dbl %f1,%0", operands);
2791       else
2792         output_asm_insn ("fldd%F1 %1,%0", operands);
2793     }
2794   else if (FP_REG_P (operands[1]))
2795     {
2796       output_asm_insn ("fstd%F0 %1,%0", operands);
2797     }
2798   else if (operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2799     {
2800       if (GET_CODE (operands[0]) == REG)
2801         {
2802           rtx xoperands[2];
2803           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2804           xoperands[0] = operands[0];
2805           output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2806         }
2807       /* This is a pain.  You have to be prepared to deal with an
2808          arbitrary address here including pre/post increment/decrement.
2809
2810          so avoid this in the MD.  */
2811       else
2812         abort ();
2813     }
2814   else abort ();
2815   return "";
2816 }
2817 \f
2818 /* Return a REG that occurs in ADDR with coefficient 1.
2819    ADDR can be effectively incremented by incrementing REG.  */
2820
2821 static rtx
2822 find_addr_reg (rtx addr)
2823 {
2824   while (GET_CODE (addr) == PLUS)
2825     {
2826       if (GET_CODE (XEXP (addr, 0)) == REG)
2827         addr = XEXP (addr, 0);
2828       else if (GET_CODE (XEXP (addr, 1)) == REG)
2829         addr = XEXP (addr, 1);
2830       else if (CONSTANT_P (XEXP (addr, 0)))
2831         addr = XEXP (addr, 1);
2832       else if (CONSTANT_P (XEXP (addr, 1)))
2833         addr = XEXP (addr, 0);
2834       else
2835         abort ();
2836     }
2837   if (GET_CODE (addr) == REG)
2838     return addr;
2839   abort ();
2840 }
2841
2842 /* Emit code to perform a block move.
2843
2844    OPERANDS[0] is the destination pointer as a REG, clobbered.
2845    OPERANDS[1] is the source pointer as a REG, clobbered.
2846    OPERANDS[2] is a register for temporary storage.
2847    OPERANDS[3] is a register for temporary storage.
2848    OPERANDS[4] is the size as a CONST_INT
2849    OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2850    OPERANDS[6] is another temporary register.  */
2851
2852 const char *
2853 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2854 {
2855   int align = INTVAL (operands[5]);
2856   unsigned long n_bytes = INTVAL (operands[4]);
2857
2858   /* We can't move more than a word at a time because the PA
2859      has no longer integer move insns.  (Could use fp mem ops?)  */
2860   if (align > (TARGET_64BIT ? 8 : 4))
2861     align = (TARGET_64BIT ? 8 : 4);
2862
2863   /* Note that we know each loop below will execute at least twice
2864      (else we would have open-coded the copy).  */
2865   switch (align)
2866     {
2867       case 8:
2868         /* Pre-adjust the loop counter.  */
2869         operands[4] = GEN_INT (n_bytes - 16);
2870         output_asm_insn ("ldi %4,%2", operands);
2871
2872         /* Copying loop.  */
2873         output_asm_insn ("ldd,ma 8(%1),%3", operands);
2874         output_asm_insn ("ldd,ma 8(%1),%6", operands);
2875         output_asm_insn ("std,ma %3,8(%0)", operands);
2876         output_asm_insn ("addib,>= -16,%2,.-12", operands);
2877         output_asm_insn ("std,ma %6,8(%0)", operands);
2878
2879         /* Handle the residual.  There could be up to 7 bytes of
2880            residual to copy!  */
2881         if (n_bytes % 16 != 0)
2882           {
2883             operands[4] = GEN_INT (n_bytes % 8);
2884             if (n_bytes % 16 >= 8)
2885               output_asm_insn ("ldd,ma 8(%1),%3", operands);
2886             if (n_bytes % 8 != 0)
2887               output_asm_insn ("ldd 0(%1),%6", operands);
2888             if (n_bytes % 16 >= 8)
2889               output_asm_insn ("std,ma %3,8(%0)", operands);
2890             if (n_bytes % 8 != 0)
2891               output_asm_insn ("stdby,e %6,%4(%0)", operands);
2892           }
2893         return "";
2894
2895       case 4:
2896         /* Pre-adjust the loop counter.  */
2897         operands[4] = GEN_INT (n_bytes - 8);
2898         output_asm_insn ("ldi %4,%2", operands);
2899
2900         /* Copying loop.  */
2901         output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2902         output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2903         output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2904         output_asm_insn ("addib,>= -8,%2,.-12", operands);
2905         output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2906
2907         /* Handle the residual.  There could be up to 7 bytes of
2908            residual to copy!  */
2909         if (n_bytes % 8 != 0)
2910           {
2911             operands[4] = GEN_INT (n_bytes % 4);
2912             if (n_bytes % 8 >= 4)
2913               output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2914             if (n_bytes % 4 != 0)
2915               output_asm_insn ("ldw 0(%1),%6", operands);
2916             if (n_bytes % 8 >= 4)
2917               output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2918             if (n_bytes % 4 != 0)
2919               output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2920           }
2921         return "";
2922
2923       case 2:
2924         /* Pre-adjust the loop counter.  */
2925         operands[4] = GEN_INT (n_bytes - 4);
2926         output_asm_insn ("ldi %4,%2", operands);
2927
2928         /* Copying loop.  */
2929         output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2930         output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2931         output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2932         output_asm_insn ("addib,>= -4,%2,.-12", operands);
2933         output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2934
2935         /* Handle the residual.  */
2936         if (n_bytes % 4 != 0)
2937           {
2938             if (n_bytes % 4 >= 2)
2939               output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2940             if (n_bytes % 2 != 0)
2941               output_asm_insn ("ldb 0(%1),%6", operands);
2942             if (n_bytes % 4 >= 2)
2943               output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2944             if (n_bytes % 2 != 0)
2945               output_asm_insn ("stb %6,0(%0)", operands);
2946           }
2947         return "";
2948
2949       case 1:
2950         /* Pre-adjust the loop counter.  */
2951         operands[4] = GEN_INT (n_bytes - 2);
2952         output_asm_insn ("ldi %4,%2", operands);
2953
2954         /* Copying loop.  */
2955         output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2956         output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2957         output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2958         output_asm_insn ("addib,>= -2,%2,.-12", operands);
2959         output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2960
2961         /* Handle the residual.  */
2962         if (n_bytes % 2 != 0)
2963           {
2964             output_asm_insn ("ldb 0(%1),%3", operands);
2965             output_asm_insn ("stb %3,0(%0)", operands);
2966           }
2967         return "";
2968
2969       default:
2970         abort ();
2971     }
2972 }
2973
2974 /* Count the number of insns necessary to handle this block move.
2975
2976    Basic structure is the same as emit_block_move, except that we
2977    count insns rather than emit them.  */
2978
2979 static int
2980 compute_movmem_length (rtx insn)
2981 {
2982   rtx pat = PATTERN (insn);
2983   unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2984   unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2985   unsigned int n_insns = 0;
2986
2987   /* We can't move more than four bytes at a time because the PA
2988      has no longer integer move insns.  (Could use fp mem ops?)  */
2989   if (align > (TARGET_64BIT ? 8 : 4))
2990     align = (TARGET_64BIT ? 8 : 4);
2991
2992   /* The basic copying loop.  */
2993   n_insns = 6;
2994
2995   /* Residuals.  */
2996   if (n_bytes % (2 * align) != 0)
2997     {
2998       if ((n_bytes % (2 * align)) >= align)
2999         n_insns += 2;
3000
3001       if ((n_bytes % align) != 0)
3002         n_insns += 2;
3003     }
3004
3005   /* Lengths are expressed in bytes now; each insn is 4 bytes.  */
3006   return n_insns * 4;
3007 }
3008
3009 /* Emit code to perform a block clear.
3010
3011    OPERANDS[0] is the destination pointer as a REG, clobbered.
3012    OPERANDS[1] is a register for temporary storage.
3013    OPERANDS[2] is the size as a CONST_INT
3014    OPERANDS[3] is the alignment safe to use, as a CONST_INT.  */
3015
3016 const char *
3017 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
3018 {
3019   int align = INTVAL (operands[3]);
3020   unsigned long n_bytes = INTVAL (operands[2]);
3021
3022   /* We can't clear more than a word at a time because the PA
3023      has no longer integer move insns.  */
3024   if (align > (TARGET_64BIT ? 8 : 4))
3025     align = (TARGET_64BIT ? 8 : 4);
3026
3027   /* Note that we know each loop below will execute at least twice
3028      (else we would have open-coded the copy).  */
3029   switch (align)
3030     {
3031       case 8:
3032         /* Pre-adjust the loop counter.  */
3033         operands[2] = GEN_INT (n_bytes - 16);
3034         output_asm_insn ("ldi %2,%1", operands);
3035
3036         /* Loop.  */
3037         output_asm_insn ("std,ma %%r0,8(%0)", operands);
3038         output_asm_insn ("addib,>= -16,%1,.-4", operands);
3039         output_asm_insn ("std,ma %%r0,8(%0)", operands);
3040
3041         /* Handle the residual.  There could be up to 7 bytes of
3042            residual to copy!  */
3043         if (n_bytes % 16 != 0)
3044           {
3045             operands[2] = GEN_INT (n_bytes % 8);
3046             if (n_bytes % 16 >= 8)
3047               output_asm_insn ("std,ma %%r0,8(%0)", operands);
3048             if (n_bytes % 8 != 0)
3049               output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
3050           }
3051         return "";
3052
3053       case 4:
3054         /* Pre-adjust the loop counter.  */
3055         operands[2] = GEN_INT (n_bytes - 8);
3056         output_asm_insn ("ldi %2,%1", operands);
3057
3058         /* Loop.  */
3059         output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3060         output_asm_insn ("addib,>= -8,%1,.-4", operands);
3061         output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3062
3063         /* Handle the residual.  There could be up to 7 bytes of
3064            residual to copy!  */
3065         if (n_bytes % 8 != 0)
3066           {
3067             operands[2] = GEN_INT (n_bytes % 4);
3068             if (n_bytes % 8 >= 4)
3069               output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3070             if (n_bytes % 4 != 0)
3071               output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
3072           }
3073         return "";
3074
3075       case 2:
3076         /* Pre-adjust the loop counter.  */
3077         operands[2] = GEN_INT (n_bytes - 4);
3078         output_asm_insn ("ldi %2,%1", operands);
3079
3080         /* Loop.  */
3081         output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3082         output_asm_insn ("addib,>= -4,%1,.-4", operands);
3083         output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3084
3085         /* Handle the residual.  */
3086         if (n_bytes % 4 != 0)
3087           {
3088             if (n_bytes % 4 >= 2)
3089               output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3090             if (n_bytes % 2 != 0)
3091               output_asm_insn ("stb %%r0,0(%0)", operands);
3092           }
3093         return "";
3094
3095       case 1:
3096         /* Pre-adjust the loop counter.  */
3097         operands[2] = GEN_INT (n_bytes - 2);
3098         output_asm_insn ("ldi %2,%1", operands);
3099
3100         /* Loop.  */
3101         output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3102         output_asm_insn ("addib,>= -2,%1,.-4", operands);
3103         output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3104
3105         /* Handle the residual.  */
3106         if (n_bytes % 2 != 0)
3107           output_asm_insn ("stb %%r0,0(%0)", operands);
3108
3109         return "";
3110
3111       default:
3112         abort ();
3113     }
3114 }
3115
3116 /* Count the number of insns necessary to handle this block move.
3117
3118    Basic structure is the same as emit_block_move, except that we
3119    count insns rather than emit them.  */
3120
3121 static int
3122 compute_clrmem_length (rtx insn)
3123 {
3124   rtx pat = PATTERN (insn);
3125   unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
3126   unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
3127   unsigned int n_insns = 0;
3128
3129   /* We can't clear more than a word at a time because the PA
3130      has no longer integer move insns.  */
3131   if (align > (TARGET_64BIT ? 8 : 4))
3132     align = (TARGET_64BIT ? 8 : 4);
3133
3134   /* The basic loop.  */
3135   n_insns = 4;
3136
3137   /* Residuals.  */
3138   if (n_bytes % (2 * align) != 0)
3139     {
3140       if ((n_bytes % (2 * align)) >= align)
3141         n_insns++;
3142
3143       if ((n_bytes % align) != 0)
3144         n_insns++;
3145     }
3146
3147   /* Lengths are expressed in bytes now; each insn is 4 bytes.  */
3148   return n_insns * 4;
3149 }
3150 \f
3151
3152 const char *
3153 output_and (rtx *operands)
3154 {
3155   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3156     {
3157       unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3158       int ls0, ls1, ms0, p, len;
3159
3160       for (ls0 = 0; ls0 < 32; ls0++)
3161         if ((mask & (1 << ls0)) == 0)
3162           break;
3163
3164       for (ls1 = ls0; ls1 < 32; ls1++)
3165         if ((mask & (1 << ls1)) != 0)
3166           break;
3167
3168       for (ms0 = ls1; ms0 < 32; ms0++)
3169         if ((mask & (1 << ms0)) == 0)
3170           break;
3171
3172       if (ms0 != 32)
3173         abort ();
3174
3175       if (ls1 == 32)
3176         {
3177           len = ls0;
3178
3179           if (len == 0)
3180             abort ();
3181
3182           operands[2] = GEN_INT (len);
3183           return "{extru|extrw,u} %1,31,%2,%0";
3184         }
3185       else
3186         {
3187           /* We could use this `depi' for the case above as well, but `depi'
3188              requires one more register file access than an `extru'.  */
3189
3190           p = 31 - ls0;
3191           len = ls1 - ls0;
3192
3193           operands[2] = GEN_INT (p);
3194           operands[3] = GEN_INT (len);
3195           return "{depi|depwi} 0,%2,%3,%0";
3196         }
3197     }
3198   else
3199     return "and %1,%2,%0";
3200 }
3201
3202 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3203    storing the result in operands[0].  */
3204 const char *
3205 output_64bit_and (rtx *operands)
3206 {
3207   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3208     {
3209       unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3210       int ls0, ls1, ms0, p, len;
3211
3212       for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
3213         if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
3214           break;
3215
3216       for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
3217         if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
3218           break;
3219
3220       for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
3221         if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
3222           break;
3223
3224       if (ms0 != HOST_BITS_PER_WIDE_INT)
3225         abort ();
3226
3227       if (ls1 == HOST_BITS_PER_WIDE_INT)
3228         {
3229           len = ls0;
3230
3231           if (len == 0)
3232             abort ();
3233
3234           operands[2] = GEN_INT (len);
3235           return "extrd,u %1,63,%2,%0";
3236         }
3237       else
3238         {
3239           /* We could use this `depi' for the case above as well, but `depi'
3240              requires one more register file access than an `extru'.  */
3241
3242           p = 63 - ls0;
3243           len = ls1 - ls0;
3244
3245           operands[2] = GEN_INT (p);
3246           operands[3] = GEN_INT (len);
3247           return "depdi 0,%2,%3,%0";
3248         }
3249     }
3250   else
3251     return "and %1,%2,%0";
3252 }
3253
3254 const char *
3255 output_ior (rtx *operands)
3256 {
3257   unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3258   int bs0, bs1, p, len;
3259
3260   if (INTVAL (operands[2]) == 0)
3261     return "copy %1,%0";
3262
3263   for (bs0 = 0; bs0 < 32; bs0++)
3264     if ((mask & (1 << bs0)) != 0)
3265       break;
3266
3267   for (bs1 = bs0; bs1 < 32; bs1++)
3268     if ((mask & (1 << bs1)) == 0)
3269       break;
3270
3271   if (bs1 != 32 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3272     abort ();
3273
3274   p = 31 - bs0;
3275   len = bs1 - bs0;
3276
3277   operands[2] = GEN_INT (p);
3278   operands[3] = GEN_INT (len);
3279   return "{depi|depwi} -1,%2,%3,%0";
3280 }
3281
3282 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3283    storing the result in operands[0].  */
3284 const char *
3285 output_64bit_ior (rtx *operands)
3286 {
3287   unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3288   int bs0, bs1, p, len;
3289
3290   if (INTVAL (operands[2]) == 0)
3291     return "copy %1,%0";
3292
3293   for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3294     if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3295       break;
3296
3297   for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3298     if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3299       break;
3300
3301   if (bs1 != HOST_BITS_PER_WIDE_INT
3302       && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3303     abort ();
3304
3305   p = 63 - bs0;
3306   len = bs1 - bs0;
3307
3308   operands[2] = GEN_INT (p);
3309   operands[3] = GEN_INT (len);
3310   return "depdi -1,%2,%3,%0";
3311 }
3312 \f
3313 /* Target hook for assembling integer objects.  This code handles
3314    aligned SI and DI integers specially, since function references must
3315    be preceded by P%.  */
3316
3317 static bool
3318 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3319 {
3320   if (size == UNITS_PER_WORD && aligned_p
3321       && function_label_operand (x, VOIDmode))
3322     {
3323       fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
3324       output_addr_const (asm_out_file, x);
3325       fputc ('\n', asm_out_file);
3326       return true;
3327     }
3328   return default_assemble_integer (x, size, aligned_p);
3329 }
3330 \f
3331 /* Output an ascii string.  */
3332 void
3333 output_ascii (FILE *file, const char *p, int size)
3334 {
3335   int i;
3336   int chars_output;
3337   unsigned char partial_output[16];     /* Max space 4 chars can occupy.  */
3338
3339   /* The HP assembler can only take strings of 256 characters at one
3340      time.  This is a limitation on input line length, *not* the
3341      length of the string.  Sigh.  Even worse, it seems that the
3342      restriction is in number of input characters (see \xnn &
3343      \whatever).  So we have to do this very carefully.  */
3344
3345   fputs ("\t.STRING \"", file);
3346
3347   chars_output = 0;
3348   for (i = 0; i < size; i += 4)
3349     {
3350       int co = 0;
3351       int io = 0;
3352       for (io = 0, co = 0; io < MIN (4, size - i); io++)
3353         {
3354           register unsigned int c = (unsigned char) p[i + io];
3355
3356           if (c == '\"' || c == '\\')
3357             partial_output[co++] = '\\';
3358           if (c >= ' ' && c < 0177)
3359             partial_output[co++] = c;
3360           else
3361             {
3362               unsigned int hexd;
3363               partial_output[co++] = '\\';
3364               partial_output[co++] = 'x';
3365               hexd =  c  / 16 - 0 + '0';
3366               if (hexd > '9')
3367                 hexd -= '9' - 'a' + 1;
3368               partial_output[co++] = hexd;
3369               hexd =  c % 16 - 0 + '0';
3370               if (hexd > '9')
3371                 hexd -= '9' - 'a' + 1;
3372               partial_output[co++] = hexd;
3373             }
3374         }
3375       if (chars_output + co > 243)
3376         {
3377           fputs ("\"\n\t.STRING \"", file);
3378           chars_output = 0;
3379         }
3380       fwrite (partial_output, 1, (size_t) co, file);
3381       chars_output += co;
3382       co = 0;
3383     }
3384   fputs ("\"\n", file);
3385 }
3386
3387 /* Try to rewrite floating point comparisons & branches to avoid
3388    useless add,tr insns.
3389
3390    CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3391    to see if FPCC is dead.  CHECK_NOTES is nonzero for the
3392    first attempt to remove useless add,tr insns.  It is zero
3393    for the second pass as reorg sometimes leaves bogus REG_DEAD
3394    notes lying around.
3395
3396    When CHECK_NOTES is zero we can only eliminate add,tr insns
3397    when there's a 1:1 correspondence between fcmp and ftest/fbranch
3398    instructions.  */
3399 static void
3400 remove_useless_addtr_insns (int check_notes)
3401 {
3402   rtx insn;
3403   static int pass = 0;
3404
3405   /* This is fairly cheap, so always run it when optimizing.  */
3406   if (optimize > 0)
3407     {
3408       int fcmp_count = 0;
3409       int fbranch_count = 0;
3410
3411       /* Walk all the insns in this function looking for fcmp & fbranch
3412          instructions.  Keep track of how many of each we find.  */
3413       for (insn = get_insns (); insn; insn = next_insn (insn))
3414         {
3415           rtx tmp;
3416
3417           /* Ignore anything that isn't an INSN or a JUMP_INSN.  */
3418           if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3419             continue;
3420
3421           tmp = PATTERN (insn);
3422
3423           /* It must be a set.  */
3424           if (GET_CODE (tmp) != SET)
3425             continue;
3426
3427           /* If the destination is CCFP, then we've found an fcmp insn.  */
3428           tmp = SET_DEST (tmp);
3429           if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3430             {
3431               fcmp_count++;
3432               continue;
3433             }
3434
3435           tmp = PATTERN (insn);
3436           /* If this is an fbranch instruction, bump the fbranch counter.  */
3437           if (GET_CODE (tmp) == SET
3438               && SET_DEST (tmp) == pc_rtx
3439               && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3440               && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3441               && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3442               && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3443             {
3444               fbranch_count++;
3445               continue;
3446             }
3447         }
3448
3449
3450       /* Find all floating point compare + branch insns.  If possible,
3451          reverse the comparison & the branch to avoid add,tr insns.  */
3452       for (insn = get_insns (); insn; insn = next_insn (insn))
3453         {
3454           rtx tmp, next;
3455
3456           /* Ignore anything that isn't an INSN.  */
3457           if (GET_CODE (insn) != INSN)
3458             continue;
3459
3460           tmp = PATTERN (insn);
3461
3462           /* It must be a set.  */
3463           if (GET_CODE (tmp) != SET)
3464             continue;
3465
3466           /* The destination must be CCFP, which is register zero.  */
3467           tmp = SET_DEST (tmp);
3468           if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3469             continue;
3470
3471           /* INSN should be a set of CCFP.
3472
3473              See if the result of this insn is used in a reversed FP
3474              conditional branch.  If so, reverse our condition and
3475              the branch.  Doing so avoids useless add,tr insns.  */
3476           next = next_insn (insn);
3477           while (next)
3478             {
3479               /* Jumps, calls and labels stop our search.  */
3480               if (GET_CODE (next) == JUMP_INSN
3481                   || GET_CODE (next) == CALL_INSN
3482                   || GET_CODE (next) == CODE_LABEL)
3483                 break;
3484
3485               /* As does another fcmp insn.  */
3486               if (GET_CODE (next) == INSN
3487                   && GET_CODE (PATTERN (next)) == SET
3488                   && GET_CODE (SET_DEST (PATTERN (next))) == REG
3489                   && REGNO (SET_DEST (PATTERN (next))) == 0)
3490                 break;
3491
3492               next = next_insn (next);
3493             }
3494
3495           /* Is NEXT_INSN a branch?  */
3496           if (next
3497               && GET_CODE (next) == JUMP_INSN)
3498             {
3499               rtx pattern = PATTERN (next);
3500
3501               /* If it a reversed fp conditional branch (e.g. uses add,tr)
3502                  and CCFP dies, then reverse our conditional and the branch
3503                  to avoid the add,tr.  */
3504               if (GET_CODE (pattern) == SET
3505                   && SET_DEST (pattern) == pc_rtx
3506                   && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3507                   && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3508                   && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3509                   && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3510                   && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3511                   && (fcmp_count == fbranch_count
3512                       || (check_notes
3513                           && find_regno_note (next, REG_DEAD, 0))))
3514                 {
3515                   /* Reverse the branch.  */
3516                   tmp = XEXP (SET_SRC (pattern), 1);
3517                   XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3518                   XEXP (SET_SRC (pattern), 2) = tmp;
3519                   INSN_CODE (next) = -1;
3520
3521                   /* Reverse our condition.  */
3522                   tmp = PATTERN (insn);
3523                   PUT_CODE (XEXP (tmp, 1),
3524                             (reverse_condition_maybe_unordered
3525                              (GET_CODE (XEXP (tmp, 1)))));
3526                 }
3527             }
3528         }
3529     }
3530
3531   pass = !pass;
3532
3533 }
3534 \f
3535 /* You may have trouble believing this, but this is the 32 bit HP-PA
3536    stack layout.  Wow.
3537
3538    Offset               Contents
3539
3540    Variable arguments   (optional; any number may be allocated)
3541
3542    SP-(4*(N+9))         arg word N
3543         :                   :
3544       SP-56             arg word 5
3545       SP-52             arg word 4
3546
3547    Fixed arguments      (must be allocated; may remain unused)
3548
3549       SP-48             arg word 3
3550       SP-44             arg word 2
3551       SP-40             arg word 1
3552       SP-36             arg word 0
3553
3554    Frame Marker
3555
3556       SP-32             External Data Pointer (DP)
3557       SP-28             External sr4
3558       SP-24             External/stub RP (RP')
3559       SP-20             Current RP
3560       SP-16             Static Link
3561       SP-12             Clean up
3562       SP-8              Calling Stub RP (RP'')
3563       SP-4              Previous SP
3564
3565    Top of Frame
3566
3567       SP-0              Stack Pointer (points to next available address)
3568
3569 */
3570
3571 /* This function saves registers as follows.  Registers marked with ' are
3572    this function's registers (as opposed to the previous function's).
3573    If a frame_pointer isn't needed, r4 is saved as a general register;
3574    the space for the frame pointer is still allocated, though, to keep
3575    things simple.
3576
3577
3578    Top of Frame
3579
3580        SP (FP')         Previous FP
3581        SP + 4           Alignment filler (sigh)
3582        SP + 8           Space for locals reserved here.
3583        .
3584        .
3585        .
3586        SP + n           All call saved register used.
3587        .
3588        .
3589        .
3590        SP + o           All call saved fp registers used.
3591        .
3592        .
3593        .
3594        SP + p (SP')     points to next available address.
3595
3596 */
3597
3598 /* Global variables set by output_function_prologue().  */
3599 /* Size of frame.  Need to know this to emit return insns from
3600    leaf procedures.  */
3601 static HOST_WIDE_INT actual_fsize, local_fsize;
3602 static int save_fregs;
3603
3604 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3605    Handle case where DISP > 8k by using the add_high_const patterns.
3606
3607    Note in DISP > 8k case, we will leave the high part of the address
3608    in %r1.  There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3609
3610 static void
3611 store_reg (int reg, HOST_WIDE_INT disp, int base)
3612 {
3613   rtx insn, dest, src, basereg;
3614
3615   src = gen_rtx_REG (word_mode, reg);
3616   basereg = gen_rtx_REG (Pmode, base);
3617   if (VAL_14_BITS_P (disp))
3618     {
3619       dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3620       insn = emit_move_insn (dest, src);
3621     }
3622   else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3623     {
3624       rtx delta = GEN_INT (disp);
3625       rtx tmpreg = gen_rtx_REG (Pmode, 1);
3626
3627       emit_move_insn (tmpreg, delta);
3628       emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3629       dest = gen_rtx_MEM (word_mode, tmpreg);
3630       insn = emit_move_insn (dest, src);
3631       if (DO_FRAME_NOTES)
3632         {
3633           REG_NOTES (insn)
3634             = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3635                 gen_rtx_SET (VOIDmode,
3636                              gen_rtx_MEM (word_mode,
3637                                           gen_rtx_PLUS (word_mode, basereg,
3638                                                         delta)),
3639                              src),
3640                 REG_NOTES (insn));
3641         }
3642     }
3643   else
3644     {
3645       rtx delta = GEN_INT (disp);
3646       rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3647       rtx tmpreg = gen_rtx_REG (Pmode, 1);
3648
3649       emit_move_insn (tmpreg, high);
3650       dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3651       insn = emit_move_insn (dest, src);
3652       if (DO_FRAME_NOTES)
3653         {
3654           REG_NOTES (insn)
3655             = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3656                 gen_rtx_SET (VOIDmode,
3657                              gen_rtx_MEM (word_mode,
3658                                           gen_rtx_PLUS (word_mode, basereg,
3659                                                         delta)),
3660                              src),
3661                 REG_NOTES (insn));
3662         }
3663     }
3664
3665   if (DO_FRAME_NOTES)
3666     RTX_FRAME_RELATED_P (insn) = 1;
3667 }
3668
3669 /* Emit RTL to store REG at the memory location specified by BASE and then
3670    add MOD to BASE.  MOD must be <= 8k.  */
3671
3672 static void
3673 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3674 {
3675   rtx insn, basereg, srcreg, delta;
3676
3677   if (!VAL_14_BITS_P (mod))
3678     abort ();
3679
3680   basereg = gen_rtx_REG (Pmode, base);
3681   srcreg = gen_rtx_REG (word_mode, reg);
3682   delta = GEN_INT (mod);
3683
3684   insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3685   if (DO_FRAME_NOTES)
3686     {
3687       RTX_FRAME_RELATED_P (insn) = 1;
3688
3689       /* RTX_FRAME_RELATED_P must be set on each frame related set
3690          in a parallel with more than one element.  Don't set
3691          RTX_FRAME_RELATED_P in the first set if reg is temporary
3692          register 1. The effect of this operation is recorded in
3693          the initial copy.  */
3694       if (reg != 1)
3695         {
3696           RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3697           RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3698         }
3699       else
3700         {
3701           /* The first element of a PARALLEL is always processed if it is
3702              a SET.  Thus, we need an expression list for this case.  */
3703           REG_NOTES (insn)
3704             = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3705                 gen_rtx_SET (VOIDmode, basereg,
3706                              gen_rtx_PLUS (word_mode, basereg, delta)),
3707                 REG_NOTES (insn));
3708         }
3709     }
3710 }
3711
3712 /* Emit RTL to set REG to the value specified by BASE+DISP.  Handle case
3713    where DISP > 8k by using the add_high_const patterns.  NOTE indicates
3714    whether to add a frame note or not.
3715
3716    In the DISP > 8k case, we leave the high part of the address in %r1.
3717    There is code in expand_hppa_{prologue,epilogue} that knows about this.  */
3718
3719 static void
3720 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3721 {
3722   rtx insn;
3723
3724   if (VAL_14_BITS_P (disp))
3725     {
3726       insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3727                              plus_constant (gen_rtx_REG (Pmode, base), disp));
3728     }
3729   else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3730     {
3731       rtx basereg = gen_rtx_REG (Pmode, base);
3732       rtx delta = GEN_INT (disp);
3733       rtx tmpreg = gen_rtx_REG (Pmode, 1);
3734
3735       emit_move_insn (tmpreg, delta);
3736       insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3737                              gen_rtx_PLUS (Pmode, tmpreg, basereg));
3738     }
3739   else
3740     {
3741       rtx basereg = gen_rtx_REG (Pmode, base);
3742       rtx delta = GEN_INT (disp);
3743       rtx tmpreg = gen_rtx_REG (Pmode, 1);
3744
3745       emit_move_insn (tmpreg,
3746                       gen_rtx_PLUS (Pmode, basereg,
3747                                     gen_rtx_HIGH (Pmode, delta)));
3748       insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3749                              gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3750     }
3751
3752   if (DO_FRAME_NOTES && note)
3753     RTX_FRAME_RELATED_P (insn) = 1;
3754 }
3755
3756 HOST_WIDE_INT
3757 compute_frame_size (HOST_WIDE_INT size, int *fregs_live)
3758 {
3759   int freg_saved = 0;
3760   int i, j;
3761
3762   /* The code in hppa_expand_prologue and hppa_expand_epilogue must
3763      be consistent with the rounding and size calculation done here.
3764      Change them at the same time.  */
3765
3766   /* We do our own stack alignment.  First, round the size of the
3767      stack locals up to a word boundary.  */
3768   size = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3769
3770   /* Space for previous frame pointer + filler.  If any frame is
3771      allocated, we need to add in the STARTING_FRAME_OFFSET.  We
3772      waste some space here for the sake of HP compatibility.  The
3773      first slot is only used when the frame pointer is needed.  */
3774   if (size || frame_pointer_needed)
3775     size += STARTING_FRAME_OFFSET;
3776   
3777   /* If the current function calls __builtin_eh_return, then we need
3778      to allocate stack space for registers that will hold data for
3779      the exception handler.  */
3780   if (DO_FRAME_NOTES && current_function_calls_eh_return)
3781     {
3782       unsigned int i;
3783
3784       for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
3785         continue;
3786       size += i * UNITS_PER_WORD;
3787     }
3788
3789   /* Account for space used by the callee general register saves.  */
3790   for (i = 18, j = frame_pointer_needed ? 4 : 3; i >= j; i--)
3791     if (regs_ever_live[i])
3792       size += UNITS_PER_WORD;
3793
3794   /* Account for space used by the callee floating point register saves.  */
3795   for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3796     if (regs_ever_live[i]
3797         || (!TARGET_64BIT && regs_ever_live[i + 1]))
3798       {
3799         freg_saved = 1;
3800
3801         /* We always save both halves of the FP register, so always
3802            increment the frame size by 8 bytes.  */
3803         size += 8;
3804       }
3805
3806   /* If any of the floating registers are saved, account for the
3807      alignment needed for the floating point register save block.  */
3808   if (freg_saved)
3809     {
3810       size = (size + 7) & ~7;
3811       if (fregs_live)
3812         *fregs_live = 1;
3813     }
3814
3815   /* The various ABIs include space for the outgoing parameters in the
3816      size of the current function's stack frame.  We don't need to align
3817      for the outgoing arguments as their alignment is set by the final
3818      rounding for the frame as a whole.  */
3819   size += current_function_outgoing_args_size;
3820
3821   /* Allocate space for the fixed frame marker.  This space must be
3822      allocated for any function that makes calls or allocates
3823      stack space.  */
3824   if (!current_function_is_leaf || size)
3825     size += TARGET_64BIT ? 48 : 32;
3826
3827   /* Finally, round to the preferred stack boundary.  */
3828   return ((size + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)
3829           & ~(PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1));
3830 }
3831
3832 /* Generate the assembly code for function entry.  FILE is a stdio
3833    stream to output the code to.  SIZE is an int: how many units of
3834    temporary storage to allocate.
3835
3836    Refer to the array `regs_ever_live' to determine which registers to
3837    save; `regs_ever_live[I]' is nonzero if register number I is ever
3838    used in the function.  This function is responsible for knowing
3839    which registers should not be saved even if used.  */
3840
3841 /* On HP-PA, move-double insns between fpu and cpu need an 8-byte block
3842    of memory.  If any fpu reg is used in the function, we allocate
3843    such a block here, at the bottom of the frame, just in case it's needed.
3844
3845    If this function is a leaf procedure, then we may choose not
3846    to do a "save" insn.  The decision about whether or not
3847    to do this is made in regclass.c.  */
3848
3849 static void
3850 pa_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3851 {
3852   /* The function's label and associated .PROC must never be
3853      separated and must be output *after* any profiling declarations
3854      to avoid changing spaces/subspaces within a procedure.  */
3855   ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3856   fputs ("\t.PROC\n", file);
3857
3858   /* hppa_expand_prologue does the dirty work now.  We just need
3859      to output the assembler directives which denote the start
3860      of a function.  */
3861   fprintf (file, "\t.CALLINFO FRAME=" HOST_WIDE_INT_PRINT_DEC, actual_fsize);
3862   if (regs_ever_live[2])
3863     fputs (",CALLS,SAVE_RP", file);
3864   else
3865     fputs (",NO_CALLS", file);
3866
3867   /* The SAVE_SP flag is used to indicate that register %r3 is stored
3868      at the beginning of the frame and that it is used as the frame
3869      pointer for the frame.  We do this because our current frame
3870      layout doesn't conform to that specified in the the HP runtime
3871      documentation and we need a way to indicate to programs such as
3872      GDB where %r3 is saved.  The SAVE_SP flag was chosen because it
3873      isn't used by HP compilers but is supported by the assembler.
3874      However, SAVE_SP is supposed to indicate that the previous stack
3875      pointer has been saved in the frame marker.  */
3876   if (frame_pointer_needed)
3877     fputs (",SAVE_SP", file);
3878
3879   /* Pass on information about the number of callee register saves
3880      performed in the prologue.
3881
3882      The compiler is supposed to pass the highest register number
3883      saved, the assembler then has to adjust that number before
3884      entering it into the unwind descriptor (to account for any
3885      caller saved registers with lower register numbers than the
3886      first callee saved register).  */
3887   if (gr_saved)
3888     fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
3889
3890   if (fr_saved)
3891     fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
3892
3893   fputs ("\n\t.ENTRY\n", file);
3894
3895   remove_useless_addtr_insns (0);
3896 }
3897
3898 void
3899 hppa_expand_prologue (void)
3900 {
3901   int merge_sp_adjust_with_store = 0;
3902   HOST_WIDE_INT size = get_frame_size ();
3903   HOST_WIDE_INT offset;
3904   int i;
3905   rtx insn, tmpreg;
3906
3907   gr_saved = 0;
3908   fr_saved = 0;
3909   save_fregs = 0;
3910
3911   /* Compute total size for frame pointer, filler, locals and rounding to
3912      the next word boundary.  Similar code appears in compute_frame_size
3913      and must be changed in tandem with this code.  */
3914   local_fsize = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3915   if (local_fsize || frame_pointer_needed)
3916     local_fsize += STARTING_FRAME_OFFSET;
3917
3918   actual_fsize = compute_frame_size (size, &save_fregs);
3919
3920   /* Compute a few things we will use often.  */
3921   tmpreg = gen_rtx_REG (word_mode, 1);
3922
3923   /* Save RP first.  The calling conventions manual states RP will
3924      always be stored into the caller's frame at sp - 20 or sp - 16
3925      depending on which ABI is in use.  */
3926   if (regs_ever_live[2] || current_function_calls_eh_return)
3927     store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM);
3928
3929   /* Allocate the local frame and set up the frame pointer if needed.  */
3930   if (actual_fsize != 0)
3931     {
3932       if (frame_pointer_needed)
3933         {
3934           /* Copy the old frame pointer temporarily into %r1.  Set up the
3935              new stack pointer, then store away the saved old frame pointer
3936              into the stack at sp and at the same time update the stack
3937              pointer by actual_fsize bytes.  Two versions, first
3938              handles small (<8k) frames.  The second handles large (>=8k)
3939              frames.  */
3940           insn = emit_move_insn (tmpreg, frame_pointer_rtx);
3941           if (DO_FRAME_NOTES)
3942             {
3943               /* We need to record the frame pointer save here since the
3944                  new frame pointer is set in the following insn.  */
3945               RTX_FRAME_RELATED_P (insn) = 1;
3946               REG_NOTES (insn)
3947                 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3948                     gen_rtx_SET (VOIDmode,
3949                                  gen_rtx_MEM (word_mode, stack_pointer_rtx),
3950                                  frame_pointer_rtx),
3951                     REG_NOTES (insn));
3952             }
3953
3954           insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
3955           if (DO_FRAME_NOTES)
3956             RTX_FRAME_RELATED_P (insn) = 1;
3957
3958           if (VAL_14_BITS_P (actual_fsize))
3959             store_reg_modify (STACK_POINTER_REGNUM, 1, actual_fsize);
3960           else
3961             {
3962               /* It is incorrect to store the saved frame pointer at *sp,
3963                  then increment sp (writes beyond the current stack boundary).
3964
3965                  So instead use stwm to store at *sp and post-increment the
3966                  stack pointer as an atomic operation.  Then increment sp to
3967                  finish allocating the new frame.  */
3968               HOST_WIDE_INT adjust1 = 8192 - 64;
3969               HOST_WIDE_INT adjust2 = actual_fsize - adjust1;
3970
3971               store_reg_modify (STACK_POINTER_REGNUM, 1, adjust1);
3972               set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3973                               adjust2, 1);
3974             }
3975
3976           /* We set SAVE_SP in frames that need a frame pointer.  Thus,
3977              we need to store the previous stack pointer (frame pointer)
3978              into the frame marker on targets that use the HP unwind
3979              library.  This allows the HP unwind library to be used to
3980              unwind GCC frames.  However, we are not fully compatible
3981              with the HP library because our frame layout differs from
3982              that specified in the HP runtime specification.
3983
3984              We don't want a frame note on this instruction as the frame
3985              marker moves during dynamic stack allocation.
3986
3987              This instruction also serves as a blockage to prevent
3988              register spills from being scheduled before the stack
3989              pointer is raised.  This is necessary as we store
3990              registers using the frame pointer as a base register,
3991              and the frame pointer is set before sp is raised.  */
3992           if (TARGET_HPUX_UNWIND_LIBRARY)
3993             {
3994               rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx,
3995                                        GEN_INT (TARGET_64BIT ? -8 : -4));
3996
3997               emit_move_insn (gen_rtx_MEM (word_mode, addr),
3998                               frame_pointer_rtx);
3999             }
4000           else
4001             emit_insn (gen_blockage ());
4002         }
4003       /* no frame pointer needed.  */
4004       else
4005         {
4006           /* In some cases we can perform the first callee register save
4007              and allocating the stack frame at the same time.   If so, just
4008              make a note of it and defer allocating the frame until saving
4009              the callee registers.  */
4010           if (VAL_14_BITS_P (actual_fsize) && local_fsize == 0)
4011             merge_sp_adjust_with_store = 1;
4012           /* Can not optimize.  Adjust the stack frame by actual_fsize
4013              bytes.  */
4014           else
4015             set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4016                             actual_fsize, 1);
4017         }
4018     }
4019
4020   /* Normal register save.
4021
4022      Do not save the frame pointer in the frame_pointer_needed case.  It
4023      was done earlier.  */
4024   if (frame_pointer_needed)
4025     {
4026       offset = local_fsize;
4027
4028       /* Saving the EH return data registers in the frame is the simplest
4029          way to get the frame unwind information emitted.  We put them
4030          just before the general registers.  */
4031       if (DO_FRAME_NOTES && current_function_calls_eh_return)
4032         {
4033           unsigned int i, regno;
4034
4035           for (i = 0; ; ++i)
4036             {
4037               regno = EH_RETURN_DATA_REGNO (i);
4038               if (regno == INVALID_REGNUM)
4039                 break;
4040
4041               store_reg (regno, offset, FRAME_POINTER_REGNUM);
4042               offset += UNITS_PER_WORD;
4043             }
4044         }
4045
4046       for (i = 18; i >= 4; i--)
4047         if (regs_ever_live[i] && ! call_used_regs[i])
4048           {
4049             store_reg (i, offset, FRAME_POINTER_REGNUM);
4050             offset += UNITS_PER_WORD;
4051             gr_saved++;
4052           }
4053       /* Account for %r3 which is saved in a special place.  */
4054       gr_saved++;
4055     }
4056   /* No frame pointer needed.  */
4057   else
4058     {
4059       offset = local_fsize - actual_fsize;
4060
4061       /* Saving the EH return data registers in the frame is the simplest
4062          way to get the frame unwind information emitted.  */
4063       if (DO_FRAME_NOTES && current_function_calls_eh_return)
4064         {
4065           unsigned int i, regno;
4066
4067           for (i = 0; ; ++i)
4068             {
4069               regno = EH_RETURN_DATA_REGNO (i);
4070               if (regno == INVALID_REGNUM)
4071                 break;
4072
4073               /* If merge_sp_adjust_with_store is nonzero, then we can
4074                  optimize the first save.  */
4075               if (merge_sp_adjust_with_store)
4076                 {
4077                   store_reg_modify (STACK_POINTER_REGNUM, regno, -offset);
4078                   merge_sp_adjust_with_store = 0;
4079                 }
4080               else
4081                 store_reg (regno, offset, STACK_POINTER_REGNUM);
4082               offset += UNITS_PER_WORD;
4083             }
4084         }
4085
4086       for (i = 18; i >= 3; i--)
4087         if (regs_ever_live[i] && ! call_used_regs[i])
4088           {
4089             /* If merge_sp_adjust_with_store is nonzero, then we can
4090                optimize the first GR save.  */
4091             if (merge_sp_adjust_with_store)
4092               {
4093                 store_reg_modify (STACK_POINTER_REGNUM, i, -offset);
4094                 merge_sp_adjust_with_store = 0;
4095               }
4096             else
4097               store_reg (i, offset, STACK_POINTER_REGNUM);
4098             offset += UNITS_PER_WORD;
4099             gr_saved++;
4100           }
4101
4102       /* If we wanted to merge the SP adjustment with a GR save, but we never
4103          did any GR saves, then just emit the adjustment here.  */
4104       if (merge_sp_adjust_with_store)
4105         set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4106                         actual_fsize, 1);
4107     }
4108
4109   /* The hppa calling conventions say that %r19, the pic offset
4110      register, is saved at sp - 32 (in this function's frame)
4111      when generating PIC code.  FIXME:  What is the correct thing
4112      to do for functions which make no calls and allocate no
4113      frame?  Do we need to allocate a frame, or can we just omit
4114      the save?   For now we'll just omit the save.
4115      
4116      We don't want a note on this insn as the frame marker can
4117      move if there is a dynamic stack allocation.  */
4118   if (flag_pic && actual_fsize != 0 && !TARGET_64BIT)
4119     {
4120       rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx, GEN_INT (-32));
4121
4122       emit_move_insn (gen_rtx_MEM (word_mode, addr), pic_offset_table_rtx);
4123
4124     }
4125
4126   /* Align pointer properly (doubleword boundary).  */
4127   offset = (offset + 7) & ~7;
4128
4129   /* Floating point register store.  */
4130   if (save_fregs)
4131     {
4132       rtx base;
4133
4134       /* First get the frame or stack pointer to the start of the FP register
4135          save area.  */
4136       if (frame_pointer_needed)
4137         {
4138           set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset, 0);
4139           base = frame_pointer_rtx;
4140         }
4141       else
4142         {
4143           set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4144           base = stack_pointer_rtx;
4145         }
4146
4147       /* Now actually save the FP registers.  */
4148       for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4149         {
4150           if (regs_ever_live[i]
4151               || (! TARGET_64BIT && regs_ever_live[i + 1]))
4152             {
4153               rtx addr, insn, reg;
4154               addr = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
4155               reg = gen_rtx_REG (DFmode, i);
4156               insn = emit_move_insn (addr, reg);
4157               if (DO_FRAME_NOTES)
4158                 {
4159                   RTX_FRAME_RELATED_P (insn) = 1;
4160                   if (TARGET_64BIT)
4161                     {
4162                       rtx mem = gen_rtx_MEM (DFmode,
4163                                              plus_constant (base, offset));
4164                       REG_NOTES (insn)
4165                         = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
4166                                              gen_rtx_SET (VOIDmode, mem, reg),
4167                                              REG_NOTES (insn));
4168                     }
4169                   else
4170                     {
4171                       rtx meml = gen_rtx_MEM (SFmode,
4172                                               plus_constant (base, offset));
4173                       rtx memr = gen_rtx_MEM (SFmode,
4174                                               plus_constant (base, offset + 4));
4175                       rtx regl = gen_rtx_REG (SFmode, i);
4176                       rtx regr = gen_rtx_REG (SFmode, i + 1);
4177                       rtx setl = gen_rtx_SET (VOIDmode, meml, regl);
4178                       rtx setr = gen_rtx_SET (VOIDmode, memr, regr);
4179                       rtvec vec;
4180
4181                       RTX_FRAME_RELATED_P (setl) = 1;
4182                       RTX_FRAME_RELATED_P (setr) = 1;
4183                       vec = gen_rtvec (2, setl, setr);
4184                       REG_NOTES (insn)
4185                         = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
4186                                              gen_rtx_SEQUENCE (VOIDmode, vec),
4187                                              REG_NOTES (insn));
4188                     }
4189                 }
4190               offset += GET_MODE_SIZE (DFmode);
4191               fr_saved++;
4192             }
4193         }
4194     }
4195 }
4196
4197 /* Emit RTL to load REG from the memory location specified by BASE+DISP.
4198    Handle case where DISP > 8k by using the add_high_const patterns.  */
4199
4200 static void
4201 load_reg (int reg, HOST_WIDE_INT disp, int base)
4202 {
4203   rtx dest = gen_rtx_REG (word_mode, reg);
4204   rtx basereg = gen_rtx_REG (Pmode, base);
4205   rtx src;
4206
4207   if (VAL_14_BITS_P (disp))
4208     src = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
4209   else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
4210     {
4211       rtx delta = GEN_INT (disp);
4212       rtx tmpreg = gen_rtx_REG (Pmode, 1);
4213
4214       emit_move_insn (tmpreg, delta);
4215       if (TARGET_DISABLE_INDEXING)
4216         {
4217           emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4218           src = gen_rtx_MEM (word_mode, tmpreg);
4219         }
4220       else
4221         src = gen_rtx_MEM (word_mode, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4222     }
4223   else
4224     {
4225       rtx delta = GEN_INT (disp);
4226       rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
4227       rtx tmpreg = gen_rtx_REG (Pmode, 1);
4228
4229       emit_move_insn (tmpreg, high);
4230       src = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
4231     }
4232
4233   emit_move_insn (dest, src);
4234 }
4235
4236 /* Update the total code bytes output to the text section.  */
4237
4238 static void
4239 update_total_code_bytes (int nbytes)
4240 {
4241   if ((TARGET_PORTABLE_RUNTIME || !TARGET_GAS || !TARGET_SOM)
4242       && !IN_NAMED_SECTION_P (cfun->decl))
4243     {
4244       if (INSN_ADDRESSES_SET_P ())
4245         {
4246           unsigned long old_total = total_code_bytes;
4247
4248           total_code_bytes += nbytes;
4249
4250           /* Be prepared to handle overflows.  */
4251           if (old_total > total_code_bytes)
4252             total_code_bytes = -1;
4253         }
4254       else
4255         total_code_bytes = -1;
4256     }
4257 }
4258
4259 /* This function generates the assembly code for function exit.
4260    Args are as for output_function_prologue ().
4261
4262    The function epilogue should not depend on the current stack
4263    pointer!  It should use the frame pointer only.  This is mandatory
4264    because of alloca; we also take advantage of it to omit stack
4265    adjustments before returning.  */
4266
4267 static void
4268 pa_output_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4269 {
4270   rtx insn = get_last_insn ();
4271
4272   last_address = 0;
4273
4274   /* hppa_expand_epilogue does the dirty work now.  We just need
4275      to output the assembler directives which denote the end
4276      of a function.
4277
4278      To make debuggers happy, emit a nop if the epilogue was completely
4279      eliminated due to a volatile call as the last insn in the
4280      current function.  That way the return address (in %r2) will
4281      always point to a valid instruction in the current function.  */
4282
4283   /* Get the last real insn.  */
4284   if (GET_CODE (insn) == NOTE)
4285     insn = prev_real_insn (insn);
4286
4287   /* If it is a sequence, then look inside.  */
4288   if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
4289     insn = XVECEXP (PATTERN (insn), 0, 0);
4290
4291   /* If insn is a CALL_INSN, then it must be a call to a volatile
4292      function (otherwise there would be epilogue insns).  */
4293   if (insn && GET_CODE (insn) == CALL_INSN)
4294     {
4295       fputs ("\tnop\n", file);
4296       last_address += 4;
4297     }
4298
4299   fputs ("\t.EXIT\n\t.PROCEND\n", file);
4300
4301   if (TARGET_SOM && TARGET_GAS)
4302     {
4303       /* We done with this subspace except possibly for some additional
4304          debug information.  Forget that we are in this subspace to ensure
4305          that the next function is output in its own subspace.  */
4306       forget_section ();
4307     }
4308
4309   if (INSN_ADDRESSES_SET_P ())
4310     {
4311       insn = get_last_nonnote_insn ();
4312       last_address += INSN_ADDRESSES (INSN_UID (insn));
4313       if (INSN_P (insn))
4314         last_address += insn_default_length (insn);
4315       last_address = ((last_address + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
4316                       & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
4317     }
4318
4319   /* Finally, update the total number of code bytes output so far.  */
4320   update_total_code_bytes (last_address);
4321 }
4322
4323 void
4324 hppa_expand_epilogue (void)
4325 {
4326   rtx tmpreg;
4327   HOST_WIDE_INT offset;
4328   HOST_WIDE_INT ret_off = 0;
4329   int i;
4330   int merge_sp_adjust_with_load = 0;
4331
4332   /* We will use this often.  */
4333   tmpreg = gen_rtx_REG (word_mode, 1);
4334
4335   /* Try to restore RP early to avoid load/use interlocks when
4336      RP gets used in the return (bv) instruction.  This appears to still
4337      be necessary even when we schedule the prologue and epilogue.  */
4338   if (regs_ever_live [2] || current_function_calls_eh_return)
4339     {
4340       ret_off = TARGET_64BIT ? -16 : -20;
4341       if (frame_pointer_needed)
4342         {
4343           load_reg (2, ret_off, FRAME_POINTER_REGNUM);
4344           ret_off = 0;
4345         }
4346       else
4347         {
4348           /* No frame pointer, and stack is smaller than 8k.  */
4349           if (VAL_14_BITS_P (ret_off - actual_fsize))
4350             {
4351               load_reg (2, ret_off - actual_fsize, STACK_POINTER_REGNUM);
4352               ret_off = 0;
4353             }
4354         }
4355     }
4356
4357   /* General register restores.  */
4358   if (frame_pointer_needed)
4359     {
4360       offset = local_fsize;
4361
4362       /* If the current function calls __builtin_eh_return, then we need
4363          to restore the saved EH data registers.  */
4364       if (DO_FRAME_NOTES && current_function_calls_eh_return)
4365         {
4366           unsigned int i, regno;
4367
4368           for (i = 0; ; ++i)
4369             {
4370               regno = EH_RETURN_DATA_REGNO (i);
4371               if (regno == INVALID_REGNUM)
4372                 break;
4373
4374               load_reg (regno, offset, FRAME_POINTER_REGNUM);
4375               offset += UNITS_PER_WORD;
4376             }
4377         }
4378
4379       for (i = 18; i >= 4; i--)
4380         if (regs_ever_live[i] && ! call_used_regs[i])
4381           {
4382             load_reg (i, offset, FRAME_POINTER_REGNUM);
4383             offset += UNITS_PER_WORD;
4384           }
4385     }
4386   else
4387     {
4388       offset = local_fsize - actual_fsize;
4389
4390       /* If the current function calls __builtin_eh_return, then we need
4391          to restore the saved EH data registers.  */
4392       if (DO_FRAME_NOTES && current_function_calls_eh_return)
4393         {
4394           unsigned int i, regno;
4395
4396           for (i = 0; ; ++i)
4397             {
4398               regno = EH_RETURN_DATA_REGNO (i);
4399               if (regno == INVALID_REGNUM)
4400                 break;
4401
4402               /* Only for the first load.
4403                  merge_sp_adjust_with_load holds the register load
4404                  with which we will merge the sp adjustment.  */
4405               if (merge_sp_adjust_with_load == 0
4406                   && local_fsize == 0
4407                   && VAL_14_BITS_P (-actual_fsize))
4408                 merge_sp_adjust_with_load = regno;
4409               else
4410                 load_reg (regno, offset, STACK_POINTER_REGNUM);
4411               offset += UNITS_PER_WORD;
4412             }
4413         }
4414
4415       for (i = 18; i >= 3; i--)
4416         {
4417           if (regs_ever_live[i] && ! call_used_regs[i])
4418             {
4419               /* Only for the first load.
4420                  merge_sp_adjust_with_load holds the register load
4421                  with which we will merge the sp adjustment.  */
4422               if (merge_sp_adjust_with_load == 0
4423                   && local_fsize == 0
4424                   && VAL_14_BITS_P (-actual_fsize))
4425                 merge_sp_adjust_with_load = i;
4426               else
4427                 load_reg (i, offset, STACK_POINTER_REGNUM);
4428               offset += UNITS_PER_WORD;
4429             }
4430         }
4431     }
4432
4433   /* Align pointer properly (doubleword boundary).  */
4434   offset = (offset + 7) & ~7;
4435
4436   /* FP register restores.  */
4437   if (save_fregs)
4438     {
4439       /* Adjust the register to index off of.  */
4440       if (frame_pointer_needed)
4441         set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset, 0);
4442       else
4443         set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4444
4445       /* Actually do the restores now.  */
4446       for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4447         if (regs_ever_live[i]
4448             || (! TARGET_64BIT && regs_ever_live[i + 1]))
4449           {
4450             rtx src = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
4451             rtx dest = gen_rtx_REG (DFmode, i);
4452             emit_move_insn (dest, src);
4453           }
4454     }
4455
4456   /* Emit a blockage insn here to keep these insns from being moved to
4457      an earlier spot in the epilogue, or into the main instruction stream.
4458
4459      This is necessary as we must not cut the stack back before all the
4460      restores are finished.  */
4461   emit_insn (gen_blockage ());
4462
4463   /* Reset stack pointer (and possibly frame pointer).  The stack
4464      pointer is initially set to fp + 64 to avoid a race condition.  */
4465   if (frame_pointer_needed)
4466     {
4467       rtx delta = GEN_INT (-64);
4468
4469       set_reg_plus_d (STACK_POINTER_REGNUM, FRAME_POINTER_REGNUM, 64, 0);
4470       emit_insn (gen_pre_load (frame_pointer_rtx, stack_pointer_rtx, delta));
4471     }
4472   /* If we were deferring a callee register restore, do it now.  */
4473   else if (merge_sp_adjust_with_load)
4474     {
4475       rtx delta = GEN_INT (-actual_fsize);
4476       rtx dest = gen_rtx_REG (word_mode, merge_sp_adjust_with_load);
4477
4478       emit_insn (gen_pre_load (dest, stack_pointer_rtx, delta));
4479     }
4480   else if (actual_fsize != 0)
4481     set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4482                     - actual_fsize, 0);
4483
4484   /* If we haven't restored %r2 yet (no frame pointer, and a stack
4485      frame greater than 8k), do so now.  */
4486   if (ret_off != 0)
4487     load_reg (2, ret_off, STACK_POINTER_REGNUM);
4488
4489   if (DO_FRAME_NOTES && current_function_calls_eh_return)
4490     {
4491       rtx sa = EH_RETURN_STACKADJ_RTX;
4492
4493       emit_insn (gen_blockage ());
4494       emit_insn (TARGET_64BIT
4495                  ? gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, sa)
4496                  : gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, sa));
4497     }
4498 }
4499
4500 rtx
4501 hppa_pic_save_rtx (void)
4502 {
4503   return get_hard_reg_initial_val (word_mode, PIC_OFFSET_TABLE_REGNUM);
4504 }
4505
4506 void
4507 hppa_profile_hook (int label_no)
4508 {
4509   /* We use SImode for the address of the function in both 32 and
4510      64-bit code to avoid having to provide DImode versions of the
4511      lcla2 and load_offset_label_address insn patterns.  */
4512   rtx reg = gen_reg_rtx (SImode);
4513   rtx label_rtx = gen_label_rtx ();
4514   rtx begin_label_rtx, call_insn;
4515   char begin_label_name[16];
4516
4517   ASM_GENERATE_INTERNAL_LABEL (begin_label_name, FUNC_BEGIN_PROLOG_LABEL,
4518                                label_no);
4519   begin_label_rtx = gen_rtx_SYMBOL_REF (SImode, ggc_strdup (begin_label_name));
4520
4521   if (TARGET_64BIT)
4522     emit_move_insn (arg_pointer_rtx,
4523                     gen_rtx_PLUS (word_mode, virtual_outgoing_args_rtx,
4524                                   GEN_INT (64)));
4525
4526   emit_move_insn (gen_rtx_REG (word_mode, 26), gen_rtx_REG (word_mode, 2));
4527
4528   /* The address of the function is loaded into %r25 with a instruction-
4529      relative sequence that avoids the use of relocations.  The sequence
4530      is split so that the load_offset_label_address instruction can
4531      occupy the delay slot of the call to _mcount.  */
4532   if (TARGET_PA_20)
4533     emit_insn (gen_lcla2 (reg, label_rtx));
4534   else
4535     emit_insn (gen_lcla1 (reg, label_rtx));
4536
4537   emit_insn (gen_load_offset_label_address (gen_rtx_REG (SImode, 25), 
4538                                             reg, begin_label_rtx, label_rtx));
4539
4540 #ifndef NO_PROFILE_COUNTERS
4541   {
4542     rtx count_label_rtx, addr, r24;
4543     char count_label_name[16];
4544
4545     ASM_GENERATE_INTERNAL_LABEL (count_label_name, "LP", label_no);
4546     count_label_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (count_label_name));
4547
4548     addr = force_reg (Pmode, count_label_rtx);
4549     r24 = gen_rtx_REG (Pmode, 24);
4550     emit_move_insn (r24, addr);
4551
4552     call_insn =
4553       emit_call_insn (gen_call (gen_rtx_MEM (Pmode, 
4554                                              gen_rtx_SYMBOL_REF (Pmode, 
4555                                                                  "_mcount")),
4556                                 GEN_INT (TARGET_64BIT ? 24 : 12)));
4557
4558     use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), r24);
4559   }
4560 #else
4561
4562   call_insn =
4563     emit_call_insn (gen_call (gen_rtx_MEM (Pmode, 
4564                                            gen_rtx_SYMBOL_REF (Pmode, 
4565                                                                "_mcount")),
4566                               GEN_INT (TARGET_64BIT ? 16 : 8)));
4567
4568 #endif
4569
4570   use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 25));
4571   use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 26));
4572
4573   /* Indicate the _mcount call cannot throw, nor will it execute a
4574      non-local goto.  */
4575   REG_NOTES (call_insn)
4576     = gen_rtx_EXPR_LIST (REG_EH_REGION, constm1_rtx, REG_NOTES (call_insn));
4577 }
4578
4579 /* Fetch the return address for the frame COUNT steps up from
4580    the current frame, after the prologue.  FRAMEADDR is the
4581    frame pointer of the COUNT frame.
4582
4583    We want to ignore any export stub remnants here.  To handle this,
4584    we examine the code at the return address, and if it is an export
4585    stub, we return a memory rtx for the stub return address stored
4586    at frame-24.
4587
4588    The value returned is used in two different ways:
4589
4590         1. To find a function's caller.
4591
4592         2. To change the return address for a function.
4593
4594    This function handles most instances of case 1; however, it will
4595    fail if there are two levels of stubs to execute on the return
4596    path.  The only way I believe that can happen is if the return value
4597    needs a parameter relocation, which never happens for C code.
4598
4599    This function handles most instances of case 2; however, it will
4600    fail if we did not originally have stub code on the return path
4601    but will need stub code on the new return path.  This can happen if
4602    the caller & callee are both in the main program, but the new
4603    return location is in a shared library.  */
4604
4605 rtx
4606 return_addr_rtx (int count, rtx frameaddr)
4607 {
4608   rtx label;
4609   rtx rp;
4610   rtx saved_rp;
4611   rtx ins;
4612
4613   if (count != 0)
4614     return NULL_RTX;
4615
4616   rp = get_hard_reg_initial_val (Pmode, 2);
4617
4618   if (TARGET_64BIT || TARGET_NO_SPACE_REGS)
4619     return rp;
4620
4621   saved_rp = gen_reg_rtx (Pmode);
4622   emit_move_insn (saved_rp, rp);
4623
4624   /* Get pointer to the instruction stream.  We have to mask out the
4625      privilege level from the two low order bits of the return address
4626      pointer here so that ins will point to the start of the first
4627      instruction that would have been executed if we returned.  */
4628   ins = copy_to_reg (gen_rtx_AND (Pmode, rp, MASK_RETURN_ADDR));
4629   label = gen_label_rtx ();
4630
4631   /* Check the instruction stream at the normal return address for the
4632      export stub:
4633
4634         0x4bc23fd1 | stub+8:   ldw -18(sr0,sp),rp
4635         0x004010a1 | stub+12:  ldsid (sr0,rp),r1
4636         0x00011820 | stub+16:  mtsp r1,sr0
4637         0xe0400002 | stub+20:  be,n 0(sr0,rp)
4638
4639      If it is an export stub, than our return address is really in
4640      -24[frameaddr].  */
4641
4642   emit_cmp_insn (gen_rtx_MEM (SImode, ins), GEN_INT (0x4bc23fd1), NE,
4643                  NULL_RTX, SImode, 1);
4644   emit_jump_insn (gen_bne (label));
4645
4646   emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 4)),
4647                  GEN_INT (0x004010a1), NE, NULL_RTX, SImode, 1);
4648   emit_jump_insn (gen_bne (label));
4649
4650   emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 8)),
4651                  GEN_INT (0x00011820), NE, NULL_RTX, SImode, 1);
4652   emit_jump_insn (gen_bne (label));
4653
4654   emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 12)),
4655                  GEN_INT (0xe0400002), NE, NULL_RTX, SImode, 1);
4656
4657   /* If there is no export stub then just use the value saved from
4658      the return pointer register.  */
4659
4660   emit_jump_insn (gen_bne (label));
4661
4662   /* Here we know that our return address points to an export
4663      stub.  We don't want to return the address of the export stub,
4664      but rather the return address of the export stub.  That return
4665      address is stored at -24[frameaddr].  */
4666
4667   emit_move_insn (saved_rp,
4668                   gen_rtx_MEM (Pmode,
4669                                memory_address (Pmode,
4670                                                plus_constant (frameaddr,
4671                                                               -24))));
4672
4673   emit_label (label);
4674   return saved_rp;
4675 }
4676
4677 /* This is only valid once reload has completed because it depends on
4678    knowing exactly how much (if any) frame there is and...
4679
4680    It's only valid if there is no frame marker to de-allocate and...
4681
4682    It's only valid if %r2 hasn't been saved into the caller's frame
4683    (we're not profiling and %r2 isn't live anywhere).  */
4684 int
4685 hppa_can_use_return_insn_p (void)
4686 {
4687   return (reload_completed
4688           && (compute_frame_size (get_frame_size (), 0) ? 0 : 1)
4689           && ! regs_ever_live[2]
4690           && ! frame_pointer_needed);
4691 }
4692
4693 void
4694 emit_bcond_fp (enum rtx_code code, rtx operand0)
4695 {
4696   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4697                                gen_rtx_IF_THEN_ELSE (VOIDmode,
4698                                                      gen_rtx_fmt_ee (code,
4699                                                               VOIDmode,
4700                                                               gen_rtx_REG (CCFPmode, 0),
4701                                                               const0_rtx),
4702                                                      gen_rtx_LABEL_REF (VOIDmode, operand0),
4703                                                      pc_rtx)));
4704
4705 }
4706
4707 rtx
4708 gen_cmp_fp (enum rtx_code code, rtx operand0, rtx operand1)
4709 {
4710   return gen_rtx_SET (VOIDmode, gen_rtx_REG (CCFPmode, 0),
4711                       gen_rtx_fmt_ee (code, CCFPmode, operand0, operand1));
4712 }
4713
4714 /* Adjust the cost of a scheduling dependency.  Return the new cost of
4715    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
4716
4717 static int
4718 pa_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
4719 {
4720   enum attr_type attr_type;
4721
4722   /* Don't adjust costs for a pa8000 chip, also do not adjust any
4723      true dependencies as they are described with bypasses now.  */
4724   if (pa_cpu >= PROCESSOR_8000 || REG_NOTE_KIND (link) == 0)
4725     return cost;
4726
4727   if (! recog_memoized (insn))
4728     return 0;
4729
4730   attr_type = get_attr_type (insn);
4731
4732   if (REG_NOTE_KIND (link) == REG_DEP_ANTI)
4733     {
4734       /* Anti dependency; DEP_INSN reads a register that INSN writes some
4735          cycles later.  */
4736
4737       if (attr_type == TYPE_FPLOAD)
4738         {
4739           rtx pat = PATTERN (insn);
4740           rtx dep_pat = PATTERN (dep_insn);
4741           if (GET_CODE (pat) == PARALLEL)
4742             {
4743               /* This happens for the fldXs,mb patterns.  */
4744               pat = XVECEXP (pat, 0, 0);
4745             }
4746           if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4747             /* If this happens, we have to extend this to schedule
4748                optimally.  Return 0 for now.  */
4749           return 0;
4750
4751           if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4752             {
4753               if (! recog_memoized (dep_insn))
4754                 return 0;
4755               switch (get_attr_type (dep_insn))
4756                 {
4757                 case TYPE_FPALU:
4758                 case TYPE_FPMULSGL:
4759                 case TYPE_FPMULDBL:
4760                 case TYPE_FPDIVSGL:
4761                 case TYPE_FPDIVDBL:
4762                 case TYPE_FPSQRTSGL:
4763                 case TYPE_FPSQRTDBL:
4764                   /* A fpload can't be issued until one cycle before a
4765                      preceding arithmetic operation has finished if
4766                      the target of the fpload is any of the sources
4767                      (or destination) of the arithmetic operation.  */
4768                   return insn_default_latency (dep_insn) - 1;
4769
4770                 default:
4771                   return 0;
4772                 }
4773             }
4774         }
4775       else if (attr_type == TYPE_FPALU)
4776         {
4777           rtx pat = PATTERN (insn);
4778           rtx dep_pat = PATTERN (dep_insn);
4779           if (GET_CODE (pat) == PARALLEL)
4780             {
4781               /* This happens for the fldXs,mb patterns.  */
4782               pat = XVECEXP (pat, 0, 0);
4783             }
4784           if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4785             /* If this happens, we have to extend this to schedule
4786                optimally.  Return 0 for now.  */
4787           return 0;
4788
4789           if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4790             {
4791               if (! recog_memoized (dep_insn))
4792                 return 0;
4793               switch (get_attr_type (dep_insn))
4794                 {
4795                 case TYPE_FPDIVSGL:
4796                 case TYPE_FPDIVDBL:
4797                 case TYPE_FPSQRTSGL:
4798                 case TYPE_FPSQRTDBL:
4799                   /* An ALU flop can't be issued until two cycles before a
4800                      preceding divide or sqrt operation has finished if
4801                      the target of the ALU flop is any of the sources
4802                      (or destination) of the divide or sqrt operation.  */
4803                   return insn_default_latency (dep_insn) - 2;
4804
4805                 default:
4806                   return 0;
4807                 }
4808             }
4809         }
4810
4811       /* For other anti dependencies, the cost is 0.  */
4812       return 0;
4813     }
4814   else if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT)
4815     {
4816       /* Output dependency; DEP_INSN writes a register that INSN writes some
4817          cycles later.  */
4818       if (attr_type == TYPE_FPLOAD)
4819         {
4820           rtx pat = PATTERN (insn);
4821           rtx dep_pat = PATTERN (dep_insn);
4822           if (GET_CODE (pat) == PARALLEL)
4823             {
4824               /* This happens for the fldXs,mb patterns.  */
4825               pat = XVECEXP (pat, 0, 0);
4826             }
4827           if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4828             /* If this happens, we have to extend this to schedule
4829                optimally.  Return 0 for now.  */
4830           return 0;
4831
4832           if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4833             {
4834               if (! recog_memoized (dep_insn))
4835                 return 0;
4836               switch (get_attr_type (dep_insn))
4837                 {
4838                 case TYPE_FPALU:
4839                 case TYPE_FPMULSGL:
4840                 case TYPE_FPMULDBL:
4841                 case TYPE_FPDIVSGL:
4842                 case TYPE_FPDIVDBL:
4843                 case TYPE_FPSQRTSGL:
4844                 case TYPE_FPSQRTDBL:
4845                   /* A fpload can't be issued until one cycle before a
4846                      preceding arithmetic operation has finished if
4847                      the target of the fpload is the destination of the
4848                      arithmetic operation. 
4849
4850                      Exception: For PA7100LC, PA7200 and PA7300, the cost
4851                      is 3 cycles, unless they bundle together.   We also
4852                      pay the penalty if the second insn is a fpload.  */
4853                   return insn_default_latency (dep_insn) - 1;
4854
4855                 default:
4856                   return 0;
4857                 }
4858             }
4859         }
4860       else if (attr_type == TYPE_FPALU)
4861         {
4862           rtx pat = PATTERN (insn);
4863           rtx dep_pat = PATTERN (dep_insn);
4864           if (GET_CODE (pat) == PARALLEL)
4865             {
4866               /* This happens for the fldXs,mb patterns.  */
4867               pat = XVECEXP (pat, 0, 0);
4868             }
4869           if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4870             /* If this happens, we have to extend this to schedule
4871                optimally.  Return 0 for now.  */
4872           return 0;
4873
4874           if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4875             {
4876               if (! recog_memoized (dep_insn))
4877                 return 0;
4878               switch (get_attr_type (dep_insn))
4879                 {
4880                 case TYPE_FPDIVSGL:
4881                 case TYPE_FPDIVDBL:
4882                 case TYPE_FPSQRTSGL:
4883                 case TYPE_FPSQRTDBL:
4884                   /* An ALU flop can't be issued until two cycles before a
4885                      preceding divide or sqrt operation has finished if
4886                      the target of the ALU flop is also the target of
4887                      the divide or sqrt operation.  */
4888                   return insn_default_latency (dep_insn) - 2;
4889
4890                 default:
4891                   return 0;
4892                 }
4893             }
4894         }
4895
4896       /* For other output dependencies, the cost is 0.  */
4897       return 0;
4898     }
4899   else
4900     abort ();
4901 }
4902
4903 /* Adjust scheduling priorities.  We use this to try and keep addil
4904    and the next use of %r1 close together.  */
4905 static int
4906 pa_adjust_priority (rtx insn, int priority)
4907 {
4908   rtx set = single_set (insn);
4909   rtx src, dest;
4910   if (set)
4911     {
4912       src = SET_SRC (set);
4913       dest = SET_DEST (set);
4914       if (GET_CODE (src) == LO_SUM
4915           && symbolic_operand (XEXP (src, 1), VOIDmode)
4916           && ! read_only_operand (XEXP (src, 1), VOIDmode))
4917         priority >>= 3;
4918
4919       else if (GET_CODE (src) == MEM
4920                && GET_CODE (XEXP (src, 0)) == LO_SUM
4921                && symbolic_operand (XEXP (XEXP (src, 0), 1), VOIDmode)
4922                && ! read_only_operand (XEXP (XEXP (src, 0), 1), VOIDmode))
4923         priority >>= 1;
4924
4925       else if (GET_CODE (dest) == MEM
4926                && GET_CODE (XEXP (dest, 0)) == LO_SUM
4927                && symbolic_operand (XEXP (XEXP (dest, 0), 1), VOIDmode)
4928                && ! read_only_operand (XEXP (XEXP (dest, 0), 1), VOIDmode))
4929         priority >>= 3;
4930     }
4931   return priority;
4932 }
4933
4934 /* The 700 can only issue a single insn at a time.
4935    The 7XXX processors can issue two insns at a time.
4936    The 8000 can issue 4 insns at a time.  */
4937 static int
4938 pa_issue_rate (void)
4939 {
4940   switch (pa_cpu)
4941     {
4942     case PROCESSOR_700:         return 1;
4943     case PROCESSOR_7100:        return 2;
4944     case PROCESSOR_7100LC:      return 2;
4945     case PROCESSOR_7200:        return 2;
4946     case PROCESSOR_7300:        return 2;
4947     case PROCESSOR_8000:        return 4;
4948
4949     default:
4950       abort ();
4951     }
4952 }
4953
4954
4955
4956 /* Return any length adjustment needed by INSN which already has its length
4957    computed as LENGTH.   Return zero if no adjustment is necessary.
4958
4959    For the PA: function calls, millicode calls, and backwards short
4960    conditional branches with unfilled delay slots need an adjustment by +1
4961    (to account for the NOP which will be inserted into the instruction stream).
4962
4963    Also compute the length of an inline block move here as it is too
4964    complicated to express as a length attribute in pa.md.  */
4965 int
4966 pa_adjust_insn_length (rtx insn, int length)
4967 {
4968   rtx pat = PATTERN (insn);
4969
4970   /* Jumps inside switch tables which have unfilled delay slots need
4971      adjustment.  */
4972   if (GET_CODE (insn) == JUMP_INSN
4973       && GET_CODE (pat) == PARALLEL
4974       && get_attr_type (insn) == TYPE_BTABLE_BRANCH)
4975     return 4;
4976   /* Millicode insn with an unfilled delay slot.  */
4977   else if (GET_CODE (insn) == INSN
4978            && GET_CODE (pat) != SEQUENCE
4979            && GET_CODE (pat) != USE
4980            && GET_CODE (pat) != CLOBBER
4981            && get_attr_type (insn) == TYPE_MILLI)
4982     return 4;
4983   /* Block move pattern.  */
4984   else if (GET_CODE (insn) == INSN
4985            && GET_CODE (pat) == PARALLEL
4986            && GET_CODE (XVECEXP (pat, 0, 0)) == SET
4987            && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
4988            && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 1)) == MEM
4989            && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode
4990            && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 1)) == BLKmode)
4991     return compute_movmem_length (insn) - 4;
4992   /* Block clear pattern.  */
4993   else if (GET_CODE (insn) == INSN
4994            && GET_CODE (pat) == PARALLEL
4995            && GET_CODE (XVECEXP (pat, 0, 0)) == SET
4996            && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
4997            && XEXP (XVECEXP (pat, 0, 0), 1) == const0_rtx
4998            && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode)
4999     return compute_clrmem_length (insn) - 4;
5000   /* Conditional branch with an unfilled delay slot.  */
5001   else if (GET_CODE (insn) == JUMP_INSN && ! simplejump_p (insn))
5002     {
5003       /* Adjust a short backwards conditional with an unfilled delay slot.  */
5004       if (GET_CODE (pat) == SET
5005           && length == 4
5006           && ! forward_branch_p (insn))
5007         return 4;
5008       else if (GET_CODE (pat) == PARALLEL
5009                && get_attr_type (insn) == TYPE_PARALLEL_BRANCH
5010                && length == 4)
5011         return 4;
5012       /* Adjust dbra insn with short backwards conditional branch with
5013          unfilled delay slot -- only for case where counter is in a
5014          general register register.  */
5015       else if (GET_CODE (pat) == PARALLEL
5016                && GET_CODE (XVECEXP (pat, 0, 1)) == SET
5017                && GET_CODE (XEXP (XVECEXP (pat, 0, 1), 0)) == REG
5018                && ! FP_REG_P (XEXP (XVECEXP (pat, 0, 1), 0))
5019                && length == 4
5020                && ! forward_branch_p (insn))
5021         return 4;
5022       else
5023         return 0;
5024     }
5025   return 0;
5026 }
5027
5028 /* Print operand X (an rtx) in assembler syntax to file FILE.
5029    CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
5030    For `%' followed by punctuation, CODE is the punctuation and X is null.  */
5031
5032 void
5033 print_operand (FILE *file, rtx x, int code)
5034 {
5035   switch (code)
5036     {
5037     case '#':
5038       /* Output a 'nop' if there's nothing for the delay slot.  */
5039       if (dbr_sequence_length () == 0)
5040         fputs ("\n\tnop", file);
5041       return;
5042     case '*':
5043       /* Output a nullification completer if there's nothing for the */
5044       /* delay slot or nullification is requested.  */
5045       if (dbr_sequence_length () == 0 ||
5046           (final_sequence &&
5047            INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))))
5048         fputs (",n", file);
5049       return;
5050     case 'R':
5051       /* Print out the second register name of a register pair.
5052          I.e., R (6) => 7.  */
5053       fputs (reg_names[REGNO (x) + 1], file);
5054       return;
5055     case 'r':
5056       /* A register or zero.  */
5057       if (x == const0_rtx
5058           || (x == CONST0_RTX (DFmode))
5059           || (x == CONST0_RTX (SFmode)))
5060         {
5061           fputs ("%r0", file);
5062           return;
5063         }
5064       else
5065         break;
5066     case 'f':
5067       /* A register or zero (floating point).  */
5068       if (x == const0_rtx
5069           || (x == CONST0_RTX (DFmode))
5070           || (x == CONST0_RTX (SFmode)))
5071         {
5072           fputs ("%fr0", file);
5073           return;
5074         }
5075       else
5076         break;
5077     case 'A':
5078       {
5079         rtx xoperands[2];
5080
5081         xoperands[0] = XEXP (XEXP (x, 0), 0);
5082         xoperands[1] = XVECEXP (XEXP (XEXP (x, 0), 1), 0, 0);
5083         output_global_address (file, xoperands[1], 0);
5084         fprintf (file, "(%s)", reg_names [REGNO (xoperands[0])]);
5085         return;
5086       }
5087
5088     case 'C':                   /* Plain (C)ondition */
5089     case 'X':
5090       switch (GET_CODE (x))
5091         {
5092         case EQ:
5093           fputs ("=", file);  break;
5094         case NE:
5095           fputs ("<>", file);  break;
5096         case GT:
5097           fputs (">", file);  break;
5098         case GE:
5099           fputs (">=", file);  break;
5100         case GEU:
5101           fputs (">>=", file);  break;
5102         case GTU:
5103           fputs (">>", file);  break;
5104         case LT:
5105           fputs ("<", file);  break;
5106         case LE:
5107           fputs ("<=", file);  break;
5108         case LEU:
5109           fputs ("<<=", file);  break;
5110         case LTU:
5111           fputs ("<<", file);  break;
5112         default:
5113           abort ();
5114         }
5115       return;
5116     case 'N':                   /* Condition, (N)egated */
5117       switch (GET_CODE (x))
5118         {
5119         case EQ:
5120           fputs ("<>", file);  break;
5121         case NE:
5122           fputs ("=", file);  break;
5123         case GT:
5124           fputs ("<=", file);  break;
5125         case GE:
5126           fputs ("<", file);  break;
5127         case GEU:
5128           fputs ("<<", file);  break;
5129         case GTU:
5130           fputs ("<<=", file);  break;
5131         case LT:
5132           fputs (">=", file);  break;
5133         case LE:
5134           fputs (">", file);  break;
5135         case LEU:
5136           fputs (">>", file);  break;
5137         case LTU:
5138           fputs (">>=", file);  break;
5139         default:
5140           abort ();
5141         }
5142       return;
5143     /* For floating point comparisons.  Note that the output
5144        predicates are the complement of the desired mode.  The
5145        conditions for GT, GE, LT, LE and LTGT cause an invalid
5146        operation exception if the result is unordered and this
5147        exception is enabled in the floating-point status register.  */
5148     case 'Y':
5149       switch (GET_CODE (x))
5150         {
5151         case EQ:
5152           fputs ("!=", file);  break;
5153         case NE:
5154           fputs ("=", file);  break;
5155         case GT:
5156           fputs ("!>", file);  break;
5157         case GE:
5158           fputs ("!>=", file);  break;
5159         case LT:
5160           fputs ("!<", file);  break;
5161         case LE:
5162           fputs ("!<=", file);  break;
5163         case LTGT:
5164           fputs ("!<>", file);  break;
5165         case UNLE:
5166           fputs ("!?<=", file);  break;
5167         case UNLT:
5168           fputs ("!?<", file);  break;
5169         case UNGE:
5170           fputs ("!?>=", file);  break;
5171         case UNGT:
5172           fputs ("!?>", file);  break;
5173         case UNEQ:
5174           fputs ("!?=", file);  break;
5175         case UNORDERED:
5176           fputs ("!?", file);  break;
5177         case ORDERED:
5178           fputs ("?", file);  break;
5179         default:
5180           abort ();
5181         }
5182       return;
5183     case 'S':                   /* Condition, operands are (S)wapped.  */
5184       switch (GET_CODE (x))
5185         {
5186         case EQ:
5187           fputs ("=", file);  break;
5188         case NE:
5189           fputs ("<>", file);  break;
5190         case GT:
5191           fputs ("<", file);  break;
5192         case GE:
5193           fputs ("<=", file);  break;
5194         case GEU:
5195           fputs ("<<=", file);  break;
5196         case GTU:
5197           fputs ("<<", file);  break;
5198         case LT:
5199           fputs (">", file);  break;
5200         case LE:
5201           fputs (">=", file);  break;
5202         case LEU:
5203           fputs (">>=", file);  break;
5204         case LTU:
5205           fputs (">>", file);  break;
5206         default:
5207           abort ();
5208         }
5209       return;
5210     case 'B':                   /* Condition, (B)oth swapped and negate.  */
5211       switch (GET_CODE (x))
5212         {
5213         case EQ:
5214           fputs ("<>", file);  break;
5215         case NE:
5216           fputs ("=", file);  break;
5217         case GT:
5218           fputs (">=", file);  break;
5219         case GE:
5220           fputs (">", file);  break;
5221         case GEU:
5222           fputs (">>", file);  break;
5223         case GTU:
5224           fputs (">>=", file);  break;
5225         case LT:
5226           fputs ("<=", file);  break;
5227         case LE:
5228           fputs ("<", file);  break;
5229         case LEU:
5230           fputs ("<<", file);  break;
5231         case LTU:
5232           fputs ("<<=", file);  break;
5233         default:
5234           abort ();
5235         }
5236       return;
5237     case 'k':
5238       if (GET_CODE (x) == CONST_INT)
5239         {
5240           fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~INTVAL (x));
5241           return;
5242         }
5243       abort ();
5244     case 'Q':
5245       if (GET_CODE (x) == CONST_INT)
5246         {
5247           fprintf (file, HOST_WIDE_INT_PRINT_DEC, 64 - (INTVAL (x) & 63));
5248           return;
5249         }
5250       abort ();
5251     case 'L':
5252       if (GET_CODE (x) == CONST_INT)
5253         {
5254           fprintf (file, HOST_WIDE_INT_PRINT_DEC, 32 - (INTVAL (x) & 31));
5255           return;
5256         }
5257       abort ();
5258     case 'O':
5259       if (GET_CODE (x) == CONST_INT && exact_log2 (INTVAL (x)) >= 0)
5260         {
5261           fprintf (file, "%d", exact_log2 (INTVAL (x)));
5262           return;
5263         }
5264       abort ();
5265     case 'p':
5266       if (GET_CODE (x) == CONST_INT)
5267         {
5268           fprintf (file, HOST_WIDE_INT_PRINT_DEC, 63 - (INTVAL (x) & 63));
5269           return;
5270         }
5271       abort ();
5272     case 'P':
5273       if (GET_CODE (x) == CONST_INT)
5274         {
5275           fprintf (file, HOST_WIDE_INT_PRINT_DEC, 31 - (INTVAL (x) & 31));
5276           return;
5277         }
5278       abort ();
5279     case 'I':
5280       if (GET_CODE (x) == CONST_INT)
5281         fputs ("i", file);
5282       return;
5283     case 'M':
5284     case 'F':
5285       switch (GET_CODE (XEXP (x, 0)))
5286         {
5287         case PRE_DEC:
5288         case PRE_INC:
5289           if (ASSEMBLER_DIALECT == 0)
5290             fputs ("s,mb", file);
5291           else
5292             fputs (",mb", file);
5293           break;
5294         case POST_DEC:
5295         case POST_INC:
5296           if (ASSEMBLER_DIALECT == 0)
5297             fputs ("s,ma", file);
5298           else
5299             fputs (",ma", file);
5300           break;
5301         case PLUS:
5302           if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5303               && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5304             {
5305               if (ASSEMBLER_DIALECT == 0)
5306                 fputs ("x", file);
5307             }
5308           else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
5309                    || GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5310             {
5311               if (ASSEMBLER_DIALECT == 0)
5312                 fputs ("x,s", file);
5313               else
5314                 fputs (",s", file);
5315             }
5316           else if (code == 'F' && ASSEMBLER_DIALECT == 0)
5317             fputs ("s", file);
5318           break;
5319         default:
5320           if (code == 'F' && ASSEMBLER_DIALECT == 0)
5321             fputs ("s", file);
5322           break;
5323         }
5324       return;
5325     case 'G':
5326       output_global_address (file, x, 0);
5327       return;
5328     case 'H':
5329       output_global_address (file, x, 1);
5330       return;
5331     case 0:                     /* Don't do anything special */
5332       break;
5333     case 'Z':
5334       {
5335         unsigned op[3];
5336         compute_zdepwi_operands (INTVAL (x), op);
5337         fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5338         return;
5339       }
5340     case 'z':
5341       {
5342         unsigned op[3];
5343         compute_zdepdi_operands (INTVAL (x), op);
5344         fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5345         return;
5346       }
5347     case 'c':
5348       /* We can get here from a .vtable_inherit due to our
5349          CONSTANT_ADDRESS_P rejecting perfectly good constant
5350          addresses.  */
5351       break;
5352     default:
5353       abort ();
5354     }
5355   if (GET_CODE (x) == REG)
5356     {
5357       fputs (reg_names [REGNO (x)], file);
5358       if (TARGET_64BIT && FP_REG_P (x) && GET_MODE_SIZE (GET_MODE (x)) <= 4)
5359         {
5360           fputs ("R", file);
5361           return;
5362         }
5363       if (FP_REG_P (x)
5364           && GET_MODE_SIZE (GET_MODE (x)) <= 4
5365           && (REGNO (x) & 1) == 0)
5366         fputs ("L", file);
5367     }
5368   else if (GET_CODE (x) == MEM)
5369     {
5370       int size = GET_MODE_SIZE (GET_MODE (x));
5371       rtx base = NULL_RTX;
5372       switch (GET_CODE (XEXP (x, 0)))
5373         {
5374         case PRE_DEC:
5375         case POST_DEC:
5376           base = XEXP (XEXP (x, 0), 0);
5377           fprintf (file, "-%d(%s)", size, reg_names [REGNO (base)]);
5378           break;
5379         case PRE_INC:
5380         case POST_INC:
5381           base = XEXP (XEXP (x, 0), 0);
5382           fprintf (file, "%d(%s)", size, reg_names [REGNO (base)]);
5383           break;
5384         case PLUS:
5385           if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
5386             fprintf (file, "%s(%s)",
5387                      reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 0), 0))],
5388                      reg_names [REGNO (XEXP (XEXP (x, 0), 1))]);
5389           else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5390             fprintf (file, "%s(%s)",
5391                      reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 1), 0))],
5392                      reg_names [REGNO (XEXP (XEXP (x, 0), 0))]);
5393           else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5394                    && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5395             {
5396               /* Because the REG_POINTER flag can get lost during reload,
5397                  GO_IF_LEGITIMATE_ADDRESS canonicalizes the order of the
5398                  index and base registers in the combined move patterns.  */
5399               rtx base = XEXP (XEXP (x, 0), 1);
5400               rtx index = XEXP (XEXP (x, 0), 0);
5401
5402               fprintf (file, "%s(%s)",
5403                        reg_names [REGNO (index)], reg_names [REGNO (base)]);
5404             }
5405           else
5406             output_address (XEXP (x, 0));
5407           break;
5408         default:
5409           output_address (XEXP (x, 0));
5410           break;
5411         }
5412     }
5413   else
5414     output_addr_const (file, x);
5415 }
5416
5417 /* output a SYMBOL_REF or a CONST expression involving a SYMBOL_REF.  */
5418
5419 void
5420 output_global_address (FILE *file, rtx x, int round_constant)
5421 {
5422
5423   /* Imagine  (high (const (plus ...))).  */
5424   if (GET_CODE (x) == HIGH)
5425     x = XEXP (x, 0);
5426
5427   if (GET_CODE (x) == SYMBOL_REF && read_only_operand (x, VOIDmode))
5428     assemble_name (file, XSTR (x, 0));
5429   else if (GET_CODE (x) == SYMBOL_REF && !flag_pic)
5430     {
5431       assemble_name (file, XSTR (x, 0));
5432       fputs ("-$global$", file);
5433     }
5434   else if (GET_CODE (x) == CONST)
5435     {
5436       const char *sep = "";
5437       int offset = 0;           /* assembler wants -$global$ at end */
5438       rtx base = NULL_RTX;
5439
5440       if (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)
5441         {
5442           base = XEXP (XEXP (x, 0), 0);
5443           output_addr_const (file, base);
5444         }
5445       else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == CONST_INT)
5446         offset = INTVAL (XEXP (XEXP (x, 0), 0));
5447       else abort ();
5448
5449       if (GET_CODE (XEXP (XEXP (x, 0), 1)) == SYMBOL_REF)
5450         {
5451           base = XEXP (XEXP (x, 0), 1);
5452           output_addr_const (file, base);
5453         }
5454       else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
5455         offset = INTVAL (XEXP (XEXP (x, 0), 1));
5456       else abort ();
5457
5458       /* How bogus.  The compiler is apparently responsible for
5459          rounding the constant if it uses an LR field selector.
5460
5461          The linker and/or assembler seem a better place since
5462          they have to do this kind of thing already.
5463
5464          If we fail to do this, HP's optimizing linker may eliminate
5465          an addil, but not update the ldw/stw/ldo instruction that
5466          uses the result of the addil.  */
5467       if (round_constant)
5468         offset = ((offset + 0x1000) & ~0x1fff);
5469
5470       if (GET_CODE (XEXP (x, 0)) == PLUS)
5471         {
5472           if (offset < 0)
5473             {
5474               offset = -offset;
5475               sep = "-";
5476             }
5477           else
5478             sep = "+";
5479         }
5480       else if (GET_CODE (XEXP (x, 0)) == MINUS
5481                && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF))
5482         sep = "-";
5483       else abort ();
5484
5485       if (!read_only_operand (base, VOIDmode) && !flag_pic)
5486         fputs ("-$global$", file);
5487       if (offset)
5488         fprintf (file, "%s%d", sep, offset);
5489     }
5490   else
5491     output_addr_const (file, x);
5492 }
5493
5494 /* Output boilerplate text to appear at the beginning of the file.
5495    There are several possible versions.  */
5496 #define aputs(x) fputs(x, asm_out_file)
5497 static inline void
5498 pa_file_start_level (void)
5499 {
5500   if (TARGET_64BIT)
5501     aputs ("\t.LEVEL 2.0w\n");
5502   else if (TARGET_PA_20)
5503     aputs ("\t.LEVEL 2.0\n");
5504   else if (TARGET_PA_11)
5505     aputs ("\t.LEVEL 1.1\n");
5506   else
5507     aputs ("\t.LEVEL 1.0\n");
5508 }
5509
5510 static inline void
5511 pa_file_start_space (int sortspace)
5512 {
5513   aputs ("\t.SPACE $PRIVATE$");
5514   if (sortspace)
5515     aputs (",SORT=16");
5516   aputs ("\n\t.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31"
5517          "\n\t.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82"
5518          "\n\t.SPACE $TEXT$");
5519   if (sortspace)
5520     aputs (",SORT=8");
5521   aputs ("\n\t.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44"
5522          "\n\t.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n");
5523 }
5524
5525 static inline void
5526 pa_file_start_file (int want_version)
5527 {
5528   if (write_symbols != NO_DEBUG)
5529     {
5530       output_file_directive (asm_out_file, main_input_filename);
5531       if (want_version)
5532         aputs ("\t.version\t\"01.01\"\n");
5533     }
5534 }
5535
5536 static inline void
5537 pa_file_start_mcount (const char *aswhat)
5538 {
5539   if (profile_flag)
5540     fprintf (asm_out_file, "\t.IMPORT _mcount,%s\n", aswhat);
5541 }
5542   
5543 static void
5544 pa_elf_file_start (void)
5545 {
5546   pa_file_start_level ();
5547   pa_file_start_mcount ("ENTRY");
5548   pa_file_start_file (0);
5549 }
5550
5551 static void
5552 pa_som_file_start (void)
5553 {
5554   pa_file_start_level ();
5555   pa_file_start_space (0);
5556   aputs ("\t.IMPORT $global$,DATA\n"
5557          "\t.IMPORT $$dyncall,MILLICODE\n");
5558   pa_file_start_mcount ("CODE");
5559   pa_file_start_file (0);
5560 }
5561
5562 static void
5563 pa_linux_file_start (void)
5564 {
5565   pa_file_start_file (1);
5566   pa_file_start_level ();
5567   pa_file_start_mcount ("CODE");
5568 }
5569
5570 static void
5571 pa_hpux64_gas_file_start (void)
5572 {
5573   pa_file_start_level ();
5574 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
5575   if (profile_flag)
5576     ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, "_mcount", "function");
5577 #endif
5578   pa_file_start_file (1);
5579 }
5580
5581 static void
5582 pa_hpux64_hpas_file_start (void)
5583 {
5584   pa_file_start_level ();
5585   pa_file_start_space (1);
5586   pa_file_start_mcount ("CODE");
5587   pa_file_start_file (0);
5588 }
5589 #undef aputs
5590
5591 static struct deferred_plabel *
5592 get_plabel (const char *fname)
5593 {
5594   size_t i;
5595
5596   /* See if we have already put this function on the list of deferred
5597      plabels.  This list is generally small, so a liner search is not
5598      too ugly.  If it proves too slow replace it with something faster.  */
5599   for (i = 0; i < n_deferred_plabels; i++)
5600     if (strcmp (fname, deferred_plabels[i].name) == 0)
5601       break;
5602
5603   /* If the deferred plabel list is empty, or this entry was not found
5604      on the list, create a new entry on the list.  */
5605   if (deferred_plabels == NULL || i == n_deferred_plabels)
5606     {
5607       const char *real_name;
5608
5609       if (deferred_plabels == 0)
5610         deferred_plabels = (struct deferred_plabel *)
5611           ggc_alloc (sizeof (struct deferred_plabel));
5612       else
5613         deferred_plabels = (struct deferred_plabel *)
5614           ggc_realloc (deferred_plabels,
5615                        ((n_deferred_plabels + 1)
5616                         * sizeof (struct deferred_plabel)));
5617
5618       i = n_deferred_plabels++;
5619       deferred_plabels[i].internal_label = gen_label_rtx ();
5620       deferred_plabels[i].name = ggc_strdup (fname);
5621
5622       /* Gross.  We have just implicitly taken the address of this function,
5623          mark it as such.  */
5624       real_name = (*targetm.strip_name_encoding) (fname);
5625       TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
5626     }
5627
5628   return &deferred_plabels[i];
5629 }
5630
5631 static void
5632 output_deferred_plabels (void)
5633 {
5634   size_t i;
5635   /* If we have deferred plabels, then we need to switch into the data
5636      section and align it to a 4 byte boundary before we output the
5637      deferred plabels.  */
5638   if (n_deferred_plabels)
5639     {
5640       data_section ();
5641       ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2);
5642     }
5643
5644   /* Now output the deferred plabels.  */
5645   for (i = 0; i < n_deferred_plabels; i++)
5646     {
5647       (*targetm.asm_out.internal_label) (asm_out_file, "L",
5648                  CODE_LABEL_NUMBER (deferred_plabels[i].internal_label));
5649       assemble_integer (gen_rtx_SYMBOL_REF (Pmode, deferred_plabels[i].name),
5650                         TARGET_64BIT ? 8 : 4, TARGET_64BIT ? 64 : 32, 1);
5651     }
5652 }
5653
5654 #ifdef HPUX_LONG_DOUBLE_LIBRARY
5655 /* Initialize optabs to point to HPUX long double emulation routines.  */
5656 static void
5657 pa_hpux_init_libfuncs (void)
5658 {
5659   set_optab_libfunc (add_optab, TFmode, "_U_Qfadd");
5660   set_optab_libfunc (sub_optab, TFmode, "_U_Qfsub");
5661   set_optab_libfunc (smul_optab, TFmode, "_U_Qfmpy");
5662   set_optab_libfunc (sdiv_optab, TFmode, "_U_Qfdiv");
5663   set_optab_libfunc (smin_optab, TFmode, "_U_Qmin");
5664   set_optab_libfunc (smax_optab, TFmode, "_U_Qfmax");
5665   set_optab_libfunc (sqrt_optab, TFmode, "_U_Qfsqrt");
5666   set_optab_libfunc (abs_optab, TFmode, "_U_Qfabs");
5667   set_optab_libfunc (neg_optab, TFmode, "_U_Qfneg");
5668
5669   set_optab_libfunc (eq_optab, TFmode, "_U_Qfeq");
5670   set_optab_libfunc (ne_optab, TFmode, "_U_Qfne");
5671   set_optab_libfunc (gt_optab, TFmode, "_U_Qfgt");
5672   set_optab_libfunc (ge_optab, TFmode, "_U_Qfge");
5673   set_optab_libfunc (lt_optab, TFmode, "_U_Qflt");
5674   set_optab_libfunc (le_optab, TFmode, "_U_Qfle");
5675   set_optab_libfunc (unord_optab, TFmode, "_U_Qfunord");
5676
5677   set_conv_libfunc (sext_optab,   TFmode, SFmode, "_U_Qfcnvff_sgl_to_quad");
5678   set_conv_libfunc (sext_optab,   TFmode, DFmode, "_U_Qfcnvff_dbl_to_quad");
5679   set_conv_libfunc (trunc_optab,  SFmode, TFmode, "_U_Qfcnvff_quad_to_sgl");
5680   set_conv_libfunc (trunc_optab,  DFmode, TFmode, "_U_Qfcnvff_quad_to_dbl");
5681
5682   set_conv_libfunc (sfix_optab,   SImode, TFmode, TARGET_64BIT
5683                                                   ? "__U_Qfcnvfxt_quad_to_sgl"
5684                                                   : "_U_Qfcnvfxt_quad_to_sgl");
5685   set_conv_libfunc (sfix_optab,   DImode, TFmode, "_U_Qfcnvfxt_quad_to_dbl");
5686   set_conv_libfunc (ufix_optab,   SImode, TFmode, "_U_Qfcnvfxt_quad_to_usgl");
5687   set_conv_libfunc (ufix_optab,   DImode, TFmode, "_U_Qfcnvfxt_quad_to_udbl");
5688
5689   set_conv_libfunc (sfloat_optab, TFmode, SImode, "_U_Qfcnvxf_sgl_to_quad");
5690   set_conv_libfunc (sfloat_optab, TFmode, DImode, "_U_Qfcnvxf_dbl_to_quad");
5691 }
5692 #endif
5693
5694 /* HP's millicode routines mean something special to the assembler.
5695    Keep track of which ones we have used.  */
5696
5697 enum millicodes { remI, remU, divI, divU, mulI, end1000 };
5698 static void import_milli (enum millicodes);
5699 static char imported[(int) end1000];
5700 static const char * const milli_names[] = {"remI", "remU", "divI", "divU", "mulI"};
5701 static const char import_string[] = ".IMPORT $$....,MILLICODE";
5702 #define MILLI_START 10
5703
5704 static void
5705 import_milli (enum millicodes code)
5706 {
5707   char str[sizeof (import_string)];
5708
5709   if (!imported[(int) code])
5710     {
5711       imported[(int) code] = 1;
5712       strcpy (str, import_string);
5713       strncpy (str + MILLI_START, milli_names[(int) code], 4);
5714       output_asm_insn (str, 0);
5715     }
5716 }
5717
5718 /* The register constraints have put the operands and return value in
5719    the proper registers.  */
5720
5721 const char *
5722 output_mul_insn (int unsignedp ATTRIBUTE_UNUSED, rtx insn)
5723 {
5724   import_milli (mulI);
5725   return output_millicode_call (insn, gen_rtx_SYMBOL_REF (Pmode, "$$mulI"));
5726 }
5727
5728 /* Emit the rtl for doing a division by a constant.  */
5729
5730 /* Do magic division millicodes exist for this value? */
5731 static const int magic_milli[]= {0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0,
5732                                  1, 1};
5733
5734 /* We'll use an array to keep track of the magic millicodes and
5735    whether or not we've used them already. [n][0] is signed, [n][1] is
5736    unsigned.  */
5737
5738 static int div_milli[16][2];
5739
5740 int
5741 div_operand (rtx op, enum machine_mode mode)
5742 {
5743   return (mode == SImode
5744           && ((GET_CODE (op) == REG && REGNO (op) == 25)
5745               || (GET_CODE (op) == CONST_INT && INTVAL (op) > 0
5746                   && INTVAL (op) < 16 && magic_milli[INTVAL (op)])));
5747 }
5748
5749 int
5750 emit_hpdiv_const (rtx *operands, int unsignedp)
5751 {
5752   if (GET_CODE (operands[2]) == CONST_INT
5753       && INTVAL (operands[2]) > 0
5754       && INTVAL (operands[2]) < 16
5755       && magic_milli[INTVAL (operands[2])])
5756     {
5757       rtx ret = gen_rtx_REG (SImode, TARGET_64BIT ? 2 : 31);
5758
5759       emit_move_insn (gen_rtx_REG (SImode, 26), operands[1]);
5760       emit
5761         (gen_rtx_PARALLEL
5762          (VOIDmode,
5763           gen_rtvec (6, gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, 29),
5764                                      gen_rtx_fmt_ee (unsignedp ? UDIV : DIV,
5765                                                      SImode,
5766                                                      gen_rtx_REG (SImode, 26),
5767                                                      operands[2])),
5768                      gen_rtx_CLOBBER (VOIDmode, operands[4]),
5769                      gen_rtx_CLOBBER (VOIDmode, operands[3]),
5770                      gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 26)),
5771                      gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 25)),
5772                      gen_rtx_CLOBBER (VOIDmode, ret))));
5773       emit_move_insn (operands[0], gen_rtx_REG (SImode, 29));
5774       return 1;
5775     }
5776   return 0;
5777 }
5778
5779 const char *
5780 output_div_insn (rtx *operands, int unsignedp, rtx insn)
5781 {
5782   int divisor;
5783
5784   /* If the divisor is a constant, try to use one of the special
5785      opcodes .*/
5786   if (GET_CODE (operands[0]) == CONST_INT)
5787     {
5788       static char buf[100];
5789       divisor = INTVAL (operands[0]);
5790       if (!div_milli[divisor][unsignedp])
5791         {
5792           div_milli[divisor][unsignedp] = 1;
5793           if (unsignedp)
5794             output_asm_insn (".IMPORT $$divU_%0,MILLICODE", operands);
5795           else
5796             output_asm_insn (".IMPORT $$divI_%0,MILLICODE", operands);
5797         }
5798       if (unsignedp)
5799         {
5800           sprintf (buf, "$$divU_" HOST_WIDE_INT_PRINT_DEC,
5801                    INTVAL (operands[0]));
5802           return output_millicode_call (insn,
5803                                         gen_rtx_SYMBOL_REF (SImode, buf));
5804         }
5805       else
5806         {
5807           sprintf (buf, "$$divI_" HOST_WIDE_INT_PRINT_DEC,
5808                    INTVAL (operands[0]));
5809           return output_millicode_call (insn,
5810                                         gen_rtx_SYMBOL_REF (SImode, buf));
5811         }
5812     }
5813   /* Divisor isn't a special constant.  */
5814   else
5815     {
5816       if (unsignedp)
5817         {
5818           import_milli (divU);
5819           return output_millicode_call (insn,
5820                                         gen_rtx_SYMBOL_REF (SImode, "$$divU"));
5821         }
5822       else
5823         {
5824           import_milli (divI);
5825           return output_millicode_call (insn,
5826                                         gen_rtx_SYMBOL_REF (SImode, "$$divI"));
5827         }
5828     }
5829 }
5830
5831 /* Output a $$rem millicode to do mod.  */
5832
5833 const char *
5834 output_mod_insn (int unsignedp, rtx insn)
5835 {
5836   if (unsignedp)
5837     {
5838       import_milli (remU);
5839       return output_millicode_call (insn,
5840                                     gen_rtx_SYMBOL_REF (SImode, "$$remU"));
5841     }
5842   else
5843     {
5844       import_milli (remI);
5845       return output_millicode_call (insn,
5846                                     gen_rtx_SYMBOL_REF (SImode, "$$remI"));
5847     }
5848 }
5849
5850 void
5851 output_arg_descriptor (rtx call_insn)
5852 {
5853   const char *arg_regs[4];
5854   enum machine_mode arg_mode;
5855   rtx link;
5856   int i, output_flag = 0;
5857   int regno;
5858
5859   /* We neither need nor want argument location descriptors for the
5860      64bit runtime environment or the ELF32 environment.  */
5861   if (TARGET_64BIT || TARGET_ELF32)
5862     return;
5863
5864   for (i = 0; i < 4; i++)
5865     arg_regs[i] = 0;
5866
5867   /* Specify explicitly that no argument relocations should take place
5868      if using the portable runtime calling conventions.  */
5869   if (TARGET_PORTABLE_RUNTIME)
5870     {
5871       fputs ("\t.CALL ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RETVAL=NO\n",
5872              asm_out_file);
5873       return;
5874     }
5875
5876   if (GET_CODE (call_insn) != CALL_INSN)
5877     abort ();
5878   for (link = CALL_INSN_FUNCTION_USAGE (call_insn); link; link = XEXP (link, 1))
5879     {
5880       rtx use = XEXP (link, 0);
5881
5882       if (! (GET_CODE (use) == USE
5883              && GET_CODE (XEXP (use, 0)) == REG
5884              && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
5885         continue;
5886
5887       arg_mode = GET_MODE (XEXP (use, 0));
5888       regno = REGNO (XEXP (use, 0));
5889       if (regno >= 23 && regno <= 26)
5890         {
5891           arg_regs[26 - regno] = "GR";
5892           if (arg_mode == DImode)
5893             arg_regs[25 - regno] = "GR";
5894         }
5895       else if (regno >= 32 && regno <= 39)
5896         {
5897           if (arg_mode == SFmode)
5898             arg_regs[(regno - 32) / 2] = "FR";
5899           else
5900             {
5901 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
5902               arg_regs[(regno - 34) / 2] = "FR";
5903               arg_regs[(regno - 34) / 2 + 1] = "FU";
5904 #else
5905               arg_regs[(regno - 34) / 2] = "FU";
5906               arg_regs[(regno - 34) / 2 + 1] = "FR";
5907 #endif
5908             }
5909         }
5910     }
5911   fputs ("\t.CALL ", asm_out_file);
5912   for (i = 0; i < 4; i++)
5913     {
5914       if (arg_regs[i])
5915         {
5916           if (output_flag++)
5917             fputc (',', asm_out_file);
5918           fprintf (asm_out_file, "ARGW%d=%s", i, arg_regs[i]);
5919         }
5920     }
5921   fputc ('\n', asm_out_file);
5922 }
5923 \f
5924 /* Return the class of any secondary reload register that is needed to
5925    move IN into a register in class CLASS using mode MODE.
5926
5927    Profiling has showed this routine and its descendants account for
5928    a significant amount of compile time (~7%).  So it has been
5929    optimized to reduce redundant computations and eliminate useless
5930    function calls.
5931
5932    It might be worthwhile to try and make this a leaf function too.  */
5933
5934 enum reg_class
5935 secondary_reload_class (enum reg_class class, enum machine_mode mode, rtx in)
5936 {
5937   int regno, is_symbolic;
5938
5939   /* Trying to load a constant into a FP register during PIC code
5940      generation will require %r1 as a scratch register.  */
5941   if (flag_pic
5942       && GET_MODE_CLASS (mode) == MODE_INT
5943       && FP_REG_CLASS_P (class)
5944       && (GET_CODE (in) == CONST_INT || GET_CODE (in) == CONST_DOUBLE))
5945     return R1_REGS;
5946
5947   /* Profiling showed the PA port spends about 1.3% of its compilation
5948      time in true_regnum from calls inside secondary_reload_class.  */
5949
5950   if (GET_CODE (in) == REG)
5951     {
5952       regno = REGNO (in);
5953       if (regno >= FIRST_PSEUDO_REGISTER)
5954         regno = true_regnum (in);
5955     }
5956   else if (GET_CODE (in) == SUBREG)
5957     regno = true_regnum (in);
5958   else
5959     regno = -1;
5960
5961   /* If we have something like (mem (mem (...)), we can safely assume the
5962      inner MEM will end up in a general register after reloading, so there's
5963      no need for a secondary reload.  */
5964   if (GET_CODE (in) == MEM
5965       && GET_CODE (XEXP (in, 0)) == MEM)
5966     return NO_REGS;
5967
5968   /* Handle out of range displacement for integer mode loads/stores of
5969      FP registers.  */
5970   if (((regno >= FIRST_PSEUDO_REGISTER || regno == -1)
5971        && GET_MODE_CLASS (mode) == MODE_INT
5972        && FP_REG_CLASS_P (class))
5973       || (class == SHIFT_REGS && (regno <= 0 || regno >= 32)))
5974     return GENERAL_REGS;
5975
5976   /* A SAR<->FP register copy requires a secondary register (GPR) as
5977      well as secondary memory.  */
5978   if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5979       && ((REGNO_REG_CLASS (regno) == SHIFT_REGS && FP_REG_CLASS_P (class))
5980           || (class == SHIFT_REGS && FP_REG_CLASS_P (REGNO_REG_CLASS (regno)))))
5981     return GENERAL_REGS;
5982
5983   if (GET_CODE (in) == HIGH)
5984     in = XEXP (in, 0);
5985
5986   /* Profiling has showed GCC spends about 2.6% of its compilation
5987      time in symbolic_operand from calls inside secondary_reload_class.
5988
5989      We use an inline copy and only compute its return value once to avoid
5990      useless work.  */
5991   switch (GET_CODE (in))
5992     {
5993       rtx tmp;
5994
5995       case SYMBOL_REF:
5996       case LABEL_REF:
5997         is_symbolic = 1;
5998         break;
5999       case CONST:
6000         tmp = XEXP (in, 0);
6001         is_symbolic = ((GET_CODE (XEXP (tmp, 0)) == SYMBOL_REF
6002                         || GET_CODE (XEXP (tmp, 0)) == LABEL_REF)
6003                        && GET_CODE (XEXP (tmp, 1)) == CONST_INT);
6004         break;
6005
6006       default:
6007         is_symbolic = 0;
6008         break;
6009     }
6010
6011   if (!flag_pic
6012       && is_symbolic
6013       && read_only_operand (in, VOIDmode))
6014     return NO_REGS;
6015
6016   if (class != R1_REGS && is_symbolic)
6017     return R1_REGS;
6018
6019   return NO_REGS;
6020 }
6021
6022 /* In the 32-bit runtime, arguments larger than eight bytes are passed
6023    by invisible reference.  As a GCC extension, we also pass anything
6024    with a zero or variable size by reference.
6025
6026    The 64-bit runtime does not describe passing any types by invisible
6027    reference.  The internals of GCC can't currently handle passing
6028    empty structures, and zero or variable length arrays when they are
6029    not passed entirely on the stack or by reference.  Thus, as a GCC
6030    extension, we pass these types by reference.  The HP compiler doesn't
6031    support these types, so hopefully there shouldn't be any compatibility
6032    issues.  This may have to be revisited when HP releases a C99 compiler
6033    or updates the ABI.  */
6034
6035 static bool
6036 pa_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
6037                       enum machine_mode mode, tree type,
6038                       bool named ATTRIBUTE_UNUSED)
6039 {
6040   HOST_WIDE_INT size;
6041
6042   if (type)
6043     size = int_size_in_bytes (type);
6044   else
6045     size = GET_MODE_SIZE (mode);
6046
6047   if (TARGET_64BIT)
6048     return size <= 0;
6049   else
6050     return size <= 0 || size > 8;
6051 }
6052
6053 enum direction
6054 function_arg_padding (enum machine_mode mode, tree type)
6055 {
6056   if (mode == BLKmode
6057       || (TARGET_64BIT && type && AGGREGATE_TYPE_P (type)))
6058     {
6059       /* Return none if justification is not required.  */
6060       if (type
6061           && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
6062           && (int_size_in_bytes (type) * BITS_PER_UNIT) % PARM_BOUNDARY == 0)
6063         return none;
6064
6065       /* The directions set here are ignored when a BLKmode argument larger
6066          than a word is placed in a register.  Different code is used for
6067          the stack and registers.  This makes it difficult to have a
6068          consistent data representation for both the stack and registers.
6069          For both runtimes, the justification and padding for arguments on
6070          the stack and in registers should be identical.  */
6071       if (TARGET_64BIT)
6072         /* The 64-bit runtime specifies left justification for aggregates.  */
6073         return upward;
6074       else
6075         /* The 32-bit runtime architecture specifies right justification.
6076            When the argument is passed on the stack, the argument is padded
6077            with garbage on the left.  The HP compiler pads with zeros.  */
6078         return downward;
6079     }
6080
6081   if (GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
6082     return downward;
6083   else
6084     return none;
6085 }
6086
6087 \f
6088 /* Do what is necessary for `va_start'.  We look at the current function
6089    to determine if stdargs or varargs is used and fill in an initial
6090    va_list.  A pointer to this constructor is returned.  */
6091
6092 static rtx
6093 hppa_builtin_saveregs (void)
6094 {
6095   rtx offset, dest;
6096   tree fntype = TREE_TYPE (current_function_decl);
6097   int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
6098                    && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
6099                        != void_type_node)))
6100                 ? UNITS_PER_WORD : 0);
6101
6102   if (argadj)
6103     offset = plus_constant (current_function_arg_offset_rtx, argadj);
6104   else
6105     offset = current_function_arg_offset_rtx;
6106
6107   if (TARGET_64BIT)
6108     {
6109       int i, off;
6110
6111       /* Adjust for varargs/stdarg differences.  */
6112       if (argadj)
6113         offset = plus_constant (current_function_arg_offset_rtx, -argadj);
6114       else
6115         offset = current_function_arg_offset_rtx;
6116
6117       /* We need to save %r26 .. %r19 inclusive starting at offset -64
6118          from the incoming arg pointer and growing to larger addresses.  */
6119       for (i = 26, off = -64; i >= 19; i--, off += 8)
6120         emit_move_insn (gen_rtx_MEM (word_mode,
6121                                      plus_constant (arg_pointer_rtx, off)),
6122                         gen_rtx_REG (word_mode, i));
6123
6124       /* The incoming args pointer points just beyond the flushback area;
6125          normally this is not a serious concern.  However, when we are doing
6126          varargs/stdargs we want to make the arg pointer point to the start
6127          of the incoming argument area.  */
6128       emit_move_insn (virtual_incoming_args_rtx,
6129                       plus_constant (arg_pointer_rtx, -64));
6130
6131       /* Now return a pointer to the first anonymous argument.  */
6132       return copy_to_reg (expand_binop (Pmode, add_optab,
6133                                         virtual_incoming_args_rtx,
6134                                         offset, 0, 0, OPTAB_LIB_WIDEN));
6135     }
6136
6137   /* Store general registers on the stack.  */
6138   dest = gen_rtx_MEM (BLKmode,
6139                       plus_constant (current_function_internal_arg_pointer,
6140                                      -16));
6141   set_mem_alias_set (dest, get_varargs_alias_set ());
6142   set_mem_align (dest, BITS_PER_WORD);
6143   move_block_from_reg (23, dest, 4);
6144
6145   /* move_block_from_reg will emit code to store the argument registers
6146      individually as scalar stores.
6147
6148      However, other insns may later load from the same addresses for
6149      a structure load (passing a struct to a varargs routine).
6150
6151      The alias code assumes that such aliasing can never happen, so we
6152      have to keep memory referencing insns from moving up beyond the
6153      last argument register store.  So we emit a blockage insn here.  */
6154   emit_insn (gen_blockage ());
6155
6156   return copy_to_reg (expand_binop (Pmode, add_optab,
6157                                     current_function_internal_arg_pointer,
6158                                     offset, 0, 0, OPTAB_LIB_WIDEN));
6159 }
6160
6161 void
6162 hppa_va_start (tree valist, rtx nextarg)
6163 {
6164   nextarg = expand_builtin_saveregs ();
6165   std_expand_builtin_va_start (valist, nextarg);
6166 }
6167
6168 static tree
6169 hppa_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p, tree *post_p)
6170 {
6171   if (TARGET_64BIT)
6172     {
6173       /* Args grow upward.  We can use the generic routines.  */
6174       return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6175     }
6176   else /* !TARGET_64BIT */
6177     {
6178       tree ptr = build_pointer_type (type);
6179       tree valist_type;
6180       tree t, u;
6181       unsigned int size, ofs;
6182       bool indirect;
6183
6184       indirect = pass_by_reference (NULL, TYPE_MODE (type), type, 0);
6185       if (indirect)
6186         {
6187           type = ptr;
6188           ptr = build_pointer_type (type);
6189         }
6190       size = int_size_in_bytes (type);
6191       valist_type = TREE_TYPE (valist);
6192
6193       /* Args grow down.  Not handled by generic routines.  */
6194
6195       u = fold_convert (valist_type, size_in_bytes (type));
6196       t = build (MINUS_EXPR, valist_type, valist, u);
6197
6198       /* Copied from va-pa.h, but we probably don't need to align to
6199          word size, since we generate and preserve that invariant.  */
6200       u = build_int_cst (valist_type, (size > 4 ? -8 : -4));
6201       t = build (BIT_AND_EXPR, valist_type, t, u);
6202
6203       t = build (MODIFY_EXPR, valist_type, valist, t);
6204
6205       ofs = (8 - size) % 4;
6206       if (ofs != 0)
6207         {
6208           u = fold_convert (valist_type, size_int (ofs));
6209           t = build (PLUS_EXPR, valist_type, t, u);
6210         }
6211
6212       t = fold_convert (ptr, t);
6213       t = build_fold_indirect_ref (t);
6214
6215       if (indirect)
6216         t = build_fold_indirect_ref (t);
6217
6218       return t;
6219     }
6220 }
6221
6222 /* This routine handles all the normal conditional branch sequences we
6223    might need to generate.  It handles compare immediate vs compare
6224    register, nullification of delay slots, varying length branches,
6225    negated branches, and all combinations of the above.  It returns the
6226    output appropriate to emit the branch corresponding to all given
6227    parameters.  */
6228
6229 const char *
6230 output_cbranch (rtx *operands, int nullify, int length, int negated, rtx insn)
6231 {
6232   static char buf[100];
6233   int useskip = 0;
6234   rtx xoperands[5];
6235
6236   /* A conditional branch to the following instruction (e.g. the delay slot)
6237      is asking for a disaster.  This can happen when not optimizing and
6238      when jump optimization fails.
6239
6240      While it is usually safe to emit nothing, this can fail if the
6241      preceding instruction is a nullified branch with an empty delay
6242      slot and the same branch target as this branch.  We could check
6243      for this but jump optimization should eliminate nop jumps.  It
6244      is always safe to emit a nop.  */
6245   if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6246     return "nop";
6247
6248   /* The doubleword form of the cmpib instruction doesn't have the LEU
6249      and GTU conditions while the cmpb instruction does.  Since we accept
6250      zero for cmpb, we must ensure that we use cmpb for the comparison.  */
6251   if (GET_MODE (operands[1]) == DImode && operands[2] == const0_rtx)
6252     operands[2] = gen_rtx_REG (DImode, 0);
6253
6254   /* If this is a long branch with its delay slot unfilled, set `nullify'
6255      as it can nullify the delay slot and save a nop.  */
6256   if (length == 8 && dbr_sequence_length () == 0)
6257     nullify = 1;
6258
6259   /* If this is a short forward conditional branch which did not get
6260      its delay slot filled, the delay slot can still be nullified.  */
6261   if (! nullify && length == 4 && dbr_sequence_length () == 0)
6262     nullify = forward_branch_p (insn);
6263
6264   /* A forward branch over a single nullified insn can be done with a
6265      comclr instruction.  This avoids a single cycle penalty due to
6266      mis-predicted branch if we fall through (branch not taken).  */
6267   if (length == 4
6268       && next_real_insn (insn) != 0
6269       && get_attr_length (next_real_insn (insn)) == 4
6270       && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6271       && nullify)
6272     useskip = 1;
6273
6274   switch (length)
6275     {
6276       /* All short conditional branches except backwards with an unfilled
6277          delay slot.  */
6278       case 4:
6279         if (useskip)
6280           strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6281         else
6282           strcpy (buf, "{com%I2b,|cmp%I2b,}");
6283         if (GET_MODE (operands[1]) == DImode)
6284           strcat (buf, "*");
6285         if (negated)
6286           strcat (buf, "%B3");
6287         else
6288           strcat (buf, "%S3");
6289         if (useskip)
6290           strcat (buf, " %2,%r1,%%r0");
6291         else if (nullify)
6292           strcat (buf, ",n %2,%r1,%0");
6293         else
6294           strcat (buf, " %2,%r1,%0");
6295         break;
6296
6297      /* All long conditionals.  Note a short backward branch with an
6298         unfilled delay slot is treated just like a long backward branch
6299         with an unfilled delay slot.  */
6300       case 8:
6301         /* Handle weird backwards branch with a filled delay slot
6302            with is nullified.  */
6303         if (dbr_sequence_length () != 0
6304             && ! forward_branch_p (insn)
6305             && nullify)
6306           {
6307             strcpy (buf, "{com%I2b,|cmp%I2b,}");
6308             if (GET_MODE (operands[1]) == DImode)
6309               strcat (buf, "*");
6310             if (negated)
6311               strcat (buf, "%S3");
6312             else
6313               strcat (buf, "%B3");
6314             strcat (buf, ",n %2,%r1,.+12\n\tb %0");
6315           }
6316         /* Handle short backwards branch with an unfilled delay slot.
6317            Using a comb;nop rather than comiclr;bl saves 1 cycle for both
6318            taken and untaken branches.  */
6319         else if (dbr_sequence_length () == 0
6320                  && ! forward_branch_p (insn)
6321                  && INSN_ADDRESSES_SET_P ()
6322                  && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6323                                     - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6324           {
6325             strcpy (buf, "{com%I2b,|cmp%I2b,}");
6326             if (GET_MODE (operands[1]) == DImode)
6327               strcat (buf, "*");
6328             if (negated)
6329               strcat (buf, "%B3 %2,%r1,%0%#");
6330             else
6331               strcat (buf, "%S3 %2,%r1,%0%#");
6332           }
6333         else
6334           {
6335             strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6336             if (GET_MODE (operands[1]) == DImode)
6337               strcat (buf, "*");
6338             if (negated)
6339               strcat (buf, "%S3");
6340             else
6341               strcat (buf, "%B3");
6342             if (nullify)
6343               strcat (buf, " %2,%r1,%%r0\n\tb,n %0");
6344             else
6345               strcat (buf, " %2,%r1,%%r0\n\tb %0");
6346           }
6347         break;
6348
6349       case 20:
6350       case 28:
6351         xoperands[0] = operands[0];
6352         xoperands[1] = operands[1];
6353         xoperands[2] = operands[2];
6354         xoperands[3] = operands[3];
6355
6356         /* The reversed conditional branch must branch over one additional
6357            instruction if the delay slot is filled.  If the delay slot
6358            is empty, the instruction after the reversed condition branch
6359            must be nullified.  */
6360         nullify = dbr_sequence_length () == 0;
6361         xoperands[4] = nullify ? GEN_INT (length) : GEN_INT (length + 4);
6362
6363         /* Create a reversed conditional branch which branches around
6364            the following insns.  */
6365         if (GET_MODE (operands[1]) != DImode)
6366           {
6367             if (nullify)
6368               {
6369                 if (negated)
6370                   strcpy (buf,
6371                     "{com%I2b,%S3,n %2,%r1,.+%4|cmp%I2b,%S3,n %2,%r1,.+%4}");
6372                 else
6373                   strcpy (buf,
6374                     "{com%I2b,%B3,n %2,%r1,.+%4|cmp%I2b,%B3,n %2,%r1,.+%4}");
6375               }
6376             else
6377               {
6378                 if (negated)
6379                   strcpy (buf,
6380                     "{com%I2b,%S3 %2,%r1,.+%4|cmp%I2b,%S3 %2,%r1,.+%4}");
6381                 else
6382                   strcpy (buf,
6383                     "{com%I2b,%B3 %2,%r1,.+%4|cmp%I2b,%B3 %2,%r1,.+%4}");
6384               }
6385           }
6386         else
6387           {
6388             if (nullify)
6389               {
6390                 if (negated)
6391                   strcpy (buf,
6392                     "{com%I2b,*%S3,n %2,%r1,.+%4|cmp%I2b,*%S3,n %2,%r1,.+%4}");
6393                 else
6394                   strcpy (buf,
6395                     "{com%I2b,*%B3,n %2,%r1,.+%4|cmp%I2b,*%B3,n %2,%r1,.+%4}");
6396               }
6397             else
6398               {
6399                 if (negated)
6400                   strcpy (buf,
6401                     "{com%I2b,*%S3 %2,%r1,.+%4|cmp%I2b,*%S3 %2,%r1,.+%4}");
6402                 else
6403                   strcpy (buf,
6404                     "{com%I2b,*%B3 %2,%r1,.+%4|cmp%I2b,*%B3 %2,%r1,.+%4}");
6405               }
6406           }
6407
6408         output_asm_insn (buf, xoperands);
6409         return output_lbranch (operands[0], insn);
6410
6411       default:
6412         abort ();
6413     }
6414   return buf;
6415 }
6416
6417 /* This routine handles long unconditional branches that exceed the
6418    maximum range of a simple branch instruction.  */
6419
6420 const char *
6421 output_lbranch (rtx dest, rtx insn)
6422 {
6423   rtx xoperands[2];
6424  
6425   xoperands[0] = dest;
6426
6427   /* First, free up the delay slot.  */
6428   if (dbr_sequence_length () != 0)
6429     {
6430       /* We can't handle a jump in the delay slot.  */
6431       if (GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
6432         abort ();
6433
6434       final_scan_insn (NEXT_INSN (insn), asm_out_file,
6435                        optimize, 0, 0, NULL);
6436
6437       /* Now delete the delay insn.  */
6438       PUT_CODE (NEXT_INSN (insn), NOTE);
6439       NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
6440       NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
6441     }
6442
6443   /* Output an insn to save %r1.  The runtime documentation doesn't
6444      specify whether the "Clean Up" slot in the callers frame can
6445      be clobbered by the callee.  It isn't copied by HP's builtin
6446      alloca, so this suggests that it can be clobbered if necessary.
6447      The "Static Link" location is copied by HP builtin alloca, so
6448      we avoid using it.  Using the cleanup slot might be a problem
6449      if we have to interoperate with languages that pass cleanup
6450      information.  However, it should be possible to handle these
6451      situations with GCC's asm feature.
6452
6453      The "Current RP" slot is reserved for the called procedure, so
6454      we try to use it when we don't have a frame of our own.  It's
6455      rather unlikely that we won't have a frame when we need to emit
6456      a very long branch.
6457
6458      Really the way to go long term is a register scavenger; goto
6459      the target of the jump and find a register which we can use
6460      as a scratch to hold the value in %r1.  Then, we wouldn't have
6461      to free up the delay slot or clobber a slot that may be needed
6462      for other purposes.  */
6463   if (TARGET_64BIT)
6464     {
6465       if (actual_fsize == 0 && !regs_ever_live[2])
6466         /* Use the return pointer slot in the frame marker.  */
6467         output_asm_insn ("std %%r1,-16(%%r30)", xoperands);
6468       else
6469         /* Use the slot at -40 in the frame marker since HP builtin
6470            alloca doesn't copy it.  */
6471         output_asm_insn ("std %%r1,-40(%%r30)", xoperands);
6472     }
6473   else
6474     {
6475       if (actual_fsize == 0 && !regs_ever_live[2])
6476         /* Use the return pointer slot in the frame marker.  */
6477         output_asm_insn ("stw %%r1,-20(%%r30)", xoperands);
6478       else
6479         /* Use the "Clean Up" slot in the frame marker.  In GCC,
6480            the only other use of this location is for copying a
6481            floating point double argument from a floating-point
6482            register to two general registers.  The copy is done
6483            as an "atomic" operation when outputting a call, so it
6484            won't interfere with our using the location here.  */
6485         output_asm_insn ("stw %%r1,-12(%%r30)", xoperands);
6486     }
6487
6488   if (TARGET_PORTABLE_RUNTIME)
6489     {
6490       output_asm_insn ("ldil L'%0,%%r1", xoperands);
6491       output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
6492       output_asm_insn ("bv %%r0(%%r1)", xoperands);
6493     }
6494   else if (flag_pic)
6495     {
6496       output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
6497       if (TARGET_SOM || !TARGET_GAS)
6498         {
6499           xoperands[1] = gen_label_rtx ();
6500           output_asm_insn ("addil L'%l0-%l1,%%r1", xoperands);
6501           (*targetm.asm_out.internal_label) (asm_out_file, "L",
6502                                              CODE_LABEL_NUMBER (xoperands[1]));
6503           output_asm_insn ("ldo R'%l0-%l1(%%r1),%%r1", xoperands);
6504         }
6505       else
6506         {
6507           output_asm_insn ("addil L'%l0-$PIC_pcrel$0+4,%%r1", xoperands);
6508           output_asm_insn ("ldo R'%l0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
6509         }
6510       output_asm_insn ("bv %%r0(%%r1)", xoperands);
6511     }
6512   else
6513     /* Now output a very long branch to the original target.  */
6514     output_asm_insn ("ldil L'%l0,%%r1\n\tbe R'%l0(%%sr4,%%r1)", xoperands);
6515
6516   /* Now restore the value of %r1 in the delay slot.  */
6517   if (TARGET_64BIT)
6518     {
6519       if (actual_fsize == 0 && !regs_ever_live[2])
6520         return "ldd -16(%%r30),%%r1";
6521       else
6522         return "ldd -40(%%r30),%%r1";
6523     }
6524   else
6525     {
6526       if (actual_fsize == 0 && !regs_ever_live[2])
6527         return "ldw -20(%%r30),%%r1";
6528       else
6529         return "ldw -12(%%r30),%%r1";
6530     }
6531 }
6532
6533 /* This routine handles all the branch-on-bit conditional branch sequences we
6534    might need to generate.  It handles nullification of delay slots,
6535    varying length branches, negated branches and all combinations of the
6536    above.  it returns the appropriate output template to emit the branch.  */
6537
6538 const char *
6539 output_bb (rtx *operands ATTRIBUTE_UNUSED, int nullify, int length,
6540            int negated, rtx insn, int which)
6541 {
6542   static char buf[100];
6543   int useskip = 0;
6544
6545   /* A conditional branch to the following instruction (e.g. the delay slot) is
6546      asking for a disaster.  I do not think this can happen as this pattern
6547      is only used when optimizing; jump optimization should eliminate the
6548      jump.  But be prepared just in case.  */
6549
6550   if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6551     return "nop";
6552
6553   /* If this is a long branch with its delay slot unfilled, set `nullify'
6554      as it can nullify the delay slot and save a nop.  */
6555   if (length == 8 && dbr_sequence_length () == 0)
6556     nullify = 1;
6557
6558   /* If this is a short forward conditional branch which did not get
6559      its delay slot filled, the delay slot can still be nullified.  */
6560   if (! nullify && length == 4 && dbr_sequence_length () == 0)
6561     nullify = forward_branch_p (insn);
6562
6563   /* A forward branch over a single nullified insn can be done with a
6564      extrs instruction.  This avoids a single cycle penalty due to
6565      mis-predicted branch if we fall through (branch not taken).  */
6566
6567   if (length == 4
6568       && next_real_insn (insn) != 0
6569       && get_attr_length (next_real_insn (insn)) == 4
6570       && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6571       && nullify)
6572     useskip = 1;
6573
6574   switch (length)
6575     {
6576
6577       /* All short conditional branches except backwards with an unfilled
6578          delay slot.  */
6579       case 4:
6580         if (useskip)
6581           strcpy (buf, "{extrs,|extrw,s,}");
6582         else
6583           strcpy (buf, "bb,");
6584         if (useskip && GET_MODE (operands[0]) == DImode)
6585           strcpy (buf, "extrd,s,*");
6586         else if (GET_MODE (operands[0]) == DImode)
6587           strcpy (buf, "bb,*");
6588         if ((which == 0 && negated)
6589              || (which == 1 && ! negated))
6590           strcat (buf, ">=");
6591         else
6592           strcat (buf, "<");
6593         if (useskip)
6594           strcat (buf, " %0,%1,1,%%r0");
6595         else if (nullify && negated)
6596           strcat (buf, ",n %0,%1,%3");
6597         else if (nullify && ! negated)
6598           strcat (buf, ",n %0,%1,%2");
6599         else if (! nullify && negated)
6600           strcat (buf, "%0,%1,%3");
6601         else if (! nullify && ! negated)
6602           strcat (buf, " %0,%1,%2");
6603         break;
6604
6605      /* All long conditionals.  Note a short backward branch with an
6606         unfilled delay slot is treated just like a long backward branch
6607         with an unfilled delay slot.  */
6608       case 8:
6609         /* Handle weird backwards branch with a filled delay slot
6610            with is nullified.  */
6611         if (dbr_sequence_length () != 0
6612             && ! forward_branch_p (insn)
6613             && nullify)
6614           {
6615             strcpy (buf, "bb,");
6616             if (GET_MODE (operands[0]) == DImode)
6617               strcat (buf, "*");
6618             if ((which == 0 && negated)
6619                 || (which == 1 && ! negated))
6620               strcat (buf, "<");
6621             else
6622               strcat (buf, ">=");
6623             if (negated)
6624               strcat (buf, ",n %0,%1,.+12\n\tb %3");
6625             else
6626               strcat (buf, ",n %0,%1,.+12\n\tb %2");
6627           }
6628         /* Handle short backwards branch with an unfilled delay slot.
6629            Using a bb;nop rather than extrs;bl saves 1 cycle for both
6630            taken and untaken branches.  */
6631         else if (dbr_sequence_length () == 0
6632                  && ! forward_branch_p (insn)
6633                  && INSN_ADDRESSES_SET_P ()
6634                  && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6635                                     - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6636           {
6637             strcpy (buf, "bb,");
6638             if (GET_MODE (operands[0]) == DImode)
6639               strcat (buf, "*");
6640             if ((which == 0 && negated)
6641                 || (which == 1 && ! negated))
6642               strcat (buf, ">=");
6643             else
6644               strcat (buf, "<");
6645             if (negated)
6646               strcat (buf, " %0,%1,%3%#");
6647             else
6648               strcat (buf, " %0,%1,%2%#");
6649           }
6650         else
6651           {
6652             strcpy (buf, "{extrs,|extrw,s,}");
6653             if (GET_MODE (operands[0]) == DImode)
6654               strcpy (buf, "extrd,s,*");
6655             if ((which == 0 && negated)
6656                 || (which == 1 && ! negated))
6657               strcat (buf, "<");
6658             else
6659               strcat (buf, ">=");
6660             if (nullify && negated)
6661               strcat (buf, " %0,%1,1,%%r0\n\tb,n %3");
6662             else if (nullify && ! negated)
6663               strcat (buf, " %0,%1,1,%%r0\n\tb,n %2");
6664             else if (negated)
6665               strcat (buf, " %0,%1,1,%%r0\n\tb %3");
6666             else
6667               strcat (buf, " %0,%1,1,%%r0\n\tb %2");
6668           }
6669         break;
6670
6671       default:
6672         abort ();
6673     }
6674   return buf;
6675 }
6676
6677 /* This routine handles all the branch-on-variable-bit conditional branch
6678    sequences we might need to generate.  It handles nullification of delay
6679    slots, varying length branches, negated branches and all combinations
6680    of the above.  it returns the appropriate output template to emit the
6681    branch.  */
6682
6683 const char *
6684 output_bvb (rtx *operands ATTRIBUTE_UNUSED, int nullify, int length,
6685             int negated, rtx insn, int which)
6686 {
6687   static char buf[100];
6688   int useskip = 0;
6689
6690   /* A conditional branch to the following instruction (e.g. the delay slot) is
6691      asking for a disaster.  I do not think this can happen as this pattern
6692      is only used when optimizing; jump optimization should eliminate the
6693      jump.  But be prepared just in case.  */
6694
6695   if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6696     return "nop";
6697
6698   /* If this is a long branch with its delay slot unfilled, set `nullify'
6699      as it can nullify the delay slot and save a nop.  */
6700   if (length == 8 && dbr_sequence_length () == 0)
6701     nullify = 1;
6702
6703   /* If this is a short forward conditional branch which did not get
6704      its delay slot filled, the delay slot can still be nullified.  */
6705   if (! nullify && length == 4 && dbr_sequence_length () == 0)
6706     nullify = forward_branch_p (insn);
6707
6708   /* A forward branch over a single nullified insn can be done with a
6709      extrs instruction.  This avoids a single cycle penalty due to
6710      mis-predicted branch if we fall through (branch not taken).  */
6711
6712   if (length == 4
6713       && next_real_insn (insn) != 0
6714       && get_attr_length (next_real_insn (insn)) == 4
6715       && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6716       && nullify)
6717     useskip = 1;
6718
6719   switch (length)
6720     {
6721
6722       /* All short conditional branches except backwards with an unfilled
6723          delay slot.  */
6724       case 4:
6725         if (useskip)
6726           strcpy (buf, "{vextrs,|extrw,s,}");
6727         else
6728           strcpy (buf, "{bvb,|bb,}");
6729         if (useskip && GET_MODE (operands[0]) == DImode)
6730           strcpy (buf, "extrd,s,*");
6731         else if (GET_MODE (operands[0]) == DImode)
6732           strcpy (buf, "bb,*");
6733         if ((which == 0 && negated)
6734              || (which == 1 && ! negated))
6735           strcat (buf, ">=");
6736         else
6737           strcat (buf, "<");
6738         if (useskip)
6739           strcat (buf, "{ %0,1,%%r0| %0,%%sar,1,%%r0}");
6740         else if (nullify && negated)
6741           strcat (buf, "{,n %0,%3|,n %0,%%sar,%3}");
6742         else if (nullify && ! negated)
6743           strcat (buf, "{,n %0,%2|,n %0,%%sar,%2}");
6744         else if (! nullify && negated)
6745           strcat (buf, "{%0,%3|%0,%%sar,%3}");
6746         else if (! nullify && ! negated)
6747           strcat (buf, "{ %0,%2| %0,%%sar,%2}");
6748         break;
6749
6750      /* All long conditionals.  Note a short backward branch with an
6751         unfilled delay slot is treated just like a long backward branch
6752         with an unfilled delay slot.  */
6753       case 8:
6754         /* Handle weird backwards branch with a filled delay slot
6755            with is nullified.  */
6756         if (dbr_sequence_length () != 0
6757             && ! forward_branch_p (insn)
6758             && nullify)
6759           {
6760             strcpy (buf, "{bvb,|bb,}");
6761             if (GET_MODE (operands[0]) == DImode)
6762               strcat (buf, "*");
6763             if ((which == 0 && negated)
6764                 || (which == 1 && ! negated))
6765               strcat (buf, "<");
6766             else
6767               strcat (buf, ">=");
6768             if (negated)
6769               strcat (buf, "{,n %0,.+12\n\tb %3|,n %0,%%sar,.+12\n\tb %3}");
6770             else
6771               strcat (buf, "{,n %0,.+12\n\tb %2|,n %0,%%sar,.+12\n\tb %2}");
6772           }
6773         /* Handle short backwards branch with an unfilled delay slot.
6774            Using a bb;nop rather than extrs;bl saves 1 cycle for both
6775            taken and untaken branches.  */
6776         else if (dbr_sequence_length () == 0
6777                  && ! forward_branch_p (insn)
6778                  && INSN_ADDRESSES_SET_P ()
6779                  && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6780                                     - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6781           {
6782             strcpy (buf, "{bvb,|bb,}");
6783             if (GET_MODE (operands[0]) == DImode)
6784               strcat (buf, "*");
6785             if ((which == 0 && negated)
6786                 || (which == 1 && ! negated))
6787               strcat (buf, ">=");
6788             else
6789               strcat (buf, "<");
6790             if (negated)
6791               strcat (buf, "{ %0,%3%#| %0,%%sar,%3%#}");
6792             else
6793               strcat (buf, "{ %0,%2%#| %0,%%sar,%2%#}");
6794           }
6795         else
6796           {
6797             strcpy (buf, "{vextrs,|extrw,s,}");
6798             if (GET_MODE (operands[0]) == DImode)
6799               strcpy (buf, "extrd,s,*");
6800             if ((which == 0 && negated)
6801                 || (which == 1 && ! negated))
6802               strcat (buf, "<");
6803             else
6804               strcat (buf, ">=");
6805             if (nullify && negated)
6806               strcat (buf, "{ %0,1,%%r0\n\tb,n %3| %0,%%sar,1,%%r0\n\tb,n %3}");
6807             else if (nullify && ! negated)
6808               strcat (buf, "{ %0,1,%%r0\n\tb,n %2| %0,%%sar,1,%%r0\n\tb,n %2}");
6809             else if (negated)
6810               strcat (buf, "{ %0,1,%%r0\n\tb %3| %0,%%sar,1,%%r0\n\tb %3}");
6811             else
6812               strcat (buf, "{ %0,1,%%r0\n\tb %2| %0,%%sar,1,%%r0\n\tb %2}");
6813           }
6814         break;
6815
6816       default:
6817         abort ();
6818     }
6819   return buf;
6820 }
6821
6822 /* Return the output template for emitting a dbra type insn.
6823
6824    Note it may perform some output operations on its own before
6825    returning the final output string.  */
6826 const char *
6827 output_dbra (rtx *operands, rtx insn, int which_alternative)
6828 {
6829
6830   /* A conditional branch to the following instruction (e.g. the delay slot) is
6831      asking for a disaster.  Be prepared!  */
6832
6833   if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6834     {
6835       if (which_alternative == 0)
6836         return "ldo %1(%0),%0";
6837       else if (which_alternative == 1)
6838         {
6839           output_asm_insn ("{fstws|fstw} %0,-16(%%r30)", operands);
6840           output_asm_insn ("ldw -16(%%r30),%4", operands);
6841           output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
6842           return "{fldws|fldw} -16(%%r30),%0";
6843         }
6844       else
6845         {
6846           output_asm_insn ("ldw %0,%4", operands);
6847           return "ldo %1(%4),%4\n\tstw %4,%0";
6848         }
6849     }
6850
6851   if (which_alternative == 0)
6852     {
6853       int nullify = INSN_ANNULLED_BRANCH_P (insn);
6854       int length = get_attr_length (insn);
6855
6856       /* If this is a long branch with its delay slot unfilled, set `nullify'
6857          as it can nullify the delay slot and save a nop.  */
6858       if (length == 8 && dbr_sequence_length () == 0)
6859         nullify = 1;
6860
6861       /* If this is a short forward conditional branch which did not get
6862          its delay slot filled, the delay slot can still be nullified.  */
6863       if (! nullify && length == 4 && dbr_sequence_length () == 0)
6864         nullify = forward_branch_p (insn);
6865
6866       /* Handle short versions first.  */
6867       if (length == 4 && nullify)
6868         return "addib,%C2,n %1,%0,%3";
6869       else if (length == 4 && ! nullify)
6870         return "addib,%C2 %1,%0,%3";
6871       else if (length == 8)
6872         {
6873           /* Handle weird backwards branch with a fulled delay slot
6874              which is nullified.  */
6875           if (dbr_sequence_length () != 0
6876               && ! forward_branch_p (insn)
6877               && nullify)
6878             return "addib,%N2,n %1,%0,.+12\n\tb %3";
6879           /* Handle short backwards branch with an unfilled delay slot.
6880              Using a addb;nop rather than addi;bl saves 1 cycle for both
6881              taken and untaken branches.  */
6882           else if (dbr_sequence_length () == 0
6883                    && ! forward_branch_p (insn)
6884                    && INSN_ADDRESSES_SET_P ()
6885                    && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6886                                       - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6887               return "addib,%C2 %1,%0,%3%#";
6888
6889           /* Handle normal cases.  */
6890           if (nullify)
6891             return "addi,%N2 %1,%0,%0\n\tb,n %3";
6892           else
6893             return "addi,%N2 %1,%0,%0\n\tb %3";
6894         }
6895       else
6896         abort ();
6897     }
6898   /* Deal with gross reload from FP register case.  */
6899   else if (which_alternative == 1)
6900     {
6901       /* Move loop counter from FP register to MEM then into a GR,
6902          increment the GR, store the GR into MEM, and finally reload
6903          the FP register from MEM from within the branch's delay slot.  */
6904       output_asm_insn ("{fstws|fstw} %0,-16(%%r30)\n\tldw -16(%%r30),%4",
6905                        operands);
6906       output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
6907       if (get_attr_length (insn) == 24)
6908         return "{comb|cmpb},%S2 %%r0,%4,%3\n\t{fldws|fldw} -16(%%r30),%0";
6909       else
6910         return "{comclr|cmpclr},%B2 %%r0,%4,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
6911     }
6912   /* Deal with gross reload from memory case.  */
6913   else
6914     {
6915       /* Reload loop counter from memory, the store back to memory
6916          happens in the branch's delay slot.  */
6917       output_asm_insn ("ldw %0,%4", operands);
6918       if (get_attr_length (insn) == 12)
6919         return "addib,%C2 %1,%4,%3\n\tstw %4,%0";
6920       else
6921         return "addi,%N2 %1,%4,%4\n\tb %3\n\tstw %4,%0";
6922     }
6923 }
6924
6925 /* Return the output template for emitting a dbra type insn.
6926
6927    Note it may perform some output operations on its own before
6928    returning the final output string.  */
6929 const char *
6930 output_movb (rtx *operands, rtx insn, int which_alternative,
6931              int reverse_comparison)
6932 {
6933
6934   /* A conditional branch to the following instruction (e.g. the delay slot) is
6935      asking for a disaster.  Be prepared!  */
6936
6937   if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6938     {
6939       if (which_alternative == 0)
6940         return "copy %1,%0";
6941       else if (which_alternative == 1)
6942         {
6943           output_asm_insn ("stw %1,-16(%%r30)", operands);
6944           return "{fldws|fldw} -16(%%r30),%0";
6945         }
6946       else if (which_alternative == 2)
6947         return "stw %1,%0";
6948       else
6949         return "mtsar %r1";
6950     }
6951
6952   /* Support the second variant.  */
6953   if (reverse_comparison)
6954     PUT_CODE (operands[2], reverse_condition (GET_CODE (operands[2])));
6955
6956   if (which_alternative == 0)
6957     {
6958       int nullify = INSN_ANNULLED_BRANCH_P (insn);
6959       int length = get_attr_length (insn);
6960
6961       /* If this is a long branch with its delay slot unfilled, set `nullify'
6962          as it can nullify the delay slot and save a nop.  */
6963       if (length == 8 && dbr_sequence_length () == 0)
6964         nullify = 1;
6965
6966       /* If this is a short forward conditional branch which did not get
6967          its delay slot filled, the delay slot can still be nullified.  */
6968       if (! nullify && length == 4 && dbr_sequence_length () == 0)
6969         nullify = forward_branch_p (insn);
6970
6971       /* Handle short versions first.  */
6972       if (length == 4 && nullify)
6973         return "movb,%C2,n %1,%0,%3";
6974       else if (length == 4 && ! nullify)
6975         return "movb,%C2 %1,%0,%3";
6976       else if (length == 8)
6977         {
6978           /* Handle weird backwards branch with a filled delay slot
6979              which is nullified.  */
6980           if (dbr_sequence_length () != 0
6981               && ! forward_branch_p (insn)
6982               && nullify)
6983             return "movb,%N2,n %1,%0,.+12\n\tb %3";
6984
6985           /* Handle short backwards branch with an unfilled delay slot.
6986              Using a movb;nop rather than or;bl saves 1 cycle for both
6987              taken and untaken branches.  */
6988           else if (dbr_sequence_length () == 0
6989                    && ! forward_branch_p (insn)
6990                    && INSN_ADDRESSES_SET_P ()
6991                    && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6992                                       - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6993             return "movb,%C2 %1,%0,%3%#";
6994           /* Handle normal cases.  */
6995           if (nullify)
6996             return "or,%N2 %1,%%r0,%0\n\tb,n %3";
6997           else
6998             return "or,%N2 %1,%%r0,%0\n\tb %3";
6999         }
7000       else
7001         abort ();
7002     }
7003   /* Deal with gross reload from FP register case.  */
7004   else if (which_alternative == 1)
7005     {
7006       /* Move loop counter from FP register to MEM then into a GR,
7007          increment the GR, store the GR into MEM, and finally reload
7008          the FP register from MEM from within the branch's delay slot.  */
7009       output_asm_insn ("stw %1,-16(%%r30)", operands);
7010       if (get_attr_length (insn) == 12)
7011         return "{comb|cmpb},%S2 %%r0,%1,%3\n\t{fldws|fldw} -16(%%r30),%0";
7012       else
7013         return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
7014     }
7015   /* Deal with gross reload from memory case.  */
7016   else if (which_alternative == 2)
7017     {
7018       /* Reload loop counter from memory, the store back to memory
7019          happens in the branch's delay slot.  */
7020       if (get_attr_length (insn) == 8)
7021         return "{comb|cmpb},%S2 %%r0,%1,%3\n\tstw %1,%0";
7022       else
7023         return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tstw %1,%0";
7024     }
7025   /* Handle SAR as a destination.  */
7026   else
7027     {
7028       if (get_attr_length (insn) == 8)
7029         return "{comb|cmpb},%S2 %%r0,%1,%3\n\tmtsar %r1";
7030       else
7031         return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tmtsar %r1";
7032     }
7033 }
7034
7035 /* Copy any FP arguments in INSN into integer registers.  */
7036 static void
7037 copy_fp_args (rtx insn)
7038 {
7039   rtx link;
7040   rtx xoperands[2];
7041
7042   for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7043     {
7044       int arg_mode, regno;
7045       rtx use = XEXP (link, 0);
7046
7047       if (! (GET_CODE (use) == USE
7048           && GET_CODE (XEXP (use, 0)) == REG
7049           && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7050         continue;
7051
7052       arg_mode = GET_MODE (XEXP (use, 0));
7053       regno = REGNO (XEXP (use, 0));
7054
7055       /* Is it a floating point register?  */
7056       if (regno >= 32 && regno <= 39)
7057         {
7058           /* Copy the FP register into an integer register via memory.  */
7059           if (arg_mode == SFmode)
7060             {
7061               xoperands[0] = XEXP (use, 0);
7062               xoperands[1] = gen_rtx_REG (SImode, 26 - (regno - 32) / 2);
7063               output_asm_insn ("{fstws|fstw} %0,-16(%%sr0,%%r30)", xoperands);
7064               output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7065             }
7066           else
7067             {
7068               xoperands[0] = XEXP (use, 0);
7069               xoperands[1] = gen_rtx_REG (DImode, 25 - (regno - 34) / 2);
7070               output_asm_insn ("{fstds|fstd} %0,-16(%%sr0,%%r30)", xoperands);
7071               output_asm_insn ("ldw -12(%%sr0,%%r30),%R1", xoperands);
7072               output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7073             }
7074         }
7075     }
7076 }
7077
7078 /* Compute length of the FP argument copy sequence for INSN.  */
7079 static int
7080 length_fp_args (rtx insn)
7081 {
7082   int length = 0;
7083   rtx link;
7084
7085   for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7086     {
7087       int arg_mode, regno;
7088       rtx use = XEXP (link, 0);
7089
7090       if (! (GET_CODE (use) == USE
7091           && GET_CODE (XEXP (use, 0)) == REG
7092           && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7093         continue;
7094
7095       arg_mode = GET_MODE (XEXP (use, 0));
7096       regno = REGNO (XEXP (use, 0));
7097
7098       /* Is it a floating point register?  */
7099       if (regno >= 32 && regno <= 39)
7100         {
7101           if (arg_mode == SFmode)
7102             length += 8;
7103           else
7104             length += 12;
7105         }
7106     }
7107
7108   return length;
7109 }
7110
7111 /* Return the attribute length for the millicode call instruction INSN.
7112    The length must match the code generated by output_millicode_call.
7113    We include the delay slot in the returned length as it is better to
7114    over estimate the length than to under estimate it.  */
7115
7116 int
7117 attr_length_millicode_call (rtx insn)
7118 {
7119   unsigned long distance = -1;
7120   unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7121
7122   if (INSN_ADDRESSES_SET_P ())
7123     {
7124       distance = (total + insn_current_reference_address (insn));
7125       if (distance < total)
7126         distance = -1;
7127     }
7128
7129   if (TARGET_64BIT)
7130     {
7131       if (!TARGET_LONG_CALLS && distance < 7600000)
7132         return 8;
7133
7134       return 20;
7135     }
7136   else if (TARGET_PORTABLE_RUNTIME)
7137     return 24;
7138   else
7139     {
7140       if (!TARGET_LONG_CALLS && distance < 240000)
7141         return 8;
7142
7143       if (TARGET_LONG_ABS_CALL && !flag_pic)
7144         return 12;
7145
7146       return 24;
7147     }
7148 }
7149
7150 /* INSN is a function call.  It may have an unconditional jump
7151    in its delay slot.
7152
7153    CALL_DEST is the routine we are calling.  */
7154
7155 const char *
7156 output_millicode_call (rtx insn, rtx call_dest)
7157 {
7158   int attr_length = get_attr_length (insn);
7159   int seq_length = dbr_sequence_length ();
7160   int distance;
7161   rtx seq_insn;
7162   rtx xoperands[3];
7163
7164   xoperands[0] = call_dest;
7165   xoperands[2] = gen_rtx_REG (Pmode, TARGET_64BIT ? 2 : 31);
7166
7167   /* Handle the common case where we are sure that the branch will
7168      reach the beginning of the $CODE$ subspace.  The within reach
7169      form of the $$sh_func_adrs call has a length of 28.  Because
7170      it has an attribute type of multi, it never has a nonzero
7171      sequence length.  The length of the $$sh_func_adrs is the same
7172      as certain out of reach PIC calls to other routines.  */
7173   if (!TARGET_LONG_CALLS
7174       && ((seq_length == 0
7175            && (attr_length == 12
7176                || (attr_length == 28 && get_attr_type (insn) == TYPE_MULTI)))
7177           || (seq_length != 0 && attr_length == 8)))
7178     {
7179       output_asm_insn ("{bl|b,l} %0,%2", xoperands);
7180     }
7181   else
7182     {
7183       if (TARGET_64BIT)
7184         {
7185           /* It might seem that one insn could be saved by accessing
7186              the millicode function using the linkage table.  However,
7187              this doesn't work in shared libraries and other dynamically
7188              loaded objects.  Using a pc-relative sequence also avoids
7189              problems related to the implicit use of the gp register.  */
7190           output_asm_insn ("b,l .+8,%%r1", xoperands);
7191
7192           if (TARGET_GAS)
7193             {
7194               output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
7195               output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
7196             }
7197           else
7198             {
7199               xoperands[1] = gen_label_rtx ();
7200               output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7201               (*targetm.asm_out.internal_label) (asm_out_file, "L",
7202                                          CODE_LABEL_NUMBER (xoperands[1]));
7203               output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7204             }
7205
7206           output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7207         }
7208       else if (TARGET_PORTABLE_RUNTIME)
7209         {
7210           /* Pure portable runtime doesn't allow be/ble; we also don't
7211              have PIC support in the assembler/linker, so this sequence
7212              is needed.  */
7213
7214           /* Get the address of our target into %r1.  */
7215           output_asm_insn ("ldil L'%0,%%r1", xoperands);
7216           output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
7217
7218           /* Get our return address into %r31.  */
7219           output_asm_insn ("{bl|b,l} .+8,%%r31", xoperands);
7220           output_asm_insn ("addi 8,%%r31,%%r31", xoperands);
7221
7222           /* Jump to our target address in %r1.  */
7223           output_asm_insn ("bv %%r0(%%r1)", xoperands);
7224         }
7225       else if (!flag_pic)
7226         {
7227           output_asm_insn ("ldil L'%0,%%r1", xoperands);
7228           if (TARGET_PA_20)
7229             output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31", xoperands);
7230           else
7231             output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
7232         }
7233       else
7234         {
7235           output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7236           output_asm_insn ("addi 16,%%r1,%%r31", xoperands);
7237
7238           if (TARGET_SOM || !TARGET_GAS)
7239             {
7240               /* The HP assembler can generate relocations for the
7241                  difference of two symbols.  GAS can do this for a
7242                  millicode symbol but not an arbitrary external
7243                  symbol when generating SOM output.  */
7244               xoperands[1] = gen_label_rtx ();
7245               (*targetm.asm_out.internal_label) (asm_out_file, "L",
7246                                          CODE_LABEL_NUMBER (xoperands[1]));
7247               output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7248               output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7249             }
7250           else
7251             {
7252               output_asm_insn ("addil L'%0-$PIC_pcrel$0+8,%%r1", xoperands);
7253               output_asm_insn ("ldo R'%0-$PIC_pcrel$0+12(%%r1),%%r1",
7254                                xoperands);
7255             }
7256
7257           /* Jump to our target address in %r1.  */
7258           output_asm_insn ("bv %%r0(%%r1)", xoperands);
7259         }
7260     }
7261
7262   if (seq_length == 0)
7263     output_asm_insn ("nop", xoperands);
7264
7265   /* We are done if there isn't a jump in the delay slot.  */
7266   if (seq_length == 0 || GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
7267     return "";
7268
7269   /* This call has an unconditional jump in its delay slot.  */
7270   xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
7271
7272   /* See if the return address can be adjusted.  Use the containing
7273      sequence insn's address.  */
7274   if (INSN_ADDRESSES_SET_P ())
7275     {
7276       seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
7277       distance = (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
7278                   - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8);
7279
7280       if (VAL_14_BITS_P (distance))
7281         {
7282           xoperands[1] = gen_label_rtx ();
7283           output_asm_insn ("ldo %0-%1(%2),%2", xoperands);
7284           (*targetm.asm_out.internal_label) (asm_out_file, "L",
7285                                              CODE_LABEL_NUMBER (xoperands[1]));
7286         }
7287       else
7288         /* ??? This branch may not reach its target.  */
7289         output_asm_insn ("nop\n\tb,n %0", xoperands);
7290     }
7291   else
7292     /* ??? This branch may not reach its target.  */
7293     output_asm_insn ("nop\n\tb,n %0", xoperands);
7294
7295   /* Delete the jump.  */
7296   PUT_CODE (NEXT_INSN (insn), NOTE);
7297   NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7298   NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7299
7300   return "";
7301 }
7302
7303 /* Return the attribute length of the call instruction INSN.  The SIBCALL
7304    flag indicates whether INSN is a regular call or a sibling call.  The
7305    length returned must be longer than the code actually generated by
7306    output_call.  Since branch shortening is done before delay branch
7307    sequencing, there is no way to determine whether or not the delay
7308    slot will be filled during branch shortening.  Even when the delay
7309    slot is filled, we may have to add a nop if the delay slot contains
7310    a branch that can't reach its target.  Thus, we always have to include
7311    the delay slot in the length estimate.  This used to be done in
7312    pa_adjust_insn_length but we do it here now as some sequences always
7313    fill the delay slot and we can save four bytes in the estimate for
7314    these sequences.  */
7315
7316 int
7317 attr_length_call (rtx insn, int sibcall)
7318 {
7319   int local_call;
7320   rtx call_dest;
7321   tree call_decl;
7322   int length = 0;
7323   rtx pat = PATTERN (insn);
7324   unsigned long distance = -1;
7325
7326   if (INSN_ADDRESSES_SET_P ())
7327     {
7328       unsigned long total;
7329
7330       total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7331       distance = (total + insn_current_reference_address (insn));
7332       if (distance < total)
7333         distance = -1;
7334     }
7335
7336   /* Determine if this is a local call.  */
7337   if (GET_CODE (XVECEXP (pat, 0, 0)) == CALL)
7338     call_dest = XEXP (XEXP (XVECEXP (pat, 0, 0), 0), 0);
7339   else
7340     call_dest = XEXP (XEXP (XEXP (XVECEXP (pat, 0, 0), 1), 0), 0);
7341
7342   call_decl = SYMBOL_REF_DECL (call_dest);
7343   local_call = call_decl && (*targetm.binds_local_p) (call_decl);
7344
7345   /* pc-relative branch.  */
7346   if (!TARGET_LONG_CALLS
7347       && ((TARGET_PA_20 && !sibcall && distance < 7600000)
7348           || distance < 240000))
7349     length += 8;
7350
7351   /* 64-bit plabel sequence.  */
7352   else if (TARGET_64BIT && !local_call)
7353     length += sibcall ? 28 : 24;
7354
7355   /* non-pic long absolute branch sequence.  */
7356   else if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7357     length += 12;
7358
7359   /* long pc-relative branch sequence.  */
7360   else if ((TARGET_SOM && TARGET_LONG_PIC_SDIFF_CALL)
7361            || (TARGET_64BIT && !TARGET_GAS)
7362            || (TARGET_GAS && (TARGET_LONG_PIC_PCREL_CALL || local_call)))
7363     {
7364       length += 20;
7365
7366       if (!TARGET_PA_20 && !TARGET_NO_SPACE_REGS)
7367         length += 8;
7368     }
7369
7370   /* 32-bit plabel sequence.  */
7371   else
7372     {
7373       length += 32;
7374
7375       if (TARGET_SOM)
7376         length += length_fp_args (insn);
7377
7378       if (flag_pic)
7379         length += 4;
7380
7381       if (!TARGET_PA_20)
7382         {
7383           if (!sibcall)
7384             length += 8;
7385
7386           if (!TARGET_NO_SPACE_REGS)
7387             length += 8;
7388         }
7389     }
7390
7391   return length;
7392 }
7393
7394 /* INSN is a function call.  It may have an unconditional jump
7395    in its delay slot.
7396
7397    CALL_DEST is the routine we are calling.  */
7398
7399 const char *
7400 output_call (rtx insn, rtx call_dest, int sibcall)
7401 {
7402   int delay_insn_deleted = 0;
7403   int delay_slot_filled = 0;
7404   int seq_length = dbr_sequence_length ();
7405   tree call_decl = SYMBOL_REF_DECL (call_dest);
7406   int local_call = call_decl && (*targetm.binds_local_p) (call_decl);
7407   rtx xoperands[2];
7408
7409   xoperands[0] = call_dest;
7410
7411   /* Handle the common case where we're sure that the branch will reach
7412      the beginning of the "$CODE$" subspace.  This is the beginning of
7413      the current function if we are in a named section.  */
7414   if (!TARGET_LONG_CALLS && attr_length_call (insn, sibcall) == 8)
7415     {
7416       xoperands[1] = gen_rtx_REG (word_mode, sibcall ? 0 : 2);
7417       output_asm_insn ("{bl|b,l} %0,%1", xoperands);
7418     }
7419   else
7420     {
7421       if (TARGET_64BIT && !local_call)
7422         {
7423           /* ??? As far as I can tell, the HP linker doesn't support the
7424              long pc-relative sequence described in the 64-bit runtime
7425              architecture.  So, we use a slightly longer indirect call.  */
7426           struct deferred_plabel *p = get_plabel (XSTR (call_dest, 0));
7427
7428           xoperands[0] = p->internal_label;
7429           xoperands[1] = gen_label_rtx ();
7430
7431           /* If this isn't a sibcall, we put the load of %r27 into the
7432              delay slot.  We can't do this in a sibcall as we don't
7433              have a second call-clobbered scratch register available.  */
7434           if (seq_length != 0
7435               && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
7436               && !sibcall)
7437             {
7438               final_scan_insn (NEXT_INSN (insn), asm_out_file,
7439                                optimize, 0, 0, NULL);
7440
7441               /* Now delete the delay insn.  */
7442               PUT_CODE (NEXT_INSN (insn), NOTE);
7443               NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7444               NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7445               delay_insn_deleted = 1;
7446             }
7447
7448           output_asm_insn ("addil LT'%0,%%r27", xoperands);
7449           output_asm_insn ("ldd RT'%0(%%r1),%%r1", xoperands);
7450           output_asm_insn ("ldd 0(%%r1),%%r1", xoperands);
7451
7452           if (sibcall)
7453             {
7454               output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7455               output_asm_insn ("ldd 16(%%r1),%%r1", xoperands);
7456               output_asm_insn ("bve (%%r1)", xoperands);
7457             }
7458           else
7459             {
7460               output_asm_insn ("ldd 16(%%r1),%%r2", xoperands);
7461               output_asm_insn ("bve,l (%%r2),%%r2", xoperands);
7462               output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7463               delay_slot_filled = 1;
7464             }
7465         }
7466       else
7467         {
7468           int indirect_call = 0;
7469
7470           /* Emit a long call.  There are several different sequences
7471              of increasing length and complexity.  In most cases,
7472              they don't allow an instruction in the delay slot.  */
7473           if (!((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7474               && !(TARGET_SOM && TARGET_LONG_PIC_SDIFF_CALL)
7475               && !(TARGET_GAS && (TARGET_LONG_PIC_PCREL_CALL || local_call))
7476               && !TARGET_64BIT)
7477             indirect_call = 1;
7478
7479           if (seq_length != 0
7480               && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
7481               && !sibcall
7482               && (!TARGET_PA_20 || indirect_call))
7483             {
7484               /* A non-jump insn in the delay slot.  By definition we can
7485                  emit this insn before the call (and in fact before argument
7486                  relocating.  */
7487               final_scan_insn (NEXT_INSN (insn), asm_out_file, optimize, 0, 0,
7488                                NULL);
7489
7490               /* Now delete the delay insn.  */
7491               PUT_CODE (NEXT_INSN (insn), NOTE);
7492               NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7493               NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7494               delay_insn_deleted = 1;
7495             }
7496
7497           if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7498             {
7499               /* This is the best sequence for making long calls in
7500                  non-pic code.  Unfortunately, GNU ld doesn't provide
7501                  the stub needed for external calls, and GAS's support
7502                  for this with the SOM linker is buggy.  It is safe
7503                  to use this for local calls.  */
7504               output_asm_insn ("ldil L'%0,%%r1", xoperands);
7505               if (sibcall)
7506                 output_asm_insn ("be R'%0(%%sr4,%%r1)", xoperands);
7507               else
7508                 {
7509                   if (TARGET_PA_20)
7510                     output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31",
7511                                      xoperands);
7512                   else
7513                     output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
7514
7515                   output_asm_insn ("copy %%r31,%%r2", xoperands);
7516                   delay_slot_filled = 1;
7517                 }
7518             }
7519           else
7520             {
7521               if ((TARGET_SOM && TARGET_LONG_PIC_SDIFF_CALL)
7522                   || (TARGET_64BIT && !TARGET_GAS))
7523                 {
7524                   /* The HP assembler and linker can handle relocations
7525                      for the difference of two symbols.  GAS and the HP
7526                      linker can't do this when one of the symbols is
7527                      external.  */
7528                   xoperands[1] = gen_label_rtx ();
7529                   output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7530                   output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7531                   (*targetm.asm_out.internal_label) (asm_out_file, "L",
7532                                              CODE_LABEL_NUMBER (xoperands[1]));
7533                   output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7534                 }
7535               else if (TARGET_GAS && (TARGET_LONG_PIC_PCREL_CALL || local_call))
7536                 {
7537                   /*  GAS currently can't generate the relocations that
7538                       are needed for the SOM linker under HP-UX using this
7539                       sequence.  The GNU linker doesn't generate the stubs
7540                       that are needed for external calls on TARGET_ELF32
7541                       with this sequence.  For now, we have to use a
7542                       longer plabel sequence when using GAS.  */
7543                   output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7544                   output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1",
7545                                    xoperands);
7546                   output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1",
7547                                    xoperands);
7548                 }
7549               else
7550                 {
7551                   /* Emit a long plabel-based call sequence.  This is
7552                      essentially an inline implementation of $$dyncall.
7553                      We don't actually try to call $$dyncall as this is
7554                      as difficult as calling the function itself.  */
7555                   struct deferred_plabel *p = get_plabel (XSTR (call_dest, 0));
7556
7557                   xoperands[0] = p->internal_label;
7558                   xoperands[1] = gen_label_rtx ();
7559
7560                   /* Since the call is indirect, FP arguments in registers
7561                      need to be copied to the general registers.  Then, the
7562                      argument relocation stub will copy them back.  */
7563                   if (TARGET_SOM)
7564                     copy_fp_args (insn);
7565
7566                   if (flag_pic)
7567                     {
7568                       output_asm_insn ("addil LT'%0,%%r19", xoperands);
7569                       output_asm_insn ("ldw RT'%0(%%r1),%%r1", xoperands);
7570                       output_asm_insn ("ldw 0(%%r1),%%r1", xoperands);
7571                     }
7572                   else
7573                     {
7574                       output_asm_insn ("addil LR'%0-$global$,%%r27",
7575                                        xoperands);
7576                       output_asm_insn ("ldw RR'%0-$global$(%%r1),%%r1",
7577                                        xoperands);
7578                     }
7579
7580                   output_asm_insn ("bb,>=,n %%r1,30,.+16", xoperands);
7581                   output_asm_insn ("depi 0,31,2,%%r1", xoperands);
7582                   output_asm_insn ("ldw 4(%%sr0,%%r1),%%r19", xoperands);
7583                   output_asm_insn ("ldw 0(%%sr0,%%r1),%%r1", xoperands);
7584
7585                   if (!sibcall && !TARGET_PA_20)
7586                     {
7587                       output_asm_insn ("{bl|b,l} .+8,%%r2", xoperands);
7588                       if (TARGET_NO_SPACE_REGS)
7589                         output_asm_insn ("addi 8,%%r2,%%r2", xoperands);
7590                       else
7591                         output_asm_insn ("addi 16,%%r2,%%r2", xoperands);
7592                     }
7593                 }
7594
7595               if (TARGET_PA_20)
7596                 {
7597                   if (sibcall)
7598                     output_asm_insn ("bve (%%r1)", xoperands);
7599                   else
7600                     {
7601                       if (indirect_call)
7602                         {
7603                           output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7604                           output_asm_insn ("stw %%r2,-24(%%sp)", xoperands);
7605                           delay_slot_filled = 1;
7606                         }
7607                       else
7608                         output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7609                     }
7610                 }
7611               else
7612                 {
7613                   if (!TARGET_NO_SPACE_REGS)
7614                     output_asm_insn ("ldsid (%%r1),%%r31\n\tmtsp %%r31,%%sr0",
7615                                      xoperands);
7616
7617                   if (sibcall)
7618                     {
7619                       if (TARGET_NO_SPACE_REGS)
7620                         output_asm_insn ("be 0(%%sr4,%%r1)", xoperands);
7621                       else
7622                         output_asm_insn ("be 0(%%sr0,%%r1)", xoperands);
7623                     }
7624                   else
7625                     {
7626                       if (TARGET_NO_SPACE_REGS)
7627                         output_asm_insn ("ble 0(%%sr4,%%r1)", xoperands);
7628                       else
7629                         output_asm_insn ("ble 0(%%sr0,%%r1)", xoperands);
7630
7631                       if (indirect_call)
7632                         output_asm_insn ("stw %%r31,-24(%%sp)", xoperands);
7633                       else
7634                         output_asm_insn ("copy %%r31,%%r2", xoperands);
7635                       delay_slot_filled = 1;
7636                     }
7637                 }
7638             }
7639         }
7640     }
7641
7642   if (!delay_slot_filled && (seq_length == 0 || delay_insn_deleted))
7643     output_asm_insn ("nop", xoperands);
7644
7645   /* We are done if there isn't a jump in the delay slot.  */
7646   if (seq_length == 0
7647       || delay_insn_deleted
7648       || GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
7649     return "";
7650
7651   /* A sibcall should never have a branch in the delay slot.  */
7652   if (sibcall)
7653     abort ();
7654
7655   /* This call has an unconditional jump in its delay slot.  */
7656   xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
7657
7658   if (!delay_slot_filled && INSN_ADDRESSES_SET_P ())
7659     {
7660       /* See if the return address can be adjusted.  Use the containing
7661          sequence insn's address.  */
7662       rtx seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
7663       int distance = (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
7664                       - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8);
7665
7666       if (VAL_14_BITS_P (distance))
7667         {
7668           xoperands[1] = gen_label_rtx ();
7669           output_asm_insn ("ldo %0-%1(%%r2),%%r2", xoperands);
7670           (*targetm.asm_out.internal_label) (asm_out_file, "L",
7671                                              CODE_LABEL_NUMBER (xoperands[1]));
7672         }
7673       else
7674         output_asm_insn ("nop\n\tb,n %0", xoperands);
7675     }
7676   else
7677     output_asm_insn ("b,n %0", xoperands);
7678
7679   /* Delete the jump.  */
7680   PUT_CODE (NEXT_INSN (insn), NOTE);
7681   NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7682   NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7683
7684   return "";
7685 }
7686
7687 /* Return the attribute length of the indirect call instruction INSN.
7688    The length must match the code generated by output_indirect call.
7689    The returned length includes the delay slot.  Currently, the delay
7690    slot of an indirect call sequence is not exposed and it is used by
7691    the sequence itself.  */
7692
7693 int
7694 attr_length_indirect_call (rtx insn)
7695 {
7696   unsigned long distance = -1;
7697   unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7698
7699   if (INSN_ADDRESSES_SET_P ())
7700     {
7701       distance = (total + insn_current_reference_address (insn));
7702       if (distance < total)
7703         distance = -1;
7704     }
7705
7706   if (TARGET_64BIT)
7707     return 12;
7708
7709   if (TARGET_FAST_INDIRECT_CALLS
7710       || (!TARGET_PORTABLE_RUNTIME
7711           && ((TARGET_PA_20 && distance < 7600000) || distance < 240000)))
7712     return 8;
7713
7714   if (flag_pic)
7715     return 24;
7716
7717   if (TARGET_PORTABLE_RUNTIME)
7718     return 20;
7719
7720   /* Out of reach, can use ble.  */
7721   return 12;
7722 }
7723
7724 const char *
7725 output_indirect_call (rtx insn, rtx call_dest)
7726 {
7727   rtx xoperands[1];
7728
7729   if (TARGET_64BIT)
7730     {
7731       xoperands[0] = call_dest;
7732       output_asm_insn ("ldd 16(%0),%%r2", xoperands);
7733       output_asm_insn ("bve,l (%%r2),%%r2\n\tldd 24(%0),%%r27", xoperands);
7734       return "";
7735     }
7736
7737   /* First the special case for kernels, level 0 systems, etc.  */
7738   if (TARGET_FAST_INDIRECT_CALLS)
7739     return "ble 0(%%sr4,%%r22)\n\tcopy %%r31,%%r2"; 
7740
7741   /* Now the normal case -- we can reach $$dyncall directly or
7742      we're sure that we can get there via a long-branch stub. 
7743
7744      No need to check target flags as the length uniquely identifies
7745      the remaining cases.  */
7746   if (attr_length_indirect_call (insn) == 8)
7747     {
7748       /* The HP linker substitutes a BLE for millicode calls using
7749          the short PIC PCREL form.  Thus, we must use %r31 as the
7750          link register when generating PA 1.x code.  */
7751       if (TARGET_PA_20)
7752         return ".CALL\tARGW0=GR\n\tb,l $$dyncall,%%r2\n\tcopy %%r2,%%r31";
7753       else
7754         return ".CALL\tARGW0=GR\n\tbl $$dyncall,%%r31\n\tcopy %%r31,%%r2";
7755     }
7756
7757   /* Long millicode call, but we are not generating PIC or portable runtime
7758      code.  */
7759   if (attr_length_indirect_call (insn) == 12)
7760     return ".CALL\tARGW0=GR\n\tldil L'$$dyncall,%%r2\n\tble R'$$dyncall(%%sr4,%%r2)\n\tcopy %%r31,%%r2";
7761
7762   /* Long millicode call for portable runtime.  */
7763   if (attr_length_indirect_call (insn) == 20)
7764     return "ldil L'$$dyncall,%%r31\n\tldo R'$$dyncall(%%r31),%%r31\n\tblr %%r0,%%r2\n\tbv,n %%r0(%%r31)\n\tnop";
7765
7766   /* We need a long PIC call to $$dyncall.  */
7767   xoperands[0] = NULL_RTX;
7768   output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7769   if (TARGET_SOM || !TARGET_GAS)
7770     {
7771       xoperands[0] = gen_label_rtx ();
7772       output_asm_insn ("addil L'$$dyncall-%0,%%r1", xoperands);
7773       (*targetm.asm_out.internal_label) (asm_out_file, "L",
7774                                          CODE_LABEL_NUMBER (xoperands[0]));
7775       output_asm_insn ("ldo R'$$dyncall-%0(%%r1),%%r1", xoperands);
7776     }
7777   else
7778     {
7779       output_asm_insn ("addil L'$$dyncall-$PIC_pcrel$0+4,%%r1", xoperands);
7780       output_asm_insn ("ldo R'$$dyncall-$PIC_pcrel$0+8(%%r1),%%r1",
7781                        xoperands);
7782     }
7783   output_asm_insn ("blr %%r0,%%r2", xoperands);
7784   output_asm_insn ("bv,n %%r0(%%r1)\n\tnop", xoperands);
7785   return "";
7786 }
7787
7788 /* Return the total length of the save and restore instructions needed for
7789    the data linkage table pointer (i.e., the PIC register) across the call
7790    instruction INSN.  No-return calls do not require a save and restore.
7791    In addition, we may be able to avoid the save and restore for calls
7792    within the same translation unit.  */
7793
7794 int
7795 attr_length_save_restore_dltp (rtx insn)
7796 {
7797   if (find_reg_note (insn, REG_NORETURN, NULL_RTX))
7798     return 0;
7799
7800   return 8;
7801 }
7802
7803 /* In HPUX 8.0's shared library scheme, special relocations are needed
7804    for function labels if they might be passed to a function
7805    in a shared library (because shared libraries don't live in code
7806    space), and special magic is needed to construct their address.  */
7807
7808 void
7809 hppa_encode_label (rtx sym)
7810 {
7811   const char *str = XSTR (sym, 0);
7812   int len = strlen (str) + 1;
7813   char *newstr, *p;
7814
7815   p = newstr = alloca (len + 1);
7816   *p++ = '@';
7817   strcpy (p, str);
7818
7819   XSTR (sym, 0) = ggc_alloc_string (newstr, len);
7820 }
7821
7822 static void
7823 pa_encode_section_info (tree decl, rtx rtl, int first)
7824 {
7825   if (first && TEXT_SPACE_P (decl))
7826     {
7827       SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
7828       if (TREE_CODE (decl) == FUNCTION_DECL)
7829         hppa_encode_label (XEXP (rtl, 0));
7830     }
7831 }
7832
7833 /* This is sort of inverse to pa_encode_section_info.  */
7834
7835 static const char *
7836 pa_strip_name_encoding (const char *str)
7837 {
7838   str += (*str == '@');
7839   str += (*str == '*');
7840   return str;
7841 }
7842
7843 int
7844 function_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
7845 {
7846   return GET_CODE (op) == SYMBOL_REF && FUNCTION_NAME_P (XSTR (op, 0));
7847 }
7848
7849 /* Returns 1 if OP is a function label involved in a simple addition
7850    with a constant.  Used to keep certain patterns from matching
7851    during instruction combination.  */
7852 int
7853 is_function_label_plus_const (rtx op)
7854 {
7855   /* Strip off any CONST.  */
7856   if (GET_CODE (op) == CONST)
7857     op = XEXP (op, 0);
7858
7859   return (GET_CODE (op) == PLUS
7860           && function_label_operand (XEXP (op, 0), Pmode)
7861           && GET_CODE (XEXP (op, 1)) == CONST_INT);
7862 }
7863
7864 /* Output assembly code for a thunk to FUNCTION.  */
7865
7866 static void
7867 pa_asm_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
7868                         HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
7869                         tree function)
7870 {
7871   const char *fname = XSTR (XEXP (DECL_RTL (function), 0), 0);
7872   const char *tname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
7873   int val_14 = VAL_14_BITS_P (delta);
7874   int nbytes = 0;
7875   static unsigned int current_thunk_number;
7876   char label[16];
7877
7878   ASM_OUTPUT_LABEL (file, tname);
7879   fprintf (file, "\t.PROC\n\t.CALLINFO FRAME=0,NO_CALLS\n\t.ENTRY\n");
7880
7881   fname = (*targetm.strip_name_encoding) (fname);
7882   tname = (*targetm.strip_name_encoding) (tname);
7883
7884   /* Output the thunk.  We know that the function is in the same
7885      translation unit (i.e., the same space) as the thunk, and that
7886      thunks are output after their method.  Thus, we don't need an
7887      external branch to reach the function.  With SOM and GAS,
7888      functions and thunks are effectively in different sections.
7889      Thus, we can always use a IA-relative branch and the linker
7890      will add a long branch stub if necessary.
7891
7892      However, we have to be careful when generating PIC code on the
7893      SOM port to ensure that the sequence does not transfer to an
7894      import stub for the target function as this could clobber the
7895      return value saved at SP-24.  This would also apply to the
7896      32-bit linux port if the multi-space model is implemented.  */
7897   if ((!TARGET_LONG_CALLS && TARGET_SOM && !TARGET_PORTABLE_RUNTIME
7898        && !(flag_pic && TREE_PUBLIC (function))
7899        && (TARGET_GAS || last_address < 262132))
7900       || (!TARGET_LONG_CALLS && !TARGET_SOM && !TARGET_PORTABLE_RUNTIME
7901           && ((targetm.have_named_sections
7902                && DECL_SECTION_NAME (thunk_fndecl) != NULL
7903                /* The GNU 64-bit linker has rather poor stub management.
7904                   So, we use a long branch from thunks that aren't in
7905                   the same section as the target function.  */
7906                && ((!TARGET_64BIT
7907                     && (DECL_SECTION_NAME (thunk_fndecl)
7908                         != DECL_SECTION_NAME (function)))
7909                    || ((DECL_SECTION_NAME (thunk_fndecl)
7910                         == DECL_SECTION_NAME (function))
7911                        && last_address < 262132)))
7912               || (!targetm.have_named_sections && last_address < 262132))))
7913     {
7914       if (val_14)
7915         {
7916           fprintf (file, "\tb %s\n\tldo " HOST_WIDE_INT_PRINT_DEC
7917                          "(%%r26),%%r26\n", fname, delta);
7918           nbytes += 8;
7919         }
7920       else
7921         {
7922           fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
7923                          ",%%r26\n", delta);
7924           fprintf (file, "\tb %s\n\tldo R'" HOST_WIDE_INT_PRINT_DEC
7925                          "(%%r1),%%r26\n", fname, delta);
7926           nbytes += 12;
7927         }
7928     }
7929   else if (TARGET_64BIT)
7930     {
7931       /* We only have one call-clobbered scratch register, so we can't
7932          make use of the delay slot if delta doesn't fit in 14 bits.  */
7933       if (!val_14)
7934         fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
7935                        ",%%r26\n\tldo R'" HOST_WIDE_INT_PRINT_DEC
7936                        "(%%r1),%%r26\n", delta, delta);
7937
7938       fprintf (file, "\tb,l .+8,%%r1\n");
7939
7940       if (TARGET_GAS)
7941         {
7942           fprintf (file, "\taddil L'%s-$PIC_pcrel$0+4,%%r1\n", fname);
7943           fprintf (file, "\tldo R'%s-$PIC_pcrel$0+8(%%r1),%%r1\n", fname);
7944         }
7945       else
7946         {
7947           int off = val_14 ? 8 : 16;
7948           fprintf (file, "\taddil L'%s-%s-%d,%%r1\n", fname, tname, off);
7949           fprintf (file, "\tldo R'%s-%s-%d(%%r1),%%r1\n", fname, tname, off);
7950         }
7951
7952       if (val_14)
7953         {
7954           fprintf (file, "\tbv %%r0(%%r1)\n\tldo ");
7955           fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
7956           nbytes += 20;
7957         }
7958       else
7959         {
7960           fprintf (file, "\tbv,n %%r0(%%r1)\n");
7961           nbytes += 24;
7962         }
7963     }
7964   else if (TARGET_PORTABLE_RUNTIME)
7965     {
7966       fprintf (file, "\tldil L'%s,%%r1\n", fname);
7967       fprintf (file, "\tldo R'%s(%%r1),%%r22\n", fname);
7968
7969       if (val_14)
7970         {
7971           fprintf (file, "\tbv %%r0(%%r22)\n\tldo ");
7972           fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
7973           nbytes += 16;
7974         }
7975       else
7976         {
7977           fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
7978                          ",%%r26\n", delta);
7979           fprintf (file, "\tbv %%r0(%%r22)\n\tldo ");
7980           fprintf (file, "R'" HOST_WIDE_INT_PRINT_DEC "(%%r1),%%r26\n", delta);
7981           nbytes += 20;
7982         }
7983     }
7984   else if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
7985     {
7986       /* The function is accessible from outside this module.  The only
7987          way to avoid an import stub between the thunk and function is to
7988          call the function directly with an indirect sequence similar to
7989          that used by $$dyncall.  This is possible because $$dyncall acts
7990          as the import stub in an indirect call.  */
7991       const char *lab;
7992
7993       ASM_GENERATE_INTERNAL_LABEL (label, "LTHN", current_thunk_number);
7994       lab = (*targetm.strip_name_encoding) (label);
7995
7996       fprintf (file, "\taddil LT'%s,%%r19\n", lab);
7997       fprintf (file, "\tldw RT'%s(%%r1),%%r22\n", lab);
7998       fprintf (file, "\tldw 0(%%sr0,%%r22),%%r22\n");
7999       fprintf (file, "\tbb,>=,n %%r22,30,.+16\n");
8000       fprintf (file, "\tdepi 0,31,2,%%r22\n");
8001       fprintf (file, "\tldw 4(%%sr0,%%r22),%%r19\n");
8002       fprintf (file, "\tldw 0(%%sr0,%%r22),%%r22\n");
8003       if (!val_14)
8004         {
8005           fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
8006                          ",%%r26\n", delta);
8007           nbytes += 4;
8008         }
8009       if (TARGET_PA_20)
8010         {
8011           fprintf (file, "\tbve (%%r22)\n\tldo ");
8012           nbytes += 36;
8013         }
8014       else
8015         {
8016           if (TARGET_NO_SPACE_REGS)
8017             {
8018               fprintf (file, "\tbe 0(%%sr4,%%r22)\n\tldo ");
8019               nbytes += 36;
8020             }
8021           else
8022             {
8023               fprintf (file, "\tldsid (%%sr0,%%r22),%%r21\n");
8024               fprintf (file, "\tmtsp %%r21,%%sr0\n");
8025               fprintf (file, "\tbe 0(%%sr0,%%r22)\n\tldo ");
8026               nbytes += 44;
8027             }
8028         }
8029
8030       if (val_14)
8031         fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
8032       else
8033         fprintf (file, "R'" HOST_WIDE_INT_PRINT_DEC "(%%r1),%%r26\n", delta);
8034     }
8035   else if (flag_pic)
8036     {
8037       if (TARGET_PA_20)
8038         fprintf (file, "\tb,l .+8,%%r1\n");
8039       else
8040         fprintf (file, "\tbl .+8,%%r1\n");
8041
8042       if (TARGET_SOM || !TARGET_GAS)
8043         {
8044           fprintf (file, "\taddil L'%s-%s-8,%%r1\n", fname, tname);
8045           fprintf (file, "\tldo R'%s-%s-8(%%r1),%%r22\n", fname, tname);
8046         }
8047       else
8048         {
8049           fprintf (file, "\taddil L'%s-$PIC_pcrel$0+4,%%r1\n", fname);
8050           fprintf (file, "\tldo R'%s-$PIC_pcrel$0+8(%%r1),%%r22\n", fname);
8051         }
8052
8053       if (val_14)
8054         {
8055           fprintf (file, "\tbv %%r0(%%r22)\n\tldo ");
8056           fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
8057           nbytes += 20;
8058         }
8059       else
8060         {
8061           fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
8062                          ",%%r26\n", delta);
8063           fprintf (file, "\tbv %%r0(%%r22)\n\tldo ");
8064           fprintf (file, "R'" HOST_WIDE_INT_PRINT_DEC "(%%r1),%%r26\n", delta);
8065           nbytes += 24;
8066         }
8067     }
8068   else
8069     {
8070       if (!val_14)
8071         fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC ",%%r26\n", delta);
8072
8073       fprintf (file, "\tldil L'%s,%%r22\n", fname);
8074       fprintf (file, "\tbe R'%s(%%sr4,%%r22)\n\tldo ", fname);
8075
8076       if (val_14)
8077         {
8078           fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
8079           nbytes += 12;
8080         }
8081       else
8082         {
8083           fprintf (file, "R'" HOST_WIDE_INT_PRINT_DEC "(%%r1),%%r26\n", delta);
8084           nbytes += 16;
8085         }
8086     }
8087
8088   fprintf (file, "\t.EXIT\n\t.PROCEND\n");
8089
8090   if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8091     {
8092       data_section ();
8093       fprintf (file, "\t.align 4\n");
8094       ASM_OUTPUT_LABEL (file, label);
8095       fprintf (file, "\t.word P'%s\n", fname);
8096     }
8097   else if (TARGET_SOM && TARGET_GAS)
8098     forget_section ();
8099
8100   current_thunk_number++;
8101   nbytes = ((nbytes + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
8102             & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
8103   last_address += nbytes;
8104   update_total_code_bytes (nbytes);
8105 }
8106
8107 /* Only direct calls to static functions are allowed to be sibling (tail)
8108    call optimized.
8109
8110    This restriction is necessary because some linker generated stubs will
8111    store return pointers into rp' in some cases which might clobber a
8112    live value already in rp'.
8113
8114    In a sibcall the current function and the target function share stack
8115    space.  Thus if the path to the current function and the path to the
8116    target function save a value in rp', they save the value into the
8117    same stack slot, which has undesirable consequences.
8118
8119    Because of the deferred binding nature of shared libraries any function
8120    with external scope could be in a different load module and thus require
8121    rp' to be saved when calling that function.  So sibcall optimizations
8122    can only be safe for static function.
8123
8124    Note that GCC never needs return value relocations, so we don't have to
8125    worry about static calls with return value relocations (which require
8126    saving rp').
8127
8128    It is safe to perform a sibcall optimization when the target function
8129    will never return.  */
8130 static bool
8131 pa_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
8132 {
8133   if (TARGET_PORTABLE_RUNTIME)
8134     return false;
8135
8136   /* Sibcalls are ok for TARGET_ELF32 as along as the linker is used in
8137      single subspace mode and the call is not indirect.  As far as I know,
8138      there is no operating system support for the multiple subspace mode.
8139      It might be possible to support indirect calls if we didn't use
8140      $$dyncall (see the indirect sequence generated in output_call).  */
8141   if (TARGET_ELF32)
8142     return (decl != NULL_TREE);
8143
8144   /* Sibcalls are not ok because the arg pointer register is not a fixed
8145      register.  This prevents the sibcall optimization from occurring.  In
8146      addition, there are problems with stub placement using GNU ld.  This
8147      is because a normal sibcall branch uses a 17-bit relocation while
8148      a regular call branch uses a 22-bit relocation.  As a result, more
8149      care needs to be taken in the placement of long-branch stubs.  */
8150   if (TARGET_64BIT)
8151     return false;
8152
8153   /* Sibcalls are only ok within a translation unit.  */
8154   return (decl && !TREE_PUBLIC (decl));
8155 }
8156
8157 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8158    use in fmpyadd instructions.  */
8159 int
8160 fmpyaddoperands (rtx *operands)
8161 {
8162   enum machine_mode mode = GET_MODE (operands[0]);
8163
8164   /* Must be a floating point mode.  */
8165   if (mode != SFmode && mode != DFmode)
8166     return 0;
8167
8168   /* All modes must be the same.  */
8169   if (! (mode == GET_MODE (operands[1])
8170          && mode == GET_MODE (operands[2])
8171          && mode == GET_MODE (operands[3])
8172          && mode == GET_MODE (operands[4])
8173          && mode == GET_MODE (operands[5])))
8174     return 0;
8175
8176   /* All operands must be registers.  */
8177   if (! (GET_CODE (operands[1]) == REG
8178          && GET_CODE (operands[2]) == REG
8179          && GET_CODE (operands[3]) == REG
8180          && GET_CODE (operands[4]) == REG
8181          && GET_CODE (operands[5]) == REG))
8182     return 0;
8183
8184   /* Only 2 real operands to the addition.  One of the input operands must
8185      be the same as the output operand.  */
8186   if (! rtx_equal_p (operands[3], operands[4])
8187       && ! rtx_equal_p (operands[3], operands[5]))
8188     return 0;
8189
8190   /* Inout operand of add cannot conflict with any operands from multiply.  */
8191   if (rtx_equal_p (operands[3], operands[0])
8192      || rtx_equal_p (operands[3], operands[1])
8193      || rtx_equal_p (operands[3], operands[2]))
8194     return 0;
8195
8196   /* multiply cannot feed into addition operands.  */
8197   if (rtx_equal_p (operands[4], operands[0])
8198       || rtx_equal_p (operands[5], operands[0]))
8199     return 0;
8200
8201   /* SFmode limits the registers to the upper 32 of the 32bit FP regs.  */
8202   if (mode == SFmode
8203       && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8204           || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8205           || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8206           || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8207           || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8208           || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8209     return 0;
8210
8211   /* Passed.  Operands are suitable for fmpyadd.  */
8212   return 1;
8213 }
8214
8215 #if !defined(USE_COLLECT2)
8216 static void
8217 pa_asm_out_constructor (rtx symbol, int priority)
8218 {
8219   if (!function_label_operand (symbol, VOIDmode))
8220     hppa_encode_label (symbol);
8221
8222 #ifdef CTORS_SECTION_ASM_OP
8223   default_ctor_section_asm_out_constructor (symbol, priority);
8224 #else
8225 # ifdef TARGET_ASM_NAMED_SECTION
8226   default_named_section_asm_out_constructor (symbol, priority);
8227 # else
8228   default_stabs_asm_out_constructor (symbol, priority);
8229 # endif
8230 #endif
8231 }
8232
8233 static void
8234 pa_asm_out_destructor (rtx symbol, int priority)
8235 {
8236   if (!function_label_operand (symbol, VOIDmode))
8237     hppa_encode_label (symbol);
8238
8239 #ifdef DTORS_SECTION_ASM_OP
8240   default_dtor_section_asm_out_destructor (symbol, priority);
8241 #else
8242 # ifdef TARGET_ASM_NAMED_SECTION
8243   default_named_section_asm_out_destructor (symbol, priority);
8244 # else
8245   default_stabs_asm_out_destructor (symbol, priority);
8246 # endif
8247 #endif
8248 }
8249 #endif
8250
8251 /* This function places uninitialized global data in the bss section.
8252    The ASM_OUTPUT_ALIGNED_BSS macro needs to be defined to call this
8253    function on the SOM port to prevent uninitialized global data from
8254    being placed in the data section.  */
8255    
8256 void
8257 pa_asm_output_aligned_bss (FILE *stream,
8258                            const char *name,
8259                            unsigned HOST_WIDE_INT size,
8260                            unsigned int align)
8261 {
8262   bss_section ();
8263   fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8264
8265 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
8266   ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object");
8267 #endif
8268
8269 #ifdef ASM_OUTPUT_SIZE_DIRECTIVE
8270   ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
8271 #endif
8272
8273   fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8274   ASM_OUTPUT_LABEL (stream, name);
8275   fprintf (stream, "\t.block "HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8276 }
8277
8278 /* Both the HP and GNU assemblers under HP-UX provide a .comm directive
8279    that doesn't allow the alignment of global common storage to be directly
8280    specified.  The SOM linker aligns common storage based on the rounded
8281    value of the NUM_BYTES parameter in the .comm directive.  It's not
8282    possible to use the .align directive as it doesn't affect the alignment
8283    of the label associated with a .comm directive.  */
8284
8285 void
8286 pa_asm_output_aligned_common (FILE *stream,
8287                               const char *name,
8288                               unsigned HOST_WIDE_INT size,
8289                               unsigned int align)
8290 {
8291   unsigned int max_common_align;
8292
8293   max_common_align = TARGET_64BIT ? 128 : (size >= 4096 ? 256 : 64);
8294   if (align > max_common_align)
8295     {
8296       warning ("alignment (%u) for %s exceeds maximum alignment "
8297                "for global common data.  Using %u",
8298                align / BITS_PER_UNIT, name, max_common_align / BITS_PER_UNIT);
8299       align = max_common_align;
8300     }
8301
8302   bss_section ();
8303
8304   assemble_name (stream, name);
8305   fprintf (stream, "\t.comm "HOST_WIDE_INT_PRINT_UNSIGNED"\n",
8306            MAX (size, align / BITS_PER_UNIT));
8307 }
8308
8309 /* We can't use .comm for local common storage as the SOM linker effectively
8310    treats the symbol as universal and uses the same storage for local symbols
8311    with the same name in different object files.  The .block directive
8312    reserves an uninitialized block of storage.  However, it's not common
8313    storage.  Fortunately, GCC never requests common storage with the same
8314    name in any given translation unit.  */
8315
8316 void
8317 pa_asm_output_aligned_local (FILE *stream,
8318                              const char *name,
8319                              unsigned HOST_WIDE_INT size,
8320                              unsigned int align)
8321 {
8322   bss_section ();
8323   fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8324
8325 #ifdef LOCAL_ASM_OP
8326   fprintf (stream, "%s", LOCAL_ASM_OP);
8327   assemble_name (stream, name);
8328   fprintf (stream, "\n");
8329 #endif
8330
8331   ASM_OUTPUT_LABEL (stream, name);
8332   fprintf (stream, "\t.block "HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8333 }
8334
8335 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8336    use in fmpysub instructions.  */
8337 int
8338 fmpysuboperands (rtx *operands)
8339 {
8340   enum machine_mode mode = GET_MODE (operands[0]);
8341
8342   /* Must be a floating point mode.  */
8343   if (mode != SFmode && mode != DFmode)
8344     return 0;
8345
8346   /* All modes must be the same.  */
8347   if (! (mode == GET_MODE (operands[1])
8348          && mode == GET_MODE (operands[2])
8349          && mode == GET_MODE (operands[3])
8350          && mode == GET_MODE (operands[4])
8351          && mode == GET_MODE (operands[5])))
8352     return 0;
8353
8354   /* All operands must be registers.  */
8355   if (! (GET_CODE (operands[1]) == REG
8356          && GET_CODE (operands[2]) == REG
8357          && GET_CODE (operands[3]) == REG
8358          && GET_CODE (operands[4]) == REG
8359          && GET_CODE (operands[5]) == REG))
8360     return 0;
8361
8362   /* Only 2 real operands to the subtraction.  Subtraction is not a commutative
8363      operation, so operands[4] must be the same as operand[3].  */
8364   if (! rtx_equal_p (operands[3], operands[4]))
8365     return 0;
8366
8367   /* multiply cannot feed into subtraction.  */
8368   if (rtx_equal_p (operands[5], operands[0]))
8369     return 0;
8370
8371   /* Inout operand of sub cannot conflict with any operands from multiply.  */
8372   if (rtx_equal_p (operands[3], operands[0])
8373      || rtx_equal_p (operands[3], operands[1])
8374      || rtx_equal_p (operands[3], operands[2]))
8375     return 0;
8376
8377   /* SFmode limits the registers to the upper 32 of the 32bit FP regs.  */
8378   if (mode == SFmode
8379       && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8380           || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8381           || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8382           || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8383           || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8384           || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8385     return 0;
8386
8387   /* Passed.  Operands are suitable for fmpysub.  */
8388   return 1;
8389 }
8390
8391 int
8392 plus_xor_ior_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8393 {
8394   return (GET_CODE (op) == PLUS || GET_CODE (op) == XOR
8395           || GET_CODE (op) == IOR);
8396 }
8397
8398 /* Return 1 if the given constant is 2, 4, or 8.  These are the valid
8399    constants for shadd instructions.  */
8400 static int
8401 shadd_constant_p (int val)
8402 {
8403   if (val == 2 || val == 4 || val == 8)
8404     return 1;
8405   else
8406     return 0;
8407 }
8408
8409 /* Return 1 if OP is a CONST_INT with the value 2, 4, or 8.  These are
8410    the valid constant for shadd instructions.  */
8411 int
8412 shadd_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8413 {
8414   return (GET_CODE (op) == CONST_INT && shadd_constant_p (INTVAL (op)));
8415 }
8416
8417 /* Return 1 if OP is valid as a base or index register in a
8418    REG+REG address.  */
8419
8420 int
8421 borx_reg_operand (rtx op, enum machine_mode mode)
8422 {
8423   if (GET_CODE (op) != REG)
8424     return 0;
8425
8426   /* We must reject virtual registers as the only expressions that
8427      can be instantiated are REG and REG+CONST.  */
8428   if (op == virtual_incoming_args_rtx
8429       || op == virtual_stack_vars_rtx
8430       || op == virtual_stack_dynamic_rtx
8431       || op == virtual_outgoing_args_rtx
8432       || op == virtual_cfa_rtx)
8433     return 0;
8434
8435   /* While it's always safe to index off the frame pointer, it's not
8436      profitable to do so when the frame pointer is being eliminated.  */
8437   if (!reload_completed
8438       && flag_omit_frame_pointer
8439       && !current_function_calls_alloca
8440       && op == frame_pointer_rtx)
8441     return 0;
8442
8443   return register_operand (op, mode);
8444 }
8445
8446 /* Return 1 if this operand is anything other than a hard register.  */
8447
8448 int
8449 non_hard_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8450 {
8451   return ! (GET_CODE (op) == REG && REGNO (op) < FIRST_PSEUDO_REGISTER);
8452 }
8453
8454 /* Return 1 if INSN branches forward.  Should be using insn_addresses
8455    to avoid walking through all the insns...  */
8456 static int
8457 forward_branch_p (rtx insn)
8458 {
8459   rtx label = JUMP_LABEL (insn);
8460
8461   while (insn)
8462     {
8463       if (insn == label)
8464         break;
8465       else
8466         insn = NEXT_INSN (insn);
8467     }
8468
8469   return (insn == label);
8470 }
8471
8472 /* Return 1 if OP is an equality comparison, else return 0.  */
8473 int
8474 eq_neq_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8475 {
8476   return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
8477 }
8478
8479 /* Return 1 if OP is an operator suitable for use in a movb instruction.  */
8480 int
8481 movb_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8482 {
8483   return (GET_CODE (op) == EQ || GET_CODE (op) == NE
8484           || GET_CODE (op) == LT || GET_CODE (op) == GE);
8485 }
8486
8487 /* Return 1 if INSN is in the delay slot of a call instruction.  */
8488 int
8489 jump_in_call_delay (rtx insn)
8490 {
8491
8492   if (GET_CODE (insn) != JUMP_INSN)
8493     return 0;
8494
8495   if (PREV_INSN (insn)
8496       && PREV_INSN (PREV_INSN (insn))
8497       && GET_CODE (next_real_insn (PREV_INSN (PREV_INSN (insn)))) == INSN)
8498     {
8499       rtx test_insn = next_real_insn (PREV_INSN (PREV_INSN (insn)));
8500
8501       return (GET_CODE (PATTERN (test_insn)) == SEQUENCE
8502               && XVECEXP (PATTERN (test_insn), 0, 1) == insn);
8503
8504     }
8505   else
8506     return 0;
8507 }
8508
8509 /* Output an unconditional move and branch insn.  */
8510
8511 const char *
8512 output_parallel_movb (rtx *operands, int length)
8513 {
8514   /* These are the cases in which we win.  */
8515   if (length == 4)
8516     return "mov%I1b,tr %1,%0,%2";
8517
8518   /* None of these cases wins, but they don't lose either.  */
8519   if (dbr_sequence_length () == 0)
8520     {
8521       /* Nothing in the delay slot, fake it by putting the combined
8522          insn (the copy or add) in the delay slot of a bl.  */
8523       if (GET_CODE (operands[1]) == CONST_INT)
8524         return "b %2\n\tldi %1,%0";
8525       else
8526         return "b %2\n\tcopy %1,%0";
8527     }
8528   else
8529     {
8530       /* Something in the delay slot, but we've got a long branch.  */
8531       if (GET_CODE (operands[1]) == CONST_INT)
8532         return "ldi %1,%0\n\tb %2";
8533       else
8534         return "copy %1,%0\n\tb %2";
8535     }
8536 }
8537
8538 /* Output an unconditional add and branch insn.  */
8539
8540 const char *
8541 output_parallel_addb (rtx *operands, int length)
8542 {
8543   /* To make life easy we want operand0 to be the shared input/output
8544      operand and operand1 to be the readonly operand.  */
8545   if (operands[0] == operands[1])
8546     operands[1] = operands[2];
8547
8548   /* These are the cases in which we win.  */
8549   if (length == 4)
8550     return "add%I1b,tr %1,%0,%3";
8551
8552   /* None of these cases win, but they don't lose either.  */
8553   if (dbr_sequence_length () == 0)
8554     {
8555       /* Nothing in the delay slot, fake it by putting the combined
8556          insn (the copy or add) in the delay slot of a bl.  */
8557       return "b %3\n\tadd%I1 %1,%0,%0";
8558     }
8559   else
8560     {
8561       /* Something in the delay slot, but we've got a long branch.  */
8562       return "add%I1 %1,%0,%0\n\tb %3";
8563     }
8564 }
8565
8566 /* Return nonzero if INSN (a jump insn) immediately follows a call
8567    to a named function.  This is used to avoid filling the delay slot
8568    of the jump since it can usually be eliminated by modifying RP in
8569    the delay slot of the call.  */
8570
8571 int
8572 following_call (rtx insn)
8573 {
8574   if (! TARGET_JUMP_IN_DELAY)
8575     return 0;
8576
8577   /* Find the previous real insn, skipping NOTEs.  */
8578   insn = PREV_INSN (insn);
8579   while (insn && GET_CODE (insn) == NOTE)
8580     insn = PREV_INSN (insn);
8581
8582   /* Check for CALL_INSNs and millicode calls.  */
8583   if (insn
8584       && ((GET_CODE (insn) == CALL_INSN
8585            && get_attr_type (insn) != TYPE_DYNCALL)
8586           || (GET_CODE (insn) == INSN
8587               && GET_CODE (PATTERN (insn)) != SEQUENCE
8588               && GET_CODE (PATTERN (insn)) != USE
8589               && GET_CODE (PATTERN (insn)) != CLOBBER
8590               && get_attr_type (insn) == TYPE_MILLI)))
8591     return 1;
8592
8593   return 0;
8594 }
8595
8596 /* We use this hook to perform a PA specific optimization which is difficult
8597    to do in earlier passes.
8598
8599    We want the delay slots of branches within jump tables to be filled.
8600    None of the compiler passes at the moment even has the notion that a
8601    PA jump table doesn't contain addresses, but instead contains actual
8602    instructions!
8603
8604    Because we actually jump into the table, the addresses of each entry
8605    must stay constant in relation to the beginning of the table (which
8606    itself must stay constant relative to the instruction to jump into
8607    it).  I don't believe we can guarantee earlier passes of the compiler
8608    will adhere to those rules.
8609
8610    So, late in the compilation process we find all the jump tables, and
8611    expand them into real code -- e.g. each entry in the jump table vector
8612    will get an appropriate label followed by a jump to the final target.
8613
8614    Reorg and the final jump pass can then optimize these branches and
8615    fill their delay slots.  We end up with smaller, more efficient code.
8616
8617    The jump instructions within the table are special; we must be able
8618    to identify them during assembly output (if the jumps don't get filled
8619    we need to emit a nop rather than nullifying the delay slot)).  We
8620    identify jumps in switch tables by using insns with the attribute
8621    type TYPE_BTABLE_BRANCH.
8622
8623    We also surround the jump table itself with BEGIN_BRTAB and END_BRTAB
8624    insns.  This serves two purposes, first it prevents jump.c from
8625    noticing that the last N entries in the table jump to the instruction
8626    immediately after the table and deleting the jumps.  Second, those
8627    insns mark where we should emit .begin_brtab and .end_brtab directives
8628    when using GAS (allows for better link time optimizations).  */
8629
8630 static void
8631 pa_reorg (void)
8632 {
8633   rtx insn;
8634
8635   remove_useless_addtr_insns (1);
8636
8637   if (pa_cpu < PROCESSOR_8000)
8638     pa_combine_instructions ();
8639
8640
8641   /* This is fairly cheap, so always run it if optimizing.  */
8642   if (optimize > 0 && !TARGET_BIG_SWITCH)
8643     {
8644       /* Find and explode all ADDR_VEC or ADDR_DIFF_VEC insns.  */
8645       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
8646         {
8647           rtx pattern, tmp, location, label;
8648           unsigned int length, i;
8649
8650           /* Find an ADDR_VEC or ADDR_DIFF_VEC insn to explode.  */
8651           if (GET_CODE (insn) != JUMP_INSN
8652               || (GET_CODE (PATTERN (insn)) != ADDR_VEC
8653                   && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
8654             continue;
8655
8656           /* Emit marker for the beginning of the branch table.  */
8657           emit_insn_before (gen_begin_brtab (), insn);
8658
8659           pattern = PATTERN (insn);
8660           location = PREV_INSN (insn);
8661           length = XVECLEN (pattern, GET_CODE (pattern) == ADDR_DIFF_VEC);
8662
8663           for (i = 0; i < length; i++)
8664             {
8665               /* Emit a label before each jump to keep jump.c from
8666                  removing this code.  */
8667               tmp = gen_label_rtx ();
8668               LABEL_NUSES (tmp) = 1;
8669               emit_label_after (tmp, location);
8670               location = NEXT_INSN (location);
8671
8672               if (GET_CODE (pattern) == ADDR_VEC)
8673                 label = XEXP (XVECEXP (pattern, 0, i), 0);
8674               else
8675                 label = XEXP (XVECEXP (pattern, 1, i), 0);
8676
8677               tmp = gen_short_jump (label);
8678
8679               /* Emit the jump itself.  */
8680               tmp = emit_jump_insn_after (tmp, location);
8681               JUMP_LABEL (tmp) = label;
8682               LABEL_NUSES (label)++;
8683               location = NEXT_INSN (location);
8684
8685               /* Emit a BARRIER after the jump.  */
8686               emit_barrier_after (location);
8687               location = NEXT_INSN (location);
8688             }
8689
8690           /* Emit marker for the end of the branch table.  */
8691           emit_insn_before (gen_end_brtab (), location);
8692           location = NEXT_INSN (location);
8693           emit_barrier_after (location);
8694
8695           /* Delete the ADDR_VEC or ADDR_DIFF_VEC.  */
8696           delete_insn (insn);
8697         }
8698     }
8699   else
8700     {
8701       /* Still need brtab marker insns.  FIXME: the presence of these
8702          markers disables output of the branch table to readonly memory,
8703          and any alignment directives that might be needed.  Possibly,
8704          the begin_brtab insn should be output before the label for the
8705          table.  This doesn't matter at the moment since the tables are
8706          always output in the text section.  */
8707       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
8708         {
8709           /* Find an ADDR_VEC insn.  */
8710           if (GET_CODE (insn) != JUMP_INSN
8711               || (GET_CODE (PATTERN (insn)) != ADDR_VEC
8712                   && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
8713             continue;
8714
8715           /* Now generate markers for the beginning and end of the
8716              branch table.  */
8717           emit_insn_before (gen_begin_brtab (), insn);
8718           emit_insn_after (gen_end_brtab (), insn);
8719         }
8720     }
8721 }
8722
8723 /* The PA has a number of odd instructions which can perform multiple
8724    tasks at once.  On first generation PA machines (PA1.0 and PA1.1)
8725    it may be profitable to combine two instructions into one instruction
8726    with two outputs.  It's not profitable PA2.0 machines because the
8727    two outputs would take two slots in the reorder buffers.
8728
8729    This routine finds instructions which can be combined and combines
8730    them.  We only support some of the potential combinations, and we
8731    only try common ways to find suitable instructions.
8732
8733       * addb can add two registers or a register and a small integer
8734       and jump to a nearby (+-8k) location.  Normally the jump to the
8735       nearby location is conditional on the result of the add, but by
8736       using the "true" condition we can make the jump unconditional.
8737       Thus addb can perform two independent operations in one insn.
8738
8739       * movb is similar to addb in that it can perform a reg->reg
8740       or small immediate->reg copy and jump to a nearby (+-8k location).
8741
8742       * fmpyadd and fmpysub can perform a FP multiply and either an
8743       FP add or FP sub if the operands of the multiply and add/sub are
8744       independent (there are other minor restrictions).  Note both
8745       the fmpy and fadd/fsub can in theory move to better spots according
8746       to data dependencies, but for now we require the fmpy stay at a
8747       fixed location.
8748
8749       * Many of the memory operations can perform pre & post updates
8750       of index registers.  GCC's pre/post increment/decrement addressing
8751       is far too simple to take advantage of all the possibilities.  This
8752       pass may not be suitable since those insns may not be independent.
8753
8754       * comclr can compare two ints or an int and a register, nullify
8755       the following instruction and zero some other register.  This
8756       is more difficult to use as it's harder to find an insn which
8757       will generate a comclr than finding something like an unconditional
8758       branch.  (conditional moves & long branches create comclr insns).
8759
8760       * Most arithmetic operations can conditionally skip the next
8761       instruction.  They can be viewed as "perform this operation
8762       and conditionally jump to this nearby location" (where nearby
8763       is an insns away).  These are difficult to use due to the
8764       branch length restrictions.  */
8765
8766 static void
8767 pa_combine_instructions (void)
8768 {
8769   rtx anchor, new;
8770
8771   /* This can get expensive since the basic algorithm is on the
8772      order of O(n^2) (or worse).  Only do it for -O2 or higher
8773      levels of optimization.  */
8774   if (optimize < 2)
8775     return;
8776
8777   /* Walk down the list of insns looking for "anchor" insns which
8778      may be combined with "floating" insns.  As the name implies,
8779      "anchor" instructions don't move, while "floating" insns may
8780      move around.  */
8781   new = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, NULL_RTX, NULL_RTX));
8782   new = make_insn_raw (new);
8783
8784   for (anchor = get_insns (); anchor; anchor = NEXT_INSN (anchor))
8785     {
8786       enum attr_pa_combine_type anchor_attr;
8787       enum attr_pa_combine_type floater_attr;
8788
8789       /* We only care about INSNs, JUMP_INSNs, and CALL_INSNs.
8790          Also ignore any special USE insns.  */
8791       if ((GET_CODE (anchor) != INSN
8792           && GET_CODE (anchor) != JUMP_INSN
8793           && GET_CODE (anchor) != CALL_INSN)
8794           || GET_CODE (PATTERN (anchor)) == USE
8795           || GET_CODE (PATTERN (anchor)) == CLOBBER
8796           || GET_CODE (PATTERN (anchor)) == ADDR_VEC
8797           || GET_CODE (PATTERN (anchor)) == ADDR_DIFF_VEC)
8798         continue;
8799
8800       anchor_attr = get_attr_pa_combine_type (anchor);
8801       /* See if anchor is an insn suitable for combination.  */
8802       if (anchor_attr == PA_COMBINE_TYPE_FMPY
8803           || anchor_attr == PA_COMBINE_TYPE_FADDSUB
8804           || (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
8805               && ! forward_branch_p (anchor)))
8806         {
8807           rtx floater;
8808
8809           for (floater = PREV_INSN (anchor);
8810                floater;
8811                floater = PREV_INSN (floater))
8812             {
8813               if (GET_CODE (floater) == NOTE
8814                   || (GET_CODE (floater) == INSN
8815                       && (GET_CODE (PATTERN (floater)) == USE
8816                           || GET_CODE (PATTERN (floater)) == CLOBBER)))
8817                 continue;
8818
8819               /* Anything except a regular INSN will stop our search.  */
8820               if (GET_CODE (floater) != INSN
8821                   || GET_CODE (PATTERN (floater)) == ADDR_VEC
8822                   || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
8823                 {
8824                   floater = NULL_RTX;
8825                   break;
8826                 }
8827
8828               /* See if FLOATER is suitable for combination with the
8829                  anchor.  */
8830               floater_attr = get_attr_pa_combine_type (floater);
8831               if ((anchor_attr == PA_COMBINE_TYPE_FMPY
8832                    && floater_attr == PA_COMBINE_TYPE_FADDSUB)
8833                   || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
8834                       && floater_attr == PA_COMBINE_TYPE_FMPY))
8835                 {
8836                   /* If ANCHOR and FLOATER can be combined, then we're
8837                      done with this pass.  */
8838                   if (pa_can_combine_p (new, anchor, floater, 0,
8839                                         SET_DEST (PATTERN (floater)),
8840                                         XEXP (SET_SRC (PATTERN (floater)), 0),
8841                                         XEXP (SET_SRC (PATTERN (floater)), 1)))
8842                     break;
8843                 }
8844
8845               else if (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
8846                        && floater_attr == PA_COMBINE_TYPE_ADDMOVE)
8847                 {
8848                   if (GET_CODE (SET_SRC (PATTERN (floater))) == PLUS)
8849                     {
8850                       if (pa_can_combine_p (new, anchor, floater, 0,
8851                                             SET_DEST (PATTERN (floater)),
8852                                         XEXP (SET_SRC (PATTERN (floater)), 0),
8853                                         XEXP (SET_SRC (PATTERN (floater)), 1)))
8854                         break;
8855                     }
8856                   else
8857                     {
8858                       if (pa_can_combine_p (new, anchor, floater, 0,
8859                                             SET_DEST (PATTERN (floater)),
8860                                             SET_SRC (PATTERN (floater)),
8861                                             SET_SRC (PATTERN (floater))))
8862                         break;
8863                     }
8864                 }
8865             }
8866
8867           /* If we didn't find anything on the backwards scan try forwards.  */
8868           if (!floater
8869               && (anchor_attr == PA_COMBINE_TYPE_FMPY
8870                   || anchor_attr == PA_COMBINE_TYPE_FADDSUB))
8871             {
8872               for (floater = anchor; floater; floater = NEXT_INSN (floater))
8873                 {
8874                   if (GET_CODE (floater) == NOTE
8875                       || (GET_CODE (floater) == INSN
8876                           && (GET_CODE (PATTERN (floater)) == USE
8877                               || GET_CODE (PATTERN (floater)) == CLOBBER)))
8878
8879                     continue;
8880
8881                   /* Anything except a regular INSN will stop our search.  */
8882                   if (GET_CODE (floater) != INSN
8883                       || GET_CODE (PATTERN (floater)) == ADDR_VEC
8884                       || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
8885                     {
8886                       floater = NULL_RTX;
8887                       break;
8888                     }
8889
8890                   /* See if FLOATER is suitable for combination with the
8891                      anchor.  */
8892                   floater_attr = get_attr_pa_combine_type (floater);
8893                   if ((anchor_attr == PA_COMBINE_TYPE_FMPY
8894                        && floater_attr == PA_COMBINE_TYPE_FADDSUB)
8895                       || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
8896                           && floater_attr == PA_COMBINE_TYPE_FMPY))
8897                     {
8898                       /* If ANCHOR and FLOATER can be combined, then we're
8899                          done with this pass.  */
8900                       if (pa_can_combine_p (new, anchor, floater, 1,
8901                                             SET_DEST (PATTERN (floater)),
8902                                             XEXP (SET_SRC (PATTERN (floater)),
8903                                                   0),
8904                                             XEXP (SET_SRC (PATTERN (floater)),
8905                                                   1)))
8906                         break;
8907                     }
8908                 }
8909             }
8910
8911           /* FLOATER will be nonzero if we found a suitable floating
8912              insn for combination with ANCHOR.  */
8913           if (floater
8914               && (anchor_attr == PA_COMBINE_TYPE_FADDSUB
8915                   || anchor_attr == PA_COMBINE_TYPE_FMPY))
8916             {
8917               /* Emit the new instruction and delete the old anchor.  */
8918               emit_insn_before (gen_rtx_PARALLEL
8919                                 (VOIDmode,
8920                                  gen_rtvec (2, PATTERN (anchor),
8921                                             PATTERN (floater))),
8922                                 anchor);
8923
8924               PUT_CODE (anchor, NOTE);
8925               NOTE_LINE_NUMBER (anchor) = NOTE_INSN_DELETED;
8926               NOTE_SOURCE_FILE (anchor) = 0;
8927
8928               /* Emit a special USE insn for FLOATER, then delete
8929                  the floating insn.  */
8930               emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
8931               delete_insn (floater);
8932
8933               continue;
8934             }
8935           else if (floater
8936                    && anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH)
8937             {
8938               rtx temp;
8939               /* Emit the new_jump instruction and delete the old anchor.  */
8940               temp
8941                 = emit_jump_insn_before (gen_rtx_PARALLEL
8942                                          (VOIDmode,
8943                                           gen_rtvec (2, PATTERN (anchor),
8944                                                      PATTERN (floater))),
8945                                          anchor);
8946
8947               JUMP_LABEL (temp) = JUMP_LABEL (anchor);
8948               PUT_CODE (anchor, NOTE);
8949               NOTE_LINE_NUMBER (anchor) = NOTE_INSN_DELETED;
8950               NOTE_SOURCE_FILE (anchor) = 0;
8951
8952               /* Emit a special USE insn for FLOATER, then delete
8953                  the floating insn.  */
8954               emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
8955               delete_insn (floater);
8956               continue;
8957             }
8958         }
8959     }
8960 }
8961
8962 static int
8963 pa_can_combine_p (rtx new, rtx anchor, rtx floater, int reversed, rtx dest,
8964                   rtx src1, rtx src2)
8965 {
8966   int insn_code_number;
8967   rtx start, end;
8968
8969   /* Create a PARALLEL with the patterns of ANCHOR and
8970      FLOATER, try to recognize it, then test constraints
8971      for the resulting pattern.
8972
8973      If the pattern doesn't match or the constraints
8974      aren't met keep searching for a suitable floater
8975      insn.  */
8976   XVECEXP (PATTERN (new), 0, 0) = PATTERN (anchor);
8977   XVECEXP (PATTERN (new), 0, 1) = PATTERN (floater);
8978   INSN_CODE (new) = -1;
8979   insn_code_number = recog_memoized (new);
8980   if (insn_code_number < 0
8981       || (extract_insn (new), ! constrain_operands (1)))
8982     return 0;
8983
8984   if (reversed)
8985     {
8986       start = anchor;
8987       end = floater;
8988     }
8989   else
8990     {
8991       start = floater;
8992       end = anchor;
8993     }
8994
8995   /* There's up to three operands to consider.  One
8996      output and two inputs.
8997
8998      The output must not be used between FLOATER & ANCHOR
8999      exclusive.  The inputs must not be set between
9000      FLOATER and ANCHOR exclusive.  */
9001
9002   if (reg_used_between_p (dest, start, end))
9003     return 0;
9004
9005   if (reg_set_between_p (src1, start, end))
9006     return 0;
9007
9008   if (reg_set_between_p (src2, start, end))
9009     return 0;
9010
9011   /* If we get here, then everything is good.  */
9012   return 1;
9013 }
9014
9015 /* Return nonzero if references for INSN are delayed.
9016
9017    Millicode insns are actually function calls with some special
9018    constraints on arguments and register usage.
9019
9020    Millicode calls always expect their arguments in the integer argument
9021    registers, and always return their result in %r29 (ret1).  They
9022    are expected to clobber their arguments, %r1, %r29, and the return
9023    pointer which is %r31 on 32-bit and %r2 on 64-bit, and nothing else.
9024
9025    This function tells reorg that the references to arguments and
9026    millicode calls do not appear to happen until after the millicode call.
9027    This allows reorg to put insns which set the argument registers into the
9028    delay slot of the millicode call -- thus they act more like traditional
9029    CALL_INSNs.
9030
9031    Note we cannot consider side effects of the insn to be delayed because
9032    the branch and link insn will clobber the return pointer.  If we happened
9033    to use the return pointer in the delay slot of the call, then we lose.
9034
9035    get_attr_type will try to recognize the given insn, so make sure to
9036    filter out things it will not accept -- SEQUENCE, USE and CLOBBER insns
9037    in particular.  */
9038 int
9039 insn_refs_are_delayed (rtx insn)
9040 {
9041   return ((GET_CODE (insn) == INSN
9042            && GET_CODE (PATTERN (insn)) != SEQUENCE
9043            && GET_CODE (PATTERN (insn)) != USE
9044            && GET_CODE (PATTERN (insn)) != CLOBBER
9045            && get_attr_type (insn) == TYPE_MILLI));
9046 }
9047
9048 /* On the HP-PA the value is found in register(s) 28(-29), unless
9049    the mode is SF or DF. Then the value is returned in fr4 (32).
9050
9051    This must perform the same promotions as PROMOTE_MODE, else
9052    TARGET_PROMOTE_FUNCTION_RETURN will not work correctly.
9053
9054    Small structures must be returned in a PARALLEL on PA64 in order
9055    to match the HP Compiler ABI.  */
9056
9057 rtx
9058 function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
9059 {
9060   enum machine_mode valmode;
9061
9062   /* Aggregates with a size less than or equal to 128 bits are returned
9063      in GR 28(-29).  They are left justified.  The pad bits are undefined.
9064      Larger aggregates are returned in memory.  */
9065   if (TARGET_64BIT && AGGREGATE_TYPE_P (valtype))
9066     {
9067       rtx loc[2];
9068       int i, offset = 0;
9069       int ub = int_size_in_bytes (valtype) <= UNITS_PER_WORD ? 1 : 2;
9070
9071       for (i = 0; i < ub; i++)
9072         {
9073           loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9074                                       gen_rtx_REG (DImode, 28 + i),
9075                                       GEN_INT (offset));
9076           offset += 8;
9077         }
9078
9079       return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (ub, loc));
9080     }
9081
9082   if ((INTEGRAL_TYPE_P (valtype)
9083        && TYPE_PRECISION (valtype) < BITS_PER_WORD)
9084       || POINTER_TYPE_P (valtype))
9085     valmode = word_mode;
9086   else
9087     valmode = TYPE_MODE (valtype);
9088
9089   if (TREE_CODE (valtype) == REAL_TYPE
9090       && TYPE_MODE (valtype) != TFmode
9091       && !TARGET_SOFT_FLOAT)
9092     return gen_rtx_REG (valmode, 32);
9093
9094   return gen_rtx_REG (valmode, 28);
9095 }
9096
9097 /* Return the location of a parameter that is passed in a register or NULL
9098    if the parameter has any component that is passed in memory.
9099
9100    This is new code and will be pushed to into the net sources after
9101    further testing.
9102
9103    ??? We might want to restructure this so that it looks more like other
9104    ports.  */
9105 rtx
9106 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, tree type,
9107               int named ATTRIBUTE_UNUSED)
9108 {
9109   int max_arg_words = (TARGET_64BIT ? 8 : 4);
9110   int alignment = 0;
9111   int arg_size;
9112   int fpr_reg_base;
9113   int gpr_reg_base;
9114   rtx retval;
9115
9116   if (mode == VOIDmode)
9117     return NULL_RTX;
9118
9119   arg_size = FUNCTION_ARG_SIZE (mode, type);
9120
9121   /* If this arg would be passed partially or totally on the stack, then
9122      this routine should return zero.  pa_arg_partial_bytes will
9123      handle arguments which are split between regs and stack slots if
9124      the ABI mandates split arguments.  */
9125   if (! TARGET_64BIT)
9126     {
9127       /* The 32-bit ABI does not split arguments.  */
9128       if (cum->words + arg_size > max_arg_words)
9129         return NULL_RTX;
9130     }
9131   else
9132     {
9133       if (arg_size > 1)
9134         alignment = cum->words & 1;
9135       if (cum->words + alignment >= max_arg_words)
9136         return NULL_RTX;
9137     }
9138
9139   /* The 32bit ABIs and the 64bit ABIs are rather different,
9140      particularly in their handling of FP registers.  We might
9141      be able to cleverly share code between them, but I'm not
9142      going to bother in the hope that splitting them up results
9143      in code that is more easily understood.  */
9144
9145   if (TARGET_64BIT)
9146     {
9147       /* Advance the base registers to their current locations.
9148
9149          Remember, gprs grow towards smaller register numbers while
9150          fprs grow to higher register numbers.  Also remember that
9151          although FP regs are 32-bit addressable, we pretend that
9152          the registers are 64-bits wide.  */
9153       gpr_reg_base = 26 - cum->words;
9154       fpr_reg_base = 32 + cum->words;
9155
9156       /* Arguments wider than one word and small aggregates need special
9157          treatment.  */
9158       if (arg_size > 1
9159           || mode == BLKmode
9160           || (type && AGGREGATE_TYPE_P (type)))
9161         {
9162           /* Double-extended precision (80-bit), quad-precision (128-bit)
9163              and aggregates including complex numbers are aligned on
9164              128-bit boundaries.  The first eight 64-bit argument slots
9165              are associated one-to-one, with general registers r26
9166              through r19, and also with floating-point registers fr4
9167              through fr11.  Arguments larger than one word are always
9168              passed in general registers.
9169
9170              Using a PARALLEL with a word mode register results in left
9171              justified data on a big-endian target.  */
9172
9173           rtx loc[8];
9174           int i, offset = 0, ub = arg_size;
9175
9176           /* Align the base register.  */
9177           gpr_reg_base -= alignment;
9178
9179           ub = MIN (ub, max_arg_words - cum->words - alignment);
9180           for (i = 0; i < ub; i++)
9181             {
9182               loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9183                                           gen_rtx_REG (DImode, gpr_reg_base),
9184                                           GEN_INT (offset));
9185               gpr_reg_base -= 1;
9186               offset += 8;
9187             }
9188
9189           return gen_rtx_PARALLEL (mode, gen_rtvec_v (ub, loc));
9190         }
9191      }
9192   else
9193     {
9194       /* If the argument is larger than a word, then we know precisely
9195          which registers we must use.  */
9196       if (arg_size > 1)
9197         {
9198           if (cum->words)
9199             {
9200               gpr_reg_base = 23;
9201               fpr_reg_base = 38;
9202             }
9203           else
9204             {
9205               gpr_reg_base = 25;
9206               fpr_reg_base = 34;
9207             }
9208
9209           /* Structures 5 to 8 bytes in size are passed in the general
9210              registers in the same manner as other non floating-point
9211              objects.  The data is right-justified and zero-extended
9212              to 64 bits.  This is opposite to the normal justification
9213              used on big endian targets and requires special treatment.
9214              We now define BLOCK_REG_PADDING to pad these objects.  */
9215           if (mode == BLKmode)
9216             {
9217               rtx loc = gen_rtx_EXPR_LIST (VOIDmode,
9218                                            gen_rtx_REG (DImode, gpr_reg_base),
9219                                            const0_rtx);
9220               return gen_rtx_PARALLEL (mode, gen_rtvec (1, loc));
9221             }
9222         }
9223       else
9224         {
9225            /* We have a single word (32 bits).  A simple computation
9226               will get us the register #s we need.  */
9227            gpr_reg_base = 26 - cum->words;
9228            fpr_reg_base = 32 + 2 * cum->words;
9229         }
9230     }
9231
9232   /* Determine if the argument needs to be passed in both general and
9233      floating point registers.  */
9234   if (((TARGET_PORTABLE_RUNTIME || TARGET_64BIT || TARGET_ELF32)
9235        /* If we are doing soft-float with portable runtime, then there
9236           is no need to worry about FP regs.  */
9237        && !TARGET_SOFT_FLOAT
9238        /* The parameter must be some kind of float, else we can just
9239           pass it in integer registers.  */
9240        && FLOAT_MODE_P (mode)
9241        /* The target function must not have a prototype.  */
9242        && cum->nargs_prototype <= 0
9243        /* libcalls do not need to pass items in both FP and general
9244           registers.  */
9245        && type != NULL_TREE
9246        /* All this hair applies to "outgoing" args only.  This includes
9247           sibcall arguments setup with FUNCTION_INCOMING_ARG.  */
9248        && !cum->incoming)
9249       /* Also pass outgoing floating arguments in both registers in indirect
9250          calls with the 32 bit ABI and the HP assembler since there is no
9251          way to the specify argument locations in static functions.  */
9252       || (!TARGET_64BIT
9253           && !TARGET_GAS
9254           && !cum->incoming
9255           && cum->indirect
9256           && FLOAT_MODE_P (mode)))
9257     {
9258       retval
9259         = gen_rtx_PARALLEL
9260             (mode,
9261              gen_rtvec (2,
9262                         gen_rtx_EXPR_LIST (VOIDmode,
9263                                            gen_rtx_REG (mode, fpr_reg_base),
9264                                            const0_rtx),
9265                         gen_rtx_EXPR_LIST (VOIDmode,
9266                                            gen_rtx_REG (mode, gpr_reg_base),
9267                                            const0_rtx)));
9268     }
9269   else
9270     {
9271       /* See if we should pass this parameter in a general register.  */
9272       if (TARGET_SOFT_FLOAT
9273           /* Indirect calls in the normal 32bit ABI require all arguments
9274              to be passed in general registers.  */
9275           || (!TARGET_PORTABLE_RUNTIME
9276               && !TARGET_64BIT
9277               && !TARGET_ELF32
9278               && cum->indirect)
9279           /* If the parameter is not a floating point parameter, then
9280              it belongs in GPRs.  */
9281           || !FLOAT_MODE_P (mode))
9282         retval = gen_rtx_REG (mode, gpr_reg_base);
9283       else
9284         retval = gen_rtx_REG (mode, fpr_reg_base);
9285     }
9286   return retval;
9287 }
9288
9289
9290 /* If this arg would be passed totally in registers or totally on the stack,
9291    then this routine should return zero.  */
9292
9293 static int
9294 pa_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
9295                       tree type, bool named ATTRIBUTE_UNUSED)
9296 {
9297   unsigned int max_arg_words = 8;
9298   unsigned int offset = 0;
9299
9300   if (!TARGET_64BIT)
9301     return 0;
9302
9303   if (FUNCTION_ARG_SIZE (mode, type) > 1 && (cum->words & 1))
9304     offset = 1;
9305
9306   if (cum->words + offset + FUNCTION_ARG_SIZE (mode, type) <= max_arg_words)
9307     /* Arg fits fully into registers.  */
9308     return 0;
9309   else if (cum->words + offset >= max_arg_words)
9310     /* Arg fully on the stack.  */
9311     return 0;
9312   else
9313     /* Arg is split.  */
9314     return (max_arg_words - cum->words - offset) * UNITS_PER_WORD;
9315 }
9316
9317
9318 /* Return 1 if this is a comparison operator.  This allows the use of
9319    MATCH_OPERATOR to recognize all the branch insns.  */
9320
9321 int
9322 cmpib_comparison_operator (rtx op, enum machine_mode mode)
9323 {
9324   return ((mode == VOIDmode || GET_MODE (op) == mode)
9325           && (GET_CODE (op) == EQ
9326               || GET_CODE (op) == NE
9327               || GET_CODE (op) == GT
9328               || GET_CODE (op) == GTU
9329               || GET_CODE (op) == GE
9330               || GET_CODE (op) == LT
9331               || GET_CODE (op) == LE
9332               || GET_CODE (op) == LEU));
9333 }
9334
9335 /* Return a string to output before text in the current function.
9336
9337    This function is only used with SOM.  Because we don't support
9338    named subspaces, we can only create a new subspace or switch back
9339    to the default text subspace.  */
9340 const char *
9341 som_text_section_asm_op (void)
9342 {
9343   if (!TARGET_SOM)
9344     return "";
9345
9346   if (TARGET_GAS)
9347     {
9348       if (cfun && !cfun->machine->in_nsubspa)
9349         {
9350           /* We only want to emit a .nsubspa directive once at the
9351              start of the function.  */
9352           cfun->machine->in_nsubspa = 1;
9353
9354           /* Create a new subspace for the text.  This provides
9355              better stub placement and one-only functions.  */
9356           if (cfun->decl
9357               && DECL_ONE_ONLY (cfun->decl)
9358               && !DECL_WEAK (cfun->decl))
9359             return
9360  "\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,SORT=24,COMDAT";
9361
9362           return "\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$";
9363         }
9364       else
9365         {
9366           /* There isn't a current function or the body of the current
9367              function has been completed.  So, we are changing to the
9368              text section to output debugging information.  Do this in
9369              the default text section.  We need to forget that we are
9370              in the text section so that the function text_section in
9371              varasm.c will call us the next time around.  */
9372           forget_section ();
9373         }
9374     }
9375
9376   return "\t.SPACE $TEXT$\n\t.SUBSPA $CODE$";
9377 }
9378
9379 /* On hpux10, the linker will give an error if we have a reference
9380    in the read-only data section to a symbol defined in a shared
9381    library.  Therefore, expressions that might require a reloc can
9382    not be placed in the read-only data section.  */
9383
9384 static void
9385 pa_select_section (tree exp, int reloc,
9386                    unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
9387 {
9388   if (TREE_CODE (exp) == VAR_DECL
9389       && TREE_READONLY (exp)
9390       && !TREE_THIS_VOLATILE (exp)
9391       && DECL_INITIAL (exp)
9392       && (DECL_INITIAL (exp) == error_mark_node
9393           || TREE_CONSTANT (DECL_INITIAL (exp)))
9394       && !reloc)
9395     {
9396       if (TARGET_SOM
9397           && DECL_ONE_ONLY (exp)
9398           && !DECL_WEAK (exp))
9399         som_one_only_readonly_data_section ();
9400       else
9401         readonly_data_section ();
9402     }
9403   else if (CONSTANT_CLASS_P (exp) && !reloc)
9404     readonly_data_section ();
9405   else if (TARGET_SOM
9406            && TREE_CODE (exp) == VAR_DECL
9407            && DECL_ONE_ONLY (exp)
9408            && !DECL_WEAK (exp))
9409     som_one_only_data_section ();
9410   else
9411     data_section ();
9412 }
9413
9414 static void
9415 pa_globalize_label (FILE *stream, const char *name)
9416 {
9417   /* We only handle DATA objects here, functions are globalized in
9418      ASM_DECLARE_FUNCTION_NAME.  */
9419   if (! FUNCTION_NAME_P (name))
9420   {
9421     fputs ("\t.EXPORT ", stream);
9422     assemble_name (stream, name);
9423     fputs (",DATA\n", stream);
9424   }
9425 }
9426
9427 /* Worker function for TARGET_STRUCT_VALUE_RTX.  */
9428
9429 static rtx
9430 pa_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
9431                      int incoming ATTRIBUTE_UNUSED)
9432 {
9433   return gen_rtx_REG (Pmode, PA_STRUCT_VALUE_REGNUM);
9434 }
9435
9436 /* Worker function for TARGET_RETURN_IN_MEMORY.  */
9437
9438 bool
9439 pa_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
9440 {
9441   /* SOM ABI says that objects larger than 64 bits are returned in memory.
9442      PA64 ABI says that objects larger than 128 bits are returned in memory.
9443      Note, int_size_in_bytes can return -1 if the size of the object is
9444      variable or larger than the maximum value that can be expressed as
9445      a HOST_WIDE_INT.   It can also return zero for an empty type.  The
9446      simplest way to handle variable and empty types is to pass them in
9447      memory.  This avoids problems in defining the boundaries of argument
9448      slots, allocating registers, etc.  */
9449   return (int_size_in_bytes (type) > (TARGET_64BIT ? 16 : 8)
9450           || int_size_in_bytes (type) <= 0);
9451 }
9452
9453 #include "gt-pa.h"