Go to the documentation of this file.
14 #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DATAFLOWANALYSIS_H
15 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DATAFLOWANALYSIS_H
27 #include "llvm/ADT/Any.h"
28 #include "llvm/ADT/Optional.h"
29 #include "llvm/ADT/STLExtras.h"
30 #include "llvm/Support/Error.h"
59 template <
typename Derived,
typename LatticeT>
72 return {
static_cast<Derived *
>(
this)->initialElement()};
77 Lattice &L1 = llvm::any_cast<Lattice &>(E1.Value);
78 const Lattice &L2 = llvm::any_cast<const Lattice &>(E2.Value);
84 const Lattice &L1 = llvm::any_cast<const Lattice &>(E1.Value);
85 const Lattice &L2 = llvm::any_cast<const Lattice &>(E2.Value);
91 Lattice &L = llvm::any_cast<Lattice &>(E.Value);
113 template <
typename AnalysisT>
118 auto TypeErasedBlockStates =
120 if (!TypeErasedBlockStates)
121 return TypeErasedBlockStates.takeError();
126 BlockStates.reserve(TypeErasedBlockStates->size());
128 llvm::transform(std::move(*TypeErasedBlockStates),
129 std::back_inserter(BlockStates), [](
auto &OptState) {
130 return std::move(OptState).map([](
auto &&
State) {
132 llvm::any_cast<typename AnalysisT::Lattice>(
133 std::move(
State.Lattice.Value)),
134 std::move(
State.Env)};
152 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DATAFLOWANALYSIS_H
Abstract base class for dataflow "models": reusable analysis components that model a particular aspec...
Type-erased lattice element container.
LatticeJoinEffect joinTypeErased(TypeErasedLattice &E1, const TypeErasedLattice &E2) final
Joins two type-erased lattice elements by computing their least upper bound.
void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env)
Evaluates S and updates Env accordingly.
LatticeJoinEffect join(const SourceLocationsLattice &Other)
LatticeJoinEffect
Effect indicating whether a lattice join operation resulted in a new value.
ASTContext & getASTContext() final
Returns the ASTContext that is used by the analysis.
Base class template for dataflow analyses built on a single lattice type.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
DataflowAnalysis(ASTContext &Context, bool ApplyBuiltinTransfer)
Supplements Environment with non-standard comparison and join operations.
DataflowAnalysis(ASTContext &Context)
Holds CFG and other derived context that is needed to perform dataflow analysis.
void transferTypeErased(const Stmt *Stmt, TypeErasedLattice &E, Environment &Env) final
Applies the analysis transfer function for a given statement and type-erased lattice element.
virtual bool transfer(const Stmt *Stmt, Environment &Env)=0
Return value indicates whether the model processed the Stmt.
Type-erased base class for dataflow analyses built on a single lattice type.
TypeErasedLattice typeErasedInitialElement() final
Returns a type-erased lattice element that models the initial state of a basic block.
Stmt - This represents one statement.
llvm::Expected< std::vector< llvm::Optional< DataflowAnalysisState< typename AnalysisT::Lattice > > > > runDataflowAnalysis(const ControlFlowContext &CFCtx, AnalysisT &Analysis, const Environment &InitEnv)
Performs dataflow analysis and returns a mapping from basic block IDs to dataflow analysis states tha...
bool isEqualTypeErased(const TypeErasedLattice &E1, const TypeErasedLattice &E2) final
Returns true if and only if the two given type-erased lattice elements are equal.
llvm::Expected< std::vector< llvm::Optional< TypeErasedDataflowAnalysisState > > > runTypeErasedDataflowAnalysis(const ControlFlowContext &CFCtx, TypeErasedDataflowAnalysis &Analysis, const Environment &InitEnv)
Performs dataflow analysis and returns a mapping from basic block IDs to dataflow analysis states tha...
Lattice for dataflow analysis that keeps track of a set of source locations.
Holds the state of the program (store and heap) at a given program point.