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