2017-09-26 Thomas Koenig <tkoenig@gcc.gnu.org>
[official-gcc.git] / gcc / lto / lto-lang.c
blobeaf793383f7718f7ac5178f5ad09735ecb6da60d
1 /* Language-dependent hooks for LTO.
2 Copyright (C) 2009-2017 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 "cilk.h"
38 #include "stringpool.h"
39 #include "attribs.h"
41 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
42 static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
43 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
44 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
45 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
46 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
47 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
48 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
49 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
50 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
51 static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool *);
52 static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
53 static tree handle_patchable_function_entry_attribute (tree *, tree, tree,
54 int, bool *);
55 static tree ignore_attribute (tree *, tree, tree, int, bool *);
57 static tree handle_format_attribute (tree *, tree, tree, int, bool *);
58 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
59 static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
61 /* Table of machine-independent attributes supported in GIMPLE. */
62 const struct attribute_spec lto_attribute_table[] =
64 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
65 do_diagnostic } */
66 { "noreturn", 0, 0, true, false, false,
67 handle_noreturn_attribute, false },
68 { "leaf", 0, 0, true, false, false,
69 handle_leaf_attribute, false },
70 /* The same comments as for noreturn attributes apply to const ones. */
71 { "const", 0, 0, true, false, false,
72 handle_const_attribute, false },
73 { "malloc", 0, 0, true, false, false,
74 handle_malloc_attribute, false },
75 { "pure", 0, 0, true, false, false,
76 handle_pure_attribute, false },
77 { "no vops", 0, 0, true, false, false,
78 handle_novops_attribute, false },
79 { "nonnull", 0, -1, false, true, true,
80 handle_nonnull_attribute, false },
81 { "nothrow", 0, 0, true, false, false,
82 handle_nothrow_attribute, false },
83 { "patchable_function_entry", 1, 2, true, false, false,
84 handle_patchable_function_entry_attribute,
85 false },
86 { "returns_twice", 0, 0, true, false, false,
87 handle_returns_twice_attribute, false },
88 { "sentinel", 0, 1, false, true, true,
89 handle_sentinel_attribute, false },
90 { "type generic", 0, 0, false, true, true,
91 handle_type_generic_attribute, false },
92 { "fn spec", 1, 1, false, true, true,
93 handle_fnspec_attribute, false },
94 { "transaction_pure", 0, 0, false, true, true,
95 handle_transaction_pure_attribute, false },
96 /* For internal use only. The leading '*' both prevents its usage in
97 source code and signals that it may be overridden by machine tables. */
98 { "*tm regparm", 0, 0, false, true, true,
99 ignore_attribute, false },
100 { NULL, 0, 0, false, false, false, NULL, false }
103 /* Give the specifications for the format attributes, used by C and all
104 descendants. */
106 const struct attribute_spec lto_format_attribute_table[] =
108 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
109 affects_type_identity } */
110 { "format", 3, 3, false, true, true,
111 handle_format_attribute, false },
112 { "format_arg", 1, 1, false, true, true,
113 handle_format_arg_attribute, false },
114 { NULL, 0, 0, false, false, false, NULL, false }
117 enum built_in_attribute
119 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
120 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
121 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
122 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
123 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
124 #include "builtin-attrs.def"
125 #undef DEF_ATTR_NULL_TREE
126 #undef DEF_ATTR_INT
127 #undef DEF_ATTR_STRING
128 #undef DEF_ATTR_IDENT
129 #undef DEF_ATTR_TREE_LIST
130 ATTR_LAST
133 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
135 /* Builtin types. */
137 enum lto_builtin_type
139 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
140 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
141 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
142 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
143 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
144 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
145 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
146 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
147 ARG6) NAME,
148 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
149 ARG6, ARG7) NAME,
150 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
151 ARG6, ARG7, ARG8) NAME,
152 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
153 ARG6, ARG7, ARG8, ARG9) NAME,
154 #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
155 ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
156 #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
157 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
158 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
159 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
160 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
161 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
162 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
163 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
164 NAME,
165 #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
166 ARG6) NAME,
167 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
168 ARG6, ARG7) NAME,
169 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
170 #include "builtin-types.def"
171 #undef DEF_PRIMITIVE_TYPE
172 #undef DEF_FUNCTION_TYPE_0
173 #undef DEF_FUNCTION_TYPE_1
174 #undef DEF_FUNCTION_TYPE_2
175 #undef DEF_FUNCTION_TYPE_3
176 #undef DEF_FUNCTION_TYPE_4
177 #undef DEF_FUNCTION_TYPE_5
178 #undef DEF_FUNCTION_TYPE_6
179 #undef DEF_FUNCTION_TYPE_7
180 #undef DEF_FUNCTION_TYPE_8
181 #undef DEF_FUNCTION_TYPE_9
182 #undef DEF_FUNCTION_TYPE_10
183 #undef DEF_FUNCTION_TYPE_11
184 #undef DEF_FUNCTION_TYPE_VAR_0
185 #undef DEF_FUNCTION_TYPE_VAR_1
186 #undef DEF_FUNCTION_TYPE_VAR_2
187 #undef DEF_FUNCTION_TYPE_VAR_3
188 #undef DEF_FUNCTION_TYPE_VAR_4
189 #undef DEF_FUNCTION_TYPE_VAR_5
190 #undef DEF_FUNCTION_TYPE_VAR_6
191 #undef DEF_FUNCTION_TYPE_VAR_7
192 #undef DEF_POINTER_TYPE
193 BT_LAST
196 typedef enum lto_builtin_type builtin_type;
198 static GTY(()) tree builtin_types[(int) BT_LAST + 1];
200 static GTY(()) tree string_type_node;
201 static GTY(()) tree const_string_type_node;
202 static GTY(()) tree wint_type_node;
203 static GTY(()) tree intmax_type_node;
204 static GTY(()) tree uintmax_type_node;
205 static GTY(()) tree signed_size_type_node;
207 /* Flags needed to process builtins.def. */
208 int flag_isoc94;
209 int flag_isoc99;
210 int flag_isoc11;
212 /* Attribute handlers. */
214 /* Handle a "noreturn" attribute; arguments as in
215 struct attribute_spec.handler. */
217 static tree
218 handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
219 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
220 bool * ARG_UNUSED (no_add_attrs))
222 tree type = TREE_TYPE (*node);
224 if (TREE_CODE (*node) == FUNCTION_DECL)
225 TREE_THIS_VOLATILE (*node) = 1;
226 else if (TREE_CODE (type) == POINTER_TYPE
227 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
228 TREE_TYPE (*node)
229 = build_pointer_type
230 (build_type_variant (TREE_TYPE (type),
231 TYPE_READONLY (TREE_TYPE (type)), 1));
232 else
233 gcc_unreachable ();
235 return NULL_TREE;
238 /* Handle a "leaf" attribute; arguments as in
239 struct attribute_spec.handler. */
241 static tree
242 handle_leaf_attribute (tree *node, tree name,
243 tree ARG_UNUSED (args),
244 int ARG_UNUSED (flags), bool *no_add_attrs)
246 if (TREE_CODE (*node) != FUNCTION_DECL)
248 warning (OPT_Wattributes, "%qE attribute ignored", name);
249 *no_add_attrs = true;
251 if (!TREE_PUBLIC (*node))
253 warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
254 *no_add_attrs = true;
257 return NULL_TREE;
260 /* Handle a "const" attribute; arguments as in
261 struct attribute_spec.handler. */
263 static tree
264 handle_const_attribute (tree *node, tree ARG_UNUSED (name),
265 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
266 bool * ARG_UNUSED (no_add_attrs))
268 tree type = TREE_TYPE (*node);
270 /* See FIXME comment on noreturn in c_common_attribute_table. */
271 if (TREE_CODE (*node) == FUNCTION_DECL)
272 TREE_READONLY (*node) = 1;
273 else if (TREE_CODE (type) == POINTER_TYPE
274 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
275 TREE_TYPE (*node)
276 = build_pointer_type
277 (build_type_variant (TREE_TYPE (type), 1,
278 TREE_THIS_VOLATILE (TREE_TYPE (type))));
279 else
280 gcc_unreachable ();
282 return NULL_TREE;
286 /* Handle a "malloc" attribute; arguments as in
287 struct attribute_spec.handler. */
289 static tree
290 handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
291 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
292 bool * ARG_UNUSED (no_add_attrs))
294 if (TREE_CODE (*node) == FUNCTION_DECL
295 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
296 DECL_IS_MALLOC (*node) = 1;
297 else
298 gcc_unreachable ();
300 return NULL_TREE;
304 /* Handle a "pure" attribute; arguments as in
305 struct attribute_spec.handler. */
307 static tree
308 handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
309 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
310 bool * ARG_UNUSED (no_add_attrs))
312 if (TREE_CODE (*node) == FUNCTION_DECL)
313 DECL_PURE_P (*node) = 1;
314 else
315 gcc_unreachable ();
317 return NULL_TREE;
321 /* Handle a "no vops" attribute; arguments as in
322 struct attribute_spec.handler. */
324 static tree
325 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
326 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
327 bool *ARG_UNUSED (no_add_attrs))
329 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
330 DECL_IS_NOVOPS (*node) = 1;
331 return NULL_TREE;
335 /* Helper for nonnull attribute handling; fetch the operand number
336 from the attribute argument list. */
338 static bool
339 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
341 /* Verify the arg number is a constant. */
342 if (!tree_fits_uhwi_p (arg_num_expr))
343 return false;
345 *valp = TREE_INT_CST_LOW (arg_num_expr);
346 return true;
349 /* Handle the "nonnull" attribute. */
351 static tree
352 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
353 tree args, int ARG_UNUSED (flags),
354 bool * ARG_UNUSED (no_add_attrs))
356 tree type = *node;
358 /* If no arguments are specified, all pointer arguments should be
359 non-null. Verify a full prototype is given so that the arguments
360 will have the correct types when we actually check them later.
361 Avoid diagnosing type-generic built-ins since those have no
362 prototype. */
363 if (!args)
365 gcc_assert (prototype_p (type)
366 || !TYPE_ATTRIBUTES (type)
367 || lookup_attribute ("type generic", TYPE_ATTRIBUTES (type)));
369 return NULL_TREE;
372 /* Argument list specified. Verify that each argument number references
373 a pointer argument. */
374 for (; args; args = TREE_CHAIN (args))
376 tree argument;
377 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
379 if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
380 gcc_unreachable ();
382 argument = TYPE_ARG_TYPES (type);
383 if (argument)
385 for (ck_num = 1; ; ck_num++)
387 if (!argument || ck_num == arg_num)
388 break;
389 argument = TREE_CHAIN (argument);
392 gcc_assert (argument
393 && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
397 return NULL_TREE;
401 /* Handle a "nothrow" attribute; arguments as in
402 struct attribute_spec.handler. */
404 static tree
405 handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
406 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
407 bool * ARG_UNUSED (no_add_attrs))
409 if (TREE_CODE (*node) == FUNCTION_DECL)
410 TREE_NOTHROW (*node) = 1;
411 else
412 gcc_unreachable ();
414 return NULL_TREE;
418 /* Handle a "sentinel" attribute. */
420 static tree
421 handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
422 int ARG_UNUSED (flags),
423 bool * ARG_UNUSED (no_add_attrs))
425 gcc_assert (stdarg_p (*node));
427 if (args)
429 tree position = TREE_VALUE (args);
430 gcc_assert (TREE_CODE (position) == INTEGER_CST);
431 if (tree_int_cst_lt (position, integer_zero_node))
432 gcc_unreachable ();
435 return NULL_TREE;
438 /* Handle a "type_generic" attribute. */
440 static tree
441 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
442 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
443 bool * ARG_UNUSED (no_add_attrs))
445 /* Ensure we have a function type. */
446 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
448 /* Ensure we have a variadic function. */
449 gcc_assert (!prototype_p (*node) || stdarg_p (*node));
451 return NULL_TREE;
454 /* Handle a "transaction_pure" attribute. */
456 static tree
457 handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
458 tree ARG_UNUSED (args),
459 int ARG_UNUSED (flags),
460 bool * ARG_UNUSED (no_add_attrs))
462 /* Ensure we have a function type. */
463 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
465 return NULL_TREE;
468 /* Handle a "returns_twice" attribute. */
470 static tree
471 handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name),
472 tree ARG_UNUSED (args),
473 int ARG_UNUSED (flags),
474 bool * ARG_UNUSED (no_add_attrs))
476 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
478 DECL_IS_RETURNS_TWICE (*node) = 1;
480 return NULL_TREE;
483 static tree
484 handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
486 /* Nothing to be done here. */
487 return NULL_TREE;
490 /* Ignore the given attribute. Used when this attribute may be usefully
491 overridden by the target, but is not used generically. */
493 static tree
494 ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
495 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
496 bool *no_add_attrs)
498 *no_add_attrs = true;
499 return NULL_TREE;
502 /* Handle a "format" attribute; arguments as in
503 struct attribute_spec.handler. */
505 static tree
506 handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
507 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
508 bool *no_add_attrs)
510 *no_add_attrs = true;
511 return NULL_TREE;
515 /* Handle a "format_arg" attribute; arguments as in
516 struct attribute_spec.handler. */
518 tree
519 handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
520 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
521 bool *no_add_attrs)
523 *no_add_attrs = true;
524 return NULL_TREE;
528 /* Handle a "fn spec" attribute; arguments as in
529 struct attribute_spec.handler. */
531 static tree
532 handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
533 tree args, int ARG_UNUSED (flags),
534 bool *no_add_attrs ATTRIBUTE_UNUSED)
536 gcc_assert (args
537 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
538 && !TREE_CHAIN (args));
539 return NULL_TREE;
542 /* Cribbed from c-common.c. */
544 static void
545 def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
547 tree t;
548 tree *args = XALLOCAVEC (tree, n);
549 va_list list;
550 int i;
551 bool err = false;
553 va_start (list, n);
554 for (i = 0; i < n; ++i)
556 builtin_type a = (builtin_type) va_arg (list, int);
557 t = builtin_types[a];
558 if (t == error_mark_node)
559 err = true;
560 args[i] = t;
562 va_end (list);
564 t = builtin_types[ret];
565 if (err)
566 t = error_mark_node;
567 if (t == error_mark_node)
569 else if (var)
570 t = build_varargs_function_type_array (t, n, args);
571 else
572 t = build_function_type_array (t, n, args);
574 builtin_types[def] = t;
577 /* Used to help initialize the builtin-types.def table. When a type of
578 the correct size doesn't exist, use error_mark_node instead of NULL.
579 The later results in segfaults even when a decl using the type doesn't
580 get invoked. */
582 static tree
583 builtin_type_for_size (int size, bool unsignedp)
585 tree type = lang_hooks.types.type_for_size (size, unsignedp);
586 return type ? type : error_mark_node;
589 /* Support for DEF_BUILTIN. */
591 static void
592 def_builtin_1 (enum built_in_function fncode, const char *name,
593 enum built_in_class fnclass, tree fntype, tree libtype,
594 bool both_p, bool fallback_p, bool nonansi_p,
595 tree fnattrs, bool implicit_p)
597 tree decl;
598 const char *libname;
600 if (fntype == error_mark_node)
601 return;
603 libname = name + strlen ("__builtin_");
604 decl = add_builtin_function (name, fntype, fncode, fnclass,
605 (fallback_p ? libname : NULL),
606 fnattrs);
608 if (both_p
609 && !flag_no_builtin
610 && !(nonansi_p && flag_no_nonansi_builtin))
611 add_builtin_function (libname, libtype, fncode, fnclass,
612 NULL, fnattrs);
614 set_builtin_decl (fncode, decl, implicit_p);
618 /* Initialize the attribute table for all the supported builtins. */
620 static void
621 lto_init_attributes (void)
623 /* Fill in the built_in_attributes array. */
624 #define DEF_ATTR_NULL_TREE(ENUM) \
625 built_in_attributes[(int) ENUM] = NULL_TREE;
626 #define DEF_ATTR_INT(ENUM, VALUE) \
627 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
628 #define DEF_ATTR_STRING(ENUM, VALUE) \
629 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
630 #define DEF_ATTR_IDENT(ENUM, STRING) \
631 built_in_attributes[(int) ENUM] = get_identifier (STRING);
632 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
633 built_in_attributes[(int) ENUM] \
634 = tree_cons (built_in_attributes[(int) PURPOSE], \
635 built_in_attributes[(int) VALUE], \
636 built_in_attributes[(int) CHAIN]);
637 #include "builtin-attrs.def"
638 #undef DEF_ATTR_NULL_TREE
639 #undef DEF_ATTR_INT
640 #undef DEF_ATTR_STRING
641 #undef DEF_ATTR_IDENT
642 #undef DEF_ATTR_TREE_LIST
645 /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
646 VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
648 static void
649 lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
650 tree va_list_arg_type_node ATTRIBUTE_UNUSED)
652 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
653 builtin_types[ENUM] = VALUE;
654 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
655 def_fn_type (ENUM, RETURN, 0, 0);
656 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
657 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
658 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
659 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
660 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
661 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
662 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
663 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
664 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
665 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
666 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
667 ARG6) \
668 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
669 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
670 ARG6, ARG7) \
671 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
672 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
673 ARG6, ARG7, ARG8) \
674 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
675 ARG7, ARG8);
676 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
677 ARG6, ARG7, ARG8, ARG9) \
678 def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
679 ARG7, ARG8, ARG9);
680 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
681 ARG6, ARG7, ARG8, ARG9, ARG10) \
682 def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
683 ARG7, ARG8, ARG9, ARG10);
684 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
685 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
686 def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
687 ARG7, ARG8, ARG9, ARG10, ARG11);
688 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
689 def_fn_type (ENUM, RETURN, 1, 0);
690 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
691 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
692 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
693 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
694 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
695 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
696 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
697 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
698 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
699 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
700 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
701 ARG6) \
702 def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
703 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
704 ARG6, ARG7) \
705 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
706 #define DEF_POINTER_TYPE(ENUM, TYPE) \
707 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
709 #include "builtin-types.def"
711 #undef DEF_PRIMITIVE_TYPE
712 #undef DEF_FUNCTION_TYPE_0
713 #undef DEF_FUNCTION_TYPE_1
714 #undef DEF_FUNCTION_TYPE_2
715 #undef DEF_FUNCTION_TYPE_3
716 #undef DEF_FUNCTION_TYPE_4
717 #undef DEF_FUNCTION_TYPE_5
718 #undef DEF_FUNCTION_TYPE_6
719 #undef DEF_FUNCTION_TYPE_7
720 #undef DEF_FUNCTION_TYPE_8
721 #undef DEF_FUNCTION_TYPE_9
722 #undef DEF_FUNCTION_TYPE_10
723 #undef DEF_FUNCTION_TYPE_11
724 #undef DEF_FUNCTION_TYPE_VAR_0
725 #undef DEF_FUNCTION_TYPE_VAR_1
726 #undef DEF_FUNCTION_TYPE_VAR_2
727 #undef DEF_FUNCTION_TYPE_VAR_3
728 #undef DEF_FUNCTION_TYPE_VAR_4
729 #undef DEF_FUNCTION_TYPE_VAR_5
730 #undef DEF_FUNCTION_TYPE_VAR_6
731 #undef DEF_FUNCTION_TYPE_VAR_7
732 #undef DEF_POINTER_TYPE
733 builtin_types[(int) BT_LAST] = NULL_TREE;
735 lto_init_attributes ();
737 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
738 NONANSI_P, ATTRS, IMPLICIT, COND) \
739 if (NAME && COND) \
740 def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
741 builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
742 NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
743 #include "builtins.def"
746 static GTY(()) tree registered_builtin_types;
748 /* Language hooks. */
750 static unsigned int
751 lto_option_lang_mask (void)
753 return CL_LTO;
756 static bool
757 lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
759 /* The LTO front end inherits all the options from the first front
760 end that was used. However, not all the original front end
761 options make sense in LTO.
763 A real solution would be to filter this in collect2, but collect2
764 does not have access to all the option attributes to know what to
765 filter. So, in lto1 we silently accept inherited flags and do
766 nothing about it. */
767 return false;
770 static void
771 lto_init_options_struct (struct gcc_options *opts)
773 /* By default, C99-like requirements for complex multiply and divide.
774 ??? Until the complex method is encoded in the IL this is the only
775 safe choice. This will pessimize Fortran code with LTO unless
776 people specify a complex method manually or use -ffast-math. */
777 opts->x_flag_complex_method = 2;
780 /* Handle command-line option SCODE. If the option takes an argument, it is
781 stored in ARG, which is otherwise NULL. VALUE holds either a numerical
782 argument or a binary value indicating whether the positive or negative form
783 of the option was supplied. */
785 const char *resolution_file_name;
786 static bool
787 lto_handle_option (size_t scode, const char *arg,
788 int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
789 location_t loc ATTRIBUTE_UNUSED,
790 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
792 enum opt_code code = (enum opt_code) scode;
793 bool result = true;
795 switch (code)
797 case OPT_fresolution_:
798 resolution_file_name = arg;
799 break;
801 case OPT_Wabi:
802 warn_psabi = value;
803 break;
805 case OPT_fwpa:
806 flag_wpa = value ? "" : NULL;
807 break;
809 default:
810 break;
813 return result;
816 /* Perform post-option processing. Does additional initialization based on
817 command-line options. PFILENAME is the main input filename. Returns false
818 to enable subsequent back-end initialization. */
820 static bool
821 lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
823 /* -fltrans and -fwpa are mutually exclusive. Check for that here. */
824 if (flag_wpa && flag_ltrans)
825 error ("-fwpa and -fltrans are mutually exclusive");
827 if (flag_ltrans)
829 flag_generate_lto = 0;
831 /* During LTRANS, we are not looking at the whole program, only
832 a subset of the whole callgraph. */
833 flag_whole_program = 0;
836 if (flag_wpa)
837 flag_generate_lto = 1;
839 /* Initialize the codegen flags according to the output type. */
840 switch (flag_lto_linker_output)
842 case LTO_LINKER_OUTPUT_REL: /* .o: incremental link producing LTO IL */
843 flag_whole_program = 0;
844 flag_incremental_link = 1;
845 break;
847 case LTO_LINKER_OUTPUT_DYN: /* .so: PID library */
848 /* On some targets, like i386 it makes sense to build PIC library wihout
849 -fpic for performance reasons. So no need to adjust flags. */
850 break;
852 case LTO_LINKER_OUTPUT_PIE: /* PIE binary */
853 /* If -fPIC or -fPIE was used at compile time, be sure that
854 flag_pie is 2. */
855 flag_pie = MAX (flag_pie, flag_pic);
856 flag_pic = flag_pie;
857 break;
859 case LTO_LINKER_OUTPUT_EXEC: /* Normal executable */
860 flag_pic = 0;
861 flag_pie = 0;
862 break;
864 case LTO_LINKER_OUTPUT_UNKNOWN:
865 break;
868 /* Excess precision other than "fast" requires front-end
869 support. */
870 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
872 /* When partitioning, we can tear appart STRING_CSTs uses from the same
873 TU into multiple partitions. Without constant merging the constants
874 might not be equal at runtime. See PR50199. */
875 if (!flag_merge_constants)
876 flag_merge_constants = 1;
878 /* Initialize the compiler back end. */
879 return false;
882 /* Return a data type that has machine mode MODE.
883 If the mode is an integer,
884 then UNSIGNEDP selects between signed and unsigned types.
885 If the mode is a fixed-point mode,
886 then UNSIGNEDP selects between saturating and nonsaturating types. */
888 static tree
889 lto_type_for_mode (machine_mode mode, int unsigned_p)
891 tree t;
892 int i;
894 if (mode == TYPE_MODE (integer_type_node))
895 return unsigned_p ? unsigned_type_node : integer_type_node;
897 if (mode == TYPE_MODE (signed_char_type_node))
898 return unsigned_p ? unsigned_char_type_node : signed_char_type_node;
900 if (mode == TYPE_MODE (short_integer_type_node))
901 return unsigned_p ? short_unsigned_type_node : short_integer_type_node;
903 if (mode == TYPE_MODE (long_integer_type_node))
904 return unsigned_p ? long_unsigned_type_node : long_integer_type_node;
906 if (mode == TYPE_MODE (long_long_integer_type_node))
907 return unsigned_p ? long_long_unsigned_type_node : long_long_integer_type_node;
909 for (i = 0; i < NUM_INT_N_ENTS; i ++)
910 if (int_n_enabled_p[i]
911 && mode == int_n_data[i].m)
912 return (unsigned_p ? int_n_trees[i].unsigned_type
913 : int_n_trees[i].signed_type);
915 if (mode == QImode)
916 return unsigned_p ? unsigned_intQI_type_node : intQI_type_node;
918 if (mode == HImode)
919 return unsigned_p ? unsigned_intHI_type_node : intHI_type_node;
921 if (mode == SImode)
922 return unsigned_p ? unsigned_intSI_type_node : intSI_type_node;
924 if (mode == DImode)
925 return unsigned_p ? unsigned_intDI_type_node : intDI_type_node;
927 #if HOST_BITS_PER_WIDE_INT >= 64
928 if (mode == TYPE_MODE (intTI_type_node))
929 return unsigned_p ? unsigned_intTI_type_node : intTI_type_node;
930 #endif
932 if (mode == TYPE_MODE (float_type_node))
933 return float_type_node;
935 if (mode == TYPE_MODE (double_type_node))
936 return double_type_node;
938 if (mode == TYPE_MODE (long_double_type_node))
939 return long_double_type_node;
941 if (mode == TYPE_MODE (void_type_node))
942 return void_type_node;
944 if (mode == TYPE_MODE (build_pointer_type (char_type_node))
945 || mode == TYPE_MODE (build_pointer_type (integer_type_node)))
947 unsigned int precision
948 = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode));
949 return (unsigned_p
950 ? make_unsigned_type (precision)
951 : make_signed_type (precision));
954 if (COMPLEX_MODE_P (mode))
956 machine_mode inner_mode;
957 tree inner_type;
959 if (mode == TYPE_MODE (complex_float_type_node))
960 return complex_float_type_node;
961 if (mode == TYPE_MODE (complex_double_type_node))
962 return complex_double_type_node;
963 if (mode == TYPE_MODE (complex_long_double_type_node))
964 return complex_long_double_type_node;
966 if (mode == TYPE_MODE (complex_integer_type_node) && !unsigned_p)
967 return complex_integer_type_node;
969 inner_mode = GET_MODE_INNER (mode);
970 inner_type = lto_type_for_mode (inner_mode, unsigned_p);
971 if (inner_type != NULL_TREE)
972 return build_complex_type (inner_type);
974 else if (VECTOR_MODE_P (mode))
976 machine_mode inner_mode = GET_MODE_INNER (mode);
977 tree inner_type = lto_type_for_mode (inner_mode, unsigned_p);
978 if (inner_type != NULL_TREE)
979 return build_vector_type_for_mode (inner_type, mode);
982 if (mode == TYPE_MODE (dfloat32_type_node))
983 return dfloat32_type_node;
984 if (mode == TYPE_MODE (dfloat64_type_node))
985 return dfloat64_type_node;
986 if (mode == TYPE_MODE (dfloat128_type_node))
987 return dfloat128_type_node;
989 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
991 if (mode == TYPE_MODE (short_fract_type_node))
992 return unsigned_p ? sat_short_fract_type_node : short_fract_type_node;
993 if (mode == TYPE_MODE (fract_type_node))
994 return unsigned_p ? sat_fract_type_node : fract_type_node;
995 if (mode == TYPE_MODE (long_fract_type_node))
996 return unsigned_p ? sat_long_fract_type_node : long_fract_type_node;
997 if (mode == TYPE_MODE (long_long_fract_type_node))
998 return unsigned_p ? sat_long_long_fract_type_node
999 : long_long_fract_type_node;
1001 if (mode == TYPE_MODE (unsigned_short_fract_type_node))
1002 return unsigned_p ? sat_unsigned_short_fract_type_node
1003 : unsigned_short_fract_type_node;
1004 if (mode == TYPE_MODE (unsigned_fract_type_node))
1005 return unsigned_p ? sat_unsigned_fract_type_node
1006 : unsigned_fract_type_node;
1007 if (mode == TYPE_MODE (unsigned_long_fract_type_node))
1008 return unsigned_p ? sat_unsigned_long_fract_type_node
1009 : unsigned_long_fract_type_node;
1010 if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
1011 return unsigned_p ? sat_unsigned_long_long_fract_type_node
1012 : unsigned_long_long_fract_type_node;
1014 if (mode == TYPE_MODE (short_accum_type_node))
1015 return unsigned_p ? sat_short_accum_type_node : short_accum_type_node;
1016 if (mode == TYPE_MODE (accum_type_node))
1017 return unsigned_p ? sat_accum_type_node : accum_type_node;
1018 if (mode == TYPE_MODE (long_accum_type_node))
1019 return unsigned_p ? sat_long_accum_type_node : long_accum_type_node;
1020 if (mode == TYPE_MODE (long_long_accum_type_node))
1021 return unsigned_p ? sat_long_long_accum_type_node
1022 : long_long_accum_type_node;
1024 if (mode == TYPE_MODE (unsigned_short_accum_type_node))
1025 return unsigned_p ? sat_unsigned_short_accum_type_node
1026 : unsigned_short_accum_type_node;
1027 if (mode == TYPE_MODE (unsigned_accum_type_node))
1028 return unsigned_p ? sat_unsigned_accum_type_node
1029 : unsigned_accum_type_node;
1030 if (mode == TYPE_MODE (unsigned_long_accum_type_node))
1031 return unsigned_p ? sat_unsigned_long_accum_type_node
1032 : unsigned_long_accum_type_node;
1033 if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
1034 return unsigned_p ? sat_unsigned_long_long_accum_type_node
1035 : unsigned_long_long_accum_type_node;
1037 if (mode == QQmode)
1038 return unsigned_p ? sat_qq_type_node : qq_type_node;
1039 if (mode == HQmode)
1040 return unsigned_p ? sat_hq_type_node : hq_type_node;
1041 if (mode == SQmode)
1042 return unsigned_p ? sat_sq_type_node : sq_type_node;
1043 if (mode == DQmode)
1044 return unsigned_p ? sat_dq_type_node : dq_type_node;
1045 if (mode == TQmode)
1046 return unsigned_p ? sat_tq_type_node : tq_type_node;
1048 if (mode == UQQmode)
1049 return unsigned_p ? sat_uqq_type_node : uqq_type_node;
1050 if (mode == UHQmode)
1051 return unsigned_p ? sat_uhq_type_node : uhq_type_node;
1052 if (mode == USQmode)
1053 return unsigned_p ? sat_usq_type_node : usq_type_node;
1054 if (mode == UDQmode)
1055 return unsigned_p ? sat_udq_type_node : udq_type_node;
1056 if (mode == UTQmode)
1057 return unsigned_p ? sat_utq_type_node : utq_type_node;
1059 if (mode == HAmode)
1060 return unsigned_p ? sat_ha_type_node : ha_type_node;
1061 if (mode == SAmode)
1062 return unsigned_p ? sat_sa_type_node : sa_type_node;
1063 if (mode == DAmode)
1064 return unsigned_p ? sat_da_type_node : da_type_node;
1065 if (mode == TAmode)
1066 return unsigned_p ? sat_ta_type_node : ta_type_node;
1068 if (mode == UHAmode)
1069 return unsigned_p ? sat_uha_type_node : uha_type_node;
1070 if (mode == USAmode)
1071 return unsigned_p ? sat_usa_type_node : usa_type_node;
1072 if (mode == UDAmode)
1073 return unsigned_p ? sat_uda_type_node : uda_type_node;
1074 if (mode == UTAmode)
1075 return unsigned_p ? sat_uta_type_node : uta_type_node;
1078 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
1079 if (TYPE_MODE (TREE_VALUE (t)) == mode)
1080 return TREE_VALUE (t);
1082 return NULL_TREE;
1085 /* Return true if we are in the global binding level. */
1087 static bool
1088 lto_global_bindings_p (void)
1090 return cfun == NULL;
1093 static void
1094 lto_set_decl_assembler_name (tree decl)
1096 /* This is almost the same as lhd_set_decl_assembler_name, except that
1097 we need to uniquify file-scope names, even if they are not
1098 TREE_PUBLIC, to avoid conflicts between individual files. */
1099 tree id;
1101 if (TREE_PUBLIC (decl))
1102 id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
1103 else
1105 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1106 char *label;
1108 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
1109 id = get_identifier (label);
1112 SET_DECL_ASSEMBLER_NAME (decl, id);
1115 static tree
1116 lto_pushdecl (tree t ATTRIBUTE_UNUSED)
1118 /* Do nothing, since we get all information from DWARF and LTO
1119 sections. */
1120 return NULL_TREE;
1123 static tree
1124 lto_getdecls (void)
1126 /* We have our own write_globals langhook, hence the getdecls
1127 langhook shouldn't be used, except by dbxout.c, so we can't
1128 just abort here. */
1129 return NULL_TREE;
1132 static tree
1133 lto_builtin_function (tree decl)
1135 return decl;
1138 static void
1139 lto_register_builtin_type (tree type, const char *name)
1141 tree decl;
1143 if (!TYPE_NAME (type))
1145 decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
1146 get_identifier (name), type);
1147 DECL_ARTIFICIAL (decl) = 1;
1148 TYPE_NAME (type) = decl;
1151 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
1154 /* Build nodes that would have be created by the C front-end; necessary
1155 for including builtin-types.def and ultimately builtins.def. */
1157 static void
1158 lto_build_c_type_nodes (void)
1160 gcc_assert (void_type_node);
1162 void_list_node = build_tree_list (NULL_TREE, void_type_node);
1163 string_type_node = build_pointer_type (char_type_node);
1164 const_string_type_node
1165 = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
1167 if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1169 intmax_type_node = integer_type_node;
1170 uintmax_type_node = unsigned_type_node;
1171 signed_size_type_node = integer_type_node;
1173 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1175 intmax_type_node = long_integer_type_node;
1176 uintmax_type_node = long_unsigned_type_node;
1177 signed_size_type_node = long_integer_type_node;
1179 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1181 intmax_type_node = long_long_integer_type_node;
1182 uintmax_type_node = long_long_unsigned_type_node;
1183 signed_size_type_node = long_long_integer_type_node;
1185 else
1187 int i;
1189 signed_size_type_node = NULL_TREE;
1190 for (i = 0; i < NUM_INT_N_ENTS; i++)
1191 if (int_n_enabled_p[i])
1193 char name[50];
1194 sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
1196 if (strcmp (name, SIZE_TYPE) == 0)
1198 intmax_type_node = int_n_trees[i].signed_type;
1199 uintmax_type_node = int_n_trees[i].unsigned_type;
1200 signed_size_type_node = int_n_trees[i].signed_type;
1203 if (signed_size_type_node == NULL_TREE)
1204 gcc_unreachable ();
1207 wint_type_node = unsigned_type_node;
1208 pid_type_node = integer_type_node;
1211 /* Perform LTO-specific initialization. */
1213 static bool
1214 lto_init (void)
1216 int i;
1218 /* Initialize LTO-specific data structures. */
1219 in_lto_p = true;
1221 /* We need to generate LTO if running in WPA mode. */
1222 flag_generate_lto = (flag_wpa != NULL);
1224 /* Create the basic integer types. */
1225 build_common_tree_nodes (flag_signed_char);
1227 /* The global tree for the main identifier is filled in by
1228 language-specific front-end initialization that is not run in the
1229 LTO back-end. It appears that all languages that perform such
1230 initialization currently do so in the same way, so we do it here. */
1231 if (main_identifier_node == NULL_TREE)
1232 main_identifier_node = get_identifier ("main");
1234 /* In the C++ front-end, fileptr_type_node is defined as a variant
1235 copy of ptr_type_node, rather than ptr_node itself. The
1236 distinction should only be relevant to the front-end, so we
1237 always use the C definition here in lto1.
1238 Likewise for const struct tm*. */
1239 for (unsigned i = 0;
1240 i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
1241 ++i)
1243 gcc_assert (builtin_structptr_types[i].node
1244 == builtin_structptr_types[i].base);
1245 gcc_assert (TYPE_MAIN_VARIANT (builtin_structptr_types[i].node)
1246 == builtin_structptr_types[i].base);
1249 lto_build_c_type_nodes ();
1250 gcc_assert (va_list_type_node);
1252 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1254 tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
1255 lto_define_builtins (x, x);
1257 else
1259 lto_define_builtins (build_reference_type (va_list_type_node),
1260 va_list_type_node);
1263 if (flag_cilkplus)
1264 cilk_init_builtins ();
1266 targetm.init_builtins ();
1267 build_common_builtin_nodes ();
1269 /* Assign names to the builtin types, otherwise they'll end up
1270 as __unknown__ in debug info.
1271 ??? We simply need to stop pre-seeding the streamer cache.
1272 Below is modeled after from c-common.c:c_common_nodes_and_builtins */
1273 #define NAME_TYPE(t,n) \
1274 if (t) \
1275 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \
1276 get_identifier (n), t)
1277 NAME_TYPE (integer_type_node, "int");
1278 NAME_TYPE (char_type_node, "char");
1279 NAME_TYPE (long_integer_type_node, "long int");
1280 NAME_TYPE (unsigned_type_node, "unsigned int");
1281 NAME_TYPE (long_unsigned_type_node, "long unsigned int");
1282 NAME_TYPE (long_long_integer_type_node, "long long int");
1283 NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int");
1284 NAME_TYPE (short_integer_type_node, "short int");
1285 NAME_TYPE (short_unsigned_type_node, "short unsigned int");
1286 if (signed_char_type_node != char_type_node)
1287 NAME_TYPE (signed_char_type_node, "signed char");
1288 if (unsigned_char_type_node != char_type_node)
1289 NAME_TYPE (unsigned_char_type_node, "unsigned char");
1290 NAME_TYPE (float_type_node, "float");
1291 NAME_TYPE (double_type_node, "double");
1292 NAME_TYPE (long_double_type_node, "long double");
1293 NAME_TYPE (void_type_node, "void");
1294 NAME_TYPE (boolean_type_node, "bool");
1295 NAME_TYPE (complex_float_type_node, "complex float");
1296 NAME_TYPE (complex_double_type_node, "complex double");
1297 NAME_TYPE (complex_long_double_type_node, "complex long double");
1298 for (i = 0; i < NUM_INT_N_ENTS; i++)
1299 if (int_n_enabled_p[i])
1301 char name[50];
1302 sprintf (name, "__int%d", int_n_data[i].bitsize);
1303 NAME_TYPE (int_n_trees[i].signed_type, name);
1305 #undef NAME_TYPE
1307 return true;
1310 /* Initialize tree structures required by the LTO front end. */
1312 static void lto_init_ts (void)
1314 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1317 #undef LANG_HOOKS_NAME
1318 #define LANG_HOOKS_NAME "GNU GIMPLE"
1319 #undef LANG_HOOKS_OPTION_LANG_MASK
1320 #define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
1321 #undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
1322 #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
1323 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1324 #define LANG_HOOKS_INIT_OPTIONS_STRUCT lto_init_options_struct
1325 #undef LANG_HOOKS_HANDLE_OPTION
1326 #define LANG_HOOKS_HANDLE_OPTION lto_handle_option
1327 #undef LANG_HOOKS_POST_OPTIONS
1328 #define LANG_HOOKS_POST_OPTIONS lto_post_options
1329 #undef LANG_HOOKS_GET_ALIAS_SET
1330 #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
1331 #undef LANG_HOOKS_TYPE_FOR_MODE
1332 #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
1333 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
1334 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
1335 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1336 #define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
1337 #undef LANG_HOOKS_PUSHDECL
1338 #define LANG_HOOKS_PUSHDECL lto_pushdecl
1339 #undef LANG_HOOKS_GETDECLS
1340 #define LANG_HOOKS_GETDECLS lto_getdecls
1341 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1342 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
1343 #undef LANG_HOOKS_BUILTIN_FUNCTION
1344 #define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
1345 #undef LANG_HOOKS_INIT
1346 #define LANG_HOOKS_INIT lto_init
1347 #undef LANG_HOOKS_PARSE_FILE
1348 #define LANG_HOOKS_PARSE_FILE lto_main
1349 #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
1350 #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
1351 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1352 #define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
1353 #undef LANG_HOOKS_EH_PERSONALITY
1354 #define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
1356 /* Attribute hooks. */
1357 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1358 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
1359 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
1360 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
1362 #undef LANG_HOOKS_BEGIN_SECTION
1363 #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
1364 #undef LANG_HOOKS_APPEND_DATA
1365 #define LANG_HOOKS_APPEND_DATA lto_obj_append_data
1366 #undef LANG_HOOKS_END_SECTION
1367 #define LANG_HOOKS_END_SECTION lto_obj_end_section
1369 #undef LANG_HOOKS_INIT_TS
1370 #define LANG_HOOKS_INIT_TS lto_init_ts
1372 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1374 /* Language hooks that are not part of lang_hooks. */
1376 tree
1377 convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1379 gcc_unreachable ();
1382 /* Tree walking support. */
1384 static enum lto_tree_node_structure_enum
1385 lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
1387 return TS_LTO_GENERIC;
1390 #include "gtype-lto.h"
1391 #include "gt-lto-lto-lang.h"