This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Don't insert YieldOp for non-void loop.for by default.
AbandonedPublic

Authored by pifon2a on Apr 3 2020, 6:26 AM.

Details

Summary

The ForOp::build ensures that there is a block terminator which is great for
the default use case when there are no iter_args and loop.for returns no
results. In non-zero results case we always need to call replaceOpWithNewOp
which is not the nicest thing in the world. We can stop inserting YieldOp when
iter_args is non-empty. IfOp::build already behaves similarly.

Diff Detail

Event Timeline

pifon2a created this revision.Apr 3 2020, 6:26 AM
pifon2a updated this revision to Diff 254777.Apr 3 2020, 6:29 AM

Reformat.

pifon2a edited reviewers, added: ftynse, herhut; removed: nicolasvasilache.Apr 3 2020, 6:30 AM
ftynse added inline comments.Apr 3 2020, 7:05 AM
mlir/lib/Dialect/LoopOps/LoopOps.cpp
51

This looks like the constructed op will be invalid by construction if iterArgs is non-empty, due to the missing terminator. It may be fine as long as it is clear from the documentation that the caller is supposed to fix that. Alternatively, you can still create a terminator that returns iterArgs, which would give you a valid region, but will probably defy the purpose of this patch.

bondhugula requested changes to this revision.Apr 3 2020, 7:19 AM
bondhugula added a subscriber: bondhugula.

Commit summary please - even if it's a couple of lines. It's not clear from the title why the 'for' block won't be missing a terminator.

This revision now requires changes to proceed.Apr 3 2020, 7:19 AM
pifon2a updated this revision to Diff 254828.Apr 3 2020, 8:45 AM

Improved commit description

pifon2a edited the summary of this revision. (Show Details)Apr 3 2020, 8:46 AM
pifon2a updated this revision to Diff 254831.Apr 3 2020, 8:58 AM

Updated docs in .td.

pifon2a marked 2 inline comments as done.Apr 3 2020, 9:03 AM

Commit summary please - even if it's a couple of lines. It's not clear from the title why the 'for' block won't be missing a terminator.

@bondhugula Updated the summary. Thanks!

mlir/lib/Dialect/LoopOps/LoopOps.cpp
51

I updated the documentation in LoopOps.td. The option with removing 'ensureTermitor' even for the default case without results did not work quite well, since it breaks many users and adds boilerplate code to insert YieldOp, since mostly, ForOp is used without `iter_args' and I think it makes sense to leave this use case with implicit insertion of terminator.

ftynse accepted this revision.Apr 3 2020, 9:10 AM

I've been told we have the same for IfOp, so this behavior is at least consistent within the dialect.

Harbormaster completed remote builds in B51655: Diff 254831.
pifon2a updated this revision to Diff 255130.Apr 5 2020, 2:49 AM
pifon2a marked an inline comment as done.

Formatting.

pifon2a abandoned this revision.Apr 5 2020, 2:59 AM