Skip to content

Commit 0bf165e

Browse files
[RISCV] Add support for RISC-V Pointer Masking (#79929)
This patch implements the v0.8.1 specification. This patch reports version 0.8 in llvm since `RISCVISAInfo::ExtensionVersion` only has a `Major` and `Minor` version number. This patch includes includes support of the `Ssnpm`, `Smnpm`, `Smmpm`, `Sspm` and `Supm` extensions that make up RISC-V pointer masking. All of these extensions require emitting attribute containing correct `march` string. `Ssnpm`, `Smnpm`, `Smmpm` extensions introduce a 2-bit WARL field (PMM). The extension does not specify how PMM is set, and therefore this patch does not need to address this. One example of how it *could* be set is using the Zicsr instructions to update the PMM bits of the described registers. The full specification can be found at https://github.com/riscv/riscv-j-extension/blob/master/zjpm-spec.pdf
1 parent 0c02ea0 commit 0bf165e

File tree

7 files changed

+114
-0
lines changed

7 files changed

+114
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@
159159

160160
// Experimental extensions
161161

162+
// CHECK-NOT: __riscv_smmpm{{.*$}}
163+
// CHECK-NOT: __riscv_smnpm{{.*$}}
164+
// CHECK-NOT: __riscv_ssnpm{{.*$}}
165+
// CHECK-NOT: __riscv_sspm{{.*$}}
166+
// CHECK-NOT: __riscv_supm{{.*$}}
162167
// CHECK-NOT: __riscv_zaamo {{.*$}}
163168
// CHECK-NOT: __riscv_zacas {{.*$}}
164169
// CHECK-NOT: __riscv_zalasr {{.*$}}
@@ -1567,6 +1572,46 @@
15671572
// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
15681573
// CHECK-ZICFISS-EXT: __riscv_zicfiss 4000{{$}}
15691574

1575+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1576+
// RUN: -march=rv32i_ssnpm0p8 -E -dM %s \
1577+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSNPM-EXT %s
1578+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1579+
// RUN: -march=rv64i_ssnpm0p8 -E -dM %s \
1580+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSNPM-EXT %s
1581+
// CHECK-SSNPM-EXT: __riscv_ssnpm 8000{{$}}
1582+
1583+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1584+
// RUN: -march=rv32i_smnpm0p8 -E -dM %s \
1585+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMNPM-EXT %s
1586+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1587+
// RUN: -march=rv64i_smnpm0p8 -E -dM %s \
1588+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMNPM-EXT %s
1589+
// CHECK-SMNPM-EXT: __riscv_smnpm 8000{{$}}
1590+
1591+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1592+
// RUN: -march=rv32i_smmpm0p8 -E -dM %s \
1593+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMMPM-EXT %s
1594+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1595+
// RUN: -march=rv64i_smmpm0p8 -E -dM %s \
1596+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMMPM-EXT %s
1597+
// CHECK-SMMPM-EXT: __riscv_smmpm 8000{{$}}
1598+
1599+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1600+
// RUN: -march=rv32i_sspm0p8 -E -dM %s \
1601+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSPM-EXT %s
1602+
// RUN: %clang --target=riscv64 \
1603+
// RUN: -march=rv64i_sspm0p8 -E -dM %s -menable-experimental-extensions \
1604+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSPM-EXT %s
1605+
// CHECK-SSPM-EXT: __riscv_sspm 8000{{$}}
1606+
1607+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1608+
// RUN: -march=rv32i_supm0p8 -E -dM %s \
1609+
// RUN: -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
1610+
// RUN: %clang --target=riscv64 \
1611+
// RUN: -march=rv64i_supm0p8 -E -dM %s -menable-experimental-extensions \
1612+
// RUN: -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
1613+
// CHECK-SUPM-EXT: __riscv_supm 8000{{$}}
1614+
15701615
// Misaligned
15711616

15721617
// RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -E -dM %s \

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ LLVM supports (to various degrees) a number of experimental extensions. All exp
243243

244244
The primary goal of experimental support is to assist in the process of ratification by providing an existence proof of an implementation, and simplifying efforts to validate the value of a proposed extension against large code bases. Experimental extensions are expected to either transition to ratified status, or be eventually removed. The decision on whether to accept an experimental extension is currently done on an entirely case by case basis; if you want to propose one, attending the bi-weekly RISC-V sync-up call is strongly advised.
245245

246+
``experimental-ssnpm``, ``experimental-smnpm``, ``experimental-smmpm``, ``experimental-sspm``, ``experimental-supm``
247+
LLVM implements the `v0.8.1 draft specification <https://github.com/riscv/riscv-j-extension/blob/master/zjpm-spec.pdf>`
248+
246249
``experimental-zabha``
247250
LLVM implements assembler support for the `v1.0-rc1 draft specification <https://github.com/riscv/riscv-zabha/tree/v1.0-rc1>`_.
248251

llvm/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Changes to the RISC-V Backend
101101
* The names of the majority of the S-prefixed (supervisor-level) extension
102102
names in the RISC-V profiles specification are now recognised.
103103
* Codegen support was added for the Zimop (May-Be-Operations) extension.
104+
* The experimental Ssnpm, Smnpm, Smmpm, Sspm, and Supm 0.8.1 Pointer Masking extensions are supported.
104105

105106
Changes to the WebAssembly Backend
106107
----------------------------------

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
211211
// NOTE: This table should be sorted alphabetically by extension name.
212212
// clang-format off
213213
static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
214+
{"smmpm", {0, 8}},
215+
{"smnpm", {0, 8}},
216+
{"ssnpm", {0, 8}},
217+
{"sspm", {0, 8}},
218+
{"supm", {0, 8}},
219+
214220
{"zaamo", {0, 2}},
215221
{"zabha", {1, 0}},
216222
{"zacas", {1, 0}},

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,40 @@ def FeatureStdExtSvpbmt
876876
: SubtargetFeature<"svpbmt", "HasStdExtSvpbmt", "true",
877877
"'Svpbmt' (Page-Based Memory Types)">;
878878

879+
// Pointer Masking extensions
880+
881+
// A supervisor-level extension that provides pointer masking for the next lower
882+
// privilege mode (U-mode), and for VS- and VU-modes if the H extension is
883+
// present.
884+
def FeatureStdExtSsnpm
885+
: SubtargetFeature<"experimental-ssnpm", "HasStdExtSsnpm", "true",
886+
"'Ssnpm' (Supervisor-level Pointer Masking for next lower privilege mode)">;
887+
888+
// A machine-level extension that provides pointer masking for the next lower
889+
// privilege mode (S/HS if S-mode is implemented, or U-mode otherwise).
890+
def FeatureStdExtSmnpm
891+
: SubtargetFeature<"experimental-smnpm", "HasStdExtSmnpm", "true",
892+
"'Smnpm' (Machine-level Pointer Masking for next lower privilege mode)">;
893+
894+
// A machine-level extension that provides pointer masking for M-mode.
895+
def FeatureStdExtSmmpm
896+
: SubtargetFeature<"experimental-smmpm", "HasStdExtSmmpm", "true",
897+
"'Smmpm' (Machine-level Pointer Masking for M-mode)">;
898+
899+
// An extension that indicates that there is pointer-masking support available
900+
// in supervisor mode, with some facility provided in the supervisor execution
901+
// environment to control pointer masking.
902+
def FeatureStdExtSspm
903+
: SubtargetFeature<"experimental-sspm", "HasStdExtSspm", "true",
904+
"'Sspm' (Indicates Supervisor-mode Pointer Masking)">;
905+
906+
// An extension that indicates that there is pointer-masking support available
907+
// in user mode, with some facility provided in the application execution
908+
// environment to control pointer masking.
909+
def FeatureStdExtSupm
910+
: SubtargetFeature<"experimental-supm", "HasStdExtSupm", "true",
911+
"'Supm' (Indicates User-mode Pointer Masking)">;
912+
879913
//===----------------------------------------------------------------------===//
880914
// Vendor extensions
881915
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s
117117
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV32ZICFILP %s
118118
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zabha %s -o - | FileCheck --check-prefix=RV32ZABHA %s
119+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV32SSNPM %s
120+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-smnpm %s -o - | FileCheck --check-prefix=RV32SMNPM %s
121+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-smmpm %s -o - | FileCheck --check-prefix=RV32SMMPM %s
122+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-sspm %s -o - | FileCheck --check-prefix=RV32SSPM %s
123+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-supm %s -o - | FileCheck --check-prefix=RV32SUPM %s
119124

120125
; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
121126
; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -239,6 +244,11 @@
239244
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV64ZALRSC %s
240245
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV64ZICFILP %s
241246
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zabha %s -o - | FileCheck --check-prefix=RV64ZABHA %s
247+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV64SSNPM %s
248+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-smnpm %s -o - | FileCheck --check-prefix=RV64SMNPM %s
249+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-smmpm %s -o - | FileCheck --check-prefix=RV64SMMPM %s
250+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-sspm %s -o - | FileCheck --check-prefix=RV64SSPM %s
251+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-supm %s -o - | FileCheck --check-prefix=RV64SUPM %s
242252

243253
; CHECK: .attribute 4, 16
244254

@@ -357,6 +367,11 @@
357367
; RV32ZALRSC: .attribute 5, "rv32i2p1_zalrsc0p2"
358368
; RV32ZICFILP: .attribute 5, "rv32i2p1_zicfilp0p4"
359369
; RV32ZABHA: .attribute 5, "rv32i2p1_a2p1_zabha1p0"
370+
; RV32SSNPM: .attribute 5, "rv32i2p1_ssnpm0p8"
371+
; RV32SMNPM: .attribute 5, "rv32i2p1_smnpm0p8"
372+
; RV32SMMPM: .attribute 5, "rv32i2p1_smmpm0p8"
373+
; RV32SSPM: .attribute 5, "rv32i2p1_sspm0p8"
374+
; RV32SUPM: .attribute 5, "rv32i2p1_supm0p8"
360375

361376
; RV64M: .attribute 5, "rv64i2p1_m2p0"
362377
; RV64ZMMUL: .attribute 5, "rv64i2p1_zmmul1p0"
@@ -479,6 +494,11 @@
479494
; RV64ZALRSC: .attribute 5, "rv64i2p1_zalrsc0p2"
480495
; RV64ZICFILP: .attribute 5, "rv64i2p1_zicfilp0p4"
481496
; RV64ZABHA: .attribute 5, "rv64i2p1_a2p1_zabha1p0"
497+
; RV64SSNPM: .attribute 5, "rv64i2p1_ssnpm0p8"
498+
; RV64SMNPM: .attribute 5, "rv64i2p1_smnpm0p8"
499+
; RV64SMMPM: .attribute 5, "rv64i2p1_smmpm0p8"
500+
; RV64SSPM: .attribute 5, "rv64i2p1_sspm0p8"
501+
; RV64SUPM: .attribute 5, "rv64i2p1_supm0p8"
482502

483503
define i32 @addi(i32 %a) {
484504
%1 = add i32 %a, 1

llvm/unittests/Support/RISCVISAInfoTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,11 @@ Experimental extensions
881881
ztso 0.1
882882
zvfbfmin 1.0
883883
zvfbfwma 1.0
884+
smmpm 0.8
885+
smnpm 0.8
886+
ssnpm 0.8
887+
sspm 0.8
888+
supm 0.8
884889
885890
Use -march to specify the target's extension.
886891
For example, clang -march=rv32i_v1p0)";

0 commit comments

Comments
 (0)