29#define DEBUG_TYPE "hexagontti"
36 cl::desc(
"Allow auto-generation of HVX scatter-gather"));
40 cl::desc(
"Enable auto-vectorization of floatint point types on v68."));
44 cl::desc(
"Control lookup table emission on Hexagon target"));
54bool HexagonTTIImpl::useHVX()
const {
58bool HexagonTTIImpl::isHVXVectorType(
Type *Ty)
const {
62 if (!ST.isTypeForHVX(VecTy))
64 if (ST.useHVXV69Ops() || !VecTy->getElementType()->isFloatingPointTy())
69unsigned HexagonTTIImpl::getTypeNumElements(
Type *Ty)
const {
71 return VTy->getNumElements();
73 "Expecting scalar type");
81 UP.Runtime = UP.Partial =
true;
88 if (L && L->isInnermost() &&
canPeel(L) &&
105 bool Vector = ClassID == 1;
107 return useHVX() ? 32 : 0;
113 bool HasUnorderedReductions)
const {
114 return useHVX() ? 2 : 1;
132 return useHVX() ? ST.getVectorLength()*8 : 32;
150 if (ICA.
getID() == Intrinsic::bswap) {
151 std::pair<InstructionCost, MVT> LT =
171 assert(Opcode == Instruction::Load || Opcode == Instruction::Store);
176 CostKind, OpInfo,
I);
182 if (Opcode == Instruction::Store)
184 CostKind, OpInfo,
I);
186 if (Src->isVectorTy()) {
189 if (isHVXVectorType(VecTy)) {
193 assert(RegWidth &&
"Non-zero vector register width expected");
195 if (VecWidth % RegWidth == 0)
196 return VecWidth / RegWidth;
198 const Align RegAlign(RegWidth / 8);
199 if (Alignment > RegAlign)
200 Alignment = RegAlign;
201 unsigned AlignWidth = 8 * Alignment.value();
202 unsigned NumLoads =
alignTo(VecWidth, AlignWidth) / AlignWidth;
212 const Align BoundAlignment = std::min(Alignment,
Align(8));
213 unsigned AlignWidth = 8 * BoundAlignment.
value();
214 unsigned NumLoads =
alignTo(VecWidth, AlignWidth) / AlignWidth;
215 if (Alignment ==
Align(4) || Alignment ==
Align(8))
216 return Cost * NumLoads;
219 unsigned LogA =
Log2(BoundAlignment);
220 return (3 - LogA) *
Cost * NumLoads;
238 bool UseMaskForCond,
bool UseMaskForGaps)
const {
239 if (Indices.
size() != Factor || UseMaskForCond || UseMaskForGaps)
243 UseMaskForCond, UseMaskForGaps);
255 if (Opcode == Instruction::FCmp)
256 return LT.first +
FloatFactor * getTypeNumElements(ValTy);
259 Op1Info, Op2Info,
I);
270 Args, CtxI, TLibInfo, Scalars);
272 if (Ty->isVectorTy()) {
273 if (!isHVXVectorType(Ty) && Ty->isFPOrFPVectorTy())
276 if (LT.second.isFloatingPoint())
277 return LT.first +
FloatFactor * getTypeNumElements(Ty);
280 Args, CtxI, TLibInfo, Scalars);
288 auto isNonHVXFP = [
this] (
Type *Ty) {
289 return Ty->isVectorTy() && !isHVXVectorType(Ty) && Ty->isFPOrFPVectorTy();
291 if (isNonHVXFP(SrcTy) || isNonHVXFP(DstTy))
295 unsigned SrcN = SrcTy->isFPOrFPVectorTy() ? getTypeNumElements(SrcTy) : 0;
301 std::max(SrcLT.first, DstLT.first) +
FloatFactor * (SrcN + DstN);
304 return Cost == 0 ? 0 : 1;
315 if (Opcode == Instruction::InsertElement) {
317 unsigned Cost = (Index != 0) ? 2 : 0;
318 if (
ElemTy->isIntegerTy(32))
322 Index, Op0, Op1, VIC);
325 if (Opcode == Instruction::ExtractElement)
332 switch (
II->getIntrinsicID()) {
333 case Intrinsic::vector_reduce_add:
345 (ST.isTypeForHVX(DataType) || ST.isTypeForHLX(DataType));
354 (ST.isTypeForHVX(DataType) || ST.isTypeForHLX(DataType));
359 if (!Ty->isVectorTy() || !ST.isTypeForHVX(Ty) ||
363 switch (Ty->getScalarSizeInBits()) {
365 return (getTypeNumElements(Ty) == 128);
367 if (getTypeNumElements(Ty) == 64 || getTypeNumElements(Ty) == 32)
368 return (Alignment >= 2);
371 if (getTypeNumElements(Ty) == 32)
372 return (Alignment >= 4);
381 if (!Ty->isVectorTy() || !ST.isTypeForHVX(Ty) ||
385 switch (Ty->getScalarSizeInBits()) {
387 return (getTypeNumElements(Ty) == 128);
389 if (getTypeNumElements(Ty) == 64)
390 return (Alignment >= 2);
393 if (getTypeNumElements(Ty) == 32)
394 return (Alignment >= 4);
403 Align Alignment)
const {
408 Align Alignment)
const {
415 return ST.getL1PrefetchDistance();
419 return ST.getL1CacheLineSize();
426 auto isCastFoldedIntoLoad = [
this](
const CastInst *CI) ->
bool {
427 if (!CI->isIntegerCast())
432 unsigned SBW =
DL.getTypeSizeInBits(CI->getSrcTy());
433 unsigned DBW =
DL.getTypeSizeInBits(CI->getDestTy());
434 if (DBW != 32 || SBW >= DBW)
445 if (isCastFoldedIntoLoad(CI))
459 if (Caller->hasFnAttribute(
"hexagon_hmx") !=
460 Callee->hasFnAttribute(
"hexagon_hmx"))
462 if (Callee->hasFnAttribute(
"hexagon_hvx") &&
463 !Caller->hasFnAttribute(
"hexagon_hvx"))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t IntrinsicInst * II
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
bool areInlineCompatible(const Function *Caller, const Function *Callee) const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind) const override
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP) const override
std::pair< InstructionCost, MVT > getTypeLegalizationCost(Type *Ty) const
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Opd2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, const TargetLibraryInfo *TLibInfo=nullptr, ArrayRef< const Value * > Scalars={}) const override
This is the base class for all instructions that perform data casts.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
A parsed version of the target data layout string in and methods for querying it.
static constexpr ElementCount getFixed(ScalarTy MinVal)
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
bool forceScalarizeMaskedScatter(VectorType *VTy, Align Alignment) const override
bool isLegalMaskedStore(Type *DataType, Align Alignment, unsigned AddressSpace, TTI::MaskKind MaskKind) const override
ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const override
bool shouldExpandReduction(const IntrinsicInst *II) const override
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
bool forceScalarizeMaskedGather(VectorType *VTy, Align Alignment) const override
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
unsigned getNumberOfRegisters(unsigned ClassID) const override
— Vector TTI begin —
InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE, const SCEV *S, TTI::TargetCostKind CostKind) const override
unsigned getMinVectorRegisterBitWidth() const override
bool isLegalMaskedLoad(Type *DataType, Align Alignment, unsigned AddressSpace, TTI::MaskKind MaskKind) const override
bool isLegalMaskedGather(Type *Ty, Align Alignment) const override
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, const TargetLibraryInfo *TLibInfo=nullptr, ArrayRef< const Value * > Scalars={}) const override
InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind) const override
Compute a cost of the given call instruction.
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, TTI::TargetCostKind CostKind, ArrayRef< int > Mask, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP) const override
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
Get intrinsic cost based on arguments.
TTI::AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const override
Bias LSR towards creating post-increment opportunities.
bool shouldBuildLookupTables() const override
unsigned getMaxInterleaveFactor(ElementCount VF, bool HasUnorderedReductions) const override
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
bool isLegalMaskedScatter(Type *Ty, Align Alignment) const override
bool areInlineCompatible(const Function *Caller, const Function *Callee) const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind) const override
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const override
unsigned getCacheLineSize() const override
unsigned getPrefetchDistance() const override
— Vector TTI end —
static InstructionCost getMax()
Type * getReturnType() const
Intrinsic::ID getID() const
A wrapper class for inspecting calls to intrinsic functions.
An instruction for reading from memory.
Represents a single loop in the control flow graph.
This class represents an analyzed expression in the program.
The main scalar evolution driver.
LLVM_ABI unsigned getSmallConstantMaxTripCount(const Loop *L, SmallVectorImpl< const SCEVPredicate * > *Predicates=nullptr)
Returns the upper bound of the loop trip count as a normal unsigned value.
LLVM_ABI unsigned getSmallConstantTripCount(const Loop *L)
Returns the exact trip count of the loop if we can compute it, and the result is a small constant.
Provides information about what library functions are available for the current target.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
static constexpr TypeSize getScalable(ScalarTy MinimumSize)
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
LLVM Value Representation.
bool hasOneUse() const
Return true if there is exactly one use of this value.
Base class of all SIMD vector types.
Type * getElementType() const
constexpr ScalarTy getFixedValue() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool canPeel(const Loop *L)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
unsigned Log2(Align A)
Returns the log2 of the alignment.
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.