LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
LLZKWhileToForPass.cpp File Reference

This file identifies scf.while loops that can be converted to scf.for loops and performs the conversion. More...

Include dependency graph for LLZKWhileToForPass.cpp:

Go to the source code of this file.

Classes

class  llzk::impl::WhileToForPassBase< DerivedT >

Namespaces

namespace  llzk
namespace  llzk::impl

Macros

#define GEN_PASS_DEF_WHILETOFORPASS
#define DEBUG_TYPE   "while-to-for"

Functions

std::unique_ptr<::mlir::Pass > llzk::impl::createWhileToForPass ()
std::unique_ptr<::mlir::Pass > llzk::createWhileToForPass ()

Detailed Description

This file identifies scf.while loops that can be converted to scf.for loops and performs the conversion.

A while loop can be converted if:

  • The scf.condition directly forwards before block arguments to the after block
  • The before block has an argument arg (the "induction variable") such that:
    • The scf.condition condition has the form bool.cmp lt(arg, upper_bound)
    • The value yielded from the after block has the form felt.add arg, step
  • upper_bound and step do not depend on any loop-carried variables
  • The final yielded value of the induction variable does not have uses outside the loop

This pass begins by identifying the induction variable, lower and upper bounds, and step (ForOp::parseInfo), then materializes a for loop with these parameters and copies the before and after blocks into the body, drops the yielded induction variable, and remaps uses of the other yielded values (transformWhileToFor).

Definition in file LLZKWhileToForPass.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "while-to-for"

Definition at line 42 of file LLZKWhileToForPass.cpp.

◆ GEN_PASS_DEF_WHILETOFORPASS

#define GEN_PASS_DEF_WHILETOFORPASS

Definition at line 38 of file LLZKWhileToForPass.cpp.