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