LLVM  8.0.1
LegalityPredicates.cpp
Go to the documentation of this file.
1 //===- lib/CodeGen/GlobalISel/LegalizerPredicates.cpp - Predicates --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // A library of predicate factories to use for LegalityPredicate.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 
16 using namespace llvm;
17 
19  return
20  [=](const LegalityQuery &Query) { return Query.Types[TypeIdx] == Type; };
21 }
22 
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();
29  };
30 }
31 
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();
39  };
40 }
41 
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].SizeInBits};
49  return std::find(TypesAndMemSize.begin(), TypesAndMemSize.end(), Match) !=
50  TypesAndMemSize.end();
51  };
52 }
53 
55  return [=](const LegalityQuery &Query) {
56  return Query.Types[TypeIdx].isScalar();
57  };
58 }
59 
61  unsigned Size) {
62  return [=](const LegalityQuery &Query) {
63  const LLT &QueryTy = Query.Types[TypeIdx];
64  return QueryTy.isScalar() && QueryTy.getSizeInBits() < Size;
65  };
66 }
67 
69  unsigned Size) {
70  return [=](const LegalityQuery &Query) {
71  const LLT &QueryTy = Query.Types[TypeIdx];
72  return QueryTy.isScalar() && QueryTy.getSizeInBits() > Size;
73  };
74 }
75 
77  return [=](const LegalityQuery &Query) {
78  const LLT &QueryTy = Query.Types[TypeIdx];
79  return QueryTy.isScalar() && !isPowerOf2_32(QueryTy.getSizeInBits());
80  };
81 }
82 
84  return [=](const LegalityQuery &Query) {
85  return !isPowerOf2_32(Query.MMODescrs[MMOIdx].SizeInBits / 8);
86  };
87 }
88 
90  return [=](const LegalityQuery &Query) {
91  const LLT &QueryTy = Query.Types[TypeIdx];
92  return QueryTy.isVector() && isPowerOf2_32(QueryTy.getNumElements());
93  };
94 }
95 
97  unsigned MMOIdx, AtomicOrdering Ordering) {
98  return [=](const LegalityQuery &Query) {
99  return isAtLeastOrStrongerThan(Query.MMODescrs[MMOIdx].Ordering, Ordering);
100  };
101 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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 typeIs(unsigned TypeIdx, LLT TypesInit)
True iff the given type index is the specified types.
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 typePairAndMemSizeInSet(unsigned TypeIdx0, unsigned TypeIdx1, unsigned MMOIdx, std::initializer_list< TypePairAndMemSize > TypesAndMemSizeInit)
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:429
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
LegalityPredicate narrowerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that&#39;s narrower than the given size.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:129
LegalityPredicate memSizeInBytesNotPow2(unsigned MMOIdx)
True iff the specified MMO index has a size that is not a power of 2.
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:1207
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:133
LegalityPredicate typeInSet(unsigned TypeIdx, std::initializer_list< LLT > TypesInit)
True iff the given type index is one of the specified types.
static void Query(const MachineInstr &MI, AliasAnalysis &AA, bool &Read, bool &Write, bool &Effects, bool &StackPointer)
uint32_t Size
Definition: Profile.cpp:47
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 widerThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a scalar that&#39;s wider than the given size.