LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
IntervalAnalysis.h
Go to the documentation of this file.
1//===-- IntervalAnalysis.h --------------------------------------*- C++ -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
10#pragma once
11
16#include "llzk/Analysis/Field.h"
27#include "llzk/Util/Compare.h"
28
29#include <mlir/IR/BuiltinOps.h>
30#include <mlir/Pass/AnalysisManager.h>
31#include <mlir/Support/LLVM.h>
32
33#include <llvm/ADT/DynamicAPInt.h>
34#include <llvm/ADT/MapVector.h>
35#include <llvm/Support/SMTAPI.h>
36
37#include <array>
38#include <mutex>
39
40namespace llzk {
41
42/* ExpressionValue */
43
47public:
48 /* Must be default initializable to be a ScalarLatticeValue. */
49 ExpressionValue() : i(), expr(nullptr) {}
50
51 explicit ExpressionValue(const Field &f) : i(Interval::Entire(f)), expr(nullptr) {}
52
53 ExpressionValue(const Field &f, llvm::SMTExprRef exprRef)
54 : i(Interval::Entire(f)), expr(exprRef) {}
55
56 ExpressionValue(const Field &f, llvm::SMTExprRef exprRef, const llvm::DynamicAPInt &singleVal)
57 : i(Interval::Degenerate(f, singleVal)), expr(exprRef) {}
58
59 ExpressionValue(llvm::SMTExprRef exprRef, const Interval &interval)
60 : i(interval), expr(exprRef) {}
61
62 llvm::SMTExprRef getExpr() const { return expr; }
63
64 const Interval &getInterval() const { return i; }
65
66 const Field &getField() const { return i.getField(); }
67
71 ExpressionValue withInterval(const Interval &newInterval) const {
72 return ExpressionValue(expr, newInterval);
73 }
74
76 ExpressionValue withExpression(const llvm::SMTExprRef &newExpr) const {
77 return ExpressionValue(newExpr, i);
78 }
79
80 /* Required to be a ScalarLatticeValue. */
84 return *this;
85 }
86
87 bool operator==(const ExpressionValue &rhs) const;
88
89 bool isBoolSort(llvm::SMTSolverRef solver) const {
90 return solver->getBoolSort() == solver->getSort(expr);
91 }
92
99 friend ExpressionValue
100 intersection(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
101
108 friend ExpressionValue
109 join(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
110
111 // arithmetic ops
112
113 friend ExpressionValue
114 add(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
115
116 friend ExpressionValue
117 sub(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
118
119 friend ExpressionValue
120 mul(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
121
122 friend ExpressionValue
123 div(llvm::SMTSolverRef solver, felt::DivFeltOp op, const ExpressionValue &lhs,
124 const ExpressionValue &rhs);
125
126 friend ExpressionValue
127 mod(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
128
129 friend ExpressionValue
130 bitAnd(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
131
132 friend ExpressionValue
133 shiftLeft(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
134
135 friend ExpressionValue
136 shiftRight(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
137
138 friend ExpressionValue
139 cmp(llvm::SMTSolverRef solver, boolean::CmpOp op, const ExpressionValue &lhs,
140 const ExpressionValue &rhs);
141
142 friend ExpressionValue
143 boolAnd(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
144
145 friend ExpressionValue
146 boolOr(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
147
148 friend ExpressionValue
149 boolXor(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs);
150
160 llvm::SMTSolverRef solver, mlir::Operation *op, const ExpressionValue &lhs,
161 const ExpressionValue &rhs
162 );
163
164 friend ExpressionValue neg(llvm::SMTSolverRef solver, const ExpressionValue &val);
165
166 friend ExpressionValue notOp(llvm::SMTSolverRef solver, const ExpressionValue &val);
167
168 friend ExpressionValue boolNot(llvm::SMTSolverRef solver, const ExpressionValue &val);
169
170 friend ExpressionValue
171 fallbackUnaryOp(llvm::SMTSolverRef solver, mlir::Operation *op, const ExpressionValue &val);
172
173 /* Utility */
174
175 void print(mlir::raw_ostream &os) const;
176
177 friend mlir::raw_ostream &operator<<(mlir::raw_ostream &os, const ExpressionValue &e) {
178 e.print(os);
179 return os;
180 }
181
182 struct Hash {
183 unsigned operator()(const ExpressionValue &e) const {
184 return Interval::Hash {}(e.i) ^ llvm::hash_value(e.expr);
185 }
186 };
187
188private:
189 Interval i;
190 llvm::SMTExprRef expr;
191};
192
193/* IntervalAnalysisLatticeValue */
194
196 : public dataflow::AbstractLatticeValue<IntervalAnalysisLatticeValue, ExpressionValue> {
197public:
198 using AbstractLatticeValue::AbstractLatticeValue;
199};
200
201/* IntervalAnalysisLattice */
202
204
206public:
208 // Map mlir::Values to LatticeValues
209 using ValueMap = mlir::DenseMap<mlir::Value, LatticeValue>;
210 // Map field references to LatticeValues. Used for field reads and writes.
211 // Structure is component value -> field attribute -> latticeValue
212 using FieldMap = mlir::DenseMap<mlir::Value, mlir::DenseMap<mlir::StringAttr, LatticeValue>>;
213 // Expression to interval map for convenience.
214 using ExpressionIntervals = mlir::DenseMap<llvm::SMTExprRef, Interval>;
215 // Tracks all constraints and assignments in insertion order
216 using ConstraintSet = llvm::SetVector<ExpressionValue>;
217
218 using AbstractSparseLattice::AbstractSparseLattice;
219
220 mlir::ChangeResult join(const AbstractSparseLattice &other) override;
221
222 mlir::ChangeResult meet(const AbstractSparseLattice &other) override;
223
224 void print(mlir::raw_ostream &os) const override;
225
226 const LatticeValue &getValue() const { return val; }
227
228 mlir::ChangeResult setValue(const LatticeValue &val);
229 mlir::ChangeResult setValue(ExpressionValue e);
230
231 mlir::ChangeResult addSolverConstraint(ExpressionValue e);
232
233 friend mlir::raw_ostream &operator<<(mlir::raw_ostream &os, const IntervalAnalysisLattice &l) {
234 l.print(os);
235 return os;
236 }
237
238 const ConstraintSet &getConstraints() const { return constraints; }
239
240 mlir::FailureOr<Interval> findInterval(llvm::SMTExprRef expr) const;
241 mlir::ChangeResult setInterval(llvm::SMTExprRef expr, const Interval &i);
242
243private:
244 LatticeValue val;
245 ConstraintSet constraints;
246};
247
248/* IntervalDataFlowAnalysis */
249
251 : public dataflow::SparseForwardDataFlowAnalysis<IntervalAnalysisLattice> {
253 using Lattice = IntervalAnalysisLattice;
254 using LatticeValue = IntervalAnalysisLattice::LatticeValue;
255
256 // Map fields to their symbols
257 using SymbolMap = mlir::DenseMap<SourceRef, llvm::SMTExprRef>;
258
259public:
261 mlir::DataFlowSolver &dataflowSolver, llvm::SMTSolverRef smt, const Field &f,
262 bool propInputConstraints
263 )
264 : Base::SparseForwardDataFlowAnalysis(dataflowSolver), _dataflowSolver(dataflowSolver),
265 smtSolver(smt), field(f), propagateInputConstraints(propInputConstraints) {}
266
267 mlir::LogicalResult visitOperation(
268 mlir::Operation *op, mlir::ArrayRef<const Lattice *> operands,
269 mlir::ArrayRef<Lattice *> results
270 ) override;
271
276 llvm::SMTExprRef getOrCreateSymbol(const SourceRef &r);
277
278 const llvm::DenseMap<SourceRef, llvm::DenseSet<Lattice *>> &getFieldReadResults() const {
279 return fieldReadResults;
280 }
281
282 const llvm::DenseMap<SourceRef, ExpressionValue> &getFieldWriteResults() const {
283 return fieldWriteResults;
284 }
285
286private:
287 mlir::DataFlowSolver &_dataflowSolver;
288 llvm::SMTSolverRef smtSolver;
289 SymbolMap refSymbols;
290 std::reference_wrapper<const Field> field;
291 bool propagateInputConstraints;
292 mlir::SymbolTableCollection tables;
293
294 // Track field reads so that propagations to fields can be all updated efficiently.
295 llvm::DenseMap<SourceRef, llvm::DenseSet<Lattice *>> fieldReadResults;
296 // Track field writes values. For now, we'll overapproximate this.
297 llvm::DenseMap<SourceRef, ExpressionValue> fieldWriteResults;
298
299 void setToEntryState(Lattice *lattice) override {
300 // Initialize the value with an interval in our specified field.
301 (void)lattice->setValue(ExpressionValue(field.get()));
302 }
303
304 llvm::SMTExprRef createFeltSymbol(const SourceRef &r) const;
305
306 llvm::SMTExprRef createFeltSymbol(mlir::Value val) const;
307
308 llvm::SMTExprRef createFeltSymbol(const char *name) const;
309
310 bool isConstOp(mlir::Operation *op) const {
311 return llvm::isa<
312 felt::FeltConstantOp, mlir::arith::ConstantIndexOp, mlir::arith::ConstantIntOp>(op);
313 }
314
315 llvm::DynamicAPInt getConst(mlir::Operation *op) const;
316
317 inline llvm::SMTExprRef createConstBitvectorExpr(const llvm::DynamicAPInt &v) const {
318 return createConstBitvectorExpr(toAPSInt(v));
319 }
320
321 inline llvm::SMTExprRef createConstBitvectorExpr(const llvm::APSInt &v) const {
322 return smtSolver->mkBitvector(v, field.get().bitWidth());
323 }
324
325 llvm::SMTExprRef createConstBoolExpr(bool v) const {
326 return smtSolver->mkBitvector(mlir::APSInt((int)v), field.get().bitWidth());
327 }
328
329 bool isArithmeticOp(mlir::Operation *op) const {
330 return llvm::isa<
331 felt::AddFeltOp, felt::SubFeltOp, felt::MulFeltOp, felt::DivFeltOp, felt::ModFeltOp,
332 felt::NegFeltOp, felt::InvFeltOp, felt::AndFeltOp, felt::OrFeltOp, felt::XorFeltOp,
333 felt::NotFeltOp, felt::ShlFeltOp, felt::ShrFeltOp, boolean::CmpOp, boolean::AndBoolOp,
334 boolean::OrBoolOp, boolean::XorBoolOp, boolean::NotBoolOp>(op);
335 }
336
337 ExpressionValue
338 performBinaryArithmetic(mlir::Operation *op, const LatticeValue &a, const LatticeValue &b);
339
340 ExpressionValue performUnaryArithmetic(mlir::Operation *op, const LatticeValue &a);
341
348 void applyInterval(mlir::Operation *originalOp, mlir::Value val, Interval newInterval);
349
351 mlir::FailureOr<std::pair<llvm::DenseSet<mlir::Value>, Interval>>
352 getGeneralizedDecompInterval(mlir::Operation *baseOp, mlir::Value lhs, mlir::Value rhs);
353
354 bool isReadOp(mlir::Operation *op) const {
355 return llvm::isa<component::FieldReadOp, polymorphic::ConstReadOp, array::ReadArrayOp>(op);
356 }
357
358 bool isDefinitionOp(mlir::Operation *op) const {
359 return llvm::isa<
360 component::StructDefOp, function::FuncDefOp, component::FieldDefOp, global::GlobalDefOp,
361 mlir::ModuleOp>(op);
362 }
363
364 bool isReturnOp(mlir::Operation *op) const { return llvm::isa<function::ReturnOp>(op); }
365
368 const SourceRefLattice *getSourceRefLattice(mlir::Operation *baseOp, mlir::Value val);
369};
370
371/* StructIntervals */
372
376 llvm::SMTSolverRef smtSolver;
377 std::optional<std::reference_wrapper<const Field>> field;
379
380 llvm::SMTExprRef getSymbol(const SourceRef &r) const { return intervalDFA->getOrCreateSymbol(r); }
381 bool hasField() const { return field.has_value(); }
382 const Field &getField() const {
383 ensure(field.has_value(), "field not set within context");
384 return field->get();
385 }
387
388 friend bool
390};
391
392} // namespace llzk
393
394template <> struct std::hash<llzk::IntervalAnalysisContext> {
396 return llvm::hash_combine(
397 std::hash<const llzk::IntervalDataFlowAnalysis *> {}(c.intervalDFA),
398 std::hash<const llvm::SMTSolver *> {}(c.smtSolver.get()),
399 std::hash<const llzk::Field *> {}(&c.getField()),
400 std::hash<bool> {}(c.propagateInputConstraints)
401 );
402 }
403};
404
405namespace llzk {
406
407class StructIntervals {
408public:
418 static mlir::FailureOr<StructIntervals> compute(
419 mlir::ModuleOp mod, component::StructDefOp s, mlir::DataFlowSolver &solver,
420 const IntervalAnalysisContext &ctx
421 ) {
422 StructIntervals si(mod, s);
423 if (si.computeIntervals(solver, ctx).failed()) {
424 return mlir::failure();
425 }
426 return si;
427 }
428
429 mlir::LogicalResult
430 computeIntervals(mlir::DataFlowSolver &solver, const IntervalAnalysisContext &ctx);
431
432 void print(mlir::raw_ostream &os, bool withConstraints = false, bool printCompute = false) const;
433
434 const llvm::MapVector<SourceRef, Interval> &getConstrainIntervals() const {
435 return constrainFieldRanges;
436 }
437
438 const llvm::SetVector<ExpressionValue> getConstrainSolverConstraints() const {
439 return constrainSolverConstraints;
440 }
441
442 const llvm::MapVector<SourceRef, Interval> &getComputeIntervals() const {
443 return computeFieldRanges;
444 }
445
446 const llvm::SetVector<ExpressionValue> getComputeSolverConstraints() const {
447 return computeSolverConstraints;
448 }
449
450 friend mlir::raw_ostream &operator<<(mlir::raw_ostream &os, const StructIntervals &si) {
451 si.print(os);
452 return os;
453 }
454
455private:
456 mlir::ModuleOp mod;
457 component::StructDefOp structDef;
458 llvm::SMTSolverRef smtSolver;
459 // llvm::MapVector keeps insertion order for consistent iteration
460 llvm::MapVector<SourceRef, Interval> constrainFieldRanges, computeFieldRanges;
461 // llvm::SetVector for the same reasons as above
462 llvm::SetVector<ExpressionValue> constrainSolverConstraints, computeSolverConstraints;
463
464 StructIntervals(mlir::ModuleOp m, component::StructDefOp s) : mod(m), structDef(s) {}
465};
466
467/* StructIntervalAnalysis */
468
470
471class StructIntervalAnalysis : public StructAnalysis<StructIntervals, IntervalAnalysisContext> {
472public:
474 virtual ~StructIntervalAnalysis() = default;
475
476 mlir::LogicalResult runAnalysis(
477 mlir::DataFlowSolver &solver, mlir::AnalysisManager &, const IntervalAnalysisContext &ctx
478 ) override {
479 auto computeRes = StructIntervals::compute(getModule(), getStruct(), solver, ctx);
480 if (mlir::failed(computeRes)) {
481 return mlir::failure();
482 }
483 setResult(ctx, std::move(*computeRes));
484 return mlir::success();
485 }
486};
487
488/* ModuleIntervalAnalysis */
489
491 : public ModuleAnalysis<StructIntervals, IntervalAnalysisContext, StructIntervalAnalysis> {
492
493public:
494 ModuleIntervalAnalysis(mlir::Operation *op) : ModuleAnalysis(op), ctx {} {
495 ctx.smtSolver = llvm::CreateZ3Solver();
496 }
497 virtual ~ModuleIntervalAnalysis() = default;
498
499 void setField(const Field &f) { ctx.field = f; }
500 void setPropagateInputConstraints(bool prop) { ctx.propagateInputConstraints = prop; }
501
502protected:
503 void initializeSolver() override {
504 ensure(ctx.hasField(), "field not set, could not generate analysis context");
505 (void)solver.load<SourceRefAnalysis>();
506 auto smtSolverRef = ctx.smtSolver;
507 bool prop = ctx.propagateInputConstraints;
508 ctx.intervalDFA =
509 solver.load<IntervalDataFlowAnalysis, llvm::SMTSolverRef, const Field &, bool>(
510 std::move(smtSolverRef), ctx.getField(), std::move(prop)
511 );
512 }
513
514 const IntervalAnalysisContext &getContext() const override {
515 ensure(ctx.field.has_value(), "field not set, could not generate analysis context");
516 return ctx;
517 }
518
519private:
521};
522
523} // namespace llzk
524
525namespace llvm {
526
527template <> struct DenseMapInfo<llzk::ExpressionValue> {
528
529 static SMTExprRef getEmptyExpr() {
530 static auto emptyPtr = reinterpret_cast<SMTExprRef>(1);
531 return emptyPtr;
532 }
533 static SMTExprRef getTombstoneExpr() {
534 static auto tombstonePtr = reinterpret_cast<SMTExprRef>(2);
535 return tombstonePtr;
536 }
537
544 static unsigned getHashValue(const llzk::ExpressionValue &e) {
545 return llzk::ExpressionValue::Hash {}(e);
546 }
547 static bool isEqual(const llzk::ExpressionValue &lhs, const llzk::ExpressionValue &rhs) {
548 if (lhs.getExpr() == getEmptyExpr() || lhs.getExpr() == getTombstoneExpr() ||
549 rhs.getExpr() == getEmptyExpr() || rhs.getExpr() == getTombstoneExpr()) {
550 return lhs.getExpr() == rhs.getExpr();
551 }
552 return lhs == rhs;
553 }
554};
555
556} // namespace llvm
Convenience classes for a frequent pattern of dataflow analysis used in LLZK, where an analysis is ru...
This file implements (LLZK-tailored) dense data-flow analysis using the data-flow analysis framework.
This file implements sparse data-flow analysis using the data-flow analysis framework.
Tracks a solver expression and an interval range for that expression.
ExpressionValue(llvm::SMTExprRef exprRef, const Interval &interval)
ExpressionValue withExpression(const llvm::SMTExprRef &newExpr) const
Return the current expression with a new SMT expression.
friend ExpressionValue neg(llvm::SMTSolverRef solver, const ExpressionValue &val)
friend ExpressionValue notOp(llvm::SMTSolverRef solver, const ExpressionValue &val)
const Interval & getInterval() const
friend ExpressionValue cmp(llvm::SMTSolverRef solver, boolean::CmpOp op, const ExpressionValue &lhs, const ExpressionValue &rhs)
ExpressionValue(const Field &f, llvm::SMTExprRef exprRef)
friend ExpressionValue sub(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
ExpressionValue(const Field &f)
friend ExpressionValue mul(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
bool isBoolSort(llvm::SMTSolverRef solver) const
friend ExpressionValue fallbackUnaryOp(llvm::SMTSolverRef solver, mlir::Operation *op, const ExpressionValue &val)
friend ExpressionValue boolOr(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
friend ExpressionValue div(llvm::SMTSolverRef solver, felt::DivFeltOp op, const ExpressionValue &lhs, const ExpressionValue &rhs)
ExpressionValue withInterval(const Interval &newInterval) const
Return the current expression with a new interval.
void print(mlir::raw_ostream &os) const
bool operator==(const ExpressionValue &rhs) const
friend ExpressionValue add(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
friend ExpressionValue shiftRight(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
llvm::SMTExprRef getExpr() const
friend ExpressionValue fallbackBinaryOp(llvm::SMTSolverRef solver, mlir::Operation *op, const ExpressionValue &lhs, const ExpressionValue &rhs)
Computes a solver expression based on the operation, but computes a fallback interval (which is just ...
ExpressionValue(const Field &f, llvm::SMTExprRef exprRef, const llvm::DynamicAPInt &singleVal)
friend ExpressionValue bitAnd(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
friend ExpressionValue boolXor(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
friend ExpressionValue join(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
Compute the union of the lhs and rhs intervals, and create a solver expression that constrains both s...
friend mlir::raw_ostream & operator<<(mlir::raw_ostream &os, const ExpressionValue &e)
friend ExpressionValue boolAnd(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
const Field & getField() const
friend ExpressionValue mod(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
friend ExpressionValue shiftLeft(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
ExpressionValue & join(const ExpressionValue &)
Fold two expressions together when overapproximating array elements.
friend ExpressionValue intersection(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
Compute the intersection of the lhs and rhs intervals, and create a solver expression that constrains...
friend ExpressionValue boolNot(llvm::SMTSolverRef solver, const ExpressionValue &val)
Information about the prime finite field used for the interval analysis.
Definition Field.h:27
static const Field & getField(const char *fieldName)
Get a Field from a given field name string.
Definition Field.cpp:31
friend mlir::raw_ostream & operator<<(mlir::raw_ostream &os, const IntervalAnalysisLattice &l)
mlir::DenseMap< mlir::Value, mlir::DenseMap< mlir::StringAttr, LatticeValue > > FieldMap
const LatticeValue & getValue() const
llvm::SetVector< ExpressionValue > ConstraintSet
mlir::ChangeResult setValue(const LatticeValue &val)
IntervalAnalysisLatticeValue LatticeValue
mlir::DenseMap< mlir::Value, LatticeValue > ValueMap
mlir::ChangeResult meet(const AbstractSparseLattice &other) override
mlir::ChangeResult addSolverConstraint(ExpressionValue e)
const ConstraintSet & getConstraints() const
void print(mlir::raw_ostream &os) const override
mlir::ChangeResult join(const AbstractSparseLattice &other) override
mlir::ChangeResult setInterval(llvm::SMTExprRef expr, const Interval &i)
mlir::DenseMap< llvm::SMTExprRef, Interval > ExpressionIntervals
mlir::FailureOr< Interval > findInterval(llvm::SMTExprRef expr) const
mlir::LogicalResult visitOperation(mlir::Operation *op, mlir::ArrayRef< const Lattice * > operands, mlir::ArrayRef< Lattice * > results) override
Visit an operation with the lattices of its operands.
llvm::SMTExprRef getOrCreateSymbol(const SourceRef &r)
Either return the existing SMT expression that corresponds to the SourceRef, or create one.
const llvm::DenseMap< SourceRef, llvm::DenseSet< Lattice * > > & getFieldReadResults() const
IntervalDataFlowAnalysis(mlir::DataFlowSolver &dataflowSolver, llvm::SMTSolverRef smt, const Field &f, bool propInputConstraints)
const llvm::DenseMap< SourceRef, ExpressionValue > & getFieldWriteResults() const
Intervals over a finite field.
Definition Intervals.h:200
ModuleIntervalAnalysis(mlir::Operation *op)
virtual ~ModuleIntervalAnalysis()=default
void setPropagateInputConstraints(bool prop)
void initializeSolver() override
Initialize the shared dataflow solver with any common analyses required by the contained struct analy...
const IntervalAnalysisContext & getContext() const override
Return the current Context object.
void setField(const Field &f)
The dataflow analysis that computes the set of references that LLZK operations use and produce.
A reference to a "source", which is the base value from which other SSA values are derived.
Definition SourceRef.h:127
StructAnalysis(mlir::Operation *op)
Assert that this analysis is being run on a StructDefOp and initializes the analysis with the current...
void setResult(const IntervalAnalysisContext &ctx, StructIntervals &&r)
StructAnalysis(mlir::Operation *op)
Assert that this analysis is being run on a StructDefOp and initializes the analysis with the current...
virtual ~StructIntervalAnalysis()=default
mlir::LogicalResult runAnalysis(mlir::DataFlowSolver &solver, mlir::AnalysisManager &, const IntervalAnalysisContext &ctx) override
Perform the analysis and construct the Result output.
const llvm::MapVector< SourceRef, Interval > & getConstrainIntervals() const
const llvm::SetVector< ExpressionValue > getConstrainSolverConstraints() const
const llvm::SetVector< ExpressionValue > getComputeSolverConstraints() const
const llvm::MapVector< SourceRef, Interval > & getComputeIntervals() const
void print(mlir::raw_ostream &os, bool withConstraints=false, bool printCompute=false) const
static mlir::FailureOr< StructIntervals > compute(mlir::ModuleOp mod, component::StructDefOp s, mlir::DataFlowSolver &solver, const IntervalAnalysisContext &ctx)
Compute the struct intervals.
friend mlir::raw_ostream & operator<<(mlir::raw_ostream &os, const StructIntervals &si)
mlir::LogicalResult computeIntervals(mlir::DataFlowSolver &solver, const IntervalAnalysisContext &ctx)
mlir::SymbolTableCollection tables
LLZK: Added for use of symbol helper caching.
A sparse forward data-flow analysis for propagating SSA value lattices across the IR by implementing ...
mlir::dataflow::AbstractSparseLattice AbstractSparseLattice
void ensure(bool condition, const llvm::Twine &errMsg)
APSInt toAPSInt(const DynamicAPInt &i)
ExpressionValue mod(llvm::SMTSolverRef solver, const ExpressionValue &lhs, const ExpressionValue &rhs)
static unsigned getHashValue(const llzk::ExpressionValue &e)
static bool isEqual(const llzk::ExpressionValue &lhs, const llzk::ExpressionValue &rhs)
static llzk::ExpressionValue getTombstoneKey()
static llzk::ExpressionValue getEmptyKey()
unsigned operator()(const ExpressionValue &e) const
Parameters and shared objects to pass to child analyses.
const Field & getField() const
friend bool operator==(const IntervalAnalysisContext &a, const IntervalAnalysisContext &b)=default
std::optional< std::reference_wrapper< const Field > > field
IntervalDataFlowAnalysis * intervalDFA
llvm::SMTExprRef getSymbol(const SourceRef &r) const
size_t operator()(const llzk::IntervalAnalysisContext &c) const