LLVM  10.0.0svn
LegalizeMutations.cpp
Go to the documentation of this file.
1 //===- lib/CodeGen/GlobalISel/LegalizerMutations.cpp - Mutations ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // A library of mutation factories to use for LegalityMutation.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
15 using namespace llvm;
16 
18  return
19  [=](const LegalityQuery &Query) { return std::make_pair(TypeIdx, Ty); };
20 }
21 
23  unsigned FromTypeIdx) {
24  return [=](const LegalityQuery &Query) {
25  return std::make_pair(TypeIdx, Query.Types[FromTypeIdx]);
26  };
27 }
28 
30  unsigned FromTypeIdx) {
31  return [=](const LegalityQuery &Query) {
32  const LLT OldTy = Query.Types[TypeIdx];
33  const LLT NewTy = Query.Types[FromTypeIdx];
34  return std::make_pair(TypeIdx, OldTy.changeElementType(NewTy));
35  };
36 }
37 
39  LLT NewEltTy) {
40  return [=](const LegalityQuery &Query) {
41  const LLT OldTy = Query.Types[TypeIdx];
42  return std::make_pair(TypeIdx, OldTy.changeElementType(NewEltTy));
43  };
44 }
45 
47  unsigned Min) {
48  return [=](const LegalityQuery &Query) {
49  const LLT Ty = Query.Types[TypeIdx];
50  unsigned NewEltSizeInBits =
51  std::max(1u << Log2_32_Ceil(Ty.getScalarSizeInBits()), Min);
52  return std::make_pair(TypeIdx, Ty.changeElementSize(NewEltSizeInBits));
53  };
54 }
55 
57  unsigned Min) {
58  return [=](const LegalityQuery &Query) {
59  const LLT VecTy = Query.Types[TypeIdx];
60  unsigned NewNumElements =
61  std::max(1u << Log2_32_Ceil(VecTy.getNumElements()), Min);
62  return std::make_pair(TypeIdx,
63  LLT::vector(NewNumElements, VecTy.getElementType()));
64  };
65 }
66 
68  return [=](const LegalityQuery &Query) {
69  return std::make_pair(TypeIdx, Query.Types[TypeIdx].getElementType());
70  };
71 }
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition: MathExtras.h:551
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
unsigned getScalarSizeInBits() const
The LegalityQuery object bundles together all the information that&#39;s needed to decide whether a given...
LLT changeElementType(LLT NewEltTy) const
If this type is a vector, return a vector with the same number of elements but the new element type...
LegalizeMutation changeTo(unsigned TypeIdx, LLT Ty)
Select this specific type for the given type index.
LLT getElementType() const
Returns the vector&#39;s element type. Only valid for vector types.
LegalizeMutation scalarize(unsigned TypeIdx)
Break up the vector type for the given type index into the element type.
std::function< std::pair< unsigned, LLT >(const LegalityQuery &)> LegalizeMutation
LegalizeMutation changeElementTo(unsigned TypeIdx, unsigned FromTypeIdx)
Keep the same scalar or element type as the given type index.
LegalizeMutation widenScalarOrEltToNextPow2(unsigned TypeIdx, unsigned Min=0)
Widen the scalar type or vector element type for the given type index to the next power of 2...
LegalizeMutation moreElementsToNextPow2(unsigned TypeIdx, unsigned Min=0)
Add more elements to the type for the given type index to the next power of.
LLT changeElementSize(unsigned NewEltSize) const
If this type is a vector, return a vector with the same number of elements but the new element size...
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
static LLT vector(uint16_t NumElements, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.