This is an archive of the discontinued LLVM Phabricator instance.

[flang] Lower and code gen for allocate on polymorphic entities
ClosedPublic

Authored by clementval on Oct 21 2022, 12:50 AM.

Details

Summary

When allocating a polymorphic entity, its type descriptor can come
from the declared type or can be provided in the allocate statement.
This patch adds lowering for allocate on polymorphic by calling
the AllocatableInitDerived runtime function with the correct
type descriptor. Some adaptation are made in the code generation
to accept fir.class where it is appropriate.

Diff Detail

Event Timeline

clementval created this revision.Oct 21 2022, 12:50 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Oct 21 2022, 12:50 AM

Remove unrelated change

Update design doc as well

jeanPerier accepted this revision.Oct 21 2022, 4:08 AM

LGTM

flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
308

Wow, you made that type accurate ! I am pondering whether this is needed or not. Do you see drawbacks of using fir.ref<None> for this type currently ?
The cons I see of defining the accurate type here is that you will have to maintain it if it changes, and it makes the IR a bit more verbose (although I really think we should leverage MLIR type aliasing to make IR with derived type more readable, so it should not be the main motivation).

flang/lib/Lower/Allocatable.cpp
492

I think this assert should be a fir::emitFatalError() instead because a user can trigger this state by hiding the intrinsic module which will prevent type descriptor symbols to not be created and generated.

This revision is now accepted and ready to land.Oct 21 2022, 4:08 AM

Address review comments

clementval marked 2 inline comments as done.Oct 21 2022, 5:06 AM
clementval added inline comments.
flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
308

Yeah it's a bit overkill here. Going with the !fir.ref<none> at least for now since there is no real need to have the accruate type.

flang/lib/Lower/Allocatable.cpp
492

Changed to fatal error.

This revision was automatically updated to reflect the committed changes.
clementval marked 2 inline comments as done.