This is an archive of the discontinued LLVM Phabricator instance.

[flang] Support lowering of parent component in strecture constructor
ClosedPublic

Authored by peixin on Oct 22 2022, 8:52 AM.

Details

Summary

Reuse the previous record assignment code. Use gen(expr) to generate
the fir::ExtendedValue of parent component recursively and convert the
structure to a fir.ref<T> type, where T is the record type of parent
component. Then, fir:🏭:genRecordAssignment can be reused to
assign the parent component to the type-casted structure.

Diff Detail

Event Timeline

peixin created this revision.Oct 22 2022, 8:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 22 2022, 8:52 AM
peixin requested review of this revision.Oct 22 2022, 8:52 AM
jeanPerier added inline comments.Oct 24 2022, 6:23 AM
flang/lib/Lower/ConvertExpr.cpp
1069

I think you can simply convert res to a fir.ref<T> where T is the recordType of from, and call fir::factory::genRecordAssignment(builder, loc, resCast, from);. This should deal with the case where the runtime needs to be called without making a full copy of from before calling th

flang/lib/Optimizer/Builder/FIRBuilder.cpp
1053

I do not follow why this change was required. Doesn't llvm::zip already safely take the smallest of the two lists as iteration size ? I think the new code could segafult at compile time if genComponentByComponentAssignment was called with a lhs that has less components than the rhs (which would of course be a compiler bug)

1180

I think you can avoid adding genParentCompAssigment and all this by calling genRecordAssignment (the mutable box trick is a bit weird, better to keep it in one place).

peixin updated this revision to Diff 470413.Oct 25 2022, 1:56 AM
peixin edited the summary of this revision. (Show Details)

Thanks @jeanPerier a lot for the suggestions.

I do not follow why this change was required. Doesn't llvm::zip already safely take the smallest of the two lists as iteration size ? I think the new code could segafult at compile time if genComponentByComponentAssignment was called with a lhs that has less components than the rhs (which would of course be a compiler bug)

Right. I had thought llvm::zip requires the size of two list to be the same. I was wrong.

flang/lib/Lower/ConvertExpr.cpp
1069

Good idea. This makes things much simple. Thanks for this.

This revision is now accepted and ready to land.Oct 25 2022, 9:41 AM