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