LLVM  15.0.0git
CFLSteensAliasAnalysis.h
Go to the documentation of this file.
1 //==- CFLSteensAliasAnalysis.h - Unification-based Alias Analysis -*- C++-*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This is the interface for LLVM's unification-based alias analysis
10 /// implemented with CFL graph reachability.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H
15 #define LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H
16 
17 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/IR/PassManager.h"
22 #include "llvm/Pass.h"
23 #include <forward_list>
24 #include <memory>
25 
26 namespace llvm {
27 
28 class Function;
29 class TargetLibraryInfo;
30 
31 namespace cflaa {
32 
33 struct AliasSummary;
34 
35 } // end namespace cflaa
36 
37 class CFLSteensAAResult : public AAResultBase<CFLSteensAAResult> {
39 
40  class FunctionInfo;
41 
42 public:
43  explicit CFLSteensAAResult(
44  std::function<const TargetLibraryInfo &(Function &)> GetTLI);
47 
48  /// Handle invalidation events from the new pass manager.
49  ///
50  /// By definition, this result is stateless and so remains valid.
53  return false;
54  }
55 
56  /// Inserts the given Function into the cache.
57  void scan(Function *Fn);
58 
59  void evict(Function *Fn);
60 
61  /// Ensures that the given function is available in the cache.
62  /// Returns the appropriate entry from the cache.
64 
65  /// Get the alias summary for the given function
66  /// Return nullptr if the summary is not found or not available
68 
69  AliasResult query(const MemoryLocation &LocA, const MemoryLocation &LocB);
70 
71  AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
72  AAQueryInfo &AAQI) {
73  if (LocA.Ptr == LocB.Ptr)
75 
76  // Comparisons between global variables and other constants should be
77  // handled by BasicAA.
78  // CFLSteensAA may report NoAlias when comparing a GlobalValue and
79  // ConstantExpr, but every query needs to have at least one Value tied to a
80  // Function, and neither GlobalValues nor ConstantExprs are.
81  if (isa<Constant>(LocA.Ptr) && isa<Constant>(LocB.Ptr))
82  return AAResultBase::alias(LocA, LocB, AAQI);
83 
84  AliasResult QueryResult = query(LocA, LocB);
85  if (QueryResult == AliasResult::MayAlias)
86  return AAResultBase::alias(LocA, LocB, AAQI);
87 
88  return QueryResult;
89  }
90 
91 private:
92  std::function<const TargetLibraryInfo &(Function &)> GetTLI;
93 
94  /// Cached mapping of Functions to their StratifiedSets.
95  /// If a function's sets are currently being built, it is marked
96  /// in the cache as an Optional without a value. This way, if we
97  /// have any kind of recursion, it is discernable from a function
98  /// that simply has empty sets.
100  std::forward_list<cflaa::FunctionHandle<CFLSteensAAResult>> Handles;
101 
102  FunctionInfo buildSetsFrom(Function *F);
103 };
104 
105 /// Analysis pass providing a never-invalidated alias analysis result.
106 ///
107 /// FIXME: We really should refactor CFL to use the analysis more heavily, and
108 /// in particular to leverage invalidation to trigger re-computation of sets.
109 class CFLSteensAA : public AnalysisInfoMixin<CFLSteensAA> {
111 
112  static AnalysisKey Key;
113 
114 public:
116 
118 };
119 
120 /// Legacy wrapper pass to provide the CFLSteensAAResult object.
122  std::unique_ptr<CFLSteensAAResult> Result;
123 
124 public:
125  static char ID;
126 
128 
129  CFLSteensAAResult &getResult() { return *Result; }
130  const CFLSteensAAResult &getResult() const { return *Result; }
131 
132  void initializePass() override;
133  void getAnalysisUsage(AnalysisUsage &AU) const override;
134 };
135 
136 // createCFLSteensAAWrapperPass - This pass implements a set-based approach to
137 // alias analysis.
138 ImmutablePass *createCFLSteensAAWrapperPass();
139 
140 } // end namespace llvm
141 
142 #endif // LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
llvm::AliasResult::MayAlias
@ MayAlias
The two locations may or may not alias.
Definition: AliasAnalysis.h:102
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::CFLSteensAAResult::CFLSteensAAResult
CFLSteensAAResult(std::function< const TargetLibraryInfo &(Function &)> GetTLI)
llvm::ImmutablePass
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:279
llvm::MemoryLocation::Ptr
const Value * Ptr
The address of the start of the location.
Definition: MemoryLocation.h:218
llvm::Function
Definition: Function.h:60
Pass.h
llvm::CFLSteensAAResult::getAliasSummary
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...
Definition: CFLSteensAliasAnalysis.cpp:258
llvm::CFLSteensAAResult
Definition: CFLSteensAliasAnalysis.h:37
DenseMap.h
llvm::createCFLSteensAAWrapperPass
ImmutablePass * createCFLSteensAAWrapperPass()
llvm::Optional
Definition: APInt.h:33
llvm::AliasResult
The possible results of an alias query.
Definition: AliasAnalysis.h:81
llvm::CFLSteensAAResult::invalidate
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle invalidation events from the new pass manager.
Definition: CFLSteensAliasAnalysis.h:51
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::CFLSteensAAResult::~CFLSteensAAResult
~CFLSteensAAResult()
AliasAnalysis.h
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
llvm::AAQueryInfo
This class stores info we want to provide to or retain within an alias query.
Definition: AliasAnalysis.h:462
llvm::CFLSteensAAWrapperPass::ID
static char ID
Definition: CFLSteensAliasAnalysis.h:125
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::AnalysisManager::Invalidator
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:667
llvm::CFLSteensAA
Analysis pass providing a never-invalidated alias analysis result.
Definition: CFLSteensAliasAnalysis.h:109
llvm::AAResultBase::alias
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI)
Definition: AliasAnalysis.h:1222
llvm::CFLSteensAAWrapperPass::getResult
const CFLSteensAAResult & getResult() const
Definition: CFLSteensAliasAnalysis.h:130
llvm::CFLSteensAAResult::scan
void scan(Function *Fn)
Inserts the given Function into the cache.
Definition: CFLSteensAliasAnalysis.cpp:227
llvm::CFLSteensAA::run
CFLSteensAAResult run(Function &F, FunctionAnalysisManager &AM)
Definition: CFLSteensAliasAnalysis.cpp:335
MemoryLocation.h
llvm::DenseMap
Definition: DenseMap.h:716
llvm::CFLSteensAAResult::alias
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI)
Definition: CFLSteensAliasAnalysis.h:71
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69
llvm::CFLSteensAAResult::evict
void evict(Function *Fn)
Definition: CFLSteensAliasAnalysis.cpp:242
llvm::CFLSteensAAWrapperPass
Legacy wrapper pass to provide the CFLSteensAAResult object.
Definition: CFLSteensAliasAnalysis.h:121
llvm::CFLSteensAAWrapperPass::getResult
CFLSteensAAResult & getResult()
Definition: CFLSteensAliasAnalysis.h:129
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::AnalysisInfoMixin
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:394
llvm::cflaa::AliasSummary
AliasSummary is just a collection of ExternalRelation and ExternalAttribute.
Definition: AliasAnalysisSummary.h:193
llvm::AliasResult::MustAlias
@ MustAlias
The two locations precisely alias each other.
Definition: AliasAnalysis.h:106
llvm::CFLSteensAAResult::query
AliasResult query(const MemoryLocation &LocA, const MemoryLocation &LocB)
Definition: CFLSteensAliasAnalysis.cpp:266
llvm::CFLSteensAAResult::FunctionInfo
Information we have about a function and would like to keep around.
Definition: CFLSteensAliasAnalysis.cpp:72
PassManager.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:222
llvm::CFLSteensAAWrapperPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: CFLSteensAliasAnalysis.cpp:361
llvm::CFLSteensAAResult::ensureCached
const Optional< FunctionInfo > & ensureCached(Function *Fn)
Ensures that the given function is available in the cache.
Definition: CFLSteensAliasAnalysis.cpp:247
llvm::CFLSteensAAWrapperPass::initializePass
void initializePass() override
initializePass - This method may be overriden by immutable passes to allow them to perform various in...
Definition: CFLSteensAliasAnalysis.cpp:354
CFLAliasAnalysisUtils.h
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::CFLSteensAAWrapperPass::CFLSteensAAWrapperPass
CFLSteensAAWrapperPass()
Definition: CFLSteensAliasAnalysis.cpp:350
llvm::AAResultBase
A CRTP-driven "mixin" base class to help implement the function alias analysis results concept.
Definition: AliasAnalysis.h:1134
llvm::MemoryLocation
Representation for a specific memory location.
Definition: MemoryLocation.h:210
llvm::codeview::PublicSymFlags::Function
@ Function