//===- SparseAnalysis.h - Sparse data-flow analysis -----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements sparse data-flow analysis using the data-flow analysis // framework. The analysis is forward and conditional and uses the results of // dead code analysis to prune dead code during the analysis. // //===----------------------------------------------------------------------===// #ifndef MLIR_ANALYSIS_DATAFLOW_SPARSEANALYSIS_H #define MLIR_ANALYSIS_DATAFLOW_SPARSEANALYSIS_H #include "mlir/Analysis/DataFlowFramework.h" #include "mlir/IR/SymbolTable.h" #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/ControlFlowInterfaces.h" #include "llvm/ADT/SmallPtrSet.h" namespace mlir { namespace dataflow { //===----------------------------------------------------------------------===// // AbstractSparseLattice //===----------------------------------------------------------------------===// /// This class represents an abstract lattice. A lattice contains information /// about an SSA value and is what's propagated across the IR by sparse /// data-flow analysis. class AbstractSparseLattice : public AnalysisState { … }; //===----------------------------------------------------------------------===// // Lattice //===----------------------------------------------------------------------===// /// This class represents a lattice holding a specific value of type `ValueT`. /// Lattice values (`ValueT`) are required to adhere to the following: /// /// * static ValueT join(const ValueT &lhs, const ValueT &rhs); /// - This method conservatively joins the information held by `lhs` /// and `rhs` into a new value. This method is required to be monotonic. /// * bool operator==(const ValueT &rhs) const; /// template <typename ValueT> class Lattice : public AbstractSparseLattice { … }; //===----------------------------------------------------------------------===// // AbstractSparseForwardDataFlowAnalysis //===----------------------------------------------------------------------===// /// Base class for sparse forward data-flow analyses. A sparse analysis /// implements a transfer function on operations from the lattices of the /// operands to the lattices of the results. This analysis will propagate /// lattices across control-flow edges and the callgraph using liveness /// information. /// /// Visit a program point in sparse forward data-flow analysis will invoke the /// transfer function of the operation preceding the program point iterator. /// Visit a program point at the begining of block will visit the block itself. class AbstractSparseForwardDataFlowAnalysis : public DataFlowAnalysis { … }; //===----------------------------------------------------------------------===// // SparseForwardDataFlowAnalysis //===----------------------------------------------------------------------===// /// A sparse forward data-flow analysis for propagating SSA value lattices /// across the IR by implementing transfer functions for operations. /// /// `StateT` is expected to be a subclass of `AbstractSparseLattice`. template <typename StateT> class SparseForwardDataFlowAnalysis : public AbstractSparseForwardDataFlowAnalysis { … }; //===----------------------------------------------------------------------===// // AbstractSparseBackwardDataFlowAnalysis //===----------------------------------------------------------------------===// /// Base class for sparse backward data-flow analyses. Similar to /// AbstractSparseForwardDataFlowAnalysis, but walks bottom to top. class AbstractSparseBackwardDataFlowAnalysis : public DataFlowAnalysis { … }; //===----------------------------------------------------------------------===// // SparseBackwardDataFlowAnalysis //===----------------------------------------------------------------------===// /// A sparse (backward) data-flow analysis for propagating SSA value lattices /// backwards across the IR by implementing transfer functions for operations. /// /// `StateT` is expected to be a subclass of `AbstractSparseLattice`. /// /// Visit a program point in sparse backward data-flow analysis will invoke the /// transfer function of the operation preceding the program point iterator. /// Visit a program point at the begining of block will visit the block itself. template <typename StateT> class SparseBackwardDataFlowAnalysis : public AbstractSparseBackwardDataFlowAnalysis { … }; } // end namespace dataflow } // end namespace mlir #endif // MLIR_ANALYSIS_DATAFLOW_SPARSEANALYSIS_H