Skip to content

Commit c583fa2

Browse files
authored
[LLVM][XTHeadVector] Implement 16.7-16.8 viota/vid (llvm#98)
* [LLVM][XTHeadVector] Implement 16.7-16.8 `viota/vid` * [LLVM][XTHeadVector] Test 16.7-16.8 `viota/vid`
1 parent cdecd48 commit c583fa2

File tree

4 files changed

+1873
-0
lines changed

4 files changed

+1873
-0
lines changed

llvm/include/llvm/IR/IntrinsicsRISCVXTHeadV.td

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,4 +924,48 @@ let TargetPrefix = "riscv" in {
924924
// 16.6. vmsof.m set-only-first mask bit
925925
defm th_vmsof : RISCVMaskedUnaryMOut;
926926

927+
// 16.7. Vector Iota Operations
928+
// Output: (vector)
929+
// Input: (passthru, mask type input, vl)
930+
def int_riscv_th_viota
931+
: DefaultAttrsIntrinsic<[llvm_anyvector_ty],
932+
[LLVMMatchType<0>,
933+
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
934+
llvm_anyint_ty],
935+
[IntrNoMem]>, RISCVVIntrinsic {
936+
let VLOperand = 2;
937+
}
938+
// Output: (vector)
939+
// Input: (maskedoff, mask type vector_in, mask, vl)
940+
def int_riscv_th_viota_mask
941+
: DefaultAttrsIntrinsic<[llvm_anyvector_ty],
942+
[LLVMMatchType<0>,
943+
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
944+
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
945+
llvm_anyint_ty],
946+
[IntrNoMem]>, RISCVVIntrinsic {
947+
let VLOperand = 3;
948+
}
949+
950+
// 16.8. Vector Element Index Operations
951+
// Output: (vector)
952+
// Input: (passthru, vl)
953+
def int_riscv_th_vid
954+
: DefaultAttrsIntrinsic<[llvm_anyvector_ty],
955+
[LLVMMatchType<0>, llvm_anyint_ty],
956+
[IntrNoMem]>, RISCVVIntrinsic {
957+
let VLOperand = 1;
958+
}
959+
960+
// Output: (vector)
961+
// Input: (maskedoff, mask, vl)
962+
def int_riscv_th_vid_mask
963+
: DefaultAttrsIntrinsic<[llvm_anyvector_ty],
964+
[LLVMMatchType<0>,
965+
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
966+
llvm_anyint_ty],
967+
[IntrNoMem]>, RISCVVIntrinsic {
968+
let VLOperand = 2;
969+
}
970+
927971
} // TargetPrefix = "riscv"

llvm/lib/Target/RISCV/RISCVInstrInfoXTHeadVPseudos.td

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,29 @@ class XVPseudoUnaryMask<VReg RetClass, VReg OpClass, string Constraint = ""> :
17571757
let HasSEWOp = 1;
17581758
}
17591759

1760+
class XVPseudoNullaryNoMask<VReg RegClass>:
1761+
Pseudo<(outs RegClass:$rd),
1762+
(ins RegClass:$merge, AVL:$vl, ixlenimm:$sew), []>, RISCVVPseudo {
1763+
let mayLoad = 0;
1764+
let mayStore = 0;
1765+
let hasSideEffects = 0;
1766+
let Constraints = "$rd = $merge";
1767+
let HasVLOp = 1;
1768+
let HasSEWOp = 1;
1769+
}
1770+
1771+
class XVPseudoNullaryMask<VReg RegClass>:
1772+
Pseudo<(outs GetVRegNoV0<RegClass>.R:$rd),
1773+
(ins GetVRegNoV0<RegClass>.R:$merge, VMaskOp:$vm, AVL:$vl,
1774+
ixlenimm:$sew), []>, RISCVVPseudo {
1775+
let mayLoad = 0;
1776+
let mayStore = 0;
1777+
let hasSideEffects = 0;
1778+
let Constraints ="$rd = $merge";
1779+
let HasVLOp = 1;
1780+
let HasSEWOp = 1;
1781+
}
1782+
17601783
multiclass XVPseudoBinary<VReg RetClass,
17611784
VReg Op1Class,
17621785
DAGOperand Op2Class,
@@ -2596,6 +2619,38 @@ multiclass XVPseudoVSFS_M {
25962619
}
25972620
}
25982621

2622+
multiclass XVPseudoVIOT_M {
2623+
defvar constraint = "@earlyclobber $rd";
2624+
foreach m = MxListXTHeadV in {
2625+
defvar mx = m.MX;
2626+
defvar WriteVMIotV_MX = !cast<SchedWrite>("WriteVMIotV_" # mx);
2627+
defvar ReadVMIotV_MX = !cast<SchedRead>("ReadVMIotV_" # mx);
2628+
let VLMul = m.value in {
2629+
def "_" # m.MX : XVPseudoUnaryNoMask<m.vrclass, VR, constraint>,
2630+
Sched<[WriteVMIotV_MX, ReadVMIotV_MX, ReadVMask]>;
2631+
def "_" # m.MX # "_MASK" : XVPseudoUnaryMask<m.vrclass, VR, constraint>,
2632+
RISCVMaskedPseudo<MaskIdx=2>,
2633+
Sched<[WriteVMIotV_MX, ReadVMIotV_MX, ReadVMask]>;
2634+
}
2635+
}
2636+
}
2637+
2638+
multiclass XVPseudoVID_V {
2639+
foreach m = MxListXTHeadV in {
2640+
defvar mx = m.MX;
2641+
defvar WriteVMIdxV_MX = !cast<SchedWrite>("WriteVMIdxV_" # mx);
2642+
defvar ReadVMIdxV_MX = !cast<SchedRead>("ReadVMIdxV_" # mx);
2643+
2644+
let VLMul = m.value in {
2645+
def "_V_" # m.MX : XVPseudoNullaryNoMask<m.vrclass>,
2646+
Sched<[WriteVMIdxV_MX, ReadVMask]>;
2647+
def "_V_" # m.MX # "_MASK" : XVPseudoNullaryMask<m.vrclass>,
2648+
RISCVMaskedPseudo<MaskIdx=1>,
2649+
Sched<[WriteVMIdxV_MX, ReadVMask]>;
2650+
}
2651+
}
2652+
}
2653+
25992654
//===----------------------------------------------------------------------===//
26002655
// Helpers to define the intrinsic patterns for the XTHeadVector extension.
26012656
//===----------------------------------------------------------------------===//
@@ -3066,6 +3121,24 @@ multiclass XVPatBinaryM_MM<string intrinsic, string instruction> {
30663121
mti.Log2SEW, VR, VR>;
30673122
}
30683123

3124+
multiclass XVPatNullaryV<string intrinsic, string instruction> {
3125+
foreach vti = AllIntegerXVectors in {
3126+
let Predicates = GetXVTypePredicates<vti>.Predicates in {
3127+
def : Pat<(vti.Vector (!cast<Intrinsic>(intrinsic)
3128+
(vti.Vector vti.RegClass:$merge),
3129+
VLOpFrag)),
3130+
(!cast<Instruction>(instruction#"_V_" # vti.LMul.MX)
3131+
vti.RegClass:$merge, GPR:$vl, vti.Log2SEW)>;
3132+
def : Pat<(vti.Vector (!cast<Intrinsic>(intrinsic # "_mask")
3133+
(vti.Vector vti.RegClass:$merge),
3134+
(vti.Mask V0), VLOpFrag)),
3135+
(!cast<Instruction>(instruction#"_V_" # vti.LMul.MX # "_MASK")
3136+
vti.RegClass:$merge, (vti.Mask V0),
3137+
GPR:$vl, vti.Log2SEW)>;
3138+
}
3139+
}
3140+
}
3141+
30693142
multiclass XVPatNullaryM<string intrinsic, string inst> {
30703143
foreach mti = AllXMasks in
30713144
def : Pat<(mti.Mask (!cast<Intrinsic>(intrinsic)
@@ -3120,6 +3193,63 @@ multiclass XVPatUnaryM_M<string intrinsic,
31203193
}
31213194
}
31223195

3196+
class XVPatUnaryNoMask<string intrinsic_name,
3197+
string inst,
3198+
string kind,
3199+
ValueType result_type,
3200+
ValueType op2_type,
3201+
int log2sew,
3202+
LMULInfo vlmul,
3203+
VReg result_reg_class,
3204+
VReg op2_reg_class,
3205+
bit isSEWAware = 0> :
3206+
Pat<(result_type (!cast<Intrinsic>(intrinsic_name)
3207+
(result_type result_reg_class:$merge),
3208+
(op2_type op2_reg_class:$rs2),
3209+
VLOpFrag)),
3210+
(!cast<Instruction>(
3211+
!if(isSEWAware,
3212+
inst#"_"#kind#"_"#vlmul.MX#"_E"#!shl(1, log2sew),
3213+
inst#"_"#kind#"_"#vlmul.MX))
3214+
(result_type result_reg_class:$merge),
3215+
(op2_type op2_reg_class:$rs2),
3216+
GPR:$vl, log2sew)>;
3217+
3218+
class XVPatUnaryMask<string intrinsic_name,
3219+
string inst,
3220+
string kind,
3221+
ValueType result_type,
3222+
ValueType op2_type,
3223+
ValueType mask_type,
3224+
int log2sew,
3225+
LMULInfo vlmul,
3226+
VReg result_reg_class,
3227+
VReg op2_reg_class,
3228+
bit isSEWAware = 0> :
3229+
Pat<(result_type (!cast<Intrinsic>(intrinsic_name#"_mask")
3230+
(result_type result_reg_class:$merge),
3231+
(op2_type op2_reg_class:$rs2),
3232+
(mask_type V0),
3233+
VLOpFrag)),
3234+
(!cast<Instruction>(
3235+
!if(isSEWAware,
3236+
inst#"_"#kind#"_"#vlmul.MX#"_E"#!shl(1, log2sew)#"_MASK",
3237+
inst#"_"#kind#"_"#vlmul.MX#"_MASK"))
3238+
(result_type result_reg_class:$merge),
3239+
(op2_type op2_reg_class:$rs2),
3240+
(mask_type V0), GPR:$vl, log2sew)>;
3241+
3242+
multiclass XVPatUnaryV_M<string intrinsic, string instruction> {
3243+
foreach vti = AllIntegerXVectors in {
3244+
let Predicates = GetXVTypePredicates<vti>.Predicates in {
3245+
def : XVPatUnaryNoMask<intrinsic, instruction, "M", vti.Vector, vti.Mask,
3246+
vti.Log2SEW, vti.LMul, vti.RegClass, VR>;
3247+
def : XVPatUnaryMask<intrinsic, instruction, "M", vti.Vector, vti.Mask,
3248+
vti.Mask, vti.Log2SEW, vti.LMul, vti.RegClass, VR>;
3249+
}
3250+
}
3251+
}
3252+
31233253
multiclass XVPatCompare_VI<string intrinsic, string inst,
31243254
ImmLeaf ImmType> {
31253255
foreach vti = AllIntegerXVectors in {
@@ -4069,4 +4199,15 @@ defm : XVPatUnaryM_M<"int_riscv_th_vmsbf", "PseudoTH_VMSBF">;
40694199
defm : XVPatUnaryM_M<"int_riscv_th_vmsif", "PseudoTH_VMSIF">;
40704200
defm : XVPatUnaryM_M<"int_riscv_th_vmsof", "PseudoTH_VMSOF">;
40714201

4202+
//===----------------------------------------------------------------------===//
4203+
// 16.7. Vector Iota Operations
4204+
// 16.8. Vector Element Index Operations
4205+
//===----------------------------------------------------------------------===//
4206+
defm PseudoTH_VIOTA_M: XVPseudoVIOT_M;
4207+
defm PseudoTH_VID : XVPseudoVID_V;
4208+
4209+
// Patterns
4210+
defm : XVPatUnaryV_M<"int_riscv_th_viota", "PseudoTH_VIOTA">;
4211+
defm : XVPatNullaryV<"int_riscv_th_vid", "PseudoTH_VID">;
4212+
40724213
include "RISCVInstrInfoXTHeadVVLPatterns.td"

0 commit comments

Comments
 (0)