1 //===- lib/CodeGen/GlobalISel/LegalizerMutations.cpp - Mutations ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // A library of mutation factories to use for LegalityMutation.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
18 LegalizeMutation LegalizeMutations::changeTo(unsigned TypeIdx, LLT Ty) {
20 [=](const LegalityQuery &Query) { return std::make_pair(TypeIdx, Ty); };
23 LegalizeMutation LegalizeMutations::changeTo(unsigned TypeIdx,
24 unsigned FromTypeIdx) {
25 return [=](const LegalityQuery &Query) {
26 return std::make_pair(TypeIdx, Query.Types[FromTypeIdx]);
30 LegalizeMutation LegalizeMutations::widenScalarToNextPow2(unsigned TypeIdx,
32 return [=](const LegalityQuery &Query) {
33 unsigned NewSizeInBits =
34 1 << Log2_32_Ceil(Query.Types[TypeIdx].getSizeInBits());
35 if (NewSizeInBits < Min)
37 return std::make_pair(TypeIdx, LLT::scalar(NewSizeInBits));
41 LegalizeMutation LegalizeMutations::moreElementsToNextPow2(unsigned TypeIdx,
43 return [=](const LegalityQuery &Query) {
44 const LLT &VecTy = Query.Types[TypeIdx];
45 unsigned NewNumElements = 1 << Log2_32_Ceil(VecTy.getNumElements());
46 if (NewNumElements < Min)
48 return std::make_pair(
49 TypeIdx, LLT::vector(NewNumElements, VecTy.getScalarSizeInBits()));