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