This is an archive of the discontinued LLVM Phabricator instance.

[flang] Support lowering intrinsic `selected_real_kind` for variables
ClosedPublic

Authored by peixin on Jul 20 2022, 9:52 AM.

Details

Summary

As Fortran 2018 16.9.170, the argument of selected_real_kind is integer
scalar, and result is default integer scalar. The constant expression in
this intrinsic has been supported by folding the constant expression.
This supports lowering this intrinsic for variables using runtime.

Diff Detail

Event Timeline

peixin created this revision.Jul 20 2022, 9:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2022, 9:52 AM
peixin requested review of this revision.Jul 20 2022, 9:52 AM
peixin added inline comments.Jul 20 2022, 9:55 AM
flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
164

I am thinking if it is possible to refactor the Forced### ? For multiple arguments, the combination will result in a large amount of helpers. Or leave it there when more intrinsics have this problem.

peixin planned changes to this revision.Jul 20 2022, 9:58 AM
peixin updated this revision to Diff 446196.Jul 20 2022, 10:11 AM

Fix the error.

jeanPerier requested changes to this revision.Jul 21 2022, 12:48 AM

I think this is way too much entry point for a not so performance critical important intrinsic (that is folded 90% of the cases).
Have you considered using a single select_real_kind(void* precision , int precisionKind, void* range, int rangeKind, void* radix, int radixKind) interface ? It should also allow a better handling of the dynamically absent cases.
(Simplifying the interface for select_int_kind is also actually probably worth it, but since it is simpler, I am also OK with its current form).

flang/runtime/numeric.cpp
121

Right now I think there would be an issue if RADIX is absent, lowering would set it to zero, causing the runtime to return an error while the runtime says there is no requirement is about the radix if it is dynamically absent (say it is an absent optional).

I think it would be better to have the runtime interface be const Descriptor*/void* so that the dynamically absent case can be handled by the runtime.

This revision now requires changes to proceed.Jul 21 2022, 12:48 AM
peixin updated this revision to Diff 446865.Jul 22 2022, 9:08 AM

Use the new approach as @jeanPerier suggested.

peixin updated this revision to Diff 447121.Jul 24 2022, 4:21 AM

Rebase due to application patch conflict.

jeanPerier accepted this revision.Jul 25 2022, 12:59 AM

Thanks, looks good to me

This revision is now accepted and ready to land.Jul 25 2022, 12:59 AM