From 6cda8cbe9739a26090a5ecd24caf9459fd8917ed Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 5 Jul 2018 15:15:38 -0400
Subject: [PATCH 41/58] FIXME: add dump_impl_location_t to opt_problem, use
 push_vect_problem in more places

---
 gcc/opt-problem.cc                       |  8 ++++++++
 gcc/opt-problem.h                        |  6 ++++--
 gcc/optinfo-emit-diagnostics.cc          |  4 ++--
 gcc/testsuite/gcc.dg/vect/vect-remarks.c |  4 ++--
 gcc/tree-vect-loop.c                     | 13 +++++++++++--
 gcc/tree-vect-stmts.c                    |  4 ++--
 gcc/tree-vectorizer.c                    | 10 ++++++----
 gcc/tree-vectorizer.h                    |  6 +++++-
 8 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/gcc/opt-problem.cc b/gcc/opt-problem.cc
index 40fcd4c..58b3347 100644
--- a/gcc/opt-problem.cc
+++ b/gcc/opt-problem.cc
@@ -44,6 +44,11 @@ opt_report::remark (dump_location_t loc, int opt, const char *gmsgid, ...)
   return ret;
 }
 
+// FIXME:
+extern void
+print_impl_location (pretty_printer *pp, const dump_impl_location_t &impl_loc);
+
+
 /* Emit a diagnostic note describing why an optimization wasn't possible.  */
 
 void
@@ -55,12 +60,15 @@ opt_problem::report_reason (opt_report &report)
   bool show_color = pp_show_color (global_dc->printer);
 
   pretty_printer pp;
+  pp_show_color (&pp) = pp_show_color (global_dc->printer);
   pp_string (&pp, m_text);
   pp_string (&pp, ": ");
   pp_begin_quote (&pp, show_color);
   pp_gimple_stmt_1 (&pp, m_stmt, 0, TDF_SLIM);
   pp_end_quote (&pp, show_color);
 
+  print_impl_location (&pp, m_impl_location);
+
   const char *msg = pp_formatted_text (&pp);
 
   inform (gimple_location_safe (m_stmt), "%s", msg);
