Merge from mainline (163495:164578).
[official-gcc/graphite-test-results.git] / gcc / config / pa / pa.c
blob754d27adc06184de1eb65e4c2d702bcd1de595cf
1 /* Subroutines for insn-output.c for HPPA.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "tree.h"
35 #include "output.h"
36 #include "except.h"
37 #include "expr.h"
38 #include "optabs.h"
39 #include "reload.h"
40 #include "integrate.h"
41 #include "function.h"
42 #include "diagnostic-core.h"
43 #include "toplev.h"
44 #include "ggc.h"
45 #include "recog.h"
46 #include "predict.h"
47 #include "tm_p.h"
48 #include "target.h"
49 #include "target-def.h"
50 #include "df.h"
52 /* Return nonzero if there is a bypass for the output of
53 OUT_INSN and the fp store IN_INSN. */
54 int
55 hppa_fpstore_bypass_p (rtx out_insn, rtx in_insn)
57 enum machine_mode store_mode;
58 enum machine_mode other_mode;
59 rtx set;
61 if (recog_memoized (in_insn) < 0
62 || (get_attr_type (in_insn) != TYPE_FPSTORE
63 && get_attr_type (in_insn) != TYPE_FPSTORE_LOAD)
64 || recog_memoized (out_insn) < 0)
65 return 0;
67 store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
69 set = single_set (out_insn);
70 if (!set)
71 return 0;
73 other_mode = GET_MODE (SET_SRC (set));
75 return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
79 #ifndef DO_FRAME_NOTES
80 #ifdef INCOMING_RETURN_ADDR_RTX
81 #define DO_FRAME_NOTES 1
82 #else
83 #define DO_FRAME_NOTES 0
84 #endif
85 #endif
87 static void pa_option_override (void);
88 static void copy_reg_pointer (rtx, rtx);
89 static void fix_range (const char *);
90 static bool pa_handle_option (size_t, const char *, int);
91 static int hppa_register_move_cost (enum machine_mode mode, reg_class_t,
92 reg_class_t);
93 static int hppa_address_cost (rtx, bool);
94 static bool hppa_rtx_costs (rtx, int, int, int *, bool);
95 static inline rtx force_mode (enum machine_mode, rtx);
96 static void pa_reorg (void);
97 static void pa_combine_instructions (void);
98 static int pa_can_combine_p (rtx, rtx, rtx, int, rtx, rtx, rtx);
99 static bool forward_branch_p (rtx);
100 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
101 static int compute_movmem_length (rtx);
102 static int compute_clrmem_length (rtx);
103 static bool pa_assemble_integer (rtx, unsigned int, int);
104 static void remove_useless_addtr_insns (int);
105 static void store_reg (int, HOST_WIDE_INT, int);
106 static void store_reg_modify (int, int, HOST_WIDE_INT);
107 static void load_reg (int, HOST_WIDE_INT, int);
108 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
109 static rtx pa_function_value (const_tree, const_tree, bool);
110 static rtx pa_libcall_value (enum machine_mode, const_rtx);
111 static bool pa_function_value_regno_p (const unsigned int);
112 static void pa_output_function_prologue (FILE *, HOST_WIDE_INT);
113 static void update_total_code_bytes (unsigned int);
114 static void pa_output_function_epilogue (FILE *, HOST_WIDE_INT);
115 static int pa_adjust_cost (rtx, rtx, rtx, int);
116 static int pa_adjust_priority (rtx, int);
117 static int pa_issue_rate (void);
118 static void pa_som_asm_init_sections (void) ATTRIBUTE_UNUSED;
119 static section *pa_select_section (tree, int, unsigned HOST_WIDE_INT)
120 ATTRIBUTE_UNUSED;
121 static void pa_encode_section_info (tree, rtx, int);
122 static const char *pa_strip_name_encoding (const char *);
123 static bool pa_function_ok_for_sibcall (tree, tree);
124 static void pa_globalize_label (FILE *, const char *)
125 ATTRIBUTE_UNUSED;
126 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
127 HOST_WIDE_INT, tree);
128 #if !defined(USE_COLLECT2)
129 static void pa_asm_out_constructor (rtx, int);
130 static void pa_asm_out_destructor (rtx, int);
131 #endif
132 static void pa_init_builtins (void);
133 static rtx hppa_builtin_saveregs (void);
134 static void hppa_va_start (tree, rtx);
135 static tree hppa_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
136 static bool pa_scalar_mode_supported_p (enum machine_mode);
137 static bool pa_commutative_p (const_rtx x, int outer_code);
138 static void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
139 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
140 static rtx hppa_legitimize_address (rtx, rtx, enum machine_mode);
141 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
142 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
143 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
144 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
145 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
146 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
147 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
148 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
149 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
150 static void output_deferred_plabels (void);
151 static void output_deferred_profile_counters (void) ATTRIBUTE_UNUSED;
152 #ifdef ASM_OUTPUT_EXTERNAL_REAL
153 static void pa_hpux_file_end (void);
154 #endif
155 #ifdef HPUX_LONG_DOUBLE_LIBRARY
156 static void pa_hpux_init_libfuncs (void);
157 #endif
158 static rtx pa_struct_value_rtx (tree, int);
159 static bool pa_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
160 const_tree, bool);
161 static int pa_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
162 tree, bool);
163 static struct machine_function * pa_init_machine_status (void);
164 static reg_class_t pa_secondary_reload (bool, rtx, reg_class_t,
165 enum machine_mode,
166 secondary_reload_info *);
167 static void pa_extra_live_on_entry (bitmap);
168 static enum machine_mode pa_promote_function_mode (const_tree,
169 enum machine_mode, int *,
170 const_tree, int);
172 static void pa_asm_trampoline_template (FILE *);
173 static void pa_trampoline_init (rtx, tree, rtx);
174 static rtx pa_trampoline_adjust_address (rtx);
175 static rtx pa_delegitimize_address (rtx);
176 static bool pa_print_operand_punct_valid_p (unsigned char);
177 static rtx pa_internal_arg_pointer (void);
178 static bool pa_can_eliminate (const int, const int);
180 /* The following extra sections are only used for SOM. */
181 static GTY(()) section *som_readonly_data_section;
182 static GTY(()) section *som_one_only_readonly_data_section;
183 static GTY(()) section *som_one_only_data_section;
185 /* Which cpu we are scheduling for. */
186 enum processor_type pa_cpu = TARGET_SCHED_DEFAULT;
188 /* The UNIX standard to use for predefines and linking. */
189 int flag_pa_unix = TARGET_HPUX_11_11 ? 1998 : TARGET_HPUX_10_10 ? 1995 : 1993;
191 /* Counts for the number of callee-saved general and floating point
192 registers which were saved by the current function's prologue. */
193 static int gr_saved, fr_saved;
195 /* Boolean indicating whether the return pointer was saved by the
196 current function's prologue. */
197 static bool rp_saved;
199 static rtx find_addr_reg (rtx);
201 /* Keep track of the number of bytes we have output in the CODE subspace
202 during this compilation so we'll know when to emit inline long-calls. */
203 unsigned long total_code_bytes;
205 /* The last address of the previous function plus the number of bytes in
206 associated thunks that have been output. This is used to determine if
207 a thunk can use an IA-relative branch to reach its target function. */
208 static unsigned int last_address;
210 /* Variables to handle plabels that we discover are necessary at assembly
211 output time. They are output after the current function. */
212 struct GTY(()) deferred_plabel
214 rtx internal_label;
215 rtx symbol;
217 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
218 deferred_plabels;
219 static size_t n_deferred_plabels = 0;
222 /* Initialize the GCC target structure. */
224 #undef TARGET_OPTION_OVERRIDE
225 #define TARGET_OPTION_OVERRIDE pa_option_override
227 #undef TARGET_ASM_ALIGNED_HI_OP
228 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
229 #undef TARGET_ASM_ALIGNED_SI_OP
230 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
231 #undef TARGET_ASM_ALIGNED_DI_OP
232 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
233 #undef TARGET_ASM_UNALIGNED_HI_OP
234 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
235 #undef TARGET_ASM_UNALIGNED_SI_OP
236 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
237 #undef TARGET_ASM_UNALIGNED_DI_OP
238 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
239 #undef TARGET_ASM_INTEGER
240 #define TARGET_ASM_INTEGER pa_assemble_integer
242 #undef TARGET_ASM_FUNCTION_PROLOGUE
243 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
244 #undef TARGET_ASM_FUNCTION_EPILOGUE
245 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
247 #undef TARGET_FUNCTION_VALUE
248 #define TARGET_FUNCTION_VALUE pa_function_value
249 #undef TARGET_LIBCALL_VALUE
250 #define TARGET_LIBCALL_VALUE pa_libcall_value
251 #undef TARGET_FUNCTION_VALUE_REGNO_P
252 #define TARGET_FUNCTION_VALUE_REGNO_P pa_function_value_regno_p
254 #undef TARGET_LEGITIMIZE_ADDRESS
255 #define TARGET_LEGITIMIZE_ADDRESS hppa_legitimize_address
257 #undef TARGET_SCHED_ADJUST_COST
258 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
259 #undef TARGET_SCHED_ADJUST_PRIORITY
260 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
261 #undef TARGET_SCHED_ISSUE_RATE
262 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
264 #undef TARGET_ENCODE_SECTION_INFO
265 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
266 #undef TARGET_STRIP_NAME_ENCODING
267 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
269 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
270 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
272 #undef TARGET_COMMUTATIVE_P
273 #define TARGET_COMMUTATIVE_P pa_commutative_p
275 #undef TARGET_ASM_OUTPUT_MI_THUNK
276 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
277 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
278 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
280 #undef TARGET_ASM_FILE_END
281 #ifdef ASM_OUTPUT_EXTERNAL_REAL
282 #define TARGET_ASM_FILE_END pa_hpux_file_end
283 #else
284 #define TARGET_ASM_FILE_END output_deferred_plabels
285 #endif
287 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
288 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P pa_print_operand_punct_valid_p
290 #if !defined(USE_COLLECT2)
291 #undef TARGET_ASM_CONSTRUCTOR
292 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
293 #undef TARGET_ASM_DESTRUCTOR
294 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
295 #endif
297 #undef TARGET_DEFAULT_TARGET_FLAGS
298 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | TARGET_CPU_DEFAULT)
299 #undef TARGET_HANDLE_OPTION
300 #define TARGET_HANDLE_OPTION pa_handle_option
302 #undef TARGET_INIT_BUILTINS
303 #define TARGET_INIT_BUILTINS pa_init_builtins
305 #undef TARGET_REGISTER_MOVE_COST
306 #define TARGET_REGISTER_MOVE_COST hppa_register_move_cost
307 #undef TARGET_RTX_COSTS
308 #define TARGET_RTX_COSTS hppa_rtx_costs
309 #undef TARGET_ADDRESS_COST
310 #define TARGET_ADDRESS_COST hppa_address_cost
312 #undef TARGET_MACHINE_DEPENDENT_REORG
313 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
315 #ifdef HPUX_LONG_DOUBLE_LIBRARY
316 #undef TARGET_INIT_LIBFUNCS
317 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
318 #endif
320 #undef TARGET_PROMOTE_FUNCTION_MODE
321 #define TARGET_PROMOTE_FUNCTION_MODE pa_promote_function_mode
322 #undef TARGET_PROMOTE_PROTOTYPES
323 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
325 #undef TARGET_STRUCT_VALUE_RTX
326 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
327 #undef TARGET_RETURN_IN_MEMORY
328 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
329 #undef TARGET_MUST_PASS_IN_STACK
330 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
331 #undef TARGET_PASS_BY_REFERENCE
332 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
333 #undef TARGET_CALLEE_COPIES
334 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
335 #undef TARGET_ARG_PARTIAL_BYTES
336 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
338 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
339 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
340 #undef TARGET_EXPAND_BUILTIN_VA_START
341 #define TARGET_EXPAND_BUILTIN_VA_START hppa_va_start
342 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
343 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
345 #undef TARGET_SCALAR_MODE_SUPPORTED_P
346 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
348 #undef TARGET_CANNOT_FORCE_CONST_MEM
349 #define TARGET_CANNOT_FORCE_CONST_MEM pa_tls_referenced_p
351 #undef TARGET_SECONDARY_RELOAD
352 #define TARGET_SECONDARY_RELOAD pa_secondary_reload
354 #undef TARGET_EXTRA_LIVE_ON_ENTRY
355 #define TARGET_EXTRA_LIVE_ON_ENTRY pa_extra_live_on_entry
357 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
358 #define TARGET_ASM_TRAMPOLINE_TEMPLATE pa_asm_trampoline_template
359 #undef TARGET_TRAMPOLINE_INIT
360 #define TARGET_TRAMPOLINE_INIT pa_trampoline_init
361 #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
362 #define TARGET_TRAMPOLINE_ADJUST_ADDRESS pa_trampoline_adjust_address
363 #undef TARGET_DELEGITIMIZE_ADDRESS
364 #define TARGET_DELEGITIMIZE_ADDRESS pa_delegitimize_address
365 #undef TARGET_INTERNAL_ARG_POINTER
366 #define TARGET_INTERNAL_ARG_POINTER pa_internal_arg_pointer
367 #undef TARGET_CAN_ELIMINATE
368 #define TARGET_CAN_ELIMINATE pa_can_eliminate
370 struct gcc_target targetm = TARGET_INITIALIZER;
372 /* Parse the -mfixed-range= option string. */
374 static void
375 fix_range (const char *const_str)
377 int i, first, last;
378 char *str, *dash, *comma;
380 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
381 REG2 are either register names or register numbers. The effect
382 of this option is to mark the registers in the range from REG1 to
383 REG2 as ``fixed'' so they won't be used by the compiler. This is
384 used, e.g., to ensure that kernel mode code doesn't use fr4-fr31. */
386 i = strlen (const_str);
387 str = (char *) alloca (i + 1);
388 memcpy (str, const_str, i + 1);
390 while (1)
392 dash = strchr (str, '-');
393 if (!dash)
395 warning (0, "value of -mfixed-range must have form REG1-REG2");
396 return;
398 *dash = '\0';
400 comma = strchr (dash + 1, ',');
401 if (comma)
402 *comma = '\0';
404 first = decode_reg_name (str);
405 if (first < 0)
407 warning (0, "unknown register name: %s", str);
408 return;
411 last = decode_reg_name (dash + 1);
412 if (last < 0)
414 warning (0, "unknown register name: %s", dash + 1);
415 return;
418 *dash = '-';
420 if (first > last)
422 warning (0, "%s-%s is an empty range", str, dash + 1);
423 return;
426 for (i = first; i <= last; ++i)
427 fixed_regs[i] = call_used_regs[i] = 1;
429 if (!comma)
430 break;
432 *comma = ',';
433 str = comma + 1;
436 /* Check if all floating point registers have been fixed. */
437 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
438 if (!fixed_regs[i])
439 break;
441 if (i > FP_REG_LAST)
442 target_flags |= MASK_DISABLE_FPREGS;
445 /* Implement TARGET_HANDLE_OPTION. */
447 static bool
448 pa_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
450 switch (code)
452 case OPT_mnosnake:
453 case OPT_mpa_risc_1_0:
454 case OPT_march_1_0:
455 target_flags &= ~(MASK_PA_11 | MASK_PA_20);
456 return true;
458 case OPT_msnake:
459 case OPT_mpa_risc_1_1:
460 case OPT_march_1_1:
461 target_flags &= ~MASK_PA_20;
462 target_flags |= MASK_PA_11;
463 return true;
465 case OPT_mpa_risc_2_0:
466 case OPT_march_2_0:
467 target_flags |= MASK_PA_11 | MASK_PA_20;
468 return true;
470 case OPT_mschedule_:
471 if (strcmp (arg, "8000") == 0)
472 pa_cpu = PROCESSOR_8000;
473 else if (strcmp (arg, "7100") == 0)
474 pa_cpu = PROCESSOR_7100;
475 else if (strcmp (arg, "700") == 0)
476 pa_cpu = PROCESSOR_700;
477 else if (strcmp (arg, "7100LC") == 0)
478 pa_cpu = PROCESSOR_7100LC;
479 else if (strcmp (arg, "7200") == 0)
480 pa_cpu = PROCESSOR_7200;
481 else if (strcmp (arg, "7300") == 0)
482 pa_cpu = PROCESSOR_7300;
483 else
484 return false;
485 return true;
487 case OPT_mfixed_range_:
488 fix_range (arg);
489 return true;
491 #if TARGET_HPUX
492 case OPT_munix_93:
493 flag_pa_unix = 1993;
494 return true;
495 #endif
497 #if TARGET_HPUX_10_10
498 case OPT_munix_95:
499 flag_pa_unix = 1995;
500 return true;
501 #endif
503 #if TARGET_HPUX_11_11
504 case OPT_munix_98:
505 flag_pa_unix = 1998;
506 return true;
507 #endif
509 default:
510 return true;
514 /* Implement the TARGET_OPTION_OVERRIDE hook. */
516 static void
517 pa_option_override (void)
519 /* Unconditional branches in the delay slot are not compatible with dwarf2
520 call frame information. There is no benefit in using this optimization
521 on PA8000 and later processors. */
522 if (pa_cpu >= PROCESSOR_8000
523 || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
524 || flag_unwind_tables)
525 target_flags &= ~MASK_JUMP_IN_DELAY;
527 if (flag_pic && TARGET_PORTABLE_RUNTIME)
529 warning (0, "PIC code generation is not supported in the portable runtime model");
532 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
534 warning (0, "PIC code generation is not compatible with fast indirect calls");
537 if (! TARGET_GAS && write_symbols != NO_DEBUG)
539 warning (0, "-g is only supported when using GAS on this processor,");
540 warning (0, "-g option disabled");
541 write_symbols = NO_DEBUG;
544 /* We only support the "big PIC" model now. And we always generate PIC
545 code when in 64bit mode. */
546 if (flag_pic == 1 || TARGET_64BIT)
547 flag_pic = 2;
549 /* Disable -freorder-blocks-and-partition as we don't support hot and
550 cold partitioning. */
551 if (flag_reorder_blocks_and_partition)
553 inform (input_location,
554 "-freorder-blocks-and-partition does not work "
555 "on this architecture");
556 flag_reorder_blocks_and_partition = 0;
557 flag_reorder_blocks = 1;
560 /* We can't guarantee that .dword is available for 32-bit targets. */
561 if (UNITS_PER_WORD == 4)
562 targetm.asm_out.aligned_op.di = NULL;
564 /* The unaligned ops are only available when using GAS. */
565 if (!TARGET_GAS)
567 targetm.asm_out.unaligned_op.hi = NULL;
568 targetm.asm_out.unaligned_op.si = NULL;
569 targetm.asm_out.unaligned_op.di = NULL;
572 init_machine_status = pa_init_machine_status;
575 static void
576 pa_init_builtins (void)
578 #ifdef DONT_HAVE_FPUTC_UNLOCKED
579 built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] =
580 built_in_decls[(int) BUILT_IN_PUTC_UNLOCKED];
581 implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED]
582 = implicit_built_in_decls[(int) BUILT_IN_PUTC_UNLOCKED];
583 #endif
584 #if TARGET_HPUX_11
585 if (built_in_decls [BUILT_IN_FINITE])
586 set_user_assembler_name (built_in_decls [BUILT_IN_FINITE], "_Isfinite");
587 if (built_in_decls [BUILT_IN_FINITEF])
588 set_user_assembler_name (built_in_decls [BUILT_IN_FINITEF], "_Isfinitef");
589 #endif
592 /* Function to init struct machine_function.
593 This will be called, via a pointer variable,
594 from push_function_context. */
596 static struct machine_function *
597 pa_init_machine_status (void)
599 return ggc_alloc_cleared_machine_function ();
602 /* If FROM is a probable pointer register, mark TO as a probable
603 pointer register with the same pointer alignment as FROM. */
605 static void
606 copy_reg_pointer (rtx to, rtx from)
608 if (REG_POINTER (from))
609 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
612 /* Return 1 if X contains a symbolic expression. We know these
613 expressions will have one of a few well defined forms, so
614 we need only check those forms. */
616 symbolic_expression_p (rtx x)
619 /* Strip off any HIGH. */
620 if (GET_CODE (x) == HIGH)
621 x = XEXP (x, 0);
623 return (symbolic_operand (x, VOIDmode));
626 /* Accept any constant that can be moved in one instruction into a
627 general register. */
629 cint_ok_for_move (HOST_WIDE_INT ival)
631 /* OK if ldo, ldil, or zdepi, can be used. */
632 return (VAL_14_BITS_P (ival)
633 || ldil_cint_p (ival)
634 || zdepi_cint_p (ival));
637 /* Return truth value of whether OP can be used as an operand in a
638 adddi3 insn. */
640 adddi3_operand (rtx op, enum machine_mode mode)
642 return (register_operand (op, mode)
643 || (GET_CODE (op) == CONST_INT
644 && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
647 /* True iff the operand OP can be used as the destination operand of
648 an integer store. This also implies the operand could be used as
649 the source operand of an integer load. Symbolic, lo_sum and indexed
650 memory operands are not allowed. We accept reloading pseudos and
651 other memory operands. */
653 integer_store_memory_operand (rtx op, enum machine_mode mode)
655 return ((reload_in_progress
656 && REG_P (op)
657 && REGNO (op) >= FIRST_PSEUDO_REGISTER
658 && reg_renumber [REGNO (op)] < 0)
659 || (GET_CODE (op) == MEM
660 && (reload_in_progress || memory_address_p (mode, XEXP (op, 0)))
661 && !symbolic_memory_operand (op, VOIDmode)
662 && !IS_LO_SUM_DLT_ADDR_P (XEXP (op, 0))
663 && !IS_INDEX_ADDR_P (XEXP (op, 0))));
666 /* True iff ldil can be used to load this CONST_INT. The least
667 significant 11 bits of the value must be zero and the value must
668 not change sign when extended from 32 to 64 bits. */
670 ldil_cint_p (HOST_WIDE_INT ival)
672 HOST_WIDE_INT x = ival & (((HOST_WIDE_INT) -1 << 31) | 0x7ff);
674 return x == 0 || x == ((HOST_WIDE_INT) -1 << 31);
677 /* True iff zdepi can be used to generate this CONST_INT.
678 zdepi first sign extends a 5-bit signed number to a given field
679 length, then places this field anywhere in a zero. */
681 zdepi_cint_p (unsigned HOST_WIDE_INT x)
683 unsigned HOST_WIDE_INT lsb_mask, t;
685 /* This might not be obvious, but it's at least fast.
686 This function is critical; we don't have the time loops would take. */
687 lsb_mask = x & -x;
688 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
689 /* Return true iff t is a power of two. */
690 return ((t & (t - 1)) == 0);
693 /* True iff depi or extru can be used to compute (reg & mask).
694 Accept bit pattern like these:
695 0....01....1
696 1....10....0
697 1..10..01..1 */
699 and_mask_p (unsigned HOST_WIDE_INT mask)
701 mask = ~mask;
702 mask += mask & -mask;
703 return (mask & (mask - 1)) == 0;
706 /* True iff depi can be used to compute (reg | MASK). */
708 ior_mask_p (unsigned HOST_WIDE_INT mask)
710 mask += mask & -mask;
711 return (mask & (mask - 1)) == 0;
714 /* Legitimize PIC addresses. If the address is already
715 position-independent, we return ORIG. Newly generated
716 position-independent addresses go to REG. If we need more
717 than one register, we lose. */
720 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
722 rtx pic_ref = orig;
724 gcc_assert (!PA_SYMBOL_REF_TLS_P (orig));
726 /* Labels need special handling. */
727 if (pic_label_operand (orig, mode))
729 rtx insn;
731 /* We do not want to go through the movXX expanders here since that
732 would create recursion.
734 Nor do we really want to call a generator for a named pattern
735 since that requires multiple patterns if we want to support
736 multiple word sizes.
738 So instead we just emit the raw set, which avoids the movXX
739 expanders completely. */
740 mark_reg_pointer (reg, BITS_PER_UNIT);
741 insn = emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
743 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
744 add_reg_note (insn, REG_EQUAL, orig);
746 /* During and after reload, we need to generate a REG_LABEL_OPERAND note
747 and update LABEL_NUSES because this is not done automatically. */
748 if (reload_in_progress || reload_completed)
750 /* Extract LABEL_REF. */
751 if (GET_CODE (orig) == CONST)
752 orig = XEXP (XEXP (orig, 0), 0);
753 /* Extract CODE_LABEL. */
754 orig = XEXP (orig, 0);
755 add_reg_note (insn, REG_LABEL_OPERAND, orig);
756 LABEL_NUSES (orig)++;
758 crtl->uses_pic_offset_table = 1;
759 return reg;
761 if (GET_CODE (orig) == SYMBOL_REF)
763 rtx insn, tmp_reg;
765 gcc_assert (reg);
767 /* Before reload, allocate a temporary register for the intermediate
768 result. This allows the sequence to be deleted when the final
769 result is unused and the insns are trivially dead. */
770 tmp_reg = ((reload_in_progress || reload_completed)
771 ? reg : gen_reg_rtx (Pmode));
773 if (function_label_operand (orig, mode))
775 /* Force function label into memory in word mode. */
776 orig = XEXP (force_const_mem (word_mode, orig), 0);
777 /* Load plabel address from DLT. */
778 emit_move_insn (tmp_reg,
779 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
780 gen_rtx_HIGH (word_mode, orig)));
781 pic_ref
782 = gen_const_mem (Pmode,
783 gen_rtx_LO_SUM (Pmode, tmp_reg,
784 gen_rtx_UNSPEC (Pmode,
785 gen_rtvec (1, orig),
786 UNSPEC_DLTIND14R)));
787 emit_move_insn (reg, pic_ref);
788 /* Now load address of function descriptor. */
789 pic_ref = gen_rtx_MEM (Pmode, reg);
791 else
793 /* Load symbol reference from DLT. */
794 emit_move_insn (tmp_reg,
795 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
796 gen_rtx_HIGH (word_mode, orig)));
797 pic_ref
798 = gen_const_mem (Pmode,
799 gen_rtx_LO_SUM (Pmode, tmp_reg,
800 gen_rtx_UNSPEC (Pmode,
801 gen_rtvec (1, orig),
802 UNSPEC_DLTIND14R)));
805 crtl->uses_pic_offset_table = 1;
806 mark_reg_pointer (reg, BITS_PER_UNIT);
807 insn = emit_move_insn (reg, pic_ref);
809 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
810 set_unique_reg_note (insn, REG_EQUAL, orig);
812 return reg;
814 else if (GET_CODE (orig) == CONST)
816 rtx base;
818 if (GET_CODE (XEXP (orig, 0)) == PLUS
819 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
820 return orig;
822 gcc_assert (reg);
823 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
825 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
826 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
827 base == reg ? 0 : reg);
829 if (GET_CODE (orig) == CONST_INT)
831 if (INT_14_BITS (orig))
832 return plus_constant (base, INTVAL (orig));
833 orig = force_reg (Pmode, orig);
835 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
836 /* Likewise, should we set special REG_NOTEs here? */
839 return pic_ref;
842 static GTY(()) rtx gen_tls_tga;
844 static rtx
845 gen_tls_get_addr (void)
847 if (!gen_tls_tga)
848 gen_tls_tga = init_one_libfunc ("__tls_get_addr");
849 return gen_tls_tga;
852 static rtx
853 hppa_tls_call (rtx arg)
855 rtx ret;
857 ret = gen_reg_rtx (Pmode);
858 emit_library_call_value (gen_tls_get_addr (), ret,
859 LCT_CONST, Pmode, 1, arg, Pmode);
861 return ret;
864 static rtx
865 legitimize_tls_address (rtx addr)
867 rtx ret, insn, tmp, t1, t2, tp;
868 enum tls_model model = SYMBOL_REF_TLS_MODEL (addr);
870 switch (model)
872 case TLS_MODEL_GLOBAL_DYNAMIC:
873 tmp = gen_reg_rtx (Pmode);
874 if (flag_pic)
875 emit_insn (gen_tgd_load_pic (tmp, addr));
876 else
877 emit_insn (gen_tgd_load (tmp, addr));
878 ret = hppa_tls_call (tmp);
879 break;
881 case TLS_MODEL_LOCAL_DYNAMIC:
882 ret = gen_reg_rtx (Pmode);
883 tmp = gen_reg_rtx (Pmode);
884 start_sequence ();
885 if (flag_pic)
886 emit_insn (gen_tld_load_pic (tmp, addr));
887 else
888 emit_insn (gen_tld_load (tmp, addr));
889 t1 = hppa_tls_call (tmp);
890 insn = get_insns ();
891 end_sequence ();
892 t2 = gen_reg_rtx (Pmode);
893 emit_libcall_block (insn, t2, t1,
894 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
895 UNSPEC_TLSLDBASE));
896 emit_insn (gen_tld_offset_load (ret, addr, t2));
897 break;
899 case TLS_MODEL_INITIAL_EXEC:
900 tp = gen_reg_rtx (Pmode);
901 tmp = gen_reg_rtx (Pmode);
902 ret = gen_reg_rtx (Pmode);
903 emit_insn (gen_tp_load (tp));
904 if (flag_pic)
905 emit_insn (gen_tie_load_pic (tmp, addr));
906 else
907 emit_insn (gen_tie_load (tmp, addr));
908 emit_move_insn (ret, gen_rtx_PLUS (Pmode, tp, tmp));
909 break;
911 case TLS_MODEL_LOCAL_EXEC:
912 tp = gen_reg_rtx (Pmode);
913 ret = gen_reg_rtx (Pmode);
914 emit_insn (gen_tp_load (tp));
915 emit_insn (gen_tle_load (ret, addr, tp));
916 break;
918 default:
919 gcc_unreachable ();
922 return ret;
925 /* Try machine-dependent ways of modifying an illegitimate address
926 to be legitimate. If we find one, return the new, valid address.
927 This macro is used in only one place: `memory_address' in explow.c.
929 OLDX is the address as it was before break_out_memory_refs was called.
930 In some cases it is useful to look at this to decide what needs to be done.
932 It is always safe for this macro to do nothing. It exists to recognize
933 opportunities to optimize the output.
935 For the PA, transform:
937 memory(X + <large int>)
939 into:
941 if (<large int> & mask) >= 16
942 Y = (<large int> & ~mask) + mask + 1 Round up.
943 else
944 Y = (<large int> & ~mask) Round down.
945 Z = X + Y
946 memory (Z + (<large int> - Y));
948 This is for CSE to find several similar references, and only use one Z.
950 X can either be a SYMBOL_REF or REG, but because combine cannot
951 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
952 D will not fit in 14 bits.
954 MODE_FLOAT references allow displacements which fit in 5 bits, so use
955 0x1f as the mask.
957 MODE_INT references allow displacements which fit in 14 bits, so use
958 0x3fff as the mask.
960 This relies on the fact that most mode MODE_FLOAT references will use FP
961 registers and most mode MODE_INT references will use integer registers.
962 (In the rare case of an FP register used in an integer MODE, we depend
963 on secondary reloads to clean things up.)
966 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
967 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
968 addressing modes to be used).
970 Put X and Z into registers. Then put the entire expression into
971 a register. */
974 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
975 enum machine_mode mode)
977 rtx orig = x;
979 /* We need to canonicalize the order of operands in unscaled indexed
980 addresses since the code that checks if an address is valid doesn't
981 always try both orders. */
982 if (!TARGET_NO_SPACE_REGS
983 && GET_CODE (x) == PLUS
984 && GET_MODE (x) == Pmode
985 && REG_P (XEXP (x, 0))
986 && REG_P (XEXP (x, 1))
987 && REG_POINTER (XEXP (x, 0))
988 && !REG_POINTER (XEXP (x, 1)))
989 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
991 if (PA_SYMBOL_REF_TLS_P (x))
992 return legitimize_tls_address (x);
993 else if (flag_pic)
994 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
996 /* Strip off CONST. */
997 if (GET_CODE (x) == CONST)
998 x = XEXP (x, 0);
1000 /* Special case. Get the SYMBOL_REF into a register and use indexing.
1001 That should always be safe. */
1002 if (GET_CODE (x) == PLUS
1003 && GET_CODE (XEXP (x, 0)) == REG
1004 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
1006 rtx reg = force_reg (Pmode, XEXP (x, 1));
1007 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
1010 /* Note we must reject symbols which represent function addresses
1011 since the assembler/linker can't handle arithmetic on plabels. */
1012 if (GET_CODE (x) == PLUS
1013 && GET_CODE (XEXP (x, 1)) == CONST_INT
1014 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1015 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
1016 || GET_CODE (XEXP (x, 0)) == REG))
1018 rtx int_part, ptr_reg;
1019 int newoffset;
1020 int offset = INTVAL (XEXP (x, 1));
1021 int mask;
1023 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
1024 ? (INT14_OK_STRICT ? 0x3fff : 0x1f) : 0x3fff);
1026 /* Choose which way to round the offset. Round up if we
1027 are >= halfway to the next boundary. */
1028 if ((offset & mask) >= ((mask + 1) / 2))
1029 newoffset = (offset & ~ mask) + mask + 1;
1030 else
1031 newoffset = (offset & ~ mask);
1033 /* If the newoffset will not fit in 14 bits (ldo), then
1034 handling this would take 4 or 5 instructions (2 to load
1035 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
1036 add the new offset and the SYMBOL_REF.) Combine can
1037 not handle 4->2 or 5->2 combinations, so do not create
1038 them. */
1039 if (! VAL_14_BITS_P (newoffset)
1040 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
1042 rtx const_part = plus_constant (XEXP (x, 0), newoffset);
1043 rtx tmp_reg
1044 = force_reg (Pmode,
1045 gen_rtx_HIGH (Pmode, const_part));
1046 ptr_reg
1047 = force_reg (Pmode,
1048 gen_rtx_LO_SUM (Pmode,
1049 tmp_reg, const_part));
1051 else
1053 if (! VAL_14_BITS_P (newoffset))
1054 int_part = force_reg (Pmode, GEN_INT (newoffset));
1055 else
1056 int_part = GEN_INT (newoffset);
1058 ptr_reg = force_reg (Pmode,
1059 gen_rtx_PLUS (Pmode,
1060 force_reg (Pmode, XEXP (x, 0)),
1061 int_part));
1063 return plus_constant (ptr_reg, offset - newoffset);
1066 /* Handle (plus (mult (a) (shadd_constant)) (b)). */
1068 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1069 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1070 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
1071 && (OBJECT_P (XEXP (x, 1))
1072 || GET_CODE (XEXP (x, 1)) == SUBREG)
1073 && GET_CODE (XEXP (x, 1)) != CONST)
1075 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1076 rtx reg1, reg2;
1078 reg1 = XEXP (x, 1);
1079 if (GET_CODE (reg1) != REG)
1080 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1082 reg2 = XEXP (XEXP (x, 0), 0);
1083 if (GET_CODE (reg2) != REG)
1084 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1086 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1087 gen_rtx_MULT (Pmode,
1088 reg2,
1089 GEN_INT (val)),
1090 reg1));
1093 /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
1095 Only do so for floating point modes since this is more speculative
1096 and we lose if it's an integer store. */
1097 if (GET_CODE (x) == PLUS
1098 && GET_CODE (XEXP (x, 0)) == PLUS
1099 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1100 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
1101 && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1102 && (mode == SFmode || mode == DFmode))
1105 /* First, try and figure out what to use as a base register. */
1106 rtx reg1, reg2, base, idx;
1108 reg1 = XEXP (XEXP (x, 0), 1);
1109 reg2 = XEXP (x, 1);
1110 base = NULL_RTX;
1111 idx = NULL_RTX;
1113 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
1114 then emit_move_sequence will turn on REG_POINTER so we'll know
1115 it's a base register below. */
1116 if (GET_CODE (reg1) != REG)
1117 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1119 if (GET_CODE (reg2) != REG)
1120 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1122 /* Figure out what the base and index are. */
1124 if (GET_CODE (reg1) == REG
1125 && REG_POINTER (reg1))
1127 base = reg1;
1128 idx = gen_rtx_PLUS (Pmode,
1129 gen_rtx_MULT (Pmode,
1130 XEXP (XEXP (XEXP (x, 0), 0), 0),
1131 XEXP (XEXP (XEXP (x, 0), 0), 1)),
1132 XEXP (x, 1));
1134 else if (GET_CODE (reg2) == REG
1135 && REG_POINTER (reg2))
1137 base = reg2;
1138 idx = XEXP (x, 0);
1141 if (base == 0)
1142 return orig;
1144 /* If the index adds a large constant, try to scale the
1145 constant so that it can be loaded with only one insn. */
1146 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1147 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1148 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1149 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1151 /* Divide the CONST_INT by the scale factor, then add it to A. */
1152 int val = INTVAL (XEXP (idx, 1));
1154 val /= INTVAL (XEXP (XEXP (idx, 0), 1));
1155 reg1 = XEXP (XEXP (idx, 0), 0);
1156 if (GET_CODE (reg1) != REG)
1157 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1159 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1161 /* We can now generate a simple scaled indexed address. */
1162 return
1163 force_reg
1164 (Pmode, gen_rtx_PLUS (Pmode,
1165 gen_rtx_MULT (Pmode, reg1,
1166 XEXP (XEXP (idx, 0), 1)),
1167 base));
1170 /* If B + C is still a valid base register, then add them. */
1171 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1172 && INTVAL (XEXP (idx, 1)) <= 4096
1173 && INTVAL (XEXP (idx, 1)) >= -4096)
1175 int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1176 rtx reg1, reg2;
1178 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1180 reg2 = XEXP (XEXP (idx, 0), 0);
1181 if (GET_CODE (reg2) != CONST_INT)
1182 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1184 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1185 gen_rtx_MULT (Pmode,
1186 reg2,
1187 GEN_INT (val)),
1188 reg1));
1191 /* Get the index into a register, then add the base + index and
1192 return a register holding the result. */
1194 /* First get A into a register. */
1195 reg1 = XEXP (XEXP (idx, 0), 0);
1196 if (GET_CODE (reg1) != REG)
1197 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1199 /* And get B into a register. */
1200 reg2 = XEXP (idx, 1);
1201 if (GET_CODE (reg2) != REG)
1202 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1204 reg1 = force_reg (Pmode,
1205 gen_rtx_PLUS (Pmode,
1206 gen_rtx_MULT (Pmode, reg1,
1207 XEXP (XEXP (idx, 0), 1)),
1208 reg2));
1210 /* Add the result to our base register and return. */
1211 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1215 /* Uh-oh. We might have an address for x[n-100000]. This needs
1216 special handling to avoid creating an indexed memory address
1217 with x-100000 as the base.
1219 If the constant part is small enough, then it's still safe because
1220 there is a guard page at the beginning and end of the data segment.
1222 Scaled references are common enough that we want to try and rearrange the
1223 terms so that we can use indexing for these addresses too. Only
1224 do the optimization for floatint point modes. */
1226 if (GET_CODE (x) == PLUS
1227 && symbolic_expression_p (XEXP (x, 1)))
1229 /* Ugly. We modify things here so that the address offset specified
1230 by the index expression is computed first, then added to x to form
1231 the entire address. */
1233 rtx regx1, regx2, regy1, regy2, y;
1235 /* Strip off any CONST. */
1236 y = XEXP (x, 1);
1237 if (GET_CODE (y) == CONST)
1238 y = XEXP (y, 0);
1240 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1242 /* See if this looks like
1243 (plus (mult (reg) (shadd_const))
1244 (const (plus (symbol_ref) (const_int))))
1246 Where const_int is small. In that case the const
1247 expression is a valid pointer for indexing.
1249 If const_int is big, but can be divided evenly by shadd_const
1250 and added to (reg). This allows more scaled indexed addresses. */
1251 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1252 && GET_CODE (XEXP (x, 0)) == MULT
1253 && GET_CODE (XEXP (y, 1)) == CONST_INT
1254 && INTVAL (XEXP (y, 1)) >= -4096
1255 && INTVAL (XEXP (y, 1)) <= 4095
1256 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1257 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1259 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1260 rtx reg1, reg2;
1262 reg1 = XEXP (x, 1);
1263 if (GET_CODE (reg1) != REG)
1264 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1266 reg2 = XEXP (XEXP (x, 0), 0);
1267 if (GET_CODE (reg2) != REG)
1268 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1270 return force_reg (Pmode,
1271 gen_rtx_PLUS (Pmode,
1272 gen_rtx_MULT (Pmode,
1273 reg2,
1274 GEN_INT (val)),
1275 reg1));
1277 else if ((mode == DFmode || mode == SFmode)
1278 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1279 && GET_CODE (XEXP (x, 0)) == MULT
1280 && GET_CODE (XEXP (y, 1)) == CONST_INT
1281 && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1282 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1283 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1285 regx1
1286 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1287 / INTVAL (XEXP (XEXP (x, 0), 1))));
1288 regx2 = XEXP (XEXP (x, 0), 0);
1289 if (GET_CODE (regx2) != REG)
1290 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1291 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1292 regx2, regx1));
1293 return
1294 force_reg (Pmode,
1295 gen_rtx_PLUS (Pmode,
1296 gen_rtx_MULT (Pmode, regx2,
1297 XEXP (XEXP (x, 0), 1)),
1298 force_reg (Pmode, XEXP (y, 0))));
1300 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1301 && INTVAL (XEXP (y, 1)) >= -4096
1302 && INTVAL (XEXP (y, 1)) <= 4095)
1304 /* This is safe because of the guard page at the
1305 beginning and end of the data space. Just
1306 return the original address. */
1307 return orig;
1309 else
1311 /* Doesn't look like one we can optimize. */
1312 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1313 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1314 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1315 regx1 = force_reg (Pmode,
1316 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1317 regx1, regy2));
1318 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1323 return orig;
1326 /* Implement the TARGET_REGISTER_MOVE_COST hook.
1328 Compute extra cost of moving data between one register class
1329 and another.
1331 Make moves from SAR so expensive they should never happen. We used to
1332 have 0xffff here, but that generates overflow in rare cases.
1334 Copies involving a FP register and a non-FP register are relatively
1335 expensive because they must go through memory.
1337 Other copies are reasonably cheap. */
1339 static int
1340 hppa_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1341 reg_class_t from, reg_class_t to)
1343 if (from == SHIFT_REGS)
1344 return 0x100;
1345 else if ((FP_REG_CLASS_P (from) && ! FP_REG_CLASS_P (to))
1346 || (FP_REG_CLASS_P (to) && ! FP_REG_CLASS_P (from)))
1347 return 16;
1348 else
1349 return 2;
1352 /* For the HPPA, REG and REG+CONST is cost 0
1353 and addresses involving symbolic constants are cost 2.
1355 PIC addresses are very expensive.
1357 It is no coincidence that this has the same structure
1358 as GO_IF_LEGITIMATE_ADDRESS. */
1360 static int
1361 hppa_address_cost (rtx X,
1362 bool speed ATTRIBUTE_UNUSED)
1364 switch (GET_CODE (X))
1366 case REG:
1367 case PLUS:
1368 case LO_SUM:
1369 return 1;
1370 case HIGH:
1371 return 2;
1372 default:
1373 return 4;
1377 /* Compute a (partial) cost for rtx X. Return true if the complete
1378 cost has been computed, and false if subexpressions should be
1379 scanned. In either case, *TOTAL contains the cost result. */
1381 static bool
1382 hppa_rtx_costs (rtx x, int code, int outer_code, int *total,
1383 bool speed ATTRIBUTE_UNUSED)
1385 switch (code)
1387 case CONST_INT:
1388 if (INTVAL (x) == 0)
1389 *total = 0;
1390 else if (INT_14_BITS (x))
1391 *total = 1;
1392 else
1393 *total = 2;
1394 return true;
1396 case HIGH:
1397 *total = 2;
1398 return true;
1400 case CONST:
1401 case LABEL_REF:
1402 case SYMBOL_REF:
1403 *total = 4;
1404 return true;
1406 case CONST_DOUBLE:
1407 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1408 && outer_code != SET)
1409 *total = 0;
1410 else
1411 *total = 8;
1412 return true;
1414 case MULT:
1415 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1416 *total = COSTS_N_INSNS (3);
1417 else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1418 *total = COSTS_N_INSNS (8);
1419 else
1420 *total = COSTS_N_INSNS (20);
1421 return true;
1423 case DIV:
1424 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1426 *total = COSTS_N_INSNS (14);
1427 return true;
1429 /* FALLTHRU */
1431 case UDIV:
1432 case MOD:
1433 case UMOD:
1434 *total = COSTS_N_INSNS (60);
1435 return true;
1437 case PLUS: /* this includes shNadd insns */
1438 case MINUS:
1439 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1440 *total = COSTS_N_INSNS (3);
1441 else
1442 *total = COSTS_N_INSNS (1);
1443 return true;
1445 case ASHIFT:
1446 case ASHIFTRT:
1447 case LSHIFTRT:
1448 *total = COSTS_N_INSNS (1);
1449 return true;
1451 default:
1452 return false;
1456 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1457 new rtx with the correct mode. */
1458 static inline rtx
1459 force_mode (enum machine_mode mode, rtx orig)
1461 if (mode == GET_MODE (orig))
1462 return orig;
1464 gcc_assert (REGNO (orig) < FIRST_PSEUDO_REGISTER);
1466 return gen_rtx_REG (mode, REGNO (orig));
1469 /* Return 1 if *X is a thread-local symbol. */
1471 static int
1472 pa_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1474 return PA_SYMBOL_REF_TLS_P (*x);
1477 /* Return 1 if X contains a thread-local symbol. */
1479 bool
1480 pa_tls_referenced_p (rtx x)
1482 if (!TARGET_HAVE_TLS)
1483 return false;
1485 return for_each_rtx (&x, &pa_tls_symbol_ref_1, 0);
1488 /* Emit insns to move operands[1] into operands[0].
1490 Return 1 if we have written out everything that needs to be done to
1491 do the move. Otherwise, return 0 and the caller will emit the move
1492 normally.
1494 Note SCRATCH_REG may not be in the proper mode depending on how it
1495 will be used. This routine is responsible for creating a new copy
1496 of SCRATCH_REG in the proper mode. */
1499 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1501 register rtx operand0 = operands[0];
1502 register rtx operand1 = operands[1];
1503 register rtx tem;
1505 /* We can only handle indexed addresses in the destination operand
1506 of floating point stores. Thus, we need to break out indexed
1507 addresses from the destination operand. */
1508 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1510 gcc_assert (can_create_pseudo_p ());
1512 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1513 operand0 = replace_equiv_address (operand0, tem);
1516 /* On targets with non-equivalent space registers, break out unscaled
1517 indexed addresses from the source operand before the final CSE.
1518 We have to do this because the REG_POINTER flag is not correctly
1519 carried through various optimization passes and CSE may substitute
1520 a pseudo without the pointer set for one with the pointer set. As
1521 a result, we loose various opportunities to create insns with
1522 unscaled indexed addresses. */
1523 if (!TARGET_NO_SPACE_REGS
1524 && !cse_not_expected
1525 && GET_CODE (operand1) == MEM
1526 && GET_CODE (XEXP (operand1, 0)) == PLUS
1527 && REG_P (XEXP (XEXP (operand1, 0), 0))
1528 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1529 operand1
1530 = replace_equiv_address (operand1,
1531 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1533 if (scratch_reg
1534 && reload_in_progress && GET_CODE (operand0) == REG
1535 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1536 operand0 = reg_equiv_mem[REGNO (operand0)];
1537 else if (scratch_reg
1538 && reload_in_progress && GET_CODE (operand0) == SUBREG
1539 && GET_CODE (SUBREG_REG (operand0)) == REG
1540 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1542 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1543 the code which tracks sets/uses for delete_output_reload. */
1544 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1545 reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1546 SUBREG_BYTE (operand0));
1547 operand0 = alter_subreg (&temp);
1550 if (scratch_reg
1551 && reload_in_progress && GET_CODE (operand1) == REG
1552 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1553 operand1 = reg_equiv_mem[REGNO (operand1)];
1554 else if (scratch_reg
1555 && reload_in_progress && GET_CODE (operand1) == SUBREG
1556 && GET_CODE (SUBREG_REG (operand1)) == REG
1557 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1559 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1560 the code which tracks sets/uses for delete_output_reload. */
1561 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1562 reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1563 SUBREG_BYTE (operand1));
1564 operand1 = alter_subreg (&temp);
1567 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1568 && ((tem = find_replacement (&XEXP (operand0, 0)))
1569 != XEXP (operand0, 0)))
1570 operand0 = replace_equiv_address (operand0, tem);
1572 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1573 && ((tem = find_replacement (&XEXP (operand1, 0)))
1574 != XEXP (operand1, 0)))
1575 operand1 = replace_equiv_address (operand1, tem);
1577 /* Handle secondary reloads for loads/stores of FP registers from
1578 REG+D addresses where D does not fit in 5 or 14 bits, including
1579 (subreg (mem (addr))) cases. */
1580 if (scratch_reg
1581 && fp_reg_operand (operand0, mode)
1582 && ((GET_CODE (operand1) == MEM
1583 && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1584 XEXP (operand1, 0)))
1585 || ((GET_CODE (operand1) == SUBREG
1586 && GET_CODE (XEXP (operand1, 0)) == MEM
1587 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1588 ? SFmode : DFmode),
1589 XEXP (XEXP (operand1, 0), 0))))))
1591 if (GET_CODE (operand1) == SUBREG)
1592 operand1 = XEXP (operand1, 0);
1594 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1595 it in WORD_MODE regardless of what mode it was originally given
1596 to us. */
1597 scratch_reg = force_mode (word_mode, scratch_reg);
1599 /* D might not fit in 14 bits either; for such cases load D into
1600 scratch reg. */
1601 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1603 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1604 emit_move_insn (scratch_reg,
1605 gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1606 Pmode,
1607 XEXP (XEXP (operand1, 0), 0),
1608 scratch_reg));
1610 else
1611 emit_move_insn (scratch_reg, XEXP (operand1, 0));
1612 emit_insn (gen_rtx_SET (VOIDmode, operand0,
1613 replace_equiv_address (operand1, scratch_reg)));
1614 return 1;
1616 else if (scratch_reg
1617 && fp_reg_operand (operand1, mode)
1618 && ((GET_CODE (operand0) == MEM
1619 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1620 ? SFmode : DFmode),
1621 XEXP (operand0, 0)))
1622 || ((GET_CODE (operand0) == SUBREG)
1623 && GET_CODE (XEXP (operand0, 0)) == MEM
1624 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1625 ? SFmode : DFmode),
1626 XEXP (XEXP (operand0, 0), 0)))))
1628 if (GET_CODE (operand0) == SUBREG)
1629 operand0 = XEXP (operand0, 0);
1631 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1632 it in WORD_MODE regardless of what mode it was originally given
1633 to us. */
1634 scratch_reg = force_mode (word_mode, scratch_reg);
1636 /* D might not fit in 14 bits either; for such cases load D into
1637 scratch reg. */
1638 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1640 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1641 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1642 0)),
1643 Pmode,
1644 XEXP (XEXP (operand0, 0),
1646 scratch_reg));
1648 else
1649 emit_move_insn (scratch_reg, XEXP (operand0, 0));
1650 emit_insn (gen_rtx_SET (VOIDmode,
1651 replace_equiv_address (operand0, scratch_reg),
1652 operand1));
1653 return 1;
1655 /* Handle secondary reloads for loads of FP registers from constant
1656 expressions by forcing the constant into memory.
1658 Use scratch_reg to hold the address of the memory location.
1660 The proper fix is to change PREFERRED_RELOAD_CLASS to return
1661 NO_REGS when presented with a const_int and a register class
1662 containing only FP registers. Doing so unfortunately creates
1663 more problems than it solves. Fix this for 2.5. */
1664 else if (scratch_reg
1665 && CONSTANT_P (operand1)
1666 && fp_reg_operand (operand0, mode))
1668 rtx const_mem, xoperands[2];
1670 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1671 it in WORD_MODE regardless of what mode it was originally given
1672 to us. */
1673 scratch_reg = force_mode (word_mode, scratch_reg);
1675 /* Force the constant into memory and put the address of the
1676 memory location into scratch_reg. */
1677 const_mem = force_const_mem (mode, operand1);
1678 xoperands[0] = scratch_reg;
1679 xoperands[1] = XEXP (const_mem, 0);
1680 emit_move_sequence (xoperands, Pmode, 0);
1682 /* Now load the destination register. */
1683 emit_insn (gen_rtx_SET (mode, operand0,
1684 replace_equiv_address (const_mem, scratch_reg)));
1685 return 1;
1687 /* Handle secondary reloads for SAR. These occur when trying to load
1688 the SAR from memory, FP register, or with a constant. */
1689 else if (scratch_reg
1690 && GET_CODE (operand0) == REG
1691 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1692 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1693 && (GET_CODE (operand1) == MEM
1694 || GET_CODE (operand1) == CONST_INT
1695 || (GET_CODE (operand1) == REG
1696 && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1698 /* D might not fit in 14 bits either; for such cases load D into
1699 scratch reg. */
1700 if (GET_CODE (operand1) == MEM
1701 && !memory_address_p (GET_MODE (operand0), XEXP (operand1, 0)))
1703 /* We are reloading the address into the scratch register, so we
1704 want to make sure the scratch register is a full register. */
1705 scratch_reg = force_mode (word_mode, scratch_reg);
1707 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1708 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1709 0)),
1710 Pmode,
1711 XEXP (XEXP (operand1, 0),
1713 scratch_reg));
1715 /* Now we are going to load the scratch register from memory,
1716 we want to load it in the same width as the original MEM,
1717 which must be the same as the width of the ultimate destination,
1718 OPERAND0. */
1719 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1721 emit_move_insn (scratch_reg,
1722 replace_equiv_address (operand1, scratch_reg));
1724 else
1726 /* We want to load the scratch register using the same mode as
1727 the ultimate destination. */
1728 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1730 emit_move_insn (scratch_reg, operand1);
1733 /* And emit the insn to set the ultimate destination. We know that
1734 the scratch register has the same mode as the destination at this
1735 point. */
1736 emit_move_insn (operand0, scratch_reg);
1737 return 1;
1739 /* Handle the most common case: storing into a register. */
1740 else if (register_operand (operand0, mode))
1742 if (register_operand (operand1, mode)
1743 || (GET_CODE (operand1) == CONST_INT
1744 && cint_ok_for_move (INTVAL (operand1)))
1745 || (operand1 == CONST0_RTX (mode))
1746 || (GET_CODE (operand1) == HIGH
1747 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1748 /* Only `general_operands' can come here, so MEM is ok. */
1749 || GET_CODE (operand1) == MEM)
1751 /* Various sets are created during RTL generation which don't
1752 have the REG_POINTER flag correctly set. After the CSE pass,
1753 instruction recognition can fail if we don't consistently
1754 set this flag when performing register copies. This should
1755 also improve the opportunities for creating insns that use
1756 unscaled indexing. */
1757 if (REG_P (operand0) && REG_P (operand1))
1759 if (REG_POINTER (operand1)
1760 && !REG_POINTER (operand0)
1761 && !HARD_REGISTER_P (operand0))
1762 copy_reg_pointer (operand0, operand1);
1765 /* When MEMs are broken out, the REG_POINTER flag doesn't
1766 get set. In some cases, we can set the REG_POINTER flag
1767 from the declaration for the MEM. */
1768 if (REG_P (operand0)
1769 && GET_CODE (operand1) == MEM
1770 && !REG_POINTER (operand0))
1772 tree decl = MEM_EXPR (operand1);
1774 /* Set the register pointer flag and register alignment
1775 if the declaration for this memory reference is a
1776 pointer type. */
1777 if (decl)
1779 tree type;
1781 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1782 tree operand 1. */
1783 if (TREE_CODE (decl) == COMPONENT_REF)
1784 decl = TREE_OPERAND (decl, 1);
1786 type = TREE_TYPE (decl);
1787 type = strip_array_types (type);
1789 if (POINTER_TYPE_P (type))
1791 int align;
1793 type = TREE_TYPE (type);
1794 /* Using TYPE_ALIGN_OK is rather conservative as
1795 only the ada frontend actually sets it. */
1796 align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1797 : BITS_PER_UNIT);
1798 mark_reg_pointer (operand0, align);
1803 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1804 return 1;
1807 else if (GET_CODE (operand0) == MEM)
1809 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1810 && !(reload_in_progress || reload_completed))
1812 rtx temp = gen_reg_rtx (DFmode);
1814 emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1815 emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1816 return 1;
1818 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1820 /* Run this case quickly. */
1821 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1822 return 1;
1824 if (! (reload_in_progress || reload_completed))
1826 operands[0] = validize_mem (operand0);
1827 operands[1] = operand1 = force_reg (mode, operand1);
1831 /* Simplify the source if we need to.
1832 Note we do have to handle function labels here, even though we do
1833 not consider them legitimate constants. Loop optimizations can
1834 call the emit_move_xxx with one as a source. */
1835 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1836 || function_label_operand (operand1, mode)
1837 || (GET_CODE (operand1) == HIGH
1838 && symbolic_operand (XEXP (operand1, 0), mode)))
1840 int ishighonly = 0;
1842 if (GET_CODE (operand1) == HIGH)
1844 ishighonly = 1;
1845 operand1 = XEXP (operand1, 0);
1847 if (symbolic_operand (operand1, mode))
1849 /* Argh. The assembler and linker can't handle arithmetic
1850 involving plabels.
1852 So we force the plabel into memory, load operand0 from
1853 the memory location, then add in the constant part. */
1854 if ((GET_CODE (operand1) == CONST
1855 && GET_CODE (XEXP (operand1, 0)) == PLUS
1856 && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
1857 || function_label_operand (operand1, mode))
1859 rtx temp, const_part;
1861 /* Figure out what (if any) scratch register to use. */
1862 if (reload_in_progress || reload_completed)
1864 scratch_reg = scratch_reg ? scratch_reg : operand0;
1865 /* SCRATCH_REG will hold an address and maybe the actual
1866 data. We want it in WORD_MODE regardless of what mode it
1867 was originally given to us. */
1868 scratch_reg = force_mode (word_mode, scratch_reg);
1870 else if (flag_pic)
1871 scratch_reg = gen_reg_rtx (Pmode);
1873 if (GET_CODE (operand1) == CONST)
1875 /* Save away the constant part of the expression. */
1876 const_part = XEXP (XEXP (operand1, 0), 1);
1877 gcc_assert (GET_CODE (const_part) == CONST_INT);
1879 /* Force the function label into memory. */
1880 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
1882 else
1884 /* No constant part. */
1885 const_part = NULL_RTX;
1887 /* Force the function label into memory. */
1888 temp = force_const_mem (mode, operand1);
1892 /* Get the address of the memory location. PIC-ify it if
1893 necessary. */
1894 temp = XEXP (temp, 0);
1895 if (flag_pic)
1896 temp = legitimize_pic_address (temp, mode, scratch_reg);
1898 /* Put the address of the memory location into our destination
1899 register. */
1900 operands[1] = temp;
1901 emit_move_sequence (operands, mode, scratch_reg);
1903 /* Now load from the memory location into our destination
1904 register. */
1905 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
1906 emit_move_sequence (operands, mode, scratch_reg);
1908 /* And add back in the constant part. */
1909 if (const_part != NULL_RTX)
1910 expand_inc (operand0, const_part);
1912 return 1;
1915 if (flag_pic)
1917 rtx temp;
1919 if (reload_in_progress || reload_completed)
1921 temp = scratch_reg ? scratch_reg : operand0;
1922 /* TEMP will hold an address and maybe the actual
1923 data. We want it in WORD_MODE regardless of what mode it
1924 was originally given to us. */
1925 temp = force_mode (word_mode, temp);
1927 else
1928 temp = gen_reg_rtx (Pmode);
1930 /* (const (plus (symbol) (const_int))) must be forced to
1931 memory during/after reload if the const_int will not fit
1932 in 14 bits. */
1933 if (GET_CODE (operand1) == CONST
1934 && GET_CODE (XEXP (operand1, 0)) == PLUS
1935 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
1936 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
1937 && (reload_completed || reload_in_progress)
1938 && flag_pic)
1940 rtx const_mem = force_const_mem (mode, operand1);
1941 operands[1] = legitimize_pic_address (XEXP (const_mem, 0),
1942 mode, temp);
1943 operands[1] = replace_equiv_address (const_mem, operands[1]);
1944 emit_move_sequence (operands, mode, temp);
1946 else
1948 operands[1] = legitimize_pic_address (operand1, mode, temp);
1949 if (REG_P (operand0) && REG_P (operands[1]))
1950 copy_reg_pointer (operand0, operands[1]);
1951 emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
1954 /* On the HPPA, references to data space are supposed to use dp,
1955 register 27, but showing it in the RTL inhibits various cse
1956 and loop optimizations. */
1957 else
1959 rtx temp, set;
1961 if (reload_in_progress || reload_completed)
1963 temp = scratch_reg ? scratch_reg : operand0;
1964 /* TEMP will hold an address and maybe the actual
1965 data. We want it in WORD_MODE regardless of what mode it
1966 was originally given to us. */
1967 temp = force_mode (word_mode, temp);
1969 else
1970 temp = gen_reg_rtx (mode);
1972 /* Loading a SYMBOL_REF into a register makes that register
1973 safe to be used as the base in an indexed address.
1975 Don't mark hard registers though. That loses. */
1976 if (GET_CODE (operand0) == REG
1977 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1978 mark_reg_pointer (operand0, BITS_PER_UNIT);
1979 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
1980 mark_reg_pointer (temp, BITS_PER_UNIT);
1982 if (ishighonly)
1983 set = gen_rtx_SET (mode, operand0, temp);
1984 else
1985 set = gen_rtx_SET (VOIDmode,
1986 operand0,
1987 gen_rtx_LO_SUM (mode, temp, operand1));
1989 emit_insn (gen_rtx_SET (VOIDmode,
1990 temp,
1991 gen_rtx_HIGH (mode, operand1)));
1992 emit_insn (set);
1995 return 1;
1997 else if (pa_tls_referenced_p (operand1))
1999 rtx tmp = operand1;
2000 rtx addend = NULL;
2002 if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
2004 addend = XEXP (XEXP (tmp, 0), 1);
2005 tmp = XEXP (XEXP (tmp, 0), 0);
2008 gcc_assert (GET_CODE (tmp) == SYMBOL_REF);
2009 tmp = legitimize_tls_address (tmp);
2010 if (addend)
2012 tmp = gen_rtx_PLUS (mode, tmp, addend);
2013 tmp = force_operand (tmp, operands[0]);
2015 operands[1] = tmp;
2017 else if (GET_CODE (operand1) != CONST_INT
2018 || !cint_ok_for_move (INTVAL (operand1)))
2020 rtx insn, temp;
2021 rtx op1 = operand1;
2022 HOST_WIDE_INT value = 0;
2023 HOST_WIDE_INT insv = 0;
2024 int insert = 0;
2026 if (GET_CODE (operand1) == CONST_INT)
2027 value = INTVAL (operand1);
2029 if (TARGET_64BIT
2030 && GET_CODE (operand1) == CONST_INT
2031 && HOST_BITS_PER_WIDE_INT > 32
2032 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
2034 HOST_WIDE_INT nval;
2036 /* Extract the low order 32 bits of the value and sign extend.
2037 If the new value is the same as the original value, we can
2038 can use the original value as-is. If the new value is
2039 different, we use it and insert the most-significant 32-bits
2040 of the original value into the final result. */
2041 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
2042 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
2043 if (value != nval)
2045 #if HOST_BITS_PER_WIDE_INT > 32
2046 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
2047 #endif
2048 insert = 1;
2049 value = nval;
2050 operand1 = GEN_INT (nval);
2054 if (reload_in_progress || reload_completed)
2055 temp = scratch_reg ? scratch_reg : operand0;
2056 else
2057 temp = gen_reg_rtx (mode);
2059 /* We don't directly split DImode constants on 32-bit targets
2060 because PLUS uses an 11-bit immediate and the insn sequence
2061 generated is not as efficient as the one using HIGH/LO_SUM. */
2062 if (GET_CODE (operand1) == CONST_INT
2063 && GET_MODE_BITSIZE (mode) <= BITS_PER_WORD
2064 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2065 && !insert)
2067 /* Directly break constant into high and low parts. This
2068 provides better optimization opportunities because various
2069 passes recognize constants split with PLUS but not LO_SUM.
2070 We use a 14-bit signed low part except when the addition
2071 of 0x4000 to the high part might change the sign of the
2072 high part. */
2073 HOST_WIDE_INT low = value & 0x3fff;
2074 HOST_WIDE_INT high = value & ~ 0x3fff;
2076 if (low >= 0x2000)
2078 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
2079 high += 0x2000;
2080 else
2081 high += 0x4000;
2084 low = value - high;
2086 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
2087 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2089 else
2091 emit_insn (gen_rtx_SET (VOIDmode, temp,
2092 gen_rtx_HIGH (mode, operand1)));
2093 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
2096 insn = emit_move_insn (operands[0], operands[1]);
2098 /* Now insert the most significant 32 bits of the value
2099 into the register. When we don't have a second register
2100 available, it could take up to nine instructions to load
2101 a 64-bit integer constant. Prior to reload, we force
2102 constants that would take more than three instructions
2103 to load to the constant pool. During and after reload,
2104 we have to handle all possible values. */
2105 if (insert)
2107 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
2108 register and the value to be inserted is outside the
2109 range that can be loaded with three depdi instructions. */
2110 if (temp != operand0 && (insv >= 16384 || insv < -16384))
2112 operand1 = GEN_INT (insv);
2114 emit_insn (gen_rtx_SET (VOIDmode, temp,
2115 gen_rtx_HIGH (mode, operand1)));
2116 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
2117 emit_insn (gen_insv (operand0, GEN_INT (32),
2118 const0_rtx, temp));
2120 else
2122 int len = 5, pos = 27;
2124 /* Insert the bits using the depdi instruction. */
2125 while (pos >= 0)
2127 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2128 HOST_WIDE_INT sign = v5 < 0;
2130 /* Left extend the insertion. */
2131 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2132 while (pos > 0 && (insv & 1) == sign)
2134 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2135 len += 1;
2136 pos -= 1;
2139 emit_insn (gen_insv (operand0, GEN_INT (len),
2140 GEN_INT (pos), GEN_INT (v5)));
2142 len = pos > 0 && pos < 5 ? pos : 5;
2143 pos -= len;
2148 set_unique_reg_note (insn, REG_EQUAL, op1);
2150 return 1;
2153 /* Now have insn-emit do whatever it normally does. */
2154 return 0;
2157 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2158 it will need a link/runtime reloc). */
2161 reloc_needed (tree exp)
2163 int reloc = 0;
2165 switch (TREE_CODE (exp))
2167 case ADDR_EXPR:
2168 return 1;
2170 case POINTER_PLUS_EXPR:
2171 case PLUS_EXPR:
2172 case MINUS_EXPR:
2173 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2174 reloc |= reloc_needed (TREE_OPERAND (exp, 1));
2175 break;
2177 CASE_CONVERT:
2178 case NON_LVALUE_EXPR:
2179 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2180 break;
2182 case CONSTRUCTOR:
2184 tree value;
2185 unsigned HOST_WIDE_INT ix;
2187 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), ix, value)
2188 if (value)
2189 reloc |= reloc_needed (value);
2191 break;
2193 case ERROR_MARK:
2194 break;
2196 default:
2197 break;
2199 return reloc;
2202 /* Does operand (which is a symbolic_operand) live in text space?
2203 If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2204 will be true. */
2207 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2209 if (GET_CODE (operand) == CONST)
2210 operand = XEXP (XEXP (operand, 0), 0);
2211 if (flag_pic)
2213 if (GET_CODE (operand) == SYMBOL_REF)
2214 return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2216 else
2218 if (GET_CODE (operand) == SYMBOL_REF)
2219 return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2221 return 1;
2225 /* Return the best assembler insn template
2226 for moving operands[1] into operands[0] as a fullword. */
2227 const char *
2228 singlemove_string (rtx *operands)
2230 HOST_WIDE_INT intval;
2232 if (GET_CODE (operands[0]) == MEM)
2233 return "stw %r1,%0";
2234 if (GET_CODE (operands[1]) == MEM)
2235 return "ldw %1,%0";
2236 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2238 long i;
2239 REAL_VALUE_TYPE d;
2241 gcc_assert (GET_MODE (operands[1]) == SFmode);
2243 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2244 bit pattern. */
2245 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2246 REAL_VALUE_TO_TARGET_SINGLE (d, i);
2248 operands[1] = GEN_INT (i);
2249 /* Fall through to CONST_INT case. */
2251 if (GET_CODE (operands[1]) == CONST_INT)
2253 intval = INTVAL (operands[1]);
2255 if (VAL_14_BITS_P (intval))
2256 return "ldi %1,%0";
2257 else if ((intval & 0x7ff) == 0)
2258 return "ldil L'%1,%0";
2259 else if (zdepi_cint_p (intval))
2260 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2261 else
2262 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2264 return "copy %1,%0";
2268 /* Compute position (in OP[1]) and width (in OP[2])
2269 useful for copying IMM to a register using the zdepi
2270 instructions. Store the immediate value to insert in OP[0]. */
2271 static void
2272 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2274 int lsb, len;
2276 /* Find the least significant set bit in IMM. */
2277 for (lsb = 0; lsb < 32; lsb++)
2279 if ((imm & 1) != 0)
2280 break;
2281 imm >>= 1;
2284 /* Choose variants based on *sign* of the 5-bit field. */
2285 if ((imm & 0x10) == 0)
2286 len = (lsb <= 28) ? 4 : 32 - lsb;
2287 else
2289 /* Find the width of the bitstring in IMM. */
2290 for (len = 5; len < 32 - lsb; len++)
2292 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2293 break;
2296 /* Sign extend IMM as a 5-bit value. */
2297 imm = (imm & 0xf) - 0x10;
2300 op[0] = imm;
2301 op[1] = 31 - lsb;
2302 op[2] = len;
2305 /* Compute position (in OP[1]) and width (in OP[2])
2306 useful for copying IMM to a register using the depdi,z
2307 instructions. Store the immediate value to insert in OP[0]. */
2308 void
2309 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2311 int lsb, len, maxlen;
2313 maxlen = MIN (HOST_BITS_PER_WIDE_INT, 64);
2315 /* Find the least significant set bit in IMM. */
2316 for (lsb = 0; lsb < maxlen; lsb++)
2318 if ((imm & 1) != 0)
2319 break;
2320 imm >>= 1;
2323 /* Choose variants based on *sign* of the 5-bit field. */
2324 if ((imm & 0x10) == 0)
2325 len = (lsb <= maxlen - 4) ? 4 : maxlen - lsb;
2326 else
2328 /* Find the width of the bitstring in IMM. */
2329 for (len = 5; len < maxlen - lsb; len++)
2331 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2332 break;
2335 /* Extend length if host is narrow and IMM is negative. */
2336 if (HOST_BITS_PER_WIDE_INT == 32 && len == maxlen - lsb)
2337 len += 32;
2339 /* Sign extend IMM as a 5-bit value. */
2340 imm = (imm & 0xf) - 0x10;
2343 op[0] = imm;
2344 op[1] = 63 - lsb;
2345 op[2] = len;
2348 /* Output assembler code to perform a doubleword move insn
2349 with operands OPERANDS. */
2351 const char *
2352 output_move_double (rtx *operands)
2354 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2355 rtx latehalf[2];
2356 rtx addreg0 = 0, addreg1 = 0;
2358 /* First classify both operands. */
2360 if (REG_P (operands[0]))
2361 optype0 = REGOP;
2362 else if (offsettable_memref_p (operands[0]))
2363 optype0 = OFFSOP;
2364 else if (GET_CODE (operands[0]) == MEM)
2365 optype0 = MEMOP;
2366 else
2367 optype0 = RNDOP;
2369 if (REG_P (operands[1]))
2370 optype1 = REGOP;
2371 else if (CONSTANT_P (operands[1]))
2372 optype1 = CNSTOP;
2373 else if (offsettable_memref_p (operands[1]))
2374 optype1 = OFFSOP;
2375 else if (GET_CODE (operands[1]) == MEM)
2376 optype1 = MEMOP;
2377 else
2378 optype1 = RNDOP;
2380 /* Check for the cases that the operand constraints are not
2381 supposed to allow to happen. */
2382 gcc_assert (optype0 == REGOP || optype1 == REGOP);
2384 /* Handle copies between general and floating registers. */
2386 if (optype0 == REGOP && optype1 == REGOP
2387 && FP_REG_P (operands[0]) ^ FP_REG_P (operands[1]))
2389 if (FP_REG_P (operands[0]))
2391 output_asm_insn ("{stws|stw} %1,-16(%%sp)", operands);
2392 output_asm_insn ("{stws|stw} %R1,-12(%%sp)", operands);
2393 return "{fldds|fldd} -16(%%sp),%0";
2395 else
2397 output_asm_insn ("{fstds|fstd} %1,-16(%%sp)", operands);
2398 output_asm_insn ("{ldws|ldw} -16(%%sp),%0", operands);
2399 return "{ldws|ldw} -12(%%sp),%R0";
2403 /* Handle auto decrementing and incrementing loads and stores
2404 specifically, since the structure of the function doesn't work
2405 for them without major modification. Do it better when we learn
2406 this port about the general inc/dec addressing of PA.
2407 (This was written by tege. Chide him if it doesn't work.) */
2409 if (optype0 == MEMOP)
2411 /* We have to output the address syntax ourselves, since print_operand
2412 doesn't deal with the addresses we want to use. Fix this later. */
2414 rtx addr = XEXP (operands[0], 0);
2415 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2417 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2419 operands[0] = XEXP (addr, 0);
2420 gcc_assert (GET_CODE (operands[1]) == REG
2421 && GET_CODE (operands[0]) == REG);
2423 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2425 /* No overlap between high target register and address
2426 register. (We do this in a non-obvious way to
2427 save a register file writeback) */
2428 if (GET_CODE (addr) == POST_INC)
2429 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2430 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2432 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2434 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2436 operands[0] = XEXP (addr, 0);
2437 gcc_assert (GET_CODE (operands[1]) == REG
2438 && GET_CODE (operands[0]) == REG);
2440 gcc_assert (!reg_overlap_mentioned_p (high_reg, addr));
2441 /* No overlap between high target register and address
2442 register. (We do this in a non-obvious way to save a
2443 register file writeback) */
2444 if (GET_CODE (addr) == PRE_INC)
2445 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2446 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2449 if (optype1 == MEMOP)
2451 /* We have to output the address syntax ourselves, since print_operand
2452 doesn't deal with the addresses we want to use. Fix this later. */
2454 rtx addr = XEXP (operands[1], 0);
2455 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2457 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2459 operands[1] = XEXP (addr, 0);
2460 gcc_assert (GET_CODE (operands[0]) == REG
2461 && GET_CODE (operands[1]) == REG);
2463 if (!reg_overlap_mentioned_p (high_reg, addr))
2465 /* No overlap between high target register and address
2466 register. (We do this in a non-obvious way to
2467 save a register file writeback) */
2468 if (GET_CODE (addr) == POST_INC)
2469 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2470 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2472 else
2474 /* This is an undefined situation. We should load into the
2475 address register *and* update that register. Probably
2476 we don't need to handle this at all. */
2477 if (GET_CODE (addr) == POST_INC)
2478 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2479 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2482 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2484 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2486 operands[1] = XEXP (addr, 0);
2487 gcc_assert (GET_CODE (operands[0]) == REG
2488 && GET_CODE (operands[1]) == REG);
2490 if (!reg_overlap_mentioned_p (high_reg, addr))
2492 /* No overlap between high target register and address
2493 register. (We do this in a non-obvious way to
2494 save a register file writeback) */
2495 if (GET_CODE (addr) == PRE_INC)
2496 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2497 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2499 else
2501 /* This is an undefined situation. We should load into the
2502 address register *and* update that register. Probably
2503 we don't need to handle this at all. */
2504 if (GET_CODE (addr) == PRE_INC)
2505 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2506 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2509 else if (GET_CODE (addr) == PLUS
2510 && GET_CODE (XEXP (addr, 0)) == MULT)
2512 rtx xoperands[4];
2513 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2515 if (!reg_overlap_mentioned_p (high_reg, addr))
2517 xoperands[0] = high_reg;
2518 xoperands[1] = XEXP (addr, 1);
2519 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2520 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2521 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2522 xoperands);
2523 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2525 else
2527 xoperands[0] = high_reg;
2528 xoperands[1] = XEXP (addr, 1);
2529 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2530 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2531 output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2532 xoperands);
2533 return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2538 /* If an operand is an unoffsettable memory ref, find a register
2539 we can increment temporarily to make it refer to the second word. */
2541 if (optype0 == MEMOP)
2542 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2544 if (optype1 == MEMOP)
2545 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2547 /* Ok, we can do one word at a time.
2548 Normally we do the low-numbered word first.
2550 In either case, set up in LATEHALF the operands to use
2551 for the high-numbered word and in some cases alter the
2552 operands in OPERANDS to be suitable for the low-numbered word. */
2554 if (optype0 == REGOP)
2555 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2556 else if (optype0 == OFFSOP)
2557 latehalf[0] = adjust_address (operands[0], SImode, 4);
2558 else
2559 latehalf[0] = operands[0];
2561 if (optype1 == REGOP)
2562 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2563 else if (optype1 == OFFSOP)
2564 latehalf[1] = adjust_address (operands[1], SImode, 4);
2565 else if (optype1 == CNSTOP)
2566 split_double (operands[1], &operands[1], &latehalf[1]);
2567 else
2568 latehalf[1] = operands[1];
2570 /* If the first move would clobber the source of the second one,
2571 do them in the other order.
2573 This can happen in two cases:
2575 mem -> register where the first half of the destination register
2576 is the same register used in the memory's address. Reload
2577 can create such insns.
2579 mem in this case will be either register indirect or register
2580 indirect plus a valid offset.
2582 register -> register move where REGNO(dst) == REGNO(src + 1)
2583 someone (Tim/Tege?) claimed this can happen for parameter loads.
2585 Handle mem -> register case first. */
2586 if (optype0 == REGOP
2587 && (optype1 == MEMOP || optype1 == OFFSOP)
2588 && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2589 operands[1], 0))
2591 /* Do the late half first. */
2592 if (addreg1)
2593 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2594 output_asm_insn (singlemove_string (latehalf), latehalf);
2596 /* Then clobber. */
2597 if (addreg1)
2598 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2599 return singlemove_string (operands);
2602 /* Now handle register -> register case. */
2603 if (optype0 == REGOP && optype1 == REGOP
2604 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2606 output_asm_insn (singlemove_string (latehalf), latehalf);
2607 return singlemove_string (operands);
2610 /* Normal case: do the two words, low-numbered first. */
2612 output_asm_insn (singlemove_string (operands), operands);
2614 /* Make any unoffsettable addresses point at high-numbered word. */
2615 if (addreg0)
2616 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2617 if (addreg1)
2618 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2620 /* Do that word. */
2621 output_asm_insn (singlemove_string (latehalf), latehalf);
2623 /* Undo the adds we just did. */
2624 if (addreg0)
2625 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2626 if (addreg1)
2627 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2629 return "";
2632 const char *
2633 output_fp_move_double (rtx *operands)
2635 if (FP_REG_P (operands[0]))
2637 if (FP_REG_P (operands[1])
2638 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2639 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2640 else
2641 output_asm_insn ("fldd%F1 %1,%0", operands);
2643 else if (FP_REG_P (operands[1]))
2645 output_asm_insn ("fstd%F0 %1,%0", operands);
2647 else
2649 rtx xoperands[2];
2651 gcc_assert (operands[1] == CONST0_RTX (GET_MODE (operands[0])));
2653 /* This is a pain. You have to be prepared to deal with an
2654 arbitrary address here including pre/post increment/decrement.
2656 so avoid this in the MD. */
2657 gcc_assert (GET_CODE (operands[0]) == REG);
2659 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2660 xoperands[0] = operands[0];
2661 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2663 return "";
2666 /* Return a REG that occurs in ADDR with coefficient 1.
2667 ADDR can be effectively incremented by incrementing REG. */
2669 static rtx
2670 find_addr_reg (rtx addr)
2672 while (GET_CODE (addr) == PLUS)
2674 if (GET_CODE (XEXP (addr, 0)) == REG)
2675 addr = XEXP (addr, 0);
2676 else if (GET_CODE (XEXP (addr, 1)) == REG)
2677 addr = XEXP (addr, 1);
2678 else if (CONSTANT_P (XEXP (addr, 0)))
2679 addr = XEXP (addr, 1);
2680 else if (CONSTANT_P (XEXP (addr, 1)))
2681 addr = XEXP (addr, 0);
2682 else
2683 gcc_unreachable ();
2685 gcc_assert (GET_CODE (addr) == REG);
2686 return addr;
2689 /* Emit code to perform a block move.
2691 OPERANDS[0] is the destination pointer as a REG, clobbered.
2692 OPERANDS[1] is the source pointer as a REG, clobbered.
2693 OPERANDS[2] is a register for temporary storage.
2694 OPERANDS[3] is a register for temporary storage.
2695 OPERANDS[4] is the size as a CONST_INT
2696 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2697 OPERANDS[6] is another temporary register. */
2699 const char *
2700 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2702 int align = INTVAL (operands[5]);
2703 unsigned long n_bytes = INTVAL (operands[4]);
2705 /* We can't move more than a word at a time because the PA
2706 has no longer integer move insns. (Could use fp mem ops?) */
2707 if (align > (TARGET_64BIT ? 8 : 4))
2708 align = (TARGET_64BIT ? 8 : 4);
2710 /* Note that we know each loop below will execute at least twice
2711 (else we would have open-coded the copy). */
2712 switch (align)
2714 case 8:
2715 /* Pre-adjust the loop counter. */
2716 operands[4] = GEN_INT (n_bytes - 16);
2717 output_asm_insn ("ldi %4,%2", operands);
2719 /* Copying loop. */
2720 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2721 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2722 output_asm_insn ("std,ma %3,8(%0)", operands);
2723 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2724 output_asm_insn ("std,ma %6,8(%0)", operands);
2726 /* Handle the residual. There could be up to 7 bytes of
2727 residual to copy! */
2728 if (n_bytes % 16 != 0)
2730 operands[4] = GEN_INT (n_bytes % 8);
2731 if (n_bytes % 16 >= 8)
2732 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2733 if (n_bytes % 8 != 0)
2734 output_asm_insn ("ldd 0(%1),%6", operands);
2735 if (n_bytes % 16 >= 8)
2736 output_asm_insn ("std,ma %3,8(%0)", operands);
2737 if (n_bytes % 8 != 0)
2738 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2740 return "";
2742 case 4:
2743 /* Pre-adjust the loop counter. */
2744 operands[4] = GEN_INT (n_bytes - 8);
2745 output_asm_insn ("ldi %4,%2", operands);
2747 /* Copying loop. */
2748 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2749 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2750 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2751 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2752 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2754 /* Handle the residual. There could be up to 7 bytes of
2755 residual to copy! */
2756 if (n_bytes % 8 != 0)
2758 operands[4] = GEN_INT (n_bytes % 4);
2759 if (n_bytes % 8 >= 4)
2760 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2761 if (n_bytes % 4 != 0)
2762 output_asm_insn ("ldw 0(%1),%6", operands);
2763 if (n_bytes % 8 >= 4)
2764 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2765 if (n_bytes % 4 != 0)
2766 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2768 return "";
2770 case 2:
2771 /* Pre-adjust the loop counter. */
2772 operands[4] = GEN_INT (n_bytes - 4);
2773 output_asm_insn ("ldi %4,%2", operands);
2775 /* Copying loop. */
2776 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2777 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2778 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2779 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2780 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2782 /* Handle the residual. */
2783 if (n_bytes % 4 != 0)
2785 if (n_bytes % 4 >= 2)
2786 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2787 if (n_bytes % 2 != 0)
2788 output_asm_insn ("ldb 0(%1),%6", operands);
2789 if (n_bytes % 4 >= 2)
2790 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2791 if (n_bytes % 2 != 0)
2792 output_asm_insn ("stb %6,0(%0)", operands);
2794 return "";
2796 case 1:
2797 /* Pre-adjust the loop counter. */
2798 operands[4] = GEN_INT (n_bytes - 2);
2799 output_asm_insn ("ldi %4,%2", operands);
2801 /* Copying loop. */
2802 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2803 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2804 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2805 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2806 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2808 /* Handle the residual. */
2809 if (n_bytes % 2 != 0)
2811 output_asm_insn ("ldb 0(%1),%3", operands);
2812 output_asm_insn ("stb %3,0(%0)", operands);
2814 return "";
2816 default:
2817 gcc_unreachable ();
2821 /* Count the number of insns necessary to handle this block move.
2823 Basic structure is the same as emit_block_move, except that we
2824 count insns rather than emit them. */
2826 static int
2827 compute_movmem_length (rtx insn)
2829 rtx pat = PATTERN (insn);
2830 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2831 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2832 unsigned int n_insns = 0;
2834 /* We can't move more than four bytes at a time because the PA
2835 has no longer integer move insns. (Could use fp mem ops?) */
2836 if (align > (TARGET_64BIT ? 8 : 4))
2837 align = (TARGET_64BIT ? 8 : 4);
2839 /* The basic copying loop. */
2840 n_insns = 6;
2842 /* Residuals. */
2843 if (n_bytes % (2 * align) != 0)
2845 if ((n_bytes % (2 * align)) >= align)
2846 n_insns += 2;
2848 if ((n_bytes % align) != 0)
2849 n_insns += 2;
2852 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2853 return n_insns * 4;
2856 /* Emit code to perform a block clear.
2858 OPERANDS[0] is the destination pointer as a REG, clobbered.
2859 OPERANDS[1] is a register for temporary storage.
2860 OPERANDS[2] is the size as a CONST_INT
2861 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
2863 const char *
2864 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2866 int align = INTVAL (operands[3]);
2867 unsigned long n_bytes = INTVAL (operands[2]);
2869 /* We can't clear more than a word at a time because the PA
2870 has no longer integer move insns. */
2871 if (align > (TARGET_64BIT ? 8 : 4))
2872 align = (TARGET_64BIT ? 8 : 4);
2874 /* Note that we know each loop below will execute at least twice
2875 (else we would have open-coded the copy). */
2876 switch (align)
2878 case 8:
2879 /* Pre-adjust the loop counter. */
2880 operands[2] = GEN_INT (n_bytes - 16);
2881 output_asm_insn ("ldi %2,%1", operands);
2883 /* Loop. */
2884 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2885 output_asm_insn ("addib,>= -16,%1,.-4", operands);
2886 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2888 /* Handle the residual. There could be up to 7 bytes of
2889 residual to copy! */
2890 if (n_bytes % 16 != 0)
2892 operands[2] = GEN_INT (n_bytes % 8);
2893 if (n_bytes % 16 >= 8)
2894 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2895 if (n_bytes % 8 != 0)
2896 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
2898 return "";
2900 case 4:
2901 /* Pre-adjust the loop counter. */
2902 operands[2] = GEN_INT (n_bytes - 8);
2903 output_asm_insn ("ldi %2,%1", operands);
2905 /* Loop. */
2906 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2907 output_asm_insn ("addib,>= -8,%1,.-4", operands);
2908 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2910 /* Handle the residual. There could be up to 7 bytes of
2911 residual to copy! */
2912 if (n_bytes % 8 != 0)
2914 operands[2] = GEN_INT (n_bytes % 4);
2915 if (n_bytes % 8 >= 4)
2916 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2917 if (n_bytes % 4 != 0)
2918 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
2920 return "";
2922 case 2:
2923 /* Pre-adjust the loop counter. */
2924 operands[2] = GEN_INT (n_bytes - 4);
2925 output_asm_insn ("ldi %2,%1", operands);
2927 /* Loop. */
2928 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2929 output_asm_insn ("addib,>= -4,%1,.-4", operands);
2930 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2932 /* Handle the residual. */
2933 if (n_bytes % 4 != 0)
2935 if (n_bytes % 4 >= 2)
2936 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
2937 if (n_bytes % 2 != 0)
2938 output_asm_insn ("stb %%r0,0(%0)", operands);
2940 return "";
2942 case 1:
2943 /* Pre-adjust the loop counter. */
2944 operands[2] = GEN_INT (n_bytes - 2);
2945 output_asm_insn ("ldi %2,%1", operands);
2947 /* Loop. */
2948 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2949 output_asm_insn ("addib,>= -2,%1,.-4", operands);
2950 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
2952 /* Handle the residual. */
2953 if (n_bytes % 2 != 0)
2954 output_asm_insn ("stb %%r0,0(%0)", operands);
2956 return "";
2958 default:
2959 gcc_unreachable ();
2963 /* Count the number of insns necessary to handle this block move.
2965 Basic structure is the same as emit_block_move, except that we
2966 count insns rather than emit them. */
2968 static int
2969 compute_clrmem_length (rtx insn)
2971 rtx pat = PATTERN (insn);
2972 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
2973 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
2974 unsigned int n_insns = 0;
2976 /* We can't clear more than a word at a time because the PA
2977 has no longer integer move insns. */
2978 if (align > (TARGET_64BIT ? 8 : 4))
2979 align = (TARGET_64BIT ? 8 : 4);
2981 /* The basic loop. */
2982 n_insns = 4;
2984 /* Residuals. */
2985 if (n_bytes % (2 * align) != 0)
2987 if ((n_bytes % (2 * align)) >= align)
2988 n_insns++;
2990 if ((n_bytes % align) != 0)
2991 n_insns++;
2994 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2995 return n_insns * 4;
2999 const char *
3000 output_and (rtx *operands)
3002 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3004 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3005 int ls0, ls1, ms0, p, len;
3007 for (ls0 = 0; ls0 < 32; ls0++)
3008 if ((mask & (1 << ls0)) == 0)
3009 break;
3011 for (ls1 = ls0; ls1 < 32; ls1++)
3012 if ((mask & (1 << ls1)) != 0)
3013 break;
3015 for (ms0 = ls1; ms0 < 32; ms0++)
3016 if ((mask & (1 << ms0)) == 0)
3017 break;
3019 gcc_assert (ms0 == 32);
3021 if (ls1 == 32)
3023 len = ls0;
3025 gcc_assert (len);
3027 operands[2] = GEN_INT (len);
3028 return "{extru|extrw,u} %1,31,%2,%0";
3030 else
3032 /* We could use this `depi' for the case above as well, but `depi'
3033 requires one more register file access than an `extru'. */
3035 p = 31 - ls0;
3036 len = ls1 - ls0;
3038 operands[2] = GEN_INT (p);
3039 operands[3] = GEN_INT (len);
3040 return "{depi|depwi} 0,%2,%3,%0";
3043 else
3044 return "and %1,%2,%0";
3047 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3048 storing the result in operands[0]. */
3049 const char *
3050 output_64bit_and (rtx *operands)
3052 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3054 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3055 int ls0, ls1, ms0, p, len;
3057 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
3058 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
3059 break;
3061 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
3062 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
3063 break;
3065 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
3066 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
3067 break;
3069 gcc_assert (ms0 == HOST_BITS_PER_WIDE_INT);
3071 if (ls1 == HOST_BITS_PER_WIDE_INT)
3073 len = ls0;
3075 gcc_assert (len);
3077 operands[2] = GEN_INT (len);
3078 return "extrd,u %1,63,%2,%0";
3080 else
3082 /* We could use this `depi' for the case above as well, but `depi'
3083 requires one more register file access than an `extru'. */
3085 p = 63 - ls0;
3086 len = ls1 - ls0;
3088 operands[2] = GEN_INT (p);
3089 operands[3] = GEN_INT (len);
3090 return "depdi 0,%2,%3,%0";
3093 else
3094 return "and %1,%2,%0";
3097 const char *
3098 output_ior (rtx *operands)
3100 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3101 int bs0, bs1, p, len;
3103 if (INTVAL (operands[2]) == 0)
3104 return "copy %1,%0";
3106 for (bs0 = 0; bs0 < 32; bs0++)
3107 if ((mask & (1 << bs0)) != 0)
3108 break;
3110 for (bs1 = bs0; bs1 < 32; bs1++)
3111 if ((mask & (1 << bs1)) == 0)
3112 break;
3114 gcc_assert (bs1 == 32 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
3116 p = 31 - bs0;
3117 len = bs1 - bs0;
3119 operands[2] = GEN_INT (p);
3120 operands[3] = GEN_INT (len);
3121 return "{depi|depwi} -1,%2,%3,%0";
3124 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3125 storing the result in operands[0]. */
3126 const char *
3127 output_64bit_ior (rtx *operands)
3129 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3130 int bs0, bs1, p, len;
3132 if (INTVAL (operands[2]) == 0)
3133 return "copy %1,%0";
3135 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3136 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3137 break;
3139 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3140 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3141 break;
3143 gcc_assert (bs1 == HOST_BITS_PER_WIDE_INT
3144 || ((unsigned HOST_WIDE_INT) 1 << bs1) > mask);
3146 p = 63 - bs0;
3147 len = bs1 - bs0;
3149 operands[2] = GEN_INT (p);
3150 operands[3] = GEN_INT (len);
3151 return "depdi -1,%2,%3,%0";
3154 /* Target hook for assembling integer objects. This code handles
3155 aligned SI and DI integers specially since function references
3156 must be preceded by P%. */
3158 static bool
3159 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3161 if (size == UNITS_PER_WORD
3162 && aligned_p
3163 && function_label_operand (x, VOIDmode))
3165 fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
3166 output_addr_const (asm_out_file, x);
3167 fputc ('\n', asm_out_file);
3168 return true;
3170 return default_assemble_integer (x, size, aligned_p);
3173 /* Output an ascii string. */
3174 void
3175 output_ascii (FILE *file, const char *p, int size)
3177 int i;
3178 int chars_output;
3179 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3181 /* The HP assembler can only take strings of 256 characters at one
3182 time. This is a limitation on input line length, *not* the
3183 length of the string. Sigh. Even worse, it seems that the
3184 restriction is in number of input characters (see \xnn &
3185 \whatever). So we have to do this very carefully. */
3187 fputs ("\t.STRING \"", file);
3189 chars_output = 0;
3190 for (i = 0; i < size; i += 4)
3192 int co = 0;
3193 int io = 0;
3194 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3196 register unsigned int c = (unsigned char) p[i + io];
3198 if (c == '\"' || c == '\\')
3199 partial_output[co++] = '\\';
3200 if (c >= ' ' && c < 0177)
3201 partial_output[co++] = c;
3202 else
3204 unsigned int hexd;
3205 partial_output[co++] = '\\';
3206 partial_output[co++] = 'x';
3207 hexd = c / 16 - 0 + '0';
3208 if (hexd > '9')
3209 hexd -= '9' - 'a' + 1;
3210 partial_output[co++] = hexd;
3211 hexd = c % 16 - 0 + '0';
3212 if (hexd > '9')
3213 hexd -= '9' - 'a' + 1;
3214 partial_output[co++] = hexd;
3217 if (chars_output + co > 243)
3219 fputs ("\"\n\t.STRING \"", file);
3220 chars_output = 0;
3222 fwrite (partial_output, 1, (size_t) co, file);
3223 chars_output += co;
3224 co = 0;
3226 fputs ("\"\n", file);
3229 /* Try to rewrite floating point comparisons & branches to avoid
3230 useless add,tr insns.
3232 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3233 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3234 first attempt to remove useless add,tr insns. It is zero
3235 for the second pass as reorg sometimes leaves bogus REG_DEAD
3236 notes lying around.
3238 When CHECK_NOTES is zero we can only eliminate add,tr insns
3239 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3240 instructions. */
3241 static void
3242 remove_useless_addtr_insns (int check_notes)
3244 rtx insn;
3245 static int pass = 0;
3247 /* This is fairly cheap, so always run it when optimizing. */
3248 if (optimize > 0)
3250 int fcmp_count = 0;
3251 int fbranch_count = 0;
3253 /* Walk all the insns in this function looking for fcmp & fbranch
3254 instructions. Keep track of how many of each we find. */
3255 for (insn = get_insns (); insn; insn = next_insn (insn))
3257 rtx tmp;
3259 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3260 if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3261 continue;
3263 tmp = PATTERN (insn);
3265 /* It must be a set. */
3266 if (GET_CODE (tmp) != SET)
3267 continue;
3269 /* If the destination is CCFP, then we've found an fcmp insn. */
3270 tmp = SET_DEST (tmp);
3271 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3273 fcmp_count++;
3274 continue;
3277 tmp = PATTERN (insn);
3278 /* If this is an fbranch instruction, bump the fbranch counter. */
3279 if (GET_CODE (tmp) == SET
3280 && SET_DEST (tmp) == pc_rtx
3281 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3282 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3283 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3284 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3286 fbranch_count++;
3287 continue;
3292 /* Find all floating point compare + branch insns. If possible,
3293 reverse the comparison & the branch to avoid add,tr insns. */
3294 for (insn = get_insns (); insn; insn = next_insn (insn))
3296 rtx tmp, next;
3298 /* Ignore anything that isn't an INSN. */
3299 if (GET_CODE (insn) != INSN)
3300 continue;
3302 tmp = PATTERN (insn);
3304 /* It must be a set. */
3305 if (GET_CODE (tmp) != SET)
3306 continue;
3308 /* The destination must be CCFP, which is register zero. */
3309 tmp = SET_DEST (tmp);
3310 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3311 continue;
3313 /* INSN should be a set of CCFP.
3315 See if the result of this insn is used in a reversed FP
3316 conditional branch. If so, reverse our condition and
3317 the branch. Doing so avoids useless add,tr insns. */
3318 next = next_insn (insn);
3319 while (next)
3321 /* Jumps, calls and labels stop our search. */
3322 if (GET_CODE (next) == JUMP_INSN
3323 || GET_CODE (next) == CALL_INSN
3324 || GET_CODE (next) == CODE_LABEL)
3325 break;
3327 /* As does another fcmp insn. */
3328 if (GET_CODE (next) == INSN
3329 && GET_CODE (PATTERN (next)) == SET
3330 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3331 && REGNO (SET_DEST (PATTERN (next))) == 0)
3332 break;
3334 next = next_insn (next);
3337 /* Is NEXT_INSN a branch? */
3338 if (next
3339 && GET_CODE (next) == JUMP_INSN)
3341 rtx pattern = PATTERN (next);
3343 /* If it a reversed fp conditional branch (e.g. uses add,tr)
3344 and CCFP dies, then reverse our conditional and the branch
3345 to avoid the add,tr. */
3346 if (GET_CODE (pattern) == SET
3347 && SET_DEST (pattern) == pc_rtx
3348 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3349 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3350 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3351 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3352 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3353 && (fcmp_count == fbranch_count
3354 || (check_notes
3355 && find_regno_note (next, REG_DEAD, 0))))
3357 /* Reverse the branch. */
3358 tmp = XEXP (SET_SRC (pattern), 1);
3359 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3360 XEXP (SET_SRC (pattern), 2) = tmp;
3361 INSN_CODE (next) = -1;
3363 /* Reverse our condition. */
3364 tmp = PATTERN (insn);
3365 PUT_CODE (XEXP (tmp, 1),
3366 (reverse_condition_maybe_unordered
3367 (GET_CODE (XEXP (tmp, 1)))));
3373 pass = !pass;
3377 /* You may have trouble believing this, but this is the 32 bit HP-PA
3378 stack layout. Wow.
3380 Offset Contents
3382 Variable arguments (optional; any number may be allocated)
3384 SP-(4*(N+9)) arg word N
3386 SP-56 arg word 5
3387 SP-52 arg word 4
3389 Fixed arguments (must be allocated; may remain unused)
3391 SP-48 arg word 3
3392 SP-44 arg word 2
3393 SP-40 arg word 1
3394 SP-36 arg word 0
3396 Frame Marker
3398 SP-32 External Data Pointer (DP)
3399 SP-28 External sr4
3400 SP-24 External/stub RP (RP')
3401 SP-20 Current RP
3402 SP-16 Static Link
3403 SP-12 Clean up
3404 SP-8 Calling Stub RP (RP'')
3405 SP-4 Previous SP
3407 Top of Frame
3409 SP-0 Stack Pointer (points to next available address)
3413 /* This function saves registers as follows. Registers marked with ' are
3414 this function's registers (as opposed to the previous function's).
3415 If a frame_pointer isn't needed, r4 is saved as a general register;
3416 the space for the frame pointer is still allocated, though, to keep
3417 things simple.
3420 Top of Frame
3422 SP (FP') Previous FP
3423 SP + 4 Alignment filler (sigh)
3424 SP + 8 Space for locals reserved here.
3428 SP + n All call saved register used.
3432 SP + o All call saved fp registers used.
3436 SP + p (SP') points to next available address.
3440 /* Global variables set by output_function_prologue(). */
3441 /* Size of frame. Need to know this to emit return insns from
3442 leaf procedures. */
3443 static HOST_WIDE_INT actual_fsize, local_fsize;
3444 static int save_fregs;
3446 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3447 Handle case where DISP > 8k by using the add_high_const patterns.
3449 Note in DISP > 8k case, we will leave the high part of the address
3450 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3452 static void
3453 store_reg (int reg, HOST_WIDE_INT disp, int base)
3455 rtx insn, dest, src, basereg;
3457 src = gen_rtx_REG (word_mode, reg);
3458 basereg = gen_rtx_REG (Pmode, base);
3459 if (VAL_14_BITS_P (disp))
3461 dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3462 insn = emit_move_insn (dest, src);
3464 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3466 rtx delta = GEN_INT (disp);
3467 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3469 emit_move_insn (tmpreg, delta);
3470 insn = emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3471 if (DO_FRAME_NOTES)
3473 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
3474 gen_rtx_SET (VOIDmode, tmpreg,
3475 gen_rtx_PLUS (Pmode, basereg, delta)));
3476 RTX_FRAME_RELATED_P (insn) = 1;
3478 dest = gen_rtx_MEM (word_mode, tmpreg);
3479 insn = emit_move_insn (dest, src);
3481 else
3483 rtx delta = GEN_INT (disp);
3484 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3485 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3487 emit_move_insn (tmpreg, high);
3488 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3489 insn = emit_move_insn (dest, src);
3490 if (DO_FRAME_NOTES)
3491 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
3492 gen_rtx_SET (VOIDmode,
3493 gen_rtx_MEM (word_mode,
3494 gen_rtx_PLUS (word_mode,
3495 basereg,
3496 delta)),
3497 src));
3500 if (DO_FRAME_NOTES)
3501 RTX_FRAME_RELATED_P (insn) = 1;
3504 /* Emit RTL to store REG at the memory location specified by BASE and then
3505 add MOD to BASE. MOD must be <= 8k. */
3507 static void
3508 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3510 rtx insn, basereg, srcreg, delta;
3512 gcc_assert (VAL_14_BITS_P (mod));
3514 basereg = gen_rtx_REG (Pmode, base);
3515 srcreg = gen_rtx_REG (word_mode, reg);
3516 delta = GEN_INT (mod);
3518 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3519 if (DO_FRAME_NOTES)
3521 RTX_FRAME_RELATED_P (insn) = 1;
3523 /* RTX_FRAME_RELATED_P must be set on each frame related set
3524 in a parallel with more than one element. */
3525 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3526 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3530 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
3531 where DISP > 8k by using the add_high_const patterns. NOTE indicates
3532 whether to add a frame note or not.
3534 In the DISP > 8k case, we leave the high part of the address in %r1.
3535 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
3537 static void
3538 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3540 rtx insn;
3542 if (VAL_14_BITS_P (disp))
3544 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3545 plus_constant (gen_rtx_REG (Pmode, base), disp));
3547 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3549 rtx basereg = gen_rtx_REG (Pmode, base);
3550 rtx delta = GEN_INT (disp);
3551 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3553 emit_move_insn (tmpreg, delta);
3554 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3555 gen_rtx_PLUS (Pmode, tmpreg, basereg));
3556 if (DO_FRAME_NOTES)
3557 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
3558 gen_rtx_SET (VOIDmode, tmpreg,
3559 gen_rtx_PLUS (Pmode, basereg, delta)));
3561 else
3563 rtx basereg = gen_rtx_REG (Pmode, base);
3564 rtx delta = GEN_INT (disp);
3565 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3567 emit_move_insn (tmpreg,
3568 gen_rtx_PLUS (Pmode, basereg,
3569 gen_rtx_HIGH (Pmode, delta)));
3570 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3571 gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3574 if (DO_FRAME_NOTES && note)
3575 RTX_FRAME_RELATED_P (insn) = 1;
3578 HOST_WIDE_INT
3579 compute_frame_size (HOST_WIDE_INT size, int *fregs_live)
3581 int freg_saved = 0;
3582 int i, j;
3584 /* The code in hppa_expand_prologue and hppa_expand_epilogue must
3585 be consistent with the rounding and size calculation done here.
3586 Change them at the same time. */
3588 /* We do our own stack alignment. First, round the size of the
3589 stack locals up to a word boundary. */
3590 size = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3592 /* Space for previous frame pointer + filler. If any frame is
3593 allocated, we need to add in the STARTING_FRAME_OFFSET. We
3594 waste some space here for the sake of HP compatibility. The
3595 first slot is only used when the frame pointer is needed. */
3596 if (size || frame_pointer_needed)
3597 size += STARTING_FRAME_OFFSET;
3599 /* If the current function calls __builtin_eh_return, then we need
3600 to allocate stack space for registers that will hold data for
3601 the exception handler. */
3602 if (DO_FRAME_NOTES && crtl->calls_eh_return)
3604 unsigned int i;
3606 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
3607 continue;
3608 size += i * UNITS_PER_WORD;
3611 /* Account for space used by the callee general register saves. */
3612 for (i = 18, j = frame_pointer_needed ? 4 : 3; i >= j; i--)
3613 if (df_regs_ever_live_p (i))
3614 size += UNITS_PER_WORD;
3616 /* Account for space used by the callee floating point register saves. */
3617 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3618 if (df_regs_ever_live_p (i)
3619 || (!TARGET_64BIT && df_regs_ever_live_p (i + 1)))
3621 freg_saved = 1;
3623 /* We always save both halves of the FP register, so always
3624 increment the frame size by 8 bytes. */
3625 size += 8;
3628 /* If any of the floating registers are saved, account for the
3629 alignment needed for the floating point register save block. */
3630 if (freg_saved)
3632 size = (size + 7) & ~7;
3633 if (fregs_live)
3634 *fregs_live = 1;
3637 /* The various ABIs include space for the outgoing parameters in the
3638 size of the current function's stack frame. We don't need to align
3639 for the outgoing arguments as their alignment is set by the final
3640 rounding for the frame as a whole. */
3641 size += crtl->outgoing_args_size;
3643 /* Allocate space for the fixed frame marker. This space must be
3644 allocated for any function that makes calls or allocates
3645 stack space. */
3646 if (!current_function_is_leaf || size)
3647 size += TARGET_64BIT ? 48 : 32;
3649 /* Finally, round to the preferred stack boundary. */
3650 return ((size + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)
3651 & ~(PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1));
3654 /* Generate the assembly code for function entry. FILE is a stdio
3655 stream to output the code to. SIZE is an int: how many units of
3656 temporary storage to allocate.
3658 Refer to the array `regs_ever_live' to determine which registers to
3659 save; `regs_ever_live[I]' is nonzero if register number I is ever
3660 used in the function. This function is responsible for knowing
3661 which registers should not be saved even if used. */
3663 /* On HP-PA, move-double insns between fpu and cpu need an 8-byte block
3664 of memory. If any fpu reg is used in the function, we allocate
3665 such a block here, at the bottom of the frame, just in case it's needed.
3667 If this function is a leaf procedure, then we may choose not
3668 to do a "save" insn. The decision about whether or not
3669 to do this is made in regclass.c. */
3671 static void
3672 pa_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3674 /* The function's label and associated .PROC must never be
3675 separated and must be output *after* any profiling declarations
3676 to avoid changing spaces/subspaces within a procedure. */
3677 ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3678 fputs ("\t.PROC\n", file);
3680 /* hppa_expand_prologue does the dirty work now. We just need
3681 to output the assembler directives which denote the start
3682 of a function. */
3683 fprintf (file, "\t.CALLINFO FRAME=" HOST_WIDE_INT_PRINT_DEC, actual_fsize);
3684 if (current_function_is_leaf)
3685 fputs (",NO_CALLS", file);
3686 else
3687 fputs (",CALLS", file);
3688 if (rp_saved)
3689 fputs (",SAVE_RP", file);
3691 /* The SAVE_SP flag is used to indicate that register %r3 is stored
3692 at the beginning of the frame and that it is used as the frame
3693 pointer for the frame. We do this because our current frame
3694 layout doesn't conform to that specified in the HP runtime
3695 documentation and we need a way to indicate to programs such as
3696 GDB where %r3 is saved. The SAVE_SP flag was chosen because it
3697 isn't used by HP compilers but is supported by the assembler.
3698 However, SAVE_SP is supposed to indicate that the previous stack
3699 pointer has been saved in the frame marker. */
3700 if (frame_pointer_needed)
3701 fputs (",SAVE_SP", file);
3703 /* Pass on information about the number of callee register saves
3704 performed in the prologue.
3706 The compiler is supposed to pass the highest register number
3707 saved, the assembler then has to adjust that number before
3708 entering it into the unwind descriptor (to account for any
3709 caller saved registers with lower register numbers than the
3710 first callee saved register). */
3711 if (gr_saved)
3712 fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
3714 if (fr_saved)
3715 fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
3717 fputs ("\n\t.ENTRY\n", file);
3719 remove_useless_addtr_insns (0);
3722 void
3723 hppa_expand_prologue (void)
3725 int merge_sp_adjust_with_store = 0;
3726 HOST_WIDE_INT size = get_frame_size ();
3727 HOST_WIDE_INT offset;
3728 int i;
3729 rtx insn, tmpreg;
3731 gr_saved = 0;
3732 fr_saved = 0;
3733 save_fregs = 0;
3735 /* Compute total size for frame pointer, filler, locals and rounding to
3736 the next word boundary. Similar code appears in compute_frame_size
3737 and must be changed in tandem with this code. */
3738 local_fsize = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3739 if (local_fsize || frame_pointer_needed)
3740 local_fsize += STARTING_FRAME_OFFSET;
3742 actual_fsize = compute_frame_size (size, &save_fregs);
3743 if (flag_stack_usage)
3744 current_function_static_stack_size = actual_fsize;
3746 /* Compute a few things we will use often. */
3747 tmpreg = gen_rtx_REG (word_mode, 1);
3749 /* Save RP first. The calling conventions manual states RP will
3750 always be stored into the caller's frame at sp - 20 or sp - 16
3751 depending on which ABI is in use. */
3752 if (df_regs_ever_live_p (2) || crtl->calls_eh_return)
3754 store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM);
3755 rp_saved = true;
3757 else
3758 rp_saved = false;
3760 /* Allocate the local frame and set up the frame pointer if needed. */
3761 if (actual_fsize != 0)
3763 if (frame_pointer_needed)
3765 /* Copy the old frame pointer temporarily into %r1. Set up the
3766 new stack pointer, then store away the saved old frame pointer
3767 into the stack at sp and at the same time update the stack
3768 pointer by actual_fsize bytes. Two versions, first
3769 handles small (<8k) frames. The second handles large (>=8k)
3770 frames. */
3771 insn = emit_move_insn (tmpreg, hard_frame_pointer_rtx);
3772 if (DO_FRAME_NOTES)
3773 RTX_FRAME_RELATED_P (insn) = 1;
3775 insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
3776 if (DO_FRAME_NOTES)
3777 RTX_FRAME_RELATED_P (insn) = 1;
3779 if (VAL_14_BITS_P (actual_fsize))
3780 store_reg_modify (STACK_POINTER_REGNUM, 1, actual_fsize);
3781 else
3783 /* It is incorrect to store the saved frame pointer at *sp,
3784 then increment sp (writes beyond the current stack boundary).
3786 So instead use stwm to store at *sp and post-increment the
3787 stack pointer as an atomic operation. Then increment sp to
3788 finish allocating the new frame. */
3789 HOST_WIDE_INT adjust1 = 8192 - 64;
3790 HOST_WIDE_INT adjust2 = actual_fsize - adjust1;
3792 store_reg_modify (STACK_POINTER_REGNUM, 1, adjust1);
3793 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3794 adjust2, 1);
3797 /* We set SAVE_SP in frames that need a frame pointer. Thus,
3798 we need to store the previous stack pointer (frame pointer)
3799 into the frame marker on targets that use the HP unwind
3800 library. This allows the HP unwind library to be used to
3801 unwind GCC frames. However, we are not fully compatible
3802 with the HP library because our frame layout differs from
3803 that specified in the HP runtime specification.
3805 We don't want a frame note on this instruction as the frame
3806 marker moves during dynamic stack allocation.
3808 This instruction also serves as a blockage to prevent
3809 register spills from being scheduled before the stack
3810 pointer is raised. This is necessary as we store
3811 registers using the frame pointer as a base register,
3812 and the frame pointer is set before sp is raised. */
3813 if (TARGET_HPUX_UNWIND_LIBRARY)
3815 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx,
3816 GEN_INT (TARGET_64BIT ? -8 : -4));
3818 emit_move_insn (gen_rtx_MEM (word_mode, addr),
3819 hard_frame_pointer_rtx);
3821 else
3822 emit_insn (gen_blockage ());
3824 /* no frame pointer needed. */
3825 else
3827 /* In some cases we can perform the first callee register save
3828 and allocating the stack frame at the same time. If so, just
3829 make a note of it and defer allocating the frame until saving
3830 the callee registers. */
3831 if (VAL_14_BITS_P (actual_fsize) && local_fsize == 0)
3832 merge_sp_adjust_with_store = 1;
3833 /* Can not optimize. Adjust the stack frame by actual_fsize
3834 bytes. */
3835 else
3836 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3837 actual_fsize, 1);
3841 /* Normal register save.
3843 Do not save the frame pointer in the frame_pointer_needed case. It
3844 was done earlier. */
3845 if (frame_pointer_needed)
3847 offset = local_fsize;
3849 /* Saving the EH return data registers in the frame is the simplest
3850 way to get the frame unwind information emitted. We put them
3851 just before the general registers. */
3852 if (DO_FRAME_NOTES && crtl->calls_eh_return)
3854 unsigned int i, regno;
3856 for (i = 0; ; ++i)
3858 regno = EH_RETURN_DATA_REGNO (i);
3859 if (regno == INVALID_REGNUM)
3860 break;
3862 store_reg (regno, offset, HARD_FRAME_POINTER_REGNUM);
3863 offset += UNITS_PER_WORD;
3867 for (i = 18; i >= 4; i--)
3868 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
3870 store_reg (i, offset, HARD_FRAME_POINTER_REGNUM);
3871 offset += UNITS_PER_WORD;
3872 gr_saved++;
3874 /* Account for %r3 which is saved in a special place. */
3875 gr_saved++;
3877 /* No frame pointer needed. */
3878 else
3880 offset = local_fsize - actual_fsize;
3882 /* Saving the EH return data registers in the frame is the simplest
3883 way to get the frame unwind information emitted. */
3884 if (DO_FRAME_NOTES && crtl->calls_eh_return)
3886 unsigned int i, regno;
3888 for (i = 0; ; ++i)
3890 regno = EH_RETURN_DATA_REGNO (i);
3891 if (regno == INVALID_REGNUM)
3892 break;
3894 /* If merge_sp_adjust_with_store is nonzero, then we can
3895 optimize the first save. */
3896 if (merge_sp_adjust_with_store)
3898 store_reg_modify (STACK_POINTER_REGNUM, regno, -offset);
3899 merge_sp_adjust_with_store = 0;
3901 else
3902 store_reg (regno, offset, STACK_POINTER_REGNUM);
3903 offset += UNITS_PER_WORD;
3907 for (i = 18; i >= 3; i--)
3908 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
3910 /* If merge_sp_adjust_with_store is nonzero, then we can
3911 optimize the first GR save. */
3912 if (merge_sp_adjust_with_store)
3914 store_reg_modify (STACK_POINTER_REGNUM, i, -offset);
3915 merge_sp_adjust_with_store = 0;
3917 else
3918 store_reg (i, offset, STACK_POINTER_REGNUM);
3919 offset += UNITS_PER_WORD;
3920 gr_saved++;
3923 /* If we wanted to merge the SP adjustment with a GR save, but we never
3924 did any GR saves, then just emit the adjustment here. */
3925 if (merge_sp_adjust_with_store)
3926 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3927 actual_fsize, 1);
3930 /* The hppa calling conventions say that %r19, the pic offset
3931 register, is saved at sp - 32 (in this function's frame)
3932 when generating PIC code. FIXME: What is the correct thing
3933 to do for functions which make no calls and allocate no
3934 frame? Do we need to allocate a frame, or can we just omit
3935 the save? For now we'll just omit the save.
3937 We don't want a note on this insn as the frame marker can
3938 move if there is a dynamic stack allocation. */
3939 if (flag_pic && actual_fsize != 0 && !TARGET_64BIT)
3941 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx, GEN_INT (-32));
3943 emit_move_insn (gen_rtx_MEM (word_mode, addr), pic_offset_table_rtx);
3947 /* Align pointer properly (doubleword boundary). */
3948 offset = (offset + 7) & ~7;
3950 /* Floating point register store. */
3951 if (save_fregs)
3953 rtx base;
3955 /* First get the frame or stack pointer to the start of the FP register
3956 save area. */
3957 if (frame_pointer_needed)
3959 set_reg_plus_d (1, HARD_FRAME_POINTER_REGNUM, offset, 0);
3960 base = hard_frame_pointer_rtx;
3962 else
3964 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
3965 base = stack_pointer_rtx;
3968 /* Now actually save the FP registers. */
3969 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3971 if (df_regs_ever_live_p (i)
3972 || (! TARGET_64BIT && df_regs_ever_live_p (i + 1)))
3974 rtx addr, insn, reg;
3975 addr = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
3976 reg = gen_rtx_REG (DFmode, i);
3977 insn = emit_move_insn (addr, reg);
3978 if (DO_FRAME_NOTES)
3980 RTX_FRAME_RELATED_P (insn) = 1;
3981 if (TARGET_64BIT)
3983 rtx mem = gen_rtx_MEM (DFmode,
3984 plus_constant (base, offset));
3985 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
3986 gen_rtx_SET (VOIDmode, mem, reg));
3988 else
3990 rtx meml = gen_rtx_MEM (SFmode,
3991 plus_constant (base, offset));
3992 rtx memr = gen_rtx_MEM (SFmode,
3993 plus_constant (base, offset + 4));
3994 rtx regl = gen_rtx_REG (SFmode, i);
3995 rtx regr = gen_rtx_REG (SFmode, i + 1);
3996 rtx setl = gen_rtx_SET (VOIDmode, meml, regl);
3997 rtx setr = gen_rtx_SET (VOIDmode, memr, regr);
3998 rtvec vec;
4000 RTX_FRAME_RELATED_P (setl) = 1;
4001 RTX_FRAME_RELATED_P (setr) = 1;
4002 vec = gen_rtvec (2, setl, setr);
4003 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
4004 gen_rtx_SEQUENCE (VOIDmode, vec));
4007 offset += GET_MODE_SIZE (DFmode);
4008 fr_saved++;
4014 /* Emit RTL to load REG from the memory location specified by BASE+DISP.
4015 Handle case where DISP > 8k by using the add_high_const patterns. */
4017 static void
4018 load_reg (int reg, HOST_WIDE_INT disp, int base)
4020 rtx dest = gen_rtx_REG (word_mode, reg);
4021 rtx basereg = gen_rtx_REG (Pmode, base);
4022 rtx src;
4024 if (VAL_14_BITS_P (disp))
4025 src = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
4026 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
4028 rtx delta = GEN_INT (disp);
4029 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4031 emit_move_insn (tmpreg, delta);
4032 if (TARGET_DISABLE_INDEXING)
4034 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4035 src = gen_rtx_MEM (word_mode, tmpreg);
4037 else
4038 src = gen_rtx_MEM (word_mode, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4040 else
4042 rtx delta = GEN_INT (disp);
4043 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
4044 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4046 emit_move_insn (tmpreg, high);
4047 src = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
4050 emit_move_insn (dest, src);
4053 /* Update the total code bytes output to the text section. */
4055 static void
4056 update_total_code_bytes (unsigned int nbytes)
4058 if ((TARGET_PORTABLE_RUNTIME || !TARGET_GAS || !TARGET_SOM)
4059 && !IN_NAMED_SECTION_P (cfun->decl))
4061 unsigned int old_total = total_code_bytes;
4063 total_code_bytes += nbytes;
4065 /* Be prepared to handle overflows. */
4066 if (old_total > total_code_bytes)
4067 total_code_bytes = UINT_MAX;
4071 /* This function generates the assembly code for function exit.
4072 Args are as for output_function_prologue ().
4074 The function epilogue should not depend on the current stack
4075 pointer! It should use the frame pointer only. This is mandatory
4076 because of alloca; we also take advantage of it to omit stack
4077 adjustments before returning. */
4079 static void
4080 pa_output_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4082 rtx insn = get_last_insn ();
4084 last_address = 0;
4086 /* hppa_expand_epilogue does the dirty work now. We just need
4087 to output the assembler directives which denote the end
4088 of a function.
4090 To make debuggers happy, emit a nop if the epilogue was completely
4091 eliminated due to a volatile call as the last insn in the
4092 current function. That way the return address (in %r2) will
4093 always point to a valid instruction in the current function. */
4095 /* Get the last real insn. */
4096 if (GET_CODE (insn) == NOTE)
4097 insn = prev_real_insn (insn);
4099 /* If it is a sequence, then look inside. */
4100 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
4101 insn = XVECEXP (PATTERN (insn), 0, 0);
4103 /* If insn is a CALL_INSN, then it must be a call to a volatile
4104 function (otherwise there would be epilogue insns). */
4105 if (insn && GET_CODE (insn) == CALL_INSN)
4107 fputs ("\tnop\n", file);
4108 last_address += 4;
4111 fputs ("\t.EXIT\n\t.PROCEND\n", file);
4113 if (TARGET_SOM && TARGET_GAS)
4115 /* We done with this subspace except possibly for some additional
4116 debug information. Forget that we are in this subspace to ensure
4117 that the next function is output in its own subspace. */
4118 in_section = NULL;
4119 cfun->machine->in_nsubspa = 2;
4122 if (INSN_ADDRESSES_SET_P ())
4124 insn = get_last_nonnote_insn ();
4125 last_address += INSN_ADDRESSES (INSN_UID (insn));
4126 if (INSN_P (insn))
4127 last_address += insn_default_length (insn);
4128 last_address = ((last_address + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
4129 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
4131 else
4132 last_address = UINT_MAX;
4134 /* Finally, update the total number of code bytes output so far. */
4135 update_total_code_bytes (last_address);
4138 void
4139 hppa_expand_epilogue (void)
4141 rtx tmpreg;
4142 HOST_WIDE_INT offset;
4143 HOST_WIDE_INT ret_off = 0;
4144 int i;
4145 int merge_sp_adjust_with_load = 0;
4147 /* We will use this often. */
4148 tmpreg = gen_rtx_REG (word_mode, 1);
4150 /* Try to restore RP early to avoid load/use interlocks when
4151 RP gets used in the return (bv) instruction. This appears to still
4152 be necessary even when we schedule the prologue and epilogue. */
4153 if (rp_saved)
4155 ret_off = TARGET_64BIT ? -16 : -20;
4156 if (frame_pointer_needed)
4158 load_reg (2, ret_off, HARD_FRAME_POINTER_REGNUM);
4159 ret_off = 0;
4161 else
4163 /* No frame pointer, and stack is smaller than 8k. */
4164 if (VAL_14_BITS_P (ret_off - actual_fsize))
4166 load_reg (2, ret_off - actual_fsize, STACK_POINTER_REGNUM);
4167 ret_off = 0;
4172 /* General register restores. */
4173 if (frame_pointer_needed)
4175 offset = local_fsize;
4177 /* If the current function calls __builtin_eh_return, then we need
4178 to restore the saved EH data registers. */
4179 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4181 unsigned int i, regno;
4183 for (i = 0; ; ++i)
4185 regno = EH_RETURN_DATA_REGNO (i);
4186 if (regno == INVALID_REGNUM)
4187 break;
4189 load_reg (regno, offset, HARD_FRAME_POINTER_REGNUM);
4190 offset += UNITS_PER_WORD;
4194 for (i = 18; i >= 4; i--)
4195 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
4197 load_reg (i, offset, HARD_FRAME_POINTER_REGNUM);
4198 offset += UNITS_PER_WORD;
4201 else
4203 offset = local_fsize - actual_fsize;
4205 /* If the current function calls __builtin_eh_return, then we need
4206 to restore the saved EH data registers. */
4207 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4209 unsigned int i, regno;
4211 for (i = 0; ; ++i)
4213 regno = EH_RETURN_DATA_REGNO (i);
4214 if (regno == INVALID_REGNUM)
4215 break;
4217 /* Only for the first load.
4218 merge_sp_adjust_with_load holds the register load
4219 with which we will merge the sp adjustment. */
4220 if (merge_sp_adjust_with_load == 0
4221 && local_fsize == 0
4222 && VAL_14_BITS_P (-actual_fsize))
4223 merge_sp_adjust_with_load = regno;
4224 else
4225 load_reg (regno, offset, STACK_POINTER_REGNUM);
4226 offset += UNITS_PER_WORD;
4230 for (i = 18; i >= 3; i--)
4232 if (df_regs_ever_live_p (i) && ! call_used_regs[i])
4234 /* Only for the first load.
4235 merge_sp_adjust_with_load holds the register load
4236 with which we will merge the sp adjustment. */
4237 if (merge_sp_adjust_with_load == 0
4238 && local_fsize == 0
4239 && VAL_14_BITS_P (-actual_fsize))
4240 merge_sp_adjust_with_load = i;
4241 else
4242 load_reg (i, offset, STACK_POINTER_REGNUM);
4243 offset += UNITS_PER_WORD;
4248 /* Align pointer properly (doubleword boundary). */
4249 offset = (offset + 7) & ~7;
4251 /* FP register restores. */
4252 if (save_fregs)
4254 /* Adjust the register to index off of. */
4255 if (frame_pointer_needed)
4256 set_reg_plus_d (1, HARD_FRAME_POINTER_REGNUM, offset, 0);
4257 else
4258 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4260 /* Actually do the restores now. */
4261 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4262 if (df_regs_ever_live_p (i)
4263 || (! TARGET_64BIT && df_regs_ever_live_p (i + 1)))
4265 rtx src = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
4266 rtx dest = gen_rtx_REG (DFmode, i);
4267 emit_move_insn (dest, src);
4271 /* Emit a blockage insn here to keep these insns from being moved to
4272 an earlier spot in the epilogue, or into the main instruction stream.
4274 This is necessary as we must not cut the stack back before all the
4275 restores are finished. */
4276 emit_insn (gen_blockage ());
4278 /* Reset stack pointer (and possibly frame pointer). The stack
4279 pointer is initially set to fp + 64 to avoid a race condition. */
4280 if (frame_pointer_needed)
4282 rtx delta = GEN_INT (-64);
4284 set_reg_plus_d (STACK_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM, 64, 0);
4285 emit_insn (gen_pre_load (hard_frame_pointer_rtx,
4286 stack_pointer_rtx, delta));
4288 /* If we were deferring a callee register restore, do it now. */
4289 else if (merge_sp_adjust_with_load)
4291 rtx delta = GEN_INT (-actual_fsize);
4292 rtx dest = gen_rtx_REG (word_mode, merge_sp_adjust_with_load);
4294 emit_insn (gen_pre_load (dest, stack_pointer_rtx, delta));
4296 else if (actual_fsize != 0)
4297 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4298 - actual_fsize, 0);
4300 /* If we haven't restored %r2 yet (no frame pointer, and a stack
4301 frame greater than 8k), do so now. */
4302 if (ret_off != 0)
4303 load_reg (2, ret_off, STACK_POINTER_REGNUM);
4305 if (DO_FRAME_NOTES && crtl->calls_eh_return)
4307 rtx sa = EH_RETURN_STACKADJ_RTX;
4309 emit_insn (gen_blockage ());
4310 emit_insn (TARGET_64BIT
4311 ? gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, sa)
4312 : gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, sa));
4317 hppa_pic_save_rtx (void)
4319 return get_hard_reg_initial_val (word_mode, PIC_OFFSET_TABLE_REGNUM);
4322 #ifndef NO_DEFERRED_PROFILE_COUNTERS
4323 #define NO_DEFERRED_PROFILE_COUNTERS 0
4324 #endif
4327 /* Vector of funcdef numbers. */
4328 static VEC(int,heap) *funcdef_nos;
4330 /* Output deferred profile counters. */
4331 static void
4332 output_deferred_profile_counters (void)
4334 unsigned int i;
4335 int align, n;
4337 if (VEC_empty (int, funcdef_nos))
4338 return;
4340 switch_to_section (data_section);
4341 align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
4342 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
4344 for (i = 0; VEC_iterate (int, funcdef_nos, i, n); i++)
4346 targetm.asm_out.internal_label (asm_out_file, "LP", n);
4347 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, align, 1);
4350 VEC_free (int, heap, funcdef_nos);
4353 void
4354 hppa_profile_hook (int label_no)
4356 /* We use SImode for the address of the function in both 32 and
4357 64-bit code to avoid having to provide DImode versions of the
4358 lcla2 and load_offset_label_address insn patterns. */
4359 rtx reg = gen_reg_rtx (SImode);
4360 rtx label_rtx = gen_label_rtx ();
4361 rtx begin_label_rtx, call_insn;
4362 char begin_label_name[16];
4364 ASM_GENERATE_INTERNAL_LABEL (begin_label_name, FUNC_BEGIN_PROLOG_LABEL,
4365 label_no);
4366 begin_label_rtx = gen_rtx_SYMBOL_REF (SImode, ggc_strdup (begin_label_name));
4368 if (TARGET_64BIT)
4369 emit_move_insn (arg_pointer_rtx,
4370 gen_rtx_PLUS (word_mode, virtual_outgoing_args_rtx,
4371 GEN_INT (64)));
4373 emit_move_insn (gen_rtx_REG (word_mode, 26), gen_rtx_REG (word_mode, 2));
4375 /* The address of the function is loaded into %r25 with an instruction-
4376 relative sequence that avoids the use of relocations. The sequence
4377 is split so that the load_offset_label_address instruction can
4378 occupy the delay slot of the call to _mcount. */
4379 if (TARGET_PA_20)
4380 emit_insn (gen_lcla2 (reg, label_rtx));
4381 else
4382 emit_insn (gen_lcla1 (reg, label_rtx));
4384 emit_insn (gen_load_offset_label_address (gen_rtx_REG (SImode, 25),
4385 reg, begin_label_rtx, label_rtx));
4387 #if !NO_DEFERRED_PROFILE_COUNTERS
4389 rtx count_label_rtx, addr, r24;
4390 char count_label_name[16];
4392 VEC_safe_push (int, heap, funcdef_nos, label_no);
4393 ASM_GENERATE_INTERNAL_LABEL (count_label_name, "LP", label_no);
4394 count_label_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (count_label_name));
4396 addr = force_reg (Pmode, count_label_rtx);
4397 r24 = gen_rtx_REG (Pmode, 24);
4398 emit_move_insn (r24, addr);
4400 call_insn =
4401 emit_call_insn (gen_call (gen_rtx_MEM (Pmode,
4402 gen_rtx_SYMBOL_REF (Pmode,
4403 "_mcount")),
4404 GEN_INT (TARGET_64BIT ? 24 : 12)));
4406 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), r24);
4408 #else
4410 call_insn =
4411 emit_call_insn (gen_call (gen_rtx_MEM (Pmode,
4412 gen_rtx_SYMBOL_REF (Pmode,
4413 "_mcount")),
4414 GEN_INT (TARGET_64BIT ? 16 : 8)));
4416 #endif
4418 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 25));
4419 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 26));
4421 /* Indicate the _mcount call cannot throw, nor will it execute a
4422 non-local goto. */
4423 make_reg_eh_region_note_nothrow_nononlocal (call_insn);
4426 /* Fetch the return address for the frame COUNT steps up from
4427 the current frame, after the prologue. FRAMEADDR is the
4428 frame pointer of the COUNT frame.
4430 We want to ignore any export stub remnants here. To handle this,
4431 we examine the code at the return address, and if it is an export
4432 stub, we return a memory rtx for the stub return address stored
4433 at frame-24.
4435 The value returned is used in two different ways:
4437 1. To find a function's caller.
4439 2. To change the return address for a function.
4441 This function handles most instances of case 1; however, it will
4442 fail if there are two levels of stubs to execute on the return
4443 path. The only way I believe that can happen is if the return value
4444 needs a parameter relocation, which never happens for C code.
4446 This function handles most instances of case 2; however, it will
4447 fail if we did not originally have stub code on the return path
4448 but will need stub code on the new return path. This can happen if
4449 the caller & callee are both in the main program, but the new
4450 return location is in a shared library. */
4453 return_addr_rtx (int count, rtx frameaddr)
4455 rtx label;
4456 rtx rp;
4457 rtx saved_rp;
4458 rtx ins;
4460 /* Instruction stream at the normal return address for the export stub:
4462 0x4bc23fd1 | stub+8: ldw -18(sr0,sp),rp
4463 0x004010a1 | stub+12: ldsid (sr0,rp),r1
4464 0x00011820 | stub+16: mtsp r1,sr0
4465 0xe0400002 | stub+20: be,n 0(sr0,rp)
4467 0xe0400002 must be specified as -532676606 so that it won't be
4468 rejected as an invalid immediate operand on 64-bit hosts. */
4470 HOST_WIDE_INT insns[4] = {0x4bc23fd1, 0x004010a1, 0x00011820, -532676606};
4471 int i;
4473 if (count != 0)
4474 return NULL_RTX;
4476 rp = get_hard_reg_initial_val (Pmode, 2);
4478 if (TARGET_64BIT || TARGET_NO_SPACE_REGS)
4479 return rp;
4481 /* If there is no export stub then just use the value saved from
4482 the return pointer register. */
4484 saved_rp = gen_reg_rtx (Pmode);
4485 emit_move_insn (saved_rp, rp);
4487 /* Get pointer to the instruction stream. We have to mask out the
4488 privilege level from the two low order bits of the return address
4489 pointer here so that ins will point to the start of the first
4490 instruction that would have been executed if we returned. */
4491 ins = copy_to_reg (gen_rtx_AND (Pmode, rp, MASK_RETURN_ADDR));
4492 label = gen_label_rtx ();
4494 /* Check the instruction stream at the normal return address for the
4495 export stub. If it is an export stub, than our return address is
4496 really in -24[frameaddr]. */
4498 for (i = 0; i < 3; i++)
4500 rtx op0 = gen_rtx_MEM (SImode, plus_constant (ins, i * 4));
4501 rtx op1 = GEN_INT (insns[i]);
4502 emit_cmp_and_jump_insns (op0, op1, NE, NULL, SImode, 0, label);
4505 /* Here we know that our return address points to an export
4506 stub. We don't want to return the address of the export stub,
4507 but rather the return address of the export stub. That return
4508 address is stored at -24[frameaddr]. */
4510 emit_move_insn (saved_rp,
4511 gen_rtx_MEM (Pmode,
4512 memory_address (Pmode,
4513 plus_constant (frameaddr,
4514 -24))));
4516 emit_label (label);
4518 return saved_rp;
4521 void
4522 emit_bcond_fp (rtx operands[])
4524 enum rtx_code code = GET_CODE (operands[0]);
4525 rtx operand0 = operands[1];
4526 rtx operand1 = operands[2];
4527 rtx label = operands[3];
4529 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_REG (CCFPmode, 0),
4530 gen_rtx_fmt_ee (code, CCFPmode, operand0, operand1)));
4532 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4533 gen_rtx_IF_THEN_ELSE (VOIDmode,
4534 gen_rtx_fmt_ee (NE,
4535 VOIDmode,
4536 gen_rtx_REG (CCFPmode, 0),
4537 const0_rtx),
4538 gen_rtx_LABEL_REF (VOIDmode, label),
4539 pc_rtx)));
4543 /* Adjust the cost of a scheduling dependency. Return the new cost of
4544 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
4546 static int
4547 pa_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
4549 enum attr_type attr_type;
4551 /* Don't adjust costs for a pa8000 chip, also do not adjust any
4552 true dependencies as they are described with bypasses now. */
4553 if (pa_cpu >= PROCESSOR_8000 || REG_NOTE_KIND (link) == 0)
4554 return cost;
4556 if (! recog_memoized (insn))
4557 return 0;
4559 attr_type = get_attr_type (insn);
4561 switch (REG_NOTE_KIND (link))
4563 case REG_DEP_ANTI:
4564 /* Anti dependency; DEP_INSN reads a register that INSN writes some
4565 cycles later. */
4567 if (attr_type == TYPE_FPLOAD)
4569 rtx pat = PATTERN (insn);
4570 rtx dep_pat = PATTERN (dep_insn);
4571 if (GET_CODE (pat) == PARALLEL)
4573 /* This happens for the fldXs,mb patterns. */
4574 pat = XVECEXP (pat, 0, 0);
4576 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4577 /* If this happens, we have to extend this to schedule
4578 optimally. Return 0 for now. */
4579 return 0;
4581 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4583 if (! recog_memoized (dep_insn))
4584 return 0;
4585 switch (get_attr_type (dep_insn))
4587 case TYPE_FPALU:
4588 case TYPE_FPMULSGL:
4589 case TYPE_FPMULDBL:
4590 case TYPE_FPDIVSGL:
4591 case TYPE_FPDIVDBL:
4592 case TYPE_FPSQRTSGL:
4593 case TYPE_FPSQRTDBL:
4594 /* A fpload can't be issued until one cycle before a
4595 preceding arithmetic operation has finished if
4596 the target of the fpload is any of the sources
4597 (or destination) of the arithmetic operation. */
4598 return insn_default_latency (dep_insn) - 1;
4600 default:
4601 return 0;
4605 else if (attr_type == TYPE_FPALU)
4607 rtx pat = PATTERN (insn);
4608 rtx dep_pat = PATTERN (dep_insn);
4609 if (GET_CODE (pat) == PARALLEL)
4611 /* This happens for the fldXs,mb patterns. */
4612 pat = XVECEXP (pat, 0, 0);
4614 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4615 /* If this happens, we have to extend this to schedule
4616 optimally. Return 0 for now. */
4617 return 0;
4619 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4621 if (! recog_memoized (dep_insn))
4622 return 0;
4623 switch (get_attr_type (dep_insn))
4625 case TYPE_FPDIVSGL:
4626 case TYPE_FPDIVDBL:
4627 case TYPE_FPSQRTSGL:
4628 case TYPE_FPSQRTDBL:
4629 /* An ALU flop can't be issued until two cycles before a
4630 preceding divide or sqrt operation has finished if
4631 the target of the ALU flop is any of the sources
4632 (or destination) of the divide or sqrt operation. */
4633 return insn_default_latency (dep_insn) - 2;
4635 default:
4636 return 0;
4641 /* For other anti dependencies, the cost is 0. */
4642 return 0;
4644 case REG_DEP_OUTPUT:
4645 /* Output dependency; DEP_INSN writes a register that INSN writes some
4646 cycles later. */
4647 if (attr_type == TYPE_FPLOAD)
4649 rtx pat = PATTERN (insn);
4650 rtx dep_pat = PATTERN (dep_insn);
4651 if (GET_CODE (pat) == PARALLEL)
4653 /* This happens for the fldXs,mb patterns. */
4654 pat = XVECEXP (pat, 0, 0);
4656 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4657 /* If this happens, we have to extend this to schedule
4658 optimally. Return 0 for now. */
4659 return 0;
4661 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4663 if (! recog_memoized (dep_insn))
4664 return 0;
4665 switch (get_attr_type (dep_insn))
4667 case TYPE_FPALU:
4668 case TYPE_FPMULSGL:
4669 case TYPE_FPMULDBL:
4670 case TYPE_FPDIVSGL:
4671 case TYPE_FPDIVDBL:
4672 case TYPE_FPSQRTSGL:
4673 case TYPE_FPSQRTDBL:
4674 /* A fpload can't be issued until one cycle before a
4675 preceding arithmetic operation has finished if
4676 the target of the fpload is the destination of the
4677 arithmetic operation.
4679 Exception: For PA7100LC, PA7200 and PA7300, the cost
4680 is 3 cycles, unless they bundle together. We also
4681 pay the penalty if the second insn is a fpload. */
4682 return insn_default_latency (dep_insn) - 1;
4684 default:
4685 return 0;
4689 else if (attr_type == TYPE_FPALU)
4691 rtx pat = PATTERN (insn);
4692 rtx dep_pat = PATTERN (dep_insn);
4693 if (GET_CODE (pat) == PARALLEL)
4695 /* This happens for the fldXs,mb patterns. */
4696 pat = XVECEXP (pat, 0, 0);
4698 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4699 /* If this happens, we have to extend this to schedule
4700 optimally. Return 0 for now. */
4701 return 0;
4703 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4705 if (! recog_memoized (dep_insn))
4706 return 0;
4707 switch (get_attr_type (dep_insn))
4709 case TYPE_FPDIVSGL:
4710 case TYPE_FPDIVDBL:
4711 case TYPE_FPSQRTSGL:
4712 case TYPE_FPSQRTDBL:
4713 /* An ALU flop can't be issued until two cycles before a
4714 preceding divide or sqrt operation has finished if
4715 the target of the ALU flop is also the target of
4716 the divide or sqrt operation. */
4717 return insn_default_latency (dep_insn) - 2;
4719 default:
4720 return 0;
4725 /* For other output dependencies, the cost is 0. */
4726 return 0;
4728 default:
4729 gcc_unreachable ();
4733 /* Adjust scheduling priorities. We use this to try and keep addil
4734 and the next use of %r1 close together. */
4735 static int
4736 pa_adjust_priority (rtx insn, int priority)
4738 rtx set = single_set (insn);
4739 rtx src, dest;
4740 if (set)
4742 src = SET_SRC (set);
4743 dest = SET_DEST (set);
4744 if (GET_CODE (src) == LO_SUM
4745 && symbolic_operand (XEXP (src, 1), VOIDmode)
4746 && ! read_only_operand (XEXP (src, 1), VOIDmode))
4747 priority >>= 3;
4749 else if (GET_CODE (src) == MEM
4750 && GET_CODE (XEXP (src, 0)) == LO_SUM
4751 && symbolic_operand (XEXP (XEXP (src, 0), 1), VOIDmode)
4752 && ! read_only_operand (XEXP (XEXP (src, 0), 1), VOIDmode))
4753 priority >>= 1;
4755 else if (GET_CODE (dest) == MEM
4756 && GET_CODE (XEXP (dest, 0)) == LO_SUM
4757 && symbolic_operand (XEXP (XEXP (dest, 0), 1), VOIDmode)
4758 && ! read_only_operand (XEXP (XEXP (dest, 0), 1), VOIDmode))
4759 priority >>= 3;
4761 return priority;
4764 /* The 700 can only issue a single insn at a time.
4765 The 7XXX processors can issue two insns at a time.
4766 The 8000 can issue 4 insns at a time. */
4767 static int
4768 pa_issue_rate (void)
4770 switch (pa_cpu)
4772 case PROCESSOR_700: return 1;
4773 case PROCESSOR_7100: return 2;
4774 case PROCESSOR_7100LC: return 2;
4775 case PROCESSOR_7200: return 2;
4776 case PROCESSOR_7300: return 2;
4777 case PROCESSOR_8000: return 4;
4779 default:
4780 gcc_unreachable ();
4786 /* Return any length adjustment needed by INSN which already has its length
4787 computed as LENGTH. Return zero if no adjustment is necessary.
4789 For the PA: function calls, millicode calls, and backwards short
4790 conditional branches with unfilled delay slots need an adjustment by +1
4791 (to account for the NOP which will be inserted into the instruction stream).
4793 Also compute the length of an inline block move here as it is too
4794 complicated to express as a length attribute in pa.md. */
4796 pa_adjust_insn_length (rtx insn, int length)
4798 rtx pat = PATTERN (insn);
4800 /* Jumps inside switch tables which have unfilled delay slots need
4801 adjustment. */
4802 if (GET_CODE (insn) == JUMP_INSN
4803 && GET_CODE (pat) == PARALLEL
4804 && get_attr_type (insn) == TYPE_BTABLE_BRANCH)
4805 return 4;
4806 /* Millicode insn with an unfilled delay slot. */
4807 else if (GET_CODE (insn) == INSN
4808 && GET_CODE (pat) != SEQUENCE
4809 && GET_CODE (pat) != USE
4810 && GET_CODE (pat) != CLOBBER
4811 && get_attr_type (insn) == TYPE_MILLI)
4812 return 4;
4813 /* Block move pattern. */
4814 else if (GET_CODE (insn) == INSN
4815 && GET_CODE (pat) == PARALLEL
4816 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
4817 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
4818 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 1)) == MEM
4819 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode
4820 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 1)) == BLKmode)
4821 return compute_movmem_length (insn) - 4;
4822 /* Block clear pattern. */
4823 else if (GET_CODE (insn) == INSN
4824 && GET_CODE (pat) == PARALLEL
4825 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
4826 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
4827 && XEXP (XVECEXP (pat, 0, 0), 1) == const0_rtx
4828 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode)
4829 return compute_clrmem_length (insn) - 4;
4830 /* Conditional branch with an unfilled delay slot. */
4831 else if (GET_CODE (insn) == JUMP_INSN && ! simplejump_p (insn))
4833 /* Adjust a short backwards conditional with an unfilled delay slot. */
4834 if (GET_CODE (pat) == SET
4835 && length == 4
4836 && JUMP_LABEL (insn) != NULL_RTX
4837 && ! forward_branch_p (insn))
4838 return 4;
4839 else if (GET_CODE (pat) == PARALLEL
4840 && get_attr_type (insn) == TYPE_PARALLEL_BRANCH
4841 && length == 4)
4842 return 4;
4843 /* Adjust dbra insn with short backwards conditional branch with
4844 unfilled delay slot -- only for case where counter is in a
4845 general register register. */
4846 else if (GET_CODE (pat) == PARALLEL
4847 && GET_CODE (XVECEXP (pat, 0, 1)) == SET
4848 && GET_CODE (XEXP (XVECEXP (pat, 0, 1), 0)) == REG
4849 && ! FP_REG_P (XEXP (XVECEXP (pat, 0, 1), 0))
4850 && length == 4
4851 && ! forward_branch_p (insn))
4852 return 4;
4853 else
4854 return 0;
4856 return 0;
4859 /* Implement the TARGET_PRINT_OPERAND_PUNCT_VALID_P hook. */
4861 static bool
4862 pa_print_operand_punct_valid_p (unsigned char code)
4864 if (code == '@'
4865 || code == '#'
4866 || code == '*'
4867 || code == '^')
4868 return true;
4870 return false;
4873 /* Print operand X (an rtx) in assembler syntax to file FILE.
4874 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
4875 For `%' followed by punctuation, CODE is the punctuation and X is null. */
4877 void
4878 print_operand (FILE *file, rtx x, int code)
4880 switch (code)
4882 case '#':
4883 /* Output a 'nop' if there's nothing for the delay slot. */
4884 if (dbr_sequence_length () == 0)
4885 fputs ("\n\tnop", file);
4886 return;
4887 case '*':
4888 /* Output a nullification completer if there's nothing for the */
4889 /* delay slot or nullification is requested. */
4890 if (dbr_sequence_length () == 0 ||
4891 (final_sequence &&
4892 INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))))
4893 fputs (",n", file);
4894 return;
4895 case 'R':
4896 /* Print out the second register name of a register pair.
4897 I.e., R (6) => 7. */
4898 fputs (reg_names[REGNO (x) + 1], file);
4899 return;
4900 case 'r':
4901 /* A register or zero. */
4902 if (x == const0_rtx
4903 || (x == CONST0_RTX (DFmode))
4904 || (x == CONST0_RTX (SFmode)))
4906 fputs ("%r0", file);
4907 return;
4909 else
4910 break;
4911 case 'f':
4912 /* A register or zero (floating point). */
4913 if (x == const0_rtx
4914 || (x == CONST0_RTX (DFmode))
4915 || (x == CONST0_RTX (SFmode)))
4917 fputs ("%fr0", file);
4918 return;
4920 else
4921 break;
4922 case 'A':
4924 rtx xoperands[2];
4926 xoperands[0] = XEXP (XEXP (x, 0), 0);
4927 xoperands[1] = XVECEXP (XEXP (XEXP (x, 0), 1), 0, 0);
4928 output_global_address (file, xoperands[1], 0);
4929 fprintf (file, "(%s)", reg_names [REGNO (xoperands[0])]);
4930 return;
4933 case 'C': /* Plain (C)ondition */
4934 case 'X':
4935 switch (GET_CODE (x))
4937 case EQ:
4938 fputs ("=", file); break;
4939 case NE:
4940 fputs ("<>", file); break;
4941 case GT:
4942 fputs (">", file); break;
4943 case GE:
4944 fputs (">=", file); break;
4945 case GEU:
4946 fputs (">>=", file); break;
4947 case GTU:
4948 fputs (">>", file); break;
4949 case LT:
4950 fputs ("<", file); break;
4951 case LE:
4952 fputs ("<=", file); break;
4953 case LEU:
4954 fputs ("<<=", file); break;
4955 case LTU:
4956 fputs ("<<", file); break;
4957 default:
4958 gcc_unreachable ();
4960 return;
4961 case 'N': /* Condition, (N)egated */
4962 switch (GET_CODE (x))
4964 case EQ:
4965 fputs ("<>", file); break;
4966 case NE:
4967 fputs ("=", file); break;
4968 case GT:
4969 fputs ("<=", file); break;
4970 case GE:
4971 fputs ("<", file); break;
4972 case GEU:
4973 fputs ("<<", file); break;
4974 case GTU:
4975 fputs ("<<=", file); break;
4976 case LT:
4977 fputs (">=", file); break;
4978 case LE:
4979 fputs (">", file); break;
4980 case LEU:
4981 fputs (">>", file); break;
4982 case LTU:
4983 fputs (">>=", file); break;
4984 default:
4985 gcc_unreachable ();
4987 return;
4988 /* For floating point comparisons. Note that the output
4989 predicates are the complement of the desired mode. The
4990 conditions for GT, GE, LT, LE and LTGT cause an invalid
4991 operation exception if the result is unordered and this
4992 exception is enabled in the floating-point status register. */
4993 case 'Y':
4994 switch (GET_CODE (x))
4996 case EQ:
4997 fputs ("!=", file); break;
4998 case NE:
4999 fputs ("=", file); break;
5000 case GT:
5001 fputs ("!>", file); break;
5002 case GE:
5003 fputs ("!>=", file); break;
5004 case LT:
5005 fputs ("!<", file); break;
5006 case LE:
5007 fputs ("!<=", file); break;
5008 case LTGT:
5009 fputs ("!<>", file); break;
5010 case UNLE:
5011 fputs ("!?<=", file); break;
5012 case UNLT:
5013 fputs ("!?<", file); break;
5014 case UNGE:
5015 fputs ("!?>=", file); break;
5016 case UNGT:
5017 fputs ("!?>", file); break;
5018 case UNEQ:
5019 fputs ("!?=", file); break;
5020 case UNORDERED:
5021 fputs ("!?", file); break;
5022 case ORDERED:
5023 fputs ("?", file); break;
5024 default:
5025 gcc_unreachable ();
5027 return;
5028 case 'S': /* Condition, operands are (S)wapped. */
5029 switch (GET_CODE (x))
5031 case EQ:
5032 fputs ("=", file); break;
5033 case NE:
5034 fputs ("<>", file); break;
5035 case GT:
5036 fputs ("<", file); break;
5037 case GE:
5038 fputs ("<=", file); break;
5039 case GEU:
5040 fputs ("<<=", file); break;
5041 case GTU:
5042 fputs ("<<", file); break;
5043 case LT:
5044 fputs (">", file); break;
5045 case LE:
5046 fputs (">=", file); break;
5047 case LEU:
5048 fputs (">>=", file); break;
5049 case LTU:
5050 fputs (">>", file); break;
5051 default:
5052 gcc_unreachable ();
5054 return;
5055 case 'B': /* Condition, (B)oth swapped and negate. */
5056 switch (GET_CODE (x))
5058 case EQ:
5059 fputs ("<>", file); break;
5060 case NE:
5061 fputs ("=", file); break;
5062 case GT:
5063 fputs (">=", file); break;
5064 case GE:
5065 fputs (">", file); break;
5066 case GEU:
5067 fputs (">>", file); break;
5068 case GTU:
5069 fputs (">>=", file); break;
5070 case LT:
5071 fputs ("<=", file); break;
5072 case LE:
5073 fputs ("<", file); break;
5074 case LEU:
5075 fputs ("<<", file); break;
5076 case LTU:
5077 fputs ("<<=", file); break;
5078 default:
5079 gcc_unreachable ();
5081 return;
5082 case 'k':
5083 gcc_assert (GET_CODE (x) == CONST_INT);
5084 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~INTVAL (x));
5085 return;
5086 case 'Q':
5087 gcc_assert (GET_CODE (x) == CONST_INT);
5088 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 64 - (INTVAL (x) & 63));
5089 return;
5090 case 'L':
5091 gcc_assert (GET_CODE (x) == CONST_INT);
5092 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 32 - (INTVAL (x) & 31));
5093 return;
5094 case 'O':
5095 gcc_assert (GET_CODE (x) == CONST_INT && exact_log2 (INTVAL (x)) >= 0);
5096 fprintf (file, "%d", exact_log2 (INTVAL (x)));
5097 return;
5098 case 'p':
5099 gcc_assert (GET_CODE (x) == CONST_INT);
5100 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 63 - (INTVAL (x) & 63));
5101 return;
5102 case 'P':
5103 gcc_assert (GET_CODE (x) == CONST_INT);
5104 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 31 - (INTVAL (x) & 31));
5105 return;
5106 case 'I':
5107 if (GET_CODE (x) == CONST_INT)
5108 fputs ("i", file);
5109 return;
5110 case 'M':
5111 case 'F':
5112 switch (GET_CODE (XEXP (x, 0)))
5114 case PRE_DEC:
5115 case PRE_INC:
5116 if (ASSEMBLER_DIALECT == 0)
5117 fputs ("s,mb", file);
5118 else
5119 fputs (",mb", file);
5120 break;
5121 case POST_DEC:
5122 case POST_INC:
5123 if (ASSEMBLER_DIALECT == 0)
5124 fputs ("s,ma", file);
5125 else
5126 fputs (",ma", file);
5127 break;
5128 case PLUS:
5129 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5130 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5132 if (ASSEMBLER_DIALECT == 0)
5133 fputs ("x", file);
5135 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
5136 || GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5138 if (ASSEMBLER_DIALECT == 0)
5139 fputs ("x,s", file);
5140 else
5141 fputs (",s", file);
5143 else if (code == 'F' && ASSEMBLER_DIALECT == 0)
5144 fputs ("s", file);
5145 break;
5146 default:
5147 if (code == 'F' && ASSEMBLER_DIALECT == 0)
5148 fputs ("s", file);
5149 break;
5151 return;
5152 case 'G':
5153 output_global_address (file, x, 0);
5154 return;
5155 case 'H':
5156 output_global_address (file, x, 1);
5157 return;
5158 case 0: /* Don't do anything special */
5159 break;
5160 case 'Z':
5162 unsigned op[3];
5163 compute_zdepwi_operands (INTVAL (x), op);
5164 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5165 return;
5167 case 'z':
5169 unsigned op[3];
5170 compute_zdepdi_operands (INTVAL (x), op);
5171 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5172 return;
5174 case 'c':
5175 /* We can get here from a .vtable_inherit due to our
5176 CONSTANT_ADDRESS_P rejecting perfectly good constant
5177 addresses. */
5178 break;
5179 default:
5180 gcc_unreachable ();
5182 if (GET_CODE (x) == REG)
5184 fputs (reg_names [REGNO (x)], file);
5185 if (TARGET_64BIT && FP_REG_P (x) && GET_MODE_SIZE (GET_MODE (x)) <= 4)
5187 fputs ("R", file);
5188 return;
5190 if (FP_REG_P (x)
5191 && GET_MODE_SIZE (GET_MODE (x)) <= 4
5192 && (REGNO (x) & 1) == 0)
5193 fputs ("L", file);
5195 else if (GET_CODE (x) == MEM)
5197 int size = GET_MODE_SIZE (GET_MODE (x));
5198 rtx base = NULL_RTX;
5199 switch (GET_CODE (XEXP (x, 0)))
5201 case PRE_DEC:
5202 case POST_DEC:
5203 base = XEXP (XEXP (x, 0), 0);
5204 fprintf (file, "-%d(%s)", size, reg_names [REGNO (base)]);
5205 break;
5206 case PRE_INC:
5207 case POST_INC:
5208 base = XEXP (XEXP (x, 0), 0);
5209 fprintf (file, "%d(%s)", size, reg_names [REGNO (base)]);
5210 break;
5211 case PLUS:
5212 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
5213 fprintf (file, "%s(%s)",
5214 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 0), 0))],
5215 reg_names [REGNO (XEXP (XEXP (x, 0), 1))]);
5216 else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5217 fprintf (file, "%s(%s)",
5218 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 1), 0))],
5219 reg_names [REGNO (XEXP (XEXP (x, 0), 0))]);
5220 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5221 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5223 /* Because the REG_POINTER flag can get lost during reload,
5224 GO_IF_LEGITIMATE_ADDRESS canonicalizes the order of the
5225 index and base registers in the combined move patterns. */
5226 rtx base = XEXP (XEXP (x, 0), 1);
5227 rtx index = XEXP (XEXP (x, 0), 0);
5229 fprintf (file, "%s(%s)",
5230 reg_names [REGNO (index)], reg_names [REGNO (base)]);
5232 else
5233 output_address (XEXP (x, 0));
5234 break;
5235 default:
5236 output_address (XEXP (x, 0));
5237 break;
5240 else
5241 output_addr_const (file, x);
5244 /* output a SYMBOL_REF or a CONST expression involving a SYMBOL_REF. */
5246 void
5247 output_global_address (FILE *file, rtx x, int round_constant)
5250 /* Imagine (high (const (plus ...))). */
5251 if (GET_CODE (x) == HIGH)
5252 x = XEXP (x, 0);
5254 if (GET_CODE (x) == SYMBOL_REF && read_only_operand (x, VOIDmode))
5255 output_addr_const (file, x);
5256 else if (GET_CODE (x) == SYMBOL_REF && !flag_pic)
5258 output_addr_const (file, x);
5259 fputs ("-$global$", file);
5261 else if (GET_CODE (x) == CONST)
5263 const char *sep = "";
5264 int offset = 0; /* assembler wants -$global$ at end */
5265 rtx base = NULL_RTX;
5267 switch (GET_CODE (XEXP (XEXP (x, 0), 0)))
5269 case SYMBOL_REF:
5270 base = XEXP (XEXP (x, 0), 0);
5271 output_addr_const (file, base);
5272 break;
5273 case CONST_INT:
5274 offset = INTVAL (XEXP (XEXP (x, 0), 0));
5275 break;
5276 default:
5277 gcc_unreachable ();
5280 switch (GET_CODE (XEXP (XEXP (x, 0), 1)))
5282 case SYMBOL_REF:
5283 base = XEXP (XEXP (x, 0), 1);
5284 output_addr_const (file, base);
5285 break;
5286 case CONST_INT:
5287 offset = INTVAL (XEXP (XEXP (x, 0), 1));
5288 break;
5289 default:
5290 gcc_unreachable ();
5293 /* How bogus. The compiler is apparently responsible for
5294 rounding the constant if it uses an LR field selector.
5296 The linker and/or assembler seem a better place since
5297 they have to do this kind of thing already.
5299 If we fail to do this, HP's optimizing linker may eliminate
5300 an addil, but not update the ldw/stw/ldo instruction that
5301 uses the result of the addil. */
5302 if (round_constant)
5303 offset = ((offset + 0x1000) & ~0x1fff);
5305 switch (GET_CODE (XEXP (x, 0)))
5307 case PLUS:
5308 if (offset < 0)
5310 offset = -offset;
5311 sep = "-";
5313 else
5314 sep = "+";
5315 break;
5317 case MINUS:
5318 gcc_assert (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF);
5319 sep = "-";
5320 break;
5322 default:
5323 gcc_unreachable ();
5326 if (!read_only_operand (base, VOIDmode) && !flag_pic)
5327 fputs ("-$global$", file);
5328 if (offset)
5329 fprintf (file, "%s%d", sep, offset);
5331 else
5332 output_addr_const (file, x);
5335 /* Output boilerplate text to appear at the beginning of the file.
5336 There are several possible versions. */
5337 #define aputs(x) fputs(x, asm_out_file)
5338 static inline void
5339 pa_file_start_level (void)
5341 if (TARGET_64BIT)
5342 aputs ("\t.LEVEL 2.0w\n");
5343 else if (TARGET_PA_20)
5344 aputs ("\t.LEVEL 2.0\n");
5345 else if (TARGET_PA_11)
5346 aputs ("\t.LEVEL 1.1\n");
5347 else
5348 aputs ("\t.LEVEL 1.0\n");
5351 static inline void
5352 pa_file_start_space (int sortspace)
5354 aputs ("\t.SPACE $PRIVATE$");
5355 if (sortspace)
5356 aputs (",SORT=16");
5357 aputs ("\n\t.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31"
5358 "\n\t.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82"
5359 "\n\t.SPACE $TEXT$");
5360 if (sortspace)
5361 aputs (",SORT=8");
5362 aputs ("\n\t.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44"
5363 "\n\t.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n");
5366 static inline void
5367 pa_file_start_file (int want_version)
5369 if (write_symbols != NO_DEBUG)
5371 output_file_directive (asm_out_file, main_input_filename);
5372 if (want_version)
5373 aputs ("\t.version\t\"01.01\"\n");
5377 static inline void
5378 pa_file_start_mcount (const char *aswhat)
5380 if (profile_flag)
5381 fprintf (asm_out_file, "\t.IMPORT _mcount,%s\n", aswhat);
5384 static void
5385 pa_elf_file_start (void)
5387 pa_file_start_level ();
5388 pa_file_start_mcount ("ENTRY");
5389 pa_file_start_file (0);
5392 static void
5393 pa_som_file_start (void)
5395 pa_file_start_level ();
5396 pa_file_start_space (0);
5397 aputs ("\t.IMPORT $global$,DATA\n"
5398 "\t.IMPORT $$dyncall,MILLICODE\n");
5399 pa_file_start_mcount ("CODE");
5400 pa_file_start_file (0);
5403 static void
5404 pa_linux_file_start (void)
5406 pa_file_start_file (1);
5407 pa_file_start_level ();
5408 pa_file_start_mcount ("CODE");
5411 static void
5412 pa_hpux64_gas_file_start (void)
5414 pa_file_start_level ();
5415 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
5416 if (profile_flag)
5417 ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, "_mcount", "function");
5418 #endif
5419 pa_file_start_file (1);
5422 static void
5423 pa_hpux64_hpas_file_start (void)
5425 pa_file_start_level ();
5426 pa_file_start_space (1);
5427 pa_file_start_mcount ("CODE");
5428 pa_file_start_file (0);
5430 #undef aputs
5432 /* Search the deferred plabel list for SYMBOL and return its internal
5433 label. If an entry for SYMBOL is not found, a new entry is created. */
5436 get_deferred_plabel (rtx symbol)
5438 const char *fname = XSTR (symbol, 0);
5439 size_t i;
5441 /* See if we have already put this function on the list of deferred
5442 plabels. This list is generally small, so a liner search is not
5443 too ugly. If it proves too slow replace it with something faster. */
5444 for (i = 0; i < n_deferred_plabels; i++)
5445 if (strcmp (fname, XSTR (deferred_plabels[i].symbol, 0)) == 0)
5446 break;
5448 /* If the deferred plabel list is empty, or this entry was not found
5449 on the list, create a new entry on the list. */
5450 if (deferred_plabels == NULL || i == n_deferred_plabels)
5452 tree id;
5454 if (deferred_plabels == 0)
5455 deferred_plabels = ggc_alloc_deferred_plabel ();
5456 else
5457 deferred_plabels = GGC_RESIZEVEC (struct deferred_plabel,
5458 deferred_plabels,
5459 n_deferred_plabels + 1);
5461 i = n_deferred_plabels++;
5462 deferred_plabels[i].internal_label = gen_label_rtx ();
5463 deferred_plabels[i].symbol = symbol;
5465 /* Gross. We have just implicitly taken the address of this
5466 function. Mark it in the same manner as assemble_name. */
5467 id = maybe_get_identifier (targetm.strip_name_encoding (fname));
5468 if (id)
5469 mark_referenced (id);
5472 return deferred_plabels[i].internal_label;
5475 static void
5476 output_deferred_plabels (void)
5478 size_t i;
5480 /* If we have some deferred plabels, then we need to switch into the
5481 data or readonly data section, and align it to a 4 byte boundary
5482 before outputting the deferred plabels. */
5483 if (n_deferred_plabels)
5485 switch_to_section (flag_pic ? data_section : readonly_data_section);
5486 ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2);
5489 /* Now output the deferred plabels. */
5490 for (i = 0; i < n_deferred_plabels; i++)
5492 targetm.asm_out.internal_label (asm_out_file, "L",
5493 CODE_LABEL_NUMBER (deferred_plabels[i].internal_label));
5494 assemble_integer (deferred_plabels[i].symbol,
5495 TARGET_64BIT ? 8 : 4, TARGET_64BIT ? 64 : 32, 1);
5499 #ifdef HPUX_LONG_DOUBLE_LIBRARY
5500 /* Initialize optabs to point to HPUX long double emulation routines. */
5501 static void
5502 pa_hpux_init_libfuncs (void)
5504 set_optab_libfunc (add_optab, TFmode, "_U_Qfadd");
5505 set_optab_libfunc (sub_optab, TFmode, "_U_Qfsub");
5506 set_optab_libfunc (smul_optab, TFmode, "_U_Qfmpy");
5507 set_optab_libfunc (sdiv_optab, TFmode, "_U_Qfdiv");
5508 set_optab_libfunc (smin_optab, TFmode, "_U_Qmin");
5509 set_optab_libfunc (smax_optab, TFmode, "_U_Qfmax");
5510 set_optab_libfunc (sqrt_optab, TFmode, "_U_Qfsqrt");
5511 set_optab_libfunc (abs_optab, TFmode, "_U_Qfabs");
5512 set_optab_libfunc (neg_optab, TFmode, "_U_Qfneg");
5514 set_optab_libfunc (eq_optab, TFmode, "_U_Qfeq");
5515 set_optab_libfunc (ne_optab, TFmode, "_U_Qfne");
5516 set_optab_libfunc (gt_optab, TFmode, "_U_Qfgt");
5517 set_optab_libfunc (ge_optab, TFmode, "_U_Qfge");
5518 set_optab_libfunc (lt_optab, TFmode, "_U_Qflt");
5519 set_optab_libfunc (le_optab, TFmode, "_U_Qfle");
5520 set_optab_libfunc (unord_optab, TFmode, "_U_Qfunord");
5522 set_conv_libfunc (sext_optab, TFmode, SFmode, "_U_Qfcnvff_sgl_to_quad");
5523 set_conv_libfunc (sext_optab, TFmode, DFmode, "_U_Qfcnvff_dbl_to_quad");
5524 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_U_Qfcnvff_quad_to_sgl");
5525 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_U_Qfcnvff_quad_to_dbl");
5527 set_conv_libfunc (sfix_optab, SImode, TFmode, TARGET_64BIT
5528 ? "__U_Qfcnvfxt_quad_to_sgl"
5529 : "_U_Qfcnvfxt_quad_to_sgl");
5530 set_conv_libfunc (sfix_optab, DImode, TFmode, "_U_Qfcnvfxt_quad_to_dbl");
5531 set_conv_libfunc (ufix_optab, SImode, TFmode, "_U_Qfcnvfxt_quad_to_usgl");
5532 set_conv_libfunc (ufix_optab, DImode, TFmode, "_U_Qfcnvfxt_quad_to_udbl");
5534 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_U_Qfcnvxf_sgl_to_quad");
5535 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_U_Qfcnvxf_dbl_to_quad");
5536 set_conv_libfunc (ufloat_optab, TFmode, SImode, "_U_Qfcnvxf_usgl_to_quad");
5537 set_conv_libfunc (ufloat_optab, TFmode, DImode, "_U_Qfcnvxf_udbl_to_quad");
5539 #endif
5541 /* HP's millicode routines mean something special to the assembler.
5542 Keep track of which ones we have used. */
5544 enum millicodes { remI, remU, divI, divU, mulI, end1000 };
5545 static void import_milli (enum millicodes);
5546 static char imported[(int) end1000];
5547 static const char * const milli_names[] = {"remI", "remU", "divI", "divU", "mulI"};
5548 static const char import_string[] = ".IMPORT $$....,MILLICODE";
5549 #define MILLI_START 10
5551 static void
5552 import_milli (enum millicodes code)
5554 char str[sizeof (import_string)];
5556 if (!imported[(int) code])
5558 imported[(int) code] = 1;
5559 strcpy (str, import_string);
5560 strncpy (str + MILLI_START, milli_names[(int) code], 4);
5561 output_asm_insn (str, 0);
5565 /* The register constraints have put the operands and return value in
5566 the proper registers. */
5568 const char *
5569 output_mul_insn (int unsignedp ATTRIBUTE_UNUSED, rtx insn)
5571 import_milli (mulI);
5572 return output_millicode_call (insn, gen_rtx_SYMBOL_REF (Pmode, "$$mulI"));
5575 /* Emit the rtl for doing a division by a constant. */
5577 /* Do magic division millicodes exist for this value? */
5578 const int magic_milli[]= {0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1};
5580 /* We'll use an array to keep track of the magic millicodes and
5581 whether or not we've used them already. [n][0] is signed, [n][1] is
5582 unsigned. */
5584 static int div_milli[16][2];
5587 emit_hpdiv_const (rtx *operands, int unsignedp)
5589 if (GET_CODE (operands[2]) == CONST_INT
5590 && INTVAL (operands[2]) > 0
5591 && INTVAL (operands[2]) < 16
5592 && magic_milli[INTVAL (operands[2])])
5594 rtx ret = gen_rtx_REG (SImode, TARGET_64BIT ? 2 : 31);
5596 emit_move_insn (gen_rtx_REG (SImode, 26), operands[1]);
5597 emit
5598 (gen_rtx_PARALLEL
5599 (VOIDmode,
5600 gen_rtvec (6, gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, 29),
5601 gen_rtx_fmt_ee (unsignedp ? UDIV : DIV,
5602 SImode,
5603 gen_rtx_REG (SImode, 26),
5604 operands[2])),
5605 gen_rtx_CLOBBER (VOIDmode, operands[4]),
5606 gen_rtx_CLOBBER (VOIDmode, operands[3]),
5607 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 26)),
5608 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 25)),
5609 gen_rtx_CLOBBER (VOIDmode, ret))));
5610 emit_move_insn (operands[0], gen_rtx_REG (SImode, 29));
5611 return 1;
5613 return 0;
5616 const char *
5617 output_div_insn (rtx *operands, int unsignedp, rtx insn)
5619 int divisor;
5621 /* If the divisor is a constant, try to use one of the special
5622 opcodes .*/
5623 if (GET_CODE (operands[0]) == CONST_INT)
5625 static char buf[100];
5626 divisor = INTVAL (operands[0]);
5627 if (!div_milli[divisor][unsignedp])
5629 div_milli[divisor][unsignedp] = 1;
5630 if (unsignedp)
5631 output_asm_insn (".IMPORT $$divU_%0,MILLICODE", operands);
5632 else
5633 output_asm_insn (".IMPORT $$divI_%0,MILLICODE", operands);
5635 if (unsignedp)
5637 sprintf (buf, "$$divU_" HOST_WIDE_INT_PRINT_DEC,
5638 INTVAL (operands[0]));
5639 return output_millicode_call (insn,
5640 gen_rtx_SYMBOL_REF (SImode, buf));
5642 else
5644 sprintf (buf, "$$divI_" HOST_WIDE_INT_PRINT_DEC,
5645 INTVAL (operands[0]));
5646 return output_millicode_call (insn,
5647 gen_rtx_SYMBOL_REF (SImode, buf));
5650 /* Divisor isn't a special constant. */
5651 else
5653 if (unsignedp)
5655 import_milli (divU);
5656 return output_millicode_call (insn,
5657 gen_rtx_SYMBOL_REF (SImode, "$$divU"));
5659 else
5661 import_milli (divI);
5662 return output_millicode_call (insn,
5663 gen_rtx_SYMBOL_REF (SImode, "$$divI"));
5668 /* Output a $$rem millicode to do mod. */
5670 const char *
5671 output_mod_insn (int unsignedp, rtx insn)
5673 if (unsignedp)
5675 import_milli (remU);
5676 return output_millicode_call (insn,
5677 gen_rtx_SYMBOL_REF (SImode, "$$remU"));
5679 else
5681 import_milli (remI);
5682 return output_millicode_call (insn,
5683 gen_rtx_SYMBOL_REF (SImode, "$$remI"));
5687 void
5688 output_arg_descriptor (rtx call_insn)
5690 const char *arg_regs[4];
5691 enum machine_mode arg_mode;
5692 rtx link;
5693 int i, output_flag = 0;
5694 int regno;
5696 /* We neither need nor want argument location descriptors for the
5697 64bit runtime environment or the ELF32 environment. */
5698 if (TARGET_64BIT || TARGET_ELF32)
5699 return;
5701 for (i = 0; i < 4; i++)
5702 arg_regs[i] = 0;
5704 /* Specify explicitly that no argument relocations should take place
5705 if using the portable runtime calling conventions. */
5706 if (TARGET_PORTABLE_RUNTIME)
5708 fputs ("\t.CALL ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RETVAL=NO\n",
5709 asm_out_file);
5710 return;
5713 gcc_assert (GET_CODE (call_insn) == CALL_INSN);
5714 for (link = CALL_INSN_FUNCTION_USAGE (call_insn);
5715 link; link = XEXP (link, 1))
5717 rtx use = XEXP (link, 0);
5719 if (! (GET_CODE (use) == USE
5720 && GET_CODE (XEXP (use, 0)) == REG
5721 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
5722 continue;
5724 arg_mode = GET_MODE (XEXP (use, 0));
5725 regno = REGNO (XEXP (use, 0));
5726 if (regno >= 23 && regno <= 26)
5728 arg_regs[26 - regno] = "GR";
5729 if (arg_mode == DImode)
5730 arg_regs[25 - regno] = "GR";
5732 else if (regno >= 32 && regno <= 39)
5734 if (arg_mode == SFmode)
5735 arg_regs[(regno - 32) / 2] = "FR";
5736 else
5738 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
5739 arg_regs[(regno - 34) / 2] = "FR";
5740 arg_regs[(regno - 34) / 2 + 1] = "FU";
5741 #else
5742 arg_regs[(regno - 34) / 2] = "FU";
5743 arg_regs[(regno - 34) / 2 + 1] = "FR";
5744 #endif
5748 fputs ("\t.CALL ", asm_out_file);
5749 for (i = 0; i < 4; i++)
5751 if (arg_regs[i])
5753 if (output_flag++)
5754 fputc (',', asm_out_file);
5755 fprintf (asm_out_file, "ARGW%d=%s", i, arg_regs[i]);
5758 fputc ('\n', asm_out_file);
5761 static reg_class_t
5762 pa_secondary_reload (bool in_p, rtx x, reg_class_t rclass_i,
5763 enum machine_mode mode, secondary_reload_info *sri)
5765 int is_symbolic, regno;
5766 enum reg_class rclass = (enum reg_class) rclass_i;
5768 /* Handle the easy stuff first. */
5769 if (rclass == R1_REGS)
5770 return NO_REGS;
5772 if (REG_P (x))
5774 regno = REGNO (x);
5775 if (rclass == BASE_REG_CLASS && regno < FIRST_PSEUDO_REGISTER)
5776 return NO_REGS;
5778 else
5779 regno = -1;
5781 /* If we have something like (mem (mem (...)), we can safely assume the
5782 inner MEM will end up in a general register after reloading, so there's
5783 no need for a secondary reload. */
5784 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == MEM)
5785 return NO_REGS;
5787 /* Trying to load a constant into a FP register during PIC code
5788 generation requires %r1 as a scratch register. */
5789 if (flag_pic
5790 && (mode == SImode || mode == DImode)
5791 && FP_REG_CLASS_P (rclass)
5792 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
5794 sri->icode = (mode == SImode ? CODE_FOR_reload_insi_r1
5795 : CODE_FOR_reload_indi_r1);
5796 return NO_REGS;
5799 /* Profiling showed the PA port spends about 1.3% of its compilation
5800 time in true_regnum from calls inside pa_secondary_reload_class. */
5801 if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
5802 regno = true_regnum (x);
5804 /* In order to allow 14-bit displacements in integer loads and stores,
5805 we need to prevent reload from generating out of range integer mode
5806 loads and stores to the floating point registers. Previously, we
5807 used to call for a secondary reload and have emit_move_sequence()
5808 fix the instruction sequence. However, reload occasionally wouldn't
5809 generate the reload and we would end up with an invalid REG+D memory
5810 address. So, now we use an intermediate general register for most
5811 memory loads and stores. */
5812 if ((regno >= FIRST_PSEUDO_REGISTER || regno == -1)
5813 && GET_MODE_CLASS (mode) == MODE_INT
5814 && FP_REG_CLASS_P (rclass))
5816 /* Reload passes (mem:SI (reg/f:DI 30 %r30) when it wants to check
5817 the secondary reload needed for a pseudo. It never passes a
5818 REG+D address. */
5819 if (GET_CODE (x) == MEM)
5821 x = XEXP (x, 0);
5823 /* We don't need an intermediate for indexed and LO_SUM DLT
5824 memory addresses. When INT14_OK_STRICT is true, it might
5825 appear that we could directly allow register indirect
5826 memory addresses. However, this doesn't work because we
5827 don't support SUBREGs in floating-point register copies
5828 and reload doesn't tell us when it's going to use a SUBREG. */
5829 if (IS_INDEX_ADDR_P (x)
5830 || IS_LO_SUM_DLT_ADDR_P (x))
5831 return NO_REGS;
5833 /* Otherwise, we need an intermediate general register. */
5834 return GENERAL_REGS;
5837 /* Request a secondary reload with a general scratch register
5838 for everthing else. ??? Could symbolic operands be handled
5839 directly when generating non-pic PA 2.0 code? */
5840 sri->icode = (in_p
5841 ? direct_optab_handler (reload_in_optab, mode)
5842 : direct_optab_handler (reload_out_optab, mode));
5843 return NO_REGS;
5846 /* We need a secondary register (GPR) for copies between the SAR
5847 and anything other than a general register. */
5848 if (rclass == SHIFT_REGS && (regno <= 0 || regno >= 32))
5850 sri->icode = (in_p
5851 ? direct_optab_handler (reload_in_optab, mode)
5852 : direct_optab_handler (reload_out_optab, mode));
5853 return NO_REGS;
5856 /* A SAR<->FP register copy requires a secondary register (GPR) as
5857 well as secondary memory. */
5858 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5859 && (REGNO_REG_CLASS (regno) == SHIFT_REGS
5860 && FP_REG_CLASS_P (rclass)))
5862 sri->icode = (in_p
5863 ? direct_optab_handler (reload_in_optab, mode)
5864 : direct_optab_handler (reload_out_optab, mode));
5865 return NO_REGS;
5868 /* Secondary reloads of symbolic operands require %r1 as a scratch
5869 register when we're generating PIC code and when the operand isn't
5870 readonly. */
5871 if (GET_CODE (x) == HIGH)
5872 x = XEXP (x, 0);
5874 /* Profiling has showed GCC spends about 2.6% of its compilation
5875 time in symbolic_operand from calls inside pa_secondary_reload_class.
5876 So, we use an inline copy to avoid useless work. */
5877 switch (GET_CODE (x))
5879 rtx op;
5881 case SYMBOL_REF:
5882 is_symbolic = !SYMBOL_REF_TLS_MODEL (x);
5883 break;
5884 case LABEL_REF:
5885 is_symbolic = 1;
5886 break;
5887 case CONST:
5888 op = XEXP (x, 0);
5889 is_symbolic = (GET_CODE (op) == PLUS
5890 && ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
5891 && !SYMBOL_REF_TLS_MODEL (XEXP (op, 0)))
5892 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
5893 && GET_CODE (XEXP (op, 1)) == CONST_INT);
5894 break;
5895 default:
5896 is_symbolic = 0;
5897 break;
5900 if (is_symbolic && (flag_pic || !read_only_operand (x, VOIDmode)))
5902 gcc_assert (mode == SImode || mode == DImode);
5903 sri->icode = (mode == SImode ? CODE_FOR_reload_insi_r1
5904 : CODE_FOR_reload_indi_r1);
5907 return NO_REGS;
5910 /* Implement TARGET_EXTRA_LIVE_ON_ENTRY. The argument pointer
5911 is only marked as live on entry by df-scan when it is a fixed
5912 register. It isn't a fixed register in the 64-bit runtime,
5913 so we need to mark it here. */
5915 static void
5916 pa_extra_live_on_entry (bitmap regs)
5918 if (TARGET_64BIT)
5919 bitmap_set_bit (regs, ARG_POINTER_REGNUM);
5922 /* Implement EH_RETURN_HANDLER_RTX. The MEM needs to be volatile
5923 to prevent it from being deleted. */
5926 pa_eh_return_handler_rtx (void)
5928 rtx tmp;
5930 tmp = gen_rtx_PLUS (word_mode, hard_frame_pointer_rtx,
5931 TARGET_64BIT ? GEN_INT (-16) : GEN_INT (-20));
5932 tmp = gen_rtx_MEM (word_mode, tmp);
5933 tmp->volatil = 1;
5934 return tmp;
5937 /* In the 32-bit runtime, arguments larger than eight bytes are passed
5938 by invisible reference. As a GCC extension, we also pass anything
5939 with a zero or variable size by reference.
5941 The 64-bit runtime does not describe passing any types by invisible
5942 reference. The internals of GCC can't currently handle passing
5943 empty structures, and zero or variable length arrays when they are
5944 not passed entirely on the stack or by reference. Thus, as a GCC
5945 extension, we pass these types by reference. The HP compiler doesn't
5946 support these types, so hopefully there shouldn't be any compatibility
5947 issues. This may have to be revisited when HP releases a C99 compiler
5948 or updates the ABI. */
5950 static bool
5951 pa_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
5952 enum machine_mode mode, const_tree type,
5953 bool named ATTRIBUTE_UNUSED)
5955 HOST_WIDE_INT size;
5957 if (type)
5958 size = int_size_in_bytes (type);
5959 else
5960 size = GET_MODE_SIZE (mode);
5962 if (TARGET_64BIT)
5963 return size <= 0;
5964 else
5965 return size <= 0 || size > 8;
5968 enum direction
5969 function_arg_padding (enum machine_mode mode, const_tree type)
5971 if (mode == BLKmode
5972 || (TARGET_64BIT
5973 && type
5974 && (AGGREGATE_TYPE_P (type)
5975 || TREE_CODE (type) == COMPLEX_TYPE
5976 || TREE_CODE (type) == VECTOR_TYPE)))
5978 /* Return none if justification is not required. */
5979 if (type
5980 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
5981 && (int_size_in_bytes (type) * BITS_PER_UNIT) % PARM_BOUNDARY == 0)
5982 return none;
5984 /* The directions set here are ignored when a BLKmode argument larger
5985 than a word is placed in a register. Different code is used for
5986 the stack and registers. This makes it difficult to have a
5987 consistent data representation for both the stack and registers.
5988 For both runtimes, the justification and padding for arguments on
5989 the stack and in registers should be identical. */
5990 if (TARGET_64BIT)
5991 /* The 64-bit runtime specifies left justification for aggregates. */
5992 return upward;
5993 else
5994 /* The 32-bit runtime architecture specifies right justification.
5995 When the argument is passed on the stack, the argument is padded
5996 with garbage on the left. The HP compiler pads with zeros. */
5997 return downward;
6000 if (GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
6001 return downward;
6002 else
6003 return none;
6007 /* Do what is necessary for `va_start'. We look at the current function
6008 to determine if stdargs or varargs is used and fill in an initial
6009 va_list. A pointer to this constructor is returned. */
6011 static rtx
6012 hppa_builtin_saveregs (void)
6014 rtx offset, dest;
6015 tree fntype = TREE_TYPE (current_function_decl);
6016 int argadj = ((!stdarg_p (fntype))
6017 ? UNITS_PER_WORD : 0);
6019 if (argadj)
6020 offset = plus_constant (crtl->args.arg_offset_rtx, argadj);
6021 else
6022 offset = crtl->args.arg_offset_rtx;
6024 if (TARGET_64BIT)
6026 int i, off;
6028 /* Adjust for varargs/stdarg differences. */
6029 if (argadj)
6030 offset = plus_constant (crtl->args.arg_offset_rtx, -argadj);
6031 else
6032 offset = crtl->args.arg_offset_rtx;
6034 /* We need to save %r26 .. %r19 inclusive starting at offset -64
6035 from the incoming arg pointer and growing to larger addresses. */
6036 for (i = 26, off = -64; i >= 19; i--, off += 8)
6037 emit_move_insn (gen_rtx_MEM (word_mode,
6038 plus_constant (arg_pointer_rtx, off)),
6039 gen_rtx_REG (word_mode, i));
6041 /* The incoming args pointer points just beyond the flushback area;
6042 normally this is not a serious concern. However, when we are doing
6043 varargs/stdargs we want to make the arg pointer point to the start
6044 of the incoming argument area. */
6045 emit_move_insn (virtual_incoming_args_rtx,
6046 plus_constant (arg_pointer_rtx, -64));
6048 /* Now return a pointer to the first anonymous argument. */
6049 return copy_to_reg (expand_binop (Pmode, add_optab,
6050 virtual_incoming_args_rtx,
6051 offset, 0, 0, OPTAB_LIB_WIDEN));
6054 /* Store general registers on the stack. */
6055 dest = gen_rtx_MEM (BLKmode,
6056 plus_constant (crtl->args.internal_arg_pointer,
6057 -16));
6058 set_mem_alias_set (dest, get_varargs_alias_set ());
6059 set_mem_align (dest, BITS_PER_WORD);
6060 move_block_from_reg (23, dest, 4);
6062 /* move_block_from_reg will emit code to store the argument registers
6063 individually as scalar stores.
6065 However, other insns may later load from the same addresses for
6066 a structure load (passing a struct to a varargs routine).
6068 The alias code assumes that such aliasing can never happen, so we
6069 have to keep memory referencing insns from moving up beyond the
6070 last argument register store. So we emit a blockage insn here. */
6071 emit_insn (gen_blockage ());
6073 return copy_to_reg (expand_binop (Pmode, add_optab,
6074 crtl->args.internal_arg_pointer,
6075 offset, 0, 0, OPTAB_LIB_WIDEN));
6078 static void
6079 hppa_va_start (tree valist, rtx nextarg)
6081 nextarg = expand_builtin_saveregs ();
6082 std_expand_builtin_va_start (valist, nextarg);
6085 static tree
6086 hppa_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
6087 gimple_seq *post_p)
6089 if (TARGET_64BIT)
6091 /* Args grow upward. We can use the generic routines. */
6092 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6094 else /* !TARGET_64BIT */
6096 tree ptr = build_pointer_type (type);
6097 tree valist_type;
6098 tree t, u;
6099 unsigned int size, ofs;
6100 bool indirect;
6102 indirect = pass_by_reference (NULL, TYPE_MODE (type), type, 0);
6103 if (indirect)
6105 type = ptr;
6106 ptr = build_pointer_type (type);
6108 size = int_size_in_bytes (type);
6109 valist_type = TREE_TYPE (valist);
6111 /* Args grow down. Not handled by generic routines. */
6113 u = fold_convert (sizetype, size_in_bytes (type));
6114 u = fold_build1 (NEGATE_EXPR, sizetype, u);
6115 t = build2 (POINTER_PLUS_EXPR, valist_type, valist, u);
6117 /* Align to 4 or 8 byte boundary depending on argument size. */
6119 u = build_int_cst (TREE_TYPE (t), (HOST_WIDE_INT)(size > 4 ? -8 : -4));
6120 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t, u);
6121 t = fold_convert (valist_type, t);
6123 t = build2 (MODIFY_EXPR, valist_type, valist, t);
6125 ofs = (8 - size) % 4;
6126 if (ofs != 0)
6128 u = size_int (ofs);
6129 t = build2 (POINTER_PLUS_EXPR, valist_type, t, u);
6132 t = fold_convert (ptr, t);
6133 t = build_va_arg_indirect_ref (t);
6135 if (indirect)
6136 t = build_va_arg_indirect_ref (t);
6138 return t;
6142 /* True if MODE is valid for the target. By "valid", we mean able to
6143 be manipulated in non-trivial ways. In particular, this means all
6144 the arithmetic is supported.
6146 Currently, TImode is not valid as the HP 64-bit runtime documentation
6147 doesn't document the alignment and calling conventions for this type.
6148 Thus, we return false when PRECISION is 2 * BITS_PER_WORD and
6149 2 * BITS_PER_WORD isn't equal LONG_LONG_TYPE_SIZE. */
6151 static bool
6152 pa_scalar_mode_supported_p (enum machine_mode mode)
6154 int precision = GET_MODE_PRECISION (mode);
6156 switch (GET_MODE_CLASS (mode))
6158 case MODE_PARTIAL_INT:
6159 case MODE_INT:
6160 if (precision == CHAR_TYPE_SIZE)
6161 return true;
6162 if (precision == SHORT_TYPE_SIZE)
6163 return true;
6164 if (precision == INT_TYPE_SIZE)
6165 return true;
6166 if (precision == LONG_TYPE_SIZE)
6167 return true;
6168 if (precision == LONG_LONG_TYPE_SIZE)
6169 return true;
6170 return false;
6172 case MODE_FLOAT:
6173 if (precision == FLOAT_TYPE_SIZE)
6174 return true;
6175 if (precision == DOUBLE_TYPE_SIZE)
6176 return true;
6177 if (precision == LONG_DOUBLE_TYPE_SIZE)
6178 return true;
6179 return false;
6181 case MODE_DECIMAL_FLOAT:
6182 return false;
6184 default:
6185 gcc_unreachable ();
6189 /* Return TRUE if INSN, a jump insn, has an unfilled delay slot and
6190 it branches to the next real instruction. Otherwise, return FALSE. */
6192 static bool
6193 branch_to_delay_slot_p (rtx insn)
6195 if (dbr_sequence_length ())
6196 return FALSE;
6198 return next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn);
6201 /* Return TRUE if INSN, a jump insn, needs a nop in its delay slot.
6203 This occurs when INSN has an unfilled delay slot and is followed
6204 by an ASM_INPUT. Disaster can occur if the ASM_INPUT is empty and
6205 the jump branches into the delay slot. So, we add a nop in the delay
6206 slot just to be safe. This messes up our instruction count, but we
6207 don't know how big the ASM_INPUT insn is anyway. */
6209 static bool
6210 branch_needs_nop_p (rtx insn)
6212 rtx next_insn;
6214 if (dbr_sequence_length ())
6215 return FALSE;
6217 next_insn = next_real_insn (insn);
6218 return GET_CODE (PATTERN (next_insn)) == ASM_INPUT;
6221 /* This routine handles all the normal conditional branch sequences we
6222 might need to generate. It handles compare immediate vs compare
6223 register, nullification of delay slots, varying length branches,
6224 negated branches, and all combinations of the above. It returns the
6225 output appropriate to emit the branch corresponding to all given
6226 parameters. */
6228 const char *
6229 output_cbranch (rtx *operands, int negated, rtx insn)
6231 static char buf[100];
6232 int useskip = 0;
6233 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6234 int length = get_attr_length (insn);
6235 int xdelay;
6237 /* A conditional branch to the following instruction (e.g. the delay slot)
6238 is asking for a disaster. This can happen when not optimizing and
6239 when jump optimization fails.
6241 While it is usually safe to emit nothing, this can fail if the
6242 preceding instruction is a nullified branch with an empty delay
6243 slot and the same branch target as this branch. We could check
6244 for this but jump optimization should eliminate nop jumps. It
6245 is always safe to emit a nop. */
6246 if (branch_to_delay_slot_p (insn))
6247 return "nop";
6249 /* The doubleword form of the cmpib instruction doesn't have the LEU
6250 and GTU conditions while the cmpb instruction does. Since we accept
6251 zero for cmpb, we must ensure that we use cmpb for the comparison. */
6252 if (GET_MODE (operands[1]) == DImode && operands[2] == const0_rtx)
6253 operands[2] = gen_rtx_REG (DImode, 0);
6254 if (GET_MODE (operands[2]) == DImode && operands[1] == const0_rtx)
6255 operands[1] = gen_rtx_REG (DImode, 0);
6257 /* If this is a long branch with its delay slot unfilled, set `nullify'
6258 as it can nullify the delay slot and save a nop. */
6259 if (length == 8 && dbr_sequence_length () == 0)
6260 nullify = 1;
6262 /* If this is a short forward conditional branch which did not get
6263 its delay slot filled, the delay slot can still be nullified. */
6264 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6265 nullify = forward_branch_p (insn);
6267 /* A forward branch over a single nullified insn can be done with a
6268 comclr instruction. This avoids a single cycle penalty due to
6269 mis-predicted branch if we fall through (branch not taken). */
6270 if (length == 4
6271 && next_real_insn (insn) != 0
6272 && get_attr_length (next_real_insn (insn)) == 4
6273 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6274 && nullify)
6275 useskip = 1;
6277 switch (length)
6279 /* All short conditional branches except backwards with an unfilled
6280 delay slot. */
6281 case 4:
6282 if (useskip)
6283 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6284 else
6285 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6286 if (GET_MODE (operands[1]) == DImode)
6287 strcat (buf, "*");
6288 if (negated)
6289 strcat (buf, "%B3");
6290 else
6291 strcat (buf, "%S3");
6292 if (useskip)
6293 strcat (buf, " %2,%r1,%%r0");
6294 else if (nullify)
6296 if (branch_needs_nop_p (insn))
6297 strcat (buf, ",n %2,%r1,%0%#");
6298 else
6299 strcat (buf, ",n %2,%r1,%0");
6301 else
6302 strcat (buf, " %2,%r1,%0");
6303 break;
6305 /* All long conditionals. Note a short backward branch with an
6306 unfilled delay slot is treated just like a long backward branch
6307 with an unfilled delay slot. */
6308 case 8:
6309 /* Handle weird backwards branch with a filled delay slot
6310 which is nullified. */
6311 if (dbr_sequence_length () != 0
6312 && ! forward_branch_p (insn)
6313 && nullify)
6315 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6316 if (GET_MODE (operands[1]) == DImode)
6317 strcat (buf, "*");
6318 if (negated)
6319 strcat (buf, "%S3");
6320 else
6321 strcat (buf, "%B3");
6322 strcat (buf, ",n %2,%r1,.+12\n\tb %0");
6324 /* Handle short backwards branch with an unfilled delay slot.
6325 Using a comb;nop rather than comiclr;bl saves 1 cycle for both
6326 taken and untaken branches. */
6327 else if (dbr_sequence_length () == 0
6328 && ! forward_branch_p (insn)
6329 && INSN_ADDRESSES_SET_P ()
6330 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6331 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6333 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6334 if (GET_MODE (operands[1]) == DImode)
6335 strcat (buf, "*");
6336 if (negated)
6337 strcat (buf, "%B3 %2,%r1,%0%#");
6338 else
6339 strcat (buf, "%S3 %2,%r1,%0%#");
6341 else
6343 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6344 if (GET_MODE (operands[1]) == DImode)
6345 strcat (buf, "*");
6346 if (negated)
6347 strcat (buf, "%S3");
6348 else
6349 strcat (buf, "%B3");
6350 if (nullify)
6351 strcat (buf, " %2,%r1,%%r0\n\tb,n %0");
6352 else
6353 strcat (buf, " %2,%r1,%%r0\n\tb %0");
6355 break;
6357 default:
6358 /* The reversed conditional branch must branch over one additional
6359 instruction if the delay slot is filled and needs to be extracted
6360 by output_lbranch. If the delay slot is empty or this is a
6361 nullified forward branch, the instruction after the reversed
6362 condition branch must be nullified. */
6363 if (dbr_sequence_length () == 0
6364 || (nullify && forward_branch_p (insn)))
6366 nullify = 1;
6367 xdelay = 0;
6368 operands[4] = GEN_INT (length);
6370 else
6372 xdelay = 1;
6373 operands[4] = GEN_INT (length + 4);
6376 /* Create a reversed conditional branch which branches around
6377 the following insns. */
6378 if (GET_MODE (operands[1]) != DImode)
6380 if (nullify)
6382 if (negated)
6383 strcpy (buf,
6384 "{com%I2b,%S3,n %2,%r1,.+%4|cmp%I2b,%S3,n %2,%r1,.+%4}");
6385 else
6386 strcpy (buf,
6387 "{com%I2b,%B3,n %2,%r1,.+%4|cmp%I2b,%B3,n %2,%r1,.+%4}");
6389 else
6391 if (negated)
6392 strcpy (buf,
6393 "{com%I2b,%S3 %2,%r1,.+%4|cmp%I2b,%S3 %2,%r1,.+%4}");
6394 else
6395 strcpy (buf,
6396 "{com%I2b,%B3 %2,%r1,.+%4|cmp%I2b,%B3 %2,%r1,.+%4}");
6399 else
6401 if (nullify)
6403 if (negated)
6404 strcpy (buf,
6405 "{com%I2b,*%S3,n %2,%r1,.+%4|cmp%I2b,*%S3,n %2,%r1,.+%4}");
6406 else
6407 strcpy (buf,
6408 "{com%I2b,*%B3,n %2,%r1,.+%4|cmp%I2b,*%B3,n %2,%r1,.+%4}");
6410 else
6412 if (negated)
6413 strcpy (buf,
6414 "{com%I2b,*%S3 %2,%r1,.+%4|cmp%I2b,*%S3 %2,%r1,.+%4}");
6415 else
6416 strcpy (buf,
6417 "{com%I2b,*%B3 %2,%r1,.+%4|cmp%I2b,*%B3 %2,%r1,.+%4}");
6421 output_asm_insn (buf, operands);
6422 return output_lbranch (operands[0], insn, xdelay);
6424 return buf;
6427 /* This routine handles output of long unconditional branches that
6428 exceed the maximum range of a simple branch instruction. Since
6429 we don't have a register available for the branch, we save register
6430 %r1 in the frame marker, load the branch destination DEST into %r1,
6431 execute the branch, and restore %r1 in the delay slot of the branch.
6433 Since long branches may have an insn in the delay slot and the
6434 delay slot is used to restore %r1, we in general need to extract
6435 this insn and execute it before the branch. However, to facilitate
6436 use of this function by conditional branches, we also provide an
6437 option to not extract the delay insn so that it will be emitted
6438 after the long branch. So, if there is an insn in the delay slot,
6439 it is extracted if XDELAY is nonzero.
6441 The lengths of the various long-branch sequences are 20, 16 and 24
6442 bytes for the portable runtime, non-PIC and PIC cases, respectively. */
6444 const char *
6445 output_lbranch (rtx dest, rtx insn, int xdelay)
6447 rtx xoperands[2];
6449 xoperands[0] = dest;
6451 /* First, free up the delay slot. */
6452 if (xdelay && dbr_sequence_length () != 0)
6454 /* We can't handle a jump in the delay slot. */
6455 gcc_assert (GET_CODE (NEXT_INSN (insn)) != JUMP_INSN);
6457 final_scan_insn (NEXT_INSN (insn), asm_out_file,
6458 optimize, 0, NULL);
6460 /* Now delete the delay insn. */
6461 SET_INSN_DELETED (NEXT_INSN (insn));
6464 /* Output an insn to save %r1. The runtime documentation doesn't
6465 specify whether the "Clean Up" slot in the callers frame can
6466 be clobbered by the callee. It isn't copied by HP's builtin
6467 alloca, so this suggests that it can be clobbered if necessary.
6468 The "Static Link" location is copied by HP builtin alloca, so
6469 we avoid using it. Using the cleanup slot might be a problem
6470 if we have to interoperate with languages that pass cleanup
6471 information. However, it should be possible to handle these
6472 situations with GCC's asm feature.
6474 The "Current RP" slot is reserved for the called procedure, so
6475 we try to use it when we don't have a frame of our own. It's
6476 rather unlikely that we won't have a frame when we need to emit
6477 a very long branch.
6479 Really the way to go long term is a register scavenger; goto
6480 the target of the jump and find a register which we can use
6481 as a scratch to hold the value in %r1. Then, we wouldn't have
6482 to free up the delay slot or clobber a slot that may be needed
6483 for other purposes. */
6484 if (TARGET_64BIT)
6486 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
6487 /* Use the return pointer slot in the frame marker. */
6488 output_asm_insn ("std %%r1,-16(%%r30)", xoperands);
6489 else
6490 /* Use the slot at -40 in the frame marker since HP builtin
6491 alloca doesn't copy it. */
6492 output_asm_insn ("std %%r1,-40(%%r30)", xoperands);
6494 else
6496 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
6497 /* Use the return pointer slot in the frame marker. */
6498 output_asm_insn ("stw %%r1,-20(%%r30)", xoperands);
6499 else
6500 /* Use the "Clean Up" slot in the frame marker. In GCC,
6501 the only other use of this location is for copying a
6502 floating point double argument from a floating-point
6503 register to two general registers. The copy is done
6504 as an "atomic" operation when outputting a call, so it
6505 won't interfere with our using the location here. */
6506 output_asm_insn ("stw %%r1,-12(%%r30)", xoperands);
6509 if (TARGET_PORTABLE_RUNTIME)
6511 output_asm_insn ("ldil L'%0,%%r1", xoperands);
6512 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
6513 output_asm_insn ("bv %%r0(%%r1)", xoperands);
6515 else if (flag_pic)
6517 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
6518 if (TARGET_SOM || !TARGET_GAS)
6520 xoperands[1] = gen_label_rtx ();
6521 output_asm_insn ("addil L'%l0-%l1,%%r1", xoperands);
6522 targetm.asm_out.internal_label (asm_out_file, "L",
6523 CODE_LABEL_NUMBER (xoperands[1]));
6524 output_asm_insn ("ldo R'%l0-%l1(%%r1),%%r1", xoperands);
6526 else
6528 output_asm_insn ("addil L'%l0-$PIC_pcrel$0+4,%%r1", xoperands);
6529 output_asm_insn ("ldo R'%l0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
6531 output_asm_insn ("bv %%r0(%%r1)", xoperands);
6533 else
6534 /* Now output a very long branch to the original target. */
6535 output_asm_insn ("ldil L'%l0,%%r1\n\tbe R'%l0(%%sr4,%%r1)", xoperands);
6537 /* Now restore the value of %r1 in the delay slot. */
6538 if (TARGET_64BIT)
6540 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
6541 return "ldd -16(%%r30),%%r1";
6542 else
6543 return "ldd -40(%%r30),%%r1";
6545 else
6547 if (actual_fsize == 0 && !df_regs_ever_live_p (2))
6548 return "ldw -20(%%r30),%%r1";
6549 else
6550 return "ldw -12(%%r30),%%r1";
6554 /* This routine handles all the branch-on-bit conditional branch sequences we
6555 might need to generate. It handles nullification of delay slots,
6556 varying length branches, negated branches and all combinations of the
6557 above. it returns the appropriate output template to emit the branch. */
6559 const char *
6560 output_bb (rtx *operands ATTRIBUTE_UNUSED, int negated, rtx insn, int which)
6562 static char buf[100];
6563 int useskip = 0;
6564 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6565 int length = get_attr_length (insn);
6566 int xdelay;
6568 /* A conditional branch to the following instruction (e.g. the delay slot) is
6569 asking for a disaster. I do not think this can happen as this pattern
6570 is only used when optimizing; jump optimization should eliminate the
6571 jump. But be prepared just in case. */
6573 if (branch_to_delay_slot_p (insn))
6574 return "nop";
6576 /* If this is a long branch with its delay slot unfilled, set `nullify'
6577 as it can nullify the delay slot and save a nop. */
6578 if (length == 8 && dbr_sequence_length () == 0)
6579 nullify = 1;
6581 /* If this is a short forward conditional branch which did not get
6582 its delay slot filled, the delay slot can still be nullified. */
6583 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6584 nullify = forward_branch_p (insn);
6586 /* A forward branch over a single nullified insn can be done with a
6587 extrs instruction. This avoids a single cycle penalty due to
6588 mis-predicted branch if we fall through (branch not taken). */
6590 if (length == 4
6591 && next_real_insn (insn) != 0
6592 && get_attr_length (next_real_insn (insn)) == 4
6593 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6594 && nullify)
6595 useskip = 1;
6597 switch (length)
6600 /* All short conditional branches except backwards with an unfilled
6601 delay slot. */
6602 case 4:
6603 if (useskip)
6604 strcpy (buf, "{extrs,|extrw,s,}");
6605 else
6606 strcpy (buf, "bb,");
6607 if (useskip && GET_MODE (operands[0]) == DImode)
6608 strcpy (buf, "extrd,s,*");
6609 else if (GET_MODE (operands[0]) == DImode)
6610 strcpy (buf, "bb,*");
6611 if ((which == 0 && negated)
6612 || (which == 1 && ! negated))
6613 strcat (buf, ">=");
6614 else
6615 strcat (buf, "<");
6616 if (useskip)
6617 strcat (buf, " %0,%1,1,%%r0");
6618 else if (nullify && negated)
6620 if (branch_needs_nop_p (insn))
6621 strcat (buf, ",n %0,%1,%3%#");
6622 else
6623 strcat (buf, ",n %0,%1,%3");
6625 else if (nullify && ! negated)
6627 if (branch_needs_nop_p (insn))
6628 strcat (buf, ",n %0,%1,%2%#");
6629 else
6630 strcat (buf, ",n %0,%1,%2");
6632 else if (! nullify && negated)
6633 strcat (buf, " %0,%1,%3");
6634 else if (! nullify && ! negated)
6635 strcat (buf, " %0,%1,%2");
6636 break;
6638 /* All long conditionals. Note a short backward branch with an
6639 unfilled delay slot is treated just like a long backward branch
6640 with an unfilled delay slot. */
6641 case 8:
6642 /* Handle weird backwards branch with a filled delay slot
6643 which is nullified. */
6644 if (dbr_sequence_length () != 0
6645 && ! forward_branch_p (insn)
6646 && nullify)
6648 strcpy (buf, "bb,");
6649 if (GET_MODE (operands[0]) == DImode)
6650 strcat (buf, "*");
6651 if ((which == 0 && negated)
6652 || (which == 1 && ! negated))
6653 strcat (buf, "<");
6654 else
6655 strcat (buf, ">=");
6656 if (negated)
6657 strcat (buf, ",n %0,%1,.+12\n\tb %3");
6658 else
6659 strcat (buf, ",n %0,%1,.+12\n\tb %2");
6661 /* Handle short backwards branch with an unfilled delay slot.
6662 Using a bb;nop rather than extrs;bl saves 1 cycle for both
6663 taken and untaken branches. */
6664 else if (dbr_sequence_length () == 0
6665 && ! forward_branch_p (insn)
6666 && INSN_ADDRESSES_SET_P ()
6667 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6668 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6670 strcpy (buf, "bb,");
6671 if (GET_MODE (operands[0]) == DImode)
6672 strcat (buf, "*");
6673 if ((which == 0 && negated)
6674 || (which == 1 && ! negated))
6675 strcat (buf, ">=");
6676 else
6677 strcat (buf, "<");
6678 if (negated)
6679 strcat (buf, " %0,%1,%3%#");
6680 else
6681 strcat (buf, " %0,%1,%2%#");
6683 else
6685 if (GET_MODE (operands[0]) == DImode)
6686 strcpy (buf, "extrd,s,*");
6687 else
6688 strcpy (buf, "{extrs,|extrw,s,}");
6689 if ((which == 0 && negated)
6690 || (which == 1 && ! negated))
6691 strcat (buf, "<");
6692 else
6693 strcat (buf, ">=");
6694 if (nullify && negated)
6695 strcat (buf, " %0,%1,1,%%r0\n\tb,n %3");
6696 else if (nullify && ! negated)
6697 strcat (buf, " %0,%1,1,%%r0\n\tb,n %2");
6698 else if (negated)
6699 strcat (buf, " %0,%1,1,%%r0\n\tb %3");
6700 else
6701 strcat (buf, " %0,%1,1,%%r0\n\tb %2");
6703 break;
6705 default:
6706 /* The reversed conditional branch must branch over one additional
6707 instruction if the delay slot is filled and needs to be extracted
6708 by output_lbranch. If the delay slot is empty or this is a
6709 nullified forward branch, the instruction after the reversed
6710 condition branch must be nullified. */
6711 if (dbr_sequence_length () == 0
6712 || (nullify && forward_branch_p (insn)))
6714 nullify = 1;
6715 xdelay = 0;
6716 operands[4] = GEN_INT (length);
6718 else
6720 xdelay = 1;
6721 operands[4] = GEN_INT (length + 4);
6724 if (GET_MODE (operands[0]) == DImode)
6725 strcpy (buf, "bb,*");
6726 else
6727 strcpy (buf, "bb,");
6728 if ((which == 0 && negated)
6729 || (which == 1 && !negated))
6730 strcat (buf, "<");
6731 else
6732 strcat (buf, ">=");
6733 if (nullify)
6734 strcat (buf, ",n %0,%1,.+%4");
6735 else
6736 strcat (buf, " %0,%1,.+%4");
6737 output_asm_insn (buf, operands);
6738 return output_lbranch (negated ? operands[3] : operands[2],
6739 insn, xdelay);
6741 return buf;
6744 /* This routine handles all the branch-on-variable-bit conditional branch
6745 sequences we might need to generate. It handles nullification of delay
6746 slots, varying length branches, negated branches and all combinations
6747 of the above. it returns the appropriate output template to emit the
6748 branch. */
6750 const char *
6751 output_bvb (rtx *operands ATTRIBUTE_UNUSED, int negated, rtx insn, int which)
6753 static char buf[100];
6754 int useskip = 0;
6755 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6756 int length = get_attr_length (insn);
6757 int xdelay;
6759 /* A conditional branch to the following instruction (e.g. the delay slot) is
6760 asking for a disaster. I do not think this can happen as this pattern
6761 is only used when optimizing; jump optimization should eliminate the
6762 jump. But be prepared just in case. */
6764 if (branch_to_delay_slot_p (insn))
6765 return "nop";
6767 /* If this is a long branch with its delay slot unfilled, set `nullify'
6768 as it can nullify the delay slot and save a nop. */
6769 if (length == 8 && dbr_sequence_length () == 0)
6770 nullify = 1;
6772 /* If this is a short forward conditional branch which did not get
6773 its delay slot filled, the delay slot can still be nullified. */
6774 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6775 nullify = forward_branch_p (insn);
6777 /* A forward branch over a single nullified insn can be done with a
6778 extrs instruction. This avoids a single cycle penalty due to
6779 mis-predicted branch if we fall through (branch not taken). */
6781 if (length == 4
6782 && next_real_insn (insn) != 0
6783 && get_attr_length (next_real_insn (insn)) == 4
6784 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6785 && nullify)
6786 useskip = 1;
6788 switch (length)
6791 /* All short conditional branches except backwards with an unfilled
6792 delay slot. */
6793 case 4:
6794 if (useskip)
6795 strcpy (buf, "{vextrs,|extrw,s,}");
6796 else
6797 strcpy (buf, "{bvb,|bb,}");
6798 if (useskip && GET_MODE (operands[0]) == DImode)
6799 strcpy (buf, "extrd,s,*");
6800 else if (GET_MODE (operands[0]) == DImode)
6801 strcpy (buf, "bb,*");
6802 if ((which == 0 && negated)
6803 || (which == 1 && ! negated))
6804 strcat (buf, ">=");
6805 else
6806 strcat (buf, "<");
6807 if (useskip)
6808 strcat (buf, "{ %0,1,%%r0| %0,%%sar,1,%%r0}");
6809 else if (nullify && negated)
6811 if (branch_needs_nop_p (insn))
6812 strcat (buf, "{,n %0,%3%#|,n %0,%%sar,%3%#}");
6813 else
6814 strcat (buf, "{,n %0,%3|,n %0,%%sar,%3}");
6816 else if (nullify && ! negated)
6818 if (branch_needs_nop_p (insn))
6819 strcat (buf, "{,n %0,%2%#|,n %0,%%sar,%2%#}");
6820 else
6821 strcat (buf, "{,n %0,%2|,n %0,%%sar,%2}");
6823 else if (! nullify && negated)
6824 strcat (buf, "{ %0,%3| %0,%%sar,%3}");
6825 else if (! nullify && ! negated)
6826 strcat (buf, "{ %0,%2| %0,%%sar,%2}");
6827 break;
6829 /* All long conditionals. Note a short backward branch with an
6830 unfilled delay slot is treated just like a long backward branch
6831 with an unfilled delay slot. */
6832 case 8:
6833 /* Handle weird backwards branch with a filled delay slot
6834 which is nullified. */
6835 if (dbr_sequence_length () != 0
6836 && ! forward_branch_p (insn)
6837 && nullify)
6839 strcpy (buf, "{bvb,|bb,}");
6840 if (GET_MODE (operands[0]) == DImode)
6841 strcat (buf, "*");
6842 if ((which == 0 && negated)
6843 || (which == 1 && ! negated))
6844 strcat (buf, "<");
6845 else
6846 strcat (buf, ">=");
6847 if (negated)
6848 strcat (buf, "{,n %0,.+12\n\tb %3|,n %0,%%sar,.+12\n\tb %3}");
6849 else
6850 strcat (buf, "{,n %0,.+12\n\tb %2|,n %0,%%sar,.+12\n\tb %2}");
6852 /* Handle short backwards branch with an unfilled delay slot.
6853 Using a bb;nop rather than extrs;bl saves 1 cycle for both
6854 taken and untaken branches. */
6855 else if (dbr_sequence_length () == 0
6856 && ! forward_branch_p (insn)
6857 && INSN_ADDRESSES_SET_P ()
6858 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6859 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6861 strcpy (buf, "{bvb,|bb,}");
6862 if (GET_MODE (operands[0]) == DImode)
6863 strcat (buf, "*");
6864 if ((which == 0 && negated)
6865 || (which == 1 && ! negated))
6866 strcat (buf, ">=");
6867 else
6868 strcat (buf, "<");
6869 if (negated)
6870 strcat (buf, "{ %0,%3%#| %0,%%sar,%3%#}");
6871 else
6872 strcat (buf, "{ %0,%2%#| %0,%%sar,%2%#}");
6874 else
6876 strcpy (buf, "{vextrs,|extrw,s,}");
6877 if (GET_MODE (operands[0]) == DImode)
6878 strcpy (buf, "extrd,s,*");
6879 if ((which == 0 && negated)
6880 || (which == 1 && ! negated))
6881 strcat (buf, "<");
6882 else
6883 strcat (buf, ">=");
6884 if (nullify && negated)
6885 strcat (buf, "{ %0,1,%%r0\n\tb,n %3| %0,%%sar,1,%%r0\n\tb,n %3}");
6886 else if (nullify && ! negated)
6887 strcat (buf, "{ %0,1,%%r0\n\tb,n %2| %0,%%sar,1,%%r0\n\tb,n %2}");
6888 else if (negated)
6889 strcat (buf, "{ %0,1,%%r0\n\tb %3| %0,%%sar,1,%%r0\n\tb %3}");
6890 else
6891 strcat (buf, "{ %0,1,%%r0\n\tb %2| %0,%%sar,1,%%r0\n\tb %2}");
6893 break;
6895 default:
6896 /* The reversed conditional branch must branch over one additional
6897 instruction if the delay slot is filled and needs to be extracted
6898 by output_lbranch. If the delay slot is empty or this is a
6899 nullified forward branch, the instruction after the reversed
6900 condition branch must be nullified. */
6901 if (dbr_sequence_length () == 0
6902 || (nullify && forward_branch_p (insn)))
6904 nullify = 1;
6905 xdelay = 0;
6906 operands[4] = GEN_INT (length);
6908 else
6910 xdelay = 1;
6911 operands[4] = GEN_INT (length + 4);
6914 if (GET_MODE (operands[0]) == DImode)
6915 strcpy (buf, "bb,*");
6916 else
6917 strcpy (buf, "{bvb,|bb,}");
6918 if ((which == 0 && negated)
6919 || (which == 1 && !negated))
6920 strcat (buf, "<");
6921 else
6922 strcat (buf, ">=");
6923 if (nullify)
6924 strcat (buf, ",n {%0,.+%4|%0,%%sar,.+%4}");
6925 else
6926 strcat (buf, " {%0,.+%4|%0,%%sar,.+%4}");
6927 output_asm_insn (buf, operands);
6928 return output_lbranch (negated ? operands[3] : operands[2],
6929 insn, xdelay);
6931 return buf;
6934 /* Return the output template for emitting a dbra type insn.
6936 Note it may perform some output operations on its own before
6937 returning the final output string. */
6938 const char *
6939 output_dbra (rtx *operands, rtx insn, int which_alternative)
6941 int length = get_attr_length (insn);
6943 /* A conditional branch to the following instruction (e.g. the delay slot) is
6944 asking for a disaster. Be prepared! */
6946 if (branch_to_delay_slot_p (insn))
6948 if (which_alternative == 0)
6949 return "ldo %1(%0),%0";
6950 else if (which_alternative == 1)
6952 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)", operands);
6953 output_asm_insn ("ldw -16(%%r30),%4", operands);
6954 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
6955 return "{fldws|fldw} -16(%%r30),%0";
6957 else
6959 output_asm_insn ("ldw %0,%4", operands);
6960 return "ldo %1(%4),%4\n\tstw %4,%0";
6964 if (which_alternative == 0)
6966 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6967 int xdelay;
6969 /* If this is a long branch with its delay slot unfilled, set `nullify'
6970 as it can nullify the delay slot and save a nop. */
6971 if (length == 8 && dbr_sequence_length () == 0)
6972 nullify = 1;
6974 /* If this is a short forward conditional branch which did not get
6975 its delay slot filled, the delay slot can still be nullified. */
6976 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6977 nullify = forward_branch_p (insn);
6979 switch (length)
6981 case 4:
6982 if (nullify)
6984 if (branch_needs_nop_p (insn))
6985 return "addib,%C2,n %1,%0,%3%#";
6986 else
6987 return "addib,%C2,n %1,%0,%3";
6989 else
6990 return "addib,%C2 %1,%0,%3";
6992 case 8:
6993 /* Handle weird backwards branch with a fulled delay slot
6994 which is nullified. */
6995 if (dbr_sequence_length () != 0
6996 && ! forward_branch_p (insn)
6997 && nullify)
6998 return "addib,%N2,n %1,%0,.+12\n\tb %3";
6999 /* Handle short backwards branch with an unfilled delay slot.
7000 Using a addb;nop rather than addi;bl saves 1 cycle for both
7001 taken and untaken branches. */
7002 else if (dbr_sequence_length () == 0
7003 && ! forward_branch_p (insn)
7004 && INSN_ADDRESSES_SET_P ()
7005 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7006 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7007 return "addib,%C2 %1,%0,%3%#";
7009 /* Handle normal cases. */
7010 if (nullify)
7011 return "addi,%N2 %1,%0,%0\n\tb,n %3";
7012 else
7013 return "addi,%N2 %1,%0,%0\n\tb %3";
7015 default:
7016 /* The reversed conditional branch must branch over one additional
7017 instruction if the delay slot is filled and needs to be extracted
7018 by output_lbranch. If the delay slot is empty or this is a
7019 nullified forward branch, the instruction after the reversed
7020 condition branch must be nullified. */
7021 if (dbr_sequence_length () == 0
7022 || (nullify && forward_branch_p (insn)))
7024 nullify = 1;
7025 xdelay = 0;
7026 operands[4] = GEN_INT (length);
7028 else
7030 xdelay = 1;
7031 operands[4] = GEN_INT (length + 4);
7034 if (nullify)
7035 output_asm_insn ("addib,%N2,n %1,%0,.+%4", operands);
7036 else
7037 output_asm_insn ("addib,%N2 %1,%0,.+%4", operands);
7039 return output_lbranch (operands[3], insn, xdelay);
7043 /* Deal with gross reload from FP register case. */
7044 else if (which_alternative == 1)
7046 /* Move loop counter from FP register to MEM then into a GR,
7047 increment the GR, store the GR into MEM, and finally reload
7048 the FP register from MEM from within the branch's delay slot. */
7049 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)\n\tldw -16(%%r30),%4",
7050 operands);
7051 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
7052 if (length == 24)
7053 return "{comb|cmpb},%S2 %%r0,%4,%3\n\t{fldws|fldw} -16(%%r30),%0";
7054 else if (length == 28)
7055 return "{comclr|cmpclr},%B2 %%r0,%4,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
7056 else
7058 operands[5] = GEN_INT (length - 16);
7059 output_asm_insn ("{comb|cmpb},%B2 %%r0,%4,.+%5", operands);
7060 output_asm_insn ("{fldws|fldw} -16(%%r30),%0", operands);
7061 return output_lbranch (operands[3], insn, 0);
7064 /* Deal with gross reload from memory case. */
7065 else
7067 /* Reload loop counter from memory, the store back to memory
7068 happens in the branch's delay slot. */
7069 output_asm_insn ("ldw %0,%4", operands);
7070 if (length == 12)
7071 return "addib,%C2 %1,%4,%3\n\tstw %4,%0";
7072 else if (length == 16)
7073 return "addi,%N2 %1,%4,%4\n\tb %3\n\tstw %4,%0";
7074 else
7076 operands[5] = GEN_INT (length - 4);
7077 output_asm_insn ("addib,%N2 %1,%4,.+%5\n\tstw %4,%0", operands);
7078 return output_lbranch (operands[3], insn, 0);
7083 /* Return the output template for emitting a movb type insn.
7085 Note it may perform some output operations on its own before
7086 returning the final output string. */
7087 const char *
7088 output_movb (rtx *operands, rtx insn, int which_alternative,
7089 int reverse_comparison)
7091 int length = get_attr_length (insn);
7093 /* A conditional branch to the following instruction (e.g. the delay slot) is
7094 asking for a disaster. Be prepared! */
7096 if (branch_to_delay_slot_p (insn))
7098 if (which_alternative == 0)
7099 return "copy %1,%0";
7100 else if (which_alternative == 1)
7102 output_asm_insn ("stw %1,-16(%%r30)", operands);
7103 return "{fldws|fldw} -16(%%r30),%0";
7105 else if (which_alternative == 2)
7106 return "stw %1,%0";
7107 else
7108 return "mtsar %r1";
7111 /* Support the second variant. */
7112 if (reverse_comparison)
7113 PUT_CODE (operands[2], reverse_condition (GET_CODE (operands[2])));
7115 if (which_alternative == 0)
7117 int nullify = INSN_ANNULLED_BRANCH_P (insn);
7118 int xdelay;
7120 /* If this is a long branch with its delay slot unfilled, set `nullify'
7121 as it can nullify the delay slot and save a nop. */
7122 if (length == 8 && dbr_sequence_length () == 0)
7123 nullify = 1;
7125 /* If this is a short forward conditional branch which did not get
7126 its delay slot filled, the delay slot can still be nullified. */
7127 if (! nullify && length == 4 && dbr_sequence_length () == 0)
7128 nullify = forward_branch_p (insn);
7130 switch (length)
7132 case 4:
7133 if (nullify)
7135 if (branch_needs_nop_p (insn))
7136 return "movb,%C2,n %1,%0,%3%#";
7137 else
7138 return "movb,%C2,n %1,%0,%3";
7140 else
7141 return "movb,%C2 %1,%0,%3";
7143 case 8:
7144 /* Handle weird backwards branch with a filled delay slot
7145 which is nullified. */
7146 if (dbr_sequence_length () != 0
7147 && ! forward_branch_p (insn)
7148 && nullify)
7149 return "movb,%N2,n %1,%0,.+12\n\tb %3";
7151 /* Handle short backwards branch with an unfilled delay slot.
7152 Using a movb;nop rather than or;bl saves 1 cycle for both
7153 taken and untaken branches. */
7154 else if (dbr_sequence_length () == 0
7155 && ! forward_branch_p (insn)
7156 && INSN_ADDRESSES_SET_P ()
7157 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7158 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7159 return "movb,%C2 %1,%0,%3%#";
7160 /* Handle normal cases. */
7161 if (nullify)
7162 return "or,%N2 %1,%%r0,%0\n\tb,n %3";
7163 else
7164 return "or,%N2 %1,%%r0,%0\n\tb %3";
7166 default:
7167 /* The reversed conditional branch must branch over one additional
7168 instruction if the delay slot is filled and needs to be extracted
7169 by output_lbranch. If the delay slot is empty or this is a
7170 nullified forward branch, the instruction after the reversed
7171 condition branch must be nullified. */
7172 if (dbr_sequence_length () == 0
7173 || (nullify && forward_branch_p (insn)))
7175 nullify = 1;
7176 xdelay = 0;
7177 operands[4] = GEN_INT (length);
7179 else
7181 xdelay = 1;
7182 operands[4] = GEN_INT (length + 4);
7185 if (nullify)
7186 output_asm_insn ("movb,%N2,n %1,%0,.+%4", operands);
7187 else
7188 output_asm_insn ("movb,%N2 %1,%0,.+%4", operands);
7190 return output_lbranch (operands[3], insn, xdelay);
7193 /* Deal with gross reload for FP destination register case. */
7194 else if (which_alternative == 1)
7196 /* Move source register to MEM, perform the branch test, then
7197 finally load the FP register from MEM from within the branch's
7198 delay slot. */
7199 output_asm_insn ("stw %1,-16(%%r30)", operands);
7200 if (length == 12)
7201 return "{comb|cmpb},%S2 %%r0,%1,%3\n\t{fldws|fldw} -16(%%r30),%0";
7202 else if (length == 16)
7203 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
7204 else
7206 operands[4] = GEN_INT (length - 4);
7207 output_asm_insn ("{comb|cmpb},%B2 %%r0,%1,.+%4", operands);
7208 output_asm_insn ("{fldws|fldw} -16(%%r30),%0", operands);
7209 return output_lbranch (operands[3], insn, 0);
7212 /* Deal with gross reload from memory case. */
7213 else if (which_alternative == 2)
7215 /* Reload loop counter from memory, the store back to memory
7216 happens in the branch's delay slot. */
7217 if (length == 8)
7218 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tstw %1,%0";
7219 else if (length == 12)
7220 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tstw %1,%0";
7221 else
7223 operands[4] = GEN_INT (length);
7224 output_asm_insn ("{comb|cmpb},%B2 %%r0,%1,.+%4\n\tstw %1,%0",
7225 operands);
7226 return output_lbranch (operands[3], insn, 0);
7229 /* Handle SAR as a destination. */
7230 else
7232 if (length == 8)
7233 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tmtsar %r1";
7234 else if (length == 12)
7235 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tmtsar %r1";
7236 else
7238 operands[4] = GEN_INT (length);
7239 output_asm_insn ("{comb|cmpb},%B2 %%r0,%1,.+%4\n\tmtsar %r1",
7240 operands);
7241 return output_lbranch (operands[3], insn, 0);
7246 /* Copy any FP arguments in INSN into integer registers. */
7247 static void
7248 copy_fp_args (rtx insn)
7250 rtx link;
7251 rtx xoperands[2];
7253 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7255 int arg_mode, regno;
7256 rtx use = XEXP (link, 0);
7258 if (! (GET_CODE (use) == USE
7259 && GET_CODE (XEXP (use, 0)) == REG
7260 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7261 continue;
7263 arg_mode = GET_MODE (XEXP (use, 0));
7264 regno = REGNO (XEXP (use, 0));
7266 /* Is it a floating point register? */
7267 if (regno >= 32 && regno <= 39)
7269 /* Copy the FP register into an integer register via memory. */
7270 if (arg_mode == SFmode)
7272 xoperands[0] = XEXP (use, 0);
7273 xoperands[1] = gen_rtx_REG (SImode, 26 - (regno - 32) / 2);
7274 output_asm_insn ("{fstws|fstw} %0,-16(%%sr0,%%r30)", xoperands);
7275 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7277 else
7279 xoperands[0] = XEXP (use, 0);
7280 xoperands[1] = gen_rtx_REG (DImode, 25 - (regno - 34) / 2);
7281 output_asm_insn ("{fstds|fstd} %0,-16(%%sr0,%%r30)", xoperands);
7282 output_asm_insn ("ldw -12(%%sr0,%%r30),%R1", xoperands);
7283 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7289 /* Compute length of the FP argument copy sequence for INSN. */
7290 static int
7291 length_fp_args (rtx insn)
7293 int length = 0;
7294 rtx link;
7296 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7298 int arg_mode, regno;
7299 rtx use = XEXP (link, 0);
7301 if (! (GET_CODE (use) == USE
7302 && GET_CODE (XEXP (use, 0)) == REG
7303 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7304 continue;
7306 arg_mode = GET_MODE (XEXP (use, 0));
7307 regno = REGNO (XEXP (use, 0));
7309 /* Is it a floating point register? */
7310 if (regno >= 32 && regno <= 39)
7312 if (arg_mode == SFmode)
7313 length += 8;
7314 else
7315 length += 12;
7319 return length;
7322 /* Return the attribute length for the millicode call instruction INSN.
7323 The length must match the code generated by output_millicode_call.
7324 We include the delay slot in the returned length as it is better to
7325 over estimate the length than to under estimate it. */
7328 attr_length_millicode_call (rtx insn)
7330 unsigned long distance = -1;
7331 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7333 if (INSN_ADDRESSES_SET_P ())
7335 distance = (total + insn_current_reference_address (insn));
7336 if (distance < total)
7337 distance = -1;
7340 if (TARGET_64BIT)
7342 if (!TARGET_LONG_CALLS && distance < 7600000)
7343 return 8;
7345 return 20;
7347 else if (TARGET_PORTABLE_RUNTIME)
7348 return 24;
7349 else
7351 if (!TARGET_LONG_CALLS && distance < 240000)
7352 return 8;
7354 if (TARGET_LONG_ABS_CALL && !flag_pic)
7355 return 12;
7357 return 24;
7361 /* INSN is a function call. It may have an unconditional jump
7362 in its delay slot.
7364 CALL_DEST is the routine we are calling. */
7366 const char *
7367 output_millicode_call (rtx insn, rtx call_dest)
7369 int attr_length = get_attr_length (insn);
7370 int seq_length = dbr_sequence_length ();
7371 int distance;
7372 rtx seq_insn;
7373 rtx xoperands[3];
7375 xoperands[0] = call_dest;
7376 xoperands[2] = gen_rtx_REG (Pmode, TARGET_64BIT ? 2 : 31);
7378 /* Handle the common case where we are sure that the branch will
7379 reach the beginning of the $CODE$ subspace. The within reach
7380 form of the $$sh_func_adrs call has a length of 28. Because
7381 it has an attribute type of multi, it never has a nonzero
7382 sequence length. The length of the $$sh_func_adrs is the same
7383 as certain out of reach PIC calls to other routines. */
7384 if (!TARGET_LONG_CALLS
7385 && ((seq_length == 0
7386 && (attr_length == 12
7387 || (attr_length == 28 && get_attr_type (insn) == TYPE_MULTI)))
7388 || (seq_length != 0 && attr_length == 8)))
7390 output_asm_insn ("{bl|b,l} %0,%2", xoperands);
7392 else
7394 if (TARGET_64BIT)
7396 /* It might seem that one insn could be saved by accessing
7397 the millicode function using the linkage table. However,
7398 this doesn't work in shared libraries and other dynamically
7399 loaded objects. Using a pc-relative sequence also avoids
7400 problems related to the implicit use of the gp register. */
7401 output_asm_insn ("b,l .+8,%%r1", xoperands);
7403 if (TARGET_GAS)
7405 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
7406 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
7408 else
7410 xoperands[1] = gen_label_rtx ();
7411 output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7412 targetm.asm_out.internal_label (asm_out_file, "L",
7413 CODE_LABEL_NUMBER (xoperands[1]));
7414 output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7417 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7419 else if (TARGET_PORTABLE_RUNTIME)
7421 /* Pure portable runtime doesn't allow be/ble; we also don't
7422 have PIC support in the assembler/linker, so this sequence
7423 is needed. */
7425 /* Get the address of our target into %r1. */
7426 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7427 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
7429 /* Get our return address into %r31. */
7430 output_asm_insn ("{bl|b,l} .+8,%%r31", xoperands);
7431 output_asm_insn ("addi 8,%%r31,%%r31", xoperands);
7433 /* Jump to our target address in %r1. */
7434 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7436 else if (!flag_pic)
7438 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7439 if (TARGET_PA_20)
7440 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31", xoperands);
7441 else
7442 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
7444 else
7446 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7447 output_asm_insn ("addi 16,%%r1,%%r31", xoperands);
7449 if (TARGET_SOM || !TARGET_GAS)
7451 /* The HP assembler can generate relocations for the
7452 difference of two symbols. GAS can do this for a
7453 millicode symbol but not an arbitrary external
7454 symbol when generating SOM output. */
7455 xoperands[1] = gen_label_rtx ();
7456 targetm.asm_out.internal_label (asm_out_file, "L",
7457 CODE_LABEL_NUMBER (xoperands[1]));
7458 output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7459 output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7461 else
7463 output_asm_insn ("addil L'%0-$PIC_pcrel$0+8,%%r1", xoperands);
7464 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+12(%%r1),%%r1",
7465 xoperands);
7468 /* Jump to our target address in %r1. */
7469 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7473 if (seq_length == 0)
7474 output_asm_insn ("nop", xoperands);
7476 /* We are done if there isn't a jump in the delay slot. */
7477 if (seq_length == 0 || GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
7478 return "";
7480 /* This call has an unconditional jump in its delay slot. */
7481 xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
7483 /* See if the return address can be adjusted. Use the containing
7484 sequence insn's address. */
7485 if (INSN_ADDRESSES_SET_P ())
7487 seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
7488 distance = (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
7489 - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8);
7491 if (VAL_14_BITS_P (distance))
7493 xoperands[1] = gen_label_rtx ();
7494 output_asm_insn ("ldo %0-%1(%2),%2", xoperands);
7495 targetm.asm_out.internal_label (asm_out_file, "L",
7496 CODE_LABEL_NUMBER (xoperands[1]));
7498 else
7499 /* ??? This branch may not reach its target. */
7500 output_asm_insn ("nop\n\tb,n %0", xoperands);
7502 else
7503 /* ??? This branch may not reach its target. */
7504 output_asm_insn ("nop\n\tb,n %0", xoperands);
7506 /* Delete the jump. */
7507 SET_INSN_DELETED (NEXT_INSN (insn));
7509 return "";
7512 /* Return the attribute length of the call instruction INSN. The SIBCALL
7513 flag indicates whether INSN is a regular call or a sibling call. The
7514 length returned must be longer than the code actually generated by
7515 output_call. Since branch shortening is done before delay branch
7516 sequencing, there is no way to determine whether or not the delay
7517 slot will be filled during branch shortening. Even when the delay
7518 slot is filled, we may have to add a nop if the delay slot contains
7519 a branch that can't reach its target. Thus, we always have to include
7520 the delay slot in the length estimate. This used to be done in
7521 pa_adjust_insn_length but we do it here now as some sequences always
7522 fill the delay slot and we can save four bytes in the estimate for
7523 these sequences. */
7526 attr_length_call (rtx insn, int sibcall)
7528 int local_call;
7529 rtx call, call_dest;
7530 tree call_decl;
7531 int length = 0;
7532 rtx pat = PATTERN (insn);
7533 unsigned long distance = -1;
7535 gcc_assert (GET_CODE (insn) == CALL_INSN);
7537 if (INSN_ADDRESSES_SET_P ())
7539 unsigned long total;
7541 total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7542 distance = (total + insn_current_reference_address (insn));
7543 if (distance < total)
7544 distance = -1;
7547 gcc_assert (GET_CODE (pat) == PARALLEL);
7549 /* Get the call rtx. */
7550 call = XVECEXP (pat, 0, 0);
7551 if (GET_CODE (call) == SET)
7552 call = SET_SRC (call);
7554 gcc_assert (GET_CODE (call) == CALL);
7556 /* Determine if this is a local call. */
7557 call_dest = XEXP (XEXP (call, 0), 0);
7558 call_decl = SYMBOL_REF_DECL (call_dest);
7559 local_call = call_decl && targetm.binds_local_p (call_decl);
7561 /* pc-relative branch. */
7562 if (!TARGET_LONG_CALLS
7563 && ((TARGET_PA_20 && !sibcall && distance < 7600000)
7564 || distance < 240000))
7565 length += 8;
7567 /* 64-bit plabel sequence. */
7568 else if (TARGET_64BIT && !local_call)
7569 length += sibcall ? 28 : 24;
7571 /* non-pic long absolute branch sequence. */
7572 else if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7573 length += 12;
7575 /* long pc-relative branch sequence. */
7576 else if (TARGET_LONG_PIC_SDIFF_CALL
7577 || (TARGET_GAS && !TARGET_SOM
7578 && (TARGET_LONG_PIC_PCREL_CALL || local_call)))
7580 length += 20;
7582 if (!TARGET_PA_20 && !TARGET_NO_SPACE_REGS && (!local_call || flag_pic))
7583 length += 8;
7586 /* 32-bit plabel sequence. */
7587 else
7589 length += 32;
7591 if (TARGET_SOM)
7592 length += length_fp_args (insn);
7594 if (flag_pic)
7595 length += 4;
7597 if (!TARGET_PA_20)
7599 if (!sibcall)
7600 length += 8;
7602 if (!TARGET_NO_SPACE_REGS && (!local_call || flag_pic))
7603 length += 8;
7607 return length;
7610 /* INSN is a function call. It may have an unconditional jump
7611 in its delay slot.
7613 CALL_DEST is the routine we are calling. */
7615 const char *
7616 output_call (rtx insn, rtx call_dest, int sibcall)
7618 int delay_insn_deleted = 0;
7619 int delay_slot_filled = 0;
7620 int seq_length = dbr_sequence_length ();
7621 tree call_decl = SYMBOL_REF_DECL (call_dest);
7622 int local_call = call_decl && targetm.binds_local_p (call_decl);
7623 rtx xoperands[2];
7625 xoperands[0] = call_dest;
7627 /* Handle the common case where we're sure that the branch will reach
7628 the beginning of the "$CODE$" subspace. This is the beginning of
7629 the current function if we are in a named section. */
7630 if (!TARGET_LONG_CALLS && attr_length_call (insn, sibcall) == 8)
7632 xoperands[1] = gen_rtx_REG (word_mode, sibcall ? 0 : 2);
7633 output_asm_insn ("{bl|b,l} %0,%1", xoperands);
7635 else
7637 if (TARGET_64BIT && !local_call)
7639 /* ??? As far as I can tell, the HP linker doesn't support the
7640 long pc-relative sequence described in the 64-bit runtime
7641 architecture. So, we use a slightly longer indirect call. */
7642 xoperands[0] = get_deferred_plabel (call_dest);
7643 xoperands[1] = gen_label_rtx ();
7645 /* If this isn't a sibcall, we put the load of %r27 into the
7646 delay slot. We can't do this in a sibcall as we don't
7647 have a second call-clobbered scratch register available. */
7648 if (seq_length != 0
7649 && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
7650 && !sibcall)
7652 final_scan_insn (NEXT_INSN (insn), asm_out_file,
7653 optimize, 0, NULL);
7655 /* Now delete the delay insn. */
7656 SET_INSN_DELETED (NEXT_INSN (insn));
7657 delay_insn_deleted = 1;
7660 output_asm_insn ("addil LT'%0,%%r27", xoperands);
7661 output_asm_insn ("ldd RT'%0(%%r1),%%r1", xoperands);
7662 output_asm_insn ("ldd 0(%%r1),%%r1", xoperands);
7664 if (sibcall)
7666 output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7667 output_asm_insn ("ldd 16(%%r1),%%r1", xoperands);
7668 output_asm_insn ("bve (%%r1)", xoperands);
7670 else
7672 output_asm_insn ("ldd 16(%%r1),%%r2", xoperands);
7673 output_asm_insn ("bve,l (%%r2),%%r2", xoperands);
7674 output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7675 delay_slot_filled = 1;
7678 else
7680 int indirect_call = 0;
7682 /* Emit a long call. There are several different sequences
7683 of increasing length and complexity. In most cases,
7684 they don't allow an instruction in the delay slot. */
7685 if (!((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7686 && !TARGET_LONG_PIC_SDIFF_CALL
7687 && !(TARGET_GAS && !TARGET_SOM
7688 && (TARGET_LONG_PIC_PCREL_CALL || local_call))
7689 && !TARGET_64BIT)
7690 indirect_call = 1;
7692 if (seq_length != 0
7693 && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
7694 && !sibcall
7695 && (!TARGET_PA_20
7696 || indirect_call
7697 || ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)))
7699 /* A non-jump insn in the delay slot. By definition we can
7700 emit this insn before the call (and in fact before argument
7701 relocating. */
7702 final_scan_insn (NEXT_INSN (insn), asm_out_file, optimize, 0,
7703 NULL);
7705 /* Now delete the delay insn. */
7706 SET_INSN_DELETED (NEXT_INSN (insn));
7707 delay_insn_deleted = 1;
7710 if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7712 /* This is the best sequence for making long calls in
7713 non-pic code. Unfortunately, GNU ld doesn't provide
7714 the stub needed for external calls, and GAS's support
7715 for this with the SOM linker is buggy. It is safe
7716 to use this for local calls. */
7717 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7718 if (sibcall)
7719 output_asm_insn ("be R'%0(%%sr4,%%r1)", xoperands);
7720 else
7722 if (TARGET_PA_20)
7723 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31",
7724 xoperands);
7725 else
7726 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
7728 output_asm_insn ("copy %%r31,%%r2", xoperands);
7729 delay_slot_filled = 1;
7732 else
7734 if (TARGET_LONG_PIC_SDIFF_CALL)
7736 /* The HP assembler and linker can handle relocations
7737 for the difference of two symbols. The HP assembler
7738 recognizes the sequence as a pc-relative call and
7739 the linker provides stubs when needed. */
7740 xoperands[1] = gen_label_rtx ();
7741 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7742 output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7743 targetm.asm_out.internal_label (asm_out_file, "L",
7744 CODE_LABEL_NUMBER (xoperands[1]));
7745 output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7747 else if (TARGET_GAS && !TARGET_SOM
7748 && (TARGET_LONG_PIC_PCREL_CALL || local_call))
7750 /* GAS currently can't generate the relocations that
7751 are needed for the SOM linker under HP-UX using this
7752 sequence. The GNU linker doesn't generate the stubs
7753 that are needed for external calls on TARGET_ELF32
7754 with this sequence. For now, we have to use a
7755 longer plabel sequence when using GAS. */
7756 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7757 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1",
7758 xoperands);
7759 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1",
7760 xoperands);
7762 else
7764 /* Emit a long plabel-based call sequence. This is
7765 essentially an inline implementation of $$dyncall.
7766 We don't actually try to call $$dyncall as this is
7767 as difficult as calling the function itself. */
7768 xoperands[0] = get_deferred_plabel (call_dest);
7769 xoperands[1] = gen_label_rtx ();
7771 /* Since the call is indirect, FP arguments in registers
7772 need to be copied to the general registers. Then, the
7773 argument relocation stub will copy them back. */
7774 if (TARGET_SOM)
7775 copy_fp_args (insn);
7777 if (flag_pic)
7779 output_asm_insn ("addil LT'%0,%%r19", xoperands);
7780 output_asm_insn ("ldw RT'%0(%%r1),%%r1", xoperands);
7781 output_asm_insn ("ldw 0(%%r1),%%r1", xoperands);
7783 else
7785 output_asm_insn ("addil LR'%0-$global$,%%r27",
7786 xoperands);
7787 output_asm_insn ("ldw RR'%0-$global$(%%r1),%%r1",
7788 xoperands);
7791 output_asm_insn ("bb,>=,n %%r1,30,.+16", xoperands);
7792 output_asm_insn ("depi 0,31,2,%%r1", xoperands);
7793 output_asm_insn ("ldw 4(%%sr0,%%r1),%%r19", xoperands);
7794 output_asm_insn ("ldw 0(%%sr0,%%r1),%%r1", xoperands);
7796 if (!sibcall && !TARGET_PA_20)
7798 output_asm_insn ("{bl|b,l} .+8,%%r2", xoperands);
7799 if (TARGET_NO_SPACE_REGS || (local_call && !flag_pic))
7800 output_asm_insn ("addi 8,%%r2,%%r2", xoperands);
7801 else
7802 output_asm_insn ("addi 16,%%r2,%%r2", xoperands);
7806 if (TARGET_PA_20)
7808 if (sibcall)
7809 output_asm_insn ("bve (%%r1)", xoperands);
7810 else
7812 if (indirect_call)
7814 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7815 output_asm_insn ("stw %%r2,-24(%%sp)", xoperands);
7816 delay_slot_filled = 1;
7818 else
7819 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7822 else
7824 if (!TARGET_NO_SPACE_REGS && (!local_call || flag_pic))
7825 output_asm_insn ("ldsid (%%r1),%%r31\n\tmtsp %%r31,%%sr0",
7826 xoperands);
7828 if (sibcall)
7830 if (TARGET_NO_SPACE_REGS || (local_call && !flag_pic))
7831 output_asm_insn ("be 0(%%sr4,%%r1)", xoperands);
7832 else
7833 output_asm_insn ("be 0(%%sr0,%%r1)", xoperands);
7835 else
7837 if (TARGET_NO_SPACE_REGS || (local_call && !flag_pic))
7838 output_asm_insn ("ble 0(%%sr4,%%r1)", xoperands);
7839 else
7840 output_asm_insn ("ble 0(%%sr0,%%r1)", xoperands);
7842 if (indirect_call)
7843 output_asm_insn ("stw %%r31,-24(%%sp)", xoperands);
7844 else
7845 output_asm_insn ("copy %%r31,%%r2", xoperands);
7846 delay_slot_filled = 1;
7853 if (!delay_slot_filled && (seq_length == 0 || delay_insn_deleted))
7854 output_asm_insn ("nop", xoperands);
7856 /* We are done if there isn't a jump in the delay slot. */
7857 if (seq_length == 0
7858 || delay_insn_deleted
7859 || GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
7860 return "";
7862 /* A sibcall should never have a branch in the delay slot. */
7863 gcc_assert (!sibcall);
7865 /* This call has an unconditional jump in its delay slot. */
7866 xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
7868 if (!delay_slot_filled && INSN_ADDRESSES_SET_P ())
7870 /* See if the return address can be adjusted. Use the containing
7871 sequence insn's address. This would break the regular call/return@
7872 relationship assumed by the table based eh unwinder, so only do that
7873 if the call is not possibly throwing. */
7874 rtx seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
7875 int distance = (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
7876 - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8);
7878 if (VAL_14_BITS_P (distance)
7879 && !(can_throw_internal (insn) || can_throw_external (insn)))
7881 xoperands[1] = gen_label_rtx ();
7882 output_asm_insn ("ldo %0-%1(%%r2),%%r2", xoperands);
7883 targetm.asm_out.internal_label (asm_out_file, "L",
7884 CODE_LABEL_NUMBER (xoperands[1]));
7886 else
7887 output_asm_insn ("nop\n\tb,n %0", xoperands);
7889 else
7890 output_asm_insn ("b,n %0", xoperands);
7892 /* Delete the jump. */
7893 SET_INSN_DELETED (NEXT_INSN (insn));
7895 return "";
7898 /* Return the attribute length of the indirect call instruction INSN.
7899 The length must match the code generated by output_indirect call.
7900 The returned length includes the delay slot. Currently, the delay
7901 slot of an indirect call sequence is not exposed and it is used by
7902 the sequence itself. */
7905 attr_length_indirect_call (rtx insn)
7907 unsigned long distance = -1;
7908 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7910 if (INSN_ADDRESSES_SET_P ())
7912 distance = (total + insn_current_reference_address (insn));
7913 if (distance < total)
7914 distance = -1;
7917 if (TARGET_64BIT)
7918 return 12;
7920 if (TARGET_FAST_INDIRECT_CALLS
7921 || (!TARGET_PORTABLE_RUNTIME
7922 && ((TARGET_PA_20 && !TARGET_SOM && distance < 7600000)
7923 || distance < 240000)))
7924 return 8;
7926 if (flag_pic)
7927 return 24;
7929 if (TARGET_PORTABLE_RUNTIME)
7930 return 20;
7932 /* Out of reach, can use ble. */
7933 return 12;
7936 const char *
7937 output_indirect_call (rtx insn, rtx call_dest)
7939 rtx xoperands[1];
7941 if (TARGET_64BIT)
7943 xoperands[0] = call_dest;
7944 output_asm_insn ("ldd 16(%0),%%r2", xoperands);
7945 output_asm_insn ("bve,l (%%r2),%%r2\n\tldd 24(%0),%%r27", xoperands);
7946 return "";
7949 /* First the special case for kernels, level 0 systems, etc. */
7950 if (TARGET_FAST_INDIRECT_CALLS)
7951 return "ble 0(%%sr4,%%r22)\n\tcopy %%r31,%%r2";
7953 /* Now the normal case -- we can reach $$dyncall directly or
7954 we're sure that we can get there via a long-branch stub.
7956 No need to check target flags as the length uniquely identifies
7957 the remaining cases. */
7958 if (attr_length_indirect_call (insn) == 8)
7960 /* The HP linker sometimes substitutes a BLE for BL/B,L calls to
7961 $$dyncall. Since BLE uses %r31 as the link register, the 22-bit
7962 variant of the B,L instruction can't be used on the SOM target. */
7963 if (TARGET_PA_20 && !TARGET_SOM)
7964 return ".CALL\tARGW0=GR\n\tb,l $$dyncall,%%r2\n\tcopy %%r2,%%r31";
7965 else
7966 return ".CALL\tARGW0=GR\n\tbl $$dyncall,%%r31\n\tcopy %%r31,%%r2";
7969 /* Long millicode call, but we are not generating PIC or portable runtime
7970 code. */
7971 if (attr_length_indirect_call (insn) == 12)
7972 return ".CALL\tARGW0=GR\n\tldil L'$$dyncall,%%r2\n\tble R'$$dyncall(%%sr4,%%r2)\n\tcopy %%r31,%%r2";
7974 /* Long millicode call for portable runtime. */
7975 if (attr_length_indirect_call (insn) == 20)
7976 return "ldil L'$$dyncall,%%r31\n\tldo R'$$dyncall(%%r31),%%r31\n\tblr %%r0,%%r2\n\tbv,n %%r0(%%r31)\n\tnop";
7978 /* We need a long PIC call to $$dyncall. */
7979 xoperands[0] = NULL_RTX;
7980 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7981 if (TARGET_SOM || !TARGET_GAS)
7983 xoperands[0] = gen_label_rtx ();
7984 output_asm_insn ("addil L'$$dyncall-%0,%%r1", xoperands);
7985 targetm.asm_out.internal_label (asm_out_file, "L",
7986 CODE_LABEL_NUMBER (xoperands[0]));
7987 output_asm_insn ("ldo R'$$dyncall-%0(%%r1),%%r1", xoperands);
7989 else
7991 output_asm_insn ("addil L'$$dyncall-$PIC_pcrel$0+4,%%r1", xoperands);
7992 output_asm_insn ("ldo R'$$dyncall-$PIC_pcrel$0+8(%%r1),%%r1",
7993 xoperands);
7995 output_asm_insn ("blr %%r0,%%r2", xoperands);
7996 output_asm_insn ("bv,n %%r0(%%r1)\n\tnop", xoperands);
7997 return "";
8000 /* Return the total length of the save and restore instructions needed for
8001 the data linkage table pointer (i.e., the PIC register) across the call
8002 instruction INSN. No-return calls do not require a save and restore.
8003 In addition, we may be able to avoid the save and restore for calls
8004 within the same translation unit. */
8007 attr_length_save_restore_dltp (rtx insn)
8009 if (find_reg_note (insn, REG_NORETURN, NULL_RTX))
8010 return 0;
8012 return 8;
8015 /* In HPUX 8.0's shared library scheme, special relocations are needed
8016 for function labels if they might be passed to a function
8017 in a shared library (because shared libraries don't live in code
8018 space), and special magic is needed to construct their address. */
8020 void
8021 hppa_encode_label (rtx sym)
8023 const char *str = XSTR (sym, 0);
8024 int len = strlen (str) + 1;
8025 char *newstr, *p;
8027 p = newstr = XALLOCAVEC (char, len + 1);
8028 *p++ = '@';
8029 strcpy (p, str);
8031 XSTR (sym, 0) = ggc_alloc_string (newstr, len);
8034 static void
8035 pa_encode_section_info (tree decl, rtx rtl, int first)
8037 int old_referenced = 0;
8039 if (!first && MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
8040 old_referenced
8041 = SYMBOL_REF_FLAGS (XEXP (rtl, 0)) & SYMBOL_FLAG_REFERENCED;
8043 default_encode_section_info (decl, rtl, first);
8045 if (first && TEXT_SPACE_P (decl))
8047 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
8048 if (TREE_CODE (decl) == FUNCTION_DECL)
8049 hppa_encode_label (XEXP (rtl, 0));
8051 else if (old_referenced)
8052 SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= old_referenced;
8055 /* This is sort of inverse to pa_encode_section_info. */
8057 static const char *
8058 pa_strip_name_encoding (const char *str)
8060 str += (*str == '@');
8061 str += (*str == '*');
8062 return str;
8066 function_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8068 return GET_CODE (op) == SYMBOL_REF && FUNCTION_NAME_P (XSTR (op, 0));
8071 /* Returns 1 if OP is a function label involved in a simple addition
8072 with a constant. Used to keep certain patterns from matching
8073 during instruction combination. */
8075 is_function_label_plus_const (rtx op)
8077 /* Strip off any CONST. */
8078 if (GET_CODE (op) == CONST)
8079 op = XEXP (op, 0);
8081 return (GET_CODE (op) == PLUS
8082 && function_label_operand (XEXP (op, 0), Pmode)
8083 && GET_CODE (XEXP (op, 1)) == CONST_INT);
8086 /* Output assembly code for a thunk to FUNCTION. */
8088 static void
8089 pa_asm_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
8090 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
8091 tree function)
8093 static unsigned int current_thunk_number;
8094 int val_14 = VAL_14_BITS_P (delta);
8095 unsigned int old_last_address = last_address, nbytes = 0;
8096 char label[16];
8097 rtx xoperands[4];
8099 xoperands[0] = XEXP (DECL_RTL (function), 0);
8100 xoperands[1] = XEXP (DECL_RTL (thunk_fndecl), 0);
8101 xoperands[2] = GEN_INT (delta);
8103 ASM_OUTPUT_LABEL (file, XSTR (xoperands[1], 0));
8104 fprintf (file, "\t.PROC\n\t.CALLINFO FRAME=0,NO_CALLS\n\t.ENTRY\n");
8106 /* Output the thunk. We know that the function is in the same
8107 translation unit (i.e., the same space) as the thunk, and that
8108 thunks are output after their method. Thus, we don't need an
8109 external branch to reach the function. With SOM and GAS,
8110 functions and thunks are effectively in different sections.
8111 Thus, we can always use a IA-relative branch and the linker
8112 will add a long branch stub if necessary.
8114 However, we have to be careful when generating PIC code on the
8115 SOM port to ensure that the sequence does not transfer to an
8116 import stub for the target function as this could clobber the
8117 return value saved at SP-24. This would also apply to the
8118 32-bit linux port if the multi-space model is implemented. */
8119 if ((!TARGET_LONG_CALLS && TARGET_SOM && !TARGET_PORTABLE_RUNTIME
8120 && !(flag_pic && TREE_PUBLIC (function))
8121 && (TARGET_GAS || last_address < 262132))
8122 || (!TARGET_LONG_CALLS && !TARGET_SOM && !TARGET_PORTABLE_RUNTIME
8123 && ((targetm.have_named_sections
8124 && DECL_SECTION_NAME (thunk_fndecl) != NULL
8125 /* The GNU 64-bit linker has rather poor stub management.
8126 So, we use a long branch from thunks that aren't in
8127 the same section as the target function. */
8128 && ((!TARGET_64BIT
8129 && (DECL_SECTION_NAME (thunk_fndecl)
8130 != DECL_SECTION_NAME (function)))
8131 || ((DECL_SECTION_NAME (thunk_fndecl)
8132 == DECL_SECTION_NAME (function))
8133 && last_address < 262132)))
8134 || (targetm.have_named_sections
8135 && DECL_SECTION_NAME (thunk_fndecl) == NULL
8136 && DECL_SECTION_NAME (function) == NULL
8137 && last_address < 262132)
8138 || (!targetm.have_named_sections && last_address < 262132))))
8140 if (!val_14)
8141 output_asm_insn ("addil L'%2,%%r26", xoperands);
8143 output_asm_insn ("b %0", xoperands);
8145 if (val_14)
8147 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8148 nbytes += 8;
8150 else
8152 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8153 nbytes += 12;
8156 else if (TARGET_64BIT)
8158 /* We only have one call-clobbered scratch register, so we can't
8159 make use of the delay slot if delta doesn't fit in 14 bits. */
8160 if (!val_14)
8162 output_asm_insn ("addil L'%2,%%r26", xoperands);
8163 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8166 output_asm_insn ("b,l .+8,%%r1", xoperands);
8168 if (TARGET_GAS)
8170 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
8171 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
8173 else
8175 xoperands[3] = GEN_INT (val_14 ? 8 : 16);
8176 output_asm_insn ("addil L'%0-%1-%3,%%r1", xoperands);
8179 if (val_14)
8181 output_asm_insn ("bv %%r0(%%r1)", xoperands);
8182 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8183 nbytes += 20;
8185 else
8187 output_asm_insn ("bv,n %%r0(%%r1)", xoperands);
8188 nbytes += 24;
8191 else if (TARGET_PORTABLE_RUNTIME)
8193 output_asm_insn ("ldil L'%0,%%r1", xoperands);
8194 output_asm_insn ("ldo R'%0(%%r1),%%r22", xoperands);
8196 if (!val_14)
8197 output_asm_insn ("addil L'%2,%%r26", xoperands);
8199 output_asm_insn ("bv %%r0(%%r22)", xoperands);
8201 if (val_14)
8203 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8204 nbytes += 16;
8206 else
8208 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8209 nbytes += 20;
8212 else if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8214 /* The function is accessible from outside this module. The only
8215 way to avoid an import stub between the thunk and function is to
8216 call the function directly with an indirect sequence similar to
8217 that used by $$dyncall. This is possible because $$dyncall acts
8218 as the import stub in an indirect call. */
8219 ASM_GENERATE_INTERNAL_LABEL (label, "LTHN", current_thunk_number);
8220 xoperands[3] = gen_rtx_SYMBOL_REF (Pmode, label);
8221 output_asm_insn ("addil LT'%3,%%r19", xoperands);
8222 output_asm_insn ("ldw RT'%3(%%r1),%%r22", xoperands);
8223 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8224 output_asm_insn ("bb,>=,n %%r22,30,.+16", xoperands);
8225 output_asm_insn ("depi 0,31,2,%%r22", xoperands);
8226 output_asm_insn ("ldw 4(%%sr0,%%r22),%%r19", xoperands);
8227 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8229 if (!val_14)
8231 output_asm_insn ("addil L'%2,%%r26", xoperands);
8232 nbytes += 4;
8235 if (TARGET_PA_20)
8237 output_asm_insn ("bve (%%r22)", xoperands);
8238 nbytes += 36;
8240 else if (TARGET_NO_SPACE_REGS)
8242 output_asm_insn ("be 0(%%sr4,%%r22)", xoperands);
8243 nbytes += 36;
8245 else
8247 output_asm_insn ("ldsid (%%sr0,%%r22),%%r21", xoperands);
8248 output_asm_insn ("mtsp %%r21,%%sr0", xoperands);
8249 output_asm_insn ("be 0(%%sr0,%%r22)", xoperands);
8250 nbytes += 44;
8253 if (val_14)
8254 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8255 else
8256 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8258 else if (flag_pic)
8260 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
8262 if (TARGET_SOM || !TARGET_GAS)
8264 output_asm_insn ("addil L'%0-%1-8,%%r1", xoperands);
8265 output_asm_insn ("ldo R'%0-%1-8(%%r1),%%r22", xoperands);
8267 else
8269 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
8270 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r22", xoperands);
8273 if (!val_14)
8274 output_asm_insn ("addil L'%2,%%r26", xoperands);
8276 output_asm_insn ("bv %%r0(%%r22)", xoperands);
8278 if (val_14)
8280 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8281 nbytes += 20;
8283 else
8285 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8286 nbytes += 24;
8289 else
8291 if (!val_14)
8292 output_asm_insn ("addil L'%2,%%r26", xoperands);
8294 output_asm_insn ("ldil L'%0,%%r22", xoperands);
8295 output_asm_insn ("be R'%0(%%sr4,%%r22)", xoperands);
8297 if (val_14)
8299 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8300 nbytes += 12;
8302 else
8304 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8305 nbytes += 16;
8309 fprintf (file, "\t.EXIT\n\t.PROCEND\n");
8311 if (TARGET_SOM && TARGET_GAS)
8313 /* We done with this subspace except possibly for some additional
8314 debug information. Forget that we are in this subspace to ensure
8315 that the next function is output in its own subspace. */
8316 in_section = NULL;
8317 cfun->machine->in_nsubspa = 2;
8320 if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8322 switch_to_section (data_section);
8323 output_asm_insn (".align 4", xoperands);
8324 ASM_OUTPUT_LABEL (file, label);
8325 output_asm_insn (".word P'%0", xoperands);
8328 current_thunk_number++;
8329 nbytes = ((nbytes + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
8330 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
8331 last_address += nbytes;
8332 if (old_last_address > last_address)
8333 last_address = UINT_MAX;
8334 update_total_code_bytes (nbytes);
8337 /* Only direct calls to static functions are allowed to be sibling (tail)
8338 call optimized.
8340 This restriction is necessary because some linker generated stubs will
8341 store return pointers into rp' in some cases which might clobber a
8342 live value already in rp'.
8344 In a sibcall the current function and the target function share stack
8345 space. Thus if the path to the current function and the path to the
8346 target function save a value in rp', they save the value into the
8347 same stack slot, which has undesirable consequences.
8349 Because of the deferred binding nature of shared libraries any function
8350 with external scope could be in a different load module and thus require
8351 rp' to be saved when calling that function. So sibcall optimizations
8352 can only be safe for static function.
8354 Note that GCC never needs return value relocations, so we don't have to
8355 worry about static calls with return value relocations (which require
8356 saving rp').
8358 It is safe to perform a sibcall optimization when the target function
8359 will never return. */
8360 static bool
8361 pa_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
8363 if (TARGET_PORTABLE_RUNTIME)
8364 return false;
8366 /* Sibcalls are ok for TARGET_ELF32 as along as the linker is used in
8367 single subspace mode and the call is not indirect. As far as I know,
8368 there is no operating system support for the multiple subspace mode.
8369 It might be possible to support indirect calls if we didn't use
8370 $$dyncall (see the indirect sequence generated in output_call). */
8371 if (TARGET_ELF32)
8372 return (decl != NULL_TREE);
8374 /* Sibcalls are not ok because the arg pointer register is not a fixed
8375 register. This prevents the sibcall optimization from occurring. In
8376 addition, there are problems with stub placement using GNU ld. This
8377 is because a normal sibcall branch uses a 17-bit relocation while
8378 a regular call branch uses a 22-bit relocation. As a result, more
8379 care needs to be taken in the placement of long-branch stubs. */
8380 if (TARGET_64BIT)
8381 return false;
8383 /* Sibcalls are only ok within a translation unit. */
8384 return (decl && !TREE_PUBLIC (decl));
8387 /* ??? Addition is not commutative on the PA due to the weird implicit
8388 space register selection rules for memory addresses. Therefore, we
8389 don't consider a + b == b + a, as this might be inside a MEM. */
8390 static bool
8391 pa_commutative_p (const_rtx x, int outer_code)
8393 return (COMMUTATIVE_P (x)
8394 && (TARGET_NO_SPACE_REGS
8395 || (outer_code != UNKNOWN && outer_code != MEM)
8396 || GET_CODE (x) != PLUS));
8399 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8400 use in fmpyadd instructions. */
8402 fmpyaddoperands (rtx *operands)
8404 enum machine_mode mode = GET_MODE (operands[0]);
8406 /* Must be a floating point mode. */
8407 if (mode != SFmode && mode != DFmode)
8408 return 0;
8410 /* All modes must be the same. */
8411 if (! (mode == GET_MODE (operands[1])
8412 && mode == GET_MODE (operands[2])
8413 && mode == GET_MODE (operands[3])
8414 && mode == GET_MODE (operands[4])
8415 && mode == GET_MODE (operands[5])))
8416 return 0;
8418 /* All operands must be registers. */
8419 if (! (GET_CODE (operands[1]) == REG
8420 && GET_CODE (operands[2]) == REG
8421 && GET_CODE (operands[3]) == REG
8422 && GET_CODE (operands[4]) == REG
8423 && GET_CODE (operands[5]) == REG))
8424 return 0;
8426 /* Only 2 real operands to the addition. One of the input operands must
8427 be the same as the output operand. */
8428 if (! rtx_equal_p (operands[3], operands[4])
8429 && ! rtx_equal_p (operands[3], operands[5]))
8430 return 0;
8432 /* Inout operand of add cannot conflict with any operands from multiply. */
8433 if (rtx_equal_p (operands[3], operands[0])
8434 || rtx_equal_p (operands[3], operands[1])
8435 || rtx_equal_p (operands[3], operands[2]))
8436 return 0;
8438 /* multiply cannot feed into addition operands. */
8439 if (rtx_equal_p (operands[4], operands[0])
8440 || rtx_equal_p (operands[5], operands[0]))
8441 return 0;
8443 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
8444 if (mode == SFmode
8445 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8446 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8447 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8448 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8449 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8450 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8451 return 0;
8453 /* Passed. Operands are suitable for fmpyadd. */
8454 return 1;
8457 #if !defined(USE_COLLECT2)
8458 static void
8459 pa_asm_out_constructor (rtx symbol, int priority)
8461 if (!function_label_operand (symbol, VOIDmode))
8462 hppa_encode_label (symbol);
8464 #ifdef CTORS_SECTION_ASM_OP
8465 default_ctor_section_asm_out_constructor (symbol, priority);
8466 #else
8467 # ifdef TARGET_ASM_NAMED_SECTION
8468 default_named_section_asm_out_constructor (symbol, priority);
8469 # else
8470 default_stabs_asm_out_constructor (symbol, priority);
8471 # endif
8472 #endif
8475 static void
8476 pa_asm_out_destructor (rtx symbol, int priority)
8478 if (!function_label_operand (symbol, VOIDmode))
8479 hppa_encode_label (symbol);
8481 #ifdef DTORS_SECTION_ASM_OP
8482 default_dtor_section_asm_out_destructor (symbol, priority);
8483 #else
8484 # ifdef TARGET_ASM_NAMED_SECTION
8485 default_named_section_asm_out_destructor (symbol, priority);
8486 # else
8487 default_stabs_asm_out_destructor (symbol, priority);
8488 # endif
8489 #endif
8491 #endif
8493 /* This function places uninitialized global data in the bss section.
8494 The ASM_OUTPUT_ALIGNED_BSS macro needs to be defined to call this
8495 function on the SOM port to prevent uninitialized global data from
8496 being placed in the data section. */
8498 void
8499 pa_asm_output_aligned_bss (FILE *stream,
8500 const char *name,
8501 unsigned HOST_WIDE_INT size,
8502 unsigned int align)
8504 switch_to_section (bss_section);
8505 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8507 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
8508 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object");
8509 #endif
8511 #ifdef ASM_OUTPUT_SIZE_DIRECTIVE
8512 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
8513 #endif
8515 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8516 ASM_OUTPUT_LABEL (stream, name);
8517 fprintf (stream, "\t.block "HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8520 /* Both the HP and GNU assemblers under HP-UX provide a .comm directive
8521 that doesn't allow the alignment of global common storage to be directly
8522 specified. The SOM linker aligns common storage based on the rounded
8523 value of the NUM_BYTES parameter in the .comm directive. It's not
8524 possible to use the .align directive as it doesn't affect the alignment
8525 of the label associated with a .comm directive. */
8527 void
8528 pa_asm_output_aligned_common (FILE *stream,
8529 const char *name,
8530 unsigned HOST_WIDE_INT size,
8531 unsigned int align)
8533 unsigned int max_common_align;
8535 max_common_align = TARGET_64BIT ? 128 : (size >= 4096 ? 256 : 64);
8536 if (align > max_common_align)
8538 warning (0, "alignment (%u) for %s exceeds maximum alignment "
8539 "for global common data. Using %u",
8540 align / BITS_PER_UNIT, name, max_common_align / BITS_PER_UNIT);
8541 align = max_common_align;
8544 switch_to_section (bss_section);
8546 assemble_name (stream, name);
8547 fprintf (stream, "\t.comm "HOST_WIDE_INT_PRINT_UNSIGNED"\n",
8548 MAX (size, align / BITS_PER_UNIT));
8551 /* We can't use .comm for local common storage as the SOM linker effectively
8552 treats the symbol as universal and uses the same storage for local symbols
8553 with the same name in different object files. The .block directive
8554 reserves an uninitialized block of storage. However, it's not common
8555 storage. Fortunately, GCC never requests common storage with the same
8556 name in any given translation unit. */
8558 void
8559 pa_asm_output_aligned_local (FILE *stream,
8560 const char *name,
8561 unsigned HOST_WIDE_INT size,
8562 unsigned int align)
8564 switch_to_section (bss_section);
8565 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8567 #ifdef LOCAL_ASM_OP
8568 fprintf (stream, "%s", LOCAL_ASM_OP);
8569 assemble_name (stream, name);
8570 fprintf (stream, "\n");
8571 #endif
8573 ASM_OUTPUT_LABEL (stream, name);
8574 fprintf (stream, "\t.block "HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8577 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8578 use in fmpysub instructions. */
8580 fmpysuboperands (rtx *operands)
8582 enum machine_mode mode = GET_MODE (operands[0]);
8584 /* Must be a floating point mode. */
8585 if (mode != SFmode && mode != DFmode)
8586 return 0;
8588 /* All modes must be the same. */
8589 if (! (mode == GET_MODE (operands[1])
8590 && mode == GET_MODE (operands[2])
8591 && mode == GET_MODE (operands[3])
8592 && mode == GET_MODE (operands[4])
8593 && mode == GET_MODE (operands[5])))
8594 return 0;
8596 /* All operands must be registers. */
8597 if (! (GET_CODE (operands[1]) == REG
8598 && GET_CODE (operands[2]) == REG
8599 && GET_CODE (operands[3]) == REG
8600 && GET_CODE (operands[4]) == REG
8601 && GET_CODE (operands[5]) == REG))
8602 return 0;
8604 /* Only 2 real operands to the subtraction. Subtraction is not a commutative
8605 operation, so operands[4] must be the same as operand[3]. */
8606 if (! rtx_equal_p (operands[3], operands[4]))
8607 return 0;
8609 /* multiply cannot feed into subtraction. */
8610 if (rtx_equal_p (operands[5], operands[0]))
8611 return 0;
8613 /* Inout operand of sub cannot conflict with any operands from multiply. */
8614 if (rtx_equal_p (operands[3], operands[0])
8615 || rtx_equal_p (operands[3], operands[1])
8616 || rtx_equal_p (operands[3], operands[2]))
8617 return 0;
8619 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
8620 if (mode == SFmode
8621 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8622 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8623 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8624 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8625 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8626 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8627 return 0;
8629 /* Passed. Operands are suitable for fmpysub. */
8630 return 1;
8633 /* Return 1 if the given constant is 2, 4, or 8. These are the valid
8634 constants for shadd instructions. */
8636 shadd_constant_p (int val)
8638 if (val == 2 || val == 4 || val == 8)
8639 return 1;
8640 else
8641 return 0;
8644 /* Return 1 if OP is valid as a base or index register in a
8645 REG+REG address. */
8648 borx_reg_operand (rtx op, enum machine_mode mode)
8650 if (GET_CODE (op) != REG)
8651 return 0;
8653 /* We must reject virtual registers as the only expressions that
8654 can be instantiated are REG and REG+CONST. */
8655 if (op == virtual_incoming_args_rtx
8656 || op == virtual_stack_vars_rtx
8657 || op == virtual_stack_dynamic_rtx
8658 || op == virtual_outgoing_args_rtx
8659 || op == virtual_cfa_rtx)
8660 return 0;
8662 /* While it's always safe to index off the frame pointer, it's not
8663 profitable to do so when the frame pointer is being eliminated. */
8664 if (!reload_completed
8665 && flag_omit_frame_pointer
8666 && !cfun->calls_alloca
8667 && op == frame_pointer_rtx)
8668 return 0;
8670 return register_operand (op, mode);
8673 /* Return 1 if this operand is anything other than a hard register. */
8676 non_hard_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8678 return ! (GET_CODE (op) == REG && REGNO (op) < FIRST_PSEUDO_REGISTER);
8681 /* Return TRUE if INSN branches forward. */
8683 static bool
8684 forward_branch_p (rtx insn)
8686 rtx lab = JUMP_LABEL (insn);
8688 /* The INSN must have a jump label. */
8689 gcc_assert (lab != NULL_RTX);
8691 if (INSN_ADDRESSES_SET_P ())
8692 return INSN_ADDRESSES (INSN_UID (lab)) > INSN_ADDRESSES (INSN_UID (insn));
8694 while (insn)
8696 if (insn == lab)
8697 return true;
8698 else
8699 insn = NEXT_INSN (insn);
8702 return false;
8705 /* Return 1 if OP is an equality comparison, else return 0. */
8707 eq_neq_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8709 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
8712 /* Return 1 if INSN is in the delay slot of a call instruction. */
8714 jump_in_call_delay (rtx insn)
8717 if (GET_CODE (insn) != JUMP_INSN)
8718 return 0;
8720 if (PREV_INSN (insn)
8721 && PREV_INSN (PREV_INSN (insn))
8722 && GET_CODE (next_real_insn (PREV_INSN (PREV_INSN (insn)))) == INSN)
8724 rtx test_insn = next_real_insn (PREV_INSN (PREV_INSN (insn)));
8726 return (GET_CODE (PATTERN (test_insn)) == SEQUENCE
8727 && XVECEXP (PATTERN (test_insn), 0, 1) == insn);
8730 else
8731 return 0;
8734 /* Output an unconditional move and branch insn. */
8736 const char *
8737 output_parallel_movb (rtx *operands, rtx insn)
8739 int length = get_attr_length (insn);
8741 /* These are the cases in which we win. */
8742 if (length == 4)
8743 return "mov%I1b,tr %1,%0,%2";
8745 /* None of the following cases win, but they don't lose either. */
8746 if (length == 8)
8748 if (dbr_sequence_length () == 0)
8750 /* Nothing in the delay slot, fake it by putting the combined
8751 insn (the copy or add) in the delay slot of a bl. */
8752 if (GET_CODE (operands[1]) == CONST_INT)
8753 return "b %2\n\tldi %1,%0";
8754 else
8755 return "b %2\n\tcopy %1,%0";
8757 else
8759 /* Something in the delay slot, but we've got a long branch. */
8760 if (GET_CODE (operands[1]) == CONST_INT)
8761 return "ldi %1,%0\n\tb %2";
8762 else
8763 return "copy %1,%0\n\tb %2";
8767 if (GET_CODE (operands[1]) == CONST_INT)
8768 output_asm_insn ("ldi %1,%0", operands);
8769 else
8770 output_asm_insn ("copy %1,%0", operands);
8771 return output_lbranch (operands[2], insn, 1);
8774 /* Output an unconditional add and branch insn. */
8776 const char *
8777 output_parallel_addb (rtx *operands, rtx insn)
8779 int length = get_attr_length (insn);
8781 /* To make life easy we want operand0 to be the shared input/output
8782 operand and operand1 to be the readonly operand. */
8783 if (operands[0] == operands[1])
8784 operands[1] = operands[2];
8786 /* These are the cases in which we win. */
8787 if (length == 4)
8788 return "add%I1b,tr %1,%0,%3";
8790 /* None of the following cases win, but they don't lose either. */
8791 if (length == 8)
8793 if (dbr_sequence_length () == 0)
8794 /* Nothing in the delay slot, fake it by putting the combined
8795 insn (the copy or add) in the delay slot of a bl. */
8796 return "b %3\n\tadd%I1 %1,%0,%0";
8797 else
8798 /* Something in the delay slot, but we've got a long branch. */
8799 return "add%I1 %1,%0,%0\n\tb %3";
8802 output_asm_insn ("add%I1 %1,%0,%0", operands);
8803 return output_lbranch (operands[3], insn, 1);
8806 /* Return nonzero if INSN (a jump insn) immediately follows a call
8807 to a named function. This is used to avoid filling the delay slot
8808 of the jump since it can usually be eliminated by modifying RP in
8809 the delay slot of the call. */
8812 following_call (rtx insn)
8814 if (! TARGET_JUMP_IN_DELAY)
8815 return 0;
8817 /* Find the previous real insn, skipping NOTEs. */
8818 insn = PREV_INSN (insn);
8819 while (insn && GET_CODE (insn) == NOTE)
8820 insn = PREV_INSN (insn);
8822 /* Check for CALL_INSNs and millicode calls. */
8823 if (insn
8824 && ((GET_CODE (insn) == CALL_INSN
8825 && get_attr_type (insn) != TYPE_DYNCALL)
8826 || (GET_CODE (insn) == INSN
8827 && GET_CODE (PATTERN (insn)) != SEQUENCE
8828 && GET_CODE (PATTERN (insn)) != USE
8829 && GET_CODE (PATTERN (insn)) != CLOBBER
8830 && get_attr_type (insn) == TYPE_MILLI)))
8831 return 1;
8833 return 0;
8836 /* We use this hook to perform a PA specific optimization which is difficult
8837 to do in earlier passes.
8839 We want the delay slots of branches within jump tables to be filled.
8840 None of the compiler passes at the moment even has the notion that a
8841 PA jump table doesn't contain addresses, but instead contains actual
8842 instructions!
8844 Because we actually jump into the table, the addresses of each entry
8845 must stay constant in relation to the beginning of the table (which
8846 itself must stay constant relative to the instruction to jump into
8847 it). I don't believe we can guarantee earlier passes of the compiler
8848 will adhere to those rules.
8850 So, late in the compilation process we find all the jump tables, and
8851 expand them into real code -- e.g. each entry in the jump table vector
8852 will get an appropriate label followed by a jump to the final target.
8854 Reorg and the final jump pass can then optimize these branches and
8855 fill their delay slots. We end up with smaller, more efficient code.
8857 The jump instructions within the table are special; we must be able
8858 to identify them during assembly output (if the jumps don't get filled
8859 we need to emit a nop rather than nullifying the delay slot)). We
8860 identify jumps in switch tables by using insns with the attribute
8861 type TYPE_BTABLE_BRANCH.
8863 We also surround the jump table itself with BEGIN_BRTAB and END_BRTAB
8864 insns. This serves two purposes, first it prevents jump.c from
8865 noticing that the last N entries in the table jump to the instruction
8866 immediately after the table and deleting the jumps. Second, those
8867 insns mark where we should emit .begin_brtab and .end_brtab directives
8868 when using GAS (allows for better link time optimizations). */
8870 static void
8871 pa_reorg (void)
8873 rtx insn;
8875 remove_useless_addtr_insns (1);
8877 if (pa_cpu < PROCESSOR_8000)
8878 pa_combine_instructions ();
8881 /* This is fairly cheap, so always run it if optimizing. */
8882 if (optimize > 0 && !TARGET_BIG_SWITCH)
8884 /* Find and explode all ADDR_VEC or ADDR_DIFF_VEC insns. */
8885 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
8887 rtx pattern, tmp, location, label;
8888 unsigned int length, i;
8890 /* Find an ADDR_VEC or ADDR_DIFF_VEC insn to explode. */
8891 if (GET_CODE (insn) != JUMP_INSN
8892 || (GET_CODE (PATTERN (insn)) != ADDR_VEC
8893 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
8894 continue;
8896 /* Emit marker for the beginning of the branch table. */
8897 emit_insn_before (gen_begin_brtab (), insn);
8899 pattern = PATTERN (insn);
8900 location = PREV_INSN (insn);
8901 length = XVECLEN (pattern, GET_CODE (pattern) == ADDR_DIFF_VEC);
8903 for (i = 0; i < length; i++)
8905 /* Emit a label before each jump to keep jump.c from
8906 removing this code. */
8907 tmp = gen_label_rtx ();
8908 LABEL_NUSES (tmp) = 1;
8909 emit_label_after (tmp, location);
8910 location = NEXT_INSN (location);
8912 if (GET_CODE (pattern) == ADDR_VEC)
8913 label = XEXP (XVECEXP (pattern, 0, i), 0);
8914 else
8915 label = XEXP (XVECEXP (pattern, 1, i), 0);
8917 tmp = gen_short_jump (label);
8919 /* Emit the jump itself. */
8920 tmp = emit_jump_insn_after (tmp, location);
8921 JUMP_LABEL (tmp) = label;
8922 LABEL_NUSES (label)++;
8923 location = NEXT_INSN (location);
8925 /* Emit a BARRIER after the jump. */
8926 emit_barrier_after (location);
8927 location = NEXT_INSN (location);
8930 /* Emit marker for the end of the branch table. */
8931 emit_insn_before (gen_end_brtab (), location);
8932 location = NEXT_INSN (location);
8933 emit_barrier_after (location);
8935 /* Delete the ADDR_VEC or ADDR_DIFF_VEC. */
8936 delete_insn (insn);
8939 else
8941 /* Still need brtab marker insns. FIXME: the presence of these
8942 markers disables output of the branch table to readonly memory,
8943 and any alignment directives that might be needed. Possibly,
8944 the begin_brtab insn should be output before the label for the
8945 table. This doesn't matter at the moment since the tables are
8946 always output in the text section. */
8947 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
8949 /* Find an ADDR_VEC insn. */
8950 if (GET_CODE (insn) != JUMP_INSN
8951 || (GET_CODE (PATTERN (insn)) != ADDR_VEC
8952 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
8953 continue;
8955 /* Now generate markers for the beginning and end of the
8956 branch table. */
8957 emit_insn_before (gen_begin_brtab (), insn);
8958 emit_insn_after (gen_end_brtab (), insn);
8963 /* The PA has a number of odd instructions which can perform multiple
8964 tasks at once. On first generation PA machines (PA1.0 and PA1.1)
8965 it may be profitable to combine two instructions into one instruction
8966 with two outputs. It's not profitable PA2.0 machines because the
8967 two outputs would take two slots in the reorder buffers.
8969 This routine finds instructions which can be combined and combines
8970 them. We only support some of the potential combinations, and we
8971 only try common ways to find suitable instructions.
8973 * addb can add two registers or a register and a small integer
8974 and jump to a nearby (+-8k) location. Normally the jump to the
8975 nearby location is conditional on the result of the add, but by
8976 using the "true" condition we can make the jump unconditional.
8977 Thus addb can perform two independent operations in one insn.
8979 * movb is similar to addb in that it can perform a reg->reg
8980 or small immediate->reg copy and jump to a nearby (+-8k location).
8982 * fmpyadd and fmpysub can perform a FP multiply and either an
8983 FP add or FP sub if the operands of the multiply and add/sub are
8984 independent (there are other minor restrictions). Note both
8985 the fmpy and fadd/fsub can in theory move to better spots according
8986 to data dependencies, but for now we require the fmpy stay at a
8987 fixed location.
8989 * Many of the memory operations can perform pre & post updates
8990 of index registers. GCC's pre/post increment/decrement addressing
8991 is far too simple to take advantage of all the possibilities. This
8992 pass may not be suitable since those insns may not be independent.
8994 * comclr can compare two ints or an int and a register, nullify
8995 the following instruction and zero some other register. This
8996 is more difficult to use as it's harder to find an insn which
8997 will generate a comclr than finding something like an unconditional
8998 branch. (conditional moves & long branches create comclr insns).
9000 * Most arithmetic operations can conditionally skip the next
9001 instruction. They can be viewed as "perform this operation
9002 and conditionally jump to this nearby location" (where nearby
9003 is an insns away). These are difficult to use due to the
9004 branch length restrictions. */
9006 static void
9007 pa_combine_instructions (void)
9009 rtx anchor, new_rtx;
9011 /* This can get expensive since the basic algorithm is on the
9012 order of O(n^2) (or worse). Only do it for -O2 or higher
9013 levels of optimization. */
9014 if (optimize < 2)
9015 return;
9017 /* Walk down the list of insns looking for "anchor" insns which
9018 may be combined with "floating" insns. As the name implies,
9019 "anchor" instructions don't move, while "floating" insns may
9020 move around. */
9021 new_rtx = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, NULL_RTX, NULL_RTX));
9022 new_rtx = make_insn_raw (new_rtx);
9024 for (anchor = get_insns (); anchor; anchor = NEXT_INSN (anchor))
9026 enum attr_pa_combine_type anchor_attr;
9027 enum attr_pa_combine_type floater_attr;
9029 /* We only care about INSNs, JUMP_INSNs, and CALL_INSNs.
9030 Also ignore any special USE insns. */
9031 if ((GET_CODE (anchor) != INSN
9032 && GET_CODE (anchor) != JUMP_INSN
9033 && GET_CODE (anchor) != CALL_INSN)
9034 || GET_CODE (PATTERN (anchor)) == USE
9035 || GET_CODE (PATTERN (anchor)) == CLOBBER
9036 || GET_CODE (PATTERN (anchor)) == ADDR_VEC
9037 || GET_CODE (PATTERN (anchor)) == ADDR_DIFF_VEC)
9038 continue;
9040 anchor_attr = get_attr_pa_combine_type (anchor);
9041 /* See if anchor is an insn suitable for combination. */
9042 if (anchor_attr == PA_COMBINE_TYPE_FMPY
9043 || anchor_attr == PA_COMBINE_TYPE_FADDSUB
9044 || (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
9045 && ! forward_branch_p (anchor)))
9047 rtx floater;
9049 for (floater = PREV_INSN (anchor);
9050 floater;
9051 floater = PREV_INSN (floater))
9053 if (GET_CODE (floater) == NOTE
9054 || (GET_CODE (floater) == INSN
9055 && (GET_CODE (PATTERN (floater)) == USE
9056 || GET_CODE (PATTERN (floater)) == CLOBBER)))
9057 continue;
9059 /* Anything except a regular INSN will stop our search. */
9060 if (GET_CODE (floater) != INSN
9061 || GET_CODE (PATTERN (floater)) == ADDR_VEC
9062 || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
9064 floater = NULL_RTX;
9065 break;
9068 /* See if FLOATER is suitable for combination with the
9069 anchor. */
9070 floater_attr = get_attr_pa_combine_type (floater);
9071 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
9072 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
9073 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
9074 && floater_attr == PA_COMBINE_TYPE_FMPY))
9076 /* If ANCHOR and FLOATER can be combined, then we're
9077 done with this pass. */
9078 if (pa_can_combine_p (new_rtx, anchor, floater, 0,
9079 SET_DEST (PATTERN (floater)),
9080 XEXP (SET_SRC (PATTERN (floater)), 0),
9081 XEXP (SET_SRC (PATTERN (floater)), 1)))
9082 break;
9085 else if (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
9086 && floater_attr == PA_COMBINE_TYPE_ADDMOVE)
9088 if (GET_CODE (SET_SRC (PATTERN (floater))) == PLUS)
9090 if (pa_can_combine_p (new_rtx, anchor, floater, 0,
9091 SET_DEST (PATTERN (floater)),
9092 XEXP (SET_SRC (PATTERN (floater)), 0),
9093 XEXP (SET_SRC (PATTERN (floater)), 1)))
9094 break;
9096 else
9098 if (pa_can_combine_p (new_rtx, anchor, floater, 0,
9099 SET_DEST (PATTERN (floater)),
9100 SET_SRC (PATTERN (floater)),
9101 SET_SRC (PATTERN (floater))))
9102 break;
9107 /* If we didn't find anything on the backwards scan try forwards. */
9108 if (!floater
9109 && (anchor_attr == PA_COMBINE_TYPE_FMPY
9110 || anchor_attr == PA_COMBINE_TYPE_FADDSUB))
9112 for (floater = anchor; floater; floater = NEXT_INSN (floater))
9114 if (GET_CODE (floater) == NOTE
9115 || (GET_CODE (floater) == INSN
9116 && (GET_CODE (PATTERN (floater)) == USE
9117 || GET_CODE (PATTERN (floater)) == CLOBBER)))
9119 continue;
9121 /* Anything except a regular INSN will stop our search. */
9122 if (GET_CODE (floater) != INSN
9123 || GET_CODE (PATTERN (floater)) == ADDR_VEC
9124 || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
9126 floater = NULL_RTX;
9127 break;
9130 /* See if FLOATER is suitable for combination with the
9131 anchor. */
9132 floater_attr = get_attr_pa_combine_type (floater);
9133 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
9134 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
9135 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
9136 && floater_attr == PA_COMBINE_TYPE_FMPY))
9138 /* If ANCHOR and FLOATER can be combined, then we're
9139 done with this pass. */
9140 if (pa_can_combine_p (new_rtx, anchor, floater, 1,
9141 SET_DEST (PATTERN (floater)),
9142 XEXP (SET_SRC (PATTERN (floater)),
9144 XEXP (SET_SRC (PATTERN (floater)),
9145 1)))
9146 break;
9151 /* FLOATER will be nonzero if we found a suitable floating
9152 insn for combination with ANCHOR. */
9153 if (floater
9154 && (anchor_attr == PA_COMBINE_TYPE_FADDSUB
9155 || anchor_attr == PA_COMBINE_TYPE_FMPY))
9157 /* Emit the new instruction and delete the old anchor. */
9158 emit_insn_before (gen_rtx_PARALLEL
9159 (VOIDmode,
9160 gen_rtvec (2, PATTERN (anchor),
9161 PATTERN (floater))),
9162 anchor);
9164 SET_INSN_DELETED (anchor);
9166 /* Emit a special USE insn for FLOATER, then delete
9167 the floating insn. */
9168 emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
9169 delete_insn (floater);
9171 continue;
9173 else if (floater
9174 && anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH)
9176 rtx temp;
9177 /* Emit the new_jump instruction and delete the old anchor. */
9178 temp
9179 = emit_jump_insn_before (gen_rtx_PARALLEL
9180 (VOIDmode,
9181 gen_rtvec (2, PATTERN (anchor),
9182 PATTERN (floater))),
9183 anchor);
9185 JUMP_LABEL (temp) = JUMP_LABEL (anchor);
9186 SET_INSN_DELETED (anchor);
9188 /* Emit a special USE insn for FLOATER, then delete
9189 the floating insn. */
9190 emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
9191 delete_insn (floater);
9192 continue;
9198 static int
9199 pa_can_combine_p (rtx new_rtx, rtx anchor, rtx floater, int reversed, rtx dest,
9200 rtx src1, rtx src2)
9202 int insn_code_number;
9203 rtx start, end;
9205 /* Create a PARALLEL with the patterns of ANCHOR and
9206 FLOATER, try to recognize it, then test constraints
9207 for the resulting pattern.
9209 If the pattern doesn't match or the constraints
9210 aren't met keep searching for a suitable floater
9211 insn. */
9212 XVECEXP (PATTERN (new_rtx), 0, 0) = PATTERN (anchor);
9213 XVECEXP (PATTERN (new_rtx), 0, 1) = PATTERN (floater);
9214 INSN_CODE (new_rtx) = -1;
9215 insn_code_number = recog_memoized (new_rtx);
9216 if (insn_code_number < 0
9217 || (extract_insn (new_rtx), ! constrain_operands (1)))
9218 return 0;
9220 if (reversed)
9222 start = anchor;
9223 end = floater;
9225 else
9227 start = floater;
9228 end = anchor;
9231 /* There's up to three operands to consider. One
9232 output and two inputs.
9234 The output must not be used between FLOATER & ANCHOR
9235 exclusive. The inputs must not be set between
9236 FLOATER and ANCHOR exclusive. */
9238 if (reg_used_between_p (dest, start, end))
9239 return 0;
9241 if (reg_set_between_p (src1, start, end))
9242 return 0;
9244 if (reg_set_between_p (src2, start, end))
9245 return 0;
9247 /* If we get here, then everything is good. */
9248 return 1;
9251 /* Return nonzero if references for INSN are delayed.
9253 Millicode insns are actually function calls with some special
9254 constraints on arguments and register usage.
9256 Millicode calls always expect their arguments in the integer argument
9257 registers, and always return their result in %r29 (ret1). They
9258 are expected to clobber their arguments, %r1, %r29, and the return
9259 pointer which is %r31 on 32-bit and %r2 on 64-bit, and nothing else.
9261 This function tells reorg that the references to arguments and
9262 millicode calls do not appear to happen until after the millicode call.
9263 This allows reorg to put insns which set the argument registers into the
9264 delay slot of the millicode call -- thus they act more like traditional
9265 CALL_INSNs.
9267 Note we cannot consider side effects of the insn to be delayed because
9268 the branch and link insn will clobber the return pointer. If we happened
9269 to use the return pointer in the delay slot of the call, then we lose.
9271 get_attr_type will try to recognize the given insn, so make sure to
9272 filter out things it will not accept -- SEQUENCE, USE and CLOBBER insns
9273 in particular. */
9275 insn_refs_are_delayed (rtx insn)
9277 return ((GET_CODE (insn) == INSN
9278 && GET_CODE (PATTERN (insn)) != SEQUENCE
9279 && GET_CODE (PATTERN (insn)) != USE
9280 && GET_CODE (PATTERN (insn)) != CLOBBER
9281 && get_attr_type (insn) == TYPE_MILLI));
9284 /* Promote the return value, but not the arguments. */
9286 static enum machine_mode
9287 pa_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
9288 enum machine_mode mode,
9289 int *punsignedp ATTRIBUTE_UNUSED,
9290 const_tree fntype ATTRIBUTE_UNUSED,
9291 int for_return)
9293 if (for_return == 0)
9294 return mode;
9295 return promote_mode (type, mode, punsignedp);
9298 /* On the HP-PA the value is found in register(s) 28(-29), unless
9299 the mode is SF or DF. Then the value is returned in fr4 (32).
9301 This must perform the same promotions as PROMOTE_MODE, else promoting
9302 return values in TARGET_PROMOTE_FUNCTION_MODE will not work correctly.
9304 Small structures must be returned in a PARALLEL on PA64 in order
9305 to match the HP Compiler ABI. */
9307 static rtx
9308 pa_function_value (const_tree valtype,
9309 const_tree func ATTRIBUTE_UNUSED,
9310 bool outgoing ATTRIBUTE_UNUSED)
9312 enum machine_mode valmode;
9314 if (AGGREGATE_TYPE_P (valtype)
9315 || TREE_CODE (valtype) == COMPLEX_TYPE
9316 || TREE_CODE (valtype) == VECTOR_TYPE)
9318 if (TARGET_64BIT)
9320 /* Aggregates with a size less than or equal to 128 bits are
9321 returned in GR 28(-29). They are left justified. The pad
9322 bits are undefined. Larger aggregates are returned in
9323 memory. */
9324 rtx loc[2];
9325 int i, offset = 0;
9326 int ub = int_size_in_bytes (valtype) <= UNITS_PER_WORD ? 1 : 2;
9328 for (i = 0; i < ub; i++)
9330 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9331 gen_rtx_REG (DImode, 28 + i),
9332 GEN_INT (offset));
9333 offset += 8;
9336 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (ub, loc));
9338 else if (int_size_in_bytes (valtype) > UNITS_PER_WORD)
9340 /* Aggregates 5 to 8 bytes in size are returned in general
9341 registers r28-r29 in the same manner as other non
9342 floating-point objects. The data is right-justified and
9343 zero-extended to 64 bits. This is opposite to the normal
9344 justification used on big endian targets and requires
9345 special treatment. */
9346 rtx loc = gen_rtx_EXPR_LIST (VOIDmode,
9347 gen_rtx_REG (DImode, 28), const0_rtx);
9348 return gen_rtx_PARALLEL (BLKmode, gen_rtvec (1, loc));
9352 if ((INTEGRAL_TYPE_P (valtype)
9353 && GET_MODE_BITSIZE (TYPE_MODE (valtype)) < BITS_PER_WORD)
9354 || POINTER_TYPE_P (valtype))
9355 valmode = word_mode;
9356 else
9357 valmode = TYPE_MODE (valtype);
9359 if (TREE_CODE (valtype) == REAL_TYPE
9360 && !AGGREGATE_TYPE_P (valtype)
9361 && TYPE_MODE (valtype) != TFmode
9362 && !TARGET_SOFT_FLOAT)
9363 return gen_rtx_REG (valmode, 32);
9365 return gen_rtx_REG (valmode, 28);
9368 /* Implement the TARGET_LIBCALL_VALUE hook. */
9370 static rtx
9371 pa_libcall_value (enum machine_mode mode,
9372 const_rtx fun ATTRIBUTE_UNUSED)
9374 if (! TARGET_SOFT_FLOAT
9375 && (mode == SFmode || mode == DFmode))
9376 return gen_rtx_REG (mode, 32);
9377 else
9378 return gen_rtx_REG (mode, 28);
9381 /* Implement the TARGET_FUNCTION_VALUE_REGNO_P hook. */
9383 static bool
9384 pa_function_value_regno_p (const unsigned int regno)
9386 if (regno == 28
9387 || (! TARGET_SOFT_FLOAT && regno == 32))
9388 return true;
9390 return false;
9393 /* Return the location of a parameter that is passed in a register or NULL
9394 if the parameter has any component that is passed in memory.
9396 This is new code and will be pushed to into the net sources after
9397 further testing.
9399 ??? We might want to restructure this so that it looks more like other
9400 ports. */
9402 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, tree type,
9403 int named ATTRIBUTE_UNUSED)
9405 int max_arg_words = (TARGET_64BIT ? 8 : 4);
9406 int alignment = 0;
9407 int arg_size;
9408 int fpr_reg_base;
9409 int gpr_reg_base;
9410 rtx retval;
9412 if (mode == VOIDmode)
9413 return NULL_RTX;
9415 arg_size = FUNCTION_ARG_SIZE (mode, type);
9417 /* If this arg would be passed partially or totally on the stack, then
9418 this routine should return zero. pa_arg_partial_bytes will
9419 handle arguments which are split between regs and stack slots if
9420 the ABI mandates split arguments. */
9421 if (!TARGET_64BIT)
9423 /* The 32-bit ABI does not split arguments. */
9424 if (cum->words + arg_size > max_arg_words)
9425 return NULL_RTX;
9427 else
9429 if (arg_size > 1)
9430 alignment = cum->words & 1;
9431 if (cum->words + alignment >= max_arg_words)
9432 return NULL_RTX;
9435 /* The 32bit ABIs and the 64bit ABIs are rather different,
9436 particularly in their handling of FP registers. We might
9437 be able to cleverly share code between them, but I'm not
9438 going to bother in the hope that splitting them up results
9439 in code that is more easily understood. */
9441 if (TARGET_64BIT)
9443 /* Advance the base registers to their current locations.
9445 Remember, gprs grow towards smaller register numbers while
9446 fprs grow to higher register numbers. Also remember that
9447 although FP regs are 32-bit addressable, we pretend that
9448 the registers are 64-bits wide. */
9449 gpr_reg_base = 26 - cum->words;
9450 fpr_reg_base = 32 + cum->words;
9452 /* Arguments wider than one word and small aggregates need special
9453 treatment. */
9454 if (arg_size > 1
9455 || mode == BLKmode
9456 || (type && (AGGREGATE_TYPE_P (type)
9457 || TREE_CODE (type) == COMPLEX_TYPE
9458 || TREE_CODE (type) == VECTOR_TYPE)))
9460 /* Double-extended precision (80-bit), quad-precision (128-bit)
9461 and aggregates including complex numbers are aligned on
9462 128-bit boundaries. The first eight 64-bit argument slots
9463 are associated one-to-one, with general registers r26
9464 through r19, and also with floating-point registers fr4
9465 through fr11. Arguments larger than one word are always
9466 passed in general registers.
9468 Using a PARALLEL with a word mode register results in left
9469 justified data on a big-endian target. */
9471 rtx loc[8];
9472 int i, offset = 0, ub = arg_size;
9474 /* Align the base register. */
9475 gpr_reg_base -= alignment;
9477 ub = MIN (ub, max_arg_words - cum->words - alignment);
9478 for (i = 0; i < ub; i++)
9480 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9481 gen_rtx_REG (DImode, gpr_reg_base),
9482 GEN_INT (offset));
9483 gpr_reg_base -= 1;
9484 offset += 8;
9487 return gen_rtx_PARALLEL (mode, gen_rtvec_v (ub, loc));
9490 else
9492 /* If the argument is larger than a word, then we know precisely
9493 which registers we must use. */
9494 if (arg_size > 1)
9496 if (cum->words)
9498 gpr_reg_base = 23;
9499 fpr_reg_base = 38;
9501 else
9503 gpr_reg_base = 25;
9504 fpr_reg_base = 34;
9507 /* Structures 5 to 8 bytes in size are passed in the general
9508 registers in the same manner as other non floating-point
9509 objects. The data is right-justified and zero-extended
9510 to 64 bits. This is opposite to the normal justification
9511 used on big endian targets and requires special treatment.
9512 We now define BLOCK_REG_PADDING to pad these objects.
9513 Aggregates, complex and vector types are passed in the same
9514 manner as structures. */
9515 if (mode == BLKmode
9516 || (type && (AGGREGATE_TYPE_P (type)
9517 || TREE_CODE (type) == COMPLEX_TYPE
9518 || TREE_CODE (type) == VECTOR_TYPE)))
9520 rtx loc = gen_rtx_EXPR_LIST (VOIDmode,
9521 gen_rtx_REG (DImode, gpr_reg_base),
9522 const0_rtx);
9523 return gen_rtx_PARALLEL (BLKmode, gen_rtvec (1, loc));
9526 else
9528 /* We have a single word (32 bits). A simple computation
9529 will get us the register #s we need. */
9530 gpr_reg_base = 26 - cum->words;
9531 fpr_reg_base = 32 + 2 * cum->words;
9535 /* Determine if the argument needs to be passed in both general and
9536 floating point registers. */
9537 if (((TARGET_PORTABLE_RUNTIME || TARGET_64BIT || TARGET_ELF32)
9538 /* If we are doing soft-float with portable runtime, then there
9539 is no need to worry about FP regs. */
9540 && !TARGET_SOFT_FLOAT
9541 /* The parameter must be some kind of scalar float, else we just
9542 pass it in integer registers. */
9543 && GET_MODE_CLASS (mode) == MODE_FLOAT
9544 /* The target function must not have a prototype. */
9545 && cum->nargs_prototype <= 0
9546 /* libcalls do not need to pass items in both FP and general
9547 registers. */
9548 && type != NULL_TREE
9549 /* All this hair applies to "outgoing" args only. This includes
9550 sibcall arguments setup with FUNCTION_INCOMING_ARG. */
9551 && !cum->incoming)
9552 /* Also pass outgoing floating arguments in both registers in indirect
9553 calls with the 32 bit ABI and the HP assembler since there is no
9554 way to the specify argument locations in static functions. */
9555 || (!TARGET_64BIT
9556 && !TARGET_GAS
9557 && !cum->incoming
9558 && cum->indirect
9559 && GET_MODE_CLASS (mode) == MODE_FLOAT))
9561 retval
9562 = gen_rtx_PARALLEL
9563 (mode,
9564 gen_rtvec (2,
9565 gen_rtx_EXPR_LIST (VOIDmode,
9566 gen_rtx_REG (mode, fpr_reg_base),
9567 const0_rtx),
9568 gen_rtx_EXPR_LIST (VOIDmode,
9569 gen_rtx_REG (mode, gpr_reg_base),
9570 const0_rtx)));
9572 else
9574 /* See if we should pass this parameter in a general register. */
9575 if (TARGET_SOFT_FLOAT
9576 /* Indirect calls in the normal 32bit ABI require all arguments
9577 to be passed in general registers. */
9578 || (!TARGET_PORTABLE_RUNTIME
9579 && !TARGET_64BIT
9580 && !TARGET_ELF32
9581 && cum->indirect)
9582 /* If the parameter is not a scalar floating-point parameter,
9583 then it belongs in GPRs. */
9584 || GET_MODE_CLASS (mode) != MODE_FLOAT
9585 /* Structure with single SFmode field belongs in GPR. */
9586 || (type && AGGREGATE_TYPE_P (type)))
9587 retval = gen_rtx_REG (mode, gpr_reg_base);
9588 else
9589 retval = gen_rtx_REG (mode, fpr_reg_base);
9591 return retval;
9595 /* If this arg would be passed totally in registers or totally on the stack,
9596 then this routine should return zero. */
9598 static int
9599 pa_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
9600 tree type, bool named ATTRIBUTE_UNUSED)
9602 unsigned int max_arg_words = 8;
9603 unsigned int offset = 0;
9605 if (!TARGET_64BIT)
9606 return 0;
9608 if (FUNCTION_ARG_SIZE (mode, type) > 1 && (cum->words & 1))
9609 offset = 1;
9611 if (cum->words + offset + FUNCTION_ARG_SIZE (mode, type) <= max_arg_words)
9612 /* Arg fits fully into registers. */
9613 return 0;
9614 else if (cum->words + offset >= max_arg_words)
9615 /* Arg fully on the stack. */
9616 return 0;
9617 else
9618 /* Arg is split. */
9619 return (max_arg_words - cum->words - offset) * UNITS_PER_WORD;
9623 /* A get_unnamed_section callback for switching to the text section.
9625 This function is only used with SOM. Because we don't support
9626 named subspaces, we can only create a new subspace or switch back
9627 to the default text subspace. */
9629 static void
9630 som_output_text_section_asm_op (const void *data ATTRIBUTE_UNUSED)
9632 gcc_assert (TARGET_SOM);
9633 if (TARGET_GAS)
9635 if (cfun && cfun->machine && !cfun->machine->in_nsubspa)
9637 /* We only want to emit a .nsubspa directive once at the
9638 start of the function. */
9639 cfun->machine->in_nsubspa = 1;
9641 /* Create a new subspace for the text. This provides
9642 better stub placement and one-only functions. */
9643 if (cfun->decl
9644 && DECL_ONE_ONLY (cfun->decl)
9645 && !DECL_WEAK (cfun->decl))
9647 output_section_asm_op ("\t.SPACE $TEXT$\n"
9648 "\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,"
9649 "ACCESS=44,SORT=24,COMDAT");
9650 return;
9653 else
9655 /* There isn't a current function or the body of the current
9656 function has been completed. So, we are changing to the
9657 text section to output debugging information. Thus, we
9658 need to forget that we are in the text section so that
9659 varasm.c will call us when text_section is selected again. */
9660 gcc_assert (!cfun || !cfun->machine
9661 || cfun->machine->in_nsubspa == 2);
9662 in_section = NULL;
9664 output_section_asm_op ("\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$");
9665 return;
9667 output_section_asm_op ("\t.SPACE $TEXT$\n\t.SUBSPA $CODE$");
9670 /* A get_unnamed_section callback for switching to comdat data
9671 sections. This function is only used with SOM. */
9673 static void
9674 som_output_comdat_data_section_asm_op (const void *data)
9676 in_section = NULL;
9677 output_section_asm_op (data);
9680 /* Implement TARGET_ASM_INITIALIZE_SECTIONS */
9682 static void
9683 pa_som_asm_init_sections (void)
9685 text_section
9686 = get_unnamed_section (0, som_output_text_section_asm_op, NULL);
9688 /* SOM puts readonly data in the default $LIT$ subspace when PIC code
9689 is not being generated. */
9690 som_readonly_data_section
9691 = get_unnamed_section (0, output_section_asm_op,
9692 "\t.SPACE $TEXT$\n\t.SUBSPA $LIT$");
9694 /* When secondary definitions are not supported, SOM makes readonly
9695 data one-only by creating a new $LIT$ subspace in $TEXT$ with
9696 the comdat flag. */
9697 som_one_only_readonly_data_section
9698 = get_unnamed_section (0, som_output_comdat_data_section_asm_op,
9699 "\t.SPACE $TEXT$\n"
9700 "\t.NSUBSPA $LIT$,QUAD=0,ALIGN=8,"
9701 "ACCESS=0x2c,SORT=16,COMDAT");
9704 /* When secondary definitions are not supported, SOM makes data one-only
9705 by creating a new $DATA$ subspace in $PRIVATE$ with the comdat flag. */
9706 som_one_only_data_section
9707 = get_unnamed_section (SECTION_WRITE,
9708 som_output_comdat_data_section_asm_op,
9709 "\t.SPACE $PRIVATE$\n"
9710 "\t.NSUBSPA $DATA$,QUAD=1,ALIGN=8,"
9711 "ACCESS=31,SORT=24,COMDAT");
9713 /* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups
9714 which reference data within the $TEXT$ space (for example constant
9715 strings in the $LIT$ subspace).
9717 The assemblers (GAS and HP as) both have problems with handling
9718 the difference of two symbols which is the other correct way to
9719 reference constant data during PIC code generation.
9721 So, there's no way to reference constant data which is in the
9722 $TEXT$ space during PIC generation. Instead place all constant
9723 data into the $PRIVATE$ subspace (this reduces sharing, but it
9724 works correctly). */
9725 readonly_data_section = flag_pic ? data_section : som_readonly_data_section;
9727 /* We must not have a reference to an external symbol defined in a
9728 shared library in a readonly section, else the SOM linker will
9729 complain.
9731 So, we force exception information into the data section. */
9732 exception_section = data_section;
9735 /* On hpux10, the linker will give an error if we have a reference
9736 in the read-only data section to a symbol defined in a shared
9737 library. Therefore, expressions that might require a reloc can
9738 not be placed in the read-only data section. */
9740 static section *
9741 pa_select_section (tree exp, int reloc,
9742 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
9744 if (TREE_CODE (exp) == VAR_DECL
9745 && TREE_READONLY (exp)
9746 && !TREE_THIS_VOLATILE (exp)
9747 && DECL_INITIAL (exp)
9748 && (DECL_INITIAL (exp) == error_mark_node
9749 || TREE_CONSTANT (DECL_INITIAL (exp)))
9750 && !reloc)
9752 if (TARGET_SOM
9753 && DECL_ONE_ONLY (exp)
9754 && !DECL_WEAK (exp))
9755 return som_one_only_readonly_data_section;
9756 else
9757 return readonly_data_section;
9759 else if (CONSTANT_CLASS_P (exp) && !reloc)
9760 return readonly_data_section;
9761 else if (TARGET_SOM
9762 && TREE_CODE (exp) == VAR_DECL
9763 && DECL_ONE_ONLY (exp)
9764 && !DECL_WEAK (exp))
9765 return som_one_only_data_section;
9766 else
9767 return data_section;
9770 static void
9771 pa_globalize_label (FILE *stream, const char *name)
9773 /* We only handle DATA objects here, functions are globalized in
9774 ASM_DECLARE_FUNCTION_NAME. */
9775 if (! FUNCTION_NAME_P (name))
9777 fputs ("\t.EXPORT ", stream);
9778 assemble_name (stream, name);
9779 fputs (",DATA\n", stream);
9783 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
9785 static rtx
9786 pa_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
9787 int incoming ATTRIBUTE_UNUSED)
9789 return gen_rtx_REG (Pmode, PA_STRUCT_VALUE_REGNUM);
9792 /* Worker function for TARGET_RETURN_IN_MEMORY. */
9794 bool
9795 pa_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
9797 /* SOM ABI says that objects larger than 64 bits are returned in memory.
9798 PA64 ABI says that objects larger than 128 bits are returned in memory.
9799 Note, int_size_in_bytes can return -1 if the size of the object is
9800 variable or larger than the maximum value that can be expressed as
9801 a HOST_WIDE_INT. It can also return zero for an empty type. The
9802 simplest way to handle variable and empty types is to pass them in
9803 memory. This avoids problems in defining the boundaries of argument
9804 slots, allocating registers, etc. */
9805 return (int_size_in_bytes (type) > (TARGET_64BIT ? 16 : 8)
9806 || int_size_in_bytes (type) <= 0);
9809 /* Structure to hold declaration and name of external symbols that are
9810 emitted by GCC. We generate a vector of these symbols and output them
9811 at the end of the file if and only if SYMBOL_REF_REFERENCED_P is true.
9812 This avoids putting out names that are never really used. */
9814 typedef struct GTY(()) extern_symbol
9816 tree decl;
9817 const char *name;
9818 } extern_symbol;
9820 /* Define gc'd vector type for extern_symbol. */
9821 DEF_VEC_O(extern_symbol);
9822 DEF_VEC_ALLOC_O(extern_symbol,gc);
9824 /* Vector of extern_symbol pointers. */
9825 static GTY(()) VEC(extern_symbol,gc) *extern_symbols;
9827 #ifdef ASM_OUTPUT_EXTERNAL_REAL
9828 /* Mark DECL (name NAME) as an external reference (assembler output
9829 file FILE). This saves the names to output at the end of the file
9830 if actually referenced. */
9832 void
9833 pa_hpux_asm_output_external (FILE *file, tree decl, const char *name)
9835 extern_symbol * p = VEC_safe_push (extern_symbol, gc, extern_symbols, NULL);
9837 gcc_assert (file == asm_out_file);
9838 p->decl = decl;
9839 p->name = name;
9842 /* Output text required at the end of an assembler file.
9843 This includes deferred plabels and .import directives for
9844 all external symbols that were actually referenced. */
9846 static void
9847 pa_hpux_file_end (void)
9849 unsigned int i;
9850 extern_symbol *p;
9852 if (!NO_DEFERRED_PROFILE_COUNTERS)
9853 output_deferred_profile_counters ();
9855 output_deferred_plabels ();
9857 for (i = 0; VEC_iterate (extern_symbol, extern_symbols, i, p); i++)
9859 tree decl = p->decl;
9861 if (!TREE_ASM_WRITTEN (decl)
9862 && SYMBOL_REF_REFERENCED_P (XEXP (DECL_RTL (decl), 0)))
9863 ASM_OUTPUT_EXTERNAL_REAL (asm_out_file, decl, p->name);
9866 VEC_free (extern_symbol, gc, extern_symbols);
9868 #endif
9870 /* Return true if a change from mode FROM to mode TO for a register
9871 in register class RCLASS is invalid. */
9873 bool
9874 pa_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
9875 enum reg_class rclass)
9877 if (from == to)
9878 return false;
9880 /* Reject changes to/from complex and vector modes. */
9881 if (COMPLEX_MODE_P (from) || VECTOR_MODE_P (from)
9882 || COMPLEX_MODE_P (to) || VECTOR_MODE_P (to))
9883 return true;
9885 if (GET_MODE_SIZE (from) == GET_MODE_SIZE (to))
9886 return false;
9888 /* There is no way to load QImode or HImode values directly from
9889 memory. SImode loads to the FP registers are not zero extended.
9890 On the 64-bit target, this conflicts with the definition of
9891 LOAD_EXTEND_OP. Thus, we can't allow changing between modes
9892 with different sizes in the floating-point registers. */
9893 if (MAYBE_FP_REG_CLASS_P (rclass))
9894 return true;
9896 /* HARD_REGNO_MODE_OK places modes with sizes larger than a word
9897 in specific sets of registers. Thus, we cannot allow changing
9898 to a larger mode when it's larger than a word. */
9899 if (GET_MODE_SIZE (to) > UNITS_PER_WORD
9900 && GET_MODE_SIZE (to) > GET_MODE_SIZE (from))
9901 return true;
9903 return false;
9906 /* Returns TRUE if it is a good idea to tie two pseudo registers
9907 when one has mode MODE1 and one has mode MODE2.
9908 If HARD_REGNO_MODE_OK could produce different values for MODE1 and MODE2,
9909 for any hard reg, then this must be FALSE for correct output.
9911 We should return FALSE for QImode and HImode because these modes
9912 are not ok in the floating-point registers. However, this prevents
9913 tieing these modes to SImode and DImode in the general registers.
9914 So, this isn't a good idea. We rely on HARD_REGNO_MODE_OK and
9915 CANNOT_CHANGE_MODE_CLASS to prevent these modes from being used
9916 in the floating-point registers. */
9918 bool
9919 pa_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
9921 /* Don't tie modes in different classes. */
9922 if (GET_MODE_CLASS (mode1) != GET_MODE_CLASS (mode2))
9923 return false;
9925 return true;
9929 /* Length in units of the trampoline instruction code. */
9931 #define TRAMPOLINE_CODE_SIZE (TARGET_64BIT ? 24 : (TARGET_PA_20 ? 32 : 40))
9934 /* Output assembler code for a block containing the constant parts
9935 of a trampoline, leaving space for the variable parts.\
9937 The trampoline sets the static chain pointer to STATIC_CHAIN_REGNUM
9938 and then branches to the specified routine.
9940 This code template is copied from text segment to stack location
9941 and then patched with pa_trampoline_init to contain valid values,
9942 and then entered as a subroutine.
9944 It is best to keep this as small as possible to avoid having to
9945 flush multiple lines in the cache. */
9947 static void
9948 pa_asm_trampoline_template (FILE *f)
9950 if (!TARGET_64BIT)
9952 fputs ("\tldw 36(%r22),%r21\n", f);
9953 fputs ("\tbb,>=,n %r21,30,.+16\n", f);
9954 if (ASSEMBLER_DIALECT == 0)
9955 fputs ("\tdepi 0,31,2,%r21\n", f);
9956 else
9957 fputs ("\tdepwi 0,31,2,%r21\n", f);
9958 fputs ("\tldw 4(%r21),%r19\n", f);
9959 fputs ("\tldw 0(%r21),%r21\n", f);
9960 if (TARGET_PA_20)
9962 fputs ("\tbve (%r21)\n", f);
9963 fputs ("\tldw 40(%r22),%r29\n", f);
9964 fputs ("\t.word 0\n", f);
9965 fputs ("\t.word 0\n", f);
9967 else
9969 fputs ("\tldsid (%r21),%r1\n", f);
9970 fputs ("\tmtsp %r1,%sr0\n", f);
9971 fputs ("\tbe 0(%sr0,%r21)\n", f);
9972 fputs ("\tldw 40(%r22),%r29\n", f);
9974 fputs ("\t.word 0\n", f);
9975 fputs ("\t.word 0\n", f);
9976 fputs ("\t.word 0\n", f);
9977 fputs ("\t.word 0\n", f);
9979 else
9981 fputs ("\t.dword 0\n", f);
9982 fputs ("\t.dword 0\n", f);
9983 fputs ("\t.dword 0\n", f);
9984 fputs ("\t.dword 0\n", f);
9985 fputs ("\tmfia %r31\n", f);
9986 fputs ("\tldd 24(%r31),%r1\n", f);
9987 fputs ("\tldd 24(%r1),%r27\n", f);
9988 fputs ("\tldd 16(%r1),%r1\n", f);
9989 fputs ("\tbve (%r1)\n", f);
9990 fputs ("\tldd 32(%r31),%r31\n", f);
9991 fputs ("\t.dword 0 ; fptr\n", f);
9992 fputs ("\t.dword 0 ; static link\n", f);
9996 /* Emit RTL insns to initialize the variable parts of a trampoline.
9997 FNADDR is an RTX for the address of the function's pure code.
9998 CXT is an RTX for the static chain value for the function.
10000 Move the function address to the trampoline template at offset 36.
10001 Move the static chain value to trampoline template at offset 40.
10002 Move the trampoline address to trampoline template at offset 44.
10003 Move r19 to trampoline template at offset 48. The latter two
10004 words create a plabel for the indirect call to the trampoline.
10006 A similar sequence is used for the 64-bit port but the plabel is
10007 at the beginning of the trampoline.
10009 Finally, the cache entries for the trampoline code are flushed.
10010 This is necessary to ensure that the trampoline instruction sequence
10011 is written to memory prior to any attempts at prefetching the code
10012 sequence. */
10014 static void
10015 pa_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
10017 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
10018 rtx start_addr = gen_reg_rtx (Pmode);
10019 rtx end_addr = gen_reg_rtx (Pmode);
10020 rtx line_length = gen_reg_rtx (Pmode);
10021 rtx r_tramp, tmp;
10023 emit_block_move (m_tramp, assemble_trampoline_template (),
10024 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
10025 r_tramp = force_reg (Pmode, XEXP (m_tramp, 0));
10027 if (!TARGET_64BIT)
10029 tmp = adjust_address (m_tramp, Pmode, 36);
10030 emit_move_insn (tmp, fnaddr);
10031 tmp = adjust_address (m_tramp, Pmode, 40);
10032 emit_move_insn (tmp, chain_value);
10034 /* Create a fat pointer for the trampoline. */
10035 tmp = adjust_address (m_tramp, Pmode, 44);
10036 emit_move_insn (tmp, r_tramp);
10037 tmp = adjust_address (m_tramp, Pmode, 48);
10038 emit_move_insn (tmp, gen_rtx_REG (Pmode, 19));
10040 /* fdc and fic only use registers for the address to flush,
10041 they do not accept integer displacements. We align the
10042 start and end addresses to the beginning of their respective
10043 cache lines to minimize the number of lines flushed. */
10044 emit_insn (gen_andsi3 (start_addr, r_tramp,
10045 GEN_INT (-MIN_CACHELINE_SIZE)));
10046 tmp = force_reg (Pmode, plus_constant (r_tramp, TRAMPOLINE_CODE_SIZE-1));
10047 emit_insn (gen_andsi3 (end_addr, tmp,
10048 GEN_INT (-MIN_CACHELINE_SIZE)));
10049 emit_move_insn (line_length, GEN_INT (MIN_CACHELINE_SIZE));
10050 emit_insn (gen_dcacheflushsi (start_addr, end_addr, line_length));
10051 emit_insn (gen_icacheflushsi (start_addr, end_addr, line_length,
10052 gen_reg_rtx (Pmode),
10053 gen_reg_rtx (Pmode)));
10055 else
10057 tmp = adjust_address (m_tramp, Pmode, 56);
10058 emit_move_insn (tmp, fnaddr);
10059 tmp = adjust_address (m_tramp, Pmode, 64);
10060 emit_move_insn (tmp, chain_value);
10062 /* Create a fat pointer for the trampoline. */
10063 tmp = adjust_address (m_tramp, Pmode, 16);
10064 emit_move_insn (tmp, force_reg (Pmode, plus_constant (r_tramp, 32)));
10065 tmp = adjust_address (m_tramp, Pmode, 24);
10066 emit_move_insn (tmp, gen_rtx_REG (Pmode, 27));
10068 /* fdc and fic only use registers for the address to flush,
10069 they do not accept integer displacements. We align the
10070 start and end addresses to the beginning of their respective
10071 cache lines to minimize the number of lines flushed. */
10072 tmp = force_reg (Pmode, plus_constant (r_tramp, 32));
10073 emit_insn (gen_anddi3 (start_addr, tmp,
10074 GEN_INT (-MIN_CACHELINE_SIZE)));
10075 tmp = force_reg (Pmode, plus_constant (tmp, TRAMPOLINE_CODE_SIZE - 1));
10076 emit_insn (gen_anddi3 (end_addr, tmp,
10077 GEN_INT (-MIN_CACHELINE_SIZE)));
10078 emit_move_insn (line_length, GEN_INT (MIN_CACHELINE_SIZE));
10079 emit_insn (gen_dcacheflushdi (start_addr, end_addr, line_length));
10080 emit_insn (gen_icacheflushdi (start_addr, end_addr, line_length,
10081 gen_reg_rtx (Pmode),
10082 gen_reg_rtx (Pmode)));
10086 /* Perform any machine-specific adjustment in the address of the trampoline.
10087 ADDR contains the address that was passed to pa_trampoline_init.
10088 Adjust the trampoline address to point to the plabel at offset 44. */
10090 static rtx
10091 pa_trampoline_adjust_address (rtx addr)
10093 if (!TARGET_64BIT)
10094 addr = memory_address (Pmode, plus_constant (addr, 46));
10095 return addr;
10098 static rtx
10099 pa_delegitimize_address (rtx orig_x)
10101 rtx x = delegitimize_mem_from_attrs (orig_x);
10103 if (GET_CODE (x) == LO_SUM
10104 && GET_CODE (XEXP (x, 1)) == UNSPEC
10105 && XINT (XEXP (x, 1), 1) == UNSPEC_DLTIND14R)
10106 return gen_const_mem (Pmode, XVECEXP (XEXP (x, 1), 0, 0));
10107 return x;
10110 static rtx
10111 pa_internal_arg_pointer (void)
10113 /* The argument pointer and the hard frame pointer are the same in
10114 the 32-bit runtime, so we don't need a copy. */
10115 if (TARGET_64BIT)
10116 return copy_to_reg (virtual_incoming_args_rtx);
10117 else
10118 return virtual_incoming_args_rtx;
10121 /* Given FROM and TO register numbers, say whether this elimination is allowed.
10122 Frame pointer elimination is automatically handled. */
10124 static bool
10125 pa_can_eliminate (const int from, const int to)
10127 /* The argument cannot be eliminated in the 64-bit runtime. */
10128 if (TARGET_64BIT && from == ARG_POINTER_REGNUM)
10129 return false;
10131 return (from == HARD_FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM
10132 ? ! frame_pointer_needed
10133 : true);
10136 /* Define the offset between two registers, FROM to be eliminated and its
10137 replacement TO, at the start of a routine. */
10138 HOST_WIDE_INT
10139 pa_initial_elimination_offset (int from, int to)
10141 HOST_WIDE_INT offset;
10143 if ((from == HARD_FRAME_POINTER_REGNUM || from == FRAME_POINTER_REGNUM)
10144 && to == STACK_POINTER_REGNUM)
10145 offset = -compute_frame_size (get_frame_size (), 0);
10146 else if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
10147 offset = 0;
10148 else
10149 gcc_unreachable ();
10151 return offset;
10154 #include "gt-pa.h"