From patchwork Thu Nov 10 13:08:54 2016 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: 81640 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp714121qge; Thu, 10 Nov 2016 05:09:24 -0800 (PST) X-Received: by 10.98.160.140 with SMTP id p12mr9882061pfl.122.1478783364440; Thu, 10 Nov 2016 05:09:24 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id k126si4800556pgc.159.2016.11.10.05.09.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Nov 2016 05:09:24 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-440951-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-440951-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440951-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=w2UPungx75yYvdNmkHDDoDEchbfVL31TexSB/oOMY2IHtGT9TZ bz1FBkwEyuBPDoj1h9+PTdOkDwz8KCds9EGdxcWGrkX0KpRS7W1Td8/USs/8tfTS TxBVcri3H5eqQ4nUotrN4aLDleOr3Oya/fVxlVFvSxA85NgkTRZ8WeIJk= 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:from :to:cc:subject:message-id:date:mime-version:content-type; s= default; bh=enOXrd1QtkDRk8I5OfNIB40sUfk=; b=B60B64QgCJxxVi9aoCLe tvaAuDxWXsccq3KanfSe4cNA72SEAxdSxZswpvmJdUujHmcc7fJveBDorz+sd8xl z/2fa0XenJeK3U3Z/C/leujt6V6dscOXFAi87Q5ZwYbO0Wl8g2DjMSaj92MkGx8A 9kYAWQKQBDo3/XWes44A3bU= Received: (qmail 82568 invoked by alias); 10 Nov 2016 13:09: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 82557 invoked by uid 89); 10 Nov 2016 13:09:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=drives, bucket, printtreec, print-tree.c 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; Thu, 10 Nov 2016 13:08:56 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BDC3AABF9 for ; Thu, 10 Nov 2016 13:08:54 +0000 (UTC) From: =?UTF-8?Q?Martin_Li=c5=a1ka?= To: GCC Patches Cc: Jan Hubicka Subject: [PATCH] Fix print_node for CONSTRUCTORs Message-ID: <1b9be525-ffb2-c599-ae57-52050af91e8c@suse.cz> Date: Thu, 10 Nov 2016 14:08:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-IsSubscribed: yes Hello. Following patch fixes indentation of print_node when printing a constructor that has some equal elements. Current implementation caches tree to prevent deep debug outputs. Such behavior is undesired for ctor elements. Apart from that, I switch to hash_set for a table that is used for tree node caching. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Before: constant 1> val constant 120> idx constant 2> val idx constant 3> val idx constant 4> val idx constant 5> val > After: constant 1> val constant 120> idx constant 2> val constant 120> idx constant 3> val constant 120> idx constant 4> val constant 120> idx constant 5> val constant 120>> Ready to be installed? Martin >From 6d18ff00ec1d8e6a8a154fbb70af25b2dda8165e Mon Sep 17 00:00:00 2001 From: marxin Date: Wed, 9 Nov 2016 16:28:52 +0100 Subject: [PATCH] Fix print_node for CONSTRUCTORs gcc/ChangeLog: 2016-11-10 Martin Liska * print-tree.c (struct bucket): Remove. (print_node): Add new argument which drives whether a tree node is printed briefly or not. (debug_tree): Replace a custom hash table with hash_set. * print-tree.h (print_node): Add the argument. --- gcc/print-tree.c | 43 +++++++++++++++---------------------------- gcc/print-tree.h | 3 ++- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/gcc/print-tree.c b/gcc/print-tree.c index 8c63cb8..f3ee04c 100644 --- a/gcc/print-tree.c +++ b/gcc/print-tree.c @@ -33,19 +33,14 @@ along with GCC; see the file COPYING3. If not see #include "gimple-pretty-print.h" /* FIXME */ #include "tree-cfg.h" #include "tree-dump.h" +#include "print-tree.h" /* Define the hash table of nodes already seen. Such nodes are not repeated; brief cross-references are used. */ #define HASH_SIZE 37 -struct bucket -{ - tree node; - struct bucket *next; -}; - -static struct bucket **table; +static hash_set *table = NULL; /* Print PREFIX and ADDR to FILE. */ void @@ -176,10 +171,9 @@ indent_to (FILE *file, int column) starting in column INDENT. */ void -print_node (FILE *file, const char *prefix, tree node, int indent) +print_node (FILE *file, const char *prefix, tree node, int indent, + bool brief_for_visited) { - int hash; - struct bucket *b; machine_mode mode; enum tree_code_class tclass; int len; @@ -219,21 +213,14 @@ print_node (FILE *file, const char *prefix, tree node, int indent) /* Allow this function to be called if the table is not there. */ if (table) { - hash = ((uintptr_t) node) % HASH_SIZE; - /* If node is in the table, just mention its address. */ - for (b = table[hash]; b; b = b->next) - if (b->node == node) - { - print_node_brief (file, prefix, node, indent); - return; - } + if (table->contains (node) && brief_for_visited) + { + print_node_brief (file, prefix, node, indent); + return; + } - /* Add this node to the table. */ - b = XNEW (struct bucket); - b->node = node; - b->next = table[hash]; - table[hash] = b; + table->add (node); } /* Indent to the specified column, since this is the long form. */ @@ -846,8 +833,8 @@ print_node (FILE *file, const char *prefix, tree node, int indent) FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), cnt, index, value) { - print_node (file, "idx", index, indent + 4); - print_node (file, "val", value, indent + 4); + print_node (file, "idx", index, indent + 4, false); + print_node (file, "val", value, indent + 4, false); } } break; @@ -997,10 +984,10 @@ print_node (FILE *file, const char *prefix, tree node, int indent) DEBUG_FUNCTION void debug_tree (tree node) { - table = XCNEWVEC (struct bucket *, HASH_SIZE); + table = new hash_set (HASH_SIZE); print_node (stderr, "", node, 0); - free (table); - table = 0; + delete table; + table = NULL; putc ('\n', stderr); } diff --git a/gcc/print-tree.h b/gcc/print-tree.h index 124deab..fd610f9 100644 --- a/gcc/print-tree.h +++ b/gcc/print-tree.h @@ -38,7 +38,8 @@ extern void debug_raw (vec &ref); extern void debug_raw (vec *ptr); #ifdef BUFSIZ extern void dump_addr (FILE*, const char *, const void *); -extern void print_node (FILE *, const char *, tree, int); +extern void print_node (FILE *, const char *, tree, int, + bool brief_for_visited = true); extern void print_node_brief (FILE *, const char *, const_tree, int); extern void indent_to (FILE *, int); #endif -- 2.10.1