Skip to content

Commit 3ccbd4f

Browse files
committed
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
1 parent 49c0ab6 commit 3ccbd4f

10 files changed

+47
-44
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,12 @@ class TargetTransformInfo {
317317
///
318318
/// The returned cost is defined in terms of \c TargetCostConstants, see its
319319
/// comments for a detailed explanation of the cost values.
320-
int getUserCost(const User *U, ArrayRef<const Value *> Operands,
321-
TargetCostKind CostKind) const;
320+
InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
321+
TargetCostKind CostKind) const;
322322

323323
/// This is a helper function which calls the two-argument getUserCost
324324
/// with \p Operands which are the current operands U has.
325-
int getUserCost(const User *U, TargetCostKind CostKind) const {
325+
InstructionCost getUserCost(const User *U, TargetCostKind CostKind) const {
326326
SmallVector<const Value *, 4> Operands(U->operand_values());
327327
return getUserCost(U, Operands, CostKind);
328328
}
@@ -1371,11 +1371,11 @@ class TargetTransformInfo {
13711371
private:
13721372
/// Estimate the latency of specified instruction.
13731373
/// Returns 1 as the default value.
1374-
int getInstructionLatency(const Instruction *I) const;
1374+
InstructionCost getInstructionLatency(const Instruction *I) const;
13751375

13761376
/// Returns the expected throughput cost of the instruction.
13771377
/// Returns -1 if the cost is unknown.
1378-
int getInstructionThroughput(const Instruction *I) const;
1378+
InstructionCost getInstructionThroughput(const Instruction *I) const;
13791379

13801380
/// The abstract base class used to type erase specific TTI
13811381
/// implementations.
@@ -1403,8 +1403,9 @@ class TargetTransformInfo::Concept {
14031403
getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize,
14041404
ProfileSummaryInfo *PSI,
14051405
BlockFrequencyInfo *BFI) = 0;
1406-
virtual int getUserCost(const User *U, ArrayRef<const Value *> Operands,
1407-
TargetCostKind CostKind) = 0;
1406+
virtual InstructionCost getUserCost(const User *U,
1407+
ArrayRef<const Value *> Operands,
1408+
TargetCostKind CostKind) = 0;
14081409
virtual BranchProbability getPredictableBranchThreshold() = 0;
14091410
virtual bool hasBranchDivergence() = 0;
14101411
virtual bool useGPUDivergenceAnalysis() = 0;
@@ -1661,7 +1662,7 @@ class TargetTransformInfo::Concept {
16611662
virtual unsigned getGISelRematGlobalCost() const = 0;
16621663
virtual bool supportsScalableVectors() const = 0;
16631664
virtual bool hasActiveVectorLength() const = 0;
1664-
virtual int getInstructionLatency(const Instruction *I) = 0;
1665+
virtual InstructionCost getInstructionLatency(const Instruction *I) = 0;
16651666
};
16661667

16671668
template <typename T>
@@ -1693,8 +1694,8 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
16931694
int getMemcpyCost(const Instruction *I) override {
16941695
return Impl.getMemcpyCost(I);
16951696
}
1696-
int getUserCost(const User *U, ArrayRef<const Value *> Operands,
1697-
TargetCostKind CostKind) override {
1697+
InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
1698+
TargetCostKind CostKind) override {
16981699
return Impl.getUserCost(U, Operands, CostKind);
16991700
}
17001701
BranchProbability getPredictableBranchThreshold() override {
@@ -2214,7 +2215,7 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
22142215
return Impl.hasActiveVectorLength();
22152216
}
22162217

2217-
int getInstructionLatency(const Instruction *I) override {
2218+
InstructionCost getInstructionLatency(const Instruction *I) override {
22182219
return Impl.getInstructionLatency(I);
22192220
}
22202221
};

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
899899
return TTI::TCC_Basic;
900900
}
901901

902-
int getUserCost(const User *U, ArrayRef<const Value *> Operands,
903-
TTI::TargetCostKind CostKind) {
902+
InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
903+
TTI::TargetCostKind CostKind) {
904904
auto *TargetTTI = static_cast<T *>(this);
905905
// Handle non-intrinsic calls, invokes, and callbr.
906906
// FIXME: Unlikely to be true for anything but CodeSize.
@@ -1119,7 +1119,7 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
11191119
return TTI::TCC_Basic;
11201120
}
11211121

1122-
int getInstructionLatency(const Instruction *I) {
1122+
InstructionCost getInstructionLatency(const Instruction *I) {
11231123
SmallVector<const Value *, 4> Operands(I->operand_values());
11241124
if (getUserCost(I, Operands, TTI::TCK_Latency) == TTI::TCC_Free)
11251125
return 0;

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
517517
SimplifyAndSetOp);
518518
}
519519

520-
int getInstructionLatency(const Instruction *I) {
520+
InstructionCost getInstructionLatency(const Instruction *I) {
521521
if (isa<LoadInst>(I))
522522
return getST()->getSchedModel().DefaultLoadLatency;
523523

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,9 +1037,9 @@ bool CallAnalyzer::isGEPFree(GetElementPtrInst &GEP) {
10371037
Operands.push_back(SimpleOp);
10381038
else
10391039
Operands.push_back(Op);
1040-
return TargetTransformInfo::TCC_Free ==
1041-
TTI.getUserCost(&GEP, Operands,
1042-
TargetTransformInfo::TCK_SizeAndLatency);
1040+
return TTI.getUserCost(&GEP, Operands,
1041+
TargetTransformInfo::TCK_SizeAndLatency) ==
1042+
TargetTransformInfo::TCC_Free;
10431043
}
10441044

10451045
bool CallAnalyzer::visitAlloca(AllocaInst &I) {
@@ -1309,8 +1309,8 @@ bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) {
13091309
if (auto *SROAArg = getSROAArgForValueOrNull(I.getOperand(0)))
13101310
SROAArgValues[&I] = SROAArg;
13111311

1312-
return TargetTransformInfo::TCC_Free ==
1313-
TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency);
1312+
return TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency) ==
1313+
TargetTransformInfo::TCC_Free;
13141314
}
13151315

13161316
bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
@@ -1334,8 +1334,8 @@ bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
13341334
if (auto *SROAArg = getSROAArgForValueOrNull(Op))
13351335
SROAArgValues[&I] = SROAArg;
13361336

1337-
return TargetTransformInfo::TCC_Free ==
1338-
TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency);
1337+
return TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency) ==
1338+
TargetTransformInfo::TCC_Free;
13391339
}
13401340

