xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h (revision e64bea71c21eb42e97aa615188ba91f6cce0d36d)
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 
16 namespace llvm {
17 
18 class 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 
getST()26   const SystemZSubtarget *getST() const { return ST; }
getTLI()27   const SystemZTargetLowering *getTLI() const { return TLI; }
28 
29   unsigned const LIBCALL_COST = 30;
30 
isInt128InVR(Type * Ty)31   bool isInt128InVR(Type *Ty) const {
32     return Ty->isIntegerTy(128) && ST->hasVector();
33   }
34 
35 public:
SystemZTTIImpl(const SystemZTargetMachine * TM,const Function & F)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 
getCacheLineSize()77   unsigned getCacheLineSize() const override { return 256; }
getPrefetchDistance()78   unsigned getPrefetchDistance() const override { return 4500; }
79   unsigned getMinPrefetchStride(unsigned NumMemAccesses,
80                                 unsigned NumStridedMemAccesses,
81                                 unsigned NumPrefetches,
82                                 bool HasCall) const override;
enableWritePrefetching()83   bool enableWritePrefetching() const override { return true; }
84 
85   bool hasDivRemOp(Type *DataType, bool IsSigned) const override;
prefersVectorizedAddressing()86   bool prefersVectorizedAddressing() const override { return false; }
LSRWithInstrQueries()87   bool LSRWithInstrQueries() const override { return true; }
88   InstructionCost getScalarizationOverhead(
89       VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
90       TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
91       ArrayRef<Value *> VL = {}) const override;
supportsEfficientVectorElementLoadStore()92   bool supportsEfficientVectorElementLoadStore() const override { return true; }
enableInterleavedAccessVectorization()93   bool enableInterleavedAccessVectorization() const override { return true; }
94 
95   InstructionCost getArithmeticInstrCost(
96       unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
97       TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
98       TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
99       ArrayRef<const Value *> Args = {},
100       const Instruction *CxtI = nullptr) const override;
101   InstructionCost
102   getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
103                  ArrayRef<int> Mask, TTI::TargetCostKind CostKind, int Index,
104                  VectorType *SubTp, ArrayRef<const Value *> Args = {},
105                  const Instruction *CxtI = nullptr) const override;
106   unsigned getVectorTruncCost(Type *SrcTy, Type *DstTy) const;
107   unsigned getVectorBitmaskConversionCost(Type *SrcTy, Type *DstTy) const;
108   unsigned getBoolVecToIntConversionCost(unsigned Opcode, Type *Dst,
109                                          const Instruction *I) const;
110   InstructionCost
111   getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
112                    TTI::CastContextHint CCH, TTI::TargetCostKind CostKind,
113                    const Instruction *I = nullptr) const override;
114   InstructionCost getCmpSelInstrCost(
115       unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
116       TTI::TargetCostKind CostKind,
117       TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
118       TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
119       const Instruction *I = nullptr) const override;
120   using BaseT::getVectorInstrCost;
121   InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
122                                      TTI::TargetCostKind CostKind,
123                                      unsigned Index, const Value *Op0,
124                                      const Value *Op1) const override;
125   bool isFoldableLoad(const LoadInst *Ld,
126                       const Instruction *&FoldedValue) const;
127   InstructionCost getMemoryOpCost(
128       unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
129       TTI::TargetCostKind CostKind,
130       TTI::OperandValueInfo OpInfo = {TTI::OK_AnyValue, TTI::OP_None},
131       const Instruction *I = nullptr) const override;
132 
133   InstructionCost getInterleavedMemoryOpCost(
134       unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
135       Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
136       bool UseMaskForCond = false, bool UseMaskForGaps = false) const override;
137 
138   InstructionCost
139   getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
140                              std::optional<FastMathFlags> FMF,
141                              TTI::TargetCostKind CostKind) const override;
142   InstructionCost
143   getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF,
144                          TTI::TargetCostKind CostKind) const override;
145 
146   InstructionCost
147   getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
148                         TTI::TargetCostKind CostKind) const override;
149 
150   bool shouldExpandReduction(const IntrinsicInst *II) const override;
151   /// @}
152 };
153 
154 } // end namespace llvm
155 
156 #endif
157