From patchwork Thu Jul 9 09:13:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 493375 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 142211402B0 for ; Thu, 9 Jul 2015 21:08:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Gig9Kchg; 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-to:resent-date:resent-message-id:message-id :in-reply-to:references:from:date:subject:to; q=dns; s=default; b= EN3Pomzx2b75YcmVtO4IKwl6uFti5NGJaF33WKfdzrifoD/CcJsoR6faCfJ2N9DJ ISTU6UdGqwriF0X726qzbxSdzwlEe/BX+wU27fp+k3obLUHyQb1XoAsU1sll/DWs n9s3CfsgGnP8fAFLzG7jGCpK02S+UIUZhp0ycshr9W8= 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-to:resent-date:resent-message-id:message-id :in-reply-to:references:from:date:subject:to; s=default; bh=9nl8 t12VW08f7jE9NacnsrWU8Ec=; b=Gig9Kchg8LgZZmnzrCJwXu4LaLyt/eu1CZw0 G5QR2kvOOH/7wYvD8UqybaqIP/lTz4243N9hRb4X8TTwwZnD7HWF54B1OHAZaKf5 7sUTaPQvRAjkIKbCpCuaYdnhcFPd457KoT6zyyr7KfoNrAExYL3s56uQmXqxvSei InzVmas= Received: (qmail 61119 invoked by alias); 9 Jul 2015 11:08:08 -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 60962 invoked by uid 89); 9 Jul 2015 11:08:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Thu, 09 Jul 2015 11:07:57 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CF917AD01 for ; Thu, 9 Jul 2015 11:07:53 +0000 (UTC) Resent-From: =?UTF-8?B?TWFydGluIExpxaFrYQ==?= Resent-To: GCC Patches Resent-Date: Thu, 9 Jul 2015 13:07:40 +0200 Resent-Message-ID: <559E55FC.7020806@suse.cz> Resent-User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 Message-Id: In-Reply-To: References: From: mliska Date: Thu, 9 Jul 2015 11:13:53 +0200 Subject: [PATCH 4/6] Port ipa-cp to use cgraph_edge summary. To: gcc-patches@gcc.gnu.org X-IsSubscribed: yes gcc/ChangeLog: 2015-07-03 Martin Liska * ipa-cp.c (struct edge_clone_summary): New structure. (class edge_clone_summary_t): Likewise. (edge_clone_summary_t::initialize): New method. (edge_clone_summary_t::duplicate): Likewise. (get_next_cgraph_edge_clone): Remove. (get_info_about_necessary_edges): Refactor using the new data structure. (gather_edges_for_value): Likewise. (perhaps_add_new_callers): Likewise. (ipcp_driver): Allocate and deallocate newly added instance. --- gcc/ipa-cp.c | 198 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 113 insertions(+), 85 deletions(-) diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 16b9cde..8a50b63 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -2888,54 +2888,79 @@ ipcp_discover_new_direct_edges (struct cgraph_node *node, inline_update_overall_summary (node); } -/* Vector of pointers which for linked lists of clones of an original crgaph - edge. */ +/* Edge clone summary. */ -static vec next_edge_clone; -static vec prev_edge_clone; - -static inline void -grow_edge_clone_vectors (void) +struct edge_clone_summary { - if (next_edge_clone.length () - <= (unsigned) symtab->edges_max_uid) - next_edge_clone.safe_grow_cleared (symtab->edges_max_uid + 1); - if (prev_edge_clone.length () - <= (unsigned) symtab->edges_max_uid) - prev_edge_clone.safe_grow_cleared (symtab->edges_max_uid + 1); -} + /* Default constructor. */ + edge_clone_summary (): edge_set (NULL), edge (NULL) {} -/* Edge duplication hook to grow the appropriate linked list in - next_edge_clone. */ + /* Default destructor. */ + ~edge_clone_summary () + { + gcc_assert (edge_set != NULL); -static void -ipcp_edge_duplication_hook (struct cgraph_edge *src, struct cgraph_edge *dst, - void *) + if (edge != NULL) + { + gcc_checking_assert (edge_set->contains (edge)); + edge_set->remove (edge); + } + + /* Release memory for an empty set. */ + if (edge_set->elements () == 0) + delete edge_set; + } + + hash_set *edge_set; + cgraph_edge *edge; +}; + +class edge_clone_summary_t: + public edge_summary { - grow_edge_clone_vectors (); +public: + edge_clone_summary_t (symbol_table *symtab): + edge_summary (symtab) {} + + virtual void initialize (cgraph_edge *edge, edge_clone_summary *data); + virtual void duplicate (cgraph_edge *src_edge, cgraph_edge *dst_edge, + edge_clone_summary *src_data, + edge_clone_summary *dst_data); +}; - struct cgraph_edge *old_next = next_edge_clone[src->uid]; - if (old_next) - prev_edge_clone[old_next->uid] = dst; - prev_edge_clone[dst->uid] = src; +static edge_summary *edge_clone_summaries = NULL; + +void +edge_clone_summary_t::initialize (cgraph_edge *edge, edge_clone_summary *data) +{ + gcc_checking_assert (data->edge_set == NULL); - next_edge_clone[dst->uid] = old_next; - next_edge_clone[src->uid] = dst; + data->edge_set = new hash_set (); + data->edge_set->add (edge); + data->edge = edge; } -/* Hook that is called by cgraph.c when an edge is removed. */ +/* Edge duplication hook. */ -static void -ipcp_edge_removal_hook (struct cgraph_edge *cs, void *) +void +edge_clone_summary_t::duplicate (cgraph_edge *src_edge, cgraph_edge *dst_edge, + edge_clone_summary *src_data, + edge_clone_summary *dst_data) { - grow_edge_clone_vectors (); - - struct cgraph_edge *prev = prev_edge_clone[cs->uid]; - struct cgraph_edge *next = next_edge_clone[cs->uid]; - if (prev) - next_edge_clone[prev->uid] = next; - if (next) - prev_edge_clone[next->uid] = prev; + dst_data->edge = dst_edge; + if (src_data->edge_set == NULL) + { + src_data->edge_set = new hash_set (); + src_data->edge_set->add (src_edge); + } + + src_data->edge_set->add (dst_edge); + + /* As ::initialize processes an allocation, we have to release previous + edge_set. */ + delete dst_data->edge_set; + + dst_data->edge_set = src_data->edge_set; } /* See if NODE is a clone with a known aggregate value at a given OFFSET of a @@ -3050,14 +3075,6 @@ cgraph_edge_brings_value_p (cgraph_edge *cs, plats->ctxlat.values->value); } -/* Get the next clone in the linked list of clones of an edge. */ - -static inline struct cgraph_edge * -get_next_cgraph_edge_clone (struct cgraph_edge *cs) -{ - return next_edge_clone[cs->uid]; -} - /* Given VAL that is intended for DEST, iterate over all its sources and if they still hold, add their edge frequency and their number into *FREQUENCY and *CALLER_COUNT respectively. */ @@ -3075,18 +3092,23 @@ get_info_about_necessary_edges (ipcp_value *val, cgraph_node *dest, for (src = val->sources; src; src = src->next) { - struct cgraph_edge *cs = src->cs; - while (cs) - { - if (cgraph_edge_brings_value_p (cs, src, dest)) + cgraph_edge *cs = src->cs; + + edge_clone_summary *s = edge_clone_summaries->get (cs); + if (s->edge_set != NULL) + for (hash_set ::iterator it = s->edge_set->begin (); + it != s->edge_set->end (); ++it) + { + cs = *it; + + if (cgraph_edge_brings_value_p (cs, src, dest)) { count++; freq += cs->frequency; cnt += cs->count; hot |= cs->maybe_hot_p (); } - cs = get_next_cgraph_edge_clone (cs); - } + } } *freq_sum = freq; @@ -3109,13 +3131,16 @@ gather_edges_for_value (ipcp_value *val, cgraph_node *dest, ret.create (caller_count); for (src = val->sources; src; src = src->next) { - struct cgraph_edge *cs = src->cs; - while (cs) - { - if (cgraph_edge_brings_value_p (cs, src, dest)) - ret.quick_push (cs); - cs = get_next_cgraph_edge_clone (cs); - } + cgraph_edge *cs = src->cs; + edge_clone_summary *s = edge_clone_summaries->get (cs); + if (s->edge_set != NULL) + for (hash_set ::iterator it = s->edge_set->begin (); + it != s->edge_set->end (); ++it) + { + cs = *it; + if (cgraph_edge_brings_value_p (cs, src, dest)) + ret.quick_push (cs); + } } return ret; @@ -3971,25 +3996,35 @@ perhaps_add_new_callers (cgraph_node *node, ipcp_value *val) for (src = val->sources; src; src = src->next) { struct cgraph_edge *cs = src->cs; - while (cs) + + edge_clone_summary *s = edge_clone_summaries->get (cs); + if (s->edge_set != NULL) { - if (cgraph_edge_brings_value_p (cs, src, node) - && cgraph_edge_brings_all_scalars_for_node (cs, val->spec_node) - && cgraph_edge_brings_all_agg_vals_for_node (cs, val->spec_node)) + for (hash_set ::iterator it = s->edge_set->begin (); + it != s->edge_set->end (); ++it) { - if (dump_file) - fprintf (dump_file, " - adding an extra caller %s/%i" - " of %s/%i\n", - xstrdup_for_dump (cs->caller->name ()), - cs->caller->order, - xstrdup_for_dump (val->spec_node->name ()), - val->spec_node->order); - - cs->redirect_callee_duplicating_thunks (val->spec_node); - val->spec_node->expand_all_artificial_thunks (); - redirected_sum += cs->count; + cgraph_edge *cs = *it; + + if (cgraph_edge_brings_value_p (cs, src, node) + && cgraph_edge_brings_all_scalars_for_node (cs, + val->spec_node) + && cgraph_edge_brings_all_agg_vals_for_node (cs, + val->spec_node)) + { + if (dump_file) + fprintf (dump_file, " - adding an extra caller %s/%i" + " of %s/%i\n", + xstrdup_for_dump (cs->caller->name ()), + cs->caller->order, + xstrdup_for_dump (val->spec_node->name ()), + val->spec_node->order); + + cs->redirect_callee_duplicating_thunks (val->spec_node); + val->spec_node->expand_all_artificial_thunks (); + redirected_sum += cs->count; + + } } - cs = get_next_cgraph_edge_clone (cs); } } @@ -4441,17 +4476,13 @@ ipcp_store_alignment_results (void) static unsigned int ipcp_driver (void) { - struct cgraph_2edge_hook_list *edge_duplication_hook_holder; - struct cgraph_edge_hook_list *edge_removal_hook_holder; struct ipa_topo_info topo; + if (edge_clone_summaries == NULL) + edge_clone_summaries = new edge_clone_summary_t (symtab); + ipa_check_create_node_params (); ipa_check_create_edge_args (); - grow_edge_clone_vectors (); - edge_duplication_hook_holder = - symtab->add_edge_duplication_hook (&ipcp_edge_duplication_hook, NULL); - edge_removal_hook_holder = - symtab->add_edge_removal_hook (&ipcp_edge_removal_hook, NULL); if (dump_file) { @@ -4472,10 +4503,7 @@ ipcp_driver (void) /* Free all IPCP structures. */ free_toporder_info (&topo); - next_edge_clone.release (); - prev_edge_clone.release (); - symtab->remove_edge_removal_hook (edge_removal_hook_holder); - symtab->remove_edge_duplication_hook (edge_duplication_hook_holder); + delete edge_clone_summaries; ipa_free_all_structures_after_ipa_cp (); if (dump_file) fprintf (dump_file, "\nIPA constant propagation end\n");