1//===-- TransformationPasses.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_POLYMORPHIC_TRANSFORMATION_PASSES_TD
11#define LLZK_POLYMORPHIC_TRANSFORMATION_PASSES_TD
13include "llzk/Pass/PassBase.td"
14include "mlir/IR/EnumAttr.td"
16def StructCleanupModeDescription {
17 string r = "Specifies the extent to which unused parameterized structs are "
18 "removed during the flattening pass.";
22 : I32EnumAttr<"StructCleanupMode", StructCleanupModeDescription.r,
24 // Disabled: No structs are deleted.
25 I32EnumAttrCase<"Disabled", 0, "disabled">,
26 // Preimage: Only structs that were replaced with concrete
27 // instantiations are deleted.
28 I32EnumAttrCase<"Preimage", 1, "preimage">,
29 // ConcreteAsRoot: All structs that cannot be reached by a
30 // use-def chain from some concrete struct are deleted.
31 I32EnumAttrCase<"ConcreteAsRoot", 2, "concrete-as-root">,
32 // MainAsRoot: All structs that cannot be reached by a
33 // use-def chain from the "Main" struct are deleted.
34 I32EnumAttrCase<"MainAsRoot", 3, "main-as-root">,
36 let cppNamespace = "::llzk::polymorphic";
37 let genSpecializedAttr = 0;
40def EmptyParamListRemovalPass : LLZKPass<"llzk-drop-empty-params"> {
41 let summary = "Remove empty struct parameter lists";
42 let constructor = "llzk::polymorphic::createEmptyParamListRemoval()";
45def FlatteningPass : LLZKPass<"llzk-flatten"> {
46 let summary = "Flatten structs and unroll loops";
48 Performs the following transformations:
49 - Instantiate `affine_map` parameters of StructType and ArrayType
50 to constant values using the arguments at the instantiation site
51 - Replace parameterized structs with flattened (i.e., no parameter)
52 versions of those structs based on requested return type at calls
53 to `compute()` functions and unroll loops
56 let constructor = "llzk::polymorphic::createFlatteningPass()";
58 let options = [Option<
59 "iterationLimit", "max-iter", "unsigned",
61 "Maximum number of times the pass will run if a fixpoint "
62 "is not reached earlier. Unrolling loops can provide more "
63 "opportunities for instantiating structs but the converse "
64 "is true as well. Thus, the pass will run multiple times "
65 "until no further changes can be made or the upper limit "
66 "provided in this option is reached.">,
67 Option<"cleanupMode", "cleanup",
68 "::llzk::polymorphic::StructCleanupMode",
70 "::llzk::polymorphic::StructCleanupMode::Preimage",
71 StructCleanupModeDescription.r, [{::llvm::cl::values(
72 clEnumValN(::llzk::polymorphic::StructCleanupMode::Disabled,
73 stringifyStructCleanupMode(::llzk::polymorphic::StructCleanupMode::Disabled), "No structs are deleted."),
74 clEnumValN(::llzk::polymorphic::StructCleanupMode::Preimage,
75 stringifyStructCleanupMode(::llzk::polymorphic::StructCleanupMode::Preimage),
76 "Only structs that were replaced with concrete instantiations are deleted."),
77 clEnumValN(::llzk::polymorphic::StructCleanupMode::ConcreteAsRoot,
78 stringifyStructCleanupMode(::llzk::polymorphic::StructCleanupMode::ConcreteAsRoot),
79 "All structs that cannot be reached by a use-def chain from some concrete struct are deleted."),
80 clEnumValN(::llzk::polymorphic::StructCleanupMode::MainAsRoot,
81 stringifyStructCleanupMode(::llzk::polymorphic::StructCleanupMode::MainAsRoot),
82 "All structs that cannot be reached by a use-def chain from the \"Main\" struct are deleted.")
87#endif // LLZK_POLYMORPHIC_TRANSFORMATION_PASSES_TD