13411341
bool CallAnalyzer::visitCastInst(CastInst &I) {
@@ -1366,8 +1366,8 @@ bool CallAnalyzer::visitCastInst(CastInst &I) {
13661366
break;
13671367
}
13681368

1369-
return TargetTransformInfo::TCC_Free ==
1370-
TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency);
1369+
return TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency) ==
1370+
TargetTransformInfo::TCC_Free;
13711371
}
13721372

13731373
bool CallAnalyzer::visitUnaryInstruction(UnaryInstruction &I) {
@@ -2071,8 +2071,8 @@ bool CallAnalyzer::visitUnreachableInst(UnreachableInst &I) {
20712071
bool CallAnalyzer::visitInstruction(Instruction &I) {
20722072
// Some instructions are free. All of the free intrinsics can also be
20732073
// handled by SROA, etc.
2074-
if (TargetTransformInfo::TCC_Free ==
2075-
TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency))
2074+
if (TTI.getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency) ==
2075+
TargetTransformInfo::TCC_Free)
20762076
return true;
20772077

20782078
// We found something we don't understand or can't handle. Mark any SROA-able

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,11 @@ unsigned TargetTransformInfo::getEstimatedNumberOfCaseClusters(
219219
return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI);
220220
}
221221

222-
int TargetTransformInfo::getUserCost(const User *U,
223-
ArrayRef<const Value *> Operands,
224-
enum TargetCostKind CostKind) const {
225-
int Cost = TTIImpl->getUserCost(U, Operands, CostKind);
222+
InstructionCost
223+
TargetTransformInfo::getUserCost(const User *U,
224+
ArrayRef<const Value *> Operands,
225+
enum TargetCostKind CostKind) const {
226+
InstructionCost Cost = TTIImpl->getUserCost(U, Operands, CostKind);
226227
assert((CostKind == TTI::TCK_RecipThroughput || Cost >= 0) &&
227228
"TTI should not produce negative costs!");
228229
return Cost;
@@ -1032,7 +1033,8 @@ bool TargetTransformInfo::supportsScalableVectors() const {
10321033
return TTIImpl->supportsScalableVectors();
10331034
}
10341035

1035-
int TargetTransformInfo::getInstructionLatency(const Instruction *I) const {
1036+
InstructionCost
1037+
TargetTransformInfo::getInstructionLatency(const Instruction *I) const {
10361038
return TTIImpl->getInstructionLatency(I);
10371039
}
10381040

@@ -1321,7 +1323,8 @@ TTI::matchVectorReduction(const ExtractElementInst *Root, unsigned &Opcode,
13211323
return matchPairwiseReduction(Root, Opcode, Ty);
13221324
}
13231325

1324-
int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
1326+
InstructionCost
1327+
TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
13251328
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
13261329

13271330
switch (I->getOpcode()) {

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ void ARMTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
21652165

21662166
// Scan the loop: don't unroll loops with calls as this could prevent
21672167
// inlining.
2168-
unsigned Cost = 0;
2168+
InstructionCost Cost = 0;
21692169
for (auto *BB : L->getBlocks()) {
21702170
for (auto &I : *BB) {
21712171
// Don't unroll vectorised loop. MVE does not benefit from it as much as

llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,9 @@ unsigned HexagonTTIImpl::getCacheLineSize() const {
334334
return ST.getL1CacheLineSize();
335335
}
336336

337-
int
338-
HexagonTTIImpl::getUserCost(const User *U,
339-
ArrayRef<const Value *> Operands,
340-
TTI::TargetCostKind CostKind) {
337+
InstructionCost HexagonTTIImpl::getUserCost(const User *U,
338+
ArrayRef<const Value *> Operands,
339+
TTI::TargetCostKind CostKind) {
341340
auto isCastFoldedIntoLoad = [this](const CastInst *CI) -> bool {
342341
if (!CI->isIntegerCast())
343342
return false;

llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class HexagonTTIImpl : public BasicTTIImplBase<HexagonTTIImpl> {
162162

163163
/// @}
164164

165-
int getUserCost(const User *U, ArrayRef<const Value *> Operands,
166-
TTI::TargetCostKind CostKind);
165+
InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
166+
TTI::TargetCostKind CostKind);
167167

168168
// Hexagon specific decision to generate a lookup table.
169169
bool shouldBuildLookupTables() const;

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ int PPCTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
318318
return PPCTTIImpl::getIntImmCost(Imm, Ty, CostKind);
319319
}
320320

321-
unsigned
322-
PPCTTIImpl::getUserCost(const User *U, ArrayRef<const Value *> Operands,
323-
TTI::TargetCostKind CostKind) {
321+
InstructionCost PPCTTIImpl::getUserCost(const User *U,
322+
ArrayRef<const Value *> Operands,
323+
TTI::TargetCostKind CostKind) {
324324
// We already implement getCastInstrCost and getMemoryOpCost where we perform
325325
// the vector adjustment there.
326326
if (isa<CastInst>(U) || isa<LoadInst>(U) || isa<StoreInst>(U))

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class PPCTTIImpl : public BasicTTIImplBase<PPCTTIImpl> {
5757
int getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
5858
Type *Ty, TTI::TargetCostKind CostKind);
5959

60-
unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands,
61-
TTI::TargetCostKind CostKind);
60+
InstructionCost getUserCost(const User *U, ArrayRef<const Value *> Operands,
61+
TTI::TargetCostKind CostKind);
6262

6363
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);
6464
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,

0 commit comments

Comments
 (0)