@@ -259,86 +259,65 @@ inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) {
259
259
return match_combine_and<LTy, RTy>(L, R);
260
260
}
261
261
262
- struct apint_match {
263
- const APInt *&Res;
262
+ template <typename APTy> struct ap_match {
263
+ static_assert (std::is_same_v<APTy, APInt> || std::is_same_v<APTy, APFloat>);
264
+ using ConstantTy =
265
+ std::conditional_t <std::is_same_v<APTy, APInt>, ConstantInt, ConstantFP>;
266
+
267
+ const APTy *&Res;
264
268
bool AllowPoison;
265
269
266
- apint_match (const APInt *&Res, bool AllowPoison)
270
+ ap_match (const APTy *&Res, bool AllowPoison)
267
271
: Res(Res), AllowPoison(AllowPoison) {}
268
272
269
273
template <typename ITy> bool match (ITy *V) const {
270
- if (auto *CI = dyn_cast<ConstantInt >(V)) {
274
+ if (auto *CI = dyn_cast<ConstantTy >(V)) {
271
275
Res = &CI->getValue ();
272
276
return true ;
273
277
}
274
278
if (V->getType ()->isVectorTy ())
275
279
if (const auto *C = dyn_cast<Constant>(V))
276
280
if (auto *CI =
277
- dyn_cast_or_null<ConstantInt >(C->getSplatValue (AllowPoison))) {
281
+ dyn_cast_or_null<ConstantTy >(C->getSplatValue (AllowPoison))) {
278
282
Res = &CI->getValue ();
279
283
return true ;
280
284
}
281
285
return false ;
282
286
}
283
287
};
284
- // Either constexpr if or renaming ConstantFP::getValueAPF to
285
- // ConstantFP::getValue is needed to do it via single template
286
- // function for both apint/apfloat.
287
- struct apfloat_match {
288
- const APFloat *&Res;
289
- bool AllowPoison;
290
-
291
- apfloat_match (const APFloat *&Res, bool AllowPoison)
292
- : Res(Res), AllowPoison(AllowPoison) {}
293
-
294
- template <typename ITy> bool match (ITy *V) const {
295
- if (auto *CI = dyn_cast<ConstantFP>(V)) {
296
- Res = &CI->getValueAPF ();
297
- return true ;
298
- }
299
- if (V->getType ()->isVectorTy ())
300
- if (const auto *C = dyn_cast<Constant>(V))
301
- if (auto *CI =
302
- dyn_cast_or_null<ConstantFP>(C->getSplatValue (AllowPoison))) {
303
- Res = &CI->getValueAPF ();
304
- return true ;
305
- }
306
- return false ;
307
- }
308
- };
309
288
310
289
// / Match a ConstantInt or splatted ConstantVector, binding the
311
290
// / specified pointer to the contained APInt.
312
- inline apint_match m_APInt (const APInt *&Res) {
291
+ inline ap_match<APInt> m_APInt (const APInt *&Res) {
313
292
// Forbid poison by default to maintain previous behavior.
314
- return apint_match (Res, /* AllowPoison */ false );
293
+ return ap_match<APInt> (Res, /* AllowPoison */ false );
315
294
}
316
295
317
296
// / Match APInt while allowing poison in splat vector constants.
318
- inline apint_match m_APIntAllowPoison (const APInt *&Res) {
319
- return apint_match (Res, /* AllowPoison */ true );
297
+ inline ap_match<APInt> m_APIntAllowPoison (const APInt *&Res) {
298
+ return ap_match<APInt> (Res, /* AllowPoison */ true );
320
299
}
321
300
322
301
// / Match APInt while forbidding poison in splat vector constants.
323
- inline apint_match m_APIntForbidPoison (const APInt *&Res) {
324
- return apint_match (Res, /* AllowPoison */ false );
302
+ inline ap_match<APInt> m_APIntForbidPoison (const APInt *&Res) {
303
+ return ap_match<APInt> (Res, /* AllowPoison */ false );
325
304
}
326
305
327
306
// / Match a ConstantFP or splatted ConstantVector, binding the
328
307
// / specified pointer to the contained APFloat.
329
- inline apfloat_match m_APFloat (const APFloat *&Res) {
308
+ inline ap_match<APFloat> m_APFloat (const APFloat *&Res) {
330
309
// Forbid undefs by default to maintain previous behavior.
331
- return apfloat_match (Res, /* AllowPoison */ false );
310
+ return ap_match<APFloat> (Res, /* AllowPoison */ false );
332
311
}
333
312
334
313
// / Match APFloat while allowing poison in splat vector constants.
335
- inline apfloat_match m_APFloatAllowPoison (const APFloat *&Res) {
336
- return apfloat_match (Res, /* AllowPoison */ true );
314
+ inline ap_match<APFloat> m_APFloatAllowPoison (const APFloat *&Res) {
315
+ return ap_match<APFloat> (Res, /* AllowPoison */ true );
337
316
}
338
317
339
318
// / Match APFloat while forbidding poison in splat vector constants.
340
- inline apfloat_match m_APFloatForbidPoison (const APFloat *&Res) {
341
- return apfloat_match (Res, /* AllowPoison */ false );
319
+ inline ap_match<APFloat> m_APFloatForbidPoison (const APFloat *&Res) {
320
+ return ap_match<APFloat> (Res, /* AllowPoison */ false );
342
321
}
343
322
344
323
template <int64_t Val> struct constantint_match {
@@ -1027,7 +1006,7 @@ struct bind_const_intval_ty {
1027
1006
1028
1007
template <typename ITy> bool match (ITy *V) const {
1029
1008
const APInt *ConstInt;
1030
- if (!apint_match (ConstInt, /* AllowPoison=*/ false ).match (V))
1009
+ if (!ap_match<APInt> (ConstInt, /* AllowPoison=*/ false ).match (V))
1031
1010
return false ;
1032
1011
if (ConstInt->getActiveBits () > 64 )
1033
1012
return false ;
0 commit comments