1 //===- NoAliasAnalysis.cpp - Minimal Alias Analysis Impl ------------------===//
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 //
10 // This file defines the default implementation of the Alias Analysis interface
11 // that simply returns "I don't know" for all queries.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/Analysis/Passes.h"
16 #include "llvm/Analysis/AliasAnalysis.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/Pass.h"
21 using namespace llvm;
22 
23 namespace {
24   /// NoAA - This class implements the -no-aa pass, which always returns "I
25   /// don't know" for alias queries.  NoAA is unlike other alias analysis
26   /// implementations, in that it does not chain to a previous analysis.  As
27   /// such it doesn't follow many of the rules that other alias analyses must.
28   ///
29   struct NoAA : public ImmutablePass, public AliasAnalysis {
30     static char ID; // Class identification, replacement for typeinfo
NoAA__anon4016a3100111::NoAA31     NoAA() : ImmutablePass(ID) {
32       initializeNoAAPass(*PassRegistry::getPassRegistry());
33     }
34 
getAnalysisUsage__anon4016a3100111::NoAA35     void getAnalysisUsage(AnalysisUsage &AU) const override {}
36 
doInitialization__anon4016a3100111::NoAA37     bool doInitialization(Module &M) override {
38       // Note: NoAA does not call InitializeAliasAnalysis because it's
39       // special and does not support chaining.
40       DL = &M.getDataLayout();
41       return true;
42     }
43 
alias__anon4016a3100111::NoAA44     AliasResult alias(const Location &LocA, const Location &LocB) override {
45       return MayAlias;
46     }
47 
getModRefBehavior__anon4016a3100111::NoAA48     ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
49       return UnknownModRefBehavior;
50     }
getModRefBehavior__anon4016a3100111::NoAA51     ModRefBehavior getModRefBehavior(const Function *F) override {
52       return UnknownModRefBehavior;
53     }
54 
pointsToConstantMemory__anon4016a3100111::NoAA55     bool pointsToConstantMemory(const Location &Loc, bool OrLocal) override {
56       return false;
57     }
getArgLocation__anon4016a3100111::NoAA58     Location getArgLocation(ImmutableCallSite CS, unsigned ArgIdx,
59                             ModRefResult &Mask) override {
60       Mask = ModRef;
61       AAMDNodes AATags;
62       CS->getAAMetadata(AATags);
63       return Location(CS.getArgument(ArgIdx), UnknownSize, AATags);
64     }
65 
getModRefInfo__anon4016a3100111::NoAA66     ModRefResult getModRefInfo(ImmutableCallSite CS,
67                                const Location &Loc) override {
68       return ModRef;
69     }
getModRefInfo__anon4016a3100111::NoAA70     ModRefResult getModRefInfo(ImmutableCallSite CS1,
71                                ImmutableCallSite CS2) override {
72       return ModRef;
73     }
74 
deleteValue__anon4016a3100111::NoAA75     void deleteValue(Value *V) override {}
copyValue__anon4016a3100111::NoAA76     void copyValue(Value *From, Value *To) override {}
addEscapingUse__anon4016a3100111::NoAA77     void addEscapingUse(Use &U) override {}
78 
79     /// getAdjustedAnalysisPointer - This method is used when a pass implements
80     /// an analysis interface through multiple inheritance.  If needed, it
81     /// should override this to adjust the this pointer as needed for the
82     /// specified pass info.
getAdjustedAnalysisPointer__anon4016a3100111::NoAA83     void *getAdjustedAnalysisPointer(const void *ID) override {
84       if (ID == &AliasAnalysis::ID)
85         return (AliasAnalysis*)this;
86       return this;
87     }
88   };
89 }  // End of anonymous namespace
90 
91 // Register this pass...
92 char NoAA::ID = 0;
93 INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
94                    "No Alias Analysis (always returns 'may' alias)",
95                    true, true, true)
96 
createNoAAPass()97 ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }
98