1//===-- LLZKTransformationPasses.td ------------------------*- 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_TRANSFORMATION_PASSES_TD
11#define LLZK_TRANSFORMATION_PASSES_TD
13include "llzk/Pass/PassBase.td"
15def RedundantReadAndWriteEliminationPass
16 : LLZKPass<"llzk-duplicate-read-write-elim"> {
17 let summary = "Remove redundant reads and writes";
19 Remove read and write operations to struct members and arrays that are redundant or unnecessary.
21 let constructor = "llzk::createRedundantReadAndWriteEliminationPass()";
24def RedundantOperationEliminationPass : LLZKPass<"llzk-duplicate-op-elim"> {
25 let summary = "Remove redundant operations";
27 Remove llzk and arith dialect operations that produce the same results
28 as previously executed operations.
30 Pass should be run after `llzk-duplicate-read-write-elim` for maximum effect.
32 let constructor = "llzk::createRedundantOperationEliminationPass()";
35def UnusedDeclarationEliminationPass
36 : LLZKPass<"llzk-unused-declaration-elim"> {
37 let summary = "Remove unused member and struct declarations";
39 Remove member and struct declarations that are unused within the current compilation
40 unit. Note that this pass may cause linking issues with external modules that
41 depend on any unused member and struct declarations from this compilation unit.
43 Pass should be run after `llzk-duplicate-read-write-elim`
44 and `llzk-duplicate-op-elim` for maximum effect.
46 let constructor = "llzk::createUnusedDeclarationEliminationPass()";
47 let options = [Option<"removeStructs", "remove-structs", "bool",
48 /* default */ "false",
49 "Whether to remove unused struct definitions as well. "
50 "Requires module to declare a Main component, "
51 "otherwise all components will appear unused.">,
55def PolyLoweringPass : LLZKPass<"llzk-poly-lowering-pass"> {
57 "Lower the degree of all polynomial equations to a specified maximum";
59 Rewrites constraint expressions into an (observationally) equivalent system where the degree of
60 every polynomial is less than or equal to the specified maximum.
62 This pass is best used as part of the `-llzk-full-poly-lowering` pipeline, which includes
63 additional cleanup passes to ensure correctness and optimal performance.
65 let constructor = "llzk::createPolyLoweringPass()";
66 let options = [Option<"maxDegree", "max-degree", "unsigned",
68 "Maximum degree of constraint polynomials "
69 "(default 2, minimum 2)">,
73def InlineStructsPass : LLZKPass<"llzk-inline-structs"> {
74 let summary = "Inlines nested structs (i.e., subcomponents).";
76 This pass inlines nested structs (i.e., subcomponents) at struct-type members and at calls to the
77 subcomponent compute/constrain functions. Inlining decisions are guided by the call graph of
78 "constrain" functions.
80 The `max-merge-complexity` parameter can be used to limit the complexity of the resulting structs such
81 that a potential inlining will not take place if doing so would push the sum of constraint and
82 multiplications in the combined struct over the limit. The default value `0` indicates no limits
83 which means all structs will be inlined into the Main struct.
85 This pass should be run after `llzk-flatten` to ensure structs do not have template parameters
86 because structs with template parameters cannot (currently) be inlined. Inlining is also not
87 (currently) supported for subcomponent structs stored in an array-type member.
89 This pass also assumes that all subcomponents that are created by calling a struct "@compute"
90 function are ultimately written to exactly one member within the current struct.
92 let constructor = "llzk::createInlineStructsPass()";
93 let options = [Option<"maxComplexity", "max-merge-complexity", "uint64_t",
95 "Maximum allowed constraint+multiplications in merged "
96 "@constrain functions">,
100def ComputeConstrainToProductPass
101 : LLZKPass<"llzk-compute-constrain-to-product"> {
102 let summary = "Replace separate @compute and @constrain functions in a "
103 "struct with a single @product function";
104 let description = summary;
105 let constructor = "llzk::createComputeConstrainToProductPass()";
106 let options = [Option<"rootStruct", "root-struct", "std::string",
107 /* default */ "\"@Main\"",
108 "Root struct at which to start alignment "
109 "(default to `@Main`)">];
112def FuseProductLoopsPass : LLZKPass<"llzk-fuse-product-loops"> {
113 let summary = "Fuse matching witness/constraint loops in a @product function";
114 let description = summary;
115 let constructor = "llzk::createFuseProductLoopsPass()";
119def EnforceNoMemberOverwritePass : LLZKPass<"llzk-enforce-no-overwrite"> {
120 let summary = "Checks that every struct member is written exactly once";
122 This pass currently reports an error if any struct member may not be written
123 exactly once (i.e. overwritten or left uninitialized), and does not
124 attempt to perform any repairs (e.g. SSA-ifying overwritten struct
125 members, or default-initializing unwritten members). This pass
126 overapproximates conditionals, and can result in false positives.
128 let constructor = "llzk::createNoOverwritesPass()";
132#endif // LLZK_TRANSFORMATION_PASSES_TD