Skip to content

Commit 4c37d30

Browse files
quic-garvgupttopperc
authored andcommitted
[RISCV] Add support for custom instructions for Sifive S76.
Support for below instruction is added 1. CFLUSH.D.L1 2. CDISCARD.D.L1 3. CEASE Additionally, Zihintpause extension is added to sifive s76 for pause instruction. Spec - https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D153370
1 parent 4a32581 commit 4c37d30

File tree

11 files changed

+113
-2
lines changed

11 files changed

+113
-2
lines changed

clang/test/Driver/riscv-cpus.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@
112112
// MCPU-SIFIVE-S76: "-nostdsysteminc" "-target-cpu" "sifive-s76"
113113
// MCPU-SIFIVE-S76: "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d"
114114
// MCPU-SIFIVE-S76: "-target-feature" "+c"
115-
// MCPU-SIFIVE-S76: "-target-feature" "+zicsr" "-target-feature" "+zifencei"
115+
// MCPU-SIFIVE-S76: "-target-feature" "+zicsr" "-target-feature" "+zifencei" "-target-feature" "+zihintpause"
116+
// MCPU-SIFIVE-S76: "-target-feature" "+xsfcie"
116117
// MCPU-SIFIVE-S76: "-target-abi" "lp64d"
117118

118119
// mcpu with default march

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,6 @@ The current vendor extensions supported are:
273273

274274
``XCVmac``
275275
LLVM implements `version 1.3.1 of the Core-V Multiply-Accumulate (MAC) custom instructions specification <https://github.com/openhwgroup/cv32e40p/blob/4f024fe4b15a68b76615b0630c07a6745c620da7/docs/source/instruction_set_extensions.rst>`_ by Core-V. All instructions are prefixed with `cv.mac.` as described in the specification. These instructions are only available for riscv32 at this time.
276+
277+
``XSfcie``
278+
LLVM implements `version 1.0.0 of the SiFive Custom Instruction Extension (CIE) Software Specification <https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf>`_ by SiFive. All custom instruction are added as described in the specification, and the riscv-toolchain-convention document linked above. These instructions are only available for S76 processor at this time.

llvm/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ Changes to the RISC-V Backend
210210
extension disassembler/assembler.
211211
* Added support for the vendor-defined Xsfvcp (SiFive VCIX) extension
212212
disassembler/assembler.
213+
* Added support for the vendor-defined Xsfcie (SiFive CIE) extension
214+
disassembler/assembler.
213215
* Support for the now-ratified Zawrs extension is no longer experimental.
214216
* Adds support for the vendor-defined XTHeadCmo (cache management operations) extension.
215217
* Adds support for the vendor-defined XTHeadSync (multi-core synchronization instructions) extension.

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
6666
{"v", RISCVExtensionVersion{1, 0}},
6767

6868
// vendor-defined ('X') extensions
69+
{"xsfcie", RISCVExtensionVersion{1, 0}},
6970
{"xsfvcp", RISCVExtensionVersion{1, 0}},
7071
{"xtheadba", RISCVExtensionVersion{1, 0}},
7172
{"xtheadbb", RISCVExtensionVersion{1, 0}},

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
558558
"XTHeadVdot custom opcode table");
559559
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfvcp, DecoderTableXSfvcp32,
560560
"SiFive VCIX custom opcode table");
561+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfcie, DecoderTableXSfcie32,
562+
"Sifive CIE custom opcode table");
561563
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbitmanip,
562564
DecoderTableXCVbitmanip32,
563565
"CORE-V Bit Manipulation custom opcode table");

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,12 @@ def HasVendorXSfvcp : Predicate<"Subtarget->hasVendorXSfvcp()">,
752752
AssemblerPredicate<(all_of FeatureVendorXSfvcp),
753753
"'XSfvcp' (SiFive Custom Vector Coprocessor Interface Instructions)">;
754754

