25#include <mlir/Analysis/DataFlow/DeadCodeAnalysis.h>
26#include <mlir/Analysis/DataFlow/SparseAnalysis.h>
27#include <mlir/Analysis/DataFlowFramework.h>
28#include <mlir/IR/Block.h>
29#include <mlir/IR/Operation.h>
30#include <mlir/IR/Region.h>
31#include <mlir/IR/SymbolTable.h>
32#include <mlir/IR/Value.h>
33#include <mlir/Interfaces/CallInterfaces.h>
34#include <mlir/Interfaces/ControlFlowInterfaces.h>
35#include <mlir/Support/LLVM.h>
37#include <llvm/ADT/SmallVector.h>
38#include <llvm/Support/Casting.h>
63 :
public mlir::dataflow::AbstractSparseForwardDataFlowAnalysis {
64 using Base = mlir::dataflow::AbstractSparseForwardDataFlowAnalysis;
72 mlir::LogicalResult
initialize(mlir::Operation *top)
override;
76 mlir::LogicalResult
visit(mlir::ProgramPoint *point)
override;
93 mlir::LogicalResult initializeRecursivelyInProgramOrder(mlir::Operation *op);
96 mlir::LogicalResult visitOperationDuringInitialization(mlir::Operation *op);
99 bool isOperationLive(mlir::Operation *op);
103 llvm::SmallVector<const AbstractSparseLattice *, 4>
104 collectOperandLatticesAndSubscribe(mlir::Operation *op);
107 mlir::LogicalResult visitZeroResultCallOperation(
108 mlir::CallOpInterface call, mlir::ArrayRef<const AbstractSparseLattice *> operandLattices
114 mlir::LogicalResult visitZeroResultOperation(mlir::Operation *op);
125template <
typename StateT>
128 std::is_base_of<AbstractSparseLattice, StateT>::value,
129 "analysis state class expected to subclass AbstractSparseLattice"
140 mlir::Operation *op, mlir::ArrayRef<const StateT *> operands, mlir::ArrayRef<StateT *> results
146 mlir::CallOpInterface , mlir::ArrayRef<const StateT *> ,
147 mlir::ArrayRef<StateT *> resultLattices
159 mlir::Operation * ,
const mlir::RegionSuccessor &successor,
160 mlir::ArrayRef<StateT *> argLattices,
unsigned firstIndex
163 setAllToEntryStates(argLattices.drop_front(firstIndex + successor.getSuccessorInputs().size()));
173 return static_cast<const StateT *
>(
174 mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::getLatticeElementFor(point, value)
181 mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::setAllToEntryStates(
189 mlir::LogicalResult visitOperationImpl(
190 mlir::Operation *op, mlir::ArrayRef<const AbstractSparseLattice *> operandLattices,
191 mlir::ArrayRef<AbstractSparseLattice *> resultLattices
195 {
reinterpret_cast<const StateT *
const *
>(operandLattices.begin()), operandLattices.size()},
196 {
reinterpret_cast<StateT *
const *
>(resultLattices.begin()), resultLattices.size()}
200 void visitExternalCallImpl(
201 mlir::CallOpInterface call, mlir::ArrayRef<const AbstractSparseLattice *> argumentLattices,
202 mlir::ArrayRef<AbstractSparseLattice *> resultLattices
206 {
reinterpret_cast<const StateT *
const *
>(argumentLattices.begin()),
207 argumentLattices.size()},
208 {
reinterpret_cast<StateT *
const *
>(resultLattices.begin()), resultLattices.size()}
212 void visitNonControlFlowArgumentsImpl(
213 mlir::Operation *op,
const mlir::RegionSuccessor &successor,
214 mlir::ArrayRef<AbstractSparseLattice *> argLattices,
unsigned firstIndex
217 op, successor, {
reinterpret_cast<StateT *
const *
>(argLattices.begin()), argLattices.size()},
mlir::LogicalResult visit(mlir::ProgramPoint *point) override
Delegate block starts and result-producing operations to upstream MLIR.
mlir::LogicalResult initialize(mlir::Operation *top) override
Initialize the analysis while preserving the program-order visitation of the old LLZK sparse analysis...
AbstractSparseForwardDataFlowAnalysis(mlir::DataFlowSolver &s)
mlir::SymbolTableCollection tables
LLZK: Kept as a compatibility cache for analyses that derived from the old ported class and used this...
const StateT * getLatticeElementFor(mlir::ProgramPoint *point, mlir::Value value)
Get the lattice element for a value and create a dependency on the provided program point.
virtual void visitExternalCall(mlir::CallOpInterface, mlir::ArrayRef< const StateT * >, mlir::ArrayRef< StateT * > resultLattices)
Visit a call operation to an externally defined function given the lattices of its arguments.
SparseForwardDataFlowAnalysis(mlir::DataFlowSolver &s)
virtual void visitNonControlFlowArguments(mlir::Operation *, const mlir::RegionSuccessor &successor, mlir::ArrayRef< StateT * > argLattices, unsigned firstIndex)
Given an operation with possible region control-flow, the lattices of the operands,...
void setAllToEntryStates(mlir::ArrayRef< StateT * > lattices)
virtual mlir::LogicalResult visitOperation(mlir::Operation *op, mlir::ArrayRef< const StateT * > operands, mlir::ArrayRef< StateT * > results)=0
Visit an operation with the lattices of its operands.
virtual void setToEntryState(StateT *lattice)=0
Set the given lattice element(s) at control-flow entry point(s).
StateT * getLatticeElement(mlir::Value value) override
Get the lattice element for a value.
mlir::dataflow::AbstractSparseLattice AbstractSparseLattice