@@ -25,17 +25,27 @@ namespace llvm {
25
25
namespace RISCV {
26
26
27
27
const RegisterBankInfo::PartialMapping PartMappings[] = {
28
+ // clang-format off
28
29
{0 , 32 , GPRBRegBank},
29
30
{0 , 64 , GPRBRegBank},
30
31
{0 , 32 , FPRBRegBank},
31
32
{0 , 64 , FPRBRegBank},
33
+ {0 , 64 , VRBRegBank},
34
+ {0 , 128 , VRBRegBank},
35
+ {0 , 256 , VRBRegBank},
36
+ {0 , 512 , VRBRegBank},
37
+ // clang-format on
32
38
};
33
39
34
40
enum PartialMappingIdx {
35
41
PMI_GPRB32 = 0 ,
36
42
PMI_GPRB64 = 1 ,
37
43
PMI_FPRB32 = 2 ,
38
44
PMI_FPRB64 = 3 ,
45
+ PMI_VRB64 = 4 ,
46
+ PMI_VRB128 = 5 ,
47
+ PMI_VRB256 = 6 ,
48
+ PMI_VRB512 = 7 ,
39
49
};
40
50
41
51
const RegisterBankInfo::ValueMapping ValueMappings[] = {
@@ -57,6 +67,22 @@ const RegisterBankInfo::ValueMapping ValueMappings[] = {
57
67
{&PartMappings[PMI_FPRB64], 1 },
58
68
{&PartMappings[PMI_FPRB64], 1 },
59
69
{&PartMappings[PMI_FPRB64], 1 },
70
+ // Maximum 3 VR LMUL={1, MF2, MF4, MF8} operands.
71
+ {&PartMappings[PMI_VRB64], 1 },
72
+ {&PartMappings[PMI_VRB64], 1 },
73
+ {&PartMappings[PMI_VRB64], 1 },
74
+ // Maximum 3 VR LMUL=2 operands.
75
+ {&PartMappings[PMI_VRB128], 1 },
76
+ {&PartMappings[PMI_VRB128], 1 },
77
+ {&PartMappings[PMI_VRB128], 1 },
78
+ // Maximum 3 VR LMUL=4 operands.
79
+ {&PartMappings[PMI_VRB256], 1 },
80
+ {&PartMappings[PMI_VRB256], 1 },
81
+ {&PartMappings[PMI_VRB256], 1 },
82
+ // Maximum 3 VR LMUL=8 operands.
83
+ {&PartMappings[PMI_VRB512], 1 },
84
+ {&PartMappings[PMI_VRB512], 1 },
85
+ {&PartMappings[PMI_VRB512], 1 },
60
86
};
61
87
62
88
enum ValueMappingIdx {
@@ -65,6 +91,10 @@ enum ValueMappingIdx {
65
91
GPRB64Idx = 4 ,
66
92
FPRB32Idx = 7 ,
67
93
FPRB64Idx = 10 ,
94
+ VRB64Idx = 13 ,
95
+ VRB128Idx = 16 ,
96
+ VRB256Idx = 19 ,
97
+ VRB512Idx = 22 ,
68
98
};
69
99
} // namespace RISCV
70
100
} // namespace llvm
@@ -215,6 +245,23 @@ bool RISCVRegisterBankInfo::anyUseOnlyUseFP(
215
245
[&](const MachineInstr &UseMI) { return onlyUsesFP (UseMI, MRI, TRI); });
216
246
}
217
247
248
+ static const RegisterBankInfo::ValueMapping *getVRBValueMapping (unsigned Size ) {
249
+ unsigned Idx;
250
+
251
+ if (Size <= 64 )
252
+ Idx = RISCV::VRB64Idx;
253
+ else if (Size == 128 )
254
+ Idx = RISCV::VRB128Idx;
255
+ else if (Size == 256 )
256
+ Idx = RISCV::VRB256Idx;
257
+ else if (Size == 512 )
258
+ Idx = RISCV::VRB512Idx;
259
+ else
260
+ llvm::report_fatal_error (" Invalid Size" );
261
+
262
+ return &RISCV::ValueMappings[Idx];
263
+ }
264
+
218
265
const RegisterBankInfo::InstructionMapping &
219
266
RISCVRegisterBankInfo::getInstrMapping (const MachineInstr &MI) const {
220
267
const unsigned Opc = MI.getOpcode ();
@@ -242,7 +289,16 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
242
289
243
290
switch (Opc) {
244
291
case TargetOpcode::G_ADD:
245
- case TargetOpcode::G_SUB:
292
+ case TargetOpcode::G_SUB: {
293
+ if (MRI.getType (MI.getOperand (0 ).getReg ()).isVector ()) {
294
+ LLT Ty = MRI.getType (MI.getOperand (0 ).getReg ());
295
+ return getInstructionMapping (
296
+ DefaultMappingID, /* Cost=*/ 1 ,
297
+ getVRBValueMapping (Ty.getSizeInBits ().getKnownMinValue ()),
298
+ NumOperands);
299
+ }
300
+ }
301
+ LLVM_FALLTHROUGH;
246
302
case TargetOpcode::G_SHL:
247
303
case TargetOpcode::G_ASHR:
248
304
case TargetOpcode::G_LSHR:
0 commit comments