Skip to content

[MLIR][IRDL] Support for concrete attribute values in IRDL #85546

Open
@mikeurbach

Description

@mikeurbach

I am trying to use IRDL to define an op like a constant op that takes some attribute and returns some result, like a constant op in many dialects. I've followed the example IRDL in the tests, and have something this:

module {                                                                                                                                                                                                                                             
  irdl.dialect @cmath {                                                                                                                                                                                                                              
    irdl.type @complex                                                                                                                                                                                                                               
    irdl.operation @const {                                                                                                                                                                                                                          
      %0 = irdl.parametric @complex<>                                                                                                                                                                                                                
      %1 = irdl.is i64                                                                                                                                                                                                                               
      irdl.attributes {"value" = %1}                                                                                                                                                                                                                 
      irdl.operands()                                                                                                                                                                                                                                
      irdl.results(%0)                                                                                                                                                                                                                               
    }                                                                                                                                                                                                                                                
}

I am trying to build a cmath.const op, passing a concrete attribute for the value:

%0 = "cmath.const"() {value = 1 : i64} : () -> !cmath.complex

This fails to verify with:

error: expected 'i64' but got '1 : i64'

The tests here seem to reflect this as well, in the examples, only a TypeAttr is passed, not an IntegerAttr of the corresponding type:

"testd.attrs"() {attr1 = i32, attr2 = i64} : () -> ()

I want my op to express that it requires a TypedAttribute of some type, like i64, not that the attribute is a TypeAttr of type i64. Is this possible? In other words, I want to be able to pass concrete attribute values and have the types of those attributes checked against the IRDL op definition.

I reviewed the discussion on the original patch, and it seems like this was what was originally implemented but then this was changed. Is there any plan to support this? Or am I using the existing tooling wrong?

cc @math-fehr @unterumarmung

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions