OSDN Git Service

* hooks.c (hook_bool_rtx_int_false): New function.
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / pa.c
1 /* Subroutines for insn-output.c for HPPA.
2    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3    2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4    Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-attr.h"
34 #include "flags.h"
35 #include "tree.h"
36 #include "output.h"
37 #include "except.h"
38 #include "expr.h"
39 #include "optabs.h"
40 #include "reload.h"
41 #include "integrate.h"
42 #include "function.h"
43 #include "toplev.h"
44 #include "ggc.h"
45 #include "recog.h"
46 #include "predict.h"
47 #include "tm_p.h"
48 #include "target.h"
49 #include "target-def.h"
50
51 /* Return nonzero if there is a bypass for the output of 
52    OUT_INSN and the fp store IN_INSN.  */
53 int
54 hppa_fpstore_bypass_p (rtx out_insn, rtx in_insn)
55 {
56   enum machine_mode store_mode;
57   enum machine_mode other_mode;
58   rtx set;
59
60   if (recog_memoized (in_insn) < 0
61       || get_attr_type (in_insn) != TYPE_FPSTORE
62       || recog_memoized (out_insn) < 0)
63     return 0;
64
65   store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
66
67   set = single_set (out_insn);
68   if (!set)
69     return 0;
70
71   other_mode = GET_MODE (SET_SRC (set));
72
73   return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
74 }
75   
76
77 #ifndef DO_FRAME_NOTES
78 #ifdef INCOMING_RETURN_ADDR_RTX
79 #define DO_FRAME_NOTES 1
80 #else
81 #define DO_FRAME_NOTES 0
82 #endif
83 #endif
84
85 static void copy_reg_pointer (rtx, rtx);
86 static void fix_range (const char *);
87 static bool pa_handle_option (size_t, const char *, int);
88 static int hppa_address_cost (rtx);
89 static bool hppa_rtx_costs (rtx, int, int, int *);
90 static inline rtx force_mode (enum machine_mode, rtx);
91 static void pa_reorg (void);
92 static void pa_combine_instructions (void);
93 static int pa_can_combine_p (rtx, rtx, rtx, int, rtx, rtx, rtx);
94 static int forward_branch_p (rtx);
95 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
96 static int compute_movmem_length (rtx);
97 static int compute_clrmem_length (rtx);
98 static bool pa_assemble_integer (rtx, unsigned int, int);
99 static void remove_useless_addtr_insns (int);
100 static void store_reg (int, HOST_WIDE_INT, int);
101 static void store_reg_modify (int, int, HOST_WIDE_INT);
102 static void load_reg (int, HOST_WIDE_INT, int);
103 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
104 static void pa_output_function_prologue (FILE *, HOST_WIDE_INT);
105 static void update_total_code_bytes (int);
106 static void pa_output_function_epilogue (FILE *, HOST_WIDE_INT);
107 static int pa_adjust_cost (rtx, rtx, rtx, int);
108 static int pa_adjust_priority (rtx, int);
109 static int pa_issue_rate (void);
110 static void pa_select_section (tree, int, unsigned HOST_WIDE_INT)
111      ATTRIBUTE_UNUSED;
112 static void pa_encode_section_info (tree, rtx, int);
113 static const char *pa_strip_name_encoding (const char *);
114 static bool pa_function_ok_for_sibcall (tree, tree);
115 static void pa_globalize_label (FILE *, const char *)
116      ATTRIBUTE_UNUSED;
117 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
118                                     HOST_WIDE_INT, tree);
119 #if !defined(USE_COLLECT2)
120 static void pa_asm_out_constructor (rtx, int);
121 static void pa_asm_out_destructor (rtx, int);
122 #endif
123 static void pa_init_builtins (void);
124 static rtx hppa_builtin_saveregs (void);
125 static tree hppa_gimplify_va_arg_expr (tree, tree, tree *, tree *);
126 static bool pa_scalar_mode_supported_p (enum machine_mode);
127 static bool pa_commutative_p (rtx x, int outer_code);
128 static void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
129 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
130 static struct deferred_plabel *get_plabel (rtx) ATTRIBUTE_UNUSED;
131 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
132 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
133 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
134 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
135 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
136 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
137 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
138 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
139 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
140 static void output_deferred_plabels (void);
141 #ifdef ASM_OUTPUT_EXTERNAL_REAL
142 static void pa_hpux_file_end (void);
143 #endif
144 #ifdef HPUX_LONG_DOUBLE_LIBRARY
145 static void pa_hpux_init_libfuncs (void);
146 #endif
147 static rtx pa_struct_value_rtx (tree, int);
148 static bool pa_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
149                                   tree, bool);
150 static int pa_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
151                                  tree, bool);
152 static struct machine_function * pa_init_machine_status (void);
153
154
155 /* Save the operands last given to a compare for use when we
156    generate a scc or bcc insn.  */
157 rtx hppa_compare_op0, hppa_compare_op1;
158 enum cmp_type hppa_branch_type;
159
160 /* Which cpu we are scheduling for.  */
161 enum processor_type pa_cpu = TARGET_SCHED_DEFAULT;
162
163 /* The UNIX standard to use for predefines and linking.  */
164 int flag_pa_unix = TARGET_HPUX_11_11 ? 1998 : TARGET_HPUX_10_10 ? 1995 : 1993;
165
166 /* Counts for the number of callee-saved general and floating point
167    registers which were saved by the current function's prologue.  */
168 static int gr_saved, fr_saved;
169
170 static rtx find_addr_reg (rtx);
171
172 /* Keep track of the number of bytes we have output in the CODE subspace
173    during this compilation so we'll know when to emit inline long-calls.  */
174 unsigned long total_code_bytes;
175
176 /* The last address of the previous function plus the number of bytes in
177    associated thunks that have been output.  This is used to determine if
178    a thunk can use an IA-relative branch to reach its target function.  */
179 static int last_address;
180
181 /* Variables to handle plabels that we discover are necessary at assembly
182    output time.  They are output after the current function.  */
183 struct deferred_plabel GTY(())
184 {
185   rtx internal_label;
186   rtx symbol;
187 };
188 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
189   deferred_plabels;
190 static size_t n_deferred_plabels = 0;
191
192 \f
193 /* Initialize the GCC target structure.  */
194
195 #undef TARGET_ASM_ALIGNED_HI_OP
196 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
197 #undef TARGET_ASM_ALIGNED_SI_OP
198 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
199 #undef TARGET_ASM_ALIGNED_DI_OP
200 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
201 #undef TARGET_ASM_UNALIGNED_HI_OP
202 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
203 #undef TARGET_ASM_UNALIGNED_SI_OP
204 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
205 #undef TARGET_ASM_UNALIGNED_DI_OP
206 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
207 #undef TARGET_ASM_INTEGER
208 #define TARGET_ASM_INTEGER pa_assemble_integer
209
210 #undef TARGET_ASM_FUNCTION_PROLOGUE
211 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
212 #undef TARGET_ASM_FUNCTION_EPILOGUE
213 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
214
215 #undef TARGET_SCHED_ADJUST_COST
216 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
217 #undef TARGET_SCHED_ADJUST_PRIORITY
218 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
219 #undef TARGET_SCHED_ISSUE_RATE
220 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
221
222 #undef TARGET_ENCODE_SECTION_INFO
223 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
224 #undef TARGET_STRIP_NAME_ENCODING
225 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
226
227 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
228 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
229
230 #undef TARGET_COMMUTATIVE_P
231 #define TARGET_COMMUTATIVE_P pa_commutative_p
232
233 #undef TARGET_ASM_OUTPUT_MI_THUNK
234 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
235 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
236 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
237
238 #undef TARGET_ASM_FILE_END
239 #ifdef ASM_OUTPUT_EXTERNAL_REAL
240 #define TARGET_ASM_FILE_END pa_hpux_file_end
241 #else
242 #define TARGET_ASM_FILE_END output_deferred_plabels
243 #endif
244
245 #if !defined(USE_COLLECT2)
246 #undef TARGET_ASM_CONSTRUCTOR
247 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
248 #undef TARGET_ASM_DESTRUCTOR
249 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
250 #endif
251
252 #undef TARGET_DEFAULT_TARGET_FLAGS
253 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | TARGET_CPU_DEFAULT)
254 #undef TARGET_HANDLE_OPTION
255 #define TARGET_HANDLE_OPTION pa_handle_option
256
257 #undef TARGET_INIT_BUILTINS
258 #define TARGET_INIT_BUILTINS pa_init_builtins
259
260 #undef TARGET_RTX_COSTS
261 #define TARGET_RTX_COSTS hppa_rtx_costs
262 #undef TARGET_ADDRESS_COST
263 #define TARGET_ADDRESS_COST hppa_address_cost
264
265 #undef TARGET_MACHINE_DEPENDENT_REORG
266 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
267
268 #ifdef HPUX_LONG_DOUBLE_LIBRARY
269 #undef TARGET_INIT_LIBFUNCS
270 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
271 #endif
272
273 #undef TARGET_PROMOTE_FUNCTION_RETURN
274 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
275 #undef TARGET_PROMOTE_PROTOTYPES
276 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
277
278 #undef TARGET_STRUCT_VALUE_RTX
279 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
280 #undef TARGET_RETURN_IN_MEMORY
281 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
282 #undef TARGET_MUST_PASS_IN_STACK
283 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
284 #undef TARGET_PASS_BY_REFERENCE
285 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
286 #undef TARGET_CALLEE_COPIES
287 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
288 #undef TARGET_ARG_PARTIAL_BYTES
289 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
290
291 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
292 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
293 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
294 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
295
296 #undef TARGET_SCALAR_MODE_SUPPORTED_P
297 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
298
299 #undef TARGET_CANNOT_FORCE_CONST_MEM
300 #define TARGET_CANNOT_FORCE_CONST_MEM pa_tls_referenced_p
301
302 struct gcc_target targetm = TARGET_INITIALIZER;
303 \f
304 /* Parse the -mfixed-range= option string.  */
305
306 static void
307 fix_range (const char *const_str)
308 {
309   int i, first, last;
310   char *str, *dash, *comma;
311
312   /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
313      REG2 are either register names or register numbers.  The effect
314      of this option is to mark the registers in the range from REG1 to
315      REG2 as ``fixed'' so they won't be used by the compiler.  This is
316      used, e.g., to ensure that kernel mode code doesn't use fr4-fr31.  */
317
318   i = strlen (const_str);
319   str = (char *) alloca (i + 1);
320   memcpy (str, const_str, i + 1);
321
322   while (1)
323     {
324       dash = strchr (str, '-');
325       if (!dash)
326         {
327           warning (0, "value of -mfixed-range must have form REG1-REG2");
328           return;
329         }
330       *dash = '\0';
331
332       comma = strchr (dash + 1, ',');
333       if (comma)
334         *comma = '\0';
335
336       first = decode_reg_name (str);
337       if (first < 0)
338         {
339           warning (0, "unknown register name: %s", str);
340           return;
341         }
342
343       last = decode_reg_name (dash + 1);
344       if (last < 0)
345         {
346           warning (0, "unknown register name: %s", dash + 1);
347           return;
348         }
349
350       *dash = '-';
351
352       if (first > last)
353         {
354           warning (0, "%s-%s is an empty range", str, dash + 1);
355           return;
356         }
357
358       for (i = first; i <= last; ++i)
359         fixed_regs[i] = call_used_regs[i] = 1;
360
361       if (!comma)
362         break;
363
364       *comma = ',';
365       str = comma + 1;
366     }
367
368   /* Check if all floating point registers have been fixed.  */
369   for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
370     if (!fixed_regs[i])
371       break;
372
373   if (i > FP_REG_LAST)
374     target_flags |= MASK_DISABLE_FPREGS;
375 }
376
377 /* Implement TARGET_HANDLE_OPTION.  */
378
379 static bool
380 pa_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
381 {
382   switch (code)
383     {
384     case OPT_mnosnake:
385     case OPT_mpa_risc_1_0:
386     case OPT_march_1_0:
387       target_flags &= ~(MASK_PA_11 | MASK_PA_20);
388       return true;
389
390     case OPT_msnake:
391     case OPT_mpa_risc_1_1:
392     case OPT_march_1_1:
393       target_flags &= ~MASK_PA_20;
394       target_flags |= MASK_PA_11;
395       return true;
396
397     case OPT_mpa_risc_2_0:
398     case OPT_march_2_0:
399       target_flags |= MASK_PA_11 | MASK_PA_20;
400       return true;
401
402     case OPT_mschedule_:
403       if (strcmp (arg, "8000") == 0)
404         pa_cpu = PROCESSOR_8000;
405       else if (strcmp (arg, "7100") == 0)
406         pa_cpu = PROCESSOR_7100;
407       else if (strcmp (arg, "700") == 0)
408         pa_cpu = PROCESSOR_700;
409       else if (strcmp (arg, "7100LC") == 0)
410         pa_cpu = PROCESSOR_7100LC;
411       else if (strcmp (arg, "7200") == 0)
412         pa_cpu = PROCESSOR_7200;
413       else if (strcmp (arg, "7300") == 0)
414         pa_cpu = PROCESSOR_7300;
415       else
416         return false;
417       return true;
418
419     case OPT_mfixed_range_:
420       fix_range (arg);
421       return true;
422
423 #if TARGET_HPUX
424     case OPT_munix_93:
425       flag_pa_unix = 1993;
426       return true;
427 #endif
428
429 #if TARGET_HPUX_10_10
430     case OPT_munix_95:
431       flag_pa_unix = 1995;
432       return true;
433 #endif
434
435 #if TARGET_HPUX_11_11
436     case OPT_munix_98:
437       flag_pa_unix = 1998;
438       return true;
439 #endif
440
441     default:
442       return true;
443     }
444 }
445
446 void
447 override_options (void)
448 {
449   /* Unconditional branches in the delay slot are not compatible with dwarf2
450      call frame information.  There is no benefit in using this optimization
451      on PA8000 and later processors.  */
452   if (pa_cpu >= PROCESSOR_8000
453       || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
454       || flag_unwind_tables)
455     target_flags &= ~MASK_JUMP_IN_DELAY;
456
457   if (flag_pic && TARGET_PORTABLE_RUNTIME)
458     {
459       warning (0, "PIC code generation is not supported in the portable runtime model");
460     }
461
462   if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
463    {
464       warning (0, "PIC code generation is not compatible with fast indirect calls");
465    }
466
467   if (! TARGET_GAS && write_symbols != NO_DEBUG)
468     {
469       warning (0, "-g is only supported when using GAS on this processor,");
470       warning (0, "-g option disabled");
471       write_symbols = NO_DEBUG;
472     }
473
474   /* We only support the "big PIC" model now.  And we always generate PIC
475      code when in 64bit mode.  */
476   if (flag_pic == 1 || TARGET_64BIT)
477     flag_pic = 2;
478
479   /* We can't guarantee that .dword is available for 32-bit targets.  */
480   if (UNITS_PER_WORD == 4)
481     targetm.asm_out.aligned_op.di = NULL;
482
483   /* The unaligned ops are only available when using GAS.  */
484   if (!TARGET_GAS)
485     {
486       targetm.asm_out.unaligned_op.hi = NULL;
487       targetm.asm_out.unaligned_op.si = NULL;
488       targetm.asm_out.unaligned_op.di = NULL;
489     }
490
491   init_machine_status = pa_init_machine_status;
492 }
493
494 static void
495 pa_init_builtins (void)
496 {
497 #ifdef DONT_HAVE_FPUTC_UNLOCKED
498   built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
499   implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
500 #endif
501 }
502
503 /* Function to init struct machine_function.
504    This will be called, via a pointer variable,
505    from push_function_context.  */
506
507 static struct machine_function *
508 pa_init_machine_status (void)
509 {
510   return ggc_alloc_cleared (sizeof (machine_function));
511 }
512
513 /* If FROM is a probable pointer register, mark TO as a probable
514    pointer register with the same pointer alignment as FROM.  */
515
516 static void
517 copy_reg_pointer (rtx to, rtx from)
518 {
519   if (REG_POINTER (from))
520     mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
521 }
522
523 /* Return 1 if X contains a symbolic expression.  We know these
524    expressions will have one of a few well defined forms, so
525    we need only check those forms.  */
526 int
527 symbolic_expression_p (rtx x)
528 {
529
530   /* Strip off any HIGH.  */
531   if (GET_CODE (x) == HIGH)
532     x = XEXP (x, 0);
533
534   return (symbolic_operand (x, VOIDmode));
535 }
536
537 /* Accept any constant that can be moved in one instruction into a
538    general register.  */
539 int
540 cint_ok_for_move (HOST_WIDE_INT intval)
541 {
542   /* OK if ldo, ldil, or zdepi, can be used.  */
543   return (CONST_OK_FOR_LETTER_P (intval, 'J')
544           || CONST_OK_FOR_LETTER_P (intval, 'N')
545           || CONST_OK_FOR_LETTER_P (intval, 'K'));
546 }
547 \f
548 /* Return truth value of whether OP can be used as an operand in a
549    adddi3 insn.  */
550 int
551 adddi3_operand (rtx op, enum machine_mode mode)
552 {
553   return (register_operand (op, mode)
554           || (GET_CODE (op) == CONST_INT
555               && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
556 }
557
558 /* True iff zdepi can be used to generate this CONST_INT.
559    zdepi first sign extends a 5 bit signed number to a given field
560    length, then places this field anywhere in a zero.  */
561 int
562 zdepi_cint_p (unsigned HOST_WIDE_INT x)
563 {
564   unsigned HOST_WIDE_INT lsb_mask, t;
565
566   /* This might not be obvious, but it's at least fast.
567      This function is critical; we don't have the time loops would take.  */
568   lsb_mask = x & -x;
569   t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
570   /* Return true iff t is a power of two.  */
571   return ((t & (t - 1)) == 0);
572 }
573
574 /* True iff depi or extru can be used to compute (reg & mask).
575    Accept bit pattern like these:
576    0....01....1
577    1....10....0
578    1..10..01..1  */
579 int
580 and_mask_p (unsigned HOST_WIDE_INT mask)
581 {
582   mask = ~mask;
583   mask += mask & -mask;
584   return (mask & (mask - 1)) == 0;
585 }
586
587 /* True iff depi can be used to compute (reg | MASK).  */
588 int
589 ior_mask_p (unsigned HOST_WIDE_INT mask)
590 {
591   mask += mask & -mask;
592   return (mask & (mask - 1)) == 0;
593 }
594 \f
595 /* Legitimize PIC addresses.  If the address is already
596    position-independent, we return ORIG.  Newly generated
597    position-independent addresses go to REG.  If we need more
598    than one register, we lose.  */
599
600 rtx
601 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
602 {
603   rtx pic_ref = orig;
604
605   gcc_assert (!PA_SYMBOL_REF_TLS_P (orig));
606
607   /* Labels need special handling.  */
608   if (pic_label_operand (orig, mode))
609     {
610       /* We do not want to go through the movXX expanders here since that
611          would create recursion.
612
613          Nor do we really want to call a generator for a named pattern
614          since that requires multiple patterns if we want to support
615          multiple word sizes.
616
617          So instead we just emit the raw set, which avoids the movXX
618          expanders completely.  */
619       mark_reg_pointer (reg, BITS_PER_UNIT);
620       emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
621       current_function_uses_pic_offset_table = 1;
622       return reg;
623     }
624   if (GET_CODE (orig) == SYMBOL_REF)
625     {
626       rtx insn, tmp_reg;
627
628       gcc_assert (reg);
629
630       /* Before reload, allocate a temporary register for the intermediate
631          result.  This allows the sequence to be deleted when the final
632          result is unused and the insns are trivially dead.  */
633       tmp_reg = ((reload_in_progress || reload_completed)
634                  ? reg : gen_reg_rtx (Pmode));
635
636       emit_move_insn (tmp_reg,
637                       gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
638                                     gen_rtx_HIGH (word_mode, orig)));
639       pic_ref
640         = gen_const_mem (Pmode,
641                          gen_rtx_LO_SUM (Pmode, tmp_reg,
642                                          gen_rtx_UNSPEC (Pmode,
643                                                          gen_rtvec (1, orig),
644                                                          UNSPEC_DLTIND14R)));
645
646       current_function_uses_pic_offset_table = 1;
647       mark_reg_pointer (reg, BITS_PER_UNIT);
648       insn = emit_move_insn (reg, pic_ref);
649
650       /* Put a REG_EQUAL note on this insn, so that it can be optimized.  */
651       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig, REG_NOTES (insn));
652
653       return reg;
654     }
655   else if (GET_CODE (orig) == CONST)
656     {
657       rtx base;
658
659       if (GET_CODE (XEXP (orig, 0)) == PLUS
660           && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
661         return orig;
662
663       gcc_assert (reg);
664       gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
665       
666       base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
667       orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
668                                      base == reg ? 0 : reg);
669
670       if (GET_CODE (orig) == CONST_INT)
671         {
672           if (INT_14_BITS (orig))
673             return plus_constant (base, INTVAL (orig));
674           orig = force_reg (Pmode, orig);
675         }
676       pic_ref = gen_rtx_PLUS (Pmode, base, orig);
677       /* Likewise, should we set special REG_NOTEs here?  */
678     }
679
680   return pic_ref;
681 }
682
683 static GTY(()) rtx gen_tls_tga;
684
685 static rtx
686 gen_tls_get_addr (void)
687 {
688   if (!gen_tls_tga)
689     gen_tls_tga = init_one_libfunc ("__tls_get_addr");
690   return gen_tls_tga;
691 }
692
693 static rtx
694 hppa_tls_call (rtx arg)
695 {
696   rtx ret;
697
698   ret = gen_reg_rtx (Pmode);
699   emit_library_call_value (gen_tls_get_addr (), ret,
700                            LCT_CONST, Pmode, 1, arg, Pmode);
701
702   return ret;
703 }
704
705 static rtx
706 legitimize_tls_address (rtx addr)
707 {
708   rtx ret, insn, tmp, t1, t2, tp;
709   enum tls_model model = SYMBOL_REF_TLS_MODEL (addr);
710
711   switch (model) 
712     {
713       case TLS_MODEL_GLOBAL_DYNAMIC:
714         tmp = gen_reg_rtx (Pmode);
715         emit_insn (gen_tgd_load (tmp, addr));
716         ret = hppa_tls_call (tmp);
717         break;
718
719       case TLS_MODEL_LOCAL_DYNAMIC:
720         ret = gen_reg_rtx (Pmode);
721         tmp = gen_reg_rtx (Pmode);
722         start_sequence ();
723         emit_insn (gen_tld_load (tmp, addr));
724         t1 = hppa_tls_call (tmp);
725         insn = get_insns ();
726         end_sequence ();
727         t2 = gen_reg_rtx (Pmode);
728         emit_libcall_block (insn, t2, t1, 
729                             gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
730                                             UNSPEC_TLSLDBASE));
731         emit_insn (gen_tld_offset_load (ret, addr, t2));
732         break;
733
734       case TLS_MODEL_INITIAL_EXEC:
735         tp = gen_reg_rtx (Pmode);
736         tmp = gen_reg_rtx (Pmode);
737         ret = gen_reg_rtx (Pmode);
738         emit_insn (gen_tp_load (tp));
739         emit_insn (gen_tie_load (tmp, addr));
740         emit_move_insn (ret, gen_rtx_PLUS (Pmode, tp, tmp));
741         break;
742
743       case TLS_MODEL_LOCAL_EXEC:
744         tp = gen_reg_rtx (Pmode);
745         ret = gen_reg_rtx (Pmode);
746         emit_insn (gen_tp_load (tp));
747         emit_insn (gen_tle_load (ret, addr, tp));
748         break;
749
750       default:
751         gcc_unreachable ();
752     }
753
754   return ret;
755 }
756
757 /* Try machine-dependent ways of modifying an illegitimate address
758    to be legitimate.  If we find one, return the new, valid address.
759    This macro is used in only one place: `memory_address' in explow.c.
760
761    OLDX is the address as it was before break_out_memory_refs was called.
762    In some cases it is useful to look at this to decide what needs to be done.
763
764    MODE and WIN are passed so that this macro can use
765    GO_IF_LEGITIMATE_ADDRESS.
766
767    It is always safe for this macro to do nothing.  It exists to recognize
768    opportunities to optimize the output.
769
770    For the PA, transform:
771
772         memory(X + <large int>)
773
774    into:
775
776         if (<large int> & mask) >= 16
777           Y = (<large int> & ~mask) + mask + 1  Round up.
778         else
779           Y = (<large int> & ~mask)             Round down.
780         Z = X + Y
781         memory (Z + (<large int> - Y));
782
783    This is for CSE to find several similar references, and only use one Z.
784
785    X can either be a SYMBOL_REF or REG, but because combine cannot
786    perform a 4->2 combination we do nothing for SYMBOL_REF + D where
787    D will not fit in 14 bits.
788
789    MODE_FLOAT references allow displacements which fit in 5 bits, so use
790    0x1f as the mask.
791
792    MODE_INT references allow displacements which fit in 14 bits, so use
793    0x3fff as the mask.
794
795    This relies on the fact that most mode MODE_FLOAT references will use FP
796    registers and most mode MODE_INT references will use integer registers.
797    (In the rare case of an FP register used in an integer MODE, we depend
798    on secondary reloads to clean things up.)
799
800
801    It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
802    manner if Y is 2, 4, or 8.  (allows more shadd insns and shifted indexed
803    addressing modes to be used).
804
805    Put X and Z into registers.  Then put the entire expression into
806    a register.  */
807
808 rtx
809 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
810                          enum machine_mode mode)
811 {
812   rtx orig = x;
813
814   /* We need to canonicalize the order of operands in unscaled indexed
815      addresses since the code that checks if an address is valid doesn't
816      always try both orders.  */
817   if (!TARGET_NO_SPACE_REGS
818       && GET_CODE (x) == PLUS
819       && GET_MODE (x) == Pmode
820       && REG_P (XEXP (x, 0))
821       && REG_P (XEXP (x, 1))
822       && REG_POINTER (XEXP (x, 0))
823       && !REG_POINTER (XEXP (x, 1)))
824     return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
825
826   if (PA_SYMBOL_REF_TLS_P (x))
827     return legitimize_tls_address (x);
828   else if (flag_pic)
829     return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
830
831   /* Strip off CONST.  */
832   if (GET_CODE (x) == CONST)
833     x = XEXP (x, 0);
834
835   /* Special case.  Get the SYMBOL_REF into a register and use indexing.
836      That should always be safe.  */
837   if (GET_CODE (x) == PLUS
838       && GET_CODE (XEXP (x, 0)) == REG
839       && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
840     {
841       rtx reg = force_reg (Pmode, XEXP (x, 1));
842       return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
843     }
844
845   /* Note we must reject symbols which represent function addresses
846      since the assembler/linker can't handle arithmetic on plabels.  */
847   if (GET_CODE (x) == PLUS
848       && GET_CODE (XEXP (x, 1)) == CONST_INT
849       && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
850            && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
851           || GET_CODE (XEXP (x, 0)) == REG))
852     {
853       rtx int_part, ptr_reg;
854       int newoffset;
855       int offset = INTVAL (XEXP (x, 1));
856       int mask;
857
858       mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
859               ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
860
861       /* Choose which way to round the offset.  Round up if we
862          are >= halfway to the next boundary.  */
863       if ((offset & mask) >= ((mask + 1) / 2))
864         newoffset = (offset & ~ mask) + mask + 1;
865       else
866         newoffset = (offset & ~ mask);
867
868       /* If the newoffset will not fit in 14 bits (ldo), then
869          handling this would take 4 or 5 instructions (2 to load
870          the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
871          add the new offset and the SYMBOL_REF.)  Combine can
872          not handle 4->2 or 5->2 combinations, so do not create
873          them.  */
874       if (! VAL_14_BITS_P (newoffset)
875           && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
876         {
877           rtx const_part = plus_constant (XEXP (x, 0), newoffset);
878           rtx tmp_reg
879             = force_reg (Pmode,
880                          gen_rtx_HIGH (Pmode, const_part));
881           ptr_reg
882             = force_reg (Pmode,
883                          gen_rtx_LO_SUM (Pmode,
884                                          tmp_reg, const_part));
885         }
886       else
887         {
888           if (! VAL_14_BITS_P (newoffset))
889             int_part = force_reg (Pmode, GEN_INT (newoffset));
890           else
891             int_part = GEN_INT (newoffset);
892
893           ptr_reg = force_reg (Pmode,
894                                gen_rtx_PLUS (Pmode,
895                                              force_reg (Pmode, XEXP (x, 0)),
896                                              int_part));
897         }
898       return plus_constant (ptr_reg, offset - newoffset);
899     }
900
901   /* Handle (plus (mult (a) (shadd_constant)) (b)).  */
902
903   if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
904       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
905       && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
906       && (OBJECT_P (XEXP (x, 1))
907           || GET_CODE (XEXP (x, 1)) == SUBREG)
908       && GET_CODE (XEXP (x, 1)) != CONST)
909     {
910       int val = INTVAL (XEXP (XEXP (x, 0), 1));
911       rtx reg1, reg2;
912
913       reg1 = XEXP (x, 1);
914       if (GET_CODE (reg1) != REG)
915         reg1 = force_reg (Pmode, force_operand (reg1, 0));
916
917       reg2 = XEXP (XEXP (x, 0), 0);
918       if (GET_CODE (reg2) != REG)
919         reg2 = force_reg (Pmode, force_operand (reg2, 0));
920
921       return force_reg (Pmode, gen_rtx_PLUS (Pmode,
922                                              gen_rtx_MULT (Pmode,
923                                                            reg2,
924                                                            GEN_INT (val)),
925                                              reg1));
926     }
927
928   /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
929
930      Only do so for floating point modes since this is more speculative
931      and we lose if it's an integer store.  */
932   if (GET_CODE (x) == PLUS
933       && GET_CODE (XEXP (x, 0)) == PLUS
934       && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
935       && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
936       && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
937       && (mode == SFmode || mode == DFmode))
938     {
939
940       /* First, try and figure out what to use as a base register.  */
941       rtx reg1, reg2, base, idx, orig_base;
942
943       reg1 = XEXP (XEXP (x, 0), 1);
944       reg2 = XEXP (x, 1);
945       base = NULL_RTX;
946       idx = NULL_RTX;
947
948       /* Make sure they're both regs.  If one was a SYMBOL_REF [+ const],
949          then emit_move_sequence will turn on REG_POINTER so we'll know
950          it's a base register below.  */
951       if (GET_CODE (reg1) != REG)
952         reg1 = force_reg (Pmode, force_operand (reg1, 0));
953
954       if (GET_CODE (reg2) != REG)
955         reg2 = force_reg (Pmode, force_operand (reg2, 0));
956
957       /* Figure out what the base and index are.  */
958
959       if (GET_CODE (reg1) == REG
960           && REG_POINTER (reg1))
961         {
962           base = reg1;
963           orig_base = XEXP (XEXP (x, 0), 1);
964           idx = gen_rtx_PLUS (Pmode,
965                               gen_rtx_MULT (Pmode,
966                                             XEXP (XEXP (XEXP (x, 0), 0), 0),
967                                             XEXP (XEXP (XEXP (x, 0), 0), 1)),
968                               XEXP (x, 1));
969         }
970       else if (GET_CODE (reg2) == REG
971                && REG_POINTER (reg2))
972         {
973           base = reg2;
974           orig_base = XEXP (x, 1);
975           idx = XEXP (x, 0);
976         }
977
978       if (base == 0)
979         return orig;
980
981       /* If the index adds a large constant, try to scale the
982          constant so that it can be loaded with only one insn.  */
983       if (GET_CODE (XEXP (idx, 1)) == CONST_INT
984           && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
985                             / INTVAL (XEXP (XEXP (idx, 0), 1)))
986           && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
987         {
988           /* Divide the CONST_INT by the scale factor, then add it to A.  */
989           int val = INTVAL (XEXP (idx, 1));
990
991           val /= INTVAL (XEXP (XEXP (idx, 0), 1));
992           reg1 = XEXP (XEXP (idx, 0), 0);
993           if (GET_CODE (reg1) != REG)
994             reg1 = force_reg (Pmode, force_operand (reg1, 0));
995
996           reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
997
998           /* We can now generate a simple scaled indexed address.  */
999           return
1000             force_reg
1001               (Pmode, gen_rtx_PLUS (Pmode,
1002                                     gen_rtx_MULT (Pmode, reg1,
1003                                                   XEXP (XEXP (idx, 0), 1)),
1004                                     base));
1005         }
1006
1007       /* If B + C is still a valid base register, then add them.  */
1008       if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1009           && INTVAL (XEXP (idx, 1)) <= 4096
1010           && INTVAL (XEXP (idx, 1)) >= -4096)
1011         {
1012           int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1013           rtx reg1, reg2;
1014
1015           reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1016
1017           reg2 = XEXP (XEXP (idx, 0), 0);
1018           if (GET_CODE (reg2) != CONST_INT)
1019             reg2 = force_reg (Pmode, force_operand (reg2, 0));
1020
1021           return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1022                                                  gen_rtx_MULT (Pmode,
1023                                                                reg2,
1024                                                                GEN_INT (val)),
1025                                                  reg1));
1026         }
1027
1028       /* Get the index into a register, then add the base + index and
1029          return a register holding the result.  */
1030
1031       /* First get A into a register.  */
1032       reg1 = XEXP (XEXP (idx, 0), 0);
1033       if (GET_CODE (reg1) != REG)
1034         reg1 = force_reg (Pmode, force_operand (reg1, 0));
1035
1036       /* And get B into a register.  */
1037       reg2 = XEXP (idx, 1);
1038       if (GET_CODE (reg2) != REG)
1039         reg2 = force_reg (Pmode, force_operand (reg2, 0));
1040
1041       reg1 = force_reg (Pmode,
1042                         gen_rtx_PLUS (Pmode,
1043                                       gen_rtx_MULT (Pmode, reg1,
1044                                                     XEXP (XEXP (idx, 0), 1)),
1045                                       reg2));
1046
1047       /* Add the result to our base register and return.  */
1048       return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1049
1050     }
1051
1052   /* Uh-oh.  We might have an address for x[n-100000].  This needs
1053      special handling to avoid creating an indexed memory address
1054      with x-100000 as the base.
1055
1056      If the constant part is small enough, then it's still safe because
1057      there is a guard page at the beginning and end of the data segment.
1058
1059      Scaled references are common enough that we want to try and rearrange the
1060      terms so that we can use indexing for these addresses too.  Only
1061      do the optimization for floatint point modes.  */
1062
1063   if (GET_CODE (x) == PLUS
1064       && symbolic_expression_p (XEXP (x, 1)))
1065     {
1066       /* Ugly.  We modify things here so that the address offset specified
1067          by the index expression is computed first, then added to x to form
1068          the entire address.  */
1069
1070       rtx regx1, regx2, regy1, regy2, y;
1071
1072       /* Strip off any CONST.  */
1073       y = XEXP (x, 1);
1074       if (GET_CODE (y) == CONST)
1075         y = XEXP (y, 0);
1076
1077       if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1078         {
1079           /* See if this looks like
1080                 (plus (mult (reg) (shadd_const))
1081                       (const (plus (symbol_ref) (const_int))))
1082
1083              Where const_int is small.  In that case the const
1084              expression is a valid pointer for indexing.
1085
1086              If const_int is big, but can be divided evenly by shadd_const
1087              and added to (reg).  This allows more scaled indexed addresses.  */
1088           if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1089               && GET_CODE (XEXP (x, 0)) == MULT
1090               && GET_CODE (XEXP (y, 1)) == CONST_INT
1091               && INTVAL (XEXP (y, 1)) >= -4096
1092               && INTVAL (XEXP (y, 1)) <= 4095
1093               && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1094               && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1095             {
1096               int val = INTVAL (XEXP (XEXP (x, 0), 1));
1097               rtx reg1, reg2;
1098
1099               reg1 = XEXP (x, 1);
1100               if (GET_CODE (reg1) != REG)
1101                 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1102
1103               reg2 = XEXP (XEXP (x, 0), 0);
1104               if (GET_CODE (reg2) != REG)
1105                 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1106
1107               return force_reg (Pmode,
1108                                 gen_rtx_PLUS (Pmode,
1109                                               gen_rtx_MULT (Pmode,
1110                                                             reg2,
1111                                                             GEN_INT (val)),
1112                                               reg1));
1113             }
1114           else if ((mode == DFmode || mode == SFmode)
1115                    && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1116                    && GET_CODE (XEXP (x, 0)) == MULT
1117                    && GET_CODE (XEXP (y, 1)) == CONST_INT
1118                    && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1119                    && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1120                    && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1121             {
1122               regx1
1123                 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1124                                              / INTVAL (XEXP (XEXP (x, 0), 1))));
1125               regx2 = XEXP (XEXP (x, 0), 0);
1126               if (GET_CODE (regx2) != REG)
1127                 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1128               regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1129                                                         regx2, regx1));
1130               return
1131                 force_reg (Pmode,
1132                            gen_rtx_PLUS (Pmode,
1133                                          gen_rtx_MULT (Pmode, regx2,
1134                                                        XEXP (XEXP (x, 0), 1)),
1135                                          force_reg (Pmode, XEXP (y, 0))));
1136             }
1137           else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1138                    && INTVAL (XEXP (y, 1)) >= -4096
1139                    && INTVAL (XEXP (y, 1)) <= 4095)
1140             {
1141               /* This is safe because of the guard page at the
1142                  beginning and end of the data space.  Just
1143                  return the original address.  */
1144               return orig;
1145             }
1146           else
1147             {
1148               /* Doesn't look like one we can optimize.  */
1149               regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1150               regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1151               regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1152               regx1 = force_reg (Pmode,
1153                                  gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1154                                                  regx1, regy2));
1155               return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1156             }
1157         }
1158     }
1159
1160   return orig;
1161 }
1162
1163 /* For the HPPA, REG and REG+CONST is cost 0
1164    and addresses involving symbolic constants are cost 2.
1165
1166    PIC addresses are very expensive.
1167
1168    It is no coincidence that this has the same structure
1169    as GO_IF_LEGITIMATE_ADDRESS.  */
1170
1171 static int
1172 hppa_address_cost (rtx X)
1173 {
1174   switch (GET_CODE (X))
1175     {
1176     case REG:
1177     case PLUS:
1178     case LO_SUM:
1179       return 1;
1180     case HIGH:
1181       return 2;
1182     default:
1183       return 4;
1184     }
1185 }
1186
1187 /* Compute a (partial) cost for rtx X.  Return true if the complete
1188    cost has been computed, and false if subexpressions should be
1189    scanned.  In either case, *TOTAL contains the cost result.  */
1190
1191 static bool
1192 hppa_rtx_costs (rtx x, int code, int outer_code, int *total)
1193 {
1194   switch (code)
1195     {
1196     case CONST_INT:
1197       if (INTVAL (x) == 0)
1198         *total = 0;
1199       else if (INT_14_BITS (x))
1200         *total = 1;
1201       else
1202         *total = 2;
1203       return true;
1204
1205     case HIGH:
1206       *total = 2;
1207       return true;
1208
1209     case CONST:
1210     case LABEL_REF:
1211     case SYMBOL_REF:
1212       *total = 4;
1213       return true;
1214
1215     case CONST_DOUBLE:
1216       if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1217           && outer_code != SET)
1218         *total = 0;
1219       else
1220         *total = 8;
1221       return true;
1222
1223     case MULT:
1224       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1225         *total = COSTS_N_INSNS (3);
1226       else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1227         *total = COSTS_N_INSNS (8);
1228       else
1229         *total = COSTS_N_INSNS (20);
1230       return true;
1231
1232     case DIV:
1233       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1234         {
1235           *total = COSTS_N_INSNS (14);
1236           return true;
1237         }
1238       /* FALLTHRU */
1239
1240     case UDIV:
1241     case MOD:
1242     case UMOD:
1243       *total = COSTS_N_INSNS (60);
1244       return true;
1245
1246     case PLUS: /* this includes shNadd insns */
1247     case MINUS:
1248       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1249         *total = COSTS_N_INSNS (3);
1250       else
1251         *total = COSTS_N_INSNS (1);
1252       return true;
1253
1254     case ASHIFT:
1255     case ASHIFTRT:
1256     case LSHIFTRT:
1257       *total = COSTS_N_INSNS (1);
1258       return true;
1259
1260     default:
1261       return false;
1262     }
1263 }
1264
1265 /* Ensure mode of ORIG, a REG rtx, is MODE.  Returns either ORIG or a
1266    new rtx with the correct mode.  */
1267 static inline rtx
1268 force_mode (enum machine_mode mode, rtx orig)
1269 {
1270   if (mode == GET_MODE (orig))
1271     return orig;
1272
1273   gcc_assert (REGNO (orig) < FIRST_PSEUDO_REGISTER);
1274
1275   return gen_rtx_REG (mode, REGNO (orig));
1276 }
1277
1278 /* Return 1 if *X is a thread-local symbol.  */
1279
1280 static int
1281 pa_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1282 {
1283   return PA_SYMBOL_REF_TLS_P (*x);
1284 }
1285
1286 /* Return 1 if X contains a thread-local symbol.  */
1287
1288 bool
1289 pa_tls_referenced_p (rtx x)
1290 {
1291   if (!TARGET_HAVE_TLS)
1292     return false;
1293
1294   return for_each_rtx (&x, &pa_tls_symbol_ref_1, 0);
1295 }
1296
1297 /* Emit insns to move operands[1] into operands[0].
1298
1299    Return 1 if we have written out everything that needs to be done to
1300    do the move.  Otherwise, return 0 and the caller will emit the move
1301    normally.
1302
1303    Note SCRATCH_REG may not be in the proper mode depending on how it
1304    will be used.  This routine is responsible for creating a new copy
1305    of SCRATCH_REG in the proper mode.  */
1306
1307 int
1308 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1309 {
1310   register rtx operand0 = operands[0];
1311   register rtx operand1 = operands[1];
1312   register rtx tem;
1313
1314   /* We can only handle indexed addresses in the destination operand
1315      of floating point stores.  Thus, we need to break out indexed
1316      addresses from the destination operand.  */
1317   if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1318     {
1319       /* This is only safe up to the beginning of life analysis.  */
1320       gcc_assert (!no_new_pseudos);
1321
1322       tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1323       operand0 = replace_equiv_address (operand0, tem);
1324     }
1325
1326   /* On targets with non-equivalent space registers, break out unscaled
1327      indexed addresses from the source operand before the final CSE.
1328      We have to do this because the REG_POINTER flag is not correctly
1329      carried through various optimization passes and CSE may substitute
1330      a pseudo without the pointer set for one with the pointer set.  As
1331      a result, we loose various opportunities to create insns with
1332      unscaled indexed addresses.  */
1333   if (!TARGET_NO_SPACE_REGS
1334       && !cse_not_expected
1335       && GET_CODE (operand1) == MEM
1336       && GET_CODE (XEXP (operand1, 0)) == PLUS
1337       && REG_P (XEXP (XEXP (operand1, 0), 0))
1338       && REG_P (XEXP (XEXP (operand1, 0), 1)))
1339     operand1
1340       = replace_equiv_address (operand1,
1341                                copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1342
1343   if (scratch_reg
1344       && reload_in_progress && GET_CODE (operand0) == REG
1345       && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1346     operand0 = reg_equiv_mem[REGNO (operand0)];
1347   else if (scratch_reg
1348            && reload_in_progress && GET_CODE (operand0) == SUBREG
1349            && GET_CODE (SUBREG_REG (operand0)) == REG
1350            && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1351     {
1352      /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1353         the code which tracks sets/uses for delete_output_reload.  */
1354       rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1355                                  reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1356                                  SUBREG_BYTE (operand0));
1357       operand0 = alter_subreg (&temp);
1358     }
1359
1360   if (scratch_reg
1361       && reload_in_progress && GET_CODE (operand1) == REG
1362       && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1363     operand1 = reg_equiv_mem[REGNO (operand1)];
1364   else if (scratch_reg
1365            && reload_in_progress && GET_CODE (operand1) == SUBREG
1366            && GET_CODE (SUBREG_REG (operand1)) == REG
1367            && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1368     {
1369      /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1370         the code which tracks sets/uses for delete_output_reload.  */
1371       rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1372                                  reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1373                                  SUBREG_BYTE (operand1));
1374       operand1 = alter_subreg (&temp);
1375     }
1376
1377   if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1378       && ((tem = find_replacement (&XEXP (operand0, 0)))
1379           != XEXP (operand0, 0)))
1380     operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
1381
1382   if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1383       && ((tem = find_replacement (&XEXP (operand1, 0)))
1384           != XEXP (operand1, 0)))
1385     operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
1386
1387   /* Handle secondary reloads for loads/stores of FP registers from
1388      REG+D addresses where D does not fit in 5 or 14 bits, including
1389      (subreg (mem (addr))) cases.  */
1390   if (scratch_reg
1391       && fp_reg_operand (operand0, mode)
1392       && ((GET_CODE (operand1) == MEM
1393            && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1394                                  XEXP (operand1, 0)))
1395           || ((GET_CODE (operand1) == SUBREG
1396                && GET_CODE (XEXP (operand1, 0)) == MEM
1397                && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1398                                       ? SFmode : DFmode),
1399                                      XEXP (XEXP (operand1, 0), 0))))))
1400     {
1401       if (GET_CODE (operand1) == SUBREG)
1402         operand1 = XEXP (operand1, 0);
1403
1404       /* SCRATCH_REG will hold an address and maybe the actual data.  We want
1405          it in WORD_MODE regardless of what mode it was originally given
1406          to us.  */
1407       scratch_reg = force_mode (word_mode, scratch_reg);
1408
1409       /* D might not fit in 14 bits either; for such cases load D into
1410          scratch reg.  */
1411       if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1412         {
1413           emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1414           emit_move_insn (scratch_reg,
1415                           gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1416                                           Pmode,
1417                                           XEXP (XEXP (operand1, 0), 0),
1418                                           scratch_reg));
1419         }
1420       else
1421         emit_move_insn (scratch_reg, XEXP (operand1, 0));
1422       emit_insn (gen_rtx_SET (VOIDmode, operand0,
1423                               gen_rtx_MEM (mode, scratch_reg)));
1424       return 1;
1425     }
1426   else if (scratch_reg
1427            && fp_reg_operand (operand1, mode)
1428            && ((GET_CODE (operand0) == MEM
1429                 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1430                                         ? SFmode : DFmode),
1431                                        XEXP (operand0, 0)))
1432                || ((GET_CODE (operand0) == SUBREG)
1433                    && GET_CODE (XEXP (operand0, 0)) == MEM
1434                    && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1435                                           ? SFmode : DFmode),
1436                                          XEXP (XEXP (operand0, 0), 0)))))
1437     {
1438       if (GET_CODE (operand0) == SUBREG)
1439         operand0 = XEXP (operand0, 0);
1440
1441       /* SCRATCH_REG will hold an address and maybe the actual data.  We want
1442          it in WORD_MODE regardless of what mode it was originally given
1443          to us.  */
1444       scratch_reg = force_mode (word_mode, scratch_reg);
1445
1446       /* D might not fit in 14 bits either; for such cases load D into
1447          scratch reg.  */
1448       if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1449         {
1450           emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1451           emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1452                                                                         0)),
1453                                                        Pmode,
1454                                                        XEXP (XEXP (operand0, 0),
1455                                                                    0),
1456                                                        scratch_reg));
1457         }
1458       else
1459         emit_move_insn (scratch_reg, XEXP (operand0, 0));
1460       emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
1461                               operand1));
1462       return 1;
1463     }
1464   /* Handle secondary reloads for loads of FP registers from constant
1465      expressions by forcing the constant into memory.
1466
1467      Use scratch_reg to hold the address of the memory location.
1468
1469      The proper fix is to change PREFERRED_RELOAD_CLASS to return
1470      NO_REGS when presented with a const_int and a register class
1471      containing only FP registers.  Doing so unfortunately creates
1472      more problems than it solves.   Fix this for 2.5.  */
1473   else if (scratch_reg
1474            && CONSTANT_P (operand1)
1475            && fp_reg_operand (operand0, mode))
1476     {
1477       rtx xoperands[2];
1478
1479       /* SCRATCH_REG will hold an address and maybe the actual data.  We want
1480          it in WORD_MODE regardless of what mode it was originally given
1481          to us.  */
1482       scratch_reg = force_mode (word_mode, scratch_reg);
1483
1484       /* Force the constant into memory and put the address of the
1485          memory location into scratch_reg.  */
1486       xoperands[0] = scratch_reg;
1487       xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
1488       emit_move_sequence (xoperands, Pmode, 0);
1489
1490       /* Now load the destination register.  */
1491       emit_insn (gen_rtx_SET (mode, operand0,
1492                               gen_rtx_MEM (mode, scratch_reg)));
1493       return 1;
1494     }
1495   /* Handle secondary reloads for SAR.  These occur when trying to load
1496      the SAR from memory, FP register, or with a constant.  */
1497   else if (scratch_reg
1498            && GET_CODE (operand0) == REG
1499            && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1500            && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1501            && (GET_CODE (operand1) == MEM
1502                || GET_CODE (operand1) == CONST_INT
1503                || (GET_CODE (operand1) == REG
1504                    && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1505     {
1506       /* D might not fit in 14 bits either; for such cases load D into
1507          scratch reg.  */
1508       if (GET_CODE (operand1) == MEM
1509           && !memory_address_p (Pmode, XEXP (operand1, 0)))
1510         {
1511           /* We are reloading the address into the scratch register, so we
1512              want to make sure the scratch register is a full register.  */
1513           scratch_reg = force_mode (word_mode, scratch_reg);
1514
1515           emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1516           emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1517                                                                         0)),
1518                                                        Pmode,
1519                                                        XEXP (XEXP (operand1, 0),
1520                                                        0),
1521                                                        scratch_reg));
1522
1523           /* Now we are going to load the scratch register from memory,
1524              we want to load it in the same width as the original MEM,
1525              which must be the same as the width of the ultimate destination,
1526              OPERAND0.  */
1527           scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1528
1529           emit_move_insn (scratch_reg, gen_rtx_MEM (GET_MODE (operand0),
1530                                                     scratch_reg));
1531         }
1532       else
1533         {
1534           /* We want to load the scratch register using the same mode as
1535              the ultimate destination.  */
1536           scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1537
1538           emit_move_insn (scratch_reg, operand1);
1539         }
1540
1541       /* And emit the insn to set the ultimate destination.  We know that
1542          the scratch register has the same mode as the destination at this
1543          point.  */
1544       emit_move_insn (operand0, scratch_reg);
1545       return 1;
1546     }
1547   /* Handle the most common case: storing into a register.  */
1548   else if (register_operand (operand0, mode))
1549     {
1550       if (register_operand (operand1, mode)
1551           || (GET_CODE (operand1) == CONST_INT
1552               && cint_ok_for_move (INTVAL (operand1)))
1553           || (operand1 == CONST0_RTX (mode))
1554           || (GET_CODE (operand1) == HIGH
1555               && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1556           /* Only `general_operands' can come here, so MEM is ok.  */
1557           || GET_CODE (operand1) == MEM)
1558         {
1559           /* Various sets are created during RTL generation which don't
1560              have the REG_POINTER flag correctly set.  After the CSE pass,
1561              instruction recognition can fail if we don't consistently
1562              set this flag when performing register copies.  This should
1563              also improve the opportunities for creating insns that use
1564              unscaled indexing.  */
1565           if (REG_P (operand0) && REG_P (operand1))
1566             {
1567               if (REG_POINTER (operand1)
1568                   && !REG_POINTER (operand0)
1569                   && !HARD_REGISTER_P (operand0))
1570                 copy_reg_pointer (operand0, operand1);
1571               else if (REG_POINTER (operand0)
1572                        && !REG_POINTER (operand1)
1573                        && !HARD_REGISTER_P (operand1))
1574                 copy_reg_pointer (operand1, operand0);
1575             }
1576           
1577           /* When MEMs are broken out, the REG_POINTER flag doesn't
1578              get set.  In some cases, we can set the REG_POINTER flag
1579              from the declaration for the MEM.  */
1580           if (REG_P (operand0)
1581               && GET_CODE (operand1) == MEM
1582               && !REG_POINTER (operand0))
1583             {
1584               tree decl = MEM_EXPR (operand1);
1585
1586               /* Set the register pointer flag and register alignment
1587                  if the declaration for this memory reference is a
1588                  pointer type.  Fortran indirect argument references
1589                  are ignored.  */
1590               if (decl
1591                   && !(flag_argument_noalias > 1
1592                        && TREE_CODE (decl) == INDIRECT_REF
1593                        && TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL))
1594                 {
1595                   tree type;
1596
1597                   /* If this is a COMPONENT_REF, use the FIELD_DECL from
1598                      tree operand 1.  */
1599                   if (TREE_CODE (decl) == COMPONENT_REF)
1600                     decl = TREE_OPERAND (decl, 1);
1601
1602                   type = TREE_TYPE (decl);
1603                   if (TREE_CODE (type) == ARRAY_TYPE)
1604                     type = get_inner_array_type (type);
1605
1606                   if (POINTER_TYPE_P (type))
1607                     {
1608                       int align;
1609
1610                       type = TREE_TYPE (type);
1611                       /* Using TYPE_ALIGN_OK is rather conservative as
1612                          only the ada frontend actually sets it.  */
1613                       align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1614                                : BITS_PER_UNIT);
1615                       mark_reg_pointer (operand0, align);
1616                     }
1617                 }
1618             }
1619
1620           emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1621           return 1;
1622         }
1623     }
1624   else if (GET_CODE (operand0) == MEM)
1625     {
1626       if (mode == DFmode && operand1 == CONST0_RTX (mode)
1627           && !(reload_in_progress || reload_completed))
1628         {
1629           rtx temp = gen_reg_rtx (DFmode);
1630
1631           emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1632           emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1633           return 1;
1634         }
1635       if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1636         {
1637           /* Run this case quickly.  */
1638           emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1639           return 1;
1640         }
1641       if (! (reload_in_progress || reload_completed))
1642         {
1643           operands[0] = validize_mem (operand0);
1644           operands[1] = operand1 = force_reg (mode, operand1);
1645         }
1646     }
1647
1648   /* Simplify the source if we need to.
1649      Note we do have to handle function labels here, even though we do
1650      not consider them legitimate constants.  Loop optimizations can
1651      call the emit_move_xxx with one as a source.  */
1652   if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1653       || function_label_operand (operand1, mode)
1654       || (GET_CODE (operand1) == HIGH
1655           && symbolic_operand (XEXP (operand1, 0), mode)))
1656     {
1657       int ishighonly = 0;
1658
1659       if (GET_CODE (operand1) == HIGH)
1660         {
1661           ishighonly = 1;
1662           operand1 = XEXP (operand1, 0);
1663         }
1664       if (symbolic_operand (operand1, mode))
1665         {
1666           /* Argh.  The assembler and linker can't handle arithmetic
1667              involving plabels.
1668
1669              So we force the plabel into memory, load operand0 from
1670              the memory location, then add in the constant part.  */
1671           if ((GET_CODE (operand1) == CONST
1672                && GET_CODE (XEXP (operand1, 0)) == PLUS
1673                && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
1674               || function_label_operand (operand1, mode))
1675             {
1676               rtx temp, const_part;
1677
1678               /* Figure out what (if any) scratch register to use.  */
1679               if (reload_in_progress || reload_completed)
1680                 {
1681                   scratch_reg = scratch_reg ? scratch_reg : operand0;
1682                   /* SCRATCH_REG will hold an address and maybe the actual
1683                      data.  We want it in WORD_MODE regardless of what mode it
1684                      was originally given to us.  */
1685                   scratch_reg = force_mode (word_mode, scratch_reg);
1686                 }
1687               else if (flag_pic)
1688                 scratch_reg = gen_reg_rtx (Pmode);
1689
1690               if (GET_CODE (operand1) == CONST)
1691                 {
1692                   /* Save away the constant part of the expression.  */
1693                   const_part = XEXP (XEXP (operand1, 0), 1);
1694                   gcc_assert (GET_CODE (const_part) == CONST_INT);
1695
1696                   /* Force the function label into memory.  */
1697                   temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
1698                 }
1699               else
1700                 {
1701                   /* No constant part.  */
1702                   const_part = NULL_RTX;
1703
1704                   /* Force the function label into memory.  */
1705                   temp = force_const_mem (mode, operand1);
1706                 }
1707
1708
1709               /* Get the address of the memory location.  PIC-ify it if
1710                  necessary.  */
1711               temp = XEXP (temp, 0);
1712               if (flag_pic)
1713                 temp = legitimize_pic_address (temp, mode, scratch_reg);
1714
1715               /* Put the address of the memory location into our destination
1716                  register.  */
1717               operands[1] = temp;
1718               emit_move_sequence (operands, mode, scratch_reg);
1719
1720               /* Now load from the memory location into our destination
1721                  register.  */
1722               operands[1] = gen_rtx_MEM (Pmode, operands[0]);
1723               emit_move_sequence (operands, mode, scratch_reg);
1724
1725               /* And add back in the constant part.  */
1726               if (const_part != NULL_RTX)
1727                 expand_inc (operand0, const_part);
1728
1729               return 1;
1730             }
1731
1732           if (flag_pic)
1733             {
1734               rtx temp;
1735
1736               if (reload_in_progress || reload_completed)
1737                 {
1738                   temp = scratch_reg ? scratch_reg : operand0;
1739                   /* TEMP will hold an address and maybe the actual
1740                      data.  We want it in WORD_MODE regardless of what mode it
1741                      was originally given to us.  */
1742                   temp = force_mode (word_mode, temp);
1743                 }
1744               else
1745                 temp = gen_reg_rtx (Pmode);
1746
1747               /* (const (plus (symbol) (const_int))) must be forced to
1748                  memory during/after reload if the const_int will not fit
1749                  in 14 bits.  */
1750               if (GET_CODE (operand1) == CONST
1751                        && GET_CODE (XEXP (operand1, 0)) == PLUS
1752                        && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
1753                        && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
1754                        && (reload_completed || reload_in_progress)
1755                        && flag_pic)
1756                 {
1757                   operands[1] = force_const_mem (mode, operand1);
1758                   operands[1] = legitimize_pic_address (XEXP (operands[1], 0),
1759                                                         mode, temp);
1760                   operands[1] = gen_rtx_MEM (mode, operands[1]);
1761                   emit_move_sequence (operands, mode, temp);
1762                 }
1763               else
1764                 {
1765                   operands[1] = legitimize_pic_address (operand1, mode, temp);
1766                   if (REG_P (operand0) && REG_P (operands[1]))
1767                     copy_reg_pointer (operand0, operands[1]);
1768                   emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
1769                 }
1770             }
1771           /* On the HPPA, references to data space are supposed to use dp,
1772              register 27, but showing it in the RTL inhibits various cse
1773              and loop optimizations.  */
1774           else
1775             {
1776               rtx temp, set;
1777
1778               if (reload_in_progress || reload_completed)
1779                 {
1780                   temp = scratch_reg ? scratch_reg : operand0;
1781                   /* TEMP will hold an address and maybe the actual
1782                      data.  We want it in WORD_MODE regardless of what mode it
1783                      was originally given to us.  */
1784                   temp = force_mode (word_mode, temp);
1785                 }
1786               else
1787                 temp = gen_reg_rtx (mode);
1788
1789               /* Loading a SYMBOL_REF into a register makes that register
1790                  safe to be used as the base in an indexed address.
1791
1792                  Don't mark hard registers though.  That loses.  */
1793               if (GET_CODE (operand0) == REG
1794                   && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1795                 mark_reg_pointer (operand0, BITS_PER_UNIT);
1796               if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
1797                 mark_reg_pointer (temp, BITS_PER_UNIT);
1798
1799               if (ishighonly)
1800                 set = gen_rtx_SET (mode, operand0, temp);
1801               else
1802                 set = gen_rtx_SET (VOIDmode,
1803                                    operand0,
1804                                    gen_rtx_LO_SUM (mode, temp, operand1));
1805
1806               emit_insn (gen_rtx_SET (VOIDmode,
1807                                       temp,
1808                                       gen_rtx_HIGH (mode, operand1)));
1809               emit_insn (set);
1810
1811             }
1812           return 1;
1813         }
1814       else if (pa_tls_referenced_p (operand1))
1815         {
1816           rtx tmp = operand1;
1817           rtx addend = NULL;
1818
1819           if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
1820             {
1821               addend = XEXP (XEXP (tmp, 0), 1);
1822               tmp = XEXP (XEXP (tmp, 0), 0);
1823             }
1824
1825           gcc_assert (GET_CODE (tmp) == SYMBOL_REF);
1826           tmp = legitimize_tls_address (tmp);
1827           if (addend)
1828             {
1829               tmp = gen_rtx_PLUS (mode, tmp, addend);
1830               tmp = force_operand (tmp, operands[0]);
1831             }
1832           operands[1] = tmp;
1833         }
1834       else if (GET_CODE (operand1) != CONST_INT
1835                || !cint_ok_for_move (INTVAL (operand1)))
1836         {
1837           rtx insn, temp;
1838           rtx op1 = operand1;
1839           HOST_WIDE_INT value = 0;
1840           HOST_WIDE_INT insv = 0;
1841           int insert = 0;
1842
1843           if (GET_CODE (operand1) == CONST_INT)
1844             value = INTVAL (operand1);
1845
1846           if (TARGET_64BIT
1847               && GET_CODE (operand1) == CONST_INT
1848               && HOST_BITS_PER_WIDE_INT > 32
1849               && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
1850             {
1851               HOST_WIDE_INT nval;
1852
1853               /* Extract the low order 32 bits of the value and sign extend.
1854                  If the new value is the same as the original value, we can
1855                  can use the original value as-is.  If the new value is
1856                  different, we use it and insert the most-significant 32-bits
1857                  of the original value into the final result.  */
1858               nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
1859                       ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
1860               if (value != nval)
1861                 {
1862 #if HOST_BITS_PER_WIDE_INT > 32
1863                   insv = value >= 0 ? value >> 32 : ~(~value >> 32);
1864 #endif
1865                   insert = 1;
1866                   value = nval;
1867                   operand1 = GEN_INT (nval);
1868                 }
1869             }
1870
1871           if (reload_in_progress || reload_completed)
1872             temp = scratch_reg ? scratch_reg : operand0;
1873           else
1874             temp = gen_reg_rtx (mode);
1875
1876           /* We don't directly split DImode constants on 32-bit targets
1877              because PLUS uses an 11-bit immediate and the insn sequence
1878              generated is not as efficient as the one using HIGH/LO_SUM.  */
1879           if (GET_CODE (operand1) == CONST_INT
1880               && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1881               && !insert)
1882             {
1883               /* Directly break constant into high and low parts.  This
1884                  provides better optimization opportunities because various
1885                  passes recognize constants split with PLUS but not LO_SUM.
1886                  We use a 14-bit signed low part except when the addition
1887                  of 0x4000 to the high part might change the sign of the
1888                  high part.  */
1889               HOST_WIDE_INT low = value & 0x3fff;
1890               HOST_WIDE_INT high = value & ~ 0x3fff;
1891
1892               if (low >= 0x2000)
1893                 {
1894                   if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
1895                     high += 0x2000;
1896                   else
1897                     high += 0x4000;
1898                 }
1899
1900               low = value - high;
1901
1902               emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
1903               operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
1904             }
1905           else
1906             {
1907               emit_insn (gen_rtx_SET (VOIDmode, temp,
1908                                       gen_rtx_HIGH (mode, operand1)));
1909               operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
1910             }
1911
1912           insn = emit_move_insn (operands[0], operands[1]);
1913
1914           /* Now insert the most significant 32 bits of the value
1915              into the register.  When we don't have a second register
1916              available, it could take up to nine instructions to load
1917              a 64-bit integer constant.  Prior to reload, we force
1918              constants that would take more than three instructions
1919              to load to the constant pool.  During and after reload,
1920              we have to handle all possible values.  */
1921           if (insert)
1922             {
1923               /* Use a HIGH/LO_SUM/INSV sequence if we have a second
1924                  register and the value to be inserted is outside the
1925                  range that can be loaded with three depdi instructions.  */
1926               if (temp != operand0 && (insv >= 16384 || insv < -16384))
1927                 {
1928                   operand1 = GEN_INT (insv);
1929
1930                   emit_insn (gen_rtx_SET (VOIDmode, temp,
1931                                           gen_rtx_HIGH (mode, operand1)));
1932                   emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
1933                   emit_insn (gen_insv (operand0, GEN_INT (32),
1934                                        const0_rtx, temp));
1935                 }
1936               else
1937                 {
1938                   int len = 5, pos = 27;
1939
1940                   /* Insert the bits using the depdi instruction.  */
1941                   while (pos >= 0)
1942                     {
1943                       HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
1944                       HOST_WIDE_INT sign = v5 < 0;
1945
1946                       /* Left extend the insertion.  */
1947                       insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
1948                       while (pos > 0 && (insv & 1) == sign)
1949                         {
1950                           insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
1951                           len += 1;
1952                           pos -= 1;
1953                         }
1954
1955                       emit_insn (gen_insv (operand0, GEN_INT (len),
1956                                            GEN_INT (pos), GEN_INT (v5)));
1957
1958                       len = pos > 0 && pos < 5 ? pos : 5;
1959                       pos -= len;
1960                     }
1961                 }
1962             }
1963
1964           REG_NOTES (insn)
1965             = gen_rtx_EXPR_LIST (REG_EQUAL, op1, REG_NOTES (insn));
1966
1967           return 1;
1968         }
1969     }
1970   /* Now have insn-emit do whatever it normally does.  */
1971   return 0;
1972 }
1973
1974 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
1975    it will need a link/runtime reloc).  */
1976
1977 int
1978 reloc_needed (tree exp)
1979 {
1980   int reloc = 0;
1981
1982   switch (TREE_CODE (exp))
1983     {
1984     case ADDR_EXPR:
1985       return 1;
1986
1987     case PLUS_EXPR:
1988     case MINUS_EXPR:
1989       reloc = reloc_needed (TREE_OPERAND (exp, 0));
1990       reloc |= reloc_needed (TREE_OPERAND (exp, 1));
1991       break;
1992
1993     case NOP_EXPR:
1994     case CONVERT_EXPR:
1995     case NON_LVALUE_EXPR:
1996       reloc = reloc_needed (TREE_OPERAND (exp, 0));
1997       break;
1998
1999     case CONSTRUCTOR:
2000       {
2001         register tree link;
2002         for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2003           if (TREE_VALUE (link) != 0)
2004             reloc |= reloc_needed (TREE_VALUE (link));
2005       }
2006       break;
2007
2008     case ERROR_MARK:
2009       break;
2010
2011     default:
2012       break;
2013     }
2014   return reloc;
2015 }
2016
2017 /* Does operand (which is a symbolic_operand) live in text space?
2018    If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2019    will be true.  */
2020
2021 int
2022 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2023 {
2024   if (GET_CODE (operand) == CONST)
2025     operand = XEXP (XEXP (operand, 0), 0);
2026   if (flag_pic)
2027     {
2028       if (GET_CODE (operand) == SYMBOL_REF)
2029         return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2030     }
2031   else
2032     {
2033       if (GET_CODE (operand) == SYMBOL_REF)
2034         return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2035     }
2036   return 1;
2037 }
2038
2039 \f
2040 /* Return the best assembler insn template
2041    for moving operands[1] into operands[0] as a fullword.  */
2042 const char *
2043 singlemove_string (rtx *operands)
2044 {
2045   HOST_WIDE_INT intval;
2046
2047   if (GET_CODE (operands[0]) == MEM)
2048     return "stw %r1,%0";
2049   if (GET_CODE (operands[1]) == MEM)
2050     return "ldw %1,%0";
2051   if (GET_CODE (operands[1]) == CONST_DOUBLE)
2052     {
2053       long i;
2054       REAL_VALUE_TYPE d;
2055
2056       gcc_assert (GET_MODE (operands[1]) == SFmode);
2057
2058       /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2059          bit pattern.  */
2060       REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2061       REAL_VALUE_TO_TARGET_SINGLE (d, i);
2062
2063       operands[1] = GEN_INT (i);
2064       /* Fall through to CONST_INT case.  */
2065     }
2066   if (GET_CODE (operands[1]) == CONST_INT)
2067     {
2068       intval = INTVAL (operands[1]);
2069
2070       if (VAL_14_BITS_P (intval))
2071         return "ldi %1,%0";
2072       else if ((intval & 0x7ff) == 0)
2073         return "ldil L'%1,%0";
2074       else if (zdepi_cint_p (intval))
2075         return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2076       else
2077         return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2078     }
2079   return "copy %1,%0";
2080 }
2081 \f
2082
2083 /* Compute position (in OP[1]) and width (in OP[2])
2084    useful for copying IMM to a register using the zdepi
2085    instructions.  Store the immediate value to insert in OP[0].  */
2086 static void
2087 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2088 {
2089   int lsb, len;
2090
2091   /* Find the least significant set bit in IMM.  */
2092   for (lsb = 0; lsb < 32; lsb++)
2093     {
2094       if ((imm & 1) != 0)
2095         break;
2096       imm >>= 1;
2097     }
2098
2099   /* Choose variants based on *sign* of the 5-bit field.  */
2100   if ((imm & 0x10) == 0)
2101     len = (lsb <= 28) ? 4 : 32 - lsb;
2102   else
2103     {
2104       /* Find the width of the bitstring in IMM.  */
2105       for (len = 5; len < 32; len++)
2106         {
2107           if ((imm & (1 << len)) == 0)
2108             break;
2109         }
2110
2111       /* Sign extend IMM as a 5-bit value.  */
2112       imm = (imm & 0xf) - 0x10;
2113     }
2114
2115   op[0] = imm;
2116   op[1] = 31 - lsb;
2117   op[2] = len;
2118 }
2119
2120 /* Compute position (in OP[1]) and width (in OP[2])
2121    useful for copying IMM to a register using the depdi,z
2122    instructions.  Store the immediate value to insert in OP[0].  */
2123 void
2124 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2125 {
2126   HOST_WIDE_INT lsb, len;
2127
2128   /* Find the least significant set bit in IMM.  */
2129   for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
2130     {
2131       if ((imm & 1) != 0)
2132         break;
2133       imm >>= 1;
2134     }
2135
2136   /* Choose variants based on *sign* of the 5-bit field.  */
2137   if ((imm & 0x10) == 0)
2138     len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
2139            ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
2140   else
2141     {
2142       /* Find the width of the bitstring in IMM.  */
2143       for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
2144         {
2145           if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2146             break;
2147         }
2148
2149       /* Sign extend IMM as a 5-bit value.  */
2150       imm = (imm & 0xf) - 0x10;
2151     }
2152
2153   op[0] = imm;
2154   op[1] = 63 - lsb;
2155   op[2] = len;
2156 }
2157
2158 /* Output assembler code to perform a doubleword move insn
2159    with operands OPERANDS.  */
2160
2161 const char *
2162 output_move_double (rtx *operands)
2163 {
2164   enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2165   rtx latehalf[2];
2166   rtx addreg0 = 0, addreg1 = 0;
2167
2168   /* First classify both operands.  */
2169
2170   if (REG_P (operands[0]))
2171     optype0 = REGOP;
2172   else if (offsettable_memref_p (operands[0]))
2173     optype0 = OFFSOP;
2174   else if (GET_CODE (operands[0]) == MEM)
2175     optype0 = MEMOP;
2176   else
2177     optype0 = RNDOP;
2178
2179   if (REG_P (operands[1]))
2180     optype1 = REGOP;
2181   else if (CONSTANT_P (operands[1]))
2182     optype1 = CNSTOP;
2183   else if (offsettable_memref_p (operands[1]))
2184     optype1 = OFFSOP;
2185   else if (GET_CODE (operands[1]) == MEM)
2186     optype1 = MEMOP;
2187   else
2188     optype1 = RNDOP;
2189
2190   /* Check for the cases that the operand constraints are not
2191      supposed to allow to happen.  */
2192   gcc_assert (optype0 == REGOP || optype1 == REGOP);
2193
2194    /* Handle auto decrementing and incrementing loads and stores
2195      specifically, since the structure of the function doesn't work
2196      for them without major modification.  Do it better when we learn
2197      this port about the general inc/dec addressing of PA.
2198      (This was written by tege.  Chide him if it doesn't work.)  */
2199
2200   if (optype0 == MEMOP)
2201     {
2202       /* We have to output the address syntax ourselves, since print_operand
2203          doesn't deal with the addresses we want to use.  Fix this later.  */
2204
2205       rtx addr = XEXP (operands[0], 0);
2206       if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2207         {
2208           rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2209
2210           operands[0] = XEXP (addr, 0);
2211           gcc_assert (GET_CODE (operands[1]) == REG
2212                       && GET_CODE (operands[0]) == REG);
2213
2214           gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2215           
2216           /* No overlap between high target register and address
2217              register.  (We do this in a non-obvious way to
2218              save a register file writeback)  */
2219           if (GET_CODE (addr) == POST_INC)
2220             return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2221           return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2222         }
2223       else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2224         {
2225           rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2226
2227           operands[0] = XEXP (addr, 0);
2228           gcc_assert (GET_CODE (operands[1]) == REG
2229                       && GET_CODE (operands[0]) == REG);
2230           
2231           gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2232           /* No overlap between high target register and address
2233              register.  (We do this in a non-obvious way to save a
2234              register file writeback)  */
2235           if (GET_CODE (addr) == PRE_INC)
2236             return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2237           return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2238         }
2239     }
2240   if (optype1 == MEMOP)
2241     {
2242       /* We have to output the address syntax ourselves, since print_operand
2243          doesn't deal with the addresses we want to use.  Fix this later.  */
2244
2245       rtx addr = XEXP (operands[1], 0);
2246       if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2247         {
2248           rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2249
2250           operands[1] = XEXP (addr, 0);
2251           gcc_assert (GET_CODE (operands[0]) == REG
2252                       && GET_CODE (operands[1]) == REG);
2253
2254           if (!reg_overlap_mentioned_p (high_reg, addr))
2255             {
2256               /* No overlap between high target register and address
2257                  register.  (We do this in a non-obvious way to
2258                  save a register file writeback)  */
2259               if (GET_CODE (addr) == POST_INC)
2260                 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2261               return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2262             }
2263           else
2264             {
2265               /* This is an undefined situation.  We should load into the
2266                  address register *and* update that register.  Probably
2267                  we don't need to handle this at all.  */
2268               if (GET_CODE (addr) == POST_INC)
2269                 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2270               return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2271             }
2272         }
2273       else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2274         {
2275           rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2276
2277           operands[1] = XEXP (addr, 0);
2278           gcc_assert (GET_CODE (operands[0]) == REG
2279                       && GET_CODE (operands[1]) == REG);
2280
2281           if (!reg_overlap_mentioned_p (high_reg, addr))
2282             {
2283               /* No overlap between high target register and address
2284                  register.  (We do this in a non-obvious way to
2285                  save a register file writeback)  */
2286               if (GET_CODE (addr) == PRE_INC)
2287                 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2288               return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2289             }
2290           else
2291             {
2292               /* This is an undefined situation.  We should load into the
2293                  address register *and* update that register.  Probably
2294                  we don't need to handle this at all.  */
2295               if (GET_CODE (addr) == PRE_INC)
2296                 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2297               return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2298             }
2299         }
2300       else if (GET_CODE (addr) == PLUS
2301                && GET_CODE (XEXP (addr, 0)) == MULT)
2302         {
2303           rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2304
2305           if (!reg_overlap_mentioned_p (high_reg, addr))
2306             {
2307               rtx xoperands[3];
2308
2309               xoperands[0] = high_reg;
2310               xoperands[1] = XEXP (addr, 1);
2311               xoperands[2] = XEXP (XEXP (addr, 0), 0);
2312               xoperands[3] = XEXP (XEXP (addr, 0), 1);
2313               output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2314                                xoperands);
2315               return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2316             }
2317           else
2318             {
2319               rtx xoperands[3];
2320
2321               xoperands[0] = high_reg;
2322               xoperands[1] = XEXP (addr, 1);
2323               xoperands[2] = XEXP (XEXP (addr, 0), 0);
2324               xoperands[3] = XEXP (XEXP (addr, 0), 1);
2325               output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2326                                xoperands);
2327               return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2328             }
2329         }
2330     }
2331
2332   /* If an operand is an unoffsettable memory ref, find a register
2333      we can increment temporarily to make it refer to the second word.  */
2334
2335   if (optype0 == MEMOP)
2336     addreg0 = find_addr_reg (XEXP (operands[0], 0));
2337
2338   if (optype1 == MEMOP)
2339     addreg1 = find_addr_reg (XEXP (operands[1], 0));
2340
2341   /* Ok, we can do one word at a time.
2342      Normally we do the low-numbered word first.
2343
2344      In either case, set up in LATEHALF the operands to use
2345      for the high-numbered word and in some cases alter the
2346      operands in OPERANDS to be suitable for the low-numbered word.  */
2347
2348   if (optype0 == REGOP)
2349     latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2350   else if (optype0 == OFFSOP)
2351     latehalf[0] = adjust_address (operands[0], SImode, 4);
2352   else
2353     latehalf[0] = operands[0];
2354
2355   if (optype1 == REGOP)
2356     latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2357   else if (optype1 == OFFSOP)
2358     latehalf[1] = adjust_address (operands[1], SImode, 4);
2359   else if (optype1 == CNSTOP)
2360     split_double (operands[1], &operands[1], &latehalf[1]);
2361   else
2362     latehalf[1] = operands[1];
2363
2364   /* If the first move would clobber the source of the second one,
2365      do them in the other order.
2366
2367      This can happen in two cases:
2368
2369         mem -> register where the first half of the destination register
2370         is the same register used in the memory's address.  Reload
2371         can create such insns.
2372
2373         mem in this case will be either register indirect or register
2374         indirect plus a valid offset.
2375
2376         register -> register move where REGNO(dst) == REGNO(src + 1)
2377         someone (Tim/Tege?) claimed this can happen for parameter loads.
2378
2379      Handle mem -> register case first.  */
2380   if (optype0 == REGOP
2381       && (optype1 == MEMOP || optype1 == OFFSOP)
2382       && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2383                             operands[1], 0))
2384     {
2385       /* Do the late half first.  */
2386       if (addreg1)
2387         output_asm_insn ("ldo 4(%0),%0", &addreg1);
2388       output_asm_insn (singlemove_string (latehalf), latehalf);
2389
2390       /* Then clobber.  */
2391       if (addreg1)
2392         output_asm_insn ("ldo -4(%0),%0", &addreg1);
2393       return singlemove_string (operands);
2394     }
2395
2396   /* Now handle register -> register case.  */
2397   if (optype0 == REGOP && optype1 == REGOP
2398       && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2399     {
2400       output_asm_insn (singlemove_string (latehalf), latehalf);
2401       return singlemove_string (operands);
2402     }
2403
2404   /* Normal case: do the two words, low-numbered first.  */
2405
2406   output_asm_insn (singlemove_string (operands), operands);
2407
2408   /* Make any unoffsettable addresses point at high-numbered word.  */
2409   if (addreg0)
2410     output_asm_insn ("ldo 4(%0),%0", &addreg0);
2411   if (addreg1)
2412     output_asm_insn ("ldo 4(%0),%0", &addreg1);
2413
2414   /* Do that word.  */
2415   output_asm_insn (singlemove_string (latehalf), latehalf);
2416
2417   /* Undo the adds we just did.  */
2418   if (addreg0)
2419     output_asm_insn ("ldo -4(%0),%0", &addreg0);
2420   if (addreg1)
2421     output_asm_insn ("ldo -4(%0),%0", &addreg1);
2422
2423   return "";
2424 }
2425 \f
2426 const char *
2427 output_fp_move_double (rtx *operands)
2428 {
2429   if (FP_REG_P (operands[0]))
2430     {
2431       if (FP_REG_P (operands[1])
2432           || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2433         output_asm_insn ("fcpy,dbl %f1,%0", operands);
2434       else
2435         output_asm_insn ("fldd%F1 %1,%0", operands);
2436     }
2437   else if (FP_REG_P (operands[1]))
2438     {
2439       output_asm_insn ("fstd%F0 %1,%0", operands);
2440     }
2441   else
2442     {
2443       rtx xoperands[2];
2444       
2445       gcc_assert (operands[1] == CONST0_RTX (GET_MODE (operands[0])));
2446       
2447       /* This is a pain.  You have to be prepared to deal with an
2448          arbitrary address here including pre/post increment/decrement.
2449
2450          so avoid this in the MD.  */
2451       gcc_assert (GET_CODE (operands[0]) == REG);
2452       
2453       xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2454       xoperands[0] = operands[0];
2455       output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2456     }
2457   return "";
2458 }
2459 \f
2460 /* Return a REG that occurs in ADDR with coefficient 1.
2461    ADDR can be effectively incremented by incrementing REG.  */
2462
2463 static rtx
2464 find_addr_reg (rtx addr)
2465 {
2466   while (GET_CODE (addr) == PLUS)
2467     {
2468       if (GET_CODE (XEXP (addr, 0)) == REG)
2469         addr = XEXP (addr, 0);
2470       else if (GET_CODE (XEXP (addr, 1)) == REG)
2471         addr = XEXP (addr, 1);
2472       else if (CONSTANT_P (XEXP (addr, 0)))
2473         addr = XEXP (addr, 1);
2474       else if (CONSTANT_P (XEXP (addr, 1)))
2475         addr = XEXP (addr, 0);
2476       else
2477         gcc_unreachable ();
2478     }
2479   gcc_assert (GET_CODE (addr) == REG);
2480   return addr;
2481 }
2482
2483 /* Emit code to perform a block move.
2484
2485    OPERANDS[0] is the destination pointer as a REG, clobbered.
2486    OPERANDS[1] is the source pointer as a REG, clobbered.
2487    OPERANDS[2] is a register for temporary storage.
2488    OPERANDS[3] is a register for temporary storage.
2489    OPERANDS[4] is the size as a CONST_INT
2490    OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2491    OPERANDS[6] is another temporary register.  */
2492
2493 const char *
2494 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2495 {
2496   int align = INTVAL (operands[5]);
2497   unsigned long n_bytes = INTVAL (operands[4]);
2498
2499   /* We can't move more than a word at a time because the PA
2500      has no longer integer move insns.  (Could use fp mem ops?)  */
2501   if (align > (TARGET_64BIT ? 8 : 4))
2502     align = (TARGET_64BIT ? 8 : 4);
2503
2504   /* Note that we know each loop below will execute at least twice
2505      (else we would have open-coded the copy).  */
2506   switch (align)
2507     {
2508       case 8:
2509         /* Pre-adjust the loop counter.  */
2510         operands[4] = GEN_INT (n_bytes - 16);
2511         output_asm_insn ("ldi %4,%2", operands);
2512
2513         /* Copying loop.  */
2514         output_asm_insn ("ldd,ma 8(%1),%3", operands);
2515         output_asm_insn ("ldd,ma 8(%1),%6", operands);
2516         output_asm_insn ("std,ma %3,8(%0)", operands);
2517         output_asm_insn ("addib,>= -16,%2,.-12", operands);
2518         output_asm_insn ("std,ma %6,8(%0)", operands);
2519
2520         /* Handle the residual.  There could be up to 7 bytes of
2521            residual to copy!  */
2522         if (n_bytes % 16 != 0)
2523           {
2524             operands[4] = GEN_INT (n_bytes % 8);
2525             if (n_bytes % 16 >= 8)
2526               output_asm_insn ("ldd,ma 8(%1),%3", operands);
2527             if (n_bytes % 8 != 0)
2528               output_asm_insn ("ldd 0(%1),%6", operands);
2529             if (n_bytes % 16 >= 8)
2530               output_asm_insn ("std,ma %3,8(%0)", operands);
2531             if (n_bytes % 8 != 0)
2532               output_asm_insn ("stdby,e %6,%4(%0)", operands);
2533           }
2534         return "";
2535
2536       case 4:
2537         /* Pre-adjust the loop counter.  */
2538         operands[4] = GEN_INT (n_bytes - 8);
2539         output_asm_insn ("ldi %4,%2", operands);
2540
2541         /* Copying loop.  */
2542         output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2543         output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2544         output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2545         output_asm_insn ("addib,>= -8,%2,.-12", operands);
2546         output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2547
2548         /* Handle the residual.  There could be up to 7 bytes of
2549            residual to copy!  */
2550         if (n_bytes % 8 != 0)
2551           {
2552             operands[4] = GEN_INT (n_bytes % 4);
2553             if (n_bytes % 8 >= 4)
2554               output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2555             if (n_bytes % 4 != 0)
2556               output_asm_insn ("ldw 0(%1),%6", operands);
2557             if (n_bytes % 8 >= 4)
2558               output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2559             if (n_bytes % 4 != 0)
2560               output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2561           }
2562         return "";
2563
2564       case 2:
2565         /* Pre-adjust the loop counter.  */
2566         operands[4] = GEN_INT (n_bytes - 4);
2567         output_asm_insn ("ldi %4,%2", operands);
2568
2569         /* Copying loop.  */
2570         output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2571         output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2572         output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2573         output_asm_insn ("addib,>= -4,%2,.-12", operands);
2574         output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2575
2576         /* Handle the residual.  */
2577         if (n_bytes % 4 != 0)
2578           {
2579             if (n_bytes % 4 >= 2)
2580               output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2581             if (n_bytes % 2 != 0)
2582               output_asm_insn ("ldb 0(%1),%6", operands);
2583             if (n_bytes % 4 >= 2)
2584               output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2585             if (n_bytes % 2 != 0)
2586               output_asm_insn ("stb %6,0(%0)", operands);
2587           }
2588         return "";
2589
2590       case 1:
2591         /* Pre-adjust the loop counter.  */
2592         operands[4] = GEN_INT (n_bytes - 2);
2593         output_asm_insn ("ldi %4,%2", operands);
2594
2595         /* Copying loop.  */
2596         output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2597         output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2598         output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2599         output_asm_insn ("addib,>= -2,%2,.-12", operands);
2600         output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2601
2602         /* Handle the residual.  */
2603         if (n_bytes % 2 != 0)
2604           {
2605             output_asm_insn ("ldb 0(%1),%3", operands);
2606             output_asm_insn ("stb %3,0(%0)", operands);
2607           }
2608         return "";
2609
2610       default:
2611         gcc_unreachable ();
2612     }
2613 }
2614
2615 /* Count the number of insns necessary to handle this block move.
2616
2617    Basic structure is the same as emit_block_move, except that we
2618    count insns rather than emit them.  */
2619
2620 static int
2621 compute_movmem_length (rtx insn)
2622 {
2623   rtx pat = PATTERN (insn);
2624   unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2625   unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2626   unsigned int n_insns = 0;
2627
2628   /* We can't move more than four bytes at a time because the PA
2629      has no longer integer move insns.  (Could use fp mem ops?)  */
2630   if (align > (TARGET_64BIT ? 8 : 4))
2631     align = (TARGET_64BIT ? 8 : 4);
2632
2633   /* The basic copying loop.  */
2634   n_insns = 6;
2635
2636   /* Residuals.  */
2637   if (n_bytes % (2 * align) != 0)
2638     {
2639       if ((n_bytes % (2 * align)) >= align)
2640         n_insns += 2;
2641
2642       if ((n_bytes % align) != 0)
2643         n_insns += 2;
2644     }
2645
2646   /* Lengths are expressed in bytes now; each insn is 4 bytes.  */
2647   return n_insns * 4;
2648 }
2649
2650 /* Emit code to perform a block clear.
2651
2652    OPERANDS[0] is the destination pointer as a REG, clobbered.
2653    OPERANDS[1] is a register for temporary storage.
2654    OPERANDS[2] is the size as a CONST_INT
2655    OPERANDS[3] is the alignment safe to use, as a CONST_INT.  */
2656
2657 const char *
2658 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2659 {
2660   int align = INTVAL (operands[3]);
2661   unsigned long n_bytes = INTVAL (operands[2]);
2662
2663   /* We can't clear more than a word at a time because the PA
2664      has no longer integer move insns.  */
2665   if (align > (TARGET_64BIT ? 8 : 4))
2666     align = (TARGET_64BIT ? 8 : 4);
2667
2668   /* Note that we know each loop below will execute at least twice
2669      (else we would have open-coded the copy).  */
2670   switch (align)
2671     {
2672       case 8:
2673         /* Pre-adjust the loop counter.  */
2674         operands[2] = GEN_INT (n_bytes - 16);
2675         output_asm_insn ("ldi %2,%1", operands);
2676
2677         /* Loop.  */
2678         output_asm_insn ("std,ma %%r0,8(%0)", operands);
2679         output_asm_insn ("addib,>= -16,%1,.-4", operands);
2680         output_asm_insn ("std,ma %%r0,8(%0)", operands);
2681
2682         /* Handle the residual.  There could be up to 7 bytes of
2683            residual to copy!  */
2684         if (n_bytes % 16 != 0)
2685           {
2686             operands[2] = GEN_INT (n_bytes % 8);
2687             if (n_bytes % 16 >= 8)
2688               output_asm_insn ("std,ma %%r0,8(%0)", operands);
2689             if (n_bytes % 8 != 0)
2690               output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
2691           }
2692         return "";
2693
2694       case 4:
2695         /* Pre-adjust the loop counter.  */
2696         operands[2] = GEN_INT (n_bytes - 8);
2697         output_asm_insn ("ldi %2,%1", operands);
2698
2699         /* Loop.  */
2700         output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2701         output_asm_insn ("addib,>= -8,%1,.-4", operands);
2702         output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2703
2704         /* Handle the residual.  There could be up to 7 bytes of
2705            residual to copy!  */
2706         if (n_bytes % 8 != 0)
2707           {
2708             operands[2] = GEN_INT (n_bytes % 4);
2709             if (n_bytes % 8 >= 4)
2710               output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2711             if (n_bytes % 4 != 0)
2712               output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
2713           }
2714         return "";
2715
2716       case 2:
2717         /* Pre-adjust the loop counter.  */
2718         operands[2] = GEN_INT (n_bytes - 4);
2719         output_asm_insn ("ldi %2,%1", operands);
2720
2721         /* Loop.  */
2722         output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2723         output_asm_insn ("addib,>= -4,%1,.-4", operands);
2724         output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2725
2726         /* Handle the residual.  */
2727         if (n_bytes % 4 != 0)
2728           {
2729             if (n_bytes % 4 >= 2)
2730               output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2731             if (n_bytes % 2 != 0)
2732               output_asm_insn ("stb %%r0,0(%0)", operands);
2733           }
2734         return "";
2735
2736       case 1:
2737         /* Pre-adjust the loop counter.  */
2738         operands[2] = GEN_INT (n_bytes - 2);
2739         output_asm_insn ("ldi %2,%1", operands);
2740
2741         /* Loop.  */
2742         output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2743         output_asm_insn ("addib,>= -2,%1,.-4", operands);
2744         output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2745
2746         /* Handle the residual.  */
2747         if (n_bytes % 2 != 0)
2748           output_asm_insn ("stb %%r0,0(%0)", operands);
2749
2750         return "";
2751
2752       default:
2753         gcc_unreachable ();
2754     }
2755 }
2756
2757 /* Count the number of insns necessary to handle this block move.
2758
2759    Basic structure is the same as emit_block_move, except that we
2760    count insns rather than emit them.  */
2761
2762 static int
2763 compute_clrmem_length (rtx insn)
2764 {
2765   rtx pat = PATTERN (insn);
2766   unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
2767   unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
2768   unsigned int n_insns = 0;
2769
2770   /* We can't clear more than a word at a time because the PA
2771      has no longer integer move insns.  */
2772   if (align > (TARGET_64BIT ? 8 : 4))
2773     align = (TARGET_64BIT ? 8 : 4);
2774
2775   /* The basic loop.  */
2776   n_insns = 4;
2777
2778   /* Residuals.  */
2779   if (n_bytes % (2 * align) != 0)
2780     {
2781       if ((n_bytes % (2 * align)) >= align)
2782         n_insns++;
2783
2784       if ((n_bytes % align) != 0)
2785         n_insns++;
2786     }
2787
2788   /* Lengths are expressed in bytes now; each insn is 4 bytes.  */
2789   return n_insns * 4;
2790 }
2791 \f
2792
2793 const char *
2794 output_and (rtx *operands)
2795 {
2796   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2797     {
2798       unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2799       int ls0, ls1, ms0, p, len;
2800
2801       for (ls0 = 0; ls0 < 32; ls0++)
2802         if ((mask & (1 << ls0)) == 0)
2803           break;
2804
2805       for (ls1 = ls0; ls1 < 32; ls1++)
2806         if ((mask & (1 << ls1)) != 0)
2807           break;
2808
2809       for (ms0 = ls1; ms0 < 32; ms0++)
2810         if ((mask & (1 << ms0)) == 0)
2811           break;
2812
2813       gcc_assert (ms0 == 32);
2814
2815       if (ls1 == 32)
2816         {
2817           len = ls0;
2818
2819           gcc_assert (len);
2820
2821           operands[2] = GEN_INT (len);
2822           return "{extru|extrw,u} %1,31,%2,%0";
2823         }
2824       else
2825         {
2826           /* We could use this `depi' for the case above as well, but `depi'
2827              requires one more register file access than an `extru'.  */
2828
2829           p = 31 - ls0;
2830           len = ls1 - ls0;
2831
2832           operands[2] = GEN_INT (p);
2833           operands[3] = GEN_INT (len);
2834           return "{depi|depwi} 0,%2,%3,%0";
2835         }
2836     }
2837   else
2838     return "and %1,%2,%0";
2839 }
2840
2841 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
2842    storing the result in operands[0].  */
2843 const char *
2844 output_64bit_and (rtx *operands)
2845 {
2846   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2847     {
2848       unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2849       int ls0, ls1, ms0, p, len;
2850
2851       for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
2852         if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
2853           break;
2854
2855       for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
2856         if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
2857           break;
2858
2859       for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
2860         if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
2861           break;
2862
2863       gcc_assert (ms0 == HOST_BITS_PER_WIDE_INT);
2864
2865       if (ls1 == HOST_BITS_PER_WIDE_INT)
2866         {
2867           len = ls0;
2868
2869           gcc_assert (len);
2870
2871           operands[2] = GEN_INT (len);
2872           return "extrd,u %1,63,%2,%0";
2873         }
2874       else
2875         {
2876           /* We could use this `depi' for the case above as well, but `depi'
2877              requires one more register file access than an `extru'.  */
2878
2879           p = 63 - ls0;
2880           len = ls1 - ls0;
2881
2882           operands[2] = GEN_INT (p);
2883           operands[3] = GEN_INT (len);
2884           return "depdi 0,%2,%3,%0";
2885         }
2886     }
2887   else
2888     return "and %1,%2,%0";
2889 }
2890
2891 const char *
2892 output_ior (rtx *operands)
2893 {
2894   unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2895   int bs0, bs1, p, len;
2896
2897   if (INTVAL (operands[2]) == 0)
2898     return "copy %1,%0";
2899
2900   for (bs0 = 0; bs0 < 32; bs0++)
2901     if ((mask & (1 << bs0)) != 0)
2902       break;
2903
2904   for (bs1 = bs0; bs1 < 32; bs1++)
2905     if ((mask & (1 << bs1)) == 0)
2906       break;
2907
2908   gcc_assert (bs1 == 32 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
2909
2910   p = 31 - bs0;
2911   len = bs1 - bs0;
2912
2913   operands[2] = GEN_INT (p);
2914   operands[3] = GEN_INT (len);
2915   return "{depi|depwi} -1,%2,%3,%0";
2916 }
2917
2918 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
2919    storing the result in operands[0].  */
2920 const char *
2921 output_64bit_ior (rtx *operands)
2922 {
2923   unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2924   int bs0, bs1, p, len;
2925
2926   if (INTVAL (operands[2]) == 0)
2927     return "copy %1,%0";
2928
2929   for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
2930     if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
2931       break;
2932
2933   for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
2934     if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
2935       break;
2936
2937   gcc_assert (bs1 == HOST_BITS_PER_WIDE_INT
2938               || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
2939
2940   p = 63 - bs0;
2941   len = bs1 - bs0;
2942
2943   operands[2] = GEN_INT (p);
2944   operands[3] = GEN_INT (len);
2945   return "depdi -1,%2,%3,%0";
2946 }
2947 \f
2948 /* Target hook for assembling integer objects.  This code handles
2949    aligned SI and DI integers specially since function references
2950    must be preceded by P%.  */
2951
2952 static bool
2953 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
2954 {
2955   if (size == UNITS_PER_WORD
2956       && aligned_p
2957       && function_label_operand (x, VOIDmode))
2958     {
2959       fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
2960       output_addr_const (asm_out_file, x);
2961       fputc ('\n', asm_out_file);
2962       return true;
2963     }
2964   return default_assemble_integer (x, size, aligned_p);
2965 }
2966 \f
2967 /* Output an ascii string.  */
2968 void
2969 output_ascii (FILE *file, const char *p, int size)
2970 {
2971   int i;
2972   int chars_output;
2973   unsigned char partial_output[16];     /* Max space 4 chars can occupy.  */
2974
2975   /* The HP assembler can only take strings of 256 characters at one
2976      time.  This is a limitation on input line length, *not* the
2977      length of the string.  Sigh.  Even worse, it seems that the
2978      restriction is in number of input characters (see \xnn &
2979      \whatever).  So we have to do this very carefully.  */
2980
2981   fputs ("\t.STRING \"", file);
2982
2983   chars_output = 0;
2984   for (i = 0; i < size; i += 4)
2985     {
2986       int co = 0;
2987       int io = 0;
2988       for (io = 0, co = 0; io < MIN (4, size - i); io++)
2989         {
2990           register unsigned int c = (unsigned char) p[i + io];
2991
2992           if (c == '\"' || c == '\\')
2993             partial_output[co++] = '\\';
2994           if (c >= ' ' && c < 0177)
2995             partial_output[co++] = c;
2996           else
2997             {
2998               unsigned int hexd;
2999               partial_output[co++] = '\\';
3000               partial_output[co++] = 'x';
3001               hexd =  c  / 16 - 0 + '0';
3002               if (hexd > '9')
3003                 hexd -= '9' - 'a' + 1;
3004               partial_output[co++] = hexd;
3005               hexd =  c % 16 - 0 + '0';
3006               if (hexd > '9')
3007                 hexd -= '9' - 'a' + 1;
3008               partial_output[co++] = hexd;
3009             }
3010         }
3011       if (chars_output + co > 243)
3012         {
3013           fputs ("\"\n\t.STRING \"", file);
3014           chars_output = 0;
3015         }
3016       fwrite (partial_output, 1, (size_t) co, file);
3017       chars_output += co;
3018       co = 0;
3019     }
3020   fputs ("\"\n", file);
3021 }
3022
3023 /* Try to rewrite floating point comparisons & branches to avoid
3024    useless add,tr insns.
3025
3026    CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3027    to see if FPCC is dead.  CHECK_NOTES is nonzero for the
3028    first attempt to remove useless add,tr insns.  It is zero
3029    for the second pass as reorg sometimes leaves bogus REG_DEAD
3030    notes lying around.
3031
3032    When CHECK_NOTES is zero we can only eliminate add,tr insns
3033    when there's a 1:1 correspondence between fcmp and ftest/fbranch
3034    instructions.  */
3035 static void
3036 remove_useless_addtr_insns (int check_notes)
3037 {
3038   rtx insn;
3039   static int pass = 0;
3040
3041   /* This is fairly cheap, so always run it when optimizing.  */
3042   if (optimize > 0)
3043     {
3044       int fcmp_count = 0;
3045       int fbranch_count = 0;
3046
3047       /* Walk all the insns in this function looking for fcmp & fbranch
3048          instructions.  Keep track of how many of each we find.  */
3049       for (insn = get_insns (); insn; insn = next_insn (insn))
3050         {
3051           rtx tmp;
3052
3053           /* Ignore anything that isn't an INSN or a JUMP_INSN.  */
3054           if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3055             continue;
3056
3057           tmp = PATTERN (insn);
3058
3059           /* It must be a set.  */
3060           if (GET_CODE (tmp) != SET)
3061             continue;
3062
3063           /* If the destination is CCFP, then we've found an fcmp insn.  */
3064           tmp = SET_DEST (tmp);
3065           if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3066             {
3067               fcmp_count++;
3068               continue;
3069             }
3070
3071           tmp = PATTERN (insn);
3072           /* If this is an fbranch instruction, bump the fbranch counter.  */
3073           if (GET_CODE (tmp) == SET
3074               && SET_DEST (tmp) == pc_rtx
3075               && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3076               && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3077               && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3078               && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3079             {
3080               fbranch_count++;
3081               continue;
3082             }
3083         }
3084
3085
3086       /* Find all floating point compare + branch insns.  If possible,
3087          reverse the comparison & the branch to avoid add,tr insns.  */
3088       for (insn = get_insns (); insn; insn = next_insn (insn))
3089         {
3090           rtx tmp, next;
3091
3092           /* Ignore anything that isn't an INSN.  */
3093           if (GET_CODE (insn) != INSN)
3094             continue;
3095
3096           tmp = PATTERN (insn);
3097
3098           /* It must be a set.  */
3099           if (GET_CODE (tmp) != SET)
3100             continue;
3101
3102           /* The destination must be CCFP, which is register zero.  */
3103           tmp = SET_DEST (tmp);
3104           if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3105             continue;
3106
3107           /* INSN should be a set of CCFP.
3108
3109              See if the result of this insn is used in a reversed FP
3110              conditional branch.  If so, reverse our condition and
3111              the branch.  Doing so avoids useless add,tr insns.  */
3112           next = next_insn (insn);
3113           while (next)
3114             {
3115               /* Jumps, calls and labels stop our search.  */
3116               if (GET_CODE (next) == JUMP_INSN
3117                   || GET_CODE (next) == CALL_INSN
3118                   || GET_CODE (next) == CODE_LABEL)
3119                 break;
3120
3121               /* As does another fcmp insn.  */
3122               if (GET_CODE (next) == INSN
3123                   && GET_CODE (PATTERN (next)) == SET
3124                   && GET_CODE (SET_DEST (PATTERN (next))) == REG
3125                   && REGNO (SET_DEST (PATTERN (next))) == 0)
3126                 break;
3127
3128               next = next_insn (next);
3129             }
3130
3131           /* Is NEXT_INSN a branch?  */
3132           if (next
3133               && GET_CODE (next) == JUMP_INSN)
3134             {
3135               rtx pattern = PATTERN (next);
3136
3137               /* If it a reversed fp conditional branch (e.g. uses add,tr)
3138                  and CCFP dies, then reverse our conditional and the branch
3139                  to avoid the add,tr.  */
3140               if (GET_CODE (pattern) == SET
3141                   && SET_DEST (pattern) == pc_rtx
3142                   && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3143                   && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3144                   && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3145                   && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3146                   && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3147                   && (fcmp_count == fbranch_count
3148                       || (check_notes
3149                           && find_regno_note (next, REG_DEAD, 0))))
3150                 {
3151                   /* Reverse the branch.  */
3152                   tmp = XEXP (SET_SRC (pattern), 1);
3153                   XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3154                   XEXP (SET_SRC (pattern), 2) = tmp;
3155                   INSN_CODE (next) = -1;
3156
3157                   /* Reverse our condition.  */
3158                   tmp = PATTERN (insn);
3159                   PUT_CODE (XEXP (tmp, 1),
3160                             (reverse_condition_maybe_unordered
3161                              (GET_CODE (XEXP (tmp, 1)))));
3162                 }
3163             }
3164         }
3165     }
3166
3167   pass = !pass;
3168
3169 }
3170 \f
3171 /* You may have trouble believing this, but this is the 32 bit HP-PA
3172    stack layout.  Wow.
3173
3174    Offset               Contents
3175
3176    Variable arguments   (optional; any number may be allocated)
3177
3178    SP-(4*(N+9))         arg word N
3179         :                   :
3180       SP-56             arg word 5
3181       SP-52             arg word 4
3182
3183    Fixed arguments      (must be allocated; may remain unused)
3184
3185       SP-48             arg word 3
3186       SP-44             arg word 2
3187       SP-40             arg word 1
3188       SP-36             arg word 0
3189
3190    Frame Marker
3191
3192       SP-32             External Data Pointer (DP)
3193       SP-28             External sr4
3194       SP-24             External/stub RP (RP')
3195       SP-20             Current RP
3196       SP-16             Static Link
3197       SP-12             Clean up
3198       SP-8              Calling Stub RP (RP'')
3199       SP-4              Previous SP
3200
3201    Top of Frame
3202
3203       SP-0              Stack Pointer (points to next available address)
3204
3205 */
3206
3207 /* This function saves registers as follows.  Registers marked with ' are
3208    this function's registers (as opposed to the previous function's).
3209    If a frame_pointer isn't needed, r4 is saved as a general register;
3210    the space for the frame pointer is still allocated, though, to keep
3211    things simple.
3212
3213
3214    Top of Frame
3215
3216        SP (FP')         Previous FP
3217        SP + 4           Alignment filler (sigh)
3218        SP + 8           Space for locals reserved here.
3219        .
3220        .
3221        .
3222        SP + n           All call saved register used.
3223        .
3224        .
3225        .
3226        SP + o           All call saved fp registers used.
3227        .
3228        .
3229        .
3230        SP + p (SP')     points to next available address.
3231
3232 */
3233
3234 /* Global variables set by output_function_prologue().  */
3235 /* Size of frame.  Need to know this to emit return insns from
3236    leaf procedures.  */
3237 static HOST_WIDE_INT actual_fsize, local_fsize;
3238 static int save_fregs;
3239
3240 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3241    Handle case where DISP > 8k by using the add_high_const patterns.
3242
3243    Note in DISP > 8k case, we will leave the high part of the address
3244    in %r1.  There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3245
3246 static void
3247 store_reg (int reg, HOST_WIDE_INT disp, int base)
3248 {
3249   rtx insn, dest, src, basereg;
3250
3251   src = gen_rtx_REG (word_mode, reg);
3252   basereg = gen_rtx_REG (Pmode, base);
3253   if (VAL_14_BITS_P (disp))
3254     {
3255       dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3256       insn = emit_move_insn (dest, src);
3257     }
3258   else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3259     {
3260       rtx delta = GEN_INT (disp);
3261       rtx tmpreg = gen_rtx_REG (Pmode, 1);
3262
3263       emit_move_insn (tmpreg, delta);
3264       emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3265       dest = gen_rtx_MEM (word_mode, tmpreg);
3266       insn = emit_move_insn (dest, src);
3267       if (DO_FRAME_NOTES)
3268         {
3269           REG_NOTES (insn)
3270             = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3271                 gen_rtx_SET (VOIDmode,
3272                              gen_rtx_MEM (word_mode,
3273                                           gen_rtx_PLUS (word_mode, basereg,
3274                                                         delta)),
3275                              src),
3276                 REG_NOTES (insn));
3277         }
3278     }
3279   else
3280     {
3281       rtx delta = GEN_INT (disp);
3282       rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3283       rtx tmpreg = gen_rtx_REG (Pmode, 1);
3284
3285       emit_move_insn (tmpreg, high);
3286       dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3287       insn = emit_move_insn (dest, src);
3288       if (DO_FRAME_NOTES)
3289         {
3290           REG_NOTES (insn)
3291             = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3292                 gen_rtx_SET (VOIDmode,
3293                              gen_rtx_MEM (word_mode,
3294                                           gen_rtx_PLUS (word_mode, basereg,
3295                                                         delta)),
3296                              src),
3297                 REG_NOTES (insn));
3298         }
3299     }
3300
3301   if (DO_FRAME_NOTES)
3302     RTX_FRAME_RELATED_P (insn) = 1;
3303 }
3304
3305 /* Emit RTL to store REG at the memory location specified by BASE and then
3306    add MOD to BASE.  MOD must be <= 8k.  */
3307
3308 static void
3309 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3310 {
3311   rtx insn, basereg, srcreg, delta;
3312
3313   gcc_assert (VAL_14_BITS_P (mod));
3314
3315   basereg = gen_rtx_REG (Pmode, base);
3316   srcreg = gen_rtx_REG (word_mode, reg);
3317   delta = GEN_INT (mod);
3318
3319   insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3320   if (DO_FRAME_NOTES)
3321     {
3322       RTX_FRAME_RELATED_P (insn) = 1;
3323
3324       /* RTX_FRAME_RELATED_P must be set on each frame related set
3325          in a parallel with more than one element.  Don't set
3326          RTX_FRAME_RELATED_P in the first set if reg is temporary
3327          register 1. The effect of this operation is recorded in
3328          the initial copy.  */
3329       if (reg != 1)
3330         {
3331           RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3332           RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3333         }
3334       else
3335         {
3336           /* The first element of a PARALLEL is always processed if it is
3337              a SET.  Thus, we need an expression list for this case.  */
3338           REG_NOTES (insn)
3339             = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3340                 gen_rtx_SET (VOIDmode, basereg,
3341                              gen_rtx_PLUS (word_mode, basereg, delta)),
3342                 REG_NOTES (insn));
3343         }
3344     }
3345 }
3346
3347 /* Emit RTL to set REG to the value specified by BASE+DISP.  Handle case
3348    where DISP > 8k by using the add_high_const patterns.  NOTE indicates
3349    whether to add a frame note or not.
3350
3351    In the DISP > 8k case, we leave the high part of the address in %r1.
3352    There is code in expand_hppa_{prologue,epilogue} that knows about this.  */
3353
3354 static void
3355 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3356 {
3357   rtx insn;
3358
3359   if (VAL_14_BITS_P (disp))
3360     {
3361       insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3362                              plus_constant (gen_rtx_REG (Pmode, base), disp));
3363     }
3364   else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3365     {
3366       rtx basereg = gen_rtx_REG (Pmode, base);
3367       rtx delta = GEN_INT (disp);
3368       rtx tmpreg = gen_rtx_REG (Pmode, 1);
3369
3370       emit_move_insn (tmpreg, delta);
3371       insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3372                              gen_rtx_PLUS (Pmode, tmpreg, basereg));
3373     }
3374   else
3375     {
3376       rtx basereg = gen_rtx_REG (Pmode, base);
3377       rtx delta = GEN_INT (disp);
3378       rtx tmpreg = gen_rtx_REG (Pmode, 1);
3379
3380       emit_move_insn (tmpreg,
3381                       gen_rtx_PLUS (Pmode, basereg,
3382                                     gen_rtx_HIGH (Pmode, delta)));
3383       insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3384                         &