This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Fix `Region`s `takeBody` method if the region is not empty
ClosedPublic

Authored by zero9178 on Apr 17 2022, 8:41 AM.

Details

Summary

The current implementation of takeBody first clears the Region, before then taking ownership of the blocks of the other regions. The issue here however, is that when clearing the region, it does not take into account references of operations to each other. In particular, blocks are deleted from front to back, and operations within a block are very likely to be deleted despite still having uses, causing an assertion to trigger [0].

This patch fixes that issue by simply calling dropAllReferences()before clearing the blocks.

[0] https://github.com/llvm/llvm-project/blob/9a8bb4bc635de9d56706262083c15eb1e0cf3e87/mlir/lib/IR/Operation.cpp#L154

Diff Detail

Event Timeline

zero9178 created this revision.Apr 17 2022, 8:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 17 2022, 8:41 AM
zero9178 requested review of this revision.Apr 17 2022, 8:41 AM
rriddle accepted this revision.Apr 17 2022, 11:17 AM
rriddle added inline comments.
mlir/test/lib/IR/TestTakeBody.cpp
1 ↗(On Diff #423297)

Can this file be more generally for Region related tests? Otherwise, we'll have a huge number of test files potentially.

42 ↗(On Diff #423297)

This should probably have Region in the name. If this file is for Region tests in general, this could just be registerRegionTestPasses().

This revision is now accepted and ready to land.Apr 17 2022, 11:17 AM
zero9178 updated this revision to Diff 424177.Apr 21 2022, 6:32 AM
zero9178 marked 2 inline comments as done.

Address review comments

This revision was landed with ongoing or failed builds.Apr 21 2022, 6:33 AM
This revision was automatically updated to reflect the committed changes.