Re: [10/46] Temporarily make stmt_vec_info a class

2018-07-25 Thread Richard Biener
On Tue, Jul 24, 2018 at 11:57 AM Richard Sandiford
 wrote:
>
> This patch turns stmt_vec_info into an unspeakably bad wrapper class
> and adds an implicit conversion to the associated gimple stmt.
> Having this conversion makes the rest of the series easier to write,
> but since the class goes away again at the end of the series, I've
> not bothered adding any comments or tried to make it pretty.

So I guess I do not need to approve it ;)

>
> 2018-07-24  Richard Sandiford  
>
> gcc/
> * tree-vectorizer.h (stmt_vec_info): Temporarily change from
> a typedef to a wrapper class.
> (NULL_STMT_VEC_INFO): New macro.
> (vec_info::stmt_infos): Change to vec.
> (stmt_vec_info::operator*): New function.
> (stmt_vec_info::operator gimple *): Likewise.
> (set_vinfo_for_stmt): Use NULL_STMT_VEC_INFO.
> (add_stmt_costs): Likewise.
> * tree-vect-loop-manip.c (iv_phi_p): Likewise.
> * tree-vect-loop.c (vect_compute_single_scalar_iteration_cost)
> (vect_get_known_peeling_cost): Likewise.
> (vect_estimate_min_profitable_iters): Likewise.
> * tree-vect-patterns.c (vect_init_pattern_stmt): Likewise.
> * tree-vect-slp.c (vect_remove_slp_scalar_calls): Likewise.
> * tree-vect-stmts.c (vect_build_gather_load_calls): Likewise.
> (vectorizable_store, free_stmt_vec_infos): Likewise.
> (new_stmt_vec_info): Change return type of xcalloc to
> _stmt_vec_info *.
>
> Index: gcc/tree-vectorizer.h
> ===
> --- gcc/tree-vectorizer.h   2018-07-24 10:22:30.401309046 +0100
> +++ gcc/tree-vectorizer.h   2018-07-24 10:22:33.829278607 +0100
> @@ -21,12 +21,31 @@ Software Foundation; either version 3, o
>  #ifndef GCC_TREE_VECTORIZER_H
>  #define GCC_TREE_VECTORIZER_H
>
> +class stmt_vec_info {
> +public:
> +  stmt_vec_info () {}
> +  stmt_vec_info (struct _stmt_vec_info *ptr) : m_ptr (ptr) {}
> +  struct _stmt_vec_info *operator-> () const { return m_ptr; }
> +  struct _stmt_vec_info * () const;
> +  operator struct _stmt_vec_info * () const { return m_ptr; }
> +  operator gimple * () const;
> +  operator void * () const { return m_ptr; }
> +  operator bool () const { return m_ptr; }
> +  bool operator == (const stmt_vec_info ) { return x.m_ptr == m_ptr; }
> +  bool operator == (_stmt_vec_info *x) { return x == m_ptr; }
> +  bool operator != (const stmt_vec_info ) { return x.m_ptr != m_ptr; }
> +  bool operator != (_stmt_vec_info *x) { return x != m_ptr; }
> +
> +private:
> +  struct _stmt_vec_info *m_ptr;
> +};
> +
> +#define NULL_STMT_VEC_INFO (stmt_vec_info (NULL))
> +
>  #include "tree-data-ref.h"
>  #include "tree-hash-traits.h"
>  #include "target.h"
>
> -typedef struct _stmt_vec_info *stmt_vec_info;
> -
>  /* Used for naming of new temporaries.  */
>  enum vect_var_kind {
>vect_simple_var,
> @@ -229,7 +248,7 @@ struct vec_info {
>vec_info_shared *shared;
>
>/* The mapping of GIMPLE UID to stmt_vec_info.  */
> -  vec stmt_vec_infos;
> +  vec stmt_vec_infos;
>
>/* All SLP instances.  */
>auto_vec slp_instances;
> @@ -1052,6 +1071,17 @@ #define VECT_SCALAR_BOOLEAN_TYPE_P(TYPE)
> && TYPE_PRECISION (TYPE) == 1   \
> && TYPE_UNSIGNED (TYPE)))
>
> +inline _stmt_vec_info &
> +stmt_vec_info::operator* () const
> +{
> +  return *m_ptr;
> +}
> +
> +inline stmt_vec_info::operator gimple * () const
> +{
> +  return m_ptr ? m_ptr->stmt : NULL;
> +}
> +
>  extern vec *stmt_vec_info_vec;
>
>  void set_stmt_vec_info_vec (vec *);
> @@ -1084,7 +1114,7 @@ set_vinfo_for_stmt (gimple *stmt, stmt_v
>  }
>else
>  {
> -  gcc_checking_assert (info == NULL);
> +  gcc_checking_assert (info == NULL_STMT_VEC_INFO);
>(*stmt_vec_info_vec)[uid - 1] = info;
>  }
>  }
> @@ -1261,7 +1291,9 @@ add_stmt_costs (void *data, stmt_vector_
>unsigned i;
>FOR_EACH_VEC_ELT (*cost_vec, i, cost)
>  add_stmt_cost (data, cost->count, cost->kind,
> -  cost->stmt ? vinfo_for_stmt (cost->stmt) : NULL,
> +  (cost->stmt
> +   ? vinfo_for_stmt (cost->stmt)
> +   : NULL_STMT_VEC_INFO),
>cost->misalign, cost->where);
>  }
>
> Index: gcc/tree-vect-loop-manip.c
> ===
> --- gcc/tree-vect-loop-manip.c  2018-06-30 14:56:22.022893750 +0100
> +++ gcc/tree-vect-loop-manip.c  2018-07-24 10:22:33.821278677 +0100
> @@ -1344,7 +1344,7 @@ iv_phi_p (gphi *phi)
>  return false;
>
>stmt_vec_info stmt_info = vinfo_for_stmt (phi);
> -  gcc_assert (stmt_info != NULL);
> +  gcc_assert (stmt_info != NULL_STMT_VEC_INFO);
>if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def
>|| STMT_VINFO_DEF_TYPE (stmt_info) == vect_double_reduction_def)
>  return false;
> Index: gcc/tree-vect-loop.c
> 

