OSDN Git Service

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