Skip to content

Commit 2fae5bd

Browse files
authored
[RISCV] Add support of Sdext,Sdtrig extentions (#120936)
`Sdext` and `Sdtrig` are RISC-V extensions related to debugging. The full specification can be found at https://github.com/riscv/riscv-debug-spec/releases/download/1.0.0-rc4/riscv-debug-specification.pdf
1 parent 2582568 commit 2fae5bd

File tree

11 files changed

+87
-0
lines changed

11 files changed

+87
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@
185185
// CHECK-NEXT: zalasr 0.1 'Zalasr' (Load-Acquire and Store-Release Instructions)
186186
// CHECK-NEXT: zvbc32e 0.7 'Zvbc32e' (Vector Carryless Multiplication with 32-bits elements)
187187
// CHECK-NEXT: zvkgs 0.7 'Zvkgs' (Vector-Scalar GCM instructions for Cryptography)
188+
// CHECK-NEXT: sdext 1.0 'Sdext' (External debugger)
189+
// CHECK-NEXT: sdtrig 1.0 'Sdtrig' (Debugger triggers)
188190
// CHECK-NEXT: smctr 1.0 'Smctr' (Control Transfer Records Machine Level)
189191
// CHECK-NEXT: ssctr 1.0 'Ssctr' (Control Transfer Records Supervisor Level)
190192
// CHECK-NEXT: svukte 0.3 'Svukte' (Address-Independent Latency of User-Mode Faults to Supervisor Addresses)

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@
182182

183183
// Experimental extensions
184184

185+
// CHECK-NOT: __riscv_sdext{{.*$}}
186+
// CHECK-NOT: __riscv_sdtrig{{.*$}}
185187
// CHECK-NOT: __riscv_smctr{{.*$}}
186188
// CHECK-NOT: __riscv_smmpm{{.*$}}
187189
// CHECK-NOT: __riscv_smnpm{{.*$}}
@@ -1795,6 +1797,22 @@
17951797
// RUN: -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
17961798
// CHECK-SUPM-EXT: __riscv_supm 1000000{{$}}
17971799

1800+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1801+
// RUN: -march=rv32i_sdext1p0 -E -dM %s \
1802+
// RUN: -o - | FileCheck --check-prefix=CHECK-SDEXT-EXT %s
1803+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1804+
// RUN: -march=rv64i_sdext1p0 -E -dM %s \
1805+
// RUN: -o - | FileCheck --check-prefix=CHECK-SDEXT-EXT %s
1806+
// CHECK-SDEXT-EXT: __riscv_sdext 1000000{{$}}
1807+
1808+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1809+
// RUN: -march=rv32i_sdtrig1p0 -E -dM %s \
1810+
// RUN: -o - | FileCheck --check-prefix=CHECK-SDTRIG-EXT %s
1811+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1812+
// RUN: -march=rv64i_sdtrig1p0 -E -dM %s \
1813+
// RUN: -o - | FileCheck --check-prefix=CHECK-SDTRIG-EXT %s
1814+
// CHECK-SDTRIG-EXT: __riscv_sdtrig 1000000{{$}}
1815+
17981816
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
17991817
// RUN: -march=rv32i_smctr1p0 -E -dM %s \
18001818
// RUN: -o - | FileCheck --check-prefix=CHECK-SMCTR-EXT %s

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ The primary goal of experimental support is to assist in the process of ratifica
326326
``experimental-zvbc32e``, ``experimental-zvkgs``
327327
LLVM implements the `0.7 release specification <https://github.com/user-attachments/files/16450464/riscv-crypto-spec-vector-extra_v0.0.7.pdf>`__.
328328

329+
``experimental-sdext``, ``experimental-sdtrig``
330+
LLVM implements the `1.0-rc4 specification <https://github.com/riscv/riscv-debug-spec/releases/download/1.0.0-rc4/riscv-debug-specification.pdf>`__.
331+
329332
``experimental-smctr``, ``experimental-ssctr``
330333
LLVM implements the `1.0-rc3 specification <https://github.com/riscv/riscv-control-transfer-records/releases/tag/v1.0_rc3>`__.
331334

llvm/docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ Changes to the RISC-V Backend
232232
extension.
233233
* Adds experimental assembler support for the Qualcomm uC 'Xqcicli` (Conditional Load Immediate)
234234
extension.
235+
* Added ``Sdext`` and ``Sdtrig`` extensions.
235236

236237
Changes to the WebAssembly Backend
237238
----------------------------------

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,10 @@ def HasStdExtH : Predicate<"Subtarget->hasStdExtH()">,
844844

845845
// Supervisor extensions
846846

847+
def FeatureStdExtSdext : RISCVExperimentalExtension<1, 0, "External debugger">;
848+
849+
def FeatureStdExtSdtrig : RISCVExperimentalExtension<1, 0, "Debugger triggers">;
850+
847851
def FeatureStdExtShgatpa
848852
: RISCVExtension<1, 0,
849853
"SvNNx4 mode supported for all modes supported by satp, as well as Bare">;

llvm/lib/Target/RISCV/RISCVSystemOperands.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ def : SysReg<"tselect", 0x7A0>;
323323
def : SysReg<"tdata1", 0x7A1>;
324324
def : SysReg<"tdata2", 0x7A2>;
325325
def : SysReg<"tdata3", 0x7A3>;
326+
def : SysReg<"tinfo", 0x7A4>;
327+
def : SysReg<"tcontrol", 0x7A5>;
326328
def : SysReg<"mcontext", 0x7A8>;
329+
def : SysReg<"mscontext", 0x7AA>;
327330

328331
//===----------------------------------------------------------------------===//
329332
// Debug Mode Registers

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@
296296
; RUN: llc -mtriple=riscv64 -mattr=+supm %s -o - | FileCheck --check-prefix=RV64SUPM %s
297297
; RUN: llc -mtriple=riscv64 -mattr=+experimental-smctr %s -o - | FileCheck --check-prefix=RV64SMCTR %s
298298
; RUN: llc -mtriple=riscv64 -mattr=+experimental-ssctr %s -o - | FileCheck --check-prefix=RV64SSCTR %s
299+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-sdext %s -o - | FileCheck --check-prefix=RV64SDEXT %s
300+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-sdtrig %s -o - | FileCheck --check-prefix=RV64SDTRIG %s
299301

300302
; Tests for profile features.
301303
; RUN: llc -mtriple=riscv32 -mattr=+rvi20u32 %s -o - | FileCheck --check-prefix=RVI20U32 %s
@@ -605,6 +607,8 @@
605607
; RV64SUPM: .attribute 5, "rv64i2p1_supm1p0"
606608
; RV64SMCTR: .attribute 5, "rv64i2p1_smctr1p0_sscsrind1p0"
607609
; RV64SSCTR: .attribute 5, "rv64i2p1_sscsrind1p0_ssctr1p0"
610+
; RV64SDEXT: .attribute 5, "rv64i2p1_sdext1p0"
611+
; RV64SDTRIG: .attribute 5, "rv64i2p1_sdtrig1p0"
608612

609613
; RVI20U32: .attribute 5, "rv32i2p1"
610614
; RVI20U64: .attribute 5, "rv64i2p1"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
; CHECK: e - 'E' (Embedded Instruction Set with 16 GPRs).
1616
; CHECK: experimental - Experimental intrinsics.
1717
; CHECK: experimental-rvm23u32 - RISC-V experimental-rvm23u32 profile.
18+
; CHECK: experimental-sdext - 'Sdext' (External debugger).
19+
; CHECK: experimental-sdtrig - 'Sdtrig' (Debugger triggers).
1820
; CHECK: experimental-smctr - 'Smctr' (Control Transfer Records Machine Level).
1921
; CHECK: experimental-ssctr - 'Ssctr' (Control Transfer Records Supervisor Level).
2022
; CHECK: experimental-svukte - 'Svukte' (Address-Independent Latency of User-Mode Faults to Supervisor Addresses).

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,9 @@
467467

468468
.attribute arch, "rv32i_ssctr1p0"
469469
# CHECK: attribute 5, "rv32i2p1_sscsrind1p0_ssctr1p0"
470+
471+
.attribute arch, "rv32i_sdext1p0"
472+
# CHECK: attribute 5, "rv32i2p1_sdext1p0"
473+
474+
.attribute arch, "rv32i_sdtrig1p0"
475+
# CHECK: attribute 5, "rv32i2p1_sdtrig1p0"

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,34 @@ csrrs t1, tdata3, zero
14191419
# uimm12
14201420
csrrs t2, 0x7A3, zero
14211421

1422+
# tinfo
1423+
# name
1424+
# CHECK-INST: csrrs t1, tinfo, zero
1425+
# CHECK-ENC: encoding: [0x73,0x23,0x40,0x7a]
1426+
# CHECK-INST-ALIAS: csrr t1, tinfo
1427+
# uimm12
1428+
# CHECK-INST: csrrs t2, tinfo, zero
1429+
# CHECK-ENC: encoding: [0xf3,0x23,0x40,0x7a]
1430+
# CHECK-INST-ALIAS: csrr t2, tinfo
1431+
# name
1432+
csrrs t1, tinfo, zero
1433+
# uimm12
1434+
csrrs t2, 0x7A4, zero
1435+
1436+
# tcontrol
1437+
# name
1438+
# CHECK-INST: csrrs t1, tcontrol, zero
1439+
# CHECK-ENC: encoding: [0x73,0x23,0x50,0x7a]
1440+
# CHECK-INST-ALIAS: csrr t1, tcontrol
1441+
# uimm12
1442+
# CHECK-INST: csrrs t2, tcontrol, zero
1443+
# CHECK-ENC: encoding: [0xf3,0x23,0x50,0x7a]
1444+
# CHECK-INST-ALIAS: csrr t2, tcontrol
1445+
# name
1446+
csrrs t1, tcontrol, zero
1447+
# uimm12
1448+
csrrs t2, 0x7A5, zero
1449+
14221450
# mcontext
14231451
# name
14241452
# CHECK-INST: csrrs t1, mcontext, zero
@@ -1433,6 +1461,20 @@ csrrs t1, mcontext, zero
14331461
# uimm12
14341462
csrrs t2, 0x7A8, zero
14351463

1464+
# mscontext
1465+
# name
1466+
# CHECK-INST: csrrs t1, mscontext, zero
1467+
# CHECK-ENC: encoding: [0x73,0x23,0xa0,0x7a]
1468+
# CHECK-INST-ALIAS: csrr t1, mscontext
1469+
# uimm12
1470+
# CHECK-INST: csrrs t2, mscontext, zero
1471+
# CHECK-ENC: encoding: [0xf3,0x23,0xa0,0x7a]
1472+
# CHECK-INST-ALIAS: csrr t2, mscontext
1473+
# name
1474+
csrrs t1, mscontext, zero
1475+
# uimm12
1476+
csrrs t2, 0x7AA, zero
1477+
14361478
#######################
14371479
# Debug Mode Registers
14381480
########################

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,8 @@ Experimental extensions
11101110
zalasr 0.1
11111111
zvbc32e 0.7
11121112
zvkgs 0.7
1113+
sdext 1.0
1114+
sdtrig 1.0
11131115
smctr 1.0
11141116
ssctr 1.0
11151117
svukte 0.3

0 commit comments

Comments
 (0)