From 57b3bc8c603e25380ba56a5b95b2887010e9c1c0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 7 Nov 2020 12:25:55 +0100 Subject: [PATCH] [CaptureTracking] Add statistics (NFC) Add basic statistics on the number of pointers that have been determined to maybe capture / not capture. --- llvm/lib/Analysis/CaptureTracking.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp index 6ff7cbc048f2..b2fc6e603f9e 100644 --- a/llvm/lib/Analysis/CaptureTracking.cpp +++ b/llvm/lib/Analysis/CaptureTracking.cpp @@ -18,6 +18,7 @@ #include "llvm/Analysis/CaptureTracking.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CFG.h" #include "llvm/Analysis/ValueTracking.h" @@ -29,6 +30,13 @@ using namespace llvm; +#define DEBUG_TYPE "capture-tracking" + +STATISTIC(NumCaptured, "Number of pointers maybe captured"); +STATISTIC(NumNotCaptured, "Number of pointers not captured"); +STATISTIC(NumCapturedBefore, "Number of pointers maybe captured before"); +STATISTIC(NumNotCapturedBefore, "Number of pointers not captured before"); + /// The default value for MaxUsesToExplore argument. It's relatively small to /// keep the cost of analysis reasonable for clients like BasicAliasAnalysis, /// where the results can't be cached. @@ -194,6 +202,10 @@ bool llvm::PointerMayBeCaptured(const Value *V, SimpleCaptureTracker SCT(ReturnCaptures); PointerMayBeCaptured(V, &SCT, MaxUsesToExplore); + if (SCT.Captured) + ++NumCaptured; + else + ++NumNotCaptured; return SCT.Captured; } @@ -222,6 +234,10 @@ bool llvm::PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures, CapturesBefore CB(ReturnCaptures, I, DT, IncludeI); PointerMayBeCaptured(V, &CB, MaxUsesToExplore); + if (CB.Captured) + ++NumCapturedBefore; + else + ++NumNotCapturedBefore; return CB.Captured; }