comparison gcc/ipa.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Basic IPA optimizations and utilities. 1 /* Basic IPA optimizations and utilities.
2 Copyright (C) 2003-2017 Free Software Foundation, Inc. 2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
128 DECL_ATTRIBUTES (body->decl)))))) 128 DECL_ATTRIBUTES (body->decl))))))
129 /* We use variable constructors during late compilation for 129 /* We use variable constructors during late compilation for
130 constant folding. Keep references alive so partitioning 130 constant folding. Keep references alive so partitioning
131 knows about potential references. */ 131 knows about potential references. */
132 || (VAR_P (node->decl) 132 || (VAR_P (node->decl)
133 && flag_wpa 133 && (flag_wpa
134 && ctor_for_folding (node->decl) 134 || flag_incremental_link
135 != error_mark_node)))) 135 == INCREMENTAL_LINK_LTO)
136 && dyn_cast <varpool_node *> (node)
137 ->ctor_useable_for_folding_p ()))))
136 { 138 {
137 /* Be sure that we will not optimize out alias target 139 /* Be sure that we will not optimize out alias target
138 body. */ 140 body. */
139 if (DECL_EXTERNAL (node->decl) 141 if (DECL_EXTERNAL (node->decl)
140 && node->alias 142 && node->alias
221 else 223 else
222 target = cgraph_node::get_create 224 target = cgraph_node::get_create
223 (builtin_decl_implicit (BUILT_IN_UNREACHABLE)); 225 (builtin_decl_implicit (BUILT_IN_UNREACHABLE));
224 226
225 if (dump_enabled_p ()) 227 if (dump_enabled_p ())
226 { 228 {
227 location_t locus; 229 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, edge->call_stmt,
228 if (edge->call_stmt)
229 locus = gimple_location (edge->call_stmt);
230 else
231 locus = UNKNOWN_LOCATION;
232 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, locus,
233 "devirtualizing call in %s to %s\n", 230 "devirtualizing call in %s to %s\n",
234 edge->caller->dump_name (), 231 edge->caller->dump_name (),
235 target->dump_name ()); 232 target->dump_name ());
236 } 233 }
237 edge = edge->make_direct (target); 234 edge = edge->make_direct (target);
238 if (ipa_fn_summaries) 235 if (ipa_fn_summaries)
239 ipa_update_overall_fn_summary (node); 236 ipa_update_overall_fn_summary (node);
240 else if (edge->call_stmt) 237 else if (edge->call_stmt)
241 { 238 edge->redirect_call_stmt_to_callee ();
242 edge->redirect_call_stmt_to_callee ();
243
244 /* Call to __builtin_unreachable shouldn't be instrumented. */
245 if (!targets.length ())
246 gimple_call_set_with_bounds (edge->call_stmt, false);
247 }
248 } 239 }
249 } 240 }
250 } 241 }
251 242
252 /* Perform reachability analysis and reclaim all unreachable nodes. 243 /* Perform reachability analysis and reclaim all unreachable nodes.
458 /* When inline clone exists, mark body to be preserved so when removing 449 /* When inline clone exists, mark body to be preserved so when removing
459 offline copy of the function we don't kill it. */ 450 offline copy of the function we don't kill it. */
460 if (cnode->global.inlined_to) 451 if (cnode->global.inlined_to)
461 body_needed_for_clonning.add (cnode->decl); 452 body_needed_for_clonning.add (cnode->decl);
462 453
463 /* For instrumentation clones we always need original
464 function node for proper LTO privatization. */
465 if (cnode->instrumentation_clone
466 && cnode->definition)
467 {
468 gcc_assert (cnode->instrumented_version || in_lto_p);
469 if (cnode->instrumented_version)
470 {
471 enqueue_node (cnode->instrumented_version, &first,
472 &reachable);
473 reachable.add (cnode->instrumented_version);
474 }
475 }
476
477 /* For non-inline clones, force their origins to the boundary and ensure 454 /* For non-inline clones, force their origins to the boundary and ensure
478 that body is not removed. */ 455 that body is not removed. */
479 while (cnode->clone_of) 456 while (cnode->clone_of)
480 { 457 {
481 bool noninline = cnode->clone_of->decl != cnode->decl; 458 bool noninline = cnode->clone_of->decl != cnode->decl;
620 } 597 }
621 if (file) 598 if (file)
622 fprintf (file, " %s", vnode->dump_name ()); 599 fprintf (file, " %s", vnode->dump_name ());
623 vnext = next_variable (vnode); 600 vnext = next_variable (vnode);
624 /* Signal removal to the debug machinery. */ 601 /* Signal removal to the debug machinery. */
625 if (! flag_wpa) 602 if (! flag_wpa || flag_incremental_link == INCREMENTAL_LINK_LTO)
626 { 603 {
627 vnode->definition = false; 604 vnode->definition = false;
628 (*debug_hooks->late_global_decl) (vnode->decl); 605 (*debug_hooks->late_global_decl) (vnode->decl);
629 } 606 }
630 vnode->remove (); 607 vnode->remove ();
638 if (file) 615 if (file)
639 fprintf (file, " %s", vnode->name ()); 616 fprintf (file, " %s", vnode->name ());
640 changed = true; 617 changed = true;
641 } 618 }
642 /* Keep body if it may be useful for constant folding. */ 619 /* Keep body if it may be useful for constant folding. */
643 if ((init = ctor_for_folding (vnode->decl)) == error_mark_node 620 if ((flag_wpa || flag_incremental_link == INCREMENTAL_LINK_LTO)
644 && !POINTER_BOUNDS_P (vnode->decl)) 621 || ((init = ctor_for_folding (vnode->decl)) == error_mark_node))
645 vnode->remove_initializer (); 622 vnode->remove_initializer ();
646 else 623 else
647 DECL_INITIAL (vnode->decl) = init; 624 DECL_INITIAL (vnode->decl) = init;
648 vnode->body_removed = true; 625 vnode->body_removed = true;
649 vnode->definition = false; 626 vnode->definition = false;
664 FOR_EACH_DEFINED_FUNCTION (node) 641 FOR_EACH_DEFINED_FUNCTION (node)
665 if (node->address_taken 642 if (node->address_taken
666 && !node->used_from_other_partition) 643 && !node->used_from_other_partition)
667 { 644 {
668 if (!node->call_for_symbol_and_aliases 645 if (!node->call_for_symbol_and_aliases
669 (has_addr_references_p, NULL, true) 646 (has_addr_references_p, NULL, true))
670 && (!node->instrumentation_clone
671 || !node->instrumented_version
672 || !node->instrumented_version->address_taken))
673 { 647 {
674 if (file) 648 if (file)
675 fprintf (file, " %s", node->name ()); 649 fprintf (file, " %s", node->name ());
676 node->address_taken = false; 650 node->address_taken = false;
677 changed = true; 651 changed = true;
735 break; 709 break;
736 case IPA_REF_ALIAS: 710 case IPA_REF_ALIAS:
737 process_references (dyn_cast<varpool_node *> (ref->referring), written, 711 process_references (dyn_cast<varpool_node *> (ref->referring), written,
738 address_taken, read, explicit_refs); 712 address_taken, read, explicit_refs);
739 break; 713 break;
740 case IPA_REF_CHKP:
741 gcc_unreachable ();
742 } 714 }
743 } 715 }
744 716
745 /* Set TREE_READONLY bit. */ 717 /* Set TREE_READONLY bit. */
746 718
842 fprintf (dump_file, "\n"); 814 fprintf (dump_file, "\n");
843 return remove_p; 815 return remove_p;
844 } 816 }
845 817
846 /* Generate and emit a static constructor or destructor. WHICH must 818 /* Generate and emit a static constructor or destructor. WHICH must
847 be one of 'I' (for a constructor), 'D' (for a destructor), 'P' 819 be one of 'I' (for a constructor), 'D' (for a destructor).
848 (for chp static vars constructor) or 'B' (for chkp static bounds 820 BODY is a STATEMENT_LIST containing GENERIC
849 constructor). BODY is a STATEMENT_LIST containing GENERIC
850 statements. PRIORITY is the initialization priority for this 821 statements. PRIORITY is the initialization priority for this
851 constructor or destructor. 822 constructor or destructor.
852 823
853 FINAL specify whether the externally visible name for collect2 should 824 FINAL specify whether the externally visible name for collect2 should
854 be produced. */ 825 be produced. */
907 { 878 {
908 case 'I': 879 case 'I':
909 DECL_STATIC_CONSTRUCTOR (decl) = 1; 880 DECL_STATIC_CONSTRUCTOR (decl) = 1;
910 decl_init_priority_insert (decl, priority); 881 decl_init_priority_insert (decl, priority);
911 break; 882 break;
912 case 'P':
913 DECL_STATIC_CONSTRUCTOR (decl) = 1;
914 DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("chkp ctor"),
915 NULL,
916 NULL_TREE);
917 decl_init_priority_insert (decl, priority);
918 break;
919 case 'B':
920 DECL_STATIC_CONSTRUCTOR (decl) = 1;
921 DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("bnd_legacy"),
922 NULL,
923 NULL_TREE);
924 decl_init_priority_insert (decl, priority);
925 break;
926 case 'D': 883 case 'D':
927 DECL_STATIC_DESTRUCTOR (decl) = 1; 884 DECL_STATIC_DESTRUCTOR (decl) = 1;
928 decl_fini_priority_insert (decl, priority); 885 decl_fini_priority_insert (decl, priority);
929 break; 886 break;
930 default: 887 default:
938 set_cfun (NULL); 895 set_cfun (NULL);
939 current_function_decl = NULL; 896 current_function_decl = NULL;
940 } 897 }
941 898
942 /* Generate and emit a static constructor or destructor. WHICH must 899 /* Generate and emit a static constructor or destructor. WHICH must
943 be one of 'I' (for a constructor), 'D' (for a destructor), 'P' 900 be one of 'I' (for a constructor) or 'D' (for a destructor).
944 (for chkp static vars constructor) or 'B' (for chkp static bounds 901 BODY is a STATEMENT_LIST containing GENERIC
945 constructor). BODY is a STATEMENT_LIST containing GENERIC
946 statements. PRIORITY is the initialization priority for this 902 statements. PRIORITY is the initialization priority for this
947 constructor or destructor. */ 903 constructor or destructor. */
948 904
949 void 905 void
950 cgraph_build_static_cdtor (char which, tree body, int priority) 906 cgraph_build_static_cdtor (char which, tree body, int priority)