NFC: Change getUserCost 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

Depends on D97382

Reviewed By: ctetreau, paulwalker-arm

Differential Revision: https://reviews.llvm.org/D97466
This commit is contained in:
Sander de Smalen 2021-01-20 17:17:23 +00:00
parent 49c0ab6d76
commit 3ccbd4f3c7
10 changed files with 47 additions and 44 deletions

View File

@ -317,12 +317,12 @@ public:
/// ///
/// The returned cost is defined in terms of \c TargetCostConstants, see its /// The returned cost is defined in terms of \c TargetCostConstants, see its
/// comments for a detailed explanation of the cost values. /// comments for a detailed explanation of the cost values.
int getUserCost(const User *U, ArrayRef<const Value *> Operands, InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
TargetCostKind CostKind) const; TargetCostKind CostKind) const;
/// This is a helper function which calls the two-argument getUserCost /// This is a helper function which calls the two-argument getUserCost
/// with \p Operands which are the current operands U has. /// with \p Operands which are the current operands U has.
int getUserCost(const User *U, TargetCostKind CostKind) const { InstructionCost getUserCost(const User *U, TargetCostKind CostKind) const {
SmallVector<const Value *, 4> Operands(U->operand_values()); SmallVector<const Value *, 4> Operands(U->operand_values());
return getUserCost(U, Operands, CostKind); return getUserCost(U, Operands, CostKind);
} }
@ -1371,11 +1371,11 @@ public:
private: private:
/// Estimate the latency of specified instruction. /// Estimate the latency of specified instruction.
/// Returns 1 as the default value. /// Returns 1 as the default value.
int getInstructionLatency(const Instruction *I) const; InstructionCost getInstructionLatency(const Instruction *I) const;
/// Returns the expected throughput cost of the instruction. /// Returns the expected throughput cost of the instruction.
/// Returns -1 if the cost is unknown. /// Returns -1 if the cost is unknown.
int getInstructionThroughput(const Instruction *I) const; InstructionCost getInstructionThroughput(const Instruction *I) const;
/// The abstract base class used to type erase specific TTI /// The abstract base class used to type erase specific TTI
/// implementations. /// implementations.
@ -1403,7 +1403,8 @@ public:
getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize, getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize,
ProfileSummaryInfo *PSI, ProfileSummaryInfo *PSI,
BlockFrequencyInfo *BFI) = 0; BlockFrequencyInfo *BFI) = 0;
virtual int getUserCost(const User *U, ArrayRef<const Value *> Operands, virtual InstructionCost getUserCost(const User *U,
ArrayRef<const Value *> Operands,
TargetCostKind CostKind) = 0; TargetCostKind CostKind) = 0;
virtual BranchProbability getPredictableBranchThreshold() = 0; virtual BranchProbability getPredictableBranchThreshold() = 0;
virtual bool hasBranchDivergence() = 0; virtual bool hasBranchDivergence() = 0;
@ -1661,7 +1662,7 @@ public:
virtual unsigned getGISelRematGlobalCost() const = 0; virtual unsigned getGISelRematGlobalCost() const = 0;
virtual bool supportsScalableVectors() const = 0; virtual bool supportsScalableVectors() const = 0;
virtual bool hasActiveVectorLength() const = 0; virtual bool hasActiveVectorLength() const = 0;
virtual int getInstructionLatency(const Instruction *I) = 0; virtual InstructionCost getInstructionLatency(const Instruction *I) = 0;
}; };
template <typename T> template <typename T>
@ -1693,7 +1694,7 @@ public:
int getMemcpyCost(const Instruction *I) override { int getMemcpyCost(const Instruction *I) override {
return Impl.getMemcpyCost(I); return Impl.getMemcpyCost(I);
} }
int getUserCost(const User *U, ArrayRef<const Value *> Operands, InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
TargetCostKind CostKind) override { TargetCostKind CostKind) override {
return Impl.getUserCost(U, Operands, CostKind); return Impl.getUserCost(U, Operands, CostKind);
} }
@ -2214,7 +2215,7 @@ public:
return Impl.hasActiveVectorLength(); return Impl.hasActiveVectorLength();
} }
int getInstructionLatency(const Instruction *I) override { InstructionCost getInstructionLatency(const Instruction *I) override {
return Impl.getInstructionLatency(I); return Impl.getInstructionLatency(I);
} }
}; };

View File

