18#include <mlir/Pass/AnalysisManager.h>
20#include <llvm/ADT/EquivalenceClasses.h>
45 static mlir::FailureOr<SourceRefLatticeValue>
51 mlir::Operation *op, mlir::ArrayRef<const Lattice *> operands,
52 mlir::ArrayRef<Lattice *> results
56 mlir::CallOpInterface call, mlir::ArrayRef<const Lattice *> argumentLattices,
57 mlir::ArrayRef<Lattice *> resultLattices
65 mlir::Operation *op,
const OperandValues &operandVals, mlir::ArrayRef<Lattice *> results
75 mlir::SymbolTableCollection tables;
89template <>
struct std::hash<
llzk::CDGAnalysisContext> {
135 static mlir::FailureOr<ConstraintDependencyGraph>
compute(
144 void print(mlir::raw_ostream &os)
const;
174 : mod(other.mod), structDef(other.structDef), ctx(other.ctx), signalSets(other.signalSets),
175 constantSets(other.constantSets), ref2Val(other.ref2Val), tables() {}
179 structDef = other.structDef;
181 signalSets = other.signalSets;
182 constantSets = other.constantSets;
183 ref2Val = other.ref2Val;
196 llvm::EquivalenceClasses<SourceRef> signalSets;
199 std::unordered_map<SourceRef, SourceRefSet, SourceRef::Hash> constantSets;
205 mutable mlir::SymbolTableCollection tables;
213 : mod(m), structDef(s), ctx(c) {}
220 mlir::LogicalResult computeConstraints(mlir::DataFlowSolver &solver, mlir::AnalysisManager &am);
228 void walkConstrainOp(mlir::DataFlowSolver &solver, mlir::Operation *emitOp);
236 :
public StructAnalysis<ConstraintDependencyGraph, CDGAnalysisContext> {
244 mlir::DataFlowSolver &solver, mlir::AnalysisManager &moduleAnalysisManager,
253 ConstraintDependencyGraph, CDGAnalysisContext, ConstraintDependencyGraphStructAnalysis> {
265 ctx = {.runIntraprocedural = runIntraprocedural};
Convenience classes for a frequent pattern of dataflow analysis used in LLZK, where an analysis is ru...
This file implements sparse data-flow analysis using the data-flow analysis framework.
ConstraintDependencyGraphModuleAnalysis(mlir::Operation *op)
~ConstraintDependencyGraphModuleAnalysis() override=default
void setIntraprocedural(bool runIntraprocedural)
void initializeSolver() override
Initialize the shared dataflow solver with any common analyses required by the contained struct analy...
const CDGAnalysisContext & getContext() const override
Return the current Context object.
An analysis wrapper around the ConstraintDependencyGraph for a given struct.
StructAnalysis(mlir::Operation *op)
Assert that this analysis is being run on a StructDefOp and initializes the analysis with the current...
mlir::LogicalResult runAnalysis(mlir::DataFlowSolver &solver, mlir::AnalysisManager &moduleAnalysisManager, const CDGAnalysisContext &ctx) override
Construct a CDG, using the module's analysis manager to query ConstraintDependencyGraph objects for n...
~ConstraintDependencyGraphStructAnalysis() override=default
ConstraintDependencyGraph & operator=(const ConstraintDependencyGraph &other)
void print(mlir::raw_ostream &os) const
Print the CDG to the specified output stream.
ConstraintDependencyGraph(const ConstraintDependencyGraph &other)
virtual ~ConstraintDependencyGraph()=default
static mlir::FailureOr< ConstraintDependencyGraph > compute(mlir::ModuleOp mod, component::StructDefOp s, mlir::DataFlowSolver &solver, mlir::AnalysisManager &am, const CDGAnalysisContext &ctx)
Compute a ConstraintDependencyGraph (CDG)
SourceRefSet getConstrainingValues(const SourceRef &ref) const
Get the values that are connected to the given ref via emitted constraints.
void dump() const
Dumps the CDG to stderr.
const SourceRefLattice::Ref2Val & getRef2Val() const
ConstraintDependencyGraph translate(SourceRefRemappings translation) const
Translate the SourceRefs in this CDG to that of a different context.
mlir::DataFlowSolver solver
ModuleAnalysis(mlir::Operation *op, const mlir::DataFlowConfig &config=mlir::DataFlowConfig())
The dataflow analysis that computes the set of references that LLZK operations use and produce.
static mlir::ChangeResult fallbackOpUpdate(mlir::Operation *op, const OperandValues &operandVals, mlir::ArrayRef< Lattice * > results)
void visitExternalCall(mlir::CallOpInterface call, mlir::ArrayRef< const Lattice * > argumentLattices, mlir::ArrayRef< Lattice * > resultLattices) override
Visit a call operation to an externally defined function given the lattices of its arguments.
static mlir::FailureOr< SourceRefLatticeValue > getWriteTargetState(mlir::DataFlowSolver &solver, mlir::Operation *op)
static SourceRefLatticeValue arraySubdivisionOpUpdate(array::ArrayAccessOpInterface op, const OperandValues &operandVals)
static SourceRefLatticeValue getValueState(mlir::DataFlowSolver &solver, mlir::Value val)
void setToEntryState(Lattice *lattice) override
Set the given lattice element(s) at control flow entry point(s).
mlir::LogicalResult visitOperation(mlir::Operation *op, mlir::ArrayRef< const Lattice * > operands, mlir::ArrayRef< Lattice * > results) override
Propagate SourceRef lattice values from operands to results.
dataflow::SparseForwardDataFlowAnalysis< Lattice > Base
static const Lattice * getLattice(mlir::DataFlowSolver &solver, mlir::Value val)
mlir::DenseMap< mlir::Value, const Lattice * > OperandValues
A value at a given point of the SourceRefLattice.
Sparse SSA-value lattice for SourceRef propagation.
mlir::DenseMap< SourceRef, mlir::DenseSet< ValueTy > > Ref2Val
A reference to a "source", which is the base value from which other SSA values are derived.
StructAnalysis(mlir::Operation *op)
Assert that this analysis is being run on a StructDefOp and initializes the analysis with the current...
A sparse forward data-flow analysis for propagating SSA value lattices across the IR by implementing ...
SparseForwardDataFlowAnalysis(mlir::DataFlowSolver &s)
std::vector< std::pair< SourceRef, SourceRefLatticeValue > > SourceRefRemappings
Parameters and shared objects to pass to child analyses.
friend bool operator==(const CDGAnalysisContext &a, const CDGAnalysisContext &b)=default
bool runIntraproceduralAnalysis() const
size_t operator()(const llzk::CDGAnalysisContext &c) const