1 /* Definitions of target machine for GNU compiler.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by James E. Wilson <wilson@cygnus.com> and
5 David Mosberger <davidm@hpl.hp.com>.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to
21 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
26 #include "coretypes.h"
31 #include "hard-reg-set.h"
33 #include "insn-config.h"
34 #include "conditions.h"
36 #include "insn-attr.h"
44 #include "basic-block.h"
46 #include "sched-int.h"
49 #include "target-def.h"
52 #include "langhooks.h"
53 #include "cfglayout.h"
54 #include "tree-gimple.h"
57 /* This is used for communication between ASM_OUTPUT_LABEL and
58 ASM_OUTPUT_LABELREF. */
59 int ia64_asm_output_label = 0;
61 /* Define the information needed to generate branch and scc insns. This is
62 stored from the compare operation. */
63 struct rtx_def * ia64_compare_op0;
64 struct rtx_def * ia64_compare_op1;
66 /* Register names for ia64_expand_prologue. */
67 static const char * const ia64_reg_numbers[96] =
68 { "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
69 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
70 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
71 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
72 "r64", "r65", "r66", "r67", "r68", "r69", "r70", "r71",
73 "r72", "r73", "r74", "r75", "r76", "r77", "r78", "r79",
74 "r80", "r81", "r82", "r83", "r84", "r85", "r86", "r87",
75 "r88", "r89", "r90", "r91", "r92", "r93", "r94", "r95",
76 "r96", "r97", "r98", "r99", "r100","r101","r102","r103",
77 "r104","r105","r106","r107","r108","r109","r110","r111",
78 "r112","r113","r114","r115","r116","r117","r118","r119",
79 "r120","r121","r122","r123","r124","r125","r126","r127"};
81 /* ??? These strings could be shared with REGISTER_NAMES. */
82 static const char * const ia64_input_reg_names[8] =
83 { "in0", "in1", "in2", "in3", "in4", "in5", "in6", "in7" };
85 /* ??? These strings could be shared with REGISTER_NAMES. */
86 static const char * const ia64_local_reg_names[80] =
87 { "loc0", "loc1", "loc2", "loc3", "loc4", "loc5", "loc6", "loc7",
88 "loc8", "loc9", "loc10","loc11","loc12","loc13","loc14","loc15",
89 "loc16","loc17","loc18","loc19","loc20","loc21","loc22","loc23",
90 "loc24","loc25","loc26","loc27","loc28","loc29","loc30","loc31",
91 "loc32","loc33","loc34","loc35","loc36","loc37","loc38","loc39",
92 "loc40","loc41","loc42","loc43","loc44","loc45","loc46","loc47",
93 "loc48","loc49","loc50","loc51","loc52","loc53","loc54","loc55",
94 "loc56","loc57","loc58","loc59","loc60","loc61","loc62","loc63",
95 "loc64","loc65","loc66","loc67","loc68","loc69","loc70","loc71",
96 "loc72","loc73","loc74","loc75","loc76","loc77","loc78","loc79" };
98 /* ??? These strings could be shared with REGISTER_NAMES. */
99 static const char * const ia64_output_reg_names[8] =
100 { "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7" };
102 /* Which cpu are we scheduling for. */
103 enum processor_type ia64_tune = PROCESSOR_ITANIUM2;
105 /* Determines whether we run our final scheduling pass or not. We always
106 avoid the normal second scheduling pass. */
107 static int ia64_flag_schedule_insns2;
109 /* Determines whether we run variable tracking in machine dependent
111 static int ia64_flag_var_tracking;
113 /* Variables which are this size or smaller are put in the sdata/sbss
116 unsigned int ia64_section_threshold;
118 /* The following variable is used by the DFA insn scheduler. The value is
119 TRUE if we do insn bundling instead of insn scheduling. */
122 /* Structure to be filled in by ia64_compute_frame_size with register
123 save masks and offsets for the current function. */
125 struct ia64_frame_info
127 HOST_WIDE_INT total_size; /* size of the stack frame, not including
128 the caller's scratch area. */
129 HOST_WIDE_INT spill_cfa_off; /* top of the reg spill area from the cfa. */
130 HOST_WIDE_INT spill_size; /* size of the gr/br/fr spill area. */
131 HOST_WIDE_INT extra_spill_size; /* size of spill area for others. */
132 HARD_REG_SET mask; /* mask of saved registers. */
133 unsigned int gr_used_mask; /* mask of registers in use as gr spill
134 registers or long-term scratches. */
135 int n_spilled; /* number of spilled registers. */
136 int reg_fp; /* register for fp. */
137 int reg_save_b0; /* save register for b0. */
138 int reg_save_pr; /* save register for prs. */
139 int reg_save_ar_pfs; /* save register for ar.pfs. */
140 int reg_save_ar_unat; /* save register for ar.unat. */
141 int reg_save_ar_lc; /* save register for ar.lc. */
142 int reg_save_gp; /* save register for gp. */
143 int n_input_regs; /* number of input registers used. */
144 int n_local_regs; /* number of local registers used. */
145 int n_output_regs; /* number of output registers used. */
146 int n_rotate_regs; /* number of rotating registers used. */
148 char need_regstk; /* true if a .regstk directive needed. */
149 char initialized; /* true if the data is finalized. */
152 /* Current frame information calculated by ia64_compute_frame_size. */
153 static struct ia64_frame_info current_frame_info;
155 static int ia64_first_cycle_multipass_dfa_lookahead (void);
156 static void ia64_dependencies_evaluation_hook (rtx, rtx);
157 static void ia64_init_dfa_pre_cycle_insn (void);
158 static rtx ia64_dfa_pre_cycle_insn (void);
159 static int ia64_first_cycle_multipass_dfa_lookahead_guard (rtx);
160 static int ia64_dfa_new_cycle (FILE *, int, rtx, int, int, int *);
161 static rtx gen_tls_get_addr (void);
162 static rtx gen_thread_pointer (void);
163 static int find_gr_spill (int);
164 static int next_scratch_gr_reg (void);
165 static void mark_reg_gr_used_mask (rtx, void *);
166 static void ia64_compute_frame_size (HOST_WIDE_INT);
167 static void setup_spill_pointers (int, rtx, HOST_WIDE_INT);
168 static void finish_spill_pointers (void);
169 static rtx spill_restore_mem (rtx, HOST_WIDE_INT);
170 static void do_spill (rtx (*)(rtx, rtx, rtx), rtx, HOST_WIDE_INT, rtx);
171 static void do_restore (rtx (*)(rtx, rtx, rtx), rtx, HOST_WIDE_INT);
172 static rtx gen_movdi_x (rtx, rtx, rtx);
173 static rtx gen_fr_spill_x (rtx, rtx, rtx);
174 static rtx gen_fr_restore_x (rtx, rtx, rtx);
176 static enum machine_mode hfa_element_mode (tree, bool);
177 static void ia64_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
179 static bool ia64_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
181 static int ia64_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
183 static bool ia64_function_ok_for_sibcall (tree, tree);
184 static bool ia64_return_in_memory (tree, tree);
185 static bool ia64_rtx_costs (rtx, int, int, int *);
186 static void fix_range (const char *);
187 static bool ia64_handle_option (size_t, const char *, int);
188 static struct machine_function * ia64_init_machine_status (void);
189 static void emit_insn_group_barriers (FILE *);
190 static void emit_all_insn_group_barriers (FILE *);
191 static void final_emit_insn_group_barriers (FILE *);
192 static void emit_predicate_relation_info (void);
193 static void ia64_reorg (void);
194 static bool ia64_in_small_data_p (tree);
195 static void process_epilogue (void);
196 static int process_set (FILE *, rtx);
198 static bool ia64_assemble_integer (rtx, unsigned int, int);
199 static void ia64_output_function_prologue (FILE *, HOST_WIDE_INT);
200 static void ia64_output_function_epilogue (FILE *, HOST_WIDE_INT);
201 static void ia64_output_function_end_prologue (FILE *);
203 static int ia64_issue_rate (void);
204 static int ia64_adjust_cost (rtx, rtx, rtx, int);
205 static void ia64_sched_init (FILE *, int, int);
206 static void ia64_sched_finish (FILE *, int);
207 static int ia64_dfa_sched_reorder (FILE *, int, rtx *, int *, int, int);
208 static int ia64_sched_reorder (FILE *, int, rtx *, int *, int);
209 static int ia64_sched_reorder2 (FILE *, int, rtx *, int *, int);
210 static int ia64_variable_issue (FILE *, int, rtx, int);
212 static struct bundle_state *get_free_bundle_state (void);
213 static void free_bundle_state (struct bundle_state *);
214 static void initiate_bundle_states (void);
215 static void finish_bundle_states (void);
216 static unsigned bundle_state_hash (const void *);
217 static int bundle_state_eq_p (const void *, const void *);
218 static int insert_bundle_state (struct bundle_state *);
219 static void initiate_bundle_state_table (void);
220 static void finish_bundle_state_table (void);
221 static int try_issue_nops (struct bundle_state *, int);
222 static int try_issue_insn (struct bundle_state *, rtx);
223 static void issue_nops_and_insn (struct bundle_state *, int, rtx, int, int);
224 static int get_max_pos (state_t);
225 static int get_template (state_t, int);
227 static rtx get_next_important_insn (rtx, rtx);
228 static void bundling (FILE *, int, rtx, rtx);
230 static void ia64_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
231 HOST_WIDE_INT, tree);
232 static void ia64_file_start (void);
234 static void ia64_select_rtx_section (enum machine_mode, rtx,
235 unsigned HOST_WIDE_INT);
236 static void ia64_output_dwarf_dtprel (FILE *, int, rtx)
238 static void ia64_rwreloc_select_section (tree, int, unsigned HOST_WIDE_INT)
240 static void ia64_rwreloc_unique_section (tree, int)
242 static void ia64_rwreloc_select_rtx_section (enum machine_mode, rtx,
243 unsigned HOST_WIDE_INT)
245 static unsigned int ia64_section_type_flags (tree, const char *, int);
246 static void ia64_hpux_add_extern_decl (tree decl)
248 static void ia64_hpux_file_end (void)
250 static void ia64_init_libfuncs (void)
252 static void ia64_hpux_init_libfuncs (void)
254 static void ia64_sysv4_init_libfuncs (void)
256 static void ia64_vms_init_libfuncs (void)
259 static tree ia64_handle_model_attribute (tree *, tree, tree, int, bool *);
260 static void ia64_encode_section_info (tree, rtx, int);
261 static rtx ia64_struct_value_rtx (tree, int);
262 static tree ia64_gimplify_va_arg (tree, tree, tree *, tree *);
263 static bool ia64_scalar_mode_supported_p (enum machine_mode mode);
264 static bool ia64_vector_mode_supported_p (enum machine_mode mode);
265 static bool ia64_cannot_force_const_mem (rtx);
266 static const char *ia64_mangle_fundamental_type (tree);
267 static const char *ia64_invalid_conversion (tree, tree);
268 static const char *ia64_invalid_unary_op (int, tree);
269 static const char *ia64_invalid_binary_op (int, tree, tree);
271 /* Table of valid machine attributes. */
272 static const struct attribute_spec ia64_attribute_table[] =
274 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
275 { "syscall_linkage", 0, 0, false, true, true, NULL },
276 { "model", 1, 1, true, false, false, ia64_handle_model_attribute },
277 { NULL, 0, 0, false, false, false, NULL }
280 /* Initialize the GCC target structure. */
281 #undef TARGET_ATTRIBUTE_TABLE
282 #define TARGET_ATTRIBUTE_TABLE ia64_attribute_table
284 #undef TARGET_INIT_BUILTINS
285 #define TARGET_INIT_BUILTINS ia64_init_builtins
287 #undef TARGET_EXPAND_BUILTIN
288 #define TARGET_EXPAND_BUILTIN ia64_expand_builtin
290 #undef TARGET_ASM_BYTE_OP
291 #define TARGET_ASM_BYTE_OP "\tdata1\t"
292 #undef TARGET_ASM_ALIGNED_HI_OP
293 #define TARGET_ASM_ALIGNED_HI_OP "\tdata2\t"
294 #undef TARGET_ASM_ALIGNED_SI_OP
295 #define TARGET_ASM_ALIGNED_SI_OP "\tdata4\t"
296 #undef TARGET_ASM_ALIGNED_DI_OP
297 #define TARGET_ASM_ALIGNED_DI_OP "\tdata8\t"
298 #undef TARGET_ASM_UNALIGNED_HI_OP
299 #define TARGET_ASM_UNALIGNED_HI_OP "\tdata2.ua\t"
300 #undef TARGET_ASM_UNALIGNED_SI_OP
301 #define TARGET_ASM_UNALIGNED_SI_OP "\tdata4.ua\t"
302 #undef TARGET_ASM_UNALIGNED_DI_OP
303 #define TARGET_ASM_UNALIGNED_DI_OP "\tdata8.ua\t"
304 #undef TARGET_ASM_INTEGER
305 #define TARGET_ASM_INTEGER ia64_assemble_integer
307 #undef TARGET_ASM_FUNCTION_PROLOGUE
308 #define TARGET_ASM_FUNCTION_PROLOGUE ia64_output_function_prologue
309 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
310 #define TARGET_ASM_FUNCTION_END_PROLOGUE ia64_output_function_end_prologue
311 #undef TARGET_ASM_FUNCTION_EPILOGUE
312 #define TARGET_ASM_FUNCTION_EPILOGUE ia64_output_function_epilogue
314 #undef TARGET_IN_SMALL_DATA_P
315 #define TARGET_IN_SMALL_DATA_P ia64_in_small_data_p
317 #undef TARGET_SCHED_ADJUST_COST
318 #define TARGET_SCHED_ADJUST_COST ia64_adjust_cost
319 #undef TARGET_SCHED_ISSUE_RATE
320 #define TARGET_SCHED_ISSUE_RATE ia64_issue_rate
321 #undef TARGET_SCHED_VARIABLE_ISSUE
322 #define TARGET_SCHED_VARIABLE_ISSUE ia64_variable_issue
323 #undef TARGET_SCHED_INIT
324 #define TARGET_SCHED_INIT ia64_sched_init
325 #undef TARGET_SCHED_FINISH
326 #define TARGET_SCHED_FINISH ia64_sched_finish
327 #undef TARGET_SCHED_REORDER
328 #define TARGET_SCHED_REORDER ia64_sched_reorder
329 #undef TARGET_SCHED_REORDER2
330 #define TARGET_SCHED_REORDER2 ia64_sched_reorder2
332 #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
333 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK ia64_dependencies_evaluation_hook
335 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
336 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD ia64_first_cycle_multipass_dfa_lookahead
338 #undef TARGET_SCHED_INIT_DFA_PRE_CYCLE_INSN
339 #define TARGET_SCHED_INIT_DFA_PRE_CYCLE_INSN ia64_init_dfa_pre_cycle_insn
340 #undef TARGET_SCHED_DFA_PRE_CYCLE_INSN
341 #define TARGET_SCHED_DFA_PRE_CYCLE_INSN ia64_dfa_pre_cycle_insn
343 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD
344 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD\
345 ia64_first_cycle_multipass_dfa_lookahead_guard
347 #undef TARGET_SCHED_DFA_NEW_CYCLE
348 #define TARGET_SCHED_DFA_NEW_CYCLE ia64_dfa_new_cycle
350 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
351 #define TARGET_FUNCTION_OK_FOR_SIBCALL ia64_function_ok_for_sibcall
352 #undef TARGET_PASS_BY_REFERENCE
353 #define TARGET_PASS_BY_REFERENCE ia64_pass_by_reference
354 #undef TARGET_ARG_PARTIAL_BYTES
355 #define TARGET_ARG_PARTIAL_BYTES ia64_arg_partial_bytes
357 #undef TARGET_ASM_OUTPUT_MI_THUNK
358 #define TARGET_ASM_OUTPUT_MI_THUNK ia64_output_mi_thunk
359 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
360 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
362 #undef TARGET_ASM_FILE_START
363 #define TARGET_ASM_FILE_START ia64_file_start
365 #undef TARGET_RTX_COSTS
366 #define TARGET_RTX_COSTS ia64_rtx_costs
367 #undef TARGET_ADDRESS_COST
368 #define TARGET_ADDRESS_COST hook_int_rtx_0
370 #undef TARGET_MACHINE_DEPENDENT_REORG
371 #define TARGET_MACHINE_DEPENDENT_REORG ia64_reorg
373 #undef TARGET_ENCODE_SECTION_INFO
374 #define TARGET_ENCODE_SECTION_INFO ia64_encode_section_info
376 #undef TARGET_SECTION_TYPE_FLAGS
377 #define TARGET_SECTION_TYPE_FLAGS ia64_section_type_flags
380 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
381 #define TARGET_ASM_OUTPUT_DWARF_DTPREL ia64_output_dwarf_dtprel
384 /* ??? ABI doesn't allow us to define this. */
386 #undef TARGET_PROMOTE_FUNCTION_ARGS
387 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
390 /* ??? ABI doesn't allow us to define this. */
392 #undef TARGET_PROMOTE_FUNCTION_RETURN
393 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
396 /* ??? Investigate. */
398 #undef TARGET_PROMOTE_PROTOTYPES
399 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
402 #undef TARGET_STRUCT_VALUE_RTX
403 #define TARGET_STRUCT_VALUE_RTX ia64_struct_value_rtx
404 #undef TARGET_RETURN_IN_MEMORY
405 #define TARGET_RETURN_IN_MEMORY ia64_return_in_memory
406 #undef TARGET_SETUP_INCOMING_VARARGS
407 #define TARGET_SETUP_INCOMING_VARARGS ia64_setup_incoming_varargs
408 #undef TARGET_STRICT_ARGUMENT_NAMING
409 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
410 #undef TARGET_MUST_PASS_IN_STACK
411 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
413 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
414 #define TARGET_GIMPLIFY_VA_ARG_EXPR ia64_gimplify_va_arg
416 #undef TARGET_UNWIND_EMIT
417 #define TARGET_UNWIND_EMIT process_for_unwind_directive
419 #undef TARGET_SCALAR_MODE_SUPPORTED_P
420 #define TARGET_SCALAR_MODE_SUPPORTED_P ia64_scalar_mode_supported_p
421 #undef TARGET_VECTOR_MODE_SUPPORTED_P
422 #define TARGET_VECTOR_MODE_SUPPORTED_P ia64_vector_mode_supported_p
424 /* ia64 architecture manual 4.4.7: ... reads, writes, and flushes may occur
425 in an order different from the specified program order. */
426 #undef TARGET_RELAXED_ORDERING
427 #define TARGET_RELAXED_ORDERING true
429 #undef TARGET_DEFAULT_TARGET_FLAGS
430 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | TARGET_CPU_DEFAULT)
431 #undef TARGET_HANDLE_OPTION
432 #define TARGET_HANDLE_OPTION ia64_handle_option
434 #undef TARGET_CANNOT_FORCE_CONST_MEM
435 #define TARGET_CANNOT_FORCE_CONST_MEM ia64_cannot_force_const_mem
437 #undef TARGET_MANGLE_FUNDAMENTAL_TYPE
438 #define TARGET_MANGLE_FUNDAMENTAL_TYPE ia64_mangle_fundamental_type
440 #undef TARGET_INVALID_CONVERSION
441 #define TARGET_INVALID_CONVERSION ia64_invalid_conversion
442 #undef TARGET_INVALID_UNARY_OP
443 #define TARGET_INVALID_UNARY_OP ia64_invalid_unary_op
444 #undef TARGET_INVALID_BINARY_OP
445 #define TARGET_INVALID_BINARY_OP ia64_invalid_binary_op
447 struct gcc_target targetm = TARGET_INITIALIZER;
451 ADDR_AREA_NORMAL, /* normal address area */
452 ADDR_AREA_SMALL /* addressable by "addl" (-2MB < addr < 2MB) */
456 static GTY(()) tree small_ident1;
457 static GTY(()) tree small_ident2;
462 if (small_ident1 == 0)
464 small_ident1 = get_identifier ("small");
465 small_ident2 = get_identifier ("__small__");
469 /* Retrieve the address area that has been chosen for the given decl. */
471 static ia64_addr_area
472 ia64_get_addr_area (tree decl)
476 model_attr = lookup_attribute ("model", DECL_ATTRIBUTES (decl));
482 id = TREE_VALUE (TREE_VALUE (model_attr));
483 if (id == small_ident1 || id == small_ident2)
484 return ADDR_AREA_SMALL;
486 return ADDR_AREA_NORMAL;
490 ia64_handle_model_attribute (tree *node, tree name, tree args,
491 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
493 ia64_addr_area addr_area = ADDR_AREA_NORMAL;
495 tree arg, decl = *node;
498 arg = TREE_VALUE (args);
499 if (arg == small_ident1 || arg == small_ident2)
501 addr_area = ADDR_AREA_SMALL;
505 warning (OPT_Wattributes, "invalid argument of %qs attribute",
506 IDENTIFIER_POINTER (name));
507 *no_add_attrs = true;
510 switch (TREE_CODE (decl))
513 if ((DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl))
515 && !TREE_STATIC (decl))
517 error ("%Jan address area attribute cannot be specified for "
518 "local variables", decl);
519 *no_add_attrs = true;
521 area = ia64_get_addr_area (decl);
522 if (area != ADDR_AREA_NORMAL && addr_area != area)
524 error ("address area of %q+D conflicts with previous "
525 "declaration", decl);
526 *no_add_attrs = true;
531 error ("%Jaddress area attribute cannot be specified for functions",
533 *no_add_attrs = true;
537 warning (OPT_Wattributes, "%qs attribute ignored",
538 IDENTIFIER_POINTER (name));
539 *no_add_attrs = true;
547 ia64_encode_addr_area (tree decl, rtx symbol)
551 flags = SYMBOL_REF_FLAGS (symbol);
552 switch (ia64_get_addr_area (decl))
554 case ADDR_AREA_NORMAL: break;
555 case ADDR_AREA_SMALL: flags |= SYMBOL_FLAG_SMALL_ADDR; break;
556 default: gcc_unreachable ();
558 SYMBOL_REF_FLAGS (symbol) = flags;
562 ia64_encode_section_info (tree decl, rtx rtl, int first)
564 default_encode_section_info (decl, rtl, first);
566 /* Careful not to prod global register variables. */
567 if (TREE_CODE (decl) == VAR_DECL
568 && GET_CODE (DECL_RTL (decl)) == MEM
569 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF
570 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
571 ia64_encode_addr_area (decl, XEXP (rtl, 0));
574 /* Implement CONST_OK_FOR_LETTER_P. */
577 ia64_const_ok_for_letter_p (HOST_WIDE_INT value, char c)
582 return CONST_OK_FOR_I (value);
584 return CONST_OK_FOR_J (value);
586 return CONST_OK_FOR_K (value);
588 return CONST_OK_FOR_L (value);
590 return CONST_OK_FOR_M (value);
592 return CONST_OK_FOR_N (value);
594 return CONST_OK_FOR_O (value);
596 return CONST_OK_FOR_P (value);
602 /* Implement CONST_DOUBLE_OK_FOR_LETTER_P. */
605 ia64_const_double_ok_for_letter_p (rtx value, char c)
610 return CONST_DOUBLE_OK_FOR_G (value);
616 /* Implement EXTRA_CONSTRAINT. */
619 ia64_extra_constraint (rtx value, char c)
624 /* Non-volatile memory for FP_REG loads/stores. */
625 return memory_operand(value, VOIDmode) && !MEM_VOLATILE_P (value);
628 /* 1..4 for shladd arguments. */
629 return (GET_CODE (value) == CONST_INT
630 && INTVAL (value) >= 1 && INTVAL (value) <= 4);
633 /* Non-post-inc memory for asms and other unsavory creatures. */
634 return (GET_CODE (value) == MEM
635 && GET_RTX_CLASS (GET_CODE (XEXP (value, 0))) != RTX_AUTOINC
636 && (reload_in_progress || memory_operand (value, VOIDmode)));
639 /* Symbol ref to small-address-area. */
640 return small_addr_symbolic_operand (value, VOIDmode);
644 return value == CONST0_RTX (GET_MODE (value));
647 /* An integer vector, such that conversion to an integer yields a
648 value appropriate for an integer 'J' constraint. */
649 if (GET_CODE (value) == CONST_VECTOR
650 && GET_MODE_CLASS (GET_MODE (value)) == MODE_VECTOR_INT)
652 value = simplify_subreg (DImode, value, GET_MODE (value), 0);
653 return ia64_const_ok_for_letter_p (INTVAL (value), 'J');
658 /* A V2SF vector containing elements that satisfy 'G'. */
660 (GET_CODE (value) == CONST_VECTOR
661 && GET_MODE (value) == V2SFmode
662 && ia64_const_double_ok_for_letter_p (XVECEXP (value, 0, 0), 'G')
663 && ia64_const_double_ok_for_letter_p (XVECEXP (value, 0, 1), 'G'));
670 /* Return 1 if the operands of a move are ok. */
673 ia64_move_ok (rtx dst, rtx src)
675 /* If we're under init_recog_no_volatile, we'll not be able to use
676 memory_operand. So check the code directly and don't worry about
677 the validity of the underlying address, which should have been
678 checked elsewhere anyway. */
679 if (GET_CODE (dst) != MEM)
681 if (GET_CODE (src) == MEM)
683 if (register_operand (src, VOIDmode))
686 /* Otherwise, this must be a constant, and that either 0 or 0.0 or 1.0. */
687 if (INTEGRAL_MODE_P (GET_MODE (dst)))
688 return src == const0_rtx;
690 return GET_CODE (src) == CONST_DOUBLE && CONST_DOUBLE_OK_FOR_G (src);
694 addp4_optimize_ok (rtx op1, rtx op2)
696 return (basereg_operand (op1, GET_MODE(op1)) !=
697 basereg_operand (op2, GET_MODE(op2)));
700 /* Check if OP is a mask suitable for use with SHIFT in a dep.z instruction.
701 Return the length of the field, or <= 0 on failure. */
704 ia64_depz_field_mask (rtx rop, rtx rshift)
706 unsigned HOST_WIDE_INT op = INTVAL (rop);
707 unsigned HOST_WIDE_INT shift = INTVAL (rshift);
709 /* Get rid of the zero bits we're shifting in. */
712 /* We must now have a solid block of 1's at bit 0. */
713 return exact_log2 (op + 1);
716 /* Return the TLS model to use for ADDR. */
718 static enum tls_model
719 tls_symbolic_operand_type (rtx addr)
721 enum tls_model tls_kind = 0;
723 if (GET_CODE (addr) == CONST)
725 if (GET_CODE (XEXP (addr, 0)) == PLUS
726 && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF)
727 tls_kind = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (addr, 0), 0));
729 else if (GET_CODE (addr) == SYMBOL_REF)
730 tls_kind = SYMBOL_REF_TLS_MODEL (addr);
735 /* Return true if X is a constant that is valid for some immediate
736 field in an instruction. */
739 ia64_legitimate_constant_p (rtx x)
741 switch (GET_CODE (x))
748 if (GET_MODE (x) == VOIDmode)
750 return CONST_DOUBLE_OK_FOR_G (x);
754 return tls_symbolic_operand_type (x) == 0;
758 enum machine_mode mode = GET_MODE (x);
760 if (mode == V2SFmode)
761 return ia64_extra_constraint (x, 'Y');
763 return (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
764 && GET_MODE_SIZE (mode) <= 8);
772 /* Don't allow TLS addresses to get spilled to memory. */
775 ia64_cannot_force_const_mem (rtx x)
777 return tls_symbolic_operand_type (x) != 0;
780 /* Expand a symbolic constant load. */
783 ia64_expand_load_address (rtx dest, rtx src)
785 gcc_assert (GET_CODE (dest) == REG);
787 /* ILP32 mode still loads 64-bits of data from the GOT. This avoids
788 having to pointer-extend the value afterward. Other forms of address
789 computation below are also more natural to compute as 64-bit quantities.
790 If we've been given an SImode destination register, change it. */
791 if (GET_MODE (dest) != Pmode)
792 dest = gen_rtx_REG_offset (dest, Pmode, REGNO (dest), 0);
796 if (small_addr_symbolic_operand (src, VOIDmode))
800 emit_insn (gen_load_gprel64 (dest, src));
801 else if (GET_CODE (src) == SYMBOL_REF && SYMBOL_REF_FUNCTION_P (src))
802 emit_insn (gen_load_fptr (dest, src));
803 else if (sdata_symbolic_operand (src, VOIDmode))
804 emit_insn (gen_load_gprel (dest, src));
807 HOST_WIDE_INT addend = 0;
810 /* We did split constant offsets in ia64_expand_move, and we did try
811 to keep them split in move_operand, but we also allowed reload to
812 rematerialize arbitrary constants rather than spill the value to
813 the stack and reload it. So we have to be prepared here to split
815 if (GET_CODE (src) == CONST)
817 HOST_WIDE_INT hi, lo;
819 hi = INTVAL (XEXP (XEXP (src, 0), 1));
820 lo = ((hi & 0x3fff) ^ 0x2000) - 0x2000;
826 src = plus_constant (XEXP (XEXP (src, 0), 0), hi);
830 tmp = gen_rtx_HIGH (Pmode, src);
831 tmp = gen_rtx_PLUS (Pmode, tmp, pic_offset_table_rtx);
832 emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
834 tmp = gen_rtx_LO_SUM (Pmode, dest, src);
835 emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
839 tmp = gen_rtx_PLUS (Pmode, dest, GEN_INT (addend));
840 emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
847 static GTY(()) rtx gen_tls_tga;
849 gen_tls_get_addr (void)
852 gen_tls_tga = init_one_libfunc ("__tls_get_addr");
856 static GTY(()) rtx thread_pointer_rtx;
858 gen_thread_pointer (void)
860 if (!thread_pointer_rtx)
861 thread_pointer_rtx = gen_rtx_REG (Pmode, 13);
862 return thread_pointer_rtx;
866 ia64_expand_tls_address (enum tls_model tls_kind, rtx op0, rtx op1,
867 HOST_WIDE_INT addend)
869 rtx tga_op1, tga_op2, tga_ret, tga_eqv, tmp, insns;
870 rtx orig_op0 = op0, orig_op1 = op1;
871 HOST_WIDE_INT addend_lo, addend_hi;
873 addend_lo = ((addend & 0x3fff) ^ 0x2000) - 0x2000;
874 addend_hi = addend - addend_lo;
878 case TLS_MODEL_GLOBAL_DYNAMIC:
881 tga_op1 = gen_reg_rtx (Pmode);
882 emit_insn (gen_load_dtpmod (tga_op1, op1));
884 tga_op2 = gen_reg_rtx (Pmode);
885 emit_insn (gen_load_dtprel (tga_op2, op1));
887 tga_ret = emit_library_call_value (gen_tls_get_addr (), NULL_RTX,
888 LCT_CONST, Pmode, 2, tga_op1,
889 Pmode, tga_op2, Pmode);
891 insns = get_insns ();
894 if (GET_MODE (op0) != Pmode)
896 emit_libcall_block (insns, op0, tga_ret, op1);
899 case TLS_MODEL_LOCAL_DYNAMIC:
900 /* ??? This isn't the completely proper way to do local-dynamic
901 If the call to __tls_get_addr is used only by a single symbol,
902 then we should (somehow) move the dtprel to the second arg
903 to avoid the extra add. */
906 tga_op1 = gen_reg_rtx (Pmode);
907 emit_insn (gen_load_dtpmod (tga_op1, op1));
909 tga_op2 = const0_rtx;
911 tga_ret = emit_library_call_value (gen_tls_get_addr (), NULL_RTX,
912 LCT_CONST, Pmode, 2, tga_op1,
913 Pmode, tga_op2, Pmode);
915 insns = get_insns ();
918 tga_eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
920 tmp = gen_reg_rtx (Pmode);
921 emit_libcall_block (insns, tmp, tga_ret, tga_eqv);
923 if (!register_operand (op0, Pmode))
924 op0 = gen_reg_rtx (Pmode);
927 emit_insn (gen_load_dtprel (op0, op1));
928 emit_insn (gen_adddi3 (op0, tmp, op0));
931 emit_insn (gen_add_dtprel (op0, op1, tmp));
934 case TLS_MODEL_INITIAL_EXEC:
935 op1 = plus_constant (op1, addend_hi);
938 tmp = gen_reg_rtx (Pmode);
939 emit_insn (gen_load_tprel (tmp, op1));
941 if (!register_operand (op0, Pmode))
942 op0 = gen_reg_rtx (Pmode);
943 emit_insn (gen_adddi3 (op0, tmp, gen_thread_pointer ()));
946 case TLS_MODEL_LOCAL_EXEC:
947 if (!register_operand (op0, Pmode))
948 op0 = gen_reg_rtx (Pmode);
954 emit_insn (gen_load_tprel (op0, op1));
955 emit_insn (gen_adddi3 (op0, op0, gen_thread_pointer ()));
958 emit_insn (gen_add_tprel (op0, op1, gen_thread_pointer ()));
966 op0 = expand_simple_binop (Pmode, PLUS, op0, GEN_INT (addend),
967 orig_op0, 1, OPTAB_DIRECT);
970 if (GET_MODE (orig_op0) == Pmode)
972 return gen_lowpart (GET_MODE (orig_op0), op0);
976 ia64_expand_move (rtx op0, rtx op1)
978 enum machine_mode mode = GET_MODE (op0);
980 if (!reload_in_progress && !reload_completed && !ia64_move_ok (op0, op1))
981 op1 = force_reg (mode, op1);
983 if ((mode == Pmode || mode == ptr_mode) && symbolic_operand (op1, VOIDmode))
985 HOST_WIDE_INT addend = 0;
986 enum tls_model tls_kind;
989 if (GET_CODE (op1) == CONST
990 && GET_CODE (XEXP (op1, 0)) == PLUS
991 && GET_CODE (XEXP (XEXP (op1, 0), 1)) == CONST_INT)
993 addend = INTVAL (XEXP (XEXP (op1, 0), 1));
994 sym = XEXP (XEXP (op1, 0), 0);
997 tls_kind = tls_symbolic_operand_type (sym);
999 return ia64_expand_tls_address (tls_kind, op0, sym, addend);
1001 if (any_offset_symbol_operand (sym, mode))
1003 else if (aligned_offset_symbol_operand (sym, mode))
1005 HOST_WIDE_INT addend_lo, addend_hi;
1007 addend_lo = ((addend & 0x3fff) ^ 0x2000) - 0x2000;
1008 addend_hi = addend - addend_lo;
1012 op1 = plus_constant (sym, addend_hi);
1021 if (reload_completed)
1023 /* We really should have taken care of this offset earlier. */
1024 gcc_assert (addend == 0);
1025 if (ia64_expand_load_address (op0, op1))
1031 rtx subtarget = no_new_pseudos ? op0 : gen_reg_rtx (mode);
1033 emit_insn (gen_rtx_SET (VOIDmode, subtarget, op1));
1035 op1 = expand_simple_binop (mode, PLUS, subtarget,
1036 GEN_INT (addend), op0, 1, OPTAB_DIRECT);
1045 /* Split a move from OP1 to OP0 conditional on COND. */
1048 ia64_emit_cond_move (rtx op0, rtx op1, rtx cond)
1050 rtx insn, first = get_last_insn ();
1052 emit_move_insn (op0, op1);
1054 for (insn = get_last_insn (); insn != first; insn = PREV_INSN (insn))
1056 PATTERN (insn) = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond),
1060 /* Split a post-reload TImode or TFmode reference into two DImode
1061 components. This is made extra difficult by the fact that we do
1062 not get any scratch registers to work with, because reload cannot
1063 be prevented from giving us a scratch that overlaps the register
1064 pair involved. So instead, when addressing memory, we tweak the
1065 pointer register up and back down with POST_INCs. Or up and not
1066 back down when we can get away with it.
1068 REVERSED is true when the loads must be done in reversed order
1069 (high word first) for correctness. DEAD is true when the pointer
1070 dies with the second insn we generate and therefore the second
1071 address must not carry a postmodify.
1073 May return an insn which is to be emitted after the moves. */
1076 ia64_split_tmode (rtx out[2], rtx in, bool reversed, bool dead)
1080 switch (GET_CODE (in))
1083 out[reversed] = gen_rtx_REG (DImode, REGNO (in));
1084 out[!reversed] = gen_rtx_REG (DImode, REGNO (in) + 1);
1089 /* Cannot occur reversed. */
1090 gcc_assert (!reversed);
1092 if (GET_MODE (in) != TFmode)
1093 split_double (in, &out[0], &out[1]);
1095 /* split_double does not understand how to split a TFmode
1096 quantity into a pair of DImode constants. */
1099 unsigned HOST_WIDE_INT p[2];
1100 long l[4]; /* TFmode is 128 bits */
1102 REAL_VALUE_FROM_CONST_DOUBLE (r, in);
1103 real_to_target (l, &r, TFmode);
1105 if (FLOAT_WORDS_BIG_ENDIAN)
1107 p[0] = (((unsigned HOST_WIDE_INT) l[0]) << 32) + l[1];
1108 p[1] = (((unsigned HOST_WIDE_INT) l[2]) << 32) + l[3];
1112 p[0] = (((unsigned HOST_WIDE_INT) l[3]) << 32) + l[2];
1113 p[1] = (((unsigned HOST_WIDE_INT) l[1]) << 32) + l[0];
1115 out[0] = GEN_INT (p[0]);
1116 out[1] = GEN_INT (p[1]);
1122 rtx base = XEXP (in, 0);
1125 switch (GET_CODE (base))
1130 out[0] = adjust_automodify_address
1131 (in, DImode, gen_rtx_POST_INC (Pmode, base), 0);
1132 out[1] = adjust_automodify_address
1133 (in, DImode, dead ? 0 : gen_rtx_POST_DEC (Pmode, base), 8);
1137 /* Reversal requires a pre-increment, which can only
1138 be done as a separate insn. */
1139 emit_insn (gen_adddi3 (base, base, GEN_INT (8)));
1140 out[0] = adjust_automodify_address
1141 (in, DImode, gen_rtx_POST_DEC (Pmode, base), 8);
1142 out[1] = adjust_address (in, DImode, 0);
1147 gcc_assert (!reversed && !dead);
1149 /* Just do the increment in two steps. */
1150 out[0] = adjust_automodify_address (in, DImode, 0, 0);
1151 out[1] = adjust_automodify_address (in, DImode, 0, 8);
1155 gcc_assert (!reversed && !dead);
1157 /* Add 8, subtract 24. */
1158 base = XEXP (base, 0);
1159 out[0] = adjust_automodify_address
1160 (in, DImode, gen_rtx_POST_INC (Pmode, base), 0);
1161 out[1] = adjust_automodify_address
1163 gen_rtx_POST_MODIFY (Pmode, base, plus_constant (base, -24)),
1168 gcc_assert (!reversed && !dead);
1170 /* Extract and adjust the modification. This case is
1171 trickier than the others, because we might have an
1172 index register, or we might have a combined offset that
1173 doesn't fit a signed 9-bit displacement field. We can
1174 assume the incoming expression is already legitimate. */
1175 offset = XEXP (base, 1);
1176 base = XEXP (base, 0);
1178 out[0] = adjust_automodify_address
1179 (in, DImode, gen_rtx_POST_INC (Pmode, base), 0);
1181 if (GET_CODE (XEXP (offset, 1)) == REG)
1183 /* Can't adjust the postmodify to match. Emit the
1184 original, then a separate addition insn. */
1185 out[1] = adjust_automodify_address (in, DImode, 0, 8);
1186 fixup = gen_adddi3 (base, base, GEN_INT (-8));
1190 gcc_assert (GET_CODE (XEXP (offset, 1)) == CONST_INT);
1191 if (INTVAL (XEXP (offset, 1)) < -256 + 8)
1193 /* Again the postmodify cannot be made to match,
1194 but in this case it's more efficient to get rid
1195 of the postmodify entirely and fix up with an
1197 out[1] = adjust_automodify_address (in, DImode, base, 8);
1199 (base, base, GEN_INT (INTVAL (XEXP (offset, 1)) - 8));
1203 /* Combined offset still fits in the displacement field.
1204 (We cannot overflow it at the high end.) */
1205 out[1] = adjust_automodify_address
1206 (in, DImode, gen_rtx_POST_MODIFY
1207 (Pmode, base, gen_rtx_PLUS
1209 GEN_INT (INTVAL (XEXP (offset, 1)) - 8))),
1228 /* Split a TImode or TFmode move instruction after reload.
1229 This is used by *movtf_internal and *movti_internal. */
1231 ia64_split_tmode_move (rtx operands[])
1233 rtx in[2], out[2], insn;
1236 bool reversed = false;
1238 /* It is possible for reload to decide to overwrite a pointer with
1239 the value it points to. In that case we have to do the loads in
1240 the appropriate order so that the pointer is not destroyed too
1241 early. Also we must not generate a postmodify for that second
1242 load, or rws_access_regno will die. */
1243 if (GET_CODE (operands[1]) == MEM
1244 && reg_overlap_mentioned_p (operands[0], operands[1]))
1246 rtx base = XEXP (operands[1], 0);
1247 while (GET_CODE (base) != REG)
1248 base = XEXP (base, 0);
1250 if (REGNO (base) == REGNO (operands[0]))
1254 /* Another reason to do the moves in reversed order is if the first
1255 element of the target register pair is also the second element of
1256 the source register pair. */
1257 if (GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
1258 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
1261 fixup[0] = ia64_split_tmode (in, operands[1], reversed, dead);
1262 fixup[1] = ia64_split_tmode (out, operands[0], reversed, dead);
1264 #define MAYBE_ADD_REG_INC_NOTE(INSN, EXP) \
1265 if (GET_CODE (EXP) == MEM \
1266 && (GET_CODE (XEXP (EXP, 0)) == POST_MODIFY \
1267 || GET_CODE (XEXP (EXP, 0)) == POST_INC \
1268 || GET_CODE (XEXP (EXP, 0)) == POST_DEC)) \
1269 REG_NOTES (INSN) = gen_rtx_EXPR_LIST (REG_INC, \
1270 XEXP (XEXP (EXP, 0), 0), \
1273 insn = emit_insn (gen_rtx_SET (VOIDmode, out[0], in[0]));
1274 MAYBE_ADD_REG_INC_NOTE (insn, in[0]);
1275 MAYBE_ADD_REG_INC_NOTE (insn, out[0]);
1277 insn = emit_insn (gen_rtx_SET (VOIDmode, out[1], in[1]));
1278 MAYBE_ADD_REG_INC_NOTE (insn, in[1]);
1279 MAYBE_ADD_REG_INC_NOTE (insn, out[1]);
1282 emit_insn (fixup[0]);
1284 emit_insn (fixup[1]);
1286 #undef MAYBE_ADD_REG_INC_NOTE
1289 /* ??? Fixing GR->FR XFmode moves during reload is hard. You need to go
1290 through memory plus an extra GR scratch register. Except that you can
1291 either get the first from SECONDARY_MEMORY_NEEDED or the second from
1292 SECONDARY_RELOAD_CLASS, but not both.
1294 We got into problems in the first place by allowing a construct like
1295 (subreg:XF (reg:TI)), which we got from a union containing a long double.
1296 This solution attempts to prevent this situation from occurring. When
1297 we see something like the above, we spill the inner register to memory. */
1300 spill_xfmode_rfmode_operand (rtx in, int force, enum machine_mode mode)
1302 if (GET_CODE (in) == SUBREG
1303 && GET_MODE (SUBREG_REG (in)) == TImode
1304 && GET_CODE (SUBREG_REG (in)) == REG)
1306 rtx memt = assign_stack_temp (TImode, 16, 0);
1307 emit_move_insn (memt, SUBREG_REG (in));
1308 return adjust_address (memt, mode, 0);
1310 else if (force && GET_CODE (in) == REG)
1312 rtx memx = assign_stack_temp (mode, 16, 0);
1313 emit_move_insn (memx, in);
1320 /* Expand the movxf or movrf pattern (MODE says which) with the given
1321 OPERANDS, returning true if the pattern should then invoke
1325 ia64_expand_movxf_movrf (enum machine_mode mode, rtx operands[])
1327 rtx op0 = operands[0];
1329 if (GET_CODE (op0) == SUBREG)
1330 op0 = SUBREG_REG (op0);
1332 /* We must support XFmode loads into general registers for stdarg/vararg,
1333 unprototyped calls, and a rare case where a long double is passed as
1334 an argument after a float HFA fills the FP registers. We split them into
1335 DImode loads for convenience. We also need to support XFmode stores
1336 for the last case. This case does not happen for stdarg/vararg routines,
1337 because we do a block store to memory of unnamed arguments. */
1339 if (GET_CODE (op0) == REG && GR_REGNO_P (REGNO (op0)))
1343 /* We're hoping to transform everything that deals with XFmode
1344 quantities and GR registers early in the compiler. */
1345 gcc_assert (!no_new_pseudos);
1347 /* Struct to register can just use TImode instead. */
1348 if ((GET_CODE (operands[1]) == SUBREG
1349 && GET_MODE (SUBREG_REG (operands[1])) == TImode)
1350 || (GET_CODE (operands[1]) == REG
1351 && GR_REGNO_P (REGNO (operands[1]))))
1353 rtx op1 = operands[1];
1355 if (GET_CODE (op1) == SUBREG)
1356 op1 = SUBREG_REG (op1);
1358 op1 = gen_rtx_REG (TImode, REGNO (op1));
1360 emit_move_insn (gen_rtx_REG (TImode, REGNO (op0)), op1);
1364 if (GET_CODE (operands[1]) == CONST_DOUBLE)
1366 emit_move_insn (gen_rtx_REG (DImode, REGNO (op0)),
1367 operand_subword (operands[1], 0, 0, mode));
1368 emit_move_insn (gen_rtx_REG (DImode, REGNO (op0) + 1),
1369 operand_subword (operands[1], 1, 0, mode));
1373 /* If the quantity is in a register not known to be GR, spill it. */
1374 if (register_operand (operands[1], mode))
1375 operands[1] = spill_xfmode_rfmode_operand (operands[1], 1, mode);
1377 gcc_assert (GET_CODE (operands[1]) == MEM);
1379 out[WORDS_BIG_ENDIAN] = gen_rtx_REG (DImode, REGNO (op0));
1380 out[!WORDS_BIG_ENDIAN] = gen_rtx_REG (DImode, REGNO (op0) + 1);
1382 emit_move_insn (out[0], adjust_address (operands[1], DImode, 0));
1383 emit_move_insn (out[1], adjust_address (operands[1], DImode, 8));
1387 if (GET_CODE (operands[1]) == REG && GR_REGNO_P (REGNO (operands[1])))
1389 /* We're hoping to transform everything that deals with XFmode
1390 quantities and GR registers early in the compiler. */
1391 gcc_assert (!no_new_pseudos);
1393 /* Op0 can't be a GR_REG here, as that case is handled above.
1394 If op0 is a register, then we spill op1, so that we now have a
1395 MEM operand. This requires creating an XFmode subreg of a TImode reg
1396 to force the spill. */
1397 if (register_operand (operands[0], mode))
1399 rtx op1 = gen_rtx_REG (TImode, REGNO (operands[1]));
1400 op1 = gen_rtx_SUBREG (mode, op1, 0);
1401 operands[1] = spill_xfmode_rfmode_operand (op1, 0, mode);
1408 gcc_assert (GET_CODE (operands[0]) == MEM);
1409 in[WORDS_BIG_ENDIAN] = gen_rtx_REG (DImode, REGNO (operands[1]));
1410 in[!WORDS_BIG_ENDIAN] = gen_rtx_REG (DImode, REGNO (operands[1]) + 1);
1412 emit_move_insn (adjust_address (operands[0], DImode, 0), in[0]);
1413 emit_move_insn (adjust_address (operands[0], DImode, 8), in[1]);
1418 if (!reload_in_progress && !reload_completed)
1420 operands[1] = spill_xfmode_rfmode_operand (operands[1], 0, mode);
1422 if (GET_MODE (op0) == TImode && GET_CODE (op0) == REG)
1424 rtx memt, memx, in = operands[1];
1425 if (CONSTANT_P (in))
1426 in = validize_mem (force_const_mem (mode, in));
1427 if (GET_CODE (in) == MEM)
1428 memt = adjust_address (in, TImode, 0);
1431 memt = assign_stack_temp (TImode, 16, 0);
1432 memx = adjust_address (memt, mode, 0);
1433 emit_move_insn (memx, in);
1435 emit_move_insn (op0, memt);
1439 if (!ia64_move_ok (operands[0], operands[1]))
1440 operands[1] = force_reg (mode, operands[1]);
1446 /* Emit comparison instruction if necessary, returning the expression
1447 that holds the compare result in the proper mode. */
1449 static GTY(()) rtx cmptf_libfunc;
1452 ia64_expand_compare (enum rtx_code code, enum machine_mode mode)
1454 rtx op0 = ia64_compare_op0, op1 = ia64_compare_op1;
1457 /* If we have a BImode input, then we already have a compare result, and
1458 do not need to emit another comparison. */
1459 if (GET_MODE (op0) == BImode)
1461 gcc_assert ((code == NE || code == EQ) && op1 == const0_rtx);
1464 /* HPUX TFmode compare requires a library call to _U_Qfcmp, which takes a
1465 magic number as its third argument, that indicates what to do.
1466 The return value is an integer to be compared against zero. */
1467 else if (GET_MODE (op0) == TFmode)
1470 QCMP_INV = 1, /* Raise FP_INVALID on SNaN as a side effect. */
1476 enum rtx_code ncode;
1479 gcc_assert (cmptf_libfunc && GET_MODE (op1) == TFmode);
1482 /* 1 = equal, 0 = not equal. Equality operators do
1483 not raise FP_INVALID when given an SNaN operand. */
1484 case EQ: magic = QCMP_EQ; ncode = NE; break;
1485 case NE: magic = QCMP_EQ; ncode = EQ; break;
1486 /* isunordered() from C99. */
1487 case UNORDERED: magic = QCMP_UNORD; ncode = NE; break;
1488 case ORDERED: magic = QCMP_UNORD; ncode = EQ; break;
1489 /* Relational operators raise FP_INVALID when given
1491 case LT: magic = QCMP_LT |QCMP_INV; ncode = NE; break;
1492 case LE: magic = QCMP_LT|QCMP_EQ|QCMP_INV; ncode = NE; break;
1493 case GT: magic = QCMP_GT |QCMP_INV; ncode = NE; break;
1494 case GE: magic = QCMP_GT|QCMP_EQ|QCMP_INV; ncode = NE; break;
1495 /* FUTURE: Implement UNEQ, UNLT, UNLE, UNGT, UNGE, LTGT.
1496 Expanders for buneq etc. weuld have to be added to ia64.md
1497 for this to be useful. */
1498 default: gcc_unreachable ();
1503 ret = emit_library_call_value (cmptf_libfunc, 0, LCT_CONST, DImode, 3,
1504 op0, TFmode, op1, TFmode,
1505 GEN_INT (magic), DImode);
1506 cmp = gen_reg_rtx (BImode);
1507 emit_insn (gen_rtx_SET (VOIDmode, cmp,
1508 gen_rtx_fmt_ee (ncode, BImode,
1511 insns = get_insns ();
1514 emit_libcall_block (insns, cmp, cmp,
1515 gen_rtx_fmt_ee (code, BImode, op0, op1));
1520 cmp = gen_reg_rtx (BImode);
1521 emit_insn (gen_rtx_SET (VOIDmode, cmp,
1522 gen_rtx_fmt_ee (code, BImode, op0, op1)));
1526 return gen_rtx_fmt_ee (code, mode, cmp, const0_rtx);
1529 /* Generate an integral vector comparison. Return true if the condition has
1530 been reversed, and so the sense of the comparison should be inverted. */
1533 ia64_expand_vecint_compare (enum rtx_code code, enum machine_mode mode,
1534 rtx dest, rtx op0, rtx op1)
1536 bool negate = false;
1539 /* Canonicalize the comparison to EQ, GT, GTU. */
1550 code = reverse_condition (code);
1556 code = reverse_condition (code);
1562 code = swap_condition (code);
1563 x = op0, op0 = op1, op1 = x;
1570 /* Unsigned parallel compare is not supported by the hardware. Play some
1571 tricks to turn this into a signed comparison against 0. */
1580 /* Perform a parallel modulo subtraction. */
1581 t1 = gen_reg_rtx (V2SImode);
1582 emit_insn (gen_subv2si3 (t1, op0, op1));
1584 /* Extract the original sign bit of op0. */
1585 mask = GEN_INT (-0x80000000);
1586 mask = gen_rtx_CONST_VECTOR (V2SImode, gen_rtvec (2, mask, mask));
1587 mask = force_reg (V2SImode, mask);
1588 t2 = gen_reg_rtx (V2SImode);
1589 emit_insn (gen_andv2si3 (t2, op0, mask));
1591 /* XOR it back into the result of the subtraction. This results
1592 in the sign bit set iff we saw unsigned underflow. */
1593 x = gen_reg_rtx (V2SImode);
1594 emit_insn (gen_xorv2si3 (x, t1, t2));
1598 op1 = CONST0_RTX (mode);
1604 /* Perform a parallel unsigned saturating subtraction. */
1605 x = gen_reg_rtx (mode);
1606 emit_insn (gen_rtx_SET (VOIDmode, x,
1607 gen_rtx_US_MINUS (mode, op0, op1)));
1611 op1 = CONST0_RTX (mode);
1620 x = gen_rtx_fmt_ee (code, mode, op0, op1);
1621 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
1626 /* Emit an integral vector conditional move. */
1629 ia64_expand_vecint_cmov (rtx operands[])
1631 enum machine_mode mode = GET_MODE (operands[0]);
1632 enum rtx_code code = GET_CODE (operands[3]);
1636 cmp = gen_reg_rtx (mode);
1637 negate = ia64_expand_vecint_compare (code, mode, cmp,
1638 operands[4], operands[5]);
1640 ot = operands[1+negate];
1641 of = operands[2-negate];
1643 if (ot == CONST0_RTX (mode))
1645 if (of == CONST0_RTX (mode))
1647 emit_move_insn (operands[0], ot);
1651 x = gen_rtx_NOT (mode, cmp);
1652 x = gen_rtx_AND (mode, x, of);
1653 emit_insn (gen_rtx_SET (VOIDmode, operands[0], x));
1655 else if (of == CONST0_RTX (mode))
1657 x = gen_rtx_AND (mode, cmp, ot);
1658 emit_insn (gen_rtx_SET (VOIDmode, operands[0], x));
1664 t = gen_reg_rtx (mode);
1665 x = gen_rtx_AND (mode, cmp, operands[1+negate]);
1666 emit_insn (gen_rtx_SET (VOIDmode, t, x));
1668 f = gen_reg_rtx (mode);
1669 x = gen_rtx_NOT (mode, cmp);
1670 x = gen_rtx_AND (mode, x, operands[2-negate]);
1671 emit_insn (gen_rtx_SET (VOIDmode, f, x));
1673 x = gen_rtx_IOR (mode, t, f);
1674 emit_insn (gen_rtx_SET (VOIDmode, operands[0], x));
1678 /* Emit an integral vector min or max operation. Return true if all done. */
1681 ia64_expand_vecint_minmax (enum rtx_code code, enum machine_mode mode,
1686 /* These four combinations are supported directly. */
1687 if (mode == V8QImode && (code == UMIN || code == UMAX))
1689 if (mode == V4HImode && (code == SMIN || code == SMAX))
1692 /* This combination can be implemented with only saturating subtraction. */
1693 if (mode == V4HImode && code == UMAX)
1695 rtx x, tmp = gen_reg_rtx (mode);
1697 x = gen_rtx_US_MINUS (mode, operands[1], operands[2]);
1698 emit_insn (gen_rtx_SET (VOIDmode, tmp, x));
1700 emit_insn (gen_addv4hi3 (operands[0], tmp, operands[2]));
1704 /* Everything else implemented via vector comparisons. */
1705 xops[0] = operands[0];
1706 xops[4] = xops[1] = operands[1];
1707 xops[5] = xops[2] = operands[2];
1726 xops[3] = gen_rtx_fmt_ee (code, VOIDmode, operands[1], operands[2]);
1728 ia64_expand_vecint_cmov (xops);
1732 /* Emit the appropriate sequence for a call. */
1735 ia64_expand_call (rtx retval, rtx addr, rtx nextarg ATTRIBUTE_UNUSED,
1740 addr = XEXP (addr, 0);
1741 addr = convert_memory_address (DImode, addr);
1742 b0 = gen_rtx_REG (DImode, R_BR (0));
1744 /* ??? Should do this for functions known to bind local too. */
1745 if (TARGET_NO_PIC || TARGET_AUTO_PIC)
1748 insn = gen_sibcall_nogp (addr);
1750 insn = gen_call_nogp (addr, b0);
1752 insn = gen_call_value_nogp (retval, addr, b0);
1753 insn = emit_call_insn (insn);
1758 insn = gen_sibcall_gp (addr);
1760 insn = gen_call_gp (addr, b0);
1762 insn = gen_call_value_gp (retval, addr, b0);
1763 insn = emit_call_insn (insn);
1765 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
1769 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), b0);
1773 ia64_reload_gp (void)
1777 if (current_frame_info.reg_save_gp)
1778 tmp = gen_rtx_REG (DImode, current_frame_info.reg_save_gp);
1781 HOST_WIDE_INT offset;
1783 offset = (current_frame_info.spill_cfa_off
1784 + current_frame_info.spill_size);
1785 if (frame_pointer_needed)
1787 tmp = hard_frame_pointer_rtx;
1792 tmp = stack_pointer_rtx;
1793 offset = current_frame_info.total_size - offset;
1796 if (CONST_OK_FOR_I (offset))
1797 emit_insn (gen_adddi3 (pic_offset_table_rtx,
1798 tmp, GEN_INT (offset)));
1801 emit_move_insn (pic_offset_table_rtx, GEN_INT (offset));
1802 emit_insn (gen_adddi3 (pic_offset_table_rtx,
1803 pic_offset_table_rtx, tmp));
1806 tmp = gen_rtx_MEM (DImode, pic_offset_table_rtx);
1809 emit_move_insn (pic_offset_table_rtx, tmp);
1813 ia64_split_call (rtx retval, rtx addr, rtx retaddr, rtx scratch_r,
1814 rtx scratch_b, int noreturn_p, int sibcall_p)
1817 bool is_desc = false;
1819 /* If we find we're calling through a register, then we're actually
1820 calling through a descriptor, so load up the values. */
1821 if (REG_P (addr) && GR_REGNO_P (REGNO (addr)))
1826 /* ??? We are currently constrained to *not* use peep2, because
1827 we can legitimately change the global lifetime of the GP
1828 (in the form of killing where previously live). This is
1829 because a call through a descriptor doesn't use the previous
1830 value of the GP, while a direct call does, and we do not
1831 commit to either form until the split here.
1833 That said, this means that we lack precise life info for
1834 whether ADDR is dead after this call. This is not terribly
1835 important, since we can fix things up essentially for free
1836 with the POST_DEC below, but it's nice to not use it when we
1837 can immediately tell it's not necessary. */
1838 addr_dead_p = ((noreturn_p || sibcall_p
1839 || TEST_HARD_REG_BIT (regs_invalidated_by_call,
1841 && !FUNCTION_ARG_REGNO_P (REGNO (addr)));
1843 /* Load the code address into scratch_b. */
1844 tmp = gen_rtx_POST_INC (Pmode, addr);
1845 tmp = gen_rtx_MEM (Pmode, tmp);
1846 emit_move_insn (scratch_r, tmp);
1847 emit_move_insn (scratch_b, scratch_r);
1849 /* Load the GP address. If ADDR is not dead here, then we must
1850 revert the change made above via the POST_INCREMENT. */
1852 tmp = gen_rtx_POST_DEC (Pmode, addr);
1855 tmp = gen_rtx_MEM (Pmode, tmp);
1856 emit_move_insn (pic_offset_table_rtx, tmp);
1863 insn = gen_sibcall_nogp (addr);
1865 insn = gen_call_value_nogp (retval, addr, retaddr);
1867 insn = gen_call_nogp (addr, retaddr);
1868 emit_call_insn (insn);
1870 if ((!TARGET_CONST_GP || is_desc) && !noreturn_p && !sibcall_p)
1874 /* Expand an atomic operation. We want to perform MEM <CODE>= VAL atomically.
1876 This differs from the generic code in that we know about the zero-extending
1877 properties of cmpxchg, and the zero-extending requirements of ar.ccv. We
1878 also know that ld.acq+cmpxchg.rel equals a full barrier.
1880 The loop we want to generate looks like
1885 new_reg = cmp_reg op val;
1886 cmp_reg = compare-and-swap(mem, old_reg, new_reg)
1887 if (cmp_reg != old_reg)
1890 Note that we only do the plain load from memory once. Subsequent
1891 iterations use the value loaded by the compare-and-swap pattern. */
1894 ia64_expand_atomic_op (enum rtx_code code, rtx mem, rtx val,
1895 rtx old_dst, rtx new_dst)
1897 enum machine_mode mode = GET_MODE (mem);
1898 rtx old_reg, new_reg, cmp_reg, ar_ccv, label;
1899 enum insn_code icode;
1901 /* Special case for using fetchadd. */
1902 if ((mode == SImode || mode == DImode) && fetchadd_operand (val, mode))
1905 old_dst = gen_reg_rtx (mode);
1907 emit_insn (gen_memory_barrier ());
1910 icode = CODE_FOR_fetchadd_acq_si;
1912 icode = CODE_FOR_fetchadd_acq_di;
1913 emit_insn (GEN_FCN (icode) (old_dst, mem, val));
1917 new_reg = expand_simple_binop (mode, PLUS, old_dst, val, new_dst,
1919 if (new_reg != new_dst)
1920 emit_move_insn (new_dst, new_reg);
1925 /* Because of the volatile mem read, we get an ld.acq, which is the
1926 front half of the full barrier. The end half is the cmpxchg.rel. */
1927 gcc_assert (MEM_VOLATILE_P (mem));
1929 old_reg = gen_reg_rtx (DImode);
1930 cmp_reg = gen_reg_rtx (DImode);
1931 label = gen_label_rtx ();
1935 val = simplify_gen_subreg (DImode, val, mode, 0);
1936 emit_insn (gen_extend_insn (cmp_reg, mem, DImode, mode, 1));
1939 emit_move_insn (cmp_reg, mem);
1943 ar_ccv = gen_rtx_REG (DImode, AR_CCV_REGNUM);
1944 emit_move_insn (old_reg, cmp_reg);
1945 emit_move_insn (ar_ccv, cmp_reg);
1948 emit_move_insn (old_dst, gen_lowpart (mode, cmp_reg));
1953 new_reg = expand_simple_unop (DImode, NOT, new_reg, NULL_RTX, true);
1956 new_reg = expand_simple_binop (DImode, code, new_reg, val, NULL_RTX,
1957 true, OPTAB_DIRECT);
1960 new_reg = gen_lowpart (mode, new_reg);
1962 emit_move_insn (new_dst, new_reg);
1966 case QImode: icode = CODE_FOR_cmpxchg_rel_qi; break;
1967 case HImode: icode = CODE_FOR_cmpxchg_rel_hi; break;
1968 case SImode: icode = CODE_FOR_cmpxchg_rel_si; break;
1969 case DImode: icode = CODE_FOR_cmpxchg_rel_di; break;
1974 emit_insn (GEN_FCN (icode) (cmp_reg, mem, ar_ccv, new_reg));
1976 emit_cmp_and_jump_insns (cmp_reg, old_reg, EQ, NULL, DImode, true, label);
1979 /* Begin the assembly file. */
1982 ia64_file_start (void)
1984 /* Variable tracking should be run after all optimizations which change order
1985 of insns. It also needs a valid CFG. This can't be done in
1986 ia64_override_options, because flag_var_tracking is finalized after
1988 ia64_flag_var_tracking = flag_var_tracking;
1989 flag_var_tracking = 0;
1991 default_file_start ();
1992 emit_safe_across_calls ();
1996 emit_safe_across_calls (void)
1998 unsigned int rs, re;
2005 while (rs < 64 && call_used_regs[PR_REG (rs)])
2009 for (re = rs + 1; re < 64 && ! call_used_regs[PR_REG (re)]; re++)
2013 fputs ("\t.pred.safe_across_calls ", asm_out_file);
2017 fputc (',', asm_out_file);
2019 fprintf (asm_out_file, "p%u", rs);
2021 fprintf (asm_out_file, "p%u-p%u", rs, re - 1);
2025 fputc ('\n', asm_out_file);
2028 /* Helper function for ia64_compute_frame_size: find an appropriate general
2029 register to spill some special register to. SPECIAL_SPILL_MASK contains
2030 bits in GR0 to GR31 that have already been allocated by this routine.
2031 TRY_LOCALS is true if we should attempt to locate a local regnum. */
2034 find_gr_spill (int try_locals)
2038 /* If this is a leaf function, first try an otherwise unused
2039 call-clobbered register. */
2040 if (current_function_is_leaf)
2042 for (regno = GR_REG (1); regno <= GR_REG (31); regno++)
2043 if (! regs_ever_live[regno]
2044 && call_used_regs[regno]
2045 && ! fixed_regs[regno]
2046 && ! global_regs[regno]
2047 && ((current_frame_info.gr_used_mask >> regno) & 1) == 0)
2049 current_frame_info.gr_used_mask |= 1 << regno;
2056 regno = current_frame_info.n_local_regs;
2057 /* If there is a frame pointer, then we can't use loc79, because
2058 that is HARD_FRAME_POINTER_REGNUM. In particular, see the
2059 reg_name switching code in ia64_expand_prologue. */
2060 if (regno < (80 - frame_pointer_needed))
2062 current_frame_info.n_local_regs = regno + 1;
2063 return LOC_REG (0) + regno;
2067 /* Failed to find a general register to spill to. Must use stack. */
2071 /* In order to make for nice schedules, we try to allocate every temporary
2072 to a different register. We must of course stay away from call-saved,
2073 fixed, and global registers. We must also stay away from registers
2074 allocated in current_frame_info.gr_used_mask, since those include regs
2075 used all through the prologue.
2077 Any register allocated here must be used immediately. The idea is to
2078 aid scheduling, not to solve data flow problems. */
2080 static int last_scratch_gr_reg;
2083 next_scratch_gr_reg (void)
2087 for (i = 0; i < 32; ++i)
2089 regno = (last_scratch_gr_reg + i + 1) & 31;
2090 if (call_used_regs[regno]
2091 && ! fixed_regs[regno]
2092 && ! global_regs[regno]
2093 && ((current_frame_info.gr_used_mask >> regno) & 1) == 0)
2095 last_scratch_gr_reg = regno;
2100 /* There must be _something_ available. */
2104 /* Helper function for ia64_compute_frame_size, called through
2105 diddle_return_value. Mark REG in current_frame_info.gr_used_mask. */
2108 mark_reg_gr_used_mask (rtx reg, void *data ATTRIBUTE_UNUSED)
2110 unsigned int regno = REGNO (reg);
2113 unsigned int i, n = hard_regno_nregs[regno][GET_MODE (reg)];
2114 for (i = 0; i < n; ++i)
2115 current_frame_info.gr_used_mask |= 1 << (regno + i);
2119 /* Returns the number of bytes offset between the frame pointer and the stack
2120 pointer for the current function. SIZE is the number of bytes of space
2121 needed for local variables. */
2124 ia64_compute_frame_size (HOST_WIDE_INT size)
2126 HOST_WIDE_INT total_size;
2127 HOST_WIDE_INT spill_size = 0;
2128 HOST_WIDE_INT extra_spill_size = 0;
2129 HOST_WIDE_INT pretend_args_size;
2132 int spilled_gr_p = 0;
2133 int spilled_fr_p = 0;
2137 if (current_frame_info.initialized)
2140 memset (¤t_frame_info, 0, sizeof current_frame_info);
2141 CLEAR_HARD_REG_SET (mask);
2143 /* Don't allocate scratches to the return register. */
2144 diddle_return_value (mark_reg_gr_used_mask, NULL);
2146 /* Don't allocate scratches to the EH scratch registers. */
2147 if (cfun->machine->ia64_eh_epilogue_sp)
2148 mark_reg_gr_used_mask (cfun->machine->ia64_eh_epilogue_sp, NULL);
2149 if (cfun->machine->ia64_eh_epilogue_bsp)
2150 mark_reg_gr_used_mask (cfun->machine->ia64_eh_epilogue_bsp, NULL);
2152 /* Find the size of the register stack frame. We have only 80 local
2153 registers, because we reserve 8 for the inputs and 8 for the
2156 /* Skip HARD_FRAME_POINTER_REGNUM (loc79) when frame_pointer_needed,
2157 since we'll be adjusting that down later. */
2158 regno = LOC_REG (78) + ! frame_pointer_needed;
2159 for (; regno >= LOC_REG (0); regno--)
2160 if (regs_ever_live[regno])
2162 current_frame_info.n_local_regs = regno - LOC_REG (0) + 1;
2164 /* For functions marked with the syscall_linkage attribute, we must mark
2165 all eight input registers as in use, so that locals aren't visible to
2168 if (cfun->machine->n_varargs > 0
2169 || lookup_attribute ("syscall_linkage",
2170 TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
2171 current_frame_info.n_input_regs = 8;
2174 for (regno = IN_REG (7); regno >= IN_REG (0); regno--)
2175 if (regs_ever_live[regno])
2177 current_frame_info.n_input_regs = regno - IN_REG (0) + 1;
2180 for (regno = OUT_REG (7); regno >= OUT_REG (0); regno--)
2181 if (regs_ever_live[regno])
2183 i = regno - OUT_REG (0) + 1;
2185 #ifndef PROFILE_HOOK
2186 /* When -p profiling, we need one output register for the mcount argument.
2187 Likewise for -a profiling for the bb_init_func argument. For -ax
2188 profiling, we need two output registers for the two bb_init_trace_func
2190 if (current_function_profile)
2193 current_frame_info.n_output_regs = i;
2195 /* ??? No rotating register support yet. */
2196 current_frame_info.n_rotate_regs = 0;
2198 /* Discover which registers need spilling, and how much room that
2199 will take. Begin with floating point and general registers,
2200 which will always wind up on the stack. */
2202 for (regno = FR_REG (2); regno <= FR_REG (127); regno++)
2203 if (regs_ever_live[regno] && ! call_used_regs[regno])
2205 SET_HARD_REG_BIT (mask, regno);
2211 for (regno = GR_REG (1); regno <= GR_REG (31); regno++)
2212 if (regs_ever_live[regno] && ! call_used_regs[regno])
2214 SET_HARD_REG_BIT (mask, regno);
2220 for (regno = BR_REG (1); regno <= BR_REG (7); regno++)
2221 if (regs_ever_live[regno] && ! call_used_regs[regno])
2223 SET_HARD_REG_BIT (mask, regno);
2228 /* Now come all special registers that might get saved in other
2229 general registers. */
2231 if (frame_pointer_needed)
2233 current_frame_info.reg_fp = find_gr_spill (1);
2234 /* If we did not get a register, then we take LOC79. This is guaranteed
2235 to be free, even if regs_ever_live is already set, because this is
2236 HARD_FRAME_POINTER_REGNUM. This requires incrementing n_local_regs,
2237 as we don't count loc79 above. */
2238 if (current_frame_info.reg_fp == 0)
2240 current_frame_info.reg_fp = LOC_REG (79);
2241 current_frame_info.n_local_regs++;
2245 if (! current_function_is_leaf)
2247 /* Emit a save of BR0 if we call other functions. Do this even
2248 if this function doesn't return, as EH depends on this to be
2249 able to unwind the stack. */
2250 SET_HARD_REG_BIT (mask, BR_REG (0));
2252 current_frame_info.reg_save_b0 = find_gr_spill (1);
2253 if (current_frame_info.reg_save_b0 == 0)
2259 /* Similarly for ar.pfs. */
2260 SET_HARD_REG_BIT (mask, AR_PFS_REGNUM);
2261 current_frame_info.reg_save_ar_pfs = find_gr_spill (1);
2262 if (current_frame_info.reg_save_ar_pfs == 0)
2264 extra_spill_size += 8;
2268 /* Similarly for gp. Note that if we're calling setjmp, the stacked
2269 registers are clobbered, so we fall back to the stack. */
2270 current_frame_info.reg_save_gp
2271 = (current_function_calls_setjmp ? 0 : find_gr_spill (1));
2272 if (current_frame_info.reg_save_gp == 0)
2274 SET_HARD_REG_BIT (mask, GR_REG (1));
2281 if (regs_ever_live[BR_REG (0)] && ! call_used_regs[BR_REG (0)])
2283 SET_HARD_REG_BIT (mask, BR_REG (0));
2288 if (regs_ever_live[AR_PFS_REGNUM])
2290 SET_HARD_REG_BIT (mask, AR_PFS_REGNUM);
2291 current_frame_info.reg_save_ar_pfs = find_gr_spill (1);
2292 if (current_frame_info.reg_save_ar_pfs == 0)
2294 extra_spill_size += 8;
2300 /* Unwind descriptor hackery: things are most efficient if we allocate
2301 consecutive GR save registers for RP, PFS, FP in that order. However,
2302 it is absolutely critical that FP get the only hard register that's
2303 guaranteed to be free, so we allocated it first. If all three did
2304 happen to be allocated hard regs, and are consecutive, rearrange them
2305 into the preferred order now. */
2306 if (current_frame_info.reg_fp != 0
2307 && current_frame_info.reg_save_b0 == current_frame_info.reg_fp + 1
2308 && current_frame_info.reg_save_ar_pfs == current_frame_info.reg_fp + 2)
2310 current_frame_info.reg_save_b0 = current_frame_info.reg_fp;
2311 current_frame_info.reg_save_ar_pfs = current_frame_info.reg_fp + 1;
2312 current_frame_info.reg_fp = current_frame_info.reg_fp + 2;
2315 /* See if we need to store the predicate register block. */
2316 for (regno = PR_REG (0); regno <= PR_REG (63); regno++)
2317 if (regs_ever_live[regno] && ! call_used_regs[regno])
2319 if (regno <= PR_REG (63))
2321 SET_HARD_REG_BIT (mask, PR_REG (0));
2322 current_frame_info.reg_save_pr = find_gr_spill (1);
2323 if (current_frame_info.reg_save_pr == 0)
2325 extra_spill_size += 8;
2329 /* ??? Mark them all as used so that register renaming and such
2330 are free to use them. */
2331 for (regno = PR_REG (0); regno <= PR_REG (63); regno++)
2332 regs_ever_live[regno] = 1;
2335 /* If we're forced to use st8.spill, we're forced to save and restore
2336 ar.unat as well. The check for existing liveness allows inline asm
2337 to touch ar.unat. */
2338 if (spilled_gr_p || cfun->machine->n_varargs
2339 || regs_ever_live[AR_UNAT_REGNUM])
2341 regs_ever_live[AR_UNAT_REGNUM] = 1;
2342 SET_HARD_REG_BIT (mask, AR_UNAT_REGNUM);
2343 current_frame_info.reg_save_ar_unat = find_gr_spill (spill_size == 0);
2344 if (current_frame_info.reg_save_ar_unat == 0)
2346 extra_spill_size += 8;
2351 if (regs_ever_live[AR_LC_REGNUM])
2353 SET_HARD_REG_BIT (mask, AR_LC_REGNUM);
2354 current_frame_info.reg_save_ar_lc = find_gr_spill (spill_size == 0);
2355 if (current_frame_info.reg_save_ar_lc == 0)
2357 extra_spill_size += 8;
2362 /* If we have an odd number of words of pretend arguments written to
2363 the stack, then the FR save area will be unaligned. We round the
2364 size of this area up to keep things 16 byte aligned. */
2366 pretend_args_size = IA64_STACK_ALIGN (current_function_pretend_args_size);
2368 pretend_args_size = current_function_pretend_args_size;
2370 total_size = (spill_size + extra_spill_size + size + pretend_args_size
2371 + current_function_outgoing_args_size);
2372 total_size = IA64_STACK_ALIGN (total_size);
2374 /* We always use the 16-byte scratch area provided by the caller, but
2375 if we are a leaf function, there's no one to which we need to provide
2377 if (current_function_is_leaf)
2378 total_size = MAX (0, total_size - 16);
2380 current_frame_info.total_size = total_size;
2381 current_frame_info.spill_cfa_off = pretend_args_size - 16;
2382 current_frame_info.spill_size = spill_size;
2383 current_frame_info.extra_spill_size = extra_spill_size;
2384 COPY_HARD_REG_SET (current_frame_info.mask, mask);
2385 current_frame_info.n_spilled = n_spilled;
2386 current_frame_info.initialized = reload_completed;
2389 /* Compute the initial difference between the specified pair of registers. */
2392 ia64_initial_elimination_offset (int from, int to)
2394 HOST_WIDE_INT offset;
2396 ia64_compute_frame_size (get_frame_size ());
2399 case FRAME_POINTER_REGNUM:
2402 case HARD_FRAME_POINTER_REGNUM:
2403 if (current_function_is_leaf)
2404 offset = -current_frame_info.total_size;
2406 offset = -(current_frame_info.total_size
2407 - current_function_outgoing_args_size - 16);
2410 case STACK_POINTER_REGNUM:
2411 if (current_function_is_leaf)
2414 offset = 16 + current_function_outgoing_args_size;
2422 case ARG_POINTER_REGNUM:
2423 /* Arguments start above the 16 byte save area, unless stdarg
2424 in which case we store through the 16 byte save area. */
2427 case HARD_FRAME_POINTER_REGNUM:
2428 offset = 16 - current_function_pretend_args_size;
2431 case STACK_POINTER_REGNUM:
2432 offset = (current_frame_info.total_size
2433 + 16 - current_function_pretend_args_size);
2448 /* If there are more than a trivial number of register spills, we use
2449 two interleaved iterators so that we can get two memory references
2452 In order to simplify things in the prologue and epilogue expanders,
2453 we use helper functions to fix up the memory references after the
2454 fact with the appropriate offsets to a POST_MODIFY memory mode.
2455 The following data structure tracks the state of the two iterators
2456 while insns are being emitted. */
2458 struct spill_fill_data
2460 rtx init_after; /* point at which to emit initializations */
2461 rtx init_reg[2]; /* initial base register */
2462 rtx iter_reg[2]; /* the iterator registers */
2463 rtx *prev_addr[2]; /* address of last memory use */
2464 rtx prev_insn[2]; /* the insn corresponding to prev_addr */
2465 HOST_WIDE_INT prev_off[2]; /* last offset */
2466 int n_iter; /* number of iterators in use */
2467 int next_iter; /* next iterator to use */
2468 unsigned int save_gr_used_mask;
2471 static struct spill_fill_data spill_fill_data;
2474 setup_spill_pointers (int n_spills, rtx init_reg, HOST_WIDE_INT cfa_off)
2478 spill_fill_data.init_after = get_last_insn ();
2479 spill_fill_data.init_reg[0] = init_reg;
2480 spill_fill_data.init_reg[1] = init_reg;
2481 spill_fill_data.prev_addr[0] = NULL;
2482 spill_fill_data.prev_addr[1] = NULL;
2483 spill_fill_data.prev_insn[0] = NULL;
2484 spill_fill_data.prev_insn[1] = NULL;
2485 spill_fill_data.prev_off[0] = cfa_off;
2486 spill_fill_data.prev_off[1] = cfa_off;
2487 spill_fill_data.next_iter = 0;
2488 spill_fill_data.save_gr_used_mask = current_frame_info.gr_used_mask;
2490 spill_fill_data.n_iter = 1 + (n_spills > 2);
2491 for (i = 0; i < spill_fill_data.n_iter; ++i)
2493 int regno = next_scratch_gr_reg ();
2494 spill_fill_data.iter_reg[i] = gen_rtx_REG (DImode, regno);
2495 current_frame_info.gr_used_mask |= 1 << regno;
2500 finish_spill_pointers (void)
2502 current_frame_info.gr_used_mask = spill_fill_data.save_gr_used_mask;
2506 spill_restore_mem (rtx reg, HOST_WIDE_INT cfa_off)
2508 int iter = spill_fill_data.next_iter;
2509 HOST_WIDE_INT disp = spill_fill_data.prev_off[iter] - cfa_off;
2510 rtx disp_rtx = GEN_INT (disp);
2513 if (spill_fill_data.prev_addr[iter])
2515 if (CONST_OK_FOR_N (disp))
2517 *spill_fill_data.prev_addr[iter]
2518 = gen_rtx_POST_MODIFY (DImode, spill_fill_data.iter_reg[iter],
2519 gen_rtx_PLUS (DImode,
2520 spill_fill_data.iter_reg[iter],
2522 REG_NOTES (spill_fill_data.prev_insn[iter])
2523 = gen_rtx_EXPR_LIST (REG_INC, spill_fill_data.iter_reg[iter],
2524 REG_NOTES (spill_fill_data.prev_insn[iter]));
2528 /* ??? Could use register post_modify for loads. */
2529 if (! CONST_OK_FOR_I (disp))
2531 rtx tmp = gen_rtx_REG (DImode, next_scratch_gr_reg ());
2532 emit_move_insn (tmp, disp_rtx);
2535 emit_insn (gen_adddi3 (spill_fill_data.iter_reg[iter],
2536 spill_fill_data.iter_reg[iter], disp_rtx));
2539 /* Micro-optimization: if we've created a frame pointer, it's at
2540 CFA 0, which may allow the real iterator to be initialized lower,
2541 slightly increasing parallelism. Also, if there are few saves
2542 it may eliminate the iterator entirely. */
2544 && spill_fill_data.init_reg[iter] == stack_pointer_rtx
2545 && frame_pointer_needed)
2547 mem = gen_rtx_MEM (GET_MODE (reg), hard_frame_pointer_rtx);
2548 set_mem_alias_set (mem, get_varargs_alias_set ());
2556 seq = gen_movdi (spill_fill_data.iter_reg[iter],
2557 spill_fill_data.init_reg[iter]);
2562 if (! CONST_OK_FOR_I (disp))
2564 rtx tmp = gen_rtx_REG (DImode, next_scratch_gr_reg ());
2565 emit_move_insn (tmp, disp_rtx);
2569 emit_insn (gen_adddi3 (spill_fill_data.iter_reg[iter],
2570 spill_fill_data.init_reg[iter],
2577 /* Careful for being the first insn in a sequence. */
2578 if (spill_fill_data.init_after)
2579 insn = emit_insn_after (seq, spill_fill_data.init_after);
2582 rtx first = get_insns ();
2584 insn = emit_insn_before (seq, first);
2586 insn = emit_insn (seq);
2588 spill_fill_data.init_after = insn;
2590 /* If DISP is 0, we may or may not have a further adjustment
2591 afterward. If we do, then the load/store insn may be modified
2592 to be a post-modify. If we don't, then this copy may be
2593 eliminated by copyprop_hardreg_forward, which makes this
2594 insn garbage, which runs afoul of the sanity check in
2595 propagate_one_insn. So mark this insn as legal to delete. */
2597 REG_NOTES(insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, const0_rtx,
2601 mem = gen_rtx_MEM (GET_MODE (reg), spill_fill_data.iter_reg[iter]);
2603 /* ??? Not all of the spills are for varargs, but some of them are.
2604 The rest of the spills belong in an alias set of their own. But
2605 it doesn't actually hurt to include them here. */
2606 set_mem_alias_set (mem, get_varargs_alias_set ());
2608 spill_fill_data.prev_addr[iter] = &XEXP (mem, 0);
2609 spill_fill_data.prev_off[iter] = cfa_off;
2611 if (++iter >= spill_fill_data.n_iter)
2613 spill_fill_data.next_iter = iter;
2619 do_spill (rtx (*move_fn) (rtx, rtx, rtx), rtx reg, HOST_WIDE_INT cfa_off,
2622 int iter = spill_fill_data.next_iter;
2625 mem = spill_restore_mem (reg, cfa_off);
2626 insn = emit_insn ((*move_fn) (mem, reg, GEN_INT (cfa_off)));
2627 spill_fill_data.prev_insn[iter] = insn;
2634 RTX_FRAME_RELATED_P (insn) = 1;
2636 /* Don't even pretend that the unwind code can intuit its way
2637 through a pair of interleaved post_modify iterators. Just
2638 provide the correct answer. */
2640 if (frame_pointer_needed)
2642 base = hard_frame_pointer_rtx;
2647 base = stack_pointer_rtx;
2648 off = current_frame_info.total_size - cfa_off;
2652 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2653 gen_rtx_SET (VOIDmode,
2654 gen_rtx_MEM (GET_MODE (reg),
2655 plus_constant (base, off)),
2662 do_restore (rtx (*move_fn) (rtx, rtx, rtx), rtx reg, HOST_WIDE_INT cfa_off)
2664 int iter = spill_fill_data.next_iter;
2667 insn = emit_insn ((*move_fn) (reg, spill_restore_mem (reg, cfa_off),
2668 GEN_INT (cfa_off)));
2669 spill_fill_data.prev_insn[iter] = insn;
2672 /* Wrapper functions that discards the CONST_INT spill offset. These
2673 exist so that we can give gr_spill/gr_fill the offset they need and
2674 use a consistent function interface. */
2677 gen_movdi_x (rtx dest, rtx src, rtx offset ATTRIBUTE_UNUSED)
2679 return gen_movdi (dest, src);
2683 gen_fr_spill_x (rtx dest, rtx src, rtx offset ATTRIBUTE_UNUSED)
2685 return gen_fr_spill (dest, src);
2689 gen_fr_restore_x (rtx dest, rtx src, rtx offset ATTRIBUTE_UNUSED)
2691 return gen_fr_restore (dest, src);
2694 /* Called after register allocation to add any instructions needed for the
2695 prologue. Using a prologue insn is favored compared to putting all of the
2696 instructions in output_function_prologue(), since it allows the scheduler
2697 to intermix instructions with the saves of the caller saved registers. In
2698 some cases, it might be necessary to emit a barrier instruction as the last
2699 insn to prevent such scheduling.
2701 Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
2702 so that the debug info generation code can handle them properly.
2704 The register save area is layed out like so:
2706 [ varargs spill area ]
2707 [ fr register spill area ]
2708 [ br register spill area ]
2709 [ ar register spill area ]
2710 [ pr register spill area ]
2711 [ gr register spill area ] */
2713 /* ??? Get inefficient code when the frame size is larger than can fit in an
2714 adds instruction. */
2717 ia64_expand_prologue (void)
2719 rtx insn, ar_pfs_save_reg, ar_unat_save_reg;
2720 int i, epilogue_p, regno, alt_regno, cfa_off, n_varargs;
2723 ia64_compute_frame_size (get_frame_size ());
2724 last_scratch_gr_reg = 15;
2726 /* If there is no epilogue, then we don't need some prologue insns.
2727 We need to avoid emitting the dead prologue insns, because flow
2728 will complain about them. */
2734 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
2735 if ((e->flags & EDGE_FAKE) == 0
2736 && (e->flags & EDGE_FALLTHRU) != 0)
2738 epilogue_p = (e != NULL);
2743 /* Set the local, input, and output register names. We need to do this
2744 for GNU libc, which creates crti.S/crtn.S by splitting initfini.c in
2745 half. If we use in/loc/out register names, then we get assembler errors
2746 in crtn.S because there is no alloc insn or regstk directive in there. */
2747 if (! TARGET_REG_NAMES)
2749 int inputs = current_frame_info.n_input_regs;
2750 int locals = current_frame_info.n_local_regs;
2751 int outputs = current_frame_info.n_output_regs;
2753 for (i = 0; i < inputs; i++)
2754 reg_names[IN_REG (i)] = ia64_reg_numbers[i];
2755 for (i = 0; i < locals; i++)
2756 reg_names[LOC_REG (i)] = ia64_reg_numbers[inputs + i];
2757 for (i = 0; i < outputs; i++)
2758 reg_names[OUT_REG (i)] = ia64_reg_numbers[inputs + locals + i];
2761 /* Set the frame pointer register name. The regnum is logically loc79,
2762 but of course we'll not have allocated that many locals. Rather than
2763 worrying about renumbering the existing rtxs, we adjust the name. */
2764 /* ??? This code means that we can never use one local register when
2765 there is a frame pointer. loc79 gets wasted in this case, as it is
2766 renamed to a register that will never be used. See also the try_locals
2767 code in find_gr_spill. */
2768 if (current_frame_info.reg_fp)
2770 const char *tmp = reg_names[HARD_FRAME_POINTER_REGNUM];
2771 reg_names[HARD_FRAME_POINTER_REGNUM]
2772 = reg_names[current_frame_info.reg_fp];
2773 reg_names[current_frame_info.reg_fp] = tmp;
2776 /* We don't need an alloc instruction if we've used no outputs or locals. */
2777 if (current_frame_info.n_local_regs == 0
2778 && current_frame_info.n_output_regs == 0
2779 && current_frame_info.n_input_regs <= current_function_args_info.int_regs
2780 && !TEST_HARD_REG_BIT (current_frame_info.mask, AR_PFS_REGNUM))
2782 /* If there is no alloc, but there are input registers used, then we
2783 need a .regstk directive. */
2784 current_frame_info.need_regstk = (TARGET_REG_NAMES != 0);
2785 ar_pfs_save_reg = NULL_RTX;
2789 current_frame_info.need_regstk = 0;
2791 if (current_frame_info.reg_save_ar_pfs)
2792 regno = current_frame_info.reg_save_ar_pfs;
2794 regno = next_scratch_gr_reg ();
2795 ar_pfs_save_reg = gen_rtx_REG (DImode, regno);
2797 insn = emit_insn (gen_alloc (ar_pfs_save_reg,
2798 GEN_INT (current_frame_info.n_input_regs),
2799 GEN_INT (current_frame_info.n_local_regs),
2800 GEN_INT (current_frame_info.n_output_regs),
2801 GEN_INT (current_frame_info.n_rotate_regs)));
2802 RTX_FRAME_RELATED_P (insn) = (current_frame_info.reg_save_ar_pfs != 0);
2805 /* Set up frame pointer, stack pointer, and spill iterators. */
2807 n_varargs = cfun->machine->n_varargs;
2808 setup_spill_pointers (current_frame_info.n_spilled + n_varargs,
2809 stack_pointer_rtx, 0);
2811 if (frame_pointer_needed)
2813 insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
2814 RTX_FRAME_RELATED_P (insn) = 1;
2817 if (current_frame_info.total_size != 0)
2819 rtx frame_size_rtx = GEN_INT (- current_frame_info.total_size);
2822 if (CONST_OK_FOR_I (- current_frame_info.total_size))
2823 offset = frame_size_rtx;
2826 regno = next_scratch_gr_reg ();
2827 offset = gen_rtx_REG (DImode, regno);
2828 emit_move_insn (offset, frame_size_rtx);
2831 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2832 stack_pointer_rtx, offset));
2834 if (! frame_pointer_needed)
2836 RTX_FRAME_RELATED_P (insn) = 1;
2837 if (GET_CODE (offset) != CONST_INT)
2840 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2841 gen_rtx_SET (VOIDmode,
2843 gen_rtx_PLUS (DImode,
2850 /* ??? At this point we must generate a magic insn that appears to
2851 modify the stack pointer, the frame pointer, and all spill
2852 iterators. This would allow the most scheduling freedom. For
2853 now, just hard stop. */
2854 emit_insn (gen_blockage ());
2857 /* Must copy out ar.unat before doing any integer spills. */
2858 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_UNAT_REGNUM))
2860 if (current_frame_info.reg_save_ar_unat)
2862 = gen_rtx_REG (DImode, current_frame_info.reg_save_ar_unat);
2865 alt_regno = next_scratch_gr_reg ();
2866 ar_unat_save_reg = gen_rtx_REG (DImode, alt_regno);
2867 current_frame_info.gr_used_mask |= 1 << alt_regno;
2870 reg = gen_rtx_REG (DImode, AR_UNAT_REGNUM);
2871 insn = emit_move_insn (ar_unat_save_reg, reg);
2872 RTX_FRAME_RELATED_P (insn) = (current_frame_info.reg_save_ar_unat != 0);
2874 /* Even if we're not going to generate an epilogue, we still
2875 need to save the register so that EH works. */
2876 if (! epilogue_p && current_frame_info.reg_save_ar_unat)
2877 emit_insn (gen_prologue_use (ar_unat_save_reg));
2880 ar_unat_save_reg = NULL_RTX;
2882 /* Spill all varargs registers. Do this before spilling any GR registers,
2883 since we want the UNAT bits for the GR registers to override the UNAT
2884 bits from varargs, which we don't care about. */
2887 for (regno = GR_ARG_FIRST + 7; n_varargs > 0; --n_varargs, --regno)
2889 reg = gen_rtx_REG (DImode, regno);
2890 do_spill (gen_gr_spill, reg, cfa_off += 8, NULL_RTX);
2893 /* Locate the bottom of the register save area. */
2894 cfa_off = (current_frame_info.spill_cfa_off
2895 + current_frame_info.spill_size
2896 + current_frame_info.extra_spill_size);
2898 /* Save the predicate register block either in a register or in memory. */
2899 if (TEST_HARD_REG_BIT (current_frame_info.mask, PR_REG (0)))
2901 reg = gen_rtx_REG (DImode, PR_REG (0));
2902 if (current_frame_info.reg_save_pr != 0)
2904 alt_reg = gen_rtx_REG (DImode, current_frame_info.reg_save_pr);
2905 insn = emit_move_insn (alt_reg, reg);
2907 /* ??? Denote pr spill/fill by a DImode move that modifies all
2908 64 hard registers. */
2909 RTX_FRAME_RELATED_P (insn) = 1;
2911 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2912 gen_rtx_SET (VOIDmode, alt_reg, reg),
2915 /* Even if we're not going to generate an epilogue, we still
2916 need to save the register so that EH works. */
2918 emit_insn (gen_prologue_use (alt_reg));
2922 alt_regno = next_scratch_gr_reg ();
2923 alt_reg = gen_rtx_REG (DImode, alt_regno);
2924 insn = emit_move_insn (alt_reg, reg);
2925 do_spill (gen_movdi_x, alt_reg, cfa_off, reg);
2930 /* Handle AR regs in numerical order. All of them get special handling. */
2931 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_UNAT_REGNUM)
2932 && current_frame_info.reg_save_ar_unat == 0)
2934 reg = gen_rtx_REG (DImode, AR_UNAT_REGNUM);
2935 do_spill (gen_movdi_x, ar_unat_save_reg, cfa_off, reg);
2939 /* The alloc insn already copied ar.pfs into a general register. The
2940 only thing we have to do now is copy that register to a stack slot
2941 if we'd not allocated a local register for the job. */
2942 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_PFS_REGNUM)
2943 && current_frame_info.reg_save_ar_pfs == 0)
2945 reg = gen_rtx_REG (DImode, AR_PFS_REGNUM);
2946 do_spill (gen_movdi_x, ar_pfs_save_reg, cfa_off, reg);
2950 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_LC_REGNUM))
2952 reg = gen_rtx_REG (DImode, AR_LC_REGNUM);
2953 if (current_frame_info.reg_save_ar_lc != 0)
2955 alt_reg = gen_rtx_REG (DImode, current_frame_info.reg_save_ar_lc);
2956 insn = emit_move_insn (alt_reg, reg);
2957 RTX_FRAME_RELATED_P (insn) = 1;
2959 /* Even if we're not going to generate an epilogue, we still
2960 need to save the register so that EH works. */
2962 emit_insn (gen_prologue_use (alt_reg));
2966 alt_regno = next_scratch_gr_reg ();
2967 alt_reg = gen_rtx_REG (DImode, alt_regno);
2968 emit_move_insn (alt_reg, reg);
2969 do_spill (gen_movdi_x, alt_reg, cfa_off, reg);
2974 if (current_frame_info.reg_save_gp)
2976 insn = emit_move_insn (gen_rtx_REG (DImode,
2977 current_frame_info.reg_save_gp),
2978 pic_offset_table_rtx);
2979 /* We don't know for sure yet if this is actually needed, since
2980 we've not split the PIC call patterns. If all of the calls
2981 are indirect, and not followed by any uses of the gp, then
2982 this save is dead. Allow it to go away. */
2984 = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, const0_rtx, REG_NOTES (insn));
2987 /* We should now be at the base of the gr/br/fr spill area. */
2988 gcc_assert (cfa_off == (current_frame_info.spill_cfa_off
2989 + current_frame_info.spill_size));
2991 /* Spill all general registers. */
2992 for (regno = GR_REG (1); regno <= GR_REG (31); ++regno)
2993 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
2995 reg = gen_rtx_REG (DImode, regno);
2996 do_spill (gen_gr_spill, reg, cfa_off, reg);
3000 /* Handle BR0 specially -- it may be getting stored permanently in
3001 some GR register. */
3002 if (TEST_HARD_REG_BIT (current_frame_info.mask, BR_REG (0)))
3004 reg = gen_rtx_REG (DImode, BR_REG (0));
3005 if (current_frame_info.reg_save_b0 != 0)
3007 alt_reg = gen_rtx_REG (DImode, current_frame_info.reg_save_b0);
3008 insn = emit_move_insn (alt_reg, reg);
3009 RTX_FRAME_RELATED_P (insn) = 1;
3011 /* Even if we're not going to generate an epilogue, we still
3012 need to save the register so that EH works. */
3014 emit_insn (gen_prologue_use (alt_reg));
3018 alt_regno = next_scratch_gr_reg ();
3019 alt_reg = gen_rtx_REG (DImode, alt_regno);
3020 emit_move_insn (alt_reg, reg);
3021 do_spill (gen_movdi_x, alt_reg, cfa_off, reg);
3026 /* Spill the rest of the BR registers. */
3027 for (regno = BR_REG (1); regno <= BR_REG (7); ++regno)
3028 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3030 alt_regno = next_scratch_gr_reg ();
3031 alt_reg = gen_rtx_REG (DImode, alt_regno);
3032 reg = gen_rtx_REG (DImode, regno);
3033 emit_move_insn (alt_reg, reg);
3034 do_spill (gen_movdi_x, alt_reg, cfa_off, reg);
3038 /* Align the frame and spill all FR registers. */
3039 for (regno = FR_REG (2); regno <= FR_REG (127); ++regno)
3040 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3042 gcc_assert (!(cfa_off & 15));
3043 reg = gen_rtx_REG (XFmode, regno);
3044 do_spill (gen_fr_spill_x, reg, cfa_off, reg);
3048 gcc_assert (cfa_off == current_frame_info.spill_cfa_off);
3050 finish_spill_pointers ();
3053 /* Called after register allocation to add any instructions needed for the
3054 epilogue. Using an epilogue insn is favored compared to putting all of the
3055 instructions in output_function_prologue(), since it allows the scheduler
3056 to intermix instructions with the saves of the caller saved registers. In
3057 some cases, it might be necessary to emit a barrier instruction as the last
3058 insn to prevent such scheduling. */
3061 ia64_expand_epilogue (int sibcall_p)
3063 rtx insn, reg, alt_reg, ar_unat_save_reg;
3064 int regno, alt_regno, cfa_off;
3066 ia64_compute_frame_size (get_frame_size ());
3068 /* If there is a frame pointer, then we use it instead of the stack
3069 pointer, so that the stack pointer does not need to be valid when
3070 the epilogue starts. See EXIT_IGNORE_STACK. */
3071 if (frame_pointer_needed)
3072 setup_spill_pointers (current_frame_info.n_spilled,
3073 hard_frame_pointer_rtx, 0);
3075 setup_spill_pointers (current_frame_info.n_spilled, stack_pointer_rtx,
3076 current_frame_info.total_size);
3078 if (current_frame_info.total_size != 0)
3080 /* ??? At this point we must generate a magic insn that appears to
3081 modify the spill iterators and the frame pointer. This would
3082 allow the most scheduling freedom. For now, just hard stop. */
3083 emit_insn (gen_blockage ());
3086 /* Locate the bottom of the register save area. */
3087 cfa_off = (current_frame_info.spill_cfa_off
3088 + current_frame_info.spill_size
3089 + current_frame_info.extra_spill_size);
3091 /* Restore the predicate registers. */
3092 if (TEST_HARD_REG_BIT (current_frame_info.mask, PR_REG (0)))
3094 if (current_frame_info.reg_save_pr != 0)
3095 alt_reg = gen_rtx_REG (DImode, current_frame_info.reg_save_pr);
3098 alt_regno = next_scratch_gr_reg ();
3099 alt_reg = gen_rtx_REG (DImode, alt_regno);
3100 do_restore (gen_movdi_x, alt_reg, cfa_off);
3103 reg = gen_rtx_REG (DImode, PR_REG (0));
3104 emit_move_insn (reg, alt_reg);
3107 /* Restore the application registers. */
3109 /* Load the saved unat from the stack, but do not restore it until
3110 after the GRs have been restored. */
3111 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_UNAT_REGNUM))
3113 if (current_frame_info.reg_save_ar_unat != 0)
3115 = gen_rtx_REG (DImode, current_frame_info.reg_save_ar_unat);
3118 alt_regno = next_scratch_gr_reg ();
3119 ar_unat_save_reg = gen_rtx_REG (DImode, alt_regno);
3120 current_frame_info.gr_used_mask |= 1 << alt_regno;
3121 do_restore (gen_movdi_x, ar_unat_save_reg, cfa_off);
3126 ar_unat_save_reg = NULL_RTX;
3128 if (current_frame_info.reg_save_ar_pfs != 0)
3130 alt_reg = gen_rtx_REG (DImode, current_frame_info.reg_save_ar_pfs);
3131 reg = gen_rtx_REG (DImode, AR_PFS_REGNUM);
3132 emit_move_insn (reg, alt_reg);
3134 else if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_PFS_REGNUM))
3136 alt_regno = next_scratch_gr_reg ();
3137 alt_reg = gen_rtx_REG (DImode, alt_regno);
3138 do_restore (gen_movdi_x, alt_reg, cfa_off);
3140 reg = gen_rtx_REG (DImode, AR_PFS_REGNUM);
3141 emit_move_insn (reg, alt_reg);
3144 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_LC_REGNUM))
3146 if (current_frame_info.reg_save_ar_lc != 0)
3147 alt_reg = gen_rtx_REG (DImode, current_frame_info.reg_save_ar_lc);
3150 alt_regno = next_scratch_gr_reg ();
3151 alt_reg = gen_rtx_REG (DImode, alt_regno);
3152 do_restore (gen_movdi_x, alt_reg, cfa_off);
3155 reg = gen_rtx_REG (DImode, AR_LC_REGNUM);
3156 emit_move_insn (reg, alt_reg);
3159 /* We should now be at the base of the gr/br/fr spill area. */
3160 gcc_assert (cfa_off == (current_frame_info.spill_cfa_off
3161 + current_frame_info.spill_size));
3163 /* The GP may be stored on the stack in the prologue, but it's
3164 never restored in the epilogue. Skip the stack slot. */
3165 if (TEST_HARD_REG_BIT (current_frame_info.mask, GR_REG (1)))
3168 /* Restore all general registers. */
3169 for (regno = GR_REG (2); regno <= GR_REG (31); ++regno)
3170 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3172 reg = gen_rtx_REG (DImode, regno);
3173 do_restore (gen_gr_restore, reg, cfa_off);
3177 /* Restore the branch registers. Handle B0 specially, as it may
3178 have gotten stored in some GR register. */
3179 if (TEST_HARD_REG_BIT (current_frame_info.mask, BR_REG (0)))
3181 if (current_frame_info.reg_save_b0 != 0)
3182 alt_reg = gen_rtx_REG (DImode, current_frame_info.reg_save_b0);
3185 alt_regno = next_scratch_gr_reg ();
3186 alt_reg = gen_rtx_REG (DImode, alt_regno);
3187 do_restore (gen_movdi_x, alt_reg, cfa_off);
3190 reg = gen_rtx_REG (DImode, BR_REG (0));
3191 emit_move_insn (reg, alt_reg);
3194 for (regno = BR_REG (1); regno <= BR_REG (7); ++regno)
3195 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3197 alt_regno = next_scratch_gr_reg ();
3198 alt_reg = gen_rtx_REG (DImode, alt_regno);
3199 do_restore (gen_movdi_x, alt_reg, cfa_off);
3201 reg = gen_rtx_REG (DImode, regno);
3202 emit_move_insn (reg, alt_reg);
3205 /* Restore floating point registers. */
3206 for (regno = FR_REG (2); regno <= FR_REG (127); ++regno)
3207 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3209 gcc_assert (!(cfa_off & 15));
3210 reg = gen_rtx_REG (XFmode, regno);
3211 do_restore (gen_fr_restore_x, reg, cfa_off);
3215 /* Restore ar.unat for real. */
3216 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_UNAT_REGNUM))
3218 reg = gen_rtx_REG (DImode, AR_UNAT_REGNUM);
3219 emit_move_insn (reg, ar_unat_save_reg);
3222 gcc_assert (cfa_off == current_frame_info.spill_cfa_off);
3224 finish_spill_pointers ();
3226 if (current_frame_info.total_size || cfun->machine->ia64_eh_epilogue_sp)
3228 /* ??? At this point we must generate a magic insn that appears to
3229 modify the spill iterators, the stack pointer, and the frame
3230 pointer. This would allow the most scheduling freedom. For now,
3232 emit_insn (gen_blockage ());
3235 if (cfun->machine->ia64_eh_epilogue_sp)
3236 emit_move_insn (stack_pointer_rtx, cfun->machine->ia64_eh_epilogue_sp);
3237 else if (frame_pointer_needed)
3239 insn = emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
3240 RTX_FRAME_RELATED_P (insn) = 1;
3242 else if (current_frame_info.total_size)
3244 rtx offset, frame_size_rtx;
3246 frame_size_rtx = GEN_INT (current_frame_info.total_size);
3247 if (CONST_OK_FOR_I (current_frame_info.total_size))
3248 offset = frame_size_rtx;
3251 regno = next_scratch_gr_reg ();
3252 offset = gen_rtx_REG (DImode, regno);
3253 emit_move_insn (offset, frame_size_rtx);
3256 insn = emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
3259 RTX_FRAME_RELATED_P (insn) = 1;
3260 if (GET_CODE (offset) != CONST_INT)
3263 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3264 gen_rtx_SET (VOIDmode,
3266 gen_rtx_PLUS (DImode,
3273 if (cfun->machine->ia64_eh_epilogue_bsp)
3274 emit_insn (gen_set_bsp (cfun->machine->ia64_eh_epilogue_bsp));
3277 emit_jump_insn (gen_return_internal (gen_rtx_REG (DImode, BR_REG (0))));
3280 int fp = GR_REG (2);
3281 /* We need a throw away register here, r0 and r1 are reserved, so r2 is the
3282 first available call clobbered register. If there was a frame_pointer
3283 register, we may have swapped the names of r2 and HARD_FRAME_POINTER_REGNUM,
3284 so we have to make sure we're using the string "r2" when emitting
3285 the register name for the assembler. */
3286 if (current_frame_info.reg_fp && current_frame_info.reg_fp == GR_REG (2))
3287 fp = HARD_FRAME_POINTER_REGNUM;
3289 /* We must emit an alloc to force the input registers to become output
3290 registers. Otherwise, if the callee tries to pass its parameters
3291 through to another call without an intervening alloc, then these
3293 /* ??? We don't need to preserve all input registers. We only need to
3294 preserve those input registers used as arguments to the sibling call.
3295 It is unclear how to compute that number here. */
3296 if (current_frame_info.n_input_regs != 0)
3298 rtx n_inputs = GEN_INT (current_frame_info.n_input_regs);
3299 insn = emit_insn (gen_alloc (gen_rtx_REG (DImode, fp),
3300 const0_rtx, const0_rtx,
3301 n_inputs, const0_rtx));
3302 RTX_FRAME_RELATED_P (insn) = 1;
3307 /* Return 1 if br.ret can do all the work required to return from a
3311 ia64_direct_return (void)
3313 if (reload_completed && ! frame_pointer_needed)
3315 ia64_compute_frame_size (get_frame_size ());
3317 return (current_frame_info.total_size == 0
3318 && current_frame_info.n_spilled == 0
3319 && current_frame_info.reg_save_b0 == 0
3320 && current_frame_info.reg_save_pr == 0
3321 && current_frame_info.reg_save_ar_pfs == 0
3322 && current_frame_info.reg_save_ar_unat == 0
3323 && current_frame_info.reg_save_ar_lc == 0);
3328 /* Return the magic cookie that we use to hold the return address
3329 during early compilation. */
3332 ia64_return_addr_rtx (HOST_WIDE_INT count, rtx frame ATTRIBUTE_UNUSED)
3336 return gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), UNSPEC_RET_ADDR);
3339 /* Split this value after reload, now that we know where the return
3340 address is saved. */
3343 ia64_split_return_addr_rtx (rtx dest)
3347 if (TEST_HARD_REG_BIT (current_frame_info.mask, BR_REG (0)))
3349 if (current_frame_info.reg_save_b0 != 0)
3350 src = gen_rtx_REG (DImode, current_frame_info.reg_save_b0);
3356 /* Compute offset from CFA for BR0. */
3357 /* ??? Must be kept in sync with ia64_expand_prologue. */
3358 off = (current_frame_info.spill_cfa_off
3359 + current_frame_info.spill_size);
3360 for (regno = GR_REG (1); regno <= GR_REG (31); ++regno)
3361 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3364 /* Convert CFA offset to a register based offset. */
3365 if (frame_pointer_needed)
3366 src = hard_frame_pointer_rtx;
3369 src = stack_pointer_rtx;
3370 off += current_frame_info.total_size;
3373 /* Load address into scratch register. */
3374 if (CONST_OK_FOR_I (off))
3375 emit_insn (gen_adddi3 (dest, src, GEN_INT (off)));
3378 emit_move_insn (dest, GEN_INT (off));
3379 emit_insn (gen_adddi3 (dest, src, dest));
3382 src = gen_rtx_MEM (Pmode, dest);
3386 src = gen_rtx_REG (DImode, BR_REG (0));
3388 emit_move_insn (dest, src);
3392 ia64_hard_regno_rename_ok (int from, int to)
3394 /* Don't clobber any of the registers we reserved for the prologue. */
3395 if (to == current_frame_info.reg_fp
3396 || to == current_frame_info.reg_save_b0
3397 || to == current_frame_info.reg_save_pr
3398 || to == current_frame_info.reg_save_ar_pfs
3399 || to == current_frame_info.reg_save_ar_unat
3400 || to == current_frame_info.reg_save_ar_lc)
3403 if (from == current_frame_info.reg_fp
3404 || from == current_frame_info.reg_save_b0
3405 || from == current_frame_info.reg_save_pr
3406 || from == current_frame_info.reg_save_ar_pfs
3407 || from == current_frame_info.reg_save_ar_unat
3408 || from == current_frame_info.reg_save_ar_lc)
3411 /* Don't use output registers outside the register frame. */
3412 if (OUT_REGNO_P (to) && to >= OUT_REG (current_frame_info.n_output_regs))
3415 /* Retain even/oddness on predicate register pairs. */
3416 if (PR_REGNO_P (from) && PR_REGNO_P (to))
3417 return (from & 1) == (to & 1);
3422 /* Target hook for assembling integer objects. Handle word-sized
3423 aligned objects and detect the cases when @fptr is needed. */
3426 ia64_assemble_integer (rtx x, unsigned int size, int aligned_p)
3428 if (size == POINTER_SIZE / BITS_PER_UNIT
3429 && !(TARGET_NO_PIC || TARGET_AUTO_PIC)
3430 && GET_CODE (x) == SYMBOL_REF
3431 && SYMBOL_REF_FUNCTION_P (x))
3433 static const char * const directive[2][2] = {
3434 /* 64-bit pointer */ /* 32-bit pointer */
3435 { "\tdata8.ua\t@fptr(", "\tdata4.ua\t@fptr("}, /* unaligned */
3436 { "\tdata8\t@fptr(", "\tdata4\t@fptr("} /* aligned */
3438 fputs (directive[(aligned_p != 0)][POINTER_SIZE == 32], asm_out_file);
3439 output_addr_const (asm_out_file, x);
3440 fputs (")\n", asm_out_file);
3443 return default_assemble_integer (x, size, aligned_p);
3446 /* Emit the function prologue. */
3449 ia64_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3451 int mask, grsave, grsave_prev;
3453 if (current_frame_info.need_regstk)
3454 fprintf (file, "\t.regstk %d, %d, %d, %d\n",
3455 current_frame_info.n_input_regs,
3456 current_frame_info.n_local_regs,
3457 current_frame_info.n_output_regs,
3458 current_frame_info.n_rotate_regs);
3460 if (!flag_unwind_tables && (!flag_exceptions || USING_SJLJ_EXCEPTIONS))
3463 /* Emit the .prologue directive. */
3466 grsave = grsave_prev = 0;
3467 if (current_frame_info.reg_save_b0 != 0)
3470 grsave = grsave_prev = current_frame_info.reg_save_b0;
3472 if (current_frame_info.reg_save_ar_pfs != 0
3473 && (grsave_prev == 0
3474 || current_frame_info.reg_save_ar_pfs == grsave_prev + 1))
3477 if (grsave_prev == 0)
3478 grsave = current_frame_info.reg_save_ar_pfs;
3479 grsave_prev = current_frame_info.reg_save_ar_pfs;
3481 if (current_frame_info.reg_fp != 0
3482 && (grsave_prev == 0
3483 || current_frame_info.reg_fp == grsave_prev + 1))
3486 if (grsave_prev == 0)
3487 grsave = HARD_FRAME_POINTER_REGNUM;
3488 grsave_prev = current_frame_info.reg_fp;
3490 if (current_frame_info.reg_save_pr != 0
3491 && (grsave_prev == 0
3492 || current_frame_info.reg_save_pr == grsave_prev + 1))
3495 if (grsave_prev == 0)
3496 grsave = current_frame_info.reg_save_pr;
3499 if (mask && TARGET_GNU_AS)
3500 fprintf (file, "\t.prologue %d, %d\n", mask,
3501 ia64_dbx_register_number (grsave));
3503 fputs ("\t.prologue\n", file);
3505 /* Emit a .spill directive, if necessary, to relocate the base of
3506 the register spill area. */
3507 if (current_frame_info.spill_cfa_off != -16)
3508 fprintf (file, "\t.spill %ld\n",
3509 (long) (current_frame_info.spill_cfa_off
3510 + current_frame_info.spill_size));
3513 /* Emit the .body directive at the scheduled end of the prologue. */
3516 ia64_output_function_end_prologue (FILE *file)
3518 if (!flag_unwind_tables && (!flag_exceptions || USING_SJLJ_EXCEPTIONS))
3521 fputs ("\t.body\n", file);
3524 /* Emit the function epilogue. */
3527 ia64_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
3528 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
3532 if (current_frame_info.reg_fp)
3534 const char *tmp = reg_names[HARD_FRAME_POINTER_REGNUM];
3535 reg_names[HARD_FRAME_POINTER_REGNUM]
3536 = reg_names[current_frame_info.reg_fp];
3537 reg_names[current_frame_info.reg_fp] = tmp;
3539 if (! TARGET_REG_NAMES)
3541 for (i = 0; i < current_frame_info.n_input_regs; i++)
3542 reg_names[IN_REG (i)] = ia64_input_reg_names[i];
3543 for (i = 0; i < current_frame_info.n_local_regs; i++)
3544 reg_names[LOC_REG (i)] = ia64_local_reg_names[i];
3545 for (i = 0; i < current_frame_info.n_output_regs; i++)
3546 reg_names[OUT_REG (i)] = ia64_output_reg_names[i];
3549 current_frame_info.initialized = 0;
3553 ia64_dbx_register_number (int regno)
3555 /* In ia64_expand_prologue we quite literally renamed the frame pointer
3556 from its home at loc79 to something inside the register frame. We
3557 must perform the same renumbering here for the debug info. */
3558 if (current_frame_info.reg_fp)
3560 if (regno == HARD_FRAME_POINTER_REGNUM)
3561 regno = current_frame_info.reg_fp;
3562 else if (regno == current_frame_info.reg_fp)
3563 regno = HARD_FRAME_POINTER_REGNUM;
3566 if (IN_REGNO_P (regno))
3567 return 32 + regno - IN_REG (0);
3568 else if (LOC_REGNO_P (regno))
3569 return 32 + current_frame_info.n_input_regs + regno - LOC_REG (0);
3570 else if (OUT_REGNO_P (regno))
3571 return (32 + current_frame_info.n_input_regs
3572 + current_frame_info.n_local_regs + regno - OUT_REG (0));
3578 ia64_initialize_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
3580 rtx addr_reg, eight = GEN_INT (8);
3582 /* The Intel assembler requires that the global __ia64_trampoline symbol
3583 be declared explicitly */
3586 static bool declared_ia64_trampoline = false;
3588 if (!declared_ia64_trampoline)
3590 declared_ia64_trampoline = true;
3591 (*targetm.asm_out.globalize_label) (asm_out_file,
3592 "__ia64_trampoline");
3596 /* Make sure addresses are Pmode even if we are in ILP32 mode. */
3597 addr = convert_memory_address (Pmode, addr);
3598 fnaddr = convert_memory_address (Pmode, fnaddr);
3599 static_chain = convert_memory_address (Pmode, static_chain);
3601 /* Load up our iterator. */
3602 addr_reg = gen_reg_rtx (Pmode);
3603 emit_move_insn (addr_reg, addr);
3605 /* The first two words are the fake descriptor:
3606 __ia64_trampoline, ADDR+16. */
3607 emit_move_insn (gen_rtx_MEM (Pmode, addr_reg),
3608 gen_rtx_SYMBOL_REF (Pmode, "__ia64_trampoline"));
3609 emit_insn (gen_adddi3 (addr_reg, addr_reg, eight));
3611 emit_move_insn (gen_rtx_MEM (Pmode, addr_reg),
3612 copy_to_reg (plus_constant (addr, 16)));
3613 emit_insn (gen_adddi3 (addr_reg, addr_reg, eight));
3615 /* The third word is the target descriptor. */
3616 emit_move_insn (gen_rtx_MEM (Pmode, addr_reg), fnaddr);
3617 emit_insn (gen_adddi3 (addr_reg, addr_reg, eight));
3619 /* The fourth word is the static chain. */
3620 emit_move_insn (gen_rtx_MEM (Pmode, addr_reg), static_chain);
3623 /* Do any needed setup for a variadic function. CUM has not been updated
3624 for the last named argument which has type TYPE and mode MODE.
3626 We generate the actual spill instructions during prologue generation. */
3629 ia64_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3630 tree type, int * pretend_size,
3631 int second_time ATTRIBUTE_UNUSED)
3633 CUMULATIVE_ARGS next_cum = *cum;
3635 /* Skip the current argument. */
3636 ia64_function_arg_advance (&next_cum, mode, type, 1);
3638 if (next_cum.words < MAX_ARGUMENT_SLOTS)
3640 int n = MAX_ARGUMENT_SLOTS - next_cum.words;
3641 *pretend_size = n * UNITS_PER_WORD;
3642 cfun->machine->n_varargs = n;
3646 /* Check whether TYPE is a homogeneous floating point aggregate. If
3647 it is, return the mode of the floating point type that appears
3648 in all leafs. If it is not, return VOIDmode.
3650 An aggregate is a homogeneous floating point aggregate is if all
3651 fields/elements in it have the same floating point type (e.g,
3652 SFmode). 128-bit quad-precision floats are excluded.
3654 Variable sized aggregates should never arrive here, since we should
3655 have already decided to pass them by reference. Top-level zero-sized
3656 aggregates are excluded because our parallels crash the middle-end. */
3658 static enum machine_mode
3659 hfa_element_mode (tree type, bool nested)
3661 enum machine_mode element_mode = VOIDmode;
3662 enum machine_mode mode;
3663 enum tree_code code = TREE_CODE (type);
3664 int know_element_mode = 0;
3667 if (!nested && (!TYPE_SIZE (type) || integer_zerop (TYPE_SIZE (type))))
3672 case VOID_TYPE: case INTEGER_TYPE: case ENUMERAL_TYPE:
3673 case BOOLEAN_TYPE: case CHAR_TYPE: case POINTER_TYPE:
3674 case OFFSET_TYPE: case REFERENCE_TYPE: case METHOD_TYPE:
3675 case LANG_TYPE: case FUNCTION_TYPE:
3678 /* Fortran complex types are supposed to be HFAs, so we need to handle
3679 gcc's COMPLEX_TYPEs as HFAs. We need to exclude the integral complex
3682 if (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_COMPLEX_FLOAT
3683 && TYPE_MODE (type) != TCmode)
3684 return GET_MODE_INNER (TYPE_MODE (type));
3689 /* We want to return VOIDmode for raw REAL_TYPEs, but the actual
3690 mode if this is contained within an aggregate. */
3691 if (nested && TYPE_MODE (type) != TFmode)
3692 return TYPE_MODE (type);
3697 return hfa_element_mode (TREE_TYPE (type), 1);
3701 case QUAL_UNION_TYPE:
3702 for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
3704 if (TREE_CODE (t) != FIELD_DECL)
3707 mode = hfa_element_mode (TREE_TYPE (t), 1);
3708 if (know_element_mode)
3710 if (mode != element_mode)
3713 else if (GET_MODE_CLASS (mode) != MODE_FLOAT)
3717 know_element_mode = 1;
3718 element_mode = mode;
3721 return element_mode;
3724 /* If we reach here, we probably have some front-end specific type
3725 that the backend doesn't know about. This can happen via the
3726 aggregate_value_p call in init_function_start. All we can do is
3727 ignore unknown tree types. */
3734 /* Return the number of words required to hold a quantity of TYPE and MODE
3735 when passed as an argument. */
3737 ia64_function_arg_words (tree type, enum machine_mode mode)
3741 if (mode == BLKmode)
3742 words = int_size_in_bytes (type);
3744 words = GET_MODE_SIZE (mode);
3746 return (words + UNITS_PER_WORD - 1) / UNITS_PER_WORD; /* round up */
3749 /* Return the number of registers that should be skipped so the current
3750 argument (described by TYPE and WORDS) will be properly aligned.
3752 Integer and float arguments larger than 8 bytes start at the next
3753 even boundary. Aggregates larger than 8 bytes start at the next
3754 even boundary if the aggregate has 16 byte alignment. Note that
3755 in the 32-bit ABI, TImode and TFmode have only 8-byte alignment
3756 but are still to be aligned in registers.
3758 ??? The ABI does not specify how to handle aggregates with
3759 alignment from 9 to 15 bytes, or greater than 16. We handle them
3760 all as if they had 16 byte alignment. Such aggregates can occur
3761 only if gcc extensions are used. */
3763 ia64_function_arg_offset (CUMULATIVE_ARGS *cum, tree type, int words)
3765 if ((cum->words & 1) == 0)
3769 && TREE_CODE (type) != INTEGER_TYPE
3770 && TREE_CODE (type) != REAL_TYPE)
3771 return TYPE_ALIGN (type) > 8 * BITS_PER_UNIT;
3776 /* Return rtx for register where argument is passed, or zero if it is passed
3778 /* ??? 128-bit quad-precision floats are always passed in general
3782 ia64_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, tree type,
3783 int named, int incoming)
3785 int basereg = (incoming ? GR_ARG_FIRST : AR_ARG_FIRST);
3786 int words = ia64_function_arg_words (type, mode);
3787 int offset = ia64_function_arg_offset (cum, type, words);
3788 enum machine_mode hfa_mode = VOIDmode;
3790 /* If all argument slots are used, then it must go on the stack. */
3791 if (cum->words + offset >= MAX_ARGUMENT_SLOTS)
3794 /* Check for and handle homogeneous FP aggregates. */
3796 hfa_mode = hfa_element_mode (type, 0);
3798 /* Unnamed prototyped hfas are passed as usual. Named prototyped hfas
3799 and unprototyped hfas are passed specially. */
3800 if (hfa_mode != VOIDmode && (! cum->prototype || named))
3804 int fp_regs = cum->fp_regs;
3805 int int_regs = cum->words + offset;
3806 int hfa_size = GET_MODE_SIZE (hfa_mode);
3810 /* If prototyped, pass it in FR regs then GR regs.
3811 If not prototyped, pass it in both FR and GR regs.
3813 If this is an SFmode aggregate, then it is possible to run out of
3814 FR regs while GR regs are still left. In that case, we pass the
3815 remaining part in the GR regs. */
3817 /* Fill the FP regs. We do this always. We stop if we reach the end
3818 of the argument, the last FP register, or the last argument slot. */
3820 byte_size = ((mode == BLKmode)
3821 ? int_size_in_bytes (type) : GET_MODE_SIZE (mode));
3822 args_byte_size = int_regs * UNITS_PER_WORD;
3824 for (; (offset < byte_size && fp_regs < MAX_ARGUMENT_SLOTS
3825 && args_byte_size < (MAX_ARGUMENT_SLOTS * UNITS_PER_WORD)); i++)
3827 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
3828 gen_rtx_REG (hfa_mode, (FR_ARG_FIRST
3832 args_byte_size += hfa_size;
3836 /* If no prototype, then the whole thing must go in GR regs. */
3837 if (! cum->prototype)
3839 /* If this is an SFmode aggregate, then we might have some left over
3840 that needs to go in GR regs. */
3841 else if (byte_size != offset)
3842 int_regs += offset / UNITS_PER_WORD;
3844 /* Fill in the GR regs. We must use DImode here, not the hfa mode. */
3846 for (; offset < byte_size && int_regs < MAX_ARGUMENT_SLOTS; i++)
3848 enum machine_mode gr_mode = DImode;
3849 unsigned int gr_size;
3851 /* If we have an odd 4 byte hunk because we ran out of FR regs,
3852 then this goes in a GR reg left adjusted/little endian, right
3853 adjusted/big endian. */
3854 /* ??? Currently this is handled wrong, because 4-byte hunks are
3855 always right adjusted/little endian. */
3858 /* If we have an even 4 byte hunk because the aggregate is a
3859 multiple of 4 bytes in size, then this goes in a GR reg right
3860 adjusted/little endian. */
3861 else if (byte_size - offset == 4)
3864 loc[i] = gen_rtx_EXPR_LIST (VOIDmode,
3865 gen_rtx_REG (gr_mode, (basereg
3869 gr_size = GET_MODE_SIZE (gr_mode);
3871 if (gr_size == UNITS_PER_WORD
3872 || (gr_size < UNITS_PER_WORD && offset % UNITS_PER_WORD == 0))
3874 else if (gr_size > UNITS_PER_WORD)
3875 int_regs += gr_size / UNITS_PER_WORD;
3877 return gen_rtx_PARALLEL (mode, gen_rtvec_v (i, loc));
3880 /* Integral and aggregates go in general registers. If we have run out of
3881 FR registers, then FP values must also go in general registers. This can
3882 happen when we have a SFmode HFA. */
3883 else if (mode == TFmode || mode == TCmode
3884 || (! FLOAT_MODE_P (mode) || cum->fp_regs == MAX_ARGUMENT_SLOTS))
3886 int byte_size = ((mode == BLKmode)
3887 ? int_size_in_bytes (type) : GET_MODE_SIZE (mode));
3888 if (BYTES_BIG_ENDIAN
3889 && (mode == BLKmode || (type && AGGREGATE_TYPE_P (type)))
3890 && byte_size < UNITS_PER_WORD
3893 rtx gr_reg = gen_rtx_EXPR_LIST (VOIDmode,
3894 gen_rtx_REG (DImode,
3895 (basereg + cum->words
3898 return gen_rtx_PARALLEL (mode, gen_rtvec (1, gr_reg));
3901 return gen_rtx_REG (mode, basereg + cum->words + offset);
3905 /* If there is a prototype, then FP values go in a FR register when
3906 named, and in a GR register when unnamed. */
3907 else if (cum->prototype)
3910 return gen_rtx_REG (mode, FR_ARG_FIRST + cum->fp_regs);
3911 /* In big-endian mode, an anonymous SFmode value must be represented
3912 as (parallel:SF [(expr_list (reg:DI n) (const_int 0))]) to force
3913 the value into the high half of the general register. */
3914 else if (BYTES_BIG_ENDIAN && mode == SFmode)
3915 return gen_rtx_PARALLEL (mode,
3917 gen_rtx_EXPR_LIST (VOIDmode,
3918 gen_rtx_REG (DImode, basereg + cum->words + offset),
3920 /* Similarly, an anonymous XFmode or RFmode value must be split
3921 into two registers and padded appropriately. */
3922 else if (BYTES_BIG_ENDIAN && (mode == XFmode || mode == RFmode))
3925 loc[0] = gen_rtx_EXPR_LIST (VOIDmode,
3926 gen_rtx_REG (DImode, basereg + cum->words + offset),
3928 loc[1] = gen_rtx_EXPR_LIST (VOIDmode,
3929 gen_rtx_REG (DImode, basereg + cum->words + offset + 1),
3930 GEN_INT (UNITS_PER_WORD));
3931 return gen_rtx_PARALLEL (mode, gen_rtvec_v (2, loc));
3934 return gen_rtx_REG (mode, basereg + cum->words + offset);
3936 /* If there is no prototype, then FP values go in both FR and GR
3940 /* See comment above. */
3941 enum machine_mode inner_mode =
3942 (BYTES_BIG_ENDIAN && mode == SFmode) ? DImode : mode;
3944 rtx fp_reg = gen_rtx_EXPR_LIST (VOIDmode,
3945 gen_rtx_REG (mode, (FR_ARG_FIRST
3948 rtx gr_reg = gen_rtx_EXPR_LIST (VOIDmode,
3949 gen_rtx_REG (inner_mode,
3950 (basereg + cum->words
3954 return gen_rtx_PARALLEL (mode, gen_rtvec (2, fp_reg, gr_reg));
3958 /* Return number of bytes, at the beginning of the argument, that must be
3959 put in registers. 0 is the argument is entirely in registers or entirely
3963 ia64_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3964 tree type, bool named ATTRIBUTE_UNUSED)
3966 int words = ia64_function_arg_words (type, mode);
3967 int offset = ia64_function_arg_offset (cum, type, words);
3969 /* If all argument slots are used, then it must go on the stack. */
3970 if (cum->words + offset >= MAX_ARGUMENT_SLOTS)
3973 /* It doesn't matter whether the argument goes in FR or GR regs. If
3974 it fits within the 8 argument slots, then it goes entirely in
3975 registers. If it extends past the last argument slot, then the rest
3976 goes on the stack. */
3978 if (words + cum->words + offset <= MAX_ARGUMENT_SLOTS)
3981 return (MAX_ARGUMENT_SLOTS - cum->words - offset) * UNITS_PER_WORD;
3984 /* Update CUM to point after this argument. This is patterned after
3985 ia64_function_arg. */
3988 ia64_function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3989 tree type, int named)
3991 int words = ia64_function_arg_words (type, mode);
3992 int offset = ia64_function_arg_offset (cum, type, words);
3993 enum machine_mode hfa_mode = VOIDmode;
3995 /* If all arg slots are already full, then there is nothing to do. */
3996 if (cum->words >= MAX_ARGUMENT_SLOTS)
3999 cum->words += words + offset;
4001 /* Check for and handle homogeneous FP aggregates. */
4003 hfa_mode = hfa_element_mode (type, 0);
4005 /* Unnamed prototyped hfas are passed as usual. Named prototyped hfas
4006 and unprototyped hfas are passed specially. */
4007 if (hfa_mode != VOIDmode && (! cum->prototype || named))
4009 int fp_regs = cum->fp_regs;
4010 /* This is the original value of cum->words + offset. */
4011 int int_regs = cum->words - words;
4012 int hfa_size = GET_MODE_SIZE (hfa_mode);
4016 /* If prototyped, pass it in FR regs then GR regs.
4017 If not prototyped, pass it in both FR and GR regs.
4019 If this is an SFmode aggregate, then it is possible to run out of
4020 FR regs while GR regs are still left. In that case, we pass the
4021 remaining part in the GR regs. */
4023 /* Fill the FP regs. We do this always. We stop if we reach the end
4024 of the argument, the last FP register, or the last argument slot. */
4026 byte_size = ((mode == BLKmode)
4027 ? int_size_in_bytes (type) : GET_MODE_SIZE (mode));
4028 args_byte_size = int_regs * UNITS_PER_WORD;
4030 for (; (offset < byte_size && fp_regs < MAX_ARGUMENT_SLOTS
4031 && args_byte_size < (MAX_ARGUMENT_SLOTS * UNITS_PER_WORD));)
4034 args_byte_size += hfa_size;