30 #define DEBUG_TYPE "AMDGPUtti"
33 "amdgpu-unroll-threshold-private",
34 cl::desc(
"Unroll threshold for AMDGPU if private memory used in a loop"),
38 "amdgpu-unroll-threshold-local",
39 cl::desc(
"Unroll threshold for AMDGPU if local memory used in a loop"),
43 "amdgpu-unroll-threshold-if",
44 cl::desc(
"Unroll threshold increment for AMDGPU for each if statement inside loop"),
56 if (
const PHINode *PHI = dyn_cast<PHINode>(V)) {
58 return SubLoop->contains(PHI); }))
75 const unsigned MaxAlloca = (256 - 16) * 4;
78 unsigned MaxBoost =
std::max(ThresholdPrivate, ThresholdLocal);
82 unsigned LocalGEPsSeen = 0;
85 return SubLoop->contains(BB); }))
95 if (
const BranchInst *Br = dyn_cast<BranchInst>(&
I)) {
96 if (UP.
Threshold < MaxBoost && Br->isConditional()) {
103 <<
" for loop:\n" << *L <<
" due to " << *Br <<
'\n');
118 Threshold = ThresholdPrivate;
120 Threshold = ThresholdLocal;
135 if (AllocaSize > MaxAlloca)
150 bool HasLoopDef =
false;
157 return SubLoop->contains(Inst); }))
179 DEBUG(
dbgs() <<
"Set unroll threshold " << Threshold <<
" for loop:\n"
180 << *L <<
" due to " << *GEP <<
'\n');
235 unsigned AddrSpace)
const {
241 ChainSizeInBytes <= ST->getMaxPrivateElementSize();
248 unsigned AddrSpace)
const {
254 unsigned AddrSpace)
const {
275 Opd1PropInfo, Opd2PropInfo);
284 unsigned NElts = LT.second.isVector() ?
285 LT.second.getVectorNumElements() : 1;
294 return get64BitInstrCost() * LT.first * NElts;
297 return getFullRateInstrCost() * LT.first * NElts;
306 return 2 * getFullRateInstrCost() * LT.first * NElts;
309 return LT.first * NElts * getFullRateInstrCost();
312 const int QuarterRateCost = getQuarterRateInstrCost();
314 const int FullRateCost = getFullRateInstrCost();
315 return (4 * QuarterRateCost + (2 * 2) * FullRateCost) * LT.first * NElts;
319 return QuarterRateCost * NElts * LT.first;
325 return LT.first * NElts * get64BitInstrCost();
328 return LT.first * NElts * getFullRateInstrCost();
336 int Cost = 4 * get64BitInstrCost() + 7 * getQuarterRateInstrCost();
340 Cost += 3 * getFullRateInstrCost();
342 return LT.first * Cost * NElts;
348 int Cost = 7 * getFullRateInstrCost() + 1 * getQuarterRateInstrCost();
349 return LT.first * NElts * Cost;
358 Opd1PropInfo, Opd2PropInfo);
364 case Instruction::Br:
375 case Instruction::ExtractElement:
376 case Instruction::InsertElement: {
390 return Index == ~0u ? 2 : 0;
399 case Intrinsic::amdgcn_workitem_id_x:
400 case Intrinsic::amdgcn_workitem_id_y:
401 case Intrinsic::amdgcn_workitem_id_z:
402 case Intrinsic::amdgcn_interp_mov:
403 case Intrinsic::amdgcn_interp_p1:
404 case Intrinsic::amdgcn_interp_p2:
405 case Intrinsic::amdgcn_mbcnt_hi:
406 case Intrinsic::amdgcn_mbcnt_lo:
407 case Intrinsic::r600_read_tidig_x:
408 case Intrinsic::r600_read_tidig_y:
409 case Intrinsic::r600_read_tidig_z:
410 case Intrinsic::amdgcn_atomic_inc:
411 case Intrinsic::amdgcn_atomic_dec:
412 case Intrinsic::amdgcn_image_atomic_swap:
413 case Intrinsic::amdgcn_image_atomic_add:
414 case Intrinsic::amdgcn_image_atomic_sub:
415 case Intrinsic::amdgcn_image_atomic_smin:
416 case Intrinsic::amdgcn_image_atomic_umin:
417 case Intrinsic::amdgcn_image_atomic_smax:
418 case Intrinsic::amdgcn_image_atomic_umax:
419 case Intrinsic::amdgcn_image_atomic_and:
420 case Intrinsic::amdgcn_image_atomic_or:
421 case Intrinsic::amdgcn_image_atomic_xor:
422 case Intrinsic::amdgcn_image_atomic_inc:
423 case Intrinsic::amdgcn_image_atomic_dec:
424 case Intrinsic::amdgcn_image_atomic_cmpswap:
425 case Intrinsic::amdgcn_buffer_atomic_swap:
426 case Intrinsic::amdgcn_buffer_atomic_add:
427 case Intrinsic::amdgcn_buffer_atomic_sub:
428 case Intrinsic::amdgcn_buffer_atomic_smin:
429 case Intrinsic::amdgcn_buffer_atomic_umin:
430 case Intrinsic::amdgcn_buffer_atomic_smax:
431 case Intrinsic::amdgcn_buffer_atomic_umax:
432 case Intrinsic::amdgcn_buffer_atomic_and:
433 case Intrinsic::amdgcn_buffer_atomic_or:
434 case Intrinsic::amdgcn_buffer_atomic_xor:
435 case Intrinsic::amdgcn_buffer_atomic_cmpswap:
436 case Intrinsic::amdgcn_ps_live:
437 case Intrinsic::amdgcn_ds_swizzle:
473 if (
const Argument *
A = dyn_cast<Argument>(V))
489 if (isa<AtomicRMWInst>(V) || isa<AtomicCmpXchgInst>(V))
492 if (
const IntrinsicInst *Intrinsic = dyn_cast<IntrinsicInst>(V))
496 if (isa<CallInst>(V) || isa<InvokeInst>(V))
503 if (
const IntrinsicInst *Intrinsic = dyn_cast<IntrinsicInst>(V)) {
504 switch (Intrinsic->getIntrinsicID()) {
507 case Intrinsic::amdgcn_readfirstlane:
508 case Intrinsic::amdgcn_readlane:
Calling convention used for Mesa compute shaders.
A parsed version of the target data layout string in and methods for querying it. ...
Value * getPointerOperand()
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
Cost tables and simple lookup functions.
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
The main scalar evolution driver.
bool isLoopExiting(const BlockT *BB) const
True if terminator in the block can branch to another block that is outside of the current loop...
unsigned getMinVectorRegisterBitWidth() const
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
Calling convention used for Mesa geometry shaders.
An instruction for reading from memory.
const std::vector< BlockT * > & getBlocks() const
Get a list of the basic blocks which make up this loop.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
static const unsigned LOCAL_ADDRESS
Address space for local memory.
bool isSourceOfDivergence(const Value *V) const
AttributeList getAttributes() const
Return the attribute list for this Function.
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
OpenCL uses address spaces to differentiate between various memory regions on the hardware...
static const unsigned CONSTANT_BUFFER_15
Shift and rotation operations.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
Calling convention used for Mesa hull shaders.
unsigned getMaxInterleaveFactor(unsigned VF)
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
unsigned getHardwareNumberOfRegisters(bool Vector) const
Simple integer binary arithmetic operators.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
Generation getGeneration() const
Type * getElementType() const
unsigned getRegisterBitWidth(bool Vector) const
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
SPIR_KERNEL - Calling convention for SPIR kernel functions.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
initializer< Ty > init(const Ty &Val)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
const Function * getParent() const
Simple binary floating point operators.
Conditional or Unconditional Branch instruction.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool hasUnalignedScratchAccess() const
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
uint64_t getNumElements() const
static const unsigned PARAM_D_ADDRESS
Address space for direct addressible parameter memory (CONST0)
bool hasFP32Denormals() const
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
bool has16BitInsts() const
unsigned REGION_ADDRESS
Address space for region memory.
bool isAlwaysUniform(const Value *V) const
Calling convention used for Mesa vertex shaders.
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...
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
unsigned getCFInstrCost(unsigned Opcode)
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
static const unsigned CONSTANT_BUFFER_0
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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 * >())
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
Calling convention used for Mesa pixel shaders.
Module.h This file contains the declarations for the Module class.
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
AMDGPUAS getAMDGPUAS() const
unsigned getCFInstrCost(unsigned Opcode)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class to represent vector types.
static const unsigned PARAM_I_ADDRESS
Address space for indirect addressible parameter memory (VTX1)
std::pair< int, MVT > getTypeLegalizationCost(const DataLayout &DL, Type *Ty) const
Estimate the cost of type-legalization and the legalized type.
llvm_unreachable("Unknown RegBank!")
int getVectorInstrCost(unsigned Opcode, Type *ValTy, unsigned Index)
Bitwise operators - logical and, logical or, logical xor.
unsigned getMaxPrivateElementSize() const
unsigned getNumberOfRegisters(bool Vector) const
Represents a single loop in the control flow graph.
unsigned FLAT_ADDRESS
Address space for flat memory.
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)
static const unsigned CONSTANT_ADDRESS
Address space for constant memory (VTX2)
static const unsigned GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
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 * >())
LLVM Value Representation.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
bool hasVOP3PInsts() const
const std::vector< LoopT * > & getSubLoops() const
Return the loops contained entirely within this loop.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
unsigned getLoopDepth() const
Return the nesting level of this loop.
Calling convention for AMDGPU code object kernels.
unsigned PRIVATE_ADDRESS
Address space for private memory.
A wrapper class for inspecting calls to intrinsic functions.
This file describes how to lower LLVM code to machine code.
an instruction to allocate memory on the stack