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