Re: [PATCH] RISC-V: Add riscv_vector_cc function attribute
Thanks for your patch! this is generally in good shape, just a few minor comments :) > diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi > index 2135dfde9c8..afe486ba47b 100644 > --- a/gcc/doc/extend.texi > +++ b/gcc/doc/extend.texi > @@ -6314,6 +6314,18 @@ Permissible values for this parameter are @code{user}, > @code{supervisor}, > and @code{machine}. If there is no parameter, then it defaults to > @code{machine}. > > +@cindex @code{riscv_vector_cc} function attribute, RISC-V > +@item riscv_vector_cc > +Use this attribute to force the function to use the vector calling > +convention variant. > +For more information on riscv_vector_cc, please see > +@uref{https://github.com/riscv-non-isa/riscv-c-api-doc/pull/67} Please remove above two line, I guess it's not good idea to reference a pull request link here :P > + > +@smallexample > +void foo() __attribute__((riscv_vector_cc)); > +[[riscv::vector_cc]] void foo(); // For C++11 and C23 > +@end smallexample > + > @end table > > The following target-specific function attributes are available for the > diff --git > a/gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c > > b/gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c > new file mode 100644 > index 000..7db9d874bcd > --- /dev/null > +++ > b/gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c > @@ -0,0 +1,117 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=rv64gcv -mabi=lp64d -O1" } */ > +/* { dg-final { check-function-bodies "**" "" } } */ I would like to prevent scanning the asm body if possible, since it might cause problem when we improving code gen, so could you try to scan .variant_cc\t like gcc/testsuite/gcc.target/aarch64/pcs_attribute-3.c? Then we can also drop -O1 in the option :) > + > +#include Drop this. > +void __attribute__((riscv_vector_cc)) > +foo2 (int a) > +{ > + int8_t data[1024]; Just char rather than int8_t, I would like to remove unnecessary header including if possible :)
Re: [PATCH] RISC-V: Add riscv_vector_cc function attribute
Ping. xu...@eswincomputing.com From: Li Xu Date: 2024-02-27 09:17 To: gcc-patches CC: kito.cheng; palmer; juzhe.zhong; zhengyu; xuli Subject: [PATCH] RISC-V: Add riscv_vector_cc function attribute From: xuli Standard vector calling convention variant will only enabled when function has vector argument or returning value by default, however user may also want to invoke function without that during a vectorized loop at some situation, but it will cause a huge performance penalty due to vector register store/restore. So user can declare function with this riscv_vector_cc attribute like below, that could enforce function will use standard vector calling convention variant. void foo() __attribute__((riscv_vector_cc)); [[riscv::vector_cc]] void foo(); // For C++11 and C23 For more details please reference the below link. https://github.com/riscv-non-isa/riscv-c-api-doc/pull/67 gcc/ChangeLog: * config/riscv/riscv.cc (TARGET_GNU_ATTRIBUTES): Add riscv_vector_cc attribute to riscv_attribute_table. (riscv_vector_cc_function_p): Return true if FUNC is a riscv_vector_cc function. (riscv_fntype_abi): Add riscv_vector_cc attribute check. * doc/extend.texi: Add riscv_vector_cc attribute description. gcc/testsuite/ChangeLog: * g++.target/riscv/rvv/base/attribute-riscv_vector_cc-error.C: New test. * gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c: New test. * gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-error.c: New test. --- gcc/config/riscv/riscv.cc | 55 ++-- gcc/doc/extend.texi | 12 ++ .../base/attribute-riscv_vector_cc-error.C| 22 .../attribute-riscv_vector_cc-callee-saved.c | 117 ++ .../base/attribute-riscv_vector_cc-error.c| 11 ++ 5 files changed, 209 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/attribute-riscv_vector_cc-error.C create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-error.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 4100abc9dd1..7f37f231796 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -537,24 +537,52 @@ static tree riscv_handle_fndecl_attribute (tree *, tree, tree, int, bool *); static tree riscv_handle_type_attribute (tree *, tree, tree, int, bool *); /* Defining target-specific uses of __attribute__. */ -TARGET_GNU_ATTRIBUTES (riscv_attribute_table, +static const attribute_spec riscv_gnu_attributes[] = { /* Syntax: { name, min_len, max_len, decl_required, type_required, function_type_required, affects_type_identity, handler, exclude } */ /* The attribute telling no prologue/epilogue. */ - { "naked", 0, 0, true, false, false, false, -riscv_handle_fndecl_attribute, NULL }, + {"naked", 0, 0, true, false, false, false, riscv_handle_fndecl_attribute, + NULL}, /* This attribute generates prologue/epilogue for interrupt handlers. */ - { "interrupt", 0, 1, false, true, true, false, -riscv_handle_type_attribute, NULL }, + {"interrupt", 0, 1, false, true, true, false, riscv_handle_type_attribute, + NULL}, /* The following two are used for the built-in properties of the Vector type and are not used externally */ {"RVV sizeless type", 4, 4, false, true, false, true, NULL, NULL}, - {"RVV type", 0, 0, false, true, false, true, NULL, NULL} -}); + {"RVV type", 0, 0, false, true, false, true, NULL, NULL}, + /* This attribute is used to declare a function, forcing it to use the +standard vector calling convention variant. Syntax: +__attribute__((riscv_vector_cc)). */ + {"riscv_vector_cc", 0, 0, false, true, true, true, NULL, NULL} +}; + +static const scoped_attribute_specs riscv_gnu_attribute_table = +{ + "gnu", {riscv_gnu_attributes} +}; + +static const attribute_spec riscv_attributes[] = +{ + /* This attribute is used to declare a function, forcing it to use the + standard vector calling convention variant. Syntax: + [[riscv::vector_cc]]. */ + {"vector_cc", 0, 0, false, true, true, true, NULL, NULL} +}; + +static const scoped_attribute_specs riscv_nongnu_attribute_table = +{ + "riscv", {riscv_attributes} +}; + +static const scoped_attribute_specs *const riscv_attribute_table[] = +{ + &riscv_gnu_attribute_table, + &riscv_nongnu_attribute_table +}; /* Order for the CLOBBERs/USEs of gpr_save. */ static const unsigned gpr_save_reg_order[] = { @@ -5425,6 +5453,16 @@ riscv_arguments_is_vector_type_p (const_tree fntype) return false; } +/* Return true if FUNC is a riscv_vector_cc function. + For more details please reference the below link. + https://github.com/riscv-non-isa/riscv-c-api-doc/pull/67 */ +static bool +riscv_vector_cc_function_p (const
Re: [PATCH] RISC-V: Add riscv_vector_cc function attribute
Thanks for supporting this. I'd rather leave this patch review to kito's since it's kito's proposal. juzhe.zh...@rivai.ai From: Li Xu Date: 2024-02-27 09:17 To: gcc-patches CC: kito.cheng; palmer; juzhe.zhong; zhengyu; xuli Subject: [PATCH] RISC-V: Add riscv_vector_cc function attribute From: xuli Standard vector calling convention variant will only enabled when function has vector argument or returning value by default, however user may also want to invoke function without that during a vectorized loop at some situation, but it will cause a huge performance penalty due to vector register store/restore. So user can declare function with this riscv_vector_cc attribute like below, that could enforce function will use standard vector calling convention variant. void foo() __attribute__((riscv_vector_cc)); [[riscv::vector_cc]] void foo(); // For C++11 and C23 For more details please reference the below link. https://github.com/riscv-non-isa/riscv-c-api-doc/pull/67 gcc/ChangeLog: * config/riscv/riscv.cc (TARGET_GNU_ATTRIBUTES): Add riscv_vector_cc attribute to riscv_attribute_table. (riscv_vector_cc_function_p): Return true if FUNC is a riscv_vector_cc function. (riscv_fntype_abi): Add riscv_vector_cc attribute check. * doc/extend.texi: Add riscv_vector_cc attribute description. gcc/testsuite/ChangeLog: * g++.target/riscv/rvv/base/attribute-riscv_vector_cc-error.C: New test. * gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c: New test. * gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-error.c: New test. --- gcc/config/riscv/riscv.cc | 55 ++-- gcc/doc/extend.texi | 12 ++ .../base/attribute-riscv_vector_cc-error.C| 22 .../attribute-riscv_vector_cc-callee-saved.c | 117 ++ .../base/attribute-riscv_vector_cc-error.c| 11 ++ 5 files changed, 209 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/attribute-riscv_vector_cc-error.C create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-error.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 4100abc9dd1..7f37f231796 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -537,24 +537,52 @@ static tree riscv_handle_fndecl_attribute (tree *, tree, tree, int, bool *); static tree riscv_handle_type_attribute (tree *, tree, tree, int, bool *); /* Defining target-specific uses of __attribute__. */ -TARGET_GNU_ATTRIBUTES (riscv_attribute_table, +static const attribute_spec riscv_gnu_attributes[] = { /* Syntax: { name, min_len, max_len, decl_required, type_required, function_type_required, affects_type_identity, handler, exclude } */ /* The attribute telling no prologue/epilogue. */ - { "naked", 0, 0, true, false, false, false, -riscv_handle_fndecl_attribute, NULL }, + {"naked", 0, 0, true, false, false, false, riscv_handle_fndecl_attribute, + NULL}, /* This attribute generates prologue/epilogue for interrupt handlers. */ - { "interrupt", 0, 1, false, true, true, false, -riscv_handle_type_attribute, NULL }, + {"interrupt", 0, 1, false, true, true, false, riscv_handle_type_attribute, + NULL}, /* The following two are used for the built-in properties of the Vector type and are not used externally */ {"RVV sizeless type", 4, 4, false, true, false, true, NULL, NULL}, - {"RVV type", 0, 0, false, true, false, true, NULL, NULL} -}); + {"RVV type", 0, 0, false, true, false, true, NULL, NULL}, + /* This attribute is used to declare a function, forcing it to use the +standard vector calling convention variant. Syntax: +__attribute__((riscv_vector_cc)). */ + {"riscv_vector_cc", 0, 0, false, true, true, true, NULL, NULL} +}; + +static const scoped_attribute_specs riscv_gnu_attribute_table = +{ + "gnu", {riscv_gnu_attributes} +}; + +static const attribute_spec riscv_attributes[] = +{ + /* This attribute is used to declare a function, forcing it to use the + standard vector calling convention variant. Syntax: + [[riscv::vector_cc]]. */ + {"vector_cc", 0, 0, false, true, true, true, NULL, NULL} +}; + +static const scoped_attribute_specs riscv_nongnu_attribute_table = +{ + "riscv", {riscv_attributes} +}; + +static const scoped_attribute_specs *const riscv_attribute_table[] = +{ + &riscv_gnu_attribute_table, + &riscv_nongnu_attribute_table +}; /* Order for the CLOBBERs/USEs of gpr_save. */ static const unsigned gpr_save_reg_order[] = { @@ -5425,6 +5453,16 @@ riscv_arguments_is_vector_type_p (const_tree fntype) return false; } +/* Return true if FUNC is a riscv_vector_cc function. + For more details please reference the below link.
[PATCH] RISC-V: Add riscv_vector_cc function attribute
From: xuli Standard vector calling convention variant will only enabled when function has vector argument or returning value by default, however user may also want to invoke function without that during a vectorized loop at some situation, but it will cause a huge performance penalty due to vector register store/restore. So user can declare function with this riscv_vector_cc attribute like below, that could enforce function will use standard vector calling convention variant. void foo() __attribute__((riscv_vector_cc)); [[riscv::vector_cc]] void foo(); // For C++11 and C23 For more details please reference the below link. https://github.com/riscv-non-isa/riscv-c-api-doc/pull/67 gcc/ChangeLog: * config/riscv/riscv.cc (TARGET_GNU_ATTRIBUTES): Add riscv_vector_cc attribute to riscv_attribute_table. (riscv_vector_cc_function_p): Return true if FUNC is a riscv_vector_cc function. (riscv_fntype_abi): Add riscv_vector_cc attribute check. * doc/extend.texi: Add riscv_vector_cc attribute description. gcc/testsuite/ChangeLog: * g++.target/riscv/rvv/base/attribute-riscv_vector_cc-error.C: New test. * gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c: New test. * gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-error.c: New test. --- gcc/config/riscv/riscv.cc | 55 ++-- gcc/doc/extend.texi | 12 ++ .../base/attribute-riscv_vector_cc-error.C| 22 .../attribute-riscv_vector_cc-callee-saved.c | 117 ++ .../base/attribute-riscv_vector_cc-error.c| 11 ++ 5 files changed, 209 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/attribute-riscv_vector_cc-error.C create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-error.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 4100abc9dd1..7f37f231796 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -537,24 +537,52 @@ static tree riscv_handle_fndecl_attribute (tree *, tree, tree, int, bool *); static tree riscv_handle_type_attribute (tree *, tree, tree, int, bool *); /* Defining target-specific uses of __attribute__. */ -TARGET_GNU_ATTRIBUTES (riscv_attribute_table, +static const attribute_spec riscv_gnu_attributes[] = { /* Syntax: { name, min_len, max_len, decl_required, type_required, function_type_required, affects_type_identity, handler, exclude } */ /* The attribute telling no prologue/epilogue. */ - { "naked", 0, 0, true, false, false, false, -riscv_handle_fndecl_attribute, NULL }, + {"naked", 0, 0, true, false, false, false, riscv_handle_fndecl_attribute, + NULL}, /* This attribute generates prologue/epilogue for interrupt handlers. */ - { "interrupt", 0, 1, false, true, true, false, -riscv_handle_type_attribute, NULL }, + {"interrupt", 0, 1, false, true, true, false, riscv_handle_type_attribute, + NULL}, /* The following two are used for the built-in properties of the Vector type and are not used externally */ {"RVV sizeless type", 4, 4, false, true, false, true, NULL, NULL}, - {"RVV type", 0, 0, false, true, false, true, NULL, NULL} -}); + {"RVV type", 0, 0, false, true, false, true, NULL, NULL}, + /* This attribute is used to declare a function, forcing it to use the +standard vector calling convention variant. Syntax: +__attribute__((riscv_vector_cc)). */ + {"riscv_vector_cc", 0, 0, false, true, true, true, NULL, NULL} +}; + +static const scoped_attribute_specs riscv_gnu_attribute_table = +{ + "gnu", {riscv_gnu_attributes} +}; + +static const attribute_spec riscv_attributes[] = +{ + /* This attribute is used to declare a function, forcing it to use the + standard vector calling convention variant. Syntax: + [[riscv::vector_cc]]. */ + {"vector_cc", 0, 0, false, true, true, true, NULL, NULL} +}; + +static const scoped_attribute_specs riscv_nongnu_attribute_table = +{ + "riscv", {riscv_attributes} +}; + +static const scoped_attribute_specs *const riscv_attribute_table[] = +{ + &riscv_gnu_attribute_table, + &riscv_nongnu_attribute_table +}; /* Order for the CLOBBERs/USEs of gpr_save. */ static const unsigned gpr_save_reg_order[] = { @@ -5425,6 +5453,16 @@ riscv_arguments_is_vector_type_p (const_tree fntype) return false; } +/* Return true if FUNC is a riscv_vector_cc function. + For more details please reference the below link. + https://github.com/riscv-non-isa/riscv-c-api-doc/pull/67 */ +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; +} + /* Implement TARGET_FNTYPE_ABI