[10/46] Temporarily make stmt_vec_info a class

2018-07-24 Thread Richard Sandiford
This patch turns stmt_vec_info into an unspeakably bad wrapper class
and adds an implicit conversion to the associated gimple stmt.
Having this conversion makes the rest of the series easier to write,
but since the class goes away again at the end of the series, I've
not bothered adding any comments or tried to make it pretty.


2018-07-24  Richard Sandiford  

gcc/
* tree-vectorizer.h (stmt_vec_info): Temporarily change from
a typedef to a wrapper class.
(NULL_STMT_VEC_INFO): New macro.
(vec_info::stmt_infos): Change to vec.
(stmt_vec_info::operator*): New function.
(stmt_vec_info::operator gimple *): Likewise.
(set_vinfo_for_stmt): Use NULL_STMT_VEC_INFO.
(add_stmt_costs): Likewise.
* tree-vect-loop-manip.c (iv_phi_p): Likewise.
* tree-vect-loop.c (vect_compute_single_scalar_iteration_cost)
(vect_get_known_peeling_cost): Likewise.
(vect_estimate_min_profitable_iters): Likewise.
* tree-vect-patterns.c (vect_init_pattern_stmt): Likewise.
* tree-vect-slp.c (vect_remove_slp_scalar_calls): Likewise.
* tree-vect-stmts.c (vect_build_gather_load_calls): Likewise.
(vectorizable_store, free_stmt_vec_infos): Likewise.
(new_stmt_vec_info): Change return type of xcalloc to
_stmt_vec_info *.

Index: gcc/tree-vectorizer.h
===
--- gcc/tree-vectorizer.h   2018-07-24 10:22:30.401309046 +0100
+++ gcc/tree-vectorizer.h   2018-07-24 10:22:33.829278607 +0100
@@ -21,12 +21,31 @@ Software Foundation; either version 3, o
 #ifndef GCC_TREE_VECTORIZER_H
 #define GCC_TREE_VECTORIZER_H
 
