blob: 9a5430e0bc0fd4aa76f94b5373eb5da537bd2bb9 [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"
Hal Finkel354e23b2014-07-17 01:28:25 +000018#include "llvm/IR/LLVMContext.h"
Mehdi Amini46a43552015-03-04 18:43:29 +000019#include "llvm/IR/Module.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/Pass.h"
Dan Gohmanda85ed82010-10-19 23:09:08 +000021using namespace llvm;
22
23namespace {
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 Toppere9ba7592014-03-05 07:30:04 +000035 void getAnalysisUsage(AnalysisUsage &AU) const override {}
Dan Gohmanda85ed82010-10-19 23:09:08 +000036
Mehdi Amini46a43552015-03-04 18:43:29 +000037 bool doInitialization(Module &M) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000038 // Note: NoAA does not call InitializeAliasAnalysis because it's
39 // special and does not support chaining.
Mehdi Amini46a43552015-03-04 18:43:29 +000040 DL = &M.getDataLayout();
41 return true;
Dan Gohmanda85ed82010-10-19 23:09:08 +000042 }
43
Craig Toppere9ba7592014-03-05 07:30:04 +000044 AliasResult alias(const Location &LocA, const Location &LocB) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000045 return MayAlias;
46 }
47
Craig Toppere9ba7592014-03-05 07:30:04 +000048 ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000049 return UnknownModRefBehavior;
50 }
Craig Toppere9ba7592014-03-05 07:30:04 +000051 ModRefBehavior getModRefBehavior(const Function *F) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000052 return UnknownModRefBehavior;
53 }
54
Craig Toppere9ba7592014-03-05 07:30:04 +000055 bool pointsToConstantMemory(const Location &Loc, bool OrLocal) override {
Dan Gohman9130bad2010-11-08 16:45:26 +000056 return false;
57 }
Chandler Carruthc41404a2015-06-17 07:12:40 +000058 ModRefResult getArgModRefInfo(ImmutableCallSite CS,
59 unsigned ArgIdx) override {
60 return ModRef;
Hal Finkel354e23b2014-07-17 01:28:25 +000061 }
62
Craig Toppere9ba7592014-03-05 07:30:04 +000063 ModRefResult getModRefInfo(ImmutableCallSite CS,
64 const Location &Loc) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000065 return ModRef;
66 }
Craig Toppere9ba7592014-03-05 07:30:04 +000067 ModRefResult getModRefInfo(ImmutableCallSite CS1,
68 ImmutableCallSite CS2) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000069 return ModRef;
70 }
71
Craig Toppere9ba7592014-03-05 07:30:04 +000072 void deleteValue(Value *V) override {}
73 void copyValue(Value *From, Value *To) override {}
74 void addEscapingUse(Use &U) override {}
75
Dan Gohmanda85ed82010-10-19 23:09:08 +000076 /// 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 Toppere9ba7592014-03-05 07:30:04 +000080 void *getAdjustedAnalysisPointer(const void *ID) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000081 if (ID == &AliasAnalysis::ID)
82 return (AliasAnalysis*)this;
83 return this;
84 }
85 };
86} // End of anonymous namespace
87
88// Register this pass...
89char NoAA::ID = 0;
90INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
91 "No Alias Analysis (always returns 'may' alias)",
92 true, true, true)
93
94ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }