aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/CodeMetrics.cpp
diff options
context:
space:
mode:
authorSander de Smalen <sander.desmalen@arm.com>2021-02-11 10:25:14 +0000
committerSander de Smalen <sander.desmalen@arm.com>2021-02-11 11:08:41 +0000
commit41500836b0f2e335b71919700e5db9341de76e8a (patch)
treef4d7717976fce3802a0695975fa75c44cf7ad66f /llvm/lib/Analysis/CodeMetrics.cpp
parent90081f3020e38727eb30506d052cbb4e3a489eb6 (diff)
downloadllvm-41500836b0f2e335b71919700e5db9341de76e8a.zip
llvm-41500836b0f2e335b71919700e5db9341de76e8a.tar.gz
llvm-41500836b0f2e335b71919700e5db9341de76e8a.tar.bz2
NFC: Migrate CodeMetrics to work on InstructionCost
This patch migrates cost values and arithmetic to work on InstructionCost. When the interfaces to TargetTransformInfo are changed, any InstructionCost state will propagate naturally. See this patch for the introduction of the type: https://reviews.llvm.org/D91174 See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2020-November/146408.html Reviewed By: david-arm Differential Revision: https://reviews.llvm.org/D96030
Diffstat (limited to 'llvm/lib/Analysis/CodeMetrics.cpp')
-rw-r--r--llvm/lib/Analysis/CodeMetrics.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/CodeMetrics.cpp b/llvm/lib/Analysis/CodeMetrics.cpp
index b0b46cb..846e1eb 100644
--- a/llvm/lib/Analysis/CodeMetrics.cpp
+++ b/llvm/lib/Analysis/CodeMetrics.cpp
@@ -18,6 +18,7 @@
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/InstructionCost.h"
#define DEBUG_TYPE "code-metrics"
@@ -112,7 +113,14 @@ void CodeMetrics::analyzeBasicBlock(
const BasicBlock *BB, const TargetTransformInfo &TTI,
const SmallPtrSetImpl<const Value *> &EphValues, bool PrepareForLTO) {
++NumBlocks;
- unsigned NumInstsBeforeThisBB = NumInsts;
+ // Use a proxy variable for NumInsts of type InstructionCost, so that it can
+ // use InstructionCost's arithmetic properties such as saturation when this
+ // feature is added to InstructionCost.
+ // When storing the value back to NumInsts, we can assume all costs are Valid
+ // because the IR should not contain any nodes that cannot be costed. If that
+ // happens the cost-model is broken.
+ InstructionCost NumInstsProxy = NumInsts;
+ InstructionCost NumInstsBeforeThisBB = NumInsts;
for (const Instruction &I : *BB) {
// Skip ephemeral values.
if (EphValues.count(&I))
@@ -171,7 +179,8 @@ void CodeMetrics::analyzeBasicBlock(
if (InvI->cannotDuplicate())
notDuplicatable = true;
- NumInsts += TTI.getUserCost(&I, TargetTransformInfo::TCK_CodeSize);
+ NumInstsProxy += TTI.getUserCost(&I, TargetTransformInfo::TCK_CodeSize);
+ NumInsts = *NumInstsProxy.getValue();
}
if (isa<ReturnInst>(BB->getTerminator()))
@@ -191,5 +200,6 @@ void CodeMetrics::analyzeBasicBlock(
notDuplicatable |= isa<IndirectBrInst>(BB->getTerminator());
// Remember NumInsts for this BB.
- NumBBInsts[BB] = NumInsts - NumInstsBeforeThisBB;
+ InstructionCost NumInstsThisBB = NumInstsProxy - NumInstsBeforeThisBB;
+ NumBBInsts[BB] = *NumInstsThisBB.getValue();
}