public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer helper functions.
@ 2020-09-25 14:27 Tamar Christina
  2020-11-03 15:06 ` Tamar Christina
  0 siblings, 1 reply; 3+ messages in thread
From: Tamar Christina @ 2020-09-25 14:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, rguenther, ook

[-- Attachment #1: Type: text/plain, Size: 629 bytes --]

Hi All,

This is a small refactoring which exposes some helper functions in the
vectorizer so they can be used in other places.

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	* tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static.
	* tree-vect-slp.c (vect_free_slp_tree,
	vect_build_slp_tree): Remove static.
	(struct bst_traits, bst_traits::hash, bst_traits::equal): Move...
	* tree-vectorizer.h (struct bst_traits, bst_traits::hash,
	bst_traits::equal): ... to here.
	(vect_mark_pattern_stmts, vect_free_slp_tree,
	vect_build_slp_tree): Declare.

-- 

[-- Attachment #2: rb13506.patch --]
[-- Type: text/x-diff, Size: 5462 bytes --]

diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index db45740da3cba14a3552f9446651e8f289187fbb..3bacd5c827e1a6436c5916022c04e0d6594c316a 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5169,7 +5169,7 @@ const unsigned int NUM_PATTERNS = ARRAY_SIZE (vect_vect_recog_func_ptrs);
 
 /* Mark statements that are involved in a pattern.  */
 
-static inline void
+void
 vect_mark_pattern_stmts (vec_info *vinfo,
 			 stmt_vec_info orig_stmt_info, gimple *pattern_stmt,
                          tree pattern_vectype)
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index bf8ea4326597f4211d2772e9db60aa69285b5998..01189d44d892fc42b132bbb7de1c471df45518ae 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -86,7 +86,7 @@ _slp_tree::~_slp_tree ()
 
 /* Recursively free the memory allocated for the SLP tree rooted at NODE.  */
 
-static void
+void
 vect_free_slp_tree (slp_tree node)
 {
   int i;
@@ -1120,45 +1120,6 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
   return true;
 }
 
-/* Traits for the hash_set to record failed SLP builds for a stmt set.
-   Note we never remove apart from at destruction time so we do not
-   need a special value for deleted that differs from empty.  */
-struct bst_traits
-{
-  typedef vec <stmt_vec_info> value_type;
-  typedef vec <stmt_vec_info> compare_type;
-  static inline hashval_t hash (value_type);
-  static inline bool equal (value_type existing, value_type candidate);
-  static inline bool is_empty (value_type x) { return !x.exists (); }
-  static inline bool is_deleted (value_type x) { return !x.exists (); }
-  static const bool empty_zero_p = true;
-  static inline void mark_empty (value_type &x) { x.release (); }
-  static inline void mark_deleted (value_type &x) { x.release (); }
-  static inline void remove (value_type &x) { x.release (); }
-};
-inline hashval_t
-bst_traits::hash (value_type x)
-{
-  inchash::hash h;
-  for (unsigned i = 0; i < x.length (); ++i)
-    h.add_int (gimple_uid (x[i]->stmt));
-  return h.end ();
-}
-inline bool
-bst_traits::equal (value_type existing, value_type candidate)
-{
-  if (existing.length () != candidate.length ())
-    return false;
-  for (unsigned i = 0; i < existing.length (); ++i)
-    if (existing[i] != candidate[i])
-      return false;
-  return true;
-}
-
-typedef hash_map <vec <gimple *>, slp_tree,
-		  simple_hashmap_traits <bst_traits, slp_tree> >
-  scalar_stmts_to_slp_tree_map_t;
-
 static slp_tree
 vect_build_slp_tree_2 (vec_info *vinfo,
 		       vec<stmt_vec_info> stmts, unsigned int group_size,
@@ -1166,7 +1127,7 @@ vect_build_slp_tree_2 (vec_info *vinfo,
 		       bool *matches, unsigned *npermutes, unsigned *tree_size,
 		       scalar_stmts_to_slp_tree_map_t *bst_map);
 
-static slp_tree
+slp_tree
 vect_build_slp_tree (vec_info *vinfo,
 		     vec<stmt_vec_info> stmts, unsigned int group_size,
 		     poly_uint64 *max_nunits,
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 2ebcf9f9926ec7175f28391f172800499bbc59db..79926f1a43534635ddca85556a928e364022c40a 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -2047,6 +2047,9 @@ extern int vect_get_place_in_interleaving_chain (stmt_vec_info, stmt_vec_info);
 extern bool vect_update_shared_vectype (stmt_vec_info, tree);
 
 /* In tree-vect-patterns.c.  */
+extern void
+vect_mark_pattern_stmts (vec_info *, stmt_vec_info, gimple *, tree);
+
 /* Pattern recognition functions.
    Additional pattern recognition functions can (and will) be added
    in the future.  */
@@ -2058,4 +2061,51 @@ void vect_free_loop_info_assumptions (class loop *);
 gimple *vect_loop_vectorized_call (class loop *, gcond **cond = NULL);
 bool vect_stmt_dominates_stmt_p (gimple *, gimple *);
 
+/* Traits for the hash_set to record failed SLP builds for a stmt set.
+   Note we never remove apart from at destruction time so we do not
+   need a special value for deleted that differs from empty.  */
+struct bst_traits
+{
+  typedef vec <stmt_vec_info> value_type;
+  typedef vec <stmt_vec_info> compare_type;
+  static inline hashval_t hash (value_type);
+  static inline bool equal (value_type existing, value_type candidate);
+  static inline bool is_empty (value_type x) { return !x.exists (); }
+  static inline bool is_deleted (value_type x) { return !x.exists (); }
+  static const bool empty_zero_p = true;
+  static inline void mark_empty (value_type &x) { x.release (); }
+  static inline void mark_deleted (value_type &x) { x.release (); }
+  static inline void remove (value_type &x) { x.release (); }
+};
+inline hashval_t
+bst_traits::hash (value_type x)
+{
+  inchash::hash h;
+  for (unsigned i = 0; i < x.length (); ++i)
+    h.add_int (gimple_uid (x[i]->stmt));
+  return h.end ();
+}
+inline bool
+bst_traits::equal (value_type existing, value_type candidate)
+{
+  if (existing.length () != candidate.length ())
+    return false;
+  for (unsigned i = 0; i < existing.length (); ++i)
+    if (existing[i] != candidate[i])
+      return false;
+  return true;
+}
+
+typedef hash_map <vec <gimple *>, slp_tree,
+		  simple_hashmap_traits <bst_traits, slp_tree> >
+  scalar_stmts_to_slp_tree_map_t;
+
+extern void
+vect_free_slp_tree (slp_tree node);
+
+slp_tree
+vect_build_slp_tree (vec_info *, vec<stmt_vec_info>, unsigned int,
+		     poly_uint64 *, bool *, unsigned *, unsigned *,
+		     scalar_stmts_to_slp_tree_map_t *);
+
 #endif  /* GCC_TREE_VECTORIZER_H  */


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer helper functions.
  2020-09-25 14:27 [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer helper functions Tamar Christina
@ 2020-11-03 15:06 ` Tamar Christina
  2020-11-04 11:09   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Tamar Christina @ 2020-11-03 15:06 UTC (permalink / raw)
  To: Tamar Christina, gcc-patches; +Cc: nd, rguenther, ook

