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