This pass implements the stack arrays RFC at https://reviews.llvm.org/D139617 - see the RFC document for more information. In short, this is a pass to move heap allocated array temporaries to the stack to implement the -fstack-arrays flag.
There are two cases of array temporary allocation which are not transformed by the current analysis. See the RFC for more information. I intend to merge stack arrays with the current design then visit these more complex cases later once I have a better understanding of the HLFIR changes.
In brief, this pass uses data flow analysis to detect heap allocations which are always freed within the same function as the allocation. If these allocations were added by flang (not by allocate statements in the source code) these allocations can be moved to the stack. A single pass was chosen because of concerns that heap temporaries are generated in many places within flang and so it would be difficult to maintain changes at all of those locations going forward. Data flow analysis is needed to detect cases where allocations may not always be freed, depending upon runtime control flow. The RFC provides a full documentation of the design.
Can you define the attr in the central place so we don't hardcode the name here and in the passes.
https://github.com/llvm/llvm-project/blob/main/flang/include/flang/Optimizer/Dialect/FIRAttr.h
or
https://github.com/llvm/llvm-project/blob/main/flang/include/flang/Optimizer/Dialect/FIRAttr.td