@@ -63,6 +63,22 @@ static cl::opt<IntrinsicCostStrategy> IntrinsicCost(
63
63
#define CM_NAME " cost-model"
64
64
#define DEBUG_TYPE CM_NAME
65
65
66
+ static InstructionCost getCost (Instruction &Inst, TTI::TargetCostKind CostKind,
67
+ TargetTransformInfo &TTI,
68
+ TargetLibraryInfo &TLI) {
69
+ auto *II = dyn_cast<IntrinsicInst>(&Inst);
70
+ if (II && IntrinsicCost != IntrinsicCostStrategy::InstructionCost) {
71
+ IntrinsicCostAttributes ICA (
72
+ II->getIntrinsicID (), *II, InstructionCost::getInvalid (),
73
+ /* TypeBasedOnly=*/ IntrinsicCost ==
74
+ IntrinsicCostStrategy::TypeBasedIntrinsicCost,
75
+ &TLI);
76
+ return TTI.getIntrinsicInstrCost (ICA, CostKind);
77
+ }
78
+
79
+ return TTI.getInstructionCost (&Inst, CostKind);
80
+ }
81
+
66
82
PreservedAnalyses CostModelPrinterPass::run (Function &F,
67
83
FunctionAnalysisManager &AM) {
68
84
auto &TTI = AM.getResult <TargetIRAnalysis>(F);
@@ -72,19 +88,7 @@ PreservedAnalyses CostModelPrinterPass::run(Function &F,
72
88
for (Instruction &Inst : B) {
73
89
// TODO: Use a pass parameter instead of cl::opt CostKind to determine
74
90
// which cost kind to print.
75
- InstructionCost Cost;
76
- auto *II = dyn_cast<IntrinsicInst>(&Inst);
77
- if (II && IntrinsicCost != IntrinsicCostStrategy::InstructionCost) {
78
- IntrinsicCostAttributes ICA (
79
- II->getIntrinsicID (), *II, InstructionCost::getInvalid (),
80
- /* TypeBasedOnly=*/ IntrinsicCost ==
81
- IntrinsicCostStrategy::TypeBasedIntrinsicCost,
82
- &TLI);
83
- Cost = TTI.getIntrinsicInstrCost (ICA, CostKind);
84
- } else {
85
- Cost = TTI.getInstructionCost (&Inst, CostKind);
86
- }
87
-
91
+ InstructionCost Cost = getCost (Inst, CostKind, TTI, TLI);
88
92
if (auto CostVal = Cost.getValue ())
89
93
OS << " Cost Model: Found an estimated cost of " << *CostVal;
90
94
else
0 commit comments