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