Skip to content

Commit 1debf23

Browse files
[RISC-V] Added the mips extension instructions like ehb,ihb and pause etc for MIPS RV64 P8700. (#155747)
Please refer the https://mips.com/wp-content/uploads/2025/06/P8700_Programmers_Reference_Manual_Rev1.84_5-31-2025.pdf for more information . and files like RISCVInstrInfoXMips.td clang formatted . No Regression found. --------- Co-authored-by: Craig Topper <[email protected]>
1 parent 38268ec commit 1debf23

File tree

9 files changed

+72
-18
lines changed

9 files changed

+72
-18
lines changed

clang/test/Driver/print-supported-extensions-riscv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
// CHECK-NEXT: xcvsimd 1.0 'XCVsimd' (CORE-V SIMD ALU)
176176
// CHECK-NEXT: xmipscbop 1.0 'XMIPSCBOP' (MIPS Software Prefetch)
177177
// CHECK-NEXT: xmipscmov 1.0 'XMIPSCMov' (MIPS conditional move instruction (mips.ccmov))
178+
// CHECK-NEXT: xmipsexectl 1.0 'XMIPSEXECTL' (MIPS execution control)
178179
// CHECK-NEXT: xmipslsp 1.0 'XMIPSLSP' (MIPS optimization for hardware load-store bonding)
179180
// CHECK-NEXT: xsfcease 1.0 'XSfcease' (SiFive sf.cease Instruction)
180181
// CHECK-NEXT: xsfmm128t 0.6 'XSfmm128t' (TE=128 configuration)

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,13 @@ static constexpr FeatureBitset XSfSystemGroup = {
656656
RISCV::FeatureVendorXSiFivecflushdlone,
657657
};
658658

659+
static constexpr FeatureBitset XMIPSGroup = {
660+
RISCV::FeatureVendorXMIPSLSP,
661+
RISCV::FeatureVendorXMIPSCMov,
662+
RISCV::FeatureVendorXMIPSCBOP,
663+
RISCV::FeatureVendorXMIPSEXECTL,
664+
};
665+
659666
static constexpr FeatureBitset XTHeadGroup = {
660667
RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
661668
RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
@@ -684,13 +691,7 @@ static constexpr DecoderListEntry DecoderList32[]{
684691
{DecoderTableXSfvector32, XSfVectorGroup, "SiFive vector extensions"},
685692
{DecoderTableXSfsystem32, XSfSystemGroup, "SiFive system extensions"},
686693
{DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease}, "SiFive sf.cease"},
687-
{DecoderTableXmipslsp32, {RISCV::FeatureVendorXMIPSLSP}, "MIPS mips.lsp"},
688-
{DecoderTableXmipscmov32,
689-
{RISCV::FeatureVendorXMIPSCMov},
690-
"MIPS mips.ccmov"},
691-
{DecoderTableXmipscbop32,
692-
{RISCV::FeatureVendorXMIPSCBOP},
693-
"MIPS mips.pref"},
694+
{DecoderTableXMIPS32, XMIPSGroup, "Mips extensions"},
694695
{DecoderTableXAndes32, XAndesGroup, "Andes extensions"},
695696
{DecoderTableXSMT32, XSMTGroup, "SpacemiT extensions"},
696697
// Standard Extensions

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,20 +1403,27 @@ def HasVendorXMIPSCMov
14031403
AssemblerPredicate<(all_of FeatureVendorXMIPSCMov),
14041404
"'Xmipscmov' ('mips.ccmov' instruction)">;
14051405
def UseCCMovInsn : Predicate<"Subtarget->useCCMovInsn()">;
1406+
14061407
def FeatureVendorXMIPSLSP
14071408
: RISCVExtension<1, 0, "MIPS optimization for hardware load-store bonding">;
14081409
def HasVendorXMIPSLSP
14091410
: Predicate<"Subtarget->hasVendorXMIPSLSP()">,
14101411
AssemblerPredicate<(all_of FeatureVendorXMIPSLSP),
14111412
"'Xmipslsp' (load and store pair instructions)">;
1412-
def FeatureVendorXMIPSCBOP
1413-
: RISCVExtension<1, 0, "MIPS Software Prefetch">;
1413+
1414+
def FeatureVendorXMIPSCBOP : RISCVExtension<1, 0, "MIPS Software Prefetch">;
14141415
def HasVendorXMIPSCBOP
14151416
: Predicate<"Subtarget->hasVendorXMIPSCBOP()">,
14161417
AssemblerPredicate<(all_of FeatureVendorXMIPSCBOP),
14171418
"'Xmipscbop' (MIPS hardware prefetch)">;
14181419
def NoVendorXMIPSCBOP : Predicate<"!Subtarget->hasVendorXMIPSCBOP()">;
14191420

1421+
def FeatureVendorXMIPSEXECTL : RISCVExtension<1, 0, "MIPS execution control">;
1422+
def HasVendorXMIPSEXECTL
1423+
: Predicate<"Subtarget->hasVendorXMIPSEXT()">,
1424+
AssemblerPredicate<(all_of FeatureVendorXMIPSEXECTL),
1425+
"'Xmipsexectl' (MIPS execution control)">;
1426+
14201427
// WCH / Nanjing Qinheng Microelectronics Extension(s)
14211428

14221429
def FeatureVendorXwchc

llvm/lib/Target/RISCV/RISCVInstrInfoXMips.td

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,25 @@ class Mips_prefetch_ri<dag outs, dag ins, string opcodestr, string argstr>
125125
let Inst{6-0} = OPC_CUSTOM_0.Value;
126126
}
127127

128+
// MIPS Custom Barrier Insns Format.
129+
let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
130+
class MIPSExtInst_ri<bits<6> shimm5, string opcodestr>
131+
: RVInstIShift<0b00000, 0b001, OPC_OP_IMM, (outs), (ins), opcodestr, ""> {
132+
let shamt = shimm5;
133+
let rd = 0;
134+
let rs1 = 0;
135+
}
136+
128137
//===----------------------------------------------------------------------===//
129138
// MIPS extensions
130139
//===----------------------------------------------------------------------===//
131-
let Predicates = [HasVendorXMIPSCBOP] ,DecoderNamespace = "Xmipscbop" in {
140+
let Predicates = [HasVendorXMIPSEXECTL], DecoderNamespace = "XMIPS" in {
141+
def MIPS_EHB : MIPSExtInst_ri<0b000011, "mips.ehb">;
142+
def MIPS_IHB : MIPSExtInst_ri<0b000001, "mips.ihb">;
143+
def MIPS_PAUSE : MIPSExtInst_ri<0b000101, "mips.pause">;
144+
}
145+
146+
let Predicates = [HasVendorXMIPSCBOP], DecoderNamespace = "XMIPS" in {
132147
def MIPS_PREF : Mips_prefetch_ri<(outs), (ins GPR:$rs1, uimm9:$imm9, uimm5:$hint),
133148
"mips.pref", "$hint, ${imm9}(${rs1})">,
134149
Sched<[]>;
@@ -146,7 +161,7 @@ let Predicates = [HasVendorXMIPSCBOP] in {
146161
}
147162

148163
let Predicates = [HasVendorXMIPSCMov], hasSideEffects = 0, mayLoad = 0, mayStore = 0,
149-
DecoderNamespace = "Xmipscmov" in {
164+
DecoderNamespace = "XMIPS" in {
150165
def MIPS_CCMOV : RVInstR4<0b11, 0b011, OPC_CUSTOM_0, (outs GPR:$rd),
151166
(ins GPR:$rs1, GPR:$rs2, GPR:$rs3),
152167
"mips.ccmov", "$rd, $rs2, $rs1, $rs3">,
@@ -166,7 +181,7 @@ def : Pat<(select (XLenVT GPR:$rs2), (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
166181
}
167182

168183
let Predicates = [HasVendorXMIPSLSP], hasSideEffects = 0,
169-
DecoderNamespace = "Xmipslsp" in {
184+
DecoderNamespace = "XMIPS" in {
170185
let mayLoad = 1, mayStore = 0 in {
171186
def MIPS_LWP : LWPFormat<(outs GPR:$rd1, GPR:$rd2), (ins GPR:$rs1, uimm7_lsb00:$imm7),
172187
"mips.lwp", "$rd1, $rd2, ${imm7}(${rs1})">,
@@ -184,4 +199,4 @@ def MIPS_SDP : SDPFormat<(outs), (ins GPR:$rs2, GPR:$rs3, GPR:$rs1, uimm7_lsb000
184199
"mips.sdp", "$rs2, $rs3, ${imm7}(${rs1})">,
185200
Sched<[WriteSTD, ReadStoreData, ReadStoreData, ReadMemBase]>;
186201
} // mayLoad = 0, mayStore = 1
187-
} // Predicates = [HasVendorXMIPSLSP], hasSideEffects = 0, DecoderNamespace = "Xmipslsp"
202+
} // Predicates = [HasVendorXMIPSLSP], hasSideEffects = 0, DecoderNamespace = "XMIPS"

llvm/lib/Target/RISCV/RISCVProcessors.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def MIPS_P8700 : RISCVProcessorModel<"mips-p8700",
121121
FeatureStdExtZicsr,
122122
FeatureVendorXMIPSCMov,
123123
FeatureVendorXMIPSLSP,
124-
FeatureVendorXMIPSCBOP],
124+
FeatureVendorXMIPSCBOP,
125+
FeatureVendorXMIPSEXECTL],
125126
[TuneMIPSP8700]>;
126127

127128
def ROCKET_RV32 : RISCVProcessorModel<"rocket-rv32",

llvm/test/CodeGen/RISCV/features-info.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
; CHECK-NEXT: xcvsimd - 'XCVsimd' (CORE-V SIMD ALU).
200200
; CHECK-NEXT: xmipscbop - 'XMIPSCBOP' (MIPS Software Prefetch).
201201
; CHECK-NEXT: xmipscmov - 'XMIPSCMov' (MIPS conditional move instruction (mips.ccmov)).
202+
; CHECK-NEXT: mipsexectl - 'XMIPSEXECTL' (MIPS execution control).
202203
; CHECK-NEXT: xmipslsp - 'XMIPSLSP' (MIPS optimization for hardware load-store bonding).
203204
; CHECK-NEXT: xsfcease - 'XSfcease' (SiFive sf.cease Instruction).
204205
; CHECK-NEXT: xsfmm128t - 'XSfmm128t' (TE=128 configuration).

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# RUN: not llvm-mc -triple=riscv64 < %s 2>&1 | FileCheck %s -check-prefixes=CHECK-FEATURE
2-
# RUN: not llvm-mc -triple=riscv64 -mattr=+xmipslsp,+xmipscmov,+Xmipscbop < %s 2>&1 | FileCheck %s
2+
# RUN: not llvm-mc -triple=riscv64 -mattr=+xmipslsp,+xmipscmov,+xmipscbop,+xmipsexectl < %s 2>&1 | FileCheck %s
3+
4+
mips.pause 10
5+
# CHECK: error: invalid operand for instruction
6+
7+
mips.ehb 10
8+
# CHECK: error: invalid operand for instruction
9+
10+
mips.ihb 10
11+
# CHECK: error: invalid operand for instruction
312

413
mips.pref 8, 512(a0)
514
# CHECK: error: immediate offset must be in the range [0, 511]

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
# RUN: llvm-mc %s -triple=riscv64 -mattr=+xmipslsp,+xmipscmov,+xmipscbop -M no-aliases -show-encoding \
1+
# RUN: llvm-mc %s -triple=riscv64 -mattr=+xmipslsp,+xmipscmov,+xmipscbop,+xmipsexectl -M no-aliases -show-encoding \
22
# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-ENC %s
3-
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+xmipslsp,+xmipscmov,+xmipscbop < %s \
4-
# RUN: | llvm-objdump --mattr=+xmipslsp,+xmipscmov,+xmipscbop -M no-aliases -d - \
3+
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+xmipslsp,+xmipscmov,+xmipscbop,+xmipsexectl < %s \
4+
# RUN: | llvm-objdump --mattr=+xmipslsp,+xmipscmov,+xmipscbop,+xmipsexectl -M no-aliases -d - \
55
# RUN: | FileCheck -check-prefix=CHECK-DIS %s
66

7+
# CHECK-INST: mips.pause
8+
# CHECK-ENC: encoding: [0x13,0x10,0x50,0x00]
9+
mips.pause
10+
11+
# CHECK-DIS: mips.pause
12+
13+
# CHECK-INST: mips.ehb
14+
# CHECK-ENC: encoding: [0x13,0x10,0x30,0x00]
15+
mips.ehb
16+
17+
# CHECK-DIS: mips.ehb
18+
19+
# CHECK-INST: mips.ihb
20+
# CHECK-ENC: encoding: [0x13,0x10,0x10,0x00]
21+
mips.ihb
22+
23+
# CHECK-DIS: mips.ihb
24+
725
# CHECK-INST: mips.pref 8, 511(a0)
826
# CHECK-ENC: encoding: [0x0b,0x04,0xf5,0x1f]
927
mips.pref 8, 511(a0)

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ R"(All available -march extensions for RISC-V
11461146
xcvsimd 1.0
11471147
xmipscbop 1.0
11481148
xmipscmov 1.0
1149+
xmipsexectl 1.0
11491150
xmipslsp 1.0
11501151
xsfcease 1.0
11511152
xsfmm128t 0.6

0 commit comments

Comments
 (0)