Skip to content

Commit bc844fb

Browse files
[RISCV] Add support for RISC-V Pointer Masking
This patch implements the v0.8.1 specification. This includes support of the `Ssnpm`, `Smnpm`, `Smmpm`, `Sspm` and `Supm` extensions that make up RISC-V pointer masking. All of these extensions only 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 b52fe2d commit bc844fb

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
@@ -142,6 +142,11 @@
142142

143143
// Experimental extensions
144144

145+
// CHECK-NOT: __riscv_smmpm{{.*$}}
146+
// CHECK-NOT: __riscv_smnpm{{.*$}}
147+
// CHECK-NOT: __riscv_ssnpm{{.*$}}
148+
// CHECK-NOT: __riscv_sspm{{.*$}}
149+
// CHECK-NOT: __riscv_supm{{.*$}}
145150
// CHECK-NOT: __riscv_zaamo {{.*$}}
146151
// CHECK-NOT: __riscv_zacas {{.*$}}
147152
// CHECK-NOT: __riscv_zalrsc {{.*$}}
@@ -1405,6 +1410,46 @@
14051410
// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
14061411
// CHECK-ZICFISS-EXT: __riscv_zicfiss 4000{{$}}
14071412

1413+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1414+
// RUN: -march=rv32i_ssnpm0p8 -E -dM %s \
1415+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSNPM-EXT %s
1416+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1417+
// RUN: -march=rv64i_ssnpm0p8 -E -dM %s \
1418+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSNPM-EXT %s
1419+
// CHECK-SSNPM-EXT: __riscv_ssnpm 8000{{$}}
1420+
1421+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1422+
// RUN: -march=rv32i_smnpm0p8 -E -dM %s \
1423+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMNPM-EXT %s
1424+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1425+
// RUN: -march=rv64i_smnpm0p8 -E -dM %s \
1426+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMNPM-EXT %s
1427+
// CHECK-SMNPM-EXT: __riscv_smnpm 8000{{$}}
1428+
1429+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1430+
// RUN: -march=rv32i_smmpm0p8 -E -dM %s \
1431+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMMPM-EXT %s
1432+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1433+
// RUN: -march=rv64i_smmpm0p8 -E -dM %s \
1434+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMMPM-EXT %s
1435+
// CHECK-SMMPM-EXT: __riscv_smmpm 8000{{$}}
1436+
1437+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1438+
// RUN: -march=rv32i_sspm0p8 -E -dM %s \
1439+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSPM-EXT %s
1440+
// RUN: %clang --target=riscv64 \
1441+
// RUN: -march=rv64i_sspm0p8 -E -dM %s -menable-experimental-extensions \
1442+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSPM-EXT %s
1443+
// CHECK-SSPM-EXT: __riscv_sspm 8000{{$}}
1444+
1445+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1446+
// RUN: -march=rv32i_supm0p8 -E -dM %s \
1447+
// RUN: -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
1448+
// RUN: %clang --target=riscv64 \
1449+
// RUN: -march=rv64i_supm0p8 -E -dM %s -menable-experimental-extensions \
1450+
// RUN: -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
1451+
// CHECK-SUPM-EXT: __riscv_supm 8000{{$}}
1452+
14081453
// Misaligned
14091454

14101455
// 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
@@ -226,6 +226,9 @@ LLVM supports (to various degrees) a number of experimental extensions. All exp
226226

227227
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.
228228

229+
``Ssnpm``, ``Smnpm``, ``Smmpm``, ``Sspm``, ``Supm``
230+
LLVM implements the `v0.8.1 draft specification <https://github.com/riscv/riscv-j-extension/blob/master/zjpm-spec.pdf>
231+
229232
``experimental-zacas``
230233
LLVM implements the `1.0-rc1 draft specification <https://github.com/riscv/riscv-zacas/releases/tag/v1.0-rc1>`_.
231234

llvm/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Changes to the RISC-V Backend
9393
-----------------------------
9494

9595
* Support for the Zicond extension is no longer experimental.
96+
* The experimental Ssnpm, Smnpm, Smmpm, Sspm, and Supm 0.8.1 Pointer Masking extensions are supported.
9697

9798
Changes to the WebAssembly Backend
9899
----------------------------------

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
193193
// NOTE: This table should be sorted alphabetically by extension name.
194194
// clang-format off
195195
static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
196+
{"smmpm", {0, 8}},
197+
{"smnpm", {0, 8}},
198+
{"ssnpm", {0, 8}},
199+
{"sspm", {0, 8}},
200+
{"supm", {0, 8}},
201+
196202
{"zaamo", {0, 2}},
197203
{"zacas", {1, 0}},
198204
{"zalrsc", {0, 2}},

llvm/lib/Target/RISCV/RISCVFeatures.td

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

