OSDN Git Service

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