Skip to content

Commit 307d91e

Browse files
authored
[RISCV] Add smcdeleg and ssccfg extensions (#95163)
Specification: https://github.com/riscv/riscv-isa-manual/blob/main/src/smcdeleg.adoc `Ssccfg` introduces one new CSR `scountinhibit`.
1 parent 4748b49 commit 307d91e

File tree

9 files changed

+67
-0
lines changed

9 files changed

+67
-0
lines changed

clang/test/Preprocessor/riscv-target-features.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
// CHECK-NOT: __riscv_shvstvala {{.*$}}
2828
// CHECK-NOT: __riscv_shvstvecd {{.*$}}
2929
// CHECK-NOT: __riscv_smaia {{.*$}}
30+
// CHECK-NOT: __riscv_smcdeleg {{.*$}}
3031
// CHECK-NOT: __riscv_smepmp {{.*$}}
3132
// CHECK-NOT: __riscv_smstateen {{.*$}}
3233
// CHECK-NOT: __riscv_ssaia {{.*$}}
34+
// CHECK-NOT: __riscv_ssccfg {{.*$}}
3335
// CHECK-NOT: __riscv_ssccptr {{.*$}}
3436
// CHECK-NOT: __riscv_sscofpmf {{.*$}}
3537
// CHECK-NOT: __riscv_sscounterenw {{.*$}}
@@ -362,6 +364,14 @@
362364
// RUN: -o - | FileCheck --check-prefix=CHECK-SHVSTVECD-EXT %s
363365
// CHECK-SHVSTVECD-EXT: __riscv_shvstvecd 1000000{{$}}
364366

367+
// RUN: %clang --target=riscv32-unknown-linux-gnu \
368+
// RUN: -march=rv32issccfg -E -dM %s \
369+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSCCFG-EXT %s
370+
// RUN: %clang --target=riscv64-unknown-linux-gnu \
371+
// RUN: -march=rv64issccfg -E -dM %s \
372+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSCCFG-EXT %s
373+
// CHECK-SSCCFG-EXT: __riscv_ssccfg 1000000{{$}}
374+
365375
// RUN: %clang --target=riscv32-unknown-linux-gnu \
366376
// RUN: -march=rv32issccptr -E -dM %s \
367377
// RUN: -o - | FileCheck --check-prefix=CHECK-SSCCPTR-EXT %s
@@ -1393,6 +1403,14 @@
13931403
// RUN: -o - | FileCheck --check-prefix=CHECK-SSAIA-EXT %s
13941404
// CHECK-SSAIA-EXT: __riscv_ssaia 1000000{{$}}
13951405

1406+
// RUN: %clang --target=riscv32 \
1407+
// RUN: -march=rv32ismcdeleg1p0 -E -dM %s \
1408+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMCDELEG-EXT %s
1409+
// RUN: %clang --target=riscv64 \
1410+
// RUN: -march=rv64ismcdeleg1p0 -E -dM %s \
1411+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMCDELEG-EXT %s
1412+
// CHECK-SMCDELEG-EXT: __riscv_smcdeleg 1000000{{$}}
1413+
13961414
// RUN: %clang --target=riscv32 \
13971415
// RUN: -march=rv32ismepmp1p0 -E -dM %s \
13981416
// RUN: -o - | FileCheck --check-prefix=CHECK-SMEPMP-EXT %s

llvm/docs/RISCVUsage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ on support follow.
9999
``Shvstvala`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__)
100100
``Shvstvecd`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__)
101101
``Smaia`` Supported
102+
``Smcdeleg`` Supported
102103
``Smepmp`` Supported
103104
``Smstateen`` Assembly Support
104105
``Ssaia`` Supported
106+
``Ssccfg`` Supported
105107
``Ssccptr`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__)
106108
``Sscofpmf`` Assembly Support
107109
``Sscounterenw`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__)

llvm/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Changes to the RISC-V Backend
157157
* Processors that enable post reg-alloc scheduling (PostMachineScheduler) by default should use the `UsePostRAScheduler` subtarget feature. Setting `PostRAScheduler = 1` in the scheduler model will have no effect on the enabling of the PostMachineScheduler.
158158
* Zabha is no longer experimental.
159159
* B (the collection of the Zba, Zbb, Zbs extensions) is supported.
160+
* Added smcdeleg and ssccfg extensions to -march.
160161

161162
Changes to the WebAssembly Backend
162163
----------------------------------

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,13 @@ def FeatureStdExtSmepmp
859859
: RISCVExtension<"smepmp", 1, 0,
860860
"'Smepmp' (Enhanced Physical Memory Protection)">;
861861

862+
def FeatureStdExtSmcdeleg
863+
: RISCVExtension<"smcdeleg", 1, 0,
864+
"'Smcdeleg' (Counter Delegation Machine Level)">;
865+
def FeatureStdExtSsccfg
866+
: RISCVExtension<"ssccfg", 1, 0,
867+
"'Ssccfg' (Counter Configuration Supervisor Level)">;
868+
862869
def FeatureStdExtSsccptr
863870
: RISCVExtension<"ssccptr", 1, 0,
864871
"'Ssccptr' (Main memory supports page table reads)">;

