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