This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Fix dialect conversion cancelRootUpdate
ClosedPublic

Authored by bondhugula on Jul 3 2021, 9:14 AM.

Details

Summary

Fix dialect conversion ConversionPatternRewriter::cancelRootUpdate: the
erasure of operations here from the list of root update was off by one.
Should have been:

rootUpdates.erase(rootUpdates.begin() + (rootUpdates.rend() - it - 1));

instead of

rootUpdates.erase(rootUpdates.begin() + (rootUpdates.rend() - it));

or more directly:

rootUpdates.erase(it.base() -1)

While on this, add an assertion to improve dev experience when a cancel is
called on an op on which a root update hasn't been started.

Diff Detail

Event Timeline

bondhugula created this revision.Jul 3 2021, 9:14 AM
bondhugula requested review of this revision.Jul 3 2021, 9:14 AM
bondhugula updated this revision to Diff 356346.Jul 3 2021, 9:15 AM
bondhugula edited the summary of this revision. (Show Details)

Update commit summary a bit.

Fix iterator and commit message.

bondhugula edited the summary of this revision. (Show Details)Jul 3 2021, 10:36 AM
mehdi_amini added inline comments.Jul 5 2021, 2:10 PM
mlir/lib/Transforms/Utils/DialectConversion.cpp
1488

This formula is confusing me. And std::prev(rootUpdates.rend()) even more so. How is it different from begin()?

mehdi_amini accepted this revision.Jul 5 2021, 2:14 PM
mehdi_amini added inline comments.
mlir/lib/Transforms/Utils/DialectConversion.cpp
1488

Re-reading, it will be a reverse iterator, and you're trying to get its position here.
Maybe name a variable for this? int updateIdx = std::prev(rootUpdates.rend()) - it;

2053

Can you write const Pattern * instead of auto?

This revision is now accepted and ready to land.Jul 5 2021, 2:14 PM

NFC. Putting position in a var.

bondhugula marked 2 inline comments as done.Jul 5 2021, 10:25 PM
bondhugula added inline comments.
mlir/lib/Transforms/Utils/DialectConversion.cpp
1488

Not sure how naming a variable here helps but I've done it. (Anything coming after begin() + will always be read as a position).

bondhugula marked 2 inline comments as done.Jul 5 2021, 10:29 PM
bondhugula added inline comments.
mlir/lib/Transforms/Utils/DialectConversion.cpp
2053

This won't be const Pattern *, but a const Pattern *const *. It's an iterator. I fixed this one since my in-editor checker (YCM) complains due to the clang-tidy check. This is annoying as it would mask other more non-borderline style errors. We can leave it at auto *it.

This revision was automatically updated to reflect the committed changes.
bondhugula marked an inline comment as done.