This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Fix auto usage to avoid copies
ClosedPublic

Authored by akshaykhadse on Mar 22 2023, 11:11 PM.

Details

Summary

Fixes some usages of the "auto" keyword to avoid creation of copies.

Diff Detail

Event Timeline

akshaykhadse created this revision.Mar 22 2023, 11:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2023, 11:11 PM
akshaykhadse requested review of this revision.Mar 22 2023, 11:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2023, 11:11 PM
akshaykhadse edited the summary of this revision. (Show Details)
LuoYuanke retitled this revision from Fix auto usage to avoid copies to [NFC] Fix auto usage to avoid copies.Mar 22 2023, 11:42 PM
LuoYuanke added inline comments.Mar 22 2023, 11:56 PM
llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
857

I notice in https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable, the example code show "auto &Val". Should we follow the same style "auto &Pair". Ditto for others?

craig.topper added inline comments.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
20966 ↗(On Diff #507621)

Doesn't the deference operator for enumerate return by value?

craig.topper added inline comments.Mar 23 2023, 12:15 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
20966 ↗(On Diff #507621)

So I'm not sure this is really preventing a copy.

Addressed comments

LuoYuanke added inline comments.Mar 23 2023, 2:18 AM
llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
857

@craig.topper, how about this one? Does the iteration return reference? For basic practice "auto &" is better than "auto"?

akshaykhadse marked an inline comment as done.

Avoid using references for enumerate

akshaykhadse marked 2 inline comments as done.

Address Craig's comments

This revision is now accepted and ready to land.Mar 23 2023, 5:13 AM

@akshaykhadse, do you want me to help merge the patch?

@akshaykhadse, do you want me to help merge the patch?

Yes. That would be great!

This revision was automatically updated to reflect the committed changes.