Add debug_vn_reference_ops helper
authorRichard Biener <rguenther@suse.de>
Wed, 7 Apr 2021 07:09:09 +0000 (09:09 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 7 Apr 2021 07:59:07 +0000 (09:59 +0200)
This factors out a helper to dump VN reference operands, sth that
proves useful in debugging VN issues.

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
gcc/tree-ssa-sccvn.c
gcc/tree-ssa-sccvn.h

index 1a022fb..91dd492 100644 (file)
@@ -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, "@");
index 0567a2e..16e75b5 100644 (file)
@@ -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.  */
 
index e4f1ff1..6df526c 100644 (file)
@@ -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);