From patchwork Thu Aug 14 11:08:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 379899 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 E84B2140088 for ; Thu, 14 Aug 2014 21:12:17 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=FSahLWbutTFuv53dotk7mwo5WYnk0CeAc49e3KpQWFEUVjtdFHl6N QFSxQYb3KVp459jb1shhbUwA0I1Tool58GEWefGofX7jZOcuiVxDTHnOjb6ZQ2GJ aTL0FfCmN3ASTVoVQFX09iOMhsRy3UzcPKFWQlBY4TlSFAeZNF8XAg= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=GaYyePR2n5tyVik8SoFfqSPoZ3s=; b=QNsSdZJJ3IeO9fUAhWms llmyKGJ7q9EvXEs515T3qVv0ruXXWt4bVAs8BB4Q/3jo5g8WP1+xkddc9scAhPPo MtqL6MGva+CDObbhHuTB8KHpAEkJvhHcl0KbCD/tM4doxA7cHDrNhkNL8yxQpwO/ xjIkuhNEPErFGrqD7EUvyIQ= Received: (qmail 16722 invoked by alias); 14 Aug 2014 11:12:07 -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 16704 invoked by uid 89); 14 Aug 2014 11:12:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD 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, 14 Aug 2014 11:12:03 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C33DEAB43 for ; Thu, 14 Aug 2014 11:11:59 +0000 (UTC) Date: Thu, 14 Aug 2014 13:08:49 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Speed up type_hash_canon Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 This speeds up type_hash_canon by avoiding a 2nd hashtable lookup in the case no previous same type is in the hashtable. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-08-14 Richard Biener * tree.c (type_hash_lookup, type_hash_add): Merge into ... (type_hash_canon): ... this and avoid 2nd lookup for the add. Index: gcc/tree.c =================================================================== --- gcc/tree.c (revision 213951) +++ gcc/tree.c (working copy) @@ -6763,44 +6763,6 @@ type_hash_hash (const void *item) return ((const struct type_hash *) item)->hash; } -/* Look in the type hash table for a type isomorphic to TYPE. - If one is found, return it. Otherwise return 0. */ - -static tree -type_hash_lookup (hashval_t hashcode, tree type) -{ - struct type_hash *h, in; - - /* The TYPE_ALIGN field of a type is set by layout_type(), so we - must call that routine before comparing TYPE_ALIGNs. */ - layout_type (type); - - in.hash = hashcode; - in.type = type; - - h = (struct type_hash *) htab_find_with_hash (type_hash_table, &in, - hashcode); - if (h) - return h->type; - return NULL_TREE; -} - -/* Add an entry to the type-hash-table - for a type TYPE whose hash code is HASHCODE. */ - -static void -type_hash_add (hashval_t hashcode, tree type) -{ - struct type_hash *h; - void **loc; - - h = ggc_alloc (); - h->hash = hashcode; - h->type = type; - loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT); - *loc = (void *)h; -} - /* Given TYPE, and HASHCODE its hash code, return the canonical object for an identical type if one already exists. Otherwise, return TYPE, and record it as the canonical object. @@ -6813,17 +6775,28 @@ type_hash_add (hashval_t hashcode, tree tree type_hash_canon (unsigned int hashcode, tree type) { - tree t1; + type_hash in; + void **loc; /* The hash table only contains main variants, so ensure that's what we're being passed. */ gcc_assert (TYPE_MAIN_VARIANT (type) == type); - /* See if the type is in the hash table already. If so, return it. - Otherwise, add the type. */ - t1 = type_hash_lookup (hashcode, type); - if (t1 != 0) + /* The TYPE_ALIGN field of a type is set by layout_type(), so we + must call that routine before comparing TYPE_ALIGNs. */ + layout_type (type); + + in.hash = hashcode; + in.type = type; + + loc = htab_find_slot_with_hash (type_hash_table, &in, hashcode, INSERT); + if (*loc) { + tree t1 = ((type_hash *) *loc)->type; + /* ??? We'd like to assert here that the hashtable only contains + main variants but the C++ frontend breaks this by modifying + types already in the hashtable in build_cplus_array_type. */ + /* gcc_assert (TYPE_MAIN_VARIANT (t1) == t1); */ if (GATHER_STATISTICS) { tree_code_counts[(int) TREE_CODE (type)]--; @@ -6834,7 +6807,13 @@ type_hash_canon (unsigned int hashcode, } else { - type_hash_add (hashcode, type); + struct type_hash *h; + + h = ggc_alloc (); + h->hash = hashcode; + h->type = type; + *loc = (void *)h; + return type; } }