From patchwork Mon Feb 27 16:35:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 732950 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 3vX6sQ5BBGz9s9r for ; Tue, 28 Feb 2017 03:40:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XuQWA+bv"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :resent-from:resent-date:resent-message-id:resent-to:message-id :in-reply-to:references:from:date:subject:to:cc; q=dns; s= default; b=cbo/U2EynxpxSCV7+YoeV+hir9Uv9j/4KPHYI+8d8Tg4fwnvfsL2g O4fiygKdDuYxTvq/3Ei7HQls9VgfnzgwlLrTpLRnUt/mstrsidyrzIR5Gjxa5jLx 8JsmgmIGozXHrCpYPu9MrMCR+WhjjSxHXqAwYpTZNdfEH4GqzgbCqc= 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 :resent-from:resent-date:resent-message-id:resent-to:message-id :in-reply-to:references:from:date:subject:to:cc; s=default; bh=X F/wd0dx5gh50SlP40rIINMNDYs=; b=XuQWA+bvK+wDf63yObUrYQcIkk1MAsW6k hI4MvzYvn5SkcX55UoL6dTfYQDF/y4qW6Usw34tNRdY6rSNnzId9xfqjVDD2Jy80 GieX2Vthp/AQARcFyjiTFbkDtjdq9TaLVQ5CIq36DEpgLqSDKavpROhtYw4LgrPn 4sKyXewGIc= Received: (qmail 120378 invoked by alias); 27 Feb 2017 16:39:50 -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 120207 invoked by uid 89); 27 Feb 2017 16:39:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=gigantic, registering X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Feb 2017 16:39:45 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 60C35AD45 for ; Mon, 27 Feb 2017 16:39:43 +0000 (UTC) Resent-From: Martin Jambor Resent-Date: Mon, 27 Feb 2017 17:39:42 +0100 Resent-Message-ID: <20170227163942.qdgkwxkmyr7spdgh@virgil.suse.cz> Resent-To: GCC Patches , Jan Hubicka , Martin Liska Message-Id: <6f917f9291ca035ee572f81e1600f7894408cee9.1488213408.git.mjambor@suse.cz> In-Reply-To: References: From: Martin Jambor Date: Mon, 27 Feb 2017 17:35:22 +0100 Subject: [RFC PATCH 2/3] Use call_summary in ipa-prop and ipa-cp To: GCC Patches Cc: Jan Hubicka , Martin Liska X-IsSubscribed: yes Hello, this is patch is afairly straightforward conversion from use of a vector indexed by edge->uid to use of the new call_summary from the previous patch. The patch is generally a cleanup, hashing is a nicer method of keeping call-site related information than a gigantic vector that we never shrink during its lifetime. Moreover, it should allow further cleanups and of course is a nice way of testing that the previous patch works. Any comments and/or suggestions are welcome, Martin 2017-02-27 Martin Jambor * ipa-prop.h (ipa_edge_args): Make a class. Mark with for_user GTY tag. Added a default constructor and a destructor. (ipa_edge_args_sum_t): New class; (ipa_edge_args_sum): Declare. (ipa_edge_args_vector): Remove declaration. (IPA_EDGE_REF): Use ipa_edge_args_sum. (ipa_free_edge_args_substructures): Remove declaration. (ipa_check_create_edge_args): Use ipa_edge_args_sum. (ipa_edge_args_info_available_for_edge_p): Likewise. * ipa-prop.c (ipa_edge_args_vector): Removed. (edge_removal_hook_holder): Likewise. (edge_duplication_hook_holder): Likewise. (ipa_edge_args_sum): New variable. (ipa_propagate_indirect_call_infos): Test ipa_edge_args_sum instead of ipa_edge_args_vector. (ipa_free_edge_args_substructures): Likewise. (ipa_free_all_edge_args): Free ipa_edge_args_sum instead of ipa_edge_args_vector. (ipa_edge_removal_hook): Turned into method ipa_edge_args_sum_t::remove. (ipa_edge_duplication_hook): Turned into method ipa_edge_args_sum_t::duplicate. (ipa_register_cgraph_hooks): Create ipa_edge_args_sum instead of registering edge hooks. (ipa_unregister_cgraph_hooks): Do not unregister edge hooks. * ipa-inline-analysis.c (estimate_function_body_sizes): Test ipa_edge_args_sum instead of ipa_edge_args_vector. * ipa-profile.c (ipa_profile): Likewise. --- gcc/ipa-inline-analysis.c | 2 +- gcc/ipa-profile.c | 2 +- gcc/ipa-prop.c | 71 +++++++++++------------------------------------ gcc/ipa-prop.h | 59 +++++++++++++++++++++++++++++---------- 4 files changed, 63 insertions(+), 71 deletions(-) diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c index 611faab570f..639fc05fccd 100644 --- a/gcc/ipa-inline-analysis.c +++ b/gcc/ipa-inline-analysis.c @@ -2937,7 +2937,7 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early) { if (!early) loop_optimizer_finalize (); - else if (!ipa_edge_args_vector) + else if (!ipa_edge_args_sum) ipa_free_all_node_params (); free_dominance_info (CDI_DOMINATORS); } diff --git a/gcc/ipa-profile.c b/gcc/ipa-profile.c index ae1ca2f3762..0bfbfa1e447 100644 --- a/gcc/ipa-profile.c +++ b/gcc/ipa-profile.c @@ -620,7 +620,7 @@ ipa_profile (void) "Not speculating: target is overwritable " "and can be discarded.\n"); } - else if (ipa_node_params_sum && ipa_edge_args_vector + else if (ipa_node_params_sum && ipa_edge_args_sum && (!vec_safe_is_empty (IPA_NODE_REF (n2)->descriptors)) && ipa_get_param_count (IPA_NODE_REF (n2)) diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index e4e44ce20c6..6d598763d02 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -57,12 +57,10 @@ along with GCC; see the file COPYING3. If not see ipa_node_params_t *ipa_node_params_sum = NULL; /* Vector of IPA-CP transformation data for each clone. */ vec *ipcp_transformations; -/* Vector where the parameter infos are actually stored. */ -vec *ipa_edge_args_vector; +/* Edge summary for IPA-CP edge information. */ +ipa_edge_args_sum_t *ipa_edge_args_sum; /* Holders of ipa cgraph hooks: */ -static struct cgraph_edge_hook_list *edge_removal_hook_holder; -static struct cgraph_2edge_hook_list *edge_duplication_hook_holder; static struct cgraph_node_hook_list *function_insertion_hook_holder; /* Description of a reference to an IPA constant. */ @@ -3537,7 +3535,7 @@ ipa_propagate_indirect_call_infos (struct cgraph_edge *cs, (i.e. during early inlining). */ if (!ipa_node_params_sum) return false; - gcc_assert (ipa_edge_args_vector); + gcc_assert (ipa_edge_args_sum); propagate_controlled_uses (cs); changed = propagate_info_to_inlined_callees (cs, cs->callee, new_edges); @@ -3545,31 +3543,16 @@ ipa_propagate_indirect_call_infos (struct cgraph_edge *cs, return changed; } -/* Frees all dynamically allocated structures that the argument info points - to. */ - -void -ipa_free_edge_args_substructures (struct ipa_edge_args *args) -{ - vec_free (args->jump_functions); - memset (args, 0, sizeof (*args)); -} - /* Free all ipa_edge structures. */ void ipa_free_all_edge_args (void) { - int i; - struct ipa_edge_args *args; - - if (!ipa_edge_args_vector) + if (!ipa_edge_args_sum) return; - FOR_EACH_VEC_ELT (*ipa_edge_args_vector, i, args) - ipa_free_edge_args_substructures (args); - - vec_free (ipa_edge_args_vector); + ipa_edge_args_sum->release (); + ipa_edge_args_sum = NULL; } /* Free all ipa_node_params structures. */ @@ -3601,18 +3584,12 @@ ipa_set_node_agg_value_chain (struct cgraph_node *node, (*ipcp_transformations)[node->uid].agg_values = aggvals; } -/* Hook that is called by cgraph.c when an edge is removed. */ +/* Hook that is called by cgraph.c when an edge is removed. Adjust reference + count data structures accordingly. */ -static void -ipa_edge_removal_hook (struct cgraph_edge *cs, void *data ATTRIBUTE_UNUSED) +void +ipa_edge_args_sum_t::remove (cgraph_edge *cs, ipa_edge_args *args) { - struct ipa_edge_args *args; - - /* During IPA-CP updating we can be called on not-yet analyzed clones. */ - if (vec_safe_length (ipa_edge_args_vector) <= (unsigned)cs->uid) - return; - - args = IPA_EDGE_REF (cs); if (args->jump_functions) { struct ipa_jump_func *jf; @@ -3627,24 +3604,17 @@ ipa_edge_removal_hook (struct cgraph_edge *cs, void *data ATTRIBUTE_UNUSED) rdesc->cs = NULL; } } - - ipa_free_edge_args_substructures (IPA_EDGE_REF (cs)); } -/* Hook that is called by cgraph.c when an edge is duplicated. */ +/* Method invoked when an edge is duplicated. Copy ipa_edge_args and adjust + reference count data strucutres accordingly. */ -static void -ipa_edge_duplication_hook (struct cgraph_edge *src, struct cgraph_edge *dst, - void *) +void +ipa_edge_args_sum_t::duplicate (cgraph_edge *src, cgraph_edge *dst, + ipa_edge_args *old_args, ipa_edge_args *new_args) { - struct ipa_edge_args *old_args, *new_args; unsigned int i; - ipa_check_create_edge_args (); - - old_args = IPA_EDGE_REF (src); - new_args = IPA_EDGE_REF (dst); - new_args->jump_functions = vec_safe_copy (old_args->jump_functions); if (old_args->polymorphic_call_contexts) new_args->polymorphic_call_contexts @@ -3811,13 +3781,8 @@ void ipa_register_cgraph_hooks (void) { ipa_check_create_node_params (); + ipa_check_create_edge_args (); - if (!edge_removal_hook_holder) - edge_removal_hook_holder = - symtab->add_edge_removal_hook (&ipa_edge_removal_hook, NULL); - if (!edge_duplication_hook_holder) - edge_duplication_hook_holder = - symtab->add_edge_duplication_hook (&ipa_edge_duplication_hook, NULL); function_insertion_hook_holder = symtab->add_cgraph_insertion_hook (&ipa_add_new_function, NULL); } @@ -3827,10 +3792,6 @@ ipa_register_cgraph_hooks (void) static void ipa_unregister_cgraph_hooks (void) { - symtab->remove_edge_removal_hook (edge_removal_hook_holder); - edge_removal_hook_holder = NULL; - symtab->remove_edge_duplication_hook (edge_duplication_hook_holder); - edge_duplication_hook_holder = NULL; symtab->remove_cgraph_insertion_hook (function_insertion_hook_holder); function_insertion_hook_holder = NULL; } diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 8f7eb088813..4d8ee0d351d 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -558,9 +558,24 @@ void ipcp_grow_transformations_if_necessary (void); /* ipa_edge_args stores information related to a callsite and particularly its arguments. It can be accessed by the IPA_EDGE_REF macro. */ -struct GTY(()) ipa_edge_args + +class GTY((for_user)) ipa_edge_args { - /* Vector of the callsite's jump function of each parameter. */ + public: + + /* Default constructor. */ + ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL) + {} + + /* Destructor. */ + ~ipa_edge_args () + { + vec_free (jump_functions); + vec_free (polymorphic_call_contexts); + } + + /* Vectors of the callsite's jump function and polymorphic context + information of each parameter. */ vec *jump_functions; vec *polymorphic_call_contexts; }; @@ -610,19 +625,35 @@ public: ipa_node_params *data2); }; +/* Summary to manange ipa_edge_args structures. */ + +class GTY((user)) ipa_edge_args_sum_t : public call_summary +{ + public: + ipa_edge_args_sum_t (symbol_table *table, bool ggc) + : call_summary (table, ggc) { } + + /* Hook that is called by summary when an edge is duplicated. */ + virtual void remove (cgraph_edge *cs, ipa_edge_args *args); + /* Hook that is called by summary when an edge is duplicated. */ + virtual void duplicate (cgraph_edge *src, + cgraph_edge *dst, + ipa_edge_args *old_args, + ipa_edge_args *new_args); +}; + /* Function summary where the parameter infos are actually stored. */ extern GTY(()) ipa_node_params_t * ipa_node_params_sum; +/* Call summary to store information about edges such as jump functions. */ +extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum; /* Vector of IPA-CP transformation data for each clone. */ extern GTY(()) vec *ipcp_transformations; -/* Vector where the parameter infos are actually stored. */ -extern GTY(()) vec *ipa_edge_args_vector; - /* Return the associated parameter/argument info corresponding to the given node/edge. */ #define IPA_NODE_REF(NODE) (ipa_node_params_sum->get (NODE)) -#define IPA_EDGE_REF(EDGE) (&(*ipa_edge_args_vector)[(EDGE)->uid]) +#define IPA_EDGE_REF(EDGE) (ipa_edge_args_sum->get (EDGE)) /* This macro checks validity of index returned by ipa_get_param_decl_index function. */ #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1) @@ -630,7 +661,6 @@ extern GTY(()) vec *ipa_edge_args_vector; /* Creating and freeing ipa_node_params and ipa_edge_args. */ void ipa_create_all_node_params (void); void ipa_create_all_edge_args (void); -void ipa_free_edge_args_substructures (struct ipa_edge_args *); void ipa_free_all_node_params (void); void ipa_free_all_edge_args (void); void ipa_free_all_structures_after_ipa_cp (void); @@ -657,19 +687,20 @@ ipa_check_create_node_params (void) static inline void ipa_check_create_edge_args (void) { - if (vec_safe_length (ipa_edge_args_vector) - <= (unsigned) symtab->edges_max_uid) - vec_safe_grow_cleared (ipa_edge_args_vector, symtab->edges_max_uid + 1); + if (!ipa_edge_args_sum) + ipa_edge_args_sum + = (new (ggc_cleared_alloc ()) + ipa_edge_args_sum_t (symtab, true)); } -/* Returns true if the array of edge infos is large enough to accommodate an - info for EDGE. The main purpose of this function is that debug dumping - function can check info availability without causing reallocations. */ +/* Returns true if edge summary contains a record for EDGE. The main purpose + of this function is that debug dumping function can check info availability + without causing allocations. */ static inline bool ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge) { - return ((unsigned) edge->uid < vec_safe_length (ipa_edge_args_vector)); + return ipa_edge_args_sum->exists (edge); } static inline ipcp_transformation_summary *