OSDN Git Service

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