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