blob: 0c119d645963d1cf0c2ae6261deb276429a26239 [file] [log] [blame]
Dan Gohmanda85ed82010-10-19 23:09:08 +00001//===- 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 Gohmanda85ed82010-10-19 23:09:08 +000015#include "llvm/Analysis/Passes.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "llvm/Analysis/AliasAnalysis.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000017#include "llvm/IR/DataLayout.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include "llvm/Pass.h"
Dan Gohmanda85ed82010-10-19 23:09:08 +000019using namespace llvm;
20
21namespace {
22 /// NoAA - This class implements the -no-aa pass, which always returns "I
23 /// don't know" for alias queries. NoAA is unlike other alias analysis
24 /// implementations, in that it does not chain to a previous analysis. As
25 /// such it doesn't follow many of the rules that other alias analyses must.
26 ///
27 struct NoAA : public ImmutablePass, public AliasAnalysis {
28 static char ID; // Class identification, replacement for typeinfo
29 NoAA() : ImmutablePass(ID) {
30 initializeNoAAPass(*PassRegistry::getPassRegistry());
31 }
32
Craig Toppere9ba7592014-03-05 07:30:04 +000033 void getAnalysisUsage(AnalysisUsage &AU) const override {}
Dan Gohmanda85ed82010-10-19 23:09:08 +000034
Craig Toppere9ba7592014-03-05 07:30:04 +000035 void initializePass() override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000036 // Note: NoAA does not call InitializeAliasAnalysis because it's
37 // special and does not support chaining.
Rafael Espindola93512512014-02-25 17:30:31 +000038 DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
39 DL = DLP ? &DLP->getDataLayout() : 0;
Dan Gohmanda85ed82010-10-19 23:09:08 +000040 }
41
Craig Toppere9ba7592014-03-05 07:30:04 +000042 AliasResult alias(const Location &LocA, const Location &LocB) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000043 return MayAlias;
44 }
45
Craig Toppere9ba7592014-03-05 07:30:04 +000046 ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000047 return UnknownModRefBehavior;
48 }
Craig Toppere9ba7592014-03-05 07:30:04 +000049 ModRefBehavior getModRefBehavior(const Function *F) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000050 return UnknownModRefBehavior;
51 }
52
Craig Toppere9ba7592014-03-05 07:30:04 +000053 bool pointsToConstantMemory(const Location &Loc, bool OrLocal) override {
Dan Gohman9130bad2010-11-08 16:45:26 +000054 return false;
55 }
Craig Toppere9ba7592014-03-05 07:30:04 +000056 ModRefResult getModRefInfo(ImmutableCallSite CS,
57 const Location &Loc) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000058 return ModRef;
59 }
Craig Toppere9ba7592014-03-05 07:30:04 +000060 ModRefResult getModRefInfo(ImmutableCallSite CS1,
61 ImmutableCallSite CS2) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000062 return ModRef;
63 }
64
Craig Toppere9ba7592014-03-05 07:30:04 +000065 void deleteValue(Value *V) override {}
66 void copyValue(Value *From, Value *To) override {}
67 void addEscapingUse(Use &U) override {}
68
Dan Gohmanda85ed82010-10-19 23:09:08 +000069 /// getAdjustedAnalysisPointer - This method is used when a pass implements
70 /// an analysis interface through multiple inheritance. If needed, it
71 /// should override this to adjust the this pointer as needed for the
72 /// specified pass info.
Craig Toppere9ba7592014-03-05 07:30:04 +000073 void *getAdjustedAnalysisPointer(const void *ID) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000074 if (ID == &AliasAnalysis::ID)
75 return (AliasAnalysis*)this;
76 return this;
77 }
78 };
79} // End of anonymous namespace
80
81// Register this pass...
82char NoAA::ID = 0;
83INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
84 "No Alias Analysis (always returns 'may' alias)",
85 true, true, true)
86
87ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }