Skip to content

Commit 0cb7636

Browse files
authored
[RISCV] Add MIPS extensions (#121394)
Adding two extensions for MIPS p8700 CPU: 1. cmove (conditional move) 2. lsp (load/store pair) The official product page here: https://mips.com/products/hardware/p8700
1 parent b968fd9 commit 0cb7636

22 files changed

+453
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@
157157
// CHECK-NEXT: xcvmac 1.0 'XCVmac' (CORE-V Multiply-Accumulate)
158158
// CHECK-NEXT: xcvmem 1.0 'XCVmem' (CORE-V Post-incrementing Load & Store)
159159
// CHECK-NEXT: xcvsimd 1.0 'XCVsimd' (CORE-V SIMD ALU)
160+
// CHECK-NEXT: xmipscmove 1.0 'XMIPSCMove' (MIPS conditional move instruction(s) (ccmov))
161+
// CHECK-NEXT: xmipslsp 1.0 'XMIPSLSP' (MIPS optimization for hardware load-store bonding)
160162
// CHECK-NEXT: xsfcease 1.0 'XSfcease' (SiFive sf.cease Instruction)
161163
// CHECK-NEXT: xsfvcp 1.0 'XSfvcp' (SiFive Custom Vector Coprocessor Interface Instructions)
162164
// CHECK-NEXT: xsfvfnrclipxfqf 1.0 'XSfvfnrclipxfqf' (SiFive FP32-to-int8 Ranged Clip Instructions)

llvm/docs/RISCVUsage.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,12 @@ The current vendor extensions supported are:
459459
``experimental-Xqcisls``
460460
LLVM implements `version 0.2 of the Qualcomm uC Scaled Load Store extension specification <https://github.com/quic/riscv-unified-db/releases/latest>`__ by Qualcomm. All instructions are prefixed with `qc.` as described in the specification. These instructions are only available for riscv32.
461461

462+
``Xmipscmove``
463+
LLVM implements conditional move for the `p8700 processor <https://mips.com/products/hardware/p8700/>` by MIPS.
464+
465+
``Xmipslsp``
466+
LLVM implements load/store pair instructions for the `p8700 processor <https://mips.com/products/hardware/p8700/>` by MIPS.
467+
462468
Experimental C Intrinsics
463469
=========================
464470

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,16 @@ struct RISCVOperand final : public MCParsedAsmOperand {
877877
VK == RISCVMCExpr::VK_RISCV_None;
878878
}
879879

880+
bool isUImm7Lsb000() const {
881+
if (!isImm())
882+
return false;
883+
int64_t Imm;
884+
RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
885+
bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
886+
return IsConstantImm && isShiftedUInt<4, 3>(Imm) &&
887+
VK == RISCVMCExpr::VK_RISCV_None;
888+
}
889+
880890
bool isUImm8Lsb00() const {
881891
if (!isImm())
882892
return false;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,11 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
681681
"SiFive sf.cflush.d.l1 custom opcode table");
682682
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfcease, DecoderTableXSfcease32,
683683
"SiFive sf.cease custom opcode table");
684+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXMIPSLSP, DecoderTableXmipslsp32,
685+
"MIPS mips.lsp custom opcode table");
686+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXMIPSCMove,
687+
DecoderTableXmipscmove32,
688+
"MIPS mips.ccmov custom opcode table");
684689
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbitmanip,
685690
DecoderTableXCVbitmanip32,
686691
"CORE-V Bit Manipulation custom opcode table");

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ enum OperandType : unsigned {
308308
OPERAND_UIMM6_LSB0,
309309
OPERAND_UIMM7,
310310
OPERAND_UIMM7_LSB00,
311+
OPERAND_UIMM7_LSB000,
311312
OPERAND_UIMM8_LSB00,
312313
OPERAND_UIMM8,
313314
OPERAND_UIMM8_LSB000,

llvm/lib/Target/RISCV/RISCV.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ void initializeRISCVMoveMergePass(PassRegistry &);
8484

8585
FunctionPass *createRISCVPushPopOptimizationPass();
8686
void initializeRISCVPushPopOptPass(PassRegistry &);
87+
FunctionPass *createRISCVLoadStoreOptPass();
88+
void initializeRISCVLoadStoreOptPass(PassRegistry &);
8789

8890
FunctionPass *createRISCVZacasABIFixPass();
8991
void initializeRISCVZacasABIFixPass(PassRegistry &);

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,21 @@ def HasVendorXCVbi
12281228
: Predicate<"Subtarget->hasVendorXCVbi()">,
12291229
AssemblerPredicate<(all_of FeatureVendorXCVbi),
12301230
"'XCVbi' (CORE-V Immediate Branching)">;
1231+
// MIPS Extensions
1232+
1233+
def FeatureVendorXMIPSCMove
1234+
: RISCVExtension<1, 0, "MIPS conditional move instruction(s) (ccmov)">;
1235+
def HasVendorXMIPSCMove
1236+
: Predicate<"Subtarget->hasVendorXMIPSCMove()">,
1237+
AssemblerPredicate<(all_of FeatureVendorXMIPSCMove),
1238+
"'Xmipscmove' ('mips.ccmov' instruction)">;
1239+
def UseCCMovInsn : Predicate<"Subtarget->useCCMovInsn()">;
1240+
def FeatureVendorXMIPSLSP
1241+
: RISCVExtension<1, 0, "MIPS optimization for hardware load-store bonding">;
1242+
def HasVendorXMIPSLSP
1243+
: Predicate<"Subtarget->hasVendorXMIPSLSP()">,
1244+
AssemblerPredicate<(all_of FeatureVendorXMIPSLSP),
1245+
"'Xmipslsp' (load and store pair instructions)">;
12311246

12321247
// WCH / Nanjing Qinheng Microelectronics Extension(s)
12331248

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
409409
setOperationAction(ISD::ABS, MVT::i32, Custom);
410410
}
411411

