This is an archive of the discontinued LLVM Phabricator instance.

[ADT][mlir][NFCI] Do not use non-const lvalue-refs with enumerate
ClosedPublic

Authored by kuhar on Mar 13 2023, 6:54 PM.

Details

Summary

Replace references to enumerate results with either result_pairs
(reference wrapper type) or structured bindings. I did not use
structured bindings everywhere as it wasn't clear to me it would
improve readability.

This is in preparation to the switch to zip semantics which won't
support non-const lvalue reference to elements:
https://reviews.llvm.org/D144503.

I chose to use values instead of const lvalue-refs because MLIR is
biased towards avoiding const local variables. This won't degrade
performance because currently result_pair is cheap to copy (size_t
+ iterator), and in the future, the enumerator iterator dereference
will return temporaries anyway.

Diff Detail

Event Timeline

kuhar created this revision.Mar 13 2023, 6:54 PM
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a reviewer: ftynse. · View Herald Transcript
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
kuhar requested review of this revision.Mar 13 2023, 6:54 PM
dblaikie accepted this revision.Mar 14 2023, 10:06 AM

Looks good, thanks!

This revision is now accepted and ready to land.Mar 14 2023, 10:06 AM