[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 4 06:12:30 PST 2021
sdesmalen created this revision.
sdesmalen added reviewers: david-arm, ctetreau, RKSimon, spatel.
Herald added a subscriber: hiraditya.
sdesmalen requested review of this revision.
Herald added a project: LLVM.
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
Repository:
rG LLVM Github Monorepo
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"
@@ -116,7 +117,10 @@
const BasicBlock *BB, const TargetTransformInfo &TTI,
const SmallPtrSetImpl<const Value *> &EphValues, bool PrepareForLTO) {
++NumBlocks;
- unsigned NumInstsBeforeThisBB = NumInsts;
+ // Use a proxy for NumInsts, so that it can use InstructionCost's arithmetic
+ // properties.
+ InstructionCost NumInstsProxy = NumInsts;
+ InstructionCost NumInstsBeforeThisBB = NumInsts;
for (const Instruction &I : *BB) {
// Skip ephemeral values.
if (EphValues.count(&I))
@@ -175,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()))
@@ -195,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.321407.patch
Type: text/x-patch
Size: 1540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210204/7e1b2b4c/attachment.bin>
More information about the llvm-commits
mailing list