Skip to content

Commit 5d07763

Browse files
committed
fixup! [RISCV] RISCV vector calling convention (1/2)
1 parent a3ac9a5 commit 5d07763

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2981,7 +2981,9 @@ def PreserveNone : DeclOrTypeAttr, TargetSpecificAttr<TargetAnyX86> {
29812981
}
29822982

29832983
def RISCVVectorCC: DeclOrTypeAttr {
2984-
let Spellings = [Clang<"riscv_vector_cc">];
2984+
let Spellings = [CXX11<"riscv", "vector_cc">,
2985+
C23<"riscv", "vector_cc">,
2986+
Clang<"riscv_vector_cc">];
29852987
let Documentation = [RISCVVectorCCDocs];
29862988
}
29872989

clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// REQUIRES: riscv-registered-target
22
// RUN: %clang_cc1 -triple riscv64 -target-feature +v \
33
// RUN: -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-LLVM %s
4+
// RUN: %clang_cc1 -std=c23 -triple riscv64 -target-feature +v \
5+
// RUN: -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-LLVM %s
46

57
#include <riscv_vector.h>
68

@@ -13,6 +15,15 @@ vint32m1_t test_vector_cc_attr(vint32m1_t input, int32_t *base, size_t vl) {
1315
return ret;
1416
}
1517

18+
// CHECK-LLVM: call riscv_vector_cc <vscale x 2 x i32> @bar
19+
[[riscv::vector_cc]] vint32m1_t bar(vint32m1_t input);
20+
vint32m1_t test_vector_cc_attr2(vint32m1_t input, int32_t *base, size_t vl) {
21+
vint32m1_t val = __riscv_vle32_v_i32m1(base, vl);
22+
vint32m1_t ret = bar(input);
23+
__riscv_vse32_v_i32m1(base, val, vl);
24+
return ret;
25+
}
26+
1627
// CHECK-LLVM: call <vscale x 2 x i32> @baz
1728
vint32m1_t baz(vint32m1_t input);
1829
vint32m1_t test_no_vector_cc_attr(vint32m1_t input, int32_t *base, size_t vl) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// REQUIRES: riscv-registered-target
2+
// RUN: %clang_cc1 -std=c++11 -triple riscv64 -target-feature +v \
3+
// RUN: -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-LLVM %s
4+
5+
#include <riscv_vector.h>
6+
7+
// CHECK-LLVM: call riscv_vector_cc <vscale x 2 x i32> @_Z3baru15__rvv_int32m1_t
8+
vint32m1_t __attribute__((riscv_vector_cc)) bar(vint32m1_t input);
9+
vint32m1_t test_vector_cc_attr(vint32m1_t input, int32_t *base, size_t vl) {
10+
vint32m1_t val = __riscv_vle32_v_i32m1(base, vl);
11+
vint32m1_t ret = bar(input);
12+
__riscv_vse32_v_i32m1(base, val, vl);
13+
return ret;
14+
}
15+
16+
// CHECK-LLVM: call riscv_vector_cc <vscale x 2 x i32> @_Z3baru15__rvv_int32m1_t
17+
[[riscv::vector_cc]] vint32m1_t bar(vint32m1_t input);
18+
vint32m1_t test_vector_cc_attr2(vint32m1_t input, int32_t *base, size_t vl) {
19+
vint32m1_t val = __riscv_vle32_v_i32m1(base, vl);
20+
vint32m1_t ret = bar(input);
21+
__riscv_vse32_v_i32m1(base, val, vl);
22+
return ret;
23+
}
24+
25+
// CHECK-LLVM: call <vscale x 2 x i32> @_Z3bazu15__rvv_int32m1_t
26+
vint32m1_t baz(vint32m1_t input);
27+
vint32m1_t test_no_vector_cc_attr(vint32m1_t input, int32_t *base, size_t vl) {
28+
vint32m1_t val = __riscv_vle32_v_i32m1(base, vl);
29+
vint32m1_t ret = baz(input);
30+
__riscv_vse32_v_i32m1(base, val, vl);
31+
return ret;
32+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 %s -std=c23 -triple riscv64 -target-feature +v -verify
2+
3+
__attribute__((riscv_vector_cc)) int var; // expected-warning {{'riscv_vector_cc' only applies to function types; type here is 'int'}}
4+
5+
__attribute__((riscv_vector_cc)) void func();
6+
__attribute__((riscv_vector_cc(1))) void func_invalid(); // expected-error {{'riscv_vector_cc' attribute takes no arguments}}
7+
8+
void test_no_attribute(int); // expected-note {{previous declaration is here}}
9+
void __attribute__((riscv_vector_cc)) test_no_attribute(int x) { } // expected-error {{function declared 'riscv_vector_cc' here was previously declared without calling convention}}
10+
11+
[[riscv::vector_cc]] int var2; // expected-warning {{'vector_cc' only applies to function types; type here is 'int'}}
12+
13+
[[riscv::vector_cc]] void func2();
14+
[[riscv::vector_cc(1)]] void func_invalid2(); // expected-error {{'vector_cc' attribute takes no arguments}}
15+
16+
void test_no_attribute2(int); // expected-note {{previous declaration is here}}
17+
[[riscv::vector_cc]] void test_no_attribute2(int x) { } // expected-error {{function declared 'riscv_vector_cc' here was previously declared without calling convention}}

clang/test/CodeGen/RISCV/riscv-vector-callingconv.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,20 @@ void test_lambda() {
1616
__attribute__((riscv_vector_cc)) auto lambda = []() { // expected-warning {{'riscv_vector_cc' only applies to function types; type here is 'auto'}}
1717
};
1818
}
19+
20+
[[riscv::vector_cc]] int var2; // expected-warning {{'vector_cc' only applies to function types; type here is 'int'}}
21+
22+
[[riscv::vector_cc]] void func2();
23+
[[riscv::vector_cc(1)]] void func_invalid2(); // expected-error {{'vector_cc' attribute takes no arguments}}
24+
25+
void test_no_attribute2(int); // expected-note {{previous declaration is here}}
26+
[[riscv::vector_cc]] void test_no_attribute2(int x) { } // expected-error {{function declared 'riscv_vector_cc' here was previously declared without calling convention}}
27+
28+
class test_cc2 {
29+
[[riscv::vector_cc]] void member_func();
30+
};
31+
32+
void test_lambda2() {
33+
[[riscv::vector_cc]] auto lambda = []() { // expected-warning {{'vector_cc' only applies to function types; type here is 'auto'}}
34+
};
35+
}

0 commit comments

Comments
 (0)