OSDN Git Service

2010-12-06 Richard Guenther <rguenther@suse.de>
[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
38 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
39 static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
40 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
41 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
42 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
43 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
44 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
45 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
46 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
47 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
48 static tree handle_format_attribute (tree *, tree, tree, int, bool *);
49 static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
50
51 /* Table of machine-independent attributes supported in GIMPLE.  */
52 const struct attribute_spec lto_attribute_table[] =
53 {
54   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
55   { "noreturn",               0, 0, true,  false, false,
56                               handle_noreturn_attribute },
57   { "leaf",                   0, 0, true,  false, false,
58                               handle_leaf_attribute },
59   /* The same comments as for noreturn attributes apply to const ones.  */
60   { "const",                  0, 0, true,  false, false,
61                               handle_const_attribute },
62   { "malloc",                 0, 0, true,  false, false,
63                               handle_malloc_attribute },
64   { "pure",                   0, 0, true,  false, false,
65                               handle_pure_attribute },
66   { "no vops",                0, 0, true,  false, false,
67                               handle_novops_attribute },
68   { "nonnull",                0, -1, false, true, true,
69                               handle_nonnull_attribute },
70   { "nothrow",                0, 0, true,  false, false,
71                               handle_nothrow_attribute },
72   { "sentinel",               0, 1, false, true, true,
73                               handle_sentinel_attribute },
74   { "type generic",           0, 0, false, true, true,
75                               handle_type_generic_attribute },
76   { NULL,                     0, 0, false, false, false, NULL }
77 };
78
79 /* Give the specifications for the format attributes, used by C and all
80    descendants.  */
81
82 const struct attribute_spec lto_format_attribute_table[] =
83 {
84   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
85   { "format",                 3, 3, false, true,  true,
86                               handle_format_attribute },
87   { "format_arg",             1, 1, false, true,  true,
88                               handle_format_arg_attribute },
89   { NULL,                     0, 0, false, false, false, NULL }
90 };
91
92 enum built_in_attribute
93 {
94 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
95 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
96 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
97 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
98 #include "builtin-attrs.def"
99 #undef DEF_ATTR_NULL_TREE
100 #undef DEF_ATTR_INT
101 #undef DEF_ATTR_IDENT
102 #undef DEF_ATTR_TREE_LIST
103   ATTR_LAST
104 };
105
106 static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
107
108 /* Builtin types.  */
109
110 enum lto_builtin_type
111 {
112 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
113 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
114 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
115 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
116 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
117 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
118 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
119 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
120 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
121 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
122 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
123 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
124 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
125 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
126 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
127   NAME,
128 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
129 #include "builtin-types.def"
130 #undef DEF_PRIMITIVE_TYPE
131 #undef DEF_FUNCTION_TYPE_0
132 #undef DEF_FUNCTION_TYPE_1
133 #undef DEF_FUNCTION_TYPE_2
134 #undef DEF_FUNCTION_TYPE_3
135 #undef DEF_FUNCTION_TYPE_4
136 #undef DEF_FUNCTION_TYPE_5
137 #undef DEF_FUNCTION_TYPE_6
138 #undef DEF_FUNCTION_TYPE_7
139 #undef DEF_FUNCTION_TYPE_VAR_0
140 #undef DEF_FUNCTION_TYPE_VAR_1
141 #undef DEF_FUNCTION_TYPE_VAR_2
142 #undef DEF_FUNCTION_TYPE_VAR_3
143 #undef DEF_FUNCTION_TYPE_VAR_4
144 #undef DEF_FUNCTION_TYPE_VAR_5
145 #undef DEF_POINTER_TYPE
146   BT_LAST
147 };
148
149 typedef enum lto_builtin_type builtin_type;
150
151 static GTY(()) tree builtin_types[(int) BT_LAST + 1];
152
153 static GTY(()) tree string_type_node;
154 static GTY(()) tree const_string_type_node;
155 static GTY(()) tree wint_type_node;
156 static GTY(()) tree intmax_type_node;
157 static GTY(()) tree uintmax_type_node;
158 static GTY(()) tree signed_size_type_node;
159
160 /* Flags needed to process builtins.def.  */
161 int flag_isoc94;
162 int flag_isoc99;
163
164 /* Attribute handlers.  */
165
166 /* Handle a "noreturn" attribute; arguments as in
167    struct attribute_spec.handler.  */
168
169 static tree
170 handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
171                            tree ARG_UNUSED (args), int ARG_UNUSED (flags),
172                            bool * ARG_UNUSED (no_add_attrs))
173 {
174   tree type = TREE_TYPE (*node);
175
176   if (TREE_CODE (*node) == FUNCTION_DECL)
177     TREE_THIS_VOLATILE (*node) = 1;
178   else if (TREE_CODE (type) == POINTER_TYPE
179            && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
180     TREE_TYPE (*node)
181       = build_pointer_type
182         (build_type_variant (TREE_TYPE (type),
183                              TYPE_READONLY (TREE_TYPE (type)), 1));
184   else
185     gcc_unreachable ();
186
187   return NULL_TREE;
188 }
189
190 /* Handle a "leaf" attribute; arguments as in
191    struct attribute_spec.handler.  */
192
193 static tree
194 handle_leaf_attribute (tree *node, tree name,
195                        tree ARG_UNUSED (args),
196                        int ARG_UNUSED (flags), bool *no_add_attrs)
197 {
198   if (TREE_CODE (*node) != FUNCTION_DECL)
199     {
200       warning (OPT_Wattributes, "%qE attribute ignored", name);
201       *no_add_attrs = true;
202     }
203   if (!TREE_PUBLIC (*node))
204     {
205       warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
206       *no_add_attrs = true;
207     }
208
209   return NULL_TREE;
210 }
211
212 /* Handle a "const" attribute; arguments as in
213    struct attribute_spec.handler.  */
214
215 static tree
216 handle_const_attribute (tree *node, tree ARG_UNUSED (name),
217                         tree ARG_UNUSED (args), int ARG_UNUSED (flags),
218                         bool * ARG_UNUSED (no_add_attrs))
219 {
220   tree type = TREE_TYPE (*node);
221
222   /* See FIXME comment on noreturn in c_common_attribute_table.  */
223   if (TREE_CODE (*node) == FUNCTION_DECL)
224     TREE_READONLY (*node) = 1;
225   else if (TREE_CODE (type) == POINTER_TYPE
226            && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
227     TREE_TYPE (*node)
228       = build_pointer_type
229         (build_type_variant (TREE_TYPE (type), 1,
230                              TREE_THIS_VOLATILE (TREE_TYPE (type))));
231   else
232     gcc_unreachable ();
233
234   return NULL_TREE;
235 }
236
237
238 /* Handle a "malloc" attribute; arguments as in
239    struct attribute_spec.handler.  */
240
241 static tree
242 handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
243                          tree ARG_UNUSED (args), int ARG_UNUSED (flags),
244                          bool * ARG_UNUSED (no_add_attrs))
245 {
246   if (TREE_CODE (*node) == FUNCTION_DECL
247       && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
248     DECL_IS_MALLOC (*node) = 1;
249   else
250     gcc_unreachable ();
251
252   return NULL_TREE;
253 }
254
255
256 /* Handle a "pure" attribute; arguments as in
257    struct attribute_spec.handler.  */
258
259 static tree
260 handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
261                        tree ARG_UNUSED (args), int ARG_UNUSED (flags),
262                        bool * ARG_UNUSED (no_add_attrs))
263 {
264   if (TREE_CODE (*node) == FUNCTION_DECL)
265     DECL_PURE_P (*node) = 1;
266   else
267     gcc_unreachable ();
268
269   return NULL_TREE;
270 }
271
272
273 /* Handle a "no vops" attribute; arguments as in
274    struct attribute_spec.handler.  */
275
276 static tree
277 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
278                          tree ARG_UNUSED (args), int ARG_UNUSED (flags),
279                          bool *ARG_UNUSED (no_add_attrs))
280 {
281   gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
282   DECL_IS_NOVOPS (*node) = 1;
283   return NULL_TREE;
284 }
285
286
287 /* Helper for nonnull attribute handling; fetch the operand number
288    from the attribute argument list.  */
289
290 static bool
291 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
292 {
293   /* Verify the arg number is a constant.  */
294   if (TREE_CODE (arg_num_expr) != INTEGER_CST
295       || TREE_INT_CST_HIGH (arg_num_expr) != 0)
296     return false;
297
298   *valp = TREE_INT_CST_LOW (arg_num_expr);
299   return true;
300 }
301
302 /* Handle the "nonnull" attribute.  */
303
304 static tree
305 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
306                           tree args, int ARG_UNUSED (flags),
307                           bool * ARG_UNUSED (no_add_attrs))
308 {
309   tree type = *node;
310
311   /* If no arguments are specified, all pointer arguments should be
312      non-null.  Verify a full prototype is given so that the arguments
313      will have the correct types when we actually check them later.  */
314   if (!args)
315     {
316       gcc_assert (TYPE_ARG_TYPES (type));
317       return NULL_TREE;
318     }
319
320   /* Argument list specified.  Verify that each argument number references
321      a pointer argument.  */
322   for (; args; args = TREE_CHAIN (args))
323     {
324       tree argument;
325       unsigned HOST_WIDE_INT arg_num = 0, ck_num;
326
327       if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
328         gcc_unreachable ();
329
330       argument = TYPE_ARG_TYPES (type);
331       if (argument)
332         {
333           for (ck_num = 1; ; ck_num++)
334             {
335               if (!argument || ck_num == arg_num)
336                 break;
337               argument = TREE_CHAIN (argument);
338             }
339
340           gcc_assert (argument
341                       && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
342         }
343     }
344
345   return NULL_TREE;
346 }
347
348
349 /* Handle a "nothrow" attribute; arguments as in
350    struct attribute_spec.handler.  */
351
352 static tree
353 handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
354                           tree ARG_UNUSED (args), int ARG_UNUSED (flags),
355                           bool * ARG_UNUSED (no_add_attrs))
356 {
357   if (TREE_CODE (*node) == FUNCTION_DECL)
358     TREE_NOTHROW (*node) = 1;
359   else
360     gcc_unreachable ();
361
362   return NULL_TREE;
363 }
364
365
366 /* Handle a "sentinel" attribute.  */
367
368 static tree
369 handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
370                            int ARG_UNUSED (flags),
371                            bool * ARG_UNUSED (no_add_attrs))
372 {
373   tree params = TYPE_ARG_TYPES (*node);
374   gcc_assert (params);
375
376   while (TREE_CHAIN (params))
377     params = TREE_CHAIN (params);
378
379   gcc_assert (!VOID_TYPE_P (TREE_VALUE (params)));
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   tree params;
400   
401   /* Ensure we have a function type.  */
402   gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
403   
404   params = TYPE_ARG_TYPES (*node);
405   while (params && ! VOID_TYPE_P (TREE_VALUE (params)))
406     params = TREE_CHAIN (params);
407
408   /* Ensure we have a variadic function.  */
409   gcc_assert (!params);
410
411   return NULL_TREE;
412 }
413
414 /* Handle a "format" attribute; arguments as in
415    struct attribute_spec.handler.  */
416
417 static tree
418 handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
419                          tree ARG_UNUSED (args), int ARG_UNUSED (flags),
420                          bool *no_add_attrs)
421 {
422   *no_add_attrs = true;
423   return NULL_TREE;
424 }
425
426
427 /* Handle a "format_arg" attribute; arguments as in
428    struct attribute_spec.handler.  */
429
430 tree
431 handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
432                              tree ARG_UNUSED (args), int ARG_UNUSED (flags),
433                              bool *no_add_attrs)
434 {
435   *no_add_attrs = true;
436   return NULL_TREE;
437 }
438
439
440 /* Cribbed from c-common.c.  */
441
442 static void
443 def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
444 {
445   tree args = NULL, t;
446   va_list list;
447   int i;
448
449   va_start (list, n);
450   for (i = 0; i < n; ++i)
451     {
452       builtin_type a = (builtin_type) va_arg (list, int);
453       t = builtin_types[a];
454       if (t == error_mark_node)
455         goto egress;
456       args = tree_cons (NULL_TREE, t, args);
457     }
458   va_end (list);
459
460   args = nreverse (args);
461   if (!var)
462     args = chainon (args, void_list_node);
463
464   t = builtin_types[ret];
465   if (t == error_mark_node)
466     goto egress;
467   t = build_function_type (t, args);
468
469  egress:
470   builtin_types[def] = t;
471 }
472
473 /* Used to help initialize the builtin-types.def table.  When a type of
474    the correct size doesn't exist, use error_mark_node instead of NULL.
475    The later results in segfaults even when a decl using the type doesn't
476    get invoked.  */
477
478 static tree
479 builtin_type_for_size (int size, bool unsignedp)
480 {
481   tree type = lang_hooks.types.type_for_size (size, unsignedp);
482   return type ? type : error_mark_node;
483 }
484
485 /* Support for DEF_BUILTIN.  */
486
487 static void
488 def_builtin_1 (enum built_in_function fncode, const char *name,
489                enum built_in_class fnclass, tree fntype, tree libtype,
490                bool both_p, bool fallback_p, bool nonansi_p,
491                tree fnattrs, bool implicit_p)
492 {
493   tree decl;
494   const char *libname;
495
496   if (fntype == error_mark_node)
497     return;
498
499   libname = name + strlen ("__builtin_");
500   decl = add_builtin_function (name, fntype, fncode, fnclass,
501                                (fallback_p ? libname : NULL),
502                                fnattrs);
503
504   if (both_p
505       && !flag_no_builtin
506       && !(nonansi_p && flag_no_nonansi_builtin))
507     add_builtin_function (libname, libtype, fncode, fnclass,
508                           NULL, fnattrs);
509
510   built_in_decls[(int) fncode] = decl;
511   if (implicit_p)
512     implicit_built_in_decls[(int) fncode] = decl;
513 }
514
515
516 /* Initialize the attribute table for all the supported builtins.  */
517
518 static void
519 lto_init_attributes (void)
520 {
521   /* Fill in the built_in_attributes array.  */
522 #define DEF_ATTR_NULL_TREE(ENUM)                                \
523   built_in_attributes[(int) ENUM] = NULL_TREE;
524 #define DEF_ATTR_INT(ENUM, VALUE)                               \
525   built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
526 #define DEF_ATTR_IDENT(ENUM, STRING)                            \
527   built_in_attributes[(int) ENUM] = get_identifier (STRING);
528 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
529   built_in_attributes[(int) ENUM]                       \
530     = tree_cons (built_in_attributes[(int) PURPOSE],    \
531                  built_in_attributes[(int) VALUE],      \
532                  built_in_attributes[(int) CHAIN]);
533 #include "builtin-attrs.def"
534 #undef DEF_ATTR_NULL_TREE
535 #undef DEF_ATTR_INT
536 #undef DEF_ATTR_IDENT
537 #undef DEF_ATTR_TREE_LIST
538 }
539
540 /* Create builtin types and functions.  VA_LIST_REF_TYPE_NODE and
541    VA_LIST_ARG_TYPE_NODE are used in builtin-types.def.  */
542
543 static void
544 lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
545                      tree va_list_arg_type_node ATTRIBUTE_UNUSED)
546 {
547 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
548   builtin_types[ENUM] = VALUE;
549 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
550   def_fn_type (ENUM, RETURN, 0, 0);
551 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
552   def_fn_type (ENUM, RETURN, 0, 1, ARG1);
553 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
554   def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
555 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
556   def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
557 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
558   def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
559 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
560   def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
561 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
562                             ARG6)                                       \
563   def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
564 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
565                             ARG6, ARG7)                                 \
566   def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
567 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
568   def_fn_type (ENUM, RETURN, 1, 0);
569 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
570   def_fn_type (ENUM, RETURN, 1, 1, ARG1);
571 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
572   def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
573 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
574   def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
575 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
576   def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
577 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
578   def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
579 #define DEF_POINTER_TYPE(ENUM, TYPE) \
580   builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
581
582 #include "builtin-types.def"
583
584 #undef DEF_PRIMITIVE_TYPE
585 #undef DEF_FUNCTION_TYPE_1
586 #undef DEF_FUNCTION_TYPE_2
587 #undef DEF_FUNCTION_TYPE_3
588 #undef DEF_FUNCTION_TYPE_4
589 #undef DEF_FUNCTION_TYPE_5
590 #undef DEF_FUNCTION_TYPE_6
591 #undef DEF_FUNCTION_TYPE_VAR_0
592 #undef DEF_FUNCTION_TYPE_VAR_1
593 #undef DEF_FUNCTION_TYPE_VAR_2
594 #undef DEF_FUNCTION_TYPE_VAR_3
595 #undef DEF_FUNCTION_TYPE_VAR_4
596 #undef DEF_FUNCTION_TYPE_VAR_5
597 #undef DEF_POINTER_TYPE
598   builtin_types[(int) BT_LAST] = NULL_TREE;
599
600   lto_init_attributes ();
601
602 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
603                     NONANSI_P, ATTRS, IMPLICIT, COND)                   \
604     if (NAME && COND)                                                   \
605       def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE],      \
606                      builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P,  \
607                      NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
608 #include "builtins.def"
609 #undef DEF_BUILTIN
610 }
611
612 static GTY(()) tree registered_builtin_types;
613
614 /* A chain of builtin functions that we need to recognize.  We will
615    assume that all other function names we see will be defined by the
616    user's program.  */
617 static GTY(()) tree registered_builtin_fndecls;
618
619 /* Language hooks.  */
620
621 static unsigned int
622 lto_option_lang_mask (void)
623 {
624   return CL_LTO;
625 }
626
627 static bool
628 lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
629 {
630   /* The LTO front end inherits all the options from the first front
631      end that was used.  However, not all the original front end
632      options make sense in LTO.
633
634      A real solution would be to filter this in collect2, but collect2
635      does not have access to all the option attributes to know what to
636      filter.  So, in lto1 we silently accept inherited flags and do
637      nothing about it.  */
638   return false;
639 }
640
641 static void
642 lto_init_options_struct (struct gcc_options *opts)
643 {
644   /* By default, C99-like requirements for complex multiply and divide.
645      ???  Until the complex method is encoded in the IL this is the only
646      safe choice.  This will pessimize Fortran code with LTO unless
647      people specify a complex method manually or use -ffast-math.  */
648   opts->x_flag_complex_method = 2;
649 }
650
651 /* Handle command-line option SCODE.  If the option takes an argument, it is
652    stored in ARG, which is otherwise NULL.  VALUE holds either a numerical
653    argument or a binary value indicating whether the positive or negative form
654    of the option was supplied.  */
655
656 const char *resolution_file_name;
657 static bool
658 lto_handle_option (size_t scode, const char *arg,
659                    int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
660                    location_t loc ATTRIBUTE_UNUSED,
661                    const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
662 {
663   enum opt_code code = (enum opt_code) scode;
664   bool result = true;
665
666   switch (code)
667     {
668     case OPT_fresolution_:
669       resolution_file_name = arg;
670       break;
671
672     case OPT_Wabi:
673       warn_psabi = value;
674       break;
675
676     default:
677       break;
678     }
679
680   return result;
681 }
682
683 /* Perform post-option processing.  Does additional initialization based on
684    command-line options.  PFILENAME is the main input filename.  Returns false
685    to enable subsequent back-end initialization.  */
686
687 static bool
688 lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
689 {
690   /* -fltrans and -fwpa are mutually exclusive.  Check for that here.  */
691   if (flag_wpa && flag_ltrans)
692     error ("-fwpa and -fltrans are mutually exclusive");
693
694   if (flag_ltrans)
695     {
696       flag_generate_lto = 0;
697
698       /* During LTRANS, we are not looking at the whole program, only
699          a subset of the whole callgraph.  */
700       flag_whole_program = 0;
701     }
702
703   if (flag_wpa)
704     flag_generate_lto = 1;
705
706   /* Excess precision other than "fast" requires front-end
707      support.  */
708   flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
709
710   lto_read_all_file_options ();
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 static int
955 lto_global_bindings_p (void) 
956 {
957   return cfun == NULL;
958 }
959
960 static void
961 lto_set_decl_assembler_name (tree decl)
962 {
963   /* This is almost the same as lhd_set_decl_assembler_name, except that
964      we need to uniquify file-scope names, even if they are not
965      TREE_PUBLIC, to avoid conflicts between individual files.  */
966   tree id;
967
968   if (TREE_PUBLIC (decl))
969     id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
970   else
971     {
972       const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
973       char *label;
974
975       ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
976       id = get_identifier (label);
977     }
978
979   SET_DECL_ASSEMBLER_NAME (decl, id);
980 }
981
982 static tree
983 lto_pushdecl (tree t ATTRIBUTE_UNUSED)
984 {
985   /* Do nothing, since we get all information from DWARF and LTO
986      sections.  */
987   return NULL_TREE;
988 }
989
990 static tree
991 lto_getdecls (void)
992 {
993   return registered_builtin_fndecls;
994 }
995
996 static void
997 lto_write_globals (void)
998 {
999   tree *vec = VEC_address (tree, lto_global_var_decls);
1000   int len = VEC_length (tree, lto_global_var_decls);
1001   wrapup_global_declarations (vec, len);
1002   emit_debug_global_declarations (vec, len);
1003   VEC_free (tree, gc, lto_global_var_decls);
1004 }
1005
1006 static tree
1007 lto_builtin_function (tree decl)
1008 {
1009   /* Record it.  */
1010   TREE_CHAIN (decl) = registered_builtin_fndecls;
1011   registered_builtin_fndecls = decl;
1012
1013   return decl;
1014 }
1015
1016 static void
1017 lto_register_builtin_type (tree type, const char *name)
1018 {
1019   tree decl;
1020
1021   decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier (name), type);
1022   DECL_ARTIFICIAL (decl) = 1;
1023   if (!TYPE_NAME (type))
1024     TYPE_NAME (type) = decl;
1025
1026   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
1027 }
1028
1029 /* Build nodes that would have be created by the C front-end; necessary
1030    for including builtin-types.def and ultimately builtins.def.  */
1031
1032 static void
1033 lto_build_c_type_nodes (void)
1034 {
1035   gcc_assert (void_type_node);
1036
1037   void_list_node = build_tree_list (NULL_TREE, void_type_node);
1038   string_type_node = build_pointer_type (char_type_node);
1039   const_string_type_node
1040     = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
1041
1042   if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1043     {
1044       intmax_type_node = integer_type_node;
1045       uintmax_type_node = unsigned_type_node;
1046       signed_size_type_node = integer_type_node;
1047     }
1048   else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1049     {
1050       intmax_type_node = long_integer_type_node;
1051       uintmax_type_node = long_unsigned_type_node;
1052       signed_size_type_node = long_integer_type_node;
1053     }
1054   else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1055     {
1056       intmax_type_node = long_long_integer_type_node;
1057       uintmax_type_node = long_long_unsigned_type_node;
1058       signed_size_type_node = long_long_integer_type_node;
1059     }
1060   else
1061     gcc_unreachable ();
1062
1063   wint_type_node = unsigned_type_node;
1064   pid_type_node = integer_type_node;
1065 }
1066
1067
1068 /* Perform LTO-specific initialization.  */
1069
1070 static bool
1071 lto_init (void)
1072 {
1073   /* We need to generate LTO if running in WPA mode.  */
1074   flag_generate_lto = flag_wpa;
1075
1076   /* Initialize libcpp line maps for gcc_assert to work.  */
1077   linemap_add (line_table, LC_RENAME, 0, NULL, 0);
1078   linemap_add (line_table, LC_RENAME, 0, NULL, 0);
1079
1080   /* Create the basic integer types.  */
1081   build_common_tree_nodes (flag_signed_char);
1082
1083   /* Share char_type_node with whatever would be the default for the target.
1084      char_type_node will be used for internal types such as
1085      va_list_type_node but will not be present in the lto stream.  */
1086   /* ???  This breaks the more common case of consistent but non-standard
1087      setting of flag_signed_char, so share according to flag_signed_char.
1088      See PR42528.  */
1089   char_type_node
1090     = flag_signed_char ? signed_char_type_node : unsigned_char_type_node;
1091
1092   /* Tell the middle end what type to use for the size of objects.  */
1093   if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1094     {
1095       set_sizetype (unsigned_type_node);
1096       size_type_node = unsigned_type_node;
1097     }
1098   else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1099     {
1100       set_sizetype (long_unsigned_type_node);
1101       size_type_node = long_unsigned_type_node;
1102     }
1103   else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1104     {
1105       set_sizetype (long_long_unsigned_type_node);
1106       size_type_node = long_long_unsigned_type_node;
1107     }
1108   else
1109     gcc_unreachable ();
1110
1111   /* The global tree for the main identifier is filled in by
1112      language-specific front-end initialization that is not run in the
1113      LTO back-end.  It appears that all languages that perform such
1114      initialization currently do so in the same way, so we do it here.  */
1115   if (main_identifier_node == NULL_TREE)
1116     main_identifier_node = get_identifier ("main");
1117
1118   /* In the C++ front-end, fileptr_type_node is defined as a variant
1119      copy of of ptr_type_node, rather than ptr_node itself.  The
1120      distinction should only be relevant to the front-end, so we
1121      always use the C definition here in lto1.  */
1122   gcc_assert (fileptr_type_node == ptr_type_node);
1123
1124   ptrdiff_type_node = integer_type_node;
1125
1126   /* Create other basic types.  */
1127   build_common_tree_nodes_2 (/*short_double=*/false);
1128   lto_build_c_type_nodes ();
1129   gcc_assert (va_list_type_node);
1130
1131   if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1132     {
1133       tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
1134       lto_define_builtins (x, x);
1135     }
1136   else
1137     {
1138       lto_define_builtins (va_list_type_node,
1139                            build_reference_type (va_list_type_node));
1140     }
1141
1142   targetm.init_builtins ();
1143   build_common_builtin_nodes ();
1144
1145   /* Assign names to the builtin types, otherwise they'll end up
1146      as __unknown__ in debug info.
1147      ???  We simply need to stop pre-seeding the streamer cache.
1148      Below is modeled after from c-common.c:c_common_nodes_and_builtins  */
1149 #define NAME_TYPE(t,n) \
1150   if (t) \
1151     TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \
1152                                 get_identifier (n), t)
1153   NAME_TYPE (integer_type_node, "int");
1154   NAME_TYPE (char_type_node, "char");
1155   NAME_TYPE (long_integer_type_node, "long int");
1156   NAME_TYPE (unsigned_type_node, "unsigned int");
1157   NAME_TYPE (long_unsigned_type_node, "long unsigned int");
1158   NAME_TYPE (long_long_integer_type_node, "long long int");
1159   NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int");
1160   NAME_TYPE (short_integer_type_node, "short int");
1161   NAME_TYPE (short_unsigned_type_node, "short unsigned int");
1162   if (signed_char_type_node != char_type_node)
1163     NAME_TYPE (signed_char_type_node, "signed char");
1164   if (unsigned_char_type_node != char_type_node)
1165     NAME_TYPE (unsigned_char_type_node, "unsigned char");
1166   NAME_TYPE (float_type_node, "float");
1167   NAME_TYPE (double_type_node, "double");
1168   NAME_TYPE (long_double_type_node, "long double");
1169   NAME_TYPE (void_type_node, "void");
1170   NAME_TYPE (boolean_type_node, "bool");
1171 #undef NAME_TYPE
1172
1173   /* Initialize LTO-specific data structures.  */
1174   lto_global_var_decls = VEC_alloc (tree, gc, 256);
1175   in_lto_p = true;
1176
1177   return true;
1178 }
1179
1180 /* Initialize tree structures required by the LTO front end.  */
1181
1182 static void lto_init_ts (void)
1183 {
1184   tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1185 }
1186
1187 #undef LANG_HOOKS_NAME
1188 #define LANG_HOOKS_NAME "GNU GIMPLE"
1189 #undef LANG_HOOKS_OPTION_LANG_MASK
1190 #define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
1191 #undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
1192 #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
1193 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1194 #define LANG_HOOKS_INIT_OPTIONS_STRUCT lto_init_options_struct
1195 #undef LANG_HOOKS_HANDLE_OPTION
1196 #define LANG_HOOKS_HANDLE_OPTION lto_handle_option
1197 #undef LANG_HOOKS_POST_OPTIONS
1198 #define LANG_HOOKS_POST_OPTIONS lto_post_options
1199 #undef LANG_HOOKS_GET_ALIAS_SET
1200 #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
1201 #undef LANG_HOOKS_TYPE_FOR_MODE
1202 #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
1203 #undef LANG_HOOKS_TYPE_FOR_SIZE
1204 #define LANG_HOOKS_TYPE_FOR_SIZE lto_type_for_size
1205 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
1206 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
1207 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1208 #define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
1209 #undef LANG_HOOKS_PUSHDECL
1210 #define LANG_HOOKS_PUSHDECL lto_pushdecl
1211 #undef LANG_HOOKS_GETDECLS
1212 #define LANG_HOOKS_GETDECLS lto_getdecls
1213 #undef LANG_HOOKS_WRITE_GLOBALS
1214 #define LANG_HOOKS_WRITE_GLOBALS lto_write_globals
1215 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1216 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
1217 #undef LANG_HOOKS_BUILTIN_FUNCTION
1218 #define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
1219 #undef LANG_HOOKS_INIT
1220 #define LANG_HOOKS_INIT lto_init
1221 #undef LANG_HOOKS_PARSE_FILE
1222 #define LANG_HOOKS_PARSE_FILE lto_main
1223 #undef LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION
1224 #define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION tree_rest_of_compilation
1225 #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
1226 #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
1227 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1228 #define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
1229 #undef LANG_HOOKS_EH_PERSONALITY
1230 #define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
1231
1232 /* Attribute hooks.  */
1233 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1234 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
1235 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
1236 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
1237
1238 #undef LANG_HOOKS_BEGIN_SECTION
1239 #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
1240 #undef LANG_HOOKS_APPEND_DATA
1241 #define LANG_HOOKS_APPEND_DATA lto_obj_append_data
1242 #undef LANG_HOOKS_END_SECTION
1243 #define LANG_HOOKS_END_SECTION lto_obj_end_section
1244
1245 #undef LANG_HOOKS_INIT_TS
1246 #define LANG_HOOKS_INIT_TS lto_init_ts
1247
1248 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1249
1250 /* Language hooks that are not part of lang_hooks.  */
1251
1252 tree
1253 convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1254 {
1255   gcc_unreachable ();
1256 }
1257
1258 /* Tree walking support.  */
1259
1260 static enum lto_tree_node_structure_enum
1261 lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
1262 {
1263   return TS_LTO_GENERIC;
1264 }
1265
1266 #include "ggc.h"
1267 #include "gtype-lto.h"
1268 #include "gt-lto-lto-lang.h"