This patch adds a new interface to function_resolver::resolve_to
in which the mode suffix stays the same (which is the common case).
It then moves the handling of explicit first type suffixes from
function_resolver::resolve_unary to this new function.

This makes things slightly simpler for existing code.  However, the
main reason for doing it is that it helps require_derived_vector_type
handle explicit type suffixes correctly, which in turn improves the
error messages generated by the manual C overloading code in a
follow-up SME patch.

gcc/
        * config/aarch64/aarch64-sve-builtins.h
        (function_resolver::resolve_to): Add an overload that takes
        only the type suffixes.
        * config/aarch64/aarch64-sve-builtins.cc
        (function_resolver::resolve_to): Likewise.  Handle explicit type
        suffixes here rather than...
        (function_resolver::resolve_unary): ...here.
        (function_resolver::require_derived_vector_type): Simplify accordingly.
        (function_resolver::finish_opt_n_resolution): Likewise.
        (function_resolver::resolve_uniform): Likewise.
        * config/aarch64/aarch64-sve-builtins-shapes.cc
        (binary_imm_narrowt_base::resolve): Likewise.
        (load_contiguous_base::resolve): Likewise.
        (mmla_def::resolve): Likewise.
        (ternary_resize2_base::resolve): Likewise.
        (ternary_resize2_lane_base::resolve): Likewise.
        (unary_narrowt_base::resolve): Likewise.
        (binary_n_def::resolve): Likewise.
        (binary_uint_def::resolve): Likewise.
        (binary_uint_n_def::resolve): Likewise.
        (binary_uint64_n_def::resolve): Likewise.
        (binary_wide_def::resolve): Likewise.
        (compare_ptr_def::resolve): Likewise.
        (compare_scalar_def::resolve): Likewise.
        (fold_left_def::resolve): Likewise.
        (get_def::resolve): Likewise.
        (inc_dec_pred_def::resolve): Likewise.
        (inc_dec_pred_scalar_def::resolve): Likewise.
        (set_def::resolve): Likewise.
        (store_def::resolve): Likewise.
        (tbl_tuple_def::resolve): Likewise.
        (ternary_qq_lane_rotate_def::resolve): Likewise.
        (ternary_qq_rotate_def::resolve): Likewise.
        (ternary_uint_def::resolve): Likewise.
        (unary_def::resolve): Likewise.
        (unary_widen_def::resolve): Likewise.
---
 .../aarch64/aarch64-sve-builtins-shapes.cc    | 48 +++++++++----------
 gcc/config/aarch64/aarch64-sve-builtins.cc    | 34 +++++++++----
 gcc/config/aarch64/aarch64-sve-builtins.h     |  1 +
 3 files changed, 49 insertions(+), 34 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc 
b/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc
index 5b47dff0b41..df2d5414c07 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc
@@ -550,7 +550,7 @@ struct binary_imm_narrowt_base : public overloaded_base<0>
        || !r.require_integer_immediate (i + 2))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 
@@ -649,7 +649,7 @@ struct load_contiguous_base : public overloaded_base<0>
        || (vnum_p && !r.require_scalar_type (i + 1, "int64_t")))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 
@@ -739,7 +739,7 @@ struct mmla_def : public overloaded_base<0>
 
     /* Make sure that the function exists now, since not all forms
        follow a set pattern after this point.  */
-    tree res = r.resolve_to (r.mode_suffix_id, type);
+    tree res = r.resolve_to (type);
     if (res == error_mark_node)
       return res;
 
@@ -896,7 +896,7 @@ struct ternary_resize2_base : public overloaded_base<0>
                                           MODIFIER))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 
@@ -921,7 +921,7 @@ struct ternary_resize2_lane_base : public overloaded_base<0>
        || !r.require_integer_immediate (i + 3))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 
@@ -1012,7 +1012,7 @@ struct unary_narrowt_base : public overloaded_base<0>
        || !r.require_derived_vector_type (i, i + 1, type, CLASS, r.HALF_SIZE))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 
@@ -1218,7 +1218,7 @@ struct binary_n_def : public overloaded_base<0>
        || !r.require_derived_scalar_type (i + 1, r.SAME_TYPE_CLASS))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (binary_n)
