LLVM  14.0.0git
LegalityPredicates.cpp
Go to the documentation of this file.
1 //===- lib/CodeGen/GlobalISel/LegalizerPredicates.cpp - Predicates --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // A library of predicate factories to use for LegalityPredicate.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 // Enable optimizations to work around MSVC debug mode bug in 32-bit:
14 // https://developercommunity.visualstudio.com/content/problem/1179643/msvc-copies-overaligned-non-trivially-copyable-par.html
15 // FIXME: Remove this when the issue is closed.
16 #if defined(_MSC_VER) && !defined(__clang__) && defined(_M_IX86)
17 // We have to disable runtime checks in order to enable optimizations. This is
18 // done for the entire file because the problem is actually observed in STL
19 // template functions.
20 #pragma runtime_checks("", off)
21 #pragma optimize("gs", on)
22 #endif
23 
25 
26 using namespace llvm;
27 
29  return
30  [=](const LegalityQuery &Query) { return Query.Types[TypeIdx] == Type; };
31 }
32 
35  std::initializer_list<LLT> TypesInit) {
36  SmallVector<LLT, 4> Types = TypesInit;
37  return [=](const LegalityQuery &Query) {
38  return llvm::is_contained(Types, Query.Types[TypeIdx]);
39  };
40 }
41 
43  unsigned TypeIdx0, unsigned TypeIdx1,
44  std::initializer_list<std::pair<LLT, LLT>> TypesInit) {
45  SmallVector<std::pair<LLT, LLT>, 4> Types = TypesInit;
46  return [=](const LegalityQuery &Query) {
47  std::pair<LLT, LLT> Match = {Query.Types[TypeIdx0], Query.Types[TypeIdx1]};
48  return llvm::is_contained(Types, Match);
49  };
50 }
51 
53  unsigned TypeIdx0, unsigned TypeIdx1, unsigned MMOIdx,
54  std::initializer_list<TypePairAndMemDesc> TypesAndMemDescInit) {
55  SmallVector<TypePairAndMemDesc, 4> TypesAndMemDesc = TypesAndMemDescInit;
56  return [=](const LegalityQuery &Query) {
57  TypePairAndMemDesc Match = {Query.Types[TypeIdx0], Query.Types[TypeIdx1],
58  Query.MMODescrs[MMOIdx].MemoryTy,
59  Query.MMODescrs[MMOIdx].AlignInBits};
60  return llvm::any_of(TypesAndMemDesc,
61  [=](const TypePairAndMemDesc &Entry) -> bool {
62  return Match.isCompatible(Entry);
63  });
64  };
65 }
66 
68  return [=](const LegalityQuery &Query) {
69  return Query.Types[TypeIdx].isScalar();
70  };
71 }
72 
74  return [=](const LegalityQuery &Query) {
75  return Query.Types[TypeIdx].isVector();
76  };
77 }
78 
80  return [=](const LegalityQuery &Query) {
81  return Query.Types[TypeIdx].isPointer();
82  };
83 }
84 
86  unsigned AddrSpace) {
87  return [=](const LegalityQuery &Query) {
88  LLT Ty = Query.Types[TypeIdx];
89  return Ty.isPointer() && Ty.getAddressSpace() == AddrSpace;
90  };
91 }
92 
94  LLT EltTy) {
95  return [=](const LegalityQuery &Query) {
96  const LLT QueryTy = Query.Types[TypeIdx];
97  return QueryTy.isVector() && QueryTy.getElementType() == EltTy;
98  };
99 }
100 
102  unsigned Size) {
103  return [=](const LegalityQuery &Query) {
104  const LLT QueryTy = Query.Types[TypeIdx];
105  return QueryTy.isScalar() && QueryTy.getSizeInBits() < Size;
106  };
107 }
108 
110  unsigned Size) {
111  return [=](const LegalityQuery &Query) {
112  const LLT QueryTy = Query.Types[TypeIdx];
113  return QueryTy.isScalar() && QueryTy.getSizeInBits() > Size;
114  };
115 }
116 
118  unsigned TypeIdx1) {
119  return [=](const LegalityQuery &Query) {
120  return Query.Types[TypeIdx0].getSizeInBits() <
121  Query.Types[TypeIdx1].getSizeInBits();
122  };
123 }
124 
126  unsigned TypeIdx1) {
127  return [=](const LegalityQuery &Query) {
128  return Query.Types[TypeIdx0].getSizeInBits() >
129  Query.Types[TypeIdx1].getSizeInBits();
130  };
131 }
132 
134  unsigned Size) {
135  return [=](const LegalityQuery &Query) {
136  const LLT QueryTy = Query.Types[TypeIdx];
137  return QueryTy.getScalarSizeInBits() < Size;
138  };
139 }
140 
142  unsigned Size) {
143  return [=](const LegalityQuery &Query) {
144  const LLT QueryTy = Query.Types[TypeIdx];
145  return QueryTy.getScalarSizeInBits() > Size;
146  };
147 }
148 
150  return [=](const LegalityQuery &Query) {
151  const LLT QueryTy = Query.Types[TypeIdx];
152  return !isPowerOf2_32(QueryTy.getScalarSizeInBits());
153  };
154 }
155 
157  unsigned Size) {
158  return [=](const LegalityQuery &Query) {
159  const LLT QueryTy = Query.Types[TypeIdx];
160  return QueryTy.isScalar() && QueryTy.getSizeInBits() % Size != 0;
161  };
162 }
163 
165  return [=](const LegalityQuery &Query) {
166  const LLT QueryTy = Query.Types[TypeIdx];
167  return QueryTy.isScalar() && !isPowerOf2_32(QueryTy.getSizeInBits());
168  };
169 }
170 
171 LegalityPredicate LegalityPredicates::sizeIs(unsigned TypeIdx, unsigned Size) {
172  return [=](const LegalityQuery &Query) {
173  return Query.Types[TypeIdx].getSizeInBits() == Size;
174  };
175 }
176 
178  unsigned TypeIdx1) {
179  return [=](const LegalityQuery &Query) {
180  return Query.Types[TypeIdx0].getSizeInBits() ==
181  Query.Types[TypeIdx1].getSizeInBits();
182  };
183 }
184 
186  return [=](const LegalityQuery &Query) {
187  return !isPowerOf2_32(Query.MMODescrs[MMOIdx].MemoryTy.getSizeInBytes());
188  };
189 }
190 
192  return [=](const LegalityQuery &Query) {
193  const LLT QueryTy = Query.Types[TypeIdx];
194  return QueryTy.isVector() && !isPowerOf2_32(QueryTy.getNumElements());
195  };
196 }
197 
199  unsigned MMOIdx, AtomicOrdering Ordering) {
200  return [=](const LegalityQuery &Query) {
201  return isAtLeastOrStrongerThan(Query.MMODescrs[MMOIdx].Ordering, Ordering);
202  };
203 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::LegalityPredicates::scalarOrEltWiderThan
LegalityPredicate scalarOrEltWiderThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar or a vector with an element type that's wider than the ...
Definition: LegalityPredicates.cpp:141
llvm::LLT::getScalarSizeInBits
unsigned getScalarSizeInBits() const
Definition: LowLevelTypeImpl.h:213
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::LegalityPredicates::largerThan
LegalityPredicate largerThan(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the first type index has a larger total bit size than second type index.
Definition: LegalityPredicates.cpp:125
llvm::LegalityPredicates::scalarNarrowerThan
LegalityPredicate scalarNarrowerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that's narrower than the given size.
Definition: LegalityPredicates.cpp:101
llvm::LegalityPredicates::elementTypeIs
LegalityPredicate elementTypeIs(unsigned TypeIdx, LLT EltTy)
True if the type index is a vector with element type EltTy.
Definition: LegalityPredicates.cpp:93
llvm::DiagnosticPredicateTy::Match
@ Match
llvm::LegalityPredicates::sizeNotMultipleOf
LegalityPredicate sizeNotMultipleOf(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar whose size is not a multiple of Size.
Definition: LegalityPredicates.cpp:156
llvm::isPowerOf2_32
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:491
LegalizerInfo.h
llvm::LegalityPredicates::isPointer
LegalityPredicate isPointer(unsigned TypeIdx)
True iff the specified type index is a pointer (with any address space).
Definition: LegalityPredicates.cpp:79
llvm::LegalityPredicates::atomicOrderingAtLeastOrStrongerThan
LegalityPredicate atomicOrderingAtLeastOrStrongerThan(unsigned MMOIdx, AtomicOrdering Ordering)
True iff the specified MMO index has at an atomic ordering of at Ordering or stronger.
Definition: LegalityPredicates.cpp:198
llvm::isAtLeastOrStrongerThan
bool isAtLeastOrStrongerThan(AtomicOrdering AO, AtomicOrdering Other)
Definition: AtomicOrdering.h:105
llvm::LegalityPredicates::typeIs
LegalityPredicate typeIs(unsigned TypeIdx, LLT TypesInit)
True iff the given type index is the specified type.
Definition: LegalityPredicates.cpp:28
llvm::LegalityPredicates::smallerThan
LegalityPredicate smallerThan(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the first type index has a smaller total bit size than second type index.
Definition: LegalityPredicates.cpp:117
llvm::LLT::getSizeInBits
TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
Definition: LowLevelTypeImpl.h:153
llvm::LegalityPredicates::scalarOrEltSizeNotPow2
LegalityPredicate scalarOrEltSizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar or vector whose element size is not a power of 2.
Definition: LegalityPredicates.cpp:149
llvm::LLT::getAddressSpace
unsigned getAddressSpace() const
Definition: LowLevelTypeImpl.h:227
llvm::AtomicOrdering
AtomicOrdering
Atomic ordering for LLVM's memory model.
Definition: AtomicOrdering.h:56
llvm::LLT::isVector
bool isVector() const
Definition: LowLevelTypeImpl.h:123
llvm::LLT::getNumElements
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
Definition: LowLevelTypeImpl.h:127
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1616
llvm::LLT::isPointer
bool isPointer() const
Definition: LowLevelTypeImpl.h:121
llvm::LegalityPredicate
std::function< bool(const LegalityQuery &)> LegalityPredicate
Definition: LegalizerInfo.h:199
llvm::LegalityPredicates::typeInSet
LegalityPredicate typeInSet(unsigned TypeIdx, std::initializer_list< LLT > TypesInit)
True iff the given type index is one of the specified types.
Definition: LegalityPredicates.cpp:34
llvm::LLT::isScalar
bool isScalar() const
Definition: LowLevelTypeImpl.h:119
llvm::LegalityQuery
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
Definition: LegalizerInfo.h:108
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1558
llvm::LegalityPredicates::typePairInSet
LegalityPredicate typePairInSet(unsigned TypeIdx0, unsigned TypeIdx1, std::initializer_list< std::pair< LLT, LLT >> TypesInit)
True iff the given types for the given pair of type indexes is one of the specified type pairs.
Definition: LegalityPredicates.cpp:42
llvm::LegalityPredicates::sizeNotPow2
LegalityPredicate sizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar whose size is not a power of.
Definition: LegalityPredicates.cpp:164
llvm::LegalityPredicates::isScalar
LegalityPredicate isScalar(unsigned TypeIdx)
True iff the specified type index is a scalar.
Definition: LegalityPredicates.cpp:67
llvm::LegalityPredicates::scalarOrEltNarrowerThan
LegalityPredicate scalarOrEltNarrowerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar or vector with an element type that's narrower than the...
Definition: LegalityPredicates.cpp:133
llvm::LegalityPredicates::sizeIs
LegalityPredicate sizeIs(unsigned TypeIdx, unsigned Size)
True if the total bitwidth of the specified type index is Size bits.
Definition: LegalityPredicates.cpp:171
llvm::LegalityPredicates::memSizeInBytesNotPow2
LegalityPredicate memSizeInBytesNotPow2(unsigned MMOIdx)
True iff the specified MMO index has a size that is not a power of 2.
Definition: LegalityPredicates.cpp:185
llvm::LegalityPredicates::scalarWiderThan
LegalityPredicate scalarWiderThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that's wider than the given size.
Definition: LegalityPredicates.cpp:109
llvm::LegalityPredicates::TypePairAndMemDesc
Definition: LegalizerInfo.h:204
llvm::LegalityPredicates::numElementsNotPow2
LegalityPredicate numElementsNotPow2(unsigned TypeIdx)
True iff the specified type index is a vector whose element count is not a power of 2.
Definition: LegalityPredicates.cpp:191
llvm::LegalityPredicates::isVector
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
Definition: LegalityPredicates.cpp:73
llvm::LegalityPredicates::typePairAndMemDescInSet
LegalityPredicate typePairAndMemDescInSet(unsigned TypeIdx0, unsigned TypeIdx1, unsigned MMOIdx, std::initializer_list< TypePairAndMemDesc > TypesAndMemDescInit)
True iff the given types for the given pair of type indexes is one of the specified type pairs.
Definition: LegalityPredicates.cpp:52
llvm::LLT::getElementType
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
Definition: LowLevelTypeImpl.h:237
llvm::LegalityPredicates::sameSize
LegalityPredicate sameSize(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the specified type indices are both the same bit size.
Definition: LegalityPredicates.cpp:177
llvm::LLT
Definition: LowLevelTypeImpl.h:40