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 Free Software Foundation, Inc.
4 Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
6 This file is part of GCC.
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)
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.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-attr.h"
41 #include "integrate.h"
49 #include "target-def.h"
51 /* Return nonzero if there is a bypass for the output of
52 OUT_INSN and the fp store IN_INSN. */
54 hppa_fpstore_bypass_p (rtx out_insn, rtx in_insn)
56 enum machine_mode store_mode;
57 enum machine_mode other_mode;
60 if (recog_memoized (in_insn) < 0
61 || get_attr_type (in_insn) != TYPE_FPSTORE
62 || recog_memoized (out_insn) < 0)
65 store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
67 set = single_set (out_insn);
71 other_mode = GET_MODE (SET_SRC (set));
73 return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
77 #ifndef DO_FRAME_NOTES
78 #ifdef INCOMING_RETURN_ADDR_RTX
79 #define DO_FRAME_NOTES 1
81 #define DO_FRAME_NOTES 0
85 static void copy_reg_pointer (rtx, rtx);
86 static void fix_range (const char *);
87 static int hppa_address_cost (rtx);
88 static bool hppa_rtx_costs (rtx, int, int, int *);
89 static inline rtx force_mode (enum machine_mode, rtx);
90 static void pa_reorg (void);
91 static void pa_combine_instructions (void);
92 static int pa_can_combine_p (rtx, rtx, rtx, int, rtx, rtx, rtx);
93 static int forward_branch_p (rtx);
94 static int shadd_constant_p (int);
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)
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 *)
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);
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 void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
127 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
128 static struct deferred_plabel *get_plabel (const char *)
130 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
131 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
132 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
133 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
134 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
135 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
136 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
137 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
138 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
139 static void output_deferred_plabels (void);
140 #ifdef HPUX_LONG_DOUBLE_LIBRARY
141 static void pa_hpux_init_libfuncs (void);
143 static rtx pa_struct_value_rtx (tree, int);
144 static bool pa_pass_by_reference (CUMULATIVE_ARGS *ca, enum machine_mode,
146 static struct machine_function * pa_init_machine_status (void);
149 /* Save the operands last given to a compare for use when we
150 generate a scc or bcc insn. */
151 rtx hppa_compare_op0, hppa_compare_op1;
152 enum cmp_type hppa_branch_type;
154 /* Which architecture we are generating code for. */
155 enum architecture_type pa_arch;
157 /* String to hold which architecture we are generating code for. */
158 const char *pa_arch_string;
160 /* String used with the -mfixed-range= option. */
161 const char *pa_fixed_range_string;
163 /* Which cpu we are scheduling for. */
164 enum processor_type pa_cpu;
166 /* String to hold which cpu we are scheduling for. */
167 const char *pa_cpu_string;
169 /* String used with the -munix= option. */
170 const char *pa_unix_string;
172 /* The UNIX standard to use for predefines and linking. */
175 /* Counts for the number of callee-saved general and floating point
176 registers which were saved by the current function's prologue. */
177 static int gr_saved, fr_saved;
179 static rtx find_addr_reg (rtx);
181 /* Keep track of the number of bytes we have output in the CODE subspace
182 during this compilation so we'll know when to emit inline long-calls. */
183 unsigned long total_code_bytes;
185 /* The last address of the previous function plus the number of bytes in
186 associated thunks that have been output. This is used to determine if
187 a thunk can use an IA-relative branch to reach its target function. */
188 static int last_address;
190 /* Variables to handle plabels that we discover are necessary at assembly
191 output time. They are output after the current function. */
192 struct deferred_plabel GTY(())
197 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
199 static size_t n_deferred_plabels = 0;
202 /* Initialize the GCC target structure. */
204 #undef TARGET_ASM_ALIGNED_HI_OP
205 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
206 #undef TARGET_ASM_ALIGNED_SI_OP
207 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
208 #undef TARGET_ASM_ALIGNED_DI_OP
209 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
210 #undef TARGET_ASM_UNALIGNED_HI_OP
211 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
212 #undef TARGET_ASM_UNALIGNED_SI_OP
213 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
214 #undef TARGET_ASM_UNALIGNED_DI_OP
215 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
216 #undef TARGET_ASM_INTEGER
217 #define TARGET_ASM_INTEGER pa_assemble_integer
219 #undef TARGET_ASM_FUNCTION_PROLOGUE
220 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
221 #undef TARGET_ASM_FUNCTION_EPILOGUE
222 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
224 #undef TARGET_SCHED_ADJUST_COST
225 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
226 #undef TARGET_SCHED_ADJUST_PRIORITY
227 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
228 #undef TARGET_SCHED_ISSUE_RATE
229 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
231 #undef TARGET_ENCODE_SECTION_INFO
232 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
233 #undef TARGET_STRIP_NAME_ENCODING
234 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
236 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
237 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
239 #undef TARGET_ASM_OUTPUT_MI_THUNK
240 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
241 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
242 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
244 #undef TARGET_ASM_FILE_END
245 #define TARGET_ASM_FILE_END output_deferred_plabels
247 #if !defined(USE_COLLECT2)
248 #undef TARGET_ASM_CONSTRUCTOR
249 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
250 #undef TARGET_ASM_DESTRUCTOR
251 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
254 #undef TARGET_INIT_BUILTINS
255 #define TARGET_INIT_BUILTINS pa_init_builtins
257 #undef TARGET_RTX_COSTS
258 #define TARGET_RTX_COSTS hppa_rtx_costs
259 #undef TARGET_ADDRESS_COST
260 #define TARGET_ADDRESS_COST hppa_address_cost
262 #undef TARGET_MACHINE_DEPENDENT_REORG
263 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
265 #ifdef HPUX_LONG_DOUBLE_LIBRARY
266 #undef TARGET_INIT_LIBFUNCS
267 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
270 #undef TARGET_PROMOTE_FUNCTION_RETURN
271 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
272 #undef TARGET_PROMOTE_PROTOTYPES
273 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
275 #undef TARGET_STRUCT_VALUE_RTX
276 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
277 #undef TARGET_RETURN_IN_MEMORY
278 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
279 #undef TARGET_MUST_PASS_IN_STACK
280 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
281 #undef TARGET_PASS_BY_REFERENCE
282 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
283 #undef TARGET_CALLEE_COPIES
284 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
286 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
287 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
288 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
289 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
291 struct gcc_target targetm = TARGET_INITIALIZER;
293 /* Parse the -mfixed-range= option string. */
296 fix_range (const char *const_str)
299 char *str, *dash, *comma;
301 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
302 REG2 are either register names or register numbers. The effect
303 of this option is to mark the registers in the range from REG1 to
304 REG2 as ``fixed'' so they won't be used by the compiler. This is
305 used, e.g., to ensure that kernel mode code doesn't use f32-f127. */
307 i = strlen (const_str);
308 str = (char *) alloca (i + 1);
309 memcpy (str, const_str, i + 1);
313 dash = strchr (str, '-');
316 warning ("value of -mfixed-range must have form REG1-REG2");
321 comma = strchr (dash + 1, ',');
325 first = decode_reg_name (str);
328 warning ("unknown register name: %s", str);
332 last = decode_reg_name (dash + 1);
335 warning ("unknown register name: %s", dash + 1);
343 warning ("%s-%s is an empty range", str, dash + 1);
347 for (i = first; i <= last; ++i)
348 fixed_regs[i] = call_used_regs[i] = 1;
357 /* Check if all floating point registers have been fixed. */
358 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
363 target_flags |= MASK_DISABLE_FPREGS;
367 override_options (void)
369 if (pa_cpu_string == NULL)
370 pa_cpu_string = TARGET_SCHED_DEFAULT;
372 if (! strcmp (pa_cpu_string, "8000"))
374 pa_cpu_string = "8000";
375 pa_cpu = PROCESSOR_8000;
377 else if (! strcmp (pa_cpu_string, "7100"))
379 pa_cpu_string = "7100";
380 pa_cpu = PROCESSOR_7100;
382 else if (! strcmp (pa_cpu_string, "700"))
384 pa_cpu_string = "700";
385 pa_cpu = PROCESSOR_700;
387 else if (! strcmp (pa_cpu_string, "7100LC"))
389 pa_cpu_string = "7100LC";
390 pa_cpu = PROCESSOR_7100LC;
392 else if (! strcmp (pa_cpu_string, "7200"))
394 pa_cpu_string = "7200";
395 pa_cpu = PROCESSOR_7200;
397 else if (! strcmp (pa_cpu_string, "7300"))
399 pa_cpu_string = "7300";
400 pa_cpu = PROCESSOR_7300;
404 warning ("unknown -mschedule= option (%s).\nValid options are 700, 7100, 7100LC, 7200, 7300, and 8000\n", pa_cpu_string);
407 /* Set the instruction architecture. */
408 if (pa_arch_string && ! strcmp (pa_arch_string, "1.0"))
410 pa_arch_string = "1.0";
411 pa_arch = ARCHITECTURE_10;
412 target_flags &= ~(MASK_PA_11 | MASK_PA_20);
414 else if (pa_arch_string && ! strcmp (pa_arch_string, "1.1"))
416 pa_arch_string = "1.1";
417 pa_arch = ARCHITECTURE_11;
418 target_flags &= ~MASK_PA_20;
419 target_flags |= MASK_PA_11;
421 else if (pa_arch_string && ! strcmp (pa_arch_string, "2.0"))
423 pa_arch_string = "2.0";
424 pa_arch = ARCHITECTURE_20;
425 target_flags |= MASK_PA_11 | MASK_PA_20;
427 else if (pa_arch_string)
429 warning ("unknown -march= option (%s).\nValid options are 1.0, 1.1, and 2.0\n", pa_arch_string);
434 /* Set the default UNIX standard for HP-UX. This affects the
435 predefines and startfiles used for the target. */
436 if (pa_unix_string == NULL)
438 = TARGET_HPUX_11_11 ? "98" : (TARGET_HPUX_10_10 ? "95" : "93");
440 if (!strcmp (pa_unix_string, "93"))
442 else if (!strcmp (pa_unix_string, "95"))
444 else if (TARGET_HPUX_11_11)
446 if (!strcmp (pa_unix_string, "98"))
449 warning ("unknown -munix= option (%s).\n"
450 "Valid options are 93, 95 and 98.\n",
453 else if (TARGET_HPUX_10_10)
454 warning ("unknown -munix= option (%s)."
455 "\nValid options are 93 and 95.\n",
458 warning ("unknown -munix= option (%s).\nValid option is 93.\n",
462 if (pa_fixed_range_string)
463 fix_range (pa_fixed_range_string);
465 /* Unconditional branches in the delay slot are not compatible with dwarf2
466 call frame information. There is no benefit in using this optimization
467 on PA8000 and later processors. */
468 if (pa_cpu >= PROCESSOR_8000
469 || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
470 || flag_unwind_tables)
471 target_flags &= ~MASK_JUMP_IN_DELAY;
473 if (flag_pic && TARGET_PORTABLE_RUNTIME)
475 warning ("PIC code generation is not supported in the portable runtime model\n");
478 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
480 warning ("PIC code generation is not compatible with fast indirect calls\n");
483 if (! TARGET_GAS && write_symbols != NO_DEBUG)
485 warning ("-g is only supported when using GAS on this processor,");
486 warning ("-g option disabled");
487 write_symbols = NO_DEBUG;
490 /* We only support the "big PIC" model now. And we always generate PIC
491 code when in 64bit mode. */
492 if (flag_pic == 1 || TARGET_64BIT)
495 /* We can't guarantee that .dword is available for 32-bit targets. */
496 if (UNITS_PER_WORD == 4)
497 targetm.asm_out.aligned_op.di = NULL;
499 /* The unaligned ops are only available when using GAS. */
502 targetm.asm_out.unaligned_op.hi = NULL;
503 targetm.asm_out.unaligned_op.si = NULL;
504 targetm.asm_out.unaligned_op.di = NULL;
507 init_machine_status = pa_init_machine_status;
511 pa_init_builtins (void)
513 #ifdef DONT_HAVE_FPUTC_UNLOCKED
514 built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
515 implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
519 /* Function to init struct machine_function.
520 This will be called, via a pointer variable,
521 from push_function_context. */
523 static struct machine_function *
524 pa_init_machine_status (void)
526 return ggc_alloc_cleared (sizeof (machine_function));
529 /* If FROM is a probable pointer register, mark TO as a probable
530 pointer register with the same pointer alignment as FROM. */
533 copy_reg_pointer (rtx to, rtx from)
535 if (REG_POINTER (from))
536 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
539 /* Return nonzero only if OP is a register of mode MODE,
542 reg_or_0_operand (rtx op, enum machine_mode mode)
544 return (op == CONST0_RTX (mode) || register_operand (op, mode));
547 /* Return nonzero if OP is suitable for use in a call to a named
550 For 2.5 try to eliminate either call_operand_address or
551 function_label_operand, they perform very similar functions. */
553 call_operand_address (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
555 return (GET_MODE (op) == word_mode
556 && CONSTANT_P (op) && ! TARGET_PORTABLE_RUNTIME);
559 /* Return 1 if X contains a symbolic expression. We know these
560 expressions will have one of a few well defined forms, so
561 we need only check those forms. */
563 symbolic_expression_p (rtx x)
566 /* Strip off any HIGH. */
567 if (GET_CODE (x) == HIGH)
570 return (symbolic_operand (x, VOIDmode));
574 symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
576 switch (GET_CODE (op))
583 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
584 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
585 && GET_CODE (XEXP (op, 1)) == CONST_INT);
591 /* Return truth value of statement that OP is a symbolic memory
592 operand of mode MODE. */
595 symbolic_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
597 if (GET_CODE (op) == SUBREG)
598 op = SUBREG_REG (op);
599 if (GET_CODE (op) != MEM)
602 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
603 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
606 /* Return 1 if the operand is either a register, zero, or a memory operand
607 that is not symbolic. */
610 reg_or_0_or_nonsymb_mem_operand (rtx op, enum machine_mode mode)
612 if (register_operand (op, mode))
615 if (op == CONST0_RTX (mode))
618 if (GET_CODE (op) == SUBREG)
619 op = SUBREG_REG (op);
621 if (GET_CODE (op) != MEM)
624 /* Until problems with management of the REG_POINTER flag are resolved,
625 we need to delay creating move insns with unscaled indexed addresses
626 until CSE is not expected. */
627 if (!TARGET_NO_SPACE_REGS
629 && GET_CODE (XEXP (op, 0)) == PLUS
630 && REG_P (XEXP (XEXP (op, 0), 0))
631 && REG_P (XEXP (XEXP (op, 0), 1)))
634 return (!symbolic_memory_operand (op, mode)
635 && memory_address_p (mode, XEXP (op, 0)));
638 /* Return 1 if the operand is a register operand or a non-symbolic memory
639 operand after reload. This predicate is used for branch patterns that
640 internally handle register reloading. We need to accept non-symbolic
641 memory operands after reload to ensure that the pattern is still valid
642 if reload didn't find a hard register for the operand. */
645 reg_before_reload_operand (rtx op, enum machine_mode mode)
647 /* Don't accept a SUBREG since it will need a reload. */
648 if (GET_CODE (op) == SUBREG)
651 if (register_operand (op, mode))
655 && memory_operand (op, mode)
656 && !symbolic_memory_operand (op, mode))
662 /* Accept any constant that can be moved in one instruction into a
665 cint_ok_for_move (HOST_WIDE_INT intval)
667 /* OK if ldo, ldil, or zdepi, can be used. */
668 return (CONST_OK_FOR_LETTER_P (intval, 'J')
669 || CONST_OK_FOR_LETTER_P (intval, 'N')
670 || CONST_OK_FOR_LETTER_P (intval, 'K'));
673 /* Return 1 iff OP is an indexed memory operand. */
675 indexed_memory_operand (rtx op, enum machine_mode mode)
677 if (GET_MODE (op) != mode)
680 /* Before reload, a (SUBREG (MEM...)) forces reloading into a register. */
681 if (reload_completed && GET_CODE (op) == SUBREG)
682 op = SUBREG_REG (op);
684 if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
689 return (memory_address_p (mode, op) && IS_INDEX_ADDR_P (op));
692 /* Accept anything that can be used as a destination operand for a
693 move instruction. We don't accept indexed memory operands since
694 they are supported only for floating point stores. */
696 move_dest_operand (rtx op, enum machine_mode mode)
698 if (register_operand (op, mode))
701 if (GET_MODE (op) != mode)
704 if (GET_CODE (op) == SUBREG)
705 op = SUBREG_REG (op);
707 if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
712 return (memory_address_p (mode, op)
713 && !IS_INDEX_ADDR_P (op)
714 && !IS_LO_SUM_DLT_ADDR_P (op));
717 /* Accept anything that can be used as a source operand for a move
720 move_src_operand (rtx op, enum machine_mode mode)
722 if (register_operand (op, mode))
725 if (GET_CODE (op) == CONST_INT)
726 return cint_ok_for_move (INTVAL (op));
728 if (GET_MODE (op) != mode)
731 if (GET_CODE (op) == SUBREG)
732 op = SUBREG_REG (op);
734 if (GET_CODE (op) != MEM)
737 /* Until problems with management of the REG_POINTER flag are resolved,
738 we need to delay creating move insns with unscaled indexed addresses
739 until CSE is not expected. */
740 if (!TARGET_NO_SPACE_REGS
742 && GET_CODE (XEXP (op, 0)) == PLUS
743 && REG_P (XEXP (XEXP (op, 0), 0))
744 && REG_P (XEXP (XEXP (op, 0), 1)))
747 return memory_address_p (mode, XEXP (op, 0));
750 /* Accept anything that can be used as the source operand for a prefetch
753 prefetch_operand (rtx op, enum machine_mode mode)
755 if (GET_CODE (op) != MEM)
758 /* Until problems with management of the REG_POINTER flag are resolved,
759 we need to delay creating prefetch insns with unscaled indexed addresses
760 until CSE is not expected. */
761 if (!TARGET_NO_SPACE_REGS
763 && GET_CODE (XEXP (op, 0)) == PLUS
764 && REG_P (XEXP (XEXP (op, 0), 0))
765 && REG_P (XEXP (XEXP (op, 0), 1)))
768 return memory_address_p (mode, XEXP (op, 0));
771 /* Accept REG and any CONST_INT that can be moved in one instruction into a
774 reg_or_cint_move_operand (rtx op, enum machine_mode mode)
776 if (register_operand (op, mode))
779 return (GET_CODE (op) == CONST_INT && cint_ok_for_move (INTVAL (op)));
783 pic_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
788 switch (GET_CODE (op))
794 return (GET_CODE (XEXP (op, 0)) == LABEL_REF
795 && GET_CODE (XEXP (op, 1)) == CONST_INT);
802 fp_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
804 return reg_renumber && FP_REG_P (op);
809 /* Return truth value of whether OP can be used as an operand in a
810 three operand arithmetic insn that accepts registers of mode MODE
811 or 14-bit signed integers. */
813 arith_operand (rtx op, enum machine_mode mode)
815 return (register_operand (op, mode)
816 || (GET_CODE (op) == CONST_INT && INT_14_BITS (op)));
819 /* Return truth value of whether OP can be used as an operand in a
820 three operand arithmetic insn that accepts registers of mode MODE
821 or 11-bit signed integers. */
823 arith11_operand (rtx op, enum machine_mode mode)
825 return (register_operand (op, mode)
826 || (GET_CODE (op) == CONST_INT && INT_11_BITS (op)));
829 /* Return truth value of whether OP can be used as an operand in a
832 adddi3_operand (rtx op, enum machine_mode mode)
834 return (register_operand (op, mode)
835 || (GET_CODE (op) == CONST_INT
836 && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
839 /* A constant integer suitable for use in a PRE_MODIFY memory
842 pre_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
844 return (GET_CODE (op) == CONST_INT
845 && INTVAL (op) >= -0x2000 && INTVAL (op) < 0x10);
848 /* A constant integer suitable for use in a POST_MODIFY memory
851 post_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
853 return (GET_CODE (op) == CONST_INT
854 && INTVAL (op) < 0x2000 && INTVAL (op) >= -0x10);
858 arith_double_operand (rtx op, enum machine_mode mode)
860 return (register_operand (op, mode)
861 || (GET_CODE (op) == CONST_DOUBLE
862 && GET_MODE (op) == mode
863 && VAL_14_BITS_P (CONST_DOUBLE_LOW (op))
864 && ((CONST_DOUBLE_HIGH (op) >= 0)
865 == ((CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
868 /* Return truth value of whether OP is an integer which fits the
869 range constraining immediate operands in three-address insns, or
870 is an integer register. */
873 ireg_or_int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
875 return ((GET_CODE (op) == CONST_INT && INT_5_BITS (op))
876 || (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32));
879 /* Return nonzero if OP is an integer register, else return zero. */
881 ireg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
883 return (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32);
886 /* Return truth value of whether OP is an integer which fits the
887 range constraining immediate operands in three-address insns. */
890 int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
892 return (GET_CODE (op) == CONST_INT && INT_5_BITS (op));
896 uint5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
898 return (GET_CODE (op) == CONST_INT && INT_U5_BITS (op));
902 int11_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
904 return (GET_CODE (op) == CONST_INT && INT_11_BITS (op));
908 uint32_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
910 #if HOST_BITS_PER_WIDE_INT > 32
911 /* All allowed constants will fit a CONST_INT. */
912 return (GET_CODE (op) == CONST_INT
913 && (INTVAL (op) >= 0 && INTVAL (op) < (HOST_WIDE_INT) 1 << 32));
915 return (GET_CODE (op) == CONST_INT
916 || (GET_CODE (op) == CONST_DOUBLE
917 && CONST_DOUBLE_HIGH (op) == 0));
922 arith5_operand (rtx op, enum machine_mode mode)
924 return register_operand (op, mode) || int5_operand (op, mode);
927 /* True iff zdepi can be used to generate this CONST_INT.
928 zdepi first sign extends a 5 bit signed number to a given field
929 length, then places this field anywhere in a zero. */
931 zdepi_cint_p (unsigned HOST_WIDE_INT x)
933 unsigned HOST_WIDE_INT lsb_mask, t;
935 /* This might not be obvious, but it's at least fast.
936 This function is critical; we don't have the time loops would take. */
938 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
939 /* Return true iff t is a power of two. */
940 return ((t & (t - 1)) == 0);
943 /* True iff depi or extru can be used to compute (reg & mask).
944 Accept bit pattern like these:
949 and_mask_p (unsigned HOST_WIDE_INT mask)
952 mask += mask & -mask;
953 return (mask & (mask - 1)) == 0;
956 /* True iff depi or extru can be used to compute (reg & OP). */
958 and_operand (rtx op, enum machine_mode mode)
960 return (register_operand (op, mode)
961 || (GET_CODE (op) == CONST_INT && and_mask_p (INTVAL (op))));
964 /* True iff depi can be used to compute (reg | MASK). */
966 ior_mask_p (unsigned HOST_WIDE_INT mask)
968 mask += mask & -mask;
969 return (mask & (mask - 1)) == 0;
972 /* True iff depi can be used to compute (reg | OP). */
974 ior_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
976 return (GET_CODE (op) == CONST_INT && ior_mask_p (INTVAL (op)));
980 lhs_lshift_operand (rtx op, enum machine_mode mode)
982 return register_operand (op, mode) || lhs_lshift_cint_operand (op, mode);
985 /* True iff OP is a CONST_INT of the forms 0...0xxxx or 0...01...1xxxx.
986 Such values can be the left hand side x in (x << r), using the zvdepi
989 lhs_lshift_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
991 unsigned HOST_WIDE_INT x;
992 if (GET_CODE (op) != CONST_INT)
994 x = INTVAL (op) >> 4;
995 return (x & (x + 1)) == 0;
999 arith32_operand (rtx op, enum machine_mode mode)
1001 return register_operand (op, mode) || GET_CODE (op) == CONST_INT;
1005 pc_or_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1007 return (GET_CODE (op) == PC || GET_CODE (op) == LABEL_REF);
1010 /* Legitimize PIC addresses. If the address is already
1011 position-independent, we return ORIG. Newly generated
1012 position-independent addresses go to REG. If we need more
1013 than one register, we lose. */
1016 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
1020 /* Labels need special handling. */
1021 if (pic_label_operand (orig, mode))
1023 /* We do not want to go through the movXX expanders here since that
1024 would create recursion.
1026 Nor do we really want to call a generator for a named pattern
1027 since that requires multiple patterns if we want to support
1028 multiple word sizes.
1030 So instead we just emit the raw set, which avoids the movXX
1031 expanders completely. */
1032 mark_reg_pointer (reg, BITS_PER_UNIT);
1033 emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
1034 current_function_uses_pic_offset_table = 1;
1037 if (GET_CODE (orig) == SYMBOL_REF)
1044 /* Before reload, allocate a temporary register for the intermediate
1045 result. This allows the sequence to be deleted when the final
1046 result is unused and the insns are trivially dead. */
1047 tmp_reg = ((reload_in_progress || reload_completed)
1048 ? reg : gen_reg_rtx (Pmode));
1050 emit_move_insn (tmp_reg,
1051 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
1052 gen_rtx_HIGH (word_mode, orig)));
1054 = gen_const_mem (Pmode,
1055 gen_rtx_LO_SUM (Pmode, tmp_reg,
1056 gen_rtx_UNSPEC (Pmode,
1057 gen_rtvec (1, orig),
1058 UNSPEC_DLTIND14R)));
1060 current_function_uses_pic_offset_table = 1;
1061 mark_reg_pointer (reg, BITS_PER_UNIT);
1062 insn = emit_move_insn (reg, pic_ref);
1064 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
1065 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig, REG_NOTES (insn));
1069 else if (GET_CODE (orig) == CONST)
1073 if (GET_CODE (XEXP (orig, 0)) == PLUS
1074 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1080 if (GET_CODE (XEXP (orig, 0)) == PLUS)
1082 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1083 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1084 base == reg ? 0 : reg);
1089 if (GET_CODE (orig) == CONST_INT)
1091 if (INT_14_BITS (orig))
1092 return plus_constant (base, INTVAL (orig));
1093 orig = force_reg (Pmode, orig);
1095 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
1096 /* Likewise, should we set special REG_NOTEs here? */
1102 /* Try machine-dependent ways of modifying an illegitimate address
1103 to be legitimate. If we find one, return the new, valid address.
1104 This macro is used in only one place: `memory_address' in explow.c.
1106 OLDX is the address as it was before break_out_memory_refs was called.
1107 In some cases it is useful to look at this to decide what needs to be done.
1109 MODE and WIN are passed so that this macro can use
1110 GO_IF_LEGITIMATE_ADDRESS.
1112 It is always safe for this macro to do nothing. It exists to recognize
1113 opportunities to optimize the output.
1115 For the PA, transform:
1117 memory(X + <large int>)
1121 if (<large int> & mask) >= 16
1122 Y = (<large int> & ~mask) + mask + 1 Round up.
1124 Y = (<large int> & ~mask) Round down.
1126 memory (Z + (<large int> - Y));
1128 This is for CSE to find several similar references, and only use one Z.
1130 X can either be a SYMBOL_REF or REG, but because combine cannot
1131 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
1132 D will not fit in 14 bits.
1134 MODE_FLOAT references allow displacements which fit in 5 bits, so use
1137 MODE_INT references allow displacements which fit in 14 bits, so use
1140 This relies on the fact that most mode MODE_FLOAT references will use FP
1141 registers and most mode MODE_INT references will use integer registers.
1142 (In the rare case of an FP register used in an integer MODE, we depend
1143 on secondary reloads to clean things up.)
1146 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
1147 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
1148 addressing modes to be used).
1150 Put X and Z into registers. Then put the entire expression into
1154 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1155 enum machine_mode mode)
1159 /* We need to canonicalize the order of operands in unscaled indexed
1160 addresses since the code that checks if an address is valid doesn't
1161 always try both orders. */
1162 if (!TARGET_NO_SPACE_REGS
1163 && GET_CODE (x) == PLUS
1164 && GET_MODE (x) == Pmode
1165 && REG_P (XEXP (x, 0))
1166 && REG_P (XEXP (x, 1))
1167 && REG_POINTER (XEXP (x, 0))
1168 && !REG_POINTER (XEXP (x, 1)))
1169 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
1172 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
1174 /* Strip off CONST. */
1175 if (GET_CODE (x) == CONST)
1178 /* Special case. Get the SYMBOL_REF into a register and use indexing.
1179 That should always be safe. */
1180 if (GET_CODE (x) == PLUS
1181 && GET_CODE (XEXP (x, 0)) == REG
1182 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
1184 rtx reg = force_reg (Pmode, XEXP (x, 1));
1185 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
1188 /* Note we must reject symbols which represent function addresses
1189 since the assembler/linker can't handle arithmetic on plabels. */
1190 if (GET_CODE (x) == PLUS
1191 && GET_CODE (XEXP (x, 1)) == CONST_INT
1192 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1193 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
1194 || GET_CODE (XEXP (x, 0)) == REG))
1196 rtx int_part, ptr_reg;
1198 int offset = INTVAL (XEXP (x, 1));
1201 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
1202 ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
1204 /* Choose which way to round the offset. Round up if we
1205 are >= halfway to the next boundary. */
1206 if ((offset & mask) >= ((mask + 1) / 2))
1207 newoffset = (offset & ~ mask) + mask + 1;
1209 newoffset = (offset & ~ mask);
1211 /* If the newoffset will not fit in 14 bits (ldo), then
1212 handling this would take 4 or 5 instructions (2 to load
1213 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
1214 add the new offset and the SYMBOL_REF.) Combine can
1215 not handle 4->2 or 5->2 combinations, so do not create
1217 if (! VAL_14_BITS_P (newoffset)
1218 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
1220 rtx const_part = plus_constant (XEXP (x, 0), newoffset);
1223 gen_rtx_HIGH (Pmode, const_part));
1226 gen_rtx_LO_SUM (Pmode,
1227 tmp_reg, const_part));
1231 if (! VAL_14_BITS_P (newoffset))
1232 int_part = force_reg (Pmode, GEN_INT (newoffset));
1234 int_part = GEN_INT (newoffset);
1236 ptr_reg = force_reg (Pmode,
1237 gen_rtx_PLUS (Pmode,
1238 force_reg (Pmode, XEXP (x, 0)),
1241 return plus_constant (ptr_reg, offset - newoffset);
1244 /* Handle (plus (mult (a) (shadd_constant)) (b)). */
1246 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1247 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1248 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
1249 && (OBJECT_P (XEXP (x, 1))
1250 || GET_CODE (XEXP (x, 1)) == SUBREG)
1251 && GET_CODE (XEXP (x, 1)) != CONST)
1253 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1257 if (GET_CODE (reg1) != REG)
1258 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1260 reg2 = XEXP (XEXP (x, 0), 0);
1261 if (GET_CODE (reg2) != REG)
1262 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1264 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1265 gen_rtx_MULT (Pmode,
1271 /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
1273 Only do so for floating point modes since this is more speculative
1274 and we lose if it's an integer store. */
1275 if (GET_CODE (x) == PLUS
1276 && GET_CODE (XEXP (x, 0)) == PLUS
1277 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1278 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
1279 && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1280 && (mode == SFmode || mode == DFmode))
1283 /* First, try and figure out what to use as a base register. */
1284 rtx reg1, reg2, base, idx, orig_base;
1286 reg1 = XEXP (XEXP (x, 0), 1);
1291 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
1292 then emit_move_sequence will turn on REG_POINTER so we'll know
1293 it's a base register below. */
1294 if (GET_CODE (reg1) != REG)
1295 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1297 if (GET_CODE (reg2) != REG)
1298 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1300 /* Figure out what the base and index are. */
1302 if (GET_CODE (reg1) == REG
1303 && REG_POINTER (reg1))
1306 orig_base = XEXP (XEXP (x, 0), 1);
1307 idx = gen_rtx_PLUS (Pmode,
1308 gen_rtx_MULT (Pmode,
1309 XEXP (XEXP (XEXP (x, 0), 0), 0),
1310 XEXP (XEXP (XEXP (x, 0), 0), 1)),
1313 else if (GET_CODE (reg2) == REG
1314 && REG_POINTER (reg2))
1317 orig_base = XEXP (x, 1);
1324 /* If the index adds a large constant, try to scale the
1325 constant so that it can be loaded with only one insn. */
1326 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1327 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1328 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1329 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1331 /* Divide the CONST_INT by the scale factor, then add it to A. */
1332 int val = INTVAL (XEXP (idx, 1));
1334 val /= INTVAL (XEXP (XEXP (idx, 0), 1));
1335 reg1 = XEXP (XEXP (idx, 0), 0);
1336 if (GET_CODE (reg1) != REG)
1337 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1339 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1341 /* We can now generate a simple scaled indexed address. */
1344 (Pmode, gen_rtx_PLUS (Pmode,
1345 gen_rtx_MULT (Pmode, reg1,
1346 XEXP (XEXP (idx, 0), 1)),
1350 /* If B + C is still a valid base register, then add them. */
1351 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1352 && INTVAL (XEXP (idx, 1)) <= 4096
1353 && INTVAL (XEXP (idx, 1)) >= -4096)
1355 int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1358 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1360 reg2 = XEXP (XEXP (idx, 0), 0);
1361 if (GET_CODE (reg2) != CONST_INT)
1362 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1364 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1365 gen_rtx_MULT (Pmode,
1371 /* Get the index into a register, then add the base + index and
1372 return a register holding the result. */
1374 /* First get A into a register. */
1375 reg1 = XEXP (XEXP (idx, 0), 0);
1376 if (GET_CODE (reg1) != REG)
1377 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1379 /* And get B into a register. */
1380 reg2 = XEXP (idx, 1);
1381 if (GET_CODE (reg2) != REG)
1382 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1384 reg1 = force_reg (Pmode,
1385 gen_rtx_PLUS (Pmode,
1386 gen_rtx_MULT (Pmode, reg1,
1387 XEXP (XEXP (idx, 0), 1)),
1390 /* Add the result to our base register and return. */
1391 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1395 /* Uh-oh. We might have an address for x[n-100000]. This needs
1396 special handling to avoid creating an indexed memory address
1397 with x-100000 as the base.
1399 If the constant part is small enough, then it's still safe because
1400 there is a guard page at the beginning and end of the data segment.
1402 Scaled references are common enough that we want to try and rearrange the
1403 terms so that we can use indexing for these addresses too. Only
1404 do the optimization for floatint point modes. */
1406 if (GET_CODE (x) == PLUS
1407 && symbolic_expression_p (XEXP (x, 1)))
1409 /* Ugly. We modify things here so that the address offset specified
1410 by the index expression is computed first, then added to x to form
1411 the entire address. */
1413 rtx regx1, regx2, regy1, regy2, y;
1415 /* Strip off any CONST. */
1417 if (GET_CODE (y) == CONST)
1420 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1422 /* See if this looks like
1423 (plus (mult (reg) (shadd_const))
1424 (const (plus (symbol_ref) (const_int))))
1426 Where const_int is small. In that case the const
1427 expression is a valid pointer for indexing.
1429 If const_int is big, but can be divided evenly by shadd_const
1430 and added to (reg). This allows more scaled indexed addresses. */
1431 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1432 && GET_CODE (XEXP (x, 0)) == MULT
1433 && GET_CODE (XEXP (y, 1)) == CONST_INT
1434 && INTVAL (XEXP (y, 1)) >= -4096
1435 && INTVAL (XEXP (y, 1)) <= 4095
1436 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1437 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1439 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1443 if (GET_CODE (reg1) != REG)
1444 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1446 reg2 = XEXP (XEXP (x, 0), 0);
1447 if (GET_CODE (reg2) != REG)
1448 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1450 return force_reg (Pmode,
1451 gen_rtx_PLUS (Pmode,
1452 gen_rtx_MULT (Pmode,
1457 else if ((mode == DFmode || mode == SFmode)
1458 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1459 && GET_CODE (XEXP (x, 0)) == MULT
1460 && GET_CODE (XEXP (y, 1)) == CONST_INT
1461 && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1462 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1463 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1466 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1467 / INTVAL (XEXP (XEXP (x, 0), 1))));
1468 regx2 = XEXP (XEXP (x, 0), 0);
1469 if (GET_CODE (regx2) != REG)
1470 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1471 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1475 gen_rtx_PLUS (Pmode,
1476 gen_rtx_MULT (Pmode, regx2,
1477 XEXP (XEXP (x, 0), 1)),
1478 force_reg (Pmode, XEXP (y, 0))));
1480 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1481 && INTVAL (XEXP (y, 1)) >= -4096
1482 && INTVAL (XEXP (y, 1)) <= 4095)
1484 /* This is safe because of the guard page at the
1485 beginning and end of the data space. Just
1486 return the original address. */
1491 /* Doesn't look like one we can optimize. */
1492 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1493 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1494 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1495 regx1 = force_reg (Pmode,
1496 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1498 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1506 /* For the HPPA, REG and REG+CONST is cost 0
1507 and addresses involving symbolic constants are cost 2.
1509 PIC addresses are very expensive.
1511 It is no coincidence that this has the same structure
1512 as GO_IF_LEGITIMATE_ADDRESS. */
1515 hppa_address_cost (rtx X)
1517 switch (GET_CODE (X))
1530 /* Compute a (partial) cost for rtx X. Return true if the complete
1531 cost has been computed, and false if subexpressions should be
1532 scanned. In either case, *TOTAL contains the cost result. */
1535 hppa_rtx_costs (rtx x, int code, int outer_code, int *total)
1540 if (INTVAL (x) == 0)
1542 else if (INT_14_BITS (x))
1559 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1560 && outer_code != SET)
1567 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1568 *total = COSTS_N_INSNS (3);
1569 else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1570 *total = COSTS_N_INSNS (8);
1572 *total = COSTS_N_INSNS (20);
1576 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1578 *total = COSTS_N_INSNS (14);
1586 *total = COSTS_N_INSNS (60);
1589 case PLUS: /* this includes shNadd insns */
1591 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1592 *total = COSTS_N_INSNS (3);
1594 *total = COSTS_N_INSNS (1);
1600 *total = COSTS_N_INSNS (1);
1608 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1609 new rtx with the correct mode. */
1611 force_mode (enum machine_mode mode, rtx orig)
1613 if (mode == GET_MODE (orig))
1616 if (REGNO (orig) >= FIRST_PSEUDO_REGISTER)
1619 return gen_rtx_REG (mode, REGNO (orig));
1622 /* Emit insns to move operands[1] into operands[0].
1624 Return 1 if we have written out everything that needs to be done to
1625 do the move. Otherwise, return 0 and the caller will emit the move
1628 Note SCRATCH_REG may not be in the proper mode depending on how it
1629 will be used. This routine is responsible for creating a new copy
1630 of SCRATCH_REG in the proper mode. */
1633 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1635 register rtx operand0 = operands[0];
1636 register rtx operand1 = operands[1];
1639 /* We can only handle indexed addresses in the destination operand
1640 of floating point stores. Thus, we need to break out indexed
1641 addresses from the destination operand. */
1642 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1644 /* This is only safe up to the beginning of life analysis. */
1648 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1649 operand0 = replace_equiv_address (operand0, tem);
1652 /* On targets with non-equivalent space registers, break out unscaled
1653 indexed addresses from the source operand before the final CSE.
1654 We have to do this because the REG_POINTER flag is not correctly
1655 carried through various optimization passes and CSE may substitute
1656 a pseudo without the pointer set for one with the pointer set. As
1657 a result, we loose various opportunities to create insns with
1658 unscaled indexed addresses. */
1659 if (!TARGET_NO_SPACE_REGS
1660 && !cse_not_expected
1661 && GET_CODE (operand1) == MEM
1662 && GET_CODE (XEXP (operand1, 0)) == PLUS
1663 && REG_P (XEXP (XEXP (operand1, 0), 0))
1664 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1666 = replace_equiv_address (operand1,
1667 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1670 && reload_in_progress && GET_CODE (operand0) == REG
1671 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1672 operand0 = reg_equiv_mem[REGNO (operand0)];
1673 else if (scratch_reg
1674 && reload_in_progress && GET_CODE (operand0) == SUBREG
1675 && GET_CODE (SUBREG_REG (operand0)) == REG
1676 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1678 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1679 the code which tracks sets/uses for delete_output_reload. */
1680 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1681 reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1682 SUBREG_BYTE (operand0));
1683 operand0 = alter_subreg (&temp);
1687 && reload_in_progress && GET_CODE (operand1) == REG
1688 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1689 operand1 = reg_equiv_mem[REGNO (operand1)];
1690 else if (scratch_reg
1691 && reload_in_progress && GET_CODE (operand1) == SUBREG
1692 && GET_CODE (SUBREG_REG (operand1)) == REG
1693 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1695 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1696 the code which tracks sets/uses for delete_output_reload. */
1697 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1698 reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1699 SUBREG_BYTE (operand1));
1700 operand1 = alter_subreg (&temp);
1703 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1704 && ((tem = find_replacement (&XEXP (operand0, 0)))
1705 != XEXP (operand0, 0)))
1706 operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
1708 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1709 && ((tem = find_replacement (&XEXP (operand1, 0)))
1710 != XEXP (operand1, 0)))
1711 operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
1713 /* Handle secondary reloads for loads/stores of FP registers from
1714 REG+D addresses where D does not fit in 5 or 14 bits, including
1715 (subreg (mem (addr))) cases. */
1717 && fp_reg_operand (operand0, mode)
1718 && ((GET_CODE (operand1) == MEM
1719 && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1720 XEXP (operand1, 0)))
1721 || ((GET_CODE (operand1) == SUBREG
1722 && GET_CODE (XEXP (operand1, 0)) == MEM
1723 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1725 XEXP (XEXP (operand1, 0), 0))))))
1727 if (GET_CODE (operand1) == SUBREG)
1728 operand1 = XEXP (operand1, 0);
1730 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1731 it in WORD_MODE regardless of what mode it was originally given
1733 scratch_reg = force_mode (word_mode, scratch_reg);
1735 /* D might not fit in 14 bits either; for such cases load D into
1737 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1739 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1740 emit_move_insn (scratch_reg,
1741 gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1743 XEXP (XEXP (operand1, 0), 0),
1747 emit_move_insn (scratch_reg, XEXP (operand1, 0));
1748 emit_insn (gen_rtx_SET (VOIDmode, operand0,
1749 gen_rtx_MEM (mode, scratch_reg)));
1752 else if (scratch_reg
1753 && fp_reg_operand (operand1, mode)
1754 && ((GET_CODE (operand0) == MEM
1755 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1757 XEXP (operand0, 0)))
1758 || ((GET_CODE (operand0) == SUBREG)
1759 && GET_CODE (XEXP (operand0, 0)) == MEM
1760 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1762 XEXP (XEXP (operand0, 0), 0)))))
1764 if (GET_CODE (operand0) == SUBREG)
1765 operand0 = XEXP (operand0, 0);
1767 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1768 it in WORD_MODE regardless of what mode it was originally given
1770 scratch_reg = force_mode (word_mode, scratch_reg);
1772 /* D might not fit in 14 bits either; for such cases load D into
1774 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1776 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1777 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1780 XEXP (XEXP (operand0, 0),
1785 emit_move_insn (scratch_reg, XEXP (operand0, 0));
1786 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
1790 /* Handle secondary reloads for loads of FP registers from constant
1791 expressions by forcing the constant into memory.
1793 Use scratch_reg to hold the address of the memory location.
1795 The proper fix is to change PREFERRED_RELOAD_CLASS to return
1796 NO_REGS when presented with a const_int and a register class
1797 containing only FP registers. Doing so unfortunately creates
1798 more problems than it solves. Fix this for 2.5. */
1799 else if (scratch_reg
1800 && CONSTANT_P (operand1)
1801 && fp_reg_operand (operand0, mode))
1805 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1806 it in WORD_MODE regardless of what mode it was originally given
1808 scratch_reg = force_mode (word_mode, scratch_reg);
1810 /* Force the constant into memory and put the address of the
1811 memory location into scratch_reg. */
1812 xoperands[0] = scratch_reg;
1813 xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
1814 emit_move_sequence (xoperands, Pmode, 0);
1816 /* Now load the destination register. */
1817 emit_insn (gen_rtx_SET (mode, operand0,
1818 gen_rtx_MEM (mode, scratch_reg)));
1821 /* Handle secondary reloads for SAR. These occur when trying to load
1822 the SAR from memory, FP register, or with a constant. */
1823 else if (scratch_reg
1824 && GET_CODE (operand0) == REG
1825 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1826 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1827 && (GET_CODE (operand1) == MEM
1828 || GET_CODE (operand1) == CONST_INT
1829 || (GET_CODE (operand1) == REG
1830 && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1832 /* D might not fit in 14 bits either; for such cases load D into
1834 if (GET_CODE (operand1) == MEM
1835 && !memory_address_p (Pmode, XEXP (operand1, 0)))
1837 /* We are reloading the address into the scratch register, so we
1838 want to make sure the scratch register is a full register. */
1839 scratch_reg = force_mode (word_mode, scratch_reg);
1841 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1842 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1845 XEXP (XEXP (operand1, 0),
1849 /* Now we are going to load the scratch register from memory,
1850 we want to load it in the same width as the original MEM,
1851 which must be the same as the width of the ultimate destination,
1853 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1855 emit_move_insn (scratch_reg, gen_rtx_MEM (GET_MODE (operand0),
1860 /* We want to load the scratch register using the same mode as
1861 the ultimate destination. */
1862 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1864 emit_move_insn (scratch_reg, operand1);
1867 /* And emit the insn to set the ultimate destination. We know that
1868 the scratch register has the same mode as the destination at this
1870 emit_move_insn (operand0, scratch_reg);
1873 /* Handle the most common case: storing into a register. */
1874 else if (register_operand (operand0, mode))
1876 if (register_operand (operand1, mode)
1877 || (GET_CODE (operand1) == CONST_INT
1878 && cint_ok_for_move (INTVAL (operand1)))
1879 || (operand1 == CONST0_RTX (mode))
1880 || (GET_CODE (operand1) == HIGH
1881 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1882 /* Only `general_operands' can come here, so MEM is ok. */
1883 || GET_CODE (operand1) == MEM)
1885 /* Various sets are created during RTL generation which don't
1886 have the REG_POINTER flag correctly set. After the CSE pass,
1887 instruction recognition can fail if we don't consistently
1888 set this flag when performing register copies. This should
1889 also improve the opportunities for creating insns that use
1890 unscaled indexing. */
1891 if (REG_P (operand0) && REG_P (operand1))
1893 if (REG_POINTER (operand1)
1894 && !REG_POINTER (operand0)
1895 && !HARD_REGISTER_P (operand0))
1896 copy_reg_pointer (operand0, operand1);
1897 else if (REG_POINTER (operand0)
1898 && !REG_POINTER (operand1)
1899 && !HARD_REGISTER_P (operand1))
1900 copy_reg_pointer (operand1, operand0);
1903 /* When MEMs are broken out, the REG_POINTER flag doesn't
1904 get set. In some cases, we can set the REG_POINTER flag
1905 from the declaration for the MEM. */
1906 if (REG_P (operand0)
1907 && GET_CODE (operand1) == MEM
1908 && !REG_POINTER (operand0))
1910 tree decl = MEM_EXPR (operand1);
1912 /* Set the register pointer flag and register alignment
1913 if the declaration for this memory reference is a
1914 pointer type. Fortran indirect argument references
1917 && !(flag_argument_noalias > 1
1918 && TREE_CODE (decl) == INDIRECT_REF
1919 && TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL))
1923 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1925 if (TREE_CODE (decl) == COMPONENT_REF)
1926 decl = TREE_OPERAND (decl, 1);
1928 type = TREE_TYPE (decl);
1929 if (TREE_CODE (type) == ARRAY_TYPE)
1930 type = get_inner_array_type (type);
1932 if (POINTER_TYPE_P (type))
1936 type = TREE_TYPE (type);
1937 /* Using TYPE_ALIGN_OK is rather conservative as
1938 only the ada frontend actually sets it. */
1939 align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1941 mark_reg_pointer (operand0, align);
1946 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1950 else if (GET_CODE (operand0) == MEM)
1952 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1953 && !(reload_in_progress || reload_completed))
1955 rtx temp = gen_reg_rtx (DFmode);
1957 emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1958 emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1961 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1963 /* Run this case quickly. */
1964 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1967 if (! (reload_in_progress || reload_completed))
1969 operands[0] = validize_mem (operand0);
1970 operands[1] = operand1 = force_reg (mode, operand1);
1974 /* Simplify the source if we need to.
1975 Note we do have to handle function labels here, even though we do
1976 not consider them legitimate constants. Loop optimizations can
1977 call the emit_move_xxx with one as a source. */
1978 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1979 || function_label_operand (operand1, mode)
1980 || (GET_CODE (operand1) == HIGH
1981 && symbolic_operand (XEXP (operand1, 0), mode)))
1985 if (GET_CODE (operand1) == HIGH)
1988 operand1 = XEXP (operand1, 0);
1990 if (symbolic_operand (operand1, mode))
1992 /* Argh. The assembler and linker can't handle arithmetic
1995 So we force the plabel into memory, load operand0 from
1996 the memory location, then add in the constant part. */
1997 if ((GET_CODE (operand1) == CONST
1998 && GET_CODE (XEXP (operand1, 0)) == PLUS
1999 && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
2000 || function_label_operand (operand1, mode))
2002 rtx temp, const_part;
2004 /* Figure out what (if any) scratch register to use. */
2005 if (reload_in_progress || reload_completed)
2007 scratch_reg = scratch_reg ? scratch_reg : operand0;
2008 /* SCRATCH_REG will hold an address and maybe the actual
2009 data. We want it in WORD_MODE regardless of what mode it
2010 was originally given to us. */
2011 scratch_reg = force_mode (word_mode, scratch_reg);
2014 scratch_reg = gen_reg_rtx (Pmode);
2016 if (GET_CODE (operand1) == CONST)
2018 /* Save away the constant part of the expression. */
2019 const_part = XEXP (XEXP (operand1, 0), 1);
2020 if (GET_CODE (const_part) != CONST_INT)
2023 /* Force the function label into memory. */
2024 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
2028 /* No constant part. */
2029 const_part = NULL_RTX;
2031 /* Force the function label into memory. */
2032 temp = force_const_mem (mode, operand1);
2036 /* Get the address of the memory location. PIC-ify it if
2038 temp = XEXP (temp, 0);
2040 temp = legitimize_pic_address (temp, mode, scratch_reg);
2042 /* Put the address of the memory location into our destination
2045 emit_move_sequence (operands, mode, scratch_reg);
2047 /* Now load from the memory location into our destination
2049 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
2050 emit_move_sequence (operands, mode, scratch_reg);
2052 /* And add back in the constant part. */
2053 if (const_part != NULL_RTX)
2054 expand_inc (operand0, const_part);
2063 if (reload_in_progress || reload_completed)
2065 temp = scratch_reg ? scratch_reg : operand0;
2066 /* TEMP will hold an address and maybe the actual
2067 data. We want it in WORD_MODE regardless of what mode it
2068 was originally given to us. */
2069 temp = force_mode (word_mode, temp);
2072 temp = gen_reg_rtx (Pmode);
2074 /* (const (plus (symbol) (const_int))) must be forced to
2075 memory during/after reload if the const_int will not fit
2077 if (GET_CODE (operand1) == CONST
2078 && GET_CODE (XEXP (operand1, 0)) == PLUS
2079 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
2080 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
2081 && (reload_completed || reload_in_progress)
2084 operands[1] = force_const_mem (mode, operand1);
2085 operands[1] = legitimize_pic_address (XEXP (operands[1], 0),
2087 operands[1] = gen_rtx_MEM (mode, operands[1]);
2088 emit_move_sequence (operands, mode, temp);
2092 operands[1] = legitimize_pic_address (operand1, mode, temp);
2093 if (REG_P (operand0) && REG_P (operands[1]))
2094 copy_reg_pointer (operand0, operands[1]);
2095 emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
2098 /* On the HPPA, references to data space are supposed to use dp,
2099 register 27, but showing it in the RTL inhibits various cse
2100 and loop optimizations. */
2105 if (reload_in_progress || reload_completed)
2107 temp = scratch_reg ? scratch_reg : operand0;
2108 /* TEMP will hold an address and maybe the actual
2109 data. We want it in WORD_MODE regardless of what mode it
2110 was originally given to us. */
2111 temp = force_mode (word_mode, temp);
2114 temp = gen_reg_rtx (mode);
2116 /* Loading a SYMBOL_REF into a register makes that register
2117 safe to be used as the base in an indexed address.
2119 Don't mark hard registers though. That loses. */
2120 if (GET_CODE (operand0) == REG
2121 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
2122 mark_reg_pointer (operand0, BITS_PER_UNIT);
2123 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
2124 mark_reg_pointer (temp, BITS_PER_UNIT);
2127 set = gen_rtx_SET (mode, operand0, temp);
2129 set = gen_rtx_SET (VOIDmode,
2131 gen_rtx_LO_SUM (mode, temp, operand1));
2133 emit_insn (gen_rtx_SET (VOIDmode,
2135 gen_rtx_HIGH (mode, operand1)));
2141 else if (GET_CODE (operand1) != CONST_INT
2142 || !cint_ok_for_move (INTVAL (operand1)))
2146 HOST_WIDE_INT value = 0;
2147 HOST_WIDE_INT insv = 0;
2150 if (GET_CODE (operand1) == CONST_INT)
2151 value = INTVAL (operand1);
2154 && GET_CODE (operand1) == CONST_INT
2155 && HOST_BITS_PER_WIDE_INT > 32
2156 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
2160 /* Extract the low order 32 bits of the value and sign extend.
2161 If the new value is the same as the original value, we can
2162 can use the original value as-is. If the new value is
2163 different, we use it and insert the most-significant 32-bits
2164 of the original value into the final result. */
2165 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
2166 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
2169 #if HOST_BITS_PER_WIDE_INT > 32
2170 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
2174 operand1 = GEN_INT (nval);
2178 if (reload_in_progress || reload_completed)
2179 temp = scratch_reg ? scratch_reg : operand0;
2181 temp = gen_reg_rtx (mode);
2183 /* We don't directly split DImode constants on 32-bit targets
2184 because PLUS uses an 11-bit immediate and the insn sequence
2185 generated is not as efficient as the one using HIGH/LO_SUM. */
2186 if (GET_CODE (operand1) == CONST_INT
2187 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2190 /* Directly break constant into high and low parts. This
2191 provides better optimization opportunities because various
2192 passes recognize constants split with PLUS but not LO_SUM.
2193 We use a 14-bit signed low part except when the addition
2194 of 0x4000 to the high part might change the sign of the
2196 HOST_WIDE_INT low = value & 0x3fff;
2197 HOST_WIDE_INT high = value & ~ 0x3fff;
2201 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
2209 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
2210 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2214 emit_insn (gen_rtx_SET (VOIDmode, temp,
2215 gen_rtx_HIGH (mode, operand1)));
2216 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
2219 insn = emit_move_insn (operands[0], operands[1]);
2221 /* Now insert the most significant 32 bits of the value
2222 into the register. When we don't have a second register
2223 available, it could take up to nine instructions to load
2224 a 64-bit integer constant. Prior to reload, we force
2225 constants that would take more than three instructions
2226 to load to the constant pool. During and after reload,
2227 we have to handle all possible values. */
2230 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
2231 register and the value to be inserted is outside the
2232 range that can be loaded with three depdi instructions. */
2233 if (temp != operand0 && (insv >= 16384 || insv < -16384))
2235 operand1 = GEN_INT (insv);
2237 emit_insn (gen_rtx_SET (VOIDmode, temp,
2238 gen_rtx_HIGH (mode, operand1)));
2239 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
2240 emit_insn (gen_insv (operand0, GEN_INT (32),
2245 int len = 5, pos = 27;
2247 /* Insert the bits using the depdi instruction. */
2250 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2251 HOST_WIDE_INT sign = v5 < 0;
2253 /* Left extend the insertion. */
2254 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2255 while (pos > 0 && (insv & 1) == sign)
2257 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2262 emit_insn (gen_insv (operand0, GEN_INT (len),
2263 GEN_INT (pos), GEN_INT (v5)));
2265 len = pos > 0 && pos < 5 ? pos : 5;
2272 = gen_rtx_EXPR_LIST (REG_EQUAL, op1, REG_NOTES (insn));
2277 /* Now have insn-emit do whatever it normally does. */
2281 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2282 it will need a link/runtime reloc). */
2285 reloc_needed (tree exp)
2289 switch (TREE_CODE (exp))
2296 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2297 reloc |= reloc_needed (TREE_OPERAND (exp, 1));
2302 case NON_LVALUE_EXPR:
2303 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2309 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2310 if (TREE_VALUE (link) != 0)
2311 reloc |= reloc_needed (TREE_VALUE (link));
2324 /* Does operand (which is a symbolic_operand) live in text space?
2325 If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2329 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2331 if (GET_CODE (operand) == CONST)
2332 operand = XEXP (XEXP (operand, 0), 0);
2335 if (GET_CODE (operand) == SYMBOL_REF)
2336 return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2340 if (GET_CODE (operand) == SYMBOL_REF)
2341 return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2347 /* Return the best assembler insn template
2348 for moving operands[1] into operands[0] as a fullword. */
2350 singlemove_string (rtx *operands)
2352 HOST_WIDE_INT intval;
2354 if (GET_CODE (operands[0]) == MEM)
2355 return "stw %r1,%0";
2356 if (GET_CODE (operands[1]) == MEM)
2358 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2363 if (GET_MODE (operands[1]) != SFmode)
2366 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2368 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2369 REAL_VALUE_TO_TARGET_SINGLE (d, i);
2371 operands[1] = GEN_INT (i);
2372 /* Fall through to CONST_INT case. */
2374 if (GET_CODE (operands[1]) == CONST_INT)
2376 intval = INTVAL (operands[1]);
2378 if (VAL_14_BITS_P (intval))
2380 else if ((intval & 0x7ff) == 0)
2381 return "ldil L'%1,%0";
2382 else if (zdepi_cint_p (intval))
2383 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2385 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2387 return "copy %1,%0";
2391 /* Compute position (in OP[1]) and width (in OP[2])
2392 useful for copying IMM to a register using the zdepi
2393 instructions. Store the immediate value to insert in OP[0]. */
2395 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2399 /* Find the least significant set bit in IMM. */
2400 for (lsb = 0; lsb < 32; lsb++)
2407 /* Choose variants based on *sign* of the 5-bit field. */
2408 if ((imm & 0x10) == 0)
2409 len = (lsb <= 28) ? 4 : 32 - lsb;
2412 /* Find the width of the bitstring in IMM. */
2413 for (len = 5; len < 32; len++)
2415 if ((imm & (1 << len)) == 0)
2419 /* Sign extend IMM as a 5-bit value. */
2420 imm = (imm & 0xf) - 0x10;
2428 /* Compute position (in OP[1]) and width (in OP[2])
2429 useful for copying IMM to a register using the depdi,z
2430 instructions. Store the immediate value to insert in OP[0]. */
2432 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2434 HOST_WIDE_INT lsb, len;
2436 /* Find the least significant set bit in IMM. */
2437 for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
2444 /* Choose variants based on *sign* of the 5-bit field. */
2445 if ((imm & 0x10) == 0)
2446 len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
2447 ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
2450 /* Find the width of the bitstring in IMM. */
2451 for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
2453 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2457 /* Sign extend IMM as a 5-bit value. */
2458 imm = (imm & 0xf) - 0x10;
2466 /* Output assembler code to perform a doubleword move insn
2467 with operands OPERANDS. */
2470 output_move_double (rtx *operands)
2472 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2474 rtx addreg0 = 0, addreg1 = 0;
2476 /* First classify both operands. */
2478 if (REG_P (operands[0]))
2480 else if (offsettable_memref_p (operands[0]))
2482 else if (GET_CODE (operands[0]) == MEM)
2487 if (REG_P (operands[1]))
2489 else if (CONSTANT_P (operands[1]))
2491 else if (offsettable_memref_p (operands[1]))
2493 else if (GET_CODE (operands[1]) == MEM)
2498 /* Check for the cases that the operand constraints are not
2499 supposed to allow to happen. Abort if we get one,
2500 because generating code for these cases is painful. */
2502 if (optype0 != REGOP && optype1 != REGOP)
2505 /* Handle auto decrementing and incrementing loads and stores
2506 specifically, since the structure of the function doesn't work
2507 for them without major modification. Do it better when we learn
2508 this port about the general inc/dec addressing of PA.
2509 (This was written by tege. Chide him if it doesn't work.) */
2511 if (optype0 == MEMOP)
2513 /* We have to output the address syntax ourselves, since print_operand
2514 doesn't deal with the addresses we want to use. Fix this later. */
2516 rtx addr = XEXP (operands[0], 0);
2517 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2519 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2521 operands[0] = XEXP (addr, 0);
2522 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2525 if (!reg_overlap_mentioned_p (high_reg, addr))
2527 /* No overlap between high target register and address
2528 register. (We do this in a non-obvious way to
2529 save a register file writeback) */
2530 if (GET_CODE (addr) == POST_INC)
2531 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2532 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2537 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2539 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2541 operands[0] = XEXP (addr, 0);
2542 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2545 if (!reg_overlap_mentioned_p (high_reg, addr))
2547 /* No overlap between high target register and address
2548 register. (We do this in a non-obvious way to
2549 save a register file writeback) */
2550 if (GET_CODE (addr) == PRE_INC)
2551 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2552 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2558 if (optype1 == MEMOP)
2560 /* We have to output the address syntax ourselves, since print_operand
2561 doesn't deal with the addresses we want to use. Fix this later. */
2563 rtx addr = XEXP (operands[1], 0);
2564 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2566 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2568 operands[1] = XEXP (addr, 0);
2569 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2572 if (!reg_overlap_mentioned_p (high_reg, addr))
2574 /* No overlap between high target register and address
2575 register. (We do this in a non-obvious way to
2576 save a register file writeback) */
2577 if (GET_CODE (addr) == POST_INC)
2578 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2579 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2583 /* This is an undefined situation. We should load into the
2584 address register *and* update that register. Probably
2585 we don't need to handle this at all. */
2586 if (GET_CODE (addr) == POST_INC)
2587 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2588 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2591 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2593 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2595 operands[1] = XEXP (addr, 0);
2596 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2599 if (!reg_overlap_mentioned_p (high_reg, addr))
2601 /* No overlap between high target register and address
2602 register. (We do this in a non-obvious way to
2603 save a register file writeback) */
2604 if (GET_CODE (addr) == PRE_INC)
2605 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2606 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2610 /* This is an undefined situation. We should load into the
2611 address register *and* update that register. Probably
2612 we don't need to handle this at all. */
2613 if (GET_CODE (addr) == PRE_INC)
2614 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2615 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2618 else if (GET_CODE (addr) == PLUS
2619 && GET_CODE (XEXP (addr, 0)) == MULT)
2621 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2623 if (!reg_overlap_mentioned_p (high_reg, addr))
2627 xoperands[0] = high_reg;
2628 xoperands[1] = XEXP (addr, 1);
2629 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2630 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2631 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2633 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2639 xoperands[0] = high_reg;
2640 xoperands[1] = XEXP (addr, 1);
2641 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2642 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2643 output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2645 return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2650 /* If an operand is an unoffsettable memory ref, find a register
2651 we can increment temporarily to make it refer to the second word. */
2653 if (optype0 == MEMOP)
2654 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2656 if (optype1 == MEMOP)
2657 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2659 /* Ok, we can do one word at a time.
2660 Normally we do the low-numbered word first.
2662 In either case, set up in LATEHALF the operands to use
2663 for the high-numbered word and in some cases alter the
2664 operands in OPERANDS to be suitable for the low-numbered word. */
2666 if (optype0 == REGOP)
2667 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2668 else if (optype0 == OFFSOP)
2669 latehalf[0] = adjust_address (operands[0], SImode, 4);
2671 latehalf[0] = operands[0];
2673 if (optype1 == REGOP)
2674 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2675 else if (optype1 == OFFSOP)
2676 latehalf[1] = adjust_address (operands[1], SImode, 4);
2677 else if (optype1 == CNSTOP)
2678 split_double (operands[1], &operands[1], &latehalf[1]);
2680 latehalf[1] = operands[1];
2682 /* If the first move would clobber the source of the second one,
2683 do them in the other order.
2685 This can happen in two cases:
2687 mem -> register where the first half of the destination register
2688 is the same register used in the memory's address. Reload
2689 can create such insns.
2691 mem in this case will be either register indirect or register
2692 indirect plus a valid offset.
2694 register -> register move where REGNO(dst) == REGNO(src + 1)
2695 someone (Tim/Tege?) claimed this can happen for parameter loads.
2697 Handle mem -> register case first. */
2698 if (optype0 == REGOP
2699 && (optype1 == MEMOP || optype1 == OFFSOP)
2700 && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2703 /* Do the late half first. */
2705 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2706 output_asm_insn (singlemove_string (latehalf), latehalf);
2710 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2711 return singlemove_string (operands);
2714 /* Now handle register -> register case. */
2715 if (optype0 == REGOP && optype1 == REGOP
2716 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2718 output_asm_insn (singlemove_string (latehalf), latehalf);
2719 return singlemove_string (operands);
2722 /* Normal case: do the two words, low-numbered first. */
2724 output_asm_insn (singlemove_string (operands), operands);
2726 /* Make any unoffsettable addresses point at high-numbered word. */
2728 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2730 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2733 output_asm_insn (singlemove_string (latehalf), latehalf);
2735 /* Undo the adds we just did. */
2737 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2739 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2745 output_fp_move_double (rtx *operands)
2747 if (FP_REG_P (operands[0]))
2749 if (FP_REG_P (operands[1])
2750 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2751 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2753 output_asm_insn ("fldd%F1 %1,%0", operands);
2755 else if (FP_REG_P (operands[1]))
2757 output_asm_insn ("fstd%F0 %1,%0", operands);
2759 else if (operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2761 if (GET_CODE (operands[0]) == REG)
2764 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2765 xoperands[0] = operands[0];
2766 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2768 /* This is a pain. You have to be prepared to deal with an
2769 arbitrary address here including pre/post increment/decrement.
2771 so avoid this in the MD. */
2779 /* Return a REG that occurs in ADDR with coefficient 1.
2780 ADDR can be effectively incremented by incrementing REG. */
2783 find_addr_reg (rtx addr)
2785 while (GET_CODE (addr) == PLUS)
2787 if (GET_CODE (XEXP (addr, 0)) == REG)
2788 addr = XEXP (addr, 0);
2789 else if (GET_CODE (XEXP (addr, 1)) == REG)
2790 addr = XEXP (addr, 1);
2791 else if (CONSTANT_P (XEXP (addr, 0)))
2792 addr = XEXP (addr, 1);
2793 else if (CONSTANT_P (XEXP (addr, 1)))
2794 addr = XEXP (addr, 0);
2798 if (GET_CODE (addr) == REG)
2803 /* Emit code to perform a block move.
2805 OPERANDS[0] is the destination pointer as a REG, clobbered.
2806 OPERANDS[1] is the source pointer as a REG, clobbered.
2807 OPERANDS[2] is a register for temporary storage.
2808 OPERANDS[3] is a register for temporary storage.
2809 OPERANDS[4] is the size as a CONST_INT
2810 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2811 OPERANDS[6] is another temporary register. */
2814 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2816 int align = INTVAL (operands[5]);
2817 unsigned long n_bytes = INTVAL (operands[4]);
2819 /* We can't move more than a word at a time because the PA
2820 has no longer integer move insns. (Could use fp mem ops?) */
2821 if (align > (TARGET_64BIT ? 8 : 4))
2822 align = (TARGET_64BIT ? 8 : 4);
2824 /* Note that we know each loop below will execute at least twice
2825 (else we would have open-coded the copy). */
2829 /* Pre-adjust the loop counter. */
2830 operands[4] = GEN_INT (n_bytes - 16);
2831 output_asm_insn ("ldi %4,%2", operands);
2834 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2835 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2836 output_asm_insn ("std,ma %3,8(%0)", operands);
2837 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2838 output_asm_insn ("std,ma %6,8(%0)", operands);
2840 /* Handle the residual. There could be up to 7 bytes of
2841 residual to copy! */
2842 if (n_bytes % 16 != 0)
2844 operands[4] = GEN_INT (n_bytes % 8);
2845 if (n_bytes % 16 >= 8)
2846 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2847 if (n_bytes % 8 != 0)
2848 output_asm_insn ("ldd 0(%1),%6", operands);
2849 if (n_bytes % 16 >= 8)
2850 output_asm_insn ("std,ma %3,8(%0)", operands);
2851 if (n_bytes % 8 != 0)
2852 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2857 /* Pre-adjust the loop counter. */
2858 operands[4] = GEN_INT (n_bytes - 8);
2859 output_asm_insn ("ldi %4,%2", operands);
2862 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2863 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2864 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2865 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2866 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2868 /* Handle the residual. There could be up to 7 bytes of
2869 residual to copy! */
2870 if (n_bytes % 8 != 0)
2872 operands[4] = GEN_INT (n_bytes % 4);
2873 if (n_bytes % 8 >= 4)
2874 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2875 if (n_bytes % 4 != 0)
2876 output_asm_insn ("ldw 0(%1),%6", operands);
2877 if (n_bytes % 8 >= 4)
2878 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2879 if (n_bytes % 4 != 0)
2880 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2885 /* Pre-adjust the loop counter. */
2886 operands[4] = GEN_INT (n_bytes - 4);
2887 output_asm_insn ("ldi %4,%2", operands);
2890 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2891 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2892 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2893 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2894 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2896 /* Handle the residual. */
2897 if (n_bytes % 4 != 0)
2899 if (n_bytes % 4 >= 2)
2900 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2901 if (n_bytes % 2 != 0)
2902 output_asm_insn ("ldb 0(%1),%6", operands);
2903 if (n_bytes % 4 >= 2)
2904 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2905 if (n_bytes % 2 != 0)
2906 output_asm_insn ("stb %6,0(%0)", operands);
2911 /* Pre-adjust the loop counter. */
2912 operands[4] = GEN_INT (n_bytes - 2);
2913 output_asm_insn ("ldi %4,%2", operands);
2916 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2917 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2918 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2919 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2920 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2922 /* Handle the residual. */
2923 if (n_bytes % 2 != 0)
2925 output_asm_insn ("ldb 0(%1),%3", operands);
2926 output_asm_insn ("stb %3,0(%0)", operands);
2935 /* Count the number of insns necessary to handle this block move.
2937 Basic structure is the same as emit_block_move, except that we
2938 count insns rather than emit them. */
2941 compute_movmem_length (rtx insn)
2943 rtx pat = PATTERN (insn);
2944 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2945 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2946 unsigned int n_insns = 0;
2948 /* We can't move more than four bytes at a time because the PA
2949 has no longer integer move insns. (Could use fp mem ops?) */
2950 if (align > (TARGET_64BIT ? 8 : 4))
2951 align = (TARGET_64BIT ? 8 : 4);
2953 /* The basic copying loop. */
2957 if (n_bytes % (2 * align) != 0)
2959 if ((n_bytes % (2 * align)) >= align)
2962 if ((n_bytes % align) != 0)
2966 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2970 /* Emit code to perform a block clear.
2972 OPERANDS[0] is the destination pointer as a REG, clobbered.
2973 OPERANDS[1] is a register for temporary storage.
2974 OPERANDS[2] is the size as a CONST_INT
2975 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
2978 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2980 int align = INTVAL (operands[3]);
2981 unsigned long n_bytes = INTVAL (operands[2]);
2983 /* We can't clear more than a word at a time because the PA
2984 has no longer integer move insns. */
2985 if (align > (TARGET_64BIT ? 8 : 4))
2986 align = (TARGET_64BIT ? 8 : 4);
2988 /* Note that we know each loop below will execute at least twice
2989 (else we would have open-coded the copy). */
2993 /* Pre-adjust the loop counter. */
2994 operands[2] = GEN_INT (n_bytes - 16);
2995 output_asm_insn ("ldi %2,%1", operands);
2998 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2999 output_asm_insn ("addib,>= -16,%1,.-4", operands);
3000 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3002 /* Handle the residual. There could be up to 7 bytes of
3003 residual to copy! */
3004 if (n_bytes % 16 != 0)
3006 operands[2] = GEN_INT (n_bytes % 8);
3007 if (n_bytes % 16 >= 8)
3008 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3009 if (n_bytes % 8 != 0)
3010 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
3015 /* Pre-adjust the loop counter. */
3016 operands[2] = GEN_INT (n_bytes - 8);
3017 output_asm_insn ("ldi %2,%1", operands);
3020 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3021 output_asm_insn ("addib,>= -8,%1,.-4", operands);
3022 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3024 /* Handle the residual. There could be up to 7 bytes of
3025 residual to copy! */
3026 if (n_bytes % 8 != 0)
3028 operands[2] = GEN_INT (n_bytes % 4);
3029 if (n_bytes % 8 >= 4)
3030 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3031 if (n_bytes % 4 != 0)
3032 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
3037 /* Pre-adjust the loop counter. */
3038 operands[2] = GEN_INT (n_bytes - 4);
3039 output_asm_insn ("ldi %2,%1", operands);
3042 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3043 output_asm_insn ("addib,>= -4,%1,.-4", operands);
3044 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3046 /* Handle the residual. */
3047 if (n_bytes % 4 != 0)
3049 if (n_bytes % 4 >= 2)
3050 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3051 if (n_bytes % 2 != 0)
3052 output_asm_insn ("stb %%r0,0(%0)", operands);
3057 /* Pre-adjust the loop counter. */
3058 operands[2] = GEN_INT (n_bytes - 2);
3059 output_asm_insn ("ldi %2,%1", operands);
3062 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3063 output_asm_insn ("addib,>= -2,%1,.-4", operands);
3064 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3066 /* Handle the residual. */
3067 if (n_bytes % 2 != 0)
3068 output_asm_insn ("stb %%r0,0(%0)", operands);
3077 /* Count the number of insns necessary to handle this block move.
3079 Basic structure is the same as emit_block_move, except that we
3080 count insns rather than emit them. */
3083 compute_clrmem_length (rtx insn)
3085 rtx pat = PATTERN (insn);
3086 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
3087 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
3088 unsigned int n_insns = 0;
3090 /* We can't clear more than a word at a time because the PA
3091 has no longer integer move insns. */
3092 if (align > (TARGET_64BIT ? 8 : 4))
3093 align = (TARGET_64BIT ? 8 : 4);
3095 /* The basic loop. */
3099 if (n_bytes % (2 * align) != 0)
3101 if ((n_bytes % (2 * align)) >= align)
3104 if ((n_bytes % align) != 0)
3108 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3114 output_and (rtx *operands)
3116 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3118 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3119 int ls0, ls1, ms0, p, len;
3121 for (ls0 = 0; ls0 < 32; ls0++)
3122 if ((mask & (1 << ls0)) == 0)
3125 for (ls1 = ls0; ls1 < 32; ls1++)
3126 if ((mask & (1 << ls1)) != 0)
3129 for (ms0 = ls1; ms0 < 32; ms0++)
3130 if ((mask & (1 << ms0)) == 0)
3143 operands[2] = GEN_INT (len);
3144 return "{extru|extrw,u} %1,31,%2,%0";
3148 /* We could use this `depi' for the case above as well, but `depi'
3149 requires one more register file access than an `extru'. */
3154 operands[2] = GEN_INT (p);
3155 operands[3] = GEN_INT (len);
3156 return "{depi|depwi} 0,%2,%3,%0";
3160 return "and %1,%2,%0";
3163 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3164 storing the result in operands[0]. */
3166 output_64bit_and (rtx *operands)
3168 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3170 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3171 int ls0, ls1, ms0, p, len;
3173 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
3174 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
3177 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
3178 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
3181 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
3182 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
3185 if (ms0 != HOST_BITS_PER_WIDE_INT)
3188 if (ls1 == HOST_BITS_PER_WIDE_INT)
3195 operands[2] = GEN_INT (len);
3196 return "extrd,u %1,63,%2,%0";
3200 /* We could use this `depi' for the case above as well, but `depi'
3201 requires one more register file access than an `extru'. */
3206 operands[2] = GEN_INT (p);
3207 operands[3] = GEN_INT (len);
3208 return "depdi 0,%2,%3,%0";
3212 return "and %1,%2,%0";
3216 output_ior (rtx *operands)
3218 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3219 int bs0, bs1, p, len;
3221 if (INTVAL (operands[2]) == 0)
3222 return "copy %1,%0";
3224 for (bs0 = 0; bs0 < 32; bs0++)
3225 if ((mask & (1 << bs0)) != 0)
3228 for (bs1 = bs0; bs1 < 32; bs1++)
3229 if ((mask & (1 << bs1)) == 0)
3232 if (bs1 != 32 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3238 operands[2] = GEN_INT (p);
3239 operands[3] = GEN_INT (len);
3240 return "{depi|depwi} -1,%2,%3,%0";
3243 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3244 storing the result in operands[0]. */
3246 output_64bit_ior (rtx *operands)
3248 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3249 int bs0, bs1, p, len;
3251 if (INTVAL (operands[2]) == 0)
3252 return "copy %1,%0";
3254 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3255 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3258 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3259 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3262 if (bs1 != HOST_BITS_PER_WIDE_INT
3263 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3269 operands[2] = GEN_INT (p);
3270 operands[3] = GEN_INT (len);
3271 return "depdi -1,%2,%3,%0";
3274 /* Target hook for assembling integer objects. This code handles
3275 aligned SI and DI integers specially, since function references must
3276 be preceded by P%. */
3279 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3281 if (size == UNITS_PER_WORD && aligned_p
3282 && function_label_operand (x, VOIDmode))
3284 fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
3285 output_addr_const (asm_out_file, x);
3286 fputc ('\n', asm_out_file);
3289 return default_assemble_integer (x, size, aligned_p);
3292 /* Output an ascii string. */
3294 output_ascii (FILE *file, const char *p, int size)
3298 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3300 /* The HP assembler can only take strings of 256 characters at one
3301 time. This is a limitation on input line length, *not* the
3302 length of the string. Sigh. Even worse, it seems that the
3303 restriction is in number of input characters (see \xnn &
3304 \whatever). So we have to do this very carefully. */
3306 fputs ("\t.STRING \"", file);
3309 for (i = 0; i < size; i += 4)
3313 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3315 register unsigned int c = (unsigned char) p[i + io];
3317 if (c == '\"' || c == '\\')
3318 partial_output[co++] = '\\';
3319 if (c >= ' ' && c < 0177)
3320 partial_output[co++] = c;
3324 partial_output[co++] = '\\';
3325 partial_output[co++] = 'x';
3326 hexd = c / 16 - 0 + '0';
3328 hexd -= '9' - 'a' + 1;
3329 partial_output[co++] = hexd;
3330 hexd = c % 16 - 0 + '0';
3332 hexd -= '9' - 'a' + 1;
3333 partial_output[co++] = hexd;
3336 if (chars_output + co > 243)
3338 fputs ("\"\n\t.STRING \"", file);
3341 fwrite (partial_output, 1, (size_t) co, file);
3345 fputs ("\"\n", file);
3348 /* Try to rewrite floating point comparisons & branches to avoid
3349 useless add,tr insns.
3351 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3352 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3353 first attempt to remove useless add,tr insns. It is zero
3354 for the second pass as reorg sometimes leaves bogus REG_DEAD
3357 When CHECK_NOTES is zero we can only eliminate add,tr insns
3358 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3361 remove_useless_addtr_insns (int check_notes)
3364 static int pass = 0;
3366 /* This is fairly cheap, so always run it when optimizing. */
3370 int fbranch_count = 0;
3372 /* Walk all the insns in this function looking for fcmp & fbranch
3373 instructions. Keep track of how many of each we find. */
3374 for (insn = get_insns (); insn; insn = next_insn (insn))
3378 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3379 if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3382 tmp = PATTERN (insn);
3384 /* It must be a set. */
3385 if (GET_CODE (tmp) != SET)
3388 /* If the destination is CCFP, then we've found an fcmp insn. */
3389 tmp = SET_DEST (tmp);
3390 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3396 tmp = PATTERN (insn);
3397 /* If this is an fbranch instruction, bump the fbranch counter. */
3398 if (GET_CODE (tmp) == SET
3399 && SET_DEST (tmp) == pc_rtx
3400 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3401 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3402 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3403 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3411 /* Find all floating point compare + branch insns. If possible,
3412 reverse the comparison & the branch to avoid add,tr insns. */
3413 for (insn = get_insns (); insn; insn = next_insn (insn))
3417 /* Ignore anything that isn't an INSN. */
3418 if (GET_CODE (insn) != INSN)
3421 tmp = PATTERN (insn);
3423 /* It must be a set. */
3424 if (GET_CODE (tmp) != SET)
3427 /* The destination must be CCFP, which is register zero. */
3428 tmp = SET_DEST (tmp);
3429 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3432 /* INSN should be a set of CCFP.
3434 See if the result of this insn is used in a reversed FP
3435 conditional branch. If so, reverse our condition and
3436 the branch. Doing so avoids useless add,tr insns. */
3437 next = next_insn (insn);
3440 /* Jumps, calls and labels stop our search. */
3441 if (GET_CODE (next) == JUMP_INSN
3442 || GET_CODE (next) == CALL_INSN
3443 || GET_CODE (next) == CODE_LABEL)
3446 /* As does another fcmp insn. */
3447 if (GET_CODE (next) == INSN
3448 && GET_CODE (PATTERN (next)) == SET
3449 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3450 && REGNO (SET_DEST (PATTERN (next))) == 0)
3453 next = next_insn (next);
3456 /* Is NEXT_INSN a branch? */
3458 && GET_CODE (next) == JUMP_INSN)
3460 rtx pattern = PATTERN (next);
3462 /* If it a reversed fp conditional branch (eg uses add,tr)
3463 and CCFP dies, then reverse our conditional and the branch
3464 to avoid the add,tr. */
3465 if (GET_CODE (pattern) == SET
3466 && SET_DEST (pattern) == pc_rtx
3467 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3468 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3469 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3470 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3471 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3472 && (fcmp_count == fbranch_count
3474 && find_regno_note (next, REG_DEAD, 0))))
3476 /* Reverse the branch. */
3477 tmp = XEXP (SET_SRC (pattern), 1);
3478 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3479 XEXP (SET_SRC (pattern), 2) = tmp;
3480 INSN_CODE (next) = -1;
3482 /* Reverse our condition. */
3483 tmp = PATTERN (insn);
3484 PUT_CODE (XEXP (tmp, 1),
3485 (reverse_condition_maybe_unordered
3486 (GET_CODE (XEXP (tmp, 1)))));
3496 /* You may have trouble believing this, but this is the 32 bit HP-PA
3501 Variable arguments (optional; any number may be allocated)
3503 SP-(4*(N+9)) arg word N
3508 Fixed arguments (must be allocated; may remain unused)
3517 SP-32 External Data Pointer (DP)
3519 SP-24 External/stub RP (RP')
3523 SP-8 Calling Stub RP (RP'')
3528 SP-0 Stack Pointer (points to next available address)
3532 /* This function saves registers as follows. Registers marked with ' are
3533 this function's registers (as opposed to the previous function's).
3534 If a frame_pointer isn't needed, r4 is saved as a general register;
3535 the space for the frame pointer is still allocated, though, to keep
3541 SP (FP') Previous FP
3542 SP + 4 Alignment filler (sigh)
3543 SP + 8 Space for locals reserved here.
3547 SP + n All call saved register used.
3551 SP + o All call saved fp registers used.
3555 SP + p (SP') points to next available address.
3559 /* Global variables set by output_function_prologue(). */
3560 /* Size of frame. Need to know this to emit return insns from
3562 static HOST_WIDE_INT actual_fsize, local_fsize;
3563 static int save_fregs;
3565 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3566 Handle case where DISP > 8k by using the add_high_const patterns.
3568 Note in DISP > 8k case, we will leave the high part of the address
3569 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3572 store_reg (int reg, HOST_WIDE_INT disp, int base)
3574 rtx insn, dest, src, basereg;
3576 src = gen_rtx_REG (word_mode, reg);
3577 basereg = gen_rtx_REG (Pmode, base);
3578 if (VAL_14_BITS_P (disp))
3580 dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3581 insn = emit_move_insn (dest, src);
3583 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3585 rtx delta = GEN_INT (disp);
3586 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3588 emit_move_insn (tmpreg, delta);
3589 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3590 dest = gen_rtx_MEM (word_mode, tmpreg);
3591 insn = emit_move_insn (dest, src);
3595 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3596 gen_rtx_SET (VOIDmode,
3597 gen_rtx_MEM (word_mode,
3598 gen_rtx_PLUS (word_mode, basereg,
3606 rtx delta = GEN_INT (disp);
3607 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3608 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3610 emit_move_insn (tmpreg, high);
3611 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3612 insn = emit_move_insn (dest, src);
3616 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3617 gen_rtx_SET (VOIDmode,
3618 gen_rtx_MEM (word_mode,
3619 gen_rtx_PLUS (word_mode, basereg,
3627 RTX_FRAME_RELATED_P (insn) = 1;
3630 /* Emit RTL to store REG at the memory location specified by BASE and then
3631 add MOD to BASE. MOD must be <= 8k. */
3634 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3636 rtx insn, basereg, srcreg, delta;
3638 if (!VAL_14_BITS_P (mod))
3641 basereg = gen_rtx_REG (Pmode, base);
3642 srcreg = gen_rtx_REG (word_mode, reg);
3643 delta = GEN_INT (mod);
3645 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3648 RTX_FRAME_RELATED_P (insn) = 1;
3650 /* RTX_FRAME_RELATED_P must be set on each frame related set
3651 in a parallel with more than one element. Don't set
3652 RTX_FRAME_RELATED_P in the first set if reg is temporary
3653 register 1. The effect of this operation is recorded in
3654 the initial copy. */
3657 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3658 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3662 /* The first element of a PARALLEL is always processed if it is
3663 a SET. Thus, we need an expression list for this case. */
3665 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3666 gen_rtx_SET (VOIDmode, basereg,
3667 gen_rtx_PLUS (word_mode, basereg, delta)),
3673 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
3674 where DISP > 8k by using the add_high_const patterns. NOTE indicates
3675 whether to add a frame note or not.
3677 In the DISP > 8k case, we leave the high part of the address in %r1.
3678 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
3681 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3685 if (VAL_14_BITS_P (disp))
3687 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3688 plus_constant (gen_rtx_REG (Pmode, base), disp));
3690 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3692 rtx basereg = gen_rtx_REG (Pmode, base);
3693 rtx delta = GEN_INT (disp);
3694 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3696 emit_move_insn (tmpreg, delta);
3697 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3698 gen_rtx_PLUS (Pmode, tmpreg, basereg));
3702 rtx basereg = gen_rtx_REG (Pmode, base);
3703 rtx delta = GEN_INT (disp);
3704 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3706 emit_move_insn (tmpreg,
3707 gen_rtx_PLUS (Pmode, basereg,
3708 gen_rtx_HIGH (Pmode, delta)));
3709 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3710 gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3713 if (DO_FRAME_NOTES && note)
3714 RTX_FRAME_RELATED_P (insn) = 1;
3718 compute_frame_size (HOST_WIDE_INT size, int *fregs_live)
3723 /* The code in hppa_expand_prologue and hppa_expand_epilogue must
3724 be consistent with the rounding and size calculation done here.
3725 Change them at the same time. */
3727 /* We do our own stack alignment. First, round the size of the
3728 stack locals up to a word boundary. */
3729 size = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3731 /* Space for previous frame pointer + filler. If any frame is
3732 allocated, we need to add in the STARTING_FRAME_OFFSET. We
3733 waste some space here for the sake of HP compatibility. The
3734 first slot is only used when the frame pointer is needed. */
3735 if (size || frame_pointer_needed)
3736 size += STARTING_FRAME_OFFSET;
3738 /* If the current function calls __builtin_eh_return, then we need
3739 to allocate stack space for registers that will hold data for
3740 the exception handler. */
3741 if (DO_FRAME_NOTES && current_function_calls_eh_return)
3745 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
3747 size += i * UNITS_PER_WORD;
3750 /* Account for space used by the callee general register saves. */
3751 for (i = 18, j = frame_pointer_needed ? 4 : 3; i >= j; i--)
3752 if (regs_ever_live[i])
3753 size += UNITS_PER_WORD;
3755 /* Account for space used by the callee floating point register saves. */
3756 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3757 if (regs_ever_live[i]
3758 || (!TARGET_64BIT && regs_ever_live[i + 1]))
3762 /* We always save both halves of the FP register, so always
3763 increment the frame size by 8 bytes. */
3767 /* If any of the floating registers are saved, account for the
3768 alignment needed for the floating point register save block. */
3771 size = (size + 7) & ~7;
3776 /* The various ABIs include space for the outgoing parameters in the
3777 size of the current function's stack frame. We don't need to align
3778 for the outgoing arguments as their alignment is set by the final
3779 rounding for the frame as a whole. */
3780 size += current_function_outgoing_args_size;
3782 /* Allocate space for the fixed frame marker. This space must be
3783 allocated for any function that makes calls or allocates
3785 if (!current_function_is_leaf || size)
3786 size += TARGET_64BIT ? 48 : 32;
3788 /* Finally, round to the preferred stack boundary. */
3789 return ((size + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)
3790 & ~(PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1));
3793 /* Generate the assembly code for function entry. FILE is a stdio
3794 stream to output the code to. SIZE is an int: how many units of
3795 temporary storage to allocate.
3797 Refer to the array `regs_ever_live' to determine which registers to
3798 save; `regs_ever_live[I]' is nonzero if register number I is ever
3799 used in the function. This function is responsible for knowing
3800 which registers should not be saved even if used. */
3802 /* On HP-PA, move-double insns between fpu and cpu need an 8-byte block
3803 of memory. If any fpu reg is used in the function, we allocate
3804 such a block here, at the bottom of the frame, just in case it's needed.
3806 If this function is a leaf procedure, then we may choose not
3807 to do a "save" insn. The decision about whether or not
3808 to do this is made in regclass.c. */
3811 pa_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3813 /* The function's label and associated .PROC must never be
3814 separated and must be output *after* any profiling declarations
3815 to avoid changing spaces/subspaces within a procedure. */
3816 ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3817 fputs ("\t.PROC\n", file);
3819 /* hppa_expand_prologue does the dirty work now. We just need
3820 to output the assembler directives which denote the start
3822 fprintf (file, "\t.CALLINFO FRAME=" HOST_WIDE_INT_PRINT_DEC, actual_fsize);
3823 if (regs_ever_live[2])
3824 fputs (",CALLS,SAVE_RP", file);
3826 fputs (",NO_CALLS", file);
3828 /* The SAVE_SP flag is used to indicate that register %r3 is stored
3829 at the beginning of the frame and that it is used as the frame
3830 pointer for the frame. We do this because our current frame
3831 layout doesn't conform to that specified in the the HP runtime
3832 documentation and we need a way to indicate to programs such as
3833 GDB where %r3 is saved. The SAVE_SP flag was chosen because it
3834 isn't used by HP compilers but is supported by the assembler.
3835 However, SAVE_SP is supposed to indicate that the previous stack
3836 pointer has been saved in the frame marker. */
3837 if (frame_pointer_needed)
3838 fputs (",SAVE_SP", file);
3840 /* Pass on information about the number of callee register saves
3841 performed in the prologue.
3843 The compiler is supposed to pass the highest register number
3844 saved, the assembler then has to adjust that number before
3845 entering it into the unwind descriptor (to account for any
3846 caller saved registers with lower register numbers than the
3847 first callee saved register). */
3849 fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
3852 fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
3854 fputs ("\n\t.ENTRY\n", file);
3856 remove_useless_addtr_insns (0);
3860 hppa_expand_prologue (void)
3862 int merge_sp_adjust_with_store = 0;
3863 HOST_WIDE_INT size = get_frame_size ();
3864 HOST_WIDE_INT offset;
3872 /* Compute total size for frame pointer, filler, locals and rounding to
3873 the next word boundary. Similar code appears in compute_frame_size
3874 and must be changed in tandem with this code. */
3875 local_fsize = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3876 if (local_fsize || frame_pointer_needed)
3877 local_fsize += STARTING_FRAME_OFFSET;
3879 actual_fsize = compute_frame_size (size, &save_fregs);
3881 /* Compute a few things we will use often. */
3882 tmpreg = gen_rtx_REG (word_mode, 1);
3884 /* Save RP first. The calling conventions manual states RP will
3885 always be stored into the caller's frame at sp - 20 or sp - 16
3886 depending on which ABI is in use. */
3887 if (regs_ever_live[2] || current_function_calls_eh_return)
3888 store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM);
3890 /* Allocate the local frame and set up the frame pointer if needed. */
3891 if (actual_fsize != 0)
3893 if (frame_pointer_needed)
3895 /* Copy the old frame pointer temporarily into %r1. Set up the
3896 new stack pointer, then store away the saved old frame pointer
3897 into the stack at sp and at the same time update the stack
3898 pointer by actual_fsize bytes. Two versions, first
3899 handles small (<8k) frames. The second handles large (>=8k)
3901 insn = emit_move_insn (tmpreg, frame_pointer_rtx);
3904 /* We need to record the frame pointer save here since the
3905 new frame pointer is set in the following insn. */
3906 RTX_FRAME_RELATED_P (insn) = 1;
3908 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3909 gen_rtx_SET (VOIDmode,
3910 gen_rtx_MEM (word_mode, stack_pointer_rtx),
3915 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
3917 RTX_FRAME_RELATED_P (insn) = 1;
3919 if (VAL_14_BITS_P (actual_fsize))
3920 store_reg_modify (STACK_POINTER_REGNUM, 1, actual_fsize);
3923 /* It is incorrect to store the saved frame pointer at *sp,
3924 then increment sp (writes beyond the current stack boundary).
3926 So instead use stwm to store at *sp and post-increment the
3927 stack pointer as an atomic operation. Then increment sp to
3928 finish allocating the new frame. */
3929 HOST_WIDE_INT adjust1 = 8192 - 64;
3930 HOST_WIDE_INT adjust2 = actual_fsize - adjust1;
3932 store_reg_modify (STACK_POINTER_REGNUM, 1, adjust1);
3933 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3937 /* We set SAVE_SP in frames that need a frame pointer. Thus,
3938 we need to store the previous stack pointer (frame pointer)
3939 into the frame marker on targets that use the HP unwind
3940 library. This allows the HP unwind library to be used to
3941 unwind GCC frames. However, we are not fully compatible
3942 with the HP library because our frame layout differs from
3943 that specified in the HP runtime specification.
3945 We don't want a frame note on this instruction as the frame
3946 marker moves during dynamic stack allocation.
3948 This instruction also serves as a blockage to prevent
3949 register spills from being scheduled before the stack
3950 pointer is raised. This is necessary as we store
3951 registers using the frame pointer as a base register,
3952 and the frame pointer is set before sp is raised. */
3953 if (TARGET_HPUX_UNWIND_LIBRARY)
3955 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx,
3956 GEN_INT (TARGET_64BIT ? -8 : -4));
3958 emit_move_insn (gen_rtx_MEM (word_mode, addr),
3962 emit_insn (gen_blockage ());
3964 /* no frame pointer needed. */
3967 /* In some cases we can perform the first callee register save
3968 and allocating the stack frame at the same time. If so, just
3969 make a note of it and defer allocating the frame until saving
3970 the callee registers. */
3971 if (VAL_14_BITS_P (actual_fsize) && local_fsize == 0)
3972 merge_sp_adjust_with_store = 1;
3973 /* Can not optimize. Adjust the stack frame by actual_fsize
3976 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,