public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] Allow md iterators to include other iterators
@ 2023-11-10 15:48 Richard Sandiford
  0 siblings, 0 replies; only message in thread
From: Richard Sandiford @ 2023-11-10 15:48 UTC (permalink / raw)
  To: gcc-patches

This patch allows an .md iterator to include the contents of
previous iterators, possibly with an extra condition attached.

Too much indirection might become hard to follow, so for the
AArch64 changes I tried to stick to things that seemed likely
to be uncontroversial:

(a) structure iterators that combine modes for different sizes
    and vector counts

(b) iterators that explicitly duplicate another iterator
    (for iterating over the cross product)

Tested on aarch64-linux-gnu & pushed.

Richard


gcc/
	* read-rtl.cc (md_reader::read_mapping): Allow iterators to
	include other iterators.
	* doc/md.texi: Document the change.
	* config/aarch64/iterators.md (DREG2, VQ2, TX2, DX2, SX2): Include
	the iterator that is being duplicated, rather than reproducing it.
	(VSTRUCT_D): Redefine using VSTRUCT_[234]D.
	(VSTRUCT_Q): Likewise VSTRUCT_[234]Q.
	(VSTRUCT_2QD, VSTRUCT_3QD, VSTRUCT_4QD, VSTRUCT_QD): Redefine using
	the individual D and Q iterators.
---
 gcc/config/aarch64/iterators.md | 60 +++++++++------------------------
 gcc/doc/md.texi                 | 13 +++++++
 gcc/read-rtl.cc                 | 21 ++++++++++--
 3 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md
index 1593a8fd04f..a920de99ffc 100644
--- a/gcc/config/aarch64/iterators.md
+++ b/gcc/config/aarch64/iterators.md
@@ -106,7 +106,7 @@ (define_mode_iterator VDZ [V8QI V4HI V4HF V4BF V2SI V2SF DI DF])
 (define_mode_iterator DREG [V8QI V4HI V4HF V2SI V2SF DF])
 
 ;; Copy of the above.
-(define_mode_iterator DREG2 [V8QI V4HI V4HF V2SI V2SF DF])
+(define_mode_iterator DREG2 [DREG])
 
 ;; Advanced SIMD modes for integer divides.
 (define_mode_iterator VQDIV [V4SI V2DI])
@@ -124,7 +124,7 @@ (define_mode_iterator VDQ_BHSI [V8QI V16QI V4HI V8HI V2SI V4SI])
 (define_mode_iterator VQ [V16QI V8HI V4SI V2DI V8HF V4SF V2DF V8BF])
 
 ;; Copy of the above.
-(define_mode_iterator VQ2 [V16QI V8HI V4SI V2DI V8HF V8BF V4SF V2DF])
+(define_mode_iterator VQ2 [VQ])
 
 ;; Quad vector modes suitable for moving.  Includes BFmode.
 (define_mode_iterator VQMOV [V16QI V8HI V4SI V2DI V8HF V8BF V4SF V2DF])
@@ -320,21 +320,13 @@ (define_mode_iterator VS [V2SI V4SI])
 (define_mode_iterator TX [TI TF TD])
 
 ;; Duplicate of the above
-(define_mode_iterator TX2 [TI TF TD])
+(define_mode_iterator TX2 [TX])
 
 (define_mode_iterator VTX [TI TF TD V16QI V8HI V4SI V2DI V8HF V4SF V2DF V8BF])
 
 ;; Advanced SIMD opaque structure modes.
 (define_mode_iterator VSTRUCT [OI CI XI])
 
-;; Advanced SIMD 64-bit vector structure modes.
-(define_mode_iterator VSTRUCT_D [V2x8QI V2x4HI V2x2SI V2x1DI
-				 V2x4HF V2x2SF V2x1DF V2x4BF
-				 V3x8QI V3x4HI V3x2SI V3x1DI
-				 V3x4HF V3x2SF V3x1DF V3x4BF
-				 V4x8QI V4x4HI V4x2SI V4x1DI
-				 V4x4HF V4x2SF V4x1DF V4x4BF])
-
 ;; Advanced SIMD 64-bit 2-vector structure modes.
 (define_mode_iterator VSTRUCT_2D [V2x8QI V2x4HI V2x2SI V2x1DI
 				  V2x4HF V2x2SF V2x1DF V2x4BF])
@@ -347,6 +339,9 @@ (define_mode_iterator VSTRUCT_3D [V3x8QI V3x4HI V3x2SI V3x1DI
 (define_mode_iterator VSTRUCT_4D [V4x8QI V4x4HI V4x2SI V4x1DI
 				  V4x4HF V4x2SF V4x1DF V4x4BF])
 
+;; Advanced SIMD 64-bit vector structure modes.
+(define_mode_iterator VSTRUCT_D [VSTRUCT_2D VSTRUCT_3D VSTRUCT_4D])
+
 ;; Advanced SIMD 64-bit 2-vector structure modes minus V2x1DI and V2x1DF.
 (define_mode_iterator VSTRUCT_2DNX [V2x8QI V2x4HI V2x2SI V2x4HF
 				    V2x2SF V2x4BF])
@@ -371,14 +366,6 @@ (define_mode_iterator VSTRUCT_3DX [V3x1DI V3x1DF])
 ;; Advanced SIMD 64-bit 4-vector structure modes with 64-bit elements.
 (define_mode_iterator VSTRUCT_4DX [V4x1DI V4x1DF])
 
-;; Advanced SIMD 128-bit vector structure modes.
-(define_mode_iterator VSTRUCT_Q [V2x16QI V2x8HI V2x4SI V2x2DI
-				 V2x8HF V2x4SF V2x2DF V2x8BF
-				 V3x16QI V3x8HI V3x4SI V3x2DI
-				 V3x8HF V3x4SF V3x2DF V3x8BF
-				 V4x16QI V4x8HI V4x4SI V4x2DI
-				 V4x8HF V4x4SF V4x2DF V4x8BF])
-
 ;; Advanced SIMD 128-bit 2-vector structure modes.
 (define_mode_iterator VSTRUCT_2Q [V2x16QI V2x8HI V2x4SI V2x2DI
 				  V2x8HF V2x4SF V2x2DF V2x8BF])
@@ -391,49 +378,32 @@ (define_mode_iterator VSTRUCT_3Q [V3x16QI V3x8HI V3x4SI V3x2DI
 (define_mode_iterator VSTRUCT_4Q [V4x16QI V4x8HI V4x4SI V4x2DI
 				  V4x8HF V4x4SF V4x2DF V4x8BF])
 
+;; Advanced SIMD 128-bit vector structure modes.
+(define_mode_iterator VSTRUCT_Q [VSTRUCT_2Q VSTRUCT_3Q VSTRUCT_4Q])
+
 ;; Advanced SIMD 2-vector structure modes.
-(define_mode_iterator VSTRUCT_2QD [V2x8QI V2x4HI V2x2SI V2x1DI
-				   V2x4HF V2x2SF V2x1DF V2x4BF
-				   V2x16QI V2x8HI V2x4SI V2x2DI
-				   V2x8HF V2x4SF V2x2DF V2x8BF])
+(define_mode_iterator VSTRUCT_2QD [VSTRUCT_2D VSTRUCT_2Q])
 
 ;; Advanced SIMD 3-vector structure modes.
-(define_mode_iterator VSTRUCT_3QD [V3x8QI V3x4HI V3x2SI V3x1DI
-				   V3x4HF V3x2SF V3x1DF V3x4BF
-				   V3x16QI V3x8HI V3x4SI V3x2DI
-				   V3x8HF V3x4SF V3x2DF V3x8BF])
+(define_mode_iterator VSTRUCT_3QD [VSTRUCT_3D VSTRUCT_3Q])
 
 ;; Advanced SIMD 4-vector structure modes.
-(define_mode_iterator VSTRUCT_4QD [V4x8QI V4x4HI V4x2SI V4x1DI
-				   V4x4HF V4x2SF V4x1DF V4x4BF
-				   V4x16QI V4x8HI V4x4SI V4x2DI
-				   V4x8HF V4x4SF V4x2DF V4x8BF])
+(define_mode_iterator VSTRUCT_4QD [VSTRUCT_4D VSTRUCT_4Q])
 
 ;; Advanced SIMD vector structure modes.
-(define_mode_iterator VSTRUCT_QD [V2x8QI V2x4HI V2x2SI V2x1DI
-				  V2x4HF V2x2SF V2x1DF V2x4BF
-				  V3x8QI V3x4HI V3x2SI V3x1DI
-				  V3x4HF V3x2SF V3x1DF V3x4BF
-				  V4x8QI V4x4HI V4x2SI V4x1DI
-				  V4x4HF V4x2SF V4x1DF V4x4BF
-				  V2x16QI V2x8HI V2x4SI V2x2DI
-				  V2x8HF V2x4SF V2x2DF V2x8BF
-				  V3x16QI V3x8HI V3x4SI V3x2DI
-				  V3x8HF V3x4SF V3x2DF V3x8BF
-				  V4x16QI V4x8HI V4x4SI V4x2DI
-				  V4x8HF V4x4SF V4x2DF V4x8BF])
+(define_mode_iterator VSTRUCT_QD [VSTRUCT_D VSTRUCT_Q])
 
 ;; Double scalar modes
 (define_mode_iterator DX [DI DF DD])
 
 ;; Duplicate of the above
-(define_mode_iterator DX2 [DI DF DD])
+(define_mode_iterator DX2 [DX])
 
 ;; Single scalar modes
 (define_mode_iterator SX [SI SF])
 
 ;; Duplicate of the above
-(define_mode_iterator SX2 [SI SF])
+(define_mode_iterator SX2 [SX])
 
 ;; Single and double integer and float modes
 (define_mode_iterator DSX [DF DI SF SI])
diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index a5c1d1faf92..5d86152e5dd 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -11797,6 +11797,19 @@ to @code{@var{mode}}.  For example:
 means that the @code{:DI} expansion only applies if @code{TARGET_64BIT}
 but that the @code{:SI} expansion has no such constraint.
 
+It is also possible to include iterators in other iterators.  For example:
+
+@smallexample
+(define_mode_iterator VI [V16QI V8HI V4SI V2DI])
+(define_mode_iterator VF [V8HF V4SF (V2DF "TARGET_DOUBLE")])
+(define_mode_iterator V [VI (VF "TARGET_FLOAT")])
+@end smallexample
+
+makes @samp{:V} iterate over the modes in @code{VI} and the modes
+in @code{VF}.  When a construct uses @samp{:V}, the @code{V8HF} and
+@code{V4SF} expansions require @samp{TARGET_FLOAT} while the @code{V2DF}
+expansion requires @samp{TARGET_DOUBLE && TARGET_FLOAT}.
+
 Iterators are applied in the order they are defined.  This can be
 significant if two iterators are used in a construct that requires
 substitutions.  @xref{Substitutions}.
diff --git a/gcc/read-rtl.cc b/gcc/read-rtl.cc
index f3b5613dfdb..00bf4abae5c 100644
--- a/gcc/read-rtl.cc
+++ b/gcc/read-rtl.cc
@@ -1293,8 +1293,25 @@ md_reader::read_mapping (struct iterator_group *group, htab_t table)
 	  string = read_string (false);
 	  require_char_ws (')');
 	}
-      number = group->find_builtin (name.string);
-      end_ptr = add_map_value (end_ptr, number, string);
+      auto *subm = (struct mapping *) htab_find (group->iterators,
+						 &name.string);
+      if (subm)
+	{
+	  if (m == subm)
+	    fatal_with_file_and_line ("recursive definition of `%s'",
+				      name.string);
+	  for (map_value *v = subm->values; v; v = v->next)
+	    {
+	      auto *joined = rtx_reader_ptr->join_c_conditions (v->string,
+								string);
+	      end_ptr = add_map_value (end_ptr, v->number, joined);
+	    }
+	}
+      else
+	{
+	  number = group->find_builtin (name.string);
+	  end_ptr = add_map_value (end_ptr, number, string);
+	}
       c = read_skip_spaces ();
     }
   while (c != ']');
-- 
2.25.1

Date: Fri, 10 Nov 2023 15:47:53 +0000
From: Richard Sandiford <richard.sandiford@arm.com>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-10 15:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-10 15:48 [pushed] Allow md iterators to include other iterators Richard Sandiford

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).