755+
def FeatureVendorXSfcie
756+
: SubtargetFeature<"xsfcie", "HasVendorXSfcie", "true",
757+
"'XSfcie' (SiFive Custom Instruction Extension SCIE.)">;
758+
def HasVendorXSfcie : Predicate<"Subtarget->hasVendorXSfcie()">,
759+
AssemblerPredicate<(all_of FeatureVendorXSfcie),
760+
"'XSfcie' (SiFive Custom Instruction Extension SCIE.)">;
755761

756762
def FeatureVendorXCVbitmanip
757763
: SubtargetFeature<"xcvbitmanip", "HasVendorXCVbitmanip", "true",

llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,27 @@ let Predicates = [HasVendorXSfvcp] in {
504504
}
505505
}
506506
}
507+
508+
let Predicates = [HasVendorXSfcie] in {
509+
let hasSideEffects = 1, mayLoad = 0, mayStore = 0, DecoderNamespace = "XSfcie" in {
510+
def SF_CFLUSH_D_L1 : RVInstI<0b000, OPC_SYSTEM, (outs), (ins GPR:$rs1), "cflush.d.l1","$rs1">,
511+
Sched<[]> {
512+
let rd = 0;
513+
let imm12 = {0b1111,0b1100,0b0000};
514+
}
515+
516+
def SF_CDISCARD_D_L1 : RVInstI<0b000, OPC_SYSTEM, (outs), (ins GPR:$rs1), "cdiscard.d.l1","$rs1">,
517+
Sched<[]> {
518+
let rd = 0;
519+
let imm12 = {0b1111,0b1100,0b0010};
520+
}
521+
522+
def SF_CEASE : RVInstI<0b000, OPC_SYSTEM, (outs), (ins), "cease","">, Sched<[]> {
523+
let rs1 = 0;
524+
let rd = 0;
525+
let imm12 = {0b0011,0b0000,0b0101};
526+
}
527+
}
528+
def : InstAlias<"cflush.d.l1", (SF_CFLUSH_D_L1 X0)>;
529+
def : InstAlias<"cdiscard.d.l1", (SF_CDISCARD_D_L1 X0)>;
530+
} // Predicates = [HasVendorXScie]

llvm/lib/Target/RISCV/RISCVProcessors.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def SIFIVE_S76 : RISCVProcessorModel<"sifive-s76",
142142
FeatureStdExtA,
143143
FeatureStdExtF,
144144
FeatureStdExtD,
145-
FeatureStdExtC],
145+
FeatureStdExtC,
146+
FeatureStdExtZihintpause,
147+
FeatureVendorXSfcie],
146148
[TuneSiFive7]>;
147149

148150
def SIFIVE_U54 : RISCVProcessorModel<"sifive-u54",

llvm/test/MC/RISCV/attribute-arch.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,6 @@
278278

279279
.attribute arch, "rv32i_zvfbfwma0p6"
280280
# CHECK: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfwma0p6_zvl32b1p0"
281+
282+
.attribute arch, "rv64i_xsfcie"
283+
# CHECK: attribute 5, "rv64i2p1_xsfcie1p0"

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SCIE - SiFive Custom Instructions Extension.
2+
# RUN: not llvm-mc -triple riscv32 -mattr=-xsfcie < %s 2>&1 | FileCheck %s
3+
# RUN: not llvm-mc -triple riscv64 -mattr=-xsfcie < %s 2>&1 | FileCheck %s
4+
5+
cflush.d.l1 0x10 # CHECK: :[[@LINE]]:13: error: invalid operand for instruction
6+
7+
cdiscard.d.l1 0x10 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction
8+
9+
cflush.d.l1 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
10+
11+
cdiscard.d.l1 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
12+
13+
cflush.d.l1 x0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
14+
15+
cflush.d.l1 x7 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
16+
17+
cdiscard.d.l1 x0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
18+
19+
cdiscard.d.l1 x7 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
20+
21+
cease x1 # CHECK: :[[@LINE]]:7: error: invalid operand for instruction
22+
23+
cease 0x10 # CHECK: :[[@LINE]]:7: error: invalid operand for instruction
24+
25+
cease # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)

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

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

0 commit comments

Comments
 (0)