68c9069fd42da5cb001d8c37c4b01cc9d94fda10
[oota-llvm.git] / include / llvm / Analysis / AliasAnalysisCounter.h
1 //===- AliasAnalysisCounter.h - Alias Analysis Query Counter ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
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.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_ANALYSIS_ALIASANALYSISCOUNTER_H
17 #define LLVM_ANALYSIS_ALIASANALYSISCOUNTER_H
18
19 #include "llvm/Analysis/AliasAnalysis.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/Pass.h"
22
23 namespace llvm {
24
25 class AliasAnalysisCounter : public ModulePass, public AliasAnalysis {
26   unsigned No, May, Partial, Must;
27   unsigned NoMR, JustRef, JustMod, MR;
28   Module *M;
29
30 public:
31   static char ID; // Class identification, replacement for typeinfo
32
33   AliasAnalysisCounter();
34   ~AliasAnalysisCounter() override;
35
36   bool runOnModule(Module &M) override;
37
38   void getAnalysisUsage(AnalysisUsage &AU) const override;
39
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;
45
46   // FIXME: We could count these too...
47   bool pointsToConstantMemory(const MemoryLocation &Loc,
48                               bool OrLocal) override {
49     return getAnalysis<AliasAnalysis>().pointsToConstantMemory(Loc, OrLocal);
50   }
51
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;
56
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);
62   }
63 };
64
65 //===--------------------------------------------------------------------===//
66 //
67 // createAliasAnalysisCounterPass - This pass counts alias queries and how the
68 // alias analysis implementation responds.
69 //
70 ModulePass *createAliasAnalysisCounterPass();
71
72 }
73
74 #endif