Skip to content

Commit 207e45f

Browse files
authored
[RISCV] Add back SiFive's cdiscard.d.l1, cflush.d.l1, and cease instructions. (#83896)
These were in LLVM 17 but removed from LLVM 18 due to an incorrect extension name being used. This restores them with new extension names that match SiFive's downstream compiler. The extension name has been used internally for some time. It uses XSiFive instead of XSf like the newer extensions. `cease` did not have an internal extension name so its using the `XSf` convention. The spec for the instructions is here https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf though the extension name is not listed. Column width in the extension printing had to be changed to accommodate a longer extension name.
1 parent 003e292 commit 207e45f

File tree

9 files changed

+325
-163
lines changed

9 files changed

+325
-163
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@
5656
// CHECK-NOT: __riscv_xcvmac {{.*$}}
5757
// CHECK-NOT: __riscv_xcvmem {{.*$}}
5858
// CHECK-NOT: __riscv_xcvsimd {{.*$}}
59+
// CHECK-NOT: __riscv_xsfcease {{.*$}}
5960
// CHECK-NOT: __riscv_xsfvcp {{.*$}}
6061
// CHECK-NOT: __riscv_xsfvfnrclipxfqf {{.*$}}
6162
// CHECK-NOT: __riscv_xsfvfwmaccqqq {{.*$}}
6263
// CHECK-NOT: __riscv_xsfqmaccdod {{.*$}}
6364
// CHECK-NOT: __riscv_xsfvqmaccqoq {{.*$}}
65+
// CHECK-NOT: __riscv_xsifivecdiscarddlone {{.*$}}
66+
// CHECK-NOT: __riscv_xsifivecflushdlone {{.*$}}
6467
// CHECK-NOT: __riscv_xtheadba {{.*$}}
6568
// CHECK-NOT: __riscv_xtheadbb {{.*$}}
6669
// CHECK-NOT: __riscv_xtheadbs {{.*$}}
@@ -517,6 +520,14 @@
517520
// RUN: -o - | FileCheck --check-prefix=CHECK-XCVSIMD-EXT %s
518521
// CHECK-XCVSIMD-EXT: __riscv_xcvsimd 1000000{{$}}
519522

523+
// RUN: %clang --target=riscv32-unknown-linux-gnu \
524+
// RUN: -march=rv32ixsfcease -E -dM %s \
525+
// RUN: -o - | FileCheck --check-prefix=CHECK-XSFCEASE-EXT %s
526+
// RUN: %clang --target=riscv64-unknown-linux-gnu \
527+
// RUN: -march=rv64ixsfcease -E -dM %s \
528+
// RUN: -o - | FileCheck --check-prefix=CHECK-XSFCEASE-EXT %s
529+
// CHECK-XSFCEASE-EXT: __riscv_xsfcease 1000000{{$}}
530+
520531
// RUN: %clang --target=riscv32-unknown-linux-gnu \
521532
// RUN: -march=rv32ixsfvcp -E -dM %s \
522533
// RUN: -o - | FileCheck --check-prefix=CHECK-XSFVCP-EXT %s
@@ -557,6 +568,22 @@
557568
// RUN: -o - | FileCheck --check-prefix=CHECK-XSFVQMACCQOQ-EXT %s
558569
// CHECK-XSFVQMACCQOQ-EXT: __riscv_xsfvqmaccqoq 1000000{{$}}
559570

