[AA] Add statistics for alias results (NFC)

Count how many NoAlias/MustAlias/MayAlias we get from top-level
queries.
This commit is contained in:
Nikita Popov 2020-12-05 10:39:31 +01:00
parent 8925d23474
commit f8afba5f7a
2 changed files with 26 additions and 3 deletions

View File

@ -814,6 +814,9 @@ private:
std::vector<AnalysisKey *> AADeps;
/// Query depth used to distinguish recursive queries.
unsigned Depth;
friend class BatchAAResults;
};

View File

@ -24,6 +24,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/CFLAndersAliasAnalysis.h"
#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
@ -54,8 +55,14 @@
#include <functional>
#include <iterator>
#define DEBUG_TYPE "aa"
using namespace llvm;
STATISTIC(NumNoAlias, "Number of NoAlias results");
STATISTIC(NumMayAlias, "Number of MayAlias results");
STATISTIC(NumMustAlias, "Number of MustAlias results");
/// Allow disabling BasicAA from the AA results. This is particularly useful
/// when testing to isolate a single AA implementation.
cl::opt<bool> DisableBasicAA("disable-basic-aa", cl::Hidden, cl::init(false));
@ -109,12 +116,25 @@ AliasResult AAResults::alias(const MemoryLocation &LocA,
AliasResult AAResults::alias(const MemoryLocation &LocA,
const MemoryLocation &LocB, AAQueryInfo &AAQI) {
AliasResult Result = MayAlias;
Depth++;
for (const auto &AA : AAs) {
auto Result = AA->alias(LocA, LocB, AAQI);
Result = AA->alias(LocA, LocB, AAQI);
if (Result != MayAlias)
return Result;
break;
}
return MayAlias;
Depth--;
if (Depth == 0) {
if (Result == NoAlias)
++NumNoAlias;
else if (Result == MustAlias)
++NumMustAlias;
else
++NumMayAlias;
}
return Result;
}
bool AAResults::pointsToConstantMemory(const MemoryLocation &Loc,