[Mlir-commits] [mlir] [mlir][polynomial] use typed attributes for polynomial.constant op (PR #92818)

Jeremy Kun llvmlistbot at llvm.org
Mon May 20 22:35:28 PDT 2024


================
@@ -286,10 +286,10 @@ def Polynomial_ConstantOp : Op<Polynomial_Dialect, "constant", [Pure]> {
     ```mlir
     #poly = #polynomial.int_polynomial<x**1024 - 1>
     #ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536:i32, polynomialModulus=#poly>
-    %0 = polynomial.constant #polynomial.int_polynomial<1 + x**2> : !polynomial.polynomial<#ring>
+    %0 = polynomial.constant {value=#polynomial.int_polynomial<1 + x**2>} : !polynomial.polynomial<#ring>
----------------
j2kun wrote:

I worked on this for an hour or two and got it working, but not quite perfect.

In the last commit, the syntax is now

```mlir
%0 = polynomial.constant #polynomial.typed_int_polynomial<1 + x**2> : !polynomial.polynomial<ring=...>
```

I tried to get rid of the `#polynomial.typed_int_polynomial` to make it just

```mlir
%0 = polynomial.constant <1 + x**2> : !polynomial.polynomial<ring=...>
```

But I wasn't able to make it work. The parser infrastructure seems to make it infeasible to parse a dialect-defined attribute without the leading `#dialect_namespace.attribute` part, and when I tired to work around it in https://github.com/llvm/llvm-project/pull/92818/commits/ef17f2af7f75bd2c98c05720eb8d3f77d652ef43, I wasn't able to make it first try to parse the int polynomial, then fall back to parsing the float version on failure. It worked for the int polynomial, but failed for float_polynomial. It seemed like the parser was consuming the initial `<` token when trying to parse the int_polynomial, and then was not able to find the `<` when trying to parse the float_polynomial. I don't see a way to save and restore parser state to work around this...

If you have any alternative ideas, I'm all ears.

https://github.com/llvm/llvm-project/pull/92818


More information about the Mlir-commits mailing list