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 FlatteningCleanupModeDescription {
18 "Specifies the extent to which unused parameterized definitions (i.e. "
19 "structs or free functions within a `poly.template`) are removed during "
20 "the flattening pass.";
23def FlatteningCleanupMode
24 : I32EnumAttr<"FlatteningCleanupMode", FlatteningCleanupModeDescription.r,
26 // Disabled: No definitions are deleted.
27 I32EnumAttrCase<"Disabled", 0, "disabled">,
28 // Preimage: Only definitions that were replaced with
29 // concrete instantiations are deleted.
30 I32EnumAttrCase<"Preimage", 1, "preimage">,
31 // ConcreteAsRoot: All definitions that cannot be reached
32 // by a use-def chain from some concrete definition are
34 I32EnumAttrCase<"ConcreteAsRoot", 2, "concrete-as-root">,
35 // MainAsRoot: All definitions that cannot be reached by a
36 // use-def chain from the main struct are deleted.
37 I32EnumAttrCase<"MainAsRoot", 3, "main-as-root">,
39 let cppNamespace = "::llzk::polymorphic";
40 let genSpecializedAttr = 0;
43def EmptyTemplateRemovalPass : LLZKPass<"llzk-drop-empty-templates"> {
44 let summary = "Remove empty templates";
46 Performs the following transformations:
47 - Convert templates with no constant parameters or expressions into modules.
48 - Remove templates with no struct or function definitions.
52def FlatteningPass : LLZKPass<"llzk-flatten"> {
53 let summary = "Flatten structs and unroll loops";
55 Performs the following transformations:
56 - Instantiate `affine_map` parameters of StructType and ArrayType
57 to constant values using the arguments at the instantiation site
58 - Replace parameterized structs with flattened (i.e., no parameter)
59 versions of those structs based on requested return type at calls
60 to `compute()` functions and unroll loops
64 [Option<"iterationLimit", "max-iter", "unsigned",
66 "Maximum number of times the pass will run if a fixpoint "
67 "is not reached earlier. Unrolling loops can provide more "
68 "opportunities for instantiating structs but the converse "
69 "is true as well. Thus, the pass will run multiple times "
70 "until no further changes can be made or the upper limit "
71 "provided in this option is reached.">,
72 Option<"cleanupMode", "cleanup",
73 "::llzk::polymorphic::FlatteningCleanupMode",
75 "::llzk::polymorphic::FlatteningCleanupMode::Preimage",
76 FlatteningCleanupModeDescription.r, [{::llvm::cl::values(
77 clEnumValN(::llzk::polymorphic::FlatteningCleanupMode::Disabled,
78 stringifyFlatteningCleanupMode(::llzk::polymorphic::FlatteningCleanupMode::Disabled), "No definitions are deleted."),
79 clEnumValN(::llzk::polymorphic::FlatteningCleanupMode::Preimage,
80 stringifyFlatteningCleanupMode(::llzk::polymorphic::FlatteningCleanupMode::Preimage),
81 "Only definitions that were replaced with concrete instantiations are deleted."),
82 clEnumValN(::llzk::polymorphic::FlatteningCleanupMode::ConcreteAsRoot,
83 stringifyFlatteningCleanupMode(::llzk::polymorphic::FlatteningCleanupMode::ConcreteAsRoot),
84 "All definitions that cannot be reached by a use-def chain from some concrete definition are deleted."),
85 clEnumValN(::llzk::polymorphic::FlatteningCleanupMode::MainAsRoot,
86 stringifyFlatteningCleanupMode(::llzk::polymorphic::FlatteningCleanupMode::MainAsRoot),
87 "All definitions that cannot be reached by a use-def chain from the \"Main\" struct are deleted.")
92#endif // LLZK_POLYMORPHIC_TRANSFORMATION_PASSES_TD