Skip to content

Commit 7dca481

Browse files
committed
Added the mips extension instructions like ehb,ihb and pause etc.
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.
1 parent a2bc0ca commit 7dca481

File tree

8 files changed

+210
-94
lines changed

8 files changed

+210
-94
lines changed

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
@@ -1396,20 +1396,27 @@ def HasVendorXMIPSCMov
13961396
AssemblerPredicate<(all_of FeatureVendorXMIPSCMov),
13971397
"'Xmipscmov' ('mips.ccmov' instruction)">;
13981398
def UseCCMovInsn : Predicate<"Subtarget->useCCMovInsn()">;
1399+
13991400
def FeatureVendorXMIPSLSP
14001401
: RISCVExtension<1, 0, "MIPS optimization for hardware load-store bonding">;
14011402
def HasVendorXMIPSLSP
14021403
: Predicate<"Subtarget->hasVendorXMIPSLSP()">,
14031404
AssemblerPredicate<(all_of FeatureVendorXMIPSLSP),
14041405
"'Xmipslsp' (load and store pair instructions)">;
1405-
def FeatureVendorXMIPSCBOP
1406-
: RISCVExtension<1, 0, "MIPS Software Prefetch">;
1406+
1407+
def FeatureVendorXMIPSCBOP : RISCVExtension<1, 0, "MIPS Software Prefetch">;
14071408
def HasVendorXMIPSCBOP
14081409
: Predicate<"Subtarget->hasVendorXMIPSCBOP()">,
14091410
AssemblerPredicate<(all_of FeatureVendorXMIPSCBOP),
14101411
"'Xmipscbop' (MIPS hardware prefetch)">;
14111412
def NoVendorXMIPSCBOP : Predicate<"!Subtarget->hasVendorXMIPSCBOP()">;
14121413

1414+
def FeatureVendorXMIPSEXECTL : RISCVExtension<1, 0, "MIPS extensions">;
1415+
def HasVendorXMIPSEXECTL
1416+
: Predicate<"Subtarget->hasVendorXMIPSEXT()">,
1417+
AssemblerPredicate<(all_of FeatureVendorXMIPSEXECTL),
1418+
"'Xmipsexectl' (Mips extensions)">;
1419+
14131420
// WCH / Nanjing Qinheng Microelectronics Extension(s)
14141421

14151422
def FeatureVendorXwchc

llvm/lib/Target/RISCV/RISCVInstrInfoXMips.td

Lines changed: 158 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class LDPFormat<dag outs, dag ins, string opcodestr, string argstr>
4747
bits<5> rd1;
4848
bits<5> rd2;
4949

50-
let Inst{31-27} = rd2;
51-
let Inst{26-23} = imm7{6-3};
52-
let Inst{22-20} = 0b000;
53-
let Inst{19-15} = rs1;
54-
let Inst{14-12} = 0b100;
55-
let Inst{11-7} = rd1;
56-
let Inst{6-0} = OPC_CUSTOM_0.Value;
50+
let Inst{31 - 27} = rd2;
51+
let Inst{26 - 23} = imm7{6 - 3};
52+
let Inst{22 - 20} = 0b000;
53+
let Inst{19 - 15} = rs1;
54+
let Inst{14 - 12} = 0b100;
55+
let Inst{11 - 7} = rd1;
56+
let Inst{6 - 0} = OPC_CUSTOM_0.Value;
5757
}
5858

5959
// Load word pair format.
@@ -64,13 +64,13 @@ class LWPFormat<dag outs, dag ins, string opcodestr, string argstr>
6464
bits<5> rd1;
6565
bits<5> rd2;
6666

67-
let Inst{31-27} = rd2;
68-
let Inst{26-22} = imm7{6-2};
69-
let Inst{21-20} = 0b01;
70-
let Inst{19-15} = rs1;
71-
let Inst{14-12} = 0b100;
72-
let Inst{11-7} = rd1;
73-
let Inst{6-0} = OPC_CUSTOM_0.Value;
67+
let Inst{31 - 27} = rd2;
68+
let Inst{26 - 22} = imm7{6 - 2};
69+
let Inst{21 - 20} = 0b01;
70+
let Inst{19 - 15} = rs1;
71+
let Inst{14 - 12} = 0b100;
72+
let Inst{11 - 7} = rd1;
73+
let Inst{6 - 0} = OPC_CUSTOM_0.Value;
7474
}
7575

7676
// Store double pair format.
@@ -81,14 +81,14 @@ class SDPFormat<dag outs, dag ins, string opcodestr, string argstr>
8181
bits<5> rs2;
8282
bits<5> rs1;
8383

