This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse] refactor handling of merger leafs and ops
ClosedPublic

Authored by aartbik on Jun 7 2022, 5:40 PM.

Details

Summary

Using "default:" in the switch statemements that handle all our
merger ops has become a bit cumbersome since it is easy to overlook
parts of the code that need to handle ops specifically. By enforcing
full switch statements without "default:", we get a compiler warning
when cases are overlooked.

Diff Detail

Event Timeline

aartbik created this revision.Jun 7 2022, 5:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 5:40 PM
aartbik requested review of this revision.Jun 7 2022, 5:40 PM
wrengr accepted this revision.Jun 8 2022, 11:29 AM

I like this change a lot, since default cases are too fragile when there are so many cases to consider.

I do wonder though if it might be time to start refactoring the Kind enum to better handle the natural groupings of things. In particular I'm thinking it should be treated like a "bit enum" rather than an "int enum" (e.g., so that the I/F/C/etc suffix is encoded into, say, the low-order bits, whether something is leaf/unary/binary is encoded in the high-order bits, and then the op itself in the middle bits). Of course that should be done in a separate CL

mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
1101–1102

Why is the template keyword needed here when we don't need it for any of the other .cast<T>() method calls?

This revision is now accepted and ready to land.Jun 8 2022, 11:29 AM
aartbik marked an inline comment as done.Jun 9 2022, 10:31 AM
aartbik added inline comments.
mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
1101–1102

Good question, I am not sure how this was introduced, but we can do without. I removed all occurrences in the code.

aartbik updated this revision to Diff 435606.Jun 9 2022, 10:32 AM
aartbik marked an inline comment as done.

removed template keywords

I do wonder though if it might be time to start refactoring the Kind enum to better handle the natural groupings of things.

Agreed. A bit more "horizontal" encoding of type will simplify the long switch statements a bit, and get an intuitive way of getting the type from an op. But yeah, seems follow up CL.

This revision was automatically updated to reflect the committed changes.

Removing the default: on the switch in isSingleCondition broke the Windows bot, but unfortunately it was down so there was no timely notification. Sorry about that!
https://lab.llvm.org/buildbot/#/builders/13/builds/21881

FAILED: tools/mlir/lib/Dialect/SparseTensor/Utils/CMakeFiles/obj.MLIRSparseTensorUtils.dir/Merger.cpp.obj 
C:\PROGRA~2\MICROS~3\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe  ... /Fotools\mlir\lib\Dialect\SparseTensor\Utils\CMakeFiles\obj.MLIRSparseTensorUtils.dir\Merger.cpp.obj /Fdtools\mlir\lib\Dialect\SparseTensor\Utils\CMakeFiles\obj.MLIRSparseTensorUtils.dir\ /FS -c C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Utils\Merger.cpp
C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Utils\Merger.cpp(380) : error C2220: the following warning is treated as an error
C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Utils\Merger.cpp(380) : warning C4715: 'mlir::sparse_tensor::Merger::isSingleCondition': not all control paths return a value