tree-core.h: Include symtab.h.
[official-gcc.git] / gcc / lto / lto-lang.c
blob3e878527fb2d5f27ccd19c759587947a0c6c3a9a
1 /* Language-dependent hooks for LTO.
2 Copyright (C) 2009-2015 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 "flags.h"
25 #include "tm.h"
26 #include "function.h"
27 #include "predict.h"
28 #include "basic-block.h"
29 #include "tree.h"
30 #include "gimple.h"
31 #include "hard-reg-set.h"
32 #include "alias.h"
33 #include "fold-const.h"
34 #include "stringpool.h"
35 #include "stor-layout.h"
36 #include "target.h"
37 #include "langhooks.h"
38 #include "langhooks-def.h"
39 #include "debug.h"
40 #include "lto-tree.h"
41 #include "lto.h"
42 #include "tree-inline.h"
43 #include "internal-fn.h"
44 #include "diagnostic-core.h"
45 #include "toplev.h"
46 #include "cgraph.h"
47 #include "lto-streamer.h"
48 #include "cilk.h"
50 static tree lto_type_for_size (unsigned, int);
52 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
53 static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
54 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
55 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
56 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
57 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
58 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
59 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
60 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
61 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
62 static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool *);
63 static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
64 static tree ignore_attribute (tree *, tree, tree, int, bool *);
66 static tree handle_format_attribute (tree *, tree, tree, int, bool *);
67 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
68 static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
70 /* Table of machine-independent attributes supported in GIMPLE. */
71 const struct attribute_spec lto_attribute_table[] =
73 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
74 do_diagnostic } */
75 { "noreturn", 0, 0, true, false, false,
76 handle_noreturn_attribute, false },
77 { "leaf", 0, 0, true, false, false,
78 handle_leaf_attribute, false },
79 /* The same comments as for noreturn attributes apply to const ones. */
80 { "const", 0, 0, true, false, false,
81 handle_const_attribute, false },
82 { "malloc", 0, 0, true, false, false,
83 handle_malloc_attribute, false },
84 { "pure", 0, 0, true, false, false,
85 handle_pure_attribute, false },
86 { "no vops", 0, 0, true, false, false,
87 handle_novops_attribute, false },
88 { "nonnull", 0, -1, false, true, true,
89 handle_nonnull_attribute, false },
90 { "nothrow", 0, 0, true, false, false,
91 handle_nothrow_attribute, false },
92 { "returns_twice", 0, 0, true, false, false,
93 handle_returns_twice_attribute, false },
94 { "sentinel", 0, 1, false, true, true,
95 handle_sentinel_attribute, false },
96 { "type generic", 0, 0, false, true, true,
97 handle_type_generic_attribute, false },
98 { "fn spec", 1, 1, false, true, true,
99 handle_fnspec_attribute, false },
100 { "transaction_pure", 0, 0, false, true, true,
101 handle_transaction_pure_attribute, false },
102 /* For internal use only. The leading '*' both prevents its usage in
103 source code and signals that it may be overridden by machine tables. */
104 { "*tm regparm", 0, 0, false, true, true,
105 ignore_attribute, false },
106 { NULL, 0, 0, false, false, false, NULL, false }
109 /* Give the specifications for the format attributes, used by C and all
110 descendants. */
112 const struct attribute_spec lto_format_attribute_table[] =
114 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
115 affects_type_identity } */
116 { "format", 3, 3, false, true, true,
117 handle_format_attribute, false },
118 { "format_arg", 1, 1, false, true, true,
119 handle_format_arg_attribute, false },
120 { NULL, 0, 0, false, false, false, NULL, false }
123 enum built_in_attribute
125 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
126 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
127 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
128 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
129 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
130 #include "builtin-attrs.def"
131 #undef DEF_ATTR_NULL_TREE
132 #undef DEF_ATTR_INT
133 #undef DEF_ATTR_STRING
134 #undef DEF_ATTR_IDENT
135 #undef DEF_ATTR_TREE_LIST
136 ATTR_LAST
139 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
141 /* Builtin types. */
143 enum lto_builtin_type
145 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
146 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
147 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
148 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
149 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
150 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
151 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
152 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
153 ARG6) NAME,
154 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
155 ARG6, ARG7) NAME,
156 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
157 ARG6, ARG7, ARG8) 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_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
166 ARG6, ARG7) NAME,
167 #define DEF_FUNCTION_TYPE_VAR_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
168 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) 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_VAR_0
182 #undef DEF_FUNCTION_TYPE_VAR_1
183 #undef DEF_FUNCTION_TYPE_VAR_2
184 #undef DEF_FUNCTION_TYPE_VAR_3
185 #undef DEF_FUNCTION_TYPE_VAR_4
186 #undef DEF_FUNCTION_TYPE_VAR_5
187 #undef DEF_FUNCTION_TYPE_VAR_7
188 #undef DEF_FUNCTION_TYPE_VAR_11
189 #undef DEF_POINTER_TYPE
190 BT_LAST
193 typedef enum lto_builtin_type builtin_type;
195 static GTY(()) tree builtin_types[(int) BT_LAST + 1];
197 static GTY(()) tree string_type_node;
198 static GTY(()) tree const_string_type_node;
199 static GTY(()) tree wint_type_node;
200 static GTY(()) tree intmax_type_node;
201 static GTY(()) tree uintmax_type_node;
202 static GTY(()) tree signed_size_type_node;
204 /* Flags needed to process builtins.def. */
205 int flag_isoc94;
206 int flag_isoc99;
207 int flag_isoc11;
209 /* Attribute handlers. */
211 /* Handle a "noreturn" attribute; arguments as in
212 struct attribute_spec.handler. */
214 static tree
215 handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
216 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
217 bool * ARG_UNUSED (no_add_attrs))
219 tree type = TREE_TYPE (*node);
221 if (TREE_CODE (*node) == FUNCTION_DECL)
222 TREE_THIS_VOLATILE (*node) = 1;
223 else if (TREE_CODE (type) == POINTER_TYPE
224 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
225 TREE_TYPE (*node)
226 = build_pointer_type
227 (build_type_variant (TREE_TYPE (type),
228 TYPE_READONLY (TREE_TYPE (type)), 1));
229 else
230 gcc_unreachable ();
232 return NULL_TREE;
235 /* Handle a "leaf" attribute; arguments as in
236 struct attribute_spec.handler. */
238 static tree
239 handle_leaf_attribute (tree *node, tree name,
240 tree ARG_UNUSED (args),
241 int ARG_UNUSED (flags), bool *no_add_attrs)
243 if (TREE_CODE (*node) != FUNCTION_DECL)
245 warning (OPT_Wattributes, "%qE attribute ignored", name);
246 *no_add_attrs = true;
248 if (!TREE_PUBLIC (*node))
250 warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
251 *no_add_attrs = true;
254 return NULL_TREE;
257 /* Handle a "const" attribute; arguments as in
258 struct attribute_spec.handler. */
260 static tree
261 handle_const_attribute (tree *node, tree ARG_UNUSED (name),
262 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
263 bool * ARG_UNUSED (no_add_attrs))
265 tree type = TREE_TYPE (*node);
267 /* See FIXME comment on noreturn in c_common_attribute_table. */
268 if (TREE_CODE (*node) == FUNCTION_DECL)
269 TREE_READONLY (*node) = 1;
270 else if (TREE_CODE (type) == POINTER_TYPE
271 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
272 TREE_TYPE (*node)
273 = build_pointer_type
274 (build_type_variant (TREE_TYPE (type), 1,
275 TREE_THIS_VOLATILE (TREE_TYPE (type))));
276 else
277 gcc_unreachable ();
279 return NULL_TREE;
283 /* Handle a "malloc" attribute; arguments as in
284 struct attribute_spec.handler. */
286 static tree
287 handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
288 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
289 bool * ARG_UNUSED (no_add_attrs))
291 if (TREE_CODE (*node) == FUNCTION_DECL
292 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
293 DECL_IS_MALLOC (*node) = 1;
294 else
295 gcc_unreachable ();
297 return NULL_TREE;
301 /* Handle a "pure" attribute; arguments as in
302 struct attribute_spec.handler. */
304 static tree
305 handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
306 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
307 bool * ARG_UNUSED (no_add_attrs))
309 if (TREE_CODE (*node) == FUNCTION_DECL)
310 DECL_PURE_P (*node) = 1;
311 else
312 gcc_unreachable ();
314 return NULL_TREE;
318 /* Handle a "no vops" attribute; arguments as in
319 struct attribute_spec.handler. */
321 static tree
322 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
323 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
324 bool *ARG_UNUSED (no_add_attrs))
326 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
327 DECL_IS_NOVOPS (*node) = 1;
328 return NULL_TREE;
332 /* Helper for nonnull attribute handling; fetch the operand number
333 from the attribute argument list. */
335 static bool
336 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
338 /* Verify the arg number is a constant. */
339 if (!tree_fits_uhwi_p (arg_num_expr))
340 return false;
342 *valp = TREE_INT_CST_LOW (arg_num_expr);
343 return true;
346 /* Handle the "nonnull" attribute. */
348 static tree
349 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
350 tree args, int ARG_UNUSED (flags),
351 bool * ARG_UNUSED (no_add_attrs))
353 tree type = *node;
355 /* If no arguments are specified, all pointer arguments should be
356 non-null. Verify a full prototype is given so that the arguments
357 will have the correct types when we actually check them later. */
358 if (!args)
360 gcc_assert (prototype_p (type));
361 return NULL_TREE;
364 /* Argument list specified. Verify that each argument number references
365 a pointer argument. */
366 for (; args; args = TREE_CHAIN (args))
368 tree argument;
369 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
371 if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
372 gcc_unreachable ();
374 argument = TYPE_ARG_TYPES (type);
375 if (argument)
377 for (ck_num = 1; ; ck_num++)
379 if (!argument || ck_num == arg_num)
380 break;
381 argument = TREE_CHAIN (argument);
384 gcc_assert (argument
385 && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
389 return NULL_TREE;
393 /* Handle a "nothrow" attribute; arguments as in
394 struct attribute_spec.handler. */
396 static tree
397 handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
398 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
399 bool * ARG_UNUSED (no_add_attrs))
401 if (TREE_CODE (*node) == FUNCTION_DECL)
402 TREE_NOTHROW (*node) = 1;
403 else
404 gcc_unreachable ();
406 return NULL_TREE;
410 /* Handle a "sentinel" attribute. */
412 static tree
413 handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
414 int ARG_UNUSED (flags),
415 bool * ARG_UNUSED (no_add_attrs))
417 gcc_assert (stdarg_p (*node));
419 if (args)
421 tree position = TREE_VALUE (args);
422 gcc_assert (TREE_CODE (position) == INTEGER_CST);
423 if (tree_int_cst_lt (position, integer_zero_node))
424 gcc_unreachable ();
427 return NULL_TREE;
430 /* Handle a "type_generic" attribute. */
432 static tree
433 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
434 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
435 bool * ARG_UNUSED (no_add_attrs))
437 /* Ensure we have a function type. */
438 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
440 /* Ensure we have a variadic function. */
441 gcc_assert (!prototype_p (*node) || stdarg_p (*node));
443 return NULL_TREE;
446 /* Handle a "transaction_pure" attribute. */
448 static tree
449 handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
450 tree ARG_UNUSED (args),
451 int ARG_UNUSED (flags),
452 bool * ARG_UNUSED (no_add_attrs))
454 /* Ensure we have a function type. */
455 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
457 return NULL_TREE;
460 /* Handle a "returns_twice" attribute. */
462 static tree
463 handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name),
464 tree ARG_UNUSED (args),
465 int ARG_UNUSED (flags),
466 bool * ARG_UNUSED (no_add_attrs))
468 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
470 DECL_IS_RETURNS_TWICE (*node) = 1;
472 return NULL_TREE;
475 /* Ignore the given attribute. Used when this attribute may be usefully
476 overridden by the target, but is not used generically. */
478 static tree
479 ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
480 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
481 bool *no_add_attrs)
483 *no_add_attrs = true;
484 return NULL_TREE;
487 /* Handle a "format" attribute; arguments as in
488 struct attribute_spec.handler. */
490 static tree
491 handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
492 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
493 bool *no_add_attrs)
495 *no_add_attrs = true;
496 return NULL_TREE;
500 /* Handle a "format_arg" attribute; arguments as in
501 struct attribute_spec.handler. */
503 tree
504 handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
505 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
506 bool *no_add_attrs)
508 *no_add_attrs = true;
509 return NULL_TREE;
513 /* Handle a "fn spec" attribute; arguments as in
514 struct attribute_spec.handler. */
516 static tree
517 handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
518 tree args, int ARG_UNUSED (flags),
519 bool *no_add_attrs ATTRIBUTE_UNUSED)
521 gcc_assert (args
522 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
523 && !TREE_CHAIN (args));
524 return NULL_TREE;
527 /* Cribbed from c-common.c. */
529 static void
530 def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
532 tree t;
533 tree *args = XALLOCAVEC (tree, n);
534 va_list list;
535 int i;
536 bool err = false;
538 va_start (list, n);
539 for (i = 0; i < n; ++i)
541 builtin_type a = (builtin_type) va_arg (list, int);
542 t = builtin_types[a];
543 if (t == error_mark_node)
544 err = true;
545 args[i] = t;
547 va_end (list);
549 t = builtin_types[ret];
550 if (err)
551 t = error_mark_node;
552 if (t == error_mark_node)
554 else if (var)
555 t = build_varargs_function_type_array (t, n, args);
556 else
557 t = build_function_type_array (t, n, args);
559 builtin_types[def] = t;
562 /* Used to help initialize the builtin-types.def table. When a type of
563 the correct size doesn't exist, use error_mark_node instead of NULL.
564 The later results in segfaults even when a decl using the type doesn't
565 get invoked. */
567 static tree
568 builtin_type_for_size (int size, bool unsignedp)
570 tree type = lto_type_for_size (size, unsignedp);
571 return type ? type : error_mark_node;
574 /* Support for DEF_BUILTIN. */
576 static void
577 def_builtin_1 (enum built_in_function fncode, const char *name,
578 enum built_in_class fnclass, tree fntype, tree libtype,
579 bool both_p, bool fallback_p, bool nonansi_p,
580 tree fnattrs, bool implicit_p)
582 tree decl;
583 const char *libname;
585 if (fntype == error_mark_node)
586 return;
588 libname = name + strlen ("__builtin_");
589 decl = add_builtin_function (name, fntype, fncode, fnclass,
590 (fallback_p ? libname : NULL),
591 fnattrs);
593 if (both_p
594 && !flag_no_builtin
595 && !(nonansi_p && flag_no_nonansi_builtin))
596 add_builtin_function (libname, libtype, fncode, fnclass,
597 NULL, fnattrs);
599 set_builtin_decl (fncode, decl, implicit_p);
603 /* Initialize the attribute table for all the supported builtins. */
605 static void
606 lto_init_attributes (void)
608 /* Fill in the built_in_attributes array. */
609 #define DEF_ATTR_NULL_TREE(ENUM) \
610 built_in_attributes[(int) ENUM] = NULL_TREE;
611 #define DEF_ATTR_INT(ENUM, VALUE) \
612 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
613 #define DEF_ATTR_STRING(ENUM, VALUE) \
614 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
615 #define DEF_ATTR_IDENT(ENUM, STRING) \
616 built_in_attributes[(int) ENUM] = get_identifier (STRING);
617 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
618 built_in_attributes[(int) ENUM] \
619 = tree_cons (built_in_attributes[(int) PURPOSE], \
620 built_in_attributes[(int) VALUE], \
621 built_in_attributes[(int) CHAIN]);
622 #include "builtin-attrs.def"
623 #undef DEF_ATTR_NULL_TREE
624 #undef DEF_ATTR_INT
625 #undef DEF_ATTR_STRING
626 #undef DEF_ATTR_IDENT
627 #undef DEF_ATTR_TREE_LIST
630 /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
631 VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
633 static void
634 lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
635 tree va_list_arg_type_node ATTRIBUTE_UNUSED)
637 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
638 builtin_types[ENUM] = VALUE;
639 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
640 def_fn_type (ENUM, RETURN, 0, 0);
641 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
642 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
643 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
644 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
645 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
646 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
647 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
648 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
649 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
650 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
651 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
652 ARG6) \
653 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
654 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
655 ARG6, ARG7) \
656 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
657 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
658 ARG6, ARG7, ARG8) \
659 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
660 ARG7, ARG8);
661 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
662 def_fn_type (ENUM, RETURN, 1, 0);
663 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
664 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
665 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
666 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
667 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
668 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
669 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
670 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
671 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
672 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
673 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
674 ARG6, ARG7) \
675 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
676 #define DEF_FUNCTION_TYPE_VAR_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
677 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
678 def_fn_type (ENUM, RETURN, 1, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
679 ARG7, ARG8, ARG9, ARG10, ARG11);
680 #define DEF_POINTER_TYPE(ENUM, TYPE) \
681 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
683 #include "builtin-types.def"
685 #undef DEF_PRIMITIVE_TYPE
686 #undef DEF_FUNCTION_TYPE_0
687 #undef DEF_FUNCTION_TYPE_1
688 #undef DEF_FUNCTION_TYPE_2
689 #undef DEF_FUNCTION_TYPE_3
690 #undef DEF_FUNCTION_TYPE_4
691 #undef DEF_FUNCTION_TYPE_5
692 #undef DEF_FUNCTION_TYPE_6
693 #undef DEF_FUNCTION_TYPE_7
694 #undef DEF_FUNCTION_TYPE_8
695 #undef DEF_FUNCTION_TYPE_VAR_0
696 #undef DEF_FUNCTION_TYPE_VAR_1
697 #undef DEF_FUNCTION_TYPE_VAR_2
698 #undef DEF_FUNCTION_TYPE_VAR_3
699 #undef DEF_FUNCTION_TYPE_VAR_4
700 #undef DEF_FUNCTION_TYPE_VAR_5
701 #undef DEF_FUNCTION_TYPE_VAR_7
702 #undef DEF_FUNCTION_TYPE_VAR_11
703 #undef DEF_POINTER_TYPE
704 builtin_types[(int) BT_LAST] = NULL_TREE;
706 lto_init_attributes ();
708 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
709 NONANSI_P, ATTRS, IMPLICIT, COND) \
710 if (NAME && COND) \
711 def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
712 builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
713 NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
714 #include "builtins.def"
715 #undef DEF_BUILTIN
718 static GTY(()) tree registered_builtin_types;
720 /* Language hooks. */
722 static unsigned int
723 lto_option_lang_mask (void)
725 return CL_LTO;
728 static bool
729 lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
731 /* The LTO front end inherits all the options from the first front
732 end that was used. However, not all the original front end
733 options make sense in LTO.
735 A real solution would be to filter this in collect2, but collect2
736 does not have access to all the option attributes to know what to
737 filter. So, in lto1 we silently accept inherited flags and do
738 nothing about it. */
739 return false;
742 static void
743 lto_init_options_struct (struct gcc_options *opts)
745 /* By default, C99-like requirements for complex multiply and divide.
746 ??? Until the complex method is encoded in the IL this is the only
747 safe choice. This will pessimize Fortran code with LTO unless
748 people specify a complex method manually or use -ffast-math. */
749 opts->x_flag_complex_method = 2;
752 /* Handle command-line option SCODE. If the option takes an argument, it is
753 stored in ARG, which is otherwise NULL. VALUE holds either a numerical
754 argument or a binary value indicating whether the positive or negative form
755 of the option was supplied. */
757 const char *resolution_file_name;
758 static bool
759 lto_handle_option (size_t scode, const char *arg,
760 int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
761 location_t loc ATTRIBUTE_UNUSED,
762 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
764 enum opt_code code = (enum opt_code) scode;
765 bool result = true;
767 switch (code)
769 case OPT_fresolution_:
770 resolution_file_name = arg;
771 break;
773 case OPT_Wabi:
774 warn_psabi = value;
775 break;
777 case OPT_fwpa:
778 flag_wpa = value ? "" : NULL;
779 break;
781 default:
782 break;
785 return result;
788 /* Perform post-option processing. Does additional initialization based on
789 command-line options. PFILENAME is the main input filename. Returns false
790 to enable subsequent back-end initialization. */
792 static bool
793 lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
795 /* -fltrans and -fwpa are mutually exclusive. Check for that here. */
796 if (flag_wpa && flag_ltrans)
797 error ("-fwpa and -fltrans are mutually exclusive");
799 if (flag_ltrans)
801 flag_generate_lto = 0;
803 /* During LTRANS, we are not looking at the whole program, only
804 a subset of the whole callgraph. */
805 flag_whole_program = 0;
808 if (flag_wpa)
809 flag_generate_lto = 1;
811 /* Excess precision other than "fast" requires front-end
812 support. */
813 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
815 /* Initialize the compiler back end. */
816 return false;
819 /* Return an integer type with PRECISION bits of precision,
820 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
822 static tree
823 lto_type_for_size (unsigned precision, int unsignedp)
825 int i;
827 if (precision == TYPE_PRECISION (integer_type_node))
828 return unsignedp ? unsigned_type_node : integer_type_node;
830 if (precision == TYPE_PRECISION (signed_char_type_node))
831 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
833 if (precision == TYPE_PRECISION (short_integer_type_node))
834 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
836 if (precision == TYPE_PRECISION (long_integer_type_node))
837 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
839 if (precision == TYPE_PRECISION (long_long_integer_type_node))
840 return unsignedp
841 ? long_long_unsigned_type_node
842 : long_long_integer_type_node;
844 for (i = 0; i < NUM_INT_N_ENTS; i ++)
845 if (int_n_enabled_p[i]
846 && precision == int_n_data[i].bitsize)
847 return (unsignedp ? int_n_trees[i].unsigned_type
848 : int_n_trees[i].signed_type);
850 if (precision <= TYPE_PRECISION (intQI_type_node))
851 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
853 if (precision <= TYPE_PRECISION (intHI_type_node))
854 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
856 if (precision <= TYPE_PRECISION (intSI_type_node))
857 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
859 if (precision <= TYPE_PRECISION (intDI_type_node))
860 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
862 if (precision <= TYPE_PRECISION (intTI_type_node))
863 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
865 return NULL_TREE;
869 /* Return a data type that has machine mode MODE.
870 If the mode is an integer,
871 then UNSIGNEDP selects between signed and unsigned types.
872 If the mode is a fixed-point mode,
873 then UNSIGNEDP selects between saturating and nonsaturating types. */
875 static tree
876 lto_type_for_mode (machine_mode mode, int unsigned_p)
878 tree t;
879 int i;
881 if (mode == TYPE_MODE (integer_type_node))
882 return unsigned_p ? unsigned_type_node : integer_type_node;
884 if (mode == TYPE_MODE (signed_char_type_node))
885 return unsigned_p ? unsigned_char_type_node : signed_char_type_node;
887 if (mode == TYPE_MODE (short_integer_type_node))
888 return unsigned_p ? short_unsigned_type_node : short_integer_type_node;
890 if (mode == TYPE_MODE (long_integer_type_node))
891 return unsigned_p ? long_unsigned_type_node : long_integer_type_node;
893 if (mode == TYPE_MODE (long_long_integer_type_node))
894 return unsigned_p ? long_long_unsigned_type_node : long_long_integer_type_node;
896 for (i = 0; i < NUM_INT_N_ENTS; i ++)
897 if (int_n_enabled_p[i]
898 && mode == int_n_data[i].m)
899 return (unsigned_p ? int_n_trees[i].unsigned_type
900 : int_n_trees[i].signed_type);
902 if (mode == QImode)
903 return unsigned_p ? unsigned_intQI_type_node : intQI_type_node;
905 if (mode == HImode)
906 return unsigned_p ? unsigned_intHI_type_node : intHI_type_node;
908 if (mode == SImode)
909 return unsigned_p ? unsigned_intSI_type_node : intSI_type_node;
911 if (mode == DImode)
912 return unsigned_p ? unsigned_intDI_type_node : intDI_type_node;
914 #if HOST_BITS_PER_WIDE_INT >= 64
915 if (mode == TYPE_MODE (intTI_type_node))
916 return unsigned_p ? unsigned_intTI_type_node : intTI_type_node;
917 #endif
919 if (mode == TYPE_MODE (float_type_node))
920 return float_type_node;
922 if (mode == TYPE_MODE (double_type_node))
923 return double_type_node;
925 if (mode == TYPE_MODE (long_double_type_node))
926 return long_double_type_node;
928 if (mode == TYPE_MODE (void_type_node))
929 return void_type_node;
931 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
932 return (unsigned_p
933 ? make_unsigned_type (GET_MODE_PRECISION (mode))
934 : make_signed_type (GET_MODE_PRECISION (mode)));
936 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
937 return (unsigned_p
938 ? make_unsigned_type (GET_MODE_PRECISION (mode))
939 : make_signed_type (GET_MODE_PRECISION (mode)));
941 if (COMPLEX_MODE_P (mode))
943 machine_mode inner_mode;
944 tree inner_type;
946 if (mode == TYPE_MODE (complex_float_type_node))
947 return complex_float_type_node;
948 if (mode == TYPE_MODE (complex_double_type_node))
949 return complex_double_type_node;
950 if (mode == TYPE_MODE (complex_long_double_type_node))
951 return complex_long_double_type_node;
953 if (mode == TYPE_MODE (complex_integer_type_node) && !unsigned_p)
954 return complex_integer_type_node;
956 inner_mode = GET_MODE_INNER (mode);
957 inner_type = lto_type_for_mode (inner_mode, unsigned_p);
958 if (inner_type != NULL_TREE)
959 return build_complex_type (inner_type);
961 else if (VECTOR_MODE_P (mode))
963 machine_mode inner_mode = GET_MODE_INNER (mode);
964 tree inner_type = lto_type_for_mode (inner_mode, unsigned_p);
965 if (inner_type != NULL_TREE)
966 return build_vector_type_for_mode (inner_type, mode);
969 if (mode == TYPE_MODE (dfloat32_type_node))
970 return dfloat32_type_node;
971 if (mode == TYPE_MODE (dfloat64_type_node))
972 return dfloat64_type_node;
973 if (mode == TYPE_MODE (dfloat128_type_node))
974 return dfloat128_type_node;
976 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
978 if (mode == TYPE_MODE (short_fract_type_node))
979 return unsigned_p ? sat_short_fract_type_node : short_fract_type_node;
980 if (mode == TYPE_MODE (fract_type_node))
981 return unsigned_p ? sat_fract_type_node : fract_type_node;
982 if (mode == TYPE_MODE (long_fract_type_node))
983 return unsigned_p ? sat_long_fract_type_node : long_fract_type_node;
984 if (mode == TYPE_MODE (long_long_fract_type_node))
985 return unsigned_p ? sat_long_long_fract_type_node
986 : long_long_fract_type_node;
988 if (mode == TYPE_MODE (unsigned_short_fract_type_node))
989 return unsigned_p ? sat_unsigned_short_fract_type_node
990 : unsigned_short_fract_type_node;
991 if (mode == TYPE_MODE (unsigned_fract_type_node))
992 return unsigned_p ? sat_unsigned_fract_type_node
993 : unsigned_fract_type_node;
994 if (mode == TYPE_MODE (unsigned_long_fract_type_node))
995 return unsigned_p ? sat_unsigned_long_fract_type_node
996 : unsigned_long_fract_type_node;
997 if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
998 return unsigned_p ? sat_unsigned_long_long_fract_type_node
999 : unsigned_long_long_fract_type_node;
1001 if (mode == TYPE_MODE (short_accum_type_node))
1002 return unsigned_p ? sat_short_accum_type_node : short_accum_type_node;
1003 if (mode == TYPE_MODE (accum_type_node))
1004 return unsigned_p ? sat_accum_type_node : accum_type_node;
1005 if (mode == TYPE_MODE (long_accum_type_node))
1006 return unsigned_p ? sat_long_accum_type_node : long_accum_type_node;
1007 if (mode == TYPE_MODE (long_long_accum_type_node))
1008 return unsigned_p ? sat_long_long_accum_type_node
1009 : long_long_accum_type_node;
1011 if (mode == TYPE_MODE (unsigned_short_accum_type_node))
1012 return unsigned_p ? sat_unsigned_short_accum_type_node
1013 : unsigned_short_accum_type_node;
1014 if (mode == TYPE_MODE (unsigned_accum_type_node))
1015 return unsigned_p ? sat_unsigned_accum_type_node
1016 : unsigned_accum_type_node;
1017 if (mode == TYPE_MODE (unsigned_long_accum_type_node))
1018 return unsigned_p ? sat_unsigned_long_accum_type_node
1019 : unsigned_long_accum_type_node;
1020 if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
1021 return unsigned_p ? sat_unsigned_long_long_accum_type_node
1022 : unsigned_long_long_accum_type_node;
1024 if (mode == QQmode)
1025 return unsigned_p ? sat_qq_type_node : qq_type_node;
1026 if (mode == HQmode)
1027 return unsigned_p ? sat_hq_type_node : hq_type_node;
1028 if (mode == SQmode)
1029 return unsigned_p ? sat_sq_type_node : sq_type_node;
1030 if (mode == DQmode)
1031 return unsigned_p ? sat_dq_type_node : dq_type_node;
1032 if (mode == TQmode)
1033 return unsigned_p ? sat_tq_type_node : tq_type_node;
1035 if (mode == UQQmode)
1036 return unsigned_p ? sat_uqq_type_node : uqq_type_node;
1037 if (mode == UHQmode)
1038 return unsigned_p ? sat_uhq_type_node : uhq_type_node;
1039 if (mode == USQmode)
1040 return unsigned_p ? sat_usq_type_node : usq_type_node;
1041 if (mode == UDQmode)
1042 return unsigned_p ? sat_udq_type_node : udq_type_node;
1043 if (mode == UTQmode)
1044 return unsigned_p ? sat_utq_type_node : utq_type_node;
1046 if (mode == HAmode)
1047 return unsigned_p ? sat_ha_type_node : ha_type_node;
1048 if (mode == SAmode)
1049 return unsigned_p ? sat_sa_type_node : sa_type_node;
1050 if (mode == DAmode)
1051 return unsigned_p ? sat_da_type_node : da_type_node;
1052 if (mode == TAmode)
1053 return unsigned_p ? sat_ta_type_node : ta_type_node;
1055 if (mode == UHAmode)
1056 return unsigned_p ? sat_uha_type_node : uha_type_node;
1057 if (mode == USAmode)
1058 return unsigned_p ? sat_usa_type_node : usa_type_node;
1059 if (mode == UDAmode)
1060 return unsigned_p ? sat_uda_type_node : uda_type_node;
1061 if (mode == UTAmode)
1062 return unsigned_p ? sat_uta_type_node : uta_type_node;
1065 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
1066 if (TYPE_MODE (TREE_VALUE (t)) == mode)
1067 return TREE_VALUE (t);
1069 return NULL_TREE;
1072 /* Return true if we are in the global binding level. */
1074 static bool
1075 lto_global_bindings_p (void)
1077 return cfun == NULL;
1080 static void
1081 lto_set_decl_assembler_name (tree decl)
1083 /* This is almost the same as lhd_set_decl_assembler_name, except that
1084 we need to uniquify file-scope names, even if they are not
1085 TREE_PUBLIC, to avoid conflicts between individual files. */
1086 tree id;
1088 if (TREE_PUBLIC (decl))
1089 id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
1090 else
1092 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1093 char *label;
1095 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
1096 id = get_identifier (label);
1099 SET_DECL_ASSEMBLER_NAME (decl, id);
1102 static tree
1103 lto_pushdecl (tree t ATTRIBUTE_UNUSED)
1105 /* Do nothing, since we get all information from DWARF and LTO
1106 sections. */
1107 return NULL_TREE;
1110 static tree
1111 lto_getdecls (void)
1113 /* We have our own write_globals langhook, hence the getdecls
1114 langhook shouldn't be used, except by dbxout.c, so we can't
1115 just abort here. */
1116 return NULL_TREE;
1119 static tree
1120 lto_builtin_function (tree decl)
1122 return decl;
1125 static void
1126 lto_register_builtin_type (tree type, const char *name)
1128 tree decl;
1130 if (!TYPE_NAME (type))
1132 decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
1133 get_identifier (name), type);
1134 DECL_ARTIFICIAL (decl) = 1;
1135 TYPE_NAME (type) = decl;
1138 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
1141 /* Build nodes that would have be created by the C front-end; necessary
1142 for including builtin-types.def and ultimately builtins.def. */
1144 static void
1145 lto_build_c_type_nodes (void)
1147 gcc_assert (void_type_node);
1149 void_list_node = build_tree_list (NULL_TREE, void_type_node);
1150 string_type_node = build_pointer_type (char_type_node);
1151 const_string_type_node
1152 = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
1154 if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1156 intmax_type_node = integer_type_node;
1157 uintmax_type_node = unsigned_type_node;
1158 signed_size_type_node = integer_type_node;
1160 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1162 intmax_type_node = long_integer_type_node;
1163 uintmax_type_node = long_unsigned_type_node;
1164 signed_size_type_node = long_integer_type_node;
1166 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1168 intmax_type_node = long_long_integer_type_node;
1169 uintmax_type_node = long_long_unsigned_type_node;
1170 signed_size_type_node = long_long_integer_type_node;
1172 else
1174 int i;
1176 signed_size_type_node = NULL_TREE;
1177 for (i = 0; i < NUM_INT_N_ENTS; i++)
1178 if (int_n_enabled_p[i])
1180 char name[50];
1181 sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
1183 if (strcmp (name, SIZE_TYPE) == 0)
1185 intmax_type_node = int_n_trees[i].signed_type;
1186 uintmax_type_node = int_n_trees[i].unsigned_type;
1187 signed_size_type_node = int_n_trees[i].signed_type;
1190 if (signed_size_type_node == NULL_TREE)
1191 gcc_unreachable ();
1194 wint_type_node = unsigned_type_node;
1195 pid_type_node = integer_type_node;
1198 /* Perform LTO-specific initialization. */
1200 static bool
1201 lto_init (void)
1203 int i;
1205 /* We need to generate LTO if running in WPA mode. */
1206 flag_generate_lto = (flag_wpa != NULL);
1208 /* Create the basic integer types. */
1209 build_common_tree_nodes (flag_signed_char, flag_short_double);
1211 /* The global tree for the main identifier is filled in by
1212 language-specific front-end initialization that is not run in the
1213 LTO back-end. It appears that all languages that perform such
1214 initialization currently do so in the same way, so we do it here. */
1215 if (main_identifier_node == NULL_TREE)
1216 main_identifier_node = get_identifier ("main");
1218 /* In the C++ front-end, fileptr_type_node is defined as a variant
1219 copy of of ptr_type_node, rather than ptr_node itself. The
1220 distinction should only be relevant to the front-end, so we
1221 always use the C definition here in lto1. */
1222 gcc_assert (fileptr_type_node == ptr_type_node);
1223 gcc_assert (TYPE_MAIN_VARIANT (fileptr_type_node) == ptr_type_node);
1225 ptrdiff_type_node = integer_type_node;
1227 lto_build_c_type_nodes ();
1228 gcc_assert (va_list_type_node);
1230 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1232 tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
1233 lto_define_builtins (x, x);
1235 else
1237 lto_define_builtins (build_reference_type (va_list_type_node),
1238 va_list_type_node);
1241 if (flag_cilkplus)
1242 cilk_init_builtins ();
1244 targetm.init_builtins ();
1245 build_common_builtin_nodes ();
1247 /* Assign names to the builtin types, otherwise they'll end up
1248 as __unknown__ in debug info.
1249 ??? We simply need to stop pre-seeding the streamer cache.
1250 Below is modeled after from c-common.c:c_common_nodes_and_builtins */
1251 #define NAME_TYPE(t,n) \
1252 if (t) \
1253 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \
1254 get_identifier (n), t)
1255 NAME_TYPE (integer_type_node, "int");
1256 NAME_TYPE (char_type_node, "char");
1257 NAME_TYPE (long_integer_type_node, "long int");
1258 NAME_TYPE (unsigned_type_node, "unsigned int");
1259 NAME_TYPE (long_unsigned_type_node, "long unsigned int");
1260 NAME_TYPE (long_long_integer_type_node, "long long int");
1261 NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int");
1262 NAME_TYPE (short_integer_type_node, "short int");
1263 NAME_TYPE (short_unsigned_type_node, "short unsigned int");
1264 if (signed_char_type_node != char_type_node)
1265 NAME_TYPE (signed_char_type_node, "signed char");
1266 if (unsigned_char_type_node != char_type_node)
1267 NAME_TYPE (unsigned_char_type_node, "unsigned char");
1268 NAME_TYPE (float_type_node, "float");
1269 NAME_TYPE (double_type_node, "double");
1270 NAME_TYPE (long_double_type_node, "long double");
1271 NAME_TYPE (void_type_node, "void");
1272 NAME_TYPE (boolean_type_node, "bool");
1273 NAME_TYPE (complex_float_type_node, "complex float");
1274 NAME_TYPE (complex_double_type_node, "complex double");
1275 NAME_TYPE (complex_long_double_type_node, "complex long double");
1276 for (i = 0; i < NUM_INT_N_ENTS; i++)
1277 if (int_n_enabled_p[i])
1279 char name[50];
1280 sprintf (name, "__int%d", int_n_data[i].bitsize);
1281 NAME_TYPE (int_n_trees[i].signed_type, name);
1283 #undef NAME_TYPE
1285 /* Initialize LTO-specific data structures. */
1286 in_lto_p = true;
1288 return true;
1291 /* Initialize tree structures required by the LTO front end. */
1293 static void lto_init_ts (void)
1295 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1298 #undef LANG_HOOKS_NAME
1299 #define LANG_HOOKS_NAME "GNU GIMPLE"
1300 #undef LANG_HOOKS_OPTION_LANG_MASK
1301 #define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
1302 #undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
1303 #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
1304 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1305 #define LANG_HOOKS_INIT_OPTIONS_STRUCT lto_init_options_struct
1306 #undef LANG_HOOKS_HANDLE_OPTION
1307 #define LANG_HOOKS_HANDLE_OPTION lto_handle_option
1308 #undef LANG_HOOKS_POST_OPTIONS
1309 #define LANG_HOOKS_POST_OPTIONS lto_post_options
1310 #undef LANG_HOOKS_GET_ALIAS_SET
1311 #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
1312 #undef LANG_HOOKS_TYPE_FOR_MODE
1313 #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
1314 #undef LANG_HOOKS_TYPE_FOR_SIZE
1315 #define LANG_HOOKS_TYPE_FOR_SIZE lto_type_for_size
1316 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
1317 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
1318 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1319 #define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
1320 #undef LANG_HOOKS_PUSHDECL
1321 #define LANG_HOOKS_PUSHDECL lto_pushdecl
1322 #undef LANG_HOOKS_GETDECLS
1323 #define LANG_HOOKS_GETDECLS lto_getdecls
1324 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1325 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
1326 #undef LANG_HOOKS_BUILTIN_FUNCTION
1327 #define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
1328 #undef LANG_HOOKS_INIT
1329 #define LANG_HOOKS_INIT lto_init
1330 #undef LANG_HOOKS_PARSE_FILE
1331 #define LANG_HOOKS_PARSE_FILE lto_main
1332 #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
1333 #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
1334 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1335 #define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
1336 #undef LANG_HOOKS_EH_PERSONALITY
1337 #define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
1339 /* Attribute hooks. */
1340 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1341 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
1342 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
1343 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
1345 #undef LANG_HOOKS_BEGIN_SECTION
1346 #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
1347 #undef LANG_HOOKS_APPEND_DATA
1348 #define LANG_HOOKS_APPEND_DATA lto_obj_append_data
1349 #undef LANG_HOOKS_END_SECTION
1350 #define LANG_HOOKS_END_SECTION lto_obj_end_section
1352 #undef LANG_HOOKS_INIT_TS
1353 #define LANG_HOOKS_INIT_TS lto_init_ts
1355 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1357 /* Language hooks that are not part of lang_hooks. */
1359 tree
1360 convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1362 gcc_unreachable ();
1365 /* Tree walking support. */
1367 static enum lto_tree_node_structure_enum
1368 lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
1370 return TS_LTO_GENERIC;
1373 #include "gtype-lto.h"
1374 #include "gt-lto-lto-lang.h"