1 /* Language-dependent hooks for LTO.
2 Copyright 2009, 2010 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, 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
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
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/>. */
23 #include "coretypes.h"
28 #include "langhooks.h"
29 #include "langhooks-def.h"
33 #include "tree-inline.h"
37 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
38 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
39 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
40 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
41 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
42 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
43 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
44 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
45 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
46 static tree handle_format_attribute (tree *, tree, tree, int, bool *);
47 static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
49 /* Table of machine-independent attributes supported in GIMPLE. */
50 const struct attribute_spec lto_attribute_table[] =
52 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
53 { "noreturn", 0, 0, true, false, false,
54 handle_noreturn_attribute },
55 /* The same comments as for noreturn attributes apply to const ones. */
56 { "const", 0, 0, true, false, false,
57 handle_const_attribute },
58 { "malloc", 0, 0, true, false, false,
59 handle_malloc_attribute },
60 { "pure", 0, 0, true, false, false,
61 handle_pure_attribute },
62 { "no vops", 0, 0, true, false, false,
63 handle_novops_attribute },
64 { "nonnull", 0, -1, false, true, true,
65 handle_nonnull_attribute },
66 { "nothrow", 0, 0, true, false, false,
67 handle_nothrow_attribute },
68 { "sentinel", 0, 1, false, true, true,
69 handle_sentinel_attribute },
70 { "type generic", 0, 0, false, true, true,
71 handle_type_generic_attribute },
72 { NULL, 0, 0, false, false, false, NULL }
75 /* Give the specifications for the format attributes, used by C and all
78 const struct attribute_spec lto_format_attribute_table[] =
80 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
81 { "format", 3, 3, false, true, true,
82 handle_format_attribute },
83 { "format_arg", 1, 1, false, true, true,
84 handle_format_arg_attribute },
85 { NULL, 0, 0, false, false, false, NULL }
88 enum built_in_attribute
90 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
91 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
92 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
93 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
94 #include "builtin-attrs.def"
95 #undef DEF_ATTR_NULL_TREE
98 #undef DEF_ATTR_TREE_LIST
102 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
106 enum lto_builtin_type
108 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
109 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
110 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
111 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
112 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
113 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
114 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
115 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
116 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
117 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
118 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
119 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
120 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
121 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
122 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
124 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
125 #include "builtin-types.def"
126 #undef DEF_PRIMITIVE_TYPE
127 #undef DEF_FUNCTION_TYPE_0
128 #undef DEF_FUNCTION_TYPE_1
129 #undef DEF_FUNCTION_TYPE_2
130 #undef DEF_FUNCTION_TYPE_3
131 #undef DEF_FUNCTION_TYPE_4
132 #undef DEF_FUNCTION_TYPE_5
133 #undef DEF_FUNCTION_TYPE_6
134 #undef DEF_FUNCTION_TYPE_7
135 #undef DEF_FUNCTION_TYPE_VAR_0
136 #undef DEF_FUNCTION_TYPE_VAR_1
137 #undef DEF_FUNCTION_TYPE_VAR_2
138 #undef DEF_FUNCTION_TYPE_VAR_3
139 #undef DEF_FUNCTION_TYPE_VAR_4
140 #undef DEF_FUNCTION_TYPE_VAR_5
141 #undef DEF_POINTER_TYPE
145 typedef enum lto_builtin_type builtin_type;
147 static GTY(()) tree builtin_types[(int) BT_LAST + 1];
149 static GTY(()) tree string_type_node;
150 static GTY(()) tree const_string_type_node;
151 static GTY(()) tree wint_type_node;
152 static GTY(()) tree intmax_type_node;
153 static GTY(()) tree uintmax_type_node;
154 static GTY(()) tree signed_size_type_node;
156 /* Flags needed to process builtins.def. */
160 /* Attribute handlers. */
162 /* Handle a "noreturn" attribute; arguments as in
163 struct attribute_spec.handler. */
166 handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
167 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
168 bool * ARG_UNUSED (no_add_attrs))
170 tree type = TREE_TYPE (*node);
172 if (TREE_CODE (*node) == FUNCTION_DECL)
173 TREE_THIS_VOLATILE (*node) = 1;
174 else if (TREE_CODE (type) == POINTER_TYPE
175 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
178 (build_type_variant (TREE_TYPE (type),
179 TYPE_READONLY (TREE_TYPE (type)), 1));
187 /* Handle a "const" attribute; arguments as in
188 struct attribute_spec.handler. */
191 handle_const_attribute (tree *node, tree ARG_UNUSED (name),
192 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
193 bool * ARG_UNUSED (no_add_attrs))
195 tree type = TREE_TYPE (*node);
197 /* See FIXME comment on noreturn in c_common_attribute_table. */
198 if (TREE_CODE (*node) == FUNCTION_DECL)
199 TREE_READONLY (*node) = 1;
200 else if (TREE_CODE (type) == POINTER_TYPE
201 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
204 (build_type_variant (TREE_TYPE (type), 1,
205 TREE_THIS_VOLATILE (TREE_TYPE (type))));
213 /* Handle a "malloc" attribute; arguments as in
214 struct attribute_spec.handler. */
217 handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
218 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
219 bool * ARG_UNUSED (no_add_attrs))
221 if (TREE_CODE (*node) == FUNCTION_DECL
222 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
223 DECL_IS_MALLOC (*node) = 1;
231 /* Handle a "pure" attribute; arguments as in
232 struct attribute_spec.handler. */
235 handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
236 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
237 bool * ARG_UNUSED (no_add_attrs))
239 if (TREE_CODE (*node) == FUNCTION_DECL)
240 DECL_PURE_P (*node) = 1;
248 /* Handle a "no vops" attribute; arguments as in
249 struct attribute_spec.handler. */
252 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
253 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
254 bool *ARG_UNUSED (no_add_attrs))
256 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
257 DECL_IS_NOVOPS (*node) = 1;
262 /* Helper for nonnull attribute handling; fetch the operand number
263 from the attribute argument list. */
266 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
268 /* Verify the arg number is a constant. */
269 if (TREE_CODE (arg_num_expr) != INTEGER_CST
270 || TREE_INT_CST_HIGH (arg_num_expr) != 0)
273 *valp = TREE_INT_CST_LOW (arg_num_expr);
277 /* Handle the "nonnull" attribute. */
280 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
281 tree args, int ARG_UNUSED (flags),
282 bool * ARG_UNUSED (no_add_attrs))
286 /* If no arguments are specified, all pointer arguments should be
287 non-null. Verify a full prototype is given so that the arguments
288 will have the correct types when we actually check them later. */
291 gcc_assert (TYPE_ARG_TYPES (type));
295 /* Argument list specified. Verify that each argument number references
296 a pointer argument. */
297 for (; args; args = TREE_CHAIN (args))
300 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
302 if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
305 argument = TYPE_ARG_TYPES (type);
308 for (ck_num = 1; ; ck_num++)
310 if (!argument || ck_num == arg_num)
312 argument = TREE_CHAIN (argument);
316 && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
324 /* Handle a "nothrow" attribute; arguments as in
325 struct attribute_spec.handler. */
328 handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
329 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
330 bool * ARG_UNUSED (no_add_attrs))
332 if (TREE_CODE (*node) == FUNCTION_DECL)
333 TREE_NOTHROW (*node) = 1;
341 /* Handle a "sentinel" attribute. */
344 handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
345 int ARG_UNUSED (flags),
346 bool * ARG_UNUSED (no_add_attrs))
348 tree params = TYPE_ARG_TYPES (*node);
351 while (TREE_CHAIN (params))
352 params = TREE_CHAIN (params);
354 gcc_assert (!VOID_TYPE_P (TREE_VALUE (params)));
358 tree position = TREE_VALUE (args);
359 gcc_assert (TREE_CODE (position) == INTEGER_CST);
360 if (tree_int_cst_lt (position, integer_zero_node))
367 /* Handle a "type_generic" attribute. */
370 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
371 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
372 bool * ARG_UNUSED (no_add_attrs))
376 /* Ensure we have a function type. */
377 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
379 params = TYPE_ARG_TYPES (*node);
380 while (params && ! VOID_TYPE_P (TREE_VALUE (params)))
381 params = TREE_CHAIN (params);
383 /* Ensure we have a variadic function. */
384 gcc_assert (!params);
389 /* Handle a "format" attribute; arguments as in
390 struct attribute_spec.handler. */
393 handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
394 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
397 *no_add_attrs = true;
402 /* Handle a "format_arg" attribute; arguments as in
403 struct attribute_spec.handler. */
406 handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
407 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
410 *no_add_attrs = true;
415 /* Cribbed from c-common.c. */
418 def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
425 for (i = 0; i < n; ++i)
427 builtin_type a = (builtin_type) va_arg (list, int);
428 t = builtin_types[a];
429 if (t == error_mark_node)
431 args = tree_cons (NULL_TREE, t, args);
435 args = nreverse (args);
437 args = chainon (args, void_list_node);
439 t = builtin_types[ret];
440 if (t == error_mark_node)
442 t = build_function_type (t, args);
445 builtin_types[def] = t;
448 /* Used to help initialize the builtin-types.def table. When a type of
449 the correct size doesn't exist, use error_mark_node instead of NULL.
450 The later results in segfaults even when a decl using the type doesn't
454 builtin_type_for_size (int size, bool unsignedp)
456 tree type = lang_hooks.types.type_for_size (size, unsignedp);
457 return type ? type : error_mark_node;
460 /* Support for DEF_BUILTIN. */
463 def_builtin_1 (enum built_in_function fncode, const char *name,
464 enum built_in_class fnclass, tree fntype, tree libtype,
465 bool both_p, bool fallback_p, bool nonansi_p,
466 tree fnattrs, bool implicit_p)
471 if (fntype == error_mark_node)
474 libname = name + strlen ("__builtin_");
475 decl = add_builtin_function (name, fntype, fncode, fnclass,
476 (fallback_p ? libname : NULL),
481 && !(nonansi_p && flag_no_nonansi_builtin))
482 add_builtin_function (libname, libtype, fncode, fnclass,
485 built_in_decls[(int) fncode] = decl;
487 implicit_built_in_decls[(int) fncode] = decl;
491 /* Initialize the attribute table for all the supported builtins. */
494 lto_init_attributes (void)
496 /* Fill in the built_in_attributes array. */
497 #define DEF_ATTR_NULL_TREE(ENUM) \
498 built_in_attributes[(int) ENUM] = NULL_TREE;
499 #define DEF_ATTR_INT(ENUM, VALUE) \
500 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
501 #define DEF_ATTR_IDENT(ENUM, STRING) \
502 built_in_attributes[(int) ENUM] = get_identifier (STRING);
503 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
504 built_in_attributes[(int) ENUM] \
505 = tree_cons (built_in_attributes[(int) PURPOSE], \
506 built_in_attributes[(int) VALUE], \
507 built_in_attributes[(int) CHAIN]);
508 #include "builtin-attrs.def"
509 #undef DEF_ATTR_NULL_TREE
511 #undef DEF_ATTR_IDENT
512 #undef DEF_ATTR_TREE_LIST
515 /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
516 VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
519 lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
520 tree va_list_arg_type_node ATTRIBUTE_UNUSED)
522 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
523 builtin_types[ENUM] = VALUE;
524 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
525 def_fn_type (ENUM, RETURN, 0, 0);
526 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
527 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
528 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
529 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
530 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
531 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
532 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
533 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
534 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
535 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
536 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
538 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
539 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
541 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
542 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
543 def_fn_type (ENUM, RETURN, 1, 0);
544 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
545 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
546 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
547 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
548 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
549 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
550 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
551 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
552 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
553 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
554 #define DEF_POINTER_TYPE(ENUM, TYPE) \
555 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
557 #include "builtin-types.def"
559 #undef DEF_PRIMITIVE_TYPE
560 #undef DEF_FUNCTION_TYPE_1
561 #undef DEF_FUNCTION_TYPE_2
562 #undef DEF_FUNCTION_TYPE_3
563 #undef DEF_FUNCTION_TYPE_4
564 #undef DEF_FUNCTION_TYPE_5
565 #undef DEF_FUNCTION_TYPE_6
566 #undef DEF_FUNCTION_TYPE_VAR_0
567 #undef DEF_FUNCTION_TYPE_VAR_1
568 #undef DEF_FUNCTION_TYPE_VAR_2
569 #undef DEF_FUNCTION_TYPE_VAR_3
570 #undef DEF_FUNCTION_TYPE_VAR_4
571 #undef DEF_FUNCTION_TYPE_VAR_5
572 #undef DEF_POINTER_TYPE
573 builtin_types[(int) BT_LAST] = NULL_TREE;
575 lto_init_attributes ();
577 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
578 NONANSI_P, ATTRS, IMPLICIT, COND) \
580 def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
581 builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
582 NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
583 #include "builtins.def"
587 static GTY(()) tree registered_builtin_types;
589 /* A chain of builtin functions that we need to recognize. We will
590 assume that all other function names we see will be defined by the
592 static GTY(()) tree registered_builtin_fndecls;
594 /* Language hooks. */
597 lto_init_options (unsigned int argc ATTRIBUTE_UNUSED,
598 const char **argv ATTRIBUTE_UNUSED)
600 /* By default, C99-like requirements for complex multiply and divide.
601 ??? Until the complex method is encoded in the IL this is the only
602 safe choice. This will pessimize Fortran code with LTO unless
603 people specify a complex method manually or use -ffast-math. */
604 flag_complex_method = 2;
609 /* Handle command-line option SCODE. If the option takes an argument, it is
610 stored in ARG, which is otherwise NULL. VALUE holds either a numerical
611 argument or a binary value indicating whether the positive or negative form
612 of the option was supplied. */
614 const char *resolution_file_name;
616 lto_handle_option (size_t scode, const char *arg,
617 int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED)
619 enum opt_code code = (enum opt_code) scode;
624 case OPT_fresolution_:
625 resolution_file_name = arg;
640 /* Perform post-option processing. Does additional initialization based on
641 command-line options. PFILENAME is the main input filename. Returns false
642 to enable subsequent back-end initialization. */
645 lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
647 /* -fltrans and -fwpa are mutually exclusive. Check for that here. */
648 if (flag_wpa && flag_ltrans)
649 error ("-fwpa and -fltrans are mutually exclusive");
653 flag_generate_lto = 0;
655 /* During LTRANS, we are not looking at the whole program, only
656 a subset of the whole callgraph. */
657 flag_whole_program = 0;
661 flag_generate_lto = 1;
663 /* Excess precision other than "fast" requires front-end
665 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
667 lto_read_all_file_options ();
669 /* Initialize the compiler back end. */
673 /* Return an integer type with PRECISION bits of precision,
674 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
677 lto_type_for_size (unsigned precision, int unsignedp)
679 if (precision == TYPE_PRECISION (integer_type_node))
680 return unsignedp ? unsigned_type_node : integer_type_node;
682 if (precision == TYPE_PRECISION (signed_char_type_node))
683 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
685 if (precision == TYPE_PRECISION (short_integer_type_node))
686 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
688 if (precision == TYPE_PRECISION (long_integer_type_node))
689 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
691 if (precision == TYPE_PRECISION (long_long_integer_type_node))
693 ? long_long_unsigned_type_node
694 : long_long_integer_type_node;
696 if (precision <= TYPE_PRECISION (intQI_type_node))
697 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
699 if (precision <= TYPE_PRECISION (intHI_type_node))
700 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
702 if (precision <= TYPE_PRECISION (intSI_type_node))
703 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
705 if (precision <= TYPE_PRECISION (intDI_type_node))
706 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
708 if (precision <= TYPE_PRECISION (intTI_type_node))
709 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
715 /* Return a data type that has machine mode MODE.
716 If the mode is an integer,
717 then UNSIGNEDP selects between signed and unsigned types.
718 If the mode is a fixed-point mode,
719 then UNSIGNEDP selects between saturating and nonsaturating types. */
722 lto_type_for_mode (enum machine_mode mode, int unsigned_p)
726 if (mode == TYPE_MODE (integer_type_node))
727 return unsigned_p ? unsigned_type_node : integer_type_node;
729 if (mode == TYPE_MODE (signed_char_type_node))
730 return unsigned_p ? unsigned_char_type_node : signed_char_type_node;
732 if (mode == TYPE_MODE (short_integer_type_node))
733 return unsigned_p ? short_unsigned_type_node : short_integer_type_node;
735 if (mode == TYPE_MODE (long_integer_type_node))
736 return unsigned_p ? long_unsigned_type_node : long_integer_type_node;
738 if (mode == TYPE_MODE (long_long_integer_type_node))
739 return unsigned_p ? long_long_unsigned_type_node : long_long_integer_type_node;
742 return unsigned_p ? unsigned_intQI_type_node : intQI_type_node;
745 return unsigned_p ? unsigned_intHI_type_node : intHI_type_node;
748 return unsigned_p ? unsigned_intSI_type_node : intSI_type_node;
751 return unsigned_p ? unsigned_intDI_type_node : intDI_type_node;
753 #if HOST_BITS_PER_WIDE_INT >= 64
754 if (mode == TYPE_MODE (intTI_type_node))
755 return unsigned_p ? unsigned_intTI_type_node : intTI_type_node;
758 if (mode == TYPE_MODE (float_type_node))
759 return float_type_node;
761 if (mode == TYPE_MODE (double_type_node))
762 return double_type_node;
764 if (mode == TYPE_MODE (long_double_type_node))
765 return long_double_type_node;
767 if (mode == TYPE_MODE (void_type_node))
768 return void_type_node;
770 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
772 ? make_unsigned_type (GET_MODE_PRECISION (mode))
773 : make_signed_type (GET_MODE_PRECISION (mode)));
775 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
777 ? make_unsigned_type (GET_MODE_PRECISION (mode))
778 : make_signed_type (GET_MODE_PRECISION (mode)));
780 if (COMPLEX_MODE_P (mode))
782 enum machine_mode inner_mode;
785 if (mode == TYPE_MODE (complex_float_type_node))
786 return complex_float_type_node;
787 if (mode == TYPE_MODE (complex_double_type_node))
788 return complex_double_type_node;
789 if (mode == TYPE_MODE (complex_long_double_type_node))
790 return complex_long_double_type_node;
792 if (mode == TYPE_MODE (complex_integer_type_node) && !unsigned_p)
793 return complex_integer_type_node;
795 inner_mode = GET_MODE_INNER (mode);
796 inner_type = lto_type_for_mode (inner_mode, unsigned_p);
797 if (inner_type != NULL_TREE)
798 return build_complex_type (inner_type);
800 else if (VECTOR_MODE_P (mode))
802 enum machine_mode inner_mode = GET_MODE_INNER (mode);
803 tree inner_type = lto_type_for_mode (inner_mode, unsigned_p);
804 if (inner_type != NULL_TREE)
805 return build_vector_type_for_mode (inner_type, mode);
808 if (mode == TYPE_MODE (dfloat32_type_node))
809 return dfloat32_type_node;
810 if (mode == TYPE_MODE (dfloat64_type_node))
811 return dfloat64_type_node;
812 if (mode == TYPE_MODE (dfloat128_type_node))
813 return dfloat128_type_node;
815 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
817 if (mode == TYPE_MODE (short_fract_type_node))
818 return unsigned_p ? sat_short_fract_type_node : short_fract_type_node;
819 if (mode == TYPE_MODE (fract_type_node))
820 return unsigned_p ? sat_fract_type_node : fract_type_node;
821 if (mode == TYPE_MODE (long_fract_type_node))
822 return unsigned_p ? sat_long_fract_type_node : long_fract_type_node;
823 if (mode == TYPE_MODE (long_long_fract_type_node))
824 return unsigned_p ? sat_long_long_fract_type_node
825 : long_long_fract_type_node;
827 if (mode == TYPE_MODE (unsigned_short_fract_type_node))
828 return unsigned_p ? sat_unsigned_short_fract_type_node
829 : unsigned_short_fract_type_node;
830 if (mode == TYPE_MODE (unsigned_fract_type_node))
831 return unsigned_p ? sat_unsigned_fract_type_node
832 : unsigned_fract_type_node;
833 if (mode == TYPE_MODE (unsigned_long_fract_type_node))
834 return unsigned_p ? sat_unsigned_long_fract_type_node
835 : unsigned_long_fract_type_node;
836 if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
837 return unsigned_p ? sat_unsigned_long_long_fract_type_node
838 : unsigned_long_long_fract_type_node;
840 if (mode == TYPE_MODE (short_accum_type_node))
841 return unsigned_p ? sat_short_accum_type_node : short_accum_type_node;
842 if (mode == TYPE_MODE (accum_type_node))
843 return unsigned_p ? sat_accum_type_node : accum_type_node;
844 if (mode == TYPE_MODE (long_accum_type_node))
845 return unsigned_p ? sat_long_accum_type_node : long_accum_type_node;
846 if (mode == TYPE_MODE (long_long_accum_type_node))
847 return unsigned_p ? sat_long_long_accum_type_node
848 : long_long_accum_type_node;
850 if (mode == TYPE_MODE (unsigned_short_accum_type_node))
851 return unsigned_p ? sat_unsigned_short_accum_type_node
852 : unsigned_short_accum_type_node;
853 if (mode == TYPE_MODE (unsigned_accum_type_node))
854 return unsigned_p ? sat_unsigned_accum_type_node
855 : unsigned_accum_type_node;
856 if (mode == TYPE_MODE (unsigned_long_accum_type_node))
857 return unsigned_p ? sat_unsigned_long_accum_type_node
858 : unsigned_long_accum_type_node;
859 if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
860 return unsigned_p ? sat_unsigned_long_long_accum_type_node
861 : unsigned_long_long_accum_type_node;
864 return unsigned_p ? sat_qq_type_node : qq_type_node;
866 return unsigned_p ? sat_hq_type_node : hq_type_node;
868 return unsigned_p ? sat_sq_type_node : sq_type_node;
870 return unsigned_p ? sat_dq_type_node : dq_type_node;
872 return unsigned_p ? sat_tq_type_node : tq_type_node;
875 return unsigned_p ? sat_uqq_type_node : uqq_type_node;
877 return unsigned_p ? sat_uhq_type_node : uhq_type_node;
879 return unsigned_p ? sat_usq_type_node : usq_type_node;
881 return unsigned_p ? sat_udq_type_node : udq_type_node;
883 return unsigned_p ? sat_utq_type_node : utq_type_node;
886 return unsigned_p ? sat_ha_type_node : ha_type_node;
888 return unsigned_p ? sat_sa_type_node : sa_type_node;
890 return unsigned_p ? sat_da_type_node : da_type_node;
892 return unsigned_p ? sat_ta_type_node : ta_type_node;
895 return unsigned_p ? sat_uha_type_node : uha_type_node;
897 return unsigned_p ? sat_usa_type_node : usa_type_node;
899 return unsigned_p ? sat_uda_type_node : uda_type_node;
901 return unsigned_p ? sat_uta_type_node : uta_type_node;
904 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
905 if (TYPE_MODE (TREE_VALUE (t)) == mode)
906 return TREE_VALUE (t);
912 lto_global_bindings_p (void)
918 lto_set_decl_assembler_name (tree decl)
920 /* This is almost the same as lhd_set_decl_assembler_name, except that
921 we need to uniquify file-scope names, even if they are not
922 TREE_PUBLIC, to avoid conflicts between individual files. */
925 if (TREE_PUBLIC (decl))
926 id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
929 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
932 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
933 id = get_identifier (label);
936 SET_DECL_ASSEMBLER_NAME (decl, id);
940 lto_pushdecl (tree t ATTRIBUTE_UNUSED)
942 /* Do nothing, since we get all information from DWARF and LTO
950 return registered_builtin_fndecls;
954 lto_write_globals (void)
956 tree *vec = VEC_address (tree, lto_global_var_decls);
957 int len = VEC_length (tree, lto_global_var_decls);
958 wrapup_global_declarations (vec, len);
959 emit_debug_global_declarations (vec, len);
960 VEC_free (tree, gc, lto_global_var_decls);
964 lto_builtin_function (tree decl)
967 TREE_CHAIN (decl) = registered_builtin_fndecls;
968 registered_builtin_fndecls = decl;
974 lto_register_builtin_type (tree type, const char *name)
978 decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier (name), type);
979 DECL_ARTIFICIAL (decl) = 1;
980 if (!TYPE_NAME (type))
981 TYPE_NAME (type) = decl;
983 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
986 /* Build nodes that would have be created by the C front-end; necessary
987 for including builtin-types.def and ultimately builtins.def. */
990 lto_build_c_type_nodes (void)
992 gcc_assert (void_type_node);
994 void_list_node = build_tree_list (NULL_TREE, void_type_node);
995 string_type_node = build_pointer_type (char_type_node);
996 const_string_type_node
997 = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
999 if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1001 intmax_type_node = integer_type_node;
1002 uintmax_type_node = unsigned_type_node;
1003 signed_size_type_node = integer_type_node;
1005 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1007 intmax_type_node = long_integer_type_node;
1008 uintmax_type_node = long_unsigned_type_node;
1009 signed_size_type_node = long_integer_type_node;
1011 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1013 intmax_type_node = long_long_integer_type_node;
1014 uintmax_type_node = long_long_unsigned_type_node;
1015 signed_size_type_node = long_long_integer_type_node;
1020 wint_type_node = unsigned_type_node;
1021 pid_type_node = integer_type_node;
1025 /* Perform LTO-specific initialization. */
1030 /* We need to generate LTO if running in WPA mode. */
1031 flag_generate_lto = flag_wpa;
1033 /* Initialize libcpp line maps for gcc_assert to work. */
1034 linemap_add (line_table, LC_RENAME, 0, NULL, 0);
1035 linemap_add (line_table, LC_RENAME, 0, NULL, 0);
1037 /* Create the basic integer types. */
1038 build_common_tree_nodes (flag_signed_char);
1040 /* Share char_type_node with whatever would be the default for the target.
1041 char_type_node will be used for internal types such as
1042 va_list_type_node but will not be present in the lto stream. */
1043 /* ??? This breaks the more common case of consistent but non-standard
1044 setting of flag_signed_char, so share according to flag_signed_char.
1047 = flag_signed_char ? signed_char_type_node : unsigned_char_type_node;
1049 /* Tell the middle end what type to use for the size of objects. */
1050 if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1052 set_sizetype (unsigned_type_node);
1053 size_type_node = unsigned_type_node;
1055 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1057 set_sizetype (long_unsigned_type_node);
1058 size_type_node = long_unsigned_type_node;
1060 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1062 set_sizetype (long_long_unsigned_type_node);
1063 size_type_node = long_long_unsigned_type_node;
1068 /* The global tree for the main identifier is filled in by
1069 language-specific front-end initialization that is not run in the
1070 LTO back-end. It appears that all languages that perform such
1071 initialization currently do so in the same way, so we do it here. */
1072 if (main_identifier_node == NULL_TREE)
1073 main_identifier_node = get_identifier ("main");
1075 /* In the C++ front-end, fileptr_type_node is defined as a variant
1076 copy of of ptr_type_node, rather than ptr_node itself. The
1077 distinction should only be relevant to the front-end, so we
1078 always use the C definition here in lto1. */
1079 gcc_assert (fileptr_type_node == ptr_type_node);
1081 ptrdiff_type_node = integer_type_node;
1083 /* Create other basic types. */
1084 build_common_tree_nodes_2 (/*short_double=*/false);
1085 lto_build_c_type_nodes ();
1086 gcc_assert (va_list_type_node);
1088 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1090 tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
1091 lto_define_builtins (x, x);
1095 lto_define_builtins (va_list_type_node,
1096 build_reference_type (va_list_type_node));
1099 targetm.init_builtins ();
1100 build_common_builtin_nodes ();
1102 /* Initialize LTO-specific data structures. */
1103 lto_global_var_decls = VEC_alloc (tree, gc, 256);
1109 /* Initialize tree structures required by the LTO front end. */
1111 static void lto_init_ts (void)
1113 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1116 #undef LANG_HOOKS_NAME
1117 #define LANG_HOOKS_NAME "GNU GIMPLE"
1118 #undef LANG_HOOKS_INIT_OPTIONS
1119 #define LANG_HOOKS_INIT_OPTIONS lto_init_options
1120 #undef LANG_HOOKS_HANDLE_OPTION
1121 #define LANG_HOOKS_HANDLE_OPTION lto_handle_option
1122 #undef LANG_HOOKS_POST_OPTIONS
1123 #define LANG_HOOKS_POST_OPTIONS lto_post_options
1124 #undef LANG_HOOKS_GET_ALIAS_SET
1125 #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
1126 #undef LANG_HOOKS_TYPE_FOR_MODE
1127 #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
1128 #undef LANG_HOOKS_TYPE_FOR_SIZE
1129 #define LANG_HOOKS_TYPE_FOR_SIZE lto_type_for_size
1130 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
1131 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
1132 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1133 #define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
1134 #undef LANG_HOOKS_PUSHDECL
1135 #define LANG_HOOKS_PUSHDECL lto_pushdecl
1136 #undef LANG_HOOKS_GETDECLS
1137 #define LANG_HOOKS_GETDECLS lto_getdecls
1138 #undef LANG_HOOKS_WRITE_GLOBALS
1139 #define LANG_HOOKS_WRITE_GLOBALS lto_write_globals
1140 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1141 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
1142 #undef LANG_HOOKS_BUILTIN_FUNCTION
1143 #define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
1144 #undef LANG_HOOKS_INIT
1145 #define LANG_HOOKS_INIT lto_init
1146 #undef LANG_HOOKS_PARSE_FILE
1147 #define LANG_HOOKS_PARSE_FILE lto_main
1148 #undef LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION
1149 #define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION tree_rest_of_compilation
1150 #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
1151 #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
1152 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1153 #define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
1154 #undef LANG_HOOKS_EH_PERSONALITY
1155 #define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
1157 /* Attribute hooks. */
1158 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1159 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
1160 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
1161 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
1163 #undef LANG_HOOKS_BEGIN_SECTION
1164 #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
1165 #undef LANG_HOOKS_APPEND_DATA
1166 #define LANG_HOOKS_APPEND_DATA lto_obj_append_data
1167 #undef LANG_HOOKS_END_SECTION
1168 #define LANG_HOOKS_END_SECTION lto_obj_end_section
1170 #undef LANG_HOOKS_INIT_TS
1171 #define LANG_HOOKS_INIT_TS lto_init_ts
1173 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1175 /* Language hooks that are not part of lang_hooks. */
1178 convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1183 /* Tree walking support. */
1185 static enum lto_tree_node_structure_enum
1186 lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
1188 return TS_LTO_GENERIC;
1192 #include "gtype-lto.h"
1193 #include "gt-lto-lto-lang.h"