[TTI] NFC: Change getArithmeticInstrCost to return InstructionCost

This patch migrates the TTI cost interfaces to return an InstructionCost.

See this patch for the introduction of the type: https://reviews.llvm.org/D91174
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2020-November/146408.html

Reviewed By: dmgreen

Differential Revision: https://reviews.llvm.org/D100317
This commit is contained in:
Sander de Smalen 2021-04-14 16:53:01 +01:00
parent d84bd951a8
commit 4f42d873c2
23 changed files with 110 additions and 131 deletions

View File

@ -1036,7 +1036,7 @@ public:
/// cases or optimizations based on those values. /// cases or optimizations based on those values.
/// \p CxtI is the optional original context instruction, if one exists, to /// \p CxtI is the optional original context instruction, if one exists, to
/// provide even more information. /// provide even more information.
int getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
OperandValueKind Opd1Info = OK_AnyValue, OperandValueKind Opd1Info = OK_AnyValue,
@ -1568,13 +1568,11 @@ public:
virtual bool enableWritePrefetching() const = 0; virtual bool enableWritePrefetching() const = 0;
virtual unsigned getMaxInterleaveFactor(unsigned VF) = 0; virtual unsigned getMaxInterleaveFactor(unsigned VF) = 0;
virtual unsigned getArithmeticInstrCost( virtual InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::TargetCostKind CostKind, OperandValueKind Opd1Info, OperandValueKind Opd2Info,
OperandValueKind Opd1Info, OperandValueProperties Opd1PropInfo, OperandValueProperties Opd2PropInfo,
OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) = 0;
OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI = nullptr) = 0;
virtual InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp, virtual InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp,
ArrayRef<int> Mask, int Index, ArrayRef<int> Mask, int Index,
VectorType *SubTp) = 0; VectorType *SubTp) = 0;
@ -2039,14 +2037,12 @@ public:
BlockFrequencyInfo *BFI) override { BlockFrequencyInfo *BFI) override {
return Impl.getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI); return Impl.getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI);
} }
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, InstructionCost getArithmeticInstrCost(
TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
OperandValueKind Opd1Info, OperandValueKind Opd1Info, OperandValueKind Opd2Info,
OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo, OperandValueProperties Opd2PropInfo,
OperandValueProperties Opd1PropInfo, ArrayRef<const Value *> Args,
OperandValueProperties Opd2PropInfo, const Instruction *CxtI = nullptr) override {
ArrayRef<const Value *> Args,
const Instruction *CxtI = nullptr) override {
return Impl.getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info, return Impl.getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI); Opd1PropInfo, Opd2PropInfo, Args, CxtI);
} }

View File

