[PATCH] D77762: [llvm][nfc] InstructionCostDetail encapsulation
Mircea Trofin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 8 15:46:25 PDT 2020
mtrofin created this revision.
mtrofin added reviewers: davidxl, eraman, knaumov.
Herald added subscribers: llvm-commits, haicheng, hiraditya.
Herald added a project: LLVM.
Ensured initialized fields; encapsulad delta calulations and evaluation of threshold having had changed; assertion for CostThresholdMap dereference, to capture design intent.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77762
Files:
llvm/lib/Analysis/InlineCost.cpp
Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -116,10 +116,16 @@
// 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 @@
// 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";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77762.256128.patch
Type: text/x-patch
Size: 2306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200408/07974b12/attachment-0001.bin>
More information about the llvm-commits
mailing list