xref: /freebsd/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h (revision da5432eda807c4b7232d030d5157d5b417ea4f52)
1 //===-- PPCTargetTransformInfo.h - PPC specific TTI -------------*- C++ -*-===//
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 /// \file
9 /// This file a TargetTransformInfo::Concept conforming object specific to the
10 /// PPC target machine. It uses the target's detailed information to
11 /// provide more precise answers to certain TTI queries, while letting the
12 /// target independent and default TTI implementations handle the rest.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LIB_TARGET_POWERPC_PPCTARGETTRANSFORMINFO_H
17 #define LLVM_LIB_TARGET_POWERPC_PPCTARGETTRANSFORMINFO_H
18 
19 #include "PPCTargetMachine.h"
20 #include "llvm/Analysis/TargetTransformInfo.h"
21 #include "llvm/CodeGen/BasicTTIImpl.h"
22 #include "llvm/CodeGen/TargetLowering.h"
23 #include <optional>
24 
25 namespace llvm {
26 
27 class PPCTTIImpl : public BasicTTIImplBase<PPCTTIImpl> {
28   typedef BasicTTIImplBase<PPCTTIImpl> BaseT;
29   typedef TargetTransformInfo TTI;
30   friend BaseT;
31 
32   const PPCSubtarget *ST;
33   const PPCTargetLowering *TLI;
34 
35   const PPCSubtarget *getST() const { return ST; }
36   const PPCTargetLowering *getTLI() const { return TLI; }
37   bool mightUseCTR(BasicBlock *BB, TargetLibraryInfo *LibInfo,
38                    SmallPtrSetImpl<const Value *> &Visited);
39 
40 public:
41   explicit PPCTTIImpl(const PPCTargetMachine *TM, const Function &F)
42       : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
43         TLI(ST->getTargetLowering()) {}
44 
45   std::optional<Instruction *> instCombineIntrinsic(InstCombiner & IC,
46                                                     IntrinsicInst & II) const;
47 
48   /// \name Scalar TTI Implementations
49   /// @{
50 
51   using BaseT::getIntImmCost;
52   InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
53                                 TTI::TargetCostKind CostKind);
54 
55   InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx,
56                                     const APInt &Imm, Type *Ty,
57                                     TTI::TargetCostKind CostKind,
58                                     Instruction *Inst = nullptr);
59   InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,
60                                       const APInt &Imm, Type *Ty,
61                                       TTI::TargetCostKind CostKind);
62 
63   InstructionCost getInstructionCost(const User *U,
64                                      ArrayRef<const Value *> Operands,
65                                      TTI::TargetCostKind CostKind);
66 
67   TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);
68   bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
69                                 AssumptionCache &AC,
70                                 TargetLibraryInfo *LibInfo,
71                                 HardwareLoopInfo &HWLoopInfo);
72   bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI,
73                   DominatorTree *DT, AssumptionCache *AC,
74                   TargetLibraryInfo *LibInfo);
75   bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info);
76   void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
77                                TTI::UnrollingPreferences &UP,
78                                OptimizationRemarkEmitter *ORE);
79   void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
80                              TTI::PeelingPreferences &PP);
81   bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
82                      const TargetTransformInfo::LSRCost &C2);
83   bool isNumRegsMajorCostOfLSR();
84   bool shouldBuildRelLookupTables() const;
85   /// @}
86 
87   /// \name Vector TTI Implementations
88   /// @{
89   bool useColdCCForColdCall(Function &F);
90   bool enableAggressiveInterleaving(bool LoopHasReductions);
91   TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,
92                                                     bool IsZeroCmp) const;
93   bool enableInterleavedAccessVectorization();
94 
95   enum PPCRegisterClass {
96     GPRRC, FPRRC, VRRC, VSXRC
97   };
98   unsigned getNumberOfRegisters(unsigned ClassID) const;
99   unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const;
100   const char* getRegisterClassName(unsigned ClassID) const;
101   TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const;
102   unsigned getCacheLineSize() const override;
103   unsigned getPrefetchDistance() const override;
104   unsigned getMaxInterleaveFactor(unsigned VF);
105   InstructionCost vectorCostAdjustmentFactor(unsigned Opcode, Type *Ty1,
106                                              Type *Ty2);
107   InstructionCost getArithmeticInstrCost(
108       unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
109       TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
110       TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
111       ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
112       const Instruction *CxtI = nullptr);
113   InstructionCost getShuffleCost(TTI::ShuffleKind Kind, Type *Tp,
114                                  ArrayRef<int> Mask,
115                                  TTI::TargetCostKind CostKind, int Index,
116                                  Type *SubTp,
117                                  ArrayRef<const Value *> Args = std::nullopt);
118   InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
119                                    TTI::CastContextHint CCH,
120                                    TTI::TargetCostKind CostKind,
121                                    const Instruction *I = nullptr);
122   InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
123                                  const Instruction *I = nullptr);
124   InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
125                                      CmpInst::Predicate VecPred,
126                                      TTI::TargetCostKind CostKind,
127                                      const Instruction *I = nullptr);
128   using BaseT::getVectorInstrCost;
129   InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
130                                      TTI::TargetCostKind CostKind,
131                                      unsigned Index, Value *Op0, Value *Op1);
132   InstructionCost
133   getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment,
134                   unsigned AddressSpace, TTI::TargetCostKind CostKind,
135                   TTI::OperandValueInfo OpInfo = {TTI::OK_AnyValue, TTI::OP_None},
136                   const Instruction *I = nullptr);
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);
141   InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
142                                         TTI::TargetCostKind CostKind);
143   bool areTypesABICompatible(const Function *Caller, const Function *Callee,
144                              const ArrayRef<Type *> &Types) const;
145   bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
146                              Align Alignment) const;
147   InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
148                                     unsigned AddressSpace,
149                                     TTI::TargetCostKind CostKind,
150                                     const Instruction *I = nullptr);
151   bool supportsTailCallFor(const CallBase *CB) const;
152 
153 private:
154   // The following constant is used for estimating costs on power9.
155   static const InstructionCost::CostType P9PipelineFlushEstimate = 80;
156 
157   /// @}
158 };
159 
160 } // end namespace llvm
161 
162 #endif
163