OSDN Git Service

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