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"
35 #include "diagnostic-core.h"
37 #include "lto-streamer.h"
39 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
40 static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
41 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
42 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
43 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
44 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
45 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
46 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
47 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
48 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
49 static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool *);
50 static tree handle_format_attribute (tree *, tree, tree, int, bool *);
51 static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
53 /* Table of machine-independent attributes supported in GIMPLE. */
54 const struct attribute_spec lto_attribute_table[] =
56 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
58 { "noreturn", 0, 0, true, false, false,
59 handle_noreturn_attribute, false },
60 { "leaf", 0, 0, true, false, false,
61 handle_leaf_attribute, false },
62 /* The same comments as for noreturn attributes apply to const ones. */
63 { "const", 0, 0, true, false, false,
64 handle_const_attribute, false },
65 { "malloc", 0, 0, true, false, false,
66 handle_malloc_attribute, false },
67 { "pure", 0, 0, true, false, false,
68 handle_pure_attribute, false },
69 { "no vops", 0, 0, true, false, false,
70 handle_novops_attribute, false },
71 { "nonnull", 0, -1, false, true, true,
72 handle_nonnull_attribute, false },
73 { "nothrow", 0, 0, true, false, false,
74 handle_nothrow_attribute, false },
75 { "sentinel", 0, 1, false, true, true,
76 handle_sentinel_attribute, false },
77 { "type generic", 0, 0, false, true, true,
78 handle_type_generic_attribute, false },
79 { "transaction_pure", 0, 0, false, true, true,
80 handle_transaction_pure_attribute, false },
81 { NULL, 0, 0, false, false, false, NULL, false }
84 /* Give the specifications for the format attributes, used by C and all
87 const struct attribute_spec lto_format_attribute_table[] =
89 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
90 affects_type_identity } */
91 { "format", 3, 3, false, true, true,
92 handle_format_attribute, false },
93 { "format_arg", 1, 1, false, true, true,
94 handle_format_arg_attribute, false },
95 { NULL, 0, 0, false, false, false, NULL, false }
98 enum built_in_attribute
100 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
101 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
102 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
103 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
104 #include "builtin-attrs.def"
105 #undef DEF_ATTR_NULL_TREE
107 #undef DEF_ATTR_IDENT
108 #undef DEF_ATTR_TREE_LIST
112 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
116 enum lto_builtin_type
118 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
119 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
120 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
121 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
122 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
123 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
124 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
125 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
126 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
127 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
128 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
129 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
130 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
131 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
132 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
134 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
135 #include "builtin-types.def"
136 #undef DEF_PRIMITIVE_TYPE
137 #undef DEF_FUNCTION_TYPE_0
138 #undef DEF_FUNCTION_TYPE_1
139 #undef DEF_FUNCTION_TYPE_2
140 #undef DEF_FUNCTION_TYPE_3
141 #undef DEF_FUNCTION_TYPE_4
142 #undef DEF_FUNCTION_TYPE_5
143 #undef DEF_FUNCTION_TYPE_6
144 #undef DEF_FUNCTION_TYPE_7
145 #undef DEF_FUNCTION_TYPE_VAR_0
146 #undef DEF_FUNCTION_TYPE_VAR_1
147 #undef DEF_FUNCTION_TYPE_VAR_2
148 #undef DEF_FUNCTION_TYPE_VAR_3
149 #undef DEF_FUNCTION_TYPE_VAR_4
150 #undef DEF_FUNCTION_TYPE_VAR_5
151 #undef DEF_POINTER_TYPE
155 typedef enum lto_builtin_type builtin_type;
157 static GTY(()) tree builtin_types[(int) BT_LAST + 1];
159 static GTY(()) tree string_type_node;
160 static GTY(()) tree const_string_type_node;
161 static GTY(()) tree wint_type_node;
162 static GTY(()) tree intmax_type_node;
163 static GTY(()) tree uintmax_type_node;
164 static GTY(()) tree signed_size_type_node;
166 /* Flags needed to process builtins.def. */
170 /* Attribute handlers. */
172 /* Handle a "noreturn" attribute; arguments as in
173 struct attribute_spec.handler. */
176 handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
177 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
178 bool * ARG_UNUSED (no_add_attrs))
180 tree type = TREE_TYPE (*node);
182 if (TREE_CODE (*node) == FUNCTION_DECL)
183 TREE_THIS_VOLATILE (*node) = 1;
184 else if (TREE_CODE (type) == POINTER_TYPE
185 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
188 (build_type_variant (TREE_TYPE (type),
189 TYPE_READONLY (TREE_TYPE (type)), 1));
196 /* Handle a "leaf" attribute; arguments as in
197 struct attribute_spec.handler. */
200 handle_leaf_attribute (tree *node, tree name,
201 tree ARG_UNUSED (args),
202 int ARG_UNUSED (flags), bool *no_add_attrs)
204 if (TREE_CODE (*node) != FUNCTION_DECL)
206 warning (OPT_Wattributes, "%qE attribute ignored", name);
207 *no_add_attrs = true;
209 if (!TREE_PUBLIC (*node))
211 warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
212 *no_add_attrs = true;
218 /* Handle a "const" attribute; arguments as in
219 struct attribute_spec.handler. */
222 handle_const_attribute (tree *node, tree ARG_UNUSED (name),
223 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
224 bool * ARG_UNUSED (no_add_attrs))
226 tree type = TREE_TYPE (*node);
228 /* See FIXME comment on noreturn in c_common_attribute_table. */
229 if (TREE_CODE (*node) == FUNCTION_DECL)
230 TREE_READONLY (*node) = 1;
231 else if (TREE_CODE (type) == POINTER_TYPE
232 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
235 (build_type_variant (TREE_TYPE (type), 1,
236 TREE_THIS_VOLATILE (TREE_TYPE (type))));
244 /* Handle a "malloc" attribute; arguments as in
245 struct attribute_spec.handler. */
248 handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
249 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
250 bool * ARG_UNUSED (no_add_attrs))
252 if (TREE_CODE (*node) == FUNCTION_DECL
253 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
254 DECL_IS_MALLOC (*node) = 1;
262 /* Handle a "pure" attribute; arguments as in
263 struct attribute_spec.handler. */
266 handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
267 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
268 bool * ARG_UNUSED (no_add_attrs))
270 if (TREE_CODE (*node) == FUNCTION_DECL)
271 DECL_PURE_P (*node) = 1;
279 /* Handle a "no vops" attribute; arguments as in
280 struct attribute_spec.handler. */
283 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
284 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
285 bool *ARG_UNUSED (no_add_attrs))
287 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
288 DECL_IS_NOVOPS (*node) = 1;
293 /* Helper for nonnull attribute handling; fetch the operand number
294 from the attribute argument list. */
297 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
299 /* Verify the arg number is a constant. */
300 if (TREE_CODE (arg_num_expr) != INTEGER_CST
301 || TREE_INT_CST_HIGH (arg_num_expr) != 0)
304 *valp = TREE_INT_CST_LOW (arg_num_expr);
308 /* Handle the "nonnull" attribute. */
311 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
312 tree args, int ARG_UNUSED (flags),
313 bool * ARG_UNUSED (no_add_attrs))
317 /* If no arguments are specified, all pointer arguments should be
318 non-null. Verify a full prototype is given so that the arguments
319 will have the correct types when we actually check them later. */
322 gcc_assert (prototype_p (type));
326 /* Argument list specified. Verify that each argument number references
327 a pointer argument. */
328 for (; args; args = TREE_CHAIN (args))
331 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
333 if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
336 argument = TYPE_ARG_TYPES (type);
339 for (ck_num = 1; ; ck_num++)
341 if (!argument || ck_num == arg_num)
343 argument = TREE_CHAIN (argument);
347 && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
355 /* Handle a "nothrow" attribute; arguments as in
356 struct attribute_spec.handler. */
359 handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
360 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
361 bool * ARG_UNUSED (no_add_attrs))
363 if (TREE_CODE (*node) == FUNCTION_DECL)
364 TREE_NOTHROW (*node) = 1;
372 /* Handle a "sentinel" attribute. */
375 handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
376 int ARG_UNUSED (flags),
377 bool * ARG_UNUSED (no_add_attrs))
379 gcc_assert (stdarg_p (*node));
383 tree position = TREE_VALUE (args);
384 gcc_assert (TREE_CODE (position) == INTEGER_CST);
385 if (tree_int_cst_lt (position, integer_zero_node))
392 /* Handle a "type_generic" attribute. */
395 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
396 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
397 bool * ARG_UNUSED (no_add_attrs))
399 /* Ensure we have a function type. */
400 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
402 /* Ensure we have a variadic function. */
403 gcc_assert (!prototype_p (*node) || stdarg_p (*node));
408 /* Handle a "transaction_pure" attribute. */
411 handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
412 tree ARG_UNUSED (args),
413 int ARG_UNUSED (flags),
414 bool * ARG_UNUSED (no_add_attrs))
416 /* Ensure we have a function type. */
417 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
422 /* Handle a "format" attribute; arguments as in
423 struct attribute_spec.handler. */
426 handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
427 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
430 *no_add_attrs = true;
435 /* Handle a "format_arg" attribute; arguments as in
436 struct attribute_spec.handler. */
439 handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
440 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
443 *no_add_attrs = true;
448 /* Cribbed from c-common.c. */
451 def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
454 tree *args = XALLOCAVEC (tree, n);
459 for (i = 0; i < n; ++i)
461 builtin_type a = (builtin_type) va_arg (list, int);
462 t = builtin_types[a];
463 if (t == error_mark_node)
469 t = builtin_types[ret];
470 if (t == error_mark_node)
473 t = build_varargs_function_type_array (t, n, args);
475 t = build_function_type_array (t, n, args);
478 builtin_types[def] = t;
482 /* Used to help initialize the builtin-types.def table. When a type of
483 the correct size doesn't exist, use error_mark_node instead of NULL.
484 The later results in segfaults even when a decl using the type doesn't
488 builtin_type_for_size (int size, bool unsignedp)
490 tree type = lang_hooks.types.type_for_size (size, unsignedp);
491 return type ? type : error_mark_node;
494 /* Support for DEF_BUILTIN. */
497 def_builtin_1 (enum built_in_function fncode, const char *name,
498 enum built_in_class fnclass, tree fntype, tree libtype,
499 bool both_p, bool fallback_p, bool nonansi_p,
500 tree fnattrs, bool implicit_p)
505 if (fntype == error_mark_node)
508 libname = name + strlen ("__builtin_");
509 decl = add_builtin_function (name, fntype, fncode, fnclass,
510 (fallback_p ? libname : NULL),
515 && !(nonansi_p && flag_no_nonansi_builtin))
516 add_builtin_function (libname, libtype, fncode, fnclass,
519 set_builtin_decl (fncode, decl, implicit_p);
523 /* Initialize the attribute table for all the supported builtins. */
526 lto_init_attributes (void)
528 /* Fill in the built_in_attributes array. */
529 #define DEF_ATTR_NULL_TREE(ENUM) \
530 built_in_attributes[(int) ENUM] = NULL_TREE;
531 #define DEF_ATTR_INT(ENUM, VALUE) \
532 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
533 #define DEF_ATTR_IDENT(ENUM, STRING) \
534 built_in_attributes[(int) ENUM] = get_identifier (STRING);
535 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
536 built_in_attributes[(int) ENUM] \
537 = tree_cons (built_in_attributes[(int) PURPOSE], \
538 built_in_attributes[(int) VALUE], \
539 built_in_attributes[(int) CHAIN]);
540 #include "builtin-attrs.def"
541 #undef DEF_ATTR_NULL_TREE
543 #undef DEF_ATTR_IDENT
544 #undef DEF_ATTR_TREE_LIST
547 /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
548 VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
551 lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
552 tree va_list_arg_type_node ATTRIBUTE_UNUSED)
554 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
555 builtin_types[ENUM] = VALUE;
556 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
557 def_fn_type (ENUM, RETURN, 0, 0);
558 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
559 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
560 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
561 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
562 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
563 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
564 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
565 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
566 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
567 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
568 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
570 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
571 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
573 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
574 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
575 def_fn_type (ENUM, RETURN, 1, 0);
576 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
577 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
578 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
579 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
580 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
581 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
582 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
583 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
584 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
585 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
586 #define DEF_POINTER_TYPE(ENUM, TYPE) \
587 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
589 #include "builtin-types.def"
591 #undef DEF_PRIMITIVE_TYPE
592 #undef DEF_FUNCTION_TYPE_1
593 #undef DEF_FUNCTION_TYPE_2
594 #undef DEF_FUNCTION_TYPE_3
595 #undef DEF_FUNCTION_TYPE_4
596 #undef DEF_FUNCTION_TYPE_5
597 #undef DEF_FUNCTION_TYPE_6
598 #undef DEF_FUNCTION_TYPE_VAR_0
599 #undef DEF_FUNCTION_TYPE_VAR_1
600 #undef DEF_FUNCTION_TYPE_VAR_2
601 #undef DEF_FUNCTION_TYPE_VAR_3
602 #undef DEF_FUNCTION_TYPE_VAR_4
603 #undef DEF_FUNCTION_TYPE_VAR_5
604 #undef DEF_POINTER_TYPE
605 builtin_types[(int) BT_LAST] = NULL_TREE;
607 lto_init_attributes ();
609 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
610 NONANSI_P, ATTRS, IMPLICIT, COND) \
612 def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
613 builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
614 NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
615 #include "builtins.def"
619 static GTY(()) tree registered_builtin_types;
621 /* Language hooks. */
624 lto_option_lang_mask (void)
630 lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
632 /* The LTO front end inherits all the options from the first front
633 end that was used. However, not all the original front end
634 options make sense in LTO.
636 A real solution would be to filter this in collect2, but collect2
637 does not have access to all the option attributes to know what to
638 filter. So, in lto1 we silently accept inherited flags and do
644 lto_init_options_struct (struct gcc_options *opts)
646 /* By default, C99-like requirements for complex multiply and divide.
647 ??? Until the complex method is encoded in the IL this is the only
648 safe choice. This will pessimize Fortran code with LTO unless
649 people specify a complex method manually or use -ffast-math. */
650 opts->x_flag_complex_method = 2;
653 /* Handle command-line option SCODE. If the option takes an argument, it is
654 stored in ARG, which is otherwise NULL. VALUE holds either a numerical
655 argument or a binary value indicating whether the positive or negative form
656 of the option was supplied. */
658 const char *resolution_file_name;
660 lto_handle_option (size_t scode, const char *arg,
661 int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
662 location_t loc ATTRIBUTE_UNUSED,
663 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
665 enum opt_code code = (enum opt_code) scode;
670 case OPT_fresolution_:
671 resolution_file_name = arg;
685 /* Perform post-option processing. Does additional initialization based on
686 command-line options. PFILENAME is the main input filename. Returns false
687 to enable subsequent back-end initialization. */
690 lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
692 /* -fltrans and -fwpa are mutually exclusive. Check for that here. */
693 if (flag_wpa && flag_ltrans)
694 error ("-fwpa and -fltrans are mutually exclusive");
698 flag_generate_lto = 0;
700 /* During LTRANS, we are not looking at the whole program, only
701 a subset of the whole callgraph. */
702 flag_whole_program = 0;
706 flag_generate_lto = 1;
708 /* Excess precision other than "fast" requires front-end
710 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
712 /* Initialize the compiler back end. */
716 /* Return an integer type with PRECISION bits of precision,
717 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
720 lto_type_for_size (unsigned precision, int unsignedp)
722 if (precision == TYPE_PRECISION (integer_type_node))
723 return unsignedp ? unsigned_type_node : integer_type_node;
725 if (precision == TYPE_PRECISION (signed_char_type_node))
726 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
728 if (precision == TYPE_PRECISION (short_integer_type_node))
729 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
731 if (precision == TYPE_PRECISION (long_integer_type_node))
732 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
734 if (precision == TYPE_PRECISION (long_long_integer_type_node))
736 ? long_long_unsigned_type_node
737 : long_long_integer_type_node;
739 if (precision <= TYPE_PRECISION (intQI_type_node))
740 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
742 if (precision <= TYPE_PRECISION (intHI_type_node))
743 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
745 if (precision <= TYPE_PRECISION (intSI_type_node))
746 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
748 if (precision <= TYPE_PRECISION (intDI_type_node))
749 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
751 if (precision <= TYPE_PRECISION (intTI_type_node))
752 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
758 /* Return a data type that has machine mode MODE.
759 If the mode is an integer,
760 then UNSIGNEDP selects between signed and unsigned types.
761 If the mode is a fixed-point mode,
762 then UNSIGNEDP selects between saturating and nonsaturating types. */
765 lto_type_for_mode (enum machine_mode mode, int unsigned_p)
769 if (mode == TYPE_MODE (integer_type_node))
770 return unsigned_p ? unsigned_type_node : integer_type_node;
772 if (mode == TYPE_MODE (signed_char_type_node))
773 return unsigned_p ? unsigned_char_type_node : signed_char_type_node;
775 if (mode == TYPE_MODE (short_integer_type_node))
776 return unsigned_p ? short_unsigned_type_node : short_integer_type_node;
778 if (mode == TYPE_MODE (long_integer_type_node))
779 return unsigned_p ? long_unsigned_type_node : long_integer_type_node;
781 if (mode == TYPE_MODE (long_long_integer_type_node))
782 return unsigned_p ? long_long_unsigned_type_node : long_long_integer_type_node;
785 return unsigned_p ? unsigned_intQI_type_node : intQI_type_node;
788 return unsigned_p ? unsigned_intHI_type_node : intHI_type_node;
791 return unsigned_p ? unsigned_intSI_type_node : intSI_type_node;
794 return unsigned_p ? unsigned_intDI_type_node : intDI_type_node;
796 #if HOST_BITS_PER_WIDE_INT >= 64
797 if (mode == TYPE_MODE (intTI_type_node))
798 return unsigned_p ? unsigned_intTI_type_node : intTI_type_node;
801 if (mode == TYPE_MODE (float_type_node))
802 return float_type_node;
804 if (mode == TYPE_MODE (double_type_node))
805 return double_type_node;
807 if (mode == TYPE_MODE (long_double_type_node))
808 return long_double_type_node;
810 if (mode == TYPE_MODE (void_type_node))
811 return void_type_node;
813 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
815 ? make_unsigned_type (GET_MODE_PRECISION (mode))
816 : make_signed_type (GET_MODE_PRECISION (mode)));
818 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
820 ? make_unsigned_type (GET_MODE_PRECISION (mode))
821 : make_signed_type (GET_MODE_PRECISION (mode)));
823 if (COMPLEX_MODE_P (mode))
825 enum machine_mode inner_mode;
828 if (mode == TYPE_MODE (complex_float_type_node))
829 return complex_float_type_node;
830 if (mode == TYPE_MODE (complex_double_type_node))
831 return complex_double_type_node;
832 if (mode == TYPE_MODE (complex_long_double_type_node))
833 return complex_long_double_type_node;
835 if (mode == TYPE_MODE (complex_integer_type_node) && !unsigned_p)
836 return complex_integer_type_node;
838 inner_mode = GET_MODE_INNER (mode);
839 inner_type = lto_type_for_mode (inner_mode, unsigned_p);
840 if (inner_type != NULL_TREE)
841 return build_complex_type (inner_type);
843 else if (VECTOR_MODE_P (mode))
845 enum machine_mode inner_mode = GET_MODE_INNER (mode);
846 tree inner_type = lto_type_for_mode (inner_mode, unsigned_p);
847 if (inner_type != NULL_TREE)
848 return build_vector_type_for_mode (inner_type, mode);
851 if (mode == TYPE_MODE (dfloat32_type_node))
852 return dfloat32_type_node;
853 if (mode == TYPE_MODE (dfloat64_type_node))
854 return dfloat64_type_node;
855 if (mode == TYPE_MODE (dfloat128_type_node))
856 return dfloat128_type_node;
858 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
860 if (mode == TYPE_MODE (short_fract_type_node))
861 return unsigned_p ? sat_short_fract_type_node : short_fract_type_node;
862 if (mode == TYPE_MODE (fract_type_node))
863 return unsigned_p ? sat_fract_type_node : fract_type_node;
864 if (mode == TYPE_MODE (long_fract_type_node))
865 return unsigned_p ? sat_long_fract_type_node : long_fract_type_node;
866 if (mode == TYPE_MODE (long_long_fract_type_node))
867 return unsigned_p ? sat_long_long_fract_type_node
868 : long_long_fract_type_node;
870 if (mode == TYPE_MODE (unsigned_short_fract_type_node))
871 return unsigned_p ? sat_unsigned_short_fract_type_node
872 : unsigned_short_fract_type_node;
873 if (mode == TYPE_MODE (unsigned_fract_type_node))
874 return unsigned_p ? sat_unsigned_fract_type_node
875 : unsigned_fract_type_node;
876 if (mode == TYPE_MODE (unsigned_long_fract_type_node))
877 return unsigned_p ? sat_unsigned_long_fract_type_node
878 : unsigned_long_fract_type_node;
879 if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
880 return unsigned_p ? sat_unsigned_long_long_fract_type_node
881 : unsigned_long_long_fract_type_node;
883 if (mode == TYPE_MODE (short_accum_type_node))
884 return unsigned_p ? sat_short_accum_type_node : short_accum_type_node;
885 if (mode == TYPE_MODE (accum_type_node))
886 return unsigned_p ? sat_accum_type_node : accum_type_node;
887 if (mode == TYPE_MODE (long_accum_type_node))
888 return unsigned_p ? sat_long_accum_type_node : long_accum_type_node;
889 if (mode == TYPE_MODE (long_long_accum_type_node))
890 return unsigned_p ? sat_long_long_accum_type_node
891 : long_long_accum_type_node;
893 if (mode == TYPE_MODE (unsigned_short_accum_type_node))
894 return unsigned_p ? sat_unsigned_short_accum_type_node
895 : unsigned_short_accum_type_node;
896 if (mode == TYPE_MODE (unsigned_accum_type_node))
897 return unsigned_p ? sat_unsigned_accum_type_node
898 : unsigned_accum_type_node;
899 if (mode == TYPE_MODE (unsigned_long_accum_type_node))
900 return unsigned_p ? sat_unsigned_long_accum_type_node
901 : unsigned_long_accum_type_node;
902 if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
903 return unsigned_p ? sat_unsigned_long_long_accum_type_node
904 : unsigned_long_long_accum_type_node;
907 return unsigned_p ? sat_qq_type_node : qq_type_node;
909 return unsigned_p ? sat_hq_type_node : hq_type_node;
911 return unsigned_p ? sat_sq_type_node : sq_type_node;
913 return unsigned_p ? sat_dq_type_node : dq_type_node;
915 return unsigned_p ? sat_tq_type_node : tq_type_node;
918 return unsigned_p ? sat_uqq_type_node : uqq_type_node;
920 return unsigned_p ? sat_uhq_type_node : uhq_type_node;
922 return unsigned_p ? sat_usq_type_node : usq_type_node;
924 return unsigned_p ? sat_udq_type_node : udq_type_node;
926 return unsigned_p ? sat_utq_type_node : utq_type_node;
929 return unsigned_p ? sat_ha_type_node : ha_type_node;
931 return unsigned_p ? sat_sa_type_node : sa_type_node;
933 return unsigned_p ? sat_da_type_node : da_type_node;
935 return unsigned_p ? sat_ta_type_node : ta_type_node;
938 return unsigned_p ? sat_uha_type_node : uha_type_node;
940 return unsigned_p ? sat_usa_type_node : usa_type_node;
942 return unsigned_p ? sat_uda_type_node : uda_type_node;
944 return unsigned_p ? sat_uta_type_node : uta_type_node;
947 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
948 if (TYPE_MODE (TREE_VALUE (t)) == mode)
949 return TREE_VALUE (t);
954 /* Return true if we are in the global binding level. */
957 lto_global_bindings_p (void)
963 lto_set_decl_assembler_name (tree decl)
965 /* This is almost the same as lhd_set_decl_assembler_name, except that
966 we need to uniquify file-scope names, even if they are not
967 TREE_PUBLIC, to avoid conflicts between individual files. */
970 if (TREE_PUBLIC (decl))
971 id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
974 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
977 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
978 id = get_identifier (label);
981 SET_DECL_ASSEMBLER_NAME (decl, id);
985 lto_pushdecl (tree t ATTRIBUTE_UNUSED)
987 /* Do nothing, since we get all information from DWARF and LTO
995 /* We have our own write_globals langhook, hence the getdecls
996 langhook shouldn't be used, except by dbxout.c, so we can't
1002 lto_write_globals (void)
1004 tree *vec = VEC_address (tree, lto_global_var_decls);
1005 int len = VEC_length (tree, lto_global_var_decls);
1006 wrapup_global_declarations (vec, len);
1007 emit_debug_global_declarations (vec, len);
1008 VEC_free (tree, gc, lto_global_var_decls);
1012 lto_builtin_function (tree decl)
1018 lto_register_builtin_type (tree type, const char *name)
1022 decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier (name), type);
1023 DECL_ARTIFICIAL (decl) = 1;
1024 if (!TYPE_NAME (type))
1025 TYPE_NAME (type) = decl;
1027 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
1030 /* Build nodes that would have be created by the C front-end; necessary
1031 for including builtin-types.def and ultimately builtins.def. */
1034 lto_build_c_type_nodes (void)
1036 gcc_assert (void_type_node);
1038 void_list_node = build_tree_list (NULL_TREE, void_type_node);
1039 string_type_node = build_pointer_type (char_type_node);
1040 const_string_type_node
1041 = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
1043 if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1045 intmax_type_node = integer_type_node;
1046 uintmax_type_node = unsigned_type_node;
1047 signed_size_type_node = integer_type_node;
1049 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1051 intmax_type_node = long_integer_type_node;
1052 uintmax_type_node = long_unsigned_type_node;
1053 signed_size_type_node = long_integer_type_node;
1055 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1057 intmax_type_node = long_long_integer_type_node;
1058 uintmax_type_node = long_long_unsigned_type_node;
1059 signed_size_type_node = long_long_integer_type_node;
1064 wint_type_node = unsigned_type_node;
1065 pid_type_node = integer_type_node;
1068 /* Re-compute TYPE_CANONICAL for NODE and related types. */
1071 lto_register_canonical_types (tree node)
1077 TYPE_CANONICAL (node) = NULL_TREE;
1078 TYPE_CANONICAL (node) = gimple_register_canonical_type (node);
1080 if (POINTER_TYPE_P (node)
1081 || TREE_CODE (node) == COMPLEX_TYPE
1082 || TREE_CODE (node) == ARRAY_TYPE)
1083 lto_register_canonical_types (TREE_TYPE (node));
1086 /* Perform LTO-specific initialization. */
1093 /* We need to generate LTO if running in WPA mode. */
1094 flag_generate_lto = flag_wpa;
1096 /* Initialize libcpp line maps for gcc_assert to work. */
1097 linemap_add (line_table, LC_ENTER, 0, NULL, 0);
1099 /* Create the basic integer types. */
1100 build_common_tree_nodes (flag_signed_char, /*short_double=*/false);
1102 /* The global tree for the main identifier is filled in by
1103 language-specific front-end initialization that is not run in the
1104 LTO back-end. It appears that all languages that perform such
1105 initialization currently do so in the same way, so we do it here. */
1106 if (main_identifier_node == NULL_TREE)
1107 main_identifier_node = get_identifier ("main");
1109 /* In the C++ front-end, fileptr_type_node is defined as a variant
1110 copy of of ptr_type_node, rather than ptr_node itself. The
1111 distinction should only be relevant to the front-end, so we
1112 always use the C definition here in lto1. */
1113 gcc_assert (fileptr_type_node == ptr_type_node);
1114 gcc_assert (TYPE_MAIN_VARIANT (fileptr_type_node) == ptr_type_node);
1116 ptrdiff_type_node = integer_type_node;
1118 lto_build_c_type_nodes ();
1119 gcc_assert (va_list_type_node);
1121 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1123 tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
1124 lto_define_builtins (x, x);
1128 lto_define_builtins (va_list_type_node,
1129 build_reference_type (va_list_type_node));
1132 targetm.init_builtins ();
1133 build_common_builtin_nodes ();
1135 /* Assign names to the builtin types, otherwise they'll end up
1136 as __unknown__ in debug info.
1137 ??? We simply need to stop pre-seeding the streamer cache.
1138 Below is modeled after from c-common.c:c_common_nodes_and_builtins */
1139 #define NAME_TYPE(t,n) \
1141 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \
1142 get_identifier (n), t)
1143 NAME_TYPE (integer_type_node, "int");
1144 NAME_TYPE (char_type_node, "char");
1145 NAME_TYPE (long_integer_type_node, "long int");
1146 NAME_TYPE (unsigned_type_node, "unsigned int");
1147 NAME_TYPE (long_unsigned_type_node, "long unsigned int");
1148 NAME_TYPE (long_long_integer_type_node, "long long int");
1149 NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int");
1150 NAME_TYPE (short_integer_type_node, "short int");
1151 NAME_TYPE (short_unsigned_type_node, "short unsigned int");
1152 if (signed_char_type_node != char_type_node)
1153 NAME_TYPE (signed_char_type_node, "signed char");
1154 if (unsigned_char_type_node != char_type_node)
1155 NAME_TYPE (unsigned_char_type_node, "unsigned char");
1156 NAME_TYPE (float_type_node, "float");
1157 NAME_TYPE (double_type_node, "double");
1158 NAME_TYPE (long_double_type_node, "long double");
1159 NAME_TYPE (void_type_node, "void");
1160 NAME_TYPE (boolean_type_node, "bool");
1163 /* Register the common node types with the canonical type machinery so
1164 we properly share alias-sets across languages and TUs. Do not
1165 expose the common nodes as type merge target - those that should be
1166 are already exposed so by pre-loading the LTO streamer caches. */
1167 for (i = 0; i < itk_none; ++i)
1168 lto_register_canonical_types (integer_types[i]);
1169 /* The sizetypes are not used to access data so we do not need to
1170 do anything about them. */
1171 for (i = 0; i < TI_MAX; ++i)
1172 lto_register_canonical_types (global_trees[i]);
1174 /* Initialize LTO-specific data structures. */
1175 lto_global_var_decls = VEC_alloc (tree, gc, 256);
1181 /* Initialize tree structures required by the LTO front end. */
1183 static void lto_init_ts (void)
1185 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1188 #undef LANG_HOOKS_NAME
1189 #define LANG_HOOKS_NAME "GNU GIMPLE"
1190 #undef LANG_HOOKS_OPTION_LANG_MASK
1191 #define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
1192 #undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
1193 #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
1194 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1195 #define LANG_HOOKS_INIT_OPTIONS_STRUCT lto_init_options_struct
1196 #undef LANG_HOOKS_HANDLE_OPTION
1197 #define LANG_HOOKS_HANDLE_OPTION lto_handle_option
1198 #undef LANG_HOOKS_POST_OPTIONS
1199 #define LANG_HOOKS_POST_OPTIONS lto_post_options
1200 #undef LANG_HOOKS_GET_ALIAS_SET
1201 #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
1202 #undef LANG_HOOKS_TYPE_FOR_MODE
1203 #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
1204 #undef LANG_HOOKS_TYPE_FOR_SIZE
1205 #define LANG_HOOKS_TYPE_FOR_SIZE lto_type_for_size
1206 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
1207 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
1208 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1209 #define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
1210 #undef LANG_HOOKS_PUSHDECL
1211 #define LANG_HOOKS_PUSHDECL lto_pushdecl
1212 #undef LANG_HOOKS_GETDECLS
1213 #define LANG_HOOKS_GETDECLS lto_getdecls
1214 #undef LANG_HOOKS_WRITE_GLOBALS
1215 #define LANG_HOOKS_WRITE_GLOBALS lto_write_globals
1216 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1217 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
1218 #undef LANG_HOOKS_BUILTIN_FUNCTION
1219 #define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
1220 #undef LANG_HOOKS_INIT
1221 #define LANG_HOOKS_INIT lto_init
1222 #undef LANG_HOOKS_PARSE_FILE
1223 #define LANG_HOOKS_PARSE_FILE lto_main
1224 #undef LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION
1225 #define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION tree_rest_of_compilation
1226 #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
1227 #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
1228 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1229 #define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
1230 #undef LANG_HOOKS_EH_PERSONALITY
1231 #define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
1233 /* Attribute hooks. */
1234 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1235 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
1236 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
1237 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
1239 #undef LANG_HOOKS_BEGIN_SECTION
1240 #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
1241 #undef LANG_HOOKS_APPEND_DATA
1242 #define LANG_HOOKS_APPEND_DATA lto_obj_append_data
1243 #undef LANG_HOOKS_END_SECTION
1244 #define LANG_HOOKS_END_SECTION lto_obj_end_section
1246 #undef LANG_HOOKS_INIT_TS
1247 #define LANG_HOOKS_INIT_TS lto_init_ts
1249 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1251 /* Language hooks that are not part of lang_hooks. */
1254 convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1259 /* Tree walking support. */
1261 static enum lto_tree_node_structure_enum
1262 lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
1264 return TS_LTO_GENERIC;
1268 #include "gtype-lto.h"
1269 #include "gt-lto-lto-lang.h"