a0a5625aeecdca63bf8083664029543f3393f796
[oota-llvm.git] / include / llvm / Analysis / TypeBasedAliasAnalysis.h
1 //===- TypeBasedAliasAnalysis.h - Type-Based Alias Analysis -----*- 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 is the interface for a metadata-based TBAA. See the source file for
11 /// details on the algorithm.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
16 #define LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
17
18 #include "llvm/Analysis/AliasAnalysis.h"
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/Metadata.h"
21 #include "llvm/Pass.h"
22
23 namespace llvm {
24
25 /// TypeBasedAliasAnalysis - This is a simple alias analysis
26 /// implementation that uses TypeBased to answer queries.
27 class TypeBasedAliasAnalysis : public ImmutablePass, public AliasAnalysis {
28 public:
29   static char ID; // Class identification, replacement for typeinfo
30   TypeBasedAliasAnalysis() : ImmutablePass(ID) {
31     initializeTypeBasedAliasAnalysisPass(*PassRegistry::getPassRegistry());
32   }
33
34   bool doInitialization(Module &M) override;
35
36   /// getAdjustedAnalysisPointer - This method is used when a pass implements
37   /// an analysis interface through multiple inheritance.  If needed, it
38   /// should override this to adjust the this pointer as needed for the
39   /// specified pass info.
40   void *getAdjustedAnalysisPointer(const void *PI) override {
41     if (PI == &AliasAnalysis::ID)
42       return (AliasAnalysis *)this;
43     return this;
44   }
45
46   bool Aliases(const MDNode *A, const MDNode *B) const;
47   bool PathAliases(const MDNode *A, const MDNode *B) const;
48
49 private:
50   void getAnalysisUsage(AnalysisUsage &AU) const override;
51   AliasResult alias(const MemoryLocation &LocA,
52                     const MemoryLocation &LocB) override;
53   bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal) override;
54   FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) override;
55   FunctionModRefBehavior getModRefBehavior(const Function *F) override;
56   ModRefInfo getModRefInfo(ImmutableCallSite CS,
57                            const MemoryLocation &Loc) override;
58   ModRefInfo getModRefInfo(ImmutableCallSite CS1,
59                            ImmutableCallSite CS2) override;
60 };
61
62 //===--------------------------------------------------------------------===//
63 //
64 // createTypeBasedAliasAnalysisPass - This pass implements metadata-based
65 // type-based alias analysis.
66 //
67 ImmutablePass *createTypeBasedAliasAnalysisPass();
68
69 }
70
71 #endif