1 //===- NoAliasAnalysis.cpp - Minimal Alias Analysis Impl ------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the default implementation of the Alias Analysis interface
11 // that simply returns "I don't know" for all queries.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Analysis/Passes.h"
16 #include "llvm/Analysis/AliasAnalysis.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/Pass.h"
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.
27 struct NoAA : public ImmutablePass, public AliasAnalysis {
28 static char ID; // Class identification, replacement for typeinfo
29 NoAA() : ImmutablePass(ID) {
30 initializeNoAAPass(*PassRegistry::getPassRegistry());
33 void getAnalysisUsage(AnalysisUsage &AU) const override {}
35 void initializePass() override {
36 // Note: NoAA does not call InitializeAliasAnalysis because it's
37 // special and does not support chaining.
38 DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
39 DL = DLP ? &DLP->getDataLayout() : nullptr;
42 AliasResult alias(const Location &LocA, const Location &LocB) override {
46 ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
47 return UnknownModRefBehavior;
49 ModRefBehavior getModRefBehavior(const Function *F) override {
50 return UnknownModRefBehavior;
53 bool pointsToConstantMemory(const Location &Loc, bool OrLocal) override {
56 ModRefResult getModRefInfo(ImmutableCallSite CS,
57 const Location &Loc) override {
60 ModRefResult getModRefInfo(ImmutableCallSite CS1,
61 ImmutableCallSite CS2) override {
65 void deleteValue(Value *V) override {}
66 void copyValue(Value *From, Value *To) override {}
67 void addEscapingUse(Use &U) override {}
69 /// 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.
73 void *getAdjustedAnalysisPointer(const void *ID) override {
74 if (ID == &AliasAnalysis::ID)
75 return (AliasAnalysis*)this;
79 } // End of anonymous namespace
81 // Register this pass...
83 INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
84 "No Alias Analysis (always returns 'may' alias)",
87 ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }