forked from ruyisdk/riscv-gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RISC-V: Add riscv_vector_cc function attribute
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. riscv-non-isa/riscv-c-api-doc#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.
- Loading branch information
1 parent
84b44ce
commit 68cd5cb
Showing
5 changed files
with
119 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
gcc/testsuite/g++.target/riscv/rvv/base/attribute-riscv_vector_cc-error.C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* { dg-do compile } */ | ||
/* { dg-options "-march=rv64gcv -mabi=lp64d -O1" } */ | ||
|
||
[[riscv::vector_cc]] void foo();// For C++11 and C23 | ||
|
||
[[riscv::vector_cc]] int var; /* { dg-warning "'vector_cc' attribute only applies to function types" } */ | ||
|
||
void __attribute__((riscv_vector_cc)) func(); | ||
void __attribute__((riscv_vector_cc(1))) func_invalid(); /* { dg-error "wrong number of arguments specified for 'riscv_vector_cc' attribute" } */ | ||
|
||
void test_no_attribute(int); | ||
void __attribute__((riscv_vector_cc)) test_no_attribute(int x) { } | ||
|
||
class test_cc { | ||
__attribute__((riscv_vector_cc)) void member_func(); | ||
}; | ||
|
||
void test_lambda() { | ||
__attribute__((riscv_vector_cc)) auto lambda = []() { /* { dg-warning "'riscv_vector_cc' attribute only applies to function types" } */ | ||
}; | ||
} |
30 changes: 30 additions & 0 deletions
30
gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-saved.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* { dg-do compile } */ | ||
/* { dg-options "-march=rv64gcv -mabi=lp64d" } */ | ||
|
||
void __attribute__((riscv_vector_cc)) bar1 (int a); | ||
void bar2 (); | ||
|
||
void __attribute__((riscv_vector_cc)) | ||
foo1 (int a) | ||
{ | ||
bar1 (a); | ||
} | ||
|
||
void __attribute__((riscv_vector_cc)) | ||
foo2 (int a) | ||
{ | ||
char data[1024]; | ||
bar2 (); | ||
} | ||
|
||
void | ||
foo3 (int *a) | ||
{ | ||
bar1 (*a); | ||
} | ||
|
||
/* { dg-final { scan-assembler-not {\.variant_cc\tbar2} } } */ | ||
/* { dg-final { scan-assembler-not {\.variant_cc\tfoo3} } } */ | ||
/* { dg-final { scan-assembler-times {\.variant_cc\tbar1} 1 } } */ | ||
/* { dg-final { scan-assembler-times {\.variant_cc\tfoo1} 1 } } */ | ||
/* { dg-final { scan-assembler-times {\.variant_cc\tfoo2} 1 } } */ |
11 changes: 11 additions & 0 deletions
11
gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-error.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* { dg-do compile } */ | ||
/* { dg-options "-march=rv64gcv -mabi=lp64d -O1" } */ | ||
|
||
__attribute__((riscv_vector_cc)) int var; /* { dg-warning "'riscv_vector_cc' attribute only applies to function types" } */ | ||
[[riscv::vector_cc]] int var1; /* { dg-warning "'vector_cc' attribute only applies to function types" } */ | ||
|
||
void __attribute__((riscv_vector_cc)) func(); | ||
void __attribute__((riscv_vector_cc(1))) func_invalid(); /* { dg-error "wrong number of arguments specified for 'riscv_vector_cc' attribute" } */ | ||
|
||
void test_no_attribute(int); | ||
void __attribute__((riscv_vector_cc)) test_no_attribute(int x) { } |