PR testsuite/39776
[official-gcc.git] / gcc / targhooks.c
blob7035c4943314eb6826972b6309bdfa64acdd6161
1 /* Default target hook functions.
2 Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* The migration of target macros to target hooks works as follows:
23 1. Create a target hook that uses the existing target macros to
24 implement the same functionality.
26 2. Convert all the MI files to use the hook instead of the macro.
28 3. Repeat for a majority of the remaining target macros. This will
29 take some time.
31 4. Tell target maintainers to start migrating.
33 5. Eventually convert the backends to override the hook instead of
34 defining the macros. This will take some time too.
36 6. TBD when, poison the macros. Unmigrated targets will break at
37 this point.
39 Note that we expect steps 1-3 to be done by the people that
40 understand what the MI does with each macro, and step 5 to be done
41 by the target maintainers for their respective targets.
43 Note that steps 1 and 2 don't have to be done together, but no
44 target can override the new hook until step 2 is complete for it.
46 Once the macros are poisoned, we will revert to the old migration
47 rules - migrate the macro, callers, and targets all at once. This
48 comment can thus be removed at that point. */
50 #include "config.h"
51 #include "system.h"
52 #include "coretypes.h"
53 #include "tm.h"
54 #include "machmode.h"
55 #include "rtl.h"
56 #include "tree.h"
57 #include "expr.h"
58 #include "output.h"
59 #include "toplev.h"
60 #include "function.h"
61 #include "target.h"
62 #include "tm_p.h"
63 #include "target-def.h"
64 #include "ggc.h"
65 #include "hard-reg-set.h"
66 #include "reload.h"
67 #include "optabs.h"
68 #include "recog.h"
71 void
72 default_external_libcall (rtx fun ATTRIBUTE_UNUSED)
74 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
75 ASM_OUTPUT_EXTERNAL_LIBCALL(asm_out_file, fun);
76 #endif
79 int
80 default_unspec_may_trap_p (const_rtx x, unsigned flags)
82 int i;
84 if (GET_CODE (x) == UNSPEC_VOLATILE
85 /* Any floating arithmetic may trap. */
86 || (SCALAR_FLOAT_MODE_P (GET_MODE (x))
87 && flag_trapping_math))
88 return 1;
90 for (i = 0; i < XVECLEN (x, 0); ++i)
92 if (may_trap_p_1 (XVECEXP (x, 0, i), flags))
93 return 1;
96 return 0;
99 enum machine_mode
100 default_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
102 if (m1 == m2)
103 return m1;
104 return VOIDmode;
107 bool
108 default_return_in_memory (const_tree type,
109 const_tree fntype ATTRIBUTE_UNUSED)
111 return (TYPE_MODE (type) == BLKmode);
115 default_expand_builtin_saveregs (void)
117 error ("__builtin_saveregs not supported by this target");
118 return const0_rtx;
121 void
122 default_setup_incoming_varargs (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
123 enum machine_mode mode ATTRIBUTE_UNUSED,
124 tree type ATTRIBUTE_UNUSED,
125 int *pretend_arg_size ATTRIBUTE_UNUSED,
126 int second_time ATTRIBUTE_UNUSED)
130 /* The default implementation of TARGET_BUILTIN_SETJMP_FRAME_VALUE. */
133 default_builtin_setjmp_frame_value (void)
135 return virtual_stack_vars_rtx;
138 /* Generic hook that takes a CUMULATIVE_ARGS pointer and returns false. */
140 bool
141 hook_bool_CUMULATIVE_ARGS_false (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED)
143 return false;
146 bool
147 default_pretend_outgoing_varargs_named (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED)
149 return (targetm.calls.setup_incoming_varargs
150 != default_setup_incoming_varargs);
153 enum machine_mode
154 default_eh_return_filter_mode (void)
156 return targetm.unwind_word_mode ();
159 enum machine_mode
160 default_libgcc_cmp_return_mode (void)
162 return word_mode;
165 enum machine_mode
166 default_libgcc_shift_count_mode (void)
168 return word_mode;
171 enum machine_mode
172 default_unwind_word_mode (void)
174 return word_mode;
177 /* The default implementation of TARGET_SHIFT_TRUNCATION_MASK. */
179 unsigned HOST_WIDE_INT
180 default_shift_truncation_mask (enum machine_mode mode)
182 return SHIFT_COUNT_TRUNCATED ? GET_MODE_BITSIZE (mode) - 1 : 0;
185 /* The default implementation of TARGET_MIN_DIVISIONS_FOR_RECIP_MUL. */
187 unsigned int
188 default_min_divisions_for_recip_mul (enum machine_mode mode ATTRIBUTE_UNUSED)
190 return have_insn_for (DIV, mode) ? 3 : 2;
193 /* The default implementation of TARGET_MODE_REP_EXTENDED. */
196 default_mode_rep_extended (enum machine_mode mode ATTRIBUTE_UNUSED,
197 enum machine_mode mode_rep ATTRIBUTE_UNUSED)
199 return UNKNOWN;
202 /* Generic hook that takes a CUMULATIVE_ARGS pointer and returns true. */
204 bool
205 hook_bool_CUMULATIVE_ARGS_true (CUMULATIVE_ARGS * a ATTRIBUTE_UNUSED)
207 return true;
210 /* Return machine mode for non-standard suffix
211 or VOIDmode if non-standard suffixes are unsupported. */
212 enum machine_mode
213 default_mode_for_suffix (char suffix ATTRIBUTE_UNUSED)
215 return VOIDmode;
218 /* The generic C++ ABI specifies this is a 64-bit value. */
219 tree
220 default_cxx_guard_type (void)
222 return long_long_integer_type_node;
226 /* Returns the size of the cookie to use when allocating an array
227 whose elements have the indicated TYPE. Assumes that it is already
228 known that a cookie is needed. */
230 tree
231 default_cxx_get_cookie_size (tree type)
233 tree cookie_size;
235 /* We need to allocate an additional max (sizeof (size_t), alignof
236 (true_type)) bytes. */
237 tree sizetype_size;
238 tree type_align;
240 sizetype_size = size_in_bytes (sizetype);
241 type_align = size_int (TYPE_ALIGN_UNIT (type));
242 if (INT_CST_LT_UNSIGNED (type_align, sizetype_size))
243 cookie_size = sizetype_size;
244 else
245 cookie_size = type_align;
247 return cookie_size;
250 /* Return true if a parameter must be passed by reference. This version
251 of the TARGET_PASS_BY_REFERENCE hook uses just MUST_PASS_IN_STACK. */
253 bool
254 hook_pass_by_reference_must_pass_in_stack (CUMULATIVE_ARGS *c ATTRIBUTE_UNUSED,
255 enum machine_mode mode ATTRIBUTE_UNUSED, const_tree type ATTRIBUTE_UNUSED,
256 bool named_arg ATTRIBUTE_UNUSED)
258 return targetm.calls.must_pass_in_stack (mode, type);
261 /* Return true if a parameter follows callee copies conventions. This
262 version of the hook is true for all named arguments. */
264 bool
265 hook_callee_copies_named (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
266 enum machine_mode mode ATTRIBUTE_UNUSED,
267 const_tree type ATTRIBUTE_UNUSED, bool named)
269 return named;
272 /* Emit any directives required to unwind this instruction. */
274 void
275 default_unwind_emit (FILE * stream ATTRIBUTE_UNUSED,
276 rtx insn ATTRIBUTE_UNUSED)
278 /* Should never happen. */
279 gcc_unreachable ();
282 /* True if MODE is valid for the target. By "valid", we mean able to
283 be manipulated in non-trivial ways. In particular, this means all
284 the arithmetic is supported.
286 By default we guess this means that any C type is supported. If
287 we can't map the mode back to a type that would be available in C,
288 then reject it. Special case, here, is the double-word arithmetic
289 supported by optabs.c. */
291 bool
292 default_scalar_mode_supported_p (enum machine_mode mode)
294 int precision = GET_MODE_PRECISION (mode);
296 switch (GET_MODE_CLASS (mode))
298 case MODE_PARTIAL_INT:
299 case MODE_INT:
300 if (precision == CHAR_TYPE_SIZE)
301 return true;
302 if (precision == SHORT_TYPE_SIZE)
303 return true;
304 if (precision == INT_TYPE_SIZE)
305 return true;
306 if (precision == LONG_TYPE_SIZE)
307 return true;
308 if (precision == LONG_LONG_TYPE_SIZE)
309 return true;
310 if (precision == 2 * BITS_PER_WORD)
311 return true;
312 return false;
314 case MODE_FLOAT:
315 if (precision == FLOAT_TYPE_SIZE)
316 return true;
317 if (precision == DOUBLE_TYPE_SIZE)
318 return true;
319 if (precision == LONG_DOUBLE_TYPE_SIZE)
320 return true;
321 return false;
323 case MODE_DECIMAL_FLOAT:
324 case MODE_FRACT:
325 case MODE_UFRACT:
326 case MODE_ACCUM:
327 case MODE_UACCUM:
328 return false;
330 default:
331 gcc_unreachable ();
335 /* True if the target supports decimal floating point. */
337 bool
338 default_decimal_float_supported_p (void)
340 return ENABLE_DECIMAL_FLOAT;
343 /* True if the target supports fixed-point arithmetic. */
345 bool
346 default_fixed_point_supported_p (void)
348 return ENABLE_FIXED_POINT;
351 /* NULL if INSN insn is valid within a low-overhead loop, otherwise returns
352 an error message.
354 This function checks whether a given INSN is valid within a low-overhead
355 loop. If INSN is invalid it returns the reason for that, otherwise it
356 returns NULL. A called function may clobber any special registers required
357 for low-overhead looping. Additionally, some targets (eg, PPC) use the count
358 register for branch on table instructions. We reject the doloop pattern in
359 these cases. */
361 const char *
362 default_invalid_within_doloop (const_rtx insn)
364 if (CALL_P (insn))
365 return "Function call in loop.";
367 if (JUMP_P (insn)
368 && (GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC
369 || GET_CODE (PATTERN (insn)) == ADDR_VEC))
370 return "Computed branch in the loop.";
372 return NULL;
375 /* Mapping of builtin functions to vectorized variants. */
377 tree
378 default_builtin_vectorized_function (enum built_in_function fn ATTRIBUTE_UNUSED,
379 tree type_out ATTRIBUTE_UNUSED,
380 tree type_in ATTRIBUTE_UNUSED)
382 return NULL_TREE;
385 /* Vectorized conversion. */
387 tree
388 default_builtin_vectorized_conversion (enum tree_code code ATTRIBUTE_UNUSED,
389 tree type ATTRIBUTE_UNUSED)
391 return NULL_TREE;
394 /* Reciprocal. */
396 tree
397 default_builtin_reciprocal (enum built_in_function fn ATTRIBUTE_UNUSED,
398 bool md_fn ATTRIBUTE_UNUSED,
399 bool sqrt ATTRIBUTE_UNUSED)
401 return NULL_TREE;
404 bool
405 hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false (
406 CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
407 enum machine_mode mode ATTRIBUTE_UNUSED,
408 const_tree type ATTRIBUTE_UNUSED, bool named ATTRIBUTE_UNUSED)
410 return false;
413 bool
414 hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true (
415 CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
416 enum machine_mode mode ATTRIBUTE_UNUSED,
417 const_tree type ATTRIBUTE_UNUSED, bool named ATTRIBUTE_UNUSED)
419 return true;
423 hook_int_CUMULATIVE_ARGS_mode_tree_bool_0 (
424 CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
425 enum machine_mode mode ATTRIBUTE_UNUSED,
426 tree type ATTRIBUTE_UNUSED, bool named ATTRIBUTE_UNUSED)
428 return 0;
431 void
432 hook_void_bitmap (bitmap regs ATTRIBUTE_UNUSED)
436 const char *
437 hook_invalid_arg_for_unprototyped_fn (
438 const_tree typelist ATTRIBUTE_UNUSED,
439 const_tree funcdecl ATTRIBUTE_UNUSED,
440 const_tree val ATTRIBUTE_UNUSED)
442 return NULL;
445 /* Initialize the stack protection decls. */
447 /* Stack protection related decls living in libgcc. */
448 static GTY(()) tree stack_chk_guard_decl;
450 tree
451 default_stack_protect_guard (void)
453 tree t = stack_chk_guard_decl;
455 if (t == NULL)
457 t = build_decl (VAR_DECL, get_identifier ("__stack_chk_guard"),
458 ptr_type_node);
459 TREE_STATIC (t) = 1;
460 TREE_PUBLIC (t) = 1;
461 DECL_EXTERNAL (t) = 1;
462 TREE_USED (t) = 1;
463 TREE_THIS_VOLATILE (t) = 1;
464 DECL_ARTIFICIAL (t) = 1;
465 DECL_IGNORED_P (t) = 1;
467 stack_chk_guard_decl = t;
470 return t;
473 static GTY(()) tree stack_chk_fail_decl;
475 tree
476 default_external_stack_protect_fail (void)
478 tree t = stack_chk_fail_decl;
480 if (t == NULL_TREE)
482 t = build_function_type_list (void_type_node, NULL_TREE);
483 t = build_decl (FUNCTION_DECL, get_identifier ("__stack_chk_fail"), t);
484 TREE_STATIC (t) = 1;
485 TREE_PUBLIC (t) = 1;
486 DECL_EXTERNAL (t) = 1;
487 TREE_USED (t) = 1;
488 TREE_THIS_VOLATILE (t) = 1;
489 TREE_NOTHROW (t) = 1;
490 DECL_ARTIFICIAL (t) = 1;
491 DECL_IGNORED_P (t) = 1;
492 DECL_VISIBILITY (t) = VISIBILITY_DEFAULT;
493 DECL_VISIBILITY_SPECIFIED (t) = 1;
495 stack_chk_fail_decl = t;
498 return build_call_expr (t, 0);
501 tree
502 default_hidden_stack_protect_fail (void)
504 #ifndef HAVE_GAS_HIDDEN
505 return default_external_stack_protect_fail ();
506 #else
507 tree t = stack_chk_fail_decl;
509 if (!flag_pic)
510 return default_external_stack_protect_fail ();
512 if (t == NULL_TREE)
514 t = build_function_type_list (void_type_node, NULL_TREE);
515 t = build_decl (FUNCTION_DECL,
516 get_identifier ("__stack_chk_fail_local"), t);
517 TREE_STATIC (t) = 1;
518 TREE_PUBLIC (t) = 1;
519 DECL_EXTERNAL (t) = 1;
520 TREE_USED (t) = 1;
521 TREE_THIS_VOLATILE (t) = 1;
522 TREE_NOTHROW (t) = 1;
523 DECL_ARTIFICIAL (t) = 1;
524 DECL_IGNORED_P (t) = 1;
525 DECL_VISIBILITY_SPECIFIED (t) = 1;
526 DECL_VISIBILITY (t) = VISIBILITY_HIDDEN;
528 stack_chk_fail_decl = t;
531 return build_call_expr (t, 0);
532 #endif
535 bool
536 hook_bool_const_rtx_commutative_p (const_rtx x,
537 int outer_code ATTRIBUTE_UNUSED)
539 return COMMUTATIVE_P (x);
543 default_function_value (const_tree ret_type ATTRIBUTE_UNUSED,
544 const_tree fn_decl_or_type,
545 bool outgoing ATTRIBUTE_UNUSED)
547 /* The old interface doesn't handle receiving the function type. */
548 if (fn_decl_or_type
549 && !DECL_P (fn_decl_or_type))
550 fn_decl_or_type = NULL;
552 #ifdef FUNCTION_OUTGOING_VALUE
553 if (outgoing)
554 return FUNCTION_OUTGOING_VALUE (ret_type, fn_decl_or_type);
555 #endif
557 #ifdef FUNCTION_VALUE
558 return FUNCTION_VALUE (ret_type, fn_decl_or_type);
559 #else
560 return NULL_RTX;
561 #endif
565 default_internal_arg_pointer (void)
567 /* If the reg that the virtual arg pointer will be translated into is
568 not a fixed reg or is the stack pointer, make a copy of the virtual
569 arg pointer, and address parms via the copy. The frame pointer is
570 considered fixed even though it is not marked as such. */
571 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
572 || ! (fixed_regs[ARG_POINTER_REGNUM]
573 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
574 return copy_to_reg (virtual_incoming_args_rtx);
575 else
576 return virtual_incoming_args_rtx;
579 enum reg_class
580 default_branch_target_register_class (void)
582 return NO_REGS;
585 #ifdef IRA_COVER_CLASSES
586 const enum reg_class *
587 default_ira_cover_classes (void)
589 static enum reg_class classes[] = IRA_COVER_CLASSES;
590 return classes;
592 #endif
594 enum reg_class
595 default_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x ATTRIBUTE_UNUSED,
596 enum reg_class reload_class ATTRIBUTE_UNUSED,
597 enum machine_mode reload_mode ATTRIBUTE_UNUSED,
598 secondary_reload_info *sri)
600 enum reg_class rclass = NO_REGS;
602 if (sri->prev_sri && sri->prev_sri->t_icode != CODE_FOR_nothing)
604 sri->icode = sri->prev_sri->t_icode;
605 return NO_REGS;
607 #ifdef SECONDARY_INPUT_RELOAD_CLASS
608 if (in_p)
609 rclass = SECONDARY_INPUT_RELOAD_CLASS (reload_class, reload_mode, x);
610 #endif
611 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
612 if (! in_p)
613 rclass = SECONDARY_OUTPUT_RELOAD_CLASS (reload_class, reload_mode, x);
614 #endif
615 if (rclass != NO_REGS)
617 enum insn_code icode = (in_p ? reload_in_optab[(int) reload_mode]
618 : reload_out_optab[(int) reload_mode]);
620 if (icode != CODE_FOR_nothing
621 && insn_data[(int) icode].operand[in_p].predicate
622 && ! insn_data[(int) icode].operand[in_p].predicate (x, reload_mode))
623 icode = CODE_FOR_nothing;
624 else if (icode != CODE_FOR_nothing)
626 const char *insn_constraint, *scratch_constraint;
627 char insn_letter, scratch_letter;
628 enum reg_class insn_class, scratch_class;
630 gcc_assert (insn_data[(int) icode].n_operands == 3);
631 insn_constraint = insn_data[(int) icode].operand[!in_p].constraint;
632 if (!*insn_constraint)
633 insn_class = ALL_REGS;
634 else
636 if (in_p)
638 gcc_assert (*insn_constraint == '=');
639 insn_constraint++;
641 insn_letter = *insn_constraint;
642 insn_class
643 = (insn_letter == 'r' ? GENERAL_REGS
644 : REG_CLASS_FROM_CONSTRAINT ((unsigned char) insn_letter,
645 insn_constraint));
646 gcc_assert (insn_class != NO_REGS);
649 scratch_constraint = insn_data[(int) icode].operand[2].constraint;
650 /* The scratch register's constraint must start with "=&",
651 except for an input reload, where only "=" is necessary,
652 and where it might be beneficial to re-use registers from
653 the input. */
654 gcc_assert (scratch_constraint[0] == '='
655 && (in_p || scratch_constraint[1] == '&'));
656 scratch_constraint++;
657 if (*scratch_constraint == '&')
658 scratch_constraint++;
659 scratch_letter = *scratch_constraint;
660 scratch_class
661 = (scratch_letter == 'r' ? GENERAL_REGS
662 : REG_CLASS_FROM_CONSTRAINT ((unsigned char) scratch_letter,
663 scratch_constraint));
665 if (reg_class_subset_p (reload_class, insn_class))
667 gcc_assert (scratch_class == rclass);
668 rclass = NO_REGS;
670 else
671 rclass = insn_class;
674 if (rclass == NO_REGS)
675 sri->icode = icode;
676 else
677 sri->t_icode = icode;
679 return rclass;
682 bool
683 default_handle_c_option (size_t code ATTRIBUTE_UNUSED,
684 const char *arg ATTRIBUTE_UNUSED,
685 int value ATTRIBUTE_UNUSED)
687 return false;
690 /* By default, if flag_pic is true, then neither local nor global relocs
691 should be placed in readonly memory. */
694 default_reloc_rw_mask (void)
696 return flag_pic ? 3 : 0;
699 /* By default, do no modification. */
700 tree default_mangle_decl_assembler_name (tree decl ATTRIBUTE_UNUSED,
701 tree id)
703 return id;
706 bool
707 default_builtin_vector_alignment_reachable (const_tree type, bool is_packed)
709 if (is_packed)
710 return false;
712 /* Assuming that types whose size is > pointer-size are not guaranteed to be
713 naturally aligned. */
714 if (tree_int_cst_compare (TYPE_SIZE (type), bitsize_int (POINTER_SIZE)) > 0)
715 return false;
717 /* Assuming that types whose size is <= pointer-size
718 are naturally aligned. */
719 return true;
722 bool
723 default_hard_regno_scratch_ok (unsigned int regno ATTRIBUTE_UNUSED)
725 return true;
728 bool
729 default_target_option_valid_attribute_p (tree ARG_UNUSED (fndecl),
730 tree ARG_UNUSED (name),
731 tree ARG_UNUSED (args),
732 int ARG_UNUSED (flags))
734 warning (OPT_Wattributes,
735 "target attribute is not supported on this machine");
737 return false;
740 bool
741 default_target_option_pragma_parse (tree ARG_UNUSED (args),
742 tree ARG_UNUSED (pop_target))
744 warning (OPT_Wpragmas,
745 "#pragma GCC target is not supported for this machine");
747 return false;
750 bool
751 default_target_option_can_inline_p (tree caller, tree callee)
753 bool ret = false;
754 tree callee_opts = DECL_FUNCTION_SPECIFIC_TARGET (callee);
755 tree caller_opts = DECL_FUNCTION_SPECIFIC_TARGET (caller);
757 /* If callee has no option attributes, then it is ok to inline */
758 if (!callee_opts)
759 ret = true;
761 /* If caller has no option attributes, but callee does then it is not ok to
762 inline */
763 else if (!caller_opts)
764 ret = false;
766 /* If both caller and callee have attributes, assume that if the pointer is
767 different, the the two functions have different target options since
768 build_target_option_node uses a hash table for the options. */
769 else
770 ret = (callee_opts == caller_opts);
772 return ret;
775 #ifndef HAVE_casesi
776 # define HAVE_casesi 0
777 #endif
779 /* If the machine does not have a case insn that compares the bounds,
780 this means extra overhead for dispatch tables, which raises the
781 threshold for using them. */
783 unsigned int default_case_values_threshold (void)
785 return (HAVE_casesi ? 4 : 5);
788 #include "gt-targhooks.h"