-;;; Do a backward walk in the flow graph simulating the run-time stack of
-;;; unknown-values continuations and annotating the blocks with the result.
-;;;
-;;; Block is the block that is currently being walked and Stack is the stack
-;;; of unknown-values continuations in effect immediately after block. We
-;;; simulate the stack by popping off the unknown-values generated by this
-;;; block (if any) and pushing the continuations for values received by this
-;;; block. (The role of push and pop are interchanged because we are doing a
-;;; backward walk.)
-;;;
-;;; If we run into a values generator whose continuation isn't on stack top,
-;;; then the receiver hasn't yet been reached on any walk to this use. In this
-;;; case, we ignore the push for now, counting on Annotate-Dead-Values to clean
-;;; it up if we discover that it isn't reachable at all.
-;;;
-;;; If our final stack isn't empty, then we walk all the predecessor blocks
-;;; that don't have all the continuations that we have on our Start-Stack on
-;;; their End-Stack. This is our termination condition for the graph walk. We
-;;; put the test around the recursive call so that the initial call to this
-;;; function will do something even though there isn't initially anything on
-;;; the stack.
-;;;
-;;; We can use the tailp test, since the only time we want to bottom out
-;;; with a non-empty stack is when we intersect with another path from the same
-;;; top-level call to this function that has more values receivers on that
-;;; path. When we bottom out in this way, we are counting on
-;;; DISCARD-UNUSED-VALUES doing its thing.
-;;;
-;;; When we do recurse, we check that predecessor's END-STACK is a
-;;; subsequence of our START-STACK. There may be extra stuff on the top
-;;; of our stack because the last path to the predecessor may have discarded
-;;; some values that we use. There may be extra stuff on the bottom of our
-;;; stack because this walk may be from a values receiver whose lifetime
-;;; encloses that of the previous walk.
-;;;
-;;; If a predecessor block is the component head, then it must be the case
-;;; that this is a NLX entry stub. If so, we just stop our walk, since the
-;;; stack at the exit point doesn't have anything to do with our stack.
-(defun stack-simulation-walk (block stack)
- (declare (type cblock block) (list stack))
- (let ((2block (block-info block)))
- (setf (ir2-block-end-stack 2block) stack)
- (let ((new-stack stack))
- (dolist (push (reverse (ir2-block-pushed 2block)))
- (if (eq (car new-stack) push)
- (pop new-stack)
- (assert (not (member push new-stack)))))