[10/46] Temporarily make stmt_vec_info a class
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 31 Jul 2018 14:21:56 +0000 (14:21 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Tue, 31 Jul 2018 14:21:56 +0000 (14:21 +0000)
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-31  Richard Sandiford  <richard.sandiford@arm.com>

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>.
(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 *.

From-SVN: r263125

gcc/ChangeLog
gcc/tree-vect-loop-manip.c
gcc/tree-vect-loop.c
gcc/tree-vect-patterns.c
gcc/tree-vect-slp.c
gcc/tree-vect-stmts.c
gcc/tree-vectorizer.h

index a00fad889f5e57e14c946952a6fe7f9b37adcf3d..a5695829357b4ce77e60cc9b0c544354f9dd6e15 100644 (file)
@@ -1,3 +1,24 @@
+2018-07-31  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * 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>.
+       (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 *.
+
 2018-07-31  Richard Sandiford  <richard.sandiford@arm.com>
 
        * tree-vectorizer.h (vec_info::lookup_single_use): Declare.
index 01d1850276bb9d75de58452754ff03b2167e9390..dd1cf085f4f9dd601a7eb621cde71313b7faf7d6 100644 (file)
@@ -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 4fe3e1dc5fce054746fd99ef590258abb09f5460..e451cbcff8dca5974a6c6abaee8f39151663c02d 100644 (file)
@@ -1139,7 +1139,7 @@ vect_compute_single_scalar_iteration_cost (loop_vec_info loop_vinfo)
                    j, si)
     {
       struct _stmt_vec_info *stmt_info
-       = si->stmt ? vinfo_for_stmt (si->stmt) : NULL;
+       = si->stmt ? vinfo_for_stmt (si->stmt) : NULL_STMT_VEC_INFO;
       (void) add_stmt_cost (target_cost_data, si->count,
                            si->kind, stmt_info, si->misalign,
                            vect_body);
@@ -3351,7 +3351,7 @@ vect_get_known_peeling_cost (loop_vec_info loop_vinfo, int peel_iters_prologue,
     FOR_EACH_VEC_ELT (*scalar_cost_vec, j, si)
        {
          stmt_vec_info stmt_info
-           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL;
+           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL_STMT_VEC_INFO;
          retval += record_stmt_cost (prologue_cost_vec,
                                      si->count * peel_iters_prologue,
                                      si->kind, stmt_info, si->misalign,
@@ -3361,7 +3361,7 @@ vect_get_known_peeling_cost (loop_vec_info loop_vinfo, int peel_iters_prologue,
     FOR_EACH_VEC_ELT (*scalar_cost_vec, j, si)
        {
          stmt_vec_info stmt_info
-           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL;
+           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL_STMT_VEC_INFO;
          retval += record_stmt_cost (epilogue_cost_vec,
                                      si->count * *peel_iters_epilogue,
                                      si->kind, stmt_info, si->misalign,
@@ -3504,7 +3504,7 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
                            j, si)
            {
              struct _stmt_vec_info *stmt_info
-               = si->stmt ? vinfo_for_stmt (si->stmt) : NULL;
+               = si->stmt ? vinfo_for_stmt (si->stmt) : NULL_STMT_VEC_INFO;
              (void) add_stmt_cost (target_cost_data, si->count,
                                    si->kind, stmt_info, si->misalign,
                                    vect_epilogue);
@@ -3541,7 +3541,7 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
       FOR_EACH_VEC_ELT (LOOP_VINFO_SCALAR_ITERATION_COST (loop_vinfo), j, si)
        {
          struct _stmt_vec_info *stmt_info
-           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL;
+           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL_STMT_VEC_INFO;
          (void) add_stmt_cost (target_cost_data,
                                si->count * peel_iters_prologue,
                                si->kind, stmt_info, si->misalign,
@@ -3573,7 +3573,7 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
       FOR_EACH_VEC_ELT (prologue_cost_vec, j, si)
        {
          struct _stmt_vec_info *stmt_info
-           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL;
+           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL_STMT_VEC_INFO;
          (void) add_stmt_cost (data, si->count, si->kind, stmt_info,
                                si->misalign, vect_prologue);
        }
@@ -3581,7 +3581,7 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
       FOR_EACH_VEC_ELT (epilogue_cost_vec, j, si)
        {
          struct _stmt_vec_info *stmt_info
-           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL;
+           = si->stmt ? vinfo_for_stmt (si->stmt) : NULL_STMT_VEC_INFO;
          (void) add_stmt_cost (data, si->count, si->kind, stmt_info,
                                si->misalign, vect_epilogue);
        }
index 4f9f0924f5119e533d7a9eb6ff5303189e4acbfa..f4174e46bbcc6e8728d22989edb05465eac4388a 100644 (file)
@@ -103,7 +103,7 @@ vect_init_pattern_stmt (gimple *pattern_stmt, stmt_vec_info orig_stmt_info,
 {
   vec_info *vinfo = orig_stmt_info->vinfo;
   stmt_vec_info pattern_stmt_info = vinfo->lookup_stmt (pattern_stmt);
-  if (pattern_stmt_info == NULL)
+  if (pattern_stmt_info == NULL_STMT_VEC_INFO)
     pattern_stmt_info = orig_stmt_info->vinfo->add_stmt (pattern_stmt);
   gimple_set_bb (pattern_stmt, gimple_bb (orig_stmt_info->stmt));
 
index 78aaa71ccb65aa3ca2f1dd17fcf4a7822c110516..883de92b26cd73abd08ddf63998aa01bd5b06399 100644 (file)
@@ -4039,7 +4039,7 @@ vect_remove_slp_scalar_calls (slp_tree node)
       if (!is_gimple_call (stmt) || gimple_bb (stmt) == NULL)
        continue;
       stmt_info = vinfo_for_stmt (stmt);
-      if (stmt_info == NULL
+      if (stmt_info == NULL_STMT_VEC_INFO
          || is_pattern_stmt_p (stmt_info)
          || !PURE_SLP_STMT (stmt_info))
        continue;
index f21599ea3aab30fa6f0ab506919ef3f5451d145d..629e2055498eca378f2d50123fd272e4c3e7ce64 100644 (file)
@@ -2865,7 +2865,7 @@ vect_build_gather_load_calls (gimple *stmt, gimple_stmt_iterator *gsi,
          new_stmt = SSA_NAME_DEF_STMT (var);
        }
 
-      if (prev_stmt_info == NULL)
+      if (prev_stmt_info == NULL_STMT_VEC_INFO)
        STMT_VINFO_VEC_STMT (stmt_info) = *vec_stmt = new_stmt;
       else
        STMT_VINFO_RELATED_STMT (prev_stmt_info) = new_stmt;
@@ -6550,7 +6550,7 @@ vectorizable_store (gimple *stmt, gimple_stmt_iterator *gsi, gimple **vec_stmt,
 
          vect_finish_stmt_generation (stmt, new_stmt, gsi);
 
-         if (prev_stmt_info == NULL)
+         if (prev_stmt_info == NULL_STMT_VEC_INFO)
            STMT_VINFO_VEC_STMT (stmt_info) = *vec_stmt = new_stmt;
          else
            STMT_VINFO_RELATED_STMT (prev_stmt_info) = new_stmt;
@@ -9805,7 +9805,7 @@ stmt_vec_info
 new_stmt_vec_info (gimple *stmt, vec_info *vinfo)
 {
   stmt_vec_info res;
-  res = (stmt_vec_info) xcalloc (1, sizeof (struct _stmt_vec_info));
+  res = (_stmt_vec_info *) xcalloc (1, sizeof (struct _stmt_vec_info));
 
   STMT_VINFO_TYPE (res) = undef_vec_info_type;
   STMT_VINFO_STMT (res) = stmt;
@@ -9862,7 +9862,7 @@ free_stmt_vec_infos (vec<stmt_vec_info> *v)
   unsigned int i;
   stmt_vec_info info;
   FOR_EACH_VEC_ELT (*v, i, info)
-    if (info != NULL)
+    if (info != NULL_STMT_VEC_INFO)
       free_stmt_vec_info (STMT_VINFO_STMT (info));
   if (v == stmt_vec_info_vec)
     stmt_vec_info_vec = NULL;
index cbec2fbdc1dacbb7d0f7186952357a0279b32cbd..31d2db4d8c52275c57a487eb0cfd8562751ae07a 100644 (file)
@@ -21,12 +21,31 @@ along with GCC; see the file COPYING3.  If not see
 #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 &operator* () 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 &x) { return x.m_ptr == m_ptr; }
+  bool operator == (_stmt_vec_info *x) { return x == m_ptr; }
+  bool operator != (const stmt_vec_info &x) { 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<struct _stmt_vec_info *> stmt_vec_infos;
+  vec<stmt_vec_info> stmt_vec_infos;
 
   /* All SLP instances.  */
   auto_vec<slp_instance> slp_instances;
@@ -1052,6 +1071,17 @@ STMT_VINFO_BB_VINFO (stmt_vec_info stmt_vinfo)
        && 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> *stmt_vec_info_vec;
 
 void set_stmt_vec_info_vec (vec<stmt_vec_info> *);
@@ -1084,7 +1114,7 @@ set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info)
     }
   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_for_cost *cost_vec)
   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);
 }