Skip to content

Commit 9e26c79

Browse files
authored
[RISCV] Add smcntrpmf extension (#136556)
spec: https://github.com/riscvarchive/riscv-smcntrpmf
1 parent 0014b49 commit 9e26c79

File tree

11 files changed

+81
-0
lines changed

11 files changed

+81
-0
lines changed

clang/test/Driver/print-supported-extensions-riscv.c

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
// CHECK-NEXT: shvstvecd 1.0 'Shvstvecd' (vstvec supports Direct mode)
124124
// CHECK-NEXT: smaia 1.0 'Smaia' (Advanced Interrupt Architecture Machine Level)
125125
// CHECK-NEXT: smcdeleg 1.0 'Smcdeleg' (Counter Delegation Machine Level)
126+
// CHECK-NEXT: smcntrpmf 1.0 'Smcntrpmf' (Cycle and Instret Privilege Mode Filtering)
126127
// CHECK-NEXT: smcsrind 1.0 'Smcsrind' (Indirect CSR Access Machine Level)
127128
// CHECK-NEXT: smdbltrp 1.0 'Smdbltrp' (Double Trap Machine Level)
128129
// CHECK-NEXT: smepmp 1.0 'Smepmp' (Enhanced Physical Memory Protection)

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

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// CHECK-NOT: __riscv_shvstvecd {{.*$}}
3030
// CHECK-NOT: __riscv_smaia {{.*$}}
3131
// CHECK-NOT: __riscv_smcdeleg {{.*$}}
32+
// CHECK-NOT: __riscv_smcntrpmf {{.*$}}
3233
// CHECK-NOT: __riscv_smcsrind {{.*$}}
3334
// CHECK-NOT: __riscv_smdbltrp {{.*$}}
3435
// CHECK-NOT: __riscv_smepmp {{.*$}}
@@ -1445,6 +1446,14 @@
14451446
// RUN: -o - | FileCheck --check-prefix=CHECK-SSAIA-EXT %s
14461447
// CHECK-SSAIA-EXT: __riscv_ssaia 1000000{{$}}
14471448

1449+
// RUN: %clang --target=riscv32 \
1450+
// RUN: -march=rv32ismcntrpmf1p0 -E -dM %s \
1451+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMCNTRPMF-EXT %s
1452+
// RUN: %clang --target=riscv64 \
1453+
// RUN: -march=rv64ismcntrpmf1p0 -E -dM %s \
1454+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMCNTRPMF-EXT %s
1455+
// CHECK-SMCNTRPMF-EXT: __riscv_smcntrpmf 1000000{{$}}
1456+
14481457
// RUN: %clang --target=riscv32 \
14491458
// RUN: -march=rv32ismcsrind1p0 -E -dM %s \
14501459
// RUN: -o - | FileCheck --check-prefix=CHECK-SMCSRIND-EXT %s

llvm/docs/RISCVUsage.rst

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ on support follow.
128128
``Shvstvecd`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__)
129129
``Smaia`` Supported
130130
``Smcdeleg`` Supported
131+
``Smcntrpmf`` Supported
131132
``Smcsrind`` Supported
132133
``Smdbltrp`` Supported
133134
``Smepmp`` Supported

llvm/lib/Target/RISCV/RISCVFeatures.td

+3
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@ def FeatureStdExtSsaia
899899
: RISCVExtension<1, 0,
900900
"Advanced Interrupt Architecture Supervisor Level">;
901901

902+
def FeatureStdExtSmcntrpmf
903+
: RISCVExtension<1, 0, "Cycle and Instret Privilege Mode Filtering">;
904+
902905
def FeatureStdExtSmcsrind
903906
: RISCVExtension<1, 0, "Indirect CSR Access Machine Level">;
904907
def FeatureStdExtSscsrind

llvm/lib/Target/RISCV/RISCVSystemOperands.td

+10
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,16 @@ def : SysReg<"sctrdepth", 0x15f>;
482482
def : SysReg<"vsctrctl", 0x24e>;
483483
def : SysReg<"mctrctl", 0x34e>;
484484

485+
//===-----------------------------------------------
486+
// Cycle and Instret Privilege Mode Filtering (Smcntrpmf)
487+
//===-----------------------------------------------
488+
def : SysReg<"mcyclecfg", 0x321>;
489+
def : SysReg<"minstretcfg", 0x322>;
490+
let isRV32Only = 1 in {
491+
def : SysReg<"mcyclecfgh", 0x721>;
492+
def : SysReg<"minstretcfgh", 0x722>;
493+
} // isRV32Only
494+
485495
//===-----------------------------------------------
486496
// Vendor CSRs
487497
//===-----------------------------------------------

llvm/test/CodeGen/RISCV/attributes.ll

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
; RUN: llc -mtriple=riscv32 -mattr=+ssdbltrp %s -o - | FileCheck --check-prefixes=CHECK,RV32SSDBLTRP %s
148148
; RUN: llc -mtriple=riscv32 -mattr=+ssqosid %s -o - | FileCheck --check-prefix=RV32SSQOSID %s
149149
; RUN: llc -mtriple=riscv32 -mattr=+smcdeleg %s -o - | FileCheck --check-prefixes=CHECK,RV32SMCDELEG %s
150+
; RUN: llc -mtriple=riscv32 -mattr=+smcntrpmf %s -o - | FileCheck --check-prefixes=CHECK,RV32SMCNTRPMF %s
150151
; RUN: llc -mtriple=riscv32 -mattr=+smepmp %s -o - | FileCheck --check-prefixes=CHECK,RV32SMEPMP %s
151152
; RUN: llc -mtriple=riscv32 -mattr=+smrnmi %s -o - | FileCheck --check-prefixes=CHECK,RV32SMRNMI %s
152153
; RUN: llc -mtriple=riscv32 -mattr=+zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZFBFMIN %s
@@ -301,6 +302,7 @@
301302
; RUN: llc -mtriple=riscv64 -mattr=+ssdbltrp %s -o - | FileCheck --check-prefixes=CHECK,RV64SSDBLTRP %s
302303
; RUN: llc -mtriple=riscv64 -mattr=+ssqosid %s -o - | FileCheck --check-prefix=RV64SSQOSID %s
303304
; RUN: llc -mtriple=riscv64 -mattr=+smcdeleg %s -o - | FileCheck --check-prefixes=CHECK,RV64SMCDELEG %s
305+
; RUN: llc -mtriple=riscv64 -mattr=+smcntrpmf %s -o - | FileCheck --check-prefixes=CHECK,RV64SMCNTRPMF %s
304306
; RUN: llc -mtriple=riscv64 -mattr=+smepmp %s -o - | FileCheck --check-prefixes=CHECK,RV64SMEPMP %s
305307
; RUN: llc -mtriple=riscv64 -mattr=+smrnmi %s -o - | FileCheck --check-prefixes=CHECK,RV64SMRNMI %s
306308
; RUN: llc -mtriple=riscv64 -mattr=+zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZFBFMIN %s
@@ -485,6 +487,7 @@
485487
; RV32SSDBLTRP: .attribute 5, "rv32i2p1_ssdbltrp1p0"
486488
; RV32SSQOSID: .attribute 5, "rv32i2p1_ssqosid1p0"
487489
; RV32SMCDELEG: .attribute 5, "rv32i2p1_smcdeleg1p0"
490+
; RV32SMCNTRPMF: .attribute 5, "rv32i2p1_smcntrpmf1p0"
488491
; RV32SMEPMP: .attribute 5, "rv32i2p1_smepmp1p0"
489492
; RV32SMRNMI: .attribute 5, "rv32i2p1_smrnmi1p0"
490493
; RV32ZFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin1p0"
@@ -636,6 +639,7 @@
636639
; RV64SSDBLTRP: .attribute 5, "rv64i2p1_ssdbltrp1p0"
637640
; RV64SSQOSID: .attribute 5, "rv64i2p1_ssqosid1p0"
638641
; RV64SMCDELEG: .attribute 5, "rv64i2p1_smcdeleg1p0"
642+
; RV64SMCNTRPMF: .attribute 5, "rv64i2p1_smcntrpmf1p0"
639643
; RV64SMEPMP: .attribute 5, "rv64i2p1_smepmp1p0"
640644
; RV64SMRNMI: .attribute 5, "rv64i2p1_smrnmi1p0"
641645
; RV64ZFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin1p0"

llvm/test/CodeGen/RISCV/features-info.ll

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
; CHECK-NEXT: sifive7 - SiFive 7-Series processors.
130130
; CHECK-NEXT: smaia - 'Smaia' (Advanced Interrupt Architecture Machine Level).
131131
; CHECK-NEXT: smcdeleg - 'Smcdeleg' (Counter Delegation Machine Level).
132+
; CHECK-NEXT: smcntrpmf - 'Smcntrpmf' (Cycle and Instret Privilege Mode Filtering).
132133
; CHECK-NEXT: smcsrind - 'Smcsrind' (Indirect CSR Access Machine Level).
133134
; CHECK-NEXT: smdbltrp - 'Smdbltrp' (Double Trap Machine Level).
134135
; CHECK-NEXT: smepmp - 'Smepmp' (Enhanced Physical Memory Protection).

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

+3
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@
336336
.attribute arch, "rv32i_smcdeleg1p0"
337337
# CHECK: attribute 5, "rv32i2p1_smcdeleg1p0"
338338

339+
.attribute arch, "rv32i_smcntrpmf1p0"
340+
# CHECK: attribute 5, "rv32i2p1_smcntrpmf1p0"
341+
339342
.attribute arch, "rv32i_smepmp1p0"
340343
# CHECK: attribute 5, "rv32i2p1_smepmp1p0"
341344

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

+24
Original file line numberDiff line numberDiff line change
@@ -2733,3 +2733,27 @@ csrrs t2, 0x742, zero
27332733
csrrs t1, mnstatus, zero
27342734
# uimm12
27352735
csrrs t2, 0x744, zero
2736+
2737+
# mcyclecfg
2738+
# name
2739+
# CHECK-INST: csrrs t1, mcyclecfg, zero
2740+
# CHECK-ENC: encoding: [0x73,0x23,0x10,0x32]
2741+
# CHECK-INST-ALIAS: csrr t1, mcyclecfg
2742+
csrrs t1, mcyclecfg, zero
2743+
# uimm12
2744+
# CHECK-INST: csrrs t2, mcyclecfg, zero
2745+
# CHECK-ENC: encoding: [0xf3,0x23,0x10,0x32]
2746+
# CHECK-INST-ALIAS: csrr t2, mcyclecfg
2747+
csrrs t2, 0x321, zero
2748+
2749+
# minstretcfg
2750+
# name
2751+
# CHECK-INST: csrrs t1, minstretcfg, zero
2752+
# CHECK-ENC: encoding: [0x73,0x23,0x20,0x32]
2753+
# CHECK-INST-ALIAS: csrr t1, minstretcfg
2754+
csrrs t1, minstretcfg, zero
2755+
# uimm12
2756+
# CHECK-INST: csrrs t2, minstretcfg, zero
2757+
# CHECK-ENC: encoding: [0xf3,0x23,0x20,0x32]
2758+
# CHECK-INST-ALIAS: csrr t2, minstretcfg
2759+
csrrs t2, 0x322, zero

llvm/test/MC/RISCV/rv32-machine-csr-names.s

+24
Original file line numberDiff line numberDiff line change
@@ -1163,3 +1163,27 @@ csrrs t2, 0x319, zero
11631163
csrrs t1, miph, zero
11641164
# uimm12
11651165
csrrs t2, 0x354, zero
1166+
1167+
# mcyclecfgh
1168+
# name
1169+
# CHECK-INST: csrrs t1, mcyclecfgh, zero
1170+
# CHECK-ENC: encoding: [0x73,0x23,0x10,0x72]
1171+
# CHECK-INST-ALIAS: csrr t1, mcyclecfgh
1172+
csrrs t1, mcyclecfgh, zero
1173+
# uimm12
1174+
# CHECK-INST: csrrs t2, mcyclecfgh, zero
1175+
# CHECK-ENC: encoding: [0xf3,0x23,0x10,0x72]
1176+
# CHECK-INST-ALIAS: csrr t2, mcyclecfgh
1177+
csrrs t2, 0x721, zero
1178+
1179+
# minstretcfgh
1180+
# name
1181+
# CHECK-INST: csrrs t1, minstretcfgh, zero
1182+
# CHECK-ENC: encoding: [0x73,0x23,0x20,0x72]
1183+
# CHECK-INST-ALIAS: csrr t1, minstretcfgh
1184+
csrrs t1, minstretcfgh, zero
1185+
# uimm12
1186+
# CHECK-INST: csrrs t2, minstretcfgh, zero
1187+
# CHECK-ENC: encoding: [0xf3,0x23,0x20,0x72]
1188+
# CHECK-INST-ALIAS: csrr t2, minstretcfgh
1189+
csrrs t2, 0x722, zero

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ R"(All available -march extensions for RISC-V
10861086
shvstvecd 1.0
10871087
smaia 1.0
10881088
smcdeleg 1.0
1089+
smcntrpmf 1.0
10891090
smcsrind 1.0
10901091
smdbltrp 1.0
10911092
smepmp 1.0

0 commit comments

Comments
 (0)