[llvm-exegesis] Fix missing std::move.
[llvm-complete.git] / lib / CodeGen / GlobalISel / LegalityPredicates.cpp
blob344f573a67f5e25c20eb75ea9e2c4f02fa08415c
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.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
16 using namespace llvm;
18 LegalityPredicate LegalityPredicates::typeIs(unsigned TypeIdx, LLT Type) {
19 return
20 [=](const LegalityQuery &Query) { return Query.Types[TypeIdx] == Type; };
23 LegalityPredicate
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();
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();
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();
54 LegalityPredicate LegalityPredicates::isScalar(unsigned TypeIdx) {
55 return [=](const LegalityQuery &Query) {
56 return Query.Types[TypeIdx].isScalar();
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;
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;
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());
83 LegalityPredicate LegalityPredicates::memSizeInBytesNotPow2(unsigned MMOIdx) {
84 return [=](const LegalityQuery &Query) {
85 return !isPowerOf2_32(Query.MMODescrs[MMOIdx].Size /* In Bytes */);
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());
96 LegalityPredicate LegalityPredicates::atomicOrderingAtLeastOrStrongerThan(
97 unsigned MMOIdx, AtomicOrdering Ordering) {
98 return [=](const LegalityQuery &Query) {
99 return isAtLeastOrStrongerThan(Query.MMODescrs[MMOIdx].Ordering, Ordering);