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

[Binding] CastOp doesn't work for indices #28

Closed chhzh123 closed 2 years ago

chhzh123 commented 2 years ago

The following imperative program

with hcl.for_(0, 10) as i:
    A[i] = i

will generate the MLIR code as follows.

module {
  func @top(%arg0: memref<10xi32>) attributes {extra_itypes = "s", extra_otypes = ""} {
    %0 = hcl.create_loop_handle "loop_0" : !hcl.LoopHandle
    affine.for %arg1 = 0 to 10 {
      %1 = builtin.unrealized_conversion_cast %arg1 : index to i32
      %2 = builtin.unrealized_conversion_cast %arg1 : index to index
      affine.store %1, %arg0[%arg1] {to = "compute_0"} : memref<10xi32>
    } {loop_name = "loop_0"}
    return
  }
}

Two unrealized_conversion_cast are generated but they should not be there, since i32 and index are builtin types that are supported by builtin cast operations.

chhzh123 commented 2 years ago

This is because the input data type of IterVar uses string to represent. See this line. Thus, get_mlir_type should be called at first in CastOp.