1 /* Definitions of target machine for GNU compiler.
2 Copyright (C) 1999-2014 Free Software Foundation, Inc.
3 Contributed by James E. Wilson <wilson@cygnus.com> and
4 David Mosberger <davidm@hpl.hp.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
28 #include "stringpool.h"
29 #include "stor-layout.h"
33 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
45 #include "basic-block.h"
47 #include "diagnostic-core.h"
48 #include "sched-int.h"
51 #include "target-def.h"
52 #include "common/common-target.h"
54 #include "hash-table.h"
55 #include "langhooks.h"
57 #include "basic-block.h"
58 #include "tree-ssa-alias.h"
59 #include "internal-fn.h"
60 #include "gimple-fold.h"
62 #include "gimple-expr.h"
71 #include "tm-constrs.h"
72 #include "sel-sched.h"
78 /* This is used for communication between ASM_OUTPUT_LABEL and
79 ASM_OUTPUT_LABELREF. */
80 int ia64_asm_output_label
= 0;
82 /* Register names for ia64_expand_prologue. */
83 static const char * const ia64_reg_numbers
[96] =
84 { "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
85 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
86 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
87 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
88 "r64", "r65", "r66", "r67", "r68", "r69", "r70", "r71",
89 "r72", "r73", "r74", "r75", "r76", "r77", "r78", "r79",
90 "r80", "r81", "r82", "r83", "r84", "r85", "r86", "r87",
91 "r88", "r89", "r90", "r91", "r92", "r93", "r94", "r95",
92 "r96", "r97", "r98", "r99", "r100","r101","r102","r103",
93 "r104","r105","r106","r107","r108","r109","r110","r111",
94 "r112","r113","r114","r115","r116","r117","r118","r119",
95 "r120","r121","r122","r123","r124","r125","r126","r127"};
97 /* ??? These strings could be shared with REGISTER_NAMES. */
98 static const char * const ia64_input_reg_names
[8] =
99 { "in0", "in1", "in2", "in3", "in4", "in5", "in6", "in7" };
101 /* ??? These strings could be shared with REGISTER_NAMES. */
102 static const char * const ia64_local_reg_names
[80] =
103 { "loc0", "loc1", "loc2", "loc3", "loc4", "loc5", "loc6", "loc7",
104 "loc8", "loc9", "loc10","loc11","loc12","loc13","loc14","loc15",
105 "loc16","loc17","loc18","loc19","loc20","loc21","loc22","loc23",
106 "loc24","loc25","loc26","loc27","loc28","loc29","loc30","loc31",
107 "loc32","loc33","loc34","loc35","loc36","loc37","loc38","loc39",
108 "loc40","loc41","loc42","loc43","loc44","loc45","loc46","loc47",
109 "loc48","loc49","loc50","loc51","loc52","loc53","loc54","loc55",
110 "loc56","loc57","loc58","loc59","loc60","loc61","loc62","loc63",
111 "loc64","loc65","loc66","loc67","loc68","loc69","loc70","loc71",
112 "loc72","loc73","loc74","loc75","loc76","loc77","loc78","loc79" };
114 /* ??? These strings could be shared with REGISTER_NAMES. */
115 static const char * const ia64_output_reg_names
[8] =
116 { "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7" };
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_insn
*, rtx_insn
*);
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_insn
*, int);
173 static int ia64_dfa_new_cycle (FILE *, int, rtx_insn
*, int, int, int *);
174 static void ia64_h_i_d_extended (void);
175 static void * ia64_alloc_sched_context (void);
176 static void ia64_init_sched_context (void *, bool);
177 static void ia64_set_sched_context (void *);
178 static void ia64_clear_sched_context (void *);
179 static void ia64_free_sched_context (void *);
180 static int ia64_mode_to_int (enum machine_mode
);
181 static void ia64_set_sched_flags (spec_info_t
);
182 static ds_t
ia64_get_insn_spec_ds (rtx_insn
*);
183 static ds_t
ia64_get_insn_checked_ds (rtx_insn
*);
184 static bool ia64_skip_rtx_p (const_rtx
);
185 static int ia64_speculate_insn (rtx_insn
*, ds_t
, rtx
*);
186 static bool ia64_needs_block_p (ds_t
);
187 static rtx
ia64_gen_spec_check (rtx_insn
*, rtx_insn
*, ds_t
);
188 static int ia64_spec_check_p (rtx
);
189 static int ia64_spec_check_src_p (rtx
);
190 static rtx
gen_tls_get_addr (void);
191 static rtx
gen_thread_pointer (void);
192 static int find_gr_spill (enum ia64_frame_regs
, int);
193 static int next_scratch_gr_reg (void);
194 static void mark_reg_gr_used_mask (rtx
, void *);
195 static void ia64_compute_frame_size (HOST_WIDE_INT
);
196 static void setup_spill_pointers (int, rtx
, HOST_WIDE_INT
);
197 static void finish_spill_pointers (void);
198 static rtx
spill_restore_mem (rtx
, HOST_WIDE_INT
);
199 static void do_spill (rtx (*)(rtx
, rtx
, rtx
), rtx
, HOST_WIDE_INT
, rtx
);
200 static void do_restore (rtx (*)(rtx
, rtx
, rtx
), rtx
, HOST_WIDE_INT
);
201 static rtx
gen_movdi_x (rtx
, rtx
, rtx
);
202 static rtx
gen_fr_spill_x (rtx
, rtx
, rtx
);
203 static rtx
gen_fr_restore_x (rtx
, rtx
, rtx
);
205 static void ia64_option_override (void);
206 static bool ia64_can_eliminate (const int, const int);
207 static enum machine_mode
hfa_element_mode (const_tree
, bool);
208 static void ia64_setup_incoming_varargs (cumulative_args_t
, enum machine_mode
,
210 static int ia64_arg_partial_bytes (cumulative_args_t
, enum machine_mode
,
212 static rtx
ia64_function_arg_1 (cumulative_args_t
, enum machine_mode
,
213 const_tree
, bool, bool);
214 static rtx
ia64_function_arg (cumulative_args_t
, enum machine_mode
,
216 static rtx
ia64_function_incoming_arg (cumulative_args_t
,
217 enum machine_mode
, const_tree
, bool);
218 static void ia64_function_arg_advance (cumulative_args_t
, enum machine_mode
,
220 static unsigned int ia64_function_arg_boundary (enum machine_mode
,
222 static bool ia64_function_ok_for_sibcall (tree
, tree
);
223 static bool ia64_return_in_memory (const_tree
, const_tree
);
224 static rtx
ia64_function_value (const_tree
, const_tree
, bool);
225 static rtx
ia64_libcall_value (enum machine_mode
, const_rtx
);
226 static bool ia64_function_value_regno_p (const unsigned int);
227 static int ia64_register_move_cost (enum machine_mode
, reg_class_t
,
229 static int ia64_memory_move_cost (enum machine_mode mode
, reg_class_t
,
231 static bool ia64_rtx_costs (rtx
, int, int, int, int *, bool);
232 static int ia64_unspec_may_trap_p (const_rtx
, unsigned);
233 static void fix_range (const char *);
234 static struct machine_function
* ia64_init_machine_status (void);
235 static void emit_insn_group_barriers (FILE *);
236 static void emit_all_insn_group_barriers (FILE *);
237 static void final_emit_insn_group_barriers (FILE *);
238 static void emit_predicate_relation_info (void);
239 static void ia64_reorg (void);
240 static bool ia64_in_small_data_p (const_tree
);
241 static void process_epilogue (FILE *, rtx
, bool, bool);
243 static bool ia64_assemble_integer (rtx
, unsigned int, int);
244 static void ia64_output_function_prologue (FILE *, HOST_WIDE_INT
);
245 static void ia64_output_function_epilogue (FILE *, HOST_WIDE_INT
);
246 static void ia64_output_function_end_prologue (FILE *);
248 static void ia64_print_operand (FILE *, rtx
, int);
249 static void ia64_print_operand_address (FILE *, rtx
);
250 static bool ia64_print_operand_punct_valid_p (unsigned char code
);
252 static int ia64_issue_rate (void);
253 static int ia64_adjust_cost_2 (rtx_insn
*, int, rtx_insn
*, int, dw_t
);
254 static void ia64_sched_init (FILE *, int, int);
255 static void ia64_sched_init_global (FILE *, int, int);
256 static void ia64_sched_finish_global (FILE *, int);
257 static void ia64_sched_finish (FILE *, int);
258 static int ia64_dfa_sched_reorder (FILE *, int, rtx_insn
**, int *, int, int);
259 static int ia64_sched_reorder (FILE *, int, rtx_insn
**, int *, int);
260 static int ia64_sched_reorder2 (FILE *, int, rtx_insn
**, int *, int);
261 static int ia64_variable_issue (FILE *, int, rtx_insn
*, int);
263 static void ia64_asm_unwind_emit (FILE *, rtx_insn
*);
264 static void ia64_asm_emit_except_personality (rtx
);
265 static void ia64_asm_init_sections (void);
267 static enum unwind_info_type
ia64_debug_unwind_info (void);
269 static struct bundle_state
*get_free_bundle_state (void);
270 static void free_bundle_state (struct bundle_state
*);
271 static void initiate_bundle_states (void);
272 static void finish_bundle_states (void);
273 static int insert_bundle_state (struct bundle_state
*);
274 static void initiate_bundle_state_table (void);
275 static void finish_bundle_state_table (void);
276 static int try_issue_nops (struct bundle_state
*, int);
277 static int try_issue_insn (struct bundle_state
*, rtx
);
278 static void issue_nops_and_insn (struct bundle_state
*, int, rtx
, int, int);
279 static int get_max_pos (state_t
);
280 static int get_template (state_t
, int);
282 static rtx
get_next_important_insn (rtx
, rtx
);
283 static bool important_for_bundling_p (rtx
);
284 static bool unknown_for_bundling_p (rtx
);
285 static void bundling (FILE *, int, rtx
, rtx
);
287 static void ia64_output_mi_thunk (FILE *, tree
, HOST_WIDE_INT
,
288 HOST_WIDE_INT
, tree
);
289 static void ia64_file_start (void);
290 static void ia64_globalize_decl_name (FILE *, tree
);
292 static int ia64_hpux_reloc_rw_mask (void) ATTRIBUTE_UNUSED
;
293 static int ia64_reloc_rw_mask (void) ATTRIBUTE_UNUSED
;
294 static section
*ia64_select_rtx_section (enum machine_mode
, rtx
,
295 unsigned HOST_WIDE_INT
);
296 static void ia64_output_dwarf_dtprel (FILE *, int, rtx
)
298 static unsigned int ia64_section_type_flags (tree
, const char *, int);
299 static void ia64_init_libfuncs (void)
301 static void ia64_hpux_init_libfuncs (void)
303 static void ia64_sysv4_init_libfuncs (void)
305 static void ia64_vms_init_libfuncs (void)
307 static void ia64_soft_fp_init_libfuncs (void)
309 static bool ia64_vms_valid_pointer_mode (enum machine_mode mode
)
311 static tree
ia64_vms_common_object_attribute (tree
*, tree
, tree
, int, bool *)
314 static tree
ia64_handle_model_attribute (tree
*, tree
, tree
, int, bool *);
315 static tree
ia64_handle_version_id_attribute (tree
*, tree
, tree
, int, bool *);
316 static void ia64_encode_section_info (tree
, rtx
, int);
317 static rtx
ia64_struct_value_rtx (tree
, int);
318 static tree
ia64_gimplify_va_arg (tree
, tree
, gimple_seq
*, gimple_seq
*);
319 static bool ia64_scalar_mode_supported_p (enum machine_mode mode
);
320 static bool ia64_vector_mode_supported_p (enum machine_mode mode
);
321 static bool ia64_legitimate_constant_p (enum machine_mode
, rtx
);
322 static bool ia64_legitimate_address_p (enum machine_mode
, rtx
, bool);
323 static bool ia64_cannot_force_const_mem (enum machine_mode
, rtx
);
324 static const char *ia64_mangle_type (const_tree
);
325 static const char *ia64_invalid_conversion (const_tree
, const_tree
);
326 static const char *ia64_invalid_unary_op (int, const_tree
);
327 static const char *ia64_invalid_binary_op (int, const_tree
, const_tree
);
328 static enum machine_mode
ia64_c_mode_for_suffix (char);
329 static void ia64_trampoline_init (rtx
, tree
, rtx
);
330 static void ia64_override_options_after_change (void);
331 static bool ia64_member_type_forces_blk (const_tree
, enum machine_mode
);
333 static tree
ia64_builtin_decl (unsigned, bool);
335 static reg_class_t
ia64_preferred_reload_class (rtx
, reg_class_t
);
336 static enum machine_mode
ia64_get_reg_raw_mode (int regno
);
337 static section
* ia64_hpux_function_section (tree
, enum node_frequency
,
340 static bool ia64_vectorize_vec_perm_const_ok (enum machine_mode vmode
,
341 const unsigned char *sel
);
343 #define MAX_VECT_LEN 8
345 struct expand_vec_perm_d
347 rtx target
, op0
, op1
;
348 unsigned char perm
[MAX_VECT_LEN
];
349 enum machine_mode vmode
;
355 static bool ia64_expand_vec_perm_const_1 (struct expand_vec_perm_d
*d
);
358 /* Table of valid machine attributes. */
359 static const struct attribute_spec ia64_attribute_table
[] =
361 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
362 affects_type_identity } */
363 { "syscall_linkage", 0, 0, false, true, true, NULL
, false },
364 { "model", 1, 1, true, false, false, ia64_handle_model_attribute
,
366 #if TARGET_ABI_OPEN_VMS
367 { "common_object", 1, 1, true, false, false,
368 ia64_vms_common_object_attribute
, false },
370 { "version_id", 1, 1, true, false, false,
371 ia64_handle_version_id_attribute
, false },
372 { NULL
, 0, 0, false, false, false, NULL
, false }
375 /* Initialize the GCC target structure. */
376 #undef TARGET_ATTRIBUTE_TABLE
377 #define TARGET_ATTRIBUTE_TABLE ia64_attribute_table
379 #undef TARGET_INIT_BUILTINS
380 #define TARGET_INIT_BUILTINS ia64_init_builtins
382 #undef TARGET_EXPAND_BUILTIN
383 #define TARGET_EXPAND_BUILTIN ia64_expand_builtin
385 #undef TARGET_BUILTIN_DECL
386 #define TARGET_BUILTIN_DECL ia64_builtin_decl
388 #undef TARGET_ASM_BYTE_OP
389 #define TARGET_ASM_BYTE_OP "\tdata1\t"
390 #undef TARGET_ASM_ALIGNED_HI_OP
391 #define TARGET_ASM_ALIGNED_HI_OP "\tdata2\t"
392 #undef TARGET_ASM_ALIGNED_SI_OP
393 #define TARGET_ASM_ALIGNED_SI_OP "\tdata4\t"
394 #undef TARGET_ASM_ALIGNED_DI_OP
395 #define TARGET_ASM_ALIGNED_DI_OP "\tdata8\t"
396 #undef TARGET_ASM_UNALIGNED_HI_OP
397 #define TARGET_ASM_UNALIGNED_HI_OP "\tdata2.ua\t"
398 #undef TARGET_ASM_UNALIGNED_SI_OP
399 #define TARGET_ASM_UNALIGNED_SI_OP "\tdata4.ua\t"
400 #undef TARGET_ASM_UNALIGNED_DI_OP
401 #define TARGET_ASM_UNALIGNED_DI_OP "\tdata8.ua\t"
402 #undef TARGET_ASM_INTEGER
403 #define TARGET_ASM_INTEGER ia64_assemble_integer
405 #undef TARGET_OPTION_OVERRIDE
406 #define TARGET_OPTION_OVERRIDE ia64_option_override
408 #undef TARGET_ASM_FUNCTION_PROLOGUE
409 #define TARGET_ASM_FUNCTION_PROLOGUE ia64_output_function_prologue
410 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
411 #define TARGET_ASM_FUNCTION_END_PROLOGUE ia64_output_function_end_prologue
412 #undef TARGET_ASM_FUNCTION_EPILOGUE
413 #define TARGET_ASM_FUNCTION_EPILOGUE ia64_output_function_epilogue
415 #undef TARGET_PRINT_OPERAND
416 #define TARGET_PRINT_OPERAND ia64_print_operand
417 #undef TARGET_PRINT_OPERAND_ADDRESS
418 #define TARGET_PRINT_OPERAND_ADDRESS ia64_print_operand_address
419 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
420 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P ia64_print_operand_punct_valid_p
422 #undef TARGET_IN_SMALL_DATA_P
423 #define TARGET_IN_SMALL_DATA_P ia64_in_small_data_p
425 #undef TARGET_SCHED_ADJUST_COST_2
426 #define TARGET_SCHED_ADJUST_COST_2 ia64_adjust_cost_2
427 #undef TARGET_SCHED_ISSUE_RATE
428 #define TARGET_SCHED_ISSUE_RATE ia64_issue_rate
429 #undef TARGET_SCHED_VARIABLE_ISSUE
430 #define TARGET_SCHED_VARIABLE_ISSUE ia64_variable_issue
431 #undef TARGET_SCHED_INIT
432 #define TARGET_SCHED_INIT ia64_sched_init
433 #undef TARGET_SCHED_FINISH
434 #define TARGET_SCHED_FINISH ia64_sched_finish
435 #undef TARGET_SCHED_INIT_GLOBAL
436 #define TARGET_SCHED_INIT_GLOBAL ia64_sched_init_global
437 #undef TARGET_SCHED_FINISH_GLOBAL
438 #define TARGET_SCHED_FINISH_GLOBAL ia64_sched_finish_global
439 #undef TARGET_SCHED_REORDER
440 #define TARGET_SCHED_REORDER ia64_sched_reorder
441 #undef TARGET_SCHED_REORDER2
442 #define TARGET_SCHED_REORDER2 ia64_sched_reorder2
444 #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
445 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK ia64_dependencies_evaluation_hook
447 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
448 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD ia64_first_cycle_multipass_dfa_lookahead
450 #undef TARGET_SCHED_INIT_DFA_PRE_CYCLE_INSN
451 #define TARGET_SCHED_INIT_DFA_PRE_CYCLE_INSN ia64_init_dfa_pre_cycle_insn
452 #undef TARGET_SCHED_DFA_PRE_CYCLE_INSN
453 #define TARGET_SCHED_DFA_PRE_CYCLE_INSN ia64_dfa_pre_cycle_insn
455 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD
456 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD\
457 ia64_first_cycle_multipass_dfa_lookahead_guard
459 #undef TARGET_SCHED_DFA_NEW_CYCLE
460 #define TARGET_SCHED_DFA_NEW_CYCLE ia64_dfa_new_cycle
462 #undef TARGET_SCHED_H_I_D_EXTENDED
463 #define TARGET_SCHED_H_I_D_EXTENDED ia64_h_i_d_extended
465 #undef TARGET_SCHED_ALLOC_SCHED_CONTEXT
466 #define TARGET_SCHED_ALLOC_SCHED_CONTEXT ia64_alloc_sched_context
468 #undef TARGET_SCHED_INIT_SCHED_CONTEXT
469 #define TARGET_SCHED_INIT_SCHED_CONTEXT ia64_init_sched_context
471 #undef TARGET_SCHED_SET_SCHED_CONTEXT
472 #define TARGET_SCHED_SET_SCHED_CONTEXT ia64_set_sched_context
474 #undef TARGET_SCHED_CLEAR_SCHED_CONTEXT
475 #define TARGET_SCHED_CLEAR_SCHED_CONTEXT ia64_clear_sched_context
477 #undef TARGET_SCHED_FREE_SCHED_CONTEXT
478 #define TARGET_SCHED_FREE_SCHED_CONTEXT ia64_free_sched_context
480 #undef TARGET_SCHED_SET_SCHED_FLAGS
481 #define TARGET_SCHED_SET_SCHED_FLAGS ia64_set_sched_flags
483 #undef TARGET_SCHED_GET_INSN_SPEC_DS
484 #define TARGET_SCHED_GET_INSN_SPEC_DS ia64_get_insn_spec_ds
486 #undef TARGET_SCHED_GET_INSN_CHECKED_DS
487 #define TARGET_SCHED_GET_INSN_CHECKED_DS ia64_get_insn_checked_ds
489 #undef TARGET_SCHED_SPECULATE_INSN
490 #define TARGET_SCHED_SPECULATE_INSN ia64_speculate_insn
492 #undef TARGET_SCHED_NEEDS_BLOCK_P
493 #define TARGET_SCHED_NEEDS_BLOCK_P ia64_needs_block_p
495 #undef TARGET_SCHED_GEN_SPEC_CHECK
496 #define TARGET_SCHED_GEN_SPEC_CHECK ia64_gen_spec_check
498 #undef TARGET_SCHED_SKIP_RTX_P
499 #define TARGET_SCHED_SKIP_RTX_P ia64_skip_rtx_p
501 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
502 #define TARGET_FUNCTION_OK_FOR_SIBCALL ia64_function_ok_for_sibcall
503 #undef TARGET_ARG_PARTIAL_BYTES
504 #define TARGET_ARG_PARTIAL_BYTES ia64_arg_partial_bytes
505 #undef TARGET_FUNCTION_ARG
506 #define TARGET_FUNCTION_ARG ia64_function_arg
507 #undef TARGET_FUNCTION_INCOMING_ARG
508 #define TARGET_FUNCTION_INCOMING_ARG ia64_function_incoming_arg
509 #undef TARGET_FUNCTION_ARG_ADVANCE
510 #define TARGET_FUNCTION_ARG_ADVANCE ia64_function_arg_advance
511 #undef TARGET_FUNCTION_ARG_BOUNDARY
512 #define TARGET_FUNCTION_ARG_BOUNDARY ia64_function_arg_boundary
514 #undef TARGET_ASM_OUTPUT_MI_THUNK
515 #define TARGET_ASM_OUTPUT_MI_THUNK ia64_output_mi_thunk
516 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
517 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
519 #undef TARGET_ASM_FILE_START
520 #define TARGET_ASM_FILE_START ia64_file_start
522 #undef TARGET_ASM_GLOBALIZE_DECL_NAME
523 #define TARGET_ASM_GLOBALIZE_DECL_NAME ia64_globalize_decl_name
525 #undef TARGET_REGISTER_MOVE_COST
526 #define TARGET_REGISTER_MOVE_COST ia64_register_move_cost
527 #undef TARGET_MEMORY_MOVE_COST
528 #define TARGET_MEMORY_MOVE_COST ia64_memory_move_cost
529 #undef TARGET_RTX_COSTS
530 #define TARGET_RTX_COSTS ia64_rtx_costs
531 #undef TARGET_ADDRESS_COST
532 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
534 #undef TARGET_UNSPEC_MAY_TRAP_P
535 #define TARGET_UNSPEC_MAY_TRAP_P ia64_unspec_may_trap_p
537 #undef TARGET_MACHINE_DEPENDENT_REORG
538 #define TARGET_MACHINE_DEPENDENT_REORG ia64_reorg
540 #undef TARGET_ENCODE_SECTION_INFO
541 #define TARGET_ENCODE_SECTION_INFO ia64_encode_section_info
543 #undef TARGET_SECTION_TYPE_FLAGS
544 #define TARGET_SECTION_TYPE_FLAGS ia64_section_type_flags
547 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
548 #define TARGET_ASM_OUTPUT_DWARF_DTPREL ia64_output_dwarf_dtprel
551 /* ??? Investigate. */
553 #undef TARGET_PROMOTE_PROTOTYPES
554 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
557 #undef TARGET_FUNCTION_VALUE
558 #define TARGET_FUNCTION_VALUE ia64_function_value
559 #undef TARGET_LIBCALL_VALUE
560 #define TARGET_LIBCALL_VALUE ia64_libcall_value
561 #undef TARGET_FUNCTION_VALUE_REGNO_P
562 #define TARGET_FUNCTION_VALUE_REGNO_P ia64_function_value_regno_p
564 #undef TARGET_STRUCT_VALUE_RTX
565 #define TARGET_STRUCT_VALUE_RTX ia64_struct_value_rtx
566 #undef TARGET_RETURN_IN_MEMORY
567 #define TARGET_RETURN_IN_MEMORY ia64_return_in_memory
568 #undef TARGET_SETUP_INCOMING_VARARGS
569 #define TARGET_SETUP_INCOMING_VARARGS ia64_setup_incoming_varargs
570 #undef TARGET_STRICT_ARGUMENT_NAMING
571 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
572 #undef TARGET_MUST_PASS_IN_STACK
573 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
574 #undef TARGET_GET_RAW_RESULT_MODE
575 #define TARGET_GET_RAW_RESULT_MODE ia64_get_reg_raw_mode
576 #undef TARGET_GET_RAW_ARG_MODE
577 #define TARGET_GET_RAW_ARG_MODE ia64_get_reg_raw_mode
579 #undef TARGET_MEMBER_TYPE_FORCES_BLK
580 #define TARGET_MEMBER_TYPE_FORCES_BLK ia64_member_type_forces_blk
582 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
583 #define TARGET_GIMPLIFY_VA_ARG_EXPR ia64_gimplify_va_arg
585 #undef TARGET_ASM_UNWIND_EMIT
586 #define TARGET_ASM_UNWIND_EMIT ia64_asm_unwind_emit
587 #undef TARGET_ASM_EMIT_EXCEPT_PERSONALITY
588 #define TARGET_ASM_EMIT_EXCEPT_PERSONALITY ia64_asm_emit_except_personality
589 #undef TARGET_ASM_INIT_SECTIONS
590 #define TARGET_ASM_INIT_SECTIONS ia64_asm_init_sections
592 #undef TARGET_DEBUG_UNWIND_INFO
593 #define TARGET_DEBUG_UNWIND_INFO ia64_debug_unwind_info
595 #undef TARGET_SCALAR_MODE_SUPPORTED_P
596 #define TARGET_SCALAR_MODE_SUPPORTED_P ia64_scalar_mode_supported_p
597 #undef TARGET_VECTOR_MODE_SUPPORTED_P
598 #define TARGET_VECTOR_MODE_SUPPORTED_P ia64_vector_mode_supported_p
600 /* ia64 architecture manual 4.4.7: ... reads, writes, and flushes may occur
601 in an order different from the specified program order. */
602 #undef TARGET_RELAXED_ORDERING
603 #define TARGET_RELAXED_ORDERING true
605 #undef TARGET_LEGITIMATE_CONSTANT_P
606 #define TARGET_LEGITIMATE_CONSTANT_P ia64_legitimate_constant_p
607 #undef TARGET_LEGITIMATE_ADDRESS_P
608 #define TARGET_LEGITIMATE_ADDRESS_P ia64_legitimate_address_p
610 #undef TARGET_CANNOT_FORCE_CONST_MEM
611 #define TARGET_CANNOT_FORCE_CONST_MEM ia64_cannot_force_const_mem
613 #undef TARGET_MANGLE_TYPE
614 #define TARGET_MANGLE_TYPE ia64_mangle_type
616 #undef TARGET_INVALID_CONVERSION
617 #define TARGET_INVALID_CONVERSION ia64_invalid_conversion
618 #undef TARGET_INVALID_UNARY_OP
619 #define TARGET_INVALID_UNARY_OP ia64_invalid_unary_op
620 #undef TARGET_INVALID_BINARY_OP
621 #define TARGET_INVALID_BINARY_OP ia64_invalid_binary_op
623 #undef TARGET_C_MODE_FOR_SUFFIX
624 #define TARGET_C_MODE_FOR_SUFFIX ia64_c_mode_for_suffix
626 #undef TARGET_CAN_ELIMINATE
627 #define TARGET_CAN_ELIMINATE ia64_can_eliminate
629 #undef TARGET_TRAMPOLINE_INIT
630 #define TARGET_TRAMPOLINE_INIT ia64_trampoline_init
632 #undef TARGET_CAN_USE_DOLOOP_P
633 #define TARGET_CAN_USE_DOLOOP_P can_use_doloop_if_innermost
634 #undef TARGET_INVALID_WITHIN_DOLOOP
635 #define TARGET_INVALID_WITHIN_DOLOOP hook_constcharptr_const_rtx_insn_null
637 #undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
638 #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE ia64_override_options_after_change
640 #undef TARGET_PREFERRED_RELOAD_CLASS
641 #define TARGET_PREFERRED_RELOAD_CLASS ia64_preferred_reload_class
643 #undef TARGET_DELAY_SCHED2
644 #define TARGET_DELAY_SCHED2 true
646 /* Variable tracking should be run after all optimizations which
647 change order of insns. It also needs a valid CFG. */
648 #undef TARGET_DELAY_VARTRACK
649 #define TARGET_DELAY_VARTRACK true
651 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
652 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK ia64_vectorize_vec_perm_const_ok
654 struct gcc_target targetm
= TARGET_INITIALIZER
;
658 ADDR_AREA_NORMAL
, /* normal address area */
659 ADDR_AREA_SMALL
/* addressable by "addl" (-2MB < addr < 2MB) */
663 static GTY(()) tree small_ident1
;
664 static GTY(()) tree small_ident2
;
669 if (small_ident1
== 0)
671 small_ident1
= get_identifier ("small");
672 small_ident2
= get_identifier ("__small__");
676 /* Retrieve the address area that has been chosen for the given decl. */
678 static ia64_addr_area
679 ia64_get_addr_area (tree decl
)
683 model_attr
= lookup_attribute ("model", DECL_ATTRIBUTES (decl
));
689 id
= TREE_VALUE (TREE_VALUE (model_attr
));
690 if (id
== small_ident1
|| id
== small_ident2
)
691 return ADDR_AREA_SMALL
;
693 return ADDR_AREA_NORMAL
;
697 ia64_handle_model_attribute (tree
*node
, tree name
, tree args
,
698 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
700 ia64_addr_area addr_area
= ADDR_AREA_NORMAL
;
702 tree arg
, decl
= *node
;
705 arg
= TREE_VALUE (args
);
706 if (arg
== small_ident1
|| arg
== small_ident2
)
708 addr_area
= ADDR_AREA_SMALL
;
712 warning (OPT_Wattributes
, "invalid argument of %qE attribute",
714 *no_add_attrs
= true;
717 switch (TREE_CODE (decl
))
720 if ((DECL_CONTEXT (decl
) && TREE_CODE (DECL_CONTEXT (decl
))
722 && !TREE_STATIC (decl
))
724 error_at (DECL_SOURCE_LOCATION (decl
),
725 "an address area attribute cannot be specified for "
727 *no_add_attrs
= true;
729 area
= ia64_get_addr_area (decl
);
730 if (area
!= ADDR_AREA_NORMAL
&& addr_area
!= area
)
732 error ("address area of %q+D conflicts with previous "
733 "declaration", decl
);
734 *no_add_attrs
= true;
739 error_at (DECL_SOURCE_LOCATION (decl
),
740 "address area attribute cannot be specified for "
742 *no_add_attrs
= true;
746 warning (OPT_Wattributes
, "%qE attribute ignored",
748 *no_add_attrs
= true;
755 /* Part of the low level implementation of DEC Ada pragma Common_Object which
756 enables the shared use of variables stored in overlaid linker areas
757 corresponding to the use of Fortran COMMON. */
760 ia64_vms_common_object_attribute (tree
*node
, tree name
, tree args
,
761 int flags ATTRIBUTE_UNUSED
,
767 gcc_assert (DECL_P (decl
));
769 DECL_COMMON (decl
) = 1;
770 id
= TREE_VALUE (args
);
771 if (TREE_CODE (id
) != IDENTIFIER_NODE
&& TREE_CODE (id
) != STRING_CST
)
773 error ("%qE attribute requires a string constant argument", name
);
774 *no_add_attrs
= true;
780 /* Part of the low level implementation of DEC Ada pragma Common_Object. */
783 ia64_vms_output_aligned_decl_common (FILE *file
, tree decl
, const char *name
,
784 unsigned HOST_WIDE_INT size
,
787 tree attr
= DECL_ATTRIBUTES (decl
);
790 attr
= lookup_attribute ("common_object", attr
);
793 tree id
= TREE_VALUE (TREE_VALUE (attr
));
796 if (TREE_CODE (id
) == IDENTIFIER_NODE
)
797 name
= IDENTIFIER_POINTER (id
);
798 else if (TREE_CODE (id
) == STRING_CST
)
799 name
= TREE_STRING_POINTER (id
);
803 fprintf (file
, "\t.vms_common\t\"%s\",", name
);
806 fprintf (file
, "%s", COMMON_ASM_OP
);
808 /* Code from elfos.h. */
809 assemble_name (file
, name
);
810 fprintf (file
, ","HOST_WIDE_INT_PRINT_UNSIGNED
",%u",
811 size
, align
/ BITS_PER_UNIT
);
817 ia64_encode_addr_area (tree decl
, rtx symbol
)
821 flags
= SYMBOL_REF_FLAGS (symbol
);
822 switch (ia64_get_addr_area (decl
))
824 case ADDR_AREA_NORMAL
: break;
825 case ADDR_AREA_SMALL
: flags
|= SYMBOL_FLAG_SMALL_ADDR
; break;
826 default: gcc_unreachable ();
828 SYMBOL_REF_FLAGS (symbol
) = flags
;
832 ia64_encode_section_info (tree decl
, rtx rtl
, int first
)
834 default_encode_section_info (decl
, rtl
, first
);
836 /* Careful not to prod global register variables. */
837 if (TREE_CODE (decl
) == VAR_DECL
838 && GET_CODE (DECL_RTL (decl
)) == MEM
839 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
840 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
841 ia64_encode_addr_area (decl
, XEXP (rtl
, 0));
844 /* Return 1 if the operands of a move are ok. */
847 ia64_move_ok (rtx dst
, rtx src
)
849 /* If we're under init_recog_no_volatile, we'll not be able to use
850 memory_operand. So check the code directly and don't worry about
851 the validity of the underlying address, which should have been
852 checked elsewhere anyway. */
853 if (GET_CODE (dst
) != MEM
)
855 if (GET_CODE (src
) == MEM
)
857 if (register_operand (src
, VOIDmode
))
860 /* Otherwise, this must be a constant, and that either 0 or 0.0 or 1.0. */
861 if (INTEGRAL_MODE_P (GET_MODE (dst
)))
862 return src
== const0_rtx
;
864 return satisfies_constraint_G (src
);
867 /* Return 1 if the operands are ok for a floating point load pair. */
870 ia64_load_pair_ok (rtx dst
, rtx src
)
872 /* ??? There is a thinko in the implementation of the "x" constraint and the
873 FP_REGS class. The constraint will also reject (reg f30:TI) so we must
874 also return false for it. */
875 if (GET_CODE (dst
) != REG
876 || !(FP_REGNO_P (REGNO (dst
)) && FP_REGNO_P (REGNO (dst
) + 1)))
878 if (GET_CODE (src
) != MEM
|| MEM_VOLATILE_P (src
))
880 switch (GET_CODE (XEXP (src
, 0)))
889 rtx adjust
= XEXP (XEXP (XEXP (src
, 0), 1), 1);
891 if (GET_CODE (adjust
) != CONST_INT
892 || INTVAL (adjust
) != GET_MODE_SIZE (GET_MODE (src
)))
903 addp4_optimize_ok (rtx op1
, rtx op2
)
905 return (basereg_operand (op1
, GET_MODE(op1
)) !=
906 basereg_operand (op2
, GET_MODE(op2
)));
909 /* Check if OP is a mask suitable for use with SHIFT in a dep.z instruction.
910 Return the length of the field, or <= 0 on failure. */
913 ia64_depz_field_mask (rtx rop
, rtx rshift
)
915 unsigned HOST_WIDE_INT op
= INTVAL (rop
);
916 unsigned HOST_WIDE_INT shift
= INTVAL (rshift
);
918 /* Get rid of the zero bits we're shifting in. */
921 /* We must now have a solid block of 1's at bit 0. */
922 return exact_log2 (op
+ 1);
925 /* Return the TLS model to use for ADDR. */
927 static enum tls_model
928 tls_symbolic_operand_type (rtx addr
)
930 enum tls_model tls_kind
= TLS_MODEL_NONE
;
932 if (GET_CODE (addr
) == CONST
)
934 if (GET_CODE (XEXP (addr
, 0)) == PLUS
935 && GET_CODE (XEXP (XEXP (addr
, 0), 0)) == SYMBOL_REF
)
936 tls_kind
= SYMBOL_REF_TLS_MODEL (XEXP (XEXP (addr
, 0), 0));
938 else if (GET_CODE (addr
) == SYMBOL_REF
)
939 tls_kind
= SYMBOL_REF_TLS_MODEL (addr
);
944 /* Returns true if REG (assumed to be a `reg' RTX) is valid for use
945 as a base register. */
948 ia64_reg_ok_for_base_p (const_rtx reg
, bool strict
)
951 && REGNO_OK_FOR_BASE_P (REGNO (reg
)))
954 && (GENERAL_REGNO_P (REGNO (reg
))
955 || !HARD_REGISTER_P (reg
)))
962 ia64_legitimate_address_reg (const_rtx reg
, bool strict
)
964 if ((REG_P (reg
) && ia64_reg_ok_for_base_p (reg
, strict
))
965 || (GET_CODE (reg
) == SUBREG
&& REG_P (XEXP (reg
, 0))
966 && ia64_reg_ok_for_base_p (XEXP (reg
, 0), strict
)))
973 ia64_legitimate_address_disp (const_rtx reg
, const_rtx disp
, bool strict
)
975 if (GET_CODE (disp
) == PLUS
976 && rtx_equal_p (reg
, XEXP (disp
, 0))
977 && (ia64_legitimate_address_reg (XEXP (disp
, 1), strict
)
978 || (CONST_INT_P (XEXP (disp
, 1))
979 && IN_RANGE (INTVAL (XEXP (disp
, 1)), -256, 255))))
985 /* Implement TARGET_LEGITIMATE_ADDRESS_P. */
988 ia64_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
991 if (ia64_legitimate_address_reg (x
, strict
))
993 else if ((GET_CODE (x
) == POST_INC
|| GET_CODE (x
) == POST_DEC
)
994 && ia64_legitimate_address_reg (XEXP (x
, 0), strict
)
995 && XEXP (x
, 0) != arg_pointer_rtx
)
997 else if (GET_CODE (x
) == POST_MODIFY
998 && ia64_legitimate_address_reg (XEXP (x
, 0), strict
)
999 && XEXP (x
, 0) != arg_pointer_rtx
1000 && ia64_legitimate_address_disp (XEXP (x
, 0), XEXP (x
, 1), strict
))
1006 /* Return true if X is a constant that is valid for some immediate
1007 field in an instruction. */
1010 ia64_legitimate_constant_p (enum machine_mode mode
, rtx x
)
1012 switch (GET_CODE (x
))
1019 if (GET_MODE (x
) == VOIDmode
|| mode
== SFmode
|| mode
== DFmode
)
1021 return satisfies_constraint_G (x
);
1025 /* ??? Short term workaround for PR 28490. We must make the code here
1026 match the code in ia64_expand_move and move_operand, even though they
1027 are both technically wrong. */
1028 if (tls_symbolic_operand_type (x
) == 0)
1030 HOST_WIDE_INT addend
= 0;
1033 if (GET_CODE (op
) == CONST
1034 && GET_CODE (XEXP (op
, 0)) == PLUS
1035 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
)
1037 addend
= INTVAL (XEXP (XEXP (op
, 0), 1));
1038 op
= XEXP (XEXP (op
, 0), 0);
1041 if (any_offset_symbol_operand (op
, mode
)
1042 || function_operand (op
, mode
))
1044 if (aligned_offset_symbol_operand (op
, mode
))
1045 return (addend
& 0x3fff) == 0;
1051 if (mode
== V2SFmode
)
1052 return satisfies_constraint_Y (x
);
1054 return (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
1055 && GET_MODE_SIZE (mode
) <= 8);
1062 /* Don't allow TLS addresses to get spilled to memory. */
1065 ia64_cannot_force_const_mem (enum machine_mode mode
, rtx x
)
1069 return tls_symbolic_operand_type (x
) != 0;
1072 /* Expand a symbolic constant load. */
1075 ia64_expand_load_address (rtx dest
, rtx src
)
1077 gcc_assert (GET_CODE (dest
) == REG
);
1079 /* ILP32 mode still loads 64-bits of data from the GOT. This avoids
1080 having to pointer-extend the value afterward. Other forms of address
1081 computation below are also more natural to compute as 64-bit quantities.
1082 If we've been given an SImode destination register, change it. */
1083 if (GET_MODE (dest
) != Pmode
)
1084 dest
= gen_rtx_REG_offset (dest
, Pmode
, REGNO (dest
),
1085 byte_lowpart_offset (Pmode
, GET_MODE (dest
)));
1089 if (small_addr_symbolic_operand (src
, VOIDmode
))
1092 if (TARGET_AUTO_PIC
)
1093 emit_insn (gen_load_gprel64 (dest
, src
));
1094 else if (GET_CODE (src
) == SYMBOL_REF
&& SYMBOL_REF_FUNCTION_P (src
))
1095 emit_insn (gen_load_fptr (dest
, src
));
1096 else if (sdata_symbolic_operand (src
, VOIDmode
))
1097 emit_insn (gen_load_gprel (dest
, src
));
1100 HOST_WIDE_INT addend
= 0;
1103 /* We did split constant offsets in ia64_expand_move, and we did try
1104 to keep them split in move_operand, but we also allowed reload to
1105 rematerialize arbitrary constants rather than spill the value to
1106 the stack and reload it. So we have to be prepared here to split
1107 them apart again. */
1108 if (GET_CODE (src
) == CONST
)
1110 HOST_WIDE_INT hi
, lo
;
1112 hi
= INTVAL (XEXP (XEXP (src
, 0), 1));
1113 lo
= ((hi
& 0x3fff) ^ 0x2000) - 0x2000;
1119 src
= plus_constant (Pmode
, XEXP (XEXP (src
, 0), 0), hi
);
1123 tmp
= gen_rtx_HIGH (Pmode
, src
);
1124 tmp
= gen_rtx_PLUS (Pmode
, tmp
, pic_offset_table_rtx
);
1125 emit_insn (gen_rtx_SET (VOIDmode
, dest
, tmp
));
1127 tmp
= gen_rtx_LO_SUM (Pmode
, gen_const_mem (Pmode
, dest
), src
);
1128 emit_insn (gen_rtx_SET (VOIDmode
, dest
, tmp
));
1132 tmp
= gen_rtx_PLUS (Pmode
, dest
, GEN_INT (addend
));
1133 emit_insn (gen_rtx_SET (VOIDmode
, dest
, tmp
));
1140 static GTY(()) rtx gen_tls_tga
;
1142 gen_tls_get_addr (void)
1145 gen_tls_tga
= init_one_libfunc ("__tls_get_addr");
1149 static GTY(()) rtx thread_pointer_rtx
;
1151 gen_thread_pointer (void)
1153 if (!thread_pointer_rtx
)
1154 thread_pointer_rtx
= gen_rtx_REG (Pmode
, 13);
1155 return thread_pointer_rtx
;
1159 ia64_expand_tls_address (enum tls_model tls_kind
, rtx op0
, rtx op1
,
1160 rtx orig_op1
, HOST_WIDE_INT addend
)
1162 rtx tga_op1
, tga_op2
, tga_ret
, tga_eqv
, tmp
;
1165 HOST_WIDE_INT addend_lo
, addend_hi
;
1169 case TLS_MODEL_GLOBAL_DYNAMIC
:
1172 tga_op1
= gen_reg_rtx (Pmode
);
1173 emit_insn (gen_load_dtpmod (tga_op1
, op1
));
1175 tga_op2
= gen_reg_rtx (Pmode
);
1176 emit_insn (gen_load_dtprel (tga_op2
, op1
));
1178 tga_ret
= emit_library_call_value (gen_tls_get_addr (), NULL_RTX
,
1179 LCT_CONST
, Pmode
, 2, tga_op1
,
1180 Pmode
, tga_op2
, Pmode
);
1182 insns
= get_insns ();
1185 if (GET_MODE (op0
) != Pmode
)
1187 emit_libcall_block (insns
, op0
, tga_ret
, op1
);
1190 case TLS_MODEL_LOCAL_DYNAMIC
:
1191 /* ??? This isn't the completely proper way to do local-dynamic
1192 If the call to __tls_get_addr is used only by a single symbol,
1193 then we should (somehow) move the dtprel to the second arg
1194 to avoid the extra add. */
1197 tga_op1
= gen_reg_rtx (Pmode
);
1198 emit_insn (gen_load_dtpmod (tga_op1
, op1
));
1200 tga_op2
= const0_rtx
;
1202 tga_ret
= emit_library_call_value (gen_tls_get_addr (), NULL_RTX
,
1203 LCT_CONST
, Pmode
, 2, tga_op1
,
1204 Pmode
, tga_op2
, Pmode
);
1206 insns
= get_insns ();
1209 tga_eqv
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
),
1211 tmp
= gen_reg_rtx (Pmode
);
1212 emit_libcall_block (insns
, tmp
, tga_ret
, tga_eqv
);
1214 if (!register_operand (op0
, Pmode
))
1215 op0
= gen_reg_rtx (Pmode
);
1218 emit_insn (gen_load_dtprel (op0
, op1
));
1219 emit_insn (gen_adddi3 (op0
, tmp
, op0
));
1222 emit_insn (gen_add_dtprel (op0
, op1
, tmp
));
1225 case TLS_MODEL_INITIAL_EXEC
:
1226 addend_lo
= ((addend
& 0x3fff) ^ 0x2000) - 0x2000;
1227 addend_hi
= addend
- addend_lo
;
1229 op1
= plus_constant (Pmode
, op1
, addend_hi
);
1232 tmp
= gen_reg_rtx (Pmode
);
1233 emit_insn (gen_load_tprel (tmp
, op1
));
1235 if (!register_operand (op0
, Pmode
))
1236 op0
= gen_reg_rtx (Pmode
);
1237 emit_insn (gen_adddi3 (op0
, tmp
, gen_thread_pointer ()));
1240 case TLS_MODEL_LOCAL_EXEC
:
1241 if (!register_operand (op0
, Pmode
))
1242 op0
= gen_reg_rtx (Pmode
);
1248 emit_insn (gen_load_tprel (op0
, op1
));
1249 emit_insn (gen_adddi3 (op0
, op0
, gen_thread_pointer ()));
1252 emit_insn (gen_add_tprel (op0
, op1
, gen_thread_pointer ()));
1260 op0
= expand_simple_binop (Pmode
, PLUS
, op0
, GEN_INT (addend
),
1261 orig_op0
, 1, OPTAB_DIRECT
);
1262 if (orig_op0
== op0
)
1264 if (GET_MODE (orig_op0
) == Pmode
)
1266 return gen_lowpart (GET_MODE (orig_op0
), op0
);
1270 ia64_expand_move (rtx op0
, rtx op1
)
1272 enum machine_mode mode
= GET_MODE (op0
);
1274 if (!reload_in_progress
&& !reload_completed
&& !ia64_move_ok (op0
, op1
))
1275 op1
= force_reg (mode
, op1
);
1277 if ((mode
== Pmode
|| mode
== ptr_mode
) && symbolic_operand (op1
, VOIDmode
))
1279 HOST_WIDE_INT addend
= 0;
1280 enum tls_model tls_kind
;
1283 if (GET_CODE (op1
) == CONST
1284 && GET_CODE (XEXP (op1
, 0)) == PLUS
1285 && GET_CODE (XEXP (XEXP (op1
, 0), 1)) == CONST_INT
)
1287 addend
= INTVAL (XEXP (XEXP (op1
, 0), 1));
1288 sym
= XEXP (XEXP (op1
, 0), 0);
1291 tls_kind
= tls_symbolic_operand_type (sym
);
1293 return ia64_expand_tls_address (tls_kind
, op0
, sym
, op1
, addend
);
1295 if (any_offset_symbol_operand (sym
, mode
))
1297 else if (aligned_offset_symbol_operand (sym
, mode
))
1299 HOST_WIDE_INT addend_lo
, addend_hi
;
1301 addend_lo
= ((addend
& 0x3fff) ^ 0x2000) - 0x2000;
1302 addend_hi
= addend
- addend_lo
;
1306 op1
= plus_constant (mode
, sym
, addend_hi
);
1315 if (reload_completed
)
1317 /* We really should have taken care of this offset earlier. */
1318 gcc_assert (addend
== 0);
1319 if (ia64_expand_load_address (op0
, op1
))
1325 rtx subtarget
= !can_create_pseudo_p () ? op0
: gen_reg_rtx (mode
);
1327 emit_insn (gen_rtx_SET (VOIDmode
, subtarget
, op1
));
1329 op1
= expand_simple_binop (mode
, PLUS
, subtarget
,
1330 GEN_INT (addend
), op0
, 1, OPTAB_DIRECT
);
1339 /* Split a move from OP1 to OP0 conditional on COND. */
1342 ia64_emit_cond_move (rtx op0
, rtx op1
, rtx cond
)
1344 rtx_insn
*insn
, *first
= get_last_insn ();
1346 emit_move_insn (op0
, op1
);
1348 for (insn
= get_last_insn (); insn
!= first
; insn
= PREV_INSN (insn
))
1350 PATTERN (insn
) = gen_rtx_COND_EXEC (VOIDmode
, copy_rtx (cond
),
1354 /* Split a post-reload TImode or TFmode reference into two DImode
1355 components. This is made extra difficult by the fact that we do
1356 not get any scratch registers to work with, because reload cannot
1357 be prevented from giving us a scratch that overlaps the register
1358 pair involved. So instead, when addressing memory, we tweak the
1359 pointer register up and back down with POST_INCs. Or up and not
1360 back down when we can get away with it.
1362 REVERSED is true when the loads must be done in reversed order
1363 (high word first) for correctness. DEAD is true when the pointer
1364 dies with the second insn we generate and therefore the second
1365 address must not carry a postmodify.
1367 May return an insn which is to be emitted after the moves. */
1370 ia64_split_tmode (rtx out
[2], rtx in
, bool reversed
, bool dead
)
1374 switch (GET_CODE (in
))
1377 out
[reversed
] = gen_rtx_REG (DImode
, REGNO (in
));
1378 out
[!reversed
] = gen_rtx_REG (DImode
, REGNO (in
) + 1);
1383 /* Cannot occur reversed. */
1384 gcc_assert (!reversed
);
1386 if (GET_MODE (in
) != TFmode
)
1387 split_double (in
, &out
[0], &out
[1]);
1389 /* split_double does not understand how to split a TFmode
1390 quantity into a pair of DImode constants. */
1393 unsigned HOST_WIDE_INT p
[2];
1394 long l
[4]; /* TFmode is 128 bits */
1396 REAL_VALUE_FROM_CONST_DOUBLE (r
, in
);
1397 real_to_target (l
, &r
, TFmode
);
1399 if (FLOAT_WORDS_BIG_ENDIAN
)
1401 p
[0] = (((unsigned HOST_WIDE_INT
) l
[0]) << 32) + l
[1];
1402 p
[1] = (((unsigned HOST_WIDE_INT
) l
[2]) << 32) + l
[3];
1406 p
[0] = (((unsigned HOST_WIDE_INT
) l
[1]) << 32) + l
[0];
1407 p
[1] = (((unsigned HOST_WIDE_INT
) l
[3]) << 32) + l
[2];
1409 out
[0] = GEN_INT (p
[0]);
1410 out
[1] = GEN_INT (p
[1]);
1416 rtx base
= XEXP (in
, 0);
1419 switch (GET_CODE (base
))
1424 out
[0] = adjust_automodify_address
1425 (in
, DImode
, gen_rtx_POST_INC (Pmode
, base
), 0);
1426 out
[1] = adjust_automodify_address
1427 (in
, DImode
, dead
? 0 : gen_rtx_POST_DEC (Pmode
, base
), 8);
1431 /* Reversal requires a pre-increment, which can only
1432 be done as a separate insn. */
1433 emit_insn (gen_adddi3 (base
, base
, GEN_INT (8)));
1434 out
[0] = adjust_automodify_address
1435 (in
, DImode
, gen_rtx_POST_DEC (Pmode
, base
), 8);
1436 out
[1] = adjust_address (in
, DImode
, 0);
1441 gcc_assert (!reversed
&& !dead
);
1443 /* Just do the increment in two steps. */
1444 out
[0] = adjust_automodify_address (in
, DImode
, 0, 0);
1445 out
[1] = adjust_automodify_address (in
, DImode
, 0, 8);
1449 gcc_assert (!reversed
&& !dead
);
1451 /* Add 8, subtract 24. */
1452 base
= XEXP (base
, 0);
1453 out
[0] = adjust_automodify_address
1454 (in
, DImode
, gen_rtx_POST_INC (Pmode
, base
), 0);
1455 out
[1] = adjust_automodify_address
1457 gen_rtx_POST_MODIFY (Pmode
, base
,
1458 plus_constant (Pmode
, base
, -24)),
1463 gcc_assert (!reversed
&& !dead
);
1465 /* Extract and adjust the modification. This case is
1466 trickier than the others, because we might have an
1467 index register, or we might have a combined offset that
1468 doesn't fit a signed 9-bit displacement field. We can
1469 assume the incoming expression is already legitimate. */
1470 offset
= XEXP (base
, 1);
1471 base
= XEXP (base
, 0);
1473 out
[0] = adjust_automodify_address
1474 (in
, DImode
, gen_rtx_POST_INC (Pmode
, base
), 0);
1476 if (GET_CODE (XEXP (offset
, 1)) == REG
)
1478 /* Can't adjust the postmodify to match. Emit the
1479 original, then a separate addition insn. */
1480 out
[1] = adjust_automodify_address (in
, DImode
, 0, 8);
1481 fixup
= gen_adddi3 (base
, base
, GEN_INT (-8));
1485 gcc_assert (GET_CODE (XEXP (offset
, 1)) == CONST_INT
);
1486 if (INTVAL (XEXP (offset
, 1)) < -256 + 8)
1488 /* Again the postmodify cannot be made to match,
1489 but in this case it's more efficient to get rid
1490 of the postmodify entirely and fix up with an
1492 out
[1] = adjust_automodify_address (in
, DImode
, base
, 8);
1494 (base
, base
, GEN_INT (INTVAL (XEXP (offset
, 1)) - 8));
1498 /* Combined offset still fits in the displacement field.
1499 (We cannot overflow it at the high end.) */
1500 out
[1] = adjust_automodify_address
1501 (in
, DImode
, gen_rtx_POST_MODIFY
1502 (Pmode
, base
, gen_rtx_PLUS
1504 GEN_INT (INTVAL (XEXP (offset
, 1)) - 8))),
1523 /* Split a TImode or TFmode move instruction after reload.
1524 This is used by *movtf_internal and *movti_internal. */
1526 ia64_split_tmode_move (rtx operands
[])
1528 rtx in
[2], out
[2], insn
;
1531 bool reversed
= false;
1533 /* It is possible for reload to decide to overwrite a pointer with
1534 the value it points to. In that case we have to do the loads in
1535 the appropriate order so that the pointer is not destroyed too
1536 early. Also we must not generate a postmodify for that second
1537 load, or rws_access_regno will die. And we must not generate a
1538 postmodify for the second load if the destination register
1539 overlaps with the base register. */
1540 if (GET_CODE (operands
[1]) == MEM
1541 && reg_overlap_mentioned_p (operands
[0], operands
[1]))
1543 rtx base
= XEXP (operands
[1], 0);
1544 while (GET_CODE (base
) != REG
)
1545 base
= XEXP (base
, 0);
1547 if (REGNO (base
) == REGNO (operands
[0]))
1550 if (refers_to_regno_p (REGNO (operands
[0]),
1551 REGNO (operands
[0])+2,
1555 /* Another reason to do the moves in reversed order is if the first
1556 element of the target register pair is also the second element of
1557 the source register pair. */
1558 if (GET_CODE (operands
[0]) == REG
&& GET_CODE (operands
[1]) == REG
1559 && REGNO (operands
[0]) == REGNO (operands
[1]) + 1)
1562 fixup
[0] = ia64_split_tmode (in
, operands
[1], reversed
, dead
);
1563 fixup
[1] = ia64_split_tmode (out
, operands
[0], reversed
, dead
);
1565 #define MAYBE_ADD_REG_INC_NOTE(INSN, EXP) \
1566 if (GET_CODE (EXP) == MEM \
1567 && (GET_CODE (XEXP (EXP, 0)) == POST_MODIFY \
1568 || GET_CODE (XEXP (EXP, 0)) == POST_INC \
1569 || GET_CODE (XEXP (EXP, 0)) == POST_DEC)) \
1570 add_reg_note (insn, REG_INC, XEXP (XEXP (EXP, 0), 0))
1572 insn
= emit_insn (gen_rtx_SET (VOIDmode
, out
[0], in
[0]));
1573 MAYBE_ADD_REG_INC_NOTE (insn
, in
[0]);
1574 MAYBE_ADD_REG_INC_NOTE (insn
, out
[0]);
1576 insn
= emit_insn (gen_rtx_SET (VOIDmode
, out
[1], in
[1]));
1577 MAYBE_ADD_REG_INC_NOTE (insn
, in
[1]);
1578 MAYBE_ADD_REG_INC_NOTE (insn
, out
[1]);
1581 emit_insn (fixup
[0]);
1583 emit_insn (fixup
[1]);
1585 #undef MAYBE_ADD_REG_INC_NOTE
1588 /* ??? Fixing GR->FR XFmode moves during reload is hard. You need to go
1589 through memory plus an extra GR scratch register. Except that you can
1590 either get the first from SECONDARY_MEMORY_NEEDED or the second from
1591 SECONDARY_RELOAD_CLASS, but not both.
1593 We got into problems in the first place by allowing a construct like
1594 (subreg:XF (reg:TI)), which we got from a union containing a long double.
1595 This solution attempts to prevent this situation from occurring. When
1596 we see something like the above, we spill the inner register to memory. */
1599 spill_xfmode_rfmode_operand (rtx in
, int force
, enum machine_mode mode
)
1601 if (GET_CODE (in
) == SUBREG
1602 && GET_MODE (SUBREG_REG (in
)) == TImode
1603 && GET_CODE (SUBREG_REG (in
)) == REG
)
1605 rtx memt
= assign_stack_temp (TImode
, 16);
1606 emit_move_insn (memt
, SUBREG_REG (in
));
1607 return adjust_address (memt
, mode
, 0);
1609 else if (force
&& GET_CODE (in
) == REG
)
1611 rtx memx
= assign_stack_temp (mode
, 16);
1612 emit_move_insn (memx
, in
);
1619 /* Expand the movxf or movrf pattern (MODE says which) with the given
1620 OPERANDS, returning true if the pattern should then invoke
1624 ia64_expand_movxf_movrf (enum machine_mode mode
, rtx operands
[])
1626 rtx op0
= operands
[0];
1628 if (GET_CODE (op0
) == SUBREG
)
1629 op0
= SUBREG_REG (op0
);
1631 /* We must support XFmode loads into general registers for stdarg/vararg,
1632 unprototyped calls, and a rare case where a long double is passed as
1633 an argument after a float HFA fills the FP registers. We split them into
1634 DImode loads for convenience. We also need to support XFmode stores
1635 for the last case. This case does not happen for stdarg/vararg routines,
1636 because we do a block store to memory of unnamed arguments. */
1638 if (GET_CODE (op0
) == REG
&& GR_REGNO_P (REGNO (op0
)))
1642 /* We're hoping to transform everything that deals with XFmode
1643 quantities and GR registers early in the compiler. */
1644 gcc_assert (can_create_pseudo_p ());
1646 /* Struct to register can just use TImode instead. */
1647 if ((GET_CODE (operands
[1]) == SUBREG
1648 && GET_MODE (SUBREG_REG (operands
[1])) == TImode
)
1649 || (GET_CODE (operands
[1]) == REG
1650 && GR_REGNO_P (REGNO (operands
[1]))))
1652 rtx op1
= operands
[1];
1654 if (GET_CODE (op1
) == SUBREG
)
1655 op1
= SUBREG_REG (op1
);
1657 op1
= gen_rtx_REG (TImode
, REGNO (op1
));
1659 emit_move_insn (gen_rtx_REG (TImode
, REGNO (op0
)), op1
);
1663 if (GET_CODE (operands
[1]) == CONST_DOUBLE
)
1665 /* Don't word-swap when reading in the constant. */
1666 emit_move_insn (gen_rtx_REG (DImode
, REGNO (op0
)),
1667 operand_subword (operands
[1], WORDS_BIG_ENDIAN
,
1669 emit_move_insn (gen_rtx_REG (DImode
, REGNO (op0
) + 1),
1670 operand_subword (operands
[1], !WORDS_BIG_ENDIAN
,
1675 /* If the quantity is in a register not known to be GR, spill it. */
1676 if (register_operand (operands
[1], mode
))
1677 operands
[1] = spill_xfmode_rfmode_operand (operands
[1], 1, mode
);
1679 gcc_assert (GET_CODE (operands
[1]) == MEM
);
1681 /* Don't word-swap when reading in the value. */
1682 out
[0] = gen_rtx_REG (DImode
, REGNO (op0
));
1683 out
[1] = gen_rtx_REG (DImode
, REGNO (op0
) + 1);
1685 emit_move_insn (out
[0], adjust_address (operands
[1], DImode
, 0));
1686 emit_move_insn (out
[1], adjust_address (operands
[1], DImode
, 8));
1690 if (GET_CODE (operands
[1]) == REG
&& GR_REGNO_P (REGNO (operands
[1])))
1692 /* We're hoping to transform everything that deals with XFmode
1693 quantities and GR registers early in the compiler. */
1694 gcc_assert (can_create_pseudo_p ());
1696 /* Op0 can't be a GR_REG here, as that case is handled above.
1697 If op0 is a register, then we spill op1, so that we now have a
1698 MEM operand. This requires creating an XFmode subreg of a TImode reg
1699 to force the spill. */
1700 if (register_operand (operands
[0], mode
))
1702 rtx op1
= gen_rtx_REG (TImode
, REGNO (operands
[1]));
1703 op1
= gen_rtx_SUBREG (mode
, op1
, 0);
1704 operands
[1] = spill_xfmode_rfmode_operand (op1
, 0, mode
);
1711 gcc_assert (GET_CODE (operands
[0]) == MEM
);
1713 /* Don't word-swap when writing out the value. */
1714 in
[0] = gen_rtx_REG (DImode
, REGNO (operands
[1]));
1715 in
[1] = gen_rtx_REG (DImode
, REGNO (operands
[1]) + 1);
1717 emit_move_insn (adjust_address (operands
[0], DImode
, 0), in
[0]);
1718 emit_move_insn (adjust_address (operands
[0], DImode
, 8), in
[1]);
1723 if (!reload_in_progress
&& !reload_completed
)
1725 operands
[1] = spill_xfmode_rfmode_operand (operands
[1], 0, mode
);
1727 if (GET_MODE (op0
) == TImode
&& GET_CODE (op0
) == REG
)
1729 rtx memt
, memx
, in
= operands
[1];
1730 if (CONSTANT_P (in
))
1731 in
= validize_mem (force_const_mem (mode
, in
));
1732 if (GET_CODE (in
) == MEM
)
1733 memt
= adjust_address (in
, TImode
, 0);
1736 memt
= assign_stack_temp (TImode
, 16);
1737 memx
= adjust_address (memt
, mode
, 0);
1738 emit_move_insn (memx
, in
);
1740 emit_move_insn (op0
, memt
);
1744 if (!ia64_move_ok (operands
[0], operands
[1]))
1745 operands
[1] = force_reg (mode
, operands
[1]);
1751 /* Emit comparison instruction if necessary, replacing *EXPR, *OP0, *OP1
1752 with the expression that holds the compare result (in VOIDmode). */
1754 static GTY(()) rtx cmptf_libfunc
;
1757 ia64_expand_compare (rtx
*expr
, rtx
*op0
, rtx
*op1
)
1759 enum rtx_code code
= GET_CODE (*expr
);
1762 /* If we have a BImode input, then we already have a compare result, and
1763 do not need to emit another comparison. */
1764 if (GET_MODE (*op0
) == BImode
)
1766 gcc_assert ((code
== NE
|| code
== EQ
) && *op1
== const0_rtx
);
1769 /* HPUX TFmode compare requires a library call to _U_Qfcmp, which takes a
1770 magic number as its third argument, that indicates what to do.
1771 The return value is an integer to be compared against zero. */
1772 else if (TARGET_HPUX
&& GET_MODE (*op0
) == TFmode
)
1775 QCMP_INV
= 1, /* Raise FP_INVALID on NaNs as a side effect. */
1782 enum rtx_code ncode
;
1785 gcc_assert (cmptf_libfunc
&& GET_MODE (*op1
) == TFmode
);
1788 /* 1 = equal, 0 = not equal. Equality operators do
1789 not raise FP_INVALID when given a NaN operand. */
1790 case EQ
: magic
= QCMP_EQ
; ncode
= NE
; break;
1791 case NE
: magic
= QCMP_EQ
; ncode
= EQ
; break;
1792 /* isunordered() from C99. */
1793 case UNORDERED
: magic
= QCMP_UNORD
; ncode
= NE
; break;
1794 case ORDERED
: magic
= QCMP_UNORD
; ncode
= EQ
; break;
1795 /* Relational operators raise FP_INVALID when given
1797 case LT
: magic
= QCMP_LT
|QCMP_INV
; ncode
= NE
; break;
1798 case LE
: magic
= QCMP_LT
|QCMP_EQ
|QCMP_INV
; ncode
= NE
; break;
1799 case GT
: magic
= QCMP_GT
|QCMP_INV
; ncode
= NE
; break;
1800 case GE
: magic
= QCMP_GT
|QCMP_EQ
|QCMP_INV
; ncode
= NE
; break;
1801 /* Unordered relational operators do not raise FP_INVALID
1802 when given a NaN operand. */
1803 case UNLT
: magic
= QCMP_LT
|QCMP_UNORD
; ncode
= NE
; break;
1804 case UNLE
: magic
= QCMP_LT
|QCMP_EQ
|QCMP_UNORD
; ncode
= NE
; break;
1805 case UNGT
: magic
= QCMP_GT
|QCMP_UNORD
; ncode
= NE
; break;
1806 case UNGE
: magic
= QCMP_GT
|QCMP_EQ
|QCMP_UNORD
; ncode
= NE
; break;
1807 /* Not supported. */
1810 default: gcc_unreachable ();
1815 ret
= emit_library_call_value (cmptf_libfunc
, 0, LCT_CONST
, DImode
, 3,
1816 *op0
, TFmode
, *op1
, TFmode
,
1817 GEN_INT (magic
), DImode
);
1818 cmp
= gen_reg_rtx (BImode
);
1819 emit_insn (gen_rtx_SET (VOIDmode
, cmp
,
1820 gen_rtx_fmt_ee (ncode
, BImode
,
1823 insns
= get_insns ();
1826 emit_libcall_block (insns
, cmp
, cmp
,
1827 gen_rtx_fmt_ee (code
, BImode
, *op0
, *op1
));
1832 cmp
= gen_reg_rtx (BImode
);
1833 emit_insn (gen_rtx_SET (VOIDmode
, cmp
,
1834 gen_rtx_fmt_ee (code
, BImode
, *op0
, *op1
)));
1838 *expr
= gen_rtx_fmt_ee (code
, VOIDmode
, cmp
, const0_rtx
);
1843 /* Generate an integral vector comparison. Return true if the condition has
1844 been reversed, and so the sense of the comparison should be inverted. */
1847 ia64_expand_vecint_compare (enum rtx_code code
, enum machine_mode mode
,
1848 rtx dest
, rtx op0
, rtx op1
)
1850 bool negate
= false;
1853 /* Canonicalize the comparison to EQ, GT, GTU. */
1864 code
= reverse_condition (code
);
1870 code
= reverse_condition (code
);
1876 code
= swap_condition (code
);
1877 x
= op0
, op0
= op1
, op1
= x
;
1884 /* Unsigned parallel compare is not supported by the hardware. Play some
1885 tricks to turn this into a signed comparison against 0. */
1894 /* Subtract (-(INT MAX) - 1) from both operands to make
1896 mask
= GEN_INT (0x80000000);
1897 mask
= gen_rtx_CONST_VECTOR (V2SImode
, gen_rtvec (2, mask
, mask
));
1898 mask
= force_reg (mode
, mask
);
1899 t1
= gen_reg_rtx (mode
);
1900 emit_insn (gen_subv2si3 (t1
, op0
, mask
));
1901 t2
= gen_reg_rtx (mode
);
1902 emit_insn (gen_subv2si3 (t2
, op1
, mask
));
1911 /* Perform a parallel unsigned saturating subtraction. */
1912 x
= gen_reg_rtx (mode
);
1913 emit_insn (gen_rtx_SET (VOIDmode
, x
,
1914 gen_rtx_US_MINUS (mode
, op0
, op1
)));
1918 op1
= CONST0_RTX (mode
);
1927 x
= gen_rtx_fmt_ee (code
, mode
, op0
, op1
);
1928 emit_insn (gen_rtx_SET (VOIDmode
, dest
, x
));
1933 /* Emit an integral vector conditional move. */
1936 ia64_expand_vecint_cmov (rtx operands
[])
1938 enum machine_mode mode
= GET_MODE (operands
[0]);
1939 enum rtx_code code
= GET_CODE (operands
[3]);
1943 cmp
= gen_reg_rtx (mode
);
1944 negate
= ia64_expand_vecint_compare (code
, mode
, cmp
,
1945 operands
[4], operands
[5]);
1947 ot
= operands
[1+negate
];
1948 of
= operands
[2-negate
];
1950 if (ot
== CONST0_RTX (mode
))
1952 if (of
== CONST0_RTX (mode
))
1954 emit_move_insn (operands
[0], ot
);
1958 x
= gen_rtx_NOT (mode
, cmp
);
1959 x
= gen_rtx_AND (mode
, x
, of
);
1960 emit_insn (gen_rtx_SET (VOIDmode
, operands
[0], x
));
1962 else if (of
== CONST0_RTX (mode
))
1964 x
= gen_rtx_AND (mode
, cmp
, ot
);
1965 emit_insn (gen_rtx_SET (VOIDmode
, operands
[0], x
));
1971 t
= gen_reg_rtx (mode
);
1972 x
= gen_rtx_AND (mode
, cmp
, operands
[1+negate
]);
1973 emit_insn (gen_rtx_SET (VOIDmode
, t
, x
));
1975 f
= gen_reg_rtx (mode
);
1976 x
= gen_rtx_NOT (mode
, cmp
);
1977 x
= gen_rtx_AND (mode
, x
, operands
[2-negate
]);
1978 emit_insn (gen_rtx_SET (VOIDmode
, f
, x
));
1980 x
= gen_rtx_IOR (mode
, t
, f
);
1981 emit_insn (gen_rtx_SET (VOIDmode
, operands
[0], x
));
1985 /* Emit an integral vector min or max operation. Return true if all done. */
1988 ia64_expand_vecint_minmax (enum rtx_code code
, enum machine_mode mode
,
1993 /* These four combinations are supported directly. */
1994 if (mode
== V8QImode
&& (code
== UMIN
|| code
== UMAX
))
1996 if (mode
== V4HImode
&& (code
== SMIN
|| code
== SMAX
))
1999 /* This combination can be implemented with only saturating subtraction. */
2000 if (mode
== V4HImode
&& code
== UMAX
)
2002 rtx x
, tmp
= gen_reg_rtx (mode
);
2004 x
= gen_rtx_US_MINUS (mode
, operands
[1], operands
[2]);
2005 emit_insn (gen_rtx_SET (VOIDmode
, tmp
, x
));
2007 emit_insn (gen_addv4hi3 (operands
[0], tmp
, operands
[2]));
2011 /* Everything else implemented via vector comparisons. */
2012 xops
[0] = operands
[0];
2013 xops
[4] = xops
[1] = operands
[1];
2014 xops
[5] = xops
[2] = operands
[2];
2033 xops
[3] = gen_rtx_fmt_ee (code
, VOIDmode
, operands
[1], operands
[2]);
2035 ia64_expand_vecint_cmov (xops
);
2039 /* The vectors LO and HI each contain N halves of a double-wide vector.
2040 Reassemble either the first N/2 or the second N/2 elements. */
2043 ia64_unpack_assemble (rtx out
, rtx lo
, rtx hi
, bool highp
)
2045 enum machine_mode vmode
= GET_MODE (lo
);
2046 unsigned int i
, high
, nelt
= GET_MODE_NUNITS (vmode
);
2047 struct expand_vec_perm_d d
;
2050 d
.target
= gen_lowpart (vmode
, out
);
2051 d
.op0
= (TARGET_BIG_ENDIAN
? hi
: lo
);
2052 d
.op1
= (TARGET_BIG_ENDIAN
? lo
: hi
);
2055 d
.one_operand_p
= false;
2056 d
.testing_p
= false;
2058 high
= (highp
? nelt
/ 2 : 0);
2059 for (i
= 0; i
< nelt
/ 2; ++i
)
2061 d
.perm
[i
* 2] = i
+ high
;
2062 d
.perm
[i
* 2 + 1] = i
+ high
+ nelt
;
2065 ok
= ia64_expand_vec_perm_const_1 (&d
);
2069 /* Return a vector of the sign-extension of VEC. */
2072 ia64_unpack_sign (rtx vec
, bool unsignedp
)
2074 enum machine_mode mode
= GET_MODE (vec
);
2075 rtx zero
= CONST0_RTX (mode
);
2081 rtx sign
= gen_reg_rtx (mode
);
2084 neg
= ia64_expand_vecint_compare (LT
, mode
, sign
, vec
, zero
);
2091 /* Emit an integral vector unpack operation. */
2094 ia64_expand_unpack (rtx operands
[3], bool unsignedp
, bool highp
)
2096 rtx sign
= ia64_unpack_sign (operands
[1], unsignedp
);
2097 ia64_unpack_assemble (operands
[0], operands
[1], sign
, highp
);
2100 /* Emit an integral vector widening sum operations. */
2103 ia64_expand_widen_sum (rtx operands
[3], bool unsignedp
)
2105 enum machine_mode wmode
;
2108 sign
= ia64_unpack_sign (operands
[1], unsignedp
);
2110 wmode
= GET_MODE (operands
[0]);
2111 l
= gen_reg_rtx (wmode
);
2112 h
= gen_reg_rtx (wmode
);
2114 ia64_unpack_assemble (l
, operands
[1], sign
, false);
2115 ia64_unpack_assemble (h
, operands
[1], sign
, true);
2117 t
= expand_binop (wmode
, add_optab
, l
, operands
[2], NULL
, 0, OPTAB_DIRECT
);
2118 t
= expand_binop (wmode
, add_optab
, h
, t
, operands
[0], 0, OPTAB_DIRECT
);
2119 if (t
!= operands
[0])
2120 emit_move_insn (operands
[0], t
);
2123 /* Emit the appropriate sequence for a call. */
2126 ia64_expand_call (rtx retval
, rtx addr
, rtx nextarg ATTRIBUTE_UNUSED
,
2131 addr
= XEXP (addr
, 0);
2132 addr
= convert_memory_address (DImode
, addr
);
2133 b0
= gen_rtx_REG (DImode
, R_BR (0));
2135 /* ??? Should do this for functions known to bind local too. */
2136 if (TARGET_NO_PIC
|| TARGET_AUTO_PIC
)
2139 insn
= gen_sibcall_nogp (addr
);
2141 insn
= gen_call_nogp (addr
, b0
);
2143 insn
= gen_call_value_nogp (retval
, addr
, b0
);
2144 insn
= emit_call_insn (insn
);
2149 insn
= gen_sibcall_gp (addr
);
2151 insn
= gen_call_gp (addr
, b0
);
2153 insn
= gen_call_value_gp (retval
, addr
, b0
);
2154 insn
= emit_call_insn (insn
);
2156 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), pic_offset_table_rtx
);
2160 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
), b0
);
2162 if (TARGET_ABI_OPEN_VMS
)
2163 use_reg (&CALL_INSN_FUNCTION_USAGE (insn
),
2164 gen_rtx_REG (DImode
, GR_REG (25)));
2168 reg_emitted (enum ia64_frame_regs r
)
2170 if (emitted_frame_related_regs
[r
] == 0)
2171 emitted_frame_related_regs
[r
] = current_frame_info
.r
[r
];
2173 gcc_assert (emitted_frame_related_regs
[r
] == current_frame_info
.r
[r
]);
2177 get_reg (enum ia64_frame_regs r
)
2180 return current_frame_info
.r
[r
];
2184 is_emitted (int regno
)
2188 for (r
= reg_fp
; r
< number_of_ia64_frame_regs
; r
++)
2189 if (emitted_frame_related_regs
[r
] == regno
)
2195 ia64_reload_gp (void)
2199 if (current_frame_info
.r
[reg_save_gp
])
2201 tmp
= gen_rtx_REG (DImode
, get_reg (reg_save_gp
));
2205 HOST_WIDE_INT offset
;
2208 offset
= (current_frame_info
.spill_cfa_off
2209 + current_frame_info
.spill_size
);
2210 if (frame_pointer_needed
)
2212 tmp
= hard_frame_pointer_rtx
;
2217 tmp
= stack_pointer_rtx
;
2218 offset
= current_frame_info
.total_size
- offset
;
2221 offset_r
= GEN_INT (offset
);
2222 if (satisfies_constraint_I (offset_r
))
2223 emit_insn (gen_adddi3 (pic_offset_table_rtx
, tmp
, offset_r
));
2226 emit_move_insn (pic_offset_table_rtx
, offset_r
);
2227 emit_insn (gen_adddi3 (pic_offset_table_rtx
,
2228 pic_offset_table_rtx
, tmp
));
2231 tmp
= gen_rtx_MEM (DImode
, pic_offset_table_rtx
);
2234 emit_move_insn (pic_offset_table_rtx
, tmp
);
2238 ia64_split_call (rtx retval
, rtx addr
, rtx retaddr
, rtx scratch_r
,
2239 rtx scratch_b
, int noreturn_p
, int sibcall_p
)
2242 bool is_desc
= false;
2244 /* If we find we're calling through a register, then we're actually
2245 calling through a descriptor, so load up the values. */
2246 if (REG_P (addr
) && GR_REGNO_P (REGNO (addr
)))
2251 /* ??? We are currently constrained to *not* use peep2, because
2252 we can legitimately change the global lifetime of the GP
2253 (in the form of killing where previously live). This is
2254 because a call through a descriptor doesn't use the previous
2255 value of the GP, while a direct call does, and we do not
2256 commit to either form until the split here.
2258 That said, this means that we lack precise life info for
2259 whether ADDR is dead after this call. This is not terribly
2260 important, since we can fix things up essentially for free
2261 with the POST_DEC below, but it's nice to not use it when we
2262 can immediately tell it's not necessary. */
2263 addr_dead_p
= ((noreturn_p
|| sibcall_p
2264 || TEST_HARD_REG_BIT (regs_invalidated_by_call
,
2266 && !FUNCTION_ARG_REGNO_P (REGNO (addr
)));
2268 /* Load the code address into scratch_b. */
2269 tmp
= gen_rtx_POST_INC (Pmode
, addr
);
2270 tmp
= gen_rtx_MEM (Pmode
, tmp
);
2271 emit_move_insn (scratch_r
, tmp
);
2272 emit_move_insn (scratch_b
, scratch_r
);
2274 /* Load the GP address. If ADDR is not dead here, then we must
2275 revert the change made above via the POST_INCREMENT. */
2277 tmp
= gen_rtx_POST_DEC (Pmode
, addr
);
2280 tmp
= gen_rtx_MEM (Pmode
, tmp
);
2281 emit_move_insn (pic_offset_table_rtx
, tmp
);
2288 insn
= gen_sibcall_nogp (addr
);
2290 insn
= gen_call_value_nogp (retval
, addr
, retaddr
);
2292 insn
= gen_call_nogp (addr
, retaddr
);
2293 emit_call_insn (insn
);
2295 if ((!TARGET_CONST_GP
|| is_desc
) && !noreturn_p
&& !sibcall_p
)
2299 /* Expand an atomic operation. We want to perform MEM <CODE>= VAL atomically.
2301 This differs from the generic code in that we know about the zero-extending
2302 properties of cmpxchg, and the zero-extending requirements of ar.ccv. We
2303 also know that ld.acq+cmpxchg.rel equals a full barrier.
2305 The loop we want to generate looks like
2310 new_reg = cmp_reg op val;
2311 cmp_reg = compare-and-swap(mem, old_reg, new_reg)
2312 if (cmp_reg != old_reg)
2315 Note that we only do the plain load from memory once. Subsequent
2316 iterations use the value loaded by the compare-and-swap pattern. */
2319 ia64_expand_atomic_op (enum rtx_code code
, rtx mem
, rtx val
,
2320 rtx old_dst
, rtx new_dst
, enum memmodel model
)
2322 enum machine_mode mode
= GET_MODE (mem
);
2323 rtx old_reg
, new_reg
, cmp_reg
, ar_ccv
, label
;
2324 enum insn_code icode
;
2326 /* Special case for using fetchadd. */
2327 if ((mode
== SImode
|| mode
== DImode
)
2328 && (code
== PLUS
|| code
== MINUS
)
2329 && fetchadd_operand (val
, mode
))
2332 val
= GEN_INT (-INTVAL (val
));
2335 old_dst
= gen_reg_rtx (mode
);
2339 case MEMMODEL_ACQ_REL
:
2340 case MEMMODEL_SEQ_CST
:
2341 emit_insn (gen_memory_barrier ());
2343 case MEMMODEL_RELAXED
:
2344 case MEMMODEL_ACQUIRE
:
2345 case MEMMODEL_CONSUME
:
2347 icode
= CODE_FOR_fetchadd_acq_si
;
2349 icode
= CODE_FOR_fetchadd_acq_di
;
2351 case MEMMODEL_RELEASE
:
2353 icode
= CODE_FOR_fetchadd_rel_si
;
2355 icode
= CODE_FOR_fetchadd_rel_di
;
2362 emit_insn (GEN_FCN (icode
) (old_dst
, mem
, val
));
2366 new_reg
= expand_simple_binop (mode
, PLUS
, old_dst
, val
, new_dst
,
2368 if (new_reg
!= new_dst
)
2369 emit_move_insn (new_dst
, new_reg
);
2374 /* Because of the volatile mem read, we get an ld.acq, which is the
2375 front half of the full barrier. The end half is the cmpxchg.rel.
2376 For relaxed and release memory models, we don't need this. But we
2377 also don't bother trying to prevent it either. */
2378 gcc_assert (model
== MEMMODEL_RELAXED
2379 || model
== MEMMODEL_RELEASE
2380 || MEM_VOLATILE_P (mem
));
2382 old_reg
= gen_reg_rtx (DImode
);
2383 cmp_reg
= gen_reg_rtx (DImode
);
2384 label
= gen_label_rtx ();
2388 val
= simplify_gen_subreg (DImode
, val
, mode
, 0);
2389 emit_insn (gen_extend_insn (cmp_reg
, mem
, DImode
, mode
, 1));
2392 emit_move_insn (cmp_reg
, mem
);
2396 ar_ccv
= gen_rtx_REG (DImode
, AR_CCV_REGNUM
);
2397 emit_move_insn (old_reg
, cmp_reg
);
2398 emit_move_insn (ar_ccv
, cmp_reg
);
2401 emit_move_insn (old_dst
, gen_lowpart (mode
, cmp_reg
));
2406 new_reg
= expand_simple_binop (DImode
, AND
, new_reg
, val
, NULL_RTX
,
2407 true, OPTAB_DIRECT
);
2408 new_reg
= expand_simple_unop (DImode
, code
, new_reg
, NULL_RTX
, true);
2411 new_reg
= expand_simple_binop (DImode
, code
, new_reg
, val
, NULL_RTX
,
2412 true, OPTAB_DIRECT
);
2415 new_reg
= gen_lowpart (mode
, new_reg
);
2417 emit_move_insn (new_dst
, new_reg
);
2421 case MEMMODEL_RELAXED
:
2422 case MEMMODEL_ACQUIRE
:
2423 case MEMMODEL_CONSUME
:
2426 case QImode
: icode
= CODE_FOR_cmpxchg_acq_qi
; break;
2427 case HImode
: icode
= CODE_FOR_cmpxchg_acq_hi
; break;
2428 case SImode
: icode
= CODE_FOR_cmpxchg_acq_si
; break;
2429 case DImode
: icode
= CODE_FOR_cmpxchg_acq_di
; break;
2435 case MEMMODEL_RELEASE
:
2436 case MEMMODEL_ACQ_REL
:
2437 case MEMMODEL_SEQ_CST
:
2440 case QImode
: icode
= CODE_FOR_cmpxchg_rel_qi
; break;
2441 case HImode
: icode
= CODE_FOR_cmpxchg_rel_hi
; break;
2442 case SImode
: icode
= CODE_FOR_cmpxchg_rel_si
; break;
2443 case DImode
: icode
= CODE_FOR_cmpxchg_rel_di
; break;
2453 emit_insn (GEN_FCN (icode
) (cmp_reg
, mem
, ar_ccv
, new_reg
));
2455 emit_cmp_and_jump_insns (cmp_reg
, old_reg
, NE
, NULL
, DImode
, true, label
);
2458 /* Begin the assembly file. */
2461 ia64_file_start (void)
2463 default_file_start ();
2464 emit_safe_across_calls ();
2468 emit_safe_across_calls (void)
2470 unsigned int rs
, re
;
2477 while (rs
< 64 && call_used_regs
[PR_REG (rs
)])
2481 for (re
= rs
+ 1; re
< 64 && ! call_used_regs
[PR_REG (re
)]; re
++)
2485 fputs ("\t.pred.safe_across_calls ", asm_out_file
);
2489 fputc (',', asm_out_file
);
2491 fprintf (asm_out_file
, "p%u", rs
);
2493 fprintf (asm_out_file
, "p%u-p%u", rs
, re
- 1);
2497 fputc ('\n', asm_out_file
);
2500 /* Globalize a declaration. */
2503 ia64_globalize_decl_name (FILE * stream
, tree decl
)
2505 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
2506 tree version_attr
= lookup_attribute ("version_id", DECL_ATTRIBUTES (decl
));
2509 tree v
= TREE_VALUE (TREE_VALUE (version_attr
));
2510 const char *p
= TREE_STRING_POINTER (v
);
2511 fprintf (stream
, "\t.alias %s#, \"%s{%s}\"\n", name
, name
, p
);
2513 targetm
.asm_out
.globalize_label (stream
, name
);
2514 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2515 ASM_OUTPUT_TYPE_DIRECTIVE (stream
, name
, "function");
2518 /* Helper function for ia64_compute_frame_size: find an appropriate general
2519 register to spill some special register to. SPECIAL_SPILL_MASK contains
2520 bits in GR0 to GR31 that have already been allocated by this routine.
2521 TRY_LOCALS is true if we should attempt to locate a local regnum. */
2524 find_gr_spill (enum ia64_frame_regs r
, int try_locals
)
2528 if (emitted_frame_related_regs
[r
] != 0)
2530 regno
= emitted_frame_related_regs
[r
];
2531 if (regno
>= LOC_REG (0) && regno
< LOC_REG (80 - frame_pointer_needed
)
2532 && current_frame_info
.n_local_regs
< regno
- LOC_REG (0) + 1)
2533 current_frame_info
.n_local_regs
= regno
- LOC_REG (0) + 1;
2534 else if (crtl
->is_leaf
2535 && regno
>= GR_REG (1) && regno
<= GR_REG (31))
2536 current_frame_info
.gr_used_mask
|= 1 << regno
;
2541 /* If this is a leaf function, first try an otherwise unused
2542 call-clobbered register. */
2545 for (regno
= GR_REG (1); regno
<= GR_REG (31); regno
++)
2546 if (! df_regs_ever_live_p (regno
)
2547 && call_used_regs
[regno
]
2548 && ! fixed_regs
[regno
]
2549 && ! global_regs
[regno
]
2550 && ((current_frame_info
.gr_used_mask
>> regno
) & 1) == 0
2551 && ! is_emitted (regno
))
2553 current_frame_info
.gr_used_mask
|= 1 << regno
;
2560 regno
= current_frame_info
.n_local_regs
;
2561 /* If there is a frame pointer, then we can't use loc79, because
2562 that is HARD_FRAME_POINTER_REGNUM. In particular, see the
2563 reg_name switching code in ia64_expand_prologue. */
2564 while (regno
< (80 - frame_pointer_needed
))
2565 if (! is_emitted (LOC_REG (regno
++)))
2567 current_frame_info
.n_local_regs
= regno
;
2568 return LOC_REG (regno
- 1);
2572 /* Failed to find a general register to spill to. Must use stack. */
2576 /* In order to make for nice schedules, we try to allocate every temporary
2577 to a different register. We must of course stay away from call-saved,
2578 fixed, and global registers. We must also stay away from registers
2579 allocated in current_frame_info.gr_used_mask, since those include regs
2580 used all through the prologue.
2582 Any register allocated here must be used immediately. The idea is to
2583 aid scheduling, not to solve data flow problems. */
2585 static int last_scratch_gr_reg
;
2588 next_scratch_gr_reg (void)
2592 for (i
= 0; i
< 32; ++i
)
2594 regno
= (last_scratch_gr_reg
+ i
+ 1) & 31;
2595 if (call_used_regs
[regno
]
2596 && ! fixed_regs
[regno
]
2597 && ! global_regs
[regno
]
2598 && ((current_frame_info
.gr_used_mask
>> regno
) & 1) == 0)
2600 last_scratch_gr_reg
= regno
;
2605 /* There must be _something_ available. */
2609 /* Helper function for ia64_compute_frame_size, called through
2610 diddle_return_value. Mark REG in current_frame_info.gr_used_mask. */
2613 mark_reg_gr_used_mask (rtx reg
, void *data ATTRIBUTE_UNUSED
)
2615 unsigned int regno
= REGNO (reg
);
2618 unsigned int i
, n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
2619 for (i
= 0; i
< n
; ++i
)
2620 current_frame_info
.gr_used_mask
|= 1 << (regno
+ i
);
2625 /* Returns the number of bytes offset between the frame pointer and the stack
2626 pointer for the current function. SIZE is the number of bytes of space
2627 needed for local variables. */
2630 ia64_compute_frame_size (HOST_WIDE_INT size
)
2632 HOST_WIDE_INT total_size
;
2633 HOST_WIDE_INT spill_size
= 0;
2634 HOST_WIDE_INT extra_spill_size
= 0;
2635 HOST_WIDE_INT pretend_args_size
;
2638 int spilled_gr_p
= 0;
2639 int spilled_fr_p
= 0;
2645 if (current_frame_info
.initialized
)
2648 memset (¤t_frame_info
, 0, sizeof current_frame_info
);
2649 CLEAR_HARD_REG_SET (mask
);
2651 /* Don't allocate scratches to the return register. */
2652 diddle_return_value (mark_reg_gr_used_mask
, NULL
);
2654 /* Don't allocate scratches to the EH scratch registers. */
2655 if (cfun
->machine
->ia64_eh_epilogue_sp
)
2656 mark_reg_gr_used_mask (cfun
->machine
->ia64_eh_epilogue_sp
, NULL
);
2657 if (cfun
->machine
->ia64_eh_epilogue_bsp
)
2658 mark_reg_gr_used_mask (cfun
->machine
->ia64_eh_epilogue_bsp
, NULL
);
2660 /* Static stack checking uses r2 and r3. */
2661 if (flag_stack_check
== STATIC_BUILTIN_STACK_CHECK
)
2662 current_frame_info
.gr_used_mask
|= 0xc;
2664 /* Find the size of the register stack frame. We have only 80 local
2665 registers, because we reserve 8 for the inputs and 8 for the
2668 /* Skip HARD_FRAME_POINTER_REGNUM (loc79) when frame_pointer_needed,
2669 since we'll be adjusting that down later. */
2670 regno
= LOC_REG (78) + ! frame_pointer_needed
;
2671 for (; regno
>= LOC_REG (0); regno
--)
2672 if (df_regs_ever_live_p (regno
) && !is_emitted (regno
))
2674 current_frame_info
.n_local_regs
= regno
- LOC_REG (0) + 1;
2676 /* For functions marked with the syscall_linkage attribute, we must mark
2677 all eight input registers as in use, so that locals aren't visible to
2680 if (cfun
->machine
->n_varargs
> 0
2681 || lookup_attribute ("syscall_linkage",
2682 TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl
))))
2683 current_frame_info
.n_input_regs
= 8;
2686 for (regno
= IN_REG (7); regno
>= IN_REG (0); regno
--)
2687 if (df_regs_ever_live_p (regno
))
2689 current_frame_info
.n_input_regs
= regno
- IN_REG (0) + 1;
2692 for (regno
= OUT_REG (7); regno
>= OUT_REG (0); regno
--)
2693 if (df_regs_ever_live_p (regno
))
2695 i
= regno
- OUT_REG (0) + 1;
2697 #ifndef PROFILE_HOOK
2698 /* When -p profiling, we need one output register for the mcount argument.
2699 Likewise for -a profiling for the bb_init_func argument. For -ax
2700 profiling, we need two output registers for the two bb_init_trace_func
2705 current_frame_info
.n_output_regs
= i
;
2707 /* ??? No rotating register support yet. */
2708 current_frame_info
.n_rotate_regs
= 0;
2710 /* Discover which registers need spilling, and how much room that
2711 will take. Begin with floating point and general registers,
2712 which will always wind up on the stack. */
2714 for (regno
= FR_REG (2); regno
<= FR_REG (127); regno
++)
2715 if (df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2717 SET_HARD_REG_BIT (mask
, regno
);
2723 for (regno
= GR_REG (1); regno
<= GR_REG (31); regno
++)
2724 if (df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2726 SET_HARD_REG_BIT (mask
, regno
);
2732 for (regno
= BR_REG (1); regno
<= BR_REG (7); regno
++)
2733 if (df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2735 SET_HARD_REG_BIT (mask
, regno
);
2740 /* Now come all special registers that might get saved in other
2741 general registers. */
2743 if (frame_pointer_needed
)
2745 current_frame_info
.r
[reg_fp
] = find_gr_spill (reg_fp
, 1);
2746 /* If we did not get a register, then we take LOC79. This is guaranteed
2747 to be free, even if regs_ever_live is already set, because this is
2748 HARD_FRAME_POINTER_REGNUM. This requires incrementing n_local_regs,
2749 as we don't count loc79 above. */
2750 if (current_frame_info
.r
[reg_fp
] == 0)
2752 current_frame_info
.r
[reg_fp
] = LOC_REG (79);
2753 current_frame_info
.n_local_regs
= LOC_REG (79) - LOC_REG (0) + 1;
2757 if (! crtl
->is_leaf
)
2759 /* Emit a save of BR0 if we call other functions. Do this even
2760 if this function doesn't return, as EH depends on this to be
2761 able to unwind the stack. */
2762 SET_HARD_REG_BIT (mask
, BR_REG (0));
2764 current_frame_info
.r
[reg_save_b0
] = find_gr_spill (reg_save_b0
, 1);
2765 if (current_frame_info
.r
[reg_save_b0
] == 0)
2767 extra_spill_size
+= 8;
2771 /* Similarly for ar.pfs. */
2772 SET_HARD_REG_BIT (mask
, AR_PFS_REGNUM
);
2773 current_frame_info
.r
[reg_save_ar_pfs
] = find_gr_spill (reg_save_ar_pfs
, 1);
2774 if (current_frame_info
.r
[reg_save_ar_pfs
] == 0)
2776 extra_spill_size
+= 8;
2780 /* Similarly for gp. Note that if we're calling setjmp, the stacked
2781 registers are clobbered, so we fall back to the stack. */
2782 current_frame_info
.r
[reg_save_gp
]
2783 = (cfun
->calls_setjmp
? 0 : find_gr_spill (reg_save_gp
, 1));
2784 if (current_frame_info
.r
[reg_save_gp
] == 0)
2786 SET_HARD_REG_BIT (mask
, GR_REG (1));
2793 if (df_regs_ever_live_p (BR_REG (0)) && ! call_used_regs
[BR_REG (0)])
2795 SET_HARD_REG_BIT (mask
, BR_REG (0));
2796 extra_spill_size
+= 8;
2800 if (df_regs_ever_live_p (AR_PFS_REGNUM
))
2802 SET_HARD_REG_BIT (mask
, AR_PFS_REGNUM
);
2803 current_frame_info
.r
[reg_save_ar_pfs
]
2804 = find_gr_spill (reg_save_ar_pfs
, 1);
2805 if (current_frame_info
.r
[reg_save_ar_pfs
] == 0)
2807 extra_spill_size
+= 8;
2813 /* Unwind descriptor hackery: things are most efficient if we allocate
2814 consecutive GR save registers for RP, PFS, FP in that order. However,
2815 it is absolutely critical that FP get the only hard register that's
2816 guaranteed to be free, so we allocated it first. If all three did
2817 happen to be allocated hard regs, and are consecutive, rearrange them
2818 into the preferred order now.
2820 If we have already emitted code for any of those registers,
2821 then it's already too late to change. */
2822 min_regno
= MIN (current_frame_info
.r
[reg_fp
],
2823 MIN (current_frame_info
.r
[reg_save_b0
],
2824 current_frame_info
.r
[reg_save_ar_pfs
]));
2825 max_regno
= MAX (current_frame_info
.r
[reg_fp
],
2826 MAX (current_frame_info
.r
[reg_save_b0
],
2827 current_frame_info
.r
[reg_save_ar_pfs
]));
2829 && min_regno
+ 2 == max_regno
2830 && (current_frame_info
.r
[reg_fp
] == min_regno
+ 1
2831 || current_frame_info
.r
[reg_save_b0
] == min_regno
+ 1
2832 || current_frame_info
.r
[reg_save_ar_pfs
] == min_regno
+ 1)
2833 && (emitted_frame_related_regs
[reg_save_b0
] == 0
2834 || emitted_frame_related_regs
[reg_save_b0
] == min_regno
)
2835 && (emitted_frame_related_regs
[reg_save_ar_pfs
] == 0
2836 || emitted_frame_related_regs
[reg_save_ar_pfs
] == min_regno
+ 1)
2837 && (emitted_frame_related_regs
[reg_fp
] == 0
2838 || emitted_frame_related_regs
[reg_fp
] == min_regno
+ 2))
2840 current_frame_info
.r
[reg_save_b0
] = min_regno
;
2841 current_frame_info
.r
[reg_save_ar_pfs
] = min_regno
+ 1;
2842 current_frame_info
.r
[reg_fp
] = min_regno
+ 2;
2845 /* See if we need to store the predicate register block. */
2846 for (regno
= PR_REG (0); regno
<= PR_REG (63); regno
++)
2847 if (df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2849 if (regno
<= PR_REG (63))
2851 SET_HARD_REG_BIT (mask
, PR_REG (0));
2852 current_frame_info
.r
[reg_save_pr
] = find_gr_spill (reg_save_pr
, 1);
2853 if (current_frame_info
.r
[reg_save_pr
] == 0)
2855 extra_spill_size
+= 8;
2859 /* ??? Mark them all as used so that register renaming and such
2860 are free to use them. */
2861 for (regno
= PR_REG (0); regno
<= PR_REG (63); regno
++)
2862 df_set_regs_ever_live (regno
, true);
2865 /* If we're forced to use st8.spill, we're forced to save and restore
2866 ar.unat as well. The check for existing liveness allows inline asm
2867 to touch ar.unat. */
2868 if (spilled_gr_p
|| cfun
->machine
->n_varargs
2869 || df_regs_ever_live_p (AR_UNAT_REGNUM
))
2871 df_set_regs_ever_live (AR_UNAT_REGNUM
, true);
2872 SET_HARD_REG_BIT (mask
, AR_UNAT_REGNUM
);
2873 current_frame_info
.r
[reg_save_ar_unat
]
2874 = find_gr_spill (reg_save_ar_unat
, spill_size
== 0);
2875 if (current_frame_info
.r
[reg_save_ar_unat
] == 0)
2877 extra_spill_size
+= 8;
2882 if (df_regs_ever_live_p (AR_LC_REGNUM
))
2884 SET_HARD_REG_BIT (mask
, AR_LC_REGNUM
);
2885 current_frame_info
.r
[reg_save_ar_lc
]
2886 = find_gr_spill (reg_save_ar_lc
, spill_size
== 0);
2887 if (current_frame_info
.r
[reg_save_ar_lc
] == 0)
2889 extra_spill_size
+= 8;
2894 /* If we have an odd number of words of pretend arguments written to
2895 the stack, then the FR save area will be unaligned. We round the
2896 size of this area up to keep things 16 byte aligned. */
2898 pretend_args_size
= IA64_STACK_ALIGN (crtl
->args
.pretend_args_size
);
2900 pretend_args_size
= crtl
->args
.pretend_args_size
;
2902 total_size
= (spill_size
+ extra_spill_size
+ size
+ pretend_args_size
2903 + crtl
->outgoing_args_size
);
2904 total_size
= IA64_STACK_ALIGN (total_size
);
2906 /* We always use the 16-byte scratch area provided by the caller, but
2907 if we are a leaf function, there's no one to which we need to provide
2908 a scratch area. However, if the function allocates dynamic stack space,
2909 the dynamic offset is computed early and contains STACK_POINTER_OFFSET,
2910 so we need to cope. */
2911 if (crtl
->is_leaf
&& !cfun
->calls_alloca
)
2912 total_size
= MAX (0, total_size
- 16);
2914 current_frame_info
.total_size
= total_size
;
2915 current_frame_info
.spill_cfa_off
= pretend_args_size
- 16;
2916 current_frame_info
.spill_size
= spill_size
;
2917 current_frame_info
.extra_spill_size
= extra_spill_size
;
2918 COPY_HARD_REG_SET (current_frame_info
.mask
, mask
);
2919 current_frame_info
.n_spilled
= n_spilled
;
2920 current_frame_info
.initialized
= reload_completed
;
2923 /* Worker function for TARGET_CAN_ELIMINATE. */
2926 ia64_can_eliminate (const int from ATTRIBUTE_UNUSED
, const int to
)
2928 return (to
== BR_REG (0) ? crtl
->is_leaf
: true);
2931 /* Compute the initial difference between the specified pair of registers. */
2934 ia64_initial_elimination_offset (int from
, int to
)
2936 HOST_WIDE_INT offset
;
2938 ia64_compute_frame_size (get_frame_size ());
2941 case FRAME_POINTER_REGNUM
:
2944 case HARD_FRAME_POINTER_REGNUM
:
2945 offset
= -current_frame_info
.total_size
;
2946 if (!crtl
->is_leaf
|| cfun
->calls_alloca
)
2947 offset
+= 16 + crtl
->outgoing_args_size
;
2950 case STACK_POINTER_REGNUM
:
2952 if (!crtl
->is_leaf
|| cfun
->calls_alloca
)
2953 offset
+= 16 + crtl
->outgoing_args_size
;
2961 case ARG_POINTER_REGNUM
:
2962 /* Arguments start above the 16 byte save area, unless stdarg
2963 in which case we store through the 16 byte save area. */
2966 case HARD_FRAME_POINTER_REGNUM
:
2967 offset
= 16 - crtl
->args
.pretend_args_size
;
2970 case STACK_POINTER_REGNUM
:
2971 offset
= (current_frame_info
.total_size
2972 + 16 - crtl
->args
.pretend_args_size
);
2987 /* If there are more than a trivial number of register spills, we use
2988 two interleaved iterators so that we can get two memory references
2991 In order to simplify things in the prologue and epilogue expanders,
2992 we use helper functions to fix up the memory references after the
2993 fact with the appropriate offsets to a POST_MODIFY memory mode.
2994 The following data structure tracks the state of the two iterators
2995 while insns are being emitted. */
2997 struct spill_fill_data
2999 rtx_insn
*init_after
; /* point at which to emit initializations */
3000 rtx init_reg
[2]; /* initial base register */
3001 rtx iter_reg
[2]; /* the iterator registers */
3002 rtx
*prev_addr
[2]; /* address of last memory use */
3003 rtx_insn
*prev_insn
[2]; /* the insn corresponding to prev_addr */
3004 HOST_WIDE_INT prev_off
[2]; /* last offset */
3005 int n_iter
; /* number of iterators in use */
3006 int next_iter
; /* next iterator to use */
3007 unsigned int save_gr_used_mask
;
3010 static struct spill_fill_data spill_fill_data
;
3013 setup_spill_pointers (int n_spills
, rtx init_reg
, HOST_WIDE_INT cfa_off
)
3017 spill_fill_data
.init_after
= get_last_insn ();
3018 spill_fill_data
.init_reg
[0] = init_reg
;
3019 spill_fill_data
.init_reg
[1] = init_reg
;
3020 spill_fill_data
.prev_addr
[0] = NULL
;
3021 spill_fill_data
.prev_addr
[1] = NULL
;
3022 spill_fill_data
.prev_insn
[0] = NULL
;
3023 spill_fill_data
.prev_insn
[1] = NULL
;
3024 spill_fill_data
.prev_off
[0] = cfa_off
;
3025 spill_fill_data
.prev_off
[1] = cfa_off
;
3026 spill_fill_data
.next_iter
= 0;
3027 spill_fill_data
.save_gr_used_mask
= current_frame_info
.gr_used_mask
;
3029 spill_fill_data
.n_iter
= 1 + (n_spills
> 2);
3030 for (i
= 0; i
< spill_fill_data
.n_iter
; ++i
)
3032 int regno
= next_scratch_gr_reg ();
3033 spill_fill_data
.iter_reg
[i
] = gen_rtx_REG (DImode
, regno
);
3034 current_frame_info
.gr_used_mask
|= 1 << regno
;
3039 finish_spill_pointers (void)
3041 current_frame_info
.gr_used_mask
= spill_fill_data
.save_gr_used_mask
;
3045 spill_restore_mem (rtx reg
, HOST_WIDE_INT cfa_off
)
3047 int iter
= spill_fill_data
.next_iter
;
3048 HOST_WIDE_INT disp
= spill_fill_data
.prev_off
[iter
] - cfa_off
;
3049 rtx disp_rtx
= GEN_INT (disp
);
3052 if (spill_fill_data
.prev_addr
[iter
])
3054 if (satisfies_constraint_N (disp_rtx
))
3056 *spill_fill_data
.prev_addr
[iter
]
3057 = gen_rtx_POST_MODIFY (DImode
, spill_fill_data
.iter_reg
[iter
],
3058 gen_rtx_PLUS (DImode
,
3059 spill_fill_data
.iter_reg
[iter
],
3061 add_reg_note (spill_fill_data
.prev_insn
[iter
],
3062 REG_INC
, spill_fill_data
.iter_reg
[iter
]);
3066 /* ??? Could use register post_modify for loads. */
3067 if (!satisfies_constraint_I (disp_rtx
))
3069 rtx tmp
= gen_rtx_REG (DImode
, next_scratch_gr_reg ());
3070 emit_move_insn (tmp
, disp_rtx
);
3073 emit_insn (gen_adddi3 (spill_fill_data
.iter_reg
[iter
],
3074 spill_fill_data
.iter_reg
[iter
], disp_rtx
));
3077 /* Micro-optimization: if we've created a frame pointer, it's at
3078 CFA 0, which may allow the real iterator to be initialized lower,
3079 slightly increasing parallelism. Also, if there are few saves
3080 it may eliminate the iterator entirely. */
3082 && spill_fill_data
.init_reg
[iter
] == stack_pointer_rtx
3083 && frame_pointer_needed
)
3085 mem
= gen_rtx_MEM (GET_MODE (reg
), hard_frame_pointer_rtx
);
3086 set_mem_alias_set (mem
, get_varargs_alias_set ());
3095 seq
= gen_movdi (spill_fill_data
.iter_reg
[iter
],
3096 spill_fill_data
.init_reg
[iter
]);
3101 if (!satisfies_constraint_I (disp_rtx
))
3103 rtx tmp
= gen_rtx_REG (DImode
, next_scratch_gr_reg ());
3104 emit_move_insn (tmp
, disp_rtx
);
3108 emit_insn (gen_adddi3 (spill_fill_data
.iter_reg
[iter
],
3109 spill_fill_data
.init_reg
[iter
],
3116 /* Careful for being the first insn in a sequence. */
3117 if (spill_fill_data
.init_after
)
3118 insn
= emit_insn_after (seq
, spill_fill_data
.init_after
);
3121 rtx_insn
*first
= get_insns ();
3123 insn
= emit_insn_before (seq
, first
);
3125 insn
= emit_insn (seq
);
3127 spill_fill_data
.init_after
= insn
;
3130 mem
= gen_rtx_MEM (GET_MODE (reg
), spill_fill_data
.iter_reg
[iter
]);
3132 /* ??? Not all of the spills are for varargs, but some of them are.
3133 The rest of the spills belong in an alias set of their own. But
3134 it doesn't actually hurt to include them here. */
3135 set_mem_alias_set (mem
, get_varargs_alias_set ());
3137 spill_fill_data
.prev_addr
[iter
] = &XEXP (mem
, 0);
3138 spill_fill_data
.prev_off
[iter
] = cfa_off
;
3140 if (++iter
>= spill_fill_data
.n_iter
)
3142 spill_fill_data
.next_iter
= iter
;
3148 do_spill (rtx (*move_fn
) (rtx
, rtx
, rtx
), rtx reg
, HOST_WIDE_INT cfa_off
,
3151 int iter
= spill_fill_data
.next_iter
;
3155 mem
= spill_restore_mem (reg
, cfa_off
);
3156 insn
= emit_insn ((*move_fn
) (mem
, reg
, GEN_INT (cfa_off
)));
3157 spill_fill_data
.prev_insn
[iter
] = insn
;
3164 RTX_FRAME_RELATED_P (insn
) = 1;
3166 /* Don't even pretend that the unwind code can intuit its way
3167 through a pair of interleaved post_modify iterators. Just
3168 provide the correct answer. */
3170 if (frame_pointer_needed
)
3172 base
= hard_frame_pointer_rtx
;
3177 base
= stack_pointer_rtx
;
3178 off
= current_frame_info
.total_size
- cfa_off
;
3181 add_reg_note (insn
, REG_CFA_OFFSET
,
3182 gen_rtx_SET (VOIDmode
,
3183 gen_rtx_MEM (GET_MODE (reg
),
3184 plus_constant (Pmode
,
3191 do_restore (rtx (*move_fn
) (rtx
, rtx
, rtx
), rtx reg
, HOST_WIDE_INT cfa_off
)
3193 int iter
= spill_fill_data
.next_iter
;
3196 insn
= emit_insn ((*move_fn
) (reg
, spill_restore_mem (reg
, cfa_off
),
3197 GEN_INT (cfa_off
)));
3198 spill_fill_data
.prev_insn
[iter
] = insn
;
3201 /* Wrapper functions that discards the CONST_INT spill offset. These
3202 exist so that we can give gr_spill/gr_fill the offset they need and
3203 use a consistent function interface. */
3206 gen_movdi_x (rtx dest
, rtx src
, rtx offset ATTRIBUTE_UNUSED
)
3208 return gen_movdi (dest
, src
);
3212 gen_fr_spill_x (rtx dest
, rtx src
, rtx offset ATTRIBUTE_UNUSED
)
3214 return gen_fr_spill (dest
, src
);
3218 gen_fr_restore_x (rtx dest
, rtx src
, rtx offset ATTRIBUTE_UNUSED
)
3220 return gen_fr_restore (dest
, src
);
3223 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
3225 /* See Table 6.2 of the IA-64 Software Developer Manual, Volume 2. */
3226 #define BACKING_STORE_SIZE(N) ((N) > 0 ? ((N) + (N)/63 + 1) * 8 : 0)
3228 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
3229 inclusive. These are offsets from the current stack pointer. BS_SIZE
3230 is the size of the backing store. ??? This clobbers r2 and r3. */
3233 ia64_emit_probe_stack_range (HOST_WIDE_INT first
, HOST_WIDE_INT size
,
3236 rtx r2
= gen_rtx_REG (Pmode
, GR_REG (2));
3237 rtx r3
= gen_rtx_REG (Pmode
, GR_REG (3));
3238 rtx p6
= gen_rtx_REG (BImode
, PR_REG (6));
3240 /* On the IA-64 there is a second stack in memory, namely the Backing Store
3241 of the Register Stack Engine. We also need to probe it after checking
3242 that the 2 stacks don't overlap. */
3243 emit_insn (gen_bsp_value (r3
));
3244 emit_move_insn (r2
, GEN_INT (-(first
+ size
)));
3246 /* Compare current value of BSP and SP registers. */
3247 emit_insn (gen_rtx_SET (VOIDmode
, p6
,
3248 gen_rtx_fmt_ee (LTU
, BImode
,
3249 r3
, stack_pointer_rtx
)));
3251 /* Compute the address of the probe for the Backing Store (which grows
3252 towards higher addresses). We probe only at the first offset of
3253 the next page because some OS (eg Linux/ia64) only extend the
3254 backing store when this specific address is hit (but generate a SEGV
3255 on other address). Page size is the worst case (4KB). The reserve
3256 size is at least 4096 - (96 + 2) * 8 = 3312 bytes, which is enough.
3257 Also compute the address of the last probe for the memory stack
3258 (which grows towards lower addresses). */
3259 emit_insn (gen_rtx_SET (VOIDmode
, r3
, plus_constant (Pmode
, r3
, 4095)));
3260 emit_insn (gen_rtx_SET (VOIDmode
, r2
,
3261 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, r2
)));
3263 /* Compare them and raise SEGV if the former has topped the latter. */
3264 emit_insn (gen_rtx_COND_EXEC (VOIDmode
,
3265 gen_rtx_fmt_ee (NE
, VOIDmode
, p6
, const0_rtx
),
3266 gen_rtx_SET (VOIDmode
, p6
,
3267 gen_rtx_fmt_ee (GEU
, BImode
,
3269 emit_insn (gen_rtx_SET (VOIDmode
,
3270 gen_rtx_ZERO_EXTRACT (DImode
, r3
, GEN_INT (12),
3273 emit_insn (gen_rtx_COND_EXEC (VOIDmode
,
3274 gen_rtx_fmt_ee (NE
, VOIDmode
, p6
, const0_rtx
),
3275 gen_rtx_TRAP_IF (VOIDmode
, const1_rtx
,
3278 /* Probe the Backing Store if necessary. */
3280 emit_stack_probe (r3
);
3282 /* Probe the memory stack if necessary. */
3286 /* See if we have a constant small number of probes to generate. If so,
3287 that's the easy case. */
3288 else if (size
<= PROBE_INTERVAL
)
3289 emit_stack_probe (r2
);
3291 /* The run-time loop is made up of 8 insns in the generic case while this
3292 compile-time loop is made up of 5+2*(n-2) insns for n # of intervals. */
3293 else if (size
<= 4 * PROBE_INTERVAL
)
3297 emit_move_insn (r2
, GEN_INT (-(first
+ PROBE_INTERVAL
)));
3298 emit_insn (gen_rtx_SET (VOIDmode
, r2
,
3299 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, r2
)));
3300 emit_stack_probe (r2
);
3302 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 2 until
3303 it exceeds SIZE. If only two probes are needed, this will not
3304 generate any code. Then probe at FIRST + SIZE. */
3305 for (i
= 2 * PROBE_INTERVAL
; i
< size
; i
+= PROBE_INTERVAL
)
3307 emit_insn (gen_rtx_SET (VOIDmode
, r2
,
3308 plus_constant (Pmode
, r2
, -PROBE_INTERVAL
)));
3309 emit_stack_probe (r2
);
3312 emit_insn (gen_rtx_SET (VOIDmode
, r2
,
3313 plus_constant (Pmode
, r2
,
3314 (i
- PROBE_INTERVAL
) - size
)));
3315 emit_stack_probe (r2
);
3318 /* Otherwise, do the same as above, but in a loop. Note that we must be
3319 extra careful with variables wrapping around because we might be at
3320 the very top (or the very bottom) of the address space and we have
3321 to be able to handle this case properly; in particular, we use an
3322 equality test for the loop condition. */
3325 HOST_WIDE_INT rounded_size
;
3327 emit_move_insn (r2
, GEN_INT (-first
));
3330 /* Step 1: round SIZE to the previous multiple of the interval. */
3332 rounded_size
= size
& -PROBE_INTERVAL
;
3335 /* Step 2: compute initial and final value of the loop counter. */
3337 /* TEST_ADDR = SP + FIRST. */
3338 emit_insn (gen_rtx_SET (VOIDmode
, r2
,
3339 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, r2
)));
3341 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
3342 if (rounded_size
> (1 << 21))
3344 emit_move_insn (r3
, GEN_INT (-rounded_size
));
3345 emit_insn (gen_rtx_SET (VOIDmode
, r3
, gen_rtx_PLUS (Pmode
, r2
, r3
)));
3348 emit_insn (gen_rtx_SET (VOIDmode
, r3
,
3349 gen_rtx_PLUS (Pmode
, r2
,
3350 GEN_INT (-rounded_size
))));
3355 while (TEST_ADDR != LAST_ADDR)
3357 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
3361 probes at FIRST + N * PROBE_INTERVAL for values of N from 1
3362 until it is equal to ROUNDED_SIZE. */
3364 emit_insn (gen_probe_stack_range (r2
, r2
, r3
));
3367 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
3368 that SIZE is equal to ROUNDED_SIZE. */
3370 /* TEMP = SIZE - ROUNDED_SIZE. */
3371 if (size
!= rounded_size
)
3373 emit_insn (gen_rtx_SET (VOIDmode
, r2
,
3374 plus_constant (Pmode
, r2
,
3375 rounded_size
- size
)));
3376 emit_stack_probe (r2
);
3380 /* Make sure nothing is scheduled before we are done. */
3381 emit_insn (gen_blockage ());
3384 /* Probe a range of stack addresses from REG1 to REG2 inclusive. These are
3385 absolute addresses. */
3388 output_probe_stack_range (rtx reg1
, rtx reg2
)
3390 static int labelno
= 0;
3391 char loop_lab
[32], end_lab
[32];
3394 ASM_GENERATE_INTERNAL_LABEL (loop_lab
, "LPSRL", labelno
);
3395 ASM_GENERATE_INTERNAL_LABEL (end_lab
, "LPSRE", labelno
++);
3397 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, loop_lab
);
3399 /* Jump to END_LAB if TEST_ADDR == LAST_ADDR. */
3402 xops
[2] = gen_rtx_REG (BImode
, PR_REG (6));
3403 output_asm_insn ("cmp.eq %2, %I2 = %0, %1", xops
);
3404 fprintf (asm_out_file
, "\t(%s) br.cond.dpnt ", reg_names
[REGNO (xops
[2])]);
3405 assemble_name_raw (asm_out_file
, end_lab
);
3406 fputc ('\n', asm_out_file
);
3408 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
3409 xops
[1] = GEN_INT (-PROBE_INTERVAL
);
3410 output_asm_insn ("addl %0 = %1, %0", xops
);
3411 fputs ("\t;;\n", asm_out_file
);
3413 /* Probe at TEST_ADDR and branch. */
3414 output_asm_insn ("probe.w.fault %0, 0", xops
);
3415 fprintf (asm_out_file
, "\tbr ");
3416 assemble_name_raw (asm_out_file
, loop_lab
);
3417 fputc ('\n', asm_out_file
);
3419 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, end_lab
);
3424 /* Called after register allocation to add any instructions needed for the
3425 prologue. Using a prologue insn is favored compared to putting all of the
3426 instructions in output_function_prologue(), since it allows the scheduler
3427 to intermix instructions with the saves of the caller saved registers. In
3428 some cases, it might be necessary to emit a barrier instruction as the last
3429 insn to prevent such scheduling.
3431 Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
3432 so that the debug info generation code can handle them properly.
3434 The register save area is laid out like so:
3436 [ varargs spill area ]
3437 [ fr register spill area ]
3438 [ br register spill area ]
3439 [ ar register spill area ]
3440 [ pr register spill area ]
3441 [ gr register spill area ] */
3443 /* ??? Get inefficient code when the frame size is larger than can fit in an
3444 adds instruction. */
3447 ia64_expand_prologue (void)
3450 rtx ar_pfs_save_reg
, ar_unat_save_reg
;
3451 int i
, epilogue_p
, regno
, alt_regno
, cfa_off
, n_varargs
;
3454 ia64_compute_frame_size (get_frame_size ());
3455 last_scratch_gr_reg
= 15;
3457 if (flag_stack_usage_info
)
3458 current_function_static_stack_size
= current_frame_info
.total_size
;
3460 if (flag_stack_check
== STATIC_BUILTIN_STACK_CHECK
)
3462 HOST_WIDE_INT size
= current_frame_info
.total_size
;
3463 int bs_size
= BACKING_STORE_SIZE (current_frame_info
.n_input_regs
3464 + current_frame_info
.n_local_regs
);
3466 if (crtl
->is_leaf
&& !cfun
->calls_alloca
)
3468 if (size
> PROBE_INTERVAL
&& size
> STACK_CHECK_PROTECT
)
3469 ia64_emit_probe_stack_range (STACK_CHECK_PROTECT
,
3470 size
- STACK_CHECK_PROTECT
,
3472 else if (size
+ bs_size
> STACK_CHECK_PROTECT
)
3473 ia64_emit_probe_stack_range (STACK_CHECK_PROTECT
, 0, bs_size
);
3475 else if (size
+ bs_size
> 0)
3476 ia64_emit_probe_stack_range (STACK_CHECK_PROTECT
, size
, bs_size
);
3481 fprintf (dump_file
, "ia64 frame related registers "
3482 "recorded in current_frame_info.r[]:\n");
3483 #define PRINTREG(a) if (current_frame_info.r[a]) \
3484 fprintf(dump_file, "%s = %d\n", #a, current_frame_info.r[a])
3486 PRINTREG(reg_save_b0
);
3487 PRINTREG(reg_save_pr
);
3488 PRINTREG(reg_save_ar_pfs
);
3489 PRINTREG(reg_save_ar_unat
);
3490 PRINTREG(reg_save_ar_lc
);
3491 PRINTREG(reg_save_gp
);
3495 /* If there is no epilogue, then we don't need some prologue insns.
3496 We need to avoid emitting the dead prologue insns, because flow
3497 will complain about them. */
3503 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
)
3504 if ((e
->flags
& EDGE_FAKE
) == 0
3505 && (e
->flags
& EDGE_FALLTHRU
) != 0)
3507 epilogue_p
= (e
!= NULL
);
3512 /* Set the local, input, and output register names. We need to do this
3513 for GNU libc, which creates crti.S/crtn.S by splitting initfini.c in
3514 half. If we use in/loc/out register names, then we get assembler errors
3515 in crtn.S because there is no alloc insn or regstk directive in there. */
3516 if (! TARGET_REG_NAMES
)
3518 int inputs
= current_frame_info
.n_input_regs
;
3519 int locals
= current_frame_info
.n_local_regs
;
3520 int outputs
= current_frame_info
.n_output_regs
;
3522 for (i
= 0; i
< inputs
; i
++)
3523 reg_names
[IN_REG (i
)] = ia64_reg_numbers
[i
];
3524 for (i
= 0; i
< locals
; i
++)
3525 reg_names
[LOC_REG (i
)] = ia64_reg_numbers
[inputs
+ i
];
3526 for (i
= 0; i
< outputs
; i
++)
3527 reg_names
[OUT_REG (i
)] = ia64_reg_numbers
[inputs
+ locals
+ i
];
3530 /* Set the frame pointer register name. The regnum is logically loc79,
3531 but of course we'll not have allocated that many locals. Rather than
3532 worrying about renumbering the existing rtxs, we adjust the name. */
3533 /* ??? This code means that we can never use one local register when
3534 there is a frame pointer. loc79 gets wasted in this case, as it is
3535 renamed to a register that will never be used. See also the try_locals
3536 code in find_gr_spill. */
3537 if (current_frame_info
.r
[reg_fp
])
3539 const char *tmp
= reg_names
[HARD_FRAME_POINTER_REGNUM
];
3540 reg_names
[HARD_FRAME_POINTER_REGNUM
]
3541 = reg_names
[current_frame_info
.r
[reg_fp
]];
3542 reg_names
[current_frame_info
.r
[reg_fp
]] = tmp
;
3545 /* We don't need an alloc instruction if we've used no outputs or locals. */
3546 if (current_frame_info
.n_local_regs
== 0
3547 && current_frame_info
.n_output_regs
== 0
3548 && current_frame_info
.n_input_regs
<= crtl
->args
.info
.int_regs
3549 && !TEST_HARD_REG_BIT (current_frame_info
.mask
, AR_PFS_REGNUM
))
3551 /* If there is no alloc, but there are input registers used, then we
3552 need a .regstk directive. */
3553 current_frame_info
.need_regstk
= (TARGET_REG_NAMES
!= 0);
3554 ar_pfs_save_reg
= NULL_RTX
;
3558 current_frame_info
.need_regstk
= 0;
3560 if (current_frame_info
.r
[reg_save_ar_pfs
])
3562 regno
= current_frame_info
.r
[reg_save_ar_pfs
];
3563 reg_emitted (reg_save_ar_pfs
);
3566 regno
= next_scratch_gr_reg ();
3567 ar_pfs_save_reg
= gen_rtx_REG (DImode
, regno
);
3569 insn
= emit_insn (gen_alloc (ar_pfs_save_reg
,
3570 GEN_INT (current_frame_info
.n_input_regs
),
3571 GEN_INT (current_frame_info
.n_local_regs
),
3572 GEN_INT (current_frame_info
.n_output_regs
),
3573 GEN_INT (current_frame_info
.n_rotate_regs
)));
3574 if (current_frame_info
.r
[reg_save_ar_pfs
])
3576 RTX_FRAME_RELATED_P (insn
) = 1;
3577 add_reg_note (insn
, REG_CFA_REGISTER
,
3578 gen_rtx_SET (VOIDmode
,
3580 gen_rtx_REG (DImode
, AR_PFS_REGNUM
)));
3584 /* Set up frame pointer, stack pointer, and spill iterators. */
3586 n_varargs
= cfun
->machine
->n_varargs
;
3587 setup_spill_pointers (current_frame_info
.n_spilled
+ n_varargs
,
3588 stack_pointer_rtx
, 0);
3590 if (frame_pointer_needed
)
3592 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
3593 RTX_FRAME_RELATED_P (insn
) = 1;
3595 /* Force the unwind info to recognize this as defining a new CFA,
3596 rather than some temp register setup. */
3597 add_reg_note (insn
, REG_CFA_ADJUST_CFA
, NULL_RTX
);
3600 if (current_frame_info
.total_size
!= 0)
3602 rtx frame_size_rtx
= GEN_INT (- current_frame_info
.total_size
);
3605 if (satisfies_constraint_I (frame_size_rtx
))
3606 offset
= frame_size_rtx
;
3609 regno
= next_scratch_gr_reg ();
3610 offset
= gen_rtx_REG (DImode
, regno
);
3611 emit_move_insn (offset
, frame_size_rtx
);
3614 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
3615 stack_pointer_rtx
, offset
));
3617 if (! frame_pointer_needed
)
3619 RTX_FRAME_RELATED_P (insn
) = 1;
3620 add_reg_note (insn
, REG_CFA_ADJUST_CFA
,
3621 gen_rtx_SET (VOIDmode
,
3623 gen_rtx_PLUS (DImode
,
3628 /* ??? At this point we must generate a magic insn that appears to
3629 modify the stack pointer, the frame pointer, and all spill
3630 iterators. This would allow the most scheduling freedom. For
3631 now, just hard stop. */
3632 emit_insn (gen_blockage ());
3635 /* Must copy out ar.unat before doing any integer spills. */
3636 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, AR_UNAT_REGNUM
))
3638 if (current_frame_info
.r
[reg_save_ar_unat
])
3641 = gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_ar_unat
]);
3642 reg_emitted (reg_save_ar_unat
);
3646 alt_regno
= next_scratch_gr_reg ();
3647 ar_unat_save_reg
= gen_rtx_REG (DImode
, alt_regno
);
3648 current_frame_info
.gr_used_mask
|= 1 << alt_regno
;
3651 reg
= gen_rtx_REG (DImode
, AR_UNAT_REGNUM
);
3652 insn
= emit_move_insn (ar_unat_save_reg
, reg
);
3653 if (current_frame_info
.r
[reg_save_ar_unat
])
3655 RTX_FRAME_RELATED_P (insn
) = 1;
3656 add_reg_note (insn
, REG_CFA_REGISTER
, NULL_RTX
);
3659 /* Even if we're not going to generate an epilogue, we still
3660 need to save the register so that EH works. */
3661 if (! epilogue_p
&& current_frame_info
.r
[reg_save_ar_unat
])
3662 emit_insn (gen_prologue_use (ar_unat_save_reg
));
3665 ar_unat_save_reg
= NULL_RTX
;
3667 /* Spill all varargs registers. Do this before spilling any GR registers,
3668 since we want the UNAT bits for the GR registers to override the UNAT
3669 bits from varargs, which we don't care about. */
3672 for (regno
= GR_ARG_FIRST
+ 7; n_varargs
> 0; --n_varargs
, --regno
)
3674 reg
= gen_rtx_REG (DImode
, regno
);
3675 do_spill (gen_gr_spill
, reg
, cfa_off
+= 8, NULL_RTX
);
3678 /* Locate the bottom of the register save area. */
3679 cfa_off
= (current_frame_info
.spill_cfa_off
3680 + current_frame_info
.spill_size
3681 + current_frame_info
.extra_spill_size
);
3683 /* Save the predicate register block either in a register or in memory. */
3684 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, PR_REG (0)))
3686 reg
= gen_rtx_REG (DImode
, PR_REG (0));
3687 if (current_frame_info
.r
[reg_save_pr
] != 0)
3689 alt_reg
= gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_pr
]);
3690 reg_emitted (reg_save_pr
);
3691 insn
= emit_move_insn (alt_reg
, reg
);
3693 /* ??? Denote pr spill/fill by a DImode move that modifies all
3694 64 hard registers. */
3695 RTX_FRAME_RELATED_P (insn
) = 1;
3696 add_reg_note (insn
, REG_CFA_REGISTER
, NULL_RTX
);
3698 /* Even if we're not going to generate an epilogue, we still
3699 need to save the register so that EH works. */
3701 emit_insn (gen_prologue_use (alt_reg
));
3705 alt_regno
= next_scratch_gr_reg ();
3706 alt_reg
= gen_rtx_REG (DImode
, alt_regno
);
3707 insn
= emit_move_insn (alt_reg
, reg
);
3708 do_spill (gen_movdi_x
, alt_reg
, cfa_off
, reg
);
3713 /* Handle AR regs in numerical order. All of them get special handling. */
3714 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, AR_UNAT_REGNUM
)
3715 && current_frame_info
.r
[reg_save_ar_unat
] == 0)
3717 reg
= gen_rtx_REG (DImode
, AR_UNAT_REGNUM
);
3718 do_spill (gen_movdi_x
, ar_unat_save_reg
, cfa_off
, reg
);
3722 /* The alloc insn already copied ar.pfs into a general register. The
3723 only thing we have to do now is copy that register to a stack slot
3724 if we'd not allocated a local register for the job. */
3725 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, AR_PFS_REGNUM
)
3726 && current_frame_info
.r
[reg_save_ar_pfs
] == 0)
3728 reg
= gen_rtx_REG (DImode
, AR_PFS_REGNUM
);
3729 do_spill (gen_movdi_x
, ar_pfs_save_reg
, cfa_off
, reg
);
3733 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, AR_LC_REGNUM
))
3735 reg
= gen_rtx_REG (DImode
, AR_LC_REGNUM
);
3736 if (current_frame_info
.r
[reg_save_ar_lc
] != 0)
3738 alt_reg
= gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_ar_lc
]);
3739 reg_emitted (reg_save_ar_lc
);
3740 insn
= emit_move_insn (alt_reg
, reg
);
3741 RTX_FRAME_RELATED_P (insn
) = 1;
3742 add_reg_note (insn
, REG_CFA_REGISTER
, NULL_RTX
);
3744 /* Even if we're not going to generate an epilogue, we still
3745 need to save the register so that EH works. */
3747 emit_insn (gen_prologue_use (alt_reg
));
3751 alt_regno
= next_scratch_gr_reg ();
3752 alt_reg
= gen_rtx_REG (DImode
, alt_regno
);
3753 emit_move_insn (alt_reg
, reg
);
3754 do_spill (gen_movdi_x
, alt_reg
, cfa_off
, reg
);
3759 /* Save the return pointer. */
3760 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, BR_REG (0)))
3762 reg
= gen_rtx_REG (DImode
, BR_REG (0));
3763 if (current_frame_info
.r
[reg_save_b0
] != 0)
3765 alt_reg
= gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_b0
]);
3766 reg_emitted (reg_save_b0
);
3767 insn
= emit_move_insn (alt_reg
, reg
);
3768 RTX_FRAME_RELATED_P (insn
) = 1;
3769 add_reg_note (insn
, REG_CFA_REGISTER
,
3770 gen_rtx_SET (VOIDmode
, alt_reg
, pc_rtx
));
3772 /* Even if we're not going to generate an epilogue, we still
3773 need to save the register so that EH works. */
3775 emit_insn (gen_prologue_use (alt_reg
));
3779 alt_regno
= next_scratch_gr_reg ();
3780 alt_reg
= gen_rtx_REG (DImode
, alt_regno
);
3781 emit_move_insn (alt_reg
, reg
);
3782 do_spill (gen_movdi_x
, alt_reg
, cfa_off
, reg
);
3787 if (current_frame_info
.r
[reg_save_gp
])
3789 reg_emitted (reg_save_gp
);
3790 insn
= emit_move_insn (gen_rtx_REG (DImode
,
3791 current_frame_info
.r
[reg_save_gp
]),
3792 pic_offset_table_rtx
);
3795 /* We should now be at the base of the gr/br/fr spill area. */
3796 gcc_assert (cfa_off
== (current_frame_info
.spill_cfa_off
3797 + current_frame_info
.spill_size
));
3799 /* Spill all general registers. */
3800 for (regno
= GR_REG (1); regno
<= GR_REG (31); ++regno
)
3801 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, regno
))
3803 reg
= gen_rtx_REG (DImode
, regno
);
3804 do_spill (gen_gr_spill
, reg
, cfa_off
, reg
);
3808 /* Spill the rest of the BR registers. */
3809 for (regno
= BR_REG (1); regno
<= BR_REG (7); ++regno
)
3810 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, regno
))
3812 alt_regno
= next_scratch_gr_reg ();
3813 alt_reg
= gen_rtx_REG (DImode
, alt_regno
);
3814 reg
= gen_rtx_REG (DImode
, regno
);
3815 emit_move_insn (alt_reg
, reg
);
3816 do_spill (gen_movdi_x
, alt_reg
, cfa_off
, reg
);
3820 /* Align the frame and spill all FR registers. */
3821 for (regno
= FR_REG (2); regno
<= FR_REG (127); ++regno
)
3822 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, regno
))
3824 gcc_assert (!(cfa_off
& 15));
3825 reg
= gen_rtx_REG (XFmode
, regno
);
3826 do_spill (gen_fr_spill_x
, reg
, cfa_off
, reg
);
3830 gcc_assert (cfa_off
== current_frame_info
.spill_cfa_off
);
3832 finish_spill_pointers ();
3835 /* Output the textual info surrounding the prologue. */
3838 ia64_start_function (FILE *file
, const char *fnname
,
3839 tree decl ATTRIBUTE_UNUSED
)
3841 #if TARGET_ABI_OPEN_VMS
3842 vms_start_function (fnname
);
3845 fputs ("\t.proc ", file
);
3846 assemble_name (file
, fnname
);
3848 ASM_OUTPUT_LABEL (file
, fnname
);
3851 /* Called after register allocation to add any instructions needed for the
3852 epilogue. Using an epilogue insn is favored compared to putting all of the
3853 instructions in output_function_prologue(), since it allows the scheduler
3854 to intermix instructions with the saves of the caller saved registers. In
3855 some cases, it might be necessary to emit a barrier instruction as the last
3856 insn to prevent such scheduling. */
3859 ia64_expand_epilogue (int sibcall_p
)
3862 rtx reg
, alt_reg
, ar_unat_save_reg
;
3863 int regno
, alt_regno
, cfa_off
;
3865 ia64_compute_frame_size (get_frame_size ());
3867 /* If there is a frame pointer, then we use it instead of the stack
3868 pointer, so that the stack pointer does not need to be valid when
3869 the epilogue starts. See EXIT_IGNORE_STACK. */
3870 if (frame_pointer_needed
)
3871 setup_spill_pointers (current_frame_info
.n_spilled
,
3872 hard_frame_pointer_rtx
, 0);
3874 setup_spill_pointers (current_frame_info
.n_spilled
, stack_pointer_rtx
,
3875 current_frame_info
.total_size
);
3877 if (current_frame_info
.total_size
!= 0)
3879 /* ??? At this point we must generate a magic insn that appears to
3880 modify the spill iterators and the frame pointer. This would
3881 allow the most scheduling freedom. For now, just hard stop. */
3882 emit_insn (gen_blockage ());
3885 /* Locate the bottom of the register save area. */
3886 cfa_off
= (current_frame_info
.spill_cfa_off
3887 + current_frame_info
.spill_size
3888 + current_frame_info
.extra_spill_size
);
3890 /* Restore the predicate registers. */
3891 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, PR_REG (0)))
3893 if (current_frame_info
.r
[reg_save_pr
] != 0)
3895 alt_reg
= gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_pr
]);
3896 reg_emitted (reg_save_pr
);
3900 alt_regno
= next_scratch_gr_reg ();
3901 alt_reg
= gen_rtx_REG (DImode
, alt_regno
);
3902 do_restore (gen_movdi_x
, alt_reg
, cfa_off
);
3905 reg
= gen_rtx_REG (DImode
, PR_REG (0));
3906 emit_move_insn (reg
, alt_reg
);
3909 /* Restore the application registers. */
3911 /* Load the saved unat from the stack, but do not restore it until
3912 after the GRs have been restored. */
3913 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, AR_UNAT_REGNUM
))
3915 if (current_frame_info
.r
[reg_save_ar_unat
] != 0)
3918 = gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_ar_unat
]);
3919 reg_emitted (reg_save_ar_unat
);
3923 alt_regno
= next_scratch_gr_reg ();
3924 ar_unat_save_reg
= gen_rtx_REG (DImode
, alt_regno
);
3925 current_frame_info
.gr_used_mask
|= 1 << alt_regno
;
3926 do_restore (gen_movdi_x
, ar_unat_save_reg
, cfa_off
);
3931 ar_unat_save_reg
= NULL_RTX
;
3933 if (current_frame_info
.r
[reg_save_ar_pfs
] != 0)
3935 reg_emitted (reg_save_ar_pfs
);
3936 alt_reg
= gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_ar_pfs
]);
3937 reg
= gen_rtx_REG (DImode
, AR_PFS_REGNUM
);
3938 emit_move_insn (reg
, alt_reg
);
3940 else if (TEST_HARD_REG_BIT (current_frame_info
.mask
, AR_PFS_REGNUM
))
3942 alt_regno
= next_scratch_gr_reg ();
3943 alt_reg
= gen_rtx_REG (DImode
, alt_regno
);
3944 do_restore (gen_movdi_x
, alt_reg
, cfa_off
);
3946 reg
= gen_rtx_REG (DImode
, AR_PFS_REGNUM
);
3947 emit_move_insn (reg
, alt_reg
);
3950 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, AR_LC_REGNUM
))
3952 if (current_frame_info
.r
[reg_save_ar_lc
] != 0)
3954 alt_reg
= gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_ar_lc
]);
3955 reg_emitted (reg_save_ar_lc
);
3959 alt_regno
= next_scratch_gr_reg ();
3960 alt_reg
= gen_rtx_REG (DImode
, alt_regno
);
3961 do_restore (gen_movdi_x
, alt_reg
, cfa_off
);
3964 reg
= gen_rtx_REG (DImode
, AR_LC_REGNUM
);
3965 emit_move_insn (reg
, alt_reg
);
3968 /* Restore the return pointer. */
3969 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, BR_REG (0)))
3971 if (current_frame_info
.r
[reg_save_b0
] != 0)
3973 alt_reg
= gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_b0
]);
3974 reg_emitted (reg_save_b0
);
3978 alt_regno
= next_scratch_gr_reg ();
3979 alt_reg
= gen_rtx_REG (DImode
, alt_regno
);
3980 do_restore (gen_movdi_x
, alt_reg
, cfa_off
);
3983 reg
= gen_rtx_REG (DImode
, BR_REG (0));
3984 emit_move_insn (reg
, alt_reg
);
3987 /* We should now be at the base of the gr/br/fr spill area. */
3988 gcc_assert (cfa_off
== (current_frame_info
.spill_cfa_off
3989 + current_frame_info
.spill_size
));
3991 /* The GP may be stored on the stack in the prologue, but it's
3992 never restored in the epilogue. Skip the stack slot. */
3993 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, GR_REG (1)))
3996 /* Restore all general registers. */
3997 for (regno
= GR_REG (2); regno
<= GR_REG (31); ++regno
)
3998 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, regno
))
4000 reg
= gen_rtx_REG (DImode
, regno
);
4001 do_restore (gen_gr_restore
, reg
, cfa_off
);
4005 /* Restore the branch registers. */
4006 for (regno
= BR_REG (1); regno
<= BR_REG (7); ++regno
)
4007 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, regno
))
4009 alt_regno
= next_scratch_gr_reg ();
4010 alt_reg
= gen_rtx_REG (DImode
, alt_regno
);
4011 do_restore (gen_movdi_x
, alt_reg
, cfa_off
);
4013 reg
= gen_rtx_REG (DImode
, regno
);
4014 emit_move_insn (reg
, alt_reg
);
4017 /* Restore floating point registers. */
4018 for (regno
= FR_REG (2); regno
<= FR_REG (127); ++regno
)
4019 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, regno
))
4021 gcc_assert (!(cfa_off
& 15));
4022 reg
= gen_rtx_REG (XFmode
, regno
);
4023 do_restore (gen_fr_restore_x
, reg
, cfa_off
);
4027 /* Restore ar.unat for real. */
4028 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, AR_UNAT_REGNUM
))
4030 reg
= gen_rtx_REG (DImode
, AR_UNAT_REGNUM
);
4031 emit_move_insn (reg
, ar_unat_save_reg
);
4034 gcc_assert (cfa_off
== current_frame_info
.spill_cfa_off
);
4036 finish_spill_pointers ();
4038 if (current_frame_info
.total_size
4039 || cfun
->machine
->ia64_eh_epilogue_sp
4040 || frame_pointer_needed
)
4042 /* ??? At this point we must generate a magic insn that appears to
4043 modify the spill iterators, the stack pointer, and the frame
4044 pointer. This would allow the most scheduling freedom. For now,
4046 emit_insn (gen_blockage ());
4049 if (cfun
->machine
->ia64_eh_epilogue_sp
)
4050 emit_move_insn (stack_pointer_rtx
, cfun
->machine
->ia64_eh_epilogue_sp
);
4051 else if (frame_pointer_needed
)
4053 insn
= emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
4054 RTX_FRAME_RELATED_P (insn
) = 1;
4055 add_reg_note (insn
, REG_CFA_ADJUST_CFA
, NULL
);
4057 else if (current_frame_info
.total_size
)
4059 rtx offset
, frame_size_rtx
;
4061 frame_size_rtx
= GEN_INT (current_frame_info
.total_size
);
4062 if (satisfies_constraint_I (frame_size_rtx
))
4063 offset
= frame_size_rtx
;
4066 regno
= next_scratch_gr_reg ();
4067 offset
= gen_rtx_REG (DImode
, regno
);
4068 emit_move_insn (offset
, frame_size_rtx
);
4071 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
4074 RTX_FRAME_RELATED_P (insn
) = 1;
4075 add_reg_note (insn
, REG_CFA_ADJUST_CFA
,
4076 gen_rtx_SET (VOIDmode
,
4078 gen_rtx_PLUS (DImode
,
4083 if (cfun
->machine
->ia64_eh_epilogue_bsp
)
4084 emit_insn (gen_set_bsp (cfun
->machine
->ia64_eh_epilogue_bsp
));
4087 emit_jump_insn (gen_return_internal (gen_rtx_REG (DImode
, BR_REG (0))));
4090 int fp
= GR_REG (2);
4091 /* We need a throw away register here, r0 and r1 are reserved,
4092 so r2 is the first available call clobbered register. If
4093 there was a frame_pointer register, we may have swapped the
4094 names of r2 and HARD_FRAME_POINTER_REGNUM, so we have to make
4095 sure we're using the string "r2" when emitting the register
4096 name for the assembler. */
4097 if (current_frame_info
.r
[reg_fp
]
4098 && current_frame_info
.r
[reg_fp
] == GR_REG (2))
4099 fp
= HARD_FRAME_POINTER_REGNUM
;
4101 /* We must emit an alloc to force the input registers to become output
4102 registers. Otherwise, if the callee tries to pass its parameters
4103 through to another call without an intervening alloc, then these
4105 /* ??? We don't need to preserve all input registers. We only need to
4106 preserve those input registers used as arguments to the sibling call.
4107 It is unclear how to compute that number here. */
4108 if (current_frame_info
.n_input_regs
!= 0)
4110 rtx n_inputs
= GEN_INT (current_frame_info
.n_input_regs
);
4112 insn
= emit_insn (gen_alloc (gen_rtx_REG (DImode
, fp
),
4113 const0_rtx
, const0_rtx
,
4114 n_inputs
, const0_rtx
));
4115 RTX_FRAME_RELATED_P (insn
) = 1;
4117 /* ??? We need to mark the alloc as frame-related so that it gets
4118 passed into ia64_asm_unwind_emit for ia64-specific unwinding.
4119 But there's nothing dwarf2 related to be done wrt the register
4120 windows. If we do nothing, dwarf2out will abort on the UNSPEC;
4121 the empty parallel means dwarf2out will not see anything. */
4122 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
4123 gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (0)));
4128 /* Return 1 if br.ret can do all the work required to return from a
4132 ia64_direct_return (void)
4134 if (reload_completed
&& ! frame_pointer_needed
)
4136 ia64_compute_frame_size (get_frame_size ());
4138 return (current_frame_info
.total_size
== 0
4139 && current_frame_info
.n_spilled
== 0
4140 && current_frame_info
.r
[reg_save_b0
] == 0
4141 && current_frame_info
.r
[reg_save_pr
] == 0
4142 && current_frame_info
.r
[reg_save_ar_pfs
] == 0
4143 && current_frame_info
.r
[reg_save_ar_unat
] == 0
4144 && current_frame_info
.r
[reg_save_ar_lc
] == 0);
4149 /* Return the magic cookie that we use to hold the return address
4150 during early compilation. */
4153 ia64_return_addr_rtx (HOST_WIDE_INT count
, rtx frame ATTRIBUTE_UNUSED
)
4157 return gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
), UNSPEC_RET_ADDR
);
4160 /* Split this value after reload, now that we know where the return
4161 address is saved. */
4164 ia64_split_return_addr_rtx (rtx dest
)
4168 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, BR_REG (0)))
4170 if (current_frame_info
.r
[reg_save_b0
] != 0)
4172 src
= gen_rtx_REG (DImode
, current_frame_info
.r
[reg_save_b0
]);
4173 reg_emitted (reg_save_b0
);
4181 /* Compute offset from CFA for BR0. */
4182 /* ??? Must be kept in sync with ia64_expand_prologue. */
4183 off
= (current_frame_info
.spill_cfa_off
4184 + current_frame_info
.spill_size
);
4185 for (regno
= GR_REG (1); regno
<= GR_REG (31); ++regno
)
4186 if (TEST_HARD_REG_BIT (current_frame_info
.mask
, regno
))
4189 /* Convert CFA offset to a register based offset. */
4190 if (frame_pointer_needed
)
4191 src
= hard_frame_pointer_rtx
;
4194 src
= stack_pointer_rtx
;
4195 off
+= current_frame_info
.total_size
;
4198 /* Load address into scratch register. */
4199 off_r
= GEN_INT (off
);
4200 if (satisfies_constraint_I (off_r
))
4201 emit_insn (gen_adddi3 (dest
, src
, off_r
));
4204 emit_move_insn (dest
, off_r
);
4205 emit_insn (gen_adddi3 (dest
, src
, dest
));
4208 src
= gen_rtx_MEM (Pmode
, dest
);
4212 src
= gen_rtx_REG (DImode
, BR_REG (0));
4214 emit_move_insn (dest
, src
);
4218 ia64_hard_regno_rename_ok (int from
, int to
)
4220 /* Don't clobber any of the registers we reserved for the prologue. */
4223 for (r
= reg_fp
; r
<= reg_save_ar_lc
; r
++)
4224 if (to
== current_frame_info
.r
[r
]
4225 || from
== current_frame_info
.r
[r
]
4226 || to
== emitted_frame_related_regs
[r
]
4227 || from
== emitted_frame_related_regs
[r
])
4230 /* Don't use output registers outside the register frame. */
4231 if (OUT_REGNO_P (to
) && to
>= OUT_REG (current_frame_info
.n_output_regs
))
4234 /* Retain even/oddness on predicate register pairs. */
4235 if (PR_REGNO_P (from
) && PR_REGNO_P (to
))
4236 return (from
& 1) == (to
& 1);
4241 /* Target hook for assembling integer objects. Handle word-sized
4242 aligned objects and detect the cases when @fptr is needed. */
4245 ia64_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
4247 if (size
== POINTER_SIZE
/ BITS_PER_UNIT
4248 && !(TARGET_NO_PIC
|| TARGET_AUTO_PIC
)
4249 && GET_CODE (x
) == SYMBOL_REF
4250 && SYMBOL_REF_FUNCTION_P (x
))
4252 static const char * const directive
[2][2] = {
4253 /* 64-bit pointer */ /* 32-bit pointer */
4254 { "\tdata8.ua\t@fptr(", "\tdata4.ua\t@fptr("}, /* unaligned */
4255 { "\tdata8\t@fptr(", "\tdata4\t@fptr("} /* aligned */
4257 fputs (directive
[(aligned_p
!= 0)][POINTER_SIZE
== 32], asm_out_file
);
4258 output_addr_const (asm_out_file
, x
);
4259 fputs (")\n", asm_out_file
);
4262 return default_assemble_integer (x
, size
, aligned_p
);
4265 /* Emit the function prologue. */
4268 ia64_output_function_prologue (FILE *file
, HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
4270 int mask
, grsave
, grsave_prev
;
4272 if (current_frame_info
.need_regstk
)
4273 fprintf (file
, "\t.regstk %d, %d, %d, %d\n",
4274 current_frame_info
.n_input_regs
,
4275 current_frame_info
.n_local_regs
,
4276 current_frame_info
.n_output_regs
,
4277 current_frame_info
.n_rotate_regs
);
4279 if (ia64_except_unwind_info (&global_options
) != UI_TARGET
)
4282 /* Emit the .prologue directive. */
4285 grsave
= grsave_prev
= 0;
4286 if (current_frame_info
.r
[reg_save_b0
] != 0)
4289 grsave
= grsave_prev
= current_frame_info
.r
[reg_save_b0
];
4291 if (current_frame_info
.r
[reg_save_ar_pfs
] != 0
4292 && (grsave_prev
== 0
4293 || current_frame_info
.r
[reg_save_ar_pfs
] == grsave_prev
+ 1))
4296 if (grsave_prev
== 0)
4297 grsave
= current_frame_info
.r
[reg_save_ar_pfs
];
4298 grsave_prev
= current_frame_info
.r
[reg_save_ar_pfs
];
4300 if (current_frame_info
.r
[reg_fp
] != 0
4301 && (grsave_prev
== 0
4302 || current_frame_info
.r
[reg_fp
] == grsave_prev
+ 1))
4305 if (grsave_prev
== 0)
4306 grsave
= HARD_FRAME_POINTER_REGNUM
;
4307 grsave_prev
= current_frame_info
.r
[reg_fp
];
4309 if (current_frame_info
.r
[reg_save_pr
] != 0
4310 && (grsave_prev
== 0
4311 || current_frame_info
.r
[reg_save_pr
] == grsave_prev
+ 1))
4314 if (grsave_prev
== 0)
4315 grsave
= current_frame_info
.r
[reg_save_pr
];
4318 if (mask
&& TARGET_GNU_AS
)
4319 fprintf (file
, "\t.prologue %d, %d\n", mask
,
4320 ia64_dbx_register_number (grsave
));
4322 fputs ("\t.prologue\n", file
);
4324 /* Emit a .spill directive, if necessary, to relocate the base of
4325 the register spill area. */
4326 if (current_frame_info
.spill_cfa_off
!= -16)
4327 fprintf (file
, "\t.spill %ld\n",
4328 (long) (current_frame_info
.spill_cfa_off
4329 + current_frame_info
.spill_size
));
4332 /* Emit the .body directive at the scheduled end of the prologue. */
4335 ia64_output_function_end_prologue (FILE *file
)
4337 if (ia64_except_unwind_info (&global_options
) != UI_TARGET
)
4340 fputs ("\t.body\n", file
);
4343 /* Emit the function epilogue. */
4346 ia64_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED
,
4347 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
4351 if (current_frame_info
.r
[reg_fp
])
4353 const char *tmp
= reg_names
[HARD_FRAME_POINTER_REGNUM
];
4354 reg_names
[HARD_FRAME_POINTER_REGNUM
]
4355 = reg_names
[current_frame_info
.r
[reg_fp
]];
4356 reg_names
[current_frame_info
.r
[reg_fp
]] = tmp
;
4357 reg_emitted (reg_fp
);
4359 if (! TARGET_REG_NAMES
)
4361 for (i
= 0; i
< current_frame_info
.n_input_regs
; i
++)
4362 reg_names
[IN_REG (i
)] = ia64_input_reg_names
[i
];
4363 for (i
= 0; i
< current_frame_info
.n_local_regs
; i
++)
4364 reg_names
[LOC_REG (i
)] = ia64_local_reg_names
[i
];
4365 for (i
= 0; i
< current_frame_info
.n_output_regs
; i
++)
4366 reg_names
[OUT_REG (i
)] = ia64_output_reg_names
[i
];
4369 current_frame_info
.initialized
= 0;
4373 ia64_dbx_register_number (int regno
)
4375 /* In ia64_expand_prologue we quite literally renamed the frame pointer
4376 from its home at loc79 to something inside the register frame. We
4377 must perform the same renumbering here for the debug info. */
4378 if (current_frame_info
.r
[reg_fp
])
4380 if (regno
== HARD_FRAME_POINTER_REGNUM
)
4381 regno
= current_frame_info
.r
[reg_fp
];
4382 else if (regno
== current_frame_info
.r
[reg_fp
])
4383 regno
= HARD_FRAME_POINTER_REGNUM
;
4386 if (IN_REGNO_P (regno
))
4387 return 32 + regno
- IN_REG (0);
4388 else if (LOC_REGNO_P (regno
))
4389 return 32 + current_frame_info
.n_input_regs
+ regno
- LOC_REG (0);
4390 else if (OUT_REGNO_P (regno
))
4391 return (32 + current_frame_info
.n_input_regs
4392 + current_frame_info
.n_local_regs
+ regno
- OUT_REG (0));
4397 /* Implement TARGET_TRAMPOLINE_INIT.
4399 The trampoline should set the static chain pointer to value placed
4400 into the trampoline and should branch to the specified routine.
4401 To make the normal indirect-subroutine calling convention work,
4402 the trampoline must look like a function descriptor; the first
4403 word being the target address and the second being the target's
4406 We abuse the concept of a global pointer by arranging for it
4407 to point to the data we need to load. The complete trampoline
4408 has the following form:
4410 +-------------------+ \
4411 TRAMP: | __ia64_trampoline | |
4412 +-------------------+ > fake function descriptor
4414 +-------------------+ /
4415 | target descriptor |
4416 +-------------------+
4418 +-------------------+
4422 ia64_trampoline_init (rtx m_tramp
, tree fndecl
, rtx static_chain
)
4424 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
4425 rtx addr
, addr_reg
, tramp
, eight
= GEN_INT (8);
4427 /* The Intel assembler requires that the global __ia64_trampoline symbol
4428 be declared explicitly */
4431 static bool declared_ia64_trampoline
= false;
4433 if (!declared_ia64_trampoline
)
4435 declared_ia64_trampoline
= true;
4436 (*targetm
.asm_out
.globalize_label
) (asm_out_file
,
4437 "__ia64_trampoline");
4441 /* Make sure addresses are Pmode even if we are in ILP32 mode. */
4442 addr
= convert_memory_address (Pmode
, XEXP (m_tramp
, 0));
4443 fnaddr
= convert_memory_address (Pmode
, fnaddr
);
4444 static_chain
= convert_memory_address (Pmode
, static_chain
);
4446 /* Load up our iterator. */
4447 addr_reg
= copy_to_reg (addr
);
4448 m_tramp
= adjust_automodify_address (m_tramp
, Pmode
, addr_reg
, 0);
4450 /* The first two words are the fake descriptor:
4451 __ia64_trampoline, ADDR+16. */
4452 tramp
= gen_rtx_SYMBOL_REF (Pmode
, "__ia64_trampoline");
4453 if (TARGET_ABI_OPEN_VMS
)
4455 /* HP decided to break the ELF ABI on VMS (to deal with an ambiguity
4456 in the Macro-32 compiler) and changed the semantics of the LTOFF22
4457 relocation against function symbols to make it identical to the
4458 LTOFF_FPTR22 relocation. Emit the latter directly to stay within
4459 strict ELF and dereference to get the bare code address. */
4460 rtx reg
= gen_reg_rtx (Pmode
);
4461 SYMBOL_REF_FLAGS (tramp
) |= SYMBOL_FLAG_FUNCTION
;
4462 emit_move_insn (reg
, tramp
);
4463 emit_move_insn (reg
, gen_rtx_MEM (Pmode
, reg
));
4466 emit_move_insn (m_tramp
, tramp
);
4467 emit_insn (gen_adddi3 (addr_reg
, addr_reg
, eight
));
4468 m_tramp
= adjust_automodify_address (m_tramp
, VOIDmode
, NULL
, 8);
4470 emit_move_insn (m_tramp
, force_reg (Pmode
, plus_constant (Pmode
, addr
, 16)));
4471 emit_insn (gen_adddi3 (addr_reg
, addr_reg
, eight
));
4472 m_tramp
= adjust_automodify_address (m_tramp
, VOIDmode
, NULL
, 8);
4474 /* The third word is the target descriptor. */
4475 emit_move_insn (m_tramp
, force_reg (Pmode
, fnaddr
));
4476 emit_insn (gen_adddi3 (addr_reg
, addr_reg
, eight
));
4477 m_tramp
= adjust_automodify_address (m_tramp
, VOIDmode
, NULL
, 8);
4479 /* The fourth word is the static chain. */
4480 emit_move_insn (m_tramp
, static_chain
);
4483 /* Do any needed setup for a variadic function. CUM has not been updated
4484 for the last named argument which has type TYPE and mode MODE.
4486 We generate the actual spill instructions during prologue generation. */
4489 ia64_setup_incoming_varargs (cumulative_args_t cum
, enum machine_mode mode
,
4490 tree type
, int * pretend_size
,
4491 int second_time ATTRIBUTE_UNUSED
)
4493 CUMULATIVE_ARGS next_cum
= *get_cumulative_args (cum
);
4495 /* Skip the current argument. */
4496 ia64_function_arg_advance (pack_cumulative_args (&next_cum
), mode
, type
, 1);
4498 if (next_cum
.words
< MAX_ARGUMENT_SLOTS
)
4500 int n
= MAX_ARGUMENT_SLOTS
- next_cum
.words
;
4501 *pretend_size
= n
* UNITS_PER_WORD
;
4502 cfun
->machine
->n_varargs
= n
;
4506 /* Check whether TYPE is a homogeneous floating point aggregate. If
4507 it is, return the mode of the floating point type that appears
4508 in all leafs. If it is not, return VOIDmode.
4510 An aggregate is a homogeneous floating point aggregate is if all
4511 fields/elements in it have the same floating point type (e.g,
4512 SFmode). 128-bit quad-precision floats are excluded.
4514 Variable sized aggregates should never arrive here, since we should
4515 have already decided to pass them by reference. Top-level zero-sized
4516 aggregates are excluded because our parallels crash the middle-end. */
4518 static enum machine_mode
4519 hfa_element_mode (const_tree type
, bool nested
)
4521 enum machine_mode element_mode
= VOIDmode
;
4522 enum machine_mode mode
;
4523 enum tree_code code
= TREE_CODE (type
);
4524 int know_element_mode
= 0;
4527 if (!nested
&& (!TYPE_SIZE (type
) || integer_zerop (TYPE_SIZE (type
))))
4532 case VOID_TYPE
: case INTEGER_TYPE
: case ENUMERAL_TYPE
:
4533 case BOOLEAN_TYPE
: case POINTER_TYPE
:
4534 case OFFSET_TYPE
: case REFERENCE_TYPE
: case METHOD_TYPE
:
4535 case LANG_TYPE
: case FUNCTION_TYPE
:
4538 /* Fortran complex types are supposed to be HFAs, so we need to handle
4539 gcc's COMPLEX_TYPEs as HFAs. We need to exclude the integral complex
4542 if (GET_MODE_CLASS (TYPE_MODE (type
)) == MODE_COMPLEX_FLOAT
4543 && TYPE_MODE (type
) != TCmode
)
4544 return GET_MODE_INNER (TYPE_MODE (type
));
4549 /* We want to return VOIDmode for raw REAL_TYPEs, but the actual
4550 mode if this is contained within an aggregate. */
4551 if (nested
&& TYPE_MODE (type
) != TFmode
)
4552 return TYPE_MODE (type
);
4557 return hfa_element_mode (TREE_TYPE (type
), 1);
4561 case QUAL_UNION_TYPE
:
4562 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
4564 if (TREE_CODE (t
) != FIELD_DECL
)
4567 mode
= hfa_element_mode (TREE_TYPE (t
), 1);
4568 if (know_element_mode
)
4570 if (mode
!= element_mode
)
4573 else if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
4577 know_element_mode
= 1;
4578 element_mode
= mode
;
4581 return element_mode
;
4584 /* If we reach here, we probably have some front-end specific type
4585 that the backend doesn't know about. This can happen via the
4586 aggregate_value_p call in init_function_start. All we can do is
4587 ignore unknown tree types. */
4594 /* Return the number of words required to hold a quantity of TYPE and MODE
4595 when passed as an argument. */
4597 ia64_function_arg_words (const_tree type
, enum machine_mode mode
)
4601 if (mode
== BLKmode
)
4602 words
= int_size_in_bytes (type
);
4604 words
= GET_MODE_SIZE (mode
);
4606 return (words
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
; /* round up */
4609 /* Return the number of registers that should be skipped so the current
4610 argument (described by TYPE and WORDS) will be properly aligned.
4612 Integer and float arguments larger than 8 bytes start at the next
4613 even boundary. Aggregates larger than 8 bytes start at the next
4614 even boundary if the aggregate has 16 byte alignment. Note that
4615 in the 32-bit ABI, TImode and TFmode have only 8-byte alignment
4616 but are still to be aligned in registers.
4618 ??? The ABI does not specify how to handle aggregates with
4619 alignment from 9 to 15 bytes, or greater than 16. We handle them
4620 all as if they had 16 byte alignment. Such aggregates can occur
4621 only if gcc extensions are used. */
4623 ia64_function_arg_offset (const CUMULATIVE_ARGS
*cum
,
4624 const_tree type
, int words
)
4626 /* No registers are skipped on VMS. */
4627 if (TARGET_ABI_OPEN_VMS
|| (cum
->words
& 1) == 0)
4631 && TREE_CODE (type
) != INTEGER_TYPE
4632 && TREE_CODE (type
) != REAL_TYPE
)
4633 return TYPE_ALIGN (type
) > 8 * BITS_PER_UNIT
;
4638 /* Return rtx for register where argument is passed, or zero if it is passed
4640 /* ??? 128-bit quad-precision floats are always passed in general
4644 ia64_function_arg_1 (cumulative_args_t cum_v
, enum machine_mode mode
,
4645 const_tree type
, bool named
, bool incoming
)
4647 const CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
4649 int basereg
= (incoming
? GR_ARG_FIRST
: AR_ARG_FIRST
);
4650 int words
= ia64_function_arg_words (type
, mode
);
4651 int offset
= ia64_function_arg_offset (cum
, type
, words
);
4652 enum machine_mode hfa_mode
= VOIDmode
;
4654 /* For OPEN VMS, emit the instruction setting up the argument register here,
4655 when we know this will be together with the other arguments setup related
4656 insns. This is not the conceptually best place to do this, but this is
4657 the easiest as we have convenient access to cumulative args info. */
4659 if (TARGET_ABI_OPEN_VMS
&& mode
== VOIDmode
&& type
== void_type_node
4662 unsigned HOST_WIDE_INT regval
= cum
->words
;
4665 for (i
= 0; i
< 8; i
++)
4666 regval
|= ((int) cum
->atypes
[i
]) << (i
* 3 + 8);
4668 emit_move_insn (gen_rtx_REG (DImode
, GR_REG (25)),
4672 /* If all argument slots are used, then it must go on the stack. */
4673 if (cum
->words
+ offset
>= MAX_ARGUMENT_SLOTS
)
4676 /* On OpenVMS argument is either in Rn or Fn. */
4677 if (TARGET_ABI_OPEN_VMS
)
4679 if (FLOAT_MODE_P (mode
))
4680 return gen_rtx_REG (mode
, FR_ARG_FIRST
+ cum
->words
);
4682 return gen_rtx_REG (mode
, basereg
+ cum
->words
);
4685 /* Check for and handle homogeneous FP aggregates. */
4687 hfa_mode
= hfa_element_mode (type
, 0);
4689 /* Unnamed prototyped hfas are passed as usual. Named prototyped hfas
4690 and unprototyped hfas are passed specially. */
4691 if (hfa_mode
!= VOIDmode
&& (! cum
->prototype
|| named
))
4695 int fp_regs
= cum
->fp_regs
;
4696 int int_regs
= cum
->words
+ offset
;
4697 int hfa_size
= GET_MODE_SIZE (hfa_mode
);
4701 /* If prototyped, pass it in FR regs then GR regs.
4702 If not prototyped, pass it in both FR and GR regs.
4704 If this is an SFmode aggregate, then it is possible to run out of
4705 FR regs while GR regs are still left. In that case, we pass the
4706 remaining part in the GR regs. */
4708 /* Fill the FP regs. We do this always. We stop if we reach the end
4709 of the argument, the last FP register, or the last argument slot. */
4711 byte_size
= ((mode
== BLKmode
)
4712 ? int_size_in_bytes (type
) : GET_MODE_SIZE (mode
));
4713 args_byte_size
= int_regs
* UNITS_PER_WORD
;
4715 for (; (offset
< byte_size
&& fp_regs
< MAX_ARGUMENT_SLOTS
4716 && args_byte_size
< (MAX_ARGUMENT_SLOTS
* UNITS_PER_WORD
)); i
++)
4718 loc
[i
] = gen_rtx_EXPR_LIST (VOIDmode
,
4719 gen_rtx_REG (hfa_mode
, (FR_ARG_FIRST
4723 args_byte_size
+= hfa_size
;
4727 /* If no prototype, then the whole thing must go in GR regs. */
4728 if (! cum
->prototype
)
4730 /* If this is an SFmode aggregate, then we might have some left over
4731 that needs to go in GR regs. */
4732 else if (byte_size
!= offset
)
4733 int_regs
+= offset
/ UNITS_PER_WORD
;
4735 /* Fill in the GR regs. We must use DImode here, not the hfa mode. */
4737 for (; offset
< byte_size
&& int_regs
< MAX_ARGUMENT_SLOTS
; i
++)
4739 enum machine_mode gr_mode
= DImode
;
4740 unsigned int gr_size
;
4742 /* If we have an odd 4 byte hunk because we ran out of FR regs,
4743 then this goes in a GR reg left adjusted/little endian, right
4744 adjusted/big endian. */
4745 /* ??? Currently this is handled wrong, because 4-byte hunks are
4746 always right adjusted/little endian. */
4749 /* If we have an even 4 byte hunk because the aggregate is a
4750 multiple of 4 bytes in size, then this goes in a GR reg right
4751 adjusted/little endian. */
4752 else if (byte_size
- offset
== 4)
4755 loc
[i
] = gen_rtx_EXPR_LIST (VOIDmode
,
4756 gen_rtx_REG (gr_mode
, (basereg
4760 gr_size
= GET_MODE_SIZE (gr_mode
);
4762 if (gr_size
== UNITS_PER_WORD
4763 || (gr_size
< UNITS_PER_WORD
&& offset
% UNITS_PER_WORD
== 0))
4765 else if (gr_size
> UNITS_PER_WORD
)
4766 int_regs
+= gr_size
/ UNITS_PER_WORD
;
4768 return gen_rtx_PARALLEL (mode
, gen_rtvec_v (i
, loc
));
4771 /* Integral and aggregates go in general registers. If we have run out of
4772 FR registers, then FP values must also go in general registers. This can
4773 happen when we have a SFmode HFA. */
4774 else if (mode
== TFmode
|| mode
== TCmode
4775 || (! FLOAT_MODE_P (mode
) || cum
->fp_regs
== MAX_ARGUMENT_SLOTS
))
4777 int byte_size
= ((mode
== BLKmode
)
4778 ? int_size_in_bytes (type
) : GET_MODE_SIZE (mode
));
4779 if (BYTES_BIG_ENDIAN
4780 && (mode
== BLKmode
|| (type
&& AGGREGATE_TYPE_P (type
)))
4781 && byte_size
< UNITS_PER_WORD
4784 rtx gr_reg
= gen_rtx_EXPR_LIST (VOIDmode
,
4785 gen_rtx_REG (DImode
,
4786 (basereg
+ cum
->words
4789 return gen_rtx_PARALLEL (mode
, gen_rtvec (1, gr_reg
));
4792 return gen_rtx_REG (mode
, basereg
+ cum
->words
+ offset
);
4796 /* If there is a prototype, then FP values go in a FR register when
4797 named, and in a GR register when unnamed. */
4798 else if (cum
->prototype
)
4801 return gen_rtx_REG (mode
, FR_ARG_FIRST
+ cum
->fp_regs
);
4802 /* In big-endian mode, an anonymous SFmode value must be represented
4803 as (parallel:SF [(expr_list (reg:DI n) (const_int 0))]) to force
4804 the value into the high half of the general register. */
4805 else if (BYTES_BIG_ENDIAN
&& mode
== SFmode
)
4806 return gen_rtx_PARALLEL (mode
,
4808 gen_rtx_EXPR_LIST (VOIDmode
,
4809 gen_rtx_REG (DImode
, basereg
+ cum
->words
+ offset
),
4812 return gen_rtx_REG (mode
, basereg
+ cum
->words
+ offset
);
4814 /* If there is no prototype, then FP values go in both FR and GR
4818 /* See comment above. */
4819 enum machine_mode inner_mode
=
4820 (BYTES_BIG_ENDIAN
&& mode
== SFmode
) ? DImode
: mode
;
4822 rtx fp_reg
= gen_rtx_EXPR_LIST (VOIDmode
,
4823 gen_rtx_REG (mode
, (FR_ARG_FIRST
4826 rtx gr_reg
= gen_rtx_EXPR_LIST (VOIDmode
,
4827 gen_rtx_REG (inner_mode
,
4828 (basereg
+ cum
->words
4832 return gen_rtx_PARALLEL (mode
, gen_rtvec (2, fp_reg
, gr_reg
));
4836 /* Implement TARGET_FUNCION_ARG target hook. */
4839 ia64_function_arg (cumulative_args_t cum
, enum machine_mode mode
,
4840 const_tree type
, bool named
)
4842 return ia64_function_arg_1 (cum
, mode
, type
, named
, false);
4845 /* Implement TARGET_FUNCION_INCOMING_ARG target hook. */
4848 ia64_function_incoming_arg (cumulative_args_t cum
,
4849 enum machine_mode mode
,
4850 const_tree type
, bool named
)
4852 return ia64_function_arg_1 (cum
, mode
, type
, named
, true);
4855 /* Return number of bytes, at the beginning of the argument, that must be
4856 put in registers. 0 is the argument is entirely in registers or entirely
4860 ia64_arg_partial_bytes (cumulative_args_t cum_v
, enum machine_mode mode
,
4861 tree type
, bool named ATTRIBUTE_UNUSED
)
4863 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
4865 int words
= ia64_function_arg_words (type
, mode
);
4866 int offset
= ia64_function_arg_offset (cum
, type
, words
);
4868 /* If all argument slots are used, then it must go on the stack. */
4869 if (cum
->words
+ offset
>= MAX_ARGUMENT_SLOTS
)
4872 /* It doesn't matter whether the argument goes in FR or GR regs. If
4873 it fits within the 8 argument slots, then it goes entirely in
4874 registers. If it extends past the last argument slot, then the rest
4875 goes on the stack. */
4877 if (words
+ cum
->words
+ offset
<= MAX_ARGUMENT_SLOTS
)
4880 return (MAX_ARGUMENT_SLOTS
- cum
->words
- offset
) * UNITS_PER_WORD
;
4883 /* Return ivms_arg_type based on machine_mode. */
4885 static enum ivms_arg_type
4886 ia64_arg_type (enum machine_mode mode
)
4899 /* Update CUM to point after this argument. This is patterned after
4900 ia64_function_arg. */
4903 ia64_function_arg_advance (cumulative_args_t cum_v
, enum machine_mode mode
,
4904 const_tree type
, bool named
)
4906 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
4907 int words
= ia64_function_arg_words (type
, mode
);
4908 int offset
= ia64_function_arg_offset (cum
, type
, words
);
4909 enum machine_mode hfa_mode
= VOIDmode
;
4911 /* If all arg slots are already full, then there is nothing to do. */
4912 if (cum
->words
>= MAX_ARGUMENT_SLOTS
)
4914 cum
->words
+= words
+ offset
;
4918 cum
->atypes
[cum
->words
] = ia64_arg_type (mode
);
4919 cum
->words
+= words
+ offset
;
4921 /* On OpenVMS argument is either in Rn or Fn. */
4922 if (TARGET_ABI_OPEN_VMS
)
4924 cum
->int_regs
= cum
->words
;
4925 cum
->fp_regs
= cum
->words
;
4929 /* Check for and handle homogeneous FP aggregates. */
4931 hfa_mode
= hfa_element_mode (type
, 0);
4933 /* Unnamed prototyped hfas are passed as usual. Named prototyped hfas
4934 and unprototyped hfas are passed specially. */
4935 if (hfa_mode
!= VOIDmode
&& (! cum
->prototype
|| named
))
4937 int fp_regs
= cum
->fp_regs
;
4938 /* This is the original value of cum->words + offset. */
4939 int int_regs
= cum
->words
- words
;
4940 int hfa_size
= GET_MODE_SIZE (hfa_mode
);
4944 /* If prototyped, pass it in FR regs then GR regs.
4945 If not prototyped, pass it in both FR and GR regs.
4947 If this is an SFmode aggregate, then it is possible to run out of
4948 FR regs while GR regs are still left. In that case, we pass the
4949 remaining part in the GR regs. */
4951 /* Fill the FP regs. We do this always. We stop if we reach the end
4952 of the argument, the last FP register, or the last argument slot. */
4954 byte_size
= ((mode
== BLKmode
)
4955 ? int_size_in_bytes (type
) : GET_MODE_SIZE (mode
));
4956 args_byte_size
= int_regs
* UNITS_PER_WORD
;
4958 for (; (offset
< byte_size
&& fp_regs
< MAX_ARGUMENT_SLOTS
4959 && args_byte_size
< (MAX_ARGUMENT_SLOTS
* UNITS_PER_WORD
));)
4962 args_byte_size
+= hfa_size
;
4966 cum
->fp_regs
= fp_regs
;
4969 /* Integral and aggregates go in general registers. So do TFmode FP values.
4970 If we have run out of FR registers, then other FP values must also go in
4971 general registers. This can happen when we have a SFmode HFA. */
4972 else if (mode
== TFmode
|| mode
== TCmode
4973 || (! FLOAT_MODE_P (mode
) || cum
->fp_regs
== MAX_ARGUMENT_SLOTS
))
4974 cum
->int_regs
= cum
->words
;
4976 /* If there is a prototype, then FP values go in a FR register when
4977 named, and in a GR register when unnamed. */
4978 else if (cum
->prototype
)
4981 cum
->int_regs
= cum
->words
;
4983 /* ??? Complex types should not reach here. */
4984 cum
->fp_regs
+= (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
? 2 : 1);
4986 /* If there is no prototype, then FP values go in both FR and GR
4990 /* ??? Complex types should not reach here. */
4991 cum
->fp_regs
+= (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
? 2 : 1);
4992 cum
->int_regs
= cum
->words
;
4996 /* Arguments with alignment larger than 8 bytes start at the next even
4997 boundary. On ILP32 HPUX, TFmode arguments start on next even boundary
4998 even though their normal alignment is 8 bytes. See ia64_function_arg. */
5001 ia64_function_arg_boundary (enum machine_mode mode
, const_tree type
)
5003 if (mode
== TFmode
&& TARGET_HPUX
&& TARGET_ILP32
)
5004 return PARM_BOUNDARY
* 2;
5008 if (TYPE_ALIGN (type
) > PARM_BOUNDARY
)
5009 return PARM_BOUNDARY
* 2;
5011 return PARM_BOUNDARY
;
5014 if (GET_MODE_BITSIZE (mode
) > PARM_BOUNDARY
)
5015 return PARM_BOUNDARY
* 2;
5017 return PARM_BOUNDARY
;
5020 /* True if it is OK to do sibling call optimization for the specified
5021 call expression EXP. DECL will be the called function, or NULL if
5022 this is an indirect call. */
5024 ia64_function_ok_for_sibcall (tree decl
, tree exp ATTRIBUTE_UNUSED
)
5026 /* We can't perform a sibcall if the current function has the syscall_linkage
5028 if (lookup_attribute ("syscall_linkage",
5029 TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl
))))
5032 /* We must always return with our current GP. This means we can
5033 only sibcall to functions defined in the current module unless
5034 TARGET_CONST_GP is set to true. */
5035 return (decl
&& (*targetm
.binds_local_p
) (decl
)) || TARGET_CONST_GP
;
5039 /* Implement va_arg. */
5042 ia64_gimplify_va_arg (tree valist
, tree type
, gimple_seq
*pre_p
,
5045 /* Variable sized types are passed by reference. */
5046 if (pass_by_reference (NULL
, TYPE_MODE (type
), type
, false))
5048 tree ptrtype
= build_pointer_type (type
);
5049 tree addr
= std_gimplify_va_arg_expr (valist
, ptrtype
, pre_p
, post_p
);
5050 return build_va_arg_indirect_ref (addr
);
5053 /* Aggregate arguments with alignment larger than 8 bytes start at
5054 the next even boundary. Integer and floating point arguments
5055 do so if they are larger than 8 bytes, whether or not they are
5056 also aligned larger than 8 bytes. */
5057 if ((TREE_CODE (type
) == REAL_TYPE
|| TREE_CODE (type
) == INTEGER_TYPE
)
5058 ? int_size_in_bytes (type
) > 8 : TYPE_ALIGN (type
) > 8 * BITS_PER_UNIT
)
5060 tree t
= fold_build_pointer_plus_hwi (valist
, 2 * UNITS_PER_WORD
- 1);
5061 t
= build2 (BIT_AND_EXPR
, TREE_TYPE (t
), t
,
5062 build_int_cst (TREE_TYPE (t
), -2 * UNITS_PER_WORD
));
5063 gimplify_assign (unshare_expr (valist
), t
, pre_p
);
5066 return std_gimplify_va_arg_expr (valist
, type
, pre_p
, post_p
);
5069 /* Return 1 if function return value returned in memory. Return 0 if it is
5073 ia64_return_in_memory (const_tree valtype
, const_tree fntype ATTRIBUTE_UNUSED
)
5075 enum machine_mode mode
;
5076 enum machine_mode hfa_mode
;
5077 HOST_WIDE_INT byte_size
;
5079 mode
= TYPE_MODE (valtype
);
5080 byte_size
= GET_MODE_SIZE (mode
);
5081 if (mode
== BLKmode
)
5083 byte_size
= int_size_in_bytes (valtype
);
5088 /* Hfa's with up to 8 elements are returned in the FP argument registers. */
5090 hfa_mode
= hfa_element_mode (valtype
, 0);
5091 if (hfa_mode
!= VOIDmode
)
5093 int hfa_size
= GET_MODE_SIZE (hfa_mode
);
5095 if (byte_size
/ hfa_size
> MAX_ARGUMENT_SLOTS
)
5100 else if (byte_size
> UNITS_PER_WORD
* MAX_INT_RETURN_SLOTS
)
5106 /* Return rtx for register that holds the function return value. */
5109 ia64_function_value (const_tree valtype
,
5110 const_tree fn_decl_or_type
,
5111 bool outgoing ATTRIBUTE_UNUSED
)
5113 enum machine_mode mode
;
5114 enum machine_mode hfa_mode
;
5116 const_tree func
= fn_decl_or_type
;
5119 && !DECL_P (fn_decl_or_type
))
5122 mode
= TYPE_MODE (valtype
);
5123 hfa_mode
= hfa_element_mode (valtype
, 0);
5125 if (hfa_mode
!= VOIDmode
)
5133 hfa_size
= GET_MODE_SIZE (hfa_mode
);
5134 byte_size
= ((mode
== BLKmode
)
5135 ? int_size_in_bytes (valtype
) : GET_MODE_SIZE (mode
));
5137 for (i
= 0; offset
< byte_size
; i
++)
5139 loc
[i
] = gen_rtx_EXPR_LIST (VOIDmode
,
5140 gen_rtx_REG (hfa_mode
, FR_ARG_FIRST
+ i
),
5144 return gen_rtx_PARALLEL (mode
, gen_rtvec_v (i
, loc
));
5146 else if (FLOAT_TYPE_P (valtype
) && mode
!= TFmode
&& mode
!= TCmode
)
5147 return gen_rtx_REG (mode
, FR_ARG_FIRST
);
5150 bool need_parallel
= false;
5152 /* In big-endian mode, we need to manage the layout of aggregates
5153 in the registers so that we get the bits properly aligned in
5154 the highpart of the registers. */
5155 if (BYTES_BIG_ENDIAN
5156 && (mode
== BLKmode
|| (valtype
&& AGGREGATE_TYPE_P (valtype
))))
5157 need_parallel
= true;
5159 /* Something like struct S { long double x; char a[0] } is not an
5160 HFA structure, and therefore doesn't go in fp registers. But
5161 the middle-end will give it XFmode anyway, and XFmode values
5162 don't normally fit in integer registers. So we need to smuggle
5163 the value inside a parallel. */
5164 else if (mode
== XFmode
|| mode
== XCmode
|| mode
== RFmode
)
5165 need_parallel
= true;
5175 bytesize
= int_size_in_bytes (valtype
);
5176 /* An empty PARALLEL is invalid here, but the return value
5177 doesn't matter for empty structs. */
5179 return gen_rtx_REG (mode
, GR_RET_FIRST
);
5180 for (i
= 0; offset
< bytesize
; i
++)
5182 loc
[i
] = gen_rtx_EXPR_LIST (VOIDmode
,
5183 gen_rtx_REG (DImode
,
5186 offset
+= UNITS_PER_WORD
;
5188 return gen_rtx_PARALLEL (mode
, gen_rtvec_v (i
, loc
));
5191 mode
= promote_function_mode (valtype
, mode
, &unsignedp
,
5192 func
? TREE_TYPE (func
) : NULL_TREE
,
5195 return gen_rtx_REG (mode
, GR_RET_FIRST
);
5199 /* Worker function for TARGET_LIBCALL_VALUE. */
5202 ia64_libcall_value (enum machine_mode mode
,
5203 const_rtx fun ATTRIBUTE_UNUSED
)
5205 return gen_rtx_REG (mode
,
5206 (((GET_MODE_CLASS (mode
) == MODE_FLOAT
5207 || GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
5208 && (mode
) != TFmode
)
5209 ? FR_RET_FIRST
: GR_RET_FIRST
));
5212 /* Worker function for FUNCTION_VALUE_REGNO_P. */
5215 ia64_function_value_regno_p (const unsigned int regno
)
5217 return ((regno
>= GR_RET_FIRST
&& regno
<= GR_RET_LAST
)
5218 || (regno
>= FR_RET_FIRST
&& regno
<= FR_RET_LAST
));
5221 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
5222 We need to emit DTP-relative relocations. */
5225 ia64_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
5227 gcc_assert (size
== 4 || size
== 8);
5229 fputs ("\tdata4.ua\t@dtprel(", file
);
5231 fputs ("\tdata8.ua\t@dtprel(", file
);
5232 output_addr_const (file
, x
);
5236 /* Print a memory address as an operand to reference that memory location. */
5238 /* ??? Do we need this? It gets used only for 'a' operands. We could perhaps
5239 also call this from ia64_print_operand for memory addresses. */
5242 ia64_print_operand_address (FILE * stream ATTRIBUTE_UNUSED
,
5243 rtx address ATTRIBUTE_UNUSED
)
5247 /* Print an operand to an assembler instruction.
5248 C Swap and print a comparison operator.
5249 D Print an FP comparison operator.
5250 E Print 32 - constant, for SImode shifts as extract.
5251 e Print 64 - constant, for DImode rotates.
5252 F A floating point constant 0.0 emitted as f0, or 1.0 emitted as f1, or
5253 a floating point register emitted normally.
5254 G A floating point constant.
5255 I Invert a predicate register by adding 1.
5256 J Select the proper predicate register for a condition.
5257 j Select the inverse predicate register for a condition.
5258 O Append .acq for volatile load.
5259 P Postincrement of a MEM.
5260 Q Append .rel for volatile store.
5261 R Print .s .d or nothing for a single, double or no truncation.
5262 S Shift amount for shladd instruction.
5263 T Print an 8-bit sign extended number (K) as a 32-bit unsigned number
5264 for Intel assembler.
5265 U Print an 8-bit sign extended number (K) as a 64-bit unsigned number
5266 for Intel assembler.
5267 X A pair of floating point registers.
5268 r Print register name, or constant 0 as r0. HP compatibility for
5270 v Print vector constant value as an 8-byte integer value. */
5273 ia64_print_operand (FILE * file
, rtx x
, int code
)
5280 /* Handled below. */
5285 enum rtx_code c
= swap_condition (GET_CODE (x
));
5286 fputs (GET_RTX_NAME (c
), file
);
5291 switch (GET_CODE (x
))
5318 str
= GET_RTX_NAME (GET_CODE (x
));
5325 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, 32 - INTVAL (x
));
5329 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, 64 - INTVAL (x
));
5333 if (x
== CONST0_RTX (GET_MODE (x
)))
5334 str
= reg_names
[FR_REG (0)];
5335 else if (x
== CONST1_RTX (GET_MODE (x
)))
5336 str
= reg_names
[FR_REG (1)];
5339 gcc_assert (GET_CODE (x
) == REG
);
5340 str
= reg_names
[REGNO (x
)];
5349 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
5350 real_to_target (val
, &rv
, GET_MODE (x
));
5351 if (GET_MODE (x
) == SFmode
)
5352 fprintf (file
, "0x%08lx", val
[0] & 0xffffffff);
5353 else if (GET_MODE (x
) == DFmode
)
5354 fprintf (file
, "0x%08lx%08lx", (WORDS_BIG_ENDIAN
? val
[0] : val
[1])
5356 (WORDS_BIG_ENDIAN
? val
[1] : val
[0])
5359 output_operand_lossage ("invalid %%G mode");
5364 fputs (reg_names
[REGNO (x
) + 1], file
);
5370 unsigned int regno
= REGNO (XEXP (x
, 0));
5371 if (GET_CODE (x
) == EQ
)
5375 fputs (reg_names
[regno
], file
);
5380 if (MEM_VOLATILE_P (x
))
5381 fputs(".acq", file
);
5386 HOST_WIDE_INT value
;
5388 switch (GET_CODE (XEXP (x
, 0)))
5394 x
= XEXP (XEXP (XEXP (x
, 0), 1), 1);
5395 if (GET_CODE (x
) == CONST_INT
)
5399 gcc_assert (GET_CODE (x
) == REG
);
5400 fprintf (file
, ", %s", reg_names
[REGNO (x
)]);
5406 value
= GET_MODE_SIZE (GET_MODE (x
));
5410 value
= - (HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (x
));
5414 fprintf (file
, ", " HOST_WIDE_INT_PRINT_DEC
, value
);
5419 if (MEM_VOLATILE_P (x
))
5420 fputs(".rel", file
);
5424 if (x
== CONST0_RTX (GET_MODE (x
)))
5426 else if (x
== CONST1_RTX (GET_MODE (x
)))
5428 else if (x
== CONST2_RTX (GET_MODE (x
)))
5431 output_operand_lossage ("invalid %%R value");
5435 fprintf (file
, "%d", exact_log2 (INTVAL (x
)));
5439 if (! TARGET_GNU_AS
&& GET_CODE (x
) == CONST_INT
)
5441 fprintf (file
, "0x%x", (int) INTVAL (x
) & 0xffffffff);
5447 if (! TARGET_GNU_AS
&& GET_CODE (x
) == CONST_INT
)
5449 const char *prefix
= "0x";
5450 if (INTVAL (x
) & 0x80000000)
5452 fprintf (file
, "0xffffffff");
5455 fprintf (file
, "%s%x", prefix
, (int) INTVAL (x
) & 0xffffffff);
5462 unsigned int regno
= REGNO (x
);
5463 fprintf (file
, "%s, %s", reg_names
[regno
], reg_names
[regno
+ 1]);
5468 /* If this operand is the constant zero, write it as register zero.
5469 Any register, zero, or CONST_INT value is OK here. */
5470 if (GET_CODE (x
) == REG
)
5471 fputs (reg_names
[REGNO (x
)], file
);
5472 else if (x
== CONST0_RTX (GET_MODE (x
)))
5474 else if (GET_CODE (x
) == CONST_INT
)
5475 output_addr_const (file
, x
);
5477 output_operand_lossage ("invalid %%r value");
5481 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
5482 x
= simplify_subreg (DImode
, x
, GET_MODE (x
), 0);
5489 /* For conditional branches, returns or calls, substitute
5490 sptk, dptk, dpnt, or spnt for %s. */
5491 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
5494 int pred_val
= XINT (x
, 0);
5496 /* Guess top and bottom 10% statically predicted. */
5497 if (pred_val
< REG_BR_PROB_BASE
/ 50
5498 && br_prob_note_reliable_p (x
))
5500 else if (pred_val
< REG_BR_PROB_BASE
/ 2)
5502 else if (pred_val
< REG_BR_PROB_BASE
/ 100 * 98
5503 || !br_prob_note_reliable_p (x
))
5508 else if (CALL_P (current_output_insn
))
5513 fputs (which
, file
);
5518 x
= current_insn_predicate
;
5521 unsigned int regno
= REGNO (XEXP (x
, 0));
5522 if (GET_CODE (x
) == EQ
)
5524 fprintf (file
, "(%s) ", reg_names
[regno
]);
5529 output_operand_lossage ("ia64_print_operand: unknown code");
5533 switch (GET_CODE (x
))
5535 /* This happens for the spill/restore instructions. */
5540 /* ... fall through ... */
5543 fputs (reg_names
[REGNO (x
)], file
);
5548 rtx addr
= XEXP (x
, 0);
5549 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
5550 addr
= XEXP (addr
, 0);
5551 fprintf (file
, "[%s]", reg_names
[REGNO (addr
)]);
5556 output_addr_const (file
, x
);
5563 /* Worker function for TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
5566 ia64_print_operand_punct_valid_p (unsigned char code
)
5568 return (code
== '+' || code
== ',');
5571 /* Compute a (partial) cost for rtx X. Return true if the complete
5572 cost has been computed, and false if subexpressions should be
5573 scanned. In either case, *TOTAL contains the cost result. */
5574 /* ??? This is incomplete. */
5577 ia64_rtx_costs (rtx x
, int code
, int outer_code
, int opno ATTRIBUTE_UNUSED
,
5578 int *total
, bool speed ATTRIBUTE_UNUSED
)
5586 *total
= satisfies_constraint_J (x
) ? 0 : COSTS_N_INSNS (1);
5589 if (satisfies_constraint_I (x
))
5591 else if (satisfies_constraint_J (x
))
5594 *total
= COSTS_N_INSNS (1);
5597 if (satisfies_constraint_K (x
) || satisfies_constraint_L (x
))
5600 *total
= COSTS_N_INSNS (1);
5605 *total
= COSTS_N_INSNS (1);
5611 *total
= COSTS_N_INSNS (3);
5615 *total
= COSTS_N_INSNS (4);
5619 /* For multiplies wider than HImode, we have to go to the FPU,
5620 which normally involves copies. Plus there's the latency
5621 of the multiply itself, and the latency of the instructions to
5622 transfer integer regs to FP regs. */
5623 if (FLOAT_MODE_P (GET_MODE (x
)))
5624 *total
= COSTS_N_INSNS (4);
5625 else if (GET_MODE_SIZE (GET_MODE (x
)) > 2)
5626 *total
= COSTS_N_INSNS (10);
5628 *total
= COSTS_N_INSNS (2);
5633 if (FLOAT_MODE_P (GET_MODE (x
)))
5635 *total
= COSTS_N_INSNS (4);
5643 *total
= COSTS_N_INSNS (1);
5650 /* We make divide expensive, so that divide-by-constant will be
5651 optimized to a multiply. */
5652 *total
= COSTS_N_INSNS (60);
5660 /* Calculate the cost of moving data from a register in class FROM to
5661 one in class TO, using MODE. */
5664 ia64_register_move_cost (enum machine_mode mode
, reg_class_t from
,
5667 /* ADDL_REGS is the same as GR_REGS for movement purposes. */
5668 if (to
== ADDL_REGS
)
5670 if (from
== ADDL_REGS
)
5673 /* All costs are symmetric, so reduce cases by putting the
5674 lower number class as the destination. */
5677 reg_class_t tmp
= to
;
5678 to
= from
, from
= tmp
;
5681 /* Moving from FR<->GR in XFmode must be more expensive than 2,
5682 so that we get secondary memory reloads. Between FR_REGS,
5683 we have to make this at least as expensive as memory_move_cost
5684 to avoid spectacularly poor register class preferencing. */
5685 if (mode
== XFmode
|| mode
== RFmode
)
5687 if (to
!= GR_REGS
|| from
!= GR_REGS
)
5688 return memory_move_cost (mode
, to
, false);
5696 /* Moving between PR registers takes two insns. */
5697 if (from
== PR_REGS
)
5699 /* Moving between PR and anything but GR is impossible. */
5700 if (from
!= GR_REGS
)
5701 return memory_move_cost (mode
, to
, false);
5705 /* Moving between BR and anything but GR is impossible. */
5706 if (from
!= GR_REGS
&& from
!= GR_AND_BR_REGS
)
5707 return memory_move_cost (mode
, to
, false);
5712 /* Moving between AR and anything but GR is impossible. */
5713 if (from
!= GR_REGS
)
5714 return memory_move_cost (mode
, to
, false);
5720 case GR_AND_FR_REGS
:
5721 case GR_AND_BR_REGS
:
5732 /* Calculate the cost of moving data of MODE from a register to or from
5736 ia64_memory_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
5738 bool in ATTRIBUTE_UNUSED
)
5740 if (rclass
== GENERAL_REGS
5741 || rclass
== FR_REGS
5742 || rclass
== FP_REGS
5743 || rclass
== GR_AND_FR_REGS
)
5749 /* Implement TARGET_PREFERRED_RELOAD_CLASS. Place additional restrictions
5750 on RCLASS to use when copying X into that class. */
5753 ia64_preferred_reload_class (rtx x
, reg_class_t rclass
)
5759 /* Don't allow volatile mem reloads into floating point registers.
5760 This is defined to force reload to choose the r/m case instead
5761 of the f/f case when reloading (set (reg fX) (mem/v)). */
5762 if (MEM_P (x
) && MEM_VOLATILE_P (x
))
5765 /* Force all unrecognized constants into the constant pool. */
5783 /* This function returns the register class required for a secondary
5784 register when copying between one of the registers in RCLASS, and X,
5785 using MODE. A return value of NO_REGS means that no secondary register
5789 ia64_secondary_reload_class (enum reg_class rclass
,
5790 enum machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
5794 if (GET_CODE (x
) == REG
|| GET_CODE (x
) == SUBREG
)
5795 regno
= true_regnum (x
);
5802 /* ??? BR<->BR register copies can happen due to a bad gcse/cse/global
5803 interaction. We end up with two pseudos with overlapping lifetimes
5804 both of which are equiv to the same constant, and both which need
5805 to be in BR_REGS. This seems to be a cse bug. cse_basic_block_end
5806 changes depending on the path length, which means the qty_first_reg
5807 check in make_regs_eqv can give different answers at different times.
5808 At some point I'll probably need a reload_indi pattern to handle
5811 We can also get GR_AND_FR_REGS to BR_REGS/AR_REGS copies, where we
5812 wound up with a FP register from GR_AND_FR_REGS. Extend that to all
5813 non-general registers for good measure. */
5814 if (regno
>= 0 && ! GENERAL_REGNO_P (regno
))
5817 /* This is needed if a pseudo used as a call_operand gets spilled to a
5819 if (GET_CODE (x
) == MEM
)
5825 /* Need to go through general registers to get to other class regs. */
5826 if (regno
>= 0 && ! (FR_REGNO_P (regno
) || GENERAL_REGNO_P (regno
)))
5829 /* This can happen when a paradoxical subreg is an operand to the
5831 /* ??? This shouldn't be necessary after instruction scheduling is
5832 enabled, because paradoxical subregs are not accepted by
5833 register_operand when INSN_SCHEDULING is defined. Or alternatively,
5834 stop the paradoxical subreg stupidity in the *_operand functions
5836 if (GET_CODE (x
) == MEM
5837 && (GET_MODE (x
) == SImode
|| GET_MODE (x
) == HImode
5838 || GET_MODE (x
) == QImode
))
5841 /* This can happen because of the ior/and/etc patterns that accept FP
5842 registers as operands. If the third operand is a constant, then it
5843 needs to be reloaded into a FP register. */
5844 if (GET_CODE (x
) == CONST_INT
)
5847 /* This can happen because of register elimination in a muldi3 insn.
5848 E.g. `26107 * (unsigned long)&u'. */
5849 if (GET_CODE (x
) == PLUS
)
5854 /* ??? This happens if we cse/gcse a BImode value across a call,
5855 and the function has a nonlocal goto. This is because global
5856 does not allocate call crossing pseudos to hard registers when
5857 crtl->has_nonlocal_goto is true. This is relatively
5858 common for C++ programs that use exceptions. To reproduce,
5859 return NO_REGS and compile libstdc++. */
5860 if (GET_CODE (x
) == MEM
)
5863 /* This can happen when we take a BImode subreg of a DImode value,
5864 and that DImode value winds up in some non-GR register. */
5865 if (regno
>= 0 && ! GENERAL_REGNO_P (regno
) && ! PR_REGNO_P (regno
))
5877 /* Implement targetm.unspec_may_trap_p hook. */
5879 ia64_unspec_may_trap_p (const_rtx x
, unsigned flags
)
5881 switch (XINT (x
, 1))
5887 case UNSPEC_CHKACLR
:
5889 /* These unspecs are just wrappers. */
5890 return may_trap_p_1 (XVECEXP (x
, 0, 0), flags
);
5893 return default_unspec_may_trap_p (x
, flags
);
5897 /* Parse the -mfixed-range= option string. */
5900 fix_range (const char *const_str
)
5903 char *str
, *dash
, *comma
;
5905 /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
5906 REG2 are either register names or register numbers. The effect
5907 of this option is to mark the registers in the range from REG1 to
5908 REG2 as ``fixed'' so they won't be used by the compiler. This is
5909 used, e.g., to ensure that kernel mode code doesn't use f32-f127. */
5911 i
= strlen (const_str
);
5912 str
= (char *) alloca (i
+ 1);
5913 memcpy (str
, const_str
, i
+ 1);
5917 dash
= strchr (str
, '-');
5920 warning (0, "value of -mfixed-range must have form REG1-REG2");
5925 comma
= strchr (dash
+ 1, ',');
5929 first
= decode_reg_name (str
);
5932 warning (0, "unknown register name: %s", str
);
5936 last
= decode_reg_name (dash
+ 1);
5939 warning (0, "unknown register name: %s", dash
+ 1);
5947 warning (0, "%s-%s is an empty range", str
, dash
+ 1);
5951 for (i
= first
; i
<= last
; ++i
)
5952 fixed_regs
[i
] = call_used_regs
[i
] = 1;
5962 /* Implement TARGET_OPTION_OVERRIDE. */
5965 ia64_option_override (void)
5968 cl_deferred_option
*opt
;
5969 vec
<cl_deferred_option
> *v
5970 = (vec
<cl_deferred_option
> *) ia64_deferred_options
;
5973 FOR_EACH_VEC_ELT (*v
, i
, opt
)
5975 switch (opt
->opt_index
)
5977 case OPT_mfixed_range_
:
5978 fix_range (opt
->arg
);
5986 if (TARGET_AUTO_PIC
)
5987 target_flags
|= MASK_CONST_GP
;
5989 /* Numerous experiment shows that IRA based loop pressure
5990 calculation works better for RTL loop invariant motion on targets
5991 with enough (>= 32) registers. It is an expensive optimization.
5992 So it is on only for peak performance. */
5994 flag_ira_loop_pressure
= 1;
5997 ia64_section_threshold
= (global_options_set
.x_g_switch_value
5999 : IA64_DEFAULT_GVALUE
);
6001 init_machine_status
= ia64_init_machine_status
;
6003 if (align_functions
<= 0)
6004 align_functions
= 64;
6005 if (align_loops
<= 0)
6007 if (TARGET_ABI_OPEN_VMS
)
6010 ia64_override_options_after_change();
6013 /* Implement targetm.override_options_after_change. */
6016 ia64_override_options_after_change (void)
6019 && !global_options_set
.x_flag_selective_scheduling
6020 && !global_options_set
.x_flag_selective_scheduling2
)
6022 flag_selective_scheduling2
= 1;
6023 flag_sel_sched_pipelining
= 1;
6025 if (mflag_sched_control_spec
== 2)
6027 /* Control speculation is on by default for the selective scheduler,
6028 but not for the Haifa scheduler. */
6029 mflag_sched_control_spec
= flag_selective_scheduling2
? 1 : 0;
6031 if (flag_sel_sched_pipelining
&& flag_auto_inc_dec
)
6033 /* FIXME: remove this when we'd implement breaking autoinsns as
6034 a transformation. */
6035 flag_auto_inc_dec
= 0;
6039 /* Initialize the record of emitted frame related registers. */
6041 void ia64_init_expanders (void)
6043 memset (&emitted_frame_related_regs
, 0, sizeof (emitted_frame_related_regs
));
6046 static struct machine_function
*
6047 ia64_init_machine_status (void)
6049 return ggc_cleared_alloc
<machine_function
> ();
6052 static enum attr_itanium_class
ia64_safe_itanium_class (rtx
);
6053 static enum attr_type
ia64_safe_type (rtx
);
6055 static enum attr_itanium_class
6056 ia64_safe_itanium_class (rtx insn
)
6058 if (recog_memoized (insn
) >= 0)
6059 return get_attr_itanium_class (insn
);
6060 else if (DEBUG_INSN_P (insn
))
6061 return ITANIUM_CLASS_IGNORE
;
6063 return ITANIUM_CLASS_UNKNOWN
;
6066 static enum attr_type
6067 ia64_safe_type (rtx insn
)
6069 if (recog_memoized (insn
) >= 0)
6070 return get_attr_type (insn
);
6072 return TYPE_UNKNOWN
;
6075 /* The following collection of routines emit instruction group stop bits as
6076 necessary to avoid dependencies. */
6078 /* Need to track some additional registers as far as serialization is
6079 concerned so we can properly handle br.call and br.ret. We could
6080 make these registers visible to gcc, but since these registers are
6081 never explicitly used in gcc generated code, it seems wasteful to
6082 do so (plus it would make the call and return patterns needlessly
6084 #define REG_RP (BR_REG (0))
6085 #define REG_AR_CFM (FIRST_PSEUDO_REGISTER + 1)
6086 /* This is used for volatile asms which may require a stop bit immediately
6087 before and after them. */
6088 #define REG_VOLATILE (FIRST_PSEUDO_REGISTER + 2)
6089 #define AR_UNAT_BIT_0 (FIRST_PSEUDO_REGISTER + 3)
6090 #define NUM_REGS (AR_UNAT_BIT_0 + 64)
6092 /* For each register, we keep track of how it has been written in the
6093 current instruction group.
6095 If a register is written unconditionally (no qualifying predicate),
6096 WRITE_COUNT is set to 2 and FIRST_PRED is ignored.
6098 If a register is written if its qualifying predicate P is true, we
6099 set WRITE_COUNT to 1 and FIRST_PRED to P. Later on, the same register
6100 may be written again by the complement of P (P^1) and when this happens,
6101 WRITE_COUNT gets set to 2.
6103 The result of this is that whenever an insn attempts to write a register
6104 whose WRITE_COUNT is two, we need to issue an insn group barrier first.
6106 If a predicate register is written by a floating-point insn, we set
6107 WRITTEN_BY_FP to true.
6109 If a predicate register is written by an AND.ORCM we set WRITTEN_BY_AND
6110 to true; if it was written by an OR.ANDCM we set WRITTEN_BY_OR to true. */
6112 #if GCC_VERSION >= 4000
6113 #define RWS_FIELD_TYPE __extension__ unsigned short
6115 #define RWS_FIELD_TYPE unsigned int
6117 struct reg_write_state
6119 RWS_FIELD_TYPE write_count
: 2;
6120 RWS_FIELD_TYPE first_pred
: 10;
6121 RWS_FIELD_TYPE written_by_fp
: 1;
6122 RWS_FIELD_TYPE written_by_and
: 1;
6123 RWS_FIELD_TYPE written_by_or
: 1;
6126 /* Cumulative info for the current instruction group. */
6127 struct reg_write_state rws_sum
[NUM_REGS
];
6128 #ifdef ENABLE_CHECKING
6129 /* Bitmap whether a register has been written in the current insn. */
6130 HARD_REG_ELT_TYPE rws_insn
[(NUM_REGS
+ HOST_BITS_PER_WIDEST_FAST_INT
- 1)
6131 / HOST_BITS_PER_WIDEST_FAST_INT
];
6134 rws_insn_set (int regno
)
6136 gcc_assert (!TEST_HARD_REG_BIT (rws_insn
, regno
));
6137 SET_HARD_REG_BIT (rws_insn
, regno
);
6141 rws_insn_test (int regno
)
6143 return TEST_HARD_REG_BIT (rws_insn
, regno
);
6146 /* When not checking, track just REG_AR_CFM and REG_VOLATILE. */
6147 unsigned char rws_insn
[2];
6150 rws_insn_set (int regno
)
6152 if (regno
== REG_AR_CFM
)
6154 else if (regno
== REG_VOLATILE
)
6159 rws_insn_test (int regno
)
6161 if (regno
== REG_AR_CFM
)
6163 if (regno
== REG_VOLATILE
)
6169 /* Indicates whether this is the first instruction after a stop bit,
6170 in which case we don't need another stop bit. Without this,
6171 ia64_variable_issue will die when scheduling an alloc. */
6172 static int first_instruction
;
6174 /* Misc flags needed to compute RAW/WAW dependencies while we are traversing
6175 RTL for one instruction. */
6178 unsigned int is_write
: 1; /* Is register being written? */
6179 unsigned int is_fp
: 1; /* Is register used as part of an fp op? */
6180 unsigned int is_branch
: 1; /* Is register used as part of a branch? */
6181 unsigned int is_and
: 1; /* Is register used as part of and.orcm? */
6182 unsigned int is_or
: 1; /* Is register used as part of or.andcm? */
6183 unsigned int is_sibcall
: 1; /* Is this a sibling or normal call? */
6186 static void rws_update (int, struct reg_flags
, int);
6187 static int rws_access_regno (int, struct reg_flags
, int);
6188 static int rws_access_reg (rtx
, struct reg_flags
, int);
6189 static void update_set_flags (rtx
, struct reg_flags
*);
6190 static int set_src_needs_barrier (rtx
, struct reg_flags
, int);
6191 static int rtx_needs_barrier (rtx
, struct reg_flags
, int);
6192 static void init_insn_group_barriers (void);
6193 static int group_barrier_needed (rtx
);
6194 static int safe_group_barrier_needed (rtx
);
6195 static int in_safe_group_barrier
;
6197 /* Update *RWS for REGNO, which is being written by the current instruction,
6198 with predicate PRED, and associated register flags in FLAGS. */
6201 rws_update (int regno
, struct reg_flags flags
, int pred
)
6204 rws_sum
[regno
].write_count
++;
6206 rws_sum
[regno
].write_count
= 2;
6207 rws_sum
[regno
].written_by_fp
|= flags
.is_fp
;
6208 /* ??? Not tracking and/or across differing predicates. */
6209 rws_sum
[regno
].written_by_and
= flags
.is_and
;
6210 rws_sum
[regno
].written_by_or
= flags
.is_or
;
6211 rws_sum
[regno
].first_pred
= pred
;
6214 /* Handle an access to register REGNO of type FLAGS using predicate register
6215 PRED. Update rws_sum array. Return 1 if this access creates
6216 a dependency with an earlier instruction in the same group. */
6219 rws_access_regno (int regno
, struct reg_flags flags
, int pred
)
6221 int need_barrier
= 0;
6223 gcc_assert (regno
< NUM_REGS
);
6225 if (! PR_REGNO_P (regno
))
6226 flags
.is_and
= flags
.is_or
= 0;
6232 rws_insn_set (regno
);
6233 write_count
= rws_sum
[regno
].write_count
;
6235 switch (write_count
)
6238 /* The register has not been written yet. */
6239 if (!in_safe_group_barrier
)
6240 rws_update (regno
, flags
, pred
);
6244 /* The register has been written via a predicate. Treat
6245 it like a unconditional write and do not try to check
6246 for complementary pred reg in earlier write. */
6247 if (flags
.is_and
&& rws_sum
[regno
].written_by_and
)
6249 else if (flags
.is_or
&& rws_sum
[regno
].written_by_or
)
6253 if (!in_safe_group_barrier
)
6254 rws_update (regno
, flags
, pred
);
6258 /* The register has been unconditionally written already. We
6260 if (flags
.is_and
&& rws_sum
[regno
].written_by_and
)
6262 else if (flags
.is_or
&& rws_sum
[regno
].written_by_or
)
6266 if (!in_safe_group_barrier
)
6268 rws_sum
[regno
].written_by_and
= flags
.is_and
;
6269 rws_sum
[regno
].written_by_or
= flags
.is_or
;
6279 if (flags
.is_branch
)
6281 /* Branches have several RAW exceptions that allow to avoid
6284 if (REGNO_REG_CLASS (regno
) == BR_REGS
|| regno
== AR_PFS_REGNUM
)
6285 /* RAW dependencies on branch regs are permissible as long
6286 as the writer is a non-branch instruction. Since we
6287 never generate code that uses a branch register written
6288 by a branch instruction, handling this case is
6292 if (REGNO_REG_CLASS (regno
) == PR_REGS
6293 && ! rws_sum
[regno
].written_by_fp
)
6294 /* The predicates of a branch are available within the
6295 same insn group as long as the predicate was written by
6296 something other than a floating-point instruction. */
6300 if (flags
.is_and
&& rws_sum
[regno
].written_by_and
)
6302 if (flags
.is_or
&& rws_sum
[regno
].written_by_or
)
6305 switch (rws_sum
[regno
].write_count
)
6308 /* The register has not been written yet. */
6312 /* The register has been written via a predicate, assume we
6313 need a barrier (don't check for complementary regs). */
6318 /* The register has been unconditionally written already. We
6328 return need_barrier
;
6332 rws_access_reg (rtx reg
, struct reg_flags flags
, int pred
)
6334 int regno
= REGNO (reg
);
6335 int n
= HARD_REGNO_NREGS (REGNO (reg
), GET_MODE (reg
));
6338 return rws_access_regno (regno
, flags
, pred
);
6341 int need_barrier
= 0;
6343 need_barrier
|= rws_access_regno (regno
+ n
, flags
, pred
);
6344 return need_barrier
;
6348 /* Examine X, which is a SET rtx, and update the flags, the predicate, and
6349 the condition, stored in *PFLAGS, *PPRED and *PCOND. */
6352 update_set_flags (rtx x
, struct reg_flags
*pflags
)
6354 rtx src
= SET_SRC (x
);
6356 switch (GET_CODE (src
))
6362 /* There are four cases here:
6363 (1) The destination is (pc), in which case this is a branch,
6364 nothing here applies.
6365 (2) The destination is ar.lc, in which case this is a
6366 doloop_end_internal,
6367 (3) The destination is an fp register, in which case this is
6368 an fselect instruction.
6369 (4) The condition has (unspec [(reg)] UNSPEC_LDC), in which case
6370 this is a check load.
6371 In all cases, nothing we do in this function applies. */
6375 if (COMPARISON_P (src
)
6376 && SCALAR_FLOAT_MODE_P (GET_MODE (XEXP (src
, 0))))
6377 /* Set pflags->is_fp to 1 so that we know we're dealing
6378 with a floating point comparison when processing the
6379 destination of the SET. */
6382 /* Discover if this is a parallel comparison. We only handle
6383 and.orcm and or.andcm at present, since we must retain a
6384 strict inverse on the predicate pair. */
6385 else if (GET_CODE (src
) == AND
)
6387 else if (GET_CODE (src
) == IOR
)
6394 /* Subroutine of rtx_needs_barrier; this function determines whether the
6395 source of a given SET rtx found in X needs a barrier. FLAGS and PRED
6396 are as in rtx_needs_barrier. COND is an rtx that holds the condition
6400 set_src_needs_barrier (rtx x
, struct reg_flags flags
, int pred
)
6402 int need_barrier
= 0;
6404 rtx src
= SET_SRC (x
);
6406 if (GET_CODE (src
) == CALL
)
6407 /* We don't need to worry about the result registers that
6408 get written by subroutine call. */
6409 return rtx_needs_barrier (src
, flags
, pred
);
6410 else if (SET_DEST (x
) == pc_rtx
)
6412 /* X is a conditional branch. */
6413 /* ??? This seems redundant, as the caller sets this bit for
6415 if (!ia64_spec_check_src_p (src
))
6416 flags
.is_branch
= 1;
6417 return rtx_needs_barrier (src
, flags
, pred
);
6420 if (ia64_spec_check_src_p (src
))
6421 /* Avoid checking one register twice (in condition
6422 and in 'then' section) for ldc pattern. */
6424 gcc_assert (REG_P (XEXP (src
, 2)));
6425 need_barrier
= rtx_needs_barrier (XEXP (src
, 2), flags
, pred
);
6427 /* We process MEM below. */
6428 src
= XEXP (src
, 1);
6431 need_barrier
|= rtx_needs_barrier (src
, flags
, pred
);
6434 if (GET_CODE (dst
) == ZERO_EXTRACT
)
6436 need_barrier
|= rtx_needs_barrier (XEXP (dst
, 1), flags
, pred
);
6437 need_barrier
|= rtx_needs_barrier (XEXP (dst
, 2), flags
, pred
);
6439 return need_barrier
;
6442 /* Handle an access to rtx X of type FLAGS using predicate register
6443 PRED. Return 1 if this access creates a dependency with an earlier
6444 instruction in the same group. */
6447 rtx_needs_barrier (rtx x
, struct reg_flags flags
, int pred
)
6450 int is_complemented
= 0;
6451 int need_barrier
= 0;
6452 const char *format_ptr
;
6453 struct reg_flags new_flags
;
6461 switch (GET_CODE (x
))
6464 update_set_flags (x
, &new_flags
);
6465 need_barrier
= set_src_needs_barrier (x
, new_flags
, pred
);
6466 if (GET_CODE (SET_SRC (x
)) != CALL
)
6468 new_flags
.is_write
= 1;
6469 need_barrier
|= rtx_needs_barrier (SET_DEST (x
), new_flags
, pred
);
6474 new_flags
.is_write
= 0;
6475 need_barrier
|= rws_access_regno (AR_EC_REGNUM
, new_flags
, pred
);
6477 /* Avoid multiple register writes, in case this is a pattern with
6478 multiple CALL rtx. This avoids a failure in rws_access_reg. */
6479 if (! flags
.is_sibcall
&& ! rws_insn_test (REG_AR_CFM
))
6481 new_flags
.is_write
= 1;
6482 need_barrier
|= rws_access_regno (REG_RP
, new_flags
, pred
);
6483 need_barrier
|= rws_access_regno (AR_PFS_REGNUM
, new_flags
, pred
);
6484 need_barrier
|= rws_access_regno (REG_AR_CFM
, new_flags
, pred
);
6489 /* X is a predicated instruction. */
6491 cond
= COND_EXEC_TEST (x
);
6493 need_barrier
= rtx_needs_barrier (cond
, flags
, 0);
6495 if (GET_CODE (cond
) == EQ
)
6496 is_complemented
= 1;
6497 cond
= XEXP (cond
, 0);
6498 gcc_assert (GET_CODE (cond
) == REG
6499 && REGNO_REG_CLASS (REGNO (cond
)) == PR_REGS
);
6500 pred
= REGNO (cond
);
6501 if (is_complemented
)
6504 need_barrier
|= rtx_needs_barrier (COND_EXEC_CODE (x
), flags
, pred
);
6505 return need_barrier
;
6509 /* Clobber & use are for earlier compiler-phases only. */
6514 /* We always emit stop bits for traditional asms. We emit stop bits
6515 for volatile extended asms if TARGET_VOL_ASM_STOP is true. */
6516 if (GET_CODE (x
) != ASM_OPERANDS
6517 || (MEM_VOLATILE_P (x
) && TARGET_VOL_ASM_STOP
))
6519 /* Avoid writing the register multiple times if we have multiple
6520 asm outputs. This avoids a failure in rws_access_reg. */
6521 if (! rws_insn_test (REG_VOLATILE
))
6523 new_flags
.is_write
= 1;
6524 rws_access_regno (REG_VOLATILE
, new_flags
, pred
);
6529 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
6530 We cannot just fall through here since then we would be confused
6531 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
6532 traditional asms unlike their normal usage. */
6534 for (i
= ASM_OPERANDS_INPUT_LENGTH (x
) - 1; i
>= 0; --i
)
6535 if (rtx_needs_barrier (ASM_OPERANDS_INPUT (x
, i
), flags
, pred
))
6540 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; --i
)
6542 rtx pat
= XVECEXP (x
, 0, i
);
6543 switch (GET_CODE (pat
))
6546 update_set_flags (pat
, &new_flags
);
6547 need_barrier
|= set_src_needs_barrier (pat
, new_flags
, pred
);
6553 need_barrier
|= rtx_needs_barrier (pat
, flags
, pred
);
6557 if (REG_P (XEXP (pat
, 0))
6558 && extract_asm_operands (x
) != NULL_RTX
6559 && REGNO (XEXP (pat
, 0)) != AR_UNAT_REGNUM
)
6561 new_flags
.is_write
= 1;
6562 need_barrier
|= rtx_needs_barrier (XEXP (pat
, 0),
6575 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; --i
)
6577 rtx pat
= XVECEXP (x
, 0, i
);
6578 if (GET_CODE (pat
) == SET
)
6580 if (GET_CODE (SET_SRC (pat
)) != CALL
)
6582 new_flags
.is_write
= 1;
6583 need_barrier
|= rtx_needs_barrier (SET_DEST (pat
), new_flags
,
6587 else if (GET_CODE (pat
) == CLOBBER
|| GET_CODE (pat
) == RETURN
)
6588 need_barrier
|= rtx_needs_barrier (pat
, flags
, pred
);
6593 need_barrier
|= rtx_needs_barrier (SUBREG_REG (x
), flags
, pred
);
6596 if (REGNO (x
) == AR_UNAT_REGNUM
)
6598 for (i
= 0; i
< 64; ++i
)
6599 need_barrier
|= rws_access_regno (AR_UNAT_BIT_0
+ i
, flags
, pred
);
6602 need_barrier
= rws_access_reg (x
, flags
, pred
);
6606 /* Find the regs used in memory address computation. */
6607 new_flags
.is_write
= 0;
6608 need_barrier
= rtx_needs_barrier (XEXP (x
, 0), new_flags
, pred
);
6611 case CONST_INT
: case CONST_DOUBLE
: case CONST_VECTOR
:
6612 case SYMBOL_REF
: case LABEL_REF
: case CONST
:
6615 /* Operators with side-effects. */
6616 case POST_INC
: case POST_DEC
:
6617 gcc_assert (GET_CODE (XEXP (x
, 0)) == REG
);
6619 new_flags
.is_write
= 0;
6620 need_barrier
= rws_access_reg (XEXP (x
, 0), new_flags
, pred
);
6621 new_flags
.is_write
= 1;
6622 need_barrier
|= rws_access_reg (XEXP (x
, 0), new_flags
, pred
);
6626 gcc_assert (GET_CODE (XEXP (x
, 0)) == REG
);
6628 new_flags
.is_write
= 0;
6629 need_barrier
= rws_access_reg (XEXP (x
, 0), new_flags
, pred
);
6630 need_barrier
|= rtx_needs_barrier (XEXP (x
, 1), new_flags
, pred
);
6631 new_flags
.is_write
= 1;
6632 need_barrier
|= rws_access_reg (XEXP (x
, 0), new_flags
, pred
);
6635 /* Handle common unary and binary ops for efficiency. */
6636 case COMPARE
: case PLUS
: case MINUS
: case MULT
: case DIV
:
6637 case MOD
: case UDIV
: case UMOD
: case AND
: case IOR
:
6638 case XOR
: case ASHIFT
: case ROTATE
: case ASHIFTRT
: case LSHIFTRT
:
6639 case ROTATERT
: case SMIN
: case SMAX
: case UMIN
: case UMAX
:
6640 case NE
: case EQ
: case GE
: case GT
: case LE
:
6641 case LT
: case GEU
: case GTU
: case LEU
: case LTU
:
6642 need_barrier
= rtx_needs_barrier (XEXP (x
, 0), new_flags
, pred
);
6643 need_barrier
|= rtx_needs_barrier (XEXP (x
, 1), new_flags
, pred
);
6646 case NEG
: case NOT
: case SIGN_EXTEND
: case ZERO_EXTEND
:
6647 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
: case FLOAT
:
6648 case FIX
: case UNSIGNED_FLOAT
: case UNSIGNED_FIX
: case ABS
:
6649 case SQRT
: case FFS
: case POPCOUNT
:
6650 need_barrier
= rtx_needs_barrier (XEXP (x
, 0), flags
, pred
);
6654 /* VEC_SELECT's second argument is a PARALLEL with integers that
6655 describe the elements selected. On ia64, those integers are
6656 always constants. Avoid walking the PARALLEL so that we don't
6657 get confused with "normal" parallels and then die. */
6658 need_barrier
= rtx_needs_barrier (XEXP (x
, 0), flags
, pred
);
6662 switch (XINT (x
, 1))
6664 case UNSPEC_LTOFF_DTPMOD
:
6665 case UNSPEC_LTOFF_DTPREL
:
6667 case UNSPEC_LTOFF_TPREL
:
6669 case UNSPEC_PRED_REL_MUTEX
:
6670 case UNSPEC_PIC_CALL
:
6672 case UNSPEC_FETCHADD_ACQ
:
6673 case UNSPEC_FETCHADD_REL
:
6674 case UNSPEC_BSP_VALUE
:
6675 case UNSPEC_FLUSHRS
:
6676 case UNSPEC_BUNDLE_SELECTOR
:
6679 case UNSPEC_GR_SPILL
:
6680 case UNSPEC_GR_RESTORE
:
6682 HOST_WIDE_INT offset
= INTVAL (XVECEXP (x
, 0, 1));
6683 HOST_WIDE_INT bit
= (offset
>> 3) & 63;
6685 need_barrier
= rtx_needs_barrier (XVECEXP (x
, 0, 0), flags
, pred
);
6686 new_flags
.is_write
= (XINT (x
, 1) == UNSPEC_GR_SPILL
);
6687 need_barrier
|= rws_access_regno (AR_UNAT_BIT_0
+ bit
,
6692 case UNSPEC_FR_SPILL
:
6693 case UNSPEC_FR_RESTORE
:
6694 case UNSPEC_GETF_EXP
:
6695 case UNSPEC_SETF_EXP
:
6697 case UNSPEC_FR_SQRT_RECIP_APPROX
:
6698 case UNSPEC_FR_SQRT_RECIP_APPROX_RES
:
6703 case UNSPEC_CHKACLR
:
6705 need_barrier
= rtx_needs_barrier (XVECEXP (x
, 0, 0), flags
, pred
);
6708 case UNSPEC_FR_RECIP_APPROX
:
6710 case UNSPEC_COPYSIGN
:
6711 case UNSPEC_FR_RECIP_APPROX_RES
:
6712 need_barrier
= rtx_needs_barrier (XVECEXP (x
, 0, 0), flags
, pred
);
6713 need_barrier
|= rtx_needs_barrier (XVECEXP (x
, 0, 1), flags
, pred
);
6716 case UNSPEC_CMPXCHG_ACQ
:
6717 case UNSPEC_CMPXCHG_REL
:
6718 need_barrier
= rtx_needs_barrier (XVECEXP (x
, 0, 1), flags
, pred
);
6719 need_barrier
|= rtx_needs_barrier (XVECEXP (x
, 0, 2), flags
, pred
);
6727 case UNSPEC_VOLATILE
:
6728 switch (XINT (x
, 1))
6731 /* Alloc must always be the first instruction of a group.
6732 We force this by always returning true. */
6733 /* ??? We might get better scheduling if we explicitly check for
6734 input/local/output register dependencies, and modify the
6735 scheduler so that alloc is always reordered to the start of
6736 the current group. We could then eliminate all of the
6737 first_instruction code. */
6738 rws_access_regno (AR_PFS_REGNUM
, flags
, pred
);
6740 new_flags
.is_write
= 1;
6741 rws_access_regno (REG_AR_CFM
, new_flags
, pred
);
6744 case UNSPECV_SET_BSP
:
6745 case UNSPECV_PROBE_STACK_RANGE
:
6749 case UNSPECV_BLOCKAGE
:
6750 case UNSPECV_INSN_GROUP_BARRIER
:
6752 case UNSPECV_PSAC_ALL
:
6753 case UNSPECV_PSAC_NORMAL
:
6756 case UNSPECV_PROBE_STACK_ADDRESS
:
6757 need_barrier
= rtx_needs_barrier (XVECEXP (x
, 0, 0), flags
, pred
);
6766 new_flags
.is_write
= 0;
6767 need_barrier
= rws_access_regno (REG_RP
, flags
, pred
);
6768 need_barrier
|= rws_access_regno (AR_PFS_REGNUM
, flags
, pred
);
6770 new_flags
.is_write
= 1;
6771 need_barrier
|= rws_access_regno (AR_EC_REGNUM
, new_flags
, pred
);
6772 need_barrier
|= rws_access_regno (REG_AR_CFM
, new_flags
, pred
);
6776 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
6777 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
6778 switch (format_ptr
[i
])
6780 case '0': /* unused field */
6781 case 'i': /* integer */
6782 case 'n': /* note */
6783 case 'w': /* wide integer */
6784 case 's': /* pointer to string */
6785 case 'S': /* optional pointer to string */
6789 if (rtx_needs_barrier (XEXP (x
, i
), flags
, pred
))
6794 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; --j
)
6795 if (rtx_needs_barrier (XVECEXP (x
, i
, j
), flags
, pred
))
6804 return need_barrier
;
6807 /* Clear out the state for group_barrier_needed at the start of a
6808 sequence of insns. */
6811 init_insn_group_barriers (void)
6813 memset (rws_sum
, 0, sizeof (rws_sum
));
6814 first_instruction
= 1;
6817 /* Given the current state, determine whether a group barrier (a stop bit) is
6818 necessary before INSN. Return nonzero if so. This modifies the state to
6819 include the effects of INSN as a side-effect. */
6822 group_barrier_needed (rtx insn
)
6825 int need_barrier
= 0;
6826 struct reg_flags flags
;
6828 memset (&flags
, 0, sizeof (flags
));
6829 switch (GET_CODE (insn
))
6836 /* A barrier doesn't imply an instruction group boundary. */
6840 memset (rws_insn
, 0, sizeof (rws_insn
));
6844 flags
.is_branch
= 1;
6845 flags
.is_sibcall
= SIBLING_CALL_P (insn
);
6846 memset (rws_insn
, 0, sizeof (rws_insn
));
6848 /* Don't bundle a call following another call. */
6849 if ((pat
= prev_active_insn (insn
)) && CALL_P (pat
))
6855 need_barrier
= rtx_needs_barrier (PATTERN (insn
), flags
, 0);
6859 if (!ia64_spec_check_p (insn
))
6860 flags
.is_branch
= 1;
6862 /* Don't bundle a jump following a call. */
6863 if ((pat
= prev_active_insn (insn
)) && CALL_P (pat
))
6871 if (GET_CODE (PATTERN (insn
)) == USE
6872 || GET_CODE (PATTERN (insn
)) == CLOBBER
)
6873 /* Don't care about USE and CLOBBER "insns"---those are used to
6874 indicate to the optimizer that it shouldn't get rid of
6875 certain operations. */
6878 pat
= PATTERN (insn
);
6880 /* Ug. Hack hacks hacked elsewhere. */
6881 switch (recog_memoized (insn
))
6883 /* We play dependency tricks with the epilogue in order
6884 to get proper schedules. Undo this for dv analysis. */
6885 case CODE_FOR_epilogue_deallocate_stack
:
6886 case CODE_FOR_prologue_allocate_stack
:
6887 pat
= XVECEXP (pat
, 0, 0);
6890 /* The pattern we use for br.cloop confuses the code above.
6891 The second element of the vector is representative. */
6892 case CODE_FOR_doloop_end_internal
:
6893 pat
= XVECEXP (pat
, 0, 1);
6896 /* Doesn't generate code. */
6897 case CODE_FOR_pred_rel_mutex
:
6898 case CODE_FOR_prologue_use
:
6905 memset (rws_insn
, 0, sizeof (rws_insn
));
6906 need_barrier
= rtx_needs_barrier (pat
, flags
, 0);
6908 /* Check to see if the previous instruction was a volatile
6911 need_barrier
= rws_access_regno (REG_VOLATILE
, flags
, 0);
6919 if (first_instruction
&& important_for_bundling_p (insn
))
6922 first_instruction
= 0;
6925 return need_barrier
;
6928 /* Like group_barrier_needed, but do not clobber the current state. */
6931 safe_group_barrier_needed (rtx insn
)
6933 int saved_first_instruction
;
6936 saved_first_instruction
= first_instruction
;
6937 in_safe_group_barrier
= 1;
6939 t
= group_barrier_needed (insn
);
6941 first_instruction
= saved_first_instruction
;
6942 in_safe_group_barrier
= 0;
6947 /* Scan the current function and insert stop bits as necessary to
6948 eliminate dependencies. This function assumes that a final
6949 instruction scheduling pass has been run which has already
6950 inserted most of the necessary stop bits. This function only
6951 inserts new ones at basic block boundaries, since these are
6952 invisible to the scheduler. */
6955 emit_insn_group_barriers (FILE *dump
)
6958 rtx_insn
*last_label
= 0;
6959 int insns_since_last_label
= 0;
6961 init_insn_group_barriers ();
6963 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6967 if (insns_since_last_label
)
6969 insns_since_last_label
= 0;
6971 else if (NOTE_P (insn
)
6972 && NOTE_KIND (insn
) == NOTE_INSN_BASIC_BLOCK
)
6974 if (insns_since_last_label
)
6976 insns_since_last_label
= 0;
6978 else if (NONJUMP_INSN_P (insn
)
6979 && GET_CODE (PATTERN (insn
)) == UNSPEC_VOLATILE
6980 && XINT (PATTERN (insn
), 1) == UNSPECV_INSN_GROUP_BARRIER
)
6982 init_insn_group_barriers ();
6985 else if (NONDEBUG_INSN_P (insn
))
6987 insns_since_last_label
= 1;
6989 if (group_barrier_needed (insn
))
6994 fprintf (dump
, "Emitting stop before label %d\n",
6995 INSN_UID (last_label
));
6996 emit_insn_before (gen_insn_group_barrier (GEN_INT (3)), last_label
);
6999 init_insn_group_barriers ();
7007 /* Like emit_insn_group_barriers, but run if no final scheduling pass was run.
7008 This function has to emit all necessary group barriers. */
7011 emit_all_insn_group_barriers (FILE *dump ATTRIBUTE_UNUSED
)
7015 init_insn_group_barriers ();
7017 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
7019 if (BARRIER_P (insn
))
7021 rtx_insn
*last
= prev_active_insn (insn
);
7025 if (JUMP_TABLE_DATA_P (last
))
7026 last
= prev_active_insn (last
);
7027 if (recog_memoized (last
) != CODE_FOR_insn_group_barrier
)
7028 emit_insn_after (gen_insn_group_barrier (GEN_INT (3)), last
);
7030 init_insn_group_barriers ();
7032 else if (NONDEBUG_INSN_P (insn
))
7034 if (recog_memoized (insn
) == CODE_FOR_insn_group_barrier
)
7035 init_insn_group_barriers ();
7036 else if (group_barrier_needed (insn
))
7038 emit_insn_before (gen_insn_group_barrier (GEN_INT (3)), insn
);
7039 init_insn_group_barriers ();
7040 group_barrier_needed (insn
);
7048 /* Instruction scheduling support. */
7050 #define NR_BUNDLES 10
7052 /* A list of names of all available bundles. */
7054 static const char *bundle_name
[NR_BUNDLES
] =
7060 #if NR_BUNDLES == 10
7070 /* Nonzero if we should insert stop bits into the schedule. */
7072 int ia64_final_schedule
= 0;
7074 /* Codes of the corresponding queried units: */
7076 static int _0mii_
, _0mmi_
, _0mfi_
, _0mmf_
;
7077 static int _0bbb_
, _0mbb_
, _0mib_
, _0mmb_
, _0mfb_
, _0mlx_
;
7079 static int _1mii_
, _1mmi_
, _1mfi_
, _1mmf_
;
7080 static int _1bbb_
, _1mbb_
, _1mib_
, _1mmb_
, _1mfb_
, _1mlx_
;
7082 static int pos_1
, pos_2
, pos_3
, pos_4
, pos_5
, pos_6
;
7084 /* The following variable value is an insn group barrier. */
7086 static rtx_insn
*dfa_stop_insn
;
7088 /* The following variable value is the last issued insn. */
7090 static rtx last_scheduled_insn
;
7092 /* The following variable value is pointer to a DFA state used as
7093 temporary variable. */
7095 static state_t temp_dfa_state
= NULL
;
7097 /* The following variable value is DFA state after issuing the last
7100 static state_t prev_cycle_state
= NULL
;
7102 /* The following array element values are TRUE if the corresponding
7103 insn requires to add stop bits before it. */
7105 static char *stops_p
= NULL
;
7107 /* The following variable is used to set up the mentioned above array. */
7109 static int stop_before_p
= 0;
7111 /* The following variable value is length of the arrays `clocks' and
7114 static int clocks_length
;
7116 /* The following variable value is number of data speculations in progress. */
7117 static int pending_data_specs
= 0;
7119 /* Number of memory references on current and three future processor cycles. */
7120 static char mem_ops_in_group
[4];
7122 /* Number of current processor cycle (from scheduler's point of view). */
7123 static int current_cycle
;
7125 static rtx
ia64_single_set (rtx
);
7126 static void ia64_emit_insn_before (rtx
, rtx
);
7128 /* Map a bundle number to its pseudo-op. */
7131 get_bundle_name (int b
)
7133 return bundle_name
[b
];
7137 /* Return the maximum number of instructions a cpu can issue. */
7140 ia64_issue_rate (void)
7145 /* Helper function - like single_set, but look inside COND_EXEC. */
7148 ia64_single_set (rtx insn
)
7150 rtx x
= PATTERN (insn
), ret
;
7151 if (GET_CODE (x
) == COND_EXEC
)
7152 x
= COND_EXEC_CODE (x
);
7153 if (GET_CODE (x
) == SET
)
7156 /* Special case here prologue_allocate_stack and epilogue_deallocate_stack.
7157 Although they are not classical single set, the second set is there just
7158 to protect it from moving past FP-relative stack accesses. */
7159 switch (recog_memoized (insn
))
7161 case CODE_FOR_prologue_allocate_stack
:
7162 case CODE_FOR_prologue_allocate_stack_pr
:
7163 case CODE_FOR_epilogue_deallocate_stack
:
7164 case CODE_FOR_epilogue_deallocate_stack_pr
:
7165 ret
= XVECEXP (x
, 0, 0);
7169 ret
= single_set_2 (insn
, x
);
7176 /* Adjust the cost of a scheduling dependency.
7177 Return the new cost of a dependency of type DEP_TYPE or INSN on DEP_INSN.
7178 COST is the current cost, DW is dependency weakness. */
7180 ia64_adjust_cost_2 (rtx_insn
*insn
, int dep_type1
, rtx_insn
*dep_insn
,
7183 enum reg_note dep_type
= (enum reg_note
) dep_type1
;
7184 enum attr_itanium_class dep_class
;
7185 enum attr_itanium_class insn_class
;
7187 insn_class
= ia64_safe_itanium_class (insn
);
7188 dep_class
= ia64_safe_itanium_class (dep_insn
);
7190 /* Treat true memory dependencies separately. Ignore apparent true
7191 dependence between store and call (call has a MEM inside a SYMBOL_REF). */
7192 if (dep_type
== REG_DEP_TRUE
7193 && (dep_class
== ITANIUM_CLASS_ST
|| dep_class
== ITANIUM_CLASS_STF
)
7194 && (insn_class
== ITANIUM_CLASS_BR
|| insn_class
== ITANIUM_CLASS_SCALL
))
7197 if (dw
== MIN_DEP_WEAK
)
7198 /* Store and load are likely to alias, use higher cost to avoid stall. */
7199 return PARAM_VALUE (PARAM_SCHED_MEM_TRUE_DEP_COST
);
7200 else if (dw
> MIN_DEP_WEAK
)
7202 /* Store and load are less likely to alias. */
7203 if (mflag_sched_fp_mem_deps_zero_cost
&& dep_class
== ITANIUM_CLASS_STF
)
7204 /* Assume there will be no cache conflict for floating-point data.
7205 For integer data, L1 conflict penalty is huge (17 cycles), so we
7206 never assume it will not cause a conflict. */
7212 if (dep_type
!= REG_DEP_OUTPUT
)
7215 if (dep_class
== ITANIUM_CLASS_ST
|| dep_class
== ITANIUM_CLASS_STF
7216 || insn_class
== ITANIUM_CLASS_ST
|| insn_class
== ITANIUM_CLASS_STF
)
7222 /* Like emit_insn_before, but skip cycle_display notes.
7223 ??? When cycle display notes are implemented, update this. */
7226 ia64_emit_insn_before (rtx insn
, rtx before
)
7228 emit_insn_before (insn
, before
);
7231 /* The following function marks insns who produce addresses for load
7232 and store insns. Such insns will be placed into M slots because it
7233 decrease latency time for Itanium1 (see function
7234 `ia64_produce_address_p' and the DFA descriptions). */
7237 ia64_dependencies_evaluation_hook (rtx_insn
*head
, rtx_insn
*tail
)
7239 rtx_insn
*insn
, *next
, *next_tail
;
7241 /* Before reload, which_alternative is not set, which means that
7242 ia64_safe_itanium_class will produce wrong results for (at least)
7243 move instructions. */
7244 if (!reload_completed
)
7247 next_tail
= NEXT_INSN (tail
);
7248 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
7251 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
7253 && ia64_safe_itanium_class (insn
) == ITANIUM_CLASS_IALU
)
7255 sd_iterator_def sd_it
;
7257 bool has_mem_op_consumer_p
= false;
7259 FOR_EACH_DEP (insn
, SD_LIST_FORW
, sd_it
, dep
)
7261 enum attr_itanium_class c
;
7263 if (DEP_TYPE (dep
) != REG_DEP_TRUE
)
7266 next
= DEP_CON (dep
);
7267 c
= ia64_safe_itanium_class (next
);
7268 if ((c
== ITANIUM_CLASS_ST
7269 || c
== ITANIUM_CLASS_STF
)
7270 && ia64_st_address_bypass_p (insn
, next
))
7272 has_mem_op_consumer_p
= true;
7275 else if ((c
== ITANIUM_CLASS_LD
7276 || c
== ITANIUM_CLASS_FLD
7277 || c
== ITANIUM_CLASS_FLDP
)
7278 && ia64_ld_address_bypass_p (insn
, next
))
7280 has_mem_op_consumer_p
= true;
7285 insn
->call
= has_mem_op_consumer_p
;
7289 /* We're beginning a new block. Initialize data structures as necessary. */
7292 ia64_sched_init (FILE *dump ATTRIBUTE_UNUSED
,
7293 int sched_verbose ATTRIBUTE_UNUSED
,
7294 int max_ready ATTRIBUTE_UNUSED
)
7296 #ifdef ENABLE_CHECKING
7299 if (!sel_sched_p () && reload_completed
)
7300 for (insn
= NEXT_INSN (current_sched_info
->prev_head
);
7301 insn
!= current_sched_info
->next_tail
;
7302 insn
= NEXT_INSN (insn
))
7303 gcc_assert (!SCHED_GROUP_P (insn
));
7305 last_scheduled_insn
= NULL_RTX
;
7306 init_insn_group_barriers ();
7309 memset (mem_ops_in_group
, 0, sizeof (mem_ops_in_group
));
7312 /* We're beginning a scheduling pass. Check assertion. */
7315 ia64_sched_init_global (FILE *dump ATTRIBUTE_UNUSED
,
7316 int sched_verbose ATTRIBUTE_UNUSED
,
7317 int max_ready ATTRIBUTE_UNUSED
)
7319 gcc_assert (pending_data_specs
== 0);
7322 /* Scheduling pass is now finished. Free/reset static variable. */
7324 ia64_sched_finish_global (FILE *dump ATTRIBUTE_UNUSED
,
7325 int sched_verbose ATTRIBUTE_UNUSED
)
7327 gcc_assert (pending_data_specs
== 0);
7330 /* Return TRUE if INSN is a load (either normal or speculative, but not a
7331 speculation check), FALSE otherwise. */
7333 is_load_p (rtx insn
)
7335 enum attr_itanium_class insn_class
= ia64_safe_itanium_class (insn
);
7338 ((insn_class
== ITANIUM_CLASS_LD
|| insn_class
== ITANIUM_CLASS_FLD
)
7339 && get_attr_check_load (insn
) == CHECK_LOAD_NO
);
7342 /* If INSN is a memory reference, memoize it in MEM_OPS_IN_GROUP global array
7343 (taking account for 3-cycle cache reference postponing for stores: Intel
7344 Itanium 2 Reference Manual for Software Development and Optimization,
7347 record_memory_reference (rtx insn
)
7349 enum attr_itanium_class insn_class
= ia64_safe_itanium_class (insn
);
7351 switch (insn_class
) {
7352 case ITANIUM_CLASS_FLD
:
7353 case ITANIUM_CLASS_LD
:
7354 mem_ops_in_group
[current_cycle
% 4]++;
7356 case ITANIUM_CLASS_STF
:
7357 case ITANIUM_CLASS_ST
:
7358 mem_ops_in_group
[(current_cycle
+ 3) % 4]++;
7364 /* We are about to being issuing insns for this clock cycle.
7365 Override the default sort algorithm to better slot instructions. */
7368 ia64_dfa_sched_reorder (FILE *dump
, int sched_verbose
, rtx_insn
**ready
,
7369 int *pn_ready
, int clock_var
,
7373 int n_ready
= *pn_ready
;
7374 rtx_insn
**e_ready
= ready
+ n_ready
;
7378 fprintf (dump
, "// ia64_dfa_sched_reorder (type %d):\n", reorder_type
);
7380 if (reorder_type
== 0)
7382 /* First, move all USEs, CLOBBERs and other crud out of the way. */
7384 for (insnp
= ready
; insnp
< e_ready
; insnp
++)
7385 if (insnp
< e_ready
)
7387 rtx_insn
*insn
= *insnp
;
7388 enum attr_type t
= ia64_safe_type (insn
);
7389 if (t
== TYPE_UNKNOWN
)
7391 if (GET_CODE (PATTERN (insn
)) == ASM_INPUT
7392 || asm_noperands (PATTERN (insn
)) >= 0)
7394 rtx_insn
*lowest
= ready
[n_asms
];
7395 ready
[n_asms
] = insn
;
7401 rtx_insn
*highest
= ready
[n_ready
- 1];
7402 ready
[n_ready
- 1] = insn
;
7409 if (n_asms
< n_ready
)
7411 /* Some normal insns to process. Skip the asms. */
7415 else if (n_ready
> 0)
7419 if (ia64_final_schedule
)
7422 int nr_need_stop
= 0;
7424 for (insnp
= ready
; insnp
< e_ready
; insnp
++)
7425 if (safe_group_barrier_needed (*insnp
))
7428 if (reorder_type
== 1 && n_ready
== nr_need_stop
)
7430 if (reorder_type
== 0)
7433 /* Move down everything that needs a stop bit, preserving
7435 while (insnp
-- > ready
+ deleted
)
7436 while (insnp
>= ready
+ deleted
)
7438 rtx_insn
*insn
= *insnp
;
7439 if (! safe_group_barrier_needed (insn
))
7441 memmove (ready
+ 1, ready
, (insnp
- ready
) * sizeof (rtx
));
7449 current_cycle
= clock_var
;
7450 if (reload_completed
&& mem_ops_in_group
[clock_var
% 4] >= ia64_max_memory_insns
)
7455 /* Move down loads/stores, preserving relative order. */
7456 while (insnp
-- > ready
+ moved
)
7457 while (insnp
>= ready
+ moved
)
7459 rtx_insn
*insn
= *insnp
;
7460 if (! is_load_p (insn
))
7462 memmove (ready
+ 1, ready
, (insnp
- ready
) * sizeof (rtx
));
7473 /* We are about to being issuing insns for this clock cycle. Override
7474 the default sort algorithm to better slot instructions. */
7477 ia64_sched_reorder (FILE *dump
, int sched_verbose
, rtx_insn
**ready
,
7478 int *pn_ready
, int clock_var
)
7480 return ia64_dfa_sched_reorder (dump
, sched_verbose
, ready
,
7481 pn_ready
, clock_var
, 0);
7484 /* Like ia64_sched_reorder, but called after issuing each insn.
7485 Override the default sort algorithm to better slot instructions. */
7488 ia64_sched_reorder2 (FILE *dump ATTRIBUTE_UNUSED
,
7489 int sched_verbose ATTRIBUTE_UNUSED
, rtx_insn
**ready
,
7490 int *pn_ready
, int clock_var
)
7492 return ia64_dfa_sched_reorder (dump
, sched_verbose
, ready
, pn_ready
,
7496 /* We are about to issue INSN. Return the number of insns left on the
7497 ready queue that can be issued this cycle. */
7500 ia64_variable_issue (FILE *dump ATTRIBUTE_UNUSED
,
7501 int sched_verbose ATTRIBUTE_UNUSED
,
7503 int can_issue_more ATTRIBUTE_UNUSED
)
7505 if (sched_deps_info
->generate_spec_deps
&& !sel_sched_p ())
7506 /* Modulo scheduling does not extend h_i_d when emitting
7507 new instructions. Don't use h_i_d, if we don't have to. */
7509 if (DONE_SPEC (insn
) & BEGIN_DATA
)
7510 pending_data_specs
++;
7511 if (CHECK_SPEC (insn
) & BEGIN_DATA
)
7512 pending_data_specs
--;
7515 if (DEBUG_INSN_P (insn
))
7518 last_scheduled_insn
= insn
;
7519 memcpy (prev_cycle_state
, curr_state
, dfa_state_size
);
7520 if (reload_completed
)
7522 int needed
= group_barrier_needed (insn
);
7524 gcc_assert (!needed
);
7526 init_insn_group_barriers ();
7527 stops_p
[INSN_UID (insn
)] = stop_before_p
;
7530 record_memory_reference (insn
);
7535 /* We are choosing insn from the ready queue. Return zero if INSN
7539 ia64_first_cycle_multipass_dfa_lookahead_guard (rtx_insn
*insn
, int ready_index
)
7541 gcc_assert (insn
&& INSN_P (insn
));
7543 /* Size of ALAT is 32. As far as we perform conservative
7544 data speculation, we keep ALAT half-empty. */
7545 if (pending_data_specs
>= 16 && (TODO_SPEC (insn
) & BEGIN_DATA
))
7546 return ready_index
== 0 ? -1 : 1;
7548 if (ready_index
== 0)
7551 if ((!reload_completed
7552 || !safe_group_barrier_needed (insn
))
7553 && (!mflag_sched_mem_insns_hard_limit
7554 || !is_load_p (insn
)
7555 || mem_ops_in_group
[current_cycle
% 4] < ia64_max_memory_insns
))
7561 /* The following variable value is pseudo-insn used by the DFA insn
7562 scheduler to change the DFA state when the simulated clock is
7565 static rtx_insn
*dfa_pre_cycle_insn
;
7567 /* Returns 1 when a meaningful insn was scheduled between the last group
7568 barrier and LAST. */
7570 scheduled_good_insn (rtx last
)
7572 if (last
&& recog_memoized (last
) >= 0)
7576 last
!= NULL
&& !NOTE_INSN_BASIC_BLOCK_P (last
)
7577 && !stops_p
[INSN_UID (last
)];
7578 last
= PREV_INSN (last
))
7579 /* We could hit a NOTE_INSN_DELETED here which is actually outside
7580 the ebb we're scheduling. */
7581 if (INSN_P (last
) && recog_memoized (last
) >= 0)
7587 /* We are about to being issuing INSN. Return nonzero if we cannot
7588 issue it on given cycle CLOCK and return zero if we should not sort
7589 the ready queue on the next clock start. */
7592 ia64_dfa_new_cycle (FILE *dump
, int verbose
, rtx_insn
*insn
, int last_clock
,
7593 int clock
, int *sort_p
)
7595 gcc_assert (insn
&& INSN_P (insn
));
7597 if (DEBUG_INSN_P (insn
))
7600 /* When a group barrier is needed for insn, last_scheduled_insn
7602 gcc_assert (!(reload_completed
&& safe_group_barrier_needed (insn
))
7603 || last_scheduled_insn
);
7605 if ((reload_completed
7606 && (safe_group_barrier_needed (insn
)
7607 || (mflag_sched_stop_bits_after_every_cycle
7608 && last_clock
!= clock
7609 && last_scheduled_insn
7610 && scheduled_good_insn (last_scheduled_insn
))))
7611 || (last_scheduled_insn
7612 && (CALL_P (last_scheduled_insn
)
7613 || unknown_for_bundling_p (last_scheduled_insn
))))
7615 init_insn_group_barriers ();
7617 if (verbose
&& dump
)
7618 fprintf (dump
, "// Stop should be before %d%s\n", INSN_UID (insn
),
7619 last_clock
== clock
? " + cycle advance" : "");
7622 current_cycle
= clock
;
7623 mem_ops_in_group
[current_cycle
% 4] = 0;
7625 if (last_clock
== clock
)
7627 state_transition (curr_state
, dfa_stop_insn
);
7628 if (TARGET_EARLY_STOP_BITS
)
7629 *sort_p
= (last_scheduled_insn
== NULL_RTX
7630 || ! CALL_P (last_scheduled_insn
));
7636 if (last_scheduled_insn
)
7638 if (unknown_for_bundling_p (last_scheduled_insn
))
7639 state_reset (curr_state
);
7642 memcpy (curr_state
, prev_cycle_state
, dfa_state_size
);
7643 state_transition (curr_state
, dfa_stop_insn
);
7644 state_transition (curr_state
, dfa_pre_cycle_insn
);
7645 state_transition (curr_state
, NULL
);
7652 /* Implement targetm.sched.h_i_d_extended hook.
7653 Extend internal data structures. */
7655 ia64_h_i_d_extended (void)
7657 if (stops_p
!= NULL
)
7659 int new_clocks_length
= get_max_uid () * 3 / 2;
7660 stops_p
= (char *) xrecalloc (stops_p
, new_clocks_length
, clocks_length
, 1);
7661 clocks_length
= new_clocks_length
;
7666 /* This structure describes the data used by the backend to guide scheduling.
7667 When the current scheduling point is switched, this data should be saved
7668 and restored later, if the scheduler returns to this point. */
7669 struct _ia64_sched_context
7671 state_t prev_cycle_state
;
7672 rtx last_scheduled_insn
;
7673 struct reg_write_state rws_sum
[NUM_REGS
];
7674 struct reg_write_state rws_insn
[NUM_REGS
];
7675 int first_instruction
;
7676 int pending_data_specs
;
7678 char mem_ops_in_group
[4];
7680 typedef struct _ia64_sched_context
*ia64_sched_context_t
;
7682 /* Allocates a scheduling context. */
7684 ia64_alloc_sched_context (void)
7686 return xmalloc (sizeof (struct _ia64_sched_context
));
7689 /* Initializes the _SC context with clean data, if CLEAN_P, and from
7690 the global context otherwise. */
7692 ia64_init_sched_context (void *_sc
, bool clean_p
)
7694 ia64_sched_context_t sc
= (ia64_sched_context_t
) _sc
;
7696 sc
->prev_cycle_state
= xmalloc (dfa_state_size
);
7699 state_reset (sc
->prev_cycle_state
);
7700 sc
->last_scheduled_insn
= NULL_RTX
;
7701 memset (sc
->rws_sum
, 0, sizeof (rws_sum
));
7702 memset (sc
->rws_insn
, 0, sizeof (rws_insn
));
7703 sc
->first_instruction
= 1;
7704 sc
->pending_data_specs
= 0;
7705 sc
->current_cycle
= 0;
7706 memset (sc
->mem_ops_in_group
, 0, sizeof (mem_ops_in_group
));
7710 memcpy (sc
->prev_cycle_state
, prev_cycle_state
, dfa_state_size
);
7711 sc
->last_scheduled_insn
= last_scheduled_insn
;
7712 memcpy (sc
->rws_sum
, rws_sum
, sizeof (rws_sum
));
7713 memcpy (sc
->rws_insn
, rws_insn
, sizeof (rws_insn
));
7714 sc
->first_instruction
= first_instruction
;
7715 sc
->pending_data_specs
= pending_data_specs
;
7716 sc
->current_cycle
= current_cycle
;
7717 memcpy (sc
->mem_ops_in_group
, mem_ops_in_group
, sizeof (mem_ops_in_group
));
7721 /* Sets the global scheduling context to the one pointed to by _SC. */
7723 ia64_set_sched_context (void *_sc
)
7725 ia64_sched_context_t sc
= (ia64_sched_context_t
) _sc
;
7727 gcc_assert (sc
!= NULL
);
7729 memcpy (prev_cycle_state
, sc
->prev_cycle_state
, dfa_state_size
);
7730 last_scheduled_insn
= sc
->last_scheduled_insn
;
7731 memcpy (rws_sum
, sc
->rws_sum
, sizeof (rws_sum
));
7732 memcpy (rws_insn
, sc
->rws_insn
, sizeof (rws_insn
));
7733 first_instruction
= sc
->first_instruction
;
7734 pending_data_specs
= sc
->pending_data_specs
;
7735 current_cycle
= sc
->current_cycle
;
7736 memcpy (mem_ops_in_group
, sc
->mem_ops_in_group
, sizeof (mem_ops_in_group
));
7739 /* Clears the data in the _SC scheduling context. */
7741 ia64_clear_sched_context (void *_sc
)
7743 ia64_sched_context_t sc
= (ia64_sched_context_t
) _sc
;
7745 free (sc
->prev_cycle_state
);
7746 sc
->prev_cycle_state
= NULL
;
7749 /* Frees the _SC scheduling context. */
7751 ia64_free_sched_context (void *_sc
)
7753 gcc_assert (_sc
!= NULL
);
7758 typedef rtx (* gen_func_t
) (rtx
, rtx
);
7760 /* Return a function that will generate a load of mode MODE_NO
7761 with speculation types TS. */
7763 get_spec_load_gen_function (ds_t ts
, int mode_no
)
7765 static gen_func_t gen_ld_
[] = {
7775 gen_zero_extendqidi2
,
7776 gen_zero_extendhidi2
,
7777 gen_zero_extendsidi2
,
7780 static gen_func_t gen_ld_a
[] = {
7790 gen_zero_extendqidi2_advanced
,
7791 gen_zero_extendhidi2_advanced
,
7792 gen_zero_extendsidi2_advanced
,
7794 static gen_func_t gen_ld_s
[] = {
7795 gen_movbi_speculative
,
7796 gen_movqi_speculative
,
7797 gen_movhi_speculative
,
7798 gen_movsi_speculative
,
7799 gen_movdi_speculative
,
7800 gen_movsf_speculative
,
7801 gen_movdf_speculative
,
7802 gen_movxf_speculative
,
7803 gen_movti_speculative
,
7804 gen_zero_extendqidi2_speculative
,
7805 gen_zero_extendhidi2_speculative
,
7806 gen_zero_extendsidi2_speculative
,
7808 static gen_func_t gen_ld_sa
[] = {
7809 gen_movbi_speculative_advanced
,
7810 gen_movqi_speculative_advanced
,
7811 gen_movhi_speculative_advanced
,
7812 gen_movsi_speculative_advanced
,
7813 gen_movdi_speculative_advanced
,
7814 gen_movsf_speculative_advanced
,
7815 gen_movdf_speculative_advanced
,
7816 gen_movxf_speculative_advanced
,
7817 gen_movti_speculative_advanced
,
7818 gen_zero_extendqidi2_speculative_advanced
,
7819 gen_zero_extendhidi2_speculative_advanced
,
7820 gen_zero_extendsidi2_speculative_advanced
,
7822 static gen_func_t gen_ld_s_a
[] = {
7823 gen_movbi_speculative_a
,
7824 gen_movqi_speculative_a
,
7825 gen_movhi_speculative_a
,
7826 gen_movsi_speculative_a
,
7827 gen_movdi_speculative_a
,
7828 gen_movsf_speculative_a
,
7829 gen_movdf_speculative_a
,
7830 gen_movxf_speculative_a
,
7831 gen_movti_speculative_a
,
7832 gen_zero_extendqidi2_speculative_a
,
7833 gen_zero_extendhidi2_speculative_a
,
7834 gen_zero_extendsidi2_speculative_a
,
7839 if (ts
& BEGIN_DATA
)
7841 if (ts
& BEGIN_CONTROL
)
7846 else if (ts
& BEGIN_CONTROL
)
7848 if ((spec_info
->flags
& SEL_SCHED_SPEC_DONT_CHECK_CONTROL
)
7849 || ia64_needs_block_p (ts
))
7852 gen_ld
= gen_ld_s_a
;
7859 return gen_ld
[mode_no
];
7862 /* Constants that help mapping 'enum machine_mode' to int. */
7865 SPEC_MODE_INVALID
= -1,
7866 SPEC_MODE_FIRST
= 0,
7867 SPEC_MODE_FOR_EXTEND_FIRST
= 1,
7868 SPEC_MODE_FOR_EXTEND_LAST
= 3,
7874 /* Offset to reach ZERO_EXTEND patterns. */
7875 SPEC_GEN_EXTEND_OFFSET
= SPEC_MODE_LAST
- SPEC_MODE_FOR_EXTEND_FIRST
+ 1
7878 /* Return index of the MODE. */
7880 ia64_mode_to_int (enum machine_mode mode
)
7884 case BImode
: return 0; /* SPEC_MODE_FIRST */
7885 case QImode
: return 1; /* SPEC_MODE_FOR_EXTEND_FIRST */
7886 case HImode
: return 2;
7887 case SImode
: return 3; /* SPEC_MODE_FOR_EXTEND_LAST */
7888 case DImode
: return 4;
7889 case SFmode
: return 5;
7890 case DFmode
: return 6;
7891 case XFmode
: return 7;
7893 /* ??? This mode needs testing. Bypasses for ldfp8 instruction are not
7894 mentioned in itanium[12].md. Predicate fp_register_operand also
7895 needs to be defined. Bottom line: better disable for now. */
7896 return SPEC_MODE_INVALID
;
7897 default: return SPEC_MODE_INVALID
;
7901 /* Provide information about speculation capabilities. */
7903 ia64_set_sched_flags (spec_info_t spec_info
)
7905 unsigned int *flags
= &(current_sched_info
->flags
);
7907 if (*flags
& SCHED_RGN
7908 || *flags
& SCHED_EBB
7909 || *flags
& SEL_SCHED
)
7913 if ((mflag_sched_br_data_spec
&& !reload_completed
&& optimize
> 0)
7914 || (mflag_sched_ar_data_spec
&& reload_completed
))
7919 && ((mflag_sched_br_in_data_spec
&& !reload_completed
)
7920 || (mflag_sched_ar_in_data_spec
&& reload_completed
)))
7924 if (mflag_sched_control_spec
7926 || reload_completed
))
7928 mask
|= BEGIN_CONTROL
;
7930 if (!sel_sched_p () && mflag_sched_in_control_spec
)
7931 mask
|= BE_IN_CONTROL
;
7934 spec_info
->mask
= mask
;
7938 *flags
|= USE_DEPS_LIST
| DO_SPECULATION
;
7940 if (mask
& BE_IN_SPEC
)
7943 spec_info
->flags
= 0;
7945 if ((mask
& CONTROL_SPEC
)
7946 && sel_sched_p () && mflag_sel_sched_dont_check_control_spec
)
7947 spec_info
->flags
|= SEL_SCHED_SPEC_DONT_CHECK_CONTROL
;
7949 if (sched_verbose
>= 1)
7950 spec_info
->dump
= sched_dump
;
7952 spec_info
->dump
= 0;
7954 if (mflag_sched_count_spec_in_critical_path
)
7955 spec_info
->flags
|= COUNT_SPEC_IN_CRITICAL_PATH
;
7959 spec_info
->mask
= 0;
7962 /* If INSN is an appropriate load return its mode.
7963 Return -1 otherwise. */
7965 get_mode_no_for_insn (rtx insn
)
7967 rtx reg
, mem
, mode_rtx
;
7971 extract_insn_cached (insn
);
7973 /* We use WHICH_ALTERNATIVE only after reload. This will
7974 guarantee that reload won't touch a speculative insn. */
7976 if (recog_data
.n_operands
!= 2)
7979 reg
= recog_data
.operand
[0];
7980 mem
= recog_data
.operand
[1];
7982 /* We should use MEM's mode since REG's mode in presence of
7983 ZERO_EXTEND will always be DImode. */
7984 if (get_attr_speculable1 (insn
) == SPECULABLE1_YES
)
7985 /* Process non-speculative ld. */
7987 if (!reload_completed
)
7989 /* Do not speculate into regs like ar.lc. */
7990 if (!REG_P (reg
) || AR_REGNO_P (REGNO (reg
)))
7997 rtx mem_reg
= XEXP (mem
, 0);
7999 if (!REG_P (mem_reg
))
8005 else if (get_attr_speculable2 (insn
) == SPECULABLE2_YES
)
8007 gcc_assert (REG_P (reg
) && MEM_P (mem
));
8013 else if (get_attr_data_speculative (insn
) == DATA_SPECULATIVE_YES
8014 || get_attr_control_speculative (insn
) == CONTROL_SPECULATIVE_YES
8015 || get_attr_check_load (insn
) == CHECK_LOAD_YES
)
8016 /* Process speculative ld or ld.c. */
8018 gcc_assert (REG_P (reg
) && MEM_P (mem
));
8023 enum attr_itanium_class attr_class
= get_attr_itanium_class (insn
);
8025 if (attr_class
== ITANIUM_CLASS_CHK_A
8026 || attr_class
== ITANIUM_CLASS_CHK_S_I
8027 || attr_class
== ITANIUM_CLASS_CHK_S_F
)
8034 mode_no
= ia64_mode_to_int (GET_MODE (mode_rtx
));
8036 if (mode_no
== SPEC_MODE_INVALID
)
8039 extend_p
= (GET_MODE (reg
) != GET_MODE (mode_rtx
));
8043 if (!(SPEC_MODE_FOR_EXTEND_FIRST
<= mode_no
8044 && mode_no
<= SPEC_MODE_FOR_EXTEND_LAST
))
8047 mode_no
+= SPEC_GEN_EXTEND_OFFSET
;
8053 /* If X is an unspec part of a speculative load, return its code.
8054 Return -1 otherwise. */
8056 get_spec_unspec_code (const_rtx x
)
8058 if (GET_CODE (x
) != UNSPEC
)
8080 /* Implement skip_rtx_p hook. */
8082 ia64_skip_rtx_p (const_rtx x
)
8084 return get_spec_unspec_code (x
) != -1;
8087 /* If INSN is a speculative load, return its UNSPEC code.
8088 Return -1 otherwise. */
8090 get_insn_spec_code (const_rtx insn
)
8094 pat
= PATTERN (insn
);
8096 if (GET_CODE (pat
) == COND_EXEC
)
8097 pat
= COND_EXEC_CODE (pat
);
8099 if (GET_CODE (pat
) != SET
)
8102 reg
= SET_DEST (pat
);
8106 mem
= SET_SRC (pat
);
8107 if (GET_CODE (mem
) == ZERO_EXTEND
)
8108 mem
= XEXP (mem
, 0);
8110 return get_spec_unspec_code (mem
);
8113 /* If INSN is a speculative load, return a ds with the speculation types.
8114 Otherwise [if INSN is a normal instruction] return 0. */
8116 ia64_get_insn_spec_ds (rtx_insn
*insn
)
8118 int code
= get_insn_spec_code (insn
);
8127 return BEGIN_CONTROL
;
8130 return BEGIN_DATA
| BEGIN_CONTROL
;
8137 /* If INSN is a speculative load return a ds with the speculation types that
8139 Otherwise [if INSN is a normal instruction] return 0. */
8141 ia64_get_insn_checked_ds (rtx_insn
*insn
)
8143 int code
= get_insn_spec_code (insn
);
8148 return BEGIN_DATA
| BEGIN_CONTROL
;
8151 return BEGIN_CONTROL
;
8155 return BEGIN_DATA
| BEGIN_CONTROL
;
8162 /* If GEN_P is true, calculate the index of needed speculation check and return
8163 speculative pattern for INSN with speculative mode TS, machine mode
8164 MODE_NO and with ZERO_EXTEND (if EXTEND_P is true).
8165 If GEN_P is false, just calculate the index of needed speculation check. */
8167 ia64_gen_spec_load (rtx insn
, ds_t ts
, int mode_no
)
8170 gen_func_t gen_load
;
8172 gen_load
= get_spec_load_gen_function (ts
, mode_no
);
8174 new_pat
= gen_load (copy_rtx (recog_data
.operand
[0]),
8175 copy_rtx (recog_data
.operand
[1]));
8177 pat
= PATTERN (insn
);
8178 if (GET_CODE (pat
) == COND_EXEC
)
8179 new_pat
= gen_rtx_COND_EXEC (VOIDmode
, copy_rtx (COND_EXEC_TEST (pat
)),
8186 insn_can_be_in_speculative_p (rtx insn ATTRIBUTE_UNUSED
,
8187 ds_t ds ATTRIBUTE_UNUSED
)
8192 /* Implement targetm.sched.speculate_insn hook.
8193 Check if the INSN can be TS speculative.
8194 If 'no' - return -1.
8195 If 'yes' - generate speculative pattern in the NEW_PAT and return 1.
8196 If current pattern of the INSN already provides TS speculation,
8199 ia64_speculate_insn (rtx_insn
*insn
, ds_t ts
, rtx
*new_pat
)
8204 gcc_assert (!(ts
& ~SPECULATIVE
));
8206 if (ia64_spec_check_p (insn
))
8209 if ((ts
& BE_IN_SPEC
)
8210 && !insn_can_be_in_speculative_p (insn
, ts
))
8213 mode_no
= get_mode_no_for_insn (insn
);
8215 if (mode_no
!= SPEC_MODE_INVALID
)
8217 if (ia64_get_insn_spec_ds (insn
) == ds_get_speculation_types (ts
))
8222 *new_pat
= ia64_gen_spec_load (insn
, ts
, mode_no
);
8231 /* Return a function that will generate a check for speculation TS with mode
8233 If simple check is needed, pass true for SIMPLE_CHECK_P.
8234 If clearing check is needed, pass true for CLEARING_CHECK_P. */
8236 get_spec_check_gen_function (ds_t ts
, int mode_no
,
8237 bool simple_check_p
, bool clearing_check_p
)
8239 static gen_func_t gen_ld_c_clr
[] = {
8249 gen_zero_extendqidi2_clr
,
8250 gen_zero_extendhidi2_clr
,
8251 gen_zero_extendsidi2_clr
,
8253 static gen_func_t gen_ld_c_nc
[] = {
8263 gen_zero_extendqidi2_nc
,
8264 gen_zero_extendhidi2_nc
,
8265 gen_zero_extendsidi2_nc
,
8267 static gen_func_t gen_chk_a_clr
[] = {
8268 gen_advanced_load_check_clr_bi
,
8269 gen_advanced_load_check_clr_qi
,
8270 gen_advanced_load_check_clr_hi
,
8271 gen_advanced_load_check_clr_si
,
8272 gen_advanced_load_check_clr_di
,
8273 gen_advanced_load_check_clr_sf
,
8274 gen_advanced_load_check_clr_df
,
8275 gen_advanced_load_check_clr_xf
,
8276 gen_advanced_load_check_clr_ti
,
8277 gen_advanced_load_check_clr_di
,
8278 gen_advanced_load_check_clr_di
,
8279 gen_advanced_load_check_clr_di
,
8281 static gen_func_t gen_chk_a_nc
[] = {
8282 gen_advanced_load_check_nc_bi
,
8283 gen_advanced_load_check_nc_qi
,
8284 gen_advanced_load_check_nc_hi
,
8285 gen_advanced_load_check_nc_si
,
8286 gen_advanced_load_check_nc_di
,
8287 gen_advanced_load_check_nc_sf
,
8288 gen_advanced_load_check_nc_df
,
8289 gen_advanced_load_check_nc_xf
,
8290 gen_advanced_load_check_nc_ti
,
8291 gen_advanced_load_check_nc_di
,
8292 gen_advanced_load_check_nc_di
,
8293 gen_advanced_load_check_nc_di
,
8295 static gen_func_t gen_chk_s
[] = {
8296 gen_speculation_check_bi
,
8297 gen_speculation_check_qi
,
8298 gen_speculation_check_hi
,
8299 gen_speculation_check_si
,
8300 gen_speculation_check_di
,
8301 gen_speculation_check_sf
,
8302 gen_speculation_check_df
,
8303 gen_speculation_check_xf
,
8304 gen_speculation_check_ti
,
8305 gen_speculation_check_di
,
8306 gen_speculation_check_di
,
8307 gen_speculation_check_di
,
8310 gen_func_t
*gen_check
;
8312 if (ts
& BEGIN_DATA
)
8314 /* We don't need recovery because even if this is ld.sa
8315 ALAT entry will be allocated only if NAT bit is set to zero.
8316 So it is enough to use ld.c here. */
8320 gcc_assert (mflag_sched_spec_ldc
);
8322 if (clearing_check_p
)
8323 gen_check
= gen_ld_c_clr
;
8325 gen_check
= gen_ld_c_nc
;
8329 if (clearing_check_p
)
8330 gen_check
= gen_chk_a_clr
;
8332 gen_check
= gen_chk_a_nc
;
8335 else if (ts
& BEGIN_CONTROL
)
8338 /* We might want to use ld.sa -> ld.c instead of
8341 gcc_assert (!ia64_needs_block_p (ts
));
8343 if (clearing_check_p
)
8344 gen_check
= gen_ld_c_clr
;
8346 gen_check
= gen_ld_c_nc
;
8350 gen_check
= gen_chk_s
;
8356 gcc_assert (mode_no
>= 0);
8357 return gen_check
[mode_no
];
8360 /* Return nonzero, if INSN needs branchy recovery check. */
8362 ia64_needs_block_p (ds_t ts
)
8364 if (ts
& BEGIN_DATA
)
8365 return !mflag_sched_spec_ldc
;
8367 gcc_assert ((ts
& BEGIN_CONTROL
) != 0);
8369 return !(mflag_sched_spec_control_ldc
&& mflag_sched_spec_ldc
);
8372 /* Generate (or regenerate) a recovery check for INSN. */
8374 ia64_gen_spec_check (rtx_insn
*insn
, rtx_insn
*label
, ds_t ds
)
8376 rtx op1
, pat
, check_pat
;
8377 gen_func_t gen_check
;
8380 mode_no
= get_mode_no_for_insn (insn
);
8381 gcc_assert (mode_no
>= 0);
8387 gcc_assert (!ia64_needs_block_p (ds
));
8388 op1
= copy_rtx (recog_data
.operand
[1]);
8391 gen_check
= get_spec_check_gen_function (ds
, mode_no
, label
== NULL_RTX
,
8394 check_pat
= gen_check (copy_rtx (recog_data
.operand
[0]), op1
);
8396 pat
= PATTERN (insn
);
8397 if (GET_CODE (pat
) == COND_EXEC
)
8398 check_pat
= gen_rtx_COND_EXEC (VOIDmode
, copy_rtx (COND_EXEC_TEST (pat
)),
8404 /* Return nonzero, if X is branchy recovery check. */
8406 ia64_spec_check_p (rtx x
)
8409 if (GET_CODE (x
) == COND_EXEC
)
8410 x
= COND_EXEC_CODE (x
);
8411 if (GET_CODE (x
) == SET
)
8412 return ia64_spec_check_src_p (SET_SRC (x
));
8416 /* Return nonzero, if SRC belongs to recovery check. */
8418 ia64_spec_check_src_p (rtx src
)
8420 if (GET_CODE (src
) == IF_THEN_ELSE
)
8425 if (GET_CODE (t
) == NE
)
8429 if (GET_CODE (t
) == UNSPEC
)
8435 if (code
== UNSPEC_LDCCLR
8436 || code
== UNSPEC_LDCNC
8437 || code
== UNSPEC_CHKACLR
8438 || code
== UNSPEC_CHKANC
8439 || code
== UNSPEC_CHKS
)
8441 gcc_assert (code
!= 0);
8451 /* The following page contains abstract data `bundle states' which are
8452 used for bundling insns (inserting nops and template generation). */
8454 /* The following describes state of insn bundling. */
8458 /* Unique bundle state number to identify them in the debugging
8461 rtx insn
; /* corresponding insn, NULL for the 1st and the last state */
8462 /* number nops before and after the insn */
8463 short before_nops_num
, after_nops_num
;
8464 int insn_num
; /* insn number (0 - for initial state, 1 - for the 1st
8466 int cost
; /* cost of the state in cycles */
8467 int accumulated_insns_num
; /* number of all previous insns including
8468 nops. L is considered as 2 insns */
8469 int branch_deviation
; /* deviation of previous branches from 3rd slots */
8470 int middle_bundle_stops
; /* number of stop bits in the middle of bundles */
8471 struct bundle_state
*next
; /* next state with the same insn_num */
8472 struct bundle_state
*originator
; /* originator (previous insn state) */
8473 /* All bundle states are in the following chain. */
8474 struct bundle_state
*allocated_states_chain
;
8475 /* The DFA State after issuing the insn and the nops. */
8479 /* The following is map insn number to the corresponding bundle state. */
8481 static struct bundle_state
**index_to_bundle_states
;
8483 /* The unique number of next bundle state. */
8485 static int bundle_states_num
;
8487 /* All allocated bundle states are in the following chain. */
8489 static struct bundle_state
*allocated_bundle_states_chain
;
8491 /* All allocated but not used bundle states are in the following
8494 static struct bundle_state
*free_bundle_state_chain
;
8497 /* The following function returns a free bundle state. */
8499 static struct bundle_state
*
8500 get_free_bundle_state (void)
8502 struct bundle_state
*result
;
8504 if (free_bundle_state_chain
!= NULL
)
8506 result
= free_bundle_state_chain
;
8507 free_bundle_state_chain
= result
->next
;
8511 result
= XNEW (struct bundle_state
);
8512 result
->dfa_state
= xmalloc (dfa_state_size
);
8513 result
->allocated_states_chain
= allocated_bundle_states_chain
;
8514 allocated_bundle_states_chain
= result
;
8516 result
->unique_num
= bundle_states_num
++;
8521 /* The following function frees given bundle state. */
8524 free_bundle_state (struct bundle_state
*state
)
8526 state
->next
= free_bundle_state_chain
;
8527 free_bundle_state_chain
= state
;
8530 /* Start work with abstract data `bundle states'. */
8533 initiate_bundle_states (void)
8535 bundle_states_num
= 0;
8536 free_bundle_state_chain
= NULL
;
8537 allocated_bundle_states_chain
= NULL
;
8540 /* Finish work with abstract data `bundle states'. */
8543 finish_bundle_states (void)
8545 struct bundle_state
*curr_state
, *next_state
;
8547 for (curr_state
= allocated_bundle_states_chain
;
8549 curr_state
= next_state
)
8551 next_state
= curr_state
->allocated_states_chain
;
8552 free (curr_state
->dfa_state
);
8557 /* Hashtable helpers. */
8559 struct bundle_state_hasher
: typed_noop_remove
<bundle_state
>
8561 typedef bundle_state value_type
;
8562 typedef bundle_state compare_type
;
8563 static inline hashval_t
hash (const value_type
*);
8564 static inline bool equal (const value_type
*, const compare_type
*);
8567 /* The function returns hash of BUNDLE_STATE. */
8570 bundle_state_hasher::hash (const value_type
*state
)
8574 for (result
= i
= 0; i
< dfa_state_size
; i
++)
8575 result
+= (((unsigned char *) state
->dfa_state
) [i
]
8576 << ((i
% CHAR_BIT
) * 3 + CHAR_BIT
));
8577 return result
+ state
->insn_num
;
8580 /* The function returns nonzero if the bundle state keys are equal. */
8583 bundle_state_hasher::equal (const value_type
*state1
,
8584 const compare_type
*state2
)
8586 return (state1
->insn_num
== state2
->insn_num
8587 && memcmp (state1
->dfa_state
, state2
->dfa_state
,
8588 dfa_state_size
) == 0);
8591 /* Hash table of the bundle states. The key is dfa_state and insn_num
8592 of the bundle states. */
8594 static hash_table
<bundle_state_hasher
> *bundle_state_table
;
8596 /* The function inserts the BUNDLE_STATE into the hash table. The
8597 function returns nonzero if the bundle has been inserted into the
8598 table. The table contains the best bundle state with given key. */
8601 insert_bundle_state (struct bundle_state
*bundle_state
)
8603 struct bundle_state
**entry_ptr
;
8605 entry_ptr
= bundle_state_table
->find_slot (bundle_state
, INSERT
);
8606 if (*entry_ptr
== NULL
)
8608 bundle_state
->next
= index_to_bundle_states
[bundle_state
->insn_num
];
8609 index_to_bundle_states
[bundle_state
->insn_num
] = bundle_state
;
8610 *entry_ptr
= bundle_state
;
8613 else if (bundle_state
->cost
< (*entry_ptr
)->cost
8614 || (bundle_state
->cost
== (*entry_ptr
)->cost
8615 && ((*entry_ptr
)->accumulated_insns_num
8616 > bundle_state
->accumulated_insns_num
8617 || ((*entry_ptr
)->accumulated_insns_num
8618 == bundle_state
->accumulated_insns_num
8619 && ((*entry_ptr
)->branch_deviation
8620 > bundle_state
->branch_deviation
8621 || ((*entry_ptr
)->branch_deviation
8622 == bundle_state
->branch_deviation
8623 && (*entry_ptr
)->middle_bundle_stops
8624 > bundle_state
->middle_bundle_stops
))))))
8627 struct bundle_state temp
;
8630 **entry_ptr
= *bundle_state
;
8631 (*entry_ptr
)->next
= temp
.next
;
8632 *bundle_state
= temp
;
8637 /* Start work with the hash table. */
8640 initiate_bundle_state_table (void)
8642 bundle_state_table
= new hash_table
<bundle_state_hasher
> (50);
8645 /* Finish work with the hash table. */
8648 finish_bundle_state_table (void)
8650 delete bundle_state_table
;
8651 bundle_state_table
= NULL
;
8656 /* The following variable is a insn `nop' used to check bundle states
8657 with different number of inserted nops. */
8659 static rtx_insn
*ia64_nop
;
8661 /* The following function tries to issue NOPS_NUM nops for the current
8662 state without advancing processor cycle. If it failed, the
8663 function returns FALSE and frees the current state. */
8666 try_issue_nops (struct bundle_state
*curr_state
, int nops_num
)
8670 for (i
= 0; i
< nops_num
; i
++)
8671 if (state_transition (curr_state
->dfa_state
, ia64_nop
) >= 0)
8673 free_bundle_state (curr_state
);
8679 /* The following function tries to issue INSN for the current
8680 state without advancing processor cycle. If it failed, the
8681 function returns FALSE and frees the current state. */
8684 try_issue_insn (struct bundle_state
*curr_state
, rtx insn
)
8686 if (insn
&& state_transition (curr_state
->dfa_state
, insn
) >= 0)
8688 free_bundle_state (curr_state
);
8694 /* The following function tries to issue BEFORE_NOPS_NUM nops and INSN
8695 starting with ORIGINATOR without advancing processor cycle. If
8696 TRY_BUNDLE_END_P is TRUE, the function also/only (if
8697 ONLY_BUNDLE_END_P is TRUE) tries to issue nops to fill all bundle.
8698 If it was successful, the function creates new bundle state and
8699 insert into the hash table and into `index_to_bundle_states'. */
8702 issue_nops_and_insn (struct bundle_state
*originator
, int before_nops_num
,
8703 rtx insn
, int try_bundle_end_p
, int only_bundle_end_p
)
8705 struct bundle_state
*curr_state
;
8707 curr_state
= get_free_bundle_state ();
8708 memcpy (curr_state
->dfa_state
, originator
->dfa_state
, dfa_state_size
);
8709 curr_state
->insn
= insn
;
8710 curr_state
->insn_num
= originator
->insn_num
+ 1;
8711 curr_state
->cost
= originator
->cost
;
8712 curr_state
->originator
= originator
;
8713 curr_state
->before_nops_num
= before_nops_num
;
8714 curr_state
->after_nops_num
= 0;
8715 curr_state
->accumulated_insns_num
8716 = originator
->accumulated_insns_num
+ before_nops_num
;
8717 curr_state
->branch_deviation
= originator
->branch_deviation
;
8718 curr_state
->middle_bundle_stops
= originator
->middle_bundle_stops
;
8720 if (INSN_CODE (insn
) == CODE_FOR_insn_group_barrier
)
8722 gcc_assert (GET_MODE (insn
) != TImode
);
8723 if (!try_issue_nops (curr_state
, before_nops_num
))
8725 if (!try_issue_insn (curr_state
, insn
))
8727 memcpy (temp_dfa_state
, curr_state
->dfa_state
, dfa_state_size
);
8728 if (curr_state
->accumulated_insns_num
% 3 != 0)
8729 curr_state
->middle_bundle_stops
++;
8730 if (state_transition (temp_dfa_state
, dfa_pre_cycle_insn
) >= 0
8731 && curr_state
->accumulated_insns_num
% 3 != 0)
8733 free_bundle_state (curr_state
);
8737 else if (GET_MODE (insn
) != TImode
)
8739 if (!try_issue_nops (curr_state
, before_nops_num
))
8741 if (!try_issue_insn (curr_state
, insn
))
8743 curr_state
->accumulated_insns_num
++;
8744 gcc_assert (!unknown_for_bundling_p (insn
));
8746 if (ia64_safe_type (insn
) == TYPE_L
)
8747 curr_state
->accumulated_insns_num
++;
8751 /* If this is an insn that must be first in a group, then don't allow
8752 nops to be emitted before it. Currently, alloc is the only such
8753 supported instruction. */
8754 /* ??? The bundling automatons should handle this for us, but they do
8755 not yet have support for the first_insn attribute. */
8756 if (before_nops_num
> 0 && get_attr_first_insn (insn
) == FIRST_INSN_YES
)
8758 free_bundle_state (curr_state
);
8762 state_transition (curr_state
->dfa_state
, dfa_pre_cycle_insn
);
8763 state_transition (curr_state
->dfa_state
, NULL
);
8765 if (!try_issue_nops (curr_state
, before_nops_num
))
8767 if (!try_issue_insn (curr_state
, insn
))
8769 curr_state
->accumulated_insns_num
++;
8770 if (unknown_for_bundling_p (insn
))
8772 /* Finish bundle containing asm insn. */
8773 curr_state
->after_nops_num
8774 = 3 - curr_state
->accumulated_insns_num
% 3;
8775 curr_state
->accumulated_insns_num
8776 += 3 - curr_state
->accumulated_insns_num
% 3;
8778 else if (ia64_safe_type (insn
) == TYPE_L
)
8779 curr_state
->accumulated_insns_num
++;
8781 if (ia64_safe_type (insn
) == TYPE_B
)
8782 curr_state
->branch_deviation
8783 += 2 - (curr_state
->accumulated_insns_num
- 1) % 3;
8784 if (try_bundle_end_p
&& curr_state
->accumulated_insns_num
% 3 != 0)
8786 if (!only_bundle_end_p
&& insert_bundle_state (curr_state
))
8789 struct bundle_state
*curr_state1
;
8790 struct bundle_state
*allocated_states_chain
;
8792 curr_state1
= get_free_bundle_state ();
8793 dfa_state
= curr_state1
->dfa_state
;
8794 allocated_states_chain
= curr_state1
->allocated_states_chain
;
8795 *curr_state1
= *curr_state
;
8796 curr_state1
->dfa_state
= dfa_state
;
8797 curr_state1
->allocated_states_chain
= allocated_states_chain
;
8798 memcpy (curr_state1
->dfa_state
, curr_state
->dfa_state
,
8800 curr_state
= curr_state1
;
8802 if (!try_issue_nops (curr_state
,
8803 3 - curr_state
->accumulated_insns_num
% 3))
8805 curr_state
->after_nops_num
8806 = 3 - curr_state
->accumulated_insns_num
% 3;
8807 curr_state
->accumulated_insns_num
8808 += 3 - curr_state
->accumulated_insns_num
% 3;
8810 if (!insert_bundle_state (curr_state
))
8811 free_bundle_state (curr_state
);
8815 /* The following function returns position in the two window bundle
8819 get_max_pos (state_t state
)
8821 if (cpu_unit_reservation_p (state
, pos_6
))
8823 else if (cpu_unit_reservation_p (state
, pos_5
))
8825 else if (cpu_unit_reservation_p (state
, pos_4
))
8827 else if (cpu_unit_reservation_p (state
, pos_3
))
8829 else if (cpu_unit_reservation_p (state
, pos_2
))
8831 else if (cpu_unit_reservation_p (state
, pos_1
))
8837 /* The function returns code of a possible template for given position
8838 and state. The function should be called only with 2 values of
8839 position equal to 3 or 6. We avoid generating F NOPs by putting
8840 templates containing F insns at the end of the template search
8841 because undocumented anomaly in McKinley derived cores which can
8842 cause stalls if an F-unit insn (including a NOP) is issued within a
8843 six-cycle window after reading certain application registers (such
8844 as ar.bsp). Furthermore, power-considerations also argue against
8845 the use of F-unit instructions unless they're really needed. */
8848 get_template (state_t state
, int pos
)
8853 if (cpu_unit_reservation_p (state
, _0mmi_
))
8855 else if (cpu_unit_reservation_p (state
, _0mii_
))
8857 else if (cpu_unit_reservation_p (state
, _0mmb_
))
8859 else if (cpu_unit_reservation_p (state
, _0mib_
))
8861 else if (cpu_unit_reservation_p (state
, _0mbb_
))
8863 else if (cpu_unit_reservation_p (state
, _0bbb_
))
8865 else if (cpu_unit_reservation_p (state
, _0mmf_
))
8867 else if (cpu_unit_reservation_p (state
, _0mfi_
))
8869 else if (cpu_unit_reservation_p (state
, _0mfb_
))
8871 else if (cpu_unit_reservation_p (state
, _0mlx_
))
8876 if (cpu_unit_reservation_p (state
, _1mmi_
))
8878 else if (cpu_unit_reservation_p (state
, _1mii_
))
8880 else if (cpu_unit_reservation_p (state
, _1mmb_
))
8882 else if (cpu_unit_reservation_p (state
, _1mib_
))
8884 else if (cpu_unit_reservation_p (state
, _1mbb_
))
8886 else if (cpu_unit_reservation_p (state
, _1bbb_
))
8888 else if (_1mmf_
>= 0 && cpu_unit_reservation_p (state
, _1mmf_
))
8890 else if (cpu_unit_reservation_p (state
, _1mfi_
))
8892 else if (cpu_unit_reservation_p (state
, _1mfb_
))
8894 else if (cpu_unit_reservation_p (state
, _1mlx_
))
8903 /* True when INSN is important for bundling. */
8906 important_for_bundling_p (rtx insn
)
8908 return (INSN_P (insn
)
8909 && ia64_safe_itanium_class (insn
) != ITANIUM_CLASS_IGNORE
8910 && GET_CODE (PATTERN (insn
)) != USE
8911 && GET_CODE (PATTERN (insn
)) != CLOBBER
);
8914 /* The following function returns an insn important for insn bundling
8915 followed by INSN and before TAIL. */
8918 get_next_important_insn (rtx insn
, rtx tail
)
8920 for (; insn
&& insn
!= tail
; insn
= NEXT_INSN (insn
))
8921 if (important_for_bundling_p (insn
))
8926 /* True when INSN is unknown, but important, for bundling. */
8929 unknown_for_bundling_p (rtx insn
)
8931 return (INSN_P (insn
)
8932 && ia64_safe_itanium_class (insn
) == ITANIUM_CLASS_UNKNOWN
8933 && GET_CODE (PATTERN (insn
)) != USE
8934 && GET_CODE (PATTERN (insn
)) != CLOBBER
);
8937 /* Add a bundle selector TEMPLATE0 before INSN. */
8940 ia64_add_bundle_selector_before (int template0
, rtx insn
)
8942 rtx b
= gen_bundle_selector (GEN_INT (template0
));
8944 ia64_emit_insn_before (b
, insn
);
8945 #if NR_BUNDLES == 10
8946 if ((template0
== 4 || template0
== 5)
8947 && ia64_except_unwind_info (&global_options
) == UI_TARGET
)
8950 rtx note
= NULL_RTX
;
8952 /* In .mbb and .bbb bundles, check if CALL_INSN isn't in the
8953 first or second slot. If it is and has REG_EH_NOTE set, copy it
8954 to following nops, as br.call sets rp to the address of following
8955 bundle and therefore an EH region end must be on a bundle
8957 insn
= PREV_INSN (insn
);
8958 for (i
= 0; i
< 3; i
++)
8961 insn
= next_active_insn (insn
);
8962 while (NONJUMP_INSN_P (insn
)
8963 && get_attr_empty (insn
) == EMPTY_YES
);
8965 note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
8970 gcc_assert ((code
= recog_memoized (insn
)) == CODE_FOR_nop
8971 || code
== CODE_FOR_nop_b
);
8972 if (find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
))
8975 add_reg_note (insn
, REG_EH_REGION
, XEXP (note
, 0));
8982 /* The following function does insn bundling. Bundling means
8983 inserting templates and nop insns to fit insn groups into permitted
8984 templates. Instruction scheduling uses NDFA (non-deterministic
8985 finite automata) encoding informations about the templates and the
8986 inserted nops. Nondeterminism of the automata permits follows
8987 all possible insn sequences very fast.
8989 Unfortunately it is not possible to get information about inserting
8990 nop insns and used templates from the automata states. The
8991 automata only says that we can issue an insn possibly inserting
8992 some nops before it and using some template. Therefore insn
8993 bundling in this function is implemented by using DFA
8994 (deterministic finite automata). We follow all possible insn
8995 sequences by inserting 0-2 nops (that is what the NDFA describe for
8996 insn scheduling) before/after each insn being bundled. We know the
8997 start of simulated processor cycle from insn scheduling (insn
8998 starting a new cycle has TImode).
9000 Simple implementation of insn bundling would create enormous
9001 number of possible insn sequences satisfying information about new
9002 cycle ticks taken from the insn scheduling. To make the algorithm
9003 practical we use dynamic programming. Each decision (about
9004 inserting nops and implicitly about previous decisions) is described
9005 by structure bundle_state (see above). If we generate the same
9006 bundle state (key is automaton state after issuing the insns and
9007 nops for it), we reuse already generated one. As consequence we
9008 reject some decisions which cannot improve the solution and
9009 reduce memory for the algorithm.
9011 When we reach the end of EBB (extended basic block), we choose the
9012 best sequence and then, moving back in EBB, insert templates for
9013 the best alternative. The templates are taken from querying
9014 automaton state for each insn in chosen bundle states.
9016 So the algorithm makes two (forward and backward) passes through
9020 bundling (FILE *dump
, int verbose
, rtx prev_head_insn
, rtx tail
)
9022 struct bundle_state
*curr_state
, *next_state
, *best_state
;
9023 rtx insn
, next_insn
;
9025 int i
, bundle_end_p
, only_bundle_end_p
, asm_p
;
9026 int pos
= 0, max_pos
, template0
, template1
;
9029 enum attr_type type
;
9032 /* Count insns in the EBB. */
9033 for (insn
= NEXT_INSN (prev_head_insn
);
9034 insn
&& insn
!= tail
;
9035 insn
= NEXT_INSN (insn
))
9041 dfa_clean_insn_cache ();
9042 initiate_bundle_state_table ();
9043 index_to_bundle_states
= XNEWVEC (struct bundle_state
*, insn_num
+ 2);
9044 /* First (forward) pass -- generation of bundle states. */
9045 curr_state
= get_free_bundle_state ();
9046 curr_state
->insn
= NULL
;
9047 curr_state
->before_nops_num
= 0;
9048 curr_state
->after_nops_num
= 0;
9049 curr_state
->insn_num
= 0;
9050 curr_state
->cost
= 0;
9051 curr_state
->accumulated_insns_num
= 0;
9052 curr_state
->branch_deviation
= 0;
9053 curr_state
->middle_bundle_stops
= 0;
9054 curr_state
->next
= NULL
;
9055 curr_state
->originator
= NULL
;
9056 state_reset (curr_state
->dfa_state
);
9057 index_to_bundle_states
[0] = curr_state
;
9059 /* Shift cycle mark if it is put on insn which could be ignored. */
9060 for (insn
= NEXT_INSN (prev_head_insn
);
9062 insn
= NEXT_INSN (insn
))
9064 && !important_for_bundling_p (insn
)
9065 && GET_MODE (insn
) == TImode
)
9067 PUT_MODE (insn
, VOIDmode
);
9068 for (next_insn
= NEXT_INSN (insn
);
9070 next_insn
= NEXT_INSN (next_insn
))
9071 if (important_for_bundling_p (next_insn
)
9072 && INSN_CODE (next_insn
) != CODE_FOR_insn_group_barrier
)
9074 PUT_MODE (next_insn
, TImode
);
9078 /* Forward pass: generation of bundle states. */
9079 for (insn
= get_next_important_insn (NEXT_INSN (prev_head_insn
), tail
);
9083 gcc_assert (important_for_bundling_p (insn
));
9084 type
= ia64_safe_type (insn
);
9085 next_insn
= get_next_important_insn (NEXT_INSN (insn
), tail
);
9087 index_to_bundle_states
[insn_num
] = NULL
;
9088 for (curr_state
= index_to_bundle_states
[insn_num
- 1];
9090 curr_state
= next_state
)
9092 pos
= curr_state
->accumulated_insns_num
% 3;
9093 next_state
= curr_state
->next
;
9094 /* We must fill up the current bundle in order to start a
9095 subsequent asm insn in a new bundle. Asm insn is always
9096 placed in a separate bundle. */
9098 = (next_insn
!= NULL_RTX
9099 && INSN_CODE (insn
) == CODE_FOR_insn_group_barrier
9100 && unknown_for_bundling_p (next_insn
));
9101 /* We may fill up the current bundle if it is the cycle end
9102 without a group barrier. */
9104 = (only_bundle_end_p
|| next_insn
== NULL_RTX
9105 || (GET_MODE (next_insn
) == TImode
9106 && INSN_CODE (insn
) != CODE_FOR_insn_group_barrier
));
9107 if (type
== TYPE_F
|| type
== TYPE_B
|| type
== TYPE_L
9109 issue_nops_and_insn (curr_state
, 2, insn
, bundle_end_p
,
9111 issue_nops_and_insn (curr_state
, 1, insn
, bundle_end_p
,
9113 issue_nops_and_insn (curr_state
, 0, insn
, bundle_end_p
,
9116 gcc_assert (index_to_bundle_states
[insn_num
]);
9117 for (curr_state
= index_to_bundle_states
[insn_num
];
9119 curr_state
= curr_state
->next
)
9120 if (verbose
>= 2 && dump
)
9122 /* This structure is taken from generated code of the
9123 pipeline hazard recognizer (see file insn-attrtab.c).
9124 Please don't forget to change the structure if a new
9125 automaton is added to .md file. */
9128 unsigned short one_automaton_state
;
9129 unsigned short oneb_automaton_state
;
9130 unsigned short two_automaton_state
;
9131 unsigned short twob_automaton_state
;
9136 "// Bundle state %d (orig %d, cost %d, nops %d/%d, insns %d, branch %d, mid.stops %d state %d) for %d\n",
9137 curr_state
->unique_num
,
9138 (curr_state
->originator
== NULL
9139 ? -1 : curr_state
->originator
->unique_num
),
9141 curr_state
->before_nops_num
, curr_state
->after_nops_num
,
9142 curr_state
->accumulated_insns_num
, curr_state
->branch_deviation
,
9143 curr_state
->middle_bundle_stops
,
9144 ((struct DFA_chip
*) curr_state
->dfa_state
)->twob_automaton_state
,
9149 /* We should find a solution because the 2nd insn scheduling has
9151 gcc_assert (index_to_bundle_states
[insn_num
]);
9152 /* Find a state corresponding to the best insn sequence. */
9154 for (curr_state
= index_to_bundle_states
[insn_num
];
9156 curr_state
= curr_state
->next
)
9157 /* We are just looking at the states with fully filled up last
9158 bundle. The first we prefer insn sequences with minimal cost
9159 then with minimal inserted nops and finally with branch insns
9160 placed in the 3rd slots. */
9161 if (curr_state
->accumulated_insns_num
% 3 == 0
9162 && (best_state
== NULL
|| best_state
->cost
> curr_state
->cost
9163 || (best_state
->cost
== curr_state
->cost
9164 && (curr_state
->accumulated_insns_num
9165 < best_state
->accumulated_insns_num
9166 || (curr_state
->accumulated_insns_num
9167 == best_state
->accumulated_insns_num
9168 && (curr_state
->branch_deviation
9169 < best_state
->branch_deviation
9170 || (curr_state
->branch_deviation
9171 == best_state
->branch_deviation
9172 && curr_state
->middle_bundle_stops
9173 < best_state
->middle_bundle_stops
)))))))
9174 best_state
= curr_state
;
9175 /* Second (backward) pass: adding nops and templates. */
9176 gcc_assert (best_state
);
9177 insn_num
= best_state
->before_nops_num
;
9178 template0
= template1
= -1;
9179 for (curr_state
= best_state
;
9180 curr_state
->originator
!= NULL
;
9181 curr_state
= curr_state
->originator
)
9183 insn
= curr_state
->insn
;
9184 asm_p
= unknown_for_bundling_p (insn
);
9186 if (verbose
>= 2 && dump
)
9190 unsigned short one_automaton_state
;
9191 unsigned short oneb_automaton_state
;
9192 unsigned short two_automaton_state
;
9193 unsigned short twob_automaton_state
;
9198 "// Best %d (orig %d, cost %d, nops %d/%d, insns %d, branch %d, mid.stops %d, state %d) for %d\n",
9199 curr_state
->unique_num
,
9200 (curr_state
->originator
== NULL
9201 ? -1 : curr_state
->originator
->unique_num
),
9203 curr_state
->before_nops_num
, curr_state
->after_nops_num
,
9204 curr_state
->accumulated_insns_num
, curr_state
->branch_deviation
,
9205 curr_state
->middle_bundle_stops
,
9206 ((struct DFA_chip
*) curr_state
->dfa_state
)->twob_automaton_state
,
9209 /* Find the position in the current bundle window. The window can
9210 contain at most two bundles. Two bundle window means that
9211 the processor will make two bundle rotation. */
9212 max_pos
= get_max_pos (curr_state
->dfa_state
);
9214 /* The following (negative template number) means that the
9215 processor did one bundle rotation. */
9216 || (max_pos
== 3 && template0
< 0))
9218 /* We are at the end of the window -- find template(s) for
9222 template0
= get_template (curr_state
->dfa_state
, 3);
9225 template1
= get_template (curr_state
->dfa_state
, 3);
9226 template0
= get_template (curr_state
->dfa_state
, 6);
9229 if (max_pos
> 3 && template1
< 0)
9230 /* It may happen when we have the stop inside a bundle. */
9232 gcc_assert (pos
<= 3);
9233 template1
= get_template (curr_state
->dfa_state
, 3);
9237 /* Emit nops after the current insn. */
9238 for (i
= 0; i
< curr_state
->after_nops_num
; i
++)
9241 emit_insn_after (nop
, insn
);
9243 gcc_assert (pos
>= 0);
9246 /* We are at the start of a bundle: emit the template
9247 (it should be defined). */
9248 gcc_assert (template0
>= 0);
9249 ia64_add_bundle_selector_before (template0
, nop
);
9250 /* If we have two bundle window, we make one bundle
9251 rotation. Otherwise template0 will be undefined
9252 (negative value). */
9253 template0
= template1
;
9257 /* Move the position backward in the window. Group barrier has
9258 no slot. Asm insn takes all bundle. */
9259 if (INSN_CODE (insn
) != CODE_FOR_insn_group_barrier
9260 && !unknown_for_bundling_p (insn
))
9262 /* Long insn takes 2 slots. */
9263 if (ia64_safe_type (insn
) == TYPE_L
)
9265 gcc_assert (pos
>= 0);
9267 && INSN_CODE (insn
) != CODE_FOR_insn_group_barrier
9268 && !unknown_for_bundling_p (insn
))
9270 /* The current insn is at the bundle start: emit the
9272 gcc_assert (template0
>= 0);
9273 ia64_add_bundle_selector_before (template0
, insn
);
9274 b
= PREV_INSN (insn
);
9276 /* See comment above in analogous place for emitting nops
9278 template0
= template1
;
9281 /* Emit nops after the current insn. */
9282 for (i
= 0; i
< curr_state
->before_nops_num
; i
++)
9285 ia64_emit_insn_before (nop
, insn
);
9286 nop
= PREV_INSN (insn
);
9289 gcc_assert (pos
>= 0);
9292 /* See comment above in analogous place for emitting nops
9294 gcc_assert (template0
>= 0);
9295 ia64_add_bundle_selector_before (template0
, insn
);
9296 b
= PREV_INSN (insn
);
9298 template0
= template1
;
9304 #ifdef ENABLE_CHECKING
9306 /* Assert right calculation of middle_bundle_stops. */
9307 int num
= best_state
->middle_bundle_stops
;
9308 bool start_bundle
= true, end_bundle
= false;
9310 for (insn
= NEXT_INSN (prev_head_insn
);
9311 insn
&& insn
!= tail
;
9312 insn
= NEXT_INSN (insn
))
9316 if (recog_memoized (insn
) == CODE_FOR_bundle_selector
)
9317 start_bundle
= true;
9322 for (next_insn
= NEXT_INSN (insn
);
9323 next_insn
&& next_insn
!= tail
;
9324 next_insn
= NEXT_INSN (next_insn
))
9325 if (INSN_P (next_insn
)
9326 && (ia64_safe_itanium_class (next_insn
)
9327 != ITANIUM_CLASS_IGNORE
9328 || recog_memoized (next_insn
)
9329 == CODE_FOR_bundle_selector
)
9330 && GET_CODE (PATTERN (next_insn
)) != USE
9331 && GET_CODE (PATTERN (next_insn
)) != CLOBBER
)
9334 end_bundle
= next_insn
== NULL_RTX
9335 || next_insn
== tail
9336 || (INSN_P (next_insn
)
9337 && recog_memoized (next_insn
)
9338 == CODE_FOR_bundle_selector
);
9339 if (recog_memoized (insn
) == CODE_FOR_insn_group_barrier
9340 && !start_bundle
&& !end_bundle
9342 && !unknown_for_bundling_p (next_insn
))
9345 start_bundle
= false;
9349 gcc_assert (num
== 0);
9353 free (index_to_bundle_states
);
9354 finish_bundle_state_table ();
9356 dfa_clean_insn_cache ();
9359 /* The following function is called at the end of scheduling BB or
9360 EBB. After reload, it inserts stop bits and does insn bundling. */
9363 ia64_sched_finish (FILE *dump
, int sched_verbose
)
9366 fprintf (dump
, "// Finishing schedule.\n");
9367 if (!reload_completed
)
9369 if (reload_completed
)
9371 final_emit_insn_group_barriers (dump
);
9372 bundling (dump
, sched_verbose
, current_sched_info
->prev_head
,
9373 current_sched_info
->next_tail
);
9374 if (sched_verbose
&& dump
)
9375 fprintf (dump
, "// finishing %d-%d\n",
9376 INSN_UID (NEXT_INSN (current_sched_info
->prev_head
)),
9377 INSN_UID (PREV_INSN (current_sched_info
->next_tail
)));
9383 /* The following function inserts stop bits in scheduled BB or EBB. */
9386 final_emit_insn_group_barriers (FILE *dump ATTRIBUTE_UNUSED
)
9389 int need_barrier_p
= 0;
9390 int seen_good_insn
= 0;
9392 init_insn_group_barriers ();
9394 for (insn
= NEXT_INSN (current_sched_info
->prev_head
);
9395 insn
!= current_sched_info
->next_tail
;
9396 insn
= NEXT_INSN (insn
))
9398 if (BARRIER_P (insn
))
9400 rtx_insn
*last
= prev_active_insn (insn
);
9404 if (JUMP_TABLE_DATA_P (last
))
9405 last
= prev_active_insn (last
);
9406 if (recog_memoized (last
) != CODE_FOR_insn_group_barrier
)
9407 emit_insn_after (gen_insn_group_barrier (GEN_INT (3)), last
);
9409 init_insn_group_barriers ();
9413 else if (NONDEBUG_INSN_P (insn
))
9415 if (recog_memoized (insn
) == CODE_FOR_insn_group_barrier
)
9417 init_insn_group_barriers ();
9421 else if (need_barrier_p
|| group_barrier_needed (insn
)
9422 || (mflag_sched_stop_bits_after_every_cycle
9423 && GET_MODE (insn
) == TImode
9426 if (TARGET_EARLY_STOP_BITS
)
9431 last
!= current_sched_info
->prev_head
;
9432 last
= PREV_INSN (last
))
9433 if (INSN_P (last
) && GET_MODE (last
) == TImode
9434 && stops_p
[INSN_UID (last
)])
9436 if (last
== current_sched_info
->prev_head
)
9438 last
= prev_active_insn (last
);
9440 && recog_memoized (last
) != CODE_FOR_insn_group_barrier
)
9441 emit_insn_after (gen_insn_group_barrier (GEN_INT (3)),
9443 init_insn_group_barriers ();
9444 for (last
= NEXT_INSN (last
);
9446 last
= NEXT_INSN (last
))
9449 group_barrier_needed (last
);
9450 if (recog_memoized (last
) >= 0
9451 && important_for_bundling_p (last
))
9457 emit_insn_before (gen_insn_group_barrier (GEN_INT (3)),
9459 init_insn_group_barriers ();
9462 group_barrier_needed (insn
);
9463 if (recog_memoized (insn
) >= 0
9464 && important_for_bundling_p (insn
))
9467 else if (recog_memoized (insn
) >= 0
9468 && important_for_bundling_p (insn
))
9470 need_barrier_p
= (CALL_P (insn
) || unknown_for_bundling_p (insn
));
9477 /* If the following function returns TRUE, we will use the DFA
9481 ia64_first_cycle_multipass_dfa_lookahead (void)
9483 return (reload_completed
? 6 : 4);
9486 /* The following function initiates variable `dfa_pre_cycle_insn'. */
9489 ia64_init_dfa_pre_cycle_insn (void)
9491 if (temp_dfa_state
== NULL
)
9493 dfa_state_size
= state_size ();
9494 temp_dfa_state
= xmalloc (dfa_state_size
);
9495 prev_cycle_state
= xmalloc (dfa_state_size
);
9497 dfa_pre_cycle_insn
= make_insn_raw (gen_pre_cycle ());
9498 SET_PREV_INSN (dfa_pre_cycle_insn
) = SET_NEXT_INSN (dfa_pre_cycle_insn
) = NULL_RTX
;
9499 recog_memoized (dfa_pre_cycle_insn
);
9500 dfa_stop_insn
= make_insn_raw (gen_insn_group_barrier (GEN_INT (3)));
9501 SET_PREV_INSN (dfa_stop_insn
) = SET_NEXT_INSN (dfa_stop_insn
) = NULL_RTX
;
9502 recog_memoized (dfa_stop_insn
);
9505 /* The following function returns the pseudo insn DFA_PRE_CYCLE_INSN
9506 used by the DFA insn scheduler. */
9509 ia64_dfa_pre_cycle_insn (void)
9511 return dfa_pre_cycle_insn
;
9514 /* The following function returns TRUE if PRODUCER (of type ilog or
9515 ld) produces address for CONSUMER (of type st or stf). */
9518 ia64_st_address_bypass_p (rtx producer
, rtx consumer
)
9522 gcc_assert (producer
&& consumer
);
9523 dest
= ia64_single_set (producer
);
9525 reg
= SET_DEST (dest
);
9527 if (GET_CODE (reg
) == SUBREG
)
9528 reg
= SUBREG_REG (reg
);
9529 gcc_assert (GET_CODE (reg
) == REG
);
9531 dest
= ia64_single_set (consumer
);
9533 mem
= SET_DEST (dest
);
9534 gcc_assert (mem
&& GET_CODE (mem
) == MEM
);
9535 return reg_mentioned_p (reg
, mem
);
9538 /* The following function returns TRUE if PRODUCER (of type ilog or
9539 ld) produces address for CONSUMER (of type ld or fld). */
9542 ia64_ld_address_bypass_p (rtx producer
, rtx consumer
)
9544 rtx dest
, src
, reg
, mem
;
9546 gcc_assert (producer
&& consumer
);
9547 dest
= ia64_single_set (producer
);
9549 reg
= SET_DEST (dest
);
9551 if (GET_CODE (reg
) == SUBREG
)
9552 reg
= SUBREG_REG (reg
);
9553 gcc_assert (GET_CODE (reg
) == REG
);
9555 src
= ia64_single_set (consumer
);
9557 mem
= SET_SRC (src
);
9560 if (GET_CODE (mem
) == UNSPEC
&& XVECLEN (mem
, 0) > 0)
9561 mem
= XVECEXP (mem
, 0, 0);
9562 else if (GET_CODE (mem
) == IF_THEN_ELSE
)
9563 /* ??? Is this bypass necessary for ld.c? */
9565 gcc_assert (XINT (XEXP (XEXP (mem
, 0), 0), 1) == UNSPEC_LDCCLR
);
9566 mem
= XEXP (mem
, 1);
9569 while (GET_CODE (mem
) == SUBREG
|| GET_CODE (mem
) == ZERO_EXTEND
)
9570 mem
= XEXP (mem
, 0);
9572 if (GET_CODE (mem
) == UNSPEC
)
9574 int c
= XINT (mem
, 1);
9576 gcc_assert (c
== UNSPEC_LDA
|| c
== UNSPEC_LDS
|| c
== UNSPEC_LDS_A
9577 || c
== UNSPEC_LDSA
);
9578 mem
= XVECEXP (mem
, 0, 0);
9581 /* Note that LO_SUM is used for GOT loads. */
9582 gcc_assert (GET_CODE (mem
) == LO_SUM
|| GET_CODE (mem
) == MEM
);
9584 return reg_mentioned_p (reg
, mem
);
9587 /* The following function returns TRUE if INSN produces address for a
9588 load/store insn. We will place such insns into M slot because it
9589 decreases its latency time. */
9592 ia64_produce_address_p (rtx insn
)
9598 /* Emit pseudo-ops for the assembler to describe predicate relations.
9599 At present this assumes that we only consider predicate pairs to
9600 be mutex, and that the assembler can deduce proper values from
9601 straight-line code. */
9604 emit_predicate_relation_info (void)
9608 FOR_EACH_BB_REVERSE_FN (bb
, cfun
)
9611 rtx_insn
*head
= BB_HEAD (bb
);
9613 /* We only need such notes at code labels. */
9614 if (! LABEL_P (head
))
9616 if (NOTE_INSN_BASIC_BLOCK_P (NEXT_INSN (head
)))
9617 head
= NEXT_INSN (head
);
9619 /* Skip p0, which may be thought to be live due to (reg:DI p0)
9620 grabbing the entire block of predicate registers. */
9621 for (r
= PR_REG (2); r
< PR_REG (64); r
+= 2)
9622 if (REGNO_REG_SET_P (df_get_live_in (bb
), r
))
9624 rtx p
= gen_rtx_REG (BImode
, r
);
9625 rtx_insn
*n
= emit_insn_after (gen_pred_rel_mutex (p
), head
);
9626 if (head
== BB_END (bb
))
9632 /* Look for conditional calls that do not return, and protect predicate
9633 relations around them. Otherwise the assembler will assume the call
9634 returns, and complain about uses of call-clobbered predicates after
9636 FOR_EACH_BB_REVERSE_FN (bb
, cfun
)
9638 rtx_insn
*insn
= BB_HEAD (bb
);
9643 && GET_CODE (PATTERN (insn
)) == COND_EXEC
9644 && find_reg_note (insn
, REG_NORETURN
, NULL_RTX
))
9647 emit_insn_before (gen_safe_across_calls_all (), insn
);
9648 rtx_insn
*a
= emit_insn_after (gen_safe_across_calls_normal (), insn
);
9649 if (BB_HEAD (bb
) == insn
)
9651 if (BB_END (bb
) == insn
)
9655 if (insn
== BB_END (bb
))
9657 insn
= NEXT_INSN (insn
);
9662 /* Perform machine dependent operations on the rtl chain INSNS. */
9667 /* We are freeing block_for_insn in the toplev to keep compatibility
9668 with old MDEP_REORGS that are not CFG based. Recompute it now. */
9669 compute_bb_for_insn ();
9671 /* If optimizing, we'll have split before scheduling. */
9675 if (optimize
&& flag_schedule_insns_after_reload
9676 && dbg_cnt (ia64_sched2
))
9679 timevar_push (TV_SCHED2
);
9680 ia64_final_schedule
= 1;
9682 /* We can't let modulo-sched prevent us from scheduling any bbs,
9683 since we need the final schedule to produce bundle information. */
9684 FOR_EACH_BB_FN (bb
, cfun
)
9685 bb
->flags
&= ~BB_DISABLE_SCHEDULE
;
9687 initiate_bundle_states ();
9688 ia64_nop
= make_insn_raw (gen_nop ());
9689 SET_PREV_INSN (ia64_nop
) = SET_NEXT_INSN (ia64_nop
) = NULL_RTX
;
9690 recog_memoized (ia64_nop
);
9691 clocks_length
= get_max_uid () + 1;
9692 stops_p
= XCNEWVEC (char, clocks_length
);
9694 if (ia64_tune
== PROCESSOR_ITANIUM2
)
9696 pos_1
= get_cpu_unit_code ("2_1");
9697 pos_2
= get_cpu_unit_code ("2_2");
9698 pos_3
= get_cpu_unit_code ("2_3");
9699 pos_4
= get_cpu_unit_code ("2_4");
9700 pos_5
= get_cpu_unit_code ("2_5");
9701 pos_6
= get_cpu_unit_code ("2_6");
9702 _0mii_
= get_cpu_unit_code ("2b_0mii.");
9703 _0mmi_
= get_cpu_unit_code ("2b_0mmi.");
9704 _0mfi_
= get_cpu_unit_code ("2b_0mfi.");
9705 _0mmf_
= get_cpu_unit_code ("2b_0mmf.");
9706 _0bbb_
= get_cpu_unit_code ("2b_0bbb.");
9707 _0mbb_
= get_cpu_unit_code ("2b_0mbb.");
9708 _0mib_
= get_cpu_unit_code ("2b_0mib.");
9709 _0mmb_
= get_cpu_unit_code ("2b_0mmb.");
9710 _0mfb_
= get_cpu_unit_code ("2b_0mfb.");
9711 _0mlx_
= get_cpu_unit_code ("2b_0mlx.");
9712 _1mii_
= get_cpu_unit_code ("2b_1mii.");
9713 _1mmi_
= get_cpu_unit_code ("2b_1mmi.");
9714 _1mfi_
= get_cpu_unit_code ("2b_1mfi.");
9715 _1mmf_
= get_cpu_unit_code ("2b_1mmf.");
9716 _1bbb_
= get_cpu_unit_code ("2b_1bbb.");
9717 _1mbb_
= get_cpu_unit_code ("2b_1mbb.");
9718 _1mib_
= get_cpu_unit_code ("2b_1mib.");
9719 _1mmb_
= get_cpu_unit_code ("2b_1mmb.");
9720 _1mfb_
= get_cpu_unit_code ("2b_1mfb.");
9721 _1mlx_
= get_cpu_unit_code ("2b_1mlx.");
9725 pos_1
= get_cpu_unit_code ("1_1");
9726 pos_2
= get_cpu_unit_code ("1_2");
9727 pos_3
= get_cpu_unit_code ("1_3");
9728 pos_4
= get_cpu_unit_code ("1_4");
9729 pos_5
= get_cpu_unit_code ("1_5");
9730 pos_6
= get_cpu_unit_code ("1_6");
9731 _0mii_
= get_cpu_unit_code ("1b_0mii.");
9732 _0mmi_
= get_cpu_unit_code ("1b_0mmi.");
9733 _0mfi_
= get_cpu_unit_code ("1b_0mfi.");
9734 _0mmf_
= get_cpu_unit_code ("1b_0mmf.");
9735 _0bbb_
= get_cpu_unit_code ("1b_0bbb.");
9736 _0mbb_
= get_cpu_unit_code ("1b_0mbb.");
9737 _0mib_
= get_cpu_unit_code ("1b_0mib.");
9738 _0mmb_
= get_cpu_unit_code ("1b_0mmb.");
9739 _0mfb_
= get_cpu_unit_code ("1b_0mfb.");
9740 _0mlx_
= get_cpu_unit_code ("1b_0mlx.");
9741 _1mii_
= get_cpu_unit_code ("1b_1mii.");
9742 _1mmi_
= get_cpu_unit_code ("1b_1mmi.");
9743 _1mfi_
= get_cpu_unit_code ("1b_1mfi.");
9744 _1mmf_
= get_cpu_unit_code ("1b_1mmf.");
9745 _1bbb_
= get_cpu_unit_code ("1b_1bbb.");
9746 _1mbb_
= get_cpu_unit_code ("1b_1mbb.");
9747 _1mib_
= get_cpu_unit_code ("1b_1mib.");
9748 _1mmb_
= get_cpu_unit_code ("1b_1mmb.");
9749 _1mfb_
= get_cpu_unit_code ("1b_1mfb.");
9750 _1mlx_
= get_cpu_unit_code ("1b_1mlx.");
9753 if (flag_selective_scheduling2
9754 && !maybe_skip_selective_scheduling ())
9755 run_selective_scheduling ();
9759 /* Redo alignment computation, as it might gone wrong. */
9760 compute_alignments ();
9762 /* We cannot reuse this one because it has been corrupted by the
9764 finish_bundle_states ();
9767 emit_insn_group_barriers (dump_file
);
9769 ia64_final_schedule
= 0;
9770 timevar_pop (TV_SCHED2
);
9773 emit_all_insn_group_barriers (dump_file
);
9777 /* A call must not be the last instruction in a function, so that the
9778 return address is still within the function, so that unwinding works
9779 properly. Note that IA-64 differs from dwarf2 on this point. */
9780 if (ia64_except_unwind_info (&global_options
) == UI_TARGET
)
9785 insn
= get_last_insn ();
9786 if (! INSN_P (insn
))
9787 insn
= prev_active_insn (insn
);
9790 /* Skip over insns that expand to nothing. */
9791 while (NONJUMP_INSN_P (insn
)
9792 && get_attr_empty (insn
) == EMPTY_YES
)
9794 if (GET_CODE (PATTERN (insn
)) == UNSPEC_VOLATILE
9795 && XINT (PATTERN (insn
), 1) == UNSPECV_INSN_GROUP_BARRIER
)
9797 insn
= prev_active_insn (insn
);
9802 emit_insn (gen_insn_group_barrier (GEN_INT (3)));
9803 emit_insn (gen_break_f ());
9804 emit_insn (gen_insn_group_barrier (GEN_INT (3)));
9809 emit_predicate_relation_info ();
9811 if (flag_var_tracking
)
9813 timevar_push (TV_VAR_TRACKING
);
9814 variable_tracking_main ();
9815 timevar_pop (TV_VAR_TRACKING
);
9817 df_finish_pass (false);
9820 /* Return true if REGNO is used by the epilogue. */
9823 ia64_epilogue_uses (int regno
)
9828 /* With a call to a function in another module, we will write a new
9829 value to "gp". After returning from such a call, we need to make
9830 sure the function restores the original gp-value, even if the
9831 function itself does not use the gp anymore. */
9832 return !(TARGET_AUTO_PIC
|| TARGET_NO_PIC
);
9834 case IN_REG (0): case IN_REG (1): case IN_REG (2): case IN_REG (3):
9835 case IN_REG (4): case IN_REG (5): case IN_REG (6): case IN_REG (7):
9836 /* For functions defined with the syscall_linkage attribute, all
9837 input registers are marked as live at all function exits. This
9838 prevents the register allocator from using the input registers,
9839 which in turn makes it possible to restart a system call after
9840 an interrupt without having to save/restore the input registers.
9841 This also prevents kernel data from leaking to application code. */
9842 return lookup_attribute ("syscall_linkage",
9843 TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl
))) != NULL
;
9846 /* Conditional return patterns can't represent the use of `b0' as
9847 the return address, so we force the value live this way. */
9851 /* Likewise for ar.pfs, which is used by br.ret. */
9859 /* Return true if REGNO is used by the frame unwinder. */
9862 ia64_eh_uses (int regno
)
9866 if (! reload_completed
)
9872 for (r
= reg_save_b0
; r
<= reg_save_ar_lc
; r
++)
9873 if (regno
== current_frame_info
.r
[r
]
9874 || regno
== emitted_frame_related_regs
[r
])
9880 /* Return true if this goes in small data/bss. */
9882 /* ??? We could also support own long data here. Generating movl/add/ld8
9883 instead of addl,ld8/ld8. This makes the code bigger, but should make the
9884 code faster because there is one less load. This also includes incomplete
9885 types which can't go in sdata/sbss. */
9888 ia64_in_small_data_p (const_tree exp
)
9890 if (TARGET_NO_SDATA
)
9893 /* We want to merge strings, so we never consider them small data. */
9894 if (TREE_CODE (exp
) == STRING_CST
)
9897 /* Functions are never small data. */
9898 if (TREE_CODE (exp
) == FUNCTION_DECL
)
9901 if (TREE_CODE (exp
) == VAR_DECL
&& DECL_SECTION_NAME (exp
))
9903 const char *section
= DECL_SECTION_NAME (exp
);
9905 if (strcmp (section
, ".sdata") == 0
9906 || strncmp (section
, ".sdata.", 7) == 0
9907 || strncmp (section
, ".gnu.linkonce.s.", 16) == 0
9908 || strcmp (section
, ".sbss") == 0
9909 || strncmp (section
, ".sbss.", 6) == 0
9910 || strncmp (section
, ".gnu.linkonce.sb.", 17) == 0)
9915 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
9917 /* If this is an incomplete type with size 0, then we can't put it
9918 in sdata because it might be too big when completed. */
9919 if (size
> 0 && size
<= ia64_section_threshold
)
9926 /* Output assembly directives for prologue regions. */
9928 /* The current basic block number. */
9930 static bool last_block
;
9932 /* True if we need a copy_state command at the start of the next block. */
9934 static bool need_copy_state
;
9936 #ifndef MAX_ARTIFICIAL_LABEL_BYTES
9937 # define MAX_ARTIFICIAL_LABEL_BYTES 30
9940 /* The function emits unwind directives for the start of an epilogue. */
9943 process_epilogue (FILE *asm_out_file
, rtx insn ATTRIBUTE_UNUSED
,
9944 bool unwind
, bool frame ATTRIBUTE_UNUSED
)
9946 /* If this isn't the last block of the function, then we need to label the
9947 current state, and copy it back in at the start of the next block. */
9952 fprintf (asm_out_file
, "\t.label_state %d\n",
9953 ++cfun
->machine
->state_num
);
9954 need_copy_state
= true;
9958 fprintf (asm_out_file
, "\t.restore sp\n");
9961 /* This function processes a SET pattern for REG_CFA_ADJUST_CFA. */
9964 process_cfa_adjust_cfa (FILE *asm_out_file
, rtx pat
, rtx insn
,
9965 bool unwind
, bool frame
)
9967 rtx dest
= SET_DEST (pat
);
9968 rtx src
= SET_SRC (pat
);
9970 if (dest
== stack_pointer_rtx
)
9972 if (GET_CODE (src
) == PLUS
)
9974 rtx op0
= XEXP (src
, 0);
9975 rtx op1
= XEXP (src
, 1);
9977 gcc_assert (op0
== dest
&& GET_CODE (op1
) == CONST_INT
);
9979 if (INTVAL (op1
) < 0)
9981 gcc_assert (!frame_pointer_needed
);
9983 fprintf (asm_out_file
,
9984 "\t.fframe "HOST_WIDE_INT_PRINT_DEC
"\n",
9988 process_epilogue (asm_out_file
, insn
, unwind
, frame
);
9992 gcc_assert (src
== hard_frame_pointer_rtx
);
9993 process_epilogue (asm_out_file
, insn
, unwind
, frame
);
9996 else if (dest
== hard_frame_pointer_rtx
)
9998 gcc_assert (src
== stack_pointer_rtx
);
9999 gcc_assert (frame_pointer_needed
);
10002 fprintf (asm_out_file
, "\t.vframe r%d\n",
10003 ia64_dbx_register_number (REGNO (dest
)));
10006 gcc_unreachable ();
10009 /* This function processes a SET pattern for REG_CFA_REGISTER. */
10012 process_cfa_register (FILE *asm_out_file
, rtx pat
, bool unwind
)
10014 rtx dest
= SET_DEST (pat
);
10015 rtx src
= SET_SRC (pat
);
10016 int dest_regno
= REGNO (dest
);
10021 /* Saving return address pointer. */
10023 fprintf (asm_out_file
, "\t.save rp, r%d\n",
10024 ia64_dbx_register_number (dest_regno
));
10028 src_regno
= REGNO (src
);
10033 gcc_assert (dest_regno
== current_frame_info
.r
[reg_save_pr
]);
10035 fprintf (asm_out_file
, "\t.save pr, r%d\n",
10036 ia64_dbx_register_number (dest_regno
));
10039 case AR_UNAT_REGNUM
:
10040 gcc_assert (dest_regno
== current_frame_info
.r
[reg_save_ar_unat
]);
10042 fprintf (asm_out_file
, "\t.save ar.unat, r%d\n",
10043 ia64_dbx_register_number (dest_regno
));
10047 gcc_assert (dest_regno
== current_frame_info
.r
[reg_save_ar_lc
]);
10049 fprintf (asm_out_file
, "\t.save ar.lc, r%d\n",
10050 ia64_dbx_register_number (dest_regno
));
10054 /* Everything else should indicate being stored to memory. */
10055 gcc_unreachable ();
10059 /* This function processes a SET pattern for REG_CFA_OFFSET. */
10062 process_cfa_offset (FILE *asm_out_file
, rtx pat
, bool unwind
)
10064 rtx dest
= SET_DEST (pat
);
10065 rtx src
= SET_SRC (pat
);
10066 int src_regno
= REGNO (src
);
10067 const char *saveop
;
10071 gcc_assert (MEM_P (dest
));
10072 if (GET_CODE (XEXP (dest
, 0)) == REG
)
10074 base
= XEXP (dest
, 0);
10079 gcc_assert (GET_CODE (XEXP (dest
, 0)) == PLUS
10080 && GET_CODE (XEXP (XEXP (dest
, 0), 1)) == CONST_INT
);
10081 base
= XEXP (XEXP (dest
, 0), 0);
10082 off
= INTVAL (XEXP (XEXP (dest
, 0), 1));
10085 if (base
== hard_frame_pointer_rtx
)
10087 saveop
= ".savepsp";
10092 gcc_assert (base
== stack_pointer_rtx
);
10093 saveop
= ".savesp";
10096 src_regno
= REGNO (src
);
10100 gcc_assert (!current_frame_info
.r
[reg_save_b0
]);
10102 fprintf (asm_out_file
, "\t%s rp, " HOST_WIDE_INT_PRINT_DEC
"\n",
10107 gcc_assert (!current_frame_info
.r
[reg_save_pr
]);
10109 fprintf (asm_out_file
, "\t%s pr, " HOST_WIDE_INT_PRINT_DEC
"\n",
10114 gcc_assert (!current_frame_info
.r
[reg_save_ar_lc
]);
10116 fprintf (asm_out_file
, "\t%s ar.lc, " HOST_WIDE_INT_PRINT_DEC
"\n",
10120 case AR_PFS_REGNUM
:
10121 gcc_assert (!current_frame_info
.r
[reg_save_ar_pfs
]);
10123 fprintf (asm_out_file
, "\t%s ar.pfs, " HOST_WIDE_INT_PRINT_DEC
"\n",
10127 case AR_UNAT_REGNUM
:
10128 gcc_assert (!current_frame_info
.r
[reg_save_ar_unat
]);
10130 fprintf (asm_out_file
, "\t%s ar.unat, " HOST_WIDE_INT_PRINT_DEC
"\n",
10139 fprintf (asm_out_file
, "\t.save.g 0x%x\n",
10140 1 << (src_regno
- GR_REG (4)));
10149 fprintf (asm_out_file
, "\t.save.b 0x%x\n",
10150 1 << (src_regno
- BR_REG (1)));
10158 fprintf (asm_out_file
, "\t.save.f 0x%x\n",
10159 1 << (src_regno
- FR_REG (2)));
10162 case FR_REG (16): case FR_REG (17): case FR_REG (18): case FR_REG (19):
10163 case FR_REG (20): case FR_REG (21): case FR_REG (22): case FR_REG (23):
10164 case FR_REG (24): case FR_REG (25): case FR_REG (26): case FR_REG (27):
10165 case FR_REG (28): case FR_REG (29): case FR_REG (30): case FR_REG (31):
10167 fprintf (asm_out_file
, "\t.save.gf 0x0, 0x%x\n",
10168 1 << (src_regno
- FR_REG (12)));
10172 /* ??? For some reason we mark other general registers, even those
10173 we can't represent in the unwind info. Ignore them. */
10178 /* This function looks at a single insn and emits any directives
10179 required to unwind this insn. */
10182 ia64_asm_unwind_emit (FILE *asm_out_file
, rtx_insn
*insn
)
10184 bool unwind
= ia64_except_unwind_info (&global_options
) == UI_TARGET
;
10185 bool frame
= dwarf2out_do_frame ();
10189 if (!unwind
&& !frame
)
10192 if (NOTE_INSN_BASIC_BLOCK_P (insn
))
10194 last_block
= NOTE_BASIC_BLOCK (insn
)->next_bb
10195 == EXIT_BLOCK_PTR_FOR_FN (cfun
);
10197 /* Restore unwind state from immediately before the epilogue. */
10198 if (need_copy_state
)
10202 fprintf (asm_out_file
, "\t.body\n");
10203 fprintf (asm_out_file
, "\t.copy_state %d\n",
10204 cfun
->machine
->state_num
);
10206 need_copy_state
= false;
10210 if (NOTE_P (insn
) || ! RTX_FRAME_RELATED_P (insn
))
10213 /* Look for the ALLOC insn. */
10214 if (INSN_CODE (insn
) == CODE_FOR_alloc
)
10216 rtx dest
= SET_DEST (XVECEXP (PATTERN (insn
), 0, 0));
10217 int dest_regno
= REGNO (dest
);
10219 /* If this is the final destination for ar.pfs, then this must
10220 be the alloc in the prologue. */
10221 if (dest_regno
== current_frame_info
.r
[reg_save_ar_pfs
])
10224 fprintf (asm_out_file
, "\t.save ar.pfs, r%d\n",
10225 ia64_dbx_register_number (dest_regno
));
10229 /* This must be an alloc before a sibcall. We must drop the
10230 old frame info. The easiest way to drop the old frame
10231 info is to ensure we had a ".restore sp" directive
10232 followed by a new prologue. If the procedure doesn't
10233 have a memory-stack frame, we'll issue a dummy ".restore
10235 if (current_frame_info
.total_size
== 0 && !frame_pointer_needed
)
10236 /* if haven't done process_epilogue() yet, do it now */
10237 process_epilogue (asm_out_file
, insn
, unwind
, frame
);
10239 fprintf (asm_out_file
, "\t.prologue\n");
10244 handled_one
= false;
10245 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
10246 switch (REG_NOTE_KIND (note
))
10248 case REG_CFA_ADJUST_CFA
:
10249 pat
= XEXP (note
, 0);
10251 pat
= PATTERN (insn
);
10252 process_cfa_adjust_cfa (asm_out_file
, pat
, insn
, unwind
, frame
);
10253 handled_one
= true;
10256 case REG_CFA_OFFSET
:
10257 pat
= XEXP (note
, 0);
10259 pat
= PATTERN (insn
);
10260 process_cfa_offset (asm_out_file
, pat
, unwind
);
10261 handled_one
= true;
10264 case REG_CFA_REGISTER
:
10265 pat
= XEXP (note
, 0);
10267 pat
= PATTERN (insn
);
10268 process_cfa_register (asm_out_file
, pat
, unwind
);
10269 handled_one
= true;
10272 case REG_FRAME_RELATED_EXPR
:
10273 case REG_CFA_DEF_CFA
:
10274 case REG_CFA_EXPRESSION
:
10275 case REG_CFA_RESTORE
:
10276 case REG_CFA_SET_VDRAP
:
10277 /* Not used in the ia64 port. */
10278 gcc_unreachable ();
10281 /* Not a frame-related note. */
10285 /* All REG_FRAME_RELATED_P insns, besides ALLOC, are marked with the
10286 explicit action to take. No guessing required. */
10287 gcc_assert (handled_one
);
10290 /* Implement TARGET_ASM_EMIT_EXCEPT_PERSONALITY. */
10293 ia64_asm_emit_except_personality (rtx personality
)
10295 fputs ("\t.personality\t", asm_out_file
);
10296 output_addr_const (asm_out_file
, personality
);
10297 fputc ('\n', asm_out_file
);
10300 /* Implement TARGET_ASM_INITIALIZE_SECTIONS. */
10303 ia64_asm_init_sections (void)
10305 exception_section
= get_unnamed_section (0, output_section_asm_op
,
10309 /* Implement TARGET_DEBUG_UNWIND_INFO. */
10311 static enum unwind_info_type
10312 ia64_debug_unwind_info (void)
10320 IA64_BUILTIN_COPYSIGNQ
,
10321 IA64_BUILTIN_FABSQ
,
10322 IA64_BUILTIN_FLUSHRS
,
10324 IA64_BUILTIN_HUGE_VALQ
,
10328 static GTY(()) tree ia64_builtins
[(int) IA64_BUILTIN_max
];
10331 ia64_init_builtins (void)
10337 /* The __fpreg type. */
10338 fpreg_type
= make_node (REAL_TYPE
);
10339 TYPE_PRECISION (fpreg_type
) = 82;
10340 layout_type (fpreg_type
);
10341 (*lang_hooks
.types
.register_builtin_type
) (fpreg_type
, "__fpreg");
10343 /* The __float80 type. */
10344 float80_type
= make_node (REAL_TYPE
);
10345 TYPE_PRECISION (float80_type
) = 80;
10346 layout_type (float80_type
);
10347 (*lang_hooks
.types
.register_builtin_type
) (float80_type
, "__float80");
10349 /* The __float128 type. */
10353 tree float128_type
= make_node (REAL_TYPE
);
10355 TYPE_PRECISION (float128_type
) = 128;
10356 layout_type (float128_type
);
10357 (*lang_hooks
.types
.register_builtin_type
) (float128_type
, "__float128");
10359 /* TFmode support builtins. */
10360 ftype
= build_function_type_list (float128_type
, NULL_TREE
);
10361 decl
= add_builtin_function ("__builtin_infq", ftype
,
10362 IA64_BUILTIN_INFQ
, BUILT_IN_MD
,
10364 ia64_builtins
[IA64_BUILTIN_INFQ
] = decl
;
10366 decl
= add_builtin_function ("__builtin_huge_valq", ftype
,
10367 IA64_BUILTIN_HUGE_VALQ
, BUILT_IN_MD
,
10369 ia64_builtins
[IA64_BUILTIN_HUGE_VALQ
] = decl
;
10371 ftype
= build_function_type_list (float128_type
,
10374 decl
= add_builtin_function ("__builtin_fabsq", ftype
,
10375 IA64_BUILTIN_FABSQ
, BUILT_IN_MD
,
10376 "__fabstf2", NULL_TREE
);
10377 TREE_READONLY (decl
) = 1;
10378 ia64_builtins
[IA64_BUILTIN_FABSQ
] = decl
;
10380 ftype
= build_function_type_list (float128_type
,
10384 decl
= add_builtin_function ("__builtin_copysignq", ftype
,
10385 IA64_BUILTIN_COPYSIGNQ
, BUILT_IN_MD
,
10386 "__copysigntf3", NULL_TREE
);
10387 TREE_READONLY (decl
) = 1;
10388 ia64_builtins
[IA64_BUILTIN_COPYSIGNQ
] = decl
;
10391 /* Under HPUX, this is a synonym for "long double". */
10392 (*lang_hooks
.types
.register_builtin_type
) (long_double_type_node
,
10395 /* Fwrite on VMS is non-standard. */
10396 #if TARGET_ABI_OPEN_VMS
10397 vms_patch_builtins ();
10400 #define def_builtin(name, type, code) \
10401 add_builtin_function ((name), (type), (code), BUILT_IN_MD, \
10404 decl
= def_builtin ("__builtin_ia64_bsp",
10405 build_function_type_list (ptr_type_node
, NULL_TREE
),
10407 ia64_builtins
[IA64_BUILTIN_BSP
] = decl
;
10409 decl
= def_builtin ("__builtin_ia64_flushrs",
10410 build_function_type_list (void_type_node
, NULL_TREE
),
10411 IA64_BUILTIN_FLUSHRS
);
10412 ia64_builtins
[IA64_BUILTIN_FLUSHRS
] = decl
;
10418 if ((decl
= builtin_decl_explicit (BUILT_IN_FINITE
)) != NULL_TREE
)
10419 set_user_assembler_name (decl
, "_Isfinite");
10420 if ((decl
= builtin_decl_explicit (BUILT_IN_FINITEF
)) != NULL_TREE
)
10421 set_user_assembler_name (decl
, "_Isfinitef");
10422 if ((decl
= builtin_decl_explicit (BUILT_IN_FINITEL
)) != NULL_TREE
)
10423 set_user_assembler_name (decl
, "_Isfinitef128");
10428 ia64_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
10429 enum machine_mode mode ATTRIBUTE_UNUSED
,
10430 int ignore ATTRIBUTE_UNUSED
)
10432 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
10433 unsigned int fcode
= DECL_FUNCTION_CODE (fndecl
);
10437 case IA64_BUILTIN_BSP
:
10438 if (! target
|| ! register_operand (target
, DImode
))
10439 target
= gen_reg_rtx (DImode
);
10440 emit_insn (gen_bsp_value (target
));
10441 #ifdef POINTERS_EXTEND_UNSIGNED
10442 target
= convert_memory_address (ptr_mode
, target
);
10446 case IA64_BUILTIN_FLUSHRS
:
10447 emit_insn (gen_flushrs ());
10450 case IA64_BUILTIN_INFQ
:
10451 case IA64_BUILTIN_HUGE_VALQ
:
10453 enum machine_mode target_mode
= TYPE_MODE (TREE_TYPE (exp
));
10454 REAL_VALUE_TYPE inf
;
10458 tmp
= CONST_DOUBLE_FROM_REAL_VALUE (inf
, target_mode
);
10460 tmp
= validize_mem (force_const_mem (target_mode
, tmp
));
10463 target
= gen_reg_rtx (target_mode
);
10465 emit_move_insn (target
, tmp
);
10469 case IA64_BUILTIN_FABSQ
:
10470 case IA64_BUILTIN_COPYSIGNQ
:
10471 return expand_call (exp
, target
, ignore
);
10474 gcc_unreachable ();
10480 /* Return the ia64 builtin for CODE. */
10483 ia64_builtin_decl (unsigned code
, bool initialize_p ATTRIBUTE_UNUSED
)
10485 if (code
>= IA64_BUILTIN_max
)
10486 return error_mark_node
;
10488 return ia64_builtins
[code
];
10491 /* For the HP-UX IA64 aggregate parameters are passed stored in the
10492 most significant bits of the stack slot. */
10495 ia64_hpux_function_arg_padding (enum machine_mode mode
, const_tree type
)
10497 /* Exception to normal case for structures/unions/etc. */
10499 if (type
&& AGGREGATE_TYPE_P (type
)
10500 && int_size_in_bytes (type
) < UNITS_PER_WORD
)
10503 /* Fall back to the default. */
10504 return DEFAULT_FUNCTION_ARG_PADDING (mode
, type
);
10507 /* Emit text to declare externally defined variables and functions, because
10508 the Intel assembler does not support undefined externals. */
10511 ia64_asm_output_external (FILE *file
, tree decl
, const char *name
)
10513 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
10514 set in order to avoid putting out names that are never really
10516 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)))
10518 /* maybe_assemble_visibility will return 1 if the assembler
10519 visibility directive is output. */
10520 int need_visibility
= ((*targetm
.binds_local_p
) (decl
)
10521 && maybe_assemble_visibility (decl
));
10523 /* GNU as does not need anything here, but the HP linker does
10524 need something for external functions. */
10525 if ((TARGET_HPUX_LD
|| !TARGET_GNU_AS
)
10526 && TREE_CODE (decl
) == FUNCTION_DECL
)
10527 (*targetm
.asm_out
.globalize_decl_name
) (file
, decl
);
10528 else if (need_visibility
&& !TARGET_GNU_AS
)
10529 (*targetm
.asm_out
.globalize_label
) (file
, name
);
10533 /* Set SImode div/mod functions, init_integral_libfuncs only initializes
10534 modes of word_mode and larger. Rename the TFmode libfuncs using the
10535 HPUX conventions. __divtf3 is used for XFmode. We need to keep it for
10536 backward compatibility. */
10539 ia64_init_libfuncs (void)
10541 set_optab_libfunc (sdiv_optab
, SImode
, "__divsi3");
10542 set_optab_libfunc (udiv_optab
, SImode
, "__udivsi3");
10543 set_optab_libfunc (smod_optab
, SImode
, "__modsi3");
10544 set_optab_libfunc (umod_optab
, SImode
, "__umodsi3");
10546 set_optab_libfunc (add_optab
, TFmode
, "_U_Qfadd");
10547 set_optab_libfunc (sub_optab
, TFmode
, "_U_Qfsub");
10548 set_optab_libfunc (smul_optab
, TFmode
, "_U_Qfmpy");
10549 set_optab_libfunc (sdiv_optab
, TFmode
, "_U_Qfdiv");
10550 set_optab_libfunc (neg_optab
, TFmode
, "_U_Qfneg");
10552 set_conv_libfunc (sext_optab
, TFmode
, SFmode
, "_U_Qfcnvff_sgl_to_quad");
10553 set_conv_libfunc (sext_optab
, TFmode
, DFmode
, "_U_Qfcnvff_dbl_to_quad");
10554 set_conv_libfunc (sext_optab
, TFmode
, XFmode
, "_U_Qfcnvff_f80_to_quad");
10555 set_conv_libfunc (trunc_optab
, SFmode
, TFmode
, "_U_Qfcnvff_quad_to_sgl");
10556 set_conv_libfunc (trunc_optab
, DFmode
, TFmode
, "_U_Qfcnvff_quad_to_dbl");
10557 set_conv_libfunc (trunc_optab
, XFmode
, TFmode
, "_U_Qfcnvff_quad_to_f80");
10559 set_conv_libfunc (sfix_optab
, SImode
, TFmode
, "_U_Qfcnvfxt_quad_to_sgl");
10560 set_conv_libfunc (sfix_optab
, DImode
, TFmode
, "_U_Qfcnvfxt_quad_to_dbl");
10561 set_conv_libfunc (sfix_optab
, TImode
, TFmode
, "_U_Qfcnvfxt_quad_to_quad");
10562 set_conv_libfunc (ufix_optab
, SImode
, TFmode
, "_U_Qfcnvfxut_quad_to_sgl");
10563 set_conv_libfunc (ufix_optab
, DImode
, TFmode
, "_U_Qfcnvfxut_quad_to_dbl");
10565 set_conv_libfunc (sfloat_optab
, TFmode
, SImode
, "_U_Qfcnvxf_sgl_to_quad");
10566 set_conv_libfunc (sfloat_optab
, TFmode
, DImode
, "_U_Qfcnvxf_dbl_to_quad");
10567 set_conv_libfunc (sfloat_optab
, TFmode
, TImode
, "_U_Qfcnvxf_quad_to_quad");
10568 /* HP-UX 11.23 libc does not have a function for unsigned
10569 SImode-to-TFmode conversion. */
10570 set_conv_libfunc (ufloat_optab
, TFmode
, DImode
, "_U_Qfcnvxuf_dbl_to_quad");
10573 /* Rename all the TFmode libfuncs using the HPUX conventions. */
10576 ia64_hpux_init_libfuncs (void)
10578 ia64_init_libfuncs ();
10580 /* The HP SI millicode division and mod functions expect DI arguments.
10581 By turning them off completely we avoid using both libgcc and the
10582 non-standard millicode routines and use the HP DI millicode routines
10585 set_optab_libfunc (sdiv_optab
, SImode
, 0);
10586 set_optab_libfunc (udiv_optab
, SImode
, 0);
10587 set_optab_libfunc (smod_optab
, SImode
, 0);
10588 set_optab_libfunc (umod_optab
, SImode
, 0);
10590 set_optab_libfunc (sdiv_optab
, DImode
, "__milli_divI");
10591 set_optab_libfunc (udiv_optab
, DImode
, "__milli_divU");
10592 set_optab_libfunc (smod_optab
, DImode
, "__milli_remI");
10593 set_optab_libfunc (umod_optab
, DImode
, "__milli_remU");
10595 /* HP-UX libc has TF min/max/abs routines in it. */
10596 set_optab_libfunc (smin_optab
, TFmode
, "_U_Qfmin");
10597 set_optab_libfunc (smax_optab
, TFmode
, "_U_Qfmax");
10598 set_optab_libfunc (abs_optab
, TFmode
, "_U_Qfabs");
10600 /* ia64_expand_compare uses this. */
10601 cmptf_libfunc
= init_one_libfunc ("_U_Qfcmp");
10603 /* These should never be used. */
10604 set_optab_libfunc (eq_optab
, TFmode
, 0);
10605 set_optab_libfunc (ne_optab
, TFmode
, 0);
10606 set_optab_libfunc (gt_optab
, TFmode
, 0);
10607 set_optab_libfunc (ge_optab
, TFmode
, 0);
10608 set_optab_libfunc (lt_optab
, TFmode
, 0);
10609 set_optab_libfunc (le_optab
, TFmode
, 0);
10612 /* Rename the division and modulus functions in VMS. */
10615 ia64_vms_init_libfuncs (void)
10617 set_optab_libfunc (sdiv_optab
, SImode
, "OTS$DIV_I");
10618 set_optab_libfunc (sdiv_optab
, DImode
, "OTS$DIV_L");
10619 set_optab_libfunc (udiv_optab
, SImode
, "OTS$DIV_UI");
10620 set_optab_libfunc (udiv_optab
, DImode
, "OTS$DIV_UL");
10621 set_optab_libfunc (smod_optab
, SImode
, "OTS$REM_I");
10622 set_optab_libfunc (smod_optab
, DImode
, "OTS$REM_L");
10623 set_optab_libfunc (umod_optab
, SImode
, "OTS$REM_UI");
10624 set_optab_libfunc (umod_optab
, DImode
, "OTS$REM_UL");
10625 abort_libfunc
= init_one_libfunc ("decc$abort");
10626 memcmp_libfunc
= init_one_libfunc ("decc$memcmp");
10627 #ifdef MEM_LIBFUNCS_INIT
10632 /* Rename the TFmode libfuncs available from soft-fp in glibc using
10633 the HPUX conventions. */
10636 ia64_sysv4_init_libfuncs (void)
10638 ia64_init_libfuncs ();
10640 /* These functions are not part of the HPUX TFmode interface. We
10641 use them instead of _U_Qfcmp, which doesn't work the way we
10643 set_optab_libfunc (eq_optab
, TFmode
, "_U_Qfeq");
10644 set_optab_libfunc (ne_optab
, TFmode
, "_U_Qfne");
10645 set_optab_libfunc (gt_optab
, TFmode
, "_U_Qfgt");
10646 set_optab_libfunc (ge_optab
, TFmode
, "_U_Qfge");
10647 set_optab_libfunc (lt_optab
, TFmode
, "_U_Qflt");
10648 set_optab_libfunc (le_optab
, TFmode
, "_U_Qfle");
10650 /* We leave out _U_Qfmin, _U_Qfmax and _U_Qfabs since soft-fp in
10651 glibc doesn't have them. */
10657 ia64_soft_fp_init_libfuncs (void)
10662 ia64_vms_valid_pointer_mode (enum machine_mode mode
)
10664 return (mode
== SImode
|| mode
== DImode
);
10667 /* For HPUX, it is illegal to have relocations in shared segments. */
10670 ia64_hpux_reloc_rw_mask (void)
10675 /* For others, relax this so that relocations to local data goes in
10676 read-only segments, but we still cannot allow global relocations
10677 in read-only segments. */
10680 ia64_reloc_rw_mask (void)
10682 return flag_pic
? 3 : 2;
10685 /* Return the section to use for X. The only special thing we do here
10686 is to honor small data. */
10689 ia64_select_rtx_section (enum machine_mode mode
, rtx x
,
10690 unsigned HOST_WIDE_INT align
)
10692 if (GET_MODE_SIZE (mode
) > 0
10693 && GET_MODE_SIZE (mode
) <= ia64_section_threshold
10694 && !TARGET_NO_SDATA
)
10695 return sdata_section
;
10697 return default_elf_select_rtx_section (mode
, x
, align
);
10700 static unsigned int
10701 ia64_section_type_flags (tree decl
, const char *name
, int reloc
)
10703 unsigned int flags
= 0;
10705 if (strcmp (name
, ".sdata") == 0
10706 || strncmp (name
, ".sdata.", 7) == 0
10707 || strncmp (name
, ".gnu.linkonce.s.", 16) == 0
10708 || strncmp (name
, ".sdata2.", 8) == 0
10709 || strncmp (name
, ".gnu.linkonce.s2.", 17) == 0
10710 || strcmp (name
, ".sbss") == 0
10711 || strncmp (name
, ".sbss.", 6) == 0
10712 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
10713 flags
= SECTION_SMALL
;
10715 flags
|= default_section_type_flags (decl
, name
, reloc
);
10719 /* Returns true if FNTYPE (a FUNCTION_TYPE or a METHOD_TYPE) returns a
10720 structure type and that the address of that type should be passed
10721 in out0, rather than in r8. */
10724 ia64_struct_retval_addr_is_first_parm_p (tree fntype
)
10726 tree ret_type
= TREE_TYPE (fntype
);
10728 /* The Itanium C++ ABI requires that out0, rather than r8, be used
10729 as the structure return address parameter, if the return value
10730 type has a non-trivial copy constructor or destructor. It is not
10731 clear if this same convention should be used for other
10732 programming languages. Until G++ 3.4, we incorrectly used r8 for
10733 these return values. */
10734 return (abi_version_at_least (2)
10736 && TYPE_MODE (ret_type
) == BLKmode
10737 && TREE_ADDRESSABLE (ret_type
)
10738 && strcmp (lang_hooks
.name
, "GNU C++") == 0);
10741 /* Output the assembler code for a thunk function. THUNK_DECL is the
10742 declaration for the thunk function itself, FUNCTION is the decl for
10743 the target function. DELTA is an immediate constant offset to be
10744 added to THIS. If VCALL_OFFSET is nonzero, the word at
10745 *(*this + vcall_offset) should be added to THIS. */
10748 ia64_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
10749 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
10752 rtx this_rtx
, funexp
;
10754 unsigned int this_parmno
;
10755 unsigned int this_regno
;
10758 reload_completed
= 1;
10759 epilogue_completed
= 1;
10761 /* Set things up as ia64_expand_prologue might. */
10762 last_scratch_gr_reg
= 15;
10764 memset (¤t_frame_info
, 0, sizeof (current_frame_info
));
10765 current_frame_info
.spill_cfa_off
= -16;
10766 current_frame_info
.n_input_regs
= 1;
10767 current_frame_info
.need_regstk
= (TARGET_REG_NAMES
!= 0);
10769 /* Mark the end of the (empty) prologue. */
10770 emit_note (NOTE_INSN_PROLOGUE_END
);
10772 /* Figure out whether "this" will be the first parameter (the
10773 typical case) or the second parameter (as happens when the
10774 virtual function returns certain class objects). */
10776 = (ia64_struct_retval_addr_is_first_parm_p (TREE_TYPE (thunk
))
10778 this_regno
= IN_REG (this_parmno
);
10779 if (!TARGET_REG_NAMES
)
10780 reg_names
[this_regno
] = ia64_reg_numbers
[this_parmno
];
10782 this_rtx
= gen_rtx_REG (Pmode
, this_regno
);
10784 /* Apply the constant offset, if required. */
10785 delta_rtx
= GEN_INT (delta
);
10788 rtx tmp
= gen_rtx_REG (ptr_mode
, this_regno
);
10789 REG_POINTER (tmp
) = 1;
10790 if (delta
&& satisfies_constraint_I (delta_rtx
))
10792 emit_insn (gen_ptr_extend_plus_imm (this_rtx
, tmp
, delta_rtx
));
10796 emit_insn (gen_ptr_extend (this_rtx
, tmp
));
10800 if (!satisfies_constraint_I (delta_rtx
))
10802 rtx tmp
= gen_rtx_REG (Pmode
, 2);
10803 emit_move_insn (tmp
, delta_rtx
);
10806 emit_insn (gen_adddi3 (this_rtx
, this_rtx
, delta_rtx
));
10809 /* Apply the offset from the vtable, if required. */
10812 rtx vcall_offset_rtx
= GEN_INT (vcall_offset
);
10813 rtx tmp
= gen_rtx_REG (Pmode
, 2);
10817 rtx t
= gen_rtx_REG (ptr_mode
, 2);
10818 REG_POINTER (t
) = 1;
10819 emit_move_insn (t
, gen_rtx_MEM (ptr_mode
, this_rtx
));
10820 if (satisfies_constraint_I (vcall_offset_rtx
))
10822 emit_insn (gen_ptr_extend_plus_imm (tmp
, t
, vcall_offset_rtx
));
10826 emit_insn (gen_ptr_extend (tmp
, t
));
10829 emit_move_insn (tmp
, gen_rtx_MEM (Pmode
, this_rtx
));
10833 if (!satisfies_constraint_J (vcall_offset_rtx
))
10835 rtx tmp2
= gen_rtx_REG (Pmode
, next_scratch_gr_reg ());
10836 emit_move_insn (tmp2
, vcall_offset_rtx
);
10837 vcall_offset_rtx
= tmp2
;
10839 emit_insn (gen_adddi3 (tmp
, tmp
, vcall_offset_rtx
));
10843 emit_insn (gen_zero_extendsidi2 (tmp
, gen_rtx_MEM (ptr_mode
, tmp
)));
10845 emit_move_insn (tmp
, gen_rtx_MEM (Pmode
, tmp
));
10847 emit_insn (gen_adddi3 (this_rtx
, this_rtx
, tmp
));
10850 /* Generate a tail call to the target function. */
10851 if (! TREE_USED (function
))
10853 assemble_external (function
);
10854 TREE_USED (function
) = 1;
10856 funexp
= XEXP (DECL_RTL (function
), 0);
10857 funexp
= gen_rtx_MEM (FUNCTION_MODE
, funexp
);
10858 ia64_expand_call (NULL_RTX
, funexp
, NULL_RTX
, 1);
10859 insn
= get_last_insn ();
10860 SIBLING_CALL_P (insn
) = 1;
10862 /* Code generation for calls relies on splitting. */
10863 reload_completed
= 1;
10864 epilogue_completed
= 1;
10865 try_split (PATTERN (insn
), insn
, 0);
10869 /* Run just enough of rest_of_compilation to get the insns emitted.
10870 There's not really enough bulk here to make other passes such as
10871 instruction scheduling worth while. Note that use_thunk calls
10872 assemble_start_function and assemble_end_function. */
10874 emit_all_insn_group_barriers (NULL
);
10875 insn
= get_insns ();
10876 shorten_branches (insn
);
10877 final_start_function (insn
, file
, 1);
10878 final (insn
, file
, 1);
10879 final_end_function ();
10881 reload_completed
= 0;
10882 epilogue_completed
= 0;
10885 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
10888 ia64_struct_value_rtx (tree fntype
,
10889 int incoming ATTRIBUTE_UNUSED
)
10891 if (TARGET_ABI_OPEN_VMS
||
10892 (fntype
&& ia64_struct_retval_addr_is_first_parm_p (fntype
)))
10894 return gen_rtx_REG (Pmode
, GR_REG (8));
10898 ia64_scalar_mode_supported_p (enum machine_mode mode
)
10924 ia64_vector_mode_supported_p (enum machine_mode mode
)
10941 /* Implement the FUNCTION_PROFILER macro. */
10944 ia64_output_function_profiler (FILE *file
, int labelno
)
10946 bool indirect_call
;
10948 /* If the function needs a static chain and the static chain
10949 register is r15, we use an indirect call so as to bypass
10950 the PLT stub in case the executable is dynamically linked,
10951 because the stub clobbers r15 as per 5.3.6 of the psABI.
10952 We don't need to do that in non canonical PIC mode. */
10954 if (cfun
->static_chain_decl
&& !TARGET_NO_PIC
&& !TARGET_AUTO_PIC
)
10956 gcc_assert (STATIC_CHAIN_REGNUM
== 15);
10957 indirect_call
= true;
10960 indirect_call
= false;
10963 fputs ("\t.prologue 4, r40\n", file
);
10965 fputs ("\t.prologue\n\t.save ar.pfs, r40\n", file
);
10966 fputs ("\talloc out0 = ar.pfs, 8, 0, 4, 0\n", file
);
10968 if (NO_PROFILE_COUNTERS
)
10969 fputs ("\tmov out3 = r0\n", file
);
10973 ASM_GENERATE_INTERNAL_LABEL (buf
, "LP", labelno
);
10975 if (TARGET_AUTO_PIC
)
10976 fputs ("\tmovl out3 = @gprel(", file
);
10978 fputs ("\taddl out3 = @ltoff(", file
);
10979 assemble_name (file
, buf
);
10980 if (TARGET_AUTO_PIC
)
10981 fputs (")\n", file
);
10983 fputs ("), r1\n", file
);
10987 fputs ("\taddl r14 = @ltoff(@fptr(_mcount)), r1\n", file
);
10988 fputs ("\t;;\n", file
);
10990 fputs ("\t.save rp, r42\n", file
);
10991 fputs ("\tmov out2 = b0\n", file
);
10993 fputs ("\tld8 r14 = [r14]\n\t;;\n", file
);
10994 fputs ("\t.body\n", file
);
10995 fputs ("\tmov out1 = r1\n", file
);
10998 fputs ("\tld8 r16 = [r14], 8\n\t;;\n", file
);
10999 fputs ("\tmov b6 = r16\n", file
);
11000 fputs ("\tld8 r1 = [r14]\n", file
);
11001 fputs ("\tbr.call.sptk.many b0 = b6\n\t;;\n", file
);
11004 fputs ("\tbr.call.sptk.many b0 = _mcount\n\t;;\n", file
);
11007 static GTY(()) rtx mcount_func_rtx
;
11009 gen_mcount_func_rtx (void)
11011 if (!mcount_func_rtx
)
11012 mcount_func_rtx
= init_one_libfunc ("_mcount");
11013 return mcount_func_rtx
;
11017 ia64_profile_hook (int labelno
)
11021 if (NO_PROFILE_COUNTERS
)
11022 label
= const0_rtx
;
11026 const char *label_name
;
11027 ASM_GENERATE_INTERNAL_LABEL (buf
, "LP", labelno
);
11028 label_name
= ggc_strdup ((*targetm
.strip_name_encoding
) (buf
));
11029 label
= gen_rtx_SYMBOL_REF (Pmode
, label_name
);
11030 SYMBOL_REF_FLAGS (label
) = SYMBOL_FLAG_LOCAL
;
11032 ip
= gen_reg_rtx (Pmode
);
11033 emit_insn (gen_ip_value (ip
));
11034 emit_library_call (gen_mcount_func_rtx (), LCT_NORMAL
,
11036 gen_rtx_REG (Pmode
, BR_REG (0)), Pmode
,
11041 /* Return the mangling of TYPE if it is an extended fundamental type. */
11043 static const char *
11044 ia64_mangle_type (const_tree type
)
11046 type
= TYPE_MAIN_VARIANT (type
);
11048 if (TREE_CODE (type
) != VOID_TYPE
&& TREE_CODE (type
) != BOOLEAN_TYPE
11049 && TREE_CODE (type
) != INTEGER_TYPE
&& TREE_CODE (type
) != REAL_TYPE
)
11052 /* On HP-UX, "long double" is mangled as "e" so __float128 is
11054 if (!TARGET_HPUX
&& TYPE_MODE (type
) == TFmode
)
11056 /* On HP-UX, "e" is not available as a mangling of __float80 so use
11057 an extended mangling. Elsewhere, "e" is available since long
11058 double is 80 bits. */
11059 if (TYPE_MODE (type
) == XFmode
)
11060 return TARGET_HPUX
? "u9__float80" : "e";
11061 if (TYPE_MODE (type
) == RFmode
)
11062 return "u7__fpreg";
11066 /* Return the diagnostic message string if conversion from FROMTYPE to
11067 TOTYPE is not allowed, NULL otherwise. */
11068 static const char *
11069 ia64_invalid_conversion (const_tree fromtype
, const_tree totype
)
11071 /* Reject nontrivial conversion to or from __fpreg. */
11072 if (TYPE_MODE (fromtype
) == RFmode
11073 && TYPE_MODE (totype
) != RFmode
11074 && TYPE_MODE (totype
) != VOIDmode
)
11075 return N_("invalid conversion from %<__fpreg%>");
11076 if (TYPE_MODE (totype
) == RFmode
11077 && TYPE_MODE (fromtype
) != RFmode
)
11078 return N_("invalid conversion to %<__fpreg%>");
11082 /* Return the diagnostic message string if the unary operation OP is
11083 not permitted on TYPE, NULL otherwise. */
11084 static const char *
11085 ia64_invalid_unary_op (int op
, const_tree type
)
11087 /* Reject operations on __fpreg other than unary + or &. */
11088 if (TYPE_MODE (type
) == RFmode
11089 && op
!= CONVERT_EXPR
11090 && op
!= ADDR_EXPR
)
11091 return N_("invalid operation on %<__fpreg%>");
11095 /* Return the diagnostic message string if the binary operation OP is
11096 not permitted on TYPE1 and TYPE2, NULL otherwise. */
11097 static const char *
11098 ia64_invalid_binary_op (int op ATTRIBUTE_UNUSED
, const_tree type1
, const_tree type2
)
11100 /* Reject operations on __fpreg. */
11101 if (TYPE_MODE (type1
) == RFmode
|| TYPE_MODE (type2
) == RFmode
)
11102 return N_("invalid operation on %<__fpreg%>");
11106 /* HP-UX version_id attribute.
11107 For object foo, if the version_id is set to 1234 put out an alias
11108 of '.alias foo "foo{1234}" We can't use "foo{1234}" in anything
11109 other than an alias statement because it is an illegal symbol name. */
11112 ia64_handle_version_id_attribute (tree
*node ATTRIBUTE_UNUSED
,
11113 tree name ATTRIBUTE_UNUSED
,
11115 int flags ATTRIBUTE_UNUSED
,
11116 bool *no_add_attrs
)
11118 tree arg
= TREE_VALUE (args
);
11120 if (TREE_CODE (arg
) != STRING_CST
)
11122 error("version attribute is not a string");
11123 *no_add_attrs
= true;
11129 /* Target hook for c_mode_for_suffix. */
11131 static enum machine_mode
11132 ia64_c_mode_for_suffix (char suffix
)
11142 static GTY(()) rtx ia64_dconst_0_5_rtx
;
11145 ia64_dconst_0_5 (void)
11147 if (! ia64_dconst_0_5_rtx
)
11149 REAL_VALUE_TYPE rv
;
11150 real_from_string (&rv
, "0.5");
11151 ia64_dconst_0_5_rtx
= const_double_from_real_value (rv
, DFmode
);
11153 return ia64_dconst_0_5_rtx
;
11156 static GTY(()) rtx ia64_dconst_0_375_rtx
;
11159 ia64_dconst_0_375 (void)
11161 if (! ia64_dconst_0_375_rtx
)
11163 REAL_VALUE_TYPE rv
;
11164 real_from_string (&rv
, "0.375");
11165 ia64_dconst_0_375_rtx
= const_double_from_real_value (rv
, DFmode
);
11167 return ia64_dconst_0_375_rtx
;
11170 static enum machine_mode
11171 ia64_get_reg_raw_mode (int regno
)
11173 if (FR_REGNO_P (regno
))
11175 return default_get_reg_raw_mode(regno
);
11178 /* Implement TARGET_MEMBER_TYPE_FORCES_BLK. ??? Might not be needed
11182 ia64_member_type_forces_blk (const_tree
, enum machine_mode mode
)
11184 return TARGET_HPUX
&& mode
== TFmode
;
11187 /* Always default to .text section until HP-UX linker is fixed. */
11189 ATTRIBUTE_UNUSED
static section
*
11190 ia64_hpux_function_section (tree decl ATTRIBUTE_UNUSED
,
11191 enum node_frequency freq ATTRIBUTE_UNUSED
,
11192 bool startup ATTRIBUTE_UNUSED
,
11193 bool exit ATTRIBUTE_UNUSED
)
11198 /* Construct (set target (vec_select op0 (parallel perm))) and
11199 return true if that's a valid instruction in the active ISA. */
11202 expand_vselect (rtx target
, rtx op0
, const unsigned char *perm
, unsigned nelt
)
11204 rtx rperm
[MAX_VECT_LEN
], x
;
11207 for (i
= 0; i
< nelt
; ++i
)
11208 rperm
[i
] = GEN_INT (perm
[i
]);
11210 x
= gen_rtx_PARALLEL (VOIDmode
, gen_rtvec_v (nelt
, rperm
));
11211 x
= gen_rtx_VEC_SELECT (GET_MODE (target
), op0
, x
);
11212 x
= gen_rtx_SET (VOIDmode
, target
, x
);
11215 if (recog_memoized (x
) < 0)
11223 /* Similar, but generate a vec_concat from op0 and op1 as well. */
11226 expand_vselect_vconcat (rtx target
, rtx op0
, rtx op1
,
11227 const unsigned char *perm
, unsigned nelt
)
11229 enum machine_mode v2mode
;
11232 v2mode
= GET_MODE_2XWIDER_MODE (GET_MODE (op0
));
11233 x
= gen_rtx_VEC_CONCAT (v2mode
, op0
, op1
);
11234 return expand_vselect (target
, x
, perm
, nelt
);
11237 /* Try to expand a no-op permutation. */
11240 expand_vec_perm_identity (struct expand_vec_perm_d
*d
)
11242 unsigned i
, nelt
= d
->nelt
;
11244 for (i
= 0; i
< nelt
; ++i
)
11245 if (d
->perm
[i
] != i
)
11249 emit_move_insn (d
->target
, d
->op0
);
11254 /* Try to expand D via a shrp instruction. */
11257 expand_vec_perm_shrp (struct expand_vec_perm_d
*d
)
11259 unsigned i
, nelt
= d
->nelt
, shift
, mask
;
11262 /* ??? Don't force V2SFmode into the integer registers. */
11263 if (d
->vmode
== V2SFmode
)
11266 mask
= (d
->one_operand_p
? nelt
- 1 : 2 * nelt
- 1);
11268 shift
= d
->perm
[0];
11269 if (BYTES_BIG_ENDIAN
&& shift
> nelt
)
11272 for (i
= 1; i
< nelt
; ++i
)
11273 if (d
->perm
[i
] != ((shift
+ i
) & mask
))
11279 hi
= shift
< nelt
? d
->op1
: d
->op0
;
11280 lo
= shift
< nelt
? d
->op0
: d
->op1
;
11284 shift
*= GET_MODE_UNIT_SIZE (d
->vmode
) * BITS_PER_UNIT
;
11286 /* We've eliminated the shift 0 case via expand_vec_perm_identity. */
11287 gcc_assert (IN_RANGE (shift
, 1, 63));
11289 /* Recall that big-endian elements are numbered starting at the top of
11290 the register. Ideally we'd have a shift-left-pair. But since we
11291 don't, convert to a shift the other direction. */
11292 if (BYTES_BIG_ENDIAN
)
11293 shift
= 64 - shift
;
11295 tmp
= gen_reg_rtx (DImode
);
11296 hi
= gen_lowpart (DImode
, hi
);
11297 lo
= gen_lowpart (DImode
, lo
);
11298 emit_insn (gen_shrp (tmp
, hi
, lo
, GEN_INT (shift
)));
11300 emit_move_insn (d
->target
, gen_lowpart (d
->vmode
, tmp
));
11304 /* Try to instantiate D in a single instruction. */
11307 expand_vec_perm_1 (struct expand_vec_perm_d
*d
)
11309 unsigned i
, nelt
= d
->nelt
;
11310 unsigned char perm2
[MAX_VECT_LEN
];
11312 /* Try single-operand selections. */
11313 if (d
->one_operand_p
)
11315 if (expand_vec_perm_identity (d
))
11317 if (expand_vselect (d
->target
, d
->op0
, d
->perm
, nelt
))
11321 /* Try two operand selections. */
11322 if (expand_vselect_vconcat (d
->target
, d
->op0
, d
->op1
, d
->perm
, nelt
))
11325 /* Recognize interleave style patterns with reversed operands. */
11326 if (!d
->one_operand_p
)
11328 for (i
= 0; i
< nelt
; ++i
)
11330 unsigned e
= d
->perm
[i
];
11338 if (expand_vselect_vconcat (d
->target
, d
->op1
, d
->op0
, perm2
, nelt
))
11342 if (expand_vec_perm_shrp (d
))
11345 /* ??? Look for deposit-like permutations where most of the result
11346 comes from one vector unchanged and the rest comes from a
11347 sequential hunk of the other vector. */
11352 /* Pattern match broadcast permutations. */
11355 expand_vec_perm_broadcast (struct expand_vec_perm_d
*d
)
11357 unsigned i
, elt
, nelt
= d
->nelt
;
11358 unsigned char perm2
[2];
11362 if (!d
->one_operand_p
)
11366 for (i
= 1; i
< nelt
; ++i
)
11367 if (d
->perm
[i
] != elt
)
11374 /* Implementable by interleave. */
11376 perm2
[1] = elt
+ 2;
11377 ok
= expand_vselect_vconcat (d
->target
, d
->op0
, d
->op0
, perm2
, 2);
11382 /* Implementable by extract + broadcast. */
11383 if (BYTES_BIG_ENDIAN
)
11385 elt
*= BITS_PER_UNIT
;
11386 temp
= gen_reg_rtx (DImode
);
11387 emit_insn (gen_extzv (temp
, gen_lowpart (DImode
, d
->op0
),
11388 GEN_INT (8), GEN_INT (elt
)));
11389 emit_insn (gen_mux1_brcst_qi (d
->target
, gen_lowpart (QImode
, temp
)));
11393 /* Should have been matched directly by vec_select. */
11395 gcc_unreachable ();
11401 /* A subroutine of ia64_expand_vec_perm_const_1. Try to simplify a
11402 two vector permutation into a single vector permutation by using
11403 an interleave operation to merge the vectors. */
11406 expand_vec_perm_interleave_2 (struct expand_vec_perm_d
*d
)
11408 struct expand_vec_perm_d dremap
, dfinal
;
11409 unsigned char remap
[2 * MAX_VECT_LEN
];
11410 unsigned contents
, i
, nelt
, nelt2
;
11411 unsigned h0
, h1
, h2
, h3
;
11415 if (d
->one_operand_p
)
11421 /* Examine from whence the elements come. */
11423 for (i
= 0; i
< nelt
; ++i
)
11424 contents
|= 1u << d
->perm
[i
];
11426 memset (remap
, 0xff, sizeof (remap
));
11429 h0
= (1u << nelt2
) - 1;
11432 h3
= h0
<< (nelt
+ nelt2
);
11434 if ((contents
& (h0
| h2
)) == contents
) /* punpck even halves */
11436 for (i
= 0; i
< nelt
; ++i
)
11438 unsigned which
= i
/ 2 + (i
& 1 ? nelt
: 0);
11440 dremap
.perm
[i
] = which
;
11443 else if ((contents
& (h1
| h3
)) == contents
) /* punpck odd halves */
11445 for (i
= 0; i
< nelt
; ++i
)
11447 unsigned which
= i
/ 2 + nelt2
+ (i
& 1 ? nelt
: 0);
11449 dremap
.perm
[i
] = which
;
11452 else if ((contents
& 0x5555) == contents
) /* mix even elements */
11454 for (i
= 0; i
< nelt
; ++i
)
11456 unsigned which
= (i
& ~1) + (i
& 1 ? nelt
: 0);
11458 dremap
.perm
[i
] = which
;
11461 else if ((contents
& 0xaaaa) == contents
) /* mix odd elements */
11463 for (i
= 0; i
< nelt
; ++i
)
11465 unsigned which
= (i
| 1) + (i
& 1 ? nelt
: 0);
11467 dremap
.perm
[i
] = which
;
11470 else if (floor_log2 (contents
) - ctz_hwi (contents
) < (int)nelt
) /* shrp */
11472 unsigned shift
= ctz_hwi (contents
);
11473 for (i
= 0; i
< nelt
; ++i
)
11475 unsigned which
= (i
+ shift
) & (2 * nelt
- 1);
11477 dremap
.perm
[i
] = which
;
11483 /* Use the remapping array set up above to move the elements from their
11484 swizzled locations into their final destinations. */
11486 for (i
= 0; i
< nelt
; ++i
)
11488 unsigned e
= remap
[d
->perm
[i
]];
11489 gcc_assert (e
< nelt
);
11490 dfinal
.perm
[i
] = e
;
11492 dfinal
.op0
= gen_reg_rtx (dfinal
.vmode
);
11493 dfinal
.op1
= dfinal
.op0
;
11494 dfinal
.one_operand_p
= true;
11495 dremap
.target
= dfinal
.op0
;
11497 /* Test if the final remap can be done with a single insn. For V4HImode
11498 this *will* succeed. For V8QImode or V2SImode it may not. */
11500 ok
= expand_vec_perm_1 (&dfinal
);
11501 seq
= get_insns ();
11508 ok
= expand_vec_perm_1 (&dremap
);
11515 /* A subroutine of ia64_expand_vec_perm_const_1. Emit a full V4HImode
11516 constant permutation via two mux2 and a merge. */
11519 expand_vec_perm_v4hi_5 (struct expand_vec_perm_d
*d
)
11521 unsigned char perm2
[4];
11524 rtx t0
, t1
, mask
, x
;
11527 if (d
->vmode
!= V4HImode
|| d
->one_operand_p
)
11532 for (i
= 0; i
< 4; ++i
)
11534 perm2
[i
] = d
->perm
[i
] & 3;
11535 rmask
[i
] = (d
->perm
[i
] & 4 ? const0_rtx
: constm1_rtx
);
11537 mask
= gen_rtx_CONST_VECTOR (V4HImode
, gen_rtvec_v (4, rmask
));
11538 mask
= force_reg (V4HImode
, mask
);
11540 t0
= gen_reg_rtx (V4HImode
);
11541 t1
= gen_reg_rtx (V4HImode
);
11543 ok
= expand_vselect (t0
, d
->op0
, perm2
, 4);
11545 ok
= expand_vselect (t1
, d
->op1
, perm2
, 4);
11548 x
= gen_rtx_AND (V4HImode
, mask
, t0
);
11549 emit_insn (gen_rtx_SET (VOIDmode
, t0
, x
));
11551 x
= gen_rtx_NOT (V4HImode
, mask
);
11552 x
= gen_rtx_AND (V4HImode
, x
, t1
);
11553 emit_insn (gen_rtx_SET (VOIDmode
, t1
, x
));
11555 x
= gen_rtx_IOR (V4HImode
, t0
, t1
);
11556 emit_insn (gen_rtx_SET (VOIDmode
, d
->target
, x
));
11561 /* The guts of ia64_expand_vec_perm_const, also used by the ok hook.
11562 With all of the interface bits taken care of, perform the expansion
11563 in D and return true on success. */
11566 ia64_expand_vec_perm_const_1 (struct expand_vec_perm_d
*d
)
11568 if (expand_vec_perm_1 (d
))
11570 if (expand_vec_perm_broadcast (d
))
11572 if (expand_vec_perm_interleave_2 (d
))
11574 if (expand_vec_perm_v4hi_5 (d
))
11580 ia64_expand_vec_perm_const (rtx operands
[4])
11582 struct expand_vec_perm_d d
;
11583 unsigned char perm
[MAX_VECT_LEN
];
11584 int i
, nelt
, which
;
11587 d
.target
= operands
[0];
11588 d
.op0
= operands
[1];
11589 d
.op1
= operands
[2];
11592 d
.vmode
= GET_MODE (d
.target
);
11593 gcc_assert (VECTOR_MODE_P (d
.vmode
));
11594 d
.nelt
= nelt
= GET_MODE_NUNITS (d
.vmode
);
11595 d
.testing_p
= false;
11597 gcc_assert (GET_CODE (sel
) == CONST_VECTOR
);
11598 gcc_assert (XVECLEN (sel
, 0) == nelt
);
11599 gcc_checking_assert (sizeof (d
.perm
) == sizeof (perm
));
11601 for (i
= which
= 0; i
< nelt
; ++i
)
11603 rtx e
= XVECEXP (sel
, 0, i
);
11604 int ei
= INTVAL (e
) & (2 * nelt
- 1);
11606 which
|= (ei
< nelt
? 1 : 2);
11617 if (!rtx_equal_p (d
.op0
, d
.op1
))
11619 d
.one_operand_p
= false;
11623 /* The elements of PERM do not suggest that only the first operand
11624 is used, but both operands are identical. Allow easier matching
11625 of the permutation by folding the permutation into the single
11627 for (i
= 0; i
< nelt
; ++i
)
11628 if (d
.perm
[i
] >= nelt
)
11634 d
.one_operand_p
= true;
11638 for (i
= 0; i
< nelt
; ++i
)
11641 d
.one_operand_p
= true;
11645 if (ia64_expand_vec_perm_const_1 (&d
))
11648 /* If the mask says both arguments are needed, but they are the same,
11649 the above tried to expand with one_operand_p true. If that didn't
11650 work, retry with one_operand_p false, as that's what we used in _ok. */
11651 if (which
== 3 && d
.one_operand_p
)
11653 memcpy (d
.perm
, perm
, sizeof (perm
));
11654 d
.one_operand_p
= false;
11655 return ia64_expand_vec_perm_const_1 (&d
);
11661 /* Implement targetm.vectorize.vec_perm_const_ok. */
11664 ia64_vectorize_vec_perm_const_ok (enum machine_mode vmode
,
11665 const unsigned char *sel
)
11667 struct expand_vec_perm_d d
;
11668 unsigned int i
, nelt
, which
;
11672 d
.nelt
= nelt
= GET_MODE_NUNITS (d
.vmode
);
11673 d
.testing_p
= true;
11675 /* Extract the values from the vector CST into the permutation
11677 memcpy (d
.perm
, sel
, nelt
);
11678 for (i
= which
= 0; i
< nelt
; ++i
)
11680 unsigned char e
= d
.perm
[i
];
11681 gcc_assert (e
< 2 * nelt
);
11682 which
|= (e
< nelt
? 1 : 2);
11685 /* For all elements from second vector, fold the elements to first. */
11687 for (i
= 0; i
< nelt
; ++i
)
11690 /* Check whether the mask can be applied to the vector type. */
11691 d
.one_operand_p
= (which
!= 3);
11693 /* Otherwise we have to go through the motions and see if we can
11694 figure out how to generate the requested permutation. */
11695 d
.target
= gen_raw_REG (d
.vmode
, LAST_VIRTUAL_REGISTER
+ 1);
11696 d
.op1
= d
.op0
= gen_raw_REG (d
.vmode
, LAST_VIRTUAL_REGISTER
+ 2);
11697 if (!d
.one_operand_p
)
11698 d
.op1
= gen_raw_REG (d
.vmode
, LAST_VIRTUAL_REGISTER
+ 3);
11701 ret
= ia64_expand_vec_perm_const_1 (&d
);
11708 ia64_expand_vec_setv2sf (rtx operands
[3])
11710 struct expand_vec_perm_d d
;
11711 unsigned int which
;
11714 d
.target
= operands
[0];
11715 d
.op0
= operands
[0];
11716 d
.op1
= gen_reg_rtx (V2SFmode
);
11717 d
.vmode
= V2SFmode
;
11719 d
.one_operand_p
= false;
11720 d
.testing_p
= false;
11722 which
= INTVAL (operands
[2]);
11723 gcc_assert (which
<= 1);
11724 d
.perm
[0] = 1 - which
;
11725 d
.perm
[1] = which
+ 2;
11727 emit_insn (gen_fpack (d
.op1
, operands
[1], CONST0_RTX (SFmode
)));
11729 ok
= ia64_expand_vec_perm_const_1 (&d
);
11734 ia64_expand_vec_perm_even_odd (rtx target
, rtx op0
, rtx op1
, int odd
)
11736 struct expand_vec_perm_d d
;
11737 enum machine_mode vmode
= GET_MODE (target
);
11738 unsigned int i
, nelt
= GET_MODE_NUNITS (vmode
);
11746 d
.one_operand_p
= false;
11747 d
.testing_p
= false;
11749 for (i
= 0; i
< nelt
; ++i
)
11750 d
.perm
[i
] = i
* 2 + odd
;
11752 ok
= ia64_expand_vec_perm_const_1 (&d
);
11756 #include "gt-ia64.h"