Skip to content

Commit 13cdee9

Browse files
authored
[RISCV][MC] Add support for experimental Zcmop extension (#76395)
This implements experimental support for the Zcmop extension as specified here: https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc. This change adds only MC support.
1 parent 705065f commit 13cdee9

File tree

10 files changed

+108
-0
lines changed

10 files changed

+108
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
// CHECK-NOT: __riscv_zicfilp {{.*$}}
122122
// CHECK-NOT: __riscv_zicond {{.*$}}
123123
// CHECK-NOT: __riscv_zimop {{.*$}}
124+
// CHECK-NOT: __riscv_zcmop {{.*$}}
124125
// CHECK-NOT: __riscv_ztso {{.*$}}
125126
// CHECK-NOT: __riscv_zvbb {{.*$}}
126127
// CHECK-NOT: __riscv_zvbc {{.*$}}
@@ -1080,6 +1081,14 @@
10801081
// RUN: -o - | FileCheck --check-prefix=CHECK-ZIMOP-EXT %s
10811082
// CHECK-ZIMOP-EXT: __riscv_zimop 1000{{$}}
10821083

1084+
// RUN: %clang --target=riscv32 -menable-experimental-extensions \
1085+
// RUN: -march=rv32i_zcmop0p2 -x c -E -dM %s \
1086+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZCMOP-EXT %s
1087+
// RUN: %clang --target=riscv64 -menable-experimental-extensions \
1088+
// RUN: -march=rv64i_zcmop0p2 -x c -E -dM %s \
1089+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZCMOP-EXT %s
1090+
// CHECK-ZCMOP-EXT: __riscv_zcmop 2000{{$}}
1091+
10831092
// RUN: %clang --target=riscv32-unknown-linux-gnu -menable-experimental-extensions \
10841093
// RUN: -march=rv32iztso0p1 -x c -E -dM %s \
10851094
// 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
@@ -224,6 +224,9 @@ The primary goal of experimental support is to assist in the process of ratifica
224224
``experimental-zimop``
225225
LLVM implements the `v0.1 proposed specification <https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc>`__.
226226

227+
``experimental-zcmop``
228+
LLVM implements the `v0.2 proposed specification <https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc>`__.
229+
227230
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`.
228231

229232
Vendor Extensions

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
191191
static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
192192
{"zacas", RISCVExtensionVersion{1, 0}},
193193

194+
{"zcmop", RISCVExtensionVersion{0, 2}},
195+
194196
{"zfbfmin", RISCVExtensionVersion{0, 8}},
195197

196198
{"zicfilp", RISCVExtensionVersion{0, 4}},
@@ -1008,6 +1010,7 @@ static const char *ImpliedExtsZcb[] = {"zca"};
10081010
static const char *ImpliedExtsZcd[] = {"d", "zca"};
10091011
static const char *ImpliedExtsZce[] = {"zcb", "zcmp", "zcmt"};
10101012
static const char *ImpliedExtsZcf[] = {"f", "zca"};
1013+
static const char *ImpliedExtsZcmop[] = {"zca"};
10111014
static const char *ImpliedExtsZcmp[] = {"zca"};
10121015
static const char *ImpliedExtsZcmt[] = {"zca", "zicsr"};
10131016
static const char *ImpliedExtsZdinx[] = {"zfinx"};
@@ -1080,6 +1083,7 @@ static constexpr ImpliedExtsEntry ImpliedExts[] = {
10801083
{{"zcd"}, {ImpliedExtsZcd}},
10811084
{{"zce"}, {ImpliedExtsZce}},
10821085
{{"zcf"}, {ImpliedExtsZcf}},
1086+
{{"zcmop"}, {ImpliedExtsZcmop}},
10831087
{{"zcmp"}, {ImpliedExtsZcmp}},
10841088
{{"zcmt"}, {ImpliedExtsZcmt}},
10851089
{{"zdinx"}, {ImpliedExtsZdinx}},

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,13 @@ def HasStdExtZimop : Predicate<"Subtarget->hasStdExtZimop()">,
693693
AssemblerPredicate<(all_of FeatureStdExtZimop),
694694
"'Zimop' (May-Be-Operations)">;
695695

696+
def FeatureStdExtZcmop : SubtargetFeature<"experimental-zcmop", "HasStdExtZcmop", "true",
697+
"'Zcmop' (Compressed May-Be-Operations)",
698+
[FeatureStdExtZca]>;
699+
def HasStdExtZcmop : Predicate<"Subtarget->hasStdExtZcmop()">,
700+
AssemblerPredicate<(all_of FeatureStdExtZcmop),
701+
"'Zcmop' (Compressed May-Be-Operations)">;
702+
696703
def FeatureStdExtSmaia
697704
: SubtargetFeature<"smaia", "HasStdExtSmaia", "true",
698705
"'Smaia' (Smaia encompasses all added CSRs and all "

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,7 @@ include "RISCVInstrInfoZicond.td"
21192119
// Compressed
21202120
include "RISCVInstrInfoC.td"
21212121
include "RISCVInstrInfoZc.td"
2122+
include "RISCVInstrInfoZcmop.td"
21222123

21232124
//===----------------------------------------------------------------------===//
21242125
// Vendor extensions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===-- RISCVInstrInfoZcmop.td -----------------------------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file describes the RISC-V instructions from the standard Compressed
10+
// May-Be-Operations Extension (Zcmop).
11+
// This version is still experimental as the 'Zcmop' extension hasn't been
12+
// ratified yet. It is based on v0.2 of the specification.
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
17+
class CMOPInst<bits<3> imm3, string opcodestr>
18+
: RVInst16CI<0b011, 0b01, (outs), (ins), opcodestr, ""> {
19+
let Inst{6-2} = 0;
20+
let Inst{7} = 1;
21+
let Inst{10-8} = imm3;
22+
let Inst{12-11} = 0;
23+
}
24+
25+
foreach i = 0...7 in {
26+
let Predicates = [HasStdExtZcmop] in {
27+
defvar n = !add(!mul(i, 2), 1);
28+
def CMOP # n : CMOPInst<i, "cmop." # n>, Sched<[]>;
29+
} // Predicates = [HasStdExtZcmop]
30+
}

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
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
8888
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zimop %s -o - | FileCheck --check-prefix=RV32ZIMOP %s
89+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcmop %s -o - | FileCheck --check-prefix=RV32ZCMOP %s
8990
; RUN: llc -mtriple=riscv32 -mattr=+smaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SMAIA %s
9091
; RUN: llc -mtriple=riscv32 -mattr=+ssaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SSAIA %s
9192
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZFBFMIN %s
@@ -179,6 +180,7 @@
179180
; RUN: llc -mtriple=riscv64 -mattr=+zvfh %s -o - | FileCheck --check-prefix=RV64ZVFH %s
180181
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV64ZICOND %s
181182
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zimop %s -o - | FileCheck --check-prefix=RV64ZIMOP %s
183+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcmop %s -o - | FileCheck --check-prefix=RV64ZCMOP %s
182184
; RUN: llc -mtriple=riscv64 -mattr=+smaia %s -o - | FileCheck --check-prefixes=CHECK,RV64SMAIA %s
183185
; RUN: llc -mtriple=riscv64 -mattr=+ssaia %s -o - | FileCheck --check-prefixes=CHECK,RV64SSAIA %s
184186
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZFBFMIN %s
@@ -274,6 +276,7 @@
274276
; RV32ZVFH: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfhmin1p0_zve32f1p0_zve32x1p0_zvfh1p0_zvfhmin1p0_zvl32b1p0"
275277
; RV32ZICOND: .attribute 5, "rv32i2p1_zicond1p0"
276278
; RV32ZIMOP: .attribute 5, "rv32i2p1_zimop0p1"
279+
; RV32ZCMOP: .attribute 5, "rv32i2p1_zca1p0_zcmop0p2"
277280
; RV32SMAIA: .attribute 5, "rv32i2p1_smaia1p0"
278281
; RV32SSAIA: .attribute 5, "rv32i2p1_ssaia1p0"
279282
; RV32ZFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p8"
@@ -366,6 +369,7 @@
366369
; RV64ZVFH: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfhmin1p0_zve32f1p0_zve32x1p0_zvfh1p0_zvfhmin1p0_zvl32b1p0"
367370
; RV64ZICOND: .attribute 5, "rv64i2p1_zicond1p0"
368371
; RV64ZIMOP: .attribute 5, "rv64i2p1_zimop0p1"
372+
; RV64ZCMOP: .attribute 5, "rv64i2p1_zca1p0_zcmop0p2"
369373
; RV64SMAIA: .attribute 5, "rv64i2p1_smaia1p0"
370374
; RV64SSAIA: .attribute 5, "rv64i2p1_ssaia1p0"
371375
; RV64ZFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin0p8"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zcmop < %s 2>&1 | FileCheck %s
2+
3+
cmop.0 # CHECK: :[[@LINE]]:1: error: unrecognized instruction mnemonic
4+
5+
cmop.1 t0 # CHECK: :[[@LINE]]:8: error: invalid operand for instruction
6+
7+
cmop.1 0x0 # CHECK: :[[@LINE]]:8: error: invalid operand for instruction

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zcmop -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
3+
# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zcmop -show-encoding \
4+
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
5+
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zcmop < %s \
6+
# RUN: | llvm-objdump --mattr=+experimental-zcmop -d -r - \
7+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
8+
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zcmop < %s \
9+
# RUN: | llvm-objdump --mattr=+experimental-zcmop -d -r - \
10+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
11+
12+
# CHECK-ASM-AND-OBJ: cmop.1
13+
# CHECK-ASM: encoding: [0x81,0x60]
14+
cmop.1
15+
16+
# CHECK-ASM-AND-OBJ: cmop.3
17+
# CHECK-ASM: encoding: [0x81,0x61]
18+
cmop.3
19+
20+
# CHECK-ASM-AND-OBJ: cmop.5
21+
# CHECK-ASM: encoding: [0x81,0x62]
22+
cmop.5
23+
24+
# CHECK-ASM-AND-OBJ: cmop.7
25+
# CHECK-ASM: encoding: [0x81,0x63]
26+
cmop.7
27+
28+
# CHECK-ASM-AND-OBJ: cmop.9
29+
# CHECK-ASM: encoding: [0x81,0x64]
30+
cmop.9
31+
32+
# CHECK-ASM-AND-OBJ: cmop.11
33+
# CHECK-ASM: encoding: [0x81,0x65]
34+
cmop.11
35+
36+
# CHECK-ASM-AND-OBJ: cmop.13
37+
# CHECK-ASM: encoding: [0x81,0x66]
38+
cmop.13
39+
40+
# CHECK-ASM-AND-OBJ: cmop.15
41+
# CHECK-ASM: encoding: [0x81,0x67]
42+
cmop.15

llvm/unittests/Support/RISCVISAInfoTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ Experimental extensions
759759
zimop 0.1
760760
zacas 1.0
761761
zfbfmin 0.8
762+
zcmop 0.2
762763
ztso 0.1
763764
zvfbfmin 0.8
764765
zvfbfwma 0.8

0 commit comments

Comments
 (0)