571+
// RUN: %clang --target=riscv32-unknown-linux-gnu \
572+
// RUN: -march=rv32ixsifivecdiscarddlone -E -dM %s \
573+
// RUN: -o - | FileCheck --check-prefix=CHECK-XSIFIVECDISCARDDLONE-EXT %s
574+
// RUN: %clang --target=riscv64-unknown-linux-gnu \
575+
// RUN: -march=rv64ixsifivecdiscarddlone -E -dM %s \
576+
// RUN: -o - | FileCheck --check-prefix=CHECK-XSIFIVECDISCARDDLONE-EXT %s
577+
// CHECK-XSIFIVECDISCARDDLONE-EXT: __riscv_xsifivecdiscarddlone 1000000{{$}}
578+
579+
// RUN: %clang --target=riscv32-unknown-linux-gnu \
580+
// RUN: -march=rv32ixsifivecflushdlone -E -dM %s \
581+
// RUN: -o - | FileCheck --check-prefix=CHECK-XSIFIVECFLUSHDLONE-EXT %s
582+
// RUN: %clang --target=riscv64-unknown-linux-gnu \
583+
// RUN: -march=rv64ixsifivecflushdlone -E -dM %s \
584+
// RUN: -o - | FileCheck --check-prefix=CHECK-XSIFIVECFLUSHDLONE-EXT %s
585+
// CHECK-XSIFIVECFLUSHDLONE-EXT: __riscv_xsifivecflushdlone 1000000{{$}}
586+
560587
// RUN: %clang --target=riscv32-unknown-linux-gnu \
561588
// RUN: -march=rv32ixtheadba -E -dM %s \
562589
// RUN: -o - | FileCheck --check-prefix=CHECK-XTHEADBA-EXT %s

llvm/docs/RISCVUsage.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ The current vendor extensions supported are:
362362
``XCVbi``
363363
LLVM implements `version 1.0.0 of the CORE-V immediate branching custom instructions specification <https://github.com/openhwgroup/cv32e40p/blob/cv32e40p_v1.3.2/docs/source/instruction_set_extensions.rst>`__ by OpenHW Group. All instructions are prefixed with `cv.` as described in the specification. These instructions are only available for riscv32 at this time.
364364

365+
``XSiFivecdiscarddlone``
366+
LLVM implements `the SiFive sf.cdiscard.d.l1 instruction specified in <https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf>`_ by SiFive.
367+
368+
``XSiFivecflushdlone``
369+
LLVM implements `the SiFive sf.cflush.d.l1 instruction specified in <https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf>`_ by SiFive.
370+
371+
``XSfcease``
372+
LLVM implements `the SiFive sf.cease instruction specified in <https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf>`_ by SiFive.
373+
365374
Experimental C Intrinsics
366375
=========================
367376

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,14 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
9090
{"xcvmac", {1, 0}},
9191
{"xcvmem", {1, 0}},
9292
{"xcvsimd", {1, 0}},
93+
{"xsfcease", {1, 0}},
9394
{"xsfvcp", {1, 0}},
9495
{"xsfvfnrclipxfqf", {1, 0}},
9596
{"xsfvfwmaccqqq", {1, 0}},
9697
{"xsfvqmaccdod", {1, 0}},
9798
{"xsfvqmaccqoq", {1, 0}},
99+
{"xsifivecdiscarddlone", {1, 0}},
100+
{"xsifivecflushdlone", {1, 0}},
98101
{"xtheadba", {1, 0}},
99102
{"xtheadbb", {1, 0}},
100103
{"xtheadbs", {1, 0}},
@@ -258,7 +261,7 @@ static void PrintExtension(StringRef Name, StringRef Version,
258261
StringRef Description) {
259262
outs().indent(4);
260263
unsigned VersionWidth = Description.empty() ? 0 : 10;
261-
outs() << left_justify(Name, 20) << left_justify(Version, VersionWidth)
264+
outs() << left_justify(Name, 21) << left_justify(Version, VersionWidth)
262265
<< Description << "\n";
263266
}
264267

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,14 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
595595
TRY_TO_DECODE_FEATURE(
596596
RISCV::FeatureVendorXSfvfnrclipxfqf, DecoderTableXSfvfnrclipxfqf32,
597597
"SiFive FP32-to-int8 Ranged Clip Instructions opcode table");
598+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSiFivecdiscarddlone,
599+
DecoderTableXSiFivecdiscarddlone32,
600+
"SiFive sf.cdiscard.d.l1 custom opcode table");
601+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSiFivecflushdlone,
602+
DecoderTableXSiFivecflushdlone32,
603+
"SiFive sf.cflush.d.l1 custom opcode table");
604+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfcease, DecoderTableXSfcease32,
605+
"SiFive sf.cease custom opcode table");
598606
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbitmanip,
599607
DecoderTableXCVbitmanip32,
600608
"CORE-V Bit Manipulation custom opcode table");

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,30 @@ def HasVendorXSfvfnrclipxfqf
10581058
AssemblerPredicate<(all_of FeatureVendorXSfvfnrclipxfqf),
10591059
"'XSfvfnrclipxfqf' (SiFive FP32-to-int8 Ranged Clip Instructions)">;
10601060

