Add debug_vn_reference_ops helper

Message ID nycvar.YFH.7.76.2104070958320.4420@elmra.sevgm.obk
State New
Headers show
Series
  • Add debug_vn_reference_ops helper
Related show

Commit Message

Richard Biener April 7, 2021, 7:59 a.m.
This factors out a helper to dump VN reference operands, sth that
proves useful in debugging VN issues.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2021-04-07  Richard Biener  <rguenther@suse.de>

	* tree-ssa-sccvn.h (print_vn_reference_ops): Declare.
	* tree-ssa-pre.c (print_pre_expr): Factor out VN reference operand
	printing...
	* tree-ssa-sccvn.c (print_vn_reference_ops): ... into this new
	function.
	(debug_vn_reference_ops): New.
---
 gcc/tree-ssa-pre.c   | 39 +----------------------------------
 gcc/tree-ssa-sccvn.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
 gcc/tree-ssa-sccvn.h |  1 +
 3 files changed, 51 insertions(+), 38 deletions(-)

-- 
2.26.2

Patch

diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index 1a022fbaf8d..91dd49200c3 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -1067,45 +1067,8 @@  print_pre_expr (FILE *outfile, const pre_expr expr)
 
     case REFERENCE:
       {
-	vn_reference_op_t vro;
-	unsigned int i;
 	vn_reference_t ref = PRE_EXPR_REFERENCE (expr);
-	fprintf (outfile, "{");
-	for (i = 0;
-	     ref->operands.iterate (i, &vro);
-	     i++)
-	  {
-	    bool closebrace = false;
-	    if (vro->opcode != SSA_NAME
-		&& TREE_CODE_CLASS (vro->opcode) != tcc_declaration)
-	      {
-		fprintf (outfile, "%s", get_tree_code_name (vro->opcode));
-		if (vro->op0)
-		  {
-		    fprintf (outfile, "<");
-		    closebrace = true;
-		  }
-	      }
-	    if (vro->op0)
-	      {
-		print_generic_expr (outfile, vro->op0);
-		if (vro->op1)
-		  {
-		    fprintf (outfile, ",");
-		    print_generic_expr (outfile, vro->op1);
-		  }
-		if (vro->op2)
-		  {
-		    fprintf (outfile, ",");
-		    print_generic_expr (outfile, vro->op2);
-		  }
-	      }
-	    if (closebrace)
-		fprintf (outfile, ">");
-	    if (i != ref->operands.length () - 1)
-	      fprintf (outfile, ",");
-	  }
-	fprintf (outfile, "}");
+	print_vn_reference_ops (outfile, ref->operands);
 	if (ref->vuse)
 	  {
 	    fprintf (outfile, "@");
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 0567a2e9ff5..16e75b518b0 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -249,6 +249,55 @@  vn_reference_hasher::equal (const vn_reference_s *v, const vn_reference_s *c)
 typedef hash_table<vn_reference_hasher> vn_reference_table_type;
 typedef vn_reference_table_type::iterator vn_reference_iterator_type;
 
+/* Pretty-print OPS to OUTFILE.  */
+
+void
+print_vn_reference_ops (FILE *outfile, const vec<vn_reference_op_s> ops)
+{
+  vn_reference_op_t vro;
+  unsigned int i;
+  fprintf (outfile, "{");
+  for (i = 0; ops.iterate (i, &vro); i++)
+    {
+      bool closebrace = false;
+      if (vro->opcode != SSA_NAME
+	  && TREE_CODE_CLASS (vro->opcode) != tcc_declaration)
+	{
+	  fprintf (outfile, "%s", get_tree_code_name (vro->opcode));
+	  if (vro->op0)
+	    {
+	      fprintf (outfile, "<");
+	      closebrace = true;
+	    }
+	}
+      if (vro->op0)
+	{
+	  print_generic_expr (outfile, vro->op0);
+	  if (vro->op1)
+	    {
+	      fprintf (outfile, ",");
+	      print_generic_expr (outfile, vro->op1);
+	    }
+	  if (vro->op2)
+	    {
+	      fprintf (outfile, ",");
+	      print_generic_expr (outfile, vro->op2);
+	    }
+	}
+      if (closebrace)
+	fprintf (outfile, ">");
+      if (i != ops.length () - 1)
+	fprintf (outfile, ",");
+    }
+  fprintf (outfile, "}");
+}
+
+DEBUG_FUNCTION void
+debug_vn_reference_ops (const vec<vn_reference_op_s> ops)
+{
+  print_vn_reference_ops (stderr, ops);
+  fputc ('\n', stderr);
+}
 
 /* The set of VN hashtables.  */
 
diff --git a/gcc/tree-ssa-sccvn.h b/gcc/tree-ssa-sccvn.h
index e4f1ff1eb20..6df526c269b 100644
--- a/gcc/tree-ssa-sccvn.h
+++ b/gcc/tree-ssa-sccvn.h
@@ -265,6 +265,7 @@  void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t);
 vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, alias_set_type,
 					   tree, vec<vn_reference_op_s>,
 					   tree, unsigned int);
+void print_vn_reference_ops (FILE *, const vec<vn_reference_op_s>);
 
 bool vn_nary_op_eq (const_vn_nary_op_t const vno1,
 		    const_vn_nary_op_t const vno2);