84-
let Inst{31-27} = rs3;
85-
let Inst{26-25} = imm7{6-5};
86-
let Inst{24-20} = rs2;
87-
let Inst{19-15} = rs1;
88-
let Inst{14-12} = 0b101;
89-
let Inst{11-10} = imm7{4-3};
90-
let Inst{9-7} = 0b000;
91-
let Inst{6-0} = OPC_CUSTOM_0.Value;
84+
let Inst{31 - 27} = rs3;
85+
let Inst{26 - 25} = imm7{6 - 5};
86+
let Inst{24 - 20} = rs2;
87+
let Inst{19 - 15} = rs1;
88+
let Inst{14 - 12} = 0b101;
89+
let Inst{11 - 10} = imm7{4 - 3};
90+
let Inst{9 - 7} = 0b000;
91+
let Inst{6 - 0} = OPC_CUSTOM_0.Value;
9292
}
9393

9494
// Store word pair format.
@@ -99,89 +99,167 @@ class SWPFormat<dag outs, dag ins, string opcodestr, string argstr>
9999
bits<5> rs2;
100100
bits<5> rs1;
101101

102-
let Inst{31-27} = rs3;
103-
let Inst{26-25} = imm7{6-5};
104-
let Inst{24-20} = rs2;
105-
let Inst{19-15} = rs1;
106-
let Inst{14-12} = 0b101;
107-
let Inst{11-9} = imm7{4-2};
108-
let Inst{8-7} = 0b01;
109-
let Inst{6-0} = OPC_CUSTOM_0.Value;
102+
let Inst{31 - 27} = rs3;
103+
let Inst{26 - 25} = imm7{6 - 5};
104+
let Inst{24 - 20} = rs2;
105+
let Inst{19 - 15} = rs1;
106+
let Inst{14 - 12} = 0b101;
107+
let Inst{11 - 9} = imm7{4 - 2};
108+
let Inst{8 - 7} = 0b01;
109+
let Inst{6 - 0} = OPC_CUSTOM_0.Value;
110110
}
111111

112112
// Prefetch format.
113-
let hasSideEffects = 0, mayLoad = 1, mayStore = 1 in
114-
class Mips_prefetch_ri<dag outs, dag ins, string opcodestr, string argstr>
113+
let hasSideEffects = 0, mayLoad = 1,
114+
mayStore = 1 in class
115+
Mips_prefetch_ri<dag outs, dag ins, string opcodestr, string argstr>
115116
: RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> {
116117
bits<9> imm9;
117118
bits<5> rs1;
118119
bits<5> hint;
119120

120-
let Inst{31-29} = 0b000;
121-
let Inst{28-20} = imm9;
122-
let Inst{19-15} = rs1;
123-
let Inst{14-12} = 0b000;
124-
let Inst{11-7} = hint;
125-
let Inst{6-0} = OPC_CUSTOM_0.Value;
121+
let Inst{31 - 29} = 0b000;
122+
let Inst{28 - 20} = imm9;
123+
let Inst{19 - 15} = rs1;
124+
let Inst{14 - 12} = 0b000;
125+
let Inst{11 - 7} = hint;
126+
let Inst{6 - 0} = OPC_CUSTOM_0.Value;
127+
}
128+
129+
// MIPS Ext Insns
130+
let hasSideEffects = 1, mayLoad = 0,
131+
mayStore = 0 in class MIPSExtInst_ri<bits<6> shimm5, string opcodestr>
132+
: RVInstIShift<0b00000, 0b001, OPC_OP_IMM, (outs), (ins), opcodestr, ""> {
133+
let shamt = shimm5;
134+
let rd = 0;
135+
let rs1 = 0;
126136
}
127137

