LLVM 24.0.0git
SLPCostAnalysis.h
Go to the documentation of this file.
1//===- SLPCostAnalysis.h - SLP Vectorizer free cost 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 cost helpers
10// that do not depend on BoUpSLP or any other SLP-private type. The bulk of
11// the SLP cost model still lives in SLPVectorizer.cpp because it references
12// BoUpSLP internals.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOSTANALYSIS_H
17#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOSTANALYSIS_H
18
19#include "llvm/ADT/ArrayRef.h"
22
23#include <tuple>
24#include <utility>
25
26namespace llvm {
27class APInt;
28class FixedVectorType;
29class Type;
30class User;
31class Value;
32class VectorType;
33} // namespace llvm
34
35namespace llvm::slpvectorizer {
36
37/// Returns the cost of the shuffle instructions with the given \p Kind, vector
38/// type \p Tp and optional \p Mask. Adds SLP-specific cost estimation for
39/// insert subvector pattern.
41getShuffleCost(const TargetTransformInfo &TTI,
42 TargetTransformInfo::ShuffleKind Kind, VectorType *Tp,
44 ArrayRef<int> Mask = {}, int Index = 0,
45 VectorType *SubTp = nullptr, ArrayRef<const Value *> Args = {});
46
47/// Calculate the scalar and the vector costs from vectorizing set of GEPs.
48std::pair<InstructionCost, InstructionCost>
49getGEPCosts(const TargetTransformInfo &TTI, ArrayRef<Value *> Ptrs,
50 Value *BasePtr, unsigned Opcode,
52 VectorType *VecTy);
53
54/// Returns the cost of a BlendedLoadVectorize node loading \p VecTy: two masked
55/// loads (one per candidate base), a xor to negate the false-lane mask and a
56/// select. The blend mask is a separate operand node, so its cost is counted
57/// there, not here.
59getBlendedLoadCost(const TargetTransformInfo &TTI, Type *VecTy, Align Alignment,
60 unsigned AddressSpace,
62
63/// For a non-power-of-2 \p NumElts-wide integer div/rem \p Opcode, checks if
64/// padding to a full register and using the masked div/rem intrinsic is
65/// cheaper than the direct vector op. Returns the cost of the masked
66/// alternative, or an invalid cost if it is not applicable or not cheaper.
68getMaskedDivRemCost(const TargetTransformInfo &TTI, bool ReVec, unsigned Opcode,
69 Type *ScalarTy, unsigned NumElts,
71 FixedVectorType **PaddedTy = nullptr);
72
73/// This is similar to TargetTransformInfo::getScalarizationOverhead, but if
74/// ScalarTy is a FixedVectorType, a vector will be inserted or extracted
75/// instead of a scalar.
77getScalarizationOverhead(const TargetTransformInfo &TTI, bool ReVec,
78 Type *ScalarTy, VectorType *Ty,
79 const APInt &DemandedElts, bool Insert, bool Extract,
81 bool ForPoisonSrc = true, ArrayRef<Value *> VL = {},
83 TargetTransformInfo::VectorInstrContext::None);
84
85/// This is similar to TargetTransformInfo::getVectorInstrCost, but if ScalarTy
86/// is a FixedVectorType, a vector will be extracted instead of a scalar.
88getVectorInstrCost(const TargetTransformInfo &TTI, bool ReVec, Type *ScalarTy,
89 unsigned Opcode, Type *Val,
91 unsigned Index, Value *Scalar,
92 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx);
93
94/// This is similar to TargetTransformInfo::getExtractWithExtendCost, but if Dst
95/// is a FixedVectorType, a vector will be extracted instead of a scalar.
97getExtractWithExtendCost(const TargetTransformInfo &TTI, bool ReVec,
98 unsigned Opcode, Type *Dst, VectorType *VecTy,
99 unsigned Index,
101
102} // namespace llvm::slpvectorizer
103
104#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOSTANALYSIS_H
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 file defines an InstructionCost class that is used when calculating the cost of an instruction,...
This pass exposes codegen information to IR-level passes.
Class for arbitrary precision integers.
Definition APInt.h:78
Class to represent fixed width SIMD vectors.
TargetCostKind
The kind of cost model.
llvm::VectorInstrContext VectorInstrContext
ShuffleKind
The various kinds of shuffle patterns for vector queries.
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 Args[]
Key for Kernel::Metadata::mArgs.
A private "module" namespace for types and utilities used by this pass.
std::pair< InstructionCost, InstructionCost > getGEPCosts(const TargetTransformInfo &TTI, ArrayRef< Value * > Ptrs, Value *BasePtr, unsigned Opcode, const TTI::TargetCostKind CostKind, Type *ScalarTy, VectorType *VecTy)
Calculate the scalar and the vector costs from vectorizing set of GEPs.
InstructionCost getShuffleCost(const TargetTransformInfo &TTI, TTI::ShuffleKind Kind, VectorType *Tp, const TTI::TargetCostKind CostKind, ArrayRef< int > Mask, int Index, VectorType *SubTp, ArrayRef< const Value * > Args)
Returns the cost of the shuffle instructions with the given Kind, vector type Tp and optional Mask.
InstructionCost getBlendedLoadCost(const TargetTransformInfo &TTI, Type *VecTy, Align Alignment, unsigned AddressSpace, const TTI::TargetCostKind CostKind)
Returns the cost of a BlendedLoadVectorize node loading VecTy: two masked loads (one per candidate ba...
InstructionCost getVectorInstrCost(const TargetTransformInfo &TTI, bool ReVec, Type *ScalarTy, unsigned Opcode, Type *Val, const TTI::TargetCostKind CostKind, unsigned Index, Value *Scalar, ArrayRef< std::tuple< Value *, User *, int > > ScalarUserAndIdx)
This is similar to TargetTransformInfo::getVectorInstrCost, but if ScalarTy is a FixedVectorType,...
InstructionCost getScalarizationOverhead(const TargetTransformInfo &TTI, bool ReVec, Type *ScalarTy, VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, const TTI::TargetCostKind CostKind, bool ForPoisonSrc, ArrayRef< Value * > VL, TTI::VectorInstrContext VIC)
This is similar to TargetTransformInfo::getScalarizationOverhead, but if ScalarTy is a FixedVectorTyp...
InstructionCost getExtractWithExtendCost(const TargetTransformInfo &TTI, bool ReVec, unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index, const TTI::TargetCostKind CostKind)
This is similar to TargetTransformInfo::getExtractWithExtendCost, but if Dst is a FixedVectorType,...
InstructionCost getMaskedDivRemCost(const TargetTransformInfo &TTI, bool ReVec, unsigned Opcode, Type *ScalarTy, unsigned NumElts, const TTI::TargetCostKind CostKind, FixedVectorType **PaddedTy)
For a non-power-of-2 NumElts-wide integer div/rem Opcode, checks if padding to a full register and us...
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 >