LLVM 24.0.0git
SLPMemoryUtils.h
Go to the documentation of this file.
1//===- SLPMemoryUtils.h - SLP pointer/stride 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 pointer and
10// stride helpers that do not depend on BoUpSLP or any other SLP-private type.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPMEMORYUTILS_H
15#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPMEMORYUTILS_H
16
17#include "llvm/ADT/ArrayRef.h"
21
22#include <cstdint>
23
24namespace llvm {
25class AssumptionCache;
26class BasicBlock;
27class ConstantInt;
28class DataLayout;
29class DominatorTree;
30class FixedVectorType;
31class IRBuilderBase;
32class SCEV;
33class ScalarEvolution;
35class Type;
36class Value;
37class VectorType;
38} // namespace llvm
39
40namespace llvm::slpvectorizer {
41
42/// \p MaxDepth is the recursion limit for getUnderlyingObject.
43bool arePointersCompatible(Value *Ptr1, Value *Ptr2,
44 const TargetLibraryInfo &TLI, unsigned MaxDepth,
45 bool CompareOpcodes = true);
46
47/// Returns \p Stride scaled by the allocation size of \p ScalarTy, negated if
48/// \p IsReverse is set, or nullptr if \p Stride is not a constant.
49ConstantInt *getStrideBytesIfConstant(Value *Stride, Type *ScalarTy,
50 const DataLayout &DL,
51 bool IsReverse = false);
52
53/// Casts \p V between the widened strided access type and the entry vector
54/// type \p DstTy.
55Value *createWidenedStridedCast(IRBuilderBase &Builder, Value *V, Type *DstTy,
56 const DataLayout &DL);
57
58/// Calculates minimal alignment as a common alignment.
59template <typename T> Align computeCommonAlignment(ArrayRef<Value *> VL);
60
61/// Checks if the provided list of pointers \p Pointers represents the strided
62/// pointers for type ElemTy. If they are not, nullptr is returned.
63/// Otherwise, SCEV* of the stride value is returned.
64/// If `PointerOps` can be rearranged into the following sequence:
65/// ```
66/// %x + c_0 * stride,
67/// %x + c_1 * stride,
68/// %x + c_2 * stride
69/// ...
70/// ```
71/// where each `c_i` is constant. The SCEV of the `stride` will be returned.
72const SCEV *calculateRtStride(ArrayRef<Value *> PointerOps, Type *ElemTy,
73 const DataLayout &DL, ScalarEvolution &SE,
74 SmallVectorImpl<unsigned> &SortedIndices);
75
76/// Checks if the \p VL can be transformed to a (masked)load + compress or
77/// (masked) interleaved load.
80 ArrayRef<unsigned> Order, const TargetTransformInfo &TTI,
81 const DataLayout &DL, ScalarEvolution &SE, AssumptionCache &AC,
82 const DominatorTree &DT, const TargetLibraryInfo &TLI,
84 const function_ref<bool(Value *)> AreAllUsersVectorized, bool ReVec,
85 bool &IsMasked, unsigned &InterleaveFactor,
86 SmallVectorImpl<int> &CompressMask, VectorType *&LoadVecTy);
87
88/// Checks if the \p VL can be transformed to a (masked)load + compress or
89/// (masked) interleaved load.
92 ArrayRef<unsigned> Order, const TargetTransformInfo &TTI,
93 const DataLayout &DL, ScalarEvolution &SE, AssumptionCache &AC,
94 const DominatorTree &DT, const TargetLibraryInfo &TLI,
96 const function_ref<bool(Value *)> AreAllUsersVectorized, bool ReVec);
97
98/// Checks if the simple loads of \p VL, mixed with the undef and poison lanes,
99/// can be replaced by a single load of the whole \p VL width. The loads must be
100/// consecutive and match their lanes, and the whole accessed range must be safe
101/// to load unconditionally.
102bool canWidenLoadsOverUndefLanes(ArrayRef<Value *> VL, const DataLayout &DL,
103 ScalarEvolution &SE, AssumptionCache &AC,
104 const DominatorTree &DT,
105 const TargetLibraryInfo &TLI);
106
107/// Returns the distance in bytes from the start of the vector load to the
108/// first load of \p Scalars: the leading undef lanes are covered by the vector
109/// load.
111
112/// Checks if the stores \p VL with pointers \p PointerOps can be lowered as a
113/// single masked store. On success \p StoreVecTy is the widened store type and
114/// \p ReuseShuffleIndices is the expand mask that places each stored value at
115/// its element offset from the base (poison in the gaps).
117 ArrayRef<unsigned> Order,
118 const TargetTransformInfo &TTI, const DataLayout &DL,
119 ScalarEvolution &SE, Align CommonAlignment,
120 SmallVectorImpl<int> &ReuseShuffleIndices,
121 FixedVectorType *&StoreVecTy);
122
123/// Clusters \p VL pointers by (basic block, underlying object) pair and sorts
124/// each cluster by offset. Returns false and leaves \p SortedIndices empty if
125/// the accesses are not worth reordering.
127 Type *ElemTy, const DataLayout &DL,
128 ScalarEvolution &SE, unsigned MaxDepth,
129 SmallVectorImpl<unsigned> &SortedIndices);
130
131} // namespace llvm::slpvectorizer
132
133#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPMEMORYUTILS_H
unsigned uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
This pass exposes codegen information to IR-level passes.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
This is the shared class of boolean and integer constants.
Definition Constants.h:87
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
Class to represent fixed width SIMD vectors.
Common base class shared among various IRBuilders.
Definition IRBuilder.h:111
This class represents an analyzed expression in the program.
The main scalar evolution driver.
Provides information about what library functions are available for the current target.
TargetCostKind
The kind of cost model.
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
Base class of all SIMD vector types.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
A private "module" namespace for types and utilities used by this pass.
Value * createWidenedStridedCast(IRBuilderBase &Builder, Value *V, Type *DstTy, const DataLayout &DL)
Casts V between the widened strided access type and the entry vector type DstTy.
Align computeCommonAlignment(ArrayRef< Value * > VL)
Calculates minimal alignment as a common alignment.
const SCEV * calculateRtStride(ArrayRef< Value * > PointerOps, Type *ElemTy, const DataLayout &DL, ScalarEvolution &SE, SmallVectorImpl< unsigned > &SortedIndices)
Checks if the provided list of pointers Pointers represents the strided pointers for type ElemTy.
ConstantInt * getStrideBytesIfConstant(Value *Stride, Type *ScalarTy, const DataLayout &DL, bool IsReverse)
Returns Stride scaled by the allocation size of ScalarTy, negated if IsReverse is set,...
uint64_t getVectorLoadShift(ArrayRef< Value * > Scalars)
Returns the distance in bytes from the start of the vector load to the first load of Scalars: the lea...
bool isMaskedStoreCompress(ArrayRef< Value * > VL, ArrayRef< Value * > PointerOps, ArrayRef< unsigned > Order, const TargetTransformInfo &TTI, const DataLayout &DL, ScalarEvolution &SE, Align CommonAlignment, SmallVectorImpl< int > &ReuseShuffleIndices, FixedVectorType *&StoreVecTy)
Checks if the stores VL with pointers PointerOps can be lowered as a single masked store.
bool canWidenLoadsOverUndefLanes(ArrayRef< Value * > VL, const DataLayout &DL, ScalarEvolution &SE, AssumptionCache &AC, const DominatorTree &DT, const TargetLibraryInfo &TLI)
Checks if the simple loads of VL, mixed with the undef and poison lanes, can be replaced by a single ...
bool isMaskedLoadCompress(ArrayRef< Value * > VL, ArrayRef< Value * > PointerOps, ArrayRef< unsigned > Order, const TargetTransformInfo &TTI, const DataLayout &DL, ScalarEvolution &SE, AssumptionCache &AC, const DominatorTree &DT, const TargetLibraryInfo &TLI, const TargetTransformInfo::TargetCostKind CostKind, const function_ref< bool(Value *)> AreAllUsersVectorized, bool ReVec, bool &IsMasked, unsigned &InterleaveFactor, SmallVectorImpl< int > &CompressMask, VectorType *&LoadVecTy)
Checks if the VL can be transformed to a (masked)load + compress or (masked) interleaved load.
bool arePointersCompatible(Value *Ptr1, Value *Ptr2, const TargetLibraryInfo &TLI, unsigned MaxDepth, bool CompareOpcodes)
MaxDepth is the recursion limit for getUnderlyingObject.
bool clusterSortPtrAccesses(ArrayRef< Value * > VL, ArrayRef< BasicBlock * > BBs, Type *ElemTy, const DataLayout &DL, ScalarEvolution &SE, unsigned MaxDepth, SmallVectorImpl< unsigned > &SortedIndices)
Clusters VL pointers by (basic block, underlying object) pair and sorts each cluster by offset.
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
TargetTransformInfo TTI
ArrayRef(const T &OneElt) -> ArrayRef< T >