]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Allow md iterators to include other iterators
authorRichard Sandiford <richard.sandiford@arm.com>
Fri, 10 Nov 2023 15:46:21 +0000 (15:46 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Fri, 10 Nov 2023 15:46:21 +0000 (15:46 +0000)
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)

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
gcc/doc/md.texi
gcc/read-rtl.cc

index 1593a8fd04f91259295d0e393cbc7973daf7bf73..a920de99ffca378ce518f378a35cbe2766877ee8 100644 (file)
 (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])
 (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])
 (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])
 (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])
 ;; 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])
 (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])
index a5c1d1faf929e8e08a2704415d2a84e884f18cb1..5d86152e5dd9e7a5f8b0e7a7f0c6e057d3281fc0 100644 (file)
@@ -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}.
index f3b5613dfdbe41d065034fa784be4eae1c269fb7..00bf4abae5cc97b5c851584d9a3e16a76eaf396d 100644 (file)
@@ -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 != ']');