1 //===- TypeBasedAliasAnalysis.h - Type-Based 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 TBAA. See the source file for 11 /// details on the algorithm. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H 16 #define LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H 17 18 #include "llvm/Analysis/AliasAnalysis.h" 19 #include "llvm/IR/Function.h" 20 #include "llvm/IR/Metadata.h" 21 #include "llvm/Pass.h" 22 23 namespace llvm { 24 25 /// A simple AA result that uses TBAA metadata to answer queries. 26 class TypeBasedAAResult : public AAResultBase<TypeBasedAAResult> { 27 friend AAResultBase<TypeBasedAAResult>; 28 29 public: 30 explicit TypeBasedAAResult(const TargetLibraryInfo &TLI) 31 : AAResultBase(TLI) {} 32 TypeBasedAAResult(TypeBasedAAResult &&Arg) : 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. 37 bool invalidate(Function &, const PreservedAnalyses &) { return false; } 38 39 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB); 40 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal); 41 FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS); 42 FunctionModRefBehavior getModRefBehavior(const Function *F); 43 ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc); 44 ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2); 45 46 private: 47 bool Aliases(const MDNode *A, const MDNode *B) const; 48 bool PathAliases(const MDNode *A, const MDNode *B) const; 49 }; 50 51 /// Analysis pass providing a never-invalidated alias analysis result. 52 class TypeBasedAA { 53 public: 54 typedef TypeBasedAAResult Result; 55 56 /// \brief Opaque, unique identifier for this analysis pass. 57 static void *ID() { return (void *)&PassID; } 58 59 TypeBasedAAResult run(Function &F, AnalysisManager<Function> *AM); 60 61 /// \brief Provide access to a name for this pass for debugging purposes. 62 static StringRef name() { return "TypeBasedAA"; } 63 64 private: 65 static char PassID; 66 }; 67 68 /// Legacy wrapper pass to provide the TypeBasedAAResult object. 69 class TypeBasedAAWrapperPass : public ImmutablePass { 70 std::unique_ptr<TypeBasedAAResult> Result; 71 72 public: 73 static char ID; 74 75 TypeBasedAAWrapperPass(); 76 77 TypeBasedAAResult &getResult() { return *Result; } 78 const TypeBasedAAResult &getResult() const { return *Result; } 79 80 bool doInitialization(Module &M) override; 81 bool doFinalization(Module &M) override; 82 void getAnalysisUsage(AnalysisUsage &AU) const override; 83 }; 84 85 //===--------------------------------------------------------------------===// 86 // 87 // createTypeBasedAAWrapperPass - This pass implements metadata-based 88 // type-based alias analysis. 89 // 90 ImmutablePass *createTypeBasedAAWrapperPass(); 91 } 92 93 #endif 94