LLVM  14.0.0git
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 FromTypeIdx) {
48  return [=](const LegalityQuery &Query) {
49  const LLT OldTy = Query.Types[TypeIdx];
50  const LLT NewTy = Query.Types[FromTypeIdx];
51  const LLT NewEltTy = LLT::scalar(NewTy.getScalarSizeInBits());
52  return std::make_pair(TypeIdx, OldTy.changeElementType(NewEltTy));
53  };
54 }
55 
57  unsigned Min) {
58  return [=](const LegalityQuery &Query) {
59  const LLT Ty = Query.Types[TypeIdx];
60  unsigned NewEltSizeInBits =
61  std::max(1u << Log2_32_Ceil(Ty.getScalarSizeInBits()), Min);
62  return std::make_pair(TypeIdx, Ty.changeElementSize(NewEltSizeInBits));
63  };
64 }
65 
68  unsigned Size) {
69  return [=](const LegalityQuery &Query) {
70  const LLT Ty = Query.Types[TypeIdx];
71  unsigned NewEltSizeInBits = alignTo(Ty.getScalarSizeInBits(), Size);
72  return std::make_pair(TypeIdx, Ty.changeElementSize(NewEltSizeInBits));
73  };
74 }
75 
77  unsigned Min) {
78  return [=](const LegalityQuery &Query) {
79  const LLT VecTy = Query.Types[TypeIdx];
80  unsigned NewNumElements =
81  std::max(1u << Log2_32_Ceil(VecTy.getNumElements()), Min);
82  return std::make_pair(
83  TypeIdx, LLT::fixed_vector(NewNumElements, VecTy.getElementType()));
84  };
85 }
86 
88  return [=](const LegalityQuery &Query) {
89  return std::make_pair(TypeIdx, Query.Types[TypeIdx].getElementType());
90  };
91 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:148
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::LLT::getScalarSizeInBits
unsigned getScalarSizeInBits() const
Definition: LowLevelTypeImpl.h:213
llvm::LegalizeMutations::widenScalarOrEltToNextMultipleOf
LegalizeMutation widenScalarOrEltToNextMultipleOf(unsigned TypeIdx, unsigned Size)
Widen the scalar type or vector element type for the given type index to next multiple of Size.
Definition: LegalizeMutations.cpp:67
llvm::LegalizeMutations::changeTo
LegalizeMutation changeTo(unsigned TypeIdx, LLT Ty)
Select this specific type for the given type index.
Definition: LegalizeMutations.cpp:17
LegalizerInfo.h
llvm::LLT::fixed_vector
static LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
Definition: LowLevelTypeImpl.h:75
llvm::Log2_32_Ceil
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:609
llvm::LegalizeMutations::scalarize
LegalizeMutation scalarize(unsigned TypeIdx)
Break up the vector type for the given type index into the element type.
Definition: LegalizeMutations.cpp:87
llvm::LegalizeMutations::changeElementSizeTo
LegalizeMutation changeElementSizeTo(unsigned TypeIdx, unsigned FromTypeIdx)
Change the scalar size or element size to have the same scalar size as type index FromIndex.
Definition: LegalizeMutations.cpp:46
llvm::LLT::getNumElements
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
Definition: LowLevelTypeImpl.h:127
llvm::LegalityQuery
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
Definition: LegalizerInfo.h:108
llvm::LegalizeMutations::changeElementTo
LegalizeMutation changeElementTo(unsigned TypeIdx, unsigned FromTypeIdx)
Keep the same scalar or element type as the given type index.
Definition: LegalizeMutations.cpp:29
llvm::LegalizeMutations::widenScalarOrEltToNextPow2
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.
Definition: LegalizeMutations.cpp:56
llvm::LLT::changeElementType
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.
Definition: LowLevelTypeImpl.h:174
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::LegalizeMutation
std::function< std::pair< unsigned, LLT >(const LegalityQuery &)> LegalizeMutation
Definition: LegalizerInfo.h:201
llvm::LegalizeMutations::moreElementsToNextPow2
LegalizeMutation moreElementsToNextPow2(unsigned TypeIdx, unsigned Min=0)
Add more elements to the type for the given type index to the next power of.
Definition: LegalizeMutations.cpp:76
llvm::LLT::getElementType
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
Definition: LowLevelTypeImpl.h:237
llvm::LLT::scalar
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelTypeImpl.h:43
llvm::LLT::changeElementSize
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.
Definition: LowLevelTypeImpl.h:181
llvm::LLT
Definition: LowLevelTypeImpl.h:40