Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / config / pa / pa.c
blob06f5b9832b00ce4eba19133b202273c9283b0015
1 /* Subroutines for insn-output.c for HPPA.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 Contributed by Tim Moore (moore@cs.utah.edu), based on sparc.c
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
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 "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-attr.h"
34 #include "flags.h"
35 #include "tree.h"
36 #include "output.h"
37 #include "except.h"
38 #include "expr.h"
39 #include "optabs.h"
40 #include "reload.h"
41 #include "integrate.h"
42 #include "function.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"
51 /* Return nonzero if there is a bypass for the output of
52 OUT_INSN and the fp store IN_INSN. */
53 int
54 hppa_fpstore_bypass_p (rtx out_insn, rtx in_insn)
56 enum machine_mode store_mode;
57 enum machine_mode other_mode;
58 rtx set;
60 if (recog_memoized (in_insn) < 0
61 || get_attr_type (in_insn) != TYPE_FPSTORE
62 || recog_memoized (out_insn) < 0)
63 return 0;
65 store_mode = GET_MODE (SET_SRC (PATTERN (in_insn)));
67 set = single_set (out_insn);
68 if (!set)
69 return 0;
71 other_mode = GET_MODE (SET_SRC (set));
73 return (GET_MODE_SIZE (store_mode) == GET_MODE_SIZE (other_mode));
77 #ifndef DO_FRAME_NOTES
78 #ifdef INCOMING_RETURN_ADDR_RTX
79 #define DO_FRAME_NOTES 1
80 #else
81 #define DO_FRAME_NOTES 0
82 #endif
83 #endif
85 static void copy_reg_pointer (rtx, rtx);
86 static void fix_range (const char *);
87 static int hppa_address_cost (rtx);
88 static bool hppa_rtx_costs (rtx, int, int, int *);
89 static inline rtx force_mode (enum machine_mode, rtx);
90 static void pa_reorg (void);
91 static void pa_combine_instructions (void);
92 static int pa_can_combine_p (rtx, rtx, rtx, int, rtx, rtx, rtx);
93 static int forward_branch_p (rtx);
94 static int shadd_constant_p (int);
95 static void compute_zdepwi_operands (unsigned HOST_WIDE_INT, unsigned *);
96 static int compute_movmem_length (rtx);
97 static int compute_clrmem_length (rtx);
98 static bool pa_assemble_integer (rtx, unsigned int, int);
99 static void remove_useless_addtr_insns (int);
100 static void store_reg (int, HOST_WIDE_INT, int);
101 static void store_reg_modify (int, int, HOST_WIDE_INT);
102 static void load_reg (int, HOST_WIDE_INT, int);
103 static void set_reg_plus_d (int, int, HOST_WIDE_INT, int);
104 static void pa_output_function_prologue (FILE *, HOST_WIDE_INT);
105 static void update_total_code_bytes (int);
106 static void pa_output_function_epilogue (FILE *, HOST_WIDE_INT);
107 static int pa_adjust_cost (rtx, rtx, rtx, int);
108 static int pa_adjust_priority (rtx, int);
109 static int pa_issue_rate (void);
110 static void pa_select_section (tree, int, unsigned HOST_WIDE_INT)
111 ATTRIBUTE_UNUSED;
112 static void pa_encode_section_info (tree, rtx, int);
113 static const char *pa_strip_name_encoding (const char *);
114 static bool pa_function_ok_for_sibcall (tree, tree);
115 static void pa_globalize_label (FILE *, const char *)
116 ATTRIBUTE_UNUSED;
117 static void pa_asm_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
118 HOST_WIDE_INT, tree);
119 #if !defined(USE_COLLECT2)
120 static void pa_asm_out_constructor (rtx, int);
121 static void pa_asm_out_destructor (rtx, int);
122 #endif
123 static void pa_init_builtins (void);
124 static rtx hppa_builtin_saveregs (void);
125 static tree hppa_gimplify_va_arg_expr (tree, tree, tree *, tree *);
126 static bool pa_scalar_mode_supported_p (enum machine_mode);
127 static void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
128 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
129 static struct deferred_plabel *get_plabel (const char *)
130 ATTRIBUTE_UNUSED;
131 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
132 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
133 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
134 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
135 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
136 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
137 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
138 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
139 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
140 static void output_deferred_plabels (void);
141 #ifdef HPUX_LONG_DOUBLE_LIBRARY
142 static void pa_hpux_init_libfuncs (void);
143 #endif
144 static rtx pa_struct_value_rtx (tree, int);
145 static bool pa_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
146 tree, bool);
147 static int pa_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
148 tree, bool);
149 static struct machine_function * pa_init_machine_status (void);
152 /* Save the operands last given to a compare for use when we
153 generate a scc or bcc insn. */
154 rtx hppa_compare_op0, hppa_compare_op1;
155 enum cmp_type hppa_branch_type;
157 /* Which architecture we are generating code for. */
158 enum architecture_type pa_arch;
160 /* String to hold which architecture we are generating code for. */
161 const char *pa_arch_string;
163 /* String used with the -mfixed-range= option. */
164 const char *pa_fixed_range_string;
166 /* Which cpu we are scheduling for. */
167 enum processor_type pa_cpu;
169 /* String to hold which cpu we are scheduling for. */
170 const char *pa_cpu_string;
172 /* String used with the -munix= option. */
173 const char *pa_unix_string;
175 /* The UNIX standard to use for predefines and linking. */
176 int flag_pa_unix;
178 /* Counts for the number of callee-saved general and floating point
179 registers which were saved by the current function's prologue. */
180 static int gr_saved, fr_saved;
182 static rtx find_addr_reg (rtx);
184 /* Keep track of the number of bytes we have output in the CODE subspace
185 during this compilation so we'll know when to emit inline long-calls. */
186 unsigned long total_code_bytes;
188 /* The last address of the previous function plus the number of bytes in
189 associated thunks that have been output. This is used to determine if
190 a thunk can use an IA-relative branch to reach its target function. */
191 static int last_address;
193 /* Variables to handle plabels that we discover are necessary at assembly
194 output time. They are output after the current function. */
195 struct deferred_plabel GTY(())
197 rtx internal_label;
198 const char *name;
200 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
201 deferred_plabels;
202 static size_t n_deferred_plabels = 0;
205 /* Initialize the GCC target structure. */
207 #undef TARGET_ASM_ALIGNED_HI_OP
208 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
209 #undef TARGET_ASM_ALIGNED_SI_OP
210 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
211 #undef TARGET_ASM_ALIGNED_DI_OP
212 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
213 #undef TARGET_ASM_UNALIGNED_HI_OP
214 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
215 #undef TARGET_ASM_UNALIGNED_SI_OP
216 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
217 #undef TARGET_ASM_UNALIGNED_DI_OP
218 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
219 #undef TARGET_ASM_INTEGER
220 #define TARGET_ASM_INTEGER pa_assemble_integer
222 #undef TARGET_ASM_FUNCTION_PROLOGUE
223 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
224 #undef TARGET_ASM_FUNCTION_EPILOGUE
225 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
227 #undef TARGET_SCHED_ADJUST_COST
228 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
229 #undef TARGET_SCHED_ADJUST_PRIORITY
230 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
231 #undef TARGET_SCHED_ISSUE_RATE
232 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
234 #undef TARGET_ENCODE_SECTION_INFO
235 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
236 #undef TARGET_STRIP_NAME_ENCODING
237 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
239 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
240 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
242 #undef TARGET_ASM_OUTPUT_MI_THUNK
243 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
244 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
245 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
247 #undef TARGET_ASM_FILE_END
248 #define TARGET_ASM_FILE_END output_deferred_plabels
250 #if !defined(USE_COLLECT2)
251 #undef TARGET_ASM_CONSTRUCTOR
252 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
253 #undef TARGET_ASM_DESTRUCTOR
254 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
255 #endif
257 #undef TARGET_INIT_BUILTINS
258 #define TARGET_INIT_BUILTINS pa_init_builtins
260 #undef TARGET_RTX_COSTS
261 #define TARGET_RTX_COSTS hppa_rtx_costs
262 #undef TARGET_ADDRESS_COST
263 #define TARGET_ADDRESS_COST hppa_address_cost
265 #undef TARGET_MACHINE_DEPENDENT_REORG
266 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
268 #ifdef HPUX_LONG_DOUBLE_LIBRARY
269 #undef TARGET_INIT_LIBFUNCS
270 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
271 #endif
273 #undef TARGET_PROMOTE_FUNCTION_RETURN
274 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
275 #undef TARGET_PROMOTE_PROTOTYPES
276 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
278 #undef TARGET_STRUCT_VALUE_RTX
279 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
280 #undef TARGET_RETURN_IN_MEMORY
281 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
282 #undef TARGET_MUST_PASS_IN_STACK
283 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
284 #undef TARGET_PASS_BY_REFERENCE
285 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
286 #undef TARGET_CALLEE_COPIES
287 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
288 #undef TARGET_ARG_PARTIAL_BYTES
289 #define TARGET_ARG_PARTIAL_BYTES pa_arg_partial_bytes
291 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
292 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
293 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
294 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
296 #undef TARGET_SCALAR_MODE_SUPPORTED_P
297 #define TARGET_SCALAR_MODE_SUPPORTED_P pa_scalar_mode_supported_p
299 struct gcc_target targetm = TARGET_INITIALIZER;
301 /* Parse the -mfixed-range= option string. */
303 static void
304 fix_range (const char *const_str)
306 int i, first, last;
307 char *str, *dash, *comma;
309 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
310 REG2 are either register names or register numbers. The effect
311 of this option is to mark the registers in the range from REG1 to
312 REG2 as ``fixed'' so they won't be used by the compiler. This is
313 used, e.g., to ensure that kernel mode code doesn't use f32-f127. */
315 i = strlen (const_str);
316 str = (char *) alloca (i + 1);
317 memcpy (str, const_str, i + 1);
319 while (1)
321 dash = strchr (str, '-');
322 if (!dash)
324 warning ("value of -mfixed-range must have form REG1-REG2");
325 return;
327 *dash = '\0';
329 comma = strchr (dash + 1, ',');
330 if (comma)
331 *comma = '\0';
333 first = decode_reg_name (str);
334 if (first < 0)
336 warning ("unknown register name: %s", str);
337 return;
340 last = decode_reg_name (dash + 1);
341 if (last < 0)
343 warning ("unknown register name: %s", dash + 1);
344 return;
347 *dash = '-';
349 if (first > last)
351 warning ("%s-%s is an empty range", str, dash + 1);
352 return;
355 for (i = first; i <= last; ++i)
356 fixed_regs[i] = call_used_regs[i] = 1;
358 if (!comma)
359 break;
361 *comma = ',';
362 str = comma + 1;
365 /* Check if all floating point registers have been fixed. */
366 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
367 if (!fixed_regs[i])
368 break;
370 if (i > FP_REG_LAST)
371 target_flags |= MASK_DISABLE_FPREGS;
374 void
375 override_options (void)
377 if (pa_cpu_string == NULL)
378 pa_cpu_string = TARGET_SCHED_DEFAULT;
380 if (! strcmp (pa_cpu_string, "8000"))
382 pa_cpu_string = "8000";
383 pa_cpu = PROCESSOR_8000;
385 else if (! strcmp (pa_cpu_string, "7100"))
387 pa_cpu_string = "7100";
388 pa_cpu = PROCESSOR_7100;
390 else if (! strcmp (pa_cpu_string, "700"))
392 pa_cpu_string = "700";
393 pa_cpu = PROCESSOR_700;
395 else if (! strcmp (pa_cpu_string, "7100LC"))
397 pa_cpu_string = "7100LC";
398 pa_cpu = PROCESSOR_7100LC;
400 else if (! strcmp (pa_cpu_string, "7200"))
402 pa_cpu_string = "7200";
403 pa_cpu = PROCESSOR_7200;
405 else if (! strcmp (pa_cpu_string, "7300"))
407 pa_cpu_string = "7300";
408 pa_cpu = PROCESSOR_7300;
410 else
412 warning ("unknown -mschedule= option (%s).\nValid options are 700, 7100, 7100LC, 7200, 7300, and 8000\n", pa_cpu_string);
415 /* Set the instruction architecture. */
416 if (pa_arch_string && ! strcmp (pa_arch_string, "1.0"))
418 pa_arch_string = "1.0";
419 pa_arch = ARCHITECTURE_10;
420 target_flags &= ~(MASK_PA_11 | MASK_PA_20);
422 else if (pa_arch_string && ! strcmp (pa_arch_string, "1.1"))
424 pa_arch_string = "1.1";
425 pa_arch = ARCHITECTURE_11;
426 target_flags &= ~MASK_PA_20;
427 target_flags |= MASK_PA_11;
429 else if (pa_arch_string && ! strcmp (pa_arch_string, "2.0"))
431 pa_arch_string = "2.0";
432 pa_arch = ARCHITECTURE_20;
433 target_flags |= MASK_PA_11 | MASK_PA_20;
435 else if (pa_arch_string)
437 warning ("unknown -march= option (%s).\nValid options are 1.0, 1.1, and 2.0\n", pa_arch_string);
440 if (TARGET_HPUX)
442 /* Set the default UNIX standard for HP-UX. This affects the
443 predefines and startfiles used for the target. */
444 if (pa_unix_string == NULL)
445 pa_unix_string
446 = TARGET_HPUX_11_11 ? "98" : (TARGET_HPUX_10_10 ? "95" : "93");
448 if (!strcmp (pa_unix_string, "93"))
449 flag_pa_unix = 1993;
450 else if (!strcmp (pa_unix_string, "95"))
451 flag_pa_unix = 1995;
452 else if (TARGET_HPUX_11_11)
454 if (!strcmp (pa_unix_string, "98"))
455 flag_pa_unix = 1998;
456 else
457 warning ("unknown -munix= option (%s).\n"
458 "Valid options are 93, 95 and 98.\n",
459 pa_unix_string);
461 else if (TARGET_HPUX_10_10)
462 warning ("unknown -munix= option (%s)."
463 "\nValid options are 93 and 95.\n",
464 pa_unix_string);
465 else
466 warning ("unknown -munix= option (%s).\nValid option is 93.\n",
467 pa_unix_string);
470 if (pa_fixed_range_string)
471 fix_range (pa_fixed_range_string);
473 /* Unconditional branches in the delay slot are not compatible with dwarf2
474 call frame information. There is no benefit in using this optimization
475 on PA8000 and later processors. */
476 if (pa_cpu >= PROCESSOR_8000
477 || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
478 || flag_unwind_tables)
479 target_flags &= ~MASK_JUMP_IN_DELAY;
481 if (flag_pic && TARGET_PORTABLE_RUNTIME)
483 warning ("PIC code generation is not supported in the portable runtime model\n");
486 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
488 warning ("PIC code generation is not compatible with fast indirect calls\n");
491 if (! TARGET_GAS && write_symbols != NO_DEBUG)
493 warning ("-g is only supported when using GAS on this processor,");
494 warning ("-g option disabled");
495 write_symbols = NO_DEBUG;
498 /* We only support the "big PIC" model now. And we always generate PIC
499 code when in 64bit mode. */
500 if (flag_pic == 1 || TARGET_64BIT)
501 flag_pic = 2;
503 /* We can't guarantee that .dword is available for 32-bit targets. */
504 if (UNITS_PER_WORD == 4)
505 targetm.asm_out.aligned_op.di = NULL;
507 /* The unaligned ops are only available when using GAS. */
508 if (!TARGET_GAS)
510 targetm.asm_out.unaligned_op.hi = NULL;
511 targetm.asm_out.unaligned_op.si = NULL;
512 targetm.asm_out.unaligned_op.di = NULL;
515 init_machine_status = pa_init_machine_status;
518 static void
519 pa_init_builtins (void)
521 #ifdef DONT_HAVE_FPUTC_UNLOCKED
522 built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
523 implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
524 #endif
527 /* Function to init struct machine_function.
528 This will be called, via a pointer variable,
529 from push_function_context. */
531 static struct machine_function *
532 pa_init_machine_status (void)
534 return ggc_alloc_cleared (sizeof (machine_function));
537 /* If FROM is a probable pointer register, mark TO as a probable
538 pointer register with the same pointer alignment as FROM. */
540 static void
541 copy_reg_pointer (rtx to, rtx from)
543 if (REG_POINTER (from))
544 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
547 /* Return nonzero only if OP is a register of mode MODE,
548 or CONST0_RTX. */
550 reg_or_0_operand (rtx op, enum machine_mode mode)
552 return (op == CONST0_RTX (mode) || register_operand (op, mode));
555 /* Return nonzero if OP is suitable for use in a call to a named
556 function.
558 For 2.5 try to eliminate either call_operand_address or
559 function_label_operand, they perform very similar functions. */
561 call_operand_address (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
563 return (GET_MODE (op) == word_mode
564 && CONSTANT_P (op) && ! TARGET_PORTABLE_RUNTIME);
567 /* Return 1 if X contains a symbolic expression. We know these
568 expressions will have one of a few well defined forms, so
569 we need only check those forms. */
571 symbolic_expression_p (rtx x)
574 /* Strip off any HIGH. */
575 if (GET_CODE (x) == HIGH)
576 x = XEXP (x, 0);
578 return (symbolic_operand (x, VOIDmode));
582 symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
584 switch (GET_CODE (op))
586 case SYMBOL_REF:
587 case LABEL_REF:
588 return 1;
589 case CONST:
590 op = XEXP (op, 0);
591 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
592 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
593 && GET_CODE (XEXP (op, 1)) == CONST_INT);
594 default:
595 return 0;
599 /* Return truth value of statement that OP is a symbolic memory
600 operand of mode MODE. */
603 symbolic_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
605 if (GET_CODE (op) == SUBREG)
606 op = SUBREG_REG (op);
607 if (GET_CODE (op) != MEM)
608 return 0;
609 op = XEXP (op, 0);
610 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
611 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
614 /* Return 1 if the operand is either a register, zero, or a memory operand
615 that is not symbolic. */
618 reg_or_0_or_nonsymb_mem_operand (rtx op, enum machine_mode mode)
620 if (register_operand (op, mode))
621 return 1;
623 if (op == CONST0_RTX (mode))
624 return 1;
626 if (GET_CODE (op) == SUBREG)
627 op = SUBREG_REG (op);
629 if (GET_CODE (op) != MEM)
630 return 0;
632 /* Until problems with management of the REG_POINTER flag are resolved,
633 we need to delay creating move insns with unscaled indexed addresses
634 until CSE is not expected. */
635 if (!TARGET_NO_SPACE_REGS
636 && !cse_not_expected
637 && GET_CODE (XEXP (op, 0)) == PLUS
638 && REG_P (XEXP (XEXP (op, 0), 0))
639 && REG_P (XEXP (XEXP (op, 0), 1)))
640 return 0;
642 return (!symbolic_memory_operand (op, mode)
643 && memory_address_p (mode, XEXP (op, 0)));
646 /* Return 1 if the operand is a register operand or a non-symbolic memory
647 operand after reload. This predicate is used for branch patterns that
648 internally handle register reloading. We need to accept non-symbolic
649 memory operands after reload to ensure that the pattern is still valid
650 if reload didn't find a hard register for the operand. */
653 reg_before_reload_operand (rtx op, enum machine_mode mode)
655 /* Don't accept a SUBREG since it will need a reload. */
656 if (GET_CODE (op) == SUBREG)
657 return 0;
659 if (register_operand (op, mode))
660 return 1;
662 if (reload_completed
663 && memory_operand (op, mode)
664 && !symbolic_memory_operand (op, mode))
665 return 1;
667 return 0;
670 /* Accept any constant that can be moved in one instruction into a
671 general register. */
673 cint_ok_for_move (HOST_WIDE_INT intval)
675 /* OK if ldo, ldil, or zdepi, can be used. */
676 return (CONST_OK_FOR_LETTER_P (intval, 'J')
677 || CONST_OK_FOR_LETTER_P (intval, 'N')
678 || CONST_OK_FOR_LETTER_P (intval, 'K'));
681 /* Return 1 iff OP is an indexed memory operand. */
683 indexed_memory_operand (rtx op, enum machine_mode mode)
685 if (GET_MODE (op) != mode)
686 return 0;
688 /* Before reload, a (SUBREG (MEM...)) forces reloading into a register. */
689 if (reload_completed && GET_CODE (op) == SUBREG)
690 op = SUBREG_REG (op);
692 if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
693 return 0;
695 op = XEXP (op, 0);
697 return (memory_address_p (mode, op) && IS_INDEX_ADDR_P (op));
700 /* Accept anything that can be used as a destination operand for a
701 move instruction. We don't accept indexed memory operands since
702 they are supported only for floating point stores. */
704 move_dest_operand (rtx op, enum machine_mode mode)
706 if (register_operand (op, mode))
707 return 1;
709 if (GET_MODE (op) != mode)
710 return 0;
712 if (GET_CODE (op) == SUBREG)
713 op = SUBREG_REG (op);
715 if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
716 return 0;
718 op = XEXP (op, 0);
720 return (memory_address_p (mode, op)
721 && !IS_INDEX_ADDR_P (op)
722 && !IS_LO_SUM_DLT_ADDR_P (op));
725 /* Accept anything that can be used as a source operand for a move
726 instruction. */
728 move_src_operand (rtx op, enum machine_mode mode)
730 if (register_operand (op, mode))
731 return 1;
733 if (GET_CODE (op) == CONST_INT)
734 return cint_ok_for_move (INTVAL (op));
736 if (GET_MODE (op) != mode)
737 return 0;
739 if (GET_CODE (op) == SUBREG)
740 op = SUBREG_REG (op);
742 if (GET_CODE (op) != MEM)
743 return 0;
745 /* Until problems with management of the REG_POINTER flag are resolved,
746 we need to delay creating move insns with unscaled indexed addresses
747 until CSE is not expected. */
748 if (!TARGET_NO_SPACE_REGS
749 && !cse_not_expected
750 && GET_CODE (XEXP (op, 0)) == PLUS
751 && REG_P (XEXP (XEXP (op, 0), 0))
752 && REG_P (XEXP (XEXP (op, 0), 1)))
753 return 0;
755 return memory_address_p (mode, XEXP (op, 0));
758 /* Accept anything that can be used as the source operand for a prefetch
759 instruction with a cache-control completer. */
761 prefetch_cc_operand (rtx op, enum machine_mode mode)
763 if (GET_CODE (op) != MEM)
764 return 0;
766 op = XEXP (op, 0);
768 /* We must reject virtual registers as we don't allow REG+D. */
769 if (op == virtual_incoming_args_rtx
770 || op == virtual_stack_vars_rtx
771 || op == virtual_stack_dynamic_rtx
772 || op == virtual_outgoing_args_rtx
773 || op == virtual_cfa_rtx)
774 return 0;
776 if (!REG_P (op) && !IS_INDEX_ADDR_P (op))
777 return 0;
779 /* Until problems with management of the REG_POINTER flag are resolved,
780 we need to delay creating prefetch insns with unscaled indexed addresses
781 until CSE is not expected. */
782 if (!TARGET_NO_SPACE_REGS
783 && !cse_not_expected
784 && GET_CODE (op) == PLUS
785 && REG_P (XEXP (op, 0)))
786 return 0;
788 return memory_address_p (mode, op);
791 /* Accept anything that can be used as the source operand for a prefetch
792 instruction with no cache-control completer. */
794 prefetch_nocc_operand (rtx op, enum machine_mode mode)
796 if (GET_CODE (op) != MEM)
797 return 0;
799 op = XEXP (op, 0);
801 /* Until problems with management of the REG_POINTER flag are resolved,
802 we need to delay creating prefetch insns with unscaled indexed addresses
803 until CSE is not expected. */
804 if (!TARGET_NO_SPACE_REGS
805 && !cse_not_expected
806 && GET_CODE (op) == PLUS
807 && REG_P (XEXP (op, 0))
808 && REG_P (XEXP (op, 1)))
809 return 0;
811 return memory_address_p (mode, op);
814 /* Accept REG and any CONST_INT that can be moved in one instruction into a
815 general register. */
817 reg_or_cint_move_operand (rtx op, enum machine_mode mode)
819 if (register_operand (op, mode))
820 return 1;
822 return (GET_CODE (op) == CONST_INT && cint_ok_for_move (INTVAL (op)));
826 pic_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
828 if (!flag_pic)
829 return 0;
831 switch (GET_CODE (op))
833 case LABEL_REF:
834 return 1;
835 case CONST:
836 op = XEXP (op, 0);
837 return (GET_CODE (XEXP (op, 0)) == LABEL_REF
838 && GET_CODE (XEXP (op, 1)) == CONST_INT);
839 default:
840 return 0;
845 fp_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
847 return reg_renumber && FP_REG_P (op);
852 /* Return truth value of whether OP can be used as an operand in a
853 three operand arithmetic insn that accepts registers of mode MODE
854 or 14-bit signed integers. */
856 arith_operand (rtx op, enum machine_mode mode)
858 return (register_operand (op, mode)
859 || (GET_CODE (op) == CONST_INT && INT_14_BITS (op)));
862 /* Return truth value of whether OP can be used as an operand in a
863 three operand arithmetic insn that accepts registers of mode MODE
864 or 11-bit signed integers. */
866 arith11_operand (rtx op, enum machine_mode mode)
868 return (register_operand (op, mode)
869 || (GET_CODE (op) == CONST_INT && INT_11_BITS (op)));
872 /* Return truth value of whether OP can be used as an operand in a
873 adddi3 insn. */
875 adddi3_operand (rtx op, enum machine_mode mode)
877 return (register_operand (op, mode)
878 || (GET_CODE (op) == CONST_INT
879 && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
882 /* A constant integer suitable for use in a PRE_MODIFY memory
883 reference. */
885 pre_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
887 return (GET_CODE (op) == CONST_INT
888 && INTVAL (op) >= -0x2000 && INTVAL (op) < 0x10);
891 /* A constant integer suitable for use in a POST_MODIFY memory
892 reference. */
894 post_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
896 return (GET_CODE (op) == CONST_INT
897 && INTVAL (op) < 0x2000 && INTVAL (op) >= -0x10);
901 arith_double_operand (rtx op, enum machine_mode mode)
903 return (register_operand (op, mode)
904 || (GET_CODE (op) == CONST_DOUBLE
905 && GET_MODE (op) == mode
906 && VAL_14_BITS_P (CONST_DOUBLE_LOW (op))
907 && ((CONST_DOUBLE_HIGH (op) >= 0)
908 == ((CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
911 /* Return truth value of whether OP is an integer which fits the
912 range constraining immediate operands in three-address insns, or
913 is an integer register. */
916 ireg_or_int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
918 return ((GET_CODE (op) == CONST_INT && INT_5_BITS (op))
919 || (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32));
922 /* Return nonzero if OP is an integer register, else return zero. */
924 ireg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
926 return (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32);
929 /* Return truth value of whether OP is an integer which fits the
930 range constraining immediate operands in three-address insns. */
933 int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
935 return (GET_CODE (op) == CONST_INT && INT_5_BITS (op));
939 uint5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
941 return (GET_CODE (op) == CONST_INT && INT_U5_BITS (op));
945 int11_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
947 return (GET_CODE (op) == CONST_INT && INT_11_BITS (op));
951 uint32_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
953 #if HOST_BITS_PER_WIDE_INT > 32
954 /* All allowed constants will fit a CONST_INT. */
955 return (GET_CODE (op) == CONST_INT
956 && (INTVAL (op) >= 0 && INTVAL (op) < (HOST_WIDE_INT) 1 << 32));
957 #else
958 return (GET_CODE (op) == CONST_INT
959 || (GET_CODE (op) == CONST_DOUBLE
960 && CONST_DOUBLE_HIGH (op) == 0));
961 #endif
965 arith5_operand (rtx op, enum machine_mode mode)
967 return register_operand (op, mode) || int5_operand (op, mode);
970 /* True iff zdepi can be used to generate this CONST_INT.
971 zdepi first sign extends a 5 bit signed number to a given field
972 length, then places this field anywhere in a zero. */
974 zdepi_cint_p (unsigned HOST_WIDE_INT x)
976 unsigned HOST_WIDE_INT lsb_mask, t;
978 /* This might not be obvious, but it's at least fast.
979 This function is critical; we don't have the time loops would take. */
980 lsb_mask = x & -x;
981 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
982 /* Return true iff t is a power of two. */
983 return ((t & (t - 1)) == 0);
986 /* True iff depi or extru can be used to compute (reg & mask).
987 Accept bit pattern like these:
988 0....01....1
989 1....10....0
990 1..10..01..1 */
992 and_mask_p (unsigned HOST_WIDE_INT mask)
994 mask = ~mask;
995 mask += mask & -mask;
996 return (mask & (mask - 1)) == 0;
999 /* True iff depi or extru can be used to compute (reg & OP). */
1001 and_operand (rtx op, enum machine_mode mode)
1003 return (register_operand (op, mode)
1004 || (GET_CODE (op) == CONST_INT && and_mask_p (INTVAL (op))));
1007 /* True iff depi can be used to compute (reg | MASK). */
1009 ior_mask_p (unsigned HOST_WIDE_INT mask)
1011 mask += mask & -mask;
1012 return (mask & (mask - 1)) == 0;
1015 /* True iff depi can be used to compute (reg | OP). */
1017 ior_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1019 return (GET_CODE (op) == CONST_INT && ior_mask_p (INTVAL (op)));
1023 lhs_lshift_operand (rtx op, enum machine_mode mode)
1025 return register_operand (op, mode) || lhs_lshift_cint_operand (op, mode);
1028 /* True iff OP is a CONST_INT of the forms 0...0xxxx or 0...01...1xxxx.
1029 Such values can be the left hand side x in (x << r), using the zvdepi
1030 instruction. */
1032 lhs_lshift_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1034 unsigned HOST_WIDE_INT x;
1035 if (GET_CODE (op) != CONST_INT)
1036 return 0;
1037 x = INTVAL (op) >> 4;
1038 return (x & (x + 1)) == 0;
1042 arith32_operand (rtx op, enum machine_mode mode)
1044 return register_operand (op, mode) || GET_CODE (op) == CONST_INT;
1048 pc_or_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1050 return (GET_CODE (op) == PC || GET_CODE (op) == LABEL_REF);
1053 /* Legitimize PIC addresses. If the address is already
1054 position-independent, we return ORIG. Newly generated
1055 position-independent addresses go to REG. If we need more
1056 than one register, we lose. */
1059 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
1061 rtx pic_ref = orig;
1063 /* Labels need special handling. */
1064 if (pic_label_operand (orig, mode))
1066 /* We do not want to go through the movXX expanders here since that
1067 would create recursion.
1069 Nor do we really want to call a generator for a named pattern
1070 since that requires multiple patterns if we want to support
1071 multiple word sizes.
1073 So instead we just emit the raw set, which avoids the movXX
1074 expanders completely. */
1075 mark_reg_pointer (reg, BITS_PER_UNIT);
1076 emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
1077 current_function_uses_pic_offset_table = 1;
1078 return reg;
1080 if (GET_CODE (orig) == SYMBOL_REF)
1082 rtx insn, tmp_reg;
1084 if (reg == 0)
1085 abort ();
1087 /* Before reload, allocate a temporary register for the intermediate
1088 result. This allows the sequence to be deleted when the final
1089 result is unused and the insns are trivially dead. */
1090 tmp_reg = ((reload_in_progress || reload_completed)
1091 ? reg : gen_reg_rtx (Pmode));
1093 emit_move_insn (tmp_reg,
1094 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
1095 gen_rtx_HIGH (word_mode, orig)));
1096 pic_ref
1097 = gen_const_mem (Pmode,
1098 gen_rtx_LO_SUM (Pmode, tmp_reg,
1099 gen_rtx_UNSPEC (Pmode,
1100 gen_rtvec (1, orig),
1101 UNSPEC_DLTIND14R)));
1103 current_function_uses_pic_offset_table = 1;
1104 mark_reg_pointer (reg, BITS_PER_UNIT);
1105 insn = emit_move_insn (reg, pic_ref);
1107 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
1108 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig, REG_NOTES (insn));
1110 return reg;
1112 else if (GET_CODE (orig) == CONST)
1114 rtx base;
1116 if (GET_CODE (XEXP (orig, 0)) == PLUS
1117 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1118 return orig;
1120 if (reg == 0)
1121 abort ();
1123 if (GET_CODE (XEXP (orig, 0)) == PLUS)
1125 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1126 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1127 base == reg ? 0 : reg);
1129 else
1130 abort ();
1132 if (GET_CODE (orig) == CONST_INT)
1134 if (INT_14_BITS (orig))
1135 return plus_constant (base, INTVAL (orig));
1136 orig = force_reg (Pmode, orig);
1138 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
1139 /* Likewise, should we set special REG_NOTEs here? */
1142 return pic_ref;
1145 /* Try machine-dependent ways of modifying an illegitimate address
1146 to be legitimate. If we find one, return the new, valid address.
1147 This macro is used in only one place: `memory_address' in explow.c.
1149 OLDX is the address as it was before break_out_memory_refs was called.
1150 In some cases it is useful to look at this to decide what needs to be done.
1152 MODE and WIN are passed so that this macro can use
1153 GO_IF_LEGITIMATE_ADDRESS.
1155 It is always safe for this macro to do nothing. It exists to recognize
1156 opportunities to optimize the output.
1158 For the PA, transform:
1160 memory(X + <large int>)
1162 into:
1164 if (<large int> & mask) >= 16
1165 Y = (<large int> & ~mask) + mask + 1 Round up.
1166 else
1167 Y = (<large int> & ~mask) Round down.
1168 Z = X + Y
1169 memory (Z + (<large int> - Y));
1171 This is for CSE to find several similar references, and only use one Z.
1173 X can either be a SYMBOL_REF or REG, but because combine cannot
1174 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
1175 D will not fit in 14 bits.
1177 MODE_FLOAT references allow displacements which fit in 5 bits, so use
1178 0x1f as the mask.
1180 MODE_INT references allow displacements which fit in 14 bits, so use
1181 0x3fff as the mask.
1183 This relies on the fact that most mode MODE_FLOAT references will use FP
1184 registers and most mode MODE_INT references will use integer registers.
1185 (In the rare case of an FP register used in an integer MODE, we depend
1186 on secondary reloads to clean things up.)
1189 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
1190 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
1191 addressing modes to be used).
1193 Put X and Z into registers. Then put the entire expression into
1194 a register. */
1197 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1198 enum machine_mode mode)
1200 rtx orig = x;
1202 /* We need to canonicalize the order of operands in unscaled indexed
1203 addresses since the code that checks if an address is valid doesn't
1204 always try both orders. */
1205 if (!TARGET_NO_SPACE_REGS
1206 && GET_CODE (x) == PLUS
1207 && GET_MODE (x) == Pmode
1208 && REG_P (XEXP (x, 0))
1209 && REG_P (XEXP (x, 1))
1210 && REG_POINTER (XEXP (x, 0))
1211 && !REG_POINTER (XEXP (x, 1)))
1212 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
1214 if (flag_pic)
1215 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
1217 /* Strip off CONST. */
1218 if (GET_CODE (x) == CONST)
1219 x = XEXP (x, 0);
1221 /* Special case. Get the SYMBOL_REF into a register and use indexing.
1222 That should always be safe. */
1223 if (GET_CODE (x) == PLUS
1224 && GET_CODE (XEXP (x, 0)) == REG
1225 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
1227 rtx reg = force_reg (Pmode, XEXP (x, 1));
1228 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
1231 /* Note we must reject symbols which represent function addresses
1232 since the assembler/linker can't handle arithmetic on plabels. */
1233 if (GET_CODE (x) == PLUS
1234 && GET_CODE (XEXP (x, 1)) == CONST_INT
1235 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1236 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
1237 || GET_CODE (XEXP (x, 0)) == REG))
1239 rtx int_part, ptr_reg;
1240 int newoffset;
1241 int offset = INTVAL (XEXP (x, 1));
1242 int mask;
1244 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
1245 ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
1247 /* Choose which way to round the offset. Round up if we
1248 are >= halfway to the next boundary. */
1249 if ((offset & mask) >= ((mask + 1) / 2))
1250 newoffset = (offset & ~ mask) + mask + 1;
1251 else
1252 newoffset = (offset & ~ mask);
1254 /* If the newoffset will not fit in 14 bits (ldo), then
1255 handling this would take 4 or 5 instructions (2 to load
1256 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
1257 add the new offset and the SYMBOL_REF.) Combine can
1258 not handle 4->2 or 5->2 combinations, so do not create
1259 them. */
1260 if (! VAL_14_BITS_P (newoffset)
1261 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
1263 rtx const_part = plus_constant (XEXP (x, 0), newoffset);
1264 rtx tmp_reg
1265 = force_reg (Pmode,
1266 gen_rtx_HIGH (Pmode, const_part));
1267 ptr_reg
1268 = force_reg (Pmode,
1269 gen_rtx_LO_SUM (Pmode,
1270 tmp_reg, const_part));
1272 else
1274 if (! VAL_14_BITS_P (newoffset))
1275 int_part = force_reg (Pmode, GEN_INT (newoffset));
1276 else
1277 int_part = GEN_INT (newoffset);
1279 ptr_reg = force_reg (Pmode,
1280 gen_rtx_PLUS (Pmode,
1281 force_reg (Pmode, XEXP (x, 0)),
1282 int_part));
1284 return plus_constant (ptr_reg, offset - newoffset);
1287 /* Handle (plus (mult (a) (shadd_constant)) (b)). */
1289 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1290 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1291 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
1292 && (OBJECT_P (XEXP (x, 1))
1293 || GET_CODE (XEXP (x, 1)) == SUBREG)
1294 && GET_CODE (XEXP (x, 1)) != CONST)
1296 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1297 rtx reg1, reg2;
1299 reg1 = XEXP (x, 1);
1300 if (GET_CODE (reg1) != REG)
1301 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1303 reg2 = XEXP (XEXP (x, 0), 0);
1304 if (GET_CODE (reg2) != REG)
1305 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1307 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1308 gen_rtx_MULT (Pmode,
1309 reg2,
1310 GEN_INT (val)),
1311 reg1));
1314 /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
1316 Only do so for floating point modes since this is more speculative
1317 and we lose if it's an integer store. */
1318 if (GET_CODE (x) == PLUS
1319 && GET_CODE (XEXP (x, 0)) == PLUS
1320 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1321 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
1322 && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1323 && (mode == SFmode || mode == DFmode))
1326 /* First, try and figure out what to use as a base register. */
1327 rtx reg1, reg2, base, idx, orig_base;
1329 reg1 = XEXP (XEXP (x, 0), 1);
1330 reg2 = XEXP (x, 1);
1331 base = NULL_RTX;
1332 idx = NULL_RTX;
1334 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
1335 then emit_move_sequence will turn on REG_POINTER so we'll know
1336 it's a base register below. */
1337 if (GET_CODE (reg1) != REG)
1338 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1340 if (GET_CODE (reg2) != REG)
1341 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1343 /* Figure out what the base and index are. */
1345 if (GET_CODE (reg1) == REG
1346 && REG_POINTER (reg1))
1348 base = reg1;
1349 orig_base = XEXP (XEXP (x, 0), 1);
1350 idx = gen_rtx_PLUS (Pmode,
1351 gen_rtx_MULT (Pmode,
1352 XEXP (XEXP (XEXP (x, 0), 0), 0),
1353 XEXP (XEXP (XEXP (x, 0), 0), 1)),
1354 XEXP (x, 1));
1356 else if (GET_CODE (reg2) == REG
1357 && REG_POINTER (reg2))
1359 base = reg2;
1360 orig_base = XEXP (x, 1);
1361 idx = XEXP (x, 0);
1364 if (base == 0)
1365 return orig;
1367 /* If the index adds a large constant, try to scale the
1368 constant so that it can be loaded with only one insn. */
1369 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1370 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1371 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1372 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1374 /* Divide the CONST_INT by the scale factor, then add it to A. */
1375 int val = INTVAL (XEXP (idx, 1));
1377 val /= INTVAL (XEXP (XEXP (idx, 0), 1));
1378 reg1 = XEXP (XEXP (idx, 0), 0);
1379 if (GET_CODE (reg1) != REG)
1380 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1382 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1384 /* We can now generate a simple scaled indexed address. */
1385 return
1386 force_reg
1387 (Pmode, gen_rtx_PLUS (Pmode,
1388 gen_rtx_MULT (Pmode, reg1,
1389 XEXP (XEXP (idx, 0), 1)),
1390 base));
1393 /* If B + C is still a valid base register, then add them. */
1394 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1395 && INTVAL (XEXP (idx, 1)) <= 4096
1396 && INTVAL (XEXP (idx, 1)) >= -4096)
1398 int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1399 rtx reg1, reg2;
1401 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1403 reg2 = XEXP (XEXP (idx, 0), 0);
1404 if (GET_CODE (reg2) != CONST_INT)
1405 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1407 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1408 gen_rtx_MULT (Pmode,
1409 reg2,
1410 GEN_INT (val)),
1411 reg1));
1414 /* Get the index into a register, then add the base + index and
1415 return a register holding the result. */
1417 /* First get A into a register. */
1418 reg1 = XEXP (XEXP (idx, 0), 0);
1419 if (GET_CODE (reg1) != REG)
1420 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1422 /* And get B into a register. */
1423 reg2 = XEXP (idx, 1);
1424 if (GET_CODE (reg2) != REG)
1425 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1427 reg1 = force_reg (Pmode,
1428 gen_rtx_PLUS (Pmode,
1429 gen_rtx_MULT (Pmode, reg1,
1430 XEXP (XEXP (idx, 0), 1)),
1431 reg2));
1433 /* Add the result to our base register and return. */
1434 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1438 /* Uh-oh. We might have an address for x[n-100000]. This needs
1439 special handling to avoid creating an indexed memory address
1440 with x-100000 as the base.
1442 If the constant part is small enough, then it's still safe because
1443 there is a guard page at the beginning and end of the data segment.
1445 Scaled references are common enough that we want to try and rearrange the
1446 terms so that we can use indexing for these addresses too. Only
1447 do the optimization for floatint point modes. */
1449 if (GET_CODE (x) == PLUS
1450 && symbolic_expression_p (XEXP (x, 1)))
1452 /* Ugly. We modify things here so that the address offset specified
1453 by the index expression is computed first, then added to x to form
1454 the entire address. */
1456 rtx regx1, regx2, regy1, regy2, y;
1458 /* Strip off any CONST. */
1459 y = XEXP (x, 1);
1460 if (GET_CODE (y) == CONST)
1461 y = XEXP (y, 0);
1463 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1465 /* See if this looks like
1466 (plus (mult (reg) (shadd_const))
1467 (const (plus (symbol_ref) (const_int))))
1469 Where const_int is small. In that case the const
1470 expression is a valid pointer for indexing.
1472 If const_int is big, but can be divided evenly by shadd_const
1473 and added to (reg). This allows more scaled indexed addresses. */
1474 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1475 && GET_CODE (XEXP (x, 0)) == MULT
1476 && GET_CODE (XEXP (y, 1)) == CONST_INT
1477 && INTVAL (XEXP (y, 1)) >= -4096
1478 && INTVAL (XEXP (y, 1)) <= 4095
1479 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1480 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1482 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1483 rtx reg1, reg2;
1485 reg1 = XEXP (x, 1);
1486 if (GET_CODE (reg1) != REG)
1487 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1489 reg2 = XEXP (XEXP (x, 0), 0);
1490 if (GET_CODE (reg2) != REG)
1491 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1493 return force_reg (Pmode,
1494 gen_rtx_PLUS (Pmode,
1495 gen_rtx_MULT (Pmode,
1496 reg2,
1497 GEN_INT (val)),
1498 reg1));
1500 else if ((mode == DFmode || mode == SFmode)
1501 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1502 && GET_CODE (XEXP (x, 0)) == MULT
1503 && GET_CODE (XEXP (y, 1)) == CONST_INT
1504 && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1505 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1506 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1508 regx1
1509 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1510 / INTVAL (XEXP (XEXP (x, 0), 1))));
1511 regx2 = XEXP (XEXP (x, 0), 0);
1512 if (GET_CODE (regx2) != REG)
1513 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1514 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1515 regx2, regx1));
1516 return
1517 force_reg (Pmode,
1518 gen_rtx_PLUS (Pmode,
1519 gen_rtx_MULT (Pmode, regx2,
1520 XEXP (XEXP (x, 0), 1)),
1521 force_reg (Pmode, XEXP (y, 0))));
1523 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1524 && INTVAL (XEXP (y, 1)) >= -4096
1525 && INTVAL (XEXP (y, 1)) <= 4095)
1527 /* This is safe because of the guard page at the
1528 beginning and end of the data space. Just
1529 return the original address. */
1530 return orig;
1532 else
1534 /* Doesn't look like one we can optimize. */
1535 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1536 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1537 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1538 regx1 = force_reg (Pmode,
1539 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1540 regx1, regy2));
1541 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1546 return orig;
1549 /* For the HPPA, REG and REG+CONST is cost 0
1550 and addresses involving symbolic constants are cost 2.
1552 PIC addresses are very expensive.
1554 It is no coincidence that this has the same structure
1555 as GO_IF_LEGITIMATE_ADDRESS. */
1557 static int
1558 hppa_address_cost (rtx X)
1560 switch (GET_CODE (X))
1562 case REG:
1563 case PLUS:
1564 case LO_SUM:
1565 return 1;
1566 case HIGH:
1567 return 2;
1568 default:
1569 return 4;
1573 /* Compute a (partial) cost for rtx X. Return true if the complete
1574 cost has been computed, and false if subexpressions should be
1575 scanned. In either case, *TOTAL contains the cost result. */
1577 static bool
1578 hppa_rtx_costs (rtx x, int code, int outer_code, int *total)
1580 switch (code)
1582 case CONST_INT:
1583 if (INTVAL (x) == 0)
1584 *total = 0;
1585 else if (INT_14_BITS (x))
1586 *total = 1;
1587 else
1588 *total = 2;
1589 return true;
1591 case HIGH:
1592 *total = 2;
1593 return true;
1595 case CONST:
1596 case LABEL_REF:
1597 case SYMBOL_REF:
1598 *total = 4;
1599 return true;
1601 case CONST_DOUBLE:
1602 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1603 && outer_code != SET)
1604 *total = 0;
1605 else
1606 *total = 8;
1607 return true;
1609 case MULT:
1610 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1611 *total = COSTS_N_INSNS (3);
1612 else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1613 *total = COSTS_N_INSNS (8);
1614 else
1615 *total = COSTS_N_INSNS (20);
1616 return true;
1618 case DIV:
1619 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1621 *total = COSTS_N_INSNS (14);
1622 return true;
1624 /* FALLTHRU */
1626 case UDIV:
1627 case MOD:
1628 case UMOD:
1629 *total = COSTS_N_INSNS (60);
1630 return true;
1632 case PLUS: /* this includes shNadd insns */
1633 case MINUS:
1634 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1635 *total = COSTS_N_INSNS (3);
1636 else
1637 *total = COSTS_N_INSNS (1);
1638 return true;
1640 case ASHIFT:
1641 case ASHIFTRT:
1642 case LSHIFTRT:
1643 *total = COSTS_N_INSNS (1);
1644 return true;
1646 default:
1647 return false;
1651 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1652 new rtx with the correct mode. */
1653 static inline rtx
1654 force_mode (enum machine_mode mode, rtx orig)
1656 if (mode == GET_MODE (orig))
1657 return orig;
1659 if (REGNO (orig) >= FIRST_PSEUDO_REGISTER)
1660 abort ();
1662 return gen_rtx_REG (mode, REGNO (orig));
1665 /* Emit insns to move operands[1] into operands[0].
1667 Return 1 if we have written out everything that needs to be done to
1668 do the move. Otherwise, return 0 and the caller will emit the move
1669 normally.
1671 Note SCRATCH_REG may not be in the proper mode depending on how it
1672 will be used. This routine is responsible for creating a new copy
1673 of SCRATCH_REG in the proper mode. */
1676 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1678 register rtx operand0 = operands[0];
1679 register rtx operand1 = operands[1];
1680 register rtx tem;
1682 /* We can only handle indexed addresses in the destination operand
1683 of floating point stores. Thus, we need to break out indexed
1684 addresses from the destination operand. */
1685 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1687 /* This is only safe up to the beginning of life analysis. */
1688 if (no_new_pseudos)
1689 abort ();
1691 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1692 operand0 = replace_equiv_address (operand0, tem);
1695 /* On targets with non-equivalent space registers, break out unscaled
1696 indexed addresses from the source operand before the final CSE.
1697 We have to do this because the REG_POINTER flag is not correctly
1698 carried through various optimization passes and CSE may substitute
1699 a pseudo without the pointer set for one with the pointer set. As
1700 a result, we loose various opportunities to create insns with
1701 unscaled indexed addresses. */
1702 if (!TARGET_NO_SPACE_REGS
1703 && !cse_not_expected
1704 && GET_CODE (operand1) == MEM
1705 && GET_CODE (XEXP (operand1, 0)) == PLUS
1706 && REG_P (XEXP (XEXP (operand1, 0), 0))
1707 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1708 operand1
1709 = replace_equiv_address (operand1,
1710 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1712 if (scratch_reg
1713 && reload_in_progress && GET_CODE (operand0) == REG
1714 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1715 operand0 = reg_equiv_mem[REGNO (operand0)];
1716 else if (scratch_reg
1717 && reload_in_progress && GET_CODE (operand0) == SUBREG
1718 && GET_CODE (SUBREG_REG (operand0)) == REG
1719 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1721 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1722 the code which tracks sets/uses for delete_output_reload. */
1723 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1724 reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1725 SUBREG_BYTE (operand0));
1726 operand0 = alter_subreg (&temp);
1729 if (scratch_reg
1730 && reload_in_progress && GET_CODE (operand1) == REG
1731 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1732 operand1 = reg_equiv_mem[REGNO (operand1)];
1733 else if (scratch_reg
1734 && reload_in_progress && GET_CODE (operand1) == SUBREG
1735 && GET_CODE (SUBREG_REG (operand1)) == REG
1736 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1738 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1739 the code which tracks sets/uses for delete_output_reload. */
1740 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1741 reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1742 SUBREG_BYTE (operand1));
1743 operand1 = alter_subreg (&temp);
1746 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1747 && ((tem = find_replacement (&XEXP (operand0, 0)))
1748 != XEXP (operand0, 0)))
1749 operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
1751 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1752 && ((tem = find_replacement (&XEXP (operand1, 0)))
1753 != XEXP (operand1, 0)))
1754 operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
1756 /* Handle secondary reloads for loads/stores of FP registers from
1757 REG+D addresses where D does not fit in 5 or 14 bits, including
1758 (subreg (mem (addr))) cases. */
1759 if (scratch_reg
1760 && fp_reg_operand (operand0, mode)
1761 && ((GET_CODE (operand1) == MEM
1762 && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1763 XEXP (operand1, 0)))
1764 || ((GET_CODE (operand1) == SUBREG
1765 && GET_CODE (XEXP (operand1, 0)) == MEM
1766 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1767 ? SFmode : DFmode),
1768 XEXP (XEXP (operand1, 0), 0))))))
1770 if (GET_CODE (operand1) == SUBREG)
1771 operand1 = XEXP (operand1, 0);
1773 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1774 it in WORD_MODE regardless of what mode it was originally given
1775 to us. */
1776 scratch_reg = force_mode (word_mode, scratch_reg);
1778 /* D might not fit in 14 bits either; for such cases load D into
1779 scratch reg. */
1780 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1782 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1783 emit_move_insn (scratch_reg,
1784 gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1785 Pmode,
1786 XEXP (XEXP (operand1, 0), 0),
1787 scratch_reg));
1789 else
1790 emit_move_insn (scratch_reg, XEXP (operand1, 0));
1791 emit_insn (gen_rtx_SET (VOIDmode, operand0,
1792 gen_rtx_MEM (mode, scratch_reg)));
1793 return 1;
1795 else if (scratch_reg
1796 && fp_reg_operand (operand1, mode)
1797 && ((GET_CODE (operand0) == MEM
1798 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1799 ? SFmode : DFmode),
1800 XEXP (operand0, 0)))
1801 || ((GET_CODE (operand0) == SUBREG)
1802 && GET_CODE (XEXP (operand0, 0)) == MEM
1803 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1804 ? SFmode : DFmode),
1805 XEXP (XEXP (operand0, 0), 0)))))
1807 if (GET_CODE (operand0) == SUBREG)
1808 operand0 = XEXP (operand0, 0);
1810 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1811 it in WORD_MODE regardless of what mode it was originally given
1812 to us. */
1813 scratch_reg = force_mode (word_mode, scratch_reg);
1815 /* D might not fit in 14 bits either; for such cases load D into
1816 scratch reg. */
1817 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1819 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1820 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1821 0)),
1822 Pmode,
1823 XEXP (XEXP (operand0, 0),
1825 scratch_reg));
1827 else
1828 emit_move_insn (scratch_reg, XEXP (operand0, 0));
1829 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
1830 operand1));
1831 return 1;
1833 /* Handle secondary reloads for loads of FP registers from constant
1834 expressions by forcing the constant into memory.
1836 Use scratch_reg to hold the address of the memory location.
1838 The proper fix is to change PREFERRED_RELOAD_CLASS to return
1839 NO_REGS when presented with a const_int and a register class
1840 containing only FP registers. Doing so unfortunately creates
1841 more problems than it solves. Fix this for 2.5. */
1842 else if (scratch_reg
1843 && CONSTANT_P (operand1)
1844 && fp_reg_operand (operand0, mode))
1846 rtx xoperands[2];
1848 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1849 it in WORD_MODE regardless of what mode it was originally given
1850 to us. */
1851 scratch_reg = force_mode (word_mode, scratch_reg);
1853 /* Force the constant into memory and put the address of the
1854 memory location into scratch_reg. */
1855 xoperands[0] = scratch_reg;
1856 xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
1857 emit_move_sequence (xoperands, Pmode, 0);
1859 /* Now load the destination register. */
1860 emit_insn (gen_rtx_SET (mode, operand0,
1861 gen_rtx_MEM (mode, scratch_reg)));
1862 return 1;
1864 /* Handle secondary reloads for SAR. These occur when trying to load
1865 the SAR from memory, FP register, or with a constant. */
1866 else if (scratch_reg
1867 && GET_CODE (operand0) == REG
1868 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1869 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1870 && (GET_CODE (operand1) == MEM
1871 || GET_CODE (operand1) == CONST_INT
1872 || (GET_CODE (operand1) == REG
1873 && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1875 /* D might not fit in 14 bits either; for such cases load D into
1876 scratch reg. */
1877 if (GET_CODE (operand1) == MEM
1878 && !memory_address_p (Pmode, XEXP (operand1, 0)))
1880 /* We are reloading the address into the scratch register, so we
1881 want to make sure the scratch register is a full register. */
1882 scratch_reg = force_mode (word_mode, scratch_reg);
1884 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1885 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1886 0)),
1887 Pmode,
1888 XEXP (XEXP (operand1, 0),
1890 scratch_reg));
1892 /* Now we are going to load the scratch register from memory,
1893 we want to load it in the same width as the original MEM,
1894 which must be the same as the width of the ultimate destination,
1895 OPERAND0. */
1896 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1898 emit_move_insn (scratch_reg, gen_rtx_MEM (GET_MODE (operand0),
1899 scratch_reg));
1901 else
1903 /* We want to load the scratch register using the same mode as
1904 the ultimate destination. */
1905 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1907 emit_move_insn (scratch_reg, operand1);
1910 /* And emit the insn to set the ultimate destination. We know that
1911 the scratch register has the same mode as the destination at this
1912 point. */
1913 emit_move_insn (operand0, scratch_reg);
1914 return 1;
1916 /* Handle the most common case: storing into a register. */
1917 else if (register_operand (operand0, mode))
1919 if (register_operand (operand1, mode)
1920 || (GET_CODE (operand1) == CONST_INT
1921 && cint_ok_for_move (INTVAL (operand1)))
1922 || (operand1 == CONST0_RTX (mode))
1923 || (GET_CODE (operand1) == HIGH
1924 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1925 /* Only `general_operands' can come here, so MEM is ok. */
1926 || GET_CODE (operand1) == MEM)
1928 /* Various sets are created during RTL generation which don't
1929 have the REG_POINTER flag correctly set. After the CSE pass,
1930 instruction recognition can fail if we don't consistently
1931 set this flag when performing register copies. This should
1932 also improve the opportunities for creating insns that use
1933 unscaled indexing. */
1934 if (REG_P (operand0) && REG_P (operand1))
1936 if (REG_POINTER (operand1)
1937 && !REG_POINTER (operand0)
1938 && !HARD_REGISTER_P (operand0))
1939 copy_reg_pointer (operand0, operand1);
1940 else if (REG_POINTER (operand0)
1941 && !REG_POINTER (operand1)
1942 && !HARD_REGISTER_P (operand1))
1943 copy_reg_pointer (operand1, operand0);
1946 /* When MEMs are broken out, the REG_POINTER flag doesn't
1947 get set. In some cases, we can set the REG_POINTER flag
1948 from the declaration for the MEM. */
1949 if (REG_P (operand0)
1950 && GET_CODE (operand1) == MEM
1951 && !REG_POINTER (operand0))
1953 tree decl = MEM_EXPR (operand1);
1955 /* Set the register pointer flag and register alignment
1956 if the declaration for this memory reference is a
1957 pointer type. Fortran indirect argument references
1958 are ignored. */
1959 if (decl
1960 && !(flag_argument_noalias > 1
1961 && TREE_CODE (decl) == INDIRECT_REF
1962 && TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL))
1964 tree type;
1966 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1967 tree operand 1. */
1968 if (TREE_CODE (decl) == COMPONENT_REF)
1969 decl = TREE_OPERAND (decl, 1);
1971 type = TREE_TYPE (decl);
1972 if (TREE_CODE (type) == ARRAY_TYPE)
1973 type = get_inner_array_type (type);
1975 if (POINTER_TYPE_P (type))
1977 int align;
1979 type = TREE_TYPE (type);
1980 /* Using TYPE_ALIGN_OK is rather conservative as
1981 only the ada frontend actually sets it. */
1982 align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1983 : BITS_PER_UNIT);
1984 mark_reg_pointer (operand0, align);
1989 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1990 return 1;
1993 else if (GET_CODE (operand0) == MEM)
1995 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1996 && !(reload_in_progress || reload_completed))
1998 rtx temp = gen_reg_rtx (DFmode);
2000 emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
2001 emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
2002 return 1;
2004 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
2006 /* Run this case quickly. */
2007 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
2008 return 1;
2010 if (! (reload_in_progress || reload_completed))
2012 operands[0] = validize_mem (operand0);
2013 operands[1] = operand1 = force_reg (mode, operand1);
2017 /* Simplify the source if we need to.
2018 Note we do have to handle function labels here, even though we do
2019 not consider them legitimate constants. Loop optimizations can
2020 call the emit_move_xxx with one as a source. */
2021 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
2022 || function_label_operand (operand1, mode)
2023 || (GET_CODE (operand1) == HIGH
2024 && symbolic_operand (XEXP (operand1, 0), mode)))
2026 int ishighonly = 0;
2028 if (GET_CODE (operand1) == HIGH)
2030 ishighonly = 1;
2031 operand1 = XEXP (operand1, 0);
2033 if (symbolic_operand (operand1, mode))
2035 /* Argh. The assembler and linker can't handle arithmetic
2036 involving plabels.
2038 So we force the plabel into memory, load operand0 from
2039 the memory location, then add in the constant part. */
2040 if ((GET_CODE (operand1) == CONST
2041 && GET_CODE (XEXP (operand1, 0)) == PLUS
2042 && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
2043 || function_label_operand (operand1, mode))
2045 rtx temp, const_part;
2047 /* Figure out what (if any) scratch register to use. */
2048 if (reload_in_progress || reload_completed)
2050 scratch_reg = scratch_reg ? scratch_reg : operand0;
2051 /* SCRATCH_REG will hold an address and maybe the actual
2052 data. We want it in WORD_MODE regardless of what mode it
2053 was originally given to us. */
2054 scratch_reg = force_mode (word_mode, scratch_reg);
2056 else if (flag_pic)
2057 scratch_reg = gen_reg_rtx (Pmode);
2059 if (GET_CODE (operand1) == CONST)
2061 /* Save away the constant part of the expression. */
2062 const_part = XEXP (XEXP (operand1, 0), 1);
2063 if (GET_CODE (const_part) != CONST_INT)
2064 abort ();
2066 /* Force the function label into memory. */
2067 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
2069 else
2071 /* No constant part. */
2072 const_part = NULL_RTX;
2074 /* Force the function label into memory. */
2075 temp = force_const_mem (mode, operand1);
2079 /* Get the address of the memory location. PIC-ify it if
2080 necessary. */
2081 temp = XEXP (temp, 0);
2082 if (flag_pic)
2083 temp = legitimize_pic_address (temp, mode, scratch_reg);
2085 /* Put the address of the memory location into our destination
2086 register. */
2087 operands[1] = temp;
2088 emit_move_sequence (operands, mode, scratch_reg);
2090 /* Now load from the memory location into our destination
2091 register. */
2092 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
2093 emit_move_sequence (operands, mode, scratch_reg);
2095 /* And add back in the constant part. */
2096 if (const_part != NULL_RTX)
2097 expand_inc (operand0, const_part);
2099 return 1;
2102 if (flag_pic)
2104 rtx temp;
2106 if (reload_in_progress || reload_completed)
2108 temp = scratch_reg ? scratch_reg : operand0;
2109 /* TEMP will hold an address and maybe the actual
2110 data. We want it in WORD_MODE regardless of what mode it
2111 was originally given to us. */
2112 temp = force_mode (word_mode, temp);
2114 else
2115 temp = gen_reg_rtx (Pmode);
2117 /* (const (plus (symbol) (const_int))) must be forced to
2118 memory during/after reload if the const_int will not fit
2119 in 14 bits. */
2120 if (GET_CODE (operand1) == CONST
2121 && GET_CODE (XEXP (operand1, 0)) == PLUS
2122 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
2123 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
2124 && (reload_completed || reload_in_progress)
2125 && flag_pic)
2127 operands[1] = force_const_mem (mode, operand1);
2128 operands[1] = legitimize_pic_address (XEXP (operands[1], 0),
2129 mode, temp);
2130 operands[1] = gen_rtx_MEM (mode, operands[1]);
2131 emit_move_sequence (operands, mode, temp);
2133 else
2135 operands[1] = legitimize_pic_address (operand1, mode, temp);
2136 if (REG_P (operand0) && REG_P (operands[1]))
2137 copy_reg_pointer (operand0, operands[1]);
2138 emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
2141 /* On the HPPA, references to data space are supposed to use dp,
2142 register 27, but showing it in the RTL inhibits various cse
2143 and loop optimizations. */
2144 else
2146 rtx temp, set;
2148 if (reload_in_progress || reload_completed)
2150 temp = scratch_reg ? scratch_reg : operand0;
2151 /* TEMP will hold an address and maybe the actual
2152 data. We want it in WORD_MODE regardless of what mode it
2153 was originally given to us. */
2154 temp = force_mode (word_mode, temp);
2156 else
2157 temp = gen_reg_rtx (mode);
2159 /* Loading a SYMBOL_REF into a register makes that register
2160 safe to be used as the base in an indexed address.
2162 Don't mark hard registers though. That loses. */
2163 if (GET_CODE (operand0) == REG
2164 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
2165 mark_reg_pointer (operand0, BITS_PER_UNIT);
2166 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
2167 mark_reg_pointer (temp, BITS_PER_UNIT);
2169 if (ishighonly)
2170 set = gen_rtx_SET (mode, operand0, temp);
2171 else
2172 set = gen_rtx_SET (VOIDmode,
2173 operand0,
2174 gen_rtx_LO_SUM (mode, temp, operand1));
2176 emit_insn (gen_rtx_SET (VOIDmode,
2177 temp,
2178 gen_rtx_HIGH (mode, operand1)));
2179 emit_insn (set);
2182 return 1;
2184 else if (GET_CODE (operand1) != CONST_INT
2185 || !cint_ok_for_move (INTVAL (operand1)))
2187 rtx insn, temp;
2188 rtx op1 = operand1;
2189 HOST_WIDE_INT value = 0;
2190 HOST_WIDE_INT insv = 0;
2191 int insert = 0;
2193 if (GET_CODE (operand1) == CONST_INT)
2194 value = INTVAL (operand1);
2196 if (TARGET_64BIT
2197 && GET_CODE (operand1) == CONST_INT
2198 && HOST_BITS_PER_WIDE_INT > 32
2199 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
2201 HOST_WIDE_INT nval;
2203 /* Extract the low order 32 bits of the value and sign extend.
2204 If the new value is the same as the original value, we can
2205 can use the original value as-is. If the new value is
2206 different, we use it and insert the most-significant 32-bits
2207 of the original value into the final result. */
2208 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
2209 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
2210 if (value != nval)
2212 #if HOST_BITS_PER_WIDE_INT > 32
2213 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
2214 #endif
2215 insert = 1;
2216 value = nval;
2217 operand1 = GEN_INT (nval);
2221 if (reload_in_progress || reload_completed)
2222 temp = scratch_reg ? scratch_reg : operand0;
2223 else
2224 temp = gen_reg_rtx (mode);
2226 /* We don't directly split DImode constants on 32-bit targets
2227 because PLUS uses an 11-bit immediate and the insn sequence
2228 generated is not as efficient as the one using HIGH/LO_SUM. */
2229 if (GET_CODE (operand1) == CONST_INT
2230 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2231 && !insert)
2233 /* Directly break constant into high and low parts. This
2234 provides better optimization opportunities because various
2235 passes recognize constants split with PLUS but not LO_SUM.
2236 We use a 14-bit signed low part except when the addition
2237 of 0x4000 to the high part might change the sign of the
2238 high part. */
2239 HOST_WIDE_INT low = value & 0x3fff;
2240 HOST_WIDE_INT high = value & ~ 0x3fff;
2242 if (low >= 0x2000)
2244 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
2245 high += 0x2000;
2246 else
2247 high += 0x4000;
2250 low = value - high;
2252 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
2253 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2255 else
2257 emit_insn (gen_rtx_SET (VOIDmode, temp,
2258 gen_rtx_HIGH (mode, operand1)));
2259 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
2262 insn = emit_move_insn (operands[0], operands[1]);
2264 /* Now insert the most significant 32 bits of the value
2265 into the register. When we don't have a second register
2266 available, it could take up to nine instructions to load
2267 a 64-bit integer constant. Prior to reload, we force
2268 constants that would take more than three instructions
2269 to load to the constant pool. During and after reload,
2270 we have to handle all possible values. */
2271 if (insert)
2273 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
2274 register and the value to be inserted is outside the
2275 range that can be loaded with three depdi instructions. */
2276 if (temp != operand0 && (insv >= 16384 || insv < -16384))
2278 operand1 = GEN_INT (insv);
2280 emit_insn (gen_rtx_SET (VOIDmode, temp,
2281 gen_rtx_HIGH (mode, operand1)));
2282 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
2283 emit_insn (gen_insv (operand0, GEN_INT (32),
2284 const0_rtx, temp));
2286 else
2288 int len = 5, pos = 27;
2290 /* Insert the bits using the depdi instruction. */
2291 while (pos >= 0)
2293 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2294 HOST_WIDE_INT sign = v5 < 0;
2296 /* Left extend the insertion. */
2297 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2298 while (pos > 0 && (insv & 1) == sign)
2300 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2301 len += 1;
2302 pos -= 1;
2305 emit_insn (gen_insv (operand0, GEN_INT (len),
2306 GEN_INT (pos), GEN_INT (v5)));
2308 len = pos > 0 && pos < 5 ? pos : 5;
2309 pos -= len;
2314 REG_NOTES (insn)
2315 = gen_rtx_EXPR_LIST (REG_EQUAL, op1, REG_NOTES (insn));
2317 return 1;
2320 /* Now have insn-emit do whatever it normally does. */
2321 return 0;
2324 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2325 it will need a link/runtime reloc). */
2328 reloc_needed (tree exp)
2330 int reloc = 0;
2332 switch (TREE_CODE (exp))
2334 case ADDR_EXPR:
2335 return 1;
2337 case PLUS_EXPR:
2338 case MINUS_EXPR:
2339 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2340 reloc |= reloc_needed (TREE_OPERAND (exp, 1));
2341 break;
2343 case NOP_EXPR:
2344 case CONVERT_EXPR:
2345 case NON_LVALUE_EXPR:
2346 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2347 break;
2349 case CONSTRUCTOR:
2351 register tree link;
2352 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2353 if (TREE_VALUE (link) != 0)
2354 reloc |= reloc_needed (TREE_VALUE (link));
2356 break;
2358 case ERROR_MARK:
2359 break;
2361 default:
2362 break;
2364 return reloc;
2367 /* Does operand (which is a symbolic_operand) live in text space?
2368 If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2369 will be true. */
2372 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2374 if (GET_CODE (operand) == CONST)
2375 operand = XEXP (XEXP (operand, 0), 0);
2376 if (flag_pic)
2378 if (GET_CODE (operand) == SYMBOL_REF)
2379 return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2381 else
2383 if (GET_CODE (operand) == SYMBOL_REF)
2384 return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2386 return 1;
2390 /* Return the best assembler insn template
2391 for moving operands[1] into operands[0] as a fullword. */
2392 const char *
2393 singlemove_string (rtx *operands)
2395 HOST_WIDE_INT intval;
2397 if (GET_CODE (operands[0]) == MEM)
2398 return "stw %r1,%0";
2399 if (GET_CODE (operands[1]) == MEM)
2400 return "ldw %1,%0";
2401 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2403 long i;
2404 REAL_VALUE_TYPE d;
2406 if (GET_MODE (operands[1]) != SFmode)
2407 abort ();
2409 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2410 bit pattern. */
2411 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2412 REAL_VALUE_TO_TARGET_SINGLE (d, i);
2414 operands[1] = GEN_INT (i);
2415 /* Fall through to CONST_INT case. */
2417 if (GET_CODE (operands[1]) == CONST_INT)
2419 intval = INTVAL (operands[1]);
2421 if (VAL_14_BITS_P (intval))
2422 return "ldi %1,%0";
2423 else if ((intval & 0x7ff) == 0)
2424 return "ldil L'%1,%0";
2425 else if (zdepi_cint_p (intval))
2426 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2427 else
2428 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2430 return "copy %1,%0";
2434 /* Compute position (in OP[1]) and width (in OP[2])
2435 useful for copying IMM to a register using the zdepi
2436 instructions. Store the immediate value to insert in OP[0]. */
2437 static void
2438 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2440 int lsb, len;
2442 /* Find the least significant set bit in IMM. */
2443 for (lsb = 0; lsb < 32; lsb++)
2445 if ((imm & 1) != 0)
2446 break;
2447 imm >>= 1;
2450 /* Choose variants based on *sign* of the 5-bit field. */
2451 if ((imm & 0x10) == 0)
2452 len = (lsb <= 28) ? 4 : 32 - lsb;
2453 else
2455 /* Find the width of the bitstring in IMM. */
2456 for (len = 5; len < 32; len++)
2458 if ((imm & (1 << len)) == 0)
2459 break;
2462 /* Sign extend IMM as a 5-bit value. */
2463 imm = (imm & 0xf) - 0x10;
2466 op[0] = imm;
2467 op[1] = 31 - lsb;
2468 op[2] = len;
2471 /* Compute position (in OP[1]) and width (in OP[2])
2472 useful for copying IMM to a register using the depdi,z
2473 instructions. Store the immediate value to insert in OP[0]. */
2474 void
2475 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2477 HOST_WIDE_INT lsb, len;
2479 /* Find the least significant set bit in IMM. */
2480 for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
2482 if ((imm & 1) != 0)
2483 break;
2484 imm >>= 1;
2487 /* Choose variants based on *sign* of the 5-bit field. */
2488 if ((imm & 0x10) == 0)
2489 len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
2490 ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
2491 else
2493 /* Find the width of the bitstring in IMM. */
2494 for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
2496 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2497 break;
2500 /* Sign extend IMM as a 5-bit value. */
2501 imm = (imm & 0xf) - 0x10;
2504 op[0] = imm;
2505 op[1] = 63 - lsb;
2506 op[2] = len;
2509 /* Output assembler code to perform a doubleword move insn
2510 with operands OPERANDS. */
2512 const char *
2513 output_move_double (rtx *operands)
2515 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2516 rtx latehalf[2];
2517 rtx addreg0 = 0, addreg1 = 0;
2519 /* First classify both operands. */
2521 if (REG_P (operands[0]))
2522 optype0 = REGOP;
2523 else if (offsettable_memref_p (operands[0]))
2524 optype0 = OFFSOP;
2525 else if (GET_CODE (operands[0]) == MEM)
2526 optype0 = MEMOP;
2527 else
2528 optype0 = RNDOP;
2530 if (REG_P (operands[1]))
2531 optype1 = REGOP;
2532 else if (CONSTANT_P (operands[1]))
2533 optype1 = CNSTOP;
2534 else if (offsettable_memref_p (operands[1]))
2535 optype1 = OFFSOP;
2536 else if (GET_CODE (operands[1]) == MEM)
2537 optype1 = MEMOP;
2538 else
2539 optype1 = RNDOP;
2541 /* Check for the cases that the operand constraints are not
2542 supposed to allow to happen. Abort if we get one,
2543 because generating code for these cases is painful. */
2545 if (optype0 != REGOP && optype1 != REGOP)
2546 abort ();
2548 /* Handle auto decrementing and incrementing loads and stores
2549 specifically, since the structure of the function doesn't work
2550 for them without major modification. Do it better when we learn
2551 this port about the general inc/dec addressing of PA.
2552 (This was written by tege. Chide him if it doesn't work.) */
2554 if (optype0 == MEMOP)
2556 /* We have to output the address syntax ourselves, since print_operand
2557 doesn't deal with the addresses we want to use. Fix this later. */
2559 rtx addr = XEXP (operands[0], 0);
2560 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2562 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2564 operands[0] = XEXP (addr, 0);
2565 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2566 abort ();
2568 if (!reg_overlap_mentioned_p (high_reg, addr))
2570 /* No overlap between high target register and address
2571 register. (We do this in a non-obvious way to
2572 save a register file writeback) */
2573 if (GET_CODE (addr) == POST_INC)
2574 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2575 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2577 else
2578 abort ();
2580 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2582 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2584 operands[0] = XEXP (addr, 0);
2585 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2586 abort ();
2588 if (!reg_overlap_mentioned_p (high_reg, addr))
2590 /* No overlap between high target register and address
2591 register. (We do this in a non-obvious way to
2592 save a register file writeback) */
2593 if (GET_CODE (addr) == PRE_INC)
2594 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2595 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2597 else
2598 abort ();
2601 if (optype1 == MEMOP)
2603 /* We have to output the address syntax ourselves, since print_operand
2604 doesn't deal with the addresses we want to use. Fix this later. */
2606 rtx addr = XEXP (operands[1], 0);
2607 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2609 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2611 operands[1] = XEXP (addr, 0);
2612 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2613 abort ();
2615 if (!reg_overlap_mentioned_p (high_reg, addr))
2617 /* No overlap between high target register and address
2618 register. (We do this in a non-obvious way to
2619 save a register file writeback) */
2620 if (GET_CODE (addr) == POST_INC)
2621 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2622 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2624 else
2626 /* This is an undefined situation. We should load into the
2627 address register *and* update that register. Probably
2628 we don't need to handle this at all. */
2629 if (GET_CODE (addr) == POST_INC)
2630 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2631 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2634 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2636 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2638 operands[1] = XEXP (addr, 0);
2639 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2640 abort ();
2642 if (!reg_overlap_mentioned_p (high_reg, addr))
2644 /* No overlap between high target register and address
2645 register. (We do this in a non-obvious way to
2646 save a register file writeback) */
2647 if (GET_CODE (addr) == PRE_INC)
2648 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2649 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2651 else
2653 /* This is an undefined situation. We should load into the
2654 address register *and* update that register. Probably
2655 we don't need to handle this at all. */
2656 if (GET_CODE (addr) == PRE_INC)
2657 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2658 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2661 else if (GET_CODE (addr) == PLUS
2662 && GET_CODE (XEXP (addr, 0)) == MULT)
2664 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2666 if (!reg_overlap_mentioned_p (high_reg, addr))
2668 rtx xoperands[3];
2670 xoperands[0] = high_reg;
2671 xoperands[1] = XEXP (addr, 1);
2672 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2673 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2674 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2675 xoperands);
2676 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2678 else
2680 rtx xoperands[3];
2682 xoperands[0] = high_reg;
2683 xoperands[1] = XEXP (addr, 1);
2684 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2685 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2686 output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2687 xoperands);
2688 return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2693 /* If an operand is an unoffsettable memory ref, find a register
2694 we can increment temporarily to make it refer to the second word. */
2696 if (optype0 == MEMOP)
2697 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2699 if (optype1 == MEMOP)
2700 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2702 /* Ok, we can do one word at a time.
2703 Normally we do the low-numbered word first.
2705 In either case, set up in LATEHALF the operands to use
2706 for the high-numbered word and in some cases alter the
2707 operands in OPERANDS to be suitable for the low-numbered word. */
2709 if (optype0 == REGOP)
2710 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2711 else if (optype0 == OFFSOP)
2712 latehalf[0] = adjust_address (operands[0], SImode, 4);
2713 else
2714 latehalf[0] = operands[0];
2716 if (optype1 == REGOP)
2717 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2718 else if (optype1 == OFFSOP)
2719 latehalf[1] = adjust_address (operands[1], SImode, 4);
2720 else if (optype1 == CNSTOP)
2721 split_double (operands[1], &operands[1], &latehalf[1]);
2722 else
2723 latehalf[1] = operands[1];
2725 /* If the first move would clobber the source of the second one,
2726 do them in the other order.
2728 This can happen in two cases:
2730 mem -> register where the first half of the destination register
2731 is the same register used in the memory's address. Reload
2732 can create such insns.
2734 mem in this case will be either register indirect or register
2735 indirect plus a valid offset.
2737 register -> register move where REGNO(dst) == REGNO(src + 1)
2738 someone (Tim/Tege?) claimed this can happen for parameter loads.
2740 Handle mem -> register case first. */
2741 if (optype0 == REGOP
2742 && (optype1 == MEMOP || optype1 == OFFSOP)
2743 && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2744 operands[1], 0))
2746 /* Do the late half first. */
2747 if (addreg1)
2748 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2749 output_asm_insn (singlemove_string (latehalf), latehalf);
2751 /* Then clobber. */
2752 if (addreg1)
2753 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2754 return singlemove_string (operands);
2757 /* Now handle register -> register case. */
2758 if (optype0 == REGOP && optype1 == REGOP
2759 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2761 output_asm_insn (singlemove_string (latehalf), latehalf);
2762 return singlemove_string (operands);
2765 /* Normal case: do the two words, low-numbered first. */
2767 output_asm_insn (singlemove_string (operands), operands);
2769 /* Make any unoffsettable addresses point at high-numbered word. */
2770 if (addreg0)
2771 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2772 if (addreg1)
2773 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2775 /* Do that word. */
2776 output_asm_insn (singlemove_string (latehalf), latehalf);
2778 /* Undo the adds we just did. */
2779 if (addreg0)
2780 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2781 if (addreg1)
2782 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2784 return "";
2787 const char *
2788 output_fp_move_double (rtx *operands)
2790 if (FP_REG_P (operands[0]))
2792 if (FP_REG_P (operands[1])
2793 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2794 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2795 else
2796 output_asm_insn ("fldd%F1 %1,%0", operands);
2798 else if (FP_REG_P (operands[1]))
2800 output_asm_insn ("fstd%F0 %1,%0", operands);
2802 else if (operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2804 if (GET_CODE (operands[0]) == REG)
2806 rtx xoperands[2];
2807 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2808 xoperands[0] = operands[0];
2809 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2811 /* This is a pain. You have to be prepared to deal with an
2812 arbitrary address here including pre/post increment/decrement.
2814 so avoid this in the MD. */
2815 else
2816 abort ();
2818 else abort ();
2819 return "";
2822 /* Return a REG that occurs in ADDR with coefficient 1.
2823 ADDR can be effectively incremented by incrementing REG. */
2825 static rtx
2826 find_addr_reg (rtx addr)
2828 while (GET_CODE (addr) == PLUS)
2830 if (GET_CODE (XEXP (addr, 0)) == REG)
2831 addr = XEXP (addr, 0);
2832 else if (GET_CODE (XEXP (addr, 1)) == REG)
2833 addr = XEXP (addr, 1);
2834 else if (CONSTANT_P (XEXP (addr, 0)))
2835 addr = XEXP (addr, 1);
2836 else if (CONSTANT_P (XEXP (addr, 1)))
2837 addr = XEXP (addr, 0);
2838 else
2839 abort ();
2841 if (GET_CODE (addr) == REG)
2842 return addr;
2843 abort ();
2846 /* Emit code to perform a block move.
2848 OPERANDS[0] is the destination pointer as a REG, clobbered.
2849 OPERANDS[1] is the source pointer as a REG, clobbered.
2850 OPERANDS[2] is a register for temporary storage.
2851 OPERANDS[3] is a register for temporary storage.
2852 OPERANDS[4] is the size as a CONST_INT
2853 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2854 OPERANDS[6] is another temporary register. */
2856 const char *
2857 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2859 int align = INTVAL (operands[5]);
2860 unsigned long n_bytes = INTVAL (operands[4]);
2862 /* We can't move more than a word at a time because the PA
2863 has no longer integer move insns. (Could use fp mem ops?) */
2864 if (align > (TARGET_64BIT ? 8 : 4))
2865 align = (TARGET_64BIT ? 8 : 4);
2867 /* Note that we know each loop below will execute at least twice
2868 (else we would have open-coded the copy). */
2869 switch (align)
2871 case 8:
2872 /* Pre-adjust the loop counter. */
2873 operands[4] = GEN_INT (n_bytes - 16);
2874 output_asm_insn ("ldi %4,%2", operands);
2876 /* Copying loop. */
2877 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2878 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2879 output_asm_insn ("std,ma %3,8(%0)", operands);
2880 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2881 output_asm_insn ("std,ma %6,8(%0)", operands);
2883 /* Handle the residual. There could be up to 7 bytes of
2884 residual to copy! */
2885 if (n_bytes % 16 != 0)
2887 operands[4] = GEN_INT (n_bytes % 8);
2888 if (n_bytes % 16 >= 8)
2889 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2890 if (n_bytes % 8 != 0)
2891 output_asm_insn ("ldd 0(%1),%6", operands);
2892 if (n_bytes % 16 >= 8)
2893 output_asm_insn ("std,ma %3,8(%0)", operands);
2894 if (n_bytes % 8 != 0)
2895 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2897 return "";
2899 case 4:
2900 /* Pre-adjust the loop counter. */
2901 operands[4] = GEN_INT (n_bytes - 8);
2902 output_asm_insn ("ldi %4,%2", operands);
2904 /* Copying loop. */
2905 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2906 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2907 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2908 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2909 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2911 /* Handle the residual. There could be up to 7 bytes of
2912 residual to copy! */
2913 if (n_bytes % 8 != 0)
2915 operands[4] = GEN_INT (n_bytes % 4);
2916 if (n_bytes % 8 >= 4)
2917 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2918 if (n_bytes % 4 != 0)
2919 output_asm_insn ("ldw 0(%1),%6", operands);
2920 if (n_bytes % 8 >= 4)
2921 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2922 if (n_bytes % 4 != 0)
2923 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2925 return "";
2927 case 2:
2928 /* Pre-adjust the loop counter. */
2929 operands[4] = GEN_INT (n_bytes - 4);
2930 output_asm_insn ("ldi %4,%2", operands);
2932 /* Copying loop. */
2933 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2934 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2935 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2936 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2937 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2939 /* Handle the residual. */
2940 if (n_bytes % 4 != 0)
2942 if (n_bytes % 4 >= 2)
2943 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2944 if (n_bytes % 2 != 0)
2945 output_asm_insn ("ldb 0(%1),%6", operands);
2946 if (n_bytes % 4 >= 2)
2947 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2948 if (n_bytes % 2 != 0)
2949 output_asm_insn ("stb %6,0(%0)", operands);
2951 return "";
2953 case 1:
2954 /* Pre-adjust the loop counter. */
2955 operands[4] = GEN_INT (n_bytes - 2);
2956 output_asm_insn ("ldi %4,%2", operands);
2958 /* Copying loop. */
2959 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2960 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2961 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2962 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2963 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2965 /* Handle the residual. */
2966 if (n_bytes % 2 != 0)
2968 output_asm_insn ("ldb 0(%1),%3", operands);
2969 output_asm_insn ("stb %3,0(%0)", operands);
2971 return "";
2973 default:
2974 abort ();
2978 /* Count the number of insns necessary to handle this block move.
2980 Basic structure is the same as emit_block_move, except that we
2981 count insns rather than emit them. */
2983 static int
2984 compute_movmem_length (rtx insn)
2986 rtx pat = PATTERN (insn);
2987 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2988 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2989 unsigned int n_insns = 0;
2991 /* We can't move more than four bytes at a time because the PA
2992 has no longer integer move insns. (Could use fp mem ops?) */
2993 if (align > (TARGET_64BIT ? 8 : 4))
2994 align = (TARGET_64BIT ? 8 : 4);
2996 /* The basic copying loop. */
2997 n_insns = 6;
2999 /* Residuals. */
3000 if (n_bytes % (2 * align) != 0)
3002 if ((n_bytes % (2 * align)) >= align)
3003 n_insns += 2;
3005 if ((n_bytes % align) != 0)
3006 n_insns += 2;
3009 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3010 return n_insns * 4;
3013 /* Emit code to perform a block clear.
3015 OPERANDS[0] is the destination pointer as a REG, clobbered.
3016 OPERANDS[1] is a register for temporary storage.
3017 OPERANDS[2] is the size as a CONST_INT
3018 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
3020 const char *
3021 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
3023 int align = INTVAL (operands[3]);
3024 unsigned long n_bytes = INTVAL (operands[2]);
3026 /* We can't clear more than a word at a time because the PA
3027 has no longer integer move insns. */
3028 if (align > (TARGET_64BIT ? 8 : 4))
3029 align = (TARGET_64BIT ? 8 : 4);
3031 /* Note that we know each loop below will execute at least twice
3032 (else we would have open-coded the copy). */
3033 switch (align)
3035 case 8:
3036 /* Pre-adjust the loop counter. */
3037 operands[2] = GEN_INT (n_bytes - 16);
3038 output_asm_insn ("ldi %2,%1", operands);
3040 /* Loop. */
3041 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3042 output_asm_insn ("addib,>= -16,%1,.-4", operands);
3043 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3045 /* Handle the residual. There could be up to 7 bytes of
3046 residual to copy! */
3047 if (n_bytes % 16 != 0)
3049 operands[2] = GEN_INT (n_bytes % 8);
3050 if (n_bytes % 16 >= 8)
3051 output_asm_insn ("std,ma %%r0,8(%0)", operands);
3052 if (n_bytes % 8 != 0)
3053 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
3055 return "";
3057 case 4:
3058 /* Pre-adjust the loop counter. */
3059 operands[2] = GEN_INT (n_bytes - 8);
3060 output_asm_insn ("ldi %2,%1", operands);
3062 /* Loop. */
3063 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3064 output_asm_insn ("addib,>= -8,%1,.-4", operands);
3065 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3067 /* Handle the residual. There could be up to 7 bytes of
3068 residual to copy! */
3069 if (n_bytes % 8 != 0)
3071 operands[2] = GEN_INT (n_bytes % 4);
3072 if (n_bytes % 8 >= 4)
3073 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
3074 if (n_bytes % 4 != 0)
3075 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
3077 return "";
3079 case 2:
3080 /* Pre-adjust the loop counter. */
3081 operands[2] = GEN_INT (n_bytes - 4);
3082 output_asm_insn ("ldi %2,%1", operands);
3084 /* Loop. */
3085 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3086 output_asm_insn ("addib,>= -4,%1,.-4", operands);
3087 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3089 /* Handle the residual. */
3090 if (n_bytes % 4 != 0)
3092 if (n_bytes % 4 >= 2)
3093 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3094 if (n_bytes % 2 != 0)
3095 output_asm_insn ("stb %%r0,0(%0)", operands);
3097 return "";
3099 case 1:
3100 /* Pre-adjust the loop counter. */
3101 operands[2] = GEN_INT (n_bytes - 2);
3102 output_asm_insn ("ldi %2,%1", operands);
3104 /* Loop. */
3105 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3106 output_asm_insn ("addib,>= -2,%1,.-4", operands);
3107 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3109 /* Handle the residual. */
3110 if (n_bytes % 2 != 0)
3111 output_asm_insn ("stb %%r0,0(%0)", operands);
3113 return "";
3115 default:
3116 abort ();
3120 /* Count the number of insns necessary to handle this block move.
3122 Basic structure is the same as emit_block_move, except that we
3123 count insns rather than emit them. */
3125 static int
3126 compute_clrmem_length (rtx insn)
3128 rtx pat = PATTERN (insn);
3129 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
3130 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
3131 unsigned int n_insns = 0;
3133 /* We can't clear more than a word at a time because the PA
3134 has no longer integer move insns. */
3135 if (align > (TARGET_64BIT ? 8 : 4))
3136 align = (TARGET_64BIT ? 8 : 4);
3138 /* The basic loop. */
3139 n_insns = 4;
3141 /* Residuals. */
3142 if (n_bytes % (2 * align) != 0)
3144 if ((n_bytes % (2 * align)) >= align)
3145 n_insns++;
3147 if ((n_bytes % align) != 0)
3148 n_insns++;
3151 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3152 return n_insns * 4;
3156 const char *
3157 output_and (rtx *operands)
3159 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3161 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3162 int ls0, ls1, ms0, p, len;
3164 for (ls0 = 0; ls0 < 32; ls0++)
3165 if ((mask & (1 << ls0)) == 0)
3166 break;
3168 for (ls1 = ls0; ls1 < 32; ls1++)
3169 if ((mask & (1 << ls1)) != 0)
3170 break;
3172 for (ms0 = ls1; ms0 < 32; ms0++)
3173 if ((mask & (1 << ms0)) == 0)
3174 break;
3176 if (ms0 != 32)
3177 abort ();
3179 if (ls1 == 32)
3181 len = ls0;
3183 if (len == 0)
3184 abort ();
3186 operands[2] = GEN_INT (len);
3187 return "{extru|extrw,u} %1,31,%2,%0";
3189 else
3191 /* We could use this `depi' for the case above as well, but `depi'
3192 requires one more register file access than an `extru'. */
3194 p = 31 - ls0;
3195 len = ls1 - ls0;
3197 operands[2] = GEN_INT (p);
3198 operands[3] = GEN_INT (len);
3199 return "{depi|depwi} 0,%2,%3,%0";
3202 else
3203 return "and %1,%2,%0";
3206 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3207 storing the result in operands[0]. */
3208 const char *
3209 output_64bit_and (rtx *operands)
3211 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3213 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3214 int ls0, ls1, ms0, p, len;
3216 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
3217 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
3218 break;
3220 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
3221 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
3222 break;
3224 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
3225 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
3226 break;
3228 if (ms0 != HOST_BITS_PER_WIDE_INT)
3229 abort ();
3231 if (ls1 == HOST_BITS_PER_WIDE_INT)
3233 len = ls0;
3235 if (len == 0)
3236 abort ();
3238 operands[2] = GEN_INT (len);
3239 return "extrd,u %1,63,%2,%0";
3241 else
3243 /* We could use this `depi' for the case above as well, but `depi'
3244 requires one more register file access than an `extru'. */
3246 p = 63 - ls0;
3247 len = ls1 - ls0;
3249 operands[2] = GEN_INT (p);
3250 operands[3] = GEN_INT (len);
3251 return "depdi 0,%2,%3,%0";
3254 else
3255 return "and %1,%2,%0";
3258 const char *
3259 output_ior (rtx *operands)
3261 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3262 int bs0, bs1, p, len;
3264 if (INTVAL (operands[2]) == 0)
3265 return "copy %1,%0";
3267 for (bs0 = 0; bs0 < 32; bs0++)
3268 if ((mask & (1 << bs0)) != 0)
3269 break;
3271 for (bs1 = bs0; bs1 < 32; bs1++)
3272 if ((mask & (1 << bs1)) == 0)
3273 break;
3275 if (bs1 != 32 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3276 abort ();
3278 p = 31 - bs0;
3279 len = bs1 - bs0;
3281 operands[2] = GEN_INT (p);
3282 operands[3] = GEN_INT (len);
3283 return "{depi|depwi} -1,%2,%3,%0";
3286 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3287 storing the result in operands[0]. */
3288 const char *
3289 output_64bit_ior (rtx *operands)
3291 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3292 int bs0, bs1, p, len;
3294 if (INTVAL (operands[2]) == 0)
3295 return "copy %1,%0";
3297 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3298 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3299 break;
3301 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3302 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3303 break;
3305 if (bs1 != HOST_BITS_PER_WIDE_INT
3306 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3307 abort ();
3309 p = 63 - bs0;
3310 len = bs1 - bs0;
3312 operands[2] = GEN_INT (p);
3313 operands[3] = GEN_INT (len);
3314 return "depdi -1,%2,%3,%0";
3317 /* Target hook for assembling integer objects. This code handles
3318 aligned SI and DI integers specially since function references
3319 must be preceded by P%. */
3321 static bool
3322 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3324 if (size == UNITS_PER_WORD
3325 && aligned_p
3326 && function_label_operand (x, VOIDmode))
3328 fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
3329 output_addr_const (asm_out_file, x);
3330 fputc ('\n', asm_out_file);
3331 return true;
3333 return default_assemble_integer (x, size, aligned_p);
3336 /* Output an ascii string. */
3337 void
3338 output_ascii (FILE *file, const char *p, int size)
3340 int i;
3341 int chars_output;
3342 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3344 /* The HP assembler can only take strings of 256 characters at one
3345 time. This is a limitation on input line length, *not* the
3346 length of the string. Sigh. Even worse, it seems that the
3347 restriction is in number of input characters (see \xnn &
3348 \whatever). So we have to do this very carefully. */
3350 fputs ("\t.STRING \"", file);
3352 chars_output = 0;
3353 for (i = 0; i < size; i += 4)
3355 int co = 0;
3356 int io = 0;
3357 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3359 register unsigned int c = (unsigned char) p[i + io];
3361 if (c == '\"' || c == '\\')
3362 partial_output[co++] = '\\';
3363 if (c >= ' ' && c < 0177)
3364 partial_output[co++] = c;
3365 else
3367 unsigned int hexd;
3368 partial_output[co++] = '\\';
3369 partial_output[co++] = 'x';
3370 hexd = c / 16 - 0 + '0';
3371 if (hexd > '9')
3372 hexd -= '9' - 'a' + 1;
3373 partial_output[co++] = hexd;
3374 hexd = c % 16 - 0 + '0';
3375 if (hexd > '9')
3376 hexd -= '9' - 'a' + 1;
3377 partial_output[co++] = hexd;
3380 if (chars_output + co > 243)
3382 fputs ("\"\n\t.STRING \"", file);
3383 chars_output = 0;
3385 fwrite (partial_output, 1, (size_t) co, file);
3386 chars_output += co;
3387 co = 0;
3389 fputs ("\"\n", file);
3392 /* Try to rewrite floating point comparisons & branches to avoid
3393 useless add,tr insns.
3395 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3396 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3397 first attempt to remove useless add,tr insns. It is zero
3398 for the second pass as reorg sometimes leaves bogus REG_DEAD
3399 notes lying around.
3401 When CHECK_NOTES is zero we can only eliminate add,tr insns
3402 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3403 instructions. */
3404 static void
3405 remove_useless_addtr_insns (int check_notes)
3407 rtx insn;
3408 static int pass = 0;
3410 /* This is fairly cheap, so always run it when optimizing. */
3411 if (optimize > 0)
3413 int fcmp_count = 0;
3414 int fbranch_count = 0;
3416 /* Walk all the insns in this function looking for fcmp & fbranch
3417 instructions. Keep track of how many of each we find. */
3418 for (insn = get_insns (); insn; insn = next_insn (insn))
3420 rtx tmp;
3422 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3423 if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3424 continue;
3426 tmp = PATTERN (insn);
3428 /* It must be a set. */
3429 if (GET_CODE (tmp) != SET)
3430 continue;
3432 /* If the destination is CCFP, then we've found an fcmp insn. */
3433 tmp = SET_DEST (tmp);
3434 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3436 fcmp_count++;
3437 continue;
3440 tmp = PATTERN (insn);
3441 /* If this is an fbranch instruction, bump the fbranch counter. */
3442 if (GET_CODE (tmp) == SET
3443 && SET_DEST (tmp) == pc_rtx
3444 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3445 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3446 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3447 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3449 fbranch_count++;
3450 continue;
3455 /* Find all floating point compare + branch insns. If possible,
3456 reverse the comparison & the branch to avoid add,tr insns. */
3457 for (insn = get_insns (); insn; insn = next_insn (insn))
3459 rtx tmp, next;
3461 /* Ignore anything that isn't an INSN. */
3462 if (GET_CODE (insn) != INSN)
3463 continue;
3465 tmp = PATTERN (insn);
3467 /* It must be a set. */
3468 if (GET_CODE (tmp) != SET)
3469 continue;
3471 /* The destination must be CCFP, which is register zero. */
3472 tmp = SET_DEST (tmp);
3473 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3474 continue;
3476 /* INSN should be a set of CCFP.
3478 See if the result of this insn is used in a reversed FP
3479 conditional branch. If so, reverse our condition and
3480 the branch. Doing so avoids useless add,tr insns. */
3481 next = next_insn (insn);
3482 while (next)
3484 /* Jumps, calls and labels stop our search. */
3485 if (GET_CODE (next) == JUMP_INSN
3486 || GET_CODE (next) == CALL_INSN
3487 || GET_CODE (next) == CODE_LABEL)
3488 break;
3490 /* As does another fcmp insn. */
3491 if (GET_CODE (next) == INSN
3492 && GET_CODE (PATTERN (next)) == SET
3493 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3494 && REGNO (SET_DEST (PATTERN (next))) == 0)
3495 break;
3497 next = next_insn (next);
3500 /* Is NEXT_INSN a branch? */
3501 if (next
3502 && GET_CODE (next) == JUMP_INSN)
3504 rtx pattern = PATTERN (next);
3506 /* If it a reversed fp conditional branch (e.g. uses add,tr)
3507 and CCFP dies, then reverse our conditional and the branch
3508 to avoid the add,tr. */
3509 if (GET_CODE (pattern) == SET
3510 && SET_DEST (pattern) == pc_rtx
3511 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3512 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3513 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3514 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3515 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3516 && (fcmp_count == fbranch_count
3517 || (check_notes
3518 && find_regno_note (next, REG_DEAD, 0))))
3520 /* Reverse the branch. */
3521 tmp = XEXP (SET_SRC (pattern), 1);
3522 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3523 XEXP (SET_SRC (pattern), 2) = tmp;
3524 INSN_CODE (next) = -1;
3526 /* Reverse our condition. */
3527 tmp = PATTERN (insn);
3528 PUT_CODE (XEXP (tmp, 1),
3529 (reverse_condition_maybe_unordered
3530 (GET_CODE (XEXP (tmp, 1)))));
3536 pass = !pass;
3540 /* You may have trouble believing this, but this is the 32 bit HP-PA
3541 stack layout. Wow.
3543 Offset Contents
3545 Variable arguments (optional; any number may be allocated)
3547 SP-(4*(N+9)) arg word N
3549 SP-56 arg word 5
3550 SP-52 arg word 4
3552 Fixed arguments (must be allocated; may remain unused)
3554 SP-48 arg word 3
3555 SP-44 arg word 2
3556 SP-40 arg word 1
3557 SP-36 arg word 0
3559 Frame Marker
3561 SP-32 External Data Pointer (DP)
3562 SP-28 External sr4
3563 SP-24 External/stub RP (RP')
3564 SP-20 Current RP
3565 SP-16 Static Link
3566 SP-12 Clean up
3567 SP-8 Calling Stub RP (RP'')
3568 SP-4 Previous SP
3570 Top of Frame
3572 SP-0 Stack Pointer (points to next available address)
3576 /* This function saves registers as follows. Registers marked with ' are
3577 this function's registers (as opposed to the previous function's).
3578 If a frame_pointer isn't needed, r4 is saved as a general register;
3579 the space for the frame pointer is still allocated, though, to keep
3580 things simple.
3583 Top of Frame
3585 SP (FP') Previous FP
3586 SP + 4 Alignment filler (sigh)
3587 SP + 8 Space for locals reserved here.
3591 SP + n All call saved register used.
3595 SP + o All call saved fp registers used.
3599 SP + p (SP') points to next available address.
3603 /* Global variables set by output_function_prologue(). */
3604 /* Size of frame. Need to know this to emit return insns from
3605 leaf procedures. */
3606 static HOST_WIDE_INT actual_fsize, local_fsize;
3607 static int save_fregs;
3609 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3610 Handle case where DISP > 8k by using the add_high_const patterns.
3612 Note in DISP > 8k case, we will leave the high part of the address
3613 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3615 static void
3616 store_reg (int reg, HOST_WIDE_INT disp, int base)
3618 rtx insn, dest, src, basereg;
3620 src = gen_rtx_REG (word_mode, reg);
3621 basereg = gen_rtx_REG (Pmode, base);
3622 if (VAL_14_BITS_P (disp))
3624 dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3625 insn = emit_move_insn (dest, src);
3627 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3629 rtx delta = GEN_INT (disp);
3630 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3632 emit_move_insn (tmpreg, delta);
3633 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3634 dest = gen_rtx_MEM (word_mode, tmpreg);
3635 insn = emit_move_insn (dest, src);
3636 if (DO_FRAME_NOTES)
3638 REG_NOTES (insn)
3639 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3640 gen_rtx_SET (VOIDmode,
3641 gen_rtx_MEM (word_mode,
3642 gen_rtx_PLUS (word_mode, basereg,
3643 delta)),
3644 src),
3645 REG_NOTES (insn));
3648 else
3650 rtx delta = GEN_INT (disp);
3651 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3652 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3654 emit_move_insn (tmpreg, high);
3655 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3656 insn = emit_move_insn (dest, src);
3657 if (DO_FRAME_NOTES)
3659 REG_NOTES (insn)
3660 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3661 gen_rtx_SET (VOIDmode,
3662 gen_rtx_MEM (word_mode,
3663 gen_rtx_PLUS (word_mode, basereg,
3664 delta)),
3665 src),
3666 REG_NOTES (insn));
3670 if (DO_FRAME_NOTES)
3671 RTX_FRAME_RELATED_P (insn) = 1;
3674 /* Emit RTL to store REG at the memory location specified by BASE and then
3675 add MOD to BASE. MOD must be <= 8k. */
3677 static void
3678 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3680 rtx insn, basereg, srcreg, delta;
3682 if (!VAL_14_BITS_P (mod))
3683 abort ();
3685 basereg = gen_rtx_REG (Pmode, base);
3686 srcreg = gen_rtx_REG (word_mode, reg);
3687 delta = GEN_INT (mod);
3689 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3690 if (DO_FRAME_NOTES)
3692 RTX_FRAME_RELATED_P (insn) = 1;
3694 /* RTX_FRAME_RELATED_P must be set on each frame related set
3695 in a parallel with more than one element. Don't set
3696 RTX_FRAME_RELATED_P in the first set if reg is temporary
3697 register 1. The effect of this operation is recorded in
3698 the initial copy. */
3699 if (reg != 1)
3701 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3702 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3704 else
3706 /* The first element of a PARALLEL is always processed if it is
3707 a SET. Thus, we need an expression list for this case. */
3708 REG_NOTES (insn)
3709 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3710 gen_rtx_SET (VOIDmode, basereg,
3711 gen_rtx_PLUS (word_mode, basereg, delta)),
3712 REG_NOTES (insn));
3717 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
3718 where DISP > 8k by using the add_high_const patterns. NOTE indicates
3719 whether to add a frame note or not.
3721 In the DISP > 8k case, we leave the high part of the address in %r1.
3722 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
3724 static void
3725 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3727 rtx insn;
3729 if (VAL_14_BITS_P (disp))
3731 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3732 plus_constant (gen_rtx_REG (Pmode, base), disp));
3734 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3736 rtx basereg = gen_rtx_REG (Pmode, base);
3737 rtx delta = GEN_INT (disp);
3738 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3740 emit_move_insn (tmpreg, delta);
3741 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3742 gen_rtx_PLUS (Pmode, tmpreg, basereg));
3744 else
3746 rtx basereg = gen_rtx_REG (Pmode, base);
3747 rtx delta = GEN_INT (disp);
3748 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3750 emit_move_insn (tmpreg,
3751 gen_rtx_PLUS (Pmode, basereg,
3752 gen_rtx_HIGH (Pmode, delta)));
3753 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3754 gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3757 if (DO_FRAME_NOTES && note)
3758 RTX_FRAME_RELATED_P (insn) = 1;
3761 HOST_WIDE_INT
3762 compute_frame_size (HOST_WIDE_INT size, int *fregs_live)
3764 int freg_saved = 0;
3765 int i, j;
3767 /* The code in hppa_expand_prologue and hppa_expand_epilogue must
3768 be consistent with the rounding and size calculation done here.
3769 Change them at the same time. */
3771 /* We do our own stack alignment. First, round the size of the
3772 stack locals up to a word boundary. */
3773 size = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3775 /* Space for previous frame pointer + filler. If any frame is
3776 allocated, we need to add in the STARTING_FRAME_OFFSET. We
3777 waste some space here for the sake of HP compatibility. The
3778 first slot is only used when the frame pointer is needed. */
3779 if (size || frame_pointer_needed)
3780 size += STARTING_FRAME_OFFSET;
3782 /* If the current function calls __builtin_eh_return, then we need
3783 to allocate stack space for registers that will hold data for
3784 the exception handler. */
3785 if (DO_FRAME_NOTES && current_function_calls_eh_return)
3787 unsigned int i;
3789 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
3790 continue;
3791 size += i * UNITS_PER_WORD;
3794 /* Account for space used by the callee general register saves. */
3795 for (i = 18, j = frame_pointer_needed ? 4 : 3; i >= j; i--)
3796 if (regs_ever_live[i])
3797 size += UNITS_PER_WORD;
3799 /* Account for space used by the callee floating point register saves. */
3800 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3801 if (regs_ever_live[i]
3802 || (!TARGET_64BIT && regs_ever_live[i + 1]))
3804 freg_saved = 1;
3806 /* We always save both halves of the FP register, so always
3807 increment the frame size by 8 bytes. */
3808 size += 8;
3811 /* If any of the floating registers are saved, account for the
3812 alignment needed for the floating point register save block. */
3813 if (freg_saved)
3815 size = (size + 7) & ~7;
3816 if (fregs_live)
3817 *fregs_live = 1;
3820 /* The various ABIs include space for the outgoing parameters in the
3821 size of the current function's stack frame. We don't need to align
3822 for the outgoing arguments as their alignment is set by the final
3823 rounding for the frame as a whole. */
3824 size += current_function_outgoing_args_size;
3826 /* Allocate space for the fixed frame marker. This space must be
3827 allocated for any function that makes calls or allocates
3828 stack space. */
3829 if (!current_function_is_leaf || size)
3830 size += TARGET_64BIT ? 48 : 32;
3832 /* Finally, round to the preferred stack boundary. */
3833 return ((size + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)
3834 & ~(PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1));
3837 /* Generate the assembly code for function entry. FILE is a stdio
3838 stream to output the code to. SIZE is an int: how many units of
3839 temporary storage to allocate.
3841 Refer to the array `regs_ever_live' to determine which registers to
3842 save; `regs_ever_live[I]' is nonzero if register number I is ever
3843 used in the function. This function is responsible for knowing
3844 which registers should not be saved even if used. */
3846 /* On HP-PA, move-double insns between fpu and cpu need an 8-byte block
3847 of memory. If any fpu reg is used in the function, we allocate
3848 such a block here, at the bottom of the frame, just in case it's needed.
3850 If this function is a leaf procedure, then we may choose not
3851 to do a "save" insn. The decision about whether or not
3852 to do this is made in regclass.c. */
3854 static void
3855 pa_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3857 /* The function's label and associated .PROC must never be
3858 separated and must be output *after* any profiling declarations
3859 to avoid changing spaces/subspaces within a procedure. */
3860 ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3861 fputs ("\t.PROC\n", file);
3863 /* hppa_expand_prologue does the dirty work now. We just need
3864 to output the assembler directives which denote the start
3865 of a function. */
3866 fprintf (file, "\t.CALLINFO FRAME=" HOST_WIDE_INT_PRINT_DEC, actual_fsize);
3867 if (regs_ever_live[2])
3868 fputs (",CALLS,SAVE_RP", file);
3869 else
3870 fputs (",NO_CALLS", file);
3872 /* The SAVE_SP flag is used to indicate that register %r3 is stored
3873 at the beginning of the frame and that it is used as the frame
3874 pointer for the frame. We do this because our current frame
3875 layout doesn't conform to that specified in the the HP runtime
3876 documentation and we need a way to indicate to programs such as
3877 GDB where %r3 is saved. The SAVE_SP flag was chosen because it
3878 isn't used by HP compilers but is supported by the assembler.
3879 However, SAVE_SP is supposed to indicate that the previous stack
3880 pointer has been saved in the frame marker. */
3881 if (frame_pointer_needed)
3882 fputs (",SAVE_SP", file);
3884 /* Pass on information about the number of callee register saves
3885 performed in the prologue.
3887 The compiler is supposed to pass the highest register number
3888 saved, the assembler then has to adjust that number before
3889 entering it into the unwind descriptor (to account for any
3890 caller saved registers with lower register numbers than the
3891 first callee saved register). */
3892 if (gr_saved)
3893 fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
3895 if (fr_saved)
3896 fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
3898 fputs ("\n\t.ENTRY\n", file);
3900 remove_useless_addtr_insns (0);
3903 void
3904 hppa_expand_prologue (void)
3906 int merge_sp_adjust_with_store = 0;
3907 HOST_WIDE_INT size = get_frame_size ();
3908 HOST_WIDE_INT offset;
3909 int i;
3910 rtx insn, tmpreg;
3912 gr_saved = 0;
3913 fr_saved = 0;
3914 save_fregs = 0;
3916 /* Compute total size for frame pointer, filler, locals and rounding to
3917 the next word boundary. Similar code appears in compute_frame_size
3918 and must be changed in tandem with this code. */
3919 local_fsize = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3920 if (local_fsize || frame_pointer_needed)
3921 local_fsize += STARTING_FRAME_OFFSET;
3923 actual_fsize = compute_frame_size (size, &save_fregs);
3925 /* Compute a few things we will use often. */
3926 tmpreg = gen_rtx_REG (word_mode, 1);
3928 /* Save RP first. The calling conventions manual states RP will
3929 always be stored into the caller's frame at sp - 20 or sp - 16
3930 depending on which ABI is in use. */
3931 if (regs_ever_live[2] || current_function_calls_eh_return)
3932 store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM);
3934 /* Allocate the local frame and set up the frame pointer if needed. */
3935 if (actual_fsize != 0)
3937 if (frame_pointer_needed)
3939 /* Copy the old frame pointer temporarily into %r1. Set up the
3940 new stack pointer, then store away the saved old frame pointer
3941 into the stack at sp and at the same time update the stack
3942 pointer by actual_fsize bytes. Two versions, first
3943 handles small (<8k) frames. The second handles large (>=8k)
3944 frames. */
3945 insn = emit_move_insn (tmpreg, frame_pointer_rtx);
3946 if (DO_FRAME_NOTES)
3948 /* We need to record the frame pointer save here since the
3949 new frame pointer is set in the following insn. */
3950 RTX_FRAME_RELATED_P (insn) = 1;
3951 REG_NOTES (insn)
3952 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3953 gen_rtx_SET (VOIDmode,
3954 gen_rtx_MEM (word_mode, stack_pointer_rtx),
3955 frame_pointer_rtx),
3956 REG_NOTES (insn));
3959 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
3960 if (DO_FRAME_NOTES)
3961 RTX_FRAME_RELATED_P (insn) = 1;
3963 if (VAL_14_BITS_P (actual_fsize))
3964 store_reg_modify (STACK_POINTER_REGNUM, 1, actual_fsize);
3965 else
3967 /* It is incorrect to store the saved frame pointer at *sp,
3968 then increment sp (writes beyond the current stack boundary).
3970 So instead use stwm to store at *sp and post-increment the
3971 stack pointer as an atomic operation. Then increment sp to
3972 finish allocating the new frame. */
3973 HOST_WIDE_INT adjust1 = 8192 - 64;
3974 HOST_WIDE_INT adjust2 = actual_fsize - adjust1;
3976 store_reg_modify (STACK_POINTER_REGNUM, 1, adjust1);
3977 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3978 adjust2, 1);
3981 /* We set SAVE_SP in frames that need a frame pointer. Thus,
3982 we need to store the previous stack pointer (frame pointer)
3983 into the frame marker on targets that use the HP unwind
3984 library. This allows the HP unwind library to be used to
3985 unwind GCC frames. However, we are not fully compatible
3986 with the HP library because our frame layout differs from
3987 that specified in the HP runtime specification.
3989 We don't want a frame note on this instruction as the frame
3990 marker moves during dynamic stack allocation.
3992 This instruction also serves as a blockage to prevent
3993 register spills from being scheduled before the stack
3994 pointer is raised. This is necessary as we store
3995 registers using the frame pointer as a base register,
3996 and the frame pointer is set before sp is raised. */
3997 if (TARGET_HPUX_UNWIND_LIBRARY)
3999 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx,
4000 GEN_INT (TARGET_64BIT ? -8 : -4));
4002 emit_move_insn (gen_rtx_MEM (word_mode, addr),
4003 frame_pointer_rtx);
4005 else
4006 emit_insn (gen_blockage ());
4008 /* no frame pointer needed. */
4009 else
4011 /* In some cases we can perform the first callee register save
4012 and allocating the stack frame at the same time. If so, just
4013 make a note of it and defer allocating the frame until saving
4014 the callee registers. */
4015 if (VAL_14_BITS_P (actual_fsize) && local_fsize == 0)
4016 merge_sp_adjust_with_store = 1;
4017 /* Can not optimize. Adjust the stack frame by actual_fsize
4018 bytes. */
4019 else
4020 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4021 actual_fsize, 1);
4025 /* Normal register save.
4027 Do not save the frame pointer in the frame_pointer_needed case. It
4028 was done earlier. */
4029 if (frame_pointer_needed)
4031 offset = local_fsize;
4033 /* Saving the EH return data registers in the frame is the simplest
4034 way to get the frame unwind information emitted. We put them
4035 just before the general registers. */
4036 if (DO_FRAME_NOTES && current_function_calls_eh_return)
4038 unsigned int i, regno;
4040 for (i = 0; ; ++i)
4042 regno = EH_RETURN_DATA_REGNO (i);
4043 if (regno == INVALID_REGNUM)
4044 break;
4046 store_reg (regno, offset, FRAME_POINTER_REGNUM);
4047 offset += UNITS_PER_WORD;
4051 for (i = 18; i >= 4; i--)
4052 if (regs_ever_live[i] && ! call_used_regs[i])
4054 store_reg (i, offset, FRAME_POINTER_REGNUM);
4055 offset += UNITS_PER_WORD;
4056 gr_saved++;
4058 /* Account for %r3 which is saved in a special place. */
4059 gr_saved++;
4061 /* No frame pointer needed. */
4062 else
4064 offset = local_fsize - actual_fsize;
4066 /* Saving the EH return data registers in the frame is the simplest
4067 way to get the frame unwind information emitted. */
4068 if (DO_FRAME_NOTES && current_function_calls_eh_return)
4070 unsigned int i, regno;
4072 for (i = 0; ; ++i)
4074 regno = EH_RETURN_DATA_REGNO (i);
4075 if (regno == INVALID_REGNUM)
4076 break;
4078 /* If merge_sp_adjust_with_store is nonzero, then we can
4079 optimize the first save. */
4080 if (merge_sp_adjust_with_store)
4082 store_reg_modify (STACK_POINTER_REGNUM, regno, -offset);
4083 merge_sp_adjust_with_store = 0;
4085 else
4086 store_reg (regno, offset, STACK_POINTER_REGNUM);
4087 offset += UNITS_PER_WORD;
4091 for (i = 18; i >= 3; i--)
4092 if (regs_ever_live[i] && ! call_used_regs[i])
4094 /* If merge_sp_adjust_with_store is nonzero, then we can
4095 optimize the first GR save. */
4096 if (merge_sp_adjust_with_store)
4098 store_reg_modify (STACK_POINTER_REGNUM, i, -offset);
4099 merge_sp_adjust_with_store = 0;
4101 else
4102 store_reg (i, offset, STACK_POINTER_REGNUM);
4103 offset += UNITS_PER_WORD;
4104 gr_saved++;
4107 /* If we wanted to merge the SP adjustment with a GR save, but we never
4108 did any GR saves, then just emit the adjustment here. */
4109 if (merge_sp_adjust_with_store)
4110 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4111 actual_fsize, 1);
4114 /* The hppa calling conventions say that %r19, the pic offset
4115 register, is saved at sp - 32 (in this function's frame)
4116 when generating PIC code. FIXME: What is the correct thing
4117 to do for functions which make no calls and allocate no
4118 frame? Do we need to allocate a frame, or can we just omit
4119 the save? For now we'll just omit the save.
4121 We don't want a note on this insn as the frame marker can
4122 move if there is a dynamic stack allocation. */
4123 if (flag_pic && actual_fsize != 0 && !TARGET_64BIT)
4125 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx, GEN_INT (-32));
4127 emit_move_insn (gen_rtx_MEM (word_mode, addr), pic_offset_table_rtx);
4131 /* Align pointer properly (doubleword boundary). */
4132 offset = (offset + 7) & ~7;
4134 /* Floating point register store. */
4135 if (save_fregs)
4137 rtx base;
4139 /* First get the frame or stack pointer to the start of the FP register
4140 save area. */
4141 if (frame_pointer_needed)
4143 set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset, 0);
4144 base = frame_pointer_rtx;
4146 else
4148 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4149 base = stack_pointer_rtx;
4152 /* Now actually save the FP registers. */
4153 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4155 if (regs_ever_live[i]
4156 || (! TARGET_64BIT && regs_ever_live[i + 1]))
4158 rtx addr, insn, reg;
4159 addr = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
4160 reg = gen_rtx_REG (DFmode, i);
4161 insn = emit_move_insn (addr, reg);
4162 if (DO_FRAME_NOTES)
4164 RTX_FRAME_RELATED_P (insn) = 1;
4165 if (TARGET_64BIT)
4167 rtx mem = gen_rtx_MEM (DFmode,
4168 plus_constant (base, offset));
4169 REG_NOTES (insn)
4170 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
4171 gen_rtx_SET (VOIDmode, mem, reg),
4172 REG_NOTES (insn));
4174 else
4176 rtx meml = gen_rtx_MEM (SFmode,
4177 plus_constant (base, offset));
4178 rtx memr = gen_rtx_MEM (SFmode,
4179 plus_constant (base, offset + 4));
4180 rtx regl = gen_rtx_REG (SFmode, i);
4181 rtx regr = gen_rtx_REG (SFmode, i + 1);
4182 rtx setl = gen_rtx_SET (VOIDmode, meml, regl);
4183 rtx setr = gen_rtx_SET (VOIDmode, memr, regr);
4184 rtvec vec;
4186 RTX_FRAME_RELATED_P (setl) = 1;
4187 RTX_FRAME_RELATED_P (setr) = 1;
4188 vec = gen_rtvec (2, setl, setr);
4189 REG_NOTES (insn)
4190 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
4191 gen_rtx_SEQUENCE (VOIDmode, vec),
4192 REG_NOTES (insn));
4195 offset += GET_MODE_SIZE (DFmode);
4196 fr_saved++;
4202 /* Emit RTL to load REG from the memory location specified by BASE+DISP.
4203 Handle case where DISP > 8k by using the add_high_const patterns. */
4205 static void
4206 load_reg (int reg, HOST_WIDE_INT disp, int base)
4208 rtx dest = gen_rtx_REG (word_mode, reg);
4209 rtx basereg = gen_rtx_REG (Pmode, base);
4210 rtx src;
4212 if (VAL_14_BITS_P (disp))
4213 src = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
4214 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
4216 rtx delta = GEN_INT (disp);
4217 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4219 emit_move_insn (tmpreg, delta);
4220 if (TARGET_DISABLE_INDEXING)
4222 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4223 src = gen_rtx_MEM (word_mode, tmpreg);
4225 else
4226 src = gen_rtx_MEM (word_mode, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4228 else
4230 rtx delta = GEN_INT (disp);
4231 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
4232 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4234 emit_move_insn (tmpreg, high);
4235 src = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
4238 emit_move_insn (dest, src);
4241 /* Update the total code bytes output to the text section. */
4243 static void
4244 update_total_code_bytes (int nbytes)
4246 if ((TARGET_PORTABLE_RUNTIME || !TARGET_GAS || !TARGET_SOM)
4247 && !IN_NAMED_SECTION_P (cfun->decl))
4249 if (INSN_ADDRESSES_SET_P ())
4251 unsigned long old_total = total_code_bytes;
4253 total_code_bytes += nbytes;
4255 /* Be prepared to handle overflows. */
4256 if (old_total > total_code_bytes)
4257 total_code_bytes = -1;
4259 else
4260 total_code_bytes = -1;
4264 /* This function generates the assembly code for function exit.
4265 Args are as for output_function_prologue ().
4267 The function epilogue should not depend on the current stack
4268 pointer! It should use the frame pointer only. This is mandatory
4269 because of alloca; we also take advantage of it to omit stack
4270 adjustments before returning. */
4272 static void
4273 pa_output_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4275 rtx insn = get_last_insn ();
4277 last_address = 0;
4279 /* hppa_expand_epilogue does the dirty work now. We just need
4280 to output the assembler directives which denote the end
4281 of a function.
4283 To make debuggers happy, emit a nop if the epilogue was completely
4284 eliminated due to a volatile call as the last insn in the
4285 current function. That way the return address (in %r2) will
4286 always point to a valid instruction in the current function. */
4288 /* Get the last real insn. */
4289 if (GET_CODE (insn) == NOTE)
4290 insn = prev_real_insn (insn);
4292 /* If it is a sequence, then look inside. */
4293 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
4294 insn = XVECEXP (PATTERN (insn), 0, 0);
4296 /* If insn is a CALL_INSN, then it must be a call to a volatile
4297 function (otherwise there would be epilogue insns). */
4298 if (insn && GET_CODE (insn) == CALL_INSN)
4300 fputs ("\tnop\n", file);
4301 last_address += 4;
4304 fputs ("\t.EXIT\n\t.PROCEND\n", file);
4306 if (TARGET_SOM && TARGET_GAS)
4308 /* We done with this subspace except possibly for some additional
4309 debug information. Forget that we are in this subspace to ensure
4310 that the next function is output in its own subspace. */
4311 forget_section ();
4314 if (INSN_ADDRESSES_SET_P ())
4316 insn = get_last_nonnote_insn ();
4317 last_address += INSN_ADDRESSES (INSN_UID (insn));
4318 if (INSN_P (insn))
4319 last_address += insn_default_length (insn);
4320 last_address = ((last_address + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
4321 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
4324 /* Finally, update the total number of code bytes output so far. */
4325 update_total_code_bytes (last_address);
4328 void
4329 hppa_expand_epilogue (void)
4331 rtx tmpreg;
4332 HOST_WIDE_INT offset;
4333 HOST_WIDE_INT ret_off = 0;
4334 int i;
4335 int merge_sp_adjust_with_load = 0;
4337 /* We will use this often. */
4338 tmpreg = gen_rtx_REG (word_mode, 1);
4340 /* Try to restore RP early to avoid load/use interlocks when
4341 RP gets used in the return (bv) instruction. This appears to still
4342 be necessary even when we schedule the prologue and epilogue. */
4343 if (regs_ever_live [2] || current_function_calls_eh_return)
4345 ret_off = TARGET_64BIT ? -16 : -20;
4346 if (frame_pointer_needed)
4348 load_reg (2, ret_off, FRAME_POINTER_REGNUM);
4349 ret_off = 0;
4351 else
4353 /* No frame pointer, and stack is smaller than 8k. */
4354 if (VAL_14_BITS_P (ret_off - actual_fsize))
4356 load_reg (2, ret_off - actual_fsize, STACK_POINTER_REGNUM);
4357 ret_off = 0;
4362 /* General register restores. */
4363 if (frame_pointer_needed)
4365 offset = local_fsize;
4367 /* If the current function calls __builtin_eh_return, then we need
4368 to restore the saved EH data registers. */
4369 if (DO_FRAME_NOTES && current_function_calls_eh_return)
4371 unsigned int i, regno;
4373 for (i = 0; ; ++i)
4375 regno = EH_RETURN_DATA_REGNO (i);
4376 if (regno == INVALID_REGNUM)
4377 break;
4379 load_reg (regno, offset, FRAME_POINTER_REGNUM);
4380 offset += UNITS_PER_WORD;
4384 for (i = 18; i >= 4; i--)
4385 if (regs_ever_live[i] && ! call_used_regs[i])
4387 load_reg (i, offset, FRAME_POINTER_REGNUM);
4388 offset += UNITS_PER_WORD;
4391 else
4393 offset = local_fsize - actual_fsize;
4395 /* If the current function calls __builtin_eh_return, then we need
4396 to restore the saved EH data registers. */
4397 if (DO_FRAME_NOTES && current_function_calls_eh_return)
4399 unsigned int i, regno;
4401 for (i = 0; ; ++i)
4403 regno = EH_RETURN_DATA_REGNO (i);
4404 if (regno == INVALID_REGNUM)
4405 break;
4407 /* Only for the first load.
4408 merge_sp_adjust_with_load holds the register load
4409 with which we will merge the sp adjustment. */
4410 if (merge_sp_adjust_with_load == 0
4411 && local_fsize == 0
4412 && VAL_14_BITS_P (-actual_fsize))
4413 merge_sp_adjust_with_load = regno;
4414 else
4415 load_reg (regno, offset, STACK_POINTER_REGNUM);
4416 offset += UNITS_PER_WORD;
4420 for (i = 18; i >= 3; i--)
4422 if (regs_ever_live[i] && ! call_used_regs[i])
4424 /* Only for the first load.
4425 merge_sp_adjust_with_load holds the register load
4426 with which we will merge the sp adjustment. */
4427 if (merge_sp_adjust_with_load == 0
4428 && local_fsize == 0
4429 && VAL_14_BITS_P (-actual_fsize))
4430 merge_sp_adjust_with_load = i;
4431 else
4432 load_reg (i, offset, STACK_POINTER_REGNUM);
4433 offset += UNITS_PER_WORD;
4438 /* Align pointer properly (doubleword boundary). */
4439 offset = (offset + 7) & ~7;
4441 /* FP register restores. */
4442 if (save_fregs)
4444 /* Adjust the register to index off of. */
4445 if (frame_pointer_needed)
4446 set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset, 0);
4447 else
4448 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4450 /* Actually do the restores now. */
4451 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4452 if (regs_ever_live[i]
4453 || (! TARGET_64BIT && regs_ever_live[i + 1]))
4455 rtx src = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
4456 rtx dest = gen_rtx_REG (DFmode, i);
4457 emit_move_insn (dest, src);
4461 /* Emit a blockage insn here to keep these insns from being moved to
4462 an earlier spot in the epilogue, or into the main instruction stream.
4464 This is necessary as we must not cut the stack back before all the
4465 restores are finished. */
4466 emit_insn (gen_blockage ());
4468 /* Reset stack pointer (and possibly frame pointer). The stack
4469 pointer is initially set to fp + 64 to avoid a race condition. */
4470 if (frame_pointer_needed)
4472 rtx delta = GEN_INT (-64);
4474 set_reg_plus_d (STACK_POINTER_REGNUM, FRAME_POINTER_REGNUM, 64, 0);
4475 emit_insn (gen_pre_load (frame_pointer_rtx, stack_pointer_rtx, delta));
4477 /* If we were deferring a callee register restore, do it now. */
4478 else if (merge_sp_adjust_with_load)
4480 rtx delta = GEN_INT (-actual_fsize);
4481 rtx dest = gen_rtx_REG (word_mode, merge_sp_adjust_with_load);
4483 emit_insn (gen_pre_load (dest, stack_pointer_rtx, delta));
4485 else if (actual_fsize != 0)
4486 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4487 - actual_fsize, 0);
4489 /* If we haven't restored %r2 yet (no frame pointer, and a stack
4490 frame greater than 8k), do so now. */
4491 if (ret_off != 0)
4492 load_reg (2, ret_off, STACK_POINTER_REGNUM);
4494 if (DO_FRAME_NOTES && current_function_calls_eh_return)
4496 rtx sa = EH_RETURN_STACKADJ_RTX;
4498 emit_insn (gen_blockage ());
4499 emit_insn (TARGET_64BIT
4500 ? gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, sa)
4501 : gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, sa));
4506 hppa_pic_save_rtx (void)
4508 return get_hard_reg_initial_val (word_mode, PIC_OFFSET_TABLE_REGNUM);
4511 void
4512 hppa_profile_hook (int label_no)
4514 /* We use SImode for the address of the function in both 32 and
4515 64-bit code to avoid having to provide DImode versions of the
4516 lcla2 and load_offset_label_address insn patterns. */
4517 rtx reg = gen_reg_rtx (SImode);
4518 rtx label_rtx = gen_label_rtx ();
4519 rtx begin_label_rtx, call_insn;
4520 char begin_label_name[16];
4522 ASM_GENERATE_INTERNAL_LABEL (begin_label_name, FUNC_BEGIN_PROLOG_LABEL,
4523 label_no);
4524 begin_label_rtx = gen_rtx_SYMBOL_REF (SImode, ggc_strdup (begin_label_name));
4526 if (TARGET_64BIT)
4527 emit_move_insn (arg_pointer_rtx,
4528 gen_rtx_PLUS (word_mode, virtual_outgoing_args_rtx,
4529 GEN_INT (64)));
4531 emit_move_insn (gen_rtx_REG (word_mode, 26), gen_rtx_REG (word_mode, 2));
4533 /* The address of the function is loaded into %r25 with a instruction-
4534 relative sequence that avoids the use of relocations. The sequence
4535 is split so that the load_offset_label_address instruction can
4536 occupy the delay slot of the call to _mcount. */
4537 if (TARGET_PA_20)
4538 emit_insn (gen_lcla2 (reg, label_rtx));
4539 else
4540 emit_insn (gen_lcla1 (reg, label_rtx));
4542 emit_insn (gen_load_offset_label_address (gen_rtx_REG (SImode, 25),
4543 reg, begin_label_rtx, label_rtx));
4545 #ifndef NO_PROFILE_COUNTERS
4547 rtx count_label_rtx, addr, r24;
4548 char count_label_name[16];
4550 ASM_GENERATE_INTERNAL_LABEL (count_label_name, "LP", label_no);
4551 count_label_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (count_label_name));
4553 addr = force_reg (Pmode, count_label_rtx);
4554 r24 = gen_rtx_REG (Pmode, 24);
4555 emit_move_insn (r24, addr);
4557 call_insn =
4558 emit_call_insn (gen_call (gen_rtx_MEM (Pmode,
4559 gen_rtx_SYMBOL_REF (Pmode,
4560 "_mcount")),
4561 GEN_INT (TARGET_64BIT ? 24 : 12)));
4563 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), r24);
4565 #else
4567 call_insn =
4568 emit_call_insn (gen_call (gen_rtx_MEM (Pmode,
4569 gen_rtx_SYMBOL_REF (Pmode,
4570 "_mcount")),
4571 GEN_INT (TARGET_64BIT ? 16 : 8)));
4573 #endif
4575 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 25));
4576 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 26));
4578 /* Indicate the _mcount call cannot throw, nor will it execute a
4579 non-local goto. */
4580 REG_NOTES (call_insn)
4581 = gen_rtx_EXPR_LIST (REG_EH_REGION, constm1_rtx, REG_NOTES (call_insn));
4584 /* Fetch the return address for the frame COUNT steps up from
4585 the current frame, after the prologue. FRAMEADDR is the
4586 frame pointer of the COUNT frame.
4588 We want to ignore any export stub remnants here. To handle this,
4589 we examine the code at the return address, and if it is an export
4590 stub, we return a memory rtx for the stub return address stored
4591 at frame-24.
4593 The value returned is used in two different ways:
4595 1. To find a function's caller.
4597 2. To change the return address for a function.
4599 This function handles most instances of case 1; however, it will
4600 fail if there are two levels of stubs to execute on the return
4601 path. The only way I believe that can happen is if the return value
4602 needs a parameter relocation, which never happens for C code.
4604 This function handles most instances of case 2; however, it will
4605 fail if we did not originally have stub code on the return path
4606 but will need stub code on the new return path. This can happen if
4607 the caller & callee are both in the main program, but the new
4608 return location is in a shared library. */
4611 return_addr_rtx (int count, rtx frameaddr)
4613 rtx label;
4614 rtx rp;
4615 rtx saved_rp;
4616 rtx ins;
4618 if (count != 0)
4619 return NULL_RTX;
4621 rp = get_hard_reg_initial_val (Pmode, 2);
4623 if (TARGET_64BIT || TARGET_NO_SPACE_REGS)
4624 return rp;
4626 saved_rp = gen_reg_rtx (Pmode);
4627 emit_move_insn (saved_rp, rp);
4629 /* Get pointer to the instruction stream. We have to mask out the
4630 privilege level from the two low order bits of the return address
4631 pointer here so that ins will point to the start of the first
4632 instruction that would have been executed if we returned. */
4633 ins = copy_to_reg (gen_rtx_AND (Pmode, rp, MASK_RETURN_ADDR));
4634 label = gen_label_rtx ();
4636 /* Check the instruction stream at the normal return address for the
4637 export stub:
4639 0x4bc23fd1 | stub+8: ldw -18(sr0,sp),rp
4640 0x004010a1 | stub+12: ldsid (sr0,rp),r1
4641 0x00011820 | stub+16: mtsp r1,sr0
4642 0xe0400002 | stub+20: be,n 0(sr0,rp)
4644 If it is an export stub, than our return address is really in
4645 -24[frameaddr]. */
4647 emit_cmp_insn (gen_rtx_MEM (SImode, ins), GEN_INT (0x4bc23fd1), NE,
4648 NULL_RTX, SImode, 1);
4649 emit_jump_insn (gen_bne (label));
4651 emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 4)),
4652 GEN_INT (0x004010a1), NE, NULL_RTX, SImode, 1);
4653 emit_jump_insn (gen_bne (label));
4655 emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 8)),
4656 GEN_INT (0x00011820), NE, NULL_RTX, SImode, 1);
4657 emit_jump_insn (gen_bne (label));
4659 emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 12)),
4660 GEN_INT (0xe0400002), NE, NULL_RTX, SImode, 1);
4662 /* If there is no export stub then just use the value saved from
4663 the return pointer register. */
4665 emit_jump_insn (gen_bne (label));
4667 /* Here we know that our return address points to an export
4668 stub. We don't want to return the address of the export stub,
4669 but rather the return address of the export stub. That return
4670 address is stored at -24[frameaddr]. */
4672 emit_move_insn (saved_rp,
4673 gen_rtx_MEM (Pmode,
4674 memory_address (Pmode,
4675 plus_constant (frameaddr,
4676 -24))));
4678 emit_label (label);
4679 return saved_rp;
4682 /* This is only valid once reload has completed because it depends on
4683 knowing exactly how much (if any) frame there is and...
4685 It's only valid if there is no frame marker to de-allocate and...
4687 It's only valid if %r2 hasn't been saved into the caller's frame
4688 (we're not profiling and %r2 isn't live anywhere). */
4690 hppa_can_use_return_insn_p (void)
4692 return (reload_completed
4693 && (compute_frame_size (get_frame_size (), 0) ? 0 : 1)
4694 && ! regs_ever_live[2]
4695 && ! frame_pointer_needed);
4698 void
4699 emit_bcond_fp (enum rtx_code code, rtx operand0)
4701 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4702 gen_rtx_IF_THEN_ELSE (VOIDmode,
4703 gen_rtx_fmt_ee (code,
4704 VOIDmode,
4705 gen_rtx_REG (CCFPmode, 0),
4706 const0_rtx),
4707 gen_rtx_LABEL_REF (VOIDmode, operand0),
4708 pc_rtx)));
4713 gen_cmp_fp (enum rtx_code code, rtx operand0, rtx operand1)
4715 return gen_rtx_SET (VOIDmode, gen_rtx_REG (CCFPmode, 0),
4716 gen_rtx_fmt_ee (code, CCFPmode, operand0, operand1));
4719 /* Adjust the cost of a scheduling dependency. Return the new cost of
4720 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
4722 static int
4723 pa_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
4725 enum attr_type attr_type;
4727 /* Don't adjust costs for a pa8000 chip, also do not adjust any
4728 true dependencies as they are described with bypasses now. */
4729 if (pa_cpu >= PROCESSOR_8000 || REG_NOTE_KIND (link) == 0)
4730 return cost;
4732 if (! recog_memoized (insn))
4733 return 0;
4735 attr_type = get_attr_type (insn);
4737 if (REG_NOTE_KIND (link) == REG_DEP_ANTI)
4739 /* Anti dependency; DEP_INSN reads a register that INSN writes some
4740 cycles later. */
4742 if (attr_type == TYPE_FPLOAD)
4744 rtx pat = PATTERN (insn);
4745 rtx dep_pat = PATTERN (dep_insn);
4746 if (GET_CODE (pat) == PARALLEL)
4748 /* This happens for the fldXs,mb patterns. */
4749 pat = XVECEXP (pat, 0, 0);
4751 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4752 /* If this happens, we have to extend this to schedule
4753 optimally. Return 0 for now. */
4754 return 0;
4756 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4758 if (! recog_memoized (dep_insn))
4759 return 0;
4760 switch (get_attr_type (dep_insn))
4762 case TYPE_FPALU:
4763 case TYPE_FPMULSGL:
4764 case TYPE_FPMULDBL:
4765 case TYPE_FPDIVSGL:
4766 case TYPE_FPDIVDBL:
4767 case TYPE_FPSQRTSGL:
4768 case TYPE_FPSQRTDBL:
4769 /* A fpload can't be issued until one cycle before a
4770 preceding arithmetic operation has finished if
4771 the target of the fpload is any of the sources
4772 (or destination) of the arithmetic operation. */
4773 return insn_default_latency (dep_insn) - 1;
4775 default:
4776 return 0;
4780 else if (attr_type == TYPE_FPALU)
4782 rtx pat = PATTERN (insn);
4783 rtx dep_pat = PATTERN (dep_insn);
4784 if (GET_CODE (pat) == PARALLEL)
4786 /* This happens for the fldXs,mb patterns. */
4787 pat = XVECEXP (pat, 0, 0);
4789 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4790 /* If this happens, we have to extend this to schedule
4791 optimally. Return 0 for now. */
4792 return 0;
4794 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4796 if (! recog_memoized (dep_insn))
4797 return 0;
4798 switch (get_attr_type (dep_insn))
4800 case TYPE_FPDIVSGL:
4801 case TYPE_FPDIVDBL:
4802 case TYPE_FPSQRTSGL:
4803 case TYPE_FPSQRTDBL:
4804 /* An ALU flop can't be issued until two cycles before a
4805 preceding divide or sqrt operation has finished if
4806 the target of the ALU flop is any of the sources
4807 (or destination) of the divide or sqrt operation. */
4808 return insn_default_latency (dep_insn) - 2;
4810 default:
4811 return 0;
4816 /* For other anti dependencies, the cost is 0. */
4817 return 0;
4819 else if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT)
4821 /* Output dependency; DEP_INSN writes a register that INSN writes some
4822 cycles later. */
4823 if (attr_type == TYPE_FPLOAD)
4825 rtx pat = PATTERN (insn);
4826 rtx dep_pat = PATTERN (dep_insn);
4827 if (GET_CODE (pat) == PARALLEL)
4829 /* This happens for the fldXs,mb patterns. */
4830 pat = XVECEXP (pat, 0, 0);
4832 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4833 /* If this happens, we have to extend this to schedule
4834 optimally. Return 0 for now. */
4835 return 0;
4837 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4839 if (! recog_memoized (dep_insn))
4840 return 0;
4841 switch (get_attr_type (dep_insn))
4843 case TYPE_FPALU:
4844 case TYPE_FPMULSGL:
4845 case TYPE_FPMULDBL:
4846 case TYPE_FPDIVSGL:
4847 case TYPE_FPDIVDBL:
4848 case TYPE_FPSQRTSGL:
4849 case TYPE_FPSQRTDBL:
4850 /* A fpload can't be issued until one cycle before a
4851 preceding arithmetic operation has finished if
4852 the target of the fpload is the destination of the
4853 arithmetic operation.
4855 Exception: For PA7100LC, PA7200 and PA7300, the cost
4856 is 3 cycles, unless they bundle together. We also
4857 pay the penalty if the second insn is a fpload. */
4858 return insn_default_latency (dep_insn) - 1;
4860 default:
4861 return 0;
4865 else if (attr_type == TYPE_FPALU)
4867 rtx pat = PATTERN (insn);
4868 rtx dep_pat = PATTERN (dep_insn);
4869 if (GET_CODE (pat) == PARALLEL)
4871 /* This happens for the fldXs,mb patterns. */
4872 pat = XVECEXP (pat, 0, 0);
4874 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4875 /* If this happens, we have to extend this to schedule
4876 optimally. Return 0 for now. */
4877 return 0;
4879 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4881 if (! recog_memoized (dep_insn))
4882 return 0;
4883 switch (get_attr_type (dep_insn))
4885 case TYPE_FPDIVSGL:
4886 case TYPE_FPDIVDBL:
4887 case TYPE_FPSQRTSGL:
4888 case TYPE_FPSQRTDBL:
4889 /* An ALU flop can't be issued until two cycles before a
4890 preceding divide or sqrt operation has finished if
4891 the target of the ALU flop is also the target of
4892 the divide or sqrt operation. */
4893 return insn_default_latency (dep_insn) - 2;
4895 default:
4896 return 0;
4901 /* For other output dependencies, the cost is 0. */
4902 return 0;
4904 else
4905 abort ();
4908 /* Adjust scheduling priorities. We use this to try and keep addil
4909 and the next use of %r1 close together. */
4910 static int
4911 pa_adjust_priority (rtx insn, int priority)
4913 rtx set = single_set (insn);
4914 rtx src, dest;
4915 if (set)
4917 src = SET_SRC (set);
4918 dest = SET_DEST (set);
4919 if (GET_CODE (src) == LO_SUM
4920 && symbolic_operand (XEXP (src, 1), VOIDmode)
4921 && ! read_only_operand (XEXP (src, 1), VOIDmode))
4922 priority >>= 3;
4924 else if (GET_CODE (src) == MEM
4925 && GET_CODE (XEXP (src, 0)) == LO_SUM
4926 && symbolic_operand (XEXP (XEXP (src, 0), 1), VOIDmode)
4927 && ! read_only_operand (XEXP (XEXP (src, 0), 1), VOIDmode))
4928 priority >>= 1;
4930 else if (GET_CODE (dest) == MEM
4931 && GET_CODE (XEXP (dest, 0)) == LO_SUM
4932 && symbolic_operand (XEXP (XEXP (dest, 0), 1), VOIDmode)
4933 && ! read_only_operand (XEXP (XEXP (dest, 0), 1), VOIDmode))
4934 priority >>= 3;
4936 return priority;
4939 /* The 700 can only issue a single insn at a time.
4940 The 7XXX processors can issue two insns at a time.
4941 The 8000 can issue 4 insns at a time. */
4942 static int
4943 pa_issue_rate (void)
4945 switch (pa_cpu)
4947 case PROCESSOR_700: return 1;
4948 case PROCESSOR_7100: return 2;
4949 case PROCESSOR_7100LC: return 2;
4950 case PROCESSOR_7200: return 2;
4951 case PROCESSOR_7300: return 2;
4952 case PROCESSOR_8000: return 4;
4954 default:
4955 abort ();
4961 /* Return any length adjustment needed by INSN which already has its length
4962 computed as LENGTH. Return zero if no adjustment is necessary.
4964 For the PA: function calls, millicode calls, and backwards short
4965 conditional branches with unfilled delay slots need an adjustment by +1
4966 (to account for the NOP which will be inserted into the instruction stream).
4968 Also compute the length of an inline block move here as it is too
4969 complicated to express as a length attribute in pa.md. */
4971 pa_adjust_insn_length (rtx insn, int length)
4973 rtx pat = PATTERN (insn);
4975 /* Jumps inside switch tables which have unfilled delay slots need
4976 adjustment. */
4977 if (GET_CODE (insn) == JUMP_INSN
4978 && GET_CODE (pat) == PARALLEL
4979 && get_attr_type (insn) == TYPE_BTABLE_BRANCH)
4980 return 4;
4981 /* Millicode insn with an unfilled delay slot. */
4982 else if (GET_CODE (insn) == INSN
4983 && GET_CODE (pat) != SEQUENCE
4984 && GET_CODE (pat) != USE
4985 && GET_CODE (pat) != CLOBBER
4986 && get_attr_type (insn) == TYPE_MILLI)
4987 return 4;
4988 /* Block move pattern. */
4989 else if (GET_CODE (insn) == INSN
4990 && GET_CODE (pat) == PARALLEL
4991 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
4992 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
4993 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 1)) == MEM
4994 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode
4995 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 1)) == BLKmode)
4996 return compute_movmem_length (insn) - 4;
4997 /* Block clear pattern. */
4998 else if (GET_CODE (insn) == INSN
4999 && GET_CODE (pat) == PARALLEL
5000 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
5001 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
5002 && XEXP (XVECEXP (pat, 0, 0), 1) == const0_rtx
5003 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode)
5004 return compute_clrmem_length (insn) - 4;
5005 /* Conditional branch with an unfilled delay slot. */
5006 else if (GET_CODE (insn) == JUMP_INSN && ! simplejump_p (insn))
5008 /* Adjust a short backwards conditional with an unfilled delay slot. */
5009 if (GET_CODE (pat) == SET
5010 && length == 4
5011 && ! forward_branch_p (insn))
5012 return 4;
5013 else if (GET_CODE (pat) == PARALLEL
5014 && get_attr_type (insn) == TYPE_PARALLEL_BRANCH
5015 && length == 4)
5016 return 4;
5017 /* Adjust dbra insn with short backwards conditional branch with
5018 unfilled delay slot -- only for case where counter is in a
5019 general register register. */
5020 else if (GET_CODE (pat) == PARALLEL
5021 && GET_CODE (XVECEXP (pat, 0, 1)) == SET
5022 && GET_CODE (XEXP (XVECEXP (pat, 0, 1), 0)) == REG
5023 && ! FP_REG_P (XEXP (XVECEXP (pat, 0, 1), 0))
5024 && length == 4
5025 && ! forward_branch_p (insn))
5026 return 4;
5027 else
5028 return 0;
5030 return 0;
5033 /* Print operand X (an rtx) in assembler syntax to file FILE.
5034 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
5035 For `%' followed by punctuation, CODE is the punctuation and X is null. */
5037 void
5038 print_operand (FILE *file, rtx x, int code)
5040 switch (code)
5042 case '#':
5043 /* Output a 'nop' if there's nothing for the delay slot. */
5044 if (dbr_sequence_length () == 0)
5045 fputs ("\n\tnop", file);
5046 return;
5047 case '*':
5048 /* Output a nullification completer if there's nothing for the */
5049 /* delay slot or nullification is requested. */
5050 if (dbr_sequence_length () == 0 ||
5051 (final_sequence &&
5052 INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))))
5053 fputs (",n", file);
5054 return;
5055 case 'R':
5056 /* Print out the second register name of a register pair.
5057 I.e., R (6) => 7. */
5058 fputs (reg_names[REGNO (x) + 1], file);
5059 return;
5060 case 'r':
5061 /* A register or zero. */
5062 if (x == const0_rtx
5063 || (x == CONST0_RTX (DFmode))
5064 || (x == CONST0_RTX (SFmode)))
5066 fputs ("%r0", file);
5067 return;
5069 else
5070 break;
5071 case 'f':
5072 /* A register or zero (floating point). */
5073 if (x == const0_rtx
5074 || (x == CONST0_RTX (DFmode))
5075 || (x == CONST0_RTX (SFmode)))
5077 fputs ("%fr0", file);
5078 return;
5080 else
5081 break;
5082 case 'A':
5084 rtx xoperands[2];
5086 xoperands[0] = XEXP (XEXP (x, 0), 0);
5087 xoperands[1] = XVECEXP (XEXP (XEXP (x, 0), 1), 0, 0);
5088 output_global_address (file, xoperands[1], 0);
5089 fprintf (file, "(%s)", reg_names [REGNO (xoperands[0])]);
5090 return;
5093 case 'C': /* Plain (C)ondition */
5094 case 'X':
5095 switch (GET_CODE (x))
5097 case EQ:
5098 fputs ("=", file); break;
5099 case NE:
5100 fputs ("<>", file); break;
5101 case GT:
5102 fputs (">", file); break;
5103 case GE:
5104 fputs (">=", file); break;
5105 case GEU:
5106 fputs (">>=", file); break;
5107 case GTU:
5108 fputs (">>", file); break;
5109 case LT:
5110 fputs ("<", file); break;
5111 case LE:
5112 fputs ("<=", file); break;
5113 case LEU:
5114 fputs ("<<=", file); break;
5115 case LTU:
5116 fputs ("<<", file); break;
5117 default:
5118 abort ();
5120 return;
5121 case 'N': /* Condition, (N)egated */
5122 switch (GET_CODE (x))
5124 case EQ:
5125 fputs ("<>", file); break;
5126 case NE:
5127 fputs ("=", file); break;
5128 case GT:
5129 fputs ("<=", file); break;
5130 case GE:
5131 fputs ("<", file); break;
5132 case GEU:
5133 fputs ("<<", file); break;
5134 case GTU:
5135 fputs ("<<=", file); break;
5136 case LT:
5137 fputs (">=", file); break;
5138 case LE:
5139 fputs (">", file); break;
5140 case LEU:
5141 fputs (">>", file); break;
5142 case LTU:
5143 fputs (">>=", file); break;
5144 default:
5145 abort ();
5147 return;
5148 /* For floating point comparisons. Note that the output
5149 predicates are the complement of the desired mode. The
5150 conditions for GT, GE, LT, LE and LTGT cause an invalid
5151 operation exception if the result is unordered and this
5152 exception is enabled in the floating-point status register. */
5153 case 'Y':
5154 switch (GET_CODE (x))
5156 case EQ:
5157 fputs ("!=", file); break;
5158 case NE:
5159 fputs ("=", file); break;
5160 case GT:
5161 fputs ("!>", file); break;
5162 case GE:
5163 fputs ("!>=", file); break;
5164 case LT:
5165 fputs ("!<", file); break;
5166 case LE:
5167 fputs ("!<=", file); break;
5168 case LTGT:
5169 fputs ("!<>", file); break;
5170 case UNLE:
5171 fputs ("!?<=", file); break;
5172 case UNLT:
5173 fputs ("!?<", file); break;
5174 case UNGE:
5175 fputs ("!?>=", file); break;
5176 case UNGT:
5177 fputs ("!?>", file); break;
5178 case UNEQ:
5179 fputs ("!?=", file); break;
5180 case UNORDERED:
5181 fputs ("!?", file); break;
5182 case ORDERED:
5183 fputs ("?", file); break;
5184 default:
5185 abort ();
5187 return;
5188 case 'S': /* Condition, operands are (S)wapped. */
5189 switch (GET_CODE (x))
5191 case EQ:
5192 fputs ("=", file); break;
5193 case NE:
5194 fputs ("<>", file); break;
5195 case GT:
5196 fputs ("<", file); break;
5197 case GE:
5198 fputs ("<=", file); break;
5199 case GEU:
5200 fputs ("<<=", file); break;
5201 case GTU:
5202 fputs ("<<", file); break;
5203 case LT:
5204 fputs (">", file); break;
5205 case LE:
5206 fputs (">=", file); break;
5207 case LEU:
5208 fputs (">>=", file); break;
5209 case LTU:
5210 fputs (">>", file); break;
5211 default:
5212 abort ();
5214 return;
5215 case 'B': /* Condition, (B)oth swapped and negate. */
5216 switch (GET_CODE (x))
5218 case EQ:
5219 fputs ("<>", file); break;
5220 case NE:
5221 fputs ("=", file); break;
5222 case GT:
5223 fputs (">=", file); break;
5224 case GE:
5225 fputs (">", file); break;
5226 case GEU:
5227 fputs (">>", file); break;
5228 case GTU:
5229 fputs (">>=", file); break;
5230 case LT:
5231 fputs ("<=", file); break;
5232 case LE:
5233 fputs ("<", file); break;
5234 case LEU:
5235 fputs ("<<", file); break;
5236 case LTU:
5237 fputs ("<<=", file); break;
5238 default:
5239 abort ();
5241 return;
5242 case 'k':
5243 if (GET_CODE (x) == CONST_INT)
5245 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~INTVAL (x));
5246 return;
5248 abort ();
5249 case 'Q':
5250 if (GET_CODE (x) == CONST_INT)
5252 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 64 - (INTVAL (x) & 63));
5253 return;
5255 abort ();
5256 case 'L':
5257 if (GET_CODE (x) == CONST_INT)
5259 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 32 - (INTVAL (x) & 31));
5260 return;
5262 abort ();
5263 case 'O':
5264 if (GET_CODE (x) == CONST_INT && exact_log2 (INTVAL (x)) >= 0)
5266 fprintf (file, "%d", exact_log2 (INTVAL (x)));
5267 return;
5269 abort ();
5270 case 'p':
5271 if (GET_CODE (x) == CONST_INT)
5273 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 63 - (INTVAL (x) & 63));
5274 return;
5276 abort ();
5277 case 'P':
5278 if (GET_CODE (x) == CONST_INT)
5280 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 31 - (INTVAL (x) & 31));
5281 return;
5283 abort ();
5284 case 'I':
5285 if (GET_CODE (x) == CONST_INT)
5286 fputs ("i", file);
5287 return;
5288 case 'M':
5289 case 'F':
5290 switch (GET_CODE (XEXP (x, 0)))
5292 case PRE_DEC:
5293 case PRE_INC:
5294 if (ASSEMBLER_DIALECT == 0)
5295 fputs ("s,mb", file);
5296 else
5297 fputs (",mb", file);
5298 break;
5299 case POST_DEC:
5300 case POST_INC:
5301 if (ASSEMBLER_DIALECT == 0)
5302 fputs ("s,ma", file);
5303 else
5304 fputs (",ma", file);
5305 break;
5306 case PLUS:
5307 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5308 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5310 if (ASSEMBLER_DIALECT == 0)
5311 fputs ("x", file);
5313 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
5314 || GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5316 if (ASSEMBLER_DIALECT == 0)
5317 fputs ("x,s", file);
5318 else
5319 fputs (",s", file);
5321 else if (code == 'F' && ASSEMBLER_DIALECT == 0)
5322 fputs ("s", file);
5323 break;
5324 default:
5325 if (code == 'F' && ASSEMBLER_DIALECT == 0)
5326 fputs ("s", file);
5327 break;
5329 return;
5330 case 'G':
5331 output_global_address (file, x, 0);
5332 return;
5333 case 'H':
5334 output_global_address (file, x, 1);
5335 return;
5336 case 0: /* Don't do anything special */
5337 break;
5338 case 'Z':
5340 unsigned op[3];
5341 compute_zdepwi_operands (INTVAL (x), op);
5342 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5343 return;
5345 case 'z':
5347 unsigned op[3];
5348 compute_zdepdi_operands (INTVAL (x), op);
5349 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5350 return;
5352 case 'c':
5353 /* We can get here from a .vtable_inherit due to our
5354 CONSTANT_ADDRESS_P rejecting perfectly good constant
5355 addresses. */
5356 break;
5357 default:
5358 abort ();
5360 if (GET_CODE (x) == REG)
5362 fputs (reg_names [REGNO (x)], file);
5363 if (TARGET_64BIT && FP_REG_P (x) && GET_MODE_SIZE (GET_MODE (x)) <= 4)
5365 fputs ("R", file);
5366 return;
5368 if (FP_REG_P (x)
5369 && GET_MODE_SIZE (GET_MODE (x)) <= 4
5370 && (REGNO (x) & 1) == 0)
5371 fputs ("L", file);
5373 else if (GET_CODE (x) == MEM)
5375 int size = GET_MODE_SIZE (GET_MODE (x));
5376 rtx base = NULL_RTX;
5377 switch (GET_CODE (XEXP (x, 0)))
5379 case PRE_DEC:
5380 case POST_DEC:
5381 base = XEXP (XEXP (x, 0), 0);
5382 fprintf (file, "-%d(%s)", size, reg_names [REGNO (base)]);
5383 break;
5384 case PRE_INC:
5385 case POST_INC:
5386 base = XEXP (XEXP (x, 0), 0);
5387 fprintf (file, "%d(%s)", size, reg_names [REGNO (base)]);
5388 break;
5389 case PLUS:
5390 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
5391 fprintf (file, "%s(%s)",
5392 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 0), 0))],
5393 reg_names [REGNO (XEXP (XEXP (x, 0), 1))]);
5394 else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5395 fprintf (file, "%s(%s)",
5396 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 1), 0))],
5397 reg_names [REGNO (XEXP (XEXP (x, 0), 0))]);
5398 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5399 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5401 /* Because the REG_POINTER flag can get lost during reload,
5402 GO_IF_LEGITIMATE_ADDRESS canonicalizes the order of the
5403 index and base registers in the combined move patterns. */
5404 rtx base = XEXP (XEXP (x, 0), 1);
5405 rtx index = XEXP (XEXP (x, 0), 0);
5407 fprintf (file, "%s(%s)",
5408 reg_names [REGNO (index)], reg_names [REGNO (base)]);
5410 else
5411 output_address (XEXP (x, 0));
5412 break;
5413 default:
5414 output_address (XEXP (x, 0));
5415 break;
5418 else
5419 output_addr_const (file, x);
5422 /* output a SYMBOL_REF or a CONST expression involving a SYMBOL_REF. */
5424 void
5425 output_global_address (FILE *file, rtx x, int round_constant)
5428 /* Imagine (high (const (plus ...))). */
5429 if (GET_CODE (x) == HIGH)
5430 x = XEXP (x, 0);
5432 if (GET_CODE (x) == SYMBOL_REF && read_only_operand (x, VOIDmode))
5433 assemble_name (file, XSTR (x, 0));
5434 else if (GET_CODE (x) == SYMBOL_REF && !flag_pic)
5436 assemble_name (file, XSTR (x, 0));
5437 fputs ("-$global$", file);
5439 else if (GET_CODE (x) == CONST)
5441 const char *sep = "";
5442 int offset = 0; /* assembler wants -$global$ at end */
5443 rtx base = NULL_RTX;
5445 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)
5447 base = XEXP (XEXP (x, 0), 0);
5448 output_addr_const (file, base);
5450 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == CONST_INT)
5451 offset = INTVAL (XEXP (XEXP (x, 0), 0));
5452 else abort ();
5454 if (GET_CODE (XEXP (XEXP (x, 0), 1)) == SYMBOL_REF)
5456 base = XEXP (XEXP (x, 0), 1);
5457 output_addr_const (file, base);
5459 else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
5460 offset = INTVAL (XEXP (XEXP (x, 0), 1));
5461 else abort ();
5463 /* How bogus. The compiler is apparently responsible for
5464 rounding the constant if it uses an LR field selector.
5466 The linker and/or assembler seem a better place since
5467 they have to do this kind of thing already.
5469 If we fail to do this, HP's optimizing linker may eliminate
5470 an addil, but not update the ldw/stw/ldo instruction that
5471 uses the result of the addil. */
5472 if (round_constant)
5473 offset = ((offset + 0x1000) & ~0x1fff);
5475 if (GET_CODE (XEXP (x, 0)) == PLUS)
5477 if (offset < 0)
5479 offset = -offset;
5480 sep = "-";
5482 else
5483 sep = "+";
5485 else if (GET_CODE (XEXP (x, 0)) == MINUS
5486 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF))
5487 sep = "-";
5488 else abort ();
5490 if (!read_only_operand (base, VOIDmode) && !flag_pic)
5491 fputs ("-$global$", file);
5492 if (offset)
5493 fprintf (file, "%s%d", sep, offset);
5495 else
5496 output_addr_const (file, x);
5499 /* Output boilerplate text to appear at the beginning of the file.
5500 There are several possible versions. */
5501 #define aputs(x) fputs(x, asm_out_file)
5502 static inline void
5503 pa_file_start_level (void)
5505 if (TARGET_64BIT)
5506 aputs ("\t.LEVEL 2.0w\n");
5507 else if (TARGET_PA_20)
5508 aputs ("\t.LEVEL 2.0\n");
5509 else if (TARGET_PA_11)
5510 aputs ("\t.LEVEL 1.1\n");
5511 else
5512 aputs ("\t.LEVEL 1.0\n");
5515 static inline void
5516 pa_file_start_space (int sortspace)
5518 aputs ("\t.SPACE $PRIVATE$");
5519 if (sortspace)
5520 aputs (",SORT=16");
5521 aputs ("\n\t.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31"
5522 "\n\t.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82"
5523 "\n\t.SPACE $TEXT$");
5524 if (sortspace)
5525 aputs (",SORT=8");
5526 aputs ("\n\t.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44"
5527 "\n\t.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n");
5530 static inline void
5531 pa_file_start_file (int want_version)
5533 if (write_symbols != NO_DEBUG)
5535 output_file_directive (asm_out_file, main_input_filename);
5536 if (want_version)
5537 aputs ("\t.version\t\"01.01\"\n");
5541 static inline void
5542 pa_file_start_mcount (const char *aswhat)
5544 if (profile_flag)
5545 fprintf (asm_out_file, "\t.IMPORT _mcount,%s\n", aswhat);
5548 static void
5549 pa_elf_file_start (void)
5551 pa_file_start_level ();
5552 pa_file_start_mcount ("ENTRY");
5553 pa_file_start_file (0);
5556 static void
5557 pa_som_file_start (void)
5559 pa_file_start_level ();
5560 pa_file_start_space (0);
5561 aputs ("\t.IMPORT $global$,DATA\n"
5562 "\t.IMPORT $$dyncall,MILLICODE\n");
5563 pa_file_start_mcount ("CODE");
5564 pa_file_start_file (0);
5567 static void
5568 pa_linux_file_start (void)
5570 pa_file_start_file (1);
5571 pa_file_start_level ();
5572 pa_file_start_mcount ("CODE");
5575 static void
5576 pa_hpux64_gas_file_start (void)
5578 pa_file_start_level ();
5579 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
5580 if (profile_flag)
5581 ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, "_mcount", "function");
5582 #endif
5583 pa_file_start_file (1);
5586 static void
5587 pa_hpux64_hpas_file_start (void)
5589 pa_file_start_level ();
5590 pa_file_start_space (1);
5591 pa_file_start_mcount ("CODE");
5592 pa_file_start_file (0);
5594 #undef aputs
5596 static struct deferred_plabel *
5597 get_plabel (const char *fname)
5599 size_t i;
5601 /* See if we have already put this function on the list of deferred
5602 plabels. This list is generally small, so a liner search is not
5603 too ugly. If it proves too slow replace it with something faster. */
5604 for (i = 0; i < n_deferred_plabels; i++)
5605 if (strcmp (fname, deferred_plabels[i].name) == 0)
5606 break;
5608 /* If the deferred plabel list is empty, or this entry was not found
5609 on the list, create a new entry on the list. */
5610 if (deferred_plabels == NULL || i == n_deferred_plabels)
5612 if (deferred_plabels == 0)
5613 deferred_plabels = (struct deferred_plabel *)
5614 ggc_alloc (sizeof (struct deferred_plabel));
5615 else
5616 deferred_plabels = (struct deferred_plabel *)
5617 ggc_realloc (deferred_plabels,
5618 ((n_deferred_plabels + 1)
5619 * sizeof (struct deferred_plabel)));
5621 i = n_deferred_plabels++;
5622 deferred_plabels[i].internal_label = gen_label_rtx ();
5623 deferred_plabels[i].name = ggc_strdup (fname);
5625 /* Gross. We have just implicitly taken the address of
5626 this function, mark it as such. */
5627 fname = targetm.strip_name_encoding (fname);
5628 TREE_SYMBOL_REFERENCED (get_identifier (fname)) = 1;
5631 return &deferred_plabels[i];
5634 static void
5635 output_deferred_plabels (void)
5637 size_t i;
5638 /* If we have deferred plabels, then we need to switch into the data
5639 section and align it to a 4 byte boundary before we output the
5640 deferred plabels. */
5641 if (n_deferred_plabels)
5643 data_section ();
5644 ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2);
5647 /* Now output the deferred plabels. */
5648 for (i = 0; i < n_deferred_plabels; i++)
5650 (*targetm.asm_out.internal_label) (asm_out_file, "L",
5651 CODE_LABEL_NUMBER (deferred_plabels[i].internal_label));
5652 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, deferred_plabels[i].name),
5653 TARGET_64BIT ? 8 : 4, TARGET_64BIT ? 64 : 32, 1);
5657 #ifdef HPUX_LONG_DOUBLE_LIBRARY
5658 /* Initialize optabs to point to HPUX long double emulation routines. */
5659 static void
5660 pa_hpux_init_libfuncs (void)
5662 set_optab_libfunc (add_optab, TFmode, "_U_Qfadd");
5663 set_optab_libfunc (sub_optab, TFmode, "_U_Qfsub");
5664 set_optab_libfunc (smul_optab, TFmode, "_U_Qfmpy");
5665 set_optab_libfunc (sdiv_optab, TFmode, "_U_Qfdiv");
5666 set_optab_libfunc (smin_optab, TFmode, "_U_Qmin");
5667 set_optab_libfunc (smax_optab, TFmode, "_U_Qfmax");
5668 set_optab_libfunc (sqrt_optab, TFmode, "_U_Qfsqrt");
5669 set_optab_libfunc (abs_optab, TFmode, "_U_Qfabs");
5670 set_optab_libfunc (neg_optab, TFmode, "_U_Qfneg");
5672 set_optab_libfunc (eq_optab, TFmode, "_U_Qfeq");
5673 set_optab_libfunc (ne_optab, TFmode, "_U_Qfne");
5674 set_optab_libfunc (gt_optab, TFmode, "_U_Qfgt");
5675 set_optab_libfunc (ge_optab, TFmode, "_U_Qfge");
5676 set_optab_libfunc (lt_optab, TFmode, "_U_Qflt");
5677 set_optab_libfunc (le_optab, TFmode, "_U_Qfle");
5678 set_optab_libfunc (unord_optab, TFmode, "_U_Qfunord");
5680 set_conv_libfunc (sext_optab, TFmode, SFmode, "_U_Qfcnvff_sgl_to_quad");
5681 set_conv_libfunc (sext_optab, TFmode, DFmode, "_U_Qfcnvff_dbl_to_quad");
5682 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_U_Qfcnvff_quad_to_sgl");
5683 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_U_Qfcnvff_quad_to_dbl");
5685 set_conv_libfunc (sfix_optab, SImode, TFmode, TARGET_64BIT
5686 ? "__U_Qfcnvfxt_quad_to_sgl"
5687 : "_U_Qfcnvfxt_quad_to_sgl");
5688 set_conv_libfunc (sfix_optab, DImode, TFmode, "_U_Qfcnvfxt_quad_to_dbl");
5689 set_conv_libfunc (ufix_optab, SImode, TFmode, "_U_Qfcnvfxt_quad_to_usgl");
5690 set_conv_libfunc (ufix_optab, DImode, TFmode, "_U_Qfcnvfxt_quad_to_udbl");
5692 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_U_Qfcnvxf_sgl_to_quad");
5693 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_U_Qfcnvxf_dbl_to_quad");
5695 #endif
5697 /* HP's millicode routines mean something special to the assembler.
5698 Keep track of which ones we have used. */
5700 enum millicodes { remI, remU, divI, divU, mulI, end1000 };
5701 static void import_milli (enum millicodes);
5702 static char imported[(int) end1000];
5703 static const char * const milli_names[] = {"remI", "remU", "divI", "divU", "mulI"};
5704 static const char import_string[] = ".IMPORT $$....,MILLICODE";
5705 #define MILLI_START 10
5707 static void
5708 import_milli (enum millicodes code)
5710 char str[sizeof (import_string)];
5712 if (!imported[(int) code])
5714 imported[(int) code] = 1;
5715 strcpy (str, import_string);
5716 strncpy (str + MILLI_START, milli_names[(int) code], 4);
5717 output_asm_insn (str, 0);
5721 /* The register constraints have put the operands and return value in
5722 the proper registers. */
5724 const char *
5725 output_mul_insn (int unsignedp ATTRIBUTE_UNUSED, rtx insn)
5727 import_milli (mulI);
5728 return output_millicode_call (insn, gen_rtx_SYMBOL_REF (Pmode, "$$mulI"));
5731 /* Emit the rtl for doing a division by a constant. */
5733 /* Do magic division millicodes exist for this value? */
5734 static const int magic_milli[]= {0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0,
5735 1, 1};
5737 /* We'll use an array to keep track of the magic millicodes and
5738 whether or not we've used them already. [n][0] is signed, [n][1] is
5739 unsigned. */
5741 static int div_milli[16][2];
5744 div_operand (rtx op, enum machine_mode mode)
5746 return (mode == SImode
5747 && ((GET_CODE (op) == REG && REGNO (op) == 25)
5748 || (GET_CODE (op) == CONST_INT && INTVAL (op) > 0
5749 && INTVAL (op) < 16 && magic_milli[INTVAL (op)])));
5753 emit_hpdiv_const (rtx *operands, int unsignedp)
5755 if (GET_CODE (operands[2]) == CONST_INT
5756 && INTVAL (operands[2]) > 0
5757 && INTVAL (operands[2]) < 16
5758 && magic_milli[INTVAL (operands[2])])
5760 rtx ret = gen_rtx_REG (SImode, TARGET_64BIT ? 2 : 31);
5762 emit_move_insn (gen_rtx_REG (SImode, 26), operands[1]);
5763 emit
5764 (gen_rtx_PARALLEL
5765 (VOIDmode,
5766 gen_rtvec (6, gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, 29),
5767 gen_rtx_fmt_ee (unsignedp ? UDIV : DIV,
5768 SImode,
5769 gen_rtx_REG (SImode, 26),
5770 operands[2])),
5771 gen_rtx_CLOBBER (VOIDmode, operands[4]),
5772 gen_rtx_CLOBBER (VOIDmode, operands[3]),
5773 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 26)),
5774 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 25)),
5775 gen_rtx_CLOBBER (VOIDmode, ret))));
5776 emit_move_insn (operands[0], gen_rtx_REG (SImode, 29));
5777 return 1;
5779 return 0;
5782 const char *
5783 output_div_insn (rtx *operands, int unsignedp, rtx insn)
5785 int divisor;
5787 /* If the divisor is a constant, try to use one of the special
5788 opcodes .*/
5789 if (GET_CODE (operands[0]) == CONST_INT)
5791 static char buf[100];
5792 divisor = INTVAL (operands[0]);
5793 if (!div_milli[divisor][unsignedp])
5795 div_milli[divisor][unsignedp] = 1;
5796 if (unsignedp)
5797 output_asm_insn (".IMPORT $$divU_%0,MILLICODE", operands);
5798 else
5799 output_asm_insn (".IMPORT $$divI_%0,MILLICODE", operands);
5801 if (unsignedp)
5803 sprintf (buf, "$$divU_" HOST_WIDE_INT_PRINT_DEC,
5804 INTVAL (operands[0]));
5805 return output_millicode_call (insn,
5806 gen_rtx_SYMBOL_REF (SImode, buf));
5808 else
5810 sprintf (buf, "$$divI_" HOST_WIDE_INT_PRINT_DEC,
5811 INTVAL (operands[0]));
5812 return output_millicode_call (insn,
5813 gen_rtx_SYMBOL_REF (SImode, buf));
5816 /* Divisor isn't a special constant. */
5817 else
5819 if (unsignedp)
5821 import_milli (divU);
5822 return output_millicode_call (insn,
5823 gen_rtx_SYMBOL_REF (SImode, "$$divU"));
5825 else
5827 import_milli (divI);
5828 return output_millicode_call (insn,
5829 gen_rtx_SYMBOL_REF (SImode, "$$divI"));
5834 /* Output a $$rem millicode to do mod. */
5836 const char *
5837 output_mod_insn (int unsignedp, rtx insn)
5839 if (unsignedp)
5841 import_milli (remU);
5842 return output_millicode_call (insn,
5843 gen_rtx_SYMBOL_REF (SImode, "$$remU"));
5845 else
5847 import_milli (remI);
5848 return output_millicode_call (insn,
5849 gen_rtx_SYMBOL_REF (SImode, "$$remI"));
5853 void
5854 output_arg_descriptor (rtx call_insn)
5856 const char *arg_regs[4];
5857 enum machine_mode arg_mode;
5858 rtx link;
5859 int i, output_flag = 0;
5860 int regno;
5862 /* We neither need nor want argument location descriptors for the
5863 64bit runtime environment or the ELF32 environment. */
5864 if (TARGET_64BIT || TARGET_ELF32)
5865 return;
5867 for (i = 0; i < 4; i++)
5868 arg_regs[i] = 0;
5870 /* Specify explicitly that no argument relocations should take place
5871 if using the portable runtime calling conventions. */
5872 if (TARGET_PORTABLE_RUNTIME)
5874 fputs ("\t.CALL ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RETVAL=NO\n",
5875 asm_out_file);
5876 return;
5879 if (GET_CODE (call_insn) != CALL_INSN)
5880 abort ();
5881 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); link; link = XEXP (link, 1))
5883 rtx use = XEXP (link, 0);
5885 if (! (GET_CODE (use) == USE
5886 && GET_CODE (XEXP (use, 0)) == REG
5887 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
5888 continue;
5890 arg_mode = GET_MODE (XEXP (use, 0));
5891 regno = REGNO (XEXP (use, 0));
5892 if (regno >= 23 && regno <= 26)
5894 arg_regs[26 - regno] = "GR";
5895 if (arg_mode == DImode)
5896 arg_regs[25 - regno] = "GR";
5898 else if (regno >= 32 && regno <= 39)
5900 if (arg_mode == SFmode)
5901 arg_regs[(regno - 32) / 2] = "FR";
5902 else
5904 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
5905 arg_regs[(regno - 34) / 2] = "FR";
5906 arg_regs[(regno - 34) / 2 + 1] = "FU";
5907 #else
5908 arg_regs[(regno - 34) / 2] = "FU";
5909 arg_regs[(regno - 34) / 2 + 1] = "FR";
5910 #endif
5914 fputs ("\t.CALL ", asm_out_file);
5915 for (i = 0; i < 4; i++)
5917 if (arg_regs[i])
5919 if (output_flag++)
5920 fputc (',', asm_out_file);
5921 fprintf (asm_out_file, "ARGW%d=%s", i, arg_regs[i]);
5924 fputc ('\n', asm_out_file);
5927 /* Return the class of any secondary reload register that is needed to
5928 move IN into a register in class CLASS using mode MODE.
5930 Profiling has showed this routine and its descendants account for
5931 a significant amount of compile time (~7%). So it has been
5932 optimized to reduce redundant computations and eliminate useless
5933 function calls.
5935 It might be worthwhile to try and make this a leaf function too. */
5937 enum reg_class
5938 secondary_reload_class (enum reg_class class, enum machine_mode mode, rtx in)
5940 int regno, is_symbolic;
5942 /* Trying to load a constant into a FP register during PIC code
5943 generation will require %r1 as a scratch register. */
5944 if (flag_pic
5945 && GET_MODE_CLASS (mode) == MODE_INT
5946 && FP_REG_CLASS_P (class)
5947 && (GET_CODE (in) == CONST_INT || GET_CODE (in) == CONST_DOUBLE))
5948 return R1_REGS;
5950 /* Profiling showed the PA port spends about 1.3% of its compilation
5951 time in true_regnum from calls inside secondary_reload_class. */
5953 if (GET_CODE (in) == REG)
5955 regno = REGNO (in);
5956 if (regno >= FIRST_PSEUDO_REGISTER)
5957 regno = true_regnum (in);
5959 else if (GET_CODE (in) == SUBREG)
5960 regno = true_regnum (in);
5961 else
5962 regno = -1;
5964 /* If we have something like (mem (mem (...)), we can safely assume the
5965 inner MEM will end up in a general register after reloading, so there's
5966 no need for a secondary reload. */
5967 if (GET_CODE (in) == MEM
5968 && GET_CODE (XEXP (in, 0)) == MEM)
5969 return NO_REGS;
5971 /* Handle out of range displacement for integer mode loads/stores of
5972 FP registers. */
5973 if (((regno >= FIRST_PSEUDO_REGISTER || regno == -1)
5974 && GET_MODE_CLASS (mode) == MODE_INT
5975 && FP_REG_CLASS_P (class))
5976 || (class == SHIFT_REGS && (regno <= 0 || regno >= 32)))
5977 return GENERAL_REGS;
5979 /* A SAR<->FP register copy requires a secondary register (GPR) as
5980 well as secondary memory. */
5981 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5982 && ((REGNO_REG_CLASS (regno) == SHIFT_REGS && FP_REG_CLASS_P (class))
5983 || (class == SHIFT_REGS && FP_REG_CLASS_P (REGNO_REG_CLASS (regno)))))
5984 return GENERAL_REGS;
5986 if (GET_CODE (in) == HIGH)
5987 in = XEXP (in, 0);
5989 /* Profiling has showed GCC spends about 2.6% of its compilation
5990 time in symbolic_operand from calls inside secondary_reload_class.
5992 We use an inline copy and only compute its return value once to avoid
5993 useless work. */
5994 switch (GET_CODE (in))
5996 rtx tmp;
5998 case SYMBOL_REF:
5999 case LABEL_REF:
6000 is_symbolic = 1;
6001 break;
6002 case CONST:
6003 tmp = XEXP (in, 0);
6004 is_symbolic = ((GET_CODE (XEXP (tmp, 0)) == SYMBOL_REF
6005 || GET_CODE (XEXP (tmp, 0)) == LABEL_REF)
6006 && GET_CODE (XEXP (tmp, 1)) == CONST_INT);
6007 break;
6009 default:
6010 is_symbolic = 0;
6011 break;
6014 if (!flag_pic
6015 && is_symbolic
6016 && read_only_operand (in, VOIDmode))
6017 return NO_REGS;
6019 if (class != R1_REGS && is_symbolic)
6020 return R1_REGS;
6022 return NO_REGS;
6025 /* In the 32-bit runtime, arguments larger than eight bytes are passed
6026 by invisible reference. As a GCC extension, we also pass anything
6027 with a zero or variable size by reference.
6029 The 64-bit runtime does not describe passing any types by invisible
6030 reference. The internals of GCC can't currently handle passing
6031 empty structures, and zero or variable length arrays when they are
6032 not passed entirely on the stack or by reference. Thus, as a GCC
6033 extension, we pass these types by reference. The HP compiler doesn't
6034 support these types, so hopefully there shouldn't be any compatibility
6035 issues. This may have to be revisited when HP releases a C99 compiler
6036 or updates the ABI. */
6038 static bool
6039 pa_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
6040 enum machine_mode mode, tree type,
6041 bool named ATTRIBUTE_UNUSED)
6043 HOST_WIDE_INT size;
6045 if (type)
6046 size = int_size_in_bytes (type);
6047 else
6048 size = GET_MODE_SIZE (mode);
6050 if (TARGET_64BIT)
6051 return size <= 0;
6052 else
6053 return size <= 0 || size > 8;
6056 enum direction
6057 function_arg_padding (enum machine_mode mode, tree type)
6059 if (mode == BLKmode
6060 || (TARGET_64BIT && type && AGGREGATE_TYPE_P (type)))
6062 /* Return none if justification is not required. */
6063 if (type
6064 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
6065 && (int_size_in_bytes (type) * BITS_PER_UNIT) % PARM_BOUNDARY == 0)
6066 return none;
6068 /* The directions set here are ignored when a BLKmode argument larger
6069 than a word is placed in a register. Different code is used for
6070 the stack and registers. This makes it difficult to have a
6071 consistent data representation for both the stack and registers.
6072 For both runtimes, the justification and padding for arguments on
6073 the stack and in registers should be identical. */
6074 if (TARGET_64BIT)
6075 /* The 64-bit runtime specifies left justification for aggregates. */
6076 return upward;
6077 else
6078 /* The 32-bit runtime architecture specifies right justification.
6079 When the argument is passed on the stack, the argument is padded
6080 with garbage on the left. The HP compiler pads with zeros. */
6081 return downward;
6084 if (GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
6085 return downward;
6086 else
6087 return none;
6091 /* Do what is necessary for `va_start'. We look at the current function
6092 to determine if stdargs or varargs is used and fill in an initial
6093 va_list. A pointer to this constructor is returned. */
6095 static rtx
6096 hppa_builtin_saveregs (void)
6098 rtx offset, dest;
6099 tree fntype = TREE_TYPE (current_function_decl);
6100 int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
6101 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
6102 != void_type_node)))
6103 ? UNITS_PER_WORD : 0);
6105 if (argadj)
6106 offset = plus_constant (current_function_arg_offset_rtx, argadj);
6107 else
6108 offset = current_function_arg_offset_rtx;
6110 if (TARGET_64BIT)
6112 int i, off;
6114 /* Adjust for varargs/stdarg differences. */
6115 if (argadj)
6116 offset = plus_constant (current_function_arg_offset_rtx, -argadj);
6117 else
6118 offset = current_function_arg_offset_rtx;
6120 /* We need to save %r26 .. %r19 inclusive starting at offset -64
6121 from the incoming arg pointer and growing to larger addresses. */
6122 for (i = 26, off = -64; i >= 19; i--, off += 8)
6123 emit_move_insn (gen_rtx_MEM (word_mode,
6124 plus_constant (arg_pointer_rtx, off)),
6125 gen_rtx_REG (word_mode, i));
6127 /* The incoming args pointer points just beyond the flushback area;
6128 normally this is not a serious concern. However, when we are doing
6129 varargs/stdargs we want to make the arg pointer point to the start
6130 of the incoming argument area. */
6131 emit_move_insn (virtual_incoming_args_rtx,
6132 plus_constant (arg_pointer_rtx, -64));
6134 /* Now return a pointer to the first anonymous argument. */
6135 return copy_to_reg (expand_binop (Pmode, add_optab,
6136 virtual_incoming_args_rtx,
6137 offset, 0, 0, OPTAB_LIB_WIDEN));
6140 /* Store general registers on the stack. */
6141 dest = gen_rtx_MEM (BLKmode,
6142 plus_constant (current_function_internal_arg_pointer,
6143 -16));
6144 set_mem_alias_set (dest, get_varargs_alias_set ());
6145 set_mem_align (dest, BITS_PER_WORD);
6146 move_block_from_reg (23, dest, 4);
6148 /* move_block_from_reg will emit code to store the argument registers
6149 individually as scalar stores.
6151 However, other insns may later load from the same addresses for
6152 a structure load (passing a struct to a varargs routine).
6154 The alias code assumes that such aliasing can never happen, so we
6155 have to keep memory referencing insns from moving up beyond the
6156 last argument register store. So we emit a blockage insn here. */
6157 emit_insn (gen_blockage ());
6159 return copy_to_reg (expand_binop (Pmode, add_optab,
6160 current_function_internal_arg_pointer,
6161 offset, 0, 0, OPTAB_LIB_WIDEN));
6164 void
6165 hppa_va_start (tree valist, rtx nextarg)
6167 nextarg = expand_builtin_saveregs ();
6168 std_expand_builtin_va_start (valist, nextarg);
6171 static tree
6172 hppa_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p, tree *post_p)
6174 if (TARGET_64BIT)
6176 /* Args grow upward. We can use the generic routines. */
6177 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6179 else /* !TARGET_64BIT */
6181 tree ptr = build_pointer_type (type);
6182 tree valist_type;
6183 tree t, u;
6184 unsigned int size, ofs;
6185 bool indirect;
6187 indirect = pass_by_reference (NULL, TYPE_MODE (type), type, 0);
6188 if (indirect)
6190 type = ptr;
6191 ptr = build_pointer_type (type);
6193 size = int_size_in_bytes (type);
6194 valist_type = TREE_TYPE (valist);
6196 /* Args grow down. Not handled by generic routines. */
6198 u = fold_convert (valist_type, size_in_bytes (type));
6199 t = build (MINUS_EXPR, valist_type, valist, u);
6201 /* Copied from va-pa.h, but we probably don't need to align to
6202 word size, since we generate and preserve that invariant. */
6203 u = build_int_cst (valist_type, (size > 4 ? -8 : -4));
6204 t = build (BIT_AND_EXPR, valist_type, t, u);
6206 t = build (MODIFY_EXPR, valist_type, valist, t);
6208 ofs = (8 - size) % 4;
6209 if (ofs != 0)
6211 u = fold_convert (valist_type, size_int (ofs));
6212 t = build (PLUS_EXPR, valist_type, t, u);
6215 t = fold_convert (ptr, t);
6216 t = build_fold_indirect_ref (t);
6218 if (indirect)
6219 t = build_fold_indirect_ref (t);
6221 return t;
6225 /* True if MODE is valid for the target. By "valid", we mean able to
6226 be manipulated in non-trivial ways. In particular, this means all
6227 the arithmetic is supported.
6229 Currently, TImode is not valid as the HP 64-bit runtime documentation
6230 doesn't document the alignment and calling conventions for this type.
6231 Thus, we return false when PRECISION is 2 * BITS_PER_WORD and
6232 2 * BITS_PER_WORD isn't equal LONG_LONG_TYPE_SIZE. */
6234 static bool
6235 pa_scalar_mode_supported_p (enum machine_mode mode)
6237 int precision = GET_MODE_PRECISION (mode);
6239 switch (GET_MODE_CLASS (mode))
6241 case MODE_PARTIAL_INT:
6242 case MODE_INT:
6243 if (precision == CHAR_TYPE_SIZE)
6244 return true;
6245 if (precision == SHORT_TYPE_SIZE)
6246 return true;
6247 if (precision == INT_TYPE_SIZE)
6248 return true;
6249 if (precision == LONG_TYPE_SIZE)
6250 return true;
6251 if (precision == LONG_LONG_TYPE_SIZE)
6252 return true;
6253 return false;
6255 case MODE_FLOAT:
6256 if (precision == FLOAT_TYPE_SIZE)
6257 return true;
6258 if (precision == DOUBLE_TYPE_SIZE)
6259 return true;
6260 if (precision == LONG_DOUBLE_TYPE_SIZE)
6261 return true;
6262 return false;
6264 default:
6265 gcc_unreachable ();
6269 /* This routine handles all the normal conditional branch sequences we
6270 might need to generate. It handles compare immediate vs compare
6271 register, nullification of delay slots, varying length branches,
6272 negated branches, and all combinations of the above. It returns the
6273 output appropriate to emit the branch corresponding to all given
6274 parameters. */
6276 const char *
6277 output_cbranch (rtx *operands, int nullify, int length, int negated, rtx insn)
6279 static char buf[100];
6280 int useskip = 0;
6281 rtx xoperands[5];
6283 /* A conditional branch to the following instruction (e.g. the delay slot)
6284 is asking for a disaster. This can happen when not optimizing and
6285 when jump optimization fails.
6287 While it is usually safe to emit nothing, this can fail if the
6288 preceding instruction is a nullified branch with an empty delay
6289 slot and the same branch target as this branch. We could check
6290 for this but jump optimization should eliminate nop jumps. It
6291 is always safe to emit a nop. */
6292 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6293 return "nop";
6295 /* The doubleword form of the cmpib instruction doesn't have the LEU
6296 and GTU conditions while the cmpb instruction does. Since we accept
6297 zero for cmpb, we must ensure that we use cmpb for the comparison. */
6298 if (GET_MODE (operands[1]) == DImode && operands[2] == const0_rtx)
6299 operands[2] = gen_rtx_REG (DImode, 0);
6301 /* If this is a long branch with its delay slot unfilled, set `nullify'
6302 as it can nullify the delay slot and save a nop. */
6303 if (length == 8 && dbr_sequence_length () == 0)
6304 nullify = 1;
6306 /* If this is a short forward conditional branch which did not get
6307 its delay slot filled, the delay slot can still be nullified. */
6308 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6309 nullify = forward_branch_p (insn);
6311 /* A forward branch over a single nullified insn can be done with a
6312 comclr instruction. This avoids a single cycle penalty due to
6313 mis-predicted branch if we fall through (branch not taken). */
6314 if (length == 4
6315 && next_real_insn (insn) != 0
6316 && get_attr_length (next_real_insn (insn)) == 4
6317 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6318 && nullify)
6319 useskip = 1;
6321 switch (length)
6323 /* All short conditional branches except backwards with an unfilled
6324 delay slot. */
6325 case 4:
6326 if (useskip)
6327 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6328 else
6329 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6330 if (GET_MODE (operands[1]) == DImode)
6331 strcat (buf, "*");
6332 if (negated)
6333 strcat (buf, "%B3");
6334 else
6335 strcat (buf, "%S3");
6336 if (useskip)
6337 strcat (buf, " %2,%r1,%%r0");
6338 else if (nullify)
6339 strcat (buf, ",n %2,%r1,%0");
6340 else
6341 strcat (buf, " %2,%r1,%0");
6342 break;
6344 /* All long conditionals. Note a short backward branch with an
6345 unfilled delay slot is treated just like a long backward branch
6346 with an unfilled delay slot. */
6347 case 8:
6348 /* Handle weird backwards branch with a filled delay slot
6349 with is nullified. */
6350 if (dbr_sequence_length () != 0
6351 && ! forward_branch_p (insn)
6352 && nullify)
6354 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6355 if (GET_MODE (operands[1]) == DImode)
6356 strcat (buf, "*");
6357 if (negated)
6358 strcat (buf, "%S3");
6359 else
6360 strcat (buf, "%B3");
6361 strcat (buf, ",n %2,%r1,.+12\n\tb %0");
6363 /* Handle short backwards branch with an unfilled delay slot.
6364 Using a comb;nop rather than comiclr;bl saves 1 cycle for both
6365 taken and untaken branches. */
6366 else if (dbr_sequence_length () == 0
6367 && ! forward_branch_p (insn)
6368 && INSN_ADDRESSES_SET_P ()
6369 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6370 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6372 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6373 if (GET_MODE (operands[1]) == DImode)
6374 strcat (buf, "*");
6375 if (negated)
6376 strcat (buf, "%B3 %2,%r1,%0%#");
6377 else
6378 strcat (buf, "%S3 %2,%r1,%0%#");
6380 else
6382 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6383 if (GET_MODE (operands[1]) == DImode)
6384 strcat (buf, "*");
6385 if (negated)
6386 strcat (buf, "%S3");
6387 else
6388 strcat (buf, "%B3");
6389 if (nullify)
6390 strcat (buf, " %2,%r1,%%r0\n\tb,n %0");
6391 else
6392 strcat (buf, " %2,%r1,%%r0\n\tb %0");
6394 break;
6396 case 20:
6397 case 28:
6398 xoperands[0] = operands[0];
6399 xoperands[1] = operands[1];
6400 xoperands[2] = operands[2];
6401 xoperands[3] = operands[3];
6403 /* The reversed conditional branch must branch over one additional
6404 instruction if the delay slot is filled. If the delay slot
6405 is empty, the instruction after the reversed condition branch
6406 must be nullified. */
6407 nullify = dbr_sequence_length () == 0;
6408 xoperands[4] = nullify ? GEN_INT (length) : GEN_INT (length + 4);
6410 /* Create a reversed conditional branch which branches around
6411 the following insns. */
6412 if (GET_MODE (operands[1]) != DImode)
6414 if (nullify)
6416 if (negated)
6417 strcpy (buf,
6418 "{com%I2b,%S3,n %2,%r1,.+%4|cmp%I2b,%S3,n %2,%r1,.+%4}");
6419 else
6420 strcpy (buf,
6421 "{com%I2b,%B3,n %2,%r1,.+%4|cmp%I2b,%B3,n %2,%r1,.+%4}");
6423 else
6425 if (negated)
6426 strcpy (buf,
6427 "{com%I2b,%S3 %2,%r1,.+%4|cmp%I2b,%S3 %2,%r1,.+%4}");
6428 else
6429 strcpy (buf,
6430 "{com%I2b,%B3 %2,%r1,.+%4|cmp%I2b,%B3 %2,%r1,.+%4}");
6433 else
6435 if (nullify)
6437 if (negated)
6438 strcpy (buf,
6439 "{com%I2b,*%S3,n %2,%r1,.+%4|cmp%I2b,*%S3,n %2,%r1,.+%4}");
6440 else
6441 strcpy (buf,
6442 "{com%I2b,*%B3,n %2,%r1,.+%4|cmp%I2b,*%B3,n %2,%r1,.+%4}");
6444 else
6446 if (negated)
6447 strcpy (buf,
6448 "{com%I2b,*%S3 %2,%r1,.+%4|cmp%I2b,*%S3 %2,%r1,.+%4}");
6449 else
6450 strcpy (buf,
6451 "{com%I2b,*%B3 %2,%r1,.+%4|cmp%I2b,*%B3 %2,%r1,.+%4}");
6455 output_asm_insn (buf, xoperands);
6456 return output_lbranch (operands[0], insn);
6458 default:
6459 abort ();
6461 return buf;
6464 /* This routine handles long unconditional branches that exceed the
6465 maximum range of a simple branch instruction. */
6467 const char *
6468 output_lbranch (rtx dest, rtx insn)
6470 rtx xoperands[2];
6472 xoperands[0] = dest;
6474 /* First, free up the delay slot. */
6475 if (dbr_sequence_length () != 0)
6477 /* We can't handle a jump in the delay slot. */
6478 if (GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
6479 abort ();
6481 final_scan_insn (NEXT_INSN (insn), asm_out_file,
6482 optimize, 0, 0, NULL);
6484 /* Now delete the delay insn. */
6485 PUT_CODE (NEXT_INSN (insn), NOTE);
6486 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
6487 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
6490 /* Output an insn to save %r1. The runtime documentation doesn't
6491 specify whether the "Clean Up" slot in the callers frame can
6492 be clobbered by the callee. It isn't copied by HP's builtin
6493 alloca, so this suggests that it can be clobbered if necessary.
6494 The "Static Link" location is copied by HP builtin alloca, so
6495 we avoid using it. Using the cleanup slot might be a problem
6496 if we have to interoperate with languages that pass cleanup
6497 information. However, it should be possible to handle these
6498 situations with GCC's asm feature.
6500 The "Current RP" slot is reserved for the called procedure, so
6501 we try to use it when we don't have a frame of our own. It's
6502 rather unlikely that we won't have a frame when we need to emit
6503 a very long branch.
6505 Really the way to go long term is a register scavenger; goto
6506 the target of the jump and find a register which we can use
6507 as a scratch to hold the value in %r1. Then, we wouldn't have
6508 to free up the delay slot or clobber a slot that may be needed
6509 for other purposes. */
6510 if (TARGET_64BIT)
6512 if (actual_fsize == 0 && !regs_ever_live[2])
6513 /* Use the return pointer slot in the frame marker. */
6514 output_asm_insn ("std %%r1,-16(%%r30)", xoperands);
6515 else
6516 /* Use the slot at -40 in the frame marker since HP builtin
6517 alloca doesn't copy it. */
6518 output_asm_insn ("std %%r1,-40(%%r30)", xoperands);
6520 else
6522 if (actual_fsize == 0 && !regs_ever_live[2])
6523 /* Use the return pointer slot in the frame marker. */
6524 output_asm_insn ("stw %%r1,-20(%%r30)", xoperands);
6525 else
6526 /* Use the "Clean Up" slot in the frame marker. In GCC,
6527 the only other use of this location is for copying a
6528 floating point double argument from a floating-point
6529 register to two general registers. The copy is done
6530 as an "atomic" operation when outputting a call, so it
6531 won't interfere with our using the location here. */
6532 output_asm_insn ("stw %%r1,-12(%%r30)", xoperands);
6535 if (TARGET_PORTABLE_RUNTIME)
6537 output_asm_insn ("ldil L'%0,%%r1", xoperands);
6538 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
6539 output_asm_insn ("bv %%r0(%%r1)", xoperands);
6541 else if (flag_pic)
6543 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
6544 if (TARGET_SOM || !TARGET_GAS)
6546 xoperands[1] = gen_label_rtx ();
6547 output_asm_insn ("addil L'%l0-%l1,%%r1", xoperands);
6548 (*targetm.asm_out.internal_label) (asm_out_file, "L",
6549 CODE_LABEL_NUMBER (xoperands[1]));
6550 output_asm_insn ("ldo R'%l0-%l1(%%r1),%%r1", xoperands);
6552 else
6554 output_asm_insn ("addil L'%l0-$PIC_pcrel$0+4,%%r1", xoperands);
6555 output_asm_insn ("ldo R'%l0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
6557 output_asm_insn ("bv %%r0(%%r1)", xoperands);
6559 else
6560 /* Now output a very long branch to the original target. */
6561 output_asm_insn ("ldil L'%l0,%%r1\n\tbe R'%l0(%%sr4,%%r1)", xoperands);
6563 /* Now restore the value of %r1 in the delay slot. */
6564 if (TARGET_64BIT)
6566 if (actual_fsize == 0 && !regs_ever_live[2])
6567 return "ldd -16(%%r30),%%r1";
6568 else
6569 return "ldd -40(%%r30),%%r1";
6571 else
6573 if (actual_fsize == 0 && !regs_ever_live[2])
6574 return "ldw -20(%%r30),%%r1";
6575 else
6576 return "ldw -12(%%r30),%%r1";
6580 /* This routine handles all the branch-on-bit conditional branch sequences we
6581 might need to generate. It handles nullification of delay slots,
6582 varying length branches, negated branches and all combinations of the
6583 above. it returns the appropriate output template to emit the branch. */
6585 const char *
6586 output_bb (rtx *operands ATTRIBUTE_UNUSED, int nullify, int length,
6587 int negated, rtx insn, int which)
6589 static char buf[100];
6590 int useskip = 0;
6592 /* A conditional branch to the following instruction (e.g. the delay slot) is
6593 asking for a disaster. I do not think this can happen as this pattern
6594 is only used when optimizing; jump optimization should eliminate the
6595 jump. But be prepared just in case. */
6597 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6598 return "nop";
6600 /* If this is a long branch with its delay slot unfilled, set `nullify'
6601 as it can nullify the delay slot and save a nop. */
6602 if (length == 8 && dbr_sequence_length () == 0)
6603 nullify = 1;
6605 /* If this is a short forward conditional branch which did not get
6606 its delay slot filled, the delay slot can still be nullified. */
6607 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6608 nullify = forward_branch_p (insn);
6610 /* A forward branch over a single nullified insn can be done with a
6611 extrs instruction. This avoids a single cycle penalty due to
6612 mis-predicted branch if we fall through (branch not taken). */
6614 if (length == 4
6615 && next_real_insn (insn) != 0
6616 && get_attr_length (next_real_insn (insn)) == 4
6617 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6618 && nullify)
6619 useskip = 1;
6621 switch (length)
6624 /* All short conditional branches except backwards with an unfilled
6625 delay slot. */
6626 case 4:
6627 if (useskip)
6628 strcpy (buf, "{extrs,|extrw,s,}");
6629 else
6630 strcpy (buf, "bb,");
6631 if (useskip && GET_MODE (operands[0]) == DImode)
6632 strcpy (buf, "extrd,s,*");
6633 else if (GET_MODE (operands[0]) == DImode)
6634 strcpy (buf, "bb,*");
6635 if ((which == 0 && negated)
6636 || (which == 1 && ! negated))
6637 strcat (buf, ">=");
6638 else
6639 strcat (buf, "<");
6640 if (useskip)
6641 strcat (buf, " %0,%1,1,%%r0");
6642 else if (nullify && negated)
6643 strcat (buf, ",n %0,%1,%3");
6644 else if (nullify && ! negated)
6645 strcat (buf, ",n %0,%1,%2");
6646 else if (! nullify && negated)
6647 strcat (buf, "%0,%1,%3");
6648 else if (! nullify && ! negated)
6649 strcat (buf, " %0,%1,%2");
6650 break;
6652 /* All long conditionals. Note a short backward branch with an
6653 unfilled delay slot is treated just like a long backward branch
6654 with an unfilled delay slot. */
6655 case 8:
6656 /* Handle weird backwards branch with a filled delay slot
6657 with is nullified. */
6658 if (dbr_sequence_length () != 0
6659 && ! forward_branch_p (insn)
6660 && nullify)
6662 strcpy (buf, "bb,");
6663 if (GET_MODE (operands[0]) == DImode)
6664 strcat (buf, "*");
6665 if ((which == 0 && negated)
6666 || (which == 1 && ! negated))
6667 strcat (buf, "<");
6668 else
6669 strcat (buf, ">=");
6670 if (negated)
6671 strcat (buf, ",n %0,%1,.+12\n\tb %3");
6672 else
6673 strcat (buf, ",n %0,%1,.+12\n\tb %2");
6675 /* Handle short backwards branch with an unfilled delay slot.
6676 Using a bb;nop rather than extrs;bl saves 1 cycle for both
6677 taken and untaken branches. */
6678 else if (dbr_sequence_length () == 0
6679 && ! forward_branch_p (insn)
6680 && INSN_ADDRESSES_SET_P ()
6681 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6682 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6684 strcpy (buf, "bb,");
6685 if (GET_MODE (operands[0]) == DImode)
6686 strcat (buf, "*");
6687 if ((which == 0 && negated)
6688 || (which == 1 && ! negated))
6689 strcat (buf, ">=");
6690 else
6691 strcat (buf, "<");
6692 if (negated)
6693 strcat (buf, " %0,%1,%3%#");
6694 else
6695 strcat (buf, " %0,%1,%2%#");
6697 else
6699 strcpy (buf, "{extrs,|extrw,s,}");
6700 if (GET_MODE (operands[0]) == DImode)
6701 strcpy (buf, "extrd,s,*");
6702 if ((which == 0 && negated)
6703 || (which == 1 && ! negated))
6704 strcat (buf, "<");
6705 else
6706 strcat (buf, ">=");
6707 if (nullify && negated)
6708 strcat (buf, " %0,%1,1,%%r0\n\tb,n %3");
6709 else if (nullify && ! negated)
6710 strcat (buf, " %0,%1,1,%%r0\n\tb,n %2");
6711 else if (negated)
6712 strcat (buf, " %0,%1,1,%%r0\n\tb %3");
6713 else
6714 strcat (buf, " %0,%1,1,%%r0\n\tb %2");
6716 break;
6718 default:
6719 abort ();
6721 return buf;
6724 /* This routine handles all the branch-on-variable-bit conditional branch
6725 sequences we might need to generate. It handles nullification of delay
6726 slots, varying length branches, negated branches and all combinations
6727 of the above. it returns the appropriate output template to emit the
6728 branch. */
6730 const char *
6731 output_bvb (rtx *operands ATTRIBUTE_UNUSED, int nullify, int length,
6732 int negated, rtx insn, int which)
6734 static char buf[100];
6735 int useskip = 0;
6737 /* A conditional branch to the following instruction (e.g. the delay slot) is
6738 asking for a disaster. I do not think this can happen as this pattern
6739 is only used when optimizing; jump optimization should eliminate the
6740 jump. But be prepared just in case. */
6742 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6743 return "nop";
6745 /* If this is a long branch with its delay slot unfilled, set `nullify'
6746 as it can nullify the delay slot and save a nop. */
6747 if (length == 8 && dbr_sequence_length () == 0)
6748 nullify = 1;
6750 /* If this is a short forward conditional branch which did not get
6751 its delay slot filled, the delay slot can still be nullified. */
6752 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6753 nullify = forward_branch_p (insn);
6755 /* A forward branch over a single nullified insn can be done with a
6756 extrs instruction. This avoids a single cycle penalty due to
6757 mis-predicted branch if we fall through (branch not taken). */
6759 if (length == 4
6760 && next_real_insn (insn) != 0
6761 && get_attr_length (next_real_insn (insn)) == 4
6762 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6763 && nullify)
6764 useskip = 1;
6766 switch (length)
6769 /* All short conditional branches except backwards with an unfilled
6770 delay slot. */
6771 case 4:
6772 if (useskip)
6773 strcpy (buf, "{vextrs,|extrw,s,}");
6774 else
6775 strcpy (buf, "{bvb,|bb,}");
6776 if (useskip && GET_MODE (operands[0]) == DImode)
6777 strcpy (buf, "extrd,s,*");
6778 else if (GET_MODE (operands[0]) == DImode)
6779 strcpy (buf, "bb,*");
6780 if ((which == 0 && negated)
6781 || (which == 1 && ! negated))
6782 strcat (buf, ">=");
6783 else
6784 strcat (buf, "<");
6785 if (useskip)
6786 strcat (buf, "{ %0,1,%%r0| %0,%%sar,1,%%r0}");
6787 else if (nullify && negated)
6788 strcat (buf, "{,n %0,%3|,n %0,%%sar,%3}");
6789 else if (nullify && ! negated)
6790 strcat (buf, "{,n %0,%2|,n %0,%%sar,%2}");
6791 else if (! nullify && negated)
6792 strcat (buf, "{%0,%3|%0,%%sar,%3}");
6793 else if (! nullify && ! negated)
6794 strcat (buf, "{ %0,%2| %0,%%sar,%2}");
6795 break;
6797 /* All long conditionals. Note a short backward branch with an
6798 unfilled delay slot is treated just like a long backward branch
6799 with an unfilled delay slot. */
6800 case 8:
6801 /* Handle weird backwards branch with a filled delay slot
6802 with is nullified. */
6803 if (dbr_sequence_length () != 0
6804 && ! forward_branch_p (insn)
6805 && nullify)
6807 strcpy (buf, "{bvb,|bb,}");
6808 if (GET_MODE (operands[0]) == DImode)
6809 strcat (buf, "*");
6810 if ((which == 0 && negated)
6811 || (which == 1 && ! negated))
6812 strcat (buf, "<");
6813 else
6814 strcat (buf, ">=");
6815 if (negated)
6816 strcat (buf, "{,n %0,.+12\n\tb %3|,n %0,%%sar,.+12\n\tb %3}");
6817 else
6818 strcat (buf, "{,n %0,.+12\n\tb %2|,n %0,%%sar,.+12\n\tb %2}");
6820 /* Handle short backwards branch with an unfilled delay slot.
6821 Using a bb;nop rather than extrs;bl saves 1 cycle for both
6822 taken and untaken branches. */
6823 else if (dbr_sequence_length () == 0
6824 && ! forward_branch_p (insn)
6825 && INSN_ADDRESSES_SET_P ()
6826 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6827 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6829 strcpy (buf, "{bvb,|bb,}");
6830 if (GET_MODE (operands[0]) == DImode)
6831 strcat (buf, "*");
6832 if ((which == 0 && negated)
6833 || (which == 1 && ! negated))
6834 strcat (buf, ">=");
6835 else
6836 strcat (buf, "<");
6837 if (negated)
6838 strcat (buf, "{ %0,%3%#| %0,%%sar,%3%#}");
6839 else
6840 strcat (buf, "{ %0,%2%#| %0,%%sar,%2%#}");
6842 else
6844 strcpy (buf, "{vextrs,|extrw,s,}");
6845 if (GET_MODE (operands[0]) == DImode)
6846 strcpy (buf, "extrd,s,*");
6847 if ((which == 0 && negated)
6848 || (which == 1 && ! negated))
6849 strcat (buf, "<");
6850 else
6851 strcat (buf, ">=");
6852 if (nullify && negated)
6853 strcat (buf, "{ %0,1,%%r0\n\tb,n %3| %0,%%sar,1,%%r0\n\tb,n %3}");
6854 else if (nullify && ! negated)
6855 strcat (buf, "{ %0,1,%%r0\n\tb,n %2| %0,%%sar,1,%%r0\n\tb,n %2}");
6856 else if (negated)
6857 strcat (buf, "{ %0,1,%%r0\n\tb %3| %0,%%sar,1,%%r0\n\tb %3}");
6858 else
6859 strcat (buf, "{ %0,1,%%r0\n\tb %2| %0,%%sar,1,%%r0\n\tb %2}");
6861 break;
6863 default:
6864 abort ();
6866 return buf;
6869 /* Return the output template for emitting a dbra type insn.
6871 Note it may perform some output operations on its own before
6872 returning the final output string. */
6873 const char *
6874 output_dbra (rtx *operands, rtx insn, int which_alternative)
6877 /* A conditional branch to the following instruction (e.g. the delay slot) is
6878 asking for a disaster. Be prepared! */
6880 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6882 if (which_alternative == 0)
6883 return "ldo %1(%0),%0";
6884 else if (which_alternative == 1)
6886 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)", operands);
6887 output_asm_insn ("ldw -16(%%r30),%4", operands);
6888 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
6889 return "{fldws|fldw} -16(%%r30),%0";
6891 else
6893 output_asm_insn ("ldw %0,%4", operands);
6894 return "ldo %1(%4),%4\n\tstw %4,%0";
6898 if (which_alternative == 0)
6900 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6901 int length = get_attr_length (insn);
6903 /* If this is a long branch with its delay slot unfilled, set `nullify'
6904 as it can nullify the delay slot and save a nop. */
6905 if (length == 8 && dbr_sequence_length () == 0)
6906 nullify = 1;
6908 /* If this is a short forward conditional branch which did not get
6909 its delay slot filled, the delay slot can still be nullified. */
6910 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6911 nullify = forward_branch_p (insn);
6913 /* Handle short versions first. */
6914 if (length == 4 && nullify)
6915 return "addib,%C2,n %1,%0,%3";
6916 else if (length == 4 && ! nullify)
6917 return "addib,%C2 %1,%0,%3";
6918 else if (length == 8)
6920 /* Handle weird backwards branch with a fulled delay slot
6921 which is nullified. */
6922 if (dbr_sequence_length () != 0
6923 && ! forward_branch_p (insn)
6924 && nullify)
6925 return "addib,%N2,n %1,%0,.+12\n\tb %3";
6926 /* Handle short backwards branch with an unfilled delay slot.
6927 Using a addb;nop rather than addi;bl saves 1 cycle for both
6928 taken and untaken branches. */
6929 else if (dbr_sequence_length () == 0
6930 && ! forward_branch_p (insn)
6931 && INSN_ADDRESSES_SET_P ()
6932 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6933 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6934 return "addib,%C2 %1,%0,%3%#";
6936 /* Handle normal cases. */
6937 if (nullify)
6938 return "addi,%N2 %1,%0,%0\n\tb,n %3";
6939 else
6940 return "addi,%N2 %1,%0,%0\n\tb %3";
6942 else
6943 abort ();
6945 /* Deal with gross reload from FP register case. */
6946 else if (which_alternative == 1)
6948 /* Move loop counter from FP register to MEM then into a GR,
6949 increment the GR, store the GR into MEM, and finally reload
6950 the FP register from MEM from within the branch's delay slot. */
6951 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)\n\tldw -16(%%r30),%4",
6952 operands);
6953 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
6954 if (get_attr_length (insn) == 24)
6955 return "{comb|cmpb},%S2 %%r0,%4,%3\n\t{fldws|fldw} -16(%%r30),%0";
6956 else
6957 return "{comclr|cmpclr},%B2 %%r0,%4,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
6959 /* Deal with gross reload from memory case. */
6960 else
6962 /* Reload loop counter from memory, the store back to memory
6963 happens in the branch's delay slot. */
6964 output_asm_insn ("ldw %0,%4", operands);
6965 if (get_attr_length (insn) == 12)
6966 return "addib,%C2 %1,%4,%3\n\tstw %4,%0";
6967 else
6968 return "addi,%N2 %1,%4,%4\n\tb %3\n\tstw %4,%0";
6972 /* Return the output template for emitting a dbra type insn.
6974 Note it may perform some output operations on its own before
6975 returning the final output string. */
6976 const char *
6977 output_movb (rtx *operands, rtx insn, int which_alternative,
6978 int reverse_comparison)
6981 /* A conditional branch to the following instruction (e.g. the delay slot) is
6982 asking for a disaster. Be prepared! */
6984 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6986 if (which_alternative == 0)
6987 return "copy %1,%0";
6988 else if (which_alternative == 1)
6990 output_asm_insn ("stw %1,-16(%%r30)", operands);
6991 return "{fldws|fldw} -16(%%r30),%0";
6993 else if (which_alternative == 2)
6994 return "stw %1,%0";
6995 else
6996 return "mtsar %r1";
6999 /* Support the second variant. */
7000 if (reverse_comparison)
7001 PUT_CODE (operands[2], reverse_condition (GET_CODE (operands[2])));
7003 if (which_alternative == 0)
7005 int nullify = INSN_ANNULLED_BRANCH_P (insn);
7006 int length = get_attr_length (insn);
7008 /* If this is a long branch with its delay slot unfilled, set `nullify'
7009 as it can nullify the delay slot and save a nop. */
7010 if (length == 8 && dbr_sequence_length () == 0)
7011 nullify = 1;
7013 /* If this is a short forward conditional branch which did not get
7014 its delay slot filled, the delay slot can still be nullified. */
7015 if (! nullify && length == 4 && dbr_sequence_length () == 0)
7016 nullify = forward_branch_p (insn);
7018 /* Handle short versions first. */
7019 if (length == 4 && nullify)
7020 return "movb,%C2,n %1,%0,%3";
7021 else if (length == 4 && ! nullify)
7022 return "movb,%C2 %1,%0,%3";
7023 else if (length == 8)
7025 /* Handle weird backwards branch with a filled delay slot
7026 which is nullified. */
7027 if (dbr_sequence_length () != 0
7028 && ! forward_branch_p (insn)
7029 && nullify)
7030 return "movb,%N2,n %1,%0,.+12\n\tb %3";
7032 /* Handle short backwards branch with an unfilled delay slot.
7033 Using a movb;nop rather than or;bl saves 1 cycle for both
7034 taken and untaken branches. */
7035 else if (dbr_sequence_length () == 0
7036 && ! forward_branch_p (insn)
7037 && INSN_ADDRESSES_SET_P ()
7038 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
7039 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
7040 return "movb,%C2 %1,%0,%3%#";
7041 /* Handle normal cases. */
7042 if (nullify)
7043 return "or,%N2 %1,%%r0,%0\n\tb,n %3";
7044 else
7045 return "or,%N2 %1,%%r0,%0\n\tb %3";
7047 else
7048 abort ();
7050 /* Deal with gross reload from FP register case. */
7051 else if (which_alternative == 1)
7053 /* Move loop counter from FP register to MEM then into a GR,
7054 increment the GR, store the GR into MEM, and finally reload
7055 the FP register from MEM from within the branch's delay slot. */
7056 output_asm_insn ("stw %1,-16(%%r30)", operands);
7057 if (get_attr_length (insn) == 12)
7058 return "{comb|cmpb},%S2 %%r0,%1,%3\n\t{fldws|fldw} -16(%%r30),%0";
7059 else
7060 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
7062 /* Deal with gross reload from memory case. */
7063 else if (which_alternative == 2)
7065 /* Reload loop counter from memory, the store back to memory
7066 happens in the branch's delay slot. */
7067 if (get_attr_length (insn) == 8)
7068 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tstw %1,%0";
7069 else
7070 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tstw %1,%0";
7072 /* Handle SAR as a destination. */
7073 else
7075 if (get_attr_length (insn) == 8)
7076 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tmtsar %r1";
7077 else
7078 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tmtsar %r1";
7082 /* Copy any FP arguments in INSN into integer registers. */
7083 static void
7084 copy_fp_args (rtx insn)
7086 rtx link;
7087 rtx xoperands[2];
7089 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7091 int arg_mode, regno;
7092 rtx use = XEXP (link, 0);
7094 if (! (GET_CODE (use) == USE
7095 && GET_CODE (XEXP (use, 0)) == REG
7096 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7097 continue;
7099 arg_mode = GET_MODE (XEXP (use, 0));
7100 regno = REGNO (XEXP (use, 0));
7102 /* Is it a floating point register? */
7103 if (regno >= 32 && regno <= 39)
7105 /* Copy the FP register into an integer register via memory. */
7106 if (arg_mode == SFmode)
7108 xoperands[0] = XEXP (use, 0);
7109 xoperands[1] = gen_rtx_REG (SImode, 26 - (regno - 32) / 2);
7110 output_asm_insn ("{fstws|fstw} %0,-16(%%sr0,%%r30)", xoperands);
7111 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7113 else
7115 xoperands[0] = XEXP (use, 0);
7116 xoperands[1] = gen_rtx_REG (DImode, 25 - (regno - 34) / 2);
7117 output_asm_insn ("{fstds|fstd} %0,-16(%%sr0,%%r30)", xoperands);
7118 output_asm_insn ("ldw -12(%%sr0,%%r30),%R1", xoperands);
7119 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
7125 /* Compute length of the FP argument copy sequence for INSN. */
7126 static int
7127 length_fp_args (rtx insn)
7129 int length = 0;
7130 rtx link;
7132 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7134 int arg_mode, regno;
7135 rtx use = XEXP (link, 0);
7137 if (! (GET_CODE (use) == USE
7138 && GET_CODE (XEXP (use, 0)) == REG
7139 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7140 continue;
7142 arg_mode = GET_MODE (XEXP (use, 0));
7143 regno = REGNO (XEXP (use, 0));
7145 /* Is it a floating point register? */
7146 if (regno >= 32 && regno <= 39)
7148 if (arg_mode == SFmode)
7149 length += 8;
7150 else
7151 length += 12;
7155 return length;
7158 /* Return the attribute length for the millicode call instruction INSN.
7159 The length must match the code generated by output_millicode_call.
7160 We include the delay slot in the returned length as it is better to
7161 over estimate the length than to under estimate it. */
7164 attr_length_millicode_call (rtx insn)
7166 unsigned long distance = -1;
7167 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7169 if (INSN_ADDRESSES_SET_P ())
7171 distance = (total + insn_current_reference_address (insn));
7172 if (distance < total)
7173 distance = -1;
7176 if (TARGET_64BIT)
7178 if (!TARGET_LONG_CALLS && distance < 7600000)
7179 return 8;
7181 return 20;
7183 else if (TARGET_PORTABLE_RUNTIME)
7184 return 24;
7185 else
7187 if (!TARGET_LONG_CALLS && distance < 240000)
7188 return 8;
7190 if (TARGET_LONG_ABS_CALL && !flag_pic)
7191 return 12;
7193 return 24;
7197 /* INSN is a function call. It may have an unconditional jump
7198 in its delay slot.
7200 CALL_DEST is the routine we are calling. */
7202 const char *
7203 output_millicode_call (rtx insn, rtx call_dest)
7205 int attr_length = get_attr_length (insn);
7206 int seq_length = dbr_sequence_length ();
7207 int distance;
7208 rtx seq_insn;
7209 rtx xoperands[3];
7211 xoperands[0] = call_dest;
7212 xoperands[2] = gen_rtx_REG (Pmode, TARGET_64BIT ? 2 : 31);
7214 /* Handle the common case where we are sure that the branch will
7215 reach the beginning of the $CODE$ subspace. The within reach
7216 form of the $$sh_func_adrs call has a length of 28. Because
7217 it has an attribute type of multi, it never has a nonzero
7218 sequence length. The length of the $$sh_func_adrs is the same
7219 as certain out of reach PIC calls to other routines. */
7220 if (!TARGET_LONG_CALLS
7221 && ((seq_length == 0
7222 && (attr_length == 12
7223 || (attr_length == 28 && get_attr_type (insn) == TYPE_MULTI)))
7224 || (seq_length != 0 && attr_length == 8)))
7226 output_asm_insn ("{bl|b,l} %0,%2", xoperands);
7228 else
7230 if (TARGET_64BIT)
7232 /* It might seem that one insn could be saved by accessing
7233 the millicode function using the linkage table. However,
7234 this doesn't work in shared libraries and other dynamically
7235 loaded objects. Using a pc-relative sequence also avoids
7236 problems related to the implicit use of the gp register. */
7237 output_asm_insn ("b,l .+8,%%r1", xoperands);
7239 if (TARGET_GAS)
7241 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
7242 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
7244 else
7246 xoperands[1] = gen_label_rtx ();
7247 output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7248 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7249 CODE_LABEL_NUMBER (xoperands[1]));
7250 output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7253 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7255 else if (TARGET_PORTABLE_RUNTIME)
7257 /* Pure portable runtime doesn't allow be/ble; we also don't
7258 have PIC support in the assembler/linker, so this sequence
7259 is needed. */
7261 /* Get the address of our target into %r1. */
7262 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7263 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
7265 /* Get our return address into %r31. */
7266 output_asm_insn ("{bl|b,l} .+8,%%r31", xoperands);
7267 output_asm_insn ("addi 8,%%r31,%%r31", xoperands);
7269 /* Jump to our target address in %r1. */
7270 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7272 else if (!flag_pic)
7274 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7275 if (TARGET_PA_20)
7276 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31", xoperands);
7277 else
7278 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
7280 else
7282 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7283 output_asm_insn ("addi 16,%%r1,%%r31", xoperands);
7285 if (TARGET_SOM || !TARGET_GAS)
7287 /* The HP assembler can generate relocations for the
7288 difference of two symbols. GAS can do this for a
7289 millicode symbol but not an arbitrary external
7290 symbol when generating SOM output. */
7291 xoperands[1] = gen_label_rtx ();
7292 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7293 CODE_LABEL_NUMBER (xoperands[1]));
7294 output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7295 output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7297 else
7299 output_asm_insn ("addil L'%0-$PIC_pcrel$0+8,%%r1", xoperands);
7300 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+12(%%r1),%%r1",
7301 xoperands);
7304 /* Jump to our target address in %r1. */
7305 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7309 if (seq_length == 0)
7310 output_asm_insn ("nop", xoperands);
7312 /* We are done if there isn't a jump in the delay slot. */
7313 if (seq_length == 0 || GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
7314 return "";
7316 /* This call has an unconditional jump in its delay slot. */
7317 xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
7319 /* See if the return address can be adjusted. Use the containing
7320 sequence insn's address. */
7321 if (INSN_ADDRESSES_SET_P ())
7323 seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
7324 distance = (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
7325 - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8);
7327 if (VAL_14_BITS_P (distance))
7329 xoperands[1] = gen_label_rtx ();
7330 output_asm_insn ("ldo %0-%1(%2),%2", xoperands);
7331 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7332 CODE_LABEL_NUMBER (xoperands[1]));
7334 else
7335 /* ??? This branch may not reach its target. */
7336 output_asm_insn ("nop\n\tb,n %0", xoperands);
7338 else
7339 /* ??? This branch may not reach its target. */
7340 output_asm_insn ("nop\n\tb,n %0", xoperands);
7342 /* Delete the jump. */
7343 PUT_CODE (NEXT_INSN (insn), NOTE);
7344 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7345 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7347 return "";
7350 /* Return the attribute length of the call instruction INSN. The SIBCALL
7351 flag indicates whether INSN is a regular call or a sibling call. The
7352 length returned must be longer than the code actually generated by
7353 output_call. Since branch shortening is done before delay branch
7354 sequencing, there is no way to determine whether or not the delay
7355 slot will be filled during branch shortening. Even when the delay
7356 slot is filled, we may have to add a nop if the delay slot contains
7357 a branch that can't reach its target. Thus, we always have to include
7358 the delay slot in the length estimate. This used to be done in
7359 pa_adjust_insn_length but we do it here now as some sequences always
7360 fill the delay slot and we can save four bytes in the estimate for
7361 these sequences. */
7364 attr_length_call (rtx insn, int sibcall)
7366 int local_call;
7367 rtx call_dest;
7368 tree call_decl;
7369 int length = 0;
7370 rtx pat = PATTERN (insn);
7371 unsigned long distance = -1;
7373 if (INSN_ADDRESSES_SET_P ())
7375 unsigned long total;
7377 total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7378 distance = (total + insn_current_reference_address (insn));
7379 if (distance < total)
7380 distance = -1;
7383 /* Determine if this is a local call. */
7384 if (GET_CODE (XVECEXP (pat, 0, 0)) == CALL)
7385 call_dest = XEXP (XEXP (XVECEXP (pat, 0, 0), 0), 0);
7386 else
7387 call_dest = XEXP (XEXP (XEXP (XVECEXP (pat, 0, 0), 1), 0), 0);
7389 call_decl = SYMBOL_REF_DECL (call_dest);
7390 local_call = call_decl && (*targetm.binds_local_p) (call_decl);
7392 /* pc-relative branch. */
7393 if (!TARGET_LONG_CALLS
7394 && ((TARGET_PA_20 && !sibcall && distance < 7600000)
7395 || distance < 240000))
7396 length += 8;
7398 /* 64-bit plabel sequence. */
7399 else if (TARGET_64BIT && !local_call)
7400 length += sibcall ? 28 : 24;
7402 /* non-pic long absolute branch sequence. */
7403 else if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7404 length += 12;
7406 /* long pc-relative branch sequence. */
7407 else if ((TARGET_SOM && TARGET_LONG_PIC_SDIFF_CALL)
7408 || (TARGET_64BIT && !TARGET_GAS)
7409 || (TARGET_GAS && (TARGET_LONG_PIC_PCREL_CALL || local_call)))
7411 length += 20;
7413 if (!TARGET_PA_20 && !TARGET_NO_SPACE_REGS)
7414 length += 8;
7417 /* 32-bit plabel sequence. */
7418 else
7420 length += 32;
7422 if (TARGET_SOM)
7423 length += length_fp_args (insn);
7425 if (flag_pic)
7426 length += 4;
7428 if (!TARGET_PA_20)
7430 if (!sibcall)
7431 length += 8;
7433 if (!TARGET_NO_SPACE_REGS)
7434 length += 8;
7438 return length;
7441 /* INSN is a function call. It may have an unconditional jump
7442 in its delay slot.
7444 CALL_DEST is the routine we are calling. */
7446 const char *
7447 output_call (rtx insn, rtx call_dest, int sibcall)
7449 int delay_insn_deleted = 0;
7450 int delay_slot_filled = 0;
7451 int seq_length = dbr_sequence_length ();
7452 tree call_decl = SYMBOL_REF_DECL (call_dest);
7453 int local_call = call_decl && (*targetm.binds_local_p) (call_decl);
7454 rtx xoperands[2];
7456 xoperands[0] = call_dest;
7458 /* Handle the common case where we're sure that the branch will reach
7459 the beginning of the "$CODE$" subspace. This is the beginning of
7460 the current function if we are in a named section. */
7461 if (!TARGET_LONG_CALLS && attr_length_call (insn, sibcall) == 8)
7463 xoperands[1] = gen_rtx_REG (word_mode, sibcall ? 0 : 2);
7464 output_asm_insn ("{bl|b,l} %0,%1", xoperands);
7466 else
7468 if (TARGET_64BIT && !local_call)
7470 /* ??? As far as I can tell, the HP linker doesn't support the
7471 long pc-relative sequence described in the 64-bit runtime
7472 architecture. So, we use a slightly longer indirect call. */
7473 struct deferred_plabel *p = get_plabel (XSTR (call_dest, 0));
7475 xoperands[0] = p->internal_label;
7476 xoperands[1] = gen_label_rtx ();
7478 /* If this isn't a sibcall, we put the load of %r27 into the
7479 delay slot. We can't do this in a sibcall as we don't
7480 have a second call-clobbered scratch register available. */
7481 if (seq_length != 0
7482 && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
7483 && !sibcall)
7485 final_scan_insn (NEXT_INSN (insn), asm_out_file,
7486 optimize, 0, 0, NULL);
7488 /* Now delete the delay insn. */
7489 PUT_CODE (NEXT_INSN (insn), NOTE);
7490 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7491 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7492 delay_insn_deleted = 1;
7495 output_asm_insn ("addil LT'%0,%%r27", xoperands);
7496 output_asm_insn ("ldd RT'%0(%%r1),%%r1", xoperands);
7497 output_asm_insn ("ldd 0(%%r1),%%r1", xoperands);
7499 if (sibcall)
7501 output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7502 output_asm_insn ("ldd 16(%%r1),%%r1", xoperands);
7503 output_asm_insn ("bve (%%r1)", xoperands);
7505 else
7507 output_asm_insn ("ldd 16(%%r1),%%r2", xoperands);
7508 output_asm_insn ("bve,l (%%r2),%%r2", xoperands);
7509 output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7510 delay_slot_filled = 1;
7513 else
7515 int indirect_call = 0;
7517 /* Emit a long call. There are several different sequences
7518 of increasing length and complexity. In most cases,
7519 they don't allow an instruction in the delay slot. */
7520 if (!((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7521 && !(TARGET_SOM && TARGET_LONG_PIC_SDIFF_CALL)
7522 && !(TARGET_GAS && (TARGET_LONG_PIC_PCREL_CALL || local_call))
7523 && !TARGET_64BIT)
7524 indirect_call = 1;
7526 if (seq_length != 0
7527 && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
7528 && !sibcall
7529 && (!TARGET_PA_20 || indirect_call))
7531 /* A non-jump insn in the delay slot. By definition we can
7532 emit this insn before the call (and in fact before argument
7533 relocating. */
7534 final_scan_insn (NEXT_INSN (insn), asm_out_file, optimize, 0, 0,
7535 NULL);
7537 /* Now delete the delay insn. */
7538 PUT_CODE (NEXT_INSN (insn), NOTE);
7539 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7540 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7541 delay_insn_deleted = 1;
7544 if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7546 /* This is the best sequence for making long calls in
7547 non-pic code. Unfortunately, GNU ld doesn't provide
7548 the stub needed for external calls, and GAS's support
7549 for this with the SOM linker is buggy. It is safe
7550 to use this for local calls. */
7551 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7552 if (sibcall)
7553 output_asm_insn ("be R'%0(%%sr4,%%r1)", xoperands);
7554 else
7556 if (TARGET_PA_20)
7557 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31",
7558 xoperands);
7559 else
7560 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
7562 output_asm_insn ("copy %%r31,%%r2", xoperands);
7563 delay_slot_filled = 1;
7566 else
7568 if ((TARGET_SOM && TARGET_LONG_PIC_SDIFF_CALL)
7569 || (TARGET_64BIT && !TARGET_GAS))
7571 /* The HP assembler and linker can handle relocations
7572 for the difference of two symbols. GAS and the HP
7573 linker can't do this when one of the symbols is
7574 external. */
7575 xoperands[1] = gen_label_rtx ();
7576 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7577 output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7578 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7579 CODE_LABEL_NUMBER (xoperands[1]));
7580 output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7582 else if (TARGET_GAS && (TARGET_LONG_PIC_PCREL_CALL || local_call))
7584 /* GAS currently can't generate the relocations that
7585 are needed for the SOM linker under HP-UX using this
7586 sequence. The GNU linker doesn't generate the stubs
7587 that are needed for external calls on TARGET_ELF32
7588 with this sequence. For now, we have to use a
7589 longer plabel sequence when using GAS. */
7590 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7591 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1",
7592 xoperands);
7593 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1",
7594 xoperands);
7596 else
7598 /* Emit a long plabel-based call sequence. This is
7599 essentially an inline implementation of $$dyncall.
7600 We don't actually try to call $$dyncall as this is
7601 as difficult as calling the function itself. */
7602 struct deferred_plabel *p = get_plabel (XSTR (call_dest, 0));
7604 xoperands[0] = p->internal_label;
7605 xoperands[1] = gen_label_rtx ();
7607 /* Since the call is indirect, FP arguments in registers
7608 need to be copied to the general registers. Then, the
7609 argument relocation stub will copy them back. */
7610 if (TARGET_SOM)
7611 copy_fp_args (insn);
7613 if (flag_pic)
7615 output_asm_insn ("addil LT'%0,%%r19", xoperands);
7616 output_asm_insn ("ldw RT'%0(%%r1),%%r1", xoperands);
7617 output_asm_insn ("ldw 0(%%r1),%%r1", xoperands);
7619 else
7621 output_asm_insn ("addil LR'%0-$global$,%%r27",
7622 xoperands);
7623 output_asm_insn ("ldw RR'%0-$global$(%%r1),%%r1",
7624 xoperands);
7627 output_asm_insn ("bb,>=,n %%r1,30,.+16", xoperands);
7628 output_asm_insn ("depi 0,31,2,%%r1", xoperands);
7629 output_asm_insn ("ldw 4(%%sr0,%%r1),%%r19", xoperands);
7630 output_asm_insn ("ldw 0(%%sr0,%%r1),%%r1", xoperands);
7632 if (!sibcall && !TARGET_PA_20)
7634 output_asm_insn ("{bl|b,l} .+8,%%r2", xoperands);
7635 if (TARGET_NO_SPACE_REGS)
7636 output_asm_insn ("addi 8,%%r2,%%r2", xoperands);
7637 else
7638 output_asm_insn ("addi 16,%%r2,%%r2", xoperands);
7642 if (TARGET_PA_20)
7644 if (sibcall)
7645 output_asm_insn ("bve (%%r1)", xoperands);
7646 else
7648 if (indirect_call)
7650 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7651 output_asm_insn ("stw %%r2,-24(%%sp)", xoperands);
7652 delay_slot_filled = 1;
7654 else
7655 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7658 else
7660 if (!TARGET_NO_SPACE_REGS)
7661 output_asm_insn ("ldsid (%%r1),%%r31\n\tmtsp %%r31,%%sr0",
7662 xoperands);
7664 if (sibcall)
7666 if (TARGET_NO_SPACE_REGS)
7667 output_asm_insn ("be 0(%%sr4,%%r1)", xoperands);
7668 else
7669 output_asm_insn ("be 0(%%sr0,%%r1)", xoperands);
7671 else
7673 if (TARGET_NO_SPACE_REGS)
7674 output_asm_insn ("ble 0(%%sr4,%%r1)", xoperands);
7675 else
7676 output_asm_insn ("ble 0(%%sr0,%%r1)", xoperands);
7678 if (indirect_call)
7679 output_asm_insn ("stw %%r31,-24(%%sp)", xoperands);
7680 else
7681 output_asm_insn ("copy %%r31,%%r2", xoperands);
7682 delay_slot_filled = 1;
7689 if (!delay_slot_filled && (seq_length == 0 || delay_insn_deleted))
7690 output_asm_insn ("nop", xoperands);
7692 /* We are done if there isn't a jump in the delay slot. */
7693 if (seq_length == 0
7694 || delay_insn_deleted
7695 || GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
7696 return "";
7698 /* A sibcall should never have a branch in the delay slot. */
7699 if (sibcall)
7700 abort ();
7702 /* This call has an unconditional jump in its delay slot. */
7703 xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
7705 if (!delay_slot_filled && INSN_ADDRESSES_SET_P ())
7707 /* See if the return address can be adjusted. Use the containing
7708 sequence insn's address. */
7709 rtx seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
7710 int distance = (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
7711 - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8);
7713 if (VAL_14_BITS_P (distance))
7715 xoperands[1] = gen_label_rtx ();
7716 output_asm_insn ("ldo %0-%1(%%r2),%%r2", xoperands);
7717 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7718 CODE_LABEL_NUMBER (xoperands[1]));
7720 else
7721 output_asm_insn ("nop\n\tb,n %0", xoperands);
7723 else
7724 output_asm_insn ("b,n %0", xoperands);
7726 /* Delete the jump. */
7727 PUT_CODE (NEXT_INSN (insn), NOTE);
7728 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7729 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7731 return "";
7734 /* Return the attribute length of the indirect call instruction INSN.
7735 The length must match the code generated by output_indirect call.
7736 The returned length includes the delay slot. Currently, the delay
7737 slot of an indirect call sequence is not exposed and it is used by
7738 the sequence itself. */
7741 attr_length_indirect_call (rtx insn)
7743 unsigned long distance = -1;
7744 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7746 if (INSN_ADDRESSES_SET_P ())
7748 distance = (total + insn_current_reference_address (insn));
7749 if (distance < total)
7750 distance = -1;
7753 if (TARGET_64BIT)
7754 return 12;
7756 if (TARGET_FAST_INDIRECT_CALLS
7757 || (!TARGET_PORTABLE_RUNTIME
7758 && ((TARGET_PA_20 && distance < 7600000) || distance < 240000)))
7759 return 8;
7761 if (flag_pic)
7762 return 24;
7764 if (TARGET_PORTABLE_RUNTIME)
7765 return 20;
7767 /* Out of reach, can use ble. */
7768 return 12;
7771 const char *
7772 output_indirect_call (rtx insn, rtx call_dest)
7774 rtx xoperands[1];
7776 if (TARGET_64BIT)
7778 xoperands[0] = call_dest;
7779 output_asm_insn ("ldd 16(%0),%%r2", xoperands);
7780 output_asm_insn ("bve,l (%%r2),%%r2\n\tldd 24(%0),%%r27", xoperands);
7781 return "";
7784 /* First the special case for kernels, level 0 systems, etc. */
7785 if (TARGET_FAST_INDIRECT_CALLS)
7786 return "ble 0(%%sr4,%%r22)\n\tcopy %%r31,%%r2";
7788 /* Now the normal case -- we can reach $$dyncall directly or
7789 we're sure that we can get there via a long-branch stub.
7791 No need to check target flags as the length uniquely identifies
7792 the remaining cases. */
7793 if (attr_length_indirect_call (insn) == 8)
7795 /* The HP linker substitutes a BLE for millicode calls using
7796 the short PIC PCREL form. Thus, we must use %r31 as the
7797 link register when generating PA 1.x code. */
7798 if (TARGET_PA_20)
7799 return ".CALL\tARGW0=GR\n\tb,l $$dyncall,%%r2\n\tcopy %%r2,%%r31";
7800 else
7801 return ".CALL\tARGW0=GR\n\tbl $$dyncall,%%r31\n\tcopy %%r31,%%r2";
7804 /* Long millicode call, but we are not generating PIC or portable runtime
7805 code. */
7806 if (attr_length_indirect_call (insn) == 12)
7807 return ".CALL\tARGW0=GR\n\tldil L'$$dyncall,%%r2\n\tble R'$$dyncall(%%sr4,%%r2)\n\tcopy %%r31,%%r2";
7809 /* Long millicode call for portable runtime. */
7810 if (attr_length_indirect_call (insn) == 20)
7811 return "ldil L'$$dyncall,%%r31\n\tldo R'$$dyncall(%%r31),%%r31\n\tblr %%r0,%%r2\n\tbv,n %%r0(%%r31)\n\tnop";
7813 /* We need a long PIC call to $$dyncall. */
7814 xoperands[0] = NULL_RTX;
7815 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7816 if (TARGET_SOM || !TARGET_GAS)
7818 xoperands[0] = gen_label_rtx ();
7819 output_asm_insn ("addil L'$$dyncall-%0,%%r1", xoperands);
7820 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7821 CODE_LABEL_NUMBER (xoperands[0]));
7822 output_asm_insn ("ldo R'$$dyncall-%0(%%r1),%%r1", xoperands);
7824 else
7826 output_asm_insn ("addil L'$$dyncall-$PIC_pcrel$0+4,%%r1", xoperands);
7827 output_asm_insn ("ldo R'$$dyncall-$PIC_pcrel$0+8(%%r1),%%r1",
7828 xoperands);
7830 output_asm_insn ("blr %%r0,%%r2", xoperands);
7831 output_asm_insn ("bv,n %%r0(%%r1)\n\tnop", xoperands);
7832 return "";
7835 /* Return the total length of the save and restore instructions needed for
7836 the data linkage table pointer (i.e., the PIC register) across the call
7837 instruction INSN. No-return calls do not require a save and restore.
7838 In addition, we may be able to avoid the save and restore for calls
7839 within the same translation unit. */
7842 attr_length_save_restore_dltp (rtx insn)
7844 if (find_reg_note (insn, REG_NORETURN, NULL_RTX))
7845 return 0;
7847 return 8;
7850 /* In HPUX 8.0's shared library scheme, special relocations are needed
7851 for function labels if they might be passed to a function
7852 in a shared library (because shared libraries don't live in code
7853 space), and special magic is needed to construct their address. */
7855 void
7856 hppa_encode_label (rtx sym)
7858 const char *str = XSTR (sym, 0);
7859 int len = strlen (str) + 1;
7860 char *newstr, *p;
7862 p = newstr = alloca (len + 1);
7863 *p++ = '@';
7864 strcpy (p, str);
7866 XSTR (sym, 0) = ggc_alloc_string (newstr, len);
7869 static void
7870 pa_encode_section_info (tree decl, rtx rtl, int first)
7872 if (first && TEXT_SPACE_P (decl))
7874 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
7875 if (TREE_CODE (decl) == FUNCTION_DECL)
7876 hppa_encode_label (XEXP (rtl, 0));
7880 /* This is sort of inverse to pa_encode_section_info. */
7882 static const char *
7883 pa_strip_name_encoding (const char *str)
7885 str += (*str == '@');
7886 str += (*str == '*');
7887 return str;
7891 function_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
7893 return GET_CODE (op) == SYMBOL_REF && FUNCTION_NAME_P (XSTR (op, 0));
7896 /* Returns 1 if OP is a function label involved in a simple addition
7897 with a constant. Used to keep certain patterns from matching
7898 during instruction combination. */
7900 is_function_label_plus_const (rtx op)
7902 /* Strip off any CONST. */
7903 if (GET_CODE (op) == CONST)
7904 op = XEXP (op, 0);
7906 return (GET_CODE (op) == PLUS
7907 && function_label_operand (XEXP (op, 0), Pmode)
7908 && GET_CODE (XEXP (op, 1)) == CONST_INT);
7911 /* Output assembly code for a thunk to FUNCTION. */
7913 static void
7914 pa_asm_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
7915 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
7916 tree function)
7918 static unsigned int current_thunk_number;
7919 int val_14 = VAL_14_BITS_P (delta);
7920 int nbytes = 0;
7921 char label[16];
7922 rtx xoperands[4];
7924 xoperands[0] = XEXP (DECL_RTL (function), 0);
7925 xoperands[1] = XEXP (DECL_RTL (thunk_fndecl), 0);
7926 xoperands[2] = GEN_INT (delta);
7928 ASM_OUTPUT_LABEL (file, XSTR (xoperands[1], 0));
7929 fprintf (file, "\t.PROC\n\t.CALLINFO FRAME=0,NO_CALLS\n\t.ENTRY\n");
7931 /* Output the thunk. We know that the function is in the same
7932 translation unit (i.e., the same space) as the thunk, and that
7933 thunks are output after their method. Thus, we don't need an
7934 external branch to reach the function. With SOM and GAS,
7935 functions and thunks are effectively in different sections.
7936 Thus, we can always use a IA-relative branch and the linker
7937 will add a long branch stub if necessary.
7939 However, we have to be careful when generating PIC code on the
7940 SOM port to ensure that the sequence does not transfer to an
7941 import stub for the target function as this could clobber the
7942 return value saved at SP-24. This would also apply to the
7943 32-bit linux port if the multi-space model is implemented. */
7944 if ((!TARGET_LONG_CALLS && TARGET_SOM && !TARGET_PORTABLE_RUNTIME
7945 && !(flag_pic && TREE_PUBLIC (function))
7946 && (TARGET_GAS || last_address < 262132))
7947 || (!TARGET_LONG_CALLS && !TARGET_SOM && !TARGET_PORTABLE_RUNTIME
7948 && ((targetm.have_named_sections
7949 && DECL_SECTION_NAME (thunk_fndecl) != NULL
7950 /* The GNU 64-bit linker has rather poor stub management.
7951 So, we use a long branch from thunks that aren't in
7952 the same section as the target function. */
7953 && ((!TARGET_64BIT
7954 && (DECL_SECTION_NAME (thunk_fndecl)
7955 != DECL_SECTION_NAME (function)))
7956 || ((DECL_SECTION_NAME (thunk_fndecl)
7957 == DECL_SECTION_NAME (function))
7958 && last_address < 262132)))
7959 || (!targetm.have_named_sections && last_address < 262132))))
7961 if (!val_14)
7962 output_asm_insn ("addil L'%2,%%r26", xoperands);
7964 output_asm_insn ("b %0", xoperands);
7966 if (val_14)
7968 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
7969 nbytes += 8;
7971 else
7973 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
7974 nbytes += 12;
7977 else if (TARGET_64BIT)
7979 /* We only have one call-clobbered scratch register, so we can't
7980 make use of the delay slot if delta doesn't fit in 14 bits. */
7981 if (!val_14)
7983 output_asm_insn ("addil L'%2,%%r26", xoperands);
7984 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
7987 output_asm_insn ("b,l .+8,%%r1", xoperands);
7989 if (TARGET_GAS)
7991 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
7992 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
7994 else
7996 xoperands[3] = GEN_INT (val_14 ? 8 : 16);
7997 output_asm_insn ("addil L'%0-%1-%3,%%r1", xoperands);
8000 if (val_14)
8002 output_asm_insn ("bv %%r0(%%r1)", xoperands);
8003 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8004 nbytes += 20;
8006 else
8008 output_asm_insn ("bv,n %%r0(%%r1)", xoperands);
8009 nbytes += 24;
8012 else if (TARGET_PORTABLE_RUNTIME)
8014 output_asm_insn ("ldil L'%0,%%r1", xoperands);
8015 output_asm_insn ("ldo R'%0(%%r1),%%r22", xoperands);
8017 if (!val_14)
8018 output_asm_insn ("addil L'%2,%%r26", xoperands);
8020 output_asm_insn ("bv %%r0(%%r22)", xoperands);
8022 if (val_14)
8024 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8025 nbytes += 16;
8027 else
8029 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8030 nbytes += 20;
8033 else if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8035 /* The function is accessible from outside this module. The only
8036 way to avoid an import stub between the thunk and function is to
8037 call the function directly with an indirect sequence similar to
8038 that used by $$dyncall. This is possible because $$dyncall acts
8039 as the import stub in an indirect call. */
8040 ASM_GENERATE_INTERNAL_LABEL (label, "LTHN", current_thunk_number);
8041 xoperands[3] = gen_rtx_SYMBOL_REF (Pmode, label);
8042 output_asm_insn ("addil LT'%3,%%r19", xoperands);
8043 output_asm_insn ("ldw RT'%3(%%r1),%%r22", xoperands);
8044 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8045 output_asm_insn ("bb,>=,n %%r22,30,.+16", xoperands);
8046 output_asm_insn ("depi 0,31,2,%%r22", xoperands);
8047 output_asm_insn ("ldw 4(%%sr0,%%r22),%%r19", xoperands);
8048 output_asm_insn ("ldw 0(%%sr0,%%r22),%%r22", xoperands);
8050 if (!val_14)
8052 output_asm_insn ("addil L'%2,%%r26", xoperands);
8053 nbytes += 4;
8056 if (TARGET_PA_20)
8058 output_asm_insn ("bve (%%r22)", xoperands);
8059 nbytes += 36;
8061 else if (TARGET_NO_SPACE_REGS)
8063 output_asm_insn ("be 0(%%sr4,%%r22)", xoperands);
8064 nbytes += 36;
8066 else
8068 output_asm_insn ("ldsid (%%sr0,%%r22),%%r21", xoperands);
8069 output_asm_insn ("mtsp %%r21,%%sr0", xoperands);
8070 output_asm_insn ("be 0(%%sr0,%%r22)", xoperands);
8071 nbytes += 44;
8074 if (val_14)
8075 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8076 else
8077 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8079 else if (flag_pic)
8081 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
8083 if (TARGET_SOM || !TARGET_GAS)
8085 output_asm_insn ("addil L'%0-%1-8,%%r1", xoperands);
8086 output_asm_insn ("ldo R'%0-%1-8(%%r1),%%r22", xoperands);
8088 else
8090 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
8091 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r22", xoperands);
8094 if (!val_14)
8095 output_asm_insn ("addil L'%2,%%r26", xoperands);
8097 output_asm_insn ("bv %%r0(%%r22)", xoperands);
8099 if (val_14)
8101 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8102 nbytes += 20;
8104 else
8106 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8107 nbytes += 24;
8110 else
8112 if (!val_14)
8113 output_asm_insn ("addil L'%2,%%r26", xoperands);
8115 output_asm_insn ("ldil L'%0,%%r22", xoperands);
8116 output_asm_insn ("be R'%0(%%sr4,%%r22)", xoperands);
8118 if (val_14)
8120 output_asm_insn ("ldo %2(%%r26),%%r26", xoperands);
8121 nbytes += 12;
8123 else
8125 output_asm_insn ("ldo R'%2(%%r1),%%r26", xoperands);
8126 nbytes += 16;
8130 fprintf (file, "\t.EXIT\n\t.PROCEND\n");
8132 if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8134 data_section ();
8135 output_asm_insn (".align 4", xoperands);
8136 ASM_OUTPUT_LABEL (file, label);
8137 output_asm_insn (".word P'%0", xoperands);
8139 else if (TARGET_SOM && TARGET_GAS)
8140 forget_section ();
8142 current_thunk_number++;
8143 nbytes = ((nbytes + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
8144 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
8145 last_address += nbytes;
8146 update_total_code_bytes (nbytes);
8149 /* Only direct calls to static functions are allowed to be sibling (tail)
8150 call optimized.
8152 This restriction is necessary because some linker generated stubs will
8153 store return pointers into rp' in some cases which might clobber a
8154 live value already in rp'.
8156 In a sibcall the current function and the target function share stack
8157 space. Thus if the path to the current function and the path to the
8158 target function save a value in rp', they save the value into the
8159 same stack slot, which has undesirable consequences.
8161 Because of the deferred binding nature of shared libraries any function
8162 with external scope could be in a different load module and thus require
8163 rp' to be saved when calling that function. So sibcall optimizations
8164 can only be safe for static function.
8166 Note that GCC never needs return value relocations, so we don't have to
8167 worry about static calls with return value relocations (which require
8168 saving rp').
8170 It is safe to perform a sibcall optimization when the target function
8171 will never return. */
8172 static bool
8173 pa_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
8175 if (TARGET_PORTABLE_RUNTIME)
8176 return false;
8178 /* Sibcalls are ok for TARGET_ELF32 as along as the linker is used in
8179 single subspace mode and the call is not indirect. As far as I know,
8180 there is no operating system support for the multiple subspace mode.
8181 It might be possible to support indirect calls if we didn't use
8182 $$dyncall (see the indirect sequence generated in output_call). */
8183 if (TARGET_ELF32)
8184 return (decl != NULL_TREE);
8186 /* Sibcalls are not ok because the arg pointer register is not a fixed
8187 register. This prevents the sibcall optimization from occurring. In
8188 addition, there are problems with stub placement using GNU ld. This
8189 is because a normal sibcall branch uses a 17-bit relocation while
8190 a regular call branch uses a 22-bit relocation. As a result, more
8191 care needs to be taken in the placement of long-branch stubs. */
8192 if (TARGET_64BIT)
8193 return false;
8195 /* Sibcalls are only ok within a translation unit. */
8196 return (decl && !TREE_PUBLIC (decl));
8199 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8200 use in fmpyadd instructions. */
8202 fmpyaddoperands (rtx *operands)
8204 enum machine_mode mode = GET_MODE (operands[0]);
8206 /* Must be a floating point mode. */
8207 if (mode != SFmode && mode != DFmode)
8208 return 0;
8210 /* All modes must be the same. */
8211 if (! (mode == GET_MODE (operands[1])
8212 && mode == GET_MODE (operands[2])
8213 && mode == GET_MODE (operands[3])
8214 && mode == GET_MODE (operands[4])
8215 && mode == GET_MODE (operands[5])))
8216 return 0;
8218 /* All operands must be registers. */
8219 if (! (GET_CODE (operands[1]) == REG
8220 && GET_CODE (operands[2]) == REG
8221 && GET_CODE (operands[3]) == REG
8222 && GET_CODE (operands[4]) == REG
8223 && GET_CODE (operands[5]) == REG))
8224 return 0;
8226 /* Only 2 real operands to the addition. One of the input operands must
8227 be the same as the output operand. */
8228 if (! rtx_equal_p (operands[3], operands[4])
8229 && ! rtx_equal_p (operands[3], operands[5]))
8230 return 0;
8232 /* Inout operand of add cannot conflict with any operands from multiply. */
8233 if (rtx_equal_p (operands[3], operands[0])
8234 || rtx_equal_p (operands[3], operands[1])
8235 || rtx_equal_p (operands[3], operands[2]))
8236 return 0;
8238 /* multiply cannot feed into addition operands. */
8239 if (rtx_equal_p (operands[4], operands[0])
8240 || rtx_equal_p (operands[5], operands[0]))
8241 return 0;
8243 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
8244 if (mode == SFmode
8245 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8246 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8247 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8248 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8249 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8250 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8251 return 0;
8253 /* Passed. Operands are suitable for fmpyadd. */
8254 return 1;
8257 #if !defined(USE_COLLECT2)
8258 static void
8259 pa_asm_out_constructor (rtx symbol, int priority)
8261 if (!function_label_operand (symbol, VOIDmode))
8262 hppa_encode_label (symbol);
8264 #ifdef CTORS_SECTION_ASM_OP
8265 default_ctor_section_asm_out_constructor (symbol, priority);
8266 #else
8267 # ifdef TARGET_ASM_NAMED_SECTION
8268 default_named_section_asm_out_constructor (symbol, priority);
8269 # else
8270 default_stabs_asm_out_constructor (symbol, priority);
8271 # endif
8272 #endif
8275 static void
8276 pa_asm_out_destructor (rtx symbol, int priority)
8278 if (!function_label_operand (symbol, VOIDmode))
8279 hppa_encode_label (symbol);
8281 #ifdef DTORS_SECTION_ASM_OP
8282 default_dtor_section_asm_out_destructor (symbol, priority);
8283 #else
8284 # ifdef TARGET_ASM_NAMED_SECTION
8285 default_named_section_asm_out_destructor (symbol, priority);
8286 # else
8287 default_stabs_asm_out_destructor (symbol, priority);
8288 # endif
8289 #endif
8291 #endif
8293 /* This function places uninitialized global data in the bss section.
8294 The ASM_OUTPUT_ALIGNED_BSS macro needs to be defined to call this
8295 function on the SOM port to prevent uninitialized global data from
8296 being placed in the data section. */
8298 void
8299 pa_asm_output_aligned_bss (FILE *stream,
8300 const char *name,
8301 unsigned HOST_WIDE_INT size,
8302 unsigned int align)
8304 bss_section ();
8305 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8307 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
8308 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object");
8309 #endif
8311 #ifdef ASM_OUTPUT_SIZE_DIRECTIVE
8312 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
8313 #endif
8315 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8316 ASM_OUTPUT_LABEL (stream, name);
8317 fprintf (stream, "\t.block "HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8320 /* Both the HP and GNU assemblers under HP-UX provide a .comm directive
8321 that doesn't allow the alignment of global common storage to be directly
8322 specified. The SOM linker aligns common storage based on the rounded
8323 value of the NUM_BYTES parameter in the .comm directive. It's not
8324 possible to use the .align directive as it doesn't affect the alignment
8325 of the label associated with a .comm directive. */
8327 void
8328 pa_asm_output_aligned_common (FILE *stream,
8329 const char *name,
8330 unsigned HOST_WIDE_INT size,
8331 unsigned int align)
8333 unsigned int max_common_align;
8335 max_common_align = TARGET_64BIT ? 128 : (size >= 4096 ? 256 : 64);
8336 if (align > max_common_align)
8338 warning ("alignment (%u) for %s exceeds maximum alignment "
8339 "for global common data. Using %u",
8340 align / BITS_PER_UNIT, name, max_common_align / BITS_PER_UNIT);
8341 align = max_common_align;
8344 bss_section ();
8346 assemble_name (stream, name);
8347 fprintf (stream, "\t.comm "HOST_WIDE_INT_PRINT_UNSIGNED"\n",
8348 MAX (size, align / BITS_PER_UNIT));
8351 /* We can't use .comm for local common storage as the SOM linker effectively
8352 treats the symbol as universal and uses the same storage for local symbols
8353 with the same name in different object files. The .block directive
8354 reserves an uninitialized block of storage. However, it's not common
8355 storage. Fortunately, GCC never requests common storage with the same
8356 name in any given translation unit. */
8358 void
8359 pa_asm_output_aligned_local (FILE *stream,
8360 const char *name,
8361 unsigned HOST_WIDE_INT size,
8362 unsigned int align)
8364 bss_section ();
8365 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8367 #ifdef LOCAL_ASM_OP
8368 fprintf (stream, "%s", LOCAL_ASM_OP);
8369 assemble_name (stream, name);
8370 fprintf (stream, "\n");
8371 #endif
8373 ASM_OUTPUT_LABEL (stream, name);
8374 fprintf (stream, "\t.block "HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8377 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8378 use in fmpysub instructions. */
8380 fmpysuboperands (rtx *operands)
8382 enum machine_mode mode = GET_MODE (operands[0]);
8384 /* Must be a floating point mode. */
8385 if (mode != SFmode && mode != DFmode)
8386 return 0;
8388 /* All modes must be the same. */
8389 if (! (mode == GET_MODE (operands[1])
8390 && mode == GET_MODE (operands[2])
8391 && mode == GET_MODE (operands[3])
8392 && mode == GET_MODE (operands[4])
8393 && mode == GET_MODE (operands[5])))
8394 return 0;
8396 /* All operands must be registers. */
8397 if (! (GET_CODE (operands[1]) == REG
8398 && GET_CODE (operands[2]) == REG
8399 && GET_CODE (operands[3]) == REG
8400 && GET_CODE (operands[4]) == REG
8401 && GET_CODE (operands[5]) == REG))
8402 return 0;
8404 /* Only 2 real operands to the subtraction. Subtraction is not a commutative
8405 operation, so operands[4] must be the same as operand[3]. */
8406 if (! rtx_equal_p (operands[3], operands[4]))
8407 return 0;
8409 /* multiply cannot feed into subtraction. */
8410 if (rtx_equal_p (operands[5], operands[0]))
8411 return 0;
8413 /* Inout operand of sub cannot conflict with any operands from multiply. */
8414 if (rtx_equal_p (operands[3], operands[0])
8415 || rtx_equal_p (operands[3], operands[1])
8416 || rtx_equal_p (operands[3], operands[2]))
8417 return 0;
8419 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
8420 if (mode == SFmode
8421 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8422 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8423 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8424 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8425 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8426 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8427 return 0;
8429 /* Passed. Operands are suitable for fmpysub. */
8430 return 1;
8434 plus_xor_ior_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8436 return (GET_CODE (op) == PLUS || GET_CODE (op) == XOR
8437 || GET_CODE (op) == IOR);
8440 /* Return 1 if the given constant is 2, 4, or 8. These are the valid
8441 constants for shadd instructions. */
8442 static int
8443 shadd_constant_p (int val)
8445 if (val == 2 || val == 4 || val == 8)
8446 return 1;
8447 else
8448 return 0;
8451 /* Return 1 if OP is a CONST_INT with the value 2, 4, or 8. These are
8452 the valid constant for shadd instructions. */
8454 shadd_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8456 return (GET_CODE (op) == CONST_INT && shadd_constant_p (INTVAL (op)));
8459 /* Return 1 if OP is valid as a base or index register in a
8460 REG+REG address. */
8463 borx_reg_operand (rtx op, enum machine_mode mode)
8465 if (GET_CODE (op) != REG)
8466 return 0;
8468 /* We must reject virtual registers as the only expressions that
8469 can be instantiated are REG and REG+CONST. */
8470 if (op == virtual_incoming_args_rtx
8471 || op == virtual_stack_vars_rtx
8472 || op == virtual_stack_dynamic_rtx
8473 || op == virtual_outgoing_args_rtx
8474 || op == virtual_cfa_rtx)
8475 return 0;
8477 /* While it's always safe to index off the frame pointer, it's not
8478 profitable to do so when the frame pointer is being eliminated. */
8479 if (!reload_completed
8480 && flag_omit_frame_pointer
8481 && !current_function_calls_alloca
8482 && op == frame_pointer_rtx)
8483 return 0;
8485 return register_operand (op, mode);
8488 /* Return 1 if this operand is anything other than a hard register. */
8491 non_hard_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8493 return ! (GET_CODE (op) == REG && REGNO (op) < FIRST_PSEUDO_REGISTER);
8496 /* Return 1 if INSN branches forward. Should be using insn_addresses
8497 to avoid walking through all the insns... */
8498 static int
8499 forward_branch_p (rtx insn)
8501 rtx label = JUMP_LABEL (insn);
8503 while (insn)
8505 if (insn == label)
8506 break;
8507 else
8508 insn = NEXT_INSN (insn);
8511 return (insn == label);
8514 /* Return 1 if OP is an equality comparison, else return 0. */
8516 eq_neq_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8518 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
8521 /* Return 1 if OP is an operator suitable for use in a movb instruction. */
8523 movb_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8525 return (GET_CODE (op) == EQ || GET_CODE (op) == NE
8526 || GET_CODE (op) == LT || GET_CODE (op) == GE);
8529 /* Return 1 if INSN is in the delay slot of a call instruction. */
8531 jump_in_call_delay (rtx insn)
8534 if (GET_CODE (insn) != JUMP_INSN)
8535 return 0;
8537 if (PREV_INSN (insn)
8538 && PREV_INSN (PREV_INSN (insn))
8539 && GET_CODE (next_real_insn (PREV_INSN (PREV_INSN (insn)))) == INSN)
8541 rtx test_insn = next_real_insn (PREV_INSN (PREV_INSN (insn)));
8543 return (GET_CODE (PATTERN (test_insn)) == SEQUENCE
8544 && XVECEXP (PATTERN (test_insn), 0, 1) == insn);
8547 else
8548 return 0;
8551 /* Output an unconditional move and branch insn. */
8553 const char *
8554 output_parallel_movb (rtx *operands, int length)
8556 /* These are the cases in which we win. */
8557 if (length == 4)
8558 return "mov%I1b,tr %1,%0,%2";
8560 /* None of these cases wins, but they don't lose either. */
8561 if (dbr_sequence_length () == 0)
8563 /* Nothing in the delay slot, fake it by putting the combined
8564 insn (the copy or add) in the delay slot of a bl. */
8565 if (GET_CODE (operands[1]) == CONST_INT)
8566 return "b %2\n\tldi %1,%0";
8567 else
8568 return "b %2\n\tcopy %1,%0";
8570 else
8572 /* Something in the delay slot, but we've got a long branch. */
8573 if (GET_CODE (operands[1]) == CONST_INT)
8574 return "ldi %1,%0\n\tb %2";
8575 else
8576 return "copy %1,%0\n\tb %2";
8580 /* Output an unconditional add and branch insn. */
8582 const char *
8583 output_parallel_addb (rtx *operands, int length)
8585 /* To make life easy we want operand0 to be the shared input/output
8586 operand and operand1 to be the readonly operand. */
8587 if (operands[0] == operands[1])
8588 operands[1] = operands[2];
8590 /* These are the cases in which we win. */
8591 if (length == 4)
8592 return "add%I1b,tr %1,%0,%3";
8594 /* None of these cases win, but they don't lose either. */
8595 if (dbr_sequence_length () == 0)
8597 /* Nothing in the delay slot, fake it by putting the combined
8598 insn (the copy or add) in the delay slot of a bl. */
8599 return "b %3\n\tadd%I1 %1,%0,%0";
8601 else
8603 /* Something in the delay slot, but we've got a long branch. */
8604 return "add%I1 %1,%0,%0\n\tb %3";
8608 /* Return nonzero if INSN (a jump insn) immediately follows a call
8609 to a named function. This is used to avoid filling the delay slot
8610 of the jump since it can usually be eliminated by modifying RP in
8611 the delay slot of the call. */
8614 following_call (rtx insn)
8616 if (! TARGET_JUMP_IN_DELAY)
8617 return 0;
8619 /* Find the previous real insn, skipping NOTEs. */
8620 insn = PREV_INSN (insn);
8621 while (insn && GET_CODE (insn) == NOTE)
8622 insn = PREV_INSN (insn);
8624 /* Check for CALL_INSNs and millicode calls. */
8625 if (insn
8626 && ((GET_CODE (insn) == CALL_INSN
8627 && get_attr_type (insn) != TYPE_DYNCALL)
8628 || (GET_CODE (insn) == INSN
8629 && GET_CODE (PATTERN (insn)) != SEQUENCE
8630 && GET_CODE (PATTERN (insn)) != USE
8631 && GET_CODE (PATTERN (insn)) != CLOBBER
8632 && get_attr_type (insn) == TYPE_MILLI)))
8633 return 1;
8635 return 0;
8638 /* We use this hook to perform a PA specific optimization which is difficult
8639 to do in earlier passes.
8641 We want the delay slots of branches within jump tables to be filled.
8642 None of the compiler passes at the moment even has the notion that a
8643 PA jump table doesn't contain addresses, but instead contains actual
8644 instructions!
8646 Because we actually jump into the table, the addresses of each entry
8647 must stay constant in relation to the beginning of the table (which
8648 itself must stay constant relative to the instruction to jump into
8649 it). I don't believe we can guarantee earlier passes of the compiler
8650 will adhere to those rules.
8652 So, late in the compilation process we find all the jump tables, and
8653 expand them into real code -- e.g. each entry in the jump table vector
8654 will get an appropriate label followed by a jump to the final target.
8656 Reorg and the final jump pass can then optimize these branches and
8657 fill their delay slots. We end up with smaller, more efficient code.
8659 The jump instructions within the table are special; we must be able
8660 to identify them during assembly output (if the jumps don't get filled
8661 we need to emit a nop rather than nullifying the delay slot)). We
8662 identify jumps in switch tables by using insns with the attribute
8663 type TYPE_BTABLE_BRANCH.
8665 We also surround the jump table itself with BEGIN_BRTAB and END_BRTAB
8666 insns. This serves two purposes, first it prevents jump.c from
8667 noticing that the last N entries in the table jump to the instruction
8668 immediately after the table and deleting the jumps. Second, those
8669 insns mark where we should emit .begin_brtab and .end_brtab directives
8670 when using GAS (allows for better link time optimizations). */
8672 static void
8673 pa_reorg (void)
8675 rtx insn;
8677 remove_useless_addtr_insns (1);
8679 if (pa_cpu < PROCESSOR_8000)
8680 pa_combine_instructions ();
8683 /* This is fairly cheap, so always run it if optimizing. */
8684 if (optimize > 0 && !TARGET_BIG_SWITCH)
8686 /* Find and explode all ADDR_VEC or ADDR_DIFF_VEC insns. */
8687 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
8689 rtx pattern, tmp, location, label;
8690 unsigned int length, i;
8692 /* Find an ADDR_VEC or ADDR_DIFF_VEC insn to explode. */
8693 if (GET_CODE (insn) != JUMP_INSN
8694 || (GET_CODE (PATTERN (insn)) != ADDR_VEC
8695 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
8696 continue;
8698 /* Emit marker for the beginning of the branch table. */
8699 emit_insn_before (gen_begin_brtab (), insn);
8701 pattern = PATTERN (insn);
8702 location = PREV_INSN (insn);
8703 length = XVECLEN (pattern, GET_CODE (pattern) == ADDR_DIFF_VEC);
8705 for (i = 0; i < length; i++)
8707 /* Emit a label before each jump to keep jump.c from
8708 removing this code. */
8709 tmp = gen_label_rtx ();
8710 LABEL_NUSES (tmp) = 1;
8711 emit_label_after (tmp, location);
8712 location = NEXT_INSN (location);
8714 if (GET_CODE (pattern) == ADDR_VEC)
8715 label = XEXP (XVECEXP (pattern, 0, i), 0);
8716 else
8717 label = XEXP (XVECEXP (pattern, 1, i), 0);
8719 tmp = gen_short_jump (label);
8721 /* Emit the jump itself. */
8722 tmp = emit_jump_insn_after (tmp, location);
8723 JUMP_LABEL (tmp) = label;
8724 LABEL_NUSES (label)++;
8725 location = NEXT_INSN (location);
8727 /* Emit a BARRIER after the jump. */
8728 emit_barrier_after (location);
8729 location = NEXT_INSN (location);
8732 /* Emit marker for the end of the branch table. */
8733 emit_insn_before (gen_end_brtab (), location);
8734 location = NEXT_INSN (location);
8735 emit_barrier_after (location);
8737 /* Delete the ADDR_VEC or ADDR_DIFF_VEC. */
8738 delete_insn (insn);
8741 else
8743 /* Still need brtab marker insns. FIXME: the presence of these
8744 markers disables output of the branch table to readonly memory,
8745 and any alignment directives that might be needed. Possibly,
8746 the begin_brtab insn should be output before the label for the
8747 table. This doesn't matter at the moment since the tables are
8748 always output in the text section. */
8749 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
8751 /* Find an ADDR_VEC insn. */
8752 if (GET_CODE (insn) != JUMP_INSN
8753 || (GET_CODE (PATTERN (insn)) != ADDR_VEC
8754 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
8755 continue;
8757 /* Now generate markers for the beginning and end of the
8758 branch table. */
8759 emit_insn_before (gen_begin_brtab (), insn);
8760 emit_insn_after (gen_end_brtab (), insn);
8765 /* The PA has a number of odd instructions which can perform multiple
8766 tasks at once. On first generation PA machines (PA1.0 and PA1.1)
8767 it may be profitable to combine two instructions into one instruction
8768 with two outputs. It's not profitable PA2.0 machines because the
8769 two outputs would take two slots in the reorder buffers.
8771 This routine finds instructions which can be combined and combines
8772 them. We only support some of the potential combinations, and we
8773 only try common ways to find suitable instructions.
8775 * addb can add two registers or a register and a small integer
8776 and jump to a nearby (+-8k) location. Normally the jump to the
8777 nearby location is conditional on the result of the add, but by
8778 using the "true" condition we can make the jump unconditional.
8779 Thus addb can perform two independent operations in one insn.
8781 * movb is similar to addb in that it can perform a reg->reg
8782 or small immediate->reg copy and jump to a nearby (+-8k location).
8784 * fmpyadd and fmpysub can perform a FP multiply and either an
8785 FP add or FP sub if the operands of the multiply and add/sub are
8786 independent (there are other minor restrictions). Note both
8787 the fmpy and fadd/fsub can in theory move to better spots according
8788 to data dependencies, but for now we require the fmpy stay at a
8789 fixed location.
8791 * Many of the memory operations can perform pre & post updates
8792 of index registers. GCC's pre/post increment/decrement addressing
8793 is far too simple to take advantage of all the possibilities. This
8794 pass may not be suitable since those insns may not be independent.
8796 * comclr can compare two ints or an int and a register, nullify
8797 the following instruction and zero some other register. This
8798 is more difficult to use as it's harder to find an insn which
8799 will generate a comclr than finding something like an unconditional
8800 branch. (conditional moves & long branches create comclr insns).
8802 * Most arithmetic operations can conditionally skip the next
8803 instruction. They can be viewed as "perform this operation
8804 and conditionally jump to this nearby location" (where nearby
8805 is an insns away). These are difficult to use due to the
8806 branch length restrictions. */
8808 static void
8809 pa_combine_instructions (void)
8811 rtx anchor, new;
8813 /* This can get expensive since the basic algorithm is on the
8814 order of O(n^2) (or worse). Only do it for -O2 or higher
8815 levels of optimization. */
8816 if (optimize < 2)
8817 return;
8819 /* Walk down the list of insns looking for "anchor" insns which
8820 may be combined with "floating" insns. As the name implies,
8821 "anchor" instructions don't move, while "floating" insns may
8822 move around. */
8823 new = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, NULL_RTX, NULL_RTX));
8824 new = make_insn_raw (new);
8826 for (anchor = get_insns (); anchor; anchor = NEXT_INSN (anchor))
8828 enum attr_pa_combine_type anchor_attr;
8829 enum attr_pa_combine_type floater_attr;
8831 /* We only care about INSNs, JUMP_INSNs, and CALL_INSNs.
8832 Also ignore any special USE insns. */
8833 if ((GET_CODE (anchor) != INSN
8834 && GET_CODE (anchor) != JUMP_INSN
8835 && GET_CODE (anchor) != CALL_INSN)
8836 || GET_CODE (PATTERN (anchor)) == USE
8837 || GET_CODE (PATTERN (anchor)) == CLOBBER
8838 || GET_CODE (PATTERN (anchor)) == ADDR_VEC
8839 || GET_CODE (PATTERN (anchor)) == ADDR_DIFF_VEC)
8840 continue;
8842 anchor_attr = get_attr_pa_combine_type (anchor);
8843 /* See if anchor is an insn suitable for combination. */
8844 if (anchor_attr == PA_COMBINE_TYPE_FMPY
8845 || anchor_attr == PA_COMBINE_TYPE_FADDSUB
8846 || (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
8847 && ! forward_branch_p (anchor)))
8849 rtx floater;
8851 for (floater = PREV_INSN (anchor);
8852 floater;
8853 floater = PREV_INSN (floater))
8855 if (GET_CODE (floater) == NOTE
8856 || (GET_CODE (floater) == INSN
8857 && (GET_CODE (PATTERN (floater)) == USE
8858 || GET_CODE (PATTERN (floater)) == CLOBBER)))
8859 continue;
8861 /* Anything except a regular INSN will stop our search. */
8862 if (GET_CODE (floater) != INSN
8863 || GET_CODE (PATTERN (floater)) == ADDR_VEC
8864 || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
8866 floater = NULL_RTX;
8867 break;
8870 /* See if FLOATER is suitable for combination with the
8871 anchor. */
8872 floater_attr = get_attr_pa_combine_type (floater);
8873 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
8874 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
8875 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
8876 && floater_attr == PA_COMBINE_TYPE_FMPY))
8878 /* If ANCHOR and FLOATER can be combined, then we're
8879 done with this pass. */
8880 if (pa_can_combine_p (new, anchor, floater, 0,
8881 SET_DEST (PATTERN (floater)),
8882 XEXP (SET_SRC (PATTERN (floater)), 0),
8883 XEXP (SET_SRC (PATTERN (floater)), 1)))
8884 break;
8887 else if (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
8888 && floater_attr == PA_COMBINE_TYPE_ADDMOVE)
8890 if (GET_CODE (SET_SRC (PATTERN (floater))) == PLUS)
8892 if (pa_can_combine_p (new, anchor, floater, 0,
8893 SET_DEST (PATTERN (floater)),
8894 XEXP (SET_SRC (PATTERN (floater)), 0),
8895 XEXP (SET_SRC (PATTERN (floater)), 1)))
8896 break;
8898 else
8900 if (pa_can_combine_p (new, anchor, floater, 0,
8901 SET_DEST (PATTERN (floater)),
8902 SET_SRC (PATTERN (floater)),
8903 SET_SRC (PATTERN (floater))))
8904 break;
8909 /* If we didn't find anything on the backwards scan try forwards. */
8910 if (!floater
8911 && (anchor_attr == PA_COMBINE_TYPE_FMPY
8912 || anchor_attr == PA_COMBINE_TYPE_FADDSUB))
8914 for (floater = anchor; floater; floater = NEXT_INSN (floater))
8916 if (GET_CODE (floater) == NOTE
8917 || (GET_CODE (floater) == INSN
8918 && (GET_CODE (PATTERN (floater)) == USE
8919 || GET_CODE (PATTERN (floater)) == CLOBBER)))
8921 continue;
8923 /* Anything except a regular INSN will stop our search. */
8924 if (GET_CODE (floater) != INSN
8925 || GET_CODE (PATTERN (floater)) == ADDR_VEC
8926 || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
8928 floater = NULL_RTX;
8929 break;
8932 /* See if FLOATER is suitable for combination with the
8933 anchor. */
8934 floater_attr = get_attr_pa_combine_type (floater);
8935 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
8936 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
8937 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
8938 && floater_attr == PA_COMBINE_TYPE_FMPY))
8940 /* If ANCHOR and FLOATER can be combined, then we're
8941 done with this pass. */
8942 if (pa_can_combine_p (new, anchor, floater, 1,
8943 SET_DEST (PATTERN (floater)),
8944 XEXP (SET_SRC (PATTERN (floater)),
8946 XEXP (SET_SRC (PATTERN (floater)),
8947 1)))
8948 break;
8953 /* FLOATER will be nonzero if we found a suitable floating
8954 insn for combination with ANCHOR. */
8955 if (floater
8956 && (anchor_attr == PA_COMBINE_TYPE_FADDSUB
8957 || anchor_attr == PA_COMBINE_TYPE_FMPY))
8959 /* Emit the new instruction and delete the old anchor. */
8960 emit_insn_before (gen_rtx_PARALLEL
8961 (VOIDmode,
8962 gen_rtvec (2, PATTERN (anchor),
8963 PATTERN (floater))),
8964 anchor);
8966 PUT_CODE (anchor, NOTE);
8967 NOTE_LINE_NUMBER (anchor) = NOTE_INSN_DELETED;
8968 NOTE_SOURCE_FILE (anchor) = 0;
8970 /* Emit a special USE insn for FLOATER, then delete
8971 the floating insn. */
8972 emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
8973 delete_insn (floater);
8975 continue;
8977 else if (floater
8978 && anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH)
8980 rtx temp;
8981 /* Emit the new_jump instruction and delete the old anchor. */
8982 temp
8983 = emit_jump_insn_before (gen_rtx_PARALLEL
8984 (VOIDmode,
8985 gen_rtvec (2, PATTERN (anchor),
8986 PATTERN (floater))),
8987 anchor);
8989 JUMP_LABEL (temp) = JUMP_LABEL (anchor);
8990 PUT_CODE (anchor, NOTE);
8991 NOTE_LINE_NUMBER (anchor) = NOTE_INSN_DELETED;
8992 NOTE_SOURCE_FILE (anchor) = 0;
8994 /* Emit a special USE insn for FLOATER, then delete
8995 the floating insn. */
8996 emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
8997 delete_insn (floater);
8998 continue;
9004 static int
9005 pa_can_combine_p (rtx new, rtx anchor, rtx floater, int reversed, rtx dest,
9006 rtx src1, rtx src2)
9008 int insn_code_number;
9009 rtx start, end;
9011 /* Create a PARALLEL with the patterns of ANCHOR and
9012 FLOATER, try to recognize it, then test constraints
9013 for the resulting pattern.
9015 If the pattern doesn't match or the constraints
9016 aren't met keep searching for a suitable floater
9017 insn. */
9018 XVECEXP (PATTERN (new), 0, 0) = PATTERN (anchor);
9019 XVECEXP (PATTERN (new), 0, 1) = PATTERN (floater);
9020 INSN_CODE (new) = -1;
9021 insn_code_number = recog_memoized (new);
9022 if (insn_code_number < 0
9023 || (extract_insn (new), ! constrain_operands (1)))
9024 return 0;
9026 if (reversed)
9028 start = anchor;
9029 end = floater;
9031 else
9033 start = floater;
9034 end = anchor;
9037 /* There's up to three operands to consider. One
9038 output and two inputs.
9040 The output must not be used between FLOATER & ANCHOR
9041 exclusive. The inputs must not be set between
9042 FLOATER and ANCHOR exclusive. */
9044 if (reg_used_between_p (dest, start, end))
9045 return 0;
9047 if (reg_set_between_p (src1, start, end))
9048 return 0;
9050 if (reg_set_between_p (src2, start, end))
9051 return 0;
9053 /* If we get here, then everything is good. */
9054 return 1;
9057 /* Return nonzero if references for INSN are delayed.
9059 Millicode insns are actually function calls with some special
9060 constraints on arguments and register usage.
9062 Millicode calls always expect their arguments in the integer argument
9063 registers, and always return their result in %r29 (ret1). They
9064 are expected to clobber their arguments, %r1, %r29, and the return
9065 pointer which is %r31 on 32-bit and %r2 on 64-bit, and nothing else.
9067 This function tells reorg that the references to arguments and
9068 millicode calls do not appear to happen until after the millicode call.
9069 This allows reorg to put insns which set the argument registers into the
9070 delay slot of the millicode call -- thus they act more like traditional
9071 CALL_INSNs.
9073 Note we cannot consider side effects of the insn to be delayed because
9074 the branch and link insn will clobber the return pointer. If we happened
9075 to use the return pointer in the delay slot of the call, then we lose.
9077 get_attr_type will try to recognize the given insn, so make sure to
9078 filter out things it will not accept -- SEQUENCE, USE and CLOBBER insns
9079 in particular. */
9081 insn_refs_are_delayed (rtx insn)
9083 return ((GET_CODE (insn) == INSN
9084 && GET_CODE (PATTERN (insn)) != SEQUENCE
9085 && GET_CODE (PATTERN (insn)) != USE
9086 && GET_CODE (PATTERN (insn)) != CLOBBER
9087 && get_attr_type (insn) == TYPE_MILLI));
9090 /* On the HP-PA the value is found in register(s) 28(-29), unless
9091 the mode is SF or DF. Then the value is returned in fr4 (32).
9093 This must perform the same promotions as PROMOTE_MODE, else
9094 TARGET_PROMOTE_FUNCTION_RETURN will not work correctly.
9096 Small structures must be returned in a PARALLEL on PA64 in order
9097 to match the HP Compiler ABI. */
9100 function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
9102 enum machine_mode valmode;
9104 /* Aggregates with a size less than or equal to 128 bits are returned
9105 in GR 28(-29). They are left justified. The pad bits are undefined.
9106 Larger aggregates are returned in memory. */
9107 if (TARGET_64BIT && AGGREGATE_TYPE_P (valtype))
9109 rtx loc[2];
9110 int i, offset = 0;
9111 int ub = int_size_in_bytes (valtype) <= UNITS_PER_WORD ? 1 : 2;
9113 for (i = 0; i < ub; i++)
9115 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9116 gen_rtx_REG (DImode, 28 + i),
9117 GEN_INT (offset));
9118 offset += 8;
9121 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (ub, loc));
9124 if ((INTEGRAL_TYPE_P (valtype)
9125 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
9126 || POINTER_TYPE_P (valtype))
9127 valmode = word_mode;
9128 else
9129 valmode = TYPE_MODE (valtype);
9131 if (TREE_CODE (valtype) == REAL_TYPE
9132 && TYPE_MODE (valtype) != TFmode
9133 && !TARGET_SOFT_FLOAT)
9134 return gen_rtx_REG (valmode, 32);
9136 return gen_rtx_REG (valmode, 28);
9139 /* Return the location of a parameter that is passed in a register or NULL
9140 if the parameter has any component that is passed in memory.
9142 This is new code and will be pushed to into the net sources after
9143 further testing.
9145 ??? We might want to restructure this so that it looks more like other
9146 ports. */
9148 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, tree type,
9149 int named ATTRIBUTE_UNUSED)
9151 int max_arg_words = (TARGET_64BIT ? 8 : 4);
9152 int alignment = 0;
9153 int arg_size;
9154 int fpr_reg_base;
9155 int gpr_reg_base;
9156 rtx retval;
9158 if (mode == VOIDmode)
9159 return NULL_RTX;
9161 arg_size = FUNCTION_ARG_SIZE (mode, type);
9163 /* If this arg would be passed partially or totally on the stack, then
9164 this routine should return zero. pa_arg_partial_bytes will
9165 handle arguments which are split between regs and stack slots if
9166 the ABI mandates split arguments. */
9167 if (! TARGET_64BIT)
9169 /* The 32-bit ABI does not split arguments. */
9170 if (cum->words + arg_size > max_arg_words)
9171 return NULL_RTX;
9173 else
9175 if (arg_size > 1)
9176 alignment = cum->words & 1;
9177 if (cum->words + alignment >= max_arg_words)
9178 return NULL_RTX;
9181 /* The 32bit ABIs and the 64bit ABIs are rather different,
9182 particularly in their handling of FP registers. We might
9183 be able to cleverly share code between them, but I'm not
9184 going to bother in the hope that splitting them up results
9185 in code that is more easily understood. */
9187 if (TARGET_64BIT)
9189 /* Advance the base registers to their current locations.
9191 Remember, gprs grow towards smaller register numbers while
9192 fprs grow to higher register numbers. Also remember that
9193 although FP regs are 32-bit addressable, we pretend that
9194 the registers are 64-bits wide. */
9195 gpr_reg_base = 26 - cum->words;
9196 fpr_reg_base = 32 + cum->words;
9198 /* Arguments wider than one word and small aggregates need special
9199 treatment. */
9200 if (arg_size > 1
9201 || mode == BLKmode
9202 || (type && AGGREGATE_TYPE_P (type)))
9204 /* Double-extended precision (80-bit), quad-precision (128-bit)
9205 and aggregates including complex numbers are aligned on
9206 128-bit boundaries. The first eight 64-bit argument slots
9207 are associated one-to-one, with general registers r26
9208 through r19, and also with floating-point registers fr4
9209 through fr11. Arguments larger than one word are always
9210 passed in general registers.
9212 Using a PARALLEL with a word mode register results in left
9213 justified data on a big-endian target. */
9215 rtx loc[8];
9216 int i, offset = 0, ub = arg_size;
9218 /* Align the base register. */
9219 gpr_reg_base -= alignment;
9221 ub = MIN (ub, max_arg_words - cum->words - alignment);
9222 for (i = 0; i < ub; i++)
9224 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9225 gen_rtx_REG (DImode, gpr_reg_base),
9226 GEN_INT (offset));
9227 gpr_reg_base -= 1;
9228 offset += 8;
9231 return gen_rtx_PARALLEL (mode, gen_rtvec_v (ub, loc));
9234 else
9236 /* If the argument is larger than a word, then we know precisely
9237 which registers we must use. */
9238 if (arg_size > 1)
9240 if (cum->words)
9242 gpr_reg_base = 23;
9243 fpr_reg_base = 38;
9245 else
9247 gpr_reg_base = 25;
9248 fpr_reg_base = 34;
9251 /* Structures 5 to 8 bytes in size are passed in the general
9252 registers in the same manner as other non floating-point
9253 objects. The data is right-justified and zero-extended
9254 to 64 bits. This is opposite to the normal justification
9255 used on big endian targets and requires special treatment.
9256 We now define BLOCK_REG_PADDING to pad these objects. */
9257 if (mode == BLKmode)
9259 rtx loc = gen_rtx_EXPR_LIST (VOIDmode,
9260 gen_rtx_REG (DImode, gpr_reg_base),
9261 const0_rtx);
9262 return gen_rtx_PARALLEL (mode, gen_rtvec (1, loc));
9265 else
9267 /* We have a single word (32 bits). A simple computation
9268 will get us the register #s we need. */
9269 gpr_reg_base = 26 - cum->words;
9270 fpr_reg_base = 32 + 2 * cum->words;
9274 /* Determine if the argument needs to be passed in both general and
9275 floating point registers. */
9276 if (((TARGET_PORTABLE_RUNTIME || TARGET_64BIT || TARGET_ELF32)
9277 /* If we are doing soft-float with portable runtime, then there
9278 is no need to worry about FP regs. */
9279 && !TARGET_SOFT_FLOAT
9280 /* The parameter must be some kind of float, else we can just
9281 pass it in integer registers. */
9282 && FLOAT_MODE_P (mode)
9283 /* The target function must not have a prototype. */
9284 && cum->nargs_prototype <= 0
9285 /* libcalls do not need to pass items in both FP and general
9286 registers. */
9287 && type != NULL_TREE
9288 /* All this hair applies to "outgoing" args only. This includes
9289 sibcall arguments setup with FUNCTION_INCOMING_ARG. */
9290 && !cum->incoming)
9291 /* Also pass outgoing floating arguments in both registers in indirect
9292 calls with the 32 bit ABI and the HP assembler since there is no
9293 way to the specify argument locations in static functions. */
9294 || (!TARGET_64BIT
9295 && !TARGET_GAS
9296 && !cum->incoming
9297 && cum->indirect
9298 && FLOAT_MODE_P (mode)))
9300 retval
9301 = gen_rtx_PARALLEL
9302 (mode,
9303 gen_rtvec (2,
9304 gen_rtx_EXPR_LIST (VOIDmode,
9305 gen_rtx_REG (mode, fpr_reg_base),
9306 const0_rtx),
9307 gen_rtx_EXPR_LIST (VOIDmode,
9308 gen_rtx_REG (mode, gpr_reg_base),
9309 const0_rtx)));
9311 else
9313 /* See if we should pass this parameter in a general register. */
9314 if (TARGET_SOFT_FLOAT
9315 /* Indirect calls in the normal 32bit ABI require all arguments
9316 to be passed in general registers. */
9317 || (!TARGET_PORTABLE_RUNTIME
9318 && !TARGET_64BIT
9319 && !TARGET_ELF32
9320 && cum->indirect)
9321 /* If the parameter is not a floating point parameter, then
9322 it belongs in GPRs. */
9323 || !FLOAT_MODE_P (mode))
9324 retval = gen_rtx_REG (mode, gpr_reg_base);
9325 else
9326 retval = gen_rtx_REG (mode, fpr_reg_base);
9328 return retval;
9332 /* If this arg would be passed totally in registers or totally on the stack,
9333 then this routine should return zero. */
9335 static int
9336 pa_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
9337 tree type, bool named ATTRIBUTE_UNUSED)
9339 unsigned int max_arg_words = 8;
9340 unsigned int offset = 0;
9342 if (!TARGET_64BIT)
9343 return 0;
9345 if (FUNCTION_ARG_SIZE (mode, type) > 1 && (cum->words & 1))
9346 offset = 1;
9348 if (cum->words + offset + FUNCTION_ARG_SIZE (mode, type) <= max_arg_words)
9349 /* Arg fits fully into registers. */
9350 return 0;
9351 else if (cum->words + offset >= max_arg_words)
9352 /* Arg fully on the stack. */
9353 return 0;
9354 else
9355 /* Arg is split. */
9356 return (max_arg_words - cum->words - offset) * UNITS_PER_WORD;
9360 /* Return 1 if this is a comparison operator. This allows the use of
9361 MATCH_OPERATOR to recognize all the branch insns. */
9364 cmpib_comparison_operator (rtx op, enum machine_mode mode)
9366 return ((mode == VOIDmode || GET_MODE (op) == mode)
9367 && (GET_CODE (op) == EQ
9368 || GET_CODE (op) == NE
9369 || GET_CODE (op) == GT
9370 || GET_CODE (op) == GTU
9371 || GET_CODE (op) == GE
9372 || GET_CODE (op) == LT
9373 || GET_CODE (op) == LE
9374 || GET_CODE (op) == LEU));
9377 /* Return a string to output before text in the current function.
9379 This function is only used with SOM. Because we don't support
9380 named subspaces, we can only create a new subspace or switch back
9381 to the default text subspace. */
9382 const char *
9383 som_text_section_asm_op (void)
9385 if (!TARGET_SOM)
9386 return "";
9388 if (TARGET_GAS)
9390 if (cfun && !cfun->machine->in_nsubspa)
9392 /* We only want to emit a .nsubspa directive once at the
9393 start of the function. */
9394 cfun->machine->in_nsubspa = 1;
9396 /* Create a new subspace for the text. This provides
9397 better stub placement and one-only functions. */
9398 if (cfun->decl
9399 && DECL_ONE_ONLY (cfun->decl)
9400 && !DECL_WEAK (cfun->decl))
9401 return
9402 "\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,SORT=24,COMDAT";
9404 return "\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$";
9406 else
9408 /* There isn't a current function or the body of the current
9409 function has been completed. So, we are changing to the
9410 text section to output debugging information. Do this in
9411 the default text section. We need to forget that we are
9412 in the text section so that the function text_section in
9413 varasm.c will call us the next time around. */
9414 forget_section ();
9418 return "\t.SPACE $TEXT$\n\t.SUBSPA $CODE$";
9421 /* On hpux10, the linker will give an error if we have a reference
9422 in the read-only data section to a symbol defined in a shared
9423 library. Therefore, expressions that might require a reloc can
9424 not be placed in the read-only data section. */
9426 static void
9427 pa_select_section (tree exp, int reloc,
9428 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
9430 if (TREE_CODE (exp) == VAR_DECL
9431 && TREE_READONLY (exp)
9432 && !TREE_THIS_VOLATILE (exp)
9433 && DECL_INITIAL (exp)
9434 && (DECL_INITIAL (exp) == error_mark_node
9435 || TREE_CONSTANT (DECL_INITIAL (exp)))
9436 && !reloc)
9438 if (TARGET_SOM
9439 && DECL_ONE_ONLY (exp)
9440 && !DECL_WEAK (exp))
9441 som_one_only_readonly_data_section ();
9442 else
9443 readonly_data_section ();
9445 else if (CONSTANT_CLASS_P (exp) && !reloc)
9446 readonly_data_section ();
9447 else if (TARGET_SOM
9448 && TREE_CODE (exp) == VAR_DECL
9449 && DECL_ONE_ONLY (exp)
9450 && !DECL_WEAK (exp))
9451 som_one_only_data_section ();
9452 else
9453 data_section ();
9456 static void
9457 pa_globalize_label (FILE *stream, const char *name)
9459 /* We only handle DATA objects here, functions are globalized in
9460 ASM_DECLARE_FUNCTION_NAME. */
9461 if (! FUNCTION_NAME_P (name))
9463 fputs ("\t.EXPORT ", stream);
9464 assemble_name (stream, name);
9465 fputs (",DATA\n", stream);
9469 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
9471 static rtx
9472 pa_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
9473 int incoming ATTRIBUTE_UNUSED)
9475 return gen_rtx_REG (Pmode, PA_STRUCT_VALUE_REGNUM);
9478 /* Worker function for TARGET_RETURN_IN_MEMORY. */
9480 bool
9481 pa_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
9483 /* SOM ABI says that objects larger than 64 bits are returned in memory.
9484 PA64 ABI says that objects larger than 128 bits are returned in memory.
9485 Note, int_size_in_bytes can return -1 if the size of the object is
9486 variable or larger than the maximum value that can be expressed as
9487 a HOST_WIDE_INT. It can also return zero for an empty type. The
9488 simplest way to handle variable and empty types is to pass them in
9489 memory. This avoids problems in defining the boundaries of argument
9490 slots, allocating registers, etc. */
9491 return (int_size_in_bytes (type) > (TARGET_64BIT ? 16 : 8)
9492 || int_size_in_bytes (type) <= 0);
9495 #include "gt-pa.h"