LLVM API Documentation

NoAliasAnalysis.cpp
Go to the documentation of this file.
00001 //===- NoAliasAnalysis.cpp - Minimal Alias Analysis Impl ------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the default implementation of the Alias Analysis interface
00011 // that simply returns "I don't know" for all queries.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "llvm/Analysis/Passes.h"
00016 #include "llvm/Analysis/AliasAnalysis.h"
00017 #include "llvm/IR/DataLayout.h"
00018 #include "llvm/IR/LLVMContext.h"
00019 #include "llvm/Pass.h"
00020 using namespace llvm;
00021 
00022 namespace {
00023   /// NoAA - This class implements the -no-aa pass, which always returns "I
00024   /// don't know" for alias queries.  NoAA is unlike other alias analysis
00025   /// implementations, in that it does not chain to a previous analysis.  As
00026   /// such it doesn't follow many of the rules that other alias analyses must.
00027   ///
00028   struct NoAA : public ImmutablePass, public AliasAnalysis {
00029     static char ID; // Class identification, replacement for typeinfo
00030     NoAA() : ImmutablePass(ID) {
00031       initializeNoAAPass(*PassRegistry::getPassRegistry());
00032     }
00033 
00034     void getAnalysisUsage(AnalysisUsage &AU) const override {}
00035 
00036     void initializePass() override {
00037       // Note: NoAA does not call InitializeAliasAnalysis because it's
00038       // special and does not support chaining.
00039       DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
00040       DL = DLP ? &DLP->getDataLayout() : nullptr;
00041     }
00042 
00043     AliasResult alias(const Location &LocA, const Location &LocB) override {
00044       return MayAlias;
00045     }
00046 
00047     ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
00048       return UnknownModRefBehavior;
00049     }
00050     ModRefBehavior getModRefBehavior(const Function *F) override {
00051       return UnknownModRefBehavior;
00052     }
00053 
00054     bool pointsToConstantMemory(const Location &Loc, bool OrLocal) override {
00055       return false;
00056     }
00057     Location getArgLocation(ImmutableCallSite CS, unsigned ArgIdx,
00058                             ModRefResult &Mask) override {
00059       Mask = ModRef;
00060       return Location(CS.getArgument(ArgIdx), UnknownSize,
00061                       CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa));
00062     }
00063 
00064     ModRefResult getModRefInfo(ImmutableCallSite CS,
00065                                const Location &Loc) override {
00066       return ModRef;
00067     }
00068     ModRefResult getModRefInfo(ImmutableCallSite CS1,
00069                                ImmutableCallSite CS2) override {
00070       return ModRef;
00071     }
00072 
00073     void deleteValue(Value *V) override {}
00074     void copyValue(Value *From, Value *To) override {}
00075     void addEscapingUse(Use &U) override {}
00076 
00077     /// getAdjustedAnalysisPointer - This method is used when a pass implements
00078     /// an analysis interface through multiple inheritance.  If needed, it
00079     /// should override this to adjust the this pointer as needed for the
00080     /// specified pass info.
00081     void *getAdjustedAnalysisPointer(const void *ID) override {
00082       if (ID == &AliasAnalysis::ID)
00083         return (AliasAnalysis*)this;
00084       return this;
00085     }
00086   };
00087 }  // End of anonymous namespace
00088 
00089 // Register this pass...
00090 char NoAA::ID = 0;
00091 INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
00092                    "No Alias Analysis (always returns 'may' alias)",
00093                    true, true, true)
00094 
00095 ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }