|
28 | 28 |
|
29 | 29 | using namespace llvm;
|
30 | 30 |
|
31 |
| -static cl::opt<TargetTransformInfo::TargetCostKind> CostKind( |
| 31 | +enum OutputCostKind { |
| 32 | + RecipThroughput, |
| 33 | + Latency, |
| 34 | + CodeSize, |
| 35 | + SizeAndLatency, |
| 36 | + All, |
| 37 | +}; |
| 38 | + |
| 39 | +static cl::opt<OutputCostKind> CostKind( |
32 | 40 | "cost-kind", cl::desc("Target cost kind"),
|
33 |
| - cl::init(TargetTransformInfo::TCK_RecipThroughput), |
34 |
| - cl::values(clEnumValN(TargetTransformInfo::TCK_RecipThroughput, |
35 |
| - "throughput", "Reciprocal throughput"), |
36 |
| - clEnumValN(TargetTransformInfo::TCK_Latency, |
37 |
| - "latency", "Instruction latency"), |
38 |
| - clEnumValN(TargetTransformInfo::TCK_CodeSize, |
39 |
| - "code-size", "Code size"), |
40 |
| - clEnumValN(TargetTransformInfo::TCK_SizeAndLatency, |
41 |
| - "size-latency", "Code size and latency"))); |
| 41 | + cl::init(OutputCostKind::RecipThroughput), |
| 42 | + cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", |
| 43 | + "Reciprocal throughput"), |
| 44 | + clEnumValN(OutputCostKind::Latency, "latency", |
| 45 | + "Instruction latency"), |
| 46 | + clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), |
| 47 | + clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", |
| 48 | + "Code size and latency"), |
| 49 | + clEnumValN(OutputCostKind::All, "all", "Print all cost kinds"))); |
42 | 50 |
|
43 | 51 | enum class IntrinsicCostStrategy {
|
44 | 52 | InstructionCost,
|
@@ -86,15 +94,30 @@ PreservedAnalyses CostModelPrinterPass::run(Function &F,
|
86 | 94 | OS << "Printing analysis 'Cost Model Analysis' for function '" << F.getName() << "':\n";
|
87 | 95 | for (BasicBlock &B : F) {
|
88 | 96 | for (Instruction &Inst : B) {
|
89 |
| - // TODO: Use a pass parameter instead of cl::opt CostKind to determine |
90 |
| - // which cost kind to print. |
91 |
| - InstructionCost Cost = getCost(Inst, CostKind, TTI, TLI); |
92 |
| - if (auto CostVal = Cost.getValue()) |
93 |
| - OS << "Cost Model: Found an estimated cost of " << *CostVal; |
94 |
| - else |
95 |
| - OS << "Cost Model: Invalid cost"; |
96 |
| - |
97 |
| - OS << " for instruction: " << Inst << "\n"; |
| 97 | + OS << "Cost Model: "; |
| 98 | + if (CostKind == OutputCostKind::All) { |
| 99 | + OS << "Found costs of "; |
| 100 | + InstructionCost RThru = |
| 101 | + getCost(Inst, TTI::TCK_RecipThroughput, TTI, TLI); |
| 102 | + InstructionCost CodeSize = getCost(Inst, TTI::TCK_CodeSize, TTI, TLI); |
| 103 | + InstructionCost Lat = getCost(Inst, TTI::TCK_Latency, TTI, TLI); |
| 104 | + InstructionCost SizeLat = |
| 105 | + getCost(Inst, TTI::TCK_SizeAndLatency, TTI, TLI); |
| 106 | + if (RThru == CodeSize && RThru == Lat && RThru == SizeLat) |
| 107 | + OS << RThru; |
| 108 | + else |
| 109 | + OS << "RThru:" << RThru << " CodeSize:" << CodeSize << " Lat:" << Lat |
| 110 | + << " SizeLat:" << SizeLat; |
| 111 | + OS << " for: " << Inst << "\n"; |
| 112 | + } else { |
| 113 | + InstructionCost Cost = |
| 114 | + getCost(Inst, (TTI::TargetCostKind)(unsigned)CostKind, TTI, TLI); |
| 115 | + if (auto CostVal = Cost.getValue()) |
| 116 | + OS << "Found an estimated cost of " << *CostVal; |
| 117 | + else |
| 118 | + OS << "Invalid cost"; |
| 119 | + OS << " for instruction: " << Inst << "\n"; |
| 120 | + } |
98 | 121 | }
|
99 | 122 | }
|
100 | 123 | return PreservedAnalyses::all();
|
|
0 commit comments