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