412-
if (!Subtarget.hasVendorXTHeadCondMov())
412+
if (Subtarget.useCCMovInsn())
413+
setOperationAction(ISD::SELECT, XLenVT, Legal);
414+
else if (!Subtarget.hasVendorXTHeadCondMov())
413415
setOperationAction(ISD::SELECT, XLenVT, Custom);
414416

415417
static const unsigned FPLegalNodeTypes[] = {

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,9 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
24882488
case RISCVOp::OPERAND_UIMM7_LSB00:
24892489
Ok = isShiftedUInt<5, 2>(Imm);
24902490
break;
2491+
case RISCVOp::OPERAND_UIMM7_LSB000:
2492+
Ok = isShiftedUInt<4, 3>(Imm);
2493+
break;
24912494
case RISCVOp::OPERAND_UIMM8_LSB00:
24922495
Ok = isShiftedUInt<6, 2>(Imm);
24932496
break;

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ def ixlenimm_li_restricted : Operand<XLenVT> {
399399

400400
// Standalone (codegen-only) immleaf patterns.
401401

402+
// A 12-bit signed immediate plus one where the imm range will be -2047~2048.
403+
def simm12_plus1 : ImmLeaf<XLenVT,
404+
[{return (isInt<12>(Imm) && Imm != -2048) || Imm == 2048;}]>;
405+
402406
// A 6-bit constant greater than 32.
403407
def uimm6gt32 : ImmLeaf<XLenVT, [{
404408
return isUInt<6>(Imm) && Imm > 32;
@@ -2133,6 +2137,7 @@ include "RISCVInstrInfoSFB.td"
21332137
include "RISCVInstrInfoXCV.td"
21342138
include "RISCVInstrInfoXwch.td"
21352139
include "RISCVInstrInfoXqci.td"
2140+
include "RISCVInstrInfoXMips.td"
21362141

21372142
//===----------------------------------------------------------------------===//
21382143
// Global ISel

0 commit comments

Comments
 (0)