PSA: Inorder/preorder walker

Current MLIR walkers are post-order w.r.t. to the regions attached to an operation, i.e., operations are visited in program order and when an operation has attached regions, the attached regions are visited before visiting the operation. I was recently in need of a pre-order walker which would visit an operation before visiting the attached regions. It’s conceivable to find use cases where we want to visit the operation in between visiting regions, or a combination of all 3 (visit operation before, in between, and after visiting regions). Currently there are no use cases within MLIR codebase, so I have implemented such walkers in TensorFlow. Just wanted to post it here as a PSA in case other folks have implemented or need to implement something like this (and we can consider bringing them into the MLIR tree).

Thank you for the information! I have a use case for a pre-order traversal in some optimization, but I was too lazy to implement it myself. It will be nice to have something similar in the upstream.

This would be pretty useful and definitely needed at some point, esp. the pre-order walker which is the order that respects SSA dominance for nested single block ops.