* cgraphunit.c (cgraph_node::expand_thunk): Do not force DECL_IGNORED_P
[official-gcc.git] / gcc / lto / lto-lang.c
blob8eb4a25a6340df346648cddce38ad4f2cc5f249e
1 /* Language-dependent hooks for LTO.
2 Copyright (C) 2009-2018 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
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "target.h"
25 #include "function.h"
26 #include "basic-block.h"
27 #include "tree.h"
28 #include "gimple.h"
29 #include "stringpool.h"
30 #include "diagnostic-core.h"
31 #include "stor-layout.h"
32 #include "langhooks.h"
33 #include "langhooks-def.h"
34 #include "debug.h"
35 #include "lto-tree.h"
36 #include "lto.h"
37 #include "stringpool.h"
38 #include "attribs.h"
40 /* LTO specific dumps. */
41 int lto_link_dump_id, decl_merge_dump_id, partition_dump_id;
43 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
44 static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
45 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
46 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
47 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
48 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
49 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
50 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
51 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
52 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
53 static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool *);
54 static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
55 static tree handle_patchable_function_entry_attribute (tree *, tree, tree,
56 int, bool *);
57 static tree ignore_attribute (tree *, tree, tree, int, bool *);
59 static tree handle_format_attribute (tree *, tree, tree, int, bool *);
60 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
61 static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
63 /* Helper to define attribute exclusions. */
64 #define ATTR_EXCL(name, function, type, variable) \
65 { name, function, type, variable }
67 /* Define attributes that are mutually exclusive with one another. */
68 static const struct attribute_spec::exclusions attr_noreturn_exclusions[] =
70 ATTR_EXCL ("noreturn", true, true, true),
71 ATTR_EXCL ("alloc_align", true, true, true),
72 ATTR_EXCL ("alloc_size", true, true, true),
73 ATTR_EXCL ("const", true, true, true),
74 ATTR_EXCL ("malloc", true, true, true),
75 ATTR_EXCL ("pure", true, true, true),
76 ATTR_EXCL ("returns_twice", true, true, true),
77 ATTR_EXCL ("warn_unused_result", true, true, true),
78 ATTR_EXCL (NULL, false, false, false),
81 static const struct attribute_spec::exclusions attr_returns_twice_exclusions[] =
83 ATTR_EXCL ("noreturn", true, true, true),
84 ATTR_EXCL (NULL, false, false, false),
87 static const struct attribute_spec::exclusions attr_const_pure_exclusions[] =
89 ATTR_EXCL ("const", true, true, true),
90 ATTR_EXCL ("noreturn", true, true, true),
91 ATTR_EXCL ("pure", true, true, true),
92 ATTR_EXCL (NULL, false, false, false)
95 /* Table of machine-independent attributes supported in GIMPLE. */
96 const struct attribute_spec lto_attribute_table[] =
98 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
99 affects_type_identity, handler, exclude } */
100 { "noreturn", 0, 0, true, false, false, false,
101 handle_noreturn_attribute,
102 attr_noreturn_exclusions },
103 { "leaf", 0, 0, true, false, false, false,
104 handle_leaf_attribute, NULL },
105 /* The same comments as for noreturn attributes apply to const ones. */
106 { "const", 0, 0, true, false, false, false,
107 handle_const_attribute,
108 attr_const_pure_exclusions },
109 { "malloc", 0, 0, true, false, false, false,
110 handle_malloc_attribute, NULL },
111 { "pure", 0, 0, true, false, false, false,
112 handle_pure_attribute,
113 attr_const_pure_exclusions },
114 { "no vops", 0, 0, true, false, false, false,
115 handle_novops_attribute, NULL },
116 { "nonnull", 0, -1, false, true, true, false,
117 handle_nonnull_attribute, NULL },
118 { "nothrow", 0, 0, true, false, false, false,
119 handle_nothrow_attribute, NULL },
120 { "patchable_function_entry", 1, 2, true, false, false, false,
121 handle_patchable_function_entry_attribute,
122 NULL },
123 { "returns_twice", 0, 0, true, false, false, false,
124 handle_returns_twice_attribute,
125 attr_returns_twice_exclusions },
126 { "sentinel", 0, 1, false, true, true, false,
127 handle_sentinel_attribute, NULL },
128 { "type generic", 0, 0, false, true, true, false,
129 handle_type_generic_attribute, NULL },
130 { "fn spec", 1, 1, false, true, true, false,
131 handle_fnspec_attribute, NULL },
132 { "transaction_pure", 0, 0, false, true, true, false,
133 handle_transaction_pure_attribute, NULL },
134 /* For internal use only. The leading '*' both prevents its usage in
135 source code and signals that it may be overridden by machine tables. */
136 { "*tm regparm", 0, 0, false, true, true, false,
137 ignore_attribute, NULL },
138 { NULL, 0, 0, false, false, false, false, NULL, NULL }
141 /* Give the specifications for the format attributes, used by C and all
142 descendants. */
144 const struct attribute_spec lto_format_attribute_table[] =
146 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
147 affects_type_identity, handler, exclude } */
148 { "format", 3, 3, false, true, true, false,
149 handle_format_attribute, NULL },
150 { "format_arg", 1, 1, false, true, true, false,
151 handle_format_arg_attribute, NULL },
152 { NULL, 0, 0, false, false, false, false, NULL, NULL }
155 enum built_in_attribute
157 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
158 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
159 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
160 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
161 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
162 #include "builtin-attrs.def"
163 #undef DEF_ATTR_NULL_TREE
164 #undef DEF_ATTR_INT
165 #undef DEF_ATTR_STRING
166 #undef DEF_ATTR_IDENT
167 #undef DEF_ATTR_TREE_LIST
168 ATTR_LAST
171 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
173 /* Builtin types. */
175 enum lto_builtin_type
177 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
178 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
179 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
180 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
181 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
182 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
183 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
184 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
185 ARG6) NAME,
186 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
187 ARG6, ARG7) NAME,
188 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
189 ARG6, ARG7, ARG8) NAME,
190 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
191 ARG6, ARG7, ARG8, ARG9) NAME,
192 #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
193 ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
194 #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
195 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
196 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
197 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
198 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
199 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
200 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
201 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
202 NAME,
203 #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
204 ARG6) NAME,
205 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
206 ARG6, ARG7) NAME,
207 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
208 #include "builtin-types.def"
209 #undef DEF_PRIMITIVE_TYPE
210 #undef DEF_FUNCTION_TYPE_0
211 #undef DEF_FUNCTION_TYPE_1
212 #undef DEF_FUNCTION_TYPE_2
213 #undef DEF_FUNCTION_TYPE_3
214 #undef DEF_FUNCTION_TYPE_4
215 #undef DEF_FUNCTION_TYPE_5
216 #undef DEF_FUNCTION_TYPE_6
217 #undef DEF_FUNCTION_TYPE_7
218 #undef DEF_FUNCTION_TYPE_8
219 #undef DEF_FUNCTION_TYPE_9
220 #undef DEF_FUNCTION_TYPE_10
221 #undef DEF_FUNCTION_TYPE_11
222 #undef DEF_FUNCTION_TYPE_VAR_0
223 #undef DEF_FUNCTION_TYPE_VAR_1
224 #undef DEF_FUNCTION_TYPE_VAR_2
225 #undef DEF_FUNCTION_TYPE_VAR_3
226 #undef DEF_FUNCTION_TYPE_VAR_4
227 #undef DEF_FUNCTION_TYPE_VAR_5
228 #undef DEF_FUNCTION_TYPE_VAR_6
229 #undef DEF_FUNCTION_TYPE_VAR_7
230 #undef DEF_POINTER_TYPE
231 BT_LAST
234 typedef enum lto_builtin_type builtin_type;
236 static GTY(()) tree builtin_types[(int) BT_LAST + 1];
238 static GTY(()) tree string_type_node;
239 static GTY(()) tree const_string_type_node;
240 static GTY(()) tree wint_type_node;
241 static GTY(()) tree intmax_type_node;
242 static GTY(()) tree uintmax_type_node;
243 static GTY(()) tree signed_size_type_node;
245 /* Flags needed to process builtins.def. */
246 int flag_isoc94;
247 int flag_isoc99;
248 int flag_isoc11;
250 /* Attribute handlers. */
252 /* Handle a "noreturn" attribute; arguments as in
253 struct attribute_spec.handler. */
255 static tree
256 handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
257 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
258 bool * ARG_UNUSED (no_add_attrs))
260 tree type = TREE_TYPE (*node);
262 if (TREE_CODE (*node) == FUNCTION_DECL)
263 TREE_THIS_VOLATILE (*node) = 1;
264 else if (TREE_CODE (type) == POINTER_TYPE
265 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
266 TREE_TYPE (*node)
267 = build_pointer_type
268 (build_type_variant (TREE_TYPE (type),
269 TYPE_READONLY (TREE_TYPE (type)), 1));
270 else
271 gcc_unreachable ();
273 return NULL_TREE;
276 /* Handle a "leaf" attribute; arguments as in
277 struct attribute_spec.handler. */
279 static tree
280 handle_leaf_attribute (tree *node, tree name,
281 tree ARG_UNUSED (args),
282 int ARG_UNUSED (flags), bool *no_add_attrs)
284 if (TREE_CODE (*node) != FUNCTION_DECL)
286 warning (OPT_Wattributes, "%qE attribute ignored", name);
287 *no_add_attrs = true;
289 if (!TREE_PUBLIC (*node))
291 warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
292 *no_add_attrs = true;
295 return NULL_TREE;
298 /* Handle a "const" attribute; arguments as in
299 struct attribute_spec.handler. */
301 static tree
302 handle_const_attribute (tree *node, tree ARG_UNUSED (name),
303 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
304 bool * ARG_UNUSED (no_add_attrs))
306 if (!fndecl_built_in_p (*node))
307 inform (UNKNOWN_LOCATION, "%s:%s: %E: %E", __FILE__, __func__, *node, name);
309 tree type = TREE_TYPE (*node);
311 /* See FIXME comment on noreturn in c_common_attribute_table. */
312 if (TREE_CODE (*node) == FUNCTION_DECL)
313 TREE_READONLY (*node) = 1;
314 else if (TREE_CODE (type) == POINTER_TYPE
315 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
316 TREE_TYPE (*node)
317 = build_pointer_type
318 (build_type_variant (TREE_TYPE (type), 1,
319 TREE_THIS_VOLATILE (TREE_TYPE (type))));
320 else
321 gcc_unreachable ();
323 return NULL_TREE;
327 /* Handle a "malloc" attribute; arguments as in
328 struct attribute_spec.handler. */
330 static tree
331 handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
332 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
333 bool * ARG_UNUSED (no_add_attrs))
335 if (TREE_CODE (*node) == FUNCTION_DECL
336 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
337 DECL_IS_MALLOC (*node) = 1;
338 else
339 gcc_unreachable ();
341 return NULL_TREE;
345 /* Handle a "pure" attribute; arguments as in
346 struct attribute_spec.handler. */
348 static tree
349 handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
350 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
351 bool * ARG_UNUSED (no_add_attrs))
353 if (TREE_CODE (*node) == FUNCTION_DECL)
354 DECL_PURE_P (*node) = 1;
355 else
356 gcc_unreachable ();
358 return NULL_TREE;
362 /* Handle a "no vops" attribute; arguments as in
363 struct attribute_spec.handler. */
365 static tree
366 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
367 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
368 bool *ARG_UNUSED (no_add_attrs))
370 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
371 DECL_IS_NOVOPS (*node) = 1;
372 return NULL_TREE;
376 /* Helper for nonnull attribute handling; fetch the operand number
377 from the attribute argument list. */
379 static bool
380 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
382 /* Verify the arg number is a constant. */
383 if (!tree_fits_uhwi_p (arg_num_expr))
384 return false;
386 *valp = TREE_INT_CST_LOW (arg_num_expr);
387 return true;
390 /* Handle the "nonnull" attribute. */
392 static tree
393 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
394 tree args, int ARG_UNUSED (flags),
395 bool * ARG_UNUSED (no_add_attrs))
397 tree type = *node;
399 /* If no arguments are specified, all pointer arguments should be
400 non-null. Verify a full prototype is given so that the arguments
401 will have the correct types when we actually check them later.
402 Avoid diagnosing type-generic built-ins since those have no
403 prototype. */
404 if (!args)
406 gcc_assert (prototype_p (type)
407 || !TYPE_ATTRIBUTES (type)
408 || lookup_attribute ("type generic", TYPE_ATTRIBUTES (type)));
410 return NULL_TREE;
413 /* Argument list specified. Verify that each argument number references
414 a pointer argument. */
415 for (; args; args = TREE_CHAIN (args))
417 tree argument;
418 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
420 if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
421 gcc_unreachable ();
423 argument = TYPE_ARG_TYPES (type);
424 if (argument)
426 for (ck_num = 1; ; ck_num++)
428 if (!argument || ck_num == arg_num)
429 break;
430 argument = TREE_CHAIN (argument);
433 gcc_assert (argument
434 && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
438 return NULL_TREE;
442 /* Handle a "nothrow" attribute; arguments as in
443 struct attribute_spec.handler. */
445 static tree
446 handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
447 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
448 bool * ARG_UNUSED (no_add_attrs))
450 if (TREE_CODE (*node) == FUNCTION_DECL)
451 TREE_NOTHROW (*node) = 1;
452 else
453 gcc_unreachable ();
455 return NULL_TREE;
459 /* Handle a "sentinel" attribute. */
461 static tree
462 handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
463 int ARG_UNUSED (flags),
464 bool * ARG_UNUSED (no_add_attrs))
466 gcc_assert (stdarg_p (*node));
468 if (args)
470 tree position = TREE_VALUE (args);
471 gcc_assert (TREE_CODE (position) == INTEGER_CST);
472 if (tree_int_cst_lt (position, integer_zero_node))
473 gcc_unreachable ();
476 return NULL_TREE;
479 /* Handle a "type_generic" attribute. */
481 static tree
482 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
483 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
484 bool * ARG_UNUSED (no_add_attrs))
486 /* Ensure we have a function type. */
487 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
489 /* Ensure we have a variadic function. */
490 gcc_assert (!prototype_p (*node) || stdarg_p (*node));
492 return NULL_TREE;
495 /* Handle a "transaction_pure" attribute. */
497 static tree
498 handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
499 tree ARG_UNUSED (args),
500 int ARG_UNUSED (flags),
501 bool * ARG_UNUSED (no_add_attrs))
503 /* Ensure we have a function type. */
504 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
506 return NULL_TREE;
509 /* Handle a "returns_twice" attribute. */
511 static tree
512 handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name),
513 tree ARG_UNUSED (args),
514 int ARG_UNUSED (flags),
515 bool * ARG_UNUSED (no_add_attrs))
517 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
519 DECL_IS_RETURNS_TWICE (*node) = 1;
521 return NULL_TREE;
524 static tree
525 handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
527 /* Nothing to be done here. */
528 return NULL_TREE;
531 /* Ignore the given attribute. Used when this attribute may be usefully
532 overridden by the target, but is not used generically. */
534 static tree
535 ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
536 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
537 bool *no_add_attrs)
539 *no_add_attrs = true;
540 return NULL_TREE;
543 /* Handle a "format" attribute; arguments as in
544 struct attribute_spec.handler. */
546 static tree
547 handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
548 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
549 bool *no_add_attrs)
551 *no_add_attrs = true;
552 return NULL_TREE;
556 /* Handle a "format_arg" attribute; arguments as in
557 struct attribute_spec.handler. */
559 tree
560 handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
561 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
562 bool *no_add_attrs)
564 *no_add_attrs = true;
565 return NULL_TREE;
569 /* Handle a "fn spec" attribute; arguments as in
570 struct attribute_spec.handler. */
572 static tree
573 handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
574 tree args, int ARG_UNUSED (flags),
575 bool *no_add_attrs ATTRIBUTE_UNUSED)
577 gcc_assert (args
578 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
579 && !TREE_CHAIN (args));
580 return NULL_TREE;
583 /* Cribbed from c-common.c. */
585 static void
586 def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
588 tree t;
589 tree *args = XALLOCAVEC (tree, n);
590 va_list list;
591 int i;
592 bool err = false;
594 va_start (list, n);
595 for (i = 0; i < n; ++i)
597 builtin_type a = (builtin_type) va_arg (list, int);
598 t = builtin_types[a];
599 if (t == error_mark_node)
600 err = true;
601 args[i] = t;
603 va_end (list);
605 t = builtin_types[ret];
606 if (err)
607 t = error_mark_node;
608 if (t == error_mark_node)
610 else if (var)
611 t = build_varargs_function_type_array (t, n, args);
612 else
613 t = build_function_type_array (t, n, args);
615 builtin_types[def] = t;
618 /* Used to help initialize the builtin-types.def table. When a type of
619 the correct size doesn't exist, use error_mark_node instead of NULL.
620 The later results in segfaults even when a decl using the type doesn't
621 get invoked. */
623 static tree
624 builtin_type_for_size (int size, bool unsignedp)
626 tree type = lang_hooks.types.type_for_size (size, unsignedp);
627 return type ? type : error_mark_node;
630 /* Support for DEF_BUILTIN. */
632 static void
633 def_builtin_1 (enum built_in_function fncode, const char *name,
634 enum built_in_class fnclass, tree fntype, tree libtype,
635 bool both_p, bool fallback_p, bool nonansi_p,
636 tree fnattrs, bool implicit_p)
638 tree decl;
639 const char *libname;
641 if (fntype == error_mark_node)
642 return;
644 libname = name + strlen ("__builtin_");
645 decl = add_builtin_function (name, fntype, fncode, fnclass,
646 (fallback_p ? libname : NULL),
647 fnattrs);
649 if (both_p
650 && !flag_no_builtin
651 && !(nonansi_p && flag_no_nonansi_builtin))
652 add_builtin_function (libname, libtype, fncode, fnclass,
653 NULL, fnattrs);
655 set_builtin_decl (fncode, decl, implicit_p);
659 /* Initialize the attribute table for all the supported builtins. */
661 static void
662 lto_init_attributes (void)
664 /* Fill in the built_in_attributes array. */
665 #define DEF_ATTR_NULL_TREE(ENUM) \
666 built_in_attributes[(int) ENUM] = NULL_TREE;
667 #define DEF_ATTR_INT(ENUM, VALUE) \
668 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
669 #define DEF_ATTR_STRING(ENUM, VALUE) \
670 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
671 #define DEF_ATTR_IDENT(ENUM, STRING) \
672 built_in_attributes[(int) ENUM] = get_identifier (STRING);
673 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
674 built_in_attributes[(int) ENUM] \
675 = tree_cons (built_in_attributes[(int) PURPOSE], \
676 built_in_attributes[(int) VALUE], \
677 built_in_attributes[(int) CHAIN]);
678 #include "builtin-attrs.def"
679 #undef DEF_ATTR_NULL_TREE
680 #undef DEF_ATTR_INT
681 #undef DEF_ATTR_STRING
682 #undef DEF_ATTR_IDENT
683 #undef DEF_ATTR_TREE_LIST
686 /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
687 VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
689 static void
690 lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
691 tree va_list_arg_type_node ATTRIBUTE_UNUSED)
693 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
694 builtin_types[ENUM] = VALUE;
695 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
696 def_fn_type (ENUM, RETURN, 0, 0);
697 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
698 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
699 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
700 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
701 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
702 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
703 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
704 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
705 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
706 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
707 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
708 ARG6) \
709 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
710 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
711 ARG6, ARG7) \
712 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
713 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
714 ARG6, ARG7, ARG8) \
715 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
716 ARG7, ARG8);
717 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
718 ARG6, ARG7, ARG8, ARG9) \
719 def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
720 ARG7, ARG8, ARG9);
721 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
722 ARG6, ARG7, ARG8, ARG9, ARG10) \
723 def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
724 ARG7, ARG8, ARG9, ARG10);
725 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
726 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
727 def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
728 ARG7, ARG8, ARG9, ARG10, ARG11);
729 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
730 def_fn_type (ENUM, RETURN, 1, 0);
731 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
732 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
733 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
734 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
735 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
736 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
737 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
738 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
739 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
740 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
741 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
742 ARG6) \
743 def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
744 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
745 ARG6, ARG7) \
746 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
747 #define DEF_POINTER_TYPE(ENUM, TYPE) \
748 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
750 #include "builtin-types.def"
752 #undef DEF_PRIMITIVE_TYPE
753 #undef DEF_FUNCTION_TYPE_0
754 #undef DEF_FUNCTION_TYPE_1
755 #undef DEF_FUNCTION_TYPE_2
756 #undef DEF_FUNCTION_TYPE_3
757 #undef DEF_FUNCTION_TYPE_4
758 #undef DEF_FUNCTION_TYPE_5
759 #undef DEF_FUNCTION_TYPE_6
760 #undef DEF_FUNCTION_TYPE_7
761 #undef DEF_FUNCTION_TYPE_8
762 #undef DEF_FUNCTION_TYPE_9
763 #undef DEF_FUNCTION_TYPE_10
764 #undef DEF_FUNCTION_TYPE_11
765 #undef DEF_FUNCTION_TYPE_VAR_0
766 #undef DEF_FUNCTION_TYPE_VAR_1
767 #undef DEF_FUNCTION_TYPE_VAR_2
768 #undef DEF_FUNCTION_TYPE_VAR_3
769 #undef DEF_FUNCTION_TYPE_VAR_4
770 #undef DEF_FUNCTION_TYPE_VAR_5
771 #undef DEF_FUNCTION_TYPE_VAR_6
772 #undef DEF_FUNCTION_TYPE_VAR_7
773 #undef DEF_POINTER_TYPE
774 builtin_types[(int) BT_LAST] = NULL_TREE;
776 lto_init_attributes ();
778 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
779 NONANSI_P, ATTRS, IMPLICIT, COND) \
780 if (NAME && COND) \
781 def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
782 builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
783 NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
784 #include "builtins.def"
787 static GTY(()) tree registered_builtin_types;
789 /* Language hooks. */
791 static unsigned int
792 lto_option_lang_mask (void)
794 return CL_LTO;
797 static bool
798 lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
800 /* The LTO front end inherits all the options from the first front
801 end that was used. However, not all the original front end
802 options make sense in LTO.
804 A real solution would be to filter this in collect2, but collect2
805 does not have access to all the option attributes to know what to
806 filter. So, in lto1 we silently accept inherited flags and do
807 nothing about it. */
808 return false;
811 static void
812 lto_init_options_struct (struct gcc_options *opts)
814 /* By default, C99-like requirements for complex multiply and divide.
815 ??? Until the complex method is encoded in the IL this is the only
816 safe choice. This will pessimize Fortran code with LTO unless
817 people specify a complex method manually or use -ffast-math. */
818 opts->x_flag_complex_method = 2;
821 /* Handle command-line option SCODE. If the option takes an argument, it is
822 stored in ARG, which is otherwise NULL. VALUE holds either a numerical
823 argument or a binary value indicating whether the positive or negative form
824 of the option was supplied. */
826 const char *resolution_file_name;
827 static bool
828 lto_handle_option (size_t scode, const char *arg,
829 HOST_WIDE_INT value ATTRIBUTE_UNUSED,
830 int kind ATTRIBUTE_UNUSED,
831 location_t loc ATTRIBUTE_UNUSED,
832 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
834 enum opt_code code = (enum opt_code) scode;
835 bool result = true;
837 switch (code)
839 case OPT_fresolution_:
840 resolution_file_name = arg;
841 break;
843 case OPT_Wabi:
844 warn_psabi = value;
845 break;
847 case OPT_fwpa:
848 flag_wpa = value ? "" : NULL;
849 break;
851 default:
852 break;
855 return result;
858 /* Perform post-option processing. Does additional initialization based on
859 command-line options. PFILENAME is the main input filename. Returns false
860 to enable subsequent back-end initialization. */
862 static bool
863 lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
865 /* -fltrans and -fwpa are mutually exclusive. Check for that here. */
866 if (flag_wpa && flag_ltrans)
867 error ("-fwpa and -fltrans are mutually exclusive");
869 if (flag_ltrans)
871 flag_generate_lto = 0;
873 /* During LTRANS, we are not looking at the whole program, only
874 a subset of the whole callgraph. */
875 flag_whole_program = 0;
878 if (flag_wpa)
879 flag_generate_lto = 1;
881 /* Initialize the codegen flags according to the output type. */
882 switch (flag_lto_linker_output)
884 case LTO_LINKER_OUTPUT_REL: /* .o: incremental link producing LTO IL */
885 /* Configure compiler same way as normal frontend would do with -flto:
886 this way we read the trees (declarations & types), symbol table,
887 optimization summaries and link them. Subsequently we output new LTO
888 file. */
889 flag_lto = "";
890 flag_incremental_link = INCREMENTAL_LINK_LTO;
891 flag_whole_program = 0;
892 flag_wpa = 0;
893 flag_generate_lto = 1;
894 /* It would be cool to produce .o file directly, but our current
895 simple objects does not contain the lto symbol markers. Go the slow
896 way through the asm file. */
897 lang_hooks.lto.begin_section = lhd_begin_section;
898 lang_hooks.lto.append_data = lhd_append_data;
899 lang_hooks.lto.end_section = lhd_end_section;
900 if (flag_ltrans)
901 error ("-flinker-output=rel and -fltrans are mutually exclussive");
902 break;
904 case LTO_LINKER_OUTPUT_NOLTOREL: /* .o: incremental link producing asm */
905 flag_whole_program = 0;
906 flag_incremental_link = INCREMENTAL_LINK_NOLTO;
907 break;
909 case LTO_LINKER_OUTPUT_DYN: /* .so: PID library */
910 /* On some targets, like i386 it makes sense to build PIC library wihout
911 -fpic for performance reasons. So no need to adjust flags. */
912 break;
914 case LTO_LINKER_OUTPUT_PIE: /* PIE binary */
915 /* If -fPIC or -fPIE was used at compile time, be sure that
916 flag_pie is 2. */
917 flag_pie = MAX (flag_pie, flag_pic);
918 flag_pic = flag_pie;
919 flag_shlib = 0;
920 break;
922 case LTO_LINKER_OUTPUT_EXEC: /* Normal executable */
923 flag_pic = 0;
924 flag_pie = 0;
925 flag_shlib = 0;
926 break;
928 case LTO_LINKER_OUTPUT_UNKNOWN:
929 break;
932 /* Excess precision other than "fast" requires front-end
933 support. */
934 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
936 /* When partitioning, we can tear appart STRING_CSTs uses from the same
937 TU into multiple partitions. Without constant merging the constants
938 might not be equal at runtime. See PR50199. */
939 if (!flag_merge_constants)
940 flag_merge_constants = 1;
942 /* Initialize the compiler back end. */
943 return false;
946 /* Return a data type that has machine mode MODE.
947 If the mode is an integer,
948 then UNSIGNEDP selects between signed and unsigned types.
949 If the mode is a fixed-point mode,
950 then UNSIGNEDP selects between saturating and nonsaturating types. */
952 static tree
953 lto_type_for_mode (machine_mode mode, int unsigned_p)
955 tree t;
956 int i;
958 if (mode == TYPE_MODE (integer_type_node))
959 return unsigned_p ? unsigned_type_node : integer_type_node;
961 if (mode == TYPE_MODE (signed_char_type_node))
962 return unsigned_p ? unsigned_char_type_node : signed_char_type_node;
964 if (mode == TYPE_MODE (short_integer_type_node))
965 return unsigned_p ? short_unsigned_type_node : short_integer_type_node;
967 if (mode == TYPE_MODE (long_integer_type_node))
968 return unsigned_p ? long_unsigned_type_node : long_integer_type_node;
970 if (mode == TYPE_MODE (long_long_integer_type_node))
971 return unsigned_p ? long_long_unsigned_type_node : long_long_integer_type_node;
973 for (i = 0; i < NUM_INT_N_ENTS; i ++)
974 if (int_n_enabled_p[i]
975 && mode == int_n_data[i].m)
976 return (unsigned_p ? int_n_trees[i].unsigned_type
977 : int_n_trees[i].signed_type);
979 if (mode == QImode)
980 return unsigned_p ? unsigned_intQI_type_node : intQI_type_node;
982 if (mode == HImode)
983 return unsigned_p ? unsigned_intHI_type_node : intHI_type_node;
985 if (mode == SImode)
986 return unsigned_p ? unsigned_intSI_type_node : intSI_type_node;
988 if (mode == DImode)
989 return unsigned_p ? unsigned_intDI_type_node : intDI_type_node;
991 #if HOST_BITS_PER_WIDE_INT >= 64
992 if (mode == TYPE_MODE (intTI_type_node))
993 return unsigned_p ? unsigned_intTI_type_node : intTI_type_node;
994 #endif
996 if (mode == TYPE_MODE (float_type_node))
997 return float_type_node;
999 if (mode == TYPE_MODE (double_type_node))
1000 return double_type_node;
1002 if (mode == TYPE_MODE (long_double_type_node))
1003 return long_double_type_node;
1005 if (mode == TYPE_MODE (void_type_node))
1006 return void_type_node;
1008 if (mode == TYPE_MODE (build_pointer_type (char_type_node))
1009 || mode == TYPE_MODE (build_pointer_type (integer_type_node)))
1011 unsigned int precision
1012 = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode));
1013 return (unsigned_p
1014 ? make_unsigned_type (precision)
1015 : make_signed_type (precision));
1018 if (COMPLEX_MODE_P (mode))
1020 machine_mode inner_mode;
1021 tree inner_type;
1023 if (mode == TYPE_MODE (complex_float_type_node))
1024 return complex_float_type_node;
1025 if (mode == TYPE_MODE (complex_double_type_node))
1026 return complex_double_type_node;
1027 if (mode == TYPE_MODE (complex_long_double_type_node))
1028 return complex_long_double_type_node;
1030 if (mode == TYPE_MODE (complex_integer_type_node) && !unsigned_p)
1031 return complex_integer_type_node;
1033 inner_mode = GET_MODE_INNER (mode);
1034 inner_type = lto_type_for_mode (inner_mode, unsigned_p);
1035 if (inner_type != NULL_TREE)
1036 return build_complex_type (inner_type);
1038 else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
1039 && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
1041 unsigned int elem_bits = vector_element_size (GET_MODE_BITSIZE (mode),
1042 GET_MODE_NUNITS (mode));
1043 tree bool_type = build_nonstandard_boolean_type (elem_bits);
1044 return build_vector_type_for_mode (bool_type, mode);
1046 else if (VECTOR_MODE_P (mode)
1047 && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
1049 machine_mode inner_mode = GET_MODE_INNER (mode);
1050 tree inner_type = lto_type_for_mode (inner_mode, unsigned_p);
1051 if (inner_type != NULL_TREE)
1052 return build_vector_type_for_mode (inner_type, mode);
1055 if (mode == TYPE_MODE (dfloat32_type_node))
1056 return dfloat32_type_node;
1057 if (mode == TYPE_MODE (dfloat64_type_node))
1058 return dfloat64_type_node;
1059 if (mode == TYPE_MODE (dfloat128_type_node))
1060 return dfloat128_type_node;
1062 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
1064 if (mode == TYPE_MODE (short_fract_type_node))
1065 return unsigned_p ? sat_short_fract_type_node : short_fract_type_node;
1066 if (mode == TYPE_MODE (fract_type_node))
1067 return unsigned_p ? sat_fract_type_node : fract_type_node;
1068 if (mode == TYPE_MODE (long_fract_type_node))
1069 return unsigned_p ? sat_long_fract_type_node : long_fract_type_node;
1070 if (mode == TYPE_MODE (long_long_fract_type_node))
1071 return unsigned_p ? sat_long_long_fract_type_node
1072 : long_long_fract_type_node;
1074 if (mode == TYPE_MODE (unsigned_short_fract_type_node))
1075 return unsigned_p ? sat_unsigned_short_fract_type_node
1076 : unsigned_short_fract_type_node;
1077 if (mode == TYPE_MODE (unsigned_fract_type_node))
1078 return unsigned_p ? sat_unsigned_fract_type_node
1079 : unsigned_fract_type_node;
1080 if (mode == TYPE_MODE (unsigned_long_fract_type_node))
1081 return unsigned_p ? sat_unsigned_long_fract_type_node
1082 : unsigned_long_fract_type_node;
1083 if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
1084 return unsigned_p ? sat_unsigned_long_long_fract_type_node
1085 : unsigned_long_long_fract_type_node;
1087 if (mode == TYPE_MODE (short_accum_type_node))
1088 return unsigned_p ? sat_short_accum_type_node : short_accum_type_node;
1089 if (mode == TYPE_MODE (accum_type_node))
1090 return unsigned_p ? sat_accum_type_node : accum_type_node;
1091 if (mode == TYPE_MODE (long_accum_type_node))
1092 return unsigned_p ? sat_long_accum_type_node : long_accum_type_node;
1093 if (mode == TYPE_MODE (long_long_accum_type_node))
1094 return unsigned_p ? sat_long_long_accum_type_node
1095 : long_long_accum_type_node;
1097 if (mode == TYPE_MODE (unsigned_short_accum_type_node))
1098 return unsigned_p ? sat_unsigned_short_accum_type_node
1099 : unsigned_short_accum_type_node;
1100 if (mode == TYPE_MODE (unsigned_accum_type_node))
1101 return unsigned_p ? sat_unsigned_accum_type_node
1102 : unsigned_accum_type_node;
1103 if (mode == TYPE_MODE (unsigned_long_accum_type_node))
1104 return unsigned_p ? sat_unsigned_long_accum_type_node
1105 : unsigned_long_accum_type_node;
1106 if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
1107 return unsigned_p ? sat_unsigned_long_long_accum_type_node
1108 : unsigned_long_long_accum_type_node;
1110 if (mode == QQmode)
1111 return unsigned_p ? sat_qq_type_node : qq_type_node;
1112 if (mode == HQmode)
1113 return unsigned_p ? sat_hq_type_node : hq_type_node;
1114 if (mode == SQmode)
1115 return unsigned_p ? sat_sq_type_node : sq_type_node;
1116 if (mode == DQmode)
1117 return unsigned_p ? sat_dq_type_node : dq_type_node;
1118 if (mode == TQmode)
1119 return unsigned_p ? sat_tq_type_node : tq_type_node;
1121 if (mode == UQQmode)
1122 return unsigned_p ? sat_uqq_type_node : uqq_type_node;
1123 if (mode == UHQmode)
1124 return unsigned_p ? sat_uhq_type_node : uhq_type_node;
1125 if (mode == USQmode)
1126 return unsigned_p ? sat_usq_type_node : usq_type_node;
1127 if (mode == UDQmode)
1128 return unsigned_p ? sat_udq_type_node : udq_type_node;
1129 if (mode == UTQmode)
1130 return unsigned_p ? sat_utq_type_node : utq_type_node;
1132 if (mode == HAmode)
1133 return unsigned_p ? sat_ha_type_node : ha_type_node;
1134 if (mode == SAmode)
1135 return unsigned_p ? sat_sa_type_node : sa_type_node;
1136 if (mode == DAmode)
1137 return unsigned_p ? sat_da_type_node : da_type_node;
1138 if (mode == TAmode)
1139 return unsigned_p ? sat_ta_type_node : ta_type_node;
1141 if (mode == UHAmode)
1142 return unsigned_p ? sat_uha_type_node : uha_type_node;
1143 if (mode == USAmode)
1144 return unsigned_p ? sat_usa_type_node : usa_type_node;
1145 if (mode == UDAmode)
1146 return unsigned_p ? sat_uda_type_node : uda_type_node;
1147 if (mode == UTAmode)
1148 return unsigned_p ? sat_uta_type_node : uta_type_node;
1151 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
1152 if (TYPE_MODE (TREE_VALUE (t)) == mode)
1153 return TREE_VALUE (t);
1155 return NULL_TREE;
1158 /* Return true if we are in the global binding level. */
1160 static bool
1161 lto_global_bindings_p (void)
1163 return cfun == NULL;
1166 static void
1167 lto_set_decl_assembler_name (tree decl)
1169 /* This is almost the same as lhd_set_decl_assembler_name, except that
1170 we need to uniquify file-scope names, even if they are not
1171 TREE_PUBLIC, to avoid conflicts between individual files. */
1172 tree id;
1174 if (TREE_PUBLIC (decl))
1175 id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
1176 else
1178 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1179 char *label;
1181 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
1182 id = get_identifier (label);
1185 SET_DECL_ASSEMBLER_NAME (decl, id);
1188 static tree
1189 lto_pushdecl (tree t ATTRIBUTE_UNUSED)
1191 /* Do nothing, since we get all information from DWARF and LTO
1192 sections. */
1193 return NULL_TREE;
1196 static tree
1197 lto_getdecls (void)
1199 /* We have our own write_globals langhook, hence the getdecls
1200 langhook shouldn't be used, except by dbxout.c, so we can't
1201 just abort here. */
1202 return NULL_TREE;
1205 static tree
1206 lto_builtin_function (tree decl)
1208 return decl;
1211 static void
1212 lto_register_builtin_type (tree type, const char *name)
1214 tree decl;
1216 if (!TYPE_NAME (type))
1218 decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
1219 get_identifier (name), type);
1220 DECL_ARTIFICIAL (decl) = 1;
1221 TYPE_NAME (type) = decl;
1224 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
1227 /* Build nodes that would have be created by the C front-end; necessary
1228 for including builtin-types.def and ultimately builtins.def. */
1230 static void
1231 lto_build_c_type_nodes (void)
1233 gcc_assert (void_type_node);
1235 void_list_node = build_tree_list (NULL_TREE, void_type_node);
1236 string_type_node = build_pointer_type (char_type_node);
1237 const_string_type_node
1238 = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
1240 if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1242 intmax_type_node = integer_type_node;
1243 uintmax_type_node = unsigned_type_node;
1244 signed_size_type_node = integer_type_node;
1246 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1248 intmax_type_node = long_integer_type_node;
1249 uintmax_type_node = long_unsigned_type_node;
1250 signed_size_type_node = long_integer_type_node;
1252 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1254 intmax_type_node = long_long_integer_type_node;
1255 uintmax_type_node = long_long_unsigned_type_node;
1256 signed_size_type_node = long_long_integer_type_node;
1258 else
1260 int i;
1262 signed_size_type_node = NULL_TREE;
1263 for (i = 0; i < NUM_INT_N_ENTS; i++)
1264 if (int_n_enabled_p[i])
1266 char name[50];
1267 sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
1269 if (strcmp (name, SIZE_TYPE) == 0)
1271 intmax_type_node = int_n_trees[i].signed_type;
1272 uintmax_type_node = int_n_trees[i].unsigned_type;
1273 signed_size_type_node = int_n_trees[i].signed_type;
1276 if (signed_size_type_node == NULL_TREE)
1277 gcc_unreachable ();
1280 wint_type_node = unsigned_type_node;
1281 pid_type_node = integer_type_node;
1284 /* Perform LTO-specific initialization. */
1286 static bool
1287 lto_init (void)
1289 int i;
1291 /* Initialize LTO-specific data structures. */
1292 in_lto_p = true;
1294 /* We need to generate LTO if running in WPA mode. */
1295 flag_generate_lto = (flag_incremental_link == INCREMENTAL_LINK_LTO
1296 || flag_wpa != NULL);
1298 /* Create the basic integer types. */
1299 build_common_tree_nodes (flag_signed_char);
1301 /* The global tree for the main identifier is filled in by
1302 language-specific front-end initialization that is not run in the
1303 LTO back-end. It appears that all languages that perform such
1304 initialization currently do so in the same way, so we do it here. */
1305 if (main_identifier_node == NULL_TREE)
1306 main_identifier_node = get_identifier ("main");
1308 /* In the C++ front-end, fileptr_type_node is defined as a variant
1309 copy of ptr_type_node, rather than ptr_node itself. The
1310 distinction should only be relevant to the front-end, so we
1311 always use the C definition here in lto1.
1312 Likewise for const struct tm*. */
1313 for (unsigned i = 0;
1314 i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
1315 ++i)
1317 gcc_assert (builtin_structptr_types[i].node
1318 == builtin_structptr_types[i].base);
1319 gcc_assert (TYPE_MAIN_VARIANT (builtin_structptr_types[i].node)
1320 == builtin_structptr_types[i].base);
1323 lto_build_c_type_nodes ();
1324 gcc_assert (va_list_type_node);
1326 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1328 tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
1329 lto_define_builtins (x, x);
1331 else
1333 lto_define_builtins (build_reference_type (va_list_type_node),
1334 va_list_type_node);
1337 targetm.init_builtins ();
1338 build_common_builtin_nodes ();
1340 /* Assign names to the builtin types, otherwise they'll end up
1341 as __unknown__ in debug info.
1342 ??? We simply need to stop pre-seeding the streamer cache.
1343 Below is modeled after from c-common.c:c_common_nodes_and_builtins */
1344 #define NAME_TYPE(t,n) \
1345 if (t) \
1346 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \
1347 get_identifier (n), t)
1348 NAME_TYPE (integer_type_node, "int");
1349 NAME_TYPE (char_type_node, "char");
1350 NAME_TYPE (long_integer_type_node, "long int");
1351 NAME_TYPE (unsigned_type_node, "unsigned int");
1352 NAME_TYPE (long_unsigned_type_node, "long unsigned int");
1353 NAME_TYPE (long_long_integer_type_node, "long long int");
1354 NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int");
1355 NAME_TYPE (short_integer_type_node, "short int");
1356 NAME_TYPE (short_unsigned_type_node, "short unsigned int");
1357 if (signed_char_type_node != char_type_node)
1358 NAME_TYPE (signed_char_type_node, "signed char");
1359 if (unsigned_char_type_node != char_type_node)
1360 NAME_TYPE (unsigned_char_type_node, "unsigned char");
1361 NAME_TYPE (float_type_node, "float");
1362 NAME_TYPE (double_type_node, "double");
1363 NAME_TYPE (long_double_type_node, "long double");
1364 NAME_TYPE (void_type_node, "void");
1365 NAME_TYPE (boolean_type_node, "bool");
1366 NAME_TYPE (complex_float_type_node, "complex float");
1367 NAME_TYPE (complex_double_type_node, "complex double");
1368 NAME_TYPE (complex_long_double_type_node, "complex long double");
1369 for (i = 0; i < NUM_INT_N_ENTS; i++)
1370 if (int_n_enabled_p[i])
1372 char name[50];
1373 sprintf (name, "__int%d", int_n_data[i].bitsize);
1374 NAME_TYPE (int_n_trees[i].signed_type, name);
1376 #undef NAME_TYPE
1378 return true;
1381 /* Register c++-specific dumps. */
1383 void
1384 lto_register_dumps (gcc::dump_manager *dumps)
1386 lto_link_dump_id = dumps->dump_register
1387 (".lto-link", "ipa-lto-link", "ipa-lto-link",
1388 DK_ipa, OPTGROUP_NONE, false);
1389 decl_merge_dump_id = dumps->dump_register
1390 (".lto-decl-merge", "ipa-lto-decl-merge", "ipa-lto-decl-merge",
1391 DK_ipa, OPTGROUP_NONE, false);
1392 partition_dump_id = dumps->dump_register
1393 (".lto-partition", "ipa-lto-partition", "ipa-lto-partition",
1394 DK_ipa, OPTGROUP_NONE, false);
1398 /* Initialize tree structures required by the LTO front end. */
1400 static void lto_init_ts (void)
1402 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1405 #undef LANG_HOOKS_NAME
1406 #define LANG_HOOKS_NAME "GNU GIMPLE"
1407 #undef LANG_HOOKS_OPTION_LANG_MASK
1408 #define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
1409 #undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
1410 #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
1411 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1412 #define LANG_HOOKS_INIT_OPTIONS_STRUCT lto_init_options_struct
1413 #undef LANG_HOOKS_REGISTER_DUMPS
1414 #define LANG_HOOKS_REGISTER_DUMPS lto_register_dumps
1415 #undef LANG_HOOKS_HANDLE_OPTION
1416 #define LANG_HOOKS_HANDLE_OPTION lto_handle_option
1417 #undef LANG_HOOKS_POST_OPTIONS
1418 #define LANG_HOOKS_POST_OPTIONS lto_post_options
1419 #undef LANG_HOOKS_GET_ALIAS_SET
1420 #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
1421 #undef LANG_HOOKS_TYPE_FOR_MODE
1422 #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
1423 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
1424 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
1425 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1426 #define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
1427 #undef LANG_HOOKS_PUSHDECL
1428 #define LANG_HOOKS_PUSHDECL lto_pushdecl
1429 #undef LANG_HOOKS_GETDECLS
1430 #define LANG_HOOKS_GETDECLS lto_getdecls
1431 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1432 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
1433 #undef LANG_HOOKS_BUILTIN_FUNCTION
1434 #define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
1435 #undef LANG_HOOKS_INIT
1436 #define LANG_HOOKS_INIT lto_init
1437 #undef LANG_HOOKS_PARSE_FILE
1438 #define LANG_HOOKS_PARSE_FILE lto_main
1439 #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
1440 #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
1441 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1442 #define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
1443 #undef LANG_HOOKS_EH_PERSONALITY
1444 #define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
1446 /* Attribute hooks. */
1447 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1448 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
1449 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
1450 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
1452 #undef LANG_HOOKS_BEGIN_SECTION
1453 #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
1454 #undef LANG_HOOKS_APPEND_DATA
1455 #define LANG_HOOKS_APPEND_DATA lto_obj_append_data
1456 #undef LANG_HOOKS_END_SECTION
1457 #define LANG_HOOKS_END_SECTION lto_obj_end_section
1459 #undef LANG_HOOKS_INIT_TS
1460 #define LANG_HOOKS_INIT_TS lto_init_ts
1462 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1464 /* Language hooks that are not part of lang_hooks. */
1466 tree
1467 convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1469 gcc_unreachable ();
1472 /* Tree walking support. */
1474 static enum lto_tree_node_structure_enum
1475 lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
1477 return TS_LTO_GENERIC;
1480 #include "gtype-lto.h"
1481 #include "gt-lto-lto-lang.h"