From 70e332d34b795f1645953c35747e345f88b8688b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 7 Feb 2003 19:46:03 +0000 Subject: [PATCH] New general purpose alias analysis result auditor git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5503 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/AliasAnalysisCounter.cpp | 64 +++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lib/Analysis/AliasAnalysisCounter.cpp diff --git a/lib/Analysis/AliasAnalysisCounter.cpp b/lib/Analysis/AliasAnalysisCounter.cpp new file mode 100644 index 00000000000..d80a3f8bf94 --- /dev/null +++ b/lib/Analysis/AliasAnalysisCounter.cpp @@ -0,0 +1,64 @@ +//===- AliasAnalysisCounter.cpp - Alias Analysis Query Counter ------------===// +// +// This file implements a pass which can be used to count how many alias queries +// are being made and how the alias analysis implementation being used responds. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Pass.h" +#include + +namespace { + unsigned No = 0, May = 0, Must = 0; + + struct AliasAnalysisCounter : public Pass, public AliasAnalysis { + bool run(Module &M) { return false; } + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(); + AU.setPreservesAll(); + } + + Result count(Result R) { + switch (R) { + default: assert(0 && "Unknown alias type!"); + case NoAlias: No++; return NoAlias; + case MayAlias: May++; return MayAlias; + case MustAlias: Must++; return MustAlias; + } + } + + // Forwarding functions: just delegate to a real AA implementation, counting + // the number of responses... + Result alias(const Value *V1, const Value *V2) { + return count(getAnalysis().alias(V1, V2)); + } + Result canCallModify(const CallInst &CI, const Value *Ptr) { + return count(getAnalysis().canCallModify(CI, Ptr)); + } + Result canInvokeModify(const InvokeInst &I, const Value *Ptr) { + return count(getAnalysis().canInvokeModify(I, Ptr)); + } + }; + + RegisterOpt + X("count-aa", "Count Alias Analysis Query Responses"); + RegisterAnalysisGroup Y; + + + struct ResultPrinter { + ~ResultPrinter() { + unsigned Sum = No+May+Must; + if (Sum) { // Print a report if any counted queries occurred... + std::cerr + << "\n===== Alias Analysis Counter Report =====\n" + << " " << Sum << " Total Alias Queries Performed\n" + << " " << No << " no alias responses (" << No*100/Sum << "%)\n" + << " " << May << " may alias responses (" << May*100/Sum << "%)\n" + << " " << Must << " must alias responses (" <