LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
TransformationPasses.h.inc
Go to the documentation of this file.
1/* Autogenerated by mlir-tblgen; don't manually edit */
2
3#ifdef GEN_PASS_DECL
4// Generate declarations for all passes.
5#define GEN_PASS_DECL_EMPTYTEMPLATEREMOVALPASS
6#define GEN_PASS_DECL_FLATTENINGPASS
7#define GEN_PASS_DECL_TYPEVARINFERENCEPASS
8#define GEN_PASS_DECL_WILDCARDARRAYSPECIALIZATIONPASS
9#undef GEN_PASS_DECL
10#endif // GEN_PASS_DECL
11
12//===----------------------------------------------------------------------===//
13// EmptyTemplateRemovalPass
14//===----------------------------------------------------------------------===//
15#ifdef GEN_PASS_DECL_EMPTYTEMPLATEREMOVALPASS
16std::unique_ptr<::mlir::Pass> createEmptyTemplateRemovalPass();
17#undef GEN_PASS_DECL_EMPTYTEMPLATEREMOVALPASS
18#endif // GEN_PASS_DECL_EMPTYTEMPLATEREMOVALPASS
19#ifdef GEN_PASS_DEF_EMPTYTEMPLATEREMOVALPASS
20
21namespace impl {
22 std::unique_ptr<::mlir::Pass> createEmptyTemplateRemovalPass();
23} // namespace impl
24namespace impl {
25
26template <typename DerivedT>
27class EmptyTemplateRemovalPassBase : public ::mlir::OperationPass<::mlir::ModuleOp> {
28public:
29 using Base = EmptyTemplateRemovalPassBase;
30
31 EmptyTemplateRemovalPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
32 EmptyTemplateRemovalPassBase(const EmptyTemplateRemovalPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
33 EmptyTemplateRemovalPassBase& operator=(const EmptyTemplateRemovalPassBase &) = delete;
34 EmptyTemplateRemovalPassBase(EmptyTemplateRemovalPassBase &&) = delete;
35 EmptyTemplateRemovalPassBase& operator=(EmptyTemplateRemovalPassBase &&) = delete;
36 ~EmptyTemplateRemovalPassBase() = default;
37
39 static constexpr ::llvm::StringLiteral getArgumentName() {
40 return ::llvm::StringLiteral("llzk-drop-empty-templates");
41 }
42 ::llvm::StringRef getArgument() const override { return "llzk-drop-empty-templates"; }
43
44 ::llvm::StringRef getDescription() const override { return "Remove empty templates"; }
45
47 static constexpr ::llvm::StringLiteral getPassName() {
48 return ::llvm::StringLiteral("EmptyTemplateRemovalPass");
49 }
50 ::llvm::StringRef getName() const override { return "EmptyTemplateRemovalPass"; }
51
53 static bool classof(const ::mlir::Pass *pass) {
54 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
55 }
56
58 std::unique_ptr<::mlir::Pass> clonePass() const override {
59 return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
60 }
61
63 void getDependentDialects(::mlir::DialectRegistry &registry) const override {
64 registry.insert<llzk::LLZKDialect>();
65 registry.insert<llzk::boolean::BoolDialect>();
66 registry.insert<llzk::array::ArrayDialect>();
67 registry.insert<llzk::component::StructDialect>();
68 registry.insert<llzk::constrain::ConstrainDialect>();
69 registry.insert<llzk::felt::FeltDialect>();
70 registry.insert<llzk::global::GlobalDialect>();
71 registry.insert<llzk::include::IncludeDialect>();
72 registry.insert<llzk::function::FunctionDialect>();
73 registry.insert<llzk::string::StringDialect>();
74 registry.insert<llzk::polymorphic::PolymorphicDialect>();
75 registry.insert<mlir::arith::ArithDialect>();
76 registry.insert<mlir::scf::SCFDialect>();
77 }
78
82 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(EmptyTemplateRemovalPassBase<DerivedT>)
83
84protected:
85private:
86
87 friend std::unique_ptr<::mlir::Pass> createEmptyTemplateRemovalPass() {
88 return std::make_unique<DerivedT>();
89 }
90};
91} // namespace impl
92
93std::unique_ptr<::mlir::Pass> createEmptyTemplateRemovalPass() {
94 return impl::createEmptyTemplateRemovalPass();
95}
96#undef GEN_PASS_DEF_EMPTYTEMPLATEREMOVALPASS
97#endif // GEN_PASS_DEF_EMPTYTEMPLATEREMOVALPASS
98
99//===----------------------------------------------------------------------===//
100// FlatteningPass
101//===----------------------------------------------------------------------===//
102#ifdef GEN_PASS_DECL_FLATTENINGPASS
103struct FlatteningPassOptions {
104 unsigned iterationLimit = 1000;
106};
107std::unique_ptr<::mlir::Pass> createFlatteningPass();
108std::unique_ptr<::mlir::Pass> createFlatteningPass(FlatteningPassOptions options);
109#undef GEN_PASS_DECL_FLATTENINGPASS
110#endif // GEN_PASS_DECL_FLATTENINGPASS
111#ifdef GEN_PASS_DEF_FLATTENINGPASS
112
113namespace impl {
114 std::unique_ptr<::mlir::Pass> createFlatteningPass();
115} // namespace impl
116
117namespace impl {
118 std::unique_ptr<::mlir::Pass> createFlatteningPass(FlatteningPassOptions options);
119} // namespace impl
120namespace impl {
121
122template <typename DerivedT>
123class FlatteningPassBase : public ::mlir::OperationPass<::mlir::ModuleOp> {
124public:
125 using Base = FlatteningPassBase;
126
127 FlatteningPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
128 FlatteningPassBase(const FlatteningPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
129 FlatteningPassBase& operator=(const FlatteningPassBase &) = delete;
130 FlatteningPassBase(FlatteningPassBase &&) = delete;
131 FlatteningPassBase& operator=(FlatteningPassBase &&) = delete;
132 ~FlatteningPassBase() = default;
133
135 static constexpr ::llvm::StringLiteral getArgumentName() {
136 return ::llvm::StringLiteral("llzk-flatten");
137 }
138 ::llvm::StringRef getArgument() const override { return "llzk-flatten"; }
139
140 ::llvm::StringRef getDescription() const override { return "Flatten structs and unroll loops"; }
141
143 static constexpr ::llvm::StringLiteral getPassName() {
144 return ::llvm::StringLiteral("FlatteningPass");
145 }
146 ::llvm::StringRef getName() const override { return "FlatteningPass"; }
147
149 static bool classof(const ::mlir::Pass *pass) {
150 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
151 }
152
154 std::unique_ptr<::mlir::Pass> clonePass() const override {
155 return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
156 }
157
159 void getDependentDialects(::mlir::DialectRegistry &registry) const override {
160 registry.insert<llzk::LLZKDialect>();
161 registry.insert<llzk::boolean::BoolDialect>();
162 registry.insert<llzk::array::ArrayDialect>();
163 registry.insert<llzk::component::StructDialect>();
164 registry.insert<llzk::constrain::ConstrainDialect>();
165 registry.insert<llzk::felt::FeltDialect>();
166 registry.insert<llzk::global::GlobalDialect>();
167 registry.insert<llzk::include::IncludeDialect>();
168 registry.insert<llzk::function::FunctionDialect>();
169 registry.insert<llzk::string::StringDialect>();
170 registry.insert<llzk::polymorphic::PolymorphicDialect>();
171 registry.insert<mlir::arith::ArithDialect>();
172 registry.insert<mlir::scf::SCFDialect>();
173 }
174
178 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(FlatteningPassBase<DerivedT>)
179
180 FlatteningPassBase(FlatteningPassOptions options) : FlatteningPassBase() {
181 iterationLimit = std::move(options.iterationLimit);
182 cleanupMode = std::move(options.cleanupMode);
183 }
184protected:
185 ::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)};
186 ::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::Unspecified), ::llvm::cl::values(
189 "Use the cleanup mode specified by the calling pipeline (defaults to `preimage` if not specified)."),
192 "No definitions are deleted."),
195 "Only definitions that were replaced with concrete instantiations are deleted."),
198 "All definitions that cannot be reached by a use-def chain from some concrete definition are deleted."),
201 "All definitions that cannot be reached by a use-def chain from the \"Main\" struct are deleted.")
202 )};
203private:
204
205 friend std::unique_ptr<::mlir::Pass> createFlatteningPass() {
206 return std::make_unique<DerivedT>();
207 }
208
209 friend std::unique_ptr<::mlir::Pass> createFlatteningPass(FlatteningPassOptions options) {
210 return std::make_unique<DerivedT>(std::move(options));
211 }
212};
213} // namespace impl
214
215std::unique_ptr<::mlir::Pass> createFlatteningPass() {
216 return impl::createFlatteningPass();
217}
218
219std::unique_ptr<::mlir::Pass> createFlatteningPass(FlatteningPassOptions options) {
220 return impl::createFlatteningPass(std::move(options));
221}
222#undef GEN_PASS_DEF_FLATTENINGPASS
223#endif // GEN_PASS_DEF_FLATTENINGPASS
224
225//===----------------------------------------------------------------------===//
226// TypeVarInferencePass
227//===----------------------------------------------------------------------===//
228#ifdef GEN_PASS_DECL_TYPEVARINFERENCEPASS
229std::unique_ptr<::mlir::Pass> createTypeVarInferencePass();
230#undef GEN_PASS_DECL_TYPEVARINFERENCEPASS
231#endif // GEN_PASS_DECL_TYPEVARINFERENCEPASS
232#ifdef GEN_PASS_DEF_TYPEVARINFERENCEPASS
233
234namespace impl {
235 std::unique_ptr<::mlir::Pass> createTypeVarInferencePass();
236} // namespace impl
237namespace impl {
238
239template <typename DerivedT>
240class TypeVarInferencePassBase : public ::mlir::OperationPass<::mlir::ModuleOp> {
241public:
242 using Base = TypeVarInferencePassBase;
243
244 TypeVarInferencePassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
245 TypeVarInferencePassBase(const TypeVarInferencePassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
246 TypeVarInferencePassBase& operator=(const TypeVarInferencePassBase &) = delete;
247 TypeVarInferencePassBase(TypeVarInferencePassBase &&) = delete;
248 TypeVarInferencePassBase& operator=(TypeVarInferencePassBase &&) = delete;
249 ~TypeVarInferencePassBase() = default;
250
252 static constexpr ::llvm::StringLiteral getArgumentName() {
253 return ::llvm::StringLiteral("llzk-infer-tvar");
254 }
255 ::llvm::StringRef getArgument() const override { return "llzk-infer-tvar"; }
256
257 ::llvm::StringRef getDescription() const override { return "Infer concrete function types for polymorphic type variables"; }
258
260 static constexpr ::llvm::StringLiteral getPassName() {
261 return ::llvm::StringLiteral("TypeVarInferencePass");
262 }
263 ::llvm::StringRef getName() const override { return "TypeVarInferencePass"; }
264
266 static bool classof(const ::mlir::Pass *pass) {
267 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
268 }
269
271 std::unique_ptr<::mlir::Pass> clonePass() const override {
272 return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
273 }
274
276 void getDependentDialects(::mlir::DialectRegistry &registry) const override {
277 registry.insert<llzk::LLZKDialect>();
278 registry.insert<llzk::boolean::BoolDialect>();
279 registry.insert<llzk::array::ArrayDialect>();
280 registry.insert<llzk::component::StructDialect>();
281 registry.insert<llzk::constrain::ConstrainDialect>();
282 registry.insert<llzk::felt::FeltDialect>();
283 registry.insert<llzk::global::GlobalDialect>();
284 registry.insert<llzk::include::IncludeDialect>();
285 registry.insert<llzk::function::FunctionDialect>();
286 registry.insert<llzk::string::StringDialect>();
287 registry.insert<llzk::polymorphic::PolymorphicDialect>();
288 registry.insert<mlir::arith::ArithDialect>();
289 registry.insert<mlir::scf::SCFDialect>();
290 }
291
295 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TypeVarInferencePassBase<DerivedT>)
296
297protected:
298private:
299
300 friend std::unique_ptr<::mlir::Pass> createTypeVarInferencePass() {
301 return std::make_unique<DerivedT>();
302 }
303};
304} // namespace impl
305
306std::unique_ptr<::mlir::Pass> createTypeVarInferencePass() {
307 return impl::createTypeVarInferencePass();
308}
309#undef GEN_PASS_DEF_TYPEVARINFERENCEPASS
310#endif // GEN_PASS_DEF_TYPEVARINFERENCEPASS
311
312//===----------------------------------------------------------------------===//
313// WildcardArraySpecializationPass
314//===----------------------------------------------------------------------===//
315#ifdef GEN_PASS_DECL_WILDCARDARRAYSPECIALIZATIONPASS
316struct WildcardArraySpecializationPassOptions {
317 unsigned iterationLimit = 1000;
318};
319std::unique_ptr<::mlir::Pass> createWildcardArraySpecializationPass();
320std::unique_ptr<::mlir::Pass> createWildcardArraySpecializationPass(WildcardArraySpecializationPassOptions options);
321#undef GEN_PASS_DECL_WILDCARDARRAYSPECIALIZATIONPASS
322#endif // GEN_PASS_DECL_WILDCARDARRAYSPECIALIZATIONPASS
323#ifdef GEN_PASS_DEF_WILDCARDARRAYSPECIALIZATIONPASS
324
325namespace impl {
326 std::unique_ptr<::mlir::Pass> createWildcardArraySpecializationPass();
327} // namespace impl
328
329namespace impl {
330 std::unique_ptr<::mlir::Pass> createWildcardArraySpecializationPass(WildcardArraySpecializationPassOptions options);
331} // namespace impl
332namespace impl {
333
334template <typename DerivedT>
335class WildcardArraySpecializationPassBase : public ::mlir::OperationPass<::mlir::ModuleOp> {
336public:
337 using Base = WildcardArraySpecializationPassBase;
338
339 WildcardArraySpecializationPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
340 WildcardArraySpecializationPassBase(const WildcardArraySpecializationPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
341 WildcardArraySpecializationPassBase& operator=(const WildcardArraySpecializationPassBase &) = delete;
342 WildcardArraySpecializationPassBase(WildcardArraySpecializationPassBase &&) = delete;
343 WildcardArraySpecializationPassBase& operator=(WildcardArraySpecializationPassBase &&) = delete;
344 ~WildcardArraySpecializationPassBase() = default;
345
347 static constexpr ::llvm::StringLiteral getArgumentName() {
348 return ::llvm::StringLiteral("llzk-specialize-wildcard-arrays");
349 }
350 ::llvm::StringRef getArgument() const override { return "llzk-specialize-wildcard-arrays"; }
351
352 ::llvm::StringRef getDescription() const override { return "Refine wildcard array casts and specialize concrete call targets"; }
353
355 static constexpr ::llvm::StringLiteral getPassName() {
356 return ::llvm::StringLiteral("WildcardArraySpecializationPass");
357 }
358 ::llvm::StringRef getName() const override { return "WildcardArraySpecializationPass"; }
359
361 static bool classof(const ::mlir::Pass *pass) {
362 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
363 }
364
366 std::unique_ptr<::mlir::Pass> clonePass() const override {
367 return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
368 }
369
371 void getDependentDialects(::mlir::DialectRegistry &registry) const override {
372 registry.insert<llzk::LLZKDialect>();
373 registry.insert<llzk::boolean::BoolDialect>();
374 registry.insert<llzk::array::ArrayDialect>();
375 registry.insert<llzk::component::StructDialect>();
376 registry.insert<llzk::constrain::ConstrainDialect>();
377 registry.insert<llzk::felt::FeltDialect>();
378 registry.insert<llzk::global::GlobalDialect>();
379 registry.insert<llzk::include::IncludeDialect>();
380 registry.insert<llzk::function::FunctionDialect>();
381 registry.insert<llzk::string::StringDialect>();
382 registry.insert<llzk::polymorphic::PolymorphicDialect>();
383 registry.insert<mlir::arith::ArithDialect>();
384 registry.insert<mlir::scf::SCFDialect>();
385 }
386
390 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(WildcardArraySpecializationPassBase<DerivedT>)
391
392 WildcardArraySpecializationPassBase(WildcardArraySpecializationPassOptions options) : WildcardArraySpecializationPassBase() {
393 iterationLimit = std::move(options.iterationLimit);
394 }
395protected:
396 ::mlir::Pass::Option<unsigned> iterationLimit{*this, "max-iter", ::llvm::cl::desc("Maximum number of iterations before the pass gives up reaching a fixpoint."), ::llvm::cl::init(1000)};
397private:
398
399 friend std::unique_ptr<::mlir::Pass> createWildcardArraySpecializationPass() {
400 return std::make_unique<DerivedT>();
401 }
402
403 friend std::unique_ptr<::mlir::Pass> createWildcardArraySpecializationPass(WildcardArraySpecializationPassOptions options) {
404 return std::make_unique<DerivedT>(std::move(options));
405 }
406};
407} // namespace impl
408
409std::unique_ptr<::mlir::Pass> createWildcardArraySpecializationPass() {
410 return impl::createWildcardArraySpecializationPass();
411}
412
413std::unique_ptr<::mlir::Pass> createWildcardArraySpecializationPass(WildcardArraySpecializationPassOptions options) {
414 return impl::createWildcardArraySpecializationPass(std::move(options));
415}
416#undef GEN_PASS_DEF_WILDCARDARRAYSPECIALIZATIONPASS
417#endif // GEN_PASS_DEF_WILDCARDARRAYSPECIALIZATIONPASS
418#ifdef GEN_PASS_REGISTRATION
419
420//===----------------------------------------------------------------------===//
421// EmptyTemplateRemovalPass Registration
422//===----------------------------------------------------------------------===//
423
425 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
427 });
428}
429
430// Old registration code, kept for temporary backwards compatibility.
432 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
434 });
435}
436
437//===----------------------------------------------------------------------===//
438// FlatteningPass Registration
439//===----------------------------------------------------------------------===//
440
441inline void registerFlatteningPass() {
442 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
443 return createFlatteningPass();
444 });
445}
446
447// Old registration code, kept for temporary backwards compatibility.
448inline void registerFlatteningPassPass() {
449 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
450 return createFlatteningPass();
451 });
452}
453
454//===----------------------------------------------------------------------===//
455// TypeVarInferencePass Registration
456//===----------------------------------------------------------------------===//
457
458inline void registerTypeVarInferencePass() {
459 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
461 });
462}
463
464// Old registration code, kept for temporary backwards compatibility.
466 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
468 });
469}
470
471//===----------------------------------------------------------------------===//
472// WildcardArraySpecializationPass Registration
473//===----------------------------------------------------------------------===//
474
476 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
478 });
479}
480
481// Old registration code, kept for temporary backwards compatibility.
483 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
485 });
486}
487
488//===----------------------------------------------------------------------===//
489// Transformation Registration
490//===----------------------------------------------------------------------===//
491
492inline void registerTransformationPasses() {
497}
498#undef GEN_PASS_REGISTRATION
499#endif // GEN_PASS_REGISTRATION
500// Deprecated. Please use the new per-pass macros.
501#ifdef GEN_PASS_CLASSES
502
503template <typename DerivedT>
504class EmptyTemplateRemovalPassBase : public ::mlir::OperationPass<::mlir::ModuleOp> {
505public:
506 using Base = EmptyTemplateRemovalPassBase;
507
508 EmptyTemplateRemovalPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
509 EmptyTemplateRemovalPassBase(const EmptyTemplateRemovalPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
510 EmptyTemplateRemovalPassBase& operator=(const EmptyTemplateRemovalPassBase &) = delete;
511 EmptyTemplateRemovalPassBase(EmptyTemplateRemovalPassBase &&) = delete;
512 EmptyTemplateRemovalPassBase& operator=(EmptyTemplateRemovalPassBase &&) = delete;
513 ~EmptyTemplateRemovalPassBase() = default;
514
516 static constexpr ::llvm::StringLiteral getArgumentName() {
517 return ::llvm::StringLiteral("llzk-drop-empty-templates");
518 }
519 ::llvm::StringRef getArgument() const override { return "llzk-drop-empty-templates"; }
520
521 ::llvm::StringRef getDescription() const override { return "Remove empty templates"; }
522
524 static constexpr ::llvm::StringLiteral getPassName() {
525 return ::llvm::StringLiteral("EmptyTemplateRemovalPass");
526 }
527 ::llvm::StringRef getName() const override { return "EmptyTemplateRemovalPass"; }
528
530 static bool classof(const ::mlir::Pass *pass) {
531 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
532 }
533
535 std::unique_ptr<::mlir::Pass> clonePass() const override {
536 return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
537 }
538
540 void getDependentDialects(::mlir::DialectRegistry &registry) const override {
541 registry.insert<llzk::LLZKDialect>();
542 registry.insert<llzk::boolean::BoolDialect>();
543 registry.insert<llzk::array::ArrayDialect>();
544 registry.insert<llzk::component::StructDialect>();
545 registry.insert<llzk::constrain::ConstrainDialect>();
546 registry.insert<llzk::felt::FeltDialect>();
547 registry.insert<llzk::global::GlobalDialect>();
548 registry.insert<llzk::include::IncludeDialect>();
549 registry.insert<llzk::function::FunctionDialect>();
550 registry.insert<llzk::string::StringDialect>();
551 registry.insert<llzk::polymorphic::PolymorphicDialect>();
552 registry.insert<mlir::arith::ArithDialect>();
553 registry.insert<mlir::scf::SCFDialect>();
554 }
555
559 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(EmptyTemplateRemovalPassBase<DerivedT>)
560
561protected:
562};
563
564template <typename DerivedT>
565class FlatteningPassBase : public ::mlir::OperationPass<::mlir::ModuleOp> {
566public:
567 using Base = FlatteningPassBase;
568
569 FlatteningPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
570 FlatteningPassBase(const FlatteningPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
571 FlatteningPassBase& operator=(const FlatteningPassBase &) = delete;
572 FlatteningPassBase(FlatteningPassBase &&) = delete;
573 FlatteningPassBase& operator=(FlatteningPassBase &&) = delete;
574 ~FlatteningPassBase() = default;
575
577 static constexpr ::llvm::StringLiteral getArgumentName() {
578 return ::llvm::StringLiteral("llzk-flatten");
579 }
580 ::llvm::StringRef getArgument() const override { return "llzk-flatten"; }
581
582 ::llvm::StringRef getDescription() const override { return "Flatten structs and unroll loops"; }
583
585 static constexpr ::llvm::StringLiteral getPassName() {
586 return ::llvm::StringLiteral("FlatteningPass");
587 }
588 ::llvm::StringRef getName() const override { return "FlatteningPass"; }
589
591 static bool classof(const ::mlir::Pass *pass) {
592 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
593 }
594
596 std::unique_ptr<::mlir::Pass> clonePass() const override {
597 return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
598 }
599
601 void getDependentDialects(::mlir::DialectRegistry &registry) const override {
602 registry.insert<llzk::LLZKDialect>();
603 registry.insert<llzk::boolean::BoolDialect>();
604 registry.insert<llzk::array::ArrayDialect>();
605 registry.insert<llzk::component::StructDialect>();
606 registry.insert<llzk::constrain::ConstrainDialect>();
607 registry.insert<llzk::felt::FeltDialect>();
608 registry.insert<llzk::global::GlobalDialect>();
609 registry.insert<llzk::include::IncludeDialect>();
610 registry.insert<llzk::function::FunctionDialect>();
611 registry.insert<llzk::string::StringDialect>();
612 registry.insert<llzk::polymorphic::PolymorphicDialect>();
613 registry.insert<mlir::arith::ArithDialect>();
614 registry.insert<mlir::scf::SCFDialect>();
615 }
616
620 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(FlatteningPassBase<DerivedT>)
621
622protected:
623 ::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)};
624 ::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::Unspecified), ::llvm::cl::values(
627 "Use the cleanup mode specified by the calling pipeline (defaults to `preimage` if not specified)."),
630 "No definitions are deleted."),
633 "Only definitions that were replaced with concrete instantiations are deleted."),
636 "All definitions that cannot be reached by a use-def chain from some concrete definition are deleted."),
639 "All definitions that cannot be reached by a use-def chain from the \"Main\" struct are deleted.")
640 )};
641};
642
643template <typename DerivedT>
644class TypeVarInferencePassBase : public ::mlir::OperationPass<::mlir::ModuleOp> {
645public:
646 using Base = TypeVarInferencePassBase;
647
648 TypeVarInferencePassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
649 TypeVarInferencePassBase(const TypeVarInferencePassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
650 TypeVarInferencePassBase& operator=(const TypeVarInferencePassBase &) = delete;
651 TypeVarInferencePassBase(TypeVarInferencePassBase &&) = delete;
652 TypeVarInferencePassBase& operator=(TypeVarInferencePassBase &&) = delete;
653 ~TypeVarInferencePassBase() = default;
654
656 static constexpr ::llvm::StringLiteral getArgumentName() {
657 return ::llvm::StringLiteral("llzk-infer-tvar");
658 }
659 ::llvm::StringRef getArgument() const override { return "llzk-infer-tvar"; }
660
661 ::llvm::StringRef getDescription() const override { return "Infer concrete function types for polymorphic type variables"; }
662
664 static constexpr ::llvm::StringLiteral getPassName() {
665 return ::llvm::StringLiteral("TypeVarInferencePass");
666 }
667 ::llvm::StringRef getName() const override { return "TypeVarInferencePass"; }
668
670 static bool classof(const ::mlir::Pass *pass) {
671 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
672 }
673
675 std::unique_ptr<::mlir::Pass> clonePass() const override {
676 return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
677 }
678
680 void getDependentDialects(::mlir::DialectRegistry &registry) const override {
681 registry.insert<llzk::LLZKDialect>();
682 registry.insert<llzk::boolean::BoolDialect>();
683 registry.insert<llzk::array::ArrayDialect>();
684 registry.insert<llzk::component::StructDialect>();
685 registry.insert<llzk::constrain::ConstrainDialect>();
686 registry.insert<llzk::felt::FeltDialect>();
687 registry.insert<llzk::global::GlobalDialect>();
688 registry.insert<llzk::include::IncludeDialect>();
689 registry.insert<llzk::function::FunctionDialect>();
690 registry.insert<llzk::string::StringDialect>();
691 registry.insert<llzk::polymorphic::PolymorphicDialect>();
692 registry.insert<mlir::arith::ArithDialect>();
693 registry.insert<mlir::scf::SCFDialect>();
694 }
695
699 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TypeVarInferencePassBase<DerivedT>)
700
701protected:
702};
703
704template <typename DerivedT>
705class WildcardArraySpecializationPassBase : public ::mlir::OperationPass<::mlir::ModuleOp> {
706public:
707 using Base = WildcardArraySpecializationPassBase;
708
709 WildcardArraySpecializationPassBase() : ::mlir::OperationPass<::mlir::ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
710 WildcardArraySpecializationPassBase(const WildcardArraySpecializationPassBase &other) : ::mlir::OperationPass<::mlir::ModuleOp>(other) {}
711 WildcardArraySpecializationPassBase& operator=(const WildcardArraySpecializationPassBase &) = delete;
712 WildcardArraySpecializationPassBase(WildcardArraySpecializationPassBase &&) = delete;
713 WildcardArraySpecializationPassBase& operator=(WildcardArraySpecializationPassBase &&) = delete;
714 ~WildcardArraySpecializationPassBase() = default;
715
717 static constexpr ::llvm::StringLiteral getArgumentName() {
718 return ::llvm::StringLiteral("llzk-specialize-wildcard-arrays");
719 }
720 ::llvm::StringRef getArgument() const override { return "llzk-specialize-wildcard-arrays"; }
721
722 ::llvm::StringRef getDescription() const override { return "Refine wildcard array casts and specialize concrete call targets"; }
723
725 static constexpr ::llvm::StringLiteral getPassName() {
726 return ::llvm::StringLiteral("WildcardArraySpecializationPass");
727 }
728 ::llvm::StringRef getName() const override { return "WildcardArraySpecializationPass"; }
729
731 static bool classof(const ::mlir::Pass *pass) {
732 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
733 }
734
736 std::unique_ptr<::mlir::Pass> clonePass() const override {
737 return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
738 }
739
741 void getDependentDialects(::mlir::DialectRegistry &registry) const override {
742 registry.insert<llzk::LLZKDialect>();
743 registry.insert<llzk::boolean::BoolDialect>();
744 registry.insert<llzk::array::ArrayDialect>();
745 registry.insert<llzk::component::StructDialect>();
746 registry.insert<llzk::constrain::ConstrainDialect>();
747 registry.insert<llzk::felt::FeltDialect>();
748 registry.insert<llzk::global::GlobalDialect>();
749 registry.insert<llzk::include::IncludeDialect>();
750 registry.insert<llzk::function::FunctionDialect>();
751 registry.insert<llzk::string::StringDialect>();
752 registry.insert<llzk::polymorphic::PolymorphicDialect>();
753 registry.insert<mlir::arith::ArithDialect>();
754 registry.insert<mlir::scf::SCFDialect>();
755 }
756
760 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(WildcardArraySpecializationPassBase<DerivedT>)
761
762protected:
763 ::mlir::Pass::Option<unsigned> iterationLimit{*this, "max-iter", ::llvm::cl::desc("Maximum number of iterations before the pass gives up reaching a fixpoint."), ::llvm::cl::init(1000)};
764};
765#undef GEN_PASS_CLASSES
766#endif // GEN_PASS_CLASSES
void registerTransformationPasses()
std::unique_ptr<::mlir::Pass > createEmptyTemplateRemovalPass()
std::unique_ptr<::mlir::Pass > createFlatteningPass()
std::unique_ptr<::mlir::Pass > createWildcardArraySpecializationPass()
std::unique_ptr<::mlir::Pass > createTypeVarInferencePass()
::llvm::StringRef stringifyFlatteningCleanupMode(FlatteningCleanupMode val)
void registerWildcardArraySpecializationPass()
void registerEmptyTemplateRemovalPassPass()
void registerWildcardArraySpecializationPassPass()