llvm-project/flang/lib/Optimizer/Dialect
Valentin Clement fe252f8ed6
[flang] Lower boxed procedure
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.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D122223

Co-authored-by: mleair <leairmark@gmail.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2022-03-22 15:41:11 +01:00
..
CMakeLists.txt [flang][NFC] Move current inliner files in Dialect directory 2022-01-20 13:34:44 +01:00
FIRAttr.cpp [flang][NFC] Fix includes order 2022-01-19 14:32:48 +01:00
FIRDialect.cpp [flang] Remove 'using namespace mlir;` from header files 2022-03-09 10:19:51 +00:00
FIROps.cpp [flang] Lower boxed procedure 2022-03-22 15:41:11 +01:00
FIRType.cpp [flang] Lower statement function 2022-03-18 14:47:16 +01:00
Inliner.cpp [flang][NFC] Move current inliner files in Dialect directory 2022-01-20 13:34:44 +01:00