On 8/25/21 11:46 AM, Andrew MacLeod wrote:
On 8/25/21 1:25 PM, Martin Sebor wrote:
I noticed that the output of -fdump-tree-walloca (and probably all
passes that call gimple_ranger::export_global_ranges()) includes
the following two lines for all functions, even when there's
nothing else of relevance after them:

Exported global range table
===========================

I was a bit puzzled by it at first, wondering if it was leftover
debugging output, until I checked the code and realized it's
a header that may be (but isn't always) followed by the contents
of the table.

To reduce clutter in the dump the attached patch changes the function
to print the header only when it is followed by at least one line of
output.  (Another tweak to reduce even further the amount of output
printed by default that might be worth considering is to print
the table only when TDF_DETAILS is set.)

Martin

Except checking x == 1 won't work if ssa_name(1)  was not updated.

Just set a flag if the header hasn't been printed yet. tried and true. I guess you can protect it behind details if you want.

Doh!  I've fixed that.  While testing I came across another instance
of the same pattern so I've made the same change there as well.  I
also took the liberty to make the output slightly more consistent
between the two dumps.

Attached is what I'm planning to commit.  Please let me know if you
have any other suggestions.

FWIW, I see duplicate output in the EVRP1 dump that looks just like
it could be the output under Non-varying global ranges. I wonder if
it's the result of the block in ranger_cache::fill_block_cache guarded
by if (DEBUG_RANGE_CACHE).

Martin
Avoid printing range table header alone.

gcc/ChangeLog:
	* gimple-range-cache.cc (ssa_global_cache::dump): Avoid printing
	range table header alone.
	* gimple-range.cc (gimple_ranger::export_global_ranges): Same.

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 4138d0556c6..facf981c15d 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -628,20 +628,32 @@ ssa_global_cache::clear ()
 void
 ssa_global_cache::dump (FILE *f)
 {
-  unsigned x;
-  int_range_max r;
-  fprintf (f, "Non-varying global ranges:\n");
-  fprintf (f, "=========================:\n");
-  for ( x = 1; x < num_ssa_names; x++)
-    if (gimple_range_ssa_p (ssa_name (x)) &&
-	get_global_range (r, ssa_name (x))  && !r.varying_p ())
-      {
-	print_generic_expr (f, ssa_name (x), TDF_NONE);
-	fprintf (f, "  : ");
-	r.dump (f);
-	fprintf (f, "\n");
-      }
-  fputc ('\n', f);
+  /* Cleared after the table header has been printed.  */
+  bool print_header = true;
+  for (unsigned x = 1; x < num_ssa_names; x++)
+    {
+      int_range_max r;
+      if (gimple_range_ssa_p (ssa_name (x)) &&
+	  get_global_range (r, ssa_name (x))  && !r.varying_p ())
+	{
+	  if (print_header)
+	    {
+	      /* Print the header only when there's something else
+		 to print below.  */
+	      fprintf (f, "Non-varying global ranges:\n");
+	      fprintf (f, "==========================\n");
+	      print_header = false;
+	    }
+
+	  print_generic_expr (f, ssa_name (x), TDF_NONE);
+	  fprintf (f, "  : ");
+	  r.dump (f);
+	  fprintf (f, "\n");
+	}
+    }
+
+  if (!print_header)
+    fputc ('\n', f);
 }
 
 // --------------------------------------------------------------------------
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index ef3afeacc90..fb23d567971 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -259,16 +259,11 @@ gimple_ranger::range_of_stmt (irange &r, gimple *s, tree name)
 void
 gimple_ranger::export_global_ranges ()
 {
-  unsigned x;
-  int_range_max r;
-  if (dump_file)
-    {
-      fprintf (dump_file, "Exported global range table\n");
-      fprintf (dump_file, "===========================\n");
-    }
-
-  for ( x = 1; x < num_ssa_names; x++)
+  /* Cleared after the table header has been printed.  */
+  bool print_header = true;
+  for (unsigned x = 1; x < num_ssa_names; x++)
     {
+      int_range_max r;
       tree name = ssa_name (x);
       if (name && !SSA_NAME_IN_FREE_LIST (name)
 	  && gimple_range_ssa_p (name)
@@ -276,21 +271,29 @@ gimple_ranger::export_global_ranges ()
 	  && !r.varying_p())
 	{
 	  bool updated = update_global_range (r, name);
+	  if (!updated || !dump_file || !(dump_flags & TDF_DETAILS))
+	    continue;
 
-	  if (updated && dump_file)
+	  if (print_header)
 	    {
-	      value_range vr = r;
-	      print_generic_expr (dump_file, name , TDF_SLIM);
-	      fprintf (dump_file, " --> ");
-	      vr.dump (dump_file);
+	      /* Print the header only when there's something else
+		 to print below.  */
+	      fprintf (dump_file, "Exported global range table:\n");
+	      fprintf (dump_file, "============================\n");
+	      print_header = false;
+	    }
+
+	  value_range vr = r;
+	  print_generic_expr (dump_file, name , TDF_SLIM);
+	  fprintf (dump_file, "  : ");
+	  vr.dump (dump_file);
+	  fprintf (dump_file, "\n");
+	  int_range_max same = vr;
+	  if (same != r)
+	    {
+	      fprintf (dump_file, "         irange : ");
+	      r.dump (dump_file);
 	      fprintf (dump_file, "\n");
-	      int_range_max same = vr;
-	      if (same != r)
-		{
-		  fprintf (dump_file, "         irange : ");
-		  r.dump (dump_file);
-		  fprintf (dump_file, "\n");
-		}
 	    }
 	}
     }

Reply via email to