From patchwork Thu Mar 19 19:39:12 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: 452196 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 F101614008F for ; Fri, 20 Mar 2015 06:39:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=AQOpsZ8f; dkim-adsp=none (unprotected policy); 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 :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=BPD2FePPIVbrkT++DAedSfieQ938vOPZOqcZgFYAxF7 qgFP+qnV8Z57d84asgFx9jQ/1hOCOCNtokbfGhVBTUP7u5osqOBLH7IEHk/aJcbJ fs0Fus1EeL8YO1yKRBHHDVxnsaDfGwSygIaMjw/JM1vnTLqfSDvCKe2cZxy+E2CI = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=pyeH1QobkougJWCJa0IS6k/OQ+Q=; b=AQOpsZ8foZHjBKcyH U9p8BH3olBaLbaDoV/pa6BnDlWvgE7Nzs4hWsdZFWVdOjAflhZbLpkGBHmHK0f+M QSI/Gi5yTRyC+mwR8JrY1iSjkSJHpln9Oc9DwwhdPpGOFwbn4TVt2QXBOs4OR4mh baj1wNZMC7krA/L8TNdGD6wDbI= Received: (qmail 28283 invoked by alias); 19 Mar 2015 19:39:18 -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 27112 invoked by uid 89); 19 Mar 2015 19:39:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00 autolearn=ham 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, 19 Mar 2015 19:39:16 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 37964ACA9; Thu, 19 Mar 2015 19:39:13 +0000 (UTC) Message-ID: <550B25E0.1060506@suse.cz> Date: Thu, 19 Mar 2015 20:39:12 +0100 From: =?UTF-8?B?TWFydGluIExpxaFrYQ==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: GCC Patches CC: "hubic >> Jan Hubicka" Subject: [PATCH] Speed-up IPA ICF by enhanced hash values X-IsSubscribed: yes Hi. Following patch improves performance by adding hash values of references that are not candidates for IPA ICF. Tested on x86_64-linux-pc w/o any new regression observed. Ready for trunk? Thanks, Martin From 6c04cc4283d08a8aa9829574dd91579a918cb508 Mon Sep 17 00:00:00 2001 From: marxin Date: Sun, 15 Mar 2015 19:21:39 -0500 Subject: [PATCH] IPA ICF: include hash values of references. gcc/ChangeLog: 2015-03-15 Martin Liska * ipa-icf.c (sem_item::update_hash_by_addr_refs): New function. (sem_item::update_hash_by_local_refs): Likewise. (sem_variable::get_hash): Empty line is fixed. (sem_item_optimizer::execute): Include adding of hash references. (sem_item_optimizer::update_hash_by_addr_refs): New function. (sem_item_optimizer::build_hash_based_classes): Use local hash. * ipa-icf.h (sem_item::update_hash_by_addr_refs): New function. (sem_item::update_hash_by_local_refs): Likewise. --- gcc/ipa-icf.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- gcc/ipa-icf.h | 18 ++++++++++++- 2 files changed, 97 insertions(+), 5 deletions(-) diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index f68d23c..b8e3aa4 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -557,6 +557,69 @@ sem_function::equals_wpa (sem_item *item, return true; } +/* Update hash by address sensitive references. */ + +void +sem_item::update_hash_by_addr_refs (hash_map &m_symtab_node_map) +{ + if (is_a (node) && DECL_VIRTUAL_P (node->decl)) + return; + + ipa_ref* ref; + inchash::hash hstate (hash); + for (unsigned i = 0; i < node->num_references (); i++) + { + ref = node->iterate_reference (i, ref); + if (ref->address_matters_p ()) + hstate.add_ptr (ref->referred->ultimate_alias_target ()); + } + + if (is_a (node)) + { + for (cgraph_edge *e = dyn_cast (node)->callers; e; + e = e->next_caller) + { + sem_item **result = m_symtab_node_map.get (e->callee); + if (!result) + hstate.add_ptr (e->callee->ultimate_alias_target ()); + } + } + + hash = hstate.end (); +} + +/* Update hash by computed local hash values taken from different + semantic items. */ + +void +sem_item::update_hash_by_local_refs (hash_map &m_symtab_node_map) +{ + inchash::hash state (hash); + for (unsigned j = 0; j < node->num_references (); j++) + { + ipa_ref *ref; + ref = node->iterate_reference (j, ref); + sem_item **result = m_symtab_node_map.get (ref->referring); + if (result) + state.merge_hash ((*result)->hash); + } + + if (type == FUNC) + { + for (cgraph_edge *e = dyn_cast (node)->callees; e; + e = e->next_callee) + { + sem_item **result = m_symtab_node_map.get (e->caller); + if (result) + state.merge_hash ((*result)->hash); + } + } + + global_hash = state.end (); +} + /* Returns true if the item equals to ITEM given as argument. */ bool @@ -1742,8 +1805,8 @@ hashval_t sem_variable::get_hash (void) { if (hash) - return hash; + /* All WPA streamed in symbols should have their hashes computed at compile time. At this point, the constructor may not be in memory at all. DECL_INITIAL (decl) would be error_mark_node in that case. */ @@ -2202,6 +2265,8 @@ sem_item_optimizer::execute (void) filter_removed_items (); unregister_hooks (); + build_graph (); + update_hash_by_addr_refs (); build_hash_based_classes (); if (dump_file) @@ -2211,8 +2276,6 @@ sem_item_optimizer::execute (void) for (unsigned int i = 0; i < m_items.length(); i++) m_items[i]->init_wpa (); - build_graph (); - subdivide_classes_by_equality (true); if (dump_file) @@ -2301,6 +2364,19 @@ sem_item_optimizer::add_item_to_class (congruence_class *cls, sem_item *item) item->cls = cls; } +void +sem_item_optimizer::update_hash_by_addr_refs () +{ + for (unsigned i = 0; i < m_items.length (); i++) + m_items[i]->update_hash_by_addr_refs (m_symtab_node_map); + + for (unsigned i = 0; i < m_items.length (); i++) + m_items[i]->update_hash_by_local_refs (m_symtab_node_map); + + for (unsigned i = 0; i < m_items.length (); i++) + m_items[i]->hash = m_items[i]->global_hash; +} + /* Congruence classes are built by hash value. */ void @@ -2310,7 +2386,7 @@ sem_item_optimizer::build_hash_based_classes (void) { sem_item *item = m_items[i]; - congruence_class_group *group = get_group_by_hash (item->get_hash (), + congruence_class_group *group = get_group_by_hash (item->hash, item->type); if (!group->classes.length ()) diff --git a/gcc/ipa-icf.h b/gcc/ipa-icf.h index 8245b54..ad502a7 100644 --- a/gcc/ipa-icf.h +++ b/gcc/ipa-icf.h @@ -189,6 +189,15 @@ public: /* Dump symbol to FILE. */ virtual void dump_to_file (FILE *file) = 0; + /* Update hash by address sensitive references. */ + void update_hash_by_addr_refs (hash_map &m_symtab_node_map); + + /* Update hash by computed local hash values taken from different + semantic items. */ + void update_hash_by_local_refs (hash_map &m_symtab_node_map); + /* Return base tree that can be used for compatible_types_p and contains_polymorphic_type_p comparison. */ static bool get_base_types (tree *t1, tree *t2); @@ -226,9 +235,13 @@ public: /* A set with symbol table references. */ hash_set refs_set; + /* Hash of item. */ + hashval_t hash; + + /* Temporary hash used where hash values of references are added. */ + hashval_t global_hash; protected: /* Cached, once calculated hash for the item. */ - hashval_t hash; /* Accumulate to HSTATE a hash of constructor expression EXP. */ static void add_expr (const_tree exp, inchash::hash &hstate); @@ -494,6 +507,9 @@ public: private: + /* Update hash of symbol by address memory references. */ + void update_hash_by_addr_refs (); + /* Congruence classes are built by hash value. */ void build_hash_based_classes (void); -- 2.1.2