* es.po: Update.
[official-gcc.git] / gcc / lto / lto-lang.c
blobca8945e53bb5d1e3699f74203e8bdd0c6afac1c3
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"
39 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
40 static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
41 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
42 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
43 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
44 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
45 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
46 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
47 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
48 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
49 static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool *);
50 static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
51 static tree ignore_attribute (tree *, tree, tree, int, bool *);
53 static tree handle_format_attribute (tree *, tree, tree, int, bool *);
54 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
55 static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
57 /* Table of machine-independent attributes supported in GIMPLE. */
58 const struct attribute_spec lto_attribute_table[] =
60 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
61 do_diagnostic } */
62 { "noreturn", 0, 0, true, false, false,
63 handle_noreturn_attribute, false },
64 { "leaf", 0, 0, true, false, false,
65 handle_leaf_attribute, false },
66 /* The same comments as for noreturn attributes apply to const ones. */
67 { "const", 0, 0, true, false, false,
68 handle_const_attribute, false },
69 { "malloc", 0, 0, true, false, false,
70 handle_malloc_attribute, false },
71 { "pure", 0, 0, true, false, false,
72 handle_pure_attribute, false },
73 { "no vops", 0, 0, true, false, false,
74 handle_novops_attribute, false },
75 { "nonnull", 0, -1, false, true, true,
76 handle_nonnull_attribute, false },
77 { "nothrow", 0, 0, true, false, false,
78 handle_nothrow_attribute, false },
79 { "returns_twice", 0, 0, true, false, false,
80 handle_returns_twice_attribute, false },
81 { "sentinel", 0, 1, false, true, true,
82 handle_sentinel_attribute, false },
83 { "type generic", 0, 0, false, true, true,
84 handle_type_generic_attribute, false },
85 { "fn spec", 1, 1, false, true, true,
86 handle_fnspec_attribute, false },
87 { "transaction_pure", 0, 0, false, true, true,
88 handle_transaction_pure_attribute, false },
89 /* For internal use only. The leading '*' both prevents its usage in
90 source code and signals that it may be overridden by machine tables. */
91 { "*tm regparm", 0, 0, false, true, true,
92 ignore_attribute, false },
93 { NULL, 0, 0, false, false, false, NULL, false }
96 /* Give the specifications for the format attributes, used by C and all
97 descendants. */
99 const struct attribute_spec lto_format_attribute_table[] =
101 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
102 affects_type_identity } */
103 { "format", 3, 3, false, true, true,
104 handle_format_attribute, false },
105 { "format_arg", 1, 1, false, true, true,
106 handle_format_arg_attribute, false },
107 { NULL, 0, 0, false, false, false, NULL, false }
110 enum built_in_attribute
112 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
113 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
114 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
115 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
116 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
117 #include "builtin-attrs.def"
118 #undef DEF_ATTR_NULL_TREE
119 #undef DEF_ATTR_INT
120 #undef DEF_ATTR_STRING
121 #undef DEF_ATTR_IDENT
122 #undef DEF_ATTR_TREE_LIST
123 ATTR_LAST
126 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
128 /* Builtin types. */
130 enum lto_builtin_type
132 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
133 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
134 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
135 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
136 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
137 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
138 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
139 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
140 ARG6) NAME,
141 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
142 ARG6, ARG7) NAME,
143 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
144 ARG6, ARG7, ARG8) NAME,
145 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
146 ARG6, ARG7, ARG8, ARG9) NAME,
147 #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
148 ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
149 #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
150 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
151 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
152 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
153 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
154 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
155 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
156 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
157 NAME,
158 #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
159 ARG6) NAME,
160 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
161 ARG6, ARG7) NAME,
162 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
163 #include "builtin-types.def"
164 #undef DEF_PRIMITIVE_TYPE
165 #undef DEF_FUNCTION_TYPE_0
166 #undef DEF_FUNCTION_TYPE_1
167 #undef DEF_FUNCTION_TYPE_2
168 #undef DEF_FUNCTION_TYPE_3
169 #undef DEF_FUNCTION_TYPE_4
170 #undef DEF_FUNCTION_TYPE_5
171 #undef DEF_FUNCTION_TYPE_6
172 #undef DEF_FUNCTION_TYPE_7
173 #undef DEF_FUNCTION_TYPE_8
174 #undef DEF_FUNCTION_TYPE_9
175 #undef DEF_FUNCTION_TYPE_10
176 #undef DEF_FUNCTION_TYPE_11
177 #undef DEF_FUNCTION_TYPE_VAR_0
178 #undef DEF_FUNCTION_TYPE_VAR_1
179 #undef DEF_FUNCTION_TYPE_VAR_2
180 #undef DEF_FUNCTION_TYPE_VAR_3
181 #undef DEF_FUNCTION_TYPE_VAR_4
182 #undef DEF_FUNCTION_TYPE_VAR_5
183 #undef DEF_FUNCTION_TYPE_VAR_6
184 #undef DEF_FUNCTION_TYPE_VAR_7
185 #undef DEF_POINTER_TYPE
186 BT_LAST
189 typedef enum lto_builtin_type builtin_type;
191 static GTY(()) tree builtin_types[(int) BT_LAST + 1];
193 static GTY(()) tree string_type_node;
194 static GTY(()) tree const_string_type_node;
195 static GTY(()) tree wint_type_node;
196 static GTY(()) tree intmax_type_node;
197 static GTY(()) tree uintmax_type_node;
198 static GTY(()) tree signed_size_type_node;
200 /* Flags needed to process builtins.def. */
201 int flag_isoc94;
202 int flag_isoc99;
203 int flag_isoc11;
205 /* Attribute handlers. */
207 /* Handle a "noreturn" attribute; arguments as in
208 struct attribute_spec.handler. */
210 static tree
211 handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
212 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
213 bool * ARG_UNUSED (no_add_attrs))
215 tree type = TREE_TYPE (*node);
217 if (TREE_CODE (*node) == FUNCTION_DECL)
218 TREE_THIS_VOLATILE (*node) = 1;
219 else if (TREE_CODE (type) == POINTER_TYPE
220 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
221 TREE_TYPE (*node)
222 = build_pointer_type
223 (build_type_variant (TREE_TYPE (type),
224 TYPE_READONLY (TREE_TYPE (type)), 1));
225 else
226 gcc_unreachable ();
228 return NULL_TREE;
231 /* Handle a "leaf" attribute; arguments as in
232 struct attribute_spec.handler. */
234 static tree
235 handle_leaf_attribute (tree *node, tree name,
236 tree ARG_UNUSED (args),
237 int ARG_UNUSED (flags), bool *no_add_attrs)
239 if (TREE_CODE (*node) != FUNCTION_DECL)
241 warning (OPT_Wattributes, "%qE attribute ignored", name);
242 *no_add_attrs = true;
244 if (!TREE_PUBLIC (*node))
246 warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
247 *no_add_attrs = true;
250 return NULL_TREE;
253 /* Handle a "const" attribute; arguments as in
254 struct attribute_spec.handler. */
256 static tree
257 handle_const_attribute (tree *node, tree ARG_UNUSED (name),
258 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
259 bool * ARG_UNUSED (no_add_attrs))
261 tree type = TREE_TYPE (*node);
263 /* See FIXME comment on noreturn in c_common_attribute_table. */
264 if (TREE_CODE (*node) == FUNCTION_DECL)
265 TREE_READONLY (*node) = 1;
266 else if (TREE_CODE (type) == POINTER_TYPE
267 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
268 TREE_TYPE (*node)
269 = build_pointer_type
270 (build_type_variant (TREE_TYPE (type), 1,
271 TREE_THIS_VOLATILE (TREE_TYPE (type))));
272 else
273 gcc_unreachable ();
275 return NULL_TREE;
279 /* Handle a "malloc" attribute; arguments as in
280 struct attribute_spec.handler. */
282 static tree
283 handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
284 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
285 bool * ARG_UNUSED (no_add_attrs))
287 if (TREE_CODE (*node) == FUNCTION_DECL
288 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
289 DECL_IS_MALLOC (*node) = 1;
290 else
291 gcc_unreachable ();
293 return NULL_TREE;
297 /* Handle a "pure" attribute; arguments as in
298 struct attribute_spec.handler. */
300 static tree
301 handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
302 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
303 bool * ARG_UNUSED (no_add_attrs))
305 if (TREE_CODE (*node) == FUNCTION_DECL)
306 DECL_PURE_P (*node) = 1;
307 else
308 gcc_unreachable ();
310 return NULL_TREE;
314 /* Handle a "no vops" attribute; arguments as in
315 struct attribute_spec.handler. */
317 static tree
318 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
319 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
320 bool *ARG_UNUSED (no_add_attrs))
322 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
323 DECL_IS_NOVOPS (*node) = 1;
324 return NULL_TREE;
328 /* Helper for nonnull attribute handling; fetch the operand number
329 from the attribute argument list. */
331 static bool
332 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
334 /* Verify the arg number is a constant. */
335 if (!tree_fits_uhwi_p (arg_num_expr))
336 return false;
338 *valp = TREE_INT_CST_LOW (arg_num_expr);
339 return true;
342 /* Handle the "nonnull" attribute. */
344 static tree
345 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
346 tree args, int ARG_UNUSED (flags),
347 bool * ARG_UNUSED (no_add_attrs))
349 tree type = *node;
351 /* If no arguments are specified, all pointer arguments should be
352 non-null. Verify a full prototype is given so that the arguments
353 will have the correct types when we actually check them later.
354 Avoid diagnosing type-generic built-ins since those have no
355 prototype. */
356 if (!args)
358 gcc_assert (prototype_p (type)
359 || !TYPE_ATTRIBUTES (type)
360 || lookup_attribute ("type generic", TYPE_ATTRIBUTES (type)));
362 return NULL_TREE;
365 /* Argument list specified. Verify that each argument number references
366 a pointer argument. */
367 for (; args; args = TREE_CHAIN (args))
369 tree argument;
370 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
372 if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
373 gcc_unreachable ();
375 argument = TYPE_ARG_TYPES (type);
376 if (argument)
378 for (ck_num = 1; ; ck_num++)
380 if (!argument || ck_num == arg_num)
381 break;
382 argument = TREE_CHAIN (argument);
385 gcc_assert (argument
386 && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
390 return NULL_TREE;
394 /* Handle a "nothrow" attribute; arguments as in
395 struct attribute_spec.handler. */
397 static tree
398 handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
399 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
400 bool * ARG_UNUSED (no_add_attrs))
402 if (TREE_CODE (*node) == FUNCTION_DECL)
403 TREE_NOTHROW (*node) = 1;
404 else
405 gcc_unreachable ();
407 return NULL_TREE;
411 /* Handle a "sentinel" attribute. */
413 static tree
414 handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
415 int ARG_UNUSED (flags),
416 bool * ARG_UNUSED (no_add_attrs))
418 gcc_assert (stdarg_p (*node));
420 if (args)
422 tree position = TREE_VALUE (args);
423 gcc_assert (TREE_CODE (position) == INTEGER_CST);
424 if (tree_int_cst_lt (position, integer_zero_node))
425 gcc_unreachable ();
428 return NULL_TREE;
431 /* Handle a "type_generic" attribute. */
433 static tree
434 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
435 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
436 bool * ARG_UNUSED (no_add_attrs))
438 /* Ensure we have a function type. */
439 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
441 /* Ensure we have a variadic function. */
442 gcc_assert (!prototype_p (*node) || stdarg_p (*node));
444 return NULL_TREE;
447 /* Handle a "transaction_pure" attribute. */
449 static tree
450 handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
451 tree ARG_UNUSED (args),
452 int ARG_UNUSED (flags),
453 bool * ARG_UNUSED (no_add_attrs))
455 /* Ensure we have a function type. */
456 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
458 return NULL_TREE;
461 /* Handle a "returns_twice" attribute. */
463 static tree
464 handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name),
465 tree ARG_UNUSED (args),
466 int ARG_UNUSED (flags),
467 bool * ARG_UNUSED (no_add_attrs))
469 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
471 DECL_IS_RETURNS_TWICE (*node) = 1;
473 return NULL_TREE;
476 /* Ignore the given attribute. Used when this attribute may be usefully
477 overridden by the target, but is not used generically. */
479 static tree
480 ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
481 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
482 bool *no_add_attrs)
484 *no_add_attrs = true;
485 return NULL_TREE;
488 /* Handle a "format" attribute; arguments as in
489 struct attribute_spec.handler. */
491 static tree
492 handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
493 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
494 bool *no_add_attrs)
496 *no_add_attrs = true;
497 return NULL_TREE;
501 /* Handle a "format_arg" attribute; arguments as in
502 struct attribute_spec.handler. */
504 tree
505 handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
506 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
507 bool *no_add_attrs)
509 *no_add_attrs = true;
510 return NULL_TREE;
514 /* Handle a "fn spec" attribute; arguments as in
515 struct attribute_spec.handler. */
517 static tree
518 handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
519 tree args, int ARG_UNUSED (flags),
520 bool *no_add_attrs ATTRIBUTE_UNUSED)
522 gcc_assert (args
523 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
524 && !TREE_CHAIN (args));
525 return NULL_TREE;
528 /* Cribbed from c-common.c. */
530 static void
531 def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
533 tree t;
534 tree *args = XALLOCAVEC (tree, n);
535 va_list list;
536 int i;
537 bool err = false;
539 va_start (list, n);
540 for (i = 0; i < n; ++i)
542 builtin_type a = (builtin_type) va_arg (list, int);
543 t = builtin_types[a];
544 if (t == error_mark_node)
545 err = true;
546 args[i] = t;
548 va_end (list);
550 t = builtin_types[ret];
551 if (err)
552 t = error_mark_node;
553 if (t == error_mark_node)
555 else if (var)
556 t = build_varargs_function_type_array (t, n, args);
557 else
558 t = build_function_type_array (t, n, args);
560 builtin_types[def] = t;
563 /* Used to help initialize the builtin-types.def table. When a type of
564 the correct size doesn't exist, use error_mark_node instead of NULL.
565 The later results in segfaults even when a decl using the type doesn't
566 get invoked. */
568 static tree
569 builtin_type_for_size (int size, bool unsignedp)
571 tree type = lang_hooks.types.type_for_size (size, unsignedp);
572 return type ? type : error_mark_node;
575 /* Support for DEF_BUILTIN. */
577 static void
578 def_builtin_1 (enum built_in_function fncode, const char *name,
579 enum built_in_class fnclass, tree fntype, tree libtype,
580 bool both_p, bool fallback_p, bool nonansi_p,
581 tree fnattrs, bool implicit_p)
583 tree decl;
584 const char *libname;
586 if (fntype == error_mark_node)
587 return;
589 libname = name + strlen ("__builtin_");
590 decl = add_builtin_function (name, fntype, fncode, fnclass,
591 (fallback_p ? libname : NULL),
592 fnattrs);
594 if (both_p
595 && !flag_no_builtin
596 && !(nonansi_p && flag_no_nonansi_builtin))
597 add_builtin_function (libname, libtype, fncode, fnclass,
598 NULL, fnattrs);
600 set_builtin_decl (fncode, decl, implicit_p);
604 /* Initialize the attribute table for all the supported builtins. */
606 static void
607 lto_init_attributes (void)
609 /* Fill in the built_in_attributes array. */
610 #define DEF_ATTR_NULL_TREE(ENUM) \
611 built_in_attributes[(int) ENUM] = NULL_TREE;
612 #define DEF_ATTR_INT(ENUM, VALUE) \
613 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
614 #define DEF_ATTR_STRING(ENUM, VALUE) \
615 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
616 #define DEF_ATTR_IDENT(ENUM, STRING) \
617 built_in_attributes[(int) ENUM] = get_identifier (STRING);
618 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
619 built_in_attributes[(int) ENUM] \
620 = tree_cons (built_in_attributes[(int) PURPOSE], \
621 built_in_attributes[(int) VALUE], \
622 built_in_attributes[(int) CHAIN]);
623 #include "builtin-attrs.def"
624 #undef DEF_ATTR_NULL_TREE
625 #undef DEF_ATTR_INT
626 #undef DEF_ATTR_STRING
627 #undef DEF_ATTR_IDENT
628 #undef DEF_ATTR_TREE_LIST
631 /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
632 VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
634 static void
635 lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
636 tree va_list_arg_type_node ATTRIBUTE_UNUSED)
638 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
639 builtin_types[ENUM] = VALUE;
640 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
641 def_fn_type (ENUM, RETURN, 0, 0);
642 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
643 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
644 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
645 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
646 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
647 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
648 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
649 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
650 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
651 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
652 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
653 ARG6) \
654 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
655 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
656 ARG6, ARG7) \
657 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
658 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
659 ARG6, ARG7, ARG8) \
660 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
661 ARG7, ARG8);
662 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
663 ARG6, ARG7, ARG8, ARG9) \
664 def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
665 ARG7, ARG8, ARG9);
666 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
667 ARG6, ARG7, ARG8, ARG9, ARG10) \
668 def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
669 ARG7, ARG8, ARG9, ARG10);
670 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
671 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
672 def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
673 ARG7, ARG8, ARG9, ARG10, ARG11);
674 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
675 def_fn_type (ENUM, RETURN, 1, 0);
676 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
677 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
678 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
679 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
680 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
681 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
682 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
683 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
684 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
685 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
686 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
687 ARG6) \
688 def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
689 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
690 ARG6, ARG7) \
691 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
692 #define DEF_POINTER_TYPE(ENUM, TYPE) \
693 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
695 #include "builtin-types.def"
697 #undef DEF_PRIMITIVE_TYPE
698 #undef DEF_FUNCTION_TYPE_0
699 #undef DEF_FUNCTION_TYPE_1
700 #undef DEF_FUNCTION_TYPE_2
701 #undef DEF_FUNCTION_TYPE_3
702 #undef DEF_FUNCTION_TYPE_4
703 #undef DEF_FUNCTION_TYPE_5
704 #undef DEF_FUNCTION_TYPE_6
705 #undef DEF_FUNCTION_TYPE_7
706 #undef DEF_FUNCTION_TYPE_8
707 #undef DEF_FUNCTION_TYPE_9
708 #undef DEF_FUNCTION_TYPE_10
709 #undef DEF_FUNCTION_TYPE_11
710 #undef DEF_FUNCTION_TYPE_VAR_0
711 #undef DEF_FUNCTION_TYPE_VAR_1
712 #undef DEF_FUNCTION_TYPE_VAR_2
713 #undef DEF_FUNCTION_TYPE_VAR_3
714 #undef DEF_FUNCTION_TYPE_VAR_4
715 #undef DEF_FUNCTION_TYPE_VAR_5
716 #undef DEF_FUNCTION_TYPE_VAR_6
717 #undef DEF_FUNCTION_TYPE_VAR_7
718 #undef DEF_POINTER_TYPE
719 builtin_types[(int) BT_LAST] = NULL_TREE;
721 lto_init_attributes ();
723 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
724 NONANSI_P, ATTRS, IMPLICIT, COND) \
725 if (NAME && COND) \
726 def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
727 builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
728 NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
729 #include "builtins.def"
732 static GTY(()) tree registered_builtin_types;
734 /* Language hooks. */
736 static unsigned int
737 lto_option_lang_mask (void)
739 return CL_LTO;
742 static bool
743 lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
745 /* The LTO front end inherits all the options from the first front
746 end that was used. However, not all the original front end
747 options make sense in LTO.
749 A real solution would be to filter this in collect2, but collect2
750 does not have access to all the option attributes to know what to
751 filter. So, in lto1 we silently accept inherited flags and do
752 nothing about it. */
753 return false;
756 static void
757 lto_init_options_struct (struct gcc_options *opts)
759 /* By default, C99-like requirements for complex multiply and divide.
760 ??? Until the complex method is encoded in the IL this is the only
761 safe choice. This will pessimize Fortran code with LTO unless
762 people specify a complex method manually or use -ffast-math. */
763 opts->x_flag_complex_method = 2;
766 /* Handle command-line option SCODE. If the option takes an argument, it is
767 stored in ARG, which is otherwise NULL. VALUE holds either a numerical
768 argument or a binary value indicating whether the positive or negative form
769 of the option was supplied. */
771 const char *resolution_file_name;
772 static bool
773 lto_handle_option (size_t scode, const char *arg,
774 int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
775 location_t loc ATTRIBUTE_UNUSED,
776 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
778 enum opt_code code = (enum opt_code) scode;
779 bool result = true;
781 switch (code)
783 case OPT_fresolution_:
784 resolution_file_name = arg;
785 break;
787 case OPT_Wabi:
788 warn_psabi = value;
789 break;
791 case OPT_fwpa:
792 flag_wpa = value ? "" : NULL;
793 break;
795 default:
796 break;
799 return result;
802 /* Perform post-option processing. Does additional initialization based on
803 command-line options. PFILENAME is the main input filename. Returns false
804 to enable subsequent back-end initialization. */
806 static bool
807 lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
809 /* -fltrans and -fwpa are mutually exclusive. Check for that here. */
810 if (flag_wpa && flag_ltrans)
811 error ("-fwpa and -fltrans are mutually exclusive");
813 if (flag_ltrans)
815 flag_generate_lto = 0;
817 /* During LTRANS, we are not looking at the whole program, only
818 a subset of the whole callgraph. */
819 flag_whole_program = 0;
822 if (flag_wpa)
823 flag_generate_lto = 1;
825 /* Initialize the codegen flags according to the output type. */
826 switch (flag_lto_linker_output)
828 case LTO_LINKER_OUTPUT_REL: /* .o: incremental link producing LTO IL */
829 flag_whole_program = 0;
830 flag_incremental_link = 1;
831 break;
833 case LTO_LINKER_OUTPUT_DYN: /* .so: PID library */
834 /* On some targets, like i386 it makes sense to build PIC library wihout
835 -fpic for performance reasons. So no need to adjust flags. */
836 break;
838 case LTO_LINKER_OUTPUT_PIE: /* PIE binary */
839 /* If -fPIC or -fPIE was used at compile time, be sure that
840 flag_pie is 2. */
841 flag_pie = MAX (flag_pie, flag_pic);
842 flag_pic = flag_pie;
843 break;
845 case LTO_LINKER_OUTPUT_EXEC: /* Normal executable */
846 flag_pic = 0;
847 flag_pie = 0;
848 break;
850 case LTO_LINKER_OUTPUT_UNKNOWN:
851 break;
854 /* Excess precision other than "fast" requires front-end
855 support. */
856 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
858 /* When partitioning, we can tear appart STRING_CSTs uses from the same
859 TU into multiple partitions. Without constant merging the constants
860 might not be equal at runtime. See PR50199. */
861 if (!flag_merge_constants)
862 flag_merge_constants = 1;
864 /* Initialize the compiler back end. */
865 return false;
868 /* Return a data type that has machine mode MODE.
869 If the mode is an integer,
870 then UNSIGNEDP selects between signed and unsigned types.
871 If the mode is a fixed-point mode,
872 then UNSIGNEDP selects between saturating and nonsaturating types. */
874 static tree
875 lto_type_for_mode (machine_mode mode, int unsigned_p)
877 tree t;
878 int i;
880 if (mode == TYPE_MODE (integer_type_node))
881 return unsigned_p ? unsigned_type_node : integer_type_node;
883 if (mode == TYPE_MODE (signed_char_type_node))
884 return unsigned_p ? unsigned_char_type_node : signed_char_type_node;
886 if (mode == TYPE_MODE (short_integer_type_node))
887 return unsigned_p ? short_unsigned_type_node : short_integer_type_node;
889 if (mode == TYPE_MODE (long_integer_type_node))
890 return unsigned_p ? long_unsigned_type_node : long_integer_type_node;
892 if (mode == TYPE_MODE (long_long_integer_type_node))
893 return unsigned_p ? long_long_unsigned_type_node : long_long_integer_type_node;
895 for (i = 0; i < NUM_INT_N_ENTS; i ++)
896 if (int_n_enabled_p[i]
897 && mode == int_n_data[i].m)
898 return (unsigned_p ? int_n_trees[i].unsigned_type
899 : int_n_trees[i].signed_type);
901 if (mode == QImode)
902 return unsigned_p ? unsigned_intQI_type_node : intQI_type_node;
904 if (mode == HImode)
905 return unsigned_p ? unsigned_intHI_type_node : intHI_type_node;
907 if (mode == SImode)
908 return unsigned_p ? unsigned_intSI_type_node : intSI_type_node;
910 if (mode == DImode)
911 return unsigned_p ? unsigned_intDI_type_node : intDI_type_node;
913 #if HOST_BITS_PER_WIDE_INT >= 64
914 if (mode == TYPE_MODE (intTI_type_node))
915 return unsigned_p ? unsigned_intTI_type_node : intTI_type_node;
916 #endif
918 if (mode == TYPE_MODE (float_type_node))
919 return float_type_node;
921 if (mode == TYPE_MODE (double_type_node))
922 return double_type_node;
924 if (mode == TYPE_MODE (long_double_type_node))
925 return long_double_type_node;
927 if (mode == TYPE_MODE (void_type_node))
928 return void_type_node;
930 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
931 return (unsigned_p
932 ? make_unsigned_type (GET_MODE_PRECISION (mode))
933 : make_signed_type (GET_MODE_PRECISION (mode)));
935 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
936 return (unsigned_p
937 ? make_unsigned_type (GET_MODE_PRECISION (mode))
938 : make_signed_type (GET_MODE_PRECISION (mode)));
940 if (COMPLEX_MODE_P (mode))
942 machine_mode inner_mode;
943 tree inner_type;
945 if (mode == TYPE_MODE (complex_float_type_node))
946 return complex_float_type_node;
947 if (mode == TYPE_MODE (complex_double_type_node))
948 return complex_double_type_node;
949 if (mode == TYPE_MODE (complex_long_double_type_node))
950 return complex_long_double_type_node;
952 if (mode == TYPE_MODE (complex_integer_type_node) && !unsigned_p)
953 return complex_integer_type_node;
955 inner_mode = GET_MODE_INNER (mode);
956 inner_type = lto_type_for_mode (inner_mode, unsigned_p);
957 if (inner_type != NULL_TREE)
958 return build_complex_type (inner_type);
960 else if (VECTOR_MODE_P (mode))
962 machine_mode inner_mode = GET_MODE_INNER (mode);
963 tree inner_type = lto_type_for_mode (inner_mode, unsigned_p);
964 if (inner_type != NULL_TREE)
965 return build_vector_type_for_mode (inner_type, mode);
968 if (mode == TYPE_MODE (dfloat32_type_node))
969 return dfloat32_type_node;
970 if (mode == TYPE_MODE (dfloat64_type_node))
971 return dfloat64_type_node;
972 if (mode == TYPE_MODE (dfloat128_type_node))
973 return dfloat128_type_node;
975 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
977 if (mode == TYPE_MODE (short_fract_type_node))
978 return unsigned_p ? sat_short_fract_type_node : short_fract_type_node;
979 if (mode == TYPE_MODE (fract_type_node))
980 return unsigned_p ? sat_fract_type_node : fract_type_node;
981 if (mode == TYPE_MODE (long_fract_type_node))
982 return unsigned_p ? sat_long_fract_type_node : long_fract_type_node;
983 if (mode == TYPE_MODE (long_long_fract_type_node))
984 return unsigned_p ? sat_long_long_fract_type_node
985 : long_long_fract_type_node;
987 if (mode == TYPE_MODE (unsigned_short_fract_type_node))
988 return unsigned_p ? sat_unsigned_short_fract_type_node
989 : unsigned_short_fract_type_node;
990 if (mode == TYPE_MODE (unsigned_fract_type_node))
991 return unsigned_p ? sat_unsigned_fract_type_node
992 : unsigned_fract_type_node;
993 if (mode == TYPE_MODE (unsigned_long_fract_type_node))
994 return unsigned_p ? sat_unsigned_long_fract_type_node
995 : unsigned_long_fract_type_node;
996 if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
997 return unsigned_p ? sat_unsigned_long_long_fract_type_node
998 : unsigned_long_long_fract_type_node;
1000 if (mode == TYPE_MODE (short_accum_type_node))
1001 return unsigned_p ? sat_short_accum_type_node : short_accum_type_node;
1002 if (mode == TYPE_MODE (accum_type_node))
1003 return unsigned_p ? sat_accum_type_node : accum_type_node;
1004 if (mode == TYPE_MODE (long_accum_type_node))
1005 return unsigned_p ? sat_long_accum_type_node : long_accum_type_node;
1006 if (mode == TYPE_MODE (long_long_accum_type_node))
1007 return unsigned_p ? sat_long_long_accum_type_node
1008 : long_long_accum_type_node;
1010 if (mode == TYPE_MODE (unsigned_short_accum_type_node))
1011 return unsigned_p ? sat_unsigned_short_accum_type_node
1012 : unsigned_short_accum_type_node;
1013 if (mode == TYPE_MODE (unsigned_accum_type_node))
1014 return unsigned_p ? sat_unsigned_accum_type_node
1015 : unsigned_accum_type_node;
1016 if (mode == TYPE_MODE (unsigned_long_accum_type_node))
1017 return unsigned_p ? sat_unsigned_long_accum_type_node
1018 : unsigned_long_accum_type_node;
1019 if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
1020 return unsigned_p ? sat_unsigned_long_long_accum_type_node
1021 : unsigned_long_long_accum_type_node;
1023 if (mode == QQmode)
1024 return unsigned_p ? sat_qq_type_node : qq_type_node;
1025 if (mode == HQmode)
1026 return unsigned_p ? sat_hq_type_node : hq_type_node;
1027 if (mode == SQmode)
1028 return unsigned_p ? sat_sq_type_node : sq_type_node;
1029 if (mode == DQmode)
1030 return unsigned_p ? sat_dq_type_node : dq_type_node;
1031 if (mode == TQmode)
1032 return unsigned_p ? sat_tq_type_node : tq_type_node;
1034 if (mode == UQQmode)
1035 return unsigned_p ? sat_uqq_type_node : uqq_type_node;
1036 if (mode == UHQmode)
1037 return unsigned_p ? sat_uhq_type_node : uhq_type_node;
1038 if (mode == USQmode)
1039 return unsigned_p ? sat_usq_type_node : usq_type_node;
1040 if (mode == UDQmode)
1041 return unsigned_p ? sat_udq_type_node : udq_type_node;
1042 if (mode == UTQmode)
1043 return unsigned_p ? sat_utq_type_node : utq_type_node;
1045 if (mode == HAmode)
1046 return unsigned_p ? sat_ha_type_node : ha_type_node;
1047 if (mode == SAmode)
1048 return unsigned_p ? sat_sa_type_node : sa_type_node;
1049 if (mode == DAmode)
1050 return unsigned_p ? sat_da_type_node : da_type_node;
1051 if (mode == TAmode)
1052 return unsigned_p ? sat_ta_type_node : ta_type_node;
1054 if (mode == UHAmode)
1055 return unsigned_p ? sat_uha_type_node : uha_type_node;
1056 if (mode == USAmode)
1057 return unsigned_p ? sat_usa_type_node : usa_type_node;
1058 if (mode == UDAmode)
1059 return unsigned_p ? sat_uda_type_node : uda_type_node;
1060 if (mode == UTAmode)
1061 return unsigned_p ? sat_uta_type_node : uta_type_node;
1064 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
1065 if (TYPE_MODE (TREE_VALUE (t)) == mode)
1066 return TREE_VALUE (t);
1068 return NULL_TREE;
1071 /* Return true if we are in the global binding level. */
1073 static bool
1074 lto_global_bindings_p (void)
1076 return cfun == NULL;
1079 static void
1080 lto_set_decl_assembler_name (tree decl)
1082 /* This is almost the same as lhd_set_decl_assembler_name, except that
1083 we need to uniquify file-scope names, even if they are not
1084 TREE_PUBLIC, to avoid conflicts between individual files. */
1085 tree id;
1087 if (TREE_PUBLIC (decl))
1088 id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
1089 else
1091 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1092 char *label;
1094 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
1095 id = get_identifier (label);
1098 SET_DECL_ASSEMBLER_NAME (decl, id);
1101 static tree
1102 lto_pushdecl (tree t ATTRIBUTE_UNUSED)
1104 /* Do nothing, since we get all information from DWARF and LTO
1105 sections. */
1106 return NULL_TREE;
1109 static tree
1110 lto_getdecls (void)
1112 /* We have our own write_globals langhook, hence the getdecls
1113 langhook shouldn't be used, except by dbxout.c, so we can't
1114 just abort here. */
1115 return NULL_TREE;
1118 static tree
1119 lto_builtin_function (tree decl)
1121 return decl;
1124 static void
1125 lto_register_builtin_type (tree type, const char *name)
1127 tree decl;
1129 if (!TYPE_NAME (type))
1131 decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
1132 get_identifier (name), type);
1133 DECL_ARTIFICIAL (decl) = 1;
1134 TYPE_NAME (type) = decl;
1137 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
1140 /* Build nodes that would have be created by the C front-end; necessary
1141 for including builtin-types.def and ultimately builtins.def. */
1143 static void
1144 lto_build_c_type_nodes (void)
1146 gcc_assert (void_type_node);
1148 void_list_node = build_tree_list (NULL_TREE, void_type_node);
1149 string_type_node = build_pointer_type (char_type_node);
1150 const_string_type_node
1151 = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
1153 if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1155 intmax_type_node = integer_type_node;
1156 uintmax_type_node = unsigned_type_node;
1157 signed_size_type_node = integer_type_node;
1159 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1161 intmax_type_node = long_integer_type_node;
1162 uintmax_type_node = long_unsigned_type_node;
1163 signed_size_type_node = long_integer_type_node;
1165 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1167 intmax_type_node = long_long_integer_type_node;
1168 uintmax_type_node = long_long_unsigned_type_node;
1169 signed_size_type_node = long_long_integer_type_node;
1171 else
1173 int i;
1175 signed_size_type_node = NULL_TREE;
1176 for (i = 0; i < NUM_INT_N_ENTS; i++)
1177 if (int_n_enabled_p[i])
1179 char name[50];
1180 sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
1182 if (strcmp (name, SIZE_TYPE) == 0)
1184 intmax_type_node = int_n_trees[i].signed_type;
1185 uintmax_type_node = int_n_trees[i].unsigned_type;
1186 signed_size_type_node = int_n_trees[i].signed_type;
1189 if (signed_size_type_node == NULL_TREE)
1190 gcc_unreachable ();
1193 wint_type_node = unsigned_type_node;
1194 pid_type_node = integer_type_node;
1197 /* Perform LTO-specific initialization. */
1199 static bool
1200 lto_init (void)
1202 int i;
1204 /* We need to generate LTO if running in WPA mode. */
1205 flag_generate_lto = (flag_wpa != NULL);
1207 /* Create the basic integer types. */
1208 build_common_tree_nodes (flag_signed_char);
1210 /* The global tree for the main identifier is filled in by
1211 language-specific front-end initialization that is not run in the
1212 LTO back-end. It appears that all languages that perform such
1213 initialization currently do so in the same way, so we do it here. */
1214 if (main_identifier_node == NULL_TREE)
1215 main_identifier_node = get_identifier ("main");
1217 /* In the C++ front-end, fileptr_type_node is defined as a variant
1218 copy of ptr_type_node, rather than ptr_node itself. The
1219 distinction should only be relevant to the front-end, so we
1220 always use the C definition here in lto1. */
1221 gcc_assert (fileptr_type_node == ptr_type_node);
1222 gcc_assert (TYPE_MAIN_VARIANT (fileptr_type_node) == ptr_type_node);
1223 /* Likewise for const struct tm*. */
1224 gcc_assert (const_tm_ptr_type_node == const_ptr_type_node);
1225 gcc_assert (TYPE_MAIN_VARIANT (const_tm_ptr_type_node)
1226 == const_ptr_type_node);
1228 lto_build_c_type_nodes ();
1229 gcc_assert (va_list_type_node);
1231 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1233 tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
1234 lto_define_builtins (x, x);
1236 else
1238 lto_define_builtins (build_reference_type (va_list_type_node),
1239 va_list_type_node);
1242 if (flag_cilkplus)
1243 cilk_init_builtins ();
1245 targetm.init_builtins ();
1246 build_common_builtin_nodes ();
1248 /* Assign names to the builtin types, otherwise they'll end up
1249 as __unknown__ in debug info.
1250 ??? We simply need to stop pre-seeding the streamer cache.
1251 Below is modeled after from c-common.c:c_common_nodes_and_builtins */
1252 #define NAME_TYPE(t,n) \
1253 if (t) \
1254 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \
1255 get_identifier (n), t)
1256 NAME_TYPE (integer_type_node, "int");
1257 NAME_TYPE (char_type_node, "char");
1258 NAME_TYPE (long_integer_type_node, "long int");
1259 NAME_TYPE (unsigned_type_node, "unsigned int");
1260 NAME_TYPE (long_unsigned_type_node, "long unsigned int");
1261 NAME_TYPE (long_long_integer_type_node, "long long int");
1262 NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int");
1263 NAME_TYPE (short_integer_type_node, "short int");
1264 NAME_TYPE (short_unsigned_type_node, "short unsigned int");
1265 if (signed_char_type_node != char_type_node)
1266 NAME_TYPE (signed_char_type_node, "signed char");
1267 if (unsigned_char_type_node != char_type_node)
1268 NAME_TYPE (unsigned_char_type_node, "unsigned char");
1269 NAME_TYPE (float_type_node, "float");
1270 NAME_TYPE (double_type_node, "double");
1271 NAME_TYPE (long_double_type_node, "long double");
1272 NAME_TYPE (void_type_node, "void");
1273 NAME_TYPE (boolean_type_node, "bool");
1274 NAME_TYPE (complex_float_type_node, "complex float");
1275 NAME_TYPE (complex_double_type_node, "complex double");
1276 NAME_TYPE (complex_long_double_type_node, "complex long double");
1277 for (i = 0; i < NUM_INT_N_ENTS; i++)
1278 if (int_n_enabled_p[i])
1280 char name[50];
1281 sprintf (name, "__int%d", int_n_data[i].bitsize);
1282 NAME_TYPE (int_n_trees[i].signed_type, name);
1284 #undef NAME_TYPE
1286 /* Initialize LTO-specific data structures. */
1287 in_lto_p = true;
1289 return true;
1292 /* Initialize tree structures required by the LTO front end. */
1294 static void lto_init_ts (void)
1296 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1299 #undef LANG_HOOKS_NAME
1300 #define LANG_HOOKS_NAME "GNU GIMPLE"
1301 #undef LANG_HOOKS_OPTION_LANG_MASK
1302 #define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
1303 #undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
1304 #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
1305 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1306 #define LANG_HOOKS_INIT_OPTIONS_STRUCT lto_init_options_struct
1307 #undef LANG_HOOKS_HANDLE_OPTION
1308 #define LANG_HOOKS_HANDLE_OPTION lto_handle_option
1309 #undef LANG_HOOKS_POST_OPTIONS
1310 #define LANG_HOOKS_POST_OPTIONS lto_post_options
1311 #undef LANG_HOOKS_GET_ALIAS_SET
1312 #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
1313 #undef LANG_HOOKS_TYPE_FOR_MODE
1314 #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
1315 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
1316 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
1317 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1318 #define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
1319 #undef LANG_HOOKS_PUSHDECL
1320 #define LANG_HOOKS_PUSHDECL lto_pushdecl
1321 #undef LANG_HOOKS_GETDECLS
1322 #define LANG_HOOKS_GETDECLS lto_getdecls
1323 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1324 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
1325 #undef LANG_HOOKS_BUILTIN_FUNCTION
1326 #define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
1327 #undef LANG_HOOKS_INIT
1328 #define LANG_HOOKS_INIT lto_init
1329 #undef LANG_HOOKS_PARSE_FILE
1330 #define LANG_HOOKS_PARSE_FILE lto_main
1331 #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
1332 #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
1333 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1334 #define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
1335 #undef LANG_HOOKS_EH_PERSONALITY
1336 #define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
1338 /* Attribute hooks. */
1339 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1340 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
1341 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
1342 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
1344 #undef LANG_HOOKS_BEGIN_SECTION
1345 #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
1346 #undef LANG_HOOKS_APPEND_DATA
1347 #define LANG_HOOKS_APPEND_DATA lto_obj_append_data
1348 #undef LANG_HOOKS_END_SECTION
1349 #define LANG_HOOKS_END_SECTION lto_obj_end_section
1351 #undef LANG_HOOKS_INIT_TS
1352 #define LANG_HOOKS_INIT_TS lto_init_ts
1354 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1356 /* Language hooks that are not part of lang_hooks. */
1358 tree
1359 convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1361 gcc_unreachable ();
1364 /* Tree walking support. */
1366 static enum lto_tree_node_structure_enum
1367 lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
1369 return TS_LTO_GENERIC;
1372 #include "gtype-lto.h"
1373 #include "gt-lto-lto-lang.h"