xref: /freebsd/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h (revision 77013d11e6483b970af25e13c9b892075742f7e5)
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 
24 namespace llvm {
25 
26 class PPCTTIImpl : public BasicTTIImplBase<PPCTTIImpl> {
27   typedef BasicTTIImplBase<PPCTTIImpl> BaseT;
28   typedef TargetTransformInfo TTI;
29   friend BaseT;
30 
31   const PPCSubtarget *ST;
32   const PPCTargetLowering *TLI;
33 
34   const PPCSubtarget *getST() const { return ST; }
35   const PPCTargetLowering *getTLI() const { return TLI; }
36   bool mightUseCTR(BasicBlock *BB, TargetLibraryInfo *LibInfo,
37                    SmallPtrSetImpl<const Value *> &Visited);
38 
39 public:
40   explicit PPCTTIImpl(const PPCTargetMachine *TM, const Function &F)
41       : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
42         TLI(ST->getTargetLowering()) {}
43 
44   Optional<Instruction *> instCombineIntrinsic(InstCombiner &IC,
45                                                IntrinsicInst &II) const;
46 
47   /// \name Scalar TTI Implementations
48   /// @{
49 
50   using BaseT::getIntImmCost;
51   int getIntImmCost(const APInt &Imm, Type *Ty,
52                     TTI::TargetCostKind CostKind);
53 
54   int getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm,
55                         Type *Ty, TTI::TargetCostKind CostKind,
56                         Instruction *Inst = nullptr);
57   int getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
58                           Type *Ty, TTI::TargetCostKind CostKind);
59 
60   unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands,
61                        TTI::TargetCostKind CostKind);
62 
63   TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);
64   bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
65                                 AssumptionCache &AC,
66                                 TargetLibraryInfo *LibInfo,
67                                 HardwareLoopInfo &HWLoopInfo);
68   bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI,
69                   DominatorTree *DT, AssumptionCache *AC,
70                   TargetLibraryInfo *LibInfo);
71   bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info);
72   void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
73                                TTI::UnrollingPreferences &UP);
74   void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
75                              TTI::PeelingPreferences &PP);
76   bool isLSRCostLess(TargetTransformInfo::LSRCost &C1,
77                      TargetTransformInfo::LSRCost &C2);
78   bool isNumRegsMajorCostOfLSR();
79 
80   /// @}
81 
82   /// \name Vector TTI Implementations
83   /// @{
84   bool useColdCCForColdCall(Function &F);
85   bool enableAggressiveInterleaving(bool LoopHasReductions);
86   TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,
87                                                     bool IsZeroCmp) const;
88   bool enableInterleavedAccessVectorization();
89 
90   enum PPCRegisterClass {
91     GPRRC, FPRRC, VRRC, VSXRC
92   };
93   unsigned getNumberOfRegisters(unsigned ClassID) const;
94   unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const;
95   const char* getRegisterClassName(unsigned ClassID) const;
96   unsigned getRegisterBitWidth(bool Vector) const;
97   unsigned getCacheLineSize() const override;
98   unsigned getPrefetchDistance() const override;
99   unsigned getMaxInterleaveFactor(unsigned VF);
100   int vectorCostAdjustment(int Cost, unsigned Opcode, Type *Ty1, Type *Ty2);
101   int getArithmeticInstrCost(
102       unsigned Opcode, Type *Ty,
103       TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
104       TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,
105       TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue,
106       TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
107       TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
108       ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
109       const Instruction *CxtI = nullptr);
110   int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp);
111   int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
112                        TTI::CastContextHint CCH, TTI::TargetCostKind CostKind,
113                        const Instruction *I = nullptr);
114   int getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind);
115   int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
116                          CmpInst::Predicate VecPred,
117                          TTI::TargetCostKind CostKind,
118                          const Instruction *I = nullptr);
119   int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
120   int getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment,
121                       unsigned AddressSpace,
122                       TTI::TargetCostKind CostKind,
123                       const Instruction *I = nullptr);
124   int getInterleavedMemoryOpCost(
125       unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
126       Align Alignment, unsigned AddressSpace,
127       TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency,
128       bool UseMaskForCond = false, bool UseMaskForGaps = false);
129   unsigned getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
130                                  TTI::TargetCostKind CostKind);
131 
132   bool areFunctionArgsABICompatible(const Function *Caller,
133                                     const Function *Callee,
134                                     SmallPtrSetImpl<Argument *> &Args) const;
135   /// @}
136 };
137 
138 } // end namespace llvm
139 
140 #endif
141