X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fdfo.lisp;h=a22339d662d44c5cfc2a8cdbdc006c7f62dd2c69;hb=34dd23563d2f5cf05c72b971da0d0b065a09bf2a;hp=8ce81ad0736dd07560daf4811a37cd78b9ae30eb;hpb=299ef6dbeb0d2fb12da586d89ee21971693489fa;p=sbcl.git diff --git a/src/compiler/dfo.lisp b/src/compiler/dfo.lisp index 8ce81ad..a22339d 100644 --- a/src/compiler/dfo.lisp +++ b/src/compiler/dfo.lisp @@ -69,9 +69,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) @@ -100,7 +101,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,41 +187,34 @@ (res home)))) (res))) -;;; If FUN is not already in COMPONENT, just return that component. -;;; Otherwise, move the code for FUN and all functions it physically -;;; depends on (either because of calls or because of closure -;;; relationships) into COMPONENT, or possibly into another COMPONENT -;;; that we find to be related. Return whatever COMPONENT we actually -;;; merged into. +;;; If CLAMBDA is not 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 +;;; COMPONENT that we find to be related. Return whatever COMPONENT we +;;; actually merged into. ;;; ;;; (Note: The analogous CMU CL code only scavenged call-based ;;; dependencies, not closure dependencies. That seems to've been by ;;; 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 ;;; unreachable) because if the return is unreachable it (and its ;;; successor link) will be deleted in the post-deletion pass. ;;; -;;; We then do a FIND-DFO-AUX starting at the head of FUN. If this +;;; We then do a FIND-DFO-AUX starting at the head of CLAMBDA. If this ;;; flow-graph walk encounters another component (which can only ;;; happen due to a non-local exit), then we move code into that ;;; component instead. We then recurse on all functions called from -;;; FUN, moving code into whichever component the preceding call +;;; CLAMBDA, moving code into whichever component the preceding call ;;; returned. ;;; -;;; If FUN is in the initial component, but the BLOCK-FLAG is set in -;;; the bind block, then we just return COMPONENT, since we must have -;;; already reached this function in the current walk (or the +;;; If CLAMBDA is in the initial component, but the BLOCK-FLAG is set +;;; in the bind block, then we just return COMPONENT, since we must +;;; have already reached this function in the current walk (or the ;;; component would have been changed). ;;; ;;; If the function is an XEP, then we also walk all functions that @@ -229,11 +223,12 @@ ;;; ensures that conversion of a full call to a local call won't ;;; result in a need to join components, since the components will ;;; already be one. -(defun dfo-scavenge-dependency-graph (fun component) - (declare (type clambda fun) (type component component)) - (let* ((bind-block (node-block (lambda-bind fun))) +(defun dfo-scavenge-dependency-graph (clambda component) + (declare (type clambda clambda) (type component component)) + (assert (not (eql (lambda-kind clambda) :deleted))) + (let* ((bind-block (node-block (lambda-bind clambda))) (old-lambda-component (block-component bind-block)) - (return (lambda-return fun))) + (return (lambda-return clambda))) (cond ((eq old-lambda-component component) component) @@ -243,9 +238,9 @@ ((block-flag bind-block) component) (t - (push fun (component-lambdas component)) + (push clambda (component-lambdas component)) (setf (component-lambdas old-lambda-component) - (delete fun (component-lambdas old-lambda-component))) + (delete clambda (component-lambdas old-lambda-component))) (link-blocks (component-head component) bind-block) (unlink-blocks (component-head old-lambda-component) bind-block) (when return @@ -254,24 +249,53 @@ (unlink-blocks return-block (component-tail old-lambda-component)))) (let ((res (find-initial-dfo-aux bind-block component))) (declare (type component res)) - ;; Scavenge call relationships. - (let ((calls (if (eq (functional-kind fun) :external) - (append (find-reference-funs fun) - (lambda-calls fun)) - (lambda-calls fun)))) - (dolist (call calls) - (setf res (dfo-scavenge-dependency-graph call res)))) - ;; TO DO: Scavenge closure-over relationships. - (values) + ;; Scavenge related lambdas. + (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)) + (entry (scavenge-entry cc)))) + (when (eq (lambda-kind clambda) :external) + (mapc #'scavenge-call (find-reference-funs clambda)))) ;; Voila. res))))) -;;; Return true if FUN either is an XEP or has EXITS to some of its -;;; ENTRIES. -(defun has-xep-or-nlx (fun) - (declare (type clambda fun)) - (or (eq (functional-kind fun) :external) - (let ((entries (lambda-entries fun))) +;;; Return true if CLAMBDA either is an XEP or has EXITS to some of +;;; its ENTRIES. +(defun has-xep-or-nlx (clambda) + (declare (type clambda clambda)) + (or (eq (functional-kind clambda) :external) + (let ((entries (lambda-entries clambda))) (and entries (find-if #'entry-exits entries))))) @@ -354,8 +378,7 @@ ;; initial component tail (due 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))