Home | History | Annotate | Download | only in Analysis
      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   /// Handle invalidation events from the new pass manager.
     31   ///
     32   /// By definition, this result is stateless and so remains valid.
     33   bool invalidate(Function &, const PreservedAnalyses &,
     34                   FunctionAnalysisManager::Invalidator &) {
     35     return false;
     36   }
     37 
     38   AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
     39   bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
     40   FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS);
     41   FunctionModRefBehavior getModRefBehavior(const Function *F);
     42   ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
     43   ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2);
     44 
     45 private:
     46   bool Aliases(const MDNode *A, const MDNode *B) const;
     47   bool PathAliases(const MDNode *A, const MDNode *B) const;
     48 };
     49 
     50 /// Analysis pass providing a never-invalidated alias analysis result.
     51 class TypeBasedAA : public AnalysisInfoMixin<TypeBasedAA> {
     52   friend AnalysisInfoMixin<TypeBasedAA>;
     53   static AnalysisKey Key;
     54 
     55 public:
     56   typedef TypeBasedAAResult Result;
     57 
     58   TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM);
     59 };
     60 
     61 /// Legacy wrapper pass to provide the TypeBasedAAResult object.
     62 class TypeBasedAAWrapperPass : public ImmutablePass {
     63   std::unique_ptr<TypeBasedAAResult> Result;
     64 
     65 public:
     66   static char ID;
     67 
     68   TypeBasedAAWrapperPass();
     69 
     70   TypeBasedAAResult &getResult() { return *Result; }
     71   const TypeBasedAAResult &getResult() const { return *Result; }
     72 
     73   bool doInitialization(Module &M) override;
     74   bool doFinalization(Module &M) override;
     75   void getAnalysisUsage(AnalysisUsage &AU) const override;
     76 };
     77 
     78 //===--------------------------------------------------------------------===//
     79 //
     80 // createTypeBasedAAWrapperPass - This pass implements metadata-based
     81 // type-based alias analysis.
     82 //
     83 ImmutablePass *createTypeBasedAAWrapperPass();
     84 }
     85 
     86 #endif
     87