aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorMircea Trofin <mtrofin@google.com>2020-04-08 14:54:33 -0700
committerMircea Trofin <mtrofin@google.com>2020-04-09 08:21:18 -0700
commitb4924f01a45c03f4f1e7a504e3ba917a354c1ef9 (patch)
tree729db01ae60346ec46ddbcc851f751d04020857b /llvm/lib/Analysis/InlineCost.cpp
parentd4579b7ef696dc932f3174896ee5de7d235c6462 (diff)
downloadllvm-b4924f01a45c03f4f1e7a504e3ba917a354c1ef9.zip
llvm-b4924f01a45c03f4f1e7a504e3ba917a354c1ef9.tar.gz
llvm-b4924f01a45c03f4f1e7a504e3ba917a354c1ef9.tar.bz2
[llvm][nfc] InstructionCostDetail encapsulation
Ensured initialized fields; encapsulad delta calulations and evaluation of threshold having had changed; assertion for CostThresholdMap dereference, to indicate design intent. Differential Revision: https://reviews.llvm.org/D77762
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index b4aa2fb..b9f0699 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -116,10 +116,16 @@ class InlineCostCallAnalyzer;
// This struct is used to store information about inline cost of a
// particular instruction
struct InstructionCostDetail {
- int CostBefore;
- int CostAfter;
- int ThresholdBefore;
- int ThresholdAfter;
+ int CostBefore = 0;
+ int CostAfter = 0;
+ int ThresholdBefore = 0;
+ int ThresholdAfter = 0;
+
+ int getThresholdDelta() const { return ThresholdAfter - ThresholdBefore; }
+
+ int getCostDelta() const { return CostAfter - CostBefore; }
+
+ bool hasThresholdChanged() const { return ThresholdAfter != ThresholdBefore; }
};
class CostAnnotationWriter : public AssemblyAnnotationWriter {
@@ -722,16 +728,16 @@ void CostAnnotationWriter::emitInstructionAnnot(
// The cost of inlining of the given instruction is printed always.
// The threshold delta is printed only when it is non-zero. It happens
// when we decided to give a bonus at a particular instruction.
- OS << "; cost before = " << CostThresholdMap[I].CostBefore <<
- ", cost after = " << CostThresholdMap[I].CostAfter <<
- ", threshold before = " << CostThresholdMap[I].ThresholdBefore <<
- ", threshold after = " << CostThresholdMap[I].ThresholdAfter <<
- ", ";
- OS << "cost delta = " << CostThresholdMap[I].CostAfter -
- CostThresholdMap[I].CostBefore;
- if (CostThresholdMap[I].ThresholdAfter != CostThresholdMap[I].ThresholdBefore)
- OS << ", threshold delta = " << CostThresholdMap[I].ThresholdAfter -
- CostThresholdMap[I].ThresholdBefore;
+ assert(CostThresholdMap.count(I) > 0 &&
+ "Expected each instruction to have an instruction annotation");
+ const auto &Record = CostThresholdMap[I];
+ OS << "; cost before = " << Record.CostBefore
+ << ", cost after = " << Record.CostAfter
+ << ", threshold before = " << Record.ThresholdBefore
+ << ", threshold after = " << Record.ThresholdAfter << ", ";
+ OS << "cost delta = " << Record.getCostDelta();
+ if (Record.hasThresholdChanged())
+ OS << ", threshold delta = " << Record.getThresholdDelta();
OS << "\n";
}