Implemented an iterative preorder DFS topological sort
instead of the previous recursive version.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for working on this.
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | ||
---|---|---|
363 | Can this be inlined into topologicalSort? |
Addressed comments and reused llvm::ReversePostOrderTraversal for topological sorting.
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | ||
---|---|---|
389 | Nit: MLIR adopts camelBack convention for names. Switch from RPOT-> rpot? |
LGTM after resolving the remaining comments. You might want to clarify the commit title and description a bit more, it is very broad for what you are fixing here.
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | ||
---|---|---|
390 | nit: Use the range based insert instead. Also in the future, please cache the end iterator in loops when it is unchanged within the loop. |
Hey! Thanks for the patch! I wondered if it would make sense to move this utility to a public utility header. I found myself needing it locally and I wouldn't like to just copy-paste it. There is another topological sort for ops under 'include/mlir/Analysis/SliceAnalysis.h'. Maybe we could move them both to 'include/mlir/IR/Utils.h'? WDYT?
I think that if this functionality is needed elsewhere, then it should make sense to publicly expose it. Having 'include/mlir/IR/Utils.h' sounds reasonable - maybe we can have something similar to LLVM's ADT with MLIR specific utilities/algorithms built on top (I guess this is not only the case of topological sorting)? @rriddle, @mehdi_amini, @ftynse WDYT?
We use https://github.com/llvm/llvm-project/tree/master/mlir/include/mlir/Support in general for our helpers.
nit: You could just use llvm::ReversePostOrderTraversal to get the topological sort.