This is an archive of the discontinued LLVM Phabricator instance.

[mlir][flang] Do not prevent integer types from being parsed as MLIR keywords
ClosedPublic

Authored by jeanPerier on Aug 30 2021, 5:34 AM.

Details

Summary

DialectAsmParser::parseKeyword is rejecting 'i' digit+ while it is
a valid identifier according to mlir/docs/LangRef.md.

Integer types actually used to be TOK_KEYWORD a while back before the
change: https://github.com/llvm/llvm-project/commit/6af866c58d21813fb243906611d02bb2a8ffa43a.

This patch Modifies isCurrentTokenAKeyword to return true for tokens that
match integer types too.

The motivation for this change is the parsing of !fir.type<{ component-name: component-type,+ }>
type in FIR that represent Fortran derived types. The component-names are
parsed as keywords, and can very well be i32 or any ixxx (which are
valid Fortran derived type component names).

I am not sure where to add a pure MLIR test for this change, so I added
one in FIR, although the functional change is in MLIR parser.

Diff Detail

Event Timeline

jeanPerier created this revision.Aug 30 2021, 5:34 AM
jeanPerier requested review of this revision.Aug 30 2021, 5:34 AM

Could we have a MLIR test for this?

My patch actually breaks a bunch of Quant and Tosa regression tests because quant.uniform parser is assuming that integer types cannot be parsed as keywords here: https://github.com/llvm/llvm-project/blob/6bc767cd071ccdb41b5532f7d9cae22999e0fac4/mlir/lib/Dialect/Quant/IR/TypeParser.cpp#L32

So now I am wondering if I am following a wrong approach or if the quant parsing should be modified. Any opinions ?

Could we have a MLIR test for this?

How best would you suggest testing parseKeyword behavior with pure a MLIR test ?

When I grepped for negative keyword parsing tests ("expected valid keyword" error), I could only find tests with Linalg and SPIRV, so I am not sure how to come with a pure MLIR test that would show that ixxx are accepted as keywords.

When I grepped for negative keyword parsing tests ("expected valid keyword" error), I could only find tests with Linalg and SPIRV, so I am not sure how to come with a pure MLIR test that would show that ixxx are accepted as keywords.

Create an op/type in the test dialect that uses keywords in its custom syntax and try parsing it.

Add test with MLIR test dialect and change Quant dialect type parser
according to parseKeyword behaviour change (Fixes regressions).

When I grepped for negative keyword parsing tests ("expected valid keyword" error), I could only find tests with Linalg and SPIRV, so I am not sure how to come with a pure MLIR test that would show that ixxx are accepted as keywords.

Create an op/type in the test dialect that uses keywords in its custom syntax and try parsing it.

Thanks for the direction @ftynse , I have added a test with the MLIR test dialect struct type.

rriddle accepted this revision.Sep 2 2021, 3:15 PM
This revision is now accepted and ready to land.Sep 2 2021, 3:15 PM