@ -441,14 +441,12 @@ public:
unsigned getMaxInterleaveFactor(unsigned VF) const { return 1; } unsigned getMaxInterleaveFactor(unsigned VF) const { return 1; }
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, InstructionCost getArithmeticInstrCost(
TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info,
TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, const Instruction *CxtI = nullptr) const {
ArrayRef<const Value *> Args,
const Instruction *CxtI = nullptr) const {
// FIXME: A number of transformation tests seem to require these values // FIXME: A number of transformation tests seem to require these values
// which seems a little odd for how arbitary there are. // which seems a little odd for how arbitary there are.
switch (Opcode) { switch (Opcode) {

View File

@ -680,7 +680,7 @@ public:
unsigned getMaxInterleaveFactor(unsigned VF) { return 1; } unsigned getMaxInterleaveFactor(unsigned VF) { return 1; }
unsigned getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,
@ -725,7 +725,7 @@ public:
// similarly to what getCastInstrCost() does. // similarly to what getCastInstrCost() does.
if (auto *VTy = dyn_cast<VectorType>(Ty)) { if (auto *VTy = dyn_cast<VectorType>(Ty)) {
unsigned Num = cast<FixedVectorType>(VTy)->getNumElements(); unsigned Num = cast<FixedVectorType>(VTy)->getNumElements();
unsigned Cost = thisT()->getArithmeticInstrCost( InstructionCost Cost = thisT()->getArithmeticInstrCost(
Opcode, VTy->getScalarType(), CostKind, Opd1Info, Opd2Info, Opcode, VTy->getScalarType(), CostKind, Opd1Info, Opd2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI); Opd1PropInfo, Opd2PropInfo, Args, CxtI);
// Return the cost of multiple scalar invocation plus the cost of // Return the cost of multiple scalar invocation plus the cost of

View File

@ -703,15 +703,14 @@ TargetTransformInfo::getOperandInfo(const Value *V,
return OpInfo; return OpInfo;
} }
int TargetTransformInfo::getArithmeticInstrCost( InstructionCost TargetTransformInfo::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
OperandValueKind Opd1Info, OperandValueKind Opd1Info, OperandValueKind Opd2Info,
OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo, OperandValueProperties Opd1PropInfo, OperandValueProperties Opd2PropInfo,
OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args, ArrayRef<const Value *> Args, const Instruction *CxtI) const {
const Instruction *CxtI) const { InstructionCost Cost =
int Cost = TTIImpl->getArithmeticInstrCost( TTIImpl->getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info,
Opcode, Ty, CostKind, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo, Opd1PropInfo, Opd2PropInfo, Args, CxtI);
Args, CxtI);
assert(Cost >= 0 && "TTI should not produce negative costs!"); assert(Cost >= 0 && "TTI should not produce negative costs!");
return Cost; return Cost;
} }

View File

@ -261,13 +261,13 @@ AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
break; break;
} }
case Intrinsic::experimental_stepvector: { case Intrinsic::experimental_stepvector: {
unsigned Cost = 1; // Cost of the `index' instruction InstructionCost Cost = 1; // Cost of the `index' instruction
auto LT = TLI->getTypeLegalizationCost(DL, RetTy); auto LT = TLI->getTypeLegalizationCost(DL, RetTy);
// Legalisation of illegal vectors involves an `index' instruction plus // Legalisation of illegal vectors involves an `index' instruction plus
// (LT.first - 1) vector adds. // (LT.first - 1) vector adds.
if (LT.first > 1) { if (LT.first > 1) {
Type *LegalVTy = EVT(LT.second).getTypeForEVT(RetTy->getContext()); Type *LegalVTy = EVT(LT.second).getTypeForEVT(RetTy->getContext());
unsigned AddCost = InstructionCost AddCost =
getArithmeticInstrCost(Instruction::Add, LegalVTy, CostKind); getArithmeticInstrCost(Instruction::Add, LegalVTy, CostKind);
Cost += AddCost * (LT.first - 1); Cost += AddCost * (LT.first - 1);
} }
@ -690,10 +690,10 @@ InstructionCost AArch64TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
return ST->getVectorInsertExtractBaseCost(); return ST->getVectorInsertExtractBaseCost();
} }
int AArch64TTIImpl::getArithmeticInstrCost( InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info,
TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
// TODO: Handle more cost kinds. // TODO: Handle more cost kinds.
@ -711,7 +711,7 @@ int AArch64TTIImpl::getArithmeticInstrCost(
// aren't present in the generated code and have a zero cost. By adding a // aren't present in the generated code and have a zero cost. By adding a
// widening overhead here, we attach the total cost of the combined operation // widening overhead here, we attach the total cost of the combined operation
// to the widening instruction. // to the widening instruction.
int Cost = 0; InstructionCost Cost = 0;
if (isWideningInstruction(Ty, Opcode, Args)) if (isWideningInstruction(Ty, Opcode, Args))
Cost += ST->getWideningBaseCost(); Cost += ST->getWideningBaseCost();
@ -755,18 +755,15 @@ int AArch64TTIImpl::getArithmeticInstrCost(
// Vector signed division by constant are expanded to the // Vector signed division by constant are expanded to the
// sequence MULHS + ADD/SUB + SRA + SRL + ADD, and unsigned division // sequence MULHS + ADD/SUB + SRA + SRL + ADD, and unsigned division
// to MULHS + SUB + SRL + ADD + SRL. // to MULHS + SUB + SRL + ADD + SRL.
int MulCost = getArithmeticInstrCost(Instruction::Mul, Ty, CostKind, InstructionCost MulCost = getArithmeticInstrCost(
Opd1Info, Opd2Info, Instruction::Mul, Ty, CostKind, Opd1Info, Opd2Info,
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None, TargetTransformInfo::OP_None);
TargetTransformInfo::OP_None); InstructionCost AddCost = getArithmeticInstrCost(
int AddCost = getArithmeticInstrCost(Instruction::Add, Ty, CostKind, Instruction::Add, Ty, CostKind, Opd1Info, Opd2Info,
Opd1Info, Opd2Info, TargetTransformInfo::OP_None, TargetTransformInfo::OP_None);
TargetTransformInfo::OP_None, InstructionCost ShrCost = getArithmeticInstrCost(
TargetTransformInfo::OP_None); Instruction::AShr, Ty, CostKind, Opd1Info, Opd2Info,
int ShrCost = getArithmeticInstrCost(Instruction::AShr, Ty, CostKind, TargetTransformInfo::OP_None, TargetTransformInfo::OP_None);
Opd1Info, Opd2Info,
TargetTransformInfo::OP_None,
TargetTransformInfo::OP_None);
return MulCost * 2 + AddCost * 2 + ShrCost * 2 + 1; return MulCost * 2 + AddCost * 2 + ShrCost * 2 + 1;
} }
} }
@ -1280,7 +1277,7 @@ InstructionCost AArch64TTIImpl::getArithmeticReductionCostSVE(
assert(!IsPairwise && "Cannot be pair wise to continue"); assert(!IsPairwise && "Cannot be pair wise to continue");
std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy); std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy);
int LegalizationCost = 0; InstructionCost LegalizationCost = 0;
if (LT.first > 1) { if (LT.first > 1) {
Type *LegalVTy = EVT(LT.second).getTypeForEVT(ValTy->getContext()); Type *LegalVTy = EVT(LT.second).getTypeForEVT(ValTy->getContext());
LegalizationCost = getArithmeticInstrCost(Opcode, LegalVTy, CostKind); LegalizationCost = getArithmeticInstrCost(Opcode, LegalVTy, CostKind);

View File

@ -156,7 +156,7 @@ public:
bool IsPairwiseForm, bool IsPairwiseForm,
TTI::TargetCostKind CostKind); TTI::TargetCostKind CostKind);
int getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,

