Skip to content

Commit bd97d2a

Browse files
michaelmaitlandtclin914
authored andcommitted
[RISCV] Add support for RISC-V Pointer Masking (llvm#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 722625c commit bd97d2a

File tree

6 files changed

+109
-0
lines changed

6 files changed

+109
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@
100100
// CHECK-NOT: __riscv_svade {{.*$}}
101101
// CHECK-NOT: __riscv_svadu {{.*$}}
102102
// CHECK-NOT: __riscv_svbare {{.*$}}
103+
// CHECK-NOT: __riscv_smmpm{{.*$}}
104+
// CHECK-NOT: __riscv_smnpm{{.*$}}
105+
// CHECK-NOT: __riscv_ssnpm{{.*$}}
106+
// CHECK-NOT: __riscv_sspm{{.*$}}
107+
// CHECK-NOT: __riscv_supm{{.*$}}
103108
// CHECK-NOT: __riscv_zfbfmin {{.*$}}
104109
// CHECK-NOT: __riscv_zvfbfmin {{.*$}}
105110
// CHECK-NOT: __riscv_zvfbfwma {{.*$}}
@@ -992,6 +997,46 @@
992997
// RUN: -o - | FileCheck --check-prefix=CHECK-SVBARE-EXT %s
993998
// CHECK-SVBARE-EXT: __riscv_svbare 1000000{{$}}
994999

1000+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1001+
// RUN: -march=rv32i_ssnpm0p8 -E -dM %s \
1002+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSNPM-EXT %s
1003+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1004+
// RUN: -march=rv64i_ssnpm0p8 -E -dM %s \
1005+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSNPM-EXT %s
1006+
// CHECK-SSNPM-EXT: __riscv_ssnpm 8000{{$}}
1007+
1008+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1009+
// RUN: -march=rv32i_smnpm0p8 -E -dM %s \
1010+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMNPM-EXT %s
1011+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1012+
// RUN: -march=rv64i_smnpm0p8 -E -dM %s \
1013+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMNPM-EXT %s
1014+
// CHECK-SMNPM-EXT: __riscv_smnpm 8000{{$}}
1015+
1016+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1017+
// RUN: -march=rv32i_smmpm0p8 -E -dM %s \
1018+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMMPM-EXT %s
1019+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1020+
// RUN: -march=rv64i_smmpm0p8 -E -dM %s \
1021+
// RUN: -o - | FileCheck --check-prefix=CHECK-SMMPM-EXT %s
1022+
// CHECK-SMMPM-EXT: __riscv_smmpm 8000{{$}}
1023+
1024+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1025+
// RUN: -march=rv32i_sspm0p8 -E -dM %s \
1026+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSPM-EXT %s
1027+
// RUN: %clang --target=riscv64 \
1028+
// RUN: -march=rv64i_sspm0p8 -E -dM %s -menable-experimental-extensions \
1029+
// RUN: -o - | FileCheck --check-prefix=CHECK-SSPM-EXT %s
1030+
// CHECK-SSPM-EXT: __riscv_sspm 8000{{$}}
1031+
1032+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1033+
// RUN: -march=rv32i_supm0p8 -E -dM %s \
1034+
// RUN: -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
1035+
// RUN: %clang --target=riscv64 \
1036+
// RUN: -march=rv64i_supm0p8 -E -dM %s -menable-experimental-extensions \
1037+
// RUN: -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
1038+
// CHECK-SUPM-EXT: __riscv_supm 8000{{$}}
1039+
9951040
// RUN: %clang -target riscv32 -menable-experimental-extensions \
9961041
// RUN: -march=rv32izfbfmin1p0 -x c -E -dM %s \
9971042
// RUN: -o - | FileCheck --check-prefix=CHECK-ZFBFMIN-EXT %s

llvm/docs/RISCVUsage.rst

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

238238
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.
239239

240+
``experimental-ssnpm``, ``experimental-smnpm``, ``experimental-smmpm``, ``experimental-sspm``, ``experimental-supm``
241+
LLVM implements the `v0.8.1 draft specification <https://github.com/riscv/riscv-j-extension/blob/master/zjpm-spec.pdf>`
242+
240243
``experimental-zacas``
241244
LLVM implements the `1.0-rc1 draft specification <https://github.com/riscv/riscv-zacas/releases/tag/v1.0-rc1>`_.
242245

llvm/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ Changes to the RISC-V Backend
347347
and Zic64b extensions which were introduced as a part of the RISC-V Profiles
348348
specification.
349349
* The Smepmp 1.0 extension is now supported.
350+
* The experimental Ssnpm, Smnpm, Smmpm, Sspm, and Supm 0.8.1 Pointer Masking extensions are supported.
350351

351352
Changes to the WebAssembly Backend
352353
----------------------------------

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
219219
static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
220220
{"p", RISCVExtensionVersion{0, 5}},
221221

222+
{"smmpm", {0, 8}},
223+
{"smnpm", {0, 8}},
224+
{"ssnpm", {0, 8}},
225+
{"sspm", {0, 8}},
226+
{"supm", {0, 8}},
227+
222228
{"zacas", RISCVExtensionVersion{1, 0}},
223229

224230
{"zcmlsd", RISCVExtensionVersion{0, 8}},

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,40 @@ def HasStdExtZcmlsd : Predicate<"Subtarget->hasStdExtZcmlsd()">,
895895
AssemblerPredicate<(all_of FeatureStdExtZcmlsd),
896896
"'Zcmlsd' (Compressed Load/Store Pair Instructions for RV32)">;
897897

898+
// Pointer Masking extensions
899+
900+
// A supervisor-level extension that provides pointer masking for the next lower
901+
// privilege mode (U-mode), and for VS- and VU-modes if the H extension is
902+
// present.
903+
def FeatureStdExtSsnpm
904+
: SubtargetFeature<"experimental-ssnpm", "HasStdExtSsnpm", "true",
905+
"'Ssnpm' (Supervisor-level Pointer Masking for next lower privilege mode)">;
906+
907+
// A machine-level extension that provides pointer masking for the next lower
908+
// privilege mode (S/HS if S-mode is implemented, or U-mode otherwise).
909+
def FeatureStdExtSmnpm
910+
: SubtargetFeature<"experimental-smnpm", "HasStdExtSmnpm", "true",
911+
"'Smnpm' (Machine-level Pointer Masking for next lower privilege mode)">;
912+
913+
// A machine-level extension that provides pointer masking for M-mode.
914+
def FeatureStdExtSmmpm
915+
: SubtargetFeature<"experimental-smmpm", "HasStdExtSmmpm", "true",
916+
"'Smmpm' (Machine-level Pointer Masking for M-mode)">;
917+
918+
// An extension that indicates that there is pointer-masking support available
919+
// in supervisor mode, with some facility provided in the supervisor execution
920+
// environment to control pointer masking.
921+
def FeatureStdExtSspm
922+
: SubtargetFeature<"experimental-sspm", "HasStdExtSspm", "true",
923+
"'Sspm' (Indicates Supervisor-mode Pointer Masking)">;
924+
925+
// An extension that indicates that there is pointer-masking support available
926+
// in user mode, with some facility provided in the application execution
927+
// environment to control pointer masking.
928+
def FeatureStdExtSupm
929+
: SubtargetFeature<"experimental-supm", "HasStdExtSupm", "true",
930+
"'Supm' (Indicates User-mode Pointer Masking)">;
931+
898932
//===----------------------------------------------------------------------===//
899933
// Vendor extensions
900934
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@
107107
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zacas %s -o - | FileCheck --check-prefix=RV32ZACAS %s
108108
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zilsd %s -o - | FileCheck --check-prefix=RV32ZILSD %s
109109
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcmlsd %s -o - | FileCheck --check-prefix=RV32ZCMLSD %s
110+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV32SSNPM %s
111+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-smnpm %s -o - | FileCheck --check-prefix=RV32SMNPM %s
112+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-smmpm %s -o - | FileCheck --check-prefix=RV32SMMPM %s
113+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-sspm %s -o - | FileCheck --check-prefix=RV32SSPM %s
114+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-supm %s -o - | FileCheck --check-prefix=RV32SUPM %s
110115

111116
; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
112117
; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -227,6 +232,11 @@
227232
; RUN: llc -mtriple=riscv32 -mattr=+experimental-p %s -o - | FileCheck --check-prefix=RV32P %s
228233
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zpn %s -o - | FileCheck --check-prefix=RV32ZPN %s
229234
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zpsfoperand %s -o - | FileCheck --check-prefix=RV32ZPSFOPERAND %s
235+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV64SSNPM %s
236+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-smnpm %s -o - | FileCheck --check-prefix=RV64SMNPM %s
237+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-smmpm %s -o - | FileCheck --check-prefix=RV64SMMPM %s
238+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-sspm %s -o - | FileCheck --check-prefix=RV64SSPM %s
239+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-supm %s -o - | FileCheck --check-prefix=RV64SUPM %s
230240

231241
; CHECK: .attribute 4, 16
232242

@@ -339,6 +349,11 @@
339349
; RV32P: .attribute 5, "rv32i2p1_p0p5"
340350
; RV32ZPN: .attribute 5, "rv32i2p1_p0p5"
341351
; RV32ZPSFOPERAND: .attribute 5, "rv32i2p1_p0p5"
352+
; RV32SSNPM: .attribute 5, "rv32i2p1_ssnpm0p8"
353+
; RV32SMNPM: .attribute 5, "rv32i2p1_smnpm0p8"
354+
; RV32SMMPM: .attribute 5, "rv32i2p1_smmpm0p8"
355+
; RV32SSPM: .attribute 5, "rv32i2p1_sspm0p8"
356+
; RV32SUPM: .attribute 5, "rv32i2p1_supm0p8"
342357

343358
; RV64M: .attribute 5, "rv64i2p1_m2p0"
344359
; RV64ZMMUL: .attribute 5, "rv64i2p1_zmmul1p0"
@@ -458,6 +473,11 @@
458473
; RV64P: .attribute 5, "rv64i2p1_p0p5"
459474
; RV64ZPN: .attribute 5, "rv64i2p1_p0p5"
460475
; RV64ZPSFOPERAND: .attribute 5, "rv64i2p1_p0p5"
476+
; RV64SSNPM: .attribute 5, "rv64i2p1_ssnpm0p8"
477+
; RV64SMNPM: .attribute 5, "rv64i2p1_smnpm0p8"
478+
; RV64SMMPM: .attribute 5, "rv64i2p1_smmpm0p8"
479+
; RV64SSPM: .attribute 5, "rv64i2p1_sspm0p8"
480+
; RV64SUPM: .attribute 5, "rv64i2p1_supm0p8"
461481

462482
define i32 @addi(i32 %a) {
463483
%1 = add i32 %a, 1

0 commit comments

Comments
 (0)