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 InstructionCost
105 getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
106 ArrayRef<int> Mask, TTI::TargetCostKind CostKind, int Index,
107 VectorType *SubTp, ArrayRef<const Value *> Args = {},
108 const Instruction *CxtI = nullptr) const override;
109 unsigned getVectorTruncCost(Type *SrcTy, Type *DstTy) const;
110 unsigned getVectorBitmaskConversionCost(Type *SrcTy, Type *DstTy) const;
111 unsigned getBoolVecToIntConversionCost(unsigned Opcode, Type *Dst,
112 const Instruction *I) const;
113 InstructionCost
114 getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
115 TTI::CastContextHint CCH, TTI::TargetCostKind CostKind,
116 const Instruction *I = nullptr) const override;
117 InstructionCost getCmpSelInstrCost(
118 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
119 TTI::TargetCostKind CostKind,
120 TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
121 TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
122 const Instruction *I = nullptr) const override;
123 using BaseT::getVectorInstrCost;
124 InstructionCost
125 getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind,
126 unsigned Index, const Value *Op0, const Value *Op1,
127 TTI::VectorInstrContext VIC =
128 TTI::VectorInstrContext::None) const override;
129 bool isFoldableLoad(const LoadInst *Ld,
130 const Instruction *&FoldedValue) const;
131 InstructionCost getMemoryOpCost(
132 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
133 TTI::TargetCostKind CostKind,
134 TTI::OperandValueInfo OpInfo = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
135 const Instruction *I = nullptr) const override;
136
137 InstructionCost getInterleavedMemoryOpCost(
138 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
139 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
140 bool UseMaskForCond = false, bool UseMaskForGaps = false) const override;
141
142 InstructionCost
143 getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
144 std::optional<FastMathFlags> FMF,
145 TTI::TargetCostKind CostKind) const override;
146 InstructionCost
147 getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF,
148 TTI::TargetCostKind CostKind) const override;
149
150 InstructionCost
151 getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
152 TTI::TargetCostKind CostKind) const override;
153
154 bool shouldExpandReduction(const IntrinsicInst *II) const override;
155 /// @}
156};
157
158} // end namespace llvm
159
160#endif
161