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