Debian Codegraph @

gcc/config/pa/pa.cc

raw
1 /* Subroutines for insn-output.cc for HPPA.
2 Copyright (C) 1992-2025 Free Software Foundation, Inc.
3 Contributed by Tim Moore ([email protected]), based on sparc.cc
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21 #define IN_TARGET_CODE 1
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "memmodel.h"
27 #include "backend.h"
28 #include "target.h"
29 #include "rtl.h"
30 #include "tree.h"
31 #include "gimple.h"
32 #include "df.h"
33 #include "tm_p.h"
34 #include "stringpool.h"
35 #include "attribs.h"
36 #include "optabs.h"
37 #include "regs.h"
38 #include "emit-rtl.h"
39 #include "recog.h"
40 #include "diagnostic-core.h"
41 #include "insn-attr.h"
42 #include "alias.h"
43 #include "fold-const.h"
44 #include "stor-layout.h"
45 #include "varasm.h"
46 #include "calls.h"
47 #include "output.h"
48 #include "except.h"
49 #include "explow.h"
50 #include "expr.h"
51 #include "reload.h"
52 #include "common/common-target.h"
53 #include "langhooks.h"
54 #include "cfgrtl.h"
55 #include "opts.h"
56 #include "builtins.h"
57
58 /* This file should be included last. */
59 #include "target-def.h"
60
61 /* Return nonzero if there is a bypass for the output of
62 OUT_INSN and the fp store IN_INSN. */
63 int
64 pa_fpstore_bypass_p (rtx_insn *out_insn, rtx_insn *in_insn)
65 {
66 machine_mode store_mode;
67 machine_mode other_mode;
68 rtx set;
69
70 if (recog_memoized (in_insn) < 0
71 || (get_attr_type (in_insn) != TYPE_FPSTORE
72 && get_attr_type (in_insn) != TYPE_FPSTORE_LOAD)
73 || recog_memoized (out_insn) < 0)
74 return 0;
75
76 store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
77
78 set = single_set (out_insn);
79 if (!set)
80 return 0;
81
82 other_mode = GET_MODE (SET_SRC (set));
83
84 return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
85 }
86
87
88 #ifndef DO_FRAME_NOTES
89 #ifdef INCOMING_RETURN_ADDR_RTX
90 #define DO_FRAME_NOTES 1
91 #else
92 #define DO_FRAME_NOTES 0
93 #endif
94 #endif
95
96 static void pa_option_override (void);
97 static void copy_reg_pointer (rtx, rtx);
98 static void fix_range (const char *);
99 static int hppa_register_move_cost (machine_mode mode, reg_class_t,
100 reg_class_t);
101 static int hppa_address_cost (rtx, machine_mode mode, addr_space_t, bool);
102 static bool hppa_rtx_costs (rtx, machine_mode, int, int, int *, bool);
103 static inline rtx force_mode (machine_mode, rtx);
104 static void pa_reorg (void);
105 static void pa_combine_instructions (void);
106 static int pa_can_combine_p (rtx_insn *, rtx_insn *, rtx_insn *, int, rtx,
107 rtx, rtx);
108 static bool forward_branch_p (rtx_insn *);
109 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
110 static void compute_zdepdi_operands (unsigned HOST_WIDE_INT, unsigned *);
111 static int compute_cpymem_length (rtx_insn *);
112 static int compute_clrmem_length (rtx_insn *);
113 static bool pa_assemble_integer (rtx, unsigned int, int);
114 static void remove_useless_addtr_insns (int);
115 static void store_reg (int, HOST_WIDE_INT, int);
116 static void store_reg_modify (int, int, HOST_WIDE_INT);
117 static void load_reg (int, HOST_WIDE_INT, int);
118 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
119 static rtx pa_function_value (const_tree, const_tree, bool);
120 static rtx pa_libcall_value (machine_mode, const_rtx);
121 static bool pa_function_value_regno_p (const unsigned int);
122 static void pa_output_function_prologue (FILE *) ATTRIBUTE_UNUSED;
123 static void pa_linux_output_function_prologue (FILE *) ATTRIBUTE_UNUSED;
124 static void update_total_code_bytes (unsigned int);
125 static void pa_output_function_epilogue (FILE *);
126 static int pa_adjust_cost (rtx_insn *, int, rtx_insn *, int, unsigned int);
127 static int pa_issue_rate (void);
128 static int pa_reloc_rw_mask (void);
129 static void pa_som_asm_init_sections (void) ATTRIBUTE_UNUSED;
130 static section *pa_som_tm_clone_table_section (void) ATTRIBUTE_UNUSED;
131 static section *pa_select_section (tree, int, unsigned HOST_WIDE_INT)
132 ATTRIBUTE_UNUSED;
133 static void pa_encode_section_info (tree, rtx, int);
134 static const char *pa_strip_name_encoding (const char *);
135 static bool pa_function_ok_for_sibcall (tree, tree);
136 static void pa_globalize_label (FILE *, const char *)
137 ATTRIBUTE_UNUSED;
138 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
139 HOST_WIDE_INT, tree);
140 #if !defined(USE_COLLECT2)
141 static void pa_asm_out_constructor (rtx, int);
142 static void pa_asm_out_destructor (rtx, int);
143 #endif
144 static void pa_init_builtins (void);
145 static rtx pa_expand_builtin (tree, rtx, rtx, machine_mode mode, int);
146 static tree pa_builtin_decl (unsigned, bool);
147 static rtx hppa_builtin_saveregs (void);
148 static void hppa_va_start (tree, rtx);
149 static tree hppa_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
150 static bool pa_scalar_mode_supported_p (scalar_mode);
151 static bool pa_commutative_p (const_rtx x, int outer_code);
152 static void copy_fp_args (rtx_insn *) ATTRIBUTE_UNUSED;
153 static int length_fp_args (rtx_insn *) ATTRIBUTE_UNUSED;
154 static rtx hppa_legitimize_address (rtx, rtx, machine_mode);
155 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
156 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
157 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
158 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
159 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
160 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
161 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
162 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
163 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
164 static void output_deferred_plabels (void);
165 static void output_deferred_profile_counters (void) ATTRIBUTE_UNUSED;
166 static void pa_file_end (void);
167 static void pa_init_libfuncs (void);
168 static rtx pa_struct_value_rtx (tree, int);
169 static bool pa_pass_by_reference (cumulative_args_t,
170 const function_arg_info &);
171 static int pa_arg_partial_bytes (cumulative_args_t, const function_arg_info &);
172 static void pa_function_arg_advance (cumulative_args_t,
173 const function_arg_info &);
174 static rtx pa_function_arg (cumulative_args_t, const function_arg_info &);
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 bool pa_secondary_memory_needed (machine_mode,
182 reg_class_t, reg_class_t);
183 static void pa_extra_live_on_entry (bitmap);
184 static machine_mode pa_promote_function_mode (const_tree,
185 machine_mode, int *,
186 const_tree, int);
187
188 static void pa_asm_trampoline_template (FILE *);
189 static void pa_trampoline_init (rtx, tree, rtx);
190 static rtx pa_trampoline_adjust_address (rtx);
191 static rtx pa_delegitimize_address (rtx);
192 static bool pa_print_operand_punct_valid_p (unsigned char);
193 static rtx pa_internal_arg_pointer (void);
194 static bool pa_can_eliminate (const int, const int);
195 static void pa_conditional_register_usage (void);
196 static machine_mode pa_c_mode_for_suffix (char);
197 static machine_mode pa_c_mode_for_floating_type (enum tree_index);
198 static section *pa_function_section (tree, enum node_frequency, bool, bool);
199 static bool pa_cannot_force_const_mem (machine_mode, rtx);
200 static bool pa_legitimate_constant_p (machine_mode, rtx);
201 static bool pa_legitimate_address_p (machine_mode, rtx, bool,
202 code_helper = ERROR_MARK);
203 static bool pa_callee_copies (cumulative_args_t, const function_arg_info &);
204 static unsigned int pa_hard_regno_nregs (unsigned int, machine_mode);
205 static bool pa_hard_regno_mode_ok (unsigned int, machine_mode);
206 static bool pa_modes_tieable_p (machine_mode, machine_mode);
207 static bool pa_can_change_mode_class (machine_mode, machine_mode, reg_class_t);
208 static HOST_WIDE_INT pa_starting_frame_offset (void);
209 static section* pa_elf_select_rtx_section(machine_mode, rtx, unsigned HOST_WIDE_INT) ATTRIBUTE_UNUSED;
210 static void pa_atomic_assign_expand_fenv (tree *, tree *, tree *);
211 static bool pa_use_lra_p (void);
212 static bool pa_frame_pointer_required (void);
213
214 /* The following extra sections are only used for SOM. */
215 static GTY(()) section *som_readonly_data_section;
216 static GTY(()) section *som_one_only_readonly_data_section;
217 static GTY(()) section *som_one_only_data_section;
218 static GTY(()) section *som_tm_clone_table_section;
219
220 /* Counts for the number of callee-saved general and floating point
221 registers which were saved by the current function's prologue. */
222 static int gr_saved, fr_saved;
223
224 /* Boolean indicating whether the return pointer was saved by the
225 current function's prologue. */
226 static bool rp_saved;
227
228 static rtx find_addr_reg (rtx);
229
230 /* Keep track of the number of bytes we have output in the CODE subspace
231 during this compilation so we'll know when to emit inline long-calls. */
232 unsigned long total_code_bytes;
233
234 /* The last address of the previous function plus the number of bytes in
235 associated thunks that have been output. This is used to determine if
236 a thunk can use an IA-relative branch to reach its target function. */
237 static unsigned int last_address;
238
239 /* Variables to handle plabels that we discover are necessary at assembly
240 output time. They are output after the current function. */
241 struct GTY(()) deferred_plabel
242 {
243 rtx internal_label;
244 rtx symbol;
245 };
246 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
247 deferred_plabels;
248 static size_t n_deferred_plabels = 0;
249
250 /* Initialize the GCC target structure. */
251
252 #undef TARGET_OPTION_OVERRIDE
253 #define TARGET_OPTION_OVERRIDE pa_option_override
254
255 #undef TARGET_ASM_ALIGNED_HI_OP
256 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
257 #undef TARGET_ASM_ALIGNED_SI_OP
258 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
259 #undef TARGET_ASM_ALIGNED_DI_OP
260 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
261 #undef TARGET_ASM_UNALIGNED_HI_OP
262 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
263 #undef TARGET_ASM_UNALIGNED_SI_OP
264 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
265 #undef TARGET_ASM_UNALIGNED_DI_OP
266 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
267 #undef TARGET_ASM_INTEGER
268 #define TARGET_ASM_INTEGER pa_assemble_integer
269
270 #undef TARGET_ASM_FUNCTION_EPILOGUE
271 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
272
273 #undef TARGET_FUNCTION_VALUE
274 #define TARGET_FUNCTION_VALUE pa_function_value
275 #undef TARGET_LIBCALL_VALUE
276 #define TARGET_LIBCALL_VALUE pa_libcall_value
277 #undef TARGET_FUNCTION_VALUE_REGNO_P
278 #define TARGET_FUNCTION_VALUE_REGNO_P pa_function_value_regno_p
279
280 #undef TARGET_LEGITIMIZE_ADDRESS
281 #define TARGET_LEGITIMIZE_ADDRESS hppa_legitimize_address
282
283 #undef TARGET_SCHED_ADJUST_COST
284 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
285 #undef TARGET_SCHED_ISSUE_RATE
286 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
287
288 #undef TARGET_ENCODE_SECTION_INFO
289 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
290 #undef TARGET_STRIP_NAME_ENCODING
291 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
292
293 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
294 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
295
296 #undef TARGET_COMMUTATIVE_P
297 #define TARGET_COMMUTATIVE_P pa_commutative_p
298
299 #undef TARGET_ASM_OUTPUT_MI_THUNK
300 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
301 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
302 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
303
304 #undef TARGET_ASM_FILE_END
305 #define TARGET_ASM_FILE_END pa_file_end
306
307 #undef TARGET_ASM_RELOC_RW_MASK
308 #define TARGET_ASM_RELOC_RW_MASK pa_reloc_rw_mask
309
310 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
311 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P pa_print_operand_punct_valid_p
312
313 #if !defined(USE_COLLECT2)
314 #undef TARGET_ASM_CONSTRUCTOR
315 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
316 #undef TARGET_ASM_DESTRUCTOR
317 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
318 #endif
319
320 #undef TARGET_INIT_BUILTINS
321 #define TARGET_INIT_BUILTINS pa_init_builtins
322 #undef TARGET_EXPAND_BUILTIN
323 #define TARGET_EXPAND_BUILTIN pa_expand_builtin
324 #undef TARGET_BUILTIN_DECL
325 #define TARGET_BUILTIN_DECL pa_builtin_decl
326
327 #undef TARGET_REGISTER_MOVE_COST
328 #define TARGET_REGISTER_MOVE_COST hppa_register_move_cost
329 #undef TARGET_RTX_COSTS
330 #define TARGET_RTX_COSTS hppa_rtx_costs
331 #undef TARGET_ADDRESS_COST
332 #define TARGET_ADDRESS_COST hppa_address_cost
333
334 #undef TARGET_MACHINE_DEPENDENT_REORG
335 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
336
337 #undef TARGET_INIT_LIBFUNCS
338 #define TARGET_INIT_LIBFUNCS pa_init_libfuncs
339
340 #undef TARGET_PROMOTE_FUNCTION_MODE
341 #define TARGET_PROMOTE_FUNCTION_MODE pa_promote_function_mode
342 #undef TARGET_PROMOTE_PROTOTYPES
343 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
344
345 #undef TARGET_STRUCT_VALUE_RTX
346 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
347 #undef TARGET_RETURN_IN_MEMORY
348 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
349 #undef TARGET_MUST_PASS_IN_STACK
350 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
351 #undef TARGET_PASS_BY_REFERENCE
352 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
353 #undef TARGET_CALLEE_COPIES
354 #define TARGET_CALLEE_COPIES pa_callee_copies
355 #undef TARGET_ARG_PARTIAL_BYTES
356 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
357 #undef TARGET_FUNCTION_ARG
358 #define TARGET_FUNCTION_ARG pa_function_arg
359 #undef TARGET_FUNCTION_ARG_ADVANCE
360 #define TARGET_FUNCTION_ARG_ADVANCE pa_function_arg_advance
361 #undef TARGET_FUNCTION_ARG_PADDING
362 #define TARGET_FUNCTION_ARG_PADDING pa_function_arg_padding
363 #undef TARGET_FUNCTION_ARG_BOUNDARY
364 #define TARGET_FUNCTION_ARG_BOUNDARY pa_function_arg_boundary
365
366 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
367 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
368 #undef TARGET_EXPAND_BUILTIN_VA_START
369 #define TARGET_EXPAND_BUILTIN_VA_START hppa_va_start
370 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
371 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
372
373 #undef TARGET_SCALAR_MODE_SUPPORTED_P
374 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
375
376 #undef TARGET_CANNOT_FORCE_CONST_MEM
377 #define TARGET_CANNOT_FORCE_CONST_MEM pa_cannot_force_const_mem
378
379 #undef TARGET_SECONDARY_RELOAD
380 #define TARGET_SECONDARY_RELOAD pa_secondary_reload
381 #undef TARGET_SECONDARY_MEMORY_NEEDED
382 #define TARGET_SECONDARY_MEMORY_NEEDED pa_secondary_memory_needed
383
384 #undef TARGET_EXTRA_LIVE_ON_ENTRY
385 #define TARGET_EXTRA_LIVE_ON_ENTRY pa_extra_live_on_entry
386
387 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
388 #define TARGET_ASM_TRAMPOLINE_TEMPLATE pa_asm_trampoline_template
389 #undef TARGET_TRAMPOLINE_INIT
390 #define TARGET_TRAMPOLINE_INIT pa_trampoline_init
391 #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
392 #define TARGET_TRAMPOLINE_ADJUST_ADDRESS pa_trampoline_adjust_address
393 #undef TARGET_DELEGITIMIZE_ADDRESS
394 #define TARGET_DELEGITIMIZE_ADDRESS pa_delegitimize_address
395 #undef TARGET_INTERNAL_ARG_POINTER
396 #define TARGET_INTERNAL_ARG_POINTER pa_internal_arg_pointer
397 #undef TARGET_FRAME_POINTER_REQUIRED
398 #define TARGET_FRAME_POINTER_REQUIRED pa_frame_pointer_required
399 #undef TARGET_CAN_ELIMINATE
400 #define TARGET_CAN_ELIMINATE pa_can_eliminate
401 #undef TARGET_CONDITIONAL_REGISTER_USAGE
402 #define TARGET_CONDITIONAL_REGISTER_USAGE pa_conditional_register_usage
403 #undef TARGET_C_MODE_FOR_SUFFIX
404 #define TARGET_C_MODE_FOR_SUFFIX pa_c_mode_for_suffix
405 #undef TARGET_C_MODE_FOR_FLOATING_TYPE
406 #define TARGET_C_MODE_FOR_FLOATING_TYPE pa_c_mode_for_floating_type
407 #undef TARGET_ASM_FUNCTION_SECTION
408 #define TARGET_ASM_FUNCTION_SECTION pa_function_section
409
410 #undef TARGET_LEGITIMATE_CONSTANT_P
411 #define TARGET_LEGITIMATE_CONSTANT_P pa_legitimate_constant_p
412 #undef TARGET_LEGITIMATE_ADDRESS_P
413 #define TARGET_LEGITIMATE_ADDRESS_P pa_legitimate_address_p
414
415 #undef TARGET_LRA_P
416 #define TARGET_LRA_P pa_use_lra_p
417
418 #undef TARGET_HARD_REGNO_NREGS
419 #define TARGET_HARD_REGNO_NREGS pa_hard_regno_nregs
420 #undef TARGET_HARD_REGNO_MODE_OK
421 #define TARGET_HARD_REGNO_MODE_OK pa_hard_regno_mode_ok
422 #undef TARGET_MODES_TIEABLE_P
423 #define TARGET_MODES_TIEABLE_P pa_modes_tieable_p
424
425 #undef TARGET_CAN_CHANGE_MODE_CLASS
426 #define TARGET_CAN_CHANGE_MODE_CLASS pa_can_change_mode_class
427
428 #undef TARGET_CONSTANT_ALIGNMENT
429 #define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings
430
431 #undef TARGET_STARTING_FRAME_OFFSET
432 #define TARGET_STARTING_FRAME_OFFSET pa_starting_frame_offset
433
434 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
435 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
436
437 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
438 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV pa_atomic_assign_expand_fenv
439
440 struct gcc_target targetm = TARGET_INITIALIZER;
441
442 /* Parse the -mfixed-range= option string. */
443
444 static void
445 fix_range (const char *const_str)
446 {
447 int i, first, last;
448 char *str, *dash, *comma;
449
450 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
451 REG2 are either register names or register numbers. The effect
452 of this option is to mark the registers in the range from REG1 to
453 REG2 as ``fixed'' so they won't be used by the compiler. This is
454 used, e.g., to ensure that kernel mode code doesn't use fr4-fr31. */
455
456 i = strlen (const_str);
457 str = (char *) alloca (i + 1);
458 memcpy (str, const_str, i + 1);
459
460 while (1)
461 {
462 dash = strchr (str, '-');
463 if (!dash)
464 {
465 warning (0, "value of %<-mfixed-range%> must have form REG1-REG2");
466 return;
467 }
468 *dash = '\0';
469
470 comma = strchr (dash + 1, ',');
471 if (comma)
472 *comma = '\0';
473
474 first = decode_reg_name (str);
475 if (first < 0)
476 {
477 warning (0, "unknown register name: %s", str);
478 return;
479 }
480
481 last = decode_reg_name (dash + 1);
482 if (last < 0)
483 {
484 warning (0, "unknown register name: %s", dash + 1);
485 return;
486 }
487
488 *dash = '-';
489
490 if (first > last)
491 {
492 warning (0, "%s-%s is an empty range", str, dash + 1);
493 return;
494 }
495
496 for (i = first; i <= last; ++i)
497 fixed_regs[i] = call_used_regs[i] = 1;
498
499 if (!comma)
500 break;
501
502 *comma = ',';
503 str = comma + 1;
504 }
505
506 /* Check if all floating point registers have been fixed. */
507 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
508 if (!fixed_regs[i])
509 break;
510
511 if (i > FP_REG_LAST)
512 target_flags |= MASK_SOFT_FLOAT;
513 }
514
515 /* Implement the TARGET_OPTION_OVERRIDE hook. */
516
517 static void
518 pa_option_override (void)
519 {
520 unsigned int i;
521 cl_deferred_option *opt;
522 vec<cl_deferred_option> *v
523 = (vec<cl_deferred_option> *) pa_deferred_options;
524
525 if (v)
526 FOR_EACH_VEC_ELT (*v, i, opt)
527 {
528 switch (opt->opt_index)
529 {
530 case OPT_mfixed_range_:
531 fix_range (opt->arg);
532 break;
533
534 default:
535 gcc_unreachable ();
536 }
537 }
538
539 if (flag_pic && TARGET_PORTABLE_RUNTIME)
540 {
541 warning (0, "PIC code generation is not supported in the portable runtime model");
542 }
543
544 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
545 {
546 warning (0, "PIC code generation is not compatible with fast indirect calls");
547 }
548
549 if (! TARGET_GAS && write_symbols != NO_DEBUG)
550 {
551 warning (0, "%<-g%> is only supported when using GAS on this processor");
552 warning (0, "%<-g%> option disabled");
553 write_symbols = NO_DEBUG;
554 }
555
556 if (TARGET_64BIT && TARGET_HPUX)
557 {
558 /* DWARF5 is not supported by gdb. Don't emit DWARF5 unless
559 specifically selected. */
560 if (!OPTION_SET_P (dwarf_strict))
561 dwarf_strict = 1;
562 if (!OPTION_SET_P (dwarf_version))
563 dwarf_version = 4;
564 }
565
566 /* We only support the "big PIC" model now. And we always generate PIC
567 code when in 64bit mode. */
568 if (flag_pic == 1 || TARGET_64BIT)
569 flag_pic = 2;
570
571 /* 64-bit target is always PIE. */
572 if (TARGET_64BIT)
573 flag_pie = 2;
574
575 /* Disable -freorder-blocks-and-partition as we don't support hot and
576 cold partitioning. */
577 if (flag_reorder_blocks_and_partition)
578 {
579 inform (input_location,
580 "%<-freorder-blocks-and-partition%> does not work "
581 "on this architecture");
582 flag_reorder_blocks_and_partition = 0;
583 flag_reorder_blocks = 1;
584 }
585
586 /* Disable -fstack-protector to suppress warning. */
587 flag_stack_protect = 0;
588
589 /* We can't guarantee that .dword is available for 32-bit targets. */
590 if (UNITS_PER_WORD == 4)
591 targetm.asm_out.aligned_op.di = NULL;
592
593 /* The unaligned ops are only available when using GAS. */
594 if (!TARGET_GAS)
595 {
596 targetm.asm_out.unaligned_op.hi = NULL;
597 targetm.asm_out.unaligned_op.si = NULL;
598 targetm.asm_out.unaligned_op.di = NULL;
599 }
600
601 init_machine_status = pa_init_machine_status;
602 }
603
604 enum pa_builtins
605 {
606 /* FPU builtins. */
607 PA_BUILTIN_GET_FPSR,
608 PA_BUILTIN_SET_FPSR,
609
610 PA_BUILTIN_COPYSIGNQ,
611 PA_BUILTIN_FABSQ,
612 PA_BUILTIN_INFQ,
613 PA_BUILTIN_HUGE_VALQ,
614 PA_BUILTIN_max
615 };
616
617 static GTY(()) tree pa_builtins[(int) PA_BUILTIN_max];
618 static GTY(()) enum insn_code pa_builtins_icode[(int) PA_BUILTIN_max];
619
620 /* Add a PA builtin function with NAME, ICODE, CODE and TYPE. Return the
621 function decl or NULL_TREE if the builtin was not added. */
622
623 static tree
624 def_builtin (const char *name, enum insn_code icode, enum pa_builtins code,
625 tree type)
626 {
627 tree t
628 = add_builtin_function (name, type, code, BUILT_IN_MD, NULL, NULL_TREE);
629
630 if (t)
631 {
632 pa_builtins[code] = t;
633 pa_builtins_icode[code] = icode;
634 }
635
636 return t;
637 }
638
639 /* Create builtin functions for FPU instructions. */
640
641 static void
642 pa_fpu_init_builtins (void)
643 {
644 tree ftype;
645
646 ftype = build_function_type_list (unsigned_type_node, 0);
647 def_builtin ("__builtin_get_fpsr", CODE_FOR_get_fpsr,
648 PA_BUILTIN_GET_FPSR, ftype);
649 ftype = build_function_type_list (void_type_node, unsigned_type_node, 0);
650 def_builtin ("__builtin_set_fpsr", CODE_FOR_set_fpsr,
651 PA_BUILTIN_SET_FPSR, ftype);
652 }
653
654 static void
655 pa_init_builtins (void)
656 {
657 if (!TARGET_SOFT_FLOAT)
658 pa_fpu_init_builtins ();
659
660 #ifdef DONT_HAVE_FPUTC_UNLOCKED
661 {
662 tree decl = builtin_decl_explicit (BUILT_IN_PUTC_UNLOCKED);
663 set_builtin_decl (BUILT_IN_FPUTC_UNLOCKED, decl,
664 builtin_decl_implicit_p (BUILT_IN_PUTC_UNLOCKED));
665 }
666 #endif
667 #if TARGET_HPUX_11
668 {
669 tree decl;
670
671 if ((decl = builtin_decl_explicit (BUILT_IN_FINITE)) != NULL_TREE)
672 set_user_assembler_name (decl, "_Isfinite");
673 if ((decl = builtin_decl_explicit (BUILT_IN_FINITEF)) != NULL_TREE)
674 set_user_assembler_name (decl, "_Isfinitef");
675 }
676 #endif
677
678 if (HPUX_LONG_DOUBLE_LIBRARY)
679 {
680 tree decl, ftype;
681
682 /* Under HPUX, the __float128 type is a synonym for "long double". */
683 (*lang_hooks.types.register_builtin_type) (long_double_type_node,
684 "__float128");
685
686 /* TFmode support builtins. */
687 ftype = build_function_type_list (long_double_type_node,
688 long_double_type_node,
689 NULL_TREE);
690 decl = add_builtin_function ("__builtin_fabsq", ftype,
691 PA_BUILTIN_FABSQ, BUILT_IN_MD,
692 "_U_Qfabs", NULL_TREE);
693 TREE_READONLY (decl) = 1;
694 pa_builtins[PA_BUILTIN_FABSQ] = decl;
695
696 ftype = build_function_type_list (long_double_type_node,
697 long_double_type_node,
698 long_double_type_node,
699 NULL_TREE);
700 decl = add_builtin_function ("__builtin_copysignq", ftype,
701 PA_BUILTIN_COPYSIGNQ, BUILT_IN_MD,
702 "_U_Qfcopysign", NULL_TREE);
703 TREE_READONLY (decl) = 1;
704 pa_builtins[PA_BUILTIN_COPYSIGNQ] = decl;
705
706 ftype = build_function_type_list (long_double_type_node, NULL_TREE);
707 decl = add_builtin_function ("__builtin_infq", ftype,
708 PA_BUILTIN_INFQ, BUILT_IN_MD,
709 NULL, NULL_TREE);
710 pa_builtins[PA_BUILTIN_INFQ] = decl;
711
712 decl = add_builtin_function ("__builtin_huge_valq", ftype,
713 PA_BUILTIN_HUGE_VALQ, BUILT_IN_MD,
714 NULL, NULL_TREE);
715 pa_builtins[PA_BUILTIN_HUGE_VALQ] = decl;
716 }
717 }
718
719 /* Implement TARGET_BUILTIN_DECL. */
720
721 static tree
722 pa_builtin_decl (unsigned int code, bool initialize_p ATTRIBUTE_UNUSED)
723 {
724 if (code >= PA_BUILTIN_max)
725 return error_mark_node;
726 return pa_builtins[code];
727 }
728
729 static rtx
730 pa_expand_builtin_1 (tree exp, rtx target,
731 rtx subtarget ATTRIBUTE_UNUSED,
732 machine_mode tmode ATTRIBUTE_UNUSED,
733 int ignore ATTRIBUTE_UNUSED)
734 {
735 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
736 enum pa_builtins code
737 = (enum pa_builtins) DECL_MD_FUNCTION_CODE (fndecl);
738 enum insn_code icode = pa_builtins_icode[code];
739 bool nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node;
740 call_expr_arg_iterator iter;
741 int arg_count = 0;
742 rtx pat, op[4];
743 tree arg;
744
745 if (nonvoid)
746 {
747 machine_mode tmode = insn_data[icode].operand[0].mode;
748 if (!target
749 || GET_MODE (target) != tmode
750 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
751 op[0] = gen_reg_rtx (tmode);
752 else
753 op[0] = target;
754 }
755 else
756 op[0] = NULL_RTX;
757
758 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
759 {
760 const struct insn_operand_data *insn_op;
761 int idx;
762
763 if (arg == error_mark_node)
764 return NULL_RTX;
765
766 arg_count++;
767 idx = arg_count - !nonvoid;
768 insn_op = &insn_data[icode].operand[idx];
769 op[arg_count] = expand_normal (arg);
770
771 if (! (*insn_data[icode].operand[idx].predicate) (op[arg_count],
772 insn_op->mode))
773 op[arg_count] = copy_to_mode_reg (insn_op->mode, op[arg_count]);
774 }
775
776 switch (arg_count)
777 {
778 case 0:
779 pat = GEN_FCN (icode) (op[0]);
780 break;
781 case 1:
782 if (nonvoid)
783 pat = GEN_FCN (icode) (op[0], op[1]);
784 else
785 pat = GEN_FCN (icode) (op[1]);
786 break;
787 case 2:
788 pat = GEN_FCN (icode) (op[0], op[1], op[2]);
789 break;
790 case 3:
791 pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]);
792 break;
793 default:
794 gcc_unreachable ();
795 }
796
797 if (!pat)
798 return NULL_RTX;
799
800 emit_insn (pat);
801
802 return (nonvoid ? op[0] : const0_rtx);
803 }
804
805 static rtx
806 pa_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
807 machine_mode mode ATTRIBUTE_UNUSED,
808 int ignore ATTRIBUTE_UNUSED)
809 {
810 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
811 unsigned int fcode = DECL_MD_FUNCTION_CODE (fndecl);
812
813 switch (fcode)
814 {
815 case PA_BUILTIN_GET_FPSR:
816 case PA_BUILTIN_SET_FPSR:
817 return pa_expand_builtin_1 (exp, target, subtarget, mode, ignore);
818
819 case PA_BUILTIN_FABSQ:
820 case PA_BUILTIN_COPYSIGNQ:
821 return expand_call (exp, target, ignore);
822
823 case PA_BUILTIN_INFQ:
824 case PA_BUILTIN_HUGE_VALQ:
825 {
826 machine_mode target_mode = TYPE_MODE (TREE_TYPE (exp));
827 REAL_VALUE_TYPE inf;
828 rtx tmp;
829
830 real_inf (&inf);
831 tmp = const_double_from_real_value (inf, target_mode);
832
833 tmp = validize_mem (force_const_mem (target_mode, tmp));
834
835 if (target == 0)
836 target = gen_reg_rtx (target_mode);
837
838 emit_move_insn (target, tmp);
839 return target;
840 }
841
842 default:
843 gcc_unreachable ();
844 }
845
846 return NULL_RTX;
847 }
848
849 /* Function to init struct machine_function.
850 This will be called, via a pointer variable,
851 from push_function_context. */
852
853 static struct machine_function *
854 pa_init_machine_status (void)
855 {
856 return ggc_cleared_alloc<machine_function> ();
857 }
858
859 /* If FROM is a probable pointer register, mark TO as a probable
860 pointer register with the same pointer alignment as FROM. */
861
862 static void
863 copy_reg_pointer (rtx to, rtx from)
864 {
865 if (REG_POINTER (from))
866 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
867 }
868
869 /* Return 1 if X contains a symbolic expression. We know these
870 expressions will have one of a few well defined forms, so
871 we need only check those forms. */
872 int
873 pa_symbolic_expression_p (rtx x)
874 {
875
876 /* Strip off any HIGH. */
877 if (GET_CODE (x) == HIGH)
878 x = XEXP (x, 0);
879
880 return symbolic_operand (x, VOIDmode);
881 }
882
883 /* Accept any constant that can be moved in one instruction into a
884 general register. */
885 int
886 pa_cint_ok_for_move (unsigned HOST_WIDE_INT ival)
887 {
888 /* OK if ldo, ldil, or zdepi, can be used. */
889 return (VAL_14_BITS_P (ival)
890 || pa_ldil_cint_p (ival)
891 || pa_zdepi_cint_p (ival));
892 }
893
894 /* True iff ldil can be used to load this CONST_INT. The least
895 significant 11 bits of the value must be zero and the value must
896 not change sign when extended from 32 to 64 bits. */
897 int
898 pa_ldil_cint_p (unsigned HOST_WIDE_INT ival)
899 {
900 unsigned HOST_WIDE_INT x;
901
902 x = ival & (((unsigned HOST_WIDE_INT) -1 << 31) | 0x7ff);
903 return x == 0 || x == ((unsigned HOST_WIDE_INT) -1 << 31);
904 }
905
906 /* True iff zdepi can be used to generate this CONST_INT.
907 zdepi first sign extends a 5-bit signed number to a given field
908 length, then places this field anywhere in a zero. */
909 int
910 pa_zdepi_cint_p (unsigned HOST_WIDE_INT x)
911 {
912 unsigned HOST_WIDE_INT lsb_mask, t;
913
914 /* This might not be obvious, but it's at least fast.
915 This function is critical; we don't have the time loops would take. */
916 lsb_mask = x & -x;
917 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
918 /* Return true iff t is a power of two. */
919 return ((t & (t - 1)) == 0);
920 }
921
922 /* True iff depi or extru can be used to compute (reg & mask).
923 Accept bit pattern like these:
924 0....01....1
925 1....10....0
926 1..10..01..1 */
927 int
928 pa_and_mask_p (unsigned HOST_WIDE_INT mask)
929 {
930 mask = ~mask;
931 mask += mask & -mask;
932 return (mask & (mask - 1)) == 0;
933 }
934
935 /* True iff depi can be used to compute (reg | MASK). */
936 int
937 pa_ior_mask_p (unsigned HOST_WIDE_INT mask)
938 {
939 mask += mask & -mask;
940 return (mask & (mask - 1)) == 0;
941 }
942
943 /* Legitimize PIC addresses. If the address is already
944 position-independent, we return ORIG. Newly generated
945 position-independent addresses go to REG. If we need more
946 than one register, we lose. */
947
948 static rtx
949 legitimize_pic_address (rtx orig, machine_mode mode, rtx reg)
950 {
951 rtx pic_ref = orig;
952
953 gcc_assert (!PA_SYMBOL_REF_TLS_P (orig));
954
955 /* Labels need special handling. */
956 if (pic_label_operand (orig, mode))
957 {
958 rtx_insn *insn;
959
960 /* We do not want to go through the movXX expanders here since that
961 would create recursion.
962
963 Nor do we really want to call a generator for a named pattern
964 since that requires multiple patterns if we want to support
965 multiple word sizes.
966
967 So instead we just emit the raw set, which avoids the movXX
968 expanders completely. */
969 mark_reg_pointer (reg, BITS_PER_UNIT);
970 insn = emit_insn (gen_rtx_SET (reg, orig));
971
972 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
973 add_reg_note (insn, REG_EQUAL, orig);
974
975 /* During and after reload, we need to generate a REG_LABEL_OPERAND note
976 and update LABEL_NUSES because this is not done automatically. */
977 if (lra_in_progress || reload_in_progress || reload_completed)
978 {
979 /* Extract LABEL_REF. */
980 if (GET_CODE (orig) == CONST)
981 orig = XEXP (XEXP (orig, 0), 0);
982 /* Extract CODE_LABEL. */
983 orig = XEXP (orig, 0);
984 add_reg_note (insn, REG_LABEL_OPERAND, orig);
985 /* Make sure we have label and not a note. */
986 if (LABEL_P (orig))
987 LABEL_NUSES (orig)++;
988 }
989 crtl->uses_pic_offset_table = 1;
990 return reg;
991 }
992 if (GET_CODE (orig) == SYMBOL_REF)
993 {
994 rtx_insn *insn;
995 rtx tmp_reg;
996
997 gcc_assert (reg);
998
999 /* Before reload, allocate a temporary register for the intermediate
1000 result. This allows the sequence to be deleted when the final
1001 result is unused and the insns are trivially dead. */
1002 tmp_reg = ((lra_in_progress || reload_in_progress || reload_completed)
1003 ? reg : gen_reg_rtx (Pmode));
1004
1005 if (function_label_operand (orig, VOIDmode))
1006 {
1007 /* Force function label into memory in word mode. */
1008 orig = XEXP (force_const_mem (word_mode, orig), 0);
1009 /* Load plabel address from DLT. */
1010 emit_move_insn (tmp_reg,
1011 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
1012 gen_rtx_HIGH (word_mode, orig)));
1013 pic_ref
1014 = gen_const_mem (Pmode,
1015 gen_rtx_LO_SUM (Pmode, tmp_reg,
1016 gen_rtx_UNSPEC (Pmode,
1017 gen_rtvec (1, orig),
1018 UNSPEC_DLTIND14R)));
1019 emit_move_insn (reg, pic_ref);
1020 /* Now load address of function descriptor. */
1021 pic_ref = gen_rtx_MEM (Pmode, reg);
1022 }
1023 else
1024 {
1025 /* Load symbol reference from DLT. */
1026 emit_move_insn (tmp_reg,
1027 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
1028 gen_rtx_HIGH (word_mode, orig)));
1029 pic_ref
1030 = gen_const_mem (Pmode,
1031 gen_rtx_LO_SUM (Pmode, tmp_reg,
1032 gen_rtx_UNSPEC (Pmode,
1033 gen_rtvec (1, orig),
1034 UNSPEC_DLTIND14R)));
1035 }
1036
1037 crtl->uses_pic_offset_table = 1;
1038 mark_reg_pointer (reg, BITS_PER_UNIT);
1039 insn = emit_move_insn (reg, pic_ref);
1040
1041 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
1042 set_unique_reg_note (insn, REG_EQUAL, orig);
1043
1044 return reg;
1045 }
1046 else if (GET_CODE (orig) == CONST)
1047 {
1048 rtx base;
1049
1050 if (GET_CODE (XEXP (orig, 0)) == PLUS
1051 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1052 return orig;
1053
1054 gcc_assert (reg);
1055 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
1056
1057 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1058 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1059 base == reg ? 0 : reg);
1060
1061 if (GET_CODE (orig) == CONST_INT)
1062 {
1063 if (INT_14_BITS (orig))
1064 return plus_constant (Pmode, base, INTVAL (orig));
1065 orig = force_reg (Pmode, orig);
1066 }
1067 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
1068 /* Likewise, should we set special REG_NOTEs here? */
1069 }
1070
1071 return pic_ref;
1072 }
1073
1074 static GTY(()) rtx gen_tls_tga;
1075
1076 static rtx
1077 gen_tls_get_addr (void)
1078 {
1079 if (!gen_tls_tga)
1080 gen_tls_tga = init_one_libfunc ("__tls_get_addr");
1081 return gen_tls_tga;
1082 }
1083
1084 static rtx
1085 hppa_tls_call (rtx arg)
1086 {
1087 rtx ret;
1088
1089 ret = gen_reg_rtx (Pmode);
1090 emit_library_call_value (gen_tls_get_addr (), ret,
1091 LCT_CONST, Pmode, arg, Pmode);
1092
1093 return ret;
1094 }
1095
1096 static rtx
1097 legitimize_tls_address (rtx addr)
1098 {
1099 rtx ret, tmp, t1, t2, tp;
1100 rtx_insn *insn;
1101
1102 /* Currently, we can't handle anything but a SYMBOL_REF. */
1103 if (GET_CODE (addr) != SYMBOL_REF)
1104 return addr;
1105
1106 switch (SYMBOL_REF_TLS_MODEL (addr))
1107 {
1108 case TLS_MODEL_GLOBAL_DYNAMIC:
1109 tmp = gen_reg_rtx (Pmode);
1110 if (flag_pic)
1111 emit_insn (gen_tgd_load_pic (tmp, addr));
1112 else
1113 emit_insn (gen_tgd_load (tmp, addr));
1114 ret = hppa_tls_call (tmp);
1115 break;
1116
1117 case TLS_MODEL_LOCAL_DYNAMIC:
1118 ret = gen_reg_rtx (Pmode);
1119 tmp = gen_reg_rtx (Pmode);
1120 start_sequence ();
1121 if (flag_pic)
1122 emit_insn (gen_tld_load_pic (tmp, addr));
1123 else
1124 emit_insn (gen_tld_load (tmp, addr));
1125 t1 = hppa_tls_call (tmp);
1126 insn = get_insns ();
1127 end_sequence ();
1128 t2 = gen_reg_rtx (Pmode);
1129 emit_libcall_block (insn, t2, t1,
1130 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
1131 UNSPEC_TLSLDBASE));
1132 emit_insn (gen_tld_offset_load (ret, addr, t2));
1133 break;
1134
1135 case TLS_MODEL_INITIAL_EXEC:
1136 tp = gen_reg_rtx (Pmode);
1137 tmp = gen_reg_rtx (Pmode);
1138 ret = gen_reg_rtx (Pmode);
1139 emit_insn (gen_tp_load (tp));
1140 if (flag_pic)
1141 emit_insn (gen_tie_load_pic (tmp, addr));
1142 else
1143 emit_insn (gen_tie_load (tmp, addr));
1144 emit_move_insn (ret, gen_rtx_PLUS (Pmode, tp, tmp));
1145 break;
1146
1147 case TLS_MODEL_LOCAL_EXEC:
1148 tp = gen_reg_rtx (Pmode);
1149 ret = gen_reg_rtx (Pmode);
1150 emit_insn (gen_tp_load (tp));
1151 emit_insn (gen_tle_load (ret, addr, tp));
1152 break;
1153
1154 default:
1155 gcc_unreachable ();
1156 }
1157
1158 return ret;
1159 }
1160
1161 /* Helper for hppa_legitimize_address. Given X, return true if it
1162 is a left shift by 1, 2 or 3 positions or a multiply by 2, 4 or 8.
1163
1164 This respectively represent canonical shift-add rtxs or scaled
1165 memory addresses. */
1166 static bool
1167 mem_shadd_or_shadd_rtx_p (rtx x)
1168 {
1169 return ((GET_CODE (x) == ASHIFT
1170 || GET_CODE (x) == MULT)
1171 && GET_CODE (XEXP (x, 1)) == CONST_INT
1172 && ((GET_CODE (x) == ASHIFT
1173 && pa_shadd_constant_p (INTVAL (XEXP (x, 1))))
1174 || (GET_CODE (x) == MULT
1175 && pa_mem_shadd_constant_p (INTVAL (XEXP (x, 1))))));
1176 }
1177
1178 /* Try machine-dependent ways of modifying an illegitimate address
1179 to be legitimate. If we find one, return the new, valid address.
1180 This macro is used in only one place: `memory_address' in explow.cc.
1181
1182 OLDX is the address as it was before break_out_memory_refs was called.
1183 In some cases it is useful to look at this to decide what needs to be done.
1184
1185 It is always safe for this macro to do nothing. It exists to recognize
1186 opportunities to optimize the output.
1187
1188 For the PA, transform:
1189
1190 memory(X + <large int>)
1191
1192 into:
1193
1194 if (<large int> & mask) >= 16
1195 Y = (<large int> & ~mask) + mask + 1 Round up.
1196 else
1197 Y = (<large int> & ~mask) Round down.
1198 Z = X + Y
1199 memory (Z + (<large int> - Y));
1200
1201 This is for CSE to find several similar references, and only use one Z.
1202
1203 X can either be a SYMBOL_REF or REG, but because combine cannot
1204 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
1205 D will not fit in 14 bits.
1206
1207 MODE_FLOAT references allow displacements which fit in 5 bits, so use
1208 0x1f as the mask.
1209
1210 MODE_INT references allow displacements which fit in 14 bits, so use
1211 0x3fff as the mask.
1212
1213 This relies on the fact that most mode MODE_FLOAT references will use FP
1214 registers and most mode MODE_INT references will use integer registers.
1215 (In the rare case of an FP register used in an integer MODE, we depend
1216 on secondary reloads to clean things up.)
1217
1218
1219 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
1220 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
1221 addressing modes to be used).
1222
1223 Note that the addresses passed into hppa_legitimize_address always
1224 come from a MEM, so we only have to match the MULT form on incoming
1225 addresses. But to be future proof we also match the ASHIFT form.
1226
1227 However, this routine always places those shift-add sequences into
1228 registers, so we have to generate the ASHIFT form as our output.
1229
1230 Put X and Z into registers. Then put the entire expression into
1231 a register. */
1232
1233 rtx
1234 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1235 machine_mode mode)
1236 {
1237 rtx orig = x;
1238
1239 /* We need to canonicalize the order of operands in unscaled indexed
1240 addresses since the code that checks if an address is valid doesn't
1241 always try both orders. */
1242 if (!TARGET_NO_SPACE_REGS
1243 && GET_CODE (x) == PLUS
1244 && GET_MODE (x) == Pmode
1245 && REG_P (XEXP (x, 0))
1246 && REG_P (XEXP (x, 1))
1247 && REG_POINTER (XEXP (x, 0))
1248 && !REG_POINTER (XEXP (x, 1)))
1249 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
1250
1251 if (tls_referenced_p (x))
1252 return legitimize_tls_address (x);
1253 else if (flag_pic)
1254 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
1255
1256 /* Strip off CONST. */
1257 if (GET_CODE (x) == CONST)
1258 x = XEXP (x, 0);
1259
1260 /* Special case. Get the SYMBOL_REF into a register and use indexing.
1261 That should always be safe. */
1262 if (GET_CODE (x) == PLUS
1263 && GET_CODE (XEXP (x, 0)) == REG
1264 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
1265 {
1266 rtx reg = force_reg (Pmode, XEXP (x, 1));
1267 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
1268 }
1269
1270 /* Note we must reject symbols which represent function addresses
1271 since the assembler/linker can't handle arithmetic on plabels. */
1272 if (GET_CODE (x) == PLUS
1273 && GET_CODE (XEXP (x, 1)) == CONST_INT
1274 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1275 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
1276 || GET_CODE (XEXP (x, 0)) == REG))
1277 {
1278 rtx int_part, ptr_reg;
1279 int newoffset;
1280 int offset = INTVAL (XEXP (x, 1));
1281 int mask;
1282
1283 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
1284 && !INT14_OK_STRICT ? 0x1f : 0x3fff);
1285
1286 /* Choose which way to round the offset. Round up if we
1287 are >= halfway to the next boundary. */
1288 if ((offset & mask) >= ((mask + 1) / 2))
1289 newoffset = (offset & ~ mask) + mask + 1;
1290 else
1291 newoffset = (offset & ~ mask);
1292
1293 /* If the newoffset will not fit in 14 bits (ldo), then
1294 handling this would take 4 or 5 instructions (2 to load
1295 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
1296 add the new offset and the SYMBOL_REF.) Combine cannot
1297 handle 4->2 or 5->2 combinations, so do not create
1298 them. */
1299 if (! VAL_14_BITS_P (newoffset)
1300 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
1301 {
1302 rtx const_part = plus_constant (Pmode, XEXP (x, 0), newoffset);
1303 rtx tmp_reg
1304 = force_reg (Pmode,
1305 gen_rtx_HIGH (Pmode, const_part));
1306 ptr_reg
1307 = force_reg (Pmode,
1308 gen_rtx_LO_SUM (Pmode,
1309 tmp_reg, const_part));
1310 }
1311 else
1312 {
1313 if (! VAL_14_BITS_P (newoffset))
1314 int_part = force_reg (Pmode, GEN_INT (newoffset));
1315 else
1316 int_part = GEN_INT (newoffset);
1317
1318 ptr_reg = force_reg (Pmode,
1319 gen_rtx_PLUS (Pmode,
1320 force_reg (Pmode, XEXP (x, 0)),
1321 int_part));
1322 }
1323 return plus_constant (Pmode, ptr_reg, offset - newoffset);
1324 }
1325
1326 /* Handle (plus (mult (a) (mem_shadd_constant)) (b)). */
1327
1328 if (GET_CODE (x) == PLUS
1329 && mem_shadd_or_shadd_rtx_p (XEXP (x, 0))
1330 && (OBJECT_P (XEXP (x, 1))
1331 || GET_CODE (XEXP (x, 1)) == SUBREG)
1332 && GET_CODE (XEXP (x, 1)) != CONST)
1333 {
1334 /* If we were given a MULT, we must fix the constant
1335 as we're going to create the ASHIFT form. */
1336 int shift_val = INTVAL (XEXP (XEXP (x, 0), 1));
1337 if (GET_CODE (XEXP (x, 0)) == MULT)
1338 shift_val = exact_log2 (shift_val);
1339
1340 rtx reg1, reg2;
1341 reg1 = XEXP (x, 1);
1342 if (GET_CODE (reg1) != REG)
1343 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1344
1345 reg2 = XEXP (XEXP (x, 0), 0);
1346 if (GET_CODE (reg2) != REG)
1347 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1348
1349 return force_reg (Pmode,
1350 gen_rtx_PLUS (Pmode,
1351 gen_rtx_ASHIFT (Pmode, reg2,
1352 GEN_INT (shift_val)),
1353 reg1));
1354 }
1355
1356 /* Similarly for (plus (plus (mult (a) (mem_shadd_constant)) (b)) (c)).
1357
1358 Only do so for floating point modes since this is more speculative
1359 and we lose if it's an integer store. */
1360 if (GET_CODE (x) == PLUS
1361 && GET_CODE (XEXP (x, 0)) == PLUS
1362 && mem_shadd_or_shadd_rtx_p (XEXP (XEXP (x, 0), 0))
1363 && (mode == SFmode || mode == DFmode))
1364 {
1365 int shift_val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
1366
1367 /* If we were given a MULT, we must fix the constant
1368 as we're going to create the ASHIFT form. */
1369 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
1370 shift_val = exact_log2 (shift_val);
1371
1372 /* Try and figure out what to use as a base register. */
1373 rtx reg1, reg2, base, idx;
1374
1375 reg1 = XEXP (XEXP (x, 0), 1);
1376 reg2 = XEXP (x, 1);
1377 base = NULL_RTX;
1378 idx = NULL_RTX;
1379
1380 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
1381 then pa_emit_move_sequence will turn on REG_POINTER so we'll know
1382 it's a base register below. */
1383 if (GET_CODE (reg1) != REG)
1384 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1385
1386 if (GET_CODE (reg2) != REG)
1387 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1388
1389 /* Figure out what the base and index are. */
1390
1391 if (GET_CODE (reg1) == REG
1392 && REG_POINTER (reg1))
1393 {
1394 base = reg1;
1395 idx = gen_rtx_PLUS (Pmode,
1396 gen_rtx_ASHIFT (Pmode,
1397 XEXP (XEXP (XEXP (x, 0), 0), 0),
1398 GEN_INT (shift_val)),
1399 XEXP (x, 1));
1400 }
1401 else if (GET_CODE (reg2) == REG
1402 && REG_POINTER (reg2))
1403 {
1404 base = reg2;
1405 idx = XEXP (x, 0);
1406 }
1407
1408 if (base == 0)
1409 return orig;
1410
1411 /* If the index adds a large constant, try to scale the
1412 constant so that it can be loaded with only one insn. */
1413 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1414 && INTVAL (XEXP (idx, 1)) % (1 << shift_val) == 0
1415 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1416 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1417 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1418 {
1419 /* Divide the CONST_INT by the scale factor, then add it to A. */
1420 int val = INTVAL (XEXP (idx, 1));
1421 val /= (1 << shift_val);
1422
1423 reg1 = XEXP (XEXP (idx, 0), 0);
1424 if (GET_CODE (reg1) != REG)
1425 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1426
1427 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1428
1429 /* We can now generate a simple scaled indexed address. */
1430 return
1431 force_reg
1432 (Pmode, gen_rtx_PLUS (Pmode,
1433 gen_rtx_ASHIFT (Pmode, reg1,
1434 GEN_INT (shift_val)),
1435 base));
1436 }
1437
1438 /* If B + C is still a valid base register, then add them. */
1439 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1440 && INTVAL (XEXP (idx, 1)) <= 4096
1441 && INTVAL (XEXP (idx, 1)) >= -4096)
1442 {
1443 rtx reg1, reg2;
1444
1445 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1446
1447 reg2 = XEXP (XEXP (idx, 0), 0);
1448 if (GET_CODE (reg2) != CONST_INT)
1449 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1450
1451 return force_reg (Pmode,
1452 gen_rtx_PLUS (Pmode,
1453 gen_rtx_ASHIFT (Pmode, reg2,
1454 GEN_INT (shift_val)),
1455 reg1));
1456 }
1457
1458 /* Get the index into a register, then add the base + index and
1459 return a register holding the result. */
1460
1461 /* First get A into a register. */
1462 reg1 = XEXP (XEXP (idx, 0), 0);
1463 if (GET_CODE (reg1) != REG)
1464 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1465
1466 /* And get B into a register. */
1467 reg2 = XEXP (idx, 1);
1468 if (GET_CODE (reg2) != REG)
1469 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1470
1471 reg1 = force_reg (Pmode,
1472 gen_rtx_PLUS (Pmode,
1473 gen_rtx_ASHIFT (Pmode, reg1,
1474 GEN_INT (shift_val)),
1475 reg2));
1476
1477 /* Add the result to our base register and return. */
1478 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1479
1480 }
1481
1482 /* Uh-oh. We might have an address for x[n-100000]. This needs
1483 special handling to avoid creating an indexed memory address
1484 with x-100000 as the base.
1485
1486 If the constant part is small enough, then it's still safe because
1487 there is a guard page at the beginning and end of the data segment.
1488
1489 Scaled references are common enough that we want to try and rearrange the
1490 terms so that we can use indexing for these addresses too. Only
1491 do the optimization for floatint point modes. */
1492
1493 if (GET_CODE (x) == PLUS
1494 && pa_symbolic_expression_p (XEXP (x, 1)))
1495 {
1496 /* Ugly. We modify things here so that the address offset specified
1497 by the index expression is computed first, then added to x to form
1498 the entire address. */
1499
1500 rtx regx1, regx2, regy1, regy2, y;
1501
1502 /* Strip off any CONST. */
1503 y = XEXP (x, 1);
1504 if (GET_CODE (y) == CONST)
1505 y = XEXP (y, 0);
1506
1507 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1508 {
1509 /* See if this looks like
1510 (plus (mult (reg) (mem_shadd_const))
1511 (const (plus (symbol_ref) (const_int))))
1512
1513 Where const_int is small. In that case the const
1514 expression is a valid pointer for indexing.
1515
1516 If const_int is big, but can be divided evenly by shadd_const
1517 and added to (reg). This allows more scaled indexed addresses. */
1518 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1519 && mem_shadd_or_shadd_rtx_p (XEXP (x, 0))
1520 && GET_CODE (XEXP (y, 1)) == CONST_INT
1521 && INTVAL (XEXP (y, 1)) >= -4096
1522 && INTVAL (XEXP (y, 1)) <= 4095)
1523 {
1524 int shift_val = INTVAL (XEXP (XEXP (x, 0), 1));
1525
1526 /* If we were given a MULT, we must fix the constant
1527 as we're going to create the ASHIFT form. */
1528 if (GET_CODE (XEXP (x, 0)) == MULT)
1529 shift_val = exact_log2 (shift_val);
1530
1531 rtx reg1, reg2;
1532
1533 reg1 = XEXP (x, 1);
1534 if (GET_CODE (reg1) != REG)
1535 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1536
1537 reg2 = XEXP (XEXP (x, 0), 0);
1538 if (GET_CODE (reg2) != REG)
1539 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1540
1541 return
1542 force_reg (Pmode,
1543 gen_rtx_PLUS (Pmode,
1544 gen_rtx_ASHIFT (Pmode,
1545 reg2,
1546 GEN_INT (shift_val)),
1547 reg1));
1548 }
1549 else if ((mode == DFmode || mode == SFmode)
1550 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1551 && mem_shadd_or_shadd_rtx_p (XEXP (x, 0))
1552 && GET_CODE (XEXP (y, 1)) == CONST_INT
1553 && INTVAL (XEXP (y, 1)) % (1 << INTVAL (XEXP (XEXP (x, 0), 1))) == 0)
1554 {
1555 int shift_val = INTVAL (XEXP (XEXP (x, 0), 1));
1556
1557 /* If we were given a MULT, we must fix the constant
1558 as we're going to create the ASHIFT form. */
1559 if (GET_CODE (XEXP (x, 0)) == MULT)
1560 shift_val = exact_log2 (shift_val);
1561
1562 regx1
1563 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1564 / INTVAL (XEXP (XEXP (x, 0), 1))));
1565 regx2 = XEXP (XEXP (x, 0), 0);
1566 if (GET_CODE (regx2) != REG)
1567 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1568 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1569 regx2, regx1));
1570 return
1571 force_reg (Pmode,
1572 gen_rtx_PLUS (Pmode,
1573 gen_rtx_ASHIFT (Pmode, regx2,
1574 GEN_INT (shift_val)),
1575 force_reg (Pmode, XEXP (y, 0))));
1576 }
1577 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1578 && INTVAL (XEXP (y, 1)) >= -4096
1579 && INTVAL (XEXP (y, 1)) <= 4095)
1580 {
1581 /* This is safe because of the guard page at the
1582 beginning and end of the data space. Just
1583 return the original address. */
1584 return orig;
1585 }
1586 else
1587 {
1588 /* Doesn't look like one we can optimize. */
1589 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1590 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1591 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1592 regx1 = force_reg (Pmode,
1593 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1594 regx1, regy2));
1595 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1596 }
1597 }
1598 }
1599
1600 return orig;
1601 }
1602
1603 /* Implement the TARGET_REGISTER_MOVE_COST hook.
1604
1605 Compute extra cost of moving data between one register class
1606 and another.
1607
1608 Make moves from SAR so expensive they should never happen. We used to
1609 have 0xffff here, but that generates overflow in rare cases.
1610
1611 Copies involving a FP register and a non-FP register are relatively
1612 expensive because they must go through memory.
1613
1614 Other copies are reasonably cheap. */
1615
1616 static int
1617 hppa_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
1618 reg_class_t from, reg_class_t to)
1619 {
1620 if (from == SHIFT_REGS)
1621 return 0x100;
1622 else if (to == SHIFT_REGS && FP_REG_CLASS_P (from))
1623 return 18;
1624 else if ((FP_REG_CLASS_P (from) && ! FP_REG_CLASS_P (to))
1625 || (FP_REG_CLASS_P (to) && ! FP_REG_CLASS_P (from)))
1626 return 16;
1627 else
1628 return 2;
1629 }
1630
1631 /* For the HPPA, REG and REG+CONST is cost 0
1632 and addresses involving symbolic constants are cost 2.
1633
1634 PIC addresses are very expensive.
1635
1636 It is no coincidence that this has the same structure
1637 as pa_legitimate_address_p. */
1638
1639 static int
1640 hppa_address_cost (rtx X, machine_mode mode ATTRIBUTE_UNUSED,
1641 addr_space_t as ATTRIBUTE_UNUSED,
1642 bool speed ATTRIBUTE_UNUSED)
1643 {
1644 switch (GET_CODE (X))
1645 {
1646 case REG:
1647 case PLUS:
1648 case LO_SUM:
1649 return 1;
1650 case HIGH:
1651 return 2;
1652 default:
1653 return 4;
1654 }
1655 }
1656
1657 /* Return true if X represents a (possibly non-canonical) shNadd pattern.
1658 The machine mode of X is known to be SImode or DImode. */
1659
1660 static bool
1661 hppa_rtx_costs_shadd_p (rtx x)
1662 {
1663 if (GET_CODE (x) != PLUS
1664 || !REG_P (XEXP (x, 1)))
1665 return false;
1666 rtx op0 = XEXP (x, 0);
1667 if (GET_CODE (op0) == ASHIFT
1668 && CONST_INT_P (XEXP (op0, 1))
1669 && REG_P (XEXP (op0, 0)))
1670 {
1671 unsigned HOST_WIDE_INT x = UINTVAL (XEXP (op0, 1));
1672 return x == 1 || x == 2 || x == 3;
1673 }
1674 if (GET_CODE (op0) == MULT
1675 && CONST_INT_P (XEXP (op0, 1))
1676 && REG_P (XEXP (op0, 0)))
1677 {
1678 unsigned HOST_WIDE_INT x = UINTVAL (XEXP (op0, 1));
1679 return x == 2 || x == 4 || x == 8;
1680 }
1681 return false;
1682 }
1683
1684 /* Compute a (partial) cost for rtx X. Return true if the complete
1685 cost has been computed, and false if subexpressions should be
1686 scanned. In either case, *TOTAL contains the cost result. */
1687
1688 static bool
1689 hppa_rtx_costs (rtx x, machine_mode mode, int outer_code,
1690 int opno ATTRIBUTE_UNUSED,
1691 int *total, bool speed)
1692 {
1693 int code = GET_CODE (x);
1694
1695 switch (code)
1696 {
1697 case CONST_INT:
1698 if (outer_code == SET)
1699 *total = COSTS_N_INSNS (1);
1700 else if (INTVAL (x) == 0)
1701 *total = 0;
1702 else if (INT_14_BITS (x))
1703 *total = 1;
1704 else
1705 *total = 2;
1706 return true;
1707
1708 case HIGH:
1709 *total = 2;
1710 return true;
1711
1712 case CONST:
1713 case LABEL_REF:
1714 case SYMBOL_REF:
1715 *total = 4;
1716 return true;
1717
1718 case CONST_DOUBLE:
1719 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1720 && outer_code != SET)
1721 *total = 0;
1722 else
1723 *total = 8;
1724 return true;
1725
1726 case MULT:
1727 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1728 {
1729 *total = COSTS_N_INSNS (3);
1730 }
1731 else if (mode == DImode)
1732 {
1733 if (TARGET_PA_11 && !TARGET_SOFT_FLOAT && !TARGET_SOFT_MULT)
1734 *total = COSTS_N_INSNS (25);
1735 else
1736 *total = COSTS_N_INSNS (80);
1737 }
1738 else
1739 {
1740 if (TARGET_PA_11 && !TARGET_SOFT_FLOAT && !TARGET_SOFT_MULT)
1741 *total = COSTS_N_INSNS (8);
1742 else
1743 *total = COSTS_N_INSNS (20);
1744 }
1745 return REG_P (XEXP (x, 0)) && REG_P (XEXP (x, 1));
1746
1747 case DIV:
1748 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1749 {
1750 *total = COSTS_N_INSNS (14);
1751 return false;
1752 }
1753 /* FALLTHRU */
1754
1755 case UDIV:
1756 case MOD:
1757 case UMOD:
1758 /* A mode size N times larger than SImode needs O(N*N) more insns. */
1759 if (mode == DImode)
1760 *total = COSTS_N_INSNS (240);
1761 else
1762 *total = COSTS_N_INSNS (60);
1763 return REG_P (XEXP (x, 0)) && REG_P (XEXP (x, 1));
1764
1765 case PLUS: /* this includes shNadd insns */
1766 case MINUS:
1767 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1768 *total = COSTS_N_INSNS (3);
1769 else if (mode == DImode)
1770 {
1771 if (TARGET_64BIT)
1772 {
1773 *total = COSTS_N_INSNS (1);
1774 /* Handle shladd,l instructions. */
1775 if (hppa_rtx_costs_shadd_p (x))
1776 return true;
1777 }
1778 else
1779 *total = COSTS_N_INSNS (2);
1780 }
1781 else
1782 {
1783 *total = COSTS_N_INSNS (1);
1784 /* Handle shNadd instructions. */
1785 if (hppa_rtx_costs_shadd_p (x))
1786 return true;
1787 }
1788 return REG_P (XEXP (x, 0))
1789 && (REG_P (XEXP (x, 1))
1790 || CONST_INT_P (XEXP (x, 1)));
1791
1792 case ASHIFT:
1793 if (mode == DImode)
1794 {
1795 if (REG_P (XEXP (x, 0)) && CONST_INT_P (XEXP (x, 1)))
1796 {
1797 if (TARGET_64BIT)
1798 *total = COSTS_N_INSNS (1);
1799 else
1800 *total = COSTS_N_INSNS (2);
1801 return true;
1802 }
1803 else if (TARGET_64BIT)
1804 *total = COSTS_N_INSNS (3);
1805 else if (speed)
1806 *total = COSTS_N_INSNS (13);
1807 else
1808 *total = COSTS_N_INSNS (18);
1809 }
1810 else if (REG_P (XEXP (x, 0)) && CONST_INT_P (XEXP (x, 1)))
1811 {
1812 if (TARGET_64BIT)
1813 *total = COSTS_N_INSNS (2);
1814 else
1815 *total = COSTS_N_INSNS (1);
1816 return true;
1817 }
1818 else if (TARGET_64BIT)
1819 *total = COSTS_N_INSNS (4);
1820 else
1821 *total = COSTS_N_INSNS (2);
1822 return REG_P (XEXP (x, 0))
1823 && (REG_P (XEXP (x, 1))
1824 || CONST_INT_P (XEXP (x, 1)));
1825
1826 case ASHIFTRT:
1827 if (mode == DImode)
1828 {
1829 if (REG_P (XEXP (x, 0)) && CONST_INT_P (XEXP (x, 1)))
1830 {
1831 if (TARGET_64BIT)
1832 *total = COSTS_N_INSNS (1);
1833 else
1834 *total = COSTS_N_INSNS (2);
1835 return true;
1836 }
1837 else if (TARGET_64BIT)
1838 *total = COSTS_N_INSNS (3);
1839 else if (speed)
1840 *total = COSTS_N_INSNS (14);
1841 else
1842 *total = COSTS_N_INSNS (19);
1843 }
1844 else if (REG_P (XEXP (x, 0)) && CONST_INT_P (XEXP (x, 1)))
1845 {
1846 if (TARGET_64BIT)
1847 *total = COSTS_N_INSNS (2);
1848 else
1849 *total = COSTS_N_INSNS (1);
1850 return true;
1851 }
1852 else if (TARGET_64BIT)
1853 *total = COSTS_N_INSNS (4);
1854 else
1855 *total = COSTS_N_INSNS (2);
1856 return REG_P (XEXP (x, 0))
1857 && (REG_P (XEXP (x, 1))
1858 || CONST_INT_P (XEXP (x, 1)));
1859
1860 case LSHIFTRT:
1861 if (mode == DImode)
1862 {
1863 if (REG_P (XEXP (x, 0)) && CONST_INT_P (XEXP (x, 1)))
1864 {
1865 if (TARGET_64BIT)
1866 *total = COSTS_N_INSNS (1);
1867 else
1868 *total = COSTS_N_INSNS (2);
1869 return true;
1870 }
1871 else if (TARGET_64BIT)
1872 *total = COSTS_N_INSNS (2);
1873 else if (speed)
1874 *total = COSTS_N_INSNS (12);
1875 else
1876 *total = COSTS_N_INSNS (15);
1877 }
1878 else if (REG_P (XEXP (x, 0)) && CONST_INT_P (XEXP (x, 1)))
1879 {
1880 *total = COSTS_N_INSNS (1);
1881 return true;
1882 }
1883 else if (TARGET_64BIT)
1884 *total = COSTS_N_INSNS (3);
1885 else
1886 *total = COSTS_N_INSNS (2);
1887 return REG_P (XEXP (x, 0))
1888 && (REG_P (XEXP (x, 1))
1889 || CONST_INT_P (XEXP (x, 1)));
1890
1891 default:
1892 return false;
1893 }
1894 }
1895
1896 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1897 new rtx with the correct mode. */
1898 static inline rtx
1899 force_mode (machine_mode mode, rtx orig)
1900 {
1901 if (mode == GET_MODE (orig))
1902 return orig;
1903
1904 gcc_assert (REGNO (orig) < FIRST_PSEUDO_REGISTER);
1905
1906 return gen_rtx_REG (mode, REGNO (orig));
1907 }
1908
1909 /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */
1910
1911 static bool
1912 pa_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
1913 {
1914 return tls_referenced_p (x);
1915 }
1916
1917 /* Emit insns to move operands[1] into operands[0].
1918
1919 Return 1 if we have written out everything that needs to be done to
1920 do the move. Otherwise, return 0 and the caller will emit the move
1921 normally.
1922
1923 Note SCRATCH_REG may not be in the proper mode depending on how it
1924 will be used. This routine is responsible for creating a new copy
1925 of SCRATCH_REG in the proper mode. */
1926
1927 int
1928 pa_emit_move_sequence (rtx *operands, machine_mode mode, rtx scratch_reg)
1929 {
1930 rtx operand0 = operands[0];
1931 rtx operand1 = operands[1];
1932 rtx tem;
1933
1934 /* We can only handle indexed addresses in the destination operand
1935 of floating point stores. Thus, we need to break out indexed
1936 addresses from the destination operand. */
1937 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1938 {
1939 gcc_assert (can_create_pseudo_p ());
1940
1941 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1942 operand0 = replace_equiv_address (operand0, tem);
1943 }
1944
1945 /* On targets with non-equivalent space registers, break out unscaled
1946 indexed addresses from the source operand before the final CSE.
1947 We have to do this because the REG_POINTER flag is not correctly
1948 carried through various optimization passes and CSE may substitute
1949 a pseudo without the pointer set for one with the pointer set. As
1950 a result, we loose various opportunities to create insns with
1951 unscaled indexed addresses. */
1952 if (!TARGET_NO_SPACE_REGS
1953 && !cse_not_expected
1954 && GET_CODE (operand1) == MEM
1955 && GET_CODE (XEXP (operand1, 0)) == PLUS
1956 && REG_P (XEXP (XEXP (operand1, 0), 0))
1957 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1958 operand1
1959 = replace_equiv_address (operand1,
1960 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1961
1962 if (scratch_reg
1963 && reload_in_progress
1964 && GET_CODE (operand0) == REG
1965 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1966 operand0 = reg_equiv_mem (REGNO (operand0));
1967 else if (scratch_reg
1968 && reload_in_progress
1969 && GET_CODE (operand0) == SUBREG
1970 && GET_CODE (SUBREG_REG (operand0)) == REG
1971 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1972 {
1973 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1974 the code which tracks sets/uses for delete_output_reload. */
1975 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1976 reg_equiv_mem (REGNO (SUBREG_REG (operand0))),
1977 SUBREG_BYTE (operand0));
1978 operand0 = alter_subreg (&temp, true);
1979 }
1980
1981 if (scratch_reg
1982 && reload_in_progress
1983 && GET_CODE (operand1) == REG
1984 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1985 operand1 = reg_equiv_mem (REGNO (operand1));
1986 else if (scratch_reg
1987 && reload_in_progress
1988 && GET_CODE (operand1) == SUBREG
1989 && GET_CODE (SUBREG_REG (operand1)) == REG
1990 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1991 {
1992 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1993 the code which tracks sets/uses for delete_output_reload. */
1994 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1995 reg_equiv_mem (REGNO (SUBREG_REG (operand1))),
1996 SUBREG_BYTE (operand1));
1997 operand1 = alter_subreg (&temp, true);
1998 }
1999
2000 if (scratch_reg
2001 && (lra_in_progress || reload_in_progress)
2002 && GET_CODE (operand0) == MEM
2003 && ((tem = find_replacement (&XEXP (operand0, 0)))
2004 != XEXP (operand0, 0)))
2005 operand0 = replace_equiv_address (operand0, tem);
2006
2007 if (scratch_reg
2008 && (lra_in_progress || reload_in_progress)
2009 && GET_CODE (operand1) == MEM
2010 && ((tem = find_replacement (&XEXP (operand1, 0)))
2011 != XEXP (operand1, 0)))
2012 operand1 = replace_equiv_address (operand1, tem);
2013
2014 /* Handle secondary reloads for loads/stores of FP registers from
2015 REG+D addresses where D does not fit in 5 or 14 bits, including
2016 (subreg (mem (addr))) cases, and reloads for other unsupported
2017 memory operands. */
2018 if (scratch_reg
2019 && FP_REG_P (operand0)
2020 && (MEM_P (operand1)
2021 || (GET_CODE (operand1) == SUBREG
2022 && MEM_P (XEXP (operand1, 0)))))
2023 {
2024 rtx op1 = operand1;
2025
2026 if (GET_CODE (op1) == SUBREG)
2027 op1 = XEXP (op1, 0);
2028
2029 if (reg_plus_base_memory_operand (op1, GET_MODE (op1)))
2030 {
2031 if (!(INT14_OK_STRICT && INT_14_BITS (XEXP (XEXP (op1, 0), 1)))
2032 && !INT_5_BITS (XEXP (XEXP (op1, 0), 1)))
2033 {
2034 /* SCRATCH_REG will hold an address and maybe the actual data.
2035 We want it in WORD_MODE regardless of what mode it was
2036 originally given to us. */
2037 scratch_reg = force_mode (word_mode, scratch_reg);
2038
2039 /* D might not fit in 14 bits either; for such cases load D
2040 into scratch reg. */
2041 if (!INT_14_BITS (XEXP (XEXP (op1, 0), 1)))
2042 {
2043 emit_move_insn (scratch_reg, XEXP (XEXP (op1, 0), 1));
2044 emit_move_insn (scratch_reg,
2045 gen_rtx_fmt_ee (GET_CODE (XEXP (op1, 0)),
2046 Pmode,
2047 XEXP (XEXP (op1, 0), 0),
2048 scratch_reg));
2049 }
2050 else
2051 emit_move_insn (scratch_reg, XEXP (op1, 0));
2052 op1 = replace_equiv_address (op1, scratch_reg);
2053 }
2054 }
2055 else if ((!INT14_OK_STRICT && symbolic_memory_operand (op1, VOIDmode))
2056 || IS_LO_SUM_DLT_ADDR_P (XEXP (op1, 0))
2057 || IS_INDEX_ADDR_P (XEXP (op1, 0)))
2058 {
2059 /* Load memory address into SCRATCH_REG. */
2060 scratch_reg = force_mode (word_mode, scratch_reg);
2061 emit_move_insn (scratch_reg, XEXP (op1, 0));
2062 op1 = replace_equiv_address (op1, scratch_reg);
2063 }
2064 emit_insn (gen_rtx_SET (operand0, op1));
2065 return 1;
2066 }
2067 else if (scratch_reg
2068 && FP_REG_P (operand1)
2069 && (MEM_P (operand0)
2070 || (GET_CODE (operand0) == SUBREG
2071 && MEM_P (XEXP (operand0, 0)))))
2072 {
2073 rtx op0 = operand0;
2074
2075 if (GET_CODE (op0) == SUBREG)
2076 op0 = XEXP (op0, 0);
2077
2078 if (reg_plus_base_memory_operand (op0, GET_MODE (op0)))
2079 {
2080 if (!(INT14_OK_STRICT && INT_14_BITS (XEXP (XEXP (op0, 0), 1)))
2081 && !INT_5_BITS (XEXP (XEXP (op0, 0), 1)))
2082 {
2083 /* SCRATCH_REG will hold an address and maybe the actual data.
2084 We want it in WORD_MODE regardless of what mode it was
2085 originally given to us. */
2086 scratch_reg = force_mode (word_mode, scratch_reg);
2087
2088 /* D might not fit in 14 bits either; for such cases load D
2089 into scratch reg. */
2090 if (!INT_14_BITS (XEXP (XEXP (op0, 0), 1)))
2091 {
2092 emit_move_insn (scratch_reg, XEXP (XEXP (op0, 0), 1));
2093 emit_move_insn (scratch_reg,
2094 gen_rtx_fmt_ee (GET_CODE (XEXP (op0, 0)),
2095 Pmode,
2096 XEXP (XEXP (op0, 0), 0),
2097 scratch_reg));
2098 }
2099 else
2100 emit_move_insn (scratch_reg, XEXP (op0, 0));
2101 op0 = replace_equiv_address (op0, scratch_reg);
2102 }
2103 }
2104 else if ((!INT14_OK_STRICT && symbolic_memory_operand (op0, VOIDmode))
2105 || IS_LO_SUM_DLT_ADDR_P (XEXP (op0, 0))
2106 || IS_INDEX_ADDR_P (XEXP (op0, 0)))
2107 {
2108 /* Load memory address into SCRATCH_REG. */
2109 scratch_reg = force_mode (word_mode, scratch_reg);
2110 emit_move_insn (scratch_reg, XEXP (op0, 0));
2111 op0 = replace_equiv_address (op0, scratch_reg);
2112 }
2113 emit_insn (gen_rtx_SET (op0, operand1));
2114 return 1;
2115 }
2116 /* Handle secondary reloads for loads of FP registers from constant
2117 expressions by forcing the constant into memory. For the most part,
2118 this is only necessary for SImode and DImode.
2119
2120 Use scratch_reg to hold the address of the memory location. */
2121 else if (scratch_reg
2122 && CONSTANT_P (operand1)
2123 && FP_REG_P (operand0))
2124 {
2125 rtx const_mem, xoperands[2];
2126
2127 if (operand1 == CONST0_RTX (mode))
2128 {
2129 emit_insn (gen_rtx_SET (operand0, operand1));
2130 return 1;
2131 }
2132
2133 /* SCRATCH_REG will hold an address and maybe the actual data. We want
2134 it in WORD_MODE regardless of what mode it was originally given
2135 to us. */
2136 scratch_reg = force_mode (word_mode, scratch_reg);
2137
2138 /* Force the constant into memory and put the address of the
2139 memory location into scratch_reg. */
2140 const_mem = force_const_mem (mode, operand1);
2141 xoperands[0] = scratch_reg;
2142 xoperands[1] = XEXP (const_mem, 0);
2143 pa_emit_move_sequence (xoperands, Pmode, 0);
2144
2145 /* Now load the destination register. */
2146 emit_insn (gen_rtx_SET (operand0,
2147 replace_equiv_address (const_mem, scratch_reg)));
2148 return 1;
2149 }
2150 /* Handle secondary reloads for SAR. These occur when trying to load
2151 the SAR from memory or a constant. */
2152 else if (scratch_reg
2153 && GET_CODE (operand0) == REG
2154 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
2155 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
2156 && (GET_CODE (operand1) == MEM || GET_CODE (operand1) == CONST_INT))
2157 {
2158 /* D might not fit in 14 bits either; for such cases load D into
2159 scratch reg. */
2160 if (GET_CODE (operand1) == MEM
2161 && !memory_address_p (GET_MODE (operand0), XEXP (operand1, 0)))
2162 {
2163 /* We are reloading the address into the scratch register, so we
2164 want to make sure the scratch register is a full register. */
2165 scratch_reg = force_mode (word_mode, scratch_reg);
2166
2167 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
2168 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
2169 0)),
2170 Pmode,
2171 XEXP (XEXP (operand1, 0),
2172 0),
2173 scratch_reg));
2174
2175 /* Now we are going to load the scratch register from memory,
2176 we want to load it in the same width as the original MEM,
2177 which must be the same as the width of the ultimate destination,
2178 OPERAND0. */
2179 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
2180
2181 emit_move_insn (scratch_reg,
2182 replace_equiv_address (operand1, scratch_reg));
2183 }
2184 else
2185 {
2186 /* We want to load the scratch register using the same mode as
2187 the ultimate destination. */
2188 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
2189
2190 emit_move_insn (scratch_reg, operand1);
2191 }
2192
2193 /* And emit the insn to set the ultimate destination. We know that
2194 the scratch register has the same mode as the destination at this
2195 point. */
2196 emit_move_insn (operand0, scratch_reg);
2197 return 1;
2198 }
2199
2200 /* Handle the most common case: storing into a register. */
2201 if (register_operand (operand0, mode))
2202 {
2203 /* Legitimize TLS symbol references. This happens for references
2204 that aren't a legitimate constant. */
2205 if (PA_SYMBOL_REF_TLS_P (operand1))
2206 operand1 = legitimize_tls_address (operand1);
2207
2208 if (register_operand (operand1, mode)
2209 || (GET_CODE (operand1) == CONST_INT
2210 && pa_cint_ok_for_move (UINTVAL (operand1)))
2211 || (operand1 == CONST0_RTX (mode))
2212 || (GET_CODE (operand1) == HIGH
2213 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
2214 /* Only `general_operands' can come here, so MEM is ok. */
2215 || GET_CODE (operand1) == MEM)
2216 {
2217 /* Various sets are created during RTL generation which don't
2218 have the REG_POINTER flag correctly set. After the CSE pass,
2219 instruction recognition can fail if we don't consistently
2220 set this flag when performing register copies. This should
2221 also improve the opportunities for creating insns that use
2222 unscaled indexing. */
2223 if (REG_P (operand0) && REG_P (operand1))
2224 {
2225 if (REG_POINTER (operand1)
2226 && !REG_POINTER (operand0)
2227 && !HARD_REGISTER_P (operand0))
2228 copy_reg_pointer (operand0, operand1);
2229 }
2230
2231 /* When MEMs are broken out, the REG_POINTER flag doesn't
2232 get set. In some cases, we can set the REG_POINTER flag
2233 from the declaration for the MEM. */
2234 if (REG_P (operand0)
2235 && GET_CODE (operand1) == MEM
2236 && !REG_POINTER (operand0))
2237 {
2238 tree decl = MEM_EXPR (operand1);
2239
2240 /* Set the register pointer flag and register alignment
2241 if the declaration for this memory reference is a
2242 pointer type. */
2243 if (decl)
2244 {
2245 tree type;
2246
2247 /* If this is a COMPONENT_REF, use the FIELD_DECL from
2248 tree operand 1. */
2249 if (TREE_CODE (decl) == COMPONENT_REF)
2250 decl = TREE_OPERAND (decl, 1);
2251
2252 type = TREE_TYPE (decl);
2253 type = strip_array_types (type);
2254
2255 if (POINTER_TYPE_P (type))
2256 mark_reg_pointer (operand0, BITS_PER_UNIT);
2257 }
2258 }
2259
2260 emit_insn (gen_rtx_SET (operand0, operand1));
2261 return 1;
2262 }
2263 }
2264 else if (GET_CODE (operand0) == MEM)
2265 {
2266 if (mode == DFmode && operand1 == CONST0_RTX (mode)
2267 && !(lra_in_progress || reload_in_progress || reload_completed))
2268 {
2269 rtx temp = gen_reg_rtx (DFmode);
2270
2271 emit_insn (gen_rtx_SET (temp, operand1));
2272 emit_insn (gen_rtx_SET (operand0, temp));
2273 return 1;
2274 }
2275 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
2276 {
2277 /* Run this case quickly. */
2278 emit_insn (gen_rtx_SET (operand0, operand1));
2279 return 1;
2280 }
2281 if (! (lra_in_progress || reload_in_progress || reload_completed))
2282 {
2283 operands[0] = validize_mem (operand0);
2284 operands[1] = operand1 = force_reg (mode, operand1);
2285 }
2286 }
2287
2288 /* Simplify the source if we need to.
2289 Note we do have to handle function labels here, even though we do
2290 not consider them legitimate constants. Loop optimizations can
2291 call the emit_move_xxx with one as a source. */
2292 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
2293 || (GET_CODE (operand1) == HIGH
2294 && symbolic_operand (XEXP (operand1, 0), mode))
2295 || function_label_operand (operand1, VOIDmode)
2296 || tls_referenced_p (operand1))
2297 {
2298 int ishighonly = 0;
2299
2300 if (GET_CODE (operand1) == HIGH)
2301 {
2302 ishighonly = 1;
2303 operand1 = XEXP (operand1, 0);
2304 }
2305 if (symbolic_operand (operand1, mode))
2306 {
2307 /* Argh. The assembler and linker can't handle arithmetic
2308 involving plabels.
2309
2310 So we force the plabel into memory, load operand0 from
2311 the memory location, then add in the constant part. */
2312 if ((GET_CODE (operand1) == CONST
2313 && GET_CODE (XEXP (operand1, 0)) == PLUS
2314 && function_label_operand (XEXP (XEXP (operand1, 0), 0),
2315 VOIDmode))
2316 || function_label_operand (operand1, VOIDmode))
2317 {
2318 rtx temp, const_part;
2319
2320 /* Figure out what (if any) scratch register to use. */
2321 if (lra_in_progress || reload_in_progress || reload_completed)
2322 {
2323 scratch_reg = scratch_reg ? scratch_reg : operand0;
2324 /* SCRATCH_REG will hold an address and maybe the actual
2325 data. We want it in WORD_MODE regardless of what mode it
2326 was originally given to us. */
2327 scratch_reg = force_mode (word_mode, scratch_reg);
2328 }
2329 else if (flag_pic)
2330 scratch_reg = gen_reg_rtx (Pmode);
2331
2332 if (GET_CODE (operand1) == CONST)
2333 {
2334 /* Save away the constant part of the expression. */
2335 const_part = XEXP (XEXP (operand1, 0), 1);
2336 gcc_assert (GET_CODE (const_part) == CONST_INT);
2337
2338 /* Force the function label into memory. */
2339 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
2340 }
2341 else
2342 {
2343 /* No constant part. */
2344 const_part = NULL_RTX;
2345
2346 /* Force the function label into memory. */
2347 temp = force_const_mem (mode, operand1);
2348 }
2349
2350
2351 /* Get the address of the memory location. PIC-ify it if
2352 necessary. */
2353 temp = XEXP (temp, 0);
2354 if (flag_pic)
2355 temp = legitimize_pic_address (temp, mode, scratch_reg);
2356
2357 /* Put the address of the memory location into our destination
2358 register. */
2359 operands[1] = temp;
2360 pa_emit_move_sequence (operands, mode, scratch_reg);
2361
2362 /* Now load from the memory location into our destination
2363 register. */
2364 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
2365 pa_emit_move_sequence (operands, mode, scratch_reg);
2366
2367 /* And add back in the constant part. */
2368 if (const_part != NULL_RTX)
2369 expand_inc (operand0, const_part);
2370
2371 return 1;
2372 }
2373
2374 if (flag_pic)
2375 {
2376 rtx_insn *insn;
2377 rtx temp;
2378
2379 if (lra_in_progress || reload_in_progress || reload_completed)
2380 {
2381 temp = scratch_reg ? scratch_reg : operand0;
2382 /* TEMP will hold an address and maybe the actual
2383 data. We want it in WORD_MODE regardless of what mode it
2384 was originally given to us. */
2385 temp = force_mode (word_mode, temp);
2386 }
2387 else
2388 temp = gen_reg_rtx (Pmode);
2389
2390 /* Force (const (plus (symbol) (const_int))) to memory
2391 if the const_int will not fit in 14 bits. Although
2392 this requires a relocation, the instruction sequence
2393 needed to load the value is shorter. */
2394 if (GET_CODE (operand1) == CONST
2395 && GET_CODE (XEXP (operand1, 0)) == PLUS
2396 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
2397 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1)))
2398 {
2399 rtx x, m = force_const_mem (mode, operand1);
2400
2401 x = legitimize_pic_address (XEXP (m, 0), mode, temp);
2402 x = replace_equiv_address (m, x);
2403 insn = emit_move_insn (operand0, x);
2404 }
2405 else
2406 {
2407 operands[1] = legitimize_pic_address (operand1, mode, temp);
2408 if (REG_P (operand0) && REG_P (operands[1]))
2409 copy_reg_pointer (operand0, operands[1]);
2410 insn = emit_move_insn (operand0, operands[1]);
2411 }
2412
2413 /* Put a REG_EQUAL note on this insn. */
2414 set_unique_reg_note (insn, REG_EQUAL, operand1);
2415 }
2416 /* On the HPPA, references to data space are supposed to use dp,
2417 register 27, but showing it in the RTL inhibits various cse
2418 and loop optimizations. */
2419 else
2420 {
2421 rtx temp, set;
2422
2423 if (lra_in_progress || reload_in_progress || reload_completed)
2424 {
2425 temp = scratch_reg ? scratch_reg : operand0;
2426 /* TEMP will hold an address and maybe the actual
2427 data. We want it in WORD_MODE regardless of what mode it
2428 was originally given to us. */
2429 temp = force_mode (word_mode, temp);
2430 }
2431 else
2432 temp = gen_reg_rtx (mode);
2433
2434 /* Loading a SYMBOL_REF into a register makes that register
2435 safe to be used as the base in an indexed address.
2436
2437 Don't mark hard registers though. That loses. */
2438 if (GET_CODE (operand0) == REG
2439 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
2440 mark_reg_pointer (operand0, BITS_PER_UNIT);
2441 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
2442 mark_reg_pointer (temp, BITS_PER_UNIT);
2443
2444 if (ishighonly)
2445 set = gen_rtx_SET (operand0, temp);
2446 else
2447 set = gen_rtx_SET (operand0,
2448 gen_rtx_LO_SUM (mode, temp, operand1));
2449
2450 emit_insn (gen_rtx_SET (temp, gen_rtx_HIGH (mode, operand1)));
2451 emit_insn (set);
2452
2453 }
2454 return 1;
2455 }
2456 else if (tls_referenced_p (operand1))
2457 {
2458 rtx tmp = operand1;
2459 rtx addend = NULL;
2460
2461 if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
2462 {
2463 addend = XEXP (XEXP (tmp, 0), 1);
2464 tmp = XEXP (XEXP (tmp, 0), 0);
2465 }
2466
2467 gcc_assert (GET_CODE (tmp) == SYMBOL_REF);
2468 tmp = legitimize_tls_address (tmp);
2469 if (addend)
2470 {
2471 tmp = gen_rtx_PLUS (mode, tmp, addend);
2472 tmp = force_operand (tmp, operands[0]);
2473 }
2474 operands[1] = tmp;
2475 }
2476 else if (GET_CODE (operand1) != CONST_INT
2477 || !pa_cint_ok_for_move (UINTVAL (operand1)))
2478 {
2479 rtx temp;
2480 rtx_insn *insn;
2481 rtx op1 = operand1;
2482 HOST_WIDE_INT value = 0;
2483 HOST_WIDE_INT insv = 0;
2484 int insert = 0;
2485
2486 if (GET_CODE (operand1) == CONST_INT)
2487 value = INTVAL (operand1);
2488
2489 if (TARGET_64BIT
2490 && GET_CODE (operand1) == CONST_INT
2491 && HOST_BITS_PER_WIDE_INT > 32
2492 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
2493 {
2494 HOST_WIDE_INT nval;
2495
2496 /* Extract the low order 32 bits of the value and sign extend.
2497 If the new value is the same as the original value, we can
2498 can use the original value as-is. If the new value is
2499 different, we use it and insert the most-significant 32-bits
2500 of the original value into the final result. */
2501 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
2502 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
2503 if (value != nval)
2504 {
2505 #if HOST_BITS_PER_WIDE_INT > 32
2506 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
2507 #endif
2508 insert = 1;
2509 value = nval;
2510 operand1 = GEN_INT (nval);
2511 }
2512 }
2513
2514 if (lra_in_progress || reload_in_progress || reload_completed)
2515 temp = scratch_reg ? scratch_reg : operand0;
2516 else
2517 temp = gen_reg_rtx (mode);
2518
2519 /* We don't directly split DImode constants on 32-bit targets
2520 because PLUS uses an 11-bit immediate and the insn sequence
2521 generated is not as efficient as the one using HIGH/LO_SUM. */
2522 if (GET_CODE (operand1) == CONST_INT
2523 && GET_MODE_BITSIZE (mode) <= BITS_PER_WORD
2524 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2525 && !insert)
2526 {
2527 /* Directly break constant into high and low parts. This
2528 provides better optimization opportunities because various
2529 passes recognize constants split with PLUS but not LO_SUM.
2530 We use a 14-bit signed low part except when the addition
2531 of 0x4000 to the high part might change the sign of the
2532 high part. */
2533 HOST_WIDE_INT low = value & 0x3fff;
2534 HOST_WIDE_INT high = value & ~ 0x3fff;
2535
2536 if (low >= 0x2000)
2537 {
2538 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
2539 high += 0x2000;
2540 else
2541 high += 0x4000;
2542 }
2543
2544 low = value - high;
2545
2546 emit_insn (gen_rtx_SET (temp, GEN_INT (high)));
2547 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2548 }
2549 else
2550 {
2551 emit_insn (gen_rtx_SET (temp, gen_rtx_HIGH (mode, operand1)));
2552 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
2553 }
2554
2555 insn = emit_move_insn (operands[0], operands[1]);
2556
2557 /* Now insert the most significant 32 bits of the value
2558 into the register. When we don't have a second register
2559 available, it could take up to nine instructions to load
2560 a 64-bit integer constant. Prior to reload, we force
2561 constants that would take more than three instructions
2562 to load to the constant pool. During and after reload,
2563 we have to handle all possible values. */
2564 if (insert)
2565 {
2566 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
2567 register and the value to be inserted is outside the
2568 range that can be loaded with three depdi instructions. */
2569 if (temp != operand0 && (insv >= 16384 || insv < -16384))
2570 {
2571 operand1 = GEN_INT (insv);
2572
2573 emit_insn (gen_rtx_SET (temp,
2574 gen_rtx_HIGH (mode, operand1)));
2575 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
2576 if (mode == DImode)
2577 insn = emit_insn (gen_insvdi (operand0, GEN_INT (32),
2578 const0_rtx, temp));
2579 else
2580 insn = emit_insn (gen_insvsi (operand0, GEN_INT (32),
2581 const0_rtx, temp));
2582 }
2583 else
2584 {
2585 int len = 5, pos = 27;
2586
2587 /* Insert the bits using the depdi instruction. */
2588 while (pos >= 0)
2589 {
2590 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2591 HOST_WIDE_INT sign = v5 < 0;
2592
2593 /* Left extend the insertion. */
2594 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2595 while (pos > 0 && (insv & 1) == sign)
2596 {
2597 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2598 len += 1;
2599 pos -= 1;
2600 }
2601
2602 if (mode == DImode)
2603 insn = emit_insn (gen_insvdi (operand0,
2604 GEN_INT (len),
2605 GEN_INT (pos),
2606 GEN_INT (v5)));
2607 else
2608 insn = emit_insn (gen_insvsi (operand0,
2609 GEN_INT (len),
2610 GEN_INT (pos),
2611 GEN_INT (v5)));
2612
2613 len = pos > 0 && pos < 5 ? pos : 5;
2614 pos -= len;
2615 }
2616 }
2617 }
2618
2619 set_unique_reg_note (insn, REG_EQUAL, op1);
2620
2621 return 1;
2622 }
2623 }
2624 /* Now have insn-emit do whatever it normally does. */
2625 return 0;
2626 }
2627
2628 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2629 it will need a link/runtime reloc). */
2630
2631 int
2632 pa_reloc_needed (tree exp)
2633 {
2634 int reloc = 0;
2635
2636 switch (TREE_CODE (exp))
2637 {
2638 case ADDR_EXPR:
2639 return 1;
2640
2641 case POINTER_PLUS_EXPR:
2642 case PLUS_EXPR:
2643 case MINUS_EXPR:
2644 reloc = pa_reloc_needed (TREE_OPERAND (exp, 0));
2645 reloc |= pa_reloc_needed (TREE_OPERAND (exp, 1));
2646 break;
2647
2648 CASE_CONVERT:
2649 case NON_LVALUE_EXPR:
2650 reloc = pa_reloc_needed (TREE_OPERAND (exp, 0));
2651 break;
2652
2653 case CONSTRUCTOR:
2654 {
2655 tree value;
2656 unsigned HOST_WIDE_INT ix;
2657
2658 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), ix, value)
2659 if (value)
2660 reloc |= pa_reloc_needed (value);
2661 }
2662 break;
2663
2664 case ERROR_MARK:
2665 break;
2666
2667 default:
2668 break;
2669 }
2670 return reloc;
2671 }
2672
2673
2674 /* Return the best assembler insn template
2675 for moving operands[1] into operands[0] as a fullword. */
2676 const char *
2677 pa_singlemove_string (rtx *operands)
2678 {
2679 HOST_WIDE_INT intval;
2680
2681 if (GET_CODE (operands[0]) == MEM)
2682 return "stw %r1,%0";
2683 if (GET_CODE (operands[1]) == MEM)
2684 return "ldw %1,%0";
2685 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2686 {
2687 long i;
2688
2689 gcc_assert (GET_MODE (operands[1]) == SFmode);
2690
2691 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2692 bit pattern. */
2693 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (operands[1]), i);
2694
2695 operands[1] = GEN_INT (i);
2696 /* Fall through to CONST_INT case. */
2697 }
2698 if (GET_CODE (operands[1]) == CONST_INT)
2699 {
2700 intval = INTVAL (operands[1]);
2701
2702 if (VAL_14_BITS_P (intval))
2703 return "ldi %1,%0";
2704 else if ((intval & 0x7ff) == 0)
2705 return "ldil L'%1,%0";
2706 else if (pa_zdepi_cint_p (intval))
2707 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2708 else
2709 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2710 }
2711 return "copy %1,%0";
2712 }
2713
2714
2715 /* Compute position (in OP[1]) and width (in OP[2])
2716 useful for copying IMM to a register using the zdepi
2717 instructions. Store the immediate value to insert in OP[0]. */
2718 static void
2719 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2720 {
2721 int lsb, len;
2722
2723 /* Find the least significant set bit in IMM. */
2724 for (lsb = 0; lsb < 32; lsb++)
2725 {
2726 if ((imm & 1) != 0)
2727 break;
2728 imm >>= 1;
2729 }
2730
2731 /* Choose variants based on *sign* of the 5-bit field. */
2732 if ((imm & 0x10) == 0)
2733 len = (lsb <= 28) ? 4 : 32 - lsb;
2734 else
2735 {
2736 /* Find the width of the bitstring in IMM. */
2737 for (len = 5; len < 32 - lsb; len++)
2738 {
2739 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2740 break;
2741 }
2742
2743 /* Sign extend IMM as a 5-bit value. */
2744 imm = (imm & 0xf) - 0x10;
2745 }
2746
2747 op[0] = imm;
2748 op[1] = 31 - lsb;
2749 op[2] = len;
2750 }
2751
2752 /* Compute position (in OP[1]) and width (in OP[2])
2753 useful for copying IMM to a register using the depdi,z
2754 instructions. Store the immediate value to insert in OP[0]. */
2755
2756 static void
2757 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2758 {
2759 int lsb, len, maxlen;
2760
2761 maxlen = MIN (HOST_BITS_PER_WIDE_INT, 64);
2762
2763 /* Find the least significant set bit in IMM. */
2764 for (lsb = 0; lsb < maxlen; lsb++)
2765 {
2766 if ((imm & 1) != 0)
2767 break;
2768 imm >>= 1;
2769 }
2770
2771 /* Choose variants based on *sign* of the 5-bit field. */
2772 if ((imm & 0x10) == 0)
2773 len = (lsb <= maxlen - 4) ? 4 : maxlen - lsb;
2774 else
2775 {
2776 /* Find the width of the bitstring in IMM. */
2777 for (len = 5; len < maxlen - lsb; len++)
2778 {
2779 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2780 break;
2781 }
2782
2783 /* Extend length if host is narrow and IMM is negative. */
2784 if (HOST_BITS_PER_WIDE_INT == 32 && len == maxlen - lsb)
2785 len += 32;
2786
2787 /* Sign extend IMM as a 5-bit value. */
2788 imm = (imm & 0xf) - 0x10;
2789 }
2790
2791 op[0] = imm;
2792 op[1] = 63 - lsb;
2793 op[2] = len;
2794 }
2795
2796 /* Output assembler code to perform a doubleword move insn
2797 with operands OPERANDS. */
2798
2799 const char *
2800 pa_output_move_double (rtx *operands)
2801 {
2802 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2803 rtx latehalf[2];
2804 rtx addreg0 = 0, addreg1 = 0;
2805 int highonly = 0;
2806
2807 /* First classify both operands. */
2808
2809 if (REG_P (operands[0]))
2810 optype0 = REGOP;
2811 else if (offsettable_memref_p (operands[0]))
2812 optype0 = OFFSOP;
2813 else if (GET_CODE (operands[0]) == MEM)
2814 optype0 = MEMOP;
2815 else
2816 optype0 = RNDOP;
2817
2818 if (REG_P (operands[1]))
2819 optype1 = REGOP;
2820 else if (CONSTANT_P (operands[1]))
2821 optype1 = CNSTOP;
2822 else if (offsettable_memref_p (operands[1]))
2823 optype1 = OFFSOP;
2824 else if (GET_CODE (operands[1]) == MEM)
2825 optype1 = MEMOP;
2826 else
2827 optype1 = RNDOP;
2828
2829 /* Check for the cases that the operand constraints are not
2830 supposed to allow to happen. */
2831 gcc_assert (optype0 == REGOP || optype1 == REGOP);
2832
2833 /* Handle copies between general and floating registers. */
2834
2835 if (optype0 == REGOP && optype1 == REGOP
2836 && FP_REG_P (operands[0]) ^ FP_REG_P (operands[1]))
2837 {
2838 if (FP_REG_P (operands[0]))
2839 {
2840 output_asm_insn ("{stws|stw} %1,-16(%%sp)", operands);
2841 output_asm_insn ("{stws|stw} %R1,-12(%%sp)", operands);
2842 return "{fldds|fldd} -16(%%sp),%0";
2843 }
2844 else
2845 {
2846 output_asm_insn ("{fstds|fstd} %1,-16(%%sp)", operands);
2847 output_asm_insn ("{ldws|ldw} -16(%%sp),%0", operands);
2848 return "{ldws|ldw} -12(%%sp),%R0";
2849 }
2850 }
2851
2852 /* Handle auto decrementing and incrementing loads and stores
2853 specifically, since the structure of the function doesn't work
2854 for them without major modification. Do it better when we learn
2855 this port about the general inc/dec addressing of PA.
2856 (This was written by tege. Chide him if it doesn't work.) */
2857
2858 if (optype0 == MEMOP)
2859 {
2860 /* We have to output the address syntax ourselves, since print_operand
2861 doesn't deal with the addresses we want to use. Fix this later. */
2862
2863 rtx addr = XEXP (operands[0], 0);
2864 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2865 {
2866 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2867
2868 operands[0] = XEXP (addr, 0);
2869 gcc_assert (GET_CODE (operands[1]) == REG
2870 && GET_CODE (operands[0]) == REG);
2871
2872 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2873
2874 /* No overlap between high target register and address
2875 register. (We do this in a non-obvious way to
2876 save a register file writeback) */
2877 if (GET_CODE (addr) == POST_INC)
2878 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2879 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2880 }
2881 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2882 {
2883 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2884
2885 operands[0] = XEXP (addr, 0);
2886 gcc_assert (GET_CODE (operands[1]) == REG
2887 && GET_CODE (operands[0]) == REG);
2888
2889 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2890 /* No overlap between high target register and address
2891 register. (We do this in a non-obvious way to save a
2892 register file writeback) */
2893 if (GET_CODE (addr) == PRE_INC)
2894 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2895 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2896 }
2897 }
2898 if (optype1 == MEMOP)
2899 {
2900 /* We have to output the address syntax ourselves, since print_operand
2901 doesn't deal with the addresses we want to use. Fix this later. */
2902
2903 rtx addr = XEXP (operands[1], 0);
2904 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2905 {
2906 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2907
2908 operands[1] = XEXP (addr, 0);
2909 gcc_assert (GET_CODE (operands[0]) == REG
2910 && GET_CODE (operands[1]) == REG);
2911
2912 if (!reg_overlap_mentioned_p (high_reg, addr))
2913 {
2914 /* No overlap between high target register and address
2915 register. (We do this in a non-obvious way to
2916 save a register file writeback) */
2917 if (GET_CODE (addr) == POST_INC)
2918 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2919 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2920 }
2921 else
2922 {
2923 /* This is an undefined situation. We should load into the
2924 address register *and* update that register. Probably
2925 we don't need to handle this at all. */
2926 if (GET_CODE (addr) == POST_INC)
2927 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2928 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2929 }
2930 }
2931 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2932 {
2933 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2934
2935 operands[1] = XEXP (addr, 0);
2936 gcc_assert (GET_CODE (operands[0]) == REG
2937 && GET_CODE (operands[1]) == REG);
2938
2939 if (!reg_overlap_mentioned_p (high_reg, addr))
2940 {
2941 /* No overlap between high target register and address
2942 register. (We do this in a non-obvious way to
2943 save a register file writeback) */
2944 if (GET_CODE (addr) == PRE_INC)
2945 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2946 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2947 }
2948 else
2949 {
2950 /* This is an undefined situation. We should load into the
2951 address register *and* update that register. Probably
2952 we don't need to handle this at all. */
2953 if (GET_CODE (addr) == PRE_INC)
2954 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2955 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2956 }
2957 }
2958 else if (GET_CODE (addr) == PLUS
2959 && GET_CODE (XEXP (addr, 0)) == MULT)
2960 {
2961 rtx xoperands[4];
2962
2963 /* Load address into left half of destination register. */
2964 xoperands[0] = gen_rtx_SUBREG (SImode, operands[0], 0);
2965 xoperands[1] = XEXP (addr, 1);
2966 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2967 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2968 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2969 xoperands);
2970 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2971 }
2972 else if (GET_CODE (addr) == PLUS
2973 && REG_P (XEXP (addr, 0))
2974 && REG_P (XEXP (addr, 1)))
2975 {
2976 rtx xoperands[3];
2977
2978 /* Load address into left half of destination register. */
2979 xoperands[0] = gen_rtx_SUBREG (SImode, operands[0], 0);
2980 xoperands[1] = XEXP (addr, 0);
2981 xoperands[2] = XEXP (addr, 1);
2982 output_asm_insn ("{addl|add,l} %1,%2,%0",
2983 xoperands);
2984 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2985 }
2986 }
2987
2988 /* If an operand is an unoffsettable memory ref, find a register
2989 we can increment temporarily to make it refer to the second word. */
2990
2991 if (optype0 == MEMOP)
2992 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2993
2994 if (optype1 == MEMOP)
2995 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2996
2997 /* Ok, we can do one word at a time.
2998 Normally we do the low-numbered word first.
2999
3000 In either case, set up in LATEHALF the operands to use
3001 for the high-numbered word and in some cases alter the
3002 operands in OPERANDS to be suitable for the low-numbered word. */
3003
3004 if (optype0 == REGOP)
3005 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3006 else if (optype0 == OFFSOP)
3007 latehalf[0] = adjust_address_nv (operands[0], SImode, 4);
3008 else
3009 latehalf[0] = operands[0];
3010
3011 if (optype1 == REGOP)
3012 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
3013 else if (optype1 == OFFSOP)
3014 latehalf[1] = adjust_address_nv (operands[1], SImode, 4);
3015 else if (optype1 == CNSTOP)
3016 {
3017 if (GET_CODE (operands[1]) == HIGH)
3018 {
3019 operands[1] = XEXP (operands[1], 0);
3020 highonly = 1;
3021 }
3022 split_double (operands[1], &operands[1], &latehalf[1]);
3023 }
3024 else
3025 latehalf[1] = operands[1];
3026
3027 /* If the first move would clobber the source of the second one,
3028 do them in the other order.
3029
3030 This can happen in two cases:
3031
3032 mem -> register where the first half of the destination register
3033 is the same register used in the memory's address. Reload
3034 can create such insns.
3035
3036 mem in this case will be either register indirect or register
3037 indirect plus a valid offset.
3038
3039 register -> register move where REGNO(dst) == REGNO(src + 1)
3040 someone (Tim/Tege?) claimed this can happen for parameter loads.
3041
3042 Handle mem -> register case first. */
3043 if (optype0 == REGOP
3044 && (optype1 == MEMOP || optype1 == OFFSOP)
3045 && refers_to_regno_p (REGNO (operands[0]), operands[1]))
3046 {
3047 /* Do the late half first. */
3048 if (addreg1)
3049 output_asm_insn ("ldo 4(%0),%0", &addreg1);
3050 output_asm_insn (pa_singlemove_string (latehalf), latehalf);
3051
3052 /* Then clobber. */
3053 if (addreg1)
3054 output_asm_insn ("ldo -4(%0),%0", &addreg1);
3055 return pa_singlemove_string (operands);
3056 }
3057
3058 /* Now handle register -> register case. */
3059 if (optype0 == REGOP && optype1 == REGOP
3060 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
3061 {
3062 output_asm_insn (pa_singlemove_string (latehalf), latehalf);
3063 return pa_singlemove_string (operands);
3064 }
3065
3066 /* Normal case: do the two words, low-numbered first. */
3067
3068 output_asm_insn (pa_singlemove_string (operands), operands);
3069
3070 /* Make any unoffsettable addresses point at high-numbered word. */
3071 if (addreg0)
3072 output_asm_insn ("ldo 4(%0),%0", &addreg0);
3073 if (addreg1)
3074 output_asm_insn ("ldo 4(%0),%0", &addreg1);
3075
3076 /* Do high-numbered word. */
3077 if (highonly)
3078 output_asm_insn ("ldil L'%1,%0", latehalf);
3079 else
3080 output_asm_insn (pa_singlemove_string (latehalf), latehalf);
3081
3082 /* Undo the adds we just did. */
3083 if (addreg0)
3084 output_asm_insn ("ldo -4(%0),%0", &addreg0);
3085 if (addreg1)
3086 output_asm_insn ("ldo -4(%0),%0", &addreg1);
3087
3088 return "";
3089 }
3090
3091 const char *
3092 pa_output_fp_move_double (rtx *operands)
3093 {
3094 if (FP_REG_P (operands[0]))
3095 {
3096 if (FP_REG_P (operands[1])
3097 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
3098 output_asm_insn ("fcpy,dbl %f1,%0", operands);
3099 else
3100 output_asm_insn ("fldd%F1 %1,%0", operands);
3101 }
3102 else if (FP_REG_P (operands[1]))
3103 {
3104 output_asm_insn ("fstd%F0 %1,%0", operands);
3105 }
3106 else
3107 {
3108 rtx xoperands[2];
3109
3110 gcc_assert (operands[1] == CONST0_RTX (GET_MODE (operands[0])));
3111
3112 /* This is a pain. You have to be prepared to deal with an
3113 arbitrary address here including pre/post increment/decrement.
3114
3115 so avoid this in the MD. */
3116 gcc_assert (GET_CODE (operands[0]) == REG);
3117
3118 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3119 xoperands[0] = operands[0];
3120 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
3121 }
3122 return "";
3123 }
3124
3125 /* Return a REG that occurs in ADDR with coefficient 1.
3126 ADDR can be effectively incremented by incrementing REG. */
3127
3128 static rtx
3129 find_addr_reg (rtx addr)
3130 {
3131 while (GET_CODE (addr) == PLUS)
3132 {
3133 if (GET_CODE (XEXP (addr, 0)) == REG)
3134 addr = XEXP (addr, 0);
3135 else if (GET_CODE (XEXP (addr, 1)) == REG)
3136 addr = XEXP (addr, 1);
3137 else if (CONSTANT_P (XEXP (addr, 0)))
3138 addr = XEXP (addr, 1);
3139 else if (CONSTANT_P (XEXP (addr, 1)))
3140 addr = XEXP (addr, 0);
3141 else
3142 gcc_unreachable ();
3143 }
3144 gcc_assert (GET_CODE (addr) == REG);
3145 return addr;
3146 }
3147
3148 /* Emit code to perform a block move.
3149
3150 OPERANDS[0] is the destination pointer as a REG, clobbered.
3151 OPERANDS[1] is the source pointer as a REG, clobbered.
3152 OPERANDS[2] is a register for temporary storage.
3153 OPERANDS[3] is a register for temporary storage.
3154 OPERANDS[4] is the size as a CONST_INT
3155 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
3156 OPERANDS[6] is another temporary register. */
3157
3158 const char *
3159 pa_output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
3160 {
3161 int align = INTVAL (operands[5]);
3162 unsigned long n_bytes = INTVAL (operands[4]);
3163
3164 /* We can't move more than a word at a time because the PA
3165 has no longer integer move insns. (Could use fp mem ops?) */
3166 if (align > (TARGET_64BIT ? 8 : 4))
3167 align = (TARGET_64BIT ? 8 : 4);
3168
3169 /* Note that we know each loop below will execute at least twice
3170 (else we would have open-coded the copy). */
3171 switch (align)
3172 {
3173 case 8:
3174 /* Pre-adjust the loop counter. */
3175 operands[4] = GEN_INT (n_bytes - 16);
3176 output_asm_insn ("ldi %4,%2", operands);
3177
3178 /* Copying loop. */
3179 output_asm_insn ("ldd,ma 8(%1),%3", operands);
3180 output_asm_insn ("ldd,ma 8(%1),%6", operands);
3181 output_asm_insn ("std,ma %3,8(%0)", operands);
3182 output_asm_insn ("addib,>= -16,%2,.-12", operands);
3183 output_asm_insn ("std,ma %6,8(%0)", operands);
3184
3185 /* Handle the residual. There could be up to 7 bytes of
3186 residual to copy! */
3187 if (n_bytes % 16 != 0)
3188 {
3189 operands[4] = GEN_INT (n_bytes % 8);
3190 if (n_bytes % 16 >= 8)
3191 output_asm_insn ("ldd,ma 8(%1),%3", operands);
3192 if (n_bytes % 8 != 0)
3193 output_asm_insn ("ldd 0(%1),%6", operands);
3194 if (n_bytes % 16 >= 8)
3195 output_asm_insn ("std,ma %3,8(%0)", operands);
3196 if (n_bytes % 8 != 0)
3197 output_asm_insn ("stdby,e %6,%4(%0)", operands);
3198 }
3199 return "";
3200
3201 case 4:
3202 /* Pre-adjust the loop counter. */
3203 operands[4] = GEN_INT (n_bytes - 8);
3204 output_asm_insn ("ldi %4,%2", operands);
3205
3206 /* Copying loop. */
3207 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
3208 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
3209 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
3210 output_asm_insn ("addib,>= -8,%2,.-12", operands);
3211 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
3212
3213 /* Handle the residual. There could be up to 7 bytes of
3214 residual to copy! */
3215 if (n_bytes % 8 != 0)
3216 {
3217 operands[4] = GEN_INT (n_bytes % 4);
3218 if (n_bytes % 8 >= 4)
3219 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
3220 if (n_bytes % 4 != 0)
3221 output_asm_insn ("ldw 0(%1),%6", operands);
3222 if (n_bytes % 8 >= 4)
3223 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
3224 if (n_bytes % 4 != 0)
3225 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
3226 }
3227 return "";
3228
3229 case 2:
3230 /* Pre-adjust the loop counter. */
3231 operands[4] = GEN_INT (n_bytes - 4);
3232 output_asm_insn ("ldi %4,%2", operands);
3233
3234 /* Copying loop. */
3235 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
3236 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
3237 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
3238 output_asm_insn ("addib,>= -4,%2,.-12", operands);
3239 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
3240
3241 /* Handle the residual. */
3242 if (n_bytes % 4 != 0)
3243 {
3244 if (n_bytes % 4 >= 2)
3245 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
3246 if (n_bytes % 2 != 0)
3247 output_asm_insn ("ldb 0(%1),%6", operands);
3248 if (n_bytes % 4 >= 2)
3249 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
3250 if (n_bytes % 2 != 0)
3251 output_asm_insn ("stb %6,0(%0)", operands);
3252 }
3253 return "";
3254
3255 case 1:
3256 /* Pre-adjust the loop counter. */
3257 operands[4] = GEN_INT (n_bytes - 2);
3258 output_asm_insn ("ldi %4,%2", operands);
3259
3260 /* Copying loop. */
3261 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
3262 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
3263 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
3264 output_asm_insn ("addib,>= -2,%2,.-12", operands);
3265 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
3266
3267 /* Handle the residual. */
3268 if (n_bytes % 2 != 0)
3269 {
3270 output_asm_insn ("ldb 0(%1),%3", operands);
3271 output_asm_insn ("stb %3,0(%0)", operands);
3272 }
3273 return "";
3274
3275 default:
3276 gcc_unreachable ();
3277 }
3278 }
3279
3280 /* Count the number of insns necessary to handle this block move.
3281
3282 Basic structure is the same as emit_block_move, except that we
3283 count insns rather than emit them. */
3284
3285 static int
3286 compute_cpymem_length (rtx_insn *insn)
3287 {
3288 rtx pat = PATTERN (insn);
3289 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
3290 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
3291 unsigned int n_insns = 0;
3292
3293 /* We can't move more than four bytes at a time because the PA
3294 has no longer integer move insns. (Could use fp mem ops?) */
3295 if (align > (TARGET_64BIT ? 8 : 4))
3296 align = (TARGET_64BIT ? 8 : 4);
3297
3298 /* The basic copying loop. */
3299 n_insns = 6;
3300
3301 /* Residuals. */
3302 if (n_bytes % (2 * align) != 0)
3303 {
3304 if ((n_bytes % (2 * align)) >= align)
3305 n_insns += 2;
3306
3307 if ((n_bytes % align) != 0)
3308 n_insns += 2;
3309 }
3310
3311 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3312 return n_insns * 4;
3313 }
3314
3315 /* Emit code to perform a block clear.
3316
3317 OPERANDS[0] is the destination pointer as a REG, clobbered.
3318 OPERANDS[1] is a register for temporary storage.
3319 OPERANDS[2] is the size as a CONST_INT
3320 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
3321
3322 const char *
3323 pa_output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
3324 {
3325 int align = INTVAL (operands[3]);
3326 unsigned long n_bytes = INTVAL (operands[2]);
3327
3328 /* We can't clear more than a word at a time because the PA
3329 has no longer integer move insns. */
3330 if (align > (TARGET_64BIT ? 8 : 4))
3331 align = (TARGET_64BIT ? 8 : 4);
3332
3333 /* Note that we know each loop below will execute at least twice
3334 (else we would have open-coded the copy). */
3335 switch (align)
3336 {
3337 case 8:
3338 /* Pre-adjust the loop counter. */
3339 operands[2] = GEN_INT (n_bytes - 16);
3340 output_asm_insn ("ldi %2,%1", operands);
3341
3342 /* Loop. */
3343 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3344 output_asm_insn ("addib,>= -16,%1,.-4", operands);
3345 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3346
3347 /* Handle the residual. There could be up to 7 bytes of
3348 residual to copy! */
3349 if (n_bytes % 16 != 0)
3350 {
3351 operands[2] = GEN_INT (n_bytes % 8);
3352 if (n_bytes % 16 >= 8)
3353 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3354 if (n_bytes % 8 != 0)
3355 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
3356 }
3357 return "";
3358
3359 case 4:
3360 /* Pre-adjust the loop counter. */
3361 operands[2] = GEN_INT (n_bytes - 8);
3362 output_asm_insn ("ldi %2,%1", operands);
3363
3364 /* Loop. */
3365 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3366 output_asm_insn ("addib,>= -8,%1,.-4", operands);
3367 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3368
3369 /* Handle the residual. There could be up to 7 bytes of
3370 residual to copy! */
3371 if (n_bytes % 8 != 0)
3372 {
3373 operands[2] = GEN_INT (n_bytes % 4);
3374 if (n_bytes % 8 >= 4)
3375 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3376 if (n_bytes % 4 != 0)
3377 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
3378 }
3379 return "";
3380
3381 case 2:
3382 /* Pre-adjust the loop counter. */
3383 operands[2] = GEN_INT (n_bytes - 4);
3384 output_asm_insn ("ldi %2,%1", operands);
3385
3386 /* Loop. */
3387 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3388 output_asm_insn ("addib,>= -4,%1,.-4", operands);
3389 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3390
3391 /* Handle the residual. */
3392 if (n_bytes % 4 != 0)
3393 {
3394 if (n_bytes % 4 >= 2)
3395 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3396 if (n_bytes % 2 != 0)
3397 output_asm_insn ("stb %%r0,0(%0)", operands);
3398 }
3399 return "";
3400
3401 case 1:
3402 /* Pre-adjust the loop counter. */
3403 operands[2] = GEN_INT (n_bytes - 2);
3404 output_asm_insn ("ldi %2,%1", operands);
3405
3406 /* Loop. */
3407 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3408 output_asm_insn ("addib,>= -2,%1,.-4", operands);
3409 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3410
3411 /* Handle the residual. */
3412 if (n_bytes % 2 != 0)
3413 output_asm_insn ("stb %%r0,0(%0)", operands);
3414
3415 return "";
3416
3417 default:
3418 gcc_unreachable ();
3419 }
3420 }
3421
3422 /* Count the number of insns necessary to handle this block move.
3423
3424 Basic structure is the same as emit_block_move, except that we
3425 count insns rather than emit them. */
3426
3427 static int
3428 compute_clrmem_length (rtx_insn *insn)
3429 {
3430 rtx pat = PATTERN (insn);
3431 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
3432 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
3433 unsigned int n_insns = 0;
3434
3435 /* We can't clear more than a word at a time because the PA
3436 has no longer integer move insns. */
3437 if (align > (TARGET_64BIT ? 8 : 4))
3438 align = (TARGET_64BIT ? 8 : 4);
3439
3440 /* The basic loop. */
3441 n_insns = 4;
3442
3443 /* Residuals. */
3444 if (n_bytes % (2 * align) != 0)
3445 {
3446 if ((n_bytes % (2 * align)) >= align)
3447 n_insns++;
3448
3449 if ((n_bytes % align) != 0)
3450 n_insns++;
3451 }
3452
3453 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3454 return n_insns * 4;
3455 }
3456
3457
3458 const char *
3459 pa_output_and (rtx *operands)
3460 {
3461 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3462 {
3463 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3464 int ls0, ls1, ms0, p, len;
3465
3466 for (ls0 = 0; ls0 < 32; ls0++)
3467 if ((mask & (1 << ls0)) == 0)
3468 break;
3469
3470 for (ls1 = ls0; ls1 < 32; ls1++)
3471 if ((mask & (1 << ls1)) != 0)
3472 break;
3473
3474 for (ms0 = ls1; ms0 < 32; ms0++)
3475 if ((mask & (1 << ms0)) == 0)
3476 break;
3477
3478 gcc_assert (ms0 == 32);
3479
3480 if (ls1 == 32)
3481 {
3482 len = ls0;
3483
3484 gcc_assert (len);
3485
3486 operands[2] = GEN_INT (len);
3487 return "{extru|extrw,u} %1,31,%2,%0";
3488 }
3489 else
3490 {
3491 /* We could use this `depi' for the case above as well, but `depi'
3492 requires one more register file access than an `extru'. */
3493
3494 p = 31 - ls0;
3495 len = ls1 - ls0;
3496
3497 operands[2] = GEN_INT (p);
3498 operands[3] = GEN_INT (len);
3499 return "{depi|depwi} 0,%2,%3,%0";
3500 }
3501 }
3502 else
3503 return "and %1,%2,%0";
3504 }
3505
3506 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3507 storing the result in operands[0]. */
3508 const char *
3509 pa_output_64bit_and (rtx *operands)
3510 {
3511 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3512 {
3513 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3514 int ls0, ls1, ms0, p, len;
3515
3516 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
3517 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
3518 break;
3519
3520 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
3521 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
3522 break;
3523
3524 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
3525 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
3526 break;
3527
3528 gcc_assert (ms0 == HOST_BITS_PER_WIDE_INT);
3529
3530 if (ls1 == HOST_BITS_PER_WIDE_INT)
3531 {
3532 len = ls0;
3533
3534 gcc_assert (len);
3535
3536 operands[2] = GEN_INT (len);
3537 return "extrd,u %1,63,%2,%0";
3538 }
3539 else
3540 {
3541 /* We could use this `depi' for the case above as well, but `depi'
3542 requires one more register file access than an `extru'. */
3543
3544 p = 63 - ls0;
3545 len = ls1 - ls0;
3546
3547 operands[2] = GEN_INT (p);
3548 operands[3] = GEN_INT (len);
3549 return "depdi 0,%2,%3,%0";
3550 }
3551 }
3552 else
3553 return "and %1,%2,%0";
3554 }
3555
3556 const char *
3557 pa_output_ior (rtx *operands)
3558 {
3559 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3560 int bs0, bs1, p, len;
3561
3562 if (INTVAL (operands[2]) == 0)
3563 return "copy %1,%0";
3564
3565 for (bs0 = 0; bs0 < 32; bs0++)
3566 if ((mask & (1 << bs0)) != 0)
3567 break;
3568
3569 for (bs1 = bs0; bs1 < 32; bs1++)
3570 if ((mask & (1 << bs1)) == 0)
3571 break;
3572
3573 gcc_assert (bs1 == 32 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
3574
3575 p = 31 - bs0;
3576 len = bs1 - bs0;
3577
3578 operands[2] = GEN_INT (p);
3579 operands[3] = GEN_INT (len);
3580 return "{depi|depwi} -1,%2,%3,%0";
3581 }
3582
3583 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3584 storing the result in operands[0]. */
3585 const char *
3586 pa_output_64bit_ior (rtx *operands)
3587 {
3588 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3589 int bs0, bs1, p, len;
3590
3591 if (INTVAL (operands[2]) == 0)
3592 return "copy %1,%0";
3593
3594 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3595 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3596 break;
3597
3598 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3599 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3600 break;
3601
3602 gcc_assert (bs1 == HOST_BITS_PER_WIDE_INT
3603 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
3604
3605 p = 63 - bs0;
3606 len = bs1 - bs0;
3607
3608 operands[2] = GEN_INT (p);
3609 operands[3] = GEN_INT (len);
3610 return "depdi -1,%2,%3,%0";
3611 }
3612
3613 /* Target hook for assembling integer objects. This code handles
3614 aligned SI and DI integers specially since function references
3615 must be preceded by P%. */
3616
3617 static bool
3618 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3619 {
3620 bool result;
3621 tree decl = NULL;
3622
3623 /* When we have a SYMBOL_REF with a SYMBOL_REF_DECL, we need to call
3624 call assemble_external and set the SYMBOL_REF_DECL to NULL before
3625 calling output_addr_const. Otherwise, it may call assemble_external
3626 in the midst of outputing the assembler code for the SYMBOL_REF.
3627 We restore the SYMBOL_REF_DECL after the output is done. */
3628 if (GET_CODE (x) == SYMBOL_REF)
3629 {
3630 decl = SYMBOL_REF_DECL (x);
3631 if (decl)
3632 {
3633 assemble_external (decl);
3634 SET_SYMBOL_REF_DECL (x, NULL);
3635 }
3636 }
3637
3638 if (size == UNITS_PER_WORD
3639 && aligned_p
3640 && function_label_operand (x, VOIDmode))
3641 {
3642 fputs (size == 8? "\t.dword\t" : "\t.word\t", asm_out_file);
3643
3644 /* We don't want an OPD when generating fast indirect calls. */
3645 if (!TARGET_FAST_INDIRECT_CALLS)
3646 fputs ("P%", asm_out_file);
3647
3648 output_addr_const (asm_out_file, x);
3649 fputc ('\n', asm_out_file);
3650 result = true;
3651 }
3652 else
3653 result = default_assemble_integer (x, size, aligned_p);
3654
3655 if (decl)
3656 SET_SYMBOL_REF_DECL (x, decl);
3657
3658 return result;
3659 }
3660
3661 /* Output an ascii string. */
3662 void
3663 pa_output_ascii (FILE *file, const char *p, int size)
3664 {
3665 int i;
3666 int chars_output;
3667 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3668
3669 /* The HP assembler can only take strings of 256 characters at one
3670 time. This is a limitation on input line length, *not* the
3671 length of the string. Sigh. Even worse, it seems that the
3672 restriction is in number of input characters (see \xnn &
3673 \whatever). So we have to do this very carefully. */
3674
3675 fputs ("\t.STRING \"", file);
3676
3677 chars_output = 0;
3678 for (i = 0; i < size; i += 4)
3679 {
3680 int co = 0;
3681 int io = 0;
3682 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3683 {
3684 unsigned int c = (unsigned char) p[i + io];
3685
3686 if (c == '\"' || c == '\\')
3687 partial_output[co++] = '\\';
3688 if (c >= ' ' && c < 0177)
3689 partial_output[co++] = c;
3690 else
3691 {
3692 unsigned int hexd;
3693 partial_output[co++] = '\\';
3694 partial_output[co++] = 'x';
3695 hexd = c / 16 - 0 + '0';
3696 if (hexd > '9')
3697 hexd -= '9' - 'a' + 1;
3698 partial_output[co++] = hexd;
3699 hexd = c % 16 - 0 + '0';
3700 if (hexd > '9')
3701 hexd -= '9' - 'a' + 1;
3702 partial_output[co++] = hexd;
3703 }
3704 }
3705 if (chars_output + co > 243)
3706 {
3707 fputs ("\"\n\t.STRING \"", file);
3708 chars_output = 0;
3709 }
3710 fwrite (partial_output, 1, (size_t) co, file);
3711 chars_output += co;
3712 co = 0;
3713 }
3714 fputs ("\"\n", file);
3715 }
3716
3717 /* Try to rewrite floating point comparisons & branches to avoid
3718 useless add,tr insns.
3719
3720 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3721 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3722 first attempt to remove useless add,tr insns. It is zero
3723 for the second pass as reorg sometimes leaves bogus REG_DEAD
3724 notes lying around.
3725
3726 When CHECK_NOTES is zero we can only eliminate add,tr insns
3727 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3728 instructions. */
3729 static void
3730 remove_useless_addtr_insns (int check_notes)
3731 {
3732 rtx_insn *insn;
3733 static int pass = 0;
3734
3735 /* This is fairly cheap, so always run it when optimizing. */
3736 if (optimize > 0)
3737 {
3738 int fcmp_count = 0;
3739 int fbranch_count = 0;
3740
3741 /* Walk all the insns in this function looking for fcmp & fbranch
3742 instructions. Keep track of how many of each we find. */
3743 for (insn = get_insns (); insn; insn = next_insn (insn))
3744 {
3745 rtx tmp;
3746
3747 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3748 if (! NONJUMP_INSN_P (insn) && ! JUMP_P (insn))
3749 continue;
3750
3751 tmp = PATTERN (insn);
3752
3753 /* It must be a set. */
3754 if (GET_CODE (tmp) != SET)
3755 continue;
3756
3757 /* If the destination is CCFP, then we've found an fcmp insn. */
3758 tmp = SET_DEST (tmp);
3759 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3760 {
3761 fcmp_count++;
3762 continue;
3763 }
3764
3765 tmp = PATTERN (insn);
3766 /* If this is an fbranch instruction, bump the fbranch counter. */
3767 if (GET_CODE (tmp) == SET
3768 && SET_DEST (tmp) == pc_rtx
3769 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3770 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3771 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3772 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3773 {
3774 fbranch_count++;
3775 continue;
3776 }
3777 }
3778
3779
3780 /* Find all floating point compare + branch insns. If possible,
3781 reverse the comparison & the branch to avoid add,tr insns. */
3782 for (insn = get_insns (); insn; insn = next_insn (insn))
3783 {
3784 rtx tmp;
3785 rtx_insn *next;
3786
3787 /* Ignore anything that isn't an INSN. */
3788 if (! NONJUMP_INSN_P (insn))
3789 continue;
3790
3791 tmp = PATTERN (insn);
3792
3793 /* It must be a set. */
3794 if (GET_CODE (tmp) != SET)
3795 continue;
3796
3797 /* The destination must be CCFP, which is register zero. */
3798 tmp = SET_DEST (tmp);
3799 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3800 continue;
3801
3802 /* INSN should be a set of CCFP.
3803
3804 See if the result of this insn is used in a reversed FP
3805 conditional branch. If so, reverse our condition and
3806 the branch. Doing so avoids useless add,tr insns. */
3807 next = next_insn (insn);
3808 while (next)
3809 {
3810 /* Jumps, calls and labels stop our search. */
3811 if (JUMP_P (next) || CALL_P (next) || LABEL_P (next))
3812 break;
3813
3814 /* As does another fcmp insn. */
3815 if (NONJUMP_INSN_P (next)
3816 && GET_CODE (PATTERN (next)) == SET
3817 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3818 && REGNO (SET_DEST (PATTERN (next))) == 0)
3819 break;
3820
3821 next = next_insn (next);
3822 }
3823
3824 /* Is NEXT_INSN a branch? */
3825 if (next && JUMP_P (next))
3826 {
3827 rtx pattern = PATTERN (next);
3828
3829 /* If it a reversed fp conditional branch (e.g. uses add,tr)
3830 and CCFP dies, then reverse our conditional and the branch
3831 to avoid the add,tr. */
3832 if (GET_CODE (pattern) == SET
3833 && SET_DEST (pattern) == pc_rtx
3834 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3835 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3836 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3837 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3838 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3839 && (fcmp_count == fbranch_count
3840 || (check_notes
3841 && find_regno_note (next, REG_DEAD, 0))))
3842 {
3843 /* Reverse the branch. */
3844 tmp = XEXP (SET_SRC (pattern), 1);
3845 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3846 XEXP (SET_SRC (pattern), 2) = tmp;
3847 INSN_CODE (next) = -1;
3848
3849 /* Reverse our condition. */
3850 tmp = PATTERN (insn);
3851 PUT_CODE (XEXP (tmp, 1),
3852 (reverse_condition_maybe_unordered
3853 (GET_CODE (XEXP (tmp, 1)))));
3854 }
3855 }
3856 }
3857 }
3858
3859 pass = !pass;
3860
3861 }
3862
3863 /* You may have trouble believing this, but this is the 32 bit HP-PA
3864 stack layout. Wow.
3865
3866 Offset Contents
3867
3868 Variable arguments (optional; any number may be allocated)
3869
3870 SP-(4*(N+9)) arg word N
3871 : :
3872 SP-56 arg word 5
3873 SP-52 arg word 4
3874
3875 Fixed arguments (must be allocated; may remain unused)
3876
3877 SP-48 arg word 3
3878 SP-44 arg word 2
3879 SP-40 arg word 1
3880 SP-36 arg word 0
3881
3882 Frame Marker
3883
3884 SP-32 External Data Pointer (DP)
3885 SP-28 External sr4
3886 SP-24 External/stub RP (RP')
3887 SP-20 Current RP
3888 SP-16 Static Link
3889 SP-12 Clean up
3890 SP-8 Calling Stub RP (RP'')
3891 SP-4 Previous SP
3892
3893 Top of Frame
3894
3895 SP-0 Stack Pointer (points to next available address)
3896
3897 */
3898
3899 /* This function saves registers as follows. Registers marked with ' are
3900 this function's registers (as opposed to the previous function's).
3901 If a frame_pointer isn't needed, r4 is saved as a general register;
3902 the space for the frame pointer is still allocated, though, to keep
3903 things simple.
3904
3905
3906 Top of Frame
3907
3908 SP (FP') Previous FP
3909 SP + 4 Alignment filler (sigh)
3910 SP + 8 Space for locals reserved here.
3911 .
3912 .
3913 .
3914 SP + n All call saved register used.
3915 .
3916 .
3917 .
3918 SP + o All call saved fp registers used.
3919 .
3920 .
3921 .
3922 SP + p (SP') points to next available address.
3923
3924 */
3925
3926 /* Global variables set by output_function_prologue(). */
3927 /* Size of frame. Need to know this to emit return insns from
3928 leaf procedures. */
3929 static HOST_WIDE_INT actual_fsize, local_fsize;
3930 static int save_fregs;
3931
3932 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3933 Handle case where DISP > 8k by using the add_high_const patterns.
3934
3935 Note in DISP > 8k case, we will leave the high part of the address
3936 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3937
3938 static void
3939 store_reg (int reg, HOST_WIDE_INT disp, int base)
3940 {
3941 rtx dest, src, basereg;
3942 rtx_insn *insn;
3943
3944 src = gen_rtx_REG (word_mode, reg);
3945 basereg = gen_rtx_REG (Pmode, base);
3946 if (VAL_14_BITS_P (disp))
3947 {
3948 dest = gen_rtx_MEM (word_mode, plus_constant (Pmode, basereg, disp));
3949 insn = emit_move_insn (dest, src);
3950 }
3951 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3952 {
3953 rtx delta = GEN_INT (disp);
3954 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3955
3956 emit_move_insn (tmpreg, delta);
3957 insn = emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3958 if (DO_FRAME_NOTES)
3959 {
3960 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
3961 gen_rtx_SET (tmpreg,
3962 gen_rtx_PLUS (Pmode, basereg, delta)));
3963 RTX_FRAME_RELATED_P (insn) = 1;
3964 }
3965 dest = gen_rtx_MEM (word_mode, tmpreg);
3966 insn = emit_move_insn (dest, src);
3967 }
3968 else
3969 {
3970 rtx delta = GEN_INT (disp);
3971 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3972 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3973
3974 emit_move_insn (tmpreg, high);
3975 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3976 insn = emit_move_insn (dest, src);
3977 if (DO_FRAME_NOTES)
3978 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
3979 gen_rtx_SET (gen_rtx_MEM (word_mode,
3980 gen_rtx_PLUS (word_mode,
3981 basereg,
3982 delta)),
3983 src));
3984 }
3985
3986 if (DO_FRAME_NOTES)
3987 RTX_FRAME_RELATED_P (insn) = 1;
3988 }
3989
3990 /* Emit RTL to store REG at the memory location specified by BASE and then
3991 add MOD to BASE. MOD must be <= 8k. */
3992
3993 static void
3994 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3995 {
3996 rtx basereg, srcreg, delta;
3997 rtx_insn *insn;
3998
3999 gcc_assert (VAL_14_BITS_P (mod));
4000
4001 basereg = gen_rtx_REG (Pmode, base);
4002 srcreg = gen_rtx_REG (word_mode, reg);
4003 delta = GEN_INT (mod);
4004
4005 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
4006 if (DO_FRAME_NOTES)
4007 {
4008 RTX_FRAME_RELATED_P (insn) = 1;
4009
4010 /* RTX_FRAME_RELATED_P must be set on each frame related set
4011 in a parallel with more than one element. */
4012 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
4013 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
4014 }
4015 }
4016
4017 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
4018 where DISP > 8k by using the add_high_const patterns. NOTE indicates
4019 whether to add a frame note or not.
4020
4021 In the DISP > 8k case, we leave the high part of the address in %r1.
4022 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
4023
4024 static void
4025 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
4026 {
4027 rtx_insn *insn;
4028
4029 if (VAL_14_BITS_P (disp))
4030 {
4031 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
4032 plus_constant (Pmode,
4033 gen_rtx_REG (Pmode, base), disp));
4034 }
4035 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
4036 {
4037 rtx basereg = gen_rtx_REG (Pmode, base);
4038 rtx delta = GEN_INT (disp);
4039 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4040
4041 emit_move_insn (tmpreg, delta);
4042 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
4043 gen_rtx_PLUS (Pmode, tmpreg, basereg));
4044 if (DO_FRAME_NOTES)
4045 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
4046 gen_rtx_SET (tmpreg,
4047 gen_rtx_PLUS (Pmode, basereg, delta)));
4048 }
4049 else
4050 {
4051 rtx basereg = gen_rtx_REG (Pmode, base);
4052 rtx delta = GEN_INT (disp);
4053 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4054
4055 emit_move_insn (tmpreg,
4056 gen_rtx_PLUS (Pmode, basereg,
4057 gen_rtx_HIGH (Pmode, delta)));
4058 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
4059 gen_rtx_LO_SUM (Pmode, tmpreg, delta));
4060 }
4061
4062 if (DO_FRAME_NOTES && note)
4063 RTX_FRAME_RELATED_P (insn) = 1;
4064 }
4065
4066 HOST_WIDE_INT
4067 pa_compute_frame_size (poly_int64 size, int *fregs_live)
4068 {
4069 int freg_saved = 0;
4070 int i, j;
4071
4072 /* The code in pa_expand_prologue and pa_expand_epilogue must
4073 be consistent with the rounding and size calculation done here.
4074 Change them at the same time. */
4075
4076 /* We do our own stack alignment. First, round the size of the
4077 stack locals up to a word boundary. */
4078 size = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
4079
4080 /* Space for previous frame pointer + filler. If any frame is
4081 allocated, we need to add in the TARGET_STARTING_FRAME_OFFSET. We
4082 waste some space here for the sake of HP compatibility. The
4083 first slot is only used when the frame pointer is needed. */
4084 if (size || frame_pointer_needed)
4085 size += pa_starting_frame_offset ();
4086
4087 /* If the current function calls __builtin_eh_return, then we need
4088 to allocate stack space for registers that will hold data for
4089 the exception handler. */
4090 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4091 {
4092 unsigned int i;
4093
4094 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
4095 continue;
4096 size += i * UNITS_PER_WORD;
4097 }
4098
4099 /* Account for space used by the callee general register saves. */
4100 for (i = 18, j = frame_pointer_needed ? 4 : 3; i >= j; i--)
4101 if (df_regs_ever_live_p (i))
4102 size += UNITS_PER_WORD;
4103
4104 /* Account for space used by the callee floating point register saves. */
4105 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4106 if (df_regs_ever_live_p (i)
4107 || (!TARGET_64BIT && df_regs_ever_live_p (i + 1)))
4108 {
4109 freg_saved = 1;
4110
4111 /* We always save both halves of the FP register, so always
4112 increment the frame size by 8 bytes. */
4113 size += 8;
4114 }
4115
4116 /* If any of the floating registers are saved, account for the
4117 alignment needed for the floating point register save block. */
4118 if (freg_saved)
4119 {
4120 size = (size + 7) & ~7;
4121 if (fregs_live)
4122 *fregs_live = 1;
4123 }
4124
4125 /* The various ABIs include space for the outgoing parameters in the
4126 size of the current function's stack frame. We don't need to align
4127 for the outgoing arguments as their alignment is set by the final
4128 rounding for the frame as a whole. */
4129 size += crtl->outgoing_args_size;
4130
4131 /* Allocate space for the fixed frame marker. This space must be
4132 allocated for any function that makes calls or allocates
4133 stack space. */
4134 if (!crtl->is_leaf || size)
4135 size += TARGET_64BIT ? 48 : 32;
4136
4137 /* Finally, round to the preferred stack boundary. */
4138 return ((size + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)
4139 & ~(PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1));
4140 }
4141
4142 /* Output function label, and associated .PROC and .CALLINFO statements. */
4143
4144 void
4145 pa_output_function_label (FILE *file)
4146 {
4147 /* The function's label and associated .PROC must never be
4148 separated and must be output *after* any profiling declarations
4149 to avoid changing spaces/subspaces within a procedure. */
4150 const char *name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
4151 ASM_OUTPUT_FUNCTION_LABEL (file, name, current_function_decl);
4152 fputs ("\t.PROC\n", file);
4153
4154 /* pa_expand_prologue does the dirty work now. We just need
4155 to output the assembler directives which denote the start
4156 of a function. */
4157 fprintf (file, "\t.CALLINFO FRAME=" HOST_WIDE_INT_PRINT_DEC, actual_fsize);
4158 if (crtl->is_leaf)
4159 fputs (",NO_CALLS", file);
4160 else
4161 fputs (",CALLS", file);
4162 if (rp_saved)
4163 fputs (",SAVE_RP", file);
4164
4165 /* The SAVE_SP flag is used to indicate that register %r3 is stored
4166 at the beginning of the frame and that it is used as the frame
4167 pointer for the frame. We do this because our current frame
4168 layout doesn't conform to that specified in the HP runtime
4169 documentation and we need a way to indicate to programs such as
4170 GDB where %r3 is saved. The SAVE_SP flag was chosen because it
4171 isn't used by HP compilers but is supported by the assembler.
4172 However, SAVE_SP is supposed to indicate that the previous stack
4173 pointer has been saved in the frame marker. */
4174 if (frame_pointer_needed)
4175 fputs (",SAVE_SP", file);
4176
4177 /* Pass on information about the number of callee register saves
4178 performed in the prologue.
4179
4180 The compiler is supposed to pass the highest register number
4181 saved, the assembler then has to adjust that number before
4182 entering it into the unwind descriptor (to account for any
4183 caller saved registers with lower register numbers than the
4184 first callee saved register). */
4185 if (gr_saved)
4186 fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
4187
4188 if (fr_saved)
4189 fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
4190
4191 fputs ("\n\t.ENTRY\n", file);
4192 }
4193
4194 /* Output function prologue. */
4195
4196 static void
4197 pa_output_function_prologue (FILE *file)
4198 {
4199 pa_output_function_label (file);
4200 remove_useless_addtr_insns (0);
4201 }
4202
4203 /* The label is output by ASM_DECLARE_FUNCTION_NAME on linux. */
4204
4205 static void
4206 pa_linux_output_function_prologue (FILE *file ATTRIBUTE_UNUSED)
4207 {
4208 remove_useless_addtr_insns (0);
4209 }
4210
4211 void
4212 pa_expand_prologue (void)
4213 {
4214 int merge_sp_adjust_with_store = 0;
4215 HOST_WIDE_INT size = get_frame_size ();
4216 HOST_WIDE_INT offset;
4217 int i;
4218 rtx tmpreg;
4219 rtx_insn *insn;
4220
4221 gr_saved = 0;
4222 fr_saved = 0;
4223 save_fregs = 0;
4224
4225 /* Compute total size for frame pointer, filler, locals and rounding to
4226 the next word boundary. Similar code appears in pa_compute_frame_size
4227 and must be changed in tandem with this code. */
4228 local_fsize = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
4229 if (local_fsize || frame_pointer_needed)
4230 local_fsize += pa_starting_frame_offset ();
4231
4232 actual_fsize = pa_compute_frame_size (size, &save_fregs);
4233 if (flag_stack_usage_info)
4234 current_function_static_stack_size = actual_fsize;
4235
4236 /* Compute a few things we will use often. */
4237 tmpreg = gen_rtx_REG (word_mode, 1);
4238
4239 /* Save RP first. The calling conventions manual states RP will
4240 always be stored into the caller's frame at sp - 20 or sp - 16
4241 depending on which ABI is in use. */
4242 if (df_regs_ever_live_p (2) || crtl->calls_eh_return)
4243 {
4244 store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM);
4245 rp_saved = true;
4246 }
4247 else
4248 rp_saved = false;
4249
4250 /* Allocate the local frame and set up the frame pointer if needed. */
4251 if (actual_fsize != 0)
4252 {
4253 if (frame_pointer_needed)
4254 {
4255 /* Copy the old frame pointer temporarily into %r1. Set up the
4256 new stack pointer, then store away the saved old frame pointer
4257 into the stack at sp and at the same time update the stack
4258 pointer by actual_fsize bytes. Two versions, first
4259 handles small (<8k) frames. The second handles large (>=8k)
4260 frames. */
4261 insn = emit_move_insn (tmpreg, hard_frame_pointer_rtx);
4262 if (DO_FRAME_NOTES)
4263 RTX_FRAME_RELATED_P (insn) = 1;
4264
4265 insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
4266 if (DO_FRAME_NOTES)
4267 RTX_FRAME_RELATED_P (insn) = 1;
4268
4269 if (VAL_14_BITS_P (actual_fsize))
4270 store_reg_modify (STACK_POINTER_REGNUM, 1, actual_fsize);
4271 else
4272 {
4273 /* It is incorrect to store the saved frame pointer at *sp,
4274 then increment sp (writes beyond the current stack boundary).
4275
4276 So instead use stwm to store at *sp and post-increment the
4277 stack pointer as an atomic operation. Then increment sp to
4278 finish allocating the new frame. */
4279 HOST_WIDE_INT adjust1 = 8192 - 64;
4280 HOST_WIDE_INT adjust2 = actual_fsize - adjust1;
4281
4282 store_reg_modify (STACK_POINTER_REGNUM, 1, adjust1);
4283 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4284 adjust2, 1);
4285 }
4286
4287 /* We set SAVE_SP in frames that need a frame pointer. Thus,
4288 we need to store the previous stack pointer (frame pointer)
4289 into the frame marker on targets that use the HP unwind
4290 library. This allows the HP unwind library to be used to
4291 unwind GCC frames. However, we are not fully compatible
4292 with the HP library because our frame layout differs from
4293 that specified in the HP runtime specification.
4294
4295 We don't want a frame note on this instruction as the frame
4296 marker moves during dynamic stack allocation.
4297
4298 This instruction also serves as a blockage to prevent
4299 register spills from being scheduled before the stack
4300 pointer is raised. This is necessary as we store
4301 registers using the frame pointer as a base register,
4302 and the frame pointer is set before sp is raised. */
4303 if (TARGET_HPUX_UNWIND_LIBRARY)
4304 {
4305 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx,
4306 GEN_INT (TARGET_64BIT ? -8 : -4));
4307
4308 emit_move_insn (gen_rtx_MEM (word_mode, addr),
4309 hard_frame_pointer_rtx);
4310 }
4311 else
4312 emit_insn (gen_blockage ());
4313 }
4314 /* no frame pointer needed. */
4315 else
4316 {
4317 /* In some cases we can perform the first callee register save
4318 and allocating the stack frame at the same time. If so, just
4319 make a note of it and defer allocating the frame until saving
4320 the callee registers. */
4321 if (VAL_14_BITS_P (actual_fsize) && local_fsize == 0)
4322 merge_sp_adjust_with_store = 1;
4323 /* Cannot optimize. Adjust the stack frame by actual_fsize
4324 bytes. */
4325 else
4326 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4327 actual_fsize, 1);
4328 }
4329 }
4330
4331 /* Normal register save.
4332
4333 Do not save the frame pointer in the frame_pointer_needed case. It
4334 was done earlier. */
4335 if (frame_pointer_needed)
4336 {
4337 offset = local_fsize;
4338
4339 /* Saving the EH return data registers in the frame is the simplest
4340 way to get the frame unwind information emitted. We put them
4341 just before the general registers. */
4342 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4343 {
4344 unsigned int i, regno;
4345
4346 for (i = 0; ; ++i)
4347 {
4348 regno = EH_RETURN_DATA_REGNO (i);
4349 if (regno == INVALID_REGNUM)
4350 break;
4351
4352 store_reg (regno, offset, HARD_FRAME_POINTER_REGNUM);
4353 offset += UNITS_PER_WORD;
4354 }
4355 }
4356
4357 for (i = 18; i >= 4; i--)
4358 if (df_regs_ever_live_p (i) && !call_used_or_fixed_reg_p (i))
4359 {
4360 store_reg (i, offset, HARD_FRAME_POINTER_REGNUM);
4361 offset += UNITS_PER_WORD;
4362 gr_saved++;
4363 }
4364 /* Account for %r3 which is saved in a special place. */
4365 gr_saved++;
4366 }
4367 /* No frame pointer needed. */
4368 else
4369 {
4370 offset = local_fsize - actual_fsize;
4371
4372 /* Saving the EH return data registers in the frame is the simplest
4373 way to get the frame unwind information emitted. */
4374 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4375 {
4376 unsigned int i, regno;
4377
4378 for (i = 0; ; ++i)
4379 {
4380 regno = EH_RETURN_DATA_REGNO (i);
4381 if (regno == INVALID_REGNUM)
4382 break;
4383
4384 /* If merge_sp_adjust_with_store is nonzero, then we can
4385 optimize the first save. */
4386 if (merge_sp_adjust_with_store)
4387 {
4388 store_reg_modify (STACK_POINTER_REGNUM, regno, -offset);
4389 merge_sp_adjust_with_store = 0;
4390 }
4391 else
4392 store_reg (regno, offset, STACK_POINTER_REGNUM);
4393 offset += UNITS_PER_WORD;
4394 }
4395 }
4396
4397 for (i = 18; i >= 3; i--)
4398 if (df_regs_ever_live_p (i) && !call_used_or_fixed_reg_p (i))
4399 {
4400 /* If merge_sp_adjust_with_store is nonzero, then we can
4401 optimize the first GR save. */
4402 if (merge_sp_adjust_with_store)
4403 {
4404 store_reg_modify (STACK_POINTER_REGNUM, i, -offset);
4405 merge_sp_adjust_with_store = 0;
4406 }
4407 else
4408 store_reg (i, offset, STACK_POINTER_REGNUM);
4409 offset += UNITS_PER_WORD;
4410 gr_saved++;
4411 }
4412
4413 /* If we wanted to merge the SP adjustment with a GR save, but we never
4414 did any GR saves, then just emit the adjustment here. */
4415 if (merge_sp_adjust_with_store)
4416 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4417 actual_fsize, 1);
4418 }
4419
4420 /* The hppa calling conventions say that %r19, the pic offset
4421 register, is saved at sp - 32 (in this function's frame)
4422 when generating PIC code. FIXME: What is the correct thing
4423 to do for functions which make no calls and allocate no
4424 frame? Do we need to allocate a frame, or can we just omit
4425 the save? For now we'll just omit the save.
4426
4427 We don't want a note on this insn as the frame marker can
4428 move if there is a dynamic stack allocation. */
4429 if (flag_pic && actual_fsize != 0 && !TARGET_64BIT)
4430 {
4431 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx, GEN_INT (-32));
4432
4433 emit_move_insn (gen_rtx_MEM (word_mode, addr), pic_offset_table_rtx);
4434
4435 }
4436
4437 /* Align pointer properly (doubleword boundary). */
4438 offset = (offset + 7) & ~7;
4439
4440 /* Floating point register store. */
4441 if (save_fregs)
4442 {
4443 rtx base;
4444
4445 /* First get the frame or stack pointer to the start of the FP register
4446 save area. */
4447 if (frame_pointer_needed)
4448 {
4449 set_reg_plus_d (1, HARD_FRAME_POINTER_REGNUM, offset, 0);
4450 base = hard_frame_pointer_rtx;
4451 }
4452 else
4453 {
4454 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4455 base = stack_pointer_rtx;
4456 }
4457
4458 /* Now actually save the FP registers. */
4459 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4460 {
4461 if (df_regs_ever_live_p (i)
4462 || (! TARGET_64BIT && df_regs_ever_live_p (i + 1)))
4463 {
4464 rtx addr, reg;
4465 rtx_insn *insn;
4466 addr = gen_rtx_MEM (DFmode,
4467 gen_rtx_POST_INC (word_mode, tmpreg));
4468 reg = gen_rtx_REG (DFmode, i);
4469 insn = emit_move_insn (addr, reg);
4470 if (DO_FRAME_NOTES)
4471 {
4472 RTX_FRAME_RELATED_P (insn) = 1;
4473 if (TARGET_64BIT)
4474 {
4475 rtx mem = gen_rtx_MEM (DFmode,
4476 plus_constant (Pmode, base,
4477 offset));
4478 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
4479 gen_rtx_SET (mem, reg));
4480 }
4481 else
4482 {
4483 rtx meml = gen_rtx_MEM (SFmode,
4484 plus_constant (Pmode, base,
4485 offset));
4486 rtx memr = gen_rtx_MEM (SFmode,
4487 plus_constant (Pmode, base,
4488 offset + 4));
4489 rtx regl = gen_rtx_REG (SFmode, i);
4490 rtx regr = gen_rtx_REG (SFmode, i + 1);
4491 rtx setl = gen_rtx_SET (meml, regl);
4492 rtx setr = gen_rtx_SET (memr, regr);
4493 rtvec vec;
4494
4495 RTX_FRAME_RELATED_P (setl) = 1;
4496 RTX_FRAME_RELATED_P (setr) = 1;
4497 vec = gen_rtvec (2, setl, setr);
4498 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
4499 gen_rtx_SEQUENCE (VOIDmode, vec));
4500 }
4501 }
4502 offset += GET_MODE_SIZE (DFmode);
4503 fr_saved++;
4504 }
4505 }
4506 }
4507 }
4508
4509 /* Emit RTL to load REG from the memory location specified by BASE+DISP.
4510 Handle case where DISP > 8k by using the add_high_const patterns. */
4511
4512 static void
4513 load_reg (int reg, HOST_WIDE_INT disp, int base)
4514 {
4515 rtx dest = gen_rtx_REG (word_mode, reg);
4516 rtx basereg = gen_rtx_REG (Pmode, base);
4517 rtx src;
4518
4519 if (VAL_14_BITS_P (disp))
4520 src = gen_rtx_MEM (word_mode, plus_constant (Pmode, basereg, disp));
4521 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
4522 {
4523 rtx delta = GEN_INT (disp);
4524 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4525
4526 emit_move_insn (tmpreg, delta);
4527 if (!TARGET_NO_SPACE_REGS || TARGET_DISABLE_INDEXING)
4528 {
4529 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4530 src = gen_rtx_MEM (word_mode, tmpreg);
4531 }
4532 else
4533 src = gen_rtx_MEM (word_mode, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4534 }
4535 else
4536 {
4537 rtx delta = GEN_INT (disp);
4538 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
4539 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4540
4541 emit_move_insn (tmpreg, high);
4542 src = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
4543 }
4544
4545 emit_move_insn (dest, src);
4546 }
4547
4548 /* Update the total code bytes output to the text section. */
4549
4550 static void
4551 update_total_code_bytes (unsigned int nbytes)
4552 {
4553 if ((TARGET_PORTABLE_RUNTIME || !TARGET_GAS || !TARGET_SOM)
4554 && !IN_NAMED_SECTION_P (cfun->decl))
4555 {
4556 unsigned int old_total = total_code_bytes;
4557
4558 total_code_bytes += nbytes;
4559
4560 /* Be prepared to handle overflows. */
4561 if (old_total > total_code_bytes)
4562 total_code_bytes = UINT_MAX;
4563 }
4564 }
4565
4566 /* This function generates the assembly code for function exit.
4567 Args are as for output_function_prologue ().
4568
4569 The function epilogue should not depend on the current stack
4570 pointer! It should use the frame pointer only. This is mandatory
4571 because of alloca; we also take advantage of it to omit stack
4572 adjustments before returning. */
4573
4574 static void
4575 pa_output_function_epilogue (FILE *file)
4576 {
4577 rtx_insn *insn = get_last_insn ();
4578 bool extra_nop;
4579
4580 /* pa_expand_epilogue does the dirty work now. We just need
4581 to output the assembler directives which denote the end
4582 of a function.
4583
4584 To make debuggers happy, emit a nop if the epilogue was completely
4585 eliminated due to a volatile call as the last insn in the
4586 current function. That way the return address (in %r2) will
4587 always point to a valid instruction in the current function. */
4588
4589 /* Get the last real insn. */
4590 if (NOTE_P (insn))
4591 insn = prev_real_insn (insn);
4592
4593 /* If it is a sequence, then look inside. */
4594 if (insn && NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
4595 insn = as_a <rtx_sequence *> (PATTERN (insn))-> insn (0);
4596
4597 /* If insn is a CALL_INSN, then it must be a call to a volatile
4598 function (otherwise there would be epilogue insns). */
4599 if (insn && CALL_P (insn))
4600 {
4601 fputs ("\tnop\n", file);
4602 extra_nop = true;
4603 }
4604 else
4605 extra_nop = false;
4606
4607 fputs ("\t.EXIT\n\t.PROCEND\n", file);
4608
4609 if (TARGET_SOM && TARGET_GAS)
4610 {
4611 /* We are done with this subspace except possibly for some additional
4612 debug information. Forget that we are in this subspace to ensure
4613 that the next function is output in its own subspace. */
4614 in_section = NULL;
4615 cfun->machine->in_nsubspa = 2;
4616 }
4617
4618 /* Thunks do their own insn accounting. */
4619 if (cfun->is_thunk)
4620 return;
4621
4622 if (INSN_ADDRESSES_SET_P ())
4623 {
4624 last_address = extra_nop ? 4 : 0;
4625 insn = get_last_nonnote_insn ();
4626 if (insn)
4627 {
4628 last_address += INSN_ADDRESSES (INSN_UID (insn));
4629 if (INSN_P (insn))
4630 last_address += insn_default_length (insn);
4631 }
4632 last_address = ((last_address + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
4633 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
4634 }
4635 else
4636 last_address = UINT_MAX;
4637
4638 /* Finally, update the total number of code bytes output so far. */
4639 update_total_code_bytes (last_address);
4640 }
4641
4642 void
4643 pa_expand_epilogue (void)
4644 {
4645 rtx tmpreg;
4646 HOST_WIDE_INT offset;
4647 HOST_WIDE_INT ret_off = 0;
4648 int i;
4649 int merge_sp_adjust_with_load = 0;
4650
4651 /* We will use this often. */
4652 tmpreg = gen_rtx_REG (word_mode, 1);
4653
4654 /* Try to restore RP early to avoid load/use interlocks when
4655 RP gets used in the return (bv) instruction. This appears to still
4656 be necessary even when we schedule the prologue and epilogue. */
4657 if (rp_saved)
4658 {
4659 ret_off = TARGET_64BIT ? -16 : -20;
4660 if (frame_pointer_needed)
4661 {
4662 load_reg (2, ret_off, HARD_FRAME_POINTER_REGNUM);
4663 ret_off = 0;
4664 }
4665 else
4666 {
4667 /* No frame pointer, and stack is smaller than 8k. */
4668 if (VAL_14_BITS_P (ret_off - actual_fsize))
4669 {
4670 load_reg (2, ret_off - actual_fsize, STACK_POINTER_REGNUM);
4671 ret_off = 0;
4672 }
4673 }
4674 }
4675
4676 /* General register restores. */
4677 if (frame_pointer_needed)
4678 {
4679 offset = local_fsize;
4680
4681 /* If the current function calls __builtin_eh_return, then we need
4682 to restore the saved EH data registers. */
4683 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4684 {
4685 unsigned int i, regno;
4686
4687 for (i = 0; ; ++i)
4688 {
4689 regno = EH_RETURN_DATA_REGNO (i);
4690 if (regno == INVALID_REGNUM)
4691 break;
4692
4693 load_reg (regno, offset, HARD_FRAME_POINTER_REGNUM);
4694 offset += UNITS_PER_WORD;
4695 }
4696 }
4697
4698 for (i = 18; i >= 4; i--)
4699 if (df_regs_ever_live_p (i) && !call_used_or_fixed_reg_p (i))
4700 {
4701 load_reg (i, offset, HARD_FRAME_POINTER_REGNUM);
4702 offset += UNITS_PER_WORD;
4703 }
4704 }
4705 else
4706 {
4707 offset = local_fsize - actual_fsize;
4708
4709 /* If the current function calls __builtin_eh_return, then we need
4710 to restore the saved EH data registers. */
4711 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4712 {
4713 unsigned int i, regno;
4714
4715 for (i = 0; ; ++i)
4716 {
4717 regno = EH_RETURN_DATA_REGNO (i);
4718 if (regno == INVALID_REGNUM)
4719 break;
4720
4721 /* Only for the first load.
4722 merge_sp_adjust_with_load holds the register load
4723 with which we will merge the sp adjustment. */
4724 if (merge_sp_adjust_with_load == 0
4725 && local_fsize == 0
4726 && VAL_14_BITS_P (-actual_fsize))
4727 merge_sp_adjust_with_load = regno;
4728 else
4729 load_reg (regno, offset, STACK_POINTER_REGNUM);
4730 offset += UNITS_PER_WORD;
4731 }
4732 }
4733
4734 for (i = 18; i >= 3; i--)
4735 {
4736 if (df_regs_ever_live_p (i) && !call_used_or_fixed_reg_p (i))
4737 {
4738 /* Only for the first load.
4739 merge_sp_adjust_with_load holds the register load
4740 with which we will merge the sp adjustment. */
4741 if (merge_sp_adjust_with_load == 0
4742 && local_fsize == 0
4743 && VAL_14_BITS_P (-actual_fsize))
4744 merge_sp_adjust_with_load = i;
4745 else
4746 load_reg (i, offset, STACK_POINTER_REGNUM);
4747 offset += UNITS_PER_WORD;
4748 }
4749 }
4750 }
4751
4752 /* Align pointer properly (doubleword boundary). */
4753 offset = (offset + 7) & ~7;
4754
4755 /* FP register restores. */
4756 if (save_fregs)
4757 {
4758 /* Adjust the register to index off of. */
4759 if (frame_pointer_needed)
4760 set_reg_plus_d (1, HARD_FRAME_POINTER_REGNUM, offset, 0);
4761 else
4762 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4763
4764 /* Actually do the restores now. */
4765 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4766 if (df_regs_ever_live_p (i)
4767 || (! TARGET_64BIT && df_regs_ever_live_p (i + 1)))
4768 {
4769 rtx src = gen_rtx_MEM (DFmode,
4770 gen_rtx_POST_INC (word_mode, tmpreg));
4771 rtx dest = gen_rtx_REG (DFmode, i);
4772 emit_move_insn (dest, src);
4773 }
4774 }
4775
4776 /* Emit a blockage insn here to keep these insns from being moved to
4777 an earlier spot in the epilogue, or into the main instruction stream.
4778
4779 This is necessary as we must not cut the stack back before all the
4780 restores are finished. */
4781 emit_insn (gen_blockage ());
4782
4783 /* Reset stack pointer (and possibly frame pointer). The stack
4784 pointer is initially set to fp + 64 to avoid a race condition. */
4785 if (frame_pointer_needed)
4786 {
4787 rtx delta = GEN_INT (-64);
4788
4789 set_reg_plus_d (STACK_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM, 64, 0);
4790 emit_insn (gen_pre_load (hard_frame_pointer_rtx,
4791 stack_pointer_rtx, delta));
4792 }
4793 /* If we were deferring a callee register restore, do it now. */
4794 else if (merge_sp_adjust_with_load)
4795 {
4796 rtx delta = GEN_INT (-actual_fsize);
4797 rtx dest = gen_rtx_REG (word_mode, merge_sp_adjust_with_load);
4798
4799 emit_insn (gen_pre_load (dest, stack_pointer_rtx, delta));
4800 }
4801 else if (actual_fsize != 0)
4802 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4803 - actual_fsize, 0);
4804
4805 /* If we haven't restored %r2 yet (no frame pointer, and a stack
4806 frame greater than 8k), do so now. */
4807 if (ret_off != 0)
4808 load_reg (2, ret_off, STACK_POINTER_REGNUM);
4809
4810 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4811 {
4812 rtx sa = EH_RETURN_STACKADJ_RTX;
4813
4814 emit_insn (gen_blockage ());
4815 emit_insn (TARGET_64BIT
4816 ? gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, sa)
4817 : gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, sa));
4818 }
4819 }
4820
4821 bool
4822 pa_can_use_return_insn (void)
4823 {
4824 if (!reload_completed)
4825 return false;
4826
4827 if (frame_pointer_needed)
4828 return false;
4829
4830 if (df_regs_ever_live_p (2))
4831 return false;
4832
4833 if (crtl->profile)
4834 return false;
4835
4836 return pa_compute_frame_size (get_frame_size (), 0) == 0;
4837 }
4838
4839 rtx
4840 hppa_pic_save_rtx (void)
4841 {
4842 return get_hard_reg_initial_val (word_mode, PIC_OFFSET_TABLE_REGNUM);
4843 }
4844
4845 #ifndef NO_DEFERRED_PROFILE_COUNTERS
4846 #define NO_DEFERRED_PROFILE_COUNTERS 0
4847 #endif
4848
4849
4850 /* Vector of funcdef numbers. */
4851 static vec<int> funcdef_nos;
4852
4853 /* Output deferred profile counters. */
4854 static void
4855 output_deferred_profile_counters (void)
4856 {
4857 unsigned int i;
4858 int align, n;
4859
4860 if (funcdef_nos.is_empty ())
4861 return;
4862
4863 switch_to_section (data_section);
4864 align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
4865 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
4866
4867 for (i = 0; funcdef_nos.iterate (i, &n); i++)
4868 {
4869 targetm.asm_out.internal_label (asm_out_file, "LP", n);
4870 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, align, 1);
4871 }
4872
4873 funcdef_nos.release ();
4874 }
4875
4876 void
4877 hppa_profile_hook (int label_no)
4878 {
4879 rtx_code_label *label_rtx = gen_label_rtx ();
4880 int reg_parm_stack_space = REG_PARM_STACK_SPACE (NULL_TREE);
4881 rtx arg_bytes, begin_label_rtx, mcount, sym;
4882 rtx_insn *call_insn;
4883 char begin_label_name[16];
4884 bool use_mcount_pcrel_call;
4885
4886 /* Set up call destination. */
4887 sym = gen_rtx_SYMBOL_REF (Pmode, "_mcount");
4888 pa_encode_label (sym);
4889 mcount = gen_rtx_MEM (Pmode, sym);
4890
4891 /* If we can reach _mcount with a pc-relative call, we can optimize
4892 loading the address of the current function. This requires linker
4893 long branch stub support. */
4894 if (!TARGET_PORTABLE_RUNTIME
4895 && !TARGET_LONG_CALLS
4896 && (TARGET_SOM || flag_function_sections))
4897 use_mcount_pcrel_call = TRUE;
4898 else
4899 use_mcount_pcrel_call = FALSE;
4900
4901 ASM_GENERATE_INTERNAL_LABEL (begin_label_name, FUNC_BEGIN_PROLOG_LABEL,
4902 label_no);
4903 begin_label_rtx = gen_rtx_SYMBOL_REF (SImode, ggc_strdup (begin_label_name));
4904
4905 emit_move_insn (gen_rtx_REG (word_mode, 26), gen_rtx_REG (word_mode, 2));
4906
4907 if (!use_mcount_pcrel_call)
4908 {
4909 /* The address of the function is loaded into %r25 with an instruction-
4910 relative sequence that avoids the use of relocations. We use SImode
4911 for the address of the function in both 32 and 64-bit code to avoid
4912 having to provide DImode versions of the lcla2 pattern. */
4913 if (TARGET_PA_20)
4914 emit_insn (gen_lcla2 (gen_rtx_REG (SImode, 25), label_rtx));
4915 else
4916 emit_insn (gen_lcla1 (gen_rtx_REG (SImode, 25), label_rtx));
4917 }
4918
4919 if (!NO_DEFERRED_PROFILE_COUNTERS)
4920 {
4921 rtx count_label_rtx, addr, r24;
4922 char count_label_name[16];
4923
4924 funcdef_nos.safe_push (label_no);
4925 ASM_GENERATE_INTERNAL_LABEL (count_label_name, "LP", label_no);
4926 count_label_rtx = gen_rtx_SYMBOL_REF (Pmode,
4927 ggc_strdup (count_label_name));
4928
4929 addr = force_reg (Pmode, count_label_rtx);
4930 r24 = gen_rtx_REG (Pmode, 24);
4931 emit_move_insn (r24, addr);
4932
4933 arg_bytes = GEN_INT (TARGET_64BIT ? 24 : 12);
4934 if (use_mcount_pcrel_call)
4935 call_insn = emit_call_insn (gen_call_mcount (mcount, arg_bytes,
4936 begin_label_rtx));
4937 else
4938 call_insn = emit_call_insn (gen_call (mcount, arg_bytes));
4939
4940 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), r24);
4941 }
4942 else
4943 {
4944 arg_bytes = GEN_INT (TARGET_64BIT ? 16 : 8);
4945 if (use_mcount_pcrel_call)
4946 call_insn = emit_call_insn (gen_call_mcount (mcount, arg_bytes,
4947 begin_label_rtx));
4948 else
4949 call_insn = emit_call_insn (gen_call (mcount, arg_bytes));
4950 }
4951
4952 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 25));
4953 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 26));
4954
4955 /* Indicate the _mcount call cannot throw, nor will it execute a
4956 non-local goto. */
4957 make_reg_eh_region_note_nothrow_nononlocal (call_insn);
4958
4959 /* Allocate space for fixed arguments. */
4960 if (reg_parm_stack_space > crtl->outgoing_args_size)
4961 crtl->outgoing_args_size = reg_parm_stack_space;
4962 }
4963
4964 /* Fetch the return address for the frame COUNT steps up from
4965 the current frame, after the prologue. FRAMEADDR is the
4966 frame pointer of the COUNT frame.
4967
4968 We want to ignore any export stub remnants here. To handle this,
4969 we examine the code at the return address, and if it is an export
4970 stub, we return a memory rtx for the stub return address stored
4971 at frame-24.
4972
4973 The value returned is used in two different ways:
4974
4975 1. To find a function's caller.
4976
4977 2. To change the return address for a function.
4978
4979 This function handles most instances of case 1; however, it will
4980 fail if there are two levels of stubs to execute on the return
4981 path. The only way I believe that can happen is if the return value
4982 needs a parameter relocation, which never happens for C code.
4983
4984 This function handles most instances of case 2; however, it will
4985 fail if we did not originally have stub code on the return path
4986 but will need stub code on the new return path. This can happen if
4987 the caller & callee are both in the main program, but the new
4988 return location is in a shared library. */
4989
4990 rtx
4991 pa_return_addr_rtx (int count, rtx frameaddr)
4992 {
4993 rtx label;
4994 rtx rp;
4995 rtx saved_rp;
4996 rtx ins;
4997
4998 /* The instruction stream at the return address of a PA1.X export stub is:
4999
5000 0x4bc23fd1 | stub+8: ldw -18(sr0,sp),rp
5001 0x004010a1 | stub+12: ldsid (sr0,rp),r1
5002 0x00011820 | stub+16: mtsp r1,sr0
5003 0xe0400002 | stub+20: be,n 0(sr0,rp)
5004
5005 0xe0400002 must be specified as -532676606 so that it won't be
5006 rejected as an invalid immediate operand on 64-bit hosts.
5007
5008 The instruction stream at the return address of a PA2.0 export stub is:
5009
5010 0x4bc23fd1 | stub+8: ldw -18(sr0,sp),rp
5011 0xe840d002 | stub+12: bve,n (rp)
5012 */
5013
5014 HOST_WIDE_INT insns[4];
5015 int i, len;
5016
5017 if (count != 0)
5018 return NULL_RTX;
5019
5020 rp = get_hard_reg_initial_val (Pmode, 2);
5021
5022 if (TARGET_64BIT || TARGET_NO_SPACE_REGS)
5023 return rp;
5024
5025 /* If there is no export stub then just use the value saved from
5026 the return pointer register. */
5027
5028 saved_rp = gen_reg_rtx (Pmode);
5029 emit_move_insn (saved_rp, rp);
5030
5031 /* Get pointer to the instruction stream. We have to mask out the
5032 privilege level from the two low order bits of the return address
5033 pointer here so that ins will point to the start of the first
5034 instruction that would have been executed if we returned. */
5035 ins = copy_to_reg (gen_rtx_AND (Pmode, rp, MASK_RETURN_ADDR));
5036 label = gen_label_rtx ();
5037
5038 if (TARGET_PA_20)
5039 {
5040 insns[0] = 0x4bc23fd1;
5041 insns[1] = -398405630;
5042 len = 2;
5043 }
5044 else
5045 {
5046 insns[0] = 0x4bc23fd1;
5047 insns[1] = 0x004010a1;
5048 insns[2] = 0x00011820;
5049 insns[3] = -532676606;
5050 len = 4;
5051 }
5052
5053 /* Check the instruction stream at the normal return address for the
5054 export stub. If it is an export stub, than our return address is
5055 really in -24[frameaddr]. */
5056
5057 for (i = 0; i < len; i++)
5058 {
5059 rtx op0 = gen_rtx_MEM (SImode, plus_constant (Pmode, ins, i * 4));
5060 rtx op1 = GEN_INT (insns[i]);
5061 emit_cmp_and_jump_insns (op0, op1, NE, NULL, SImode, 0, label);
5062 }
5063
5064 /* Here we know that our return address points to an export
5065 stub. We don't want to return the address of the export stub,
5066 but rather the return address of the export stub. That return
5067 address is stored at -24[frameaddr]. */
5068
5069 emit_move_insn (saved_rp,
5070 gen_rtx_MEM (Pmode,
5071 memory_address (Pmode,
5072 plus_constant (Pmode, frameaddr,
5073 -24))));
5074
5075 emit_label (label);
5076
5077 return saved_rp;
5078 }
5079
5080 void
5081 pa_emit_bcond_fp (rtx operands[])
5082 {
5083 enum rtx_code code = GET_CODE (operands[0]);
5084 rtx operand0 = operands[1];
5085 rtx operand1 = operands[2];
5086 rtx label = operands[3];
5087
5088 emit_insn (gen_rtx_SET (gen_rtx_REG (CCFPmode, 0),
5089 gen_rtx_fmt_ee (code, CCFPmode, operand0, operand1)));
5090
5091 emit_jump_insn (gen_rtx_SET (pc_rtx,
5092 gen_rtx_IF_THEN_ELSE (VOIDmode,
5093 gen_rtx_fmt_ee (NE,
5094 VOIDmode,
5095 gen_rtx_REG (CCFPmode, 0),
5096 const0_rtx),
5097 gen_rtx_LABEL_REF (VOIDmode, label),
5098 pc_rtx)));
5099
5100 }
5101
5102 /* Adjust the cost of a scheduling dependency. Return the new cost of
5103 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
5104
5105 static int
5106 pa_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep_insn, int cost,
5107 unsigned int)
5108 {
5109 enum attr_type attr_type;
5110
5111 /* Don't adjust costs for a pa8000 chip, also do not adjust any
5112 true dependencies as they are described with bypasses now. */
5113 if (pa_cpu >= PROCESSOR_8000 || dep_type == 0)
5114 return cost;
5115
5116 if (! recog_memoized (insn))
5117 return 0;
5118
5119 attr_type = get_attr_type (insn);
5120
5121 switch (dep_type)
5122 {
5123 case REG_DEP_ANTI:
5124 /* Anti dependency; DEP_INSN reads a register that INSN writes some
5125 cycles later. */
5126
5127 if (attr_type == TYPE_FPLOAD)
5128 {
5129 rtx pat = PATTERN (insn);
5130 rtx dep_pat = PATTERN (dep_insn);
5131 if (GET_CODE (pat) == PARALLEL)
5132 {
5133 /* This happens for the fldXs,mb patterns. */
5134 pat = XVECEXP (pat, 0, 0);
5135 }
5136 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
5137 /* If this happens, we have to extend this to schedule
5138 optimally. Return 0 for now. */
5139 return 0;
5140
5141 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
5142 {
5143 if (! recog_memoized (dep_insn))
5144 return 0;
5145 switch (get_attr_type (dep_insn))
5146 {
5147 case TYPE_FPALU:
5148 case TYPE_FPMULSGL:
5149 case TYPE_FPMULDBL:
5150 case TYPE_FPDIVSGL:
5151 case TYPE_FPDIVDBL:
5152 case TYPE_FPSQRTSGL:
5153 case TYPE_FPSQRTDBL:
5154 /* A fpload can't be issued until one cycle before a
5155 preceding arithmetic operation has finished if
5156 the target of the fpload is any of the sources
5157 (or destination) of the arithmetic operation. */
5158 return insn_default_latency (dep_insn) - 1;
5159
5160 default:
5161 return 0;
5162 }
5163 }
5164 }
5165 else if (attr_type == TYPE_FPALU)
5166 {
5167 rtx pat = PATTERN (insn);
5168 rtx dep_pat = PATTERN (dep_insn);
5169 if (GET_CODE (pat) == PARALLEL)
5170 {
5171 /* This happens for the fldXs,mb patterns. */
5172 pat = XVECEXP (pat, 0, 0);
5173 }
5174 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
5175 /* If this happens, we have to extend this to schedule
5176 optimally. Return 0 for now. */
5177 return 0;
5178
5179 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
5180 {
5181 if (! recog_memoized (dep_insn))
5182 return 0;
5183 switch (get_attr_type (dep_insn))
5184 {
5185 case TYPE_FPDIVSGL:
5186 case TYPE_FPDIVDBL:
5187 case TYPE_FPSQRTSGL:
5188 case TYPE_FPSQRTDBL:
5189 /* An ALU flop can't be issued until two cycles before a
5190 preceding divide or sqrt operation has finished if
5191 the target of the ALU flop is any of the sources
5192 (or destination) of the divide or sqrt operation. */
5193 return insn_default_latency (dep_insn) - 2;
5194
5195 default:
5196 return 0;
5197 }
5198 }
5199 }
5200
5201 /* For other anti dependencies, the cost is 0. */
5202 return 0;
5203
5204 case REG_DEP_OUTPUT:
5205 /* Output dependency; DEP_INSN writes a register that INSN writes some
5206 cycles later. */
5207 if (attr_type == TYPE_FPLOAD)
5208 {
5209 rtx pat = PATTERN (insn);
5210 rtx dep_pat = PATTERN (dep_insn);
5211 if (GET_CODE (pat) == PARALLEL)
5212 {
5213 /* This happens for the fldXs,mb patterns. */
5214 pat = XVECEXP (pat, 0, 0);
5215 }
5216 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
5217 /* If this happens, we have to extend this to schedule
5218 optimally. Return 0 for now. */
5219 return 0;
5220
5221 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
5222 {
5223 if (! recog_memoized (dep_insn))
5224 return 0;
5225 switch (get_attr_type (dep_insn))
5226 {
5227 case TYPE_FPALU:
5228 case TYPE_FPMULSGL:
5229 case TYPE_FPMULDBL:
5230 case TYPE_FPDIVSGL:
5231 case TYPE_FPDIVDBL:
5232 case TYPE_FPSQRTSGL:
5233 case TYPE_FPSQRTDBL:
5234 /* A fpload can't be issued until one cycle before a
5235 preceding arithmetic operation has finished if
5236 the target of the fpload is the destination of the
5237 arithmetic operation.
5238
5239 Exception: For PA7100LC, PA7200 and PA7300, the cost
5240 is 3 cycles, unless they bundle together. We also
5241 pay the penalty if the second insn is a fpload. */
5242 return insn_default_latency (dep_insn) - 1;
5243
5244 default:
5245 return 0;
5246 }
5247 }
5248 }
5249 else if (attr_type == TYPE_FPALU)
5250 {
5251 rtx pat = PATTERN (insn);
5252 rtx dep_pat = PATTERN (dep_insn);
5253 if (GET_CODE (pat) == PARALLEL)
5254 {
5255 /* This happens for the fldXs,mb patterns. */
5256 pat = XVECEXP (pat, 0, 0);
5257 }
5258 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
5259 /* If this happens, we have to extend this to schedule
5260 optimally. Return 0 for now. */
5261 return 0;
5262
5263 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
5264 {
5265 if (! recog_memoized (dep_insn))
5266 return 0;
5267 switch (get_attr_type (dep_insn))
5268 {
5269 case TYPE_FPDIVSGL:
5270 case TYPE_FPDIVDBL:
5271 case TYPE_FPSQRTSGL:
5272 case TYPE_FPSQRTDBL:
5273 /* An ALU flop can't be issued until two cycles before a
5274 preceding divide or sqrt operation has finished if
5275 the target of the ALU flop is also the target of
5276 the divide or sqrt operation. */
5277 return insn_default_latency (dep_insn) - 2;
5278
5279 default:
5280 return 0;
5281 }
5282 }
5283 }
5284
5285 /* For other output dependencies, the cost is 0. */
5286 return 0;
5287
5288 default:
5289 gcc_unreachable ();
5290 }
5291 }
5292
5293 /* The 700 can only issue a single insn at a time.
5294 The 7XXX processors can issue two insns at a time.
5295 The 8000 can issue 4 insns at a time. */
5296 static int
5297 pa_issue_rate (void)
5298 {
5299 switch (pa_cpu)
5300 {
5301 case PROCESSOR_700: return 1;
5302 case PROCESSOR_7100: return 2;
5303 case PROCESSOR_7100LC: return 2;
5304 case PROCESSOR_7200: return 2;
5305 case PROCESSOR_7300: return 2;
5306 case PROCESSOR_8000: return 4;
5307
5308 default:
5309 gcc_unreachable ();
5310 }
5311 }
5312
5313
5314
5315 /* Return any length plus adjustment needed by INSN which already has
5316 its length computed as LENGTH. Return LENGTH if no adjustment is
5317 necessary.
5318
5319 Also compute the length of an inline block move here as it is too
5320 complicated to express as a length attribute in pa.md. */
5321 int
5322 pa_adjust_insn_length (rtx_insn *insn, int length)
5323 {
5324 rtx pat = PATTERN (insn);
5325
5326 /* If length is negative or undefined, provide initial length. */
5327 if ((unsigned int) length >= INT_MAX)
5328 {
5329 if (GET_CODE (pat) == SEQUENCE)
5330 insn = as_a <rtx_insn *> (XVECEXP (pat, 0, 0));
5331
5332 switch (get_attr_type (insn))
5333 {
5334 case TYPE_MILLI:
5335 length = pa_attr_length_millicode_call (insn);
5336 break;
5337 case TYPE_CALL:
5338 length = pa_attr_length_call (insn, 0);
5339 break;
5340 case TYPE_SIBCALL:
5341 length = pa_attr_length_call (insn, 1);
5342 break;
5343 case TYPE_DYNCALL:
5344 length = pa_attr_length_indirect_call (insn);
5345 break;
5346 case TYPE_SH_FUNC_ADRS:
5347 length = pa_attr_length_millicode_call (insn) + 20;
5348 break;
5349 default:
5350 gcc_unreachable ();
5351 }
5352 }
5353
5354 /* Block move pattern. */
5355 if (NONJUMP_INSN_P (insn)
5356 && GET_CODE (pat) == PARALLEL
5357 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
5358 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
5359 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 1)) == MEM
5360 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode
5361 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 1)) == BLKmode)
5362 length += compute_cpymem_length (insn) - 4;
5363 /* Block clear pattern. */
5364 else if (NONJUMP_INSN_P (insn)
5365 && GET_CODE (pat) == PARALLEL
5366 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
5367 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
5368 && XEXP (XVECEXP (pat, 0, 0), 1) == const0_rtx
5369 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode)
5370 length += compute_clrmem_length (insn) - 4;
5371 /* Conditional branch with an unfilled delay slot. */
5372 else if (JUMP_P (insn) && ! simplejump_p (insn))
5373 {
5374 /* Adjust a short backwards conditional with an unfilled delay slot. */
5375 if (GET_CODE (pat) == SET
5376 && length == 4
5377 && JUMP_LABEL (insn) != NULL_RTX
5378 && ! forward_branch_p (insn))
5379 length += 4;
5380 else if (GET_CODE (pat) == PARALLEL
5381 && get_attr_type (insn) == TYPE_PARALLEL_BRANCH
5382 && length == 4)
5383 length += 4;
5384 /* Adjust dbra insn with short backwards conditional branch with
5385 unfilled delay slot -- only for case where counter is in a
5386 general register register. */
5387 else if (GET_CODE (pat) == PARALLEL
5388 && GET_CODE (XVECEXP (pat, 0, 1)) == SET
5389 && GET_CODE (XEXP (XVECEXP (pat, 0, 1), 0)) == REG
5390 && ! FP_REG_P (XEXP (XVECEXP (pat, 0, 1), 0))
5391 && length == 4
5392 && ! forward_branch_p (insn))
5393 length += 4;
5394 }
5395 return length;
5396 }
5397
5398 /* Implement the TARGET_PRINT_OPERAND_PUNCT_VALID_P hook. */
5399
5400 static bool
5401 pa_print_operand_punct_valid_p (unsigned char code)
5402 {
5403 if (code == '@'
5404 || code == '#'
5405 || code == '*'
5406 || code == '^')
5407 return true;
5408
5409 return false;
5410 }
5411
5412 /* Print operand X (an rtx) in assembler syntax to file FILE.
5413 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
5414 For `%' followed by punctuation, CODE is the punctuation and X is null. */
5415
5416 void
5417 pa_print_operand (FILE *file, rtx x, int code)
5418 {
5419 switch (code)
5420 {
5421 case '#':
5422 /* Output a 'nop' if there's nothing for the delay slot. */
5423 if (dbr_sequence_length () == 0)
5424 fputs ("\n\tnop", file);
5425 return;
5426 case '*':
5427 /* Output a nullification completer if there's nothing for the */
5428 /* delay slot or nullification is requested. */
5429 if (dbr_sequence_length () == 0 ||
5430 (final_sequence &&
5431 INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))))
5432 fputs (",n", file);
5433 return;
5434 case 'R':
5435 /* Print out the second register name of a register pair.
5436 I.e., R (6) => 7. */
5437 fputs (reg_names[REGNO (x) + 1], file);
5438 return;
5439 case 'r':
5440 /* A register or zero. */
5441 if (x == const0_rtx
5442 || (x == CONST0_RTX (DFmode))
5443 || (x == CONST0_RTX (SFmode)))
5444 {
5445 fputs ("%r0", file);
5446 return;
5447 }
5448 else
5449 break;
5450 case 'f':
5451 /* A register or zero (floating point). */
5452 if (x == const0_rtx
5453 || (x == CONST0_RTX (DFmode))
5454 || (x == CONST0_RTX (SFmode)))
5455 {
5456 fputs ("%fr0", file);
5457 return;
5458 }
5459 else
5460 break;
5461 case 'A':
5462 {
5463 rtx xoperands[2];
5464
5465 xoperands[0] = XEXP (XEXP (x, 0), 0);
5466 xoperands[1] = XVECEXP (XEXP (XEXP (x, 0), 1), 0, 0);
5467 pa_output_global_address (file, xoperands[1], 0);
5468 fprintf (file, "(%s)", reg_names [REGNO (xoperands[0])]);
5469 return;
5470 }
5471
5472 case 'C': /* Plain (C)ondition */
5473 case 'X':
5474 switch (GET_CODE (x))
5475 {
5476 case EQ:
5477 fputs ("=", file); break;
5478 case NE:
5479 fputs ("<>", file); break;
5480 case GT:
5481 fputs (">", file); break;
5482 case GE:
5483 fputs (">=", file); break;
5484 case GEU:
5485 fputs (">>=", file); break;
5486 case GTU:
5487 fputs (">>", file); break;
5488 case LT:
5489 fputs ("<", file); break;
5490 case LE:
5491 fputs ("<=", file); break;
5492 case LEU:
5493 fputs ("<<=", file); break;
5494 case LTU:
5495 fputs ("<<", file); break;
5496 default:
5497 gcc_unreachable ();
5498 }
5499 return;
5500 case 'N': /* Condition, (N)egated */
5501 switch (GET_CODE (x))
5502 {
5503 case EQ:
5504 fputs ("<>", file); break;
5505 case NE:
5506 fputs ("=", file); break;
5507 case GT:
5508 fputs ("<=", file); break;
5509 case GE:
5510 fputs ("<", file); break;
5511 case GEU:
5512 fputs ("<<", file); break;
5513 case GTU:
5514 fputs ("<<=", file); break;
5515 case LT:
5516 fputs (">=", file); break;
5517 case LE:
5518 fputs (">", file); break;
5519 case LEU:
5520 fputs (">>", file); break;
5521 case LTU:
5522 fputs (">>=", file); break;
5523 default:
5524 gcc_unreachable ();
5525 }
5526 return;
5527 /* For floating point comparisons. Note that the output
5528 predicates are the complement of the desired mode. The
5529 conditions for GT, GE, LT, LE and LTGT cause an invalid
5530 operation exception if the result is unordered and this
5531 exception is enabled in the floating-point status register. */
5532 case 'Y':
5533 switch (GET_CODE (x))
5534 {
5535 case EQ:
5536 fputs ("!=", file); break;
5537 case NE:
5538 fputs ("=", file); break;
5539 case GT:
5540 fputs ("!>", file); break;
5541 case GE:
5542 fputs ("!>=", file); break;
5543 case LT:
5544 fputs ("!<", file); break;
5545 case LE:
5546 fputs ("!<=", file); break;
5547 case LTGT:
5548 fputs ("!<>", file); break;
5549 case UNLE:
5550 fputs ("!?<=", file); break;
5551 case UNLT:
5552 fputs ("!?<", file); break;
5553 case UNGE:
5554 fputs ("!?>=", file); break;
5555 case UNGT:
5556 fputs ("!?>", file); break;
5557 case UNEQ:
5558 fputs ("!?=", file); break;
5559 case UNORDERED:
5560 fputs ("!?", file); break;
5561 case ORDERED:
5562 fputs ("?", file); break;
5563 default:
5564 gcc_unreachable ();
5565 }
5566 return;
5567 case 'S': /* Condition, operands are (S)wapped. */
5568 switch (GET_CODE (x))
5569 {
5570 case EQ:
5571 fputs ("=", file); break;
5572 case NE:
5573 fputs ("<>", file); break;
5574 case GT:
5575 fputs ("<", file); break;
5576 case GE:
5577 fputs ("<=", file); break;
5578 case GEU:
5579 fputs ("<<=", file); break;
5580 case GTU:
5581 fputs ("<<", file); break;
5582 case LT:
5583 fputs (">", file); break;
5584 case LE:
5585 fputs (">=", file); break;
5586 case LEU:
5587 fputs (">>=", file); break;
5588 case LTU:
5589 fputs (">>", file); break;
5590 default:
5591 gcc_unreachable ();
5592 }
5593 return;
5594 case 'B': /* Condition, (B)oth swapped and negate. */
5595 switch (GET_CODE (x))
5596 {
5597 case EQ:
5598 fputs ("<>", file); break;
5599 case NE:
5600 fputs ("=", file); break;
5601 case GT:
5602 fputs (">=", file); break;
5603 case GE:
5604 fputs (">", file); break;
5605 case GEU:
5606 fputs (">>", file); break;
5607 case GTU:
5608 fputs (">>=", file); break;
5609 case LT:
5610 fputs ("<=", file); break;
5611 case LE:
5612 fputs ("<", file); break;
5613 case LEU:
5614 fputs ("<<", file); break;
5615 case LTU:
5616 fputs ("<<=", file); break;
5617 default:
5618 gcc_unreachable ();
5619 }
5620 return;
5621 case 'k':
5622 gcc_assert (GET_CODE (x) == CONST_INT);
5623 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~INTVAL (x));
5624 return;
5625 case 'Q':
5626 gcc_assert (GET_CODE (x) == CONST_INT);
5627 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 64 - (INTVAL (x) & 63));
5628 return;
5629 case 'L':
5630 gcc_assert (GET_CODE (x) == CONST_INT);
5631 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 32 - (INTVAL (x) & 31));
5632 return;
5633 case 'o':
5634 gcc_assert (GET_CODE (x) == CONST_INT
5635 && (INTVAL (x) == 1 || INTVAL (x) == 2 || INTVAL (x) == 3));
5636 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
5637 return;
5638 case 'O':
5639 gcc_assert (GET_CODE (x) == CONST_INT && exact_log2 (INTVAL (x)) >= 0);
5640 fprintf (file, "%d", exact_log2 (INTVAL (x)));
5641 return;
5642 case 'p':
5643 gcc_assert (GET_CODE (x) == CONST_INT);
5644 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 63 - (INTVAL (x) & 63));
5645 return;
5646 case 'P':
5647 gcc_assert (GET_CODE (x) == CONST_INT);
5648 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 31 - (INTVAL (x) & 31));
5649 return;
5650 case 'I':
5651 if (GET_CODE (x) == CONST_INT)
5652 fputs ("i", file);
5653 return;
5654 case 'M':
5655 case 'F':
5656 switch (GET_CODE (XEXP (x, 0)))
5657 {
5658 case PRE_DEC:
5659 case PRE_INC:
5660 if (ASSEMBLER_DIALECT == 0)
5661 fputs ("s,mb", file);
5662 else
5663 fputs (",mb", file);
5664 break;
5665 case POST_DEC:
5666 case POST_INC:
5667 if (ASSEMBLER_DIALECT == 0)
5668 fputs ("s,ma", file);
5669 else
5670 fputs (",ma", file);
5671 break;
5672 case PLUS:
5673 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5674 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5675 {
5676 if (ASSEMBLER_DIALECT == 0)
5677 fputs ("x", file);
5678 }
5679 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
5680 || GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5681 {
5682 if (ASSEMBLER_DIALECT == 0)
5683 fputs ("x,s", file);
5684 else
5685 fputs (",s", file);
5686 }
5687 else if (code == 'F' && ASSEMBLER_DIALECT == 0)
5688 fputs ("s", file);
5689 break;
5690 default:
5691 if (code == 'F' && ASSEMBLER_DIALECT == 0)
5692 fputs ("s", file);
5693 break;
5694 }
5695 return;
5696 case 'G':
5697 pa_output_global_address (file, x, 0);
5698 return;
5699 case 'H':
5700 pa_output_global_address (file, x, 1);
5701 return;
5702 case 0: /* Don't do anything special */
5703 break;
5704 case 'Z':
5705 {
5706 unsigned op[3];
5707 compute_zdepwi_operands (INTVAL (x), op);
5708 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5709 return;
5710 }
5711 case 'z':
5712 {
5713 unsigned op[3];
5714 compute_zdepdi_operands (INTVAL (x), op);
5715 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5716 return;
5717 }
5718 case 'c':
5719 /* We can get here from a .vtable_inherit due to our
5720 CONSTANT_ADDRESS_P rejecting perfectly good constant
5721 addresses. */
5722 break;
5723 default:
5724 gcc_unreachable ();
5725 }
5726 if (GET_CODE (x) == REG)
5727 {
5728 fputs (reg_names [REGNO (x)], file);
5729 if (TARGET_64BIT && FP_REG_P (x) && GET_MODE_SIZE (GET_MODE (x)) <= 4)
5730 {
5731 fputs ("R", file);
5732 return;
5733 }
5734 if (FP_REG_P (x)
5735 && GET_MODE_SIZE (GET_MODE (x)) <= 4
5736 && (REGNO (x) & 1) == 0)
5737 fputs ("L", file);
5738 }
5739 else if (GET_CODE (x) == MEM)
5740 {
5741 int size = GET_MODE_SIZE (GET_MODE (x));
5742 rtx base = NULL_RTX;
5743 switch (GET_CODE (XEXP (x, 0)))
5744 {
5745 case PRE_DEC:
5746 case POST_DEC:
5747 base = XEXP (XEXP (x, 0), 0);
5748 fprintf (file, "-%d(%s)", size, reg_names [REGNO (base)]);
5749 break;
5750 case PRE_INC:
5751 case POST_INC:
5752 base = XEXP (XEXP (x, 0), 0);
5753 fprintf (file, "%d(%s)", size, reg_names [REGNO (base)]);
5754 break;
5755 case PLUS:
5756 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
5757 fprintf (file, "%s(%s)",
5758 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 0), 0))],
5759 reg_names [REGNO (XEXP (XEXP (x, 0), 1))]);
5760 else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5761 fprintf (file, "%s(%s)",
5762 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 1), 0))],
5763 reg_names [REGNO (XEXP (XEXP (x, 0), 0))]);
5764 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5765 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5766 {
5767 /* Because the REG_POINTER flag can get lost during reload,
5768 pa_legitimate_address_p canonicalizes the order of the
5769 index and base registers in the combined move patterns. */
5770 rtx base = XEXP (XEXP (x, 0), 1);
5771 rtx index = XEXP (XEXP (x, 0), 0);
5772
5773 fprintf (file, "%s(%s)",
5774 reg_names [REGNO (index)], reg_names [REGNO (base)]);
5775 }
5776 else
5777 output_address (GET_MODE (x), XEXP (x, 0));
5778 break;
5779 default:
5780 output_address (GET_MODE (x), XEXP (x, 0));
5781 break;
5782 }
5783 }
5784 else
5785 output_addr_const (file, x);
5786 }
5787
5788 /* output a SYMBOL_REF or a CONST expression involving a SYMBOL_REF. */
5789
5790 void
5791 pa_output_global_address (FILE *file, rtx x, int round_constant)
5792 {
5793
5794 /* Imagine (high (const (plus ...))). */
5795 if (GET_CODE (x) == HIGH)
5796 x = XEXP (x, 0);
5797
5798 if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_DLTIND14R)
5799 {
5800 x = XVECEXP (x, 0, 0);
5801 output_addr_const (file, x);
5802 }
5803 else if (GET_CODE (x) == SYMBOL_REF && read_only_operand (x, VOIDmode))
5804 output_addr_const (file, x);
5805 else if (GET_CODE (x) == SYMBOL_REF && !flag_pic)
5806 {
5807 output_addr_const (file, x);
5808 fputs ("-$global$", file);
5809 }
5810 else if (GET_CODE (x) == CONST)
5811 {
5812 const char *sep = "";
5813 int offset = 0; /* assembler wants -$global$ at end */
5814 rtx base = NULL_RTX;
5815
5816 switch (GET_CODE (XEXP (XEXP (x, 0), 0)))
5817 {
5818 case LABEL_REF:
5819 case SYMBOL_REF:
5820 base = XEXP (XEXP (x, 0), 0);
5821 output_addr_const (file, base);
5822 break;
5823 case CONST_INT:
5824 offset = INTVAL (XEXP (XEXP (x, 0), 0));
5825 break;
5826 default:
5827 gcc_unreachable ();
5828 }
5829
5830 switch (GET_CODE (XEXP (XEXP (x, 0), 1)))
5831 {
5832 case LABEL_REF:
5833 case SYMBOL_REF:
5834 base = XEXP (XEXP (x, 0), 1);
5835 output_addr_const (file, base);
5836 break;
5837 case CONST_INT:
5838 offset = INTVAL (XEXP (XEXP (x, 0), 1));
5839 break;
5840 default:
5841 gcc_unreachable ();
5842 }
5843
5844 /* How bogus. The compiler is apparently responsible for
5845 rounding the constant if it uses an LR field selector.
5846
5847 The linker and/or assembler seem a better place since
5848 they have to do this kind of thing already.
5849
5850 If we fail to do this, HP's optimizing linker may eliminate
5851 an addil, but not update the ldw/stw/ldo instruction that
5852 uses the result of the addil. */
5853 if (round_constant)
5854 offset = ((offset + 0x1000) & ~0x1fff);
5855
5856 switch (GET_CODE (XEXP (x, 0)))
5857 {
5858 case PLUS:
5859 if (offset < 0)
5860 {
5861 offset = -offset;
5862 sep = "-";
5863 }
5864 else
5865 sep = "+";
5866 break;
5867
5868 case MINUS:
5869 gcc_assert (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF);
5870 sep = "-";
5871 break;
5872
5873 default:
5874 gcc_unreachable ();
5875 }
5876
5877 if (!read_only_operand (base, VOIDmode) && !flag_pic)
5878 fputs ("-$global$", file);
5879 if (offset)
5880 fprintf (file, "%s%d", sep, offset);
5881 }
5882 else
5883 output_addr_const (file, x);
5884 }
5885
5886 /* Output boilerplate text to appear at the beginning of the file.
5887 There are several possible versions. */
5888 #define aputs(x) fputs(x, asm_out_file)
5889 static inline void
5890 pa_file_start_level (void)
5891 {
5892 if (TARGET_64BIT)
5893 aputs ("\t.LEVEL 2.0w\n");
5894 else if (TARGET_PA_20)
5895 aputs ("\t.LEVEL 2.0\n");
5896 else if (TARGET_PA_11)
5897 aputs ("\t.LEVEL 1.1\n");
5898 else
5899 aputs ("\t.LEVEL 1.0\n");
5900 }
5901
5902 static inline void
5903 pa_file_start_space (int sortspace)
5904 {
5905 aputs ("\t.SPACE $PRIVATE$");
5906 if (sortspace)
5907 aputs (",SORT=16");
5908 aputs ("\n\t.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31");
5909 if (flag_tm)
5910 aputs ("\n\t.SUBSPA $TM_CLONE_TABLE$,QUAD=1,ALIGN=8,ACCESS=31");
5911 aputs ("\n\t.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82"
5912 "\n\t.SPACE $TEXT$");
5913 if (sortspace)
5914 aputs (",SORT=8");
5915 aputs ("\n\t.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44"
5916 "\n\t.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n");
5917 }
5918
5919 static inline void
5920 pa_file_start_file (int want_version)
5921 {
5922 if (write_symbols != NO_DEBUG)
5923 {
5924 output_file_directive (asm_out_file, main_input_filename);
5925 if (want_version)
5926 aputs ("\t.version\t\"01.01\"\n");
5927 }
5928 }
5929
5930 static inline void
5931 pa_file_start_mcount (const char *aswhat)
5932 {
5933 if (profile_flag)
5934 fprintf (asm_out_file, "\t.IMPORT _mcount,%s\n", aswhat);
5935 }
5936
5937 static void
5938 pa_elf_file_start (void)
5939 {
5940 pa_file_start_level ();
5941 pa_file_start_mcount ("ENTRY");
5942 pa_file_start_file (0);
5943 }
5944
5945 static void
5946 pa_som_file_start (void)
5947 {
5948 pa_file_start_level ();
5949 pa_file_start_space (0);
5950 aputs ("\t.IMPORT $global$,DATA\n"
5951 "\t.IMPORT $$dyncall,MILLICODE\n");
5952 pa_file_start_mcount ("CODE");
5953 pa_file_start_file (0);
5954 }
5955
5956 static void
5957 pa_linux_file_start (void)
5958 {
5959 pa_file_start_file (1);
5960 pa_file_start_level ();
5961 pa_file_start_mcount ("CODE");
5962 }
5963
5964 static void
5965 pa_hpux64_gas_file_start (void)
5966 {
5967 pa_file_start_level ();
5968 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
5969 if (profile_flag)
5970 ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, "_mcount", "function");
5971 #endif
5972 pa_file_start_file (1);
5973 }
5974
5975 static void
5976 pa_hpux64_hpas_file_start (void)
5977 {
5978 pa_file_start_level ();
5979 pa_file_start_space (1);
5980 pa_file_start_mcount ("CODE");
5981 pa_file_start_file (0);
5982 }
5983 #undef aputs
5984
5985 /* Search the deferred plabel list for SYMBOL and return its internal
5986 label. If an entry for SYMBOL is not found, a new entry is created. */
5987
5988 rtx
5989 pa_get_deferred_plabel (rtx symbol)
5990 {
5991 const char *fname = XSTR (symbol, 0);
5992 size_t i;
5993
5994 /* See if we have already put this function on the list of deferred
5995 plabels. This list is generally small, so a liner search is not
5996 too ugly. If it proves too slow replace it with something faster. */
5997 for (i = 0; i < n_deferred_plabels; i++)
5998 if (strcmp (fname, XSTR (deferred_plabels[i].symbol, 0)) == 0)
5999 break;
6000
6001 /* If the deferred plabel list is empty, or this entry was not found
6002 on the list, create a new entry on the list. */
6003 if (deferred_plabels == NULL || i == n_deferred_plabels)
6004 {
6005 tree id;
6006
6007 if (deferred_plabels == 0)
6008 deferred_plabels = ggc_alloc<deferred_plabel> ();
6009 else
6010 deferred_plabels = GGC_RESIZEVEC (struct deferred_plabel,
6011 deferred_plabels,
6012 n_deferred_plabels + 1);
6013
6014 i = n_deferred_plabels++;
6015 deferred_plabels[i].internal_label = gen_label_rtx ();
6016 deferred_plabels[i].symbol = symbol;
6017
6018 /* Gross. We have just implicitly taken the address of this
6019 function. Mark it in the same manner as assemble_name. */
6020 id = maybe_get_identifier (targetm.strip_name_encoding (fname));
6021 if (id)
6022 mark_referenced (id);
6023 }
6024
6025 return deferred_plabels[i].internal_label;
6026 }
6027
6028 static void
6029 output_deferred_plabels (void)
6030 {
6031 size_t i;
6032
6033 /* If we have some deferred plabels, then we need to switch into the
6034 data or readonly data section, and align it to a 4 byte boundary
6035 before outputting the deferred plabels. */
6036 if (n_deferred_plabels)
6037 {
6038 switch_to_section (flag_pic ? data_section : readonly_data_section);
6039 ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2);
6040 }
6041
6042 /* Now output the deferred plabels. */
6043 for (i = 0; i < n_deferred_plabels; i++)
6044 {
6045 targetm.asm_out.internal_label (asm_out_file, "L",
6046 CODE_LABEL_NUMBER (deferred_plabels[i].internal_label));
6047 assemble_integer (deferred_plabels[i].symbol,
6048 TARGET_64BIT ? 8 : 4, TARGET_64BIT ? 64 : 32, 1);
6049 }
6050 }
6051
6052 /* Initialize optabs to point to emulation routines. */
6053
6054 static void
6055 pa_init_libfuncs (void)
6056 {
6057 if (HPUX_LONG_DOUBLE_LIBRARY)
6058 {
6059 set_optab_libfunc (add_optab, TFmode, "_U_Qfadd");
6060 set_optab_libfunc (sub_optab, TFmode, "_U_Qfsub");
6061 set_optab_libfunc (smul_optab, TFmode, "_U_Qfmpy");
6062 set_optab_libfunc (sdiv_optab, TFmode, "_U_Qfdiv");
6063 set_optab_libfunc (smin_optab, TFmode, "_U_Qmin");
6064 set_optab_libfunc (smax_optab, TFmode, "_U_Qfmax");
6065 set_optab_libfunc (sqrt_optab, TFmode, "_U_Qfsqrt");
6066 set_optab_libfunc (abs_optab, TFmode, "_U_Qfabs");
6067 set_optab_libfunc (neg_optab, TFmode, "_U_Qfneg");
6068
6069 set_optab_libfunc (eq_optab, TFmode, "_U_Qfeq");
6070 set_optab_libfunc (ne_optab, TFmode, "_U_Qfne");
6071 set_optab_libfunc (gt_optab, TFmode, "_U_Qfgt");
6072 set_optab_libfunc (ge_optab, TFmode, "_U_Qfge");
6073 set_optab_libfunc (lt_optab, TFmode, "_U_Qflt");
6074 set_optab_libfunc (le_optab, TFmode, "_U_Qfle");
6075 set_optab_libfunc (unord_optab, TFmode, "_U_Qfunord");
6076
6077 set_conv_libfunc (sext_optab, TFmode, SFmode, "_U_Qfcnvff_sgl_to_quad");
6078 set_conv_libfunc (sext_optab, TFmode, DFmode, "_U_Qfcnvff_dbl_to_quad");
6079 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_U_Qfcnvff_quad_to_sgl");
6080 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_U_Qfcnvff_quad_to_dbl");
6081
6082 set_conv_libfunc (sfix_optab, SImode, TFmode,
6083 TARGET_64BIT ? "__U_Qfcnvfxt_quad_to_sgl"
6084 : "_U_Qfcnvfxt_quad_to_sgl");
6085 set_conv_libfunc (sfix_optab, DImode, TFmode,
6086 "_U_Qfcnvfxt_quad_to_dbl");
6087 set_conv_libfunc (ufix_optab, SImode, TFmode,
6088 "_U_Qfcnvfxt_quad_to_usgl");
6089 set_conv_libfunc (ufix_optab, DImode, TFmode,
6090 "_U_Qfcnvfxt_quad_to_udbl");
6091
6092 set_conv_libfunc (sfloat_optab, TFmode, SImode,
6093 "_U_Qfcnvxf_sgl_to_quad");
6094 set_conv_libfunc (sfloat_optab, TFmode, DImode,
6095 "_U_Qfcnvxf_dbl_to_quad");
6096 set_conv_libfunc (ufloat_optab, TFmode, SImode,
6097 "_U_Qfcnvxf_usgl_to_quad");
6098 set_conv_libfunc (ufloat_optab, TFmode, DImode,
6099 "_U_Qfcnvxf_udbl_to_quad");
6100 }
6101
6102 if (TARGET_SYNC_LIBCALLS)
6103 init_sync_libfuncs (MAX_SYNC_LIBFUNC_SIZE);
6104 }
6105
6106 /* HP's millicode routines mean something special to the assembler.
6107 Keep track of which ones we have used. */
6108
6109 enum millicodes { remI, remU, divI, divU, mulI, end1000 };
6110 static void import_milli (enum millicodes);
6111 static char imported[(int) end1000];
6112 static const char * const milli_names[] = {"remI", "remU", "divI", "divU", "mulI"};
6113 static const char import_string[] = ".IMPORT $$....,MILLICODE";
6114 #define MILLI_START 10
6115
6116 static void
6117 import_milli (enum millicodes code)
6118 {
6119 char str[sizeof (import_string)];
6120
6121 if (!imported[(int) code])
6122 {
6123 imported[(int) code] = 1;
6124 strcpy (str, import_string);
6125 memcpy (str + MILLI_START, milli_names[(int) code], 4);
6126 output_asm_insn (str, 0);
6127 }
6128 }
6129
6130 /* The register constraints have put the operands and return value in
6131 the proper registers. */
6132
6133 const char *
6134 pa_output_mul_insn (int unsignedp ATTRIBUTE_UNUSED, rtx_insn *insn)
6135 {
6136 import_milli (mulI);
6137 return pa_output_millicode_call (insn, gen_rtx_SYMBOL_REF (Pmode, "$$mulI"));
6138 }
6139
6140 /* Emit the rtl for doing a division by a constant. */
6141
6142 /* Do magic division millicodes exist for this value? */
6143 const int pa_magic_milli[]= {0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1};
6144
6145 /* We'll use an array to keep track of the magic millicodes and
6146 whether or not we've used them already. [n][0] is signed, [n][1] is
6147 unsigned. */
6148
6149 static int div_milli[16][2];
6150
6151 int
6152 pa_emit_hpdiv_const (rtx *operands, int unsignedp)
6153 {
6154 if (GET_CODE (operands[2]) == CONST_INT
6155 && INTVAL (operands[2]) > 0
6156 && INTVAL (operands[2]) < 16
6157 && pa_magic_milli[INTVAL (operands[2])])
6158 {
6159 rtx ret = gen_rtx_REG (SImode, TARGET_64BIT ? 2 : 31);
6160
6161 emit_move_insn (gen_rtx_REG (SImode, 26), operands[1]);
6162 emit
6163 (gen_rtx_PARALLEL
6164 (VOIDmode,
6165 gen_rtvec (5, gen_rtx_SET (gen_rtx_REG (SImode, 29),
6166 gen_rtx_fmt_ee (unsignedp ? UDIV : DIV,
6167 SImode,
6168 gen_rtx_REG (SImode, 26),
6169 operands[2])),
6170 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 1)),
6171 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 26)),
6172 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 25)),
6173 gen_rtx_CLOBBER (VOIDmode, ret))));
6174 emit_move_insn (operands[0], gen_rtx_REG (SImode, 29));
6175 return 1;
6176 }
6177 return 0;
6178 }
6179
6180 const char *
6181 pa_output_div_insn (rtx *operands, int unsignedp, rtx_insn *insn)
6182 {
6183 int divisor;
6184
6185 /* If the divisor is a constant, try to use one of the special
6186 opcodes .*/
6187 if (GET_CODE (operands[0]) == CONST_INT)
6188 {
6189 static char buf[100];
6190 divisor = INTVAL (operands[0]);
6191 if (!div_milli[divisor][unsignedp])
6192 {
6193 div_milli[divisor][unsignedp] = 1;
6194 if (unsignedp)
6195 output_asm_insn (".IMPORT $$divU_%0,MILLICODE", operands);
6196 else
6197 output_asm_insn (".IMPORT $$divI_%0,MILLICODE", operands);
6198 }
6199 if (unsignedp)
6200 {
6201 sprintf (buf, "$$divU_" HOST_WIDE_INT_PRINT_DEC,
6202 INTVAL (operands[0]));
6203 return pa_output_millicode_call (insn,
6204 gen_rtx_SYMBOL_REF (SImode, buf));
6205 }
6206 else
6207 {
6208 sprintf (buf, "$$divI_" HOST_WIDE_INT_PRINT_DEC,
6209 INTVAL (operands[0]));
6210 return pa_output_millicode_call (insn,
6211 gen_rtx_SYMBOL_REF (SImode, buf));
6212 }
6213 }
6214 /* Divisor isn't a special constant. */
6215 else
6216 {
6217 if (unsignedp)
6218 {
6219 import_milli (divU);
6220 return pa_output_millicode_call (insn,
6221 gen_rtx_SYMBOL_REF (SImode, "$$divU"));
6222 }
6223 else
6224 {
6225 import_milli (divI);
6226 return pa_output_millicode_call (insn,
6227 gen_rtx_SYMBOL_REF (SImode, "$$divI"));
6228 }
6229 }
6230 }
6231
6232 /* Output a $$rem millicode to do mod. */
6233
6234 const char *
6235 pa_output_mod_insn (int unsignedp, rtx_insn *insn)
6236 {
6237 if (unsignedp)
6238 {
6239 import_milli (remU);
6240 return pa_output_millicode_call (insn,
6241 gen_rtx_SYMBOL_REF (SImode, "$$remU"));
6242 }
6243 else
6244 {
6245 import_milli (remI);
6246 return pa_output_millicode_call (insn,
6247 gen_rtx_SYMBOL_REF (SImode, "$$remI"));
6248 }
6249 }
6250
6251 void
6252 pa_output_arg_descriptor (rtx_insn *call_insn)
6253 {
6254 const char *arg_regs[4];
6255 machine_mode arg_mode;
6256 rtx link;
6257 int i, output_flag = 0;
6258 int regno;
6259
6260 /* We neither need nor want argument location descriptors for the
6261 64bit runtime environment or the ELF32 environment. */
6262 if (TARGET_64BIT || TARGET_ELF32)
6263 return;
6264
6265 for (i = 0; i < 4; i++)
6266 arg_regs[i] = 0;
6267
6268 /* Specify explicitly that no argument relocations should take place
6269 if using the portable runtime calling conventions. */
6270 if (TARGET_PORTABLE_RUNTIME)
6271 {
6272 fputs ("\t.CALL ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RETVAL=NO\n",
6273 asm_out_file);
6274 return;
6275 }
6276
6277 gcc_assert (CALL_P (call_insn));
6278 for (link = CALL_INSN_FUNCTION_USAGE (call_insn);
6279 link; link = XEXP (link, 1))
6280 {
6281 rtx use = XEXP (link, 0);
6282
6283 if (! (GET_CODE (use) == USE
6284 && GET_CODE (XEXP (use, 0)) == REG
6285 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
6286 continue;
6287
6288 arg_mode = GET_MODE (XEXP (use, 0));
6289 regno = REGNO (XEXP (use, 0));
6290 if (regno >= 23 && regno <= 26)
6291 {
6292 arg_regs[26 - regno] = "GR";
6293 if (arg_mode == DImode)
6294 arg_regs[25 - regno] = "GR";
6295 }
6296 else if (regno >= 32 && regno <= 39)
6297 {
6298 if (arg_mode == SFmode)
6299 arg_regs[(regno - 32) / 2] = "FR";
6300 else
6301 {
6302 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
6303 arg_regs[(regno - 34) / 2] = "FR";
6304 arg_regs[(regno - 34) / 2 + 1] = "FU";
6305 #else
6306 arg_regs[(regno - 34) / 2] = "FU";
6307 arg_regs[(regno - 34) / 2 + 1] = "FR";
6308 #endif
6309 }
6310 }
6311 }
6312 fputs ("\t.CALL ", asm_out_file);
6313 for (i = 0; i < 4; i++)
6314 {
6315 if (arg_regs[i])
6316 {
6317 if (output_flag++)
6318 fputc (',', asm_out_file);
6319 fprintf (asm_out_file, "ARGW%d=%s", i, arg_regs[i]);
6320 }
6321 }
6322 fputc ('\n', asm_out_file);
6323 }
6324
6325 /* Inform reload about cases where moving X with a mode MODE to or from
6326 a register in RCLASS requires an extra scratch or immediate register.
6327 Return the class needed for the immediate register. */
6328
6329 static reg_class_t
6330 pa_secondary_reload (bool in_p, rtx x, reg_class_t rclass_i,
6331 machine_mode mode, secondary_reload_info *sri)
6332 {
6333 int regno;
6334 enum reg_class rclass = (enum reg_class) rclass_i;
6335
6336 /* Handle the easy stuff first. */
6337 if (rclass == R1_REGS)
6338 return NO_REGS;
6339
6340 if (REG_P (x))
6341 {
6342 regno = REGNO (x);
6343 if (rclass == BASE_REG_CLASS && regno < FIRST_PSEUDO_REGISTER)
6344 return NO_REGS;
6345 }
6346 else
6347 regno = -1;
6348
6349 /* If we have something like (mem (mem (...)), we can safely assume the
6350 inner MEM will end up in a general register after reloading, so there's
6351 no need for a secondary reload. */
6352 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == MEM)
6353 return NO_REGS;
6354
6355 /* Trying to load a constant into a FP register during PIC code
6356 generation requires %r1 as a scratch register. For float modes,
6357 the only legitimate constant is CONST0_RTX. However, there are
6358 a few patterns that accept constant double operands. */
6359 if (flag_pic
6360 && FP_REG_CLASS_P (rclass)
6361 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
6362 {
6363 switch (mode)
6364 {
6365 case E_SImode:
6366 sri->icode = CODE_FOR_reload_insi_r1;
6367 break;
6368
6369 case E_DImode:
6370 sri->icode = CODE_FOR_reload_indi_r1;
6371 break;
6372
6373 case E_SFmode:
6374 sri->icode = CODE_FOR_reload_insf_r1;
6375 break;
6376
6377 case E_DFmode:
6378 sri->icode = CODE_FOR_reload_indf_r1;
6379 break;
6380
6381 default:
6382 gcc_unreachable ();
6383 }
6384 return NO_REGS;
6385 }
6386
6387 /* Secondary reloads of symbolic expressions require %r1 as a scratch
6388 register when we're generating PIC code or when the operand isn't
6389 readonly. */
6390 if (pa_symbolic_expression_p (x))
6391 {
6392 if (GET_CODE (x) == HIGH)
6393 x = XEXP (x, 0);
6394
6395 if (flag_pic || !read_only_operand (x, VOIDmode))
6396 {
6397 switch (mode)
6398 {
6399 case E_SImode:
6400 sri->icode = CODE_FOR_reload_insi_r1;
6401 break;
6402
6403 case E_DImode:
6404 sri->icode = CODE_FOR_reload_indi_r1;
6405 break;
6406
6407 default:
6408 gcc_unreachable ();
6409 }
6410 return NO_REGS;
6411 }
6412 }
6413
6414 /* Profiling showed the PA port spends about 1.3% of its compilation
6415 time in true_regnum from calls inside pa_secondary_reload_class. */
6416 if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
6417 regno = true_regnum (x);
6418
6419 /* Handle reloads for floating-point loads and stores. */
6420 if (regno < 0 && FP_REG_CLASS_P (rclass))
6421 {
6422 if (REG_P (x) || GET_CODE (x) == SUBREG)
6423 return NO_REGS;
6424
6425 /* We don't need a secondary reload for indexed memory addresses.
6426
6427 When INT14_OK_STRICT is true, it might appear that we could
6428 directly allow register indirect memory addresses. However,
6429 this doesn't work because we don't support SUBREGs in
6430 floating-point register copies and reload doesn't tell us
6431 when it's going to use a SUBREG. */
6432 if (MEM_P (x) && IS_INDEX_ADDR_P (XEXP (x, 0)))
6433 return NO_REGS;
6434
6435 /* Request a secondary reload with a general scratch register
6436 for everything else. ??? Could symbolic operands be handled
6437 directly when generating non-pic PA 2.0 code? */
6438 sri->icode = (in_p
6439 ? direct_optab_handler (reload_in_optab, mode)
6440 : direct_optab_handler (reload_out_optab, mode));
6441 return NO_REGS;
6442 }
6443
6444 /* A SAR<->FP register copy requires an intermediate general register
6445 and secondary memory. We need a secondary reload with a general
6446 scratch register for spills. */
6447 if (rclass == SHIFT_REGS)
6448 {
6449 /* Handle spill. */
6450 if (regno < 0)
6451 {
6452 if (REG_P (x) || GET_CODE (x) == SUBREG)
6453 return GENERAL_REGS;
6454
6455 if (TARGET_64BIT && GET_CODE (x) == CONST_INT)
6456 return GENERAL_REGS;
6457
6458 sri->icode = (in_p
6459 ? direct_optab_handler (reload_in_optab, mode)
6460 : direct_optab_handler (reload_out_optab, mode));
6461 return NO_REGS;
6462 }
6463
6464 /* Handle FP copy. */
6465 if (FP_REG_CLASS_P (REGNO_REG_CLASS (regno)))
6466 return GENERAL_REGS;
6467 }
6468
6469 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
6470 && REGNO_REG_CLASS (regno) == SHIFT_REGS
6471 && FP_REG_CLASS_P (rclass))
6472 return GENERAL_REGS;
6473
6474 return NO_REGS;
6475 }
6476
6477 /* Implement TARGET_SECONDARY_MEMORY_NEEDED. */
6478
6479 static bool
6480 pa_secondary_memory_needed (machine_mode mode ATTRIBUTE_UNUSED,
6481 reg_class_t class1 ATTRIBUTE_UNUSED,
6482 reg_class_t class2 ATTRIBUTE_UNUSED)
6483 {
6484 #ifdef PA_SECONDARY_MEMORY_NEEDED
6485 return PA_SECONDARY_MEMORY_NEEDED (mode, class1, class2);
6486 #else
6487 return false;
6488 #endif
6489 }
6490
6491 /* Implement TARGET_EXTRA_LIVE_ON_ENTRY. The argument pointer
6492 is only marked as live on entry by df-scan when it is a fixed
6493 register. It isn't a fixed register in the 64-bit runtime,
6494 so we need to mark it here. */
6495
6496 static void
6497 pa_extra_live_on_entry (bitmap regs)
6498 {
6499 if (TARGET_64BIT)
6500 bitmap_set_bit (regs, ARG_POINTER_REGNUM);
6501 }
6502
6503 /* Implement EH_RETURN_HANDLER_RTX. The MEM needs to be volatile
6504 to prevent it from being deleted. */
6505
6506 rtx
6507 pa_eh_return_handler_rtx (void)
6508 {
6509 rtx tmp;
6510
6511 tmp = gen_rtx_PLUS (word_mode, hard_frame_pointer_rtx,
6512 TARGET_64BIT ? GEN_INT (-16) : GEN_INT (-20));
6513 tmp = gen_rtx_MEM (word_mode, tmp);
6514 tmp->volatil = 1;
6515 return tmp;
6516 }
6517
6518 /* In the 32-bit runtime, arguments larger than eight bytes are passed
6519 by invisible reference. As a GCC extension, we also pass anything
6520 with a zero or variable size by reference.
6521
6522 The 64-bit runtime does not describe passing any types by invisible
6523 reference. The internals of GCC can't currently handle passing
6524 empty structures, and zero or variable length arrays when they are
6525 not passed entirely on the stack or by reference. Thus, as a GCC
6526 extension, we pass these types by reference. The HP compiler doesn't
6527 support these types, so hopefully there shouldn't be any compatibility
6528 issues. This may have to be revisited when HP releases a C99 compiler
6529 or updates the ABI. */
6530
6531 static bool
6532 pa_pass_by_reference (cumulative_args_t, const function_arg_info &arg)
6533 {
6534 HOST_WIDE_INT size = arg.type_size_in_bytes ();
6535 if (TARGET_64BIT)
6536 return size <= 0;
6537 else
6538 return size <= 0 || size > 8;
6539 }
6540
6541 /* Implement TARGET_FUNCTION_ARG_PADDING. */
6542
6543 static pad_direction
6544 pa_function_arg_padding (machine_mode mode, const_tree type)
6545 {
6546 if (mode == BLKmode
6547 || (TARGET_64BIT
6548 && type
6549 && (AGGREGATE_TYPE_P (type)
6550 || TREE_CODE (type) == COMPLEX_TYPE
6551 || VECTOR_TYPE_P (type))))
6552 {
6553 /* Return PAD_NONE if justification is not required. */
6554 if (type
6555 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
6556 && (int_size_in_bytes (type) * BITS_PER_UNIT) % PARM_BOUNDARY == 0)
6557 return PAD_NONE;
6558
6559 /* The directions set here are ignored when a BLKmode argument larger
6560 than a word is placed in a register. Different code is used for
6561 the stack and registers. This makes it difficult to have a
6562 consistent data representation for both the stack and registers.
6563 For both runtimes, the justification and padding for arguments on
6564 the stack and in registers should be identical. */
6565 if (TARGET_64BIT)
6566 /* The 64-bit runtime specifies left justification for aggregates. */
6567 return PAD_UPWARD;
6568 else
6569 /* The 32-bit runtime architecture specifies right justification.
6570 When the argument is passed on the stack, the argument is padded
6571 with garbage on the left. The HP compiler pads with zeros. */
6572 return PAD_DOWNWARD;
6573 }
6574
6575 if (GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
6576 return PAD_DOWNWARD;
6577 else
6578 return PAD_NONE;
6579 }
6580
6581
6582 /* Do what is necessary for `va_start'. We look at the current function
6583 to determine if stdargs or varargs is used and fill in an initial
6584 va_list. A pointer to this constructor is returned. */
6585
6586 static rtx
6587 hppa_builtin_saveregs (void)
6588 {
6589 rtx offset, dest;
6590 tree fntype = TREE_TYPE (current_function_decl);
6591 int argadj = ((!stdarg_p (fntype))
6592 ? UNITS_PER_WORD : 0);
6593
6594 if (argadj)
6595 offset = plus_constant (Pmode, crtl->args.arg_offset_rtx, argadj);
6596 else
6597 offset = crtl->args.arg_offset_rtx;
6598
6599 if (TARGET_64BIT)
6600 {
6601 int i, off;
6602
6603 /* Adjust for varargs/stdarg differences. */
6604 if (argadj)
6605 offset = plus_constant (Pmode, crtl->args.arg_offset_rtx, -argadj);
6606 else
6607 offset = crtl->args.arg_offset_rtx;
6608
6609 /* We need to save %r26 .. %r19 inclusive starting at offset -64
6610 from the incoming arg pointer and growing to larger addresses. */
6611 for (i = 26, off = -64; i >= 19; i--, off += 8)
6612 emit_move_insn (gen_rtx_MEM (word_mode,
6613 plus_constant (Pmode,
6614 arg_pointer_rtx, off)),
6615 gen_rtx_REG (word_mode, i));
6616
6617 /* The incoming args pointer points just beyond the flushback area;
6618 normally this is not a serious concern. However, when we are doing
6619 varargs/stdargs we want to make the arg pointer point to the start
6620 of the incoming argument area. */
6621 emit_move_insn (virtual_incoming_args_rtx,
6622 plus_constant (Pmode, arg_pointer_rtx, -64));
6623
6624 /* Now return a pointer to the first anonymous argument. */
6625 return copy_to_reg (expand_binop (Pmode, add_optab,
6626 virtual_incoming_args_rtx,
6627 offset, 0, 0, OPTAB_LIB_WIDEN));
6628 }
6629
6630 /* Store general registers on the stack. */
6631 dest = gen_rtx_MEM (BLKmode,
6632 plus_constant (Pmode, crtl->args.internal_arg_pointer,
6633 -16));
6634 set_mem_alias_set (dest, get_varargs_alias_set ());
6635 set_mem_align (dest, BITS_PER_WORD);
6636 move_block_from_reg (23, dest, 4);
6637
6638 /* move_block_from_reg will emit code to store the argument registers
6639 individually as scalar stores.
6640
6641 However, other insns may later load from the same addresses for
6642 a structure load (passing a struct to a varargs routine).
6643
6644 The alias code assumes that such aliasing can never happen, so we
6645 have to keep memory referencing insns from moving up beyond the
6646 last argument register store. So we emit a blockage insn here. */
6647 emit_insn (gen_blockage ());
6648
6649 return copy_to_reg (expand_binop (Pmode, add_optab,
6650 crtl->args.internal_arg_pointer,
6651 offset, 0, 0, OPTAB_LIB_WIDEN));
6652 }
6653
6654 static void
6655 hppa_va_start (tree valist, rtx nextarg)
6656 {
6657 nextarg = expand_builtin_saveregs ();
6658 std_expand_builtin_va_start (valist, nextarg);
6659 }
6660
6661 static tree
6662 hppa_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
6663 gimple_seq *post_p)
6664 {
6665 if (TARGET_64BIT)
6666 {
6667 /* Args grow upward. We can use the generic routines. */
6668 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6669 }
6670 else /* !TARGET_64BIT */
6671 {
6672 tree ptr = build_pointer_type (type);
6673 tree valist_type;
6674 tree t, u;
6675 unsigned int size, ofs;
6676 bool indirect;
6677
6678 indirect = pass_va_arg_by_reference (type);
6679 if (indirect)
6680 {
6681 type = ptr;
6682 ptr = build_pointer_type (type);
6683 }
6684 size = int_size_in_bytes (type);
6685 valist_type = TREE_TYPE (valist);
6686
6687 /* Args grow down. Not handled by generic routines. */
6688
6689 u = fold_convert (sizetype, size_in_bytes (type));
6690 u = fold_build1 (NEGATE_EXPR, sizetype, u);
6691 t = fold_build_pointer_plus (valist, u);
6692
6693 /* Align to 4 or 8 byte boundary depending on argument size. */
6694
6695 u = build_int_cst (TREE_TYPE (t), (HOST_WIDE_INT)(size > 4 ? -8 : -4));
6696 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t, u);
6697 t = fold_convert (valist_type, t);
6698
6699 t = build2 (MODIFY_EXPR, valist_type, valist, t);
6700
6701 ofs = (8 - size) % 4;
6702 if (ofs != 0)
6703 t = fold_build_pointer_plus_hwi (t, ofs);
6704
6705 t = fold_convert (ptr, t);
6706 t = build_va_arg_indirect_ref (t);
6707
6708 if (indirect)
6709 t = build_va_arg_indirect_ref (t);
6710
6711 return t;
6712 }
6713 }
6714
6715 /* True if MODE is valid for the target. By "valid", we mean able to
6716 be manipulated in non-trivial ways. In particular, this means all
6717 the arithmetic is supported. */
6718
6719 static bool
6720 pa_scalar_mode_supported_p (scalar_mode mode)
6721 {
6722 int precision = GET_MODE_PRECISION (mode);
6723
6724 if (TARGET_64BIT && mode == TImode)
6725 return true;
6726
6727 switch (GET_MODE_CLASS (mode))
6728 {
6729 case MODE_PARTIAL_INT:
6730 case MODE_INT:
6731 if (precision == CHAR_TYPE_SIZE)
6732 return true;
6733 if (precision == SHORT_TYPE_SIZE)
6734 return true;
6735 if (precision == INT_TYPE_SIZE)
6736 return true;
6737 if (precision == LONG_TYPE_SIZE)
6738 return true;
6739 if (precision == LONG_LONG_TYPE_SIZE)
6740 return true;
6741 return false;
6742
6743 case MODE_FLOAT:
6744 if (precision == PA_FLOAT_TYPE_SIZE)
6745 return true;
6746 if (precision == PA_DOUBLE_TYPE_SIZE)
6747 return true;
6748 if (precision == PA_LONG_DOUBLE_TYPE_SIZE)
6749 return true;
6750 return false;
6751
6752 case MODE_DECIMAL_FLOAT:
6753 return false;
6754
6755 default:
6756 gcc_unreachable ();
6757 }
6758 }
6759
6760 /* Return TRUE if INSN, a jump insn, has an unfilled delay slot and
6761 it branches into the delay slot. Otherwise, return FALSE. */
6762
6763 static bool
6764 branch_to_delay_slot_p (rtx_insn *insn)
6765 {
6766 rtx_insn *jump_insn;
6767
6768 if (dbr_sequence_length ())
6769 return FALSE;
6770
6771 jump_insn = next_active_insn (JUMP_LABEL_AS_INSN (insn));
6772 while (insn)
6773 {
6774 insn = next_active_insn (insn);
6775 if (jump_insn == insn)
6776 return TRUE;
6777
6778 /* We can't rely on the length of asms. So, we return FALSE when
6779 the branch is followed by an asm. */
6780 if (!insn
6781 || GET_CODE (PATTERN (insn)) == ASM_INPUT
6782 || asm_noperands (PATTERN (insn)) >= 0
6783 || get_attr_length (insn) > 0)
6784 break;
6785 }
6786
6787 return FALSE;
6788 }
6789
6790 /* Return TRUE if INSN, a forward jump insn, needs a nop in its delay slot.
6791
6792 This occurs when INSN has an unfilled delay slot and is followed
6793 by an asm. Disaster can occur if the asm is empty and the jump
6794 branches into the delay slot. So, we add a nop in the delay slot
6795 when this occurs. */
6796
6797 static bool
6798 branch_needs_nop_p (rtx_insn *insn)
6799 {
6800 rtx_insn *jump_insn;
6801
6802 if (dbr_sequence_length ())
6803 return FALSE;
6804
6805 jump_insn = next_active_insn (JUMP_LABEL_AS_INSN (insn));
6806 while (insn)
6807 {
6808 insn = next_active_insn (insn);
6809 if (!insn || jump_insn == insn)
6810 return TRUE;
6811
6812 if (!(GET_CODE (PATTERN (insn)) == ASM_INPUT
6813 || asm_noperands (PATTERN (insn)) >= 0)
6814 && get_attr_length (insn) > 0)
6815 break;
6816 }
6817
6818 return FALSE;
6819 }
6820
6821 /* Return TRUE if INSN, a forward jump insn, can use nullification
6822 to skip the following instruction. This avoids an extra cycle due
6823 to a mis-predicted branch when we fall through. */
6824
6825 static bool
6826 use_skip_p (rtx_insn *insn)
6827 {
6828 rtx_insn *jump_insn = next_active_insn (JUMP_LABEL_AS_INSN (insn));
6829
6830 while (insn)
6831 {
6832 insn = next_active_insn (insn);
6833
6834 /* We can't rely on the length of asms, so we can't skip asms. */
6835 if (!insn
6836 || GET_CODE (PATTERN (insn)) == ASM_INPUT
6837 || asm_noperands (PATTERN (insn)) >= 0)
6838 break;
6839 if (get_attr_length (insn) == 4
6840 && jump_insn == next_active_insn (insn))
6841 return TRUE;
6842 if (get_attr_length (insn) > 0)
6843 break;
6844 }
6845
6846 return FALSE;
6847 }
6848
6849 /* This routine handles all the normal conditional branch sequences we
6850 might need to generate. It handles compare immediate vs compare
6851 register, nullification of delay slots, varying length branches,
6852 negated branches, and all combinations of the above. It returns the
6853 output appropriate to emit the branch corresponding to all given
6854 parameters. */
6855
6856 const char *
6857 pa_output_cbranch (rtx *operands, int negated, rtx_insn *insn)
6858 {
6859 static char buf[100];
6860 bool useskip;
6861 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6862 int length = get_attr_length (insn);
6863 int xdelay;
6864
6865 /* A conditional branch to the following instruction (e.g. the delay slot)
6866 is asking for a disaster. This can happen when not optimizing and
6867 when jump optimization fails.
6868
6869 While it is usually safe to emit nothing, this can fail if the
6870 preceding instruction is a nullified branch with an empty delay
6871 slot and the same branch target as this branch. We could check
6872 for this but jump optimization should eliminate nop jumps. It
6873 is always safe to emit a nop. */
6874 if (branch_to_delay_slot_p (insn))
6875 return "nop";
6876
6877 /* The doubleword form of the cmpib instruction doesn't have the LEU
6878 and GTU conditions while the cmpb instruction does. Since we accept
6879 zero for cmpb, we must ensure that we use cmpb for the comparison. */
6880 if (GET_MODE (operands[1]) == DImode && operands[2] == const0_rtx)
6881 operands[2] = gen_rtx_REG (DImode, 0);
6882 if (GET_MODE (operands[2]) == DImode && operands[1] == const0_rtx)
6883 operands[1] = gen_rtx_REG (DImode, 0);
6884
6885 /* If this is a long branch with its delay slot unfilled, set `nullify'
6886 as it can nullify the delay slot and save a nop. */
6887 if (length == 8 && dbr_sequence_length () == 0)
6888 nullify = 1;
6889
6890 /* If this is a short forward conditional branch which did not get
6891 its delay slot filled, the delay slot can still be nullified. */
6892 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6893 nullify = forward_branch_p (insn);
6894
6895 /* A forward branch over a single nullified insn can be done with a
6896 comclr instruction. This avoids a single cycle penalty due to
6897 mis-predicted branch if we fall through (branch not taken). */
6898 useskip = (length == 4 && nullify) ? use_skip_p (insn) : FALSE;
6899
6900 switch (length)
6901 {
6902 /* All short conditional branches except backwards with an unfilled
6903 delay slot. */
6904 case 4:
6905 if (useskip)
6906 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6907 else
6908 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6909 if (GET_MODE (operands[1]) == DImode)
6910 strcat (buf, "*");
6911 if (negated)
6912 strcat (buf, "%B3");
6913 else
6914 strcat (buf, "%S3");
6915 if (useskip)
6916 strcat (buf, " %2,%r1,%%r0");
6917 else if (nullify)
6918 {
6919 if (branch_needs_nop_p (insn))
6920 strcat (buf, ",n %2,%r1,%0%#");
6921 else
6922 strcat (buf, ",n %2,%r1,%0");
6923 }
6924 else
6925 strcat (buf, " %2,%r1,%0");
6926 break;
6927
6928 /* All long conditionals. Note a short backward branch with an
6929 unfilled delay slot is treated just like a long backward branch
6930 with an unfilled delay slot. */
6931 case 8:
6932 /* Handle weird backwards branch with a filled delay slot
6933 which is nullified. */
6934 if (dbr_sequence_length () != 0
6935 && ! forward_branch_p (insn)
6936 && nullify)
6937 {
6938 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6939 if (GET_MODE (operands[1]) == DImode)
6940 strcat (buf, "*");
6941 if (negated)
6942 strcat (buf, "%S3");
6943 else
6944 strcat (buf, "%B3");
6945 strcat (buf, ",n %2,%r1,.+12\n\tb %0");
6946 }
6947 /* Handle short backwards branch with an unfilled delay slot.
6948 Using a comb;nop rather than comiclr;bl saves 1 cycle for both
6949 taken and untaken branches. */
6950 else if (dbr_sequence_length () == 0
6951 && ! forward_branch_p (insn)
6952 && INSN_ADDRESSES_SET_P ()
6953 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6954 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6955 {
6956 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6957 if (GET_MODE (operands[1]) == DImode)
6958 strcat (buf, "*");
6959 if (negated)
6960 strcat (buf, "%B3 %2,%r1,%0%#");
6961 else
6962 strcat (buf, "%S3 %2,%r1,%0%#");
6963 }
6964 else
6965 {
6966 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6967 if (GET_MODE (operands[1]) == DImode)
6968 strcat (buf, "*");
6969 if (negated)
6970 strcat (buf, "%S3");
6971 else
6972 strcat (buf, "%B3");
6973 if (nullify)
6974 strcat (buf, " %2,%r1,%%r0\n\tb,n %0");
6975 else
6976 strcat (buf, " %2,%r1,%%r0\n\tb %0");
6977 }
6978 break;
6979
6980 default:
6981 /* The reversed conditional branch must branch over one additional
6982 instruction if the delay slot is filled and needs to be extracted
6983 by pa_output_lbranch. If the delay slot is empty or this is a
6984 nullified forward branch, the instruction after the reversed
6985 condition branch must be nullified. */
6986 if (dbr_sequence_length () == 0
6987 || (nullify && forward_branch_p (insn)))
6988 {
6989 nullify = 1;
6990 xdelay = 0;
6991 operands[4] = GEN_INT (length);
6992 }
6993 else
6994 {
6995 xdelay = 1;
6996 operands[4] = GEN_INT (length + 4);
6997 }
6998
6999 /* Create a reversed conditional branch which branches around
7000 the following insns. */
7001 if (GET_MODE (operands[1]) != DImode)
7002 {
7003 if (nullify)
7004 {
7005 if (negated)
7006 strcpy (buf,
7007 "{com%I2b,%S3,n %2,%r1,.+%4|cmp%I2b,%S3,n %2,%r1,.+%4}");
7008 else
7009 strcpy (buf,
7010 "{com%I2b,%B3,n %2,%r1,.+%4|cmp%I2b,%B3,n %2,%r1,.+%4}");
7011 }
7012 else
7013 {
7014 if (negated)
7015 strcpy (buf,
7016 "{com%I2b,%S3 %2,%r1,.+%4|cmp%I2b,%S3 %2,%r1,.+%4}");
7017 else
7018 strcpy (buf,
7019 "{com%I2b,%B3 %2,%r1,.+%4|cmp%I2b,%B3 %2,%r1,.+%4}");
7020 }
7021 }
7022 else
7023 {
7024 if (nullify)
7025 {
7026 if (negated)
7027 strcpy (buf,
7028 "{com%I2b,*%S3,n %2,%r1,.+%4|cmp%I2b,*%S3,n %2,%r1,.+%4}");
7029 else
7030 strcpy (buf,
7031 "{com%I2b,*%B3,n %2,%r1,.+%4|cmp%I2b,*%B3,n %2,%r1,.+%4}");
7032 }
7033 else
7034 {
7035 if (negated)
7036 strcpy (buf,
7037 "{com%I2b,*%S3 %2,%r1,.+%4|cmp%I2b,*%S3 %2,%r1,.+%4}");
7038 else
7039 strcpy (buf,
7040 "{com%I2b,*%B3 %2,%r1,.+%4|cmp%I2b,*%B3 %2,%r1,.+%4}");
7041 }
7042 }
7043
7044 output_asm_insn (buf, operands);
7045 return pa_output_lbranch (operands[0], insn, xdelay);
7046 }
7047 return buf;
7048 }
7049
7050 /* Output a PIC pc-relative instruction sequence to load the address of
7051 OPERANDS[0] to register OPERANDS[2]. OPERANDS[0] is a symbol ref
7052 or a code label. OPERANDS[1] specifies the register to use to load
7053 the program counter. OPERANDS[3] may be used for label generation
7054 The sequence is always three instructions in length. The program
7055 counter recorded for PA 1.X is eight bytes more than that for PA 2.0.
7056 Register %r1 is clobbered. */
7057
7058 static void
7059 pa_output_pic_pcrel_sequence (rtx *operands)
7060 {
7061 gcc_assert (SYMBOL_REF_P (operands[0]) || LABEL_P (operands[0]));
7062 if (TARGET_PA_20)
7063 {
7064 /* We can use mfia to determine the current program counter. */
7065 if (TARGET_SOM || !TARGET_GAS)
7066 {
7067 operands[3] = gen_label_rtx ();
7068 targetm.asm_out.internal_label (asm_out_file, "L",
7069 CODE_LABEL_NUMBER (operands[3]));
7070 output_asm_insn ("mfia %1", operands);
7071 output_asm_insn ("addil L'%0-%l3,%1", operands);
7072 output_asm_insn ("ldo R'%0-%l3(%%r1),%2", operands);
7073 }
7074 else
7075 {
7076 output_asm_insn ("mfia %1", operands);
7077 output_asm_insn ("addil L'%0-$PIC_pcrel$0+12,%1", operands);
7078 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+16(%%r1),%2", operands);
7079 }
7080 }
7081 else
7082 {
7083 /* We need to use a branch to determine the current program counter. */
7084 output_asm_insn ("{bl|b,l} .+8,%1", operands);
7085 if (TARGET_SOM || !TARGET_GAS)
7086 {
7087 operands[3] = gen_label_rtx ();
7088 output_asm_insn ("addil L'%0-%l3,%1", operands);
7089 targetm.asm_out.internal_label (asm_out_file, "L",
7090 CODE_LABEL_NUMBER (operands[3]));
7091 output_asm_insn ("ldo R'%0-%l3(%%r1),%2", operands);
7092 }
7093 else
7094 {
7095 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%1", operands);
7096 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%2", operands);
7097 }
7098 }
7099 }
7100
7101 /* This routine handles output of long unconditional branches that
7102 exceed the maximum range of a simple branch instruction. Since
7103 we don't have a register available for the branch, we save register
7104 %r1 in the frame marker, load the branch destination DEST into %r1,
7105 execute the branch, and restore %r1 in the delay slot of the branch.
7106
7107 Since long branches may have an insn in the delay slot and the
7108 delay slot is used to restore %r1, we in general need to extract
7109 this insn and execute it before the branch. However, to facilitate
7110 use of this function by conditional branches, we also provide an
7111 option to not extract the delay insn so that it will be emitted
7112 after the long branch. So, if there is an insn in the delay slot,
7113 it is extracted if XDELAY is nonzero.
7114
7115 The lengths of the various long-branch sequences are 20, 16 and 24
7116 bytes for the portable runtime, non-PIC and PIC cases, respectively. */
7117
7118 const char *
7119 pa_output_lbranch (rtx dest, rtx_insn *insn, int xdelay)
7120 {
7121 rtx xoperands[4];
7122
7123 xoperands[0] = dest;
7124
7125 /* First, free up the delay slot. */
7126 if (xdelay && dbr_sequence_length () != 0)
7127 {
7128 /* We can't handle a jump in the delay slot. */
7129 gcc_assert (! JUMP_P (NEXT_INSN (insn)));
7130
7131 final_scan_insn (NEXT_INSN (insn), asm_out_file,
7132 optimize, 0, NULL);
7133
7134 /* Now delete the delay insn. */
7135 SET_INSN_DELETED (NEXT_INSN (insn));
7136 }
7137
7138 /* Output an insn to save %r1. The runtime documentation doesn't
7139 specify whether the "Clean Up" slot in the callers frame can
7140 be clobbered by the callee. It isn't copied by HP's builtin
7141 alloca, so this suggests that it can be clobbered if necessary.
7142 The "Static Link" location is copied by HP builtin alloca, so
7143 we avoid using it. Using the cleanup slot might be a problem
7144 if we have to interoperate with languages that pass cleanup
7145 information. However, it should be possible to handle these
7146 situations with GCC's asm feature.
7147
7148 The "Current RP" slot is reserved for the called procedure, so
7149 we try to use it when we don't have a frame of our own. It's
7150 rather unlikely that we won't have a frame when we need to emit
7151 a very long branch.
7152
7153 Really the way to go long term is a register scavenger; goto
7154 the target of the jump and find a register which we can use
7155 as a scratch to hold the value in %r1. Then, we wouldn't have
7156 to free up the delay slot or clobber a slot that may be needed
7157 for other purposes. */
7158 if (TARGET_64BIT)
7159 {
7160 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
7161 /* Use the return pointer slot in the frame marker. */
7162 output_asm_insn ("std %%r1,-16(%%r30)", xoperands);
7163 else
7164 /* Use the slot at -40 in the frame marker since HP builtin
7165 alloca doesn't copy it. */
7166 output_asm_insn ("std %%r1,-40(%%r30)", xoperands);
7167 }
7168 else
7169 {
7170 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
7171 /* Use the return pointer slot in the frame marker. */
7172 output_asm_insn ("stw %%r1,-20(%%r30)", xoperands);
7173 else
7174 /* Use the "Clean Up" slot in the frame marker. In GCC,
7175 the only other use of this location is for copying a
7176 floating point double argument from a floating-point
7177 register to two general registers. The copy is done
7178 as an "atomic" operation when outputting a call, so it
7179 won't interfere with our using the location here. */
7180 output_asm_insn ("stw %%r1,-12(%%r30)", xoperands);
7181 }
7182
7183 if (TARGET_PORTABLE_RUNTIME)
7184 {
7185 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7186 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
7187 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7188 }
7189 else if (flag_pic)
7190 {
7191 xoperands[1] = gen_rtx_REG (Pmode, 1);
7192 xoperands[2] = xoperands[1];
7193 pa_output_pic_pcrel_sequence (xoperands);
7194 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7195 }
7196 else
7197 /* Now output a very long branch to the original target. */
7198 output_asm_insn ("ldil L'%l0,%%r1\n\tbe R'%l0(%%sr4,%%r1)", xoperands);
7199
7200 /* Now restore the value of %r1 in the delay slot. */
7201 if (TARGET_64BIT)
7202 {
7203 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
7204 return "ldd -16(%%r30),%%r1";
7205 else
7206 return "ldd -40(%%r30),%%r1";
7207 }
7208 else
7209 {
7210 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
7211 return "ldw -20(%%r30),%%r1";
7212 else
7213 return "ldw -12(%%r30),%%r1";
7214 }
7215 }
7216
7217 /* This routine handles all the branch-on-bit conditional branch sequences we
7218 might need to generate. It handles nullification of delay slots,
7219 varying length branches, negated branches and all combinations of the
7220 above. it returns the appropriate output template to emit the branch. */
7221
7222 const char *
7223 pa_output_bb (rtx *operands ATTRIBUTE_UNUSED, int negated, rtx_insn *insn, int which)
7224 {
7225 static char buf[100];
7226 bool useskip;
7227 int nullify = INSN_ANNULLED_BRANCH_P (insn);
7228 int length = get_attr_length (insn);
7229 int xdelay;
7230
7231 /* A conditional branch to the following instruction (e.g. the delay slot) is
7232 asking for a disaster. I do not think this can happen as this pattern
7233 is only used when optimizing; jump optimization should eliminate the
7234 jump. But be prepared just in case. */
7235
7236 if (branch_to_delay_slot_p (insn))
7237 return "nop";
7238
7239 /* If this is a long branch with its delay slot unfilled, set `nullify'
7240 as it can nullify the delay slot and save a nop. */
7241 if (length == 8 && dbr_sequence_length () == 0)
7242 nullify = 1;
7243
7244 /* If this is a short forward conditional branch which did not get
7245 its delay slot filled, the delay slot can still be nullified. */
7246 if (! nullify && length == 4 && dbr_sequence_length () == 0)
7247 nullify = forward_branch_p (insn);
7248
7249 /* A forward branch over a single nullified insn can be done with a
7250 extrs instruction. This avoids a single cycle penalty due to
7251 mis-predicted branch if we fall through (branch not taken). */
7252 useskip = (length == 4 && nullify) ? use_skip_p (insn) : FALSE;
7253
7254 switch (length)
7255 {
7256
7257 /* All short conditional branches except backwards with an unfilled
7258 delay slot. */
7259 case 4:
7260 if (useskip)
7261 strcpy (buf, "{extrs,|extrw,s,}");
7262 else
7263 strcpy (buf, "bb,");
7264 if (useskip && GET_MODE (operands[0]) == DImode)
7265 strcpy (buf, "extrd,s,*");
7266 else if (GET_MODE (operands[0]) == DImode)
7267 strcpy (buf, "bb,*");
7268 if ((which == 0 && negated)
7269 || (which == 1 && ! negated))
7270 strcat (buf, ">=");
7271 else
7272 strcat (buf, "<");
7273 if (useskip)
7274 strcat (buf, " %0,%1,1,%%r0");
7275 else if (nullify && negated)
7276 {
7277 if (branch_needs_nop_p (insn))
7278 strcat (buf, ",n %0,%1,%3%#");
7279 else
7280 strcat (buf, ",n %0,%1,%3");
7281 }
7282 else if (nullify && ! negated)
7283 {
7284 if (branch_needs_nop_p (insn))
7285 strcat (buf, ",n %0,%1,%2%#");
7286 else
7287 strcat (buf, ",n %0,%1,%2");
7288 }
7289 else if (! nullify && negated)
7290 strcat (buf, " %0,%1,%3");
7291 else if (! nullify && ! negated)
7292 strcat (buf, " %0,%1,%2");
7293 break;
7294
7295 /* All long conditionals. Note a short backward branch with an
7296 unfilled delay slot is treated just like a long backward branch
7297 with an unfilled delay slot. */
7298 case 8:
7299 /* Handle weird backwards branch with a filled delay slot
7300 which is nullified. */
7301 if (dbr_sequence_length () != 0
7302 && ! forward_branch_p (insn)
7303 && nullify)
7304 {
7305 strcpy (buf, "bb,");
7306 if (GET_MODE (operands[0]) == DImode)
7307 strcat (buf, "*");
7308 if ((which == 0 && negated)
7309 || (which == 1 && ! negated))
7310 strcat (buf, "<");
7311 else
7312 strcat (buf, ">=");
7313 if (negated)
7314 strcat (buf, ",n %0,%1,.+12\n\tb %3");
7315 else
7316 strcat (buf, ",n %0,%1,.+12\n\tb %2");
7317 }
7318 /* Handle short backwards branch with an unfilled delay slot.
7319 Using a bb;nop rather than extrs;bl saves 1 cycle for both
7320 taken and untaken branches. */
7321 else if (dbr_sequence_length () == 0
7322 && ! forward_branch_p (insn)
7323 && INSN_ADDRESSES_SET_P ()
7324 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7325 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7326 {
7327 strcpy (buf, "bb,");
7328 if (GET_MODE (operands[0]) == DImode)
7329 strcat (buf, "*");
7330 if ((which == 0 && negated)
7331 || (which == 1 && ! negated))
7332 strcat (buf, ">=");
7333 else
7334 strcat (buf, "<");
7335 if (negated)
7336 strcat (buf, " %0,%1,%3%#");
7337 else
7338 strcat (buf, " %0,%1,%2%#");
7339 }
7340 else
7341 {
7342 if (GET_MODE (operands[0]) == DImode)
7343 strcpy (buf, "extrd,s,*");
7344 else
7345 strcpy (buf, "{extrs,|extrw,s,}");
7346 if ((which == 0 && negated)
7347 || (which == 1 && ! negated))
7348 strcat (buf, "<");
7349 else
7350 strcat (buf, ">=");
7351 if (nullify && negated)
7352 strcat (buf, " %0,%1,1,%%r0\n\tb,n %3");
7353 else if (nullify && ! negated)
7354 strcat (buf, " %0,%1,1,%%r0\n\tb,n %2");
7355 else if (negated)
7356 strcat (buf, " %0,%1,1,%%r0\n\tb %3");
7357 else
7358 strcat (buf, " %0,%1,1,%%r0\n\tb %2");
7359 }
7360 break;
7361
7362 default:
7363 /* The reversed conditional branch must branch over one additional
7364 instruction if the delay slot is filled and needs to be extracted
7365 by pa_output_lbranch. If the delay slot is empty or this is a
7366 nullified forward branch, the instruction after the reversed
7367 condition branch must be nullified. */
7368 if (dbr_sequence_length () == 0
7369 || (nullify && forward_branch_p (insn)))
7370 {
7371 nullify = 1;
7372 xdelay = 0;
7373 operands[4] = GEN_INT (length);
7374 }
7375 else
7376 {
7377 xdelay = 1;
7378 operands[4] = GEN_INT (length + 4);
7379 }
7380
7381 if (GET_MODE (operands[0]) == DImode)
7382 strcpy (buf, "bb,*");
7383 else
7384 strcpy (buf, "bb,");
7385 if ((which == 0 && negated)
7386 || (which == 1 && !negated))
7387 strcat (buf, "<");
7388 else
7389 strcat (buf, ">=");
7390 if (nullify)
7391 strcat (buf, ",n %0,%1,.+%4");
7392 else
7393 strcat (buf, " %0,%1,.+%4");
7394 output_asm_insn (buf, operands);
7395 return pa_output_lbranch (negated ? operands[3] : operands[2],
7396 insn, xdelay);
7397 }
7398 return buf;
7399 }
7400
7401 /* This routine handles all the branch-on-variable-bit conditional branch
7402 sequences we might need to generate. It handles nullification of delay
7403 slots, varying length branches, negated branches and all combinations
7404 of the above. it returns the appropriate output template to emit the
7405 branch. */
7406
7407 const char *
7408 pa_output_bvb (rtx *operands ATTRIBUTE_UNUSED, int negated, rtx_insn *insn,
7409 int which)
7410 {
7411 static char buf[100];
7412 bool useskip;
7413 int nullify = INSN_ANNULLED_BRANCH_P (insn);
7414 int length = get_attr_length (insn);
7415 int xdelay;
7416
7417 /* A conditional branch to the following instruction (e.g. the delay slot) is
7418 asking for a disaster. I do not think this can happen as this pattern
7419 is only used when optimizing; jump optimization should eliminate the
7420 jump. But be prepared just in case. */
7421
7422 if (branch_to_delay_slot_p (insn))
7423 return "nop";
7424
7425 /* If this is a long branch with its delay slot unfilled, set `nullify'
7426 as it can nullify the delay slot and save a nop. */
7427 if (length == 8 && dbr_sequence_length () == 0)
7428 nullify = 1;
7429
7430 /* If this is a short forward conditional branch which did not get
7431 its delay slot filled, the delay slot can still be nullified. */
7432 if (! nullify && length == 4 && dbr_sequence_length () == 0)
7433 nullify = forward_branch_p (insn);
7434
7435 /* A forward branch over a single nullified insn can be done with a
7436 extrs instruction. This avoids a single cycle penalty due to
7437 mis-predicted branch if we fall through (branch not taken). */
7438 useskip = (length == 4 && nullify) ? use_skip_p (insn) : FALSE;
7439
7440 switch (length)
7441 {
7442
7443 /* All short conditional branches except backwards with an unfilled
7444 delay slot. */
7445 case 4:
7446 if (useskip)
7447 strcpy (buf, "{vextrs,|extrw,s,}");
7448 else
7449 strcpy (buf, "{bvb,|bb,}");
7450 if (useskip && GET_MODE (operands[0]) == DImode)
7451 strcpy (buf, "extrd,s,*");
7452 else if (GET_MODE (operands[0]) == DImode)
7453 strcpy (buf, "bb,*");
7454 if ((which == 0 && negated)
7455 || (which == 1 && ! negated))
7456 strcat (buf, ">=");
7457 else
7458 strcat (buf, "<");
7459 if (useskip)
7460 strcat (buf, "{ %0,1,%%r0| %0,%%sar,1,%%r0}");
7461 else if (nullify && negated)
7462 {
7463 if (branch_needs_nop_p (insn))
7464 strcat (buf, "{,n %0,%3%#|,n %0,%%sar,%3%#}");
7465 else
7466 strcat (buf, "{,n %0,%3|,n %0,%%sar,%3}");
7467 }
7468 else if (nullify && ! negated)
7469 {
7470 if (branch_needs_nop_p (insn))
7471 strcat (buf, "{,n %0,%2%#|,n %0,%%sar,%2%#}");
7472 else
7473 strcat (buf, "{,n %0,%2|,n %0,%%sar,%2}");
7474 }
7475 else if (! nullify && negated)
7476 strcat (buf, "{ %0,%3| %0,%%sar,%3}");
7477 else if (! nullify && ! negated)
7478 strcat (buf, "{ %0,%2| %0,%%sar,%2}");
7479 break;
7480
7481 /* All long conditionals. Note a short backward branch with an
7482 unfilled delay slot is treated just like a long backward branch
7483 with an unfilled delay slot. */
7484 case 8:
7485 /* Handle weird backwards branch with a filled delay slot
7486 which is nullified. */
7487 if (dbr_sequence_length () != 0
7488 && ! forward_branch_p (insn)
7489 && nullify)
7490 {
7491 strcpy (buf, "{bvb,|bb,}");
7492 if (GET_MODE (operands[0]) == DImode)
7493 strcat (buf, "*");
7494 if ((which == 0 && negated)
7495 || (which == 1 && ! negated))
7496 strcat (buf, "<");
7497 else
7498 strcat (buf, ">=");
7499 if (negated)
7500 strcat (buf, "{,n %0,.+12\n\tb %3|,n %0,%%sar,.+12\n\tb %3}");
7501 else
7502 strcat (buf, "{,n %0,.+12\n\tb %2|,n %0,%%sar,.+12\n\tb %2}");
7503 }
7504 /* Handle short backwards branch with an unfilled delay slot.
7505 Using a bb;nop rather than extrs;bl saves 1 cycle for both
7506 taken and untaken branches. */
7507 else if (dbr_sequence_length () == 0
7508 && ! forward_branch_p (insn)
7509 && INSN_ADDRESSES_SET_P ()
7510 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7511 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7512 {
7513 strcpy (buf, "{bvb,|bb,}");
7514 if (GET_MODE (operands[0]) == DImode)
7515 strcat (buf, "*");
7516 if ((which == 0 && negated)
7517 || (which == 1 && ! negated))
7518 strcat (buf, ">=");
7519 else
7520 strcat (buf, "<");
7521 if (negated)
7522 strcat (buf, "{ %0,%3%#| %0,%%sar,%3%#}");
7523 else
7524 strcat (buf, "{ %0,%2%#| %0,%%sar,%2%#}");
7525 }
7526 else
7527 {
7528 strcpy (buf, "{vextrs,|extrw,s,}");
7529 if (GET_MODE (operands[0]) == DImode)
7530 strcpy (buf, "extrd,s,*");
7531 if ((which == 0 && negated)
7532 || (which == 1 && ! negated))
7533 strcat (buf, "<");
7534 else
7535 strcat (buf, ">=");
7536 if (nullify && negated)
7537 strcat (buf, "{ %0,1,%%r0\n\tb,n %3| %0,%%sar,1,%%r0\n\tb,n %3}");
7538 else if (nullify && ! negated)
7539 strcat (buf, "{ %0,1,%%r0\n\tb,n %2| %0,%%sar,1,%%r0\n\tb,n %2}");
7540 else if (negated)
7541 strcat (buf, "{ %0,1,%%r0\n\tb %3| %0,%%sar,1,%%r0\n\tb %3}");
7542 else
7543 strcat (buf, "{ %0,1,%%r0\n\tb %2| %0,%%sar,1,%%r0\n\tb %2}");
7544 }
7545 break;
7546
7547 default:
7548 /* The reversed conditional branch must branch over one additional
7549 instruction if the delay slot is filled and needs to be extracted
7550 by pa_output_lbranch. If the delay slot is empty or this is a
7551 nullified forward branch, the instruction after the reversed
7552 condition branch must be nullified. */
7553 if (dbr_sequence_length () == 0
7554 || (nullify && forward_branch_p (insn)))
7555 {
7556 nullify = 1;
7557 xdelay = 0;
7558 operands[4] = GEN_INT (length);
7559 }
7560 else
7561 {
7562 xdelay = 1;
7563 operands[4] = GEN_INT (length + 4);
7564 }
7565
7566 if (GET_MODE (operands[0]) == DImode)
7567 strcpy (buf, "bb,*");
7568 else
7569 strcpy (buf, "{bvb,|bb,}");
7570 if ((which == 0 && negated)
7571 || (which == 1 && !negated))
7572 strcat (buf, "<");
7573 else
7574 strcat (buf, ">=");
7575 if (nullify)
7576 strcat (buf, ",n {%0,.+%4|%0,%%sar,.+%4}");
7577 else
7578 strcat (buf, " {%0,.+%4|%0,%%sar,.+%4}");
7579 output_asm_insn (buf, operands);
7580 return pa_output_lbranch (negated ? operands[3] : operands[2],
7581 insn, xdelay);
7582 }
7583 return buf;
7584 }
7585
7586 /* Return the output template for emitting a dbra type insn.
7587
7588 Note it may perform some output operations on its own before
7589 returning the final output string. */
7590 const char *
7591 pa_output_dbra (rtx *operands, rtx_insn *insn, int which_alternative)
7592 {
7593 int length = get_attr_length (insn);
7594
7595 /* A conditional branch to the following instruction (e.g. the delay slot) is
7596 asking for a disaster. Be prepared! */
7597
7598 if (branch_to_delay_slot_p (insn))
7599 {
7600 if (which_alternative == 0)
7601 return "ldo %1(%0),%0";
7602 else if (which_alternative == 1)
7603 {
7604 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)", operands);
7605 output_asm_insn ("ldw -16(%%r30),%4", operands);
7606 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
7607 return "{fldws|fldw} -16(%%r30),%0";
7608 }
7609 else
7610 {
7611 output_asm_insn ("ldw %0,%4", operands);
7612 return "ldo %1(%4),%4\n\tstw %4,%0";
7613 }
7614 }
7615
7616 if (which_alternative == 0)
7617 {
7618 int nullify = INSN_ANNULLED_BRANCH_P (insn);
7619 int xdelay;
7620
7621 /* If this is a long branch with its delay slot unfilled, set `nullify'
7622 as it can nullify the delay slot and save a nop. */
7623 if (length == 8 && dbr_sequence_length () == 0)
7624 nullify = 1;
7625
7626 /* If this is a short forward conditional branch which did not get
7627 its delay slot filled, the delay slot can still be nullified. */
7628 if (! nullify && length == 4 && dbr_sequence_length () == 0)
7629 nullify = forward_branch_p (insn);
7630
7631 switch (length)
7632 {
7633 case 4:
7634 if (nullify)
7635 {
7636 if (branch_needs_nop_p (insn))
7637 return "addib,%C2,n %1,%0,%3%#";
7638 else
7639 return "addib,%C2,n %1,%0,%3";
7640 }
7641 else
7642 return "addib,%C2 %1,%0,%3";
7643
7644 case 8:
7645 /* Handle weird backwards branch with a fulled delay slot
7646 which is nullified. */
7647 if (dbr_sequence_length () != 0
7648 && ! forward_branch_p (insn)
7649 && nullify)
7650 return "addib,%N2,n %1,%0,.+12\n\tb %3";
7651 /* Handle short backwards branch with an unfilled delay slot.
7652 Using a addb;nop rather than addi;bl saves 1 cycle for both
7653 taken and untaken branches. */
7654 else if (dbr_sequence_length () == 0
7655 && ! forward_branch_p (insn)
7656 && INSN_ADDRESSES_SET_P ()
7657 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7658 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7659 return "addib,%C2 %1,%0,%3%#";
7660
7661 /* Handle normal cases. */
7662 if (nullify)
7663 return "addi,%N2 %1,%0,%0\n\tb,n %3";
7664 else
7665 return "addi,%N2 %1,%0,%0\n\tb %3";
7666
7667 default:
7668 /* The reversed conditional branch must branch over one additional
7669 instruction if the delay slot is filled and needs to be extracted
7670 by pa_output_lbranch. If the delay slot is empty or this is a
7671 nullified forward branch, the instruction after the reversed
7672 condition branch must be nullified. */
7673 if (dbr_sequence_length () == 0
7674 || (nullify && forward_branch_p (insn)))
7675 {
7676 nullify = 1;
7677 xdelay = 0;
7678 operands[4] = GEN_INT (length);
7679 }
7680 else
7681 {
7682 xdelay = 1;
7683 operands[4] = GEN_INT (length + 4);
7684 }
7685
7686 if (nullify)
7687 output_asm_insn ("addib,%N2,n %1,%0,.+%4", operands);
7688 else
7689 output_asm_insn ("addib,%N2 %1,%0,.+%4", operands);
7690
7691 return pa_output_lbranch (operands[3], insn, xdelay);
7692 }
7693
7694 }
7695 /* Deal with gross reload from FP register case. */
7696 else if (which_alternative == 1)
7697 {
7698 /* Move loop counter from FP register to MEM then into a GR,
7699 increment the GR, store the GR into MEM, and finally reload
7700 the FP register from MEM from within the branch's delay slot. */
7701 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)\n\tldw -16(%%r30),%4",
7702 operands);
7703 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
7704 if (length == 24)
7705 return "{comb|cmpb},%S2 %%r0,%4,%3\n\t{fldws|fldw} -16(%%r30),%0";
7706 else if (length == 28)
7707 return "{comclr|cmpclr},%B2 %%r0,%4,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
7708 else
7709 {
7710 operands[5] = GEN_INT (length - 16);
7711 output_asm_insn ("{comb|cmpb},%B2 %%r0,%4,.+%5", operands);
7712 output_asm_insn ("{fldws|fldw} -16(%%r30),%0", operands);
7713 return pa_output_lbranch (operands[3], insn, 0);
7714 }
7715 }
7716 /* Deal with gross reload from memory case. */
7717 else
7718 {
7719 /* Reload loop counter from memory, the store back to memory
7720 happens in the branch's delay slot. */
7721 output_asm_insn ("ldw %0,%4", operands);
7722 if (length == 12)
7723 return "addib,%C2 %1,%4,%3\n\tstw %4,%0";
7724 else if (length == 16)
7725 return "addi,%N2 %1,%4,%4\n\tb %3\n\tstw %4,%0";
7726 else
7727 {
7728 operands[5] = GEN_INT (length - 4);
7729 output_asm_insn ("addib,%N2 %1,%4,.+%5\n\tstw %4,%0", operands);
7730 return pa_output_lbranch (operands[3], insn, 0);
7731 }
7732 }
7733 }
7734
7735 /* Return the output template for emitting a movb type insn.
7736
7737 Note it may perform some output operations on its own before
7738 returning the final output string. */
7739 const char *
7740 pa_output_movb (rtx *operands, rtx_insn *insn, int which_alternative,
7741 int reverse_comparison)
7742 {
7743 int length = get_attr_length (insn);
7744
7745 /* A conditional branch to the following instruction (e.g. the delay slot) is
7746 asking for a disaster. Be prepared! */
7747
7748 if (branch_to_delay_slot_p (insn))
7749 {
7750 if (which_alternative == 0)
7751 return "copy %1,%0";
7752 else if (which_alternative == 1)
7753 {
7754 output_asm_insn ("stw %1,-16(%%r30)", operands);
7755 return "{fldws|fldw} -16(%%r30),%0";
7756 }
7757 else if (which_alternative == 2)
7758 return "stw %1,%0";
7759 else
7760 return "mtsar %r1";
7761 }
7762
7763 /* Support the second variant. */
7764 if (reverse_comparison)
7765 PUT_CODE (operands[2], reverse_condition (GET_CODE (operands[2])));
7766
7767 if (which_alternative == 0)
7768 {
7769 int nullify = INSN_ANNULLED_BRANCH_P (insn);
7770 int xdelay;
7771
7772 /* If this is a long branch with its delay slot unfilled, set `nullify'
7773 as it can nullify the delay slot and save a nop. */
7774 if (length == 8 && dbr_sequence_length () == 0)
7775 nullify = 1;
7776
7777 /* If this is a short forward conditional branch which did not get
7778 its delay slot filled, the delay slot can still be nullified. */
7779 if (! nullify && length == 4 && dbr_sequence_length () == 0)
7780 nullify = forward_branch_p (insn);
7781
7782 switch (length)
7783 {
7784 case 4:
7785 if (nullify)
7786 {
7787 if (branch_needs_nop_p (insn))
7788 return "movb,%C2,n %1,%0,%3%#";
7789 else
7790 return "movb,%C2,n %1,%0,%3";
7791 }
7792 else
7793 return "movb,%C2 %1,%0,%3";
7794
7795 case 8:
7796 /* Handle weird backwards branch with a filled delay slot
7797 which is nullified. */
7798 if (dbr_sequence_length () != 0
7799 && ! forward_branch_p (insn)
7800 && nullify)
7801 return "movb,%N2,n %1,%0,.+12\n\tb %3";
7802
7803 /* Handle short backwards branch with an unfilled delay slot.
7804 Using a movb;nop rather than or;bl saves 1 cycle for both
7805 taken and untaken branches. */
7806 else if (dbr_sequence_length () == 0
7807 && ! forward_branch_p (insn)
7808 && INSN_ADDRESSES_SET_P ()
7809 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7810 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7811 return "movb,%C2 %1,%0,%3%#";
7812 /* Handle normal cases. */
7813 if (nullify)
7814 return "or,%N2 %1,%%r0,%0\n\tb,n %3";
7815 else
7816 return "or,%N2 %1,%%r0,%0\n\tb %3";
7817
7818 default:
7819 /* The reversed conditional branch must branch over one additional
7820 instruction if the delay slot is filled and needs to be extracted
7821 by pa_output_lbranch. If the delay slot is empty or this is a
7822 nullified forward branch, the instruction after the reversed
7823 condition branch must be nullified. */
7824 if (dbr_sequence_length () == 0
7825 || (nullify && forward_branch_p (insn)))
7826 {
7827 nullify = 1;
7828 xdelay = 0;
7829 operands[4] = GEN_INT (length);
7830 }
7831 else
7832 {
7833 xdelay = 1;
7834 operands[4] = GEN_INT (length + 4);
7835 }
7836
7837 if (nullify)
7838 output_asm_insn ("movb,%N2,n %1,%0,.+%4", operands);
7839 else
7840 output_asm_insn ("movb,%N2 %1,%0,.+%4", operands);
7841
7842 return pa_output_lbranch (operands[3], insn, xdelay);
7843 }
7844 }
7845 /* Deal with gross reload for FP destination register case. */
7846 else if (which_alternative == 1)
7847 {
7848 /* Move source register to MEM, perform the branch test, then
7849 finally load the FP register from MEM from within the branch's
7850 delay slot. */
7851 output_asm_insn ("stw %1,-16(%%r30)", operands);
7852 if (length == 12)
7853 return "{comb|cmpb},%S2 %%r0,%1,%3\n\t{fldws|fldw} -16(%%r30),%0";
7854 else if (length == 16)
7855 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
7856 else
7857 {
7858 operands[4] = GEN_INT (length - 4);
7859 output_asm_insn ("{comb|cmpb},%B2 %%r0,%1,.+%4", operands);
7860 output_asm_insn ("{fldws|fldw} -16(%%r30),%0", operands);
7861 return pa_output_lbranch (operands[3], insn, 0);
7862 }
7863 }
7864 /* Deal with gross reload from memory case. */
7865 else if (which_alternative == 2)
7866 {
7867 /* Reload loop counter from memory, the store back to memory
7868 happens in the branch's delay slot. */
7869 if (length == 8)
7870 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tstw %1,%0";
7871 else if (length == 12)
7872 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tstw %1,%0";
7873 else
7874 {
7875 operands[4] = GEN_INT (length);
7876 output_asm_insn ("{comb|cmpb},%B2 %%r0,%1,.+%4\n\tstw %1,%0",
7877 operands);
7878 return pa_output_lbranch (operands[3], insn, 0);
7879 }
7880 }
7881 /* Handle SAR as a destination. */
7882 else
7883 {
7884 if (length == 8)
7885 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tmtsar %r1";
7886 else if (length == 12)
7887 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tmtsar %r1";
7888 else
7889 {
7890 operands[4] = GEN_INT (length);
7891 output_asm_insn ("{comb|cmpb},%B2 %%r0,%1,.+%4\n\tmtsar %r1",
7892 operands);
7893 return pa_output_lbranch (operands[3], insn, 0);
7894 }
7895 }
7896 }
7897
7898 /* Copy any FP arguments in INSN into integer registers. */
7899 static void
7900 copy_fp_args (rtx_insn *insn)
7901 {
7902 rtx link;
7903 rtx xoperands[2];
7904
7905 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7906 {
7907 int arg_mode, regno;
7908 rtx use = XEXP (link, 0);
7909
7910 if (! (GET_CODE (use) == USE
7911 && GET_CODE (XEXP (use, 0)) == REG
7912 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7913 continue;
7914
7915 arg_mode = GET_MODE (XEXP (use, 0));
7916 regno = REGNO (XEXP (use, 0));
7917
7918 /* Is it a floating point register? */
7919 if (regno >= 32 && regno <= 39)
7920 {
7921 /* Copy the FP register into an integer register via memory. */
7922 if (arg_mode == SFmode)
7923 {
7924 xoperands[0] = XEXP (use, 0);
7925 xoperands[1] = gen_rtx_REG (SImode, 26 - (regno - 32) / 2);
7926 output_asm_insn ("{fstws|fstw} %0,-16(%%sr0,%%r30)", xoperands);
7927 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7928 }
7929 else
7930 {
7931 xoperands[0] = XEXP (use, 0);
7932 xoperands[1] = gen_rtx_REG (DImode, 25 - (regno - 34) / 2);
7933 output_asm_insn ("{fstds|fstd} %0,-16(%%sr0,%%r30)", xoperands);
7934 output_asm_insn ("ldw -12(%%sr0,%%r30),%R1", xoperands);
7935 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7936 }
7937 }
7938 }
7939 }
7940
7941 /* Compute length of the FP argument copy sequence for INSN. */
7942 static int
7943 length_fp_args (rtx_insn *insn)
7944 {
7945 int length = 0;
7946 rtx link;
7947
7948 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7949 {
7950 int arg_mode, regno;
7951 rtx use = XEXP (link, 0);
7952
7953 if (! (GET_CODE (use) == USE
7954 && GET_CODE (XEXP (use, 0)) == REG
7955 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7956 continue;
7957
7958 arg_mode = GET_MODE (XEXP (use, 0));
7959 regno = REGNO (XEXP (use, 0));
7960
7961 /* Is it a floating point register? */
7962 if (regno >= 32 && regno <= 39)
7963 {
7964 if (arg_mode == SFmode)
7965 length += 8;
7966 else
7967 length += 12;
7968 }
7969 }
7970
7971 return length;
7972 }
7973
7974 /* Return the attribute length for the millicode call instruction INSN.
7975 The length must match the code generated by pa_output_millicode_call.
7976 We include the delay slot in the returned length as it is better to
7977 over estimate the length than to under estimate it. */
7978
7979 int
7980 pa_attr_length_millicode_call (rtx_insn *insn)
7981 {
7982 unsigned long distance = -1;
7983 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7984
7985 if (INSN_ADDRESSES_SET_P ())
7986 {
7987 distance = (total + insn_current_reference_address (insn));
7988 if (distance < total)
7989 distance = -1;
7990 }
7991
7992 if (TARGET_64BIT)
7993 {
7994 if (!TARGET_LONG_CALLS && distance < 7600000)
7995 return 8;
7996
7997 return 20;
7998 }
7999 else if (TARGET_PORTABLE_RUNTIME)
8000 return 24;
8001 else
8002 {
8003 if (!TARGET_LONG_CALLS && distance < MAX_PCREL17F_OFFSET)
8004 return 8;
8005
8006 if (!flag_pic)
8007 return 12;
8008
8009 return 24;
8010 }
8011 }
8012
8013 /* INSN is a function call.
8014
8015 CALL_DEST is the routine we are calling. */
8016
8017 const char *
8018 pa_output_millicode_call (rtx_insn *insn, rtx call_dest)
8019 {
8020 int attr_length = get_attr_length (insn);
8021 int seq_length = dbr_sequence_length ();
8022 rtx xoperands[4];
8023
8024 xoperands[0] = call_dest;
8025
8026 /* Handle the common case where we are sure that the branch will
8027 reach the beginning of the $CODE$ subspace. The within reach
8028 form of the $$sh_func_adrs call has a length of 28. Because it
8029 has an attribute type of sh_func_adrs, it never has a nonzero
8030 sequence length (i.e., the delay slot is never filled). */
8031 if (!TARGET_LONG_CALLS
8032 && (attr_length == 8
8033 || (attr_length == 28
8034 && get_attr_type (insn) == TYPE_SH_FUNC_ADRS)))
8035 {
8036 xoperands[1] = gen_rtx_REG (Pmode, TARGET_64BIT ? 2 : 31);
8037 output_asm_insn ("{bl|b,l} %0,%1", xoperands);
8038 }
8039 else
8040 {
8041 if (TARGET_64BIT)
8042 {
8043 /* It might seem that one insn could be saved by accessing
8044 the millicode function using the linkage table. However,
8045 this doesn't work in shared libraries and other dynamically
8046 loaded objects. Using a pc-relative sequence also avoids
8047 problems related to the implicit use of the gp register. */
8048 xoperands[1] = gen_rtx_REG (Pmode, 1);
8049 xoperands[2] = xoperands[1];
8050 pa_output_pic_pcrel_sequence (xoperands);
8051 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
8052 }
8053 else if (TARGET_PORTABLE_RUNTIME)
8054 {
8055 /* Pure portable runtime doesn't allow be/ble; we also don't
8056 have PIC support in the assembler/linker, so this sequence
8057 is needed. */
8058
8059 /* Get the address of our target into %r1. */
8060 output_asm_insn ("ldil L'%0,%%r1", xoperands);
8061 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
8062
8063 /* Get our return address into %r31. */
8064 output_asm_insn ("{bl|b,l} .+8,%%r31", xoperands);
8065 output_asm_insn ("addi 8,%%r31,%%r31", xoperands);
8066
8067 /* Jump to our target address in %r1. */
8068 output_asm_insn ("bv %%r0(%%r1)", xoperands);
8069 }
8070 else if (!flag_pic)
8071 {
8072 output_asm_insn ("ldil L'%0,%%r1", xoperands);
8073 if (TARGET_PA_20)
8074 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31", xoperands);
8075 else
8076 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
8077 }
8078 else
8079 {
8080 xoperands[1] = gen_rtx_REG (Pmode, 31);
8081 xoperands[2] = gen_rtx_REG (Pmode, 1);
8082 pa_output_pic_pcrel_sequence (xoperands);
8083
8084 /* Adjust return address. */
8085 output_asm_insn ("ldo {16|24}(%%r31),%%r31", xoperands);
8086
8087 /* Jump to our target address in %r1. */
8088 output_asm_insn ("bv %%r0(%%r1)", xoperands);
8089 }
8090 }
8091
8092 if (seq_length == 0)
8093 output_asm_insn ("nop", xoperands);
8094
8095 return "";
8096 }
8097
8098 /* Return the attribute length of the call instruction INSN. The SIBCALL
8099 flag indicates whether INSN is a regular call or a sibling call. The
8100 length returned must be longer than the code actually generated by
8101 pa_output_call. Since branch shortening is done before delay branch
8102 sequencing, there is no way to determine whether or not the delay
8103 slot will be filled during branch shortening. Even when the delay
8104 slot is filled, we may have to add a nop if the delay slot contains
8105 a branch that can't reach its target. Thus, we always have to include
8106 the delay slot in the length estimate. This used to be done in
8107 pa_adjust_insn_length but we do it here now as some sequences always
8108 fill the delay slot and we can save four bytes in the estimate for
8109 these sequences. */
8110
8111 int
8112 pa_attr_length_call (rtx_insn *insn, int sibcall)
8113 {
8114 int local_call;
8115 rtx call, call_dest;
8116 tree call_decl;
8117 int length = 0;
8118 rtx pat = PATTERN (insn);
8119 unsigned long distance = -1;
8120
8121 gcc_assert (CALL_P (insn));
8122
8123 if (INSN_ADDRESSES_SET_P ())
8124 {
8125 unsigned long total;
8126
8127 total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
8128 distance = (total + insn_current_reference_address (insn));
8129 if (distance < total)
8130 distance = -1;
8131 }
8132
8133 gcc_assert (GET_CODE (pat) == PARALLEL);
8134
8135 /* Get the call rtx. */
8136 call = XVECEXP (pat, 0, 0);
8137 if (GET_CODE (call) == SET)
8138 call = SET_SRC (call);
8139
8140 gcc_assert (GET_CODE (call) == CALL);
8141
8142 /* Determine if this is a local call. */
8143 call_dest = XEXP (XEXP (call, 0), 0);
8144 call_decl = SYMBOL_REF_DECL (call_dest);
8145 local_call = call_decl && targetm.binds_local_p (call_decl);
8146
8147 /* pc-relative branch. */
8148 if (!TARGET_LONG_CALLS
8149 && ((TARGET_PA_20 && !sibcall && distance < 7600000)
8150 || distance < MAX_PCREL17F_OFFSET))
8151 length += 8;
8152
8153 /* 64-bit plabel sequence. */
8154 else if (TARGET_64BIT && !local_call)
8155 length += 24;
8156
8157 /* non-pic long absolute branch sequence. */
8158 else if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
8159 length += 12;
8160
8161 /* long pc-relative branch sequence. */
8162 else if (TARGET_LONG_PIC_SDIFF_CALL
8163 || (TARGET_GAS && !TARGET_SOM && local_call))
8164 {
8165 length += 20;
8166
8167 if (!TARGET_PA_20 && !TARGET_NO_SPACE_REGS && (!local_call || flag_pic))
8168 length += 8;
8169 }
8170
8171 /* 32-bit plabel sequence. */
8172 else
8173 {
8174 length += 32;
8175
8176 if (TARGET_SOM)
8177 length += length_fp_args (insn);
8178
8179 if (flag_pic)
8180 length += 4;
8181
8182 if (!TARGET_PA_20)
8183 {
8184 if (!sibcall)
8185 length += 8;
8186
8187 if (!TARGET_NO_SPACE_REGS && (!local_call || flag_pic))
8188 length += 8;
8189 }
8190 }
8191
8192 return length;
8193 }
8194
8195 /* INSN is a function call.
8196
8197 CALL_DEST is the routine we are calling. */
8198
8199 const char *
8200 pa_output_call (rtx_insn *insn, rtx call_dest, int sibcall)
8201 {
8202 int seq_length = dbr_sequence_length ();
8203 tree call_decl = SYMBOL_REF_DECL (call_dest);
8204 int local_call = call_decl && targetm.binds_local_p (call_decl);
8205 rtx xoperands[4];
8206
8207 xoperands[0] = call_dest;
8208
8209 /* Handle the common case where we're sure that the branch will reach
8210 the beginning of the "$CODE$" subspace. This is the beginning of
8211 the current function if we are in a named section. */
8212 if (!TARGET_LONG_CALLS && pa_attr_length_call (insn, sibcall) == 8)
8213 {
8214 xoperands[1] = gen_rtx_REG (word_mode, sibcall ? 0 : 2);
8215 output_asm_insn ("{bl|b,l} %0,%1", xoperands);
8216 }
8217 else
8218 {
8219 if (TARGET_64BIT && !local_call)
8220 {
8221 /* ??? As far as I can tell, the HP linker doesn't support the
8222 long pc-relative sequence described in the 64-bit runtime
8223 architecture. So, we use a slightly longer indirect call. */
8224 xoperands[0] = pa_get_deferred_plabel (call_dest);
8225 xoperands[1] = gen_label_rtx ();
8226
8227 /* Put the load of %r27 into the delay slot. We don't need to
8228 do anything when generating fast indirect calls. */
8229 if (seq_length != 0)
8230 {
8231 final_scan_insn (NEXT_INSN (insn), asm_out_file,
8232 optimize, 0, NULL);
8233
8234 /* Now delete the delay insn. */
8235 SET_INSN_DELETED (NEXT_INSN (insn));
8236 }
8237
8238 output_asm_insn ("addil LT'%0,%%r27", xoperands);
8239 output_asm_insn ("ldd RT'%0(%%r1),%%r1", xoperands);
8240 output_asm_insn ("ldd 0(%%r1),%%r1", xoperands);
8241 output_asm_insn ("ldd 16(%%r1),%%r2", xoperands);
8242 output_asm_insn ("bve,l (%%r2),%%r2", xoperands);
8243 output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
8244 seq_length = 1;
8245 }
8246 else
8247 {
8248 int indirect_call = 0;
8249
8250 /* Emit a long call. There are several different sequences
8251 of increasing length and complexity. In most cases,
8252 they don't allow an instruction in the delay slot. */
8253 if (!((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
8254 && !TARGET_LONG_PIC_SDIFF_CALL
8255 && !(TARGET_GAS && !TARGET_SOM && local_call)
8256 && !TARGET_64BIT)
8257 indirect_call = 1;
8258
8259 if (seq_length != 0
8260 && !sibcall
8261 && (!TARGET_PA_20
8262 || indirect_call
8263 || ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)))
8264 {
8265 /* A non-jump insn in the delay slot. By definition we can
8266 emit this insn before the call (and in fact before argument
8267 relocating. */
8268 final_scan_insn (NEXT_INSN (insn), asm_out_file, optimize, 0,
8269 NULL);
8270
8271 /* Now delete the delay insn. */
8272 SET_INSN_DELETED (NEXT_INSN (insn));
8273 seq_length = 0;
8274 }
8275
8276 if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
8277 {
8278 /* This is the best sequence for making long calls in
8279 non-pic code. Unfortunately, GNU ld doesn't provide
8280 the stub needed for external calls, and GAS's support
8281 for this with the SOM linker is buggy. It is safe
8282 to use this for local calls. */
8283 output_asm_insn ("ldil L'%0,%%r1", xoperands);
8284 if (sibcall)
8285 output_asm_insn ("be R'%0(%%sr4,%%r1)", xoperands);
8286 else
8287 {
8288 if (TARGET_PA_20)
8289 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31",
8290 xoperands);
8291 else
8292 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
8293
8294 output_asm_insn ("copy %%r31,%%r2", xoperands);
8295 seq_length = 1;
8296 }
8297 }
8298 else
8299 {
8300 /* The HP assembler and linker can handle relocations for
8301 the difference of two symbols. The HP assembler
8302 recognizes the sequence as a pc-relative call and
8303 the linker provides stubs when needed. */
8304
8305 /* GAS currently can't generate the relocations that
8306 are needed for the SOM linker under HP-UX using this
8307 sequence. The GNU linker doesn't generate the stubs
8308 that are needed for external calls on TARGET_ELF32
8309 with this sequence. For now, we have to use a longer
8310 plabel sequence when using GAS for non local calls. */
8311 if (TARGET_LONG_PIC_SDIFF_CALL
8312 || (TARGET_GAS && !TARGET_SOM && local_call))
8313 {
8314 xoperands[1] = gen_rtx_REG (Pmode, 1);
8315 xoperands[2] = xoperands[1];
8316 pa_output_pic_pcrel_sequence (xoperands);
8317 }
8318 else
8319 {
8320 /* Emit a long plabel-based call sequence. This is
8321 essentially an inline implementation of $$dyncall.
8322 We don't actually try to call $$dyncall as this is
8323 as difficult as calling the function itself. */
8324 xoperands[0] = pa_get_deferred_plabel (call_dest);
8325 xoperands[1] = gen_label_rtx ();
8326
8327 /* Since the call is indirect, FP arguments in registers
8328 need to be copied to the general registers. Then, the
8329 argument relocation stub will copy them back. */
8330 if (TARGET_SOM)
8331 copy_fp_args (insn);
8332
8333 if (flag_pic)
8334 {
8335 output_asm_insn ("addil LT'%0,%%r19", xoperands);
8336 output_asm_insn ("ldw RT'%0(%%r1),%%r1", xoperands);
8337 output_asm_insn ("ldw 0(%%r1),%%r22", xoperands);
8338 }
8339 else
8340 {
8341 output_asm_insn ("addil LR'%0-$global$,%%r27",
8342 xoperands);
8343 output_asm_insn ("ldw RR'%0-$global$(%%r1),%%r22",
8344 xoperands);
8345 }
8346
8347 output_asm_insn ("bb,>=,n %%r22,30,.+16", xoperands);
8348 output_asm_insn ("depi 0,31,2,%%r22", xoperands);
8349 /* Should this be an ordered load to ensure the target
8350 address is loaded before the global pointer? */
8351 output_asm_insn ("ldw 0(%%r22),%%r1", xoperands);
8352 output_asm_insn ("ldw 4(%%r22),%%r19", xoperands);
8353
8354 if (!sibcall && !TARGET_PA_20)
8355 {
8356 output_asm_insn ("{bl|b,l} .+8,%%r2", xoperands);
8357 if (TARGET_NO_SPACE_REGS || (local_call && !flag_pic))
8358 output_asm_insn ("addi 8,%%r2,%%r2", xoperands);
8359 else
8360 output_asm_insn ("addi 16,%%r2,%%r2", xoperands);
8361 }
8362 }
8363
8364 if (TARGET_PA_20)
8365 {
8366 if (sibcall)
8367 output_asm_insn ("bve (%%r1)", xoperands);
8368 else
8369 {
8370 if (indirect_call)
8371 {
8372 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
8373 output_asm_insn ("stw %%r2,-24(%%sp)", xoperands);
8374 seq_length = 1;
8375 }
8376 else
8377 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
8378 }
8379 }
8380 else
8381 {
8382 if (!TARGET_NO_SPACE_REGS && (!local_call || flag_pic))
8383 output_asm_insn ("ldsid (%%r1),%%r31\n\tmtsp %%r31,%%sr0",
8384 xoperands);
8385
8386 if (sibcall)
8387 {
8388 if (TARGET_NO_SPACE_REGS || (local_call && !flag_pic))
8389 output_asm_insn ("be 0(%%sr4,%%r1)", xoperands);
8390 else
8391 output_asm_insn ("be 0(%%sr0,%%r1)", xoperands);
8392 }
8393 else
8394 {
8395 if (TARGET_NO_SPACE_REGS || (local_call && !flag_pic))
8396 output_asm_insn ("ble 0(%%sr4,%%r1)", xoperands);
8397 else
8398 output_asm_insn ("ble 0(%%sr0,%%r1)", xoperands);
8399
8400 if (indirect_call)
8401 output_asm_insn ("stw %%r31,-24(%%sp)", xoperands);
8402 else
8403 output_asm_insn ("copy %%r31,%%r2", xoperands);
8404 seq_length = 1;
8405 }
8406 }
8407 }
8408 }
8409 }
8410
8411 if (seq_length == 0)
8412 output_asm_insn ("nop", xoperands);
8413
8414 return "";
8415 }
8416
8417 /* Return the attribute length of the indirect call instruction INSN.
8418 The length must match the code generated by output_indirect call.
8419 The returned length includes the delay slot. Currently, the delay
8420 slot of an indirect call sequence is not exposed and it is used by
8421 the sequence itself. */
8422
8423 int
8424 pa_attr_length_indirect_call (rtx_insn *insn)
8425 {
8426 unsigned long distance = -1;
8427 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
8428
8429 if (INSN_ADDRESSES_SET_P ())
8430 {
8431 distance = (total + insn_current_reference_address (insn));
8432 if (distance < total)
8433 distance = -1;
8434 }
8435
8436 if (TARGET_64BIT)
8437 return 12;
8438
8439 if (TARGET_FAST_INDIRECT_CALLS)
8440 return 8;
8441
8442 if (TARGET_PORTABLE_RUNTIME)
8443 return 16;
8444
8445 if (!TARGET_LONG_CALLS
8446 && ((TARGET_PA_20 && !TARGET_SOM && distance < 7600000)
8447 || distance < MAX_PCREL17F_OFFSET))
8448 return 8;
8449
8450 /* Out of reach, can use ble. */
8451 if (!flag_pic)
8452 return 12;
8453
8454 /* Inline versions of $$dyncall. */
8455 if (!optimize_size)
8456 {
8457 if (TARGET_NO_SPACE_REGS)
8458 return 28;
8459
8460 if (TARGET_PA_20)
8461 return 32;
8462 }
8463
8464 /* Long PIC pc-relative call. */
8465 return 20;
8466 }
8467
8468 const char *
8469 pa_output_indirect_call (rtx_insn *insn, rtx call_dest)
8470 {
8471 rtx xoperands[4];
8472 int length;
8473
8474 if (TARGET_64BIT)
8475 {
8476 xoperands[0] = call_dest;
8477 output_asm_insn ("ldd 16(%0),%%r2\n\t"
8478 "bve,l (%%r2),%%r2\n\t"
8479 "ldd 24(%0),%%r27", xoperands);
8480 return "";
8481 }
8482
8483 /* First the special case for kernels, level 0 systems, etc. */
8484 if (TARGET_FAST_INDIRECT_CALLS)
8485 {
8486 pa_output_arg_descriptor (insn);
8487 if (TARGET_PA_20)
8488 return "bve,l,n (%%r22),%%r2\n\tnop";
8489 return "ble 0(%%sr4,%%r22)\n\tcopy %%r31,%%r2";
8490 }
8491
8492 if (TARGET_PORTABLE_RUNTIME)
8493 {
8494 output_asm_insn ("ldil L'$$dyncall,%%r31\n\t"
8495 "ldo R'$$dyncall(%%r31),%%r31", xoperands);
8496 pa_output_arg_descriptor (insn);
8497 return "blr %%r0,%%r2\n\tbv,n %%r0(%%r31)";
8498 }
8499
8500 /* Now the normal case -- we can reach $$dyncall directly or
8501 we're sure that we can get there via a long-branch stub.
8502
8503 No need to check target flags as the length uniquely identifies
8504 the remaining cases. */
8505 length = pa_attr_length_indirect_call (insn);
8506 if (length == 8)
8507 {
8508 pa_output_arg_descriptor (insn);
8509
8510 /* The HP linker sometimes substitutes a BLE for BL/B,L calls to
8511 $$dyncall. Since BLE uses %r31 as the link register, the 22-bit
8512 variant of the B,L instruction can't be used on the SOM target. */
8513 if (TARGET_PA_20 && !TARGET_SOM)
8514 return "b,l,n $$dyncall,%%r2\n\tnop";
8515 else
8516 return "bl $$dyncall,%%r31\n\tcopy %%r31,%%r2";
8517 }
8518
8519 /* Long millicode call, but we are not generating PIC or portable runtime
8520 code. */
8521 if (length == 12)
8522 {
8523 output_asm_insn ("ldil L'$$dyncall,%%r2", xoperands);
8524 pa_output_arg_descriptor (insn);
8525 return "ble R'$$dyncall(%%sr4,%%r2)\n\tcopy %%r31,%%r2";
8526 }
8527
8528 /* The long PIC pc-relative call sequence is five instructions. So,
8529 let's use an inline version of $$dyncall when the calling sequence
8530 has a roughly similar number of instructions and we are not optimizing
8531 for size. We need two instructions to load the return pointer plus
8532 the $$dyncall implementation. */
8533 if (!optimize_size)
8534 {
8535 if (TARGET_NO_SPACE_REGS)
8536 {
8537 pa_output_arg_descriptor (insn);
8538 output_asm_insn ("bl .+8,%%r2\n\t"
8539 "ldo 20(%%r2),%%r2\n\t"
8540 "extru,<> %%r22,30,1,%%r0\n\t"
8541 "bv,n %%r0(%%r22)\n\t"
8542 "ldw -2(%%r22),%%r21\n\t"
8543 "bv %%r0(%%r21)\n\t"
8544 "ldw 2(%%r22),%%r19", xoperands);
8545 return "";
8546 }
8547 if (TARGET_PA_20)
8548 {
8549 pa_output_arg_descriptor (insn);
8550 output_asm_insn ("bl .+8,%%r2\n\t"
8551 "ldo 24(%%r2),%%r2\n\t"
8552 "stw %%r2,-24(%%sp)\n\t"
8553 "extru,<> %r22,30,1,%%r0\n\t"
8554 "bve,n (%%r22)\n\t"
8555 "ldw -2(%%r22),%%r21\n\t"
8556 "bve (%%r21)\n\t"
8557 "ldw 2(%%r22),%%r19", xoperands);
8558 return "";
8559 }
8560 }
8561
8562 /* We need a long PIC call to $$dyncall. */
8563 xoperands[0] = gen_rtx_SYMBOL_REF (Pmode, "$$dyncall");
8564 xoperands[1] = gen_rtx_REG (Pmode, 2);
8565 xoperands[2] = gen_rtx_REG (Pmode, 1);
8566 pa_output_pic_pcrel_sequence (xoperands);
8567 pa_output_arg_descriptor (insn);
8568 return "bv %%r0(%%r1)\n\tldo {12|20}(%%r2),%%r2";
8569 }
8570
8571 /* In HPUX 8.0's shared library scheme, special relocations are needed
8572 for function labels if they might be passed to a function
8573 in a shared library (because shared libraries don't live in code
8574 space), and special magic is needed to construct their address. */
8575
8576 void
8577 pa_encode_label (rtx sym)
8578 {
8579 const char *str = XSTR (sym, 0);
8580 int len = strlen (str) + 1;
8581 char *newstr, *p;
8582
8583 p = newstr = XALLOCAVEC (char, len + 1);
8584 *p++ = '@';
8585 strcpy (p, str);
8586
8587 XSTR (sym, 0) = ggc_alloc_string (newstr, len);
8588 }
8589
8590 static void
8591 pa_encode_section_info (tree decl, rtx rtl, int first)
8592 {
8593 int old_referenced = 0;
8594
8595 if (!first && MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
8596 old_referenced
8597 = SYMBOL_REF_FLAGS (XEXP (rtl, 0)) & SYMBOL_FLAG_REFERENCED;
8598
8599 default_encode_section_info (decl, rtl, first);
8600
8601 if (first && TEXT_SPACE_P (decl))
8602 {
8603 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
8604 if (TREE_CODE (decl) == FUNCTION_DECL)
8605 pa_encode_label (XEXP (rtl, 0));
8606 }
8607 else if (old_referenced)
8608 SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= old_referenced;
8609 }
8610
8611 /* This is sort of inverse to pa_encode_section_info. */
8612
8613 static const char *
8614 pa_strip_name_encoding (const char *str)
8615 {
8616 str += (*str == '@');
8617 str += (*str == '*');
8618 return str;
8619 }
8620
8621 /* Returns 1 if OP is a function label involved in a simple addition
8622 with a constant. Used to keep certain patterns from matching
8623 during instruction combination. */
8624 int
8625 pa_is_function_label_plus_const (rtx op)
8626 {
8627 /* Strip off any CONST. */
8628 if (GET_CODE (op) == CONST)
8629 op = XEXP (op, 0);
8630
8631 return (GET_CODE (op) == PLUS
8632 && function_label_operand (XEXP (op, 0), VOIDmode)
8633 && GET_CODE (XEXP (op, 1)) == CONST_INT);
8634 }
8635
8636 /* Output the assembler code for a thunk function. THUNK_DECL is the
8637 declaration for the thunk function itself, FUNCTION is the decl for
8638 the target function. DELTA is an immediate constant offset to be
8639 added to THIS. If VCALL_OFFSET is nonzero, the word at
8640 *(*this + vcall_offset) should be added to THIS. */
8641
8642 static void
8643 pa_asm_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
8644 HOST_WIDE_INT vcall_offset, tree function)
8645 {
8646 const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl));
8647 static unsigned int current_thunk_number;
8648 int val_14 = VAL_14_BITS_P (delta);
8649 unsigned int old_last_address = last_address, nbytes = 0;
8650 char label[17];
8651 rtx xoperands[4];
8652
8653 xoperands[0] = XEXP (DECL_RTL (function), 0);
8654 xoperands[1] = XEXP (DECL_RTL (thunk_fndecl), 0);
8655 xoperands[2] = GEN_INT (delta);
8656
8657 assemble_start_function (thunk_fndecl, fnname);
8658 final_start_function (emit_barrier (), file, 1);
8659
8660 if (!vcall_offset)
8661 {
8662 /* Output the thunk. We know that the function is in the same
8663 translation unit (i.e., the same space) as the thunk, and that
8664 thunks are output after their method. Thus, we don't need an
8665 external branch to reach the function. With SOM and GAS,
8666 functions and thunks are effectively in different sections.
8667 Thus, we can always use a IA-relative branch and the linker
8668 will add a long branch stub if necessary.
8669
8670 However, we have to be careful when generating PIC code on the
8671 SOM port to ensure that the sequence does not transfer to an
8672 import stub for the target function as this could clobber the
8673 return value saved at SP-24. This would also apply to the
8674 32-bit linux port if the multi-space model is implemented. */
8675 if ((!TARGET_LONG_CALLS && TARGET_SOM && !TARGET_PORTABLE_RUNTIME
8676 && !(flag_pic && TREE_PUBLIC (function))
8677 && (TARGET_GAS || last_address < 262132))
8678 || (!TARGET_LONG_CALLS && !TARGET_SOM && !TARGET_PORTABLE_RUNTIME
8679 && ((targetm_common.have_named_sections
8680 && DECL_SECTION_NAME (thunk_fndecl) != NULL
8681 /* The GNU 64-bit linker has rather poor stub management.
8682 So, we use a long branch from thunks that aren't in
8683 the same section as the target function. */
8684 && ((!TARGET_64BIT
8685 && (DECL_SECTION_NAME (thunk_fndecl)
8686 != DECL_SECTION_NAME (function)))
8687 || ((DECL_SECTION_NAME (thunk_fndecl)
8688 == DECL_SECTION_NAME (function))
8689 && last_address < 262132)))
8690 /* In this case, we need to be able to reach the start of
8691 the stub table even though the function is likely closer
8692 and can be jumped to directly. */
8693 || (targetm_common.have_named_sections
8694 && DECL_SECTION_NAME (thunk_fndecl) == NULL
8695 && DECL_SECTION_NAME (function) == NULL
8696 && total_code_bytes < MAX_PCREL17F_OFFSET)
8697 /* Likewise. */
8698 || (!targetm_common.have_named_sections
8699 && total_code_bytes < MAX_PCREL17F_OFFSET))))
8700 {
8701 if (!val_14)
8702 output_asm_insn ("addil L'%2,%%r26", xoperands);
8703
8704 output_asm_insn ("b %0", xoperands);
8705
8706 if (val_14)
8707 {
8708 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8709 nbytes += 8;
8710 }
8711 else
8712 {
8713 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8714 nbytes += 12;
8715 }
8716 }
8717 else if (TARGET_64BIT)
8718 {
8719 rtx xop[4];
8720
8721 /* We only have one call-clobbered scratch register, so we can't
8722 make use of the delay slot if delta doesn't fit in 14 bits. */
8723 if (!val_14)
8724 {
8725 output_asm_insn ("addil L'%2,%%r26", xoperands);
8726 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8727 }
8728
8729 /* Load function address into %r1. */
8730 xop[0] = xoperands[0];
8731 xop[1] = gen_rtx_REG (Pmode, 1);
8732 xop[2] = xop[1];
8733 pa_output_pic_pcrel_sequence (xop);
8734
8735 if (val_14)
8736 {
8737 output_asm_insn ("bv %%r0(%%r1)", xoperands);
8738 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8739 nbytes += 20;
8740 }
8741 else
8742 {
8743 output_asm_insn ("bv,n %%r0(%%r1)", xoperands);
8744 nbytes += 24;
8745 }
8746 }
8747 else if (TARGET_PORTABLE_RUNTIME)
8748 {
8749 output_asm_insn ("ldil L'%0,%%r1", xoperands);
8750 output_asm_insn ("ldo R'%0(%%r1),%%r22", xoperands);
8751
8752 if (!val_14)
8753 output_asm_insn ("ldil L'%2,%%r26", xoperands);
8754
8755 output_asm_insn ("bv %%r0(%%r22)", xoperands);
8756
8757 if (val_14)
8758 {
8759 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8760 nbytes += 16;
8761 }
8762 else
8763 {
8764 output_asm_insn ("ldo R'%2(%%r26),%%r26", xoperands);
8765 nbytes += 20;
8766 }
8767 }
8768 else if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8769 {
8770 /* The function is accessible from outside this module. The only
8771 way to avoid an import stub between the thunk and function is to
8772 call the function directly with an indirect sequence similar to
8773 that used by $$dyncall. This is possible because $$dyncall acts
8774 as the import stub in an indirect call. */
8775 ASM_GENERATE_INTERNAL_LABEL (label, "LTHN", current_thunk_number);
8776 xoperands[3] = gen_rtx_SYMBOL_REF (Pmode, label);
8777 output_asm_insn ("addil LT'%3,%%r19", xoperands);
8778 output_asm_insn ("ldw RT'%3(%%r1),%%r22", xoperands);
8779 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8780 output_asm_insn ("bb,>=,n %%r22,30,.+16", xoperands);
8781 output_asm_insn ("depi 0,31,2,%%r22", xoperands);
8782 output_asm_insn ("ldw 4(%%sr0,%%r22),%%r19", xoperands);
8783 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8784
8785 if (!val_14)
8786 {
8787 output_asm_insn ("addil L'%2,%%r26", xoperands);
8788 nbytes += 4;
8789 }
8790
8791 if (TARGET_PA_20)
8792 {
8793 output_asm_insn ("bve (%%r22)", xoperands);
8794 nbytes += 36;
8795 }
8796 else if (TARGET_NO_SPACE_REGS)
8797 {
8798 output_asm_insn ("be 0(%%sr4,%%r22)", xoperands);
8799 nbytes += 36;
8800 }
8801 else
8802 {
8803 output_asm_insn ("ldsid (%%sr0,%%r22),%%r21", xoperands);
8804 output_asm_insn ("mtsp %%r21,%%sr0", xoperands);
8805 output_asm_insn ("be 0(%%sr0,%%r22)", xoperands);
8806 nbytes += 44;
8807 }
8808
8809 if (val_14)
8810 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8811 else
8812 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8813 }
8814 else if (flag_pic)
8815 {
8816 rtx xop[4];
8817
8818 /* Load function address into %r22. */
8819 xop[0] = xoperands[0];
8820 xop[1] = gen_rtx_REG (Pmode, 1);
8821 xop[2] = gen_rtx_REG (Pmode, 22);
8822 pa_output_pic_pcrel_sequence (xop);
8823
8824 if (!val_14)
8825 output_asm_insn ("addil L'%2,%%r26", xoperands);
8826
8827 output_asm_insn ("bv %%r0(%%r22)", xoperands);
8828
8829 if (val_14)
8830 {
8831 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8832 nbytes += 20;
8833 }
8834 else
8835 {
8836 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8837 nbytes += 24;
8838 }
8839 }
8840 else
8841 {
8842 if (!val_14)
8843 output_asm_insn ("addil L'%2,%%r26", xoperands);
8844
8845 output_asm_insn ("ldil L'%0,%%r22", xoperands);
8846 output_asm_insn ("be R'%0(%%sr4,%%r22)", xoperands);
8847
8848 if (val_14)
8849 {
8850 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8851 nbytes += 12;
8852 }
8853 else
8854 {
8855 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8856 nbytes += 16;
8857 }
8858 }
8859 }
8860 else
8861 {
8862 rtx xop[4];
8863
8864 /* Add DELTA to THIS. */
8865 if (val_14)
8866 {
8867 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8868 nbytes += 4;
8869 }
8870 else
8871 {
8872 output_asm_insn ("addil L'%2,%%r26", xoperands);
8873 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8874 nbytes += 8;
8875 }
8876
8877 if (TARGET_64BIT)
8878 {
8879 /* Load *(THIS + DELTA) to %r1. */
8880 output_asm_insn ("ldd 0(%%r26),%%r1", xoperands);
8881
8882 val_14 = VAL_14_BITS_P (vcall_offset);
8883 xoperands[2] = GEN_INT (vcall_offset);
8884
8885 /* Load *(*(THIS + DELTA) + VCALL_OFFSET) to %r1. */
8886 if (val_14)
8887 {
8888 output_asm_insn ("ldd %2(%%r1),%%r1", xoperands);
8889 nbytes += 8;
8890 }
8891 else
8892 {
8893 output_asm_insn ("addil L'%2,%%r1", xoperands);
8894 output_asm_insn ("ldd R'%2(%%r1),%%r1", xoperands);
8895 nbytes += 12;
8896 }
8897 }
8898 else
8899 {
8900 /* Load *(THIS + DELTA) to %r1. */
8901 output_asm_insn ("ldw 0(%%r26),%%r1", xoperands);
8902
8903 val_14 = VAL_14_BITS_P (vcall_offset);
8904 xoperands[2] = GEN_INT (vcall_offset);
8905
8906 /* Load *(*(THIS + DELTA) + VCALL_OFFSET) to %r1. */
8907 if (val_14)
8908 {
8909 output_asm_insn ("ldw %2(%%r1),%%r1", xoperands);
8910 nbytes += 8;
8911 }
8912 else
8913 {
8914 output_asm_insn ("addil L'%2,%%r1", xoperands);
8915 output_asm_insn ("ldw R'%2(%%r1),%%r1", xoperands);
8916 nbytes += 12;
8917 }
8918 }
8919
8920 /* Branch to FUNCTION and add %r1 to THIS in delay slot if possible. */
8921 if ((!TARGET_LONG_CALLS && TARGET_SOM && !TARGET_PORTABLE_RUNTIME
8922 && !(flag_pic && TREE_PUBLIC (function))
8923 && (TARGET_GAS || last_address < 262132))
8924 || (!TARGET_LONG_CALLS && !TARGET_SOM && !TARGET_PORTABLE_RUNTIME
8925 && ((targetm_common.have_named_sections
8926 && DECL_SECTION_NAME (thunk_fndecl) != NULL
8927 /* The GNU 64-bit linker has rather poor stub management.
8928 So, we use a long branch from thunks that aren't in
8929 the same section as the target function. */
8930 && ((!TARGET_64BIT
8931 && (DECL_SECTION_NAME (thunk_fndecl)
8932 != DECL_SECTION_NAME (function)))
8933 || ((DECL_SECTION_NAME (thunk_fndecl)
8934 == DECL_SECTION_NAME (function))
8935 && last_address < 262132)))
8936 /* In this case, we need to be able to reach the start of
8937 the stub table even though the function is likely closer
8938 and can be jumped to directly. */
8939 || (targetm_common.have_named_sections
8940 && DECL_SECTION_NAME (thunk_fndecl) == NULL
8941 && DECL_SECTION_NAME (function) == NULL
8942 && total_code_bytes < MAX_PCREL17F_OFFSET)
8943 /* Likewise. */
8944 || (!targetm_common.have_named_sections
8945 && total_code_bytes < MAX_PCREL17F_OFFSET))))
8946 {
8947 nbytes += 4;
8948 output_asm_insn ("b %0", xoperands);
8949
8950 /* Add *(*(THIS + DELTA) + VCALL_OFFSET) to THIS. */
8951 output_asm_insn ("addl %%r1,%%r26,%%r26", xoperands);
8952 }
8953 else if (TARGET_64BIT)
8954 {
8955 /* Add *(*(THIS + DELTA) + VCALL_OFFSET) to THIS. */
8956 output_asm_insn ("addl %%r1,%%r26,%%r26", xoperands);
8957
8958 /* Load function address into %r1. */
8959 nbytes += 16;
8960 xop[0] = xoperands[0];
8961 xop[1] = gen_rtx_REG (Pmode, 1);
8962 xop[2] = xop[1];
8963 pa_output_pic_pcrel_sequence (xop);
8964
8965 output_asm_insn ("bv,n %%r0(%%r1)", xoperands);
8966 }
8967 else if (TARGET_PORTABLE_RUNTIME)
8968 {
8969 /* Load function address into %r22. */
8970 nbytes += 12;
8971 output_asm_insn ("ldil L'%0,%%r22", xoperands);
8972 output_asm_insn ("ldo R'%0(%%r22),%%r22", xoperands);
8973
8974 output_asm_insn ("bv %%r0(%%r22)", xoperands);
8975
8976 /* Add *(*(THIS + DELTA) + VCALL_OFFSET) to THIS. */
8977 output_asm_insn ("addl %%r1,%%r26,%%r26", xoperands);
8978 }
8979 else if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8980 {
8981 /* Add *(*(THIS + DELTA) + VCALL_OFFSET) to THIS. */
8982 output_asm_insn ("addl %%r1,%%r26,%%r26", xoperands);
8983
8984 /* The function is accessible from outside this module. The only
8985 way to avoid an import stub between the thunk and function is to
8986 call the function directly with an indirect sequence similar to
8987 that used by $$dyncall. This is possible because $$dyncall acts
8988 as the import stub in an indirect call. */
8989 ASM_GENERATE_INTERNAL_LABEL (label, "LTHN", current_thunk_number);
8990 xoperands[3] = gen_rtx_SYMBOL_REF (Pmode, label);
8991 output_asm_insn ("addil LT'%3,%%r19", xoperands);
8992 output_asm_insn ("ldw RT'%3(%%r1),%%r22", xoperands);
8993 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8994 output_asm_insn ("bb,>=,n %%r22,30,.+16", xoperands);
8995 output_asm_insn ("depi 0,31,2,%%r22", xoperands);
8996 output_asm_insn ("ldw 4(%%sr0,%%r22),%%r19", xoperands);
8997 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8998
8999 if (TARGET_PA_20)
9000 {
9001 output_asm_insn ("bve,n (%%r22)", xoperands);
9002 nbytes += 32;
9003 }
9004 else if (TARGET_NO_SPACE_REGS)
9005 {
9006 output_asm_insn ("be,n 0(%%sr4,%%r22)", xoperands);
9007 nbytes += 32;
9008 }
9009 else
9010 {
9011 output_asm_insn ("ldsid (%%sr0,%%r22),%%r21", xoperands);
9012 output_asm_insn ("mtsp %%r21,%%sr0", xoperands);
9013 output_asm_insn ("be,n 0(%%sr0,%%r22)", xoperands);
9014 nbytes += 40;
9015 }
9016 }
9017 else if (flag_pic)
9018 {
9019 /* Add *(*(THIS + DELTA) + VCALL_OFFSET) to THIS. */
9020 output_asm_insn ("addl %%r1,%%r26,%%r26", xoperands);
9021
9022 /* Load function address into %r1. */
9023 nbytes += 16;
9024 xop[0] = xoperands[0];
9025 xop[1] = gen_rtx_REG (Pmode, 1);
9026 xop[2] = xop[1];
9027 pa_output_pic_pcrel_sequence (xop);
9028
9029 output_asm_insn ("bv,n %%r0(%%r1)", xoperands);
9030 }
9031 else
9032 {
9033 /* Load function address into %r22. */
9034 nbytes += 8;
9035 output_asm_insn ("ldil L'%0,%%r22", xoperands);
9036 output_asm_insn ("be R'%0(%%sr4,%%r22)", xoperands);
9037
9038 /* Add *(*(THIS + DELTA) + VCALL_OFFSET) to THIS. */
9039 output_asm_insn ("addl %%r1,%%r26,%%r26", xoperands);
9040 }
9041 }
9042
9043 final_end_function ();
9044
9045 if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
9046 {
9047 switch_to_section (data_section);
9048 output_asm_insn (".align 4", xoperands);
9049 ASM_OUTPUT_LABEL (file, label);
9050 output_asm_insn (".word P'%0", xoperands);
9051 }
9052
9053 current_thunk_number++;
9054 nbytes = ((nbytes + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
9055 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
9056 last_address += nbytes;
9057 if (old_last_address > last_address)
9058 last_address = UINT_MAX;
9059 update_total_code_bytes (nbytes);
9060 assemble_end_function (thunk_fndecl, fnname);
9061 }
9062
9063 /* Only direct calls to static functions are allowed to be sibling (tail)
9064 call optimized.
9065
9066 This restriction is necessary because some linker generated stubs will
9067 store return pointers into rp' in some cases which might clobber a
9068 live value already in rp'.
9069
9070 In a sibcall the current function and the target function share stack
9071 space. Thus if the path to the current function and the path to the
9072 target function save a value in rp', they save the value into the
9073 same stack slot, which has undesirable consequences.
9074
9075 Because of the deferred binding nature of shared libraries any function
9076 with external scope could be in a different load module and thus require
9077 rp' to be saved when calling that function. So sibcall optimizations
9078 can only be safe for static function.
9079
9080 Note that GCC never needs return value relocations, so we don't have to
9081 worry about static calls with return value relocations (which require
9082 saving rp').
9083
9084 It is safe to perform a sibcall optimization when the target function
9085 will never return. */
9086 static bool
9087 pa_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
9088 {
9089 /* Sibcalls are not ok because the arg pointer register is not a fixed
9090 register. This prevents the sibcall optimization from occurring. In
9091 addition, there are problems with stub placement using GNU ld. This
9092 is because a normal sibcall branch uses a 17-bit relocation while
9093 a regular call branch uses a 22-bit relocation. As a result, more
9094 care needs to be taken in the placement of long-branch stubs. */
9095 if (TARGET_64BIT)
9096 return false;
9097
9098 if (TARGET_PORTABLE_RUNTIME)
9099 return false;
9100
9101 /* Sibcalls are only ok within a translation unit. */
9102 return decl && targetm.binds_local_p (decl);
9103 }
9104
9105 /* ??? Addition is not commutative on the PA due to the weird implicit
9106 space register selection rules for memory addresses. Therefore, we
9107 don't consider a + b == b + a, as this might be inside a MEM. */
9108 static bool
9109 pa_commutative_p (const_rtx x, int outer_code)
9110 {
9111 return (COMMUTATIVE_P (x)
9112 && (TARGET_NO_SPACE_REGS
9113 || (outer_code != UNKNOWN && outer_code != MEM)
9114 || GET_CODE (x) != PLUS));
9115 }
9116
9117 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
9118 use in fmpyadd instructions. */
9119 int
9120 pa_fmpyaddoperands (rtx *operands)
9121 {
9122 machine_mode mode = GET_MODE (operands[0]);
9123
9124 /* Must be a floating point mode. */
9125 if (mode != SFmode && mode != DFmode)
9126 return 0;
9127
9128 /* All modes must be the same. */
9129 if (! (mode == GET_MODE (operands[1])
9130 && mode == GET_MODE (operands[2])
9131 && mode == GET_MODE (operands[3])
9132 && mode == GET_MODE (operands[4])
9133 && mode == GET_MODE (operands[5])))
9134 return 0;
9135
9136 /* All operands must be registers. */
9137 if (! (GET_CODE (operands[1]) == REG
9138 && GET_CODE (operands[2]) == REG
9139 && GET_CODE (operands[3]) == REG
9140 && GET_CODE (operands[4]) == REG
9141 && GET_CODE (operands[5]) == REG))
9142 return 0;
9143
9144 /* Only 2 real operands to the addition. One of the input operands must
9145 be the same as the output operand. */
9146 if (! rtx_equal_p (operands[3], operands[4])
9147 && ! rtx_equal_p (operands[3], operands[5]))
9148 return 0;
9149
9150 /* Inout operand of add cannot conflict with any operands from multiply. */
9151 if (rtx_equal_p (operands[3], operands[0])
9152 || rtx_equal_p (operands[3], operands[1])
9153 || rtx_equal_p (operands[3], operands[2]))
9154 return 0;
9155
9156 /* multiply cannot feed into addition operands. */
9157 if (rtx_equal_p (operands[4], operands[0])
9158 || rtx_equal_p (operands[5], operands[0]))
9159 return 0;
9160
9161 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
9162 if (mode == SFmode
9163 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
9164 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
9165 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
9166 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
9167 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
9168 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
9169 return 0;
9170
9171 /* Passed. Operands are suitable for fmpyadd. */
9172 return 1;
9173 }
9174
9175 #if !defined(USE_COLLECT2)
9176 static void
9177 pa_asm_out_constructor (rtx symbol, int priority)
9178 {
9179 if (!function_label_operand (symbol, VOIDmode))
9180 pa_encode_label (symbol);
9181
9182 #ifdef CTORS_SECTION_ASM_OP
9183 default_ctor_section_asm_out_constructor (symbol, priority);
9184 #else
9185 # ifdef TARGET_ASM_NAMED_SECTION
9186 default_named_section_asm_out_constructor (symbol, priority);
9187 # else
9188 default_stabs_asm_out_constructor (symbol, priority);
9189 # endif
9190 #endif
9191 }
9192
9193 static void
9194 pa_asm_out_destructor (rtx symbol, int priority)
9195 {
9196 if (!function_label_operand (symbol, VOIDmode))
9197 pa_encode_label (symbol);
9198
9199 #ifdef DTORS_SECTION_ASM_OP
9200 default_dtor_section_asm_out_destructor (symbol, priority);
9201 #else
9202 # ifdef TARGET_ASM_NAMED_SECTION
9203 default_named_section_asm_out_destructor (symbol, priority);
9204 # else
9205 default_stabs_asm_out_destructor (symbol, priority);
9206 # endif
9207 #endif
9208 }
9209 #endif
9210
9211 /* This function places uninitialized global data in the bss section.
9212 The ASM_OUTPUT_ALIGNED_BSS macro needs to be defined to call this
9213 function on the SOM port to prevent uninitialized global data from
9214 being placed in the data section. */
9215
9216 void
9217 pa_asm_output_aligned_bss (FILE *stream,
9218 const char *name,
9219 unsigned HOST_WIDE_INT size,
9220 unsigned int align)
9221 {
9222 switch_to_section (bss_section);
9223
9224 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
9225 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object");
9226 #endif
9227
9228 #ifdef ASM_OUTPUT_SIZE_DIRECTIVE
9229 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
9230 #endif
9231
9232 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
9233 ASM_OUTPUT_LABEL (stream, name);
9234 fprintf (stream, "\t.block " HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
9235 }
9236
9237 /* Both the HP and GNU assemblers under HP-UX provide a .comm directive
9238 that doesn't allow the alignment of global common storage to be directly
9239 specified. The SOM linker aligns common storage based on the rounded
9240 value of the NUM_BYTES parameter in the .comm directive. It's not
9241 possible to use the .align directive as it doesn't affect the alignment
9242 of the label associated with a .comm directive. */
9243
9244 void
9245 pa_asm_output_aligned_common (FILE *stream,
9246 const char *name,
9247 unsigned HOST_WIDE_INT size,
9248 unsigned int align)
9249 {
9250 unsigned int max_common_align;
9251
9252 max_common_align = TARGET_64BIT ? 128 : (size >= 4096 ? 256 : 64);
9253 if (align > max_common_align)
9254 {
9255 /* Alignment exceeds maximum alignment for global common data. */
9256 align = max_common_align;
9257 }
9258
9259 switch_to_section (bss_section);
9260
9261 assemble_name (stream, name);
9262 fprintf (stream, "\t.comm " HOST_WIDE_INT_PRINT_UNSIGNED"\n",
9263 MAX (size, align / BITS_PER_UNIT));
9264 }
9265
9266 /* We can't use .comm for local common storage as the SOM linker effectively
9267 treats the symbol as universal and uses the same storage for local symbols
9268 with the same name in different object files. The .block directive
9269 reserves an uninitialized block of storage. However, it's not common
9270 storage. Fortunately, GCC never requests common storage with the same
9271 name in any given translation unit. */
9272
9273 void
9274 pa_asm_output_aligned_local (FILE *stream,
9275 const char *name,
9276 unsigned HOST_WIDE_INT size,
9277 unsigned int align)
9278 {
9279 switch_to_section (bss_section);
9280 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
9281
9282 #ifdef LOCAL_ASM_OP
9283 fprintf (stream, "%s", LOCAL_ASM_OP);
9284 assemble_name (stream, name);
9285 fprintf (stream, "\n");
9286 #endif
9287
9288 ASM_OUTPUT_LABEL (stream, name);
9289 fprintf (stream, "\t.block " HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
9290 }
9291
9292 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
9293 use in fmpysub instructions. */
9294 int
9295 pa_fmpysuboperands (rtx *operands)
9296 {
9297 machine_mode mode = GET_MODE (operands[0]);
9298
9299 /* Must be a floating point mode. */
9300 if (mode != SFmode && mode != DFmode)
9301 return 0;
9302
9303 /* All modes must be the same. */
9304 if (! (mode == GET_MODE (operands[1])
9305 && mode == GET_MODE (operands[2])
9306 && mode == GET_MODE (operands[3])
9307 && mode == GET_MODE (operands[4])
9308 && mode == GET_MODE (operands[5])))
9309 return 0;
9310
9311 /* All operands must be registers. */
9312 if (! (GET_CODE (operands[1]) == REG
9313 && GET_CODE (operands[2]) == REG
9314 && GET_CODE (operands[3]) == REG
9315 && GET_CODE (operands[4]) == REG
9316 && GET_CODE (operands[5]) == REG))
9317 return 0;
9318
9319 /* Only 2 real operands to the subtraction. Subtraction is not a commutative
9320 operation, so operands[4] must be the same as operand[3]. */
9321 if (! rtx_equal_p (operands[3], operands[4]))
9322 return 0;
9323
9324 /* multiply cannot feed into subtraction. */
9325 if (rtx_equal_p (operands[5], operands[0]))
9326 return 0;
9327
9328 /* Inout operand of sub cannot conflict with any operands from multiply. */
9329 if (rtx_equal_p (operands[3], operands[0])
9330 || rtx_equal_p (operands[3], operands[1])
9331 || rtx_equal_p (operands[3], operands[2]))
9332 return 0;
9333
9334 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
9335 if (mode == SFmode
9336 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
9337 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
9338 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
9339 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
9340 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
9341 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
9342 return 0;
9343
9344 /* Passed. Operands are suitable for fmpysub. */
9345 return 1;
9346 }
9347
9348 /* Return 1 if the given constant is 2, 4, or 8. These are the valid
9349 constants for a MULT embedded inside a memory address. */
9350 int
9351 pa_mem_shadd_constant_p (int val)
9352 {
9353 if (val == 2 || val == 4 || val == 8)
9354 return 1;
9355 else
9356 return 0;
9357 }
9358
9359 /* Return 1 if the given constant is 1, 2, or 3. These are the valid
9360 constants for shadd instructions. */
9361 int
9362 pa_shadd_constant_p (int val)
9363 {
9364 if (val == 1 || val == 2 || val == 3)
9365 return 1;
9366 else
9367 return 0;
9368 }
9369
9370 /* Return TRUE if INSN branches forward. */
9371
9372 static bool
9373 forward_branch_p (rtx_insn *insn)
9374 {
9375 rtx lab = JUMP_LABEL (insn);
9376
9377 /* The INSN must have a jump label. */
9378 gcc_assert (lab != NULL_RTX);
9379
9380 if (INSN_ADDRESSES_SET_P ())
9381 return INSN_ADDRESSES (INSN_UID (lab)) > INSN_ADDRESSES (INSN_UID (insn));
9382
9383 while (insn)
9384 {
9385 if (insn == lab)
9386 return true;
9387 else
9388 insn = NEXT_INSN (insn);
9389 }
9390
9391 return false;
9392 }
9393
9394 /* Output an unconditional move and branch insn. */
9395
9396 const char *
9397 pa_output_parallel_movb (rtx *operands, rtx_insn *insn)
9398 {
9399 int length = get_attr_length (insn);
9400
9401 /* These are the cases in which we win. */
9402 if (length == 4)
9403 return "mov%I1b,tr %1,%0,%2";
9404
9405 /* None of the following cases win, but they don't lose either. */
9406 if (length == 8)
9407 {
9408 if (dbr_sequence_length () == 0)
9409 {
9410 /* Nothing in the delay slot, fake it by putting the combined
9411 insn (the copy or add) in the delay slot of a bl. */
9412 if (GET_CODE (operands[1]) == CONST_INT)
9413 return "b %2\n\tldi %1,%0";
9414 else
9415 return "b %2\n\tcopy %1,%0";
9416 }
9417 else
9418 {
9419 /* Something in the delay slot, but we've got a long branch. */
9420 if (GET_CODE (operands[1]) == CONST_INT)
9421 return "ldi %1,%0\n\tb %2";
9422 else
9423 return "copy %1,%0\n\tb %2";
9424 }
9425 }
9426
9427 if (GET_CODE (operands[1]) == CONST_INT)
9428 output_asm_insn ("ldi %1,%0", operands);
9429 else
9430 output_asm_insn ("copy %1,%0", operands);
9431 return pa_output_lbranch (operands[2], insn, 1);
9432 }
9433
9434 /* Output an unconditional add and branch insn. */
9435
9436 const char *
9437 pa_output_parallel_addb (rtx *operands, rtx_insn *insn)
9438 {
9439 int length = get_attr_length (insn);
9440
9441 /* To make life easy we want operand0 to be the shared input/output
9442 operand and operand1 to be the readonly operand. */
9443 if (operands[0] == operands[1])
9444 operands[1] = operands[2];
9445
9446 /* These are the cases in which we win. */
9447 if (length == 4)
9448 return "add%I1b,tr %1,%0,%3";
9449
9450 /* None of the following cases win, but they don't lose either. */
9451 if (length == 8)
9452 {
9453 if (dbr_sequence_length () == 0)
9454 /* Nothing in the delay slot, fake it by putting the combined
9455 insn (the copy or add) in the delay slot of a bl. */
9456 return "b %3\n\tadd%I1 %1,%0,%0";
9457 else
9458 /* Something in the delay slot, but we've got a long branch. */
9459 return "add%I1 %1,%0,%0\n\tb %3";
9460 }
9461
9462 output_asm_insn ("add%I1 %1,%0,%0", operands);
9463 return pa_output_lbranch (operands[3], insn, 1);
9464 }
9465
9466 /* We use this hook to perform a PA specific optimization which is difficult
9467 to do in earlier passes. */
9468
9469 static void
9470 pa_reorg (void)
9471 {
9472 remove_useless_addtr_insns (1);
9473
9474 if (pa_cpu < PROCESSOR_8000)
9475 pa_combine_instructions ();
9476 }
9477
9478 /* The PA has a number of odd instructions which can perform multiple
9479 tasks at once. On first generation PA machines (PA1.0 and PA1.1)
9480 it may be profitable to combine two instructions into one instruction
9481 with two outputs. It's not profitable PA2.0 machines because the
9482 two outputs would take two slots in the reorder buffers.
9483
9484 This routine finds instructions which can be combined and combines
9485 them. We only support some of the potential combinations, and we
9486 only try common ways to find suitable instructions.
9487
9488 * addb can add two registers or a register and a small integer
9489 and jump to a nearby (+-8k) location. Normally the jump to the
9490 nearby location is conditional on the result of the add, but by
9491 using the "true" condition we can make the jump unconditional.
9492 Thus addb can perform two independent operations in one insn.
9493
9494 * movb is similar to addb in that it can perform a reg->reg
9495 or small immediate->reg copy and jump to a nearby (+-8k location).
9496
9497 * fmpyadd and fmpysub can perform a FP multiply and either an
9498 FP add or FP sub if the operands of the multiply and add/sub are
9499 independent (there are other minor restrictions). Note both
9500 the fmpy and fadd/fsub can in theory move to better spots according
9501 to data dependencies, but for now we require the fmpy stay at a
9502 fixed location.
9503
9504 * Many of the memory operations can perform pre & post updates
9505 of index registers. GCC's pre/post increment/decrement addressing
9506 is far too simple to take advantage of all the possibilities. This
9507 pass may not be suitable since those insns may not be independent.
9508
9509 * comclr can compare two ints or an int and a register, nullify
9510 the following instruction and zero some other register. This
9511 is more difficult to use as it's harder to find an insn which
9512 will generate a comclr than finding something like an unconditional
9513 branch. (conditional moves & long branches create comclr insns).
9514
9515 * Most arithmetic operations can conditionally skip the next
9516 instruction. They can be viewed as "perform this operation
9517 and conditionally jump to this nearby location" (where nearby
9518 is an insns away). These are difficult to use due to the
9519 branch length restrictions. */
9520
9521 static void
9522 pa_combine_instructions (void)
9523 {
9524 rtx_insn *anchor;
9525
9526 /* This can get expensive since the basic algorithm is on the
9527 order of O(n^2) (or worse). Only do it for -O2 or higher
9528 levels of optimization. */
9529 if (optimize < 2)
9530 return;
9531
9532 /* Walk down the list of insns looking for "anchor" insns which
9533 may be combined with "floating" insns. As the name implies,
9534 "anchor" instructions don't move, while "floating" insns may
9535 move around. */
9536 rtx par = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, NULL_RTX, NULL_RTX));
9537 rtx_insn *new_rtx = make_insn_raw (par);
9538
9539 for (anchor = get_insns (); anchor; anchor = NEXT_INSN (anchor))
9540 {
9541 enum attr_pa_combine_type anchor_attr;
9542 enum attr_pa_combine_type floater_attr;
9543
9544 /* We only care about INSNs, JUMP_INSNs, and CALL_INSNs.
9545 Also ignore any special USE insns. */
9546 if ((! NONJUMP_INSN_P (anchor) && ! JUMP_P (anchor) && ! CALL_P (anchor))
9547 || GET_CODE (PATTERN (anchor)) == USE
9548 || GET_CODE (PATTERN (anchor)) == CLOBBER)
9549 continue;
9550
9551 anchor_attr = get_attr_pa_combine_type (anchor);
9552 /* See if anchor is an insn suitable for combination. */
9553 if (anchor_attr == PA_COMBINE_TYPE_FMPY
9554 || anchor_attr == PA_COMBINE_TYPE_FADDSUB
9555 || (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
9556 && ! forward_branch_p (anchor)))
9557 {
9558 rtx_insn *floater;
9559
9560 for (floater = PREV_INSN (anchor);
9561 floater;
9562 floater = PREV_INSN (floater))
9563 {
9564 if (NOTE_P (floater)
9565 || (NONJUMP_INSN_P (floater)
9566 && (GET_CODE (PATTERN (floater)) == USE
9567 || GET_CODE (PATTERN (floater)) == CLOBBER)))
9568 continue;
9569
9570 /* Anything except a regular INSN will stop our search. */
9571 if (! NONJUMP_INSN_P (floater))
9572 {
9573 floater = NULL;
9574 break;
9575 }
9576
9577 /* See if FLOATER is suitable for combination with the
9578 anchor. */
9579 floater_attr = get_attr_pa_combine_type (floater);
9580 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
9581 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
9582 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
9583 && floater_attr == PA_COMBINE_TYPE_FMPY))
9584 {
9585 /* If ANCHOR and FLOATER can be combined, then we're
9586 done with this pass. */
9587 if (pa_can_combine_p (new_rtx, anchor, floater, 0,
9588 SET_DEST (PATTERN (floater)),
9589 XEXP (SET_SRC (PATTERN (floater)), 0),
9590 XEXP (SET_SRC (PATTERN (floater)), 1)))
9591 break;
9592 }
9593
9594 else if (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
9595 && floater_attr == PA_COMBINE_TYPE_ADDMOVE)
9596 {
9597 if (GET_CODE (SET_SRC (PATTERN (floater))) == PLUS)
9598 {
9599 if (pa_can_combine_p (new_rtx, anchor, floater, 0,
9600 SET_DEST (PATTERN (floater)),
9601 XEXP (SET_SRC (PATTERN (floater)), 0),
9602 XEXP (SET_SRC (PATTERN (floater)), 1)))
9603 break;
9604 }
9605 else
9606 {
9607 if (pa_can_combine_p (new_rtx, anchor, floater, 0,
9608 SET_DEST (PATTERN (floater)),
9609 SET_SRC (PATTERN (floater)),
9610 SET_SRC (PATTERN (floater))))
9611 break;
9612 }
9613 }
9614 }
9615
9616 /* If we didn't find anything on the backwards scan try forwards. */
9617 if (!floater
9618 && (anchor_attr == PA_COMBINE_TYPE_FMPY
9619 || anchor_attr == PA_COMBINE_TYPE_FADDSUB))
9620 {
9621 for (floater = anchor; floater; floater = NEXT_INSN (floater))
9622 {
9623 if (NOTE_P (floater)
9624 || (NONJUMP_INSN_P (floater)
9625 && (GET_CODE (PATTERN (floater)) == USE
9626 || GET_CODE (PATTERN (floater)) == CLOBBER)))
9627
9628 continue;
9629
9630 /* Anything except a regular INSN will stop our search. */
9631 if (! NONJUMP_INSN_P (floater))
9632 {
9633 floater = NULL;
9634 break;
9635 }
9636
9637 /* See if FLOATER is suitable for combination with the
9638 anchor. */
9639 floater_attr = get_attr_pa_combine_type (floater);
9640 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
9641 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
9642 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
9643 && floater_attr == PA_COMBINE_TYPE_FMPY))
9644 {
9645 /* If ANCHOR and FLOATER can be combined, then we're
9646 done with this pass. */
9647 if (pa_can_combine_p (new_rtx, anchor, floater, 1,
9648 SET_DEST (PATTERN (floater)),
9649 XEXP (SET_SRC (PATTERN (floater)),
9650 0),
9651 XEXP (SET_SRC (PATTERN (floater)),
9652 1)))
9653 break;
9654 }
9655 }
9656 }
9657
9658 /* FLOATER will be nonzero if we found a suitable floating
9659 insn for combination with ANCHOR. */
9660 if (floater
9661 && (anchor_attr == PA_COMBINE_TYPE_FADDSUB
9662 || anchor_attr == PA_COMBINE_TYPE_FMPY))
9663 {
9664 /* Emit the new instruction and delete the old anchor. */
9665 rtvec vtemp = gen_rtvec (2, copy_rtx (PATTERN (anchor)),
9666 copy_rtx (PATTERN (floater)));
9667 rtx temp = gen_rtx_PARALLEL (VOIDmode, vtemp);
9668 emit_insn_before (temp, anchor);
9669
9670 SET_INSN_DELETED (anchor);
9671
9672 /* Emit a special USE insn for FLOATER, then delete
9673 the floating insn. */
9674 temp = copy_rtx (PATTERN (floater));
9675 emit_insn_before (gen_rtx_USE (VOIDmode, temp), floater);
9676 delete_insn (floater);
9677
9678 continue;
9679 }
9680 else if (floater
9681 && anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH)
9682 {
9683 /* Emit the new_jump instruction and delete the old anchor. */
9684 rtvec vtemp = gen_rtvec (2, copy_rtx (PATTERN (anchor)),
9685 copy_rtx (PATTERN (floater)));
9686 rtx temp = gen_rtx_PARALLEL (VOIDmode, vtemp);
9687 temp = emit_jump_insn_before (temp, anchor);
9688
9689 JUMP_LABEL (temp) = JUMP_LABEL (anchor);
9690 SET_INSN_DELETED (anchor);
9691
9692 /* Emit a special USE insn for FLOATER, then delete
9693 the floating insn. */
9694 temp = copy_rtx (PATTERN (floater));
9695 emit_insn_before (gen_rtx_USE (VOIDmode, temp), floater);
9696 delete_insn (floater);
9697 continue;
9698 }
9699 }
9700 }
9701 }
9702
9703 static int
9704 pa_can_combine_p (rtx_insn *new_rtx, rtx_insn *anchor, rtx_insn *floater,
9705 int reversed, rtx dest,
9706 rtx src1, rtx src2)
9707 {
9708 int insn_code_number;
9709 rtx_insn *start, *end;
9710
9711 /* Create a PARALLEL with the patterns of ANCHOR and
9712 FLOATER, try to recognize it, then test constraints
9713 for the resulting pattern.
9714
9715 If the pattern doesn't match or the constraints
9716 aren't met keep searching for a suitable floater
9717 insn. */
9718 XVECEXP (PATTERN (new_rtx), 0, 0) = PATTERN (anchor);
9719 XVECEXP (PATTERN (new_rtx), 0, 1) = PATTERN (floater);
9720 INSN_CODE (new_rtx) = -1;
9721 insn_code_number = recog_memoized (new_rtx);
9722 basic_block bb = BLOCK_FOR_INSN (anchor);
9723 if (insn_code_number < 0
9724 || (extract_insn (new_rtx),
9725 !constrain_operands (1, get_preferred_alternatives (new_rtx, bb))))
9726 return 0;
9727
9728 if (reversed)
9729 {
9730 start = anchor;
9731 end = floater;
9732 }
9733 else
9734 {
9735 start = floater;
9736 end = anchor;
9737 }
9738
9739 /* There's up to three operands to consider. One
9740 output and two inputs.
9741
9742 The output must not be used between FLOATER & ANCHOR
9743 exclusive. The inputs must not be set between
9744 FLOATER and ANCHOR exclusive. */
9745
9746 if (reg_used_between_p (dest, start, end))
9747 return 0;
9748
9749 if (reg_set_between_p (src1, start, end))
9750 return 0;
9751
9752 if (reg_set_between_p (src2, start, end))
9753 return 0;
9754
9755 /* If we get here, then everything is good. */
9756 return 1;
9757 }
9758
9759 /* Return nonzero if references for INSN are delayed.
9760
9761 Millicode insns are actually function calls with some special
9762 constraints on arguments and register usage.
9763
9764 Millicode calls always expect their arguments in the integer argument
9765 registers, and always return their result in %r29 (ret1). They
9766 are expected to clobber their arguments, %r1, %r29, and the return
9767 pointer which is %r31 on 32-bit and %r2 on 64-bit, and nothing else.
9768
9769 This function tells reorg that the references to arguments and
9770 millicode calls do not appear to happen until after the millicode call.
9771 This allows reorg to put insns which set the argument registers into the
9772 delay slot of the millicode call -- thus they act more like traditional
9773 CALL_INSNs.
9774
9775 Note we cannot consider side effects of the insn to be delayed because
9776 the branch and link insn will clobber the return pointer. If we happened
9777 to use the return pointer in the delay slot of the call, then we lose.
9778
9779 get_attr_type will try to recognize the given insn, so make sure to
9780 filter out things it will not accept -- SEQUENCE, USE and CLOBBER insns
9781 in particular. */
9782 int
9783 pa_insn_refs_are_delayed (rtx_insn *insn)
9784 {
9785 return ((NONJUMP_INSN_P (insn)
9786 && GET_CODE (PATTERN (insn)) != SEQUENCE
9787 && GET_CODE (PATTERN (insn)) != USE
9788 && GET_CODE (PATTERN (insn)) != CLOBBER
9789 && get_attr_type (insn) == TYPE_MILLI));
9790 }
9791
9792 /* Promote the return value, but not the arguments. */
9793
9794 static machine_mode
9795 pa_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
9796 machine_mode mode,
9797 int *punsignedp ATTRIBUTE_UNUSED,
9798 const_tree fntype ATTRIBUTE_UNUSED,
9799 int for_return)
9800 {
9801 if (for_return == 0)
9802 return mode;
9803 return promote_mode (type, mode, punsignedp);
9804 }
9805
9806 /* On the HP-PA the value is found in register(s) 28(-29), unless
9807 the mode is SF or DF. Then the value is returned in fr4 (32).
9808
9809 This must perform the same promotions as PROMOTE_MODE, else promoting
9810 return values in TARGET_PROMOTE_FUNCTION_MODE will not work correctly.
9811
9812 Small structures must be returned in a PARALLEL on PA64 in order
9813 to match the HP Compiler ABI. */
9814
9815 static rtx
9816 pa_function_value (const_tree valtype,
9817 const_tree func ATTRIBUTE_UNUSED,
9818 bool outgoing ATTRIBUTE_UNUSED)
9819 {
9820 machine_mode valmode;
9821
9822 if (AGGREGATE_TYPE_P (valtype)
9823 || TREE_CODE (valtype) == COMPLEX_TYPE
9824 || VECTOR_TYPE_P (valtype))
9825 {
9826 HOST_WIDE_INT valsize = int_size_in_bytes (valtype);
9827
9828 /* Handle aggregates that fit exactly in a word or double word. */
9829 if (valsize == UNITS_PER_WORD || valsize == 2 * UNITS_PER_WORD)
9830 return gen_rtx_REG (TYPE_MODE (valtype), 28);
9831
9832 if (TARGET_64BIT)
9833 {
9834 /* Aggregates with a size less than or equal to 128 bits are
9835 returned in GR 28(-29). They are left justified. The pad
9836 bits are undefined. Larger aggregates are returned in
9837 memory. */
9838 rtx loc[2];
9839 int i, offset = 0;
9840 int ub = valsize <= UNITS_PER_WORD ? 1 : 2;
9841
9842 for (i = 0; i < ub; i++)
9843 {
9844 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9845 gen_rtx_REG (DImode, 28 + i),
9846 GEN_INT (offset));
9847 offset += 8;
9848 }
9849
9850 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (ub, loc));
9851 }
9852 else if (valsize > UNITS_PER_WORD)
9853 {
9854 /* Aggregates 5 to 8 bytes in size are returned in general
9855 registers r28-r29 in the same manner as other non
9856 floating-point objects. The data is right-justified and
9857 zero-extended to 64 bits. This is opposite to the normal
9858 justification used on big endian targets and requires
9859 special treatment. */
9860 rtx loc = gen_rtx_EXPR_LIST (VOIDmode,
9861 gen_rtx_REG (DImode, 28), const0_rtx);
9862 return gen_rtx_PARALLEL (BLKmode, gen_rtvec (1, loc));
9863 }
9864 }
9865
9866 if ((INTEGRAL_TYPE_P (valtype)
9867 && GET_MODE_BITSIZE (TYPE_MODE (valtype)) < BITS_PER_WORD)
9868 || POINTER_TYPE_P (valtype))
9869 valmode = word_mode;
9870 else
9871 valmode = TYPE_MODE (valtype);
9872
9873 if (SCALAR_FLOAT_TYPE_P (valtype)
9874 && !AGGREGATE_TYPE_P (valtype)
9875 && TYPE_MODE (valtype) != TFmode
9876 && !TARGET_SOFT_FLOAT)
9877 return gen_rtx_REG (valmode, 32);
9878
9879 return gen_rtx_REG (valmode, 28);
9880 }
9881
9882 /* Implement the TARGET_LIBCALL_VALUE hook. */
9883
9884 static rtx
9885 pa_libcall_value (machine_mode mode,
9886 const_rtx fun ATTRIBUTE_UNUSED)
9887 {
9888 if (! TARGET_SOFT_FLOAT
9889 && (mode == SFmode || mode == DFmode))
9890 return gen_rtx_REG (mode, 32);
9891 else
9892 return gen_rtx_REG (mode, 28);
9893 }
9894
9895 /* Implement the TARGET_FUNCTION_VALUE_REGNO_P hook. */
9896
9897 static bool
9898 pa_function_value_regno_p (const unsigned int regno)
9899 {
9900 if (regno == 28
9901 || (! TARGET_SOFT_FLOAT && regno == 32))
9902 return true;
9903
9904 return false;
9905 }
9906
9907 /* Update the data in CUM to advance over argument ARG. */
9908
9909 static void
9910 pa_function_arg_advance (cumulative_args_t cum_v,
9911 const function_arg_info &arg)
9912 {
9913 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
9914 int arg_size = pa_function_arg_size (arg.mode, arg.type);
9915
9916 cum->nargs_prototype--;
9917 cum->words += (arg_size
9918 + ((cum->words & 01)
9919 && arg.type != NULL_TREE
9920 && arg_size > 1));
9921 }
9922
9923 /* Return the location of a parameter that is passed in a register or NULL
9924 if the parameter has any component that is passed in memory.
9925
9926 This is new code and will be pushed to into the net sources after
9927 further testing.
9928
9929 ??? We might want to restructure this so that it looks more like other
9930 ports. */
9931 static rtx
9932 pa_function_arg (cumulative_args_t cum_v, const function_arg_info &arg)
9933 {
9934 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
9935 tree type = arg.type;
9936 machine_mode mode = arg.mode;
9937 int max_arg_words = (TARGET_64BIT ? 8 : 4);
9938 int alignment = 0;
9939 int arg_size;
9940 int fpr_reg_base;
9941 int gpr_reg_base;
9942 rtx retval;
9943
9944 if (arg.end_marker_p ())
9945 return NULL_RTX;
9946
9947 arg_size = pa_function_arg_size (mode, type);
9948 if (!arg_size)
9949 return NULL_RTX;
9950
9951 /* If this arg would be passed partially or totally on the stack, then
9952 this routine should return zero. pa_arg_partial_bytes will
9953 handle arguments which are split between regs and stack slots if
9954 the ABI mandates split arguments. */
9955 if (!TARGET_64BIT)
9956 {
9957 /* The 32-bit ABI does not split arguments. */
9958 if (cum->words + arg_size > max_arg_words)
9959 return NULL_RTX;
9960 }
9961 else
9962 {
9963 if (arg_size > 1)
9964 alignment = cum->words & 1;
9965 if (cum->words + alignment >= max_arg_words)
9966 return NULL_RTX;
9967 }
9968
9969 /* The 32bit ABIs and the 64bit ABIs are rather different,
9970 particularly in their handling of FP registers. We might
9971 be able to cleverly share code between them, but I'm not
9972 going to bother in the hope that splitting them up results
9973 in code that is more easily understood. */
9974
9975 if (TARGET_64BIT)
9976 {
9977 /* Advance the base registers to their current locations.
9978
9979 Remember, gprs grow towards smaller register numbers while
9980 fprs grow to higher register numbers. Also remember that
9981 although FP regs are 32-bit addressable, we pretend that
9982 the registers are 64-bits wide. */
9983 gpr_reg_base = 26 - cum->words;
9984 fpr_reg_base = 32 + cum->words;
9985
9986 /* Arguments wider than one word and small aggregates need special
9987 treatment. */
9988 if (arg_size > 1
9989 || mode == BLKmode
9990 || (type && (AGGREGATE_TYPE_P (type)
9991 || TREE_CODE (type) == COMPLEX_TYPE
9992 || VECTOR_TYPE_P (type))))
9993 {
9994 /* Double-extended precision (80-bit), quad-precision (128-bit)
9995 and aggregates including complex numbers are aligned on
9996 128-bit boundaries. The first eight 64-bit argument slots
9997 are associated one-to-one, with general registers r26
9998 through r19, and also with floating-point registers fr4
9999 through fr11. Arguments larger than one word are always
10000 passed in general registers.
10001
10002 Using a PARALLEL with a word mode register results in left
10003 justified data on a big-endian target. */
10004
10005 rtx loc[8];
10006 int i, offset = 0, ub = arg_size;
10007
10008 /* Align the base register. */
10009 gpr_reg_base -= alignment;
10010
10011 ub = MIN (ub, max_arg_words - cum->words - alignment);
10012 for (i = 0; i < ub; i++)
10013 {
10014 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
10015 gen_rtx_REG (DImode, gpr_reg_base),
10016 GEN_INT (offset));
10017 gpr_reg_base -= 1;
10018 offset += 8;
10019 }
10020
10021 return gen_rtx_PARALLEL (mode, gen_rtvec_v (ub, loc));
10022 }
10023 }
10024 else
10025 {
10026 /* If the argument is larger than a word, then we know precisely
10027 which registers we must use. */
10028 if (arg_size > 1)
10029 {
10030 if (cum->words)
10031 {
10032 gpr_reg_base = 23;
10033 fpr_reg_base = 38;
10034 }
10035 else
10036 {
10037 gpr_reg_base = 25;
10038 fpr_reg_base = 34;
10039 }
10040
10041 /* Structures 5 to 8 bytes in size are passed in the general
10042 registers in the same manner as other non floating-point
10043 objects. The data is right-justified and zero-extended
10044 to 64 bits. This is opposite to the normal justification
10045 used on big endian targets and requires special treatment.
10046 We now define BLOCK_REG_PADDING to pad these objects.
10047 Aggregates, complex and vector types are passed in the same
10048 manner as structures. */
10049 if (mode == BLKmode
10050 || (type && (AGGREGATE_TYPE_P (type)
10051 || TREE_CODE (type) == COMPLEX_TYPE
10052 || VECTOR_TYPE_P (type))))
10053 {
10054 rtx loc = gen_rtx_EXPR_LIST (VOIDmode,
10055 gen_rtx_REG (DImode, gpr_reg_base),
10056 const0_rtx);
10057 return gen_rtx_PARALLEL (BLKmode, gen_rtvec (1, loc));
10058 }
10059 }
10060 else
10061 {
10062 /* We have a single word (32 bits). A simple computation
10063 will get us the register #s we need. */
10064 gpr_reg_base = 26 - cum->words;
10065 fpr_reg_base = 32 + 2 * cum->words;
10066 }
10067 }
10068
10069 /* Determine if the argument needs to be passed in both general and
10070 floating point registers. */
10071 if (((TARGET_PORTABLE_RUNTIME || TARGET_64BIT || TARGET_ELF32)
10072 /* If we are doing soft-float with portable runtime, then there
10073 is no need to worry about FP regs. */
10074 && !TARGET_SOFT_FLOAT
10075 /* The parameter must be some kind of scalar float, else we just
10076 pass it in integer registers. */
10077 && GET_MODE_CLASS (mode) == MODE_FLOAT
10078 /* The target function must not have a prototype. */
10079 && cum->nargs_prototype <= 0
10080 /* libcalls do not need to pass items in both FP and general
10081 registers. */
10082 && type != NULL_TREE
10083 /* All this hair applies to "outgoing" args only. This includes
10084 sibcall arguments setup with FUNCTION_INCOMING_ARG. */
10085 && !cum->incoming)
10086 /* Also pass outgoing floating arguments in both registers in indirect
10087 calls with the 32 bit ABI and the HP assembler since there is no
10088 way to the specify argument locations in static functions. */
10089 || (!TARGET_64BIT
10090 && !TARGET_GAS
10091 && !cum->incoming
10092 && cum->indirect
10093 && GET_MODE_CLASS (mode) == MODE_FLOAT))
10094 {
10095 retval
10096 = gen_rtx_PARALLEL
10097 (mode,
10098 gen_rtvec (2,
10099 gen_rtx_EXPR_LIST (VOIDmode,
10100 gen_rtx_REG (mode, fpr_reg_base),
10101 const0_rtx),
10102 gen_rtx_EXPR_LIST (VOIDmode,
10103 gen_rtx_REG (mode, gpr_reg_base),
10104 const0_rtx)));
10105 }
10106 else
10107 {
10108 /* See if we should pass this parameter in a general register. */
10109 if (TARGET_SOFT_FLOAT
10110 /* Indirect calls in the normal 32bit ABI require all arguments
10111 to be passed in general registers. */
10112 || (!TARGET_PORTABLE_RUNTIME
10113 && !TARGET_64BIT
10114 && !TARGET_ELF32
10115 && cum->indirect)
10116 /* If the parameter is not a scalar floating-point parameter,
10117 then it belongs in GPRs. */
10118 || GET_MODE_CLASS (mode) != MODE_FLOAT
10119 /* Structure with single SFmode field belongs in GPR. */
10120 || (type && AGGREGATE_TYPE_P (type)))
10121 retval = gen_rtx_REG (mode, gpr_reg_base);
10122 else
10123 retval = gen_rtx_REG (mode, fpr_reg_base);
10124 }
10125 return retval;
10126 }
10127
10128 /* Arguments larger than one word are double word aligned. */
10129
10130 static unsigned int
10131 pa_function_arg_boundary (machine_mode mode, const_tree type)
10132 {
10133 bool singleword = (type
10134 ? (integer_zerop (TYPE_SIZE (type))
10135 || !TREE_CONSTANT (TYPE_SIZE (type))
10136 || int_size_in_bytes (type) <= UNITS_PER_WORD)
10137 : GET_MODE_SIZE (mode) <= UNITS_PER_WORD);
10138
10139 return singleword ? PARM_BOUNDARY : MAX_PARM_BOUNDARY;
10140 }
10141
10142 /* If this arg would be passed totally in registers or totally on the stack,
10143 then this routine should return zero. */
10144
10145 static int
10146 pa_arg_partial_bytes (cumulative_args_t cum_v, const function_arg_info &arg)
10147 {
10148 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
10149 unsigned int max_arg_words = 8;
10150 unsigned int offset = 0;
10151 int arg_size;
10152
10153 if (!TARGET_64BIT)
10154 return 0;
10155
10156 arg_size = pa_function_arg_size (arg.mode, arg.type);
10157 if (arg_size > 1 && (cum->words & 1))
10158 offset = 1;
10159
10160 if (cum->words + offset + arg_size <= max_arg_words)
10161 /* Arg fits fully into registers. */
10162 return 0;
10163 else if (cum->words + offset >= max_arg_words)
10164 /* Arg fully on the stack. */
10165 return 0;
10166 else
10167 /* Arg is split. */
10168 return (max_arg_words - cum->words - offset) * UNITS_PER_WORD;
10169 }
10170
10171
10172 /* A get_unnamed_section callback for switching to the text section.
10173
10174 This function is only used with SOM. Because we don't support
10175 named subspaces, we can only create a new subspace or switch back
10176 to the default text subspace. */
10177
10178 static void
10179 som_output_text_section_asm_op (const char *data ATTRIBUTE_UNUSED)
10180 {
10181 gcc_assert (TARGET_SOM);
10182 if (TARGET_GAS)
10183 {
10184 if (cfun && cfun->machine && !cfun->machine->in_nsubspa)
10185 {
10186 /* We only want to emit a .nsubspa directive once at the
10187 start of the function. */
10188 cfun->machine->in_nsubspa = 1;
10189
10190 /* Create a new subspace for the text. This provides
10191 better stub placement and one-only functions. */
10192 if (cfun->decl
10193 && DECL_ONE_ONLY (cfun->decl)
10194 && !DECL_WEAK (cfun->decl))
10195 {
10196 output_section_asm_op ("\t.SPACE $TEXT$\n"
10197 "\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,"
10198 "ACCESS=44,SORT=24,COMDAT");
10199 return;
10200 }
10201 }
10202 else
10203 {
10204 /* There isn't a current function or the body of the current
10205 function has been completed. So, we are changing to the
10206 text section to output debugging information. Thus, we
10207 need to forget that we are in the text section so that
10208 varasm.cc will call us when text_section is selected again. */
10209 gcc_assert (!cfun || !cfun->machine
10210 || cfun->machine->in_nsubspa == 2);
10211 in_section = NULL;
10212 }
10213 output_section_asm_op ("\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$");
10214 return;
10215 }
10216 output_section_asm_op ("\t.SPACE $TEXT$\n\t.SUBSPA $CODE$");
10217 }
10218
10219 /* A get_unnamed_section callback for switching to comdat data
10220 sections. This function is only used with SOM. */
10221
10222 static void
10223 som_output_comdat_data_section_asm_op (const char *data)
10224 {
10225 in_section = NULL;
10226 output_section_asm_op (data);
10227 }
10228
10229 /* Implement TARGET_ASM_INIT_SECTIONS. */
10230
10231 static void
10232 pa_som_asm_init_sections (void)
10233 {
10234 text_section
10235 = get_unnamed_section (0, som_output_text_section_asm_op, NULL);
10236
10237 /* SOM puts readonly data in the default $LIT$ subspace when PIC code
10238 is not being generated. */
10239 som_readonly_data_section
10240 = get_unnamed_section (0, output_section_asm_op,
10241 "\t.SPACE $TEXT$\n\t.SUBSPA $LIT$");
10242
10243 /* When secondary definitions are not supported, SOM makes readonly
10244 data one-only by creating a new $LIT$ subspace in $TEXT$ with
10245 the comdat flag. */
10246 som_one_only_readonly_data_section
10247 = get_unnamed_section (0, som_output_comdat_data_section_asm_op,
10248 "\t.SPACE $TEXT$\n"
10249 "\t.NSUBSPA $LIT$,QUAD=0,ALIGN=8,"
10250 "ACCESS=0x2c,SORT=16,COMDAT");
10251
10252
10253 /* When secondary definitions are not supported, SOM makes data one-only
10254 by creating a new $DATA$ subspace in $PRIVATE$ with the comdat flag. */
10255 som_one_only_data_section
10256 = get_unnamed_section (SECTION_WRITE,
10257 som_output_comdat_data_section_asm_op,
10258 "\t.SPACE $PRIVATE$\n"
10259 "\t.NSUBSPA $DATA$,QUAD=1,ALIGN=8,"
10260 "ACCESS=31,SORT=24,COMDAT");
10261
10262 if (flag_tm)
10263 som_tm_clone_table_section
10264 = get_unnamed_section (0, output_section_asm_op,
10265 "\t.SPACE $PRIVATE$\n\t.SUBSPA $TM_CLONE_TABLE$");
10266
10267 /* HPUX ld generates incorrect GOT entries for "T" fixups which
10268 reference data within the $TEXT$ space (for example constant
10269 strings in the $LIT$ subspace).
10270
10271 The assemblers (GAS and HP as) both have problems with handling
10272 the difference of two symbols. This is the other correct way to
10273 reference constant data during PIC code generation.
10274
10275 Thus, we can't put constant data needing relocation in the $TEXT$
10276 space during PIC generation.
10277
10278 Previously, we placed all constant data into the $DATA$ subspace
10279 when generating PIC code. This reduces sharing, but it works
10280 correctly. Now we rely on pa_reloc_rw_mask() for section selection.
10281 This puts constant data not needing relocation into the $TEXT$ space. */
10282 readonly_data_section = som_readonly_data_section;
10283
10284 /* We must not have a reference to an external symbol defined in a
10285 shared library in a readonly section, else the SOM linker will
10286 complain.
10287
10288 So, we force exception information into the data section. */
10289 exception_section = data_section;
10290 }
10291
10292 /* Implement TARGET_ASM_TM_CLONE_TABLE_SECTION. */
10293
10294 static section *
10295 pa_som_tm_clone_table_section (void)
10296 {
10297 return som_tm_clone_table_section;
10298 }
10299
10300 /* On hpux10, the linker will give an error if we have a reference
10301 in the read-only data section to a symbol defined in a shared
10302 library. Therefore, expressions that might require a reloc
10303 cannot be placed in the read-only data section. */
10304
10305 static section *
10306 pa_select_section (tree exp, int reloc,
10307 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
10308 {
10309 if (TREE_CODE (exp) == VAR_DECL
10310 && TREE_READONLY (exp)
10311 && !TREE_THIS_VOLATILE (exp)
10312 && DECL_INITIAL (exp)
10313 && (DECL_INITIAL (exp) == error_mark_node
10314 || TREE_CONSTANT (DECL_INITIAL (exp)))
10315 && !(reloc & pa_reloc_rw_mask ()))
10316 {
10317 if (TARGET_SOM
10318 && DECL_ONE_ONLY (exp)
10319 && !DECL_WEAK (exp))
10320 return som_one_only_readonly_data_section;
10321 else
10322 return readonly_data_section;
10323 }
10324 else if (CONSTANT_CLASS_P (exp)
10325 && !(reloc & pa_reloc_rw_mask ()))
10326 return readonly_data_section;
10327 else if (TARGET_SOM
10328 && TREE_CODE (exp) == VAR_DECL
10329 && DECL_ONE_ONLY (exp)
10330 && !DECL_WEAK (exp))
10331 return som_one_only_data_section;
10332 else
10333 return data_section;
10334 }
10335
10336 /* Implement pa_elf_select_rtx_section. If X is a function label operand
10337 and the function is in a COMDAT group, place the plabel reference in the
10338 .data.rel.ro.local section. The linker ignores references to symbols in
10339 discarded sections from this section. */
10340
10341 static section *
10342 pa_elf_select_rtx_section (machine_mode mode, rtx x,
10343 unsigned HOST_WIDE_INT align)
10344 {
10345 if (function_label_operand (x, VOIDmode))
10346 {
10347 tree decl = SYMBOL_REF_DECL (x);
10348
10349 if (!decl || (DECL_P (decl) && DECL_COMDAT_GROUP (decl)))
10350 return get_named_section (NULL, ".data.rel.ro.local", 1);
10351 }
10352
10353 return default_elf_select_rtx_section (mode, x, align);
10354 }
10355
10356 /* Implement pa_reloc_rw_mask. */
10357
10358 static int
10359 pa_reloc_rw_mask (void)
10360 {
10361 if (flag_pic || (TARGET_SOM && !TARGET_HPUX_11))
10362 return 3;
10363
10364 /* HP linker does not support global relocs in readonly memory. */
10365 return TARGET_SOM ? 2 : 0;
10366 }
10367
10368 static void
10369 pa_globalize_label (FILE *stream, const char *name)
10370 {
10371 /* We only handle DATA objects here, functions are globalized in
10372 ASM_DECLARE_FUNCTION_NAME. */
10373 if (! FUNCTION_NAME_P (name))
10374 {
10375 fputs ("\t.EXPORT ", stream);
10376 assemble_name (stream, name);
10377 fputs (",DATA\n", stream);
10378 }
10379 }
10380
10381 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
10382
10383 static rtx
10384 pa_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
10385 int incoming ATTRIBUTE_UNUSED)
10386 {
10387 return gen_rtx_REG (Pmode, PA_STRUCT_VALUE_REGNUM);
10388 }
10389
10390 /* Worker function for TARGET_RETURN_IN_MEMORY. */
10391
10392 bool
10393 pa_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
10394 {
10395 /* SOM ABI says that objects larger than 64 bits are returned in memory.
10396 PA64 ABI says that objects larger than 128 bits are returned in memory.
10397 Note, int_size_in_bytes can return -1 if the size of the object is
10398 variable or larger than the maximum value that can be expressed as
10399 a HOST_WIDE_INT. It can also return zero for an empty type. The
10400 simplest way to handle variable and empty types is to pass them in
10401 memory. This avoids problems in defining the boundaries of argument
10402 slots, allocating registers, etc. */
10403 return (int_size_in_bytes (type) > (TARGET_64BIT ? 16 : 8)
10404 || int_size_in_bytes (type) <= 0);
10405 }
10406
10407 /* Structure to hold declaration and name of external symbols that are
10408 emitted by GCC. We generate a vector of these symbols and output them
10409 at the end of the file if and only if SYMBOL_REF_REFERENCED_P is true.
10410 This avoids putting out names that are never really used. */
10411
10412 typedef struct GTY(()) extern_symbol
10413 {
10414 tree decl;
10415 const char *name;
10416 } extern_symbol;
10417
10418 /* Define gc'd vector type for extern_symbol. */
10419
10420 /* Vector of extern_symbol pointers. */
10421 static GTY(()) vec<extern_symbol, va_gc> *extern_symbols;
10422
10423 #ifdef ASM_OUTPUT_EXTERNAL_REAL
10424 /* Mark DECL (name NAME) as an external reference (assembler output
10425 file FILE). This saves the names to output at the end of the file
10426 if actually referenced. */
10427
10428 void
10429 pa_hpux_asm_output_external (FILE *file, tree decl, const char *name)
10430 {
10431 gcc_assert (file == asm_out_file);
10432 extern_symbol p = {decl, name};
10433 vec_safe_push (extern_symbols, p);
10434 }
10435 #endif
10436
10437 /* Output text required at the end of an assembler file.
10438 This includes deferred plabels and .import directives for
10439 all external symbols that were actually referenced. */
10440
10441 static void
10442 pa_file_end (void)
10443 {
10444 #ifdef ASM_OUTPUT_EXTERNAL_REAL
10445 unsigned int i;
10446 extern_symbol *p;
10447
10448 if (!NO_DEFERRED_PROFILE_COUNTERS)
10449 output_deferred_profile_counters ();
10450 #endif
10451
10452 output_deferred_plabels ();
10453
10454 #ifdef ASM_OUTPUT_EXTERNAL_REAL
10455 for (i = 0; vec_safe_iterate (extern_symbols, i, &p); i++)
10456 {
10457 tree decl = p->decl;
10458
10459 if (!TREE_ASM_WRITTEN (decl)
10460 && SYMBOL_REF_REFERENCED_P (XEXP (DECL_RTL (decl), 0)))
10461 ASM_OUTPUT_EXTERNAL_REAL (asm_out_file, decl, p->name);
10462 }
10463
10464 vec_free (extern_symbols);
10465 #endif
10466
10467 if (NEED_INDICATE_EXEC_STACK)
10468 file_end_indicate_exec_stack ();
10469 }
10470
10471 /* Implement TARGET_CAN_CHANGE_MODE_CLASS. */
10472
10473 static bool
10474 pa_can_change_mode_class (machine_mode from, machine_mode to,
10475 reg_class_t rclass)
10476 {
10477 if (from == to)
10478 return true;
10479
10480 if (GET_MODE_SIZE (from) == GET_MODE_SIZE (to))
10481 return true;
10482
10483 /* Reject changes to/from modes with zero size. */
10484 if (!GET_MODE_SIZE (from) || !GET_MODE_SIZE (to))
10485 return false;
10486
10487 /* Reject changes to/from complex and vector modes. */
10488 if (COMPLEX_MODE_P (from) || VECTOR_MODE_P (from)
10489 || COMPLEX_MODE_P (to) || VECTOR_MODE_P (to))
10490 return false;
10491
10492 /* There is no way to load QImode or HImode values directly from memory
10493 to a FP register. SImode loads to the FP registers are not zero
10494 extended. On the 64-bit target, this conflicts with the definition
10495 of LOAD_EXTEND_OP. Thus, we reject all mode changes in the FP registers
10496 except for DImode to SImode on the 64-bit target. It is handled by
10497 register renaming in pa_print_operand. */
10498 if (MAYBE_FP_REG_CLASS_P (rclass))
10499 return TARGET_64BIT && from == DImode && to == SImode;
10500
10501 /* TARGET_HARD_REGNO_MODE_OK places modes with sizes larger than a word
10502 in specific sets of registers. Thus, we cannot allow changing
10503 to a larger mode when it's larger than a word. */
10504 if (GET_MODE_SIZE (to) > UNITS_PER_WORD
10505 && GET_MODE_SIZE (to) > GET_MODE_SIZE (from))
10506 return false;
10507
10508 return true;
10509 }
10510
10511 /* Implement TARGET_MODES_TIEABLE_P.
10512
10513 We should return FALSE for QImode and HImode because these modes
10514 are not ok in the floating-point registers. However, this prevents
10515 tieing these modes to SImode and DImode in the general registers.
10516 So, this isn't a good idea. We rely on TARGET_HARD_REGNO_MODE_OK and
10517 TARGET_CAN_CHANGE_MODE_CLASS to prevent these modes from being used
10518 in the floating-point registers. */
10519
10520 static bool
10521 pa_modes_tieable_p (machine_mode mode1, machine_mode mode2)
10522 {
10523 /* Don't tie modes in different classes. */
10524 if (GET_MODE_CLASS (mode1) != GET_MODE_CLASS (mode2))
10525 return false;
10526
10527 return true;
10528 }
10529
10530
10531 /* Length in units of the trampoline instruction code. */
10532
10533 #define TRAMPOLINE_CODE_SIZE (TARGET_64BIT ? 24 : (TARGET_PA_20 ? 36 : 48))
10534
10535
10536 /* Output assembler code for a block containing the constant parts
10537 of a trampoline, leaving space for the variable parts.\
10538
10539 The trampoline sets the static chain pointer to STATIC_CHAIN_REGNUM
10540 and then branches to the specified routine.
10541
10542 This code template is copied from text segment to stack location
10543 and then patched with pa_trampoline_init to contain valid values,
10544 and then entered as a subroutine.
10545
10546 It is best to keep this as small as possible to avoid having to
10547 flush multiple lines in the cache. */
10548
10549 static void
10550 pa_asm_trampoline_template (FILE *f)
10551 {
10552 if (!TARGET_64BIT)
10553 {
10554 if (TARGET_PA_20)
10555 {
10556 fputs ("\tmfia %r20\n", f);
10557 fputs ("\tldw 48(%r20),%r22\n", f);
10558 fputs ("\tcopy %r22,%r21\n", f);
10559 fputs ("\tbb,>=,n %r22,30,.+16\n", f);
10560 fputs ("\tdepwi 0,31,2,%r22\n", f);
10561 fputs ("\tldw 0(%r22),%r21\n", f);
10562 fputs ("\tldw 4(%r22),%r19\n", f);
10563 fputs ("\tbve (%r21)\n", f);
10564 fputs ("\tldw 52(%r20),%r29\n", f);
10565 fputs ("\t.word 0\n", f);
10566 fputs ("\t.word 0\n", f);
10567 fputs ("\t.word 0\n", f);
10568 }
10569 else
10570 {
10571 if (ASSEMBLER_DIALECT == 0)
10572 {
10573 fputs ("\tbl .+8,%r20\n", f);
10574 fputs ("\tdepi 0,31,2,%r20\n", f);
10575 }
10576 else
10577 {
10578 fputs ("\tb,l .+8,%r20\n", f);
10579 fputs ("\tdepwi 0,31,2,%r20\n", f);
10580 }
10581 fputs ("\tldw 40(%r20),%r22\n", f);
10582 fputs ("\tcopy %r22,%r21\n", f);
10583 fputs ("\tbb,>=,n %r22,30,.+16\n", f);
10584 if (ASSEMBLER_DIALECT == 0)
10585 fputs ("\tdepi 0,31,2,%r22\n", f);
10586 else
10587 fputs ("\tdepwi 0,31,2,%r22\n", f);
10588 fputs ("\tldw 0(%r22),%r21\n", f);
10589 fputs ("\tldw 4(%r22),%r19\n", f);
10590 fputs ("\tldsid (%r21),%r1\n", f);
10591 fputs ("\tmtsp %r1,%sr0\n", f);
10592 fputs ("\tbe 0(%sr0,%r21)\n", f);
10593 fputs ("\tldw 44(%r20),%r29\n", f);
10594 }
10595 fputs ("\t.word 0\n", f);
10596 fputs ("\t.word 0\n", f);
10597 fputs ("\t.word 0\n", f);
10598 fputs ("\t.word 0\n", f);
10599 }
10600 else
10601 {
10602 fputs ("\t.dword 0\n", f);
10603 fputs ("\t.dword 0\n", f);
10604 fputs ("\t.dword 0\n", f);
10605 fputs ("\t.dword 0\n", f);
10606 fputs ("\tmfia %r31\n", f);
10607 fputs ("\tldd 24(%r31),%r27\n", f);
10608 fputs ("\tldd 32(%r31),%r31\n", f);
10609 fputs ("\tldd 16(%r27),%r1\n", f);
10610 fputs ("\tbve (%r1)\n", f);
10611 fputs ("\tldd 24(%r27),%r27\n", f);
10612 fputs ("\t.dword 0 ; fptr\n", f);
10613 fputs ("\t.dword 0 ; static link\n", f);
10614 }
10615 }
10616
10617 /* Emit RTL insns to initialize the variable parts of a trampoline.
10618 FNADDR is an RTX for the address of the function's pure code.
10619 CXT is an RTX for the static chain value for the function.
10620
10621 Move the function address to the trampoline template at offset 48.
10622 Move the static chain value to trampoline template at offset 52.
10623 Move the trampoline address to trampoline template at offset 56.
10624 Move r19 to trampoline template at offset 60. The latter two
10625 words create a plabel for the indirect call to the trampoline.
10626
10627 A similar sequence is used for the 64-bit port but the plabel is
10628 at the beginning of the trampoline.
10629
10630 Finally, the cache entries for the trampoline code are flushed.
10631 This is necessary to ensure that the trampoline instruction sequence
10632 is written to memory prior to any attempts at prefetching the code
10633 sequence. */
10634
10635 static void
10636 pa_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
10637 {
10638 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
10639 rtx start, end, r_tramp, tmp;
10640
10641 emit_block_move (m_tramp, assemble_trampoline_template (),
10642 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
10643 r_tramp = force_reg (Pmode, XEXP (m_tramp, 0));
10644
10645 if (!TARGET_64BIT)
10646 {
10647 /* Start of trampoline code. */
10648 start = r_tramp;
10649
10650 tmp = adjust_address (m_tramp, Pmode, 48);
10651 emit_move_insn (tmp, fnaddr);
10652 tmp = adjust_address (m_tramp, Pmode, 52);
10653 emit_move_insn (tmp, chain_value);
10654
10655 /* Create a fat pointer for the trampoline. */
10656 tmp = adjust_address (m_tramp, Pmode, 56);
10657 emit_move_insn (tmp, start);
10658 tmp = adjust_address (m_tramp, Pmode, 60);
10659 emit_move_insn (tmp, gen_rtx_REG (Pmode, 19));
10660 }
10661 else
10662 {
10663 /* Start of trampoline code. */
10664 start = force_reg (Pmode, plus_constant (Pmode, r_tramp, 32));
10665
10666 tmp = adjust_address (m_tramp, Pmode, 56);
10667 emit_move_insn (tmp, fnaddr);
10668 tmp = adjust_address (m_tramp, Pmode, 64);
10669 emit_move_insn (tmp, chain_value);
10670
10671 /* Create a fat pointer for the trampoline. */
10672 tmp = adjust_address (m_tramp, Pmode, 16);
10673 emit_move_insn (tmp, start);
10674 tmp = adjust_address (m_tramp, Pmode, 24);
10675 emit_move_insn (tmp, gen_rtx_REG (Pmode, 27));
10676 }
10677
10678 end = force_reg (Pmode, plus_constant (Pmode, start, TRAMPOLINE_CODE_SIZE));
10679
10680 /* Flush trampoline. */
10681 emit_insn (gen_clear_cache (start, end));
10682
10683 #ifdef HAVE_ENABLE_EXECUTE_STACK
10684 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
10685 LCT_NORMAL, VOIDmode, XEXP (m_tramp, 0), Pmode);
10686 #endif
10687 }
10688
10689 /* Perform any machine-specific adjustment in the address of the trampoline.
10690 ADDR contains the address that was passed to pa_trampoline_init.
10691 Adjust the trampoline address to point to the plabel at offset 56. */
10692
10693 static rtx
10694 pa_trampoline_adjust_address (rtx addr)
10695 {
10696 if (!TARGET_64BIT)
10697 addr = memory_address (Pmode, plus_constant (Pmode, addr, 58));
10698 return addr;
10699 }
10700
10701 static rtx
10702 pa_delegitimize_address (rtx orig_x)
10703 {
10704 rtx x;
10705
10706 if (GET_CODE (orig_x) == UNSPEC
10707 && XINT (orig_x, 1) == UNSPEC_TP)
10708 orig_x = XVECEXP (orig_x, 0, 0);
10709
10710 x = delegitimize_mem_from_attrs (orig_x);
10711
10712 if (GET_CODE (x) == LO_SUM
10713 && GET_CODE (XEXP (x, 1)) == UNSPEC
10714 && XINT (XEXP (x, 1), 1) == UNSPEC_DLTIND14R)
10715 return gen_const_mem (Pmode, XVECEXP (XEXP (x, 1), 0, 0));
10716 return x;
10717 }
10718
10719 static rtx
10720 pa_internal_arg_pointer (void)
10721 {
10722 /* The argument pointer and the hard frame pointer are the same in
10723 the 32-bit runtime, so we don't need a copy. */
10724 if (TARGET_64BIT)
10725 return copy_to_reg (virtual_incoming_args_rtx);
10726 else
10727 return virtual_incoming_args_rtx;
10728 }
10729
10730 /* Given FROM and TO register numbers, say whether this elimination is allowed.
10731 Frame pointer elimination is automatically handled. */
10732
10733 static bool
10734 pa_can_eliminate (const int from, const int to)
10735 {
10736 /* The argument cannot be eliminated in the 64-bit runtime. */
10737 if (TARGET_64BIT && from == ARG_POINTER_REGNUM)
10738 return false;
10739
10740 return (from == HARD_FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM
10741 ? ! frame_pointer_needed
10742 : true);
10743 }
10744
10745 /* Define the offset between two registers, FROM to be eliminated and its
10746 replacement TO, at the start of a routine. */
10747 HOST_WIDE_INT
10748 pa_initial_elimination_offset (int from, int to)
10749 {
10750 HOST_WIDE_INT offset;
10751
10752 if ((from == HARD_FRAME_POINTER_REGNUM || from == FRAME_POINTER_REGNUM)
10753 && to == STACK_POINTER_REGNUM)
10754 offset = -pa_compute_frame_size (get_frame_size (), 0);
10755 else if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
10756 offset = 0;
10757 else
10758 gcc_unreachable ();
10759
10760 return offset;
10761 }
10762
10763 static void
10764 pa_conditional_register_usage (void)
10765 {
10766 int i;
10767
10768 if (!TARGET_64BIT && !TARGET_PA_11)
10769 {
10770 for (i = 56; i <= FP_REG_LAST; i++)
10771 fixed_regs[i] = call_used_regs[i] = 1;
10772 for (i = 33; i < 56; i += 2)
10773 fixed_regs[i] = call_used_regs[i] = 1;
10774 }
10775 if (TARGET_SOFT_FLOAT)
10776 {
10777 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
10778 fixed_regs[i] = call_used_regs[i] = 1;
10779 }
10780 if (flag_pic)
10781 fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
10782 }
10783
10784 /* Target hook for c_mode_for_suffix. */
10785
10786 static machine_mode
10787 pa_c_mode_for_suffix (char suffix)
10788 {
10789 if (HPUX_LONG_DOUBLE_LIBRARY)
10790 {
10791 if (suffix == 'q')
10792 return TFmode;
10793 }
10794
10795 return VOIDmode;
10796 }
10797
10798 /* Implement TARGET_C_MODE_FOR_FLOATING_TYPE. Return TFmode or DFmode
10799 for TI_LONG_DOUBLE_TYPE which is for long double type, go with the
10800 default one for the others. */
10801
10802 static machine_mode
10803 pa_c_mode_for_floating_type (enum tree_index ti)
10804 {
10805 if (ti == TI_LONG_DOUBLE_TYPE)
10806 return PA_LONG_DOUBLE_TYPE_SIZE == 64 ? DFmode : TFmode;
10807 return default_mode_for_floating_type (ti);
10808 }
10809
10810 /* Target hook for function_section. */
10811
10812 static section *
10813 pa_function_section (tree decl, enum node_frequency freq,
10814 bool startup, bool exit)
10815 {
10816 /* Put functions in text section if target doesn't have named sections. */
10817 if (!targetm_common.have_named_sections)
10818 return text_section;
10819
10820 /* Force nested functions into the same section as the containing
10821 function. */
10822 if (decl
10823 && DECL_SECTION_NAME (decl) == NULL
10824 && DECL_CONTEXT (decl) != NULL_TREE
10825 && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL
10826 && DECL_SECTION_NAME (DECL_CONTEXT (decl)) == NULL)
10827 return function_section (DECL_CONTEXT (decl));
10828
10829 /* Otherwise, use the default function section. */
10830 return default_function_section (decl, freq, startup, exit);
10831 }
10832
10833 /* Implement TARGET_LEGITIMATE_CONSTANT_P.
10834
10835 In 64-bit mode, we reject CONST_DOUBLES. We also reject CONST_INTS
10836 that need more than three instructions to load prior to reload. This
10837 limit is somewhat arbitrary. It takes three instructions to load a
10838 CONST_INT from memory but two are memory accesses. It may be better
10839 to increase the allowed range for CONST_INTS. We may also be able
10840 to handle CONST_DOUBLES. */
10841
10842 static bool
10843 pa_legitimate_constant_p (machine_mode mode, rtx x)
10844 {
10845 if (GET_MODE_CLASS (mode) == MODE_FLOAT && x != CONST0_RTX (mode))
10846 return false;
10847
10848 if (!NEW_HP_ASSEMBLER && !TARGET_GAS && GET_CODE (x) == LABEL_REF)
10849 return false;
10850
10851 /* TLS_MODEL_GLOBAL_DYNAMIC and TLS_MODEL_LOCAL_DYNAMIC are not
10852 legitimate constants. The other variants can't be handled by
10853 the move patterns after reload starts. */
10854 if (tls_referenced_p (x))
10855 return false;
10856
10857 if (TARGET_64BIT && GET_CODE (x) == CONST_DOUBLE)
10858 return false;
10859
10860 if (TARGET_64BIT
10861 && HOST_BITS_PER_WIDE_INT > 32
10862 && GET_CODE (x) == CONST_INT
10863 && !lra_in_progress
10864 && !reload_in_progress
10865 && !reload_completed
10866 && !LEGITIMATE_64BIT_CONST_INT_P (INTVAL (x))
10867 && !pa_cint_ok_for_move (UINTVAL (x)))
10868 return false;
10869
10870 if (function_label_operand (x, mode))
10871 return false;
10872
10873 return true;
10874 }
10875
10876 /* pa_legitimate_address_p recognizes an RTL expression that is a
10877 valid memory address for an instruction. The MODE argument is the
10878 machine mode for the MEM expression that wants to use this address.
10879
10880 On HP PA-RISC, the legitimate address forms are REG+SMALLINT,
10881 REG+REG, and REG+(REG*SCALE). The indexed address forms are only
10882 available with floating point loads and stores, and integer loads.
10883 We get better code by allowing indexed addresses in the initial
10884 RTL generation.
10885
10886 The acceptance of indexed addresses as legitimate implies that we
10887 must provide patterns for doing indexed integer stores, or the move
10888 expanders must force the address of an indexed store to a register.
10889 We have adopted the latter approach.
10890
10891 Another function of pa_legitimate_address_p is to ensure that
10892 the base register is a valid pointer for indexed instructions.
10893 On targets that have non-equivalent space registers, we have to
10894 know at the time of assembler output which register in a REG+REG
10895 pair is the base register. The REG_POINTER flag is sometimes lost
10896 in reload and the following passes, so it can't be relied on during
10897 code generation. Thus, we either have to canonicalize the order
10898 of the registers in REG+REG indexed addresses, or treat REG+REG
10899 addresses separately and provide patterns for both permutations.
10900
10901 The latter approach requires several hundred additional lines of
10902 code in pa.md. The downside to canonicalizing is that a PLUS
10903 in the wrong order can't combine to form to make a scaled indexed
10904 memory operand. As we won't need to canonicalize the operands if
10905 the REG_POINTER lossage can be fixed, it seems better canonicalize.
10906
10907 We initially break out scaled indexed addresses in canonical order
10908 in pa_emit_move_sequence. LEGITIMIZE_ADDRESS also canonicalizes
10909 scaled indexed addresses during RTL generation. However, fold_rtx
10910 has its own opinion on how the operands of a PLUS should be ordered.
10911 If one of the operands is equivalent to a constant, it will make
10912 that operand the second operand. As the base register is likely to
10913 be equivalent to a SYMBOL_REF, we have made it the second operand.
10914
10915 pa_legitimate_address_p accepts REG+REG as legitimate when the
10916 operands are in the order INDEX+BASE on targets with non-equivalent
10917 space registers, and in any order on targets with equivalent space
10918 registers. It accepts both MULT+BASE and BASE+MULT for scaled indexing.
10919
10920 We treat a SYMBOL_REF as legitimate if it is part of the current
10921 function's constant-pool, because such addresses can actually be
10922 output as REG+SMALLINT. */
10923
10924 static bool
10925 pa_legitimate_address_p (machine_mode mode, rtx x, bool strict, code_helper)
10926 {
10927 if ((REG_P (x)
10928 && (strict ? STRICT_REG_OK_FOR_BASE_P (x)
10929 : REG_OK_FOR_BASE_P (x)))
10930 || ((GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_DEC
10931 || GET_CODE (x) == PRE_INC || GET_CODE (x) == POST_INC)
10932 && REG_P (XEXP (x, 0))
10933 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 0))
10934 : REG_OK_FOR_BASE_P (XEXP (x, 0)))))
10935 return true;
10936
10937 if (GET_CODE (x) == PLUS)
10938 {
10939 rtx base, index;
10940
10941 /* For REG+REG, the base register should be in XEXP (x, 1),
10942 so check it first. */
10943 if (REG_P (XEXP (x, 1))
10944 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 1))
10945 : REG_OK_FOR_BASE_P (XEXP (x, 1))))
10946 base = XEXP (x, 1), index = XEXP (x, 0);
10947 else if (REG_P (XEXP (x, 0))
10948 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 0))
10949 : REG_OK_FOR_BASE_P (XEXP (x, 0))))
10950 base = XEXP (x, 0), index = XEXP (x, 1);
10951 else
10952 return false;
10953
10954 if (GET_CODE (index) == CONST_INT)
10955 {
10956 /* Short 5-bit displacements always okay. */
10957 if (INT_5_BITS (index))
10958 return true;
10959
10960 if (!base14_operand (index, mode))
10961 return false;
10962
10963 /* Long 14-bit displacements always okay for these cases. */
10964 if (INT14_OK_STRICT
10965 || reload_completed
10966 || (reload_in_progress && !strict)
10967 || mode == QImode
10968 || mode == HImode)
10969 return true;
10970
10971 /* We have to limit displacements to those supported by
10972 both floating-point and integer accesses as reload can't
10973 fix invalid displacements. See PR114288. */
10974 return false;
10975 }
10976
10977 if (!TARGET_DISABLE_INDEXING
10978 /* Currently, the REG_POINTER flag is not set in a variety
10979 of situations (e.g., call arguments and pointer arithmetic).
10980 As a result, we can't reliably determine when unscaled
10981 addresses are legitimate on targets that need space register
10982 selection. */
10983 && TARGET_NO_SPACE_REGS
10984 && REG_P (index)
10985 && MODE_OK_FOR_UNSCALED_INDEXING_P (mode)
10986 && (strict ? STRICT_REG_OK_FOR_INDEX_P (index)
10987 : REG_OK_FOR_INDEX_P (index))
10988 && borx_reg_operand (base, Pmode)
10989 && borx_reg_operand (index, Pmode))
10990 return true;
10991
10992 if (!TARGET_DISABLE_INDEXING
10993 /* Only accept base operands with the REG_POINTER flag prior to
10994 reload on targets with non-equivalent space registers. */
10995 && (TARGET_NO_SPACE_REGS
10996 || reload_completed
10997 || ((lra_in_progress || reload_in_progress)
10998 && HARD_REGISTER_P (base))
10999 || REG_POINTER (base))
11000 && GET_CODE (index) == MULT
11001 && REG_P (XEXP (index, 0))
11002 && GET_MODE (XEXP (index, 0)) == Pmode
11003 && MODE_OK_FOR_SCALED_INDEXING_P (mode)
11004 && (strict ? STRICT_REG_OK_FOR_INDEX_P (XEXP (index, 0))
11005 : REG_OK_FOR_INDEX_P (XEXP (index, 0)))
11006 && GET_CODE (XEXP (index, 1)) == CONST_INT
11007 && INTVAL (XEXP (index, 1))
11008 == (HOST_WIDE_INT) GET_MODE_SIZE (mode)
11009 && borx_reg_operand (base, Pmode))
11010 return true;
11011
11012 return false;
11013 }
11014
11015 if (GET_CODE (x) == LO_SUM)
11016 {
11017 rtx y = XEXP (x, 0);
11018
11019 if (GET_CODE (y) == SUBREG)
11020 y = SUBREG_REG (y);
11021
11022 if (REG_P (y)
11023 && (strict ? STRICT_REG_OK_FOR_BASE_P (y)
11024 : REG_OK_FOR_BASE_P (y)))
11025 {
11026 y = XEXP (x, 1);
11027
11028 /* UNSPEC_DLTIND14R is always okay. Needed for -fPIC */
11029 if (mode == Pmode
11030 && GET_CODE (y) == UNSPEC)
11031 return true;
11032
11033 /* Before reload, we need support for 14-bit floating
11034 point loads and stores, and associated relocations. */
11035 if (!INT14_OK_STRICT
11036 && !reload_completed
11037 && mode != QImode
11038 && mode != HImode)
11039 return false;
11040
11041 if (CONSTANT_P (y)
11042 || (!flag_pic && symbolic_operand (y, mode)))
11043 return true;
11044 }
11045 return false;
11046 }
11047
11048 if (GET_CODE (x) == CONST_INT && INT_5_BITS (x))
11049 return true;
11050
11051 return false;
11052 }
11053
11054 /* Look for machine dependent ways to make the invalid address AD a
11055 valid address.
11056
11057 For the PA, transform:
11058
11059 memory(X + <large int>)
11060
11061 into:
11062
11063 if (<large int> & mask) >= 16
11064 Y = (<large int> & ~mask) + mask + 1 Round up.
11065 else
11066 Y = (<large int> & ~mask) Round down.
11067 Z = X + Y
11068 memory (Z + (<large int> - Y));
11069
11070 This makes reload inheritance and reload_cse work better since Z
11071 can be reused.
11072
11073 There may be more opportunities to improve code with this hook. */
11074
11075 rtx
11076 pa_legitimize_reload_address (rtx ad, machine_mode mode,
11077 int opnum, int type,
11078 int ind_levels ATTRIBUTE_UNUSED)
11079 {
11080 long offset, newoffset, mask;
11081 rtx new_rtx, temp = NULL_RTX;
11082
11083 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
11084 && !INT14_OK_STRICT ? 0x1f : 0x3fff);
11085
11086 if (optimize && GET_CODE (ad) == PLUS)
11087 temp = simplify_binary_operation (PLUS, Pmode,
11088 XEXP (ad, 0), XEXP (ad, 1));
11089
11090 new_rtx = temp ? temp : ad;
11091
11092 if (optimize
11093 && GET_CODE (new_rtx) == PLUS
11094 && GET_CODE (XEXP (new_rtx, 0)) == REG
11095 && GET_CODE (XEXP (new_rtx, 1)) == CONST_INT)
11096 {
11097 offset = INTVAL (XEXP ((new_rtx), 1));
11098
11099 /* Choose rounding direction. Round up if we are >= halfway. */
11100 if ((offset & mask) >= ((mask + 1) / 2))
11101 newoffset = (offset & ~mask) + mask + 1;
11102 else
11103 newoffset = offset & ~mask;
11104
11105 /* Ensure that long displacements are aligned. */
11106 if (mask == 0x3fff
11107 && (GET_MODE_CLASS (mode) == MODE_FLOAT
11108 || (TARGET_64BIT && (mode) == DImode)))
11109 newoffset &= ~(GET_MODE_SIZE (mode) - 1);
11110
11111 if (newoffset != 0 && VAL_14_BITS_P (newoffset))
11112 {
11113 temp = gen_rtx_PLUS (Pmode, XEXP (new_rtx, 0),
11114 GEN_INT (newoffset));
11115 ad = gen_rtx_PLUS (Pmode, temp, GEN_INT (offset - newoffset));
11116 push_reload (XEXP (ad, 0), 0, &XEXP (ad, 0), 0,
11117 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
11118 opnum, (enum reload_type) type);
11119 return ad;
11120 }
11121 }
11122
11123 return NULL_RTX;
11124 }
11125
11126 /* Output address vector. */
11127
11128 void
11129 pa_output_addr_vec (rtx lab, rtx body)
11130 {
11131 int idx, vlen = XVECLEN (body, 0);
11132
11133 if (!TARGET_SOM)
11134 fputs ("\t.align 4\n", asm_out_file);
11135 targetm.asm_out.internal_label (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
11136 if (TARGET_GAS)
11137 fputs ("\t.begin_brtab\n", asm_out_file);
11138 for (idx = 0; idx < vlen; idx++)
11139 {
11140 ASM_OUTPUT_ADDR_VEC_ELT
11141 (asm_out_file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
11142 }
11143 if (TARGET_GAS)
11144 fputs ("\t.end_brtab\n", asm_out_file);
11145 }
11146
11147 /* Output address difference vector. */
11148
11149 void
11150 pa_output_addr_diff_vec (rtx lab, rtx body)
11151 {
11152 rtx base = XEXP (XEXP (body, 0), 0);
11153 int idx, vlen = XVECLEN (body, 1);
11154
11155 targetm.asm_out.internal_label (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
11156 if (TARGET_GAS)
11157 fputs ("\t.begin_brtab\n", asm_out_file);
11158 for (idx = 0; idx < vlen; idx++)
11159 {
11160 ASM_OUTPUT_ADDR_DIFF_ELT
11161 (asm_out_file,
11162 body,
11163 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
11164 CODE_LABEL_NUMBER (base));
11165 }
11166 if (TARGET_GAS)
11167 fputs ("\t.end_brtab\n", asm_out_file);
11168 }
11169
11170 /* Implement TARGET_CALLEE_COPIES. The callee is responsible for copying
11171 arguments passed by hidden reference in the 32-bit HP runtime. Users
11172 can override this behavior for better compatibility with openmp at the
11173 risk of library incompatibilities. Arguments are always passed by value
11174 in the 64-bit HP runtime. */
11175
11176 static bool
11177 pa_callee_copies (cumulative_args_t, const function_arg_info &)
11178 {
11179 return !TARGET_CALLER_COPIES;
11180 }
11181
11182 /* Implement TARGET_HARD_REGNO_NREGS. */
11183
11184 static unsigned int
11185 pa_hard_regno_nregs (unsigned int regno ATTRIBUTE_UNUSED, machine_mode mode)
11186 {
11187 return PA_HARD_REGNO_NREGS (regno, mode);
11188 }
11189
11190 /* Implement TARGET_HARD_REGNO_MODE_OK. */
11191
11192 static bool
11193 pa_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
11194 {
11195 return PA_HARD_REGNO_MODE_OK (regno, mode);
11196 }
11197
11198 /* Implement TARGET_STARTING_FRAME_OFFSET.
11199
11200 On the 32-bit ports, we reserve one slot for the previous frame
11201 pointer and one fill slot. The fill slot is for compatibility
11202 with HP compiled programs. On the 64-bit ports, we reserve one
11203 slot for the previous frame pointer. */
11204
11205 static HOST_WIDE_INT
11206 pa_starting_frame_offset (void)
11207 {
11208 return 8;
11209 }
11210
11211 /* Figure out the size in words of the function argument. */
11212
11213 int
11214 pa_function_arg_size (machine_mode mode, const_tree type)
11215 {
11216 HOST_WIDE_INT size;
11217
11218 size = mode != BLKmode ? GET_MODE_SIZE (mode) : int_size_in_bytes (type);
11219
11220 /* The 64-bit runtime does not restrict the size of stack frames,
11221 but the gcc calling conventions limit argument sizes to 1G. Our
11222 prologue/epilogue code limits frame sizes to just under 32 bits.
11223 1G is also the maximum frame size that can be handled by the HPUX
11224 unwind descriptor. Since very large TYPE_SIZE_UNIT values can
11225 occur for (parallel:BLK []), we need to ignore large arguments
11226 passed by value. */
11227 if (size >= (1 << (HOST_BITS_PER_INT - 2)))
11228 size = 0;
11229 return (int) CEIL (size, UNITS_PER_WORD);
11230 }
11231
11232 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV. */
11233
11234 static void
11235 pa_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
11236 {
11237 const unsigned PA_FE_INEXACT = 1;
11238 const unsigned PA_FE_UNDERFLOW = 2;
11239 const unsigned PA_FE_OVERFLOW = 4;
11240 const unsigned PA_FE_DIVBYZERO = 8;
11241 const unsigned PA_FE_INVALID = 16;
11242 const unsigned HOST_WIDE_INT PA_FE_ALL_EXCEPT = (PA_FE_INVALID
11243 | PA_FE_DIVBYZERO
11244 | PA_FE_OVERFLOW
11245 | PA_FE_UNDERFLOW
11246 | PA_FE_INEXACT);
11247 const unsigned HOST_WIDE_INT PA_FE_EXCEPT_SHIFT = 27;
11248 tree fenv_var, get_fpsr, set_fpsr, mask, ld_fenv, masked_fenv;
11249 tree hold_all, new_fenv_var, reload_fenv, restore_fnenv;
11250 tree get_fpsr_call, set_fpsr_call, update_call, atomic_feraiseexcept;
11251
11252 if (TARGET_SOFT_FLOAT)
11253 return;
11254
11255 /* Generate the equivalent of :
11256 unsigned int fenv_var;
11257 fenv_var = __builtin_get_fpsr ();
11258
11259 unsigned int masked_fenv;
11260 masked_fenv = fenv_var & mask;
11261
11262 __builtin_set_fpsr (masked_fenv); */
11263
11264 fenv_var = create_tmp_var_raw (unsigned_type_node);
11265 get_fpsr = pa_builtins[PA_BUILTIN_GET_FPSR];
11266 set_fpsr = pa_builtins[PA_BUILTIN_SET_FPSR];
11267 mask = build_int_cst (unsigned_type_node,
11268 ~((PA_FE_ALL_EXCEPT << PA_FE_EXCEPT_SHIFT)
11269 | PA_FE_ALL_EXCEPT));
11270
11271 get_fpsr_call = build_call_expr (get_fpsr, 0);
11272 ld_fenv = build4 (TARGET_EXPR, unsigned_type_node,
11273 fenv_var, get_fpsr_call,
11274 NULL_TREE, NULL_TREE);
11275 masked_fenv = build2 (BIT_AND_EXPR, unsigned_type_node, fenv_var, mask);
11276 hold_all = build2 (COMPOUND_EXPR, void_type_node, masked_fenv, ld_fenv);
11277 set_fpsr_call = build_call_expr (set_fpsr, 1, masked_fenv);
11278 *hold = build2 (COMPOUND_EXPR, void_type_node, hold_all, set_fpsr_call);
11279
11280 /* Store the value of masked_fenv to clear the exceptions:
11281 __builtin_set_fpsr (masked_fenv); */
11282
11283 *clear = set_fpsr_call;
11284
11285 /* Generate the equivalent of :
11286 unsigned int new_fenv_var;
11287 new_fenv_var = __builtin_get_fpsr ();
11288
11289 __builtin_set_fpsr (fenv_var);
11290
11291 __atomic_feraiseexcept (new_fenv_var); */
11292
11293 new_fenv_var = create_tmp_var_raw (unsigned_type_node);
11294 reload_fenv = build4 (TARGET_EXPR, unsigned_type_node, new_fenv_var,
11295 get_fpsr_call, NULL_TREE, NULL_TREE);
11296 restore_fnenv = build_call_expr (set_fpsr, 1, fenv_var);
11297 atomic_feraiseexcept = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
11298 update_call = build_call_expr (atomic_feraiseexcept, 1,
11299 fold_convert (integer_type_node,
11300 new_fenv_var));
11301 *update = build2 (COMPOUND_EXPR, void_type_node,
11302 build2 (COMPOUND_EXPR, void_type_node,
11303 reload_fenv, restore_fnenv), update_call);
11304 }
11305
11306 /* Implement TARGET_LRA_P. */
11307
11308 static bool
11309 pa_use_lra_p ()
11310 {
11311 return pa_lra_p;
11312 }
11313
11314 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
11315
11316 bool
11317 pa_frame_pointer_required (void)
11318 {
11319 /* If the function receives nonlocal gotos, it needs to save the frame
11320 pointer in the argument save area. */
11321 if (cfun->has_nonlocal_label)
11322 return true;
11323
11324 return false;
11325 }
11326
11327 #include "gt-pa.h"