blob: a039a26437f2d11365d010df4afa9b6f8c09f5ed [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
33 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
34 }
35
36 virtual void initializePass() {
37 // Note: NoAA does not call InitializeAliasAnalysis because it's
38 // special and does not support chaining.
Rafael Espindola93512512014-02-25 17:30:31 +000039 DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
40 DL = DLP ? &DLP->getDataLayout() : 0;
Dan Gohmanda85ed82010-10-19 23:09:08 +000041 }
42
43 virtual AliasResult alias(const Location &LocA, const Location &LocB) {
44 return MayAlias;
45 }
46
47 virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS) {
48 return UnknownModRefBehavior;
49 }
50 virtual ModRefBehavior getModRefBehavior(const Function *F) {
51 return UnknownModRefBehavior;
52 }
53
Dan Gohman9130bad2010-11-08 16:45:26 +000054 virtual bool pointsToConstantMemory(const Location &Loc,
55 bool OrLocal) {
56 return false;
57 }
Dan Gohmanda85ed82010-10-19 23:09:08 +000058 virtual ModRefResult getModRefInfo(ImmutableCallSite CS,
59 const Location &Loc) {
60 return ModRef;
61 }
62 virtual ModRefResult getModRefInfo(ImmutableCallSite CS1,
63 ImmutableCallSite CS2) {
64 return ModRef;
65 }
66
67 virtual void deleteValue(Value *V) {}
68 virtual void copyValue(Value *From, Value *To) {}
Owen Andersond62d3722011-01-03 23:51:43 +000069 virtual void addEscapingUse(Use &U) {}
Dan Gohmanda85ed82010-10-19 23:09:08 +000070
71 /// getAdjustedAnalysisPointer - This method is used when a pass implements
72 /// an analysis interface through multiple inheritance. If needed, it
73 /// should override this to adjust the this pointer as needed for the
74 /// specified pass info.
75 virtual void *getAdjustedAnalysisPointer(const void *ID) {
76 if (ID == &AliasAnalysis::ID)
77 return (AliasAnalysis*)this;
78 return this;
79 }
80 };
81} // End of anonymous namespace
82
83// Register this pass...
84char NoAA::ID = 0;
85INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
86 "No Alias Analysis (always returns 'may' alias)",
87 true, true, true)
88
89ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }