Skip to content

Commit 1d76692

Browse files
JivanHln8-8
andauthored
[RISCV][MC] Add support for experimental Zimop extension (#75182)
This implements experimental support for the Zimop extension as specified here: https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc. This change adds only assembly support. --------- Co-authored-by: ln8-8 <[email protected]> Co-authored-by: ln8-8 <[email protected]>
1 parent b996f84 commit 1d76692

File tree

10 files changed

+106
-0
lines changed

10 files changed

+106
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
// CHECK-NOT: __riscv_zfbfmin {{.*$}}
121121
// CHECK-NOT: __riscv_zicfilp {{.*$}}
122122
// CHECK-NOT: __riscv_zicond {{.*$}}
123+
// CHECK-NOT: __riscv_zimop {{.*$}}
123124
// CHECK-NOT: __riscv_ztso {{.*$}}
124125
// CHECK-NOT: __riscv_zvbb {{.*$}}
125126
// CHECK-NOT: __riscv_zvbc {{.*$}}
@@ -1071,6 +1072,14 @@
10711072
// RUN: -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
10721073
// CHECK-ZICOND-EXT: __riscv_zicond 1000000{{$}}
10731074

1075+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1076+
// RUN: -march=rv32i_zimop0p1 -x c -E -dM %s \
1077+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZIMOP-EXT %s
1078+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1079+
// RUN: -march=rv64i_zimop0p1 -x c -E -dM %s \
1080+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZIMOP-EXT %s
1081+
// CHECK-ZIMOP-EXT: __riscv_zimop 1000{{$}}
1082+
10741083
// RUN: %clang --target=riscv32-unknown-linux-gnu -menable-experimental-extensions \
10751084
// RUN: -march=rv32iztso0p1 -x c -E -dM %s \
10761085
// RUN: -o - | FileCheck --check-prefix=CHECK-ZTSO-EXT %s

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ The primary goal of experimental support is to assist in the process of ratifica
221221
``experimental-ztso``
222222
LLVM implements the `v0.1 proposed specification <https://github.com/riscv/riscv-isa-manual/releases/download/draft-20220723-10eea63/riscv-spec.pdf>`__ (see Chapter 25). The mapping from the C/C++ memory model to Ztso has not yet been ratified in any standards document. There are multiple possible mappings, and they are *not* mutually ABI compatible. The mapping LLVM implements is ABI compatible with the default WMO mapping. This mapping may change and there is *explicitly* no ABI stability offered while the extension remains in experimental status. User beware.
223223

224+
``experimental-zimop``
225+
LLVM implements the `v0.1 proposed specification <https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc>`__.
226+
224227
To use an experimental extension from `clang`, you must add `-menable-experimental-extensions` to the command line, and specify the exact version of the experimental extension you are using. To use an experimental extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, `llvm-mc`), you must prefix the extension name with `experimental-`. Note that you don't need to specify the version with internal tools, and shouldn't include the `experimental-` prefix with `clang`.
225228

226229
Vendor Extensions

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
196196
{"zicfilp", RISCVExtensionVersion{0, 4}},
197197
{"zicond", RISCVExtensionVersion{1, 0}},
198198

199+
{"zimop", RISCVExtensionVersion{0, 1}},
200+
199201
{"ztso", RISCVExtensionVersion{0, 1}},
200202

201203
{"zvfbfmin", RISCVExtensionVersion{0, 8}},

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,12 @@ def HasStdExtZicond : Predicate<"Subtarget->hasStdExtZicond()">,
687687
AssemblerPredicate<(all_of FeatureStdExtZicond),
688688
"'Zicond' (Integer Conditional Operations)">;
689689

690+
def FeatureStdExtZimop : SubtargetFeature<"experimental-zimop", "HasStdExtZimop", "true",
691+
"'Zimop' (May-Be-Operations)">;
692+
def HasStdExtZimop : Predicate<"Subtarget->hasStdExtZimop()">,
693+
AssemblerPredicate<(all_of FeatureStdExtZimop),
694+
"'Zimop' (May-Be-Operations)">;
695+
690696
def FeatureStdExtSmaia
691697
: SubtargetFeature<"smaia", "HasStdExtSmaia", "true",
692698
"'Smaia' (Smaia encompasses all added CSRs and all "

llvm/lib/Target/RISCV/RISCVInstrFormats.td

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,27 @@ class RVInstIUnary<bits<12> imm12, bits<3> funct3, RISCVOpcode opcode,
410410
let Inst{31-20} = imm12;
411411
}
412412

413+
class RVInstIMopr<bits<7> imm7, bits<5> imm5, bits<3> funct3, RISCVOpcode opcode,
414+
dag outs, dag ins, string opcodestr, string argstr>
415+
: RVInstIBase<funct3, opcode, outs, ins, opcodestr, argstr> {
416+
let Inst{31} = imm7{6};
417+
let Inst{30} = imm5{4};
418+
let Inst{29-28} = imm7{5-4};
419+
let Inst{27-26} = imm5{3-2};
420+
let Inst{25-22} = imm7{3-0};
421+
let Inst{21-20} = imm5{1-0};
422+
}
423+
424+
class RVInstRMoprr<bits<4> imm4, bits<3> imm3, bits<3> funct3, RISCVOpcode opcode,
425+
dag outs, dag ins, string opcodestr, string argstr>
426+
: RVInstRBase<funct3, opcode, outs, ins, opcodestr, argstr> {
427+
let Inst{31} = imm4{3};
428+
let Inst{30} = imm3{2};
429+
let Inst{29-28} = imm4{2-1};
430+
let Inst{27-26} = imm3{1-0};
431+
let Inst{25} = imm4{0};
432+
}
433+
413434
class RVInstS<bits<3> funct3, RISCVOpcode opcode, dag outs, dag ins,
414435
string opcodestr, string argstr>
415436
: RVInst<outs, ins, opcodestr, argstr, [], InstFormatS> {

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,18 @@ class Priv_rr<string opcodestr, bits<7> funct7>
597597
let rd = 0;
598598
}
599599

600+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
601+
class RVMopr<bits<7> imm7, bits<5> imm5, bits<3> funct3,
602+
RISCVOpcode opcode, string opcodestr>
603+
: RVInstIMopr<imm7, imm5, funct3, opcode, (outs GPR:$rd), (ins GPR:$rs1),
604+
opcodestr, "$rd, $rs1">;
605+
606+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
607+
class RVMoprr<bits<4> imm4, bits<3> imm3, bits<3> funct3,
608+
RISCVOpcode opcode, string opcodestr>
609+
: RVInstRMoprr<imm4, imm3, funct3, opcode, (outs GPR:$rd), (ins GPR:$rs1, GPR:$rs2),
610+
opcodestr, "$rd, $rs1, $rs2">;
611+
600612
//===----------------------------------------------------------------------===//
601613
// Instructions
602614
//===----------------------------------------------------------------------===//
@@ -786,6 +798,22 @@ def SRAW : ALUW_rr<0b0100000, 0b101, "sraw">,
786798
} // IsSignExtendingOpW = 1
787799
} // Predicates = [IsRV64]
788800

801+
// Zimop instructions
802+
803+
foreach i = 0...31 in {
804+
let Predicates = [HasStdExtZimop] in {
805+
def MOPR#i : RVMopr<0b1000111, i, 0b100, OPC_SYSTEM, "mop.r."#i>,
806+
Sched<[]>;
807+
} // Predicates = [HasStdExtZimop]
808+
}
809+
810+
foreach i = 0...7 in {
811+
let Predicates = [HasStdExtZimop] in {
812+
def MOPRR#i : RVMoprr<0b1001, i, 0b100, OPC_SYSTEM, "mop.rr."#i>,
813+
Sched<[]>;
814+
} // Predicates = [HasStdExtZimop]
815+
}
816+
789817
//===----------------------------------------------------------------------===//
790818
// Privileged instructions
791819
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
; RUN: llc -mtriple=riscv32 -mattr=+zve32x -mattr=+zvkt %s -o - | FileCheck --check-prefix=RV32ZVKT %s
8686
; RUN: llc -mtriple=riscv32 -mattr=+zvfh %s -o - | FileCheck --check-prefix=RV32ZVFH %s
8787
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV32ZICOND %s
88+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zimop %s -o - | FileCheck --check-prefix=RV32ZIMOP %s
8889
; RUN: llc -mtriple=riscv32 -mattr=+smaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SMAIA %s
8990
; RUN: llc -mtriple=riscv32 -mattr=+ssaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SSAIA %s
9091
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZFBFMIN %s
@@ -177,6 +178,7 @@
177178
; RUN: llc -mtriple=riscv64 -mattr=+zve32x -mattr=+zvkt %s -o - | FileCheck --check-prefix=RV64ZVKT %s
178179
; RUN: llc -mtriple=riscv64 -mattr=+zvfh %s -o - | FileCheck --check-prefix=RV64ZVFH %s
179180
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV64ZICOND %s
181+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zimop %s -o - | FileCheck --check-prefix=RV64ZIMOP %s
180182
; RUN: llc -mtriple=riscv64 -mattr=+smaia %s -o - | FileCheck --check-prefixes=CHECK,RV64SMAIA %s
181183
; RUN: llc -mtriple=riscv64 -mattr=+ssaia %s -o - | FileCheck --check-prefixes=CHECK,RV64SSAIA %s
182184
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZFBFMIN %s
@@ -271,6 +273,7 @@
271273
; RV32ZVKT: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvkt1p0_zvl32b1p0"
272274
; RV32ZVFH: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfhmin1p0_zve32f1p0_zve32x1p0_zvfh1p0_zvfhmin1p0_zvl32b1p0"
273275
; RV32ZICOND: .attribute 5, "rv32i2p1_zicond1p0"
276+
; RV32ZIMOP: .attribute 5, "rv32i2p1_zimop0p1"
274277
; RV32SMAIA: .attribute 5, "rv32i2p1_smaia1p0"
275278
; RV32SSAIA: .attribute 5, "rv32i2p1_ssaia1p0"
276279
; RV32ZFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p8"
@@ -362,6 +365,7 @@
362365
; RV64ZVKT: .attribute 5, "rv64i2p1_zicsr2p0_zve32x1p0_zvkt1p0_zvl32b1p0"
363366
; RV64ZVFH: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfhmin1p0_zve32f1p0_zve32x1p0_zvfh1p0_zvfhmin1p0_zvl32b1p0"
364367
; RV64ZICOND: .attribute 5, "rv64i2p1_zicond1p0"
368+
; RV64ZIMOP: .attribute 5, "rv64i2p1_zimop0p1"
365369
; RV64SMAIA: .attribute 5, "rv64i2p1_smaia1p0"
366370
; RV64SSAIA: .attribute 5, "rv64i2p1_ssaia1p0"
367371
; RV64ZFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin0p8"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zimop < %s 2>&1 | FileCheck %s
2+
3+
# Too few operands
4+
mop.r.0 t0 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
5+
# Too few operands
6+
mop.rr.0 t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction

llvm/test/MC/RISCV/rvzimop-valid.s

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zimop -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
3+
# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zimop -show-encoding \
4+
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
5+
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zimop < %s \
6+
# RUN: | llvm-objdump --mattr=+experimental-zimop -d -r - \
7+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
8+
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zimop < %s \
9+
# RUN: | llvm-objdump --mattr=+experimental-zimop -d -r - \
10+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
11+
12+
# CHECK-ASM-AND-OBJ: mop.r.0 a2, a1
13+
# CHECK-ASM: encoding: [0x73,0xc6,0xc5,0x81]
14+
mop.r.0 a2, a1
15+
16+
# CHECK-ASM-AND-OBJ: mop.r.31 a2, a1
17+
# CHECK-ASM: encoding: [0x73,0xc6,0xf5,0xcd]
18+
mop.r.31 a2, a1
19+
20+
# CHECK-ASM-AND-OBJ: mop.rr.0 a3, a2, a1
21+
# CHECK-ASM: encoding: [0xf3,0x46,0xb6,0x82]
22+
mop.rr.0 a3, a2, a1
23+
24+
# CHECK-ASM-AND-OBJ: mop.rr.7 a3, a2, a1
25+
# CHECK-ASM: encoding: [0xf3,0x46,0xb6,0xce]
26+
mop.rr.7 a3, a2, a1

llvm/unittests/Support/RISCVISAInfoTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ R"(All available -march extensions for RISC-V
756756
Experimental extensions
757757
zicfilp 0.4 This is a long dummy description
758758
zicond 1.0
759+
zimop 0.1
759760
zacas 1.0
760761
zfbfmin 0.8
761762
ztso 0.1

0 commit comments

Comments
 (0)