LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
TransformationPasses.td
Go to the documentation of this file.
1//===-- TransformationPasses.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_POLYMORPHIC_TRANSFORMATION_PASSES_TD
11#define LLZK_POLYMORPHIC_TRANSFORMATION_PASSES_TD
12
13include "llzk/Pass/PassBase.td"
14include "mlir/IR/EnumAttr.td"
15
16def StructCleanupModeDescription {
17 string r = "Specifies the extent to which unused parameterized structs (i.e. "
18 "structs within a `poly.template`) are removed during the "
19 "flattening pass.";
20}
21
22def StructCleanupMode
23 : I32EnumAttr<"StructCleanupMode", StructCleanupModeDescription.r,
24 [
25 // Disabled: No structs are deleted.
26 I32EnumAttrCase<"Disabled", 0, "disabled">,
27 // Preimage: Only structs that were replaced with concrete
28 // instantiations are deleted.
29 I32EnumAttrCase<"Preimage", 1, "preimage">,
30 // ConcreteAsRoot: All structs that cannot be reached by a
31 // use-def chain from some concrete struct are deleted.
32 I32EnumAttrCase<"ConcreteAsRoot", 2, "concrete-as-root">,
33 // MainAsRoot: All structs that cannot be reached by a
34 // use-def chain from the main struct are deleted.
35 I32EnumAttrCase<"MainAsRoot", 3, "main-as-root">,
36]> {
37 let cppNamespace = "::llzk::polymorphic";
38 let genSpecializedAttr = 0;
39}
40
41def EmptyTemplateRemovalPass : LLZKPass<"llzk-drop-empty-templates"> {
42 let summary = "Remove empty templates";
43 let description = [{
44 Performs the following transformations:
45 - Convert templates with no constant parameters or expressions into modules.
46 - Remove templates with no struct or function definitions.
47 }];
48 let constructor = "llzk::polymorphic::createEmptyTemplateRemoval()";
49}
50
51def FlatteningPass : LLZKPass<"llzk-flatten"> {
52 let summary = "Flatten structs and unroll loops";
53 let description = [{
54 Performs the following transformations:
55 - Instantiate `affine_map` parameters of StructType and ArrayType
56 to constant values using the arguments at the instantiation site
57 - Replace parameterized structs with flattened (i.e., no parameter)
58 versions of those structs based on requested return type at calls
59 to `compute()` functions and unroll loops
60 - Unroll loops
61 }];
62 let constructor = "llzk::polymorphic::createFlatteningPass()";
63
64 let options = [Option<
65 "iterationLimit", "max-iter", "unsigned",
66 /* default */ "1000",
67 "Maximum number of times the pass will run if a fixpoint "
68 "is not reached earlier. Unrolling loops can provide more "
69 "opportunities for instantiating structs but the converse "
70 "is true as well. Thus, the pass will run multiple times "
71 "until no further changes can be made or the upper limit "
72 "provided in this option is reached.">,
73 Option<"cleanupMode", "cleanup",
74 "::llzk::polymorphic::StructCleanupMode",
75 /* default */
76 "::llzk::polymorphic::StructCleanupMode::Preimage",
77 StructCleanupModeDescription.r, [{::llvm::cl::values(
78 clEnumValN(::llzk::polymorphic::StructCleanupMode::Disabled,
79 stringifyStructCleanupMode(::llzk::polymorphic::StructCleanupMode::Disabled), "No structs are deleted."),
80 clEnumValN(::llzk::polymorphic::StructCleanupMode::Preimage,
81 stringifyStructCleanupMode(::llzk::polymorphic::StructCleanupMode::Preimage),
82 "Only structs that were replaced with concrete instantiations are deleted."),
83 clEnumValN(::llzk::polymorphic::StructCleanupMode::ConcreteAsRoot,
84 stringifyStructCleanupMode(::llzk::polymorphic::StructCleanupMode::ConcreteAsRoot),
85 "All structs that cannot be reached by a use-def chain from some concrete struct are deleted."),
86 clEnumValN(::llzk::polymorphic::StructCleanupMode::MainAsRoot,
87 stringifyStructCleanupMode(::llzk::polymorphic::StructCleanupMode::MainAsRoot),
88 "All structs that cannot be reached by a use-def chain from the \"Main\" struct are deleted.")
89 )}]>,
90 ];
91}
92
93#endif // LLZK_POLYMORPHIC_TRANSFORMATION_PASSES_TD