@@ -1399,7 +1399,7 @@ struct binary_uint_def : public overloaded_base<0>
        || !r.require_derived_vector_type (i + 1, i, type, TYPE_unsigned))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (binary_uint)
@@ -1427,7 +1427,7 @@ struct binary_uint_n_def : public overloaded_base<0>
        || !r.require_derived_scalar_type (i + 1, TYPE_unsigned))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (binary_uint_n)
@@ -1484,7 +1484,7 @@ struct binary_uint64_n_def : public overloaded_base<0>
        || !r.require_scalar_type (i + 1, "uint64_t"))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (binary_uint64_n)
@@ -1539,7 +1539,7 @@ struct binary_wide_def : public overloaded_base<0>
                                           r.HALF_SIZE))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (binary_wide)
@@ -1671,7 +1671,7 @@ struct compare_ptr_def : public overloaded_base<0>
        || !r.require_matching_pointer_type (i + 1, i, type))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (compare_ptr)
@@ -1700,7 +1700,7 @@ struct compare_scalar_def : public overloaded_base<1>
        || !r.require_matching_integer_scalar_type (i + 1, i, type))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, r.type_suffix_ids[0], type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (compare_scalar)
@@ -1877,7 +1877,7 @@ struct fold_left_def : public overloaded_base<0>
        || (type = r.infer_vector_type (i + 1)) == NUM_TYPE_SUFFIXES)
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (fold_left)
@@ -1905,7 +1905,7 @@ struct get_def : public overloaded_base<0>
        || !r.require_integer_immediate (i + 1))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 
   bool
@@ -1987,7 +1987,7 @@ struct inc_dec_pred_def : public overloaded_base<0>
        || !r.require_vector_type (i + 1, VECTOR_TYPE_svbool_t))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (inc_dec_pred)
@@ -2014,7 +2014,7 @@ struct inc_dec_pred_scalar_def : public overloaded_base<2>
        || !r.require_vector_type (i + 1, VECTOR_TYPE_svbool_t))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type, r.type_suffix_ids[1]);
+    return r.resolve_to (type, r.type_suffix_ids[1]);
   }
 };
 SHAPE (inc_dec_pred_scalar)
@@ -2419,7 +2419,7 @@ struct set_def : public overloaded_base<0>
        || !r.require_derived_vector_type (i + 2, i, type))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 
   bool
@@ -2594,7 +2594,7 @@ struct store_def : public overloaded_base<0>
        || ((type = r.infer_tuple_type (nargs - 1)) == NUM_TYPE_SUFFIXES))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (store)
@@ -2714,7 +2714,7 @@ struct tbl_tuple_def : public overloaded_base<0>
        || !r.require_derived_vector_type (i + 1, i, type, TYPE_unsigned))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (tbl_tuple)
@@ -2959,7 +2959,7 @@ struct ternary_qq_lane_rotate_def : public 
overloaded_base<0>
        || !r.require_integer_immediate (i + 4))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 
   bool
@@ -3018,7 +3018,7 @@ struct ternary_qq_rotate_def : public overloaded_base<0>
        || !r.require_integer_immediate (i + 3))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 
   bool
@@ -3107,7 +3107,7 @@ struct ternary_uint_def : public overloaded_base<0>
        || !r.require_derived_vector_type (i + 2, i, type, TYPE_unsigned))
       return error_mark_node;
 
-    return r.resolve_to (r.mode_suffix_id, type);
+    return r.resolve_to (type);
   }
 };
 SHAPE (ternary_uint)
@@ -3437,7 +3437,7 @@ struct unary_widen_def : public overloaded_base<0>
 
     /* There is only a single form for predicates.  */
     if (type == TYPE_SUFFIX_b)
-      return r.resolve_to (r.mode_suffix_id, type);
+      return r.resolve_to (type);
 
     if (type_suffixes[type].integer_p
        && type_suffixes[type].element_bits < 64)
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.cc 
b/gcc/config/aarch64/aarch64-sve-builtins.cc
index 450a8d958a8..e50a58dcc0a 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins.cc
@@ -1255,6 +1255,25 @@ function_resolver::resolve_to (mode_suffix_index mode,
   return res;
 }
 
