1//===-- SystemZTargetTransformInfo.h - SystemZ-specific TTI ---------------===//
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#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETTRANSFORMINFO_H
10#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETTRANSFORMINFO_H
11
12#include "SystemZTargetMachine.h"
13#include "llvm/Analysis/TargetTransformInfo.h"
14#include "llvm/CodeGen/BasicTTIImpl.h"
15
16namespace llvm {
17
18class SystemZTTIImpl final : public BasicTTIImplBase<SystemZTTIImpl> {
19 typedef BasicTTIImplBase<SystemZTTIImpl> BaseT;
20 typedef TargetTransformInfo TTI;
21 friend BaseT;
22
23 const SystemZSubtarget *ST;
24 const SystemZTargetLowering *TLI;
25
26 const SystemZSubtarget *getST() const { return ST; }
27 const SystemZTargetLowering *getTLI() const { return TLI; }
28
29 unsigned const LIBCALL_COST = 30;
30
31 bool isInt128InVR(Type *Ty) const {
32 return Ty->isIntegerTy(BitWidth: 128) && ST->hasVector();
33 }
34
35public:
36 explicit SystemZTTIImpl(const SystemZTargetMachine *TM, const Function &F)
37 : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
38 TLI(ST->getTargetLowering()) {}
39
40 /// \name Scalar TTI Implementations
41 /// @{
42
43 unsigned adjustInliningThreshold(const CallBase *CB) const override;
44
45 InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
46 TTI::TargetCostKind CostKind) const override;
47
48 InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx,
49 const APInt &Imm, Type *Ty,
50 TTI::TargetCostKind CostKind,
51 Instruction *Inst = nullptr) const override;
52 InstructionCost
53 getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
54 Type *Ty, TTI::TargetCostKind CostKind) const override;
55
56 TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override;
57
58 void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
59 TTI::UnrollingPreferences &UP,
60 OptimizationRemarkEmitter *ORE) const override;
61
62 void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
63 TTI::PeelingPreferences &PP) const override;
64
65 bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
66 const TargetTransformInfo::LSRCost &C2) const override;
67
68 /// @}
69
70 /// \name Vector TTI Implementations
71 /// @{
72
73 unsigned getNumberOfRegisters(unsigned ClassID) const override;
74 TypeSize
75 getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override;
76
77 unsigned getCacheLineSize() const override { return 256; }
78 unsigned getPrefetchDistance() const override { return 4500; }
79 unsigned getMinPrefetchStride(unsigned NumMemAccesses,
80 unsigned NumStridedMemAccesses,
81 unsigned NumPrefetches,
82 bool HasCall) const override;
83 bool enableWritePrefetching() const override { return true; }
84
85 unsigned getMaxInterleaveFactor(ElementCount VF,
86 bool HasUnorderedReductions) const override;
87
88 bool hasDivRemOp(Type *DataType, bool IsSigned) const override;
89 bool prefersVectorizedAddressing() const override { return false; }
90 bool LSRWithInstrQueries() const override { return true; }
91 InstructionCost
92 getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts,
93 bool Insert, bool Extract,
94 TTI::TargetCostKind CostKind,
95 bool ForPoisonSrc = true, ArrayRef<Value *> VL = {},
96 TTI::VectorInstrContext VIC =
97 TTI::VectorInstrContext::None) const override;
98 bool supportsEfficientVectorElementLoadStore() const override { return true; }
99 bool enableInterleavedAccessVectorization() const override { return true; }
100
101 InstructionCost getArithmeticInstrCost(
102 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
103 TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
104 TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
105 ArrayRef<const Value *> Args = {},
106 const Instruction *CxtI = nullptr) const override;
107
108 InstructionCost getPartialReductionCost(
109 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
110 ElementCount VF, TTI::PartialReductionExtendKind OpAExtend,
111 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
112 TTI::TargetCostKind CostKind,
113 std::optional<FastMathFlags> FMF) const override {
114 return InstructionCost::getInvalid();
115 }
116
117 InstructionCost
118 getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
119 ArrayRef<int> Mask, TTI::TargetCostKind CostKind, int Index,
120 VectorType *SubTp, ArrayRef<const Value *> Args = {},
121 const Instruction *CxtI = nullptr) const override;
122 unsigned getVectorTruncCost(Type *SrcTy, Type *DstTy) const;
123 unsigned getVectorBitmaskConversionCost(Type *SrcTy, Type *DstTy) const;
124 unsigned getBoolVecToIntConversionCost(unsigned Opcode, Type *Dst,
125 const Instruction *I) const;
126 InstructionCost
127 getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
128 TTI::CastContextHint CCH, TTI::TargetCostKind CostKind,
129 const Instruction *I = nullptr) const override;
130 InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
131 const Instruction *I = nullptr) const override;
132 InstructionCost getCmpSelInstrCost(
133 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
134 TTI::TargetCostKind CostKind,
135 TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
136 TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
137 const Instruction *I = nullptr) const override;
138 using BaseT::getVectorInstrCost;
139 InstructionCost
140 getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind,
141 unsigned Index, const Value *Op0, const Value *Op1,
142 TTI::VectorInstrContext VIC =
143 TTI::VectorInstrContext::None) const override;
144 bool isFoldableLoad(const LoadInst *Ld,
145 const Instruction *&FoldedValue) const;
146 InstructionCost getMemoryOpCost(
147 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
148 TTI::TargetCostKind CostKind,
149 TTI::OperandValueInfo OpInfo = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
150 const Instruction *I = nullptr) const override;
151
152 InstructionCost getInterleavedMemoryOpCost(
153 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
154 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
155 bool UseMaskForCond = false, bool UseMaskForGaps = false) const override;
156
157 InstructionCost
158 getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
159 std::optional<FastMathFlags> FMF,
160 TTI::TargetCostKind CostKind) const override;
161 InstructionCost
162 getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF,
163 TTI::TargetCostKind CostKind) const override;
164
165 InstructionCost
166 getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
167 TTI::TargetCostKind CostKind) const override;
168
169 bool preferEpilogueVectorization(ElementCount Iters) const override {
170 return true;
171 }
172
173 bool shouldExpandReduction(const IntrinsicInst *II) const override;
174 /// @}
175};
176
177} // end namespace llvm
178
179#endif
180