Fold what DCE does into FIND-DFO.
commit110cfb18bd0279fef67df83b1c1bf8e60769d33b
authorCharles Zhang <charleszhang99@yahoo.com>
Mon, 28 Aug 2023 22:01:48 +0000 (29 00:01 +0200)
committerCharles Zhang <charleszhang99@yahoo.com>
Mon, 28 Aug 2023 22:54:45 +0000 (29 00:54 +0200)
tree0acc2fa8adc3d4169588cd179f95995cd193da41
parentb1b6cfea3130796ddb85fc65c5479d0d03289ed5
Fold what DCE does into FIND-DFO.

DCE was essentially FIND-DFO with a stricter definition of reachable
for entry points. So we were doing a lot of repeated graph walking. We
can just make FIND-DFO use the definition of entry point reachability
that eliminate-dead-code used to achieve the same effect. This has a
number of speed advantages:

* We don't need to walk every node in the graph: FIND-DFO works with
just basic blocks.

* The graph isn't walked at all when nothing in the DFO has changed.

* The entry points are now also forced to be "sorted": entry points
which are only accessible from other entry points have lower DFNs,
which means that intraprocedural things like type propagation through
local calls might converge faster when iterating in DF order.

There is one potential performance caveat though: We take advantage of
the fact that FIND-DFO does iteration to properly compute the set of
reached entry points. However, this may in the worst case cause a
linear number of iterations to fixpoint with respect to the maximum
entry point nesting depth (an entry point being nested if its only
accessible from another entry point), so a quadratic number of total
iterations over the component's lambdas in terms of this nesting
depth. This doesn't happen in practice, probably because nested
lambdas sorted in the worst possible way just doesn't happen due to
the way IR is converted. When instrumenting self-build, it's actually
the case that the top-level DO in FIND-DFO does either the same or
one *less* iteration (probably due to dead :OPTIONAL entries) when
checking for entry point reachability. So finding new blocks in the
component seems to overshadow any theoretical worst-case lambda
nesting concerns.
src/cold/build-order.lisp-expr
src/compiler/dce.lisp [deleted file]
src/compiler/dfo.lisp
src/compiler/main.lisp