Turn FUNCTION_ARG_PADDING into a target hook
[official-gcc.git] / gcc / config / pa / pa.c
blob3ce8b3c141f2da9ed3d3a1513af381a8a1234168
1 /* Subroutines for insn-output.c for HPPA.
2 Copyright (C) 1992-2017 Free Software Foundation, Inc.
3 Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "memmodel.h"
25 #include "backend.h"
26 #include "target.h"
27 #include "rtl.h"
28 #include "tree.h"
29 #include "df.h"
30 #include "tm_p.h"
31 #include "stringpool.h"
32 #include "attribs.h"
33 #include "optabs.h"
34 #include "regs.h"
35 #include "emit-rtl.h"
36 #include "recog.h"
37 #include "diagnostic-core.h"
38 #include "insn-attr.h"
39 #include "alias.h"
40 #include "fold-const.h"
41 #include "stor-layout.h"
42 #include "varasm.h"
43 #include "calls.h"
44 #include "output.h"
45 #include "except.h"
46 #include "explow.h"
47 #include "expr.h"
48 #include "reload.h"
49 #include "common/common-target.h"
50 #include "langhooks.h"
51 #include "cfgrtl.h"
52 #include "opts.h"
53 #include "builtins.h"
55 /* This file should be included last. */
56 #include "target-def.h"
58 /* Return nonzero if there is a bypass for the output of
59 OUT_INSN and the fp store IN_INSN. */
60 int
61 pa_fpstore_bypass_p (rtx_insn *out_insn, rtx_insn *in_insn)
63 machine_mode store_mode;
64 machine_mode other_mode;
65 rtx set;
67 if (recog_memoized (in_insn) < 0
68 || (get_attr_type (in_insn) != TYPE_FPSTORE
69 && get_attr_type (in_insn) != TYPE_FPSTORE_LOAD)
70 || recog_memoized (out_insn) < 0)
71 return 0;
73 store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
75 set = single_set (out_insn);
76 if (!set)
77 return 0;
79 other_mode = GET_MODE (SET_SRC (set));
81 return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
85 #ifndef DO_FRAME_NOTES
86 #ifdef INCOMING_RETURN_ADDR_RTX
87 #define DO_FRAME_NOTES 1
88 #else
89 #define DO_FRAME_NOTES 0
90 #endif
91 #endif
93 static void pa_option_override (void);
94 static void copy_reg_pointer (rtx, rtx);
95 static void fix_range (const char *);
96 static int hppa_register_move_cost (machine_mode mode, reg_class_t,
97 reg_class_t);
98 static int hppa_address_cost (rtx, machine_mode mode, addr_space_t, bool);
99 static bool hppa_rtx_costs (rtx, machine_mode, int, int, int *, bool);
100 static inline rtx force_mode (machine_mode, rtx);
101 static void pa_reorg (void);
102 static void pa_combine_instructions (void);
103 static int pa_can_combine_p (rtx_insn *, rtx_insn *, rtx_insn *, int, rtx,
104 rtx, rtx);
105 static bool forward_branch_p (rtx_insn *);
106 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
107 static void compute_zdepdi_operands (unsigned HOST_WIDE_INT, unsigned *);
108 static int compute_movmem_length (rtx_insn *);
109 static int compute_clrmem_length (rtx_insn *);
110 static bool pa_assemble_integer (rtx, unsigned int, int);
111 static void remove_useless_addtr_insns (int);
112 static void store_reg (int, HOST_WIDE_INT, int);
113 static void store_reg_modify (int, int, HOST_WIDE_INT);
114 static void load_reg (int, HOST_WIDE_INT, int);
115 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
116 static rtx pa_function_value (const_tree, const_tree, bool);
117 static rtx pa_libcall_value (machine_mode, const_rtx);
118 static bool pa_function_value_regno_p (const unsigned int);
119 static void pa_output_function_prologue (FILE *);
120 static void update_total_code_bytes (unsigned int);
121 static void pa_output_function_epilogue (FILE *);
122 static int pa_adjust_cost (rtx_insn *, int, rtx_insn *, int, unsigned int);
123 static int pa_adjust_priority (rtx_insn *, int);
124 static int pa_issue_rate (void);
125 static int pa_reloc_rw_mask (void);
126 static void pa_som_asm_init_sections (void) ATTRIBUTE_UNUSED;
127 static section *pa_som_tm_clone_table_section (void) ATTRIBUTE_UNUSED;
128 static section *pa_select_section (tree, int, unsigned HOST_WIDE_INT)
129 ATTRIBUTE_UNUSED;
130 static void pa_encode_section_info (tree, rtx, int);
131 static const char *pa_strip_name_encoding (const char *);
132 static bool pa_function_ok_for_sibcall (tree, tree);
133 static void pa_globalize_label (FILE *, const char *)
134 ATTRIBUTE_UNUSED;
135 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
136 HOST_WIDE_INT, tree);
137 #if !defined(USE_COLLECT2)
138 static void pa_asm_out_constructor (rtx, int);
139 static void pa_asm_out_destructor (rtx, int);
140 #endif
141 static void pa_init_builtins (void);
142 static rtx pa_expand_builtin (tree, rtx, rtx, machine_mode mode, int);
143 static rtx hppa_builtin_saveregs (void);
144 static void hppa_va_start (tree, rtx);
145 static tree hppa_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
146 static bool pa_scalar_mode_supported_p (scalar_mode);
147 static bool pa_commutative_p (const_rtx x, int outer_code);
148 static void copy_fp_args (rtx_insn *) ATTRIBUTE_UNUSED;
149 static int length_fp_args (rtx_insn *) ATTRIBUTE_UNUSED;
150 static rtx hppa_legitimize_address (rtx, rtx, machine_mode);
151 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
152 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
153 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
154 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
155 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
156 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
157 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
158 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
159 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
160 static void output_deferred_plabels (void);
161 static void output_deferred_profile_counters (void) ATTRIBUTE_UNUSED;
162 #ifdef ASM_OUTPUT_EXTERNAL_REAL
163 static void pa_hpux_file_end (void);
164 #endif
165 static void pa_init_libfuncs (void);
166 static rtx pa_struct_value_rtx (tree, int);
167 static bool pa_pass_by_reference (cumulative_args_t, machine_mode,
168 const_tree, bool);
169 static int pa_arg_partial_bytes (cumulative_args_t, machine_mode,
170 tree, bool);
171 static void pa_function_arg_advance (cumulative_args_t, machine_mode,
172 const_tree, bool);
173 static rtx pa_function_arg (cumulative_args_t, machine_mode,
174 const_tree, bool);
175 static pad_direction pa_function_arg_padding (machine_mode, const_tree);
176 static unsigned int pa_function_arg_boundary (machine_mode, const_tree);
177 static struct machine_function * pa_init_machine_status (void);
178 static reg_class_t pa_secondary_reload (bool, rtx, reg_class_t,
179 machine_mode,
180 secondary_reload_info *);
181 static void pa_extra_live_on_entry (bitmap);
182 static machine_mode pa_promote_function_mode (const_tree,
183 machine_mode, int *,
184 const_tree, int);
186 static void pa_asm_trampoline_template (FILE *);
187 static void pa_trampoline_init (rtx, tree, rtx);
188 static rtx pa_trampoline_adjust_address (rtx);
189 static rtx pa_delegitimize_address (rtx);
190 static bool pa_print_operand_punct_valid_p (unsigned char);
191 static rtx pa_internal_arg_pointer (void);
192 static bool pa_can_eliminate (const int, const int);
193 static void pa_conditional_register_usage (void);
194 static machine_mode pa_c_mode_for_suffix (char);
195 static section *pa_function_section (tree, enum node_frequency, bool, bool);
196 static bool pa_cannot_force_const_mem (machine_mode, rtx);
197 static bool pa_legitimate_constant_p (machine_mode, rtx);
198 static unsigned int pa_section_type_flags (tree, const char *, int);
199 static bool pa_legitimate_address_p (machine_mode, rtx, bool);
200 static bool pa_callee_copies (cumulative_args_t, machine_mode,
201 const_tree, bool);
202 static bool pa_hard_regno_mode_ok (unsigned int, machine_mode);
203 static bool pa_modes_tieable_p (machine_mode, machine_mode);
205 /* The following extra sections are only used for SOM. */
206 static GTY(()) section *som_readonly_data_section;
207 static GTY(()) section *som_one_only_readonly_data_section;
208 static GTY(()) section *som_one_only_data_section;
209 static GTY(()) section *som_tm_clone_table_section;
211 /* Counts for the number of callee-saved general and floating point
212 registers which were saved by the current function's prologue. */
213 static int gr_saved, fr_saved;
215 /* Boolean indicating whether the return pointer was saved by the
216 current function's prologue. */
217 static bool rp_saved;
219 static rtx find_addr_reg (rtx);
221 /* Keep track of the number of bytes we have output in the CODE subspace
222 during this compilation so we'll know when to emit inline long-calls. */
223 unsigned long total_code_bytes;
225 /* The last address of the previous function plus the number of bytes in
226 associated thunks that have been output. This is used to determine if
227 a thunk can use an IA-relative branch to reach its target function. */
228 static unsigned int last_address;
230 /* Variables to handle plabels that we discover are necessary at assembly
231 output time. They are output after the current function. */
232 struct GTY(()) deferred_plabel
234 rtx internal_label;
235 rtx symbol;
237 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
238 deferred_plabels;
239 static size_t n_deferred_plabels = 0;
241 /* Initialize the GCC target structure. */
243 #undef TARGET_OPTION_OVERRIDE
244 #define TARGET_OPTION_OVERRIDE pa_option_override
246 #undef TARGET_ASM_ALIGNED_HI_OP
247 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
248 #undef TARGET_ASM_ALIGNED_SI_OP
249 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
250 #undef TARGET_ASM_ALIGNED_DI_OP
251 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
252 #undef TARGET_ASM_UNALIGNED_HI_OP
253 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
254 #undef TARGET_ASM_UNALIGNED_SI_OP
255 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
256 #undef TARGET_ASM_UNALIGNED_DI_OP
257 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
258 #undef TARGET_ASM_INTEGER
259 #define TARGET_ASM_INTEGER pa_assemble_integer
261 #undef TARGET_ASM_FUNCTION_PROLOGUE
262 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
263 #undef TARGET_ASM_FUNCTION_EPILOGUE
264 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
266 #undef TARGET_FUNCTION_VALUE
267 #define TARGET_FUNCTION_VALUE pa_function_value
268 #undef TARGET_LIBCALL_VALUE
269 #define TARGET_LIBCALL_VALUE pa_libcall_value
270 #undef TARGET_FUNCTION_VALUE_REGNO_P
271 #define TARGET_FUNCTION_VALUE_REGNO_P pa_function_value_regno_p
273 #undef TARGET_LEGITIMIZE_ADDRESS
274 #define TARGET_LEGITIMIZE_ADDRESS hppa_legitimize_address
276 #undef TARGET_SCHED_ADJUST_COST
277 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
278 #undef TARGET_SCHED_ADJUST_PRIORITY
279 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
280 #undef TARGET_SCHED_ISSUE_RATE
281 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
283 #undef TARGET_ENCODE_SECTION_INFO
284 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
285 #undef TARGET_STRIP_NAME_ENCODING
286 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
288 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
289 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
291 #undef TARGET_COMMUTATIVE_P
292 #define TARGET_COMMUTATIVE_P pa_commutative_p
294 #undef TARGET_ASM_OUTPUT_MI_THUNK
295 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
296 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
297 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
299 #undef TARGET_ASM_FILE_END
300 #ifdef ASM_OUTPUT_EXTERNAL_REAL
301 #define TARGET_ASM_FILE_END pa_hpux_file_end
302 #else
303 #define TARGET_ASM_FILE_END output_deferred_plabels
304 #endif
306 #undef TARGET_ASM_RELOC_RW_MASK
307 #define TARGET_ASM_RELOC_RW_MASK pa_reloc_rw_mask
309 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
310 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P pa_print_operand_punct_valid_p
312 #if !defined(USE_COLLECT2)
313 #undef TARGET_ASM_CONSTRUCTOR
314 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
315 #undef TARGET_ASM_DESTRUCTOR
316 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
317 #endif
319 #undef TARGET_INIT_BUILTINS
320 #define TARGET_INIT_BUILTINS pa_init_builtins
322 #undef TARGET_EXPAND_BUILTIN
323 #define TARGET_EXPAND_BUILTIN pa_expand_builtin
325 #undef TARGET_REGISTER_MOVE_COST
326 #define TARGET_REGISTER_MOVE_COST hppa_register_move_cost
327 #undef TARGET_RTX_COSTS
328 #define TARGET_RTX_COSTS hppa_rtx_costs
329 #undef TARGET_ADDRESS_COST
330 #define TARGET_ADDRESS_COST hppa_address_cost
332 #undef TARGET_MACHINE_DEPENDENT_REORG
333 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
335 #undef TARGET_INIT_LIBFUNCS
336 #define TARGET_INIT_LIBFUNCS pa_init_libfuncs
338 #undef TARGET_PROMOTE_FUNCTION_MODE
339 #define TARGET_PROMOTE_FUNCTION_MODE pa_promote_function_mode
340 #undef TARGET_PROMOTE_PROTOTYPES
341 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
343 #undef TARGET_STRUCT_VALUE_RTX
344 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
345 #undef TARGET_RETURN_IN_MEMORY
346 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
347 #undef TARGET_MUST_PASS_IN_STACK
348 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
349 #undef TARGET_PASS_BY_REFERENCE
350 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
351 #undef TARGET_CALLEE_COPIES
352 #define TARGET_CALLEE_COPIES pa_callee_copies
353 #undef TARGET_ARG_PARTIAL_BYTES
354 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
355 #undef TARGET_FUNCTION_ARG
356 #define TARGET_FUNCTION_ARG pa_function_arg
357 #undef TARGET_FUNCTION_ARG_ADVANCE
358 #define TARGET_FUNCTION_ARG_ADVANCE pa_function_arg_advance
359 #undef TARGET_FUNCTION_ARG_PADDING
360 #define TARGET_FUNCTION_ARG_PADDING pa_function_arg_padding
361 #undef TARGET_FUNCTION_ARG_BOUNDARY
362 #define TARGET_FUNCTION_ARG_BOUNDARY pa_function_arg_boundary
364 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
365 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
366 #undef TARGET_EXPAND_BUILTIN_VA_START
367 #define TARGET_EXPAND_BUILTIN_VA_START hppa_va_start
368 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
369 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
371 #undef TARGET_SCALAR_MODE_SUPPORTED_P
372 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
374 #undef TARGET_CANNOT_FORCE_CONST_MEM
375 #define TARGET_CANNOT_FORCE_CONST_MEM pa_cannot_force_const_mem
377 #undef TARGET_SECONDARY_RELOAD
378 #define TARGET_SECONDARY_RELOAD pa_secondary_reload
380 #undef TARGET_EXTRA_LIVE_ON_ENTRY
381 #define TARGET_EXTRA_LIVE_ON_ENTRY pa_extra_live_on_entry
383 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
384 #define TARGET_ASM_TRAMPOLINE_TEMPLATE pa_asm_trampoline_template
385 #undef TARGET_TRAMPOLINE_INIT
386 #define TARGET_TRAMPOLINE_INIT pa_trampoline_init
387 #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
388 #define TARGET_TRAMPOLINE_ADJUST_ADDRESS pa_trampoline_adjust_address
389 #undef TARGET_DELEGITIMIZE_ADDRESS
390 #define TARGET_DELEGITIMIZE_ADDRESS pa_delegitimize_address
391 #undef TARGET_INTERNAL_ARG_POINTER
392 #define TARGET_INTERNAL_ARG_POINTER pa_internal_arg_pointer
393 #undef TARGET_CAN_ELIMINATE
394 #define TARGET_CAN_ELIMINATE pa_can_eliminate
395 #undef TARGET_CONDITIONAL_REGISTER_USAGE
396 #define TARGET_CONDITIONAL_REGISTER_USAGE pa_conditional_register_usage
397 #undef TARGET_C_MODE_FOR_SUFFIX
398 #define TARGET_C_MODE_FOR_SUFFIX pa_c_mode_for_suffix
399 #undef TARGET_ASM_FUNCTION_SECTION
400 #define TARGET_ASM_FUNCTION_SECTION pa_function_section
402 #undef TARGET_LEGITIMATE_CONSTANT_P
403 #define TARGET_LEGITIMATE_CONSTANT_P pa_legitimate_constant_p
404 #undef TARGET_SECTION_TYPE_FLAGS
405 #define TARGET_SECTION_TYPE_FLAGS pa_section_type_flags
406 #undef TARGET_LEGITIMATE_ADDRESS_P
407 #define TARGET_LEGITIMATE_ADDRESS_P pa_legitimate_address_p
409 #undef TARGET_LRA_P
410 #define TARGET_LRA_P hook_bool_void_false
412 #undef TARGET_HARD_REGNO_MODE_OK
413 #define TARGET_HARD_REGNO_MODE_OK pa_hard_regno_mode_ok
414 #undef TARGET_MODES_TIEABLE_P
415 #define TARGET_MODES_TIEABLE_P pa_modes_tieable_p
417 struct gcc_target targetm = TARGET_INITIALIZER;
419 /* Parse the -mfixed-range= option string. */
421 static void
422 fix_range (const char *const_str)
424 int i, first, last;
425 char *str, *dash, *comma;
427 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
428 REG2 are either register names or register numbers. The effect
429 of this option is to mark the registers in the range from REG1 to
430 REG2 as ``fixed'' so they won't be used by the compiler. This is
431 used, e.g., to ensure that kernel mode code doesn't use fr4-fr31. */
433 i = strlen (const_str);
434 str = (char *) alloca (i + 1);
435 memcpy (str, const_str, i + 1);
437 while (1)
439 dash = strchr (str, '-');
440 if (!dash)
442 warning (0, "value of -mfixed-range must have form REG1-REG2");
443 return;
445 *dash = '\0';
447 comma = strchr (dash + 1, ',');
448 if (comma)
449 *comma = '\0';
451 first = decode_reg_name (str);
452 if (first < 0)
454 warning (0, "unknown register name: %s", str);
455 return;
458 last = decode_reg_name (dash + 1);
459 if (last < 0)
461 warning (0, "unknown register name: %s", dash + 1);
462 return;
465 *dash = '-';
467 if (first > last)
469 warning (0, "%s-%s is an empty range", str, dash + 1);
470 return;
473 for (i = first; i <= last; ++i)
474 fixed_regs[i] = call_used_regs[i] = 1;
476 if (!comma)
477 break;
479 *comma = ',';
480 str = comma + 1;
483 /* Check if all floating point registers have been fixed. */
484 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
485 if (!fixed_regs[i])
486 break;
488 if (i > FP_REG_LAST)
489 target_flags |= MASK_DISABLE_FPREGS;
492 /* Implement the TARGET_OPTION_OVERRIDE hook. */
494 static void
495 pa_option_override (void)
497 unsigned int i;
498 cl_deferred_option *opt;
499 vec<cl_deferred_option> *v
500 = (vec<cl_deferred_option> *) pa_deferred_options;
502 if (v)
503 FOR_EACH_VEC_ELT (*v, i, opt)
505 switch (opt->opt_index)
507 case OPT_mfixed_range_:
508 fix_range (opt->arg);
509 break;
511 default:
512 gcc_unreachable ();
516 if (flag_pic && TARGET_PORTABLE_RUNTIME)
518 warning (0, "PIC code generation is not supported in the portable runtime model");
521 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
523 warning (0, "PIC code generation is not compatible with fast indirect calls");
526 if (! TARGET_GAS && write_symbols != NO_DEBUG)
528 warning (0, "-g is only supported when using GAS on this processor,");
529 warning (0, "-g option disabled");
530 write_symbols = NO_DEBUG;
533 /* We only support the "big PIC" model now. And we always generate PIC
534 code when in 64bit mode. */
535 if (flag_pic == 1 || TARGET_64BIT)
536 flag_pic = 2;
538 /* Disable -freorder-blocks-and-partition as we don't support hot and
539 cold partitioning. */
540 if (flag_reorder_blocks_and_partition)
542 inform (input_location,
543 "-freorder-blocks-and-partition does not work "
544 "on this architecture");
545 flag_reorder_blocks_and_partition = 0;
546 flag_reorder_blocks = 1;
549 /* We can't guarantee that .dword is available for 32-bit targets. */
550 if (UNITS_PER_WORD == 4)
551 targetm.asm_out.aligned_op.di = NULL;
553 /* The unaligned ops are only available when using GAS. */
554 if (!TARGET_GAS)
556 targetm.asm_out.unaligned_op.hi = NULL;
557 targetm.asm_out.unaligned_op.si = NULL;
558 targetm.asm_out.unaligned_op.di = NULL;
561 init_machine_status = pa_init_machine_status;
564 enum pa_builtins
566 PA_BUILTIN_COPYSIGNQ,
567 PA_BUILTIN_FABSQ,
568 PA_BUILTIN_INFQ,
569 PA_BUILTIN_HUGE_VALQ,
570 PA_BUILTIN_max
573 static GTY(()) tree pa_builtins[(int) PA_BUILTIN_max];
575 static void
576 pa_init_builtins (void)
578 #ifdef DONT_HAVE_FPUTC_UNLOCKED
580 tree decl = builtin_decl_explicit (BUILT_IN_PUTC_UNLOCKED);
581 set_builtin_decl (BUILT_IN_FPUTC_UNLOCKED, decl,
582 builtin_decl_implicit_p (BUILT_IN_PUTC_UNLOCKED));
584 #endif
585 #if TARGET_HPUX_11
587 tree decl;
589 if ((decl = builtin_decl_explicit (BUILT_IN_FINITE)) != NULL_TREE)
590 set_user_assembler_name (decl, "_Isfinite");
591 if ((decl = builtin_decl_explicit (BUILT_IN_FINITEF)) != NULL_TREE)
592 set_user_assembler_name (decl, "_Isfinitef");
594 #endif
596 if (HPUX_LONG_DOUBLE_LIBRARY)
598 tree decl, ftype;
600 /* Under HPUX, the __float128 type is a synonym for "long double". */
601 (*lang_hooks.types.register_builtin_type) (long_double_type_node,
602 "__float128");
604 /* TFmode support builtins. */
605 ftype = build_function_type_list (long_double_type_node,
606 long_double_type_node,
607 NULL_TREE);
608 decl = add_builtin_function ("__builtin_fabsq", ftype,
609 PA_BUILTIN_FABSQ, BUILT_IN_MD,
610 "_U_Qfabs", NULL_TREE);
611 TREE_READONLY (decl) = 1;
612 pa_builtins[PA_BUILTIN_FABSQ] = decl;
614 ftype = build_function_type_list (long_double_type_node,
615 long_double_type_node,
616 long_double_type_node,
617 NULL_TREE);
618 decl = add_builtin_function ("__builtin_copysignq", ftype,
619 PA_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
620 "_U_Qfcopysign", NULL_TREE);
621 TREE_READONLY (decl) = 1;
622 pa_builtins[PA_BUILTIN_COPYSIGNQ] = decl;
624 ftype = build_function_type_list (long_double_type_node, NULL_TREE);
625 decl = add_builtin_function ("__builtin_infq", ftype,
626 PA_BUILTIN_INFQ, BUILT_IN_MD,
627 NULL, NULL_TREE);
628 pa_builtins[PA_BUILTIN_INFQ] = decl;
630 decl = add_builtin_function ("__builtin_huge_valq", ftype,
631 PA_BUILTIN_HUGE_VALQ, BUILT_IN_MD,
632 NULL, NULL_TREE);
633 pa_builtins[PA_BUILTIN_HUGE_VALQ] = decl;
637 static rtx
638 pa_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
639 machine_mode mode ATTRIBUTE_UNUSED,
640 int ignore ATTRIBUTE_UNUSED)
642 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
643 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
645 switch (fcode)
647 case PA_BUILTIN_FABSQ:
648 case PA_BUILTIN_COPYSIGNQ:
649 return expand_call (exp, target, ignore);
651 case PA_BUILTIN_INFQ:
652 case PA_BUILTIN_HUGE_VALQ:
654 machine_mode target_mode = TYPE_MODE (TREE_TYPE (exp));
655 REAL_VALUE_TYPE inf;
656 rtx tmp;
658 real_inf (&inf);
659 tmp = const_double_from_real_value (inf, target_mode);
661 tmp = validize_mem (force_const_mem (target_mode, tmp));
663 if (target == 0)
664 target = gen_reg_rtx (target_mode);
666 emit_move_insn (target, tmp);
667 return target;
670 default:
671 gcc_unreachable ();
674 return NULL_RTX;
677 /* Function to init struct machine_function.
678 This will be called, via a pointer variable,
679 from push_function_context. */
681 static struct machine_function *
682 pa_init_machine_status (void)
684 return ggc_cleared_alloc<machine_function> ();
687 /* If FROM is a probable pointer register, mark TO as a probable
688 pointer register with the same pointer alignment as FROM. */
690 static void
691 copy_reg_pointer (rtx to, rtx from)
693 if (REG_POINTER (from))
694 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
697 /* Return 1 if X contains a symbolic expression. We know these
698 expressions will have one of a few well defined forms, so
699 we need only check those forms. */
701 pa_symbolic_expression_p (rtx x)
704 /* Strip off any HIGH. */
705 if (GET_CODE (x) == HIGH)
706 x = XEXP (x, 0);
708 return symbolic_operand (x, VOIDmode);
711 /* Accept any constant that can be moved in one instruction into a
712 general register. */
714 pa_cint_ok_for_move (unsigned HOST_WIDE_INT ival)
716 /* OK if ldo, ldil, or zdepi, can be used. */
717 return (VAL_14_BITS_P (ival)
718 || pa_ldil_cint_p (ival)
719 || pa_zdepi_cint_p (ival));
722 /* True iff ldil can be used to load this CONST_INT. The least
723 significant 11 bits of the value must be zero and the value must
724 not change sign when extended from 32 to 64 bits. */
726 pa_ldil_cint_p (unsigned HOST_WIDE_INT ival)
728 unsigned HOST_WIDE_INT x;
730 x = ival & (((unsigned HOST_WIDE_INT) -1 << 31) | 0x7ff);
731 return x == 0 || x == ((unsigned HOST_WIDE_INT) -1 << 31);
734 /* True iff zdepi can be used to generate this CONST_INT.
735 zdepi first sign extends a 5-bit signed number to a given field
736 length, then places this field anywhere in a zero. */
738 pa_zdepi_cint_p (unsigned HOST_WIDE_INT x)
740 unsigned HOST_WIDE_INT lsb_mask, t;
742 /* This might not be obvious, but it's at least fast.
743 This function is critical; we don't have the time loops would take. */
744 lsb_mask = x & -x;
745 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
746 /* Return true iff t is a power of two. */
747 return ((t & (t - 1)) == 0);
750 /* True iff depi or extru can be used to compute (reg & mask).
751 Accept bit pattern like these:
752 0....01....1
753 1....10....0
754 1..10..01..1 */
756 pa_and_mask_p (unsigned HOST_WIDE_INT mask)
758 mask = ~mask;
759 mask += mask & -mask;
760 return (mask & (mask - 1)) == 0;
763 /* True iff depi can be used to compute (reg | MASK). */
765 pa_ior_mask_p (unsigned HOST_WIDE_INT mask)
767 mask += mask & -mask;
768 return (mask & (mask - 1)) == 0;
771 /* Legitimize PIC addresses. If the address is already
772 position-independent, we return ORIG. Newly generated
773 position-independent addresses go to REG. If we need more
774 than one register, we lose. */
776 static rtx
777 legitimize_pic_address (rtx orig, machine_mode mode, rtx reg)
779 rtx pic_ref = orig;
781 gcc_assert (!PA_SYMBOL_REF_TLS_P (orig));
783 /* Labels need special handling. */
784 if (pic_label_operand (orig, mode))
786 rtx_insn *insn;
788 /* We do not want to go through the movXX expanders here since that
789 would create recursion.
791 Nor do we really want to call a generator for a named pattern
792 since that requires multiple patterns if we want to support
793 multiple word sizes.
795 So instead we just emit the raw set, which avoids the movXX
796 expanders completely. */
797 mark_reg_pointer (reg, BITS_PER_UNIT);
798 insn = emit_insn (gen_rtx_SET (reg, orig));
800 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
801 add_reg_note (insn, REG_EQUAL, orig);
803 /* During and after reload, we need to generate a REG_LABEL_OPERAND note
804 and update LABEL_NUSES because this is not done automatically. */
805 if (reload_in_progress || reload_completed)
807 /* Extract LABEL_REF. */
808 if (GET_CODE (orig) == CONST)
809 orig = XEXP (XEXP (orig, 0), 0);
810 /* Extract CODE_LABEL. */
811 orig = XEXP (orig, 0);
812 add_reg_note (insn, REG_LABEL_OPERAND, orig);
813 /* Make sure we have label and not a note. */
814 if (LABEL_P (orig))
815 LABEL_NUSES (orig)++;
817 crtl->uses_pic_offset_table = 1;
818 return reg;
820 if (GET_CODE (orig) == SYMBOL_REF)
822 rtx_insn *insn;
823 rtx tmp_reg;
825 gcc_assert (reg);
827 /* Before reload, allocate a temporary register for the intermediate
828 result. This allows the sequence to be deleted when the final
829 result is unused and the insns are trivially dead. */
830 tmp_reg = ((reload_in_progress || reload_completed)
831 ? reg : gen_reg_rtx (Pmode));
833 if (function_label_operand (orig, VOIDmode))
835 /* Force function label into memory in word mode. */
836 orig = XEXP (force_const_mem (word_mode, orig), 0);
837 /* Load plabel address from DLT. */
838 emit_move_insn (tmp_reg,
839 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
840 gen_rtx_HIGH (word_mode, orig)));
841 pic_ref
842 = gen_const_mem (Pmode,
843 gen_rtx_LO_SUM (Pmode, tmp_reg,
844 gen_rtx_UNSPEC (Pmode,
845 gen_rtvec (1, orig),
846 UNSPEC_DLTIND14R)));
847 emit_move_insn (reg, pic_ref);
848 /* Now load address of function descriptor. */
849 pic_ref = gen_rtx_MEM (Pmode, reg);
851 else
853 /* Load symbol reference from DLT. */
854 emit_move_insn (tmp_reg,
855 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
856 gen_rtx_HIGH (word_mode, orig)));
857 pic_ref
858 = gen_const_mem (Pmode,
859 gen_rtx_LO_SUM (Pmode, tmp_reg,
860 gen_rtx_UNSPEC (Pmode,
861 gen_rtvec (1, orig),
862 UNSPEC_DLTIND14R)));
865 crtl->uses_pic_offset_table = 1;
866 mark_reg_pointer (reg, BITS_PER_UNIT);
867 insn = emit_move_insn (reg, pic_ref);
869 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
870 set_unique_reg_note (insn, REG_EQUAL, orig);
872 return reg;
874 else if (GET_CODE (orig) == CONST)
876 rtx base;
878 if (GET_CODE (XEXP (orig, 0)) == PLUS
879 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
880 return orig;
882 gcc_assert (reg);
883 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
885 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
886 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
887 base == reg ? 0 : reg);
889 if (GET_CODE (orig) == CONST_INT)
891 if (INT_14_BITS (orig))
892 return plus_constant (Pmode, base, INTVAL (orig));
893 orig = force_reg (Pmode, orig);
895 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
896 /* Likewise, should we set special REG_NOTEs here? */
899 return pic_ref;
902 static GTY(()) rtx gen_tls_tga;
904 static rtx
905 gen_tls_get_addr (void)
907 if (!gen_tls_tga)
908 gen_tls_tga = init_one_libfunc ("__tls_get_addr");
909 return gen_tls_tga;
912 static rtx
913 hppa_tls_call (rtx arg)
915 rtx ret;
917 ret = gen_reg_rtx (Pmode);
918 emit_library_call_value (gen_tls_get_addr (), ret,
919 LCT_CONST, Pmode, arg, Pmode);
921 return ret;
924 static rtx
925 legitimize_tls_address (rtx addr)
927 rtx ret, tmp, t1, t2, tp;
928 rtx_insn *insn;
930 /* Currently, we can't handle anything but a SYMBOL_REF. */
931 if (GET_CODE (addr) != SYMBOL_REF)
932 return addr;
934 switch (SYMBOL_REF_TLS_MODEL (addr))
936 case TLS_MODEL_GLOBAL_DYNAMIC:
937 tmp = gen_reg_rtx (Pmode);
938 if (flag_pic)
939 emit_insn (gen_tgd_load_pic (tmp, addr));
940 else
941 emit_insn (gen_tgd_load (tmp, addr));
942 ret = hppa_tls_call (tmp);
943 break;
945 case TLS_MODEL_LOCAL_DYNAMIC:
946 ret = gen_reg_rtx (Pmode);
947 tmp = gen_reg_rtx (Pmode);
948 start_sequence ();
949 if (flag_pic)
950 emit_insn (gen_tld_load_pic (tmp, addr));
951 else
952 emit_insn (gen_tld_load (tmp, addr));
953 t1 = hppa_tls_call (tmp);
954 insn = get_insns ();
955 end_sequence ();
956 t2 = gen_reg_rtx (Pmode);
957 emit_libcall_block (insn, t2, t1,
958 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
959 UNSPEC_TLSLDBASE));
960 emit_insn (gen_tld_offset_load (ret, addr, t2));
961 break;
963 case TLS_MODEL_INITIAL_EXEC:
964 tp = gen_reg_rtx (Pmode);
965 tmp = gen_reg_rtx (Pmode);
966 ret = gen_reg_rtx (Pmode);
967 emit_insn (gen_tp_load (tp));
968 if (flag_pic)
969 emit_insn (gen_tie_load_pic (tmp, addr));
970 else
971 emit_insn (gen_tie_load (tmp, addr));
972 emit_move_insn (ret, gen_rtx_PLUS (Pmode, tp, tmp));
973 break;
975 case TLS_MODEL_LOCAL_EXEC:
976 tp = gen_reg_rtx (Pmode);
977 ret = gen_reg_rtx (Pmode);
978 emit_insn (gen_tp_load (tp));
979 emit_insn (gen_tle_load (ret, addr, tp));
980 break;
982 default:
983 gcc_unreachable ();
986 return ret;
989 /* Helper for hppa_legitimize_address. Given X, return true if it
990 is a left shift by 1, 2 or 3 positions or a multiply by 2, 4 or 8.
992 This respectively represent canonical shift-add rtxs or scaled
993 memory addresses. */
994 static bool
995 mem_shadd_or_shadd_rtx_p (rtx x)
997 return ((GET_CODE (x) == ASHIFT
998 || GET_CODE (x) == MULT)
999 && GET_CODE (XEXP (x, 1)) == CONST_INT
1000 && ((GET_CODE (x) == ASHIFT
1001 && pa_shadd_constant_p (INTVAL (XEXP (x, 1))))
1002 || (GET_CODE (x) == MULT
1003 && pa_mem_shadd_constant_p (INTVAL (XEXP (x, 1))))));
1006 /* Try machine-dependent ways of modifying an illegitimate address
1007 to be legitimate. If we find one, return the new, valid address.
1008 This macro is used in only one place: `memory_address' in explow.c.
1010 OLDX is the address as it was before break_out_memory_refs was called.
1011 In some cases it is useful to look at this to decide what needs to be done.
1013 It is always safe for this macro to do nothing. It exists to recognize
1014 opportunities to optimize the output.
1016 For the PA, transform:
1018 memory(X + <large int>)
1020 into:
1022 if (<large int> & mask) >= 16
1023 Y = (<large int> & ~mask) + mask + 1 Round up.
1024 else
1025 Y = (<large int> & ~mask) Round down.
1026 Z = X + Y
1027 memory (Z + (<large int> - Y));
1029 This is for CSE to find several similar references, and only use one Z.
1031 X can either be a SYMBOL_REF or REG, but because combine cannot
1032 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
1033 D will not fit in 14 bits.
1035 MODE_FLOAT references allow displacements which fit in 5 bits, so use
1036 0x1f as the mask.
1038 MODE_INT references allow displacements which fit in 14 bits, so use
1039 0x3fff as the mask.
1041 This relies on the fact that most mode MODE_FLOAT references will use FP
1042 registers and most mode MODE_INT references will use integer registers.
1043 (In the rare case of an FP register used in an integer MODE, we depend
1044 on secondary reloads to clean things up.)
1047 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
1048 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
1049 addressing modes to be used).
1051 Note that the addresses passed into hppa_legitimize_address always
1052 come from a MEM, so we only have to match the MULT form on incoming
1053 addresses. But to be future proof we also match the ASHIFT form.
1055 However, this routine always places those shift-add sequences into
1056 registers, so we have to generate the ASHIFT form as our output.
1058 Put X and Z into registers. Then put the entire expression into
1059 a register. */
1062 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1063 machine_mode mode)
1065 rtx orig = x;
1067 /* We need to canonicalize the order of operands in unscaled indexed
1068 addresses since the code that checks if an address is valid doesn't
1069 always try both orders. */
1070 if (!TARGET_NO_SPACE_REGS
1071 && GET_CODE (x) == PLUS
1072 && GET_MODE (x) == Pmode
1073 && REG_P (XEXP (x, 0))
1074 && REG_P (XEXP (x, 1))
1075 && REG_POINTER (XEXP (x, 0))
1076 && !REG_POINTER (XEXP (x, 1)))
1077 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
1079 if (tls_referenced_p (x))
1080 return legitimize_tls_address (x);
1081 else if (flag_pic)
1082 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
1084 /* Strip off CONST. */
1085 if (GET_CODE (x) == CONST)
1086 x = XEXP (x, 0);
1088 /* Special case. Get the SYMBOL_REF into a register and use indexing.
1089 That should always be safe. */
1090 if (GET_CODE (x) == PLUS
1091 && GET_CODE (XEXP (x, 0)) == REG
1092 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
1094 rtx reg = force_reg (Pmode, XEXP (x, 1));
1095 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
1098 /* Note we must reject symbols which represent function addresses
1099 since the assembler/linker can't handle arithmetic on plabels. */
1100 if (GET_CODE (x) == PLUS
1101 && GET_CODE (XEXP (x, 1)) == CONST_INT
1102 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1103 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
1104 || GET_CODE (XEXP (x, 0)) == REG))
1106 rtx int_part, ptr_reg;
1107 int newoffset;
1108 int offset = INTVAL (XEXP (x, 1));
1109 int mask;
1111 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
1112 && !INT14_OK_STRICT ? 0x1f : 0x3fff);
1114 /* Choose which way to round the offset. Round up if we
1115 are >= halfway to the next boundary. */
1116 if ((offset & mask) >= ((mask + 1) / 2))
1117 newoffset = (offset & ~ mask) + mask + 1;
1118 else
1119 newoffset = (offset & ~ mask);
1121 /* If the newoffset will not fit in 14 bits (ldo), then
1122 handling this would take 4 or 5 instructions (2 to load
1123 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
1124 add the new offset and the SYMBOL_REF.) Combine can
1125 not handle 4->2 or 5->2 combinations, so do not create
1126 them. */
1127 if (! VAL_14_BITS_P (newoffset)
1128 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
1130 rtx const_part = plus_constant (Pmode, XEXP (x, 0), newoffset);
1131 rtx tmp_reg
1132 = force_reg (Pmode,
1133 gen_rtx_HIGH (Pmode, const_part));
1134 ptr_reg
1135 = force_reg (Pmode,
1136 gen_rtx_LO_SUM (Pmode,
1137 tmp_reg, const_part));
1139 else
1141 if (! VAL_14_BITS_P (newoffset))
1142 int_part = force_reg (Pmode, GEN_INT (newoffset));
1143 else
1144 int_part = GEN_INT (newoffset);
1146 ptr_reg = force_reg (Pmode,
1147 gen_rtx_PLUS (Pmode,
1148 force_reg (Pmode, XEXP (x, 0)),
1149 int_part));
1151 return plus_constant (Pmode, ptr_reg, offset - newoffset);
1154 /* Handle (plus (mult (a) (mem_shadd_constant)) (b)). */
1156 if (GET_CODE (x) == PLUS
1157 && mem_shadd_or_shadd_rtx_p (XEXP (x, 0))
1158 && (OBJECT_P (XEXP (x, 1))
1159 || GET_CODE (XEXP (x, 1)) == SUBREG)
1160 && GET_CODE (XEXP (x, 1)) != CONST)
1162 /* If we were given a MULT, we must fix the constant
1163 as we're going to create the ASHIFT form. */
1164 int shift_val = INTVAL (XEXP (XEXP (x, 0), 1));
1165 if (GET_CODE (XEXP (x, 0)) == MULT)
1166 shift_val = exact_log2 (shift_val);
1168 rtx reg1, reg2;
1169 reg1 = XEXP (x, 1);
1170 if (GET_CODE (reg1) != REG)
1171 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1173 reg2 = XEXP (XEXP (x, 0), 0);
1174 if (GET_CODE (reg2) != REG)
1175 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1177 return force_reg (Pmode,
1178 gen_rtx_PLUS (Pmode,
1179 gen_rtx_ASHIFT (Pmode, reg2,
1180 GEN_INT (shift_val)),
1181 reg1));
1184 /* Similarly for (plus (plus (mult (a) (mem_shadd_constant)) (b)) (c)).
1186 Only do so for floating point modes since this is more speculative
1187 and we lose if it's an integer store. */
1188 if (GET_CODE (x) == PLUS
1189 && GET_CODE (XEXP (x, 0)) == PLUS
1190 && mem_shadd_or_shadd_rtx_p (XEXP (XEXP (x, 0), 0))
1191 && (mode == SFmode || mode == DFmode))
1193 int shift_val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
1195 /* If we were given a MULT, we must fix the constant
1196 as we're going to create the ASHIFT form. */
1197 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
1198 shift_val = exact_log2 (shift_val);
1200 /* Try and figure out what to use as a base register. */
1201 rtx reg1, reg2, base, idx;
1203 reg1 = XEXP (XEXP (x, 0), 1);
1204 reg2 = XEXP (x, 1);
1205 base = NULL_RTX;
1206 idx = NULL_RTX;
1208 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
1209 then pa_emit_move_sequence will turn on REG_POINTER so we'll know
1210 it's a base register below. */
1211 if (GET_CODE (reg1) != REG)
1212 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1214 if (GET_CODE (reg2) != REG)
1215 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1217 /* Figure out what the base and index are. */
1219 if (GET_CODE (reg1) == REG
1220 && REG_POINTER (reg1))
1222 base = reg1;
1223 idx = gen_rtx_PLUS (Pmode,
1224 gen_rtx_ASHIFT (Pmode,
1225 XEXP (XEXP (XEXP (x, 0), 0), 0),
1226 GEN_INT (shift_val)),
1227 XEXP (x, 1));
1229 else if (GET_CODE (reg2) == REG
1230 && REG_POINTER (reg2))
1232 base = reg2;
1233 idx = XEXP (x, 0);
1236 if (base == 0)
1237 return orig;
1239 /* If the index adds a large constant, try to scale the
1240 constant so that it can be loaded with only one insn. */
1241 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1242 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1243 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1244 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1246 /* Divide the CONST_INT by the scale factor, then add it to A. */
1247 int val = INTVAL (XEXP (idx, 1));
1248 val /= (1 << shift_val);
1250 reg1 = XEXP (XEXP (idx, 0), 0);
1251 if (GET_CODE (reg1) != REG)
1252 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1254 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1256 /* We can now generate a simple scaled indexed address. */
1257 return
1258 force_reg
1259 (Pmode, gen_rtx_PLUS (Pmode,
1260 gen_rtx_ASHIFT (Pmode, reg1,
1261 GEN_INT (shift_val)),
1262 base));
1265 /* If B + C is still a valid base register, then add them. */
1266 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1267 && INTVAL (XEXP (idx, 1)) <= 4096
1268 && INTVAL (XEXP (idx, 1)) >= -4096)
1270 rtx reg1, reg2;
1272 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1274 reg2 = XEXP (XEXP (idx, 0), 0);
1275 if (GET_CODE (reg2) != CONST_INT)
1276 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1278 return force_reg (Pmode,
1279 gen_rtx_PLUS (Pmode,
1280 gen_rtx_ASHIFT (Pmode, reg2,
1281 GEN_INT (shift_val)),
1282 reg1));
1285 /* Get the index into a register, then add the base + index and
1286 return a register holding the result. */
1288 /* First get A into a register. */
1289 reg1 = XEXP (XEXP (idx, 0), 0);
1290 if (GET_CODE (reg1) != REG)
1291 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1293 /* And get B into a register. */
1294 reg2 = XEXP (idx, 1);
1295 if (GET_CODE (reg2) != REG)
1296 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1298 reg1 = force_reg (Pmode,
1299 gen_rtx_PLUS (Pmode,
1300 gen_rtx_ASHIFT (Pmode, reg1,
1301 GEN_INT (shift_val)),
1302 reg2));
1304 /* Add the result to our base register and return. */
1305 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1309 /* Uh-oh. We might have an address for x[n-100000]. This needs
1310 special handling to avoid creating an indexed memory address
1311 with x-100000 as the base.
1313 If the constant part is small enough, then it's still safe because
1314 there is a guard page at the beginning and end of the data segment.
1316 Scaled references are common enough that we want to try and rearrange the
1317 terms so that we can use indexing for these addresses too. Only
1318 do the optimization for floatint point modes. */
1320 if (GET_CODE (x) == PLUS
1321 && pa_symbolic_expression_p (XEXP (x, 1)))
1323 /* Ugly. We modify things here so that the address offset specified
1324 by the index expression is computed first, then added to x to form
1325 the entire address. */
1327 rtx regx1, regx2, regy1, regy2, y;
1329 /* Strip off any CONST. */
1330 y = XEXP (x, 1);
1331 if (GET_CODE (y) == CONST)
1332 y = XEXP (y, 0);
1334 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1336 /* See if this looks like
1337 (plus (mult (reg) (mem_shadd_const))
1338 (const (plus (symbol_ref) (const_int))))
1340 Where const_int is small. In that case the const
1341 expression is a valid pointer for indexing.
1343 If const_int is big, but can be divided evenly by shadd_const
1344 and added to (reg). This allows more scaled indexed addresses. */
1345 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1346 && mem_shadd_or_shadd_rtx_p (XEXP (x, 0))
1347 && GET_CODE (XEXP (y, 1)) == CONST_INT
1348 && INTVAL (XEXP (y, 1)) >= -4096
1349 && INTVAL (XEXP (y, 1)) <= 4095)
1351 int shift_val = INTVAL (XEXP (XEXP (x, 0), 1));
1353 /* If we were given a MULT, we must fix the constant
1354 as we're going to create the ASHIFT form. */
1355 if (GET_CODE (XEXP (x, 0)) == MULT)
1356 shift_val = exact_log2 (shift_val);
1358 rtx reg1, reg2;
1360 reg1 = XEXP (x, 1);
1361 if (GET_CODE (reg1) != REG)
1362 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1364 reg2 = XEXP (XEXP (x, 0), 0);
1365 if (GET_CODE (reg2) != REG)
1366 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1368 return
1369 force_reg (Pmode,
1370 gen_rtx_PLUS (Pmode,
1371 gen_rtx_ASHIFT (Pmode,
1372 reg2,
1373 GEN_INT (shift_val)),
1374 reg1));
1376 else if ((mode == DFmode || mode == SFmode)
1377 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1378 && mem_shadd_or_shadd_rtx_p (XEXP (x, 0))
1379 && GET_CODE (XEXP (y, 1)) == CONST_INT
1380 && INTVAL (XEXP (y, 1)) % (1 << INTVAL (XEXP (XEXP (x, 0), 1))) == 0)
1382 int shift_val = INTVAL (XEXP (XEXP (x, 0), 1));
1384 /* If we were given a MULT, we must fix the constant
1385 as we're going to create the ASHIFT form. */
1386 if (GET_CODE (XEXP (x, 0)) == MULT)
1387 shift_val = exact_log2 (shift_val);
1389 regx1
1390 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1391 / INTVAL (XEXP (XEXP (x, 0), 1))));
1392 regx2 = XEXP (XEXP (x, 0), 0);
1393 if (GET_CODE (regx2) != REG)
1394 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1395 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1396 regx2, regx1));
1397 return
1398 force_reg (Pmode,
1399 gen_rtx_PLUS (Pmode,
1400 gen_rtx_ASHIFT (Pmode, regx2,
1401 GEN_INT (shift_val)),
1402 force_reg (Pmode, XEXP (y, 0))));
1404 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1405 && INTVAL (XEXP (y, 1)) >= -4096
1406 && INTVAL (XEXP (y, 1)) <= 4095)
1408 /* This is safe because of the guard page at the
1409 beginning and end of the data space. Just
1410 return the original address. */
1411 return orig;
1413 else
1415 /* Doesn't look like one we can optimize. */
1416 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1417 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1418 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1419 regx1 = force_reg (Pmode,
1420 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1421 regx1, regy2));
1422 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1427 return orig;
1430 /* Implement the TARGET_REGISTER_MOVE_COST hook.
1432 Compute extra cost of moving data between one register class
1433 and another.
1435 Make moves from SAR so expensive they should never happen. We used to
1436 have 0xffff here, but that generates overflow in rare cases.
1438 Copies involving a FP register and a non-FP register are relatively
1439 expensive because they must go through memory.
1441 Other copies are reasonably cheap. */
1443 static int
1444 hppa_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
1445 reg_class_t from, reg_class_t to)
1447 if (from == SHIFT_REGS)
1448 return 0x100;
1449 else if (to == SHIFT_REGS && FP_REG_CLASS_P (from))
1450 return 18;
1451 else if ((FP_REG_CLASS_P (from) && ! FP_REG_CLASS_P (to))
1452 || (FP_REG_CLASS_P (to) && ! FP_REG_CLASS_P (from)))
1453 return 16;
1454 else
1455 return 2;
1458 /* For the HPPA, REG and REG+CONST is cost 0
1459 and addresses involving symbolic constants are cost 2.
1461 PIC addresses are very expensive.
1463 It is no coincidence that this has the same structure
1464 as pa_legitimate_address_p. */
1466 static int
1467 hppa_address_cost (rtx X, machine_mode mode ATTRIBUTE_UNUSED,
1468 addr_space_t as ATTRIBUTE_UNUSED,
1469 bool speed ATTRIBUTE_UNUSED)
1471 switch (GET_CODE (X))
1473 case REG:
1474 case PLUS:
1475 case LO_SUM:
1476 return 1;
1477 case HIGH:
1478 return 2;
1479 default:
1480 return 4;
1484 /* Compute a (partial) cost for rtx X. Return true if the complete
1485 cost has been computed, and false if subexpressions should be
1486 scanned. In either case, *TOTAL contains the cost result. */
1488 static bool
1489 hppa_rtx_costs (rtx x, machine_mode mode, int outer_code,
1490 int opno ATTRIBUTE_UNUSED,
1491 int *total, bool speed ATTRIBUTE_UNUSED)
1493 int factor;
1494 int code = GET_CODE (x);
1496 switch (code)
1498 case CONST_INT:
1499 if (INTVAL (x) == 0)
1500 *total = 0;
1501 else if (INT_14_BITS (x))
1502 *total = 1;
1503 else
1504 *total = 2;
1505 return true;
1507 case HIGH:
1508 *total = 2;
1509 return true;
1511 case CONST:
1512 case LABEL_REF:
1513 case SYMBOL_REF:
1514 *total = 4;
1515 return true;
1517 case CONST_DOUBLE:
1518 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1519 && outer_code != SET)
1520 *total = 0;
1521 else
1522 *total = 8;
1523 return true;
1525 case MULT:
1526 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1528 *total = COSTS_N_INSNS (3);
1529 return true;
1532 /* A mode size N times larger than SImode needs O(N*N) more insns. */
1533 factor = GET_MODE_SIZE (mode) / 4;
1534 if (factor == 0)
1535 factor = 1;
1537 if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1538 *total = factor * factor * COSTS_N_INSNS (8);
1539 else
1540 *total = factor * factor * COSTS_N_INSNS (20);
1541 return true;
1543 case DIV:
1544 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1546 *total = COSTS_N_INSNS (14);
1547 return true;
1549 /* FALLTHRU */
1551 case UDIV:
1552 case MOD:
1553 case UMOD:
1554 /* A mode size N times larger than SImode needs O(N*N) more insns. */
1555 factor = GET_MODE_SIZE (mode) / 4;
1556 if (factor == 0)
1557 factor = 1;
1559 *total = factor * factor * COSTS_N_INSNS (60);
1560 return true;
1562 case PLUS: /* this includes shNadd insns */
1563 case MINUS:
1564 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1566 *total = COSTS_N_INSNS (3);
1567 return true;
1570 /* A size N times larger than UNITS_PER_WORD needs N times as
1571 many insns, taking N times as long. */
1572 factor = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
1573 if (factor == 0)
1574 factor = 1;
1575 *total = factor * COSTS_N_INSNS (1);
1576 return true;
1578 case ASHIFT:
1579 case ASHIFTRT:
1580 case LSHIFTRT:
1581 *total = COSTS_N_INSNS (1);
1582 return true;
1584 default:
1585 return false;
1589 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1590 new rtx with the correct mode. */
1591 static inline rtx
1592 force_mode (machine_mode mode, rtx orig)
1594 if (mode == GET_MODE (orig))
1595 return orig;
1597 gcc_assert (REGNO (orig) < FIRST_PSEUDO_REGISTER);
1599 return gen_rtx_REG (mode, REGNO (orig));
1602 /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */
1604 static bool
1605 pa_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
1607 return tls_referenced_p (x);
1610 /* Emit insns to move operands[1] into operands[0].
1612 Return 1 if we have written out everything that needs to be done to
1613 do the move. Otherwise, return 0 and the caller will emit the move
1614 normally.
1616 Note SCRATCH_REG may not be in the proper mode depending on how it
1617 will be used. This routine is responsible for creating a new copy
1618 of SCRATCH_REG in the proper mode. */
1621 pa_emit_move_sequence (rtx *operands, machine_mode mode, rtx scratch_reg)
1623 register rtx operand0 = operands[0];
1624 register rtx operand1 = operands[1];
1625 register rtx tem;
1627 /* We can only handle indexed addresses in the destination operand
1628 of floating point stores. Thus, we need to break out indexed
1629 addresses from the destination operand. */
1630 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1632 gcc_assert (can_create_pseudo_p ());
1634 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1635 operand0 = replace_equiv_address (operand0, tem);
1638 /* On targets with non-equivalent space registers, break out unscaled
1639 indexed addresses from the source operand before the final CSE.
1640 We have to do this because the REG_POINTER flag is not correctly
1641 carried through various optimization passes and CSE may substitute
1642 a pseudo without the pointer set for one with the pointer set. As
1643 a result, we loose various opportunities to create insns with
1644 unscaled indexed addresses. */
1645 if (!TARGET_NO_SPACE_REGS
1646 && !cse_not_expected
1647 && GET_CODE (operand1) == MEM
1648 && GET_CODE (XEXP (operand1, 0)) == PLUS
1649 && REG_P (XEXP (XEXP (operand1, 0), 0))
1650 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1651 operand1
1652 = replace_equiv_address (operand1,
1653 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1655 if (scratch_reg
1656 && reload_in_progress && GET_CODE (operand0) == REG
1657 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1658 operand0 = reg_equiv_mem (REGNO (operand0));
1659 else if (scratch_reg
1660 && reload_in_progress && GET_CODE (operand0) == SUBREG
1661 && GET_CODE (SUBREG_REG (operand0)) == REG
1662 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1664 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1665 the code which tracks sets/uses for delete_output_reload. */
1666 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1667 reg_equiv_mem (REGNO (SUBREG_REG (operand0))),
1668 SUBREG_BYTE (operand0));
1669 operand0 = alter_subreg (&temp, true);
1672 if (scratch_reg
1673 && reload_in_progress && GET_CODE (operand1) == REG
1674 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1675 operand1 = reg_equiv_mem (REGNO (operand1));
1676 else if (scratch_reg
1677 && reload_in_progress && GET_CODE (operand1) == SUBREG
1678 && GET_CODE (SUBREG_REG (operand1)) == REG
1679 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1681 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1682 the code which tracks sets/uses for delete_output_reload. */
1683 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1684 reg_equiv_mem (REGNO (SUBREG_REG (operand1))),
1685 SUBREG_BYTE (operand1));
1686 operand1 = alter_subreg (&temp, true);
1689 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1690 && ((tem = find_replacement (&XEXP (operand0, 0)))
1691 != XEXP (operand0, 0)))
1692 operand0 = replace_equiv_address (operand0, tem);
1694 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1695 && ((tem = find_replacement (&XEXP (operand1, 0)))
1696 != XEXP (operand1, 0)))
1697 operand1 = replace_equiv_address (operand1, tem);
1699 /* Handle secondary reloads for loads/stores of FP registers from
1700 REG+D addresses where D does not fit in 5 or 14 bits, including
1701 (subreg (mem (addr))) cases, and reloads for other unsupported
1702 memory operands. */
1703 if (scratch_reg
1704 && FP_REG_P (operand0)
1705 && (MEM_P (operand1)
1706 || (GET_CODE (operand1) == SUBREG
1707 && MEM_P (XEXP (operand1, 0)))))
1709 rtx op1 = operand1;
1711 if (GET_CODE (op1) == SUBREG)
1712 op1 = XEXP (op1, 0);
1714 if (reg_plus_base_memory_operand (op1, GET_MODE (op1)))
1716 if (!(TARGET_PA_20
1717 && !TARGET_ELF32
1718 && INT_14_BITS (XEXP (XEXP (op1, 0), 1)))
1719 && !INT_5_BITS (XEXP (XEXP (op1, 0), 1)))
1721 /* SCRATCH_REG will hold an address and maybe the actual data.
1722 We want it in WORD_MODE regardless of what mode it was
1723 originally given to us. */
1724 scratch_reg = force_mode (word_mode, scratch_reg);
1726 /* D might not fit in 14 bits either; for such cases load D
1727 into scratch reg. */
1728 if (!INT_14_BITS (XEXP (XEXP (op1, 0), 1)))
1730 emit_move_insn (scratch_reg, XEXP (XEXP (op1, 0), 1));
1731 emit_move_insn (scratch_reg,
1732 gen_rtx_fmt_ee (GET_CODE (XEXP (op1, 0)),
1733 Pmode,
1734 XEXP (XEXP (op1, 0), 0),
1735 scratch_reg));
1737 else
1738 emit_move_insn (scratch_reg, XEXP (op1, 0));
1739 emit_insn (gen_rtx_SET (operand0,
1740 replace_equiv_address (op1, scratch_reg)));
1741 return 1;
1744 else if ((!INT14_OK_STRICT && symbolic_memory_operand (op1, VOIDmode))
1745 || IS_LO_SUM_DLT_ADDR_P (XEXP (op1, 0))
1746 || IS_INDEX_ADDR_P (XEXP (op1, 0)))
1748 /* Load memory address into SCRATCH_REG. */
1749 scratch_reg = force_mode (word_mode, scratch_reg);
1750 emit_move_insn (scratch_reg, XEXP (op1, 0));
1751 emit_insn (gen_rtx_SET (operand0,
1752 replace_equiv_address (op1, scratch_reg)));
1753 return 1;
1756 else if (scratch_reg
1757 && FP_REG_P (operand1)
1758 && (MEM_P (operand0)
1759 || (GET_CODE (operand0) == SUBREG
1760 && MEM_P (XEXP (operand0, 0)))))
1762 rtx op0 = operand0;
1764 if (GET_CODE (op0) == SUBREG)
1765 op0 = XEXP (op0, 0);
1767 if (reg_plus_base_memory_operand (op0, GET_MODE (op0)))
1769 if (!(TARGET_PA_20
1770 && !TARGET_ELF32
1771 && INT_14_BITS (XEXP (XEXP (op0, 0), 1)))
1772 && !INT_5_BITS (XEXP (XEXP (op0, 0), 1)))
1774 /* SCRATCH_REG will hold an address and maybe the actual data.
1775 We want it in WORD_MODE regardless of what mode it was
1776 originally given to us. */
1777 scratch_reg = force_mode (word_mode, scratch_reg);
1779 /* D might not fit in 14 bits either; for such cases load D
1780 into scratch reg. */
1781 if (!INT_14_BITS (XEXP (XEXP (op0, 0), 1)))
1783 emit_move_insn (scratch_reg, XEXP (XEXP (op0, 0), 1));
1784 emit_move_insn (scratch_reg,
1785 gen_rtx_fmt_ee (GET_CODE (XEXP (op0, 0)),
1786 Pmode,
1787 XEXP (XEXP (op0, 0), 0),
1788 scratch_reg));
1790 else
1791 emit_move_insn (scratch_reg, XEXP (op0, 0));
1792 emit_insn (gen_rtx_SET (replace_equiv_address (op0, scratch_reg),
1793 operand1));
1794 return 1;
1797 else if ((!INT14_OK_STRICT && symbolic_memory_operand (op0, VOIDmode))
1798 || IS_LO_SUM_DLT_ADDR_P (XEXP (op0, 0))
1799 || IS_INDEX_ADDR_P (XEXP (op0, 0)))
1801 /* Load memory address into SCRATCH_REG. */
1802 scratch_reg = force_mode (word_mode, scratch_reg);
1803 emit_move_insn (scratch_reg, XEXP (op0, 0));
1804 emit_insn (gen_rtx_SET (replace_equiv_address (op0, scratch_reg),
1805 operand1));
1806 return 1;
1809 /* Handle secondary reloads for loads of FP registers from constant
1810 expressions by forcing the constant into memory. For the most part,
1811 this is only necessary for SImode and DImode.
1813 Use scratch_reg to hold the address of the memory location. */
1814 else if (scratch_reg
1815 && CONSTANT_P (operand1)
1816 && FP_REG_P (operand0))
1818 rtx const_mem, xoperands[2];
1820 if (operand1 == CONST0_RTX (mode))
1822 emit_insn (gen_rtx_SET (operand0, operand1));
1823 return 1;
1826 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1827 it in WORD_MODE regardless of what mode it was originally given
1828 to us. */
1829 scratch_reg = force_mode (word_mode, scratch_reg);
1831 /* Force the constant into memory and put the address of the
1832 memory location into scratch_reg. */
1833 const_mem = force_const_mem (mode, operand1);
1834 xoperands[0] = scratch_reg;
1835 xoperands[1] = XEXP (const_mem, 0);
1836 pa_emit_move_sequence (xoperands, Pmode, 0);
1838 /* Now load the destination register. */
1839 emit_insn (gen_rtx_SET (operand0,
1840 replace_equiv_address (const_mem, scratch_reg)));
1841 return 1;
1843 /* Handle secondary reloads for SAR. These occur when trying to load
1844 the SAR from memory or a constant. */
1845 else if (scratch_reg
1846 && GET_CODE (operand0) == REG
1847 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1848 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1849 && (GET_CODE (operand1) == MEM || GET_CODE (operand1) == CONST_INT))
1851 /* D might not fit in 14 bits either; for such cases load D into
1852 scratch reg. */
1853 if (GET_CODE (operand1) == MEM
1854 && !memory_address_p (GET_MODE (operand0), XEXP (operand1, 0)))
1856 /* We are reloading the address into the scratch register, so we
1857 want to make sure the scratch register is a full register. */
1858 scratch_reg = force_mode (word_mode, scratch_reg);
1860 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1861 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1862 0)),
1863 Pmode,
1864 XEXP (XEXP (operand1, 0),
1866 scratch_reg));
1868 /* Now we are going to load the scratch register from memory,
1869 we want to load it in the same width as the original MEM,
1870 which must be the same as the width of the ultimate destination,
1871 OPERAND0. */
1872 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1874 emit_move_insn (scratch_reg,
1875 replace_equiv_address (operand1, scratch_reg));
1877 else
1879 /* We want to load the scratch register using the same mode as
1880 the ultimate destination. */
1881 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1883 emit_move_insn (scratch_reg, operand1);
1886 /* And emit the insn to set the ultimate destination. We know that
1887 the scratch register has the same mode as the destination at this
1888 point. */
1889 emit_move_insn (operand0, scratch_reg);
1890 return 1;
1893 /* Handle the most common case: storing into a register. */
1894 if (register_operand (operand0, mode))
1896 /* Legitimize TLS symbol references. This happens for references
1897 that aren't a legitimate constant. */
1898 if (PA_SYMBOL_REF_TLS_P (operand1))
1899 operand1 = legitimize_tls_address (operand1);
1901 if (register_operand (operand1, mode)
1902 || (GET_CODE (operand1) == CONST_INT
1903 && pa_cint_ok_for_move (UINTVAL (operand1)))
1904 || (operand1 == CONST0_RTX (mode))
1905 || (GET_CODE (operand1) == HIGH
1906 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1907 /* Only `general_operands' can come here, so MEM is ok. */
1908 || GET_CODE (operand1) == MEM)
1910 /* Various sets are created during RTL generation which don't
1911 have the REG_POINTER flag correctly set. After the CSE pass,
1912 instruction recognition can fail if we don't consistently
1913 set this flag when performing register copies. This should
1914 also improve the opportunities for creating insns that use
1915 unscaled indexing. */
1916 if (REG_P (operand0) && REG_P (operand1))
1918 if (REG_POINTER (operand1)
1919 && !REG_POINTER (operand0)
1920 && !HARD_REGISTER_P (operand0))
1921 copy_reg_pointer (operand0, operand1);
1924 /* When MEMs are broken out, the REG_POINTER flag doesn't
1925 get set. In some cases, we can set the REG_POINTER flag
1926 from the declaration for the MEM. */
1927 if (REG_P (operand0)
1928 && GET_CODE (operand1) == MEM
1929 && !REG_POINTER (operand0))
1931 tree decl = MEM_EXPR (operand1);
1933 /* Set the register pointer flag and register alignment
1934 if the declaration for this memory reference is a
1935 pointer type. */
1936 if (decl)
1938 tree type;
1940 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1941 tree operand 1. */
1942 if (TREE_CODE (decl) == COMPONENT_REF)
1943 decl = TREE_OPERAND (decl, 1);
1945 type = TREE_TYPE (decl);
1946 type = strip_array_types (type);
1948 if (POINTER_TYPE_P (type))
1949 mark_reg_pointer (operand0, BITS_PER_UNIT);
1953 emit_insn (gen_rtx_SET (operand0, operand1));
1954 return 1;
1957 else if (GET_CODE (operand0) == MEM)
1959 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1960 && !(reload_in_progress || reload_completed))
1962 rtx temp = gen_reg_rtx (DFmode);
1964 emit_insn (gen_rtx_SET (temp, operand1));
1965 emit_insn (gen_rtx_SET (operand0, temp));
1966 return 1;
1968 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1970 /* Run this case quickly. */
1971 emit_insn (gen_rtx_SET (operand0, operand1));
1972 return 1;
1974 if (! (reload_in_progress || reload_completed))
1976 operands[0] = validize_mem (operand0);
1977 operands[1] = operand1 = force_reg (mode, operand1);
1981 /* Simplify the source if we need to.
1982 Note we do have to handle function labels here, even though we do
1983 not consider them legitimate constants. Loop optimizations can
1984 call the emit_move_xxx with one as a source. */
1985 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1986 || (GET_CODE (operand1) == HIGH
1987 && symbolic_operand (XEXP (operand1, 0), mode))
1988 || function_label_operand (operand1, VOIDmode)
1989 || tls_referenced_p (operand1))
1991 int ishighonly = 0;
1993 if (GET_CODE (operand1) == HIGH)
1995 ishighonly = 1;
1996 operand1 = XEXP (operand1, 0);
1998 if (symbolic_operand (operand1, mode))
2000 /* Argh. The assembler and linker can't handle arithmetic
2001 involving plabels.
2003 So we force the plabel into memory, load operand0 from
2004 the memory location, then add in the constant part. */
2005 if ((GET_CODE (operand1) == CONST
2006 && GET_CODE (XEXP (operand1, 0)) == PLUS
2007 && function_label_operand (XEXP (XEXP (operand1, 0), 0),
2008 VOIDmode))
2009 || function_label_operand (operand1, VOIDmode))
2011 rtx temp, const_part;
2013 /* Figure out what (if any) scratch register to use. */
2014 if (reload_in_progress || reload_completed)
2016 scratch_reg = scratch_reg ? scratch_reg : operand0;
2017 /* SCRATCH_REG will hold an address and maybe the actual
2018 data. We want it in WORD_MODE regardless of what mode it
2019 was originally given to us. */
2020 scratch_reg = force_mode (word_mode, scratch_reg);
2022 else if (flag_pic)
2023 scratch_reg = gen_reg_rtx (Pmode);
2025 if (GET_CODE (operand1) == CONST)
2027 /* Save away the constant part of the expression. */
2028 const_part = XEXP (XEXP (operand1, 0), 1);
2029 gcc_assert (GET_CODE (const_part) == CONST_INT);
2031 /* Force the function label into memory. */
2032 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
2034 else
2036 /* No constant part. */
2037 const_part = NULL_RTX;
2039 /* Force the function label into memory. */
2040 temp = force_const_mem (mode, operand1);
2044 /* Get the address of the memory location. PIC-ify it if
2045 necessary. */
2046 temp = XEXP (temp, 0);
2047 if (flag_pic)
2048 temp = legitimize_pic_address (temp, mode, scratch_reg);
2050 /* Put the address of the memory location into our destination
2051 register. */
2052 operands[1] = temp;
2053 pa_emit_move_sequence (operands, mode, scratch_reg);
2055 /* Now load from the memory location into our destination
2056 register. */
2057 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
2058 pa_emit_move_sequence (operands, mode, scratch_reg);
2060 /* And add back in the constant part. */
2061 if (const_part != NULL_RTX)
2062 expand_inc (operand0, const_part);
2064 return 1;
2067 if (flag_pic)
2069 rtx_insn *insn;
2070 rtx temp;
2072 if (reload_in_progress || reload_completed)
2074 temp = scratch_reg ? scratch_reg : operand0;
2075 /* TEMP will hold an address and maybe the actual
2076 data. We want it in WORD_MODE regardless of what mode it
2077 was originally given to us. */
2078 temp = force_mode (word_mode, temp);
2080 else
2081 temp = gen_reg_rtx (Pmode);
2083 /* Force (const (plus (symbol) (const_int))) to memory
2084 if the const_int will not fit in 14 bits. Although
2085 this requires a relocation, the instruction sequence
2086 needed to load the value is shorter. */
2087 if (GET_CODE (operand1) == CONST
2088 && GET_CODE (XEXP (operand1, 0)) == PLUS
2089 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
2090 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1)))
2092 rtx x, m = force_const_mem (mode, operand1);
2094 x = legitimize_pic_address (XEXP (m, 0), mode, temp);
2095 x = replace_equiv_address (m, x);
2096 insn = emit_move_insn (operand0, x);
2098 else
2100 operands[1] = legitimize_pic_address (operand1, mode, temp);
2101 if (REG_P (operand0) && REG_P (operands[1]))
2102 copy_reg_pointer (operand0, operands[1]);
2103 insn = emit_move_insn (operand0, operands[1]);
2106 /* Put a REG_EQUAL note on this insn. */
2107 set_unique_reg_note (insn, REG_EQUAL, operand1);
2109 /* On the HPPA, references to data space are supposed to use dp,
2110 register 27, but showing it in the RTL inhibits various cse
2111 and loop optimizations. */
2112 else
2114 rtx temp, set;
2116 if (reload_in_progress || reload_completed)
2118 temp = scratch_reg ? scratch_reg : operand0;
2119 /* TEMP will hold an address and maybe the actual
2120 data. We want it in WORD_MODE regardless of what mode it
2121 was originally given to us. */
2122 temp = force_mode (word_mode, temp);
2124 else
2125 temp = gen_reg_rtx (mode);
2127 /* Loading a SYMBOL_REF into a register makes that register
2128 safe to be used as the base in an indexed address.
2130 Don't mark hard registers though. That loses. */
2131 if (GET_CODE (operand0) == REG
2132 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
2133 mark_reg_pointer (operand0, BITS_PER_UNIT);
2134 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
2135 mark_reg_pointer (temp, BITS_PER_UNIT);
2137 if (ishighonly)
2138 set = gen_rtx_SET (operand0, temp);
2139 else
2140 set = gen_rtx_SET (operand0,
2141 gen_rtx_LO_SUM (mode, temp, operand1));
2143 emit_insn (gen_rtx_SET (temp, gen_rtx_HIGH (mode, operand1)));
2144 emit_insn (set);
2147 return 1;
2149 else if (tls_referenced_p (operand1))
2151 rtx tmp = operand1;
2152 rtx addend = NULL;
2154 if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
2156 addend = XEXP (XEXP (tmp, 0), 1);
2157 tmp = XEXP (XEXP (tmp, 0), 0);
2160 gcc_assert (GET_CODE (tmp) == SYMBOL_REF);
2161 tmp = legitimize_tls_address (tmp);
2162 if (addend)
2164 tmp = gen_rtx_PLUS (mode, tmp, addend);
2165 tmp = force_operand (tmp, operands[0]);
2167 operands[1] = tmp;
2169 else if (GET_CODE (operand1) != CONST_INT
2170 || !pa_cint_ok_for_move (UINTVAL (operand1)))
2172 rtx temp;
2173 rtx_insn *insn;
2174 rtx op1 = operand1;
2175 HOST_WIDE_INT value = 0;
2176 HOST_WIDE_INT insv = 0;
2177 int insert = 0;
2179 if (GET_CODE (operand1) == CONST_INT)
2180 value = INTVAL (operand1);
2182 if (TARGET_64BIT
2183 && GET_CODE (operand1) == CONST_INT
2184 && HOST_BITS_PER_WIDE_INT > 32
2185 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
2187 HOST_WIDE_INT nval;
2189 /* Extract the low order 32 bits of the value and sign extend.
2190 If the new value is the same as the original value, we can
2191 can use the original value as-is. If the new value is
2192 different, we use it and insert the most-significant 32-bits
2193 of the original value into the final result. */
2194 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
2195 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
2196 if (value != nval)
2198 #if HOST_BITS_PER_WIDE_INT > 32
2199 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
2200 #endif
2201 insert = 1;
2202 value = nval;
2203 operand1 = GEN_INT (nval);
2207 if (reload_in_progress || reload_completed)
2208 temp = scratch_reg ? scratch_reg : operand0;
2209 else
2210 temp = gen_reg_rtx (mode);
2212 /* We don't directly split DImode constants on 32-bit targets
2213 because PLUS uses an 11-bit immediate and the insn sequence
2214 generated is not as efficient as the one using HIGH/LO_SUM. */
2215 if (GET_CODE (operand1) == CONST_INT
2216 && GET_MODE_BITSIZE (mode) <= BITS_PER_WORD
2217 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2218 && !insert)
2220 /* Directly break constant into high and low parts. This
2221 provides better optimization opportunities because various
2222 passes recognize constants split with PLUS but not LO_SUM.
2223 We use a 14-bit signed low part except when the addition
2224 of 0x4000 to the high part might change the sign of the
2225 high part. */
2226 HOST_WIDE_INT low = value & 0x3fff;
2227 HOST_WIDE_INT high = value & ~ 0x3fff;
2229 if (low >= 0x2000)
2231 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
2232 high += 0x2000;
2233 else
2234 high += 0x4000;
2237 low = value - high;
2239 emit_insn (gen_rtx_SET (temp, GEN_INT (high)));
2240 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2242 else
2244 emit_insn (gen_rtx_SET (temp, gen_rtx_HIGH (mode, operand1)));
2245 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
2248 insn = emit_move_insn (operands[0], operands[1]);
2250 /* Now insert the most significant 32 bits of the value
2251 into the register. When we don't have a second register
2252 available, it could take up to nine instructions to load
2253 a 64-bit integer constant. Prior to reload, we force
2254 constants that would take more than three instructions
2255 to load to the constant pool. During and after reload,
2256 we have to handle all possible values. */
2257 if (insert)
2259 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
2260 register and the value to be inserted is outside the
2261 range that can be loaded with three depdi instructions. */
2262 if (temp != operand0 && (insv >= 16384 || insv < -16384))
2264 operand1 = GEN_INT (insv);
2266 emit_insn (gen_rtx_SET (temp,
2267 gen_rtx_HIGH (mode, operand1)));
2268 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
2269 if (mode == DImode)
2270 insn = emit_insn (gen_insvdi (operand0, GEN_INT (32),
2271 const0_rtx, temp));
2272 else
2273 insn = emit_insn (gen_insvsi (operand0, GEN_INT (32),
2274 const0_rtx, temp));
2276 else
2278 int len = 5, pos = 27;
2280 /* Insert the bits using the depdi instruction. */
2281 while (pos >= 0)
2283 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2284 HOST_WIDE_INT sign = v5 < 0;
2286 /* Left extend the insertion. */
2287 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2288 while (pos > 0 && (insv & 1) == sign)
2290 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2291 len += 1;
2292 pos -= 1;
2295 if (mode == DImode)
2296 insn = emit_insn (gen_insvdi (operand0,
2297 GEN_INT (len),
2298 GEN_INT (pos),
2299 GEN_INT (v5)));
2300 else
2301 insn = emit_insn (gen_insvsi (operand0,
2302 GEN_INT (len),
2303 GEN_INT (pos),
2304 GEN_INT (v5)));
2306 len = pos > 0 && pos < 5 ? pos : 5;
2307 pos -= len;
2312 set_unique_reg_note (insn, REG_EQUAL, op1);
2314 return 1;
2317 /* Now have insn-emit do whatever it normally does. */
2318 return 0;
2321 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2322 it will need a link/runtime reloc). */
2325 pa_reloc_needed (tree exp)
2327 int reloc = 0;
2329 switch (TREE_CODE (exp))
2331 case ADDR_EXPR:
2332 return 1;
2334 case POINTER_PLUS_EXPR:
2335 case PLUS_EXPR:
2336 case MINUS_EXPR:
2337 reloc = pa_reloc_needed (TREE_OPERAND (exp, 0));
2338 reloc |= pa_reloc_needed (TREE_OPERAND (exp, 1));
2339 break;
2341 CASE_CONVERT:
2342 case NON_LVALUE_EXPR:
2343 reloc = pa_reloc_needed (TREE_OPERAND (exp, 0));
2344 break;
2346 case CONSTRUCTOR:
2348 tree value;
2349 unsigned HOST_WIDE_INT ix;
2351 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), ix, value)
2352 if (value)
2353 reloc |= pa_reloc_needed (value);
2355 break;
2357 case ERROR_MARK:
2358 break;
2360 default:
2361 break;
2363 return reloc;
2367 /* Return the best assembler insn template
2368 for moving operands[1] into operands[0] as a fullword. */
2369 const char *
2370 pa_singlemove_string (rtx *operands)
2372 HOST_WIDE_INT intval;
2374 if (GET_CODE (operands[0]) == MEM)
2375 return "stw %r1,%0";
2376 if (GET_CODE (operands[1]) == MEM)
2377 return "ldw %1,%0";
2378 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2380 long i;
2382 gcc_assert (GET_MODE (operands[1]) == SFmode);
2384 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2385 bit pattern. */
2386 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (operands[1]), i);
2388 operands[1] = GEN_INT (i);
2389 /* Fall through to CONST_INT case. */
2391 if (GET_CODE (operands[1]) == CONST_INT)
2393 intval = INTVAL (operands[1]);
2395 if (VAL_14_BITS_P (intval))
2396 return "ldi %1,%0";
2397 else if ((intval & 0x7ff) == 0)
2398 return "ldil L'%1,%0";
2399 else if (pa_zdepi_cint_p (intval))
2400 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2401 else
2402 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2404 return "copy %1,%0";
2408 /* Compute position (in OP[1]) and width (in OP[2])
2409 useful for copying IMM to a register using the zdepi
2410 instructions. Store the immediate value to insert in OP[0]. */
2411 static void
2412 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2414 int lsb, len;
2416 /* Find the least significant set bit in IMM. */
2417 for (lsb = 0; lsb < 32; lsb++)
2419 if ((imm & 1) != 0)
2420 break;
2421 imm >>= 1;
2424 /* Choose variants based on *sign* of the 5-bit field. */
2425 if ((imm & 0x10) == 0)
2426 len = (lsb <= 28) ? 4 : 32 - lsb;
2427 else
2429 /* Find the width of the bitstring in IMM. */
2430 for (len = 5; len < 32 - lsb; len++)
2432 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2433 break;
2436 /* Sign extend IMM as a 5-bit value. */
2437 imm = (imm & 0xf) - 0x10;
2440 op[0] = imm;
2441 op[1] = 31 - lsb;
2442 op[2] = len;
2445 /* Compute position (in OP[1]) and width (in OP[2])
2446 useful for copying IMM to a register using the depdi,z
2447 instructions. Store the immediate value to insert in OP[0]. */
2449 static void
2450 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2452 int lsb, len, maxlen;
2454 maxlen = MIN (HOST_BITS_PER_WIDE_INT, 64);
2456 /* Find the least significant set bit in IMM. */
2457 for (lsb = 0; lsb < maxlen; lsb++)
2459 if ((imm & 1) != 0)
2460 break;
2461 imm >>= 1;
2464 /* Choose variants based on *sign* of the 5-bit field. */
2465 if ((imm & 0x10) == 0)
2466 len = (lsb <= maxlen - 4) ? 4 : maxlen - lsb;
2467 else
2469 /* Find the width of the bitstring in IMM. */
2470 for (len = 5; len < maxlen - lsb; len++)
2472 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2473 break;
2476 /* Extend length if host is narrow and IMM is negative. */
2477 if (HOST_BITS_PER_WIDE_INT == 32 && len == maxlen - lsb)
2478 len += 32;
2480 /* Sign extend IMM as a 5-bit value. */
2481 imm = (imm & 0xf) - 0x10;
2484 op[0] = imm;
2485 op[1] = 63 - lsb;
2486 op[2] = len;
2489 /* Output assembler code to perform a doubleword move insn
2490 with operands OPERANDS. */
2492 const char *
2493 pa_output_move_double (rtx *operands)
2495 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2496 rtx latehalf[2];
2497 rtx addreg0 = 0, addreg1 = 0;
2498 int highonly = 0;
2500 /* First classify both operands. */
2502 if (REG_P (operands[0]))
2503 optype0 = REGOP;
2504 else if (offsettable_memref_p (operands[0]))
2505 optype0 = OFFSOP;
2506 else if (GET_CODE (operands[0]) == MEM)
2507 optype0 = MEMOP;
2508 else
2509 optype0 = RNDOP;
2511 if (REG_P (operands[1]))
2512 optype1 = REGOP;
2513 else if (CONSTANT_P (operands[1]))
2514 optype1 = CNSTOP;
2515 else if (offsettable_memref_p (operands[1]))
2516 optype1 = OFFSOP;
2517 else if (GET_CODE (operands[1]) == MEM)
2518 optype1 = MEMOP;
2519 else
2520 optype1 = RNDOP;
2522 /* Check for the cases that the operand constraints are not
2523 supposed to allow to happen. */
2524 gcc_assert (optype0 == REGOP || optype1 == REGOP);
2526 /* Handle copies between general and floating registers. */
2528 if (optype0 == REGOP && optype1 == REGOP
2529 && FP_REG_P (operands[0]) ^ FP_REG_P (operands[1]))
2531 if (FP_REG_P (operands[0]))
2533 output_asm_insn ("{stws|stw} %1,-16(%%sp)", operands);
2534 output_asm_insn ("{stws|stw} %R1,-12(%%sp)", operands);
2535 return "{fldds|fldd} -16(%%sp),%0";
2537 else
2539 output_asm_insn ("{fstds|fstd} %1,-16(%%sp)", operands);
2540 output_asm_insn ("{ldws|ldw} -16(%%sp),%0", operands);
2541 return "{ldws|ldw} -12(%%sp),%R0";
2545 /* Handle auto decrementing and incrementing loads and stores
2546 specifically, since the structure of the function doesn't work
2547 for them without major modification. Do it better when we learn
2548 this port about the general inc/dec addressing of PA.
2549 (This was written by tege. Chide him if it doesn't work.) */
2551 if (optype0 == MEMOP)
2553 /* We have to output the address syntax ourselves, since print_operand
2554 doesn't deal with the addresses we want to use. Fix this later. */
2556 rtx addr = XEXP (operands[0], 0);
2557 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2559 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2561 operands[0] = XEXP (addr, 0);
2562 gcc_assert (GET_CODE (operands[1]) == REG
2563 && GET_CODE (operands[0]) == REG);
2565 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2567 /* No overlap between high target register and address
2568 register. (We do this in a non-obvious way to
2569 save a register file writeback) */
2570 if (GET_CODE (addr) == POST_INC)
2571 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2572 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2574 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2576 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2578 operands[0] = XEXP (addr, 0);
2579 gcc_assert (GET_CODE (operands[1]) == REG
2580 && GET_CODE (operands[0]) == REG);
2582 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2583 /* No overlap between high target register and address
2584 register. (We do this in a non-obvious way to save a
2585 register file writeback) */
2586 if (GET_CODE (addr) == PRE_INC)
2587 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2588 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2591 if (optype1 == MEMOP)
2593 /* We have to output the address syntax ourselves, since print_operand
2594 doesn't deal with the addresses we want to use. Fix this later. */
2596 rtx addr = XEXP (operands[1], 0);
2597 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2599 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2601 operands[1] = XEXP (addr, 0);
2602 gcc_assert (GET_CODE (operands[0]) == REG
2603 && GET_CODE (operands[1]) == REG);
2605 if (!reg_overlap_mentioned_p (high_reg, addr))
2607 /* No overlap between high target register and address
2608 register. (We do this in a non-obvious way to
2609 save a register file writeback) */
2610 if (GET_CODE (addr) == POST_INC)
2611 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2612 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2614 else
2616 /* This is an undefined situation. We should load into the
2617 address register *and* update that register. Probably
2618 we don't need to handle this at all. */
2619 if (GET_CODE (addr) == POST_INC)
2620 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2621 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2624 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2626 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2628 operands[1] = XEXP (addr, 0);
2629 gcc_assert (GET_CODE (operands[0]) == REG
2630 && GET_CODE (operands[1]) == REG);
2632 if (!reg_overlap_mentioned_p (high_reg, addr))
2634 /* No overlap between high target register and address
2635 register. (We do this in a non-obvious way to
2636 save a register file writeback) */
2637 if (GET_CODE (addr) == PRE_INC)
2638 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2639 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2641 else
2643 /* This is an undefined situation. We should load into the
2644 address register *and* update that register. Probably
2645 we don't need to handle this at all. */
2646 if (GET_CODE (addr) == PRE_INC)
2647 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2648 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2651 else if (GET_CODE (addr) == PLUS
2652 && GET_CODE (XEXP (addr, 0)) == MULT)
2654 rtx xoperands[4];
2656 /* Load address into left half of destination register. */
2657 xoperands[0] = gen_rtx_SUBREG (SImode, operands[0], 0);
2658 xoperands[1] = XEXP (addr, 1);
2659 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2660 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2661 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2662 xoperands);
2663 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2665 else if (GET_CODE (addr) == PLUS
2666 && REG_P (XEXP (addr, 0))
2667 && REG_P (XEXP (addr, 1)))
2669 rtx xoperands[3];
2671 /* Load address into left half of destination register. */
2672 xoperands[0] = gen_rtx_SUBREG (SImode, operands[0], 0);
2673 xoperands[1] = XEXP (addr, 0);
2674 xoperands[2] = XEXP (addr, 1);
2675 output_asm_insn ("{addl|add,l} %1,%2,%0",
2676 xoperands);
2677 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2681 /* If an operand is an unoffsettable memory ref, find a register
2682 we can increment temporarily to make it refer to the second word. */
2684 if (optype0 == MEMOP)
2685 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2687 if (optype1 == MEMOP)
2688 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2690 /* Ok, we can do one word at a time.
2691 Normally we do the low-numbered word first.
2693 In either case, set up in LATEHALF the operands to use
2694 for the high-numbered word and in some cases alter the
2695 operands in OPERANDS to be suitable for the low-numbered word. */
2697 if (optype0 == REGOP)
2698 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2699 else if (optype0 == OFFSOP)
2700 latehalf[0] = adjust_address_nv (operands[0], SImode, 4);
2701 else
2702 latehalf[0] = operands[0];
2704 if (optype1 == REGOP)
2705 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2706 else if (optype1 == OFFSOP)
2707 latehalf[1] = adjust_address_nv (operands[1], SImode, 4);
2708 else if (optype1 == CNSTOP)
2710 if (GET_CODE (operands[1]) == HIGH)
2712 operands[1] = XEXP (operands[1], 0);
2713 highonly = 1;
2715 split_double (operands[1], &operands[1], &latehalf[1]);
2717 else
2718 latehalf[1] = operands[1];
2720 /* If the first move would clobber the source of the second one,
2721 do them in the other order.
2723 This can happen in two cases:
2725 mem -> register where the first half of the destination register
2726 is the same register used in the memory's address. Reload
2727 can create such insns.
2729 mem in this case will be either register indirect or register
2730 indirect plus a valid offset.
2732 register -> register move where REGNO(dst) == REGNO(src + 1)
2733 someone (Tim/Tege?) claimed this can happen for parameter loads.
2735 Handle mem -> register case first. */
2736 if (optype0 == REGOP
2737 && (optype1 == MEMOP || optype1 == OFFSOP)
2738 && refers_to_regno_p (REGNO (operands[0]), operands[1]))
2740 /* Do the late half first. */
2741 if (addreg1)
2742 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2743 output_asm_insn (pa_singlemove_string (latehalf), latehalf);
2745 /* Then clobber. */
2746 if (addreg1)
2747 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2748 return pa_singlemove_string (operands);
2751 /* Now handle register -> register case. */
2752 if (optype0 == REGOP && optype1 == REGOP
2753 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2755 output_asm_insn (pa_singlemove_string (latehalf), latehalf);
2756 return pa_singlemove_string (operands);
2759 /* Normal case: do the two words, low-numbered first. */
2761 output_asm_insn (pa_singlemove_string (operands), operands);
2763 /* Make any unoffsettable addresses point at high-numbered word. */
2764 if (addreg0)
2765 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2766 if (addreg1)
2767 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2769 /* Do high-numbered word. */
2770 if (highonly)
2771 output_asm_insn ("ldil L'%1,%0", latehalf);
2772 else
2773 output_asm_insn (pa_singlemove_string (latehalf), latehalf);
2775 /* Undo the adds we just did. */
2776 if (addreg0)
2777 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2778 if (addreg1)
2779 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2781 return "";
2784 const char *
2785 pa_output_fp_move_double (rtx *operands)
2787 if (FP_REG_P (operands[0]))
2789 if (FP_REG_P (operands[1])
2790 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2791 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2792 else
2793 output_asm_insn ("fldd%F1 %1,%0", operands);
2795 else if (FP_REG_P (operands[1]))
2797 output_asm_insn ("fstd%F0 %1,%0", operands);
2799 else
2801 rtx xoperands[2];
2803 gcc_assert (operands[1] == CONST0_RTX (GET_MODE (operands[0])));
2805 /* This is a pain. You have to be prepared to deal with an
2806 arbitrary address here including pre/post increment/decrement.
2808 so avoid this in the MD. */
2809 gcc_assert (GET_CODE (operands[0]) == REG);
2811 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2812 xoperands[0] = operands[0];
2813 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2815 return "";
2818 /* Return a REG that occurs in ADDR with coefficient 1.
2819 ADDR can be effectively incremented by incrementing REG. */
2821 static rtx
2822 find_addr_reg (rtx addr)
2824 while (GET_CODE (addr) == PLUS)
2826 if (GET_CODE (XEXP (addr, 0)) == REG)
2827 addr = XEXP (addr, 0);
2828 else if (GET_CODE (XEXP (addr, 1)) == REG)
2829 addr = XEXP (addr, 1);
2830 else if (CONSTANT_P (XEXP (addr, 0)))
2831 addr = XEXP (addr, 1);
2832 else if (CONSTANT_P (XEXP (addr, 1)))
2833 addr = XEXP (addr, 0);
2834 else
2835 gcc_unreachable ();
2837 gcc_assert (GET_CODE (addr) == REG);
2838 return addr;
2841 /* Emit code to perform a block move.
2843 OPERANDS[0] is the destination pointer as a REG, clobbered.
2844 OPERANDS[1] is the source pointer as a REG, clobbered.
2845 OPERANDS[2] is a register for temporary storage.
2846 OPERANDS[3] is a register for temporary storage.
2847 OPERANDS[4] is the size as a CONST_INT
2848 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2849 OPERANDS[6] is another temporary register. */
2851 const char *
2852 pa_output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2854 int align = INTVAL (operands[5]);
2855 unsigned long n_bytes = INTVAL (operands[4]);
2857 /* We can't move more than a word at a time because the PA
2858 has no longer integer move insns. (Could use fp mem ops?) */
2859 if (align > (TARGET_64BIT ? 8 : 4))
2860 align = (TARGET_64BIT ? 8 : 4);
2862 /* Note that we know each loop below will execute at least twice
2863 (else we would have open-coded the copy). */
2864 switch (align)
2866 case 8:
2867 /* Pre-adjust the loop counter. */
2868 operands[4] = GEN_INT (n_bytes - 16);
2869 output_asm_insn ("ldi %4,%2", operands);
2871 /* Copying loop. */
2872 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2873 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2874 output_asm_insn ("std,ma %3,8(%0)", operands);
2875 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2876 output_asm_insn ("std,ma %6,8(%0)", operands);
2878 /* Handle the residual. There could be up to 7 bytes of
2879 residual to copy! */
2880 if (n_bytes % 16 != 0)
2882 operands[4] = GEN_INT (n_bytes % 8);
2883 if (n_bytes % 16 >= 8)
2884 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2885 if (n_bytes % 8 != 0)
2886 output_asm_insn ("ldd 0(%1),%6", operands);
2887 if (n_bytes % 16 >= 8)
2888 output_asm_insn ("std,ma %3,8(%0)", operands);
2889 if (n_bytes % 8 != 0)
2890 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2892 return "";
2894 case 4:
2895 /* Pre-adjust the loop counter. */
2896 operands[4] = GEN_INT (n_bytes - 8);
2897 output_asm_insn ("ldi %4,%2", operands);
2899 /* Copying loop. */
2900 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2901 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2902 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2903 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2904 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2906 /* Handle the residual. There could be up to 7 bytes of
2907 residual to copy! */
2908 if (n_bytes % 8 != 0)
2910 operands[4] = GEN_INT (n_bytes % 4);
2911 if (n_bytes % 8 >= 4)
2912 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2913 if (n_bytes % 4 != 0)
2914 output_asm_insn ("ldw 0(%1),%6", operands);
2915 if (n_bytes % 8 >= 4)
2916 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2917 if (n_bytes % 4 != 0)
2918 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2920 return "";
2922 case 2:
2923 /* Pre-adjust the loop counter. */
2924 operands[4] = GEN_INT (n_bytes - 4);
2925 output_asm_insn ("ldi %4,%2", operands);
2927 /* Copying loop. */
2928 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2929 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2930 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2931 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2932 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2934 /* Handle the residual. */
2935 if (n_bytes % 4 != 0)
2937 if (n_bytes % 4 >= 2)
2938 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2939 if (n_bytes % 2 != 0)
2940 output_asm_insn ("ldb 0(%1),%6", operands);
2941 if (n_bytes % 4 >= 2)
2942 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2943 if (n_bytes % 2 != 0)
2944 output_asm_insn ("stb %6,0(%0)", operands);
2946 return "";
2948 case 1:
2949 /* Pre-adjust the loop counter. */
2950 operands[4] = GEN_INT (n_bytes - 2);
2951 output_asm_insn ("ldi %4,%2", operands);
2953 /* Copying loop. */
2954 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2955 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2956 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2957 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2958 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2960 /* Handle the residual. */
2961 if (n_bytes % 2 != 0)
2963 output_asm_insn ("ldb 0(%1),%3", operands);
2964 output_asm_insn ("stb %3,0(%0)", operands);
2966 return "";
2968 default:
2969 gcc_unreachable ();
2973 /* Count the number of insns necessary to handle this block move.
2975 Basic structure is the same as emit_block_move, except that we
2976 count insns rather than emit them. */
2978 static int
2979 compute_movmem_length (rtx_insn *insn)
2981 rtx pat = PATTERN (insn);
2982 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2983 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2984 unsigned int n_insns = 0;
2986 /* We can't move more than four bytes at a time because the PA
2987 has no longer integer move insns. (Could use fp mem ops?) */
2988 if (align > (TARGET_64BIT ? 8 : 4))
2989 align = (TARGET_64BIT ? 8 : 4);
2991 /* The basic copying loop. */
2992 n_insns = 6;
2994 /* Residuals. */
2995 if (n_bytes % (2 * align) != 0)
2997 if ((n_bytes % (2 * align)) >= align)
2998 n_insns += 2;
3000 if ((n_bytes % align) != 0)
3001 n_insns += 2;
3004 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3005 return n_insns * 4;
3008 /* Emit code to perform a block clear.
3010 OPERANDS[0] is the destination pointer as a REG, clobbered.
3011 OPERANDS[1] is a register for temporary storage.
3012 OPERANDS[2] is the size as a CONST_INT
3013 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
3015 const char *
3016 pa_output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
3018 int align = INTVAL (operands[3]);
3019 unsigned long n_bytes = INTVAL (operands[2]);
3021 /* We can't clear more than a word at a time because the PA
3022 has no longer integer move insns. */
3023 if (align > (TARGET_64BIT ? 8 : 4))
3024 align = (TARGET_64BIT ? 8 : 4);
3026 /* Note that we know each loop below will execute at least twice
3027 (else we would have open-coded the copy). */
3028 switch (align)
3030 case 8:
3031 /* Pre-adjust the loop counter. */
3032 operands[2] = GEN_INT (n_bytes - 16);
3033 output_asm_insn ("ldi %2,%1", operands);
3035 /* Loop. */
3036 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3037 output_asm_insn ("addib,>= -16,%1,.-4", operands);
3038 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3040 /* Handle the residual. There could be up to 7 bytes of
3041 residual to copy! */
3042 if (n_bytes % 16 != 0)
3044 operands[2] = GEN_INT (n_bytes % 8);
3045 if (n_bytes % 16 >= 8)
3046 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3047 if (n_bytes % 8 != 0)
3048 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
3050 return "";
3052 case 4:
3053 /* Pre-adjust the loop counter. */
3054 operands[2] = GEN_INT (n_bytes - 8);
3055 output_asm_insn ("ldi %2,%1", operands);
3057 /* Loop. */
3058 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3059 output_asm_insn ("addib,>= -8,%1,.-4", operands);
3060 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3062 /* Handle the residual. There could be up to 7 bytes of
3063 residual to copy! */
3064 if (n_bytes % 8 != 0)
3066 operands[2] = GEN_INT (n_bytes % 4);
3067 if (n_bytes % 8 >= 4)
3068 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3069 if (n_bytes % 4 != 0)
3070 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
3072 return "";
3074 case 2:
3075 /* Pre-adjust the loop counter. */
3076 operands[2] = GEN_INT (n_bytes - 4);
3077 output_asm_insn ("ldi %2,%1", operands);
3079 /* Loop. */
3080 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3081 output_asm_insn ("addib,>= -4,%1,.-4", operands);
3082 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3084 /* Handle the residual. */
3085 if (n_bytes % 4 != 0)
3087 if (n_bytes % 4 >= 2)
3088 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3089 if (n_bytes % 2 != 0)
3090 output_asm_insn ("stb %%r0,0(%0)", operands);
3092 return "";
3094 case 1:
3095 /* Pre-adjust the loop counter. */
3096 operands[2] = GEN_INT (n_bytes - 2);
3097 output_asm_insn ("ldi %2,%1", operands);
3099 /* Loop. */
3100 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3101 output_asm_insn ("addib,>= -2,%1,.-4", operands);
3102 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3104 /* Handle the residual. */
3105 if (n_bytes % 2 != 0)
3106 output_asm_insn ("stb %%r0,0(%0)", operands);
3108 return "";
3110 default:
3111 gcc_unreachable ();
3115 /* Count the number of insns necessary to handle this block move.
3117 Basic structure is the same as emit_block_move, except that we
3118 count insns rather than emit them. */
3120 static int
3121 compute_clrmem_length (rtx_insn *insn)
3123 rtx pat = PATTERN (insn);
3124 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
3125 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
3126 unsigned int n_insns = 0;
3128 /* We can't clear more than a word at a time because the PA
3129 has no longer integer move insns. */
3130 if (align > (TARGET_64BIT ? 8 : 4))
3131 align = (TARGET_64BIT ? 8 : 4);
3133 /* The basic loop. */
3134 n_insns = 4;
3136 /* Residuals. */
3137 if (n_bytes % (2 * align) != 0)
3139 if ((n_bytes % (2 * align)) >= align)
3140 n_insns++;
3142 if ((n_bytes % align) != 0)
3143 n_insns++;
3146 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3147 return n_insns * 4;
3151 const char *
3152 pa_output_and (rtx *operands)
3154 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3156 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3157 int ls0, ls1, ms0, p, len;
3159 for (ls0 = 0; ls0 < 32; ls0++)
3160 if ((mask & (1 << ls0)) == 0)
3161 break;
3163 for (ls1 = ls0; ls1 < 32; ls1++)
3164 if ((mask & (1 << ls1)) != 0)
3165 break;
3167 for (ms0 = ls1; ms0 < 32; ms0++)
3168 if ((mask & (1 << ms0)) == 0)
3169 break;
3171 gcc_assert (ms0 == 32);
3173 if (ls1 == 32)
3175 len = ls0;
3177 gcc_assert (len);
3179 operands[2] = GEN_INT (len);
3180 return "{extru|extrw,u} %1,31,%2,%0";
3182 else
3184 /* We could use this `depi' for the case above as well, but `depi'
3185 requires one more register file access than an `extru'. */
3187 p = 31 - ls0;
3188 len = ls1 - ls0;
3190 operands[2] = GEN_INT (p);
3191 operands[3] = GEN_INT (len);
3192 return "{depi|depwi} 0,%2,%3,%0";
3195 else
3196 return "and %1,%2,%0";
3199 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3200 storing the result in operands[0]. */
3201 const char *
3202 pa_output_64bit_and (rtx *operands)
3204 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3206 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3207 int ls0, ls1, ms0, p, len;
3209 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
3210 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
3211 break;
3213 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
3214 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
3215 break;
3217 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
3218 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
3219 break;
3221 gcc_assert (ms0 == HOST_BITS_PER_WIDE_INT);
3223 if (ls1 == HOST_BITS_PER_WIDE_INT)
3225 len = ls0;
3227 gcc_assert (len);
3229 operands[2] = GEN_INT (len);
3230 return "extrd,u %1,63,%2,%0";
3232 else
3234 /* We could use this `depi' for the case above as well, but `depi'
3235 requires one more register file access than an `extru'. */
3237 p = 63 - ls0;
3238 len = ls1 - ls0;
3240 operands[2] = GEN_INT (p);
3241 operands[3] = GEN_INT (len);
3242 return "depdi 0,%2,%3,%0";
3245 else
3246 return "and %1,%2,%0";
3249 const char *
3250 pa_output_ior (rtx *operands)
3252 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3253 int bs0, bs1, p, len;
3255 if (INTVAL (operands[2]) == 0)
3256 return "copy %1,%0";
3258 for (bs0 = 0; bs0 < 32; bs0++)
3259 if ((mask & (1 << bs0)) != 0)
3260 break;
3262 for (bs1 = bs0; bs1 < 32; bs1++)
3263 if ((mask & (1 << bs1)) == 0)
3264 break;
3266 gcc_assert (bs1 == 32 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
3268 p = 31 - bs0;
3269 len = bs1 - bs0;
3271 operands[2] = GEN_INT (p);
3272 operands[3] = GEN_INT (len);
3273 return "{depi|depwi} -1,%2,%3,%0";
3276 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3277 storing the result in operands[0]. */
3278 const char *
3279 pa_output_64bit_ior (rtx *operands)
3281 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3282 int bs0, bs1, p, len;
3284 if (INTVAL (operands[2]) == 0)
3285 return "copy %1,%0";
3287 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3288 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3289 break;
3291 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3292 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3293 break;
3295 gcc_assert (bs1 == HOST_BITS_PER_WIDE_INT
3296 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
3298 p = 63 - bs0;
3299 len = bs1 - bs0;
3301 operands[2] = GEN_INT (p);
3302 operands[3] = GEN_INT (len);
3303 return "depdi -1,%2,%3,%0";
3306 /* Target hook for assembling integer objects. This code handles
3307 aligned SI and DI integers specially since function references
3308 must be preceded by P%. */
3310 static bool
3311 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3313 bool result;
3314 tree decl = NULL;
3316 /* When we have a SYMBOL_REF with a SYMBOL_REF_DECL, we need to call
3317 call assemble_external and set the SYMBOL_REF_DECL to NULL before
3318 calling output_addr_const. Otherwise, it may call assemble_external
3319 in the midst of outputing the assembler code for the SYMBOL_REF.
3320 We restore the SYMBOL_REF_DECL after the output is done. */
3321 if (GET_CODE (x) == SYMBOL_REF)
3323 decl = SYMBOL_REF_DECL (x);
3324 if (decl)
3326 assemble_external (decl);
3327 SET_SYMBOL_REF_DECL (x, NULL);
3331 if (size == UNITS_PER_WORD
3332 && aligned_p
3333 && function_label_operand (x, VOIDmode))
3335 fputs (size == 8? "\t.dword\t" : "\t.word\t", asm_out_file);
3337 /* We don't want an OPD when generating fast indirect calls. */
3338 if (!TARGET_FAST_INDIRECT_CALLS)
3339 fputs ("P%", asm_out_file);
3341 output_addr_const (asm_out_file, x);
3342 fputc ('\n', asm_out_file);
3343 result = true;
3345 else
3346 result = default_assemble_integer (x, size, aligned_p);
3348 if (decl)
3349 SET_SYMBOL_REF_DECL (x, decl);
3351 return result;
3354 /* Output an ascii string. */
3355 void
3356 pa_output_ascii (FILE *file, const char *p, int size)
3358 int i;
3359 int chars_output;
3360 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3362 /* The HP assembler can only take strings of 256 characters at one
3363 time. This is a limitation on input line length, *not* the
3364 length of the string. Sigh. Even worse, it seems that the
3365 restriction is in number of input characters (see \xnn &
3366 \whatever). So we have to do this very carefully. */
3368 fputs ("\t.STRING \"", file);
3370 chars_output = 0;
3371 for (i = 0; i < size; i += 4)
3373 int co = 0;
3374 int io = 0;
3375 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3377 register unsigned int c = (unsigned char) p[i + io];
3379 if (c == '\"' || c == '\\')
3380 partial_output[co++] = '\\';
3381 if (c >= ' ' && c < 0177)
3382 partial_output[co++] = c;
3383 else
3385 unsigned int hexd;
3386 partial_output[co++] = '\\';
3387 partial_output[co++] = 'x';
3388 hexd = c / 16 - 0 + '0';
3389 if (hexd > '9')
3390 hexd -= '9' - 'a' + 1;
3391 partial_output[co++] = hexd;
3392 hexd = c % 16 - 0 + '0';
3393 if (hexd > '9')
3394 hexd -= '9' - 'a' + 1;
3395 partial_output[co++] = hexd;
3398 if (chars_output + co > 243)
3400 fputs ("\"\n\t.STRING \"", file);
3401 chars_output = 0;
3403 fwrite (partial_output, 1, (size_t) co, file);
3404 chars_output += co;
3405 co = 0;
3407 fputs ("\"\n", file);
3410 /* Try to rewrite floating point comparisons & branches to avoid
3411 useless add,tr insns.
3413 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3414 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3415 first attempt to remove useless add,tr insns. It is zero
3416 for the second pass as reorg sometimes leaves bogus REG_DEAD
3417 notes lying around.
3419 When CHECK_NOTES is zero we can only eliminate add,tr insns
3420 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3421 instructions. */
3422 static void
3423 remove_useless_addtr_insns (int check_notes)
3425 rtx_insn *insn;
3426 static int pass = 0;
3428 /* This is fairly cheap, so always run it when optimizing. */
3429 if (optimize > 0)
3431 int fcmp_count = 0;
3432 int fbranch_count = 0;
3434 /* Walk all the insns in this function looking for fcmp & fbranch
3435 instructions. Keep track of how many of each we find. */
3436 for (insn = get_insns (); insn; insn = next_insn (insn))
3438 rtx tmp;
3440 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3441 if (! NONJUMP_INSN_P (insn) && ! JUMP_P (insn))
3442 continue;
3444 tmp = PATTERN (insn);
3446 /* It must be a set. */
3447 if (GET_CODE (tmp) != SET)
3448 continue;
3450 /* If the destination is CCFP, then we've found an fcmp insn. */
3451 tmp = SET_DEST (tmp);
3452 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3454 fcmp_count++;
3455 continue;
3458 tmp = PATTERN (insn);
3459 /* If this is an fbranch instruction, bump the fbranch counter. */
3460 if (GET_CODE (tmp) == SET
3461 && SET_DEST (tmp) == pc_rtx
3462 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3463 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3464 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3465 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3467 fbranch_count++;
3468 continue;
3473 /* Find all floating point compare + branch insns. If possible,
3474 reverse the comparison & the branch to avoid add,tr insns. */
3475 for (insn = get_insns (); insn; insn = next_insn (insn))
3477 rtx tmp;
3478 rtx_insn *next;
3480 /* Ignore anything that isn't an INSN. */
3481 if (! NONJUMP_INSN_P (insn))
3482 continue;
3484 tmp = PATTERN (insn);
3486 /* It must be a set. */
3487 if (GET_CODE (tmp) != SET)
3488 continue;
3490 /* The destination must be CCFP, which is register zero. */
3491 tmp = SET_DEST (tmp);
3492 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3493 continue;
3495 /* INSN should be a set of CCFP.
3497 See if the result of this insn is used in a reversed FP
3498 conditional branch. If so, reverse our condition and
3499 the branch. Doing so avoids useless add,tr insns. */
3500 next = next_insn (insn);
3501 while (next)
3503 /* Jumps, calls and labels stop our search. */
3504 if (JUMP_P (next) || CALL_P (next) || LABEL_P (next))
3505 break;
3507 /* As does another fcmp insn. */
3508 if (NONJUMP_INSN_P (next)
3509 && GET_CODE (PATTERN (next)) == SET
3510 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3511 && REGNO (SET_DEST (PATTERN (next))) == 0)
3512 break;
3514 next = next_insn (next);
3517 /* Is NEXT_INSN a branch? */
3518 if (next && JUMP_P (next))
3520 rtx pattern = PATTERN (next);
3522 /* If it a reversed fp conditional branch (e.g. uses add,tr)
3523 and CCFP dies, then reverse our conditional and the branch
3524 to avoid the add,tr. */
3525 if (GET_CODE (pattern) == SET
3526 && SET_DEST (pattern) == pc_rtx
3527 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3528 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3529 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3530 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3531 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3532 && (fcmp_count == fbranch_count
3533 || (check_notes
3534 && find_regno_note (next, REG_DEAD, 0))))
3536 /* Reverse the branch. */
3537 tmp = XEXP (SET_SRC (pattern), 1);
3538 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3539 XEXP (SET_SRC (pattern), 2) = tmp;
3540 INSN_CODE (next) = -1;
3542 /* Reverse our condition. */
3543 tmp = PATTERN (insn);
3544 PUT_CODE (XEXP (tmp, 1),
3545 (reverse_condition_maybe_unordered
3546 (GET_CODE (XEXP (tmp, 1)))));
3552 pass = !pass;
3556 /* You may have trouble believing this, but this is the 32 bit HP-PA
3557 stack layout. Wow.
3559 Offset Contents
3561 Variable arguments (optional; any number may be allocated)
3563 SP-(4*(N+9)) arg word N
3565 SP-56 arg word 5
3566 SP-52 arg word 4
3568 Fixed arguments (must be allocated; may remain unused)
3570 SP-48 arg word 3
3571 SP-44 arg word 2
3572 SP-40 arg word 1
3573 SP-36 arg word 0
3575 Frame Marker
3577 SP-32 External Data Pointer (DP)
3578 SP-28 External sr4
3579 SP-24 External/stub RP (RP')
3580 SP-20 Current RP
3581 SP-16 Static Link
3582 SP-12 Clean up
3583 SP-8 Calling Stub RP (RP'')
3584 SP-4 Previous SP
3586 Top of Frame
3588 SP-0 Stack Pointer (points to next available address)
3592 /* This function saves registers as follows. Registers marked with ' are
3593 this function's registers (as opposed to the previous function's).
3594 If a frame_pointer isn't needed, r4 is saved as a general register;
3595 the space for the frame pointer is still allocated, though, to keep
3596 things simple.
3599 Top of Frame
3601 SP (FP') Previous FP
3602 SP + 4 Alignment filler (sigh)
3603 SP + 8 Space for locals reserved here.
3607 SP + n All call saved register used.
3611 SP + o All call saved fp registers used.
3615 SP + p (SP') points to next available address.
3619 /* Global variables set by output_function_prologue(). */
3620 /* Size of frame. Need to know this to emit return insns from
3621 leaf procedures. */
3622 static HOST_WIDE_INT actual_fsize, local_fsize;
3623 static int save_fregs;
3625 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3626 Handle case where DISP > 8k by using the add_high_const patterns.
3628 Note in DISP > 8k case, we will leave the high part of the address
3629 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3631 static void
3632 store_reg (int reg, HOST_WIDE_INT disp, int base)
3634 rtx dest, src, basereg;
3635 rtx_insn *insn;
3637 src = gen_rtx_REG (word_mode, reg);
3638 basereg = gen_rtx_REG (Pmode, base);
3639 if (VAL_14_BITS_P (disp))
3641 dest = gen_rtx_MEM (word_mode, plus_constant (Pmode, basereg, disp));
3642 insn = emit_move_insn (dest, src);
3644 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3646 rtx delta = GEN_INT (disp);
3647 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3649 emit_move_insn (tmpreg, delta);
3650 insn = emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3651 if (DO_FRAME_NOTES)
3653 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
3654 gen_rtx_SET (tmpreg,
3655 gen_rtx_PLUS (Pmode, basereg, delta)));
3656 RTX_FRAME_RELATED_P (insn) = 1;
3658 dest = gen_rtx_MEM (word_mode, tmpreg);
3659 insn = emit_move_insn (dest, src);
3661 else
3663 rtx delta = GEN_INT (disp);
3664 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3665 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3667 emit_move_insn (tmpreg, high);
3668 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3669 insn = emit_move_insn (dest, src);
3670 if (DO_FRAME_NOTES)
3671 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
3672 gen_rtx_SET (gen_rtx_MEM (word_mode,
3673 gen_rtx_PLUS (word_mode,
3674 basereg,
3675 delta)),
3676 src));
3679 if (DO_FRAME_NOTES)
3680 RTX_FRAME_RELATED_P (insn) = 1;
3683 /* Emit RTL to store REG at the memory location specified by BASE and then
3684 add MOD to BASE. MOD must be <= 8k. */
3686 static void
3687 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3689 rtx basereg, srcreg, delta;
3690 rtx_insn *insn;
3692 gcc_assert (VAL_14_BITS_P (mod));
3694 basereg = gen_rtx_REG (Pmode, base);
3695 srcreg = gen_rtx_REG (word_mode, reg);
3696 delta = GEN_INT (mod);
3698 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3699 if (DO_FRAME_NOTES)
3701 RTX_FRAME_RELATED_P (insn) = 1;
3703 /* RTX_FRAME_RELATED_P must be set on each frame related set
3704 in a parallel with more than one element. */
3705 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3706 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3710 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
3711 where DISP > 8k by using the add_high_const patterns. NOTE indicates
3712 whether to add a frame note or not.
3714 In the DISP > 8k case, we leave the high part of the address in %r1.
3715 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
3717 static void
3718 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3720 rtx_insn *insn;
3722 if (VAL_14_BITS_P (disp))
3724 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3725 plus_constant (Pmode,
3726 gen_rtx_REG (Pmode, base), disp));
3728 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3730 rtx basereg = gen_rtx_REG (Pmode, base);
3731 rtx delta = GEN_INT (disp);
3732 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3734 emit_move_insn (tmpreg, delta);
3735 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3736 gen_rtx_PLUS (Pmode, tmpreg, basereg));
3737 if (DO_FRAME_NOTES)
3738 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
3739 gen_rtx_SET (tmpreg,
3740 gen_rtx_PLUS (Pmode, basereg, delta)));
3742 else
3744 rtx basereg = gen_rtx_REG (Pmode, base);
3745 rtx delta = GEN_INT (disp);
3746 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3748 emit_move_insn (tmpreg,
3749 gen_rtx_PLUS (Pmode, basereg,
3750 gen_rtx_HIGH (Pmode, delta)));
3751 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3752 gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3755 if (DO_FRAME_NOTES && note)
3756 RTX_FRAME_RELATED_P (insn) = 1;
3759 HOST_WIDE_INT
3760 pa_compute_frame_size (HOST_WIDE_INT size, int *fregs_live)
3762 int freg_saved = 0;
3763 int i, j;
3765 /* The code in pa_expand_prologue and pa_expand_epilogue must
3766 be consistent with the rounding and size calculation done here.
3767 Change them at the same time. */
3769 /* We do our own stack alignment. First, round the size of the
3770 stack locals up to a word boundary. */
3771 size = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3773 /* Space for previous frame pointer + filler. If any frame is
3774 allocated, we need to add in the STARTING_FRAME_OFFSET. We
3775 waste some space here for the sake of HP compatibility. The
3776 first slot is only used when the frame pointer is needed. */
3777 if (size || frame_pointer_needed)
3778 size += STARTING_FRAME_OFFSET;
3780 /* If the current function calls __builtin_eh_return, then we need
3781 to allocate stack space for registers that will hold data for
3782 the exception handler. */
3783 if (DO_FRAME_NOTES && crtl->calls_eh_return)
3785 unsigned int i;
3787 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
3788 continue;
3789 size += i * UNITS_PER_WORD;
3792 /* Account for space used by the callee general register saves. */
3793 for (i = 18, j = frame_pointer_needed ? 4 : 3; i >= j; i--)
3794 if (df_regs_ever_live_p (i))
3795 size += UNITS_PER_WORD;
3797 /* Account for space used by the callee floating point register saves. */
3798 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3799 if (df_regs_ever_live_p (i)
3800 || (!TARGET_64BIT && df_regs_ever_live_p (i + 1)))
3802 freg_saved = 1;
3804 /* We always save both halves of the FP register, so always
3805 increment the frame size by 8 bytes. */
3806 size += 8;
3809 /* If any of the floating registers are saved, account for the
3810 alignment needed for the floating point register save block. */
3811 if (freg_saved)
3813 size = (size + 7) & ~7;
3814 if (fregs_live)
3815 *fregs_live = 1;
3818 /* The various ABIs include space for the outgoing parameters in the
3819 size of the current function's stack frame. We don't need to align
3820 for the outgoing arguments as their alignment is set by the final
3821 rounding for the frame as a whole. */
3822 size += crtl->outgoing_args_size;
3824 /* Allocate space for the fixed frame marker. This space must be
3825 allocated for any function that makes calls or allocates
3826 stack space. */
3827 if (!crtl->is_leaf || size)
3828 size += TARGET_64BIT ? 48 : 32;
3830 /* Finally, round to the preferred stack boundary. */
3831 return ((size + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)
3832 & ~(PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1));
3835 /* On HP-PA, move-double insns between fpu and cpu need an 8-byte block
3836 of memory. If any fpu reg is used in the function, we allocate
3837 such a block here, at the bottom of the frame, just in case it's needed.
3839 If this function is a leaf procedure, then we may choose not
3840 to do a "save" insn. The decision about whether or not
3841 to do this is made in regclass.c. */
3843 static void
3844 pa_output_function_prologue (FILE *file)
3846 /* The function's label and associated .PROC must never be
3847 separated and must be output *after* any profiling declarations
3848 to avoid changing spaces/subspaces within a procedure. */
3849 ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3850 fputs ("\t.PROC\n", file);
3852 /* pa_expand_prologue does the dirty work now. We just need
3853 to output the assembler directives which denote the start
3854 of a function. */
3855 fprintf (file, "\t.CALLINFO FRAME=" HOST_WIDE_INT_PRINT_DEC, actual_fsize);
3856 if (crtl->is_leaf)
3857 fputs (",NO_CALLS", file);
3858 else
3859 fputs (",CALLS", file);
3860 if (rp_saved)
3861 fputs (",SAVE_RP", file);
3863 /* The SAVE_SP flag is used to indicate that register %r3 is stored
3864 at the beginning of the frame and that it is used as the frame
3865 pointer for the frame. We do this because our current frame
3866 layout doesn't conform to that specified in the HP runtime
3867 documentation and we need a way to indicate to programs such as
3868 GDB where %r3 is saved. The SAVE_SP flag was chosen because it
3869 isn't used by HP compilers but is supported by the assembler.
3870 However, SAVE_SP is supposed to indicate that the previous stack
3871 pointer has been saved in the frame marker. */
3872 if (frame_pointer_needed)
3873 fputs (",SAVE_SP", file);
3875 /* Pass on information about the number of callee register saves
3876 performed in the prologue.
3878 The compiler is supposed to pass the highest register number
3879 saved, the assembler then has to adjust that number before
3880 entering it into the unwind descriptor (to account for any
3881 caller saved registers with lower register numbers than the
3882 first callee saved register). */
3883 if (gr_saved)
3884 fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
3886 if (fr_saved)
3887 fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
3889 fputs ("\n\t.ENTRY\n", file);
3891 remove_useless_addtr_insns (0);
3894 void
3895 pa_expand_prologue (void)
3897 int merge_sp_adjust_with_store = 0;
3898 HOST_WIDE_INT size = get_frame_size ();
3899 HOST_WIDE_INT offset;
3900 int i;
3901 rtx tmpreg;
3902 rtx_insn *insn;
3904 gr_saved = 0;
3905 fr_saved = 0;
3906 save_fregs = 0;
3908 /* Compute total size for frame pointer, filler, locals and rounding to
3909 the next word boundary. Similar code appears in pa_compute_frame_size
3910 and must be changed in tandem with this code. */
3911 local_fsize = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3912 if (local_fsize || frame_pointer_needed)
3913 local_fsize += STARTING_FRAME_OFFSET;
3915 actual_fsize = pa_compute_frame_size (size, &save_fregs);
3916 if (flag_stack_usage_info)
3917 current_function_static_stack_size = actual_fsize;
3919 /* Compute a few things we will use often. */
3920 tmpreg = gen_rtx_REG (word_mode, 1);
3922 /* Save RP first. The calling conventions manual states RP will
3923 always be stored into the caller's frame at sp - 20 or sp - 16
3924 depending on which ABI is in use. */
3925 if (df_regs_ever_live_p (2) || crtl->calls_eh_return)
3927 store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM);
3928 rp_saved = true;
3930 else
3931 rp_saved = false;
3933 /* Allocate the local frame and set up the frame pointer if needed. */
3934 if (actual_fsize != 0)
3936 if (frame_pointer_needed)
3938 /* Copy the old frame pointer temporarily into %r1. Set up the
3939 new stack pointer, then store away the saved old frame pointer
3940 into the stack at sp and at the same time update the stack
3941 pointer by actual_fsize bytes. Two versions, first
3942 handles small (<8k) frames. The second handles large (>=8k)
3943 frames. */
3944 insn = emit_move_insn (tmpreg, hard_frame_pointer_rtx);
3945 if (DO_FRAME_NOTES)
3946 RTX_FRAME_RELATED_P (insn) = 1;
3948 insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
3949 if (DO_FRAME_NOTES)
3950 RTX_FRAME_RELATED_P (insn) = 1;
3952 if (VAL_14_BITS_P (actual_fsize))
3953 store_reg_modify (STACK_POINTER_REGNUM, 1, actual_fsize);
3954 else
3956 /* It is incorrect to store the saved frame pointer at *sp,
3957 then increment sp (writes beyond the current stack boundary).
3959 So instead use stwm to store at *sp and post-increment the
3960 stack pointer as an atomic operation. Then increment sp to
3961 finish allocating the new frame. */
3962 HOST_WIDE_INT adjust1 = 8192 - 64;
3963 HOST_WIDE_INT adjust2 = actual_fsize - adjust1;
3965 store_reg_modify (STACK_POINTER_REGNUM, 1, adjust1);
3966 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3967 adjust2, 1);
3970 /* We set SAVE_SP in frames that need a frame pointer. Thus,
3971 we need to store the previous stack pointer (frame pointer)
3972 into the frame marker on targets that use the HP unwind
3973 library. This allows the HP unwind library to be used to
3974 unwind GCC frames. However, we are not fully compatible
3975 with the HP library because our frame layout differs from
3976 that specified in the HP runtime specification.
3978 We don't want a frame note on this instruction as the frame
3979 marker moves during dynamic stack allocation.
3981 This instruction also serves as a blockage to prevent
3982 register spills from being scheduled before the stack
3983 pointer is raised. This is necessary as we store
3984 registers using the frame pointer as a base register,
3985 and the frame pointer is set before sp is raised. */
3986 if (TARGET_HPUX_UNWIND_LIBRARY)
3988 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx,
3989 GEN_INT (TARGET_64BIT ? -8 : -4));
3991 emit_move_insn (gen_rtx_MEM (word_mode, addr),
3992 hard_frame_pointer_rtx);
3994 else
3995 emit_insn (gen_blockage ());
3997 /* no frame pointer needed. */
3998 else
4000 /* In some cases we can perform the first callee register save
4001 and allocating the stack frame at the same time. If so, just
4002 make a note of it and defer allocating the frame until saving
4003 the callee registers. */
4004 if (VAL_14_BITS_P (actual_fsize) && local_fsize == 0)
4005 merge_sp_adjust_with_store = 1;
4006 /* Can not optimize. Adjust the stack frame by actual_fsize
4007 bytes. */
4008 else
4009 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4010 actual_fsize, 1);
4014 /* Normal register save.
4016 Do not save the frame pointer in the frame_pointer_needed case. It
4017 was done earlier. */
4018 if (frame_pointer_needed)
4020 offset = local_fsize;
4022 /* Saving the EH return data registers in the frame is the simplest
4023 way to get the frame unwind information emitted. We put them
4024 just before the general registers. */
4025 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4027 unsigned int i, regno;
4029 for (i = 0; ; ++i)
4031 regno = EH_RETURN_DATA_REGNO (i);
4032 if (regno == INVALID_REGNUM)
4033 break;
4035 store_reg (regno, offset, HARD_FRAME_POINTER_REGNUM);
4036 offset += UNITS_PER_WORD;
4040 for (i = 18; i >= 4; i--)
4041 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
4043 store_reg (i, offset, HARD_FRAME_POINTER_REGNUM);
4044 offset += UNITS_PER_WORD;
4045 gr_saved++;
4047 /* Account for %r3 which is saved in a special place. */
4048 gr_saved++;
4050 /* No frame pointer needed. */
4051 else
4053 offset = local_fsize - actual_fsize;
4055 /* Saving the EH return data registers in the frame is the simplest
4056 way to get the frame unwind information emitted. */
4057 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4059 unsigned int i, regno;
4061 for (i = 0; ; ++i)
4063 regno = EH_RETURN_DATA_REGNO (i);
4064 if (regno == INVALID_REGNUM)
4065 break;
4067 /* If merge_sp_adjust_with_store is nonzero, then we can
4068 optimize the first save. */
4069 if (merge_sp_adjust_with_store)
4071 store_reg_modify (STACK_POINTER_REGNUM, regno, -offset);
4072 merge_sp_adjust_with_store = 0;
4074 else
4075 store_reg (regno, offset, STACK_POINTER_REGNUM);
4076 offset += UNITS_PER_WORD;
4080 for (i = 18; i >= 3; i--)
4081 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
4083 /* If merge_sp_adjust_with_store is nonzero, then we can
4084 optimize the first GR save. */
4085 if (merge_sp_adjust_with_store)
4087 store_reg_modify (STACK_POINTER_REGNUM, i, -offset);
4088 merge_sp_adjust_with_store = 0;
4090 else
4091 store_reg (i, offset, STACK_POINTER_REGNUM);
4092 offset += UNITS_PER_WORD;
4093 gr_saved++;
4096 /* If we wanted to merge the SP adjustment with a GR save, but we never
4097 did any GR saves, then just emit the adjustment here. */
4098 if (merge_sp_adjust_with_store)
4099 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4100 actual_fsize, 1);
4103 /* The hppa calling conventions say that %r19, the pic offset
4104 register, is saved at sp - 32 (in this function's frame)
4105 when generating PIC code. FIXME: What is the correct thing
4106 to do for functions which make no calls and allocate no
4107 frame? Do we need to allocate a frame, or can we just omit
4108 the save? For now we'll just omit the save.
4110 We don't want a note on this insn as the frame marker can
4111 move if there is a dynamic stack allocation. */
4112 if (flag_pic && actual_fsize != 0 && !TARGET_64BIT)
4114 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx, GEN_INT (-32));
4116 emit_move_insn (gen_rtx_MEM (word_mode, addr), pic_offset_table_rtx);
4120 /* Align pointer properly (doubleword boundary). */
4121 offset = (offset + 7) & ~7;
4123 /* Floating point register store. */
4124 if (save_fregs)
4126 rtx base;
4128 /* First get the frame or stack pointer to the start of the FP register
4129 save area. */
4130 if (frame_pointer_needed)
4132 set_reg_plus_d (1, HARD_FRAME_POINTER_REGNUM, offset, 0);
4133 base = hard_frame_pointer_rtx;
4135 else
4137 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4138 base = stack_pointer_rtx;
4141 /* Now actually save the FP registers. */
4142 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4144 if (df_regs_ever_live_p (i)
4145 || (! TARGET_64BIT && df_regs_ever_live_p (i + 1)))
4147 rtx addr, reg;
4148 rtx_insn *insn;
4149 addr = gen_rtx_MEM (DFmode,
4150 gen_rtx_POST_INC (word_mode, tmpreg));
4151 reg = gen_rtx_REG (DFmode, i);
4152 insn = emit_move_insn (addr, reg);
4153 if (DO_FRAME_NOTES)
4155 RTX_FRAME_RELATED_P (insn) = 1;
4156 if (TARGET_64BIT)
4158 rtx mem = gen_rtx_MEM (DFmode,
4159 plus_constant (Pmode, base,
4160 offset));
4161 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
4162 gen_rtx_SET (mem, reg));
4164 else
4166 rtx meml = gen_rtx_MEM (SFmode,
4167 plus_constant (Pmode, base,
4168 offset));
4169 rtx memr = gen_rtx_MEM (SFmode,
4170 plus_constant (Pmode, base,
4171 offset + 4));
4172 rtx regl = gen_rtx_REG (SFmode, i);
4173 rtx regr = gen_rtx_REG (SFmode, i + 1);
4174 rtx setl = gen_rtx_SET (meml, regl);
4175 rtx setr = gen_rtx_SET (memr, regr);
4176 rtvec vec;
4178 RTX_FRAME_RELATED_P (setl) = 1;
4179 RTX_FRAME_RELATED_P (setr) = 1;
4180 vec = gen_rtvec (2, setl, setr);
4181 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
4182 gen_rtx_SEQUENCE (VOIDmode, vec));
4185 offset += GET_MODE_SIZE (DFmode);
4186 fr_saved++;
4192 /* Emit RTL to load REG from the memory location specified by BASE+DISP.
4193 Handle case where DISP > 8k by using the add_high_const patterns. */
4195 static void
4196 load_reg (int reg, HOST_WIDE_INT disp, int base)
4198 rtx dest = gen_rtx_REG (word_mode, reg);
4199 rtx basereg = gen_rtx_REG (Pmode, base);
4200 rtx src;
4202 if (VAL_14_BITS_P (disp))
4203 src = gen_rtx_MEM (word_mode, plus_constant (Pmode, basereg, disp));
4204 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
4206 rtx delta = GEN_INT (disp);
4207 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4209 emit_move_insn (tmpreg, delta);
4210 if (TARGET_DISABLE_INDEXING)
4212 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4213 src = gen_rtx_MEM (word_mode, tmpreg);
4215 else
4216 src = gen_rtx_MEM (word_mode, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4218 else
4220 rtx delta = GEN_INT (disp);
4221 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
4222 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4224 emit_move_insn (tmpreg, high);
4225 src = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
4228 emit_move_insn (dest, src);
4231 /* Update the total code bytes output to the text section. */
4233 static void
4234 update_total_code_bytes (unsigned int nbytes)
4236 if ((TARGET_PORTABLE_RUNTIME || !TARGET_GAS || !TARGET_SOM)
4237 && !IN_NAMED_SECTION_P (cfun->decl))
4239 unsigned int old_total = total_code_bytes;
4241 total_code_bytes += nbytes;
4243 /* Be prepared to handle overflows. */
4244 if (old_total > total_code_bytes)
4245 total_code_bytes = UINT_MAX;
4249 /* This function generates the assembly code for function exit.
4250 Args are as for output_function_prologue ().
4252 The function epilogue should not depend on the current stack
4253 pointer! It should use the frame pointer only. This is mandatory
4254 because of alloca; we also take advantage of it to omit stack
4255 adjustments before returning. */
4257 static void
4258 pa_output_function_epilogue (FILE *file)
4260 rtx_insn *insn = get_last_insn ();
4261 bool extra_nop;
4263 /* pa_expand_epilogue does the dirty work now. We just need
4264 to output the assembler directives which denote the end
4265 of a function.
4267 To make debuggers happy, emit a nop if the epilogue was completely
4268 eliminated due to a volatile call as the last insn in the
4269 current function. That way the return address (in %r2) will
4270 always point to a valid instruction in the current function. */
4272 /* Get the last real insn. */
4273 if (NOTE_P (insn))
4274 insn = prev_real_insn (insn);
4276 /* If it is a sequence, then look inside. */
4277 if (insn && NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
4278 insn = as_a <rtx_sequence *> (PATTERN (insn))-> insn (0);
4280 /* If insn is a CALL_INSN, then it must be a call to a volatile
4281 function (otherwise there would be epilogue insns). */
4282 if (insn && CALL_P (insn))
4284 fputs ("\tnop\n", file);
4285 extra_nop = true;
4287 else
4288 extra_nop = false;
4290 fputs ("\t.EXIT\n\t.PROCEND\n", file);
4292 if (TARGET_SOM && TARGET_GAS)
4294 /* We are done with this subspace except possibly for some additional
4295 debug information. Forget that we are in this subspace to ensure
4296 that the next function is output in its own subspace. */
4297 in_section = NULL;
4298 cfun->machine->in_nsubspa = 2;
4301 /* Thunks do their own insn accounting. */
4302 if (cfun->is_thunk)
4303 return;
4305 if (INSN_ADDRESSES_SET_P ())
4307 last_address = extra_nop ? 4 : 0;
4308 insn = get_last_nonnote_insn ();
4309 if (insn)
4311 last_address += INSN_ADDRESSES (INSN_UID (insn));
4312 if (INSN_P (insn))
4313 last_address += insn_default_length (insn);
4315 last_address = ((last_address + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
4316 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
4318 else
4319 last_address = UINT_MAX;
4321 /* Finally, update the total number of code bytes output so far. */
4322 update_total_code_bytes (last_address);
4325 void
4326 pa_expand_epilogue (void)
4328 rtx tmpreg;
4329 HOST_WIDE_INT offset;
4330 HOST_WIDE_INT ret_off = 0;
4331 int i;
4332 int merge_sp_adjust_with_load = 0;
4334 /* We will use this often. */
4335 tmpreg = gen_rtx_REG (word_mode, 1);
4337 /* Try to restore RP early to avoid load/use interlocks when
4338 RP gets used in the return (bv) instruction. This appears to still
4339 be necessary even when we schedule the prologue and epilogue. */
4340 if (rp_saved)
4342 ret_off = TARGET_64BIT ? -16 : -20;
4343 if (frame_pointer_needed)
4345 load_reg (2, ret_off, HARD_FRAME_POINTER_REGNUM);
4346 ret_off = 0;
4348 else
4350 /* No frame pointer, and stack is smaller than 8k. */
4351 if (VAL_14_BITS_P (ret_off - actual_fsize))
4353 load_reg (2, ret_off - actual_fsize, STACK_POINTER_REGNUM);
4354 ret_off = 0;
4359 /* General register restores. */
4360 if (frame_pointer_needed)
4362 offset = local_fsize;
4364 /* If the current function calls __builtin_eh_return, then we need
4365 to restore the saved EH data registers. */
4366 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4368 unsigned int i, regno;
4370 for (i = 0; ; ++i)
4372 regno = EH_RETURN_DATA_REGNO (i);
4373 if (regno == INVALID_REGNUM)
4374 break;
4376 load_reg (regno, offset, HARD_FRAME_POINTER_REGNUM);
4377 offset += UNITS_PER_WORD;
4381 for (i = 18; i >= 4; i--)
4382 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
4384 load_reg (i, offset, HARD_FRAME_POINTER_REGNUM);
4385 offset += UNITS_PER_WORD;
4388 else
4390 offset = local_fsize - actual_fsize;
4392 /* If the current function calls __builtin_eh_return, then we need
4393 to restore the saved EH data registers. */
4394 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4396 unsigned int i, regno;
4398 for (i = 0; ; ++i)
4400 regno = EH_RETURN_DATA_REGNO (i);
4401 if (regno == INVALID_REGNUM)
4402 break;
4404 /* Only for the first load.
4405 merge_sp_adjust_with_load holds the register load
4406 with which we will merge the sp adjustment. */
4407 if (merge_sp_adjust_with_load == 0
4408 && local_fsize == 0
4409 && VAL_14_BITS_P (-actual_fsize))
4410 merge_sp_adjust_with_load = regno;
4411 else
4412 load_reg (regno, offset, STACK_POINTER_REGNUM);
4413 offset += UNITS_PER_WORD;
4417 for (i = 18; i >= 3; i--)
4419 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
4421 /* Only for the first load.
4422 merge_sp_adjust_with_load holds the register load
4423 with which we will merge the sp adjustment. */
4424 if (merge_sp_adjust_with_load == 0
4425 && local_fsize == 0
4426 && VAL_14_BITS_P (-actual_fsize))
4427 merge_sp_adjust_with_load = i;
4428 else
4429 load_reg (i, offset, STACK_POINTER_REGNUM);
4430 offset += UNITS_PER_WORD;
4435 /* Align pointer properly (doubleword boundary). */
4436 offset = (offset + 7) & ~7;
4438 /* FP register restores. */
4439 if (save_fregs)
4441 /* Adjust the register to index off of. */
4442 if (frame_pointer_needed)
4443 set_reg_plus_d (1, HARD_FRAME_POINTER_REGNUM, offset, 0);
4444 else
4445 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4447 /* Actually do the restores now. */
4448 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4449 if (df_regs_ever_live_p (i)
4450 || (! TARGET_64BIT && df_regs_ever_live_p (i + 1)))
4452 rtx src = gen_rtx_MEM (DFmode,
4453 gen_rtx_POST_INC (word_mode, tmpreg));
4454 rtx dest = gen_rtx_REG (DFmode, i);
4455 emit_move_insn (dest, src);
4459 /* Emit a blockage insn here to keep these insns from being moved to
4460 an earlier spot in the epilogue, or into the main instruction stream.
4462 This is necessary as we must not cut the stack back before all the
4463 restores are finished. */
4464 emit_insn (gen_blockage ());
4466 /* Reset stack pointer (and possibly frame pointer). The stack
4467 pointer is initially set to fp + 64 to avoid a race condition. */
4468 if (frame_pointer_needed)
4470 rtx delta = GEN_INT (-64);
4472 set_reg_plus_d (STACK_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM, 64, 0);
4473 emit_insn (gen_pre_load (hard_frame_pointer_rtx,
4474 stack_pointer_rtx, delta));
4476 /* If we were deferring a callee register restore, do it now. */
4477 else if (merge_sp_adjust_with_load)
4479 rtx delta = GEN_INT (-actual_fsize);
4480 rtx dest = gen_rtx_REG (word_mode, merge_sp_adjust_with_load);
4482 emit_insn (gen_pre_load (dest, stack_pointer_rtx, delta));
4484 else if (actual_fsize != 0)
4485 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4486 - actual_fsize, 0);
4488 /* If we haven't restored %r2 yet (no frame pointer, and a stack
4489 frame greater than 8k), do so now. */
4490 if (ret_off != 0)
4491 load_reg (2, ret_off, STACK_POINTER_REGNUM);
4493 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4495 rtx sa = EH_RETURN_STACKADJ_RTX;
4497 emit_insn (gen_blockage ());
4498 emit_insn (TARGET_64BIT
4499 ? gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, sa)
4500 : gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, sa));
4504 bool
4505 pa_can_use_return_insn (void)
4507 if (!reload_completed)
4508 return false;
4510 if (frame_pointer_needed)
4511 return false;
4513 if (df_regs_ever_live_p (2))
4514 return false;
4516 if (crtl->profile)
4517 return false;
4519 return pa_compute_frame_size (get_frame_size (), 0) == 0;
4523 hppa_pic_save_rtx (void)
4525 return get_hard_reg_initial_val (word_mode, PIC_OFFSET_TABLE_REGNUM);
4528 #ifndef NO_DEFERRED_PROFILE_COUNTERS
4529 #define NO_DEFERRED_PROFILE_COUNTERS 0
4530 #endif
4533 /* Vector of funcdef numbers. */
4534 static vec<int> funcdef_nos;
4536 /* Output deferred profile counters. */
4537 static void
4538 output_deferred_profile_counters (void)
4540 unsigned int i;
4541 int align, n;
4543 if (funcdef_nos.is_empty ())
4544 return;
4546 switch_to_section (data_section);
4547 align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
4548 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
4550 for (i = 0; funcdef_nos.iterate (i, &n); i++)
4552 targetm.asm_out.internal_label (asm_out_file, "LP", n);
4553 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, align, 1);
4556 funcdef_nos.release ();
4559 void
4560 hppa_profile_hook (int label_no)
4562 /* We use SImode for the address of the function in both 32 and
4563 64-bit code to avoid having to provide DImode versions of the
4564 lcla2 and load_offset_label_address insn patterns. */
4565 rtx reg = gen_reg_rtx (SImode);
4566 rtx_code_label *label_rtx = gen_label_rtx ();
4567 rtx mcount = gen_rtx_MEM (Pmode, gen_rtx_SYMBOL_REF (Pmode, "_mcount"));
4568 int reg_parm_stack_space = REG_PARM_STACK_SPACE (NULL_TREE);
4569 rtx arg_bytes, begin_label_rtx;
4570 rtx_insn *call_insn;
4571 char begin_label_name[16];
4572 bool use_mcount_pcrel_call;
4574 /* If we can reach _mcount with a pc-relative call, we can optimize
4575 loading the address of the current function. This requires linker
4576 long branch stub support. */
4577 if (!TARGET_PORTABLE_RUNTIME
4578 && !TARGET_LONG_CALLS
4579 && (TARGET_SOM || flag_function_sections))
4580 use_mcount_pcrel_call = TRUE;
4581 else
4582 use_mcount_pcrel_call = FALSE;
4584 ASM_GENERATE_INTERNAL_LABEL (begin_label_name, FUNC_BEGIN_PROLOG_LABEL,
4585 label_no);
4586 begin_label_rtx = gen_rtx_SYMBOL_REF (SImode, ggc_strdup (begin_label_name));
4588 emit_move_insn (gen_rtx_REG (word_mode, 26), gen_rtx_REG (word_mode, 2));
4590 if (!use_mcount_pcrel_call)
4592 /* The address of the function is loaded into %r25 with an instruction-
4593 relative sequence that avoids the use of relocations. The sequence
4594 is split so that the load_offset_label_address instruction can
4595 occupy the delay slot of the call to _mcount. */
4596 if (TARGET_PA_20)
4597 emit_insn (gen_lcla2 (reg, label_rtx));
4598 else
4599 emit_insn (gen_lcla1 (reg, label_rtx));
4601 emit_insn (gen_load_offset_label_address (gen_rtx_REG (SImode, 25),
4602 reg,
4603 begin_label_rtx,
4604 label_rtx));
4607 if (!NO_DEFERRED_PROFILE_COUNTERS)
4609 rtx count_label_rtx, addr, r24;
4610 char count_label_name[16];
4612 funcdef_nos.safe_push (label_no);
4613 ASM_GENERATE_INTERNAL_LABEL (count_label_name, "LP", label_no);
4614 count_label_rtx = gen_rtx_SYMBOL_REF (Pmode,
4615 ggc_strdup (count_label_name));
4617 addr = force_reg (Pmode, count_label_rtx);
4618 r24 = gen_rtx_REG (Pmode, 24);
4619 emit_move_insn (r24, addr);
4621 arg_bytes = GEN_INT (TARGET_64BIT ? 24 : 12);
4622 if (use_mcount_pcrel_call)
4623 call_insn = emit_call_insn (gen_call_mcount (mcount, arg_bytes,
4624 begin_label_rtx));
4625 else
4626 call_insn = emit_call_insn (gen_call (mcount, arg_bytes));
4628 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), r24);
4630 else
4632 arg_bytes = GEN_INT (TARGET_64BIT ? 16 : 8);
4633 if (use_mcount_pcrel_call)
4634 call_insn = emit_call_insn (gen_call_mcount (mcount, arg_bytes,
4635 begin_label_rtx));
4636 else
4637 call_insn = emit_call_insn (gen_call (mcount, arg_bytes));
4640 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 25));
4641 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 26));
4643 /* Indicate the _mcount call cannot throw, nor will it execute a
4644 non-local goto. */
4645 make_reg_eh_region_note_nothrow_nononlocal (call_insn);
4647 /* Allocate space for fixed arguments. */
4648 if (reg_parm_stack_space > crtl->outgoing_args_size)
4649 crtl->outgoing_args_size = reg_parm_stack_space;
4652 /* Fetch the return address for the frame COUNT steps up from
4653 the current frame, after the prologue. FRAMEADDR is the
4654 frame pointer of the COUNT frame.
4656 We want to ignore any export stub remnants here. To handle this,
4657 we examine the code at the return address, and if it is an export
4658 stub, we return a memory rtx for the stub return address stored
4659 at frame-24.
4661 The value returned is used in two different ways:
4663 1. To find a function's caller.
4665 2. To change the return address for a function.
4667 This function handles most instances of case 1; however, it will
4668 fail if there are two levels of stubs to execute on the return
4669 path. The only way I believe that can happen is if the return value
4670 needs a parameter relocation, which never happens for C code.
4672 This function handles most instances of case 2; however, it will
4673 fail if we did not originally have stub code on the return path
4674 but will need stub code on the new return path. This can happen if
4675 the caller & callee are both in the main program, but the new
4676 return location is in a shared library. */
4679 pa_return_addr_rtx (int count, rtx frameaddr)
4681 rtx label;
4682 rtx rp;
4683 rtx saved_rp;
4684 rtx ins;
4686 /* The instruction stream at the return address of a PA1.X export stub is:
4688 0x4bc23fd1 | stub+8: ldw -18(sr0,sp),rp
4689 0x004010a1 | stub+12: ldsid (sr0,rp),r1
4690 0x00011820 | stub+16: mtsp r1,sr0
4691 0xe0400002 | stub+20: be,n 0(sr0,rp)
4693 0xe0400002 must be specified as -532676606 so that it won't be
4694 rejected as an invalid immediate operand on 64-bit hosts.
4696 The instruction stream at the return address of a PA2.0 export stub is:
4698 0x4bc23fd1 | stub+8: ldw -18(sr0,sp),rp
4699 0xe840d002 | stub+12: bve,n (rp)
4702 HOST_WIDE_INT insns[4];
4703 int i, len;
4705 if (count != 0)
4706 return NULL_RTX;
4708 rp = get_hard_reg_initial_val (Pmode, 2);
4710 if (TARGET_64BIT || TARGET_NO_SPACE_REGS)
4711 return rp;
4713 /* If there is no export stub then just use the value saved from
4714 the return pointer register. */
4716 saved_rp = gen_reg_rtx (Pmode);
4717 emit_move_insn (saved_rp, rp);
4719 /* Get pointer to the instruction stream. We have to mask out the
4720 privilege level from the two low order bits of the return address
4721 pointer here so that ins will point to the start of the first
4722 instruction that would have been executed if we returned. */
4723 ins = copy_to_reg (gen_rtx_AND (Pmode, rp, MASK_RETURN_ADDR));
4724 label = gen_label_rtx ();
4726 if (TARGET_PA_20)
4728 insns[0] = 0x4bc23fd1;
4729 insns[1] = -398405630;
4730 len = 2;
4732 else
4734 insns[0] = 0x4bc23fd1;
4735 insns[1] = 0x004010a1;
4736 insns[2] = 0x00011820;
4737 insns[3] = -532676606;
4738 len = 4;
4741 /* Check the instruction stream at the normal return address for the
4742 export stub. If it is an export stub, than our return address is
4743 really in -24[frameaddr]. */
4745 for (i = 0; i < len; i++)
4747 rtx op0 = gen_rtx_MEM (SImode, plus_constant (Pmode, ins, i * 4));
4748 rtx op1 = GEN_INT (insns[i]);
4749 emit_cmp_and_jump_insns (op0, op1, NE, NULL, SImode, 0, label);
4752 /* Here we know that our return address points to an export
4753 stub. We don't want to return the address of the export stub,
4754 but rather the return address of the export stub. That return
4755 address is stored at -24[frameaddr]. */
4757 emit_move_insn (saved_rp,
4758 gen_rtx_MEM (Pmode,
4759 memory_address (Pmode,
4760 plus_constant (Pmode, frameaddr,
4761 -24))));
4763 emit_label (label);
4765 return saved_rp;
4768 void
4769 pa_emit_bcond_fp (rtx operands[])
4771 enum rtx_code code = GET_CODE (operands[0]);
4772 rtx operand0 = operands[1];
4773 rtx operand1 = operands[2];
4774 rtx label = operands[3];
4776 emit_insn (gen_rtx_SET (gen_rtx_REG (CCFPmode, 0),
4777 gen_rtx_fmt_ee (code, CCFPmode, operand0, operand1)));
4779 emit_jump_insn (gen_rtx_SET (pc_rtx,
4780 gen_rtx_IF_THEN_ELSE (VOIDmode,
4781 gen_rtx_fmt_ee (NE,
4782 VOIDmode,
4783 gen_rtx_REG (CCFPmode, 0),
4784 const0_rtx),
4785 gen_rtx_LABEL_REF (VOIDmode, label),
4786 pc_rtx)));
4790 /* Adjust the cost of a scheduling dependency. Return the new cost of
4791 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
4793 static int
4794 pa_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep_insn, int cost,
4795 unsigned int)
4797 enum attr_type attr_type;
4799 /* Don't adjust costs for a pa8000 chip, also do not adjust any
4800 true dependencies as they are described with bypasses now. */
4801 if (pa_cpu >= PROCESSOR_8000 || dep_type == 0)
4802 return cost;
4804 if (! recog_memoized (insn))
4805 return 0;
4807 attr_type = get_attr_type (insn);
4809 switch (dep_type)
4811 case REG_DEP_ANTI:
4812 /* Anti dependency; DEP_INSN reads a register that INSN writes some
4813 cycles later. */
4815 if (attr_type == TYPE_FPLOAD)
4817 rtx pat = PATTERN (insn);
4818 rtx dep_pat = PATTERN (dep_insn);
4819 if (GET_CODE (pat) == PARALLEL)
4821 /* This happens for the fldXs,mb patterns. */
4822 pat = XVECEXP (pat, 0, 0);
4824 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4825 /* If this happens, we have to extend this to schedule
4826 optimally. Return 0 for now. */
4827 return 0;
4829 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4831 if (! recog_memoized (dep_insn))
4832 return 0;
4833 switch (get_attr_type (dep_insn))
4835 case TYPE_FPALU:
4836 case TYPE_FPMULSGL:
4837 case TYPE_FPMULDBL:
4838 case TYPE_FPDIVSGL:
4839 case TYPE_FPDIVDBL:
4840 case TYPE_FPSQRTSGL:
4841 case TYPE_FPSQRTDBL:
4842 /* A fpload can't be issued until one cycle before a
4843 preceding arithmetic operation has finished if
4844 the target of the fpload is any of the sources
4845 (or destination) of the arithmetic operation. */
4846 return insn_default_latency (dep_insn) - 1;
4848 default:
4849 return 0;
4853 else if (attr_type == TYPE_FPALU)
4855 rtx pat = PATTERN (insn);
4856 rtx dep_pat = PATTERN (dep_insn);
4857 if (GET_CODE (pat) == PARALLEL)
4859 /* This happens for the fldXs,mb patterns. */
4860 pat = XVECEXP (pat, 0, 0);
4862 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4863 /* If this happens, we have to extend this to schedule
4864 optimally. Return 0 for now. */
4865 return 0;
4867 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4869 if (! recog_memoized (dep_insn))
4870 return 0;
4871 switch (get_attr_type (dep_insn))
4873 case TYPE_FPDIVSGL:
4874 case TYPE_FPDIVDBL:
4875 case TYPE_FPSQRTSGL:
4876 case TYPE_FPSQRTDBL:
4877 /* An ALU flop can't be issued until two cycles before a
4878 preceding divide or sqrt operation has finished if
4879 the target of the ALU flop is any of the sources
4880 (or destination) of the divide or sqrt operation. */
4881 return insn_default_latency (dep_insn) - 2;
4883 default:
4884 return 0;
4889 /* For other anti dependencies, the cost is 0. */
4890 return 0;
4892 case REG_DEP_OUTPUT:
4893 /* Output dependency; DEP_INSN writes a register that INSN writes some
4894 cycles later. */
4895 if (attr_type == TYPE_FPLOAD)
4897 rtx pat = PATTERN (insn);
4898 rtx dep_pat = PATTERN (dep_insn);
4899 if (GET_CODE (pat) == PARALLEL)
4901 /* This happens for the fldXs,mb patterns. */
4902 pat = XVECEXP (pat, 0, 0);
4904 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4905 /* If this happens, we have to extend this to schedule
4906 optimally. Return 0 for now. */
4907 return 0;
4909 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4911 if (! recog_memoized (dep_insn))
4912 return 0;
4913 switch (get_attr_type (dep_insn))
4915 case TYPE_FPALU:
4916 case TYPE_FPMULSGL:
4917 case TYPE_FPMULDBL:
4918 case TYPE_FPDIVSGL:
4919 case TYPE_FPDIVDBL:
4920 case TYPE_FPSQRTSGL:
4921 case TYPE_FPSQRTDBL:
4922 /* A fpload can't be issued until one cycle before a
4923 preceding arithmetic operation has finished if
4924 the target of the fpload is the destination of the
4925 arithmetic operation.
4927 Exception: For PA7100LC, PA7200 and PA7300, the cost
4928 is 3 cycles, unless they bundle together. We also
4929 pay the penalty if the second insn is a fpload. */
4930 return insn_default_latency (dep_insn) - 1;
4932 default:
4933 return 0;
4937 else if (attr_type == TYPE_FPALU)
4939 rtx pat = PATTERN (insn);
4940 rtx dep_pat = PATTERN (dep_insn);
4941 if (GET_CODE (pat) == PARALLEL)
4943 /* This happens for the fldXs,mb patterns. */
4944 pat = XVECEXP (pat, 0, 0);
4946 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4947 /* If this happens, we have to extend this to schedule
4948 optimally. Return 0 for now. */
4949 return 0;
4951 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4953 if (! recog_memoized (dep_insn))
4954 return 0;
4955 switch (get_attr_type (dep_insn))
4957 case TYPE_FPDIVSGL:
4958 case TYPE_FPDIVDBL:
4959 case TYPE_FPSQRTSGL:
4960 case TYPE_FPSQRTDBL:
4961 /* An ALU flop can't be issued until two cycles before a
4962 preceding divide or sqrt operation has finished if
4963 the target of the ALU flop is also the target of
4964 the divide or sqrt operation. */
4965 return insn_default_latency (dep_insn) - 2;
4967 default:
4968 return 0;
4973 /* For other output dependencies, the cost is 0. */
4974 return 0;
4976 default:
4977 gcc_unreachable ();
4981 /* Adjust scheduling priorities. We use this to try and keep addil
4982 and the next use of %r1 close together. */
4983 static int
4984 pa_adjust_priority (rtx_insn *insn, int priority)
4986 rtx set = single_set (insn);
4987 rtx src, dest;
4988 if (set)
4990 src = SET_SRC (set);
4991 dest = SET_DEST (set);
4992 if (GET_CODE (src) == LO_SUM
4993 && symbolic_operand (XEXP (src, 1), VOIDmode)
4994 && ! read_only_operand (XEXP (src, 1), VOIDmode))
4995 priority >>= 3;
4997 else if (GET_CODE (src) == MEM
4998 && GET_CODE (XEXP (src, 0)) == LO_SUM
4999 && symbolic_operand (XEXP (XEXP (src, 0), 1), VOIDmode)
5000 && ! read_only_operand (XEXP (XEXP (src, 0), 1), VOIDmode))
5001 priority >>= 1;
5003 else if (GET_CODE (dest) == MEM
5004 && GET_CODE (XEXP (dest, 0)) == LO_SUM
5005 && symbolic_operand (XEXP (XEXP (dest, 0), 1), VOIDmode)
5006 && ! read_only_operand (XEXP (XEXP (dest, 0), 1), VOIDmode))
5007 priority >>= 3;
5009 return priority;
5012 /* The 700 can only issue a single insn at a time.
5013 The 7XXX processors can issue two insns at a time.
5014 The 8000 can issue 4 insns at a time. */
5015 static int
5016 pa_issue_rate (void)
5018 switch (pa_cpu)
5020 case PROCESSOR_700: return 1;
5021 case PROCESSOR_7100: return 2;
5022 case PROCESSOR_7100LC: return 2;
5023 case PROCESSOR_7200: return 2;
5024 case PROCESSOR_7300: return 2;
5025 case PROCESSOR_8000: return 4;
5027 default:
5028 gcc_unreachable ();
5034 /* Return any length plus adjustment needed by INSN which already has
5035 its length computed as LENGTH. Return LENGTH if no adjustment is
5036 necessary.
5038 Also compute the length of an inline block move here as it is too
5039 complicated to express as a length attribute in pa.md. */
5041 pa_adjust_insn_length (rtx_insn *insn, int length)
5043 rtx pat = PATTERN (insn);
5045 /* If length is negative or undefined, provide initial length. */
5046 if ((unsigned int) length >= INT_MAX)
5048 if (GET_CODE (pat) == SEQUENCE)
5049 insn = as_a <rtx_insn *> (XVECEXP (pat, 0, 0));
5051 switch (get_attr_type (insn))
5053 case TYPE_MILLI:
5054 length = pa_attr_length_millicode_call (insn);
5055 break;
5056 case TYPE_CALL:
5057 length = pa_attr_length_call (insn, 0);
5058 break;
5059 case TYPE_SIBCALL:
5060 length = pa_attr_length_call (insn, 1);
5061 break;
5062 case TYPE_DYNCALL:
5063 length = pa_attr_length_indirect_call (insn);
5064 break;
5065 case TYPE_SH_FUNC_ADRS:
5066 length = pa_attr_length_millicode_call (insn) + 20;
5067 break;
5068 default:
5069 gcc_unreachable ();
5073 /* Block move pattern. */
5074 if (NONJUMP_INSN_P (insn)
5075 && GET_CODE (pat) == PARALLEL
5076 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
5077 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
5078 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 1)) == MEM
5079 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode
5080 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 1)) == BLKmode)
5081 length += compute_movmem_length (insn) - 4;
5082 /* Block clear pattern. */
5083 else if (NONJUMP_INSN_P (insn)
5084 && GET_CODE (pat) == PARALLEL
5085 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
5086 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
5087 && XEXP (XVECEXP (pat, 0, 0), 1) == const0_rtx
5088 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode)
5089 length += compute_clrmem_length (insn) - 4;
5090 /* Conditional branch with an unfilled delay slot. */
5091 else if (JUMP_P (insn) && ! simplejump_p (insn))
5093 /* Adjust a short backwards conditional with an unfilled delay slot. */
5094 if (GET_CODE (pat) == SET
5095 && length == 4
5096 && JUMP_LABEL (insn) != NULL_RTX
5097 && ! forward_branch_p (insn))
5098 length += 4;
5099 else if (GET_CODE (pat) == PARALLEL
5100 && get_attr_type (insn) == TYPE_PARALLEL_BRANCH
5101 && length == 4)
5102 length += 4;
5103 /* Adjust dbra insn with short backwards conditional branch with
5104 unfilled delay slot -- only for case where counter is in a
5105 general register register. */
5106 else if (GET_CODE (pat) == PARALLEL
5107 && GET_CODE (XVECEXP (pat, 0, 1)) == SET
5108 && GET_CODE (XEXP (XVECEXP (pat, 0, 1), 0)) == REG
5109 && ! FP_REG_P (XEXP (XVECEXP (pat, 0, 1), 0))
5110 && length == 4
5111 && ! forward_branch_p (insn))
5112 length += 4;
5114 return length;
5117 /* Implement the TARGET_PRINT_OPERAND_PUNCT_VALID_P hook. */
5119 static bool
5120 pa_print_operand_punct_valid_p (unsigned char code)
5122 if (code == '@'
5123 || code == '#'
5124 || code == '*'
5125 || code == '^')
5126 return true;
5128 return false;
5131 /* Print operand X (an rtx) in assembler syntax to file FILE.
5132 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
5133 For `%' followed by punctuation, CODE is the punctuation and X is null. */
5135 void
5136 pa_print_operand (FILE *file, rtx x, int code)
5138 switch (code)
5140 case '#':
5141 /* Output a 'nop' if there's nothing for the delay slot. */
5142 if (dbr_sequence_length () == 0)
5143 fputs ("\n\tnop", file);
5144 return;
5145 case '*':
5146 /* Output a nullification completer if there's nothing for the */
5147 /* delay slot or nullification is requested. */
5148 if (dbr_sequence_length () == 0 ||
5149 (final_sequence &&
5150 INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))))
5151 fputs (",n", file);
5152 return;
5153 case 'R':
5154 /* Print out the second register name of a register pair.
5155 I.e., R (6) => 7. */
5156 fputs (reg_names[REGNO (x) + 1], file);
5157 return;
5158 case 'r':
5159 /* A register or zero. */
5160 if (x == const0_rtx
5161 || (x == CONST0_RTX (DFmode))
5162 || (x == CONST0_RTX (SFmode)))
5164 fputs ("%r0", file);
5165 return;
5167 else
5168 break;
5169 case 'f':
5170 /* A register or zero (floating point). */
5171 if (x == const0_rtx
5172 || (x == CONST0_RTX (DFmode))
5173 || (x == CONST0_RTX (SFmode)))
5175 fputs ("%fr0", file);
5176 return;
5178 else
5179 break;
5180 case 'A':
5182 rtx xoperands[2];
5184 xoperands[0] = XEXP (XEXP (x, 0), 0);
5185 xoperands[1] = XVECEXP (XEXP (XEXP (x, 0), 1), 0, 0);
5186 pa_output_global_address (file, xoperands[1], 0);
5187 fprintf (file, "(%s)", reg_names [REGNO (xoperands[0])]);
5188 return;
5191 case 'C': /* Plain (C)ondition */
5192 case 'X':
5193 switch (GET_CODE (x))
5195 case EQ:
5196 fputs ("=", file); break;
5197 case NE:
5198 fputs ("<>", file); break;
5199 case GT:
5200 fputs (">", file); break;
5201 case GE:
5202 fputs (">=", file); break;
5203 case GEU:
5204 fputs (">>=", file); break;
5205 case GTU:
5206 fputs (">>", file); break;
5207 case LT:
5208 fputs ("<", file); break;
5209 case LE:
5210 fputs ("<=", file); break;
5211 case LEU:
5212 fputs ("<<=", file); break;
5213 case LTU:
5214 fputs ("<<", file); break;
5215 default:
5216 gcc_unreachable ();
5218 return;
5219 case 'N': /* Condition, (N)egated */
5220 switch (GET_CODE (x))
5222 case EQ:
5223 fputs ("<>", file); break;
5224 case NE:
5225 fputs ("=", file); break;
5226 case GT:
5227 fputs ("<=", file); break;
5228 case GE:
5229 fputs ("<", file); break;
5230 case GEU:
5231 fputs ("<<", file); break;
5232 case GTU:
5233 fputs ("<<=", file); break;
5234 case LT:
5235 fputs (">=", file); break;
5236 case LE:
5237 fputs (">", file); break;
5238 case LEU:
5239 fputs (">>", file); break;
5240 case LTU:
5241 fputs (">>=", file); break;
5242 default:
5243 gcc_unreachable ();
5245 return;
5246 /* For floating point comparisons. Note that the output
5247 predicates are the complement of the desired mode. The
5248 conditions for GT, GE, LT, LE and LTGT cause an invalid
5249 operation exception if the result is unordered and this
5250 exception is enabled in the floating-point status register. */
5251 case 'Y':
5252 switch (GET_CODE (x))
5254 case EQ:
5255 fputs ("!=", file); break;
5256 case NE:
5257 fputs ("=", file); break;
5258 case GT:
5259 fputs ("!>", file); break;
5260 case GE:
5261 fputs ("!>=", file); break;
5262 case LT:
5263 fputs ("!<", file); break;
5264 case LE:
5265 fputs ("!<=", file); break;
5266 case LTGT:
5267 fputs ("!<>", file); break;
5268 case UNLE:
5269 fputs ("!?<=", file); break;
5270 case UNLT:
5271 fputs ("!?<", file); break;
5272 case UNGE:
5273 fputs ("!?>=", file); break;
5274 case UNGT:
5275 fputs ("!?>", file); break;
5276 case UNEQ:
5277 fputs ("!?=", file); break;
5278 case UNORDERED:
5279 fputs ("!?", file); break;
5280 case ORDERED:
5281 fputs ("?", file); break;
5282 default:
5283 gcc_unreachable ();
5285 return;
5286 case 'S': /* Condition, operands are (S)wapped. */
5287 switch (GET_CODE (x))
5289 case EQ:
5290 fputs ("=", file); break;
5291 case NE:
5292 fputs ("<>", file); break;
5293 case GT:
5294 fputs ("<", file); break;
5295 case GE:
5296 fputs ("<=", file); break;
5297 case GEU:
5298 fputs ("<<=", file); break;
5299 case GTU:
5300 fputs ("<<", file); break;
5301 case LT:
5302 fputs (">", file); break;
5303 case LE:
5304 fputs (">=", file); break;
5305 case LEU:
5306 fputs (">>=", file); break;
5307 case LTU:
5308 fputs (">>", file); break;
5309 default:
5310 gcc_unreachable ();
5312 return;
5313 case 'B': /* Condition, (B)oth swapped and negate. */
5314 switch (GET_CODE (x))
5316 case EQ:
5317 fputs ("<>", file); break;
5318 case NE:
5319 fputs ("=", file); break;
5320 case GT:
5321 fputs (">=", file); break;
5322 case GE:
5323 fputs (">", file); break;
5324 case GEU:
5325 fputs (">>", file); break;
5326 case GTU:
5327 fputs (">>=", file); break;
5328 case LT:
5329 fputs ("<=", file); break;
5330 case LE:
5331 fputs ("<", file); break;
5332 case LEU:
5333 fputs ("<<", file); break;
5334 case LTU:
5335 fputs ("<<=", file); break;
5336 default:
5337 gcc_unreachable ();
5339 return;
5340 case 'k':
5341 gcc_assert (GET_CODE (x) == CONST_INT);
5342 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~INTVAL (x));
5343 return;
5344 case 'Q':
5345 gcc_assert (GET_CODE (x) == CONST_INT);
5346 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 64 - (INTVAL (x) & 63));
5347 return;
5348 case 'L':
5349 gcc_assert (GET_CODE (x) == CONST_INT);
5350 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 32 - (INTVAL (x) & 31));
5351 return;
5352 case 'o':
5353 gcc_assert (GET_CODE (x) == CONST_INT
5354 && (INTVAL (x) == 1 || INTVAL (x) == 2 || INTVAL (x) == 3));
5355 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
5356 return;
5357 case 'O':
5358 gcc_assert (GET_CODE (x) == CONST_INT && exact_log2 (INTVAL (x)) >= 0);
5359 fprintf (file, "%d", exact_log2 (INTVAL (x)));
5360 return;
5361 case 'p':
5362 gcc_assert (GET_CODE (x) == CONST_INT);
5363 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 63 - (INTVAL (x) & 63));
5364 return;
5365 case 'P':
5366 gcc_assert (GET_CODE (x) == CONST_INT);
5367 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 31 - (INTVAL (x) & 31));
5368 return;
5369 case 'I':
5370 if (GET_CODE (x) == CONST_INT)
5371 fputs ("i", file);
5372 return;
5373 case 'M':
5374 case 'F':
5375 switch (GET_CODE (XEXP (x, 0)))
5377 case PRE_DEC:
5378 case PRE_INC:
5379 if (ASSEMBLER_DIALECT == 0)
5380 fputs ("s,mb", file);
5381 else
5382 fputs (",mb", file);
5383 break;
5384 case POST_DEC:
5385 case POST_INC:
5386 if (ASSEMBLER_DIALECT == 0)
5387 fputs ("s,ma", file);
5388 else
5389 fputs (",ma", file);
5390 break;
5391 case PLUS:
5392 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5393 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5395 if (ASSEMBLER_DIALECT == 0)
5396 fputs ("x", file);
5398 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
5399 || GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5401 if (ASSEMBLER_DIALECT == 0)
5402 fputs ("x,s", file);
5403 else
5404 fputs (",s", file);
5406 else if (code == 'F' && ASSEMBLER_DIALECT == 0)
5407 fputs ("s", file);
5408 break;
5409 default:
5410 if (code == 'F' && ASSEMBLER_DIALECT == 0)
5411 fputs ("s", file);
5412 break;
5414 return;
5415 case 'G':
5416 pa_output_global_address (file, x, 0);
5417 return;
5418 case 'H':
5419 pa_output_global_address (file, x, 1);
5420 return;
5421 case 0: /* Don't do anything special */
5422 break;
5423 case 'Z':
5425 unsigned op[3];
5426 compute_zdepwi_operands (INTVAL (x), op);
5427 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5428 return;
5430 case 'z':
5432 unsigned op[3];
5433 compute_zdepdi_operands (INTVAL (x), op);
5434 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5435 return;
5437 case 'c':
5438 /* We can get here from a .vtable_inherit due to our
5439 CONSTANT_ADDRESS_P rejecting perfectly good constant
5440 addresses. */
5441 break;
5442 default:
5443 gcc_unreachable ();
5445 if (GET_CODE (x) == REG)
5447 fputs (reg_names [REGNO (x)], file);
5448 if (TARGET_64BIT && FP_REG_P (x) && GET_MODE_SIZE (GET_MODE (x)) <= 4)
5450 fputs ("R", file);
5451 return;
5453 if (FP_REG_P (x)
5454 && GET_MODE_SIZE (GET_MODE (x)) <= 4
5455 && (REGNO (x) & 1) == 0)
5456 fputs ("L", file);
5458 else if (GET_CODE (x) == MEM)
5460 int size = GET_MODE_SIZE (GET_MODE (x));
5461 rtx base = NULL_RTX;
5462 switch (GET_CODE (XEXP (x, 0)))
5464 case PRE_DEC:
5465 case POST_DEC:
5466 base = XEXP (XEXP (x, 0), 0);
5467 fprintf (file, "-%d(%s)", size, reg_names [REGNO (base)]);
5468 break;
5469 case PRE_INC:
5470 case POST_INC:
5471 base = XEXP (XEXP (x, 0), 0);
5472 fprintf (file, "%d(%s)", size, reg_names [REGNO (base)]);
5473 break;
5474 case PLUS:
5475 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
5476 fprintf (file, "%s(%s)",
5477 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 0), 0))],
5478 reg_names [REGNO (XEXP (XEXP (x, 0), 1))]);
5479 else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5480 fprintf (file, "%s(%s)",
5481 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 1), 0))],
5482 reg_names [REGNO (XEXP (XEXP (x, 0), 0))]);
5483 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5484 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5486 /* Because the REG_POINTER flag can get lost during reload,
5487 pa_legitimate_address_p canonicalizes the order of the
5488 index and base registers in the combined move patterns. */
5489 rtx base = XEXP (XEXP (x, 0), 1);
5490 rtx index = XEXP (XEXP (x, 0), 0);
5492 fprintf (file, "%s(%s)",
5493 reg_names [REGNO (index)], reg_names [REGNO (base)]);
5495 else
5496 output_address (GET_MODE (x), XEXP (x, 0));
5497 break;
5498 default:
5499 output_address (GET_MODE (x), XEXP (x, 0));
5500 break;
5503 else
5504 output_addr_const (file, x);
5507 /* output a SYMBOL_REF or a CONST expression involving a SYMBOL_REF. */
5509 void
5510 pa_output_global_address (FILE *file, rtx x, int round_constant)
5513 /* Imagine (high (const (plus ...))). */
5514 if (GET_CODE (x) == HIGH)
5515 x = XEXP (x, 0);
5517 if (GET_CODE (x) == SYMBOL_REF && read_only_operand (x, VOIDmode))
5518 output_addr_const (file, x);
5519 else if (GET_CODE (x) == SYMBOL_REF && !flag_pic)
5521 output_addr_const (file, x);
5522 fputs ("-$global$", file);
5524 else if (GET_CODE (x) == CONST)
5526 const char *sep = "";
5527 int offset = 0; /* assembler wants -$global$ at end */
5528 rtx base = NULL_RTX;
5530 switch (GET_CODE (XEXP (XEXP (x, 0), 0)))
5532 case LABEL_REF:
5533 case SYMBOL_REF:
5534 base = XEXP (XEXP (x, 0), 0);
5535 output_addr_const (file, base);
5536 break;
5537 case CONST_INT:
5538 offset = INTVAL (XEXP (XEXP (x, 0), 0));
5539 break;
5540 default:
5541 gcc_unreachable ();
5544 switch (GET_CODE (XEXP (XEXP (x, 0), 1)))
5546 case LABEL_REF:
5547 case SYMBOL_REF:
5548 base = XEXP (XEXP (x, 0), 1);
5549 output_addr_const (file, base);
5550 break;
5551 case CONST_INT:
5552 offset = INTVAL (XEXP (XEXP (x, 0), 1));
5553 break;
5554 default:
5555 gcc_unreachable ();
5558 /* How bogus. The compiler is apparently responsible for
5559 rounding the constant if it uses an LR field selector.
5561 The linker and/or assembler seem a better place since
5562 they have to do this kind of thing already.
5564 If we fail to do this, HP's optimizing linker may eliminate
5565 an addil, but not update the ldw/stw/ldo instruction that
5566 uses the result of the addil. */
5567 if (round_constant)
5568 offset = ((offset + 0x1000) & ~0x1fff);
5570 switch (GET_CODE (XEXP (x, 0)))
5572 case PLUS:
5573 if (offset < 0)
5575 offset = -offset;
5576 sep = "-";
5578 else
5579 sep = "+";
5580 break;
5582 case MINUS:
5583 gcc_assert (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF);
5584 sep = "-";
5585 break;
5587 default:
5588 gcc_unreachable ();
5591 if (!read_only_operand (base, VOIDmode) && !flag_pic)
5592 fputs ("-$global$", file);
5593 if (offset)
5594 fprintf (file, "%s%d", sep, offset);
5596 else
5597 output_addr_const (file, x);
5600 /* Output boilerplate text to appear at the beginning of the file.
5601 There are several possible versions. */
5602 #define aputs(x) fputs(x, asm_out_file)
5603 static inline void
5604 pa_file_start_level (void)
5606 if (TARGET_64BIT)
5607 aputs ("\t.LEVEL 2.0w\n");
5608 else if (TARGET_PA_20)
5609 aputs ("\t.LEVEL 2.0\n");
5610 else if (TARGET_PA_11)
5611 aputs ("\t.LEVEL 1.1\n");
5612 else
5613 aputs ("\t.LEVEL 1.0\n");
5616 static inline void
5617 pa_file_start_space (int sortspace)
5619 aputs ("\t.SPACE $PRIVATE$");
5620 if (sortspace)
5621 aputs (",SORT=16");
5622 aputs ("\n\t.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31");
5623 if (flag_tm)
5624 aputs ("\n\t.SUBSPA $TM_CLONE_TABLE$,QUAD=1,ALIGN=8,ACCESS=31");
5625 aputs ("\n\t.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82"
5626 "\n\t.SPACE $TEXT$");
5627 if (sortspace)
5628 aputs (",SORT=8");
5629 aputs ("\n\t.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44"
5630 "\n\t.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n");
5633 static inline void
5634 pa_file_start_file (int want_version)
5636 if (write_symbols != NO_DEBUG)
5638 output_file_directive (asm_out_file, main_input_filename);
5639 if (want_version)
5640 aputs ("\t.version\t\"01.01\"\n");
5644 static inline void
5645 pa_file_start_mcount (const char *aswhat)
5647 if (profile_flag)
5648 fprintf (asm_out_file, "\t.IMPORT _mcount,%s\n", aswhat);
5651 static void
5652 pa_elf_file_start (void)
5654 pa_file_start_level ();
5655 pa_file_start_mcount ("ENTRY");
5656 pa_file_start_file (0);
5659 static void
5660 pa_som_file_start (void)
5662 pa_file_start_level ();
5663 pa_file_start_space (0);
5664 aputs ("\t.IMPORT $global$,DATA\n"
5665 "\t.IMPORT $$dyncall,MILLICODE\n");
5666 pa_file_start_mcount ("CODE");
5667 pa_file_start_file (0);
5670 static void
5671 pa_linux_file_start (void)
5673 pa_file_start_file (1);
5674 pa_file_start_level ();
5675 pa_file_start_mcount ("CODE");
5678 static void
5679 pa_hpux64_gas_file_start (void)
5681 pa_file_start_level ();
5682 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
5683 if (profile_flag)
5684 ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, "_mcount", "function");
5685 #endif
5686 pa_file_start_file (1);
5689 static void
5690 pa_hpux64_hpas_file_start (void)
5692 pa_file_start_level ();
5693 pa_file_start_space (1);
5694 pa_file_start_mcount ("CODE");
5695 pa_file_start_file (0);
5697 #undef aputs
5699 /* Search the deferred plabel list for SYMBOL and return its internal
5700 label. If an entry for SYMBOL is not found, a new entry is created. */
5703 pa_get_deferred_plabel (rtx symbol)
5705 const char *fname = XSTR (symbol, 0);
5706 size_t i;
5708 /* See if we have already put this function on the list of deferred
5709 plabels. This list is generally small, so a liner search is not
5710 too ugly. If it proves too slow replace it with something faster. */
5711 for (i = 0; i < n_deferred_plabels; i++)
5712 if (strcmp (fname, XSTR (deferred_plabels[i].symbol, 0)) == 0)
5713 break;
5715 /* If the deferred plabel list is empty, or this entry was not found
5716 on the list, create a new entry on the list. */
5717 if (deferred_plabels == NULL || i == n_deferred_plabels)
5719 tree id;
5721 if (deferred_plabels == 0)
5722 deferred_plabels = ggc_alloc<deferred_plabel> ();
5723 else
5724 deferred_plabels = GGC_RESIZEVEC (struct deferred_plabel,
5725 deferred_plabels,
5726 n_deferred_plabels + 1);
5728 i = n_deferred_plabels++;
5729 deferred_plabels[i].internal_label = gen_label_rtx ();
5730 deferred_plabels[i].symbol = symbol;
5732 /* Gross. We have just implicitly taken the address of this
5733 function. Mark it in the same manner as assemble_name. */
5734 id = maybe_get_identifier (targetm.strip_name_encoding (fname));
5735 if (id)
5736 mark_referenced (id);
5739 return deferred_plabels[i].internal_label;
5742 static void
5743 output_deferred_plabels (void)
5745 size_t i;
5747 /* If we have some deferred plabels, then we need to switch into the
5748 data or readonly data section, and align it to a 4 byte boundary
5749 before outputting the deferred plabels. */
5750 if (n_deferred_plabels)
5752 switch_to_section (flag_pic ? data_section : readonly_data_section);
5753 ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2);
5756 /* Now output the deferred plabels. */
5757 for (i = 0; i < n_deferred_plabels; i++)
5759 targetm.asm_out.internal_label (asm_out_file, "L",
5760 CODE_LABEL_NUMBER (deferred_plabels[i].internal_label));
5761 assemble_integer (deferred_plabels[i].symbol,
5762 TARGET_64BIT ? 8 : 4, TARGET_64BIT ? 64 : 32, 1);
5766 /* Initialize optabs to point to emulation routines. */
5768 static void
5769 pa_init_libfuncs (void)
5771 if (HPUX_LONG_DOUBLE_LIBRARY)
5773 set_optab_libfunc (add_optab, TFmode, "_U_Qfadd");
5774 set_optab_libfunc (sub_optab, TFmode, "_U_Qfsub");
5775 set_optab_libfunc (smul_optab, TFmode, "_U_Qfmpy");
5776 set_optab_libfunc (sdiv_optab, TFmode, "_U_Qfdiv");
5777 set_optab_libfunc (smin_optab, TFmode, "_U_Qmin");
5778 set_optab_libfunc (smax_optab, TFmode, "_U_Qfmax");
5779 set_optab_libfunc (sqrt_optab, TFmode, "_U_Qfsqrt");
5780 set_optab_libfunc (abs_optab, TFmode, "_U_Qfabs");
5781 set_optab_libfunc (neg_optab, TFmode, "_U_Qfneg");
5783 set_optab_libfunc (eq_optab, TFmode, "_U_Qfeq");
5784 set_optab_libfunc (ne_optab, TFmode, "_U_Qfne");
5785 set_optab_libfunc (gt_optab, TFmode, "_U_Qfgt");
5786 set_optab_libfunc (ge_optab, TFmode, "_U_Qfge");
5787 set_optab_libfunc (lt_optab, TFmode, "_U_Qflt");
5788 set_optab_libfunc (le_optab, TFmode, "_U_Qfle");
5789 set_optab_libfunc (unord_optab, TFmode, "_U_Qfunord");
5791 set_conv_libfunc (sext_optab, TFmode, SFmode, "_U_Qfcnvff_sgl_to_quad");
5792 set_conv_libfunc (sext_optab, TFmode, DFmode, "_U_Qfcnvff_dbl_to_quad");
5793 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_U_Qfcnvff_quad_to_sgl");
5794 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_U_Qfcnvff_quad_to_dbl");
5796 set_conv_libfunc (sfix_optab, SImode, TFmode,
5797 TARGET_64BIT ? "__U_Qfcnvfxt_quad_to_sgl"
5798 : "_U_Qfcnvfxt_quad_to_sgl");
5799 set_conv_libfunc (sfix_optab, DImode, TFmode,
5800 "_U_Qfcnvfxt_quad_to_dbl");
5801 set_conv_libfunc (ufix_optab, SImode, TFmode,
5802 "_U_Qfcnvfxt_quad_to_usgl");
5803 set_conv_libfunc (ufix_optab, DImode, TFmode,
5804 "_U_Qfcnvfxt_quad_to_udbl");
5806 set_conv_libfunc (sfloat_optab, TFmode, SImode,
5807 "_U_Qfcnvxf_sgl_to_quad");
5808 set_conv_libfunc (sfloat_optab, TFmode, DImode,
5809 "_U_Qfcnvxf_dbl_to_quad");
5810 set_conv_libfunc (ufloat_optab, TFmode, SImode,
5811 "_U_Qfcnvxf_usgl_to_quad");
5812 set_conv_libfunc (ufloat_optab, TFmode, DImode,
5813 "_U_Qfcnvxf_udbl_to_quad");
5816 if (TARGET_SYNC_LIBCALL)
5817 init_sync_libfuncs (8);
5820 /* HP's millicode routines mean something special to the assembler.
5821 Keep track of which ones we have used. */
5823 enum millicodes { remI, remU, divI, divU, mulI, end1000 };
5824 static void import_milli (enum millicodes);
5825 static char imported[(int) end1000];
5826 static const char * const milli_names[] = {"remI", "remU", "divI", "divU", "mulI"};
5827 static const char import_string[] = ".IMPORT $$....,MILLICODE";
5828 #define MILLI_START 10
5830 static void
5831 import_milli (enum millicodes code)
5833 char str[sizeof (import_string)];
5835 if (!imported[(int) code])
5837 imported[(int) code] = 1;
5838 strcpy (str, import_string);
5839 strncpy (str + MILLI_START, milli_names[(int) code], 4);
5840 output_asm_insn (str, 0);
5844 /* The register constraints have put the operands and return value in
5845 the proper registers. */
5847 const char *
5848 pa_output_mul_insn (int unsignedp ATTRIBUTE_UNUSED, rtx_insn *insn)
5850 import_milli (mulI);
5851 return pa_output_millicode_call (insn, gen_rtx_SYMBOL_REF (Pmode, "$$mulI"));
5854 /* Emit the rtl for doing a division by a constant. */
5856 /* Do magic division millicodes exist for this value? */
5857 const int pa_magic_milli[]= {0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1};
5859 /* We'll use an array to keep track of the magic millicodes and
5860 whether or not we've used them already. [n][0] is signed, [n][1] is
5861 unsigned. */
5863 static int div_milli[16][2];
5866 pa_emit_hpdiv_const (rtx *operands, int unsignedp)
5868 if (GET_CODE (operands[2]) == CONST_INT
5869 && INTVAL (operands[2]) > 0
5870 && INTVAL (operands[2]) < 16
5871 && pa_magic_milli[INTVAL (operands[2])])
5873 rtx ret = gen_rtx_REG (SImode, TARGET_64BIT ? 2 : 31);
5875 emit_move_insn (gen_rtx_REG (SImode, 26), operands[1]);
5876 emit
5877 (gen_rtx_PARALLEL
5878 (VOIDmode,
5879 gen_rtvec (6, gen_rtx_SET (gen_rtx_REG (SImode, 29),
5880 gen_rtx_fmt_ee (unsignedp ? UDIV : DIV,
5881 SImode,
5882 gen_rtx_REG (SImode, 26),
5883 operands[2])),
5884 gen_rtx_CLOBBER (VOIDmode, operands[4]),
5885 gen_rtx_CLOBBER (VOIDmode, operands[3]),
5886 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 26)),
5887 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 25)),
5888 gen_rtx_CLOBBER (VOIDmode, ret))));
5889 emit_move_insn (operands[0], gen_rtx_REG (SImode, 29));
5890 return 1;
5892 return 0;
5895 const char *
5896 pa_output_div_insn (rtx *operands, int unsignedp, rtx_insn *insn)
5898 int divisor;
5900 /* If the divisor is a constant, try to use one of the special
5901 opcodes .*/
5902 if (GET_CODE (operands[0]) == CONST_INT)
5904 static char buf[100];
5905 divisor = INTVAL (operands[0]);
5906 if (!div_milli[divisor][unsignedp])
5908 div_milli[divisor][unsignedp] = 1;
5909 if (unsignedp)
5910 output_asm_insn (".IMPORT $$divU_%0,MILLICODE", operands);
5911 else
5912 output_asm_insn (".IMPORT $$divI_%0,MILLICODE", operands);
5914 if (unsignedp)
5916 sprintf (buf, "$$divU_" HOST_WIDE_INT_PRINT_DEC,
5917 INTVAL (operands[0]));
5918 return pa_output_millicode_call (insn,
5919 gen_rtx_SYMBOL_REF (SImode, buf));
5921 else
5923 sprintf (buf, "$$divI_" HOST_WIDE_INT_PRINT_DEC,
5924 INTVAL (operands[0]));
5925 return pa_output_millicode_call (insn,
5926 gen_rtx_SYMBOL_REF (SImode, buf));
5929 /* Divisor isn't a special constant. */
5930 else
5932 if (unsignedp)
5934 import_milli (divU);
5935 return pa_output_millicode_call (insn,
5936 gen_rtx_SYMBOL_REF (SImode, "$$divU"));
5938 else
5940 import_milli (divI);
5941 return pa_output_millicode_call (insn,
5942 gen_rtx_SYMBOL_REF (SImode, "$$divI"));
5947 /* Output a $$rem millicode to do mod. */
5949 const char *
5950 pa_output_mod_insn (int unsignedp, rtx_insn *insn)
5952 if (unsignedp)
5954 import_milli (remU);
5955 return pa_output_millicode_call (insn,
5956 gen_rtx_SYMBOL_REF (SImode, "$$remU"));
5958 else
5960 import_milli (remI);
5961 return pa_output_millicode_call (insn,
5962 gen_rtx_SYMBOL_REF (SImode, "$$remI"));
5966 void
5967 pa_output_arg_descriptor (rtx_insn *call_insn)
5969 const char *arg_regs[4];
5970 machine_mode arg_mode;
5971 rtx link;
5972 int i, output_flag = 0;
5973 int regno;
5975 /* We neither need nor want argument location descriptors for the
5976 64bit runtime environment or the ELF32 environment. */
5977 if (TARGET_64BIT || TARGET_ELF32)
5978 return;
5980 for (i = 0; i < 4; i++)
5981 arg_regs[i] = 0;
5983 /* Specify explicitly that no argument relocations should take place
5984 if using the portable runtime calling conventions. */
5985 if (TARGET_PORTABLE_RUNTIME)
5987 fputs ("\t.CALL ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RETVAL=NO\n",
5988 asm_out_file);
5989 return;
5992 gcc_assert (CALL_P (call_insn));
5993 for (link = CALL_INSN_FUNCTION_USAGE (call_insn);
5994 link; link = XEXP (link, 1))
5996 rtx use = XEXP (link, 0);
5998 if (! (GET_CODE (use) == USE
5999 && GET_CODE (XEXP (use, 0)) == REG
6000 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
6001 continue;
6003 arg_mode = GET_MODE (XEXP (use, 0));
6004 regno = REGNO (XEXP (use, 0));
6005 if (regno >= 23 && regno <= 26)
6007 arg_regs[26 - regno] = "GR";
6008 if (arg_mode == DImode)
6009 arg_regs[25 - regno] = "GR";
6011 else if (regno >= 32 && regno <= 39)
6013 if (arg_mode == SFmode)
6014 arg_regs[(regno - 32) / 2] = "FR";
6015 else
6017 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
6018 arg_regs[(regno - 34) / 2] = "FR";
6019 arg_regs[(regno - 34) / 2 + 1] = "FU";
6020 #else
6021 arg_regs[(regno - 34) / 2] = "FU";
6022 arg_regs[(regno - 34) / 2 + 1] = "FR";
6023 #endif
6027 fputs ("\t.CALL ", asm_out_file);
6028 for (i = 0; i < 4; i++)
6030 if (arg_regs[i])
6032 if (output_flag++)
6033 fputc (',', asm_out_file);
6034 fprintf (asm_out_file, "ARGW%d=%s", i, arg_regs[i]);
6037 fputc ('\n', asm_out_file);
6040 /* Inform reload about cases where moving X with a mode MODE to or from
6041 a register in RCLASS requires an extra scratch or immediate register.
6042 Return the class needed for the immediate register. */
6044 static reg_class_t
6045 pa_secondary_reload (bool in_p, rtx x, reg_class_t rclass_i,
6046 machine_mode mode, secondary_reload_info *sri)
6048 int regno;
6049 enum reg_class rclass = (enum reg_class) rclass_i;
6051 /* Handle the easy stuff first. */
6052 if (rclass == R1_REGS)
6053 return NO_REGS;
6055 if (REG_P (x))
6057 regno = REGNO (x);
6058 if (rclass == BASE_REG_CLASS && regno < FIRST_PSEUDO_REGISTER)
6059 return NO_REGS;
6061 else
6062 regno = -1;
6064 /* If we have something like (mem (mem (...)), we can safely assume the
6065 inner MEM will end up in a general register after reloading, so there's
6066 no need for a secondary reload. */
6067 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == MEM)
6068 return NO_REGS;
6070 /* Trying to load a constant into a FP register during PIC code
6071 generation requires %r1 as a scratch register. For float modes,
6072 the only legitimate constant is CONST0_RTX. However, there are
6073 a few patterns that accept constant double operands. */
6074 if (flag_pic
6075 && FP_REG_CLASS_P (rclass)
6076 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
6078 switch (mode)
6080 case E_SImode:
6081 sri->icode = CODE_FOR_reload_insi_r1;
6082 break;
6084 case E_DImode:
6085 sri->icode = CODE_FOR_reload_indi_r1;
6086 break;
6088 case E_SFmode:
6089 sri->icode = CODE_FOR_reload_insf_r1;
6090 break;
6092 case E_DFmode:
6093 sri->icode = CODE_FOR_reload_indf_r1;
6094 break;
6096 default:
6097 gcc_unreachable ();
6099 return NO_REGS;
6102 /* Secondary reloads of symbolic expressions require %r1 as a scratch
6103 register when we're generating PIC code or when the operand isn't
6104 readonly. */
6105 if (pa_symbolic_expression_p (x))
6107 if (GET_CODE (x) == HIGH)
6108 x = XEXP (x, 0);
6110 if (flag_pic || !read_only_operand (x, VOIDmode))
6112 switch (mode)
6114 case E_SImode:
6115 sri->icode = CODE_FOR_reload_insi_r1;
6116 break;
6118 case E_DImode:
6119 sri->icode = CODE_FOR_reload_indi_r1;
6120 break;
6122 default:
6123 gcc_unreachable ();
6125 return NO_REGS;
6129 /* Profiling showed the PA port spends about 1.3% of its compilation
6130 time in true_regnum from calls inside pa_secondary_reload_class. */
6131 if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
6132 regno = true_regnum (x);
6134 /* Handle reloads for floating point loads and stores. */
6135 if ((regno >= FIRST_PSEUDO_REGISTER || regno == -1)
6136 && FP_REG_CLASS_P (rclass))
6138 if (MEM_P (x))
6140 x = XEXP (x, 0);
6142 /* We don't need a secondary reload for indexed memory addresses.
6144 When INT14_OK_STRICT is true, it might appear that we could
6145 directly allow register indirect memory addresses. However,
6146 this doesn't work because we don't support SUBREGs in
6147 floating-point register copies and reload doesn't tell us
6148 when it's going to use a SUBREG. */
6149 if (IS_INDEX_ADDR_P (x))
6150 return NO_REGS;
6153 /* Request a secondary reload with a general scratch register
6154 for everything else. ??? Could symbolic operands be handled
6155 directly when generating non-pic PA 2.0 code? */
6156 sri->icode = (in_p
6157 ? direct_optab_handler (reload_in_optab, mode)
6158 : direct_optab_handler (reload_out_optab, mode));
6159 return NO_REGS;
6162 /* A SAR<->FP register copy requires an intermediate general register
6163 and secondary memory. We need a secondary reload with a general
6164 scratch register for spills. */
6165 if (rclass == SHIFT_REGS)
6167 /* Handle spill. */
6168 if (regno >= FIRST_PSEUDO_REGISTER || regno < 0)
6170 sri->icode = (in_p
6171 ? direct_optab_handler (reload_in_optab, mode)
6172 : direct_optab_handler (reload_out_optab, mode));
6173 return NO_REGS;
6176 /* Handle FP copy. */
6177 if (FP_REG_CLASS_P (REGNO_REG_CLASS (regno)))
6178 return GENERAL_REGS;
6181 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
6182 && REGNO_REG_CLASS (regno) == SHIFT_REGS
6183 && FP_REG_CLASS_P (rclass))
6184 return GENERAL_REGS;
6186 return NO_REGS;
6189 /* Implement TARGET_EXTRA_LIVE_ON_ENTRY. The argument pointer
6190 is only marked as live on entry by df-scan when it is a fixed
6191 register. It isn't a fixed register in the 64-bit runtime,
6192 so we need to mark it here. */
6194 static void
6195 pa_extra_live_on_entry (bitmap regs)
6197 if (TARGET_64BIT)
6198 bitmap_set_bit (regs, ARG_POINTER_REGNUM);
6201 /* Implement EH_RETURN_HANDLER_RTX. The MEM needs to be volatile
6202 to prevent it from being deleted. */
6205 pa_eh_return_handler_rtx (void)
6207 rtx tmp;
6209 tmp = gen_rtx_PLUS (word_mode, hard_frame_pointer_rtx,
6210 TARGET_64BIT ? GEN_INT (-16) : GEN_INT (-20));
6211 tmp = gen_rtx_MEM (word_mode, tmp);
6212 tmp->volatil = 1;
6213 return tmp;
6216 /* In the 32-bit runtime, arguments larger than eight bytes are passed
6217 by invisible reference. As a GCC extension, we also pass anything
6218 with a zero or variable size by reference.
6220 The 64-bit runtime does not describe passing any types by invisible
6221 reference. The internals of GCC can't currently handle passing
6222 empty structures, and zero or variable length arrays when they are
6223 not passed entirely on the stack or by reference. Thus, as a GCC
6224 extension, we pass these types by reference. The HP compiler doesn't
6225 support these types, so hopefully there shouldn't be any compatibility
6226 issues. This may have to be revisited when HP releases a C99 compiler
6227 or updates the ABI. */
6229 static bool
6230 pa_pass_by_reference (cumulative_args_t ca ATTRIBUTE_UNUSED,
6231 machine_mode mode, const_tree type,
6232 bool named ATTRIBUTE_UNUSED)
6234 HOST_WIDE_INT size;
6236 if (type)
6237 size = int_size_in_bytes (type);
6238 else
6239 size = GET_MODE_SIZE (mode);
6241 if (TARGET_64BIT)
6242 return size <= 0;
6243 else
6244 return size <= 0 || size > 8;
6247 /* Implement TARGET_FUNCTION_ARG_PADDING. */
6249 static pad_direction
6250 pa_function_arg_padding (machine_mode mode, const_tree type)
6252 if (mode == BLKmode
6253 || (TARGET_64BIT
6254 && type
6255 && (AGGREGATE_TYPE_P (type)
6256 || TREE_CODE (type) == COMPLEX_TYPE
6257 || TREE_CODE (type) == VECTOR_TYPE)))
6259 /* Return PAD_NONE if justification is not required. */
6260 if (type
6261 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
6262 && (int_size_in_bytes (type) * BITS_PER_UNIT) % PARM_BOUNDARY == 0)
6263 return PAD_NONE;
6265 /* The directions set here are ignored when a BLKmode argument larger
6266 than a word is placed in a register. Different code is used for
6267 the stack and registers. This makes it difficult to have a
6268 consistent data representation for both the stack and registers.
6269 For both runtimes, the justification and padding for arguments on
6270 the stack and in registers should be identical. */
6271 if (TARGET_64BIT)
6272 /* The 64-bit runtime specifies left justification for aggregates. */
6273 return PAD_UPWARD;
6274 else
6275 /* The 32-bit runtime architecture specifies right justification.
6276 When the argument is passed on the stack, the argument is padded
6277 with garbage on the left. The HP compiler pads with zeros. */
6278 return PAD_DOWNWARD;
6281 if (GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
6282 return PAD_DOWNWARD;
6283 else
6284 return PAD_NONE;
6288 /* Do what is necessary for `va_start'. We look at the current function
6289 to determine if stdargs or varargs is used and fill in an initial
6290 va_list. A pointer to this constructor is returned. */
6292 static rtx
6293 hppa_builtin_saveregs (void)
6295 rtx offset, dest;
6296 tree fntype = TREE_TYPE (current_function_decl);
6297 int argadj = ((!stdarg_p (fntype))
6298 ? UNITS_PER_WORD : 0);
6300 if (argadj)
6301 offset = plus_constant (Pmode, crtl->args.arg_offset_rtx, argadj);
6302 else
6303 offset = crtl->args.arg_offset_rtx;
6305 if (TARGET_64BIT)
6307 int i, off;
6309 /* Adjust for varargs/stdarg differences. */
6310 if (argadj)
6311 offset = plus_constant (Pmode, crtl->args.arg_offset_rtx, -argadj);
6312 else
6313 offset = crtl->args.arg_offset_rtx;
6315 /* We need to save %r26 .. %r19 inclusive starting at offset -64
6316 from the incoming arg pointer and growing to larger addresses. */
6317 for (i = 26, off = -64; i >= 19; i--, off += 8)
6318 emit_move_insn (gen_rtx_MEM (word_mode,
6319 plus_constant (Pmode,
6320 arg_pointer_rtx, off)),
6321 gen_rtx_REG (word_mode, i));
6323 /* The incoming args pointer points just beyond the flushback area;
6324 normally this is not a serious concern. However, when we are doing
6325 varargs/stdargs we want to make the arg pointer point to the start
6326 of the incoming argument area. */
6327 emit_move_insn (virtual_incoming_args_rtx,
6328 plus_constant (Pmode, arg_pointer_rtx, -64));
6330 /* Now return a pointer to the first anonymous argument. */
6331 return copy_to_reg (expand_binop (Pmode, add_optab,
6332 virtual_incoming_args_rtx,
6333 offset, 0, 0, OPTAB_LIB_WIDEN));
6336 /* Store general registers on the stack. */
6337 dest = gen_rtx_MEM (BLKmode,
6338 plus_constant (Pmode, crtl->args.internal_arg_pointer,
6339 -16));
6340 set_mem_alias_set (dest, get_varargs_alias_set ());
6341 set_mem_align (dest, BITS_PER_WORD);
6342 move_block_from_reg (23, dest, 4);
6344 /* move_block_from_reg will emit code to store the argument registers
6345 individually as scalar stores.
6347 However, other insns may later load from the same addresses for
6348 a structure load (passing a struct to a varargs routine).
6350 The alias code assumes that such aliasing can never happen, so we
6351 have to keep memory referencing insns from moving up beyond the
6352 last argument register store. So we emit a blockage insn here. */
6353 emit_insn (gen_blockage ());
6355 return copy_to_reg (expand_binop (Pmode, add_optab,
6356 crtl->args.internal_arg_pointer,
6357 offset, 0, 0, OPTAB_LIB_WIDEN));
6360 static void
6361 hppa_va_start (tree valist, rtx nextarg)
6363 nextarg = expand_builtin_saveregs ();
6364 std_expand_builtin_va_start (valist, nextarg);
6367 static tree
6368 hppa_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
6369 gimple_seq *post_p)
6371 if (TARGET_64BIT)
6373 /* Args grow upward. We can use the generic routines. */
6374 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6376 else /* !TARGET_64BIT */
6378 tree ptr = build_pointer_type (type);
6379 tree valist_type;
6380 tree t, u;
6381 unsigned int size, ofs;
6382 bool indirect;
6384 indirect = pass_by_reference (NULL, TYPE_MODE (type), type, 0);
6385 if (indirect)
6387 type = ptr;
6388 ptr = build_pointer_type (type);
6390 size = int_size_in_bytes (type);
6391 valist_type = TREE_TYPE (valist);
6393 /* Args grow down. Not handled by generic routines. */
6395 u = fold_convert (sizetype, size_in_bytes (type));
6396 u = fold_build1 (NEGATE_EXPR, sizetype, u);
6397 t = fold_build_pointer_plus (valist, u);
6399 /* Align to 4 or 8 byte boundary depending on argument size. */
6401 u = build_int_cst (TREE_TYPE (t), (HOST_WIDE_INT)(size > 4 ? -8 : -4));
6402 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t, u);
6403 t = fold_convert (valist_type, t);
6405 t = build2 (MODIFY_EXPR, valist_type, valist, t);
6407 ofs = (8 - size) % 4;
6408 if (ofs != 0)
6409 t = fold_build_pointer_plus_hwi (t, ofs);
6411 t = fold_convert (ptr, t);
6412 t = build_va_arg_indirect_ref (t);
6414 if (indirect)
6415 t = build_va_arg_indirect_ref (t);
6417 return t;
6421 /* True if MODE is valid for the target. By "valid", we mean able to
6422 be manipulated in non-trivial ways. In particular, this means all
6423 the arithmetic is supported.
6425 Currently, TImode is not valid as the HP 64-bit runtime documentation
6426 doesn't document the alignment and calling conventions for this type.
6427 Thus, we return false when PRECISION is 2 * BITS_PER_WORD and
6428 2 * BITS_PER_WORD isn't equal LONG_LONG_TYPE_SIZE. */
6430 static bool
6431 pa_scalar_mode_supported_p (scalar_mode mode)
6433 int precision = GET_MODE_PRECISION (mode);
6435 switch (GET_MODE_CLASS (mode))
6437 case MODE_PARTIAL_INT:
6438 case MODE_INT:
6439 if (precision == CHAR_TYPE_SIZE)
6440 return true;
6441 if (precision == SHORT_TYPE_SIZE)
6442 return true;
6443 if (precision == INT_TYPE_SIZE)
6444 return true;
6445 if (precision == LONG_TYPE_SIZE)
6446 return true;
6447 if (precision == LONG_LONG_TYPE_SIZE)
6448 return true;
6449 return false;
6451 case MODE_FLOAT:
6452 if (precision == FLOAT_TYPE_SIZE)
6453 return true;
6454 if (precision == DOUBLE_TYPE_SIZE)
6455 return true;
6456 if (precision == LONG_DOUBLE_TYPE_SIZE)
6457 return true;
6458 return false;
6460 case MODE_DECIMAL_FLOAT:
6461 return false;
6463 default:
6464 gcc_unreachable ();
6468 /* Return TRUE if INSN, a jump insn, has an unfilled delay slot and
6469 it branches into the delay slot. Otherwise, return FALSE. */
6471 static bool
6472 branch_to_delay_slot_p (rtx_insn *insn)
6474 rtx_insn *jump_insn;
6476 if (dbr_sequence_length ())
6477 return FALSE;
6479 jump_insn = next_active_insn (JUMP_LABEL_AS_INSN (insn));
6480 while (insn)
6482 insn = next_active_insn (insn);
6483 if (jump_insn == insn)
6484 return TRUE;
6486 /* We can't rely on the length of asms. So, we return FALSE when
6487 the branch is followed by an asm. */
6488 if (!insn
6489 || GET_CODE (PATTERN (insn)) == ASM_INPUT
6490 || asm_noperands (PATTERN (insn)) >= 0
6491 || get_attr_length (insn) > 0)
6492 break;
6495 return FALSE;
6498 /* Return TRUE if INSN, a forward jump insn, needs a nop in its delay slot.
6500 This occurs when INSN has an unfilled delay slot and is followed
6501 by an asm. Disaster can occur if the asm is empty and the jump
6502 branches into the delay slot. So, we add a nop in the delay slot
6503 when this occurs. */
6505 static bool
6506 branch_needs_nop_p (rtx_insn *insn)
6508 rtx_insn *jump_insn;
6510 if (dbr_sequence_length ())
6511 return FALSE;
6513 jump_insn = next_active_insn (JUMP_LABEL_AS_INSN (insn));
6514 while (insn)
6516 insn = next_active_insn (insn);
6517 if (!insn || jump_insn == insn)
6518 return TRUE;
6520 if (!(GET_CODE (PATTERN (insn)) == ASM_INPUT
6521 || asm_noperands (PATTERN (insn)) >= 0)
6522 && get_attr_length (insn) > 0)
6523 break;
6526 return FALSE;
6529 /* Return TRUE if INSN, a forward jump insn, can use nullification
6530 to skip the following instruction. This avoids an extra cycle due
6531 to a mis-predicted branch when we fall through. */
6533 static bool
6534 use_skip_p (rtx_insn *insn)
6536 rtx_insn *jump_insn = next_active_insn (JUMP_LABEL_AS_INSN (insn));
6538 while (insn)
6540 insn = next_active_insn (insn);
6542 /* We can't rely on the length of asms, so we can't skip asms. */
6543 if (!insn
6544 || GET_CODE (PATTERN (insn)) == ASM_INPUT
6545 || asm_noperands (PATTERN (insn)) >= 0)
6546 break;
6547 if (get_attr_length (insn) == 4
6548 && jump_insn == next_active_insn (insn))
6549 return TRUE;
6550 if (get_attr_length (insn) > 0)
6551 break;
6554 return FALSE;
6557 /* This routine handles all the normal conditional branch sequences we
6558 might need to generate. It handles compare immediate vs compare
6559 register, nullification of delay slots, varying length branches,
6560 negated branches, and all combinations of the above. It returns the
6561 output appropriate to emit the branch corresponding to all given
6562 parameters. */
6564 const char *
6565 pa_output_cbranch (rtx *operands, int negated, rtx_insn *insn)
6567 static char buf[100];
6568 bool useskip;
6569 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6570 int length = get_attr_length (insn);
6571 int xdelay;
6573 /* A conditional branch to the following instruction (e.g. the delay slot)
6574 is asking for a disaster. This can happen when not optimizing and
6575 when jump optimization fails.
6577 While it is usually safe to emit nothing, this can fail if the
6578 preceding instruction is a nullified branch with an empty delay
6579 slot and the same branch target as this branch. We could check
6580 for this but jump optimization should eliminate nop jumps. It
6581 is always safe to emit a nop. */
6582 if (branch_to_delay_slot_p (insn))
6583 return "nop";
6585 /* The doubleword form of the cmpib instruction doesn't have the LEU
6586 and GTU conditions while the cmpb instruction does. Since we accept
6587 zero for cmpb, we must ensure that we use cmpb for the comparison. */
6588 if (GET_MODE (operands[1]) == DImode && operands[2] == const0_rtx)
6589 operands[2] = gen_rtx_REG (DImode, 0);
6590 if (GET_MODE (operands[2]) == DImode && operands[1] == const0_rtx)
6591 operands[1] = gen_rtx_REG (DImode, 0);
6593 /* If this is a long branch with its delay slot unfilled, set `nullify'
6594 as it can nullify the delay slot and save a nop. */
6595 if (length == 8 && dbr_sequence_length () == 0)
6596 nullify = 1;
6598 /* If this is a short forward conditional branch which did not get
6599 its delay slot filled, the delay slot can still be nullified. */
6600 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6601 nullify = forward_branch_p (insn);
6603 /* A forward branch over a single nullified insn can be done with a
6604 comclr instruction. This avoids a single cycle penalty due to
6605 mis-predicted branch if we fall through (branch not taken). */
6606 useskip = (length == 4 && nullify) ? use_skip_p (insn) : FALSE;
6608 switch (length)
6610 /* All short conditional branches except backwards with an unfilled
6611 delay slot. */
6612 case 4:
6613 if (useskip)
6614 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6615 else
6616 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6617 if (GET_MODE (operands[1]) == DImode)
6618 strcat (buf, "*");
6619 if (negated)
6620 strcat (buf, "%B3");
6621 else
6622 strcat (buf, "%S3");
6623 if (useskip)
6624 strcat (buf, " %2,%r1,%%r0");
6625 else if (nullify)
6627 if (branch_needs_nop_p (insn))
6628 strcat (buf, ",n %2,%r1,%0%#");
6629 else
6630 strcat (buf, ",n %2,%r1,%0");
6632 else
6633 strcat (buf, " %2,%r1,%0");
6634 break;
6636 /* All long conditionals. Note a short backward branch with an
6637 unfilled delay slot is treated just like a long backward branch
6638 with an unfilled delay slot. */
6639 case 8:
6640 /* Handle weird backwards branch with a filled delay slot
6641 which is nullified. */
6642 if (dbr_sequence_length () != 0
6643 && ! forward_branch_p (insn)
6644 && nullify)
6646 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6647 if (GET_MODE (operands[1]) == DImode)
6648 strcat (buf, "*");
6649 if (negated)
6650 strcat (buf, "%S3");
6651 else
6652 strcat (buf, "%B3");
6653 strcat (buf, ",n %2,%r1,.+12\n\tb %0");
6655 /* Handle short backwards branch with an unfilled delay slot.
6656 Using a comb;nop rather than comiclr;bl saves 1 cycle for both
6657 taken and untaken branches. */
6658 else if (dbr_sequence_length () == 0
6659 && ! forward_branch_p (insn)
6660 && INSN_ADDRESSES_SET_P ()
6661 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6662 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6664 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6665 if (GET_MODE (operands[1]) == DImode)
6666 strcat (buf, "*");
6667 if (negated)
6668 strcat (buf, "%B3 %2,%r1,%0%#");
6669 else
6670 strcat (buf, "%S3 %2,%r1,%0%#");
6672 else
6674 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6675 if (GET_MODE (operands[1]) == DImode)
6676 strcat (buf, "*");
6677 if (negated)
6678 strcat (buf, "%S3");
6679 else
6680 strcat (buf, "%B3");
6681 if (nullify)
6682 strcat (buf, " %2,%r1,%%r0\n\tb,n %0");
6683 else
6684 strcat (buf, " %2,%r1,%%r0\n\tb %0");
6686 break;
6688 default:
6689 /* The reversed conditional branch must branch over one additional
6690 instruction if the delay slot is filled and needs to be extracted
6691 by pa_output_lbranch. If the delay slot is empty or this is a
6692 nullified forward branch, the instruction after the reversed
6693 condition branch must be nullified. */
6694 if (dbr_sequence_length () == 0
6695 || (nullify && forward_branch_p (insn)))
6697 nullify = 1;
6698 xdelay = 0;
6699 operands[4] = GEN_INT (length);
6701 else
6703 xdelay = 1;
6704 operands[4] = GEN_INT (length + 4);
6707 /* Create a reversed conditional branch which branches around
6708 the following insns. */
6709 if (GET_MODE (operands[1]) != DImode)
6711 if (nullify)
6713 if (negated)
6714 strcpy (buf,
6715 "{com%I2b,%S3,n %2,%r1,.+%4|cmp%I2b,%S3,n %2,%r1,.+%4}");
6716 else
6717 strcpy (buf,
6718 "{com%I2b,%B3,n %2,%r1,.+%4|cmp%I2b,%B3,n %2,%r1,.+%4}");
6720 else
6722 if (negated)
6723 strcpy (buf,
6724 "{com%I2b,%S3 %2,%r1,.+%4|cmp%I2b,%S3 %2,%r1,.+%4}");
6725 else
6726 strcpy (buf,
6727 "{com%I2b,%B3 %2,%r1,.+%4|cmp%I2b,%B3 %2,%r1,.+%4}");
6730 else
6732 if (nullify)
6734 if (negated)
6735 strcpy (buf,
6736 "{com%I2b,*%S3,n %2,%r1,.+%4|cmp%I2b,*%S3,n %2,%r1,.+%4}");
6737 else
6738 strcpy (buf,
6739 "{com%I2b,*%B3,n %2,%r1,.+%4|cmp%I2b,*%B3,n %2,%r1,.+%4}");
6741 else
6743 if (negated)
6744 strcpy (buf,
6745 "{com%I2b,*%S3 %2,%r1,.+%4|cmp%I2b,*%S3 %2,%r1,.+%4}");
6746 else
6747 strcpy (buf,
6748 "{com%I2b,*%B3 %2,%r1,.+%4|cmp%I2b,*%B3 %2,%r1,.+%4}");
6752 output_asm_insn (buf, operands);
6753 return pa_output_lbranch (operands[0], insn, xdelay);
6755 return buf;
6758 /* Output a PIC pc-relative instruction sequence to load the address of
6759 OPERANDS[0] to register OPERANDS[2]. OPERANDS[0] is a symbol ref
6760 or a code label. OPERANDS[1] specifies the register to use to load
6761 the program counter. OPERANDS[3] may be used for label generation
6762 The sequence is always three instructions in length. The program
6763 counter recorded for PA 1.X is eight bytes more than that for PA 2.0.
6764 Register %r1 is clobbered. */
6766 static void
6767 pa_output_pic_pcrel_sequence (rtx *operands)
6769 gcc_assert (SYMBOL_REF_P (operands[0]) || LABEL_P (operands[0]));
6770 if (TARGET_PA_20)
6772 /* We can use mfia to determine the current program counter. */
6773 if (TARGET_SOM || !TARGET_GAS)
6775 operands[3] = gen_label_rtx ();
6776 targetm.asm_out.internal_label (asm_out_file, "L",
6777 CODE_LABEL_NUMBER (operands[3]));
6778 output_asm_insn ("mfia %1", operands);
6779 output_asm_insn ("addil L'%0-%l3,%1", operands);
6780 output_asm_insn ("ldo R'%0-%l3(%%r1),%2", operands);
6782 else
6784 output_asm_insn ("mfia %1", operands);
6785 output_asm_insn ("addil L'%0-$PIC_pcrel$0+12,%1", operands);
6786 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+16(%%r1),%2", operands);
6789 else
6791 /* We need to use a branch to determine the current program counter. */
6792 output_asm_insn ("{bl|b,l} .+8,%1", operands);
6793 if (TARGET_SOM || !TARGET_GAS)
6795 operands[3] = gen_label_rtx ();
6796 output_asm_insn ("addil L'%0-%l3,%1", operands);
6797 targetm.asm_out.internal_label (asm_out_file, "L",
6798 CODE_LABEL_NUMBER (operands[3]));
6799 output_asm_insn ("ldo R'%0-%l3(%%r1),%2", operands);
6801 else
6803 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%1", operands);
6804 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%2", operands);
6809 /* This routine handles output of long unconditional branches that
6810 exceed the maximum range of a simple branch instruction. Since
6811 we don't have a register available for the branch, we save register
6812 %r1 in the frame marker, load the branch destination DEST into %r1,
6813 execute the branch, and restore %r1 in the delay slot of the branch.
6815 Since long branches may have an insn in the delay slot and the
6816 delay slot is used to restore %r1, we in general need to extract
6817 this insn and execute it before the branch. However, to facilitate
6818 use of this function by conditional branches, we also provide an
6819 option to not extract the delay insn so that it will be emitted
6820 after the long branch. So, if there is an insn in the delay slot,
6821 it is extracted if XDELAY is nonzero.
6823 The lengths of the various long-branch sequences are 20, 16 and 24
6824 bytes for the portable runtime, non-PIC and PIC cases, respectively. */
6826 const char *
6827 pa_output_lbranch (rtx dest, rtx_insn *insn, int xdelay)
6829 rtx xoperands[4];
6831 xoperands[0] = dest;
6833 /* First, free up the delay slot. */
6834 if (xdelay && dbr_sequence_length () != 0)
6836 /* We can't handle a jump in the delay slot. */
6837 gcc_assert (! JUMP_P (NEXT_INSN (insn)));
6839 final_scan_insn (NEXT_INSN (insn), asm_out_file,
6840 optimize, 0, NULL);
6842 /* Now delete the delay insn. */
6843 SET_INSN_DELETED (NEXT_INSN (insn));
6846 /* Output an insn to save %r1. The runtime documentation doesn't
6847 specify whether the "Clean Up" slot in the callers frame can
6848 be clobbered by the callee. It isn't copied by HP's builtin
6849 alloca, so this suggests that it can be clobbered if necessary.
6850 The "Static Link" location is copied by HP builtin alloca, so
6851 we avoid using it. Using the cleanup slot might be a problem
6852 if we have to interoperate with languages that pass cleanup
6853 information. However, it should be possible to handle these
6854 situations with GCC's asm feature.
6856 The "Current RP" slot is reserved for the called procedure, so
6857 we try to use it when we don't have a frame of our own. It's
6858 rather unlikely that we won't have a frame when we need to emit
6859 a very long branch.
6861 Really the way to go long term is a register scavenger; goto
6862 the target of the jump and find a register which we can use
6863 as a scratch to hold the value in %r1. Then, we wouldn't have
6864 to free up the delay slot or clobber a slot that may be needed
6865 for other purposes. */
6866 if (TARGET_64BIT)
6868 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
6869 /* Use the return pointer slot in the frame marker. */
6870 output_asm_insn ("std %%r1,-16(%%r30)", xoperands);
6871 else
6872 /* Use the slot at -40 in the frame marker since HP builtin
6873 alloca doesn't copy it. */
6874 output_asm_insn ("std %%r1,-40(%%r30)", xoperands);
6876 else
6878 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
6879 /* Use the return pointer slot in the frame marker. */
6880 output_asm_insn ("stw %%r1,-20(%%r30)", xoperands);
6881 else
6882 /* Use the "Clean Up" slot in the frame marker. In GCC,
6883 the only other use of this location is for copying a
6884 floating point double argument from a floating-point
6885 register to two general registers. The copy is done
6886 as an "atomic" operation when outputting a call, so it
6887 won't interfere with our using the location here. */
6888 output_asm_insn ("stw %%r1,-12(%%r30)", xoperands);
6891 if (TARGET_PORTABLE_RUNTIME)
6893 output_asm_insn ("ldil L'%0,%%r1", xoperands);
6894 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
6895 output_asm_insn ("bv %%r0(%%r1)", xoperands);
6897 else if (flag_pic)
6899 xoperands[1] = gen_rtx_REG (Pmode, 1);
6900 xoperands[2] = xoperands[1];
6901 pa_output_pic_pcrel_sequence (xoperands);
6902 output_asm_insn ("bv %%r0(%%r1)", xoperands);
6904 else
6905 /* Now output a very long branch to the original target. */
6906 output_asm_insn ("ldil L'%l0,%%r1\n\tbe R'%l0(%%sr4,%%r1)", xoperands);
6908 /* Now restore the value of %r1 in the delay slot. */
6909 if (TARGET_64BIT)
6911 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
6912 return "ldd -16(%%r30),%%r1";
6913 else
6914 return "ldd -40(%%r30),%%r1";
6916 else
6918 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
6919 return "ldw -20(%%r30),%%r1";
6920 else
6921 return "ldw -12(%%r30),%%r1";
6925 /* This routine handles all the branch-on-bit conditional branch sequences we
6926 might need to generate. It handles nullification of delay slots,
6927 varying length branches, negated branches and all combinations of the
6928 above. it returns the appropriate output template to emit the branch. */
6930 const char *
6931 pa_output_bb (rtx *operands ATTRIBUTE_UNUSED, int negated, rtx_insn *insn, int which)
6933 static char buf[100];
6934 bool useskip;
6935 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6936 int length = get_attr_length (insn);
6937 int xdelay;
6939 /* A conditional branch to the following instruction (e.g. the delay slot) is
6940 asking for a disaster. I do not think this can happen as this pattern
6941 is only used when optimizing; jump optimization should eliminate the
6942 jump. But be prepared just in case. */
6944 if (branch_to_delay_slot_p (insn))
6945 return "nop";
6947 /* If this is a long branch with its delay slot unfilled, set `nullify'
6948 as it can nullify the delay slot and save a nop. */
6949 if (length == 8 && dbr_sequence_length () == 0)
6950 nullify = 1;
6952 /* If this is a short forward conditional branch which did not get
6953 its delay slot filled, the delay slot can still be nullified. */
6954 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6955 nullify = forward_branch_p (insn);
6957 /* A forward branch over a single nullified insn can be done with a
6958 extrs instruction. This avoids a single cycle penalty due to
6959 mis-predicted branch if we fall through (branch not taken). */
6960 useskip = (length == 4 && nullify) ? use_skip_p (insn) : FALSE;
6962 switch (length)
6965 /* All short conditional branches except backwards with an unfilled
6966 delay slot. */
6967 case 4:
6968 if (useskip)
6969 strcpy (buf, "{extrs,|extrw,s,}");
6970 else
6971 strcpy (buf, "bb,");
6972 if (useskip && GET_MODE (operands[0]) == DImode)
6973 strcpy (buf, "extrd,s,*");
6974 else if (GET_MODE (operands[0]) == DImode)
6975 strcpy (buf, "bb,*");
6976 if ((which == 0 && negated)
6977 || (which == 1 && ! negated))
6978 strcat (buf, ">=");
6979 else
6980 strcat (buf, "<");
6981 if (useskip)
6982 strcat (buf, " %0,%1,1,%%r0");
6983 else if (nullify && negated)
6985 if (branch_needs_nop_p (insn))
6986 strcat (buf, ",n %0,%1,%3%#");
6987 else
6988 strcat (buf, ",n %0,%1,%3");
6990 else if (nullify && ! negated)
6992 if (branch_needs_nop_p (insn))
6993 strcat (buf, ",n %0,%1,%2%#");
6994 else
6995 strcat (buf, ",n %0,%1,%2");
6997 else if (! nullify && negated)
6998 strcat (buf, " %0,%1,%3");
6999 else if (! nullify && ! negated)
7000 strcat (buf, " %0,%1,%2");
7001 break;
7003 /* All long conditionals. Note a short backward branch with an
7004 unfilled delay slot is treated just like a long backward branch
7005 with an unfilled delay slot. */
7006 case 8:
7007 /* Handle weird backwards branch with a filled delay slot
7008 which is nullified. */
7009 if (dbr_sequence_length () != 0
7010 && ! forward_branch_p (insn)
7011 && nullify)
7013 strcpy (buf, "bb,");
7014 if (GET_MODE (operands[0]) == DImode)
7015 strcat (buf, "*");
7016 if ((which == 0 && negated)
7017 || (which == 1 && ! negated))
7018 strcat (buf, "<");
7019 else
7020 strcat (buf, ">=");
7021 if (negated)
7022 strcat (buf, ",n %0,%1,.+12\n\tb %3");
7023 else
7024 strcat (buf, ",n %0,%1,.+12\n\tb %2");
7026 /* Handle short backwards branch with an unfilled delay slot.
7027 Using a bb;nop rather than extrs;bl saves 1 cycle for both
7028 taken and untaken branches. */
7029 else if (dbr_sequence_length () == 0
7030 && ! forward_branch_p (insn)
7031 && INSN_ADDRESSES_SET_P ()
7032 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7033 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7035 strcpy (buf, "bb,");
7036 if (GET_MODE (operands[0]) == DImode)
7037 strcat (buf, "*");
7038 if ((which == 0 && negated)
7039 || (which == 1 && ! negated))
7040 strcat (buf, ">=");
7041 else
7042 strcat (buf, "<");
7043 if (negated)
7044 strcat (buf, " %0,%1,%3%#");
7045 else
7046 strcat (buf, " %0,%1,%2%#");
7048 else
7050 if (GET_MODE (operands[0]) == DImode)
7051 strcpy (buf, "extrd,s,*");
7052 else
7053 strcpy (buf, "{extrs,|extrw,s,}");
7054 if ((which == 0 && negated)
7055 || (which == 1 && ! negated))
7056 strcat (buf, "<");
7057 else
7058 strcat (buf, ">=");
7059 if (nullify && negated)
7060 strcat (buf, " %0,%1,1,%%r0\n\tb,n %3");
7061 else if (nullify && ! negated)
7062 strcat (buf, " %0,%1,1,%%r0\n\tb,n %2");
7063 else if (negated)
7064 strcat (buf, " %0,%1,1,%%r0\n\tb %3");
7065 else
7066 strcat (buf, " %0,%1,1,%%r0\n\tb %2");
7068 break;
7070 default:
7071 /* The reversed conditional branch must branch over one additional
7072 instruction if the delay slot is filled and needs to be extracted
7073 by pa_output_lbranch. If the delay slot is empty or this is a
7074 nullified forward branch, the instruction after the reversed
7075 condition branch must be nullified. */
7076 if (dbr_sequence_length () == 0
7077 || (nullify && forward_branch_p (insn)))
7079 nullify = 1;
7080 xdelay = 0;
7081 operands[4] = GEN_INT (length);
7083 else
7085 xdelay = 1;
7086 operands[4] = GEN_INT (length + 4);
7089 if (GET_MODE (operands[0]) == DImode)
7090 strcpy (buf, "bb,*");
7091 else
7092 strcpy (buf, "bb,");
7093 if ((which == 0 && negated)
7094 || (which == 1 && !negated))
7095 strcat (buf, "<");
7096 else
7097 strcat (buf, ">=");
7098 if (nullify)
7099 strcat (buf, ",n %0,%1,.+%4");
7100 else
7101 strcat (buf, " %0,%1,.+%4");
7102 output_asm_insn (buf, operands);
7103 return pa_output_lbranch (negated ? operands[3] : operands[2],
7104 insn, xdelay);
7106 return buf;
7109 /* This routine handles all the branch-on-variable-bit conditional branch
7110 sequences we might need to generate. It handles nullification of delay
7111 slots, varying length branches, negated branches and all combinations
7112 of the above. it returns the appropriate output template to emit the
7113 branch. */
7115 const char *
7116 pa_output_bvb (rtx *operands ATTRIBUTE_UNUSED, int negated, rtx_insn *insn,
7117 int which)
7119 static char buf[100];
7120 bool useskip;
7121 int nullify = INSN_ANNULLED_BRANCH_P (insn);
7122 int length = get_attr_length (insn);
7123 int xdelay;
7125 /* A conditional branch to the following instruction (e.g. the delay slot) is
7126 asking for a disaster. I do not think this can happen as this pattern
7127 is only used when optimizing; jump optimization should eliminate the
7128 jump. But be prepared just in case. */
7130 if (branch_to_delay_slot_p (insn))
7131 return "nop";
7133 /* If this is a long branch with its delay slot unfilled, set `nullify'
7134 as it can nullify the delay slot and save a nop. */
7135 if (length == 8 && dbr_sequence_length () == 0)
7136 nullify = 1;
7138 /* If this is a short forward conditional branch which did not get
7139 its delay slot filled, the delay slot can still be nullified. */
7140 if (! nullify && length == 4 && dbr_sequence_length () == 0)
7141 nullify = forward_branch_p (insn);
7143 /* A forward branch over a single nullified insn can be done with a
7144 extrs instruction. This avoids a single cycle penalty due to
7145 mis-predicted branch if we fall through (branch not taken). */
7146 useskip = (length == 4 && nullify) ? use_skip_p (insn) : FALSE;
7148 switch (length)
7151 /* All short conditional branches except backwards with an unfilled
7152 delay slot. */
7153 case 4:
7154 if (useskip)
7155 strcpy (buf, "{vextrs,|extrw,s,}");
7156 else
7157 strcpy (buf, "{bvb,|bb,}");
7158 if (useskip && GET_MODE (operands[0]) == DImode)
7159 strcpy (buf, "extrd,s,*");
7160 else if (GET_MODE (operands[0]) == DImode)
7161 strcpy (buf, "bb,*");
7162 if ((which == 0 && negated)
7163 || (which == 1 && ! negated))
7164 strcat (buf, ">=");
7165 else
7166 strcat (buf, "<");
7167 if (useskip)
7168 strcat (buf, "{ %0,1,%%r0| %0,%%sar,1,%%r0}");
7169 else if (nullify && negated)
7171 if (branch_needs_nop_p (insn))
7172 strcat (buf, "{,n %0,%3%#|,n %0,%%sar,%3%#}");
7173 else
7174 strcat (buf, "{,n %0,%3|,n %0,%%sar,%3}");
7176 else if (nullify && ! negated)
7178 if (branch_needs_nop_p (insn))
7179 strcat (buf, "{,n %0,%2%#|,n %0,%%sar,%2%#}");
7180 else
7181 strcat (buf, "{,n %0,%2|,n %0,%%sar,%2}");
7183 else if (! nullify && negated)
7184 strcat (buf, "{ %0,%3| %0,%%sar,%3}");
7185 else if (! nullify && ! negated)
7186 strcat (buf, "{ %0,%2| %0,%%sar,%2}");
7187 break;
7189 /* All long conditionals. Note a short backward branch with an
7190 unfilled delay slot is treated just like a long backward branch
7191 with an unfilled delay slot. */
7192 case 8:
7193 /* Handle weird backwards branch with a filled delay slot
7194 which is nullified. */
7195 if (dbr_sequence_length () != 0
7196 && ! forward_branch_p (insn)
7197 && nullify)
7199 strcpy (buf, "{bvb,|bb,}");
7200 if (GET_MODE (operands[0]) == DImode)
7201 strcat (buf, "*");
7202 if ((which == 0 && negated)
7203 || (which == 1 && ! negated))
7204 strcat (buf, "<");
7205 else
7206 strcat (buf, ">=");
7207 if (negated)
7208 strcat (buf, "{,n %0,.+12\n\tb %3|,n %0,%%sar,.+12\n\tb %3}");
7209 else
7210 strcat (buf, "{,n %0,.+12\n\tb %2|,n %0,%%sar,.+12\n\tb %2}");
7212 /* Handle short backwards branch with an unfilled delay slot.
7213 Using a bb;nop rather than extrs;bl saves 1 cycle for both
7214 taken and untaken branches. */
7215 else if (dbr_sequence_length () == 0
7216 && ! forward_branch_p (insn)
7217 && INSN_ADDRESSES_SET_P ()
7218 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7219 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7221 strcpy (buf, "{bvb,|bb,}");
7222 if (GET_MODE (operands[0]) == DImode)
7223 strcat (buf, "*");
7224 if ((which == 0 && negated)
7225 || (which == 1 && ! negated))
7226 strcat (buf, ">=");
7227 else
7228 strcat (buf, "<");
7229 if (negated)
7230 strcat (buf, "{ %0,%3%#| %0,%%sar,%3%#}");
7231 else
7232 strcat (buf, "{ %0,%2%#| %0,%%sar,%2%#}");
7234 else
7236 strcpy (buf, "{vextrs,|extrw,s,}");
7237 if (GET_MODE (operands[0]) == DImode)
7238 strcpy (buf, "extrd,s,*");
7239 if ((which == 0 && negated)
7240 || (which == 1 && ! negated))
7241 strcat (buf, "<");
7242 else
7243 strcat (buf, ">=");
7244 if (nullify && negated)
7245 strcat (buf, "{ %0,1,%%r0\n\tb,n %3| %0,%%sar,1,%%r0\n\tb,n %3}");
7246 else if (nullify && ! negated)
7247 strcat (buf, "{ %0,1,%%r0\n\tb,n %2| %0,%%sar,1,%%r0\n\tb,n %2}");
7248 else if (negated)
7249 strcat (buf, "{ %0,1,%%r0\n\tb %3| %0,%%sar,1,%%r0\n\tb %3}");
7250 else
7251 strcat (buf, "{ %0,1,%%r0\n\tb %2| %0,%%sar,1,%%r0\n\tb %2}");
7253 break;
7255 default:
7256 /* The reversed conditional branch must branch over one additional
7257 instruction if the delay slot is filled and needs to be extracted
7258 by pa_output_lbranch. If the delay slot is empty or this is a
7259 nullified forward branch, the instruction after the reversed
7260 condition branch must be nullified. */
7261 if (dbr_sequence_length () == 0
7262 || (nullify && forward_branch_p (insn)))
7264 nullify = 1;
7265 xdelay = 0;
7266 operands[4] = GEN_INT (length);
7268 else
7270 xdelay = 1;
7271 operands[4] = GEN_INT (length + 4);
7274 if (GET_MODE (operands[0]) == DImode)
7275 strcpy (buf, "bb,*");
7276 else
7277 strcpy (buf, "{bvb,|bb,}");
7278 if ((which == 0 && negated)
7279 || (which == 1 && !negated))
7280 strcat (buf, "<");
7281 else
7282 strcat (buf, ">=");
7283 if (nullify)
7284 strcat (buf, ",n {%0,.+%4|%0,%%sar,.+%4}");
7285 else
7286 strcat (buf, " {%0,.+%4|%0,%%sar,.+%4}");
7287 output_asm_insn (buf, operands);
7288 return pa_output_lbranch (negated ? operands[3] : operands[2],
7289 insn, xdelay);
7291 return buf;
7294 /* Return the output template for emitting a dbra type insn.
7296 Note it may perform some output operations on its own before
7297 returning the final output string. */
7298 const char *
7299 pa_output_dbra (rtx *operands, rtx_insn *insn, int which_alternative)
7301 int length = get_attr_length (insn);
7303 /* A conditional branch to the following instruction (e.g. the delay slot) is
7304 asking for a disaster. Be prepared! */
7306 if (branch_to_delay_slot_p (insn))
7308 if (which_alternative == 0)
7309 return "ldo %1(%0),%0";
7310 else if (which_alternative == 1)
7312 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)", operands);
7313 output_asm_insn ("ldw -16(%%r30),%4", operands);
7314 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
7315 return "{fldws|fldw} -16(%%r30),%0";
7317 else
7319 output_asm_insn ("ldw %0,%4", operands);
7320 return "ldo %1(%4),%4\n\tstw %4,%0";
7324 if (which_alternative == 0)
7326 int nullify = INSN_ANNULLED_BRANCH_P (insn);
7327 int xdelay;
7329 /* If this is a long branch with its delay slot unfilled, set `nullify'
7330 as it can nullify the delay slot and save a nop. */
7331 if (length == 8 && dbr_sequence_length () == 0)
7332 nullify = 1;
7334 /* If this is a short forward conditional branch which did not get
7335 its delay slot filled, the delay slot can still be nullified. */
7336 if (! nullify && length == 4 && dbr_sequence_length () == 0)
7337 nullify = forward_branch_p (insn);
7339 switch (length)
7341 case 4:
7342 if (nullify)
7344 if (branch_needs_nop_p (insn))
7345 return "addib,%C2,n %1,%0,%3%#";
7346 else
7347 return "addib,%C2,n %1,%0,%3";
7349 else
7350 return "addib,%C2 %1,%0,%3";
7352 case 8:
7353 /* Handle weird backwards branch with a fulled delay slot
7354 which is nullified. */
7355 if (dbr_sequence_length () != 0
7356 && ! forward_branch_p (insn)
7357 && nullify)
7358 return "addib,%N2,n %1,%0,.+12\n\tb %3";
7359 /* Handle short backwards branch with an unfilled delay slot.
7360 Using a addb;nop rather than addi;bl saves 1 cycle for both
7361 taken and untaken branches. */
7362 else if (dbr_sequence_length () == 0
7363 && ! forward_branch_p (insn)
7364 && INSN_ADDRESSES_SET_P ()
7365 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7366 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7367 return "addib,%C2 %1,%0,%3%#";
7369 /* Handle normal cases. */
7370 if (nullify)
7371 return "addi,%N2 %1,%0,%0\n\tb,n %3";
7372 else
7373 return "addi,%N2 %1,%0,%0\n\tb %3";
7375 default:
7376 /* The reversed conditional branch must branch over one additional
7377 instruction if the delay slot is filled and needs to be extracted
7378 by pa_output_lbranch. If the delay slot is empty or this is a
7379 nullified forward branch, the instruction after the reversed
7380 condition branch must be nullified. */
7381 if (dbr_sequence_length () == 0
7382 || (nullify && forward_branch_p (insn)))
7384 nullify = 1;
7385 xdelay = 0;
7386 operands[4] = GEN_INT (length);
7388 else
7390 xdelay = 1;
7391 operands[4] = GEN_INT (length + 4);
7394 if (nullify)
7395 output_asm_insn ("addib,%N2,n %1,%0,.+%4", operands);
7396 else
7397 output_asm_insn ("addib,%N2 %1,%0,.+%4", operands);
7399 return pa_output_lbranch (operands[3], insn, xdelay);
7403 /* Deal with gross reload from FP register case. */
7404 else if (which_alternative == 1)
7406 /* Move loop counter from FP register to MEM then into a GR,
7407 increment the GR, store the GR into MEM, and finally reload
7408 the FP register from MEM from within the branch's delay slot. */
7409 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)\n\tldw -16(%%r30),%4",
7410 operands);
7411 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
7412 if (length == 24)
7413 return "{comb|cmpb},%S2 %%r0,%4,%3\n\t{fldws|fldw} -16(%%r30),%0";
7414 else if (length == 28)
7415 return "{comclr|cmpclr},%B2 %%r0,%4,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
7416 else
7418 operands[5] = GEN_INT (length - 16);
7419 output_asm_insn ("{comb|cmpb},%B2 %%r0,%4,.+%5", operands);
7420 output_asm_insn ("{fldws|fldw} -16(%%r30),%0", operands);
7421 return pa_output_lbranch (operands[3], insn, 0);
7424 /* Deal with gross reload from memory case. */
7425 else
7427 /* Reload loop counter from memory, the store back to memory
7428 happens in the branch's delay slot. */
7429 output_asm_insn ("ldw %0,%4", operands);
7430 if (length == 12)
7431 return "addib,%C2 %1,%4,%3\n\tstw %4,%0";
7432 else if (length == 16)
7433 return "addi,%N2 %1,%4,%4\n\tb %3\n\tstw %4,%0";
7434 else
7436 operands[5] = GEN_INT (length - 4);
7437 output_asm_insn ("addib,%N2 %1,%4,.+%5\n\tstw %4,%0", operands);
7438 return pa_output_lbranch (operands[3], insn, 0);
7443 /* Return the output template for emitting a movb type insn.
7445 Note it may perform some output operations on its own before
7446 returning the final output string. */
7447 const char *
7448 pa_output_movb (rtx *operands, rtx_insn *insn, int which_alternative,
7449 int reverse_comparison)
7451 int length = get_attr_length (insn);
7453 /* A conditional branch to the following instruction (e.g. the delay slot) is
7454 asking for a disaster. Be prepared! */
7456 if (branch_to_delay_slot_p (insn))
7458 if (which_alternative == 0)
7459 return "copy %1,%0";
7460 else if (which_alternative == 1)
7462 output_asm_insn ("stw %1,-16(%%r30)", operands);
7463 return "{fldws|fldw} -16(%%r30),%0";
7465 else if (which_alternative == 2)
7466 return "stw %1,%0";
7467 else
7468 return "mtsar %r1";
7471 /* Support the second variant. */
7472 if (reverse_comparison)
7473 PUT_CODE (operands[2], reverse_condition (GET_CODE (operands[2])));
7475 if (which_alternative == 0)
7477 int nullify = INSN_ANNULLED_BRANCH_P (insn);
7478 int xdelay;
7480 /* If this is a long branch with its delay slot unfilled, set `nullify'
7481 as it can nullify the delay slot and save a nop. */
7482 if (length == 8 && dbr_sequence_length () == 0)
7483 nullify = 1;
7485 /* If this is a short forward conditional branch which did not get
7486 its delay slot filled, the delay slot can still be nullified. */
7487 if (! nullify && length == 4 && dbr_sequence_length () == 0)
7488 nullify = forward_branch_p (insn);
7490 switch (length)
7492 case 4:
7493 if (nullify)
7495 if (branch_needs_nop_p (insn))
7496 return "movb,%C2,n %1,%0,%3%#";
7497 else
7498 return "movb,%C2,n %1,%0,%3";
7500 else
7501 return "movb,%C2 %1,%0,%3";
7503 case 8:
7504 /* Handle weird backwards branch with a filled delay slot
7505 which is nullified. */
7506 if (dbr_sequence_length () != 0
7507 && ! forward_branch_p (insn)
7508 && nullify)
7509 return "movb,%N2,n %1,%0,.+12\n\tb %3";
7511 /* Handle short backwards branch with an unfilled delay slot.
7512 Using a movb;nop rather than or;bl saves 1 cycle for both
7513 taken and untaken branches. */
7514 else if (dbr_sequence_length () == 0
7515 && ! forward_branch_p (insn)
7516 && INSN_ADDRESSES_SET_P ()
7517 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7518 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7519 return "movb,%C2 %1,%0,%3%#";
7520 /* Handle normal cases. */
7521 if (nullify)
7522 return "or,%N2 %1,%%r0,%0\n\tb,n %3";
7523 else
7524 return "or,%N2 %1,%%r0,%0\n\tb %3";
7526 default:
7527 /* The reversed conditional branch must branch over one additional
7528 instruction if the delay slot is filled and needs to be extracted
7529 by pa_output_lbranch. If the delay slot is empty or this is a
7530 nullified forward branch, the instruction after the reversed
7531 condition branch must be nullified. */
7532 if (dbr_sequence_length () == 0
7533 || (nullify && forward_branch_p (insn)))
7535 nullify = 1;
7536 xdelay = 0;
7537 operands[4] = GEN_INT (length);
7539 else
7541 xdelay = 1;
7542 operands[4] = GEN_INT (length + 4);
7545 if (nullify)
7546 output_asm_insn ("movb,%N2,n %1,%0,.+%4", operands);
7547 else
7548 output_asm_insn ("movb,%N2 %1,%0,.+%4", operands);
7550 return pa_output_lbranch (operands[3], insn, xdelay);
7553 /* Deal with gross reload for FP destination register case. */
7554 else if (which_alternative == 1)
7556 /* Move source register to MEM, perform the branch test, then
7557 finally load the FP register from MEM from within the branch's
7558 delay slot. */
7559 output_asm_insn ("stw %1,-16(%%r30)", operands);
7560 if (length == 12)
7561 return "{comb|cmpb},%S2 %%r0,%1,%3\n\t{fldws|fldw} -16(%%r30),%0";
7562 else if (length == 16)
7563 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
7564 else
7566 operands[4] = GEN_INT (length - 4);
7567 output_asm_insn ("{comb|cmpb},%B2 %%r0,%1,.+%4", operands);
7568 output_asm_insn ("{fldws|fldw} -16(%%r30),%0", operands);
7569 return pa_output_lbranch (operands[3], insn, 0);
7572 /* Deal with gross reload from memory case. */
7573 else if (which_alternative == 2)
7575 /* Reload loop counter from memory, the store back to memory
7576 happens in the branch's delay slot. */
7577 if (length == 8)
7578 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tstw %1,%0";
7579 else if (length == 12)
7580 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tstw %1,%0";
7581 else
7583 operands[4] = GEN_INT (length);
7584 output_asm_insn ("{comb|cmpb},%B2 %%r0,%1,.+%4\n\tstw %1,%0",
7585 operands);
7586 return pa_output_lbranch (operands[3], insn, 0);
7589 /* Handle SAR as a destination. */
7590 else
7592 if (length == 8)
7593 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tmtsar %r1";
7594 else if (length == 12)
7595 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tmtsar %r1";
7596 else
7598 operands[4] = GEN_INT (length);
7599 output_asm_insn ("{comb|cmpb},%B2 %%r0,%1,.+%4\n\tmtsar %r1",
7600 operands);
7601 return pa_output_lbranch (operands[3], insn, 0);
7606 /* Copy any FP arguments in INSN into integer registers. */
7607 static void
7608 copy_fp_args (rtx_insn *insn)
7610 rtx link;
7611 rtx xoperands[2];
7613 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7615 int arg_mode, regno;
7616 rtx use = XEXP (link, 0);
7618 if (! (GET_CODE (use) == USE
7619 && GET_CODE (XEXP (use, 0)) == REG
7620 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7621 continue;
7623 arg_mode = GET_MODE (XEXP (use, 0));
7624 regno = REGNO (XEXP (use, 0));
7626 /* Is it a floating point register? */
7627 if (regno >= 32 && regno <= 39)
7629 /* Copy the FP register into an integer register via memory. */
7630 if (arg_mode == SFmode)
7632 xoperands[0] = XEXP (use, 0);
7633 xoperands[1] = gen_rtx_REG (SImode, 26 - (regno - 32) / 2);
7634 output_asm_insn ("{fstws|fstw} %0,-16(%%sr0,%%r30)", xoperands);
7635 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7637 else
7639 xoperands[0] = XEXP (use, 0);
7640 xoperands[1] = gen_rtx_REG (DImode, 25 - (regno - 34) / 2);
7641 output_asm_insn ("{fstds|fstd} %0,-16(%%sr0,%%r30)", xoperands);
7642 output_asm_insn ("ldw -12(%%sr0,%%r30),%R1", xoperands);
7643 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7649 /* Compute length of the FP argument copy sequence for INSN. */
7650 static int
7651 length_fp_args (rtx_insn *insn)
7653 int length = 0;
7654 rtx link;
7656 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7658 int arg_mode, regno;
7659 rtx use = XEXP (link, 0);
7661 if (! (GET_CODE (use) == USE
7662 && GET_CODE (XEXP (use, 0)) == REG
7663 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7664 continue;
7666 arg_mode = GET_MODE (XEXP (use, 0));
7667 regno = REGNO (XEXP (use, 0));
7669 /* Is it a floating point register? */
7670 if (regno >= 32 && regno <= 39)
7672 if (arg_mode == SFmode)
7673 length += 8;
7674 else
7675 length += 12;
7679 return length;
7682 /* Return the attribute length for the millicode call instruction INSN.
7683 The length must match the code generated by pa_output_millicode_call.
7684 We include the delay slot in the returned length as it is better to
7685 over estimate the length than to under estimate it. */
7688 pa_attr_length_millicode_call (rtx_insn *insn)
7690 unsigned long distance = -1;
7691 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7693 if (INSN_ADDRESSES_SET_P ())
7695 distance = (total + insn_current_reference_address (insn));
7696 if (distance < total)
7697 distance = -1;
7700 if (TARGET_64BIT)
7702 if (!TARGET_LONG_CALLS && distance < 7600000)
7703 return 8;
7705 return 20;
7707 else if (TARGET_PORTABLE_RUNTIME)
7708 return 24;
7709 else
7711 if (!TARGET_LONG_CALLS && distance < MAX_PCREL17F_OFFSET)
7712 return 8;
7714 if (!flag_pic)
7715 return 12;
7717 return 24;
7721 /* INSN is a function call.
7723 CALL_DEST is the routine we are calling. */
7725 const char *
7726 pa_output_millicode_call (rtx_insn *insn, rtx call_dest)
7728 int attr_length = get_attr_length (insn);
7729 int seq_length = dbr_sequence_length ();
7730 rtx xoperands[4];
7732 xoperands[0] = call_dest;
7734 /* Handle the common case where we are sure that the branch will
7735 reach the beginning of the $CODE$ subspace. The within reach
7736 form of the $$sh_func_adrs call has a length of 28. Because it
7737 has an attribute type of sh_func_adrs, it never has a nonzero
7738 sequence length (i.e., the delay slot is never filled). */
7739 if (!TARGET_LONG_CALLS
7740 && (attr_length == 8
7741 || (attr_length == 28
7742 && get_attr_type (insn) == TYPE_SH_FUNC_ADRS)))
7744 xoperands[1] = gen_rtx_REG (Pmode, TARGET_64BIT ? 2 : 31);
7745 output_asm_insn ("{bl|b,l} %0,%1", xoperands);
7747 else
7749 if (TARGET_64BIT)
7751 /* It might seem that one insn could be saved by accessing
7752 the millicode function using the linkage table. However,
7753 this doesn't work in shared libraries and other dynamically
7754 loaded objects. Using a pc-relative sequence also avoids
7755 problems related to the implicit use of the gp register. */
7756 xoperands[1] = gen_rtx_REG (Pmode, 1);
7757 xoperands[2] = xoperands[1];
7758 pa_output_pic_pcrel_sequence (xoperands);
7759 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7761 else if (TARGET_PORTABLE_RUNTIME)
7763 /* Pure portable runtime doesn't allow be/ble; we also don't
7764 have PIC support in the assembler/linker, so this sequence
7765 is needed. */
7767 /* Get the address of our target into %r1. */
7768 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7769 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
7771 /* Get our return address into %r31. */
7772 output_asm_insn ("{bl|b,l} .+8,%%r31", xoperands);
7773 output_asm_insn ("addi 8,%%r31,%%r31", xoperands);
7775 /* Jump to our target address in %r1. */
7776 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7778 else if (!flag_pic)
7780 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7781 if (TARGET_PA_20)
7782 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31", xoperands);
7783 else
7784 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
7786 else
7788 xoperands[1] = gen_rtx_REG (Pmode, 31);
7789 xoperands[2] = gen_rtx_REG (Pmode, 1);
7790 pa_output_pic_pcrel_sequence (xoperands);
7792 /* Adjust return address. */
7793 output_asm_insn ("ldo {16|24}(%%r31),%%r31", xoperands);
7795 /* Jump to our target address in %r1. */
7796 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7800 if (seq_length == 0)
7801 output_asm_insn ("nop", xoperands);
7803 return "";
7806 /* Return the attribute length of the call instruction INSN. The SIBCALL
7807 flag indicates whether INSN is a regular call or a sibling call. The
7808 length returned must be longer than the code actually generated by
7809 pa_output_call. Since branch shortening is done before delay branch
7810 sequencing, there is no way to determine whether or not the delay
7811 slot will be filled during branch shortening. Even when the delay
7812 slot is filled, we may have to add a nop if the delay slot contains
7813 a branch that can't reach its target. Thus, we always have to include
7814 the delay slot in the length estimate. This used to be done in
7815 pa_adjust_insn_length but we do it here now as some sequences always
7816 fill the delay slot and we can save four bytes in the estimate for
7817 these sequences. */
7820 pa_attr_length_call (rtx_insn *insn, int sibcall)
7822 int local_call;
7823 rtx call, call_dest;
7824 tree call_decl;
7825 int length = 0;
7826 rtx pat = PATTERN (insn);
7827 unsigned long distance = -1;
7829 gcc_assert (CALL_P (insn));
7831 if (INSN_ADDRESSES_SET_P ())
7833 unsigned long total;
7835 total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7836 distance = (total + insn_current_reference_address (insn));
7837 if (distance < total)
7838 distance = -1;
7841 gcc_assert (GET_CODE (pat) == PARALLEL);
7843 /* Get the call rtx. */
7844 call = XVECEXP (pat, 0, 0);
7845 if (GET_CODE (call) == SET)
7846 call = SET_SRC (call);
7848 gcc_assert (GET_CODE (call) == CALL);
7850 /* Determine if this is a local call. */
7851 call_dest = XEXP (XEXP (call, 0), 0);
7852 call_decl = SYMBOL_REF_DECL (call_dest);
7853 local_call = call_decl && targetm.binds_local_p (call_decl);
7855 /* pc-relative branch. */
7856 if (!TARGET_LONG_CALLS
7857 && ((TARGET_PA_20 && !sibcall && distance < 7600000)
7858 || distance < MAX_PCREL17F_OFFSET))
7859 length += 8;
7861 /* 64-bit plabel sequence. */
7862 else if (TARGET_64BIT && !local_call)
7863 length += sibcall ? 28 : 24;
7865 /* non-pic long absolute branch sequence. */
7866 else if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7867 length += 12;
7869 /* long pc-relative branch sequence. */
7870 else if (TARGET_LONG_PIC_SDIFF_CALL
7871 || (TARGET_GAS && !TARGET_SOM && local_call))
7873 length += 20;
7875 if (!TARGET_PA_20 && !TARGET_NO_SPACE_REGS && (!local_call || flag_pic))
7876 length += 8;
7879 /* 32-bit plabel sequence. */
7880 else
7882 length += 32;
7884 if (TARGET_SOM)
7885 length += length_fp_args (insn);
7887 if (flag_pic)
7888 length += 4;
7890 if (!TARGET_PA_20)
7892 if (!sibcall)
7893 length += 8;
7895 if (!TARGET_NO_SPACE_REGS && (!local_call || flag_pic))
7896 length += 8;
7900 return length;
7903 /* INSN is a function call.
7905 CALL_DEST is the routine we are calling. */
7907 const char *
7908 pa_output_call (rtx_insn *insn, rtx call_dest, int sibcall)
7910 int seq_length = dbr_sequence_length ();
7911 tree call_decl = SYMBOL_REF_DECL (call_dest);
7912 int local_call = call_decl && targetm.binds_local_p (call_decl);
7913 rtx xoperands[4];
7915 xoperands[0] = call_dest;
7917 /* Handle the common case where we're sure that the branch will reach
7918 the beginning of the "$CODE$" subspace. This is the beginning of
7919 the current function if we are in a named section. */
7920 if (!TARGET_LONG_CALLS && pa_attr_length_call (insn, sibcall) == 8)
7922 xoperands[1] = gen_rtx_REG (word_mode, sibcall ? 0 : 2);
7923 output_asm_insn ("{bl|b,l} %0,%1", xoperands);
7925 else
7927 if (TARGET_64BIT && !local_call)
7929 /* ??? As far as I can tell, the HP linker doesn't support the
7930 long pc-relative sequence described in the 64-bit runtime
7931 architecture. So, we use a slightly longer indirect call. */
7932 xoperands[0] = pa_get_deferred_plabel (call_dest);
7933 xoperands[1] = gen_label_rtx ();
7935 /* If this isn't a sibcall, we put the load of %r27 into the
7936 delay slot. We can't do this in a sibcall as we don't
7937 have a second call-clobbered scratch register available.
7938 We don't need to do anything when generating fast indirect
7939 calls. */
7940 if (seq_length != 0 && !sibcall)
7942 final_scan_insn (NEXT_INSN (insn), asm_out_file,
7943 optimize, 0, NULL);
7945 /* Now delete the delay insn. */
7946 SET_INSN_DELETED (NEXT_INSN (insn));
7947 seq_length = 0;
7950 output_asm_insn ("addil LT'%0,%%r27", xoperands);
7951 output_asm_insn ("ldd RT'%0(%%r1),%%r1", xoperands);
7952 output_asm_insn ("ldd 0(%%r1),%%r1", xoperands);
7954 if (sibcall)
7956 output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7957 output_asm_insn ("ldd 16(%%r1),%%r1", xoperands);
7958 output_asm_insn ("bve (%%r1)", xoperands);
7960 else
7962 output_asm_insn ("ldd 16(%%r1),%%r2", xoperands);
7963 output_asm_insn ("bve,l (%%r2),%%r2", xoperands);
7964 output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7965 seq_length = 1;
7968 else
7970 int indirect_call = 0;
7972 /* Emit a long call. There are several different sequences
7973 of increasing length and complexity. In most cases,
7974 they don't allow an instruction in the delay slot. */
7975 if (!((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7976 && !TARGET_LONG_PIC_SDIFF_CALL
7977 && !(TARGET_GAS && !TARGET_SOM && local_call)
7978 && !TARGET_64BIT)
7979 indirect_call = 1;
7981 if (seq_length != 0
7982 && !sibcall
7983 && (!TARGET_PA_20
7984 || indirect_call
7985 || ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)))
7987 /* A non-jump insn in the delay slot. By definition we can
7988 emit this insn before the call (and in fact before argument
7989 relocating. */
7990 final_scan_insn (NEXT_INSN (insn), asm_out_file, optimize, 0,
7991 NULL);
7993 /* Now delete the delay insn. */
7994 SET_INSN_DELETED (NEXT_INSN (insn));
7995 seq_length = 0;
7998 if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
8000 /* This is the best sequence for making long calls in
8001 non-pic code. Unfortunately, GNU ld doesn't provide
8002 the stub needed for external calls, and GAS's support
8003 for this with the SOM linker is buggy. It is safe
8004 to use this for local calls. */
8005 output_asm_insn ("ldil L'%0,%%r1", xoperands);
8006 if (sibcall)
8007 output_asm_insn ("be R'%0(%%sr4,%%r1)", xoperands);
8008 else
8010 if (TARGET_PA_20)
8011 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31",
8012 xoperands);
8013 else
8014 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
8016 output_asm_insn ("copy %%r31,%%r2", xoperands);
8017 seq_length = 1;
8020 else
8022 /* The HP assembler and linker can handle relocations for
8023 the difference of two symbols. The HP assembler
8024 recognizes the sequence as a pc-relative call and
8025 the linker provides stubs when needed. */
8027 /* GAS currently can't generate the relocations that
8028 are needed for the SOM linker under HP-UX using this
8029 sequence. The GNU linker doesn't generate the stubs
8030 that are needed for external calls on TARGET_ELF32
8031 with this sequence. For now, we have to use a longer
8032 plabel sequence when using GAS for non local calls. */
8033 if (TARGET_LONG_PIC_SDIFF_CALL
8034 || (TARGET_GAS && !TARGET_SOM && local_call))
8036 xoperands[1] = gen_rtx_REG (Pmode, 1);
8037 xoperands[2] = xoperands[1];
8038 pa_output_pic_pcrel_sequence (xoperands);
8040 else
8042 /* Emit a long plabel-based call sequence. This is
8043 essentially an inline implementation of $$dyncall.
8044 We don't actually try to call $$dyncall as this is
8045 as difficult as calling the function itself. */
8046 xoperands[0] = pa_get_deferred_plabel (call_dest);
8047 xoperands[1] = gen_label_rtx ();
8049 /* Since the call is indirect, FP arguments in registers
8050 need to be copied to the general registers. Then, the
8051 argument relocation stub will copy them back. */
8052 if (TARGET_SOM)
8053 copy_fp_args (insn);
8055 if (flag_pic)
8057 output_asm_insn ("addil LT'%0,%%r19", xoperands);
8058 output_asm_insn ("ldw RT'%0(%%r1),%%r1", xoperands);
8059 output_asm_insn ("ldw 0(%%r1),%%r1", xoperands);
8061 else
8063 output_asm_insn ("addil LR'%0-$global$,%%r27",
8064 xoperands);
8065 output_asm_insn ("ldw RR'%0-$global$(%%r1),%%r1",
8066 xoperands);
8069 output_asm_insn ("bb,>=,n %%r1,30,.+16", xoperands);
8070 output_asm_insn ("depi 0,31,2,%%r1", xoperands);
8071 output_asm_insn ("ldw 4(%%sr0,%%r1),%%r19", xoperands);
8072 output_asm_insn ("ldw 0(%%sr0,%%r1),%%r1", xoperands);
8074 if (!sibcall && !TARGET_PA_20)
8076 output_asm_insn ("{bl|b,l} .+8,%%r2", xoperands);
8077 if (TARGET_NO_SPACE_REGS || (local_call && !flag_pic))
8078 output_asm_insn ("addi 8,%%r2,%%r2", xoperands);
8079 else
8080 output_asm_insn ("addi 16,%%r2,%%r2", xoperands);
8084 if (TARGET_PA_20)
8086 if (sibcall)
8087 output_asm_insn ("bve (%%r1)", xoperands);
8088 else
8090 if (indirect_call)
8092 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
8093 output_asm_insn ("stw %%r2,-24(%%sp)", xoperands);
8094 seq_length = 1;
8096 else
8097 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
8100 else
8102 if (!TARGET_NO_SPACE_REGS && (!local_call || flag_pic))
8103 output_asm_insn ("ldsid (%%r1),%%r31\n\tmtsp %%r31,%%sr0",
8104 xoperands);
8106 if (sibcall)
8108 if (TARGET_NO_SPACE_REGS || (local_call && !flag_pic))
8109 output_asm_insn ("be 0(%%sr4,%%r1)", xoperands);
8110 else
8111 output_asm_insn ("be 0(%%sr0,%%r1)", xoperands);
8113 else
8115 if (TARGET_NO_SPACE_REGS || (local_call && !flag_pic))
8116 output_asm_insn ("ble 0(%%sr4,%%r1)", xoperands);
8117 else
8118 output_asm_insn ("ble 0(%%sr0,%%r1)", xoperands);
8120 if (indirect_call)
8121 output_asm_insn ("stw %%r31,-24(%%sp)", xoperands);
8122 else
8123 output_asm_insn ("copy %%r31,%%r2", xoperands);
8124 seq_length = 1;
8131 if (seq_length == 0)
8132 output_asm_insn ("nop", xoperands);
8134 return "";
8137 /* Return the attribute length of the indirect call instruction INSN.
8138 The length must match the code generated by output_indirect call.
8139 The returned length includes the delay slot. Currently, the delay
8140 slot of an indirect call sequence is not exposed and it is used by
8141 the sequence itself. */
8144 pa_attr_length_indirect_call (rtx_insn *insn)
8146 unsigned long distance = -1;
8147 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
8149 if (INSN_ADDRESSES_SET_P ())
8151 distance = (total + insn_current_reference_address (insn));
8152 if (distance < total)
8153 distance = -1;
8156 if (TARGET_64BIT)
8157 return 12;
8159 if (TARGET_FAST_INDIRECT_CALLS)
8160 return 8;
8162 if (TARGET_PORTABLE_RUNTIME)
8163 return 16;
8165 /* Inline version of $$dyncall. */
8166 if ((TARGET_NO_SPACE_REGS || TARGET_PA_20) && !optimize_size)
8167 return 20;
8169 if (!TARGET_LONG_CALLS
8170 && ((TARGET_PA_20 && !TARGET_SOM && distance < 7600000)
8171 || distance < MAX_PCREL17F_OFFSET))
8172 return 8;
8174 /* Out of reach, can use ble. */
8175 if (!flag_pic)
8176 return 12;
8178 /* Inline version of $$dyncall. */
8179 if (TARGET_NO_SPACE_REGS || TARGET_PA_20)
8180 return 20;
8182 if (!optimize_size)
8183 return 36;
8185 /* Long PIC pc-relative call. */
8186 return 20;
8189 const char *
8190 pa_output_indirect_call (rtx_insn *insn, rtx call_dest)
8192 rtx xoperands[4];
8193 int length;
8195 if (TARGET_64BIT)
8197 xoperands[0] = call_dest;
8198 output_asm_insn ("ldd 16(%0),%%r2\n\t"
8199 "bve,l (%%r2),%%r2\n\t"
8200 "ldd 24(%0),%%r27", xoperands);
8201 return "";
8204 /* First the special case for kernels, level 0 systems, etc. */
8205 if (TARGET_FAST_INDIRECT_CALLS)
8207 pa_output_arg_descriptor (insn);
8208 if (TARGET_PA_20)
8209 return "bve,l,n (%%r22),%%r2\n\tnop";
8210 return "ble 0(%%sr4,%%r22)\n\tcopy %%r31,%%r2";
8213 if (TARGET_PORTABLE_RUNTIME)
8215 output_asm_insn ("ldil L'$$dyncall,%%r31\n\t"
8216 "ldo R'$$dyncall(%%r31),%%r31", xoperands);
8217 pa_output_arg_descriptor (insn);
8218 return "blr %%r0,%%r2\n\tbv,n %%r0(%%r31)";
8221 /* Maybe emit a fast inline version of $$dyncall. */
8222 if ((TARGET_NO_SPACE_REGS || TARGET_PA_20) && !optimize_size)
8224 output_asm_insn ("bb,>=,n %%r22,30,.+12\n\t"
8225 "ldw 2(%%r22),%%r19\n\t"
8226 "ldw -2(%%r22),%%r22", xoperands);
8227 pa_output_arg_descriptor (insn);
8228 if (TARGET_NO_SPACE_REGS)
8230 if (TARGET_PA_20)
8231 return "bve,l,n (%%r22),%%r2\n\tnop";
8232 return "ble 0(%%sr4,%%r22)\n\tcopy %%r31,%%r2";
8234 return "bve,l (%%r22),%%r2\n\tstw %%r2,-24(%%sp)";
8237 /* Now the normal case -- we can reach $$dyncall directly or
8238 we're sure that we can get there via a long-branch stub.
8240 No need to check target flags as the length uniquely identifies
8241 the remaining cases. */
8242 length = pa_attr_length_indirect_call (insn);
8243 if (length == 8)
8245 pa_output_arg_descriptor (insn);
8247 /* The HP linker sometimes substitutes a BLE for BL/B,L calls to
8248 $$dyncall. Since BLE uses %r31 as the link register, the 22-bit
8249 variant of the B,L instruction can't be used on the SOM target. */
8250 if (TARGET_PA_20 && !TARGET_SOM)
8251 return "b,l,n $$dyncall,%%r2\n\tnop";
8252 else
8253 return "bl $$dyncall,%%r31\n\tcopy %%r31,%%r2";
8256 /* Long millicode call, but we are not generating PIC or portable runtime
8257 code. */
8258 if (length == 12)
8260 output_asm_insn ("ldil L'$$dyncall,%%r2", xoperands);
8261 pa_output_arg_descriptor (insn);
8262 return "ble R'$$dyncall(%%sr4,%%r2)\n\tcopy %%r31,%%r2";
8265 /* Maybe emit a fast inline version of $$dyncall. The long PIC
8266 pc-relative call sequence is five instructions. The inline PA 2.0
8267 version of $$dyncall is also five instructions. The PA 1.X versions
8268 are longer but still an overall win. */
8269 if (TARGET_NO_SPACE_REGS || TARGET_PA_20 || !optimize_size)
8271 output_asm_insn ("bb,>=,n %%r22,30,.+12\n\t"
8272 "ldw 2(%%r22),%%r19\n\t"
8273 "ldw -2(%%r22),%%r22", xoperands);
8274 if (TARGET_NO_SPACE_REGS)
8276 pa_output_arg_descriptor (insn);
8277 if (TARGET_PA_20)
8278 return "bve,l,n (%%r22),%%r2\n\tnop";
8279 return "ble 0(%%sr4,%%r22)\n\tcopy %%r31,%%r2";
8281 if (TARGET_PA_20)
8283 pa_output_arg_descriptor (insn);
8284 return "bve,l (%%r22),%%r2\n\tstw %%r2,-24(%%sp)";
8286 output_asm_insn ("bl .+8,%%r2\n\t"
8287 "ldo 16(%%r2),%%r2\n\t"
8288 "ldsid (%%r22),%%r1\n\t"
8289 "mtsp %%r1,%%sr0", xoperands);
8290 pa_output_arg_descriptor (insn);
8291 return "be 0(%%sr0,%%r22)\n\tstw %%r2,-24(%%sp)";
8294 /* We need a long PIC call to $$dyncall. */
8295 xoperands[0] = gen_rtx_SYMBOL_REF (Pmode, "$$dyncall");
8296 xoperands[1] = gen_rtx_REG (Pmode, 2);
8297 xoperands[2] = gen_rtx_REG (Pmode, 1);
8298 pa_output_pic_pcrel_sequence (xoperands);
8299 pa_output_arg_descriptor (insn);
8300 return "bv %%r0(%%r1)\n\tldo {12|20}(%%r2),%%r2";
8303 /* In HPUX 8.0's shared library scheme, special relocations are needed
8304 for function labels if they might be passed to a function
8305 in a shared library (because shared libraries don't live in code
8306 space), and special magic is needed to construct their address. */
8308 void
8309 pa_encode_label (rtx sym)
8311 const char *str = XSTR (sym, 0);
8312 int len = strlen (str) + 1;
8313 char *newstr, *p;
8315 p = newstr = XALLOCAVEC (char, len + 1);
8316 *p++ = '@';
8317 strcpy (p, str);
8319 XSTR (sym, 0) = ggc_alloc_string (newstr, len);
8322 static void
8323 pa_encode_section_info (tree decl, rtx rtl, int first)
8325 int old_referenced = 0;
8327 if (!first && MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
8328 old_referenced
8329 = SYMBOL_REF_FLAGS (XEXP (rtl, 0)) & SYMBOL_FLAG_REFERENCED;
8331 default_encode_section_info (decl, rtl, first);
8333 if (first && TEXT_SPACE_P (decl))
8335 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
8336 if (TREE_CODE (decl) == FUNCTION_DECL)
8337 pa_encode_label (XEXP (rtl, 0));
8339 else if (old_referenced)
8340 SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= old_referenced;
8343 /* This is sort of inverse to pa_encode_section_info. */
8345 static const char *
8346 pa_strip_name_encoding (const char *str)
8348 str += (*str == '@');
8349 str += (*str == '*');
8350 return str;
8353 /* Returns 1 if OP is a function label involved in a simple addition
8354 with a constant. Used to keep certain patterns from matching
8355 during instruction combination. */
8357 pa_is_function_label_plus_const (rtx op)
8359 /* Strip off any CONST. */
8360 if (GET_CODE (op) == CONST)
8361 op = XEXP (op, 0);
8363 return (GET_CODE (op) == PLUS
8364 && function_label_operand (XEXP (op, 0), VOIDmode)
8365 && GET_CODE (XEXP (op, 1)) == CONST_INT);
8368 /* Output assembly code for a thunk to FUNCTION. */
8370 static void
8371 pa_asm_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
8372 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
8373 tree function)
8375 static unsigned int current_thunk_number;
8376 int val_14 = VAL_14_BITS_P (delta);
8377 unsigned int old_last_address = last_address, nbytes = 0;
8378 char label[17];
8379 rtx xoperands[4];
8381 xoperands[0] = XEXP (DECL_RTL (function), 0);
8382 xoperands[1] = XEXP (DECL_RTL (thunk_fndecl), 0);
8383 xoperands[2] = GEN_INT (delta);
8385 final_start_function (emit_barrier (), file, 1);
8387 /* Output the thunk. We know that the function is in the same
8388 translation unit (i.e., the same space) as the thunk, and that
8389 thunks are output after their method. Thus, we don't need an
8390 external branch to reach the function. With SOM and GAS,
8391 functions and thunks are effectively in different sections.
8392 Thus, we can always use a IA-relative branch and the linker
8393 will add a long branch stub if necessary.
8395 However, we have to be careful when generating PIC code on the
8396 SOM port to ensure that the sequence does not transfer to an
8397 import stub for the target function as this could clobber the
8398 return value saved at SP-24. This would also apply to the
8399 32-bit linux port if the multi-space model is implemented. */
8400 if ((!TARGET_LONG_CALLS && TARGET_SOM && !TARGET_PORTABLE_RUNTIME
8401 && !(flag_pic && TREE_PUBLIC (function))
8402 && (TARGET_GAS || last_address < 262132))
8403 || (!TARGET_LONG_CALLS && !TARGET_SOM && !TARGET_PORTABLE_RUNTIME
8404 && ((targetm_common.have_named_sections
8405 && DECL_SECTION_NAME (thunk_fndecl) != NULL
8406 /* The GNU 64-bit linker has rather poor stub management.
8407 So, we use a long branch from thunks that aren't in
8408 the same section as the target function. */
8409 && ((!TARGET_64BIT
8410 && (DECL_SECTION_NAME (thunk_fndecl)
8411 != DECL_SECTION_NAME (function)))
8412 || ((DECL_SECTION_NAME (thunk_fndecl)
8413 == DECL_SECTION_NAME (function))
8414 && last_address < 262132)))
8415 /* In this case, we need to be able to reach the start of
8416 the stub table even though the function is likely closer
8417 and can be jumped to directly. */
8418 || (targetm_common.have_named_sections
8419 && DECL_SECTION_NAME (thunk_fndecl) == NULL
8420 && DECL_SECTION_NAME (function) == NULL
8421 && total_code_bytes < MAX_PCREL17F_OFFSET)
8422 /* Likewise. */
8423 || (!targetm_common.have_named_sections
8424 && total_code_bytes < MAX_PCREL17F_OFFSET))))
8426 if (!val_14)
8427 output_asm_insn ("addil L'%2,%%r26", xoperands);
8429 output_asm_insn ("b %0", xoperands);
8431 if (val_14)
8433 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8434 nbytes += 8;
8436 else
8438 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8439 nbytes += 12;
8442 else if (TARGET_64BIT)
8444 rtx xop[4];
8446 /* We only have one call-clobbered scratch register, so we can't
8447 make use of the delay slot if delta doesn't fit in 14 bits. */
8448 if (!val_14)
8450 output_asm_insn ("addil L'%2,%%r26", xoperands);
8451 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8454 /* Load function address into %r1. */
8455 xop[0] = xoperands[0];
8456 xop[1] = gen_rtx_REG (Pmode, 1);
8457 xop[2] = xop[1];
8458 pa_output_pic_pcrel_sequence (xop);
8460 if (val_14)
8462 output_asm_insn ("bv %%r0(%%r1)", xoperands);
8463 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8464 nbytes += 20;
8466 else
8468 output_asm_insn ("bv,n %%r0(%%r1)", xoperands);
8469 nbytes += 24;
8472 else if (TARGET_PORTABLE_RUNTIME)
8474 output_asm_insn ("ldil L'%0,%%r1", xoperands);
8475 output_asm_insn ("ldo R'%0(%%r1),%%r22", xoperands);
8477 if (!val_14)
8478 output_asm_insn ("ldil L'%2,%%r26", xoperands);
8480 output_asm_insn ("bv %%r0(%%r22)", xoperands);
8482 if (val_14)
8484 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8485 nbytes += 16;
8487 else
8489 output_asm_insn ("ldo R'%2(%%r26),%%r26", xoperands);
8490 nbytes += 20;
8493 else if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8495 /* The function is accessible from outside this module. The only
8496 way to avoid an import stub between the thunk and function is to
8497 call the function directly with an indirect sequence similar to
8498 that used by $$dyncall. This is possible because $$dyncall acts
8499 as the import stub in an indirect call. */
8500 ASM_GENERATE_INTERNAL_LABEL (label, "LTHN", current_thunk_number);
8501 xoperands[3] = gen_rtx_SYMBOL_REF (Pmode, label);
8502 output_asm_insn ("addil LT'%3,%%r19", xoperands);
8503 output_asm_insn ("ldw RT'%3(%%r1),%%r22", xoperands);
8504 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8505 output_asm_insn ("bb,>=,n %%r22,30,.+16", xoperands);
8506 output_asm_insn ("depi 0,31,2,%%r22", xoperands);
8507 output_asm_insn ("ldw 4(%%sr0,%%r22),%%r19", xoperands);
8508 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8510 if (!val_14)
8512 output_asm_insn ("addil L'%2,%%r26", xoperands);
8513 nbytes += 4;
8516 if (TARGET_PA_20)
8518 output_asm_insn ("bve (%%r22)", xoperands);
8519 nbytes += 36;
8521 else if (TARGET_NO_SPACE_REGS)
8523 output_asm_insn ("be 0(%%sr4,%%r22)", xoperands);
8524 nbytes += 36;
8526 else
8528 output_asm_insn ("ldsid (%%sr0,%%r22),%%r21", xoperands);
8529 output_asm_insn ("mtsp %%r21,%%sr0", xoperands);
8530 output_asm_insn ("be 0(%%sr0,%%r22)", xoperands);
8531 nbytes += 44;
8534 if (val_14)
8535 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8536 else
8537 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8539 else if (flag_pic)
8541 rtx xop[4];
8543 /* Load function address into %r22. */
8544 xop[0] = xoperands[0];
8545 xop[1] = gen_rtx_REG (Pmode, 1);
8546 xop[2] = gen_rtx_REG (Pmode, 22);
8547 pa_output_pic_pcrel_sequence (xop);
8549 if (!val_14)
8550 output_asm_insn ("addil L'%2,%%r26", xoperands);
8552 output_asm_insn ("bv %%r0(%%r22)", xoperands);
8554 if (val_14)
8556 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8557 nbytes += 20;
8559 else
8561 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8562 nbytes += 24;
8565 else
8567 if (!val_14)
8568 output_asm_insn ("addil L'%2,%%r26", xoperands);
8570 output_asm_insn ("ldil L'%0,%%r22", xoperands);
8571 output_asm_insn ("be R'%0(%%sr4,%%r22)", xoperands);
8573 if (val_14)
8575 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8576 nbytes += 12;
8578 else
8580 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8581 nbytes += 16;
8585 final_end_function ();
8587 if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8589 switch_to_section (data_section);
8590 output_asm_insn (".align 4", xoperands);
8591 ASM_OUTPUT_LABEL (file, label);
8592 output_asm_insn (".word P'%0", xoperands);
8595 current_thunk_number++;
8596 nbytes = ((nbytes + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
8597 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
8598 last_address += nbytes;
8599 if (old_last_address > last_address)
8600 last_address = UINT_MAX;
8601 update_total_code_bytes (nbytes);
8604 /* Only direct calls to static functions are allowed to be sibling (tail)
8605 call optimized.
8607 This restriction is necessary because some linker generated stubs will
8608 store return pointers into rp' in some cases which might clobber a
8609 live value already in rp'.
8611 In a sibcall the current function and the target function share stack
8612 space. Thus if the path to the current function and the path to the
8613 target function save a value in rp', they save the value into the
8614 same stack slot, which has undesirable consequences.
8616 Because of the deferred binding nature of shared libraries any function
8617 with external scope could be in a different load module and thus require
8618 rp' to be saved when calling that function. So sibcall optimizations
8619 can only be safe for static function.
8621 Note that GCC never needs return value relocations, so we don't have to
8622 worry about static calls with return value relocations (which require
8623 saving rp').
8625 It is safe to perform a sibcall optimization when the target function
8626 will never return. */
8627 static bool
8628 pa_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
8630 if (TARGET_PORTABLE_RUNTIME)
8631 return false;
8633 /* Sibcalls are not ok because the arg pointer register is not a fixed
8634 register. This prevents the sibcall optimization from occurring. In
8635 addition, there are problems with stub placement using GNU ld. This
8636 is because a normal sibcall branch uses a 17-bit relocation while
8637 a regular call branch uses a 22-bit relocation. As a result, more
8638 care needs to be taken in the placement of long-branch stubs. */
8639 if (TARGET_64BIT)
8640 return false;
8642 /* Sibcalls are only ok within a translation unit. */
8643 return (decl && !TREE_PUBLIC (decl));
8646 /* ??? Addition is not commutative on the PA due to the weird implicit
8647 space register selection rules for memory addresses. Therefore, we
8648 don't consider a + b == b + a, as this might be inside a MEM. */
8649 static bool
8650 pa_commutative_p (const_rtx x, int outer_code)
8652 return (COMMUTATIVE_P (x)
8653 && (TARGET_NO_SPACE_REGS
8654 || (outer_code != UNKNOWN && outer_code != MEM)
8655 || GET_CODE (x) != PLUS));
8658 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8659 use in fmpyadd instructions. */
8661 pa_fmpyaddoperands (rtx *operands)
8663 machine_mode mode = GET_MODE (operands[0]);
8665 /* Must be a floating point mode. */
8666 if (mode != SFmode && mode != DFmode)
8667 return 0;
8669 /* All modes must be the same. */
8670 if (! (mode == GET_MODE (operands[1])
8671 && mode == GET_MODE (operands[2])
8672 && mode == GET_MODE (operands[3])
8673 && mode == GET_MODE (operands[4])
8674 && mode == GET_MODE (operands[5])))
8675 return 0;
8677 /* All operands must be registers. */
8678 if (! (GET_CODE (operands[1]) == REG
8679 && GET_CODE (operands[2]) == REG
8680 && GET_CODE (operands[3]) == REG
8681 && GET_CODE (operands[4]) == REG
8682 && GET_CODE (operands[5]) == REG))
8683 return 0;
8685 /* Only 2 real operands to the addition. One of the input operands must
8686 be the same as the output operand. */
8687 if (! rtx_equal_p (operands[3], operands[4])
8688 && ! rtx_equal_p (operands[3], operands[5]))
8689 return 0;
8691 /* Inout operand of add cannot conflict with any operands from multiply. */
8692 if (rtx_equal_p (operands[3], operands[0])
8693 || rtx_equal_p (operands[3], operands[1])
8694 || rtx_equal_p (operands[3], operands[2]))
8695 return 0;
8697 /* multiply cannot feed into addition operands. */
8698 if (rtx_equal_p (operands[4], operands[0])
8699 || rtx_equal_p (operands[5], operands[0]))
8700 return 0;
8702 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
8703 if (mode == SFmode
8704 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8705 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8706 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8707 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8708 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8709 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8710 return 0;
8712 /* Passed. Operands are suitable for fmpyadd. */
8713 return 1;
8716 #if !defined(USE_COLLECT2)
8717 static void
8718 pa_asm_out_constructor (rtx symbol, int priority)
8720 if (!function_label_operand (symbol, VOIDmode))
8721 pa_encode_label (symbol);
8723 #ifdef CTORS_SECTION_ASM_OP
8724 default_ctor_section_asm_out_constructor (symbol, priority);
8725 #else
8726 # ifdef TARGET_ASM_NAMED_SECTION
8727 default_named_section_asm_out_constructor (symbol, priority);
8728 # else
8729 default_stabs_asm_out_constructor (symbol, priority);
8730 # endif
8731 #endif
8734 static void
8735 pa_asm_out_destructor (rtx symbol, int priority)
8737 if (!function_label_operand (symbol, VOIDmode))
8738 pa_encode_label (symbol);
8740 #ifdef DTORS_SECTION_ASM_OP
8741 default_dtor_section_asm_out_destructor (symbol, priority);
8742 #else
8743 # ifdef TARGET_ASM_NAMED_SECTION
8744 default_named_section_asm_out_destructor (symbol, priority);
8745 # else
8746 default_stabs_asm_out_destructor (symbol, priority);
8747 # endif
8748 #endif
8750 #endif
8752 /* This function places uninitialized global data in the bss section.
8753 The ASM_OUTPUT_ALIGNED_BSS macro needs to be defined to call this
8754 function on the SOM port to prevent uninitialized global data from
8755 being placed in the data section. */
8757 void
8758 pa_asm_output_aligned_bss (FILE *stream,
8759 const char *name,
8760 unsigned HOST_WIDE_INT size,
8761 unsigned int align)
8763 switch_to_section (bss_section);
8764 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8766 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
8767 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object");
8768 #endif
8770 #ifdef ASM_OUTPUT_SIZE_DIRECTIVE
8771 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
8772 #endif
8774 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8775 ASM_OUTPUT_LABEL (stream, name);
8776 fprintf (stream, "\t.block " HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8779 /* Both the HP and GNU assemblers under HP-UX provide a .comm directive
8780 that doesn't allow the alignment of global common storage to be directly
8781 specified. The SOM linker aligns common storage based on the rounded
8782 value of the NUM_BYTES parameter in the .comm directive. It's not
8783 possible to use the .align directive as it doesn't affect the alignment
8784 of the label associated with a .comm directive. */
8786 void
8787 pa_asm_output_aligned_common (FILE *stream,
8788 const char *name,
8789 unsigned HOST_WIDE_INT size,
8790 unsigned int align)
8792 unsigned int max_common_align;
8794 max_common_align = TARGET_64BIT ? 128 : (size >= 4096 ? 256 : 64);
8795 if (align > max_common_align)
8797 warning (0, "alignment (%u) for %s exceeds maximum alignment "
8798 "for global common data. Using %u",
8799 align / BITS_PER_UNIT, name, max_common_align / BITS_PER_UNIT);
8800 align = max_common_align;
8803 switch_to_section (bss_section);
8805 assemble_name (stream, name);
8806 fprintf (stream, "\t.comm " HOST_WIDE_INT_PRINT_UNSIGNED"\n",
8807 MAX (size, align / BITS_PER_UNIT));
8810 /* We can't use .comm for local common storage as the SOM linker effectively
8811 treats the symbol as universal and uses the same storage for local symbols
8812 with the same name in different object files. The .block directive
8813 reserves an uninitialized block of storage. However, it's not common
8814 storage. Fortunately, GCC never requests common storage with the same
8815 name in any given translation unit. */
8817 void
8818 pa_asm_output_aligned_local (FILE *stream,
8819 const char *name,
8820 unsigned HOST_WIDE_INT size,
8821 unsigned int align)
8823 switch_to_section (bss_section);
8824 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8826 #ifdef LOCAL_ASM_OP
8827 fprintf (stream, "%s", LOCAL_ASM_OP);
8828 assemble_name (stream, name);
8829 fprintf (stream, "\n");
8830 #endif
8832 ASM_OUTPUT_LABEL (stream, name);
8833 fprintf (stream, "\t.block " HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8836 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8837 use in fmpysub instructions. */
8839 pa_fmpysuboperands (rtx *operands)
8841 machine_mode mode = GET_MODE (operands[0]);
8843 /* Must be a floating point mode. */
8844 if (mode != SFmode && mode != DFmode)
8845 return 0;
8847 /* All modes must be the same. */
8848 if (! (mode == GET_MODE (operands[1])
8849 && mode == GET_MODE (operands[2])
8850 && mode == GET_MODE (operands[3])
8851 && mode == GET_MODE (operands[4])
8852 && mode == GET_MODE (operands[5])))
8853 return 0;
8855 /* All operands must be registers. */
8856 if (! (GET_CODE (operands[1]) == REG
8857 && GET_CODE (operands[2]) == REG
8858 && GET_CODE (operands[3]) == REG
8859 && GET_CODE (operands[4]) == REG
8860 && GET_CODE (operands[5]) == REG))
8861 return 0;
8863 /* Only 2 real operands to the subtraction. Subtraction is not a commutative
8864 operation, so operands[4] must be the same as operand[3]. */
8865 if (! rtx_equal_p (operands[3], operands[4]))
8866 return 0;
8868 /* multiply cannot feed into subtraction. */
8869 if (rtx_equal_p (operands[5], operands[0]))
8870 return 0;
8872 /* Inout operand of sub cannot conflict with any operands from multiply. */
8873 if (rtx_equal_p (operands[3], operands[0])
8874 || rtx_equal_p (operands[3], operands[1])
8875 || rtx_equal_p (operands[3], operands[2]))
8876 return 0;
8878 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
8879 if (mode == SFmode
8880 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8881 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8882 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8883 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8884 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8885 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8886 return 0;
8888 /* Passed. Operands are suitable for fmpysub. */
8889 return 1;
8892 /* Return 1 if the given constant is 2, 4, or 8. These are the valid
8893 constants for a MULT embedded inside a memory address. */
8895 pa_mem_shadd_constant_p (int val)
8897 if (val == 2 || val == 4 || val == 8)
8898 return 1;
8899 else
8900 return 0;
8903 /* Return 1 if the given constant is 1, 2, or 3. These are the valid
8904 constants for shadd instructions. */
8906 pa_shadd_constant_p (int val)
8908 if (val == 1 || val == 2 || val == 3)
8909 return 1;
8910 else
8911 return 0;
8914 /* Return TRUE if INSN branches forward. */
8916 static bool
8917 forward_branch_p (rtx_insn *insn)
8919 rtx lab = JUMP_LABEL (insn);
8921 /* The INSN must have a jump label. */
8922 gcc_assert (lab != NULL_RTX);
8924 if (INSN_ADDRESSES_SET_P ())
8925 return INSN_ADDRESSES (INSN_UID (lab)) > INSN_ADDRESSES (INSN_UID (insn));
8927 while (insn)
8929 if (insn == lab)
8930 return true;
8931 else
8932 insn = NEXT_INSN (insn);
8935 return false;
8938 /* Output an unconditional move and branch insn. */
8940 const char *
8941 pa_output_parallel_movb (rtx *operands, rtx_insn *insn)
8943 int length = get_attr_length (insn);
8945 /* These are the cases in which we win. */
8946 if (length == 4)
8947 return "mov%I1b,tr %1,%0,%2";
8949 /* None of the following cases win, but they don't lose either. */
8950 if (length == 8)
8952 if (dbr_sequence_length () == 0)
8954 /* Nothing in the delay slot, fake it by putting the combined
8955 insn (the copy or add) in the delay slot of a bl. */
8956 if (GET_CODE (operands[1]) == CONST_INT)
8957 return "b %2\n\tldi %1,%0";
8958 else
8959 return "b %2\n\tcopy %1,%0";
8961 else
8963 /* Something in the delay slot, but we've got a long branch. */
8964 if (GET_CODE (operands[1]) == CONST_INT)
8965 return "ldi %1,%0\n\tb %2";
8966 else
8967 return "copy %1,%0\n\tb %2";
8971 if (GET_CODE (operands[1]) == CONST_INT)
8972 output_asm_insn ("ldi %1,%0", operands);
8973 else
8974 output_asm_insn ("copy %1,%0", operands);
8975 return pa_output_lbranch (operands[2], insn, 1);
8978 /* Output an unconditional add and branch insn. */
8980 const char *
8981 pa_output_parallel_addb (rtx *operands, rtx_insn *insn)
8983 int length = get_attr_length (insn);
8985 /* To make life easy we want operand0 to be the shared input/output
8986 operand and operand1 to be the readonly operand. */
8987 if (operands[0] == operands[1])
8988 operands[1] = operands[2];
8990 /* These are the cases in which we win. */
8991 if (length == 4)
8992 return "add%I1b,tr %1,%0,%3";
8994 /* None of the following cases win, but they don't lose either. */
8995 if (length == 8)
8997 if (dbr_sequence_length () == 0)
8998 /* Nothing in the delay slot, fake it by putting the combined
8999 insn (the copy or add) in the delay slot of a bl. */
9000 return "b %3\n\tadd%I1 %1,%0,%0";
9001 else
9002 /* Something in the delay slot, but we've got a long branch. */
9003 return "add%I1 %1,%0,%0\n\tb %3";
9006 output_asm_insn ("add%I1 %1,%0,%0", operands);
9007 return pa_output_lbranch (operands[3], insn, 1);
9010 /* We use this hook to perform a PA specific optimization which is difficult
9011 to do in earlier passes. */
9013 static void
9014 pa_reorg (void)
9016 remove_useless_addtr_insns (1);
9018 if (pa_cpu < PROCESSOR_8000)
9019 pa_combine_instructions ();
9022 /* The PA has a number of odd instructions which can perform multiple
9023 tasks at once. On first generation PA machines (PA1.0 and PA1.1)
9024 it may be profitable to combine two instructions into one instruction
9025 with two outputs. It's not profitable PA2.0 machines because the
9026 two outputs would take two slots in the reorder buffers.
9028 This routine finds instructions which can be combined and combines
9029 them. We only support some of the potential combinations, and we
9030 only try common ways to find suitable instructions.
9032 * addb can add two registers or a register and a small integer
9033 and jump to a nearby (+-8k) location. Normally the jump to the
9034 nearby location is conditional on the result of the add, but by
9035 using the "true" condition we can make the jump unconditional.
9036 Thus addb can perform two independent operations in one insn.
9038 * movb is similar to addb in that it can perform a reg->reg
9039 or small immediate->reg copy and jump to a nearby (+-8k location).
9041 * fmpyadd and fmpysub can perform a FP multiply and either an
9042 FP add or FP sub if the operands of the multiply and add/sub are
9043 independent (there are other minor restrictions). Note both
9044 the fmpy and fadd/fsub can in theory move to better spots according
9045 to data dependencies, but for now we require the fmpy stay at a
9046 fixed location.
9048 * Many of the memory operations can perform pre & post updates
9049 of index registers. GCC's pre/post increment/decrement addressing
9050 is far too simple to take advantage of all the possibilities. This
9051 pass may not be suitable since those insns may not be independent.
9053 * comclr can compare two ints or an int and a register, nullify
9054 the following instruction and zero some other register. This
9055 is more difficult to use as it's harder to find an insn which
9056 will generate a comclr than finding something like an unconditional
9057 branch. (conditional moves & long branches create comclr insns).
9059 * Most arithmetic operations can conditionally skip the next
9060 instruction. They can be viewed as "perform this operation
9061 and conditionally jump to this nearby location" (where nearby
9062 is an insns away). These are difficult to use due to the
9063 branch length restrictions. */
9065 static void
9066 pa_combine_instructions (void)
9068 rtx_insn *anchor;
9070 /* This can get expensive since the basic algorithm is on the
9071 order of O(n^2) (or worse). Only do it for -O2 or higher
9072 levels of optimization. */
9073 if (optimize < 2)
9074 return;
9076 /* Walk down the list of insns looking for "anchor" insns which
9077 may be combined with "floating" insns. As the name implies,
9078 "anchor" instructions don't move, while "floating" insns may
9079 move around. */
9080 rtx par = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, NULL_RTX, NULL_RTX));
9081 rtx_insn *new_rtx = make_insn_raw (par);
9083 for (anchor = get_insns (); anchor; anchor = NEXT_INSN (anchor))
9085 enum attr_pa_combine_type anchor_attr;
9086 enum attr_pa_combine_type floater_attr;
9088 /* We only care about INSNs, JUMP_INSNs, and CALL_INSNs.
9089 Also ignore any special USE insns. */
9090 if ((! NONJUMP_INSN_P (anchor) && ! JUMP_P (anchor) && ! CALL_P (anchor))
9091 || GET_CODE (PATTERN (anchor)) == USE
9092 || GET_CODE (PATTERN (anchor)) == CLOBBER)
9093 continue;
9095 anchor_attr = get_attr_pa_combine_type (anchor);
9096 /* See if anchor is an insn suitable for combination. */
9097 if (anchor_attr == PA_COMBINE_TYPE_FMPY
9098 || anchor_attr == PA_COMBINE_TYPE_FADDSUB
9099 || (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
9100 && ! forward_branch_p (anchor)))
9102 rtx_insn *floater;
9104 for (floater = PREV_INSN (anchor);
9105 floater;
9106 floater = PREV_INSN (floater))
9108 if (NOTE_P (floater)
9109 || (NONJUMP_INSN_P (floater)
9110 && (GET_CODE (PATTERN (floater)) == USE
9111 || GET_CODE (PATTERN (floater)) == CLOBBER)))
9112 continue;
9114 /* Anything except a regular INSN will stop our search. */
9115 if (! NONJUMP_INSN_P (floater))
9117 floater = NULL;
9118 break;
9121 /* See if FLOATER is suitable for combination with the
9122 anchor. */
9123 floater_attr = get_attr_pa_combine_type (floater);
9124 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
9125 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
9126 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
9127 && floater_attr == PA_COMBINE_TYPE_FMPY))
9129 /* If ANCHOR and FLOATER can be combined, then we're
9130 done with this pass. */
9131 if (pa_can_combine_p (new_rtx, anchor, floater, 0,
9132 SET_DEST (PATTERN (floater)),
9133 XEXP (SET_SRC (PATTERN (floater)), 0),
9134 XEXP (SET_SRC (PATTERN (floater)), 1)))
9135 break;
9138 else if (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
9139 && floater_attr == PA_COMBINE_TYPE_ADDMOVE)
9141 if (GET_CODE (SET_SRC (PATTERN (floater))) == PLUS)
9143 if (pa_can_combine_p (new_rtx, anchor, floater, 0,
9144 SET_DEST (PATTERN (floater)),
9145 XEXP (SET_SRC (PATTERN (floater)), 0),
9146 XEXP (SET_SRC (PATTERN (floater)), 1)))
9147 break;
9149 else
9151 if (pa_can_combine_p (new_rtx, anchor, floater, 0,
9152 SET_DEST (PATTERN (floater)),
9153 SET_SRC (PATTERN (floater)),
9154 SET_SRC (PATTERN (floater))))
9155 break;
9160 /* If we didn't find anything on the backwards scan try forwards. */
9161 if (!floater
9162 && (anchor_attr == PA_COMBINE_TYPE_FMPY
9163 || anchor_attr == PA_COMBINE_TYPE_FADDSUB))
9165 for (floater = anchor; floater; floater = NEXT_INSN (floater))
9167 if (NOTE_P (floater)
9168 || (NONJUMP_INSN_P (floater)
9169 && (GET_CODE (PATTERN (floater)) == USE
9170 || GET_CODE (PATTERN (floater)) == CLOBBER)))
9172 continue;
9174 /* Anything except a regular INSN will stop our search. */
9175 if (! NONJUMP_INSN_P (floater))
9177 floater = NULL;
9178 break;
9181 /* See if FLOATER is suitable for combination with the
9182 anchor. */
9183 floater_attr = get_attr_pa_combine_type (floater);
9184 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
9185 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
9186 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
9187 && floater_attr == PA_COMBINE_TYPE_FMPY))
9189 /* If ANCHOR and FLOATER can be combined, then we're
9190 done with this pass. */
9191 if (pa_can_combine_p (new_rtx, anchor, floater, 1,
9192 SET_DEST (PATTERN (floater)),
9193 XEXP (SET_SRC (PATTERN (floater)),
9195 XEXP (SET_SRC (PATTERN (floater)),
9196 1)))
9197 break;
9202 /* FLOATER will be nonzero if we found a suitable floating
9203 insn for combination with ANCHOR. */
9204 if (floater
9205 && (anchor_attr == PA_COMBINE_TYPE_FADDSUB
9206 || anchor_attr == PA_COMBINE_TYPE_FMPY))
9208 /* Emit the new instruction and delete the old anchor. */
9209 rtvec vtemp = gen_rtvec (2, copy_rtx (PATTERN (anchor)),
9210 copy_rtx (PATTERN (floater)));
9211 rtx temp = gen_rtx_PARALLEL (VOIDmode, vtemp);
9212 emit_insn_before (temp, anchor);
9214 SET_INSN_DELETED (anchor);
9216 /* Emit a special USE insn for FLOATER, then delete
9217 the floating insn. */
9218 temp = copy_rtx (PATTERN (floater));
9219 emit_insn_before (gen_rtx_USE (VOIDmode, temp), floater);
9220 delete_insn (floater);
9222 continue;
9224 else if (floater
9225 && anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH)
9227 /* Emit the new_jump instruction and delete the old anchor. */
9228 rtvec vtemp = gen_rtvec (2, copy_rtx (PATTERN (anchor)),
9229 copy_rtx (PATTERN (floater)));
9230 rtx temp = gen_rtx_PARALLEL (VOIDmode, vtemp);
9231 temp = emit_jump_insn_before (temp, anchor);
9233 JUMP_LABEL (temp) = JUMP_LABEL (anchor);
9234 SET_INSN_DELETED (anchor);
9236 /* Emit a special USE insn for FLOATER, then delete
9237 the floating insn. */
9238 temp = copy_rtx (PATTERN (floater));
9239 emit_insn_before (gen_rtx_USE (VOIDmode, temp), floater);
9240 delete_insn (floater);
9241 continue;
9247 static int
9248 pa_can_combine_p (rtx_insn *new_rtx, rtx_insn *anchor, rtx_insn *floater,
9249 int reversed, rtx dest,
9250 rtx src1, rtx src2)
9252 int insn_code_number;
9253 rtx_insn *start, *end;
9255 /* Create a PARALLEL with the patterns of ANCHOR and
9256 FLOATER, try to recognize it, then test constraints
9257 for the resulting pattern.
9259 If the pattern doesn't match or the constraints
9260 aren't met keep searching for a suitable floater
9261 insn. */
9262 XVECEXP (PATTERN (new_rtx), 0, 0) = PATTERN (anchor);
9263 XVECEXP (PATTERN (new_rtx), 0, 1) = PATTERN (floater);
9264 INSN_CODE (new_rtx) = -1;
9265 insn_code_number = recog_memoized (new_rtx);
9266 basic_block bb = BLOCK_FOR_INSN (anchor);
9267 if (insn_code_number < 0
9268 || (extract_insn (new_rtx),
9269 !constrain_operands (1, get_preferred_alternatives (new_rtx, bb))))
9270 return 0;
9272 if (reversed)
9274 start = anchor;
9275 end = floater;
9277 else
9279 start = floater;
9280 end = anchor;
9283 /* There's up to three operands to consider. One
9284 output and two inputs.
9286 The output must not be used between FLOATER & ANCHOR
9287 exclusive. The inputs must not be set between
9288 FLOATER and ANCHOR exclusive. */
9290 if (reg_used_between_p (dest, start, end))
9291 return 0;
9293 if (reg_set_between_p (src1, start, end))
9294 return 0;
9296 if (reg_set_between_p (src2, start, end))
9297 return 0;
9299 /* If we get here, then everything is good. */
9300 return 1;
9303 /* Return nonzero if references for INSN are delayed.
9305 Millicode insns are actually function calls with some special
9306 constraints on arguments and register usage.
9308 Millicode calls always expect their arguments in the integer argument
9309 registers, and always return their result in %r29 (ret1). They
9310 are expected to clobber their arguments, %r1, %r29, and the return
9311 pointer which is %r31 on 32-bit and %r2 on 64-bit, and nothing else.
9313 This function tells reorg that the references to arguments and
9314 millicode calls do not appear to happen until after the millicode call.
9315 This allows reorg to put insns which set the argument registers into the
9316 delay slot of the millicode call -- thus they act more like traditional
9317 CALL_INSNs.
9319 Note we cannot consider side effects of the insn to be delayed because
9320 the branch and link insn will clobber the return pointer. If we happened
9321 to use the return pointer in the delay slot of the call, then we lose.
9323 get_attr_type will try to recognize the given insn, so make sure to
9324 filter out things it will not accept -- SEQUENCE, USE and CLOBBER insns
9325 in particular. */
9327 pa_insn_refs_are_delayed (rtx_insn *insn)
9329 return ((NONJUMP_INSN_P (insn)
9330 && GET_CODE (PATTERN (insn)) != SEQUENCE
9331 && GET_CODE (PATTERN (insn)) != USE
9332 && GET_CODE (PATTERN (insn)) != CLOBBER
9333 && get_attr_type (insn) == TYPE_MILLI));
9336 /* Promote the return value, but not the arguments. */
9338 static machine_mode
9339 pa_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
9340 machine_mode mode,
9341 int *punsignedp ATTRIBUTE_UNUSED,
9342 const_tree fntype ATTRIBUTE_UNUSED,
9343 int for_return)
9345 if (for_return == 0)
9346 return mode;
9347 return promote_mode (type, mode, punsignedp);
9350 /* On the HP-PA the value is found in register(s) 28(-29), unless
9351 the mode is SF or DF. Then the value is returned in fr4 (32).
9353 This must perform the same promotions as PROMOTE_MODE, else promoting
9354 return values in TARGET_PROMOTE_FUNCTION_MODE will not work correctly.
9356 Small structures must be returned in a PARALLEL on PA64 in order
9357 to match the HP Compiler ABI. */
9359 static rtx
9360 pa_function_value (const_tree valtype,
9361 const_tree func ATTRIBUTE_UNUSED,
9362 bool outgoing ATTRIBUTE_UNUSED)
9364 machine_mode valmode;
9366 if (AGGREGATE_TYPE_P (valtype)
9367 || TREE_CODE (valtype) == COMPLEX_TYPE
9368 || TREE_CODE (valtype) == VECTOR_TYPE)
9370 HOST_WIDE_INT valsize = int_size_in_bytes (valtype);
9372 /* Handle aggregates that fit exactly in a word or double word. */
9373 if ((valsize & (UNITS_PER_WORD - 1)) == 0)
9374 return gen_rtx_REG (TYPE_MODE (valtype), 28);
9376 if (TARGET_64BIT)
9378 /* Aggregates with a size less than or equal to 128 bits are
9379 returned in GR 28(-29). They are left justified. The pad
9380 bits are undefined. Larger aggregates are returned in
9381 memory. */
9382 rtx loc[2];
9383 int i, offset = 0;
9384 int ub = valsize <= UNITS_PER_WORD ? 1 : 2;
9386 for (i = 0; i < ub; i++)
9388 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9389 gen_rtx_REG (DImode, 28 + i),
9390 GEN_INT (offset));
9391 offset += 8;
9394 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (ub, loc));
9396 else if (valsize > UNITS_PER_WORD)
9398 /* Aggregates 5 to 8 bytes in size are returned in general
9399 registers r28-r29 in the same manner as other non
9400 floating-point objects. The data is right-justified and
9401 zero-extended to 64 bits. This is opposite to the normal
9402 justification used on big endian targets and requires
9403 special treatment. */
9404 rtx loc = gen_rtx_EXPR_LIST (VOIDmode,
9405 gen_rtx_REG (DImode, 28), const0_rtx);
9406 return gen_rtx_PARALLEL (BLKmode, gen_rtvec (1, loc));
9410 if ((INTEGRAL_TYPE_P (valtype)
9411 && GET_MODE_BITSIZE (TYPE_MODE (valtype)) < BITS_PER_WORD)
9412 || POINTER_TYPE_P (valtype))
9413 valmode = word_mode;
9414 else
9415 valmode = TYPE_MODE (valtype);
9417 if (TREE_CODE (valtype) == REAL_TYPE
9418 && !AGGREGATE_TYPE_P (valtype)
9419 && TYPE_MODE (valtype) != TFmode
9420 && !TARGET_SOFT_FLOAT)
9421 return gen_rtx_REG (valmode, 32);
9423 return gen_rtx_REG (valmode, 28);
9426 /* Implement the TARGET_LIBCALL_VALUE hook. */
9428 static rtx
9429 pa_libcall_value (machine_mode mode,
9430 const_rtx fun ATTRIBUTE_UNUSED)
9432 if (! TARGET_SOFT_FLOAT
9433 && (mode == SFmode || mode == DFmode))
9434 return gen_rtx_REG (mode, 32);
9435 else
9436 return gen_rtx_REG (mode, 28);
9439 /* Implement the TARGET_FUNCTION_VALUE_REGNO_P hook. */
9441 static bool
9442 pa_function_value_regno_p (const unsigned int regno)
9444 if (regno == 28
9445 || (! TARGET_SOFT_FLOAT && regno == 32))
9446 return true;
9448 return false;
9451 /* Update the data in CUM to advance over an argument
9452 of mode MODE and data type TYPE.
9453 (TYPE is null for libcalls where that information may not be available.) */
9455 static void
9456 pa_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
9457 const_tree type, bool named ATTRIBUTE_UNUSED)
9459 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
9460 int arg_size = FUNCTION_ARG_SIZE (mode, type);
9462 cum->nargs_prototype--;
9463 cum->words += (arg_size
9464 + ((cum->words & 01)
9465 && type != NULL_TREE
9466 && arg_size > 1));
9469 /* Return the location of a parameter that is passed in a register or NULL
9470 if the parameter has any component that is passed in memory.
9472 This is new code and will be pushed to into the net sources after
9473 further testing.
9475 ??? We might want to restructure this so that it looks more like other
9476 ports. */
9477 static rtx
9478 pa_function_arg (cumulative_args_t cum_v, machine_mode mode,
9479 const_tree type, bool named ATTRIBUTE_UNUSED)
9481 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
9482 int max_arg_words = (TARGET_64BIT ? 8 : 4);
9483 int alignment = 0;
9484 int arg_size;
9485 int fpr_reg_base;
9486 int gpr_reg_base;
9487 rtx retval;
9489 if (mode == VOIDmode)
9490 return NULL_RTX;
9492 arg_size = FUNCTION_ARG_SIZE (mode, type);
9494 /* If this arg would be passed partially or totally on the stack, then
9495 this routine should return zero. pa_arg_partial_bytes will
9496 handle arguments which are split between regs and stack slots if
9497 the ABI mandates split arguments. */
9498 if (!TARGET_64BIT)
9500 /* The 32-bit ABI does not split arguments. */
9501 if (cum->words + arg_size > max_arg_words)
9502 return NULL_RTX;
9504 else
9506 if (arg_size > 1)
9507 alignment = cum->words & 1;
9508 if (cum->words + alignment >= max_arg_words)
9509 return NULL_RTX;
9512 /* The 32bit ABIs and the 64bit ABIs are rather different,
9513 particularly in their handling of FP registers. We might
9514 be able to cleverly share code between them, but I'm not
9515 going to bother in the hope that splitting them up results
9516 in code that is more easily understood. */
9518 if (TARGET_64BIT)
9520 /* Advance the base registers to their current locations.
9522 Remember, gprs grow towards smaller register numbers while
9523 fprs grow to higher register numbers. Also remember that
9524 although FP regs are 32-bit addressable, we pretend that
9525 the registers are 64-bits wide. */
9526 gpr_reg_base = 26 - cum->words;
9527 fpr_reg_base = 32 + cum->words;
9529 /* Arguments wider than one word and small aggregates need special
9530 treatment. */
9531 if (arg_size > 1
9532 || mode == BLKmode
9533 || (type && (AGGREGATE_TYPE_P (type)
9534 || TREE_CODE (type) == COMPLEX_TYPE
9535 || TREE_CODE (type) == VECTOR_TYPE)))
9537 /* Double-extended precision (80-bit), quad-precision (128-bit)
9538 and aggregates including complex numbers are aligned on
9539 128-bit boundaries. The first eight 64-bit argument slots
9540 are associated one-to-one, with general registers r26
9541 through r19, and also with floating-point registers fr4
9542 through fr11. Arguments larger than one word are always
9543 passed in general registers.
9545 Using a PARALLEL with a word mode register results in left
9546 justified data on a big-endian target. */
9548 rtx loc[8];
9549 int i, offset = 0, ub = arg_size;
9551 /* Align the base register. */
9552 gpr_reg_base -= alignment;
9554 ub = MIN (ub, max_arg_words - cum->words - alignment);
9555 for (i = 0; i < ub; i++)
9557 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9558 gen_rtx_REG (DImode, gpr_reg_base),
9559 GEN_INT (offset));
9560 gpr_reg_base -= 1;
9561 offset += 8;
9564 return gen_rtx_PARALLEL (mode, gen_rtvec_v (ub, loc));
9567 else
9569 /* If the argument is larger than a word, then we know precisely
9570 which registers we must use. */
9571 if (arg_size > 1)
9573 if (cum->words)
9575 gpr_reg_base = 23;
9576 fpr_reg_base = 38;
9578 else
9580 gpr_reg_base = 25;
9581 fpr_reg_base = 34;
9584 /* Structures 5 to 8 bytes in size are passed in the general
9585 registers in the same manner as other non floating-point
9586 objects. The data is right-justified and zero-extended
9587 to 64 bits. This is opposite to the normal justification
9588 used on big endian targets and requires special treatment.
9589 We now define BLOCK_REG_PADDING to pad these objects.
9590 Aggregates, complex and vector types are passed in the same
9591 manner as structures. */
9592 if (mode == BLKmode
9593 || (type && (AGGREGATE_TYPE_P (type)
9594 || TREE_CODE (type) == COMPLEX_TYPE
9595 || TREE_CODE (type) == VECTOR_TYPE)))
9597 rtx loc = gen_rtx_EXPR_LIST (VOIDmode,
9598 gen_rtx_REG (DImode, gpr_reg_base),
9599 const0_rtx);
9600 return gen_rtx_PARALLEL (BLKmode, gen_rtvec (1, loc));
9603 else
9605 /* We have a single word (32 bits). A simple computation
9606 will get us the register #s we need. */
9607 gpr_reg_base = 26 - cum->words;
9608 fpr_reg_base = 32 + 2 * cum->words;
9612 /* Determine if the argument needs to be passed in both general and
9613 floating point registers. */
9614 if (((TARGET_PORTABLE_RUNTIME || TARGET_64BIT || TARGET_ELF32)
9615 /* If we are doing soft-float with portable runtime, then there
9616 is no need to worry about FP regs. */
9617 && !TARGET_SOFT_FLOAT
9618 /* The parameter must be some kind of scalar float, else we just
9619 pass it in integer registers. */
9620 && GET_MODE_CLASS (mode) == MODE_FLOAT
9621 /* The target function must not have a prototype. */
9622 && cum->nargs_prototype <= 0
9623 /* libcalls do not need to pass items in both FP and general
9624 registers. */
9625 && type != NULL_TREE
9626 /* All this hair applies to "outgoing" args only. This includes
9627 sibcall arguments setup with FUNCTION_INCOMING_ARG. */
9628 && !cum->incoming)
9629 /* Also pass outgoing floating arguments in both registers in indirect
9630 calls with the 32 bit ABI and the HP assembler since there is no
9631 way to the specify argument locations in static functions. */
9632 || (!TARGET_64BIT
9633 && !TARGET_GAS
9634 && !cum->incoming
9635 && cum->indirect
9636 && GET_MODE_CLASS (mode) == MODE_FLOAT))
9638 retval
9639 = gen_rtx_PARALLEL
9640 (mode,
9641 gen_rtvec (2,
9642 gen_rtx_EXPR_LIST (VOIDmode,
9643 gen_rtx_REG (mode, fpr_reg_base),
9644 const0_rtx),
9645 gen_rtx_EXPR_LIST (VOIDmode,
9646 gen_rtx_REG (mode, gpr_reg_base),
9647 const0_rtx)));
9649 else
9651 /* See if we should pass this parameter in a general register. */
9652 if (TARGET_SOFT_FLOAT
9653 /* Indirect calls in the normal 32bit ABI require all arguments
9654 to be passed in general registers. */
9655 || (!TARGET_PORTABLE_RUNTIME
9656 && !TARGET_64BIT
9657 && !TARGET_ELF32
9658 && cum->indirect)
9659 /* If the parameter is not a scalar floating-point parameter,
9660 then it belongs in GPRs. */
9661 || GET_MODE_CLASS (mode) != MODE_FLOAT
9662 /* Structure with single SFmode field belongs in GPR. */
9663 || (type && AGGREGATE_TYPE_P (type)))
9664 retval = gen_rtx_REG (mode, gpr_reg_base);
9665 else
9666 retval = gen_rtx_REG (mode, fpr_reg_base);
9668 return retval;
9671 /* Arguments larger than one word are double word aligned. */
9673 static unsigned int
9674 pa_function_arg_boundary (machine_mode mode, const_tree type)
9676 bool singleword = (type
9677 ? (integer_zerop (TYPE_SIZE (type))
9678 || !TREE_CONSTANT (TYPE_SIZE (type))
9679 || int_size_in_bytes (type) <= UNITS_PER_WORD)
9680 : GET_MODE_SIZE (mode) <= UNITS_PER_WORD);
9682 return singleword ? PARM_BOUNDARY : MAX_PARM_BOUNDARY;
9685 /* If this arg would be passed totally in registers or totally on the stack,
9686 then this routine should return zero. */
9688 static int
9689 pa_arg_partial_bytes (cumulative_args_t cum_v, machine_mode mode,
9690 tree type, bool named ATTRIBUTE_UNUSED)
9692 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
9693 unsigned int max_arg_words = 8;
9694 unsigned int offset = 0;
9696 if (!TARGET_64BIT)
9697 return 0;
9699 if (FUNCTION_ARG_SIZE (mode, type) > 1 && (cum->words & 1))
9700 offset = 1;
9702 if (cum->words + offset + FUNCTION_ARG_SIZE (mode, type) <= max_arg_words)
9703 /* Arg fits fully into registers. */
9704 return 0;
9705 else if (cum->words + offset >= max_arg_words)
9706 /* Arg fully on the stack. */
9707 return 0;
9708 else
9709 /* Arg is split. */
9710 return (max_arg_words - cum->words - offset) * UNITS_PER_WORD;
9714 /* A get_unnamed_section callback for switching to the text section.
9716 This function is only used with SOM. Because we don't support
9717 named subspaces, we can only create a new subspace or switch back
9718 to the default text subspace. */
9720 static void
9721 som_output_text_section_asm_op (const void *data ATTRIBUTE_UNUSED)
9723 gcc_assert (TARGET_SOM);
9724 if (TARGET_GAS)
9726 if (cfun && cfun->machine && !cfun->machine->in_nsubspa)
9728 /* We only want to emit a .nsubspa directive once at the
9729 start of the function. */
9730 cfun->machine->in_nsubspa = 1;
9732 /* Create a new subspace for the text. This provides
9733 better stub placement and one-only functions. */
9734 if (cfun->decl
9735 && DECL_ONE_ONLY (cfun->decl)
9736 && !DECL_WEAK (cfun->decl))
9738 output_section_asm_op ("\t.SPACE $TEXT$\n"
9739 "\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,"
9740 "ACCESS=44,SORT=24,COMDAT");
9741 return;
9744 else
9746 /* There isn't a current function or the body of the current
9747 function has been completed. So, we are changing to the
9748 text section to output debugging information. Thus, we
9749 need to forget that we are in the text section so that
9750 varasm.c will call us when text_section is selected again. */
9751 gcc_assert (!cfun || !cfun->machine
9752 || cfun->machine->in_nsubspa == 2);
9753 in_section = NULL;
9755 output_section_asm_op ("\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$");
9756 return;
9758 output_section_asm_op ("\t.SPACE $TEXT$\n\t.SUBSPA $CODE$");
9761 /* A get_unnamed_section callback for switching to comdat data
9762 sections. This function is only used with SOM. */
9764 static void
9765 som_output_comdat_data_section_asm_op (const void *data)
9767 in_section = NULL;
9768 output_section_asm_op (data);
9771 /* Implement TARGET_ASM_INITIALIZE_SECTIONS */
9773 static void
9774 pa_som_asm_init_sections (void)
9776 text_section
9777 = get_unnamed_section (0, som_output_text_section_asm_op, NULL);
9779 /* SOM puts readonly data in the default $LIT$ subspace when PIC code
9780 is not being generated. */
9781 som_readonly_data_section
9782 = get_unnamed_section (0, output_section_asm_op,
9783 "\t.SPACE $TEXT$\n\t.SUBSPA $LIT$");
9785 /* When secondary definitions are not supported, SOM makes readonly
9786 data one-only by creating a new $LIT$ subspace in $TEXT$ with
9787 the comdat flag. */
9788 som_one_only_readonly_data_section
9789 = get_unnamed_section (0, som_output_comdat_data_section_asm_op,
9790 "\t.SPACE $TEXT$\n"
9791 "\t.NSUBSPA $LIT$,QUAD=0,ALIGN=8,"
9792 "ACCESS=0x2c,SORT=16,COMDAT");
9795 /* When secondary definitions are not supported, SOM makes data one-only
9796 by creating a new $DATA$ subspace in $PRIVATE$ with the comdat flag. */
9797 som_one_only_data_section
9798 = get_unnamed_section (SECTION_WRITE,
9799 som_output_comdat_data_section_asm_op,
9800 "\t.SPACE $PRIVATE$\n"
9801 "\t.NSUBSPA $DATA$,QUAD=1,ALIGN=8,"
9802 "ACCESS=31,SORT=24,COMDAT");
9804 if (flag_tm)
9805 som_tm_clone_table_section
9806 = get_unnamed_section (0, output_section_asm_op,
9807 "\t.SPACE $PRIVATE$\n\t.SUBSPA $TM_CLONE_TABLE$");
9809 /* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups
9810 which reference data within the $TEXT$ space (for example constant
9811 strings in the $LIT$ subspace).
9813 The assemblers (GAS and HP as) both have problems with handling
9814 the difference of two symbols which is the other correct way to
9815 reference constant data during PIC code generation.
9817 So, there's no way to reference constant data which is in the
9818 $TEXT$ space during PIC generation. Instead place all constant
9819 data into the $PRIVATE$ subspace (this reduces sharing, but it
9820 works correctly). */
9821 readonly_data_section = flag_pic ? data_section : som_readonly_data_section;
9823 /* We must not have a reference to an external symbol defined in a
9824 shared library in a readonly section, else the SOM linker will
9825 complain.
9827 So, we force exception information into the data section. */
9828 exception_section = data_section;
9831 /* Implement TARGET_ASM_TM_CLONE_TABLE_SECTION. */
9833 static section *
9834 pa_som_tm_clone_table_section (void)
9836 return som_tm_clone_table_section;
9839 /* On hpux10, the linker will give an error if we have a reference
9840 in the read-only data section to a symbol defined in a shared
9841 library. Therefore, expressions that might require a reloc can
9842 not be placed in the read-only data section. */
9844 static section *
9845 pa_select_section (tree exp, int reloc,
9846 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
9848 if (TREE_CODE (exp) == VAR_DECL
9849 && TREE_READONLY (exp)
9850 && !TREE_THIS_VOLATILE (exp)
9851 && DECL_INITIAL (exp)
9852 && (DECL_INITIAL (exp) == error_mark_node
9853 || TREE_CONSTANT (DECL_INITIAL (exp)))
9854 && !reloc)
9856 if (TARGET_SOM
9857 && DECL_ONE_ONLY (exp)
9858 && !DECL_WEAK (exp))
9859 return som_one_only_readonly_data_section;
9860 else
9861 return readonly_data_section;
9863 else if (CONSTANT_CLASS_P (exp) && !reloc)
9864 return readonly_data_section;
9865 else if (TARGET_SOM
9866 && TREE_CODE (exp) == VAR_DECL
9867 && DECL_ONE_ONLY (exp)
9868 && !DECL_WEAK (exp))
9869 return som_one_only_data_section;
9870 else
9871 return data_section;
9874 /* Implement pa_reloc_rw_mask. */
9876 static int
9877 pa_reloc_rw_mask (void)
9879 /* We force (const (plus (symbol) (const_int))) to memory when the
9880 const_int doesn't fit in a 14-bit integer. The SOM linker can't
9881 handle this construct in read-only memory and we want to avoid
9882 this for ELF. So, we always force an RTX needing relocation to
9883 the data section. */
9884 return 3;
9887 static void
9888 pa_globalize_label (FILE *stream, const char *name)
9890 /* We only handle DATA objects here, functions are globalized in
9891 ASM_DECLARE_FUNCTION_NAME. */
9892 if (! FUNCTION_NAME_P (name))
9894 fputs ("\t.EXPORT ", stream);
9895 assemble_name (stream, name);
9896 fputs (",DATA\n", stream);
9900 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
9902 static rtx
9903 pa_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
9904 int incoming ATTRIBUTE_UNUSED)
9906 return gen_rtx_REG (Pmode, PA_STRUCT_VALUE_REGNUM);
9909 /* Worker function for TARGET_RETURN_IN_MEMORY. */
9911 bool
9912 pa_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
9914 /* SOM ABI says that objects larger than 64 bits are returned in memory.
9915 PA64 ABI says that objects larger than 128 bits are returned in memory.
9916 Note, int_size_in_bytes can return -1 if the size of the object is
9917 variable or larger than the maximum value that can be expressed as
9918 a HOST_WIDE_INT. It can also return zero for an empty type. The
9919 simplest way to handle variable and empty types is to pass them in
9920 memory. This avoids problems in defining the boundaries of argument
9921 slots, allocating registers, etc. */
9922 return (int_size_in_bytes (type) > (TARGET_64BIT ? 16 : 8)
9923 || int_size_in_bytes (type) <= 0);
9926 /* Structure to hold declaration and name of external symbols that are
9927 emitted by GCC. We generate a vector of these symbols and output them
9928 at the end of the file if and only if SYMBOL_REF_REFERENCED_P is true.
9929 This avoids putting out names that are never really used. */
9931 typedef struct GTY(()) extern_symbol
9933 tree decl;
9934 const char *name;
9935 } extern_symbol;
9937 /* Define gc'd vector type for extern_symbol. */
9939 /* Vector of extern_symbol pointers. */
9940 static GTY(()) vec<extern_symbol, va_gc> *extern_symbols;
9942 #ifdef ASM_OUTPUT_EXTERNAL_REAL
9943 /* Mark DECL (name NAME) as an external reference (assembler output
9944 file FILE). This saves the names to output at the end of the file
9945 if actually referenced. */
9947 void
9948 pa_hpux_asm_output_external (FILE *file, tree decl, const char *name)
9950 gcc_assert (file == asm_out_file);
9951 extern_symbol p = {decl, name};
9952 vec_safe_push (extern_symbols, p);
9955 /* Output text required at the end of an assembler file.
9956 This includes deferred plabels and .import directives for
9957 all external symbols that were actually referenced. */
9959 static void
9960 pa_hpux_file_end (void)
9962 unsigned int i;
9963 extern_symbol *p;
9965 if (!NO_DEFERRED_PROFILE_COUNTERS)
9966 output_deferred_profile_counters ();
9968 output_deferred_plabels ();
9970 for (i = 0; vec_safe_iterate (extern_symbols, i, &p); i++)
9972 tree decl = p->decl;
9974 if (!TREE_ASM_WRITTEN (decl)
9975 && SYMBOL_REF_REFERENCED_P (XEXP (DECL_RTL (decl), 0)))
9976 ASM_OUTPUT_EXTERNAL_REAL (asm_out_file, decl, p->name);
9979 vec_free (extern_symbols);
9981 #endif
9983 /* Return true if a change from mode FROM to mode TO for a register
9984 in register class RCLASS is invalid. */
9986 bool
9987 pa_cannot_change_mode_class (machine_mode from, machine_mode to,
9988 enum reg_class rclass)
9990 if (from == to)
9991 return false;
9993 if (GET_MODE_SIZE (from) == GET_MODE_SIZE (to))
9994 return false;
9996 /* Reject changes to/from modes with zero size. */
9997 if (!GET_MODE_SIZE (from) || !GET_MODE_SIZE (to))
9998 return true;
10000 /* Reject changes to/from complex and vector modes. */
10001 if (COMPLEX_MODE_P (from) || VECTOR_MODE_P (from)
10002 || COMPLEX_MODE_P (to) || VECTOR_MODE_P (to))
10003 return true;
10005 /* There is no way to load QImode or HImode values directly from memory
10006 to a FP register. SImode loads to the FP registers are not zero
10007 extended. On the 64-bit target, this conflicts with the definition
10008 of LOAD_EXTEND_OP. Thus, we can't allow changing between modes with
10009 different sizes in the floating-point registers. */
10010 if (MAYBE_FP_REG_CLASS_P (rclass))
10011 return true;
10013 /* TARGET_HARD_REGNO_MODE_OK places modes with sizes larger than a word
10014 in specific sets of registers. Thus, we cannot allow changing
10015 to a larger mode when it's larger than a word. */
10016 if (GET_MODE_SIZE (to) > UNITS_PER_WORD
10017 && GET_MODE_SIZE (to) > GET_MODE_SIZE (from))
10018 return true;
10020 return false;
10023 /* Implement TARGET_MODES_TIEABLE_P.
10025 We should return FALSE for QImode and HImode because these modes
10026 are not ok in the floating-point registers. However, this prevents
10027 tieing these modes to SImode and DImode in the general registers.
10028 So, this isn't a good idea. We rely on TARGET_HARD_REGNO_MODE_OK and
10029 CANNOT_CHANGE_MODE_CLASS to prevent these modes from being used
10030 in the floating-point registers. */
10032 static bool
10033 pa_modes_tieable_p (machine_mode mode1, machine_mode mode2)
10035 /* Don't tie modes in different classes. */
10036 if (GET_MODE_CLASS (mode1) != GET_MODE_CLASS (mode2))
10037 return false;
10039 return true;
10043 /* Length in units of the trampoline instruction code. */
10045 #define TRAMPOLINE_CODE_SIZE (TARGET_64BIT ? 24 : (TARGET_PA_20 ? 32 : 40))
10048 /* Output assembler code for a block containing the constant parts
10049 of a trampoline, leaving space for the variable parts.\
10051 The trampoline sets the static chain pointer to STATIC_CHAIN_REGNUM
10052 and then branches to the specified routine.
10054 This code template is copied from text segment to stack location
10055 and then patched with pa_trampoline_init to contain valid values,
10056 and then entered as a subroutine.
10058 It is best to keep this as small as possible to avoid having to
10059 flush multiple lines in the cache. */
10061 static void
10062 pa_asm_trampoline_template (FILE *f)
10064 if (!TARGET_64BIT)
10066 fputs ("\tldw 36(%r22),%r21\n", f);
10067 fputs ("\tbb,>=,n %r21,30,.+16\n", f);
10068 if (ASSEMBLER_DIALECT == 0)
10069 fputs ("\tdepi 0,31,2,%r21\n", f);
10070 else
10071 fputs ("\tdepwi 0,31,2,%r21\n", f);
10072 fputs ("\tldw 4(%r21),%r19\n", f);
10073 fputs ("\tldw 0(%r21),%r21\n", f);
10074 if (TARGET_PA_20)
10076 fputs ("\tbve (%r21)\n", f);
10077 fputs ("\tldw 40(%r22),%r29\n", f);
10078 fputs ("\t.word 0\n", f);
10079 fputs ("\t.word 0\n", f);
10081 else
10083 fputs ("\tldsid (%r21),%r1\n", f);
10084 fputs ("\tmtsp %r1,%sr0\n", f);
10085 fputs ("\tbe 0(%sr0,%r21)\n", f);
10086 fputs ("\tldw 40(%r22),%r29\n", f);
10088 fputs ("\t.word 0\n", f);
10089 fputs ("\t.word 0\n", f);
10090 fputs ("\t.word 0\n", f);
10091 fputs ("\t.word 0\n", f);
10093 else
10095 fputs ("\t.dword 0\n", f);
10096 fputs ("\t.dword 0\n", f);
10097 fputs ("\t.dword 0\n", f);
10098 fputs ("\t.dword 0\n", f);
10099 fputs ("\tmfia %r31\n", f);
10100 fputs ("\tldd 24(%r31),%r1\n", f);
10101 fputs ("\tldd 24(%r1),%r27\n", f);
10102 fputs ("\tldd 16(%r1),%r1\n", f);
10103 fputs ("\tbve (%r1)\n", f);
10104 fputs ("\tldd 32(%r31),%r31\n", f);
10105 fputs ("\t.dword 0 ; fptr\n", f);
10106 fputs ("\t.dword 0 ; static link\n", f);
10110 /* Emit RTL insns to initialize the variable parts of a trampoline.
10111 FNADDR is an RTX for the address of the function's pure code.
10112 CXT is an RTX for the static chain value for the function.
10114 Move the function address to the trampoline template at offset 36.
10115 Move the static chain value to trampoline template at offset 40.
10116 Move the trampoline address to trampoline template at offset 44.
10117 Move r19 to trampoline template at offset 48. The latter two
10118 words create a plabel for the indirect call to the trampoline.
10120 A similar sequence is used for the 64-bit port but the plabel is
10121 at the beginning of the trampoline.
10123 Finally, the cache entries for the trampoline code are flushed.
10124 This is necessary to ensure that the trampoline instruction sequence
10125 is written to memory prior to any attempts at prefetching the code
10126 sequence. */
10128 static void
10129 pa_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
10131 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
10132 rtx start_addr = gen_reg_rtx (Pmode);
10133 rtx end_addr = gen_reg_rtx (Pmode);
10134 rtx line_length = gen_reg_rtx (Pmode);
10135 rtx r_tramp, tmp;
10137 emit_block_move (m_tramp, assemble_trampoline_template (),
10138 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
10139 r_tramp = force_reg (Pmode, XEXP (m_tramp, 0));
10141 if (!TARGET_64BIT)
10143 tmp = adjust_address (m_tramp, Pmode, 36);
10144 emit_move_insn (tmp, fnaddr);
10145 tmp = adjust_address (m_tramp, Pmode, 40);
10146 emit_move_insn (tmp, chain_value);
10148 /* Create a fat pointer for the trampoline. */
10149 tmp = adjust_address (m_tramp, Pmode, 44);
10150 emit_move_insn (tmp, r_tramp);
10151 tmp = adjust_address (m_tramp, Pmode, 48);
10152 emit_move_insn (tmp, gen_rtx_REG (Pmode, 19));
10154 /* fdc and fic only use registers for the address to flush,
10155 they do not accept integer displacements. We align the
10156 start and end addresses to the beginning of their respective
10157 cache lines to minimize the number of lines flushed. */
10158 emit_insn (gen_andsi3 (start_addr, r_tramp,
10159 GEN_INT (-MIN_CACHELINE_SIZE)));
10160 tmp = force_reg (Pmode, plus_constant (Pmode, r_tramp,
10161 TRAMPOLINE_CODE_SIZE-1));
10162 emit_insn (gen_andsi3 (end_addr, tmp,
10163 GEN_INT (-MIN_CACHELINE_SIZE)));
10164 emit_move_insn (line_length, GEN_INT (MIN_CACHELINE_SIZE));
10165 emit_insn (gen_dcacheflushsi (start_addr, end_addr, line_length));
10166 emit_insn (gen_icacheflushsi (start_addr, end_addr, line_length,
10167 gen_reg_rtx (Pmode),
10168 gen_reg_rtx (Pmode)));
10170 else
10172 tmp = adjust_address (m_tramp, Pmode, 56);
10173 emit_move_insn (tmp, fnaddr);
10174 tmp = adjust_address (m_tramp, Pmode, 64);
10175 emit_move_insn (tmp, chain_value);
10177 /* Create a fat pointer for the trampoline. */
10178 tmp = adjust_address (m_tramp, Pmode, 16);
10179 emit_move_insn (tmp, force_reg (Pmode, plus_constant (Pmode,
10180 r_tramp, 32)));
10181 tmp = adjust_address (m_tramp, Pmode, 24);
10182 emit_move_insn (tmp, gen_rtx_REG (Pmode, 27));
10184 /* fdc and fic only use registers for the address to flush,
10185 they do not accept integer displacements. We align the
10186 start and end addresses to the beginning of their respective
10187 cache lines to minimize the number of lines flushed. */
10188 tmp = force_reg (Pmode, plus_constant (Pmode, r_tramp, 32));
10189 emit_insn (gen_anddi3 (start_addr, tmp,
10190 GEN_INT (-MIN_CACHELINE_SIZE)));
10191 tmp = force_reg (Pmode, plus_constant (Pmode, tmp,
10192 TRAMPOLINE_CODE_SIZE - 1));
10193 emit_insn (gen_anddi3 (end_addr, tmp,
10194 GEN_INT (-MIN_CACHELINE_SIZE)));
10195 emit_move_insn (line_length, GEN_INT (MIN_CACHELINE_SIZE));
10196 emit_insn (gen_dcacheflushdi (start_addr, end_addr, line_length));
10197 emit_insn (gen_icacheflushdi (start_addr, end_addr, line_length,
10198 gen_reg_rtx (Pmode),
10199 gen_reg_rtx (Pmode)));
10202 #ifdef HAVE_ENABLE_EXECUTE_STACK
10203  emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
10204 LCT_NORMAL, VOIDmode, XEXP (m_tramp, 0), Pmode);
10205 #endif
10208 /* Perform any machine-specific adjustment in the address of the trampoline.
10209 ADDR contains the address that was passed to pa_trampoline_init.
10210 Adjust the trampoline address to point to the plabel at offset 44. */
10212 static rtx
10213 pa_trampoline_adjust_address (rtx addr)
10215 if (!TARGET_64BIT)
10216 addr = memory_address (Pmode, plus_constant (Pmode, addr, 46));
10217 return addr;
10220 static rtx
10221 pa_delegitimize_address (rtx orig_x)
10223 rtx x = delegitimize_mem_from_attrs (orig_x);
10225 if (GET_CODE (x) == LO_SUM
10226 && GET_CODE (XEXP (x, 1)) == UNSPEC
10227 && XINT (XEXP (x, 1), 1) == UNSPEC_DLTIND14R)
10228 return gen_const_mem (Pmode, XVECEXP (XEXP (x, 1), 0, 0));
10229 return x;
10232 static rtx
10233 pa_internal_arg_pointer (void)
10235 /* The argument pointer and the hard frame pointer are the same in
10236 the 32-bit runtime, so we don't need a copy. */
10237 if (TARGET_64BIT)
10238 return copy_to_reg (virtual_incoming_args_rtx);
10239 else
10240 return virtual_incoming_args_rtx;
10243 /* Given FROM and TO register numbers, say whether this elimination is allowed.
10244 Frame pointer elimination is automatically handled. */
10246 static bool
10247 pa_can_eliminate (const int from, const int to)
10249 /* The argument cannot be eliminated in the 64-bit runtime. */
10250 if (TARGET_64BIT && from == ARG_POINTER_REGNUM)
10251 return false;
10253 return (from == HARD_FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM
10254 ? ! frame_pointer_needed
10255 : true);
10258 /* Define the offset between two registers, FROM to be eliminated and its
10259 replacement TO, at the start of a routine. */
10260 HOST_WIDE_INT
10261 pa_initial_elimination_offset (int from, int to)
10263 HOST_WIDE_INT offset;
10265 if ((from == HARD_FRAME_POINTER_REGNUM || from == FRAME_POINTER_REGNUM)
10266 && to == STACK_POINTER_REGNUM)
10267 offset = -pa_compute_frame_size (get_frame_size (), 0);
10268 else if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
10269 offset = 0;
10270 else
10271 gcc_unreachable ();
10273 return offset;
10276 static void
10277 pa_conditional_register_usage (void)
10279 int i;
10281 if (!TARGET_64BIT && !TARGET_PA_11)
10283 for (i = 56; i <= FP_REG_LAST; i++)
10284 fixed_regs[i] = call_used_regs[i] = 1;
10285 for (i = 33; i < 56; i += 2)
10286 fixed_regs[i] = call_used_regs[i] = 1;
10288 if (TARGET_DISABLE_FPREGS || TARGET_SOFT_FLOAT)
10290 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
10291 fixed_regs[i] = call_used_regs[i] = 1;
10293 if (flag_pic)
10294 fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
10297 /* Target hook for c_mode_for_suffix. */
10299 static machine_mode
10300 pa_c_mode_for_suffix (char suffix)
10302 if (HPUX_LONG_DOUBLE_LIBRARY)
10304 if (suffix == 'q')
10305 return TFmode;
10308 return VOIDmode;
10311 /* Target hook for function_section. */
10313 static section *
10314 pa_function_section (tree decl, enum node_frequency freq,
10315 bool startup, bool exit)
10317 /* Put functions in text section if target doesn't have named sections. */
10318 if (!targetm_common.have_named_sections)
10319 return text_section;
10321 /* Force nested functions into the same section as the containing
10322 function. */
10323 if (decl
10324 && DECL_SECTION_NAME (decl) == NULL
10325 && DECL_CONTEXT (decl) != NULL_TREE
10326 && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL
10327 && DECL_SECTION_NAME (DECL_CONTEXT (decl)) == NULL)
10328 return function_section (DECL_CONTEXT (decl));
10330 /* Otherwise, use the default function section. */
10331 return default_function_section (decl, freq, startup, exit);
10334 /* Implement TARGET_LEGITIMATE_CONSTANT_P.
10336 In 64-bit mode, we reject CONST_DOUBLES. We also reject CONST_INTS
10337 that need more than three instructions to load prior to reload. This
10338 limit is somewhat arbitrary. It takes three instructions to load a
10339 CONST_INT from memory but two are memory accesses. It may be better
10340 to increase the allowed range for CONST_INTS. We may also be able
10341 to handle CONST_DOUBLES. */
10343 static bool
10344 pa_legitimate_constant_p (machine_mode mode, rtx x)
10346 if (GET_MODE_CLASS (mode) == MODE_FLOAT && x != CONST0_RTX (mode))
10347 return false;
10349 if (!NEW_HP_ASSEMBLER && !TARGET_GAS && GET_CODE (x) == LABEL_REF)
10350 return false;
10352 /* TLS_MODEL_GLOBAL_DYNAMIC and TLS_MODEL_LOCAL_DYNAMIC are not
10353 legitimate constants. The other variants can't be handled by
10354 the move patterns after reload starts. */
10355 if (tls_referenced_p (x))
10356 return false;
10358 if (TARGET_64BIT && GET_CODE (x) == CONST_DOUBLE)
10359 return false;
10361 if (TARGET_64BIT
10362 && HOST_BITS_PER_WIDE_INT > 32
10363 && GET_CODE (x) == CONST_INT
10364 && !reload_in_progress
10365 && !reload_completed
10366 && !LEGITIMATE_64BIT_CONST_INT_P (INTVAL (x))
10367 && !pa_cint_ok_for_move (UINTVAL (x)))
10368 return false;
10370 if (function_label_operand (x, mode))
10371 return false;
10373 return true;
10376 /* Implement TARGET_SECTION_TYPE_FLAGS. */
10378 static unsigned int
10379 pa_section_type_flags (tree decl, const char *name, int reloc)
10381 unsigned int flags;
10383 flags = default_section_type_flags (decl, name, reloc);
10385 /* Function labels are placed in the constant pool. This can
10386 cause a section conflict if decls are put in ".data.rel.ro"
10387 or ".data.rel.ro.local" using the __attribute__ construct. */
10388 if (strcmp (name, ".data.rel.ro") == 0
10389 || strcmp (name, ".data.rel.ro.local") == 0)
10390 flags |= SECTION_WRITE | SECTION_RELRO;
10392 return flags;
10395 /* pa_legitimate_address_p recognizes an RTL expression that is a
10396 valid memory address for an instruction. The MODE argument is the
10397 machine mode for the MEM expression that wants to use this address.
10399 On HP PA-RISC, the legitimate address forms are REG+SMALLINT,
10400 REG+REG, and REG+(REG*SCALE). The indexed address forms are only
10401 available with floating point loads and stores, and integer loads.
10402 We get better code by allowing indexed addresses in the initial
10403 RTL generation.
10405 The acceptance of indexed addresses as legitimate implies that we
10406 must provide patterns for doing indexed integer stores, or the move
10407 expanders must force the address of an indexed store to a register.
10408 We have adopted the latter approach.
10410 Another function of pa_legitimate_address_p is to ensure that
10411 the base register is a valid pointer for indexed instructions.
10412 On targets that have non-equivalent space registers, we have to
10413 know at the time of assembler output which register in a REG+REG
10414 pair is the base register. The REG_POINTER flag is sometimes lost
10415 in reload and the following passes, so it can't be relied on during
10416 code generation. Thus, we either have to canonicalize the order
10417 of the registers in REG+REG indexed addresses, or treat REG+REG
10418 addresses separately and provide patterns for both permutations.
10420 The latter approach requires several hundred additional lines of
10421 code in pa.md. The downside to canonicalizing is that a PLUS
10422 in the wrong order can't combine to form to make a scaled indexed
10423 memory operand. As we won't need to canonicalize the operands if
10424 the REG_POINTER lossage can be fixed, it seems better canonicalize.
10426 We initially break out scaled indexed addresses in canonical order
10427 in pa_emit_move_sequence. LEGITIMIZE_ADDRESS also canonicalizes
10428 scaled indexed addresses during RTL generation. However, fold_rtx
10429 has its own opinion on how the operands of a PLUS should be ordered.
10430 If one of the operands is equivalent to a constant, it will make
10431 that operand the second operand. As the base register is likely to
10432 be equivalent to a SYMBOL_REF, we have made it the second operand.
10434 pa_legitimate_address_p accepts REG+REG as legitimate when the
10435 operands are in the order INDEX+BASE on targets with non-equivalent
10436 space registers, and in any order on targets with equivalent space
10437 registers. It accepts both MULT+BASE and BASE+MULT for scaled indexing.
10439 We treat a SYMBOL_REF as legitimate if it is part of the current
10440 function's constant-pool, because such addresses can actually be
10441 output as REG+SMALLINT. */
10443 static bool
10444 pa_legitimate_address_p (machine_mode mode, rtx x, bool strict)
10446 if ((REG_P (x)
10447 && (strict ? STRICT_REG_OK_FOR_BASE_P (x)
10448 : REG_OK_FOR_BASE_P (x)))
10449 || ((GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_DEC
10450 || GET_CODE (x) == PRE_INC || GET_CODE (x) == POST_INC)
10451 && REG_P (XEXP (x, 0))
10452 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 0))
10453 : REG_OK_FOR_BASE_P (XEXP (x, 0)))))
10454 return true;
10456 if (GET_CODE (x) == PLUS)
10458 rtx base, index;
10460 /* For REG+REG, the base register should be in XEXP (x, 1),
10461 so check it first. */
10462 if (REG_P (XEXP (x, 1))
10463 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 1))
10464 : REG_OK_FOR_BASE_P (XEXP (x, 1))))
10465 base = XEXP (x, 1), index = XEXP (x, 0);
10466 else if (REG_P (XEXP (x, 0))
10467 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 0))
10468 : REG_OK_FOR_BASE_P (XEXP (x, 0))))
10469 base = XEXP (x, 0), index = XEXP (x, 1);
10470 else
10471 return false;
10473 if (GET_CODE (index) == CONST_INT)
10475 if (INT_5_BITS (index))
10476 return true;
10478 /* When INT14_OK_STRICT is false, a secondary reload is needed
10479 to adjust the displacement of SImode and DImode floating point
10480 instructions but this may fail when the register also needs
10481 reloading. So, we return false when STRICT is true. We
10482 also reject long displacements for float mode addresses since
10483 the majority of accesses will use floating point instructions
10484 that don't support 14-bit offsets. */
10485 if (!INT14_OK_STRICT
10486 && (strict || !(reload_in_progress || reload_completed))
10487 && mode != QImode
10488 && mode != HImode)
10489 return false;
10491 return base14_operand (index, mode);
10494 if (!TARGET_DISABLE_INDEXING
10495 /* Only accept the "canonical" INDEX+BASE operand order
10496 on targets with non-equivalent space registers. */
10497 && (TARGET_NO_SPACE_REGS
10498 ? REG_P (index)
10499 : (base == XEXP (x, 1) && REG_P (index)
10500 && (reload_completed
10501 || (reload_in_progress && HARD_REGISTER_P (base))
10502 || REG_POINTER (base))
10503 && (reload_completed
10504 || (reload_in_progress && HARD_REGISTER_P (index))
10505 || !REG_POINTER (index))))
10506 && MODE_OK_FOR_UNSCALED_INDEXING_P (mode)
10507 && (strict ? STRICT_REG_OK_FOR_INDEX_P (index)
10508 : REG_OK_FOR_INDEX_P (index))
10509 && borx_reg_operand (base, Pmode)
10510 && borx_reg_operand (index, Pmode))
10511 return true;
10513 if (!TARGET_DISABLE_INDEXING
10514 && GET_CODE (index) == MULT
10515 && MODE_OK_FOR_SCALED_INDEXING_P (mode)
10516 && REG_P (XEXP (index, 0))
10517 && GET_MODE (XEXP (index, 0)) == Pmode
10518 && (strict ? STRICT_REG_OK_FOR_INDEX_P (XEXP (index, 0))
10519 : REG_OK_FOR_INDEX_P (XEXP (index, 0)))
10520 && GET_CODE (XEXP (index, 1)) == CONST_INT
10521 && INTVAL (XEXP (index, 1))
10522 == (HOST_WIDE_INT) GET_MODE_SIZE (mode)
10523 && borx_reg_operand (base, Pmode))
10524 return true;
10526 return false;
10529 if (GET_CODE (x) == LO_SUM)
10531 rtx y = XEXP (x, 0);
10533 if (GET_CODE (y) == SUBREG)
10534 y = SUBREG_REG (y);
10536 if (REG_P (y)
10537 && (strict ? STRICT_REG_OK_FOR_BASE_P (y)
10538 : REG_OK_FOR_BASE_P (y)))
10540 /* Needed for -fPIC */
10541 if (mode == Pmode
10542 && GET_CODE (XEXP (x, 1)) == UNSPEC)
10543 return true;
10545 if (!INT14_OK_STRICT
10546 && (strict || !(reload_in_progress || reload_completed))
10547 && mode != QImode
10548 && mode != HImode)
10549 return false;
10551 if (CONSTANT_P (XEXP (x, 1)))
10552 return true;
10554 return false;
10557 if (GET_CODE (x) == CONST_INT && INT_5_BITS (x))
10558 return true;
10560 return false;
10563 /* Look for machine dependent ways to make the invalid address AD a
10564 valid address.
10566 For the PA, transform:
10568 memory(X + <large int>)
10570 into:
10572 if (<large int> & mask) >= 16
10573 Y = (<large int> & ~mask) + mask + 1 Round up.
10574 else
10575 Y = (<large int> & ~mask) Round down.
10576 Z = X + Y
10577 memory (Z + (<large int> - Y));
10579 This makes reload inheritance and reload_cse work better since Z
10580 can be reused.
10582 There may be more opportunities to improve code with this hook. */
10585 pa_legitimize_reload_address (rtx ad, machine_mode mode,
10586 int opnum, int type,
10587 int ind_levels ATTRIBUTE_UNUSED)
10589 long offset, newoffset, mask;
10590 rtx new_rtx, temp = NULL_RTX;
10592 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
10593 && !INT14_OK_STRICT ? 0x1f : 0x3fff);
10595 if (optimize && GET_CODE (ad) == PLUS)
10596 temp = simplify_binary_operation (PLUS, Pmode,
10597 XEXP (ad, 0), XEXP (ad, 1));
10599 new_rtx = temp ? temp : ad;
10601 if (optimize
10602 && GET_CODE (new_rtx) == PLUS
10603 && GET_CODE (XEXP (new_rtx, 0)) == REG
10604 && GET_CODE (XEXP (new_rtx, 1)) == CONST_INT)
10606 offset = INTVAL (XEXP ((new_rtx), 1));
10608 /* Choose rounding direction. Round up if we are >= halfway. */
10609 if ((offset & mask) >= ((mask + 1) / 2))
10610 newoffset = (offset & ~mask) + mask + 1;
10611 else
10612 newoffset = offset & ~mask;
10614 /* Ensure that long displacements are aligned. */
10615 if (mask == 0x3fff
10616 && (GET_MODE_CLASS (mode) == MODE_FLOAT
10617 || (TARGET_64BIT && (mode) == DImode)))
10618 newoffset &= ~(GET_MODE_SIZE (mode) - 1);
10620 if (newoffset != 0 && VAL_14_BITS_P (newoffset))
10622 temp = gen_rtx_PLUS (Pmode, XEXP (new_rtx, 0),
10623 GEN_INT (newoffset));
10624 ad = gen_rtx_PLUS (Pmode, temp, GEN_INT (offset - newoffset));
10625 push_reload (XEXP (ad, 0), 0, &XEXP (ad, 0), 0,
10626 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
10627 opnum, (enum reload_type) type);
10628 return ad;
10632 return NULL_RTX;
10635 /* Output address vector. */
10637 void
10638 pa_output_addr_vec (rtx lab, rtx body)
10640 int idx, vlen = XVECLEN (body, 0);
10642 targetm.asm_out.internal_label (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
10643 if (TARGET_GAS)
10644 fputs ("\t.begin_brtab\n", asm_out_file);
10645 for (idx = 0; idx < vlen; idx++)
10647 ASM_OUTPUT_ADDR_VEC_ELT
10648 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
10650 if (TARGET_GAS)
10651 fputs ("\t.end_brtab\n", asm_out_file);
10654 /* Output address difference vector. */
10656 void
10657 pa_output_addr_diff_vec (rtx lab, rtx body)
10659 rtx base = XEXP (XEXP (body, 0), 0);
10660 int idx, vlen = XVECLEN (body, 1);
10662 targetm.asm_out.internal_label (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
10663 if (TARGET_GAS)
10664 fputs ("\t.begin_brtab\n", asm_out_file);
10665 for (idx = 0; idx < vlen; idx++)
10667 ASM_OUTPUT_ADDR_DIFF_ELT
10668 (asm_out_file,
10669 body,
10670 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
10671 CODE_LABEL_NUMBER (base));
10673 if (TARGET_GAS)
10674 fputs ("\t.end_brtab\n", asm_out_file);
10677 /* This is a helper function for the other atomic operations. This function
10678 emits a loop that contains SEQ that iterates until a compare-and-swap
10679 operation at the end succeeds. MEM is the memory to be modified. SEQ is
10680 a set of instructions that takes a value from OLD_REG as an input and
10681 produces a value in NEW_REG as an output. Before SEQ, OLD_REG will be
10682 set to the current contents of MEM. After SEQ, a compare-and-swap will
10683 attempt to update MEM with NEW_REG. The function returns true when the
10684 loop was generated successfully. */
10686 static bool
10687 pa_expand_compare_and_swap_loop (rtx mem, rtx old_reg, rtx new_reg, rtx seq)
10689 machine_mode mode = GET_MODE (mem);
10690 rtx_code_label *label;
10691 rtx cmp_reg, success, oldval;
10693 /* The loop we want to generate looks like
10695 cmp_reg = mem;
10696 label:
10697 old_reg = cmp_reg;
10698 seq;
10699 (success, cmp_reg) = compare-and-swap(mem, old_reg, new_reg)
10700 if (success)
10701 goto label;
10703 Note that we only do the plain load from memory once. Subsequent
10704 iterations use the value loaded by the compare-and-swap pattern. */
10706 label = gen_label_rtx ();
10707 cmp_reg = gen_reg_rtx (mode);
10709 emit_move_insn (cmp_reg, mem);
10710 emit_label (label);
10711 emit_move_insn (old_reg, cmp_reg);
10712 if (seq)
10713 emit_insn (seq);
10715 success = NULL_RTX;
10716 oldval = cmp_reg;
10717 if (!expand_atomic_compare_and_swap (&success, &oldval, mem, old_reg,
10718 new_reg, false, MEMMODEL_SYNC_SEQ_CST,
10719 MEMMODEL_RELAXED))
10720 return false;
10722 if (oldval != cmp_reg)
10723 emit_move_insn (cmp_reg, oldval);
10725 /* Mark this jump predicted not taken. */
10726 emit_cmp_and_jump_insns (success, const0_rtx, EQ, const0_rtx,
10727 GET_MODE (success), 1, label,
10728 profile_probability::guessed_never ());
10729 return true;
10732 /* This function tries to implement an atomic exchange operation using a
10733 compare_and_swap loop. VAL is written to *MEM. The previous contents of
10734 *MEM are returned, using TARGET if possible. No memory model is required
10735 since a compare_and_swap loop is seq-cst. */
10738 pa_maybe_emit_compare_and_swap_exchange_loop (rtx target, rtx mem, rtx val)
10740 machine_mode mode = GET_MODE (mem);
10742 if (can_compare_and_swap_p (mode, true))
10744 if (!target || !register_operand (target, mode))
10745 target = gen_reg_rtx (mode);
10746 if (pa_expand_compare_and_swap_loop (mem, target, val, NULL_RTX))
10747 return target;
10750 return NULL_RTX;
10753 /* Implement TARGET_CALLEE_COPIES. The callee is responsible for copying
10754 arguments passed by hidden reference in the 32-bit HP runtime. Users
10755 can override this behavior for better compatibility with openmp at the
10756 risk of library incompatibilities. Arguments are always passed by value
10757 in the 64-bit HP runtime. */
10759 static bool
10760 pa_callee_copies (cumulative_args_t cum ATTRIBUTE_UNUSED,
10761 machine_mode mode ATTRIBUTE_UNUSED,
10762 const_tree type ATTRIBUTE_UNUSED,
10763 bool named ATTRIBUTE_UNUSED)
10765 return !TARGET_CALLER_COPIES;
10768 /* Implement TARGET_HARD_REGNO_MODE_OK. */
10770 static bool
10771 pa_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
10773 return PA_HARD_REGNO_MODE_OK (regno, mode);
10776 #include "gt-pa.h"