/cp
[official-gcc.git] / gcc / lto / lto-lang.c
blob6d6a8538a8f70c83bec1c2334bd5454e028892b3
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 "tm.h"
25 #include "function.h"
26 #include "predict.h"
27 #include "basic-block.h"
28 #include "tree.h"
29 #include "gimple.h"
30 #include "hard-reg-set.h"
31 #include "alias.h"
32 #include "fold-const.h"
33 #include "stringpool.h"
34 #include "stor-layout.h"
35 #include "target.h"
36 #include "langhooks.h"
37 #include "langhooks-def.h"
38 #include "debug.h"
39 #include "lto-tree.h"
40 #include "lto.h"
41 #include "tree-inline.h"
42 #include "internal-fn.h"
43 #include "diagnostic-core.h"
44 #include "toplev.h"
45 #include "cgraph.h"
46 #include "cilk.h"
48 static tree lto_type_for_size (unsigned, int);
50 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
51 static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
52 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
53 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
54 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
55 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
56 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
57 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
58 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
59 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
60 static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool *);
61 static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
62 static tree ignore_attribute (tree *, tree, tree, int, bool *);
64 static tree handle_format_attribute (tree *, tree, tree, int, bool *);
65 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
66 static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
68 /* Table of machine-independent attributes supported in GIMPLE. */
69 const struct attribute_spec lto_attribute_table[] =
71 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
72 do_diagnostic } */
73 { "noreturn", 0, 0, true, false, false,
74 handle_noreturn_attribute, false },
75 { "leaf", 0, 0, true, false, false,
76 handle_leaf_attribute, false },
77 /* The same comments as for noreturn attributes apply to const ones. */
78 { "const", 0, 0, true, false, false,
79 handle_const_attribute, false },
80 { "malloc", 0, 0, true, false, false,
81 handle_malloc_attribute, false },
82 { "pure", 0, 0, true, false, false,
83 handle_pure_attribute, false },
84 { "no vops", 0, 0, true, false, false,
85 handle_novops_attribute, false },
86 { "nonnull", 0, -1, false, true, true,
87 handle_nonnull_attribute, false },
88 { "nothrow", 0, 0, true, false, false,
89 handle_nothrow_attribute, false },
90 { "returns_twice", 0, 0, true, false, false,
91 handle_returns_twice_attribute, false },
92 { "sentinel", 0, 1, false, true, true,
93 handle_sentinel_attribute, false },
94 { "type generic", 0, 0, false, true, true,
95 handle_type_generic_attribute, false },
96 { "fn spec", 1, 1, false, true, true,
97 handle_fnspec_attribute, false },
98 { "transaction_pure", 0, 0, false, true, true,
99 handle_transaction_pure_attribute, false },
100 /* For internal use only. The leading '*' both prevents its usage in
101 source code and signals that it may be overridden by machine tables. */
102 { "*tm regparm", 0, 0, false, true, true,
103 ignore_attribute, false },
104 { NULL, 0, 0, false, false, false, NULL, false }
107 /* Give the specifications for the format attributes, used by C and all
108 descendants. */
110 const struct attribute_spec lto_format_attribute_table[] =
112 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
113 affects_type_identity } */
114 { "format", 3, 3, false, true, true,
115 handle_format_attribute, false },
116 { "format_arg", 1, 1, false, true, true,
117 handle_format_arg_attribute, false },
118 { NULL, 0, 0, false, false, false, NULL, false }
121 enum built_in_attribute
123 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
124 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
125 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
126 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
127 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
128 #include "builtin-attrs.def"
129 #undef DEF_ATTR_NULL_TREE
130 #undef DEF_ATTR_INT
131 #undef DEF_ATTR_STRING
132 #undef DEF_ATTR_IDENT
133 #undef DEF_ATTR_TREE_LIST
134 ATTR_LAST
137 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
139 /* Builtin types. */
141 enum lto_builtin_type
143 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
144 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
145 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
146 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
147 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
148 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
149 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
150 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
151 ARG6) NAME,
152 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
153 ARG6, ARG7) NAME,
154 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
155 ARG6, ARG7, ARG8) NAME,
156 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
157 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
158 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
159 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
160 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
161 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
162 NAME,
163 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
164 ARG6, ARG7) NAME,
165 #define DEF_FUNCTION_TYPE_VAR_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
166 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
167 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
168 #include "builtin-types.def"
169 #undef DEF_PRIMITIVE_TYPE
170 #undef DEF_FUNCTION_TYPE_0
171 #undef DEF_FUNCTION_TYPE_1
172 #undef DEF_FUNCTION_TYPE_2
173 #undef DEF_FUNCTION_TYPE_3
174 #undef DEF_FUNCTION_TYPE_4
175 #undef DEF_FUNCTION_TYPE_5
176 #undef DEF_FUNCTION_TYPE_6
177 #undef DEF_FUNCTION_TYPE_7
178 #undef DEF_FUNCTION_TYPE_8
179 #undef DEF_FUNCTION_TYPE_VAR_0
180 #undef DEF_FUNCTION_TYPE_VAR_1
181 #undef DEF_FUNCTION_TYPE_VAR_2
182 #undef DEF_FUNCTION_TYPE_VAR_3
183 #undef DEF_FUNCTION_TYPE_VAR_4
184 #undef DEF_FUNCTION_TYPE_VAR_5
185 #undef DEF_FUNCTION_TYPE_VAR_7
186 #undef DEF_FUNCTION_TYPE_VAR_11
187 #undef DEF_POINTER_TYPE
188 BT_LAST
191 typedef enum lto_builtin_type builtin_type;
193 static GTY(()) tree builtin_types[(int) BT_LAST + 1];
195 static GTY(()) tree string_type_node;
196 static GTY(()) tree const_string_type_node;
197 static GTY(()) tree wint_type_node;
198 static GTY(()) tree intmax_type_node;
199 static GTY(()) tree uintmax_type_node;
200 static GTY(()) tree signed_size_type_node;
202 /* Flags needed to process builtins.def. */
203 int flag_isoc94;
204 int flag_isoc99;
205 int flag_isoc11;
207 /* Attribute handlers. */
209 /* Handle a "noreturn" attribute; arguments as in
210 struct attribute_spec.handler. */
212 static tree
213 handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
214 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
215 bool * ARG_UNUSED (no_add_attrs))
217 tree type = TREE_TYPE (*node);
219 if (TREE_CODE (*node) == FUNCTION_DECL)
220 TREE_THIS_VOLATILE (*node) = 1;
221 else if (TREE_CODE (type) == POINTER_TYPE
222 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
223 TREE_TYPE (*node)
224 = build_pointer_type
225 (build_type_variant (TREE_TYPE (type),
226 TYPE_READONLY (TREE_TYPE (type)), 1));
227 else
228 gcc_unreachable ();
230 return NULL_TREE;
233 /* Handle a "leaf" attribute; arguments as in
234 struct attribute_spec.handler. */
236 static tree
237 handle_leaf_attribute (tree *node, tree name,
238 tree ARG_UNUSED (args),
239 int ARG_UNUSED (flags), bool *no_add_attrs)
241 if (TREE_CODE (*node) != FUNCTION_DECL)
243 warning (OPT_Wattributes, "%qE attribute ignored", name);
244 *no_add_attrs = true;
246 if (!TREE_PUBLIC (*node))
248 warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
249 *no_add_attrs = true;
252 return NULL_TREE;
255 /* Handle a "const" attribute; arguments as in
256 struct attribute_spec.handler. */
258 static tree
259 handle_const_attribute (tree *node, tree ARG_UNUSED (name),
260 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
261 bool * ARG_UNUSED (no_add_attrs))
263 tree type = TREE_TYPE (*node);
265 /* See FIXME comment on noreturn in c_common_attribute_table. */
266 if (TREE_CODE (*node) == FUNCTION_DECL)
267 TREE_READONLY (*node) = 1;
268 else if (TREE_CODE (type) == POINTER_TYPE
269 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
270 TREE_TYPE (*node)
271 = build_pointer_type
272 (build_type_variant (TREE_TYPE (type), 1,
273 TREE_THIS_VOLATILE (TREE_TYPE (type))));
274 else
275 gcc_unreachable ();
277 return NULL_TREE;
281 /* Handle a "malloc" attribute; arguments as in
282 struct attribute_spec.handler. */
284 static tree
285 handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
286 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
287 bool * ARG_UNUSED (no_add_attrs))
289 if (TREE_CODE (*node) == FUNCTION_DECL
290 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
291 DECL_IS_MALLOC (*node) = 1;
292 else
293 gcc_unreachable ();
295 return NULL_TREE;
299 /* Handle a "pure" attribute; arguments as in
300 struct attribute_spec.handler. */
302 static tree
303 handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
304 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
305 bool * ARG_UNUSED (no_add_attrs))
307 if (TREE_CODE (*node) == FUNCTION_DECL)
308 DECL_PURE_P (*node) = 1;
309 else
310 gcc_unreachable ();
312 return NULL_TREE;
316 /* Handle a "no vops" attribute; arguments as in
317 struct attribute_spec.handler. */
319 static tree
320 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
321 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
322 bool *ARG_UNUSED (no_add_attrs))
324 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
325 DECL_IS_NOVOPS (*node) = 1;
326 return NULL_TREE;
330 /* Helper for nonnull attribute handling; fetch the operand number
331 from the attribute argument list. */
333 static bool
334 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
336 /* Verify the arg number is a constant. */
337 if (!tree_fits_uhwi_p (arg_num_expr))
338 return false;
340 *valp = TREE_INT_CST_LOW (arg_num_expr);
341 return true;
344 /* Handle the "nonnull" attribute. */
346 static tree
347 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
348 tree args, int ARG_UNUSED (flags),
349 bool * ARG_UNUSED (no_add_attrs))
351 tree type = *node;
353 /* If no arguments are specified, all pointer arguments should be
354 non-null. Verify a full prototype is given so that the arguments
355 will have the correct types when we actually check them later. */
356 if (!args)
358 gcc_assert (prototype_p (type));
359 return NULL_TREE;
362 /* Argument list specified. Verify that each argument number references
363 a pointer argument. */
364 for (; args; args = TREE_CHAIN (args))
366 tree argument;
367 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
369 if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
370 gcc_unreachable ();
372 argument = TYPE_ARG_TYPES (type);
373 if (argument)
375 for (ck_num = 1; ; ck_num++)
377 if (!argument || ck_num == arg_num)
378 break;
379 argument = TREE_CHAIN (argument);
382 gcc_assert (argument
383 && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
387 return NULL_TREE;
391 /* Handle a "nothrow" attribute; arguments as in
392 struct attribute_spec.handler. */
394 static tree
395 handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
396 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
397 bool * ARG_UNUSED (no_add_attrs))
399 if (TREE_CODE (*node) == FUNCTION_DECL)
400 TREE_NOTHROW (*node) = 1;
401 else
402 gcc_unreachable ();
404 return NULL_TREE;
408 /* Handle a "sentinel" attribute. */
410 static tree
411 handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
412 int ARG_UNUSED (flags),
413 bool * ARG_UNUSED (no_add_attrs))
415 gcc_assert (stdarg_p (*node));
417 if (args)
419 tree position = TREE_VALUE (args);
420 gcc_assert (TREE_CODE (position) == INTEGER_CST);
421 if (tree_int_cst_lt (position, integer_zero_node))
422 gcc_unreachable ();
425 return NULL_TREE;
428 /* Handle a "type_generic" attribute. */
430 static tree
431 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
432 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
433 bool * ARG_UNUSED (no_add_attrs))
435 /* Ensure we have a function type. */
436 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
438 /* Ensure we have a variadic function. */
439 gcc_assert (!prototype_p (*node) || stdarg_p (*node));
441 return NULL_TREE;
444 /* Handle a "transaction_pure" attribute. */
446 static tree
447 handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
448 tree ARG_UNUSED (args),
449 int ARG_UNUSED (flags),
450 bool * ARG_UNUSED (no_add_attrs))
452 /* Ensure we have a function type. */
453 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
455 return NULL_TREE;
458 /* Handle a "returns_twice" attribute. */
460 static tree
461 handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name),
462 tree ARG_UNUSED (args),
463 int ARG_UNUSED (flags),
464 bool * ARG_UNUSED (no_add_attrs))
466 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
468 DECL_IS_RETURNS_TWICE (*node) = 1;
470 return NULL_TREE;
473 /* Ignore the given attribute. Used when this attribute may be usefully
474 overridden by the target, but is not used generically. */
476 static tree
477 ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
478 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
479 bool *no_add_attrs)
481 *no_add_attrs = true;
482 return NULL_TREE;
485 /* Handle a "format" attribute; arguments as in
486 struct attribute_spec.handler. */
488 static tree
489 handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
490 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
491 bool *no_add_attrs)
493 *no_add_attrs = true;
494 return NULL_TREE;
498 /* Handle a "format_arg" attribute; arguments as in
499 struct attribute_spec.handler. */
501 tree
502 handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
503 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
504 bool *no_add_attrs)
506 *no_add_attrs = true;
507 return NULL_TREE;
511 /* Handle a "fn spec" attribute; arguments as in
512 struct attribute_spec.handler. */
514 static tree
515 handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
516 tree args, int ARG_UNUSED (flags),
517 bool *no_add_attrs ATTRIBUTE_UNUSED)
519 gcc_assert (args
520 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
521 && !TREE_CHAIN (args));
522 return NULL_TREE;
525 /* Cribbed from c-common.c. */
527 static void
528 def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
530 tree t;
531 tree *args = XALLOCAVEC (tree, n);
532 va_list list;
533 int i;
534 bool err = false;
536 va_start (list, n);
537 for (i = 0; i < n; ++i)
539 builtin_type a = (builtin_type) va_arg (list, int);
540 t = builtin_types[a];
541 if (t == error_mark_node)
542 err = true;
543 args[i] = t;
545 va_end (list);
547 t = builtin_types[ret];
548 if (err)
549 t = error_mark_node;
550 if (t == error_mark_node)
552 else if (var)
553 t = build_varargs_function_type_array (t, n, args);
554 else
555 t = build_function_type_array (t, n, args);
557 builtin_types[def] = t;
560 /* Used to help initialize the builtin-types.def table. When a type of
561 the correct size doesn't exist, use error_mark_node instead of NULL.
562 The later results in segfaults even when a decl using the type doesn't
563 get invoked. */
565 static tree
566 builtin_type_for_size (int size, bool unsignedp)
568 tree type = lto_type_for_size (size, unsignedp);
569 return type ? type : error_mark_node;
572 /* Support for DEF_BUILTIN. */
574 static void
575 def_builtin_1 (enum built_in_function fncode, const char *name,
576 enum built_in_class fnclass, tree fntype, tree libtype,
577 bool both_p, bool fallback_p, bool nonansi_p,
578 tree fnattrs, bool implicit_p)
580 tree decl;
581 const char *libname;
583 if (fntype == error_mark_node)
584 return;
586 libname = name + strlen ("__builtin_");
587 decl = add_builtin_function (name, fntype, fncode, fnclass,
588 (fallback_p ? libname : NULL),
589 fnattrs);
591 if (both_p
592 && !flag_no_builtin
593 && !(nonansi_p && flag_no_nonansi_builtin))
594 add_builtin_function (libname, libtype, fncode, fnclass,
595 NULL, fnattrs);
597 set_builtin_decl (fncode, decl, implicit_p);
601 /* Initialize the attribute table for all the supported builtins. */
603 static void
604 lto_init_attributes (void)
606 /* Fill in the built_in_attributes array. */
607 #define DEF_ATTR_NULL_TREE(ENUM) \
608 built_in_attributes[(int) ENUM] = NULL_TREE;
609 #define DEF_ATTR_INT(ENUM, VALUE) \
610 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
611 #define DEF_ATTR_STRING(ENUM, VALUE) \
612 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
613 #define DEF_ATTR_IDENT(ENUM, STRING) \
614 built_in_attributes[(int) ENUM] = get_identifier (STRING);
615 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
616 built_in_attributes[(int) ENUM] \
617 = tree_cons (built_in_attributes[(int) PURPOSE], \
618 built_in_attributes[(int) VALUE], \
619 built_in_attributes[(int) CHAIN]);
620 #include "builtin-attrs.def"
621 #undef DEF_ATTR_NULL_TREE
622 #undef DEF_ATTR_INT
623 #undef DEF_ATTR_STRING
624 #undef DEF_ATTR_IDENT
625 #undef DEF_ATTR_TREE_LIST
628 /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
629 VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
631 static void
632 lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
633 tree va_list_arg_type_node ATTRIBUTE_UNUSED)
635 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
636 builtin_types[ENUM] = VALUE;
637 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
638 def_fn_type (ENUM, RETURN, 0, 0);
639 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
640 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
641 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
642 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
643 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
644 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
645 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
646 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
647 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
648 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
649 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
650 ARG6) \
651 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
652 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
653 ARG6, ARG7) \
654 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
655 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
656 ARG6, ARG7, ARG8) \
657 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
658 ARG7, ARG8);
659 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
660 def_fn_type (ENUM, RETURN, 1, 0);
661 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
662 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
663 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
664 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
665 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
666 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
667 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
668 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
669 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
670 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
671 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
672 ARG6, ARG7) \
673 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
674 #define DEF_FUNCTION_TYPE_VAR_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
675 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
676 def_fn_type (ENUM, RETURN, 1, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
677 ARG7, ARG8, ARG9, ARG10, ARG11);
678 #define DEF_POINTER_TYPE(ENUM, TYPE) \
679 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
681 #include "builtin-types.def"
683 #undef DEF_PRIMITIVE_TYPE
684 #undef DEF_FUNCTION_TYPE_0
685 #undef DEF_FUNCTION_TYPE_1
686 #undef DEF_FUNCTION_TYPE_2
687 #undef DEF_FUNCTION_TYPE_3
688 #undef DEF_FUNCTION_TYPE_4
689 #undef DEF_FUNCTION_TYPE_5
690 #undef DEF_FUNCTION_TYPE_6
691 #undef DEF_FUNCTION_TYPE_7
692 #undef DEF_FUNCTION_TYPE_8
693 #undef DEF_FUNCTION_TYPE_VAR_0
694 #undef DEF_FUNCTION_TYPE_VAR_1
695 #undef DEF_FUNCTION_TYPE_VAR_2
696 #undef DEF_FUNCTION_TYPE_VAR_3
697 #undef DEF_FUNCTION_TYPE_VAR_4
698 #undef DEF_FUNCTION_TYPE_VAR_5
699 #undef DEF_FUNCTION_TYPE_VAR_7
700 #undef DEF_FUNCTION_TYPE_VAR_11
701 #undef DEF_POINTER_TYPE
702 builtin_types[(int) BT_LAST] = NULL_TREE;
704 lto_init_attributes ();
706 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
707 NONANSI_P, ATTRS, IMPLICIT, COND) \
708 if (NAME && COND) \
709 def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
710 builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
711 NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
712 #include "builtins.def"
713 #undef DEF_BUILTIN
716 static GTY(()) tree registered_builtin_types;
718 /* Language hooks. */
720 static unsigned int
721 lto_option_lang_mask (void)
723 return CL_LTO;
726 static bool
727 lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
729 /* The LTO front end inherits all the options from the first front
730 end that was used. However, not all the original front end
731 options make sense in LTO.
733 A real solution would be to filter this in collect2, but collect2
734 does not have access to all the option attributes to know what to
735 filter. So, in lto1 we silently accept inherited flags and do
736 nothing about it. */
737 return false;
740 static void
741 lto_init_options_struct (struct gcc_options *opts)
743 /* By default, C99-like requirements for complex multiply and divide.
744 ??? Until the complex method is encoded in the IL this is the only
745 safe choice. This will pessimize Fortran code with LTO unless
746 people specify a complex method manually or use -ffast-math. */
747 opts->x_flag_complex_method = 2;
750 /* Handle command-line option SCODE. If the option takes an argument, it is
751 stored in ARG, which is otherwise NULL. VALUE holds either a numerical
752 argument or a binary value indicating whether the positive or negative form
753 of the option was supplied. */
755 const char *resolution_file_name;
756 static bool
757 lto_handle_option (size_t scode, const char *arg,
758 int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
759 location_t loc ATTRIBUTE_UNUSED,
760 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
762 enum opt_code code = (enum opt_code) scode;
763 bool result = true;
765 switch (code)
767 case OPT_fresolution_:
768 resolution_file_name = arg;
769 break;
771 case OPT_Wabi:
772 warn_psabi = value;
773 break;
775 case OPT_fwpa:
776 flag_wpa = value ? "" : NULL;
777 break;
779 default:
780 break;
783 return result;
786 /* Perform post-option processing. Does additional initialization based on
787 command-line options. PFILENAME is the main input filename. Returns false
788 to enable subsequent back-end initialization. */
790 static bool
791 lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
793 /* -fltrans and -fwpa are mutually exclusive. Check for that here. */
794 if (flag_wpa && flag_ltrans)
795 error ("-fwpa and -fltrans are mutually exclusive");
797 if (flag_ltrans)
799 flag_generate_lto = 0;
801 /* During LTRANS, we are not looking at the whole program, only
802 a subset of the whole callgraph. */
803 flag_whole_program = 0;
806 if (flag_wpa)
807 flag_generate_lto = 1;
809 /* Excess precision other than "fast" requires front-end
810 support. */
811 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
813 /* Initialize the compiler back end. */
814 return false;
817 /* Return an integer type with PRECISION bits of precision,
818 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
820 static tree
821 lto_type_for_size (unsigned precision, int unsignedp)
823 int i;
825 if (precision == TYPE_PRECISION (integer_type_node))
826 return unsignedp ? unsigned_type_node : integer_type_node;
828 if (precision == TYPE_PRECISION (signed_char_type_node))
829 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
831 if (precision == TYPE_PRECISION (short_integer_type_node))
832 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
834 if (precision == TYPE_PRECISION (long_integer_type_node))
835 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
837 if (precision == TYPE_PRECISION (long_long_integer_type_node))
838 return unsignedp
839 ? long_long_unsigned_type_node
840 : long_long_integer_type_node;
842 for (i = 0; i < NUM_INT_N_ENTS; i ++)
843 if (int_n_enabled_p[i]
844 && precision == int_n_data[i].bitsize)
845 return (unsignedp ? int_n_trees[i].unsigned_type
846 : int_n_trees[i].signed_type);
848 if (precision <= TYPE_PRECISION (intQI_type_node))
849 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
851 if (precision <= TYPE_PRECISION (intHI_type_node))
852 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
854 if (precision <= TYPE_PRECISION (intSI_type_node))
855 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
857 if (precision <= TYPE_PRECISION (intDI_type_node))
858 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
860 if (precision <= TYPE_PRECISION (intTI_type_node))
861 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
863 return NULL_TREE;
867 /* Return a data type that has machine mode MODE.
868 If the mode is an integer,
869 then UNSIGNEDP selects between signed and unsigned types.
870 If the mode is a fixed-point mode,
871 then UNSIGNEDP selects between saturating and nonsaturating types. */
873 static tree
874 lto_type_for_mode (machine_mode mode, int unsigned_p)
876 tree t;
877 int i;
879 if (mode == TYPE_MODE (integer_type_node))
880 return unsigned_p ? unsigned_type_node : integer_type_node;
882 if (mode == TYPE_MODE (signed_char_type_node))
883 return unsigned_p ? unsigned_char_type_node : signed_char_type_node;
885 if (mode == TYPE_MODE (short_integer_type_node))
886 return unsigned_p ? short_unsigned_type_node : short_integer_type_node;
888 if (mode == TYPE_MODE (long_integer_type_node))
889 return unsigned_p ? long_unsigned_type_node : long_integer_type_node;
891 if (mode == TYPE_MODE (long_long_integer_type_node))
892 return unsigned_p ? long_long_unsigned_type_node : long_long_integer_type_node;
894 for (i = 0; i < NUM_INT_N_ENTS; i ++)
895 if (int_n_enabled_p[i]
896 && mode == int_n_data[i].m)
897 return (unsigned_p ? int_n_trees[i].unsigned_type
898 : int_n_trees[i].signed_type);
900 if (mode == QImode)
901 return unsigned_p ? unsigned_intQI_type_node : intQI_type_node;
903 if (mode == HImode)
904 return unsigned_p ? unsigned_intHI_type_node : intHI_type_node;
906 if (mode == SImode)
907 return unsigned_p ? unsigned_intSI_type_node : intSI_type_node;
909 if (mode == DImode)
910 return unsigned_p ? unsigned_intDI_type_node : intDI_type_node;
912 #if HOST_BITS_PER_WIDE_INT >= 64
913 if (mode == TYPE_MODE (intTI_type_node))
914 return unsigned_p ? unsigned_intTI_type_node : intTI_type_node;
915 #endif
917 if (mode == TYPE_MODE (float_type_node))
918 return float_type_node;
920 if (mode == TYPE_MODE (double_type_node))
921 return double_type_node;
923 if (mode == TYPE_MODE (long_double_type_node))
924 return long_double_type_node;
926 if (mode == TYPE_MODE (void_type_node))
927 return void_type_node;
929 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
930 return (unsigned_p
931 ? make_unsigned_type (GET_MODE_PRECISION (mode))
932 : make_signed_type (GET_MODE_PRECISION (mode)));
934 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
935 return (unsigned_p
936 ? make_unsigned_type (GET_MODE_PRECISION (mode))
937 : make_signed_type (GET_MODE_PRECISION (mode)));
939 if (COMPLEX_MODE_P (mode))
941 machine_mode inner_mode;
942 tree inner_type;
944 if (mode == TYPE_MODE (complex_float_type_node))
945 return complex_float_type_node;
946 if (mode == TYPE_MODE (complex_double_type_node))
947 return complex_double_type_node;
948 if (mode == TYPE_MODE (complex_long_double_type_node))
949 return complex_long_double_type_node;
951 if (mode == TYPE_MODE (complex_integer_type_node) && !unsigned_p)
952 return complex_integer_type_node;
954 inner_mode = GET_MODE_INNER (mode);
955 inner_type = lto_type_for_mode (inner_mode, unsigned_p);
956 if (inner_type != NULL_TREE)
957 return build_complex_type (inner_type);
959 else if (VECTOR_MODE_P (mode))
961 machine_mode inner_mode = GET_MODE_INNER (mode);
962 tree inner_type = lto_type_for_mode (inner_mode, unsigned_p);
963 if (inner_type != NULL_TREE)
964 return build_vector_type_for_mode (inner_type, mode);
967 if (mode == TYPE_MODE (dfloat32_type_node))
968 return dfloat32_type_node;
969 if (mode == TYPE_MODE (dfloat64_type_node))
970 return dfloat64_type_node;
971 if (mode == TYPE_MODE (dfloat128_type_node))
972 return dfloat128_type_node;
974 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
976 if (mode == TYPE_MODE (short_fract_type_node))
977 return unsigned_p ? sat_short_fract_type_node : short_fract_type_node;
978 if (mode == TYPE_MODE (fract_type_node))
979 return unsigned_p ? sat_fract_type_node : fract_type_node;
980 if (mode == TYPE_MODE (long_fract_type_node))
981 return unsigned_p ? sat_long_fract_type_node : long_fract_type_node;
982 if (mode == TYPE_MODE (long_long_fract_type_node))
983 return unsigned_p ? sat_long_long_fract_type_node
984 : long_long_fract_type_node;
986 if (mode == TYPE_MODE (unsigned_short_fract_type_node))
987 return unsigned_p ? sat_unsigned_short_fract_type_node
988 : unsigned_short_fract_type_node;
989 if (mode == TYPE_MODE (unsigned_fract_type_node))
990 return unsigned_p ? sat_unsigned_fract_type_node
991 : unsigned_fract_type_node;
992 if (mode == TYPE_MODE (unsigned_long_fract_type_node))
993 return unsigned_p ? sat_unsigned_long_fract_type_node
994 : unsigned_long_fract_type_node;
995 if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
996 return unsigned_p ? sat_unsigned_long_long_fract_type_node
997 : unsigned_long_long_fract_type_node;
999 if (mode == TYPE_MODE (short_accum_type_node))
1000 return unsigned_p ? sat_short_accum_type_node : short_accum_type_node;
1001 if (mode == TYPE_MODE (accum_type_node))
1002 return unsigned_p ? sat_accum_type_node : accum_type_node;
1003 if (mode == TYPE_MODE (long_accum_type_node))
1004 return unsigned_p ? sat_long_accum_type_node : long_accum_type_node;
1005 if (mode == TYPE_MODE (long_long_accum_type_node))
1006 return unsigned_p ? sat_long_long_accum_type_node
1007 : long_long_accum_type_node;
1009 if (mode == TYPE_MODE (unsigned_short_accum_type_node))
1010 return unsigned_p ? sat_unsigned_short_accum_type_node
1011 : unsigned_short_accum_type_node;
1012 if (mode == TYPE_MODE (unsigned_accum_type_node))
1013 return unsigned_p ? sat_unsigned_accum_type_node
1014 : unsigned_accum_type_node;
1015 if (mode == TYPE_MODE (unsigned_long_accum_type_node))
1016 return unsigned_p ? sat_unsigned_long_accum_type_node
1017 : unsigned_long_accum_type_node;
1018 if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
1019 return unsigned_p ? sat_unsigned_long_long_accum_type_node
1020 : unsigned_long_long_accum_type_node;
1022 if (mode == QQmode)
1023 return unsigned_p ? sat_qq_type_node : qq_type_node;
1024 if (mode == HQmode)
1025 return unsigned_p ? sat_hq_type_node : hq_type_node;
1026 if (mode == SQmode)
1027 return unsigned_p ? sat_sq_type_node : sq_type_node;
1028 if (mode == DQmode)
1029 return unsigned_p ? sat_dq_type_node : dq_type_node;
1030 if (mode == TQmode)
1031 return unsigned_p ? sat_tq_type_node : tq_type_node;
1033 if (mode == UQQmode)
1034 return unsigned_p ? sat_uqq_type_node : uqq_type_node;
1035 if (mode == UHQmode)
1036 return unsigned_p ? sat_uhq_type_node : uhq_type_node;
1037 if (mode == USQmode)
1038 return unsigned_p ? sat_usq_type_node : usq_type_node;
1039 if (mode == UDQmode)
1040 return unsigned_p ? sat_udq_type_node : udq_type_node;
1041 if (mode == UTQmode)
1042 return unsigned_p ? sat_utq_type_node : utq_type_node;
1044 if (mode == HAmode)
1045 return unsigned_p ? sat_ha_type_node : ha_type_node;
1046 if (mode == SAmode)
1047 return unsigned_p ? sat_sa_type_node : sa_type_node;
1048 if (mode == DAmode)
1049 return unsigned_p ? sat_da_type_node : da_type_node;
1050 if (mode == TAmode)
1051 return unsigned_p ? sat_ta_type_node : ta_type_node;
1053 if (mode == UHAmode)
1054 return unsigned_p ? sat_uha_type_node : uha_type_node;
1055 if (mode == USAmode)
1056 return unsigned_p ? sat_usa_type_node : usa_type_node;
1057 if (mode == UDAmode)
1058 return unsigned_p ? sat_uda_type_node : uda_type_node;
1059 if (mode == UTAmode)
1060 return unsigned_p ? sat_uta_type_node : uta_type_node;
1063 for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
1064 if (TYPE_MODE (TREE_VALUE (t)) == mode)
1065 return TREE_VALUE (t);
1067 return NULL_TREE;
1070 /* Return true if we are in the global binding level. */
1072 static bool
1073 lto_global_bindings_p (void)
1075 return cfun == NULL;
1078 static void
1079 lto_set_decl_assembler_name (tree decl)
1081 /* This is almost the same as lhd_set_decl_assembler_name, except that
1082 we need to uniquify file-scope names, even if they are not
1083 TREE_PUBLIC, to avoid conflicts between individual files. */
1084 tree id;
1086 if (TREE_PUBLIC (decl))
1087 id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
1088 else
1090 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1091 char *label;
1093 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
1094 id = get_identifier (label);
1097 SET_DECL_ASSEMBLER_NAME (decl, id);
1100 static tree
1101 lto_pushdecl (tree t ATTRIBUTE_UNUSED)
1103 /* Do nothing, since we get all information from DWARF and LTO
1104 sections. */
1105 return NULL_TREE;
1108 static tree
1109 lto_getdecls (void)
1111 /* We have our own write_globals langhook, hence the getdecls
1112 langhook shouldn't be used, except by dbxout.c, so we can't
1113 just abort here. */
1114 return NULL_TREE;
1117 static tree
1118 lto_builtin_function (tree decl)
1120 return decl;
1123 static void
1124 lto_register_builtin_type (tree type, const char *name)
1126 tree decl;
1128 if (!TYPE_NAME (type))
1130 decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
1131 get_identifier (name), type);
1132 DECL_ARTIFICIAL (decl) = 1;
1133 TYPE_NAME (type) = decl;
1136 registered_builtin_types = tree_cons (0, type, registered_builtin_types);
1139 /* Build nodes that would have be created by the C front-end; necessary
1140 for including builtin-types.def and ultimately builtins.def. */
1142 static void
1143 lto_build_c_type_nodes (void)
1145 gcc_assert (void_type_node);
1147 void_list_node = build_tree_list (NULL_TREE, void_type_node);
1148 string_type_node = build_pointer_type (char_type_node);
1149 const_string_type_node
1150 = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
1152 if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1154 intmax_type_node = integer_type_node;
1155 uintmax_type_node = unsigned_type_node;
1156 signed_size_type_node = integer_type_node;
1158 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1160 intmax_type_node = long_integer_type_node;
1161 uintmax_type_node = long_unsigned_type_node;
1162 signed_size_type_node = long_integer_type_node;
1164 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1166 intmax_type_node = long_long_integer_type_node;
1167 uintmax_type_node = long_long_unsigned_type_node;
1168 signed_size_type_node = long_long_integer_type_node;
1170 else
1172 int i;
1174 signed_size_type_node = NULL_TREE;
1175 for (i = 0; i < NUM_INT_N_ENTS; i++)
1176 if (int_n_enabled_p[i])
1178 char name[50];
1179 sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
1181 if (strcmp (name, SIZE_TYPE) == 0)
1183 intmax_type_node = int_n_trees[i].signed_type;
1184 uintmax_type_node = int_n_trees[i].unsigned_type;
1185 signed_size_type_node = int_n_trees[i].signed_type;
1188 if (signed_size_type_node == NULL_TREE)
1189 gcc_unreachable ();
1192 wint_type_node = unsigned_type_node;
1193 pid_type_node = integer_type_node;
1196 /* Perform LTO-specific initialization. */
1198 static bool
1199 lto_init (void)
1201 int i;
1203 /* We need to generate LTO if running in WPA mode. */
1204 flag_generate_lto = (flag_wpa != NULL);
1206 /* Create the basic integer types. */
1207 build_common_tree_nodes (flag_signed_char, flag_short_double);
1209 /* The global tree for the main identifier is filled in by
1210 language-specific front-end initialization that is not run in the
1211 LTO back-end. It appears that all languages that perform such
1212 initialization currently do so in the same way, so we do it here. */
1213 if (main_identifier_node == NULL_TREE)
1214 main_identifier_node = get_identifier ("main");
1216 /* In the C++ front-end, fileptr_type_node is defined as a variant
1217 copy of ptr_type_node, rather than ptr_node itself. The
1218 distinction should only be relevant to the front-end, so we
1219 always use the C definition here in lto1. */
1220 gcc_assert (fileptr_type_node == ptr_type_node);
1221 gcc_assert (TYPE_MAIN_VARIANT (fileptr_type_node) == ptr_type_node);
1223 ptrdiff_type_node = integer_type_node;
1225 lto_build_c_type_nodes ();
1226 gcc_assert (va_list_type_node);
1228 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1230 tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
1231 lto_define_builtins (x, x);
1233 else
1235 lto_define_builtins (build_reference_type (va_list_type_node),
1236 va_list_type_node);
1239 if (flag_cilkplus)
1240 cilk_init_builtins ();
1242 targetm.init_builtins ();
1243 build_common_builtin_nodes ();
1245 /* Assign names to the builtin types, otherwise they'll end up
1246 as __unknown__ in debug info.
1247 ??? We simply need to stop pre-seeding the streamer cache.
1248 Below is modeled after from c-common.c:c_common_nodes_and_builtins */
1249 #define NAME_TYPE(t,n) \
1250 if (t) \
1251 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \
1252 get_identifier (n), t)
1253 NAME_TYPE (integer_type_node, "int");
1254 NAME_TYPE (char_type_node, "char");
1255 NAME_TYPE (long_integer_type_node, "long int");
1256 NAME_TYPE (unsigned_type_node, "unsigned int");
1257 NAME_TYPE (long_unsigned_type_node, "long unsigned int");
1258 NAME_TYPE (long_long_integer_type_node, "long long int");
1259 NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int");
1260 NAME_TYPE (short_integer_type_node, "short int");
1261 NAME_TYPE (short_unsigned_type_node, "short unsigned int");
1262 if (signed_char_type_node != char_type_node)
1263 NAME_TYPE (signed_char_type_node, "signed char");
1264 if (unsigned_char_type_node != char_type_node)
1265 NAME_TYPE (unsigned_char_type_node, "unsigned char");
1266 NAME_TYPE (float_type_node, "float");
1267 NAME_TYPE (double_type_node, "double");
1268 NAME_TYPE (long_double_type_node, "long double");
1269 NAME_TYPE (void_type_node, "void");
1270 NAME_TYPE (boolean_type_node, "bool");
1271 NAME_TYPE (complex_float_type_node, "complex float");
1272 NAME_TYPE (complex_double_type_node, "complex double");
1273 NAME_TYPE (complex_long_double_type_node, "complex long double");
1274 for (i = 0; i < NUM_INT_N_ENTS; i++)
1275 if (int_n_enabled_p[i])
1277 char name[50];
1278 sprintf (name, "__int%d", int_n_data[i].bitsize);
1279 NAME_TYPE (int_n_trees[i].signed_type, name);
1281 #undef NAME_TYPE
1283 /* Initialize LTO-specific data structures. */
1284 in_lto_p = true;
1286 return true;
1289 /* Initialize tree structures required by the LTO front end. */
1291 static void lto_init_ts (void)
1293 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1296 #undef LANG_HOOKS_NAME
1297 #define LANG_HOOKS_NAME "GNU GIMPLE"
1298 #undef LANG_HOOKS_OPTION_LANG_MASK
1299 #define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
1300 #undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
1301 #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
1302 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1303 #define LANG_HOOKS_INIT_OPTIONS_STRUCT lto_init_options_struct
1304 #undef LANG_HOOKS_HANDLE_OPTION
1305 #define LANG_HOOKS_HANDLE_OPTION lto_handle_option
1306 #undef LANG_HOOKS_POST_OPTIONS
1307 #define LANG_HOOKS_POST_OPTIONS lto_post_options
1308 #undef LANG_HOOKS_GET_ALIAS_SET
1309 #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
1310 #undef LANG_HOOKS_TYPE_FOR_MODE
1311 #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
1312 #undef LANG_HOOKS_TYPE_FOR_SIZE
1313 #define LANG_HOOKS_TYPE_FOR_SIZE lto_type_for_size
1314 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
1315 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
1316 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1317 #define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
1318 #undef LANG_HOOKS_PUSHDECL
1319 #define LANG_HOOKS_PUSHDECL lto_pushdecl
1320 #undef LANG_HOOKS_GETDECLS
1321 #define LANG_HOOKS_GETDECLS lto_getdecls
1322 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1323 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
1324 #undef LANG_HOOKS_BUILTIN_FUNCTION
1325 #define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
1326 #undef LANG_HOOKS_INIT
1327 #define LANG_HOOKS_INIT lto_init
1328 #undef LANG_HOOKS_PARSE_FILE
1329 #define LANG_HOOKS_PARSE_FILE lto_main
1330 #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
1331 #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
1332 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1333 #define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
1334 #undef LANG_HOOKS_EH_PERSONALITY
1335 #define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
1337 /* Attribute hooks. */
1338 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1339 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
1340 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
1341 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
1343 #undef LANG_HOOKS_BEGIN_SECTION
1344 #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
1345 #undef LANG_HOOKS_APPEND_DATA
1346 #define LANG_HOOKS_APPEND_DATA lto_obj_append_data
1347 #undef LANG_HOOKS_END_SECTION
1348 #define LANG_HOOKS_END_SECTION lto_obj_end_section
1350 #undef LANG_HOOKS_INIT_TS
1351 #define LANG_HOOKS_INIT_TS lto_init_ts
1353 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1355 /* Language hooks that are not part of lang_hooks. */
1357 tree
1358 convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1360 gcc_unreachable ();
1363 /* Tree walking support. */
1365 static enum lto_tree_node_structure_enum
1366 lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
1368 return TS_LTO_GENERIC;
1371 #include "gtype-lto.h"
1372 #include "gt-lto-lto-lang.h"