blob: 961988515e5374bb02675256dbffa4ad478b7757 [file] [log] [blame]
Daniel Sanders79cb8392018-01-29 19:54:49 +00001//===- lib/CodeGen/GlobalISel/LegalizerMutations.cpp - Mutations ----------===//
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 mutation factories to use for LegalityMutation.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
15
16using namespace llvm;
17
18LegalizeMutation LegalizeMutations::identity(unsigned TypeIdx, LLT Ty) {
19 return
20 [=](const LegalityQuery &Query) { return std::make_pair(TypeIdx, Ty); };
21}
22
23LegalizeMutation LegalizeMutations::widenScalarToNextPow2(unsigned TypeIdx,
24 unsigned Min) {
25 return [=](const LegalityQuery &Query) {
26 unsigned NewSizeInBits =
27 1 << Log2_32_Ceil(Query.Types[TypeIdx].getSizeInBits());
28 if (NewSizeInBits < Min)
29 NewSizeInBits = Min;
30 return std::make_pair(TypeIdx, LLT::scalar(NewSizeInBits));
31 };
32}
33
34LegalizeMutation LegalizeMutations::moreElementsToNextPow2(unsigned TypeIdx,
35 unsigned Min) {
36 return [=](const LegalityQuery &Query) {
37 const LLT &VecTy = Query.Types[TypeIdx];
38 unsigned NewNumElements = 1 << Log2_32_Ceil(VecTy.getNumElements());
39 if (NewNumElements < Min)
40 NewNumElements = Min;
41 return std::make_pair(
42 TypeIdx, LLT::vector(NewNumElements, VecTy.getScalarSizeInBits()));
43 };
44}