From c3170ad6fa833656d2d1d467ed613a743f73513e Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 21 Jun 2018 16:07:41 -0400
Subject: [PATCH 38/44] FIXME: cprop.c: RTL examples (using dump_rtl)

---
 gcc/cprop.c | 84 +++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 45 insertions(+), 39 deletions(-)

diff --git a/gcc/cprop.c b/gcc/cprop.c
index e4df509..3908992 100644
--- a/gcc/cprop.c
+++ b/gcc/cprop.c
@@ -969,13 +969,13 @@ cprop_jump (basic_block bb, rtx_insn *setcc, rtx_insn *jump, rtx from, rtx src)
     delete_insn (setcc);
 
   global_const_prop_count++;
-  if (dump_file != NULL)
+  if (dump_enabled_p ())
     {
-      fprintf (dump_file,
-	       "GLOBAL CONST-PROP: Replacing reg %d in jump_insn %d with "
-	       "constant ", REGNO (from), INSN_UID (jump));
-      print_rtl (dump_file, src);
-      fprintf (dump_file, "\n");
+      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, jump,
+		       "GLOBAL CONST-PROP: Replacing reg %d in jump_insn %d with "
+		       "constant ", REGNO (from), INSN_UID (jump));
+      dump_rtl (MSG_OPTIMIZED_LOCATIONS, src);
+      dump_printf (MSG_OPTIMIZED_LOCATIONS, "\n");
     }
   purge_dead_edges (bb);
 
@@ -1084,14 +1084,16 @@ cprop_insn (rtx_insn *insn)
 	    {
 	      changed_this_round = changed = 1;
 	      global_const_prop_count++;
-	      if (dump_file != NULL)
+	      if (dump_enabled_p ())
 		{
-		  fprintf (dump_file,
-			   "GLOBAL CONST-PROP: Replacing reg %d in ", regno);
-		  fprintf (dump_file, "insn %d with constant ",
-			   INSN_UID (insn));
-		  print_rtl (dump_file, src_cst);
-		  fprintf (dump_file, "\n");
+		  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, insn,
+				   "GLOBAL CONST-PROP: Replacing reg %d in ",
+				   regno);
+		  dump_printf (MSG_OPTIMIZED_LOCATIONS,
+			       "insn %d with constant ",
+			       INSN_UID (insn));
+		  dump_rtl (MSG_OPTIMIZED_LOCATIONS, src_cst);
+		  dump_printf (MSG_OPTIMIZED_LOCATIONS, "\n");
 		}
 	      if (insn->deleted ())
 		return 1;
@@ -1103,12 +1105,12 @@ cprop_insn (rtx_insn *insn)
 	    {
 	      changed_this_round = changed = 1;
 	      global_copy_prop_count++;
-	      if (dump_file != NULL)
+	      if (dump_enabled_p ())
 		{
-		  fprintf (dump_file,
-			   "GLOBAL COPY-PROP: Replacing reg %d in insn %d",
-			   regno, INSN_UID (insn));
-		  fprintf (dump_file, " with reg %d\n", REGNO (src_reg));
+		  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, insn,
+				   "GLOBAL COPY-PROP: Replacing reg %d"
+				   " in insn %d with reg %d\n",
+				   regno, INSN_UID (insn), REGNO (src_reg));
 		}
 
 	      /* The original insn setting reg_used may or may not now be
@@ -1210,26 +1212,28 @@ do_local_cprop (rtx x, rtx_insn *insn)
 	}
       if (newcnst && constprop_register (x, newcnst, insn))
 	{
-	  if (dump_file != NULL)
+	  if (dump_enabled_p ())
 	    {
-	      fprintf (dump_file, "LOCAL CONST-PROP: Replacing reg %d in ",
-		       REGNO (x));
-	      fprintf (dump_file, "insn %d with constant ",
-		       INSN_UID (insn));
-	      print_rtl (dump_file, newcnst);
-	      fprintf (dump_file, "\n");
+	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, insn,
+			       "LOCAL CONST-PROP: Replacing reg %d in ",
+			       REGNO (x));
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS, "insn %d with constant ",
+			   INSN_UID (insn));
+	      dump_rtl (MSG_OPTIMIZED_LOCATIONS, newcnst);
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS, "\n");
 	    }
 	  local_const_prop_count++;
 	  return true;
 	}
       else if (newreg && newreg != x && try_replace_reg (x, newreg, insn))
 	{
-	  if (dump_file != NULL)
+	  if (dump_enabled_p ())
 	    {
-	      fprintf (dump_file,
-		       "LOCAL COPY-PROP: Replacing reg %d in insn %d",
-		       REGNO (x), INSN_UID (insn));
-	      fprintf (dump_file, " with reg %d\n", REGNO (newreg));
+	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, insn,
+			       "LOCAL COPY-PROP: Replacing reg %d in insn %d",
+			       REGNO (x), INSN_UID (insn));
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS, " with reg %d\n",
+			   REGNO (newreg));
 	    }
 	  local_copy_prop_count++;
 	  return true;
@@ -1655,16 +1659,18 @@ bypass_block (basic_block bb, rtx_insn *setcc, rtx_insn *jump)
 		    insert_insn_on_edge (copy_insn (pat), e);
 		}
 
-	      if (dump_file != NULL)
+	      if (dump_enabled_p ())
 		{
-		  fprintf (dump_file, "JUMP-BYPASS: Proved reg %d "
-				      "in jump_insn %d equals constant ",
-			   regno, INSN_UID (jump));
-		  print_rtl (dump_file, set->src);
-		  fprintf (dump_file, "\n\t     when BB %d is entered from "
-				      "BB %d.  Redirect edge %d->%d to %d.\n",
-			   old_dest->index, e->src->index, e->src->index,
-			   old_dest->index, dest->index);
+		  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, jump,
+				   "JUMP-BYPASS: Proved reg %d "
+				   "in jump_insn %d equals constant ",
+				   regno, INSN_UID (jump));
+		  dump_rtl (MSG_OPTIMIZED_LOCATIONS, set->src);
+		  dump_printf (MSG_OPTIMIZED_LOCATIONS,
+			       "\n\t     when BB %d is entered from "
+			       "BB %d.  Redirect edge %d->%d to %d.\n",
+			       old_dest->index, e->src->index, e->src->index,
+			       old_dest->index, dest->index);
 		}
 	      change = 1;
 	      removed_p = 1;
-- 
1.8.5.3

