1 //===- ScopedNoAliasAA.h - Scoped No-Alias Alias Analysis -------*- C++ -*-===// 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 /// \file 10 /// This is the interface for a metadata-based scoped no-alias analysis. 11 /// 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_ANALYSIS_SCOPEDNOALIASAA_H 15 #define LLVM_ANALYSIS_SCOPEDNOALIASAA_H 16 17 #include "llvm/Analysis/AliasAnalysis.h" 18 #include "llvm/IR/Function.h" 19 #include "llvm/IR/Metadata.h" 20 #include "llvm/IR/Module.h" 21 #include "llvm/Pass.h" 22 23 namespace llvm { 24 25 /// A simple AA result which uses scoped-noalias metadata to answer queries. 26 class ScopedNoAliasAAResult : public AAResultBase<ScopedNoAliasAAResult> { 27 friend AAResultBase<ScopedNoAliasAAResult>; 28 29 public: ScopedNoAliasAAResult()30 explicit ScopedNoAliasAAResult() : AAResultBase() {} ScopedNoAliasAAResult(ScopedNoAliasAAResult && Arg)31 ScopedNoAliasAAResult(ScopedNoAliasAAResult &&Arg) 32 : AAResultBase(std::move(Arg)) {} 33 34 /// Handle invalidation events from the new pass manager. 35 /// 36 /// By definition, this result is stateless and so remains valid. invalidate(Function &,const PreservedAnalyses &)37 bool invalidate(Function &, const PreservedAnalyses &) { return false; } 38 39 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB); 40 ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc); 41 ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2); 42 43 private: 44 bool mayAliasInScopes(const MDNode *Scopes, const MDNode *NoAlias) const; 45 void collectMDInDomain(const MDNode *List, const MDNode *Domain, 46 SmallPtrSetImpl<const MDNode *> &Nodes) const; 47 }; 48 49 /// Analysis pass providing a never-invalidated alias analysis result. 50 class ScopedNoAliasAA : public AnalysisInfoMixin<ScopedNoAliasAA> { 51 friend AnalysisInfoMixin<ScopedNoAliasAA>; 52 static char PassID; 53 54 public: 55 typedef ScopedNoAliasAAResult Result; 56 57 ScopedNoAliasAAResult run(Function &F, AnalysisManager<Function> &AM); 58 }; 59 60 /// Legacy wrapper pass to provide the ScopedNoAliasAAResult object. 61 class ScopedNoAliasAAWrapperPass : public ImmutablePass { 62 std::unique_ptr<ScopedNoAliasAAResult> Result; 63 64 public: 65 static char ID; 66 67 ScopedNoAliasAAWrapperPass(); 68 getResult()69 ScopedNoAliasAAResult &getResult() { return *Result; } getResult()70 const ScopedNoAliasAAResult &getResult() const { return *Result; } 71 72 bool doInitialization(Module &M) override; 73 bool doFinalization(Module &M) override; 74 void getAnalysisUsage(AnalysisUsage &AU) const override; 75 }; 76 77 //===--------------------------------------------------------------------===// 78 // 79 // createScopedNoAliasAAWrapperPass - This pass implements metadata-based 80 // scoped noalias analysis. 81 // 82 ImmutablePass *createScopedNoAliasAAWrapperPass(); 83 } 84 85 #endif 86