llvm/lib/Target/RISCV/RISCVSystemOperands.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ foreach i = 3...31 in {
310310
def : SysReg<"mhpmevent"#i#"h", !add(0x723, !sub(i, 3))>;
311311
}
312312

313+
//===----------------------------------------------------------------------===//
314+
// Supervisor Counter Setup
315+
//===----------------------------------------------------------------------===//
316+
def : SysReg<"scountinhibit", 0x120>;
317+
313318
//===----------------------------------------------------------------------===//
314319
// Debug/ Trace Registers (shared with Debug Mode)
315320
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
; RUN: llc -mtriple=riscv32 -mattr=+shcounterenw %s -o - | FileCheck --check-prefixes=CHECK,RV32SHCOUNTERENW %s
4343
; RUN: llc -mtriple=riscv32 -mattr=+shgatpa %s -o - | FileCheck --check-prefixes=CHECK,RV32SHGATPA %s
4444
; RUN: llc -mtriple=riscv32 -mattr=+shvsatpa %s -o - | FileCheck --check-prefixes=CHECK,RV32SHVSATPA %s
45+
; RUN: llc -mtriple=riscv32 -mattr=+ssccfg %s -o - | FileCheck --check-prefixes=CHECK,RV32SSCCFG %s
4546
; RUN: llc -mtriple=riscv32 -mattr=+ssccptr %s -o - | FileCheck --check-prefixes=CHECK,RV32SSCCPTR %s
4647
; RUN: llc -mtriple=riscv32 -mattr=+sscofpmf %s -o - | FileCheck --check-prefixes=CHECK,RV32SSCOFPMF %s
4748
; RUN: llc -mtriple=riscv32 -mattr=+sscounterenw %s -o - | FileCheck --check-prefixes=CHECK,RV32SSCOUNTERENW %s
@@ -111,6 +112,7 @@
111112
; RUN: llc -mtriple=riscv32 -mattr=+zcmop %s -o - | FileCheck --check-prefix=RV32ZCMOP %s
112113
; RUN: llc -mtriple=riscv32 -mattr=+smaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SMAIA %s
113114
; RUN: llc -mtriple=riscv32 -mattr=+ssaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SSAIA %s
115+
; RUN: llc -mtriple=riscv32 -mattr=+smcdeleg %s -o - | FileCheck --check-prefixes=CHECK,RV32SMCDELEG %s
114116
; RUN: llc -mtriple=riscv32 -mattr=+smepmp %s -o - | FileCheck --check-prefixes=CHECK,RV32SMEPMP %s
115117
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZFBFMIN %s
116118
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFMIN %s
@@ -170,6 +172,7 @@
170172
; RUN: llc -mtriple=riscv64 -mattr=+shcounterenw %s -o - | FileCheck --check-prefixes=CHECK,RV64SHCOUNTERENW %s
171173
; RUN: llc -mtriple=riscv64 -mattr=+shgatpa %s -o - | FileCheck --check-prefixes=CHECK,RV64SHGATPA %s
172174
; RUN: llc -mtriple=riscv64 -mattr=+shvsatpa %s -o - | FileCheck --check-prefixes=CHECK,RV64SHVSATPA %s
175+
; RUN: llc -mtriple=riscv64 -mattr=+ssccfg %s -o - | FileCheck --check-prefixes=CHECK,RV64SSCCFG %s
173176
; RUN: llc -mtriple=riscv64 -mattr=+ssccptr %s -o - | FileCheck --check-prefixes=CHECK,RV64SSCCPTR %s
174177
; RUN: llc -mtriple=riscv64 -mattr=+sscofpmf %s -o - | FileCheck --check-prefixes=CHECK,RV64SSCOFPMF %s
175178
; RUN: llc -mtriple=riscv64 -mattr=+sscounterenw %s -o - | FileCheck --check-prefixes=CHECK,RV64SSCOUNTERENW %s
@@ -245,6 +248,7 @@
245248
; RUN: llc -mtriple=riscv64 -mattr=+zcmop %s -o - | FileCheck --check-prefix=RV64ZCMOP %s
246249
; RUN: llc -mtriple=riscv64 -mattr=+smaia %s -o - | FileCheck --check-prefixes=CHECK,RV64SMAIA %s
247250
; RUN: llc -mtriple=riscv64 -mattr=+ssaia %s -o - | FileCheck --check-prefixes=CHECK,RV64SSAIA %s
251+
; RUN: llc -mtriple=riscv64 -mattr=+smcdeleg %s -o - | FileCheck --check-prefixes=CHECK,RV64SMCDELEG %s
248252
; RUN: llc -mtriple=riscv64 -mattr=+smepmp %s -o - | FileCheck --check-prefixes=CHECK,RV64SMEPMP %s
249253
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZFBFMIN %s
250254
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVFBFMIN %s
@@ -316,6 +320,7 @@
316320
; RV32SHCOUNTERENW: .attribute 5, "rv32i2p1_shcounterenw1p0"
317321
; RV32SHGATPA: .attribute 5, "rv32i2p1_shgatpa1p0"
318322
; RV32SHVSATPA: .attribute 5, "rv32i2p1_shvsatpa1p0"
323+
; RV32SSCCFG: .attribute 5, "rv32i2p1_ssccfg1p0"
319324
; RV32SSCCPTR: .attribute 5, "rv32i2p1_ssccptr1p0"
320325
; RV32SSCOFPMF: .attribute 5, "rv32i2p1_sscofpmf1p0"
321326
; RV32SSCOUNTERENW: .attribute 5, "rv32i2p1_sscounterenw1p0"
@@ -385,6 +390,7 @@
385390
; RV32ZCMOP: .attribute 5, "rv32i2p1_zca1p0_zcmop1p0"
386391
; RV32SMAIA: .attribute 5, "rv32i2p1_smaia1p0"
387392
; RV32SSAIA: .attribute 5, "rv32i2p1_ssaia1p0"
393+
; RV32SMCDELEG: .attribute 5, "rv32i2p1_smcdeleg1p0"
388394
; RV32SMEPMP: .attribute 5, "rv32i2p1_smepmp1p0"
389395
; RV32ZFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin1p0"
390396
; RV32ZVFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfmin1p0_zvl32b1p0"
@@ -447,6 +453,7 @@
447453
; RV64SHCOUNTERENW: .attribute 5, "rv64i2p1_shcounterenw1p0"
448454
; RV64SHGATPA: .attribute 5, "rv64i2p1_shgatpa1p0"
449455
; RV64SHVSATPA: .attribute 5, "rv64i2p1_shvsatpa1p0"
456+
; RV64SSCCFG: .attribute 5, "rv64i2p1_ssccfg1p0"
450457
; RV64SSCCPTR: .attribute 5, "rv64i2p1_ssccptr1p0"
451458
; RV64SSCOFPMF: .attribute 5, "rv64i2p1_sscofpmf1p0"
452459
; RV64SSCOUNTERENW: .attribute 5, "rv64i2p1_sscounterenw1p0"
@@ -518,6 +525,7 @@
518525
; RV64ZCMOP: .attribute 5, "rv64i2p1_zca1p0_zcmop1p0"
519526
; RV64SMAIA: .attribute 5, "rv64i2p1_smaia1p0"
520527
; RV64SSAIA: .attribute 5, "rv64i2p1_ssaia1p0"
528+
; RV64SMCDELEG: .attribute 5, "rv64i2p1_smcdeleg1p0"
521529
; RV64SMEPMP: .attribute 5, "rv64i2p1_smepmp1p0"
522530
; RV64ZFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin1p0"
523531
; RV64ZVFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfmin1p0_zvl32b1p0"

