Skip to content

Commit ed6ddff

Browse files
dong-miaolenary
andauthored
[RISCV] Add Smrnmi extension (#111668)
This commit has completed the Extension for Resumable Non Maskable Interrupts, adding four CRSs and one Trap-Return instruction. Specification link:["Smrnmi" Extension](https://github.com/riscv/riscv-isa-manual/blob/main/src/rnmi.adoc) --------- Co-authored-by: Sam Elliott <[email protected]>
1 parent b89f09f commit ed6ddff

File tree

11 files changed

+112
-0
lines changed

11 files changed

+112
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
// CHECK-NEXT: smcdeleg 1.0 'Smcdeleg' (Counter Delegation Machine Level)
121121
// CHECK-NEXT: smcsrind 1.0 'Smcsrind' (Indirect CSR Access Machine Level)
122122
// CHECK-NEXT: smepmp 1.0 'Smepmp' (Enhanced Physical Memory Protection)
123+
// CHECK-NEXT: smrnmi 1.0 'Smrnmi' (Resumable Non-Maskable Interrupts)
123124
// CHECK-NEXT: smstateen 1.0 'Smstateen' (Machine-mode view of the state-enable extension)
124125
// CHECK-NEXT: ssaia 1.0 'Ssaia' (Advanced Interrupt Architecture Supervisor Level)
125126
// CHECK-NEXT: ssccfg 1.0 'Ssccfg' (Counter Configuration Supervisor Level)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// CHECK-NOT: __riscv_smcdeleg {{.*$}}
3131
// CHECK-NOT: __riscv_smcsrind {{.*$}}
3232
// CHECK-NOT: __riscv_smepmp {{.*$}}
33+
// CHECK-NOT: __riscv_smrnmi {{.*$}}
3334
// CHECK-NOT: __riscv_smstateen {{.*$}}
3435
// CHECK-NOT: __riscv_ssaia {{.*$}}
3536
// CHECK-NOT: __riscv_ssccfg {{.*$}}
@@ -1449,6 +1450,14 @@
14491450
// RUN: -o - | FileCheck --check-prefix=CHECK-SMEPMP-EXT %s
14501451
// CHECK-SMEPMP-EXT: __riscv_smepmp 1000000{{$}}
14511452

1453+
// RUN: %clang --target=riscv32 \
1454+
// RUN: -march=rv32ismrnmi1p0 -E -dM %s \
1455+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMRNMI-EXT %s
1456+
// RUN: %clang --target=riscv64 \
1457+
// RUN: -march=rv64ismrnmi1p0 -E -dM %s \
1458+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMRNMI-EXT %s
1459+
// CHECK-SMRNMI-EXT: __riscv_smrnmi 1000000{{$}}
1460+
14521461
// RUN: %clang --target=riscv32-unknown-linux-gnu \
14531462
// RUN: -march=rv32izfa -E -dM %s \
14541463
// RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s

llvm/docs/RISCVUsage.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ on support follow.
129129
``Smcdeleg`` Supported
130130
``Smcsrind`` Supported
131131
``Smepmp`` Supported
132+
``Smrnmi`` Assembly Support
132133
``Smstateen`` Assembly Support
133134
``Ssaia`` Supported
134135
``Ssccfg`` Supported

llvm/lib/Target/RISCV/RISCVFeatures.td

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

934+
def FeatureStdExtSmrnmi
935+
: RISCVExtension<"smrnmi", 1, 0,
936+
"'Smrnmi' (Resumable Non-Maskable Interrupts)">;
937+
def HasStdExtSmrnmi : Predicate<"Subtarget->hasStdExtSmrnmi()">,
938+
AssemblerPredicate<(all_of FeatureStdExtSmrnmi),
939+
"'Smrnmi' (Resumable Non-Maskable Interrupts)">;
940+
934941
def FeatureStdExtSmcdeleg
935942
: RISCVExtension<"smcdeleg", 1, 0,
936943
"'Smcdeleg' (Counter Delegation Machine Level)">;

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,14 @@ def MRET : Priv<"mret", 0b0011000>, Sched<[]> {
815815
}
816816
} // isBarrier = 1, isReturn = 1, isTerminator = 1
817817

818+
let Predicates = [HasStdExtSmrnmi] in {
819+
def MNRET : Priv<"mnret", 0b0111000>, Sched<[]> {
820+
let rd = 0;
821+
let rs1 = 0;
822+
let rs2 = 0b00010;
823+
}
824+
}// Predicates = [HasStdExtSmrnmi]
825+
818826
def WFI : Priv<"wfi", 0b0001000>, Sched<[]> {
819827
let rd = 0;
820828
let rs1 = 0;

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
; RUN: llc -mtriple=riscv32 -mattr=+ssqosid %s -o - | FileCheck --check-prefix=RV32SSQOSID %s
119119
; RUN: llc -mtriple=riscv32 -mattr=+smcdeleg %s -o - | FileCheck --check-prefixes=CHECK,RV32SMCDELEG %s
120120
; RUN: llc -mtriple=riscv32 -mattr=+smepmp %s -o - | FileCheck --check-prefixes=CHECK,RV32SMEPMP %s
121+
; RUN: llc -mtriple=riscv32 -mattr=+smrnmi %s -o - | FileCheck --check-prefixes=CHECK,RV32SMRNMI %s
121122
; RUN: llc -mtriple=riscv32 -mattr=+zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZFBFMIN %s
122123
; RUN: llc -mtriple=riscv32 -mattr=+zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFMIN %s
123124
; RUN: llc -mtriple=riscv32 -mattr=+zvfbfwma %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFWMA %s
@@ -261,6 +262,7 @@
261262
; RUN: llc -mtriple=riscv64 -mattr=+ssqosid %s -o - | FileCheck --check-prefix=RV64SSQOSID %s
262263
; RUN: llc -mtriple=riscv64 -mattr=+smcdeleg %s -o - | FileCheck --check-prefixes=CHECK,RV64SMCDELEG %s
263264
; RUN: llc -mtriple=riscv64 -mattr=+smepmp %s -o - | FileCheck --check-prefixes=CHECK,RV64SMEPMP %s
265+
; RUN: llc -mtriple=riscv64 -mattr=+smrnmi %s -o - | FileCheck --check-prefixes=CHECK,RV64SMRNMI %s
264266
; RUN: llc -mtriple=riscv64 -mattr=+zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZFBFMIN %s
265267
; RUN: llc -mtriple=riscv64 -mattr=+zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVFBFMIN %s
266268
; RUN: llc -mtriple=riscv64 -mattr=+zvfbfwma %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVFBFWMA %s
@@ -410,6 +412,7 @@
410412
; RV32SSQOSID: .attribute 5, "rv32i2p1_ssqosid1p0"
411413
; RV32SMCDELEG: .attribute 5, "rv32i2p1_smcdeleg1p0"
412414
; RV32SMEPMP: .attribute 5, "rv32i2p1_smepmp1p0"
415+
; RV32SMRNMI: .attribute 5, "rv32i2p1_smrnmi1p0"
413416
; RV32ZFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin1p0"
414417
; RV32ZVFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfmin1p0_zvl32b1p0"
415418
; RV32ZVFBFWMA: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin1p0_zve32f1p0_zve32x1p0_zvfbfmin1p0_zvfbfwma1p0_zvl32b1p0"
@@ -551,6 +554,7 @@
551554
; RV64SSQOSID: .attribute 5, "rv64i2p1_ssqosid1p0"
552555
; RV64SMCDELEG: .attribute 5, "rv64i2p1_smcdeleg1p0"
553556
; RV64SMEPMP: .attribute 5, "rv64i2p1_smepmp1p0"
557+
; RV64SMRNMI: .attribute 5, "rv64i2p1_smrnmi1p0"
554558
; RV64ZFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin1p0"
555559
; RV64ZVFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfmin1p0_zvl32b1p0"
556560
; RV64ZVFBFWMA: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin1p0_zve32f1p0_zve32x1p0_zvfbfmin1p0_zvfbfwma1p0_zvl32b1p0"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@
327327
.attribute arch, "rv32i_smepmp1p0"
328328
# CHECK: attribute 5, "rv32i2p1_smepmp1p0"
329329

330+
.attribute arch, "rv32i_smrnmi1p0"
331+
# CHECK: attribute 5, "rv32i2p1_smrnmi1p0"
332+
330333
.attribute arch, "rv32i_ssccfg1p0"
331334
# CHECK: attribute 5, "rv32i2p1_ssccfg1p0"
332335

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,66 @@ csrrs t1, mhpmcounter31, zero
19131913
csrrs t2, 0xB1F, zero
19141914

19151915

1916+
######################################
1917+
# Machine Counter Setup
1918+
######################################
1919+
# mnscratch
1920+
# name
1921+
# CHECK-INST: csrrs t1, mnscratch, zero
1922+
# CHECK-ENC: encoding: [0x73,0x23,0x00,0x74]
1923+
# CHECK-INST-ALIAS: csrr t1, mnscratch
1924+
# uimm12
1925+
# CHECK-INST: csrrs t2, mnscratch, zero
1926+
# CHECK-ENC: encoding: [0xf3,0x23,0x00,0x74]
1927+
# CHECK-INST-ALIAS: csrr t2, mnscratch
1928+
# name
1929+
csrrs t1, mnscratch, zero
1930+
# uimm12
1931+
csrrs t2, 0x740, zero
1932+
1933+
# mnepc
1934+
# name
1935+
# CHECK-INST: csrrs t1, mnepc, zero
1936+
# CHECK-ENC: encoding: [0x73,0x23,0x10,0x74]
1937+
# CHECK-INST-ALIAS: csrr t1, mnepc
1938+
# uimm12
1939+
# CHECK-INST: csrrs t2, mnepc, zero
1940+
# CHECK-ENC: encoding: [0xf3,0x23,0x10,0x74]
1941+
# CHECK-INST-ALIAS: csrr t2, mnepc
1942+
# name
1943+
csrrs t1, mnepc, zero
1944+
# uimm12
1945+
csrrs t2, 0x741, zero
1946+
1947+
# mncause
1948+
# name
1949+
# CHECK-INST: csrrs t1, mncause, zero
1950+
# CHECK-ENC: encoding: [0x73,0x23,0x20,0x74]
1951+
# CHECK-INST-ALIAS: csrr t1, mncause
1952+
# uimm12
1953+
# CHECK-INST: csrrs t2, mncause, zero
1954+
# CHECK-ENC: encoding: [0xf3,0x23,0x20,0x74]
1955+
# CHECK-INST-ALIAS: csrr t2, mncause
1956+
# name
1957+
csrrs t1, mncause, zero
1958+
# uimm12
1959+
csrrs t2, 0x742, zero
1960+
1961+
# mnstatus
1962+
# name
1963+
# CHECK-INST: csrrs t1, mnstatus, zero
1964+
# CHECK-ENC: encoding: [0x73,0x23,0x40,0x74]
1965+
# CHECK-INST-ALIAS: csrr t1, mnstatus
1966+
# uimm12
1967+
# CHECK-INST: csrrs t2, mnstatus, zero
1968+
# CHECK-ENC: encoding: [0xf3,0x23,0x40,0x74]
1969+
# CHECK-INST-ALIAS: csrr t2, mnstatus
1970+
# name
1971+
csrrs t1, mnstatus, zero
1972+
# uimm12
1973+
csrrs t2, 0x744, zero
1974+
1975+
19161976
######################################
19171977
# Machine Counter Setup
19181978
######################################

llvm/test/MC/RISCV/smrnmi-invalid.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# RUN: not llvm-mc -triple riscv32 -mattr=+smrnmi < %s 2>&1 | FileCheck %s
2+
# RUN: not llvm-mc -triple riscv64 -mattr=+smrnmi < %s 2>&1 | FileCheck %s
3+
4+
mnret 0x10 # CHECK: :[[@LINE]]:7: error: invalid operand for instruction

llvm/test/MC/RISCV/smrnmi-valid.s

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+smrnmi -riscv-no-aliases -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
3+
# RUN: llvm-mc %s -triple=riscv64 -mattr=+smrnmi -riscv-no-aliases -show-encoding \
4+
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
5+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+smrnmi < %s \
6+
# RUN: | llvm-objdump --mattr=+smrnmi -M no-aliases -d - \
7+
# RUN: | FileCheck -check-prefix=CHECK-INST %s
8+
# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+smrnmi < %s \
9+
# RUN: | llvm-objdump --mattr=+smrnmi -M no-aliases -d - \
10+
# RUN: | FileCheck -check-prefix=CHECK-INST %s
11+
12+
# CHECK-INST: mnret
13+
# CHECK: encoding: [0x73,0x00,0x20,0x70]
14+
mnret

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ R"(All available -march extensions for RISC-V
10651065
smcdeleg 1.0
10661066
smcsrind 1.0
10671067
smepmp 1.0
1068+
smrnmi 1.0
10681069
smstateen 1.0
10691070
ssaia 1.0
10701071
ssccfg 1.0

0 commit comments

Comments
 (0)