[PM/AA] Remove two no-op overridden functions that just delegated to the
[oota-llvm.git] / include / llvm / Analysis / GlobalsModRef.h
1 //===- GlobalsModRef.h - Simple Mod/Ref AA for Globals ----------*- 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 simple mod/ref and alias analysis over globlas.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_GLOBALSMODREF_H
15 #define LLVM_ANALYSIS_GLOBALSMODREF_H
16
17 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/Analysis/CallGraph.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/IR/ValueHandle.h"
23 #include "llvm/Pass.h"
24 #include <list>
25
26 namespace llvm {
27
28 /// GlobalsModRef - The actual analysis pass.
29 class GlobalsModRef : public ModulePass, public AliasAnalysis {
30   class FunctionInfo;
31
32   /// The globals that do not have their addresses taken.
33   SmallPtrSet<const GlobalValue *, 8> NonAddressTakenGlobals;
34
35   /// IndirectGlobals - The memory pointed to by this global is known to be
36   /// 'owned' by the global.
37   SmallPtrSet<const GlobalValue *, 8> IndirectGlobals;
38
39   /// AllocsForIndirectGlobals - If an instruction allocates memory for an
40   /// indirect global, this map indicates which one.
41   DenseMap<const Value *, const GlobalValue *> AllocsForIndirectGlobals;
42
43   /// For each function, keep track of what globals are modified or read.
44   DenseMap<const Function *, FunctionInfo> FunctionInfos;
45
46   /// Handle to clear this analysis on deletion of values.
47   struct DeletionCallbackHandle final : CallbackVH {
48     GlobalsModRef &GMR;
49     std::list<DeletionCallbackHandle>::iterator I;
50
51     DeletionCallbackHandle(GlobalsModRef &GMR, Value *V)
52         : CallbackVH(V), GMR(GMR) {}
53
54     void deleted() override;
55   };
56
57   /// List of callbacks for globals being tracked by this analysis. Note that
58   /// these objects are quite large, but we only anticipate having one per
59   /// global tracked by this analysis. There are numerous optimizations we
60   /// could perform to the memory utilization here if this becomes a problem.
61   std::list<DeletionCallbackHandle> Handles;
62
63 public:
64   static char ID;
65   GlobalsModRef();
66
67   bool runOnModule(Module &M) override {
68     InitializeAliasAnalysis(this, &M.getDataLayout());
69
70     // Find non-addr taken globals.
71     AnalyzeGlobals(M);
72
73     // Propagate on CG.
74     AnalyzeCallGraph(getAnalysis<CallGraphWrapperPass>().getCallGraph(), M);
75     return false;
76   }
77
78   void getAnalysisUsage(AnalysisUsage &AU) const override {
79     AliasAnalysis::getAnalysisUsage(AU);
80     AU.addRequired<CallGraphWrapperPass>();
81     AU.setPreservesAll(); // Does not transform code
82   }
83
84   /// getAdjustedAnalysisPointer - This method is used when a pass implements
85   /// an analysis interface through multiple inheritance.  If needed, it
86   /// should override this to adjust the this pointer as needed for the
87   /// specified pass info.
88   void *getAdjustedAnalysisPointer(AnalysisID PI) override {
89     if (PI == &AliasAnalysis::ID)
90       return (AliasAnalysis *)this;
91     return this;
92   }
93
94   //------------------------------------------------
95   // Implement the AliasAnalysis API
96   //
97   AliasResult alias(const MemoryLocation &LocA,
98                     const MemoryLocation &LocB) override;
99   ModRefInfo getModRefInfo(ImmutableCallSite CS,
100                            const MemoryLocation &Loc) override;
101
102   /// getModRefBehavior - Return the behavior of the specified function if
103   /// called from the specified call site.  The call site may be null in which
104   /// case the most generic behavior of this function should be returned.
105   FunctionModRefBehavior getModRefBehavior(const Function *F) override;
106
107   /// getModRefBehavior - Return the behavior of the specified function if
108   /// called from the specified call site.  The call site may be null in which
109   /// case the most generic behavior of this function should be returned.
110   FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) override;
111
112 private:
113   FunctionInfo *getFunctionInfo(const Function *F);
114
115   void AnalyzeGlobals(Module &M);
116   void AnalyzeCallGraph(CallGraph &CG, Module &M);
117   bool AnalyzeUsesOfPointer(Value *V,
118                             SmallPtrSetImpl<Function *> *Readers = nullptr,
119                             SmallPtrSetImpl<Function *> *Writers = nullptr,
120                             GlobalValue *OkayStoreDest = nullptr);
121   bool AnalyzeIndirectGlobalMemory(GlobalValue *GV);
122
123   bool isNonEscapingGlobalNoAlias(const GlobalValue *GV, const Value *V);
124 };
125
126 //===--------------------------------------------------------------------===//
127 //
128 // createGlobalsModRefPass - This pass provides alias and mod/ref info for
129 // global values that do not have their addresses taken.
130 //
131 Pass *createGlobalsModRefPass();
132
133 }
134
135 #endif