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
22namespace llvm {
23class AssumptionCache;
24class BasicBlock;
25class ConstantInt;
26class DataLayout;
27class DominatorTree;
28class FixedVectorType;
29class SCEV;
30class ScalarEvolution;
32class Type;
33class Value;
34class VectorType;
35} // namespace llvm
36
37namespace llvm::slpvectorizer {
38
39/// \p MaxDepth is the recursion limit for getUnderlyingObject.
40bool arePointersCompatible(Value *Ptr1, Value *Ptr2,
41 const TargetLibraryInfo &TLI, unsigned MaxDepth,
42 bool CompareOpcodes = true);
43
44/// Returns \p Stride scaled by the allocation size of \p ScalarTy, negated if
45/// \p IsReverse is set, or nullptr if \p Stride is not a constant.
46ConstantInt *getStrideBytesIfConstant(Value *Stride, Type *ScalarTy,
47 const DataLayout &DL,
48 bool IsReverse = false);
49
50/// Calculates minimal alignment as a common alignment.
51template <typename T> Align computeCommonAlignment(ArrayRef<Value *> VL);
52
53/// Checks if the provided list of pointers \p Pointers represents the strided
54/// pointers for type ElemTy. If they are not, nullptr is returned.
55/// Otherwise, SCEV* of the stride value is returned.
56/// If `PointerOps` can be rearranged into the following sequence:
57/// ```
58/// %x + c_0 * stride,
59/// %x + c_1 * stride,
60/// %x + c_2 * stride
61/// ...
62/// ```
63/// where each `c_i` is constant. The SCEV of the `stride` will be returned.
64const SCEV *calculateRtStride(ArrayRef<Value *> PointerOps, Type *ElemTy,
65 const DataLayout &DL, ScalarEvolution &SE,
66 SmallVectorImpl<unsigned> &SortedIndices);
67
68/// Checks if the \p VL can be transformed to a (masked)load + compress or
69/// (masked) interleaved load.
72 ArrayRef<unsigned> Order, const TargetTransformInfo &TTI,
73 const DataLayout &DL, ScalarEvolution &SE, AssumptionCache &AC,
74 const DominatorTree &DT, const TargetLibraryInfo &TLI,
76 const function_ref<bool(Value *)> AreAllUsersVectorized, bool ReVec,
77 bool &IsMasked, unsigned &InterleaveFactor,
78 SmallVectorImpl<int> &CompressMask, VectorType *&LoadVecTy);
79
80/// Checks if the \p VL can be transformed to a (masked)load + compress or
81/// (masked) interleaved load.
84 ArrayRef<unsigned> Order, const TargetTransformInfo &TTI,
85 const DataLayout &DL, ScalarEvolution &SE, AssumptionCache &AC,
86 const DominatorTree &DT, const TargetLibraryInfo &TLI,
88 const function_ref<bool(Value *)> AreAllUsersVectorized, bool ReVec);
89
90/// Checks if the stores \p VL with pointers \p PointerOps can be lowered as a
91/// single masked store. On success \p StoreVecTy is the widened store type and
92/// \p ReuseShuffleIndices is the expand mask that places each stored value at
93/// its element offset from the base (poison in the gaps).
95 ArrayRef<unsigned> Order,
96 const TargetTransformInfo &TTI, const DataLayout &DL,
97 ScalarEvolution &SE, Align CommonAlignment,
98 SmallVectorImpl<int> &ReuseShuffleIndices,
99 FixedVectorType *&StoreVecTy);
100
101/// Clusters \p VL pointers by (basic block, underlying object) pair and sorts
102/// each cluster by offset. Returns false and leaves \p SortedIndices empty if
103/// the accesses are not worth reordering.
105 Type *ElemTy, const DataLayout &DL,
106 ScalarEvolution &SE, unsigned MaxDepth,
107 SmallVectorImpl<unsigned> &SortedIndices);
108
109} // namespace llvm::slpvectorizer
110
111#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPMEMORYUTILS_H
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.
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.
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,...
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 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 >