View File

@ -510,14 +510,12 @@ bool GCNTTIImpl::getTgtMemIntrinsic(IntrinsicInst *Inst,
} }
} }
int GCNTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty, InstructionCost GCNTTIImpl::getArithmeticInstrCost(
TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info,
TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, const Instruction *CxtI) {
ArrayRef<const Value *> Args,
const Instruction *CxtI) {
EVT OrigTy = TLI->getValueType(DL, Ty); EVT OrigTy = TLI->getValueType(DL, Ty);
if (!OrigTy.isSimple()) { if (!OrigTy.isSimple()) {
// FIXME: We're having to query the throughput cost so that the basic // FIXME: We're having to query the throughput cost so that the basic
@ -557,7 +555,7 @@ int GCNTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
// similarly to what getCastInstrCost() does. // similarly to what getCastInstrCost() does.
if (auto *VTy = dyn_cast<VectorType>(Ty)) { if (auto *VTy = dyn_cast<VectorType>(Ty)) {
unsigned Num = cast<FixedVectorType>(VTy)->getNumElements(); unsigned Num = cast<FixedVectorType>(VTy)->getNumElements();
unsigned Cost = getArithmeticInstrCost( InstructionCost Cost = getArithmeticInstrCost(
Opcode, VTy->getScalarType(), CostKind, Opd1Info, Opd2Info, Opcode, VTy->getScalarType(), CostKind, Opd1Info, Opd2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI); Opd1PropInfo, Opd2PropInfo, Args, CxtI);
// Return the cost of multiple scalar invocation plus the cost of // Return the cost of multiple scalar invocation plus the cost of

View File

@ -153,7 +153,7 @@ public:
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const; bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const;
int getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,

View File

@ -1240,14 +1240,12 @@ InstructionCost ARMTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
return BaseCost * BaseT::getShuffleCost(Kind, Tp, Mask, Index, SubTp); return BaseCost * BaseT::getShuffleCost(Kind, Tp, Mask, Index, SubTp);
} }
int ARMTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty, InstructionCost ARMTTIImpl::getArithmeticInstrCost(
TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op2Info,
TTI::OperandValueKind Op2Info, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, const Instruction *CxtI) {
ArrayRef<const Value *> Args,
const Instruction *CxtI) {
int ISDOpcode = TLI->InstructionOpcodeToISD(Opcode); int ISDOpcode = TLI->InstructionOpcodeToISD(Opcode);
if (ST->isThumb() && CostKind == TTI::TCK_CodeSize && Ty->isIntegerTy(1)) { if (ST->isThumb() && CostKind == TTI::TCK_CodeSize && Ty->isIntegerTy(1)) {
// Make operations on i1 relatively expensive as this often involves // Make operations on i1 relatively expensive as this often involves
@ -1313,9 +1311,8 @@ int ARMTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
if (const auto *Entry = CostTableLookup(CostTbl, ISDOpcode, LT.second)) if (const auto *Entry = CostTableLookup(CostTbl, ISDOpcode, LT.second))
return LT.first * Entry->Cost; return LT.first * Entry->Cost;
int Cost = BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, InstructionCost Cost = BaseT::getArithmeticInstrCost(
Op2Info, Opcode, Ty, CostKind, Op1Info, Op2Info, Opd1PropInfo, Opd2PropInfo);
Opd1PropInfo, Opd2PropInfo);
// This is somewhat of a hack. The problem that we are facing is that SROA // This is somewhat of a hack. The problem that we are facing is that SROA
// creates a sequence of shift, and, or instructions to construct values. // creates a sequence of shift, and, or instructions to construct values.
@ -1374,8 +1371,8 @@ int ARMTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
// Else this is expand, assume that we need to scalarize this op. // Else this is expand, assume that we need to scalarize this op.
if (auto *VTy = dyn_cast<FixedVectorType>(Ty)) { if (auto *VTy = dyn_cast<FixedVectorType>(Ty)) {
unsigned Num = VTy->getNumElements(); unsigned Num = VTy->getNumElements();
unsigned Cost = getArithmeticInstrCost(Opcode, Ty->getScalarType(), InstructionCost Cost =
CostKind); getArithmeticInstrCost(Opcode, Ty->getScalarType(), CostKind);
// Return the cost of multiple scalar invocation plus the cost of // Return the cost of multiple scalar invocation plus the cost of
// inserting and extracting the values. // inserting and extracting the values.
SmallVector<Type *> Tys(Args.size(), Ty); SmallVector<Type *> Tys(Args.size(), Ty);

View File

@ -218,7 +218,7 @@ public:
int getAddressComputationCost(Type *Val, ScalarEvolution *SE, int getAddressComputationCost(Type *Val, ScalarEvolution *SE,
const SCEV *Ptr); const SCEV *Ptr);
int getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Op1Info = TTI::OK_AnyValue, TTI::OperandValueKind Op1Info = TTI::OK_AnyValue,

View File

@ -258,10 +258,10 @@ InstructionCost HexagonTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I); return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I);
} }
unsigned HexagonTTIImpl::getArithmeticInstrCost( InstructionCost HexagonTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info,
TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
// TODO: Handle more cost kinds. // TODO: Handle more cost kinds.

View File

@ -139,7 +139,7 @@ public:
CmpInst::Predicate VecPred, CmpInst::Predicate VecPred,
TTI::TargetCostKind CostKind, TTI::TargetCostKind CostKind,
const Instruction *I = nullptr); const Instruction *I = nullptr);
unsigned getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,

View File

@ -77,7 +77,7 @@ public:
return getIntImmCost(Imm, Ty, CostKind); return getIntImmCost(Imm, Ty, CostKind);
} }
unsigned getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,

