1 //==- CFLAndersAliasAnalysis.h - Unification-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 //===----------------------------------------------------------------------===//
10 /// This is the interface for LLVM's inclusion-based alias analysis
11 /// implemented with CFL graph reachability.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_CFLANDERSALIASANALYSIS_H
16 #define LLVM_ANALYSIS_CFLANDERSALIASANALYSIS_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/Analysis/AliasAnalysis.h"
21 #include "llvm/Analysis/CFLAliasAnalysisUtils.h"
22 #include "llvm/IR/PassManager.h"
23 #include "llvm/Pass.h"
24 #include <forward_list>
31 class TargetLibraryInfo;
37 } // end namespace cflaa
39 class CFLAndersAAResult : public AAResultBase<CFLAndersAAResult> {
40 friend AAResultBase<CFLAndersAAResult>;
45 explicit CFLAndersAAResult(const TargetLibraryInfo &TLI);
46 CFLAndersAAResult(CFLAndersAAResult &&RHS);
49 /// Handle invalidation events from the new pass manager.
50 /// By definition, this result is stateless and so remains valid.
51 bool invalidate(Function &, const PreservedAnalyses &,
52 FunctionAnalysisManager::Invalidator &) {
56 /// Evict the given function from cache
57 void evict(const Function *Fn);
59 /// \brief Get the alias summary for the given function
60 /// Return nullptr if the summary is not found or not available
61 const cflaa::AliasSummary *getAliasSummary(const Function &);
63 AliasResult query(const MemoryLocation &, const MemoryLocation &);
64 AliasResult alias(const MemoryLocation &, const MemoryLocation &);
67 /// \brief Ensures that the given function is available in the cache.
68 /// Returns the appropriate entry from the cache.
69 const Optional<FunctionInfo> &ensureCached(const Function &);
71 /// \brief Inserts the given Function into the cache.
72 void scan(const Function &);
74 /// \brief Build summary for a given function
75 FunctionInfo buildInfoFrom(const Function &);
77 const TargetLibraryInfo &TLI;
79 /// \brief Cached mapping of Functions to their StratifiedSets.
80 /// If a function's sets are currently being built, it is marked
81 /// in the cache as an Optional without a value. This way, if we
82 /// have any kind of recursion, it is discernable from a function
83 /// that simply has empty sets.
84 DenseMap<const Function *, Optional<FunctionInfo>> Cache;
86 std::forward_list<cflaa::FunctionHandle<CFLAndersAAResult>> Handles;
89 /// Analysis pass providing a never-invalidated alias analysis result.
91 /// FIXME: We really should refactor CFL to use the analysis more heavily, and
92 /// in particular to leverage invalidation to trigger re-computation.
93 class CFLAndersAA : public AnalysisInfoMixin<CFLAndersAA> {
94 friend AnalysisInfoMixin<CFLAndersAA>;
96 static AnalysisKey Key;
99 using Result = CFLAndersAAResult;
101 CFLAndersAAResult run(Function &F, FunctionAnalysisManager &AM);
104 /// Legacy wrapper pass to provide the CFLAndersAAResult object.
105 class CFLAndersAAWrapperPass : public ImmutablePass {
106 std::unique_ptr<CFLAndersAAResult> Result;
111 CFLAndersAAWrapperPass();
113 CFLAndersAAResult &getResult() { return *Result; }
114 const CFLAndersAAResult &getResult() const { return *Result; }
116 void initializePass() override;
117 void getAnalysisUsage(AnalysisUsage &AU) const override;
120 // createCFLAndersAAWrapperPass - This pass implements a set-based approach to
122 ImmutablePass *createCFLAndersAAWrapperPass();
124 } // end namespace llvm
126 #endif // LLVM_ANALYSIS_CFLANDERSALIASANALYSIS_H