From patchwork Tue Nov 24 08:45:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 547891 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 167A61402F0 for ; Tue, 24 Nov 2015 19:45:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=L7pDC/1U; 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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=fziALgymDTwCIS7Xn2/6qrtxzIjvl3A5zit0Eg5HPQRLA0pJrMoJv ze+7Mv6zRYwQYivOXYiTcr6B7HJsi3CMZI5t8KgIffR59+sp972rdxoCZGw/QwYC BCrYgWOB5SCGmZdI8EcMvHNNXwOnh2W8W2wVTLF0kbjKMe3UPBy3Qc= 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=M7H4o0RpZIdbuKYjRVvIOU+03bA=; b=L7pDC/1UA2LZFr23HLiW y8/xdZhc2KtAGFGnd/Bq0y/jRPvMvwQeFLGxWrYlC0tegHy8MJgDm3MgUQsNm8VG odEotqwP2vYMWLqmrYU0HZ5/DCBcKMuOpo8HxEox99ql4BM1MUk5yo0VaA1BBZYl GPUugQMUj4NAsooeS1IbV1w= Received: (qmail 34963 invoked by alias); 24 Nov 2015 08:45:43 -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 34953 invoked by uid 89); 24 Nov 2015 08:45:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 24 Nov 2015 08:45:41 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 566B75423D2; Tue, 24 Nov 2015 09:45:38 +0100 (CET) Date: Tue, 24 Nov 2015 09:45:38 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rguether@suse.de Subject: Add a way to free tree node Message-ID: <20151124084538.GB90197@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi, while looking into the earlier bug I noticed that type_hash_canon is used to avoid producing type duplicates. The type is however created, then looked up in the cache and if it exists it is never used. The function takes care to remove the code found memory stats but never actually free it. I suppose it is artifact of conversion from obstack to ggc. We produce a lot of type duplicates this way that is not very cool. It always bit bothered me that unify_scc does not update the statistics so this patch introduces free_node that can be used to free given tree node. Bootstrapped/regtested x86_64-linux, OK? * tree.c (free_node): New function. (type_hash_canon): Use it. * tree.h (free_node): Declare. * lto.c (unify_scc): Use free_node. Index: tree.c =================================================================== --- tree.c (revision 230718) +++ tree.c (working copy) @@ -1103,6 +1103,27 @@ make_node_stat (enum tree_code code MEM_ return t; } + +/* Free tree node. */ + +void +free_node (tree node) +{ + enum tree_code code = TREE_CODE (node); + if (GATHER_STATISTICS) + { + tree_code_counts[(int) TREE_CODE (node)]--; + tree_node_counts[(int) t_kind]--; + tree_node_sizes[(int) t_kind] -= tree_code_size (TREE_CODE (node)); + } + if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR)) + vec_free (CONSTRUCTOR_ELTS (node)); + else if (code == BLOCK) + vec_free (BLOCK_NONLOCALIZED_VARS (node)); + else if (code == TREE_BINFO) + vec_free (BINFO_BASE_ACCESSES (node)); + ggc_free (node); +} /* Return a new node with the same contents as NODE except that its TREE_CHAIN, if it has one, is zero and it has a fresh uid. */ @@ -7100,12 +7123,7 @@ type_hash_canon (unsigned int hashcode, { tree t1 = ((type_hash *) *loc)->type; gcc_assert (TYPE_MAIN_VARIANT (t1) == t1); - if (GATHER_STATISTICS) - { - tree_code_counts[(int) TREE_CODE (type)]--; - tree_node_counts[(int) t_kind]--; - tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type_non_common); - } + free_node (type); return t1; } else Index: tree.h =================================================================== --- tree.h (revision 230718) +++ tree.h (working copy) @@ -3763,6 +3763,10 @@ extern int allocate_decl_uid (void); extern tree make_node_stat (enum tree_code MEM_STAT_DECL); #define make_node(t) make_node_stat (t MEM_STAT_INFO) +/* Free tree node. */ + +extern void free_node (tree); + /* Make a copy of a node, with all the same contents. */ extern tree copy_node_stat (tree MEM_STAT_DECL); Index: lto/lto.c =================================================================== --- lto/lto.c (revision 230718) +++ lto/lto.c (working copy) @@ -1623,13 +1622,9 @@ unify_scc (struct data_in *data_in, unsi data_in->location_cache.revert_location_cache (); for (unsigned i = 0; i < len; ++i) { - enum tree_code code; if (TYPE_P (scc->entries[i])) num_merged_types++; - code = TREE_CODE (scc->entries[i]); - if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR)) - vec_free (CONSTRUCTOR_ELTS (scc->entries[i])); - ggc_free (scc->entries[i]); + free_node (scc->entries[i]); } break;