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