This is an archive of the discontinued LLVM Phabricator instance.

[OpAsmParser] Add a parseCommaSeparatedList helper and beef up Delimeter.
ClosedPublic

Authored by lattner on Sep 20 2021, 6:27 PM.

Details

Summary

Lots of custom ops have hand-rolled comma-delimited parsing loops, as does
the MLIR parser itself. Provides a standard interface for doing this that
is less error prone and less boilerplate.

While here, extend Delimiter to support <> and {} delimited sequences as
well (I have a use for <> in CIRCT specifically).

Diff Detail

Event Timeline

lattner created this revision.Sep 20 2021, 6:27 PM
lattner requested review of this revision.Sep 20 2021, 6:27 PM

Note that I updated a bunch of random examples in the tree but there are many more that could adopt this as well.

lattner added inline comments.Sep 20 2021, 6:30 PM
mlir/lib/Parser/TypeParser.cpp
564

AFAICT, this was an outright bug that would lead to rejecting malformed input without emitting a diagnostic.

rriddle accepted this revision.Sep 20 2021, 6:36 PM

Looks much cleaner, thanks!

mlir/lib/Parser/Parser.cpp
1361

Why the move here?

mlir/lib/Parser/TypeParser.cpp
172–173

Now that parseStrideList actually emits errors in all cases, we should drop this error.

564

It looks like line73 also emits an error, which I guess covers this but can also result in a double error. We should remove the error on that line.

This revision is now accepted and ready to land.Sep 20 2021, 6:36 PM
lattner updated this revision to Diff 373771.Sep 20 2021, 8:42 PM
lattner marked an inline comment as done.

Improvements pointed out by River

mlir/lib/Parser/Parser.cpp
1361

Great catch, I was using std::function, but moved to function_ref later. function_ref doesn't need this. Removed from the patch, thanks!

mlir/lib/Parser/TypeParser.cpp
564

Aha, cool I cleaned this up, good catch.

lattner updated this revision to Diff 373773.Sep 20 2021, 8:59 PM

Remove one more unnecessary move.

This revision was landed with ongoing or failed builds.Sep 20 2021, 8:59 PM
This revision was automatically updated to reflect the committed changes.

Thank you for the speedy reviews!