1//===-- AnalysisPasses.td - LLZK Analysis Passes -----------*- tablegen -*-===//
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
8//===----------------------------------------------------------------------===//
10#ifndef LLZK_ANALYSIS_TD
11#define LLZK_ANALYSIS_TD
13include "llzk/Pass/PassBase.td"
14include "mlir/IR/EnumAttr.td"
16def OutputStreamDescription {
17 string r = "Specifies the stream to which the pass prints.";
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">,
26 let cppNamespace = "::llzk";
27 let genSpecializedAttr = 0;
30/// Reusable pass Option for allowing a pass user to specify the output stream.
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()'")
43/// Reusable pass Option allowing pass user to specify whether or not to dump
44/// the DOT graph to file.
46 : Option<"saveDotGraph", "saveDot", "bool",
47 /* default */ "false", "Whether to dump the graph to DOT format.">;
49//===----------------------------------------------------------------------===//
50// Analysis Pass definitions
51//===----------------------------------------------------------------------===//
53def CallGraphPrinterPass : LLZKPass<"llzk-print-call-graph"> {
54 let summary = "Print the LLZK module's call graph.";
55 let constructor = "llzk::createCallGraphPrinterPass(llvm::errs())";
58def CallGraphSCCsPrinterPass : LLZKPass<"llzk-print-call-graph-sccs"> {
59 let summary = "Print the SCCs from the LLZK module's call graph.";
60 let constructor = "llzk::createCallGraphSCCsPrinterPass(llvm::errs())";
63def ConstraintDependencyGraphPrinterPass
64 : LLZKPass<"llzk-print-constraint-dependency-graphs"> {
65 let summary = "Print constraint dependency graph for all LLZK structs.";
67 "llzk::createConstraintDependencyGraphPrinterPass(llvm::errs())";
68 let options = [Option<"runIntraprocedural", "intraprocedural", "bool",
69 /* default */ "false",
70 "Whether to run the analysis intra-procedurally only "
71 "(default is false).">];
74def IntervalAnalysisPrinterPass : LLZKPass<"llzk-print-interval-analysis"> {
75 let summary = "Print interval analysis results for all LLZK structs.";
76 let constructor = "llzk::createIntervalAnalysisPrinterPass(llvm::errs())";
78 [Option<"fieldName", "field", "std::string", /* default */ "\"\"",
79 "The field to use for interval analysis. If supplied, this "
80 "always overrides the module's detected field. If omitted, the "
81 "pass first tries to detect a single field from the enclosing "
82 "module's felt usage "
83 "and otherwise falls back to bn128. Supported fields: "
84 "bn128/bn254, babybear, goldilocks, koalabear, mersenne31">,
85 Option<"propagateInputConstraints", "propagate-input-constraints",
86 "bool", /* default */ "false",
87 "Whether to propagate constraints on inputs from @constrain to "
88 "@compute functions. "
89 "This allows for tighter intervals to possibly be found for "
91 "assuming that the witness generator would include constraints "
92 "as assertions during the computation.">,
93 Option<"printSolverConstraints", "print-solver-constraints", "bool",
94 /* default */ "false",
95 "Whether to output SMT solver constraints along with intervals.">,
96 Option<"printComputeIntervals", "print-compute-intervals", "bool",
97 /* default */ "false",
98 "Whether to print compute function intervals (default only "
99 "prints constrain function intervals).">,
103def SymbolDefTreePrinterPass : LLZKPass<"llzk-print-symbol-def-tree"> {
104 let summary = "Print symbol definition tree.";
105 let constructor = "llzk::createSymbolDefTreePrinterPass()";
106 let options = [OutputStreamOption, SaveDotGraphOption];
109def SymbolUseGraphPrinterPass : LLZKPass<"llzk-print-symbol-use-graph"> {
110 let summary = "Print symbol use graph.";
111 let constructor = "llzk::createSymbolUseGraphPrinterPass()";
112 let options = [OutputStreamOption, SaveDotGraphOption];
115def PredecessorPrinterPass : LLZKPass<"llzk-print-predecessors"> {
116 let summary = "Print the predecessors of all operations.";
117 let constructor = "llzk::createPredecessorPrinterPass()";
118 let options = [OutputStreamOption,
119 Option<"preRunRequiredAnalyses", "prerun", "bool",
120 /* default */ "false",
121 "Whether to pre-run the required dataflow analyses "
122 "(e.g., liveness analysis).">];
125#endif // LLZK_ANALYSIS_TD