Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 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 | |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 15 | #include "llvm/Analysis/Passes.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/Analysis/AliasAnalysis.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 17 | #include "llvm/IR/DataLayout.h" |
Hal Finkel | 354e23b | 2014-07-17 01:28:25 +0000 | [diff] [blame] | 18 | #include "llvm/IR/LLVMContext.h" |
Mehdi Amini | 46a4355 | 2015-03-04 18:43:29 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Module.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/Pass.h" |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 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 |
| 31 | NoAA() : ImmutablePass(ID) { |
| 32 | initializeNoAAPass(*PassRegistry::getPassRegistry()); |
| 33 | } |
| 34 | |
Craig Topper | e9ba759 | 2014-03-05 07:30:04 +0000 | [diff] [blame] | 35 | void getAnalysisUsage(AnalysisUsage &AU) const override {} |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 36 | |
Mehdi Amini | 46a4355 | 2015-03-04 18:43:29 +0000 | [diff] [blame] | 37 | bool doInitialization(Module &M) override { |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 38 | // Note: NoAA does not call InitializeAliasAnalysis because it's |
| 39 | // special and does not support chaining. |
Mehdi Amini | 46a4355 | 2015-03-04 18:43:29 +0000 | [diff] [blame] | 40 | DL = &M.getDataLayout(); |
| 41 | return true; |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Craig Topper | e9ba759 | 2014-03-05 07:30:04 +0000 | [diff] [blame] | 44 | AliasResult alias(const Location &LocA, const Location &LocB) override { |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 45 | return MayAlias; |
| 46 | } |
| 47 | |
Craig Topper | e9ba759 | 2014-03-05 07:30:04 +0000 | [diff] [blame] | 48 | ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override { |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 49 | return UnknownModRefBehavior; |
| 50 | } |
Craig Topper | e9ba759 | 2014-03-05 07:30:04 +0000 | [diff] [blame] | 51 | ModRefBehavior getModRefBehavior(const Function *F) override { |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 52 | return UnknownModRefBehavior; |
| 53 | } |
| 54 | |
Craig Topper | e9ba759 | 2014-03-05 07:30:04 +0000 | [diff] [blame] | 55 | bool pointsToConstantMemory(const Location &Loc, bool OrLocal) override { |
Dan Gohman | 9130bad | 2010-11-08 16:45:26 +0000 | [diff] [blame] | 56 | return false; |
| 57 | } |
Chandler Carruth | c41404a | 2015-06-17 07:12:40 +0000 | [diff] [blame^] | 58 | ModRefResult getArgModRefInfo(ImmutableCallSite CS, |
| 59 | unsigned ArgIdx) override { |
| 60 | return ModRef; |
Hal Finkel | 354e23b | 2014-07-17 01:28:25 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Craig Topper | e9ba759 | 2014-03-05 07:30:04 +0000 | [diff] [blame] | 63 | ModRefResult getModRefInfo(ImmutableCallSite CS, |
| 64 | const Location &Loc) override { |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 65 | return ModRef; |
| 66 | } |
Craig Topper | e9ba759 | 2014-03-05 07:30:04 +0000 | [diff] [blame] | 67 | ModRefResult getModRefInfo(ImmutableCallSite CS1, |
| 68 | ImmutableCallSite CS2) override { |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 69 | return ModRef; |
| 70 | } |
| 71 | |
Craig Topper | e9ba759 | 2014-03-05 07:30:04 +0000 | [diff] [blame] | 72 | void deleteValue(Value *V) override {} |
| 73 | void copyValue(Value *From, Value *To) override {} |
| 74 | void addEscapingUse(Use &U) override {} |
| 75 | |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 76 | /// getAdjustedAnalysisPointer - This method is used when a pass implements |
| 77 | /// an analysis interface through multiple inheritance. If needed, it |
| 78 | /// should override this to adjust the this pointer as needed for the |
| 79 | /// specified pass info. |
Craig Topper | e9ba759 | 2014-03-05 07:30:04 +0000 | [diff] [blame] | 80 | void *getAdjustedAnalysisPointer(const void *ID) override { |
Dan Gohman | da85ed8 | 2010-10-19 23:09:08 +0000 | [diff] [blame] | 81 | if (ID == &AliasAnalysis::ID) |
| 82 | return (AliasAnalysis*)this; |
| 83 | return this; |
| 84 | } |
| 85 | }; |
| 86 | } // End of anonymous namespace |
| 87 | |
| 88 | // Register this pass... |
| 89 | char NoAA::ID = 0; |
| 90 | INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa", |
| 91 | "No Alias Analysis (always returns 'may' alias)", |
| 92 | true, true, true) |
| 93 | |
| 94 | ImmutablePass *llvm::createNoAAPass() { return new NoAA(); } |