[PATCH] D96030: NFC: Migrate CodeMetrics to work on InstructionCost
Sander de Smalen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 03:11:07 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41500836b0f2: NFC: Migrate CodeMetrics to work on InstructionCost (authored by sdesmalen).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96030/new/
https://reviews.llvm.org/D96030
Files:
llvm/lib/Analysis/CodeMetrics.cpp
Index: llvm/lib/Analysis/CodeMetrics.cpp
===================================================================
--- llvm/lib/Analysis/CodeMetrics.cpp
+++ 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 @@
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 @@
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 @@
notDuplicatable |= isa<IndirectBrInst>(BB->getTerminator());
// Remember NumInsts for this BB.
- NumBBInsts[BB] = NumInsts - NumInstsBeforeThisBB;
+ InstructionCost NumInstsThisBB = NumInstsProxy - NumInstsBeforeThisBB;
+ NumBBInsts[BB] = *NumInstsThisBB.getValue();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96030.322936.patch
Type: text/x-patch
Size: 1846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210211/9a79dc6e/attachment.bin>
More information about the llvm-commits
mailing list