From 53d0e888b8f172d933c1a94c375bf3d6173bb462 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 6 Jul 2018 11:42:09 -0400
Subject: [PATCH 51/58] FIXME: move opt_pointer_wrapper to opt-problem.h; add
 comments

---
 gcc/opt-problem.h     | 89 +++++++++++++++++++++++++++++++++++++++++++++++++--
 gcc/tree-vectorizer.h | 53 ------------------------------
 2 files changed, 87 insertions(+), 55 deletions(-)

diff --git a/gcc/opt-problem.h b/gcc/opt-problem.h
index 5e7929a..3c50e52 100644
--- a/gcc/opt-problem.h
+++ b/gcc/opt-problem.h
@@ -69,7 +69,35 @@ class GTY(()) opt_problem
   dump_impl_location_t m_impl_location;
 };
 
-/* FIXME.  */
+/* A base class for wrapper classes that track a success/failure value, while
+   optionally supporting propagating an opt_problem * describing any
+   failure back up the call stack.
+
+   For instance, rather than:
+
+     bool ok = try_something ();
+     if (!ok)
+       {
+         if (dump_enabled_p ())
+           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                            "some message.\n");
+         return false;
+       }
+
+   we can replace the bool with an opt_result, so if dump_enabled_p, we
+   assume that if try_something fails, an opt_problem * will be created,
+   and we can propagate it up the call chain:
+
+     opt_result ok = try_something ();
+     if (!ok)
+       {
+         if (dump_enabled_p ())
+           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                            "some message.\n");
+         return ok;
+       }
+
+   The opt_problem is only created if dump_enabled_p.  */
 
 template <typename T>
 class opt_wrapper
@@ -94,7 +122,11 @@ class opt_wrapper
   opt_problem *m_problem;
 };
 
-/* FIXME.  */
+/* Subclass of opt_wrapper<T> for bool, where
+   - true signifies success, and
+   - false signifies failure
+   whilst effectively propagating an opt_problem * describing any failure
+   back up the call stack.  */
 
 class opt_result : public opt_wrapper <bool>
 {
@@ -138,4 +170,57 @@ class opt_result : public opt_wrapper <bool>
 
 };
 
+/* Subclass of opt_wrapper<T> where T is pointer type, for tracking
+   success/failure, where a non-NULL value signifies success, and
+   a NULL value signifies failure, supporting propagating an
+   opt_problem * describing the failure back up the call stack.  */
+
+template <typename PtrType_t>
+class opt_pointer_wrapper : public opt_wrapper <PtrType_t>
+{
+ public:
+  typedef PtrType_t wrapped_pointer_t;
+
+  /* Given a non-NULL pointer, make a success object wrapping it.  */
+
+  static opt_pointer_wrapper <wrapped_pointer_t>
+  success (wrapped_pointer_t ptr)
+  {
+    return opt_pointer_wrapper <wrapped_pointer_t> (ptr, NULL);
+  }
+
+  /* Given a failure wrapper of some other kind, make a NULL pointer
+     failure object, propagating the problem.  */
+
+  template <typename S>
+  static opt_pointer_wrapper <wrapped_pointer_t>
+  failure (opt_wrapper <S> other)
+  {
+    return opt_pointer_wrapper <wrapped_pointer_t> (NULL,
+						    other.get_problem ());
+  }
+
+  /* Make a NULL pointer failure object, with the given message.  */
+
+  static opt_pointer_wrapper <wrapped_pointer_t>
+  failure (const char *gmsgid,
+	   const dump_impl_location_t &impl_location
+	     = dump_impl_location_t ())
+  {
+    opt_problem *problem = opt_problem::make (gmsgid, NULL, impl_location);
+    return opt_pointer_wrapper <wrapped_pointer_t> (NULL, problem);
+  }
+
+  /* Support accessing the underlying pointer.  */
+
+  wrapped_pointer_t operator-> () const { return this->get_result (); }
+
+ private:
+  /* Private ctor; instances should be built using the static member
+     functions "success" and "failure".  */
+  opt_pointer_wrapper (wrapped_pointer_t result, opt_problem *problem)
+  : opt_wrapper<PtrType_t> (result, problem)
+  {}
+};
+
 #endif /* #ifndef GCC_OPT_PROBLEM_H */
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index b8077cf..4673764 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -595,59 +595,6 @@ typedef struct _loop_vec_info : public vec_info {
 #define LOOP_VINFO_ORIG_MAX_VECT_FACTOR(L) \
   (LOOP_VINFO_MAX_VECT_FACTOR (LOOP_VINFO_ORIG_LOOP_INFO (L)))
 
-/* Subclass of opt_wrapper<T> where T is pointer type, for tracking
-   success/failure, where a non-NULL value signifies success, and
-   a NULL value signifies failure, supporting propagating an
-   opt_problem * describing the failure back up the call stack.  */
-
-template <typename PtrType_t>
-class opt_pointer_wrapper : public opt_wrapper <PtrType_t>
-{
- public:
-  typedef PtrType_t wrapped_pointer_t;
-
-  /* Given a non-NULL pointer, make a success object wrapping it.  */
-
-  static opt_pointer_wrapper <wrapped_pointer_t>
-  success (wrapped_pointer_t ptr)
-  {
-    return opt_pointer_wrapper <wrapped_pointer_t> (ptr, NULL);
-  }
-
-  /* Given a failure wrapper of some other kind, make a NULL pointer
-     failure object, propagating the problem.  */
-
-  template <typename S>
-  static opt_pointer_wrapper <wrapped_pointer_t>
-  failure (opt_wrapper <S> other)
-  {
-    return opt_pointer_wrapper <wrapped_pointer_t> (NULL,
-						    other.get_problem ());
-  }
-
-  /* Make a NULL pointer failure object, with the given message.  */
-
-  static opt_pointer_wrapper <wrapped_pointer_t>
-  failure (const char *gmsgid,
-	   const dump_impl_location_t &impl_location
-	     = dump_impl_location_t ())
-  {
-    opt_problem *problem = opt_problem::make (gmsgid, NULL, impl_location);
-    return opt_pointer_wrapper <wrapped_pointer_t> (NULL, problem);
-  }
-
-  /* Support accessing the underlying pointer.  */
-
-  wrapped_pointer_t operator-> () const { return this->get_result (); }
-
- private:
-  /* Private ctor; instances should be built using the static member
-     functions "success" and "failure".  */
-  opt_pointer_wrapper (wrapped_pointer_t result, opt_problem *problem)
-  : opt_wrapper<PtrType_t> (result, problem)
-  {}
-};
-
 /* Wrapper for loop_vec_info, for tracking success/failure, where a non-NULL
    value signifies success, and a NULL value signifies failure, supporting
    propagating an opt_problem * describing the failure back up the call
-- 
1.8.5.3

