blob: 203e1daf7a09e9a5dfbd779387dee7169890ded6 [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 }
Hal Finkel354e23b2014-07-17 01:28:25 +000058 Location getArgLocation(ImmutableCallSite CS, unsigned ArgIdx,
59 ModRefResult &Mask) override {
60 Mask = ModRef;
Benjamin Kramer12a2d102014-10-05 12:21:57 +000061 AAMDNodes AATags;
62 CS->getAAMetadata(AATags);
Benjamin Kramer2e52f022014-10-04 22:44:29 +000063 return Location(CS.getArgument(ArgIdx), UnknownSize, AATags);
Hal Finkel354e23b2014-07-17 01:28:25 +000064 }
65
Craig Toppere9ba7592014-03-05 07:30:04 +000066 ModRefResult getModRefInfo(ImmutableCallSite CS,
67 const Location &Loc) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000068 return ModRef;
69 }
Craig Toppere9ba7592014-03-05 07:30:04 +000070 ModRefResult getModRefInfo(ImmutableCallSite CS1,
71 ImmutableCallSite CS2) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000072 return ModRef;
73 }
74
Craig Toppere9ba7592014-03-05 07:30:04 +000075 void deleteValue(Value *V) override {}
76 void copyValue(Value *From, Value *To) override {}
77 void addEscapingUse(Use &U) override {}
78
Dan Gohmanda85ed82010-10-19 23:09:08 +000079 /// getAdjustedAnalysisPointer - This method is used when a pass implements
80 /// an analysis interface through multiple inheritance. If needed, it
81 /// should override this to adjust the this pointer as needed for the
82 /// specified pass info.
Craig Toppere9ba7592014-03-05 07:30:04 +000083 void *getAdjustedAnalysisPointer(const void *ID) override {
Dan Gohmanda85ed82010-10-19 23:09:08 +000084 if (ID == &AliasAnalysis::ID)
85 return (AliasAnalysis*)this;
86 return this;
87 }
88 };
89} // End of anonymous namespace
90
91// Register this pass...
92char NoAA::ID = 0;
93INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
94 "No Alias Analysis (always returns 'may' alias)",
95 true, true, true)
96
97ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }