PPCTargetTransformInfo.h 7.3 KB

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