View File

@ -368,10 +368,10 @@ NVPTXTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
return None; return None;
} }
int NVPTXTTIImpl::getArithmeticInstrCost( InstructionCost NVPTXTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info,
TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
// Legalize the type. // Legalize the type.

View File

@ -88,7 +88,7 @@ public:
// calls are particularly expensive in NVPTX. // calls are particularly expensive in NVPTX.
unsigned getInliningThresholdMultiplier() { return 5; } unsigned getInliningThresholdMultiplier() { return 5; }
int getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,

View File

@ -965,14 +965,12 @@ InstructionCost PPCTTIImpl::vectorCostAdjustment(InstructionCost Cost,
return Cost * 2; return Cost * 2;
} }
int PPCTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty, InstructionCost PPCTTIImpl::getArithmeticInstrCost(
TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op2Info,
TTI::OperandValueKind Op2Info, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, const Instruction *CxtI) {
ArrayRef<const Value *> Args,
const Instruction *CxtI) {
assert(TLI->InstructionOpcodeToISD(Opcode) && "Invalid opcode"); assert(TLI->InstructionOpcodeToISD(Opcode) && "Invalid opcode");
// TODO: Handle more cost kinds. // TODO: Handle more cost kinds.
if (CostKind != TTI::TCK_RecipThroughput) if (CostKind != TTI::TCK_RecipThroughput)
@ -981,10 +979,9 @@ int PPCTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
Opd2PropInfo, Args, CxtI); Opd2PropInfo, Args, CxtI);
// Fallback to the default implementation. // Fallback to the default implementation.
int Cost = BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, InstructionCost Cost = BaseT::getArithmeticInstrCost(
Op2Info, Opcode, Ty, CostKind, Op1Info, Op2Info, Opd1PropInfo, Opd2PropInfo);
Opd1PropInfo, Opd2PropInfo); return vectorCostAdjustment(Cost, Opcode, Ty, nullptr);
return *vectorCostAdjustment(Cost, Opcode, Ty, nullptr).getValue();
} }
InstructionCost PPCTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, InstructionCost PPCTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp,