+class stmt_vec_info {
+public:
+  stmt_vec_info () {}
+  stmt_vec_info (struct _stmt_vec_info *ptr) : m_ptr (ptr) {}
+  struct _stmt_vec_info *operator-> () const { return m_ptr; }
+  struct _stmt_vec_info * () const;
+  operator struct _stmt_vec_info * () const { return m_ptr; }
+  operator gimple * () const;
+  operator void * () const { return m_ptr; }
+  operator bool () const { return m_ptr; }
+  bool operator == (const stmt_vec_info ) { return x.m_ptr == m_ptr; }
+  bool operator == (_stmt_vec_info *x) { return x == m_ptr; }
+  bool operator != (const stmt_vec_info ) { return x.m_ptr != m_ptr; }
+  bool operator != (_stmt_vec_info *x) { return x != m_ptr; }
+
+private:
+  struct _stmt_vec_info *m_ptr;
+};
+
+#define NULL_STMT_VEC_INFO (stmt_vec_info (NULL))
+
 #include "tree-data-ref.h"
 #include "tree-hash-traits.h"
 #include "target.h"
 
-typedef struct _stmt_vec_info *stmt_vec_info;
-
 /* Used for naming of new temporaries.  */
 enum vect_var_kind {
   vect_simple_var,
@@ -229,7 +248,7 @@ struct vec_info {
   vec_info_shared *shared;
 
   /* The mapping of GIMPLE UID to stmt_vec_info.  */
-  vec stmt_vec_infos;
+  vec stmt_vec_infos;
 
   /* All SLP instances.  */
   auto_vec slp_instances;
@@ -1052,6 +1071,17 @@ #define VECT_SCALAR_BOOLEAN_TYPE_P(TYPE)
&& TYPE_PRECISION (TYPE) == 1   \
&& TYPE_UNSIGNED (TYPE)))
 
+inline _stmt_vec_info &
+stmt_vec_info::operator* () const
+{
+  return *m_ptr;
+}
+
+inline stmt_vec_info::operator gimple * () const
+{
+  return m_ptr ? m_ptr->stmt : NULL;
+}
+
 extern vec *stmt_vec_info_vec;
 
 void set_stmt_vec_info_vec (vec *);
@@ -1084,7 +1114,7 @@ set_vinfo_for_stmt (gimple *stmt, stmt_v
 }
   else
 {
-  gcc_checking_assert (info == NULL);
+  gcc_checking_assert (info == NULL_STMT_VEC_INFO);
   (*stmt_vec_info_vec)[uid - 1] = info;
 }
 }
@@ -1261,7 +1291,9 @@ add_stmt_costs (void *data, stmt_vector_
   unsigned i;
   FOR_EACH_VEC_ELT (*cost_vec, i, cost)
 add_stmt_cost (data, cost->count, cost->kind,
-  cost->stmt ? vinfo_for_stmt (cost->stmt) : NULL,
+  (cost->stmt
+   ? vinfo_for_stmt (cost->stmt)
+   : NULL_STMT_VEC_INFO),
   cost->misalign, cost->where);
 }
 
Index: gcc/tree-vect-loop-manip.c
===
--- gcc/tree-vect-loop-manip.c  2018-06-30 14:56:22.022893750 +0100
+++ gcc/tree-vect-loop-manip.c  2018-07-24 10:22:33.821278677 +0100
@@ -1344,7 +1344,7 @@ iv_phi_p (gphi *phi)
 return false;
 
   stmt_vec_info stmt_info = vinfo_for_stmt (phi);
-  gcc_assert (stmt_info != NULL);
+  gcc_assert (stmt_info != NULL_STMT_VEC_INFO);
   if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def
   || STMT_VINFO_DEF_TYPE (stmt_info) == vect_double_reduction_def)
 return false;
Index: gcc/tree-vect-loop.c
===
--- gcc/tree-vect-loop.c2018-07-24 10:22:30.401309046 +0100
+++ gcc/tree-vect-loop.c2018-07-24 10:22:33.821278677 +0100
@@ -1139,7 +1139,7 @@ vect_compute_single_scalar_iteration_cos
j, si)
 {
   struct _stmt_vec_info *stmt_info
-   = si->stmt ? vinfo_for_stmt (si->stmt) : NULL;
+