OSDN Git Service

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