1061+
def FeatureVendorXSiFivecdiscarddlone
1062+
: SubtargetFeature<"xsifivecdiscarddlone", "HasVendorXSiFivecdiscarddlone", "true",
1063+
"'XSiFivecdiscarddlone' (SiFive sf.cdiscard.d.l1 Instruction)", []>;
1064+
def HasVendorXSiFivecdiscarddlone
1065+
: Predicate<"Subtarget->hasVendorXSiFivecdiscarddlone()">,
1066+
AssemblerPredicate<(all_of FeatureVendorXSiFivecdiscarddlone),
1067+
"'XSiFivecdiscarddlone' (SiFive sf.cdiscard.d.l1 Instruction)">;
1068+
1069+
def FeatureVendorXSiFivecflushdlone
1070+
: SubtargetFeature<"xsifivecflushdlone", "HasVendorXSiFivecflushdlone", "true",
1071+
"'XSiFivecflushdlone' (SiFive sf.cflush.d.l1 Instruction)", []>;
1072+
def HasVendorXSiFivecflushdlone
1073+
: Predicate<"Subtarget->hasVendorXSiFivecflushdlone()">,
1074+
AssemblerPredicate<(all_of FeatureVendorXSiFivecflushdlone),
1075+
"'XSiFivecflushdlone' (SiFive sf.cflush.d.l1 Instruction)">;
1076+
1077+
def FeatureVendorXSfcease
1078+
: SubtargetFeature<"xsfcease", "HasVendorXSfcease", "true",
1079+
"'XSfcease' (SiFive sf.cease Instruction)", []>;
1080+
def HasVendorXSfcease
1081+
: Predicate<"Subtarget->hasVendorXSfcease()">,
1082+
AssemblerPredicate<(all_of FeatureVendorXSfcease),
1083+
"'XSfcease' (SiFive sf.cease Instruction)">;
1084+
10611085
// Core-V Extensions
10621086

10631087
def FeatureVendorXCVelw

llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,35 @@ let Predicates = [HasVendorXSfvfnrclipxfqf] in {
808808
defm : VPatVFNRCLIP<"vfnrclip_xu_f_qf", "VFNRCLIP_XU_F_QF">;
809809
defm : VPatVFNRCLIP<"vfnrclip_x_f_qf", "VFNRCLIP_X_F_QF">;
810810
}
811+
812+
let Predicates = [HasVendorXSiFivecdiscarddlone] in {
813+
let hasNoSchedulingInfo = 1, hasSideEffects = 1, mayLoad = 0, mayStore = 0,
814+
DecoderNamespace = "XSiFivecdiscarddlone" in
815+
def SF_CDISCARD_D_L1
816+
: RVInstIUnary<0b111111000010, 0b000, OPC_SYSTEM, (outs), (ins GPR:$rs1),
817+
"sf.cdiscard.d.l1", "$rs1">, Sched<[]> {
818+
let rd = 0;
819+
}
820+
def : InstAlias<"sf.cdiscard.d.l1", (SF_CDISCARD_D_L1 X0)>;
821+
} // Predicates = [HasVendorXSifivecdiscarddlone]
822+
823+
let Predicates = [HasVendorXSiFivecflushdlone] in {
824+
let hasNoSchedulingInfo = 1, hasSideEffects = 1, mayLoad = 0, mayStore = 0,
825+
DecoderNamespace = "XSiFivecflushdlone" in
826+
def SF_CFLUSH_D_L1
827+
: RVInstIUnary<0b111111000000, 0b000, OPC_SYSTEM, (outs), (ins GPR:$rs1),
828+
"sf.cflush.d.l1", "$rs1">, Sched<[]> {
829+
let rd = 0;
830+
}
831+
def : InstAlias<"sf.cflush.d.l1", (SF_CFLUSH_D_L1 X0)>;
832+
} // Predicates = [HasVendorXSifivecflushdlone]
833+
834+
let Predicates = [HasVendorXSfcease] in {
835+
let hasNoSchedulingInfo = 1, hasSideEffects = 1, mayLoad = 0, mayStore = 0,
836+
DecoderNamespace = "XSfcease" in
837+
def SF_CEASE : RVInstIUnary<0b001100000101, 0b000, OPC_SYSTEM, (outs), (ins),
838+
"sf.cease", "">, Sched<[]> {
839+
let rs1 = 0b00000;
840+
let rd = 0b00000;
841+
}
842+
}