128138
//===----------------------------------------------------------------------===//
129139
// MIPS extensions
130140
//===----------------------------------------------------------------------===//
131-
let Predicates = [HasVendorXMIPSCBOP] ,DecoderNamespace = "Xmipscbop" in {
132-
def MIPS_PREF : Mips_prefetch_ri<(outs), (ins GPR:$rs1, uimm9:$imm9, uimm5:$hint),
133-
"mips.pref", "$hint, ${imm9}(${rs1})">,
134-
Sched<[]>;
141+
let Predicates = [HasVendorXMIPSCBOP], DecoderNamespace = "XMIPS" in {
142+
def MIPS_PREF : Mips_prefetch_ri<(outs),
143+
(ins GPR
144+
: $rs1, uimm9
145+
: $imm9, uimm5
146+
: $hint),
147+
"mips.pref", "$hint, ${imm9}(${rs1})">,
148+
Sched<[]>;
149+
}
150+
151+
let Predicates = [HasVendorXMIPSEXECTL], DecoderNamespace = "XMIPS" in {
152+
def MIPS_EHB : MIPSExtInst_ri<0b000011, "mips.ehb">;
153+
def MIPS_IHB : MIPSExtInst_ri<0b000001, "mips.ihb">;
154+
def MIPS_PAUSE : MIPSExtInst_ri<0b000101, "mips.pause">;
135155
}
136156

137157
let Predicates = [HasVendorXMIPSCBOP] in {
138158
// Prefetch Data Write.
139-
def : Pat<(prefetch (AddrRegImm9 (XLenVT GPR:$rs1), uimm9:$imm9),
159+
def : Pat<(prefetch(AddrRegImm9(XLenVT GPR
160+
: $rs1),
161+
uimm9
162+
: $imm9),
140163
(i32 1), timm, (i32 1)),
141-
(MIPS_PREF GPR:$rs1, uimm9:$imm9, 9)>;
164+
(MIPS_PREF GPR
165+
: $rs1, uimm9
166+
: $imm9, 9)>;
142167
// Prefetch Data Read.
143-
def : Pat<(prefetch (AddrRegImm9 (XLenVT GPR:$rs1), uimm9:$imm9),
168+
def : Pat<(prefetch(AddrRegImm9(XLenVT GPR
169+
: $rs1),
170+
uimm9
171+
: $imm9),
144172
(i32 0), timm, (i32 1)),
145-
(MIPS_PREF GPR:$rs1, uimm9:$imm9, 8)>;
173+
(MIPS_PREF GPR
174+
: $rs1, uimm9
175+
: $imm9, 8)>;
146176
}
147177

148-
let Predicates = [HasVendorXMIPSCMov], hasSideEffects = 0, mayLoad = 0, mayStore = 0,
149-
DecoderNamespace = "Xmipscmov" in {
150-
def MIPS_CCMOV : RVInstR4<0b11, 0b011, OPC_CUSTOM_0, (outs GPR:$rd),
151-
(ins GPR:$rs1, GPR:$rs2, GPR:$rs3),
152-
"mips.ccmov", "$rd, $rs2, $rs1, $rs3">,
153-
Sched<[]>;
178+
let Predicates = [HasVendorXMIPSCMov], hasSideEffects = 0, mayLoad = 0,
179+
mayStore = 0, DecoderNamespace = "XMIPS" in {
180+
def MIPS_CCMOV : RVInstR4<0b11, 0b011, OPC_CUSTOM_0,
181+
(outs GPR
182+
: $rd),
183+
(ins GPR
184+
: $rs1, GPR
185+
: $rs2, GPR
186+
: $rs3),
187+
"mips.ccmov", "$rd, $rs2, $rs1, $rs3">,
188+
Sched<[]>;
154189
}
155190

156191
let Predicates = [UseCCMovInsn] in {
157-
def : Pat<(select (riscv_setne (XLenVT GPR:$rs2)),
158-
(XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
159-
(MIPS_CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
160-
def : Pat<(select (riscv_seteq (XLenVT GPR:$rs2)),
161-
(XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
162-
(MIPS_CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
163-
164-
def : Pat<(select (XLenVT GPR:$rs2), (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
165-
(MIPS_CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
192+
def : Pat<(select(riscv_setne(XLenVT GPR
193+
: $rs2)),
194+
(XLenVT GPR
195+
: $rs1),
196+
(XLenVT GPR
197+
: $rs3)),
198+
(MIPS_CCMOV GPR
199+
: $rs1, GPR
200+
: $rs2, GPR
201+
: $rs3)>;
202+
def : Pat<(select(riscv_seteq(XLenVT GPR
203+
: $rs2)),
204+
(XLenVT GPR
205+
: $rs3),
206+
(XLenVT GPR
207+
: $rs1)),
208+
(MIPS_CCMOV GPR
209+
: $rs1, GPR
210+
: $rs2, GPR
211+
: $rs3)>;
212+
213+
def : Pat<(select(XLenVT GPR
214+
: $rs2),
215+
(XLenVT GPR
216+
: $rs1),
217+
(XLenVT GPR
218+
: $rs3)),
219+
(MIPS_CCMOV GPR
220+
: $rs1, GPR
221+
: $rs2, GPR
222+
: $rs3)>;
166223
}
167224

168225
let Predicates = [HasVendorXMIPSLSP], hasSideEffects = 0,
169-
DecoderNamespace = "Xmipslsp" in {
170-
let mayLoad = 1, mayStore = 0 in {
171-
def MIPS_LWP : LWPFormat<(outs GPR:$rd1, GPR:$rd2), (ins GPR:$rs1, uimm7_lsb00:$imm7),
172-
"mips.lwp", "$rd1, $rd2, ${imm7}(${rs1})">,
173-
Sched<[WriteLDW, WriteLDW, ReadMemBase]>;
174-
def MIPS_LDP : LDPFormat<(outs GPR:$rd1, GPR:$rd2), (ins GPR:$rs1, uimm7_lsb000:$imm7),
175-
"mips.ldp", "$rd1, $rd2, ${imm7}(${rs1})">,
176-
Sched<[WriteLDD, WriteLDD, ReadMemBase]>;
177-
} // mayLoad = 1, mayStore = 0
178-
179-
let mayLoad = 0, mayStore = 1 in {
180-
def MIPS_SWP : SWPFormat<(outs), (ins GPR:$rs2, GPR:$rs3, GPR:$rs1, uimm7_lsb00:$imm7),
181-
"mips.swp", "$rs2, $rs3, ${imm7}(${rs1})">,
182-
Sched<[WriteSTW, ReadStoreData, ReadStoreData, ReadMemBase]>;
183-
def MIPS_SDP : SDPFormat<(outs), (ins GPR:$rs2, GPR:$rs3, GPR:$rs1, uimm7_lsb000:$imm7),
184-
"mips.sdp", "$rs2, $rs3, ${imm7}(${rs1})">,
185-
Sched<[WriteSTD, ReadStoreData, ReadStoreData, ReadMemBase]>;
186-
} // mayLoad = 0, mayStore = 1
187-
} // Predicates = [HasVendorXMIPSLSP], hasSideEffects = 0, DecoderNamespace = "Xmipslsp"
226+
DecoderNamespace = "XMIPS" in {
227+
let mayLoad = 1, mayStore = 0 in {
228+
def MIPS_LWP : LWPFormat<(outs GPR
229+
: $rd1, GPR
230+
: $rd2),
231+
(ins GPR
232+
: $rs1, uimm7_lsb00
233+
: $imm7),
234+
"mips.lwp", "$rd1, $rd2, ${imm7}(${rs1})">,
235+
Sched<[WriteLDW, WriteLDW, ReadMemBase]>;
236+
def MIPS_LDP : LDPFormat<(outs GPR
237+
: $rd1, GPR
238+
: $rd2),
239+
(ins GPR
240+
: $rs1, uimm7_lsb000
241+
: $imm7),
242+
"mips.ldp", "$rd1, $rd2, ${imm7}(${rs1})">,
243+
Sched<[WriteLDD, WriteLDD, ReadMemBase]>;
244+
} // mayLoad = 1, mayStore = 0
245+
246+
let mayLoad = 0, mayStore = 1 in {
247+
def MIPS_SWP : SWPFormat<(outs),
248+
(ins GPR
249+
: $rs2, GPR
250+
: $rs3, GPR
251+
: $rs1, uimm7_lsb00
252+
: $imm7),
253+
"mips.swp", "$rs2, $rs3, ${imm7}(${rs1})">,
254+
Sched<[WriteSTW, ReadStoreData, ReadStoreData, ReadMemBase]>;
255+
def MIPS_SDP : SDPFormat<(outs),
256+
(ins GPR
257+
: $rs2, GPR
258+
: $rs3, GPR
259+
: $rs1, uimm7_lsb000
260+
: $imm7),
261+
"mips.sdp", "$rs2, $rs3, ${imm7}(${rs1})">,
262+
Sched<[WriteSTD, ReadStoreData, ReadStoreData, ReadMemBase]>;
263+
} // mayLoad = 0, mayStore = 1
264+
} // Predicates = [HasVendorXMIPSLSP], hasSideEffects = 0, DecoderNamespace =
265+
// "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
@@ -198,6 +198,7 @@
198198
; CHECK-NEXT: xcvsimd - 'XCVsimd' (CORE-V SIMD ALU).
199199
; CHECK-NEXT: xmipscbop - 'XMIPSCBOP' (MIPS Software Prefetch).
200200
; CHECK-NEXT: xmipscmov - 'XMIPSCMov' (MIPS conditional move instruction (mips.ccmov)).
201+
; CHECK-NEXT: mipsexectl - 'XMIPSEXECTL' (MIPS extensions).
201202
; CHECK-NEXT: xmipslsp - 'XMIPSLSP' (MIPS optimization for hardware load-store bonding).
202203
; CHECK-NEXT: xsfcease - 'XSfcease' (SiFive sf.cease Instruction).
203204
; 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]

0 commit comments

Comments
 (0)