55 #define DEBUG_TYPE "AMDGPUtti" 58 "amdgpu-unroll-threshold-private",
59 cl::desc(
"Unroll threshold for AMDGPU if private memory used in a loop"),
63 "amdgpu-unroll-threshold-local",
64 cl::desc(
"Unroll threshold for AMDGPU if local memory used in a loop"),
68 "amdgpu-unroll-threshold-if",
69 cl::desc(
"Unroll threshold increment for AMDGPU for each if statement inside loop"),
81 if (
const PHINode *PHI = dyn_cast<PHINode>(V)) {
83 return SubLoop->contains(PHI); }))
101 const unsigned MaxAlloca = (256 - 16) * 4;
104 unsigned MaxBoost =
std::max(ThresholdPrivate, ThresholdLocal);
106 const DataLayout &
DL = BB->getModule()->getDataLayout();
107 unsigned LocalGEPsSeen = 0;
110 return SubLoop->contains(BB); }))
119 if (
const BranchInst *Br = dyn_cast<BranchInst>(&
I)) {
120 if (UP.
Threshold < MaxBoost && Br->isConditional()) {
130 << *L <<
" due to " << *Br <<
'\n');
145 Threshold = ThresholdPrivate;
147 Threshold = ThresholdLocal;
162 if (AllocaSize > MaxAlloca)
178 bool HasLoopDef =
false;
185 return SubLoop->contains(Inst); }))
209 << *L <<
" due to " << *GEP <<
'\n');
225 return getHardwareNumberOfRegisters(Vec) >> 3;
237 unsigned ChainSizeInBytes,
239 unsigned VecRegBitWidth = VF * LoadSize;
242 return 128 / LoadSize;
248 unsigned ChainSizeInBytes,
250 unsigned VecRegBitWidth = VF * StoreSize;
251 if (VecRegBitWidth > 128)
252 return 128 / StoreSize;
278 unsigned AddrSpace)
const {
284 ChainSizeInBytes <= ST->getMaxPrivateElementSize();
291 unsigned AddrSpace)
const {
292 return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
297 unsigned AddrSpace)
const {
298 return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
313 case Intrinsic::amdgcn_atomic_inc:
314 case Intrinsic::amdgcn_atomic_dec:
315 case Intrinsic::amdgcn_ds_ordered_add:
316 case Intrinsic::amdgcn_ds_ordered_swap:
317 case Intrinsic::amdgcn_ds_fadd:
318 case Intrinsic::amdgcn_ds_fmin:
319 case Intrinsic::amdgcn_ds_fmax: {
322 if (!Ordering || !Volatile)
351 Opd1PropInfo, Opd2PropInfo);
360 unsigned NElts = LT.second.isVector() ?
361 LT.second.getVectorNumElements() : 1;
370 return get64BitInstrCost() * LT.first * NElts;
373 NElts = (NElts + 1) / 2;
376 return getFullRateInstrCost() * LT.first * NElts;
384 return 2 * getFullRateInstrCost() * LT.first * NElts;
388 NElts = (NElts + 1) / 2;
390 return LT.first * NElts * getFullRateInstrCost();
392 const int QuarterRateCost = getQuarterRateInstrCost();
394 const int FullRateCost = getFullRateInstrCost();
395 return (4 * QuarterRateCost + (2 * 2) * FullRateCost) * LT.first * NElts;
399 NElts = (NElts + 1) / 2;
402 return QuarterRateCost * NElts * LT.first;
408 return LT.first * NElts * get64BitInstrCost();
411 NElts = (NElts + 1) / 2;
414 return LT.first * NElts * getFullRateInstrCost();
421 int Cost = 4 * get64BitInstrCost() + 7 * getQuarterRateInstrCost();
424 Cost += 3 * getFullRateInstrCost();
426 return LT.first * Cost * NElts;
431 if ((SLT ==
MVT::f32 && !HasFP32Denormals) ||
433 return LT.first * getQuarterRateInstrCost() * NElts;
443 int Cost = 4 * getFullRateInstrCost() + 2 * getQuarterRateInstrCost();
444 return LT.first * Cost * NElts;
448 int Cost = 7 * getFullRateInstrCost() + 1 * getQuarterRateInstrCost();
450 if (!HasFP32Denormals) {
452 Cost += 2 * getFullRateInstrCost();
455 return LT.first * NElts * Cost;
463 Opd1PropInfo, Opd2PropInfo);
466 template <
typename T>
470 if (ID != Intrinsic::fma)
481 unsigned NElts = LT.second.isVector() ?
482 LT.second.getVectorNumElements() : 1;
487 return LT.first * NElts * get64BitInstrCost();
490 NElts = (NElts + 1) / 2;
492 return LT.first * NElts * (ST->
hasFastFMAF32() ? getHalfRateInstrCost()
493 : getQuarterRateInstrCost());
499 return getIntrinsicInstrCost<Value>(
ID, RetTy,
Args, FMF, VF);
504 unsigned ScalarizationCostPassed) {
505 return getIntrinsicInstrCost<Type>(
ID, RetTy, Tys, FMF,
506 ScalarizationCostPassed);
512 case Instruction::Br:
532 return LT.first * getFullRateInstrCost();
548 return LT.first * getHalfRateInstrCost();
554 case Instruction::ExtractElement:
555 case Instruction::InsertElement: {
569 return Index == ~0u ? 2 : 0;
607 if (
const Argument *A = dyn_cast<Argument>(V))
624 if (isa<AtomicRMWInst>(V) || isa<AtomicCmpXchgInst>(V))
627 if (
const IntrinsicInst *Intrinsic = dyn_cast<IntrinsicInst>(V))
631 if (isa<CallInst>(V) || isa<InvokeInst>(V))
638 if (
const IntrinsicInst *Intrinsic = dyn_cast<IntrinsicInst>(V)) {
639 switch (Intrinsic->getIntrinsicID()) {
642 case Intrinsic::amdgcn_readfirstlane:
643 case Intrinsic::amdgcn_readlane:
644 case Intrinsic::amdgcn_icmp:
645 case Intrinsic::amdgcn_fcmp:
655 case Intrinsic::amdgcn_atomic_inc:
656 case Intrinsic::amdgcn_atomic_dec:
657 case Intrinsic::amdgcn_ds_fadd:
658 case Intrinsic::amdgcn_ds_fmin:
659 case Intrinsic::amdgcn_ds_fmax:
660 case Intrinsic::amdgcn_is_shared:
661 case Intrinsic::amdgcn_is_private:
673 case Intrinsic::amdgcn_atomic_inc:
674 case Intrinsic::amdgcn_atomic_dec:
675 case Intrinsic::amdgcn_ds_fadd:
676 case Intrinsic::amdgcn_ds_fmin:
677 case Intrinsic::amdgcn_ds_fmax: {
679 if (!IsVolatile->
isZero())
690 case Intrinsic::amdgcn_is_shared:
691 case Intrinsic::amdgcn_is_private: {
692 unsigned TrueAS = IntrID == Intrinsic::amdgcn_is_shared ?
738 const FeatureBitset &CallerBits = CallerST->getFeatureBits();
739 const FeatureBitset &CalleeBits = CalleeST->getFeatureBits();
741 FeatureBitset RealCallerBits = CallerBits & ~InlineFeatureIgnoreList;
742 FeatureBitset RealCalleeBits = CalleeBits & ~InlineFeatureIgnoreList;
743 if ((RealCallerBits & RealCalleeBits) != RealCalleeBits)
755 CommonTTI.getUnrollingPreferences(L, SE, UP);
766 case Instruction::ExtractElement: {
773 case Instruction::InsertElement: {
784 if (
auto *FPMO = dyn_cast<FPMathOperator>(II))
785 FMF = FPMO->getFastMathFlags();
792 case Instruction::ShuffleVector: {
825 case Instruction::ZExt:
826 case Instruction::SExt:
827 case Instruction::FPToUI:
828 case Instruction::FPToSI:
829 case Instruction::FPExt:
830 case Instruction::PtrToInt:
831 case Instruction::IntToPtr:
832 case Instruction::SIToFP:
833 case Instruction::UIToFP:
834 case Instruction::Trunc:
835 case Instruction::FPTrunc:
836 case Instruction::BitCast:
837 case Instruction::AddrSpaceCast: {
842 case Instruction::FAdd:
843 case Instruction::Sub:
844 case Instruction::FSub:
845 case Instruction::Mul:
846 case Instruction::FMul:
847 case Instruction::UDiv:
848 case Instruction::SDiv:
849 case Instruction::FDiv:
850 case Instruction::URem:
851 case Instruction::SRem:
852 case Instruction::FRem:
853 case Instruction::Shl:
854 case Instruction::LShr:
855 case Instruction::AShr:
856 case Instruction::And:
857 case Instruction::Or:
858 case Instruction::Xor:
859 case Instruction::FNeg: {
876 return getHardwareNumberOfRegisters(Vec);
907 unsigned AddrSpace)
const {
916 unsigned AddrSpace)
const {
917 return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
922 unsigned AddrSpace)
const {
923 return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
938 case Instruction::Br:
949 case Instruction::ExtractElement:
950 case Instruction::InsertElement: {
962 return Index == ~0u ? 2 : 0;
971 CommonTTI.getUnrollingPreferences(L, SE, UP);
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
Value * getPointerOperand()
bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
This class represents an incoming formal argument to a Function.
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
Address space for 160-bit buffer fat pointers.
bool hasUsableDivScaleConditionOutput() const
Condition output from div_scale is usable.
A Module instance is used to store all the information related to an LLVM module. ...
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
unsigned getCFInstrCost(unsigned Opcode)
unsigned getLoopDepth() const
Return the nesting level of this loop.
void push_back(const T &Elt)
The main scalar evolution driver.
bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
Address space for global memory (RAT0, VTX0).
int getVectorInstrCost(unsigned Opcode, Type *ValTy, unsigned Index)
bool isReverse() const
Return true if this shuffle swaps the order of elements from exactly one source vector.
unsigned getMinVectorRegisterBitWidth() const
This instruction constructs a fixed permutation of two input vectors.
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
void setArgOperand(unsigned i, Value *v)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
int getArithmeticReductionCost(unsigned Opcode, Type *Ty, bool IsPairwise)
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Calling convention used for AMDPAL vertex shader if tessellation is in use.
int 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)
bool hasFastFMAF32() const
Address space for flat memory.
bool isSingleSource() const
Return true if this shuffle chooses elements from exactly one source vector without changing the leng...
Calling convention used for Mesa/AMDPAL geometry shaders.
bool hasVOP3PInsts() const
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Value * getArgOperand(unsigned i) const
bool match(Val *V, const Pattern &P)
unsigned getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Value * > Args, FastMathFlags FMF, unsigned VF=1)
Get intrinsic cost based on arguments.
bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const
SPIR_KERNEL - Calling convention for SPIR kernel functions.
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
bool isAlwaysUniform(const Value *V) const
Shift and rotation operations.
unsigned getNumberOfRegisters(bool Vector) const
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< T *> Args, FastMathFlags FMF, unsigned VF)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
This file contains the simple types necessary to represent the attributes associated with functions a...
unsigned getArithmeticReductionCost(unsigned Opcode, Type *Ty, bool IsPairwise)
Try to calculate arithmetic and shuffle op costs for reduction operations.
Address space for 32-bit constant memory.
mir Rename Register Operands
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
BlockT * getHeader() const
AtomicOrdering
Atomic ordering for LLVM's memory model.
Address space for region memory. (GDS)
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
Type * getType() const
All values are typed, get the type of this value.
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const
bool isInlineCompatible(SIModeRegisterDefaults CalleeMode) const
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
Simple integer binary arithmetic operators.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
unsigned getRegisterBitWidth(bool Vector) const
unsigned getMaxInterleaveFactor(unsigned VF)
AttributeList getAttributes() const
Return the attribute list for this Function.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool isSelect() const
Return true if this shuffle chooses elements from its source vectors without lane crossings and all o...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Value * getOperand(unsigned i) const
Analysis containing CSE Info
static bool isExtractSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is an extract subvector mask.
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
unsigned getCFInstrCost(unsigned Opcode)
Calling convention used for Mesa/AMDPAL compute shaders.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
initializer< Ty > init(const Ty &Val)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Container class for subtarget features.
Address space for direct addressible parameter memory (CONST0).
LLVM Basic Block Representation.
bool isLoopExiting(const BlockT *BB) const
True if terminator in the block can branch to another block that is outside of the current loop...
The instances of the Type class are immutable: once they are created, they are never changed...
bool rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const
This is an important class for using LLVM in a threaded context.
unsigned getUserCost(const User *U, ArrayRef< const Value *> Operands)
Simple binary floating point operators.
Conditional or Unconditional Branch instruction.
bool isIdentity() const
Return true if this shuffle chooses elements from exactly one source vector without lane crossings an...
unsigned getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwise, bool)
Try to calculate op costs for min/max reduction operations.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
bool has16BitInsts() const
bool isIntrinsicSourceOfDivergence(unsigned IntrID)
unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
unsigned getNumberOfRegisters(bool Vec) const
unsigned getHardwareNumberOfRegisters(bool Vec) const
bool hasUnalignedScratchAccess() const
const TargetMachine & getTargetMachine() const
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
unsigned getCFInstrCost(unsigned Opcode)
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
This is the shared class of boolean and integer constants.
bool isSourceOfDivergence(const Value *V) const
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Address space for local memory.
Calling convention used for Mesa/AMDPAL pixel shaders.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
int getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwiseForm, bool IsUnsigned)
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)
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
bool changesLength() const
Return true if this shuffle returns a vector with a different number of elements than its source vect...
static ConstantInt * getTrue(LLVMContext &Context)
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getMaxInterleaveFactor(unsigned VF)
bool isZeroEltSplat() const
Return true if all elements of this shuffle are the same value as the first element of exactly one so...
Class to represent vector types.
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
int getVectorInstrCost(unsigned Opcode, Type *ValTy, unsigned Index)
const std::vector< LoopT * > & getSubLoops() const
Return the loops contained entirely within this loop.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
bool isTranspose() const
Return true if this shuffle transposes the elements of its inputs without changing the length of the ...
Bitwise operators - logical and, logical or, logical xor.
const Function * getParent() const
unsigned getHardwareNumberOfRegisters(bool Vector) const
Represents a single loop in the control flow graph.
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
const Function * getParent() const
Return the enclosing method, or null if none.
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
int getIntegerAttribute(const Function &F, StringRef Name, int Default)
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
iterator_range< value_op_iterator > operand_values()
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Address space for private memory.
TypeSize getScalarSizeInBits() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
unsigned getMinVectorRegisterBitWidth() const
Address space for indirect addressible parameter memory (VTX1).
Primary interface to the complete machine description for the target machine.
Type * getElementType() const
Value * PtrVal
This is the pointer that the intrinsic is loading from or storing to.
Convenience struct for specifying and reasoning about fast-math flags.
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
Calling convention for AMDGPU code object kernels.
unsigned getMaxPrivateElementSize() const
VectorType * getType() const
Overload to return most specific vector type.
Information about a load/store intrinsic defined by the target.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::pair< int, MVT > getTypeLegalizationCost(const DataLayout &DL, Type *Ty) const
Estimate the cost of type-legalization and the legalized type.
unsigned getRegisterBitWidth(bool Vector) const
Address space for constant memory (VTX2).
bool empty() const
empty - Check if the array is empty.
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack