Skip to content

Commit 35f6cc6

Browse files
authored
[RISCV] Add the Sha extension (#113820)
This was introduced in the now-ratified RVA23 profile (and also added to the RVA22 text) as a simple way of referring to H plus the set of supervisor extensions required by RVA23. https://github.com/riscv/riscv-profiles/blob/main/src/rva23-profile.adoc This patch simply defines the extension. The next patch will adjust the RVA23 profile to use it, and at that point I think we will be ready to mark RVA23 as non-experimental. Note that I haven't made it so if you enable all extensions that constitute Sha, Sha is implied. Per #76893 (adding 'B'), the concern is making this implication might break older external assemblers. Perhaps this is less of a concern given the relative frequency of `-march=${foo}_zba_zbb_zbs` vs the collection of H extensions. If we did want to add that implication, we'd probably want to add it in a separate patch so it can be easily reverted if found to cause problems.
1 parent e7f422d commit 35f6cc6

File tree

7 files changed

+24
-0
lines changed

7 files changed

+24
-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
@@ -110,6 +110,7 @@
110110
// CHECK-NEXT: zvl8192b 1.0 'Zvl' (Minimum Vector Length) 8192
111111
// CHECK-NEXT: zhinx 1.0 'Zhinx' (Half Float in Integer)
112112
// CHECK-NEXT: zhinxmin 1.0 'Zhinxmin' (Half Float in Integer Minimal)
113+
// CHECK-NEXT: sha 1.0 'Sha' (Augmented Hypervisor)
113114
// CHECK-NEXT: shcounterenw 1.0 'Shcounterenw' (Support writeable hcounteren enable bit for any hpmcounter that is not read-only zero)
114115
// CHECK-NEXT: shgatpa 1.0 'Sgatpa' (SvNNx4 mode supported for all modes supported by satp, as well as Bare)
115116
// CHECK-NEXT: shtvala 1.0 'Shtvala' (htval provides all needed values)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// CHECK-NOT: __riscv_m {{.*$}}
2121
// CHECK-NOT: __riscv_mul {{.*$}}
2222
// CHECK-NOT: __riscv_muldiv {{.*$}}
23+
// CHECK-NOT: __riscv_sha {{.*$}}
2324
// CHECK-NOT: __riscv_shcounterenw {{.*$}}
2425
// CHECK-NOT: __riscv_shgatpa {{.*$}}
2526
// CHECK-NOT: __riscv_shtvala {{.*$}}
@@ -323,6 +324,14 @@
323324
// CHECK-M-EXT: __riscv_mul 1
324325
// CHECK-M-EXT: __riscv_muldiv 1
325326

327+
// RUN: %clang --target=riscv32-unknown-linux-gnu \
328+
// RUN: -march=rv32isha -E -dM %s \
329+
// RUN: -o - | FileCheck --check-prefix=CHECK-SHCOUNTERENW-EXT %s
330+
// RUN: %clang --target=riscv64-unknown-linux-gnu \
331+
// RUN: -march=rv64isha -E -dM %s \
332+
// RUN: -o - | FileCheck --check-prefix=CHECK-SHCOUNTERENW-EXT %s
333+
// CHECK-SHA-EXT: __riscv_sha 1000000{{$}}
334+
326335
// RUN: %clang --target=riscv32-unknown-linux-gnu \
327336
// RUN: -march=rv32ishcounterenw -E -dM %s \
328337
// RUN: -o - | FileCheck --check-prefix=CHECK-SHCOUNTERENW-EXT %s

llvm/docs/RISCVUsage.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ on support follow.
119119
``E`` Supported (`See note <#riscv-rve-note>`__)
120120
``H`` Assembly Support
121121
``M`` Supported
122+
``Sha`` Supported
122123
``Shcounterenw`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__)
123124
``Shgatpa`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__)
124125
``Shtvala`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__)

llvm/docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ Changes to the RISC-V Backend
183183
* The `Zacas` extension is no longer marked as experimental.
184184
* The `Smmpm`, `Smnpm`, `Ssnpm`, `Supm`, and `Sspm` pointer masking extensions
185185
are no longer marked as experimental.
186+
* The `Sha` extension is now supported.
186187

187188
Changes to the WebAssembly Backend
188189
----------------------------------

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,13 @@ def FeatureStdExtSvpbmt
10291029
: RISCVExtension<"svpbmt", 1, 0,
10301030
"'Svpbmt' (Page-Based Memory Types)">;
10311031

1032+
def FeatureStdExtSha
1033+
: RISCVExtension<"sha", 1, 0,
1034+
"'Sha' (Augmented Hypervisor)",
1035+
[FeatureStdExtH, FeatureStdExtSsstateen, FeatureStdExtShcounterenw,
1036+
FeatureStdExtShvstvala, FeatureStdExtShtvala, FeatureStdExtShvstvecd,
1037+
FeatureStdExtShvsatpa, FeatureStdExtShgatpa]>;
1038+
10321039
// Pointer Masking extensions
10331040

10341041
// A supervisor-level extension that provides pointer masking for the next lower

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
; RUN: llc -mtriple=riscv32 -mattr=+zicbom %s -o - | FileCheck --check-prefixes=CHECK,RV32ZICBOM %s
4040
; RUN: llc -mtriple=riscv32 -mattr=+zicboz %s -o - | FileCheck --check-prefixes=CHECK,RV32ZICBOZ %s
4141
; RUN: llc -mtriple=riscv32 -mattr=+zicbop %s -o - | FileCheck --check-prefixes=CHECK,RV32ZICBOP %s
42+
; RUN: llc -mtriple=riscv32 -mattr=+sha %s -o - | FileCheck --check-prefixes=CHECK,RV32SHA %s
4243
; RUN: llc -mtriple=riscv32 -mattr=+shcounterenw %s -o - | FileCheck --check-prefixes=CHECK,RV32SHCOUNTERENW %s
4344
; RUN: llc -mtriple=riscv32 -mattr=+shgatpa %s -o - | FileCheck --check-prefixes=CHECK,RV32SHGATPA %s
4445
; RUN: llc -mtriple=riscv32 -mattr=+shvsatpa %s -o - | FileCheck --check-prefixes=CHECK,RV32SHVSATPA %s
@@ -178,6 +179,7 @@
178179
; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefixes=CHECK,RV64ZICBOM %s
179180
; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefixes=CHECK,RV64ZICBOZ %s
180181
; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefixes=CHECK,RV64ZICBOP %s
182+
; RUN: llc -mtriple=riscv64 -mattr=+sha %s -o - | FileCheck --check-prefixes=CHECK,RV64SHA %s
181183
; RUN: llc -mtriple=riscv64 -mattr=+shcounterenw %s -o - | FileCheck --check-prefixes=CHECK,RV64SHCOUNTERENW %s
182184
; RUN: llc -mtriple=riscv64 -mattr=+shgatpa %s -o - | FileCheck --check-prefixes=CHECK,RV64SHGATPA %s
183185
; RUN: llc -mtriple=riscv64 -mattr=+shvsatpa %s -o - | FileCheck --check-prefixes=CHECK,RV64SHVSATPA %s
@@ -333,6 +335,7 @@
333335
; RV32ZICBOM: .attribute 5, "rv32i2p1_zicbom1p0"
334336
; RV32ZICBOZ: .attribute 5, "rv32i2p1_zicboz1p0"
335337
; RV32ZICBOP: .attribute 5, "rv32i2p1_zicbop1p0"
338+
; RV32SHA: .attribute 5, "rv32i2p1_h1p0_sha1p0_shcounterenw1p0_shgatpa1p0_shtvala1p0_shvsatpa1p0_shvstvala1p0_shvstvecd1p0_ssstateen1p0"
336339
; RV32SHCOUNTERENW: .attribute 5, "rv32i2p1_shcounterenw1p0"
337340
; RV32SHGATPA: .attribute 5, "rv32i2p1_shgatpa1p0"
338341
; RV32SHVSATPA: .attribute 5, "rv32i2p1_shvsatpa1p0"
@@ -474,6 +477,7 @@
474477
; RV64ZAMA16B: .attribute 5, "rv64i2p1_zama16b1p0"
475478
; RV64ZAWRS: .attribute 5, "rv64i2p1_zawrs1p0"
476479
; RV64ZICBOP: .attribute 5, "rv64i2p1_zicbop1p0"
480+
; RV64SHA: .attribute 5, "rv64i2p1_h1p0_sha1p0_shcounterenw1p0_shgatpa1p0_shtvala1p0_shvsatpa1p0_shvstvala1p0_shvstvecd1p0_ssstateen1p0"
477481
; RV64SHCOUNTERENW: .attribute 5, "rv64i2p1_shcounterenw1p0"
478482
; RV64SHGATPA: .attribute 5, "rv64i2p1_shgatpa1p0"
479483
; RV64SHVSATPA: .attribute 5, "rv64i2p1_shvsatpa1p0"

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ R"(All available -march extensions for RISC-V
10551055
zvl8192b 1.0
10561056
zhinx 1.0
10571057
zhinxmin 1.0
1058+
sha 1.0
10581059
shcounterenw 1.0
10591060
shgatpa 1.0
10601061
shtvala 1.0

0 commit comments

Comments
 (0)