X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fcompiler%2Fdfo.lisp;h=3923da31f44b269cee39b71cf768df129c0434cb;hb=7b384da95e6a30e1434523213aeeed3a90448c78;hp=a135cd575e272a925cd287a2c4d3ee62dd910b60;hpb=863d1c0c3314d9002e511e9f98c00d9f0f9bfa78;p=sbcl.git diff --git a/src/compiler/dfo.lisp b/src/compiler/dfo.lisp index a135cd5..3923da3 100644 --- a/src/compiler/dfo.lisp +++ b/src/compiler/dfo.lisp @@ -22,7 +22,7 @@ (let ((head (component-head component))) (do () ((dolist (ep (block-succ head) t) - (unless (block-flag ep) + (unless (or (block-flag ep) (block-delete-p ep)) (find-dfo-aux ep head component) (return nil)))))) (let ((num 0)) @@ -30,10 +30,8 @@ (do-blocks-backwards (block component :both) (if (block-flag block) (setf (block-number block) (incf num)) - (setf (block-delete-p block) t))) - (do-blocks (block component) - (unless (block-flag block) - (delete-block block)))) + (delete-block-lazily block))) + (clean-component component (component-head component))) (values)) ;;; Move all the code and entry points from OLD to NEW. The code in @@ -59,7 +57,7 @@ (unless (eq old-next old-tail) (setf (block-next head) old-next) (setf (block-prev old-next) head) - + (setf (block-prev next) old-last) (setf (block-next old-last) next)) @@ -69,9 +67,10 @@ (setf (component-lambdas new) (nconc (component-lambdas old) (component-lambdas new))) (setf (component-lambdas old) nil) - (setf (component-new-funs new) (nconc (component-new-funs old) - (component-new-funs new)) - (component-new-funs old) nil) + (setf (component-new-functionals new) + (nconc (component-new-functionals old) + (component-new-functionals new))) + (setf (component-new-functionals old) nil) (dolist (xp (block-pred old-tail)) (unlink-blocks xp old-tail) @@ -88,10 +87,22 @@ (defun find-dfo-aux (block head component) (unless (eq (block-component block) component) (join-components component (block-component block))) - (unless (block-flag block) + (unless (or (block-flag block) (block-delete-p block)) (setf (block-flag block) t) (dolist (succ (block-succ block)) (find-dfo-aux succ head component)) + (when (component-nlx-info-generated-p component) + ;; FIXME: We also need (and do) this walk before physenv + ;; analysis, but at that time we are probably not very + ;; interested in the actual DF order. + ;; + ;; TODO: It is probable that one of successors have the same (or + ;; similar) set of NLXes; try to shorten the walk (but think + ;; about a loop, the only exit from which is non-local). + (map-block-nlxes (lambda (nlx-info) + (let ((nle (nlx-info-target nlx-info))) + (find-dfo-aux nle head component))) + block)) (remove-from-dfo block) (add-to-dfo block head)) (values)) @@ -100,7 +111,7 @@ ;;; before it walks the successors. It looks at the home CLAMBDA's ;;; BIND block to see whether that block is in some other component: ;;; -- If the block is in the initial component, then do -;;; DFO-WALK-DEPENDENCY-GRAPH on the home function to move it +;;; DFO-SCAVENGE-DEPENDENCY-GRAPH on the home function to move it ;;; into COMPONENT. ;;; -- If the block is in some other component, join COMPONENT into ;;; it and return that component. @@ -186,7 +197,7 @@ (res home)))) (res))) -;;; If CLAMBDA is not already in COMPONENT, just return that +;;; If CLAMBDA is already in COMPONENT, just return that ;;; component. Otherwise, move the code for CLAMBDA and all lambdas it ;;; physically depends on (either because of calls or because of ;;; closure relationships) into COMPONENT, or possibly into another @@ -198,13 +209,6 @@ ;;; oversight, not by design, as per the bug reported by WHN on ;;; cmucl-imp ca. 2001-11-29 and explained by DTC shortly after.) ;;; -;;; FIXME: Very likely we should be scavenging NLX-based dependencies -;;; here too. OTOH, there's a lot of global weirdness in NLX handling, -;;; so it might be taken care of some other way that I haven't figured -;;; out yet. Perhaps the best way to address this would be to try to -;;; construct a NLX-based test case which fails in the same way as the -;;; closure-based test case on cmucl-imp 2001-11-29.) -;;; ;;; If the function is in an initial component, then we move its head ;;; and tail to COMPONENT and add it to COMPONENT's lambdas. It is ;;; harmless to move the tail (even though the return might be @@ -256,28 +260,41 @@ (let ((res (find-initial-dfo-aux bind-block component))) (declare (type component res)) ;; Scavenge related lambdas. - (flet (;; Scavenge call relationship. - (scavenge-call (call) - (let ((call-home (lambda-home call))) - (setf res (dfo-scavenge-dependency-graph call-home res)))) - ;; Scavenge closure-over relationship: if FUN refers to a - ;; variable whose home lambda is not FUN, then the home lambda - ;; should be in the same component as FUN. (sbcl-0.6.13, and - ;; CMU CL, didn't do this, leading to the occasional failure - ;; when physenv analysis, which is local to each component, - ;; would bogusly conclude that a closed-over variable was - ;; unused and thus delete it. See e.g. cmucl-imp 2001-11-29.) - (scavenge-closure-var (var) - (unless (null (lambda-var-refs var)) ; i.e. unless deleted - (let ((var-home-home (lambda-home (lambda-var-home var)))) - (unless (eql (lambda-kind var-home-home) :deleted) - (setf res - (dfo-scavenge-dependency-graph var-home-home - res))))))) + (labels ((scavenge-lambda (clambda) + (setf res + (dfo-scavenge-dependency-graph (lambda-home clambda) + res))) + (scavenge-possibly-deleted-lambda (clambda) + (unless (eql (lambda-kind clambda) :deleted) + (scavenge-lambda clambda))) + ;; Scavenge call relationship. + (scavenge-call (called-lambda) + (scavenge-lambda called-lambda)) + ;; Scavenge closure over a variable: if CLAMBDA + ;; refers to a variable whose home lambda is not + ;; CLAMBDA, then the home lambda should be in the + ;; same component as CLAMBDA. (sbcl-0.6.13, and CMU + ;; CL, didn't do this, leading to the occasional + ;; failure when physenv analysis, which is local to + ;; each component, would bogusly conclude that a + ;; closed-over variable was unused and thus delete + ;; it. See e.g. cmucl-imp 2001-11-29.) + (scavenge-closure-var (var) + (unless (null (lambda-var-refs var)) ; unless var deleted + (let ((var-home-home (lambda-home (lambda-var-home var)))) + (scavenge-possibly-deleted-lambda var-home-home)))) + ;; Scavenge closure over an entry for nonlocal exit. + ;; This is basically parallel to closure over a + ;; variable above. + (scavenge-entry (entry) + (declare (type entry entry)) + (let ((entry-home (node-home-lambda entry))) + (scavenge-possibly-deleted-lambda entry-home)))) (dolist (cc (lambda-calls-or-closes clambda)) (etypecase cc (clambda (scavenge-call cc)) - (lambda-var (scavenge-closure-var cc)))) + (lambda-var (scavenge-closure-var cc)) + (entry (scavenge-entry cc)))) (when (eq (lambda-kind clambda) :external) (mapc #'scavenge-call (find-reference-funs clambda)))) ;; Voila. @@ -340,8 +357,8 @@ (values (real) (top) (real-top)))) -;; COMPONENTs want strings for names, LEAF-DEBUG-NAMEs mightn't be -;; strings.. +;;; COMPONENTs want strings for names, LEAF-DEBUG-NAMEs mightn't be +;;; strings... (defun component-name-from-functional-debug-name (functional) (declare (type functional functional)) (let ((leaf-debug-name (leaf-debug-name functional))) @@ -368,11 +385,10 @@ ;; an existing component if we find that there are references ;; between them. Any code that is left in an initial component ;; must be unreachable, so we can delete it. Stray links to the - ;; initial component tail (due NIL function terminated blocks) + ;; initial component tail (due to NIL function terminated blocks) ;; are moved to the appropriate new component tail. (dolist (toplevel-lambda toplevel-lambdas) - (let* ((block (lambda-block toplevel-lambda)) - (old-component (block-component block)) + (let* ((old-component (lambda-component toplevel-lambda)) (old-component-lambdas (component-lambdas old-component)) (new-component nil)) (aver (member toplevel-lambda old-component-lambdas)) @@ -439,7 +455,7 @@ ;; in the old LAMBDA into the new one (with LETs implicitly moved ;; by changing their home.) (do-blocks (block component) - (do-nodes (node cont block) + (do-nodes (node nil block) (let ((lexenv (node-lexenv node))) (when (eq (lexenv-lambda lexenv) lambda) (setf (lexenv-lambda lexenv) result-lambda)))) @@ -482,12 +498,9 @@ ;; is always a preceding REF NIL node in top level lambdas. (let ((return (lambda-return lambda))) (when return - (let ((return-block (node-block return)) - (result (return-result return))) - (setf (block-last return-block) (continuation-use result)) - (flush-dest result) - (delete-continuation result) - (link-blocks return-block result-return-block)))))) + (link-blocks (node-block return) result-return-block) + (flush-dest (return-result return)) + (unlink-node return))))) ;;; Given a non-empty list of top level LAMBDAs, smash them into a ;;; top level lambda and component, returning these as values. We use @@ -503,14 +516,9 @@ ;; Make sure the result's return node starts a block so that we ;; can splice code in before it. (let ((prev (node-prev - (continuation-use - (return-result result-return))))) - (when (continuation-use prev) - (node-ends-block (continuation-use prev))) - (do-uses (use prev) - (let ((new (make-continuation))) - (delete-continuation-use use) - (add-continuation-use use new)))) + (lvar-uses (return-result result-return))))) + (when (ctran-use prev) + (node-ends-block (ctran-use prev)))) (dolist (lambda (rest lambdas)) (merge-1-toplevel-lambda result-lambda lambda)))