Skip to content

Lower initial data target #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2021
Merged

Lower initial data target #688

merged 2 commits into from
Mar 19, 2021

Conversation

jeanPerier
Copy link
Collaborator

Create a function genInitialDataTarget to create a fir.box for a pointer initial data target. In defineGlobal and defineCommon, use it if the global (or common member) is a pointer with an initial data target.

This is not added to defineGlobalAggregateStore because C8106 prevents pointer/derived type with pointer component to be used in equivalences.
The fact that the initial data target cannot be in an equivalence (C8108 + C765) also simplifies the logic (there is no need to try instantiating aggregate stores inside global op initializer).
The main Fortran difficulty was that the initial data target can be in common block, and so can the pointer. This is covered by the instantiateVar(var) call on the initial data target that will declare the common block if needed (as this call it does in normal context).

Most of the complexity of genInitialDataTarget stems from the fact that it is not possible to use fir.rebox in a global initializer (which we normally used in some pointer assignment case). I tried making this possible, but it was driving too much weird changes in fir.rebox codegen to support both an in memory and a struct descriptor argument. So I went for an ad-hoc handling of this corner case.

The last test cases block data snake and block data tied in pointer-initial-target-2.f90 lowers fine to FIR and LLVM dialect, but crashes the LLVM dialect to LLVM IR pass. I am working on a simple fix for this, the issue turned out to be that the translation passes declare global op and define their body in the same pass, which is an issue if they are forward reference from an initializer to a globalOp not yet declared in LLVM IR.

Derived type with length parameters are left TODOs. I can't prepare much here without more general work on them.

Copy link

@schweitzpgi schweitzpgi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

type = ty;
if (auto seqType = type.dyn_cast<fir::SequenceType>())
type = seqType.getEleTy();
return type;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this isn't already implemented someplace. Seems to pop up often.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we had a discussion a while ago about having this in FIRType.h. For types that wraps character/record, we might want quick access on the character/record type to take decisions based on the length parameters. The conclusion at the time was that it was too custom (so there is something very similar in CharacterExpr.cpp).
Would you be in favor of moving this in FIRType.h ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the best place for it, if it can reduce some replication.

@jeanPerier jeanPerier merged commit 6a9f909 into fir-dev Mar 19, 2021
@jeanPerier jeanPerier deleted the jp-pointer-init-target-7 branch March 19, 2021 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants