From 5b50ddea13f5a605a9daab50c18731afa4604e94 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 19 Jun 2018 15:11:59 -0400
Subject: [PATCH 11/51] FIXME: tree-loop-distribution.c: port from fprintf to
 dump_printf

---
 gcc/testsuite/gcc.dg/tree-ssa/ldist-11.c |   4 +-
 gcc/tree-loop-distribution.c             | 100 +++++++++++++++++--------------
 2 files changed, 57 insertions(+), 47 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ldist-11.c b/gcc/testsuite/gcc.dg/tree-ssa/ldist-11.c
index 754c7fd..7d7a794 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ldist-11.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ldist-11.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */ 
-/* { dg-options "-O2 -ftree-loop-distribution -ftree-loop-distribute-patterns -fdump-tree-ldist-all" } */
+/* { dg-options "-O2 -ftree-loop-distribution -ftree-loop-distribute-patterns -fdump-tree-ldist-all -fopt-info-loop-all" } */
 
 void foo (int * __restrict__ ia,
 	  int * __restrict__ ib,
@@ -12,7 +12,7 @@ void foo (int * __restrict__ ia,
   long int mya[52];
   long int myb[52];
 
-  for (i=0; i < 52; i++)
+  for (i=0; i < 52; i++) /* { dg-optimized "Loop 1 distributed: split to 1 loops and 1 library calls." } */
     {
       mya[i] = ia[i] * oxa[i] + ib[i] * oxb[i];
       myb[i] = -ia[i] * oxb[i] + ib[i] * oxa[i];
diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
index 1e8a9f0..0d291b8 100644
--- a/gcc/tree-loop-distribution.c
+++ b/gcc/tree-loop-distribution.c
@@ -1024,14 +1024,12 @@ generate_memset_builtin (struct loop *loop, partition *partition)
   fn_call = gimple_build_call (fn, 3, mem, val, nb_bytes);
   gsi_insert_after (&gsi, fn_call, GSI_CONTINUE_LINKING);
 
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    {
-      fprintf (dump_file, "generated memset");
-      if (bytev == 0)
-	fprintf (dump_file, " zero\n");
-      else
-	fprintf (dump_file, "\n");
-    }
+  if (dump_enabled_p ())
+    dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | MSG_PRIORITY_INTERNALS,
+		     fn_call,
+		     (bytev == 0
+		      ? "generated memset zero\n"
+		      : "generated memset\n"));
 }
 
 /* Generate a call to memcpy for PARTITION in LOOP.  */
@@ -1067,13 +1065,12 @@ generate_memcpy_builtin (struct loop *loop, partition *partition)
   fn_call = gimple_build_call (fn, 3, dest, src, nb_bytes);
   gsi_insert_after (&gsi, fn_call, GSI_CONTINUE_LINKING);
 
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    {
-      if (kind == BUILT_IN_MEMCPY)
-	fprintf (dump_file, "generated memcpy\n");
-      else
-	fprintf (dump_file, "generated memmove\n");
-    }
+  if (dump_enabled_p ())
+    dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | MSG_PRIORITY_INTERNALS,
+		     fn_call,
+		     (kind == BUILT_IN_MEMCPY
+		      ? "generated memcpy\n"
+		      : "generated memmove\n"));
 }
 
 /* Remove and destroy the loop LOOP.  */
@@ -1742,9 +1739,10 @@ rdg_build_partitions (struct graph *rdg,
     {
       int v = rdg_vertex_for_stmt (rdg, stmt);
 
-      if (dump_file && (dump_flags & TDF_DETAILS))
-	fprintf (dump_file,
-		 "ldist asked to generate code for vertex %d\n", v);
+      if (dump_enabled_p ())
+	dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | MSG_PRIORITY_INTERNALS,
+			 stmt,
+			 "ldist asked to generate code for vertex %d\n", v);
 
       /* If the vertex is already contained in another partition so
          is the partition rooted at it.  */
@@ -1754,12 +1752,16 @@ rdg_build_partitions (struct graph *rdg,
       partition *partition = build_rdg_partition_for_vertex (rdg, v);
       bitmap_ior_into (processed, partition->stmts);
 
-      if (dump_file && (dump_flags & TDF_DETAILS))
+      if (dump_enabled_p ())
 	{
-	  fprintf (dump_file, "ldist creates useful %s partition:\n",
-		   partition->type == PTYPE_PARALLEL ? "parallel" : "sequent");
-	  bitmap_print (dump_file, partition->stmts, "  ", "\n");
+	  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | MSG_PRIORITY_INTERNALS,
+			   stmt,
+			   "ldist creates useful %s partition:\n",
+			   partition->type == PTYPE_PARALLEL
+			   ? "parallel" : "sequent");
 	}
+      if (dump_file && (dump_flags & TDF_DETAILS))
+	bitmap_print (dump_file, partition->stmts, "  ", "\n");
 
       partitions->safe_push (partition);
     }
