This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Refactoring dialect and test code to use parseCommaSeparatedList
ClosedPublic

Authored by jakubtuchol on May 2 2022, 11:18 AM.

Diff Detail

Event Timeline

jakubtuchol created this revision.May 2 2022, 11:18 AM
jakubtuchol requested review of this revision.May 2 2022, 11:18 AM
lattner added inline comments.May 2 2022, 11:30 AM
mlir/include/mlir/IR/OpImplementation.h
934

I'd recommend passing the lambda inline instead of naming it. I also learned a trick where "emplace_back" will add a new empty entry to a vector and return a reference to it. This should allow you to turn this into:

return parseCommaSeparatedList([&]() {
  return parseType(result.emplace_back());
});
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
3485–3487

These parser hooks support chaining with ||, plz give this a try:

if (parser.parseCommaSeparatedList(parseOperands)) ||
    parser.parseRParen())
  return failure();
mlir/lib/Dialect/DLTI/DLTI.cpp
291

Please use the same things above - you can move this inline, and use the emplace_back inline.

jakubtuchol marked 3 inline comments as done.

Addressing lattner's review

lattner accepted this revision.May 2 2022, 4:40 PM

Nice, thank you! A couple more suggestions above.

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
555–556

You can simplify this one to "return parser.parseOperand(...);"

3074

I /think/ you can use "return parser.emitError(...)" because the result converts to failure already.

3080

here and below too (if I'm right)

This revision is now accepted and ready to land.May 2 2022, 4:40 PM
rriddle accepted this revision.May 2 2022, 4:48 PM

LG, much nicer! Thanks for tackling this.

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
2881–2885

Can you move the lambda out of line here? It's kind of difficult to read here.

3067–3069

Same here.

mlir/lib/Dialect/PDL/IR/PDL.cpp
159–161

Same here.

mlir/lib/Dialect/PDLInterp/IR/PDLInterp.cpp
82–84

Same here.

jakubtuchol marked 4 inline comments as done.

Addressing lattner's rriddle's review

Fixing clang-fmt issues

nice, congrats on your first patch!