LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
LLZKTransformationPasses.td
Go to the documentation of this file.
1//===-- LLZKTransformationPasses.td ------------------------*- 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_TRANSFORMATION_PASSES_TD
11#define LLZK_TRANSFORMATION_PASSES_TD
12
13include "llzk/Pass/PassBase.td"
14
15def RedundantReadAndWriteEliminationPass
16 : LLZKPass<"llzk-duplicate-read-write-elim"> {
17 let summary = "Remove redundant reads and writes";
18 let description = [{
19 Remove read and write operations to struct fields and arrays that are redundant or unnecessary.
20 }];
21 let constructor = "llzk::createRedundantReadAndWriteEliminationPass()";
22}
23
24def RedundantOperationEliminationPass : LLZKPass<"llzk-duplicate-op-elim"> {
25 let summary = "Remove redundant operations";
26 let description = [{
27 Remove llzk and arith dialect operations that produce the same results
28 as previously executed operations.
29
30 Pass should be run after `llzk-duplicate-read-write-elim` for maximum effect.
31 }];
32 let constructor = "llzk::createRedundantOperationEliminationPass()";
33}
34
35def UnusedDeclarationEliminationPass
36 : LLZKPass<"llzk-unused-declaration-elim"> {
37 let summary = "Remove unused field and struct declarations";
38 let description = [{
39 Remove field 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 field and struct declarations from this compilation unit.
42
43 Pass should be run after `llzk-duplicate-read-write-elim`
44 and `llzk-duplicate-op-elim` for maximum effect.
45 }];
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.">,
52 ];
53}
54
55def PolyLoweringPass : LLZKPass<"llzk-poly-lowering-pass"> {
56 let summary =
57 "Lowers the degree of all polynomial equations to a specified maximum";
58 let description = [{
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.
61
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.
64 }];
65 let constructor = "llzk::createPolyLoweringPass()";
66 let options = [Option<"maxDegree", "max-degree", "unsigned",
67 /* default */ "2",
68 "Maximum degree of constraint polynomials "
69 "(default 2, minimum 2)">,
70 ];
71}
72
73def InlineStructsPass : LLZKPass<"llzk-inline-structs"> {
74 let summary = "Inlines nested structs (i.e., subcomponents).";
75 let description = [{
76 This pass inlines nested structs (i.e., subcomponents) at struct-type fields and at calls to the
77 subcomponent compute/constrain functions. Inlining decisions are guided by the call graph of
78 "constrain" functions.
79
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.
84
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 field.
88
89 This pass also assumes that all subcomponents that are created by calling a struct "@compute"
90 function are ultimately written to exactly one field within the current struct.
91 }];
92 let constructor = "llzk::createInlineStructsPass()";
93 let options = [Option<"maxComplexity", "max-merge-complexity", "uint64_t",
94 /* default */ "0",
95 "Maximum allowed constraint+multiplications in merged "
96 "@constrain functions">,
97 ];
98}
99
100def R1CSLoweringPass : LLZKPass<"llzk-r1cs-lowering"> {
101 let summary = "Rewrites constraints to be compatible with R1CS constraints "
102 "i.e a*b - c = 0";
103 let description = [{
104 Transforms LLZK constraints into an equivalent set of R1CS constraints expressed in the r1cs dialect.
105 This pass is best used as part of the `-llzk-full-r1cs-lowering` pipeline which includes
106 a degree lowering pass and clean up passes to ensure correctness and performance.
107 }];
108 let constructor = "llzk::createR1CSLoweringPass()";
109}
110
111#endif // LLZK_TRANSFORMATION_PASSES_TD