5#define GEN_PASS_DECL_EMPTYTEMPLATEREMOVALPASS
6#define GEN_PASS_DECL_FLATTENINGPASS
13#ifdef GEN_PASS_DECL_EMPTYTEMPLATEREMOVALPASS
15#undef GEN_PASS_DECL_EMPTYTEMPLATEREMOVALPASS
17#ifdef GEN_PASS_DEF_EMPTYTEMPLATEREMOVALPASS
24template <
typename DerivedT>
25class EmptyTemplateRemovalPassBase :
public ::mlir::OperationPass<::mlir::ModuleOp> {
27 using Base = EmptyTemplateRemovalPassBase;
29 EmptyTemplateRemovalPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
30 EmptyTemplateRemovalPassBase(
const EmptyTemplateRemovalPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
31 EmptyTemplateRemovalPassBase& operator=(
const EmptyTemplateRemovalPassBase &) =
delete;
32 EmptyTemplateRemovalPassBase(EmptyTemplateRemovalPassBase &&) =
delete;
33 EmptyTemplateRemovalPassBase& operator=(EmptyTemplateRemovalPassBase &&) =
delete;
34 ~EmptyTemplateRemovalPassBase() =
default;
37 static constexpr ::llvm::StringLiteral getArgumentName() {
38 return ::llvm::StringLiteral(
"llzk-drop-empty-templates");
40 ::llvm::StringRef getArgument()
const override {
return "llzk-drop-empty-templates"; }
42 ::llvm::StringRef getDescription()
const override {
return "Remove empty templates"; }
45 static constexpr ::llvm::StringLiteral getPassName() {
46 return ::llvm::StringLiteral(
"EmptyTemplateRemovalPass");
48 ::llvm::StringRef getName()
const override {
return "EmptyTemplateRemovalPass"; }
51 static bool classof(const ::mlir::Pass *pass) {
52 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
56 std::unique_ptr<::mlir::Pass> clonePass()
const override {
57 return std::make_unique<DerivedT>(*
static_cast<const DerivedT *
>(
this));
61 void getDependentDialects(::mlir::DialectRegistry ®istry)
const override {
62 registry.insert<llzk::LLZKDialect>();
63 registry.insert<llzk::boolean::BoolDialect>();
64 registry.insert<llzk::array::ArrayDialect>();
65 registry.insert<llzk::component::StructDialect>();
66 registry.insert<llzk::constrain::ConstrainDialect>();
67 registry.insert<llzk::felt::FeltDialect>();
68 registry.insert<llzk::global::GlobalDialect>();
69 registry.insert<llzk::include::IncludeDialect>();
70 registry.insert<llzk::function::FunctionDialect>();
71 registry.insert<llzk::string::StringDialect>();
72 registry.insert<llzk::polymorphic::PolymorphicDialect>();
73 registry.insert<mlir::arith::ArithDialect>();
74 registry.insert<mlir::scf::SCFDialect>();
80 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(EmptyTemplateRemovalPassBase<DerivedT>)
86 return std::make_unique<DerivedT>();
92 return impl::createEmptyTemplateRemovalPass();
94#undef GEN_PASS_DEF_EMPTYTEMPLATEREMOVALPASS
100#ifdef GEN_PASS_DECL_FLATTENINGPASS
101struct FlatteningPassOptions {
102 unsigned iterationLimit = 1000;
107#undef GEN_PASS_DECL_FLATTENINGPASS
109#ifdef GEN_PASS_DEF_FLATTENINGPASS
120template <
typename DerivedT>
121class FlatteningPassBase :
public ::mlir::OperationPass<::mlir::ModuleOp> {
123 using Base = FlatteningPassBase;
125 FlatteningPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
126 FlatteningPassBase(
const FlatteningPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
127 FlatteningPassBase& operator=(
const FlatteningPassBase &) =
delete;
128 FlatteningPassBase(FlatteningPassBase &&) =
delete;
129 FlatteningPassBase& operator=(FlatteningPassBase &&) =
delete;
130 ~FlatteningPassBase() =
default;
133 static constexpr ::llvm::StringLiteral getArgumentName() {
134 return ::llvm::StringLiteral(
"llzk-flatten");
136 ::llvm::StringRef getArgument()
const override {
return "llzk-flatten"; }
138 ::llvm::StringRef getDescription()
const override {
return "Flatten structs and unroll loops"; }
141 static constexpr ::llvm::StringLiteral getPassName() {
142 return ::llvm::StringLiteral(
"FlatteningPass");
144 ::llvm::StringRef getName()
const override {
return "FlatteningPass"; }
147 static bool classof(const ::mlir::Pass *pass) {
148 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
152 std::unique_ptr<::mlir::Pass> clonePass()
const override {
153 return std::make_unique<DerivedT>(*
static_cast<const DerivedT *
>(
this));
157 void getDependentDialects(::mlir::DialectRegistry ®istry)
const override {
158 registry.insert<llzk::LLZKDialect>();
159 registry.insert<llzk::boolean::BoolDialect>();
160 registry.insert<llzk::array::ArrayDialect>();
161 registry.insert<llzk::component::StructDialect>();
162 registry.insert<llzk::constrain::ConstrainDialect>();
163 registry.insert<llzk::felt::FeltDialect>();
164 registry.insert<llzk::global::GlobalDialect>();
165 registry.insert<llzk::include::IncludeDialect>();
166 registry.insert<llzk::function::FunctionDialect>();
167 registry.insert<llzk::string::StringDialect>();
168 registry.insert<llzk::polymorphic::PolymorphicDialect>();
169 registry.insert<mlir::arith::ArithDialect>();
170 registry.insert<mlir::scf::SCFDialect>();
176 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(FlatteningPassBase<DerivedT>)
178 FlatteningPassBase(FlatteningPassOptions options) : FlatteningPassBase() {
179 iterationLimit = std::move(options.iterationLimit);
180 cleanupMode = std::move(options.cleanupMode);
183 ::mlir::Pass::Option<unsigned> iterationLimit{*
this,
"max-iter", ::llvm::cl::desc(
"Maximum number of times the pass will run if a fixpoint is not reached earlier. Unrolling loops can provide more opportunities for instantiating structs but the converse is true as well. Thus, the pass will run multiple times until no further changes can be made or the upper limit provided in this option is reached."), ::llvm::cl::init(1000)};
184 ::mlir::Pass::Option<::llzk::polymorphic::FlatteningCleanupMode> cleanupMode{*
this,
"cleanup", ::llvm::cl::desc(
"Specifies the extent to which unused parameterized definitions (i.e. structs or free functions within a `poly.template`) are removed during the flattening pass."), ::llvm::cl::init(
::llzk::polymorphic::FlatteningCleanupMode::Preimage), ::llvm::cl::values(
189 "Only definitions that were replaced with concrete instantiations are deleted."),
192 "All definitions that cannot be reached by a use-def chain from some concrete definition are deleted."),
195 "All definitions that cannot be reached by a use-def chain from the \"Main\" struct are deleted.")
200 return std::make_unique<DerivedT>();
204 return std::make_unique<DerivedT>(std::move(options));
210 return impl::createFlatteningPass();
214 return impl::createFlatteningPass(std::move(options));
216#undef GEN_PASS_DEF_FLATTENINGPASS
218#ifdef GEN_PASS_REGISTRATION
225 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
232 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
242 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
249 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
262#undef GEN_PASS_REGISTRATION
265#ifdef GEN_PASS_CLASSES
267template <
typename DerivedT>
268class EmptyTemplateRemovalPassBase :
public ::mlir::OperationPass<::mlir::ModuleOp> {
270 using Base = EmptyTemplateRemovalPassBase;
272 EmptyTemplateRemovalPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
273 EmptyTemplateRemovalPassBase(
const EmptyTemplateRemovalPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
274 EmptyTemplateRemovalPassBase& operator=(
const EmptyTemplateRemovalPassBase &) =
delete;
275 EmptyTemplateRemovalPassBase(EmptyTemplateRemovalPassBase &&) =
delete;
276 EmptyTemplateRemovalPassBase& operator=(EmptyTemplateRemovalPassBase &&) =
delete;
277 ~EmptyTemplateRemovalPassBase() =
default;
280 static constexpr ::llvm::StringLiteral getArgumentName() {
281 return ::llvm::StringLiteral(
"llzk-drop-empty-templates");
283 ::llvm::StringRef getArgument()
const override {
return "llzk-drop-empty-templates"; }
285 ::llvm::StringRef getDescription()
const override {
return "Remove empty templates"; }
288 static constexpr ::llvm::StringLiteral getPassName() {
289 return ::llvm::StringLiteral(
"EmptyTemplateRemovalPass");
291 ::llvm::StringRef getName()
const override {
return "EmptyTemplateRemovalPass"; }
294 static bool classof(const ::mlir::Pass *pass) {
295 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
299 std::unique_ptr<::mlir::Pass> clonePass()
const override {
300 return std::make_unique<DerivedT>(*
static_cast<const DerivedT *
>(
this));
304 void getDependentDialects(::mlir::DialectRegistry ®istry)
const override {
305 registry.insert<llzk::LLZKDialect>();
306 registry.insert<llzk::boolean::BoolDialect>();
307 registry.insert<llzk::array::ArrayDialect>();
308 registry.insert<llzk::component::StructDialect>();
309 registry.insert<llzk::constrain::ConstrainDialect>();
310 registry.insert<llzk::felt::FeltDialect>();
311 registry.insert<llzk::global::GlobalDialect>();
312 registry.insert<llzk::include::IncludeDialect>();
313 registry.insert<llzk::function::FunctionDialect>();
314 registry.insert<llzk::string::StringDialect>();
315 registry.insert<llzk::polymorphic::PolymorphicDialect>();
316 registry.insert<mlir::arith::ArithDialect>();
317 registry.insert<mlir::scf::SCFDialect>();
323 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(EmptyTemplateRemovalPassBase<DerivedT>)
328template <
typename DerivedT>
329class FlatteningPassBase :
public ::mlir::OperationPass<::mlir::ModuleOp> {
331 using Base = FlatteningPassBase;
333 FlatteningPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
334 FlatteningPassBase(
const FlatteningPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
335 FlatteningPassBase& operator=(
const FlatteningPassBase &) =
delete;
336 FlatteningPassBase(FlatteningPassBase &&) =
delete;
337 FlatteningPassBase& operator=(FlatteningPassBase &&) =
delete;
338 ~FlatteningPassBase() =
default;
341 static constexpr ::llvm::StringLiteral getArgumentName() {
342 return ::llvm::StringLiteral(
"llzk-flatten");
344 ::llvm::StringRef getArgument()
const override {
return "llzk-flatten"; }
346 ::llvm::StringRef getDescription()
const override {
return "Flatten structs and unroll loops"; }
349 static constexpr ::llvm::StringLiteral getPassName() {
350 return ::llvm::StringLiteral(
"FlatteningPass");
352 ::llvm::StringRef getName()
const override {
return "FlatteningPass"; }
355 static bool classof(const ::mlir::Pass *pass) {
356 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
360 std::unique_ptr<::mlir::Pass> clonePass()
const override {
361 return std::make_unique<DerivedT>(*
static_cast<const DerivedT *
>(
this));
365 void getDependentDialects(::mlir::DialectRegistry ®istry)
const override {
366 registry.insert<llzk::LLZKDialect>();
367 registry.insert<llzk::boolean::BoolDialect>();
368 registry.insert<llzk::array::ArrayDialect>();
369 registry.insert<llzk::component::StructDialect>();
370 registry.insert<llzk::constrain::ConstrainDialect>();
371 registry.insert<llzk::felt::FeltDialect>();
372 registry.insert<llzk::global::GlobalDialect>();
373 registry.insert<llzk::include::IncludeDialect>();
374 registry.insert<llzk::function::FunctionDialect>();
375 registry.insert<llzk::string::StringDialect>();
376 registry.insert<llzk::polymorphic::PolymorphicDialect>();
377 registry.insert<mlir::arith::ArithDialect>();
378 registry.insert<mlir::scf::SCFDialect>();
384 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(FlatteningPassBase<DerivedT>)
387 ::mlir::Pass::Option<unsigned> iterationLimit{*
this,
"max-iter", ::llvm::cl::desc(
"Maximum number of times the pass will run if a fixpoint is not reached earlier. Unrolling loops can provide more opportunities for instantiating structs but the converse is true as well. Thus, the pass will run multiple times until no further changes can be made or the upper limit provided in this option is reached."), ::llvm::cl::init(1000)};
388 ::mlir::Pass::Option<::llzk::polymorphic::FlatteningCleanupMode> cleanupMode{*
this,
"cleanup", ::llvm::cl::desc(
"Specifies the extent to which unused parameterized definitions (i.e. structs or free functions within a `poly.template`) are removed during the flattening pass."), ::llvm::cl::init(
::llzk::polymorphic::FlatteningCleanupMode::Preimage), ::llvm::cl::values(
393 "Only definitions that were replaced with concrete instantiations are deleted."),
396 "All definitions that cannot be reached by a use-def chain from some concrete definition are deleted."),
399 "All definitions that cannot be reached by a use-def chain from the \"Main\" struct are deleted.")
402#undef GEN_PASS_CLASSES
void registerTransformationPasses()
std::unique_ptr<::mlir::Pass > createEmptyTemplateRemovalPass()
std::unique_ptr<::mlir::Pass > createFlatteningPass()
void registerFlatteningPass()
::llvm::StringRef stringifyFlatteningCleanupMode(FlatteningCleanupMode val)
void registerEmptyTemplateRemovalPass()
void registerFlatteningPassPass()
void registerEmptyTemplateRemovalPassPass()