diff --git a/include/llvm/Analysis/TargetTransformInfo.h b/include/llvm/Analysis/TargetTransformInfo.h index f7ade22b6ab..3bd459c3042 100644 --- a/include/llvm/Analysis/TargetTransformInfo.h +++ b/include/llvm/Analysis/TargetTransformInfo.h @@ -728,14 +728,15 @@ public: /// Estimate the overhead of scalarizing an instruction. Insert and Extract /// are set if the demanded result elements need to be inserted and/or /// extracted from vectors. - unsigned getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, - bool Insert, bool Extract) const; + InstructionCost getScalarizationOverhead(VectorType *Ty, + const APInt &DemandedElts, + bool Insert, bool Extract) const; /// Estimate the overhead of scalarizing an instructions unique /// non-constant operands. The (potentially vector) types to use for each of /// argument are passes via Tys. - unsigned getOperandsScalarizationOverhead(ArrayRef Args, - ArrayRef Tys) const; + InstructionCost getOperandsScalarizationOverhead(ArrayRef Args, + ArrayRef Tys) const; /// If target has efficient vector element load/store instructions, it can /// return true here so that insertion/extraction costs are not added to @@ -1499,10 +1500,11 @@ public: virtual bool shouldBuildLookupTablesForConstant(Constant *C) = 0; virtual bool shouldBuildRelLookupTables() = 0; virtual bool useColdCCForColdCall(Function &F) = 0; - virtual unsigned getScalarizationOverhead(VectorType *Ty, - const APInt &DemandedElts, - bool Insert, bool Extract) = 0; - virtual unsigned + virtual InstructionCost getScalarizationOverhead(VectorType *Ty, + const APInt &DemandedElts, + bool Insert, + bool Extract) = 0; + virtual InstructionCost getOperandsScalarizationOverhead(ArrayRef Args, ArrayRef Tys) = 0; virtual bool supportsEfficientVectorElementLoadStore() = 0; @@ -1900,12 +1902,14 @@ public: return Impl.useColdCCForColdCall(F); } - unsigned getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, - bool Insert, bool Extract) override { + InstructionCost getScalarizationOverhead(VectorType *Ty, + const APInt &DemandedElts, + bool Insert, bool Extract) override { return Impl.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract); } - unsigned getOperandsScalarizationOverhead(ArrayRef Args, - ArrayRef Tys) override { + InstructionCost + getOperandsScalarizationOverhead(ArrayRef Args, + ArrayRef Tys) override { return Impl.getOperandsScalarizationOverhead(Args, Tys); } diff --git a/include/llvm/Analysis/TargetTransformInfoImpl.h b/include/llvm/Analysis/TargetTransformInfoImpl.h index 227c74abc5a..09fca81c2cd 100644 --- a/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -301,13 +301,14 @@ public: bool useColdCCForColdCall(Function &F) const { return false; } - unsigned getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, - bool Insert, bool Extract) const { + InstructionCost getScalarizationOverhead(VectorType *Ty, + const APInt &DemandedElts, + bool Insert, bool Extract) const { return 0; } - unsigned getOperandsScalarizationOverhead(ArrayRef Args, - ArrayRef Tys) const { + InstructionCost getOperandsScalarizationOverhead(ArrayRef Args, + ArrayRef Tys) const { return 0; } diff --git a/include/llvm/CodeGen/BasicTTIImpl.h b/include/llvm/CodeGen/BasicTTIImpl.h index 579ff1794b6..c3660afd307 100644 --- a/include/llvm/CodeGen/BasicTTIImpl.h +++ b/include/llvm/CodeGen/BasicTTIImpl.h @@ -213,8 +213,8 @@ private: getMemoryOpCost(Opcode, VT->getElementType(), Alignment, 0, CostKind)); // Next, compute the cost of packing the result in a vector. - int PackingCost = getScalarizationOverhead(VT, Opcode != Instruction::Store, - Opcode == Instruction::Store); + InstructionCost PackingCost = getScalarizationOverhead( + VT, Opcode != Instruction::Store, Opcode == Instruction::Store); InstructionCost ConditionalCost = 0; if (VariableMask) { @@ -650,8 +650,9 @@ public: /// Estimate the overhead of scalarizing an instruction. Insert and Extract /// are set if the demanded result elements need to be inserted and/or /// extracted from vectors. - unsigned getScalarizationOverhead(VectorType *InTy, const APInt &DemandedElts, - bool Insert, bool Extract) { + InstructionCost getScalarizationOverhead(VectorType *InTy, + const APInt &DemandedElts, + bool Insert, bool Extract) { /// FIXME: a bitfield is not a reasonable abstraction for talking about /// which elements are needed from a scalable vector auto *Ty = cast(InTy); @@ -670,12 +671,12 @@ public: Cost += thisT()->getVectorInstrCost(Instruction::ExtractElement, Ty, i); } - return *Cost.getValue(); + return Cost; } /// Helper wrapper for the DemandedElts variant of getScalarizationOverhead. - unsigned getScalarizationOverhead(VectorType *InTy, bool Insert, - bool Extract) { + InstructionCost getScalarizationOverhead(VectorType *InTy, bool Insert, + bool Extract) { auto *Ty = cast(InTy); APInt DemandedElts = APInt::getAllOnesValue(Ty->getNumElements()); @@ -685,11 +686,11 @@ public: /// Estimate the overhead of scalarizing an instructions unique /// non-constant operands. The (potentially vector) types to use for each of /// argument are passes via Tys. - unsigned getOperandsScalarizationOverhead(ArrayRef Args, - ArrayRef Tys) { + InstructionCost getOperandsScalarizationOverhead(ArrayRef Args, + ArrayRef Tys) { assert(Args.size() == Tys.size() && "Expected matching Args and Tys"); - unsigned Cost = 0; + InstructionCost Cost = 0; SmallPtrSet UniqueOperands; for (int I = 0, E = Args.size(); I != E; I++) { // Disregard things like metadata arguments. @@ -712,12 +713,10 @@ public: /// instruction, with return type RetTy and arguments Args of type Tys. If /// Args are unknown (empty), then the cost associated with one argument is /// added as a heuristic. - unsigned getScalarizationOverhead(VectorType *RetTy, - ArrayRef Args, - ArrayRef Tys) { - unsigned Cost = 0; - - Cost += getScalarizationOverhead(RetTy, true, false); + InstructionCost getScalarizationOverhead(VectorType *RetTy, + ArrayRef Args, + ArrayRef Tys) { + InstructionCost Cost = getScalarizationOverhead(RetTy, true, false); if (!Args.empty()) Cost += getOperandsScalarizationOverhead(Args, Tys); else @@ -756,7 +755,7 @@ public: bool IsFloat = Ty->isFPOrFPVectorTy(); // Assume that floating point arithmetic operations cost twice as much as // integer operations. - unsigned OpCost = (IsFloat ? 2 : 1); + InstructionCost OpCost = (IsFloat ? 2 : 1); if (TLI->isOperationLegalOrPromote(ISD, LT.second)) { // The operation is legal. Assume it costs 1. diff --git a/lib/Analysis/TargetTransformInfo.cpp b/lib/Analysis/TargetTransformInfo.cpp index bb134415e8c..40f0fb70247 100644 --- a/lib/Analysis/TargetTransformInfo.cpp +++ b/lib/Analysis/TargetTransformInfo.cpp @@ -470,14 +470,14 @@ bool TargetTransformInfo::useColdCCForColdCall(Function &F) const { return TTIImpl->useColdCCForColdCall(F); } -unsigned +InstructionCost TargetTransformInfo::getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract) const { return TTIImpl->getScalarizationOverhead(Ty, DemandedElts, Insert, Extract); } -unsigned TargetTransformInfo::getOperandsScalarizationOverhead( +InstructionCost TargetTransformInfo::getOperandsScalarizationOverhead( ArrayRef Args, ArrayRef Tys) const { return TTIImpl->getOperandsScalarizationOverhead(Args, Tys); } diff --git a/lib/Target/ARM/ARMTargetTransformInfo.cpp b/lib/Target/ARM/ARMTargetTransformInfo.cpp index df18fea092d..dad237c43e9 100644 --- a/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -1514,9 +1514,9 @@ InstructionCost ARMTTIImpl::getGatherScatterOpCost( NumElems * LT.first * ST->getMVEVectorCostFactor(CostKind); // The scalarization cost should be a lot higher. We use the number of vector // elements plus the scalarization overhead. - unsigned ScalarCost = NumElems * LT.first + - BaseT::getScalarizationOverhead(VTy, true, false) + - BaseT::getScalarizationOverhead(VTy, false, true); + InstructionCost ScalarCost = + NumElems * LT.first + BaseT::getScalarizationOverhead(VTy, true, false) + + BaseT::getScalarizationOverhead(VTy, false, true); if (EltSize < 8 || Alignment < EltSize / 8) return ScalarCost; diff --git a/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp b/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp index 96f1597bebe..93fb06c8315 100644 --- a/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp +++ b/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp @@ -122,13 +122,12 @@ ElementCount HexagonTTIImpl::getMinimumVF(unsigned ElemWidth, return ElementCount::getFixed((8 * ST.getVectorLength()) / ElemWidth); } -unsigned HexagonTTIImpl::getScalarizationOverhead(VectorType *Ty, - const APInt &DemandedElts, - bool Insert, bool Extract) { +InstructionCost HexagonTTIImpl::getScalarizationOverhead( + VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract) { return BaseT::getScalarizationOverhead(Ty, DemandedElts, Insert, Extract); } -unsigned +InstructionCost HexagonTTIImpl::getOperandsScalarizationOverhead(ArrayRef Args, ArrayRef Tys) { return BaseT::getOperandsScalarizationOverhead(Args, Tys); diff --git a/lib/Target/Hexagon/HexagonTargetTransformInfo.h b/lib/Target/Hexagon/HexagonTargetTransformInfo.h index fe799e81d4c..2144fb27eb6 100644 --- a/lib/Target/Hexagon/HexagonTargetTransformInfo.h +++ b/lib/Target/Hexagon/HexagonTargetTransformInfo.h @@ -104,10 +104,11 @@ public: return true; } - unsigned getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, - bool Insert, bool Extract); - unsigned getOperandsScalarizationOverhead(ArrayRef Args, - ArrayRef Tys); + InstructionCost getScalarizationOverhead(VectorType *Ty, + const APInt &DemandedElts, + bool Insert, bool Extract); + InstructionCost getOperandsScalarizationOverhead(ArrayRef Args, + ArrayRef Tys); InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef Tys, TTI::TargetCostKind CostKind); diff --git a/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp b/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp index 41fdf078c65..c08d9a23ae4 100644 --- a/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp +++ b/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp @@ -541,7 +541,7 @@ InstructionCost SystemZTTIImpl::getArithmeticInstrCost( // There is no native support for FRem. if (Opcode == Instruction::FRem) { SmallVector Tys(Args.size(), Ty); - unsigned Cost = + InstructionCost Cost = (VF * LIBCALL_COST) + getScalarizationOverhead(VTy, Args, Tys); // FIXME: VF 2 for float is currently just as expensive as for VF 4. if (VF == 2 && ScalarBits == 32) diff --git a/lib/Target/X86/X86TargetTransformInfo.cpp b/lib/Target/X86/X86TargetTransformInfo.cpp index e04118d9356..685b44c3d00 100644 --- a/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/lib/Target/X86/X86TargetTransformInfo.cpp @@ -3121,10 +3121,11 @@ InstructionCost X86TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, return BaseT::getVectorInstrCost(Opcode, Val, Index) + RegisterFileMoveCost; } -unsigned X86TTIImpl::getScalarizationOverhead(VectorType *Ty, - const APInt &DemandedElts, - bool Insert, bool Extract) { - unsigned Cost = 0; +InstructionCost X86TTIImpl::getScalarizationOverhead(VectorType *Ty, + const APInt &DemandedElts, + bool Insert, + bool Extract) { + InstructionCost Cost = 0; // For insertions, a ISD::BUILD_VECTOR style vector initialization can be much // cheaper than an accumulation of ISD::INSERT_VECTOR_ELT. diff --git a/lib/Target/X86/X86TargetTransformInfo.h b/lib/Target/X86/X86TargetTransformInfo.h index a2a750988c4..b45c94d24e6 100644 --- a/lib/Target/X86/X86TargetTransformInfo.h +++ b/lib/Target/X86/X86TargetTransformInfo.h @@ -140,8 +140,9 @@ public: const Instruction *I = nullptr); InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index); - unsigned getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, - bool Insert, bool Extract); + InstructionCost getScalarizationOverhead(VectorType *Ty, + const APInt &DemandedElts, + bool Insert, bool Extract); InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,