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 18 LegalityPredicate 19 LegalityPredicates::all(LegalityPredicate P0, LegalityPredicate P1) { 20 return [=](const LegalityQuery &Query) { 21 return P0(Query) && P1(Query); 22 }; 23 } 24 25 LegalityPredicate 26 LegalityPredicates::typeInSet(unsigned TypeIdx, 27 std::initializer_list<LLT> TypesInit) { 28 SmallVector<LLT, 4> Types = TypesInit; 29 return [=](const LegalityQuery &Query) { 30 return std::find(Types.begin(), Types.end(), Query.Types[TypeIdx]) != Types.end(); 31 }; 32 } 33 34 LegalityPredicate LegalityPredicates::typePairInSet( 35 unsigned TypeIdx0, unsigned TypeIdx1, 36 std::initializer_list<std::pair<LLT, LLT>> TypesInit) { 37 SmallVector<std::pair<LLT, LLT>, 4> Types = TypesInit; 38 return [=](const LegalityQuery &Query) { 39 std::pair<LLT, LLT> Match = {Query.Types[TypeIdx0], Query.Types[TypeIdx1]}; 40 return std::find(Types.begin(), Types.end(), Match) != Types.end(); 41 }; 42 } 43 44 LegalityPredicate LegalityPredicates::isScalar(unsigned TypeIdx) { 45 return [=](const LegalityQuery &Query) { 46 return Query.Types[TypeIdx].isScalar(); 47 }; 48 } 49 50 LegalityPredicate LegalityPredicates::narrowerThan(unsigned TypeIdx, 51 unsigned Size) { 52 return [=](const LegalityQuery &Query) { 53 const LLT &QueryTy = Query.Types[TypeIdx]; 54 return QueryTy.isScalar() && QueryTy.getSizeInBits() < Size; 55 }; 56 } 57 58 LegalityPredicate LegalityPredicates::widerThan(unsigned TypeIdx, 59 unsigned Size) { 60 return [=](const LegalityQuery &Query) { 61 const LLT &QueryTy = Query.Types[TypeIdx]; 62 return QueryTy.isScalar() && QueryTy.getSizeInBits() > Size; 63 }; 64 } 65 66 LegalityPredicate LegalityPredicates::sizeNotPow2(unsigned TypeIdx) { 67 return [=](const LegalityQuery &Query) { 68 const LLT &QueryTy = Query.Types[TypeIdx]; 69 return QueryTy.isScalar() && !isPowerOf2_32(QueryTy.getSizeInBits()); 70 }; 71 } 72 73 LegalityPredicate LegalityPredicates::numElementsNotPow2(unsigned TypeIdx) { 74 return [=](const LegalityQuery &Query) { 75 const LLT &QueryTy = Query.Types[TypeIdx]; 76 return QueryTy.isVector() && isPowerOf2_32(QueryTy.getNumElements()); 77 }; 78 } 79