This is an archive of the discontinued LLVM Phabricator instance.

[flang] Handle array constants of any rank
ClosedPublic

Authored by luporl on May 16 2023, 9:11 AM.

Details

Summary

Add support for representing array constants of any rank with MLIR
dense attribute. This greatly improves compile time and memory
usage of programs with large array constants. We still support only
arrays of a few basic types, such as integer, real and logic.

Fixes https://github.com/llvm/llvm-project/issues/60376

Diff Detail

Event Timeline

luporl created this revision.May 16 2023, 9:11 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 16 2023, 9:11 AM
luporl published this revision for review.May 16 2023, 9:15 AM

Thanks for working on this. Did you check with the example given by @jeanPerier in the issue? What kind of build time to you see?

luporl added a comment.EditedMay 16 2023, 9:49 AM

Thanks for working on this. Did you check with the example given by @jeanPerier in the issue? What kind of build time to you see?

Yes, I ended up commenting more about this in the issue. With @jeanPerier's example, I get the following build time:

$ time flang -c ftest_reduced.f90

real	0m1.059s
user	0m0.962s
sys	0m0.096s

This is on an ARMv8.2 Ampere Altra Mt. Jade machine.

(In the command above, flang is actually an alias to /home/leandro.lupori/git/flang-i60376/buildr/bin/flang-new)

It might to be good to add a test with the codegen to make sure we have what we expect at the LLVM IR level.

Thank you very much for improving this limitation!

flang/lib/Lower/ConvertConstant.cpp
553

I know I initially suggested the TODO, but after discussions, it would be too harsh to artificially limit the size of a program that can be compile. Some people with more RAM and time may just be OK with bigger compile time here to be able to test/use flang without modifying their programs.

The ideal would be to add a driver switch to control the size limit and to tell the user to use that switch to increase the limit in the TODO message that would warn this may lead to very long compile time.

Since threading a switch here may not be straightforward, I am also OK with just removing the TODO for now so that flang can be tested with no limit and to leave your comment with the addition that it would be nice to add a switch to control an array size after which flang should not continue to compile.

Besides, after your patch it should be a lot less common to hit the compilation time/memory issue (most big array constant expressions will use integer and reals out there).

luporl updated this revision to Diff 523113.May 17 2023, 11:04 AM

Add test that checks LLVM IR matches what is expected

luporl added inline comments.May 17 2023, 11:56 AM
flang/lib/Lower/ConvertConstant.cpp
553

Ok, since big array constants of types other than integer and real shouldn't be common, for now I'll just remove the TODO and leave a comment.

luporl updated this revision to Diff 523137.May 17 2023, 12:37 PM
luporl edited the summary of this revision. (Show Details)

Remove TODO and suggest the addition of a switch to control the maximum array size supported.

luporl marked an inline comment as done.May 17 2023, 12:37 PM
jeanPerier accepted this revision.May 19 2023, 5:46 AM

Thanks a lot, LGTM

This revision is now accepted and ready to land.May 19 2023, 5:46 AM
This revision was automatically updated to reflect the committed changes.
luporl reopened this revision.May 22 2023, 3:05 PM
This revision is now accepted and ready to land.May 22 2023, 3:05 PM
luporl updated this revision to Diff 524503.May 22 2023, 3:07 PM

Fix dense attributes for integers with KIND > 8

jeanPerier accepted this revision.May 23 2023, 12:33 AM

Thanks for the fix

This revision was automatically updated to reflect the committed changes.