[PM/AA] Hoist ScopedNoAliasAA's interface into a header and move the
[oota-llvm.git] / include / llvm / Analysis / ScopedNoAliasAA.h
1 //===- ScopedNoAliasAA.h - Scoped No-Alias 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 scoped no-alias analysis.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_SCOPEDNOALIASAA_H
15 #define LLVM_ANALYSIS_SCOPEDNOALIASAA_H
16
17 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Metadata.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/Pass.h"
22
23 namespace llvm {
24
25 /// ScopedNoAliasAA - This is a simple alias analysis
26 /// implementation that uses scoped-noalias metadata to answer queries.
27 class ScopedNoAliasAA : public ImmutablePass, public AliasAnalysis {
28 public:
29   static char ID; // Class identification, replacement for typeinfo
30   ScopedNoAliasAA() : ImmutablePass(ID) {
31     initializeScopedNoAliasAAPass(*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 protected:
47   bool mayAliasInScopes(const MDNode *Scopes, const MDNode *NoAlias) const;
48   void collectMDInDomain(const MDNode *List, const MDNode *Domain,
49                          SmallPtrSetImpl<const MDNode *> &Nodes) const;
50
51 private:
52   void getAnalysisUsage(AnalysisUsage &AU) const override;
53   AliasResult alias(const MemoryLocation &LocA,
54                     const MemoryLocation &LocB) override;
55   bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal) override;
56   FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) override;
57   FunctionModRefBehavior getModRefBehavior(const Function *F) override;
58   ModRefInfo getModRefInfo(ImmutableCallSite CS,
59                            const MemoryLocation &Loc) override;
60   ModRefInfo getModRefInfo(ImmutableCallSite CS1,
61                            ImmutableCallSite CS2) override;
62 };
63
64 //===--------------------------------------------------------------------===//
65 //
66 // createScopedNoAliasAAPass - This pass implements metadata-based
67 // scoped noalias analysis.
68 //
69 ImmutablePass *createScopedNoAliasAAPass();
70
71 }
72
73 #endif