cornell-zhang / hcl-dialect

HeteroCL-MLIR dialect for accelerator design
https://cornell-zhang.github.io/heterocl/index.html
Other
38 stars 17 forks source link

[Op][Binding] Support while loops #20

Closed chhzh123 closed 2 years ago

chhzh123 commented 2 years ago

See the specification of scf.while. The first region calculates the while condition, and the second region is the loop body.

The implementation is similar to make_if, which requires moving the condition inside the region. Since A[i] < 10 in Python is evaluated first before calling the function hcl.while_, it may be built outside the region. Thus, the correct way is to remove the original A[i] < 10 and rebuild a new one inside the region.

with hcl.while_(A[i] < 10):
    # ...