LLVM 24.0.0git
SLPTypeUtils.h
Go to the documentation of this file.
1//===- SLPTypeUtils.h - SLP Vectorizer type/width helpers ------*- C++ -*-===//
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// Internal header used by SLPVectorizer.cpp. It declares free type and vector
10// width helpers that do not depend on BoUpSLP or any other SLP-private type.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPTYPEUTILS_H
15#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPTYPEUTILS_H
16
17#include <limits>
18
19namespace llvm {
20class DataLayout;
21class FixedVectorType;
23class Type;
24class Value;
25} // namespace llvm
26
27namespace llvm::slpvectorizer {
28
29/// Predicate for the element types that the SLP vectorizer supports.
30///
31/// The most important thing to filter here are types which are invalid in LLVM
32/// vectors. We also filter target specific types which have absolutely no
33/// meaningful vectorization path such as x86_fp80 and ppc_f128. This just
34/// avoids spending time checking the cost model and realizing that they will
35/// be inevitably scalarized.
36bool isValidElementType(Type *Ty, bool ReVec);
37
38/// Returns the "element type" of the given value/instruction \p V.
39/// For stores, returns the stored value type; for insertelement (when \p ReVec
40/// is off), the inserted operand type. For compares, the default is to return
41/// the result type (i1); when \p LookThroughCmp is true, returns the type of
42/// the compared operands instead, which is needed for vector width
43/// calculations (the width is determined by the operand type, not the i1
44/// result).
45Type *getValueType(Value *V, bool ReVec, bool LookThroughCmp = false);
46
47/// \returns the vector type of ScalarTy based on vectorization factor.
48Type *getWidenedType(Type *ScalarTy, unsigned VF);
49
50/// Returns the number of elements of the given type \p Ty, not less than \p Sz,
51/// which forms type, which splits by \p TTI into whole vector types during
52/// legalization.
53unsigned getFullVectorNumberOfElements(const TargetTransformInfo &TTI, Type *Ty,
54 unsigned Sz, bool ReVec);
55
56/// Returns the number of elements of the given type \p Ty, not greater than \p
57/// Sz, which forms type, which splits by \p TTI into whole vector types during
58/// legalization.
59unsigned getFloorFullVectorNumberOfElements(const TargetTransformInfo &TTI,
60 Type *Ty, unsigned Sz, bool ReVec);
61
62/// For a non-power-of-2 \p NumElts-wide integer div/rem \p Opcode, returns the
63/// padded full-register vector type if padding is structurally possible, or
64/// nullptr if the vector already fills a register or the opcode is not
65/// div/rem. Does not check profitability.
66FixedVectorType *getMaskedDivRemType(const TargetTransformInfo &TTI,
67 unsigned Opcode, Type *ScalarTy,
68 unsigned NumElts, bool ReVec);
69
70/// Returns true if widened type of \p Ty elements with size \p Sz represents
71/// full vector type, i.e. adding extra element results in extra parts upon type
72/// legalization.
73bool hasFullVectorsOrPowerOf2(const TargetTransformInfo &TTI, Type *Ty,
74 unsigned Sz, bool ReVec);
75
76/// True when \p AllowNonPowerOf2 is set and \p NumElts is a supported
77/// non-power-of-2 width: \p NumElts + 1 must be a power of two (e.g. 3 or 7
78/// lanes, i.e. almost a full power-of-2 register).
79bool isAllowedNonPowerOf2VF(unsigned NumElts, bool AllowNonPowerOf2);
80
81/// Returns number of parts, the type \p VecTy will be split at the codegen
82/// phase. If the type is going to be scalarized or does not use whole
83/// registers, returns 1.
84unsigned
85getNumberOfPartsOrRegs(bool QueryNumParts, const TargetTransformInfo &TTI,
86 Type *VecTy, Type *ScalarTy, bool ReVec,
87 unsigned Limit = std::numeric_limits<unsigned>::max());
88
89/// Returns true if the type limit of the smax (\p IsMax) or smin lane \p V
90/// stays neutral after narrowing.
91bool isTypeLimitNeutral(const Value *V, bool IsMax, const DataLayout &DL);
92
93} // namespace llvm::slpvectorizer
94
95#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPTYPEUTILS_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Class to represent fixed width SIMD vectors.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
A private "module" namespace for types and utilities used by this pass.
unsigned getNumberOfPartsOrRegs(bool QueryNumParts, const TargetTransformInfo &TTI, Type *VecTy, Type *ScalarTy, bool ReVec, unsigned Limit)
Returns number of parts, the type VecTy will be split at the codegen phase.
unsigned getFloorFullVectorNumberOfElements(const TargetTransformInfo &TTI, Type *Ty, unsigned Sz, bool ReVec)
Returns the number of elements of the given type Ty, not greater than Sz, which forms type,...
Type * getWidenedType(Type *ScalarTy, unsigned VF)
bool hasFullVectorsOrPowerOf2(const TargetTransformInfo &TTI, Type *Ty, unsigned Sz, bool ReVec)
Returns true if widened type of Ty elements with size Sz represents full vector type,...
bool isAllowedNonPowerOf2VF(unsigned NumElts, bool AllowNonPowerOf2)
True when AllowNonPowerOf2 is set and NumElts is a supported non-power-of-2 width: NumElts + 1 must b...
FixedVectorType * getMaskedDivRemType(const TargetTransformInfo &TTI, unsigned Opcode, Type *ScalarTy, unsigned NumElts, bool ReVec)
For a non-power-of-2 NumElts-wide integer div/rem Opcode, returns the padded full-register vector typ...
bool isValidElementType(Type *Ty, bool ReVec)
Predicate for the element types that the SLP vectorizer supports.
Type * getValueType(Value *V, bool ReVec, bool LookThroughCmp)
Returns the "element type" of the given value/instruction V.
bool isTypeLimitNeutral(const Value *V, bool IsMax, const DataLayout &DL)
Returns true if the type limit of the smax (IsMax) or smin lane V stays neutral after narrowing.
unsigned getFullVectorNumberOfElements(const TargetTransformInfo &TTI, Type *Ty, unsigned Sz, bool ReVec)
Returns the number of elements of the given type Ty, not less than Sz, which forms type,...
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
TargetTransformInfo TTI