This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Special handling for temporary LHS in AssignOp.
ClosedPublic

Authored by vzakhari on Jun 8 2023, 3:56 PM.

Details

Summary

When AssignOp is used with LHS that is a compiler generated temporary
special care must be taken to initialize the temporary and avoid
finalizations of its components. This change-set adds optional
temporary_lhs attribute for AssignOp to convey this information
to HLFIR-to-FIR conversion pass. Currently, this results in
calling AssignTemporary runtime for doing the assignment.

Diff Detail

Event Timeline

vzakhari created this revision.Jun 8 2023, 3:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2023, 3:56 PM
vzakhari requested review of this revision.Jun 8 2023, 3:56 PM
tblah accepted this revision.Jun 10 2023, 7:50 AM

LGTM aside from one nit

flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
129

nit: this could have one less level of if nesting (feel free not to change if you don't think this is worth the effort)

} else if (assignOp.isTemporaryLHS())
  fir::runtime::genAssignTemporary(builder, loc, to, from);
else if (lhs.isPolymorphic())
  fir::runtime::genAssignPolymorphic(builder, loc, to, from);
else
  fir::runtime::genAssign(builder, loc, to, from);
This revision is now accepted and ready to land.Jun 10 2023, 7:50 AM

Thanks Slava, this looks like the right solution to me and this will allow using hlfir.assign for derived type array constructor too (and a few other places where we just want "dumb" copies)!

flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
129

+1

jeanPerier accepted this revision.Jun 13 2023, 8:29 AM
vzakhari updated this revision to Diff 534751.Jun 26 2023, 2:25 PM

Thank you for the review! I changed the ifs layout.