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 TargetTransformInfoImplBase 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
25namespace llvm {
26
27class PPCTTIImpl final : 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
38public:
39 explicit PPCTTIImpl(const PPCTargetMachine *TM, const Function &F)
40 : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
41 TLI(ST->getTargetLowering()) {}
42
43 std::optional<Instruction *>
44 instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const override;
45
46 /// \name Scalar TTI Implementations
47 /// @{
48
49 using BaseT::getIntImmCost;
50 InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
51 TTI::TargetCostKind CostKind) const override;
52
53 InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx,
54 const APInt &Imm, Type *Ty,
55 TTI::TargetCostKind CostKind,
56 Instruction *Inst = nullptr) const override;
57 InstructionCost
58 getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
59 Type *Ty, TTI::TargetCostKind CostKind) const override;
60
61 InstructionCost
62 getInstructionCost(const User *U, ArrayRef<const Value *> Operands,
63 TTI::TargetCostKind CostKind) const override;
64
65 TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override;
66 bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
67 AssumptionCache &AC, TargetLibraryInfo *LibInfo,
68 HardwareLoopInfo &HWLoopInfo) const override;
69 bool canSaveCmp(Loop *L, CondBrInst **BI, ScalarEvolution *SE, LoopInfo *LI,
70 DominatorTree *DT, AssumptionCache *AC,
71 TargetLibraryInfo *LibInfo) const override;
72 bool getTgtMemIntrinsic(IntrinsicInst *Inst,
73 MemIntrinsicInfo &Info) const override;
74 void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
75 TTI::UnrollingPreferences &UP,
76 OptimizationRemarkEmitter *ORE) const override;
77 void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
78 TTI::PeelingPreferences &PP) const override;
79 bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
80 const TargetTransformInfo::LSRCost &C2) const override;
81 bool isNumRegsMajorCostOfLSR() const override;
82 bool shouldBuildRelLookupTables() const override;
83 /// @}
84
85 /// \name Vector TTI Implementations
86 /// @{
87 bool useColdCCForColdCall(Function &F) const override;
88 bool enableAggressiveInterleaving(bool LoopHasReductions) const override;
89 TTI::MemCmpExpansionOptions
90 enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const override;
91 bool enableInterleavedAccessVectorization() const override;
92
93 enum PPCRegisterClass {
94 GPRRC, FPRRC, VRRC, VSXRC
95 };
96 unsigned getNumberOfRegisters(unsigned ClassID) const override;
97 unsigned getRegisterClassForType(bool Vector,
98 Type *Ty = nullptr) const override;
99 const char *getRegisterClassName(unsigned ClassID) const override;
100 TypeSize
101 getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override;
102 unsigned getCacheLineSize() const override;
103 unsigned getPrefetchDistance() const override;
104 unsigned getMaxInterleaveFactor(ElementCount VF,
105 bool HasUnorderedReductions) const override;
106 InstructionCost vectorCostAdjustmentFactor(unsigned Opcode, Type *Ty1,
107 Type *Ty2) const;
108 InstructionCost getArithmeticInstrCost(
109 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
110 TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
111 TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
112 ArrayRef<const Value *> Args = {},
113 const Instruction *CxtI = nullptr) const override;
114 InstructionCost
115 getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
116 ArrayRef<int> Mask, TTI::TargetCostKind CostKind, int Index,
117 VectorType *SubTp, ArrayRef<const Value *> Args = {},
118 const Instruction *CxtI = nullptr) const override;
119 InstructionCost
120 getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
121 TTI::CastContextHint CCH, TTI::TargetCostKind CostKind,
122 const Instruction *I = nullptr) const override;
123 InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
124 const Instruction *I = nullptr) const override;
125 InstructionCost getCmpSelInstrCost(
126 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
127 TTI::TargetCostKind CostKind,
128 TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
129 TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
130 const Instruction *I = nullptr) const override;
131 using BaseT::getVectorInstrCost;
132 InstructionCost
133 getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind,
134 unsigned Index, const Value *Op0, const Value *Op1,
135 TTI::VectorInstrContext VIC =
136 TTI::VectorInstrContext::None) const override;
137 InstructionCost getMemoryOpCost(
138 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
139 TTI::TargetCostKind CostKind,
140 TTI::OperandValueInfo OpInfo = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
141 const Instruction *I = nullptr) const override;
142 InstructionCost getInterleavedMemoryOpCost(
143 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
144 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
145 bool UseMaskForCond = false, bool UseMaskForGaps = false) const override;
146 InstructionCost
147 getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
148 TTI::TargetCostKind CostKind) const override;
149 bool areInlineCompatible(const Function *Caller,
150 const Function *Callee) const override;
151 bool areTypesABICompatible(const Function *Caller, const Function *Callee,
152 ArrayRef<Type *> Types) const override;
153 bool supportsTailCallFor(const CallBase *CB) const override;
154
155 TargetTransformInfo::VPLegalization
156 getVPLegalizationStrategy(const VPIntrinsic &PI) const override;
157
158 bool hasActiveVectorLength() const override;
159
160 bool
161 isLegalMaskedStore(Type *DataType, Align Alignment, unsigned AddressSpace,
162 TTI::MaskKind MaskKind =
163 TTI::MaskKind::VariableOrConstantMask) const override;
164 bool
165 isLegalMaskedLoad(Type *DataType, Align Alignment, unsigned AddressSpace,
166 TTI::MaskKind MaskKind =
167 TTI::MaskKind::VariableOrConstantMask) const override;
168
169 InstructionCost
170 getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA,
171 TTI::TargetCostKind CostKind) const override;
172
173 InstructionCost getPartialReductionCost(
174 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
175 ElementCount VF, TTI::PartialReductionExtendKind OpAExtend,
176 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
177 TTI::TargetCostKind CostKind,
178 std::optional<FastMathFlags> FMF) const override {
179 return InstructionCost::getInvalid();
180 }
181
182private:
183 // The following constant is used for estimating costs on power9.
184 static const InstructionCost::CostType P9PipelineFlushEstimate = 80;
185
186 /// @}
187};
188
189} // end namespace llvm
190
191#endif
192