LLVM  10.0.0
AMDGPUTargetTransformInfo.h
Go to the documentation of this file.
1 //===- AMDGPUTargetTransformInfo.h - AMDGPU 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 //
9 /// \file
10 /// This file a TargetTransformInfo::Concept conforming object specific to the
11 /// AMDGPU target machine. It uses the target's detailed information to
12 /// provide more precise answers to certain TTI queries, while letting the
13 /// target independent and default TTI implementations handle the rest.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETTRANSFORMINFO_H
18 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETTRANSFORMINFO_H
19 
20 #include "AMDGPU.h"
21 #include "AMDGPUSubtarget.h"
22 #include "AMDGPUTargetMachine.h"
24 #include "Utils/AMDGPUBaseInfo.h"
25 #include "llvm/ADT/ArrayRef.h"
28 #include "llvm/IR/Function.h"
31 #include <cassert>
32 
33 namespace llvm {
34 
35 class AMDGPUTargetLowering;
36 class Loop;
37 class ScalarEvolution;
38 class Type;
39 class Value;
40 
41 class AMDGPUTTIImpl final : public BasicTTIImplBase<AMDGPUTTIImpl> {
43  using TTI = TargetTransformInfo;
44 
45  friend BaseT;
46 
47  Triple TargetTriple;
48 
49  const GCNSubtarget *ST;
50  const TargetLoweringBase *TLI;
51 
52  const TargetSubtargetInfo *getST() const { return ST; }
53  const TargetLoweringBase *getTLI() const { return TLI; }
54 
55 public:
56  explicit AMDGPUTTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
57  : BaseT(TM, F.getParent()->getDataLayout()),
58  TargetTriple(TM->getTargetTriple()),
59  ST(static_cast<const GCNSubtarget *>(TM->getSubtargetImpl(F))),
60  TLI(ST->getTargetLowering()) {}
61 
64 };
65 
66 class GCNTTIImpl final : public BasicTTIImplBase<GCNTTIImpl> {
68  using TTI = TargetTransformInfo;
69 
70  friend BaseT;
71 
72  const GCNSubtarget *ST;
73  const AMDGPUTargetLowering *TLI;
74  AMDGPUTTIImpl CommonTTI;
75  bool IsGraphicsShader;
76  bool HasFP32Denormals;
77 
78  const FeatureBitset InlineFeatureIgnoreList = {
79  // Codegen control options which don't matter.
80  AMDGPU::FeatureEnableLoadStoreOpt,
81  AMDGPU::FeatureEnableSIScheduler,
82  AMDGPU::FeatureEnableUnsafeDSOffsetFolding,
83  AMDGPU::FeatureFlatForGlobal,
84  AMDGPU::FeaturePromoteAlloca,
85  AMDGPU::FeatureUnalignedBufferAccess,
86  AMDGPU::FeatureUnalignedScratchAccess,
87 
88  AMDGPU::FeatureAutoWaitcntBeforeBarrier,
89 
90  // Property of the kernel/environment which can't actually differ.
91  AMDGPU::FeatureSGPRInitBug,
92  AMDGPU::FeatureXNACK,
93  AMDGPU::FeatureTrapHandler,
94  AMDGPU::FeatureCodeObjectV3,
95 
96  // The default assumption needs to be ecc is enabled, but no directly
97  // exposed operations depend on it, so it can be safely inlined.
98  AMDGPU::FeatureSRAMECC,
99 
100  // Perf-tuning features
101  AMDGPU::FeatureFastFMAF32,
102  AMDGPU::HalfRate64Ops
103  };
104 
105  const GCNSubtarget *getST() const { return ST; }
106  const AMDGPUTargetLowering *getTLI() const { return TLI; }
107 
108  static inline int getFullRateInstrCost() {
110  }
111 
112  static inline int getHalfRateInstrCost() {
114  }
115 
116  // TODO: The size is usually 8 bytes, but takes 4x as many cycles. Maybe
117  // should be 2 or 4.
118  static inline int getQuarterRateInstrCost() {
120  }
121 
122  // On some parts, normal fp64 operations are half rate, and others
123  // quarter. This also applies to some integer operations.
124  inline int get64BitInstrCost() const {
125  return ST->hasHalfRate64Ops() ?
126  getHalfRateInstrCost() : getQuarterRateInstrCost();
127  }
128 
129 public:
130  explicit GCNTTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
131  : BaseT(TM, F.getParent()->getDataLayout()),
132  ST(static_cast<const GCNSubtarget*>(TM->getSubtargetImpl(F))),
133  TLI(ST->getTargetLowering()),
134  CommonTTI(TM, F),
135  IsGraphicsShader(AMDGPU::isShader(F.getCallingConv())),
136  HasFP32Denormals(ST->hasFP32Denormals(F)) { }
137 
138  bool hasBranchDivergence() { return true; }
139 
142 
144  assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
145  return TTI::PSK_FastHardware;
146  }
147 
148  unsigned getHardwareNumberOfRegisters(bool Vector) const;
149  unsigned getNumberOfRegisters(bool Vector) const;
150  unsigned getRegisterBitWidth(bool Vector) const;
151  unsigned getMinVectorRegisterBitWidth() const;
152  unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
153  unsigned ChainSizeInBytes,
154  VectorType *VecTy) const;
155  unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
156  unsigned ChainSizeInBytes,
157  VectorType *VecTy) const;
158  unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const;
159 
160  bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes,
161  unsigned Alignment,
162  unsigned AddrSpace) const;
163  bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
164  unsigned Alignment,
165  unsigned AddrSpace) const;
166  bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
167  unsigned Alignment,
168  unsigned AddrSpace) const;
169 
170  unsigned getMaxInterleaveFactor(unsigned VF);
171 
173 
175  unsigned Opcode, Type *Ty,
181  const Instruction *CxtI = nullptr);
182 
183  unsigned getCFInstrCost(unsigned Opcode);
184 
185  int getVectorInstrCost(unsigned Opcode, Type *ValTy, unsigned Index);
186  bool isSourceOfDivergence(const Value *V) const;
187  bool isAlwaysUniform(const Value *V) const;
188 
189  unsigned getFlatAddressSpace() const {
190  // Don't bother running InferAddressSpaces pass on graphics shaders which
191  // don't use flat addressing.
192  if (IsGraphicsShader)
193  return -1;
194  return AMDGPUAS::FLAT_ADDRESS;
195  }
196 
198  Intrinsic::ID IID) const;
200  Value *OldV, Value *NewV) const;
201 
202  unsigned getVectorSplitCost() { return 0; }
203 
204  unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
205  Type *SubTp);
206 
207  bool areInlineCompatible(const Function *Caller,
208  const Function *Callee) const;
209 
210  unsigned getInliningThresholdMultiplier() { return 11; }
211 
212  int getInlinerVectorBonusPercent() { return 0; }
213 
214  int getArithmeticReductionCost(unsigned Opcode,
215  Type *Ty,
216  bool IsPairwise);
217  template <typename T>
218  int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
220  unsigned VF);
221  int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
223  unsigned ScalarizationCostPassed = UINT_MAX);
224  int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
226  unsigned VF = 1);
227  int getMinMaxReductionCost(Type *Ty, Type *CondTy,
228  bool IsPairwiseForm,
229  bool IsUnsigned);
230  unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands);
231 };
232 
233 class R600TTIImpl final : public BasicTTIImplBase<R600TTIImpl> {
235  using TTI = TargetTransformInfo;
236 
237  friend BaseT;
238 
239  const R600Subtarget *ST;
240  const AMDGPUTargetLowering *TLI;
241  AMDGPUTTIImpl CommonTTI;
242 
243 public:
244  explicit R600TTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
245  : BaseT(TM, F.getParent()->getDataLayout()),
246  ST(static_cast<const R600Subtarget*>(TM->getSubtargetImpl(F))),
247  TLI(ST->getTargetLowering()),
248  CommonTTI(TM, F) {}
249 
250  const R600Subtarget *getST() const { return ST; }
251  const AMDGPUTargetLowering *getTLI() const { return TLI; }
252 
255  unsigned getHardwareNumberOfRegisters(bool Vec) const;
256  unsigned getNumberOfRegisters(bool Vec) const;
257  unsigned getRegisterBitWidth(bool Vector) const;
258  unsigned getMinVectorRegisterBitWidth() const;
259  unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const;
260  bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes, unsigned Alignment,
261  unsigned AddrSpace) const;
262  bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
263  unsigned Alignment,
264  unsigned AddrSpace) const;
265  bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
266  unsigned Alignment,
267  unsigned AddrSpace) const;
268  unsigned getMaxInterleaveFactor(unsigned VF);
269  unsigned getCFInstrCost(unsigned Opcode);
270  int getVectorInstrCost(unsigned Opcode, Type *ValTy, unsigned Index);
271 };
272 
273 } // end namespace llvm
274 
275 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETTRANSFORMINFO_H
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const
Definition: BasicTTIImpl.h:219
The main scalar evolution driver.
static bool hasFP32Denormals(const MachineFunction &MF)
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
F(f)
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:77
unsigned getMaxInterleaveFactor(unsigned VF)
Definition: BasicTTIImpl.h:628
Address space for flat memory.
Definition: AMDGPU.h:271
bool rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const
Definition: BasicTTIImpl.h:224
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
R600TTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
unsigned getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Value * > Args, FastMathFlags FMF, unsigned VF=1)
Get intrinsic cost based on arguments.
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info)
unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
unsigned getFlatAddressSpace() const
unsigned getArithmeticReductionCost(unsigned Opcode, Type *Ty, bool IsPairwise)
Try to calculate arithmetic and shuffle op costs for reduction operations.
mir Rename Register Operands
unsigned getRegisterBitWidth(bool Vector) const
Definition: BasicTTIImpl.h:565
bool hasHalfRate64Ops() const
PopcntSupportKind
Flags indicating the kind of support for population count.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
const R600Subtarget * getST() const
Container class for subtarget features.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:465
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
unsigned getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwise, bool)
Try to calculate op costs for min/max reduction operations.
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
unsigned getUserCost(const User *U, ArrayRef< const Value * > Operands)
const AMDGPUTargetLowering * getTLI() const
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
The AMDGPU TargetMachine interface definition for hw codgen targets.
unsigned getNumberOfRegisters(unsigned ClassID) const
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
OperandValueProperties
Additional properties of an operand&#39;s values.
unsigned getCFInstrCost(unsigned Opcode)
Definition: BasicTTIImpl.h:831
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
Definition: BasicTTIImpl.h:678
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value * > Args=ArrayRef< const Value * >(), const Instruction *CxtI=nullptr)
Definition: BasicTTIImpl.h:630
Class to represent vector types.
Definition: DerivedTypes.h:432
amdgpu Simplify well known AMD library false FunctionCallee Callee
bool isShader(CallingConv::ID cc)
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
GCNTTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
TargetSubtargetInfo - Generic base class for all target subtargets.
Provides AMDGPU specific target descriptions.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:509
Parameters that control the generic loop unrolling transformation.
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Definition: BasicTTIImpl.h:876
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
The cost of a typical &#39;add&#39; instruction.
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth)
bool isSourceOfDivergence(const Value *V)
Definition: BasicTTIImpl.h:210
aarch64 promote const
LLVM Value Representation.
Definition: Value.h:74
static const Function * getParent(const Value *V)
unsigned getInliningThresholdMultiplier()
AMDGPUTTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
const DataLayout & getDataLayout() const
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:160
OperandValueKind
Additional information about an operand&#39;s possible values.
This pass exposes codegen information to IR-level passes.
Information about a load/store intrinsic defined by the target.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:44
ShuffleKind
The various kinds of shuffle patterns for vector queries.