[flang] support fir.unreachable in stack arrays pass
authorTom Eccles <tom.eccles@arm.com>
Mon, 13 Feb 2023 15:45:47 +0000 (15:45 +0000)
committerTom Eccles <tom.eccles@arm.com>
Tue, 14 Feb 2023 13:44:59 +0000 (13:44 +0000)
commit7a49d50f22ad577d91cda7904c8a162c2cecd4a8
treeb5bfe0ffb2a729f8ac8f06181ef1e6c98c41a81a
parenteb436da6b8269407e03b6954319de77a082f4adf
[flang] support fir.unreachable in stack arrays pass

Some functions (e.g. the main function) end with a call to the STOP
statement instead of a func.return. This is lowered as a call to the
stop runtime function followed by a fir.unreachable. fir.unreachable is
a terminator and so this can cause functions to have no func.return.

The stack arrays pass looks to see which heap allocations have always
been freed by the time a function returns. Without any returns, the pass
does not detect any freed allocations. This patch changes this behaviour
so that fir.unreachable is checked as well as func.return.

This allows 15 heap allocations for array temporaries in spec2017
exchange2's main function to be moved to the stack.

Differential Revision: https://reviews.llvm.org/D143918
flang/lib/Optimizer/Transforms/StackArrays.cpp
flang/test/Transforms/stack-arrays.fir