Factor unrelated declarations out of tree.h.
[gcc.git] / gcc / targhooks.c
1 /* Default target hook functions.
2 Copyright (C) 2003-2013 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 /* The migration of target macros to target hooks works as follows:
21
22 1. Create a target hook that uses the existing target macros to
23 implement the same functionality.
24
25 2. Convert all the MI files to use the hook instead of the macro.
26
27 3. Repeat for a majority of the remaining target macros. This will
28 take some time.
29
30 4. Tell target maintainers to start migrating.
31
32 5. Eventually convert the backends to override the hook instead of
33 defining the macros. This will take some time too.
34
35 6. TBD when, poison the macros. Unmigrated targets will break at
36 this point.
37
38 Note that we expect steps 1-3 to be done by the people that
39 understand what the MI does with each macro, and step 5 to be done
40 by the target maintainers for their respective targets.
41
42 Note that steps 1 and 2 don't have to be done together, but no
43 target can override the new hook until step 2 is complete for it.
44
45 Once the macros are poisoned, we will revert to the old migration
46 rules - migrate the macro, callers, and targets all at once. This
47 comment can thus be removed at that point. */
48
49 #include "config.h"
50 #include "system.h"
51 #include "coretypes.h"
52 #include "tm.h"
53 #include "machmode.h"
54 #include "rtl.h"
55 #include "tree.h"
56 #include "stor-layout.h"
57 #include "varasm.h"
58 #include "expr.h"
59 #include "output.h"
60 #include "diagnostic-core.h"
61 #include "function.h"
62 #include "target.h"
63 #include "tm_p.h"
64 #include "target-def.h"
65 #include "ggc.h"
66 #include "hard-reg-set.h"
67 #include "regs.h"
68 #include "reload.h"
69 #include "optabs.h"
70 #include "recog.h"
71 #include "intl.h"
72 #include "opts.h"
73 #include "gimple.h"
74 #include "gimplify.h"
75 #include "stringpool.h"
76 #include "tree-ssanames.h"
77 #include "tree-ssa-alias.h"
78 #include "insn-codes.h"
79
80
81 bool
82 default_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
83 rtx addr ATTRIBUTE_UNUSED,
84 bool strict ATTRIBUTE_UNUSED)
85 {
86 #ifdef GO_IF_LEGITIMATE_ADDRESS
87 /* Defer to the old implementation using a goto. */
88 if (strict)
89 return strict_memory_address_p (mode, addr);
90 else
91 return memory_address_p (mode, addr);
92 #else
93 gcc_unreachable ();
94 #endif
95 }
96
97 void
98 default_external_libcall (rtx fun ATTRIBUTE_UNUSED)
99 {
100 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
101 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
102 #endif
103 }
104
105 int
106 default_unspec_may_trap_p (const_rtx x, unsigned flags)
107 {
108 int i;
109
110 /* Any floating arithmetic may trap. */
111 if ((SCALAR_FLOAT_MODE_P (GET_MODE (x)) && flag_trapping_math))
112 return 1;
113
114 for (i = 0; i < XVECLEN (x, 0); ++i)
115 {
116 if (may_trap_p_1 (XVECEXP (x, 0, i), flags))
117 return 1;
118 }
119
120 return 0;
121 }
122
123 enum machine_mode
124 default_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
125 enum machine_mode mode,
126 int *punsignedp ATTRIBUTE_UNUSED,
127 const_tree funtype ATTRIBUTE_UNUSED,
128 int for_return ATTRIBUTE_UNUSED)
129 {
130 if (type != NULL_TREE && for_return == 2)
131 return promote_mode (type, mode, punsignedp);
132 return mode;
133 }
134
135 enum machine_mode
136 default_promote_function_mode_always_promote (const_tree type,
137 enum machine_mode mode,
138 int *punsignedp,
139 const_tree funtype ATTRIBUTE_UNUSED,
140 int for_return ATTRIBUTE_UNUSED)
141 {
142 return promote_mode (type, mode, punsignedp);
143 }
144
145
146 enum machine_mode
147 default_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
148 {
149 if (m1 == m2)
150 return m1;
151 return VOIDmode;
152 }
153
154 bool
155 default_return_in_memory (const_tree type,
156 const_tree fntype ATTRIBUTE_UNUSED)
157 {
158 return (TYPE_MODE (type) == BLKmode);
159 }
160
161 rtx
162 default_legitimize_address (rtx x, rtx orig_x ATTRIBUTE_UNUSED,
163 enum machine_mode mode ATTRIBUTE_UNUSED)
164 {
165 return x;
166 }
167
168 rtx
169 default_expand_builtin_saveregs (void)
170 {
171 error ("__builtin_saveregs not supported by this target");
172 return const0_rtx;
173 }
174
175 void
176 default_setup_incoming_varargs (cumulative_args_t ca ATTRIBUTE_UNUSED,
177 enum machine_mode mode ATTRIBUTE_UNUSED,
178 tree type ATTRIBUTE_UNUSED,
179 int *pretend_arg_size ATTRIBUTE_UNUSED,
180 int second_time ATTRIBUTE_UNUSED)
181 {
182 }
183
184 /* The default implementation of TARGET_BUILTIN_SETJMP_FRAME_VALUE. */
185
186 rtx
187 default_builtin_setjmp_frame_value (void)
188 {
189 return virtual_stack_vars_rtx;
190 }
191
192 /* Generic hook that takes a CUMULATIVE_ARGS pointer and returns false. */
193
194 bool
195 hook_bool_CUMULATIVE_ARGS_false (cumulative_args_t ca ATTRIBUTE_UNUSED)
196 {
197 return false;
198 }
199
200 bool
201 default_pretend_outgoing_varargs_named (cumulative_args_t ca ATTRIBUTE_UNUSED)
202 {
203 return (targetm.calls.setup_incoming_varargs
204 != default_setup_incoming_varargs);
205 }
206
207 enum machine_mode
208 default_eh_return_filter_mode (void)
209 {
210 return targetm.unwind_word_mode ();
211 }
212
213 enum machine_mode
214 default_libgcc_cmp_return_mode (void)
215 {
216 return word_mode;
217 }
218
219 enum machine_mode
220 default_libgcc_shift_count_mode (void)
221 {
222 return word_mode;
223 }
224
225 enum machine_mode
226 default_unwind_word_mode (void)
227 {
228 return word_mode;
229 }
230
231 /* The default implementation of TARGET_SHIFT_TRUNCATION_MASK. */
232
233 unsigned HOST_WIDE_INT
234 default_shift_truncation_mask (enum machine_mode mode)
235 {
236 return SHIFT_COUNT_TRUNCATED ? GET_MODE_BITSIZE (mode) - 1 : 0;
237 }
238
239 /* The default implementation of TARGET_MIN_DIVISIONS_FOR_RECIP_MUL. */
240
241 unsigned int
242 default_min_divisions_for_recip_mul (enum machine_mode mode ATTRIBUTE_UNUSED)
243 {
244 return have_insn_for (DIV, mode) ? 3 : 2;
245 }
246
247 /* The default implementation of TARGET_MODE_REP_EXTENDED. */
248
249 int
250 default_mode_rep_extended (enum machine_mode mode ATTRIBUTE_UNUSED,
251 enum machine_mode mode_rep ATTRIBUTE_UNUSED)
252 {
253 return UNKNOWN;
254 }
255
256 /* Generic hook that takes a CUMULATIVE_ARGS pointer and returns true. */
257
258 bool
259 hook_bool_CUMULATIVE_ARGS_true (cumulative_args_t a ATTRIBUTE_UNUSED)
260 {
261 return true;
262 }
263
264 /* Return machine mode for non-standard suffix
265 or VOIDmode if non-standard suffixes are unsupported. */
266 enum machine_mode
267 default_mode_for_suffix (char suffix ATTRIBUTE_UNUSED)
268 {
269 return VOIDmode;
270 }
271
272 /* The generic C++ ABI specifies this is a 64-bit value. */
273 tree
274 default_cxx_guard_type (void)
275 {
276 return long_long_integer_type_node;
277 }
278
279
280 /* Returns the size of the cookie to use when allocating an array
281 whose elements have the indicated TYPE. Assumes that it is already
282 known that a cookie is needed. */
283
284 tree
285 default_cxx_get_cookie_size (tree type)
286 {
287 tree cookie_size;
288
289 /* We need to allocate an additional max (sizeof (size_t), alignof
290 (true_type)) bytes. */
291 tree sizetype_size;
292 tree type_align;
293
294 sizetype_size = size_in_bytes (sizetype);
295 type_align = size_int (TYPE_ALIGN_UNIT (type));
296 if (INT_CST_LT_UNSIGNED (type_align, sizetype_size))
297 cookie_size = sizetype_size;
298 else
299 cookie_size = type_align;
300
301 return cookie_size;
302 }
303
304 /* Return true if a parameter must be passed by reference. This version
305 of the TARGET_PASS_BY_REFERENCE hook uses just MUST_PASS_IN_STACK. */
306
307 bool
308 hook_pass_by_reference_must_pass_in_stack (cumulative_args_t c ATTRIBUTE_UNUSED,
309 enum machine_mode mode ATTRIBUTE_UNUSED, const_tree type ATTRIBUTE_UNUSED,
310 bool named_arg ATTRIBUTE_UNUSED)
311 {
312 return targetm.calls.must_pass_in_stack (mode, type);
313 }
314
315 /* Return true if a parameter follows callee copies conventions. This
316 version of the hook is true for all named arguments. */
317
318 bool
319 hook_callee_copies_named (cumulative_args_t ca ATTRIBUTE_UNUSED,
320 enum machine_mode mode ATTRIBUTE_UNUSED,
321 const_tree type ATTRIBUTE_UNUSED, bool named)
322 {
323 return named;
324 }
325
326 /* Emit to STREAM the assembler syntax for insn operand X. */
327
328 void
329 default_print_operand (FILE *stream ATTRIBUTE_UNUSED, rtx x ATTRIBUTE_UNUSED,
330 int code ATTRIBUTE_UNUSED)
331 {
332 #ifdef PRINT_OPERAND
333 PRINT_OPERAND (stream, x, code);
334 #else
335 gcc_unreachable ();
336 #endif
337 }
338
339 /* Emit to STREAM the assembler syntax for an insn operand whose memory
340 address is X. */
341
342 void
343 default_print_operand_address (FILE *stream ATTRIBUTE_UNUSED,
344 rtx x ATTRIBUTE_UNUSED)
345 {
346 #ifdef PRINT_OPERAND_ADDRESS
347 PRINT_OPERAND_ADDRESS (stream, x);
348 #else
349 gcc_unreachable ();
350 #endif
351 }
352
353 /* Return true if CODE is a valid punctuation character for the
354 `print_operand' hook. */
355
356 bool
357 default_print_operand_punct_valid_p (unsigned char code ATTRIBUTE_UNUSED)
358 {
359 #ifdef PRINT_OPERAND_PUNCT_VALID_P
360 return PRINT_OPERAND_PUNCT_VALID_P (code);
361 #else
362 return false;
363 #endif
364 }
365
366 /* The default implementation of TARGET_MANGLE_ASSEMBLER_NAME. */
367 tree
368 default_mangle_assembler_name (const char *name ATTRIBUTE_UNUSED)
369 {
370 const char *skipped = name + (*name == '*' ? 1 : 0);
371 const char *stripped = targetm.strip_name_encoding (skipped);
372 if (*name != '*' && user_label_prefix[0])
373 stripped = ACONCAT ((user_label_prefix, stripped, NULL));
374 return get_identifier (stripped);
375 }
376
377 /* True if MODE is valid for the target. By "valid", we mean able to
378 be manipulated in non-trivial ways. In particular, this means all
379 the arithmetic is supported.
380
381 By default we guess this means that any C type is supported. If
382 we can't map the mode back to a type that would be available in C,
383 then reject it. Special case, here, is the double-word arithmetic
384 supported by optabs.c. */
385
386 bool
387 default_scalar_mode_supported_p (enum machine_mode mode)
388 {
389 int precision = GET_MODE_PRECISION (mode);
390
391 switch (GET_MODE_CLASS (mode))
392 {
393 case MODE_PARTIAL_INT:
394 case MODE_INT:
395 if (precision == CHAR_TYPE_SIZE)
396 return true;
397 if (precision == SHORT_TYPE_SIZE)
398 return true;
399 if (precision == INT_TYPE_SIZE)
400 return true;
401 if (precision == LONG_TYPE_SIZE)
402 return true;
403 if (precision == LONG_LONG_TYPE_SIZE)
404 return true;
405 if (precision == 2 * BITS_PER_WORD)
406 return true;
407 return false;
408
409 case MODE_FLOAT:
410 if (precision == FLOAT_TYPE_SIZE)
411 return true;
412 if (precision == DOUBLE_TYPE_SIZE)
413 return true;
414 if (precision == LONG_DOUBLE_TYPE_SIZE)
415 return true;
416 return false;
417
418 case MODE_DECIMAL_FLOAT:
419 case MODE_FRACT:
420 case MODE_UFRACT:
421 case MODE_ACCUM:
422 case MODE_UACCUM:
423 return false;
424
425 default:
426 gcc_unreachable ();
427 }
428 }
429
430 /* Make some target macros useable by target-independent code. */
431 bool
432 targhook_words_big_endian (void)
433 {
434 return !!WORDS_BIG_ENDIAN;
435 }
436
437 bool
438 targhook_float_words_big_endian (void)
439 {
440 return !!FLOAT_WORDS_BIG_ENDIAN;
441 }
442
443 /* True if the target supports floating-point exceptions and rounding
444 modes. */
445
446 bool
447 default_float_exceptions_rounding_supported_p (void)
448 {
449 #ifdef HAVE_adddf3
450 return HAVE_adddf3;
451 #else
452 return false;
453 #endif
454 }
455
456 /* True if the target supports decimal floating point. */
457
458 bool
459 default_decimal_float_supported_p (void)
460 {
461 return ENABLE_DECIMAL_FLOAT;
462 }
463
464 /* True if the target supports fixed-point arithmetic. */
465
466 bool
467 default_fixed_point_supported_p (void)
468 {
469 return ENABLE_FIXED_POINT;
470 }
471
472 /* True if the target supports GNU indirect functions. */
473
474 bool
475 default_has_ifunc_p (void)
476 {
477 return HAVE_GNU_INDIRECT_FUNCTION;
478 }
479
480 /* NULL if INSN insn is valid within a low-overhead loop, otherwise returns
481 an error message.
482
483 This function checks whether a given INSN is valid within a low-overhead
484 loop. If INSN is invalid it returns the reason for that, otherwise it
485 returns NULL. A called function may clobber any special registers required
486 for low-overhead looping. Additionally, some targets (eg, PPC) use the count
487 register for branch on table instructions. We reject the doloop pattern in
488 these cases. */
489
490 const char *
491 default_invalid_within_doloop (const_rtx insn)
492 {
493 if (CALL_P (insn))
494 return "Function call in loop.";
495
496 if (tablejump_p (insn, NULL, NULL) || computed_jump_p (insn))
497 return "Computed branch in the loop.";
498
499 return NULL;
500 }
501
502 /* Mapping of builtin functions to vectorized variants. */
503
504 tree
505 default_builtin_vectorized_function (tree fndecl ATTRIBUTE_UNUSED,
506 tree type_out ATTRIBUTE_UNUSED,
507 tree type_in ATTRIBUTE_UNUSED)
508 {
509 return NULL_TREE;
510 }
511
512 /* Vectorized conversion. */
513
514 tree
515 default_builtin_vectorized_conversion (unsigned int code ATTRIBUTE_UNUSED,
516 tree dest_type ATTRIBUTE_UNUSED,
517 tree src_type ATTRIBUTE_UNUSED)
518 {
519 return NULL_TREE;
520 }
521
522 /* Default vectorizer cost model values. */
523
524 int
525 default_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
526 tree vectype,
527 int misalign ATTRIBUTE_UNUSED)
528 {
529 unsigned elements;
530
531 switch (type_of_cost)
532 {
533 case scalar_stmt:
534 case scalar_load:
535 case scalar_store:
536 case vector_stmt:
537 case vector_load:
538 case vector_store:
539 case vec_to_scalar:
540 case scalar_to_vec:
541 case cond_branch_not_taken:
542 case vec_perm:
543 case vec_promote_demote:
544 return 1;
545
546 case unaligned_load:
547 case unaligned_store:
548 return 2;
549
550 case cond_branch_taken:
551 return 3;
552
553 case vec_construct:
554 elements = TYPE_VECTOR_SUBPARTS (vectype);
555 return elements / 2 + 1;
556
557 default:
558 gcc_unreachable ();
559 }
560 }
561
562 /* Reciprocal. */
563
564 tree
565 default_builtin_reciprocal (unsigned int fn ATTRIBUTE_UNUSED,
566 bool md_fn ATTRIBUTE_UNUSED,
567 bool sqrt ATTRIBUTE_UNUSED)
568 {
569 return NULL_TREE;
570 }
571
572 bool
573 hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false (
574 cumulative_args_t ca ATTRIBUTE_UNUSED,
575 enum machine_mode mode ATTRIBUTE_UNUSED,
576 const_tree type ATTRIBUTE_UNUSED, bool named ATTRIBUTE_UNUSED)
577 {
578 return false;
579 }
580
581 bool
582 hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true (
583 cumulative_args_t ca ATTRIBUTE_UNUSED,
584 enum machine_mode mode ATTRIBUTE_UNUSED,
585 const_tree type ATTRIBUTE_UNUSED, bool named ATTRIBUTE_UNUSED)
586 {
587 return true;
588 }
589
590 int
591 hook_int_CUMULATIVE_ARGS_mode_tree_bool_0 (
592 cumulative_args_t ca ATTRIBUTE_UNUSED,
593 enum machine_mode mode ATTRIBUTE_UNUSED,
594 tree type ATTRIBUTE_UNUSED, bool named ATTRIBUTE_UNUSED)
595 {
596 return 0;
597 }
598
599 void
600 default_function_arg_advance (cumulative_args_t ca ATTRIBUTE_UNUSED,
601 enum machine_mode mode ATTRIBUTE_UNUSED,
602 const_tree type ATTRIBUTE_UNUSED,
603 bool named ATTRIBUTE_UNUSED)
604 {
605 gcc_unreachable ();
606 }
607
608 rtx
609 default_function_arg (cumulative_args_t ca ATTRIBUTE_UNUSED,
610 enum machine_mode mode ATTRIBUTE_UNUSED,
611 const_tree type ATTRIBUTE_UNUSED,
612 bool named ATTRIBUTE_UNUSED)
613 {
614 gcc_unreachable ();
615 }
616
617 rtx
618 default_function_incoming_arg (cumulative_args_t ca ATTRIBUTE_UNUSED,
619 enum machine_mode mode ATTRIBUTE_UNUSED,
620 const_tree type ATTRIBUTE_UNUSED,
621 bool named ATTRIBUTE_UNUSED)
622 {
623 gcc_unreachable ();
624 }
625
626 unsigned int
627 default_function_arg_boundary (enum machine_mode mode ATTRIBUTE_UNUSED,
628 const_tree type ATTRIBUTE_UNUSED)
629 {
630 return PARM_BOUNDARY;
631 }
632
633 unsigned int
634 default_function_arg_round_boundary (enum machine_mode mode ATTRIBUTE_UNUSED,
635 const_tree type ATTRIBUTE_UNUSED)
636 {
637 return PARM_BOUNDARY;
638 }
639
640 void
641 hook_void_bitmap (bitmap regs ATTRIBUTE_UNUSED)
642 {
643 }
644
645 const char *
646 hook_invalid_arg_for_unprototyped_fn (
647 const_tree typelist ATTRIBUTE_UNUSED,
648 const_tree funcdecl ATTRIBUTE_UNUSED,
649 const_tree val ATTRIBUTE_UNUSED)
650 {
651 return NULL;
652 }
653
654 /* Initialize the stack protection decls. */
655
656 /* Stack protection related decls living in libgcc. */
657 static GTY(()) tree stack_chk_guard_decl;
658
659 tree
660 default_stack_protect_guard (void)
661 {
662 tree t = stack_chk_guard_decl;
663
664 if (t == NULL)
665 {
666 rtx x;
667
668 t = build_decl (UNKNOWN_LOCATION,
669 VAR_DECL, get_identifier ("__stack_chk_guard"),
670 ptr_type_node);
671 TREE_STATIC (t) = 1;
672 TREE_PUBLIC (t) = 1;
673 DECL_EXTERNAL (t) = 1;
674 TREE_USED (t) = 1;
675 TREE_THIS_VOLATILE (t) = 1;
676 DECL_ARTIFICIAL (t) = 1;
677 DECL_IGNORED_P (t) = 1;
678
679 /* Do not share RTL as the declaration is visible outside of
680 current function. */
681 x = DECL_RTL (t);
682 RTX_FLAG (x, used) = 1;
683
684 stack_chk_guard_decl = t;
685 }
686
687 return t;
688 }
689
690 static GTY(()) tree stack_chk_fail_decl;
691
692 tree
693 default_external_stack_protect_fail (void)
694 {
695 tree t = stack_chk_fail_decl;
696
697 if (t == NULL_TREE)
698 {
699 t = build_function_type_list (void_type_node, NULL_TREE);
700 t = build_decl (UNKNOWN_LOCATION,
701 FUNCTION_DECL, get_identifier ("__stack_chk_fail"), t);
702 TREE_STATIC (t) = 1;
703 TREE_PUBLIC (t) = 1;
704 DECL_EXTERNAL (t) = 1;
705 TREE_USED (t) = 1;
706 TREE_THIS_VOLATILE (t) = 1;
707 TREE_NOTHROW (t) = 1;
708 DECL_ARTIFICIAL (t) = 1;
709 DECL_IGNORED_P (t) = 1;
710 DECL_VISIBILITY (t) = VISIBILITY_DEFAULT;
711 DECL_VISIBILITY_SPECIFIED (t) = 1;
712
713 stack_chk_fail_decl = t;
714 }
715
716 return build_call_expr (t, 0);
717 }
718
719 tree
720 default_hidden_stack_protect_fail (void)
721 {
722 #ifndef HAVE_GAS_HIDDEN
723 return default_external_stack_protect_fail ();
724 #else
725 tree t = stack_chk_fail_decl;
726
727 if (!flag_pic)
728 return default_external_stack_protect_fail ();
729
730 if (t == NULL_TREE)
731 {
732 t = build_function_type_list (void_type_node, NULL_TREE);
733 t = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
734 get_identifier ("__stack_chk_fail_local"), t);
735 TREE_STATIC (t) = 1;
736 TREE_PUBLIC (t) = 1;
737 DECL_EXTERNAL (t) = 1;
738 TREE_USED (t) = 1;
739 TREE_THIS_VOLATILE (t) = 1;
740 TREE_NOTHROW (t) = 1;
741 DECL_ARTIFICIAL (t) = 1;
742 DECL_IGNORED_P (t) = 1;
743 DECL_VISIBILITY_SPECIFIED (t) = 1;
744 DECL_VISIBILITY (t) = VISIBILITY_HIDDEN;
745
746 stack_chk_fail_decl = t;
747 }
748
749 return build_call_expr (t, 0);
750 #endif
751 }
752
753 bool
754 hook_bool_const_rtx_commutative_p (const_rtx x,
755 int outer_code ATTRIBUTE_UNUSED)
756 {
757 return COMMUTATIVE_P (x);
758 }
759
760 rtx
761 default_function_value (const_tree ret_type ATTRIBUTE_UNUSED,
762 const_tree fn_decl_or_type,
763 bool outgoing ATTRIBUTE_UNUSED)
764 {
765 /* The old interface doesn't handle receiving the function type. */
766 if (fn_decl_or_type
767 && !DECL_P (fn_decl_or_type))
768 fn_decl_or_type = NULL;
769
770 #ifdef FUNCTION_VALUE
771 return FUNCTION_VALUE (ret_type, fn_decl_or_type);
772 #else
773 gcc_unreachable ();
774 #endif
775 }
776
777 rtx
778 default_libcall_value (enum machine_mode mode ATTRIBUTE_UNUSED,
779 const_rtx fun ATTRIBUTE_UNUSED)
780 {
781 #ifdef LIBCALL_VALUE
782 return LIBCALL_VALUE (mode);
783 #else
784 gcc_unreachable ();
785 #endif
786 }
787
788 /* The default hook for TARGET_FUNCTION_VALUE_REGNO_P. */
789
790 bool
791 default_function_value_regno_p (const unsigned int regno ATTRIBUTE_UNUSED)
792 {
793 #ifdef FUNCTION_VALUE_REGNO_P
794 return FUNCTION_VALUE_REGNO_P (regno);
795 #else
796 gcc_unreachable ();
797 #endif
798 }
799
800 rtx
801 default_internal_arg_pointer (void)
802 {
803 /* If the reg that the virtual arg pointer will be translated into is
804 not a fixed reg or is the stack pointer, make a copy of the virtual
805 arg pointer, and address parms via the copy. The frame pointer is
806 considered fixed even though it is not marked as such. */
807 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
808 || ! (fixed_regs[ARG_POINTER_REGNUM]
809 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
810 return copy_to_reg (virtual_incoming_args_rtx);
811 else
812 return virtual_incoming_args_rtx;
813 }
814
815 rtx
816 default_static_chain (const_tree fndecl, bool incoming_p)
817 {
818 if (!DECL_STATIC_CHAIN (fndecl))
819 return NULL;
820
821 if (incoming_p)
822 {
823 #ifdef STATIC_CHAIN_INCOMING_REGNUM
824 return gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
825 #endif
826 }
827
828 #ifdef STATIC_CHAIN_REGNUM
829 return gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
830 #endif
831
832 {
833 static bool issued_error;
834 if (!issued_error)
835 {
836 issued_error = true;
837 sorry ("nested functions not supported on this target");
838 }
839
840 /* It really doesn't matter what we return here, so long at it
841 doesn't cause the rest of the compiler to crash. */
842 return gen_rtx_MEM (Pmode, stack_pointer_rtx);
843 }
844 }
845
846 void
847 default_trampoline_init (rtx ARG_UNUSED (m_tramp), tree ARG_UNUSED (t_func),
848 rtx ARG_UNUSED (r_chain))
849 {
850 sorry ("nested function trampolines not supported on this target");
851 }
852
853 int
854 default_return_pops_args (tree fundecl ATTRIBUTE_UNUSED,
855 tree funtype ATTRIBUTE_UNUSED,
856 int size ATTRIBUTE_UNUSED)
857 {
858 return 0;
859 }
860
861 reg_class_t
862 default_branch_target_register_class (void)
863 {
864 return NO_REGS;
865 }
866
867 extern bool
868 default_lra_p (void)
869 {
870 return false;
871 }
872
873 int
874 default_register_priority (int hard_regno ATTRIBUTE_UNUSED)
875 {
876 return 0;
877 }
878
879 extern bool
880 default_register_usage_leveling_p (void)
881 {
882 return false;
883 }
884
885 extern bool
886 default_different_addr_displacement_p (void)
887 {
888 return false;
889 }
890
891 reg_class_t
892 default_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x ATTRIBUTE_UNUSED,
893 reg_class_t reload_class_i ATTRIBUTE_UNUSED,
894 enum machine_mode reload_mode ATTRIBUTE_UNUSED,
895 secondary_reload_info *sri)
896 {
897 enum reg_class rclass = NO_REGS;
898 enum reg_class reload_class = (enum reg_class) reload_class_i;
899
900 if (sri->prev_sri && sri->prev_sri->t_icode != CODE_FOR_nothing)
901 {
902 sri->icode = sri->prev_sri->t_icode;
903 return NO_REGS;
904 }
905 #ifdef SECONDARY_INPUT_RELOAD_CLASS
906 if (in_p)
907 rclass = SECONDARY_INPUT_RELOAD_CLASS (reload_class, reload_mode, x);
908 #endif
909 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
910 if (! in_p)
911 rclass = SECONDARY_OUTPUT_RELOAD_CLASS (reload_class, reload_mode, x);
912 #endif
913 if (rclass != NO_REGS)
914 {
915 enum insn_code icode
916 = direct_optab_handler (in_p ? reload_in_optab : reload_out_optab,
917 reload_mode);
918
919 if (icode != CODE_FOR_nothing
920 && !insn_operand_matches (icode, in_p, x))
921 icode = CODE_FOR_nothing;
922 else if (icode != CODE_FOR_nothing)
923 {
924 const char *insn_constraint, *scratch_constraint;
925 char insn_letter, scratch_letter;
926 enum reg_class insn_class, scratch_class;
927
928 gcc_assert (insn_data[(int) icode].n_operands == 3);
929 insn_constraint = insn_data[(int) icode].operand[!in_p].constraint;
930 if (!*insn_constraint)
931 insn_class = ALL_REGS;
932 else
933 {
934 if (in_p)
935 {
936 gcc_assert (*insn_constraint == '=');
937 insn_constraint++;
938 }
939 insn_letter = *insn_constraint;
940 insn_class
941 = (insn_letter == 'r' ? GENERAL_REGS
942 : REG_CLASS_FROM_CONSTRAINT ((unsigned char) insn_letter,
943 insn_constraint));
944 gcc_assert (insn_class != NO_REGS);
945 }
946
947 scratch_constraint = insn_data[(int) icode].operand[2].constraint;
948 /* The scratch register's constraint must start with "=&",
949 except for an input reload, where only "=" is necessary,
950 and where it might be beneficial to re-use registers from
951 the input. */
952 gcc_assert (scratch_constraint[0] == '='
953 && (in_p || scratch_constraint[1] == '&'));
954 scratch_constraint++;
955 if (*scratch_constraint == '&')
956 scratch_constraint++;
957 scratch_letter = *scratch_constraint;
958 scratch_class
959 = (scratch_letter == 'r' ? GENERAL_REGS
960 : REG_CLASS_FROM_CONSTRAINT ((unsigned char) scratch_letter,
961 scratch_constraint));
962
963 if (reg_class_subset_p (reload_class, insn_class))
964 {
965 gcc_assert (scratch_class == rclass);
966 rclass = NO_REGS;
967 }
968 else
969 rclass = insn_class;
970
971 }
972 if (rclass == NO_REGS)
973 sri->icode = icode;
974 else
975 sri->t_icode = icode;
976 }
977 return rclass;
978 }
979
980 /* By default, if flag_pic is true, then neither local nor global relocs
981 should be placed in readonly memory. */
982
983 int
984 default_reloc_rw_mask (void)
985 {
986 return flag_pic ? 3 : 0;
987 }
988
989 /* By default, do no modification. */
990 tree default_mangle_decl_assembler_name (tree decl ATTRIBUTE_UNUSED,
991 tree id)
992 {
993 return id;
994 }
995
996 /* Default to natural alignment for vector types. */
997 HOST_WIDE_INT
998 default_vector_alignment (const_tree type)
999 {
1000 return tree_to_shwi (TYPE_SIZE (type));
1001 }
1002
1003 bool
1004 default_builtin_vector_alignment_reachable (const_tree type, bool is_packed)
1005 {
1006 if (is_packed)
1007 return false;
1008
1009 /* Assuming that types whose size is > pointer-size are not guaranteed to be
1010 naturally aligned. */
1011 if (tree_int_cst_compare (TYPE_SIZE (type), bitsize_int (POINTER_SIZE)) > 0)
1012 return false;
1013
1014 /* Assuming that types whose size is <= pointer-size
1015 are naturally aligned. */
1016 return true;
1017 }
1018
1019 /* By default, assume that a target supports any factor of misalignment
1020 memory access if it supports movmisalign patten.
1021 is_packed is true if the memory access is defined in a packed struct. */
1022 bool
1023 default_builtin_support_vector_misalignment (enum machine_mode mode,
1024 const_tree type
1025 ATTRIBUTE_UNUSED,
1026 int misalignment
1027 ATTRIBUTE_UNUSED,
1028 bool is_packed
1029 ATTRIBUTE_UNUSED)
1030 {
1031 if (optab_handler (movmisalign_optab, mode) != CODE_FOR_nothing)
1032 return true;
1033 return false;
1034 }
1035
1036 /* By default, only attempt to parallelize bitwise operations, and
1037 possibly adds/subtracts using bit-twiddling. */
1038
1039 enum machine_mode
1040 default_preferred_simd_mode (enum machine_mode mode ATTRIBUTE_UNUSED)
1041 {
1042 return word_mode;
1043 }
1044
1045 /* By default only the size derived from the preferred vector mode
1046 is tried. */
1047
1048 unsigned int
1049 default_autovectorize_vector_sizes (void)
1050 {
1051 return 0;
1052 }
1053
1054 /* By default, the cost model accumulates three separate costs (prologue,
1055 loop body, and epilogue) for a vectorized loop or block. So allocate an
1056 array of three unsigned ints, set it to zero, and return its address. */
1057
1058 void *
1059 default_init_cost (struct loop *loop_info ATTRIBUTE_UNUSED)
1060 {
1061 unsigned *cost = XNEWVEC (unsigned, 3);
1062 cost[vect_prologue] = cost[vect_body] = cost[vect_epilogue] = 0;
1063 return cost;
1064 }
1065
1066 /* By default, the cost model looks up the cost of the given statement
1067 kind and mode, multiplies it by the occurrence count, accumulates
1068 it into the cost specified by WHERE, and returns the cost added. */
1069
1070 unsigned
1071 default_add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
1072 struct _stmt_vec_info *stmt_info, int misalign,
1073 enum vect_cost_model_location where)
1074 {
1075 unsigned *cost = (unsigned *) data;
1076 unsigned retval = 0;
1077
1078 tree vectype = stmt_info ? stmt_vectype (stmt_info) : NULL_TREE;
1079 int stmt_cost = default_builtin_vectorization_cost (kind, vectype,
1080 misalign);
1081 /* Statements in an inner loop relative to the loop being
1082 vectorized are weighted more heavily. The value here is
1083 arbitrary and could potentially be improved with analysis. */
1084 if (where == vect_body && stmt_info && stmt_in_inner_loop_p (stmt_info))
1085 count *= 50; /* FIXME. */
1086
1087 retval = (unsigned) (count * stmt_cost);
1088 cost[where] += retval;
1089
1090 return retval;
1091 }
1092
1093 /* By default, the cost model just returns the accumulated costs. */
1094
1095 void
1096 default_finish_cost (void *data, unsigned *prologue_cost,
1097 unsigned *body_cost, unsigned *epilogue_cost)
1098 {
1099 unsigned *cost = (unsigned *) data;
1100 *prologue_cost = cost[vect_prologue];
1101 *body_cost = cost[vect_body];
1102 *epilogue_cost = cost[vect_epilogue];
1103 }
1104
1105 /* Free the cost data. */
1106
1107 void
1108 default_destroy_cost_data (void *data)
1109 {
1110 free (data);
1111 }
1112
1113 /* Determine whether or not a pointer mode is valid. Assume defaults
1114 of ptr_mode or Pmode - can be overridden. */
1115 bool
1116 default_valid_pointer_mode (enum machine_mode mode)
1117 {
1118 return (mode == ptr_mode || mode == Pmode);
1119 }
1120
1121 /* Determine whether the memory reference specified by REF may alias
1122 the C libraries errno location. */
1123 bool
1124 default_ref_may_alias_errno (ao_ref *ref)
1125 {
1126 tree base = ao_ref_base (ref);
1127 /* The default implementation assumes the errno location is
1128 a declaration of type int or is always accessed via a
1129 pointer to int. We assume that accesses to errno are
1130 not deliberately obfuscated (even in conforming ways). */
1131 if (TYPE_UNSIGNED (TREE_TYPE (base))
1132 || TYPE_MODE (TREE_TYPE (base)) != TYPE_MODE (integer_type_node))
1133 return false;
1134 /* The default implementation assumes an errno location
1135 declaration is never defined in the current compilation unit. */
1136 if (DECL_P (base)
1137 && !TREE_STATIC (base))
1138 return true;
1139 else if (TREE_CODE (base) == MEM_REF
1140 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
1141 {
1142 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0));
1143 return !pi || pi->pt.anything || pi->pt.nonlocal;
1144 }
1145 return false;
1146 }
1147
1148 /* Return the mode for a pointer to a given ADDRSPACE, defaulting to ptr_mode
1149 for the generic address space only. */
1150
1151 enum machine_mode
1152 default_addr_space_pointer_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
1153 {
1154 gcc_assert (ADDR_SPACE_GENERIC_P (addrspace));
1155 return ptr_mode;
1156 }
1157
1158 /* Return the mode for an address in a given ADDRSPACE, defaulting to Pmode
1159 for the generic address space only. */
1160
1161 enum machine_mode
1162 default_addr_space_address_mode (addr_space_t addrspace ATTRIBUTE_UNUSED)
1163 {
1164 gcc_assert (ADDR_SPACE_GENERIC_P (addrspace));
1165 return Pmode;
1166 }
1167
1168 /* Named address space version of valid_pointer_mode. */
1169
1170 bool
1171 default_addr_space_valid_pointer_mode (enum machine_mode mode, addr_space_t as)
1172 {
1173 if (!ADDR_SPACE_GENERIC_P (as))
1174 return (mode == targetm.addr_space.pointer_mode (as)
1175 || mode == targetm.addr_space.address_mode (as));
1176
1177 return targetm.valid_pointer_mode (mode);
1178 }
1179
1180 /* Some places still assume that all pointer or address modes are the
1181 standard Pmode and ptr_mode. These optimizations become invalid if
1182 the target actually supports multiple different modes. For now,
1183 we disable such optimizations on such targets, using this function. */
1184
1185 bool
1186 target_default_pointer_address_modes_p (void)
1187 {
1188 if (targetm.addr_space.address_mode != default_addr_space_address_mode)
1189 return false;
1190 if (targetm.addr_space.pointer_mode != default_addr_space_pointer_mode)
1191 return false;
1192
1193 return true;
1194 }
1195
1196 /* Named address space version of legitimate_address_p. */
1197
1198 bool
1199 default_addr_space_legitimate_address_p (enum machine_mode mode, rtx mem,
1200 bool strict, addr_space_t as)
1201 {
1202 if (!ADDR_SPACE_GENERIC_P (as))
1203 gcc_unreachable ();
1204
1205 return targetm.legitimate_address_p (mode, mem, strict);
1206 }
1207
1208 /* Named address space version of LEGITIMIZE_ADDRESS. */
1209
1210 rtx
1211 default_addr_space_legitimize_address (rtx x, rtx oldx,
1212 enum machine_mode mode, addr_space_t as)
1213 {
1214 if (!ADDR_SPACE_GENERIC_P (as))
1215 return x;
1216
1217 return targetm.legitimize_address (x, oldx, mode);
1218 }
1219
1220 /* The default hook for determining if one named address space is a subset of
1221 another and to return which address space to use as the common address
1222 space. */
1223
1224 bool
1225 default_addr_space_subset_p (addr_space_t subset, addr_space_t superset)
1226 {
1227 return (subset == superset);
1228 }
1229
1230 /* The default hook for TARGET_ADDR_SPACE_CONVERT. This hook should never be
1231 called for targets with only a generic address space. */
1232
1233 rtx
1234 default_addr_space_convert (rtx op ATTRIBUTE_UNUSED,
1235 tree from_type ATTRIBUTE_UNUSED,
1236 tree to_type ATTRIBUTE_UNUSED)
1237 {
1238 gcc_unreachable ();
1239 }
1240
1241 bool
1242 default_hard_regno_scratch_ok (unsigned int regno ATTRIBUTE_UNUSED)
1243 {
1244 return true;
1245 }
1246
1247 /* The default implementation of TARGET_MODE_DEPENDENT_ADDRESS_P. */
1248
1249 bool
1250 default_mode_dependent_address_p (const_rtx addr ATTRIBUTE_UNUSED,
1251 addr_space_t addrspace ATTRIBUTE_UNUSED)
1252 {
1253 return false;
1254 }
1255
1256 bool
1257 default_target_option_valid_attribute_p (tree ARG_UNUSED (fndecl),
1258 tree ARG_UNUSED (name),
1259 tree ARG_UNUSED (args),
1260 int ARG_UNUSED (flags))
1261 {
1262 warning (OPT_Wattributes,
1263 "target attribute is not supported on this machine");
1264
1265 return false;
1266 }
1267
1268 bool
1269 default_target_option_pragma_parse (tree ARG_UNUSED (args),
1270 tree ARG_UNUSED (pop_target))
1271 {
1272 warning (OPT_Wpragmas,
1273 "#pragma GCC target is not supported for this machine");
1274
1275 return false;
1276 }
1277
1278 bool
1279 default_target_can_inline_p (tree caller, tree callee)
1280 {
1281 bool ret = false;
1282 tree callee_opts = DECL_FUNCTION_SPECIFIC_TARGET (callee);
1283 tree caller_opts = DECL_FUNCTION_SPECIFIC_TARGET (caller);
1284
1285 /* If callee has no option attributes, then it is ok to inline */
1286 if (!callee_opts)
1287 ret = true;
1288
1289 /* If caller has no option attributes, but callee does then it is not ok to
1290 inline */
1291 else if (!caller_opts)
1292 ret = false;
1293
1294 /* If both caller and callee have attributes, assume that if the
1295 pointer is different, the two functions have different target
1296 options since build_target_option_node uses a hash table for the
1297 options. */
1298 else
1299 ret = (callee_opts == caller_opts);
1300
1301 return ret;
1302 }
1303
1304 #ifndef HAVE_casesi
1305 # define HAVE_casesi 0
1306 #endif
1307
1308 /* If the machine does not have a case insn that compares the bounds,
1309 this means extra overhead for dispatch tables, which raises the
1310 threshold for using them. */
1311
1312 unsigned int
1313 default_case_values_threshold (void)
1314 {
1315 return (HAVE_casesi ? 4 : 5);
1316 }
1317
1318 bool
1319 default_have_conditional_execution (void)
1320 {
1321 #ifdef HAVE_conditional_execution
1322 return HAVE_conditional_execution;
1323 #else
1324 return false;
1325 #endif
1326 }
1327
1328 tree
1329 default_builtin_tm_load_store (tree ARG_UNUSED (type))
1330 {
1331 return NULL_TREE;
1332 }
1333
1334 /* Compute cost of moving registers to/from memory. */
1335
1336 int
1337 default_memory_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1338 reg_class_t rclass ATTRIBUTE_UNUSED,
1339 bool in ATTRIBUTE_UNUSED)
1340 {
1341 #ifndef MEMORY_MOVE_COST
1342 return (4 + memory_move_secondary_cost (mode, (enum reg_class) rclass, in));
1343 #else
1344 return MEMORY_MOVE_COST (mode, (enum reg_class) rclass, in);
1345 #endif
1346 }
1347
1348 /* Compute cost of moving data from a register of class FROM to one of
1349 TO, using MODE. */
1350
1351 int
1352 default_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1353 reg_class_t from ATTRIBUTE_UNUSED,
1354 reg_class_t to ATTRIBUTE_UNUSED)
1355 {
1356 #ifndef REGISTER_MOVE_COST
1357 return 2;
1358 #else
1359 return REGISTER_MOVE_COST (mode, (enum reg_class) from, (enum reg_class) to);
1360 #endif
1361 }
1362
1363 bool
1364 default_profile_before_prologue (void)
1365 {
1366 #ifdef PROFILE_BEFORE_PROLOGUE
1367 return true;
1368 #else
1369 return false;
1370 #endif
1371 }
1372
1373 /* The default implementation of TARGET_PREFERRED_RELOAD_CLASS. */
1374
1375 reg_class_t
1376 default_preferred_reload_class (rtx x ATTRIBUTE_UNUSED,
1377 reg_class_t rclass)
1378 {
1379 #ifdef PREFERRED_RELOAD_CLASS
1380 return (reg_class_t) PREFERRED_RELOAD_CLASS (x, (enum reg_class) rclass);
1381 #else
1382 return rclass;
1383 #endif
1384 }
1385
1386 /* The default implementation of TARGET_OUTPUT_PREFERRED_RELOAD_CLASS. */
1387
1388 reg_class_t
1389 default_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED,
1390 reg_class_t rclass)
1391 {
1392 return rclass;
1393 }
1394
1395 /* The default implementation of TARGET_PREFERRED_RENAME_CLASS. */
1396 reg_class_t
1397 default_preferred_rename_class (reg_class_t rclass ATTRIBUTE_UNUSED)
1398 {
1399 return NO_REGS;
1400 }
1401
1402 /* The default implementation of TARGET_CLASS_LIKELY_SPILLED_P. */
1403
1404 bool
1405 default_class_likely_spilled_p (reg_class_t rclass)
1406 {
1407 return (reg_class_size[(int) rclass] == 1);
1408 }
1409
1410 /* The default implementation of TARGET_CLASS_MAX_NREGS. */
1411
1412 unsigned char
1413 default_class_max_nregs (reg_class_t rclass ATTRIBUTE_UNUSED,
1414 enum machine_mode mode ATTRIBUTE_UNUSED)
1415 {
1416 #ifdef CLASS_MAX_NREGS
1417 return (unsigned char) CLASS_MAX_NREGS ((enum reg_class) rclass, mode);
1418 #else
1419 return ((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD);
1420 #endif
1421 }
1422
1423 /* Determine the debugging unwind mechanism for the target. */
1424
1425 enum unwind_info_type
1426 default_debug_unwind_info (void)
1427 {
1428 /* If the target wants to force the use of dwarf2 unwind info, let it. */
1429 /* ??? Change all users to the hook, then poison this. */
1430 #ifdef DWARF2_FRAME_INFO
1431 if (DWARF2_FRAME_INFO)
1432 return UI_DWARF2;
1433 #endif
1434
1435 /* Otherwise, only turn it on if dwarf2 debugging is enabled. */
1436 #ifdef DWARF2_DEBUGGING_INFO
1437 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1438 return UI_DWARF2;
1439 #endif
1440
1441 return UI_NONE;
1442 }
1443
1444 /* To be used by targets where reg_raw_mode doesn't return the right
1445 mode for registers used in apply_builtin_return and apply_builtin_arg. */
1446
1447 enum machine_mode
1448 default_get_reg_raw_mode (int regno)
1449 {
1450 return reg_raw_mode[regno];
1451 }
1452
1453 /* Return true if the state of option OPTION should be stored in PCH files
1454 and checked by default_pch_valid_p. Store the option's current state
1455 in STATE if so. */
1456
1457 static inline bool
1458 option_affects_pch_p (int option, struct cl_option_state *state)
1459 {
1460 if ((cl_options[option].flags & CL_TARGET) == 0)
1461 return false;
1462 if (option_flag_var (option, &global_options) == &target_flags)
1463 if (targetm.check_pch_target_flags)
1464 return false;
1465 return get_option_state (&global_options, option, state);
1466 }
1467
1468 /* Default version of get_pch_validity.
1469 By default, every flag difference is fatal; that will be mostly right for
1470 most targets, but completely right for very few. */
1471
1472 void *
1473 default_get_pch_validity (size_t *sz)
1474 {
1475 struct cl_option_state state;
1476 size_t i;
1477 char *result, *r;
1478
1479 *sz = 2;
1480 if (targetm.check_pch_target_flags)
1481 *sz += sizeof (target_flags);
1482 for (i = 0; i < cl_options_count; i++)
1483 if (option_affects_pch_p (i, &state))
1484 *sz += state.size;
1485
1486 result = r = XNEWVEC (char, *sz);
1487 r[0] = flag_pic;
1488 r[1] = flag_pie;
1489 r += 2;
1490 if (targetm.check_pch_target_flags)
1491 {
1492 memcpy (r, &target_flags, sizeof (target_flags));
1493 r += sizeof (target_flags);
1494 }
1495
1496 for (i = 0; i < cl_options_count; i++)
1497 if (option_affects_pch_p (i, &state))
1498 {
1499 memcpy (r, state.data, state.size);
1500 r += state.size;
1501 }
1502
1503 return result;
1504 }
1505
1506 /* Return a message which says that a PCH file was created with a different
1507 setting of OPTION. */
1508
1509 static const char *
1510 pch_option_mismatch (const char *option)
1511 {
1512 char *r;
1513
1514 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1515 if (r == NULL)
1516 return _("out of memory");
1517 return r;
1518 }
1519
1520 /* Default version of pch_valid_p. */
1521
1522 const char *
1523 default_pch_valid_p (const void *data_p, size_t len)
1524 {
1525 struct cl_option_state state;
1526 const char *data = (const char *)data_p;
1527 size_t i;
1528
1529 /* -fpic and -fpie also usually make a PCH invalid. */
1530 if (data[0] != flag_pic)
1531 return _("created and used with different settings of -fpic");
1532 if (data[1] != flag_pie)
1533 return _("created and used with different settings of -fpie");
1534 data += 2;
1535
1536 /* Check target_flags. */
1537 if (targetm.check_pch_target_flags)
1538 {
1539 int tf;
1540 const char *r;
1541
1542 memcpy (&tf, data, sizeof (target_flags));
1543 data += sizeof (target_flags);
1544 len -= sizeof (target_flags);
1545 r = targetm.check_pch_target_flags (tf);
1546 if (r != NULL)
1547 return r;
1548 }
1549
1550 for (i = 0; i < cl_options_count; i++)
1551 if (option_affects_pch_p (i, &state))
1552 {
1553 if (memcmp (data, state.data, state.size) != 0)
1554 return pch_option_mismatch (cl_options[i].opt_text);
1555 data += state.size;
1556 len -= state.size;
1557 }
1558
1559 return NULL;
1560 }
1561
1562 /* Default version of cstore_mode. */
1563
1564 enum machine_mode
1565 default_cstore_mode (enum insn_code icode)
1566 {
1567 return insn_data[(int) icode].operand[0].mode;
1568 }
1569
1570 /* Default version of member_type_forces_blk. */
1571
1572 bool
1573 default_member_type_forces_blk (const_tree, enum machine_mode)
1574 {
1575 return false;
1576 }
1577 rtx
1578 default_load_bounds_for_arg (rtx addr ATTRIBUTE_UNUSED,
1579 rtx ptr ATTRIBUTE_UNUSED,
1580 rtx bnd ATTRIBUTE_UNUSED)
1581 {
1582 gcc_unreachable ();
1583 }
1584
1585 void
1586 default_store_bounds_for_arg (rtx val ATTRIBUTE_UNUSED,
1587 rtx addr ATTRIBUTE_UNUSED,
1588 rtx bounds ATTRIBUTE_UNUSED,
1589 rtx to ATTRIBUTE_UNUSED)
1590 {
1591 gcc_unreachable ();
1592 }
1593
1594 tree
1595 default_fn_abi_va_list_bounds_size (tree fndecl ATTRIBUTE_UNUSED)
1596 {
1597 return integer_zero_node;
1598 }
1599
1600 /* Default version of canonicalize_comparison. */
1601
1602 void
1603 default_canonicalize_comparison (int *, rtx *, rtx *, bool)
1604 {
1605 }
1606
1607 /* Default implementation of TARGET_ATOMIC_ASSIGN_EXPAND_FENV. */
1608
1609 void
1610 default_atomic_assign_expand_fenv (tree *, tree *, tree *)
1611 {
1612 }
1613
1614 #ifndef PAD_VARARGS_DOWN
1615 #define PAD_VARARGS_DOWN BYTES_BIG_ENDIAN
1616 #endif
1617
1618 /* Build an indirect-ref expression over the given TREE, which represents a
1619 piece of a va_arg() expansion. */
1620 tree
1621 build_va_arg_indirect_ref (tree addr)
1622 {
1623 addr = build_simple_mem_ref_loc (EXPR_LOCATION (addr), addr);
1624 return addr;
1625 }
1626
1627 /* The "standard" implementation of va_arg: read the value from the
1628 current (padded) address and increment by the (padded) size. */
1629
1630 tree
1631 std_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
1632 gimple_seq *post_p)
1633 {
1634 tree addr, t, type_size, rounded_size, valist_tmp;
1635 unsigned HOST_WIDE_INT align, boundary;
1636 bool indirect;
1637
1638 #ifdef ARGS_GROW_DOWNWARD
1639 /* All of the alignment and movement below is for args-grow-up machines.
1640 As of 2004, there are only 3 ARGS_GROW_DOWNWARD targets, and they all
1641 implement their own specialized gimplify_va_arg_expr routines. */
1642 gcc_unreachable ();
1643 #endif
1644
1645 indirect = pass_by_reference (NULL, TYPE_MODE (type), type, false);
1646 if (indirect)
1647 type = build_pointer_type (type);
1648
1649 align = PARM_BOUNDARY / BITS_PER_UNIT;
1650 boundary = targetm.calls.function_arg_boundary (TYPE_MODE (type), type);
1651
1652 /* When we align parameter on stack for caller, if the parameter
1653 alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
1654 aligned at MAX_SUPPORTED_STACK_ALIGNMENT. We will match callee
1655 here with caller. */
1656 if (boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
1657 boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
1658
1659 boundary /= BITS_PER_UNIT;
1660
1661 /* Hoist the valist value into a temporary for the moment. */
1662 valist_tmp = get_initialized_tmp_var (valist, pre_p, NULL);
1663
1664 /* va_list pointer is aligned to PARM_BOUNDARY. If argument actually
1665 requires greater alignment, we must perform dynamic alignment. */
1666 if (boundary > align
1667 && !integer_zerop (TYPE_SIZE (type)))
1668 {
1669 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp,
1670 fold_build_pointer_plus_hwi (valist_tmp, boundary - 1));
1671 gimplify_and_add (t, pre_p);
1672
1673 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp,
1674 fold_build2 (BIT_AND_EXPR, TREE_TYPE (valist),
1675 valist_tmp,
1676 build_int_cst (TREE_TYPE (valist), -boundary)));
1677 gimplify_and_add (t, pre_p);
1678 }
1679 else
1680 boundary = align;
1681
1682 /* If the actual alignment is less than the alignment of the type,
1683 adjust the type accordingly so that we don't assume strict alignment
1684 when dereferencing the pointer. */
1685 boundary *= BITS_PER_UNIT;
1686 if (boundary < TYPE_ALIGN (type))
1687 {
1688 type = build_variant_type_copy (type);
1689 TYPE_ALIGN (type) = boundary;
1690 }
1691
1692 /* Compute the rounded size of the type. */
1693 type_size = size_in_bytes (type);
1694 rounded_size = round_up (type_size, align);
1695
1696 /* Reduce rounded_size so it's sharable with the postqueue. */
1697 gimplify_expr (&rounded_size, pre_p, post_p, is_gimple_val, fb_rvalue);
1698
1699 /* Get AP. */
1700 addr = valist_tmp;
1701 if (PAD_VARARGS_DOWN && !integer_zerop (rounded_size))
1702 {
1703 /* Small args are padded downward. */
1704 t = fold_build2_loc (input_location, GT_EXPR, sizetype,
1705 rounded_size, size_int (align));
1706 t = fold_build3 (COND_EXPR, sizetype, t, size_zero_node,
1707 size_binop (MINUS_EXPR, rounded_size, type_size));
1708 addr = fold_build_pointer_plus (addr, t);
1709 }
1710
1711 /* Compute new value for AP. */
1712 t = fold_build_pointer_plus (valist_tmp, rounded_size);
1713 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist, t);
1714 gimplify_and_add (t, pre_p);
1715
1716 addr = fold_convert (build_pointer_type (type), addr);
1717
1718 if (indirect)
1719 addr = build_va_arg_indirect_ref (addr);
1720
1721 return build_va_arg_indirect_ref (addr);
1722 }
1723
1724 tree
1725 default_chkp_bound_type (void)
1726 {
1727 tree res = make_node (POINTER_BOUNDS_TYPE);
1728 TYPE_PRECISION (res) = TYPE_PRECISION (size_type_node) * 2;
1729 layout_type (res);
1730 return res;
1731 }
1732
1733 enum machine_mode
1734 default_chkp_bound_mode (void)
1735 {
1736 return VOIDmode;
1737 }
1738
1739 tree
1740 default_builtin_chkp_function (unsigned int fcode ATTRIBUTE_UNUSED)
1741 {
1742 return NULL_TREE;
1743 }
1744
1745 /* An implementation of TARGET_CAN_USE_DOLOOP_P for targets that do
1746 not support nested low-overhead loops. */
1747
1748 bool
1749 can_use_doloop_if_innermost (double_int, double_int,
1750 unsigned int loop_depth, bool)
1751 {
1752 return loop_depth == 1;
1753 }
1754
1755 #include "gt-targhooks.h"