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 : 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 public:
32   explicit SystemZTTIImpl(const SystemZTargetMachine *TM, const Function &F)
33       : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
34         TLI(ST->getTargetLowering()) {}
35 
36   /// \name Scalar TTI Implementations
37   /// @{
38 
39   unsigned getInliningThresholdMultiplier() { return 3; }
40 
41   InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
42                                 TTI::TargetCostKind CostKind);
43 
44   InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx,
45                                     const APInt &Imm, Type *Ty,
46                                     TTI::TargetCostKind CostKind,
47                                     Instruction *Inst = nullptr);
48   InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,
49                                       const APInt &Imm, Type *Ty,
50                                       TTI::TargetCostKind CostKind);
51 
52   TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);
53 
54   void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
55                                TTI::UnrollingPreferences &UP);
56 
57   void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
58                              TTI::PeelingPreferences &PP);
59 
60   bool isLSRCostLess(TargetTransformInfo::LSRCost &C1,
61                      TargetTransformInfo::LSRCost &C2);
62   /// @}
63 
64   /// \name Vector TTI Implementations
65   /// @{
66 
67   unsigned getNumberOfRegisters(unsigned ClassID) const;
68   TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const;
69 
70   unsigned getCacheLineSize() const override { return 256; }
71   unsigned getPrefetchDistance() const override { return 4500; }
72   unsigned getMinPrefetchStride(unsigned NumMemAccesses,
73                                 unsigned NumStridedMemAccesses,
74                                 unsigned NumPrefetches,
75                                 bool HasCall) const override;
76   bool enableWritePrefetching() const override { return true; }
77 
78   bool hasDivRemOp(Type *DataType, bool IsSigned);
79   bool prefersVectorizedAddressing() { return false; }
80   bool LSRWithInstrQueries() { return true; }
81   bool supportsEfficientVectorElementLoadStore() { return true; }
82   bool enableInterleavedAccessVectorization() { return true; }
83 
84   InstructionCost getArithmeticInstrCost(
85       unsigned Opcode, Type *Ty,
86       TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
87       TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,
88       TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue,
89       TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
90       TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
91       ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
92       const Instruction *CxtI = nullptr);
93   InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp,
94                                  ArrayRef<int> Mask, int Index,
95                                  VectorType *SubTp);
96   unsigned getVectorTruncCost(Type *SrcTy, Type *DstTy);
97   unsigned getVectorBitmaskConversionCost(Type *SrcTy, Type *DstTy);
98   unsigned getBoolVecToIntConversionCost(unsigned Opcode, Type *Dst,
99                                          const Instruction *I);
100   InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
101                                    TTI::CastContextHint CCH,
102                                    TTI::TargetCostKind CostKind,
103                                    const Instruction *I = nullptr);
104   InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
105                                      CmpInst::Predicate VecPred,
106                                      TTI::TargetCostKind CostKind,
107                                      const Instruction *I = nullptr);
108   InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
109                                      unsigned Index);
110   bool isFoldableLoad(const LoadInst *Ld, const Instruction *&FoldedValue);
111   InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src,
112                                   MaybeAlign Alignment, unsigned AddressSpace,
113                                   TTI::TargetCostKind CostKind,
114                                   const Instruction *I = nullptr);
115 
116   InstructionCost getInterleavedMemoryOpCost(
117       unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
118       Align Alignment, unsigned AddressSpace,
119       TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency,
120       bool UseMaskForCond = false, bool UseMaskForGaps = false);
121 
122   InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
123                                         TTI::TargetCostKind CostKind);
124   /// @}
125 };
126 
127 } // end namespace llvm
128 
129 #endif
130