diff --git a/gcc/opt-problem.h b/gcc/opt-problem.h
index b045efc..05d0e11 100644
--- a/gcc/opt-problem.h
+++ b/gcc/opt-problem.h
@@ -39,8 +39,9 @@ public:
 class GTY(()) opt_problem
 {
  public:
-  opt_problem (const char *text, gimple *stmt)
-  : m_text (text), m_stmt (stmt)
+  opt_problem (const char *text, gimple *stmt,
+	       const dump_impl_location_t &impl_location)
+  : m_text (text), m_stmt (stmt), m_impl_location (impl_location)
   {
     /* We shouldn't be bothering to construct these objects if
        dumping isn't enabled.  */
@@ -52,6 +53,7 @@ class GTY(()) opt_problem
  private:
   const char *m_text;
   gimple *m_stmt;
+  dump_impl_location_t m_impl_location;
 };
 
 #endif /* #ifndef GCC_OPT_PROBLEM_H */
diff --git a/gcc/optinfo-emit-diagnostics.cc b/gcc/optinfo-emit-diagnostics.cc
index db9b65e..30acb9e 100644
--- a/gcc/optinfo-emit-diagnostics.cc
+++ b/gcc/optinfo-emit-diagnostics.cc
@@ -140,7 +140,7 @@ print_count (pretty_printer *pp, profile_count count)
 
 /* Print IMPL_LOC to PP (as part of a remark).  */
 
-static void
+void
 print_impl_location (pretty_printer *pp, const dump_impl_location_t &impl_loc)
 {
   bool show_color = pp_show_color (pp);
@@ -211,7 +211,7 @@ emit_optinfo_as_diagnostic_remark (const optinfo *optinfo)
       return;
 
 #if 1
-#if 1
+#if 0
   switch (optinfo->get_kind ())
     {
     default:
diff --git a/gcc/testsuite/gcc.dg/vect/vect-remarks.c b/gcc/testsuite/gcc.dg/vect/vect-remarks.c
index 6ce6d27..01aeacf 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-remarks.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-remarks.c
@@ -6,7 +6,7 @@ extern void accumulate (int x, int *a);
 int compute_sum_without_inlining (int arr[], int n)
 {
   int sum = 0;
-  for (int i = 0; i < n; ++i)
-    accumulate (arr[i], &sum);
+  for (int i = 0; i < n; ++i) /* { dg-remark "couldn't vectorize loop" } */
+    accumulate (arr[i], &sum); /* { dg-message "FIXME 2: 'accumulate .*'" } */
   return sum;
 }
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 072a38b..19c7c30 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -1786,7 +1786,12 @@ vect_get_datarefs_in_loop (loop_p loop, basic_block *bbs,
 		if (fndecl != NULL_TREE)
 		  {
 		    cgraph_node *node = cgraph_node::get (fndecl);
-		    if (node != NULL && node->simd_clones != NULL)
+		    if (node == NULL)
+		      {
+			push_vect_problem ("FIXME 1", stmt);
+			return false;
+		      }
+		    if (node->simd_clones != NULL)
 		      {
 			unsigned int j, n = gimple_call_num_args (stmt);
 			for (j = 0; j < n; j++)
@@ -1810,13 +1815,17 @@ vect_get_datarefs_in_loop (loop_p loop, basic_block *bbs,
 		      }
 		  }
 	      }
+	    push_vect_problem ("FIXME 2", stmt);
 	    return false;
 	  }
 	/* If dependence analysis will give up due to the limit on the
 	   number of datarefs stop here and fail fatally.  */
 	if (datarefs->length ()
 	    > (unsigned)PARAM_VALUE (PARAM_LOOP_MAX_DATAREFS_FOR_DATADEPS))
-	  return false;
+	  {
+	    push_vect_problem ("FIXME: exceeded PARAM_LOOP_MAX_DATAREFS_FOR_DATADEPS", stmt);
+	    return false;
+	  }
       }
   return true;
 }
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index f7b59cb..7d0fc9b 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -9528,7 +9528,7 @@ vect_analyze_stmt (gimple *stmt, bool *need_to_vectorize, slp_tree node,
 
   if (!ok)
     {
-      push_vect_problem ("relevant stmt not supported", stmt);
+      push_vect_problem ("not vectorized: relevant stmt not supported", stmt);
       return false;
     }
 
@@ -9538,7 +9538,7 @@ vect_analyze_stmt (gimple *stmt, bool *need_to_vectorize, slp_tree node,
       && STMT_VINFO_TYPE (stmt_info) != reduc_vec_info_type
       && !can_vectorize_live_stmts (stmt, NULL, node, NULL, cost_vec))
     {
-      push_vect_problem ("live stmt not supported", stmt);
+      push_vect_problem ("not vectorized: live stmt not supported", stmt);
 
        return false;
     }
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index edbc37f..cb53d3b 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -1349,14 +1349,16 @@ opt_problem *the_vect_problem;
 // FIXME: maybe a stack of these?  or not
 
 void
-push_vect_problem (const char *text, gimple *stmt)
+push_vect_problem (const char *text, gimple *stmt,
+		   const dump_impl_location_t &impl_location)
 {
   if (!dump_enabled_p ())
     return;
 
-  the_vect_problem = new opt_problem (text, stmt);
+  the_vect_problem = new opt_problem (text, stmt, impl_location);
 
-  dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-		   "not vectorized: %s", text);
+  dump_printf_loc (MSG_MISSED_OPTIMIZATION,
+		   dump_location_t (vect_location, impl_location),
+		   "%s", text);
   dump_gimple_stmt (MSG_MISSED_OPTIMIZATION, TDF_SLIM, stmt, 0);
 }
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 0d4cb18..62061de 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -1669,7 +1669,11 @@ void vect_free_loop_info_assumptions (struct loop *);
 class opt_problem;
 extern opt_problem *the_vect_problem;
 
-extern void push_vect_problem (const char *text, gimple *stmt);
+// FIXME: move the dump_impl_location_t inside the wrapper.
+
+extern void push_vect_problem (const char *text, gimple *stmt,
+			       const dump_impl_location_t &impl_location
+			         = dump_impl_location_t ());
 
 
 #endif  /* GCC_TREE_VECTORIZER_H  */
-- 
1.8.5.3

