1 /* Subroutines for insn-output.c for HPPA.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
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 bool pa_scalar_mode_supported_p (enum machine_mode);
127 static void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
128 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
129 static struct deferred_plabel *get_plabel (const char *)
131 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
132 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
133 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
134 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
135 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
136 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
137 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
138 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
139 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
140 static void output_deferred_plabels (void);
141 #ifdef HPUX_LONG_DOUBLE_LIBRARY
142 static void pa_hpux_init_libfuncs (void);
144 static rtx pa_struct_value_rtx (tree, int);
145 static bool pa_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
147 static int pa_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
149 static struct machine_function * pa_init_machine_status (void);
152 /* Save the operands last given to a compare for use when we
153 generate a scc or bcc insn. */
154 rtx hppa_compare_op0, hppa_compare_op1;
155 enum cmp_type hppa_branch_type;
157 /* Which architecture we are generating code for. */
158 enum architecture_type pa_arch;
160 /* String to hold which architecture we are generating code for. */
161 const char *pa_arch_string;
163 /* String used with the -mfixed-range= option. */
164 const char *pa_fixed_range_string;
166 /* Which cpu we are scheduling for. */
167 enum processor_type pa_cpu;
169 /* String to hold which cpu we are scheduling for. */
170 const char *pa_cpu_string;
172 /* String used with the -munix= option. */
173 const char *pa_unix_string;
175 /* The UNIX standard to use for predefines and linking. */
178 /* Counts for the number of callee-saved general and floating point
179 registers which were saved by the current function's prologue. */
180 static int gr_saved, fr_saved;
182 static rtx find_addr_reg (rtx);
184 /* Keep track of the number of bytes we have output in the CODE subspace
185 during this compilation so we'll know when to emit inline long-calls. */
186 unsigned long total_code_bytes;
188 /* The last address of the previous function plus the number of bytes in
189 associated thunks that have been output. This is used to determine if
190 a thunk can use an IA-relative branch to reach its target function. */
191 static int last_address;
193 /* Variables to handle plabels that we discover are necessary at assembly
194 output time. They are output after the current function. */
195 struct deferred_plabel GTY(())
200 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
202 static size_t n_deferred_plabels = 0;
205 /* Initialize the GCC target structure. */
207 #undef TARGET_ASM_ALIGNED_HI_OP
208 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
209 #undef TARGET_ASM_ALIGNED_SI_OP
210 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
211 #undef TARGET_ASM_ALIGNED_DI_OP
212 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
213 #undef TARGET_ASM_UNALIGNED_HI_OP
214 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
215 #undef TARGET_ASM_UNALIGNED_SI_OP
216 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
217 #undef TARGET_ASM_UNALIGNED_DI_OP
218 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
219 #undef TARGET_ASM_INTEGER
220 #define TARGET_ASM_INTEGER pa_assemble_integer
222 #undef TARGET_ASM_FUNCTION_PROLOGUE
223 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
224 #undef TARGET_ASM_FUNCTION_EPILOGUE
225 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
227 #undef TARGET_SCHED_ADJUST_COST
228 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
229 #undef TARGET_SCHED_ADJUST_PRIORITY
230 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
231 #undef TARGET_SCHED_ISSUE_RATE
232 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
234 #undef TARGET_ENCODE_SECTION_INFO
235 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
236 #undef TARGET_STRIP_NAME_ENCODING
237 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
239 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
240 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
242 #undef TARGET_ASM_OUTPUT_MI_THUNK
243 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
244 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
245 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
247 #undef TARGET_ASM_FILE_END
248 #define TARGET_ASM_FILE_END output_deferred_plabels
250 #if !defined(USE_COLLECT2)
251 #undef TARGET_ASM_CONSTRUCTOR
252 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
253 #undef TARGET_ASM_DESTRUCTOR
254 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
257 #undef TARGET_INIT_BUILTINS
258 #define TARGET_INIT_BUILTINS pa_init_builtins
260 #undef TARGET_RTX_COSTS
261 #define TARGET_RTX_COSTS hppa_rtx_costs
262 #undef TARGET_ADDRESS_COST
263 #define TARGET_ADDRESS_COST hppa_address_cost
265 #undef TARGET_MACHINE_DEPENDENT_REORG
266 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
268 #ifdef HPUX_LONG_DOUBLE_LIBRARY
269 #undef TARGET_INIT_LIBFUNCS
270 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
273 #undef TARGET_PROMOTE_FUNCTION_RETURN
274 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
275 #undef TARGET_PROMOTE_PROTOTYPES
276 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
278 #undef TARGET_STRUCT_VALUE_RTX
279 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
280 #undef TARGET_RETURN_IN_MEMORY
281 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
282 #undef TARGET_MUST_PASS_IN_STACK
283 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
284 #undef TARGET_PASS_BY_REFERENCE
285 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
286 #undef TARGET_CALLEE_COPIES
287 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
288 #undef TARGET_ARG_PARTIAL_BYTES
289 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
291 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
292 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
293 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
294 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
296 #undef TARGET_SCALAR_MODE_SUPPORTED_P
297 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
299 struct gcc_target targetm = TARGET_INITIALIZER;
301 /* Parse the -mfixed-range= option string. */
304 fix_range (const char *const_str)
307 char *str, *dash, *comma;
309 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
310 REG2 are either register names or register numbers. The effect
311 of this option is to mark the registers in the range from REG1 to
312 REG2 as ``fixed'' so they won't be used by the compiler. This is
313 used, e.g., to ensure that kernel mode code doesn't use f32-f127. */
315 i = strlen (const_str);
316 str = (char *) alloca (i + 1);
317 memcpy (str, const_str, i + 1);
321 dash = strchr (str, '-');
324 warning ("value of -mfixed-range must have form REG1-REG2");
329 comma = strchr (dash + 1, ',');
333 first = decode_reg_name (str);
336 warning ("unknown register name: %s", str);
340 last = decode_reg_name (dash + 1);
343 warning ("unknown register name: %s", dash + 1);
351 warning ("%s-%s is an empty range", str, dash + 1);
355 for (i = first; i <= last; ++i)
356 fixed_regs[i] = call_used_regs[i] = 1;
365 /* Check if all floating point registers have been fixed. */
366 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
371 target_flags |= MASK_DISABLE_FPREGS;
375 override_options (void)
377 if (pa_cpu_string == NULL)
378 pa_cpu_string = TARGET_SCHED_DEFAULT;
380 if (! strcmp (pa_cpu_string, "8000"))
382 pa_cpu_string = "8000";
383 pa_cpu = PROCESSOR_8000;
385 else if (! strcmp (pa_cpu_string, "7100"))
387 pa_cpu_string = "7100";
388 pa_cpu = PROCESSOR_7100;
390 else if (! strcmp (pa_cpu_string, "700"))
392 pa_cpu_string = "700";
393 pa_cpu = PROCESSOR_700;
395 else if (! strcmp (pa_cpu_string, "7100LC"))
397 pa_cpu_string = "7100LC";
398 pa_cpu = PROCESSOR_7100LC;
400 else if (! strcmp (pa_cpu_string, "7200"))
402 pa_cpu_string = "7200";
403 pa_cpu = PROCESSOR_7200;
405 else if (! strcmp (pa_cpu_string, "7300"))
407 pa_cpu_string = "7300";
408 pa_cpu = PROCESSOR_7300;
412 warning ("unknown -mschedule= option (%s).\nValid options are 700, 7100, 7100LC, 7200, 7300, and 8000\n", pa_cpu_string);
415 /* Set the instruction architecture. */
416 if (pa_arch_string && ! strcmp (pa_arch_string, "1.0"))
418 pa_arch_string = "1.0";
419 pa_arch = ARCHITECTURE_10;
420 target_flags &= ~(MASK_PA_11 | MASK_PA_20);
422 else if (pa_arch_string && ! strcmp (pa_arch_string, "1.1"))
424 pa_arch_string = "1.1";
425 pa_arch = ARCHITECTURE_11;
426 target_flags &= ~MASK_PA_20;
427 target_flags |= MASK_PA_11;
429 else if (pa_arch_string && ! strcmp (pa_arch_string, "2.0"))
431 pa_arch_string = "2.0";
432 pa_arch = ARCHITECTURE_20;
433 target_flags |= MASK_PA_11 | MASK_PA_20;
435 else if (pa_arch_string)
437 warning ("unknown -march= option (%s).\nValid options are 1.0, 1.1, and 2.0\n", pa_arch_string);
442 /* Set the default UNIX standard for HP-UX. This affects the
443 predefines and startfiles used for the target. */
444 if (pa_unix_string == NULL)
446 = TARGET_HPUX_11_11 ? "98" : (TARGET_HPUX_10_10 ? "95" : "93");
448 if (!strcmp (pa_unix_string, "93"))
450 else if (!strcmp (pa_unix_string, "95"))
452 else if (TARGET_HPUX_11_11)
454 if (!strcmp (pa_unix_string, "98"))
457 warning ("unknown -munix= option (%s).\n"
458 "Valid options are 93, 95 and 98.\n",
461 else if (TARGET_HPUX_10_10)
462 warning ("unknown -munix= option (%s)."
463 "\nValid options are 93 and 95.\n",
466 warning ("unknown -munix= option (%s).\nValid option is 93.\n",
470 if (pa_fixed_range_string)
471 fix_range (pa_fixed_range_string);
473 /* Unconditional branches in the delay slot are not compatible with dwarf2
474 call frame information. There is no benefit in using this optimization
475 on PA8000 and later processors. */
476 if (pa_cpu >= PROCESSOR_8000
477 || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
478 || flag_unwind_tables)
479 target_flags &= ~MASK_JUMP_IN_DELAY;
481 if (flag_pic && TARGET_PORTABLE_RUNTIME)
483 warning ("PIC code generation is not supported in the portable runtime model\n");
486 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
488 warning ("PIC code generation is not compatible with fast indirect calls\n");
491 if (! TARGET_GAS && write_symbols != NO_DEBUG)
493 warning ("-g is only supported when using GAS on this processor,");
494 warning ("-g option disabled");
495 write_symbols = NO_DEBUG;
498 /* We only support the "big PIC" model now. And we always generate PIC
499 code when in 64bit mode. */
500 if (flag_pic == 1 || TARGET_64BIT)
503 /* We can't guarantee that .dword is available for 32-bit targets. */
504 if (UNITS_PER_WORD == 4)
505 targetm.asm_out.aligned_op.di = NULL;
507 /* The unaligned ops are only available when using GAS. */
510 targetm.asm_out.unaligned_op.hi = NULL;
511 targetm.asm_out.unaligned_op.si = NULL;
512 targetm.asm_out.unaligned_op.di = NULL;
515 init_machine_status = pa_init_machine_status;
519 pa_init_builtins (void)
521 #ifdef DONT_HAVE_FPUTC_UNLOCKED
522 built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
523 implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
527 /* Function to init struct machine_function.
528 This will be called, via a pointer variable,
529 from push_function_context. */
531 static struct machine_function *
532 pa_init_machine_status (void)
534 return ggc_alloc_cleared (sizeof (machine_function));
537 /* If FROM is a probable pointer register, mark TO as a probable
538 pointer register with the same pointer alignment as FROM. */
541 copy_reg_pointer (rtx to, rtx from)
543 if (REG_POINTER (from))
544 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
547 /* Return nonzero only if OP is a register of mode MODE,
550 reg_or_0_operand (rtx op, enum machine_mode mode)
552 return (op == CONST0_RTX (mode) || register_operand (op, mode));
555 /* Return nonzero if OP is suitable for use in a call to a named
558 For 2.5 try to eliminate either call_operand_address or
559 function_label_operand, they perform very similar functions. */
561 call_operand_address (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
563 return (GET_MODE (op) == word_mode
564 && CONSTANT_P (op) && ! TARGET_PORTABLE_RUNTIME);
567 /* Return 1 if X contains a symbolic expression. We know these
568 expressions will have one of a few well defined forms, so
569 we need only check those forms. */
571 symbolic_expression_p (rtx x)
574 /* Strip off any HIGH. */
575 if (GET_CODE (x) == HIGH)
578 return (symbolic_operand (x, VOIDmode));
582 symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
584 switch (GET_CODE (op))
591 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
592 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
593 && GET_CODE (XEXP (op, 1)) == CONST_INT);
599 /* Return truth value of statement that OP is a symbolic memory
600 operand of mode MODE. */
603 symbolic_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
605 if (GET_CODE (op) == SUBREG)
606 op = SUBREG_REG (op);
607 if (GET_CODE (op) != MEM)
610 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
611 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
614 /* Return 1 if the operand is either a register, zero, or a memory operand
615 that is not symbolic. */
618 reg_or_0_or_nonsymb_mem_operand (rtx op, enum machine_mode mode)
620 if (register_operand (op, mode))
623 if (op == CONST0_RTX (mode))
626 if (GET_CODE (op) == SUBREG)
627 op = SUBREG_REG (op);
629 if (GET_CODE (op) != MEM)
632 /* Until problems with management of the REG_POINTER flag are resolved,
633 we need to delay creating move insns with unscaled indexed addresses
634 until CSE is not expected. */
635 if (!TARGET_NO_SPACE_REGS
637 && GET_CODE (XEXP (op, 0)) == PLUS
638 && REG_P (XEXP (XEXP (op, 0), 0))
639 && REG_P (XEXP (XEXP (op, 0), 1)))
642 return (!symbolic_memory_operand (op, mode)
643 && memory_address_p (mode, XEXP (op, 0)));
646 /* Return 1 if the operand is a register operand or a non-symbolic memory
647 operand after reload. This predicate is used for branch patterns that
648 internally handle register reloading. We need to accept non-symbolic
649 memory operands after reload to ensure that the pattern is still valid
650 if reload didn't find a hard register for the operand. */
653 reg_before_reload_operand (rtx op, enum machine_mode mode)
655 /* Don't accept a SUBREG since it will need a reload. */
656 if (GET_CODE (op) == SUBREG)
659 if (register_operand (op, mode))
663 && memory_operand (op, mode)
664 && !symbolic_memory_operand (op, mode))
670 /* Accept any constant that can be moved in one instruction into a
673 cint_ok_for_move (HOST_WIDE_INT intval)
675 /* OK if ldo, ldil, or zdepi, can be used. */
676 return (CONST_OK_FOR_LETTER_P (intval, 'J')
677 || CONST_OK_FOR_LETTER_P (intval, 'N')
678 || CONST_OK_FOR_LETTER_P (intval, 'K'));
681 /* Return 1 iff OP is an indexed memory operand. */
683 indexed_memory_operand (rtx op, enum machine_mode mode)
685 if (GET_MODE (op) != mode)
688 /* Before reload, a (SUBREG (MEM...)) forces reloading into a register. */
689 if (reload_completed && GET_CODE (op) == SUBREG)
690 op = SUBREG_REG (op);
692 if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
697 return (memory_address_p (mode, op) && IS_INDEX_ADDR_P (op));
700 /* Accept anything that can be used as a destination operand for a
701 move instruction. We don't accept indexed memory operands since
702 they are supported only for floating point stores. */
704 move_dest_operand (rtx op, enum machine_mode mode)
706 if (register_operand (op, mode))
709 if (GET_MODE (op) != mode)
712 if (GET_CODE (op) == SUBREG)
713 op = SUBREG_REG (op);
715 if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
720 return (memory_address_p (mode, op)
721 && !IS_INDEX_ADDR_P (op)
722 && !IS_LO_SUM_DLT_ADDR_P (op));
725 /* Accept anything that can be used as a source operand for a move
728 move_src_operand (rtx op, enum machine_mode mode)
730 if (register_operand (op, mode))
733 if (GET_CODE (op) == CONST_INT)
734 return cint_ok_for_move (INTVAL (op));
736 if (GET_MODE (op) != mode)
739 if (GET_CODE (op) == SUBREG)
740 op = SUBREG_REG (op);
742 if (GET_CODE (op) != MEM)
745 /* Until problems with management of the REG_POINTER flag are resolved,
746 we need to delay creating move insns with unscaled indexed addresses
747 until CSE is not expected. */
748 if (!TARGET_NO_SPACE_REGS
750 && GET_CODE (XEXP (op, 0)) == PLUS
751 && REG_P (XEXP (XEXP (op, 0), 0))
752 && REG_P (XEXP (XEXP (op, 0), 1)))
755 return memory_address_p (mode, XEXP (op, 0));
758 /* Accept anything that can be used as the source operand for a prefetch
759 instruction with a cache-control completer. */
761 prefetch_cc_operand (rtx op, enum machine_mode mode)
763 if (GET_CODE (op) != MEM)
768 /* We must reject virtual registers as we don't allow REG+D. */
769 if (op == virtual_incoming_args_rtx
770 || op == virtual_stack_vars_rtx
771 || op == virtual_stack_dynamic_rtx
772 || op == virtual_outgoing_args_rtx
773 || op == virtual_cfa_rtx)
776 if (!REG_P (op) && !IS_INDEX_ADDR_P (op))
779 /* Until problems with management of the REG_POINTER flag are resolved,
780 we need to delay creating prefetch insns with unscaled indexed addresses
781 until CSE is not expected. */
782 if (!TARGET_NO_SPACE_REGS
784 && GET_CODE (op) == PLUS
785 && REG_P (XEXP (op, 0)))
788 return memory_address_p (mode, op);
791 /* Accept anything that can be used as the source operand for a prefetch
792 instruction with no cache-control completer. */
794 prefetch_nocc_operand (rtx op, enum machine_mode mode)
796 if (GET_CODE (op) != MEM)
801 /* Until problems with management of the REG_POINTER flag are resolved,
802 we need to delay creating prefetch insns with unscaled indexed addresses
803 until CSE is not expected. */
804 if (!TARGET_NO_SPACE_REGS
806 && GET_CODE (op) == PLUS
807 && REG_P (XEXP (op, 0))
808 && REG_P (XEXP (op, 1)))
811 return memory_address_p (mode, op);
814 /* Accept REG and any CONST_INT that can be moved in one instruction into a
817 reg_or_cint_move_operand (rtx op, enum machine_mode mode)
819 if (register_operand (op, mode))
822 return (GET_CODE (op) == CONST_INT && cint_ok_for_move (INTVAL (op)));
826 pic_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
831 switch (GET_CODE (op))
837 return (GET_CODE (XEXP (op, 0)) == LABEL_REF
838 && GET_CODE (XEXP (op, 1)) == CONST_INT);
845 fp_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
847 return reg_renumber && FP_REG_P (op);
852 /* Return truth value of whether OP can be used as an operand in a
853 three operand arithmetic insn that accepts registers of mode MODE
854 or 14-bit signed integers. */
856 arith_operand (rtx op, enum machine_mode mode)
858 return (register_operand (op, mode)
859 || (GET_CODE (op) == CONST_INT && INT_14_BITS (op)));
862 /* Return truth value of whether OP can be used as an operand in a
863 three operand arithmetic insn that accepts registers of mode MODE
864 or 11-bit signed integers. */
866 arith11_operand (rtx op, enum machine_mode mode)
868 return (register_operand (op, mode)
869 || (GET_CODE (op) == CONST_INT && INT_11_BITS (op)));
872 /* Return truth value of whether OP can be used as an operand in a
875 adddi3_operand (rtx op, enum machine_mode mode)
877 return (register_operand (op, mode)
878 || (GET_CODE (op) == CONST_INT
879 && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
882 /* A constant integer suitable for use in a PRE_MODIFY memory
885 pre_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
887 return (GET_CODE (op) == CONST_INT
888 && INTVAL (op) >= -0x2000 && INTVAL (op) < 0x10);
891 /* A constant integer suitable for use in a POST_MODIFY memory
894 post_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
896 return (GET_CODE (op) == CONST_INT
897 && INTVAL (op) < 0x2000 && INTVAL (op) >= -0x10);
901 arith_double_operand (rtx op, enum machine_mode mode)
903 return (register_operand (op, mode)
904 || (GET_CODE (op) == CONST_DOUBLE
905 && GET_MODE (op) == mode
906 && VAL_14_BITS_P (CONST_DOUBLE_LOW (op))
907 && ((CONST_DOUBLE_HIGH (op) >= 0)
908 == ((CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
911 /* Return truth value of whether OP is an integer which fits the
912 range constraining immediate operands in three-address insns, or
913 is an integer register. */
916 ireg_or_int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
918 return ((GET_CODE (op) == CONST_INT && INT_5_BITS (op))
919 || (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32));
922 /* Return nonzero if OP is an integer register, else return zero. */
924 ireg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
926 return (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32);
929 /* Return truth value of whether OP is an integer which fits the
930 range constraining immediate operands in three-address insns. */
933 int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
935 return (GET_CODE (op) == CONST_INT && INT_5_BITS (op));
939 uint5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
941 return (GET_CODE (op) == CONST_INT && INT_U5_BITS (op));
945 int11_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
947 return (GET_CODE (op) == CONST_INT && INT_11_BITS (op));
951 uint32_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
953 #if HOST_BITS_PER_WIDE_INT > 32
954 /* All allowed constants will fit a CONST_INT. */
955 return (GET_CODE (op) == CONST_INT
956 && (INTVAL (op) >= 0 && INTVAL (op) < (HOST_WIDE_INT) 1 << 32));
958 return (GET_CODE (op) == CONST_INT
959 || (GET_CODE (op) == CONST_DOUBLE
960 && CONST_DOUBLE_HIGH (op) == 0));
965 arith5_operand (rtx op, enum machine_mode mode)
967 return register_operand (op, mode) || int5_operand (op, mode);
970 /* True iff zdepi can be used to generate this CONST_INT.
971 zdepi first sign extends a 5 bit signed number to a given field
972 length, then places this field anywhere in a zero. */
974 zdepi_cint_p (unsigned HOST_WIDE_INT x)
976 unsigned HOST_WIDE_INT lsb_mask, t;
978 /* This might not be obvious, but it's at least fast.
979 This function is critical; we don't have the time loops would take. */
981 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
982 /* Return true iff t is a power of two. */
983 return ((t & (t - 1)) == 0);
986 /* True iff depi or extru can be used to compute (reg & mask).
987 Accept bit pattern like these:
992 and_mask_p (unsigned HOST_WIDE_INT mask)
995 mask += mask & -mask;
996 return (mask & (mask - 1)) == 0;
999 /* True iff depi or extru can be used to compute (reg & OP). */
1001 and_operand (rtx op, enum machine_mode mode)
1003 return (register_operand (op, mode)
1004 || (GET_CODE (op) == CONST_INT && and_mask_p (INTVAL (op))));
1007 /* True iff depi can be used to compute (reg | MASK). */
1009 ior_mask_p (unsigned HOST_WIDE_INT mask)
1011 mask += mask & -mask;
1012 return (mask & (mask - 1)) == 0;
1015 /* True iff depi can be used to compute (reg | OP). */
1017 ior_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1019 return (GET_CODE (op) == CONST_INT && ior_mask_p (INTVAL (op)));
1023 lhs_lshift_operand (rtx op, enum machine_mode mode)
1025 return register_operand (op, mode) || lhs_lshift_cint_operand (op, mode);
1028 /* True iff OP is a CONST_INT of the forms 0...0xxxx or 0...01...1xxxx.
1029 Such values can be the left hand side x in (x << r), using the zvdepi
1032 lhs_lshift_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1034 unsigned HOST_WIDE_INT x;
1035 if (GET_CODE (op) != CONST_INT)
1037 x = INTVAL (op) >> 4;
1038 return (x & (x + 1)) == 0;
1042 arith32_operand (rtx op, enum machine_mode mode)
1044 return register_operand (op, mode) || GET_CODE (op) == CONST_INT;
1048 pc_or_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1050 return (GET_CODE (op) == PC || GET_CODE (op) == LABEL_REF);
1053 /* Legitimize PIC addresses. If the address is already
1054 position-independent, we return ORIG. Newly generated
1055 position-independent addresses go to REG. If we need more
1056 than one register, we lose. */
1059 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
1063 /* Labels need special handling. */
1064 if (pic_label_operand (orig, mode))
1066 /* We do not want to go through the movXX expanders here since that
1067 would create recursion.
1069 Nor do we really want to call a generator for a named pattern
1070 since that requires multiple patterns if we want to support
1071 multiple word sizes.
1073 So instead we just emit the raw set, which avoids the movXX
1074 expanders completely. */
1075 mark_reg_pointer (reg, BITS_PER_UNIT);
1076 emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
1077 current_function_uses_pic_offset_table = 1;
1080 if (GET_CODE (orig) == SYMBOL_REF)
1087 /* Before reload, allocate a temporary register for the intermediate
1088 result. This allows the sequence to be deleted when the final
1089 result is unused and the insns are trivially dead. */
1090 tmp_reg = ((reload_in_progress || reload_completed)
1091 ? reg : gen_reg_rtx (Pmode));
1093 emit_move_insn (tmp_reg,
1094 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
1095 gen_rtx_HIGH (word_mode, orig)));
1097 = gen_const_mem (Pmode,
1098 gen_rtx_LO_SUM (Pmode, tmp_reg,
1099 gen_rtx_UNSPEC (Pmode,
1100 gen_rtvec (1, orig),
1101 UNSPEC_DLTIND14R)));
1103 current_function_uses_pic_offset_table = 1;
1104 mark_reg_pointer (reg, BITS_PER_UNIT);
1105 insn = emit_move_insn (reg, pic_ref);
1107 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
1108 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig, REG_NOTES (insn));
1112 else if (GET_CODE (orig) == CONST)
1116 if (GET_CODE (XEXP (orig, 0)) == PLUS
1117 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1123 if (GET_CODE (XEXP (orig, 0)) == PLUS)
1125 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1126 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1127 base == reg ? 0 : reg);
1132 if (GET_CODE (orig) == CONST_INT)
1134 if (INT_14_BITS (orig))
1135 return plus_constant (base, INTVAL (orig));
1136 orig = force_reg (Pmode, orig);
1138 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
1139 /* Likewise, should we set special REG_NOTEs here? */
1145 /* Try machine-dependent ways of modifying an illegitimate address
1146 to be legitimate. If we find one, return the new, valid address.
1147 This macro is used in only one place: `memory_address' in explow.c.
1149 OLDX is the address as it was before break_out_memory_refs was called.
1150 In some cases it is useful to look at this to decide what needs to be done.
1152 MODE and WIN are passed so that this macro can use
1153 GO_IF_LEGITIMATE_ADDRESS.
1155 It is always safe for this macro to do nothing. It exists to recognize
1156 opportunities to optimize the output.
1158 For the PA, transform:
1160 memory(X + <large int>)
1164 if (<large int> & mask) >= 16
1165 Y = (<large int> & ~mask) + mask + 1 Round up.
1167 Y = (<large int> & ~mask) Round down.
1169 memory (Z + (<large int> - Y));
1171 This is for CSE to find several similar references, and only use one Z.
1173 X can either be a SYMBOL_REF or REG, but because combine cannot
1174 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
1175 D will not fit in 14 bits.
1177 MODE_FLOAT references allow displacements which fit in 5 bits, so use
1180 MODE_INT references allow displacements which fit in 14 bits, so use
1183 This relies on the fact that most mode MODE_FLOAT references will use FP
1184 registers and most mode MODE_INT references will use integer registers.
1185 (In the rare case of an FP register used in an integer MODE, we depend
1186 on secondary reloads to clean things up.)
1189 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
1190 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
1191 addressing modes to be used).
1193 Put X and Z into registers. Then put the entire expression into
1197 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1198 enum machine_mode mode)
1202 /* We need to canonicalize the order of operands in unscaled indexed
1203 addresses since the code that checks if an address is valid doesn't
1204 always try both orders. */
1205 if (!TARGET_NO_SPACE_REGS
1206 && GET_CODE (x) == PLUS
1207 && GET_MODE (x) == Pmode
1208 && REG_P (XEXP (x, 0))
1209 && REG_P (XEXP (x, 1))
1210 && REG_POINTER (XEXP (x, 0))
1211 && !REG_POINTER (XEXP (x, 1)))
1212 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
1215 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
1217 /* Strip off CONST. */
1218 if (GET_CODE (x) == CONST)
1221 /* Special case. Get the SYMBOL_REF into a register and use indexing.
1222 That should always be safe. */
1223 if (GET_CODE (x) == PLUS
1224 && GET_CODE (XEXP (x, 0)) == REG
1225 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
1227 rtx reg = force_reg (Pmode, XEXP (x, 1));
1228 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
1231 /* Note we must reject symbols which represent function addresses
1232 since the assembler/linker can't handle arithmetic on plabels. */
1233 if (GET_CODE (x) == PLUS
1234 && GET_CODE (XEXP (x, 1)) == CONST_INT
1235 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1236 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
1237 || GET_CODE (XEXP (x, 0)) == REG))
1239 rtx int_part, ptr_reg;
1241 int offset = INTVAL (XEXP (x, 1));
1244 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
1245 ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
1247 /* Choose which way to round the offset. Round up if we
1248 are >= halfway to the next boundary. */
1249 if ((offset & mask) >= ((mask + 1) / 2))
1250 newoffset = (offset & ~ mask) + mask + 1;
1252 newoffset = (offset & ~ mask);
1254 /* If the newoffset will not fit in 14 bits (ldo), then
1255 handling this would take 4 or 5 instructions (2 to load
1256 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
1257 add the new offset and the SYMBOL_REF.) Combine can
1258 not handle 4->2 or 5->2 combinations, so do not create
1260 if (! VAL_14_BITS_P (newoffset)
1261 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
1263 rtx const_part = plus_constant (XEXP (x, 0), newoffset);
1266 gen_rtx_HIGH (Pmode, const_part));
1269 gen_rtx_LO_SUM (Pmode,
1270 tmp_reg, const_part));
1274 if (! VAL_14_BITS_P (newoffset))
1275 int_part = force_reg (Pmode, GEN_INT (newoffset));
1277 int_part = GEN_INT (newoffset);
1279 ptr_reg = force_reg (Pmode,
1280 gen_rtx_PLUS (Pmode,
1281 force_reg (Pmode, XEXP (x, 0)),
1284 return plus_constant (ptr_reg, offset - newoffset);
1287 /* Handle (plus (mult (a) (shadd_constant)) (b)). */
1289 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1290 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1291 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
1292 && (OBJECT_P (XEXP (x, 1))
1293 || GET_CODE (XEXP (x, 1)) == SUBREG)
1294 && GET_CODE (XEXP (x, 1)) != CONST)
1296 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1300 if (GET_CODE (reg1) != REG)
1301 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1303 reg2 = XEXP (XEXP (x, 0), 0);
1304 if (GET_CODE (reg2) != REG)
1305 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1307 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1308 gen_rtx_MULT (Pmode,
1314 /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
1316 Only do so for floating point modes since this is more speculative
1317 and we lose if it's an integer store. */
1318 if (GET_CODE (x) == PLUS
1319 && GET_CODE (XEXP (x, 0)) == PLUS
1320 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1321 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
1322 && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1323 && (mode == SFmode || mode == DFmode))
1326 /* First, try and figure out what to use as a base register. */
1327 rtx reg1, reg2, base, idx, orig_base;
1329 reg1 = XEXP (XEXP (x, 0), 1);
1334 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
1335 then emit_move_sequence will turn on REG_POINTER so we'll know
1336 it's a base register below. */
1337 if (GET_CODE (reg1) != REG)
1338 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1340 if (GET_CODE (reg2) != REG)
1341 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1343 /* Figure out what the base and index are. */
1345 if (GET_CODE (reg1) == REG
1346 && REG_POINTER (reg1))
1349 orig_base = XEXP (XEXP (x, 0), 1);
1350 idx = gen_rtx_PLUS (Pmode,
1351 gen_rtx_MULT (Pmode,
1352 XEXP (XEXP (XEXP (x, 0), 0), 0),
1353 XEXP (XEXP (XEXP (x, 0), 0), 1)),
1356 else if (GET_CODE (reg2) == REG
1357 && REG_POINTER (reg2))
1360 orig_base = XEXP (x, 1);
1367 /* If the index adds a large constant, try to scale the
1368 constant so that it can be loaded with only one insn. */
1369 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1370 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1371 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1372 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1374 /* Divide the CONST_INT by the scale factor, then add it to A. */
1375 int val = INTVAL (XEXP (idx, 1));
1377 val /= INTVAL (XEXP (XEXP (idx, 0), 1));
1378 reg1 = XEXP (XEXP (idx, 0), 0);
1379 if (GET_CODE (reg1) != REG)
1380 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1382 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1384 /* We can now generate a simple scaled indexed address. */
1387 (Pmode, gen_rtx_PLUS (Pmode,
1388 gen_rtx_MULT (Pmode, reg1,
1389 XEXP (XEXP (idx, 0), 1)),
1393 /* If B + C is still a valid base register, then add them. */
1394 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1395 && INTVAL (XEXP (idx, 1)) <= 4096
1396 && INTVAL (XEXP (idx, 1)) >= -4096)
1398 int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1401 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1403 reg2 = XEXP (XEXP (idx, 0), 0);
1404 if (GET_CODE (reg2) != CONST_INT)
1405 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1407 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1408 gen_rtx_MULT (Pmode,
1414 /* Get the index into a register, then add the base + index and
1415 return a register holding the result. */
1417 /* First get A into a register. */
1418 reg1 = XEXP (XEXP (idx, 0), 0);
1419 if (GET_CODE (reg1) != REG)
1420 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1422 /* And get B into a register. */
1423 reg2 = XEXP (idx, 1);
1424 if (GET_CODE (reg2) != REG)
1425 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1427 reg1 = force_reg (Pmode,
1428 gen_rtx_PLUS (Pmode,
1429 gen_rtx_MULT (Pmode, reg1,
1430 XEXP (XEXP (idx, 0), 1)),
1433 /* Add the result to our base register and return. */
1434 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1438 /* Uh-oh. We might have an address for x[n-100000]. This needs
1439 special handling to avoid creating an indexed memory address
1440 with x-100000 as the base.
1442 If the constant part is small enough, then it's still safe because
1443 there is a guard page at the beginning and end of the data segment.
1445 Scaled references are common enough that we want to try and rearrange the
1446 terms so that we can use indexing for these addresses too. Only
1447 do the optimization for floatint point modes. */
1449 if (GET_CODE (x) == PLUS
1450 && symbolic_expression_p (XEXP (x, 1)))
1452 /* Ugly. We modify things here so that the address offset specified
1453 by the index expression is computed first, then added to x to form
1454 the entire address. */
1456 rtx regx1, regx2, regy1, regy2, y;
1458 /* Strip off any CONST. */
1460 if (GET_CODE (y) == CONST)
1463 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1465 /* See if this looks like
1466 (plus (mult (reg) (shadd_const))
1467 (const (plus (symbol_ref) (const_int))))
1469 Where const_int is small. In that case the const
1470 expression is a valid pointer for indexing.
1472 If const_int is big, but can be divided evenly by shadd_const
1473 and added to (reg). This allows more scaled indexed addresses. */
1474 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1475 && GET_CODE (XEXP (x, 0)) == MULT
1476 && GET_CODE (XEXP (y, 1)) == CONST_INT
1477 && INTVAL (XEXP (y, 1)) >= -4096
1478 && INTVAL (XEXP (y, 1)) <= 4095
1479 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1480 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1482 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1486 if (GET_CODE (reg1) != REG)
1487 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1489 reg2 = XEXP (XEXP (x, 0), 0);
1490 if (GET_CODE (reg2) != REG)
1491 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1493 return force_reg (Pmode,
1494 gen_rtx_PLUS (Pmode,
1495 gen_rtx_MULT (Pmode,
1500 else if ((mode == DFmode || mode == SFmode)
1501 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1502 && GET_CODE (XEXP (x, 0)) == MULT
1503 && GET_CODE (XEXP (y, 1)) == CONST_INT
1504 && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1505 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1506 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1509 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1510 / INTVAL (XEXP (XEXP (x, 0), 1))));
1511 regx2 = XEXP (XEXP (x, 0), 0);
1512 if (GET_CODE (regx2) != REG)
1513 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1514 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1518 gen_rtx_PLUS (Pmode,
1519 gen_rtx_MULT (Pmode, regx2,
1520 XEXP (XEXP (x, 0), 1)),
1521 force_reg (Pmode, XEXP (y, 0))));
1523 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1524 && INTVAL (XEXP (y, 1)) >= -4096
1525 && INTVAL (XEXP (y, 1)) <= 4095)
1527 /* This is safe because of the guard page at the
1528 beginning and end of the data space. Just
1529 return the original address. */
1534 /* Doesn't look like one we can optimize. */
1535 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1536 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1537 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1538 regx1 = force_reg (Pmode,
1539 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1541 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1549 /* For the HPPA, REG and REG+CONST is cost 0
1550 and addresses involving symbolic constants are cost 2.
1552 PIC addresses are very expensive.
1554 It is no coincidence that this has the same structure
1555 as GO_IF_LEGITIMATE_ADDRESS. */
1558 hppa_address_cost (rtx X)
1560 switch (GET_CODE (X))
1573 /* Compute a (partial) cost for rtx X. Return true if the complete
1574 cost has been computed, and false if subexpressions should be
1575 scanned. In either case, *TOTAL contains the cost result. */
1578 hppa_rtx_costs (rtx x, int code, int outer_code, int *total)
1583 if (INTVAL (x) == 0)
1585 else if (INT_14_BITS (x))
1602 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1603 && outer_code != SET)
1610 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1611 *total = COSTS_N_INSNS (3);
1612 else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1613 *total = COSTS_N_INSNS (8);
1615 *total = COSTS_N_INSNS (20);
1619 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1621 *total = COSTS_N_INSNS (14);
1629 *total = COSTS_N_INSNS (60);
1632 case PLUS: /* this includes shNadd insns */
1634 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1635 *total = COSTS_N_INSNS (3);
1637 *total = COSTS_N_INSNS (1);
1643 *total = COSTS_N_INSNS (1);
1651 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1652 new rtx with the correct mode. */
1654 force_mode (enum machine_mode mode, rtx orig)
1656 if (mode == GET_MODE (orig))
1659 if (REGNO (orig) >= FIRST_PSEUDO_REGISTER)
1662 return gen_rtx_REG (mode, REGNO (orig));
1665 /* Emit insns to move operands[1] into operands[0].
1667 Return 1 if we have written out everything that needs to be done to
1668 do the move. Otherwise, return 0 and the caller will emit the move
1671 Note SCRATCH_REG may not be in the proper mode depending on how it
1672 will be used. This routine is responsible for creating a new copy
1673 of SCRATCH_REG in the proper mode. */
1676 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1678 register rtx operand0 = operands[0];
1679 register rtx operand1 = operands[1];
1682 /* We can only handle indexed addresses in the destination operand
1683 of floating point stores. Thus, we need to break out indexed
1684 addresses from the destination operand. */
1685 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1687 /* This is only safe up to the beginning of life analysis. */
1691 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1692 operand0 = replace_equiv_address (operand0, tem);
1695 /* On targets with non-equivalent space registers, break out unscaled
1696 indexed addresses from the source operand before the final CSE.
1697 We have to do this because the REG_POINTER flag is not correctly
1698 carried through various optimization passes and CSE may substitute
1699 a pseudo without the pointer set for one with the pointer set. As
1700 a result, we loose various opportunities to create insns with
1701 unscaled indexed addresses. */
1702 if (!TARGET_NO_SPACE_REGS
1703 && !cse_not_expected
1704 && GET_CODE (operand1) == MEM
1705 && GET_CODE (XEXP (operand1, 0)) == PLUS
1706 && REG_P (XEXP (XEXP (operand1, 0), 0))
1707 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1709 = replace_equiv_address (operand1,
1710 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1713 && reload_in_progress && GET_CODE (operand0) == REG
1714 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1715 operand0 = reg_equiv_mem[REGNO (operand0)];
1716 else if (scratch_reg
1717 && reload_in_progress && GET_CODE (operand0) == SUBREG
1718 && GET_CODE (SUBREG_REG (operand0)) == REG
1719 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1721 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1722 the code which tracks sets/uses for delete_output_reload. */
1723 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1724 reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1725 SUBREG_BYTE (operand0));
1726 operand0 = alter_subreg (&temp);
1730 && reload_in_progress && GET_CODE (operand1) == REG
1731 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1732 operand1 = reg_equiv_mem[REGNO (operand1)];
1733 else if (scratch_reg
1734 && reload_in_progress && GET_CODE (operand1) == SUBREG
1735 && GET_CODE (SUBREG_REG (operand1)) == REG
1736 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1738 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1739 the code which tracks sets/uses for delete_output_reload. */
1740 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1741 reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1742 SUBREG_BYTE (operand1));
1743 operand1 = alter_subreg (&temp);
1746 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1747 && ((tem = find_replacement (&XEXP (operand0, 0)))
1748 != XEXP (operand0, 0)))
1749 operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
1751 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1752 && ((tem = find_replacement (&XEXP (operand1, 0)))
1753 != XEXP (operand1, 0)))
1754 operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
1756 /* Handle secondary reloads for loads/stores of FP registers from
1757 REG+D addresses where D does not fit in 5 or 14 bits, including
1758 (subreg (mem (addr))) cases. */
1760 && fp_reg_operand (operand0, mode)
1761 && ((GET_CODE (operand1) == MEM
1762 && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1763 XEXP (operand1, 0)))
1764 || ((GET_CODE (operand1) == SUBREG
1765 && GET_CODE (XEXP (operand1, 0)) == MEM
1766 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1768 XEXP (XEXP (operand1, 0), 0))))))
1770 if (GET_CODE (operand1) == SUBREG)
1771 operand1 = XEXP (operand1, 0);
1773 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1774 it in WORD_MODE regardless of what mode it was originally given
1776 scratch_reg = force_mode (word_mode, scratch_reg);
1778 /* D might not fit in 14 bits either; for such cases load D into
1780 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1782 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1783 emit_move_insn (scratch_reg,
1784 gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1786 XEXP (XEXP (operand1, 0), 0),
1790 emit_move_insn (scratch_reg, XEXP (operand1, 0));
1791 emit_insn (gen_rtx_SET (VOIDmode, operand0,
1792 gen_rtx_MEM (mode, scratch_reg)));
1795 else if (scratch_reg
1796 && fp_reg_operand (operand1, mode)
1797 && ((GET_CODE (operand0) == MEM
1798 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1800 XEXP (operand0, 0)))
1801 || ((GET_CODE (operand0) == SUBREG)
1802 && GET_CODE (XEXP (operand0, 0)) == MEM
1803 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1805 XEXP (XEXP (operand0, 0), 0)))))
1807 if (GET_CODE (operand0) == SUBREG)
1808 operand0 = XEXP (operand0, 0);
1810 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1811 it in WORD_MODE regardless of what mode it was originally given
1813 scratch_reg = force_mode (word_mode, scratch_reg);
1815 /* D might not fit in 14 bits either; for such cases load D into
1817 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1819 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1820 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1823 XEXP (XEXP (operand0, 0),
1828 emit_move_insn (scratch_reg, XEXP (operand0, 0));
1829 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
1833 /* Handle secondary reloads for loads of FP registers from constant
1834 expressions by forcing the constant into memory.
1836 Use scratch_reg to hold the address of the memory location.
1838 The proper fix is to change PREFERRED_RELOAD_CLASS to return
1839 NO_REGS when presented with a const_int and a register class
1840 containing only FP registers. Doing so unfortunately creates
1841 more problems than it solves. Fix this for 2.5. */
1842 else if (scratch_reg
1843 && CONSTANT_P (operand1)
1844 && fp_reg_operand (operand0, mode))
1848 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1849 it in WORD_MODE regardless of what mode it was originally given
1851 scratch_reg = force_mode (word_mode, scratch_reg);
1853 /* Force the constant into memory and put the address of the
1854 memory location into scratch_reg. */
1855 xoperands[0] = scratch_reg;
1856 xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
1857 emit_move_sequence (xoperands, Pmode, 0);
1859 /* Now load the destination register. */
1860 emit_insn (gen_rtx_SET (mode, operand0,
1861 gen_rtx_MEM (mode, scratch_reg)));
1864 /* Handle secondary reloads for SAR. These occur when trying to load
1865 the SAR from memory, FP register, or with a constant. */
1866 else if (scratch_reg
1867 && GET_CODE (operand0) == REG
1868 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1869 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1870 && (GET_CODE (operand1) == MEM
1871 || GET_CODE (operand1) == CONST_INT
1872 || (GET_CODE (operand1) == REG
1873 && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1875 /* D might not fit in 14 bits either; for such cases load D into
1877 if (GET_CODE (operand1) == MEM
1878 && !memory_address_p (Pmode, XEXP (operand1, 0)))
1880 /* We are reloading the address into the scratch register, so we
1881 want to make sure the scratch register is a full register. */
1882 scratch_reg = force_mode (word_mode, scratch_reg);
1884 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1885 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1888 XEXP (XEXP (operand1, 0),
1892 /* Now we are going to load the scratch register from memory,
1893 we want to load it in the same width as the original MEM,
1894 which must be the same as the width of the ultimate destination,
1896 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1898 emit_move_insn (scratch_reg, gen_rtx_MEM (GET_MODE (operand0),
1903 /* We want to load the scratch register using the same mode as
1904 the ultimate destination. */
1905 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1907 emit_move_insn (scratch_reg, operand1);
1910 /* And emit the insn to set the ultimate destination. We know that
1911 the scratch register has the same mode as the destination at this
1913 emit_move_insn (operand0, scratch_reg);
1916 /* Handle the most common case: storing into a register. */
1917 else if (register_operand (operand0, mode))
1919 if (register_operand (operand1, mode)
1920 || (GET_CODE (operand1) == CONST_INT
1921 && cint_ok_for_move (INTVAL (operand1)))
1922 || (operand1 == CONST0_RTX (mode))
1923 || (GET_CODE (operand1) == HIGH
1924 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1925 /* Only `general_operands' can come here, so MEM is ok. */
1926 || GET_CODE (operand1) == MEM)
1928 /* Various sets are created during RTL generation which don't
1929 have the REG_POINTER flag correctly set. After the CSE pass,
1930 instruction recognition can fail if we don't consistently
1931 set this flag when performing register copies. This should
1932 also improve the opportunities for creating insns that use
1933 unscaled indexing. */
1934 if (REG_P (operand0) && REG_P (operand1))
1936 if (REG_POINTER (operand1)
1937 && !REG_POINTER (operand0)
1938 && !HARD_REGISTER_P (operand0))
1939 copy_reg_pointer (operand0, operand1);
1940 else if (REG_POINTER (operand0)
1941 && !REG_POINTER (operand1)
1942 && !HARD_REGISTER_P (operand1))
1943 copy_reg_pointer (operand1, operand0);
1946 /* When MEMs are broken out, the REG_POINTER flag doesn't
1947 get set. In some cases, we can set the REG_POINTER flag
1948 from the declaration for the MEM. */
1949 if (REG_P (operand0)
1950 && GET_CODE (operand1) == MEM
1951 && !REG_POINTER (operand0))
1953 tree decl = MEM_EXPR (operand1);
1955 /* Set the register pointer flag and register alignment
1956 if the declaration for this memory reference is a
1957 pointer type. Fortran indirect argument references
1960 && !(flag_argument_noalias > 1
1961 && TREE_CODE (decl) == INDIRECT_REF
1962 && TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL))
1966 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1968 if (TREE_CODE (decl) == COMPONENT_REF)
1969 decl = TREE_OPERAND (decl, 1);
1971 type = TREE_TYPE (decl);
1972 if (TREE_CODE (type) == ARRAY_TYPE)
1973 type = get_inner_array_type (type);
1975 if (POINTER_TYPE_P (type))
1979 type = TREE_TYPE (type);
1980 /* Using TYPE_ALIGN_OK is rather conservative as
1981 only the ada frontend actually sets it. */
1982 align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1984 mark_reg_pointer (operand0, align);
1989 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1993 else if (GET_CODE (operand0) == MEM)
1995 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1996 && !(reload_in_progress || reload_completed))
1998 rtx temp = gen_reg_rtx (DFmode);
2000 emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
2001 emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
2004 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
2006 /* Run this case quickly. */
2007 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
2010 if (! (reload_in_progress || reload_completed))
2012 operands[0] = validize_mem (operand0);
2013 operands[1] = operand1 = force_reg (mode, operand1);
2017 /* Simplify the source if we need to.
2018 Note we do have to handle function labels here, even though we do
2019 not consider them legitimate constants. Loop optimizations can
2020 call the emit_move_xxx with one as a source. */
2021 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
2022 || function_label_operand (operand1, mode)
2023 || (GET_CODE (operand1) == HIGH
2024 && symbolic_operand (XEXP (operand1, 0), mode)))
2028 if (GET_CODE (operand1) == HIGH)
2031 operand1 = XEXP (operand1, 0);
2033 if (symbolic_operand (operand1, mode))
2035 /* Argh. The assembler and linker can't handle arithmetic
2038 So we force the plabel into memory, load operand0 from
2039 the memory location, then add in the constant part. */
2040 if ((GET_CODE (operand1) == CONST
2041 && GET_CODE (XEXP (operand1, 0)) == PLUS
2042 && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
2043 || function_label_operand (operand1, mode))
2045 rtx temp, const_part;
2047 /* Figure out what (if any) scratch register to use. */
2048 if (reload_in_progress || reload_completed)
2050 scratch_reg = scratch_reg ? scratch_reg : operand0;
2051 /* SCRATCH_REG will hold an address and maybe the actual
2052 data. We want it in WORD_MODE regardless of what mode it
2053 was originally given to us. */
2054 scratch_reg = force_mode (word_mode, scratch_reg);
2057 scratch_reg = gen_reg_rtx (Pmode);
2059 if (GET_CODE (operand1) == CONST)
2061 /* Save away the constant part of the expression. */
2062 const_part = XEXP (XEXP (operand1, 0), 1);
2063 if (GET_CODE (const_part) != CONST_INT)
2066 /* Force the function label into memory. */
2067 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
2071 /* No constant part. */
2072 const_part = NULL_RTX;
2074 /* Force the function label into memory. */
2075 temp = force_const_mem (mode, operand1);
2079 /* Get the address of the memory location. PIC-ify it if
2081 temp = XEXP (temp, 0);
2083 temp = legitimize_pic_address (temp, mode, scratch_reg);
2085 /* Put the address of the memory location into our destination
2088 emit_move_sequence (operands, mode, scratch_reg);
2090 /* Now load from the memory location into our destination
2092 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
2093 emit_move_sequence (operands, mode, scratch_reg);
2095 /* And add back in the constant part. */
2096 if (const_part != NULL_RTX)
2097 expand_inc (operand0, const_part);
2106 if (reload_in_progress || reload_completed)
2108 temp = scratch_reg ? scratch_reg : operand0;
2109 /* TEMP will hold an address and maybe the actual
2110 data. We want it in WORD_MODE regardless of what mode it
2111 was originally given to us. */
2112 temp = force_mode (word_mode, temp);
2115 temp = gen_reg_rtx (Pmode);
2117 /* (const (plus (symbol) (const_int))) must be forced to
2118 memory during/after reload if the const_int will not fit
2120 if (GET_CODE (operand1) == CONST
2121 && GET_CODE (XEXP (operand1, 0)) == PLUS
2122 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
2123 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
2124 && (reload_completed || reload_in_progress)
2127 operands[1] = force_const_mem (mode, operand1);
2128 operands[1] = legitimize_pic_address (XEXP (operands[1], 0),
2130 operands[1] = gen_rtx_MEM (mode, operands[1]);
2131 emit_move_sequence (operands, mode, temp);
2135 operands[1] = legitimize_pic_address (operand1, mode, temp);
2136 if (REG_P (operand0) && REG_P (operands[1]))
2137 copy_reg_pointer (operand0, operands[1]);
2138 emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
2141 /* On the HPPA, references to data space are supposed to use dp,
2142 register 27, but showing it in the RTL inhibits various cse
2143 and loop optimizations. */
2148 if (reload_in_progress || reload_completed)
2150 temp = scratch_reg ? scratch_reg : operand0;
2151 /* TEMP will hold an address and maybe the actual
2152 data. We want it in WORD_MODE regardless of what mode it
2153 was originally given to us. */
2154 temp = force_mode (word_mode, temp);
2157 temp = gen_reg_rtx (mode);
2159 /* Loading a SYMBOL_REF into a register makes that register
2160 safe to be used as the base in an indexed address.
2162 Don't mark hard registers though. That loses. */
2163 if (GET_CODE (operand0) == REG
2164 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
2165 mark_reg_pointer (operand0, BITS_PER_UNIT);
2166 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
2167 mark_reg_pointer (temp, BITS_PER_UNIT);
2170 set = gen_rtx_SET (mode, operand0, temp);
2172 set = gen_rtx_SET (VOIDmode,
2174 gen_rtx_LO_SUM (mode, temp, operand1));
2176 emit_insn (gen_rtx_SET (VOIDmode,
2178 gen_rtx_HIGH (mode, operand1)));
2184 else if (GET_CODE (operand1) != CONST_INT
2185 || !cint_ok_for_move (INTVAL (operand1)))
2189 HOST_WIDE_INT value = 0;
2190 HOST_WIDE_INT insv = 0;
2193 if (GET_CODE (operand1) == CONST_INT)
2194 value = INTVAL (operand1);
2197 && GET_CODE (operand1) == CONST_INT
2198 && HOST_BITS_PER_WIDE_INT > 32
2199 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
2203 /* Extract the low order 32 bits of the value and sign extend.
2204 If the new value is the same as the original value, we can
2205 can use the original value as-is. If the new value is
2206 different, we use it and insert the most-significant 32-bits
2207 of the original value into the final result. */
2208 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
2209 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
2212 #if HOST_BITS_PER_WIDE_INT > 32
2213 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
2217 operand1 = GEN_INT (nval);
2221 if (reload_in_progress || reload_completed)
2222 temp = scratch_reg ? scratch_reg : operand0;
2224 temp = gen_reg_rtx (mode);
2226 /* We don't directly split DImode constants on 32-bit targets
2227 because PLUS uses an 11-bit immediate and the insn sequence
2228 generated is not as efficient as the one using HIGH/LO_SUM. */
2229 if (GET_CODE (operand1) == CONST_INT
2230 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2233 /* Directly break constant into high and low parts. This
2234 provides better optimization opportunities because various
2235 passes recognize constants split with PLUS but not LO_SUM.
2236 We use a 14-bit signed low part except when the addition
2237 of 0x4000 to the high part might change the sign of the
2239 HOST_WIDE_INT low = value & 0x3fff;
2240 HOST_WIDE_INT high = value & ~ 0x3fff;
2244 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
2252 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
2253 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2257 emit_insn (gen_rtx_SET (VOIDmode, temp,
2258 gen_rtx_HIGH (mode, operand1)));
2259 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
2262 insn = emit_move_insn (operands[0], operands[1]);
2264 /* Now insert the most significant 32 bits of the value
2265 into the register. When we don't have a second register
2266 available, it could take up to nine instructions to load
2267 a 64-bit integer constant. Prior to reload, we force
2268 constants that would take more than three instructions
2269 to load to the constant pool. During and after reload,
2270 we have to handle all possible values. */
2273 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
2274 register and the value to be inserted is outside the
2275 range that can be loaded with three depdi instructions. */
2276 if (temp != operand0 && (insv >= 16384 || insv < -16384))
2278 operand1 = GEN_INT (insv);
2280 emit_insn (gen_rtx_SET (VOIDmode, temp,
2281 gen_rtx_HIGH (mode, operand1)));
2282 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
2283 emit_insn (gen_insv (operand0, GEN_INT (32),
2288 int len = 5, pos = 27;
2290 /* Insert the bits using the depdi instruction. */
2293 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2294 HOST_WIDE_INT sign = v5 < 0;
2296 /* Left extend the insertion. */
2297 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2298 while (pos > 0 && (insv & 1) == sign)
2300 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2305 emit_insn (gen_insv (operand0, GEN_INT (len),
2306 GEN_INT (pos), GEN_INT (v5)));
2308 len = pos > 0 && pos < 5 ? pos : 5;
2315 = gen_rtx_EXPR_LIST (REG_EQUAL, op1, REG_NOTES (insn));
2320 /* Now have insn-emit do whatever it normally does. */
2324 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2325 it will need a link/runtime reloc). */
2328 reloc_needed (tree exp)
2332 switch (TREE_CODE (exp))
2339 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2340 reloc |= reloc_needed (TREE_OPERAND (exp, 1));
2345 case NON_LVALUE_EXPR:
2346 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2352 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2353 if (TREE_VALUE (link) != 0)
2354 reloc |= reloc_needed (TREE_VALUE (link));
2367 /* Does operand (which is a symbolic_operand) live in text space?
2368 If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2372 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2374 if (GET_CODE (operand) == CONST)
2375 operand = XEXP (XEXP (operand, 0), 0);
2378 if (GET_CODE (operand) == SYMBOL_REF)
2379 return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2383 if (GET_CODE (operand) == SYMBOL_REF)
2384 return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2390 /* Return the best assembler insn template
2391 for moving operands[1] into operands[0] as a fullword. */
2393 singlemove_string (rtx *operands)
2395 HOST_WIDE_INT intval;
2397 if (GET_CODE (operands[0]) == MEM)
2398 return "stw %r1,%0";
2399 if (GET_CODE (operands[1]) == MEM)
2401 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2406 if (GET_MODE (operands[1]) != SFmode)
2409 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2411 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2412 REAL_VALUE_TO_TARGET_SINGLE (d, i);
2414 operands[1] = GEN_INT (i);
2415 /* Fall through to CONST_INT case. */
2417 if (GET_CODE (operands[1]) == CONST_INT)
2419 intval = INTVAL (operands[1]);
2421 if (VAL_14_BITS_P (intval))
2423 else if ((intval & 0x7ff) == 0)
2424 return "ldil L'%1,%0";
2425 else if (zdepi_cint_p (intval))
2426 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2428 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2430 return "copy %1,%0";
2434 /* Compute position (in OP[1]) and width (in OP[2])
2435 useful for copying IMM to a register using the zdepi
2436 instructions. Store the immediate value to insert in OP[0]. */
2438 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2442 /* Find the least significant set bit in IMM. */
2443 for (lsb = 0; lsb < 32; lsb++)
2450 /* Choose variants based on *sign* of the 5-bit field. */
2451 if ((imm & 0x10) == 0)
2452 len = (lsb <= 28) ? 4 : 32 - lsb;
2455 /* Find the width of the bitstring in IMM. */
2456 for (len = 5; len < 32; len++)
2458 if ((imm & (1 << len)) == 0)
2462 /* Sign extend IMM as a 5-bit value. */
2463 imm = (imm & 0xf) - 0x10;
2471 /* Compute position (in OP[1]) and width (in OP[2])
2472 useful for copying IMM to a register using the depdi,z
2473 instructions. Store the immediate value to insert in OP[0]. */
2475 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2477 HOST_WIDE_INT lsb, len;
2479 /* Find the least significant set bit in IMM. */
2480 for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
2487 /* Choose variants based on *sign* of the 5-bit field. */
2488 if ((imm & 0x10) == 0)
2489 len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
2490 ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
2493 /* Find the width of the bitstring in IMM. */
2494 for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
2496 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2500 /* Sign extend IMM as a 5-bit value. */
2501 imm = (imm & 0xf) - 0x10;
2509 /* Output assembler code to perform a doubleword move insn
2510 with operands OPERANDS. */
2513 output_move_double (rtx *operands)
2515 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2517 rtx addreg0 = 0, addreg1 = 0;
2519 /* First classify both operands. */
2521 if (REG_P (operands[0]))
2523 else if (offsettable_memref_p (operands[0]))
2525 else if (GET_CODE (operands[0]) == MEM)
2530 if (REG_P (operands[1]))
2532 else if (CONSTANT_P (operands[1]))
2534 else if (offsettable_memref_p (operands[1]))
2536 else if (GET_CODE (operands[1]) == MEM)
2541 /* Check for the cases that the operand constraints are not
2542 supposed to allow to happen. Abort if we get one,
2543 because generating code for these cases is painful. */
2545 if (optype0 != REGOP && optype1 != REGOP)
2548 /* Handle auto decrementing and incrementing loads and stores
2549 specifically, since the structure of the function doesn't work
2550 for them without major modification. Do it better when we learn
2551 this port about the general inc/dec addressing of PA.
2552 (This was written by tege. Chide him if it doesn't work.) */
2554 if (optype0 == MEMOP)
2556 /* We have to output the address syntax ourselves, since print_operand
2557 doesn't deal with the addresses we want to use. Fix this later. */
2559 rtx addr = XEXP (operands[0], 0);
2560 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2562 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2564 operands[0] = XEXP (addr, 0);
2565 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2568 if (!reg_overlap_mentioned_p (high_reg, addr))
2570 /* No overlap between high target register and address
2571 register. (We do this in a non-obvious way to
2572 save a register file writeback) */
2573 if (GET_CODE (addr) == POST_INC)
2574 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2575 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2580 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2582 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2584 operands[0] = XEXP (addr, 0);
2585 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2588 if (!reg_overlap_mentioned_p (high_reg, addr))
2590 /* No overlap between high target register and address
2591 register. (We do this in a non-obvious way to
2592 save a register file writeback) */
2593 if (GET_CODE (addr) == PRE_INC)
2594 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2595 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2601 if (optype1 == MEMOP)
2603 /* We have to output the address syntax ourselves, since print_operand
2604 doesn't deal with the addresses we want to use. Fix this later. */
2606 rtx addr = XEXP (operands[1], 0);
2607 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2609 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2611 operands[1] = XEXP (addr, 0);
2612 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2615 if (!reg_overlap_mentioned_p (high_reg, addr))
2617 /* No overlap between high target register and address
2618 register. (We do this in a non-obvious way to
2619 save a register file writeback) */
2620 if (GET_CODE (addr) == POST_INC)
2621 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2622 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2626 /* This is an undefined situation. We should load into the
2627 address register *and* update that register. Probably
2628 we don't need to handle this at all. */
2629 if (GET_CODE (addr) == POST_INC)
2630 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2631 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2634 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2636 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2638 operands[1] = XEXP (addr, 0);
2639 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2642 if (!reg_overlap_mentioned_p (high_reg, addr))
2644 /* No overlap between high target register and address
2645 register. (We do this in a non-obvious way to
2646 save a register file writeback) */
2647 if (GET_CODE (addr) == PRE_INC)
2648 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2649 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2653 /* This is an undefined situation. We should load into the
2654 address register *and* update that register. Probably
2655 we don't need to handle this at all. */
2656 if (GET_CODE (addr) == PRE_INC)
2657 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2658 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2661 else if (GET_CODE (addr) == PLUS
2662 && GET_CODE (XEXP (addr, 0)) == MULT)
2664 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2666 if (!reg_overlap_mentioned_p (high_reg, addr))
2670 xoperands[0] = high_reg;
2671 xoperands[1] = XEXP (addr, 1);
2672 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2673 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2674 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2676 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2682 xoperands[0] = high_reg;
2683 xoperands[1] = XEXP (addr, 1);
2684 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2685 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2686 output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2688 return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2693 /* If an operand is an unoffsettable memory ref, find a register
2694 we can increment temporarily to make it refer to the second word. */
2696 if (optype0 == MEMOP)
2697 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2699 if (optype1 == MEMOP)
2700 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2702 /* Ok, we can do one word at a time.
2703 Normally we do the low-numbered word first.
2705 In either case, set up in LATEHALF the operands to use
2706 for the high-numbered word and in some cases alter the
2707 operands in OPERANDS to be suitable for the low-numbered word. */
2709 if (optype0 == REGOP)
2710 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2711 else if (optype0 == OFFSOP)
2712 latehalf[0] = adjust_address (operands[0], SImode, 4);
2714 latehalf[0] = operands[0];
2716 if (optype1 == REGOP)
2717 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2718 else if (optype1 == OFFSOP)
2719 latehalf[1] = adjust_address (operands[1], SImode, 4);
2720 else if (optype1 == CNSTOP)
2721 split_double (operands[1], &operands[1], &latehalf[1]);
2723 latehalf[1] = operands[1];
2725 /* If the first move would clobber the source of the second one,
2726 do them in the other order.
2728 This can happen in two cases:
2730 mem -> register where the first half of the destination register
2731 is the same register used in the memory's address. Reload
2732 can create such insns.
2734 mem in this case will be either register indirect or register
2735 indirect plus a valid offset.
2737 register -> register move where REGNO(dst) == REGNO(src + 1)
2738 someone (Tim/Tege?) claimed this can happen for parameter loads.
2740 Handle mem -> register case first. */
2741 if (optype0 == REGOP
2742 && (optype1 == MEMOP || optype1 == OFFSOP)
2743 && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2746 /* Do the late half first. */
2748 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2749 output_asm_insn (singlemove_string (latehalf), latehalf);
2753 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2754 return singlemove_string (operands);
2757 /* Now handle register -> register case. */
2758 if (optype0 == REGOP && optype1 == REGOP
2759 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2761 output_asm_insn (singlemove_string (latehalf), latehalf);
2762 return singlemove_string (operands);
2765 /* Normal case: do the two words, low-numbered first. */
2767 output_asm_insn (singlemove_string (operands), operands);
2769 /* Make any unoffsettable addresses point at high-numbered word. */
2771 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2773 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2776 output_asm_insn (singlemove_string (latehalf), latehalf);
2778 /* Undo the adds we just did. */
2780 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2782 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2788 output_fp_move_double (rtx *operands)
2790 if (FP_REG_P (operands[0]))
2792 if (FP_REG_P (operands[1])
2793 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2794 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2796 output_asm_insn ("fldd%F1 %1,%0", operands);
2798 else if (FP_REG_P (operands[1]))
2800 output_asm_insn ("fstd%F0 %1,%0", operands);
2802 else if (operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2804 if (GET_CODE (operands[0]) == REG)
2807 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2808 xoperands[0] = operands[0];
2809 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2811 /* This is a pain. You have to be prepared to deal with an
2812 arbitrary address here including pre/post increment/decrement.
2814 so avoid this in the MD. */
2822 /* Return a REG that occurs in ADDR with coefficient 1.
2823 ADDR can be effectively incremented by incrementing REG. */
2826 find_addr_reg (rtx addr)
2828 while (GET_CODE (addr) == PLUS)
2830 if (GET_CODE (XEXP (addr, 0)) == REG)
2831 addr = XEXP (addr, 0);
2832 else if (GET_CODE (XEXP (addr, 1)) == REG)
2833 addr = XEXP (addr, 1);
2834 else if (CONSTANT_P (XEXP (addr, 0)))
2835 addr = XEXP (addr, 1);
2836 else if (CONSTANT_P (XEXP (addr, 1)))
2837 addr = XEXP (addr, 0);
2841 if (GET_CODE (addr) == REG)
2846 /* Emit code to perform a block move.
2848 OPERANDS[0] is the destination pointer as a REG, clobbered.
2849 OPERANDS[1] is the source pointer as a REG, clobbered.
2850 OPERANDS[2] is a register for temporary storage.
2851 OPERANDS[3] is a register for temporary storage.
2852 OPERANDS[4] is the size as a CONST_INT
2853 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2854 OPERANDS[6] is another temporary register. */
2857 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2859 int align = INTVAL (operands[5]);
2860 unsigned long n_bytes = INTVAL (operands[4]);
2862 /* We can't move more than a word at a time because the PA
2863 has no longer integer move insns. (Could use fp mem ops?) */
2864 if (align > (TARGET_64BIT ? 8 : 4))
2865 align = (TARGET_64BIT ? 8 : 4);
2867 /* Note that we know each loop below will execute at least twice
2868 (else we would have open-coded the copy). */
2872 /* Pre-adjust the loop counter. */
2873 operands[4] = GEN_INT (n_bytes - 16);
2874 output_asm_insn ("ldi %4,%2", operands);
2877 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2878 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2879 output_asm_insn ("std,ma %3,8(%0)", operands);
2880 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2881 output_asm_insn ("std,ma %6,8(%0)", operands);
2883 /* Handle the residual. There could be up to 7 bytes of
2884 residual to copy! */
2885 if (n_bytes % 16 != 0)
2887 operands[4] = GEN_INT (n_bytes % 8);
2888 if (n_bytes % 16 >= 8)
2889 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2890 if (n_bytes % 8 != 0)
2891 output_asm_insn ("ldd 0(%1),%6", operands);
2892 if (n_bytes % 16 >= 8)
2893 output_asm_insn ("std,ma %3,8(%0)", operands);
2894 if (n_bytes % 8 != 0)
2895 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2900 /* Pre-adjust the loop counter. */
2901 operands[4] = GEN_INT (n_bytes - 8);
2902 output_asm_insn ("ldi %4,%2", operands);
2905 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2906 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2907 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2908 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2909 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2911 /* Handle the residual. There could be up to 7 bytes of
2912 residual to copy! */
2913 if (n_bytes % 8 != 0)
2915 operands[4] = GEN_INT (n_bytes % 4);
2916 if (n_bytes % 8 >= 4)
2917 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2918 if (n_bytes % 4 != 0)
2919 output_asm_insn ("ldw 0(%1),%6", operands);
2920 if (n_bytes % 8 >= 4)
2921 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2922 if (n_bytes % 4 != 0)
2923 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2928 /* Pre-adjust the loop counter. */
2929 operands[4] = GEN_INT (n_bytes - 4);
2930 output_asm_insn ("ldi %4,%2", operands);
2933 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2934 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2935 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2936 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2937 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2939 /* Handle the residual. */
2940 if (n_bytes % 4 != 0)
2942 if (n_bytes % 4 >= 2)
2943 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2944 if (n_bytes % 2 != 0)
2945 output_asm_insn ("ldb 0(%1),%6", operands);
2946 if (n_bytes % 4 >= 2)
2947 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2948 if (n_bytes % 2 != 0)
2949 output_asm_insn ("stb %6,0(%0)", operands);
2954 /* Pre-adjust the loop counter. */
2955 operands[4] = GEN_INT (n_bytes - 2);
2956 output_asm_insn ("ldi %4,%2", operands);
2959 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2960 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2961 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2962 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2963 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2965 /* Handle the residual. */
2966 if (n_bytes % 2 != 0)
2968 output_asm_insn ("ldb 0(%1),%3", operands);
2969 output_asm_insn ("stb %3,0(%0)", operands);
2978 /* Count the number of insns necessary to handle this block move.
2980 Basic structure is the same as emit_block_move, except that we
2981 count insns rather than emit them. */
2984 compute_movmem_length (rtx insn)
2986 rtx pat = PATTERN (insn);
2987 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2988 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2989 unsigned int n_insns = 0;
2991 /* We can't move more than four bytes at a time because the PA
2992 has no longer integer move insns. (Could use fp mem ops?) */
2993 if (align > (TARGET_64BIT ? 8 : 4))
2994 align = (TARGET_64BIT ? 8 : 4);
2996 /* The basic copying loop. */
3000 if (n_bytes % (2 * align) != 0)
3002 if ((n_bytes % (2 * align)) >= align)
3005 if ((n_bytes % align) != 0)
3009 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3013 /* Emit code to perform a block clear.
3015 OPERANDS[0] is the destination pointer as a REG, clobbered.
3016 OPERANDS[1] is a register for temporary storage.
3017 OPERANDS[2] is the size as a CONST_INT
3018 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
3021 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
3023 int align = INTVAL (operands[3]);
3024 unsigned long n_bytes = INTVAL (operands[2]);
3026 /* We can't clear more than a word at a time because the PA
3027 has no longer integer move insns. */
3028 if (align > (TARGET_64BIT ? 8 : 4))
3029 align = (TARGET_64BIT ? 8 : 4);
3031 /* Note that we know each loop below will execute at least twice
3032 (else we would have open-coded the copy). */
3036 /* Pre-adjust the loop counter. */
3037 operands[2] = GEN_INT (n_bytes - 16);
3038 output_asm_insn ("ldi %2,%1", operands);
3041 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3042 output_asm_insn ("addib,>= -16,%1,.-4", operands);
3043 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3045 /* Handle the residual. There could be up to 7 bytes of
3046 residual to copy! */
3047 if (n_bytes % 16 != 0)
3049 operands[2] = GEN_INT (n_bytes % 8);
3050 if (n_bytes % 16 >= 8)
3051 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3052 if (n_bytes % 8 != 0)
3053 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
3058 /* Pre-adjust the loop counter. */
3059 operands[2] = GEN_INT (n_bytes - 8);
3060 output_asm_insn ("ldi %2,%1", operands);
3063 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3064 output_asm_insn ("addib,>= -8,%1,.-4", operands);
3065 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3067 /* Handle the residual. There could be up to 7 bytes of
3068 residual to copy! */
3069 if (n_bytes % 8 != 0)
3071 operands[2] = GEN_INT (n_bytes % 4);
3072 if (n_bytes % 8 >= 4)
3073 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3074 if (n_bytes % 4 != 0)
3075 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
3080 /* Pre-adjust the loop counter. */
3081 operands[2] = GEN_INT (n_bytes - 4);
3082 output_asm_insn ("ldi %2,%1", operands);
3085 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3086 output_asm_insn ("addib,>= -4,%1,.-4", operands);
3087 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3089 /* Handle the residual. */
3090 if (n_bytes % 4 != 0)
3092 if (n_bytes % 4 >= 2)
3093 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3094 if (n_bytes % 2 != 0)
3095 output_asm_insn ("stb %%r0,0(%0)", operands);
3100 /* Pre-adjust the loop counter. */
3101 operands[2] = GEN_INT (n_bytes - 2);
3102 output_asm_insn ("ldi %2,%1", operands);
3105 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3106 output_asm_insn ("addib,>= -2,%1,.-4", operands);
3107 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3109 /* Handle the residual. */
3110 if (n_bytes % 2 != 0)
3111 output_asm_insn ("stb %%r0,0(%0)", operands);
3120 /* Count the number of insns necessary to handle this block move.
3122 Basic structure is the same as emit_block_move, except that we
3123 count insns rather than emit them. */
3126 compute_clrmem_length (rtx insn)
3128 rtx pat = PATTERN (insn);
3129 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
3130 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
3131 unsigned int n_insns = 0;
3133 /* We can't clear more than a word at a time because the PA
3134 has no longer integer move insns. */
3135 if (align > (TARGET_64BIT ? 8 : 4))
3136 align = (TARGET_64BIT ? 8 : 4);
3138 /* The basic loop. */
3142 if (n_bytes % (2 * align) != 0)
3144 if ((n_bytes % (2 * align)) >= align)
3147 if ((n_bytes % align) != 0)
3151 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3157 output_and (rtx *operands)
3159 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3161 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3162 int ls0, ls1, ms0, p, len;
3164 for (ls0 = 0; ls0 < 32; ls0++)
3165 if ((mask & (1 << ls0)) == 0)
3168 for (ls1 = ls0; ls1 < 32; ls1++)
3169 if ((mask & (1 << ls1)) != 0)
3172 for (ms0 = ls1; ms0 < 32; ms0++)
3173 if ((mask & (1 << ms0)) == 0)
3186 operands[2] = GEN_INT (len);
3187 return "{extru|extrw,u} %1,31,%2,%0";
3191 /* We could use this `depi' for the case above as well, but `depi'
3192 requires one more register file access than an `extru'. */
3197 operands[2] = GEN_INT (p);
3198 operands[3] = GEN_INT (len);
3199 return "{depi|depwi} 0,%2,%3,%0";
3203 return "and %1,%2,%0";
3206 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3207 storing the result in operands[0]. */
3209 output_64bit_and (rtx *operands)
3211 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3213 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3214 int ls0, ls1, ms0, p, len;
3216 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
3217 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
3220 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
3221 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
3224 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
3225 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
3228 if (ms0 != HOST_BITS_PER_WIDE_INT)
3231 if (ls1 == HOST_BITS_PER_WIDE_INT)
3238 operands[2] = GEN_INT (len);
3239 return "extrd,u %1,63,%2,%0";
3243 /* We could use this `depi' for the case above as well, but `depi'
3244 requires one more register file access than an `extru'. */
3249 operands[2] = GEN_INT (p);
3250 operands[3] = GEN_INT (len);
3251 return "depdi 0,%2,%3,%0";
3255 return "and %1,%2,%0";
3259 output_ior (rtx *operands)
3261 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3262 int bs0, bs1, p, len;
3264 if (INTVAL (operands[2]) == 0)
3265 return "copy %1,%0";
3267 for (bs0 = 0; bs0 < 32; bs0++)
3268 if ((mask & (1 << bs0)) != 0)
3271 for (bs1 = bs0; bs1 < 32; bs1++)
3272 if ((mask & (1 << bs1)) == 0)
3275 if (bs1 != 32 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3281 operands[2] = GEN_INT (p);
3282 operands[3] = GEN_INT (len);
3283 return "{depi|depwi} -1,%2,%3,%0";
3286 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3287 storing the result in operands[0]. */
3289 output_64bit_ior (rtx *operands)
3291 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3292 int bs0, bs1, p, len;
3294 if (INTVAL (operands[2]) == 0)
3295 return "copy %1,%0";
3297 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3298 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3301 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3302 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3305 if (bs1 != HOST_BITS_PER_WIDE_INT
3306 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3312 operands[2] = GEN_INT (p);
3313 operands[3] = GEN_INT (len);
3314 return "depdi -1,%2,%3,%0";
3317 /* Target hook for assembling integer objects. This code handles
3318 aligned SI and DI integers specially since function references
3319 must be preceded by P%. */
3322 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3324 if (size == UNITS_PER_WORD
3326 && function_label_operand (x, VOIDmode))
3328 fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
3329 output_addr_const (asm_out_file, x);
3330 fputc ('\n', asm_out_file);
3333 return default_assemble_integer (x, size, aligned_p);
3336 /* Output an ascii string. */
3338 output_ascii (FILE *file, const char *p, int size)
3342 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3344 /* The HP assembler can only take strings of 256 characters at one
3345 time. This is a limitation on input line length, *not* the
3346 length of the string. Sigh. Even worse, it seems that the
3347 restriction is in number of input characters (see \xnn &
3348 \whatever). So we have to do this very carefully. */
3350 fputs ("\t.STRING \"", file);
3353 for (i = 0; i < size; i += 4)
3357 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3359 register unsigned int c = (unsigned char) p[i + io];
3361 if (c == '\"' || c == '\\')
3362 partial_output[co++] = '\\';
3363 if (c >= ' ' && c < 0177)
3364 partial_output[co++] = c;
3368 partial_output[co++] = '\\';
3369 partial_output[co++] = 'x';
3370 hexd = c / 16 - 0 + '0';
3372 hexd -= '9' - 'a' + 1;
3373 partial_output[co++] = hexd;
3374 hexd = c % 16 - 0 + '0';
3376 hexd -= '9' - 'a' + 1;
3377 partial_output[co++] = hexd;
3380 if (chars_output + co > 243)
3382 fputs ("\"\n\t.STRING \"", file);
3385 fwrite (partial_output, 1, (size_t) co, file);
3389 fputs ("\"\n", file);
3392 /* Try to rewrite floating point comparisons & branches to avoid
3393 useless add,tr insns.
3395 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3396 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3397 first attempt to remove useless add,tr insns. It is zero
3398 for the second pass as reorg sometimes leaves bogus REG_DEAD
3401 When CHECK_NOTES is zero we can only eliminate add,tr insns
3402 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3405 remove_useless_addtr_insns (int check_notes)
3408 static int pass = 0;
3410 /* This is fairly cheap, so always run it when optimizing. */
3414 int fbranch_count = 0;
3416 /* Walk all the insns in this function looking for fcmp & fbranch
3417 instructions. Keep track of how many of each we find. */
3418 for (insn = get_insns (); insn; insn = next_insn (insn))
3422 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3423 if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3426 tmp = PATTERN (insn);
3428 /* It must be a set. */
3429 if (GET_CODE (tmp) != SET)
3432 /* If the destination is CCFP, then we've found an fcmp insn. */
3433 tmp = SET_DEST (tmp);
3434 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3440 tmp = PATTERN (insn);
3441 /* If this is an fbranch instruction, bump the fbranch counter. */
3442 if (GET_CODE (tmp) == SET
3443 && SET_DEST (tmp) == pc_rtx
3444 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3445 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3446 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3447 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3455 /* Find all floating point compare + branch insns. If possible,
3456 reverse the comparison & the branch to avoid add,tr insns. */
3457 for (insn = get_insns (); insn; insn = next_insn (insn))
3461 /* Ignore anything that isn't an INSN. */
3462 if (GET_CODE (insn) != INSN)
3465 tmp = PATTERN (insn);
3467 /* It must be a set. */
3468 if (GET_CODE (tmp) != SET)
3471 /* The destination must be CCFP, which is register zero. */
3472 tmp = SET_DEST (tmp);
3473 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3476 /* INSN should be a set of CCFP.
3478 See if the result of this insn is used in a reversed FP
3479 conditional branch. If so, reverse our condition and
3480 the branch. Doing so avoids useless add,tr insns. */
3481 next = next_insn (insn);
3484 /* Jumps, calls and labels stop our search. */
3485 if (GET_CODE (next) == JUMP_INSN
3486 || GET_CODE (next) == CALL_INSN
3487 || GET_CODE (next) == CODE_LABEL)
3490 /* As does another fcmp insn. */
3491 if (GET_CODE (next) == INSN
3492 && GET_CODE (PATTERN (next)) == SET
3493 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3494 && REGNO (SET_DEST (PATTERN (next))) == 0)
3497 next = next_insn (next);
3500 /* Is NEXT_INSN a branch? */
3502 && GET_CODE (next) == JUMP_INSN)
3504 rtx pattern = PATTERN (next);
3506 /* If it a reversed fp conditional branch (e.g. uses add,tr)
3507 and CCFP dies, then reverse our conditional and the branch
3508 to avoid the add,tr. */
3509 if (GET_CODE (pattern) == SET
3510 && SET_DEST (pattern) == pc_rtx
3511 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3512 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3513 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3514 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3515 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3516 && (fcmp_count == fbranch_count
3518 && find_regno_note (next, REG_DEAD, 0))))
3520 /* Reverse the branch. */
3521 tmp = XEXP (SET_SRC (pattern), 1);
3522 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3523 XEXP (SET_SRC (pattern), 2) = tmp;
3524 INSN_CODE (next) = -1;
3526 /* Reverse our condition. */
3527 tmp = PATTERN (insn);
3528 PUT_CODE (XEXP (tmp, 1),
3529 (reverse_condition_maybe_unordered
3530 (GET_CODE (XEXP (tmp, 1)))));
3540 /* You may have trouble believing this, but this is the 32 bit HP-PA
3545 Variable arguments (optional; any number may be allocated)
3547 SP-(4*(N+9)) arg word N
3552 Fixed arguments (must be allocated; may remain unused)
3561 SP-32 External Data Pointer (DP)
3563 SP-24 External/stub RP (RP')
3567 SP-8 Calling Stub RP (RP'')
3572 SP-0 Stack Pointer (points to next available address)
3576 /* This function saves registers as follows. Registers marked with ' are
3577 this function's registers (as opposed to the previous function's).
3578 If a frame_pointer isn't needed, r4 is saved as a general register;
3579 the space for the frame pointer is still allocated, though, to keep
3585 SP (FP') Previous FP
3586 SP + 4 Alignment filler (sigh)
3587 SP + 8 Space for locals reserved here.
3591 SP + n All call saved register used.
3595 SP + o All call saved fp registers used.
3599 SP + p (SP') points to next available address.
3603 /* Global variables set by output_function_prologue(). */
3604 /* Size of frame. Need to know this to emit return insns from
3606 static HOST_WIDE_INT actual_fsize, local_fsize;
3607 static int save_fregs;
3609 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3610 Handle case where DISP > 8k by using the add_high_const patterns.
3612 Note in DISP > 8k case, we will leave the high part of the address
3613 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3616 store_reg (int reg, HOST_WIDE_INT disp, int base)
3618 rtx insn, dest, src, basereg;
3620 src = gen_rtx_REG (word_mode, reg);
3621 basereg = gen_rtx_REG (Pmode, base);
3622 if (VAL_14_BITS_P (disp))
3624 dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3625 insn = emit_move_insn (dest, src);
3627 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3629 rtx delta = GEN_INT (disp);
3630 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3632 emit_move_insn (tmpreg, delta);
3633 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3634 dest = gen_rtx_MEM (word_mode, tmpreg);
3635 insn = emit_move_insn (dest, src);
3639 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3640 gen_rtx_SET (VOIDmode,
3641 gen_rtx_MEM (word_mode,
3642 gen_rtx_PLUS (word_mode, basereg,
3650 rtx delta = GEN_INT (disp);
3651 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3652 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3654 emit_move_insn (tmpreg, high);
3655 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3656 insn = emit_move_insn (dest, src);
3660 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3661 gen_rtx_SET (VOIDmode,
3662 gen_rtx_MEM (word_mode,
3663 gen_rtx_PLUS (word_mode, basereg,
3671 RTX_FRAME_RELATED_P (insn) = 1;
3674 /* Emit RTL to store REG at the memory location specified by BASE and then
3675 add MOD to BASE. MOD must be <= 8k. */
3678 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3680 rtx insn, basereg, srcreg, delta;
3682 if (!VAL_14_BITS_P (mod))
3685 basereg = gen_rtx_REG (Pmode, base);
3686 srcreg = gen_rtx_REG (word_mode, reg);
3687 delta = GEN_INT (mod);
3689 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3692 RTX_FRAME_RELATED_P (insn) = 1;
3694 /* RTX_FRAME_RELATED_P must be set on each frame related set
3695 in a parallel with more than one element. Don't set
3696 RTX_FRAME_RELATED_P in the first set if reg is temporary
3697 register 1. The effect of this operation is recorded in
3698 the initial copy. */
3701 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3702 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3706 /* The first element of a PARALLEL is always processed if it is
3707 a SET. Thus, we need an expression list for this case. */
3709 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3710 gen_rtx_SET (VOIDmode, basereg,
3711 gen_rtx_PLUS (word_mode, basereg, delta)),
3717 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
3718 where DISP > 8k by using the add_high_const patterns. NOTE indicates
3719 whether to add a frame note or not.
3721 In the DISP > 8k case, we leave the high part of the address in %r1.
3722 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
3725 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3729 if (VAL_14_BITS_P (disp))
3731 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3732 plus_constant (gen_rtx_REG (Pmode, base), disp));
3734 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3736 rtx basereg = gen_rtx_REG (Pmode, base);
3737 rtx delta = GEN_INT (disp);
3738 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3740 emit_move_insn (tmpreg, delta);
3741 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3742 gen_rtx_PLUS (Pmode, tmpreg, basereg));
3746 rtx basereg = gen_rtx_REG (Pmode, base);
3747 rtx delta = GEN_INT (disp);
3748 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3750 emit_move_insn (tmpreg,
3751 gen_rtx_PLUS (Pmode, basereg,
3752 gen_rtx_HIGH (Pmode, delta)));
3753 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3754 gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3757 if (DO_FRAME_NOTES && note)
3758 RTX_FRAME_RELATED_P (insn) = 1;
3762 compute_frame_size (HOST_WIDE_INT size, int *fregs_live)
3767 /* The code in hppa_expand_prologue and hppa_expand_epilogue must
3768 be consistent with the rounding and size calculation done here.
3769 Change them at the same time. */
3771 /* We do our own stack alignment. First, round the size of the
3772 stack locals up to a word boundary. */
3773 size = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3775 /* Space for previous frame pointer + filler. If any frame is
3776 allocated, we need to add in the STARTING_FRAME_OFFSET. We
3777 waste some space here for the sake of HP compatibility. The
3778 first slot is only used when the frame pointer is needed. */
3779 if (size || frame_pointer_needed)
3780 size += STARTING_FRAME_OFFSET;
3782 /* If the current function calls __builtin_eh_return, then we need
3783 to allocate stack space for registers that will hold data for
3784 the exception handler. */
3785 if (DO_FRAME_NOTES && current_function_calls_eh_return)
3789 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
3791 size += i * UNITS_PER_WORD;
3794 /* Account for space used by the callee general register saves. */
3795 for (i = 18, j = frame_pointer_needed ? 4 : 3; i >= j; i--)
3796 if (regs_ever_live[i])
3797 size += UNITS_PER_WORD;
3799 /* Account for space used by the callee floating point register saves. */
3800 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3801 if (regs_ever_live[i]
3802 || (!TARGET_64BIT && regs_ever_live[i + 1]))
3806 /* We always save both halves of the FP register, so always
3807 increment the frame size by 8 bytes. */
3811 /* If any of the floating registers are saved, account for the
3812 alignment needed for the floating point register save block. */
3815 size = (size + 7) & ~7;
3820 /* The various ABIs include space for the outgoing parameters in the
3821 size of the current function's stack frame. We don't need to align
3822 for the outgoing arguments as their alignment is set by the final
3823 rounding for the frame as a whole. */
3824 size += current_function_outgoing_args_size;
3826 /* Allocate space for the fixed frame marker. This space must be
3827 allocated for any function that makes calls or allocates
3829 if (!current_function_is_leaf || size)
3830 size += TARGET_64BIT ? 48 : 32;
3832 /* Finally, round to the preferred stack boundary. */
3833 return ((size + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)
3834 & ~(PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1));
3837 /* Generate the assembly code for function entry. FILE is a stdio
3838 stream to output the code to. SIZE is an int: how many units of
3839 temporary storage to allocate.
3841 Refer to the array `regs_ever_live' to determine which registers to
3842 save; `regs_ever_live[I]' is nonzero if register number I is ever
3843 used in the function. This function is responsible for knowing
3844 which registers should not be saved even if used. */
3846 /* On HP-PA, move-double insns between fpu and cpu need an 8-byte block
3847 of memory. If any fpu reg is used in the function, we allocate
3848 such a block here, at the bottom of the frame, just in case it's needed.
3850 If this function is a leaf procedure, then we may choose not
3851 to do a "save" insn. The decision about whether or not
3852 to do this is made in regclass.c. */
3855 pa_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3857 /* The function's label and associated .PROC must never be
3858 separated and must be output *after* any profiling declarations
3859 to avoid changing spaces/subspaces within a procedure. */
3860 ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3861 fputs ("\t.PROC\n", file);
3863 /* hppa_expand_prologue does the dirty work now. We just need
3864 to output the assembler directives which denote the start
3866 fprintf (file, "\t.CALLINFO FRAME=" HOST_WIDE_INT_PRINT_DEC, actual_fsize);
3867 if (regs_ever_live[2])
3868 fputs (",CALLS,SAVE_RP", file);
3870 fputs (",NO_CALLS", file);
3872 /* The SAVE_SP flag is used to indicate that register %r3 is stored
3873 at the beginning of the frame and that it is used as the frame
3874 pointer for the frame. We do this because our current frame
3875 layout doesn't conform to that specified in the the HP runtime
3876 documentation and we need a way to indicate to programs such as
3877 GDB where %r3 is saved. The SAVE_SP flag was chosen because it
3878 isn't used by HP compilers but is supported by the assembler.
3879 However, SAVE_SP is supposed to indicate that the previous stack
3880 pointer has been saved in the frame marker. */
3881 if (frame_pointer_needed)
3882 fputs (",SAVE_SP", file);
3884 /* Pass on information about the number of callee register saves
3885 performed in the prologue.
3887 The compiler is supposed to pass the highest register number
3888 saved, the assembler then has to adjust that number before
3889 entering it into the unwind descriptor (to account for any
3890 caller saved registers with lower register numbers than the
3891 first callee saved register). */
3893 fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
3896 fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
3898 fputs ("\n\t.ENTRY\n", file);
3900 remove_useless_addtr_insns (0);
3904 hppa_expand_prologue (void)
3906 int merge_sp_adjust_with_store = 0;
3907 HOST_WIDE_INT size = get_frame_size ();
3908 HOST_WIDE_INT offset;
3916 /* Compute total size for frame pointer, filler, locals and rounding to
3917 the next word boundary. Similar code appears in compute_frame_size
3918 and must be changed in tandem with this code. */
3919 local_fsize = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3920 if (local_fsize || frame_pointer_needed)
3921 local_fsize += STARTING_FRAME_OFFSET;
3923 actual_fsize = compute_frame_size (size, &save_fregs);
3925 /* Compute a few things we will use often. */
3926 tmpreg = gen_rtx_REG (word_mode, 1);
3928 /* Save RP first. The calling conventions manual states RP will
3929 always be stored into the caller's frame at sp - 20 or sp - 16
3930 depending on which ABI is in use. */
3931 if (regs_ever_live[2] || current_function_calls_eh_return)
3932 store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM);
3934 /* Allocate the local frame and set up the frame pointer if needed. */
3935 if (actual_fsize != 0)
3937 if (frame_pointer_needed)
3939 /* Copy the old frame pointer temporarily into %r1. Set up the
3940 new stack pointer, then store away the saved old frame pointer
3941 into the stack at sp and at the same time update the stack
3942 pointer by actual_fsize bytes. Two versions, first
3943 handles small (<8k) frames. The second handles large (>=8k)
3945 insn = emit_move_insn (tmpreg, frame_pointer_rtx);
3948 /* We need to record the frame pointer save here since the
3949 new frame pointer is set in the following insn. */
3950 RTX_FRAME_RELATED_P (insn) = 1;
3952 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3953 gen_rtx_SET (VOIDmode,
3954 gen_rtx_MEM (word_mode, stack_pointer_rtx),
3959 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
3961 RTX_FRAME_RELATED_P (insn) = 1;
3963 if (VAL_14_BITS_P (actual_fsize))
3964 store_reg_modify (STACK_POINTER_REGNUM, 1, actual_fsize);
3967 /* It is incorrect to store the saved frame pointer at *sp,
3968 then increment sp (writes beyond the current stack boundary).
3970 So instead use stwm to store at *sp and post-increment the
3971 stack pointer as an atomic operation. Then increment sp to
3972 finish allocating the new frame. */
3973 HOST_WIDE_INT adjust1 = 8192 - 64;
3974 HOST_WIDE_INT adjust2 = actual_fsize - adjust1;
3976 store_reg_modify (STACK_POINTER_REGNUM, 1, adjust1);
3977 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3981 /* We set SAVE_SP in frames that need a frame pointer. Thus,
3982 we need to store the previous stack pointer (frame pointer)
3983 into the frame marker on targets that use the HP unwind
3984 library. This allows the HP unwind library to be used to
3985 unwind GCC frames. However, we are not fully compatible
3986 with the HP library because our frame layout differs from