1 //===- TypeBasedAliasAnalysis.h - Type-Based Alias Analysis -----*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
11 /// This is the interface for a metadata-based TBAA. See the source file for
12 /// details on the algorithm.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
17 #define LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
19 #include "llvm/Analysis/AliasAnalysis.h"
20 #include "llvm/IR/CallSite.h"
21 #include "llvm/IR/PassManager.h"
22 #include "llvm/Pass.h"
31 /// A simple AA result that uses TBAA metadata to answer queries.
32 class TypeBasedAAResult : public AAResultBase<TypeBasedAAResult> {
33 friend AAResultBase<TypeBasedAAResult>;
36 /// Handle invalidation events from the new pass manager.
38 /// By definition, this result is stateless and so remains valid.
39 bool invalidate(Function &, const PreservedAnalyses &,
40 FunctionAnalysisManager::Invalidator &) {
44 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
45 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
46 FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS);
47 FunctionModRefBehavior getModRefBehavior(const Function *F);
48 ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
49 ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2);
52 bool Aliases(const MDNode *A, const MDNode *B) const;
53 bool PathAliases(const MDNode *A, const MDNode *B) const;
56 /// Analysis pass providing a never-invalidated alias analysis result.
57 class TypeBasedAA : public AnalysisInfoMixin<TypeBasedAA> {
58 friend AnalysisInfoMixin<TypeBasedAA>;
60 static AnalysisKey Key;
63 using Result = TypeBasedAAResult;
65 TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM);
68 /// Legacy wrapper pass to provide the TypeBasedAAResult object.
69 class TypeBasedAAWrapperPass : public ImmutablePass {
70 std::unique_ptr<TypeBasedAAResult> Result;
75 TypeBasedAAWrapperPass();
77 TypeBasedAAResult &getResult() { return *Result; }
78 const TypeBasedAAResult &getResult() const { return *Result; }
80 bool doInitialization(Module &M) override;
81 bool doFinalization(Module &M) override;
82 void getAnalysisUsage(AnalysisUsage &AU) const override;
85 //===--------------------------------------------------------------------===//
87 // createTypeBasedAAWrapperPass - This pass implements metadata-based
88 // type-based alias analysis.
90 ImmutablePass *createTypeBasedAAWrapperPass();
92 } // end namespace llvm
94 #endif // LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H