From d23a1bd88e41ac313e604c2b00a5f9830930dc65 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 5 Jul 2018 16:15:59 -0400
Subject: [PATCH 44/58] FIXME: eliminate opt_loop_vec_info ctor from ptr

---
 gcc/tree-vect-loop.c  | 25 ++++++++++++++-----------
 gcc/tree-vectorizer.h | 40 +++++++++++++++++++++++++---------------
 2 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 23caa86..1c2e590 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -1160,7 +1160,7 @@ vect_compute_single_scalar_iteration_cost (loop_vec_info loop_vinfo)
    - the number of iterations can be analyzed, i.e, a countable loop.  The
      niter could be analyzed under some assumptions.  */
 
-bool
+opt_result
 vect_analyze_loop_form_1 (struct loop *loop, gcond **loop_cond,
 			  tree *assumptions, tree *number_of_iterationsm1,
 			  tree *number_of_iterations, gcond **inner_loop_cond)
@@ -1351,16 +1351,18 @@ vect_analyze_loop_form_1 (struct loop *loop, gcond **loop_cond,
 
 /* Analyze LOOP form and return a loop_vec_info if it is of suitable form.  */
 
-loop_vec_info
+opt_loop_vec_info
 vect_analyze_loop_form (struct loop *loop, vec_info_shared *shared)
 {
   tree assumptions, number_of_iterations, number_of_iterationsm1;
   gcond *loop_cond, *inner_loop_cond = NULL;
 
-  if (! vect_analyze_loop_form_1 (loop, &loop_cond,
-				  &assumptions, &number_of_iterationsm1,
-				  &number_of_iterations, &inner_loop_cond))
-    return NULL;
+  opt_result res
+    = vect_analyze_loop_form_1 (loop, &loop_cond,
+				&assumptions, &number_of_iterationsm1,
+				&number_of_iterations, &inner_loop_cond);
+  if (!res)
+    return opt_loop_vec_info::failure (res);
 
   loop_vec_info loop_vinfo = new _loop_vec_info (loop, shared);
   LOOP_VINFO_NITERSM1 (loop_vinfo) = number_of_iterationsm1;
@@ -1398,7 +1400,7 @@ vect_analyze_loop_form (struct loop *loop, vec_info_shared *shared)
 
   gcc_assert (!loop->aux);
   loop->aux = loop_vinfo;
-  return loop_vinfo;
+  return opt_loop_vec_info::success (loop_vinfo);
 }
 
 
@@ -2321,8 +2323,7 @@ vect_analyze_loop (struct loop *loop, loop_vec_info orig_loop_vinfo,
       if (dump_enabled_p ())
 	dump_printf_loc (MSG_NOTE, vect_location,
 			 "outer-loop already vectorized.\n");
-      return opt_loop_vec_info (NULL,
-				"outer-loop already vectorized");
+      return opt_loop_vec_info::failure ("outer-loop already vectorized");
     }
 
   if (!find_loop_nest (loop, &shared->loop_nest))
@@ -2332,7 +2333,9 @@ vect_analyze_loop (struct loop *loop, loop_vec_info orig_loop_vinfo,
 			 "not vectorized: loop nest containing two "
 			 "or more consecutive inner loops cannot be "
 			 "vectorized\n");
-      return NULL;
+      return opt_loop_vec_info::failure ("loop nest containing two "
+					 "or more consecutive inner loops"
+					 " cannot be vectorized");
     }
 
   unsigned n_stmts = 0;
@@ -2378,7 +2381,7 @@ vect_analyze_loop (struct loop *loop, loop_vec_info orig_loop_vinfo,
       if (fatal
 	  || next_size == vector_sizes.length ()
 	  || known_eq (current_vector_size, 0U))
-	return opt_loop_vec_info (NULL, res);
+	return opt_loop_vec_info::failure (res);
 
       /* Try the next biggest vector size.  */
       current_vector_size = vector_sizes[next_size++];
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index aeb4594..8ffd8e5 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -600,28 +600,37 @@ typedef struct _loop_vec_info : public vec_info {
 class opt_loop_vec_info : public opt_wrapper <loop_vec_info>
 {
  public:
-#if 1
-  /* Deprecated ctor.  During transition, allow construction from ptr.
-     We want to eliminate this, as it doesn't capture the reason for
-     failures.  */
-  opt_loop_vec_info (loop_vec_info ptr,
-		     const dump_impl_location_t &impl_location
-		       = dump_impl_location_t ())
-    : opt_wrapper <loop_vec_info> (ptr,
-				   new opt_problem ("UNKNOWN", NULL,
-						    impl_location))
+  static opt_loop_vec_info
+  success (loop_vec_info ptr)
   {
+    return opt_loop_vec_info (ptr, NULL);
   }
-#endif
 
   template <typename T>
-  opt_loop_vec_info (loop_vec_info ptr, opt_wrapper <T> other)
-  : opt_wrapper <loop_vec_info> (ptr,
-				 other.get_problem ())
+  static opt_loop_vec_info
+  failure (opt_wrapper <T> other)
   {
+    return opt_loop_vec_info (NULL,
+			      other.get_problem ());
+  }
+
+  static opt_loop_vec_info
+  failure (const char *gmsgid,
+	   const dump_impl_location_t &impl_location
+	     = dump_impl_location_t ())
+  {
+    // FIXME: dump_enabled_p
+    return opt_loop_vec_info (NULL,
+			      new opt_problem (gmsgid, NULL,
+					       impl_location));
   }
 
   loop_vec_info operator-> () const { return m_result; }
+
+ private:
+  opt_loop_vec_info (wrapped_t result, opt_problem *problem)
+  : opt_wrapper (result, problem)
+  {}
 };
 
 static inline loop_vec_info
@@ -1645,7 +1654,8 @@ extern tree vect_get_loop_mask (gimple_stmt_iterator *, vec_loop_masks *,
 
 /* Drive for loop transformation stage.  */
 extern struct loop *vect_transform_loop (loop_vec_info);
-extern loop_vec_info vect_analyze_loop_form (struct loop *, vec_info_shared *);
+extern opt_loop_vec_info vect_analyze_loop_form (struct loop *,
+						 vec_info_shared *);
 extern bool vectorizable_live_operation (gimple *, gimple_stmt_iterator *,
 					 slp_tree, int, gimple **,
 					 stmt_vector_for_cost *);
-- 
1.8.5.3

