• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
14 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
15 
16 using namespace llvm;
17 
typeIs(unsigned TypeIdx,LLT Type)18 LegalityPredicate LegalityPredicates::typeIs(unsigned TypeIdx, LLT Type) {
19   return
20       [=](const LegalityQuery &Query) { return Query.Types[TypeIdx] == Type; };
21 }
22 
23 LegalityPredicate
typeInSet(unsigned TypeIdx,std::initializer_list<LLT> TypesInit)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();
29   };
30 }
31 
typePairInSet(unsigned TypeIdx0,unsigned TypeIdx1,std::initializer_list<std::pair<LLT,LLT>> TypesInit)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();
39   };
40 }
41 
typePairAndMemSizeInSet(unsigned TypeIdx0,unsigned TypeIdx1,unsigned MMOIdx,std::initializer_list<TypePairAndMemSize> TypesAndMemSizeInit)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();
51   };
52 }
53 
isScalar(unsigned TypeIdx)54 LegalityPredicate LegalityPredicates::isScalar(unsigned TypeIdx) {
55   return [=](const LegalityQuery &Query) {
56     return Query.Types[TypeIdx].isScalar();
57   };
58 }
59 
narrowerThan(unsigned TypeIdx,unsigned Size)60 LegalityPredicate LegalityPredicates::narrowerThan(unsigned TypeIdx,
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 
widerThan(unsigned TypeIdx,unsigned Size)68 LegalityPredicate LegalityPredicates::widerThan(unsigned TypeIdx,
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 
sizeNotPow2(unsigned TypeIdx)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());
80   };
81 }
82 
memSizeInBytesNotPow2(unsigned MMOIdx)83 LegalityPredicate LegalityPredicates::memSizeInBytesNotPow2(unsigned MMOIdx) {
84   return [=](const LegalityQuery &Query) {
85     return !isPowerOf2_32(Query.MMODescrs[MMOIdx].Size /* In Bytes */);
86   };
87 }
88 
numElementsNotPow2(unsigned TypeIdx)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());
93   };
94 }
95 
atomicOrderingAtLeastOrStrongerThan(unsigned MMOIdx,AtomicOrdering Ordering)96 LegalityPredicate LegalityPredicates::atomicOrderingAtLeastOrStrongerThan(
97     unsigned MMOIdx, AtomicOrdering Ordering) {
98   return [=](const LegalityQuery &Query) {
99     return isAtLeastOrStrongerThan(Query.MMODescrs[MMOIdx].Ordering, Ordering);
100   };
101 }
102