@@ -2403,8 +2405,7 @@ compute_alias_check_pairs (struct loop *loop, vec<ddr_p> *alias_ddrs,
   niters = fold_convert (sizetype, niters);
   niters_plus_one = size_binop (PLUS_EXPR, niters, size_one_node);
 
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    fprintf (dump_file, "Creating alias check pairs:\n");
+  AUTO_DUMP_SCOPE ("Creating alias check pairs:", dump_user_location_t ());
 
   /* Iterate all data dependence relations and compute alias check pairs.  */
   for (i = 0; i < alias_ddrs->length (); i++)
@@ -2453,10 +2454,10 @@ compute_alias_check_pairs (struct loop *loop, vec<ddr_p> *alias_ddrs,
 
   /* Prune alias check pairs.  */
   prune_runtime_alias_test_list (comp_alias_pairs, factor);
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    fprintf (dump_file,
-	     "Improved number of alias checks from %d to %d\n",
-	     alias_ddrs->length (), comp_alias_pairs->length ());
+  if (dump_enabled_p ())
+    dump_printf (MSG_OPTIMIZED_LOCATIONS,
+		 "Improved number of alias checks from %d to %d\n",
+		 alias_ddrs->length (), comp_alias_pairs->length ());
 }
 
 /* Given data dependence relations in ALIAS_DDRS, generate runtime alias
@@ -2477,9 +2478,11 @@ version_loop_by_alias_check (vec<struct partition *> *partitions,
   /* Generate code for runtime alias checks if necessary.  */
   gcc_assert (alias_ddrs->length () > 0);
 
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    fprintf (dump_file,
-	     "Version loop <%d> with runtime alias check\n", loop->num);
+  if (dump_enabled_p ())
+    dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | MSG_PRIORITY_INTERNALS,
+		     find_loop_location (loop),
+		     "Version loop <%d> with runtime alias check\n",
+		     loop->num);
 
   compute_alias_check_pairs (loop, alias_ddrs, &comp_alias_pairs);
   create_runtime_alias_checks (loop, &comp_alias_pairs, &cond_expr);
@@ -2759,10 +2762,11 @@ distribute_loop (struct loop *loop, vec<gimple *> stmts,
   rdg = build_rdg (loop, cd);
   if (!rdg)
     {
-      if (dump_file && (dump_flags & TDF_DETAILS))
-	fprintf (dump_file,
-		 "Loop %d not distributed: failed to build the RDG.\n",
-		 loop->num);
+      if (dump_enabled_p ())
+	dump_printf_loc (MSG_MISSED_OPTIMIZATION | MSG_PRIORITY_INTERNALS,
+			 find_loop_location (loop),
+			 "Loop %d not distributed: failed to build the RDG.\n",
+			 loop->num);
 
       loop_nest.release ();
       free_data_refs (datarefs_vec);
@@ -2772,10 +2776,12 @@ distribute_loop (struct loop *loop, vec<gimple *> stmts,
 
   if (datarefs_vec.length () > MAX_DATAREFS_NUM)
     {
-      if (dump_file && (dump_flags & TDF_DETAILS))
-	fprintf (dump_file,
-		 "Loop %d not distributed: too many memory references.\n",
-		 loop->num);
+      if (dump_enabled_p ())
+	dump_printf_loc (MSG_MISSED_OPTIMIZATION | MSG_PRIORITY_INTERNALS,
+			 find_loop_location (loop),
+			 "Loop %d not distributed: "
+			 "too many memory references.\n",
+			 loop->num);
 
       free_rdg (rdg);
       loop_nest.release ();
@@ -3139,16 +3145,20 @@ pass_loop_distribution::execute (function *fun)
 	  if (nb_generated_loops + nb_generated_calls > 0)
 	    {
 	      changed = true;
-	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS,
-			       loc, "Loop%s %d distributed: split to %d loops "
-			       "and %d library calls.\n", str, loop->num,
-			       nb_generated_loops, nb_generated_calls);
+	      if (dump_enabled_p ())
+		dump_printf_loc (MSG_OPTIMIZED_LOCATIONS,
+				 loc,
+				 "Loop%s %d distributed: split to %d loops "
+				 "and %d library calls.\n", str, loop->num,
+				 nb_generated_loops, nb_generated_calls);
 
 	      break;
 	    }
 
-	  if (dump_file && (dump_flags & TDF_DETAILS))
-	    fprintf (dump_file, "Loop%s %d not distributed.\n", str, loop->num);
+	  if (dump_enabled_p ())
+	    dump_printf_loc (MSG_MISSED_OPTIMIZATION | MSG_PRIORITY_INTERNALS,
+			     loc,
+			     "Loop%s %d not distributed.\n", str, loop->num);
 	}
     }
 
-- 
1.8.5.3