+/* A cut-down interface to the function above that keeps the mode suffix
+   unchanged.  As a convenience, resolve_to (TYPE0) can be used for functions
+   whose first type suffix is explicit, with TYPE0 then describing the
+   second type suffix rather than the first.  */
+tree
+function_resolver::resolve_to (type_suffix_index type0,
+                              type_suffix_index type1)
+{
+  /* Handle convert-like functions in which the first type suffix is
+     explicit.  */
+  if (type_suffix_ids[0] != NUM_TYPE_SUFFIXES && type1 == NUM_TYPE_SUFFIXES)
+    {
+      type1 = type0;
+      type0 = type_suffix_ids[0];
+    }
+
+  return resolve_to (mode_suffix_id, type0, type1);
+}
+
 /* Require argument ARGNO to be a 32-bit or 64-bit scalar integer type.
    Return the associated type suffix on success, otherwise report an
    error and return NUM_TYPE_SUFFIXES.  */
@@ -1636,7 +1655,7 @@ require_derived_vector_type (unsigned int argno,
 
   /* Make sure that FIRST_TYPE itself is sensible before using it
      as a basis for an error message.  */
-  if (resolve_to (mode_suffix_id, first_type) == error_mark_node)
+  if (resolve_to (first_type) == error_mark_node)
     return false;
 
   /* If the arguments have consistent type classes, but a link between
@@ -2202,7 +2221,7 @@ finish_opt_n_resolution (unsigned int argno, unsigned int 
first_argno,
 
       /* Check the vector form normally.  If that succeeds, raise an
         error about having no corresponding _n form.  */
-      tree res = resolve_to (mode_suffix_id, inferred_type);
+      tree res = resolve_to (inferred_type);
       if (res != error_mark_node)
        error_at (location, "passing %qT to argument %d of %qE, but its"
                  " %qT form does not accept scalars",
@@ -2222,7 +2241,7 @@ finish_opt_n_resolution (unsigned int argno, unsigned int 
first_argno,
                                    expected_tclass, expected_bits))
     return error_mark_node;
 
-  return resolve_to (mode_suffix_id, inferred_type);
+  return resolve_to (inferred_type);
 }
 
 /* Resolve a (possibly predicated) unary function.  If the function uses
@@ -2279,12 +2298,7 @@ function_resolver::resolve_unary (type_class_index 
merge_tclass,
        return error_mark_node;
     }
 
-  /* Handle convert-like functions in which the first type suffix is
-     explicit.  */
-  if (type_suffix_ids[0] != NUM_TYPE_SUFFIXES)
-    return resolve_to (mode_suffix_id, type_suffix_ids[0], type);
-
-  return resolve_to (mode_suffix_id, type);
+  return resolve_to (type);
 }
 
 /* Resolve a (possibly predicated) function that takes NOPS like-typed
@@ -2309,7 +2323,7 @@ function_resolver::resolve_uniform (unsigned int nops, 
unsigned int nimm)
     if (!require_integer_immediate (i))
       return error_mark_node;
 
-  return resolve_to (mode_suffix_id, type);
+  return resolve_to (type);
 }
 
 /* Resolve a (possibly predicated) function that offers a choice between
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.h 
b/gcc/config/aarch64/aarch64-sve-builtins.h
index 623b9e3a07b..479b248bef1 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.h
+++ b/gcc/config/aarch64/aarch64-sve-builtins.h
@@ -394,6 +394,7 @@ public:
   tree resolve_to (mode_suffix_index,
                   type_suffix_index = NUM_TYPE_SUFFIXES,
                   type_suffix_index = NUM_TYPE_SUFFIXES);
+  tree resolve_to (type_suffix_index, type_suffix_index = NUM_TYPE_SUFFIXES);
 
   type_suffix_index infer_integer_scalar_type (unsigned int);
   type_suffix_index infer_pointer_type (unsigned int, bool = false);
-- 
2.25.1

Reply via email to