Skip to content

Commit f166a41

Browse files
committed
Don't rely on OutputCostKind and TargetCostKind having the same values
1 parent 743084d commit f166a41

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

llvm/lib/Analysis/CostModel.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
using namespace llvm;
3030

31-
enum OutputCostKind {
31+
enum class OutputCostKind {
3232
RecipThroughput,
3333
Latency,
3434
CodeSize,
@@ -87,6 +87,22 @@ static InstructionCost getCost(Instruction &Inst, TTI::TargetCostKind CostKind,
8787
return TTI.getInstructionCost(&Inst, CostKind);
8888
}
8989

90+
static TTI::TargetCostKind
91+
OutputCostKindToTargetCostKind(OutputCostKind CostKind) {
92+
switch (CostKind) {
93+
case OutputCostKind::RecipThroughput:
94+
return TTI::TCK_RecipThroughput;
95+
case OutputCostKind::Latency:
96+
return TTI::TCK_Latency;
97+
case OutputCostKind::CodeSize:
98+
return TTI::TCK_CodeSize;
99+
case OutputCostKind::SizeAndLatency:
100+
return TTI::TCK_SizeAndLatency;
101+
default:
102+
llvm_unreachable("Unexpected OutputCostKind!");
103+
};
104+
}
105+
90106
PreservedAnalyses CostModelPrinterPass::run(Function &F,
91107
FunctionAnalysisManager &AM) {
92108
auto &TTI = AM.getResult<TargetIRAnalysis>(F);
@@ -111,7 +127,7 @@ PreservedAnalyses CostModelPrinterPass::run(Function &F,
111127
OS << " for: " << Inst << "\n";
112128
} else {
113129
InstructionCost Cost =
114-
getCost(Inst, (TTI::TargetCostKind)(unsigned)CostKind, TTI, TLI);
130+
getCost(Inst, OutputCostKindToTargetCostKind(CostKind), TTI, TLI);
115131
if (auto CostVal = Cost.getValue())
116132
OS << "Found an estimated cost of " << *CostVal;
117133
else

0 commit comments

Comments
 (0)