@ -899,7 +899,7 @@ public:
return TTI::TCC_Basic; return TTI::TCC_Basic;
} }
int getUserCost(const User *U, ArrayRef<const Value *> Operands, InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
TTI::TargetCostKind CostKind) { TTI::TargetCostKind CostKind) {
auto *TargetTTI = static_cast<T *>(this); auto *TargetTTI = static_cast<T *>(this);
// Handle non-intrinsic calls, invokes, and callbr. // Handle non-intrinsic calls, invokes, and callbr.
@ -1119,7 +1119,7 @@ public:
return TTI::TCC_Basic; return TTI::TCC_Basic;
} }
int getInstructionLatency(const Instruction *I) { InstructionCost getInstructionLatency(const Instruction *I) {
SmallVector<const Value *, 4> Operands(I->operand_values()); SmallVector<const Value *, 4> Operands(I->operand_values());
if (getUserCost(I, Operands, TTI::TCK_Latency) == TTI::TCC_Free) if (getUserCost(I, Operands, TTI::TCK_Latency) == TTI::TCC_Free)
return 0; return 0;

View File

@ -517,7 +517,7 @@ public:
SimplifyAndSetOp); SimplifyAndSetOp);
} }
int getInstructionLatency(const Instruction *I) { InstructionCost getInstructionLatency(const Instruction *I) {
if (isa<LoadInst>(I)) if (isa<LoadInst>(I))
return getST()->getSchedModel().DefaultLoadLatency; return getST()->getSchedModel().DefaultLoadLatency;

View File

@ -1037,9 +1037,9 @@ bool CallAnalyzer::isGEPFree(GetElementPtrInst &GEP) {
Operands.push_back(SimpleOp); Operands.push_back(SimpleOp);
else else
Operands.push_back(Op); Operands.push_back(Op);
return TargetTransformInfo::TCC_Free == return TTI.getUserCost(&GEP, Operands,
TTI.getUserCost(&GEP, Operands, TargetTransformInfo::TCK_SizeAndLatency) ==
TargetTransformInfo::TCK_SizeAndLatency); TargetTransformInfo::TCC_Free;
} }
bool CallAnalyzer::visitAlloca(AllocaInst &I) { bool CallAnalyzer::visitAlloca(AllocaInst &I) {
@ -1309,8 +1309,8 @@ bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) {
if (auto *SROAArg = getSROAArgForValueOrNull(I.getOperand(0))) if (auto *SROAArg = getSROAArgForValueOrNull(I.getOperand(0)))
SROAArgValues[&I] = SROAArg; SROAArgValues[&I] = SROAArg;
return TargetTransformInfo::TCC_Free == return TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency) ==
TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency); TargetTransformInfo::TCC_Free;
} }
bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) { bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
@ -1334,8 +1334,8 @@ bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
if (auto *SROAArg = getSROAArgForValueOrNull(Op)) if (auto *SROAArg = getSROAArgForValueOrNull(Op))
SROAArgValues[&I] = SROAArg; SROAArgValues[&I] = SROAArg;
return TargetTransformInfo::TCC_Free == return TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency) ==
TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency); TargetTransformInfo::TCC_Free;
} }
bool CallAnalyzer::visitCastInst(CastInst &I) { bool CallAnalyzer::visitCastInst(CastInst &I) {
@ -1366,8 +1366,8 @@ bool CallAnalyzer::visitCastInst(CastInst &I) {
break; break;
} }
return TargetTransformInfo::TCC_Free == return TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency) ==
TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency); TargetTransformInfo::TCC_Free;
} }
bool CallAnalyzer::visitUnaryInstruction(UnaryInstruction &I) { bool CallAnalyzer::visitUnaryInstruction(UnaryInstruction &I) {
@ -2071,8 +2071,8 @@ bool CallAnalyzer::visitUnreachableInst(UnreachableInst &I) {
bool CallAnalyzer::visitInstruction(Instruction &I) { bool CallAnalyzer::visitInstruction(Instruction &I) {
// Some instructions are free. All of the free intrinsics can also be // Some instructions are free. All of the free intrinsics can also be
// handled by SROA, etc. // handled by SROA, etc.
if (TargetTransformInfo::TCC_Free == if (TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency) ==
TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency)) TargetTransformInfo::TCC_Free)
return true; return true;
// We found something we don't understand or can't handle. Mark any SROA-able // We found something we don't understand or can't handle. Mark any SROA-able

View File

@ -219,10 +219,11 @@ unsigned TargetTransformInfo::getEstimatedNumberOfCaseClusters(
return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI); return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI);
} }
int TargetTransformInfo::getUserCost(const User *U, InstructionCost
TargetTransformInfo::getUserCost(const User *U,
ArrayRef<const Value *> Operands, ArrayRef<const Value *> Operands,
enum TargetCostKind CostKind) const { enum TargetCostKind CostKind) const {
int Cost = TTIImpl->getUserCost(U, Operands, CostKind); InstructionCost Cost = TTIImpl->getUserCost(U, Operands, CostKind);
assert((CostKind == TTI::TCK_RecipThroughput || Cost >= 0) && assert((CostKind == TTI::TCK_RecipThroughput || Cost >= 0) &&
"TTI should not produce negative costs!"); "TTI should not produce negative costs!");
return Cost; return Cost;
@ -1032,7 +1033,8 @@ bool TargetTransformInfo::supportsScalableVectors() const {
return TTIImpl->supportsScalableVectors(); return TTIImpl->supportsScalableVectors();
} }
int TargetTransformInfo::getInstructionLatency(const Instruction *I) const { InstructionCost
TargetTransformInfo::getInstructionLatency(const Instruction *I) const {
return TTIImpl->getInstructionLatency(I); return TTIImpl->getInstructionLatency(I);
} }
@ -1321,7 +1323,8 @@ TTI::matchVectorReduction(const ExtractElementInst *Root, unsigned &Opcode,
return matchPairwiseReduction(Root, Opcode, Ty); return matchPairwiseReduction(Root, Opcode, Ty);
} }
int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const { InstructionCost
TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
switch (I->getOpcode()) { switch (I->getOpcode()) {

View File

@ -2165,7 +2165,7 @@ void ARMTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
// Scan the loop: don't unroll loops with calls as this could prevent // Scan the loop: don't unroll loops with calls as this could prevent
// inlining. // inlining.
unsigned Cost = 0; InstructionCost Cost = 0;
for (auto *BB : L->getBlocks()) { for (auto *BB : L->getBlocks()) {
for (auto &I : *BB) { for (auto &I : *BB) {
// Don't unroll vectorised loop. MVE does not benefit from it as much as // Don't unroll vectorised loop. MVE does not benefit from it as much as

View File

@ -334,8 +334,7 @@ unsigned HexagonTTIImpl::getCacheLineSize() const {
return ST.getL1CacheLineSize(); return ST.getL1CacheLineSize();
} }
int InstructionCost HexagonTTIImpl::getUserCost(const User *U,
HexagonTTIImpl::getUserCost(const User *U,
ArrayRef<const Value *> Operands, ArrayRef<const Value *> Operands,
TTI::TargetCostKind CostKind) { TTI::TargetCostKind CostKind) {
auto isCastFoldedIntoLoad = [this](const CastInst *CI) -> bool { auto isCastFoldedIntoLoad = [this](const CastInst *CI) -> bool {

View File

@ -162,7 +162,7 @@ public:
/// @} /// @}
int getUserCost(const User *U, ArrayRef<const Value *> Operands, InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
TTI::TargetCostKind CostKind); TTI::TargetCostKind CostKind);
// Hexagon specific decision to generate a lookup table. // Hexagon specific decision to generate a lookup table.

View File

@ -318,8 +318,8 @@ int PPCTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
return PPCTTIImpl::getIntImmCost(Imm, Ty, CostKind); return PPCTTIImpl::getIntImmCost(Imm, Ty, CostKind);
} }
unsigned InstructionCost PPCTTIImpl::getUserCost(const User *U,
PPCTTIImpl::getUserCost(const User *U, ArrayRef<const Value *> Operands, ArrayRef<const Value *> Operands,
TTI::TargetCostKind CostKind) { TTI::TargetCostKind CostKind) {
// We already implement getCastInstrCost and getMemoryOpCost where we perform // We already implement getCastInstrCost and getMemoryOpCost where we perform
// the vector adjustment there. // the vector adjustment there.

View File

@ -57,7 +57,7 @@ public:
int getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, int getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
Type *Ty, TTI::TargetCostKind CostKind); Type *Ty, TTI::TargetCostKind CostKind);
unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands, InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
TTI::TargetCostKind CostKind); TTI::TargetCostKind CostKind);
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth); TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);