if (strcmp (name, "vector") == 0
|| strcmp (name, "xtheadvector") == 0)
{
- if (!TARGET_VECTOR)
+ if (TARGET_VECTOR)
+ riscv_vector::handle_pragma_vector ();
+ else /* Indicates riscv_vector.h is included but v is missing in arch */
{
- error ("%<#pragma riscv intrinsic%> option %qs needs 'V' or "
- "'XTHEADVECTOR' extension enabled",
- name);
- return;
+ /* To make the the rvv types and intrinsic API available for the
+ target("arch=+v") attribute, we need to temporally enable the
+ TARGET_VECTOR, and disable it after all initialized. */
+ target_flags |= MASK_VECTOR;
+
+ riscv_vector::init_builtins ();
+ riscv_vector::handle_pragma_vector ();
+
+ target_flags &= ~MASK_VECTOR;
}
- riscv_vector::handle_pragma_vector ();
}
else
error ("unknown %<#pragma riscv intrinsic%> option %qs", name);
expand_builtin (unsigned int code, tree exp, rtx target)
{
registered_function &rfn = *(*registered_functions)[code];
+
+ if (!TARGET_VECTOR)
+ error_at (EXPR_LOCATION (exp),
+ "builtin function %qE requires the V ISA extension", exp);
+
return function_expander (rfn.instance, rfn.decl, exp, target).expand ();
}
{
tree return_type = TREE_TYPE (fntype);
- return riscv_vector_type_p (return_type);
+ if (riscv_vector_type_p (return_type))
+ {
+ if (!TARGET_VECTOR)
+ error_at (input_location,
+ "return type %qT requires the V ISA extension", return_type);
+ return true;
+ }
+ else
+ return false;
}
/* Return true if a function with type FNTYPE takes arguments in
{
tree arg_type = TREE_VALUE (chain);
if (riscv_vector_type_p (arg_type))
- return true;
+ {
+ if (!TARGET_VECTOR)
+ error_at (input_location,
+ "argument type %qT requires the V ISA extension",
+ arg_type);
+ return true;
+ }
}
return false;
static bool
riscv_vector_cc_function_p (const_tree fntype)
{
- return lookup_attribute ("vector_cc", TYPE_ATTRIBUTES (fntype)) != NULL_TREE
- || lookup_attribute ("riscv_vector_cc", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
+ tree attr = TYPE_ATTRIBUTES (fntype);
+ bool vector_cc_p = lookup_attribute ("vector_cc", attr) != NULL_TREE
+ || lookup_attribute ("riscv_vector_cc", attr) != NULL_TREE;
+
+ if (vector_cc_p && !TARGET_VECTOR)
+ error_at (input_location,
+ "function attribute %qs requires the V ISA extension",
+ "riscv_vector_cc");
+
+ return vector_cc_p;
}
/* Implement TARGET_FNTYPE_ABI. */
#include <stdint.h>
#include <stddef.h>
-#ifndef __riscv_vector
-#error "Vector intrinsics require the vector extension."
-#else
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif // __cplusplus
-#endif // __riscv_vector
#endif // __RISCV_VECTOR_H
+++ /dev/null
-/* { dg-do compile } */
-/* { dg-options "-O3 -march=rv32gc -mabi=ilp32d" } */
-
-#pragma riscv intrinsic "vector" /* { dg-error {#pragma riscv intrinsic' option 'vector' needs 'V' or 'XTHEADVECTOR' extension enabled} } */
--- /dev/null
+/* Test that we do not have error when compile */
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
--- /dev/null
+/* Test that we do not have error when compile */
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+vint32m1_t
+__attribute__((target("arch=+v")))
+test_1 (vint32m1_t a, vint32m1_t b, size_t vl)
+{
+ return __riscv_vadd_vv_i32m1 (a, b, vl);
+}
+
+void
+test_2 ()
+{
+ vint32m1_t a;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -Wno-implicit-int" } */
+
+#include "riscv_vector.h"
+
+vint32m1_t
+__attribute__((target("arch=+zbb")))
+test_1 (vint32m1_t a, vint32m1_t b, size_t vl)
+{
+ return __riscv_vadd_vv_i32m1 (a, b, vl);
+}
+
+/* { dg-error "return type 'vint32m1_t' requires the V ISA extension" "" { target { "riscv*-*-*" } } 0 } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+void
+test_1 (vint32m1_t a) /* { dg-error {argument type 'vint32m1_t' requires the V ISA extension} } */
+{
+ return;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+vint32m1_t test_1 ()
+{
+ vint32m1_t a;
+ return a;
+}
+
+/* { dg-error "return type 'vint32m1_t' requires the V ISA extension" "" { target { "riscv*-*-*" } } 0 } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+int
+__attribute__((riscv_vector_cc))
+test_1 (int a)
+{
+ return a + 1;
+}
+/* { dg-error "function attribute 'riscv_vector_cc' requires the V ISA extension" "" { target { "riscv*-*-*" } } 0 } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+size_t test_1 (size_t vl)
+{
+ return __riscv_vsetvl_e8m4 (vl); /* { dg-error {builtin function '__riscv_vsetvl_e8m4\(vl\)' requires the V ISA extension} } */
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+vint32m1_t
+__attribute__((target("arch=+v")))
+test_1 (vint32m1_t a, vint32m1_t b, size_t vl)
+{
+ return __riscv_vadd_vv_i32m1 (a, b, vl);
+}
+
+void
+test_2 ()
+{
+ vint32m1_t a;
+}
+
+size_t
+test_3 (size_t vl)
+{
+ return __riscv_vsetvl_e8m4 (vl); /* { dg-error {builtin function '__riscv_vsetvl_e8m4\(vl\)' requires the V ISA extension} } */
+}