21 #define DEBUG_TYPE "aarch64tti"
37 return (CallerBits & CalleeBits) == CalleeBits;
53 return (64 - LZ + 15) / 16;
67 ImmVal = Imm.
sext((BitSize + 63) & ~0x3fU);
72 for (
unsigned ShiftVal = 0; ShiftVal < BitSize; ShiftVal += 64) {
91 unsigned ImmIdx = ~0U;
95 case Instruction::GetElementPtr:
104 case Instruction::Sub:
105 case Instruction::Mul:
106 case Instruction::UDiv:
107 case Instruction::SDiv:
108 case Instruction::URem:
109 case Instruction::SRem:
110 case Instruction::And:
111 case Instruction::Or:
112 case Instruction::Xor:
113 case Instruction::ICmp:
117 case Instruction::Shl:
118 case Instruction::LShr:
119 case Instruction::AShr:
123 case Instruction::Trunc:
124 case Instruction::ZExt:
125 case Instruction::SExt:
126 case Instruction::IntToPtr:
127 case Instruction::PtrToInt:
128 case Instruction::BitCast:
129 case Instruction::PHI:
138 int NumConstants = (BitSize + 63) / 64;
160 case Intrinsic::sadd_with_overflow:
161 case Intrinsic::uadd_with_overflow:
162 case Intrinsic::ssub_with_overflow:
163 case Intrinsic::usub_with_overflow:
164 case Intrinsic::smul_with_overflow:
165 case Intrinsic::umul_with_overflow:
167 int NumConstants = (BitSize + 63) / 64;
174 case Intrinsic::experimental_stackmap:
178 case Intrinsic::experimental_patchpoint_void:
179 case Intrinsic::experimental_patchpoint_i64:
190 if (TyWidth == 32 || TyWidth == 64)
196 bool AArch64TTIImpl::isWideningInstruction(
Type *DstTy,
unsigned Opcode,
201 auto toVectorTy = [&](
Type *ArgTy) {
220 case Instruction::Sub:
230 if (Args.
size() != 2 ||
231 (!isa<SExtInst>(Args[1]) && !isa<ZExtInst>(Args[1])) ||
232 !Args[1]->hasOneUse())
234 auto *Extend = cast<CastInst>(Args[1]);
239 unsigned DstElTySize = DstTyL.second.getScalarSizeInBits();
245 Type *SrcTy = toVectorTy(Extend->getSrcTy());
247 unsigned SrcElTySize = SrcTyL.second.getScalarSizeInBits();
252 unsigned NumDstEls = DstTyL.first * DstTyL.second.getVectorNumElements();
253 unsigned NumSrcEls = SrcTyL.first * SrcTyL.second.getVectorNumElements();
257 return NumDstEls == NumSrcEls && 2 * SrcElTySize == DstElTySize;
263 assert(ISD &&
"Invalid opcode");
268 auto *SingleUser = cast<Instruction>(*I->
user_begin());
270 if (isWideningInstruction(Dst, SingleUser->getOpcode(), Operands)) {
278 if (
auto *Cast = dyn_cast<CastInst>(SingleUser->getOperand(1)))
279 if (I->
getOpcode() == Cast->getOpcode() &&
280 cast<CastInst>(
I)->getSrcTy() == Cast->getSrcTy())
401 assert((Opcode == Instruction::SExt || Opcode == Instruction::ZExt) &&
409 assert(isa<IntegerType>(Dst) && isa<IntegerType>(Src) &&
"Invalid type");
423 if (!VecLT.second.isVector() || !TLI->
isTypeLegal(DstVT))
428 if (DstVT.getSizeInBits() < SrcVT.getSizeInBits())
437 case Instruction::SExt:
442 case Instruction::ZExt:
443 if (DstVT.getSizeInBits() != 64u || SrcVT.getSizeInBits() == 32u)
460 if (!LT.second.isVector())
464 unsigned Width = LT.second.getVectorNumElements();
465 Index = Index % Width;
490 if (isWideningInstruction(Ty, Opcode, Args))
520 Opd1PropInfo, Opd2PropInfo);
528 return (Cost + 1) * LT.first;
538 unsigned NumVectorInstToHideOverhead = 10;
539 int MaxMergeDistance = 64;
543 return NumVectorInstToHideOverhead;
558 const int AmortizationCost = 20;
560 VectorSelectTbl[] = {
587 LT.second.is128BitVector() && Alignment < 16) {
593 const int AmortizationCost = 6;
595 return LT.first * 2 * AmortizationCost;
603 unsigned NumVectorizableInstsToAmortize = NumVecElts * 2;
605 return NumVectorizableInstsToAmortize * NumVecElts * 2;
616 assert(Factor >= 2 &&
"Invalid interleave factor");
617 assert(isa<VectorType>(VecTy) &&
"Expect a vector type");
619 if (Factor <= TLI->getMaxSupportedInterleaveFactor()) {
626 if (NumElts % Factor == 0 &&
632 Alignment, AddressSpace);
637 for (
auto *
I : Tys) {
638 if (!
I->isVectorTy())
640 if (
I->getScalarSizeInBits() *
I->getVectorNumElements() == 128)
658 enum { MaxStridedLoads = 7 };
660 int StridedLoads = 0;
663 for (
const auto BB : L->
blocks()) {
664 for (
auto &
I : *BB) {
675 if (!LSCEVAddRec || !LSCEVAddRec->
isAffine())
684 if (StridedLoads > MaxStridedLoads / 2)
691 int StridedLoads = countStridedLoads(L, SE);
692 DEBUG(
dbgs() <<
"falkor-hwpf: detected " << StridedLoads
693 <<
" strided loads\n");
723 Type *ExpectedType) {
727 case Intrinsic::aarch64_neon_st2:
728 case Intrinsic::aarch64_neon_st3:
729 case Intrinsic::aarch64_neon_st4: {
737 for (
unsigned i = 0, e = NumElts; i != e; ++i) {
743 for (
unsigned i = 0, e = NumElts; i != e; ++i) {
749 case Intrinsic::aarch64_neon_ld2:
750 case Intrinsic::aarch64_neon_ld3:
751 case Intrinsic::aarch64_neon_ld4:
752 if (Inst->
getType() == ExpectedType)
763 case Intrinsic::aarch64_neon_ld2:
764 case Intrinsic::aarch64_neon_ld3:
765 case Intrinsic::aarch64_neon_ld4:
770 case Intrinsic::aarch64_neon_st2:
771 case Intrinsic::aarch64_neon_st3:
772 case Intrinsic::aarch64_neon_st4:
782 case Intrinsic::aarch64_neon_ld2:
783 case Intrinsic::aarch64_neon_st2:
786 case Intrinsic::aarch64_neon_ld3:
787 case Intrinsic::aarch64_neon_st3:
790 case Intrinsic::aarch64_neon_ld4:
791 case Intrinsic::aarch64_neon_st4:
804 const Instruction &
I,
bool &AllowPromotionWithoutCommonHeader) {
805 bool Considerable =
false;
806 AllowPromotionWithoutCommonHeader =
false;
807 if (!isa<SExtInst>(&I))
809 Type *ConsideredSExtType =
811 if (I.
getType() != ConsideredSExtType)
821 if (GEPInst->getNumOperands() > 2) {
822 AllowPromotionWithoutCommonHeader =
true;
848 assert(isa<VectorType>(Ty) &&
"Expected Ty to be a vector type");
851 case Instruction::FAdd:
852 case Instruction::FMul:
853 case Instruction::And:
854 case Instruction::Or:
855 case Instruction::Xor:
856 case Instruction::Mul:
860 case Instruction::ICmp:
861 return (ScalarBits < 64) &&
863 case Instruction::FCmp:
unsigned getVectorInsertExtractBaseCost() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
Cost tables and simple lookup functions.
unsigned getPrefetchDistance()
const TargetMachine & getTargetMachine() const
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth)
The main scalar evolution driver.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
const Function * getParent() const
Return the enclosing method, or null if none.
Type Conversion Cost Table.
An instruction for reading from memory.
bool isLegalInterleavedAccessType(VectorType *VecTy, const DataLayout &DL) const
Returns true if VecTy is a legal interleaved access type.
static IntegerType * getInt64Ty(LLVMContext &C)
unsigned getMaxInterleaveFactor(unsigned VF)
unsigned getMinPrefetchStride()
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
int getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index)
int getAddressComputationCost(Type *Ty, ScalarEvolution *SE, const SCEV *Ptr)
unsigned short MatchingId
Class to represent struct types.
unsigned getNumArgOperands() const
Return the number of call arguments.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
bool useReductionIntrinsic(unsigned Opcode, Type *Ty, TTI::ReductionFlags Flags) const
ARMProcFamilyEnum getProcFamily() const
Returns ARM processor family.
static bool isLogicalImmediate(uint64_t imm, unsigned regSize)
isLogicalImmediate - Return true if the immediate is valid for a logical immediate instruction of the...
const TypeConversionCostTblEntry * ConvertCostTableLookup(ArrayRef< TypeConversionCostTblEntry > Tbl, int ISD, MVT Dst, MVT Src)
Find in type conversion cost table, TypeTy must be comparable to CompareTy by ==. ...
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
Type * getVectorElementType() const
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace)
unsigned getMinPrefetchStride() const
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I)
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
This node represents a polynomial recurrence on the trip count of the specified loop.
Simple integer binary arithmetic operators.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getPrefetchDistance() const
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
Type * getElementType() const
size_t size() const
size - Get the array size.
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info)
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
iterator_range< block_iterator > blocks() const
int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
initializer< Ty > init(const Ty &Val)
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values...
Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
Container class for subtarget features.
int getIntImmCost(int64_t Val)
Calculate the cost of materializing a 64-bit value.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
The instances of the Type class are immutable: once they are created, they are never changed...
int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
bool isVectorTy() const
True if this is an instance of VectorType.
Type * getElementType(unsigned N) const
unsigned getMaxPrefetchIterationsAhead() const
int64_t getSExtValue() const
Get sign extended value.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
unsigned getMaxPrefetchIterationsAhead()
bool shouldConsiderAddressTypePromotion(const Instruction &I, bool &AllowPromotionWithoutCommonHeader)
See if I should be considered for address type promotion.
APInt sext(unsigned width) const
Sign extend to a new width.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Value * getOperand(unsigned i) const
Value * getPointerOperand()
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
bool isMisaligned128StoreSlow() const
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I=nullptr)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
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 * >())
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
unsigned getCacheLineSize()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
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 * >())
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
const FeatureBitset & getFeatureBits() const
getFeatureBits - Return the feature bits.
unsigned getMaxInterleaveFactor() const
unsigned getCacheLineSize() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
Class to represent vector types.
Class for arbitrary precision integers.
unsigned getNumInterleavedAccesses(VectorType *VecTy, const DataLayout &DL) const
Returns the number of interleaved accesses that will be generated when lowering accesses of the given...
Select(COND, TRUEVAL, FALSEVAL).
bool isIntegerTy() const
True if this is an instance of IntegerType.
iterator_range< user_iterator > users()
std::pair< int, MVT > getTypeLegalizationCost(const DataLayout &DL, Type *Ty) const
Estimate the cost of type-legalization and the legalized type.
ZERO_EXTEND - Used for integer types, zeroing the new bits.
unsigned getVectorNumElements() const
llvm_unreachable("Unknown RegBank!")
static std::vector< std::string > Flags
int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace)
Bitwise operators - logical and, logical or, logical xor.
This class represents an analyzed expression in the program.
int getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys)
Represents a single loop in the control flow graph.
bool hasOneUse() const
Return true if there is exactly one user of this value.
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 getWideningBaseCost() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Primary interface to the complete machine description for the target machine.
Value * PtrVal
This is the pointer that the intrinsic is loading from or storing to.
int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
TRUNCATE - Completely drop the high bits.
unsigned getNumElements() const
Random access to the elements.
unsigned getLoopDepth() const
Return the nesting level of this loop.
Information about a load/store intrinsic defined by the target.
const BasicBlock * getParent() const
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
A wrapper class for inspecting calls to intrinsic functions.
This file describes how to lower LLVM code to machine code.