@@ -201,44 +201,85 @@ TargetRegisterInfo::getAllocatableClass(const TargetRegisterClass *RC) const {
201
201
return nullptr ;
202
202
}
203
203
204
- // / getMinimalPhysRegClass - Returns the Register Class of a physical
205
- // / register of the given type, picking the most sub register class of
206
- // / the right type that contains this physreg.
207
- const TargetRegisterClass *
208
- TargetRegisterInfo::getMinimalPhysRegClass (MCRegister reg , MVT VT) const {
209
- assert (Register::isPhysicalRegister (reg ) &&
204
+ template < typename TypeT>
205
+ static const TargetRegisterClass *
206
+ getMinimalPhysRegClass ( const TargetRegisterInfo *TRI, MCRegister Reg,
207
+ TypeT Ty) {
208
+ static_assert (std::is_same_v<TypeT , MVT> || std::is_same_v<TypeT, LLT>);
209
+ assert (Register::isPhysicalRegister (Reg ) &&
210
210
" reg must be a physical register" );
211
211
212
+ bool IsDefault = [&]() {
213
+ if constexpr (std::is_same_v<TypeT, MVT>)
214
+ return Ty == MVT::Other;
215
+ else
216
+ return !Ty.isValid ();
217
+ }();
218
+
212
219
// Pick the most sub register class of the right type that contains
213
220
// this physreg.
214
- const TargetRegisterClass* BestRC = nullptr ;
215
- for (const TargetRegisterClass* RC : regclasses ()) {
216
- if ((VT == MVT::Other || isTypeLegalForClass (*RC, VT) ) &&
217
- RC-> contains (reg) && (!BestRC || BestRC->hasSubClass (RC)))
221
+ const TargetRegisterClass * BestRC = nullptr ;
222
+ for (const TargetRegisterClass * RC : TRI-> regclasses ()) {
223
+ if ((IsDefault || TRI-> isTypeLegalForClass (*RC, Ty)) && RC-> contains (Reg ) &&
224
+ (!BestRC || BestRC->hasSubClass (RC)))
218
225
BestRC = RC;
219
226
}
220
227
221
- assert (BestRC && " Couldn't find the register class" );
228
+ if constexpr (std::is_same_v<TypeT, MVT>)
229
+ assert (BestRC && " Couldn't find the register class" );
222
230
return BestRC;
223
231
}
224
232
225
- const TargetRegisterClass *
226
- TargetRegisterInfo::getMinimalPhysRegClassLLT (MCRegister reg, LLT Ty) const {
227
- assert (Register::isPhysicalRegister (reg) &&
228
- " reg must be a physical register" );
233
+ template <typename TypeT>
234
+ static const TargetRegisterClass *
235
+ getCommonMinimalPhysRegClass (const TargetRegisterInfo *TRI, MCRegister Reg1,
236
+ MCRegister Reg2, TypeT Ty) {
237
+ static_assert (std::is_same_v<TypeT, MVT> || std::is_same_v<TypeT, LLT>);
238
+ assert (Register::isPhysicalRegister (Reg1) &&
239
+ Register::isPhysicalRegister (Reg2) &&
240
+ " Reg1/Reg2 must be a physical register" );
241
+
242
+ bool IsDefault = [&]() {
243
+ if constexpr (std::is_same_v<TypeT, MVT>)
244
+ return Ty == MVT::Other;
245
+ else
246
+ return !Ty.isValid ();
247
+ }();
229
248
230
249
// Pick the most sub register class of the right type that contains
231
250
// this physreg.
232
251
const TargetRegisterClass *BestRC = nullptr ;
233
- for (const TargetRegisterClass *RC : regclasses ()) {
234
- if ((!Ty. isValid () || isTypeLegalForClass (*RC, Ty)) && RC-> contains (reg ) &&
235
- (!BestRC || BestRC->hasSubClass (RC)))
252
+ for (const TargetRegisterClass *RC : TRI-> regclasses ()) {
253
+ if ((IsDefault || TRI-> isTypeLegalForClass (*RC, Ty)) &&
254
+ RC-> contains (Reg1, Reg2) && (!BestRC || BestRC->hasSubClass (RC)))
236
255
BestRC = RC;
237
256
}
238
257
258
+ if constexpr (std::is_same_v<TypeT, MVT>)
259
+ assert (BestRC && " Couldn't find the register class" );
239
260
return BestRC;
240
261
}
241
262
263
+ const TargetRegisterClass *
264
+ TargetRegisterInfo::getMinimalPhysRegClass (MCRegister Reg, MVT VT) const {
265
+ return ::getMinimalPhysRegClass (this , Reg, VT);
266
+ }
267
+
268
+ const TargetRegisterClass *TargetRegisterInfo::getCommonMinimalPhysRegClass (
269
+ MCRegister Reg1, MCRegister Reg2, MVT VT) const {
270
+ return ::getCommonMinimalPhysRegClass (this , Reg1, Reg2, VT);
271
+ }
272
+
273
+ const TargetRegisterClass *
274
+ TargetRegisterInfo::getMinimalPhysRegClassLLT (MCRegister Reg, LLT Ty) const {
275
+ return ::getMinimalPhysRegClass (this , Reg, Ty);
276
+ }
277
+
278
+ const TargetRegisterClass *TargetRegisterInfo::getCommonMinimalPhysRegClassLLT (
279
+ MCRegister Reg1, MCRegister Reg2, LLT Ty) const {
280
+ return ::getCommonMinimalPhysRegClass (this , Reg1, Reg2, Ty);
281
+ }
282
+
242
283
// / getAllocatableSetForRC - Toggle the bits that represent allocatable
243
284
// / registers for the specific register class.
244
285
static void getAllocatableSetForRC (const MachineFunction &MF,
0 commit comments