llvm/test/MC/RISCV/attribute-arch.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,15 @@
315315
.attribute arch, "rv32i_ssaia1p0"
316316
# CHECK: attribute 5, "rv32i2p1_ssaia1p0"
317317

318+
.attribute arch, "rv32i_smcdeleg1p0"
319+
# CHECK: attribute 5, "rv32i2p1_smcdeleg1p0"
320+
318321
.attribute arch, "rv32i_smepmp1p0"
319322
# CHECK: attribute 5, "rv32i2p1_smepmp1p0"
320323

324+
.attribute arch, "rv32i_ssccfg1p0"
325+
# CHECK: attribute 5, "rv32i2p1_ssccfg1p0"
326+
321327
.attribute arch, "rv32i_ssccptr1p0"
322328
# CHECK: attribute 5, "rv32i2p1_ssccptr1p0"
323329

llvm/test/MC/RISCV/supervisor-csr-names.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,21 @@ csrrs t2, 0x15C, zero
369369
csrrs t1, stopi, zero
370370
# uimm12
371371
csrrs t2, 0xDB0, zero
372+
373+
#########################################
374+
# Counter Configuration (Ssccfg)
375+
#########################################
376+
377+
# scountinhibit
378+
# name
379+
# CHECK-INST: csrrs t1, scountinhibit, zero
380+
# CHECK-ENC: encoding: [0x73,0x23,0x00,0x12]
381+
# CHECK-INST-ALIAS: csrr t1, scountinhibit
382+
# uimm12
383+
# CHECK-INST: csrrs t2, scountinhibit, zero
384+
# CHECK-ENC: encoding: [0xf3,0x23,0x00,0x12]
385+
# CHECK-INST-ALIAS: csrr t2, scountinhibit
386+
# name
387+
csrrs t1, scountinhibit, zero
388+
# uimm12
389+
csrrs t2, 0x120, zero

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,11 @@ R"(All available -march extensions for RISC-V
10091009
shvstvala 1.0
10101010
shvstvecd 1.0
10111011
smaia 1.0
1012+
smcdeleg 1.0
10121013
smepmp 1.0
10131014
smstateen 1.0
10141015
ssaia 1.0
1016+
ssccfg 1.0
10151017
ssccptr 1.0
10161018
sscofpmf 1.0
10171019
sscounterenw 1.0

0 commit comments

Comments
 (0)