LLVM  10.0.0svn
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 
14 
15 using namespace llvm;
16 
18  return
19  [=](const LegalityQuery &Query) { return Query.Types[TypeIdx] == Type; };
20 }
21 
24  std::initializer_list<LLT> TypesInit) {
25  SmallVector<LLT, 4> Types = TypesInit;
26  return [=](const LegalityQuery &Query) {
27  return std::find(Types.begin(), Types.end(), Query.Types[TypeIdx]) != Types.end();
28  };
29 }
30 
32  unsigned TypeIdx0, unsigned TypeIdx1,
33  std::initializer_list<std::pair<LLT, LLT>> TypesInit) {
34  SmallVector<std::pair<LLT, LLT>, 4> Types = TypesInit;
35  return [=](const LegalityQuery &Query) {
36  std::pair<LLT, LLT> Match = {Query.Types[TypeIdx0], Query.Types[TypeIdx1]};
37  return std::find(Types.begin(), Types.end(), Match) != Types.end();
38  };
39 }
40 
42  unsigned TypeIdx0, unsigned TypeIdx1, unsigned MMOIdx,
43  std::initializer_list<TypePairAndMemDesc> TypesAndMemDescInit) {
44  SmallVector<TypePairAndMemDesc, 4> TypesAndMemDesc = TypesAndMemDescInit;
45  return [=](const LegalityQuery &Query) {
46  TypePairAndMemDesc Match = {Query.Types[TypeIdx0], Query.Types[TypeIdx1],
47  Query.MMODescrs[MMOIdx].SizeInBits,
48  Query.MMODescrs[MMOIdx].AlignInBits};
49  return std::find_if(
50  TypesAndMemDesc.begin(), TypesAndMemDesc.end(),
51  [=](const TypePairAndMemDesc &Entry) ->bool {
52  return Match.isCompatible(Entry);
53  }) != TypesAndMemDesc.end();
54  };
55 }
56 
58  return [=](const LegalityQuery &Query) {
59  return Query.Types[TypeIdx].isScalar();
60  };
61 }
62 
64  return [=](const LegalityQuery &Query) {
65  return Query.Types[TypeIdx].isVector();
66  };
67 }
68 
70  return [=](const LegalityQuery &Query) {
71  return Query.Types[TypeIdx].isPointer();
72  };
73 }
74 
76  unsigned AddrSpace) {
77  return [=](const LegalityQuery &Query) {
78  LLT Ty = Query.Types[TypeIdx];
79  return Ty.isPointer() && Ty.getAddressSpace() == AddrSpace;
80  };
81 }
82 
84  unsigned Size) {
85  return [=](const LegalityQuery &Query) {
86  const LLT QueryTy = Query.Types[TypeIdx];
87  return QueryTy.isScalar() && QueryTy.getSizeInBits() < Size;
88  };
89 }
90 
92  unsigned Size) {
93  return [=](const LegalityQuery &Query) {
94  const LLT QueryTy = Query.Types[TypeIdx];
95  return QueryTy.isScalar() && QueryTy.getSizeInBits() > Size;
96  };
97 }
98 
100  unsigned Size) {
101  return [=](const LegalityQuery &Query) {
102  const LLT QueryTy = Query.Types[TypeIdx];
103  return QueryTy.getScalarSizeInBits() < Size;
104  };
105 }
106 
108  unsigned Size) {
109  return [=](const LegalityQuery &Query) {
110  const LLT QueryTy = Query.Types[TypeIdx];
111  return QueryTy.getScalarSizeInBits() > Size;
112  };
113 }
114 
116  return [=](const LegalityQuery &Query) {
117  const LLT QueryTy = Query.Types[TypeIdx];
118  return !isPowerOf2_32(QueryTy.getScalarSizeInBits());
119  };
120 }
121 
123  return [=](const LegalityQuery &Query) {
124  const LLT QueryTy = Query.Types[TypeIdx];
125  return QueryTy.isScalar() && !isPowerOf2_32(QueryTy.getSizeInBits());
126  };
127 }
128 
130  unsigned TypeIdx1) {
131  return [=](const LegalityQuery &Query) {
132  return Query.Types[TypeIdx0].getSizeInBits() ==
133  Query.Types[TypeIdx1].getSizeInBits();
134  };
135 }
136 
138  return [=](const LegalityQuery &Query) {
139  return !isPowerOf2_32(Query.MMODescrs[MMOIdx].SizeInBits / 8);
140  };
141 }
142 
144  return [=](const LegalityQuery &Query) {
145  const LLT QueryTy = Query.Types[TypeIdx];
146  return QueryTy.isVector() && !isPowerOf2_32(QueryTy.getNumElements());
147  };
148 }
149 
151  unsigned MMOIdx, AtomicOrdering Ordering) {
152  return [=](const LegalityQuery &Query) {
153  return isAtLeastOrStrongerThan(Query.MMODescrs[MMOIdx].Ordering, Ordering);
154  };
155 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
unsigned getScalarSizeInBits() const
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...
The LegalityQuery object bundles together all the information that&#39;s needed to decide whether a given...
bool isScalar() const
LegalityPredicate scalarOrEltWiderThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar or a vector with an element type that&#39;s wider than the ...
LegalityPredicate typeIs(unsigned TypeIdx, LLT TypesInit)
True iff the given type index is the specified types.
LegalityPredicate scalarOrEltNarrowerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar or vector with an element type that&#39;s narrower than the...
LegalityPredicate isPointer(unsigned TypeIdx)
True iff the specified type index is a pointer (with any address space).
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
bool isVector() const
LegalityPredicate atomicOrderingAtLeastOrStrongerThan(unsigned MMOIdx, AtomicOrdering Ordering)
True iff the specified MMO index has at an atomic ordering of at Ordering or stronger.
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
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...
LegalityPredicate numElementsNotPow2(unsigned TypeIdx)
True iff the specified type index is a vector whose element count is not a power of 2...
bool isAtLeastOrStrongerThan(AtomicOrdering ao, AtomicOrdering other)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:428
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
LegalityPredicate narrowerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that&#39;s narrower than the given size.
LegalityPredicate memSizeInBytesNotPow2(unsigned MMOIdx)
True iff the specified MMO index has a size that is not a power of 2.
unsigned getAddressSpace() const
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1220
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1213
LegalityPredicate scalarOrEltSizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar or vector whose element size is not a power of 2...
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
LegalityPredicate isScalar(unsigned TypeIdx)
True iff the specified type index is a scalar.
bool isPointer() const
LegalityPredicate typeInSet(unsigned TypeIdx, std::initializer_list< LLT > TypesInit)
True iff the given type index is one of the specified types.
uint32_t Size
Definition: Profile.cpp:46
bool isCompatible(const TypePairAndMemDesc &Other) const
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
std::function< bool(const LegalityQuery &)> LegalityPredicate
LegalityPredicate sizeNotPow2(unsigned TypeIdx)
True iff the specified type index is a scalar whose size is not a power of.
LegalityPredicate sameSize(unsigned TypeIdx0, unsigned TypeIdx1)
True iff the specified type indices are both the same bit size.
LegalityPredicate widerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that&#39;s wider than the given size.