This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ElementsAttr] Change value_begin_impl to try_value_begin_impl
ClosedPublic

Authored by Mogball on Aug 29 2022, 6:27 PM.

Details

Summary

This patch changes value_begin_impl to a faillable
try_value_begin_impl so that specific cases can fail iteration if the
type doesn't match the internal storage.

Diff Detail

Event Timeline

Mogball created this revision.Aug 29 2022, 6:27 PM
Mogball requested review of this revision.Aug 29 2022, 6:27 PM
rriddle added inline comments.Aug 29 2022, 6:42 PM
mlir/include/mlir/IR/BuiltinAttributes.td
435–437

This doesn't look right, this implementation will crash if it can't iterate. I suppose that these are more annoying to check for (DenseElementsAttr+SparseElementsAttr), but we'll need at least a TODO here. This isn't the desired end state.

mlir/include/mlir/Support/LogicalResult.h
103

Can we use is_convertible here instead of is_same?

Mogball added inline comments.Aug 30 2022, 8:44 AM
mlir/include/mlir/IR/BuiltinAttributes.td
435–437

ElementsAttr::getValues also crashes if it can't iterate. That's why there's a tryGetValues method. Should I add one here as well?

Mogball added inline comments.Aug 30 2022, 9:10 AM
mlir/include/mlir/IR/BuiltinAttributes.td
435–437

Whoops I meant try_value_begin 🙃 ⚡

Mogball updated this revision to Diff 456722.Aug 30 2022, 10:45 AM

use std::is_convertible_v

Mogball marked 2 inline comments as done.Aug 30 2022, 10:46 AM
Mogball added inline comments.
mlir/include/mlir/IR/BuiltinAttributes.td
435–437
rriddle accepted this revision.Aug 30 2022, 12:41 PM
This revision is now accepted and ready to land.Aug 30 2022, 12:41 PM