From patchwork Mon May 19 15:24:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xinliang David Li X-Patchwork-Id: 350287 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4105814008A for ; Tue, 20 May 2014 01:24:55 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=gNB02ulF9N6bf+e0fx KKWJ5rQivn7xIm06iykhVDqG7N9yrenAPoiFGa0Jes9whs1kHXBxR8G6Ur1W7QIN 75IFJ8sXW9ux70fcvd9U5L0yo3QKoaqELlEbAufoxOQLlMEBC4ojqFbCeTY8lOFQ BSOqIVgb7z0FUSaMEOku/KaiE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=2fMrpE9UqIVV38qtNEqvqkCk pUw=; b=clQkn4dfrm1kWORt+mS6qRFAv2m02ayscrCujqNN47ojm9thfvKxYuNE 8D9Hgvxb83BtXg3puN9FySS1KWDAYdNOR9WgoDCAg+MbRdhpy7ZH9W/hE2g2WfOC K+I2NyqWA177Pjf1PY7k7MYbF5tiUrr7isXRIM6wM6fnaVoI6wA= Received: (qmail 725 invoked by alias); 19 May 2014 15:24:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 708 invoked by uid 89); 19 May 2014 15:24:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f169.google.com Received: from mail-wi0-f169.google.com (HELO mail-wi0-f169.google.com) (209.85.212.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 19 May 2014 15:24:32 +0000 Received: by mail-wi0-f169.google.com with SMTP id hi2so5399132wib.0 for ; Mon, 19 May 2014 08:24:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=+vyc6J41HfQxA+KeIPILMC1u3pjbmFXHyxXMptTjwS4=; b=eNXYh3JcLwayVIiaxGbHks1bbR4EpBM7D16A6jxzwWL30ZXmzR4UgHC2PHxIg09o9q q5m/nunmB0igOkJwJWYJPPiO4pjcqkG4qZ5IkiQzOeW7Z0QxQFCS4XlWKkuKHfgcwBMQ v1J+8fPt+MGJf/rmEi+hSZepWpGiBN12LXbZzU/zhRAYubQYT22IGDkOLibRGPZcURVn qsdHppFVRjQcr76y6LUXS+OvyIW7BK+AQBdhXRegiJRY09+bd27aOMyyLJKlVnEwGHD8 6GxS9p2mROo/pq3BVaZogam3ah2ahh5IsH4Z/XIe2OtgRhdJvv/GFLpLVWzGgd6gBlg7 /MkA== X-Gm-Message-State: ALoCoQmMNt/cMVl6ZOeYvJhGbUonpi6csyAqKcxs+GMyHWYL4sxsYTcX5b34rOvJfg+SHpO6nC9n MIME-Version: 1.0 X-Received: by 10.194.92.7 with SMTP id ci7mr30639457wjb.7.1400513068745; Mon, 19 May 2014 08:24:28 -0700 (PDT) Received: by 10.180.86.1 with HTTP; Mon, 19 May 2014 08:24:28 -0700 (PDT) In-Reply-To: References: <20140516160323.GE20755@kam.mff.cuni.cz> Date: Mon, 19 May 2014 08:24:28 -0700 Message-ID: Subject: Re: add dbgcnt and opt-info support for devirtualization From: Xinliang David Li To: Richard Biener Cc: Jan Hubicka , GCC Patches X-IsSubscribed: yes Sorry about it. Here is the patch. There is one remaining case where cgraph_dump_file and dump_enable_p are checked separately -- cgraph_dump_file is set up differently from 'dump_file'. David On Mon, May 19, 2014 at 2:21 AM, Richard Biener wrote: > On Fri, May 16, 2014 at 11:19 PM, Xinliang David Li wrote: >> Modified the patch according to yours and Richard's feedback. PTAL. > > ENOPATCH. > > Btw, I don't see any issue with leaking node order to opt-report. > > Richard. > >> thanks, >> >> David >> >> On Fri, May 16, 2014 at 9:03 AM, Jan Hubicka wrote: >>>> Hi, debugging runtime bugs due to devirtualization can be hard for >>>> very large C++ programs with complicated class hierarchy. This patch >>>> adds the support to report this high level transformation via >>>> -fopt-info (not hidden inside dump file) and the ability the do binary >>>> search with cutoff. >>>> >>>> Ok for trunk after build and test? >>> >>> Seems resonable to me. >>>> >>>> thanks, >>>> >>>> David >>> >>>> Index: ChangeLog >>>> =================================================================== >>>> --- ChangeLog (revision 210479) >>>> +++ ChangeLog (working copy) >>>> @@ -1,3 +1,18 @@ >>>> +2014-05-15 Xinliang David Li >>>> + >>>> + * cgraphunit.c (walk_polymorphic_call_targets): Add >>>> + dbgcnt and fopt-info support. >>>> + 2014-05-15 Xinliang David Li >>>> + >>>> + * cgraphunit.c (walk_polymorphic_call_targets): Add >>>> + dbgcnt and fopt-info support. >>>> + * ipa-prop.c (ipa_make_edge_direct_to_target): Ditto. >>>> + * ipa-devirt.c (ipa_devirt): Ditto. >>>> + * ipa.c (walk_polymorphic_call_targets): Ditto. >>>> + * gimple-fold.c (fold_gimple_assign): Ditto. >>>> + (gimple_fold_call): Ditto. >>>> + * dbgcnt.def: New counter. >>>> + >>>> 2014-05-15 Martin Jambor >>>> >>>> PR ipa/61085 >>>> Index: ipa-prop.c >>>> =================================================================== >>>> --- ipa-prop.c (revision 210479) >>>> +++ ipa-prop.c (working copy) >>>> @@ -59,6 +59,7 @@ along with GCC; see the file COPYING3. >>>> #include "ipa-utils.h" >>>> #include "stringpool.h" >>>> #include "tree-ssanames.h" >>>> +#include "dbgcnt.h" >>>> >>>> /* Intermediate information about a parameter that is only useful during the >>>> run of ipa_analyze_node and is not kept afterwards. */ >>>> @@ -2494,6 +2495,13 @@ ipa_make_edge_direct_to_target (struct c >>>> fprintf (dump_file, "ipa-prop: Discovered direct call to non-function" >>>> " in %s/%i, making it unreachable.\n", >>>> ie->caller->name (), ie->caller->order); >>>> + else if (dump_enabled_p ()) >>>> + { >>>> + location_t loc = gimple_location (ie->call_stmt); >>>> + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, >>>> + "Discovered direct call to non-function in %s, " >>>> + "making it unreachable\n", ie->caller->name ()); >>> >>> Perhaps "turning it to __builtin_unreachable call" and similarly in the other cases >>> we introduce __builtin_unreachable? I think that could be easier for user to work >>> out. >>> >>> What king of problems in devirtualizatoin you are seeing? >>> >>> >>> Honza Index: cgraphunit.c =================================================================== --- cgraphunit.c (revision 210479) +++ cgraphunit.c (working copy) @@ -210,6 +210,7 @@ along with GCC; see the file COPYING3. #include "pass_manager.h" #include "tree-nested.h" #include "gimplify.h" +#include "dbgcnt.h" /* Queue of cgraph nodes scheduled to be added into cgraph. This is a secondary queue used during optimization to accommodate passes that @@ -886,7 +887,7 @@ walk_polymorphic_call_targets (pointer_s make the edge direct. */ if (final) { - if (targets.length () <= 1) + if (targets.length () <= 1 && dbg_cnt (devirt)) { cgraph_node *target; if (targets.length () == 1) @@ -903,6 +904,14 @@ walk_polymorphic_call_targets (pointer_s edge->call_stmt, 0, TDF_SLIM); } + else if (dump_enabled_p ()) + { + location_t locus = gimple_location (edge->call_stmt); + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, locus, + "devirtualizing call in %s to %s\n", + edge->caller->name (), target->name ()); + } + cgraph_make_edge_direct (edge, target); cgraph_redirect_edge_call_stmt_to_callee (edge); if (cgraph_dump_file) Index: ipa-prop.c =================================================================== --- ipa-prop.c (revision 210479) +++ ipa-prop.c (working copy) @@ -59,6 +59,7 @@ along with GCC; see the file COPYING3. #include "ipa-utils.h" #include "stringpool.h" #include "tree-ssanames.h" +#include "dbgcnt.h" /* Intermediate information about a parameter that is only useful during the run of ipa_analyze_node and is not kept afterwards. */ @@ -2490,10 +2491,15 @@ ipa_make_edge_direct_to_target (struct c /* Member pointer call that goes through a VMT lookup. */ return NULL; - if (dump_file) - fprintf (dump_file, "ipa-prop: Discovered direct call to non-function" - " in %s/%i, making it unreachable.\n", - ie->caller->name (), ie->caller->order); + if (dump_enabled_p ()) + { + location_t loc = gimple_location (ie->call_stmt); + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, + "discovered direct call to non-function in %s/%i, " + "making it __builtin_unreachable\n", + ie->caller->name (), + ie->caller->order); + } target = builtin_decl_implicit (BUILT_IN_UNREACHABLE); callee = cgraph_get_create_node (target); unreachable = true; @@ -2527,6 +2533,10 @@ ipa_make_edge_direct_to_target (struct c } callee = cgraph_get_create_node (target); } + + if (!dbg_cnt (devirt)) + return NULL; + ipa_check_create_node_params (); /* We can not make edges to inline clones. It is bug that someone removed @@ -2547,6 +2557,13 @@ ipa_make_edge_direct_to_target (struct c else fprintf (dump_file, "with uid %i\n", ie->lto_stmt_uid); } + if (dump_enabled_p ()) + { + location_t loc = gimple_location (ie->call_stmt); + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, + "converting indirect call in %s to direct call to %s\n", + ie->caller->name (), callee->name ()); + } ie = cgraph_make_edge_direct (ie, callee); es = inline_edge_summary (ie); es->call_stmt_size -= (eni_size_weights.indirect_call_cost Index: ipa.c =================================================================== --- ipa.c (revision 210479) +++ ipa.c (working copy) @@ -37,6 +37,10 @@ along with GCC; see the file COPYING3. #include "tree-inline.h" #include "profile.h" #include "params.h" +#include "internal-fn.h" +#include "tree-ssa-alias.h" +#include "gimple.h" +#include "dbgcnt.h" /* Return true when NODE can not be local. Worker for cgraph_local_node_p. */ @@ -213,7 +217,7 @@ walk_polymorphic_call_targets (pointer_s make the edge direct. */ if (final) { - if (targets.length () <= 1) + if (targets.length () <= 1 && dbg_cnt (devirt)) { cgraph_node *target, *node = edge->caller; if (targets.length () == 1) @@ -222,12 +226,15 @@ walk_polymorphic_call_targets (pointer_s target = cgraph_get_create_node (builtin_decl_implicit (BUILT_IN_UNREACHABLE)); - if (dump_file) - fprintf (dump_file, - "Devirtualizing call in %s/%i to %s/%i\n", - edge->caller->name (), - edge->caller->order, - target->name (), target->order); + if (dump_enabled_p ()) + { + location_t locus = gimple_location (edge->call_stmt); + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, locus, + "devirtualizing call in %s/%i to %s/%i\n", + edge->caller->name (), edge->caller->order, + target->name (), + target->order); + } edge = cgraph_make_edge_direct (edge, target); if (inline_summary_vec) inline_update_overall_summary (node); Index: ipa-devirt.c =================================================================== --- ipa-devirt.c (revision 210479) +++ ipa-devirt.c (working copy) @@ -129,6 +129,7 @@ along with GCC; see the file COPYING3. #include "diagnostic.h" #include "tree-dfa.h" #include "demangle.h" +#include "dbgcnt.h" static bool odr_violation_reported = false; @@ -2067,14 +2068,17 @@ ipa_devirt (void) noverwritable++; continue; } - else + else if (dbg_cnt (devirt)) { - if (dump_file) - fprintf (dump_file, - "Speculatively devirtualizing call in %s/%i to %s/%i\n\n", - n->name (), n->order, - likely_target->name (), - likely_target->order); + if (dump_enabled_p ()) + { + location_t locus = gimple_location (e->call_stmt); + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, locus, + "speculatively devirtualizing call in %s/%i to %s/%i\n", + n->name (), n->order, + likely_target->name (), + likely_target->order); + } if (!symtab_can_be_discarded (likely_target)) { cgraph_node *alias; Index: dbgcnt.def =================================================================== --- dbgcnt.def (revision 210479) +++ dbgcnt.def (working copy) @@ -150,6 +150,7 @@ DEBUG_COUNTER (dce) DEBUG_COUNTER (dce_fast) DEBUG_COUNTER (dce_ud) DEBUG_COUNTER (delete_trivial_dead) +DEBUG_COUNTER (devirt) DEBUG_COUNTER (df_byte_scan) DEBUG_COUNTER (dse) DEBUG_COUNTER (dse1) Index: gimple-fold.c =================================================================== --- gimple-fold.c (revision 210479) +++ gimple-fold.c (working copy) @@ -52,6 +52,7 @@ along with GCC; see the file COPYING3. #include "tree-ssa-address.h" #include "langhooks.h" #include "gimplify-me.h" +#include "dbgcnt.h" /* Return true when DECL can be referenced from current unit. FROM_DECL (if non-null) specify constructor of variable DECL was taken from. @@ -386,13 +387,24 @@ fold_gimple_assign (gimple_stmt_iterator bool final; vec targets = possible_polymorphic_call_targets (val, &final); - if (final && targets.length () <= 1) + if (final && targets.length () <= 1 && dbg_cnt (devirt)) { tree fndecl; + if (targets.length () == 1) fndecl = targets[0]->decl; else fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE); + if (dump_enabled_p ()) + { + location_t loc = gimple_location (stmt); + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, + "resolving virtual function address " + "reference to function %s\n", + targets.length () == 1 + ? targets[0]->name () + : "__builtin_unreachable"); + } val = fold_convert (TREE_TYPE (val), fndecl); STRIP_USELESS_TYPE_CONVERSION (val); return val; @@ -1124,9 +1136,18 @@ gimple_fold_call (gimple_stmt_iterator * bool final; vec targets = possible_polymorphic_call_targets (callee, &final); - if (final && targets.length () <= 1) + if (final && targets.length () <= 1 && dbg_cnt (devirt)) { tree lhs = gimple_call_lhs (stmt); + if (dump_enabled_p ()) + { + location_t loc = gimple_location (stmt); + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, + "folding virtual function call to %s\n", + targets.length () == 1 + ? targets[0]->name () + : "__builtin_unreachable"); + } if (targets.length () == 1) { gimple_call_set_fndecl (stmt, targets[0]->decl); Index: tree-ssa-pre.c =================================================================== --- tree-ssa-pre.c (revision 210479) +++ tree-ssa-pre.c (working copy) @@ -4347,18 +4347,19 @@ eliminate_dom_walker::before_dom_childre continue; if (gimple_call_addr_fndecl (fn) != NULL_TREE && useless_type_conversion_p (TREE_TYPE (orig_fn), - TREE_TYPE (fn))) + TREE_TYPE (fn)) + && dbg_cnt (devirt)) { bool can_make_abnormal_goto = stmt_can_make_abnormal_goto (stmt); bool was_noreturn = gimple_call_noreturn_p (stmt); - if (dump_file && (dump_flags & TDF_DETAILS)) + if (dump_enabled_p ()) { - fprintf (dump_file, "Replacing call target with "); - print_generic_expr (dump_file, fn, 0); - fprintf (dump_file, " in "); - print_gimple_stmt (dump_file, stmt, 0, 0); + location_t loc = gimple_location (stmt); + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, + "converting indirect call to function %s\n", + cgraph_get_node (fn)->name ()); } gimple_call_set_fn (stmt, fn); Index: ChangeLog =================================================================== --- ChangeLog (revision 210479) +++ ChangeLog (working copy) @@ -1,3 +1,20 @@ +2014-05-15 Xinliang David Li + + * cgraphunit.c (walk_polymorphic_call_targets): Add + dbgcnt and fopt-info support. + 2014-05-15 Xinliang David Li + + * cgraphunit.c (walk_polymorphic_call_targets): Add + dbgcnt and fopt-info support. + * ipa-prop.c (ipa_make_edge_direct_to_target): Ditto. + * ipa-devirt.c (ipa_devirt): Ditto. + * tree-ssa-pre.c (eliminate_dom_walker::before_dom_children): + Ditto. + * ipa.c (walk_polymorphic_call_targets): Ditto. + * gimple-fold.c (fold_gimple_assign): Ditto. + (gimple_fold_call): Ditto. + * dbgcnt.def: New counter. + 2014-05-15 Martin Jambor PR ipa/61085