(defun ir1-optimize (component)
(declare (type component component))
(setf (component-reoptimize component) nil)
- (do-blocks (block component)
- (cond
- ;; We delete blocks when there is either no predecessor or the
- ;; block is in a lambda that has been deleted. These blocks
- ;; would eventually be deleted by DFO recomputation, but doing
- ;; it here immediately makes the effect available to IR1
- ;; optimization.
- ((or (block-delete-p block)
- (null (block-pred block)))
- (delete-block block))
- ((eq (functional-kind (block-home-lambda block)) :deleted)
- ;; Preserve the BLOCK-SUCC invariant that almost every block has
- ;; one successor (and a block with DELETE-P set is an acceptable
- ;; exception).
- (mark-for-deletion block)
- (delete-block block))
- (t
- (loop
- (let ((succ (block-succ block)))
- (unless (singleton-p succ)
- (return)))
-
- (let ((last (block-last block)))
- (typecase last
- (cif
- (flush-dest (if-test last))
- (when (unlink-node last)
- (return)))
- (exit
- (when (maybe-delete-exit last)
- (return)))))
-
- (unless (join-successor-if-possible block)
- (return)))
-
- (when (and (block-reoptimize block) (block-component block))
- (aver (not (block-delete-p block)))
- (ir1-optimize-block block))
-
- (cond ((and (block-delete-p block) (block-component block))
- (delete-block block))
- ((and (block-flush-p block) (block-component block))
- (flush-dead-code block))))))
+ (loop with block = (block-next (component-head component))
+ with tail = (component-tail component)
+ for last-block = block
+ until (eq block tail)
+ do (cond
+ ;; We delete blocks when there is either no predecessor or the
+ ;; block is in a lambda that has been deleted. These blocks
+ ;; would eventually be deleted by DFO recomputation, but doing
+ ;; it here immediately makes the effect available to IR1
+ ;; optimization.
+ ((or (block-delete-p block)
+ (null (block-pred block)))
+ (delete-block-lazily block)
+ (setq block (clean-component component block)))
+ ((eq (functional-kind (block-home-lambda block)) :deleted)
+ ;; Preserve the BLOCK-SUCC invariant that almost every block has
+ ;; one successor (and a block with DELETE-P set is an acceptable
+ ;; exception).
+ (mark-for-deletion block)
+ (setq block (clean-component component block)))
+ (t
+ (loop
+ (let ((succ (block-succ block)))
+ (unless (singleton-p succ)
+ (return)))
+
+ (let ((last (block-last block)))
+ (typecase last
+ (cif
+ (flush-dest (if-test last))
+ (when (unlink-node last)
+ (return)))
+ (exit
+ (when (maybe-delete-exit last)
+ (return)))))
+
+ (unless (join-successor-if-possible block)
+ (return)))
+
+ (when (and (block-reoptimize block) (block-component block))
+ (aver (not (block-delete-p block)))
+ (ir1-optimize-block block))
+
+ (cond ((and (block-delete-p block) (block-component block))
+ (setq block (clean-component component block)))
+ ((and (block-flush-p block) (block-component block))
+ (flush-dead-code block)))))
+ do (when (eq block last-block)
+ (setq block (block-next block))))
(values))
(lambda-tail-set (combination-lambda use))))
(when (combination-p use)
(when (nth-value 1 (maybe-convert-tail-local-call use))
- (return-from find-result-type (values)))))
+ (return-from find-result-type t))))
(t
(use-union (node-derived-type use))))))
(let ((int
;; )
))
(setf (return-result-type node) int))))
- (values))
+ nil)
;;; Do stuff to realize that something has changed about the value
;;; delivered to a return node. Since we consider the return values of
;;; results of the calls.
(defun ir1-optimize-return (node)
(declare (type creturn node))
- (let* ((tails (lambda-tail-set (return-lambda node)))
- (funs (tail-set-funs tails)))
- (collect ((res *empty-type* values-type-union))
- (dolist (fun funs)
- (let ((return (lambda-return fun)))
- (when return
- (when (node-reoptimize return)
- (setf (node-reoptimize return) nil)
- (find-result-type return))
- (res (return-result-type return)))))
-
- (when (type/= (res) (tail-set-type tails))
- (setf (tail-set-type tails) (res))
- (dolist (fun (tail-set-funs tails))
- (dolist (ref (leaf-refs fun))
- (reoptimize-lvar (node-lvar ref)))))))
+ (tagbody
+ :restart
+ (let* ((tails (lambda-tail-set (return-lambda node)))
+ (funs (tail-set-funs tails)))
+ (collect ((res *empty-type* values-type-union))
+ (dolist (fun funs)
+ (let ((return (lambda-return fun)))
+ (when return
+ (when (node-reoptimize return)
+ (setf (node-reoptimize return) nil)
+ (when (find-result-type return)
+ (go :restart)))
+ (res (return-result-type return)))))
+
+ (when (type/= (res) (tail-set-type tails))
+ (setf (tail-set-type tails) (res))
+ (dolist (fun (tail-set-funs tails))
+ (dolist (ref (leaf-refs fun))
+ (reoptimize-lvar (node-lvar ref))))))))
(values))
\f
(set-use (principal-lvar-use (set-value set)))
(() (and (combination-p set-use)
(fun-info-p (combination-kind set-use))
+ (not (node-to-be-deleted-p set-use))
(eq (combination-fun-source-name set-use) '+))
:exit-if-null)
(+-args (basic-combination-args set-use))
(unlink-node call)
(unlink-node (lambda-bind clambda))
(setf (lambda-bind clambda) nil))
+ (setf (functional-kind clambda) :zombie)
+ (let ((home (lambda-home clambda)))
+ (setf (lambda-lets home) (delete clambda (lambda-lets home))))
(values))
;;; This function is called when one of the arguments to a LET
(deftransform values ((&rest vals) * * :node node)
(unless (lvar-single-value-p (node-lvar node))
(give-up-ir1-transform))
- (setf (node-derived-type node) *wild-type*)
+ (setf (node-derived-type node)
+ (make-short-values-type (list (single-value-type
+ (node-derived-type node)))))
(principal-lvar-single-valuify (node-lvar node))
(if vals
(let ((dummies (make-gensym-list (length (cdr vals)))))
(maybe-terminate-block (lvar-uses value) nil)
;; FIXME: Is it necessary?
(aver (null (block-pred (node-block cast))))
- (setf (block-delete-p (node-block cast)) t)
+ (delete-block-lazily (node-block cast))
(return-from ir1-optimize-cast)))
(when (eq (node-derived-type cast) *empty-type*)
(maybe-terminate-block cast nil))