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 bool hasDivRemOp(Type *DataType, bool IsSigned) const override;
86 bool prefersVectorizedAddressing() const override { return false; }
87 bool LSRWithInstrQueries() const override { return true; }
88 InstructionCost
89 getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts,
90 bool Insert, bool Extract,
91 TTI::TargetCostKind CostKind,
92 bool ForPoisonSrc = true, ArrayRef<Value *> VL = {},
93 TTI::VectorInstrContext VIC =
94 TTI::VectorInstrContext::None) const override;
95 bool supportsEfficientVectorElementLoadStore() const override { return true; }
96 bool enableInterleavedAccessVectorization() const override { return true; }
97
98 InstructionCost getArithmeticInstrCost(
99 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
100 TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
101 TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
102 ArrayRef<const Value *> Args = {},
103 const Instruction *CxtI = nullptr) const override;
104
105 InstructionCost getPartialReductionCost(
106 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
107 ElementCount VF, TTI::PartialReductionExtendKind OpAExtend,
108 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
109 TTI::TargetCostKind CostKind,
110 std::optional<FastMathFlags> FMF) const override {
111 return InstructionCost::getInvalid();
112 }
113
114 InstructionCost
115 getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
116 ArrayRef<int> Mask, TTI::TargetCostKind CostKind, int Index,
117 VectorType *SubTp, ArrayRef<const Value *> Args = {},
118 const Instruction *CxtI = nullptr) const override;
119 unsigned getVectorTruncCost(Type *SrcTy, Type *DstTy) const;
120 unsigned getVectorBitmaskConversionCost(Type *SrcTy, Type *DstTy) const;
121 unsigned getBoolVecToIntConversionCost(unsigned Opcode, Type *Dst,
122 const Instruction *I) const;
123 InstructionCost
124 getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
125 TTI::CastContextHint CCH, TTI::TargetCostKind CostKind,
126 const Instruction *I = nullptr) const override;
127 InstructionCost getCmpSelInstrCost(
128 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
129 TTI::TargetCostKind CostKind,
130 TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
131 TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
132 const Instruction *I = nullptr) const override;
133 using BaseT::getVectorInstrCost;
134 InstructionCost
135 getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind,
136 unsigned Index, const Value *Op0, const Value *Op1,
137 TTI::VectorInstrContext VIC =
138 TTI::VectorInstrContext::None) const override;
139 bool isFoldableLoad(const LoadInst *Ld,
140 const Instruction *&FoldedValue) const;
141 InstructionCost getMemoryOpCost(
142 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
143 TTI::TargetCostKind CostKind,
144 TTI::OperandValueInfo OpInfo = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
145 const Instruction *I = nullptr) const override;
146
147 InstructionCost getInterleavedMemoryOpCost(
148 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
149 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
150 bool UseMaskForCond = false, bool UseMaskForGaps = false) const override;
151
152 InstructionCost
153 getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
154 std::optional<FastMathFlags> FMF,
155 TTI::TargetCostKind CostKind) const override;
156 InstructionCost
157 getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF,
158 TTI::TargetCostKind CostKind) const override;
159
160 InstructionCost
161 getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
162 TTI::TargetCostKind CostKind) const override;
163
164 bool preferEpilogueVectorization(ElementCount Iters) const override {
165 return true;
166 }
167
168 bool shouldExpandReduction(const IntrinsicInst *II) const override;
169 /// @}
170};
171
172} // end namespace llvm
173
174#endif
175