blob: 7617622b9ab6b9ac758243c3c78a2ee9b710244d [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
Chandler Carruthac80dc72015-06-17 07:18:54 +000044 AliasResult alias(const MemoryLocation &LocA,
45 const MemoryLocation &LocB) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000046 return MayAlias;
47 }
48
Craig Toppere9ba7592014-03-05 07:30:04 +000049 ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000050 return UnknownModRefBehavior;
51 }
Craig Toppere9ba7592014-03-05 07:30:04 +000052 ModRefBehavior getModRefBehavior(const Function *F) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000053 return UnknownModRefBehavior;
54 }
55
Chandler Carruthac80dc72015-06-17 07:18:54 +000056 bool pointsToConstantMemory(const MemoryLocation &Loc,
57 bool OrLocal) override {
Dan Gohman9130bad2010-11-08 16:45:26 +000058 return false;
59 }
Chandler Carruthc41404a2015-06-17 07:12:40 +000060 ModRefResult getArgModRefInfo(ImmutableCallSite CS,
61 unsigned ArgIdx) override {
62 return ModRef;
Hal Finkel354e23b2014-07-17 01:28:25 +000063 }
64
Craig Toppere9ba7592014-03-05 07:30:04 +000065 ModRefResult getModRefInfo(ImmutableCallSite CS,
Chandler Carruthac80dc72015-06-17 07:18:54 +000066 const MemoryLocation &Loc) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000067 return ModRef;
68 }
Craig Toppere9ba7592014-03-05 07:30:04 +000069 ModRefResult getModRefInfo(ImmutableCallSite CS1,
70 ImmutableCallSite CS2) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000071 return ModRef;
72 }
73
Craig Toppere9ba7592014-03-05 07:30:04 +000074 void deleteValue(Value *V) override {}
75 void copyValue(Value *From, Value *To) override {}
76 void addEscapingUse(Use &U) override {}
77
Dan Gohmanda85ed82010-10-19 23:09:08 +000078 /// getAdjustedAnalysisPointer - This method is used when a pass implements
79 /// an analysis interface through multiple inheritance. If needed, it
80 /// should override this to adjust the this pointer as needed for the
81 /// specified pass info.
Craig Toppere9ba7592014-03-05 07:30:04 +000082 void *getAdjustedAnalysisPointer(const void *ID) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000083 if (ID == &AliasAnalysis::ID)
84 return (AliasAnalysis*)this;
85 return this;
86 }
87 };
88} // End of anonymous namespace
89
90// Register this pass...
91char NoAA::ID = 0;
92INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
93 "No Alias Analysis (always returns 'may' alias)",
94 true, true, true)
95
96ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }