Make AAMDNodes ctor and operator bool (!!!) explicit, mop up bugs and weirdness expos...
[oota-llvm.git] / lib / Analysis / NoAliasAnalysis.cpp
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/Pass.h"
20 using namespace llvm;
21
22 namespace {
23   /// NoAA - This class implements the -no-aa pass, which always returns "I
24   /// don't know" for alias queries.  NoAA is unlike other alias analysis
25   /// implementations, in that it does not chain to a previous analysis.  As
26   /// such it doesn't follow many of the rules that other alias analyses must.
27   ///
28   struct NoAA : public ImmutablePass, public AliasAnalysis {
29     static char ID; // Class identification, replacement for typeinfo
30     NoAA() : ImmutablePass(ID) {
31       initializeNoAAPass(*PassRegistry::getPassRegistry());
32     }
33
34     void getAnalysisUsage(AnalysisUsage &AU) const override {}
35
36     void initializePass() override {
37       // Note: NoAA does not call InitializeAliasAnalysis because it's
38       // special and does not support chaining.
39       DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
40       DL = DLP ? &DLP->getDataLayout() : nullptr;
41     }
42
43     AliasResult alias(const Location &LocA, const Location &LocB) override {
44       return MayAlias;
45     }
46
47     ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
48       return UnknownModRefBehavior;
49     }
50     ModRefBehavior getModRefBehavior(const Function *F) override {
51       return UnknownModRefBehavior;
52     }
53
54     bool pointsToConstantMemory(const Location &Loc, bool OrLocal) override {
55       return false;
56     }
57     Location getArgLocation(ImmutableCallSite CS, unsigned ArgIdx,
58                             ModRefResult &Mask) override {
59       Mask = ModRef;
60       AAMDNodes AATags(
61           CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa),
62           CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
63           CS.getInstruction()->getMetadata(LLVMContext::MD_noalias));
64       return Location(CS.getArgument(ArgIdx), UnknownSize, AATags);
65     }
66
67     ModRefResult getModRefInfo(ImmutableCallSite CS,
68                                const Location &Loc) override {
69       return ModRef;
70     }
71     ModRefResult getModRefInfo(ImmutableCallSite CS1,
72                                ImmutableCallSite CS2) override {
73       return ModRef;
74     }
75
76     void deleteValue(Value *V) override {}
77     void copyValue(Value *From, Value *To) override {}
78     void addEscapingUse(Use &U) override {}
79
80     /// getAdjustedAnalysisPointer - This method is used when a pass implements
81     /// an analysis interface through multiple inheritance.  If needed, it
82     /// should override this to adjust the this pointer as needed for the
83     /// specified pass info.
84     void *getAdjustedAnalysisPointer(const void *ID) override {
85       if (ID == &AliasAnalysis::ID)
86         return (AliasAnalysis*)this;
87       return this;
88     }
89   };
90 }  // End of anonymous namespace
91
92 // Register this pass...
93 char NoAA::ID = 0;
94 INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
95                    "No Alias Analysis (always returns 'may' alias)",
96                    true, true, true)
97
98 ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }