//===-- RISCVInstrInfoVPseudos.td - RISC-V 'V' Pseudos -----*- tablegen -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// This file contains the required infrastructure to support code generation /// for the standard 'V' (Vector) extension, version 0.9. This version is still /// experimental as the 'V' extension hasn't been ratified yet. /// /// This file is included from RISCVInstrInfoV.td /// //===----------------------------------------------------------------------===// // X0 has special meaning for vsetvl/vsetvli. // rd | rs1 | AVL value | Effect on vl //-------------------------------------------------------------- // !X0 | X0 | VLMAX | Set vl to VLMAX // X0 | X0 | Value in vl | Keep current vl, just change vtype. def NoX0 : SDNodeXForm(N); if (C && C->isNullValue()) { SDLoc DL(N); return SDValue(CurDAG->getMachineNode(RISCV::ADDI, DL, Subtarget->getXLenVT(), CurDAG->getRegister(RISCV::X0, Subtarget->getXLenVT()), CurDAG->getTargetConstant(0, DL, Subtarget->getXLenVT())), 0); } return SDValue(N, 0); }]>; //===----------------------------------------------------------------------===// // Utilities. //===----------------------------------------------------------------------===// // This class describes information associated to the LMUL. class LMULInfo { bits<3> value = lmul; // This is encoded as the vlmul field of vtype. VReg vrclass = regclass; VReg wvrclass = wregclass; string MX = mx; } // Associate LMUL with tablegen records of register classes. def V_M1 : LMULInfo<0b000, VR, VRM2, "M1">; def V_M2 : LMULInfo<0b001, VRM2, VRM4, "M2">; def V_M4 : LMULInfo<0b010, VRM4, VRM8, "M4">; def V_M8 : LMULInfo<0b011, VRM8, NoVReg, "M8">; def V_MF8 : LMULInfo<0b101, VR, VR, "MF8">; def V_MF4 : LMULInfo<0b110, VR, VR, "MF4">; def V_MF2 : LMULInfo<0b111, VR, VR, "MF2">; // Used to iterate over all possible LMULs. def MxList { list m = [V_MF8, V_MF4, V_MF2, V_M1, V_M2, V_M4, V_M8]; } class shift_amount { int val = !if(!eq(num, 1), 0, !add(1, shift_amount.val)); } // Output pattern for X0 used to represent VLMAX in the pseudo instructions. def VLMax : OutPatFrag<(ops), (XLenVT X0)>; // List of EEW. defvar EEWList = [8, 16, 32, 64]; // We only model FPR32 for V instructions in RISCVInstrInfoV.td. // FP16/FP32/FP64 registers are alias each other. Convert FPR16 and FPR64 // to FPR32 for V instructions is enough. class ToFPR32 { dag ret = !cond(!eq(!cast(operand), !cast(FPR64)): (EXTRACT_SUBREG !dag(type, [FPR64], [name]), sub_32), !eq(!cast(operand), !cast(FPR16)): (SUBREG_TO_REG (i16 -1), !dag(type, [FPR16], [name]), sub_16), !eq(1, 1): !dag(type, [operand], [name])); } //===----------------------------------------------------------------------===// // Vector register and vector group type information. //===----------------------------------------------------------------------===// class VTypeInfo { ValueType Vector = Vec; ValueType Mask = Mas; int SEW = Sew; VReg RegClass = Reg; LMULInfo LMul = M; ValueType Scalar = Scal; RegisterClass ScalarRegClass = ScalarReg; } class GroupVTypeInfo : VTypeInfo { ValueType VectorM1 = VecM1; } defset list AllVectors = { defset list AllIntegerVectors = { def VI8MF8: VTypeInfo; def VI8MF4: VTypeInfo; def VI8MF2: VTypeInfo; def VI8M1: VTypeInfo; def VI16MF4: VTypeInfo; def VI16MF2: VTypeInfo; def VI16M1: VTypeInfo; def VI32MF2: VTypeInfo; def VI32M1: VTypeInfo; def VI64M1: VTypeInfo; def VI8M2: GroupVTypeInfo; def VI8M4: GroupVTypeInfo; def VI8M8: GroupVTypeInfo; def VI16M2: GroupVTypeInfo; def VI16M4: GroupVTypeInfo; def VI16M8: GroupVTypeInfo; def VI32M2: GroupVTypeInfo; def VI32M4: GroupVTypeInfo; def VI32M8: GroupVTypeInfo; def VI64M2: GroupVTypeInfo; def VI64M4: GroupVTypeInfo; def VI64M8: GroupVTypeInfo; } defset list AllFloatVectors = { defset list NoGroupFloatVectors = { def VF16MF4: VTypeInfo; def VF16MF2: VTypeInfo; def VF16M1: VTypeInfo; def VF32MF2: VTypeInfo; def VF32M1: VTypeInfo; def VF64M1: VTypeInfo; } defset list GroupFloatVectors = { def VF16M2: GroupVTypeInfo; def VF16M4: GroupVTypeInfo; def VF16M8: GroupVTypeInfo; def VF32M2: GroupVTypeInfo; def VF32M4: GroupVTypeInfo; def VF32M8: GroupVTypeInfo; def VF64M2: GroupVTypeInfo; def VF64M4: GroupVTypeInfo; def VF64M8: GroupVTypeInfo; } } } class VTypeInfoToWide { VTypeInfo Vti = vti; VTypeInfo Wti = wti; } defset list AllWidenableIntVectors = { def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; def : VTypeInfoToWide; } // This class holds the record of the RISCVVPseudoTable below. // This represents the information we need in codegen for each pseudo. // The definition should be consistent with `struct PseudoInfo` in // RISCVBaseInfo.h. class CONST8b val> { bits<8> V = val; } def InvalidIndex : CONST8b<0x80>; class RISCVVPseudo { Pseudo Pseudo = !cast(NAME); // Used as a key. Instruction BaseInstr; bits<8> VLIndex = InvalidIndex.V; bits<8> SEWIndex = InvalidIndex.V; bits<8> MergeOpIndex = InvalidIndex.V; bits<3> VLMul; bit HasDummyMask = 0; } // The actual table. def RISCVVPseudosTable : GenericTable { let FilterClass = "RISCVVPseudo"; let CppTypeName = "PseudoInfo"; let Fields = [ "Pseudo", "BaseInstr", "VLIndex", "SEWIndex", "MergeOpIndex", "VLMul", "HasDummyMask" ]; let PrimaryKey = [ "Pseudo" ]; let PrimaryKeyName = "getPseudoInfo"; } def RISCVVIntrinsicsTable : GenericTable { let FilterClass = "RISCVVIntrinsic"; let CppTypeName = "RISCVVIntrinsicInfo"; let Fields = ["IntrinsicID", "ExtendOperand"]; let PrimaryKey = ["IntrinsicID"]; let PrimaryKeyName = "getRISCVVIntrinsicInfo"; } //===----------------------------------------------------------------------===// // Helpers to define the different pseudo instructions. //===----------------------------------------------------------------------===// class PseudoToVInst { string VInst = !subst("_M8", "", !subst("_M4", "", !subst("_M2", "", !subst("_M1", "", !subst("_MF2", "", !subst("_MF4", "", !subst("_MF8", "", !subst("_MASK", "", !subst("Pseudo", "", PseudoInst))))))))); } // The destination vector register group for a masked vector instruction cannot // overlap the source mask register (v0), unless the destination vector register // is being written with a mask value (e.g., comparisons) or the scalar result // of a reduction. class GetVRegNoV0 { VReg R = !cond(!eq(VRegClass, VR) : VRNoV0, !eq(VRegClass, VRM2) : VRM2NoV0, !eq(VRegClass, VRM4) : VRM4NoV0, !eq(VRegClass, VRM8) : VRM8NoV0, !eq(1, 1) : VRegClass); } // Join strings in list using separator and ignoring empty elements class Join strings, string separator> { string ret = !foldl(!head(strings), !tail(strings), a, b, !cond( !and(!empty(a), !empty(b)) : "", !empty(a) : b, !empty(b) : a, 1 : a#separator#b)); } class VPseudo : Pseudo, RISCVVPseudo { let BaseInstr = instr; let VLMul = m.value; } class VPseudoUSLoadNoMask: Pseudo<(outs RetClass:$rd), (ins GPR:$rs1, GPR:$vl, ixlenimm:$sew),[]>, RISCVVPseudo { let mayLoad = 1; let mayStore = 0; let hasSideEffects = 0; let usesCustomInserter = 1; let Uses = [VL, VTYPE]; let VLIndex = 2; let SEWIndex = 3; let HasDummyMask = 1; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoUSLoadMask: Pseudo<(outs GetVRegNoV0.R:$rd), (ins GetVRegNoV0.R:$merge, GPR:$rs1, VMaskOp:$vm, GPR:$vl, ixlenimm:$sew),[]>, RISCVVPseudo { let mayLoad = 1; let mayStore = 0; let hasSideEffects = 0; let usesCustomInserter = 1; let Constraints = "$rd = $merge"; let Uses = [VL, VTYPE]; let VLIndex = 4; let SEWIndex = 5; let MergeOpIndex = 1; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoSLoadNoMask: Pseudo<(outs RetClass:$rd), (ins GPR:$rs1, GPR:$rs2, GPR:$vl, ixlenimm:$sew),[]>, RISCVVPseudo { let mayLoad = 1; let mayStore = 0; let hasSideEffects = 0; let usesCustomInserter = 1; let Uses = [VL, VTYPE]; let VLIndex = 3; let SEWIndex = 4; let HasDummyMask = 1; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoSLoadMask: Pseudo<(outs GetVRegNoV0.R:$rd), (ins GetVRegNoV0.R:$merge, GPR:$rs1, GPR:$rs2, VMaskOp:$vm, GPR:$vl, ixlenimm:$sew),[]>, RISCVVPseudo { let mayLoad = 1; let mayStore = 0; let hasSideEffects = 0; let usesCustomInserter = 1; let Constraints = "$rd = $merge"; let Uses = [VL, VTYPE]; let VLIndex = 5; let SEWIndex = 6; let MergeOpIndex = 1; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoUSStoreNoMask: Pseudo<(outs), (ins StClass:$rd, GPR:$rs1, GPR:$vl, ixlenimm:$sew),[]>, RISCVVPseudo { let mayLoad = 0; let mayStore = 1; let hasSideEffects = 0; let usesCustomInserter = 1; let Uses = [VL, VTYPE]; let VLIndex = 2; let SEWIndex = 3; let HasDummyMask = 1; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoUSStoreMask: Pseudo<(outs), (ins StClass:$rd, GPR:$rs1, VMaskOp:$vm, GPR:$vl, ixlenimm:$sew),[]>, RISCVVPseudo { let mayLoad = 0; let mayStore = 1; let hasSideEffects = 0; let usesCustomInserter = 1; let Uses = [VL, VTYPE]; let VLIndex = 3; let SEWIndex = 4; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoSStoreNoMask: Pseudo<(outs), (ins StClass:$rd, GPR:$rs1, GPR:$rs2, GPR:$vl, ixlenimm:$sew),[]>, RISCVVPseudo { let mayLoad = 0; let mayStore = 1; let hasSideEffects = 0; let usesCustomInserter = 1; let Uses = [VL, VTYPE]; let VLIndex = 3; let SEWIndex = 4; let HasDummyMask = 1; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoSStoreMask: Pseudo<(outs), (ins StClass:$rd, GPR:$rs1, GPR:$rs2, VMaskOp:$vm, GPR:$vl, ixlenimm:$sew),[]>, RISCVVPseudo { let mayLoad = 0; let mayStore = 1; let hasSideEffects = 0; let usesCustomInserter = 1; let Uses = [VL, VTYPE]; let VLIndex = 4; let SEWIndex = 5; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoBinaryNoMask : Pseudo<(outs RetClass:$rd), (ins Op1Class:$rs2, Op2Class:$rs1, GPR:$vl, ixlenimm:$sew), []>, RISCVVPseudo { let mayLoad = 0; let mayStore = 0; let hasSideEffects = 0; let usesCustomInserter = 1; let Constraints = Constraint; let Uses = [VL, VTYPE]; let VLIndex = 3; let SEWIndex = 4; let HasDummyMask = 1; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoBinaryMask : Pseudo<(outs GetVRegNoV0.R:$rd), (ins GetVRegNoV0.R:$merge, Op1Class:$rs2, Op2Class:$rs1, VMaskOp:$vm, GPR:$vl, ixlenimm:$sew), []>, RISCVVPseudo { let mayLoad = 0; let mayStore = 0; let hasSideEffects = 0; let usesCustomInserter = 1; let Constraints = Join<[Constraint, "$rd = $merge"], ",">.ret; let Uses = [VL, VTYPE]; let VLIndex = 5; let SEWIndex = 6; let MergeOpIndex = 1; let BaseInstr = !cast(PseudoToVInst.VInst); } class VPseudoBinaryCarryIn : Pseudo<(outs RetClass:$rd), !if(!eq(CarryIn, 1), (ins Op1Class:$rs2, Op2Class:$rs1, VMV0:$carry, GPR:$vl, ixlenimm:$sew), (ins Op1Class:$rs2, Op2Class:$rs1, GPR:$vl, ixlenimm:$sew)), []>, RISCVVPseudo { let mayLoad = 0; let mayStore = 0; let hasSideEffects = 0; let usesCustomInserter = 1; let Constraints = Constraint; let Uses = [VL, VTYPE]; let VLIndex = !if(!eq(CarryIn, 1), 4, 3); let SEWIndex = !if(!eq(CarryIn, 1), 5, 4); let MergeOpIndex = InvalidIndex.V; let BaseInstr = !cast(PseudoToVInst.VInst); let VLMul = MInfo.value; } multiclass VPseudoUSLoad { foreach lmul = MxList.m in { defvar LInfo = lmul.MX; defvar vreg = lmul.vrclass; let VLMul = lmul.value in { def "_V_" # LInfo : VPseudoUSLoadNoMask; def "_V_" # LInfo # "_MASK" : VPseudoUSLoadMask; } } } multiclass VPseudoSLoad { foreach lmul = MxList.m in { defvar LInfo = lmul.MX; defvar vreg = lmul.vrclass; let VLMul = lmul.value in { def "_V_" # LInfo : VPseudoSLoadNoMask; def "_V_" # LInfo # "_MASK" : VPseudoSLoadMask; } } } multiclass VPseudoUSStore { foreach lmul = MxList.m in { defvar LInfo = lmul.MX; defvar vreg = lmul.vrclass; let VLMul = lmul.value in { def "_V_" # LInfo : VPseudoUSStoreNoMask; def "_V_" # LInfo # "_MASK" : VPseudoUSStoreMask; } } } multiclass VPseudoSStore { foreach lmul = MxList.m in { defvar LInfo = lmul.MX; defvar vreg = lmul.vrclass; let VLMul = lmul.value in { def "_V_" # LInfo : VPseudoSStoreNoMask; def "_V_" # LInfo # "_MASK" : VPseudoSStoreMask; } } } multiclass VPseudoBinary { let VLMul = MInfo.value in { def "_" # MInfo.MX : VPseudoBinaryNoMask; def "_" # MInfo.MX # "_MASK" : VPseudoBinaryMask; } } multiclass VPseudoBinaryV_VV { foreach m = MxList.m in defm _VV : VPseudoBinary; } multiclass VPseudoBinaryV_VX { foreach m = MxList.m in defm !if(!eq(IsFloat, 0), "_VX", "_VF") : VPseudoBinary; } multiclass VPseudoBinaryV_VI { foreach m = MxList.m in defm _VI : VPseudoBinary; } // We use earlyclobber here due to // * The destination EEW is smaller than the source EEW and the overlap is // in the lowest-numbered part of the source register group is legal. // Otherwise, it is illegal. // * The destination EEW is greater than the source EEW, the source EMUL is // at least 1, and the overlap is in the highest-numbered part of the // destination register group is legal. Otherwise, it is illegal. multiclass VPseudoBinaryW_VV { foreach m = MxList.m[0-5] in defm _VV : VPseudoBinary; } multiclass VPseudoBinaryW_VX { foreach m = MxList.m[0-5] in defm _VX : VPseudoBinary; } multiclass VPseudoBinaryW_WV { foreach m = MxList.m[0-5] in defm _WV : VPseudoBinary; } multiclass VPseudoBinaryW_WX { foreach m = MxList.m[0-5] in defm _WX : VPseudoBinary; } multiclass VPseudoBinaryV_WV { foreach m = MxList.m[0-5] in defm _WV : VPseudoBinary; } multiclass VPseudoBinaryV_WX { foreach m = MxList.m[0-5] in defm _WX : VPseudoBinary; } multiclass VPseudoBinaryV_WI { foreach m = MxList.m[0-5] in defm _WI : VPseudoBinary; } // For vadc and vsbc, the instruction encoding is reserved if the destination // vector register is v0. // For vadc and vsbc, CarryIn == 1 and CarryOut == 0 multiclass VPseudoBinaryV_VM { foreach m = MxList.m in def "_VV" # !if(!eq(CarryIn, 1), "M", "") # "_" # m.MX : VPseudoBinaryCarryIn.R, m.vrclass)), m.vrclass, m.vrclass, m, CarryIn, Constraint>; } multiclass VPseudoBinaryV_XM { foreach m = MxList.m in def "_VX" # !if(!eq(CarryIn, 1), "M", "") # "_" # m.MX : VPseudoBinaryCarryIn.R, m.vrclass)), m.vrclass, GPR, m, CarryIn, Constraint>; } multiclass VPseudoBinaryV_IM { foreach m = MxList.m in def "_VI" # !if(!eq(CarryIn, 1), "M", "") # "_" # m.MX : VPseudoBinaryCarryIn.R, m.vrclass)), m.vrclass, simm5, m, CarryIn, Constraint>; } multiclass VPseudoBinaryV_VV_VX_VI { defm "" : VPseudoBinaryV_VV; defm "" : VPseudoBinaryV_VX; defm "" : VPseudoBinaryV_VI; } multiclass VPseudoBinaryV_VV_VX { defm "" : VPseudoBinaryV_VV; defm "" : VPseudoBinaryV_VX; } multiclass VPseudoBinaryV_VX_VI { defm "" : VPseudoBinaryV_VX; defm "" : VPseudoBinaryV_VI; } multiclass VPseudoBinaryW_VV_VX { defm "" : VPseudoBinaryW_VV; defm "" : VPseudoBinaryW_VX; } multiclass VPseudoBinaryW_WV_WX { defm "" : VPseudoBinaryW_WV; defm "" : VPseudoBinaryW_WX; } multiclass VPseudoBinaryV_VM_XM_IM { defm "" : VPseudoBinaryV_VM; defm "" : VPseudoBinaryV_XM; defm "" : VPseudoBinaryV_IM; } multiclass VPseudoBinaryV_VM_XM { defm "" : VPseudoBinaryV_VM; defm "" : VPseudoBinaryV_XM; } multiclass VPseudoBinaryM_VM_XM_IM { defm "" : VPseudoBinaryV_VM; defm "" : VPseudoBinaryV_XM; defm "" : VPseudoBinaryV_IM; } multiclass VPseudoBinaryM_VM_XM { defm "" : VPseudoBinaryV_VM; defm "" : VPseudoBinaryV_XM; } multiclass VPseudoBinaryM_V_X_I { defm "" : VPseudoBinaryV_VM; defm "" : VPseudoBinaryV_XM; defm "" : VPseudoBinaryV_IM; } multiclass VPseudoBinaryM_V_X { defm "" : VPseudoBinaryV_VM; defm "" : VPseudoBinaryV_XM; } multiclass VPseudoBinaryV_WV_WX_WI { defm "" : VPseudoBinaryV_WV; defm "" : VPseudoBinaryV_WX; defm "" : VPseudoBinaryV_WI; } //===----------------------------------------------------------------------===// // Helpers to define the SDNode patterns. //===----------------------------------------------------------------------===// multiclass VPatUSLoadStoreSDNode { defvar load_instr = !cast("PseudoVLE"#sew#"_V_"#vlmul.MX); defvar store_instr = !cast("PseudoVSE"#sew#"_V_"#vlmul.MX); // Load def : Pat<(type (load reg_rs1:$rs1)), (load_instr reg_rs1:$rs1, VLMax, sew)>; // Store def : Pat<(store type:$rs2, reg_rs1:$rs1), (store_instr reg_class:$rs2, reg_rs1:$rs1, VLMax, sew)>; } multiclass VPatUSLoadStoreSDNodes { foreach vti = AllVectors in defm "" : VPatUSLoadStoreSDNode; } class VPatBinarySDNode : Pat<(result_type (vop (op_type op_reg_class:$rs1), (op_type op_reg_class:$rs2))), (!cast(instruction_name#"_VV_"# vlmul.MX) op_reg_class:$rs1, op_reg_class:$rs2, VLMax, sew)>; multiclass VPatBinarySDNode { foreach vti = AllIntegerVectors in def : VPatBinarySDNode; } //===----------------------------------------------------------------------===// // Helpers to define the intrinsic patterns. //===----------------------------------------------------------------------===// class VPatBinaryNoMask : Pat<(result_type (!cast(intrinsic_name) (op1_type op1_reg_class:$rs1), (op2_type op2_kind:$rs2), (XLenVT GPR:$vl))), (!cast(inst#"_"#kind#"_"#vlmul.MX) (op1_type op1_reg_class:$rs1), ToFPR32.ret, (NoX0 GPR:$vl), sew)>; class VPatBinaryMask : Pat<(result_type (!cast(intrinsic_name#"_mask") (result_type result_reg_class:$merge), (op1_type op1_reg_class:$rs1), (op2_type op2_kind:$rs2), (mask_type V0), (XLenVT GPR:$vl))), (!cast(inst#"_"#kind#"_"#vlmul.MX#"_MASK") (result_type result_reg_class:$merge), (op1_type op1_reg_class:$rs1), ToFPR32.ret, (mask_type V0), (NoX0 GPR:$vl), sew)>; multiclass VPatUSLoad { defvar Intr = !cast(intrinsic); defvar Pseudo = !cast(inst#"_V_"#vlmul.MX); def : Pat<(type (Intr GPR:$rs1, GPR:$vl)), (Pseudo $rs1, (NoX0 GPR:$vl), sew)>; defvar IntrMask = !cast(intrinsic # "_mask"); defvar PseudoMask = !cast(inst#"_V_"#vlmul.MX#"_MASK"); def : Pat<(type (IntrMask (type GetVRegNoV0.R:$merge), GPR:$rs1, (mask_type V0), GPR:$vl)), (PseudoMask $merge, $rs1, (mask_type V0), (NoX0 GPR:$vl), sew)>; } multiclass VPatSLoad { defvar Intr = !cast(intrinsic); defvar Pseudo = !cast(inst#"_V_"#vlmul.MX); def : Pat<(type (Intr GPR:$rs1, GPR:$rs2, GPR:$vl)), (Pseudo $rs1, $rs2, (NoX0 GPR:$vl), sew)>; defvar IntrMask = !cast(intrinsic # "_mask"); defvar PseudoMask = !cast(inst#"_V_"#vlmul.MX#"_MASK"); def : Pat<(type (IntrMask (type GetVRegNoV0.R:$merge), GPR:$rs1, GPR:$rs2, (mask_type V0), GPR:$vl)), (PseudoMask $merge, $rs1, $rs2, (mask_type V0), (NoX0 GPR:$vl), sew)>; } multiclass VPatUSStore { defvar Intr = !cast(intrinsic); defvar Pseudo = !cast(inst#"_V_"#vlmul.MX); def : Pat<(Intr (type reg_class:$rs3), GPR:$rs1, GPR:$vl), (Pseudo $rs3, $rs1, (NoX0 GPR:$vl), sew)>; defvar IntrMask = !cast(intrinsic # "_mask"); defvar PseudoMask = !cast(inst#"_V_"#vlmul.MX#"_MASK"); def : Pat<(IntrMask (type reg_class:$rs3), GPR:$rs1, (mask_type V0), GPR:$vl), (PseudoMask $rs3, $rs1, (mask_type V0), (NoX0 GPR:$vl), sew)>; } multiclass VPatSStore { defvar Intr = !cast(intrinsic); defvar Pseudo = !cast(inst#"_V_"#vlmul.MX); def : Pat<(Intr (type reg_class:$rs3), GPR:$rs1, GPR:$rs2, GPR:$vl), (Pseudo $rs3, $rs1, $rs2, (NoX0 GPR:$vl), sew)>; defvar IntrMask = !cast(intrinsic # "_mask"); defvar PseudoMask = !cast(inst#"_V_"#vlmul.MX#"_MASK"); def : Pat<(IntrMask (type reg_class:$rs3), GPR:$rs1, GPR:$rs2, (mask_type V0), GPR:$vl), (PseudoMask $rs3, $rs1, $rs2, (mask_type V0), (NoX0 GPR:$vl), sew)>; } multiclass VPatBinary { def : VPatBinaryNoMask; def : VPatBinaryMask; } multiclass VPatBinaryCarryIn { def : Pat<(result_type (!cast(intrinsic) (op1_type op1_reg_class:$rs1), (op2_type op2_kind:$rs2), (mask_type V0), (XLenVT GPR:$vl))), (!cast(inst#"_"#kind#"_"#vlmul.MX) (op1_type op1_reg_class:$rs1), ToFPR32.ret, (mask_type V0), (NoX0 GPR:$vl), sew)>; } multiclass VPatBinaryMaskOut { def : Pat<(result_type (!cast(intrinsic) (op1_type op1_reg_class:$rs1), (op2_type op2_kind:$rs2), (XLenVT GPR:$vl))), (!cast(inst#"_"#kind#"_"#vlmul.MX) (op1_type op1_reg_class:$rs1), ToFPR32.ret, (NoX0 GPR:$vl), sew)>; } multiclass VPatBinaryV_VV vtilist> { foreach vti = vtilist in defm : VPatBinary; } multiclass VPatBinaryV_VX vtilist> { foreach vti = vtilist in defm : VPatBinary; } multiclass VPatBinaryV_VI vtilist, Operand imm_type> { foreach vti = vtilist in defm : VPatBinary; } multiclass VPatBinaryW_VV { foreach VtiToWti = AllWidenableIntVectors in { defvar Vti = VtiToWti.Vti; defvar Wti = VtiToWti.Wti; defm : VPatBinary; } } multiclass VPatBinaryW_VX { foreach VtiToWti = AllWidenableIntVectors in { defvar Vti = VtiToWti.Vti; defvar Wti = VtiToWti.Wti; defm : VPatBinary; } } multiclass VPatBinaryW_WV { foreach VtiToWti = AllWidenableIntVectors in { defvar Vti = VtiToWti.Vti; defvar Wti = VtiToWti.Wti; defm : VPatBinary; } } multiclass VPatBinaryW_WX { foreach VtiToWti = AllWidenableIntVectors in { defvar Vti = VtiToWti.Vti; defvar Wti = VtiToWti.Wti; defm : VPatBinary; } } multiclass VPatBinaryV_WV { foreach VtiToWti = AllWidenableIntVectors in { defvar Vti = VtiToWti.Vti; defvar Wti = VtiToWti.Wti; defm : VPatBinary; } } multiclass VPatBinaryV_WX { foreach VtiToWti = AllWidenableIntVectors in { defvar Vti = VtiToWti.Vti; defvar Wti = VtiToWti.Wti; defm : VPatBinary; } } multiclass VPatBinaryV_WI { foreach VtiToWti = AllWidenableIntVectors in { defvar Vti = VtiToWti.Vti; defvar Wti = VtiToWti.Wti; defm : VPatBinary; } } multiclass VPatBinaryV_VM { foreach vti = AllIntegerVectors in defm : VPatBinaryCarryIn; } multiclass VPatBinaryV_XM { foreach vti = AllIntegerVectors in defm : VPatBinaryCarryIn; } multiclass VPatBinaryV_IM { foreach vti = AllIntegerVectors in defm : VPatBinaryCarryIn; } multiclass VPatBinaryV_V { foreach vti = AllIntegerVectors in defm : VPatBinaryMaskOut; } multiclass VPatBinaryV_X { foreach vti = AllIntegerVectors in defm : VPatBinaryMaskOut; } multiclass VPatBinaryV_I { foreach vti = AllIntegerVectors in defm : VPatBinaryMaskOut; } multiclass VPatBinaryV_VV_VX_VI vtilist, Operand ImmType = simm5> { defm "" : VPatBinaryV_VV; defm "" : VPatBinaryV_VX; defm "" : VPatBinaryV_VI; } multiclass VPatBinaryV_VV_VX vtilist> { defm "" : VPatBinaryV_VV; defm "" : VPatBinaryV_VX; } multiclass VPatBinaryV_VX_VI vtilist> { defm "" : VPatBinaryV_VX; defm "" : VPatBinaryV_VI; } multiclass VPatBinaryW_VV_VX { defm "" : VPatBinaryW_VV; defm "" : VPatBinaryW_VX; } multiclass VPatBinaryW_WV_WX { defm "" : VPatBinaryW_WV; defm "" : VPatBinaryW_WX; } multiclass VPatBinaryV_WV_WX_WI { defm "" : VPatBinaryV_WV; defm "" : VPatBinaryV_WX; defm "" : VPatBinaryV_WI; } multiclass VPatBinaryV_VM_XM_IM { defm "" : VPatBinaryV_VM; defm "" : VPatBinaryV_XM; defm "" : VPatBinaryV_IM; } multiclass VPatBinaryM_VM_XM_IM { defm "" : VPatBinaryV_VM; defm "" : VPatBinaryV_XM; defm "" : VPatBinaryV_IM; } multiclass VPatBinaryM_V_X_I { defm "" : VPatBinaryV_V; defm "" : VPatBinaryV_X; defm "" : VPatBinaryV_I; } multiclass VPatBinaryV_VM_XM { defm "" : VPatBinaryV_VM; defm "" : VPatBinaryV_XM; } multiclass VPatBinaryM_VM_XM { defm "" : VPatBinaryV_VM; defm "" : VPatBinaryV_XM; } multiclass VPatBinaryM_V_X { defm "" : VPatBinaryV_V; defm "" : VPatBinaryV_X; } //===----------------------------------------------------------------------===// // Pseudo instructions and patterns. //===----------------------------------------------------------------------===// let Predicates = [HasStdExtV] in { //===----------------------------------------------------------------------===// // Pseudo Instructions for CodeGen //===----------------------------------------------------------------------===// let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { def PseudoVMV1R_V : VPseudo; def PseudoVMV2R_V : VPseudo; def PseudoVMV4R_V : VPseudo; def PseudoVMV8R_V : VPseudo; } //===----------------------------------------------------------------------===// // 6. Configuration-Setting Instructions //===----------------------------------------------------------------------===// // Pseudos. let hasSideEffects = 1, mayLoad = 0, mayStore = 0, Defs = [VL, VTYPE] in { def PseudoVSETVLI : Pseudo<(outs GPR:$rd), (ins GPR:$rs1, VTypeIOp:$vtypei), []>; } //===----------------------------------------------------------------------===// // 7. Vector Loads and Stores //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// // 7.4 Vector Unit-Stride Instructions //===----------------------------------------------------------------------===// // Pseudos Unit-Stride Loads and Stores foreach eew = EEWList in { defm PseudoVLE # eew : VPseudoUSLoad; defm PseudoVSE # eew : VPseudoUSStore; } //===----------------------------------------------------------------------===// // 7.5 Vector Strided Instructions //===----------------------------------------------------------------------===// // Vector Strided Loads and Stores foreach eew = EEWList in { defm PseudoVLSE # eew : VPseudoSLoad; defm PseudoVSSE # eew : VPseudoSStore; } //===----------------------------------------------------------------------===// // Pseudo Instructions //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// // 12. Vector Integer Arithmetic Instructions //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// // 12.1. Vector Single-Width Integer Add and Subtract //===----------------------------------------------------------------------===// defm PseudoVADD : VPseudoBinaryV_VV_VX_VI; defm PseudoVSUB : VPseudoBinaryV_VV_VX; defm PseudoVRSUB : VPseudoBinaryV_VX_VI; //===----------------------------------------------------------------------===// // 12.2. Vector Widening Integer Add/Subtract //===----------------------------------------------------------------------===// defm PseudoVWADDU : VPseudoBinaryW_VV_VX; defm PseudoVWSUBU : VPseudoBinaryW_VV_VX; defm PseudoVWADD : VPseudoBinaryW_VV_VX; defm PseudoVWSUB : VPseudoBinaryW_VV_VX; defm PseudoVWADDU : VPseudoBinaryW_WV_WX; defm PseudoVWSUBU : VPseudoBinaryW_WV_WX; defm PseudoVWADD : VPseudoBinaryW_WV_WX; defm PseudoVWSUB : VPseudoBinaryW_WV_WX; //===----------------------------------------------------------------------===// // 12.4. Vector Integer Add-with-Carry / Subtract-with-Borrow Instructions //===----------------------------------------------------------------------===// defm PseudoVADC : VPseudoBinaryV_VM_XM_IM; defm PseudoVMADC : VPseudoBinaryM_VM_XM_IM<"@earlyclobber $rd">; defm PseudoVMADC : VPseudoBinaryM_V_X_I<"@earlyclobber $rd">; defm PseudoVSBC : VPseudoBinaryV_VM_XM; defm PseudoVMSBC : VPseudoBinaryM_VM_XM<"@earlyclobber $rd">; defm PseudoVMSBC : VPseudoBinaryM_V_X<"@earlyclobber $rd">; //===----------------------------------------------------------------------===// // 12.6. Vector Single-Width Bit Shift Instructions //===----------------------------------------------------------------------===// defm PseudoVSLL : VPseudoBinaryV_VV_VX_VI; defm PseudoVSRL : VPseudoBinaryV_VV_VX_VI; defm PseudoVSRA : VPseudoBinaryV_VV_VX_VI; //===----------------------------------------------------------------------===// // 12.7. Vector Narrowing Integer Right Shift Instructions //===----------------------------------------------------------------------===// defm PseudoVNSRL : VPseudoBinaryV_WV_WX_WI; defm PseudoVNSRA : VPseudoBinaryV_WV_WX_WI; //===----------------------------------------------------------------------===// // 12.9. Vector Integer Min/Max Instructions //===----------------------------------------------------------------------===// defm PseudoVMINU : VPseudoBinaryV_VV_VX; defm PseudoVMIN : VPseudoBinaryV_VV_VX; defm PseudoVMAXU : VPseudoBinaryV_VV_VX; defm PseudoVMAX : VPseudoBinaryV_VV_VX; //===----------------------------------------------------------------------===// // 12.10. Vector Single-Width Integer Multiply Instructions //===----------------------------------------------------------------------===// defm PseudoVMUL : VPseudoBinaryV_VV_VX; defm PseudoVMULH : VPseudoBinaryV_VV_VX; defm PseudoVMULHU : VPseudoBinaryV_VV_VX; defm PseudoVMULHSU : VPseudoBinaryV_VV_VX; //===----------------------------------------------------------------------===// // 12.11. Vector Integer Divide Instructions //===----------------------------------------------------------------------===// defm PseudoVDIVU : VPseudoBinaryV_VV_VX; defm PseudoVDIV : VPseudoBinaryV_VV_VX; defm PseudoVREMU : VPseudoBinaryV_VV_VX; defm PseudoVREM : VPseudoBinaryV_VV_VX; //===----------------------------------------------------------------------===// // 12.12. Vector Widening Integer Multiply Instructions //===----------------------------------------------------------------------===// defm PseudoVWMUL : VPseudoBinaryW_VV_VX; defm PseudoVWMULU : VPseudoBinaryW_VV_VX; defm PseudoVWMULSU : VPseudoBinaryW_VV_VX; } // Predicates = [HasStdExtV] let Predicates = [HasStdExtV, HasStdExtF] in { //===----------------------------------------------------------------------===// // 14.2. Vector Single-Width Floating-Point Add/Subtract Instructions //===----------------------------------------------------------------------===// defm PseudoVFADD : VPseudoBinaryV_VV_VX; defm PseudoVFSUB : VPseudoBinaryV_VV_VX; defm PseudoVFRSUB : VPseudoBinaryV_VX; } // Predicates = [HasStdExtV, HasStdExtF] //===----------------------------------------------------------------------===// // Patterns. //===----------------------------------------------------------------------===// let Predicates = [HasStdExtV] in { // Whole-register vector patterns. // 7.4. Vector Unit-Stride Instructions defm "" : VPatUSLoadStoreSDNodes; defm "" : VPatUSLoadStoreSDNodes; // 12.1. Vector Single-Width Integer Add and Subtract defm "" : VPatBinarySDNode; //===----------------------------------------------------------------------===// // 7. Vector Loads and Stores //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// // 7.4 Vector Unit-Stride Instructions //===----------------------------------------------------------------------===// foreach vti = AllVectors in { defm : VPatUSLoad<"int_riscv_vle", "PseudoVLE" # vti.SEW, vti.Vector, vti.Mask, vti.SEW, vti.LMul, vti.RegClass>; defm : VPatUSStore<"int_riscv_vse", "PseudoVSE" # vti.SEW, vti.Vector, vti.Mask, vti.SEW, vti.LMul, vti.RegClass>; } //===----------------------------------------------------------------------===// // 7.5 Vector Strided Instructions //===----------------------------------------------------------------------===// foreach vti = AllVectors in { defm : VPatSLoad<"int_riscv_vlse", "PseudoVLSE" # vti.SEW, vti.Vector, vti.Mask, vti.SEW, vti.LMul, vti.RegClass>; defm : VPatSStore<"int_riscv_vsse", "PseudoVSSE" # vti.SEW, vti.Vector, vti.Mask, vti.SEW, vti.LMul, vti.RegClass>; } //===----------------------------------------------------------------------===// // 12. Vector Integer Arithmetic Instructions //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// // 12.1. Vector Single-Width Integer Add and Subtract //===----------------------------------------------------------------------===// defm "" : VPatBinaryV_VV_VX_VI<"int_riscv_vadd", "PseudoVADD", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vsub", "PseudoVSUB", AllIntegerVectors>; defm "" : VPatBinaryV_VX_VI<"int_riscv_vrsub", "PseudoVRSUB", AllIntegerVectors>; //===----------------------------------------------------------------------===// // 12.2. Vector Widening Integer Add/Subtract //===----------------------------------------------------------------------===// defm "" : VPatBinaryW_VV_VX<"int_riscv_vwaddu", "PseudoVWADDU">; defm "" : VPatBinaryW_VV_VX<"int_riscv_vwsubu", "PseudoVWSUBU">; defm "" : VPatBinaryW_VV_VX<"int_riscv_vwadd", "PseudoVWADD">; defm "" : VPatBinaryW_VV_VX<"int_riscv_vwsub", "PseudoVWSUB">; defm "" : VPatBinaryW_WV_WX<"int_riscv_vwaddu_w", "PseudoVWADDU">; defm "" : VPatBinaryW_WV_WX<"int_riscv_vwsubu_w", "PseudoVWSUBU">; defm "" : VPatBinaryW_WV_WX<"int_riscv_vwadd_w", "PseudoVWADD">; defm "" : VPatBinaryW_WV_WX<"int_riscv_vwsub_w", "PseudoVWSUB">; //===----------------------------------------------------------------------===// // 12.4. Vector Integer Add-with-Carry / Subtract-with-Borrow Instructions //===----------------------------------------------------------------------===// defm "" : VPatBinaryV_VM_XM_IM<"int_riscv_vadc", "PseudoVADC">; defm "" : VPatBinaryM_VM_XM_IM<"int_riscv_vmadc_carry_in", "PseudoVMADC">; defm "" : VPatBinaryM_V_X_I<"int_riscv_vmadc", "PseudoVMADC">; defm "" : VPatBinaryV_VM_XM<"int_riscv_vsbc", "PseudoVSBC">; defm "" : VPatBinaryM_VM_XM<"int_riscv_vmsbc_borrow_in", "PseudoVMSBC">; defm "" : VPatBinaryM_V_X<"int_riscv_vmsbc", "PseudoVMSBC">; //===----------------------------------------------------------------------===// // 12.6. Vector Single-Width Bit Shift Instructions //===----------------------------------------------------------------------===// defm "" : VPatBinaryV_VV_VX_VI<"int_riscv_vsll", "PseudoVSLL", AllIntegerVectors, uimm5>; defm "" : VPatBinaryV_VV_VX_VI<"int_riscv_vsrl", "PseudoVSRL", AllIntegerVectors, uimm5>; defm "" : VPatBinaryV_VV_VX_VI<"int_riscv_vsra", "PseudoVSRA", AllIntegerVectors, uimm5>; //===----------------------------------------------------------------------===// // 12.7. Vector Narrowing Integer Right Shift Instructions //===----------------------------------------------------------------------===// defm "" : VPatBinaryV_WV_WX_WI<"int_riscv_vnsrl", "PseudoVNSRL">; defm "" : VPatBinaryV_WV_WX_WI<"int_riscv_vnsra", "PseudoVNSRA">; //===----------------------------------------------------------------------===// // 12.9. Vector Integer Min/Max Instructions //===----------------------------------------------------------------------===// defm "" : VPatBinaryV_VV_VX<"int_riscv_vminu", "PseudoVMINU", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vmin", "PseudoVMIN", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vmaxu", "PseudoVMAXU", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vmax", "PseudoVMAX", AllIntegerVectors>; //===----------------------------------------------------------------------===// // 12.10. Vector Single-Width Integer Multiply Instructions //===----------------------------------------------------------------------===// defm "" : VPatBinaryV_VV_VX<"int_riscv_vmul", "PseudoVMUL", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vmulh", "PseudoVMULH", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vmulhu", "PseudoVMULHU", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vmulhsu", "PseudoVMULHSU", AllIntegerVectors>; //===----------------------------------------------------------------------===// // 12.11. Vector Integer Divide Instructions //===----------------------------------------------------------------------===// defm "" : VPatBinaryV_VV_VX<"int_riscv_vdivu", "PseudoVDIVU", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vdiv", "PseudoVDIV", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vremu", "PseudoVREMU", AllIntegerVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vrem", "PseudoVREM", AllIntegerVectors>; //===----------------------------------------------------------------------===// // 12.12. Vector Widening Integer Multiply Instructions //===----------------------------------------------------------------------===// defm "" : VPatBinaryW_VV_VX<"int_riscv_vwmul", "PseudoVWMUL">; defm "" : VPatBinaryW_VV_VX<"int_riscv_vwmulu", "PseudoVWMULU">; defm "" : VPatBinaryW_VV_VX<"int_riscv_vwmulsu", "PseudoVWMULSU">; } // Predicates = [HasStdExtV] let Predicates = [HasStdExtV, HasStdExtF] in { //===----------------------------------------------------------------------===// // 14.2. Vector Single-Width Floating-Point Add/Subtract Instructions //===----------------------------------------------------------------------===// defm "" : VPatBinaryV_VV_VX<"int_riscv_vfadd", "PseudoVFADD", AllFloatVectors>; defm "" : VPatBinaryV_VV_VX<"int_riscv_vfsub", "PseudoVFSUB", AllFloatVectors>; defm "" : VPatBinaryV_VX<"int_riscv_vfrsub", "PseudoVFRSUB", AllFloatVectors>; } // Predicates = [HasStdExtV, HasStdExtF]