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