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