1 //===- lib/CodeGen/GlobalISel/LegalizerPredicates.cpp - Predicates --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // A library of predicate factories to use for LegalityPredicate.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
18 LegalityPredicate
LegalityPredicates::typeIs(unsigned TypeIdx
, LLT Type
) {
20 [=](const LegalityQuery
&Query
) { return Query
.Types
[TypeIdx
] == Type
; };
24 LegalityPredicates::typeInSet(unsigned TypeIdx
,
25 std::initializer_list
<LLT
> TypesInit
) {
26 SmallVector
<LLT
, 4> Types
= TypesInit
;
27 return [=](const LegalityQuery
&Query
) {
28 return std::find(Types
.begin(), Types
.end(), Query
.Types
[TypeIdx
]) != Types
.end();
32 LegalityPredicate
LegalityPredicates::typePairInSet(
33 unsigned TypeIdx0
, unsigned TypeIdx1
,
34 std::initializer_list
<std::pair
<LLT
, LLT
>> TypesInit
) {
35 SmallVector
<std::pair
<LLT
, LLT
>, 4> Types
= TypesInit
;
36 return [=](const LegalityQuery
&Query
) {
37 std::pair
<LLT
, LLT
> Match
= {Query
.Types
[TypeIdx0
], Query
.Types
[TypeIdx1
]};
38 return std::find(Types
.begin(), Types
.end(), Match
) != Types
.end();
42 LegalityPredicate
LegalityPredicates::typePairAndMemSizeInSet(
43 unsigned TypeIdx0
, unsigned TypeIdx1
, unsigned MMOIdx
,
44 std::initializer_list
<TypePairAndMemSize
> TypesAndMemSizeInit
) {
45 SmallVector
<TypePairAndMemSize
, 4> TypesAndMemSize
= TypesAndMemSizeInit
;
46 return [=](const LegalityQuery
&Query
) {
47 TypePairAndMemSize Match
= {Query
.Types
[TypeIdx0
], Query
.Types
[TypeIdx1
],
48 Query
.MMODescrs
[MMOIdx
].Size
};
49 return std::find(TypesAndMemSize
.begin(), TypesAndMemSize
.end(), Match
) !=
50 TypesAndMemSize
.end();
54 LegalityPredicate
LegalityPredicates::isScalar(unsigned TypeIdx
) {
55 return [=](const LegalityQuery
&Query
) {
56 return Query
.Types
[TypeIdx
].isScalar();
60 LegalityPredicate
LegalityPredicates::narrowerThan(unsigned TypeIdx
,
62 return [=](const LegalityQuery
&Query
) {
63 const LLT
&QueryTy
= Query
.Types
[TypeIdx
];
64 return QueryTy
.isScalar() && QueryTy
.getSizeInBits() < Size
;
68 LegalityPredicate
LegalityPredicates::widerThan(unsigned TypeIdx
,
70 return [=](const LegalityQuery
&Query
) {
71 const LLT
&QueryTy
= Query
.Types
[TypeIdx
];
72 return QueryTy
.isScalar() && QueryTy
.getSizeInBits() > Size
;
76 LegalityPredicate
LegalityPredicates::sizeNotPow2(unsigned TypeIdx
) {
77 return [=](const LegalityQuery
&Query
) {
78 const LLT
&QueryTy
= Query
.Types
[TypeIdx
];
79 return QueryTy
.isScalar() && !isPowerOf2_32(QueryTy
.getSizeInBits());
83 LegalityPredicate
LegalityPredicates::memSizeInBytesNotPow2(unsigned MMOIdx
) {
84 return [=](const LegalityQuery
&Query
) {
85 return !isPowerOf2_32(Query
.MMODescrs
[MMOIdx
].Size
/* In Bytes */);
89 LegalityPredicate
LegalityPredicates::numElementsNotPow2(unsigned TypeIdx
) {
90 return [=](const LegalityQuery
&Query
) {
91 const LLT
&QueryTy
= Query
.Types
[TypeIdx
];
92 return QueryTy
.isVector() && isPowerOf2_32(QueryTy
.getNumElements());
96 LegalityPredicate
LegalityPredicates::atomicOrderingAtLeastOrStrongerThan(
97 unsigned MMOIdx
, AtomicOrdering Ordering
) {
98 return [=](const LegalityQuery
&Query
) {
99 return isAtLeastOrStrongerThan(Query
.MMODescrs
[MMOIdx
].Ordering
, Ordering
);