* emit-rtl.c (gen_const_mem): New.
[official-gcc.git] / gcc / config / pa / pa.c
blobbe1c4bd4618864e4c6eb5166c11f30d965aa4f42
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 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 void copy_fp_args (rtx) ATTRIBUTE_UNUSED;
127 static int length_fp_args (rtx) ATTRIBUTE_UNUSED;
128 static struct deferred_plabel *get_plabel (const char *)
129 ATTRIBUTE_UNUSED;
130 static inline void pa_file_start_level (void) ATTRIBUTE_UNUSED;
131 static inline void pa_file_start_space (int) ATTRIBUTE_UNUSED;
132 static inline void pa_file_start_file (int) ATTRIBUTE_UNUSED;
133 static inline void pa_file_start_mcount (const char*) ATTRIBUTE_UNUSED;
134 static void pa_elf_file_start (void) ATTRIBUTE_UNUSED;
135 static void pa_som_file_start (void) ATTRIBUTE_UNUSED;
136 static void pa_linux_file_start (void) ATTRIBUTE_UNUSED;
137 static void pa_hpux64_gas_file_start (void) ATTRIBUTE_UNUSED;
138 static void pa_hpux64_hpas_file_start (void) ATTRIBUTE_UNUSED;
139 static void output_deferred_plabels (void);
140 #ifdef HPUX_LONG_DOUBLE_LIBRARY
141 static void pa_hpux_init_libfuncs (void);
142 #endif
143 static rtx pa_struct_value_rtx (tree, int);
144 static bool pa_pass_by_reference (CUMULATIVE_ARGS *ca, enum machine_mode,
145 tree, bool);
146 static struct machine_function * pa_init_machine_status (void);
149 /* Save the operands last given to a compare for use when we
150 generate a scc or bcc insn. */
151 rtx hppa_compare_op0, hppa_compare_op1;
152 enum cmp_type hppa_branch_type;
154 /* Which architecture we are generating code for. */
155 enum architecture_type pa_arch;
157 /* String to hold which architecture we are generating code for. */
158 const char *pa_arch_string;
160 /* String used with the -mfixed-range= option. */
161 const char *pa_fixed_range_string;
163 /* Which cpu we are scheduling for. */
164 enum processor_type pa_cpu;
166 /* String to hold which cpu we are scheduling for. */
167 const char *pa_cpu_string;
169 /* Counts for the number of callee-saved general and floating point
170 registers which were saved by the current function's prologue. */
171 static int gr_saved, fr_saved;
173 static rtx find_addr_reg (rtx);
175 /* Keep track of the number of bytes we have output in the CODE subspace
176 during this compilation so we'll know when to emit inline long-calls. */
177 unsigned long total_code_bytes;
179 /* The last address of the previous function plus the number of bytes in
180 associated thunks that have been output. This is used to determine if
181 a thunk can use an IA-relative branch to reach its target function. */
182 static int last_address;
184 /* Variables to handle plabels that we discover are necessary at assembly
185 output time. They are output after the current function. */
186 struct deferred_plabel GTY(())
188 rtx internal_label;
189 const char *name;
191 static GTY((length ("n_deferred_plabels"))) struct deferred_plabel *
192 deferred_plabels;
193 static size_t n_deferred_plabels = 0;
196 /* Initialize the GCC target structure. */
198 #undef TARGET_ASM_ALIGNED_HI_OP
199 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
200 #undef TARGET_ASM_ALIGNED_SI_OP
201 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
202 #undef TARGET_ASM_ALIGNED_DI_OP
203 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
204 #undef TARGET_ASM_UNALIGNED_HI_OP
205 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
206 #undef TARGET_ASM_UNALIGNED_SI_OP
207 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
208 #undef TARGET_ASM_UNALIGNED_DI_OP
209 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
210 #undef TARGET_ASM_INTEGER
211 #define TARGET_ASM_INTEGER pa_assemble_integer
213 #undef TARGET_ASM_FUNCTION_PROLOGUE
214 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
215 #undef TARGET_ASM_FUNCTION_EPILOGUE
216 #define TARGET_ASM_FUNCTION_EPILOGUE pa_output_function_epilogue
218 #undef TARGET_SCHED_ADJUST_COST
219 #define TARGET_SCHED_ADJUST_COST pa_adjust_cost
220 #undef TARGET_SCHED_ADJUST_PRIORITY
221 #define TARGET_SCHED_ADJUST_PRIORITY pa_adjust_priority
222 #undef TARGET_SCHED_ISSUE_RATE
223 #define TARGET_SCHED_ISSUE_RATE pa_issue_rate
225 #undef TARGET_ENCODE_SECTION_INFO
226 #define TARGET_ENCODE_SECTION_INFO pa_encode_section_info
227 #undef TARGET_STRIP_NAME_ENCODING
228 #define TARGET_STRIP_NAME_ENCODING pa_strip_name_encoding
230 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
231 #define TARGET_FUNCTION_OK_FOR_SIBCALL pa_function_ok_for_sibcall
233 #undef TARGET_ASM_OUTPUT_MI_THUNK
234 #define TARGET_ASM_OUTPUT_MI_THUNK pa_asm_output_mi_thunk
235 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
236 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
238 #undef TARGET_ASM_FILE_END
239 #define TARGET_ASM_FILE_END output_deferred_plabels
241 #if !defined(USE_COLLECT2)
242 #undef TARGET_ASM_CONSTRUCTOR
243 #define TARGET_ASM_CONSTRUCTOR pa_asm_out_constructor
244 #undef TARGET_ASM_DESTRUCTOR
245 #define TARGET_ASM_DESTRUCTOR pa_asm_out_destructor
246 #endif
248 #undef TARGET_INIT_BUILTINS
249 #define TARGET_INIT_BUILTINS pa_init_builtins
251 #undef TARGET_RTX_COSTS
252 #define TARGET_RTX_COSTS hppa_rtx_costs
253 #undef TARGET_ADDRESS_COST
254 #define TARGET_ADDRESS_COST hppa_address_cost
256 #undef TARGET_MACHINE_DEPENDENT_REORG
257 #define TARGET_MACHINE_DEPENDENT_REORG pa_reorg
259 #ifdef HPUX_LONG_DOUBLE_LIBRARY
260 #undef TARGET_INIT_LIBFUNCS
261 #define TARGET_INIT_LIBFUNCS pa_hpux_init_libfuncs
262 #endif
264 #undef TARGET_PROMOTE_FUNCTION_RETURN
265 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
266 #undef TARGET_PROMOTE_PROTOTYPES
267 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
269 #undef TARGET_STRUCT_VALUE_RTX
270 #define TARGET_STRUCT_VALUE_RTX pa_struct_value_rtx
271 #undef TARGET_RETURN_IN_MEMORY
272 #define TARGET_RETURN_IN_MEMORY pa_return_in_memory
273 #undef TARGET_MUST_PASS_IN_STACK
274 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
275 #undef TARGET_PASS_BY_REFERENCE
276 #define TARGET_PASS_BY_REFERENCE pa_pass_by_reference
278 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
279 #define TARGET_EXPAND_BUILTIN_SAVEREGS hppa_builtin_saveregs
280 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
281 #define TARGET_GIMPLIFY_VA_ARG_EXPR hppa_gimplify_va_arg_expr
283 struct gcc_target targetm = TARGET_INITIALIZER;
285 /* Parse the -mfixed-range= option string. */
287 static void
288 fix_range (const char *const_str)
290 int i, first, last;
291 char *str, *dash, *comma;
293 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
294 REG2 are either register names or register numbers. The effect
295 of this option is to mark the registers in the range from REG1 to
296 REG2 as ``fixed'' so they won't be used by the compiler. This is
297 used, e.g., to ensure that kernel mode code doesn't use f32-f127. */
299 i = strlen (const_str);
300 str = (char *) alloca (i + 1);
301 memcpy (str, const_str, i + 1);
303 while (1)
305 dash = strchr (str, '-');
306 if (!dash)
308 warning ("value of -mfixed-range must have form REG1-REG2");
309 return;
311 *dash = '\0';
313 comma = strchr (dash + 1, ',');
314 if (comma)
315 *comma = '\0';
317 first = decode_reg_name (str);
318 if (first < 0)
320 warning ("unknown register name: %s", str);
321 return;
324 last = decode_reg_name (dash + 1);
325 if (last < 0)
327 warning ("unknown register name: %s", dash + 1);
328 return;
331 *dash = '-';
333 if (first > last)
335 warning ("%s-%s is an empty range", str, dash + 1);
336 return;
339 for (i = first; i <= last; ++i)
340 fixed_regs[i] = call_used_regs[i] = 1;
342 if (!comma)
343 break;
345 *comma = ',';
346 str = comma + 1;
349 /* Check if all floating point registers have been fixed. */
350 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
351 if (!fixed_regs[i])
352 break;
354 if (i > FP_REG_LAST)
355 target_flags |= MASK_DISABLE_FPREGS;
358 void
359 override_options (void)
361 if (pa_cpu_string == NULL)
362 pa_cpu_string = TARGET_SCHED_DEFAULT;
364 if (! strcmp (pa_cpu_string, "8000"))
366 pa_cpu_string = "8000";
367 pa_cpu = PROCESSOR_8000;
369 else if (! strcmp (pa_cpu_string, "7100"))
371 pa_cpu_string = "7100";
372 pa_cpu = PROCESSOR_7100;
374 else if (! strcmp (pa_cpu_string, "700"))
376 pa_cpu_string = "700";
377 pa_cpu = PROCESSOR_700;
379 else if (! strcmp (pa_cpu_string, "7100LC"))
381 pa_cpu_string = "7100LC";
382 pa_cpu = PROCESSOR_7100LC;
384 else if (! strcmp (pa_cpu_string, "7200"))
386 pa_cpu_string = "7200";
387 pa_cpu = PROCESSOR_7200;
389 else if (! strcmp (pa_cpu_string, "7300"))
391 pa_cpu_string = "7300";
392 pa_cpu = PROCESSOR_7300;
394 else
396 warning ("unknown -mschedule= option (%s).\nValid options are 700, 7100, 7100LC, 7200, 7300, and 8000\n", pa_cpu_string);
399 /* Set the instruction architecture. */
400 if (pa_arch_string && ! strcmp (pa_arch_string, "1.0"))
402 pa_arch_string = "1.0";
403 pa_arch = ARCHITECTURE_10;
404 target_flags &= ~(MASK_PA_11 | MASK_PA_20);
406 else if (pa_arch_string && ! strcmp (pa_arch_string, "1.1"))
408 pa_arch_string = "1.1";
409 pa_arch = ARCHITECTURE_11;
410 target_flags &= ~MASK_PA_20;
411 target_flags |= MASK_PA_11;
413 else if (pa_arch_string && ! strcmp (pa_arch_string, "2.0"))
415 pa_arch_string = "2.0";
416 pa_arch = ARCHITECTURE_20;
417 target_flags |= MASK_PA_11 | MASK_PA_20;
419 else if (pa_arch_string)
421 warning ("unknown -march= option (%s).\nValid options are 1.0, 1.1, and 2.0\n", pa_arch_string);
424 if (pa_fixed_range_string)
425 fix_range (pa_fixed_range_string);
427 /* Unconditional branches in the delay slot are not compatible with dwarf2
428 call frame information. There is no benefit in using this optimization
429 on PA8000 and later processors. */
430 if (pa_cpu >= PROCESSOR_8000
431 || (! USING_SJLJ_EXCEPTIONS && flag_exceptions)
432 || flag_unwind_tables)
433 target_flags &= ~MASK_JUMP_IN_DELAY;
435 if (flag_pic && TARGET_PORTABLE_RUNTIME)
437 warning ("PIC code generation is not supported in the portable runtime model\n");
440 if (flag_pic && TARGET_FAST_INDIRECT_CALLS)
442 warning ("PIC code generation is not compatible with fast indirect calls\n");
445 if (! TARGET_GAS && write_symbols != NO_DEBUG)
447 warning ("-g is only supported when using GAS on this processor,");
448 warning ("-g option disabled");
449 write_symbols = NO_DEBUG;
452 /* We only support the "big PIC" model now. And we always generate PIC
453 code when in 64bit mode. */
454 if (flag_pic == 1 || TARGET_64BIT)
455 flag_pic = 2;
457 /* We can't guarantee that .dword is available for 32-bit targets. */
458 if (UNITS_PER_WORD == 4)
459 targetm.asm_out.aligned_op.di = NULL;
461 /* The unaligned ops are only available when using GAS. */
462 if (!TARGET_GAS)
464 targetm.asm_out.unaligned_op.hi = NULL;
465 targetm.asm_out.unaligned_op.si = NULL;
466 targetm.asm_out.unaligned_op.di = NULL;
469 init_machine_status = pa_init_machine_status;
472 static void
473 pa_init_builtins (void)
475 #ifdef DONT_HAVE_FPUTC_UNLOCKED
476 built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
477 implicit_built_in_decls[(int) BUILT_IN_FPUTC_UNLOCKED] = NULL_TREE;
478 #endif
481 /* Function to init struct machine_function.
482 This will be called, via a pointer variable,
483 from push_function_context. */
485 static struct machine_function *
486 pa_init_machine_status (void)
488 return ggc_alloc_cleared (sizeof (machine_function));
491 /* If FROM is a probable pointer register, mark TO as a probable
492 pointer register with the same pointer alignment as FROM. */
494 static void
495 copy_reg_pointer (rtx to, rtx from)
497 if (REG_POINTER (from))
498 mark_reg_pointer (to, REGNO_POINTER_ALIGN (REGNO (from)));
501 /* Return nonzero only if OP is a register of mode MODE,
502 or CONST0_RTX. */
504 reg_or_0_operand (rtx op, enum machine_mode mode)
506 return (op == CONST0_RTX (mode) || register_operand (op, mode));
509 /* Return nonzero if OP is suitable for use in a call to a named
510 function.
512 For 2.5 try to eliminate either call_operand_address or
513 function_label_operand, they perform very similar functions. */
515 call_operand_address (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
517 return (GET_MODE (op) == word_mode
518 && CONSTANT_P (op) && ! TARGET_PORTABLE_RUNTIME);
521 /* Return 1 if X contains a symbolic expression. We know these
522 expressions will have one of a few well defined forms, so
523 we need only check those forms. */
525 symbolic_expression_p (rtx x)
528 /* Strip off any HIGH. */
529 if (GET_CODE (x) == HIGH)
530 x = XEXP (x, 0);
532 return (symbolic_operand (x, VOIDmode));
536 symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
538 switch (GET_CODE (op))
540 case SYMBOL_REF:
541 case LABEL_REF:
542 return 1;
543 case CONST:
544 op = XEXP (op, 0);
545 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
546 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
547 && GET_CODE (XEXP (op, 1)) == CONST_INT);
548 default:
549 return 0;
553 /* Return truth value of statement that OP is a symbolic memory
554 operand of mode MODE. */
557 symbolic_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
559 if (GET_CODE (op) == SUBREG)
560 op = SUBREG_REG (op);
561 if (GET_CODE (op) != MEM)
562 return 0;
563 op = XEXP (op, 0);
564 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
565 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
568 /* Return 1 if the operand is either a register, zero, or a memory operand
569 that is not symbolic. */
572 reg_or_0_or_nonsymb_mem_operand (rtx op, enum machine_mode mode)
574 if (register_operand (op, mode))
575 return 1;
577 if (op == CONST0_RTX (mode))
578 return 1;
580 if (GET_CODE (op) == SUBREG)
581 op = SUBREG_REG (op);
583 if (GET_CODE (op) != MEM)
584 return 0;
586 /* Until problems with management of the REG_POINTER flag are resolved,
587 we need to delay creating move insns with unscaled indexed addresses
588 until CSE is not expected. */
589 if (!TARGET_NO_SPACE_REGS
590 && !cse_not_expected
591 && GET_CODE (XEXP (op, 0)) == PLUS
592 && REG_P (XEXP (XEXP (op, 0), 0))
593 && REG_P (XEXP (XEXP (op, 0), 1)))
594 return 0;
596 return (!symbolic_memory_operand (op, mode)
597 && memory_address_p (mode, XEXP (op, 0)));
600 /* Return 1 if the operand is a register operand or a non-symbolic memory
601 operand after reload. This predicate is used for branch patterns that
602 internally handle register reloading. We need to accept non-symbolic
603 memory operands after reload to ensure that the pattern is still valid
604 if reload didn't find a hard register for the operand. */
607 reg_before_reload_operand (rtx op, enum machine_mode mode)
609 /* Don't accept a SUBREG since it will need a reload. */
610 if (GET_CODE (op) == SUBREG)
611 return 0;
613 if (register_operand (op, mode))
614 return 1;
616 if (reload_completed
617 && memory_operand (op, mode)
618 && !symbolic_memory_operand (op, mode))
619 return 1;
621 return 0;
624 /* Accept any constant that can be moved in one instruction into a
625 general register. */
627 cint_ok_for_move (HOST_WIDE_INT intval)
629 /* OK if ldo, ldil, or zdepi, can be used. */
630 return (CONST_OK_FOR_LETTER_P (intval, 'J')
631 || CONST_OK_FOR_LETTER_P (intval, 'N')
632 || CONST_OK_FOR_LETTER_P (intval, 'K'));
635 /* Return 1 iff OP is an indexed memory operand. */
637 indexed_memory_operand (rtx op, enum machine_mode mode)
639 if (GET_MODE (op) != mode)
640 return 0;
642 /* Before reload, a (SUBREG (MEM...)) forces reloading into a register. */
643 if (reload_completed && GET_CODE (op) == SUBREG)
644 op = SUBREG_REG (op);
646 if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
647 return 0;
649 op = XEXP (op, 0);
651 return (memory_address_p (mode, op) && IS_INDEX_ADDR_P (op));
654 /* Accept anything that can be used as a destination operand for a
655 move instruction. We don't accept indexed memory operands since
656 they are supported only for floating point stores. */
658 move_dest_operand (rtx op, enum machine_mode mode)
660 if (register_operand (op, mode))
661 return 1;
663 if (GET_MODE (op) != mode)
664 return 0;
666 if (GET_CODE (op) == SUBREG)
667 op = SUBREG_REG (op);
669 if (GET_CODE (op) != MEM || symbolic_memory_operand (op, mode))
670 return 0;
672 op = XEXP (op, 0);
674 return (memory_address_p (mode, op)
675 && !IS_INDEX_ADDR_P (op)
676 && !IS_LO_SUM_DLT_ADDR_P (op));
679 /* Accept anything that can be used as a source operand for a move
680 instruction. */
682 move_src_operand (rtx op, enum machine_mode mode)
684 if (register_operand (op, mode))
685 return 1;
687 if (GET_CODE (op) == CONST_INT)
688 return cint_ok_for_move (INTVAL (op));
690 if (GET_MODE (op) != mode)
691 return 0;
693 if (GET_CODE (op) == SUBREG)
694 op = SUBREG_REG (op);
696 if (GET_CODE (op) != MEM)
697 return 0;
699 /* Until problems with management of the REG_POINTER flag are resolved,
700 we need to delay creating move insns with unscaled indexed addresses
701 until CSE is not expected. */
702 if (!TARGET_NO_SPACE_REGS
703 && !cse_not_expected
704 && GET_CODE (XEXP (op, 0)) == PLUS
705 && REG_P (XEXP (XEXP (op, 0), 0))
706 && REG_P (XEXP (XEXP (op, 0), 1)))
707 return 0;
709 return memory_address_p (mode, XEXP (op, 0));
712 /* Accept anything that can be used as the source operand for a prefetch
713 instruction. */
715 prefetch_operand (rtx op, enum machine_mode mode)
717 if (GET_CODE (op) != MEM)
718 return 0;
720 /* Until problems with management of the REG_POINTER flag are resolved,
721 we need to delay creating prefetch insns with unscaled indexed addresses
722 until CSE is not expected. */
723 if (!TARGET_NO_SPACE_REGS
724 && !cse_not_expected
725 && GET_CODE (XEXP (op, 0)) == PLUS
726 && REG_P (XEXP (XEXP (op, 0), 0))
727 && REG_P (XEXP (XEXP (op, 0), 1)))
728 return 0;
730 return memory_address_p (mode, XEXP (op, 0));
733 /* Accept REG and any CONST_INT that can be moved in one instruction into a
734 general register. */
736 reg_or_cint_move_operand (rtx op, enum machine_mode mode)
738 if (register_operand (op, mode))
739 return 1;
741 return (GET_CODE (op) == CONST_INT && cint_ok_for_move (INTVAL (op)));
745 pic_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
747 if (!flag_pic)
748 return 0;
750 switch (GET_CODE (op))
752 case LABEL_REF:
753 return 1;
754 case CONST:
755 op = XEXP (op, 0);
756 return (GET_CODE (XEXP (op, 0)) == LABEL_REF
757 && GET_CODE (XEXP (op, 1)) == CONST_INT);
758 default:
759 return 0;
764 fp_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766 return reg_renumber && FP_REG_P (op);
771 /* Return truth value of whether OP can be used as an operand in a
772 three operand arithmetic insn that accepts registers of mode MODE
773 or 14-bit signed integers. */
775 arith_operand (rtx op, enum machine_mode mode)
777 return (register_operand (op, mode)
778 || (GET_CODE (op) == CONST_INT && INT_14_BITS (op)));
781 /* Return truth value of whether OP can be used as an operand in a
782 three operand arithmetic insn that accepts registers of mode MODE
783 or 11-bit signed integers. */
785 arith11_operand (rtx op, enum machine_mode mode)
787 return (register_operand (op, mode)
788 || (GET_CODE (op) == CONST_INT && INT_11_BITS (op)));
791 /* Return truth value of whether OP can be used as an operand in a
792 adddi3 insn. */
794 adddi3_operand (rtx op, enum machine_mode mode)
796 return (register_operand (op, mode)
797 || (GET_CODE (op) == CONST_INT
798 && (TARGET_64BIT ? INT_14_BITS (op) : INT_11_BITS (op))));
801 /* A constant integer suitable for use in a PRE_MODIFY memory
802 reference. */
804 pre_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
806 return (GET_CODE (op) == CONST_INT
807 && INTVAL (op) >= -0x2000 && INTVAL (op) < 0x10);
810 /* A constant integer suitable for use in a POST_MODIFY memory
811 reference. */
813 post_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
815 return (GET_CODE (op) == CONST_INT
816 && INTVAL (op) < 0x2000 && INTVAL (op) >= -0x10);
820 arith_double_operand (rtx op, enum machine_mode mode)
822 return (register_operand (op, mode)
823 || (GET_CODE (op) == CONST_DOUBLE
824 && GET_MODE (op) == mode
825 && VAL_14_BITS_P (CONST_DOUBLE_LOW (op))
826 && ((CONST_DOUBLE_HIGH (op) >= 0)
827 == ((CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
830 /* Return truth value of whether OP is an integer which fits the
831 range constraining immediate operands in three-address insns, or
832 is an integer register. */
835 ireg_or_int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
837 return ((GET_CODE (op) == CONST_INT && INT_5_BITS (op))
838 || (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32));
841 /* Return nonzero if OP is an integer register, else return zero. */
843 ireg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
845 return (GET_CODE (op) == REG && REGNO (op) > 0 && REGNO (op) < 32);
848 /* Return truth value of whether OP is an integer which fits the
849 range constraining immediate operands in three-address insns. */
852 int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
854 return (GET_CODE (op) == CONST_INT && INT_5_BITS (op));
858 uint5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
860 return (GET_CODE (op) == CONST_INT && INT_U5_BITS (op));
864 int11_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
866 return (GET_CODE (op) == CONST_INT && INT_11_BITS (op));
870 uint32_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
872 #if HOST_BITS_PER_WIDE_INT > 32
873 /* All allowed constants will fit a CONST_INT. */
874 return (GET_CODE (op) == CONST_INT
875 && (INTVAL (op) >= 0 && INTVAL (op) < (HOST_WIDE_INT) 1 << 32));
876 #else
877 return (GET_CODE (op) == CONST_INT
878 || (GET_CODE (op) == CONST_DOUBLE
879 && CONST_DOUBLE_HIGH (op) == 0));
880 #endif
884 arith5_operand (rtx op, enum machine_mode mode)
886 return register_operand (op, mode) || int5_operand (op, mode);
889 /* True iff zdepi can be used to generate this CONST_INT.
890 zdepi first sign extends a 5 bit signed number to a given field
891 length, then places this field anywhere in a zero. */
893 zdepi_cint_p (unsigned HOST_WIDE_INT x)
895 unsigned HOST_WIDE_INT lsb_mask, t;
897 /* This might not be obvious, but it's at least fast.
898 This function is critical; we don't have the time loops would take. */
899 lsb_mask = x & -x;
900 t = ((x >> 4) + lsb_mask) & ~(lsb_mask - 1);
901 /* Return true iff t is a power of two. */
902 return ((t & (t - 1)) == 0);
905 /* True iff depi or extru can be used to compute (reg & mask).
906 Accept bit pattern like these:
907 0....01....1
908 1....10....0
909 1..10..01..1 */
911 and_mask_p (unsigned HOST_WIDE_INT mask)
913 mask = ~mask;
914 mask += mask & -mask;
915 return (mask & (mask - 1)) == 0;
918 /* True iff depi or extru can be used to compute (reg & OP). */
920 and_operand (rtx op, enum machine_mode mode)
922 return (register_operand (op, mode)
923 || (GET_CODE (op) == CONST_INT && and_mask_p (INTVAL (op))));
926 /* True iff depi can be used to compute (reg | MASK). */
928 ior_mask_p (unsigned HOST_WIDE_INT mask)
930 mask += mask & -mask;
931 return (mask & (mask - 1)) == 0;
934 /* True iff depi can be used to compute (reg | OP). */
936 ior_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
938 return (GET_CODE (op) == CONST_INT && ior_mask_p (INTVAL (op)));
942 lhs_lshift_operand (rtx op, enum machine_mode mode)
944 return register_operand (op, mode) || lhs_lshift_cint_operand (op, mode);
947 /* True iff OP is a CONST_INT of the forms 0...0xxxx or 0...01...1xxxx.
948 Such values can be the left hand side x in (x << r), using the zvdepi
949 instruction. */
951 lhs_lshift_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
953 unsigned HOST_WIDE_INT x;
954 if (GET_CODE (op) != CONST_INT)
955 return 0;
956 x = INTVAL (op) >> 4;
957 return (x & (x + 1)) == 0;
961 arith32_operand (rtx op, enum machine_mode mode)
963 return register_operand (op, mode) || GET_CODE (op) == CONST_INT;
967 pc_or_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
969 return (GET_CODE (op) == PC || GET_CODE (op) == LABEL_REF);
972 /* Legitimize PIC addresses. If the address is already
973 position-independent, we return ORIG. Newly generated
974 position-independent addresses go to REG. If we need more
975 than one register, we lose. */
978 legitimize_pic_address (rtx orig, enum machine_mode mode, rtx reg)
980 rtx pic_ref = orig;
982 /* Labels need special handling. */
983 if (pic_label_operand (orig, mode))
985 /* We do not want to go through the movXX expanders here since that
986 would create recursion.
988 Nor do we really want to call a generator for a named pattern
989 since that requires multiple patterns if we want to support
990 multiple word sizes.
992 So instead we just emit the raw set, which avoids the movXX
993 expanders completely. */
994 mark_reg_pointer (reg, BITS_PER_UNIT);
995 emit_insn (gen_rtx_SET (VOIDmode, reg, orig));
996 current_function_uses_pic_offset_table = 1;
997 return reg;
999 if (GET_CODE (orig) == SYMBOL_REF)
1001 rtx insn, tmp_reg;
1003 if (reg == 0)
1004 abort ();
1006 /* Before reload, allocate a temporary register for the intermediate
1007 result. This allows the sequence to be deleted when the final
1008 result is unused and the insns are trivially dead. */
1009 tmp_reg = ((reload_in_progress || reload_completed)
1010 ? reg : gen_reg_rtx (Pmode));
1012 emit_move_insn (tmp_reg,
1013 gen_rtx_PLUS (word_mode, pic_offset_table_rtx,
1014 gen_rtx_HIGH (word_mode, orig)));
1015 pic_ref
1016 = gen_const_mem (Pmode,
1017 gen_rtx_LO_SUM (Pmode, tmp_reg,
1018 gen_rtx_UNSPEC (Pmode,
1019 gen_rtvec (1, orig),
1020 UNSPEC_DLTIND14R)));
1022 current_function_uses_pic_offset_table = 1;
1023 mark_reg_pointer (reg, BITS_PER_UNIT);
1024 insn = emit_move_insn (reg, pic_ref);
1026 /* Put a REG_EQUAL note on this insn, so that it can be optimized. */
1027 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig, REG_NOTES (insn));
1029 return reg;
1031 else if (GET_CODE (orig) == CONST)
1033 rtx base;
1035 if (GET_CODE (XEXP (orig, 0)) == PLUS
1036 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1037 return orig;
1039 if (reg == 0)
1040 abort ();
1042 if (GET_CODE (XEXP (orig, 0)) == PLUS)
1044 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1045 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1046 base == reg ? 0 : reg);
1048 else
1049 abort ();
1051 if (GET_CODE (orig) == CONST_INT)
1053 if (INT_14_BITS (orig))
1054 return plus_constant (base, INTVAL (orig));
1055 orig = force_reg (Pmode, orig);
1057 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
1058 /* Likewise, should we set special REG_NOTEs here? */
1061 return pic_ref;
1064 /* Try machine-dependent ways of modifying an illegitimate address
1065 to be legitimate. If we find one, return the new, valid address.
1066 This macro is used in only one place: `memory_address' in explow.c.
1068 OLDX is the address as it was before break_out_memory_refs was called.
1069 In some cases it is useful to look at this to decide what needs to be done.
1071 MODE and WIN are passed so that this macro can use
1072 GO_IF_LEGITIMATE_ADDRESS.
1074 It is always safe for this macro to do nothing. It exists to recognize
1075 opportunities to optimize the output.
1077 For the PA, transform:
1079 memory(X + <large int>)
1081 into:
1083 if (<large int> & mask) >= 16
1084 Y = (<large int> & ~mask) + mask + 1 Round up.
1085 else
1086 Y = (<large int> & ~mask) Round down.
1087 Z = X + Y
1088 memory (Z + (<large int> - Y));
1090 This is for CSE to find several similar references, and only use one Z.
1092 X can either be a SYMBOL_REF or REG, but because combine cannot
1093 perform a 4->2 combination we do nothing for SYMBOL_REF + D where
1094 D will not fit in 14 bits.
1096 MODE_FLOAT references allow displacements which fit in 5 bits, so use
1097 0x1f as the mask.
1099 MODE_INT references allow displacements which fit in 14 bits, so use
1100 0x3fff as the mask.
1102 This relies on the fact that most mode MODE_FLOAT references will use FP
1103 registers and most mode MODE_INT references will use integer registers.
1104 (In the rare case of an FP register used in an integer MODE, we depend
1105 on secondary reloads to clean things up.)
1108 It is also beneficial to handle (plus (mult (X) (Y)) (Z)) in a special
1109 manner if Y is 2, 4, or 8. (allows more shadd insns and shifted indexed
1110 addressing modes to be used).
1112 Put X and Z into registers. Then put the entire expression into
1113 a register. */
1116 hppa_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1117 enum machine_mode mode)
1119 rtx orig = x;
1121 /* We need to canonicalize the order of operands in unscaled indexed
1122 addresses since the code that checks if an address is valid doesn't
1123 always try both orders. */
1124 if (!TARGET_NO_SPACE_REGS
1125 && GET_CODE (x) == PLUS
1126 && GET_MODE (x) == Pmode
1127 && REG_P (XEXP (x, 0))
1128 && REG_P (XEXP (x, 1))
1129 && REG_POINTER (XEXP (x, 0))
1130 && !REG_POINTER (XEXP (x, 1)))
1131 return gen_rtx_PLUS (Pmode, XEXP (x, 1), XEXP (x, 0));
1133 if (flag_pic)
1134 return legitimize_pic_address (x, mode, gen_reg_rtx (Pmode));
1136 /* Strip off CONST. */
1137 if (GET_CODE (x) == CONST)
1138 x = XEXP (x, 0);
1140 /* Special case. Get the SYMBOL_REF into a register and use indexing.
1141 That should always be safe. */
1142 if (GET_CODE (x) == PLUS
1143 && GET_CODE (XEXP (x, 0)) == REG
1144 && GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
1146 rtx reg = force_reg (Pmode, XEXP (x, 1));
1147 return force_reg (Pmode, gen_rtx_PLUS (Pmode, reg, XEXP (x, 0)));
1150 /* Note we must reject symbols which represent function addresses
1151 since the assembler/linker can't handle arithmetic on plabels. */
1152 if (GET_CODE (x) == PLUS
1153 && GET_CODE (XEXP (x, 1)) == CONST_INT
1154 && ((GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1155 && !FUNCTION_NAME_P (XSTR (XEXP (x, 0), 0)))
1156 || GET_CODE (XEXP (x, 0)) == REG))
1158 rtx int_part, ptr_reg;
1159 int newoffset;
1160 int offset = INTVAL (XEXP (x, 1));
1161 int mask;
1163 mask = (GET_MODE_CLASS (mode) == MODE_FLOAT
1164 ? (TARGET_PA_20 ? 0x3fff : 0x1f) : 0x3fff);
1166 /* Choose which way to round the offset. Round up if we
1167 are >= halfway to the next boundary. */
1168 if ((offset & mask) >= ((mask + 1) / 2))
1169 newoffset = (offset & ~ mask) + mask + 1;
1170 else
1171 newoffset = (offset & ~ mask);
1173 /* If the newoffset will not fit in 14 bits (ldo), then
1174 handling this would take 4 or 5 instructions (2 to load
1175 the SYMBOL_REF + 1 or 2 to load the newoffset + 1 to
1176 add the new offset and the SYMBOL_REF.) Combine can
1177 not handle 4->2 or 5->2 combinations, so do not create
1178 them. */
1179 if (! VAL_14_BITS_P (newoffset)
1180 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
1182 rtx const_part = plus_constant (XEXP (x, 0), newoffset);
1183 rtx tmp_reg
1184 = force_reg (Pmode,
1185 gen_rtx_HIGH (Pmode, const_part));
1186 ptr_reg
1187 = force_reg (Pmode,
1188 gen_rtx_LO_SUM (Pmode,
1189 tmp_reg, const_part));
1191 else
1193 if (! VAL_14_BITS_P (newoffset))
1194 int_part = force_reg (Pmode, GEN_INT (newoffset));
1195 else
1196 int_part = GEN_INT (newoffset);
1198 ptr_reg = force_reg (Pmode,
1199 gen_rtx_PLUS (Pmode,
1200 force_reg (Pmode, XEXP (x, 0)),
1201 int_part));
1203 return plus_constant (ptr_reg, offset - newoffset);
1206 /* Handle (plus (mult (a) (shadd_constant)) (b)). */
1208 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1209 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1210 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1)))
1211 && (OBJECT_P (XEXP (x, 1))
1212 || GET_CODE (XEXP (x, 1)) == SUBREG)
1213 && GET_CODE (XEXP (x, 1)) != CONST)
1215 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1216 rtx reg1, reg2;
1218 reg1 = XEXP (x, 1);
1219 if (GET_CODE (reg1) != REG)
1220 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1222 reg2 = XEXP (XEXP (x, 0), 0);
1223 if (GET_CODE (reg2) != REG)
1224 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1226 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1227 gen_rtx_MULT (Pmode,
1228 reg2,
1229 GEN_INT (val)),
1230 reg1));
1233 /* Similarly for (plus (plus (mult (a) (shadd_constant)) (b)) (c)).
1235 Only do so for floating point modes since this is more speculative
1236 and we lose if it's an integer store. */
1237 if (GET_CODE (x) == PLUS
1238 && GET_CODE (XEXP (x, 0)) == PLUS
1239 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1240 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
1241 && shadd_constant_p (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1242 && (mode == SFmode || mode == DFmode))
1245 /* First, try and figure out what to use as a base register. */
1246 rtx reg1, reg2, base, idx, orig_base;
1248 reg1 = XEXP (XEXP (x, 0), 1);
1249 reg2 = XEXP (x, 1);
1250 base = NULL_RTX;
1251 idx = NULL_RTX;
1253 /* Make sure they're both regs. If one was a SYMBOL_REF [+ const],
1254 then emit_move_sequence will turn on REG_POINTER so we'll know
1255 it's a base register below. */
1256 if (GET_CODE (reg1) != REG)
1257 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1259 if (GET_CODE (reg2) != REG)
1260 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1262 /* Figure out what the base and index are. */
1264 if (GET_CODE (reg1) == REG
1265 && REG_POINTER (reg1))
1267 base = reg1;
1268 orig_base = XEXP (XEXP (x, 0), 1);
1269 idx = gen_rtx_PLUS (Pmode,
1270 gen_rtx_MULT (Pmode,
1271 XEXP (XEXP (XEXP (x, 0), 0), 0),
1272 XEXP (XEXP (XEXP (x, 0), 0), 1)),
1273 XEXP (x, 1));
1275 else if (GET_CODE (reg2) == REG
1276 && REG_POINTER (reg2))
1278 base = reg2;
1279 orig_base = XEXP (x, 1);
1280 idx = XEXP (x, 0);
1283 if (base == 0)
1284 return orig;
1286 /* If the index adds a large constant, try to scale the
1287 constant so that it can be loaded with only one insn. */
1288 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1289 && VAL_14_BITS_P (INTVAL (XEXP (idx, 1))
1290 / INTVAL (XEXP (XEXP (idx, 0), 1)))
1291 && INTVAL (XEXP (idx, 1)) % INTVAL (XEXP (XEXP (idx, 0), 1)) == 0)
1293 /* Divide the CONST_INT by the scale factor, then add it to A. */
1294 int val = INTVAL (XEXP (idx, 1));
1296 val /= INTVAL (XEXP (XEXP (idx, 0), 1));
1297 reg1 = XEXP (XEXP (idx, 0), 0);
1298 if (GET_CODE (reg1) != REG)
1299 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1301 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, reg1, GEN_INT (val)));
1303 /* We can now generate a simple scaled indexed address. */
1304 return
1305 force_reg
1306 (Pmode, gen_rtx_PLUS (Pmode,
1307 gen_rtx_MULT (Pmode, reg1,
1308 XEXP (XEXP (idx, 0), 1)),
1309 base));
1312 /* If B + C is still a valid base register, then add them. */
1313 if (GET_CODE (XEXP (idx, 1)) == CONST_INT
1314 && INTVAL (XEXP (idx, 1)) <= 4096
1315 && INTVAL (XEXP (idx, 1)) >= -4096)
1317 int val = INTVAL (XEXP (XEXP (idx, 0), 1));
1318 rtx reg1, reg2;
1320 reg1 = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, XEXP (idx, 1)));
1322 reg2 = XEXP (XEXP (idx, 0), 0);
1323 if (GET_CODE (reg2) != CONST_INT)
1324 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1326 return force_reg (Pmode, gen_rtx_PLUS (Pmode,
1327 gen_rtx_MULT (Pmode,
1328 reg2,
1329 GEN_INT (val)),
1330 reg1));
1333 /* Get the index into a register, then add the base + index and
1334 return a register holding the result. */
1336 /* First get A into a register. */
1337 reg1 = XEXP (XEXP (idx, 0), 0);
1338 if (GET_CODE (reg1) != REG)
1339 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1341 /* And get B into a register. */
1342 reg2 = XEXP (idx, 1);
1343 if (GET_CODE (reg2) != REG)
1344 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1346 reg1 = force_reg (Pmode,
1347 gen_rtx_PLUS (Pmode,
1348 gen_rtx_MULT (Pmode, reg1,
1349 XEXP (XEXP (idx, 0), 1)),
1350 reg2));
1352 /* Add the result to our base register and return. */
1353 return force_reg (Pmode, gen_rtx_PLUS (Pmode, base, reg1));
1357 /* Uh-oh. We might have an address for x[n-100000]. This needs
1358 special handling to avoid creating an indexed memory address
1359 with x-100000 as the base.
1361 If the constant part is small enough, then it's still safe because
1362 there is a guard page at the beginning and end of the data segment.
1364 Scaled references are common enough that we want to try and rearrange the
1365 terms so that we can use indexing for these addresses too. Only
1366 do the optimization for floatint point modes. */
1368 if (GET_CODE (x) == PLUS
1369 && symbolic_expression_p (XEXP (x, 1)))
1371 /* Ugly. We modify things here so that the address offset specified
1372 by the index expression is computed first, then added to x to form
1373 the entire address. */
1375 rtx regx1, regx2, regy1, regy2, y;
1377 /* Strip off any CONST. */
1378 y = XEXP (x, 1);
1379 if (GET_CODE (y) == CONST)
1380 y = XEXP (y, 0);
1382 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1384 /* See if this looks like
1385 (plus (mult (reg) (shadd_const))
1386 (const (plus (symbol_ref) (const_int))))
1388 Where const_int is small. In that case the const
1389 expression is a valid pointer for indexing.
1391 If const_int is big, but can be divided evenly by shadd_const
1392 and added to (reg). This allows more scaled indexed addresses. */
1393 if (GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1394 && GET_CODE (XEXP (x, 0)) == MULT
1395 && GET_CODE (XEXP (y, 1)) == CONST_INT
1396 && INTVAL (XEXP (y, 1)) >= -4096
1397 && INTVAL (XEXP (y, 1)) <= 4095
1398 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1399 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1401 int val = INTVAL (XEXP (XEXP (x, 0), 1));
1402 rtx reg1, reg2;
1404 reg1 = XEXP (x, 1);
1405 if (GET_CODE (reg1) != REG)
1406 reg1 = force_reg (Pmode, force_operand (reg1, 0));
1408 reg2 = XEXP (XEXP (x, 0), 0);
1409 if (GET_CODE (reg2) != REG)
1410 reg2 = force_reg (Pmode, force_operand (reg2, 0));
1412 return force_reg (Pmode,
1413 gen_rtx_PLUS (Pmode,
1414 gen_rtx_MULT (Pmode,
1415 reg2,
1416 GEN_INT (val)),
1417 reg1));
1419 else if ((mode == DFmode || mode == SFmode)
1420 && GET_CODE (XEXP (y, 0)) == SYMBOL_REF
1421 && GET_CODE (XEXP (x, 0)) == MULT
1422 && GET_CODE (XEXP (y, 1)) == CONST_INT
1423 && INTVAL (XEXP (y, 1)) % INTVAL (XEXP (XEXP (x, 0), 1)) == 0
1424 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1425 && shadd_constant_p (INTVAL (XEXP (XEXP (x, 0), 1))))
1427 regx1
1428 = force_reg (Pmode, GEN_INT (INTVAL (XEXP (y, 1))
1429 / INTVAL (XEXP (XEXP (x, 0), 1))));
1430 regx2 = XEXP (XEXP (x, 0), 0);
1431 if (GET_CODE (regx2) != REG)
1432 regx2 = force_reg (Pmode, force_operand (regx2, 0));
1433 regx2 = force_reg (Pmode, gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1434 regx2, regx1));
1435 return
1436 force_reg (Pmode,
1437 gen_rtx_PLUS (Pmode,
1438 gen_rtx_MULT (Pmode, regx2,
1439 XEXP (XEXP (x, 0), 1)),
1440 force_reg (Pmode, XEXP (y, 0))));
1442 else if (GET_CODE (XEXP (y, 1)) == CONST_INT
1443 && INTVAL (XEXP (y, 1)) >= -4096
1444 && INTVAL (XEXP (y, 1)) <= 4095)
1446 /* This is safe because of the guard page at the
1447 beginning and end of the data space. Just
1448 return the original address. */
1449 return orig;
1451 else
1453 /* Doesn't look like one we can optimize. */
1454 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1455 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1456 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1457 regx1 = force_reg (Pmode,
1458 gen_rtx_fmt_ee (GET_CODE (y), Pmode,
1459 regx1, regy2));
1460 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1465 return orig;
1468 /* For the HPPA, REG and REG+CONST is cost 0
1469 and addresses involving symbolic constants are cost 2.
1471 PIC addresses are very expensive.
1473 It is no coincidence that this has the same structure
1474 as GO_IF_LEGITIMATE_ADDRESS. */
1476 static int
1477 hppa_address_cost (rtx X)
1479 switch (GET_CODE (X))
1481 case REG:
1482 case PLUS:
1483 case LO_SUM:
1484 return 1;
1485 case HIGH:
1486 return 2;
1487 default:
1488 return 4;
1492 /* Compute a (partial) cost for rtx X. Return true if the complete
1493 cost has been computed, and false if subexpressions should be
1494 scanned. In either case, *TOTAL contains the cost result. */
1496 static bool
1497 hppa_rtx_costs (rtx x, int code, int outer_code, int *total)
1499 switch (code)
1501 case CONST_INT:
1502 if (INTVAL (x) == 0)
1503 *total = 0;
1504 else if (INT_14_BITS (x))
1505 *total = 1;
1506 else
1507 *total = 2;
1508 return true;
1510 case HIGH:
1511 *total = 2;
1512 return true;
1514 case CONST:
1515 case LABEL_REF:
1516 case SYMBOL_REF:
1517 *total = 4;
1518 return true;
1520 case CONST_DOUBLE:
1521 if ((x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
1522 && outer_code != SET)
1523 *total = 0;
1524 else
1525 *total = 8;
1526 return true;
1528 case MULT:
1529 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1530 *total = COSTS_N_INSNS (3);
1531 else if (TARGET_PA_11 && !TARGET_DISABLE_FPREGS && !TARGET_SOFT_FLOAT)
1532 *total = COSTS_N_INSNS (8);
1533 else
1534 *total = COSTS_N_INSNS (20);
1535 return true;
1537 case DIV:
1538 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1540 *total = COSTS_N_INSNS (14);
1541 return true;
1543 /* FALLTHRU */
1545 case UDIV:
1546 case MOD:
1547 case UMOD:
1548 *total = COSTS_N_INSNS (60);
1549 return true;
1551 case PLUS: /* this includes shNadd insns */
1552 case MINUS:
1553 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1554 *total = COSTS_N_INSNS (3);
1555 else
1556 *total = COSTS_N_INSNS (1);
1557 return true;
1559 case ASHIFT:
1560 case ASHIFTRT:
1561 case LSHIFTRT:
1562 *total = COSTS_N_INSNS (1);
1563 return true;
1565 default:
1566 return false;
1570 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
1571 new rtx with the correct mode. */
1572 static inline rtx
1573 force_mode (enum machine_mode mode, rtx orig)
1575 if (mode == GET_MODE (orig))
1576 return orig;
1578 if (REGNO (orig) >= FIRST_PSEUDO_REGISTER)
1579 abort ();
1581 return gen_rtx_REG (mode, REGNO (orig));
1584 /* Emit insns to move operands[1] into operands[0].
1586 Return 1 if we have written out everything that needs to be done to
1587 do the move. Otherwise, return 0 and the caller will emit the move
1588 normally.
1590 Note SCRATCH_REG may not be in the proper mode depending on how it
1591 will be used. This routine is responsible for creating a new copy
1592 of SCRATCH_REG in the proper mode. */
1595 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
1597 register rtx operand0 = operands[0];
1598 register rtx operand1 = operands[1];
1599 register rtx tem;
1601 /* We can only handle indexed addresses in the destination operand
1602 of floating point stores. Thus, we need to break out indexed
1603 addresses from the destination operand. */
1604 if (GET_CODE (operand0) == MEM && IS_INDEX_ADDR_P (XEXP (operand0, 0)))
1606 /* This is only safe up to the beginning of life analysis. */
1607 if (no_new_pseudos)
1608 abort ();
1610 tem = copy_to_mode_reg (Pmode, XEXP (operand0, 0));
1611 operand0 = replace_equiv_address (operand0, tem);
1614 /* On targets with non-equivalent space registers, break out unscaled
1615 indexed addresses from the source operand before the final CSE.
1616 We have to do this because the REG_POINTER flag is not correctly
1617 carried through various optimization passes and CSE may substitute
1618 a pseudo without the pointer set for one with the pointer set. As
1619 a result, we loose various opportunities to create insns with
1620 unscaled indexed addresses. */
1621 if (!TARGET_NO_SPACE_REGS
1622 && !cse_not_expected
1623 && GET_CODE (operand1) == MEM
1624 && GET_CODE (XEXP (operand1, 0)) == PLUS
1625 && REG_P (XEXP (XEXP (operand1, 0), 0))
1626 && REG_P (XEXP (XEXP (operand1, 0), 1)))
1627 operand1
1628 = replace_equiv_address (operand1,
1629 copy_to_mode_reg (Pmode, XEXP (operand1, 0)));
1631 if (scratch_reg
1632 && reload_in_progress && GET_CODE (operand0) == REG
1633 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
1634 operand0 = reg_equiv_mem[REGNO (operand0)];
1635 else if (scratch_reg
1636 && reload_in_progress && GET_CODE (operand0) == SUBREG
1637 && GET_CODE (SUBREG_REG (operand0)) == REG
1638 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
1640 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1641 the code which tracks sets/uses for delete_output_reload. */
1642 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
1643 reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
1644 SUBREG_BYTE (operand0));
1645 operand0 = alter_subreg (&temp);
1648 if (scratch_reg
1649 && reload_in_progress && GET_CODE (operand1) == REG
1650 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
1651 operand1 = reg_equiv_mem[REGNO (operand1)];
1652 else if (scratch_reg
1653 && reload_in_progress && GET_CODE (operand1) == SUBREG
1654 && GET_CODE (SUBREG_REG (operand1)) == REG
1655 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
1657 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
1658 the code which tracks sets/uses for delete_output_reload. */
1659 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
1660 reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
1661 SUBREG_BYTE (operand1));
1662 operand1 = alter_subreg (&temp);
1665 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
1666 && ((tem = find_replacement (&XEXP (operand0, 0)))
1667 != XEXP (operand0, 0)))
1668 operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
1670 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
1671 && ((tem = find_replacement (&XEXP (operand1, 0)))
1672 != XEXP (operand1, 0)))
1673 operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
1675 /* Handle secondary reloads for loads/stores of FP registers from
1676 REG+D addresses where D does not fit in 5 or 14 bits, including
1677 (subreg (mem (addr))) cases. */
1678 if (scratch_reg
1679 && fp_reg_operand (operand0, mode)
1680 && ((GET_CODE (operand1) == MEM
1681 && !memory_address_p ((GET_MODE_SIZE (mode) == 4 ? SFmode : DFmode),
1682 XEXP (operand1, 0)))
1683 || ((GET_CODE (operand1) == SUBREG
1684 && GET_CODE (XEXP (operand1, 0)) == MEM
1685 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1686 ? SFmode : DFmode),
1687 XEXP (XEXP (operand1, 0), 0))))))
1689 if (GET_CODE (operand1) == SUBREG)
1690 operand1 = XEXP (operand1, 0);
1692 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1693 it in WORD_MODE regardless of what mode it was originally given
1694 to us. */
1695 scratch_reg = force_mode (word_mode, scratch_reg);
1697 /* D might not fit in 14 bits either; for such cases load D into
1698 scratch reg. */
1699 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
1701 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1702 emit_move_insn (scratch_reg,
1703 gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
1704 Pmode,
1705 XEXP (XEXP (operand1, 0), 0),
1706 scratch_reg));
1708 else
1709 emit_move_insn (scratch_reg, XEXP (operand1, 0));
1710 emit_insn (gen_rtx_SET (VOIDmode, operand0,
1711 gen_rtx_MEM (mode, scratch_reg)));
1712 return 1;
1714 else if (scratch_reg
1715 && fp_reg_operand (operand1, mode)
1716 && ((GET_CODE (operand0) == MEM
1717 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1718 ? SFmode : DFmode),
1719 XEXP (operand0, 0)))
1720 || ((GET_CODE (operand0) == SUBREG)
1721 && GET_CODE (XEXP (operand0, 0)) == MEM
1722 && !memory_address_p ((GET_MODE_SIZE (mode) == 4
1723 ? SFmode : DFmode),
1724 XEXP (XEXP (operand0, 0), 0)))))
1726 if (GET_CODE (operand0) == SUBREG)
1727 operand0 = XEXP (operand0, 0);
1729 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1730 it in WORD_MODE regardless of what mode it was originally given
1731 to us. */
1732 scratch_reg = force_mode (word_mode, scratch_reg);
1734 /* D might not fit in 14 bits either; for such cases load D into
1735 scratch reg. */
1736 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
1738 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
1739 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
1740 0)),
1741 Pmode,
1742 XEXP (XEXP (operand0, 0),
1744 scratch_reg));
1746 else
1747 emit_move_insn (scratch_reg, XEXP (operand0, 0));
1748 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
1749 operand1));
1750 return 1;
1752 /* Handle secondary reloads for loads of FP registers from constant
1753 expressions by forcing the constant into memory.
1755 Use scratch_reg to hold the address of the memory location.
1757 The proper fix is to change PREFERRED_RELOAD_CLASS to return
1758 NO_REGS when presented with a const_int and a register class
1759 containing only FP registers. Doing so unfortunately creates
1760 more problems than it solves. Fix this for 2.5. */
1761 else if (scratch_reg
1762 && CONSTANT_P (operand1)
1763 && fp_reg_operand (operand0, mode))
1765 rtx xoperands[2];
1767 /* SCRATCH_REG will hold an address and maybe the actual data. We want
1768 it in WORD_MODE regardless of what mode it was originally given
1769 to us. */
1770 scratch_reg = force_mode (word_mode, scratch_reg);
1772 /* Force the constant into memory and put the address of the
1773 memory location into scratch_reg. */
1774 xoperands[0] = scratch_reg;
1775 xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
1776 emit_move_sequence (xoperands, Pmode, 0);
1778 /* Now load the destination register. */
1779 emit_insn (gen_rtx_SET (mode, operand0,
1780 gen_rtx_MEM (mode, scratch_reg)));
1781 return 1;
1783 /* Handle secondary reloads for SAR. These occur when trying to load
1784 the SAR from memory, FP register, or with a constant. */
1785 else if (scratch_reg
1786 && GET_CODE (operand0) == REG
1787 && REGNO (operand0) < FIRST_PSEUDO_REGISTER
1788 && REGNO_REG_CLASS (REGNO (operand0)) == SHIFT_REGS
1789 && (GET_CODE (operand1) == MEM
1790 || GET_CODE (operand1) == CONST_INT
1791 || (GET_CODE (operand1) == REG
1792 && FP_REG_CLASS_P (REGNO_REG_CLASS (REGNO (operand1))))))
1794 /* D might not fit in 14 bits either; for such cases load D into
1795 scratch reg. */
1796 if (GET_CODE (operand1) == MEM
1797 && !memory_address_p (Pmode, XEXP (operand1, 0)))
1799 /* We are reloading the address into the scratch register, so we
1800 want to make sure the scratch register is a full register. */
1801 scratch_reg = force_mode (word_mode, scratch_reg);
1803 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
1804 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1,
1805 0)),
1806 Pmode,
1807 XEXP (XEXP (operand1, 0),
1809 scratch_reg));
1811 /* Now we are going to load the scratch register from memory,
1812 we want to load it in the same width as the original MEM,
1813 which must be the same as the width of the ultimate destination,
1814 OPERAND0. */
1815 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1817 emit_move_insn (scratch_reg, gen_rtx_MEM (GET_MODE (operand0),
1818 scratch_reg));
1820 else
1822 /* We want to load the scratch register using the same mode as
1823 the ultimate destination. */
1824 scratch_reg = force_mode (GET_MODE (operand0), scratch_reg);
1826 emit_move_insn (scratch_reg, operand1);
1829 /* And emit the insn to set the ultimate destination. We know that
1830 the scratch register has the same mode as the destination at this
1831 point. */
1832 emit_move_insn (operand0, scratch_reg);
1833 return 1;
1835 /* Handle the most common case: storing into a register. */
1836 else if (register_operand (operand0, mode))
1838 if (register_operand (operand1, mode)
1839 || (GET_CODE (operand1) == CONST_INT
1840 && cint_ok_for_move (INTVAL (operand1)))
1841 || (operand1 == CONST0_RTX (mode))
1842 || (GET_CODE (operand1) == HIGH
1843 && !symbolic_operand (XEXP (operand1, 0), VOIDmode))
1844 /* Only `general_operands' can come here, so MEM is ok. */
1845 || GET_CODE (operand1) == MEM)
1847 /* Various sets are created during RTL generation which don't
1848 have the REG_POINTER flag correctly set. After the CSE pass,
1849 instruction recognition can fail if we don't consistently
1850 set this flag when performing register copies. This should
1851 also improve the opportunities for creating insns that use
1852 unscaled indexing. */
1853 if (REG_P (operand0) && REG_P (operand1))
1855 if (REG_POINTER (operand1)
1856 && !REG_POINTER (operand0)
1857 && !HARD_REGISTER_P (operand0))
1858 copy_reg_pointer (operand0, operand1);
1859 else if (REG_POINTER (operand0)
1860 && !REG_POINTER (operand1)
1861 && !HARD_REGISTER_P (operand1))
1862 copy_reg_pointer (operand1, operand0);
1865 /* When MEMs are broken out, the REG_POINTER flag doesn't
1866 get set. In some cases, we can set the REG_POINTER flag
1867 from the declaration for the MEM. */
1868 if (REG_P (operand0)
1869 && GET_CODE (operand1) == MEM
1870 && !REG_POINTER (operand0))
1872 tree decl = MEM_EXPR (operand1);
1874 /* Set the register pointer flag and register alignment
1875 if the declaration for this memory reference is a
1876 pointer type. Fortran indirect argument references
1877 are ignored. */
1878 if (decl
1879 && !(flag_argument_noalias > 1
1880 && TREE_CODE (decl) == INDIRECT_REF
1881 && TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL))
1883 tree type;
1885 /* If this is a COMPONENT_REF, use the FIELD_DECL from
1886 tree operand 1. */
1887 if (TREE_CODE (decl) == COMPONENT_REF)
1888 decl = TREE_OPERAND (decl, 1);
1890 type = TREE_TYPE (decl);
1891 if (TREE_CODE (type) == ARRAY_TYPE)
1892 type = get_inner_array_type (type);
1894 if (POINTER_TYPE_P (type))
1896 int align;
1898 type = TREE_TYPE (type);
1899 /* Using TYPE_ALIGN_OK is rather conservative as
1900 only the ada frontend actually sets it. */
1901 align = (TYPE_ALIGN_OK (type) ? TYPE_ALIGN (type)
1902 : BITS_PER_UNIT);
1903 mark_reg_pointer (operand0, align);
1908 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1909 return 1;
1912 else if (GET_CODE (operand0) == MEM)
1914 if (mode == DFmode && operand1 == CONST0_RTX (mode)
1915 && !(reload_in_progress || reload_completed))
1917 rtx temp = gen_reg_rtx (DFmode);
1919 emit_insn (gen_rtx_SET (VOIDmode, temp, operand1));
1920 emit_insn (gen_rtx_SET (VOIDmode, operand0, temp));
1921 return 1;
1923 if (register_operand (operand1, mode) || operand1 == CONST0_RTX (mode))
1925 /* Run this case quickly. */
1926 emit_insn (gen_rtx_SET (VOIDmode, operand0, operand1));
1927 return 1;
1929 if (! (reload_in_progress || reload_completed))
1931 operands[0] = validize_mem (operand0);
1932 operands[1] = operand1 = force_reg (mode, operand1);
1936 /* Simplify the source if we need to.
1937 Note we do have to handle function labels here, even though we do
1938 not consider them legitimate constants. Loop optimizations can
1939 call the emit_move_xxx with one as a source. */
1940 if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
1941 || function_label_operand (operand1, mode)
1942 || (GET_CODE (operand1) == HIGH
1943 && symbolic_operand (XEXP (operand1, 0), mode)))
1945 int ishighonly = 0;
1947 if (GET_CODE (operand1) == HIGH)
1949 ishighonly = 1;
1950 operand1 = XEXP (operand1, 0);
1952 if (symbolic_operand (operand1, mode))
1954 /* Argh. The assembler and linker can't handle arithmetic
1955 involving plabels.
1957 So we force the plabel into memory, load operand0 from
1958 the memory location, then add in the constant part. */
1959 if ((GET_CODE (operand1) == CONST
1960 && GET_CODE (XEXP (operand1, 0)) == PLUS
1961 && function_label_operand (XEXP (XEXP (operand1, 0), 0), Pmode))
1962 || function_label_operand (operand1, mode))
1964 rtx temp, const_part;
1966 /* Figure out what (if any) scratch register to use. */
1967 if (reload_in_progress || reload_completed)
1969 scratch_reg = scratch_reg ? scratch_reg : operand0;
1970 /* SCRATCH_REG will hold an address and maybe the actual
1971 data. We want it in WORD_MODE regardless of what mode it
1972 was originally given to us. */
1973 scratch_reg = force_mode (word_mode, scratch_reg);
1975 else if (flag_pic)
1976 scratch_reg = gen_reg_rtx (Pmode);
1978 if (GET_CODE (operand1) == CONST)
1980 /* Save away the constant part of the expression. */
1981 const_part = XEXP (XEXP (operand1, 0), 1);
1982 if (GET_CODE (const_part) != CONST_INT)
1983 abort ();
1985 /* Force the function label into memory. */
1986 temp = force_const_mem (mode, XEXP (XEXP (operand1, 0), 0));
1988 else
1990 /* No constant part. */
1991 const_part = NULL_RTX;
1993 /* Force the function label into memory. */
1994 temp = force_const_mem (mode, operand1);
1998 /* Get the address of the memory location. PIC-ify it if
1999 necessary. */
2000 temp = XEXP (temp, 0);
2001 if (flag_pic)
2002 temp = legitimize_pic_address (temp, mode, scratch_reg);
2004 /* Put the address of the memory location into our destination
2005 register. */
2006 operands[1] = temp;
2007 emit_move_sequence (operands, mode, scratch_reg);
2009 /* Now load from the memory location into our destination
2010 register. */
2011 operands[1] = gen_rtx_MEM (Pmode, operands[0]);
2012 emit_move_sequence (operands, mode, scratch_reg);
2014 /* And add back in the constant part. */
2015 if (const_part != NULL_RTX)
2016 expand_inc (operand0, const_part);
2018 return 1;
2021 if (flag_pic)
2023 rtx temp;
2025 if (reload_in_progress || reload_completed)
2027 temp = scratch_reg ? scratch_reg : operand0;
2028 /* TEMP will hold an address and maybe the actual
2029 data. We want it in WORD_MODE regardless of what mode it
2030 was originally given to us. */
2031 temp = force_mode (word_mode, temp);
2033 else
2034 temp = gen_reg_rtx (Pmode);
2036 /* (const (plus (symbol) (const_int))) must be forced to
2037 memory during/after reload if the const_int will not fit
2038 in 14 bits. */
2039 if (GET_CODE (operand1) == CONST
2040 && GET_CODE (XEXP (operand1, 0)) == PLUS
2041 && GET_CODE (XEXP (XEXP (operand1, 0), 1)) == CONST_INT
2042 && !INT_14_BITS (XEXP (XEXP (operand1, 0), 1))
2043 && (reload_completed || reload_in_progress)
2044 && flag_pic)
2046 operands[1] = force_const_mem (mode, operand1);
2047 operands[1] = legitimize_pic_address (XEXP (operands[1], 0),
2048 mode, temp);
2049 operands[1] = gen_rtx_MEM (mode, operands[1]);
2050 emit_move_sequence (operands, mode, temp);
2052 else
2054 operands[1] = legitimize_pic_address (operand1, mode, temp);
2055 if (REG_P (operand0) && REG_P (operands[1]))
2056 copy_reg_pointer (operand0, operands[1]);
2057 emit_insn (gen_rtx_SET (VOIDmode, operand0, operands[1]));
2060 /* On the HPPA, references to data space are supposed to use dp,
2061 register 27, but showing it in the RTL inhibits various cse
2062 and loop optimizations. */
2063 else
2065 rtx temp, set;
2067 if (reload_in_progress || reload_completed)
2069 temp = scratch_reg ? scratch_reg : operand0;
2070 /* TEMP will hold an address and maybe the actual
2071 data. We want it in WORD_MODE regardless of what mode it
2072 was originally given to us. */
2073 temp = force_mode (word_mode, temp);
2075 else
2076 temp = gen_reg_rtx (mode);
2078 /* Loading a SYMBOL_REF into a register makes that register
2079 safe to be used as the base in an indexed address.
2081 Don't mark hard registers though. That loses. */
2082 if (GET_CODE (operand0) == REG
2083 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
2084 mark_reg_pointer (operand0, BITS_PER_UNIT);
2085 if (REGNO (temp) >= FIRST_PSEUDO_REGISTER)
2086 mark_reg_pointer (temp, BITS_PER_UNIT);
2088 if (ishighonly)
2089 set = gen_rtx_SET (mode, operand0, temp);
2090 else
2091 set = gen_rtx_SET (VOIDmode,
2092 operand0,
2093 gen_rtx_LO_SUM (mode, temp, operand1));
2095 emit_insn (gen_rtx_SET (VOIDmode,
2096 temp,
2097 gen_rtx_HIGH (mode, operand1)));
2098 emit_insn (set);
2101 return 1;
2103 else if (GET_CODE (operand1) != CONST_INT
2104 || !cint_ok_for_move (INTVAL (operand1)))
2106 rtx insn, temp;
2107 rtx op1 = operand1;
2108 HOST_WIDE_INT value = 0;
2109 HOST_WIDE_INT insv = 0;
2110 int insert = 0;
2112 if (GET_CODE (operand1) == CONST_INT)
2113 value = INTVAL (operand1);
2115 if (TARGET_64BIT
2116 && GET_CODE (operand1) == CONST_INT
2117 && HOST_BITS_PER_WIDE_INT > 32
2118 && GET_MODE_BITSIZE (GET_MODE (operand0)) > 32)
2120 HOST_WIDE_INT nval;
2122 /* Extract the low order 32 bits of the value and sign extend.
2123 If the new value is the same as the original value, we can
2124 can use the original value as-is. If the new value is
2125 different, we use it and insert the most-significant 32-bits
2126 of the original value into the final result. */
2127 nval = ((value & (((HOST_WIDE_INT) 2 << 31) - 1))
2128 ^ ((HOST_WIDE_INT) 1 << 31)) - ((HOST_WIDE_INT) 1 << 31);
2129 if (value != nval)
2131 #if HOST_BITS_PER_WIDE_INT > 32
2132 insv = value >= 0 ? value >> 32 : ~(~value >> 32);
2133 #endif
2134 insert = 1;
2135 value = nval;
2136 operand1 = GEN_INT (nval);
2140 if (reload_in_progress || reload_completed)
2141 temp = scratch_reg ? scratch_reg : operand0;
2142 else
2143 temp = gen_reg_rtx (mode);
2145 /* We don't directly split DImode constants on 32-bit targets
2146 because PLUS uses an 11-bit immediate and the insn sequence
2147 generated is not as efficient as the one using HIGH/LO_SUM. */
2148 if (GET_CODE (operand1) == CONST_INT
2149 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2150 && !insert)
2152 /* Directly break constant into high and low parts. This
2153 provides better optimization opportunities because various
2154 passes recognize constants split with PLUS but not LO_SUM.
2155 We use a 14-bit signed low part except when the addition
2156 of 0x4000 to the high part might change the sign of the
2157 high part. */
2158 HOST_WIDE_INT low = value & 0x3fff;
2159 HOST_WIDE_INT high = value & ~ 0x3fff;
2161 if (low >= 0x2000)
2163 if (high == 0x7fffc000 || (mode == HImode && high == 0x4000))
2164 high += 0x2000;
2165 else
2166 high += 0x4000;
2169 low = value - high;
2171 emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (high)));
2172 operands[1] = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2174 else
2176 emit_insn (gen_rtx_SET (VOIDmode, temp,
2177 gen_rtx_HIGH (mode, operand1)));
2178 operands[1] = gen_rtx_LO_SUM (mode, temp, operand1);
2181 insn = emit_move_insn (operands[0], operands[1]);
2183 /* Now insert the most significant 32 bits of the value
2184 into the register. When we don't have a second register
2185 available, it could take up to nine instructions to load
2186 a 64-bit integer constant. Prior to reload, we force
2187 constants that would take more than three instructions
2188 to load to the constant pool. During and after reload,
2189 we have to handle all possible values. */
2190 if (insert)
2192 /* Use a HIGH/LO_SUM/INSV sequence if we have a second
2193 register and the value to be inserted is outside the
2194 range that can be loaded with three depdi instructions. */
2195 if (temp != operand0 && (insv >= 16384 || insv < -16384))
2197 operand1 = GEN_INT (insv);
2199 emit_insn (gen_rtx_SET (VOIDmode, temp,
2200 gen_rtx_HIGH (mode, operand1)));
2201 emit_move_insn (temp, gen_rtx_LO_SUM (mode, temp, operand1));
2202 emit_insn (gen_insv (operand0, GEN_INT (32),
2203 const0_rtx, temp));
2205 else
2207 int len = 5, pos = 27;
2209 /* Insert the bits using the depdi instruction. */
2210 while (pos >= 0)
2212 HOST_WIDE_INT v5 = ((insv & 31) ^ 16) - 16;
2213 HOST_WIDE_INT sign = v5 < 0;
2215 /* Left extend the insertion. */
2216 insv = (insv >= 0 ? insv >> len : ~(~insv >> len));
2217 while (pos > 0 && (insv & 1) == sign)
2219 insv = (insv >= 0 ? insv >> 1 : ~(~insv >> 1));
2220 len += 1;
2221 pos -= 1;
2224 emit_insn (gen_insv (operand0, GEN_INT (len),
2225 GEN_INT (pos), GEN_INT (v5)));
2227 len = pos > 0 && pos < 5 ? pos : 5;
2228 pos -= len;
2233 REG_NOTES (insn)
2234 = gen_rtx_EXPR_LIST (REG_EQUAL, op1, REG_NOTES (insn));
2236 return 1;
2239 /* Now have insn-emit do whatever it normally does. */
2240 return 0;
2243 /* Examine EXP and return nonzero if it contains an ADDR_EXPR (meaning
2244 it will need a link/runtime reloc). */
2247 reloc_needed (tree exp)
2249 int reloc = 0;
2251 switch (TREE_CODE (exp))
2253 case ADDR_EXPR:
2254 return 1;
2256 case PLUS_EXPR:
2257 case MINUS_EXPR:
2258 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2259 reloc |= reloc_needed (TREE_OPERAND (exp, 1));
2260 break;
2262 case NOP_EXPR:
2263 case CONVERT_EXPR:
2264 case NON_LVALUE_EXPR:
2265 reloc = reloc_needed (TREE_OPERAND (exp, 0));
2266 break;
2268 case CONSTRUCTOR:
2270 register tree link;
2271 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2272 if (TREE_VALUE (link) != 0)
2273 reloc |= reloc_needed (TREE_VALUE (link));
2275 break;
2277 case ERROR_MARK:
2278 break;
2280 default:
2281 break;
2283 return reloc;
2286 /* Does operand (which is a symbolic_operand) live in text space?
2287 If so, SYMBOL_REF_FLAG, which is set by pa_encode_section_info,
2288 will be true. */
2291 read_only_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
2293 if (GET_CODE (operand) == CONST)
2294 operand = XEXP (XEXP (operand, 0), 0);
2295 if (flag_pic)
2297 if (GET_CODE (operand) == SYMBOL_REF)
2298 return SYMBOL_REF_FLAG (operand) && !CONSTANT_POOL_ADDRESS_P (operand);
2300 else
2302 if (GET_CODE (operand) == SYMBOL_REF)
2303 return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
2305 return 1;
2309 /* Return the best assembler insn template
2310 for moving operands[1] into operands[0] as a fullword. */
2311 const char *
2312 singlemove_string (rtx *operands)
2314 HOST_WIDE_INT intval;
2316 if (GET_CODE (operands[0]) == MEM)
2317 return "stw %r1,%0";
2318 if (GET_CODE (operands[1]) == MEM)
2319 return "ldw %1,%0";
2320 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2322 long i;
2323 REAL_VALUE_TYPE d;
2325 if (GET_MODE (operands[1]) != SFmode)
2326 abort ();
2328 /* Translate the CONST_DOUBLE to a CONST_INT with the same target
2329 bit pattern. */
2330 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[1]);
2331 REAL_VALUE_TO_TARGET_SINGLE (d, i);
2333 operands[1] = GEN_INT (i);
2334 /* Fall through to CONST_INT case. */
2336 if (GET_CODE (operands[1]) == CONST_INT)
2338 intval = INTVAL (operands[1]);
2340 if (VAL_14_BITS_P (intval))
2341 return "ldi %1,%0";
2342 else if ((intval & 0x7ff) == 0)
2343 return "ldil L'%1,%0";
2344 else if (zdepi_cint_p (intval))
2345 return "{zdepi %Z1,%0|depwi,z %Z1,%0}";
2346 else
2347 return "ldil L'%1,%0\n\tldo R'%1(%0),%0";
2349 return "copy %1,%0";
2353 /* Compute position (in OP[1]) and width (in OP[2])
2354 useful for copying IMM to a register using the zdepi
2355 instructions. Store the immediate value to insert in OP[0]. */
2356 static void
2357 compute_zdepwi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2359 int lsb, len;
2361 /* Find the least significant set bit in IMM. */
2362 for (lsb = 0; lsb < 32; lsb++)
2364 if ((imm & 1) != 0)
2365 break;
2366 imm >>= 1;
2369 /* Choose variants based on *sign* of the 5-bit field. */
2370 if ((imm & 0x10) == 0)
2371 len = (lsb <= 28) ? 4 : 32 - lsb;
2372 else
2374 /* Find the width of the bitstring in IMM. */
2375 for (len = 5; len < 32; len++)
2377 if ((imm & (1 << len)) == 0)
2378 break;
2381 /* Sign extend IMM as a 5-bit value. */
2382 imm = (imm & 0xf) - 0x10;
2385 op[0] = imm;
2386 op[1] = 31 - lsb;
2387 op[2] = len;
2390 /* Compute position (in OP[1]) and width (in OP[2])
2391 useful for copying IMM to a register using the depdi,z
2392 instructions. Store the immediate value to insert in OP[0]. */
2393 void
2394 compute_zdepdi_operands (unsigned HOST_WIDE_INT imm, unsigned *op)
2396 HOST_WIDE_INT lsb, len;
2398 /* Find the least significant set bit in IMM. */
2399 for (lsb = 0; lsb < HOST_BITS_PER_WIDE_INT; lsb++)
2401 if ((imm & 1) != 0)
2402 break;
2403 imm >>= 1;
2406 /* Choose variants based on *sign* of the 5-bit field. */
2407 if ((imm & 0x10) == 0)
2408 len = ((lsb <= HOST_BITS_PER_WIDE_INT - 4)
2409 ? 4 : HOST_BITS_PER_WIDE_INT - lsb);
2410 else
2412 /* Find the width of the bitstring in IMM. */
2413 for (len = 5; len < HOST_BITS_PER_WIDE_INT; len++)
2415 if ((imm & ((unsigned HOST_WIDE_INT) 1 << len)) == 0)
2416 break;
2419 /* Sign extend IMM as a 5-bit value. */
2420 imm = (imm & 0xf) - 0x10;
2423 op[0] = imm;
2424 op[1] = 63 - lsb;
2425 op[2] = len;
2428 /* Output assembler code to perform a doubleword move insn
2429 with operands OPERANDS. */
2431 const char *
2432 output_move_double (rtx *operands)
2434 enum { REGOP, OFFSOP, MEMOP, CNSTOP, RNDOP } optype0, optype1;
2435 rtx latehalf[2];
2436 rtx addreg0 = 0, addreg1 = 0;
2438 /* First classify both operands. */
2440 if (REG_P (operands[0]))
2441 optype0 = REGOP;
2442 else if (offsettable_memref_p (operands[0]))
2443 optype0 = OFFSOP;
2444 else if (GET_CODE (operands[0]) == MEM)
2445 optype0 = MEMOP;
2446 else
2447 optype0 = RNDOP;
2449 if (REG_P (operands[1]))
2450 optype1 = REGOP;
2451 else if (CONSTANT_P (operands[1]))
2452 optype1 = CNSTOP;
2453 else if (offsettable_memref_p (operands[1]))
2454 optype1 = OFFSOP;
2455 else if (GET_CODE (operands[1]) == MEM)
2456 optype1 = MEMOP;
2457 else
2458 optype1 = RNDOP;
2460 /* Check for the cases that the operand constraints are not
2461 supposed to allow to happen. Abort if we get one,
2462 because generating code for these cases is painful. */
2464 if (optype0 != REGOP && optype1 != REGOP)
2465 abort ();
2467 /* Handle auto decrementing and incrementing loads and stores
2468 specifically, since the structure of the function doesn't work
2469 for them without major modification. Do it better when we learn
2470 this port about the general inc/dec addressing of PA.
2471 (This was written by tege. Chide him if it doesn't work.) */
2473 if (optype0 == MEMOP)
2475 /* We have to output the address syntax ourselves, since print_operand
2476 doesn't deal with the addresses we want to use. Fix this later. */
2478 rtx addr = XEXP (operands[0], 0);
2479 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2481 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2483 operands[0] = XEXP (addr, 0);
2484 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2485 abort ();
2487 if (!reg_overlap_mentioned_p (high_reg, addr))
2489 /* No overlap between high target register and address
2490 register. (We do this in a non-obvious way to
2491 save a register file writeback) */
2492 if (GET_CODE (addr) == POST_INC)
2493 return "{stws|stw},ma %1,8(%0)\n\tstw %R1,-4(%0)";
2494 return "{stws|stw},ma %1,-8(%0)\n\tstw %R1,12(%0)";
2496 else
2497 abort ();
2499 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2501 rtx high_reg = gen_rtx_SUBREG (SImode, operands[1], 0);
2503 operands[0] = XEXP (addr, 0);
2504 if (GET_CODE (operands[1]) != REG || GET_CODE (operands[0]) != REG)
2505 abort ();
2507 if (!reg_overlap_mentioned_p (high_reg, addr))
2509 /* No overlap between high target register and address
2510 register. (We do this in a non-obvious way to
2511 save a register file writeback) */
2512 if (GET_CODE (addr) == PRE_INC)
2513 return "{stws|stw},mb %1,8(%0)\n\tstw %R1,4(%0)";
2514 return "{stws|stw},mb %1,-8(%0)\n\tstw %R1,4(%0)";
2516 else
2517 abort ();
2520 if (optype1 == MEMOP)
2522 /* We have to output the address syntax ourselves, since print_operand
2523 doesn't deal with the addresses we want to use. Fix this later. */
2525 rtx addr = XEXP (operands[1], 0);
2526 if (GET_CODE (addr) == POST_INC || GET_CODE (addr) == POST_DEC)
2528 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2530 operands[1] = XEXP (addr, 0);
2531 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2532 abort ();
2534 if (!reg_overlap_mentioned_p (high_reg, addr))
2536 /* No overlap between high target register and address
2537 register. (We do this in a non-obvious way to
2538 save a register file writeback) */
2539 if (GET_CODE (addr) == POST_INC)
2540 return "{ldws|ldw},ma 8(%1),%0\n\tldw -4(%1),%R0";
2541 return "{ldws|ldw},ma -8(%1),%0\n\tldw 12(%1),%R0";
2543 else
2545 /* This is an undefined situation. We should load into the
2546 address register *and* update that register. Probably
2547 we don't need to handle this at all. */
2548 if (GET_CODE (addr) == POST_INC)
2549 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma 8(%1),%0";
2550 return "ldw 4(%1),%R0\n\t{ldws|ldw},ma -8(%1),%0";
2553 else if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
2555 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2557 operands[1] = XEXP (addr, 0);
2558 if (GET_CODE (operands[0]) != REG || GET_CODE (operands[1]) != REG)
2559 abort ();
2561 if (!reg_overlap_mentioned_p (high_reg, addr))
2563 /* No overlap between high target register and address
2564 register. (We do this in a non-obvious way to
2565 save a register file writeback) */
2566 if (GET_CODE (addr) == PRE_INC)
2567 return "{ldws|ldw},mb 8(%1),%0\n\tldw 4(%1),%R0";
2568 return "{ldws|ldw},mb -8(%1),%0\n\tldw 4(%1),%R0";
2570 else
2572 /* This is an undefined situation. We should load into the
2573 address register *and* update that register. Probably
2574 we don't need to handle this at all. */
2575 if (GET_CODE (addr) == PRE_INC)
2576 return "ldw 12(%1),%R0\n\t{ldws|ldw},mb 8(%1),%0";
2577 return "ldw -4(%1),%R0\n\t{ldws|ldw},mb -8(%1),%0";
2580 else if (GET_CODE (addr) == PLUS
2581 && GET_CODE (XEXP (addr, 0)) == MULT)
2583 rtx high_reg = gen_rtx_SUBREG (SImode, operands[0], 0);
2585 if (!reg_overlap_mentioned_p (high_reg, addr))
2587 rtx xoperands[3];
2589 xoperands[0] = high_reg;
2590 xoperands[1] = XEXP (addr, 1);
2591 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2592 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2593 output_asm_insn ("{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0}",
2594 xoperands);
2595 return "ldw 4(%0),%R0\n\tldw 0(%0),%0";
2597 else
2599 rtx xoperands[3];
2601 xoperands[0] = high_reg;
2602 xoperands[1] = XEXP (addr, 1);
2603 xoperands[2] = XEXP (XEXP (addr, 0), 0);
2604 xoperands[3] = XEXP (XEXP (addr, 0), 1);
2605 output_asm_insn ("{sh%O3addl %2,%1,%R0|shladd,l %2,%O3,%1,%R0}",
2606 xoperands);
2607 return "ldw 0(%R0),%0\n\tldw 4(%R0),%R0";
2612 /* If an operand is an unoffsettable memory ref, find a register
2613 we can increment temporarily to make it refer to the second word. */
2615 if (optype0 == MEMOP)
2616 addreg0 = find_addr_reg (XEXP (operands[0], 0));
2618 if (optype1 == MEMOP)
2619 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2621 /* Ok, we can do one word at a time.
2622 Normally we do the low-numbered word first.
2624 In either case, set up in LATEHALF the operands to use
2625 for the high-numbered word and in some cases alter the
2626 operands in OPERANDS to be suitable for the low-numbered word. */
2628 if (optype0 == REGOP)
2629 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2630 else if (optype0 == OFFSOP)
2631 latehalf[0] = adjust_address (operands[0], SImode, 4);
2632 else
2633 latehalf[0] = operands[0];
2635 if (optype1 == REGOP)
2636 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2637 else if (optype1 == OFFSOP)
2638 latehalf[1] = adjust_address (operands[1], SImode, 4);
2639 else if (optype1 == CNSTOP)
2640 split_double (operands[1], &operands[1], &latehalf[1]);
2641 else
2642 latehalf[1] = operands[1];
2644 /* If the first move would clobber the source of the second one,
2645 do them in the other order.
2647 This can happen in two cases:
2649 mem -> register where the first half of the destination register
2650 is the same register used in the memory's address. Reload
2651 can create such insns.
2653 mem in this case will be either register indirect or register
2654 indirect plus a valid offset.
2656 register -> register move where REGNO(dst) == REGNO(src + 1)
2657 someone (Tim/Tege?) claimed this can happen for parameter loads.
2659 Handle mem -> register case first. */
2660 if (optype0 == REGOP
2661 && (optype1 == MEMOP || optype1 == OFFSOP)
2662 && refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
2663 operands[1], 0))
2665 /* Do the late half first. */
2666 if (addreg1)
2667 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2668 output_asm_insn (singlemove_string (latehalf), latehalf);
2670 /* Then clobber. */
2671 if (addreg1)
2672 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2673 return singlemove_string (operands);
2676 /* Now handle register -> register case. */
2677 if (optype0 == REGOP && optype1 == REGOP
2678 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
2680 output_asm_insn (singlemove_string (latehalf), latehalf);
2681 return singlemove_string (operands);
2684 /* Normal case: do the two words, low-numbered first. */
2686 output_asm_insn (singlemove_string (operands), operands);
2688 /* Make any unoffsettable addresses point at high-numbered word. */
2689 if (addreg0)
2690 output_asm_insn ("ldo 4(%0),%0", &addreg0);
2691 if (addreg1)
2692 output_asm_insn ("ldo 4(%0),%0", &addreg1);
2694 /* Do that word. */
2695 output_asm_insn (singlemove_string (latehalf), latehalf);
2697 /* Undo the adds we just did. */
2698 if (addreg0)
2699 output_asm_insn ("ldo -4(%0),%0", &addreg0);
2700 if (addreg1)
2701 output_asm_insn ("ldo -4(%0),%0", &addreg1);
2703 return "";
2706 const char *
2707 output_fp_move_double (rtx *operands)
2709 if (FP_REG_P (operands[0]))
2711 if (FP_REG_P (operands[1])
2712 || operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2713 output_asm_insn ("fcpy,dbl %f1,%0", operands);
2714 else
2715 output_asm_insn ("fldd%F1 %1,%0", operands);
2717 else if (FP_REG_P (operands[1]))
2719 output_asm_insn ("fstd%F0 %1,%0", operands);
2721 else if (operands[1] == CONST0_RTX (GET_MODE (operands[0])))
2723 if (GET_CODE (operands[0]) == REG)
2725 rtx xoperands[2];
2726 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2727 xoperands[0] = operands[0];
2728 output_asm_insn ("copy %%r0,%0\n\tcopy %%r0,%1", xoperands);
2730 /* This is a pain. You have to be prepared to deal with an
2731 arbitrary address here including pre/post increment/decrement.
2733 so avoid this in the MD. */
2734 else
2735 abort ();
2737 else abort ();
2738 return "";
2741 /* Return a REG that occurs in ADDR with coefficient 1.
2742 ADDR can be effectively incremented by incrementing REG. */
2744 static rtx
2745 find_addr_reg (rtx addr)
2747 while (GET_CODE (addr) == PLUS)
2749 if (GET_CODE (XEXP (addr, 0)) == REG)
2750 addr = XEXP (addr, 0);
2751 else if (GET_CODE (XEXP (addr, 1)) == REG)
2752 addr = XEXP (addr, 1);
2753 else if (CONSTANT_P (XEXP (addr, 0)))
2754 addr = XEXP (addr, 1);
2755 else if (CONSTANT_P (XEXP (addr, 1)))
2756 addr = XEXP (addr, 0);
2757 else
2758 abort ();
2760 if (GET_CODE (addr) == REG)
2761 return addr;
2762 abort ();
2765 /* Emit code to perform a block move.
2767 OPERANDS[0] is the destination pointer as a REG, clobbered.
2768 OPERANDS[1] is the source pointer as a REG, clobbered.
2769 OPERANDS[2] is a register for temporary storage.
2770 OPERANDS[3] is a register for temporary storage.
2771 OPERANDS[4] is the size as a CONST_INT
2772 OPERANDS[5] is the alignment safe to use, as a CONST_INT.
2773 OPERANDS[6] is another temporary register. */
2775 const char *
2776 output_block_move (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2778 int align = INTVAL (operands[5]);
2779 unsigned long n_bytes = INTVAL (operands[4]);
2781 /* We can't move more than a word at a time because the PA
2782 has no longer integer move insns. (Could use fp mem ops?) */
2783 if (align > (TARGET_64BIT ? 8 : 4))
2784 align = (TARGET_64BIT ? 8 : 4);
2786 /* Note that we know each loop below will execute at least twice
2787 (else we would have open-coded the copy). */
2788 switch (align)
2790 case 8:
2791 /* Pre-adjust the loop counter. */
2792 operands[4] = GEN_INT (n_bytes - 16);
2793 output_asm_insn ("ldi %4,%2", operands);
2795 /* Copying loop. */
2796 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2797 output_asm_insn ("ldd,ma 8(%1),%6", operands);
2798 output_asm_insn ("std,ma %3,8(%0)", operands);
2799 output_asm_insn ("addib,>= -16,%2,.-12", operands);
2800 output_asm_insn ("std,ma %6,8(%0)", operands);
2802 /* Handle the residual. There could be up to 7 bytes of
2803 residual to copy! */
2804 if (n_bytes % 16 != 0)
2806 operands[4] = GEN_INT (n_bytes % 8);
2807 if (n_bytes % 16 >= 8)
2808 output_asm_insn ("ldd,ma 8(%1),%3", operands);
2809 if (n_bytes % 8 != 0)
2810 output_asm_insn ("ldd 0(%1),%6", operands);
2811 if (n_bytes % 16 >= 8)
2812 output_asm_insn ("std,ma %3,8(%0)", operands);
2813 if (n_bytes % 8 != 0)
2814 output_asm_insn ("stdby,e %6,%4(%0)", operands);
2816 return "";
2818 case 4:
2819 /* Pre-adjust the loop counter. */
2820 operands[4] = GEN_INT (n_bytes - 8);
2821 output_asm_insn ("ldi %4,%2", operands);
2823 /* Copying loop. */
2824 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2825 output_asm_insn ("{ldws|ldw},ma 4(%1),%6", operands);
2826 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2827 output_asm_insn ("addib,>= -8,%2,.-12", operands);
2828 output_asm_insn ("{stws|stw},ma %6,4(%0)", operands);
2830 /* Handle the residual. There could be up to 7 bytes of
2831 residual to copy! */
2832 if (n_bytes % 8 != 0)
2834 operands[4] = GEN_INT (n_bytes % 4);
2835 if (n_bytes % 8 >= 4)
2836 output_asm_insn ("{ldws|ldw},ma 4(%1),%3", operands);
2837 if (n_bytes % 4 != 0)
2838 output_asm_insn ("ldw 0(%1),%6", operands);
2839 if (n_bytes % 8 >= 4)
2840 output_asm_insn ("{stws|stw},ma %3,4(%0)", operands);
2841 if (n_bytes % 4 != 0)
2842 output_asm_insn ("{stbys|stby},e %6,%4(%0)", operands);
2844 return "";
2846 case 2:
2847 /* Pre-adjust the loop counter. */
2848 operands[4] = GEN_INT (n_bytes - 4);
2849 output_asm_insn ("ldi %4,%2", operands);
2851 /* Copying loop. */
2852 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2853 output_asm_insn ("{ldhs|ldh},ma 2(%1),%6", operands);
2854 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2855 output_asm_insn ("addib,>= -4,%2,.-12", operands);
2856 output_asm_insn ("{sths|sth},ma %6,2(%0)", operands);
2858 /* Handle the residual. */
2859 if (n_bytes % 4 != 0)
2861 if (n_bytes % 4 >= 2)
2862 output_asm_insn ("{ldhs|ldh},ma 2(%1),%3", operands);
2863 if (n_bytes % 2 != 0)
2864 output_asm_insn ("ldb 0(%1),%6", operands);
2865 if (n_bytes % 4 >= 2)
2866 output_asm_insn ("{sths|sth},ma %3,2(%0)", operands);
2867 if (n_bytes % 2 != 0)
2868 output_asm_insn ("stb %6,0(%0)", operands);
2870 return "";
2872 case 1:
2873 /* Pre-adjust the loop counter. */
2874 operands[4] = GEN_INT (n_bytes - 2);
2875 output_asm_insn ("ldi %4,%2", operands);
2877 /* Copying loop. */
2878 output_asm_insn ("{ldbs|ldb},ma 1(%1),%3", operands);
2879 output_asm_insn ("{ldbs|ldb},ma 1(%1),%6", operands);
2880 output_asm_insn ("{stbs|stb},ma %3,1(%0)", operands);
2881 output_asm_insn ("addib,>= -2,%2,.-12", operands);
2882 output_asm_insn ("{stbs|stb},ma %6,1(%0)", operands);
2884 /* Handle the residual. */
2885 if (n_bytes % 2 != 0)
2887 output_asm_insn ("ldb 0(%1),%3", operands);
2888 output_asm_insn ("stb %3,0(%0)", operands);
2890 return "";
2892 default:
2893 abort ();
2897 /* Count the number of insns necessary to handle this block move.
2899 Basic structure is the same as emit_block_move, except that we
2900 count insns rather than emit them. */
2902 static int
2903 compute_movmem_length (rtx insn)
2905 rtx pat = PATTERN (insn);
2906 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 7), 0));
2907 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 6), 0));
2908 unsigned int n_insns = 0;
2910 /* We can't move more than four bytes at a time because the PA
2911 has no longer integer move insns. (Could use fp mem ops?) */
2912 if (align > (TARGET_64BIT ? 8 : 4))
2913 align = (TARGET_64BIT ? 8 : 4);
2915 /* The basic copying loop. */
2916 n_insns = 6;
2918 /* Residuals. */
2919 if (n_bytes % (2 * align) != 0)
2921 if ((n_bytes % (2 * align)) >= align)
2922 n_insns += 2;
2924 if ((n_bytes % align) != 0)
2925 n_insns += 2;
2928 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
2929 return n_insns * 4;
2932 /* Emit code to perform a block clear.
2934 OPERANDS[0] is the destination pointer as a REG, clobbered.
2935 OPERANDS[1] is a register for temporary storage.
2936 OPERANDS[2] is the size as a CONST_INT
2937 OPERANDS[3] is the alignment safe to use, as a CONST_INT. */
2939 const char *
2940 output_block_clear (rtx *operands, int size_is_constant ATTRIBUTE_UNUSED)
2942 int align = INTVAL (operands[3]);
2943 unsigned long n_bytes = INTVAL (operands[2]);
2945 /* We can't clear more than a word at a time because the PA
2946 has no longer integer move insns. */
2947 if (align > (TARGET_64BIT ? 8 : 4))
2948 align = (TARGET_64BIT ? 8 : 4);
2950 /* Note that we know each loop below will execute at least twice
2951 (else we would have open-coded the copy). */
2952 switch (align)
2954 case 8:
2955 /* Pre-adjust the loop counter. */
2956 operands[2] = GEN_INT (n_bytes - 16);
2957 output_asm_insn ("ldi %2,%1", operands);
2959 /* Loop. */
2960 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2961 output_asm_insn ("addib,>= -16,%1,.-4", operands);
2962 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2964 /* Handle the residual. There could be up to 7 bytes of
2965 residual to copy! */
2966 if (n_bytes % 16 != 0)
2968 operands[2] = GEN_INT (n_bytes % 8);
2969 if (n_bytes % 16 >= 8)
2970 output_asm_insn ("std,ma %%r0,8(%0)", operands);
2971 if (n_bytes % 8 != 0)
2972 output_asm_insn ("stdby,e %%r0,%2(%0)", operands);
2974 return "";
2976 case 4:
2977 /* Pre-adjust the loop counter. */
2978 operands[2] = GEN_INT (n_bytes - 8);
2979 output_asm_insn ("ldi %2,%1", operands);
2981 /* Loop. */
2982 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2983 output_asm_insn ("addib,>= -8,%1,.-4", operands);
2984 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2986 /* Handle the residual. There could be up to 7 bytes of
2987 residual to copy! */
2988 if (n_bytes % 8 != 0)
2990 operands[2] = GEN_INT (n_bytes % 4);
2991 if (n_bytes % 8 >= 4)
2992 output_asm_insn ("{stws|stw},ma %%r0,4(%0)", operands);
2993 if (n_bytes % 4 != 0)
2994 output_asm_insn ("{stbys|stby},e %%r0,%2(%0)", operands);
2996 return "";
2998 case 2:
2999 /* Pre-adjust the loop counter. */
3000 operands[2] = GEN_INT (n_bytes - 4);
3001 output_asm_insn ("ldi %2,%1", operands);
3003 /* Loop. */
3004 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3005 output_asm_insn ("addib,>= -4,%1,.-4", operands);
3006 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3008 /* Handle the residual. */
3009 if (n_bytes % 4 != 0)
3011 if (n_bytes % 4 >= 2)
3012 output_asm_insn ("{sths|sth},ma %%r0,2(%0)", operands);
3013 if (n_bytes % 2 != 0)
3014 output_asm_insn ("stb %%r0,0(%0)", operands);
3016 return "";
3018 case 1:
3019 /* Pre-adjust the loop counter. */
3020 operands[2] = GEN_INT (n_bytes - 2);
3021 output_asm_insn ("ldi %2,%1", operands);
3023 /* Loop. */
3024 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3025 output_asm_insn ("addib,>= -2,%1,.-4", operands);
3026 output_asm_insn ("{stbs|stb},ma %%r0,1(%0)", operands);
3028 /* Handle the residual. */
3029 if (n_bytes % 2 != 0)
3030 output_asm_insn ("stb %%r0,0(%0)", operands);
3032 return "";
3034 default:
3035 abort ();
3039 /* Count the number of insns necessary to handle this block move.
3041 Basic structure is the same as emit_block_move, except that we
3042 count insns rather than emit them. */
3044 static int
3045 compute_clrmem_length (rtx insn)
3047 rtx pat = PATTERN (insn);
3048 unsigned int align = INTVAL (XEXP (XVECEXP (pat, 0, 4), 0));
3049 unsigned long n_bytes = INTVAL (XEXP (XVECEXP (pat, 0, 3), 0));
3050 unsigned int n_insns = 0;
3052 /* We can't clear more than a word at a time because the PA
3053 has no longer integer move insns. */
3054 if (align > (TARGET_64BIT ? 8 : 4))
3055 align = (TARGET_64BIT ? 8 : 4);
3057 /* The basic loop. */
3058 n_insns = 4;
3060 /* Residuals. */
3061 if (n_bytes % (2 * align) != 0)
3063 if ((n_bytes % (2 * align)) >= align)
3064 n_insns++;
3066 if ((n_bytes % align) != 0)
3067 n_insns++;
3070 /* Lengths are expressed in bytes now; each insn is 4 bytes. */
3071 return n_insns * 4;
3075 const char *
3076 output_and (rtx *operands)
3078 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3080 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3081 int ls0, ls1, ms0, p, len;
3083 for (ls0 = 0; ls0 < 32; ls0++)
3084 if ((mask & (1 << ls0)) == 0)
3085 break;
3087 for (ls1 = ls0; ls1 < 32; ls1++)
3088 if ((mask & (1 << ls1)) != 0)
3089 break;
3091 for (ms0 = ls1; ms0 < 32; ms0++)
3092 if ((mask & (1 << ms0)) == 0)
3093 break;
3095 if (ms0 != 32)
3096 abort ();
3098 if (ls1 == 32)
3100 len = ls0;
3102 if (len == 0)
3103 abort ();
3105 operands[2] = GEN_INT (len);
3106 return "{extru|extrw,u} %1,31,%2,%0";
3108 else
3110 /* We could use this `depi' for the case above as well, but `depi'
3111 requires one more register file access than an `extru'. */
3113 p = 31 - ls0;
3114 len = ls1 - ls0;
3116 operands[2] = GEN_INT (p);
3117 operands[3] = GEN_INT (len);
3118 return "{depi|depwi} 0,%2,%3,%0";
3121 else
3122 return "and %1,%2,%0";
3125 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3126 storing the result in operands[0]. */
3127 const char *
3128 output_64bit_and (rtx *operands)
3130 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
3132 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3133 int ls0, ls1, ms0, p, len;
3135 for (ls0 = 0; ls0 < HOST_BITS_PER_WIDE_INT; ls0++)
3136 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls0)) == 0)
3137 break;
3139 for (ls1 = ls0; ls1 < HOST_BITS_PER_WIDE_INT; ls1++)
3140 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ls1)) != 0)
3141 break;
3143 for (ms0 = ls1; ms0 < HOST_BITS_PER_WIDE_INT; ms0++)
3144 if ((mask & ((unsigned HOST_WIDE_INT) 1 << ms0)) == 0)
3145 break;
3147 if (ms0 != HOST_BITS_PER_WIDE_INT)
3148 abort ();
3150 if (ls1 == HOST_BITS_PER_WIDE_INT)
3152 len = ls0;
3154 if (len == 0)
3155 abort ();
3157 operands[2] = GEN_INT (len);
3158 return "extrd,u %1,63,%2,%0";
3160 else
3162 /* We could use this `depi' for the case above as well, but `depi'
3163 requires one more register file access than an `extru'. */
3165 p = 63 - ls0;
3166 len = ls1 - ls0;
3168 operands[2] = GEN_INT (p);
3169 operands[3] = GEN_INT (len);
3170 return "depdi 0,%2,%3,%0";
3173 else
3174 return "and %1,%2,%0";
3177 const char *
3178 output_ior (rtx *operands)
3180 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3181 int bs0, bs1, p, len;
3183 if (INTVAL (operands[2]) == 0)
3184 return "copy %1,%0";
3186 for (bs0 = 0; bs0 < 32; bs0++)
3187 if ((mask & (1 << bs0)) != 0)
3188 break;
3190 for (bs1 = bs0; bs1 < 32; bs1++)
3191 if ((mask & (1 << bs1)) == 0)
3192 break;
3194 if (bs1 != 32 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3195 abort ();
3197 p = 31 - bs0;
3198 len = bs1 - bs0;
3200 operands[2] = GEN_INT (p);
3201 operands[3] = GEN_INT (len);
3202 return "{depi|depwi} -1,%2,%3,%0";
3205 /* Return a string to perform a bitwise-and of operands[1] with operands[2]
3206 storing the result in operands[0]. */
3207 const char *
3208 output_64bit_ior (rtx *operands)
3210 unsigned HOST_WIDE_INT mask = INTVAL (operands[2]);
3211 int bs0, bs1, p, len;
3213 if (INTVAL (operands[2]) == 0)
3214 return "copy %1,%0";
3216 for (bs0 = 0; bs0 < HOST_BITS_PER_WIDE_INT; bs0++)
3217 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs0)) != 0)
3218 break;
3220 for (bs1 = bs0; bs1 < HOST_BITS_PER_WIDE_INT; bs1++)
3221 if ((mask & ((unsigned HOST_WIDE_INT) 1 << bs1)) == 0)
3222 break;
3224 if (bs1 != HOST_BITS_PER_WIDE_INT
3225 && ((unsigned HOST_WIDE_INT) 1 << bs1) <= mask)
3226 abort ();
3228 p = 63 - bs0;
3229 len = bs1 - bs0;
3231 operands[2] = GEN_INT (p);
3232 operands[3] = GEN_INT (len);
3233 return "depdi -1,%2,%3,%0";
3236 /* Target hook for assembling integer objects. This code handles
3237 aligned SI and DI integers specially, since function references must
3238 be preceded by P%. */
3240 static bool
3241 pa_assemble_integer (rtx x, unsigned int size, int aligned_p)
3243 if (size == UNITS_PER_WORD && aligned_p
3244 && function_label_operand (x, VOIDmode))
3246 fputs (size == 8? "\t.dword\tP%" : "\t.word\tP%", asm_out_file);
3247 output_addr_const (asm_out_file, x);
3248 fputc ('\n', asm_out_file);
3249 return true;
3251 return default_assemble_integer (x, size, aligned_p);
3254 /* Output an ascii string. */
3255 void
3256 output_ascii (FILE *file, const char *p, int size)
3258 int i;
3259 int chars_output;
3260 unsigned char partial_output[16]; /* Max space 4 chars can occupy. */
3262 /* The HP assembler can only take strings of 256 characters at one
3263 time. This is a limitation on input line length, *not* the
3264 length of the string. Sigh. Even worse, it seems that the
3265 restriction is in number of input characters (see \xnn &
3266 \whatever). So we have to do this very carefully. */
3268 fputs ("\t.STRING \"", file);
3270 chars_output = 0;
3271 for (i = 0; i < size; i += 4)
3273 int co = 0;
3274 int io = 0;
3275 for (io = 0, co = 0; io < MIN (4, size - i); io++)
3277 register unsigned int c = (unsigned char) p[i + io];
3279 if (c == '\"' || c == '\\')
3280 partial_output[co++] = '\\';
3281 if (c >= ' ' && c < 0177)
3282 partial_output[co++] = c;
3283 else
3285 unsigned int hexd;
3286 partial_output[co++] = '\\';
3287 partial_output[co++] = 'x';
3288 hexd = c / 16 - 0 + '0';
3289 if (hexd > '9')
3290 hexd -= '9' - 'a' + 1;
3291 partial_output[co++] = hexd;
3292 hexd = c % 16 - 0 + '0';
3293 if (hexd > '9')
3294 hexd -= '9' - 'a' + 1;
3295 partial_output[co++] = hexd;
3298 if (chars_output + co > 243)
3300 fputs ("\"\n\t.STRING \"", file);
3301 chars_output = 0;
3303 fwrite (partial_output, 1, (size_t) co, file);
3304 chars_output += co;
3305 co = 0;
3307 fputs ("\"\n", file);
3310 /* Try to rewrite floating point comparisons & branches to avoid
3311 useless add,tr insns.
3313 CHECK_NOTES is nonzero if we should examine REG_DEAD notes
3314 to see if FPCC is dead. CHECK_NOTES is nonzero for the
3315 first attempt to remove useless add,tr insns. It is zero
3316 for the second pass as reorg sometimes leaves bogus REG_DEAD
3317 notes lying around.
3319 When CHECK_NOTES is zero we can only eliminate add,tr insns
3320 when there's a 1:1 correspondence between fcmp and ftest/fbranch
3321 instructions. */
3322 static void
3323 remove_useless_addtr_insns (int check_notes)
3325 rtx insn;
3326 static int pass = 0;
3328 /* This is fairly cheap, so always run it when optimizing. */
3329 if (optimize > 0)
3331 int fcmp_count = 0;
3332 int fbranch_count = 0;
3334 /* Walk all the insns in this function looking for fcmp & fbranch
3335 instructions. Keep track of how many of each we find. */
3336 for (insn = get_insns (); insn; insn = next_insn (insn))
3338 rtx tmp;
3340 /* Ignore anything that isn't an INSN or a JUMP_INSN. */
3341 if (GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
3342 continue;
3344 tmp = PATTERN (insn);
3346 /* It must be a set. */
3347 if (GET_CODE (tmp) != SET)
3348 continue;
3350 /* If the destination is CCFP, then we've found an fcmp insn. */
3351 tmp = SET_DEST (tmp);
3352 if (GET_CODE (tmp) == REG && REGNO (tmp) == 0)
3354 fcmp_count++;
3355 continue;
3358 tmp = PATTERN (insn);
3359 /* If this is an fbranch instruction, bump the fbranch counter. */
3360 if (GET_CODE (tmp) == SET
3361 && SET_DEST (tmp) == pc_rtx
3362 && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
3363 && GET_CODE (XEXP (SET_SRC (tmp), 0)) == NE
3364 && GET_CODE (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == REG
3365 && REGNO (XEXP (XEXP (SET_SRC (tmp), 0), 0)) == 0)
3367 fbranch_count++;
3368 continue;
3373 /* Find all floating point compare + branch insns. If possible,
3374 reverse the comparison & the branch to avoid add,tr insns. */
3375 for (insn = get_insns (); insn; insn = next_insn (insn))
3377 rtx tmp, next;
3379 /* Ignore anything that isn't an INSN. */
3380 if (GET_CODE (insn) != INSN)
3381 continue;
3383 tmp = PATTERN (insn);
3385 /* It must be a set. */
3386 if (GET_CODE (tmp) != SET)
3387 continue;
3389 /* The destination must be CCFP, which is register zero. */
3390 tmp = SET_DEST (tmp);
3391 if (GET_CODE (tmp) != REG || REGNO (tmp) != 0)
3392 continue;
3394 /* INSN should be a set of CCFP.
3396 See if the result of this insn is used in a reversed FP
3397 conditional branch. If so, reverse our condition and
3398 the branch. Doing so avoids useless add,tr insns. */
3399 next = next_insn (insn);
3400 while (next)
3402 /* Jumps, calls and labels stop our search. */
3403 if (GET_CODE (next) == JUMP_INSN
3404 || GET_CODE (next) == CALL_INSN
3405 || GET_CODE (next) == CODE_LABEL)
3406 break;
3408 /* As does another fcmp insn. */
3409 if (GET_CODE (next) == INSN
3410 && GET_CODE (PATTERN (next)) == SET
3411 && GET_CODE (SET_DEST (PATTERN (next))) == REG
3412 && REGNO (SET_DEST (PATTERN (next))) == 0)
3413 break;
3415 next = next_insn (next);
3418 /* Is NEXT_INSN a branch? */
3419 if (next
3420 && GET_CODE (next) == JUMP_INSN)
3422 rtx pattern = PATTERN (next);
3424 /* If it a reversed fp conditional branch (eg uses add,tr)
3425 and CCFP dies, then reverse our conditional and the branch
3426 to avoid the add,tr. */
3427 if (GET_CODE (pattern) == SET
3428 && SET_DEST (pattern) == pc_rtx
3429 && GET_CODE (SET_SRC (pattern)) == IF_THEN_ELSE
3430 && GET_CODE (XEXP (SET_SRC (pattern), 0)) == NE
3431 && GET_CODE (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == REG
3432 && REGNO (XEXP (XEXP (SET_SRC (pattern), 0), 0)) == 0
3433 && GET_CODE (XEXP (SET_SRC (pattern), 1)) == PC
3434 && (fcmp_count == fbranch_count
3435 || (check_notes
3436 && find_regno_note (next, REG_DEAD, 0))))
3438 /* Reverse the branch. */
3439 tmp = XEXP (SET_SRC (pattern), 1);
3440 XEXP (SET_SRC (pattern), 1) = XEXP (SET_SRC (pattern), 2);
3441 XEXP (SET_SRC (pattern), 2) = tmp;
3442 INSN_CODE (next) = -1;
3444 /* Reverse our condition. */
3445 tmp = PATTERN (insn);
3446 PUT_CODE (XEXP (tmp, 1),
3447 (reverse_condition_maybe_unordered
3448 (GET_CODE (XEXP (tmp, 1)))));
3454 pass = !pass;
3458 /* You may have trouble believing this, but this is the 32 bit HP-PA
3459 stack layout. Wow.
3461 Offset Contents
3463 Variable arguments (optional; any number may be allocated)
3465 SP-(4*(N+9)) arg word N
3467 SP-56 arg word 5
3468 SP-52 arg word 4
3470 Fixed arguments (must be allocated; may remain unused)
3472 SP-48 arg word 3
3473 SP-44 arg word 2
3474 SP-40 arg word 1
3475 SP-36 arg word 0
3477 Frame Marker
3479 SP-32 External Data Pointer (DP)
3480 SP-28 External sr4
3481 SP-24 External/stub RP (RP')
3482 SP-20 Current RP
3483 SP-16 Static Link
3484 SP-12 Clean up
3485 SP-8 Calling Stub RP (RP'')
3486 SP-4 Previous SP
3488 Top of Frame
3490 SP-0 Stack Pointer (points to next available address)
3494 /* This function saves registers as follows. Registers marked with ' are
3495 this function's registers (as opposed to the previous function's).
3496 If a frame_pointer isn't needed, r4 is saved as a general register;
3497 the space for the frame pointer is still allocated, though, to keep
3498 things simple.
3501 Top of Frame
3503 SP (FP') Previous FP
3504 SP + 4 Alignment filler (sigh)
3505 SP + 8 Space for locals reserved here.
3509 SP + n All call saved register used.
3513 SP + o All call saved fp registers used.
3517 SP + p (SP') points to next available address.
3521 /* Global variables set by output_function_prologue(). */
3522 /* Size of frame. Need to know this to emit return insns from
3523 leaf procedures. */
3524 static HOST_WIDE_INT actual_fsize, local_fsize;
3525 static int save_fregs;
3527 /* Emit RTL to store REG at the memory location specified by BASE+DISP.
3528 Handle case where DISP > 8k by using the add_high_const patterns.
3530 Note in DISP > 8k case, we will leave the high part of the address
3531 in %r1. There is code in expand_hppa_{prologue,epilogue} that knows this.*/
3533 static void
3534 store_reg (int reg, HOST_WIDE_INT disp, int base)
3536 rtx insn, dest, src, basereg;
3538 src = gen_rtx_REG (word_mode, reg);
3539 basereg = gen_rtx_REG (Pmode, base);
3540 if (VAL_14_BITS_P (disp))
3542 dest = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
3543 insn = emit_move_insn (dest, src);
3545 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3547 rtx delta = GEN_INT (disp);
3548 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3550 emit_move_insn (tmpreg, delta);
3551 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
3552 dest = gen_rtx_MEM (word_mode, tmpreg);
3553 insn = emit_move_insn (dest, src);
3554 if (DO_FRAME_NOTES)
3556 REG_NOTES (insn)
3557 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3558 gen_rtx_SET (VOIDmode,
3559 gen_rtx_MEM (word_mode,
3560 gen_rtx_PLUS (word_mode, basereg,
3561 delta)),
3562 src),
3563 REG_NOTES (insn));
3566 else
3568 rtx delta = GEN_INT (disp);
3569 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
3570 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3572 emit_move_insn (tmpreg, high);
3573 dest = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3574 insn = emit_move_insn (dest, src);
3575 if (DO_FRAME_NOTES)
3577 REG_NOTES (insn)
3578 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3579 gen_rtx_SET (VOIDmode,
3580 gen_rtx_MEM (word_mode,
3581 gen_rtx_PLUS (word_mode, basereg,
3582 delta)),
3583 src),
3584 REG_NOTES (insn));
3588 if (DO_FRAME_NOTES)
3589 RTX_FRAME_RELATED_P (insn) = 1;
3592 /* Emit RTL to store REG at the memory location specified by BASE and then
3593 add MOD to BASE. MOD must be <= 8k. */
3595 static void
3596 store_reg_modify (int base, int reg, HOST_WIDE_INT mod)
3598 rtx insn, basereg, srcreg, delta;
3600 if (!VAL_14_BITS_P (mod))
3601 abort ();
3603 basereg = gen_rtx_REG (Pmode, base);
3604 srcreg = gen_rtx_REG (word_mode, reg);
3605 delta = GEN_INT (mod);
3607 insn = emit_insn (gen_post_store (basereg, srcreg, delta));
3608 if (DO_FRAME_NOTES)
3610 RTX_FRAME_RELATED_P (insn) = 1;
3612 /* RTX_FRAME_RELATED_P must be set on each frame related set
3613 in a parallel with more than one element. Don't set
3614 RTX_FRAME_RELATED_P in the first set if reg is temporary
3615 register 1. The effect of this operation is recorded in
3616 the initial copy. */
3617 if (reg != 1)
3619 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 0)) = 1;
3620 RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
3622 else
3624 /* The first element of a PARALLEL is always processed if it is
3625 a SET. Thus, we need an expression list for this case. */
3626 REG_NOTES (insn)
3627 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3628 gen_rtx_SET (VOIDmode, basereg,
3629 gen_rtx_PLUS (word_mode, basereg, delta)),
3630 REG_NOTES (insn));
3635 /* Emit RTL to set REG to the value specified by BASE+DISP. Handle case
3636 where DISP > 8k by using the add_high_const patterns. NOTE indicates
3637 whether to add a frame note or not.
3639 In the DISP > 8k case, we leave the high part of the address in %r1.
3640 There is code in expand_hppa_{prologue,epilogue} that knows about this. */
3642 static void
3643 set_reg_plus_d (int reg, int base, HOST_WIDE_INT disp, int note)
3645 rtx insn;
3647 if (VAL_14_BITS_P (disp))
3649 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3650 plus_constant (gen_rtx_REG (Pmode, base), disp));
3652 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
3654 rtx basereg = gen_rtx_REG (Pmode, base);
3655 rtx delta = GEN_INT (disp);
3656 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3658 emit_move_insn (tmpreg, delta);
3659 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3660 gen_rtx_PLUS (Pmode, tmpreg, basereg));
3662 else
3664 rtx basereg = gen_rtx_REG (Pmode, base);
3665 rtx delta = GEN_INT (disp);
3666 rtx tmpreg = gen_rtx_REG (Pmode, 1);
3668 emit_move_insn (tmpreg,
3669 gen_rtx_PLUS (Pmode, basereg,
3670 gen_rtx_HIGH (Pmode, delta)));
3671 insn = emit_move_insn (gen_rtx_REG (Pmode, reg),
3672 gen_rtx_LO_SUM (Pmode, tmpreg, delta));
3675 if (DO_FRAME_NOTES && note)
3676 RTX_FRAME_RELATED_P (insn) = 1;
3679 HOST_WIDE_INT
3680 compute_frame_size (HOST_WIDE_INT size, int *fregs_live)
3682 int freg_saved = 0;
3683 int i, j;
3685 /* The code in hppa_expand_prologue and hppa_expand_epilogue must
3686 be consistent with the rounding and size calculation done here.
3687 Change them at the same time. */
3689 /* We do our own stack alignment. First, round the size of the
3690 stack locals up to a word boundary. */
3691 size = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3693 /* Space for previous frame pointer + filler. If any frame is
3694 allocated, we need to add in the STARTING_FRAME_OFFSET. We
3695 waste some space here for the sake of HP compatibility. The
3696 first slot is only used when the frame pointer is needed. */
3697 if (size || frame_pointer_needed)
3698 size += STARTING_FRAME_OFFSET;
3700 /* If the current function calls __builtin_eh_return, then we need
3701 to allocate stack space for registers that will hold data for
3702 the exception handler. */
3703 if (DO_FRAME_NOTES && current_function_calls_eh_return)
3705 unsigned int i;
3707 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
3708 continue;
3709 size += i * UNITS_PER_WORD;
3712 /* Account for space used by the callee general register saves. */
3713 for (i = 18, j = frame_pointer_needed ? 4 : 3; i >= j; i--)
3714 if (regs_ever_live[i])
3715 size += UNITS_PER_WORD;
3717 /* Account for space used by the callee floating point register saves. */
3718 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
3719 if (regs_ever_live[i]
3720 || (!TARGET_64BIT && regs_ever_live[i + 1]))
3722 freg_saved = 1;
3724 /* We always save both halves of the FP register, so always
3725 increment the frame size by 8 bytes. */
3726 size += 8;
3729 /* If any of the floating registers are saved, account for the
3730 alignment needed for the floating point register save block. */
3731 if (freg_saved)
3733 size = (size + 7) & ~7;
3734 if (fregs_live)
3735 *fregs_live = 1;
3738 /* The various ABIs include space for the outgoing parameters in the
3739 size of the current function's stack frame. We don't need to align
3740 for the outgoing arguments as their alignment is set by the final
3741 rounding for the frame as a whole. */
3742 size += current_function_outgoing_args_size;
3744 /* Allocate space for the fixed frame marker. This space must be
3745 allocated for any function that makes calls or allocates
3746 stack space. */
3747 if (!current_function_is_leaf || size)
3748 size += TARGET_64BIT ? 48 : 32;
3750 /* Finally, round to the preferred stack boundary. */
3751 return ((size + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)
3752 & ~(PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1));
3755 /* Generate the assembly code for function entry. FILE is a stdio
3756 stream to output the code to. SIZE is an int: how many units of
3757 temporary storage to allocate.
3759 Refer to the array `regs_ever_live' to determine which registers to
3760 save; `regs_ever_live[I]' is nonzero if register number I is ever
3761 used in the function. This function is responsible for knowing
3762 which registers should not be saved even if used. */
3764 /* On HP-PA, move-double insns between fpu and cpu need an 8-byte block
3765 of memory. If any fpu reg is used in the function, we allocate
3766 such a block here, at the bottom of the frame, just in case it's needed.
3768 If this function is a leaf procedure, then we may choose not
3769 to do a "save" insn. The decision about whether or not
3770 to do this is made in regclass.c. */
3772 static void
3773 pa_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3775 /* The function's label and associated .PROC must never be
3776 separated and must be output *after* any profiling declarations
3777 to avoid changing spaces/subspaces within a procedure. */
3778 ASM_OUTPUT_LABEL (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
3779 fputs ("\t.PROC\n", file);
3781 /* hppa_expand_prologue does the dirty work now. We just need
3782 to output the assembler directives which denote the start
3783 of a function. */
3784 fprintf (file, "\t.CALLINFO FRAME=" HOST_WIDE_INT_PRINT_DEC, actual_fsize);
3785 if (regs_ever_live[2])
3786 fputs (",CALLS,SAVE_RP", file);
3787 else
3788 fputs (",NO_CALLS", file);
3790 /* The SAVE_SP flag is used to indicate that register %r3 is stored
3791 at the beginning of the frame and that it is used as the frame
3792 pointer for the frame. We do this because our current frame
3793 layout doesn't conform to that specified in the the HP runtime
3794 documentation and we need a way to indicate to programs such as
3795 GDB where %r3 is saved. The SAVE_SP flag was chosen because it
3796 isn't used by HP compilers but is supported by the assembler.
3797 However, SAVE_SP is supposed to indicate that the previous stack
3798 pointer has been saved in the frame marker. */
3799 if (frame_pointer_needed)
3800 fputs (",SAVE_SP", file);
3802 /* Pass on information about the number of callee register saves
3803 performed in the prologue.
3805 The compiler is supposed to pass the highest register number
3806 saved, the assembler then has to adjust that number before
3807 entering it into the unwind descriptor (to account for any
3808 caller saved registers with lower register numbers than the
3809 first callee saved register). */
3810 if (gr_saved)
3811 fprintf (file, ",ENTRY_GR=%d", gr_saved + 2);
3813 if (fr_saved)
3814 fprintf (file, ",ENTRY_FR=%d", fr_saved + 11);
3816 fputs ("\n\t.ENTRY\n", file);
3818 remove_useless_addtr_insns (0);
3821 void
3822 hppa_expand_prologue (void)
3824 int merge_sp_adjust_with_store = 0;
3825 HOST_WIDE_INT size = get_frame_size ();
3826 HOST_WIDE_INT offset;
3827 int i;
3828 rtx insn, tmpreg;
3830 gr_saved = 0;
3831 fr_saved = 0;
3832 save_fregs = 0;
3834 /* Compute total size for frame pointer, filler, locals and rounding to
3835 the next word boundary. Similar code appears in compute_frame_size
3836 and must be changed in tandem with this code. */
3837 local_fsize = (size + UNITS_PER_WORD - 1) & ~(UNITS_PER_WORD - 1);
3838 if (local_fsize || frame_pointer_needed)
3839 local_fsize += STARTING_FRAME_OFFSET;
3841 actual_fsize = compute_frame_size (size, &save_fregs);
3843 /* Compute a few things we will use often. */
3844 tmpreg = gen_rtx_REG (word_mode, 1);
3846 /* Save RP first. The calling conventions manual states RP will
3847 always be stored into the caller's frame at sp - 20 or sp - 16
3848 depending on which ABI is in use. */
3849 if (regs_ever_live[2] || current_function_calls_eh_return)
3850 store_reg (2, TARGET_64BIT ? -16 : -20, STACK_POINTER_REGNUM);
3852 /* Allocate the local frame and set up the frame pointer if needed. */
3853 if (actual_fsize != 0)
3855 if (frame_pointer_needed)
3857 /* Copy the old frame pointer temporarily into %r1. Set up the
3858 new stack pointer, then store away the saved old frame pointer
3859 into the stack at sp and at the same time update the stack
3860 pointer by actual_fsize bytes. Two versions, first
3861 handles small (<8k) frames. The second handles large (>=8k)
3862 frames. */
3863 insn = emit_move_insn (tmpreg, frame_pointer_rtx);
3864 if (DO_FRAME_NOTES)
3866 /* We need to record the frame pointer save here since the
3867 new frame pointer is set in the following insn. */
3868 RTX_FRAME_RELATED_P (insn) = 1;
3869 REG_NOTES (insn)
3870 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3871 gen_rtx_SET (VOIDmode,
3872 gen_rtx_MEM (word_mode, stack_pointer_rtx),
3873 frame_pointer_rtx),
3874 REG_NOTES (insn));
3877 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
3878 if (DO_FRAME_NOTES)
3879 RTX_FRAME_RELATED_P (insn) = 1;
3881 if (VAL_14_BITS_P (actual_fsize))
3882 store_reg_modify (STACK_POINTER_REGNUM, 1, actual_fsize);
3883 else
3885 /* It is incorrect to store the saved frame pointer at *sp,
3886 then increment sp (writes beyond the current stack boundary).
3888 So instead use stwm to store at *sp and post-increment the
3889 stack pointer as an atomic operation. Then increment sp to
3890 finish allocating the new frame. */
3891 HOST_WIDE_INT adjust1 = 8192 - 64;
3892 HOST_WIDE_INT adjust2 = actual_fsize - adjust1;
3894 store_reg_modify (STACK_POINTER_REGNUM, 1, adjust1);
3895 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3896 adjust2, 1);
3899 /* We set SAVE_SP in frames that need a frame pointer. Thus,
3900 we need to store the previous stack pointer (frame pointer)
3901 into the frame marker on targets that use the HP unwind
3902 library. This allows the HP unwind library to be used to
3903 unwind GCC frames. However, we are not fully compatible
3904 with the HP library because our frame layout differs from
3905 that specified in the HP runtime specification.
3907 We don't want a frame note on this instruction as the frame
3908 marker moves during dynamic stack allocation.
3910 This instruction also serves as a blockage to prevent
3911 register spills from being scheduled before the stack
3912 pointer is raised. This is necessary as we store
3913 registers using the frame pointer as a base register,
3914 and the frame pointer is set before sp is raised. */
3915 if (TARGET_HPUX_UNWIND_LIBRARY)
3917 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx,
3918 GEN_INT (TARGET_64BIT ? -8 : -4));
3920 emit_move_insn (gen_rtx_MEM (word_mode, addr),
3921 frame_pointer_rtx);
3923 else
3924 emit_insn (gen_blockage ());
3926 /* no frame pointer needed. */
3927 else
3929 /* In some cases we can perform the first callee register save
3930 and allocating the stack frame at the same time. If so, just
3931 make a note of it and defer allocating the frame until saving
3932 the callee registers. */
3933 if (VAL_14_BITS_P (actual_fsize) && local_fsize == 0)
3934 merge_sp_adjust_with_store = 1;
3935 /* Can not optimize. Adjust the stack frame by actual_fsize
3936 bytes. */
3937 else
3938 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
3939 actual_fsize, 1);
3943 /* Normal register save.
3945 Do not save the frame pointer in the frame_pointer_needed case. It
3946 was done earlier. */
3947 if (frame_pointer_needed)
3949 offset = local_fsize;
3951 /* Saving the EH return data registers in the frame is the simplest
3952 way to get the frame unwind information emitted. We put them
3953 just before the general registers. */
3954 if (DO_FRAME_NOTES && current_function_calls_eh_return)
3956 unsigned int i, regno;
3958 for (i = 0; ; ++i)
3960 regno = EH_RETURN_DATA_REGNO (i);
3961 if (regno == INVALID_REGNUM)
3962 break;
3964 store_reg (regno, offset, FRAME_POINTER_REGNUM);
3965 offset += UNITS_PER_WORD;
3969 for (i = 18; i >= 4; i--)
3970 if (regs_ever_live[i] && ! call_used_regs[i])
3972 store_reg (i, offset, FRAME_POINTER_REGNUM);
3973 offset += UNITS_PER_WORD;
3974 gr_saved++;
3976 /* Account for %r3 which is saved in a special place. */
3977 gr_saved++;
3979 /* No frame pointer needed. */
3980 else
3982 offset = local_fsize - actual_fsize;
3984 /* Saving the EH return data registers in the frame is the simplest
3985 way to get the frame unwind information emitted. */
3986 if (DO_FRAME_NOTES && current_function_calls_eh_return)
3988 unsigned int i, regno;
3990 for (i = 0; ; ++i)
3992 regno = EH_RETURN_DATA_REGNO (i);
3993 if (regno == INVALID_REGNUM)
3994 break;
3996 /* If merge_sp_adjust_with_store is nonzero, then we can
3997 optimize the first save. */
3998 if (merge_sp_adjust_with_store)
4000 store_reg_modify (STACK_POINTER_REGNUM, regno, -offset);
4001 merge_sp_adjust_with_store = 0;
4003 else
4004 store_reg (regno, offset, STACK_POINTER_REGNUM);
4005 offset += UNITS_PER_WORD;
4009 for (i = 18; i >= 3; i--)
4010 if (regs_ever_live[i] && ! call_used_regs[i])
4012 /* If merge_sp_adjust_with_store is nonzero, then we can
4013 optimize the first GR save. */
4014 if (merge_sp_adjust_with_store)
4016 store_reg_modify (STACK_POINTER_REGNUM, i, -offset);
4017 merge_sp_adjust_with_store = 0;
4019 else
4020 store_reg (i, offset, STACK_POINTER_REGNUM);
4021 offset += UNITS_PER_WORD;
4022 gr_saved++;
4025 /* If we wanted to merge the SP adjustment with a GR save, but we never
4026 did any GR saves, then just emit the adjustment here. */
4027 if (merge_sp_adjust_with_store)
4028 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4029 actual_fsize, 1);
4032 /* The hppa calling conventions say that %r19, the pic offset
4033 register, is saved at sp - 32 (in this function's frame)
4034 when generating PIC code. FIXME: What is the correct thing
4035 to do for functions which make no calls and allocate no
4036 frame? Do we need to allocate a frame, or can we just omit
4037 the save? For now we'll just omit the save.
4039 We don't want a note on this insn as the frame marker can
4040 move if there is a dynamic stack allocation. */
4041 if (flag_pic && actual_fsize != 0 && !TARGET_64BIT)
4043 rtx addr = gen_rtx_PLUS (word_mode, stack_pointer_rtx, GEN_INT (-32));
4045 emit_move_insn (gen_rtx_MEM (word_mode, addr), pic_offset_table_rtx);
4049 /* Align pointer properly (doubleword boundary). */
4050 offset = (offset + 7) & ~7;
4052 /* Floating point register store. */
4053 if (save_fregs)
4055 rtx base;
4057 /* First get the frame or stack pointer to the start of the FP register
4058 save area. */
4059 if (frame_pointer_needed)
4061 set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset, 0);
4062 base = frame_pointer_rtx;
4064 else
4066 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4067 base = stack_pointer_rtx;
4070 /* Now actually save the FP registers. */
4071 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4073 if (regs_ever_live[i]
4074 || (! TARGET_64BIT && regs_ever_live[i + 1]))
4076 rtx addr, insn, reg;
4077 addr = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
4078 reg = gen_rtx_REG (DFmode, i);
4079 insn = emit_move_insn (addr, reg);
4080 if (DO_FRAME_NOTES)
4082 RTX_FRAME_RELATED_P (insn) = 1;
4083 if (TARGET_64BIT)
4085 rtx mem = gen_rtx_MEM (DFmode,
4086 plus_constant (base, offset));
4087 REG_NOTES (insn)
4088 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
4089 gen_rtx_SET (VOIDmode, mem, reg),
4090 REG_NOTES (insn));
4092 else
4094 rtx meml = gen_rtx_MEM (SFmode,
4095 plus_constant (base, offset));
4096 rtx memr = gen_rtx_MEM (SFmode,
4097 plus_constant (base, offset + 4));
4098 rtx regl = gen_rtx_REG (SFmode, i);
4099 rtx regr = gen_rtx_REG (SFmode, i + 1);
4100 rtx setl = gen_rtx_SET (VOIDmode, meml, regl);
4101 rtx setr = gen_rtx_SET (VOIDmode, memr, regr);
4102 rtvec vec;
4104 RTX_FRAME_RELATED_P (setl) = 1;
4105 RTX_FRAME_RELATED_P (setr) = 1;
4106 vec = gen_rtvec (2, setl, setr);
4107 REG_NOTES (insn)
4108 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
4109 gen_rtx_SEQUENCE (VOIDmode, vec),
4110 REG_NOTES (insn));
4113 offset += GET_MODE_SIZE (DFmode);
4114 fr_saved++;
4120 /* Emit RTL to load REG from the memory location specified by BASE+DISP.
4121 Handle case where DISP > 8k by using the add_high_const patterns. */
4123 static void
4124 load_reg (int reg, HOST_WIDE_INT disp, int base)
4126 rtx dest = gen_rtx_REG (word_mode, reg);
4127 rtx basereg = gen_rtx_REG (Pmode, base);
4128 rtx src;
4130 if (VAL_14_BITS_P (disp))
4131 src = gen_rtx_MEM (word_mode, plus_constant (basereg, disp));
4132 else if (TARGET_64BIT && !VAL_32_BITS_P (disp))
4134 rtx delta = GEN_INT (disp);
4135 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4137 emit_move_insn (tmpreg, delta);
4138 if (TARGET_DISABLE_INDEXING)
4140 emit_move_insn (tmpreg, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4141 src = gen_rtx_MEM (word_mode, tmpreg);
4143 else
4144 src = gen_rtx_MEM (word_mode, gen_rtx_PLUS (Pmode, tmpreg, basereg));
4146 else
4148 rtx delta = GEN_INT (disp);
4149 rtx high = gen_rtx_PLUS (Pmode, basereg, gen_rtx_HIGH (Pmode, delta));
4150 rtx tmpreg = gen_rtx_REG (Pmode, 1);
4152 emit_move_insn (tmpreg, high);
4153 src = gen_rtx_MEM (word_mode, gen_rtx_LO_SUM (Pmode, tmpreg, delta));
4156 emit_move_insn (dest, src);
4159 /* Update the total code bytes output to the text section. */
4161 static void
4162 update_total_code_bytes (int nbytes)
4164 if ((TARGET_PORTABLE_RUNTIME || !TARGET_GAS || !TARGET_SOM)
4165 && !IN_NAMED_SECTION_P (cfun->decl))
4167 if (INSN_ADDRESSES_SET_P ())
4169 unsigned long old_total = total_code_bytes;
4171 total_code_bytes += nbytes;
4173 /* Be prepared to handle overflows. */
4174 if (old_total > total_code_bytes)
4175 total_code_bytes = -1;
4177 else
4178 total_code_bytes = -1;
4182 /* This function generates the assembly code for function exit.
4183 Args are as for output_function_prologue ().
4185 The function epilogue should not depend on the current stack
4186 pointer! It should use the frame pointer only. This is mandatory
4187 because of alloca; we also take advantage of it to omit stack
4188 adjustments before returning. */
4190 static void
4191 pa_output_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
4193 rtx insn = get_last_insn ();
4195 last_address = 0;
4197 /* hppa_expand_epilogue does the dirty work now. We just need
4198 to output the assembler directives which denote the end
4199 of a function.
4201 To make debuggers happy, emit a nop if the epilogue was completely
4202 eliminated due to a volatile call as the last insn in the
4203 current function. That way the return address (in %r2) will
4204 always point to a valid instruction in the current function. */
4206 /* Get the last real insn. */
4207 if (GET_CODE (insn) == NOTE)
4208 insn = prev_real_insn (insn);
4210 /* If it is a sequence, then look inside. */
4211 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
4212 insn = XVECEXP (PATTERN (insn), 0, 0);
4214 /* If insn is a CALL_INSN, then it must be a call to a volatile
4215 function (otherwise there would be epilogue insns). */
4216 if (insn && GET_CODE (insn) == CALL_INSN)
4218 fputs ("\tnop\n", file);
4219 last_address += 4;
4222 fputs ("\t.EXIT\n\t.PROCEND\n", file);
4224 if (TARGET_SOM && TARGET_GAS)
4226 /* We done with this subspace except possibly for some additional
4227 debug information. Forget that we are in this subspace to ensure
4228 that the next function is output in its own subspace. */
4229 forget_section ();
4232 if (INSN_ADDRESSES_SET_P ())
4234 insn = get_last_nonnote_insn ();
4235 last_address += INSN_ADDRESSES (INSN_UID (insn));
4236 if (INSN_P (insn))
4237 last_address += insn_default_length (insn);
4238 last_address = ((last_address + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
4239 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
4242 /* Finally, update the total number of code bytes output so far. */
4243 update_total_code_bytes (last_address);
4246 void
4247 hppa_expand_epilogue (void)
4249 rtx tmpreg;
4250 HOST_WIDE_INT offset;
4251 HOST_WIDE_INT ret_off = 0;
4252 int i;
4253 int merge_sp_adjust_with_load = 0;
4255 /* We will use this often. */
4256 tmpreg = gen_rtx_REG (word_mode, 1);
4258 /* Try to restore RP early to avoid load/use interlocks when
4259 RP gets used in the return (bv) instruction. This appears to still
4260 be necessary even when we schedule the prologue and epilogue. */
4261 if (regs_ever_live [2] || current_function_calls_eh_return)
4263 ret_off = TARGET_64BIT ? -16 : -20;
4264 if (frame_pointer_needed)
4266 load_reg (2, ret_off, FRAME_POINTER_REGNUM);
4267 ret_off = 0;
4269 else
4271 /* No frame pointer, and stack is smaller than 8k. */
4272 if (VAL_14_BITS_P (ret_off - actual_fsize))
4274 load_reg (2, ret_off - actual_fsize, STACK_POINTER_REGNUM);
4275 ret_off = 0;
4280 /* General register restores. */
4281 if (frame_pointer_needed)
4283 offset = local_fsize;
4285 /* If the current function calls __builtin_eh_return, then we need
4286 to restore the saved EH data registers. */
4287 if (DO_FRAME_NOTES && current_function_calls_eh_return)
4289 unsigned int i, regno;
4291 for (i = 0; ; ++i)
4293 regno = EH_RETURN_DATA_REGNO (i);
4294 if (regno == INVALID_REGNUM)
4295 break;
4297 load_reg (regno, offset, FRAME_POINTER_REGNUM);
4298 offset += UNITS_PER_WORD;
4302 for (i = 18; i >= 4; i--)
4303 if (regs_ever_live[i] && ! call_used_regs[i])
4305 load_reg (i, offset, FRAME_POINTER_REGNUM);
4306 offset += UNITS_PER_WORD;
4309 else
4311 offset = local_fsize - actual_fsize;
4313 /* If the current function calls __builtin_eh_return, then we need
4314 to restore the saved EH data registers. */
4315 if (DO_FRAME_NOTES && current_function_calls_eh_return)
4317 unsigned int i, regno;
4319 for (i = 0; ; ++i)
4321 regno = EH_RETURN_DATA_REGNO (i);
4322 if (regno == INVALID_REGNUM)
4323 break;
4325 /* Only for the first load.
4326 merge_sp_adjust_with_load holds the register load
4327 with which we will merge the sp adjustment. */
4328 if (merge_sp_adjust_with_load == 0
4329 && local_fsize == 0
4330 && VAL_14_BITS_P (-actual_fsize))
4331 merge_sp_adjust_with_load = regno;
4332 else
4333 load_reg (regno, offset, STACK_POINTER_REGNUM);
4334 offset += UNITS_PER_WORD;
4338 for (i = 18; i >= 3; i--)
4340 if (regs_ever_live[i] && ! call_used_regs[i])
4342 /* Only for the first load.
4343 merge_sp_adjust_with_load holds the register load
4344 with which we will merge the sp adjustment. */
4345 if (merge_sp_adjust_with_load == 0
4346 && local_fsize == 0
4347 && VAL_14_BITS_P (-actual_fsize))
4348 merge_sp_adjust_with_load = i;
4349 else
4350 load_reg (i, offset, STACK_POINTER_REGNUM);
4351 offset += UNITS_PER_WORD;
4356 /* Align pointer properly (doubleword boundary). */
4357 offset = (offset + 7) & ~7;
4359 /* FP register restores. */
4360 if (save_fregs)
4362 /* Adjust the register to index off of. */
4363 if (frame_pointer_needed)
4364 set_reg_plus_d (1, FRAME_POINTER_REGNUM, offset, 0);
4365 else
4366 set_reg_plus_d (1, STACK_POINTER_REGNUM, offset, 0);
4368 /* Actually do the restores now. */
4369 for (i = FP_SAVED_REG_LAST; i >= FP_SAVED_REG_FIRST; i -= FP_REG_STEP)
4370 if (regs_ever_live[i]
4371 || (! TARGET_64BIT && regs_ever_live[i + 1]))
4373 rtx src = gen_rtx_MEM (DFmode, gen_rtx_POST_INC (DFmode, tmpreg));
4374 rtx dest = gen_rtx_REG (DFmode, i);
4375 emit_move_insn (dest, src);
4379 /* Emit a blockage insn here to keep these insns from being moved to
4380 an earlier spot in the epilogue, or into the main instruction stream.
4382 This is necessary as we must not cut the stack back before all the
4383 restores are finished. */
4384 emit_insn (gen_blockage ());
4386 /* Reset stack pointer (and possibly frame pointer). The stack
4387 pointer is initially set to fp + 64 to avoid a race condition. */
4388 if (frame_pointer_needed)
4390 rtx delta = GEN_INT (-64);
4392 set_reg_plus_d (STACK_POINTER_REGNUM, FRAME_POINTER_REGNUM, 64, 0);
4393 emit_insn (gen_pre_load (frame_pointer_rtx, stack_pointer_rtx, delta));
4395 /* If we were deferring a callee register restore, do it now. */
4396 else if (merge_sp_adjust_with_load)
4398 rtx delta = GEN_INT (-actual_fsize);
4399 rtx dest = gen_rtx_REG (word_mode, merge_sp_adjust_with_load);
4401 emit_insn (gen_pre_load (dest, stack_pointer_rtx, delta));
4403 else if (actual_fsize != 0)
4404 set_reg_plus_d (STACK_POINTER_REGNUM, STACK_POINTER_REGNUM,
4405 - actual_fsize, 0);
4407 /* If we haven't restored %r2 yet (no frame pointer, and a stack
4408 frame greater than 8k), do so now. */
4409 if (ret_off != 0)
4410 load_reg (2, ret_off, STACK_POINTER_REGNUM);
4412 if (DO_FRAME_NOTES && current_function_calls_eh_return)
4414 rtx sa = EH_RETURN_STACKADJ_RTX;
4416 emit_insn (gen_blockage ());
4417 emit_insn (TARGET_64BIT
4418 ? gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, sa)
4419 : gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, sa));
4424 hppa_pic_save_rtx (void)
4426 return get_hard_reg_initial_val (word_mode, PIC_OFFSET_TABLE_REGNUM);
4429 void
4430 hppa_profile_hook (int label_no)
4432 /* We use SImode for the address of the function in both 32 and
4433 64-bit code to avoid having to provide DImode versions of the
4434 lcla2 and load_offset_label_address insn patterns. */
4435 rtx reg = gen_reg_rtx (SImode);
4436 rtx label_rtx = gen_label_rtx ();
4437 rtx begin_label_rtx, call_insn;
4438 char begin_label_name[16];
4440 ASM_GENERATE_INTERNAL_LABEL (begin_label_name, FUNC_BEGIN_PROLOG_LABEL,
4441 label_no);
4442 begin_label_rtx = gen_rtx_SYMBOL_REF (SImode, ggc_strdup (begin_label_name));
4444 if (TARGET_64BIT)
4445 emit_move_insn (arg_pointer_rtx,
4446 gen_rtx_PLUS (word_mode, virtual_outgoing_args_rtx,
4447 GEN_INT (64)));
4449 emit_move_insn (gen_rtx_REG (word_mode, 26), gen_rtx_REG (word_mode, 2));
4451 /* The address of the function is loaded into %r25 with a instruction-
4452 relative sequence that avoids the use of relocations. The sequence
4453 is split so that the load_offset_label_address instruction can
4454 occupy the delay slot of the call to _mcount. */
4455 if (TARGET_PA_20)
4456 emit_insn (gen_lcla2 (reg, label_rtx));
4457 else
4458 emit_insn (gen_lcla1 (reg, label_rtx));
4460 emit_insn (gen_load_offset_label_address (gen_rtx_REG (SImode, 25),
4461 reg, begin_label_rtx, label_rtx));
4463 #ifndef NO_PROFILE_COUNTERS
4465 rtx count_label_rtx, addr, r24;
4466 char count_label_name[16];
4468 ASM_GENERATE_INTERNAL_LABEL (count_label_name, "LP", label_no);
4469 count_label_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (count_label_name));
4471 addr = force_reg (Pmode, count_label_rtx);
4472 r24 = gen_rtx_REG (Pmode, 24);
4473 emit_move_insn (r24, addr);
4475 call_insn =
4476 emit_call_insn (gen_call (gen_rtx_MEM (Pmode,
4477 gen_rtx_SYMBOL_REF (Pmode,
4478 "_mcount")),
4479 GEN_INT (TARGET_64BIT ? 24 : 12)));
4481 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), r24);
4483 #else
4485 call_insn =
4486 emit_call_insn (gen_call (gen_rtx_MEM (Pmode,
4487 gen_rtx_SYMBOL_REF (Pmode,
4488 "_mcount")),
4489 GEN_INT (TARGET_64BIT ? 16 : 8)));
4491 #endif
4493 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 25));
4494 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), gen_rtx_REG (SImode, 26));
4496 /* Indicate the _mcount call cannot throw, nor will it execute a
4497 non-local goto. */
4498 REG_NOTES (call_insn)
4499 = gen_rtx_EXPR_LIST (REG_EH_REGION, constm1_rtx, REG_NOTES (call_insn));
4502 /* Fetch the return address for the frame COUNT steps up from
4503 the current frame, after the prologue. FRAMEADDR is the
4504 frame pointer of the COUNT frame.
4506 We want to ignore any export stub remnants here. To handle this,
4507 we examine the code at the return address, and if it is an export
4508 stub, we return a memory rtx for the stub return address stored
4509 at frame-24.
4511 The value returned is used in two different ways:
4513 1. To find a function's caller.
4515 2. To change the return address for a function.
4517 This function handles most instances of case 1; however, it will
4518 fail if there are two levels of stubs to execute on the return
4519 path. The only way I believe that can happen is if the return value
4520 needs a parameter relocation, which never happens for C code.
4522 This function handles most instances of case 2; however, it will
4523 fail if we did not originally have stub code on the return path
4524 but will need stub code on the new return path. This can happen if
4525 the caller & callee are both in the main program, but the new
4526 return location is in a shared library. */
4529 return_addr_rtx (int count, rtx frameaddr)
4531 rtx label;
4532 rtx rp;
4533 rtx saved_rp;
4534 rtx ins;
4536 if (count != 0)
4537 return NULL_RTX;
4539 rp = get_hard_reg_initial_val (Pmode, 2);
4541 if (TARGET_64BIT || TARGET_NO_SPACE_REGS)
4542 return rp;
4544 saved_rp = gen_reg_rtx (Pmode);
4545 emit_move_insn (saved_rp, rp);
4547 /* Get pointer to the instruction stream. We have to mask out the
4548 privilege level from the two low order bits of the return address
4549 pointer here so that ins will point to the start of the first
4550 instruction that would have been executed if we returned. */
4551 ins = copy_to_reg (gen_rtx_AND (Pmode, rp, MASK_RETURN_ADDR));
4552 label = gen_label_rtx ();
4554 /* Check the instruction stream at the normal return address for the
4555 export stub:
4557 0x4bc23fd1 | stub+8: ldw -18(sr0,sp),rp
4558 0x004010a1 | stub+12: ldsid (sr0,rp),r1
4559 0x00011820 | stub+16: mtsp r1,sr0
4560 0xe0400002 | stub+20: be,n 0(sr0,rp)
4562 If it is an export stub, than our return address is really in
4563 -24[frameaddr]. */
4565 emit_cmp_insn (gen_rtx_MEM (SImode, ins), GEN_INT (0x4bc23fd1), NE,
4566 NULL_RTX, SImode, 1);
4567 emit_jump_insn (gen_bne (label));
4569 emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 4)),
4570 GEN_INT (0x004010a1), NE, NULL_RTX, SImode, 1);
4571 emit_jump_insn (gen_bne (label));
4573 emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 8)),
4574 GEN_INT (0x00011820), NE, NULL_RTX, SImode, 1);
4575 emit_jump_insn (gen_bne (label));
4577 emit_cmp_insn (gen_rtx_MEM (SImode, plus_constant (ins, 12)),
4578 GEN_INT (0xe0400002), NE, NULL_RTX, SImode, 1);
4580 /* If there is no export stub then just use the value saved from
4581 the return pointer register. */
4583 emit_jump_insn (gen_bne (label));
4585 /* Here we know that our return address points to an export
4586 stub. We don't want to return the address of the export stub,
4587 but rather the return address of the export stub. That return
4588 address is stored at -24[frameaddr]. */
4590 emit_move_insn (saved_rp,
4591 gen_rtx_MEM (Pmode,
4592 memory_address (Pmode,
4593 plus_constant (frameaddr,
4594 -24))));
4596 emit_label (label);
4597 return saved_rp;
4600 /* This is only valid once reload has completed because it depends on
4601 knowing exactly how much (if any) frame there is and...
4603 It's only valid if there is no frame marker to de-allocate and...
4605 It's only valid if %r2 hasn't been saved into the caller's frame
4606 (we're not profiling and %r2 isn't live anywhere). */
4608 hppa_can_use_return_insn_p (void)
4610 return (reload_completed
4611 && (compute_frame_size (get_frame_size (), 0) ? 0 : 1)
4612 && ! regs_ever_live[2]
4613 && ! frame_pointer_needed);
4616 void
4617 emit_bcond_fp (enum rtx_code code, rtx operand0)
4619 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4620 gen_rtx_IF_THEN_ELSE (VOIDmode,
4621 gen_rtx_fmt_ee (code,
4622 VOIDmode,
4623 gen_rtx_REG (CCFPmode, 0),
4624 const0_rtx),
4625 gen_rtx_LABEL_REF (VOIDmode, operand0),
4626 pc_rtx)));
4631 gen_cmp_fp (enum rtx_code code, rtx operand0, rtx operand1)
4633 return gen_rtx_SET (VOIDmode, gen_rtx_REG (CCFPmode, 0),
4634 gen_rtx_fmt_ee (code, CCFPmode, operand0, operand1));
4637 /* Adjust the cost of a scheduling dependency. Return the new cost of
4638 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
4640 static int
4641 pa_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
4643 enum attr_type attr_type;
4645 /* Don't adjust costs for a pa8000 chip, also do not adjust any
4646 true dependencies as they are described with bypasses now. */
4647 if (pa_cpu >= PROCESSOR_8000 || REG_NOTE_KIND (link) == 0)
4648 return cost;
4650 if (! recog_memoized (insn))
4651 return 0;
4653 attr_type = get_attr_type (insn);
4655 if (REG_NOTE_KIND (link) == REG_DEP_ANTI)
4657 /* Anti dependency; DEP_INSN reads a register that INSN writes some
4658 cycles later. */
4660 if (attr_type == TYPE_FPLOAD)
4662 rtx pat = PATTERN (insn);
4663 rtx dep_pat = PATTERN (dep_insn);
4664 if (GET_CODE (pat) == PARALLEL)
4666 /* This happens for the fldXs,mb patterns. */
4667 pat = XVECEXP (pat, 0, 0);
4669 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4670 /* If this happens, we have to extend this to schedule
4671 optimally. Return 0 for now. */
4672 return 0;
4674 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4676 if (! recog_memoized (dep_insn))
4677 return 0;
4678 switch (get_attr_type (dep_insn))
4680 case TYPE_FPALU:
4681 case TYPE_FPMULSGL:
4682 case TYPE_FPMULDBL:
4683 case TYPE_FPDIVSGL:
4684 case TYPE_FPDIVDBL:
4685 case TYPE_FPSQRTSGL:
4686 case TYPE_FPSQRTDBL:
4687 /* A fpload can't be issued until one cycle before a
4688 preceding arithmetic operation has finished if
4689 the target of the fpload is any of the sources
4690 (or destination) of the arithmetic operation. */
4691 return insn_default_latency (dep_insn) - 1;
4693 default:
4694 return 0;
4698 else if (attr_type == TYPE_FPALU)
4700 rtx pat = PATTERN (insn);
4701 rtx dep_pat = PATTERN (dep_insn);
4702 if (GET_CODE (pat) == PARALLEL)
4704 /* This happens for the fldXs,mb patterns. */
4705 pat = XVECEXP (pat, 0, 0);
4707 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4708 /* If this happens, we have to extend this to schedule
4709 optimally. Return 0 for now. */
4710 return 0;
4712 if (reg_mentioned_p (SET_DEST (pat), SET_SRC (dep_pat)))
4714 if (! recog_memoized (dep_insn))
4715 return 0;
4716 switch (get_attr_type (dep_insn))
4718 case TYPE_FPDIVSGL:
4719 case TYPE_FPDIVDBL:
4720 case TYPE_FPSQRTSGL:
4721 case TYPE_FPSQRTDBL:
4722 /* An ALU flop can't be issued until two cycles before a
4723 preceding divide or sqrt operation has finished if
4724 the target of the ALU flop is any of the sources
4725 (or destination) of the divide or sqrt operation. */
4726 return insn_default_latency (dep_insn) - 2;
4728 default:
4729 return 0;
4734 /* For other anti dependencies, the cost is 0. */
4735 return 0;
4737 else if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT)
4739 /* Output dependency; DEP_INSN writes a register that INSN writes some
4740 cycles later. */
4741 if (attr_type == TYPE_FPLOAD)
4743 rtx pat = PATTERN (insn);
4744 rtx dep_pat = PATTERN (dep_insn);
4745 if (GET_CODE (pat) == PARALLEL)
4747 /* This happens for the fldXs,mb patterns. */
4748 pat = XVECEXP (pat, 0, 0);
4750 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4751 /* If this happens, we have to extend this to schedule
4752 optimally. Return 0 for now. */
4753 return 0;
4755 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4757 if (! recog_memoized (dep_insn))
4758 return 0;
4759 switch (get_attr_type (dep_insn))
4761 case TYPE_FPALU:
4762 case TYPE_FPMULSGL:
4763 case TYPE_FPMULDBL:
4764 case TYPE_FPDIVSGL:
4765 case TYPE_FPDIVDBL:
4766 case TYPE_FPSQRTSGL:
4767 case TYPE_FPSQRTDBL:
4768 /* A fpload can't be issued until one cycle before a
4769 preceding arithmetic operation has finished if
4770 the target of the fpload is the destination of the
4771 arithmetic operation.
4773 Exception: For PA7100LC, PA7200 and PA7300, the cost
4774 is 3 cycles, unless they bundle together. We also
4775 pay the penalty if the second insn is a fpload. */
4776 return insn_default_latency (dep_insn) - 1;
4778 default:
4779 return 0;
4783 else if (attr_type == TYPE_FPALU)
4785 rtx pat = PATTERN (insn);
4786 rtx dep_pat = PATTERN (dep_insn);
4787 if (GET_CODE (pat) == PARALLEL)
4789 /* This happens for the fldXs,mb patterns. */
4790 pat = XVECEXP (pat, 0, 0);
4792 if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
4793 /* If this happens, we have to extend this to schedule
4794 optimally. Return 0 for now. */
4795 return 0;
4797 if (reg_mentioned_p (SET_DEST (pat), SET_DEST (dep_pat)))
4799 if (! recog_memoized (dep_insn))
4800 return 0;
4801 switch (get_attr_type (dep_insn))
4803 case TYPE_FPDIVSGL:
4804 case TYPE_FPDIVDBL:
4805 case TYPE_FPSQRTSGL:
4806 case TYPE_FPSQRTDBL:
4807 /* An ALU flop can't be issued until two cycles before a
4808 preceding divide or sqrt operation has finished if
4809 the target of the ALU flop is also the target of
4810 the divide or sqrt operation. */
4811 return insn_default_latency (dep_insn) - 2;
4813 default:
4814 return 0;
4819 /* For other output dependencies, the cost is 0. */
4820 return 0;
4822 else
4823 abort ();
4826 /* Adjust scheduling priorities. We use this to try and keep addil
4827 and the next use of %r1 close together. */
4828 static int
4829 pa_adjust_priority (rtx insn, int priority)
4831 rtx set = single_set (insn);
4832 rtx src, dest;
4833 if (set)
4835 src = SET_SRC (set);
4836 dest = SET_DEST (set);
4837 if (GET_CODE (src) == LO_SUM
4838 && symbolic_operand (XEXP (src, 1), VOIDmode)
4839 && ! read_only_operand (XEXP (src, 1), VOIDmode))
4840 priority >>= 3;
4842 else if (GET_CODE (src) == MEM
4843 && GET_CODE (XEXP (src, 0)) == LO_SUM
4844 && symbolic_operand (XEXP (XEXP (src, 0), 1), VOIDmode)
4845 && ! read_only_operand (XEXP (XEXP (src, 0), 1), VOIDmode))
4846 priority >>= 1;
4848 else if (GET_CODE (dest) == MEM
4849 && GET_CODE (XEXP (dest, 0)) == LO_SUM
4850 && symbolic_operand (XEXP (XEXP (dest, 0), 1), VOIDmode)
4851 && ! read_only_operand (XEXP (XEXP (dest, 0), 1), VOIDmode))
4852 priority >>= 3;
4854 return priority;
4857 /* The 700 can only issue a single insn at a time.
4858 The 7XXX processors can issue two insns at a time.
4859 The 8000 can issue 4 insns at a time. */
4860 static int
4861 pa_issue_rate (void)
4863 switch (pa_cpu)
4865 case PROCESSOR_700: return 1;
4866 case PROCESSOR_7100: return 2;
4867 case PROCESSOR_7100LC: return 2;
4868 case PROCESSOR_7200: return 2;
4869 case PROCESSOR_7300: return 2;
4870 case PROCESSOR_8000: return 4;
4872 default:
4873 abort ();
4879 /* Return any length adjustment needed by INSN which already has its length
4880 computed as LENGTH. Return zero if no adjustment is necessary.
4882 For the PA: function calls, millicode calls, and backwards short
4883 conditional branches with unfilled delay slots need an adjustment by +1
4884 (to account for the NOP which will be inserted into the instruction stream).
4886 Also compute the length of an inline block move here as it is too
4887 complicated to express as a length attribute in pa.md. */
4889 pa_adjust_insn_length (rtx insn, int length)
4891 rtx pat = PATTERN (insn);
4893 /* Jumps inside switch tables which have unfilled delay slots need
4894 adjustment. */
4895 if (GET_CODE (insn) == JUMP_INSN
4896 && GET_CODE (pat) == PARALLEL
4897 && get_attr_type (insn) == TYPE_BTABLE_BRANCH)
4898 return 4;
4899 /* Millicode insn with an unfilled delay slot. */
4900 else if (GET_CODE (insn) == INSN
4901 && GET_CODE (pat) != SEQUENCE
4902 && GET_CODE (pat) != USE
4903 && GET_CODE (pat) != CLOBBER
4904 && get_attr_type (insn) == TYPE_MILLI)
4905 return 4;
4906 /* Block move pattern. */
4907 else if (GET_CODE (insn) == INSN
4908 && GET_CODE (pat) == PARALLEL
4909 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
4910 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
4911 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 1)) == MEM
4912 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode
4913 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 1)) == BLKmode)
4914 return compute_movmem_length (insn) - 4;
4915 /* Block clear pattern. */
4916 else if (GET_CODE (insn) == INSN
4917 && GET_CODE (pat) == PARALLEL
4918 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
4919 && GET_CODE (XEXP (XVECEXP (pat, 0, 0), 0)) == MEM
4920 && XEXP (XVECEXP (pat, 0, 0), 1) == const0_rtx
4921 && GET_MODE (XEXP (XVECEXP (pat, 0, 0), 0)) == BLKmode)
4922 return compute_clrmem_length (insn) - 4;
4923 /* Conditional branch with an unfilled delay slot. */
4924 else if (GET_CODE (insn) == JUMP_INSN && ! simplejump_p (insn))
4926 /* Adjust a short backwards conditional with an unfilled delay slot. */
4927 if (GET_CODE (pat) == SET
4928 && length == 4
4929 && ! forward_branch_p (insn))
4930 return 4;
4931 else if (GET_CODE (pat) == PARALLEL
4932 && get_attr_type (insn) == TYPE_PARALLEL_BRANCH
4933 && length == 4)
4934 return 4;
4935 /* Adjust dbra insn with short backwards conditional branch with
4936 unfilled delay slot -- only for case where counter is in a
4937 general register register. */
4938 else if (GET_CODE (pat) == PARALLEL
4939 && GET_CODE (XVECEXP (pat, 0, 1)) == SET
4940 && GET_CODE (XEXP (XVECEXP (pat, 0, 1), 0)) == REG
4941 && ! FP_REG_P (XEXP (XVECEXP (pat, 0, 1), 0))
4942 && length == 4
4943 && ! forward_branch_p (insn))
4944 return 4;
4945 else
4946 return 0;
4948 return 0;
4951 /* Print operand X (an rtx) in assembler syntax to file FILE.
4952 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
4953 For `%' followed by punctuation, CODE is the punctuation and X is null. */
4955 void
4956 print_operand (FILE *file, rtx x, int code)
4958 switch (code)
4960 case '#':
4961 /* Output a 'nop' if there's nothing for the delay slot. */
4962 if (dbr_sequence_length () == 0)
4963 fputs ("\n\tnop", file);
4964 return;
4965 case '*':
4966 /* Output a nullification completer if there's nothing for the */
4967 /* delay slot or nullification is requested. */
4968 if (dbr_sequence_length () == 0 ||
4969 (final_sequence &&
4970 INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))))
4971 fputs (",n", file);
4972 return;
4973 case 'R':
4974 /* Print out the second register name of a register pair.
4975 I.e., R (6) => 7. */
4976 fputs (reg_names[REGNO (x) + 1], file);
4977 return;
4978 case 'r':
4979 /* A register or zero. */
4980 if (x == const0_rtx
4981 || (x == CONST0_RTX (DFmode))
4982 || (x == CONST0_RTX (SFmode)))
4984 fputs ("%r0", file);
4985 return;
4987 else
4988 break;
4989 case 'f':
4990 /* A register or zero (floating point). */
4991 if (x == const0_rtx
4992 || (x == CONST0_RTX (DFmode))
4993 || (x == CONST0_RTX (SFmode)))
4995 fputs ("%fr0", file);
4996 return;
4998 else
4999 break;
5000 case 'A':
5002 rtx xoperands[2];
5004 xoperands[0] = XEXP (XEXP (x, 0), 0);
5005 xoperands[1] = XVECEXP (XEXP (XEXP (x, 0), 1), 0, 0);
5006 output_global_address (file, xoperands[1], 0);
5007 fprintf (file, "(%s)", reg_names [REGNO (xoperands[0])]);
5008 return;
5011 case 'C': /* Plain (C)ondition */
5012 case 'X':
5013 switch (GET_CODE (x))
5015 case EQ:
5016 fputs ("=", file); break;
5017 case NE:
5018 fputs ("<>", file); break;
5019 case GT:
5020 fputs (">", file); break;
5021 case GE:
5022 fputs (">=", file); break;
5023 case GEU:
5024 fputs (">>=", file); break;
5025 case GTU:
5026 fputs (">>", file); break;
5027 case LT:
5028 fputs ("<", file); break;
5029 case LE:
5030 fputs ("<=", file); break;
5031 case LEU:
5032 fputs ("<<=", file); break;
5033 case LTU:
5034 fputs ("<<", file); break;
5035 default:
5036 abort ();
5038 return;
5039 case 'N': /* Condition, (N)egated */
5040 switch (GET_CODE (x))
5042 case EQ:
5043 fputs ("<>", file); break;
5044 case NE:
5045 fputs ("=", file); break;
5046 case GT:
5047 fputs ("<=", file); break;
5048 case GE:
5049 fputs ("<", file); break;
5050 case GEU:
5051 fputs ("<<", file); break;
5052 case GTU:
5053 fputs ("<<=", file); break;
5054 case LT:
5055 fputs (">=", file); break;
5056 case LE:
5057 fputs (">", file); break;
5058 case LEU:
5059 fputs (">>", file); break;
5060 case LTU:
5061 fputs (">>=", file); break;
5062 default:
5063 abort ();
5065 return;
5066 /* For floating point comparisons. Note that the output
5067 predicates are the complement of the desired mode. */
5068 case 'Y':
5069 switch (GET_CODE (x))
5071 case EQ:
5072 fputs ("!=", file); break;
5073 case NE:
5074 fputs ("=", file); break;
5075 case GT:
5076 fputs ("!>", file); break;
5077 case GE:
5078 fputs ("!>=", file); break;
5079 case LT:
5080 fputs ("!<", file); break;
5081 case LE:
5082 fputs ("!<=", file); break;
5083 case LTGT:
5084 fputs ("!<>", file); break;
5085 case UNLE:
5086 fputs (">", file); break;
5087 case UNLT:
5088 fputs (">=", file); break;
5089 case UNGE:
5090 fputs ("<", file); break;
5091 case UNGT:
5092 fputs ("<=", file); break;
5093 case UNEQ:
5094 fputs ("<>", file); break;
5095 case UNORDERED:
5096 fputs ("<=>", file); break;
5097 case ORDERED:
5098 fputs ("!<=>", file); break;
5099 default:
5100 abort ();
5102 return;
5103 case 'S': /* Condition, operands are (S)wapped. */
5104 switch (GET_CODE (x))
5106 case EQ:
5107 fputs ("=", file); break;
5108 case NE:
5109 fputs ("<>", file); break;
5110 case GT:
5111 fputs ("<", file); break;
5112 case GE:
5113 fputs ("<=", file); break;
5114 case GEU:
5115 fputs ("<<=", file); break;
5116 case GTU:
5117 fputs ("<<", file); break;
5118 case LT:
5119 fputs (">", file); break;
5120 case LE:
5121 fputs (">=", file); break;
5122 case LEU:
5123 fputs (">>=", file); break;
5124 case LTU:
5125 fputs (">>", file); break;
5126 default:
5127 abort ();
5129 return;
5130 case 'B': /* Condition, (B)oth swapped and negate. */
5131 switch (GET_CODE (x))
5133 case EQ:
5134 fputs ("<>", file); break;
5135 case NE:
5136 fputs ("=", file); break;
5137 case GT:
5138 fputs (">=", file); break;
5139 case GE:
5140 fputs (">", file); break;
5141 case GEU:
5142 fputs (">>", file); break;
5143 case GTU:
5144 fputs (">>=", file); break;
5145 case LT:
5146 fputs ("<=", file); break;
5147 case LE:
5148 fputs ("<", file); break;
5149 case LEU:
5150 fputs ("<<", file); break;
5151 case LTU:
5152 fputs ("<<=", file); break;
5153 default:
5154 abort ();
5156 return;
5157 case 'k':
5158 if (GET_CODE (x) == CONST_INT)
5160 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~INTVAL (x));
5161 return;
5163 abort ();
5164 case 'Q':
5165 if (GET_CODE (x) == CONST_INT)
5167 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 64 - (INTVAL (x) & 63));
5168 return;
5170 abort ();
5171 case 'L':
5172 if (GET_CODE (x) == CONST_INT)
5174 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 32 - (INTVAL (x) & 31));
5175 return;
5177 abort ();
5178 case 'O':
5179 if (GET_CODE (x) == CONST_INT && exact_log2 (INTVAL (x)) >= 0)
5181 fprintf (file, "%d", exact_log2 (INTVAL (x)));
5182 return;
5184 abort ();
5185 case 'p':
5186 if (GET_CODE (x) == CONST_INT)
5188 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 63 - (INTVAL (x) & 63));
5189 return;
5191 abort ();
5192 case 'P':
5193 if (GET_CODE (x) == CONST_INT)
5195 fprintf (file, HOST_WIDE_INT_PRINT_DEC, 31 - (INTVAL (x) & 31));
5196 return;
5198 abort ();
5199 case 'I':
5200 if (GET_CODE (x) == CONST_INT)
5201 fputs ("i", file);
5202 return;
5203 case 'M':
5204 case 'F':
5205 switch (GET_CODE (XEXP (x, 0)))
5207 case PRE_DEC:
5208 case PRE_INC:
5209 if (ASSEMBLER_DIALECT == 0)
5210 fputs ("s,mb", file);
5211 else
5212 fputs (",mb", file);
5213 break;
5214 case POST_DEC:
5215 case POST_INC:
5216 if (ASSEMBLER_DIALECT == 0)
5217 fputs ("s,ma", file);
5218 else
5219 fputs (",ma", file);
5220 break;
5221 case PLUS:
5222 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5223 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5225 if (ASSEMBLER_DIALECT == 0)
5226 fputs ("x", file);
5228 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
5229 || GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5231 if (ASSEMBLER_DIALECT == 0)
5232 fputs ("x,s", file);
5233 else
5234 fputs (",s", file);
5236 else if (code == 'F' && ASSEMBLER_DIALECT == 0)
5237 fputs ("s", file);
5238 break;
5239 default:
5240 if (code == 'F' && ASSEMBLER_DIALECT == 0)
5241 fputs ("s", file);
5242 break;
5244 return;
5245 case 'G':
5246 output_global_address (file, x, 0);
5247 return;
5248 case 'H':
5249 output_global_address (file, x, 1);
5250 return;
5251 case 0: /* Don't do anything special */
5252 break;
5253 case 'Z':
5255 unsigned op[3];
5256 compute_zdepwi_operands (INTVAL (x), op);
5257 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5258 return;
5260 case 'z':
5262 unsigned op[3];
5263 compute_zdepdi_operands (INTVAL (x), op);
5264 fprintf (file, "%d,%d,%d", op[0], op[1], op[2]);
5265 return;
5267 case 'c':
5268 /* We can get here from a .vtable_inherit due to our
5269 CONSTANT_ADDRESS_P rejecting perfectly good constant
5270 addresses. */
5271 break;
5272 default:
5273 abort ();
5275 if (GET_CODE (x) == REG)
5277 fputs (reg_names [REGNO (x)], file);
5278 if (TARGET_64BIT && FP_REG_P (x) && GET_MODE_SIZE (GET_MODE (x)) <= 4)
5280 fputs ("R", file);
5281 return;
5283 if (FP_REG_P (x)
5284 && GET_MODE_SIZE (GET_MODE (x)) <= 4
5285 && (REGNO (x) & 1) == 0)
5286 fputs ("L", file);
5288 else if (GET_CODE (x) == MEM)
5290 int size = GET_MODE_SIZE (GET_MODE (x));
5291 rtx base = NULL_RTX;
5292 switch (GET_CODE (XEXP (x, 0)))
5294 case PRE_DEC:
5295 case POST_DEC:
5296 base = XEXP (XEXP (x, 0), 0);
5297 fprintf (file, "-%d(%s)", size, reg_names [REGNO (base)]);
5298 break;
5299 case PRE_INC:
5300 case POST_INC:
5301 base = XEXP (XEXP (x, 0), 0);
5302 fprintf (file, "%d(%s)", size, reg_names [REGNO (base)]);
5303 break;
5304 case PLUS:
5305 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
5306 fprintf (file, "%s(%s)",
5307 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 0), 0))],
5308 reg_names [REGNO (XEXP (XEXP (x, 0), 1))]);
5309 else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == MULT)
5310 fprintf (file, "%s(%s)",
5311 reg_names [REGNO (XEXP (XEXP (XEXP (x, 0), 1), 0))],
5312 reg_names [REGNO (XEXP (XEXP (x, 0), 0))]);
5313 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
5314 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
5316 /* Because the REG_POINTER flag can get lost during reload,
5317 GO_IF_LEGITIMATE_ADDRESS canonicalizes the order of the
5318 index and base registers in the combined move patterns. */
5319 rtx base = XEXP (XEXP (x, 0), 1);
5320 rtx index = XEXP (XEXP (x, 0), 0);
5322 fprintf (file, "%s(%s)",
5323 reg_names [REGNO (index)], reg_names [REGNO (base)]);
5325 else
5326 output_address (XEXP (x, 0));
5327 break;
5328 default:
5329 output_address (XEXP (x, 0));
5330 break;
5333 else
5334 output_addr_const (file, x);
5337 /* output a SYMBOL_REF or a CONST expression involving a SYMBOL_REF. */
5339 void
5340 output_global_address (FILE *file, rtx x, int round_constant)
5343 /* Imagine (high (const (plus ...))). */
5344 if (GET_CODE (x) == HIGH)
5345 x = XEXP (x, 0);
5347 if (GET_CODE (x) == SYMBOL_REF && read_only_operand (x, VOIDmode))
5348 assemble_name (file, XSTR (x, 0));
5349 else if (GET_CODE (x) == SYMBOL_REF && !flag_pic)
5351 assemble_name (file, XSTR (x, 0));
5352 fputs ("-$global$", file);
5354 else if (GET_CODE (x) == CONST)
5356 const char *sep = "";
5357 int offset = 0; /* assembler wants -$global$ at end */
5358 rtx base = NULL_RTX;
5360 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)
5362 base = XEXP (XEXP (x, 0), 0);
5363 output_addr_const (file, base);
5365 else if (GET_CODE (XEXP (XEXP (x, 0), 0)) == CONST_INT)
5366 offset = INTVAL (XEXP (XEXP (x, 0), 0));
5367 else abort ();
5369 if (GET_CODE (XEXP (XEXP (x, 0), 1)) == SYMBOL_REF)
5371 base = XEXP (XEXP (x, 0), 1);
5372 output_addr_const (file, base);
5374 else if (GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
5375 offset = INTVAL (XEXP (XEXP (x, 0), 1));
5376 else abort ();
5378 /* How bogus. The compiler is apparently responsible for
5379 rounding the constant if it uses an LR field selector.
5381 The linker and/or assembler seem a better place since
5382 they have to do this kind of thing already.
5384 If we fail to do this, HP's optimizing linker may eliminate
5385 an addil, but not update the ldw/stw/ldo instruction that
5386 uses the result of the addil. */
5387 if (round_constant)
5388 offset = ((offset + 0x1000) & ~0x1fff);
5390 if (GET_CODE (XEXP (x, 0)) == PLUS)
5392 if (offset < 0)
5394 offset = -offset;
5395 sep = "-";
5397 else
5398 sep = "+";
5400 else if (GET_CODE (XEXP (x, 0)) == MINUS
5401 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF))
5402 sep = "-";
5403 else abort ();
5405 if (!read_only_operand (base, VOIDmode) && !flag_pic)
5406 fputs ("-$global$", file);
5407 if (offset)
5408 fprintf (file, "%s%d", sep, offset);
5410 else
5411 output_addr_const (file, x);
5414 /* Output boilerplate text to appear at the beginning of the file.
5415 There are several possible versions. */
5416 #define aputs(x) fputs(x, asm_out_file)
5417 static inline void
5418 pa_file_start_level (void)
5420 if (TARGET_64BIT)
5421 aputs ("\t.LEVEL 2.0w\n");
5422 else if (TARGET_PA_20)
5423 aputs ("\t.LEVEL 2.0\n");
5424 else if (TARGET_PA_11)
5425 aputs ("\t.LEVEL 1.1\n");
5426 else
5427 aputs ("\t.LEVEL 1.0\n");
5430 static inline void
5431 pa_file_start_space (int sortspace)
5433 aputs ("\t.SPACE $PRIVATE$");
5434 if (sortspace)
5435 aputs (",SORT=16");
5436 aputs ("\n\t.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31"
5437 "\n\t.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82"
5438 "\n\t.SPACE $TEXT$");
5439 if (sortspace)
5440 aputs (",SORT=8");
5441 aputs ("\n\t.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44"
5442 "\n\t.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n");
5445 static inline void
5446 pa_file_start_file (int want_version)
5448 if (write_symbols != NO_DEBUG)
5450 output_file_directive (asm_out_file, main_input_filename);
5451 if (want_version)
5452 aputs ("\t.version\t\"01.01\"\n");
5456 static inline void
5457 pa_file_start_mcount (const char *aswhat)
5459 if (profile_flag)
5460 fprintf (asm_out_file, "\t.IMPORT _mcount,%s\n", aswhat);
5463 static void
5464 pa_elf_file_start (void)
5466 pa_file_start_level ();
5467 pa_file_start_mcount ("ENTRY");
5468 pa_file_start_file (0);
5471 static void
5472 pa_som_file_start (void)
5474 pa_file_start_level ();
5475 pa_file_start_space (0);
5476 aputs ("\t.IMPORT $global$,DATA\n"
5477 "\t.IMPORT $$dyncall,MILLICODE\n");
5478 pa_file_start_mcount ("CODE");
5479 pa_file_start_file (0);
5482 static void
5483 pa_linux_file_start (void)
5485 pa_file_start_file (1);
5486 pa_file_start_level ();
5487 pa_file_start_mcount ("CODE");
5490 static void
5491 pa_hpux64_gas_file_start (void)
5493 pa_file_start_level ();
5494 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
5495 if (profile_flag)
5496 ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, "_mcount", "function");
5497 #endif
5498 pa_file_start_file (1);
5501 static void
5502 pa_hpux64_hpas_file_start (void)
5504 pa_file_start_level ();
5505 pa_file_start_space (1);
5506 pa_file_start_mcount ("CODE");
5507 pa_file_start_file (0);
5509 #undef aputs
5511 static struct deferred_plabel *
5512 get_plabel (const char *fname)
5514 size_t i;
5516 /* See if we have already put this function on the list of deferred
5517 plabels. This list is generally small, so a liner search is not
5518 too ugly. If it proves too slow replace it with something faster. */
5519 for (i = 0; i < n_deferred_plabels; i++)
5520 if (strcmp (fname, deferred_plabels[i].name) == 0)
5521 break;
5523 /* If the deferred plabel list is empty, or this entry was not found
5524 on the list, create a new entry on the list. */
5525 if (deferred_plabels == NULL || i == n_deferred_plabels)
5527 const char *real_name;
5529 if (deferred_plabels == 0)
5530 deferred_plabels = (struct deferred_plabel *)
5531 ggc_alloc (sizeof (struct deferred_plabel));
5532 else
5533 deferred_plabels = (struct deferred_plabel *)
5534 ggc_realloc (deferred_plabels,
5535 ((n_deferred_plabels + 1)
5536 * sizeof (struct deferred_plabel)));
5538 i = n_deferred_plabels++;
5539 deferred_plabels[i].internal_label = gen_label_rtx ();
5540 deferred_plabels[i].name = ggc_strdup (fname);
5542 /* Gross. We have just implicitly taken the address of this function,
5543 mark it as such. */
5544 real_name = (*targetm.strip_name_encoding) (fname);
5545 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
5548 return &deferred_plabels[i];
5551 static void
5552 output_deferred_plabels (void)
5554 size_t i;
5555 /* If we have deferred plabels, then we need to switch into the data
5556 section and align it to a 4 byte boundary before we output the
5557 deferred plabels. */
5558 if (n_deferred_plabels)
5560 data_section ();
5561 ASM_OUTPUT_ALIGN (asm_out_file, TARGET_64BIT ? 3 : 2);
5564 /* Now output the deferred plabels. */
5565 for (i = 0; i < n_deferred_plabels; i++)
5567 (*targetm.asm_out.internal_label) (asm_out_file, "L",
5568 CODE_LABEL_NUMBER (deferred_plabels[i].internal_label));
5569 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, deferred_plabels[i].name),
5570 TARGET_64BIT ? 8 : 4, TARGET_64BIT ? 64 : 32, 1);
5574 #ifdef HPUX_LONG_DOUBLE_LIBRARY
5575 /* Initialize optabs to point to HPUX long double emulation routines. */
5576 static void
5577 pa_hpux_init_libfuncs (void)
5579 set_optab_libfunc (add_optab, TFmode, "_U_Qfadd");
5580 set_optab_libfunc (sub_optab, TFmode, "_U_Qfsub");
5581 set_optab_libfunc (smul_optab, TFmode, "_U_Qfmpy");
5582 set_optab_libfunc (sdiv_optab, TFmode, "_U_Qfdiv");
5583 set_optab_libfunc (smin_optab, TFmode, "_U_Qmin");
5584 set_optab_libfunc (smax_optab, TFmode, "_U_Qfmax");
5585 set_optab_libfunc (sqrt_optab, TFmode, "_U_Qfsqrt");
5586 set_optab_libfunc (abs_optab, TFmode, "_U_Qfabs");
5587 set_optab_libfunc (neg_optab, TFmode, "_U_Qfneg");
5589 set_optab_libfunc (eq_optab, TFmode, "_U_Qfeq");
5590 set_optab_libfunc (ne_optab, TFmode, "_U_Qfne");
5591 set_optab_libfunc (gt_optab, TFmode, "_U_Qfgt");
5592 set_optab_libfunc (ge_optab, TFmode, "_U_Qfge");
5593 set_optab_libfunc (lt_optab, TFmode, "_U_Qflt");
5594 set_optab_libfunc (le_optab, TFmode, "_U_Qfle");
5595 set_optab_libfunc (unord_optab, TFmode, "_U_Qfunord");
5597 set_conv_libfunc (sext_optab, TFmode, SFmode, "_U_Qfcnvff_sgl_to_quad");
5598 set_conv_libfunc (sext_optab, TFmode, DFmode, "_U_Qfcnvff_dbl_to_quad");
5599 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_U_Qfcnvff_quad_to_sgl");
5600 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_U_Qfcnvff_quad_to_dbl");
5602 set_conv_libfunc (sfix_optab, SImode, TFmode, TARGET_64BIT
5603 ? "__U_Qfcnvfxt_quad_to_sgl"
5604 : "_U_Qfcnvfxt_quad_to_sgl");
5605 set_conv_libfunc (sfix_optab, DImode, TFmode, "_U_Qfcnvfxt_quad_to_dbl");
5606 set_conv_libfunc (ufix_optab, SImode, TFmode, "_U_Qfcnvfxt_quad_to_usgl");
5607 set_conv_libfunc (ufix_optab, DImode, TFmode, "_U_Qfcnvfxt_quad_to_udbl");
5609 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_U_Qfcnvxf_sgl_to_quad");
5610 set_conv_libfunc (sfloat_optab, TFmode, DImode, "_U_Qfcnvxf_dbl_to_quad");
5612 #endif
5614 /* HP's millicode routines mean something special to the assembler.
5615 Keep track of which ones we have used. */
5617 enum millicodes { remI, remU, divI, divU, mulI, end1000 };
5618 static void import_milli (enum millicodes);
5619 static char imported[(int) end1000];
5620 static const char * const milli_names[] = {"remI", "remU", "divI", "divU", "mulI"};
5621 static const char import_string[] = ".IMPORT $$....,MILLICODE";
5622 #define MILLI_START 10
5624 static void
5625 import_milli (enum millicodes code)
5627 char str[sizeof (import_string)];
5629 if (!imported[(int) code])
5631 imported[(int) code] = 1;
5632 strcpy (str, import_string);
5633 strncpy (str + MILLI_START, milli_names[(int) code], 4);
5634 output_asm_insn (str, 0);
5638 /* The register constraints have put the operands and return value in
5639 the proper registers. */
5641 const char *
5642 output_mul_insn (int unsignedp ATTRIBUTE_UNUSED, rtx insn)
5644 import_milli (mulI);
5645 return output_millicode_call (insn, gen_rtx_SYMBOL_REF (Pmode, "$$mulI"));
5648 /* Emit the rtl for doing a division by a constant. */
5650 /* Do magic division millicodes exist for this value? */
5651 static const int magic_milli[]= {0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0,
5652 1, 1};
5654 /* We'll use an array to keep track of the magic millicodes and
5655 whether or not we've used them already. [n][0] is signed, [n][1] is
5656 unsigned. */
5658 static int div_milli[16][2];
5661 div_operand (rtx op, enum machine_mode mode)
5663 return (mode == SImode
5664 && ((GET_CODE (op) == REG && REGNO (op) == 25)
5665 || (GET_CODE (op) == CONST_INT && INTVAL (op) > 0
5666 && INTVAL (op) < 16 && magic_milli[INTVAL (op)])));
5670 emit_hpdiv_const (rtx *operands, int unsignedp)
5672 if (GET_CODE (operands[2]) == CONST_INT
5673 && INTVAL (operands[2]) > 0
5674 && INTVAL (operands[2]) < 16
5675 && magic_milli[INTVAL (operands[2])])
5677 rtx ret = gen_rtx_REG (SImode, TARGET_64BIT ? 2 : 31);
5679 emit_move_insn (gen_rtx_REG (SImode, 26), operands[1]);
5680 emit
5681 (gen_rtx_PARALLEL
5682 (VOIDmode,
5683 gen_rtvec (6, gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, 29),
5684 gen_rtx_fmt_ee (unsignedp ? UDIV : DIV,
5685 SImode,
5686 gen_rtx_REG (SImode, 26),
5687 operands[2])),
5688 gen_rtx_CLOBBER (VOIDmode, operands[4]),
5689 gen_rtx_CLOBBER (VOIDmode, operands[3]),
5690 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 26)),
5691 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 25)),
5692 gen_rtx_CLOBBER (VOIDmode, ret))));
5693 emit_move_insn (operands[0], gen_rtx_REG (SImode, 29));
5694 return 1;
5696 return 0;
5699 const char *
5700 output_div_insn (rtx *operands, int unsignedp, rtx insn)
5702 int divisor;
5704 /* If the divisor is a constant, try to use one of the special
5705 opcodes .*/
5706 if (GET_CODE (operands[0]) == CONST_INT)
5708 static char buf[100];
5709 divisor = INTVAL (operands[0]);
5710 if (!div_milli[divisor][unsignedp])
5712 div_milli[divisor][unsignedp] = 1;
5713 if (unsignedp)
5714 output_asm_insn (".IMPORT $$divU_%0,MILLICODE", operands);
5715 else
5716 output_asm_insn (".IMPORT $$divI_%0,MILLICODE", operands);
5718 if (unsignedp)
5720 sprintf (buf, "$$divU_" HOST_WIDE_INT_PRINT_DEC,
5721 INTVAL (operands[0]));
5722 return output_millicode_call (insn,
5723 gen_rtx_SYMBOL_REF (SImode, buf));
5725 else
5727 sprintf (buf, "$$divI_" HOST_WIDE_INT_PRINT_DEC,
5728 INTVAL (operands[0]));
5729 return output_millicode_call (insn,
5730 gen_rtx_SYMBOL_REF (SImode, buf));
5733 /* Divisor isn't a special constant. */
5734 else
5736 if (unsignedp)
5738 import_milli (divU);
5739 return output_millicode_call (insn,
5740 gen_rtx_SYMBOL_REF (SImode, "$$divU"));
5742 else
5744 import_milli (divI);
5745 return output_millicode_call (insn,
5746 gen_rtx_SYMBOL_REF (SImode, "$$divI"));
5751 /* Output a $$rem millicode to do mod. */
5753 const char *
5754 output_mod_insn (int unsignedp, rtx insn)
5756 if (unsignedp)
5758 import_milli (remU);
5759 return output_millicode_call (insn,
5760 gen_rtx_SYMBOL_REF (SImode, "$$remU"));
5762 else
5764 import_milli (remI);
5765 return output_millicode_call (insn,
5766 gen_rtx_SYMBOL_REF (SImode, "$$remI"));
5770 void
5771 output_arg_descriptor (rtx call_insn)
5773 const char *arg_regs[4];
5774 enum machine_mode arg_mode;
5775 rtx link;
5776 int i, output_flag = 0;
5777 int regno;
5779 /* We neither need nor want argument location descriptors for the
5780 64bit runtime environment or the ELF32 environment. */
5781 if (TARGET_64BIT || TARGET_ELF32)
5782 return;
5784 for (i = 0; i < 4; i++)
5785 arg_regs[i] = 0;
5787 /* Specify explicitly that no argument relocations should take place
5788 if using the portable runtime calling conventions. */
5789 if (TARGET_PORTABLE_RUNTIME)
5791 fputs ("\t.CALL ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RETVAL=NO\n",
5792 asm_out_file);
5793 return;
5796 if (GET_CODE (call_insn) != CALL_INSN)
5797 abort ();
5798 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); link; link = XEXP (link, 1))
5800 rtx use = XEXP (link, 0);
5802 if (! (GET_CODE (use) == USE
5803 && GET_CODE (XEXP (use, 0)) == REG
5804 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
5805 continue;
5807 arg_mode = GET_MODE (XEXP (use, 0));
5808 regno = REGNO (XEXP (use, 0));
5809 if (regno >= 23 && regno <= 26)
5811 arg_regs[26 - regno] = "GR";
5812 if (arg_mode == DImode)
5813 arg_regs[25 - regno] = "GR";
5815 else if (regno >= 32 && regno <= 39)
5817 if (arg_mode == SFmode)
5818 arg_regs[(regno - 32) / 2] = "FR";
5819 else
5821 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
5822 arg_regs[(regno - 34) / 2] = "FR";
5823 arg_regs[(regno - 34) / 2 + 1] = "FU";
5824 #else
5825 arg_regs[(regno - 34) / 2] = "FU";
5826 arg_regs[(regno - 34) / 2 + 1] = "FR";
5827 #endif
5831 fputs ("\t.CALL ", asm_out_file);
5832 for (i = 0; i < 4; i++)
5834 if (arg_regs[i])
5836 if (output_flag++)
5837 fputc (',', asm_out_file);
5838 fprintf (asm_out_file, "ARGW%d=%s", i, arg_regs[i]);
5841 fputc ('\n', asm_out_file);
5844 /* Return the class of any secondary reload register that is needed to
5845 move IN into a register in class CLASS using mode MODE.
5847 Profiling has showed this routine and its descendants account for
5848 a significant amount of compile time (~7%). So it has been
5849 optimized to reduce redundant computations and eliminate useless
5850 function calls.
5852 It might be worthwhile to try and make this a leaf function too. */
5854 enum reg_class
5855 secondary_reload_class (enum reg_class class, enum machine_mode mode, rtx in)
5857 int regno, is_symbolic;
5859 /* Trying to load a constant into a FP register during PIC code
5860 generation will require %r1 as a scratch register. */
5861 if (flag_pic
5862 && GET_MODE_CLASS (mode) == MODE_INT
5863 && FP_REG_CLASS_P (class)
5864 && (GET_CODE (in) == CONST_INT || GET_CODE (in) == CONST_DOUBLE))
5865 return R1_REGS;
5867 /* Profiling showed the PA port spends about 1.3% of its compilation
5868 time in true_regnum from calls inside secondary_reload_class. */
5870 if (GET_CODE (in) == REG)
5872 regno = REGNO (in);
5873 if (regno >= FIRST_PSEUDO_REGISTER)
5874 regno = true_regnum (in);
5876 else if (GET_CODE (in) == SUBREG)
5877 regno = true_regnum (in);
5878 else
5879 regno = -1;
5881 /* If we have something like (mem (mem (...)), we can safely assume the
5882 inner MEM will end up in a general register after reloading, so there's
5883 no need for a secondary reload. */
5884 if (GET_CODE (in) == MEM
5885 && GET_CODE (XEXP (in, 0)) == MEM)
5886 return NO_REGS;
5888 /* Handle out of range displacement for integer mode loads/stores of
5889 FP registers. */
5890 if (((regno >= FIRST_PSEUDO_REGISTER || regno == -1)
5891 && GET_MODE_CLASS (mode) == MODE_INT
5892 && FP_REG_CLASS_P (class))
5893 || (class == SHIFT_REGS && (regno <= 0 || regno >= 32)))
5894 return GENERAL_REGS;
5896 /* A SAR<->FP register copy requires a secondary register (GPR) as
5897 well as secondary memory. */
5898 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5899 && ((REGNO_REG_CLASS (regno) == SHIFT_REGS && FP_REG_CLASS_P (class))
5900 || (class == SHIFT_REGS && FP_REG_CLASS_P (REGNO_REG_CLASS (regno)))))
5901 return GENERAL_REGS;
5903 if (GET_CODE (in) == HIGH)
5904 in = XEXP (in, 0);
5906 /* Profiling has showed GCC spends about 2.6% of its compilation
5907 time in symbolic_operand from calls inside secondary_reload_class.
5909 We use an inline copy and only compute its return value once to avoid
5910 useless work. */
5911 switch (GET_CODE (in))
5913 rtx tmp;
5915 case SYMBOL_REF:
5916 case LABEL_REF:
5917 is_symbolic = 1;
5918 break;
5919 case CONST:
5920 tmp = XEXP (in, 0);
5921 is_symbolic = ((GET_CODE (XEXP (tmp, 0)) == SYMBOL_REF
5922 || GET_CODE (XEXP (tmp, 0)) == LABEL_REF)
5923 && GET_CODE (XEXP (tmp, 1)) == CONST_INT);
5924 break;
5926 default:
5927 is_symbolic = 0;
5928 break;
5931 if (!flag_pic
5932 && is_symbolic
5933 && read_only_operand (in, VOIDmode))
5934 return NO_REGS;
5936 if (class != R1_REGS && is_symbolic)
5937 return R1_REGS;
5939 return NO_REGS;
5942 /* In the 32-bit runtime, arguments larger than eight bytes are passed
5943 by invisible reference. As a GCC extension, we also pass anything
5944 with a zero or variable size by reference.
5946 The 64-bit runtime does not describe passing any types by invisible
5947 reference. The internals of GCC can't currently handle passing
5948 empty structures, and zero or variable length arrays when they are
5949 not passed entirely on the stack or by reference. Thus, as a GCC
5950 extension, we pass these types by reference. The HP compiler doesn't
5951 support these types, so hopefully there shouldn't be any compatibility
5952 issues. This may have to be revisited when HP releases a C99 compiler
5953 or updates the ABI. */
5955 static bool
5956 pa_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
5957 enum machine_mode mode, tree type,
5958 bool named ATTRIBUTE_UNUSED)
5960 HOST_WIDE_INT size;
5962 if (type)
5963 size = int_size_in_bytes (type);
5964 else
5965 size = GET_MODE_SIZE (mode);
5967 if (TARGET_64BIT)
5968 return size <= 0;
5969 else
5970 return size <= 0 || size > 8;
5973 enum direction
5974 function_arg_padding (enum machine_mode mode, tree type)
5976 if (mode == BLKmode
5977 || (TARGET_64BIT && type && AGGREGATE_TYPE_P (type)))
5979 /* Return none if justification is not required. */
5980 if (type
5981 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
5982 && (int_size_in_bytes (type) * BITS_PER_UNIT) % PARM_BOUNDARY == 0)
5983 return none;
5985 /* The directions set here are ignored when a BLKmode argument larger
5986 than a word is placed in a register. Different code is used for
5987 the stack and registers. This makes it difficult to have a
5988 consistent data representation for both the stack and registers.
5989 For both runtimes, the justification and padding for arguments on
5990 the stack and in registers should be identical. */
5991 if (TARGET_64BIT)
5992 /* The 64-bit runtime specifies left justification for aggregates. */
5993 return upward;
5994 else
5995 /* The 32-bit runtime architecture specifies right justification.
5996 When the argument is passed on the stack, the argument is padded
5997 with garbage on the left. The HP compiler pads with zeros. */
5998 return downward;
6001 if (GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
6002 return downward;
6003 else
6004 return none;
6008 /* Do what is necessary for `va_start'. We look at the current function
6009 to determine if stdargs or varargs is used and fill in an initial
6010 va_list. A pointer to this constructor is returned. */
6012 static rtx
6013 hppa_builtin_saveregs (void)
6015 rtx offset, dest;
6016 tree fntype = TREE_TYPE (current_function_decl);
6017 int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
6018 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
6019 != void_type_node)))
6020 ? UNITS_PER_WORD : 0);
6022 if (argadj)
6023 offset = plus_constant (current_function_arg_offset_rtx, argadj);
6024 else
6025 offset = current_function_arg_offset_rtx;
6027 if (TARGET_64BIT)
6029 int i, off;
6031 /* Adjust for varargs/stdarg differences. */
6032 if (argadj)
6033 offset = plus_constant (current_function_arg_offset_rtx, -argadj);
6034 else
6035 offset = current_function_arg_offset_rtx;
6037 /* We need to save %r26 .. %r19 inclusive starting at offset -64
6038 from the incoming arg pointer and growing to larger addresses. */
6039 for (i = 26, off = -64; i >= 19; i--, off += 8)
6040 emit_move_insn (gen_rtx_MEM (word_mode,
6041 plus_constant (arg_pointer_rtx, off)),
6042 gen_rtx_REG (word_mode, i));
6044 /* The incoming args pointer points just beyond the flushback area;
6045 normally this is not a serious concern. However, when we are doing
6046 varargs/stdargs we want to make the arg pointer point to the start
6047 of the incoming argument area. */
6048 emit_move_insn (virtual_incoming_args_rtx,
6049 plus_constant (arg_pointer_rtx, -64));
6051 /* Now return a pointer to the first anonymous argument. */
6052 return copy_to_reg (expand_binop (Pmode, add_optab,
6053 virtual_incoming_args_rtx,
6054 offset, 0, 0, OPTAB_LIB_WIDEN));
6057 /* Store general registers on the stack. */
6058 dest = gen_rtx_MEM (BLKmode,
6059 plus_constant (current_function_internal_arg_pointer,
6060 -16));
6061 set_mem_alias_set (dest, get_varargs_alias_set ());
6062 set_mem_align (dest, BITS_PER_WORD);
6063 move_block_from_reg (23, dest, 4);
6065 /* move_block_from_reg will emit code to store the argument registers
6066 individually as scalar stores.
6068 However, other insns may later load from the same addresses for
6069 a structure load (passing a struct to a varargs routine).
6071 The alias code assumes that such aliasing can never happen, so we
6072 have to keep memory referencing insns from moving up beyond the
6073 last argument register store. So we emit a blockage insn here. */
6074 emit_insn (gen_blockage ());
6076 return copy_to_reg (expand_binop (Pmode, add_optab,
6077 current_function_internal_arg_pointer,
6078 offset, 0, 0, OPTAB_LIB_WIDEN));
6081 void
6082 hppa_va_start (tree valist, rtx nextarg)
6084 nextarg = expand_builtin_saveregs ();
6085 std_expand_builtin_va_start (valist, nextarg);
6088 static tree
6089 hppa_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p, tree *post_p)
6091 if (TARGET_64BIT)
6093 /* Args grow upward. We can use the generic routines. */
6094 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6096 else /* !TARGET_64BIT */
6098 tree ptr = build_pointer_type (type);
6099 tree valist_type;
6100 tree t, u;
6101 unsigned int size, ofs;
6102 bool indirect;
6104 indirect = pass_by_reference (NULL, TYPE_MODE (type), type, 0);
6105 if (indirect)
6107 type = ptr;
6108 ptr = build_pointer_type (type);
6110 size = int_size_in_bytes (type);
6111 valist_type = TREE_TYPE (valist);
6113 /* Args grow down. Not handled by generic routines. */
6115 u = fold_convert (valist_type, size_in_bytes (type));
6116 t = build (MINUS_EXPR, valist_type, valist, u);
6118 /* Copied from va-pa.h, but we probably don't need to align to
6119 word size, since we generate and preserve that invariant. */
6120 u = build_int_cst (valist_type, (size > 4 ? -8 : -4), -1);
6121 t = build (BIT_AND_EXPR, valist_type, t, u);
6123 t = build (MODIFY_EXPR, valist_type, valist, t);
6125 ofs = (8 - size) % 4;
6126 if (ofs != 0)
6128 u = fold_convert (valist_type, size_int (ofs));
6129 t = build (PLUS_EXPR, valist_type, t, u);
6132 t = fold_convert (ptr, t);
6133 t = build_fold_indirect_ref (t);
6135 if (indirect)
6136 t = build_fold_indirect_ref (t);
6138 return t;
6142 /* This routine handles all the normal conditional branch sequences we
6143 might need to generate. It handles compare immediate vs compare
6144 register, nullification of delay slots, varying length branches,
6145 negated branches, and all combinations of the above. It returns the
6146 output appropriate to emit the branch corresponding to all given
6147 parameters. */
6149 const char *
6150 output_cbranch (rtx *operands, int nullify, int length, int negated, rtx insn)
6152 static char buf[100];
6153 int useskip = 0;
6154 rtx xoperands[5];
6156 /* A conditional branch to the following instruction (eg the delay slot)
6157 is asking for a disaster. This can happen when not optimizing and
6158 when jump optimization fails.
6160 While it is usually safe to emit nothing, this can fail if the
6161 preceding instruction is a nullified branch with an empty delay
6162 slot and the same branch target as this branch. We could check
6163 for this but jump optimization should eliminate nop jumps. It
6164 is always safe to emit a nop. */
6165 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6166 return "nop";
6168 /* The doubleword form of the cmpib instruction doesn't have the LEU
6169 and GTU conditions while the cmpb instruction does. Since we accept
6170 zero for cmpb, we must ensure that we use cmpb for the comparison. */
6171 if (GET_MODE (operands[1]) == DImode && operands[2] == const0_rtx)
6172 operands[2] = gen_rtx_REG (DImode, 0);
6174 /* If this is a long branch with its delay slot unfilled, set `nullify'
6175 as it can nullify the delay slot and save a nop. */
6176 if (length == 8 && dbr_sequence_length () == 0)
6177 nullify = 1;
6179 /* If this is a short forward conditional branch which did not get
6180 its delay slot filled, the delay slot can still be nullified. */
6181 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6182 nullify = forward_branch_p (insn);
6184 /* A forward branch over a single nullified insn can be done with a
6185 comclr instruction. This avoids a single cycle penalty due to
6186 mis-predicted branch if we fall through (branch not taken). */
6187 if (length == 4
6188 && next_real_insn (insn) != 0
6189 && get_attr_length (next_real_insn (insn)) == 4
6190 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6191 && nullify)
6192 useskip = 1;
6194 switch (length)
6196 /* All short conditional branches except backwards with an unfilled
6197 delay slot. */
6198 case 4:
6199 if (useskip)
6200 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6201 else
6202 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6203 if (GET_MODE (operands[1]) == DImode)
6204 strcat (buf, "*");
6205 if (negated)
6206 strcat (buf, "%B3");
6207 else
6208 strcat (buf, "%S3");
6209 if (useskip)
6210 strcat (buf, " %2,%r1,%%r0");
6211 else if (nullify)
6212 strcat (buf, ",n %2,%r1,%0");
6213 else
6214 strcat (buf, " %2,%r1,%0");
6215 break;
6217 /* All long conditionals. Note a short backward branch with an
6218 unfilled delay slot is treated just like a long backward branch
6219 with an unfilled delay slot. */
6220 case 8:
6221 /* Handle weird backwards branch with a filled delay slot
6222 with is nullified. */
6223 if (dbr_sequence_length () != 0
6224 && ! forward_branch_p (insn)
6225 && nullify)
6227 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6228 if (GET_MODE (operands[1]) == DImode)
6229 strcat (buf, "*");
6230 if (negated)
6231 strcat (buf, "%S3");
6232 else
6233 strcat (buf, "%B3");
6234 strcat (buf, ",n %2,%r1,.+12\n\tb %0");
6236 /* Handle short backwards branch with an unfilled delay slot.
6237 Using a comb;nop rather than comiclr;bl saves 1 cycle for both
6238 taken and untaken branches. */
6239 else if (dbr_sequence_length () == 0
6240 && ! forward_branch_p (insn)
6241 && INSN_ADDRESSES_SET_P ()
6242 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6243 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6245 strcpy (buf, "{com%I2b,|cmp%I2b,}");
6246 if (GET_MODE (operands[1]) == DImode)
6247 strcat (buf, "*");
6248 if (negated)
6249 strcat (buf, "%B3 %2,%r1,%0%#");
6250 else
6251 strcat (buf, "%S3 %2,%r1,%0%#");
6253 else
6255 strcpy (buf, "{com%I2clr,|cmp%I2clr,}");
6256 if (GET_MODE (operands[1]) == DImode)
6257 strcat (buf, "*");
6258 if (negated)
6259 strcat (buf, "%S3");
6260 else
6261 strcat (buf, "%B3");
6262 if (nullify)
6263 strcat (buf, " %2,%r1,%%r0\n\tb,n %0");
6264 else
6265 strcat (buf, " %2,%r1,%%r0\n\tb %0");
6267 break;
6269 case 20:
6270 case 28:
6271 xoperands[0] = operands[0];
6272 xoperands[1] = operands[1];
6273 xoperands[2] = operands[2];
6274 xoperands[3] = operands[3];
6276 /* The reversed conditional branch must branch over one additional
6277 instruction if the delay slot is filled. If the delay slot
6278 is empty, the instruction after the reversed condition branch
6279 must be nullified. */
6280 nullify = dbr_sequence_length () == 0;
6281 xoperands[4] = nullify ? GEN_INT (length) : GEN_INT (length + 4);
6283 /* Create a reversed conditional branch which branches around
6284 the following insns. */
6285 if (GET_MODE (operands[1]) != DImode)
6287 if (nullify)
6289 if (negated)
6290 strcpy (buf,
6291 "{com%I2b,%S3,n %2,%r1,.+%4|cmp%I2b,%S3,n %2,%r1,.+%4}");
6292 else
6293 strcpy (buf,
6294 "{com%I2b,%B3,n %2,%r1,.+%4|cmp%I2b,%B3,n %2,%r1,.+%4}");
6296 else
6298 if (negated)
6299 strcpy (buf,
6300 "{com%I2b,%S3 %2,%r1,.+%4|cmp%I2b,%S3 %2,%r1,.+%4}");
6301 else
6302 strcpy (buf,
6303 "{com%I2b,%B3 %2,%r1,.+%4|cmp%I2b,%B3 %2,%r1,.+%4}");
6306 else
6308 if (nullify)
6310 if (negated)
6311 strcpy (buf,
6312 "{com%I2b,*%S3,n %2,%r1,.+%4|cmp%I2b,*%S3,n %2,%r1,.+%4}");
6313 else
6314 strcpy (buf,
6315 "{com%I2b,*%B3,n %2,%r1,.+%4|cmp%I2b,*%B3,n %2,%r1,.+%4}");
6317 else
6319 if (negated)
6320 strcpy (buf,
6321 "{com%I2b,*%S3 %2,%r1,.+%4|cmp%I2b,*%S3 %2,%r1,.+%4}");
6322 else
6323 strcpy (buf,
6324 "{com%I2b,*%B3 %2,%r1,.+%4|cmp%I2b,*%B3 %2,%r1,.+%4}");
6328 output_asm_insn (buf, xoperands);
6329 return output_lbranch (operands[0], insn);
6331 default:
6332 abort ();
6334 return buf;
6337 /* This routine handles long unconditional branches that exceed the
6338 maximum range of a simple branch instruction. */
6340 const char *
6341 output_lbranch (rtx dest, rtx insn)
6343 rtx xoperands[2];
6345 xoperands[0] = dest;
6347 /* First, free up the delay slot. */
6348 if (dbr_sequence_length () != 0)
6350 /* We can't handle a jump in the delay slot. */
6351 if (GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
6352 abort ();
6354 final_scan_insn (NEXT_INSN (insn), asm_out_file,
6355 optimize, 0, 0, NULL);
6357 /* Now delete the delay insn. */
6358 PUT_CODE (NEXT_INSN (insn), NOTE);
6359 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
6360 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
6363 /* Output an insn to save %r1. The runtime documentation doesn't
6364 specify whether the "Clean Up" slot in the callers frame can
6365 be clobbered by the callee. It isn't copied by HP's builtin
6366 alloca, so this suggests that it can be clobbered if necessary.
6367 The "Static Link" location is copied by HP builtin alloca, so
6368 we avoid using it. Using the cleanup slot might be a problem
6369 if we have to interoperate with languages that pass cleanup
6370 information. However, it should be possible to handle these
6371 situations with GCC's asm feature.
6373 The "Current RP" slot is reserved for the called procedure, so
6374 we try to use it when we don't have a frame of our own. It's
6375 rather unlikely that we won't have a frame when we need to emit
6376 a very long branch.
6378 Really the way to go long term is a register scavenger; goto
6379 the target of the jump and find a register which we can use
6380 as a scratch to hold the value in %r1. Then, we wouldn't have
6381 to free up the delay slot or clobber a slot that may be needed
6382 for other purposes. */
6383 if (TARGET_64BIT)
6385 if (actual_fsize == 0 && !regs_ever_live[2])
6386 /* Use the return pointer slot in the frame marker. */
6387 output_asm_insn ("std %%r1,-16(%%r30)", xoperands);
6388 else
6389 /* Use the slot at -40 in the frame marker since HP builtin
6390 alloca doesn't copy it. */
6391 output_asm_insn ("std %%r1,-40(%%r30)", xoperands);
6393 else
6395 if (actual_fsize == 0 && !regs_ever_live[2])
6396 /* Use the return pointer slot in the frame marker. */
6397 output_asm_insn ("stw %%r1,-20(%%r30)", xoperands);
6398 else
6399 /* Use the "Clean Up" slot in the frame marker. In GCC,
6400 the only other use of this location is for copying a
6401 floating point double argument from a floating-point
6402 register to two general registers. The copy is done
6403 as an "atomic" operation when outputting a call, so it
6404 won't interfere with our using the location here. */
6405 output_asm_insn ("stw %%r1,-12(%%r30)", xoperands);
6408 if (TARGET_PORTABLE_RUNTIME)
6410 output_asm_insn ("ldil L'%0,%%r1", xoperands);
6411 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
6412 output_asm_insn ("bv %%r0(%%r1)", xoperands);
6414 else if (flag_pic)
6416 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
6417 if (TARGET_SOM || !TARGET_GAS)
6419 xoperands[1] = gen_label_rtx ();
6420 output_asm_insn ("addil L'%l0-%l1,%%r1", xoperands);
6421 (*targetm.asm_out.internal_label) (asm_out_file, "L",
6422 CODE_LABEL_NUMBER (xoperands[1]));
6423 output_asm_insn ("ldo R'%l0-%l1(%%r1),%%r1", xoperands);
6425 else
6427 output_asm_insn ("addil L'%l0-$PIC_pcrel$0+4,%%r1", xoperands);
6428 output_asm_insn ("ldo R'%l0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
6430 output_asm_insn ("bv %%r0(%%r1)", xoperands);
6432 else
6433 /* Now output a very long branch to the original target. */
6434 output_asm_insn ("ldil L'%l0,%%r1\n\tbe R'%l0(%%sr4,%%r1)", xoperands);
6436 /* Now restore the value of %r1 in the delay slot. */
6437 if (TARGET_64BIT)
6439 if (actual_fsize == 0 && !regs_ever_live[2])
6440 return "ldd -16(%%r30),%%r1";
6441 else
6442 return "ldd -40(%%r30),%%r1";
6444 else
6446 if (actual_fsize == 0 && !regs_ever_live[2])
6447 return "ldw -20(%%r30),%%r1";
6448 else
6449 return "ldw -12(%%r30),%%r1";
6453 /* This routine handles all the branch-on-bit conditional branch sequences we
6454 might need to generate. It handles nullification of delay slots,
6455 varying length branches, negated branches and all combinations of the
6456 above. it returns the appropriate output template to emit the branch. */
6458 const char *
6459 output_bb (rtx *operands ATTRIBUTE_UNUSED, int nullify, int length,
6460 int negated, rtx insn, int which)
6462 static char buf[100];
6463 int useskip = 0;
6465 /* A conditional branch to the following instruction (eg the delay slot) is
6466 asking for a disaster. I do not think this can happen as this pattern
6467 is only used when optimizing; jump optimization should eliminate the
6468 jump. But be prepared just in case. */
6470 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6471 return "nop";
6473 /* If this is a long branch with its delay slot unfilled, set `nullify'
6474 as it can nullify the delay slot and save a nop. */
6475 if (length == 8 && dbr_sequence_length () == 0)
6476 nullify = 1;
6478 /* If this is a short forward conditional branch which did not get
6479 its delay slot filled, the delay slot can still be nullified. */
6480 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6481 nullify = forward_branch_p (insn);
6483 /* A forward branch over a single nullified insn can be done with a
6484 extrs instruction. This avoids a single cycle penalty due to
6485 mis-predicted branch if we fall through (branch not taken). */
6487 if (length == 4
6488 && next_real_insn (insn) != 0
6489 && get_attr_length (next_real_insn (insn)) == 4
6490 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6491 && nullify)
6492 useskip = 1;
6494 switch (length)
6497 /* All short conditional branches except backwards with an unfilled
6498 delay slot. */
6499 case 4:
6500 if (useskip)
6501 strcpy (buf, "{extrs,|extrw,s,}");
6502 else
6503 strcpy (buf, "bb,");
6504 if (useskip && GET_MODE (operands[0]) == DImode)
6505 strcpy (buf, "extrd,s,*");
6506 else if (GET_MODE (operands[0]) == DImode)
6507 strcpy (buf, "bb,*");
6508 if ((which == 0 && negated)
6509 || (which == 1 && ! negated))
6510 strcat (buf, ">=");
6511 else
6512 strcat (buf, "<");
6513 if (useskip)
6514 strcat (buf, " %0,%1,1,%%r0");
6515 else if (nullify && negated)
6516 strcat (buf, ",n %0,%1,%3");
6517 else if (nullify && ! negated)
6518 strcat (buf, ",n %0,%1,%2");
6519 else if (! nullify && negated)
6520 strcat (buf, "%0,%1,%3");
6521 else if (! nullify && ! negated)
6522 strcat (buf, " %0,%1,%2");
6523 break;
6525 /* All long conditionals. Note a short backward branch with an
6526 unfilled delay slot is treated just like a long backward branch
6527 with an unfilled delay slot. */
6528 case 8:
6529 /* Handle weird backwards branch with a filled delay slot
6530 with is nullified. */
6531 if (dbr_sequence_length () != 0
6532 && ! forward_branch_p (insn)
6533 && nullify)
6535 strcpy (buf, "bb,");
6536 if (GET_MODE (operands[0]) == DImode)
6537 strcat (buf, "*");
6538 if ((which == 0 && negated)
6539 || (which == 1 && ! negated))
6540 strcat (buf, "<");
6541 else
6542 strcat (buf, ">=");
6543 if (negated)
6544 strcat (buf, ",n %0,%1,.+12\n\tb %3");
6545 else
6546 strcat (buf, ",n %0,%1,.+12\n\tb %2");
6548 /* Handle short backwards branch with an unfilled delay slot.
6549 Using a bb;nop rather than extrs;bl saves 1 cycle for both
6550 taken and untaken branches. */
6551 else if (dbr_sequence_length () == 0
6552 && ! forward_branch_p (insn)
6553 && INSN_ADDRESSES_SET_P ()
6554 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6555 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6557 strcpy (buf, "bb,");
6558 if (GET_MODE (operands[0]) == DImode)
6559 strcat (buf, "*");
6560 if ((which == 0 && negated)
6561 || (which == 1 && ! negated))
6562 strcat (buf, ">=");
6563 else
6564 strcat (buf, "<");
6565 if (negated)
6566 strcat (buf, " %0,%1,%3%#");
6567 else
6568 strcat (buf, " %0,%1,%2%#");
6570 else
6572 strcpy (buf, "{extrs,|extrw,s,}");
6573 if (GET_MODE (operands[0]) == DImode)
6574 strcpy (buf, "extrd,s,*");
6575 if ((which == 0 && negated)
6576 || (which == 1 && ! negated))
6577 strcat (buf, "<");
6578 else
6579 strcat (buf, ">=");
6580 if (nullify && negated)
6581 strcat (buf, " %0,%1,1,%%r0\n\tb,n %3");
6582 else if (nullify && ! negated)
6583 strcat (buf, " %0,%1,1,%%r0\n\tb,n %2");
6584 else if (negated)
6585 strcat (buf, " %0,%1,1,%%r0\n\tb %3");
6586 else
6587 strcat (buf, " %0,%1,1,%%r0\n\tb %2");
6589 break;
6591 default:
6592 abort ();
6594 return buf;
6597 /* This routine handles all the branch-on-variable-bit conditional branch
6598 sequences we might need to generate. It handles nullification of delay
6599 slots, varying length branches, negated branches and all combinations
6600 of the above. it returns the appropriate output template to emit the
6601 branch. */
6603 const char *
6604 output_bvb (rtx *operands ATTRIBUTE_UNUSED, int nullify, int length,
6605 int negated, rtx insn, int which)
6607 static char buf[100];
6608 int useskip = 0;
6610 /* A conditional branch to the following instruction (eg the delay slot) is
6611 asking for a disaster. I do not think this can happen as this pattern
6612 is only used when optimizing; jump optimization should eliminate the
6613 jump. But be prepared just in case. */
6615 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6616 return "nop";
6618 /* If this is a long branch with its delay slot unfilled, set `nullify'
6619 as it can nullify the delay slot and save a nop. */
6620 if (length == 8 && dbr_sequence_length () == 0)
6621 nullify = 1;
6623 /* If this is a short forward conditional branch which did not get
6624 its delay slot filled, the delay slot can still be nullified. */
6625 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6626 nullify = forward_branch_p (insn);
6628 /* A forward branch over a single nullified insn can be done with a
6629 extrs instruction. This avoids a single cycle penalty due to
6630 mis-predicted branch if we fall through (branch not taken). */
6632 if (length == 4
6633 && next_real_insn (insn) != 0
6634 && get_attr_length (next_real_insn (insn)) == 4
6635 && JUMP_LABEL (insn) == next_nonnote_insn (next_real_insn (insn))
6636 && nullify)
6637 useskip = 1;
6639 switch (length)
6642 /* All short conditional branches except backwards with an unfilled
6643 delay slot. */
6644 case 4:
6645 if (useskip)
6646 strcpy (buf, "{vextrs,|extrw,s,}");
6647 else
6648 strcpy (buf, "{bvb,|bb,}");
6649 if (useskip && GET_MODE (operands[0]) == DImode)
6650 strcpy (buf, "extrd,s,*");
6651 else if (GET_MODE (operands[0]) == DImode)
6652 strcpy (buf, "bb,*");
6653 if ((which == 0 && negated)
6654 || (which == 1 && ! negated))
6655 strcat (buf, ">=");
6656 else
6657 strcat (buf, "<");
6658 if (useskip)
6659 strcat (buf, "{ %0,1,%%r0| %0,%%sar,1,%%r0}");
6660 else if (nullify && negated)
6661 strcat (buf, "{,n %0,%3|,n %0,%%sar,%3}");
6662 else if (nullify && ! negated)
6663 strcat (buf, "{,n %0,%2|,n %0,%%sar,%2}");
6664 else if (! nullify && negated)
6665 strcat (buf, "{%0,%3|%0,%%sar,%3}");
6666 else if (! nullify && ! negated)
6667 strcat (buf, "{ %0,%2| %0,%%sar,%2}");
6668 break;
6670 /* All long conditionals. Note a short backward branch with an
6671 unfilled delay slot is treated just like a long backward branch
6672 with an unfilled delay slot. */
6673 case 8:
6674 /* Handle weird backwards branch with a filled delay slot
6675 with is nullified. */
6676 if (dbr_sequence_length () != 0
6677 && ! forward_branch_p (insn)
6678 && nullify)
6680 strcpy (buf, "{bvb,|bb,}");
6681 if (GET_MODE (operands[0]) == DImode)
6682 strcat (buf, "*");
6683 if ((which == 0 && negated)
6684 || (which == 1 && ! negated))
6685 strcat (buf, "<");
6686 else
6687 strcat (buf, ">=");
6688 if (negated)
6689 strcat (buf, "{,n %0,.+12\n\tb %3|,n %0,%%sar,.+12\n\tb %3}");
6690 else
6691 strcat (buf, "{,n %0,.+12\n\tb %2|,n %0,%%sar,.+12\n\tb %2}");
6693 /* Handle short backwards branch with an unfilled delay slot.
6694 Using a bb;nop rather than extrs;bl saves 1 cycle for both
6695 taken and untaken branches. */
6696 else if (dbr_sequence_length () == 0
6697 && ! forward_branch_p (insn)
6698 && INSN_ADDRESSES_SET_P ()
6699 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6700 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6702 strcpy (buf, "{bvb,|bb,}");
6703 if (GET_MODE (operands[0]) == DImode)
6704 strcat (buf, "*");
6705 if ((which == 0 && negated)
6706 || (which == 1 && ! negated))
6707 strcat (buf, ">=");
6708 else
6709 strcat (buf, "<");
6710 if (negated)
6711 strcat (buf, "{ %0,%3%#| %0,%%sar,%3%#}");
6712 else
6713 strcat (buf, "{ %0,%2%#| %0,%%sar,%2%#}");
6715 else
6717 strcpy (buf, "{vextrs,|extrw,s,}");
6718 if (GET_MODE (operands[0]) == DImode)
6719 strcpy (buf, "extrd,s,*");
6720 if ((which == 0 && negated)
6721 || (which == 1 && ! negated))
6722 strcat (buf, "<");
6723 else
6724 strcat (buf, ">=");
6725 if (nullify && negated)
6726 strcat (buf, "{ %0,1,%%r0\n\tb,n %3| %0,%%sar,1,%%r0\n\tb,n %3}");
6727 else if (nullify && ! negated)
6728 strcat (buf, "{ %0,1,%%r0\n\tb,n %2| %0,%%sar,1,%%r0\n\tb,n %2}");
6729 else if (negated)
6730 strcat (buf, "{ %0,1,%%r0\n\tb %3| %0,%%sar,1,%%r0\n\tb %3}");
6731 else
6732 strcat (buf, "{ %0,1,%%r0\n\tb %2| %0,%%sar,1,%%r0\n\tb %2}");
6734 break;
6736 default:
6737 abort ();
6739 return buf;
6742 /* Return the output template for emitting a dbra type insn.
6744 Note it may perform some output operations on its own before
6745 returning the final output string. */
6746 const char *
6747 output_dbra (rtx *operands, rtx insn, int which_alternative)
6750 /* A conditional branch to the following instruction (eg the delay slot) is
6751 asking for a disaster. Be prepared! */
6753 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6755 if (which_alternative == 0)
6756 return "ldo %1(%0),%0";
6757 else if (which_alternative == 1)
6759 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)", operands);
6760 output_asm_insn ("ldw -16(%%r30),%4", operands);
6761 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
6762 return "{fldws|fldw} -16(%%r30),%0";
6764 else
6766 output_asm_insn ("ldw %0,%4", operands);
6767 return "ldo %1(%4),%4\n\tstw %4,%0";
6771 if (which_alternative == 0)
6773 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6774 int length = get_attr_length (insn);
6776 /* If this is a long branch with its delay slot unfilled, set `nullify'
6777 as it can nullify the delay slot and save a nop. */
6778 if (length == 8 && dbr_sequence_length () == 0)
6779 nullify = 1;
6781 /* If this is a short forward conditional branch which did not get
6782 its delay slot filled, the delay slot can still be nullified. */
6783 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6784 nullify = forward_branch_p (insn);
6786 /* Handle short versions first. */
6787 if (length == 4 && nullify)
6788 return "addib,%C2,n %1,%0,%3";
6789 else if (length == 4 && ! nullify)
6790 return "addib,%C2 %1,%0,%3";
6791 else if (length == 8)
6793 /* Handle weird backwards branch with a fulled delay slot
6794 which is nullified. */
6795 if (dbr_sequence_length () != 0
6796 && ! forward_branch_p (insn)
6797 && nullify)
6798 return "addib,%N2,n %1,%0,.+12\n\tb %3";
6799 /* Handle short backwards branch with an unfilled delay slot.
6800 Using a addb;nop rather than addi;bl saves 1 cycle for both
6801 taken and untaken branches. */
6802 else if (dbr_sequence_length () == 0
6803 && ! forward_branch_p (insn)
6804 && INSN_ADDRESSES_SET_P ()
6805 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6806 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6807 return "addib,%C2 %1,%0,%3%#";
6809 /* Handle normal cases. */
6810 if (nullify)
6811 return "addi,%N2 %1,%0,%0\n\tb,n %3";
6812 else
6813 return "addi,%N2 %1,%0,%0\n\tb %3";
6815 else
6816 abort ();
6818 /* Deal with gross reload from FP register case. */
6819 else if (which_alternative == 1)
6821 /* Move loop counter from FP register to MEM then into a GR,
6822 increment the GR, store the GR into MEM, and finally reload
6823 the FP register from MEM from within the branch's delay slot. */
6824 output_asm_insn ("{fstws|fstw} %0,-16(%%r30)\n\tldw -16(%%r30),%4",
6825 operands);
6826 output_asm_insn ("ldo %1(%4),%4\n\tstw %4,-16(%%r30)", operands);
6827 if (get_attr_length (insn) == 24)
6828 return "{comb|cmpb},%S2 %%r0,%4,%3\n\t{fldws|fldw} -16(%%r30),%0";
6829 else
6830 return "{comclr|cmpclr},%B2 %%r0,%4,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
6832 /* Deal with gross reload from memory case. */
6833 else
6835 /* Reload loop counter from memory, the store back to memory
6836 happens in the branch's delay slot. */
6837 output_asm_insn ("ldw %0,%4", operands);
6838 if (get_attr_length (insn) == 12)
6839 return "addib,%C2 %1,%4,%3\n\tstw %4,%0";
6840 else
6841 return "addi,%N2 %1,%4,%4\n\tb %3\n\tstw %4,%0";
6845 /* Return the output template for emitting a dbra type insn.
6847 Note it may perform some output operations on its own before
6848 returning the final output string. */
6849 const char *
6850 output_movb (rtx *operands, rtx insn, int which_alternative,
6851 int reverse_comparison)
6854 /* A conditional branch to the following instruction (eg the delay slot) is
6855 asking for a disaster. Be prepared! */
6857 if (next_real_insn (JUMP_LABEL (insn)) == next_real_insn (insn))
6859 if (which_alternative == 0)
6860 return "copy %1,%0";
6861 else if (which_alternative == 1)
6863 output_asm_insn ("stw %1,-16(%%r30)", operands);
6864 return "{fldws|fldw} -16(%%r30),%0";
6866 else if (which_alternative == 2)
6867 return "stw %1,%0";
6868 else
6869 return "mtsar %r1";
6872 /* Support the second variant. */
6873 if (reverse_comparison)
6874 PUT_CODE (operands[2], reverse_condition (GET_CODE (operands[2])));
6876 if (which_alternative == 0)
6878 int nullify = INSN_ANNULLED_BRANCH_P (insn);
6879 int length = get_attr_length (insn);
6881 /* If this is a long branch with its delay slot unfilled, set `nullify'
6882 as it can nullify the delay slot and save a nop. */
6883 if (length == 8 && dbr_sequence_length () == 0)
6884 nullify = 1;
6886 /* If this is a short forward conditional branch which did not get
6887 its delay slot filled, the delay slot can still be nullified. */
6888 if (! nullify && length == 4 && dbr_sequence_length () == 0)
6889 nullify = forward_branch_p (insn);
6891 /* Handle short versions first. */
6892 if (length == 4 && nullify)
6893 return "movb,%C2,n %1,%0,%3";
6894 else if (length == 4 && ! nullify)
6895 return "movb,%C2 %1,%0,%3";
6896 else if (length == 8)
6898 /* Handle weird backwards branch with a filled delay slot
6899 which is nullified. */
6900 if (dbr_sequence_length () != 0
6901 && ! forward_branch_p (insn)
6902 && nullify)
6903 return "movb,%N2,n %1,%0,.+12\n\tb %3";
6905 /* Handle short backwards branch with an unfilled delay slot.
6906 Using a movb;nop rather than or;bl saves 1 cycle for both
6907 taken and untaken branches. */
6908 else if (dbr_sequence_length () == 0
6909 && ! forward_branch_p (insn)
6910 && INSN_ADDRESSES_SET_P ()
6911 && VAL_14_BITS_P (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (insn)))
6912 - INSN_ADDRESSES (INSN_UID (insn)) - 8))
6913 return "movb,%C2 %1,%0,%3%#";
6914 /* Handle normal cases. */
6915 if (nullify)
6916 return "or,%N2 %1,%%r0,%0\n\tb,n %3";
6917 else
6918 return "or,%N2 %1,%%r0,%0\n\tb %3";
6920 else
6921 abort ();
6923 /* Deal with gross reload from FP register case. */
6924 else if (which_alternative == 1)
6926 /* Move loop counter from FP register to MEM then into a GR,
6927 increment the GR, store the GR into MEM, and finally reload
6928 the FP register from MEM from within the branch's delay slot. */
6929 output_asm_insn ("stw %1,-16(%%r30)", operands);
6930 if (get_attr_length (insn) == 12)
6931 return "{comb|cmpb},%S2 %%r0,%1,%3\n\t{fldws|fldw} -16(%%r30),%0";
6932 else
6933 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\t{fldws|fldw} -16(%%r30),%0";
6935 /* Deal with gross reload from memory case. */
6936 else if (which_alternative == 2)
6938 /* Reload loop counter from memory, the store back to memory
6939 happens in the branch's delay slot. */
6940 if (get_attr_length (insn) == 8)
6941 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tstw %1,%0";
6942 else
6943 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tstw %1,%0";
6945 /* Handle SAR as a destination. */
6946 else
6948 if (get_attr_length (insn) == 8)
6949 return "{comb|cmpb},%S2 %%r0,%1,%3\n\tmtsar %r1";
6950 else
6951 return "{comclr|cmpclr},%B2 %%r0,%1,%%r0\n\tb %3\n\tmtsar %r1";
6955 /* Copy any FP arguments in INSN into integer registers. */
6956 static void
6957 copy_fp_args (rtx insn)
6959 rtx link;
6960 rtx xoperands[2];
6962 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
6964 int arg_mode, regno;
6965 rtx use = XEXP (link, 0);
6967 if (! (GET_CODE (use) == USE
6968 && GET_CODE (XEXP (use, 0)) == REG
6969 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
6970 continue;
6972 arg_mode = GET_MODE (XEXP (use, 0));
6973 regno = REGNO (XEXP (use, 0));
6975 /* Is it a floating point register? */
6976 if (regno >= 32 && regno <= 39)
6978 /* Copy the FP register into an integer register via memory. */
6979 if (arg_mode == SFmode)
6981 xoperands[0] = XEXP (use, 0);
6982 xoperands[1] = gen_rtx_REG (SImode, 26 - (regno - 32) / 2);
6983 output_asm_insn ("{fstws|fstw} %0,-16(%%sr0,%%r30)", xoperands);
6984 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
6986 else
6988 xoperands[0] = XEXP (use, 0);
6989 xoperands[1] = gen_rtx_REG (DImode, 25 - (regno - 34) / 2);
6990 output_asm_insn ("{fstds|fstd} %0,-16(%%sr0,%%r30)", xoperands);
6991 output_asm_insn ("ldw -12(%%sr0,%%r30),%R1", xoperands);
6992 output_asm_insn ("ldw -16(%%sr0,%%r30),%1", xoperands);
6998 /* Compute length of the FP argument copy sequence for INSN. */
6999 static int
7000 length_fp_args (rtx insn)
7002 int length = 0;
7003 rtx link;
7005 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
7007 int arg_mode, regno;
7008 rtx use = XEXP (link, 0);
7010 if (! (GET_CODE (use) == USE
7011 && GET_CODE (XEXP (use, 0)) == REG
7012 && FUNCTION_ARG_REGNO_P (REGNO (XEXP (use, 0)))))
7013 continue;
7015 arg_mode = GET_MODE (XEXP (use, 0));
7016 regno = REGNO (XEXP (use, 0));
7018 /* Is it a floating point register? */
7019 if (regno >= 32 && regno <= 39)
7021 if (arg_mode == SFmode)
7022 length += 8;
7023 else
7024 length += 12;
7028 return length;
7031 /* Return the attribute length for the millicode call instruction INSN.
7032 The length must match the code generated by output_millicode_call.
7033 We include the delay slot in the returned length as it is better to
7034 over estimate the length than to under estimate it. */
7037 attr_length_millicode_call (rtx insn)
7039 unsigned long distance = -1;
7040 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7042 if (INSN_ADDRESSES_SET_P ())
7044 distance = (total + insn_current_reference_address (insn));
7045 if (distance < total)
7046 distance = -1;
7049 if (TARGET_64BIT)
7051 if (!TARGET_LONG_CALLS && distance < 7600000)
7052 return 8;
7054 return 20;
7056 else if (TARGET_PORTABLE_RUNTIME)
7057 return 24;
7058 else
7060 if (!TARGET_LONG_CALLS && distance < 240000)
7061 return 8;
7063 if (TARGET_LONG_ABS_CALL && !flag_pic)
7064 return 12;
7066 return 24;
7070 /* INSN is a function call. It may have an unconditional jump
7071 in its delay slot.
7073 CALL_DEST is the routine we are calling. */
7075 const char *
7076 output_millicode_call (rtx insn, rtx call_dest)
7078 int attr_length = get_attr_length (insn);
7079 int seq_length = dbr_sequence_length ();
7080 int distance;
7081 rtx seq_insn;
7082 rtx xoperands[3];
7084 xoperands[0] = call_dest;
7085 xoperands[2] = gen_rtx_REG (Pmode, TARGET_64BIT ? 2 : 31);
7087 /* Handle the common case where we are sure that the branch will
7088 reach the beginning of the $CODE$ subspace. The within reach
7089 form of the $$sh_func_adrs call has a length of 28. Because
7090 it has an attribute type of multi, it never has a nonzero
7091 sequence length. The length of the $$sh_func_adrs is the same
7092 as certain out of reach PIC calls to other routines. */
7093 if (!TARGET_LONG_CALLS
7094 && ((seq_length == 0
7095 && (attr_length == 12
7096 || (attr_length == 28 && get_attr_type (insn) == TYPE_MULTI)))
7097 || (seq_length != 0 && attr_length == 8)))
7099 output_asm_insn ("{bl|b,l} %0,%2", xoperands);
7101 else
7103 if (TARGET_64BIT)
7105 /* It might seem that one insn could be saved by accessing
7106 the millicode function using the linkage table. However,
7107 this doesn't work in shared libraries and other dynamically
7108 loaded objects. Using a pc-relative sequence also avoids
7109 problems related to the implicit use of the gp register. */
7110 output_asm_insn ("b,l .+8,%%r1", xoperands);
7112 if (TARGET_GAS)
7114 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
7115 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
7117 else
7119 xoperands[1] = gen_label_rtx ();
7120 output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7121 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7122 CODE_LABEL_NUMBER (xoperands[1]));
7123 output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7126 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7128 else if (TARGET_PORTABLE_RUNTIME)
7130 /* Pure portable runtime doesn't allow be/ble; we also don't
7131 have PIC support in the assembler/linker, so this sequence
7132 is needed. */
7134 /* Get the address of our target into %r1. */
7135 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7136 output_asm_insn ("ldo R'%0(%%r1),%%r1", xoperands);
7138 /* Get our return address into %r31. */
7139 output_asm_insn ("{bl|b,l} .+8,%%r31", xoperands);
7140 output_asm_insn ("addi 8,%%r31,%%r31", xoperands);
7142 /* Jump to our target address in %r1. */
7143 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7145 else if (!flag_pic)
7147 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7148 if (TARGET_PA_20)
7149 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31", xoperands);
7150 else
7151 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
7153 else
7155 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7156 output_asm_insn ("addi 16,%%r1,%%r31", xoperands);
7158 if (TARGET_SOM || !TARGET_GAS)
7160 /* The HP assembler can generate relocations for the
7161 difference of two symbols. GAS can do this for a
7162 millicode symbol but not an arbitrary external
7163 symbol when generating SOM output. */
7164 xoperands[1] = gen_label_rtx ();
7165 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7166 CODE_LABEL_NUMBER (xoperands[1]));
7167 output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7168 output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7170 else
7172 output_asm_insn ("addil L'%0-$PIC_pcrel$0+8,%%r1", xoperands);
7173 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+12(%%r1),%%r1",
7174 xoperands);
7177 /* Jump to our target address in %r1. */
7178 output_asm_insn ("bv %%r0(%%r1)", xoperands);
7182 if (seq_length == 0)
7183 output_asm_insn ("nop", xoperands);
7185 /* We are done if there isn't a jump in the delay slot. */
7186 if (seq_length == 0 || GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
7187 return "";
7189 /* This call has an unconditional jump in its delay slot. */
7190 xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
7192 /* See if the return address can be adjusted. Use the containing
7193 sequence insn's address. */
7194 if (INSN_ADDRESSES_SET_P ())
7196 seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
7197 distance = (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
7198 - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8);
7200 if (VAL_14_BITS_P (distance))
7202 xoperands[1] = gen_label_rtx ();
7203 output_asm_insn ("ldo %0-%1(%2),%2", xoperands);
7204 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7205 CODE_LABEL_NUMBER (xoperands[1]));
7207 else
7208 /* ??? This branch may not reach its target. */
7209 output_asm_insn ("nop\n\tb,n %0", xoperands);
7211 else
7212 /* ??? This branch may not reach its target. */
7213 output_asm_insn ("nop\n\tb,n %0", xoperands);
7215 /* Delete the jump. */
7216 PUT_CODE (NEXT_INSN (insn), NOTE);
7217 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7218 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7220 return "";
7223 /* Return the attribute length of the call instruction INSN. The SIBCALL
7224 flag indicates whether INSN is a regular call or a sibling call. The
7225 length returned must be longer than the code actually generated by
7226 output_call. Since branch shortening is done before delay branch
7227 sequencing, there is no way to determine whether or not the delay
7228 slot will be filled during branch shortening. Even when the delay
7229 slot is filled, we may have to add a nop if the delay slot contains
7230 a branch that can't reach its target. Thus, we always have to include
7231 the delay slot in the length estimate. This used to be done in
7232 pa_adjust_insn_length but we do it here now as some sequences always
7233 fill the delay slot and we can save four bytes in the estimate for
7234 these sequences. */
7237 attr_length_call (rtx insn, int sibcall)
7239 int local_call;
7240 rtx call_dest;
7241 tree call_decl;
7242 int length = 0;
7243 rtx pat = PATTERN (insn);
7244 unsigned long distance = -1;
7246 if (INSN_ADDRESSES_SET_P ())
7248 unsigned long total;
7250 total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7251 distance = (total + insn_current_reference_address (insn));
7252 if (distance < total)
7253 distance = -1;
7256 /* Determine if this is a local call. */
7257 if (GET_CODE (XVECEXP (pat, 0, 0)) == CALL)
7258 call_dest = XEXP (XEXP (XVECEXP (pat, 0, 0), 0), 0);
7259 else
7260 call_dest = XEXP (XEXP (XEXP (XVECEXP (pat, 0, 0), 1), 0), 0);
7262 call_decl = SYMBOL_REF_DECL (call_dest);
7263 local_call = call_decl && (*targetm.binds_local_p) (call_decl);
7265 /* pc-relative branch. */
7266 if (!TARGET_LONG_CALLS
7267 && ((TARGET_PA_20 && !sibcall && distance < 7600000)
7268 || distance < 240000))
7269 length += 8;
7271 /* 64-bit plabel sequence. */
7272 else if (TARGET_64BIT && !local_call)
7273 length += sibcall ? 28 : 24;
7275 /* non-pic long absolute branch sequence. */
7276 else if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7277 length += 12;
7279 /* long pc-relative branch sequence. */
7280 else if ((TARGET_SOM && TARGET_LONG_PIC_SDIFF_CALL)
7281 || (TARGET_64BIT && !TARGET_GAS)
7282 || (TARGET_GAS && (TARGET_LONG_PIC_PCREL_CALL || local_call)))
7284 length += 20;
7286 if (!TARGET_PA_20 && !TARGET_NO_SPACE_REGS)
7287 length += 8;
7290 /* 32-bit plabel sequence. */
7291 else
7293 length += 32;
7295 if (TARGET_SOM)
7296 length += length_fp_args (insn);
7298 if (flag_pic)
7299 length += 4;
7301 if (!TARGET_PA_20)
7303 if (!sibcall)
7304 length += 8;
7306 if (!TARGET_NO_SPACE_REGS)
7307 length += 8;
7311 return length;
7314 /* INSN is a function call. It may have an unconditional jump
7315 in its delay slot.
7317 CALL_DEST is the routine we are calling. */
7319 const char *
7320 output_call (rtx insn, rtx call_dest, int sibcall)
7322 int delay_insn_deleted = 0;
7323 int delay_slot_filled = 0;
7324 int seq_length = dbr_sequence_length ();
7325 tree call_decl = SYMBOL_REF_DECL (call_dest);
7326 int local_call = call_decl && (*targetm.binds_local_p) (call_decl);
7327 rtx xoperands[2];
7329 xoperands[0] = call_dest;
7331 /* Handle the common case where we're sure that the branch will reach
7332 the beginning of the "$CODE$" subspace. This is the beginning of
7333 the current function if we are in a named section. */
7334 if (!TARGET_LONG_CALLS && attr_length_call (insn, sibcall) == 8)
7336 xoperands[1] = gen_rtx_REG (word_mode, sibcall ? 0 : 2);
7337 output_asm_insn ("{bl|b,l} %0,%1", xoperands);
7339 else
7341 if (TARGET_64BIT && !local_call)
7343 /* ??? As far as I can tell, the HP linker doesn't support the
7344 long pc-relative sequence described in the 64-bit runtime
7345 architecture. So, we use a slightly longer indirect call. */
7346 struct deferred_plabel *p = get_plabel (XSTR (call_dest, 0));
7348 xoperands[0] = p->internal_label;
7349 xoperands[1] = gen_label_rtx ();
7351 /* If this isn't a sibcall, we put the load of %r27 into the
7352 delay slot. We can't do this in a sibcall as we don't
7353 have a second call-clobbered scratch register available. */
7354 if (seq_length != 0
7355 && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
7356 && !sibcall)
7358 final_scan_insn (NEXT_INSN (insn), asm_out_file,
7359 optimize, 0, 0, NULL);
7361 /* Now delete the delay insn. */
7362 PUT_CODE (NEXT_INSN (insn), NOTE);
7363 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7364 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7365 delay_insn_deleted = 1;
7368 output_asm_insn ("addil LT'%0,%%r27", xoperands);
7369 output_asm_insn ("ldd RT'%0(%%r1),%%r1", xoperands);
7370 output_asm_insn ("ldd 0(%%r1),%%r1", xoperands);
7372 if (sibcall)
7374 output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7375 output_asm_insn ("ldd 16(%%r1),%%r1", xoperands);
7376 output_asm_insn ("bve (%%r1)", xoperands);
7378 else
7380 output_asm_insn ("ldd 16(%%r1),%%r2", xoperands);
7381 output_asm_insn ("bve,l (%%r2),%%r2", xoperands);
7382 output_asm_insn ("ldd 24(%%r1),%%r27", xoperands);
7383 delay_slot_filled = 1;
7386 else
7388 int indirect_call = 0;
7390 /* Emit a long call. There are several different sequences
7391 of increasing length and complexity. In most cases,
7392 they don't allow an instruction in the delay slot. */
7393 if (!((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7394 && !(TARGET_SOM && TARGET_LONG_PIC_SDIFF_CALL)
7395 && !(TARGET_GAS && (TARGET_LONG_PIC_PCREL_CALL || local_call))
7396 && !TARGET_64BIT)
7397 indirect_call = 1;
7399 if (seq_length != 0
7400 && GET_CODE (NEXT_INSN (insn)) != JUMP_INSN
7401 && !sibcall
7402 && (!TARGET_PA_20 || indirect_call))
7404 /* A non-jump insn in the delay slot. By definition we can
7405 emit this insn before the call (and in fact before argument
7406 relocating. */
7407 final_scan_insn (NEXT_INSN (insn), asm_out_file, optimize, 0, 0,
7408 NULL);
7410 /* Now delete the delay insn. */
7411 PUT_CODE (NEXT_INSN (insn), NOTE);
7412 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7413 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7414 delay_insn_deleted = 1;
7417 if ((TARGET_LONG_ABS_CALL || local_call) && !flag_pic)
7419 /* This is the best sequence for making long calls in
7420 non-pic code. Unfortunately, GNU ld doesn't provide
7421 the stub needed for external calls, and GAS's support
7422 for this with the SOM linker is buggy. It is safe
7423 to use this for local calls. */
7424 output_asm_insn ("ldil L'%0,%%r1", xoperands);
7425 if (sibcall)
7426 output_asm_insn ("be R'%0(%%sr4,%%r1)", xoperands);
7427 else
7429 if (TARGET_PA_20)
7430 output_asm_insn ("be,l R'%0(%%sr4,%%r1),%%sr0,%%r31",
7431 xoperands);
7432 else
7433 output_asm_insn ("ble R'%0(%%sr4,%%r1)", xoperands);
7435 output_asm_insn ("copy %%r31,%%r2", xoperands);
7436 delay_slot_filled = 1;
7439 else
7441 if ((TARGET_SOM && TARGET_LONG_PIC_SDIFF_CALL)
7442 || (TARGET_64BIT && !TARGET_GAS))
7444 /* The HP assembler and linker can handle relocations
7445 for the difference of two symbols. GAS and the HP
7446 linker can't do this when one of the symbols is
7447 external. */
7448 xoperands[1] = gen_label_rtx ();
7449 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7450 output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
7451 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7452 CODE_LABEL_NUMBER (xoperands[1]));
7453 output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
7455 else if (TARGET_GAS && (TARGET_LONG_PIC_PCREL_CALL || local_call))
7457 /* GAS currently can't generate the relocations that
7458 are needed for the SOM linker under HP-UX using this
7459 sequence. The GNU linker doesn't generate the stubs
7460 that are needed for external calls on TARGET_ELF32
7461 with this sequence. For now, we have to use a
7462 longer plabel sequence when using GAS. */
7463 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7464 output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1",
7465 xoperands);
7466 output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1",
7467 xoperands);
7469 else
7471 /* Emit a long plabel-based call sequence. This is
7472 essentially an inline implementation of $$dyncall.
7473 We don't actually try to call $$dyncall as this is
7474 as difficult as calling the function itself. */
7475 struct deferred_plabel *p = get_plabel (XSTR (call_dest, 0));
7477 xoperands[0] = p->internal_label;
7478 xoperands[1] = gen_label_rtx ();
7480 /* Since the call is indirect, FP arguments in registers
7481 need to be copied to the general registers. Then, the
7482 argument relocation stub will copy them back. */
7483 if (TARGET_SOM)
7484 copy_fp_args (insn);
7486 if (flag_pic)
7488 output_asm_insn ("addil LT'%0,%%r19", xoperands);
7489 output_asm_insn ("ldw RT'%0(%%r1),%%r1", xoperands);
7490 output_asm_insn ("ldw 0(%%r1),%%r1", xoperands);
7492 else
7494 output_asm_insn ("addil LR'%0-$global$,%%r27",
7495 xoperands);
7496 output_asm_insn ("ldw RR'%0-$global$(%%r1),%%r1",
7497 xoperands);
7500 output_asm_insn ("bb,>=,n %%r1,30,.+16", xoperands);
7501 output_asm_insn ("depi 0,31,2,%%r1", xoperands);
7502 output_asm_insn ("ldw 4(%%sr0,%%r1),%%r19", xoperands);
7503 output_asm_insn ("ldw 0(%%sr0,%%r1),%%r1", xoperands);
7505 if (!sibcall && !TARGET_PA_20)
7507 output_asm_insn ("{bl|b,l} .+8,%%r2", xoperands);
7508 if (TARGET_NO_SPACE_REGS)
7509 output_asm_insn ("addi 8,%%r2,%%r2", xoperands);
7510 else
7511 output_asm_insn ("addi 16,%%r2,%%r2", xoperands);
7515 if (TARGET_PA_20)
7517 if (sibcall)
7518 output_asm_insn ("bve (%%r1)", xoperands);
7519 else
7521 if (indirect_call)
7523 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7524 output_asm_insn ("stw %%r2,-24(%%sp)", xoperands);
7525 delay_slot_filled = 1;
7527 else
7528 output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
7531 else
7533 if (!TARGET_NO_SPACE_REGS)
7534 output_asm_insn ("ldsid (%%r1),%%r31\n\tmtsp %%r31,%%sr0",
7535 xoperands);
7537 if (sibcall)
7539 if (TARGET_NO_SPACE_REGS)
7540 output_asm_insn ("be 0(%%sr4,%%r1)", xoperands);
7541 else
7542 output_asm_insn ("be 0(%%sr0,%%r1)", xoperands);
7544 else
7546 if (TARGET_NO_SPACE_REGS)
7547 output_asm_insn ("ble 0(%%sr4,%%r1)", xoperands);
7548 else
7549 output_asm_insn ("ble 0(%%sr0,%%r1)", xoperands);
7551 if (indirect_call)
7552 output_asm_insn ("stw %%r31,-24(%%sp)", xoperands);
7553 else
7554 output_asm_insn ("copy %%r31,%%r2", xoperands);
7555 delay_slot_filled = 1;
7562 if (!delay_slot_filled && (seq_length == 0 || delay_insn_deleted))
7563 output_asm_insn ("nop", xoperands);
7565 /* We are done if there isn't a jump in the delay slot. */
7566 if (seq_length == 0
7567 || delay_insn_deleted
7568 || GET_CODE (NEXT_INSN (insn)) != JUMP_INSN)
7569 return "";
7571 /* A sibcall should never have a branch in the delay slot. */
7572 if (sibcall)
7573 abort ();
7575 /* This call has an unconditional jump in its delay slot. */
7576 xoperands[0] = XEXP (PATTERN (NEXT_INSN (insn)), 1);
7578 if (!delay_slot_filled && INSN_ADDRESSES_SET_P ())
7580 /* See if the return address can be adjusted. Use the containing
7581 sequence insn's address. */
7582 rtx seq_insn = NEXT_INSN (PREV_INSN (XVECEXP (final_sequence, 0, 0)));
7583 int distance = (INSN_ADDRESSES (INSN_UID (JUMP_LABEL (NEXT_INSN (insn))))
7584 - INSN_ADDRESSES (INSN_UID (seq_insn)) - 8);
7586 if (VAL_14_BITS_P (distance))
7588 xoperands[1] = gen_label_rtx ();
7589 output_asm_insn ("ldo %0-%1(%%r2),%%r2", xoperands);
7590 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7591 CODE_LABEL_NUMBER (xoperands[1]));
7593 else
7594 output_asm_insn ("nop\n\tb,n %0", xoperands);
7596 else
7597 output_asm_insn ("b,n %0", xoperands);
7599 /* Delete the jump. */
7600 PUT_CODE (NEXT_INSN (insn), NOTE);
7601 NOTE_LINE_NUMBER (NEXT_INSN (insn)) = NOTE_INSN_DELETED;
7602 NOTE_SOURCE_FILE (NEXT_INSN (insn)) = 0;
7604 return "";
7607 /* Return the attribute length of the indirect call instruction INSN.
7608 The length must match the code generated by output_indirect call.
7609 The returned length includes the delay slot. Currently, the delay
7610 slot of an indirect call sequence is not exposed and it is used by
7611 the sequence itself. */
7614 attr_length_indirect_call (rtx insn)
7616 unsigned long distance = -1;
7617 unsigned long total = IN_NAMED_SECTION_P (cfun->decl) ? 0 : total_code_bytes;
7619 if (INSN_ADDRESSES_SET_P ())
7621 distance = (total + insn_current_reference_address (insn));
7622 if (distance < total)
7623 distance = -1;
7626 if (TARGET_64BIT)
7627 return 12;
7629 if (TARGET_FAST_INDIRECT_CALLS
7630 || (!TARGET_PORTABLE_RUNTIME
7631 && ((TARGET_PA_20 && distance < 7600000) || distance < 240000)))
7632 return 8;
7634 if (flag_pic)
7635 return 24;
7637 if (TARGET_PORTABLE_RUNTIME)
7638 return 20;
7640 /* Out of reach, can use ble. */
7641 return 12;
7644 const char *
7645 output_indirect_call (rtx insn, rtx call_dest)
7647 rtx xoperands[1];
7649 if (TARGET_64BIT)
7651 xoperands[0] = call_dest;
7652 output_asm_insn ("ldd 16(%0),%%r2", xoperands);
7653 output_asm_insn ("bve,l (%%r2),%%r2\n\tldd 24(%0),%%r27", xoperands);
7654 return "";
7657 /* First the special case for kernels, level 0 systems, etc. */
7658 if (TARGET_FAST_INDIRECT_CALLS)
7659 return "ble 0(%%sr4,%%r22)\n\tcopy %%r31,%%r2";
7661 /* Now the normal case -- we can reach $$dyncall directly or
7662 we're sure that we can get there via a long-branch stub.
7664 No need to check target flags as the length uniquely identifies
7665 the remaining cases. */
7666 if (attr_length_indirect_call (insn) == 8)
7668 /* The HP linker substitutes a BLE for millicode calls using
7669 the short PIC PCREL form. Thus, we must use %r31 as the
7670 link register when generating PA 1.x code. */
7671 if (TARGET_PA_20)
7672 return ".CALL\tARGW0=GR\n\tb,l $$dyncall,%%r2\n\tcopy %%r2,%%r31";
7673 else
7674 return ".CALL\tARGW0=GR\n\tbl $$dyncall,%%r31\n\tcopy %%r31,%%r2";
7677 /* Long millicode call, but we are not generating PIC or portable runtime
7678 code. */
7679 if (attr_length_indirect_call (insn) == 12)
7680 return ".CALL\tARGW0=GR\n\tldil L'$$dyncall,%%r2\n\tble R'$$dyncall(%%sr4,%%r2)\n\tcopy %%r31,%%r2";
7682 /* Long millicode call for portable runtime. */
7683 if (attr_length_indirect_call (insn) == 20)
7684 return "ldil L'$$dyncall,%%r31\n\tldo R'$$dyncall(%%r31),%%r31\n\tblr %%r0,%%r2\n\tbv,n %%r0(%%r31)\n\tnop";
7686 /* We need a long PIC call to $$dyncall. */
7687 xoperands[0] = NULL_RTX;
7688 output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
7689 if (TARGET_SOM || !TARGET_GAS)
7691 xoperands[0] = gen_label_rtx ();
7692 output_asm_insn ("addil L'$$dyncall-%0,%%r1", xoperands);
7693 (*targetm.asm_out.internal_label) (asm_out_file, "L",
7694 CODE_LABEL_NUMBER (xoperands[0]));
7695 output_asm_insn ("ldo R'$$dyncall-%0(%%r1),%%r1", xoperands);
7697 else
7699 output_asm_insn ("addil L'$$dyncall-$PIC_pcrel$0+4,%%r1", xoperands);
7700 output_asm_insn ("ldo R'$$dyncall-$PIC_pcrel$0+8(%%r1),%%r1",
7701 xoperands);
7703 output_asm_insn ("blr %%r0,%%r2", xoperands);
7704 output_asm_insn ("bv,n %%r0(%%r1)\n\tnop", xoperands);
7705 return "";
7708 /* Return the total length of the save and restore instructions needed for
7709 the data linkage table pointer (i.e., the PIC register) across the call
7710 instruction INSN. No-return calls do not require a save and restore.
7711 In addition, we may be able to avoid the save and restore for calls
7712 within the same translation unit. */
7715 attr_length_save_restore_dltp (rtx insn)
7717 if (find_reg_note (insn, REG_NORETURN, NULL_RTX))
7718 return 0;
7720 return 8;
7723 /* In HPUX 8.0's shared library scheme, special relocations are needed
7724 for function labels if they might be passed to a function
7725 in a shared library (because shared libraries don't live in code
7726 space), and special magic is needed to construct their address. */
7728 void
7729 hppa_encode_label (rtx sym)
7731 const char *str = XSTR (sym, 0);
7732 int len = strlen (str) + 1;
7733 char *newstr, *p;
7735 p = newstr = alloca (len + 1);
7736 *p++ = '@';
7737 strcpy (p, str);
7739 XSTR (sym, 0) = ggc_alloc_string (newstr, len);
7742 static void
7743 pa_encode_section_info (tree decl, rtx rtl, int first)
7745 if (first && TEXT_SPACE_P (decl))
7747 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
7748 if (TREE_CODE (decl) == FUNCTION_DECL)
7749 hppa_encode_label (XEXP (rtl, 0));
7753 /* This is sort of inverse to pa_encode_section_info. */
7755 static const char *
7756 pa_strip_name_encoding (const char *str)
7758 str += (*str == '@');
7759 str += (*str == '*');
7760 return str;
7764 function_label_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
7766 return GET_CODE (op) == SYMBOL_REF && FUNCTION_NAME_P (XSTR (op, 0));
7769 /* Returns 1 if OP is a function label involved in a simple addition
7770 with a constant. Used to keep certain patterns from matching
7771 during instruction combination. */
7773 is_function_label_plus_const (rtx op)
7775 /* Strip off any CONST. */
7776 if (GET_CODE (op) == CONST)
7777 op = XEXP (op, 0);
7779 return (GET_CODE (op) == PLUS
7780 && function_label_operand (XEXP (op, 0), Pmode)
7781 && GET_CODE (XEXP (op, 1)) == CONST_INT);
7784 /* Output assembly code for a thunk to FUNCTION. */
7786 static void
7787 pa_asm_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
7788 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
7789 tree function)
7791 const char *fname = XSTR (XEXP (DECL_RTL (function), 0), 0);
7792 const char *tname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
7793 int val_14 = VAL_14_BITS_P (delta);
7794 int nbytes = 0;
7795 static unsigned int current_thunk_number;
7796 char label[16];
7798 ASM_OUTPUT_LABEL (file, tname);
7799 fprintf (file, "\t.PROC\n\t.CALLINFO FRAME=0,NO_CALLS\n\t.ENTRY\n");
7801 fname = (*targetm.strip_name_encoding) (fname);
7802 tname = (*targetm.strip_name_encoding) (tname);
7804 /* Output the thunk. We know that the function is in the same
7805 translation unit (i.e., the same space) as the thunk, and that
7806 thunks are output after their method. Thus, we don't need an
7807 external branch to reach the function. With SOM and GAS,
7808 functions and thunks are effectively in different sections.
7809 Thus, we can always use a IA-relative branch and the linker
7810 will add a long branch stub if necessary.
7812 However, we have to be careful when generating PIC code on the
7813 SOM port to ensure that the sequence does not transfer to an
7814 import stub for the target function as this could clobber the
7815 return value saved at SP-24. This would also apply to the
7816 32-bit linux port if the multi-space model is implemented. */
7817 if ((!TARGET_LONG_CALLS && TARGET_SOM && !TARGET_PORTABLE_RUNTIME
7818 && !(flag_pic && TREE_PUBLIC (function))
7819 && (TARGET_GAS || last_address < 262132))
7820 || (!TARGET_LONG_CALLS && !TARGET_SOM && !TARGET_PORTABLE_RUNTIME
7821 && ((targetm.have_named_sections
7822 && DECL_SECTION_NAME (thunk_fndecl) != NULL
7823 /* The GNU 64-bit linker has rather poor stub management.
7824 So, we use a long branch from thunks that aren't in
7825 the same section as the target function. */
7826 && ((!TARGET_64BIT
7827 && (DECL_SECTION_NAME (thunk_fndecl)
7828 != DECL_SECTION_NAME (function)))
7829 || ((DECL_SECTION_NAME (thunk_fndecl)
7830 == DECL_SECTION_NAME (function))
7831 && last_address < 262132)))
7832 || (!targetm.have_named_sections && last_address < 262132))))
7834 if (val_14)
7836 fprintf (file, "\tb %s\n\tldo " HOST_WIDE_INT_PRINT_DEC
7837 "(%%r26),%%r26\n", fname, delta);
7838 nbytes += 8;
7840 else
7842 fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
7843 ",%%r26\n", delta);
7844 fprintf (file, "\tb %s\n\tldo R'" HOST_WIDE_INT_PRINT_DEC
7845 "(%%r1),%%r26\n", fname, delta);
7846 nbytes += 12;
7849 else if (TARGET_64BIT)
7851 /* We only have one call-clobbered scratch register, so we can't
7852 make use of the delay slot if delta doesn't fit in 14 bits. */
7853 if (!val_14)
7854 fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
7855 ",%%r26\n\tldo R'" HOST_WIDE_INT_PRINT_DEC
7856 "(%%r1),%%r26\n", delta, delta);
7858 fprintf (file, "\tb,l .+8,%%r1\n");
7860 if (TARGET_GAS)
7862 fprintf (file, "\taddil L'%s-$PIC_pcrel$0+4,%%r1\n", fname);
7863 fprintf (file, "\tldo R'%s-$PIC_pcrel$0+8(%%r1),%%r1\n", fname);
7865 else
7867 int off = val_14 ? 8 : 16;
7868 fprintf (file, "\taddil L'%s-%s-%d,%%r1\n", fname, tname, off);
7869 fprintf (file, "\tldo R'%s-%s-%d(%%r1),%%r1\n", fname, tname, off);
7872 if (val_14)
7874 fprintf (file, "\tbv %%r0(%%r1)\n\tldo ");
7875 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
7876 nbytes += 20;
7878 else
7880 fprintf (file, "\tbv,n %%r0(%%r1)\n");
7881 nbytes += 24;
7884 else if (TARGET_PORTABLE_RUNTIME)
7886 fprintf (file, "\tldil L'%s,%%r1\n", fname);
7887 fprintf (file, "\tldo R'%s(%%r1),%%r22\n", fname);
7889 if (val_14)
7891 fprintf (file, "\tbv %%r0(%%r22)\n\tldo ");
7892 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
7893 nbytes += 16;
7895 else
7897 fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
7898 ",%%r26\n", delta);
7899 fprintf (file, "\tbv %%r0(%%r22)\n\tldo ");
7900 fprintf (file, "R'" HOST_WIDE_INT_PRINT_DEC "(%%r1),%%r26\n", delta);
7901 nbytes += 20;
7904 else if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
7906 /* The function is accessible from outside this module. The only
7907 way to avoid an import stub between the thunk and function is to
7908 call the function directly with an indirect sequence similar to
7909 that used by $$dyncall. This is possible because $$dyncall acts
7910 as the import stub in an indirect call. */
7911 const char *lab;
7913 ASM_GENERATE_INTERNAL_LABEL (label, "LTHN", current_thunk_number);
7914 lab = (*targetm.strip_name_encoding) (label);
7916 fprintf (file, "\taddil LT'%s,%%r19\n", lab);
7917 fprintf (file, "\tldw RT'%s(%%r1),%%r22\n", lab);
7918 fprintf (file, "\tldw 0(%%sr0,%%r22),%%r22\n");
7919 fprintf (file, "\tbb,>=,n %%r22,30,.+16\n");
7920 fprintf (file, "\tdepi 0,31,2,%%r22\n");
7921 fprintf (file, "\tldw 4(%%sr0,%%r22),%%r19\n");
7922 fprintf (file, "\tldw 0(%%sr0,%%r22),%%r22\n");
7923 if (!val_14)
7925 fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
7926 ",%%r26\n", delta);
7927 nbytes += 4;
7929 if (TARGET_PA_20)
7931 fprintf (file, "\tbve (%%r22)\n\tldo ");
7932 nbytes += 36;
7934 else
7936 if (TARGET_NO_SPACE_REGS)
7938 fprintf (file, "\tbe 0(%%sr4,%%r22)\n\tldo ");
7939 nbytes += 36;
7941 else
7943 fprintf (file, "\tldsid (%%sr0,%%r22),%%r21\n");
7944 fprintf (file, "\tmtsp %%r21,%%sr0\n");
7945 fprintf (file, "\tbe 0(%%sr0,%%r22)\n\tldo ");
7946 nbytes += 44;
7950 if (val_14)
7951 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
7952 else
7953 fprintf (file, "R'" HOST_WIDE_INT_PRINT_DEC "(%%r1),%%r26\n", delta);
7955 else if (flag_pic)
7957 if (TARGET_PA_20)
7958 fprintf (file, "\tb,l .+8,%%r1\n");
7959 else
7960 fprintf (file, "\tbl .+8,%%r1\n");
7962 if (TARGET_SOM || !TARGET_GAS)
7964 fprintf (file, "\taddil L'%s-%s-8,%%r1\n", fname, tname);
7965 fprintf (file, "\tldo R'%s-%s-8(%%r1),%%r22\n", fname, tname);
7967 else
7969 fprintf (file, "\taddil L'%s-$PIC_pcrel$0+4,%%r1\n", fname);
7970 fprintf (file, "\tldo R'%s-$PIC_pcrel$0+8(%%r1),%%r22\n", fname);
7973 if (val_14)
7975 fprintf (file, "\tbv %%r0(%%r22)\n\tldo ");
7976 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
7977 nbytes += 20;
7979 else
7981 fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC
7982 ",%%r26\n", delta);
7983 fprintf (file, "\tbv %%r0(%%r22)\n\tldo ");
7984 fprintf (file, "R'" HOST_WIDE_INT_PRINT_DEC "(%%r1),%%r26\n", delta);
7985 nbytes += 24;
7988 else
7990 if (!val_14)
7991 fprintf (file, "\taddil L'" HOST_WIDE_INT_PRINT_DEC ",%%r26\n", delta);
7993 fprintf (file, "\tldil L'%s,%%r22\n", fname);
7994 fprintf (file, "\tbe R'%s(%%sr4,%%r22)\n\tldo ", fname);
7996 if (val_14)
7998 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%%r26),%%r26\n", delta);
7999 nbytes += 12;
8001 else
8003 fprintf (file, "R'" HOST_WIDE_INT_PRINT_DEC "(%%r1),%%r26\n", delta);
8004 nbytes += 16;
8008 fprintf (file, "\t.EXIT\n\t.PROCEND\n");
8010 if (TARGET_SOM && flag_pic && TREE_PUBLIC (function))
8012 data_section ();
8013 fprintf (file, "\t.align 4\n");
8014 ASM_OUTPUT_LABEL (file, label);
8015 fprintf (file, "\t.word P'%s\n", fname);
8017 else if (TARGET_SOM && TARGET_GAS)
8018 forget_section ();
8020 current_thunk_number++;
8021 nbytes = ((nbytes + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
8022 & ~(FUNCTION_BOUNDARY / BITS_PER_UNIT - 1));
8023 last_address += nbytes;
8024 update_total_code_bytes (nbytes);
8027 /* Only direct calls to static functions are allowed to be sibling (tail)
8028 call optimized.
8030 This restriction is necessary because some linker generated stubs will
8031 store return pointers into rp' in some cases which might clobber a
8032 live value already in rp'.
8034 In a sibcall the current function and the target function share stack
8035 space. Thus if the path to the current function and the path to the
8036 target function save a value in rp', they save the value into the
8037 same stack slot, which has undesirable consequences.
8039 Because of the deferred binding nature of shared libraries any function
8040 with external scope could be in a different load module and thus require
8041 rp' to be saved when calling that function. So sibcall optimizations
8042 can only be safe for static function.
8044 Note that GCC never needs return value relocations, so we don't have to
8045 worry about static calls with return value relocations (which require
8046 saving rp').
8048 It is safe to perform a sibcall optimization when the target function
8049 will never return. */
8050 static bool
8051 pa_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
8053 /* Sibcalls are ok for TARGET_ELF32 as along as the linker is used in
8054 single subspace mode and the call is not indirect. As far as I know,
8055 there is no operating system support for the multiple subspace mode.
8056 It might be possible to support indirect calls if we didn't use
8057 $$dyncall (see the indirect sequence generated in output_call). */
8058 if (TARGET_ELF32)
8059 return (decl != NULL_TREE);
8061 /* Sibcalls are not ok because the arg pointer register is not a fixed
8062 register. This prevents the sibcall optimization from occurring. In
8063 addition, there are problems with stub placement using GNU ld. This
8064 is because a normal sibcall branch uses a 17-bit relocation while
8065 a regular call branch uses a 22-bit relocation. As a result, more
8066 care needs to be taken in the placement of long-branch stubs. */
8067 if (TARGET_64BIT)
8068 return false;
8070 return (decl
8071 && !TARGET_PORTABLE_RUNTIME
8072 && !TREE_PUBLIC (decl));
8075 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8076 use in fmpyadd instructions. */
8078 fmpyaddoperands (rtx *operands)
8080 enum machine_mode mode = GET_MODE (operands[0]);
8082 /* Must be a floating point mode. */
8083 if (mode != SFmode && mode != DFmode)
8084 return 0;
8086 /* All modes must be the same. */
8087 if (! (mode == GET_MODE (operands[1])
8088 && mode == GET_MODE (operands[2])
8089 && mode == GET_MODE (operands[3])
8090 && mode == GET_MODE (operands[4])
8091 && mode == GET_MODE (operands[5])))
8092 return 0;
8094 /* All operands must be registers. */
8095 if (! (GET_CODE (operands[1]) == REG
8096 && GET_CODE (operands[2]) == REG
8097 && GET_CODE (operands[3]) == REG
8098 && GET_CODE (operands[4]) == REG
8099 && GET_CODE (operands[5]) == REG))
8100 return 0;
8102 /* Only 2 real operands to the addition. One of the input operands must
8103 be the same as the output operand. */
8104 if (! rtx_equal_p (operands[3], operands[4])
8105 && ! rtx_equal_p (operands[3], operands[5]))
8106 return 0;
8108 /* Inout operand of add cannot conflict with any operands from multiply. */
8109 if (rtx_equal_p (operands[3], operands[0])
8110 || rtx_equal_p (operands[3], operands[1])
8111 || rtx_equal_p (operands[3], operands[2]))
8112 return 0;
8114 /* multiply cannot feed into addition operands. */
8115 if (rtx_equal_p (operands[4], operands[0])
8116 || rtx_equal_p (operands[5], operands[0]))
8117 return 0;
8119 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
8120 if (mode == SFmode
8121 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8122 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8123 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8124 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8125 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8126 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8127 return 0;
8129 /* Passed. Operands are suitable for fmpyadd. */
8130 return 1;
8133 #if !defined(USE_COLLECT2)
8134 static void
8135 pa_asm_out_constructor (rtx symbol, int priority)
8137 if (!function_label_operand (symbol, VOIDmode))
8138 hppa_encode_label (symbol);
8140 #ifdef CTORS_SECTION_ASM_OP
8141 default_ctor_section_asm_out_constructor (symbol, priority);
8142 #else
8143 # ifdef TARGET_ASM_NAMED_SECTION
8144 default_named_section_asm_out_constructor (symbol, priority);
8145 # else
8146 default_stabs_asm_out_constructor (symbol, priority);
8147 # endif
8148 #endif
8151 static void
8152 pa_asm_out_destructor (rtx symbol, int priority)
8154 if (!function_label_operand (symbol, VOIDmode))
8155 hppa_encode_label (symbol);
8157 #ifdef DTORS_SECTION_ASM_OP
8158 default_dtor_section_asm_out_destructor (symbol, priority);
8159 #else
8160 # ifdef TARGET_ASM_NAMED_SECTION
8161 default_named_section_asm_out_destructor (symbol, priority);
8162 # else
8163 default_stabs_asm_out_destructor (symbol, priority);
8164 # endif
8165 #endif
8167 #endif
8169 /* This function places uninitialized global data in the bss section.
8170 The ASM_OUTPUT_ALIGNED_BSS macro needs to be defined to call this
8171 function on the SOM port to prevent uninitialized global data from
8172 being placed in the data section. */
8174 void
8175 pa_asm_output_aligned_bss (FILE *stream,
8176 const char *name,
8177 unsigned HOST_WIDE_INT size,
8178 unsigned int align)
8180 bss_section ();
8181 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8183 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
8184 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object");
8185 #endif
8187 #ifdef ASM_OUTPUT_SIZE_DIRECTIVE
8188 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
8189 #endif
8191 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8192 ASM_OUTPUT_LABEL (stream, name);
8193 fprintf (stream, "\t.block "HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8196 /* Both the HP and GNU assemblers under HP-UX provide a .comm directive
8197 that doesn't allow the alignment of global common storage to be directly
8198 specified. The SOM linker aligns common storage based on the rounded
8199 value of the NUM_BYTES parameter in the .comm directive. It's not
8200 possible to use the .align directive as it doesn't affect the alignment
8201 of the label associated with a .comm directive. */
8203 void
8204 pa_asm_output_aligned_common (FILE *stream,
8205 const char *name,
8206 unsigned HOST_WIDE_INT size,
8207 unsigned int align)
8209 bss_section ();
8211 assemble_name (stream, name);
8212 fprintf (stream, "\t.comm "HOST_WIDE_INT_PRINT_UNSIGNED"\n",
8213 MAX (size, align / BITS_PER_UNIT));
8216 /* We can't use .comm for local common storage as the SOM linker effectively
8217 treats the symbol as universal and uses the same storage for local symbols
8218 with the same name in different object files. The .block directive
8219 reserves an uninitialized block of storage. However, it's not common
8220 storage. Fortunately, GCC never requests common storage with the same
8221 name in any given translation unit. */
8223 void
8224 pa_asm_output_aligned_local (FILE *stream,
8225 const char *name,
8226 unsigned HOST_WIDE_INT size,
8227 unsigned int align)
8229 bss_section ();
8230 fprintf (stream, "\t.align %u\n", align / BITS_PER_UNIT);
8232 #ifdef LOCAL_ASM_OP
8233 fprintf (stream, "%s", LOCAL_ASM_OP);
8234 assemble_name (stream, name);
8235 fprintf (stream, "\n");
8236 #endif
8238 ASM_OUTPUT_LABEL (stream, name);
8239 fprintf (stream, "\t.block "HOST_WIDE_INT_PRINT_UNSIGNED"\n", size);
8242 /* Returns 1 if the 6 operands specified in OPERANDS are suitable for
8243 use in fmpysub instructions. */
8245 fmpysuboperands (rtx *operands)
8247 enum machine_mode mode = GET_MODE (operands[0]);
8249 /* Must be a floating point mode. */
8250 if (mode != SFmode && mode != DFmode)
8251 return 0;
8253 /* All modes must be the same. */
8254 if (! (mode == GET_MODE (operands[1])
8255 && mode == GET_MODE (operands[2])
8256 && mode == GET_MODE (operands[3])
8257 && mode == GET_MODE (operands[4])
8258 && mode == GET_MODE (operands[5])))
8259 return 0;
8261 /* All operands must be registers. */
8262 if (! (GET_CODE (operands[1]) == REG
8263 && GET_CODE (operands[2]) == REG
8264 && GET_CODE (operands[3]) == REG
8265 && GET_CODE (operands[4]) == REG
8266 && GET_CODE (operands[5]) == REG))
8267 return 0;
8269 /* Only 2 real operands to the subtraction. Subtraction is not a commutative
8270 operation, so operands[4] must be the same as operand[3]. */
8271 if (! rtx_equal_p (operands[3], operands[4]))
8272 return 0;
8274 /* multiply cannot feed into subtraction. */
8275 if (rtx_equal_p (operands[5], operands[0]))
8276 return 0;
8278 /* Inout operand of sub cannot conflict with any operands from multiply. */
8279 if (rtx_equal_p (operands[3], operands[0])
8280 || rtx_equal_p (operands[3], operands[1])
8281 || rtx_equal_p (operands[3], operands[2]))
8282 return 0;
8284 /* SFmode limits the registers to the upper 32 of the 32bit FP regs. */
8285 if (mode == SFmode
8286 && (REGNO_REG_CLASS (REGNO (operands[0])) != FPUPPER_REGS
8287 || REGNO_REG_CLASS (REGNO (operands[1])) != FPUPPER_REGS
8288 || REGNO_REG_CLASS (REGNO (operands[2])) != FPUPPER_REGS
8289 || REGNO_REG_CLASS (REGNO (operands[3])) != FPUPPER_REGS
8290 || REGNO_REG_CLASS (REGNO (operands[4])) != FPUPPER_REGS
8291 || REGNO_REG_CLASS (REGNO (operands[5])) != FPUPPER_REGS))
8292 return 0;
8294 /* Passed. Operands are suitable for fmpysub. */
8295 return 1;
8299 plus_xor_ior_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8301 return (GET_CODE (op) == PLUS || GET_CODE (op) == XOR
8302 || GET_CODE (op) == IOR);
8305 /* Return 1 if the given constant is 2, 4, or 8. These are the valid
8306 constants for shadd instructions. */
8307 static int
8308 shadd_constant_p (int val)
8310 if (val == 2 || val == 4 || val == 8)
8311 return 1;
8312 else
8313 return 0;
8316 /* Return 1 if OP is a CONST_INT with the value 2, 4, or 8. These are
8317 the valid constant for shadd instructions. */
8319 shadd_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8321 return (GET_CODE (op) == CONST_INT && shadd_constant_p (INTVAL (op)));
8324 /* Return 1 if OP is valid as a base or index register in a
8325 REG+REG address. */
8328 borx_reg_operand (rtx op, enum machine_mode mode)
8330 if (GET_CODE (op) != REG)
8331 return 0;
8333 /* We must reject virtual registers as the only expressions that
8334 can be instantiated are REG and REG+CONST. */
8335 if (op == virtual_incoming_args_rtx
8336 || op == virtual_stack_vars_rtx
8337 || op == virtual_stack_dynamic_rtx
8338 || op == virtual_outgoing_args_rtx
8339 || op == virtual_cfa_rtx)
8340 return 0;
8342 /* While it's always safe to index off the frame pointer, it's not
8343 profitable to do so when the frame pointer is being eliminated. */
8344 if (!reload_completed
8345 && flag_omit_frame_pointer
8346 && !current_function_calls_alloca
8347 && op == frame_pointer_rtx)
8348 return 0;
8350 return register_operand (op, mode);
8353 /* Return 1 if this operand is anything other than a hard register. */
8356 non_hard_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8358 return ! (GET_CODE (op) == REG && REGNO (op) < FIRST_PSEUDO_REGISTER);
8361 /* Return 1 if INSN branches forward. Should be using insn_addresses
8362 to avoid walking through all the insns... */
8363 static int
8364 forward_branch_p (rtx insn)
8366 rtx label = JUMP_LABEL (insn);
8368 while (insn)
8370 if (insn == label)
8371 break;
8372 else
8373 insn = NEXT_INSN (insn);
8376 return (insn == label);
8379 /* Return 1 if OP is an equality comparison, else return 0. */
8381 eq_neq_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8383 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
8386 /* Return 1 if OP is an operator suitable for use in a movb instruction. */
8388 movb_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8390 return (GET_CODE (op) == EQ || GET_CODE (op) == NE
8391 || GET_CODE (op) == LT || GET_CODE (op) == GE);
8394 /* Return 1 if INSN is in the delay slot of a call instruction. */
8396 jump_in_call_delay (rtx insn)
8399 if (GET_CODE (insn) != JUMP_INSN)
8400 return 0;
8402 if (PREV_INSN (insn)
8403 && PREV_INSN (PREV_INSN (insn))
8404 && GET_CODE (next_real_insn (PREV_INSN (PREV_INSN (insn)))) == INSN)
8406 rtx test_insn = next_real_insn (PREV_INSN (PREV_INSN (insn)));
8408 return (GET_CODE (PATTERN (test_insn)) == SEQUENCE
8409 && XVECEXP (PATTERN (test_insn), 0, 1) == insn);
8412 else
8413 return 0;
8416 /* Output an unconditional move and branch insn. */
8418 const char *
8419 output_parallel_movb (rtx *operands, int length)
8421 /* These are the cases in which we win. */
8422 if (length == 4)
8423 return "mov%I1b,tr %1,%0,%2";
8425 /* None of these cases wins, but they don't lose either. */
8426 if (dbr_sequence_length () == 0)
8428 /* Nothing in the delay slot, fake it by putting the combined
8429 insn (the copy or add) in the delay slot of a bl. */
8430 if (GET_CODE (operands[1]) == CONST_INT)
8431 return "b %2\n\tldi %1,%0";
8432 else
8433 return "b %2\n\tcopy %1,%0";
8435 else
8437 /* Something in the delay slot, but we've got a long branch. */
8438 if (GET_CODE (operands[1]) == CONST_INT)
8439 return "ldi %1,%0\n\tb %2";
8440 else
8441 return "copy %1,%0\n\tb %2";
8445 /* Output an unconditional add and branch insn. */
8447 const char *
8448 output_parallel_addb (rtx *operands, int length)
8450 /* To make life easy we want operand0 to be the shared input/output
8451 operand and operand1 to be the readonly operand. */
8452 if (operands[0] == operands[1])
8453 operands[1] = operands[2];
8455 /* These are the cases in which we win. */
8456 if (length == 4)
8457 return "add%I1b,tr %1,%0,%3";
8459 /* None of these cases win, but they don't lose either. */
8460 if (dbr_sequence_length () == 0)
8462 /* Nothing in the delay slot, fake it by putting the combined
8463 insn (the copy or add) in the delay slot of a bl. */
8464 return "b %3\n\tadd%I1 %1,%0,%0";
8466 else
8468 /* Something in the delay slot, but we've got a long branch. */
8469 return "add%I1 %1,%0,%0\n\tb %3";
8473 /* Return nonzero if INSN (a jump insn) immediately follows a call
8474 to a named function. This is used to avoid filling the delay slot
8475 of the jump since it can usually be eliminated by modifying RP in
8476 the delay slot of the call. */
8479 following_call (rtx insn)
8481 if (! TARGET_JUMP_IN_DELAY)
8482 return 0;
8484 /* Find the previous real insn, skipping NOTEs. */
8485 insn = PREV_INSN (insn);
8486 while (insn && GET_CODE (insn) == NOTE)
8487 insn = PREV_INSN (insn);
8489 /* Check for CALL_INSNs and millicode calls. */
8490 if (insn
8491 && ((GET_CODE (insn) == CALL_INSN
8492 && get_attr_type (insn) != TYPE_DYNCALL)
8493 || (GET_CODE (insn) == INSN
8494 && GET_CODE (PATTERN (insn)) != SEQUENCE
8495 && GET_CODE (PATTERN (insn)) != USE
8496 && GET_CODE (PATTERN (insn)) != CLOBBER
8497 && get_attr_type (insn) == TYPE_MILLI)))
8498 return 1;
8500 return 0;
8503 /* We use this hook to perform a PA specific optimization which is difficult
8504 to do in earlier passes.
8506 We want the delay slots of branches within jump tables to be filled.
8507 None of the compiler passes at the moment even has the notion that a
8508 PA jump table doesn't contain addresses, but instead contains actual
8509 instructions!
8511 Because we actually jump into the table, the addresses of each entry
8512 must stay constant in relation to the beginning of the table (which
8513 itself must stay constant relative to the instruction to jump into
8514 it). I don't believe we can guarantee earlier passes of the compiler
8515 will adhere to those rules.
8517 So, late in the compilation process we find all the jump tables, and
8518 expand them into real code -- eg each entry in the jump table vector
8519 will get an appropriate label followed by a jump to the final target.
8521 Reorg and the final jump pass can then optimize these branches and
8522 fill their delay slots. We end up with smaller, more efficient code.
8524 The jump instructions within the table are special; we must be able
8525 to identify them during assembly output (if the jumps don't get filled
8526 we need to emit a nop rather than nullifying the delay slot)). We
8527 identify jumps in switch tables by using insns with the attribute
8528 type TYPE_BTABLE_BRANCH.
8530 We also surround the jump table itself with BEGIN_BRTAB and END_BRTAB
8531 insns. This serves two purposes, first it prevents jump.c from
8532 noticing that the last N entries in the table jump to the instruction
8533 immediately after the table and deleting the jumps. Second, those
8534 insns mark where we should emit .begin_brtab and .end_brtab directives
8535 when using GAS (allows for better link time optimizations). */
8537 static void
8538 pa_reorg (void)
8540 rtx insn;
8542 remove_useless_addtr_insns (1);
8544 if (pa_cpu < PROCESSOR_8000)
8545 pa_combine_instructions ();
8548 /* This is fairly cheap, so always run it if optimizing. */
8549 if (optimize > 0 && !TARGET_BIG_SWITCH)
8551 /* Find and explode all ADDR_VEC or ADDR_DIFF_VEC insns. */
8552 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
8554 rtx pattern, tmp, location, label;
8555 unsigned int length, i;
8557 /* Find an ADDR_VEC or ADDR_DIFF_VEC insn to explode. */
8558 if (GET_CODE (insn) != JUMP_INSN
8559 || (GET_CODE (PATTERN (insn)) != ADDR_VEC
8560 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
8561 continue;
8563 /* Emit marker for the beginning of the branch table. */
8564 emit_insn_before (gen_begin_brtab (), insn);
8566 pattern = PATTERN (insn);
8567 location = PREV_INSN (insn);
8568 length = XVECLEN (pattern, GET_CODE (pattern) == ADDR_DIFF_VEC);
8570 for (i = 0; i < length; i++)
8572 /* Emit a label before each jump to keep jump.c from
8573 removing this code. */
8574 tmp = gen_label_rtx ();
8575 LABEL_NUSES (tmp) = 1;
8576 emit_label_after (tmp, location);
8577 location = NEXT_INSN (location);
8579 if (GET_CODE (pattern) == ADDR_VEC)
8580 label = XEXP (XVECEXP (pattern, 0, i), 0);
8581 else
8582 label = XEXP (XVECEXP (pattern, 1, i), 0);
8584 tmp = gen_short_jump (label);
8586 /* Emit the jump itself. */
8587 tmp = emit_jump_insn_after (tmp, location);
8588 JUMP_LABEL (tmp) = label;
8589 LABEL_NUSES (label)++;
8590 location = NEXT_INSN (location);
8592 /* Emit a BARRIER after the jump. */
8593 emit_barrier_after (location);
8594 location = NEXT_INSN (location);
8597 /* Emit marker for the end of the branch table. */
8598 emit_insn_before (gen_end_brtab (), location);
8599 location = NEXT_INSN (location);
8600 emit_barrier_after (location);
8602 /* Delete the ADDR_VEC or ADDR_DIFF_VEC. */
8603 delete_insn (insn);
8606 else
8608 /* Still need brtab marker insns. FIXME: the presence of these
8609 markers disables output of the branch table to readonly memory,
8610 and any alignment directives that might be needed. Possibly,
8611 the begin_brtab insn should be output before the label for the
8612 table. This doesn't matter at the moment since the tables are
8613 always output in the text section. */
8614 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
8616 /* Find an ADDR_VEC insn. */
8617 if (GET_CODE (insn) != JUMP_INSN
8618 || (GET_CODE (PATTERN (insn)) != ADDR_VEC
8619 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC))
8620 continue;
8622 /* Now generate markers for the beginning and end of the
8623 branch table. */
8624 emit_insn_before (gen_begin_brtab (), insn);
8625 emit_insn_after (gen_end_brtab (), insn);
8630 /* The PA has a number of odd instructions which can perform multiple
8631 tasks at once. On first generation PA machines (PA1.0 and PA1.1)
8632 it may be profitable to combine two instructions into one instruction
8633 with two outputs. It's not profitable PA2.0 machines because the
8634 two outputs would take two slots in the reorder buffers.
8636 This routine finds instructions which can be combined and combines
8637 them. We only support some of the potential combinations, and we
8638 only try common ways to find suitable instructions.
8640 * addb can add two registers or a register and a small integer
8641 and jump to a nearby (+-8k) location. Normally the jump to the
8642 nearby location is conditional on the result of the add, but by
8643 using the "true" condition we can make the jump unconditional.
8644 Thus addb can perform two independent operations in one insn.
8646 * movb is similar to addb in that it can perform a reg->reg
8647 or small immediate->reg copy and jump to a nearby (+-8k location).
8649 * fmpyadd and fmpysub can perform a FP multiply and either an
8650 FP add or FP sub if the operands of the multiply and add/sub are
8651 independent (there are other minor restrictions). Note both
8652 the fmpy and fadd/fsub can in theory move to better spots according
8653 to data dependencies, but for now we require the fmpy stay at a
8654 fixed location.
8656 * Many of the memory operations can perform pre & post updates
8657 of index registers. GCC's pre/post increment/decrement addressing
8658 is far too simple to take advantage of all the possibilities. This
8659 pass may not be suitable since those insns may not be independent.
8661 * comclr can compare two ints or an int and a register, nullify
8662 the following instruction and zero some other register. This
8663 is more difficult to use as it's harder to find an insn which
8664 will generate a comclr than finding something like an unconditional
8665 branch. (conditional moves & long branches create comclr insns).
8667 * Most arithmetic operations can conditionally skip the next
8668 instruction. They can be viewed as "perform this operation
8669 and conditionally jump to this nearby location" (where nearby
8670 is an insns away). These are difficult to use due to the
8671 branch length restrictions. */
8673 static void
8674 pa_combine_instructions (void)
8676 rtx anchor, new;
8678 /* This can get expensive since the basic algorithm is on the
8679 order of O(n^2) (or worse). Only do it for -O2 or higher
8680 levels of optimization. */
8681 if (optimize < 2)
8682 return;
8684 /* Walk down the list of insns looking for "anchor" insns which
8685 may be combined with "floating" insns. As the name implies,
8686 "anchor" instructions don't move, while "floating" insns may
8687 move around. */
8688 new = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, NULL_RTX, NULL_RTX));
8689 new = make_insn_raw (new);
8691 for (anchor = get_insns (); anchor; anchor = NEXT_INSN (anchor))
8693 enum attr_pa_combine_type anchor_attr;
8694 enum attr_pa_combine_type floater_attr;
8696 /* We only care about INSNs, JUMP_INSNs, and CALL_INSNs.
8697 Also ignore any special USE insns. */
8698 if ((GET_CODE (anchor) != INSN
8699 && GET_CODE (anchor) != JUMP_INSN
8700 && GET_CODE (anchor) != CALL_INSN)
8701 || GET_CODE (PATTERN (anchor)) == USE
8702 || GET_CODE (PATTERN (anchor)) == CLOBBER
8703 || GET_CODE (PATTERN (anchor)) == ADDR_VEC
8704 || GET_CODE (PATTERN (anchor)) == ADDR_DIFF_VEC)
8705 continue;
8707 anchor_attr = get_attr_pa_combine_type (anchor);
8708 /* See if anchor is an insn suitable for combination. */
8709 if (anchor_attr == PA_COMBINE_TYPE_FMPY
8710 || anchor_attr == PA_COMBINE_TYPE_FADDSUB
8711 || (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
8712 && ! forward_branch_p (anchor)))
8714 rtx floater;
8716 for (floater = PREV_INSN (anchor);
8717 floater;
8718 floater = PREV_INSN (floater))
8720 if (GET_CODE (floater) == NOTE
8721 || (GET_CODE (floater) == INSN
8722 && (GET_CODE (PATTERN (floater)) == USE
8723 || GET_CODE (PATTERN (floater)) == CLOBBER)))
8724 continue;
8726 /* Anything except a regular INSN will stop our search. */
8727 if (GET_CODE (floater) != INSN
8728 || GET_CODE (PATTERN (floater)) == ADDR_VEC
8729 || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
8731 floater = NULL_RTX;
8732 break;
8735 /* See if FLOATER is suitable for combination with the
8736 anchor. */
8737 floater_attr = get_attr_pa_combine_type (floater);
8738 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
8739 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
8740 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
8741 && floater_attr == PA_COMBINE_TYPE_FMPY))
8743 /* If ANCHOR and FLOATER can be combined, then we're
8744 done with this pass. */
8745 if (pa_can_combine_p (new, anchor, floater, 0,
8746 SET_DEST (PATTERN (floater)),
8747 XEXP (SET_SRC (PATTERN (floater)), 0),
8748 XEXP (SET_SRC (PATTERN (floater)), 1)))
8749 break;
8752 else if (anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH
8753 && floater_attr == PA_COMBINE_TYPE_ADDMOVE)
8755 if (GET_CODE (SET_SRC (PATTERN (floater))) == PLUS)
8757 if (pa_can_combine_p (new, anchor, floater, 0,
8758 SET_DEST (PATTERN (floater)),
8759 XEXP (SET_SRC (PATTERN (floater)), 0),
8760 XEXP (SET_SRC (PATTERN (floater)), 1)))
8761 break;
8763 else
8765 if (pa_can_combine_p (new, anchor, floater, 0,
8766 SET_DEST (PATTERN (floater)),
8767 SET_SRC (PATTERN (floater)),
8768 SET_SRC (PATTERN (floater))))
8769 break;
8774 /* If we didn't find anything on the backwards scan try forwards. */
8775 if (!floater
8776 && (anchor_attr == PA_COMBINE_TYPE_FMPY
8777 || anchor_attr == PA_COMBINE_TYPE_FADDSUB))
8779 for (floater = anchor; floater; floater = NEXT_INSN (floater))
8781 if (GET_CODE (floater) == NOTE
8782 || (GET_CODE (floater) == INSN
8783 && (GET_CODE (PATTERN (floater)) == USE
8784 || GET_CODE (PATTERN (floater)) == CLOBBER)))
8786 continue;
8788 /* Anything except a regular INSN will stop our search. */
8789 if (GET_CODE (floater) != INSN
8790 || GET_CODE (PATTERN (floater)) == ADDR_VEC
8791 || GET_CODE (PATTERN (floater)) == ADDR_DIFF_VEC)
8793 floater = NULL_RTX;
8794 break;
8797 /* See if FLOATER is suitable for combination with the
8798 anchor. */
8799 floater_attr = get_attr_pa_combine_type (floater);
8800 if ((anchor_attr == PA_COMBINE_TYPE_FMPY
8801 && floater_attr == PA_COMBINE_TYPE_FADDSUB)
8802 || (anchor_attr == PA_COMBINE_TYPE_FADDSUB
8803 && floater_attr == PA_COMBINE_TYPE_FMPY))
8805 /* If ANCHOR and FLOATER can be combined, then we're
8806 done with this pass. */
8807 if (pa_can_combine_p (new, anchor, floater, 1,
8808 SET_DEST (PATTERN (floater)),
8809 XEXP (SET_SRC (PATTERN (floater)),
8811 XEXP (SET_SRC (PATTERN (floater)),
8812 1)))
8813 break;
8818 /* FLOATER will be nonzero if we found a suitable floating
8819 insn for combination with ANCHOR. */
8820 if (floater
8821 && (anchor_attr == PA_COMBINE_TYPE_FADDSUB
8822 || anchor_attr == PA_COMBINE_TYPE_FMPY))
8824 /* Emit the new instruction and delete the old anchor. */
8825 emit_insn_before (gen_rtx_PARALLEL
8826 (VOIDmode,
8827 gen_rtvec (2, PATTERN (anchor),
8828 PATTERN (floater))),
8829 anchor);
8831 PUT_CODE (anchor, NOTE);
8832 NOTE_LINE_NUMBER (anchor) = NOTE_INSN_DELETED;
8833 NOTE_SOURCE_FILE (anchor) = 0;
8835 /* Emit a special USE insn for FLOATER, then delete
8836 the floating insn. */
8837 emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
8838 delete_insn (floater);
8840 continue;
8842 else if (floater
8843 && anchor_attr == PA_COMBINE_TYPE_UNCOND_BRANCH)
8845 rtx temp;
8846 /* Emit the new_jump instruction and delete the old anchor. */
8847 temp
8848 = emit_jump_insn_before (gen_rtx_PARALLEL
8849 (VOIDmode,
8850 gen_rtvec (2, PATTERN (anchor),
8851 PATTERN (floater))),
8852 anchor);
8854 JUMP_LABEL (temp) = JUMP_LABEL (anchor);
8855 PUT_CODE (anchor, NOTE);
8856 NOTE_LINE_NUMBER (anchor) = NOTE_INSN_DELETED;
8857 NOTE_SOURCE_FILE (anchor) = 0;
8859 /* Emit a special USE insn for FLOATER, then delete
8860 the floating insn. */
8861 emit_insn_before (gen_rtx_USE (VOIDmode, floater), floater);
8862 delete_insn (floater);
8863 continue;
8869 static int
8870 pa_can_combine_p (rtx new, rtx anchor, rtx floater, int reversed, rtx dest,
8871 rtx src1, rtx src2)
8873 int insn_code_number;
8874 rtx start, end;
8876 /* Create a PARALLEL with the patterns of ANCHOR and
8877 FLOATER, try to recognize it, then test constraints
8878 for the resulting pattern.
8880 If the pattern doesn't match or the constraints
8881 aren't met keep searching for a suitable floater
8882 insn. */
8883 XVECEXP (PATTERN (new), 0, 0) = PATTERN (anchor);
8884 XVECEXP (PATTERN (new), 0, 1) = PATTERN (floater);
8885 INSN_CODE (new) = -1;
8886 insn_code_number = recog_memoized (new);
8887 if (insn_code_number < 0
8888 || (extract_insn (new), ! constrain_operands (1)))
8889 return 0;
8891 if (reversed)
8893 start = anchor;
8894 end = floater;
8896 else
8898 start = floater;
8899 end = anchor;
8902 /* There's up to three operands to consider. One
8903 output and two inputs.
8905 The output must not be used between FLOATER & ANCHOR
8906 exclusive. The inputs must not be set between
8907 FLOATER and ANCHOR exclusive. */
8909 if (reg_used_between_p (dest, start, end))
8910 return 0;
8912 if (reg_set_between_p (src1, start, end))
8913 return 0;
8915 if (reg_set_between_p (src2, start, end))
8916 return 0;
8918 /* If we get here, then everything is good. */
8919 return 1;
8922 /* Return nonzero if references for INSN are delayed.
8924 Millicode insns are actually function calls with some special
8925 constraints on arguments and register usage.
8927 Millicode calls always expect their arguments in the integer argument
8928 registers, and always return their result in %r29 (ret1). They
8929 are expected to clobber their arguments, %r1, %r29, and the return
8930 pointer which is %r31 on 32-bit and %r2 on 64-bit, and nothing else.
8932 This function tells reorg that the references to arguments and
8933 millicode calls do not appear to happen until after the millicode call.
8934 This allows reorg to put insns which set the argument registers into the
8935 delay slot of the millicode call -- thus they act more like traditional
8936 CALL_INSNs.
8938 Note we cannot consider side effects of the insn to be delayed because
8939 the branch and link insn will clobber the return pointer. If we happened
8940 to use the return pointer in the delay slot of the call, then we lose.
8942 get_attr_type will try to recognize the given insn, so make sure to
8943 filter out things it will not accept -- SEQUENCE, USE and CLOBBER insns
8944 in particular. */
8946 insn_refs_are_delayed (rtx insn)
8948 return ((GET_CODE (insn) == INSN
8949 && GET_CODE (PATTERN (insn)) != SEQUENCE
8950 && GET_CODE (PATTERN (insn)) != USE
8951 && GET_CODE (PATTERN (insn)) != CLOBBER
8952 && get_attr_type (insn) == TYPE_MILLI));
8955 /* On the HP-PA the value is found in register(s) 28(-29), unless
8956 the mode is SF or DF. Then the value is returned in fr4 (32).
8958 This must perform the same promotions as PROMOTE_MODE, else
8959 TARGET_PROMOTE_FUNCTION_RETURN will not work correctly.
8961 Small structures must be returned in a PARALLEL on PA64 in order
8962 to match the HP Compiler ABI. */
8965 function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
8967 enum machine_mode valmode;
8969 /* Aggregates with a size less than or equal to 128 bits are returned
8970 in GR 28(-29). They are left justified. The pad bits are undefined.
8971 Larger aggregates are returned in memory. */
8972 if (TARGET_64BIT && AGGREGATE_TYPE_P (valtype))
8974 rtx loc[2];
8975 int i, offset = 0;
8976 int ub = int_size_in_bytes (valtype) <= UNITS_PER_WORD ? 1 : 2;
8978 for (i = 0; i < ub; i++)
8980 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
8981 gen_rtx_REG (DImode, 28 + i),
8982 GEN_INT (offset));
8983 offset += 8;
8986 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (ub, loc));
8989 if ((INTEGRAL_TYPE_P (valtype)
8990 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
8991 || POINTER_TYPE_P (valtype))
8992 valmode = word_mode;
8993 else
8994 valmode = TYPE_MODE (valtype);
8996 if (TREE_CODE (valtype) == REAL_TYPE
8997 && TYPE_MODE (valtype) != TFmode
8998 && !TARGET_SOFT_FLOAT)
8999 return gen_rtx_REG (valmode, 32);
9001 return gen_rtx_REG (valmode, 28);
9004 /* Return the location of a parameter that is passed in a register or NULL
9005 if the parameter has any component that is passed in memory.
9007 This is new code and will be pushed to into the net sources after
9008 further testing.
9010 ??? We might want to restructure this so that it looks more like other
9011 ports. */
9013 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, tree type,
9014 int named ATTRIBUTE_UNUSED)
9016 int max_arg_words = (TARGET_64BIT ? 8 : 4);
9017 int alignment = 0;
9018 int arg_size;
9019 int fpr_reg_base;
9020 int gpr_reg_base;
9021 rtx retval;
9023 if (mode == VOIDmode)
9024 return NULL_RTX;
9026 arg_size = FUNCTION_ARG_SIZE (mode, type);
9028 /* If this arg would be passed partially or totally on the stack, then
9029 this routine should return zero. FUNCTION_ARG_PARTIAL_NREGS will
9030 handle arguments which are split between regs and stack slots if
9031 the ABI mandates split arguments. */
9032 if (! TARGET_64BIT)
9034 /* The 32-bit ABI does not split arguments. */
9035 if (cum->words + arg_size > max_arg_words)
9036 return NULL_RTX;
9038 else
9040 if (arg_size > 1)
9041 alignment = cum->words & 1;
9042 if (cum->words + alignment >= max_arg_words)
9043 return NULL_RTX;
9046 /* The 32bit ABIs and the 64bit ABIs are rather different,
9047 particularly in their handling of FP registers. We might
9048 be able to cleverly share code between them, but I'm not
9049 going to bother in the hope that splitting them up results
9050 in code that is more easily understood. */
9052 if (TARGET_64BIT)
9054 /* Advance the base registers to their current locations.
9056 Remember, gprs grow towards smaller register numbers while
9057 fprs grow to higher register numbers. Also remember that
9058 although FP regs are 32-bit addressable, we pretend that
9059 the registers are 64-bits wide. */
9060 gpr_reg_base = 26 - cum->words;
9061 fpr_reg_base = 32 + cum->words;
9063 /* Arguments wider than one word and small aggregates need special
9064 treatment. */
9065 if (arg_size > 1
9066 || mode == BLKmode
9067 || (type && AGGREGATE_TYPE_P (type)))
9069 /* Double-extended precision (80-bit), quad-precision (128-bit)
9070 and aggregates including complex numbers are aligned on
9071 128-bit boundaries. The first eight 64-bit argument slots
9072 are associated one-to-one, with general registers r26
9073 through r19, and also with floating-point registers fr4
9074 through fr11. Arguments larger than one word are always
9075 passed in general registers.
9077 Using a PARALLEL with a word mode register results in left
9078 justified data on a big-endian target. */
9080 rtx loc[8];
9081 int i, offset = 0, ub = arg_size;
9083 /* Align the base register. */
9084 gpr_reg_base -= alignment;
9086 ub = MIN (ub, max_arg_words - cum->words - alignment);
9087 for (i = 0; i < ub; i++)
9089 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
9090 gen_rtx_REG (DImode, gpr_reg_base),
9091 GEN_INT (offset));
9092 gpr_reg_base -= 1;
9093 offset += 8;
9096 return gen_rtx_PARALLEL (mode, gen_rtvec_v (ub, loc));
9099 else
9101 /* If the argument is larger than a word, then we know precisely
9102 which registers we must use. */
9103 if (arg_size > 1)
9105 if (cum->words)
9107 gpr_reg_base = 23;
9108 fpr_reg_base = 38;
9110 else
9112 gpr_reg_base = 25;
9113 fpr_reg_base = 34;
9116 /* Structures 5 to 8 bytes in size are passed in the general
9117 registers in the same manner as other non floating-point
9118 objects. The data is right-justified and zero-extended
9119 to 64 bits. This is opposite to the normal justification
9120 used on big endian targets and requires special treatment.
9121 We now define BLOCK_REG_PADDING to pad these objects. */
9122 if (mode == BLKmode)
9124 rtx loc = gen_rtx_EXPR_LIST (VOIDmode,
9125 gen_rtx_REG (DImode, gpr_reg_base),
9126 const0_rtx);
9127 return gen_rtx_PARALLEL (mode, gen_rtvec (1, loc));
9130 else
9132 /* We have a single word (32 bits). A simple computation
9133 will get us the register #s we need. */
9134 gpr_reg_base = 26 - cum->words;
9135 fpr_reg_base = 32 + 2 * cum->words;
9139 /* Determine if the argument needs to be passed in both general and
9140 floating point registers. */
9141 if (((TARGET_PORTABLE_RUNTIME || TARGET_64BIT || TARGET_ELF32)
9142 /* If we are doing soft-float with portable runtime, then there
9143 is no need to worry about FP regs. */
9144 && !TARGET_SOFT_FLOAT
9145 /* The parameter must be some kind of float, else we can just
9146 pass it in integer registers. */
9147 && FLOAT_MODE_P (mode)
9148 /* The target function must not have a prototype. */
9149 && cum->nargs_prototype <= 0
9150 /* libcalls do not need to pass items in both FP and general
9151 registers. */
9152 && type != NULL_TREE
9153 /* All this hair applies to "outgoing" args only. This includes
9154 sibcall arguments setup with FUNCTION_INCOMING_ARG. */
9155 && !cum->incoming)
9156 /* Also pass outgoing floating arguments in both registers in indirect
9157 calls with the 32 bit ABI and the HP assembler since there is no
9158 way to the specify argument locations in static functions. */
9159 || (!TARGET_64BIT
9160 && !TARGET_GAS
9161 && !cum->incoming
9162 && cum->indirect
9163 && FLOAT_MODE_P (mode)))
9165 retval
9166 = gen_rtx_PARALLEL
9167 (mode,
9168 gen_rtvec (2,
9169 gen_rtx_EXPR_LIST (VOIDmode,
9170 gen_rtx_REG (mode, fpr_reg_base),
9171 const0_rtx),
9172 gen_rtx_EXPR_LIST (VOIDmode,
9173 gen_rtx_REG (mode, gpr_reg_base),
9174 const0_rtx)));
9176 else
9178 /* See if we should pass this parameter in a general register. */
9179 if (TARGET_SOFT_FLOAT
9180 /* Indirect calls in the normal 32bit ABI require all arguments
9181 to be passed in general registers. */
9182 || (!TARGET_PORTABLE_RUNTIME
9183 && !TARGET_64BIT
9184 && !TARGET_ELF32
9185 && cum->indirect)
9186 /* If the parameter is not a floating point parameter, then
9187 it belongs in GPRs. */
9188 || !FLOAT_MODE_P (mode))
9189 retval = gen_rtx_REG (mode, gpr_reg_base);
9190 else
9191 retval = gen_rtx_REG (mode, fpr_reg_base);
9193 return retval;
9197 /* If this arg would be passed totally in registers or totally on the stack,
9198 then this routine should return zero. It is currently called only for
9199 the 64-bit target. */
9201 function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
9202 tree type, int named ATTRIBUTE_UNUSED)
9204 unsigned int max_arg_words = 8;
9205 unsigned int offset = 0;
9207 if (FUNCTION_ARG_SIZE (mode, type) > 1 && (cum->words & 1))
9208 offset = 1;
9210 if (cum->words + offset + FUNCTION_ARG_SIZE (mode, type) <= max_arg_words)
9211 /* Arg fits fully into registers. */
9212 return 0;
9213 else if (cum->words + offset >= max_arg_words)
9214 /* Arg fully on the stack. */
9215 return 0;
9216 else
9217 /* Arg is split. */
9218 return max_arg_words - cum->words - offset;
9222 /* Return 1 if this is a comparison operator. This allows the use of
9223 MATCH_OPERATOR to recognize all the branch insns. */
9226 cmpib_comparison_operator (rtx op, enum machine_mode mode)
9228 return ((mode == VOIDmode || GET_MODE (op) == mode)
9229 && (GET_CODE (op) == EQ
9230 || GET_CODE (op) == NE
9231 || GET_CODE (op) == GT
9232 || GET_CODE (op) == GTU
9233 || GET_CODE (op) == GE
9234 || GET_CODE (op) == LT
9235 || GET_CODE (op) == LE
9236 || GET_CODE (op) == LEU));
9239 #ifndef ONE_ONLY_TEXT_SECTION_ASM_OP
9240 #define ONE_ONLY_TEXT_SECTION_ASM_OP ""
9241 #endif
9243 #ifndef NEW_TEXT_SECTION_ASM_OP
9244 #define NEW_TEXT_SECTION_ASM_OP ""
9245 #endif
9247 #ifndef DEFAULT_TEXT_SECTION_ASM_OP
9248 #define DEFAULT_TEXT_SECTION_ASM_OP ""
9249 #endif
9251 /* Select and return a TEXT_SECTION_ASM_OP for the current function.
9253 This function is only used with SOM. Because we don't support
9254 named subspaces, we can only create a new subspace or switch back
9255 into the default text subspace. */
9256 const char *
9257 som_text_section_asm_op (void)
9259 if (TARGET_SOM && TARGET_GAS)
9261 if (cfun && !cfun->machine->in_nsubspa)
9263 /* We only want to emit a .nsubspa directive once at the
9264 start of the function. */
9265 cfun->machine->in_nsubspa = 1;
9267 /* Create a new subspace for the text. This provides
9268 better stub placement and one-only functions. */
9269 if (cfun->decl
9270 && DECL_ONE_ONLY (cfun->decl)
9271 && !DECL_WEAK (cfun->decl))
9272 return ONE_ONLY_TEXT_SECTION_ASM_OP;
9274 return NEW_TEXT_SECTION_ASM_OP;
9276 else
9278 /* There isn't a current function or the body of the current
9279 function has been completed. So, we are changing to the
9280 text section to output debugging information. Do this in
9281 the default text section. We need to forget that we are
9282 in the text section so that text_section will call us the
9283 next time around. */
9284 forget_section ();
9288 return DEFAULT_TEXT_SECTION_ASM_OP;
9291 /* On hpux10, the linker will give an error if we have a reference
9292 in the read-only data section to a symbol defined in a shared
9293 library. Therefore, expressions that might require a reloc can
9294 not be placed in the read-only data section. */
9296 static void
9297 pa_select_section (tree exp, int reloc,
9298 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
9300 if (TREE_CODE (exp) == VAR_DECL
9301 && TREE_READONLY (exp)
9302 && !TREE_THIS_VOLATILE (exp)
9303 && DECL_INITIAL (exp)
9304 && (DECL_INITIAL (exp) == error_mark_node
9305 || TREE_CONSTANT (DECL_INITIAL (exp)))
9306 && !reloc)
9308 if (TARGET_SOM
9309 && DECL_ONE_ONLY (exp)
9310 && !DECL_WEAK (exp))
9311 one_only_readonly_data_section ();
9312 else
9313 readonly_data_section ();
9315 else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c'
9316 && !reloc)
9317 readonly_data_section ();
9318 else if (TARGET_SOM
9319 && TREE_CODE (exp) == VAR_DECL
9320 && DECL_ONE_ONLY (exp)
9321 && !DECL_WEAK (exp)
9322 && DECL_INITIAL (exp))
9323 one_only_data_section ();
9324 else
9325 data_section ();
9328 static void
9329 pa_globalize_label (FILE *stream, const char *name)
9331 /* We only handle DATA objects here, functions are globalized in
9332 ASM_DECLARE_FUNCTION_NAME. */
9333 if (! FUNCTION_NAME_P (name))
9335 fputs ("\t.EXPORT ", stream);
9336 assemble_name (stream, name);
9337 fputs (",DATA\n", stream);
9341 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
9343 static rtx
9344 pa_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
9345 int incoming ATTRIBUTE_UNUSED)
9347 return gen_rtx_REG (Pmode, PA_STRUCT_VALUE_REGNUM);
9350 /* Worker function for TARGET_RETURN_IN_MEMORY. */
9352 bool
9353 pa_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
9355 /* SOM ABI says that objects larger than 64 bits are returned in memory.
9356 PA64 ABI says that objects larger than 128 bits are returned in memory.
9357 Note, int_size_in_bytes can return -1 if the size of the object is
9358 variable or larger than the maximum value that can be expressed as
9359 a HOST_WIDE_INT. It can also return zero for an empty type. The
9360 simplest way to handle variable and empty types is to pass them in
9361 memory. This avoids problems in defining the boundaries of argument
9362 slots, allocating registers, etc. */
9363 return (int_size_in_bytes (type) > (TARGET_64BIT ? 16 : 8)
9364 || int_size_in_bytes (type) <= 0);
9367 #include "gt-pa.h"