llvm/test/MC/RISCV/xsifive-invalid.s

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# RUN: not llvm-mc -triple riscv32 < %s 2>&1 | FileCheck %s
2+
# RUN: not llvm-mc -triple riscv64 < %s 2>&1 | FileCheck %s
3+
4+
sf.cflush.d.l1 0x10 # CHECK: :[[@LINE]]:16: error: invalid operand for instruction
5+
6+
sf.cdiscard.d.l1 0x10 # CHECK: :[[@LINE]]:18: error: invalid operand for instruction
7+
8+
sf.cflush.d.l1 x0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSiFivecflushdlone' (SiFive sf.cflush.d.l1 Instruction){{$}}
9+
10+
sf.cflush.d.l1 x7 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSiFivecflushdlone' (SiFive sf.cflush.d.l1 Instruction){{$}}
11+
12+
sf.cdiscard.d.l1 x0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSiFivecdiscarddlone' (SiFive sf.cdiscard.d.l1 Instruction){{$}}
13+
14+
sf.cdiscard.d.l1 x7 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSiFivecdiscarddlone' (SiFive sf.cdiscard.d.l1 Instruction){{$}}
15+
16+
sf.cease x1 # CHECK: :[[@LINE]]:10: error: invalid operand for instruction
17+
18+
sf.cease 0x10 # CHECK: :[[@LINE]]:10: error: invalid operand for instruction
19+
20+
sf.cease # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcease' (SiFive sf.cease Instruction){{$}}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+xsifivecdiscarddlone,+xsifivecflushdlone,+xsfcease -riscv-no-aliases -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
3+
# RUN: llvm-mc %s -triple=riscv64 -mattr=+xsifivecdiscarddlone,+xsifivecflushdlone,+xsfcease -riscv-no-aliases -show-encoding \
4+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
5+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+xsifivecdiscarddlone,+xsifivecflushdlone,+xsfcease < %s \
6+
# RUN: | llvm-objdump --mattr=+xsifivecdiscarddlone,+xsifivecflushdlone,+xsfcease -M no-aliases -d - \
7+
# RUN: | FileCheck -check-prefix=CHECK-INST %s
8+
# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+xsifivecdiscarddlone,+xsifivecflushdlone,+xsfcease < %s \
9+
# RUN: | llvm-objdump --mattr=+xsifivecdiscarddlone,+xsifivecflushdlone,+xsfcease -M no-aliases -d - \
10+
# RUN: | FileCheck -check-prefix=CHECK-INST %s
11+
12+
# CHECK-INST: sf.cflush.d.l1 zero
13+
# CHECK-ENC: encoding: [0x73,0x00,0x00,0xfc]
14+
sf.cflush.d.l1 x0
15+
# CHECK-INST: sf.cflush.d.l1 zero
16+
# CHECK-ENC: encoding: [0x73,0x00,0x00,0xfc]
17+
sf.cflush.d.l1
18+
19+
# CHECK-INST: sf.cflush.d.l1 t2
20+
# CHECK-ENC: encoding: [0x73,0x80,0x03,0xfc]
21+
sf.cflush.d.l1 x7
22+
23+
# CHECK-INST: sf.cdiscard.d.l1 zero
24+
# CHECK-ENC: encoding: [0x73,0x00,0x20,0xfc]
25+
sf.cdiscard.d.l1 x0
26+
# CHECK-INST: sf.cdiscard.d.l1 zero
27+
# CHECK-ENC: encoding: [0x73,0x00,0x20,0xfc]
28+
sf.cdiscard.d.l1
29+
30+
# CHECK-INST: sf.cdiscard.d.l1 t2
31+
# CHECK-ENC: encoding: [0x73,0x80,0x23,0xfc]
32+
sf.cdiscard.d.l1 x7
33+
34+
# CHECK-INST: sf.cease
35+
# CHECK-ENC: encoding: [0x73,0x00,0x50,0x30]
36+
sf.cease

0 commit comments

Comments
 (0)