[-- Attachment #1: Type: text/plain, Size: 1662 bytes --]

Hi All,

This patch is a respin of the previous one defining a new helper
function add_pattern_stmt.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	* tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static inline.
	* tree-vect-slp.c (vect_create_new_slp_node): Remove static and only
	set smts if valid.
	* tree-vectorizer.c (vec_info::add_pattern_stmt): New.
	(vec_info::set_vinfo_for_stmt): Optionally enforce read-only.
	* tree-vectorizer.h (struct _slp_tree): Use new types.
	(lane_permutation_t, lane_permutation_t): New.
	(vect_create_new_slp_node, vect_mark_pattern_stmts): New.

> -----Original Message-----
> From: Gcc-patches <gcc-patches-bounces@gcc.gnu.org> On Behalf Of Tamar
> Christina
> Sent: Friday, September 25, 2020 3:28 PM
> To: gcc-patches@gcc.gnu.org
> Cc: nd <nd@arm.com>; rguenther@suse.de; ook@ucw.cz
> Subject: [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer
> helper functions.
> 
> Hi All,
> 
> This is a small refactoring which exposes some helper functions in the
> vectorizer so they can be used in other places.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> 
> Ok for master?
> 
> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	* tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static.
> 	* tree-vect-slp.c (vect_free_slp_tree,
> 	vect_build_slp_tree): Remove static.
> 	(struct bst_traits, bst_traits::hash, bst_traits::equal): Move...
> 	* tree-vectorizer.h (struct bst_traits, bst_traits::hash,
> 	bst_traits::equal): ... to here.
> 	(vect_mark_pattern_stmts, vect_free_slp_tree,
> 	vect_build_slp_tree): Declare.
> 
> --

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr13506.patch --]
[-- Type: text/x-diff; name="pr13506.patch", Size: 5241 bytes --]

diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index ac56acebe016058cbbc9599cef348ec4211c19d6..32b272ac443cac6bbaf2695c81078a9c8c2a656d 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5216,7 +5216,7 @@ const unsigned int NUM_PATTERNS = ARRAY_SIZE (vect_vect_recog_func_ptrs);
 
 /* Mark statements that are involved in a pattern.  */
 
-static inline void
+void
 vect_mark_pattern_stmts (vec_info *vinfo,
 			 stmt_vec_info orig_stmt_info, gimple *pattern_stmt,
                          tree pattern_vectype)
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index e97fbe897a76008d50ee94c3b1b009344cc37d4a..30036ec84c74a0e428cc661eacf565224047f9e0 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -148,15 +148,18 @@ vect_free_slp_instance (slp_instance instance)
 
 /* Create an SLP node for SCALAR_STMTS.  */
 
-static slp_tree
+slp_tree
 vect_create_new_slp_node (slp_tree node,
 			  vec<stmt_vec_info> scalar_stmts, unsigned nops)
 {
   SLP_TREE_SCALAR_STMTS (node) = scalar_stmts;
   SLP_TREE_CHILDREN (node).create (nops);
   SLP_TREE_DEF_TYPE (node) = vect_internal_def;
-  SLP_TREE_REPRESENTATIVE (node) = scalar_stmts[0];
-  SLP_TREE_LANES (node) = scalar_stmts.length ();
+  if (scalar_stmts.exists ())
+    {
+      SLP_TREE_REPRESENTATIVE (node) = scalar_stmts[0];
+      SLP_TREE_LANES (node) = scalar_stmts.length ();
+    }
   return node;
 }
 
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index fbf5291cf065f3944040937db92d3997acd45f23..4bd454cfb185d7036843fc7140b073f525b2ec6a 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -115,6 +115,8 @@ typedef hash_map<tree_operand_hash,
   SLP
  ************************************************************************/
 typedef struct _slp_tree *slp_tree;
+typedef vec<std::pair<unsigned, unsigned> > lane_permutation_t;
+typedef vec<unsigned> load_permutation_t;
 
 extern object_allocator<_slp_tree> *slp_tree_pool;
 
@@ -137,11 +139,11 @@ struct _slp_tree {
 
   /* Load permutation relative to the stores, NULL if there is no
      permutation.  */
-  vec<unsigned> load_permutation;
+  load_permutation_t load_permutation;
   /* Lane permutation of the operands scalar lanes encoded as pairs
      of { operand number, lane number }.  The number of elements
      denotes the number of output lanes.  */
-  vec<std::pair<unsigned, unsigned> > lane_permutation;
+  lane_permutation_t lane_permutation;
 
   tree vectype;
   /* Vectorized stmt/s.  */
@@ -348,6 +350,7 @@ public:
   ~vec_info ();
 
   stmt_vec_info add_stmt (gimple *);
+  stmt_vec_info add_pattern_stmt (gimple *, stmt_vec_info);
   stmt_vec_info lookup_stmt (gimple *);
   stmt_vec_info lookup_def (tree);
   stmt_vec_info lookup_single_use (tree);
@@ -393,7 +396,7 @@ public:
 
 private:
   stmt_vec_info new_stmt_vec_info (gimple *stmt);
-  void set_vinfo_for_stmt (gimple *, stmt_vec_info);
+  void set_vinfo_for_stmt (gimple *, stmt_vec_info, bool = true);
   void free_stmt_vec_infos ();
   void free_stmt_vec_info (stmt_vec_info);
 };
@@ -1975,8 +1978,12 @@ extern void duplicate_and_interleave (vec_info *, gimple_seq *, tree,
 				      vec<tree>, unsigned int, vec<tree> &);
 extern int vect_get_place_in_interleaving_chain (stmt_vec_info, stmt_vec_info);
 extern bool vect_update_shared_vectype (stmt_vec_info, tree);
+extern slp_tree vect_create_new_slp_node (vec<stmt_vec_info>, unsigned);
 
 /* In tree-vect-patterns.c.  */
+extern void
+vect_mark_pattern_stmts (vec_info *, stmt_vec_info, gimple *, tree);
+
 /* Pattern recognition functions.
    Additional pattern recognition functions can (and will) be added
    in the future.  */
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index b63dda31a0839b094985d306a993503cc00dd7eb..d81774b242569262a51b7be02815acd6d1a6bfd0 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -525,6 +525,19 @@ vec_info::add_stmt (gimple *stmt)
   return res;
 }
 
