From 20cb6c7cebb5a3566640a9bf0da4729993ce6020 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 12 Feb 2021 16:00:24 +0100 Subject: [PATCH] [AA] Add option for tracing AA queries (NFC) Add an -aa-trace debug option that can be used to print AA queries, including any recursive queries and their results. --- llvm/lib/Analysis/AliasAnalysis.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp index ebf7070..6af69e8 100644 --- a/llvm/lib/Analysis/AliasAnalysis.cpp +++ b/llvm/lib/Analysis/AliasAnalysis.cpp @@ -67,6 +67,13 @@ STATISTIC(NumMustAlias, "Number of MustAlias results"); /// when testing to isolate a single AA implementation. cl::opt DisableBasicAA("disable-basic-aa", cl::Hidden, cl::init(false)); +#ifndef NDEBUG +/// Print a trace of alias analysis queries and their results. +static cl::opt EnableAATrace("aa-trace", cl::Hidden, cl::init(false)); +#else +static const bool EnableAATrace = false; +#endif + AAResults::AAResults(AAResults &&Arg) : TLI(Arg.TLI), AAs(std::move(Arg.AAs)), AADeps(std::move(Arg.AADeps)) { for (auto &AA : AAs) @@ -118,6 +125,13 @@ AliasResult AAResults::alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI) { AliasResult Result = MayAlias; + if (EnableAATrace) { + for (unsigned I = 0; I < AAQI.Depth; ++I) + dbgs() << " "; + dbgs() << "Start " << *LocA.Ptr << " @ " << LocA.Size << ", " + << *LocB.Ptr << " @ " << LocB.Size << "\n"; + } + AAQI.Depth++; for (const auto &AA : AAs) { Result = AA->alias(LocA, LocB, AAQI); @@ -126,6 +140,13 @@ AliasResult AAResults::alias(const MemoryLocation &LocA, } AAQI.Depth--; + if (EnableAATrace) { + for (unsigned I = 0; I < AAQI.Depth; ++I) + dbgs() << " "; + dbgs() << "End " << *LocA.Ptr << " @ " << LocA.Size << ", " + << *LocB.Ptr << " @ " << LocB.Size << " = " << Result << "\n"; + } + if (AAQI.Depth == 0) { if (Result == NoAlias) ++NumNoAlias; -- 2.7.4