LLVM  5.0.0
CFLSteensAliasAnalysis.h
Go to the documentation of this file.
1 //=- CFLSteensAliasAnalysis.h - Unification-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 LLVM's unification-based alias analysis
11 /// implemented with CFL graph reachability.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H
16 #define LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H
17 
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/None.h"
20 #include "llvm/ADT/Optional.h"
23 #include "llvm/IR/Function.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/IR/ValueHandle.h"
26 #include "llvm/Pass.h"
27 #include <forward_list>
28 
29 namespace llvm {
30 
31 class TargetLibraryInfo;
32 
33 namespace cflaa {
34 struct AliasSummary;
35 }
36 
37 class CFLSteensAAResult : public AAResultBase<CFLSteensAAResult> {
39  class FunctionInfo;
40 
41 public:
42  explicit CFLSteensAAResult(const TargetLibraryInfo &);
45 
46  /// Handle invalidation events from the new pass manager.
47  ///
48  /// By definition, this result is stateless and so remains valid.
51  return false;
52  }
53 
54  /// \brief Inserts the given Function into the cache.
55  void scan(Function *Fn);
56 
57  void evict(Function *Fn);
58 
59  /// \brief Ensures that the given function is available in the cache.
60  /// Returns the appropriate entry from the cache.
62 
63  /// \brief Get the alias summary for the given function
64  /// Return nullptr if the summary is not found or not available
66 
67  AliasResult query(const MemoryLocation &LocA, const MemoryLocation &LocB);
68 
69  AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
70  if (LocA.Ptr == LocB.Ptr)
71  return LocA.Size == LocB.Size ? MustAlias : PartialAlias;
72 
73  // Comparisons between global variables and other constants should be
74  // handled by BasicAA.
75  // CFLSteensAA may report NoAlias when comparing a GlobalValue and
76  // ConstantExpr, but every query needs to have at least one Value tied to a
77  // Function, and neither GlobalValues nor ConstantExprs are.
78  if (isa<Constant>(LocA.Ptr) && isa<Constant>(LocB.Ptr))
79  return AAResultBase::alias(LocA, LocB);
80 
81  AliasResult QueryResult = query(LocA, LocB);
82  if (QueryResult == MayAlias)
83  return AAResultBase::alias(LocA, LocB);
84 
85  return QueryResult;
86  }
87 
88 private:
89  const TargetLibraryInfo &TLI;
90 
91  /// \brief Cached mapping of Functions to their StratifiedSets.
92  /// If a function's sets are currently being built, it is marked
93  /// in the cache as an Optional without a value. This way, if we
94  /// have any kind of recursion, it is discernable from a function
95  /// that simply has empty sets.
97  std::forward_list<cflaa::FunctionHandle<CFLSteensAAResult>> Handles;
98 
99  FunctionInfo buildSetsFrom(Function *F);
100 };
101 
102 /// Analysis pass providing a never-invalidated alias analysis result.
103 ///
104 /// FIXME: We really should refactor CFL to use the analysis more heavily, and
105 /// in particular to leverage invalidation to trigger re-computation of sets.
106 class CFLSteensAA : public AnalysisInfoMixin<CFLSteensAA> {
108  static AnalysisKey Key;
109 
110 public:
112 
114 };
115 
116 /// Legacy wrapper pass to provide the CFLSteensAAResult object.
118  std::unique_ptr<CFLSteensAAResult> Result;
119 
120 public:
121  static char ID;
122 
124 
125  CFLSteensAAResult &getResult() { return *Result; }
126  const CFLSteensAAResult &getResult() const { return *Result; }
127 
128  void initializePass() override;
129  void getAnalysisUsage(AnalysisUsage &AU) const override;
130 };
131 
132 //===--------------------------------------------------------------------===//
133 //
134 // createCFLSteensAAWrapperPass - This pass implements a set-based approach to
135 // alias analysis.
136 //
137 ImmutablePass *createCFLSteensAAWrapperPass();
138 }
139 
140 #endif
The two locations precisely alias each other.
Definition: AliasAnalysis.h:85
const cflaa::AliasSummary * getAliasSummary(Function &Fn)
Get the alias summary for the given function Return nullptr if the summary is not found or not availa...
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle invalidation events from the new pass manager.
The two locations alias, but only due to a partial overlap.
Definition: AliasAnalysis.h:83
const Optional< FunctionInfo > & ensureCached(Function *Fn)
Ensures that the given function is available in the cache.
The two locations may or may not alias. This is the least precise result.
Definition: AliasAnalysis.h:81
CFLSteensAAResult run(Function &F, FunctionAnalysisManager &AM)
CFLSteensAAResult Result
A CRTP-driven "mixin" base class to help implement the function alias analysis results concept...
CFLSteensAAResult(const TargetLibraryInfo &)
#define F(x, y, z)
Definition: MD5.cpp:55
AliasSummary is just a collection of ExternalRelation and ExternalAttribute.
Legacy wrapper pass to provide the CFLSteensAAResult object.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
void scan(Function *Fn)
Inserts the given Function into the cache.
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
void initializePass() override
initializePass - This method may be overriden by immutable passes to allow them to perform various in...
Analysis pass providing a never-invalidated alias analysis result.
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:382
AliasResult
The possible results of an alias query.
Definition: AliasAnalysis.h:73
Represent the analysis usage information of a pass.
const CFLSteensAAResult & getResult() const
AliasResult query(const MemoryLocation &LocA, const MemoryLocation &LocB)
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:266
Module.h This file contains the declarations for the Module class.
Provides information about what library functions are available for the current target.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Information we have about a function and would like to keep around.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
ImmutablePass * createCFLSteensAAWrapperPass()
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:559
A container for analyses that lazily runs them and caches their results.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:70
uint64_t Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known...