Debian Codegraph @

gcc/lto/lto-lang.cc

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