From f4e1331a642b3e451cc87784e2375f894a69dfb1 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 28 Jun 2018 07:33:30 -0400
Subject: [PATCH 44/44] WIP on high-level opt_report thing

---
 gcc/opt-problem.cc                       | 21 ++++++++++++++++++++-
 gcc/opt-problem.h                        | 14 +++++++++++++-
 gcc/optinfo-emit-diagnostics.cc          |  6 ++++++
 gcc/testsuite/gcc.dg/vect/vect-remarks.c |  1 +
 gcc/tree-vectorizer.c                    |  7 +++++++
 5 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/gcc/opt-problem.cc b/gcc/opt-problem.cc
index 78d5200..40fcd4c 100644
--- a/gcc/opt-problem.cc
+++ b/gcc/opt-problem.cc
@@ -29,11 +29,29 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-pretty-print.h"
 #include "opt-problem.h"
 
+/* FIXME.  */
+
+bool
+opt_report::remark (dump_location_t loc, int opt, const char *gmsgid, ...)
+{
+  va_list ap;
+  va_start (ap, gmsgid);
+  bool ret = emit_diagnostic_valist (DK_REMARK, loc.get_location_t (), opt,
+				     gmsgid, &ap);
+  va_end (ap);
+
+  // FIXME: but also create an optinfo (but we don't want a duplicate remark)
+  return ret;
+}
+
 /* Emit a diagnostic note describing why an optimization wasn't possible.  */
 
 void
-opt_problem::report_reason ()
+opt_problem::report_reason (opt_report &report)
 {
+#if 0
+  // FIXME
+#else
   bool show_color = pp_show_color (global_dc->printer);
 
   pretty_printer pp;
@@ -46,4 +64,5 @@ opt_problem::report_reason ()
   const char *msg = pp_formatted_text (&pp);
 
   inform (gimple_location_safe (m_stmt), "%s", msg);
+#endif
 }
diff --git a/gcc/opt-problem.h b/gcc/opt-problem.h
index 406f348..b045efc 100644
--- a/gcc/opt-problem.h
+++ b/gcc/opt-problem.h
@@ -21,6 +21,18 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_OPT_PROBLEM_H
 #define GCC_OPT_PROBLEM_H
 
+/* High-level optimization reporting API.
+   User-facing, i18n, etc.
+   FIXME: this exists so that the underlying optrecords can be grouped
+   together, if we're doing optrecords.  */
+
+class opt_report
+{
+public:
+  bool remark (dump_location_t, int, const char *, ...)
+    ATTRIBUTE_GCC_DIAG(4,5);
+};
+
 /* When -fopt-info is enabled: information about why an optimization
    failed (e.g. vectorization).  */
 
@@ -35,7 +47,7 @@ class GTY(()) opt_problem
     gcc_assert (dump_enabled_p ());
   }
 
-  void report_reason ();
+  void report_reason (opt_report &report);
 
  private:
   const char *m_text;
diff --git a/gcc/optinfo-emit-diagnostics.cc b/gcc/optinfo-emit-diagnostics.cc
index c00917e..98a988a 100644
--- a/gcc/optinfo-emit-diagnostics.cc
+++ b/gcc/optinfo-emit-diagnostics.cc
@@ -206,6 +206,8 @@ emit_optinfo_as_diagnostic_remark (const optinfo *optinfo)
   if (!flag_remarks)
     return;
 
+#if 0
+#if 0
   switch (optinfo->get_kind ())
     {
     default:
@@ -218,6 +220,10 @@ emit_optinfo_as_diagnostic_remark (const optinfo *optinfo)
       /* FIXME: don't emit notes and scope for now.  */
       return;
     }
+#else
+  return;
+#endif
+#endif
 
   remark_printer pp (pp_show_color (global_dc->printer));
 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-remarks.c b/gcc/testsuite/gcc.dg/vect/vect-remarks.c
index 93ff224..6ce6d27 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-remarks.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-remarks.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-options "-fremarks -O3" } */
 
 extern void accumulate (int x, int *a);
 
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index 9031374..edbc37f 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -712,9 +712,16 @@ try_vectorize_loop_1 (hash_table<simduid_to_vf> *&simduid_to_vf_htab,
 
   if (the_vect_problem)
     {
+#if 1
+      opt_report report;
+      if (report.remark (vect_location, 0,
+			"couldn't vectorize loop"))
+	the_vect_problem->report_reason (report);
+#else
       if (remark (vect_location.get_location_t (), 0,
 		  "couldn't vectorize loop"))
 	the_vect_problem->report_reason ();
+#endif
       delete the_vect_problem;
       the_vect_problem = NULL;
     }
-- 
1.8.5.3

