2828
2929using 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+
90106PreservedAnalyses 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