800+
// Pointer Masking extensions
801+
802+
// A supervisor-level extension that provides pointer masking for the next lower
803+
// privilege mode (U-mode), and for VS- and VU-modes if the H extension is
804+
// present.
805+
def FeatureStdExtSsnpm
806+
: SubtargetFeature<"experimental-ssnpm", "HasStdExtSsnpm", "true",
807+
"'Ssnpm' (Supervisor-level Pointer Masking)">;
808+
809+
// A machine-level extension that provides pointer masking for the next lower
810+
// privilege mode (S/HS if S-mode is implemented, or U-mode otherwise).
811+
def FeatureStdExtSmnpm
812+
: SubtargetFeature<"experimental-smnpm", "HasStdExtSmnpm", "true",
813+
"'Smnpm' (Machine-level Pointer Masking)">;
814+
815+
// A machine-level extension that provides pointer masking for M-mode.
816+
def FeatureStdExtSmmpm
817+
: SubtargetFeature<"experimental-smmpm", "HasStdExtSmmpm", "true",
818+
"'Smmpm' (Machine-level Pointer Masking for M-mode)">;
819+
820+
// An extension that indicates that there is pointer-masking support available
821+
// in supervisor mode, with some facility provided in the supervisor execution
822+
// environment to control pointer masking.
823+
def FeatureStdExtSspm
824+
: SubtargetFeature<"experimental-sspm", "HasStdExtSspm", "true",
825+
"'Sspm' (Indicates Supervisor-mode Pointer Masking)">;
826+
827+
// An extension that indicates that there is pointer-masking support available
828+
// in user mode, with some facility provided in the application execution
829+
// environment to control pointer masking.
830+
def FeatureStdExtSupm
831+
: SubtargetFeature<"experimental-supm", "HasStdExtSupm", "true",
832+
"'Supm' (Indicates User-mode Pointer Masking)">;
833+
800834
//===----------------------------------------------------------------------===//
801835
// Vendor extensions
802836
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@
9797
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zacas %s -o - | FileCheck --check-prefix=RV32ZACAS %s
9898
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s
9999
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV32ZICFILP %s
100+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV32SSNPM %s
101+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-smnpm %s -o - | FileCheck --check-prefix=RV32SMNPM %s
102+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-smmpm %s -o - | FileCheck --check-prefix=RV32SMMPM %s
103+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-sspm %s -o - | FileCheck --check-prefix=RV32SSPM %s
104+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-supm %s -o - | FileCheck --check-prefix=RV32SUPM %s
100105

101106
; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
102107
; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -201,6 +206,11 @@
201206
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zacas %s -o - | FileCheck --check-prefix=RV64ZACAS %s
202207
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV64ZALRSC %s
203208
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV64ZICFILP %s
209+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV64SSNPM %s
210+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-smnpm %s -o - | FileCheck --check-prefix=RV64SMNPM %s
211+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-smmpm %s -o - | FileCheck --check-prefix=RV64SMMPM %s
212+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-sspm %s -o - | FileCheck --check-prefix=RV64SSPM %s
213+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-supm %s -o - | FileCheck --check-prefix=RV64SUPM %s
204214

205215
; CHECK: .attribute 4, 16
206216

@@ -300,6 +310,11 @@
300310
; RV32ZACAS: .attribute 5, "rv32i2p1_a2p1_zacas1p0"
301311
; RV32ZALRSC: .attribute 5, "rv32i2p1_zalrsc0p2"
302312
; RV32ZICFILP: .attribute 5, "rv32i2p1_zicfilp0p4"
313+
; RV32SSNPM: .attribute 5, "rv32i2p1_ssnpm0p8"
314+
; RV32SMNPM: .attribute 5, "rv32i2p1_smnpm0p8"
315+
; RV32SMMPM: .attribute 5, "rv32i2p1_smmpm0p8"
316+
; RV32SSPM: .attribute 5, "rv32i2p1_sspm0p8"
317+
; RV32SUPM: .attribute 5, "rv32i2p1_supm0p8"
303318

304319
; RV64M: .attribute 5, "rv64i2p1_m2p0"
305320
; RV64ZMMUL: .attribute 5, "rv64i2p1_zmmul1p0"
@@ -403,6 +418,11 @@
403418
; RV64ZACAS: .attribute 5, "rv64i2p1_a2p1_zacas1p0"
404419
; RV64ZALRSC: .attribute 5, "rv64i2p1_zalrsc0p2"
405420
; RV64ZICFILP: .attribute 5, "rv64i2p1_zicfilp0p4"
421+
; RV64SSNPM: .attribute 5, "rv64i2p1_ssnpm0p8"
422+
; RV64SMNPM: .attribute 5, "rv64i2p1_smnpm0p8"
423+
; RV64SMMPM: .attribute 5, "rv64i2p1_smmpm0p8"
424+
; RV64SSPM: .attribute 5, "rv64i2p1_sspm0p8"
425+
; RV64SUPM: .attribute 5, "rv64i2p1_supm0p8"
406426

407427
define i32 @addi(i32 %a) {
408428
%1 = add i32 %a, 1

llvm/unittests/Support/RISCVISAInfoTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,11 @@ Experimental extensions
799799
ztso 0.1
800800
zvfbfmin 1.0
801801
zvfbfwma 1.0
802+
smmpm 0.8
803+
smnpm 0.8
804+
ssnpm 0.8
805+
sspm 0.8
806+
supm 0.8
802807
803808
Use -march to specify the target's extension.
804809
For example, clang -march=rv32i_v1p0)";

0 commit comments

Comments
 (0)