diff mbox

Fix print_node for CONSTRUCTORs

Message ID 1b9be525-ffb2-c599-ae57-52050af91e8c@suse.cz
State New
Headers show

Commit Message

Martin Liška Nov. 10, 2016, 1:08 p.m. UTC
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:
 <constructor 0x7ffff6a3e438
  ...
    constant static lngt 5
    idx <integer_cst 0x7ffff68a30a8 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 1>
    val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>
    idx <integer_cst 0x7ffff695cb88 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 2> val <integer_cst 0x7ffff6a3e408 120>
    idx <integer_cst 0x7ffff6a3e048 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 3> val <integer_cst 0x7ffff6a3e408 120>
    idx <integer_cst 0x7ffff695cb28 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 4> val <integer_cst 0x7ffff6a3e408 120>
    idx <integer_cst 0x7ffff6a3e3d8 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 5> val <integer_cst 0x7ffff6a3e408 120>>

After:
 <constructor 0x7ffff6a3e438
    type <array_type 0x7ffff6a60a80
   ...
    constant static lngt 5
    idx <integer_cst 0x7ffff68a30a8 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 1>
    val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>
    idx <integer_cst 0x7ffff695cb88 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 2>
    val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>
    idx <integer_cst 0x7ffff6a3e048 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 3>
    val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>
    idx <integer_cst 0x7ffff695cb28 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 4>
    val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>
    idx <integer_cst 0x7ffff6a3e3d8 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 5>
    val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>>

Ready to be installed?
Martin

Comments

Jeff Law Nov. 23, 2016, 10:09 p.m. UTC | #1
On 11/10/2016 06:08 AM, Martin Liška wrote:
> 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:

>  <constructor 0x7ffff6a3e438

>   ...

>     constant static lngt 5

>     idx <integer_cst 0x7ffff68a30a8 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 1>

>     val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>

>     idx <integer_cst 0x7ffff695cb88 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 2> val <integer_cst 0x7ffff6a3e408 120>

>     idx <integer_cst 0x7ffff6a3e048 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 3> val <integer_cst 0x7ffff6a3e408 120>

>     idx <integer_cst 0x7ffff695cb28 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 4> val <integer_cst 0x7ffff6a3e408 120>

>     idx <integer_cst 0x7ffff6a3e3d8 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 5> val <integer_cst 0x7ffff6a3e408 120>>

>

> After:

>  <constructor 0x7ffff6a3e438

>     type <array_type 0x7ffff6a60a80

>    ...

>     constant static lngt 5

>     idx <integer_cst 0x7ffff68a30a8 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 1>

>     val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>

>     idx <integer_cst 0x7ffff695cb88 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 2>

>     val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>

>     idx <integer_cst 0x7ffff6a3e048 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 3>

>     val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>

>     idx <integer_cst 0x7ffff695cb28 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 4>

>     val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>

>     idx <integer_cst 0x7ffff6a3e3d8 type <integer_type 0x7ffff688a2a0 bitsizetype> constant 5>

>     val <integer_cst 0x7ffff6a3e408 type <integer_type 0x7ffff688a5e8 char> constant 120>>

>

> Ready to be installed?

> Martin

>

>

> 0001-Fix-print_node-for-CONSTRUCTORs.patch

>

>

> From 6d18ff00ec1d8e6a8a154fbb70af25b2dda8165e Mon Sep 17 00:00:00 2001

> From: marxin <mliska@suse.cz>

> Date: Wed, 9 Nov 2016 16:28:52 +0100

> Subject: [PATCH] Fix print_node for CONSTRUCTORs

>

> gcc/ChangeLog:

>

> 2016-11-10  Martin Liska  <mliska@suse.cz>

>

> 	* 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<T>.

> 	* print-tree.h (print_node): Add the argument.

OK.

jeff
diff mbox

Patch

From 6d18ff00ec1d8e6a8a154fbb70af25b2dda8165e Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 9 Nov 2016 16:28:52 +0100
Subject: [PATCH] Fix print_node for CONSTRUCTORs

gcc/ChangeLog:

2016-11-10  Martin Liska  <mliska@suse.cz>

	* 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<T>.
	* 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<tree> *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<tree> (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<tree, va_gc> &ref);
 extern void debug_raw (vec<tree, va_gc> *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