Skip to content

Commit 05b5188

Browse files
authored
[Clang][RISCV] Support CSRs in clobbered registers of inline assembly (llvm#67646)
To match GCC's behaviors. Fixes llvm#67596
1 parent 366ffba commit 05b5188

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ using namespace clang;
2323
using namespace clang::targets;
2424

2525
ArrayRef<const char *> RISCVTargetInfo::getGCCRegNames() const {
26+
// clang-format off
2627
static const char *const GCCRegNames[] = {
2728
// Integer registers
2829
"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
@@ -40,7 +41,12 @@ ArrayRef<const char *> RISCVTargetInfo::getGCCRegNames() const {
4041
"v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
4142
"v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
4243
"v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
43-
"v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"};
44+
"v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
45+
46+
// CSRs
47+
"fflags", "frm", "vtype", "vl", "vxsat", "vxrm"
48+
};
49+
// clang-format on
4450
return llvm::ArrayRef(GCCRegNames);
4551
}
4652

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
2+
// REQUIRES: riscv-registered-target
3+
// RUN: %clang_cc1 -triple riscv32 -O2 -emit-llvm %s -o - \
4+
// RUN: | FileCheck %s
5+
// RUN: %clang_cc1 -triple riscv64 -O2 -emit-llvm %s -o - \
6+
// RUN: | FileCheck %s
7+
8+
// Test RISC-V specific clobbered registers in inline assembly.
9+
10+
// CHECK-LABEL: define {{.*}} void @test_fflags
11+
// CHECK: tail call void asm sideeffect "", "~{fflags}"()
12+
void test_fflags(void) {
13+
asm volatile ("" :::"fflags");
14+
}
15+
16+
// CHECK-LABEL: define {{.*}} void @test_frm
17+
// CHECK: tail call void asm sideeffect "", "~{frm}"()
18+
void test_frm(void) {
19+
asm volatile ("" :::"frm");
20+
}
21+
22+
// CHECK-LABEL: define {{.*}} void @test_vtype
23+
// CHECK: tail call void asm sideeffect "", "~{vtype}"()
24+
void test_vtype(void) {
25+
asm volatile ("" :::"vtype");
26+
}
27+
28+
// CHECK-LABEL: define {{.*}} void @test_vl
29+
// CHECK: tail call void asm sideeffect "", "~{vl}"()
30+
void test_vl(void) {
31+
asm volatile ("" :::"vl");
32+
}
33+
34+
// CHECK-LABEL: define {{.*}} void @test_vxsat
35+
// CHECK: tail call void asm sideeffect "", "~{vxsat}"()
36+
void test_vxsat(void) {
37+
asm volatile ("" :::"vxsat");
38+
}
39+
40+
// CHECK-LABEL: define {{.*}} void @test_vxrm
41+
// CHECK: tail call void asm sideeffect "", "~{vxrm}"()
42+
void test_vxrm(void) {
43+
asm volatile ("" :::"vxrm");
44+
}

0 commit comments

Comments
 (0)