This is an archive of the discontinued LLVM Phabricator instance.

[flang][NFC] share Constant<SomeDerived> lowering
ClosedPublic

Authored by jeanPerier on Jan 4 2023, 6:39 AM.

Details

Summary

A previous patch (https://reviews.llvm.org/D136955) already refactored
intrinsic constant lowering to place in its own file and allow using it from
both the current lowering and the new lowering to HLFIR.

This patch does the same for derived types. The core function
"genStructComponentInInitializer" is moved from ConvertExpr.cpp and
renamed "genInlinedStructureCtorLitImpl" into ConvertConstant.cpp
without significant logic change.

Then, genScalarLit, genArrayLit (and genInlinedArrayLit/genOutlinedArrayLit)
are updated to support derived types.

The core aspect of derived type constant lowering that differs between
the current lowering and the HLFIR update is the way
addresses/initial target descriptors are built when part of a derived
type constant. This part happens in ConvertVariable.cpp (since the
address of a variable is taken in an initializer and is left TODO).

The mangling of derived type global literal constant is fixed: it did not embed
the derived type name and could cause "conflicts" between unrelated
derived types containing the same data. However, the hash remains
unstable between two compilation of the same file. This is not a
correctness issue and would require a lot of work to hash the derived
type constant data without hashing some irrelevant (but not out of bound)
data in the compile time data structure that holds derived type
constants (Constant<SomeDerived>). This may have to be revisited later.

Diff Detail

Event Timeline

jeanPerier created this revision.Jan 4 2023, 6:39 AM
Herald added a project: Restricted Project. · View Herald Transcript
jeanPerier requested review of this revision.Jan 4 2023, 6:39 AM
PeteSteinfeld accepted this revision.Jan 4 2023, 8:09 AM

Aside from a few nits in comments, all builds and tests correctly and looks good.

flang/include/flang/Lower/Mangler.h
91

"is none trivial" should read "is a nontrivial".

93

"constructor" should read "constructors".

flang/lib/Lower/ConvertConstant.cpp
367

"value" should read "values"

This revision is now accepted and ready to land.Jan 4 2023, 8:09 AM
jeanPerier marked 3 inline comments as done.

Fix typos in comments. Thanks for catching them Pete.

This revision was automatically updated to reflect the committed changes.