From 824cdc71a5662afd7728b8374e328bb6d94dda1a Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 15 May 2018 15:32:04 -0400
Subject: [PATCH 52/67] FIXME: start adding to other passes

---
 gcc/gimple-fold.c         | 29 ++++++++++++++---------------
 gcc/ipa-devirt.c          | 14 +++++++-------
 gcc/ipa.c                 | 16 ++++++----------
 gcc/optinfo.cc            |  8 ++++++++
 gcc/optinfo.h             |  5 +++++
 gcc/tree-ssa-loop-niter.c |  7 ++++---
 6 files changed, 44 insertions(+), 35 deletions(-)

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index bd8c44a..d8a7a8b 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -66,6 +66,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "calls.h"
 #include "tree-vector-builder.h"
 #include "tree-ssa-strlen.h"
+#include "optinfo.h"
 
 /* Return true when DECL can be referenced from current unit.
    FROM_DECL (if non-null) specify constructor of variable DECL was taken from.
@@ -346,15 +347,14 @@ fold_gimple_assign (gimple_stmt_iterator *si)
 		  = possible_polymorphic_call_targets (rhs, stmt, &final);
 		if (final && targets.length () <= 1 && dbg_cnt (devirt))
 		  {
-		    if (dump_enabled_p ())
+		    if (optinfo_enabled_p ())
 		      {
-			location_t loc = gimple_location_safe (stmt);
-			dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
-					 "resolving virtual function address "
-					 "reference to function %s\n",
-					 targets.length () == 1
-					 ? targets[0]->name ()
-					 : "NULL");
+			OPTINFO_SUCCESS (stmt)
+			  << optinfo_printf ("resolving virtual function address "
+					     "reference to function %s",
+					     targets.length () == 1
+					     ? targets[0]->name ()
+					     : "NULL");
 		      }
 		    if (targets.length () == 1)
 		      {
@@ -4064,14 +4064,13 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
 	  if (final && targets.length () <= 1 && dbg_cnt (devirt))
 	    {
 	      tree lhs = gimple_call_lhs (stmt);
-	      if (dump_enabled_p ())
+	      if (optinfo_enabled_p ())
 		{
-		  location_t loc = gimple_location_safe (stmt);
-		  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
-				   "folding virtual function call to %s\n",
-		 		   targets.length () == 1
-		  		   ? targets[0]->name ()
-		  		   : "__builtin_unreachable");
+		  OPTINFO_SUCCESS (stmt)
+		    << optinfo_printf ("folding virtual function call to %s",
+				       targets.length () == 1
+				       ? targets[0]->name ()
+				       : "__builtin_unreachable");
 		}
 	      if (targets.length () == 1)
 		{
diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index 308b6e6..ef532d8 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -131,6 +131,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "intl.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "optinfo.h"
 
 /* Hash based set of pairs of types.  */
 struct type_pair
@@ -3753,14 +3754,13 @@ ipa_devirt (void)
 	      }
 	    else if (dbg_cnt (devirt))
 	      {
-		if (dump_enabled_p ())
+		if (optinfo_enabled_p ())
                   {
-                    location_t locus = gimple_location_safe (e->call_stmt);
-                    dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, locus,
-				     "speculatively devirtualizing call "
-				     "in %s to %s\n",
-				     n->dump_name (),
-				     likely_target->dump_name ());
+		    OPTINFO_SUCCESS (e->call_stmt)
+		      << optinfo_printf ("speculatively devirtualizing call "
+					 "in %s to %s",
+					 n->dump_name (),
+					 likely_target->dump_name ());
                   }
 		if (!likely_target->can_be_discarded_p ())
 		  {
diff --git a/gcc/ipa.c b/gcc/ipa.c
index 9330de5..ddec39f 100644
--- a/gcc/ipa.c
+++ b/gcc/ipa.c
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "debug.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "optinfo.h"
 
 /* Return true when NODE has ADDR reference.  */
 
@@ -222,17 +223,12 @@ walk_polymorphic_call_targets (hash_set<void *> *reachable_call_targets,
 	    target = cgraph_node::get_create
 		       (builtin_decl_implicit (BUILT_IN_UNREACHABLE));
 
-	  if (dump_enabled_p ())
+	  if (optinfo_enabled_p ())
             {
-	      location_t locus;
-	      if (edge->call_stmt)
-		locus = gimple_location (edge->call_stmt);
-	      else
-		locus = UNKNOWN_LOCATION;
-	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, locus,
-			       "devirtualizing call in %s to %s\n",
-			       edge->caller->dump_name (),
-			       target->dump_name ());
+	      OPTINFO_SUCCESS (edge->call_stmt)
+		<< optinfo_printf ("devirtualizing call in %s to %s",
+				   edge->caller->dump_name (),
+				   target->dump_name ());
 	    }
 	  edge = edge->make_direct (target);
 	  if (ipa_fn_summaries)
diff --git a/gcc/optinfo.cc b/gcc/optinfo.cc
index cc77be8..a0b468b 100644
--- a/gcc/optinfo.cc
+++ b/gcc/optinfo.cc
@@ -306,14 +306,20 @@ pending_optinfo::operator<< (const optinfo_printf &p)
   return *this;
 }
 
+/* FIXME.  */
+
 static unsigned int scope_depth;
 
+/* FIXME.  */
+
 void
 push_optinfo_scope ()
 {
   scope_depth++;
 }
 
+/* FIXME.  */
+
 void
 pop_optinfo_scope ()
 {
@@ -321,6 +327,8 @@ pop_optinfo_scope ()
   optimization_records_maybe_pop_optinfo_scope ();
 }
 
+/* FIXME.  */
+
 unsigned int
 get_optinfo_scope_depth ()
 {
diff --git a/gcc/optinfo.h b/gcc/optinfo.h
index 9489516..47a14ef 100644
--- a/gcc/optinfo.h
+++ b/gcc/optinfo.h
@@ -307,6 +307,11 @@ class pending_optinfo
 #define OPTINFO_SUCCESS(LOC)\
   OPTINFO(OPTINFO_KIND_SUCCESS, (LOC))
 
+/* Emit that a failed optimization happened at LOC.  */
+
+#define OPTINFO_FAILURE(LOC)\
+  OPTINFO(OPTINFO_KIND_FAILURE, (LOC))
+
 /* Emit a note relating to an optimization at LOC.  */
 
 #define OPTINFO_NOTE(LOC)\
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 7a54c5f..8eee6de 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-scalar-evolution.h"
 #include "params.h"
 #include "tree-dfa.h"
+#include "optinfo.h"
 
 
 /* The maximum number of dominator BBs we search for conditions
@@ -2447,9 +2448,9 @@ number_of_iterations_exit (struct loop *loop, edge exit,
     return true;
 
   if (warn)
-    dump_printf_loc (MSG_MISSED_OPTIMIZATION, gimple_location_safe (stmt),
-		     "missed loop optimization: niters analysis ends up "
-		     "with assumptions.\n");
+    OPTINFO_FAILURE (stmt)
+      << ("missed loop optimization: niters analysis ends up "
+	  "with assumptions");
 
   return false;
 }
-- 
1.8.5.3

