@@ -201,79 +201,83 @@ 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 *TargetRegisterInfo::getCommonMinimalPhysRegClass (
226
- MCRegister Reg1, MCRegister Reg2, MVT VT) const {
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>);
227
238
assert (Register::isPhysicalRegister (Reg1) &&
228
239
Register::isPhysicalRegister (Reg2) &&
229
240
" Reg1/Reg2 must be a physical register" );
230
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
+ }();
248
+
231
249
// Pick the most sub register class of the right type that contains
232
250
// this physreg.
233
251
const TargetRegisterClass *BestRC = nullptr ;
234
- for (const TargetRegisterClass *RC : regclasses ()) {
235
- if ((VT == MVT::Other || isTypeLegalForClass (*RC, VT )) &&
252
+ for (const TargetRegisterClass *RC : TRI-> regclasses ()) {
253
+ if ((IsDefault || TRI-> isTypeLegalForClass (*RC, Ty )) &&
236
254
RC->contains (Reg1, Reg2) && (!BestRC || BestRC->hasSubClass (RC)))
237
255
BestRC = RC;
238
256
}
239
257
240
- assert (BestRC && " Couldn't find the register class" );
258
+ if constexpr (std::is_same_v<TypeT, MVT>)
259
+ assert (BestRC && " Couldn't find the register class" );
241
260
return BestRC;
242
261
}
243
262
244
263
const TargetRegisterClass *
245
- TargetRegisterInfo::getMinimalPhysRegClassLLT (MCRegister reg, LLT Ty ) const {
246
- assert ( Register::isPhysicalRegister (reg) &&
247
- " reg must be a physical register " );
264
+ TargetRegisterInfo::getMinimalPhysRegClass (MCRegister Reg, MVT VT ) const {
265
+ return :: getMinimalPhysRegClass ( this , Reg, VT);
266
+ }
248
267
249
- // Pick the most sub register class of the right type that contains
250
- // this physreg.
251
- const TargetRegisterClass *BestRC = nullptr ;
252
- for (const TargetRegisterClass *RC : regclasses ()) {
253
- if ((!Ty.isValid () || isTypeLegalForClass (*RC, Ty)) && RC->contains (reg) &&
254
- (!BestRC || BestRC->hasSubClass (RC)))
255
- BestRC = RC;
256
- }
268
+ const TargetRegisterClass *TargetRegisterInfo::getCommonMinimalPhysRegClass (
269
+ MCRegister Reg1, MCRegister Reg2, MVT VT) const {
270
+ return ::getCommonMinimalPhysRegClass (this , Reg1, Reg2, VT);
271
+ }
257
272
258
- return BestRC;
273
+ const TargetRegisterClass *
274
+ TargetRegisterInfo::getMinimalPhysRegClassLLT (MCRegister Reg, LLT Ty) const {
275
+ return ::getMinimalPhysRegClass (this , Reg, Ty);
259
276
}
260
277
261
278
const TargetRegisterClass *TargetRegisterInfo::getCommonMinimalPhysRegClassLLT (
262
279
MCRegister Reg1, MCRegister Reg2, LLT Ty) const {
263
- assert (Register::isPhysicalRegister (Reg1) &&
264
- Register::isPhysicalRegister (Reg2) &&
265
- " Reg1/Reg2 must be a physical register" );
266
-
267
- // Pick the most sub register class of the right type that contains
268
- // this physreg.
269
- const TargetRegisterClass *BestRC = nullptr ;
270
- for (const TargetRegisterClass *RC : regclasses ()) {
271
- if ((!Ty.isValid () || isTypeLegalForClass (*RC, Ty)) &&
272
- RC->contains (Reg1, Reg2) && (!BestRC || BestRC->hasSubClass (RC)))
273
- BestRC = RC;
274
- }
275
-
276
- return BestRC;
280
+ return ::getCommonMinimalPhysRegClass (this , Reg1, Reg2, Ty);
277
281
}
278
282
279
283
// / getAllocatableSetForRC - Toggle the bits that represent allocatable
0 commit comments