This is an archive of the discontinued LLVM Phabricator instance.

[mlir][IR] Add ForwardDominanceIterator for IR walkers
ClosedPublic

Authored by springerm on Feb 27 2023, 8:50 AM.

Details

Summary

This iterator is similar to ForwardIterator but enumerates blocks according to their successor relationship. As a first use case, this new iterator is utilized in the dialect conversion framework.

Depends On: D144887

Diff Detail

Event Timeline

springerm created this revision.Feb 27 2023, 8:50 AM
springerm requested review of this revision.Feb 27 2023, 8:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2023, 8:50 AM
springerm updated this revision to Diff 500823.Feb 27 2023, 8:59 AM

add comment

springerm planned changes to this revision.Feb 27 2023, 9:05 AM

This does not yet handle the case correctly when a block is taken from remainingBlocks: a block without predecessors must be selected. In case there is no such block, there is loop and any block can be taken. It would be more efficient to pre-compute a topologic sorting instead if following successors during the traversal. This would also allow for removing blocks during the traversal.

zero9178 added inline comments.Feb 27 2023, 9:10 AM
mlir/include/mlir/IR/Iterators.h
23

Please don't use using namespace in headers

62

I believe the not equals is automatically inherited from llvm::iterator_facade_base and therefor not necessary

springerm updated this revision to Diff 500828.Feb 27 2023, 9:20 AM

ForwardDominanceIterator does not enumerate unreachable blocks. They do not post-dominate the entry block.

springerm updated this revision to Diff 500829.Feb 27 2023, 9:23 AM

address comments

springerm marked 2 inline comments as done.Feb 27 2023, 9:23 AM

Why can't we just use the ReversePostOrderTraversal infra in LLVM?

springerm updated this revision to Diff 502949.Mar 7 2023, 12:56 AM

address comments: use llvm::depth_first

Why can't we just use the ReversePostOrderTraversal infra in LLVM?

Oh right, for the forward traversal we could use llvm::depth_first.

springerm added inline comments.Mar 7 2023, 12:57 AM
mlir/lib/Transforms/Utils/DialectConversion.cpp
73–75

Note: This error is no longer produced. Unreachable blocks DCE away so it should no matter if there are unreachable blocks.

rriddle accepted this revision.Mar 12 2023, 11:46 PM
rriddle added inline comments.
mlir/include/mlir/IR/Iterators.h
66–67

Use llvm::make_pointee_range instead.

mlir/lib/IR/RegionKindInterface.cpp
21–26
This revision is now accepted and ready to land.Mar 12 2023, 11:46 PM
This revision was automatically updated to reflect the committed changes.
springerm marked an inline comment as done.
springerm marked an inline comment as done.Mar 13 2023, 2:04 AM