This is an archive of the discontinued LLVM Phabricator instance.

[flang] Lower boxed procedure
ClosedPublic

Authored by clementval on Mar 22 2022, 5:29 AM.

Details

Summary

In FIR, we want to wrap function pointers in a special box known as a
boxproc value. Fortran has a limited form of dynamic scoping
[https://tinyurl.com/2p8v2hw7] between "host procedures" and "internal
procedures". There are a number of implementations possible.

Boxproc typed values abstract away the implementation details of when a
function pointer can be passed directly (as a raw address) and when a
function pointer has to account for the presence of a dynamic scope.
When lowering Fortran syntax to FIR, all function pointers are emboxed
as boxproc values.

When creating LLVM IR, we must strip away the abstraction and produce
low-level LLVM "assembly" code. This patch implements that
transformation as converting the boxproc values to either raw function
pointers or executable trampolines on the stack as needed. The
trampoline then captures the dynamic scope context within an executable
thunk that can be passed instead of the function's raw address.

Some extra handling is required for Fortran functions that return a
character value to deal with LEN values here.

Some of the code in Bridge.cpp and ConvertExpr.cpp and be re-arranged to
faciliate the upstreaming effort.

This patch is part of the upstreaming effort from fir-dev branch.

Diff Detail

Event Timeline

clementval created this revision.Mar 22 2022, 5:29 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
clementval requested review of this revision.Mar 22 2022, 5:29 AM
jeanPerier added inline comments.Mar 22 2022, 6:05 AM
flang/include/flang/Optimizer/Builder/FIRBuilder.h
63

I am not sure why the [[maybe_unused]] was added upstream, but this patch is not adding any usage to this function, so change looks odd to me.

451

Looks like upstream style fix is correct here.

454

en -> and ? (fir-dev likely misses the upstream fix)

clementval marked 3 inline comments as done.

Address review comment

flang/include/flang/Optimizer/Builder/FIRBuilder.h
63

Right. I'll put it back.

This revision is now accepted and ready to land.Mar 22 2022, 6:31 AM
PeteSteinfeld accepted this revision.Mar 22 2022, 6:39 AM

All builds and tests correctly and looks good.

flang/include/flang/Optimizer/Builder/FIRBuilder.h
63

I'm not sure about this particular usage, but I've run into bugs in some versions of GNU C++ where the compiler was incorrectly determining that a declaration was unused and emitting a warning that got turned into an error.

This revision was automatically updated to reflect the committed changes.
flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp