OSDN Git Service

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