1 /* Definitions of target machine for GNU compiler.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009 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 3, 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 COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
43 #include "basic-block.h"
45 #include "sched-int.h"
48 #include "target-def.h"
51 #include "langhooks.h"
52 #include "cfglayout.h"
59 #include "tm-constrs.h"
60 #include "sel-sched.h"
62 /* This is used for communication between ASM_OUTPUT_LABEL and
63 ASM_OUTPUT_LABELREF. */
64 int ia64_asm_output_label = 0;
66 /* Define the information needed to generate branch and scc insns. This is
67 stored from the compare operation. */
68 struct rtx_def * ia64_compare_op0;
69 struct rtx_def * ia64_compare_op1;
71 /* Register names for ia64_expand_prologue. */
72 static const char * const ia64_reg_numbers[96] =
73 { "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
74 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
75 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
76 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
77 "r64", "r65", "r66", "r67", "r68", "r69", "r70", "r71",
78 "r72", "r73", "r74", "r75", "r76", "r77", "r78", "r79",
79 "r80", "r81", "r82", "r83", "r84", "r85", "r86", "r87",
80 "r88", "r89", "r90", "r91", "r92", "r93", "r94", "r95",
81 "r96", "r97", "r98", "r99", "r100","r101","r102","r103",
82 "r104","r105","r106","r107","r108","r109","r110","r111",
83 "r112","r113","r114","r115","r116","r117","r118","r119",
84 "r120","r121","r122","r123","r124","r125","r126","r127"};
86 /* ??? These strings could be shared with REGISTER_NAMES. */
87 static const char * const ia64_input_reg_names[8] =
88 { "in0", "in1", "in2", "in3", "in4", "in5", "in6", "in7" };
90 /* ??? These strings could be shared with REGISTER_NAMES. */
91 static const char * const ia64_local_reg_names[80] =
92 { "loc0", "loc1", "loc2", "loc3", "loc4", "loc5", "loc6", "loc7",
93 "loc8", "loc9", "loc10","loc11","loc12","loc13","loc14","loc15",
94 "loc16","loc17","loc18","loc19","loc20","loc21","loc22","loc23",
95 "loc24","loc25","loc26","loc27","loc28","loc29","loc30","loc31",
96 "loc32","loc33","loc34","loc35","loc36","loc37","loc38","loc39",
97 "loc40","loc41","loc42","loc43","loc44","loc45","loc46","loc47",
98 "loc48","loc49","loc50","loc51","loc52","loc53","loc54","loc55",
99 "loc56","loc57","loc58","loc59","loc60","loc61","loc62","loc63",
100 "loc64","loc65","loc66","loc67","loc68","loc69","loc70","loc71",
101 "loc72","loc73","loc74","loc75","loc76","loc77","loc78","loc79" };
103 /* ??? These strings could be shared with REGISTER_NAMES. */
104 static const char * const ia64_output_reg_names[8] =
105 { "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7" };
107 /* Which cpu are we scheduling for. */
108 enum processor_type ia64_tune = PROCESSOR_ITANIUM2;
110 /* Determines whether we run our final scheduling pass or not. We always
111 avoid the normal second scheduling pass. */
112 static int ia64_flag_schedule_insns2;
114 /* Determines whether we run variable tracking in machine dependent
116 static int ia64_flag_var_tracking;
118 /* Variables which are this size or smaller are put in the sdata/sbss
121 unsigned int ia64_section_threshold;
123 /* The following variable is used by the DFA insn scheduler. The value is
124 TRUE if we do insn bundling instead of insn scheduling. */
136 number_of_ia64_frame_regs
139 /* Structure to be filled in by ia64_compute_frame_size with register
140 save masks and offsets for the current function. */
142 struct ia64_frame_info
144 HOST_WIDE_INT total_size; /* size of the stack frame, not including
145 the caller's scratch area. */
146 HOST_WIDE_INT spill_cfa_off; /* top of the reg spill area from the cfa. */
147 HOST_WIDE_INT spill_size; /* size of the gr/br/fr spill area. */
148 HOST_WIDE_INT extra_spill_size; /* size of spill area for others. */
149 HARD_REG_SET mask; /* mask of saved registers. */
150 unsigned int gr_used_mask; /* mask of registers in use as gr spill
151 registers or long-term scratches. */
152 int n_spilled; /* number of spilled registers. */
153 int r[number_of_ia64_frame_regs]; /* Frame related registers. */
154 int n_input_regs; /* number of input registers used. */
155 int n_local_regs; /* number of local registers used. */
156 int n_output_regs; /* number of output registers used. */
157 int n_rotate_regs; /* number of rotating registers used. */
159 char need_regstk; /* true if a .regstk directive needed. */
160 char initialized; /* true if the data is finalized. */
163 /* Current frame information calculated by ia64_compute_frame_size. */
164 static struct ia64_frame_info current_frame_info;
165 /* The actual registers that are emitted. */
166 static int emitted_frame_related_regs[number_of_ia64_frame_regs];
168 static int ia64_first_cycle_multipass_dfa_lookahead (void);
169 static void ia64_dependencies_evaluation_hook (rtx, rtx);
170 static void ia64_init_dfa_pre_cycle_insn (void);
171 static rtx ia64_dfa_pre_cycle_insn (void);
172 static int ia64_first_cycle_multipass_dfa_lookahead_guard (rtx);
173 static bool ia64_first_cycle_multipass_dfa_lookahead_guard_spec (const_rtx);
174 static int ia64_dfa_new_cycle (FILE *, int, rtx, int, int, int *);
175 static void ia64_h_i_d_extended (void);
176 static void * ia64_alloc_sched_context (void);
177 static void ia64_init_sched_context (void *, bool);
178 static void ia64_set_sched_context (void *);
179 static void ia64_clear_sched_context (void *);
180 static void ia64_free_sched_context (void *);
181 static int ia64_mode_to_int (enum machine_mode);
182 static void ia64_set_sched_flags (spec_info_t);
183 static ds_t ia64_get_insn_spec_ds (rtx);
184 static ds_t ia64_get_insn_checked_ds (rtx);
185 static bool ia64_skip_rtx_p (const_rtx);
186 static int ia64_speculate_insn (rtx, ds_t, rtx *);
187 static bool ia64_needs_block_p (int);
188 static rtx ia64_gen_spec_check (rtx, rtx, ds_t);
189 static int ia64_spec_check_p (rtx);
190 static int ia64_spec_check_src_p (rtx);
191 static rtx gen_tls_get_addr (void);
192 static rtx gen_thread_pointer (void);
193 static int find_gr_spill (enum ia64_frame_regs, int);
194 static int next_scratch_gr_reg (void);
195 static void mark_reg_gr_used_mask (rtx, void *);
196 static void ia64_compute_frame_size (HOST_WIDE_INT);
197 static void setup_spill_pointers (int, rtx, HOST_WIDE_INT);
198 static void finish_spill_pointers (void);
199 static rtx spill_restore_mem (rtx, HOST_WIDE_INT);
200 static void do_spill (rtx (*)(rtx, rtx, rtx), rtx, HOST_WIDE_INT, rtx);
201 static void do_restore (rtx (*)(rtx, rtx, rtx), rtx, HOST_WIDE_INT);
202 static rtx gen_movdi_x (rtx, rtx, rtx);
203 static rtx gen_fr_spill_x (rtx, rtx, rtx);
204 static rtx gen_fr_restore_x (rtx, rtx, rtx);
206 static enum machine_mode hfa_element_mode (const_tree, bool);
207 static void ia64_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
209 static int ia64_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
211 static bool ia64_function_ok_for_sibcall (tree, tree);
212 static bool ia64_return_in_memory (const_tree, const_tree);
213 static bool ia64_rtx_costs (rtx, int, int, int *, bool);
214 static int ia64_unspec_may_trap_p (const_rtx, unsigned);
215 static void fix_range (const char *);
216 static bool ia64_handle_option (size_t, const char *, int);
217 static struct machine_function * ia64_init_machine_status (void);
218 static void emit_insn_group_barriers (FILE *);
219 static void emit_all_insn_group_barriers (FILE *);
220 static void final_emit_insn_group_barriers (FILE *);
221 static void emit_predicate_relation_info (void);
222 static void ia64_reorg (void);
223 static bool ia64_in_small_data_p (const_tree);
224 static void process_epilogue (FILE *, rtx, bool, bool);
225 static int process_set (FILE *, rtx, rtx, bool, bool);
227 static bool ia64_assemble_integer (rtx, unsigned int, int);
228 static void ia64_output_function_prologue (FILE *, HOST_WIDE_INT);
229 static void ia64_output_function_epilogue (FILE *, HOST_WIDE_INT);
230 static void ia64_output_function_end_prologue (FILE *);
232 static int ia64_issue_rate (void);
233 static int ia64_adjust_cost_2 (rtx, int, rtx, int, dw_t);
234 static void ia64_sched_init (FILE *, int, int);
235 static void ia64_sched_init_global (FILE *, int, int);
236 static void ia64_sched_finish_global (FILE *, int);
237 static void ia64_sched_finish (FILE *, int);
238 static int ia64_dfa_sched_reorder (FILE *, int, rtx *, int *, int, int);
239 static int ia64_sched_reorder (FILE *, int, rtx *, int *, int);
240 static int ia64_sched_reorder2 (FILE *, int, rtx *, int *, int);
241 static int ia64_variable_issue (FILE *, int, rtx, int);
243 static struct bundle_state *get_free_bundle_state (void);
244 static void free_bundle_state (struct bundle_state *);
245 static void initiate_bundle_states (void);
246 static void finish_bundle_states (void);
247 static unsigned bundle_state_hash (const void *);
248 static int bundle_state_eq_p (const void *, const void *);
249 static int insert_bundle_state (struct bundle_state *);
250 static void initiate_bundle_state_table (void);
251 static void finish_bundle_state_table (void);
252 static int try_issue_nops (struct bundle_state *, int);
253 static int try_issue_insn (struct bundle_state *, rtx);
254 static void issue_nops_and_insn (struct bundle_state *, int, rtx, int, int);
255 static int get_max_pos (state_t);
256 static int get_template (state_t, int);
258 static rtx get_next_important_insn (rtx, rtx);
259 static bool important_for_bundling_p (rtx);
260 static void bundling (FILE *, int, rtx, rtx);
262 static void ia64_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
263 HOST_WIDE_INT, tree);
264 static void ia64_file_start (void);
265 static void ia64_globalize_decl_name (FILE *, tree);
267 static int ia64_hpux_reloc_rw_mask (void) ATTRIBUTE_UNUSED;
268 static int ia64_reloc_rw_mask (void) ATTRIBUTE_UNUSED;
269 static section *ia64_select_rtx_section (enum machine_mode, rtx,
270 unsigned HOST_WIDE_INT);
271 static void ia64_output_dwarf_dtprel (FILE *, int, rtx)
273 static unsigned int ia64_section_type_flags (tree, const char *, int);
274 static void ia64_init_libfuncs (void)
276 static void ia64_hpux_init_libfuncs (void)
278 static void ia64_sysv4_init_libfuncs (void)
280 static void ia64_vms_init_libfuncs (void)
282 static void ia64_soft_fp_init_libfuncs (void)
285 static tree ia64_handle_model_attribute (tree *, tree, tree, int, bool *);
286 static tree ia64_handle_version_id_attribute (tree *, tree, tree, int, bool *);
287 static void ia64_encode_section_info (tree, rtx, int);
288 static rtx ia64_struct_value_rtx (tree, int);
289 static tree ia64_gimplify_va_arg (tree, tree, gimple_seq *, gimple_seq *);
290 static bool ia64_scalar_mode_supported_p (enum machine_mode mode);
291 static bool ia64_vector_mode_supported_p (enum machine_mode mode);
292 static bool ia64_cannot_force_const_mem (rtx);
293 static const char *ia64_mangle_type (const_tree);
294 static const char *ia64_invalid_conversion (const_tree, const_tree);
295 static const char *ia64_invalid_unary_op (int, const_tree);
296 static const char *ia64_invalid_binary_op (int, const_tree, const_tree);
297 static enum machine_mode ia64_c_mode_for_suffix (char);
299 /* Table of valid machine attributes. */
300 static const struct attribute_spec ia64_attribute_table[] =
302 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
303 { "syscall_linkage", 0, 0, false, true, true, NULL },
304 { "model", 1, 1, true, false, false, ia64_handle_model_attribute },
305 { "version_id", 1, 1, true, false, false,
306 ia64_handle_version_id_attribute },
307 { NULL, 0, 0, false, false, false, NULL }
310 /* Initialize the GCC target structure. */
311 #undef TARGET_ATTRIBUTE_TABLE
312 #define TARGET_ATTRIBUTE_TABLE ia64_attribute_table
314 #undef TARGET_INIT_BUILTINS
315 #define TARGET_INIT_BUILTINS ia64_init_builtins
317 #undef TARGET_EXPAND_BUILTIN
318 #define TARGET_EXPAND_BUILTIN ia64_expand_builtin
320 #undef TARGET_ASM_BYTE_OP
321 #define TARGET_ASM_BYTE_OP "\tdata1\t"
322 #undef TARGET_ASM_ALIGNED_HI_OP
323 #define TARGET_ASM_ALIGNED_HI_OP "\tdata2\t"
324 #undef TARGET_ASM_ALIGNED_SI_OP
325 #define TARGET_ASM_ALIGNED_SI_OP "\tdata4\t"
326 #undef TARGET_ASM_ALIGNED_DI_OP
327 #define TARGET_ASM_ALIGNED_DI_OP "\tdata8\t"
328 #undef TARGET_ASM_UNALIGNED_HI_OP
329 #define TARGET_ASM_UNALIGNED_HI_OP "\tdata2.ua\t"
330 #undef TARGET_ASM_UNALIGNED_SI_OP
331 #define TARGET_ASM_UNALIGNED_SI_OP "\tdata4.ua\t"
332 #undef TARGET_ASM_UNALIGNED_DI_OP
333 #define TARGET_ASM_UNALIGNED_DI_OP "\tdata8.ua\t"
334 #undef TARGET_ASM_INTEGER
335 #define TARGET_ASM_INTEGER ia64_assemble_integer
337 #undef TARGET_ASM_FUNCTION_PROLOGUE
338 #define TARGET_ASM_FUNCTION_PROLOGUE ia64_output_function_prologue
339 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
340 #define TARGET_ASM_FUNCTION_END_PROLOGUE ia64_output_function_end_prologue
341 #undef TARGET_ASM_FUNCTION_EPILOGUE
342 #define TARGET_ASM_FUNCTION_EPILOGUE ia64_output_function_epilogue
344 #undef TARGET_IN_SMALL_DATA_P
345 #define TARGET_IN_SMALL_DATA_P ia64_in_small_data_p
347 #undef TARGET_SCHED_ADJUST_COST_2
348 #define TARGET_SCHED_ADJUST_COST_2 ia64_adjust_cost_2
349 #undef TARGET_SCHED_ISSUE_RATE
350 #define TARGET_SCHED_ISSUE_RATE ia64_issue_rate
351 #undef TARGET_SCHED_VARIABLE_ISSUE
352 #define TARGET_SCHED_VARIABLE_ISSUE ia64_variable_issue
353 #undef TARGET_SCHED_INIT
354 #define TARGET_SCHED_INIT ia64_sched_init
355 #undef TARGET_SCHED_FINISH
356 #define TARGET_SCHED_FINISH ia64_sched_finish
357 #undef TARGET_SCHED_INIT_GLOBAL
358 #define TARGET_SCHED_INIT_GLOBAL ia64_sched_init_global
359 #undef TARGET_SCHED_FINISH_GLOBAL
360 #define TARGET_SCHED_FINISH_GLOBAL ia64_sched_finish_global
361 #undef TARGET_SCHED_REORDER
362 #define TARGET_SCHED_REORDER ia64_sched_reorder
363 #undef TARGET_SCHED_REORDER2
364 #define TARGET_SCHED_REORDER2 ia64_sched_reorder2
366 #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
367 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK ia64_dependencies_evaluation_hook
369 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
370 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD ia64_first_cycle_multipass_dfa_lookahead
372 #undef TARGET_SCHED_INIT_DFA_PRE_CYCLE_INSN
373 #define TARGET_SCHED_INIT_DFA_PRE_CYCLE_INSN ia64_init_dfa_pre_cycle_insn
374 #undef TARGET_SCHED_DFA_PRE_CYCLE_INSN
375 #define TARGET_SCHED_DFA_PRE_CYCLE_INSN ia64_dfa_pre_cycle_insn
377 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD
378 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD\
379 ia64_first_cycle_multipass_dfa_lookahead_guard
381 #undef TARGET_SCHED_DFA_NEW_CYCLE
382 #define TARGET_SCHED_DFA_NEW_CYCLE ia64_dfa_new_cycle
384 #undef TARGET_SCHED_H_I_D_EXTENDED
385 #define TARGET_SCHED_H_I_D_EXTENDED ia64_h_i_d_extended
387 #undef TARGET_SCHED_ALLOC_SCHED_CONTEXT
388 #define TARGET_SCHED_ALLOC_SCHED_CONTEXT ia64_alloc_sched_context
390 #undef TARGET_SCHED_INIT_SCHED_CONTEXT
391 #define TARGET_SCHED_INIT_SCHED_CONTEXT ia64_init_sched_context
393 #undef TARGET_SCHED_SET_SCHED_CONTEXT
394 #define TARGET_SCHED_SET_SCHED_CONTEXT ia64_set_sched_context
396 #undef TARGET_SCHED_CLEAR_SCHED_CONTEXT
397 #define TARGET_SCHED_CLEAR_SCHED_CONTEXT ia64_clear_sched_context
399 #undef TARGET_SCHED_FREE_SCHED_CONTEXT
400 #define TARGET_SCHED_FREE_SCHED_CONTEXT ia64_free_sched_context
402 #undef TARGET_SCHED_SET_SCHED_FLAGS
403 #define TARGET_SCHED_SET_SCHED_FLAGS ia64_set_sched_flags
405 #undef TARGET_SCHED_GET_INSN_SPEC_DS
406 #define TARGET_SCHED_GET_INSN_SPEC_DS ia64_get_insn_spec_ds
408 #undef TARGET_SCHED_GET_INSN_CHECKED_DS
409 #define TARGET_SCHED_GET_INSN_CHECKED_DS ia64_get_insn_checked_ds
411 #undef TARGET_SCHED_SPECULATE_INSN
412 #define TARGET_SCHED_SPECULATE_INSN ia64_speculate_insn
414 #undef TARGET_SCHED_NEEDS_BLOCK_P
415 #define TARGET_SCHED_NEEDS_BLOCK_P ia64_needs_block_p
417 #undef TARGET_SCHED_GEN_SPEC_CHECK
418 #define TARGET_SCHED_GEN_SPEC_CHECK ia64_gen_spec_check
420 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD_SPEC
421 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD_SPEC\
422 ia64_first_cycle_multipass_dfa_lookahead_guard_spec
424 #undef TARGET_SCHED_SKIP_RTX_P
425 #define TARGET_SCHED_SKIP_RTX_P ia64_skip_rtx_p
427 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
428 #define TARGET_FUNCTION_OK_FOR_SIBCALL ia64_function_ok_for_sibcall
429 #undef TARGET_ARG_PARTIAL_BYTES
430 #define TARGET_ARG_PARTIAL_BYTES ia64_arg_partial_bytes
432 #undef TARGET_ASM_OUTPUT_MI_THUNK
433 #define TARGET_ASM_OUTPUT_MI_THUNK ia64_output_mi_thunk
434 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
435 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
437 #undef TARGET_ASM_FILE_START
438 #define TARGET_ASM_FILE_START ia64_file_start
440 #undef TARGET_ASM_GLOBALIZE_DECL_NAME
441 #define TARGET_ASM_GLOBALIZE_DECL_NAME ia64_globalize_decl_name
443 #undef TARGET_RTX_COSTS
444 #define TARGET_RTX_COSTS ia64_rtx_costs
445 #undef TARGET_ADDRESS_COST
446 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
448 #undef TARGET_UNSPEC_MAY_TRAP_P
449 #define TARGET_UNSPEC_MAY_TRAP_P ia64_unspec_may_trap_p
451 #undef TARGET_MACHINE_DEPENDENT_REORG
452 #define TARGET_MACHINE_DEPENDENT_REORG ia64_reorg
454 #undef TARGET_ENCODE_SECTION_INFO
455 #define TARGET_ENCODE_SECTION_INFO ia64_encode_section_info
457 #undef TARGET_SECTION_TYPE_FLAGS
458 #define TARGET_SECTION_TYPE_FLAGS ia64_section_type_flags
461 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
462 #define TARGET_ASM_OUTPUT_DWARF_DTPREL ia64_output_dwarf_dtprel
465 /* ??? ABI doesn't allow us to define this. */
467 #undef TARGET_PROMOTE_FUNCTION_ARGS
468 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
471 /* ??? ABI doesn't allow us to define this. */
473 #undef TARGET_PROMOTE_FUNCTION_RETURN
474 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
477 /* ??? Investigate. */
479 #undef TARGET_PROMOTE_PROTOTYPES
480 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
483 #undef TARGET_STRUCT_VALUE_RTX
484 #define TARGET_STRUCT_VALUE_RTX ia64_struct_value_rtx
485 #undef TARGET_RETURN_IN_MEMORY
486 #define TARGET_RETURN_IN_MEMORY ia64_return_in_memory
487 #undef TARGET_SETUP_INCOMING_VARARGS
488 #define TARGET_SETUP_INCOMING_VARARGS ia64_setup_incoming_varargs
489 #undef TARGET_STRICT_ARGUMENT_NAMING
490 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
491 #undef TARGET_MUST_PASS_IN_STACK
492 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
494 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
495 #define TARGET_GIMPLIFY_VA_ARG_EXPR ia64_gimplify_va_arg
497 #undef TARGET_UNWIND_EMIT
498 #define TARGET_UNWIND_EMIT process_for_unwind_directive
500 #undef TARGET_SCALAR_MODE_SUPPORTED_P
501 #define TARGET_SCALAR_MODE_SUPPORTED_P ia64_scalar_mode_supported_p
502 #undef TARGET_VECTOR_MODE_SUPPORTED_P
503 #define TARGET_VECTOR_MODE_SUPPORTED_P ia64_vector_mode_supported_p
505 /* ia64 architecture manual 4.4.7: ... reads, writes, and flushes may occur
506 in an order different from the specified program order. */
507 #undef TARGET_RELAXED_ORDERING
508 #define TARGET_RELAXED_ORDERING true
510 #undef TARGET_DEFAULT_TARGET_FLAGS
511 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | TARGET_CPU_DEFAULT)
512 #undef TARGET_HANDLE_OPTION
513 #define TARGET_HANDLE_OPTION ia64_handle_option
515 #undef TARGET_CANNOT_FORCE_CONST_MEM
516 #define TARGET_CANNOT_FORCE_CONST_MEM ia64_cannot_force_const_mem
518 #undef TARGET_MANGLE_TYPE
519 #define TARGET_MANGLE_TYPE ia64_mangle_type
521 #undef TARGET_INVALID_CONVERSION
522 #define TARGET_INVALID_CONVERSION ia64_invalid_conversion
523 #undef TARGET_INVALID_UNARY_OP
524 #define TARGET_INVALID_UNARY_OP ia64_invalid_unary_op
525 #undef TARGET_INVALID_BINARY_OP
526 #define TARGET_INVALID_BINARY_OP ia64_invalid_binary_op
528 #undef TARGET_C_MODE_FOR_SUFFIX
529 #define TARGET_C_MODE_FOR_SUFFIX ia64_c_mode_for_suffix
531 struct gcc_target targetm = TARGET_INITIALIZER;
535 ADDR_AREA_NORMAL, /* normal address area */
536 ADDR_AREA_SMALL /* addressable by "addl" (-2MB < addr < 2MB) */
540 static GTY(()) tree small_ident1;
541 static GTY(()) tree small_ident2;
546 if (small_ident1 == 0)
548 small_ident1 = get_identifier ("small");
549 small_ident2 = get_identifier ("__small__");
553 /* Retrieve the address area that has been chosen for the given decl. */
555 static ia64_addr_area
556 ia64_get_addr_area (tree decl)
560 model_attr = lookup_attribute ("model", DECL_ATTRIBUTES (decl));
566 id = TREE_VALUE (TREE_VALUE (model_attr));
567 if (id == small_ident1 || id == small_ident2)
568 return ADDR_AREA_SMALL;
570 return ADDR_AREA_NORMAL;
574 ia64_handle_model_attribute (tree *node, tree name, tree args,
575 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
577 ia64_addr_area addr_area = ADDR_AREA_NORMAL;
579 tree arg, decl = *node;
582 arg = TREE_VALUE (args);
583 if (arg == small_ident1 || arg == small_ident2)
585 addr_area = ADDR_AREA_SMALL;
589 warning (OPT_Wattributes, "invalid argument of %qs attribute",
590 IDENTIFIER_POINTER (name));
591 *no_add_attrs = true;
594 switch (TREE_CODE (decl))
597 if ((DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl))
599 && !TREE_STATIC (decl))
601 error ("%Jan address area attribute cannot be specified for "
602 "local variables", decl);
603 *no_add_attrs = true;
605 area = ia64_get_addr_area (decl);
606 if (area != ADDR_AREA_NORMAL && addr_area != area)
608 error ("address area of %q+D conflicts with previous "
609 "declaration", decl);
610 *no_add_attrs = true;
615 error ("%Jaddress area attribute cannot be specified for functions",
617 *no_add_attrs = true;
621 warning (OPT_Wattributes, "%qs attribute ignored",
622 IDENTIFIER_POINTER (name));
623 *no_add_attrs = true;
631 ia64_encode_addr_area (tree decl, rtx symbol)
635 flags = SYMBOL_REF_FLAGS (symbol);
636 switch (ia64_get_addr_area (decl))
638 case ADDR_AREA_NORMAL: break;
639 case ADDR_AREA_SMALL: flags |= SYMBOL_FLAG_SMALL_ADDR; break;
640 default: gcc_unreachable ();
642 SYMBOL_REF_FLAGS (symbol) = flags;
646 ia64_encode_section_info (tree decl, rtx rtl, int first)
648 default_encode_section_info (decl, rtl, first);
650 /* Careful not to prod global register variables. */
651 if (TREE_CODE (decl) == VAR_DECL
652 && GET_CODE (DECL_RTL (decl)) == MEM
653 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF
654 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
655 ia64_encode_addr_area (decl, XEXP (rtl, 0));
658 /* Return 1 if the operands of a move are ok. */
661 ia64_move_ok (rtx dst, rtx src)
663 /* If we're under init_recog_no_volatile, we'll not be able to use
664 memory_operand. So check the code directly and don't worry about
665 the validity of the underlying address, which should have been
666 checked elsewhere anyway. */
667 if (GET_CODE (dst) != MEM)
669 if (GET_CODE (src) == MEM)
671 if (register_operand (src, VOIDmode))
674 /* Otherwise, this must be a constant, and that either 0 or 0.0 or 1.0. */
675 if (INTEGRAL_MODE_P (GET_MODE (dst)))
676 return src == const0_rtx;
678 return satisfies_constraint_G (src);
681 /* Return 1 if the operands are ok for a floating point load pair. */
684 ia64_load_pair_ok (rtx dst, rtx src)
686 if (GET_CODE (dst) != REG || !FP_REGNO_P (REGNO (dst)))
688 if (GET_CODE (src) != MEM || MEM_VOLATILE_P (src))
690 switch (GET_CODE (XEXP (src, 0)))
699 rtx adjust = XEXP (XEXP (XEXP (src, 0), 1), 1);
701 if (GET_CODE (adjust) != CONST_INT
702 || INTVAL (adjust) != GET_MODE_SIZE (GET_MODE (src)))
713 addp4_optimize_ok (rtx op1, rtx op2)
715 return (basereg_operand (op1, GET_MODE(op1)) !=
716 basereg_operand (op2, GET_MODE(op2)));
719 /* Check if OP is a mask suitable for use with SHIFT in a dep.z instruction.
720 Return the length of the field, or <= 0 on failure. */
723 ia64_depz_field_mask (rtx rop, rtx rshift)
725 unsigned HOST_WIDE_INT op = INTVAL (rop);
726 unsigned HOST_WIDE_INT shift = INTVAL (rshift);
728 /* Get rid of the zero bits we're shifting in. */
731 /* We must now have a solid block of 1's at bit 0. */
732 return exact_log2 (op + 1);
735 /* Return the TLS model to use for ADDR. */
737 static enum tls_model
738 tls_symbolic_operand_type (rtx addr)
740 enum tls_model tls_kind = 0;
742 if (GET_CODE (addr) == CONST)
744 if (GET_CODE (XEXP (addr, 0)) == PLUS
745 && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF)
746 tls_kind = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (addr, 0), 0));
748 else if (GET_CODE (addr) == SYMBOL_REF)
749 tls_kind = SYMBOL_REF_TLS_MODEL (addr);
754 /* Return true if X is a constant that is valid for some immediate
755 field in an instruction. */
758 ia64_legitimate_constant_p (rtx x)
760 switch (GET_CODE (x))
767 if (GET_MODE (x) == VOIDmode)
769 return satisfies_constraint_G (x);
773 /* ??? Short term workaround for PR 28490. We must make the code here
774 match the code in ia64_expand_move and move_operand, even though they
775 are both technically wrong. */
776 if (tls_symbolic_operand_type (x) == 0)
778 HOST_WIDE_INT addend = 0;
781 if (GET_CODE (op) == CONST
782 && GET_CODE (XEXP (op, 0)) == PLUS
783 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
785 addend = INTVAL (XEXP (XEXP (op, 0), 1));
786 op = XEXP (XEXP (op, 0), 0);
789 if (any_offset_symbol_operand (op, GET_MODE (op))
790 || function_operand (op, GET_MODE (op)))
792 if (aligned_offset_symbol_operand (op, GET_MODE (op)))
793 return (addend & 0x3fff) == 0;
800 enum machine_mode mode = GET_MODE (x);
802 if (mode == V2SFmode)
803 return satisfies_constraint_Y (x);
805 return (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
806 && GET_MODE_SIZE (mode) <= 8);
814 /* Don't allow TLS addresses to get spilled to memory. */
817 ia64_cannot_force_const_mem (rtx x)
819 if (GET_MODE (x) == RFmode)
821 return tls_symbolic_operand_type (x) != 0;
824 /* Expand a symbolic constant load. */
827 ia64_expand_load_address (rtx dest, rtx src)
829 gcc_assert (GET_CODE (dest) == REG);
831 /* ILP32 mode still loads 64-bits of data from the GOT. This avoids
832 having to pointer-extend the value afterward. Other forms of address
833 computation below are also more natural to compute as 64-bit quantities.
834 If we've been given an SImode destination register, change it. */
835 if (GET_MODE (dest) != Pmode)
836 dest = gen_rtx_REG_offset (dest, Pmode, REGNO (dest),
837 byte_lowpart_offset (Pmode, GET_MODE (dest)));
841 if (small_addr_symbolic_operand (src, VOIDmode))
845 emit_insn (gen_load_gprel64 (dest, src));
846 else if (GET_CODE (src) == SYMBOL_REF && SYMBOL_REF_FUNCTION_P (src))
847 emit_insn (gen_load_fptr (dest, src));
848 else if (sdata_symbolic_operand (src, VOIDmode))
849 emit_insn (gen_load_gprel (dest, src));
852 HOST_WIDE_INT addend = 0;
855 /* We did split constant offsets in ia64_expand_move, and we did try
856 to keep them split in move_operand, but we also allowed reload to
857 rematerialize arbitrary constants rather than spill the value to
858 the stack and reload it. So we have to be prepared here to split
860 if (GET_CODE (src) == CONST)
862 HOST_WIDE_INT hi, lo;
864 hi = INTVAL (XEXP (XEXP (src, 0), 1));
865 lo = ((hi & 0x3fff) ^ 0x2000) - 0x2000;
871 src = plus_constant (XEXP (XEXP (src, 0), 0), hi);
875 tmp = gen_rtx_HIGH (Pmode, src);
876 tmp = gen_rtx_PLUS (Pmode, tmp, pic_offset_table_rtx);
877 emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
879 tmp = gen_rtx_LO_SUM (Pmode, dest, src);
880 emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
884 tmp = gen_rtx_PLUS (Pmode, dest, GEN_INT (addend));
885 emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
892 static GTY(()) rtx gen_tls_tga;
894 gen_tls_get_addr (void)
897 gen_tls_tga = init_one_libfunc ("__tls_get_addr");
901 static GTY(()) rtx thread_pointer_rtx;
903 gen_thread_pointer (void)
905 if (!thread_pointer_rtx)
906 thread_pointer_rtx = gen_rtx_REG (Pmode, 13);
907 return thread_pointer_rtx;
911 ia64_expand_tls_address (enum tls_model tls_kind, rtx op0, rtx op1,
912 rtx orig_op1, HOST_WIDE_INT addend)
914 rtx tga_op1, tga_op2, tga_ret, tga_eqv, tmp, insns;
916 HOST_WIDE_INT addend_lo, addend_hi;
920 case TLS_MODEL_GLOBAL_DYNAMIC:
923 tga_op1 = gen_reg_rtx (Pmode);
924 emit_insn (gen_load_dtpmod (tga_op1, op1));
926 tga_op2 = gen_reg_rtx (Pmode);
927 emit_insn (gen_load_dtprel (tga_op2, op1));
929 tga_ret = emit_library_call_value (gen_tls_get_addr (), NULL_RTX,
930 LCT_CONST, Pmode, 2, tga_op1,
931 Pmode, tga_op2, Pmode);
933 insns = get_insns ();
936 if (GET_MODE (op0) != Pmode)
938 emit_libcall_block (insns, op0, tga_ret, op1);
941 case TLS_MODEL_LOCAL_DYNAMIC:
942 /* ??? This isn't the completely proper way to do local-dynamic
943 If the call to __tls_get_addr is used only by a single symbol,
944 then we should (somehow) move the dtprel to the second arg
945 to avoid the extra add. */
948 tga_op1 = gen_reg_rtx (Pmode);
949 emit_insn (gen_load_dtpmod (tga_op1, op1));
951 tga_op2 = const0_rtx;
953 tga_ret = emit_library_call_value (gen_tls_get_addr (), NULL_RTX,
954 LCT_CONST, Pmode, 2, tga_op1,
955 Pmode, tga_op2, Pmode);
957 insns = get_insns ();
960 tga_eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
962 tmp = gen_reg_rtx (Pmode);
963 emit_libcall_block (insns, tmp, tga_ret, tga_eqv);
965 if (!register_operand (op0, Pmode))
966 op0 = gen_reg_rtx (Pmode);
969 emit_insn (gen_load_dtprel (op0, op1));
970 emit_insn (gen_adddi3 (op0, tmp, op0));
973 emit_insn (gen_add_dtprel (op0, op1, tmp));
976 case TLS_MODEL_INITIAL_EXEC:
977 addend_lo = ((addend & 0x3fff) ^ 0x2000) - 0x2000;
978 addend_hi = addend - addend_lo;
980 op1 = plus_constant (op1, addend_hi);
983 tmp = gen_reg_rtx (Pmode);
984 emit_insn (gen_load_tprel (tmp, op1));
986 if (!register_operand (op0, Pmode))
987 op0 = gen_reg_rtx (Pmode);
988 emit_insn (gen_adddi3 (op0, tmp, gen_thread_pointer ()));
991 case TLS_MODEL_LOCAL_EXEC:
992 if (!register_operand (op0, Pmode))
993 op0 = gen_reg_rtx (Pmode);
999 emit_insn (gen_load_tprel (op0, op1));
1000 emit_insn (gen_adddi3 (op0, op0, gen_thread_pointer ()));
1003 emit_insn (gen_add_tprel (op0, op1, gen_thread_pointer ()));
1011 op0 = expand_simple_binop (Pmode, PLUS, op0, GEN_INT (addend),
1012 orig_op0, 1, OPTAB_DIRECT);
1013 if (orig_op0 == op0)
1015 if (GET_MODE (orig_op0) == Pmode)
1017 return gen_lowpart (GET_MODE (orig_op0), op0);
1021 ia64_expand_move (rtx op0, rtx op1)
1023 enum machine_mode mode = GET_MODE (op0);
1025 if (!reload_in_progress && !reload_completed && !ia64_move_ok (op0, op1))
1026 op1 = force_reg (mode, op1);
1028 if ((mode == Pmode || mode == ptr_mode) && symbolic_operand (op1, VOIDmode))
1030 HOST_WIDE_INT addend = 0;
1031 enum tls_model tls_kind;
1034 if (GET_CODE (op1) == CONST
1035 && GET_CODE (XEXP (op1, 0)) == PLUS
1036 && GET_CODE (XEXP (XEXP (op1, 0), 1)) == CONST_INT)
1038 addend = INTVAL (XEXP (XEXP (op1, 0), 1));
1039 sym = XEXP (XEXP (op1, 0), 0);
1042 tls_kind = tls_symbolic_operand_type (sym);
1044 return ia64_expand_tls_address (tls_kind, op0, sym, op1, addend);
1046 if (any_offset_symbol_operand (sym, mode))
1048 else if (aligned_offset_symbol_operand (sym, mode))
1050 HOST_WIDE_INT addend_lo, addend_hi;
1052 addend_lo = ((addend & 0x3fff) ^ 0x2000) - 0x2000;
1053 addend_hi = addend - addend_lo;
1057 op1 = plus_constant (sym, addend_hi);
1066 if (reload_completed)
1068 /* We really should have taken care of this offset earlier. */
1069 gcc_assert (addend == 0);
1070 if (ia64_expand_load_address (op0, op1))
1076 rtx subtarget = !can_create_pseudo_p () ? op0 : gen_reg_rtx (mode);
1078 emit_insn (gen_rtx_SET (VOIDmode, subtarget, op1));
1080 op1 = expand_simple_binop (mode, PLUS, subtarget,
1081 GEN_INT (addend), op0, 1, OPTAB_DIRECT);
1090 /* Split a move from OP1 to OP0 conditional on COND. */
1093 ia64_emit_cond_move (rtx op0, rtx op1, rtx cond)
1095 rtx insn, first = get_last_insn ();
1097 emit_move_insn (op0, op1);
1099 for (insn = get_last_insn (); insn != first; insn = PREV_INSN (insn))
1101 PATTERN (insn) = gen_rtx_COND_EXEC (VOIDmode, copy_rtx (cond),
1105 /* Split a post-reload TImode or TFmode reference into two DImode
1106 components. This is made extra difficult by the fact that we do
1107 not get any scratch registers to work with, because reload cannot
1108 be prevented from giving us a scratch that overlaps the register
1109 pair involved. So instead, when addressing memory, we tweak the
1110 pointer register up and back down with POST_INCs. Or up and not
1111 back down when we can get away with it.
1113 REVERSED is true when the loads must be done in reversed order
1114 (high word first) for correctness. DEAD is true when the pointer
1115 dies with the second insn we generate and therefore the second
1116 address must not carry a postmodify.
1118 May return an insn which is to be emitted after the moves. */
1121 ia64_split_tmode (rtx out[2], rtx in, bool reversed, bool dead)
1125 switch (GET_CODE (in))
1128 out[reversed] = gen_rtx_REG (DImode, REGNO (in));
1129 out[!reversed] = gen_rtx_REG (DImode, REGNO (in) + 1);
1134 /* Cannot occur reversed. */
1135 gcc_assert (!reversed);
1137 if (GET_MODE (in) != TFmode)
1138 split_double (in, &out[0], &out[1]);
1140 /* split_double does not understand how to split a TFmode
1141 quantity into a pair of DImode constants. */
1144 unsigned HOST_WIDE_INT p[2];
1145 long l[4]; /* TFmode is 128 bits */
1147 REAL_VALUE_FROM_CONST_DOUBLE (r, in);
1148 real_to_target (l, &r, TFmode);
1150 if (FLOAT_WORDS_BIG_ENDIAN)
1152 p[0] = (((unsigned HOST_WIDE_INT) l[0]) << 32) + l[1];
1153 p[1] = (((unsigned HOST_WIDE_INT) l[2]) << 32) + l[3];
1157 p[0] = (((unsigned HOST_WIDE_INT) l[1]) << 32) + l[0];
1158 p[1] = (((unsigned HOST_WIDE_INT) l[3]) << 32) + l[2];
1160 out[0] = GEN_INT (p[0]);
1161 out[1] = GEN_INT (p[1]);
1167 rtx base = XEXP (in, 0);
1170 switch (GET_CODE (base))
1175 out[0] = adjust_automodify_address
1176 (in, DImode, gen_rtx_POST_INC (Pmode, base), 0);
1177 out[1] = adjust_automodify_address
1178 (in, DImode, dead ? 0 : gen_rtx_POST_DEC (Pmode, base), 8);
1182 /* Reversal requires a pre-increment, which can only
1183 be done as a separate insn. */
1184 emit_insn (gen_adddi3 (base, base, GEN_INT (8)));
1185 out[0] = adjust_automodify_address
1186 (in, DImode, gen_rtx_POST_DEC (Pmode, base), 8);
1187 out[1] = adjust_address (in, DImode, 0);
1192 gcc_assert (!reversed && !dead);
1194 /* Just do the increment in two steps. */
1195 out[0] = adjust_automodify_address (in, DImode, 0, 0);
1196 out[1] = adjust_automodify_address (in, DImode, 0, 8);
1200 gcc_assert (!reversed && !dead);
1202 /* Add 8, subtract 24. */
1203 base = XEXP (base, 0);
1204 out[0] = adjust_automodify_address
1205 (in, DImode, gen_rtx_POST_INC (Pmode, base), 0);
1206 out[1] = adjust_automodify_address
1208 gen_rtx_POST_MODIFY (Pmode, base, plus_constant (base, -24)),
1213 gcc_assert (!reversed && !dead);
1215 /* Extract and adjust the modification. This case is
1216 trickier than the others, because we might have an
1217 index register, or we might have a combined offset that
1218 doesn't fit a signed 9-bit displacement field. We can
1219 assume the incoming expression is already legitimate. */
1220 offset = XEXP (base, 1);
1221 base = XEXP (base, 0);
1223 out[0] = adjust_automodify_address
1224 (in, DImode, gen_rtx_POST_INC (Pmode, base), 0);
1226 if (GET_CODE (XEXP (offset, 1)) == REG)
1228 /* Can't adjust the postmodify to match. Emit the
1229 original, then a separate addition insn. */
1230 out[1] = adjust_automodify_address (in, DImode, 0, 8);
1231 fixup = gen_adddi3 (base, base, GEN_INT (-8));
1235 gcc_assert (GET_CODE (XEXP (offset, 1)) == CONST_INT);
1236 if (INTVAL (XEXP (offset, 1)) < -256 + 8)
1238 /* Again the postmodify cannot be made to match,
1239 but in this case it's more efficient to get rid
1240 of the postmodify entirely and fix up with an
1242 out[1] = adjust_automodify_address (in, DImode, base, 8);
1244 (base, base, GEN_INT (INTVAL (XEXP (offset, 1)) - 8));
1248 /* Combined offset still fits in the displacement field.
1249 (We cannot overflow it at the high end.) */
1250 out[1] = adjust_automodify_address
1251 (in, DImode, gen_rtx_POST_MODIFY
1252 (Pmode, base, gen_rtx_PLUS
1254 GEN_INT (INTVAL (XEXP (offset, 1)) - 8))),
1273 /* Split a TImode or TFmode move instruction after reload.
1274 This is used by *movtf_internal and *movti_internal. */
1276 ia64_split_tmode_move (rtx operands[])
1278 rtx in[2], out[2], insn;
1281 bool reversed = false;
1283 /* It is possible for reload to decide to overwrite a pointer with
1284 the value it points to. In that case we have to do the loads in
1285 the appropriate order so that the pointer is not destroyed too
1286 early. Also we must not generate a postmodify for that second
1287 load, or rws_access_regno will die. */
1288 if (GET_CODE (operands[1]) == MEM
1289 && reg_overlap_mentioned_p (operands[0], operands[1]))
1291 rtx base = XEXP (operands[1], 0);
1292 while (GET_CODE (base) != REG)
1293 base = XEXP (base, 0);
1295 if (REGNO (base) == REGNO (operands[0]))
1299 /* Another reason to do the moves in reversed order is if the first
1300 element of the target register pair is also the second element of
1301 the source register pair. */
1302 if (GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
1303 && REGNO (operands[0]) == REGNO (operands[1]) + 1)
1306 fixup[0] = ia64_split_tmode (in, operands[1], reversed, dead);
1307 fixup[1] = ia64_split_tmode (out, operands[0], reversed, dead);
1309 #define MAYBE_ADD_REG_INC_NOTE(INSN, EXP) \
1310 if (GET_CODE (EXP) == MEM \
1311 && (GET_CODE (XEXP (EXP, 0)) == POST_MODIFY \
1312 || GET_CODE (XEXP (EXP, 0)) == POST_INC \
1313 || GET_CODE (XEXP (EXP, 0)) == POST_DEC)) \
1314 REG_NOTES (INSN) = gen_rtx_EXPR_LIST (REG_INC, \
1315 XEXP (XEXP (EXP, 0), 0), \
1318 insn = emit_insn (gen_rtx_SET (VOIDmode, out[0], in[0]));
1319 MAYBE_ADD_REG_INC_NOTE (insn, in[0]);
1320 MAYBE_ADD_REG_INC_NOTE (insn, out[0]);
1322 insn = emit_insn (gen_rtx_SET (VOIDmode, out[1], in[1]));
1323 MAYBE_ADD_REG_INC_NOTE (insn, in[1]);
1324 MAYBE_ADD_REG_INC_NOTE (insn, out[1]);
1327 emit_insn (fixup[0]);
1329 emit_insn (fixup[1]);
1331 #undef MAYBE_ADD_REG_INC_NOTE
1334 /* ??? Fixing GR->FR XFmode moves during reload is hard. You need to go
1335 through memory plus an extra GR scratch register. Except that you can
1336 either get the first from SECONDARY_MEMORY_NEEDED or the second from
1337 SECONDARY_RELOAD_CLASS, but not both.
1339 We got into problems in the first place by allowing a construct like
1340 (subreg:XF (reg:TI)), which we got from a union containing a long double.
1341 This solution attempts to prevent this situation from occurring. When
1342 we see something like the above, we spill the inner register to memory. */
1345 spill_xfmode_rfmode_operand (rtx in, int force, enum machine_mode mode)
1347 if (GET_CODE (in) == SUBREG
1348 && GET_MODE (SUBREG_REG (in)) == TImode
1349 && GET_CODE (SUBREG_REG (in)) == REG)
1351 rtx memt = assign_stack_temp (TImode, 16, 0);
1352 emit_move_insn (memt, SUBREG_REG (in));
1353 return adjust_address (memt, mode, 0);
1355 else if (force && GET_CODE (in) == REG)
1357 rtx memx = assign_stack_temp (mode, 16, 0);
1358 emit_move_insn (memx, in);
1365 /* Expand the movxf or movrf pattern (MODE says which) with the given
1366 OPERANDS, returning true if the pattern should then invoke
1370 ia64_expand_movxf_movrf (enum machine_mode mode, rtx operands[])
1372 rtx op0 = operands[0];
1374 if (GET_CODE (op0) == SUBREG)
1375 op0 = SUBREG_REG (op0);
1377 /* We must support XFmode loads into general registers for stdarg/vararg,
1378 unprototyped calls, and a rare case where a long double is passed as
1379 an argument after a float HFA fills the FP registers. We split them into
1380 DImode loads for convenience. We also need to support XFmode stores
1381 for the last case. This case does not happen for stdarg/vararg routines,
1382 because we do a block store to memory of unnamed arguments. */
1384 if (GET_CODE (op0) == REG && GR_REGNO_P (REGNO (op0)))
1388 /* We're hoping to transform everything that deals with XFmode
1389 quantities and GR registers early in the compiler. */
1390 gcc_assert (can_create_pseudo_p ());
1392 /* Struct to register can just use TImode instead. */
1393 if ((GET_CODE (operands[1]) == SUBREG
1394 && GET_MODE (SUBREG_REG (operands[1])) == TImode)
1395 || (GET_CODE (operands[1]) == REG
1396 && GR_REGNO_P (REGNO (operands[1]))))
1398 rtx op1 = operands[1];
1400 if (GET_CODE (op1) == SUBREG)
1401 op1 = SUBREG_REG (op1);
1403 op1 = gen_rtx_REG (TImode, REGNO (op1));
1405 emit_move_insn (gen_rtx_REG (TImode, REGNO (op0)), op1);
1409 if (GET_CODE (operands[1]) == CONST_DOUBLE)
1411 /* Don't word-swap when reading in the constant. */
1412 emit_move_insn (gen_rtx_REG (DImode, REGNO (op0)),
1413 operand_subword (operands[1], WORDS_BIG_ENDIAN,
1415 emit_move_insn (gen_rtx_REG (DImode, REGNO (op0) + 1),
1416 operand_subword (operands[1], !WORDS_BIG_ENDIAN,
1421 /* If the quantity is in a register not known to be GR, spill it. */
1422 if (register_operand (operands[1], mode))
1423 operands[1] = spill_xfmode_rfmode_operand (operands[1], 1, mode);
1425 gcc_assert (GET_CODE (operands[1]) == MEM);
1427 /* Don't word-swap when reading in the value. */
1428 out[0] = gen_rtx_REG (DImode, REGNO (op0));
1429 out[1] = gen_rtx_REG (DImode, REGNO (op0) + 1);
1431 emit_move_insn (out[0], adjust_address (operands[1], DImode, 0));
1432 emit_move_insn (out[1], adjust_address (operands[1], DImode, 8));
1436 if (GET_CODE (operands[1]) == REG && GR_REGNO_P (REGNO (operands[1])))
1438 /* We're hoping to transform everything that deals with XFmode
1439 quantities and GR registers early in the compiler. */
1440 gcc_assert (can_create_pseudo_p ());
1442 /* Op0 can't be a GR_REG here, as that case is handled above.
1443 If op0 is a register, then we spill op1, so that we now have a
1444 MEM operand. This requires creating an XFmode subreg of a TImode reg
1445 to force the spill. */
1446 if (register_operand (operands[0], mode))
1448 rtx op1 = gen_rtx_REG (TImode, REGNO (operands[1]));
1449 op1 = gen_rtx_SUBREG (mode, op1, 0);
1450 operands[1] = spill_xfmode_rfmode_operand (op1, 0, mode);
1457 gcc_assert (GET_CODE (operands[0]) == MEM);
1459 /* Don't word-swap when writing out the value. */
1460 in[0] = gen_rtx_REG (DImode, REGNO (operands[1]));
1461 in[1] = gen_rtx_REG (DImode, REGNO (operands[1]) + 1);
1463 emit_move_insn (adjust_address (operands[0], DImode, 0), in[0]);
1464 emit_move_insn (adjust_address (operands[0], DImode, 8), in[1]);
1469 if (!reload_in_progress && !reload_completed)
1471 operands[1] = spill_xfmode_rfmode_operand (operands[1], 0, mode);
1473 if (GET_MODE (op0) == TImode && GET_CODE (op0) == REG)
1475 rtx memt, memx, in = operands[1];
1476 if (CONSTANT_P (in))
1477 in = validize_mem (force_const_mem (mode, in));
1478 if (GET_CODE (in) == MEM)
1479 memt = adjust_address (in, TImode, 0);
1482 memt = assign_stack_temp (TImode, 16, 0);
1483 memx = adjust_address (memt, mode, 0);
1484 emit_move_insn (memx, in);
1486 emit_move_insn (op0, memt);
1490 if (!ia64_move_ok (operands[0], operands[1]))
1491 operands[1] = force_reg (mode, operands[1]);
1497 /* Emit comparison instruction if necessary, returning the expression
1498 that holds the compare result in the proper mode. */
1500 static GTY(()) rtx cmptf_libfunc;
1503 ia64_expand_compare (enum rtx_code code, enum machine_mode mode)
1505 rtx op0 = ia64_compare_op0, op1 = ia64_compare_op1;
1508 /* If we have a BImode input, then we already have a compare result, and
1509 do not need to emit another comparison. */
1510 if (GET_MODE (op0) == BImode)
1512 gcc_assert ((code == NE || code == EQ) && op1 == const0_rtx);
1515 /* HPUX TFmode compare requires a library call to _U_Qfcmp, which takes a
1516 magic number as its third argument, that indicates what to do.
1517 The return value is an integer to be compared against zero. */
1518 else if (TARGET_HPUX && GET_MODE (op0) == TFmode)
1521 QCMP_INV = 1, /* Raise FP_INVALID on SNaN as a side effect. */
1527 enum rtx_code ncode;
1530 gcc_assert (cmptf_libfunc && GET_MODE (op1) == TFmode);
1533 /* 1 = equal, 0 = not equal. Equality operators do
1534 not raise FP_INVALID when given an SNaN operand. */
1535 case EQ: magic = QCMP_EQ; ncode = NE; break;
1536 case NE: magic = QCMP_EQ; ncode = EQ; break;
1537 /* isunordered() from C99. */
1538 case UNORDERED: magic = QCMP_UNORD; ncode = NE; break;
1539 case ORDERED: magic = QCMP_UNORD; ncode = EQ; break;
1540 /* Relational operators raise FP_INVALID when given
1542 case LT: magic = QCMP_LT |QCMP_INV; ncode = NE; break;
1543 case LE: magic = QCMP_LT|QCMP_EQ|QCMP_INV; ncode = NE; break;
1544 case GT: magic = QCMP_GT |QCMP_INV; ncode = NE; break;
1545 case GE: magic = QCMP_GT|QCMP_EQ|QCMP_INV; ncode = NE; break;
1546 /* FUTURE: Implement UNEQ, UNLT, UNLE, UNGT, UNGE, LTGT.
1547 Expanders for buneq etc. weuld have to be added to ia64.md
1548 for this to be useful. */
1549 default: gcc_unreachable ();
1554 ret = emit_library_call_value (cmptf_libfunc, 0, LCT_CONST, DImode, 3,
1555 op0, TFmode, op1, TFmode,
1556 GEN_INT (magic), DImode);
1557 cmp = gen_reg_rtx (BImode);
1558 emit_insn (gen_rtx_SET (VOIDmode, cmp,
1559 gen_rtx_fmt_ee (ncode, BImode,
1562 insns = get_insns ();
1565 emit_libcall_block (insns, cmp, cmp,
1566 gen_rtx_fmt_ee (code, BImode, op0, op1));
1571 cmp = gen_reg_rtx (BImode);
1572 emit_insn (gen_rtx_SET (VOIDmode, cmp,
1573 gen_rtx_fmt_ee (code, BImode, op0, op1)));
1577 return gen_rtx_fmt_ee (code, mode, cmp, const0_rtx);
1580 /* Generate an integral vector comparison. Return true if the condition has
1581 been reversed, and so the sense of the comparison should be inverted. */
1584 ia64_expand_vecint_compare (enum rtx_code code, enum machine_mode mode,
1585 rtx dest, rtx op0, rtx op1)
1587 bool negate = false;
1590 /* Canonicalize the comparison to EQ, GT, GTU. */
1601 code = reverse_condition (code);
1607 code = reverse_condition (code);
1613 code = swap_condition (code);
1614 x = op0, op0 = op1, op1 = x;
1621 /* Unsigned parallel compare is not supported by the hardware. Play some
1622 tricks to turn this into a signed comparison against 0. */
1631 /* Perform a parallel modulo subtraction. */
1632 t1 = gen_reg_rtx (V2SImode);
1633 emit_insn (gen_subv2si3 (t1, op0, op1));
1635 /* Extract the original sign bit of op0. */
1636 mask = GEN_INT (-0x80000000);
1637 mask = gen_rtx_CONST_VECTOR (V2SImode, gen_rtvec (2, mask, mask));
1638 mask = force_reg (V2SImode, mask);
1639 t2 = gen_reg_rtx (V2SImode);
1640 emit_insn (gen_andv2si3 (t2, op0, mask));
1642 /* XOR it back into the result of the subtraction. This results
1643 in the sign bit set iff we saw unsigned underflow. */
1644 x = gen_reg_rtx (V2SImode);
1645 emit_insn (gen_xorv2si3 (x, t1, t2));
1649 op1 = CONST0_RTX (mode);
1655 /* Perform a parallel unsigned saturating subtraction. */
1656 x = gen_reg_rtx (mode);
1657 emit_insn (gen_rtx_SET (VOIDmode, x,
1658 gen_rtx_US_MINUS (mode, op0, op1)));
1662 op1 = CONST0_RTX (mode);
1671 x = gen_rtx_fmt_ee (code, mode, op0, op1);
1672 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
1677 /* Emit an integral vector conditional move. */
1680 ia64_expand_vecint_cmov (rtx operands[])
1682 enum machine_mode mode = GET_MODE (operands[0]);
1683 enum rtx_code code = GET_CODE (operands[3]);
1687 cmp = gen_reg_rtx (mode);
1688 negate = ia64_expand_vecint_compare (code, mode, cmp,
1689 operands[4], operands[5]);
1691 ot = operands[1+negate];
1692 of = operands[2-negate];
1694 if (ot == CONST0_RTX (mode))
1696 if (of == CONST0_RTX (mode))
1698 emit_move_insn (operands[0], ot);
1702 x = gen_rtx_NOT (mode, cmp);
1703 x = gen_rtx_AND (mode, x, of);
1704 emit_insn (gen_rtx_SET (VOIDmode, operands[0], x));
1706 else if (of == CONST0_RTX (mode))
1708 x = gen_rtx_AND (mode, cmp, ot);
1709 emit_insn (gen_rtx_SET (VOIDmode, operands[0], x));
1715 t = gen_reg_rtx (mode);
1716 x = gen_rtx_AND (mode, cmp, operands[1+negate]);
1717 emit_insn (gen_rtx_SET (VOIDmode, t, x));
1719 f = gen_reg_rtx (mode);
1720 x = gen_rtx_NOT (mode, cmp);
1721 x = gen_rtx_AND (mode, x, operands[2-negate]);
1722 emit_insn (gen_rtx_SET (VOIDmode, f, x));
1724 x = gen_rtx_IOR (mode, t, f);
1725 emit_insn (gen_rtx_SET (VOIDmode, operands[0], x));
1729 /* Emit an integral vector min or max operation. Return true if all done. */
1732 ia64_expand_vecint_minmax (enum rtx_code code, enum machine_mode mode,
1737 /* These four combinations are supported directly. */
1738 if (mode == V8QImode && (code == UMIN || code == UMAX))
1740 if (mode == V4HImode && (code == SMIN || code == SMAX))
1743 /* This combination can be implemented with only saturating subtraction. */
1744 if (mode == V4HImode && code == UMAX)
1746 rtx x, tmp = gen_reg_rtx (mode);
1748 x = gen_rtx_US_MINUS (mode, operands[1], operands[2]);
1749 emit_insn (gen_rtx_SET (VOIDmode, tmp, x));
1751 emit_insn (gen_addv4hi3 (operands[0], tmp, operands[2]));
1755 /* Everything else implemented via vector comparisons. */
1756 xops[0] = operands[0];
1757 xops[4] = xops[1] = operands[1];
1758 xops[5] = xops[2] = operands[2];
1777 xops[3] = gen_rtx_fmt_ee (code, VOIDmode, operands[1], operands[2]);
1779 ia64_expand_vecint_cmov (xops);
1783 /* Emit an integral vector widening sum operations. */
1786 ia64_expand_widen_sum (rtx operands[3], bool unsignedp)
1789 enum machine_mode wmode, mode;
1790 rtx (*unpack_l) (rtx, rtx, rtx);
1791 rtx (*unpack_h) (rtx, rtx, rtx);
1792 rtx (*plus) (rtx, rtx, rtx);
1794 wmode = GET_MODE (operands[0]);
1795 mode = GET_MODE (operands[1]);
1800 unpack_l = gen_unpack1_l;
1801 unpack_h = gen_unpack1_h;
1802 plus = gen_addv4hi3;
1805 unpack_l = gen_unpack2_l;
1806 unpack_h = gen_unpack2_h;
1807 plus = gen_addv2si3;
1813 /* Fill in x with the sign extension of each element in op1. */
1815 x = CONST0_RTX (mode);
1820 x = gen_reg_rtx (mode);
1822 neg = ia64_expand_vecint_compare (LT, mode, x, operands[1],
1827 l = gen_reg_rtx (wmode);
1828 h = gen_reg_rtx (wmode);
1829 s = gen_reg_rtx (wmode);
1831 emit_insn (unpack_l (gen_lowpart (mode, l), operands[1], x));
1832 emit_insn (unpack_h (gen_lowpart (mode, h), operands[1], x));
1833 emit_insn (plus (s, l, operands[2]));
1834 emit_insn (plus (operands[0], h, s));
1837 /* Emit a signed or unsigned V8QI dot product operation. */
1840 ia64_expand_dot_prod_v8qi (rtx operands[4], bool unsignedp)
1842 rtx l1, l2, h1, h2, x1, x2, p1, p2, p3, p4, s1, s2, s3;
1844 /* Fill in x1 and x2 with the sign extension of each element. */
1846 x1 = x2 = CONST0_RTX (V8QImode);
1851 x1 = gen_reg_rtx (V8QImode);
1852 x2 = gen_reg_rtx (V8QImode);
1854 neg = ia64_expand_vecint_compare (LT, V8QImode, x1, operands[1],
1855 CONST0_RTX (V8QImode));
1857 neg = ia64_expand_vecint_compare (LT, V8QImode, x2, operands[2],
1858 CONST0_RTX (V8QImode));
1862 l1 = gen_reg_rtx (V4HImode);
1863 l2 = gen_reg_rtx (V4HImode);
1864 h1 = gen_reg_rtx (V4HImode);
1865 h2 = gen_reg_rtx (V4HImode);
1867 emit_insn (gen_unpack1_l (gen_lowpart (V8QImode, l1), operands[1], x1));
1868 emit_insn (gen_unpack1_l (gen_lowpart (V8QImode, l2), operands[2], x2));
1869 emit_insn (gen_unpack1_h (gen_lowpart (V8QImode, h1), operands[1], x1));
1870 emit_insn (gen_unpack1_h (gen_lowpart (V8QImode, h2), operands[2], x2));
1872 p1 = gen_reg_rtx (V2SImode);
1873 p2 = gen_reg_rtx (V2SImode);
1874 p3 = gen_reg_rtx (V2SImode);
1875 p4 = gen_reg_rtx (V2SImode);
1876 emit_insn (gen_pmpy2_r (p1, l1, l2));
1877 emit_insn (gen_pmpy2_l (p2, l1, l2));
1878 emit_insn (gen_pmpy2_r (p3, h1, h2));
1879 emit_insn (gen_pmpy2_l (p4, h1, h2));
1881 s1 = gen_reg_rtx (V2SImode);
1882 s2 = gen_reg_rtx (V2SImode);
1883 s3 = gen_reg_rtx (V2SImode);
1884 emit_insn (gen_addv2si3 (s1, p1, p2));
1885 emit_insn (gen_addv2si3 (s2, p3, p4));
1886 emit_insn (gen_addv2si3 (s3, s1, operands[3]));
1887 emit_insn (gen_addv2si3 (operands[0], s2, s3));
1890 /* Emit the appropriate sequence for a call. */
1893 ia64_expand_call (rtx retval, rtx addr, rtx nextarg ATTRIBUTE_UNUSED,
1898 addr = XEXP (addr, 0);
1899 addr = convert_memory_address (DImode, addr);
1900 b0 = gen_rtx_REG (DImode, R_BR (0));
1902 /* ??? Should do this for functions known to bind local too. */
1903 if (TARGET_NO_PIC || TARGET_AUTO_PIC)
1906 insn = gen_sibcall_nogp (addr);
1908 insn = gen_call_nogp (addr, b0);
1910 insn = gen_call_value_nogp (retval, addr, b0);
1911 insn = emit_call_insn (insn);
1916 insn = gen_sibcall_gp (addr);
1918 insn = gen_call_gp (addr, b0);
1920 insn = gen_call_value_gp (retval, addr, b0);
1921 insn = emit_call_insn (insn);
1923 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
1927 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), b0);
1931 reg_emitted (enum ia64_frame_regs r)
1933 if (emitted_frame_related_regs[r] == 0)
1934 emitted_frame_related_regs[r] = current_frame_info.r[r];
1936 gcc_assert (emitted_frame_related_regs[r] == current_frame_info.r[r]);
1940 get_reg (enum ia64_frame_regs r)
1943 return current_frame_info.r[r];
1947 is_emitted (int regno)
1949 enum ia64_frame_regs r;
1951 for (r = reg_fp; r < number_of_ia64_frame_regs; r++)
1952 if (emitted_frame_related_regs[r] == regno)
1958 ia64_reload_gp (void)
1962 if (current_frame_info.r[reg_save_gp])
1964 tmp = gen_rtx_REG (DImode, get_reg (reg_save_gp));
1968 HOST_WIDE_INT offset;
1971 offset = (current_frame_info.spill_cfa_off
1972 + current_frame_info.spill_size);
1973 if (frame_pointer_needed)
1975 tmp = hard_frame_pointer_rtx;
1980 tmp = stack_pointer_rtx;
1981 offset = current_frame_info.total_size - offset;
1984 offset_r = GEN_INT (offset);
1985 if (satisfies_constraint_I (offset_r))
1986 emit_insn (gen_adddi3 (pic_offset_table_rtx, tmp, offset_r));
1989 emit_move_insn (pic_offset_table_rtx, offset_r);
1990 emit_insn (gen_adddi3 (pic_offset_table_rtx,
1991 pic_offset_table_rtx, tmp));
1994 tmp = gen_rtx_MEM (DImode, pic_offset_table_rtx);
1997 emit_move_insn (pic_offset_table_rtx, tmp);
2001 ia64_split_call (rtx retval, rtx addr, rtx retaddr, rtx scratch_r,
2002 rtx scratch_b, int noreturn_p, int sibcall_p)
2005 bool is_desc = false;
2007 /* If we find we're calling through a register, then we're actually
2008 calling through a descriptor, so load up the values. */
2009 if (REG_P (addr) && GR_REGNO_P (REGNO (addr)))
2014 /* ??? We are currently constrained to *not* use peep2, because
2015 we can legitimately change the global lifetime of the GP
2016 (in the form of killing where previously live). This is
2017 because a call through a descriptor doesn't use the previous
2018 value of the GP, while a direct call does, and we do not
2019 commit to either form until the split here.
2021 That said, this means that we lack precise life info for
2022 whether ADDR is dead after this call. This is not terribly
2023 important, since we can fix things up essentially for free
2024 with the POST_DEC below, but it's nice to not use it when we
2025 can immediately tell it's not necessary. */
2026 addr_dead_p = ((noreturn_p || sibcall_p
2027 || TEST_HARD_REG_BIT (regs_invalidated_by_call,
2029 && !FUNCTION_ARG_REGNO_P (REGNO (addr)));
2031 /* Load the code address into scratch_b. */
2032 tmp = gen_rtx_POST_INC (Pmode, addr);
2033 tmp = gen_rtx_MEM (Pmode, tmp);
2034 emit_move_insn (scratch_r, tmp);
2035 emit_move_insn (scratch_b, scratch_r);
2037 /* Load the GP address. If ADDR is not dead here, then we must
2038 revert the change made above via the POST_INCREMENT. */
2040 tmp = gen_rtx_POST_DEC (Pmode, addr);
2043 tmp = gen_rtx_MEM (Pmode, tmp);
2044 emit_move_insn (pic_offset_table_rtx, tmp);
2051 insn = gen_sibcall_nogp (addr);
2053 insn = gen_call_value_nogp (retval, addr, retaddr);
2055 insn = gen_call_nogp (addr, retaddr);
2056 emit_call_insn (insn);
2058 if ((!TARGET_CONST_GP || is_desc) && !noreturn_p && !sibcall_p)
2062 /* Expand an atomic operation. We want to perform MEM <CODE>= VAL atomically.
2064 This differs from the generic code in that we know about the zero-extending
2065 properties of cmpxchg, and the zero-extending requirements of ar.ccv. We
2066 also know that ld.acq+cmpxchg.rel equals a full barrier.
2068 The loop we want to generate looks like
2073 new_reg = cmp_reg op val;
2074 cmp_reg = compare-and-swap(mem, old_reg, new_reg)
2075 if (cmp_reg != old_reg)
2078 Note that we only do the plain load from memory once. Subsequent
2079 iterations use the value loaded by the compare-and-swap pattern. */
2082 ia64_expand_atomic_op (enum rtx_code code, rtx mem, rtx val,
2083 rtx old_dst, rtx new_dst)
2085 enum machine_mode mode = GET_MODE (mem);
2086 rtx old_reg, new_reg, cmp_reg, ar_ccv, label;
2087 enum insn_code icode;
2089 /* Special case for using fetchadd. */
2090 if ((mode == SImode || mode == DImode)
2091 && (code == PLUS || code == MINUS)
2092 && fetchadd_operand (val, mode))
2095 val = GEN_INT (-INTVAL (val));
2098 old_dst = gen_reg_rtx (mode);
2100 emit_insn (gen_memory_barrier ());
2103 icode = CODE_FOR_fetchadd_acq_si;
2105 icode = CODE_FOR_fetchadd_acq_di;
2106 emit_insn (GEN_FCN (icode) (old_dst, mem, val));
2110 new_reg = expand_simple_binop (mode, PLUS, old_dst, val, new_dst,
2112 if (new_reg != new_dst)
2113 emit_move_insn (new_dst, new_reg);
2118 /* Because of the volatile mem read, we get an ld.acq, which is the
2119 front half of the full barrier. The end half is the cmpxchg.rel. */
2120 gcc_assert (MEM_VOLATILE_P (mem));
2122 old_reg = gen_reg_rtx (DImode);
2123 cmp_reg = gen_reg_rtx (DImode);
2124 label = gen_label_rtx ();
2128 val = simplify_gen_subreg (DImode, val, mode, 0);
2129 emit_insn (gen_extend_insn (cmp_reg, mem, DImode, mode, 1));
2132 emit_move_insn (cmp_reg, mem);
2136 ar_ccv = gen_rtx_REG (DImode, AR_CCV_REGNUM);
2137 emit_move_insn (old_reg, cmp_reg);
2138 emit_move_insn (ar_ccv, cmp_reg);
2141 emit_move_insn (old_dst, gen_lowpart (mode, cmp_reg));
2146 new_reg = expand_simple_binop (DImode, AND, new_reg, val, NULL_RTX,
2147 true, OPTAB_DIRECT);
2148 new_reg = expand_simple_unop (DImode, code, new_reg, NULL_RTX, true);
2151 new_reg = expand_simple_binop (DImode, code, new_reg, val, NULL_RTX,
2152 true, OPTAB_DIRECT);
2155 new_reg = gen_lowpart (mode, new_reg);
2157 emit_move_insn (new_dst, new_reg);
2161 case QImode: icode = CODE_FOR_cmpxchg_rel_qi; break;
2162 case HImode: icode = CODE_FOR_cmpxchg_rel_hi; break;
2163 case SImode: icode = CODE_FOR_cmpxchg_rel_si; break;
2164 case DImode: icode = CODE_FOR_cmpxchg_rel_di; break;
2169 emit_insn (GEN_FCN (icode) (cmp_reg, mem, ar_ccv, new_reg));
2171 emit_cmp_and_jump_insns (cmp_reg, old_reg, NE, NULL, DImode, true, label);
2174 /* Begin the assembly file. */
2177 ia64_file_start (void)
2179 /* Variable tracking should be run after all optimizations which change order
2180 of insns. It also needs a valid CFG. This can't be done in
2181 ia64_override_options, because flag_var_tracking is finalized after
2183 ia64_flag_var_tracking = flag_var_tracking;
2184 flag_var_tracking = 0;
2186 default_file_start ();
2187 emit_safe_across_calls ();
2191 emit_safe_across_calls (void)
2193 unsigned int rs, re;
2200 while (rs < 64 && call_used_regs[PR_REG (rs)])
2204 for (re = rs + 1; re < 64 && ! call_used_regs[PR_REG (re)]; re++)
2208 fputs ("\t.pred.safe_across_calls ", asm_out_file);
2212 fputc (',', asm_out_file);
2214 fprintf (asm_out_file, "p%u", rs);
2216 fprintf (asm_out_file, "p%u-p%u", rs, re - 1);
2220 fputc ('\n', asm_out_file);
2223 /* Globalize a declaration. */
2226 ia64_globalize_decl_name (FILE * stream, tree decl)
2228 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2229 tree version_attr = lookup_attribute ("version_id", DECL_ATTRIBUTES (decl));
2232 tree v = TREE_VALUE (TREE_VALUE (version_attr));
2233 const char *p = TREE_STRING_POINTER (v);
2234 fprintf (stream, "\t.alias %s#, \"%s{%s}\"\n", name, name, p);
2236 targetm.asm_out.globalize_label (stream, name);
2237 if (TREE_CODE (decl) == FUNCTION_DECL)
2238 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function");
2241 /* Helper function for ia64_compute_frame_size: find an appropriate general
2242 register to spill some special register to. SPECIAL_SPILL_MASK contains
2243 bits in GR0 to GR31 that have already been allocated by this routine.
2244 TRY_LOCALS is true if we should attempt to locate a local regnum. */
2247 find_gr_spill (enum ia64_frame_regs r, int try_locals)
2251 if (emitted_frame_related_regs[r] != 0)
2253 regno = emitted_frame_related_regs[r];
2254 if (regno >= LOC_REG (0) && regno < LOC_REG (80 - frame_pointer_needed)
2255 && current_frame_info.n_local_regs < regno - LOC_REG (0) + 1)
2256 current_frame_info.n_local_regs = regno - LOC_REG (0) + 1;
2257 else if (current_function_is_leaf
2258 && regno >= GR_REG (1) && regno <= GR_REG (31))
2259 current_frame_info.gr_used_mask |= 1 << regno;
2264 /* If this is a leaf function, first try an otherwise unused
2265 call-clobbered register. */
2266 if (current_function_is_leaf)
2268 for (regno = GR_REG (1); regno <= GR_REG (31); regno++)
2269 if (! df_regs_ever_live_p (regno)
2270 && call_used_regs[regno]
2271 && ! fixed_regs[regno]
2272 && ! global_regs[regno]
2273 && ((current_frame_info.gr_used_mask >> regno) & 1) == 0
2274 && ! is_emitted (regno))
2276 current_frame_info.gr_used_mask |= 1 << regno;
2283 regno = current_frame_info.n_local_regs;
2284 /* If there is a frame pointer, then we can't use loc79, because
2285 that is HARD_FRAME_POINTER_REGNUM. In particular, see the
2286 reg_name switching code in ia64_expand_prologue. */
2287 while (regno < (80 - frame_pointer_needed))
2288 if (! is_emitted (LOC_REG (regno++)))
2290 current_frame_info.n_local_regs = regno;
2291 return LOC_REG (regno - 1);
2295 /* Failed to find a general register to spill to. Must use stack. */
2299 /* In order to make for nice schedules, we try to allocate every temporary
2300 to a different register. We must of course stay away from call-saved,
2301 fixed, and global registers. We must also stay away from registers
2302 allocated in current_frame_info.gr_used_mask, since those include regs
2303 used all through the prologue.
2305 Any register allocated here must be used immediately. The idea is to
2306 aid scheduling, not to solve data flow problems. */
2308 static int last_scratch_gr_reg;
2311 next_scratch_gr_reg (void)
2315 for (i = 0; i < 32; ++i)
2317 regno = (last_scratch_gr_reg + i + 1) & 31;
2318 if (call_used_regs[regno]
2319 && ! fixed_regs[regno]
2320 && ! global_regs[regno]
2321 && ((current_frame_info.gr_used_mask >> regno) & 1) == 0)
2323 last_scratch_gr_reg = regno;
2328 /* There must be _something_ available. */
2332 /* Helper function for ia64_compute_frame_size, called through
2333 diddle_return_value. Mark REG in current_frame_info.gr_used_mask. */
2336 mark_reg_gr_used_mask (rtx reg, void *data ATTRIBUTE_UNUSED)
2338 unsigned int regno = REGNO (reg);
2341 unsigned int i, n = hard_regno_nregs[regno][GET_MODE (reg)];
2342 for (i = 0; i < n; ++i)
2343 current_frame_info.gr_used_mask |= 1 << (regno + i);
2348 /* Returns the number of bytes offset between the frame pointer and the stack
2349 pointer for the current function. SIZE is the number of bytes of space
2350 needed for local variables. */
2353 ia64_compute_frame_size (HOST_WIDE_INT size)
2355 HOST_WIDE_INT total_size;
2356 HOST_WIDE_INT spill_size = 0;
2357 HOST_WIDE_INT extra_spill_size = 0;
2358 HOST_WIDE_INT pretend_args_size;
2361 int spilled_gr_p = 0;
2362 int spilled_fr_p = 0;
2368 if (current_frame_info.initialized)
2371 memset (¤t_frame_info, 0, sizeof current_frame_info);
2372 CLEAR_HARD_REG_SET (mask);
2374 /* Don't allocate scratches to the return register. */
2375 diddle_return_value (mark_reg_gr_used_mask, NULL);
2377 /* Don't allocate scratches to the EH scratch registers. */
2378 if (cfun->machine->ia64_eh_epilogue_sp)
2379 mark_reg_gr_used_mask (cfun->machine->ia64_eh_epilogue_sp, NULL);
2380 if (cfun->machine->ia64_eh_epilogue_bsp)
2381 mark_reg_gr_used_mask (cfun->machine->ia64_eh_epilogue_bsp, NULL);
2383 /* Find the size of the register stack frame. We have only 80 local
2384 registers, because we reserve 8 for the inputs and 8 for the
2387 /* Skip HARD_FRAME_POINTER_REGNUM (loc79) when frame_pointer_needed,
2388 since we'll be adjusting that down later. */
2389 regno = LOC_REG (78) + ! frame_pointer_needed;
2390 for (; regno >= LOC_REG (0); regno--)
2391 if (df_regs_ever_live_p (regno) && !is_emitted (regno))
2393 current_frame_info.n_local_regs = regno - LOC_REG (0) + 1;
2395 /* For functions marked with the syscall_linkage attribute, we must mark
2396 all eight input registers as in use, so that locals aren't visible to
2399 if (cfun->machine->n_varargs > 0
2400 || lookup_attribute ("syscall_linkage",
2401 TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
2402 current_frame_info.n_input_regs = 8;
2405 for (regno = IN_REG (7); regno >= IN_REG (0); regno--)
2406 if (df_regs_ever_live_p (regno))
2408 current_frame_info.n_input_regs = regno - IN_REG (0) + 1;
2411 for (regno = OUT_REG (7); regno >= OUT_REG (0); regno--)
2412 if (df_regs_ever_live_p (regno))
2414 i = regno - OUT_REG (0) + 1;
2416 #ifndef PROFILE_HOOK
2417 /* When -p profiling, we need one output register for the mcount argument.
2418 Likewise for -a profiling for the bb_init_func argument. For -ax
2419 profiling, we need two output registers for the two bb_init_trace_func
2424 current_frame_info.n_output_regs = i;
2426 /* ??? No rotating register support yet. */
2427 current_frame_info.n_rotate_regs = 0;
2429 /* Discover which registers need spilling, and how much room that
2430 will take. Begin with floating point and general registers,
2431 which will always wind up on the stack. */
2433 for (regno = FR_REG (2); regno <= FR_REG (127); regno++)
2434 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2436 SET_HARD_REG_BIT (mask, regno);
2442 for (regno = GR_REG (1); regno <= GR_REG (31); regno++)
2443 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2445 SET_HARD_REG_BIT (mask, regno);
2451 for (regno = BR_REG (1); regno <= BR_REG (7); regno++)
2452 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2454 SET_HARD_REG_BIT (mask, regno);
2459 /* Now come all special registers that might get saved in other
2460 general registers. */
2462 if (frame_pointer_needed)
2464 current_frame_info.r[reg_fp] = find_gr_spill (reg_fp, 1);
2465 /* If we did not get a register, then we take LOC79. This is guaranteed
2466 to be free, even if regs_ever_live is already set, because this is
2467 HARD_FRAME_POINTER_REGNUM. This requires incrementing n_local_regs,
2468 as we don't count loc79 above. */
2469 if (current_frame_info.r[reg_fp] == 0)
2471 current_frame_info.r[reg_fp] = LOC_REG (79);
2472 current_frame_info.n_local_regs = LOC_REG (79) - LOC_REG (0) + 1;
2476 if (! current_function_is_leaf)
2478 /* Emit a save of BR0 if we call other functions. Do this even
2479 if this function doesn't return, as EH depends on this to be
2480 able to unwind the stack. */
2481 SET_HARD_REG_BIT (mask, BR_REG (0));
2483 current_frame_info.r[reg_save_b0] = find_gr_spill (reg_save_b0, 1);
2484 if (current_frame_info.r[reg_save_b0] == 0)
2486 extra_spill_size += 8;
2490 /* Similarly for ar.pfs. */
2491 SET_HARD_REG_BIT (mask, AR_PFS_REGNUM);
2492 current_frame_info.r[reg_save_ar_pfs] = find_gr_spill (reg_save_ar_pfs, 1);
2493 if (current_frame_info.r[reg_save_ar_pfs] == 0)
2495 extra_spill_size += 8;
2499 /* Similarly for gp. Note that if we're calling setjmp, the stacked
2500 registers are clobbered, so we fall back to the stack. */
2501 current_frame_info.r[reg_save_gp]
2502 = (cfun->calls_setjmp ? 0 : find_gr_spill (reg_save_gp, 1));
2503 if (current_frame_info.r[reg_save_gp] == 0)
2505 SET_HARD_REG_BIT (mask, GR_REG (1));
2512 if (df_regs_ever_live_p (BR_REG (0)) && ! call_used_regs[BR_REG (0)])
2514 SET_HARD_REG_BIT (mask, BR_REG (0));
2515 extra_spill_size += 8;
2519 if (df_regs_ever_live_p (AR_PFS_REGNUM))
2521 SET_HARD_REG_BIT (mask, AR_PFS_REGNUM);
2522 current_frame_info.r[reg_save_ar_pfs]
2523 = find_gr_spill (reg_save_ar_pfs, 1);
2524 if (current_frame_info.r[reg_save_ar_pfs] == 0)
2526 extra_spill_size += 8;
2532 /* Unwind descriptor hackery: things are most efficient if we allocate
2533 consecutive GR save registers for RP, PFS, FP in that order. However,
2534 it is absolutely critical that FP get the only hard register that's
2535 guaranteed to be free, so we allocated it first. If all three did
2536 happen to be allocated hard regs, and are consecutive, rearrange them
2537 into the preferred order now.
2539 If we have already emitted code for any of those registers,
2540 then it's already too late to change. */
2541 min_regno = MIN (current_frame_info.r[reg_fp],
2542 MIN (current_frame_info.r[reg_save_b0],
2543 current_frame_info.r[reg_save_ar_pfs]));
2544 max_regno = MAX (current_frame_info.r[reg_fp],
2545 MAX (current_frame_info.r[reg_save_b0],
2546 current_frame_info.r[reg_save_ar_pfs]));
2548 && min_regno + 2 == max_regno
2549 && (current_frame_info.r[reg_fp] == min_regno + 1
2550 || current_frame_info.r[reg_save_b0] == min_regno + 1
2551 || current_frame_info.r[reg_save_ar_pfs] == min_regno + 1)
2552 && (emitted_frame_related_regs[reg_save_b0] == 0
2553 || emitted_frame_related_regs[reg_save_b0] == min_regno)
2554 && (emitted_frame_related_regs[reg_save_ar_pfs] == 0
2555 || emitted_frame_related_regs[reg_save_ar_pfs] == min_regno + 1)
2556 && (emitted_frame_related_regs[reg_fp] == 0
2557 || emitted_frame_related_regs[reg_fp] == min_regno + 2))
2559 current_frame_info.r[reg_save_b0] = min_regno;
2560 current_frame_info.r[reg_save_ar_pfs] = min_regno + 1;
2561 current_frame_info.r[reg_fp] = min_regno + 2;
2564 /* See if we need to store the predicate register block. */
2565 for (regno = PR_REG (0); regno <= PR_REG (63); regno++)
2566 if (df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2568 if (regno <= PR_REG (63))
2570 SET_HARD_REG_BIT (mask, PR_REG (0));
2571 current_frame_info.r[reg_save_pr] = find_gr_spill (reg_save_pr, 1);
2572 if (current_frame_info.r[reg_save_pr] == 0)
2574 extra_spill_size += 8;
2578 /* ??? Mark them all as used so that register renaming and such
2579 are free to use them. */
2580 for (regno = PR_REG (0); regno <= PR_REG (63); regno++)
2581 df_set_regs_ever_live (regno, true);
2584 /* If we're forced to use st8.spill, we're forced to save and restore
2585 ar.unat as well. The check for existing liveness allows inline asm
2586 to touch ar.unat. */
2587 if (spilled_gr_p || cfun->machine->n_varargs
2588 || df_regs_ever_live_p (AR_UNAT_REGNUM))
2590 df_set_regs_ever_live (AR_UNAT_REGNUM, true);
2591 SET_HARD_REG_BIT (mask, AR_UNAT_REGNUM);
2592 current_frame_info.r[reg_save_ar_unat]
2593 = find_gr_spill (reg_save_ar_unat, spill_size == 0);
2594 if (current_frame_info.r[reg_save_ar_unat] == 0)
2596 extra_spill_size += 8;
2601 if (df_regs_ever_live_p (AR_LC_REGNUM))
2603 SET_HARD_REG_BIT (mask, AR_LC_REGNUM);
2604 current_frame_info.r[reg_save_ar_lc]
2605 = find_gr_spill (reg_save_ar_lc, spill_size == 0);
2606 if (current_frame_info.r[reg_save_ar_lc] == 0)
2608 extra_spill_size += 8;
2613 /* If we have an odd number of words of pretend arguments written to
2614 the stack, then the FR save area will be unaligned. We round the
2615 size of this area up to keep things 16 byte aligned. */
2617 pretend_args_size = IA64_STACK_ALIGN (crtl->args.pretend_args_size);
2619 pretend_args_size = crtl->args.pretend_args_size;
2621 total_size = (spill_size + extra_spill_size + size + pretend_args_size
2622 + crtl->outgoing_args_size);
2623 total_size = IA64_STACK_ALIGN (total_size);
2625 /* We always use the 16-byte scratch area provided by the caller, but
2626 if we are a leaf function, there's no one to which we need to provide
2628 if (current_function_is_leaf)
2629 total_size = MAX (0, total_size - 16);
2631 current_frame_info.total_size = total_size;
2632 current_frame_info.spill_cfa_off = pretend_args_size - 16;
2633 current_frame_info.spill_size = spill_size;
2634 current_frame_info.extra_spill_size = extra_spill_size;
2635 COPY_HARD_REG_SET (current_frame_info.mask, mask);
2636 current_frame_info.n_spilled = n_spilled;
2637 current_frame_info.initialized = reload_completed;
2640 /* Compute the initial difference between the specified pair of registers. */
2643 ia64_initial_elimination_offset (int from, int to)
2645 HOST_WIDE_INT offset;
2647 ia64_compute_frame_size (get_frame_size ());
2650 case FRAME_POINTER_REGNUM:
2653 case HARD_FRAME_POINTER_REGNUM:
2654 if (current_function_is_leaf)
2655 offset = -current_frame_info.total_size;
2657 offset = -(current_frame_info.total_size
2658 - crtl->outgoing_args_size - 16);
2661 case STACK_POINTER_REGNUM:
2662 if (current_function_is_leaf)
2665 offset = 16 + crtl->outgoing_args_size;
2673 case ARG_POINTER_REGNUM:
2674 /* Arguments start above the 16 byte save area, unless stdarg
2675 in which case we store through the 16 byte save area. */
2678 case HARD_FRAME_POINTER_REGNUM:
2679 offset = 16 - crtl->args.pretend_args_size;
2682 case STACK_POINTER_REGNUM:
2683 offset = (current_frame_info.total_size
2684 + 16 - crtl->args.pretend_args_size);
2699 /* If there are more than a trivial number of register spills, we use
2700 two interleaved iterators so that we can get two memory references
2703 In order to simplify things in the prologue and epilogue expanders,
2704 we use helper functions to fix up the memory references after the
2705 fact with the appropriate offsets to a POST_MODIFY memory mode.
2706 The following data structure tracks the state of the two iterators
2707 while insns are being emitted. */
2709 struct spill_fill_data
2711 rtx init_after; /* point at which to emit initializations */
2712 rtx init_reg[2]; /* initial base register */
2713 rtx iter_reg[2]; /* the iterator registers */
2714 rtx *prev_addr[2]; /* address of last memory use */
2715 rtx prev_insn[2]; /* the insn corresponding to prev_addr */
2716 HOST_WIDE_INT prev_off[2]; /* last offset */
2717 int n_iter; /* number of iterators in use */
2718 int next_iter; /* next iterator to use */
2719 unsigned int save_gr_used_mask;
2722 static struct spill_fill_data spill_fill_data;
2725 setup_spill_pointers (int n_spills, rtx init_reg, HOST_WIDE_INT cfa_off)
2729 spill_fill_data.init_after = get_last_insn ();
2730 spill_fill_data.init_reg[0] = init_reg;
2731 spill_fill_data.init_reg[1] = init_reg;
2732 spill_fill_data.prev_addr[0] = NULL;
2733 spill_fill_data.prev_addr[1] = NULL;
2734 spill_fill_data.prev_insn[0] = NULL;
2735 spill_fill_data.prev_insn[1] = NULL;
2736 spill_fill_data.prev_off[0] = cfa_off;
2737 spill_fill_data.prev_off[1] = cfa_off;
2738 spill_fill_data.next_iter = 0;
2739 spill_fill_data.save_gr_used_mask = current_frame_info.gr_used_mask;
2741 spill_fill_data.n_iter = 1 + (n_spills > 2);
2742 for (i = 0; i < spill_fill_data.n_iter; ++i)
2744 int regno = next_scratch_gr_reg ();
2745 spill_fill_data.iter_reg[i] = gen_rtx_REG (DImode, regno);
2746 current_frame_info.gr_used_mask |= 1 << regno;
2751 finish_spill_pointers (void)
2753 current_frame_info.gr_used_mask = spill_fill_data.save_gr_used_mask;
2757 spill_restore_mem (rtx reg, HOST_WIDE_INT cfa_off)
2759 int iter = spill_fill_data.next_iter;
2760 HOST_WIDE_INT disp = spill_fill_data.prev_off[iter] - cfa_off;
2761 rtx disp_rtx = GEN_INT (disp);
2764 if (spill_fill_data.prev_addr[iter])
2766 if (satisfies_constraint_N (disp_rtx))
2768 *spill_fill_data.prev_addr[iter]
2769 = gen_rtx_POST_MODIFY (DImode, spill_fill_data.iter_reg[iter],
2770 gen_rtx_PLUS (DImode,
2771 spill_fill_data.iter_reg[iter],
2773 REG_NOTES (spill_fill_data.prev_insn[iter])
2774 = gen_rtx_EXPR_LIST (REG_INC, spill_fill_data.iter_reg[iter],
2775 REG_NOTES (spill_fill_data.prev_insn[iter]));
2779 /* ??? Could use register post_modify for loads. */
2780 if (!satisfies_constraint_I (disp_rtx))
2782 rtx tmp = gen_rtx_REG (DImode, next_scratch_gr_reg ());
2783 emit_move_insn (tmp, disp_rtx);
2786 emit_insn (gen_adddi3 (spill_fill_data.iter_reg[iter],
2787 spill_fill_data.iter_reg[iter], disp_rtx));
2790 /* Micro-optimization: if we've created a frame pointer, it's at
2791 CFA 0, which may allow the real iterator to be initialized lower,
2792 slightly increasing parallelism. Also, if there are few saves
2793 it may eliminate the iterator entirely. */
2795 && spill_fill_data.init_reg[iter] == stack_pointer_rtx
2796 && frame_pointer_needed)
2798 mem = gen_rtx_MEM (GET_MODE (reg), hard_frame_pointer_rtx);
2799 set_mem_alias_set (mem, get_varargs_alias_set ());
2807 seq = gen_movdi (spill_fill_data.iter_reg[iter],
2808 spill_fill_data.init_reg[iter]);
2813 if (!satisfies_constraint_I (disp_rtx))
2815 rtx tmp = gen_rtx_REG (DImode, next_scratch_gr_reg ());
2816 emit_move_insn (tmp, disp_rtx);
2820 emit_insn (gen_adddi3 (spill_fill_data.iter_reg[iter],
2821 spill_fill_data.init_reg[iter],
2828 /* Careful for being the first insn in a sequence. */
2829 if (spill_fill_data.init_after)
2830 insn = emit_insn_after (seq, spill_fill_data.init_after);
2833 rtx first = get_insns ();
2835 insn = emit_insn_before (seq, first);
2837 insn = emit_insn (seq);
2839 spill_fill_data.init_after = insn;
2842 mem = gen_rtx_MEM (GET_MODE (reg), spill_fill_data.iter_reg[iter]);
2844 /* ??? Not all of the spills are for varargs, but some of them are.
2845 The rest of the spills belong in an alias set of their own. But
2846 it doesn't actually hurt to include them here. */
2847 set_mem_alias_set (mem, get_varargs_alias_set ());
2849 spill_fill_data.prev_addr[iter] = &XEXP (mem, 0);
2850 spill_fill_data.prev_off[iter] = cfa_off;
2852 if (++iter >= spill_fill_data.n_iter)
2854 spill_fill_data.next_iter = iter;
2860 do_spill (rtx (*move_fn) (rtx, rtx, rtx), rtx reg, HOST_WIDE_INT cfa_off,
2863 int iter = spill_fill_data.next_iter;
2866 mem = spill_restore_mem (reg, cfa_off);
2867 insn = emit_insn ((*move_fn) (mem, reg, GEN_INT (cfa_off)));
2868 spill_fill_data.prev_insn[iter] = insn;
2875 RTX_FRAME_RELATED_P (insn) = 1;
2877 /* Don't even pretend that the unwind code can intuit its way
2878 through a pair of interleaved post_modify iterators. Just
2879 provide the correct answer. */
2881 if (frame_pointer_needed)
2883 base = hard_frame_pointer_rtx;
2888 base = stack_pointer_rtx;
2889 off = current_frame_info.total_size - cfa_off;
2893 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2894 gen_rtx_SET (VOIDmode,
2895 gen_rtx_MEM (GET_MODE (reg),
2896 plus_constant (base, off)),
2903 do_restore (rtx (*move_fn) (rtx, rtx, rtx), rtx reg, HOST_WIDE_INT cfa_off)
2905 int iter = spill_fill_data.next_iter;
2908 insn = emit_insn ((*move_fn) (reg, spill_restore_mem (reg, cfa_off),
2909 GEN_INT (cfa_off)));
2910 spill_fill_data.prev_insn[iter] = insn;
2913 /* Wrapper functions that discards the CONST_INT spill offset. These
2914 exist so that we can give gr_spill/gr_fill the offset they need and
2915 use a consistent function interface. */
2918 gen_movdi_x (rtx dest, rtx src, rtx offset ATTRIBUTE_UNUSED)
2920 return gen_movdi (dest, src);
2924 gen_fr_spill_x (rtx dest, rtx src, rtx offset ATTRIBUTE_UNUSED)
2926 return gen_fr_spill (dest, src);
2930 gen_fr_restore_x (rtx dest, rtx src, rtx offset ATTRIBUTE_UNUSED)
2932 return gen_fr_restore (dest, src);
2935 /* Called after register allocation to add any instructions needed for the
2936 prologue. Using a prologue insn is favored compared to putting all of the
2937 instructions in output_function_prologue(), since it allows the scheduler
2938 to intermix instructions with the saves of the caller saved registers. In
2939 some cases, it might be necessary to emit a barrier instruction as the last
2940 insn to prevent such scheduling.
2942 Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
2943 so that the debug info generation code can handle them properly.
2945 The register save area is layed out like so:
2947 [ varargs spill area ]
2948 [ fr register spill area ]
2949 [ br register spill area ]
2950 [ ar register spill area ]
2951 [ pr register spill area ]
2952 [ gr register spill area ] */
2954 /* ??? Get inefficient code when the frame size is larger than can fit in an
2955 adds instruction. */
2958 ia64_expand_prologue (void)
2960 rtx insn, ar_pfs_save_reg, ar_unat_save_reg;
2961 int i, epilogue_p, regno, alt_regno, cfa_off, n_varargs;
2964 ia64_compute_frame_size (get_frame_size ());
2965 last_scratch_gr_reg = 15;
2969 fprintf (dump_file, "ia64 frame related registers "
2970 "recorded in current_frame_info.r[]:\n");
2971 #define PRINTREG(a) if (current_frame_info.r[a]) \
2972 fprintf(dump_file, "%s = %d\n", #a, current_frame_info.r[a])
2974 PRINTREG(reg_save_b0);
2975 PRINTREG(reg_save_pr);
2976 PRINTREG(reg_save_ar_pfs);
2977 PRINTREG(reg_save_ar_unat);
2978 PRINTREG(reg_save_ar_lc);
2979 PRINTREG(reg_save_gp);
2983 /* If there is no epilogue, then we don't need some prologue insns.
2984 We need to avoid emitting the dead prologue insns, because flow
2985 will complain about them. */
2991 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
2992 if ((e->flags & EDGE_FAKE) == 0
2993 && (e->flags & EDGE_FALLTHRU) != 0)
2995 epilogue_p = (e != NULL);
3000 /* Set the local, input, and output register names. We need to do this
3001 for GNU libc, which creates crti.S/crtn.S by splitting initfini.c in
3002 half. If we use in/loc/out register names, then we get assembler errors
3003 in crtn.S because there is no alloc insn or regstk directive in there. */
3004 if (! TARGET_REG_NAMES)
3006 int inputs = current_frame_info.n_input_regs;
3007 int locals = current_frame_info.n_local_regs;
3008 int outputs = current_frame_info.n_output_regs;
3010 for (i = 0; i < inputs; i++)
3011 reg_names[IN_REG (i)] = ia64_reg_numbers[i];
3012 for (i = 0; i < locals; i++)
3013 reg_names[LOC_REG (i)] = ia64_reg_numbers[inputs + i];
3014 for (i = 0; i < outputs; i++)
3015 reg_names[OUT_REG (i)] = ia64_reg_numbers[inputs + locals + i];
3018 /* Set the frame pointer register name. The regnum is logically loc79,
3019 but of course we'll not have allocated that many locals. Rather than
3020 worrying about renumbering the existing rtxs, we adjust the name. */
3021 /* ??? This code means that we can never use one local register when
3022 there is a frame pointer. loc79 gets wasted in this case, as it is
3023 renamed to a register that will never be used. See also the try_locals
3024 code in find_gr_spill. */
3025 if (current_frame_info.r[reg_fp])
3027 const char *tmp = reg_names[HARD_FRAME_POINTER_REGNUM];
3028 reg_names[HARD_FRAME_POINTER_REGNUM]
3029 = reg_names[current_frame_info.r[reg_fp]];
3030 reg_names[current_frame_info.r[reg_fp]] = tmp;
3033 /* We don't need an alloc instruction if we've used no outputs or locals. */
3034 if (current_frame_info.n_local_regs == 0
3035 && current_frame_info.n_output_regs == 0
3036 && current_frame_info.n_input_regs <= crtl->args.info.int_regs
3037 && !TEST_HARD_REG_BIT (current_frame_info.mask, AR_PFS_REGNUM))
3039 /* If there is no alloc, but there are input registers used, then we
3040 need a .regstk directive. */
3041 current_frame_info.need_regstk = (TARGET_REG_NAMES != 0);
3042 ar_pfs_save_reg = NULL_RTX;
3046 current_frame_info.need_regstk = 0;
3048 if (current_frame_info.r[reg_save_ar_pfs])
3050 regno = current_frame_info.r[reg_save_ar_pfs];
3051 reg_emitted (reg_save_ar_pfs);
3054 regno = next_scratch_gr_reg ();
3055 ar_pfs_save_reg = gen_rtx_REG (DImode, regno);
3057 insn = emit_insn (gen_alloc (ar_pfs_save_reg,
3058 GEN_INT (current_frame_info.n_input_regs),
3059 GEN_INT (current_frame_info.n_local_regs),
3060 GEN_INT (current_frame_info.n_output_regs),
3061 GEN_INT (current_frame_info.n_rotate_regs)));
3062 RTX_FRAME_RELATED_P (insn) = (current_frame_info.r[reg_save_ar_pfs] != 0);
3065 /* Set up frame pointer, stack pointer, and spill iterators. */
3067 n_varargs = cfun->machine->n_varargs;
3068 setup_spill_pointers (current_frame_info.n_spilled + n_varargs,
3069 stack_pointer_rtx, 0);
3071 if (frame_pointer_needed)
3073 insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
3074 RTX_FRAME_RELATED_P (insn) = 1;
3077 if (current_frame_info.total_size != 0)
3079 rtx frame_size_rtx = GEN_INT (- current_frame_info.total_size);
3082 if (satisfies_constraint_I (frame_size_rtx))
3083 offset = frame_size_rtx;
3086 regno = next_scratch_gr_reg ();
3087 offset = gen_rtx_REG (DImode, regno);
3088 emit_move_insn (offset, frame_size_rtx);
3091 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
3092 stack_pointer_rtx, offset));
3094 if (! frame_pointer_needed)
3096 RTX_FRAME_RELATED_P (insn) = 1;
3097 if (GET_CODE (offset) != CONST_INT)
3100 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3101 gen_rtx_SET (VOIDmode,
3103 gen_rtx_PLUS (DImode,
3110 /* ??? At this point we must generate a magic insn that appears to
3111 modify the stack pointer, the frame pointer, and all spill
3112 iterators. This would allow the most scheduling freedom. For
3113 now, just hard stop. */
3114 emit_insn (gen_blockage ());
3117 /* Must copy out ar.unat before doing any integer spills. */
3118 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_UNAT_REGNUM))
3120 if (current_frame_info.r[reg_save_ar_unat])
3123 = gen_rtx_REG (DImode, current_frame_info.r[reg_save_ar_unat]);
3124 reg_emitted (reg_save_ar_unat);
3128 alt_regno = next_scratch_gr_reg ();
3129 ar_unat_save_reg = gen_rtx_REG (DImode, alt_regno);
3130 current_frame_info.gr_used_mask |= 1 << alt_regno;
3133 reg = gen_rtx_REG (DImode, AR_UNAT_REGNUM);
3134 insn = emit_move_insn (ar_unat_save_reg, reg);
3135 RTX_FRAME_RELATED_P (insn) = (current_frame_info.r[reg_save_ar_unat] != 0);
3137 /* Even if we're not going to generate an epilogue, we still
3138 need to save the register so that EH works. */
3139 if (! epilogue_p && current_frame_info.r[reg_save_ar_unat])
3140 emit_insn (gen_prologue_use (ar_unat_save_reg));
3143 ar_unat_save_reg = NULL_RTX;
3145 /* Spill all varargs registers. Do this before spilling any GR registers,
3146 since we want the UNAT bits for the GR registers to override the UNAT
3147 bits from varargs, which we don't care about. */
3150 for (regno = GR_ARG_FIRST + 7; n_varargs > 0; --n_varargs, --regno)
3152 reg = gen_rtx_REG (DImode, regno);
3153 do_spill (gen_gr_spill, reg, cfa_off += 8, NULL_RTX);
3156 /* Locate the bottom of the register save area. */
3157 cfa_off = (current_frame_info.spill_cfa_off
3158 + current_frame_info.spill_size
3159 + current_frame_info.extra_spill_size);
3161 /* Save the predicate register block either in a register or in memory. */
3162 if (TEST_HARD_REG_BIT (current_frame_info.mask, PR_REG (0)))
3164 reg = gen_rtx_REG (DImode, PR_REG (0));
3165 if (current_frame_info.r[reg_save_pr] != 0)
3167 alt_reg = gen_rtx_REG (DImode, current_frame_info.r[reg_save_pr]);
3168 reg_emitted (reg_save_pr);
3169 insn = emit_move_insn (alt_reg, reg);
3171 /* ??? Denote pr spill/fill by a DImode move that modifies all
3172 64 hard registers. */
3173 RTX_FRAME_RELATED_P (insn) = 1;
3175 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
3176 gen_rtx_SET (VOIDmode, alt_reg, reg),
3179 /* Even if we're not going to generate an epilogue, we still
3180 need to save the register so that EH works. */
3182 emit_insn (gen_prologue_use (alt_reg));
3186 alt_regno = next_scratch_gr_reg ();
3187 alt_reg = gen_rtx_REG (DImode, alt_regno);
3188 insn = emit_move_insn (alt_reg, reg);
3189 do_spill (gen_movdi_x, alt_reg, cfa_off, reg);
3194 /* Handle AR regs in numerical order. All of them get special handling. */
3195 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_UNAT_REGNUM)
3196 && current_frame_info.r[reg_save_ar_unat] == 0)
3198 reg = gen_rtx_REG (DImode, AR_UNAT_REGNUM);
3199 do_spill (gen_movdi_x, ar_unat_save_reg, cfa_off, reg);
3203 /* The alloc insn already copied ar.pfs into a general register. The
3204 only thing we have to do now is copy that register to a stack slot
3205 if we'd not allocated a local register for the job. */
3206 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_PFS_REGNUM)
3207 && current_frame_info.r[reg_save_ar_pfs] == 0)
3209 reg = gen_rtx_REG (DImode, AR_PFS_REGNUM);
3210 do_spill (gen_movdi_x, ar_pfs_save_reg, cfa_off, reg);
3214 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_LC_REGNUM))
3216 reg = gen_rtx_REG (DImode, AR_LC_REGNUM);
3217 if (current_frame_info.r[reg_save_ar_lc] != 0)
3219 alt_reg = gen_rtx_REG (DImode, current_frame_info.r[reg_save_ar_lc]);
3220 reg_emitted (reg_save_ar_lc);
3221 insn = emit_move_insn (alt_reg, reg);
3222 RTX_FRAME_RELATED_P (insn) = 1;
3224 /* Even if we're not going to generate an epilogue, we still
3225 need to save the register so that EH works. */
3227 emit_insn (gen_prologue_use (alt_reg));
3231 alt_regno = next_scratch_gr_reg ();
3232 alt_reg = gen_rtx_REG (DImode, alt_regno);
3233 emit_move_insn (alt_reg, reg);
3234 do_spill (gen_movdi_x, alt_reg, cfa_off, reg);
3239 /* Save the return pointer. */
3240 if (TEST_HARD_REG_BIT (current_frame_info.mask, BR_REG (0)))
3242 reg = gen_rtx_REG (DImode, BR_REG (0));
3243 if (current_frame_info.r[reg_save_b0] != 0)
3245 alt_reg = gen_rtx_REG (DImode, current_frame_info.r[reg_save_b0]);
3246 reg_emitted (reg_save_b0);
3247 insn = emit_move_insn (alt_reg, reg);
3248 RTX_FRAME_RELATED_P (insn) = 1;
3250 /* Even if we're not going to generate an epilogue, we still
3251 need to save the register so that EH works. */
3253 emit_insn (gen_prologue_use (alt_reg));
3257 alt_regno = next_scratch_gr_reg ();
3258 alt_reg = gen_rtx_REG (DImode, alt_regno);
3259 emit_move_insn (alt_reg, reg);
3260 do_spill (gen_movdi_x, alt_reg, cfa_off, reg);
3265 if (current_frame_info.r[reg_save_gp])
3267 reg_emitted (reg_save_gp);
3268 insn = emit_move_insn (gen_rtx_REG (DImode,
3269 current_frame_info.r[reg_save_gp]),
3270 pic_offset_table_rtx);
3273 /* We should now be at the base of the gr/br/fr spill area. */
3274 gcc_assert (cfa_off == (current_frame_info.spill_cfa_off
3275 + current_frame_info.spill_size));
3277 /* Spill all general registers. */
3278 for (regno = GR_REG (1); regno <= GR_REG (31); ++regno)
3279 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3281 reg = gen_rtx_REG (DImode, regno);
3282 do_spill (gen_gr_spill, reg, cfa_off, reg);
3286 /* Spill the rest of the BR registers. */
3287 for (regno = BR_REG (1); regno <= BR_REG (7); ++regno)
3288 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3290 alt_regno = next_scratch_gr_reg ();
3291 alt_reg = gen_rtx_REG (DImode, alt_regno);
3292 reg = gen_rtx_REG (DImode, regno);
3293 emit_move_insn (alt_reg, reg);
3294 do_spill (gen_movdi_x, alt_reg, cfa_off, reg);
3298 /* Align the frame and spill all FR registers. */
3299 for (regno = FR_REG (2); regno <= FR_REG (127); ++regno)
3300 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3302 gcc_assert (!(cfa_off & 15));
3303 reg = gen_rtx_REG (XFmode, regno);
3304 do_spill (gen_fr_spill_x, reg, cfa_off, reg);
3308 gcc_assert (cfa_off == current_frame_info.spill_cfa_off);
3310 finish_spill_pointers ();
3313 /* Called after register allocation to add any instructions needed for the
3314 epilogue. Using an epilogue insn is favored compared to putting all of the
3315 instructions in output_function_prologue(), since it allows the scheduler
3316 to intermix instructions with the saves of the caller saved registers. In
3317 some cases, it might be necessary to emit a barrier instruction as the last
3318 insn to prevent such scheduling. */
3321 ia64_expand_epilogue (int sibcall_p)
3323 rtx insn, reg, alt_reg, ar_unat_save_reg;
3324 int regno, alt_regno, cfa_off;
3326 ia64_compute_frame_size (get_frame_size ());
3328 /* If there is a frame pointer, then we use it instead of the stack
3329 pointer, so that the stack pointer does not need to be valid when
3330 the epilogue starts. See EXIT_IGNORE_STACK. */
3331 if (frame_pointer_needed)
3332 setup_spill_pointers (current_frame_info.n_spilled,
3333 hard_frame_pointer_rtx, 0);
3335 setup_spill_pointers (current_frame_info.n_spilled, stack_pointer_rtx,
3336 current_frame_info.total_size);
3338 if (current_frame_info.total_size != 0)
3340 /* ??? At this point we must generate a magic insn that appears to
3341 modify the spill iterators and the frame pointer. This would
3342 allow the most scheduling freedom. For now, just hard stop. */
3343 emit_insn (gen_blockage ());
3346 /* Locate the bottom of the register save area. */
3347 cfa_off = (current_frame_info.spill_cfa_off
3348 + current_frame_info.spill_size
3349 + current_frame_info.extra_spill_size);
3351 /* Restore the predicate registers. */
3352 if (TEST_HARD_REG_BIT (current_frame_info.mask, PR_REG (0)))
3354 if (current_frame_info.r[reg_save_pr] != 0)
3356 alt_reg = gen_rtx_REG (DImode, current_frame_info.r[reg_save_pr]);
3357 reg_emitted (reg_save_pr);
3361 alt_regno = next_scratch_gr_reg ();
3362 alt_reg = gen_rtx_REG (DImode, alt_regno);
3363 do_restore (gen_movdi_x, alt_reg, cfa_off);
3366 reg = gen_rtx_REG (DImode, PR_REG (0));
3367 emit_move_insn (reg, alt_reg);
3370 /* Restore the application registers. */
3372 /* Load the saved unat from the stack, but do not restore it until
3373 after the GRs have been restored. */
3374 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_UNAT_REGNUM))
3376 if (current_frame_info.r[reg_save_ar_unat] != 0)
3379 = gen_rtx_REG (DImode, current_frame_info.r[reg_save_ar_unat]);
3380 reg_emitted (reg_save_ar_unat);
3384 alt_regno = next_scratch_gr_reg ();
3385 ar_unat_save_reg = gen_rtx_REG (DImode, alt_regno);
3386 current_frame_info.gr_used_mask |= 1 << alt_regno;
3387 do_restore (gen_movdi_x, ar_unat_save_reg, cfa_off);
3392 ar_unat_save_reg = NULL_RTX;
3394 if (current_frame_info.r[reg_save_ar_pfs] != 0)
3396 reg_emitted (reg_save_ar_pfs);
3397 alt_reg = gen_rtx_REG (DImode, current_frame_info.r[reg_save_ar_pfs]);
3398 reg = gen_rtx_REG (DImode, AR_PFS_REGNUM);
3399 emit_move_insn (reg, alt_reg);
3401 else if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_PFS_REGNUM))
3403 alt_regno = next_scratch_gr_reg ();
3404 alt_reg = gen_rtx_REG (DImode, alt_regno);
3405 do_restore (gen_movdi_x, alt_reg, cfa_off);
3407 reg = gen_rtx_REG (DImode, AR_PFS_REGNUM);
3408 emit_move_insn (reg, alt_reg);
3411 if (TEST_HARD_REG_BIT (current_frame_info.mask, AR_LC_REGNUM))
3413 if (current_frame_info.r[reg_save_ar_lc] != 0)
3415 alt_reg = gen_rtx_REG (DImode, current_frame_info.r[reg_save_ar_lc]);
3416 reg_emitted (reg_save_ar_lc);
3420 alt_regno = next_scratch_gr_reg ();
3421 alt_reg = gen_rtx_REG (DImode, alt_regno);
3422 do_restore (gen_movdi_x, alt_reg, cfa_off);
3425 reg = gen_rtx_REG (DImode, AR_LC_REGNUM);
3426 emit_move_insn (reg, alt_reg);
3429 /* Restore the return pointer. */
3430 if (TEST_HARD_REG_BIT (current_frame_info.mask, BR_REG (0)))
3432 if (current_frame_info.r[reg_save_b0] != 0)
3434 alt_reg = gen_rtx_REG (DImode, current_frame_info.r[reg_save_b0]);
3435 reg_emitted (reg_save_b0);
3439 alt_regno = next_scratch_gr_reg ();
3440 alt_reg = gen_rtx_REG (DImode, alt_regno);
3441 do_restore (gen_movdi_x, alt_reg, cfa_off);
3444 reg = gen_rtx_REG (DImode, BR_REG (0));
3445 emit_move_insn (reg, alt_reg);
3448 /* We should now be at the base of the gr/br/fr spill area. */
3449 gcc_assert (cfa_off == (current_frame_info.spill_cfa_off
3450 + current_frame_info.spill_size));
3452 /* The GP may be stored on the stack in the prologue, but it's
3453 never restored in the epilogue. Skip the stack slot. */
3454 if (TEST_HARD_REG_BIT (current_frame_info.mask, GR_REG (1)))
3457 /* Restore all general registers. */
3458 for (regno = GR_REG (2); regno <= GR_REG (31); ++regno)
3459 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3461 reg = gen_rtx_REG (DImode, regno);
3462 do_restore (gen_gr_restore, reg, cfa_off);
3466 /* Restore the branch registers. */
3467 for (regno = BR_REG (1); regno <= BR_REG (7); ++regno)
3468 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3470 alt_regno = next_scratch_gr_reg ();
3471 alt_reg = gen_rtx_REG (DImode, alt_regno);
3472 do_restore (gen_movdi_x, alt_reg, cfa_off);
3474 reg = gen_rtx_REG (DImode, regno);
3475 emit_move_insn (reg, alt_reg);
3478 /* Restore floating point registers. */
3479 for (regno = FR_REG (2); regno <= FR_REG (127); ++regno)
3480 if (TEST_HARD_REG_BIT (current_frame_info.mask, regno))
3482 gcc_assert (!(cfa_off & 15));
3483 reg = gen_rtx_REG (XFmode, regno);
3484 do_restore (gen_fr_restore_x, reg, cfa_off);