This is an archive of the discontinued LLVM Phabricator instance.

[Flang] Initial patch to lower a Fortran intrinsic
ClosedPublic

Authored by kiranchandramohan on Feb 16 2022, 4:18 PM.

Details

Summary

This patch brings in some initial changes for lowering Fortran
intrinsics. Intrinsics are generally lowered to a mix of FIR and
MLIR operations, runtime calls or LLVM intrinsics. This patch
particularly brings in the lowering of the Fortran andi intrinsic
to arith.andi in MLIR.

The significant changes are in ConvertExpr.cpp and IntrinsicCall.cpp.
Intrinsic functions occur as part of expressions. Lowering deals with this
in ConvertExpr.cpp in genval(const Fortran::evaluate::FunctionRef<A> &funcRef).
The code in the above mentioned function kicks of a sequence of calls
that ultimately results in a call to the genIand function in
IntrinsicCall.cpp which creates the MLIR arith.andi operation.

A few tests are also included.

Note: Generally intrinsics like iand can occur in array (elemental)
context, but since that part is not fully supported in lowering, tests
are only added for the scalar context.
This patch,
-> was originally written by Jean Perier <jperier@nvidia.com>, Eric Schweitz <eschweitz@nvidia.com> et.al
-> is part of upstreaming from the fir-dev branch of https://github.com/flang-compiler/f18-llvm-project

Diff Detail

Event Timeline

kiranchandramohan requested review of this revision.Feb 16 2022, 4:18 PM

Further, simplify the patch. Remove un-necessary changes in OpenMP.cpp, OpenACC.cpp, Runtime.cpp. Remove pgmath, llvm intrinsic, runtime call lowering in IntrinsicCall.cpp.

More cleanup and simplification required. Continues as WIP.

Further, simplified the patch. Removed un-necessary changes in ConvertType.cpp,
ConvertType.h, Utils.h, AbstractConverter.h, Bridge.cpp, removed usage of
StatementContext and the file that contains its definition.

While this patch is close to getting ready, there are further simplifications
possible in ConvertExpr.cpp and IntrinsicCall.cpp. Patch continues to be a WIP.

kiranchandramohan updated this revision to Diff 410190.EditedFeb 20 2022, 3:51 PM

Further, simplified the patch. Removed some un-necessary code from ConvertExpr.cpp,
minimised headers in IntrinsicCall.cpp, added and moved test.
I need one more pass to cleanup the comments, the commit message and a final check for code removal and addition of tests. Patch continues as WIP.

Further, simplified the patch. Added some tests, adjusted comments, modified commit message.
Patch is ready for review now.

kiranchandramohan retitled this revision from [WIP][Flang] Initial patch to lower a Fortran intrinsic to [Flang] Initial patch to lower a Fortran intrinsic.Feb 21 2022, 2:16 AM
kiranchandramohan edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Feb 21 2022, 3:12 AM