aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2013-04-29 06:16:57 +0000
committerMichael Gottesman <mgottesman@apple.com>2013-04-29 06:16:57 +0000
commitfe7ea985fac4abb4056fa5f020449a2802a81604 (patch)
tree1925a0b4dc818028d4e157f4884d93e677bd9e2f /lib/Transforms
parent2088d917922d02b452608e2c46c5ee9886a723dd (diff)
Added statistics to count the number of retains/releases before/after optimization.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180697 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/ObjCARC/ObjCARCOpts.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index 9991f156bd..54a701c978 100644
--- a/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ b/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
@@ -303,6 +303,14 @@ STATISTIC(NumRets, "Number of return value forwarding "
"retain+autoreleaes eliminated");
STATISTIC(NumRRs, "Number of retain+release paths eliminated");
STATISTIC(NumPeeps, "Number of calls peephole-optimized");
+STATISTIC(NumRetainsBeforeOpt,
+ "Number of retains before optimization.");
+STATISTIC(NumReleasesBeforeOpt,
+ "Number of releases before optimization.");
+STATISTIC(NumRetainsAfterOpt,
+ "Number of retains after optimization.");
+STATISTIC(NumReleasesAfterOpt,
+ "Number of releases after optimization.");
namespace {
/// \enum Sequence
@@ -1093,6 +1101,10 @@ namespace {
void OptimizeReturns(Function &F);
+#ifndef NDEBUG
+ void GatherStatistics(Function &F, bool AfterOptimization = false);
+#endif
+
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
virtual bool doInitialization(Module &M);
virtual bool runOnFunction(Function &F);
@@ -1480,6 +1492,7 @@ void ObjCARCOpt::OptimizeIndividualCalls(Function &F) {
break;
// FALLTHROUGH
case IC_Retain:
+ ++NumRetainsBeforeOpt;
OptimizeRetainCall(F, Inst);
break;
case IC_RetainRV:
@@ -1489,6 +1502,9 @@ void ObjCARCOpt::OptimizeIndividualCalls(Function &F) {
case IC_AutoreleaseRV:
OptimizeAutoreleaseRVCall(F, Inst, Class);
break;
+ case IC_Release:
+ ++NumReleasesBeforeOpt;
+ break;
}
// objc_autorelease(x) -> objc_release(x) if x is otherwise unused.
@@ -3006,6 +3022,30 @@ void ObjCARCOpt::OptimizeReturns(Function &F) {
}
}
+#ifndef NDEBUG
+void
+ObjCARCOpt::GatherStatistics(Function &F, bool AfterOptimization) {
+ llvm::Statistic &NumRetains =
+ AfterOptimization? NumRetainsAfterOpt : NumRetainsBeforeOpt;
+ llvm::Statistic &NumReleases =
+ AfterOptimization? NumReleasesAfterOpt : NumReleasesBeforeOpt;
+
+ for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ) {
+ Instruction *Inst = &*I++;
+ switch (GetBasicInstructionClass(Inst)) {
+ default:
+ break;
+ case IC_Retain:
+ ++NumRetains;
+ break;
+ case IC_Release:
+ ++NumReleases;
+ break;
+ }
+ }
+}
+#endif
+
bool ObjCARCOpt::doInitialization(Module &M) {
if (!EnableARCOpts)
return false;
@@ -3092,6 +3132,13 @@ bool ObjCARCOpt::runOnFunction(Function &F) {
(1 << IC_AutoreleaseRV)))
OptimizeReturns(F);
+ // Gather statistics after optimization.
+#ifndef NDEBUG
+ if (AreStatisticsEnabled()) {
+ GatherStatistics(F, true);
+ }
+#endif
+
DEBUG(dbgs() << "\n");
return Changed;