@@ -215,12 +215,27 @@ LegalityPredicate isPointer(unsigned TypeIdx, unsigned AddrSpace);
215
215
// / True iff the specified type index is a scalar that's narrower than the given
216
216
// / size.
217
217
LegalityPredicate narrowerThan (unsigned TypeIdx, unsigned Size);
218
+
218
219
// / True iff the specified type index is a scalar that's wider than the given
219
220
// / size.
220
221
LegalityPredicate widerThan (unsigned TypeIdx, unsigned Size);
222
+
223
+ // / True iff the specified type index is a scalar or vector with an element type
224
+ // / that's narrower than the given size.
225
+ LegalityPredicate scalarOrEltNarrowerThan (unsigned TypeIdx, unsigned Size);
226
+
227
+ // / True iff the specified type index is a scalar or a vector with an element
228
+ // / type that's wider than the given size.
229
+ LegalityPredicate scalarOrEltWiderThan (unsigned TypeIdx, unsigned Size);
230
+
221
231
// / True iff the specified type index is a scalar whose size is not a power of
222
232
// / 2.
223
233
LegalityPredicate sizeNotPow2 (unsigned TypeIdx);
234
+
235
+ // / True iff the specified type index is a scalar or vector whose element size
236
+ // / is not a power of 2.
237
+ LegalityPredicate scalarOrEltSizeNotPow2 (unsigned TypeIdx);
238
+
224
239
// / True iff the specified type indices are both the same bit size.
225
240
LegalityPredicate sameSize (unsigned TypeIdx0, unsigned TypeIdx1);
226
241
// / True iff the specified MMO index has a size that is not a power of 2
@@ -237,10 +252,20 @@ LegalityPredicate atomicOrderingAtLeastOrStrongerThan(unsigned MMOIdx,
237
252
namespace LegalizeMutations {
238
253
// / Select this specific type for the given type index.
239
254
LegalizeMutation changeTo (unsigned TypeIdx, LLT Ty);
255
+
240
256
// / Keep the same type as the given type index.
241
257
LegalizeMutation changeTo (unsigned TypeIdx, unsigned FromTypeIdx);
242
- // / Widen the type for the given type index to the next power of 2.
243
- LegalizeMutation widenScalarToNextPow2 (unsigned TypeIdx, unsigned Min = 0 );
258
+
259
+ // / Keep the same scalar or element type as the given type index.
260
+ LegalizeMutation changeElementTo (unsigned TypeIdx, unsigned FromTypeIdx);
261
+
262
+ // / Keep the same scalar or element type as the given type.
263
+ LegalizeMutation changeElementTo (unsigned TypeIdx, LLT Ty);
264
+
265
+ // / Widen the scalar type or vector element type for the given type index to the
266
+ // / next power of 2.
267
+ LegalizeMutation widenScalarOrEltToNextPow2 (unsigned TypeIdx, unsigned Min = 0 );
268
+
244
269
// / Add more elements to the type for the given type index to the next power of
245
270
// / 2.
246
271
LegalizeMutation moreElementsToNextPow2 (unsigned TypeIdx, unsigned Min = 0 );
@@ -618,8 +643,19 @@ class LegalizeRuleSet {
618
643
LegalizeRuleSet &widenScalarToNextPow2 (unsigned TypeIdx,
619
644
unsigned MinSize = 0 ) {
620
645
using namespace LegalityPredicates ;
621
- return actionIf (LegalizeAction::WidenScalar, sizeNotPow2 (typeIdx (TypeIdx)),
622
- LegalizeMutations::widenScalarToNextPow2 (TypeIdx, MinSize));
646
+ return actionIf (
647
+ LegalizeAction::WidenScalar, sizeNotPow2 (typeIdx (TypeIdx)),
648
+ LegalizeMutations::widenScalarOrEltToNextPow2 (TypeIdx, MinSize));
649
+ }
650
+
651
+ // / Widen the scalar or vector element type to the next power of two that is
652
+ // / at least MinSize. No effect if the scalar size is a power of two.
653
+ LegalizeRuleSet &widenScalarOrEltToNextPow2 (unsigned TypeIdx,
654
+ unsigned MinSize = 0 ) {
655
+ using namespace LegalityPredicates ;
656
+ return actionIf (
657
+ LegalizeAction::WidenScalar, scalarOrEltSizeNotPow2 (typeIdx (TypeIdx)),
658
+ LegalizeMutations::widenScalarOrEltToNextPow2 (TypeIdx, MinSize));
623
659
}
624
660
625
661
LegalizeRuleSet &narrowScalar (unsigned TypeIdx, LegalizeMutation Mutation) {
@@ -634,6 +670,15 @@ class LegalizeRuleSet {
634
670
LegalizeMutations::scalarize (TypeIdx));
635
671
}
636
672
673
+ // / Ensure the scalar is at least as wide as Ty.
674
+ LegalizeRuleSet &minScalarOrElt (unsigned TypeIdx, const LLT &Ty) {
675
+ using namespace LegalityPredicates ;
676
+ using namespace LegalizeMutations ;
677
+ return actionIf (LegalizeAction::WidenScalar,
678
+ scalarOrEltNarrowerThan (TypeIdx, Ty.getScalarSizeInBits ()),
679
+ changeElementTo (typeIdx (TypeIdx), Ty));
680
+ }
681
+
637
682
// / Ensure the scalar is at least as wide as Ty.
638
683
LegalizeRuleSet &minScalar (unsigned TypeIdx, const LLT &Ty) {
639
684
using namespace LegalityPredicates ;
@@ -643,6 +688,15 @@ class LegalizeRuleSet {
643
688
changeTo (typeIdx (TypeIdx), Ty));
644
689
}
645
690
691
+ // / Ensure the scalar is at most as wide as Ty.
692
+ LegalizeRuleSet &maxScalarOrElt (unsigned TypeIdx, const LLT &Ty) {
693
+ using namespace LegalityPredicates ;
694
+ using namespace LegalizeMutations ;
695
+ return actionIf (LegalizeAction::NarrowScalar,
696
+ scalarOrEltWiderThan (TypeIdx, Ty.getScalarSizeInBits ()),
697
+ changeElementTo (typeIdx (TypeIdx), Ty));
698
+ }
699
+
646
700
// / Ensure the scalar is at most as wide as Ty.
647
701
LegalizeRuleSet &maxScalar (unsigned TypeIdx, const LLT &Ty) {
648
702
using namespace LegalityPredicates ;
@@ -659,12 +713,12 @@ class LegalizeRuleSet {
659
713
const LLT &Ty) {
660
714
using namespace LegalityPredicates ;
661
715
using namespace LegalizeMutations ;
662
- return actionIf (LegalizeAction::NarrowScalar,
663
- [=]( const LegalityQuery &Query) {
664
- return widerThan (TypeIdx, Ty. getSizeInBits ()) &&
665
- Predicate (Query);
666
- },
667
- changeTo (typeIdx (TypeIdx), Ty));
716
+ return actionIf (
717
+ LegalizeAction::NarrowScalar,
718
+ [=]( const LegalityQuery &Query) {
719
+ return widerThan (TypeIdx, Ty. getSizeInBits ()) && Predicate (Query);
720
+ },
721
+ changeElementTo (typeIdx (TypeIdx), Ty));
668
722
}
669
723
670
724
// / Limit the range of scalar sizes to MinTy and MaxTy.
@@ -674,6 +728,12 @@ class LegalizeRuleSet {
674
728
return minScalar (TypeIdx, MinTy).maxScalar (TypeIdx, MaxTy);
675
729
}
676
730
731
+ // / Limit the range of scalar sizes to MinTy and MaxTy.
732
+ LegalizeRuleSet &clampScalarOrElt (unsigned TypeIdx, const LLT &MinTy,
733
+ const LLT &MaxTy) {
734
+ return minScalarOrElt (TypeIdx, MinTy).maxScalarOrElt (TypeIdx, MaxTy);
735
+ }
736
+
677
737
// / Widen the scalar to match the size of another.
678
738
LegalizeRuleSet &minScalarSameAs (unsigned TypeIdx, unsigned LargeTypeIdx) {
679
739
typeIdx (TypeIdx);
0 commit comments