]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use a class hierarchy for vect specific data
authorRichard Biener <rguenther@suse.de>
Wed, 30 Jul 2025 09:19:03 +0000 (11:19 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 1 Aug 2025 07:28:05 +0000 (09:28 +0200)
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.

gcc/tree-vect-slp.cc
gcc/tree-vectorizer.h

index a9c7105f47e67d2db3d48cf9c1b562c5fa75bed3..233543214faee61973d27ed57ea450d18f3b3e6e 100644 (file)
@@ -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.  */
index 095db66b94777f88699766878f564815ed865b86..6081ca4d63c4f4b82983c6d52e118f1bacfd4e22 100644 (file)
@@ -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