cornell-zhang / hcl-dialect

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

[Op] Support of multiple if conditions #76

Closed chhzh123 closed 2 years ago

chhzh123 commented 2 years ago

We need to support the following imperative program with multiple conditions in a if statement, which is also useful to support general SelectOp.

with hcl.if_(hcl.all(i > j, j >= i + 1)): # affine.if
    A[i, j] += 1
chhzh123 commented 2 years ago

To capture the high-level information, we can do the following steps:

  1. Create an hcl.logical_and op that can take in variadic arguments, each of which is a condition expression.
  2. Create a Python binding interface LogicalAndOp.
  3. Map the frontend hcl.all op to hcl_mlir.LogicalAndOp.
  4. In build_ir.py/make_if we allow the input of expression to be an LogicalAndOp, and take each of its arguments to individually traverse the expression tree and construct the affine expressions.

In this way, hcl.logical_and is actually not built as an IR node, but is directly lowered when building the MLIR code.