1 //===- AliasAnalysisCounter.h - Alias Analysis Query Counter ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// This declares an alias analysis which counts and prints queries made
11 /// through it. By inserting this between other AAs you can track when specific
12 /// layers of LLVM's AA get queried.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_ANALYSIS_ALIASANALYSISCOUNTER_H
17 #define LLVM_ANALYSIS_ALIASANALYSISCOUNTER_H
19 #include "llvm/Analysis/AliasAnalysis.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/Pass.h"
25 class AliasAnalysisCounter : public ModulePass, public AliasAnalysis {
26 unsigned No, May, Partial, Must;
27 unsigned NoMR, JustRef, JustMod, MR;
31 static char ID; // Class identification, replacement for typeinfo
33 AliasAnalysisCounter();
34 ~AliasAnalysisCounter() override;
36 bool runOnModule(Module &M) override;
38 void getAnalysisUsage(AnalysisUsage &AU) const override;
40 /// getAdjustedAnalysisPointer - This method is used when a pass implements
41 /// an analysis interface through multiple inheritance. If needed, it
42 /// should override this to adjust the this pointer as needed for the
43 /// specified pass info.
44 void *getAdjustedAnalysisPointer(AnalysisID PI) override;
46 // FIXME: We could count these too...
47 bool pointsToConstantMemory(const MemoryLocation &Loc,
48 bool OrLocal) override {
49 return getAnalysis<AliasAnalysis>().pointsToConstantMemory(Loc, OrLocal);
52 // Forwarding functions: just delegate to a real AA implementation, counting
53 // the number of responses...
54 AliasResult alias(const MemoryLocation &LocA,
55 const MemoryLocation &LocB) override;
57 ModRefInfo getModRefInfo(ImmutableCallSite CS,
58 const MemoryLocation &Loc) override;
59 ModRefInfo getModRefInfo(ImmutableCallSite CS1,
60 ImmutableCallSite CS2) override {
61 return AliasAnalysis::getModRefInfo(CS1, CS2);
65 //===--------------------------------------------------------------------===//
67 // createAliasAnalysisCounterPass - This pass counts alias queries and how the
68 // alias analysis implementation responds.
70 ModulePass *createAliasAnalysisCounterPass();