+/* Record that STMT belongs to the vectorizable region.  Create a new
+   stmt_vec_info and mark VECINFO as being related and return the new
+   stmt_vec_info.  */
+
+stmt_vec_info
+vec_info::add_pattern_stmt (gimple *stmt, stmt_vec_info stmt_info)
+{
+  stmt_vec_info res = new_stmt_vec_info (stmt);
+  set_vinfo_for_stmt (stmt, res, false);
+  STMT_VINFO_RELATED_STMT (res) = stmt_info;
+  return res;
+}
+
 /* If STMT has an associated stmt_vec_info, return that vec_info, otherwise
    return null.  It is safe to call this function on any statement, even if
    it might not be part of the vectorizable region.  */
@@ -702,12 +715,12 @@ vec_info::new_stmt_vec_info (gimple *stmt)
 /* Associate STMT with INFO.  */
 
 void
-vec_info::set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info)
+vec_info::set_vinfo_for_stmt (gimple *stmt, stmt_vec_info info, bool check_ro)
 {
   unsigned int uid = gimple_uid (stmt);
   if (uid == 0)
     {
-      gcc_assert (!stmt_vec_info_ro);
+      gcc_assert (!check_ro || !stmt_vec_info_ro);
       gcc_checking_assert (info);
       uid = stmt_vec_infos.length () + 1;
       gimple_set_uid (stmt, uid);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer helper functions.
  2020-11-03 15:06 ` Tamar Christina
@ 2020-11-04 11:09   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2020-11-04 11:09 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd, ook

On Tue, 3 Nov 2020, Tamar Christina wrote:

> Hi All,
> 
> This patch is a respin of the previous one defining a new helper
> function add_pattern_stmt.
> 
> Ok for master?

OK if the rest is approved.

> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	* tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static inline.
> 	* tree-vect-slp.c (vect_create_new_slp_node): Remove static and only
> 	set smts if valid.
> 	* tree-vectorizer.c (vec_info::add_pattern_stmt): New.
> 	(vec_info::set_vinfo_for_stmt): Optionally enforce read-only.
> 	* tree-vectorizer.h (struct _slp_tree): Use new types.
> 	(lane_permutation_t, lane_permutation_t): New.
> 	(vect_create_new_slp_node, vect_mark_pattern_stmts): New.
> 
> > -----Original Message-----
> > From: Gcc-patches <gcc-patches-bounces@gcc.gnu.org> On Behalf Of Tamar
> > Christina
> > Sent: Friday, September 25, 2020 3:28 PM
> > To: gcc-patches@gcc.gnu.org
> > Cc: nd <nd@arm.com>; rguenther@suse.de; ook@ucw.cz
> > Subject: [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer
> > helper functions.
> > 
> > Hi All,
> > 
> > This is a small refactoring which exposes some helper functions in the
> > vectorizer so they can be used in other places.
> > 
> > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> > 
> > Ok for master?
> > 
> > Thanks,
> > Tamar
> > 
> > gcc/ChangeLog:
> > 
> > 	* tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static.
> > 	* tree-vect-slp.c (vect_free_slp_tree,
> > 	vect_build_slp_tree): Remove static.
> > 	(struct bst_traits, bst_traits::hash, bst_traits::equal): Move...
> > 	* tree-vectorizer.h (struct bst_traits, bst_traits::hash,
> > 	bst_traits::equal): ... to here.
> > 	(vect_mark_pattern_stmts, vect_free_slp_tree,
> > 	vect_build_slp_tree): Declare.
> > 
> > --
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imend

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-04 11:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 14:27 [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer helper functions Tamar Christina
2020-11-03 15:06 ` Tamar Christina
2020-11-04 11:09   ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).