LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
AnalysisPasses.td
Go to the documentation of this file.
1//===-- AnalysisPasses.td - LLZK Analysis Passes -----------*- tablegen -*-===//
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#ifndef LLZK_ANALYSIS_TD
11#define LLZK_ANALYSIS_TD
12
13include "llzk/Pass/PassBase.td"
14include "mlir/IR/EnumAttr.td"
15
16def OutputStreamDescription {
17 string r = "Specifies the stream to which the pass prints.";
18}
19
20/// Enumeration of the output stream options in LLVM.
21def OutputStream : I32EnumAttr<"OutputStream", OutputStreamDescription.r,
22 [I32EnumAttrCase<"Outs", 1, "outs">,
23 I32EnumAttrCase<"Errs", 2, "errs">,
24 I32EnumAttrCase<"Dbgs", 3, "dbgs">,
25]> {
26 let cppNamespace = "::llzk";
27 let genSpecializedAttr = 0;
28}
29
30/// Reusable pass Option for allowing a pass user to specify the output stream.
31def OutputStreamOption
32 : Option<"outputStream", "stream", "::llzk::OutputStream",
33 /* default */ "::llzk::OutputStream::Errs",
34 OutputStreamDescription.r, [{::llvm::cl::values(
35 clEnumValN(::llzk::OutputStream::Outs, stringifyOutputStream(::llzk::OutputStream::Outs),
36 "Print pass output to 'llvm::outs()'"),
37 clEnumValN(::llzk::OutputStream::Errs, stringifyOutputStream(::llzk::OutputStream::Errs),
38 "Print pass output to 'llvm::errs()'"),
39 clEnumValN(::llzk::OutputStream::Dbgs, stringifyOutputStream(::llzk::OutputStream::Dbgs),
40 "Print pass output to 'llvm::dbgs()'")
41 )}]>;
42
43/// Reusable pass Option allowing pass user to specify whether or not to dump
44/// the DOT graph to file.
45def SaveDotGraphOption
46 : Option<"saveDotGraph", "saveDot", "bool",
47 /* default */ "false", "Whether to dump the graph to DOT format.">;
48
49//===----------------------------------------------------------------------===//
50// Analysis Pass definitions
51//===----------------------------------------------------------------------===//
52
53def CallGraphPrinterPass : LLZKPass<"llzk-print-call-graph"> {
54 let summary = "Print the LLZK module's call graph.";
55 let options = [OutputStreamOption];
56}
57
58def CallGraphSCCsPrinterPass : LLZKPass<"llzk-print-call-graph-sccs"> {
59 let summary = "Print the SCCs from the LLZK module's call graph.";
60 let options = [OutputStreamOption];
61}
62
63def ConstraintDependencyGraphPrinterPass
64 : LLZKPass<"llzk-print-constraint-dependency-graphs"> {
65 let summary = "Print constraint dependency graph for all LLZK structs.";
66 let options = [OutputStreamOption,
67 Option<"runIntraprocedural", "intraprocedural", "bool",
68 /* default */ "false",
69 "Whether to run the analysis intra-procedurally only "
70 "(default is false).">];
71}
72
73def IntervalAnalysisPrinterPass : LLZKPass<"llzk-print-interval-analysis"> {
74 let summary = "Print interval analysis results for all LLZK structs.";
75 let description = [{
76 An explicit `field` overrides the detected field for interval arithmetic,
77 but preserves the declared-field semantics of `felt.const`. A literal `N`
78 with declared modulus `p` is first interpreted as `N mod p`, then reduced
79 into the analysis field of modulus `q`: `(N mod p) mod q`. Fieldless
80 constants are reduced directly as `N mod q`.
81
82 For example, `felt.const 8` in a field of modulus `7` contributes `1` when
83 analyzed with modulus `5`, both before and after constant canonicalization.
84 The option changes the analysis field; it does not retarget declared felt
85 types or reinterpret their literals as raw integers in another field.
86 }];
87 let options =
88 [OutputStreamOption,
89 Option<
90 "fieldName", "field", "std::string", /* default */ "\"\"",
91 "The field to use for interval analysis. If supplied, this "
92 "always overrides the module's detected field. If omitted, the "
93 "pass first tries to detect a single field from the enclosing "
94 "module's felt usage and otherwise falls back to bn128. "
95 "Constants retain their declared-field meaning before reduction "
96 "in the analysis field; fieldless literals use the analysis field "
97 "directly. "
98 "Supported fields: bn128/bn254, babybear, goldilocks, grumpkin, "
99 "koalabear, mersenne31">,
100 Option<"propagateInputConstraints", "propagate-input-constraints",
101 "bool", /* default */ "false",
102 "Whether to propagate constraints on inputs from @constrain to "
103 "@compute functions. This allows for tighter intervals to "
104 "possibly be found for computed values, assuming that the "
105 "witness generator would include constraints as assertions "
106 "during the computation.">,
107 Option<"printSolverConstraints", "print-solver-constraints", "bool",
108 /* default */ "false",
109 "Whether to output SMT solver constraints along with intervals.">,
110 Option<"printComputeIntervals", "print-compute-intervals", "bool",
111 /* default */ "false",
112 "Whether to print compute function intervals (default only "
113 "prints constrain function intervals).">,
114 Option<"printUnreducedIntervals", "print-unreduced-intervals", "bool",
115 /* default */ "false",
116 "Whether to print tracked unreduced intervals alongside reduced "
117 "interval summaries.">,
118 Option<"printSSAIntervals", "print-ssa-intervals", "bool",
119 /* default */ "false",
120 "Whether to print per-SSA intervals for function arguments and "
121 "scalar op results.">,
122 ];
123}
124
125def SymbolDefTreePrinterPass : LLZKPass<"llzk-print-symbol-def-tree"> {
126 let summary = "Print symbol definition tree.";
127 let options = [OutputStreamOption, SaveDotGraphOption];
128}
129
130def SymbolUseGraphPrinterPass : LLZKPass<"llzk-print-symbol-use-graph"> {
131 let summary = "Print symbol use graph.";
132 let options = [OutputStreamOption, SaveDotGraphOption];
133}
134
135def PredecessorPrinterPass : LLZKPass<"llzk-print-predecessors"> {
136 let summary = "Print the predecessors of all operations.";
137 let options = [OutputStreamOption,
138 Option<"preRunRequiredAnalyses", "prerun", "bool",
139 /* default */ "false",
140 "Whether to pre-run the required dataflow analyses "
141 "(e.g., liveness analysis).">];
142}
143
144#endif // LLZK_ANALYSIS_TD