https://gcc.gnu.org/g:7a08afbc784ad41263e3cc3d039be631254183bc

commit r16-2702-g7a08afbc784ad41263e3cc3d039be631254183bc
Author: Richard Biener <rguent...@suse.de>
Date:   Wed Jul 30 11:19:03 2025 +0200

    Use a class hierarchy for vect specific data
    
    The following turns the union into a class hierarchy.  One completed
    SLP_TREE_TYPE could move into the base class.
    
            * tree-vect-slp.cc (_slp_tree::_slp_tree): Adjust.
            (_slp_tree::~_slp_tree): Likewise.
            * tree-vectorizer.h (vect_data): New base class.
            (_slp_tree::u): Remove.
            (_slp_tree::data): Add pointer to vect_data.
            (_slp_tree::get_data): New helper template.

Diff:
---
 gcc/tree-vect-slp.cc  |  4 +++-
 gcc/tree-vectorizer.h | 15 ++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index a9c7105f47e6..233543214fae 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -131,7 +131,7 @@ _slp_tree::_slp_tree ()
   this->max_nunits = 1;
   this->lanes = 0;
   SLP_TREE_TYPE (this) = undef_vec_info_type;
-  this->u.undef = NULL;
+  this->data = NULL;
 }
 
 /* Tear down a SLP node.  */
@@ -153,6 +153,8 @@ _slp_tree::~_slp_tree ()
   SLP_TREE_SIMD_CLONE_INFO (this).release ();
   if (this->failed)
     free (failed);
+  if (this->data)
+    delete this->data;
 }
 
 /* Push the single SSA definition in DEF to the vector of vector defs.  */
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 095db66b9477..6081ca4d63c4 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -239,6 +239,10 @@ typedef auto_vec<std::pair<unsigned, unsigned>, 16> 
auto_lane_permutation_t;
 typedef vec<unsigned> load_permutation_t;
 typedef auto_vec<unsigned, 16> auto_load_permutation_t;
 
+struct vect_data {
+  virtual ~vect_data () = default;
+};
+
 /* A computation tree of an SLP instance.  Each node corresponds to a group of
    stmts to be packed in a SIMD stmt.  */
 struct _slp_tree {
@@ -305,12 +309,13 @@ struct _slp_tree {
      for loop vectorization.  */
   vect_memory_access_type memory_access_type;
 
-  /* The kind of operation as determined by analysis and a tagged
-     union with kind specific data.  */
+  /* The kind of operation as determined by analysis and optional
+     kind specific data.  */
   enum stmt_vec_info_type type;
-  union {
-      void *undef;
-  } u;
+  vect_data *data;
+
+  template <class T>
+  T& get_data (T& else_) { return data ? *static_cast <T *> (data) : else_; }
 
   /* If not NULL this is a cached failed SLP discovery attempt with
      the lanes that failed during SLP discovery as 'false'.  This is

Reply via email to