This is an archive of the discontinued LLVM Phabricator instance.

[flang] lower F77 calls in HLFIR
ClosedPublic

Authored by jeanPerier on Nov 30 2022, 5:55 AM.

Details

Summary

Use recently added hlfir.associate/hlfir.end_associate to deal
with the cases where the actual argument is an expression.

Diff Detail

Event Timeline

jeanPerier created this revision.Nov 30 2022, 5:55 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a subscriber: mehdi_amini. · View Herald Transcript
jeanPerier requested review of this revision.Nov 30 2022, 5:55 AM
PeteSteinfeld accepted this revision.Nov 30 2022, 8:03 AM

Aside from nits and questions, all builds and tests correctly and looks good.

flang/include/flang/Optimizer/Builder/HLFIRTools.h
185

There's an extra space character after Return.

flang/lib/Lower/Bridge.cpp
1112–1116

I don't understand this code. This else corresponds to the if that tests to see if we're generating HLFIR. But since the code is calling createSubroutineCall, I'm concerned that we're not handling the case for a function call. Does createSubroutineCall handle both functions and subroutines?

flang/lib/Lower/ConvertCall.cpp
406–415

I wonder if this is the right test. We need to handle the case where we have an elemental function call that doesn't have any array arguments but which returns an array.

417–425

I'm curious. What's different about lowering of statement functions?

flang/lib/Optimizer/Builder/HLFIRTools.cpp
173

There's an extra space character after numerical.

177

"mismatch" should be "mismatches".

This revision is now accepted and ready to land.Nov 30 2022, 8:03 AM
jeanPerier marked 3 inline comments as done.

Fix typos and extra spaces in comments caught by Pete.

Thanks for the review @PeteSteinfeld

flang/include/flang/Optimizer/Builder/HLFIRTools.h
185

Thanks !

flang/lib/Lower/Bridge.cpp
1112–1116

There cannot be function calls here, this code (in genFIR(const Fortran::parser::CallStmt &stmt)) deals with fortran call statement lowering. Only subroutines can be called in a call statement.

Function calls lowering happen when lowering an Expr<T> that is a FunctionRef<T>.

The else case basically keeps the current lowering code during the transition.

flang/lib/Lower/ConvertCall.cpp
406–415

We need to handle the case where we have an elemental function call that doesn't have any array arguments but which returns an array.

My understanding is that this is not possible ("C15101: The result of an elemental function shall be scalar" and "15.8.2 point 1: If there are no actual arguments or the actual arguments are all scalar, the result is scalar."), do you have a specific use case in mind ?

Note that a elemental function references can be assigned to an array, but in that case (when all arguments are scalars) the function returns a scalar that is assigned to all the left hand side elements. So there is no elemental aspect to deal with in such calls, the elemental aspects happen in the assignment.

417–425

They are (and still will) be handled very differently: the statement function expression is inlined directly in lowering: we do not generate a function body and symbol for them. That is because it would be more hassle to outline statement functions than it is to inline them on the spot: statement functions do not have a body in the parse tree that would allow using the bridge code to generate a FIR function for them, it would need ad-hoc handling, whereas we already know how to lower an expression given what the referred symbols mapped to.
It is also probably better from a performance point and view. The last point is that it is possible because statement functions cannot directly or indirectly be recursive (otherwise, we would have an infinite loop in lowering).

This revision was automatically updated to reflect the committed changes.