This is an archive of the discontinued LLVM Phabricator instance.

[mlir][IR][NFC] Move `walk` definitions to header file
ClosedPublic

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

Details

Summary

This allows users to provide custom Iterator templates. A new iterator will be added in a subsequent change.

Also rename makeRange to makeIterable and add a test case for the reverse iterator.

Diff Detail

Event Timeline

springerm created this revision.Feb 27 2023, 8:49 AM
springerm requested review of this revision.Feb 27 2023, 8:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2023, 8:49 AM
mehdi_amini added inline comments.Feb 27 2023, 10:52 AM
mlir/include/mlir/IR/Visitors.h
190

This makes me think that our walk implementation is recursive right? Seems like a ticking bomb in the compiler :(
How hard will it be to remove the recursion?

Any idea of how this will affect build times? This code is now going to get instantiated a lot.

Any idea of how this will affect build times? This code is now going to get instantiated a lot.

It does not affect compile time on my machine. It's a pretty fast machine though (AMD Ryzen Threadripper PRO 3995WX 64-Cores).

BEFORE

➜  llvm-project git:(3f9b0446f9a7) time cmake --build build --target mlir-opt
[3109/3109] Linking CXX executable bin/mlir-opt
cmake --build build --target mlir-opt  13980.53s user 550.07s system 7589% cpu 3:11.46 total

➜  llvm-project git:(3f9b0446f9a7) time cmake --build build --target mlir-opt
[3109/3109] Linking CXX executable bin/mlir-opt
cmake --build build --target mlir-opt  13951.46s user 552.38s system 7599% cpu 3:10.85 total



AFTER

➜  llvm-project git:(269d19604f36) time cmake --build build --target mlir-opt
[3109/3109] Linking CXX executable bin/mlir-opt
cmake --build build --target mlir-opt  13983.18s user 554.72s system 7620% cpu 3:10.78 total

➜  llvm-project git:(269d19604f36) time cmake --build build --target mlir-opt
[3109/3109] Linking CXX executable bin/mlir-opt
cmake --build build --target mlir-opt  13982.50s user 552.88s system 7614% cpu 3:10.90 total
springerm added inline comments.Feb 28 2023, 1:38 AM
mlir/include/mlir/IR/Visitors.h
190

The post-order traversal makes it quite difficult. I think we would need to maintain a stack of iterators. Actually 3 stacks, one for operation, block and region. Alternatively, one iterator that keeps track of current op, block and region. And with three types of increment: getNextOp, getNextBlock, getNextRegion.

rriddle accepted this revision.Mar 3 2023, 9:53 AM
This revision is now accepted and ready to land.Mar 3 2023, 9:53 AM

The failures look real, seems missing clang-format

This revision was landed with ongoing or failed builds.Mar 6 2023, 12:21 AM
This revision was automatically updated to reflect the committed changes.