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