1 /* Subroutines for insn-output.c for HPPA.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 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"
51 /* Return nonzero if there is a bypass for the output of
52 OUT_INSN and the fp store IN_INSN. */
54 hppa_fpstore_bypass_p (rtx out_insn, rtx in_insn)
56 enum machine_mode store_mode;
57 enum machine_mode other_mode;
60 if (recog_memoized (in_insn) < 0
61 || get_attr_type (in_insn) != TYPE_FPSTORE
62 || recog_memoized (out_insn) < 0)
65 store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
67 set = single_set (out_insn);
71 other_mode = GET_MODE (SET_SRC (set));
73 return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
77 #ifndef DO_FRAME_NOTES
78 #ifdef INCOMING_RETURN_ADDR_RTX
79 #define DO_FRAME_NOTES 1
81 #define DO_FRAME_NOTES 0
85 static void copy_reg_pointer (rtx, rtx);
86 static void fix_range (const char *);
87 static bool pa_handle_option (size_t, const char *, int);
88 static int hppa_address_cost (rtx);
89 static bool hppa_rtx_costs (rtx, int, int, int *);
90 static inline rtx force_mode (enum machine_mode, rtx);
91 static void pa_reorg (void);
92 static void pa_combine_instructions (void);
93 static int pa_can_combine_p (rtx, rtx, rtx, int, rtx, rtx, rtx);
94 static int forward_branch_p (rtx);
95 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
96 static int compute_movmem_length (rtx);
97 static int compute_clrmem_length (rtx);
98 static bool pa_assemble_integer (rtx, unsigned int, int);
99 static void remove_useless_addtr_insns (int);
100 static void store_reg (int, HOST_WIDE_INT, int);
101 static void store_reg_modify (int, int, HOST_WIDE_INT);
102 static void load_reg (int, HOST_WIDE_INT, int);
103 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
104 static void pa_output_function_prologue (FILE *, HOST_WIDE_INT);
105 static void update_total_code_bytes (int);
106 static void pa_output_function_epilogue (FILE *, HOST_WIDE_INT);
107 static int pa_adjust_cost (rtx, rtx, rtx, int);
108 static int pa_adjust_priority (rtx, int);
109 static int pa_issue_rate (void);
110 static void pa_select_section (tree, int, unsigned HOST_WIDE_INT)
112 static void pa_encode_section_info (tree, rtx, int);
113 static const char *pa_strip_name_encoding (const char *);
114 static bool pa_function_ok_for_sibcall (tree, tree);
115 static void pa_globalize_label (FILE *, const char *)
117 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
118 HOST_WIDE_INT, tree);
119 #if !defined(USE_COLLECT2)
120 static void pa_asm_out_constructor (rtx, int);
121 static void pa_asm_out_destructor (rtx, int);
123 static void pa_init_builtins (void);
124 static rtx hppa_builtin_saveregs (void);
125 static tree hppa_gimplify_va_arg_expr (tree, tree, tree *, tree *);
126 static bool pa_scalar_mode_supported_p (enum machine_mode);
127 static bool pa_commutative_p (rtx x, int outer_code);
128 static void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
129 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
130 static struct deferred_plabel *get_plabel (rtx) ATTRIBUTE_UNUSED;
131 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
132 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
133 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
134 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
135 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
136 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
137 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
138 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
139 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
140 static void output_deferred_plabels (void);
141 #ifdef ASM_OUTPUT_EXTERNAL_REAL
142 static void pa_hpux_file_end (void);
144 #ifdef HPUX_LONG_DOUBLE_LIBRARY
145 static void pa_hpux_init_libfuncs (void);
147 static rtx pa_struct_value_rtx (tree, int);
148 static bool pa_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
150 static int pa_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
152 static struct machine_function * pa_init_machine_status (void);
155 /* Save the operands last given to a compare for use when we
156 generate a scc or bcc insn. */
157 rtx hppa_compare_op0, hppa_compare_op1;
158 enum cmp_type hppa_branch_type;
160 /* Which cpu we are scheduling for. */
161 enum processor_type pa_cpu = TARGET_SCHED_DEFAULT;
163 /* The UNIX standard to use for predefines and linking. */
164 int flag_pa_unix = TARGET_HPUX_11_11 ? 1998 : TARGET_HPUX_10_10 ? 1995 : 1993;
166 /* Counts for the number of callee-saved general and floating point
167 registers which were saved by the current function's prologue. */
168 static int gr_saved, fr_saved;
170 static rtx find_addr_reg (rtx);
172 /* Keep track of the number of bytes we have output in the CODE subspace
173 during this compilation so we'll know when to emit inline long-calls. */
174 unsigned long total_code_bytes;
176 /* The last address of the previous function plus the number of bytes in
177 associated thunks that have been output. This is used to determine if
178 a thunk can use an IA-relative branch to reach its target function. */
179 static int last_address;
181 /* Variables to handle plabels that we discover are necessary at assembly
182 output time. They are output after the current function. */
183 struct deferred_plabel GTY(())
188 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
190 static size_t n_deferred_plabels = 0;
193 /* Initialize the GCC target structure. */
195 #undef TARGET_ASM_ALIGNED_HI_OP
196 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
197 #undef TARGET_ASM_ALIGNED_SI_OP
198 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
199 #undef TARGET_ASM_ALIGNED_DI_OP
200 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
201 #undef TARGET_ASM_UNALIGNED_HI_OP
202 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
203 #undef TARGET_ASM_UNALIGNED_SI_OP
204 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
205 #undef TARGET_ASM_UNALIGNED_DI_OP
206 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
207 #undef TARGET_ASM_INTEGER
208 #define TARGET_ASM_INTEGER pa_assemble_integer
210 #undef TARGET_ASM_FUNCTION_PROLOGUE
211 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
212 #undef TARGET_ASM_FUNCTION_EPILOGUE
213 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
215 #undef TARGET_SCHED_ADJUST_COST
216 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
217 #undef TARGET_SCHED_ADJUST_PRIORITY
218 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
219 #undef TARGET_SCHED_ISSUE_RATE
220 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
222 #undef TARGET_ENCODE_SECTION_INFO
223 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
224 #undef TARGET_STRIP_NAME_ENCODING
225 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
227 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
228 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
230 #undef TARGET_COMMUTATIVE_P
231 #define TARGET_COMMUTATIVE_P pa_commutative_p
233 #undef TARGET_ASM_OUTPUT_MI_THUNK
234 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
235 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
236 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
238 #undef TARGET_ASM_FILE_END
239 #ifdef ASM_OUTPUT_EXTERNAL_REAL
240 #define TARGET_ASM_FILE_END pa_hpux_file_end
242 #define TARGET_ASM_FILE_END output_deferred_plabels
245 #if !defined(USE_COLLECT2)
246 #undef TARGET_ASM_CONSTRUCTOR
247 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
248 #undef TARGET_ASM_DESTRUCTOR
249 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
252 #undef TARGET_DEFAULT_TARGET_FLAGS
253 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | TARGET_CPU_DEFAULT)
254 #undef TARGET_HANDLE_OPTION
255 #define TARGET_HANDLE_OPTION pa_handle_option
257 #undef TARGET_INIT_BUILTINS
258 #define TARGET_INIT_BUILTINS pa_init_builtins
260 #undef TARGET_RTX_COSTS
261 #define TARGET_RTX_COSTS hppa_rtx_costs
262 #undef TARGET_ADDRESS_COST
263 #define TARGET_ADDRESS_COST hppa_address_cost
265 #undef TARGET_MACHINE_DEPENDENT_REORG
266 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
268 #ifdef HPUX_LONG_DOUBLE_LIBRARY
269 #undef TARGET_INIT_LIBFUNCS
270 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
273 #undef TARGET_PROMOTE_FUNCTION_RETURN
274 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
275 #undef TARGET_PROMOTE_PROTOTYPES
276 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
278 #undef TARGET_STRUCT_VALUE_RTX
279 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
280 #undef TARGET_RETURN_IN_MEMORY
281 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
282 #undef TARGET_MUST_PASS_IN_STACK
283 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
284 #undef TARGET_PASS_BY_REFERENCE
285 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
286 #undef TARGET_CALLEE_COPIES
287 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
288 #undef TARGET_ARG_PARTIAL_BYTES
289 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
291 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
292 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
293 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
294 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
296 #undef TARGET_SCALAR_MODE_SUPPORTED_P
297 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
299 #undef TARGET_CANNOT_FORCE_CONST_MEM
300 #define TARGET_CANNOT_FORCE_CONST_MEM pa_tls_referenced_p
302 struct gcc_target targetm = TARGET_INITIALIZER;
304 /* Parse the -mfixed-range= option string. */
307 fix_range (const char *const_str)
310 char *str, *dash, *comma;
312 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
313 REG2 are either register names or register numbers. The effect
314 of this option is to mark the registers in the range from REG1 to
315 REG2 as ``fixed'' so they won't be used by the compiler. This is
316 used, e.g., to ensure that kernel mode code doesn't use fr4-fr31. */
318 i = strlen (const_str);
319 str = (char *) alloca (i + 1);
320 memcpy (str, const_str, i + 1);
324 dash = strchr (str, '-');
327 warning (0, "value of -mfixed-range must have form REG1-REG2");
332 comma = strchr (dash + 1, ',');
336 first = decode_reg_name (str);
339 warning (0, "unknown register name: %s", str);
343 last = decode_reg_name (dash + 1);
346 warning (0, "unknown register name: %s", dash + 1);
354 warning (0, "%s-%s is an empty range", str, dash + 1);
358 for (i = first; i <= last; ++i)
359 fixed_regs[i] = call_used_regs[i] = 1;
368 /* Check if all floating point registers have been fixed. */
369 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
374 target_flags |= MASK_DISABLE_FPREGS;
377 /* Implement TARGET_HANDLE_OPTION. */
380 pa_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
385 case OPT_mpa_risc_1_0:
387 target_flags &= ~(MASK_PA_11 | MASK_PA_20);
391 case OPT_mpa_risc_1_1:
393 target_flags &= ~MASK_PA_20;
394 target_flags |= MASK_PA_11;
397 case OPT_mpa_risc_2_0:
399 target_flags |= MASK_PA_11 | MASK_PA_20;
403 if (strcmp (arg, "8000") == 0)
404 pa_cpu = PROCESSOR_8000;
405 else if (strcmp (arg, "7100") == 0)
406 pa_cpu = PROCESSOR_7100;
407 else if (strcmp (arg, "700") == 0)
408 pa_cpu = PROCESSOR_700;
409 else if (strcmp (arg, "7100LC") == 0)
410 pa_cpu = PROCESSOR_7100LC;
411 else if (strcmp (arg, "7200") == 0)
412 pa_cpu = PROCESSOR_7200;
413 else if (strcmp (arg, "7300") == 0)
414 pa_cpu = PROCESSOR_7300;
419 case OPT_mfixed_range_:
429 #if TARGET_HPUX_10_10
435 #if TARGET_HPUX_11_11
447 override_options (void)
449 /* Unconditional branches in the delay slot are not compatible with dwarf2
450 call frame information. There is no benefit in using this optimization
451 on PA8000 and later processors. */
452 if (pa_cpu >= PROCESSOR_8000
453 || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
454 || flag_unwind_tables)
455 target_flags &= ~MASK_JUMP_IN_DELAY;
457 if (flag_pic && TARGET_PORTABLE_RUNTIME)
459 warning (0, "PIC code generation is not supported in the portable runtime model");
462 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
464 warning (0, "PIC code generation is not compatible with fast indirect calls");
467 if (! TARGET_GAS && write_symbols != NO_DEBUG)
469 warning (0, "-g is only supported when using GAS on this processor,");
470 warning (0, "-g option disabled");
471 write_symbols = NO_DEBUG;
474 /* We only support the "big PIC" model now. And we always generate PIC
475 code when in 64bit mode. */
476 if (flag_pic == 1 || TARGET_64BIT)
479 /* We can't guarantee that .dword is available for 32-bit targets. */
480 if (UNITS_PER_WORD == 4)
481 targetm.asm_out.aligned_op.di = NULL;
483 /* The unaligned ops are only available when using GAS. */
486 targetm.asm_out.unaligned_op.hi = NULL;
487 targetm.asm_out.unaligned_op.si = NULL;
488 targetm.asm_out.unaligned_op.di = NULL;
491 init_machine_status = pa_init_machine_status;
495 pa_init_builtins (void)
497 #ifdef DONT_HAVE_FPUTC_UNLOCKED
498 built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
499 implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
503 /* Function to init struct machine_function.
504 This will be called, via a pointer variable,
505 from push_function_context. */
507 static struct machine_function *
508 pa_init_machine_status (void)
510 return ggc_alloc_cleared (sizeof (machine_function));
513 /* If FROM is a probable pointer register, mark TO as a probable
514 pointer register with the same pointer alignment as FROM. */
517 copy_reg_pointer (rtx to, rtx from)
519 if (REG_POINTER (from))
520 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
523 /* Return 1 if X contains a symbolic expression. We know these
524 expressions will have one of a few well defined forms, so
525 we need only check those forms. */
527 symbolic_expression_p (rtx x)
530 /* Strip off any HIGH. */
531 if (GET_CODE (x) == HIGH)
534 return (symbolic_operand (x, VOIDmode));
537 /* Accept any constant that can be moved in one instruction into a
540 cint_ok_for_move (HOST_WIDE_INT intval)
542 /* OK if ldo, ldil, or zdepi, can be used. */
543 return (CONST_OK_FOR_LETTER_P (intval, 'J')
544 || CONST_OK_FOR_LETTER_P (intval, 'N')
545 || CONST_OK_FOR_LETTER_P (intval, 'K'));
548 /* Return truth value of whether OP can be used as an operand in a
551 adddi3_operand (rtx op, enum machine_mode mode)
553 return (register_operand (op, mode)
554 || (GET_CODE (op) == CONST_INT
555 && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
558 /* True iff zdepi can be used to generate this CONST_INT.
559 zdepi first sign extends a 5 bit signed number to a given field
560 length, then places this field anywhere in a zero. */
562 zdepi_cint_p (unsigned HOST_WIDE_INT x)
564 unsigned HOST_WIDE_INT lsb_mask, t;
566 /* This might not be obvious, but it's at least fast.
567 This function is critical; we don't have the time loops would take. */
569 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
570 /* Return true iff t is a power of two. */
571 return ((t & (t - 1)) == 0);
574 /* True iff depi or extru can be used to compute (reg & mask).
575 Accept bit pattern like these:
580 and_mask_p (unsigned HOST_WIDE_INT mask)
583 mask += mask & -mask;
584 return (mask & (mask - 1)) == 0;
587 /* True iff depi can be used to compute (reg | MASK). */
589 ior_mask_p (unsigned HOST_WIDE_INT mask)
591 mask += mask & -mask;
592 return (mask & (mask - 1)) == 0;
595 /* Legitimize PIC addresses. If the address is already
596 position-independent, we return ORIG. Newly generated
597 position-independent addresses go to REG. If we need more
598 than one register, we lose. */
601 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
605 gcc_assert (!PA_SYMBOL_REF_TLS_P (orig));
607 /* Labels need special handling. */
608 if (pic_label_operand (orig, mode))
610 /* We do not want to go through the movXX expanders here since that
611 would create recursion.
613 Nor do we really want to call a generator for a named pattern
614 since that requires multiple patterns if we want to support
617 So instead we just emit the raw set, which avoids the movXX
618 expanders completely. */
619 mark_reg_pointer (reg, BITS_PER_UNIT);
620 emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
621 current_function_uses_pic_offset_table = 1;
624 if (GET_CODE (orig) == SYMBOL_REF)
630 /* Before reload, allocate a temporary register for the intermediate
631 result. This allows the sequence to be deleted when the final
632 result is unused and the insns are trivially dead. */
633 tmp_reg = ((reload_in_progress || reload_completed)
634 ? reg : gen_reg_rtx (Pmode));
636 emit_move_insn (tmp_reg,
637 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
638 gen_rtx_HIGH (word_mode, orig)));
640 = gen_const_mem (Pmode,
641 gen_rtx_LO_SUM (Pmode, tmp_reg,
642 gen_rtx_UNSPEC (Pmode,
646 current_function_uses_pic_offset_table = 1;
647 mark_reg_pointer (reg, BITS_PER_UNIT);
648 insn = emit_move_insn (reg, pic_ref);
650 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
651 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig, REG_NOTES (insn));
655 else if (GET_CODE (orig) == CONST)
659 if (GET_CODE (XEXP (orig, 0)) == PLUS
660 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
664 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
666 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
667 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
668 base == reg ? 0 : reg);
670 if (GET_CODE (orig) == CONST_INT)
672 if (INT_14_BITS (orig))
673 return plus_constant (base, INTVAL (orig));
674 orig = force_reg (Pmode, orig);
676 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
677 /* Likewise, should we set special REG_NOTEs here? */
683 static GTY(()) rtx gen_tls_tga;
686 gen_tls_get_addr (void)
689 gen_tls_tga = init_one_libfunc ("__tls_get_addr");
694 hppa_tls_call (rtx arg)
698 ret = gen_reg_rtx (Pmode);
699 emit_library_call_value (gen_tls_get_addr (), ret,
700 LCT_CONST, Pmode, 1, arg, Pmode);
706 legitimize_tls_address (rtx addr)
708 rtx ret, insn, tmp, t1, t2, tp;
709 enum tls_model model = SYMBOL_REF_TLS_MODEL (addr);
713 case TLS_MODEL_GLOBAL_DYNAMIC:
714 tmp = gen_reg_rtx (Pmode);
715 emit_insn (gen_tgd_load (tmp, addr));
716 ret = hppa_tls_call (tmp);
719 case TLS_MODEL_LOCAL_DYNAMIC:
720 ret = gen_reg_rtx (Pmode);
721 tmp = gen_reg_rtx (Pmode);
723 emit_insn (gen_tld_load (tmp, addr));
724 t1 = hppa_tls_call (tmp);
727 t2 = gen_reg_rtx (Pmode);
728 emit_libcall_block (insn, t2, t1,
729 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
731 emit_insn (gen_tld_offset_load (ret, addr, t2));
734 case TLS_MODEL_INITIAL_EXEC:
735 tp = gen_reg_rtx (Pmode);
736 tmp = gen_reg_rtx (Pmode);
737 ret = gen_reg_rtx (Pmode);
738 emit_insn (gen_tp_load (tp));
739 emit_insn (gen_tie_load (tmp, addr));
740 emit_move_insn (ret, gen_rtx_PLUS (Pmode, tp, tmp));
743 case TLS_MODEL_LOCAL_EXEC:
744 tp = gen_reg_rtx (Pmode);
745 ret = gen_reg_rtx (Pmode);
746 emit_insn (gen_tp_load (tp));
747 emit_insn (gen_tle_load (ret, addr, tp));
757 /* Try machine-dependent ways of modifying an illegitimate address
758 to be legitimate. If we find one, return the new, valid address.
759 This macro is used in only one place: `memory_address' in explow.c.
761 OLDX is the address as it was before break_out_memory_refs was called.
762 In some cases it is useful to look at this to decide what needs to be done.
764 MODE and WIN are passed so that this macro can use
765 GO_IF_LEGITIMATE_ADDRESS.
767 It is always safe for this macro to do nothing. It exists to recognize
768 opportunities to optimize the output.
770 For the PA, transform:
772 memory(X + <large int>)
776 if (<large int> & mask) >= 16
777 Y = (<large int> & ~mask) + mask + 1 Round up.
779 Y = (<large int> & ~mask) Round down.
781 memory (Z + (<large int> - Y));
783 This is for CSE to find several similar references, and only use one Z.
785 X can either be a SYMBOL_REF or REG, but because combine cannot
786 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
787 D will not fit in 14 bits.
789 MODE_FLOAT references allow displacements which fit in 5 bits, so use
792 MODE_INT references allow displacements which fit in 14 bits, so use
795 This relies on the fact that most mode MODE_FLOAT references will use FP
796 registers and most mode MODE_INT references will use integer registers.
797 (In the rare case of an FP register used in an integer MODE, we depend
798 on secondary reloads to clean things up.)
801 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
802 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
803 addressing modes to be used).
805 Put X and Z into registers. Then put the entire expression into
809 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
810 enum machine_mode mode)
814 /* We need to canonicalize the order of operands in unscaled indexed
815 addresses since the code that checks if an address is valid doesn't
816 always try both orders. */
817 if (!TARGET_NO_SPACE_REGS
818 && GET_CODE (x) == PLUS
819 && GET_MODE (x) == Pmode
820 && REG_P (XEXP (x, 0))
821 && REG_P (XEXP (x, 1))
822 && REG_POINTER (XEXP (x, 0))
823 && !REG_POINTER (XEXP (x, 1)))
824 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
826 if (PA_SYMBOL_REF_TLS_P (x))
827 return legitimize_tls_address (x);
829 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
831 /* Strip off CONST. */
832 if (GET_CODE (x) == CONST)
835 /* Special case. Get the SYMBOL_REF into a register and use indexing.
836 That should always be safe. */
837 if (GET_CODE (x) == PLUS
838 && GET_CODE (XEXP (x, 0)) == REG
839 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
841 rtx reg = force_reg (Pmode, XEXP (x, 1));
842 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
845 /* Note we must reject symbols which represent function addresses
846 since the assembler/linker can't handle arithmetic on plabels. */
847 if (GET_CODE (x) == PLUS
848 && GET_CODE (XEXP (x, 1)) == CONST_INT
849 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
850 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
851 || GET_CODE (XEXP (x, 0)) == REG))
853 rtx int_part, ptr_reg;
855 int offset = INTVAL (XEXP (x, 1));
858 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
859 ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
861 /* Choose which way to round the offset. Round up if we
862 are >= halfway to the next boundary. */
863 if ((offset & mask) >= ((mask + 1) / 2))
864 newoffset = (offset & ~ mask) + mask + 1;
866 newoffset = (offset & ~ mask);
868 /* If the newoffset will not fit in 14 bits (ldo), then
869 handling this would take 4 or 5 instructions (2 to load
870 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
871 add the new offset and the SYMBOL_REF.) Combine can
872 not handle 4->2 or 5->2 combinations, so do not create
874 if (! VAL_14_BITS_P (newoffset)
875 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
877 rtx const_part = plus_constant (XEXP (x, 0), newoffset);
880 gen_rtx_HIGH (Pmode, const_part));
883 gen_rtx_LO_SUM (Pmode,
884 tmp_reg, const_part));
888 if (! VAL_14_BITS_P (newoffset))
889 int_part = force_reg (Pmode, GEN_INT (newoffset));
891 int_part = GEN_INT (newoffset);
893 ptr_reg = force_reg (Pmode,
895 force_reg (Pmode, XEXP (x, 0)),
898 return plus_constant (ptr_reg, offset - newoffset);
901 /* Handle (plus (mult (a) (shadd_constant)) (b)). */
903 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
904 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
905 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
906 && (OBJECT_P (XEXP (x, 1))
907 || GET_CODE (XEXP (x, 1)) == SUBREG)
908 && GET_CODE (XEXP (x, 1)) != CONST)
910 int val = INTVAL (XEXP (XEXP (x, 0), 1));
914 if (GET_CODE (reg1) != REG)
915 reg1 = force_reg (Pmode, force_operand (reg1, 0));
917 reg2 = XEXP (XEXP (x, 0), 0);
918 if (GET_CODE (reg2) != REG)
919 reg2 = force_reg (Pmode, force_operand (reg2, 0));
921 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
928 /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
930 Only do so for floating point modes since this is more speculative
931 and we lose if it's an integer store. */
932 if (GET_CODE (x) == PLUS
933 && GET_CODE (XEXP (x, 0)) == PLUS
934 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
935 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
936 && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
937 && (mode == SFmode || mode == DFmode))
940 /* First, try and figure out what to use as a base register. */
941 rtx reg1, reg2, base, idx, orig_base;
943 reg1 = XEXP (XEXP (x, 0), 1);
948 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
949 then emit_move_sequence will turn on REG_POINTER so we'll know
950 it's a base register below. */
951 if (GET_CODE (reg1) != REG)
952 reg1 = force_reg (Pmode, force_operand (reg1, 0));
954 if (GET_CODE (reg2) != REG)
955 reg2 = force_reg (Pmode, force_operand (reg2, 0));
957 /* Figure out what the base and index are. */
959 if (GET_CODE (reg1) == REG
960 && REG_POINTER (reg1))
963 orig_base = XEXP (XEXP (x, 0), 1);
964 idx = gen_rtx_PLUS (Pmode,
966 XEXP (XEXP (XEXP (x, 0), 0), 0),
967 XEXP (XEXP (XEXP (x, 0), 0), 1)),
970 else if (GET_CODE (reg2) == REG
971 && REG_POINTER (reg2))
974 orig_base = XEXP (x, 1);
981 /* If the index adds a large constant, try to scale the
982 constant so that it can be loaded with only one insn. */
983 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
984 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
985 / INTVAL (XEXP (XEXP (idx, 0), 1)))
986 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
988 /* Divide the CONST_INT by the scale factor, then add it to A. */
989 int val = INTVAL (XEXP (idx, 1));
991 val /= INTVAL (XEXP (XEXP (idx, 0), 1));
992 reg1 = XEXP (XEXP (idx, 0), 0);
993 if (GET_CODE (reg1) != REG)
994 reg1 = force_reg (Pmode, force_operand (reg1, 0));
996 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
998 /* We can now generate a simple scaled indexed address. */
1001 (Pmode, gen_rtx_PLUS (Pmode,
1002 gen_rtx_MULT (Pmode, reg1,
1003 XEXP (XEXP (idx, 0), 1)),
1007 /* If B + C is still a valid base register, then add them. */
1008 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1009 && INTVAL (XEXP (idx, 1)) <= 4096
1010 && INTVAL (XEXP (idx, 1)) >= -4096)
1012 int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1015 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1017 reg2 = XEXP (XEXP (idx, 0), 0);
1018 if (GET_CODE (reg2) != CONST_INT)
1019 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1021 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1022 gen_rtx_MULT (Pmode,
1028 /* Get the index into a register, then add the base + index and
1029 return a register holding the result. */
1031 /* First get A into a register. */
1032 reg1 = XEXP (XEXP (idx, 0), 0);
1033 if (GET_CODE (reg1) != REG)
1034 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1036 /* And get B into a register. */
1037 reg2 = XEXP (idx, 1);
1038 if (GET_CODE (reg2) != REG)
1039 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1041 reg1 = force_reg (Pmode,
1042 gen_rtx_PLUS (Pmode,
1043 gen_rtx_MULT (Pmode, reg1,
1044 XEXP (XEXP (idx, 0), 1)),
1047 /* Add the result to our base register and return. */
1048 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1052 /* Uh-oh. We might have an address for x[n-100000]. This needs
1053 special handling to avoid creating an indexed memory address
1054 with x-100000 as the base.
1056 If the constant part is small enough, then it's still safe because
1057 there is a guard page at the beginning and end of the data segment.
1059 Scaled references are common enough that we want to try and rearrange the
1060 terms so that we can use indexing for these addresses too. Only
1061 do the optimization for floatint point modes. */
1063 if (GET_CODE (x) == PLUS
1064 && symbolic_expression_p (XEXP (x, 1)))
1066 /* Ugly. We modify things here so that the address offset specified
1067 by the index expression is computed first, then added to x to form
1068 the entire address. */
1070 rtx regx1, regx2, regy1, regy2, y;
1072 /* Strip off any CONST. */
1074 if (GET_CODE (y) == CONST)
1077 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1079 /* See if this looks like
1080 (plus (mult (reg) (shadd_const))
1081 (const (plus (symbol_ref) (const_int))))
1083 Where const_int is small. In that case the const
1084 expression is a valid pointer for indexing.
1086 If const_int is big, but can be divided evenly by shadd_const
1087 and added to (reg). This allows more scaled indexed addresses. */
1088 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1089 && GET_CODE (XEXP (x, 0)) == MULT
1090 && GET_CODE (XEXP (y, 1)) == CONST_INT
1091 && INTVAL (XEXP (y, 1)) >= -4096
1092 && INTVAL (XEXP (y, 1)) <= 4095
1093 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1094 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1096 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1100 if (GET_CODE (reg1) != REG)
1101 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1103 reg2 = XEXP (XEXP (x, 0), 0);
1104 if (GET_CODE (reg2) != REG)
1105 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1107 return force_reg (Pmode,
1108 gen_rtx_PLUS (Pmode,
1109 gen_rtx_MULT (Pmode,
1114 else if ((mode == DFmode || mode == SFmode)
1115 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1116 && GET_CODE (XEXP (x, 0)) == MULT
1117 && GET_CODE (XEXP (y, 1)) == CONST_INT
1118 && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1119 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1120 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1123 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1124 / INTVAL (XEXP (XEXP (x, 0), 1))));
1125 regx2 = XEXP (XEXP (x, 0), 0);
1126 if (GET_CODE (regx2) != REG)
1127 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1128 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1132 gen_rtx_PLUS (Pmode,
1133 gen_rtx_MULT (Pmode, regx2,
1134 XEXP (XEXP (x, 0), 1)),
1135 force_reg (Pmode, XEXP (y, 0))));
1137 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1138 && INTVAL (XEXP (y, 1)) >= -4096
1139 && INTVAL (XEXP (y, 1)) <= 4095)
1141 /* This is safe because of the guard page at the
1142 beginning and end of the data space. Just
1143 return the original address. */
1148 /* Doesn't look like one we can optimize. */
1149 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1150 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1151 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1152 regx1 = force_reg (Pmode,
1153 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1155 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1163 /* For the HPPA, REG and REG+CONST is cost 0
1164 and addresses involving symbolic constants are cost 2.
1166 PIC addresses are very expensive.
1168 It is no coincidence that this has the same structure
1169 as GO_IF_LEGITIMATE_ADDRESS. */
1172 hppa_address_cost (rtx X)
1174 switch (GET_CODE (X))
1187 /* Compute a (partial) cost for rtx X. Return true if the complete
1188 cost has been computed, and false if subexpressions should be
1189 scanned. In either case, *TOTAL contains the cost result. */
1192 hppa_rtx_costs (rtx x, int code, int outer_code, int *total)
1197 if (INTVAL (x) == 0)
1199 else if (INT_14_BITS (x))
1216 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1217 && outer_code != SET)
1224 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1225 *total = COSTS_N_INSNS (3);
1226 else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1227 *total = COSTS_N_INSNS (8);
1229 *total = COSTS_N_INSNS (20);
1233 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1235 *total = COSTS_N_INSNS (14);
1243 *total = COSTS_N_INSNS (60);
1246 case PLUS: /* this includes shNadd insns */
1248 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1249 *total = COSTS_N_INSNS (3);
1251 *total = COSTS_N_INSNS (1);
1257 *total = COSTS_N_INSNS (1);
1265 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1266 new rtx with the correct mode. */
1268 force_mode (enum machine_mode mode, rtx orig)
1270 if (mode == GET_MODE (orig))
1273 gcc_assert (REGNO (orig) < FIRST_PSEUDO_REGISTER);
1275 return gen_rtx_REG (mode, REGNO (orig));
1278 /* Return 1 if *X is a thread-local symbol. */
1281 pa_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1283 return PA_SYMBOL_REF_TLS_P (*x);
1286 /* Return 1 if X contains a thread-local symbol. */
1289 pa_tls_referenced_p (rtx x)
1291 if (!TARGET_HAVE_TLS)
1294 return for_each_rtx (&x, &pa_tls_symbol_ref_1, 0);
1297 /* Emit insns to move operands[1] into operands[0].
1299 Return 1 if we have written out everything that needs to be done to
1300 do the move. Otherwise, return 0 and the caller will emit the move
1303 Note SCRATCH_REG may not be in the proper mode depending on how it
1304 will be used. This routine is responsible for creating a new copy
1305 of SCRATCH_REG in the proper mode. */
1308 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1310 register rtx operand0 = operands[0];
1311 register rtx operand1 = operands[1];
1314 /* We can only handle indexed addresses in the destination operand
1315 of floating point stores. Thus, we need to break out indexed
1316 addresses from the destination operand. */
1317 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1319 /* This is only safe up to the beginning of life analysis. */
1320 gcc_assert (!no_new_pseudos);
1322 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1323 operand0 = replace_equiv_address (operand0, tem);
1326 /* On targets with non-equivalent space registers, break out unscaled
1327 indexed addresses from the source operand before the final CSE.
1328 We have to do this because the REG_POINTER flag is not correctly
1329 carried through various optimization passes and CSE may substitute
1330 a pseudo without the pointer set for one with the pointer set. As
1331 a result, we loose various opportunities to create insns with
1332 unscaled indexed addresses. */
1333 if (!TARGET_NO_SPACE_REGS
1334 && !cse_not_expected
1335 && GET_CODE (operand1) == MEM
1336 && GET_CODE (XEXP (operand1, 0)) == PLUS
1337 && REG_P (XEXP (XEXP (operand1, 0), 0))
1338 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1340 = replace_equiv_address (operand1,
1341 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1344 && reload_in_progress && GET_CODE (operand0) == REG
1345 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1346 operand0 = reg_equiv_mem[REGNO (operand0)];
1347 else if (scratch_reg
1348 && reload_in_progress && GET_CODE (operand0) == SUBREG
1349 && GET_CODE (SUBREG_REG (operand0)) == REG
1350 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1352 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1353 the code which tracks sets/uses for delete_output_reload. */
1354 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1355 reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1356 SUBREG_BYTE (operand0));
1357 operand0 = alter_subreg (&temp);
1361 && reload_in_progress && GET_CODE (operand1) == REG
1362 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1363 operand1 = reg_equiv_mem[REGNO (operand1)];
1364 else if (scratch_reg
1365 && reload_in_progress && GET_CODE (operand1) == SUBREG
1366 && GET_CODE (SUBREG_REG (operand1)) == REG
1367 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1369 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1370 the code which tracks sets/uses for delete_output_reload. */
1371 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1372 reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1373 SUBREG_BYTE (operand1));
1374 operand1 = alter_subreg (&temp);
1377 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1378 && ((tem = find_replacement (&XEXP (operand0, 0)))
1379 != XEXP (operand0, 0)))
1380 operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
1382 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1383 && ((tem = find_replacement (&XEXP (operand1, 0)))
1384 != XEXP (operand1, 0)))
1385 operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
1387 /* Handle secondary reloads for loads/stores of FP registers from
1388 REG+D addresses where D does not fit in 5 or 14 bits, including
1389 (subreg (mem (addr))) cases. */
1391 && fp_reg_operand (operand0, mode)
1392 && ((GET_CODE (operand1) == MEM
1393 && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1394 XEXP (operand1, 0)))
1395 || ((GET_CODE (operand1) == SUBREG
1396 && GET_CODE (XEXP (operand1, 0)) == MEM
1397 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1399 XEXP (XEXP (operand1, 0), 0))))))
1401 if (GET_CODE (operand1) == SUBREG)
1402 operand1 = XEXP (operand1, 0);
1404 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1405 it in WORD_MODE regardless of what mode it was originally given
1407 scratch_reg = force_mode (word_mode, scratch_reg);
1409 /* D might not fit in 14 bits either; for such cases load D into
1411 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1413 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1414 emit_move_insn (scratch_reg,
1415 gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1417 XEXP (XEXP (operand1, 0), 0),
1421 emit_move_insn (scratch_reg, XEXP (operand1, 0));
1422 emit_insn (gen_rtx_SET (VOIDmode, operand0,
1423 gen_rtx_MEM (mode, scratch_reg)));
1426 else if (scratch_reg
1427 && fp_reg_operand (operand1, mode)
1428 && ((GET_CODE (operand0) == MEM
1429 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1431 XEXP (operand0, 0)))
1432 || ((GET_CODE (operand0) == SUBREG)
1433 && GET_CODE (XEXP (operand0, 0)) == MEM
1434 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1436 XEXP (XEXP (operand0, 0), 0)))))
1438 if (GET_CODE (operand0) == SUBREG)
1439 operand0 = XEXP (operand0, 0);
1441 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1442 it in WORD_MODE regardless of what mode it was originally given
1444 scratch_reg = force_mode (word_mode, scratch_reg);
1446 /* D might not fit in 14 bits either; for such cases load D into
1448 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1450 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1451 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1454 XEXP (XEXP (operand0, 0),
1459 emit_move_insn (scratch_reg, XEXP (operand0, 0));
1460 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
1464 /* Handle secondary reloads for loads of FP registers from constant
1465 expressions by forcing the constant into memory.
1467 Use scratch_reg to hold the address of the memory location.
1469 The proper fix is to change PREFERRED_RELOAD_CLASS to return
1470 NO_REGS when presented with a const_int and a register class
1471 containing only FP registers. Doing so unfortunately creates
1472 more problems than it solves. Fix this for 2.5. */
1473 else if (scratch_reg
1474 && CONSTANT_P (operand1)
1475 && fp_reg_operand (operand0, mode))
1479 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1480 it in WORD_MODE regardless of what mode it was originally given
1482 scratch_reg = force_mode (word_mode, scratch_reg);
1484 /* Force the constant into memory and put the address of the
1485 memory location into scratch_reg. */
1486 xoperands[0] = scratch_reg;
1487 xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
1488 emit_move_sequence (xoperands, Pmode, 0);
1490 /* Now load the destination register. */
1491 emit_insn (gen_rtx_SET (mode, operand0,
1492 gen_rtx_MEM (mode, scratch_reg)));
1495 /* Handle secondary reloads for SAR. These occur when trying to load
1496 the SAR from memory, FP register, or with a constant. */
1497 else if (scratch_reg
1498 && GET_CODE (operand0) == REG
1499 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1500 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1501 && (GET_CODE (operand1) == MEM
1502 || GET_CODE (operand1) == CONST_INT
1503 || (GET_CODE (operand1) == REG
1504 && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1506 /* D might not fit in 14 bits either; for such cases load D into
1508 if (GET_CODE (operand1) == MEM
1509 && !memory_address_p (Pmode, XEXP (operand1, 0)))
1511 /* We are reloading the address into the scratch register, so we
1512 want to make sure the scratch register is a full register. */
1513 scratch_reg = force_mode (word_mode, scratch_reg);
1515 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1516 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1519 XEXP (XEXP (operand1, 0),
1523 /* Now we are going to load the scratch register from memory,
1524 we want to load it in the same width as the original MEM,
1525 which must be the same as the width of the ultimate destination,
1527 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1529 emit_move_insn (scratch_reg, gen_rtx_MEM (GET_MODE (operand0),
1534 /* We want to load the scratch register using the same mode as
1535 the ultimate destination. */
1536 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1538 emit_move_insn (scratch_reg, operand1);
1541 /* And emit the insn to set the ultimate destination. We know that
1542 the scratch register has the same mode as the destination at this
1544 emit_move_insn (operand0, scratch_reg);
1547 /* Handle the most common case: storing into a register. */
1548 else if (register_operand (operand0, mode))
1550 if (register_operand (operand1, mode)
1551 || (GET_CODE (operand1) == CONST_INT
1552 && cint_ok_for_move (INTVAL (operand1)))
1553 || (operand1 == CONST0_RTX (mode))
1554 || (GET_CODE (operand1) == HIGH
1555 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1556 /* Only `general_operands' can come here, so MEM is ok. */
1557 || GET_CODE (operand1) == MEM)
1559 /* Various sets are created during RTL generation which don't
1560 have the REG_POINTER flag correctly set. After the CSE pass,
1561 instruction recognition can fail if we don't consistently
1562 set this flag when performing register copies. This should
1563 also improve the opportunities for creating insns that use
1564 unscaled indexing. */
1565 if (REG_P (operand0) && REG_P (operand1))
1567 if (REG_POINTER (operand1)
1568 && !REG_POINTER (operand0)
1569 && !HARD_REGISTER_P (operand0))
1570 copy_reg_pointer (operand0, operand1);
1571 else if (REG_POINTER (operand0)
1572 && !REG_POINTER (operand1)
1573 && !HARD_REGISTER_P (operand1))
1574 copy_reg_pointer (operand1, operand0);
1577 /* When MEMs are broken out, the REG_POINTER flag doesn't
1578 get set. In some cases, we can set the REG_POINTER flag
1579 from the declaration for the MEM. */
1580 if (REG_P (operand0)
1581 && GET_CODE (operand1) == MEM
1582 && !REG_POINTER (operand0))
1584 tree decl = MEM_EXPR (operand1);
1586 /* Set the register pointer flag and register alignment
1587 if the declaration for this memory reference is a
1588 pointer type. Fortran indirect argument references
1591 && !(flag_argument_noalias > 1
1592 && TREE_CODE (decl) == INDIRECT_REF
1593 && TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL))
1597 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1599 if (TREE_CODE (decl) == COMPONENT_REF)
1600 decl = TREE_OPERAND (decl, 1);
1602 type = TREE_TYPE (decl);
1603 if (TREE_CODE (type) == ARRAY_TYPE)
1604 type = get_inner_array_type (type);
1606 if (POINTER_TYPE_P (type))
1610 type = TREE_TYPE (type);
1611 /* Using TYPE_ALIGN_OK is rather conservative as
1612 only the ada frontend actually sets it. */
1613 align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1615 mark_reg_pointer (operand0, align);
1620 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1624 else if (GET_CODE (operand0) == MEM)
1626 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1627 && !(reload_in_progress || reload_completed))
1629 rtx temp = gen_reg_rtx (DFmode);
1631 emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1632 emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1635 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1637 /* Run this case quickly. */
1638 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1641 if (! (reload_in_progress || reload_completed))
1643 operands[0] = validize_mem (operand0);
1644 operands[1] = operand1 = force_reg (mode, operand1);
1648 /* Simplify the source if we need to.
1649 Note we do have to handle function labels here, even though we do
1650 not consider them legitimate constants. Loop optimizations can
1651 call the emit_move_xxx with one as a source. */
1652 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1653 || function_label_operand (operand1, mode)
1654 || (GET_CODE (operand1) == HIGH
1655 && symbolic_operand (XEXP (operand1, 0), mode)))
1659 if (GET_CODE (operand1) == HIGH)
1662 operand1 = XEXP (operand1, 0);
1664 if (symbolic_operand (operand1, mode))
1666 /* Argh. The assembler and linker can't handle arithmetic
1669 So we force the plabel into memory, load operand0 from
1670 the memory location, then add in the constant part. */
1671 if ((GET_CODE (operand1) == CONST
1672 && GET_CODE (XEXP (operand1, 0)) == PLUS
1673 && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
1674 || function_label_operand (operand1, mode))
1676 rtx temp, const_part;
1678 /* Figure out what (if any) scratch register to use. */
1679 if (reload_in_progress || reload_completed)
1681 scratch_reg = scratch_reg ? scratch_reg : operand0;
1682 /* SCRATCH_REG will hold an address and maybe the actual
1683 data. We want it in WORD_MODE regardless of what mode it
1684 was originally given to us. */
1685 scratch_reg = force_mode (word_mode, scratch_reg);
1688 scratch_reg = gen_reg_rtx (Pmode);
1690 if (GET_CODE (operand1) == CONST)
1692 /* Save away the constant part of the expression. */
1693 const_part = XEXP (XEXP (operand1, 0), 1);
1694 gcc_assert (GET_CODE (const_part) == CONST_INT);
1696 /* Force the function label into memory. */
1697 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
1701 /* No constant part. */
1702 const_part = NULL_RTX;
1704 /* Force the function label into memory. */
1705 temp = force_const_mem (mode, operand1);
1709 /* Get the address of the memory location. PIC-ify it if
1711 temp = XEXP (temp, 0);
1713 temp = legitimize_pic_address (temp, mode, scratch_reg);
1715 /* Put the address of the memory location into our destination
1718 emit_move_sequence (operands, mode, scratch_reg);
1720 /* Now load from the memory location into our destination
1722 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
1723 emit_move_sequence (operands, mode, scratch_reg);
1725 /* And add back in the constant part. */
1726 if (const_part != NULL_RTX)
1727 expand_inc (operand0, const_part);
1736 if (reload_in_progress || reload_completed)
1738 temp = scratch_reg ? scratch_reg : operand0;
1739 /* TEMP will hold an address and maybe the actual
1740 data. We want it in WORD_MODE regardless of what mode it
1741 was originally given to us. */
1742 temp = force_mode (word_mode, temp);
1745 temp = gen_reg_rtx (Pmode);
1747 /* (const (plus (symbol) (const_int))) must be forced to
1748 memory during/after reload if the const_int will not fit
1750 if (GET_CODE (operand1) == CONST
1751 && GET_CODE (XEXP (operand1, 0)) == PLUS
1752 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
1753 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
1754 && (reload_completed || reload_in_progress)
1757 operands[1] = force_const_mem (mode, operand1);
1758 operands[1] = legitimize_pic_address (XEXP (operands[1], 0),
1760 operands[1] = gen_rtx_MEM (mode, operands[1]);
1761 emit_move_sequence (operands, mode, temp);
1765 operands[1] = legitimize_pic_address (operand1, mode, temp);
1766 if (REG_P (operand0) && REG_P (operands[1]))
1767 copy_reg_pointer (operand0, operands[1]);
1768 emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
1771 /* On the HPPA, references to data space are supposed to use dp,
1772 register 27, but showing it in the RTL inhibits various cse
1773 and loop optimizations. */
1778 if (reload_in_progress || reload_completed)
1780 temp = scratch_reg ? scratch_reg : operand0;
1781 /* TEMP will hold an address and maybe the actual
1782 data. We want it in WORD_MODE regardless of what mode it
1783 was originally given to us. */
1784 temp = force_mode (word_mode, temp);
1787 temp = gen_reg_rtx (mode);
1789 /* Loading a SYMBOL_REF into a register makes that register
1790 safe to be used as the base in an indexed address.
1792 Don't mark hard registers though. That loses. */
1793 if (GET_CODE (operand0) == REG
1794 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1795 mark_reg_pointer (operand0, BITS_PER_UNIT);
1796 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
1797 mark_reg_pointer (temp, BITS_PER_UNIT);
1800 set = gen_rtx_SET (mode, operand0, temp);
1802 set = gen_rtx_SET (VOIDmode,
1804 gen_rtx_LO_SUM (mode, temp, operand1));
1806 emit_insn (gen_rtx_SET (VOIDmode,
1808 gen_rtx_HIGH (mode, operand1)));
1814 else if (pa_tls_referenced_p (operand1))
1819 if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
1821 addend = XEXP (XEXP (tmp, 0), 1);
1822 tmp = XEXP (XEXP (tmp, 0), 0);
1825 gcc_assert (GET_CODE (tmp) == SYMBOL_REF);
1826 tmp = legitimize_tls_address (tmp);
1829 tmp = gen_rtx_PLUS (mode, tmp, addend);
1830 tmp = force_operand (tmp, operands[0]);
1834 else if (GET_CODE (operand1) != CONST_INT
1835 || !cint_ok_for_move (INTVAL (operand1)))
1839 HOST_WIDE_INT value = 0;
1840 HOST_WIDE_INT insv = 0;
1843 if (GET_CODE (operand1) == CONST_INT)
1844 value = INTVAL (operand1);
1847 && GET_CODE (operand1) == CONST_INT
1848 && HOST_BITS_PER_WIDE_INT > 32
1849 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
1853 /* Extract the low order 32 bits of the value and sign extend.
1854 If the new value is the same as the original value, we can
1855 can use the original value as-is. If the new value is
1856 different, we use it and insert the most-significant 32-bits
1857 of the original value into the final result. */
1858 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
1859 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
1862 #if HOST_BITS_PER_WIDE_INT > 32
1863 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
1867 operand1 = GEN_INT (nval);
1871 if (reload_in_progress || reload_completed)
1872 temp = scratch_reg ? scratch_reg : operand0;
1874 temp = gen_reg_rtx (mode);
1876 /* We don't directly split DImode constants on 32-bit targets
1877 because PLUS uses an 11-bit immediate and the insn sequence
1878 generated is not as efficient as the one using HIGH/LO_SUM. */
1879 if (GET_CODE (operand1) == CONST_INT
1880 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1883 /* Directly break constant into high and low parts. This
1884 provides better optimization opportunities because various
1885 passes recognize constants split with PLUS but not LO_SUM.
1886 We use a 14-bit signed low part except when the addition
1887 of 0x4000 to the high part might change the sign of the
1889 HOST_WIDE_INT low = value & 0x3fff;
1890 HOST_WIDE_INT high = value & ~ 0x3fff;
1894 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
1902 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
1903 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
1907 emit_insn (gen_rtx_SET (VOIDmode, temp,
1908 gen_rtx_HIGH (mode, operand1)));
1909 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
1912 insn = emit_move_insn (operands[0], operands[1]);
1914 /* Now insert the most significant 32 bits of the value
1915 into the register. When we don't have a second register
1916 available, it could take up to nine instructions to load
1917 a 64-bit integer constant. Prior to reload, we force
1918 constants that would take more than three instructions
1919 to load to the constant pool. During and after reload,
1920 we have to handle all possible values. */
1923 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
1924 register and the value to be inserted is outside the
1925 range that can be loaded with three depdi instructions. */
1926 if (temp != operand0 && (insv >= 16384 || insv < -16384))
1928 operand1 = GEN_INT (insv);
1930 emit_insn (gen_rtx_SET (VOIDmode, temp,
1931 gen_rtx_HIGH (mode, operand1)));
1932 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
1933 emit_insn (gen_insv (operand0, GEN_INT (32),
1938 int len = 5, pos = 27;
1940 /* Insert the bits using the depdi instruction. */
1943 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
1944 HOST_WIDE_INT sign = v5 < 0;
1946 /* Left extend the insertion. */
1947 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
1948 while (pos > 0 && (insv & 1) == sign)
1950 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
1955 emit_insn (gen_insv (operand0, GEN_INT (len),
1956 GEN_INT (pos), GEN_INT (v5)));
1958 len = pos > 0 && pos < 5 ? pos : 5;
1965 = gen_rtx_EXPR_LIST (REG_EQUAL, op1, REG_NOTES (insn));
1970 /* Now have insn-emit do whatever it normally does. */
1974 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
1975 it will need a link/runtime reloc). */
1978 reloc_needed (tree exp)
1982 switch (TREE_CODE (exp))
1989 reloc = reloc_needed (TREE_OPERAND (exp, 0));
1990 reloc |= reloc_needed (TREE_OPERAND (exp, 1));
1995 case NON_LVALUE_EXPR:
1996 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2002 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2003 if (TREE_VALUE (link) != 0)
2004 reloc |= reloc_needed (TREE_VALUE (link));
2017 /* Does operand (which is a symbolic_operand) live in text space?
2018 If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2022 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2024 if (GET_CODE (operand) == CONST)
2025 operand = XEXP (XEXP (operand, 0), 0);
2028 if (GET_CODE (operand) == SYMBOL_REF)
2029 return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2033 if (GET_CODE (operand) == SYMBOL_REF)
2034 return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2040 /* Return the best assembler insn template
2041 for moving operands[1] into operands[0] as a fullword. */
2043 singlemove_string (rtx *operands)
2045 HOST_WIDE_INT intval;
2047 if (GET_CODE (operands[0]) == MEM)
2048 return "stw %r1,%0";
2049 if (GET_CODE (operands[1]) == MEM)
2051 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2056 gcc_assert (GET_MODE (operands[1]) == SFmode);
2058 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2060 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2061 REAL_VALUE_TO_TARGET_SINGLE (d, i);
2063 operands[1] = GEN_INT (i);
2064 /* Fall through to CONST_INT case. */
2066 if (GET_CODE (operands[1]) == CONST_INT)
2068 intval = INTVAL (operands[1]);
2070 if (VAL_14_BITS_P (intval))
2072 else if ((intval & 0x7ff) == 0)
2073 return "ldil L'%1,%0";
2074 else if (zdepi_cint_p (intval))
2075 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2077 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2079 return "copy %1,%0";
2083 /* Compute position (in OP[1]) and width (in OP[2])
2084 useful for copying IMM to a register using the zdepi
2085 instructions. Store the immediate value to insert in OP[0]. */
2087 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2091 /* Find the least significant set bit in IMM. */
2092 for (lsb = 0; lsb < 32; lsb++)
2099 /* Choose variants based on *sign* of the 5-bit field. */
2100 if ((imm & 0x10) == 0)
2101 len = (lsb <= 28) ? 4 : 32 - lsb;
2104 /* Find the width of the bitstring in IMM. */
2105 for (len = 5; len < 32; len++)
2107 if ((imm & (1 << len)) == 0)
2111 /* Sign extend IMM as a 5-bit value. */
2112 imm = (imm & 0xf) - 0x10;
2120 /* Compute position (in OP[1]) and width (in OP[2])
2121 useful for copying IMM to a register using the depdi,z
2122 instructions. Store the immediate value to insert in OP[0]. */
2124 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2126 HOST_WIDE_INT lsb, len;
2128 /* Find the least significant set bit in IMM. */
2129 for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
2136 /* Choose variants based on *sign* of the 5-bit field. */
2137 if ((imm & 0x10) == 0)
2138 len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
2139 ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
2142 /* Find the width of the bitstring in IMM. */
2143 for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
2145 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2149 /* Sign extend IMM as a 5-bit value. */
2150 imm = (imm & 0xf) - 0x10;
2158 /* Output assembler code to perform a doubleword move insn
2159 with operands OPERANDS. */
2162 output_move_double (rtx *operands)
2164 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2166 rtx addreg0 = 0, addreg1 = 0;
2168 /* First classify both operands. */
2170 if (REG_P (operands[0]))
2172 else if (offsettable_memref_p (operands[0]))
2174 else if (GET_CODE (operands[0]) == MEM)
2179 if (REG_P (operands[1]))
2181 else if (CONSTANT_P (operands[1]))
2183 else if (offsettable_memref_p (operands[1]))
2185 else if (GET_CODE (operands[1]) == MEM)
2190 /* Check for the cases that the operand constraints are not
2191 supposed to allow to happen. */
2192 gcc_assert (optype0 == REGOP || optype1 == REGOP);
2194 /* Handle auto decrementing and incrementing loads and stores
2195 specifically, since the structure of the function doesn't work
2196 for them without major modification. Do it better when we learn
2197 this port about the general inc/dec addressing of PA.
2198 (This was written by tege. Chide him if it doesn't work.) */
2200 if (optype0 == MEMOP)
2202 /* We have to output the address syntax ourselves, since print_operand
2203 doesn't deal with the addresses we want to use. Fix this later. */
2205 rtx addr = XEXP (operands[0], 0);
2206 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2208 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2210 operands[0] = XEXP (addr, 0);
2211 gcc_assert (GET_CODE (operands[1]) == REG
2212 && GET_CODE (operands[0]) == REG);
2214 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2216 /* No overlap between high target register and address
2217 register. (We do this in a non-obvious way to
2218 save a register file writeback) */
2219 if (GET_CODE (addr) == POST_INC)
2220 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2221 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2223 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2225 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2227 operands[0] = XEXP (addr, 0);
2228 gcc_assert (GET_CODE (operands[1]) == REG
2229 && GET_CODE (operands[0]) == REG);
2231 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2232 /* No overlap between high target register and address
2233 register. (We do this in a non-obvious way to save a
2234 register file writeback) */
2235 if (GET_CODE (addr) == PRE_INC)
2236 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2237 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2240 if (optype1 == MEMOP)
2242 /* We have to output the address syntax ourselves, since print_operand
2243 doesn't deal with the addresses we want to use. Fix this later. */
2245 rtx addr = XEXP (operands[1], 0);
2246 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2248 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2250 operands[1] = XEXP (addr, 0);
2251 gcc_assert (GET_CODE (operands[0]) == REG
2252 && GET_CODE (operands[1]) == REG);
2254 if (!reg_overlap_mentioned_p (high_reg, addr))
2256 /* No overlap between high target register and address
2257 register. (We do this in a non-obvious way to
2258 save a register file writeback) */
2259 if (GET_CODE (addr) == POST_INC)
2260 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2261 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2265 /* This is an undefined situation. We should load into the
2266 address register *and* update that register. Probably
2267 we don't need to handle this at all. */
2268 if (GET_CODE (addr) == POST_INC)
2269 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2270 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2273 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2275 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2277 operands[1] = XEXP (addr, 0);
2278 gcc_assert (GET_CODE (operands[0]) == REG
2279 && GET_CODE (operands[1]) == REG);
2281 if (!reg_overlap_mentioned_p (high_reg, addr))
2283 /* No overlap between high target register and address
2284 register. (We do this in a non-obvious way to
2285 save a register file writeback) */
2286 if (GET_CODE (addr) == PRE_INC)
2287 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2288 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2292 /* This is an undefined situation. We should load into the
2293 address register *and* update that register. Probably
2294 we don't need to handle this at all. */
2295 if (GET_CODE (addr) == PRE_INC)
2296 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2297 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2300 else if (GET_CODE (addr) == PLUS
2301 && GET_CODE (XEXP (addr, 0)) == MULT)
2303 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2305 if (!reg_overlap_mentioned_p (high_reg, addr))
2309 xoperands[0] = high_reg;
2310 xoperands[1] = XEXP (addr, 1);
2311 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2312 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2313 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2315 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2321 xoperands[0] = high_reg;
2322 xoperands[1] = XEXP (addr, 1);
2323 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2324 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2325 output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2327 return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2332 /* If an operand is an unoffsettable memory ref, find a register
2333 we can increment temporarily to make it refer to the second word. */
2335 if (optype0 == MEMOP)
2336 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2338 if (optype1 == MEMOP)
2339 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2341 /* Ok, we can do one word at a time.
2342 Normally we do the low-numbered word first.
2344 In either case, set up in LATEHALF the operands to use
2345 for the high-numbered word and in some cases alter the
2346 operands in OPERANDS to be suitable for the low-numbered word. */
2348 if (optype0 == REGOP)
2349 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2350 else if (optype0 == OFFSOP)
2351 latehalf[0] = adjust_address (operands[0], SImode, 4);
2353 latehalf[0] = operands[0];
2355 if (optype1 == REGOP)
2356 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2357 else if (optype1 == OFFSOP)
2358 latehalf[1] = adjust_address (operands[1], SImode, 4);
2359 else if (optype1 == CNSTOP)
2360 split_double (operands[1], &operands[1], &latehalf[1]);
2362 latehalf[1] = operands[1];
2364 /* If the first move would clobber the source of the second one,
2365 do them in the other order.
2367 This can happen in two cases:
2369 mem -> register where the first half of the destination register
2370 is the same register used in the memory's address. Reload
2371 can create such insns.
2373 mem in this case will be either register indirect or register
2374 indirect plus a valid offset.
2376 register -> register move where REGNO(dst) == REGNO(src + 1)
2377 someone (Tim/Tege?) claimed this can happen for parameter loads.
2379 Handle mem -> register case first. */
2380 if (optype0 == REGOP
2381 && (optype1 == MEMOP || optype1 == OFFSOP)
2382 && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2385 /* Do the late half first. */
2387 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2388 output_asm_insn (singlemove_string (latehalf), latehalf);
2392 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2393 return singlemove_string (operands);
2396 /* Now handle register -> register case. */
2397 if (optype0 == REGOP && optype1 == REGOP
2398 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2400 output_asm_insn (singlemove_string (latehalf), latehalf);
2401 return singlemove_string (operands);
2404 /* Normal case: do the two words, low-numbered first. */
2406 output_asm_insn (singlemove_string (operands), operands);
2408 /* Make any unoffsettable addresses point at high-numbered word. */
2410 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2412 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2415 output_asm_insn (singlemove_string (latehalf), latehalf);
2417 /* Undo the adds we just did. */
2419 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2421 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2427 output_fp_move_double (rtx *operands)
2429 if (FP_REG_P (operands[0]))
2431 if (FP_REG_P (operands[1])
2432 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2433 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2435 output_asm_insn ("fldd%F1 %1,%0", operands);
2437 else if (FP_REG_P (operands[1]))
2439 output_asm_insn ("fstd%F0 %1,%0", operands);
2445 gcc_assert (operands[1] == CONST0_RTX (GET_MODE (operands[0])));
2447 /* This is a pain. You have to be prepared to deal with an
2448 arbitrary address here including pre/post increment/decrement.
2450 so avoid this in the MD. */
2451 gcc_assert (GET_CODE (operands[0]) == REG);
2453 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2454 xoperands[0] = operands[0];
2455 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2460 /* Return a REG that occurs in ADDR with coefficient 1.
2461 ADDR can be effectively incremented by incrementing REG. */
2464 find_addr_reg (rtx addr)
2466 while (GET_CODE (addr) == PLUS)
2468 if (GET_CODE (XEXP (addr, 0)) == REG)
2469 addr = XEXP (addr, 0);
2470 else if (GET_CODE (XEXP (addr, 1)) == REG)
2471 addr = XEXP (addr, 1);
2472 else if (CONSTANT_P (XEXP (addr, 0)))
2473 addr = XEXP (addr, 1);
2474 else if (CONSTANT_P (XEXP (addr, 1)))
2475 addr = XEXP (addr, 0);
2479 gcc_assert (GET_CODE (addr) == REG);
2483 /* Emit code to perform a block move.
2485 OPERANDS[0] is the destination pointer as a REG, clobbered.
2486 OPERANDS[1] is the source pointer as a REG, clobbered.
2487 OPERANDS[2] is a register for temporary storage.
2488 OPERANDS[3] is a register for temporary storage.
2489 OPERANDS[4] is the size as a CONST_INT
2490 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2491 OPERANDS[6] is another temporary register. */
2494 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2496 int align = INTVAL (operands[5]);
2497 unsigned long n_bytes = INTVAL (operands[4]);
2499 /* We can't move more than a word at a time because the PA
2500 has no longer integer move insns. (Could use fp mem ops?) */
2501 if (align > (TARGET_64BIT ? 8 : 4))
2502 align = (TARGET_64BIT ? 8 : 4);
2504 /* Note that we know each loop below will execute at least twice
2505 (else we would have open-coded the copy). */
2509 /* Pre-adjust the loop counter. */
2510 operands[4] = GEN_INT (n_bytes - 16);
2511 output_asm_insn ("ldi %4,%2", operands);
2514 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2515 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2516 output_asm_insn ("std,ma %3,8(%0)", operands);
2517 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2518 output_asm_insn ("std,ma %6,8(%0)", operands);
2520 /* Handle the residual. There could be up to 7 bytes of
2521 residual to copy! */
2522 if (n_bytes % 16 != 0)
2524 operands[4] = GEN_INT (n_bytes % 8);
2525 if (n_bytes % 16 >= 8)
2526 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2527 if (n_bytes % 8 != 0)
2528 output_asm_insn ("ldd 0(%1),%6", operands);
2529 if (n_bytes % 16 >= 8)
2530 output_asm_insn ("std,ma %3,8(%0)", operands);
2531 if (n_bytes % 8 != 0)
2532 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2537 /* Pre-adjust the loop counter. */
2538 operands[4] = GEN_INT (n_bytes - 8);
2539 output_asm_insn ("ldi %4,%2", operands);
2542 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2543 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2544 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2545 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2546 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2548 /* Handle the residual. There could be up to 7 bytes of
2549 residual to copy! */
2550 if (n_bytes % 8 != 0)
2552 operands[4] = GEN_INT (n_bytes % 4);
2553 if (n_bytes % 8 >= 4)
2554 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2555 if (n_bytes % 4 != 0)
2556 output_asm_insn ("ldw 0(%1),%6", operands);
2557 if (n_bytes % 8 >= 4)
2558 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2559 if (n_bytes % 4 != 0)
2560 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2565 /* Pre-adjust the loop counter. */
2566 operands[4] = GEN_INT (n_bytes - 4);
2567 output_asm_insn ("ldi %4,%2", operands);
2570 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2571 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2572 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2573 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2574 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2576 /* Handle the residual. */
2577 if (n_bytes % 4 != 0)
2579 if (n_bytes % 4 >= 2)
2580 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2581 if (n_bytes % 2 != 0)
2582 output_asm_insn ("ldb 0(%1),%6", operands);
2583 if (n_bytes % 4 >= 2)
2584 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2585 if (n_bytes % 2 != 0)
2586 output_asm_insn ("stb %6,0(%0)", operands);
2591 /* Pre-adjust the loop counter. */
2592 operands[4] = GEN_INT (n_bytes - 2);
2593 output_asm_insn ("ldi %4,%2", operands);
2596 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2597 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2598 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2599 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2600 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2602 /* Handle the residual. */
2603 if (n_bytes % 2 != 0)
2605 output_asm_insn ("ldb 0(%1),%3", operands);
2606 output_asm_insn ("stb %3,0(%0)", operands);
2615 /* Count the number of insns necessary to handle this block move.
2617 Basic structure is the same as emit_block_move, except that we
2618 count insns rather than emit them. */
2621 compute_movmem_length (rtx insn)
2623 rtx pat = PATTERN (insn);
2624 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2625 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2626 unsigned int n_insns = 0;
2628 /* We can't move more than four bytes at a time because the PA
2629 has no longer integer move insns. (Could use fp mem ops?) */
2630 if (align > (TARGET_64BIT ? 8 : 4))
2631 align = (TARGET_64BIT ? 8 : 4);
2633 /* The basic copying loop. */
2637 if (n_bytes % (2 * align) != 0)
2639 if ((n_bytes % (2 * align)) >= align)
2642 if ((n_bytes % align) != 0)
2646 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2650 /* Emit code to perform a block clear.
2652 OPERANDS[0] is the destination pointer as a REG, clobbered.
2653 OPERANDS[1] is a register for temporary storage.
2654 OPERANDS[2] is the size as a CONST_INT
2655 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
2658 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2660 int align = INTVAL (operands[3]);
2661 unsigned long n_bytes = INTVAL (operands[2]);
2663 /* We can't clear more than a word at a time because the PA
2664 has no longer integer move insns. */
2665 if (align > (TARGET_64BIT ? 8 : 4))
2666 align = (TARGET_64BIT ? 8 : 4);
2668 /* Note that we know each loop below will execute at least twice
2669 (else we would have open-coded the copy). */
2673 /* Pre-adjust the loop counter. */
2674 operands[2] = GEN_INT (n_bytes - 16);
2675 output_asm_insn ("ldi %2,%1", operands);
2678 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2679 output_asm_insn ("addib,>= -16,%1,.-4", operands);
2680 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2682 /* Handle the residual. There could be up to 7 bytes of
2683 residual to copy! */
2684 if (n_bytes % 16 != 0)
2686 operands[2] = GEN_INT (n_bytes % 8);
2687 if (n_bytes % 16 >= 8)
2688 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2689 if (n_bytes % 8 != 0)
2690 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
2695 /* Pre-adjust the loop counter. */
2696 operands[2] = GEN_INT (n_bytes - 8);
2697 output_asm_insn ("ldi %2,%1", operands);
2700 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2701 output_asm_insn ("addib,>= -8,%1,.-4", operands);
2702 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2704 /* Handle the residual. There could be up to 7 bytes of
2705 residual to copy! */
2706 if (n_bytes % 8 != 0)
2708 operands[2] = GEN_INT (n_bytes % 4);
2709 if (n_bytes % 8 >= 4)
2710 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2711 if (n_bytes % 4 != 0)
2712 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
2717 /* Pre-adjust the loop counter. */
2718 operands[2] = GEN_INT (n_bytes - 4);
2719 output_asm_insn ("ldi %2,%1", operands);
2722 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2723 output_asm_insn ("addib,>= -4,%1,.-4", operands);
2724 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2726 /* Handle the residual. */
2727 if (n_bytes % 4 != 0)
2729 if (n_bytes % 4 >= 2)
2730 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2731 if (n_bytes % 2 != 0)
2732 output_asm_insn ("stb %%r0,0(%0)", operands);
2737 /* Pre-adjust the loop counter. */
2738 operands[2] = GEN_INT (n_bytes - 2);
2739 output_asm_insn ("ldi %2,%1", operands);
2742 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2743 output_asm_insn ("addib,>= -2,%1,.-4", operands);
2744 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2746 /* Handle the residual. */
2747 if (n_bytes % 2 != 0)
2748 output_asm_insn ("stb %%r0,0(%0)", operands);
2757 /* Count the number of insns necessary to handle this block move.
2759 Basic structure is the same as emit_block_move, except that we
2760 count insns rather than emit them. */
2763 compute_clrmem_length (rtx insn)
2765 rtx pat = PATTERN (insn);
2766 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
2767 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
2768 unsigned int n_insns = 0;
2770 /* We can't clear more than a word at a time because the PA
2771 has no longer integer move insns. */
2772 if (align > (TARGET_64BIT ? 8 : 4))
2773 align = (TARGET_64BIT ? 8 : 4);
2775 /* The basic loop. */
2779 if (n_bytes % (2 * align) != 0)
2781 if ((n_bytes % (2 * align)) >= align)
2784 if ((n_bytes % align) != 0)
2788 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2794 output_and (rtx *operands)
2796 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2798 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2799 int ls0, ls1, ms0, p, len;
2801 for (ls0 = 0; ls0 < 32; ls0++)
2802 if ((mask & (1 << ls0)) == 0)
2805 for (ls1 = ls0; ls1 < 32; ls1++)
2806 if ((mask & (1 << ls1)) != 0)
2809 for (ms0 = ls1; ms0 < 32; ms0++)
2810 if ((mask & (1 << ms0)) == 0)
2813 gcc_assert (ms0 == 32);
2821 operands[2] = GEN_INT (len);
2822 return "{extru|extrw,u} %1,31,%2,%0";
2826 /* We could use this `depi' for the case above as well, but `depi'
2827 requires one more register file access than an `extru'. */
2832 operands[2] = GEN_INT (p);
2833 operands[3] = GEN_INT (len);
2834 return "{depi|depwi} 0,%2,%3,%0";
2838 return "and %1,%2,%0";
2841 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
2842 storing the result in operands[0]. */
2844 output_64bit_and (rtx *operands)
2846 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
2848 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2849 int ls0, ls1, ms0, p, len;
2851 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
2852 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
2855 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
2856 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
2859 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
2860 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
2863 gcc_assert (ms0 == HOST_BITS_PER_WIDE_INT);
2865 if (ls1 == HOST_BITS_PER_WIDE_INT)
2871 operands[2] = GEN_INT (len);
2872 return "extrd,u %1,63,%2,%0";
2876 /* We could use this `depi' for the case above as well, but `depi'
2877 requires one more register file access than an `extru'. */
2882 operands[2] = GEN_INT (p);
2883 operands[3] = GEN_INT (len);
2884 return "depdi 0,%2,%3,%0";
2888 return "and %1,%2,%0";
2892 output_ior (rtx *operands)
2894 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2895 int bs0, bs1, p, len;
2897 if (INTVAL (operands[2]) == 0)
2898 return "copy %1,%0";
2900 for (bs0 = 0; bs0 < 32; bs0++)
2901 if ((mask & (1 << bs0)) != 0)
2904 for (bs1 = bs0; bs1 < 32; bs1++)
2905 if ((mask & (1 << bs1)) == 0)
2908 gcc_assert (bs1 == 32 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
2913 operands[2] = GEN_INT (p);
2914 operands[3] = GEN_INT (len);
2915 return "{depi|depwi} -1,%2,%3,%0";
2918 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
2919 storing the result in operands[0]. */
2921 output_64bit_ior (rtx *operands)
2923 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
2924 int bs0, bs1, p, len;
2926 if (INTVAL (operands[2]) == 0)
2927 return "copy %1,%0";
2929 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
2930 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
2933 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
2934 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
2937 gcc_assert (bs1 == HOST_BITS_PER_WIDE_INT
2938 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
2943 operands[2] = GEN_INT (p);
2944 operands[3] = GEN_INT (len);
2945 return "depdi -1,%2,%3,%0";
2948 /* Target hook for assembling integer objects. This code handles
2949 aligned SI and DI integers specially since function references
2950 must be preceded by P%. */
2953 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
2955 if (size == UNITS_PER_WORD
2957 && function_label_operand (x, VOIDmode))
2959 fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
2960 output_addr_const (asm_out_file, x);
2961 fputc ('\n', asm_out_file);
2964 return default_assemble_integer (x, size, aligned_p);
2967 /* Output an ascii string. */
2969 output_ascii (FILE *file, const char *p, int size)
2973 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
2975 /* The HP assembler can only take strings of 256 characters at one
2976 time. This is a limitation on input line length, *not* the
2977 length of the string. Sigh. Even worse, it seems that the
2978 restriction is in number of input characters (see \xnn &
2979 \whatever). So we have to do this very carefully. */
2981 fputs ("\t.STRING \"", file);
2984 for (i = 0; i < size; i += 4)
2988 for (io = 0, co = 0; io < MIN (4, size - i); io++)
2990 register unsigned int c = (unsigned char) p[i + io];
2992 if (c == '\"' || c == '\\')
2993 partial_output[co++] = '\\';
2994 if (c >= ' ' && c < 0177)
2995 partial_output[co++] = c;
2999 partial_output[co++] = '\\';
3000 partial_output[co++] = 'x';
3001 hexd = c / 16 - 0 + '0';
3003 hexd -= '9' - 'a' + 1;
3004 partial_output[co++] = hexd;
3005 hexd = c % 16 - 0 + '0';
3007 hexd -= '9' - 'a' + 1;
3008 partial_output[co++] = hexd;
3011 if (chars_output + co > 243)
3013 fputs ("\"\n\t.STRING \"", file);
3016 fwrite (partial_output, 1, (size_t) co, file);
3020 fputs ("\"\n", file);
3023 /* Try to rewrite floating point comparisons & branches to avoid
3024 useless add,tr insns.
3026 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3027 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3028 first attempt to remove useless add,tr insns. It is zero
3029 for the second pass as reorg sometimes leaves bogus REG_DEAD
3032 When CHECK_NOTES is zero we can only eliminate add,tr insns
3033 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3036 remove_useless_addtr_insns (int check_notes)
3039 static int pass = 0;
3041 /* This is fairly cheap, so always run it when optimizing. */
3045 int fbranch_count = 0;
3047 /* Walk all the insns in this function looking for fcmp & fbranch
3048 instructions. Keep track of how many of each we find. */
3049 for (insn = get_insns (); insn; insn = next_insn (insn))
3053 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3054 if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3057 tmp = PATTERN (insn);
3059 /* It must be a set. */
3060 if (GET_CODE (tmp) != SET)
3063 /* If the destination is CCFP, then we've found an fcmp insn. */
3064 tmp = SET_DEST (tmp);
3065 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3071 tmp = PATTERN (insn);
3072 /* If this is an fbranch instruction, bump the fbranch counter. */
3073 if (GET_CODE (tmp) == SET
3074 && SET_DEST (tmp) == pc_rtx
3075 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3076 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3077 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3078 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3086 /* Find all floating point compare + branch insns. If possible,
3087 reverse the comparison & the branch to avoid add,tr insns. */
3088 for (insn = get_insns (); insn; insn = next_insn (insn))
3092 /* Ignore anything that isn't an INSN. */
3093 if (GET_CODE (insn) != INSN)
3096 tmp = PATTERN (insn);
3098 /* It must be a set. */
3099 if (GET_CODE (tmp) != SET)
3102 /* The destination must be CCFP, which is register zero. */
3103 tmp = SET_DEST (tmp);
3104 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3107 /* INSN should be a set of CCFP.
3109 See if the result of this insn is used in a reversed FP
3110 conditional branch. If so, reverse our condition and
3111 the branch. Doing so avoids useless add,tr insns. */
3112 next = next_insn (insn);
3115 /* Jumps, calls and labels stop our search. */
3116 if (GET_CODE (next) == JUMP_INSN
3117 || GET_CODE (next) == CALL_INSN
3118 || GET_CODE (next) == CODE_LABEL)
3121 /* As does another fcmp insn. */
3122 if (GET_CODE (next) == INSN
3123 && GET_CODE (PATTERN (next)) == SET
3124 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3125 && REGNO (SET_DEST (PATTERN (next))) == 0)
3128 next = next_insn (next);
3131 /* Is NEXT_INSN a branch? */
3133 && GET_CODE (next) == JUMP_INSN)
3135 rtx pattern = PATTERN (next);
3137 /* If it a reversed fp conditional branch (e.g. uses add,tr)
3138 and CCFP dies, then reverse our conditional and the branch
3139 to avoid the add,tr. */
3140 if (GET_CODE (pattern) == SET
3141 && SET_DEST (pattern) == pc_rtx
3142 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3143 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3144 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3145 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3146 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3147 && (fcmp_count == fbranch_count
3149 && find_regno_note (next, REG_DEAD, 0))))
3151 /* Reverse the branch. */
3152 tmp = XEXP (SET_SRC (pattern), 1);
3153 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3154 XEXP (SET_SRC (pattern), 2) = tmp;
3155 INSN_CODE (next) = -1;
3157 /* Reverse our condition. */
3158 tmp = PATTERN (insn);
3159 PUT_CODE (XEXP (tmp, 1),
3160 (reverse_condition_maybe_unordered
3161 (GET_CODE (XEXP (tmp, 1)))));
3171 /* You may have trouble believing this, but this is the 32 bit HP-PA
3176 Variable arguments (optional; any number may be allocated)
3178 SP-(4*(N+9)) arg word N
3183 Fixed arguments (must be allocated; may remain unused)
3192 SP-32 External Data Pointer (DP)
3194 SP-24 External/stub RP (RP')
3198 SP-8 Calling Stub RP (RP'')
3203 SP-0 Stack Pointer (points to next available address)
3207 /* This function saves registers as follows. Registers marked with ' are
3208 this function's registers (as opposed to the previous function's).
3209 If a frame_pointer isn't needed, r4 is saved as a general register;
3210 the space for the frame pointer is still allocated, though, to keep
3216 SP (FP') Previous FP
3217 SP + 4 Alignment filler (sigh)
3218 SP + 8 Space for locals reserved here.
3222 SP + n All call saved register used.
3226 SP + o All call saved fp registers used.
3230 SP + p (SP') points to next available address.
3234 /* Global variables set by output_function_prologue(). */
3235 /* Size of frame. Need to know this to emit return insns from
3237 static HOST_WIDE_INT actual_fsize, local_fsize;
3238 static int save_fregs;
3240 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3241 Handle case where DISP > 8k by using the add_high_const patterns.
3243 Note in DISP > 8k case, we will leave the high part of the address
3244 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3247 store_reg (int reg, HOST_WIDE_INT disp, int base)
3249 rtx insn, dest, src, basereg;
3251 src = gen_rtx_REG (word_mode, reg);
3252 basereg = gen_rtx_REG (Pmode, base);
3253 if (VAL_14_BITS_P (disp))
3255 dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3256 insn = emit_move_insn (dest, src);
3258 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3260 rtx delta = GEN_INT (disp);
3261 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3263 emit_move_insn (tmpreg, delta);
3264 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3265 dest = gen_rtx_MEM (word_mode, tmpreg);
3266 insn = emit_move_insn (dest, src);
3270 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3271 gen_rtx_SET (VOIDmode,
3272 gen_rtx_MEM (word_mode,
3273 gen_rtx_PLUS (word_mode, basereg,
3281 rtx delta = GEN_INT (disp);
3282 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3283 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3285 emit_move_insn (tmpreg, high);
3286 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3287 insn = emit_move_insn (dest, src);
3291 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3292 gen_rtx_SET (VOIDmode,
3293 gen_rtx_MEM (word_mode,
3294 gen_rtx_PLUS (word_mode, basereg,
3302 RTX_FRAME_RELATED_P (insn) = 1;
3305 /* Emit RTL to store REG at the memory location specified by BASE and then
3306 add MOD to BASE. MOD must be <= 8k. */
3309 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3311 rtx insn, basereg, srcreg, delta;
3313 gcc_assert (VAL_14_BITS_P (mod));
3315 basereg = gen_rtx_REG (Pmode, base);
3316 srcreg = gen_rtx_REG (word_mode, reg);
3317 delta = GEN_INT (mod);
3319 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3322 RTX_FRAME_RELATED_P (insn) = 1;
3324 /* RTX_FRAME_RELATED_P must be set on each frame related set
3325 in a parallel with more than one element. Don't set
3326 RTX_FRAME_RELATED_P in the first set if reg is temporary
3327 register 1. The effect of this operation is recorded in
3328 the initial copy. */
3331 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3332 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3336 /* The first element of a PARALLEL is always processed if it is
3337 a SET. Thus, we need an expression list for this case. */
3339 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3340 gen_rtx_SET (VOIDmode, basereg,
3341 gen_rtx_PLUS (word_mode, basereg, delta)),
3347 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
3348 where DISP > 8k by using the add_high_const patterns. NOTE indicates
3349 whether to add a frame note or not.
3351 In the DISP > 8k case, we leave the high part of the address in %r1.
3352 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
3355 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3359 if (VAL_14_BITS_P (disp))
3361 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3362 plus_constant (gen_rtx_REG (Pmode, base), disp));
3364 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3366 rtx basereg = gen_rtx_REG (Pmode, base);
3367 rtx delta = GEN_INT (disp);
3368 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3370 emit_move_insn (tmpreg, delta);
3371 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3372 gen_rtx_PLUS (Pmode, tmpreg, basereg));
3376 rtx basereg = gen_rtx_REG (Pmode, base);
3377 rtx delta = GEN_INT (disp);
3378 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3380 emit_move_insn (tmpreg,
3381 gen_rtx_PLUS (Pmode, basereg,
3382 gen_rtx_HIGH (Pmode, delta)));
3383 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),