[flang-commits] [PATCH] D134735: [flang] Move main variables static promotion from lowering into IsSaved
Jean Perier via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Sep 27 06:10:48 PDT 2022
jeanPerier created this revision.
jeanPerier added reviewers: klausler, vzakhari.
jeanPerier added a project: Flang.
Herald added subscribers: mehdi_amini, jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.
Currently, lowering is promoting main program array and character
variables that are not saved into static memory.
This causes issues with equivalence initial value images because
semantics is relying on IsSaved to build the initial value of variables
in static memory. It seems more robust to have IsSaved be the place
deciding if a variable needs to be in static memory (except for common
block members).
Move the logic to decide if a main program variable must be in static
memory into evaluate::IsSaved and add two options to semantics to
replace the llvm options that were used in lowering:
- SaveMainProgram (off by default): save all main program variables.
- SaveBigMainProgramVariables (on by default): save all main program variables that are bigger than 32 bytes.
The first options is required to run a few old programs that expect all
main program variables to be in bss (and therefore zero initialized).
The second option is added to allow performance testing: placing big
arrays in static memory seems a sane default to avoid blowing up the
stack with old programs that define big local arrays in the main
program, but since it is easier to prove that an alloca does not
escape/is not modified by calls, keeping big arrays on the stack could
yield improvements.
The logic of SaveBigMainProgramVariables is slightly changed compared to what
it was doing in lowering. The old code was placing all arrays and all
explicit length characters in static memory.
The new code is placing everything bigger than 32 bytes in static
memory. This has the advantages of being a simpler logic, and covering
the cases of scalar derived type with big array components or many
components. Small strings and arrays are now left on the stack (after
all, a character(1) can fit in register).
Note: I think it could have been nicer to add a single "integer" option
to set a threshold to place main program variables in static memory so
that this can be fine tuned by the drivers (SaveMainProgram would be
implemented by setting it to zero). But the language feature options are
not meant to carry integer options. Extending it for this seems an
overkill precedent, and placing it in SemanticsContext is weird (it is
a too low level option to be a bare member of SemanticsContext in my
opinion). So I just rolled my own dices and picked 32 for the sake of
simplicity.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134735
Files:
flang/include/flang/Common/Fortran-features.h
flang/lib/Evaluate/tools.cpp
flang/lib/Lower/PFTBuilder.cpp
flang/test/Lower/OpenMP/atomic-read.f90
flang/test/Lower/array-character.f90
flang/test/Lower/array-expression-slice-1.f90
flang/test/Lower/associate-construct.f90
flang/test/Lower/io-write.f90
flang/test/Lower/namelist.f90
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134735.463212.patch
Type: text/x-patch
Size: 12763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220927/9539cd5c/attachment.bin>
More information about the flang-commits
mailing list