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, 2006, 2007 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, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, 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"
52 /* Return nonzero if there is a bypass for the output of
53 OUT_INSN and the fp store IN_INSN. */
55 hppa_fpstore_bypass_p (rtx out_insn, rtx in_insn)
57 enum machine_mode store_mode;
58 enum machine_mode other_mode;
61 if (recog_memoized (in_insn) < 0
62 || (get_attr_type (in_insn) != TYPE_FPSTORE
63 && get_attr_type (in_insn) != TYPE_FPSTORE_LOAD)
64 || recog_memoized (out_insn) < 0)
67 store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
69 set = single_set (out_insn);
73 other_mode = GET_MODE (SET_SRC (set));
75 return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
79 #ifndef DO_FRAME_NOTES
80 #ifdef INCOMING_RETURN_ADDR_RTX
81 #define DO_FRAME_NOTES 1
83 #define DO_FRAME_NOTES 0
87 static void copy_reg_pointer (rtx, rtx);
88 static void fix_range (const char *);
89 static bool pa_handle_option (size_t, const char *, int);
90 static int hppa_address_cost (rtx);
91 static bool hppa_rtx_costs (rtx, int, int, int *);
92 static inline rtx force_mode (enum machine_mode, rtx);
93 static void pa_reorg (void);
94 static void pa_combine_instructions (void);
95 static int pa_can_combine_p (rtx, rtx, rtx, int, rtx, rtx, rtx);
96 static int forward_branch_p (rtx);
97 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
98 static int compute_movmem_length (rtx);
99 static int compute_clrmem_length (rtx);
100 static bool pa_assemble_integer (rtx, unsigned int, int);
101 static void remove_useless_addtr_insns (int);
102 static void store_reg (int, HOST_WIDE_INT, int);
103 static void store_reg_modify (int, int, HOST_WIDE_INT);
104 static void load_reg (int, HOST_WIDE_INT, int);
105 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
106 static void pa_output_function_prologue (FILE *, HOST_WIDE_INT);
107 static void update_total_code_bytes (int);
108 static void pa_output_function_epilogue (FILE *, HOST_WIDE_INT);
109 static int pa_adjust_cost (rtx, rtx, rtx, int);
110 static int pa_adjust_priority (rtx, int);
111 static int pa_issue_rate (void);
112 static void pa_som_asm_init_sections (void) ATTRIBUTE_UNUSED;
113 static section *pa_select_section (tree, int, unsigned HOST_WIDE_INT)
115 static void pa_encode_section_info (tree, rtx, int);
116 static const char *pa_strip_name_encoding (const char *);
117 static bool pa_function_ok_for_sibcall (tree, tree);
118 static void pa_globalize_label (FILE *, const char *)
120 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
121 HOST_WIDE_INT, tree);
122 #if !defined(USE_COLLECT2)
123 static void pa_asm_out_constructor (rtx, int);
124 static void pa_asm_out_destructor (rtx, int);
126 static void pa_init_builtins (void);
127 static rtx hppa_builtin_saveregs (void);
128 static tree hppa_gimplify_va_arg_expr (tree, tree, tree *, tree *);
129 static bool pa_scalar_mode_supported_p (enum machine_mode);
130 static bool pa_commutative_p (rtx x, int outer_code);
131 static void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
132 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
133 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
134 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
135 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
136 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
137 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
138 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
139 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
140 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
141 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
142 static void output_deferred_plabels (void);
143 static void output_deferred_profile_counters (void) ATTRIBUTE_UNUSED;
144 #ifdef ASM_OUTPUT_EXTERNAL_REAL
145 static void pa_hpux_file_end (void);
147 #ifdef HPUX_LONG_DOUBLE_LIBRARY
148 static void pa_hpux_init_libfuncs (void);
150 static rtx pa_struct_value_rtx (tree, int);
151 static bool pa_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
153 static int pa_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
155 static struct machine_function * pa_init_machine_status (void);
156 static enum reg_class pa_secondary_reload (bool, rtx, enum reg_class,
158 secondary_reload_info *);
161 /* The following extra sections are only used for SOM. */
162 static GTY(()) section *som_readonly_data_section;
163 static GTY(()) section *som_one_only_readonly_data_section;
164 static GTY(()) section *som_one_only_data_section;
166 /* Save the operands last given to a compare for use when we
167 generate a scc or bcc insn. */
168 rtx hppa_compare_op0, hppa_compare_op1;
169 enum cmp_type hppa_branch_type;
171 /* Which cpu we are scheduling for. */
172 enum processor_type pa_cpu = TARGET_SCHED_DEFAULT;
174 /* The UNIX standard to use for predefines and linking. */
175 int flag_pa_unix = TARGET_HPUX_11_11 ? 1998 : TARGET_HPUX_10_10 ? 1995 : 1993;
177 /* Counts for the number of callee-saved general and floating point
178 registers which were saved by the current function's prologue. */
179 static int gr_saved, fr_saved;
181 static rtx find_addr_reg (rtx);
183 /* Keep track of the number of bytes we have output in the CODE subspace
184 during this compilation so we'll know when to emit inline long-calls. */
185 unsigned long total_code_bytes;
187 /* The last address of the previous function plus the number of bytes in
188 associated thunks that have been output. This is used to determine if
189 a thunk can use an IA-relative branch to reach its target function. */
190 static int last_address;
192 /* Variables to handle plabels that we discover are necessary at assembly
193 output time. They are output after the current function. */
194 struct deferred_plabel GTY(())
199 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
201 static size_t n_deferred_plabels = 0;
204 /* Initialize the GCC target structure. */
206 #undef TARGET_ASM_ALIGNED_HI_OP
207 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
208 #undef TARGET_ASM_ALIGNED_SI_OP
209 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
210 #undef TARGET_ASM_ALIGNED_DI_OP
211 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
212 #undef TARGET_ASM_UNALIGNED_HI_OP
213 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
214 #undef TARGET_ASM_UNALIGNED_SI_OP
215 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
216 #undef TARGET_ASM_UNALIGNED_DI_OP
217 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
218 #undef TARGET_ASM_INTEGER
219 #define TARGET_ASM_INTEGER pa_assemble_integer
221 #undef TARGET_ASM_FUNCTION_PROLOGUE
222 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
223 #undef TARGET_ASM_FUNCTION_EPILOGUE
224 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
226 #undef TARGET_SCHED_ADJUST_COST
227 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
228 #undef TARGET_SCHED_ADJUST_PRIORITY
229 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
230 #undef TARGET_SCHED_ISSUE_RATE
231 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
233 #undef TARGET_ENCODE_SECTION_INFO
234 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
235 #undef TARGET_STRIP_NAME_ENCODING
236 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
238 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
239 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
241 #undef TARGET_COMMUTATIVE_P
242 #define TARGET_COMMUTATIVE_P pa_commutative_p
244 #undef TARGET_ASM_OUTPUT_MI_THUNK
245 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
246 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
247 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
249 #undef TARGET_ASM_FILE_END
250 #ifdef ASM_OUTPUT_EXTERNAL_REAL
251 #define TARGET_ASM_FILE_END pa_hpux_file_end
253 #define TARGET_ASM_FILE_END output_deferred_plabels
256 #if !defined(USE_COLLECT2)
257 #undef TARGET_ASM_CONSTRUCTOR
258 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
259 #undef TARGET_ASM_DESTRUCTOR
260 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
263 #undef TARGET_DEFAULT_TARGET_FLAGS
264 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | TARGET_CPU_DEFAULT)
265 #undef TARGET_HANDLE_OPTION
266 #define TARGET_HANDLE_OPTION pa_handle_option
268 #undef TARGET_INIT_BUILTINS
269 #define TARGET_INIT_BUILTINS pa_init_builtins
271 #undef TARGET_RTX_COSTS
272 #define TARGET_RTX_COSTS hppa_rtx_costs
273 #undef TARGET_ADDRESS_COST
274 #define TARGET_ADDRESS_COST hppa_address_cost
276 #undef TARGET_MACHINE_DEPENDENT_REORG
277 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
279 #ifdef HPUX_LONG_DOUBLE_LIBRARY
280 #undef TARGET_INIT_LIBFUNCS
281 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
284 #undef TARGET_PROMOTE_FUNCTION_RETURN
285 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
286 #undef TARGET_PROMOTE_PROTOTYPES
287 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
289 #undef TARGET_STRUCT_VALUE_RTX
290 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
291 #undef TARGET_RETURN_IN_MEMORY
292 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
293 #undef TARGET_MUST_PASS_IN_STACK
294 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
295 #undef TARGET_PASS_BY_REFERENCE
296 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
297 #undef TARGET_CALLEE_COPIES
298 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
299 #undef TARGET_ARG_PARTIAL_BYTES
300 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
302 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
303 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
304 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
305 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
307 #undef TARGET_SCALAR_MODE_SUPPORTED_P
308 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
310 #undef TARGET_CANNOT_FORCE_CONST_MEM
311 #define TARGET_CANNOT_FORCE_CONST_MEM pa_tls_referenced_p
313 #undef TARGET_SECONDARY_RELOAD
314 #define TARGET_SECONDARY_RELOAD pa_secondary_reload
316 struct gcc_target targetm = TARGET_INITIALIZER;
318 /* Parse the -mfixed-range= option string. */
321 fix_range (const char *const_str)
324 char *str, *dash, *comma;
326 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
327 REG2 are either register names or register numbers. The effect
328 of this option is to mark the registers in the range from REG1 to
329 REG2 as ``fixed'' so they won't be used by the compiler. This is
330 used, e.g., to ensure that kernel mode code doesn't use fr4-fr31. */
332 i = strlen (const_str);
333 str = (char *) alloca (i + 1);
334 memcpy (str, const_str, i + 1);
338 dash = strchr (str, '-');
341 warning (0, "value of -mfixed-range must have form REG1-REG2");
346 comma = strchr (dash + 1, ',');
350 first = decode_reg_name (str);
353 warning (0, "unknown register name: %s", str);
357 last = decode_reg_name (dash + 1);
360 warning (0, "unknown register name: %s", dash + 1);
368 warning (0, "%s-%s is an empty range", str, dash + 1);
372 for (i = first; i <= last; ++i)
373 fixed_regs[i] = call_used_regs[i] = 1;
382 /* Check if all floating point registers have been fixed. */
383 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
388 target_flags |= MASK_DISABLE_FPREGS;
391 /* Implement TARGET_HANDLE_OPTION. */
394 pa_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
399 case OPT_mpa_risc_1_0:
401 target_flags &= ~(MASK_PA_11 | MASK_PA_20);
405 case OPT_mpa_risc_1_1:
407 target_flags &= ~MASK_PA_20;
408 target_flags |= MASK_PA_11;
411 case OPT_mpa_risc_2_0:
413 target_flags |= MASK_PA_11 | MASK_PA_20;
417 if (strcmp (arg, "8000") == 0)
418 pa_cpu = PROCESSOR_8000;
419 else if (strcmp (arg, "7100") == 0)
420 pa_cpu = PROCESSOR_7100;
421 else if (strcmp (arg, "700") == 0)
422 pa_cpu = PROCESSOR_700;
423 else if (strcmp (arg, "7100LC") == 0)
424 pa_cpu = PROCESSOR_7100LC;
425 else if (strcmp (arg, "7200") == 0)
426 pa_cpu = PROCESSOR_7200;
427 else if (strcmp (arg, "7300") == 0)
428 pa_cpu = PROCESSOR_7300;
433 case OPT_mfixed_range_:
443 #if TARGET_HPUX_10_10
449 #if TARGET_HPUX_11_11
461 override_options (void)
463 /* Unconditional branches in the delay slot are not compatible with dwarf2
464 call frame information. There is no benefit in using this optimization
465 on PA8000 and later processors. */
466 if (pa_cpu >= PROCESSOR_8000
467 || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
468 || flag_unwind_tables)
469 target_flags &= ~MASK_JUMP_IN_DELAY;
471 if (flag_pic && TARGET_PORTABLE_RUNTIME)
473 warning (0, "PIC code generation is not supported in the portable runtime model");
476 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
478 warning (0, "PIC code generation is not compatible with fast indirect calls");
481 if (! TARGET_GAS && write_symbols != NO_DEBUG)
483 warning (0, "-g is only supported when using GAS on this processor,");
484 warning (0, "-g option disabled");
485 write_symbols = NO_DEBUG;
488 /* We only support the "big PIC" model now. And we always generate PIC
489 code when in 64bit mode. */
490 if (flag_pic == 1 || TARGET_64BIT)
493 /* We can't guarantee that .dword is available for 32-bit targets. */
494 if (UNITS_PER_WORD == 4)
495 targetm.asm_out.aligned_op.di = NULL;
497 /* The unaligned ops are only available when using GAS. */
500 targetm.asm_out.unaligned_op.hi = NULL;
501 targetm.asm_out.unaligned_op.si = NULL;
502 targetm.asm_out.unaligned_op.di = NULL;
505 init_machine_status = pa_init_machine_status;
509 pa_init_builtins (void)
511 #ifdef DONT_HAVE_FPUTC_UNLOCKED
512 built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] =
513 built_in_decls[(int) BUILT_IN_PUTC_UNLOCKED];
514 implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED]
515 = implicit_built_in_decls[(int) BUILT_IN_PUTC_UNLOCKED];
518 if (built_in_decls [BUILT_IN_FINITE])
519 set_user_assembler_name (built_in_decls [BUILT_IN_FINITE], "_Isfinite");
520 if (built_in_decls [BUILT_IN_FINITEF])
521 set_user_assembler_name (built_in_decls [BUILT_IN_FINITEF], "_Isfinitef");
525 /* Function to init struct machine_function.
526 This will be called, via a pointer variable,
527 from push_function_context. */
529 static struct machine_function *
530 pa_init_machine_status (void)
532 return ggc_alloc_cleared (sizeof (machine_function));
535 /* If FROM is a probable pointer register, mark TO as a probable
536 pointer register with the same pointer alignment as FROM. */
539 copy_reg_pointer (rtx to, rtx from)
541 if (REG_POINTER (from))
542 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
545 /* Return 1 if X contains a symbolic expression. We know these
546 expressions will have one of a few well defined forms, so
547 we need only check those forms. */
549 symbolic_expression_p (rtx x)
552 /* Strip off any HIGH. */
553 if (GET_CODE (x) == HIGH)
556 return (symbolic_operand (x, VOIDmode));
559 /* Accept any constant that can be moved in one instruction into a
562 cint_ok_for_move (HOST_WIDE_INT ival)
564 /* OK if ldo, ldil, or zdepi, can be used. */
565 return (VAL_14_BITS_P (ival)
566 || ldil_cint_p (ival)
567 || zdepi_cint_p (ival));
570 /* Return truth value of whether OP can be used as an operand in a
573 adddi3_operand (rtx op, enum machine_mode mode)
575 return (register_operand (op, mode)
576 || (GET_CODE (op) == CONST_INT
577 && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
580 /* True iff the operand OP can be used as the destination operand of
581 an integer store. This also implies the operand could be used as
582 the source operand of an integer load. Symbolic, lo_sum and indexed
583 memory operands are not allowed. We accept reloading pseudos and
584 other memory operands. */
586 integer_store_memory_operand (rtx op, enum machine_mode mode)
588 return ((reload_in_progress
590 && REGNO (op) >= FIRST_PSEUDO_REGISTER
591 && reg_renumber [REGNO (op)] < 0)
592 || (GET_CODE (op) == MEM
593 && (reload_in_progress || memory_address_p (mode, XEXP (op, 0)))
594 && !symbolic_memory_operand (op, VOIDmode)
595 && !IS_LO_SUM_DLT_ADDR_P (XEXP (op, 0))
596 && !IS_INDEX_ADDR_P (XEXP (op, 0))));
599 /* True iff ldil can be used to load this CONST_INT. The least
600 significant 11 bits of the value must be zero and the value must
601 not change sign when extended from 32 to 64 bits. */
603 ldil_cint_p (HOST_WIDE_INT ival)
605 HOST_WIDE_INT x = ival & (((HOST_WIDE_INT) -1 << 31) | 0x7ff);
607 return x == 0 || x == ((HOST_WIDE_INT) -1 << 31);
610 /* True iff zdepi can be used to generate this CONST_INT.
611 zdepi first sign extends a 5-bit signed number to a given field
612 length, then places this field anywhere in a zero. */
614 zdepi_cint_p (unsigned HOST_WIDE_INT x)
616 unsigned HOST_WIDE_INT lsb_mask, t;
618 /* This might not be obvious, but it's at least fast.
619 This function is critical; we don't have the time loops would take. */
621 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
622 /* Return true iff t is a power of two. */
623 return ((t & (t - 1)) == 0);
626 /* True iff depi or extru can be used to compute (reg & mask).
627 Accept bit pattern like these:
632 and_mask_p (unsigned HOST_WIDE_INT mask)
635 mask += mask & -mask;
636 return (mask & (mask - 1)) == 0;
639 /* True iff depi can be used to compute (reg | MASK). */
641 ior_mask_p (unsigned HOST_WIDE_INT mask)
643 mask += mask & -mask;
644 return (mask & (mask - 1)) == 0;
647 /* Legitimize PIC addresses. If the address is already
648 position-independent, we return ORIG. Newly generated
649 position-independent addresses go to REG. If we need more
650 than one register, we lose. */
653 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
657 gcc_assert (!PA_SYMBOL_REF_TLS_P (orig));
659 /* Labels need special handling. */
660 if (pic_label_operand (orig, mode))
662 /* We do not want to go through the movXX expanders here since that
663 would create recursion.
665 Nor do we really want to call a generator for a named pattern
666 since that requires multiple patterns if we want to support
669 So instead we just emit the raw set, which avoids the movXX
670 expanders completely. */
671 mark_reg_pointer (reg, BITS_PER_UNIT);
672 emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
673 current_function_uses_pic_offset_table = 1;
676 if (GET_CODE (orig) == SYMBOL_REF)
682 /* Before reload, allocate a temporary register for the intermediate
683 result. This allows the sequence to be deleted when the final
684 result is unused and the insns are trivially dead. */
685 tmp_reg = ((reload_in_progress || reload_completed)
686 ? reg : gen_reg_rtx (Pmode));
688 emit_move_insn (tmp_reg,
689 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
690 gen_rtx_HIGH (word_mode, orig)));
692 = gen_const_mem (Pmode,
693 gen_rtx_LO_SUM (Pmode, tmp_reg,
694 gen_rtx_UNSPEC (Pmode,
698 current_function_uses_pic_offset_table = 1;
699 mark_reg_pointer (reg, BITS_PER_UNIT);
700 insn = emit_move_insn (reg, pic_ref);
702 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
703 set_unique_reg_note (insn, REG_EQUAL, orig);
707 else if (GET_CODE (orig) == CONST)
711 if (GET_CODE (XEXP (orig, 0)) == PLUS
712 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
716 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
718 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
719 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
720 base == reg ? 0 : reg);
722 if (GET_CODE (orig) == CONST_INT)
724 if (INT_14_BITS (orig))
725 return plus_constant (base, INTVAL (orig));
726 orig = force_reg (Pmode, orig);
728 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
729 /* Likewise, should we set special REG_NOTEs here? */
735 static GTY(()) rtx gen_tls_tga;
738 gen_tls_get_addr (void)
741 gen_tls_tga = init_one_libfunc ("__tls_get_addr");
746 hppa_tls_call (rtx arg)
750 ret = gen_reg_rtx (Pmode);
751 emit_library_call_value (gen_tls_get_addr (), ret,
752 LCT_CONST, Pmode, 1, arg, Pmode);
758 legitimize_tls_address (rtx addr)
760 rtx ret, insn, tmp, t1, t2, tp;
761 enum tls_model model = SYMBOL_REF_TLS_MODEL (addr);
765 case TLS_MODEL_GLOBAL_DYNAMIC:
766 tmp = gen_reg_rtx (Pmode);
768 emit_insn (gen_tgd_load_pic (tmp, addr));
770 emit_insn (gen_tgd_load (tmp, addr));
771 ret = hppa_tls_call (tmp);
774 case TLS_MODEL_LOCAL_DYNAMIC:
775 ret = gen_reg_rtx (Pmode);
776 tmp = gen_reg_rtx (Pmode);
779 emit_insn (gen_tld_load_pic (tmp, addr));
781 emit_insn (gen_tld_load (tmp, addr));
782 t1 = hppa_tls_call (tmp);
785 t2 = gen_reg_rtx (Pmode);
786 emit_libcall_block (insn, t2, t1,
787 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
789 emit_insn (gen_tld_offset_load (ret, addr, t2));
792 case TLS_MODEL_INITIAL_EXEC:
793 tp = gen_reg_rtx (Pmode);
794 tmp = gen_reg_rtx (Pmode);
795 ret = gen_reg_rtx (Pmode);
796 emit_insn (gen_tp_load (tp));
798 emit_insn (gen_tie_load_pic (tmp, addr));
800 emit_insn (gen_tie_load (tmp, addr));
801 emit_move_insn (ret, gen_rtx_PLUS (Pmode, tp, tmp));
804 case TLS_MODEL_LOCAL_EXEC:
805 tp = gen_reg_rtx (Pmode);
806 ret = gen_reg_rtx (Pmode);
807 emit_insn (gen_tp_load (tp));
808 emit_insn (gen_tle_load (ret, addr, tp));
818 /* Try machine-dependent ways of modifying an illegitimate address
819 to be legitimate. If we find one, return the new, valid address.
820 This macro is used in only one place: `memory_address' in explow.c.
822 OLDX is the address as it was before break_out_memory_refs was called.
823 In some cases it is useful to look at this to decide what needs to be done.
825 MODE and WIN are passed so that this macro can use
826 GO_IF_LEGITIMATE_ADDRESS.
828 It is always safe for this macro to do nothing. It exists to recognize
829 opportunities to optimize the output.
831 For the PA, transform:
833 memory(X + <large int>)
837 if (<large int> & mask) >= 16
838 Y = (<large int> & ~mask) + mask + 1 Round up.
840 Y = (<large int> & ~mask) Round down.
842 memory (Z + (<large int> - Y));
844 This is for CSE to find several similar references, and only use one Z.
846 X can either be a SYMBOL_REF or REG, but because combine cannot
847 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
848 D will not fit in 14 bits.
850 MODE_FLOAT references allow displacements which fit in 5 bits, so use
853 MODE_INT references allow displacements which fit in 14 bits, so use
856 This relies on the fact that most mode MODE_FLOAT references will use FP
857 registers and most mode MODE_INT references will use integer registers.
858 (In the rare case of an FP register used in an integer MODE, we depend
859 on secondary reloads to clean things up.)
862 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
863 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
864 addressing modes to be used).
866 Put X and Z into registers. Then put the entire expression into
870 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
871 enum machine_mode mode)
875 /* We need to canonicalize the order of operands in unscaled indexed
876 addresses since the code that checks if an address is valid doesn't
877 always try both orders. */
878 if (!TARGET_NO_SPACE_REGS
879 && GET_CODE (x) == PLUS
880 && GET_MODE (x) == Pmode
881 && REG_P (XEXP (x, 0))
882 && REG_P (XEXP (x, 1))
883 && REG_POINTER (XEXP (x, 0))
884 && !REG_POINTER (XEXP (x, 1)))
885 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
887 if (PA_SYMBOL_REF_TLS_P (x))
888 return legitimize_tls_address (x);
890 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
892 /* Strip off CONST. */
893 if (GET_CODE (x) == CONST)
896 /* Special case. Get the SYMBOL_REF into a register and use indexing.
897 That should always be safe. */
898 if (GET_CODE (x) == PLUS
899 && GET_CODE (XEXP (x, 0)) == REG
900 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
902 rtx reg = force_reg (Pmode, XEXP (x, 1));
903 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
906 /* Note we must reject symbols which represent function addresses
907 since the assembler/linker can't handle arithmetic on plabels. */
908 if (GET_CODE (x) == PLUS
909 && GET_CODE (XEXP (x, 1)) == CONST_INT
910 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
911 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
912 || GET_CODE (XEXP (x, 0)) == REG))
914 rtx int_part, ptr_reg;
916 int offset = INTVAL (XEXP (x, 1));
919 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
920 ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
922 /* Choose which way to round the offset. Round up if we
923 are >= halfway to the next boundary. */
924 if ((offset & mask) >= ((mask + 1) / 2))
925 newoffset = (offset & ~ mask) + mask + 1;
927 newoffset = (offset & ~ mask);
929 /* If the newoffset will not fit in 14 bits (ldo), then
930 handling this would take 4 or 5 instructions (2 to load
931 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
932 add the new offset and the SYMBOL_REF.) Combine can
933 not handle 4->2 or 5->2 combinations, so do not create
935 if (! VAL_14_BITS_P (newoffset)
936 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
938 rtx const_part = plus_constant (XEXP (x, 0), newoffset);
941 gen_rtx_HIGH (Pmode, const_part));
944 gen_rtx_LO_SUM (Pmode,
945 tmp_reg, const_part));
949 if (! VAL_14_BITS_P (newoffset))
950 int_part = force_reg (Pmode, GEN_INT (newoffset));
952 int_part = GEN_INT (newoffset);
954 ptr_reg = force_reg (Pmode,
956 force_reg (Pmode, XEXP (x, 0)),
959 return plus_constant (ptr_reg, offset - newoffset);
962 /* Handle (plus (mult (a) (shadd_constant)) (b)). */
964 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
965 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
966 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
967 && (OBJECT_P (XEXP (x, 1))
968 || GET_CODE (XEXP (x, 1)) == SUBREG)
969 && GET_CODE (XEXP (x, 1)) != CONST)
971 int val = INTVAL (XEXP (XEXP (x, 0), 1));
975 if (GET_CODE (reg1) != REG)
976 reg1 = force_reg (Pmode, force_operand (reg1, 0));
978 reg2 = XEXP (XEXP (x, 0), 0);
979 if (GET_CODE (reg2) != REG)
980 reg2 = force_reg (Pmode, force_operand (reg2, 0));
982 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
989 /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
991 Only do so for floating point modes since this is more speculative
992 and we lose if it's an integer store. */
993 if (GET_CODE (x) == PLUS
994 && GET_CODE (XEXP (x, 0)) == PLUS
995 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
996 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
997 && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
998 && (mode == SFmode || mode == DFmode))
1001 /* First, try and figure out what to use as a base register. */
1002 rtx reg1, reg2, base, idx, orig_base;
1004 reg1 = XEXP (XEXP (x, 0), 1);
1009 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
1010 then emit_move_sequence will turn on REG_POINTER so we'll know
1011 it's a base register below. */
1012 if (GET_CODE (reg1) != REG)
1013 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1015 if (GET_CODE (reg2) != REG)
1016 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1018 /* Figure out what the base and index are. */
1020 if (GET_CODE (reg1) == REG
1021 && REG_POINTER (reg1))
1024 orig_base = XEXP (XEXP (x, 0), 1);
1025 idx = gen_rtx_PLUS (Pmode,
1026 gen_rtx_MULT (Pmode,
1027 XEXP (XEXP (XEXP (x, 0), 0), 0),
1028 XEXP (XEXP (XEXP (x, 0), 0), 1)),
1031 else if (GET_CODE (reg2) == REG
1032 && REG_POINTER (reg2))
1035 orig_base = XEXP (x, 1);
1042 /* If the index adds a large constant, try to scale the
1043 constant so that it can be loaded with only one insn. */
1044 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1045 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1046 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1047 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1049 /* Divide the CONST_INT by the scale factor, then add it to A. */
1050 int val = INTVAL (XEXP (idx, 1));
1052 val /= INTVAL (XEXP (XEXP (idx, 0), 1));
1053 reg1 = XEXP (XEXP (idx, 0), 0);
1054 if (GET_CODE (reg1) != REG)
1055 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1057 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1059 /* We can now generate a simple scaled indexed address. */
1062 (Pmode, gen_rtx_PLUS (Pmode,
1063 gen_rtx_MULT (Pmode, reg1,
1064 XEXP (XEXP (idx, 0), 1)),
1068 /* If B + C is still a valid base register, then add them. */
1069 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1070 && INTVAL (XEXP (idx, 1)) <= 4096
1071 && INTVAL (XEXP (idx, 1)) >= -4096)
1073 int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1076 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1078 reg2 = XEXP (XEXP (idx, 0), 0);
1079 if (GET_CODE (reg2) != CONST_INT)
1080 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1082 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1083 gen_rtx_MULT (Pmode,
1089 /* Get the index into a register, then add the base + index and
1090 return a register holding the result. */
1092 /* First get A into a register. */
1093 reg1 = XEXP (XEXP (idx, 0), 0);
1094 if (GET_CODE (reg1) != REG)
1095 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1097 /* And get B into a register. */
1098 reg2 = XEXP (idx, 1);
1099 if (GET_CODE (reg2) != REG)
1100 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1102 reg1 = force_reg (Pmode,
1103 gen_rtx_PLUS (Pmode,
1104 gen_rtx_MULT (Pmode, reg1,
1105 XEXP (XEXP (idx, 0), 1)),
1108 /* Add the result to our base register and return. */
1109 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1113 /* Uh-oh. We might have an address for x[n-100000]. This needs
1114 special handling to avoid creating an indexed memory address
1115 with x-100000 as the base.
1117 If the constant part is small enough, then it's still safe because
1118 there is a guard page at the beginning and end of the data segment.
1120 Scaled references are common enough that we want to try and rearrange the
1121 terms so that we can use indexing for these addresses too. Only
1122 do the optimization for floatint point modes. */
1124 if (GET_CODE (x) == PLUS
1125 && symbolic_expression_p (XEXP (x, 1)))
1127 /* Ugly. We modify things here so that the address offset specified
1128 by the index expression is computed first, then added to x to form
1129 the entire address. */
1131 rtx regx1, regx2, regy1, regy2, y;
1133 /* Strip off any CONST. */
1135 if (GET_CODE (y) == CONST)
1138 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1140 /* See if this looks like
1141 (plus (mult (reg) (shadd_const))
1142 (const (plus (symbol_ref) (const_int))))
1144 Where const_int is small. In that case the const
1145 expression is a valid pointer for indexing.
1147 If const_int is big, but can be divided evenly by shadd_const
1148 and added to (reg). This allows more scaled indexed addresses. */
1149 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1150 && GET_CODE (XEXP (x, 0)) == MULT
1151 && GET_CODE (XEXP (y, 1)) == CONST_INT
1152 && INTVAL (XEXP (y, 1)) >= -4096
1153 && INTVAL (XEXP (y, 1)) <= 4095
1154 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1155 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1157 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1161 if (GET_CODE (reg1) != REG)
1162 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1164 reg2 = XEXP (XEXP (x, 0), 0);
1165 if (GET_CODE (reg2) != REG)
1166 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1168 return force_reg (Pmode,
1169 gen_rtx_PLUS (Pmode,
1170 gen_rtx_MULT (Pmode,
1175 else if ((mode == DFmode || mode == SFmode)
1176 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1177 && GET_CODE (XEXP (x, 0)) == MULT
1178 && GET_CODE (XEXP (y, 1)) == CONST_INT
1179 && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1180 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1181 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1184 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1185 / INTVAL (XEXP (XEXP (x, 0), 1))));
1186 regx2 = XEXP (XEXP (x, 0), 0);
1187 if (GET_CODE (regx2) != REG)
1188 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1189 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1193 gen_rtx_PLUS (Pmode,
1194 gen_rtx_MULT (Pmode, regx2,
1195 XEXP (XEXP (x, 0), 1)),
1196 force_reg (Pmode, XEXP (y, 0))));
1198 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1199 && INTVAL (XEXP (y, 1)) >= -4096
1200 && INTVAL (XEXP (y, 1)) <= 4095)
1202 /* This is safe because of the guard page at the
1203 beginning and end of the data space. Just
1204 return the original address. */
1209 /* Doesn't look like one we can optimize. */
1210 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1211 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1212 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1213 regx1 = force_reg (Pmode,
1214 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1216 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1224 /* For the HPPA, REG and REG+CONST is cost 0
1225 and addresses involving symbolic constants are cost 2.
1227 PIC addresses are very expensive.
1229 It is no coincidence that this has the same structure
1230 as GO_IF_LEGITIMATE_ADDRESS. */
1233 hppa_address_cost (rtx X)
1235 switch (GET_CODE (X))
1248 /* Compute a (partial) cost for rtx X. Return true if the complete
1249 cost has been computed, and false if subexpressions should be
1250 scanned. In either case, *TOTAL contains the cost result. */
1253 hppa_rtx_costs (rtx x, int code, int outer_code, int *total)
1258 if (INTVAL (x) == 0)
1260 else if (INT_14_BITS (x))
1277 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1278 && outer_code != SET)
1285 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1286 *total = COSTS_N_INSNS (3);
1287 else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1288 *total = COSTS_N_INSNS (8);
1290 *total = COSTS_N_INSNS (20);
1294 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1296 *total = COSTS_N_INSNS (14);
1304 *total = COSTS_N_INSNS (60);
1307 case PLUS: /* this includes shNadd insns */
1309 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1310 *total = COSTS_N_INSNS (3);
1312 *total = COSTS_N_INSNS (1);
1318 *total = COSTS_N_INSNS (1);
1326 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1327 new rtx with the correct mode. */
1329 force_mode (enum machine_mode mode, rtx orig)
1331 if (mode == GET_MODE (orig))
1334 gcc_assert (REGNO (orig) < FIRST_PSEUDO_REGISTER);
1336 return gen_rtx_REG (mode, REGNO (orig));
1339 /* Return 1 if *X is a thread-local symbol. */
1342 pa_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1344 return PA_SYMBOL_REF_TLS_P (*x);
1347 /* Return 1 if X contains a thread-local symbol. */
1350 pa_tls_referenced_p (rtx x)
1352 if (!TARGET_HAVE_TLS)
1355 return for_each_rtx (&x, &pa_tls_symbol_ref_1, 0);
1358 /* Emit insns to move operands[1] into operands[0].
1360 Return 1 if we have written out everything that needs to be done to
1361 do the move. Otherwise, return 0 and the caller will emit the move
1364 Note SCRATCH_REG may not be in the proper mode depending on how it
1365 will be used. This routine is responsible for creating a new copy
1366 of SCRATCH_REG in the proper mode. */
1369 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1371 register rtx operand0 = operands[0];
1372 register rtx operand1 = operands[1];
1375 /* We can only handle indexed addresses in the destination operand
1376 of floating point stores. Thus, we need to break out indexed
1377 addresses from the destination operand. */
1378 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1380 gcc_assert (can_create_pseudo_p ());
1382 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1383 operand0 = replace_equiv_address (operand0, tem);
1386 /* On targets with non-equivalent space registers, break out unscaled
1387 indexed addresses from the source operand before the final CSE.
1388 We have to do this because the REG_POINTER flag is not correctly
1389 carried through various optimization passes and CSE may substitute
1390 a pseudo without the pointer set for one with the pointer set. As
1391 a result, we loose various opportunities to create insns with
1392 unscaled indexed addresses. */
1393 if (!TARGET_NO_SPACE_REGS
1394 && !cse_not_expected
1395 && GET_CODE (operand1) == MEM
1396 && GET_CODE (XEXP (operand1, 0)) == PLUS
1397 && REG_P (XEXP (XEXP (operand1, 0), 0))
1398 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1400 = replace_equiv_address (operand1,
1401 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1404 && reload_in_progress && GET_CODE (operand0) == REG
1405 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1406 operand0 = reg_equiv_mem[REGNO (operand0)];
1407 else if (scratch_reg
1408 && reload_in_progress && GET_CODE (operand0) == SUBREG
1409 && GET_CODE (SUBREG_REG (operand0)) == REG
1410 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1412 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1413 the code which tracks sets/uses for delete_output_reload. */
1414 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1415 reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1416 SUBREG_BYTE (operand0));
1417 operand0 = alter_subreg (&temp);
1421 && reload_in_progress && GET_CODE (operand1) == REG
1422 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1423 operand1 = reg_equiv_mem[REGNO (operand1)];
1424 else if (scratch_reg
1425 && reload_in_progress && GET_CODE (operand1) == SUBREG
1426 && GET_CODE (SUBREG_REG (operand1)) == REG
1427 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1429 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1430 the code which tracks sets/uses for delete_output_reload. */
1431 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1432 reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1433 SUBREG_BYTE (operand1));
1434 operand1 = alter_subreg (&temp);
1437 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1438 && ((tem = find_replacement (&XEXP (operand0, 0)))
1439 != XEXP (operand0, 0)))
1440 operand0 = replace_equiv_address (operand0, tem);
1442 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1443 && ((tem = find_replacement (&XEXP (operand1, 0)))
1444 != XEXP (operand1, 0)))
1445 operand1 = replace_equiv_address (operand1, tem);
1447 /* Handle secondary reloads for loads/stores of FP registers from
1448 REG+D addresses where D does not fit in 5 or 14 bits, including
1449 (subreg (mem (addr))) cases. */
1451 && fp_reg_operand (operand0, mode)
1452 && ((GET_CODE (operand1) == MEM
1453 && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1454 XEXP (operand1, 0)))
1455 || ((GET_CODE (operand1) == SUBREG
1456 && GET_CODE (XEXP (operand1, 0)) == MEM
1457 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1459 XEXP (XEXP (operand1, 0), 0))))))
1461 if (GET_CODE (operand1) == SUBREG)
1462 operand1 = XEXP (operand1, 0);
1464 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1465 it in WORD_MODE regardless of what mode it was originally given
1467 scratch_reg = force_mode (word_mode, scratch_reg);
1469 /* D might not fit in 14 bits either; for such cases load D into
1471 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1473 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1474 emit_move_insn (scratch_reg,
1475 gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1477 XEXP (XEXP (operand1, 0), 0),
1481 emit_move_insn (scratch_reg, XEXP (operand1, 0));
1482 emit_insn (gen_rtx_SET (VOIDmode, operand0,
1483 replace_equiv_address (operand1, scratch_reg)));
1486 else if (scratch_reg
1487 && fp_reg_operand (operand1, mode)
1488 && ((GET_CODE (operand0) == MEM
1489 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1491 XEXP (operand0, 0)))
1492 || ((GET_CODE (operand0) == SUBREG)
1493 && GET_CODE (XEXP (operand0, 0)) == MEM
1494 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1496 XEXP (XEXP (operand0, 0), 0)))))
1498 if (GET_CODE (operand0) == SUBREG)
1499 operand0 = XEXP (operand0, 0);
1501 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1502 it in WORD_MODE regardless of what mode it was originally given
1504 scratch_reg = force_mode (word_mode, scratch_reg);
1506 /* D might not fit in 14 bits either; for such cases load D into
1508 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1510 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1511 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1514 XEXP (XEXP (operand0, 0),
1519 emit_move_insn (scratch_reg, XEXP (operand0, 0));
1520 emit_insn (gen_rtx_SET (VOIDmode,
1521 replace_equiv_address (operand0, scratch_reg),
1525 /* Handle secondary reloads for loads of FP registers from constant
1526 expressions by forcing the constant into memory.
1528 Use scratch_reg to hold the address of the memory location.
1530 The proper fix is to change PREFERRED_RELOAD_CLASS to return
1531 NO_REGS when presented with a const_int and a register class
1532 containing only FP registers. Doing so unfortunately creates
1533 more problems than it solves. Fix this for 2.5. */
1534 else if (scratch_reg
1535 && CONSTANT_P (operand1)
1536 && fp_reg_operand (operand0, mode))
1538 rtx const_mem, xoperands[2];
1540 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1541 it in WORD_MODE regardless of what mode it was originally given
1543 scratch_reg = force_mode (word_mode, scratch_reg);
1545 /* Force the constant into memory and put the address of the
1546 memory location into scratch_reg. */
1547 const_mem = force_const_mem (mode, operand1);
1548 xoperands[0] = scratch_reg;
1549 xoperands[1] = XEXP (const_mem, 0);
1550 emit_move_sequence (xoperands, Pmode, 0);
1552 /* Now load the destination register. */
1553 emit_insn (gen_rtx_SET (mode, operand0,
1554 replace_equiv_address (const_mem, scratch_reg)));
1557 /* Handle secondary reloads for SAR. These occur when trying to load
1558 the SAR from memory, FP register, or with a constant. */
1559 else if (scratch_reg
1560 && GET_CODE (operand0) == REG
1561 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1562 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1563 && (GET_CODE (operand1) == MEM
1564 || GET_CODE (operand1) == CONST_INT
1565 || (GET_CODE (operand1) == REG
1566 && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1568 /* D might not fit in 14 bits either; for such cases load D into
1570 if (GET_CODE (operand1) == MEM
1571 && !memory_address_p (Pmode, XEXP (operand1, 0)))
1573 /* We are reloading the address into the scratch register, so we
1574 want to make sure the scratch register is a full register. */
1575 scratch_reg = force_mode (word_mode, scratch_reg);
1577 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1578 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1581 XEXP (XEXP (operand1, 0),
1585 /* Now we are going to load the scratch register from memory,
1586 we want to load it in the same width as the original MEM,
1587 which must be the same as the width of the ultimate destination,
1589 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1591 emit_move_insn (scratch_reg,
1592 replace_equiv_address (operand1, scratch_reg));
1596 /* We want to load the scratch register using the same mode as
1597 the ultimate destination. */
1598 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1600 emit_move_insn (scratch_reg, operand1);
1603 /* And emit the insn to set the ultimate destination. We know that
1604 the scratch register has the same mode as the destination at this
1606 emit_move_insn (operand0, scratch_reg);
1609 /* Handle the most common case: storing into a register. */
1610 else if (register_operand (operand0, mode))
1612 if (register_operand (operand1, mode)
1613 || (GET_CODE (operand1) == CONST_INT
1614 && cint_ok_for_move (INTVAL (operand1)))
1615 || (operand1 == CONST0_RTX (mode))
1616 || (GET_CODE (operand1) == HIGH
1617 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1618 /* Only `general_operands' can come here, so MEM is ok. */
1619 || GET_CODE (operand1) == MEM)
1621 /* Various sets are created during RTL generation which don't
1622 have the REG_POINTER flag correctly set. After the CSE pass,
1623 instruction recognition can fail if we don't consistently
1624 set this flag when performing register copies. This should
1625 also improve the opportunities for creating insns that use
1626 unscaled indexing. */
1627 if (REG_P (operand0) && REG_P (operand1))
1629 if (REG_POINTER (operand1)
1630 && !REG_POINTER (operand0)
1631 && !HARD_REGISTER_P (operand0))
1632 copy_reg_pointer (operand0, operand1);
1633 else if (REG_POINTER (operand0)
1634 && !REG_POINTER (operand1)
1635 && !HARD_REGISTER_P (operand1))
1636 copy_reg_pointer (operand1, operand0);
1639 /* When MEMs are broken out, the REG_POINTER flag doesn't
1640 get set. In some cases, we can set the REG_POINTER flag
1641 from the declaration for the MEM. */
1642 if (REG_P (operand0)
1643 && GET_CODE (operand1) == MEM
1644 && !REG_POINTER (operand0))
1646 tree decl = MEM_EXPR (operand1);
1648 /* Set the register pointer flag and register alignment
1649 if the declaration for this memory reference is a
1650 pointer type. Fortran indirect argument references
1653 && !(flag_argument_noalias > 1
1654 && TREE_CODE (decl) == INDIRECT_REF
1655 && TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL))
1659 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1661 if (TREE_CODE (decl) == COMPONENT_REF)
1662 decl = TREE_OPERAND (decl, 1);
1664 type = TREE_TYPE (decl);
1665 if (TREE_CODE (type) == ARRAY_TYPE)
1666 type = get_inner_array_type (type);
1668 if (POINTER_TYPE_P (type))
1672 type = TREE_TYPE (type);
1673 /* Using TYPE_ALIGN_OK is rather conservative as
1674 only the ada frontend actually sets it. */
1675 align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1677 mark_reg_pointer (operand0, align);
1682 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1686 else if (GET_CODE (operand0) == MEM)
1688 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1689 && !(reload_in_progress || reload_completed))
1691 rtx temp = gen_reg_rtx (DFmode);
1693 emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1694 emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1697 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1699 /* Run this case quickly. */
1700 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1703 if (! (reload_in_progress || reload_completed))
1705 operands[0] = validize_mem (operand0);
1706 operands[1] = operand1 = force_reg (mode, operand1);
1710 /* Simplify the source if we need to.
1711 Note we do have to handle function labels here, even though we do
1712 not consider them legitimate constants. Loop optimizations can
1713 call the emit_move_xxx with one as a source. */
1714 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1715 || function_label_operand (operand1, mode)
1716 || (GET_CODE (operand1) == HIGH
1717 && symbolic_operand (XEXP (operand1, 0), mode)))
1721 if (GET_CODE (operand1) == HIGH)
1724 operand1 = XEXP (operand1, 0);
1726 if (symbolic_operand (operand1, mode))
1728 /* Argh. The assembler and linker can't handle arithmetic
1731 So we force the plabel into memory, load operand0 from
1732 the memory location, then add in the constant part. */
1733 if ((GET_CODE (operand1) == CONST
1734 && GET_CODE (XEXP (operand1, 0)) == PLUS
1735 && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
1736 || function_label_operand (operand1, mode))
1738 rtx temp, const_part;
1740 /* Figure out what (if any) scratch register to use. */
1741 if (reload_in_progress || reload_completed)
1743 scratch_reg = scratch_reg ? scratch_reg : operand0;
1744 /* SCRATCH_REG will hold an address and maybe the actual
1745 data. We want it in WORD_MODE regardless of what mode it
1746 was originally given to us. */
1747 scratch_reg = force_mode (word_mode, scratch_reg);
1750 scratch_reg = gen_reg_rtx (Pmode);
1752 if (GET_CODE (operand1) == CONST)
1754 /* Save away the constant part of the expression. */
1755 const_part = XEXP (XEXP (operand1, 0), 1);
1756 gcc_assert (GET_CODE (const_part) == CONST_INT);
1758 /* Force the function label into memory. */
1759 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
1763 /* No constant part. */
1764 const_part = NULL_RTX;
1766 /* Force the function label into memory. */
1767 temp = force_const_mem (mode, operand1);
1771 /* Get the address of the memory location. PIC-ify it if
1773 temp = XEXP (temp, 0);
1775 temp = legitimize_pic_address (temp, mode, scratch_reg);
1777 /* Put the address of the memory location into our destination
1780 emit_move_sequence (operands, mode, scratch_reg);
1782 /* Now load from the memory location into our destination
1784 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
1785 emit_move_sequence (operands, mode, scratch_reg);
1787 /* And add back in the constant part. */
1788 if (const_part != NULL_RTX)
1789 expand_inc (operand0, const_part);
1798 if (reload_in_progress || reload_completed)
1800 temp = scratch_reg ? scratch_reg : operand0;
1801 /* TEMP will hold an address and maybe the actual
1802 data. We want it in WORD_MODE regardless of what mode it
1803 was originally given to us. */
1804 temp = force_mode (word_mode, temp);
1807 temp = gen_reg_rtx (Pmode);
1809 /* (const (plus (symbol) (const_int))) must be forced to
1810 memory during/after reload if the const_int will not fit
1812 if (GET_CODE (operand1) == CONST
1813 && GET_CODE (XEXP (operand1, 0)) == PLUS
1814 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
1815 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
1816 && (reload_completed || reload_in_progress)
1819 rtx const_mem = force_const_mem (mode, operand1);
1820 operands[1] = legitimize_pic_address (XEXP (const_mem, 0),
1822 operands[1] = replace_equiv_address (const_mem, operands[1]);
1823 emit_move_sequence (operands, mode, temp);
1827 operands[1] = legitimize_pic_address (operand1, mode, temp);
1828 if (REG_P (operand0) && REG_P (operands[1]))
1829 copy_reg_pointer (operand0, operands[1]);
1830 emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
1833 /* On the HPPA, references to data space are supposed to use dp,
1834 register 27, but showing it in the RTL inhibits various cse
1835 and loop optimizations. */
1840 if (reload_in_progress || reload_completed)
1842 temp = scratch_reg ? scratch_reg : operand0;
1843 /* TEMP will hold an address and maybe the actual
1844 data. We want it in WORD_MODE regardless of what mode it
1845 was originally given to us. */
1846 temp = force_mode (word_mode, temp);
1849 temp = gen_reg_rtx (mode);
1851 /* Loading a SYMBOL_REF into a register makes that register
1852 safe to be used as the base in an indexed address.
1854 Don't mark hard registers though. That loses. */
1855 if (GET_CODE (operand0) == REG
1856 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1857 mark_reg_pointer (operand0, BITS_PER_UNIT);
1858 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
1859 mark_reg_pointer (temp, BITS_PER_UNIT);
1862 set = gen_rtx_SET (mode, operand0, temp);
1864 set = gen_rtx_SET (VOIDmode,
1866 gen_rtx_LO_SUM (mode, temp, operand1));
1868 emit_insn (gen_rtx_SET (VOIDmode,
1870 gen_rtx_HIGH (mode, operand1)));
1876 else if (pa_tls_referenced_p (operand1))
1881 if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
1883 addend = XEXP (XEXP (tmp, 0), 1);
1884 tmp = XEXP (XEXP (tmp, 0), 0);
1887 gcc_assert (GET_CODE (tmp) == SYMBOL_REF);
1888 tmp = legitimize_tls_address (tmp);
1891 tmp = gen_rtx_PLUS (mode, tmp, addend);
1892 tmp = force_operand (tmp, operands[0]);
1896 else if (GET_CODE (operand1) != CONST_INT
1897 || !cint_ok_for_move (INTVAL (operand1)))
1901 HOST_WIDE_INT value = 0;
1902 HOST_WIDE_INT insv = 0;
1905 if (GET_CODE (operand1) == CONST_INT)
1906 value = INTVAL (operand1);
1909 && GET_CODE (operand1) == CONST_INT
1910 && HOST_BITS_PER_WIDE_INT > 32
1911 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
1915 /* Extract the low order 32 bits of the value and sign extend.
1916 If the new value is the same as the original value, we can
1917 can use the original value as-is. If the new value is
1918 different, we use it and insert the most-significant 32-bits
1919 of the original value into the final result. */
1920 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
1921 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
1924 #if HOST_BITS_PER_WIDE_INT > 32
1925 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
1929 operand1 = GEN_INT (nval);
1933 if (reload_in_progress || reload_completed)
1934 temp = scratch_reg ? scratch_reg : operand0;
1936 temp = gen_reg_rtx (mode);
1938 /* We don't directly split DImode constants on 32-bit targets
1939 because PLUS uses an 11-bit immediate and the insn sequence
1940 generated is not as efficient as the one using HIGH/LO_SUM. */
1941 if (GET_CODE (operand1) == CONST_INT
1942 && GET_MODE_BITSIZE (mode) <= BITS_PER_WORD
1943 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1946 /* Directly break constant into high and low parts. This
1947 provides better optimization opportunities because various
1948 passes recognize constants split with PLUS but not LO_SUM.
1949 We use a 14-bit signed low part except when the addition
1950 of 0x4000 to the high part might change the sign of the
1952 HOST_WIDE_INT low = value & 0x3fff;
1953 HOST_WIDE_INT high = value & ~ 0x3fff;
1957 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
1965 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
1966 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
1970 emit_insn (gen_rtx_SET (VOIDmode, temp,
1971 gen_rtx_HIGH (mode, operand1)));
1972 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
1975 insn = emit_move_insn (operands[0], operands[1]);
1977 /* Now insert the most significant 32 bits of the value
1978 into the register. When we don't have a second register
1979 available, it could take up to nine instructions to load
1980 a 64-bit integer constant. Prior to reload, we force
1981 constants that would take more than three instructions
1982 to load to the constant pool. During and after reload,
1983 we have to handle all possible values. */
1986 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
1987 register and the value to be inserted is outside the
1988 range that can be loaded with three depdi instructions. */
1989 if (temp != operand0 && (insv >= 16384 || insv < -16384))
1991 operand1 = GEN_INT (insv);
1993 emit_insn (gen_rtx_SET (VOIDmode, temp,
1994 gen_rtx_HIGH (mode, operand1)));
1995 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
1996 emit_insn (gen_insv (operand0, GEN_INT (32),
2001 int len = 5, pos = 27;
2003 /* Insert the bits using the depdi instruction. */
2006 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2007 HOST_WIDE_INT sign = v5 < 0;
2009 /* Left extend the insertion. */
2010 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2011 while (pos > 0 && (insv & 1) == sign)
2013 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2018 emit_insn (gen_insv (operand0, GEN_INT (len),
2019 GEN_INT (pos), GEN_INT (v5)));
2021 len = pos > 0 && pos < 5 ? pos : 5;
2027 set_unique_reg_note (insn, REG_EQUAL, op1);
2032 /* Now have insn-emit do whatever it normally does. */
2036 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2037 it will need a link/runtime reloc). */
2040 reloc_needed (tree exp)
2044 switch (TREE_CODE (exp))
2049 case POINTER_PLUS_EXPR:
2052 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2053 reloc |= reloc_needed (TREE_OPERAND (exp, 1));
2058 case NON_LVALUE_EXPR:
2059 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2065 unsigned HOST_WIDE_INT ix;
2067 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), ix, value)
2069 reloc |= reloc_needed (value);
2082 /* Does operand (which is a symbolic_operand) live in text space?
2083 If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2087 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2089 if (GET_CODE (operand) == CONST)
2090 operand = XEXP (XEXP (operand, 0), 0);
2093 if (GET_CODE (operand) == SYMBOL_REF)
2094 return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2098 if (GET_CODE (operand) == SYMBOL_REF)
2099 return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2105 /* Return the best assembler insn template
2106 for moving operands[1] into operands[0] as a fullword. */
2108 singlemove_string (rtx *operands)
2110 HOST_WIDE_INT intval;
2112 if (GET_CODE (operands[0]) == MEM)
2113 return "stw %r1,%0";
2114 if (GET_CODE (operands[1]) == MEM)
2116 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2121 gcc_assert (GET_MODE (operands[1]) == SFmode);
2123 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2125 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2126 REAL_VALUE_TO_TARGET_SINGLE (d, i);
2128 operands[1] = GEN_INT (i);
2129 /* Fall through to CONST_INT case. */
2131 if (GET_CODE (operands[1]) == CONST_INT)
2133 intval = INTVAL (operands[1]);
2135 if (VAL_14_BITS_P (intval))
2137 else if ((intval & 0x7ff) == 0)
2138 return "ldil L'%1,%0";
2139 else if (zdepi_cint_p (intval))
2140 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2142 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2144 return "copy %1,%0";
2148 /* Compute position (in OP[1]) and width (in OP[2])
2149 useful for copying IMM to a register using the zdepi
2150 instructions. Store the immediate value to insert in OP[0]. */
2152 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2156 /* Find the least significant set bit in IMM. */
2157 for (lsb = 0; lsb < 32; lsb++)
2164 /* Choose variants based on *sign* of the 5-bit field. */
2165 if ((imm & 0x10) == 0)
2166 len = (lsb <= 28) ? 4 : 32 - lsb;
2169 /* Find the width of the bitstring in IMM. */
2170 for (len = 5; len < 32; len++)
2172 if ((imm & (1 << len)) == 0)
2176 /* Sign extend IMM as a 5-bit value. */
2177 imm = (imm & 0xf) - 0x10;
2185 /* Compute position (in OP[1]) and width (in OP[2])
2186 useful for copying IMM to a register using the depdi,z
2187 instructions. Store the immediate value to insert in OP[0]. */
2189 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2191 HOST_WIDE_INT lsb, len;
2193 /* Find the least significant set bit in IMM. */
2194 for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
2201 /* Choose variants based on *sign* of the 5-bit field. */
2202 if ((imm & 0x10) == 0)
2203 len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
2204 ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
2207 /* Find the width of the bitstring in IMM. */
2208 for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
2210 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2214 /* Sign extend IMM as a 5-bit value. */
2215 imm = (imm & 0xf) - 0x10;
2223 /* Output assembler code to perform a doubleword move insn
2224 with operands OPERANDS. */
2227 output_move_double (rtx *operands)
2229 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2231 rtx addreg0 = 0, addreg1 = 0;
2233 /* First classify both operands. */
2235 if (REG_P (operands[0]))
2237 else if (offsettable_memref_p (operands[0]))
2239 else if (GET_CODE (operands[0]) == MEM)
2244 if (REG_P (operands[1]))
2246 else if (CONSTANT_P (operands[1]))
2248 else if (offsettable_memref_p (operands[1]))
2250 else if (GET_CODE (operands[1]) == MEM)
2255 /* Check for the cases that the operand constraints are not
2256 supposed to allow to happen. */
2257 gcc_assert (optype0 == REGOP || optype1 == REGOP);
2259 /* Handle copies between general and floating registers. */
2261 if (optype0 == REGOP && optype1 == REGOP
2262 && FP_REG_P (operands[0]) ^ FP_REG_P (operands[1]))
2264 if (FP_REG_P (operands[0]))
2266 output_asm_insn ("{stws|stw} %1,-16(%%sp)", operands);
2267 output_asm_insn ("{stws|stw} %R1,-12(%%sp)", operands);
2268 return "{fldds|fldd} -16(%%sp),%0";
2272 output_asm_insn ("{fstds|fstd} %1,-16(%%sp)", operands);
2273 output_asm_insn ("{ldws|ldw} -16(%%sp),%0", operands);
2274 return "{ldws|ldw} -12(%%sp),%R0";
2278 /* Handle auto decrementing and incrementing loads and stores
2279 specifically, since the structure of the function doesn't work
2280 for them without major modification. Do it better when we learn
2281 this port about the general inc/dec addressing of PA.
2282 (This was written by tege. Chide him if it doesn't work.) */
2284 if (optype0 == MEMOP)
2286 /* We have to output the address syntax ourselves, since print_operand
2287 doesn't deal with the addresses we want to use. Fix this later. */
2289 rtx addr = XEXP (operands[0], 0);
2290 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2292 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2294 operands[0] = XEXP (addr, 0);
2295 gcc_assert (GET_CODE (operands[1]) == REG
2296 && GET_CODE (operands[0]) == REG);
2298 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2300 /* No overlap between high target register and address
2301 register. (We do this in a non-obvious way to
2302 save a register file writeback) */
2303 if (GET_CODE (addr) == POST_INC)
2304 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2305 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2307 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2309 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2311 operands[0] = XEXP (addr, 0);
2312 gcc_assert (GET_CODE (operands[1]) == REG
2313 && GET_CODE (operands[0]) == REG);
2315 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2316 /* No overlap between high target register and address
2317 register. (We do this in a non-obvious way to save a
2318 register file writeback) */
2319 if (GET_CODE (addr) == PRE_INC)
2320 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2321 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2324 if (optype1 == MEMOP)
2326 /* We have to output the address syntax ourselves, since print_operand
2327 doesn't deal with the addresses we want to use. Fix this later. */
2329 rtx addr = XEXP (operands[1], 0);
2330 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2332 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2334 operands[1] = XEXP (addr, 0);
2335 gcc_assert (GET_CODE (operands[0]) == REG
2336 && GET_CODE (operands[1]) == REG);
2338 if (!reg_overlap_mentioned_p (high_reg, addr))
2340 /* No overlap between high target register and address
2341 register. (We do this in a non-obvious way to
2342 save a register file writeback) */
2343 if (GET_CODE (addr) == POST_INC)
2344 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2345 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2349 /* This is an undefined situation. We should load into the
2350 address register *and* update that register. Probably
2351 we don't need to handle this at all. */
2352 if (GET_CODE (addr) == POST_INC)
2353 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2354 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2357 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2359 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2361 operands[1] = XEXP (addr, 0);
2362 gcc_assert (GET_CODE (operands[0]) == REG
2363 && GET_CODE (operands[1]) == REG);
2365 if (!reg_overlap_mentioned_p (high_reg, addr))
2367 /* No overlap between high target register and address
2368 register. (We do this in a non-obvious way to
2369 save a register file writeback) */
2370 if (GET_CODE (addr) == PRE_INC)
2371 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2372 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2376 /* This is an undefined situation. We should load into the
2377 address register *and* update that register. Probably
2378 we don't need to handle this at all. */
2379 if (GET_CODE (addr) == PRE_INC)
2380 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2381 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2384 else if (GET_CODE (addr) == PLUS
2385 && GET_CODE (XEXP (addr, 0)) == MULT)
2388 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2390 if (!reg_overlap_mentioned_p (high_reg, addr))
2392 xoperands[0] = high_reg;
2393 xoperands[1] = XEXP (addr, 1);
2394 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2395 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2396 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2398 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2402 xoperands[0] = high_reg;
2403 xoperands[1] = XEXP (addr, 1);
2404 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2405 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2406 output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2408 return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2413 /* If an operand is an unoffsettable memory ref, find a register
2414 we can increment temporarily to make it refer to the second word. */
2416 if (optype0 == MEMOP)
2417 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2419 if (optype1 == MEMOP)
2420 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2422 /* Ok, we can do one word at a time.
2423 Normally we do the low-numbered word first.
2425 In either case, set up in LATEHALF the operands to use
2426 for the high-numbered word and in some cases alter the
2427 operands in OPERANDS to be suitable for the low-numbered word. */
2429 if (optype0 == REGOP)
2430 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2431 else if (optype0 == OFFSOP)
2432 latehalf[0] = adjust_address (operands[0], SImode, 4);
2434 latehalf[0] = operands[0];
2436 if (optype1 == REGOP)
2437 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2438 else if (optype1 == OFFSOP)
2439 latehalf[1] = adjust_address (operands[1], SImode, 4);
2440 else if (optype1 == CNSTOP)
2441 split_double (operands[1], &operands[1], &latehalf[1]);
2443 latehalf[1] = operands[1];
2445 /* If the first move would clobber the source of the second one,
2446 do them in the other order.
2448 This can happen in two cases:
2450 mem -> register where the first half of the destination register
2451 is the same register used in the memory's address. Reload
2452 can create such insns.
2454 mem in this case will be either register indirect or register
2455 indirect plus a valid offset.
2457 register -> register move where REGNO(dst) == REGNO(src + 1)
2458 someone (Tim/Tege?) claimed this can happen for parameter loads.
2460 Handle mem -> register case first. */
2461 if (optype0 == REGOP
2462 && (optype1 == MEMOP || optype1 == OFFSOP)
2463 && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2466 /* Do the late half first. */
2468 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2469 output_asm_insn (singlemove_string (latehalf), latehalf);
2473 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2474 return singlemove_string (operands);
2477 /* Now handle register -> register case. */
2478 if (optype0 == REGOP && optype1 == REGOP
2479 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2481 output_asm_insn (singlemove_string (latehalf), latehalf);
2482 return singlemove_string (operands);
2485 /* Normal case: do the two words, low-numbered first. */
2487 output_asm_insn (singlemove_string (operands), operands);
2489 /* Make any unoffsettable addresses point at high-numbered word. */
2491 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2493 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2496 output_asm_insn (singlemove_string (latehalf), latehalf);
2498 /* Undo the adds we just did. */
2500 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2502 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2508 output_fp_move_double (rtx *operands)
2510 if (FP_REG_P (operands[0]))
2512 if (FP_REG_P (operands[1])
2513 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2514 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2516 output_asm_insn ("fldd%F1 %1,%0", operands);
2518 else if (FP_REG_P (operands[1]))
2520 output_asm_insn ("fstd%F0 %1,%0", operands);
2526 gcc_assert (operands[1] == CONST0_RTX (GET_MODE (operands[0])));
2528 /* This is a pain. You have to be prepared to deal with an
2529 arbitrary address here including pre/post increment/decrement.
2531 so avoid this in the MD. */
2532 gcc_assert (GET_CODE (operands[0]) == REG);
2534 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2535 xoperands[0] = operands[0];
2536 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2541 /* Return a REG that occurs in ADDR with coefficient 1.
2542 ADDR can be effectively incremented by incrementing REG. */
2545 find_addr_reg (rtx addr)
2547 while (GET_CODE (addr) == PLUS)
2549 if (GET_CODE (XEXP (addr, 0)) == REG)
2550 addr = XEXP (addr, 0);
2551 else if (GET_CODE (XEXP (addr, 1)) == REG)
2552 addr = XEXP (addr, 1);
2553 else if (CONSTANT_P (XEXP (addr, 0)))
2554 addr = XEXP (addr, 1);
2555 else if (CONSTANT_P (XEXP (addr, 1)))
2556 addr = XEXP (addr, 0);
2560 gcc_assert (GET_CODE (addr) == REG);
2564 /* Emit code to perform a block move.
2566 OPERANDS[0] is the destination pointer as a REG, clobbered.
2567 OPERANDS[1] is the source pointer as a REG, clobbered.
2568 OPERANDS[2] is a register for temporary storage.
2569 OPERANDS[3] is a register for temporary storage.
2570 OPERANDS[4] is the size as a CONST_INT
2571 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2572 OPERANDS[6] is another temporary register. */
2575 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2577 int align = INTVAL (operands[5]);
2578 unsigned long n_bytes = INTVAL (operands[4]);
2580 /* We can't move more than a word at a time because the PA
2581 has no longer integer move insns. (Could use fp mem ops?) */
2582 if (align > (TARGET_64BIT ? 8 : 4))
2583 align = (TARGET_64BIT ? 8 : 4);
2585 /* Note that we know each loop below will execute at least twice
2586 (else we would have open-coded the copy). */
2590 /* Pre-adjust the loop counter. */
2591 operands[4] = GEN_INT (n_bytes - 16);
2592 output_asm_insn ("ldi %4,%2", operands);
2595 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2596 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2597 output_asm_insn ("std,ma %3,8(%0)", operands);
2598 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2599 output_asm_insn ("std,ma %6,8(%0)", operands);
2601 /* Handle the residual. There could be up to 7 bytes of
2602 residual to copy! */
2603 if (n_bytes % 16 != 0)
2605 operands[4] = GEN_INT (n_bytes % 8);
2606 if (n_bytes % 16 >= 8)
2607 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2608 if (n_bytes % 8 != 0)
2609 output_asm_insn ("ldd 0(%1),%6", operands);
2610 if (n_bytes % 16 >= 8)
2611 output_asm_insn ("std,ma %3,8(%0)", operands);
2612 if (n_bytes % 8 != 0)
2613 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2618 /* Pre-adjust the loop counter. */
2619 operands[4] = GEN_INT (n_bytes - 8);
2620 output_asm_insn ("ldi %4,%2", operands);
2623 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2624 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2625 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2626 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2627 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2629 /* Handle the residual. There could be up to 7 bytes of
2630 residual to copy! */
2631 if (n_bytes % 8 != 0)
2633 operands[4] = GEN_INT (n_bytes % 4);
2634 if (n_bytes % 8 >= 4)
2635 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2636 if (n_bytes % 4 != 0)
2637 output_asm_insn ("ldw 0(%1),%6", operands);
2638 if (n_bytes % 8 >= 4)
2639 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2640 if (n_bytes % 4 != 0)
2641 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2646 /* Pre-adjust the loop counter. */
2647 operands[4] = GEN_INT (n_bytes - 4);
2648 output_asm_insn ("ldi %4,%2", operands);
2651 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2652 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2653 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2654 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2655 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2657 /* Handle the residual. */
2658 if (n_bytes % 4 != 0)
2660 if (n_bytes % 4 >= 2)
2661 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2662 if (n_bytes % 2 != 0)
2663 output_asm_insn ("ldb 0(%1),%6", operands);
2664 if (n_bytes % 4 >= 2)
2665 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2666 if (n_bytes % 2 != 0)
2667 output_asm_insn ("stb %6,0(%0)", operands);
2672 /* Pre-adjust the loop counter. */
2673 operands[4] = GEN_INT (n_bytes - 2);
2674 output_asm_insn ("ldi %4,%2", operands);
2677 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2678 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2679 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2680 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2681 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2683 /* Handle the residual. */
2684 if (n_bytes % 2 != 0)
2686 output_asm_insn ("ldb 0(%1),%3", operands);
2687 output_asm_insn ("stb %3,0(%0)", operands);
2696 /* Count the number of insns necessary to handle this block move.
2698 Basic structure is the same as emit_block_move, except that we
2699 count insns rather than emit them. */
2702 compute_movmem_length (rtx insn)
2704 rtx pat = PATTERN (insn);
2705 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2706 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2707 unsigned int n_insns = 0;
2709 /* We can't move more than four bytes at a time because the PA
2710 has no longer integer move insns. (Could use fp mem ops?) */
2711 if (align > (TARGET_64BIT ? 8 : 4))
2712 align = (TARGET_64BIT ? 8 : 4);
2714 /* The basic copying loop. */
2718 if (n_bytes % (2 * align) != 0)
2720 if ((n_bytes % (2 * align)) >= align)
2723 if ((n_bytes % align) != 0)
2727 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2731 /* Emit code to perform a block clear.
2733 OPERANDS[0] is the destination pointer as a REG, clobbered.
2734 OPERANDS[1] is a register for temporary storage.
2735 OPERANDS[2] is the size as a CONST_INT
2736 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
2739 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2741 int align = INTVAL (operands[3]);
2742 unsigned long n_bytes = INTVAL (operands[2]);
2744 /* We can't clear more than a word at a time because the PA
2745 has no longer integer move insns. */
2746 if (align > (TARGET_64BIT ? 8 : 4))
2747 align = (TARGET_64BIT ? 8 : 4);
2749 /* Note that we know each loop below will execute at least twice
2750 (else we would have open-coded the copy). */
2754 /* Pre-adjust the loop counter. */
2755 operands[2] = GEN_INT (n_bytes - 16);
2756 output_asm_insn ("ldi %2,%1", operands);
2759 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2760 output_asm_insn ("addib,>= -16,%1,.-4", operands);
2761 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2763 /* Handle the residual. There could be up to 7 bytes of
2764 residual to copy! */
2765 if (n_bytes % 16 != 0)
2767 operands[2] = GEN_INT (n_bytes % 8);
2768 if (n_bytes % 16 >= 8)
2769 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2770 if (n_bytes % 8 != 0)
2771 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
2776 /* Pre-adjust the loop counter. */
2777 operands[2] = GEN_INT (n_bytes - 8);
2778 output_asm_insn ("ldi %2,%1", operands);
2781 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2782 output_asm_insn ("addib,>= -8,%1,.-4", operands);
2783 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2785 /* Handle the residual. There could be up to 7 bytes of
2786 residual to copy! */
2787 if (n_bytes % 8 != 0)
2789 operands[2] = GEN_INT (n_bytes % 4);
2790 if (n_bytes % 8 >= 4)
2791 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2792 if (n_bytes % 4 != 0)
2793 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
2798 /* Pre-adjust the loop counter. */
2799 operands[2] = GEN_INT (n_bytes - 4);
2800 output_asm_insn ("ldi %2,%1", operands);
2803 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2804 output_asm_insn ("addib,>= -4,%1,.-4", operands);
2805 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2807 /* Handle the residual. */
2808 if (n_bytes % 4 != 0)
2810 if (n_bytes % 4 >= 2)
2811 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2812 if (n_bytes % 2 != 0)
2813 output_asm_insn ("stb %%r0,0(%0)", operands);
2818 /* Pre-adjust the loop counter. */
2819 operands[2] = GEN_INT (n_bytes - 2);
2820 output_asm_insn ("ldi %2,%1", operands);
2823 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2824 output_asm_insn ("addib,>= -2,%1,.-4", operands);
2825 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2827 /* Handle the residual. */
2828 if (n_bytes % 2 != 0)
2829 output_asm_insn ("stb %%r0,0(%0)", operands);
2838 /* Count the number of insns necessary to handle this block move.
2840 Basic structure is the same as emit_block_move, except that we
2841 count insns rather than emit them. */
2844 compute_clrmem_length (rtx insn)
2846 rtx pat = PATTERN (insn);
2847 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
2848 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
2849 unsigned int n_insns = 0;
2851 /* We can't clear more than a word at a time because the PA
2852 has no longer integer move insns. */
2853 if (align > (TARGET_64BIT ? 8 : 4))
2854 align = (TARGET_64BIT ? 8 : 4);
2856 /* The basic loop. */
2860 if (n_bytes % (2 * align) != 0)
2862 if ((n_bytes % (2 * align)) >= align)
2865 if ((n_bytes % align) != 0)
2869 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2875 output_and (rtx *operands)
2877 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2879 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2880 int ls0, ls1, ms0, p, len;
2882 for (ls0 = 0; ls0 < 32; ls0++)
2883 if ((mask & (1 << ls0)) == 0)
2886 for (ls1 = ls0; ls1 < 32; ls1++)
2887 if ((mask & (1 << ls1)) != 0)
2890 for (ms0 = ls1; ms0 < 32; ms0++)
2891 if ((mask & (1 << ms0)) == 0)
2894 gcc_assert (ms0 == 32);
2902 operands[2] = GEN_INT (len);
2903 return "{extru|extrw,u} %1,31,%2,%0";
2907 /* We could use this `depi' for the case above as well, but `depi'
2908 requires one more register file access than an `extru'. */
2913 operands[2] = GEN_INT (p);
2914 operands[3] = GEN_INT (len);
2915 return "{depi|depwi} 0,%2,%3,%0";
2919 return "and %1,%2,%0";
2922 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
2923 storing the result in operands[0]. */
2925 output_64bit_and (rtx *operands)
2927 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2929 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2930 int ls0, ls1, ms0, p, len;
2932 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
2933 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
2936 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
2937 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
2940 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
2941 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
2944 gcc_assert (ms0 == HOST_BITS_PER_WIDE_INT);
2946 if (ls1 == HOST_BITS_PER_WIDE_INT)
2952 operands[2] = GEN_INT (len);
2953 return "extrd,u %1,63,%2,%0";
2957 /* We could use this `depi' for the case above as well, but `depi'
2958 requires one more register file access than an `extru'. */
2963 operands[2] = GEN_INT (p);
2964 operands[3] = GEN_INT (len);
2965 return "depdi 0,%2,%3,%0";
2969 return "and %1,%2,%0";
2973 output_ior (rtx *operands)
2975 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2976 int bs0, bs1, p, len;
2978 if (INTVAL (operands[2]) == 0)
2979 return "copy %1,%0";
2981 for (bs0 = 0; bs0 < 32; bs0++)
2982 if ((mask & (1 << bs0)) != 0)
2985 for (bs1 = bs0; bs1 < 32; bs1++)
2986 if ((mask & (1 << bs1)) == 0)
2989 gcc_assert (bs1 == 32 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
2994 operands[2] = GEN_INT (p);
2995 operands[3] = GEN_INT (len);
2996 return "{depi|depwi} -1,%2,%3,%0";
2999 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3000 storing the result in operands[0]. */
3002 output_64bit_ior (rtx *operands)
3004 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3005 int bs0, bs1, p, len;
3007 if (INTVAL (operands[2]) == 0)
3008 return "copy %1,%0";
3010 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3011 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3014 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3015 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3018 gcc_assert (bs1 == HOST_BITS_PER_WIDE_INT
3019 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
3024 operands[2] = GEN_INT (p);
3025 operands[3] = GEN_INT (len);
3026 return "depdi -1,%2,%3,%0";
3029 /* Target hook for assembling integer objects. This code handles
3030 aligned SI and DI integers specially since function references
3031 must be preceded by P%. */
3034 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3036 if (size == UNITS_PER_WORD
3038 && function_label_operand (x, VOIDmode))
3040 fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
3041 output_addr_const (asm_out_file, x);
3042 fputc ('\n', asm_out_file);
3045 return default_assemble_integer (x, size, aligned_p);
3048 /* Output an ascii string. */
3050 output_ascii (FILE *file, const char *p, int size)
3054 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3056 /* The HP assembler can only take strings of 256 characters at one
3057 time. This is a limitation on input line length, *not* the
3058 length of the string. Sigh. Even worse, it seems that the
3059 restriction is in number of input characters (see \xnn &
3060 \whatever). So we have to do this very carefully. */
3062 fputs ("\t.STRING \"", file);
3065 for (i = 0; i < size; i += 4)
3069 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3071 register unsigned int c = (unsigned char) p[i + io];
3073 if (c == '\"' || c == '\\')
3074 partial_output[co++] = '\\';
3075 if (c >= ' ' && c < 0177)
3076 partial_output[co++] = c;
3080 partial_output[co++] = '\\';
3081 partial_output[co++] = 'x';
3082 hexd = c / 16 - 0 + '0';
3084 hexd -= '9' - 'a' + 1;
3085 partial_output[co++] = hexd;
3086 hexd = c % 16 - 0 + '0';
3088 hexd -= '9' - 'a' + 1;
3089 partial_output[co++] = hexd;
3092 if (chars_output + co > 243)
3094 fputs ("\"\n\t.STRING \"", file);
3097 fwrite (partial_output, 1, (size_t) co, file);
3101 fputs ("\"\n", file);
3104 /* Try to rewrite floating point comparisons & branches to avoid
3105 useless add,tr insns.
3107 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3108 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3109 first attempt to remove useless add,tr insns. It is zero
3110 for the second pass as reorg sometimes leaves bogus REG_DEAD
3113 When CHECK_NOTES is zero we can only eliminate add,tr insns
3114 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3117 remove_useless_addtr_insns (int check_notes)
3120 static int pass = 0;
3122 /* This is fairly cheap, so always run it when optimizing. */
3126 int fbranch_count = 0;
3128 /* Walk all the insns in this function looking for fcmp & fbranch
3129 instructions. Keep track of how many of each we find. */
3130 for (insn = get_insns (); insn; insn = next_insn (insn))
3134 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3135 if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3138 tmp = PATTERN (insn);
3140 /* It must be a set. */
3141 if (GET_CODE (tmp) != SET)
3144 /* If the destination is CCFP, then we've found an fcmp insn. */
3145 tmp = SET_DEST (tmp);
3146 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3152 tmp = PATTERN (insn);
3153 /* If this is an fbranch instruction, bump the fbranch counter. */
3154 if (GET_CODE (tmp) == SET
3155 && SET_DEST (tmp) == pc_rtx
3156 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3157 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3158 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3159 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3167 /* Find all floating point compare + branch insns. If possible,
3168 reverse the comparison & the branch to avoid add,tr insns. */
3169 for (insn = get_insns (); insn; insn = next_insn (insn))
3173 /* Ignore anything that isn't an INSN. */
3174 if (GET_CODE (insn) != INSN)
3177 tmp = PATTERN (insn);
3179 /* It must be a set. */
3180 if (GET_CODE (tmp) != SET)
3183 /* The destination must be CCFP, which is register zero. */
3184 tmp = SET_DEST (tmp);
3185 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3188 /* INSN should be a set of CCFP.
3190 See if the result of this insn is used in a reversed FP
3191 conditional branch. If so, reverse our condition and
3192 the branch. Doing so avoids useless add,tr insns. */
3193 next = next_insn (insn);
3196 /* Jumps, calls and labels stop our search. */
3197 if (GET_CODE (next) == JUMP_INSN
3198 || GET_CODE (next) == CALL_INSN
3199 || GET_CODE (next) == CODE_LABEL)
3202 /* As does another fcmp insn. */
3203 if (GET_CODE (next) == INSN
3204 && GET_CODE (PATTERN (next)) == SET
3205 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3206 && REGNO (SET_DEST (PATTERN (next))) == 0)
3209 next = next_insn (next);
3212 /* Is NEXT_INSN a branch? */
3214 && GET_CODE (next) == JUMP_INSN)
3216 rtx pattern = PATTERN (next);
3218 /* If it a reversed fp conditional branch (e.g. uses add,tr)
3219 and CCFP dies, then reverse our conditional and the branch
3220 to avoid the add,tr. */
3221 if (GET_CODE (pattern) == SET
3222 && SET_DEST (pattern) == pc_rtx
3223 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3224 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3225 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3226 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3227 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3228 && (fcmp_count == fbranch_count
3230 && find_regno_note (next, REG_DEAD, 0))))
3232 /* Reverse the branch. */
3233 tmp = XEXP (SET_SRC (pattern), 1);
3234 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3235 XEXP (SET_SRC (pattern), 2) = tmp;
3236 INSN_CODE (next) = -1;
3238 /* Reverse our condition. */
3239 tmp = PATTERN (insn);
3240 PUT_CODE (XEXP (tmp, 1),
3241 (reverse_condition_maybe_unordered
3242 (GET_CODE (XEXP (tmp, 1)))));
3252 /* You may have trouble believing this, but this is the 32 bit HP-PA
3257 Variable arguments (optional; any number may be allocated)
3259 SP-(4*(N+9)) arg word N
3264 Fixed arguments (must be allocated; may remain unused)
3273 SP-32 External Data Pointer (DP)
3275 SP-24 External/stub RP (RP')
3279 SP-8 Calling Stub RP (RP'')
3284 SP-0 Stack Pointer (points to next available address)
3288 /* This function saves registers as follows. Registers marked with ' are
3289 this function's registers (as opposed to the previous function's).
3290 If a frame_pointer isn't needed, r4 is saved as a general register;
3291 the space for the frame pointer is still allocated, though, to keep
3297 SP (FP') Previous FP
3298 SP + 4 Alignment filler (sigh)
3299 SP + 8 Space for locals reserved here.
3303 SP + n All call saved register used.
3307 SP + o All call saved fp registers used.
3311 SP + p (SP') points to next available address.
3315 /* Global variables set by output_function_prologue(). */
3316 /* Size of frame. Need to know this to emit return insns from
3318 static HOST_WIDE_INT actual_fsize, local_fsize;
3319 static int save_fregs;
3321 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3322 Handle case where DISP > 8k by using the add_high_const patterns.
3324 Note in DISP > 8k case, we will leave the high part of the address
3325 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3328 store_reg (int reg, HOST_WIDE_INT disp, int base)
3330 rtx insn, dest, src, basereg;
3332 src = gen_rtx_REG (word_mode, reg);
3333 basereg = gen_rtx_REG (Pmode, base);
3334 if (VAL_14_BITS_P (disp))
3336 dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3337 insn = emit_move_insn (dest, src);
3339 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3341 rtx delta = GEN_INT (disp);
3342 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3344 emit_move_insn (tmpreg, delta);
3345 insn = emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3349 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3350 gen_rtx_SET (VOIDmode, tmpreg,
3351 gen_rtx_PLUS (Pmode, basereg, delta)),
3353 RTX_FRAME_RELATED_P (insn) = 1;
3355 dest = gen_rtx_MEM (word_mode, tmpreg);
3356 insn = emit_move_insn (dest, src);
3360 rtx delta = GEN_INT (disp);
3361 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3362 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3364 emit_move_insn (tmpreg, high);
3365 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3366 insn = emit_move_insn (dest, src);
3370 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3371 gen_rtx_SET (VOIDmode,
3372 gen_rtx_MEM (word_mode,
3373 gen_rtx_PLUS (word_mode, basereg,
3381 RTX_FRAME_RELATED_P (insn) = 1;
3384 /* Emit RTL to store REG at the memory location specified by BASE and then
3385 add MOD to BASE. MOD must be <= 8k. */
3388 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3390 rtx insn, basereg, srcreg, delta;
3392 gcc_assert (VAL_14_BITS_P (mod));
3394 basereg = gen_rtx_REG (Pmode, base);
3395 srcreg = gen_rtx_REG (word_mode, reg);
3396 delta = GEN_INT (mod);
3398 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3401 RTX_FRAME_RELATED_P (insn) = 1;
3403 /* RTX_FRAME_RELATED_P must be set on each frame related set
3404 in a parallel with more than one element. */
3405 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3406 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3410 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
3411 where DISP > 8k by using the add_high_const patterns. NOTE indicates
3412 whether to add a frame note or not.
3414 In the DISP > 8k case, we leave the high part of the address in %r1.
3415 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
3418 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3422 if (VAL_14_BITS_P (disp))
3424 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3425 plus_constant (gen_rtx_REG (Pmode, base), disp));
3427 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3429 rtx basereg = gen_rtx_REG (Pmode, base);
3430 rtx delta = GEN_INT (disp);
3431 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3433 emit_move_insn (tmpreg, delta);
3434 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3435 gen_rtx_PLUS (Pmode, tmpreg, basereg));
3438 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3439 gen_rtx_SET (VOIDmode, tmpreg,
3440 gen_rtx_PLUS (Pmode, basereg, delta)),
3445 rtx basereg = gen_rtx_REG (Pmode, base);
3446 rtx delta = GEN_INT (disp);
3447 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3449 emit_move_insn (tmpreg,
3450 gen_rtx_PLUS (Pmode, basereg,
3451 gen_rtx_HIGH (Pmode, delta)));
3452 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3453 gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3456 if (DO_FRAME_NOTES && note)
3457 RTX_FRAME_RELATED_P (insn) = 1;
3461 compute_frame_size (HOST_WIDE_INT size, int *fregs_live)
3466 /* The code in hppa_expand_prologue and hppa_expand_epilogue must
3467 be consistent with the rounding and size calculation done here.
3468 Change them at the same time. */
3470 /* We do our own stack alignment. First, round the size of the
3471 stack locals up to a word boundary. */
3472 size = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3474 /* Space for previous frame pointer + filler. If any frame is
3475 allocated, we need to add in the STARTING_FRAME_OFFSET. We
3476 waste some space here for the sake of HP compatibility. The
3477 first slot is only used when the frame pointer is needed. */
3478 if (size || frame_pointer_needed)
3479 size += STARTING_FRAME_OFFSET;
3481 /* If the current function calls __builtin_eh_return, then we need
3482 to allocate stack space for registers that will hold data for
3483 the exception handler. */
3484 if (DO_FRAME_NOTES && current_function_calls_eh_return)
3488 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
3490 size += i * UNITS_PER_WORD;
3493 /* Account for space used by the callee general register saves. */
3494 for (i = 18, j = frame_pointer_needed ? 4 : 3; i >= j; i--)
3495 if (df_regs_ever_live_p (i))
3496 size += UNITS_PER_WORD;
3498 /* Account for space used by the callee floating point register saves. */
3499 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3500 if (df_regs_ever_live_p (i)
3501 || (!TARGET_64BIT && df_regs_ever_live_p (i + 1)))
3505 /* We always save both halves of the FP register, so always
3506 increment the frame size by 8 bytes. */
3510 /* If any of the floating registers are saved, account for the
3511 alignment needed for the floating point register save block. */
3514 size = (size + 7) & ~7;
3519 /* The various ABIs include space for the outgoing parameters in the
3520 size of the current function's stack frame. We don't need to align
3521 for the outgoing arguments as their alignment is set by the final
3522 rounding for the frame as a whole. */
3523 size += current_function_outgoing_args_size;
3525 /* Allocate space for the fixed frame marker. This space must be
3526 allocated for any function that makes calls or allocates
3528 if (!current_function_is_leaf || size)
3529 size += TARGET_64BIT ? 48 : 32;
3531 /* Finally, round to the preferred stack boundary. */
3532 return ((size + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)
3533 & ~(PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1));
3536 /* Generate the assembly code for function entry. FILE is a stdio
3537 stream to output the code to. SIZE is an int: how many units of
3538 temporary storage to allocate.
3540 Refer to the array `regs_ever_live' to determine which registers to
3541 save; `regs_ever_live[I]' is nonzero if register number I is ever
3542 used in the function. This function is responsible for knowing
3543 which registers should not be saved even if used. */
3545 /* On HP-PA, move-double insns between fpu and cpu need an 8-byte block
3546 of memory. If any fpu reg is used in the function, we allocate
3547 such a block here, at the bottom of the frame, just in case it's needed.
3549 If this function is a leaf procedure, then we may choose not
3550 to do a "save" insn. The decision about whether or not
3551 to do this is made in regclass.c. */
3554 pa_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3556 /* The function's label and associated .PROC must never be
3557 separated and must be output *after* any profiling declarations
3558 to avoid changing spaces/subspaces within a procedure. */
3559 ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3560 fputs ("\t.PROC\n", file);
3562 /* hppa_expand_prologue does the dirty work now. We just need
3563 to output the assembler directives which denote the start
3565 fprintf (file, "\t.CALLINFO FRAME=" HOST_WIDE_INT_PRINT_DEC, actual_fsize);
3566 if (df_regs_ever_live_p (2))
3567 fputs (",CALLS,SAVE_RP", file);
3569 fputs (",NO_CALLS", file);
3571 /* The SAVE_SP flag is used to indicate that register %r3 is stored
3572 at the beginning of the frame and that it is used as the frame
3573 pointer for the frame. We do this because our current frame
3574 layout doesn't conform to that specified in the HP runtime
3575 documentation and we need a way to indicate to programs such as
3576 GDB where %r3 is saved. The SAVE_SP flag was chosen because it
3577 isn't used by HP compilers but is supported by the assembler.
3578 However, SAVE_SP is supposed to indicate that the previous stack
3579 pointer has been saved in the frame marker. */
3580 if (frame_pointer_needed)
3581 fputs (",SAVE_SP", file);
3583 /* Pass on information about the number of callee register saves
3584 performed in the prologue.
3586 The compiler is supposed to pass the highest register number
3587 saved, the assembler then has to adjust that number before
3588 entering it into the unwind descriptor (to account for any
3589 caller saved registers with lower register numbers than the
3590 first callee saved register). */
3592 fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
3595 fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
3597 fputs ("\n\t.ENTRY\n", file);
3599 remove_useless_addtr_insns (0);
3603 hppa_expand_prologue (void)
3605 int merge_sp_adjust_with_store = 0;
3606 HOST_WIDE_INT size = get_frame_size ();
3607 HOST_WIDE_INT offset;
3615 /* Compute total size for frame pointer, filler, locals and rounding to
3616 the next word boundary. Similar code appears in compute_frame_size
3617 and must be changed in tandem with this code. */
3618 local_fsize = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3619 if (local_fsize || frame_pointer_needed)
3620 local_fsize += STARTING_FRAME_OFFSET;
3622 actual_fsize = compute_frame_size (size, &save_fregs);
3624 /* Compute a few things we will use often. */
3625 tmpreg = gen_rtx_REG (word_mode, 1);
3627 /* Save RP first. The calling conventions manual states RP will
3628 always be stored into the caller's frame at sp - 20 or sp - 16
3629 depending on which ABI is in use. */
3630 if (df_regs_ever_live_p (2) || current_function_calls_eh_return)
3631 store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM);
3633 /* Allocate the local frame and set up the frame pointer if needed. */
3634 if (actual_fsize != 0)
3636 if (frame_pointer_needed)
3638 /* Copy the old frame pointer temporarily into %r1. Set up the
3639 new stack pointer, then store away the saved old frame pointer
3640 into the stack at sp and at the same time update the stack
3641 pointer by actual_fsize bytes. Two versions, first
3642 handles small (<8k) frames. The second handles large (>=8k)
3644 insn = emit_move_insn (tmpreg, frame_pointer_rtx);
3646 RTX_FRAME_RELATED_P (insn) = 1;
3648 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
3650 RTX_FRAME_RELATED_P (insn) = 1;
3652 if (VAL_14_BITS_P (actual_fsize))
3653 store_reg_modify (STACK_POINTER_REGNUM, 1, actual_fsize);
3656 /* It is incorrect to store the saved frame pointer at *sp,
3657 then increment sp (writes beyond the current stack boundary).
3659 So instead use stwm to store at *sp and post-increment the
3660 stack pointer as an atomic operation. Then increment sp to
3661 finish allocating the new frame. */
3662 HOST_WIDE_INT adjust1 = 8192 - 64;
3663 HOST_WIDE_INT adjust2 = actual_fsize - adjust1;
3665 store_reg_modify (STACK_POINTER_REGNUM, 1, adjust1);
3666 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3670 /* We set SAVE_SP in frames that need a frame pointer. Thus,
3671 we need to store the previous stack pointer (frame pointer)
3672 into the frame marker on targets that use the HP unwind
3673 library. This allows the HP unwind library to be used to
3674 unwind GCC frames. However, we are not fully compatible
3675 with the HP library because our frame layout differs from
3676 that specified in the HP runtime specification.
3678 We don't want a frame note on this instruction as the frame
3679 marker moves during dynamic stack allocation.
3681 This instruction also serves as a blockage to prevent
3682 register spills from being scheduled before the stack
3683 pointer is raised. This is necessary as we store
3684 registers using the frame pointer as a base register,
3685 and the frame pointer is set before sp is raised. */
3686 if (TARGET_HPUX_UNWIND_LIBRARY)
3688 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx,
3689 GEN_INT (TARGET_64BIT ? -8 : -4));
3691 emit_move_insn (gen_rtx_MEM (word_mode, addr),
3695 emit_insn (gen_blockage ());
3697 /* no frame pointer needed. */
3700 /* In some cases we can perform the first callee register save
3701 and allocating the stack frame at the same time. If so, just
3702 make a note of it and defer allocating the frame until saving
3703 the callee registers. */
3704 if (VAL_14_BITS_P (actual_fsize) && local_fsize == 0)
3705 merge_sp_adjust_with_store = 1;
3706 /* Can not optimize. Adjust the stack frame by actual_fsize
3709 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3714 /* Normal register save.
3716 Do not save the frame pointer in the frame_pointer_needed case. It
3717 was done earlier. */
3718 if (frame_pointer_needed)
3720 offset = local_fsize;
3722 /* Saving the EH return data registers in the frame is the simplest
3723 way to get the frame unwind information emitted. We put them
3724 just before the general registers. */
3725 if (DO_FRAME_NOTES && current_function_calls_eh_return)
3727 unsigned int i, regno;
3731 regno = EH_RETURN_DATA_REGNO (i);
3732 if (regno == INVALID_REGNUM)
3735 store_reg (regno, offset, FRAME_POINTER_REGNUM);
3736 offset += UNITS_PER_WORD;
3740 for (i = 18; i >= 4; i--)
3741 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
3743 store_reg (i, offset, FRAME_POINTER_REGNUM);
3744 offset += UNITS_PER_WORD;
3747 /* Account for %r3 which is saved in a special place. */
3750 /* No frame pointer needed. */
3753 offset = local_fsize - actual_fsize;
3755 /* Saving the EH return data registers in the frame is the simplest
3756 way to get the frame unwind information emitted. */
3757 if (DO_FRAME_NOTES && current_function_calls_eh_return)
3759 unsigned int i, regno;
3763 regno = EH_RETURN_DATA_REGNO (i);
3764 if (regno == INVALID_REGNUM)
3767 /* If merge_sp_adjust_with_store is nonzero, then we can
3768 optimize the first save. */
3769 if (merge_sp_adjust_with_store)
3771 store_reg_modify (STACK_POINTER_REGNUM, regno, -offset);
3772 merge_sp_adjust_with_store = 0;
3775 store_reg (regno, offset, STACK_POINTER_REGNUM);
3776 offset += UNITS_PER_WORD;
3780 for (i = 18; i >= 3; i--)
3781 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
3783 /* If merge_sp_adjust_with_store is nonzero, then we can
3784 optimize the first GR save. */
3785 if (merge_sp_adjust_with_store)
3787 store_reg_modify (STACK_POINTER_REGNUM, i, -offset);
3788 merge_sp_adjust_with_store = 0;
3791 store_reg (i, offset, STACK_POINTER_REGNUM);
3792 offset += UNITS_PER_WORD;
3796 /* If we wanted to merge the SP adjustment with a GR save, but we never
3797 did any GR saves, then just emit the adjustment here. */
3798 if (merge_sp_adjust_with_store)
3799 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3803 /* The hppa calling conventions say that %r19, the pic offset
3804 register, is saved at sp - 32 (in this function's frame)
3805 when generating PIC code. FIXME: What is the correct thing
3806 to do for functions which make no calls and allocate no
3807 frame? Do we need to allocate a frame, or can we just omit
3808 the save? For now we'll just omit the save.
3810 We don't want a note on this insn as the frame marker can
3811 move if there is a dynamic stack allocation. */
3812 if (flag_pic && actual_fsize != 0 && !TARGET_64BIT)
3814 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx, GEN_INT (-32));
3816 emit_move_insn (gen_rtx_MEM (word_mode, addr), pic_offset_table_rtx);
3820 /* Align pointer properly (doubleword boundary). */
3821 offset = (offset + 7) & ~7;
3823 /* Floating point register store. */
3828 /* First get the frame or stack pointer to the start of the FP register
3830 if (frame_pointer_needed)
3832 set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset, 0);
3833 base = frame_pointer_rtx;
3837 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
3838 base = stack_pointer_rtx;
3841 /* Now actually save the FP registers. */
3842 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3844 if (df_regs_ever_live_p (i)
3845 || (! TARGET_64BIT && df_regs_ever_live_p (i + 1)))
3847 rtx addr, insn, reg;
3848 addr = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
3849 reg = gen_rtx_REG (DFmode, i);
3850 insn = emit_move_insn (addr, reg);
3853 RTX_FRAME_RELATED_P (insn) = 1;
3856 rtx mem = gen_rtx_MEM (DFmode,
3857 plus_constant (base, offset));
3859 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3860 gen_rtx_SET (VOIDmode, mem, reg),
3865 rtx meml = gen_rtx_MEM (SFmode,
3866 plus_constant (base, offset));
3867 rtx memr = gen_rtx_MEM (SFmode,
3868 plus_constant (base, offset + 4));
3869 rtx regl = gen_rtx_REG (SFmode, i);
3870 rtx regr = gen_rtx_REG (SFmode, i + 1);
3871 rtx setl = gen_rtx_SET (VOIDmode, meml, regl);
3872 rtx setr = gen_rtx_SET (VOIDmode, memr, regr);
3875 RTX_FRAME_RELATED_P (setl) = 1;
3876 RTX_FRAME_RELATED_P (setr) = 1;
3877 vec = gen_rtvec (2, setl, setr);
3879 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3880 gen_rtx_SEQUENCE (VOIDmode, vec),
3884 offset += GET_MODE_SIZE (DFmode);
3891 /* Emit RTL to load REG from the memory location specified by BASE+DISP.
3892 Handle case where DISP > 8k by using the add_high_const patterns. */
3895 load_reg (int reg, HOST_WIDE_INT disp, int base)
3897 rtx dest = gen_rtx_REG (word_mode, reg);
3898 rtx basereg = gen_rtx_REG (Pmode, base);
3901 if (VAL_14_BITS_P (disp))
3902 src = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3903 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3905 rtx delta = GEN_INT (disp);
3906 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3908 emit_move_insn (tmpreg, delta);
3909 if (TARGET_DISABLE_INDEXING)
3911 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3912 src = gen_rtx_MEM (word_mode, tmpreg);
3915 src = gen_rtx_MEM (word_mode, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3919 rtx delta = GEN_INT (disp);
3920 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3921 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3923 emit_move_insn (tmpreg, high);
3924 src = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3927 emit_move_insn (dest, src);
3930 /* Update the total code bytes output to the text section. */
3933 update_total_code_bytes (int nbytes)
3935 if ((TARGET_PORTABLE_RUNTIME || !TARGET_GAS || !TARGET_SOM)
3936 && !IN_NAMED_SECTION_P (cfun->decl))
3938 if (INSN_ADDRESSES_SET_P ())
3940 unsigned long old_total = total_code_bytes;