PPCTargetTransformInfo.h 7.7 KB

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