This is an archive of the discontinued LLVM Phabricator instance.

Lower Fortran intrinsic to a runtime call/llvm intrinsic
ClosedPublic

Authored by kiranchandramohan on Feb 23 2022, 4:15 AM.

Details

Summary

This patch brings in code which can lower a Fortran intrinsic to
a runtime call or an llvm intrinsic. For math intrinsics the
runtime call is to the math or pgmath library. Non-math
intrinsics are covered by the Flang runtime. A distance computation
mechanism is introduced to find the runtime function that closely
matches the types of the intrinsic call.

In this patch, the abs intrinsic is lowered in the following way,
-> Integer version is lowered as a group of MLIR/FIR operations
-> Real version is lowered to llvm intrinsics
-> Complex version is lowered to the math_hypot runtime function

This patch is part of upstreaming from the fir-dev branch of https://github.com/flang-compiler/f18-llvm-project

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: zacharyselk <zrselk@gmail.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: mehdi_amini. · View Herald Transcript
kiranchandramohan requested review of this revision.Feb 23 2022, 4:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 23 2022, 4:15 AM

Added tests. Patch is ready for review.

flang/lib/Lower/IntrinsicCall.cpp
153–167

Note: These flags are not tested in this patch since the abs intrinsic does not have fast/relaxed/precise versions for float, it only has an llvm or math runtime lowering for float. Can remove if necessary.

211

Have raised https://github.com/flang-compiler/f18-llvm-project/issues/1497 to discuss the half, bfloat, 80bit, 128bit precision types.

kiranchandramohan retitled this revision from [WIP][Flang] Lower Fortran intrinsic to a runtime call/llvm intr to Lower Fortran intrinsic to a runtime call/llvm intrinsic.Feb 24 2022, 4:11 PM
clementval accepted this revision.EditedFeb 24 2022, 11:12 PM

LGTM.

Please use the Co-authored-by: notation in the commit message otherwise the contributions is not correctly attributed.

This revision is now accepted and ready to land.Feb 24 2022, 11:12 PM
awarzynski added inline comments.Feb 25 2022, 1:43 AM
flang/test/Lower/Intrinsics/abs.f90
2

Shall we test with flang-new as well? I think that that would be helpful to make sure that the two stay in sync.

Add testing with flang-new -fc1. Add co-authors.

kiranchandramohan edited the summary of this revision. (Show Details)Feb 25 2022, 6:52 AM

Removed code dealing with relaxed and precise pgmath intrinsics since this is not tested.
Also removed flags which can switch between precise, relaxed, fast or llvm intrinsics.

Removed code dealing with relaxed and precise pgmath intrinsics since this is not tested.
Also removed flags which can switch between precise, relaxed, fast or llvm intrinsics.

Would be better to remove the code before review.

@clementval wrote: Please use the Co-authored-by: notation in the commit message otherwise the contributions is not correctly attributed.

Done

Removed code dealing with relaxed and precise pgmath intrinsics since this is not tested.
Also removed flags which can switch between precise, relaxed, fast or llvm intrinsics.

Would be better to remove the code before review.

Sorry about that. I will bring the removed code soon in another review. Submitting this now.

flang/lib/Lower/IntrinsicCall.cpp
153–167

done

flang/test/Lower/Intrinsics/abs.f90
2

done.

schweitz added inline comments.Feb 25 2022, 9:40 AM
flang/lib/Lower/IntrinsicCall.cpp
80

I assume we want to add some doxygen commentary to these, albeit brief. (Noting that some of these member functions have it and some do not.)

282

Extra unneeded braces used throughout this function.

321

I think this will use the default initializer without explicitly stating it, no?

322

nit: use =

346

nit: =

351

nit: LLVM style else after return

Thanks @schweitz for the comments. I submitted before I saw the comments. Will address these in a separate patch.