View File

@ -99,7 +99,7 @@ public:
unsigned getMaxInterleaveFactor(unsigned VF); unsigned getMaxInterleaveFactor(unsigned VF);
InstructionCost vectorCostAdjustment(InstructionCost Cost, unsigned Opcode, InstructionCost vectorCostAdjustment(InstructionCost Cost, unsigned Opcode,
Type *Ty1, Type *Ty2); Type *Ty1, Type *Ty2);
int getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,

View File

@ -379,10 +379,10 @@ static unsigned getNumVectorRegs(Type *Ty) {
return ((WideBits % 128U) ? ((WideBits / 128U) + 1) : (WideBits / 128U)); return ((WideBits % 128U) ? ((WideBits / 128U) + 1) : (WideBits / 128U));
} }
int SystemZTTIImpl::getArithmeticInstrCost( InstructionCost SystemZTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op2Info,
TTI::OperandValueKind Op2Info, TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
@ -518,10 +518,10 @@ int SystemZTTIImpl::getArithmeticInstrCost(
return NumVectors; return NumVectors;
// Return the cost of multiple scalar invocation plus the cost of // Return the cost of multiple scalar invocation plus the cost of
// inserting and extracting the values. // inserting and extracting the values.
unsigned ScalarCost = InstructionCost ScalarCost =
getArithmeticInstrCost(Opcode, Ty->getScalarType(), CostKind); getArithmeticInstrCost(Opcode, Ty->getScalarType(), CostKind);
SmallVector<Type *> Tys(Args.size(), Ty); SmallVector<Type *> Tys(Args.size(), Ty);
unsigned Cost = InstructionCost Cost =
(VF * ScalarCost) + getScalarizationOverhead(VTy, Args, Tys); (VF * ScalarCost) + getScalarizationOverhead(VTy, Args, Tys);
// FIXME: VF 2 for these FP operations are currently just as // FIXME: VF 2 for these FP operations are currently just as
// expensive as for VF 4. // expensive as for VF 4.

View File

@ -78,7 +78,7 @@ public:
bool supportsEfficientVectorElementLoadStore() { return true; } bool supportsEfficientVectorElementLoadStore() { return true; }
bool enableInterleavedAccessVectorization() { return true; } bool enableInterleavedAccessVectorization() { return true; }
int getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,

View File

@ -50,15 +50,16 @@ TypeSize WebAssemblyTTIImpl::getRegisterBitWidth(
llvm_unreachable("Unsupported register kind"); llvm_unreachable("Unsupported register kind");
} }
unsigned WebAssemblyTTIImpl::getArithmeticInstrCost( InstructionCost WebAssemblyTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info,
TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
const Instruction *CxtI) { const Instruction *CxtI) {
unsigned Cost = BasicTTIImplBase<WebAssemblyTTIImpl>::getArithmeticInstrCost( InstructionCost Cost =
Opcode, Ty, CostKind, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo); BasicTTIImplBase<WebAssemblyTTIImpl>::getArithmeticInstrCost(
Opcode, Ty, CostKind, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo);
if (auto *VTy = dyn_cast<VectorType>(Ty)) { if (auto *VTy = dyn_cast<VectorType>(Ty)) {
switch (Opcode) { switch (Opcode) {

View File

@ -58,7 +58,7 @@ public:
unsigned getNumberOfRegisters(unsigned ClassID) const; unsigned getNumberOfRegisters(unsigned ClassID) const;
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const; TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const;
unsigned getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency, TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,

View File

@ -173,14 +173,12 @@ unsigned X86TTIImpl::getMaxInterleaveFactor(unsigned VF) {
return 2; return 2;
} }
int X86TTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty, InstructionCost X86TTIImpl::getArithmeticInstrCost(
TTI::TargetCostKind CostKind, unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op2Info,
TTI::OperandValueKind Op2Info, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args,
TTI::OperandValueProperties Opd2PropInfo, const Instruction *CxtI) {
ArrayRef<const Value *> Args,
const Instruction *CxtI) {
// TODO: Handle more cost kinds. // TODO: Handle more cost kinds.
if (CostKind != TTI::TCK_RecipThroughput) if (CostKind != TTI::TCK_RecipThroughput)
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
@ -265,10 +263,9 @@ int X86TTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
// normally expanded to the sequence SRA + SRL + ADD + SRA. // normally expanded to the sequence SRA + SRL + ADD + SRA.
// The OperandValue properties may not be the same as that of the previous // The OperandValue properties may not be the same as that of the previous
// operation; conservatively assume OP_None. // operation; conservatively assume OP_None.
int Cost = InstructionCost Cost =
2 * getArithmeticInstrCost(Instruction::AShr, Ty, CostKind, Op1Info, 2 * getArithmeticInstrCost(Instruction::AShr, Ty, CostKind, Op1Info,
Op2Info, Op2Info, TargetTransformInfo::OP_None,
TargetTransformInfo::OP_None,
TargetTransformInfo::OP_None); TargetTransformInfo::OP_None);
Cost += getArithmeticInstrCost(Instruction::LShr, Ty, CostKind, Op1Info, Cost += getArithmeticInstrCost(Instruction::LShr, Ty, CostKind, Op1Info,
Op2Info, Op2Info,
@ -953,7 +950,7 @@ int X86TTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
// to hide "20 cycles" for each lane. // to hide "20 cycles" for each lane.
if (LT.second.isVector() && (ISD == ISD::SDIV || ISD == ISD::SREM || if (LT.second.isVector() && (ISD == ISD::SDIV || ISD == ISD::SREM ||
ISD == ISD::UDIV || ISD == ISD::UREM)) { ISD == ISD::UDIV || ISD == ISD::UREM)) {
int ScalarCost = getArithmeticInstrCost( InstructionCost ScalarCost = getArithmeticInstrCost(
Opcode, Ty->getScalarType(), CostKind, Op1Info, Op2Info, Opcode, Ty->getScalarType(), CostKind, Op1Info, Op2Info,
TargetTransformInfo::OP_None, TargetTransformInfo::OP_None); TargetTransformInfo::OP_None, TargetTransformInfo::OP_None);
return 20 * LT.first * LT.second.getVectorNumElements() * ScalarCost; return 20 * LT.first * LT.second.getVectorNumElements() * ScalarCost;
@ -3419,14 +3416,13 @@ X86TTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *ValTy,
if (ISD == ISD::MUL && MTy.getScalarType() == MVT::i8) { if (ISD == ISD::MUL && MTy.getScalarType() == MVT::i8) {
auto *WideSclTy = IntegerType::get(ValVTy->getContext(), 16); auto *WideSclTy = IntegerType::get(ValVTy->getContext(), 16);
auto *WideVecTy = FixedVectorType::get(WideSclTy, ValVTy->getNumElements()); auto *WideVecTy = FixedVectorType::get(WideSclTy, ValVTy->getNumElements());
return *getCastInstrCost(Instruction::ZExt, WideVecTy, ValTy, return getCastInstrCost(Instruction::ZExt, WideVecTy, ValTy,
TargetTransformInfo::CastContextHint::None, TargetTransformInfo::CastContextHint::None,
CostKind) CostKind) +
.getValue() +
getArithmeticReductionCost(Opcode, WideVecTy, IsPairwise, CostKind); getArithmeticReductionCost(Opcode, WideVecTy, IsPairwise, CostKind);
} }
unsigned ArithmeticCost = 0; InstructionCost ArithmeticCost = 0;
if (LT.first != 1 && MTy.isVector() && if (LT.first != 1 && MTy.isVector() &&
MTy.getVectorNumElements() < ValVTy->getNumElements()) { MTy.getVectorNumElements() < ValVTy->getNumElements()) {
// Type needs to be split. We need LT.first - 1 arithmetic ops. // Type needs to be split. We need LT.first - 1 arithmetic ops.
@ -3496,7 +3492,7 @@ X86TTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *ValTy,
// Handle bool allof/anyof patterns. // Handle bool allof/anyof patterns.
if (ValVTy->getElementType()->isIntegerTy(1)) { if (ValVTy->getElementType()->isIntegerTy(1)) {
unsigned ArithmeticCost = 0; InstructionCost ArithmeticCost = 0;
if (LT.first != 1 && MTy.isVector() && if (LT.first != 1 && MTy.isVector() &&
MTy.getVectorNumElements() < ValVTy->getNumElements()) { MTy.getVectorNumElements() < ValVTy->getNumElements()) {
// Type needs to be split. We need LT.first - 1 arithmetic ops. // Type needs to be split. We need LT.first - 1 arithmetic ops.

View File

@ -118,7 +118,7 @@ public:
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const; TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const;
unsigned getLoadStoreVecRegBitWidth(unsigned AS) const; unsigned getLoadStoreVecRegBitWidth(unsigned AS) const;
unsigned getMaxInterleaveFactor(unsigned VF); unsigned getMaxInterleaveFactor(unsigned VF);
int getArithmeticInstrCost( InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty, unsigned Opcode, Type *Ty,
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,