aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-attribs.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-02-11 12:43:22 +0100
committerRichard Biener <rguenther@suse.de>2022-02-11 13:53:45 +0100
commitae117af43944101ca47b99b743c85a3c528b4b4f (patch)
treee6b640e8c3125ff9be07dc1d869a03e4d682beef /gcc/c-family/c-attribs.cc
parent84993d94e13ad2ab3aee151bb5a5e767cf75d51e (diff)
downloadgcc-ae117af43944101ca47b99b743c85a3c528b4b4f.zip
gcc-ae117af43944101ca47b99b743c85a3c528b4b4f.tar.gz
gcc-ae117af43944101ca47b99b743c85a3c528b4b4f.tar.bz2
[gimplefe] Add vector_mask attribute to get access to vector bools
The following adds __attribute__((vector_mask)) to get access to the corresponding mask type for a vector type. The implementation simply uses truth_type_for so creating a mask type that's not what the target would choose as canonical, say a AVX2 style one when AVX512VL is enabled, is not possible. It might be possible to provide access to that with an optional argument specifying the precision of the bool element. The syntax is as simple as typedef vector_type mask_type __attribute__((vector_mask)); In theory this allows to create unit testcases for vector lowering and ISEL. 2022-02-11 Richard Biener <rguenther@suse.de> gcc/c-family/ * c-attribs.cc (c_common_attribute_table): Add entry for vector_mask. (handle_vector_mask_attribute): New. gcc/c/ * gimple-parser.cc (c_parser_gimple_statement): Properly parse VEC_COND_EXPRs. gcc/testsuite/ * gcc.dg/gimplefe-48.c: New testcase.
Diffstat (limited to 'gcc/c-family/c-attribs.cc')
-rw-r--r--gcc/c-family/c-attribs.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 4fb5dbd..3849dba 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -129,6 +129,8 @@ static tree handle_unavailable_attribute (tree *, tree, tree, int,
bool *);
static tree handle_vector_size_attribute (tree *, tree, tree, int,
bool *) ATTRIBUTE_NONNULL(3);
+static tree handle_vector_mask_attribute (tree *, tree, tree, int,
+ bool *) ATTRIBUTE_NONNULL(3);
static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
static tree handle_nonstring_attribute (tree *, tree, tree, int, bool *);
static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
@@ -417,6 +419,8 @@ const struct attribute_spec c_common_attribute_table[] =
handle_unavailable_attribute, NULL },
{ "vector_size", 1, 1, false, true, false, true,
handle_vector_size_attribute, NULL },
+ { "vector_mask", 0, 0, false, true, false, true,
+ handle_vector_mask_attribute, NULL },
{ "visibility", 1, 1, false, false, false, false,
handle_visibility_attribute, NULL },
{ "tls_model", 1, 1, true, false, false, false,
@@ -4419,6 +4423,38 @@ handle_vector_size_attribute (tree *node, tree name, tree args,
return NULL_TREE;
}
+/* Handle a "vector_mask" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+static tree
+handle_vector_mask_attribute (tree *node, tree name, tree,
+ int ARG_UNUSED (flags),
+ bool *no_add_attrs)
+{
+ *no_add_attrs = true;
+ if (!flag_gimple)
+ {
+ warning (OPT_Wattributes, "%qE attribute ignored", name);
+ return NULL_TREE;
+ }
+
+ /* Determine the "base" type to apply the attribute to. */
+ tree type = type_for_vector_size (*node);
+ if (!VECTOR_TYPE_P (type) || VECTOR_BOOLEAN_TYPE_P (type))
+ {
+ warning (OPT_Wattributes, "%qE attribute only supported on "
+ "non-mask vector types", name);
+ return NULL_TREE;
+ }
+
+ tree new_type = truth_type_for (type);
+
+ /* Build back pointers if needed. */
+ *node = lang_hooks.types.reconstruct_complex_type (*node, new_type);
+
+ return NULL_TREE;
+}
+
/* Handle the "nonnull" attribute. */
static tree