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