X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fnode.lisp;h=4439b79e1b9848a8658ebab9ff5a0bed017f8f42;hb=5ecef987f3847ed5de8c03f66ef9d8ab468af993;hp=0025ca5d998d6315b475a6387655e0f860141cfa;hpb=6053e7f804b430144bb09e2d107ad4ab3fb97db4;p=sbcl.git diff --git a/src/compiler/node.lisp b/src/compiler/node.lisp index 0025ca5..4439b79 100644 --- a/src/compiler/node.lisp +++ b/src/compiler/node.lisp @@ -53,7 +53,7 @@ (def!method print-object ((x ctran) stream) (print-unreadable-object (x stream :type t :identity t) - (format stream " #~D" (cont-num x)))) + (format stream "~D" (cont-num x)))) ;;; Linear VARiable. Multiple-value (possibly of unknown number) ;;; temporal storage. @@ -76,15 +76,17 @@ ;; Cached type which is checked by DEST. If NIL, then this must be ;; recomputed: see LVAR-EXTERNALLY-CHECKABLE-TYPE. (%externally-checkable-type nil :type (or null ctype)) + ;; if the LVAR value is DYNAMIC-EXTENT, CLEANUP protecting it. + (dynamic-extent nil :type (or null cleanup)) ;; something or other that the back end annotates this lvar with (info nil)) (def!method print-object ((x lvar) stream) (print-unreadable-object (x stream :type t :identity t) - (format stream " #~D" (cont-num x)))) + (format stream "~D" (cont-num x)))) -(defstruct (node (:constructor nil) - (:copier nil)) +(def!struct (node (:constructor nil) + (:copier nil)) ;; unique ID for debugging #!+sb-show (id (new-object-id) :read-only t) ;; True if this node needs to be optimized. This is set to true @@ -134,10 +136,10 @@ ;; can null out this slot. (tail-p nil :type boolean)) -(defstruct (valued-node (:conc-name node-) - (:include node) - (:constructor nil) - (:copier nil)) +(def!struct (valued-node (:conc-name node-) + (:include node) + (:constructor nil) + (:copier nil)) ;; the bottom-up derived type for this node. (derived-type *wild-type* :type ctype) ;; Lvar, receiving the values, produced by this node. May be NIL if @@ -189,11 +191,11 @@ ;;; order. This latter numbering also forms the basis of the block ;;; numbering in the debug-info (though that is relative to the start ;;; of the function.) -(defstruct (cblock (:include sset-element) - (:constructor make-block (start)) - (:constructor make-block-key) - (:conc-name block-) - (:predicate block-p)) +(def!struct (cblock (:include sset-element) + (:constructor make-block (start)) + (:constructor make-block-key) + (:conc-name block-) + (:predicate block-p)) ;; a list of all the blocks that are predecessors/successors of this ;; block. In well-formed IR1, most blocks will have one successor. ;; The only exceptions are: @@ -225,6 +227,13 @@ (gen nil) (in nil) (out nil) + ;; Set of all blocks that dominate this block. NIL is interpreted + ;; as "all blocks in component". + (dominators nil :type (or null sset)) + ;; the LOOP that this block belongs to + (loop nil :type (or null cloop)) + ;; next block in the loop. + (loop-next nil :type (or null cblock)) ;; the component this block is in, or NIL temporarily during IR1 ;; conversion and in deleted blocks (component (progn @@ -250,8 +259,8 @@ ;;; The BLOCK-ANNOTATION class is inherited (via :INCLUDE) by ;;; different BLOCK-INFO annotation structures so that code ;;; (specifically control analysis) can be shared. -(defstruct (block-annotation (:constructor nil) - (:copier nil)) +(def!struct (block-annotation (:constructor nil) + (:copier nil)) ;; The IR1 block that this block is in the INFO for. (block (missing-arg) :type cblock) ;; the next and previous block in emission order (not DFO). This @@ -272,9 +281,13 @@ ;;; size of flow analysis problems, this allows back-end data ;;; structures to be reclaimed after the compilation of each ;;; component. -(defstruct (component (:copier nil) - (:constructor - make-component (head tail &aux (last-block tail)))) +(def!struct (component (:copier nil) + (:constructor + make-component + (head + tail &aux + (last-block tail) + (outer-loop (make-loop :kind :outer :head head))))) ;; unique ID for debugging #!+sb-show (id (new-object-id) :read-only t) ;; the kind of component @@ -339,14 +352,15 @@ ;; Between runs of local call analysis there may be some debris of ;; converted or even deleted functions in this list. (new-functionals () :type list) - ;; If this is true, then there is stuff in this component that could - ;; benefit from further IR1 optimization. - (reoptimize t :type boolean) + ;; If this is :MAYBE, then there is stuff in this component that + ;; could benefit from further IR1 optimization. T means that + ;; reoptimization is necessary. + (reoptimize t :type (member nil :maybe t)) ;; If this is true, then the control flow in this component was ;; messed up by IR1 optimizations, so the DFO should be recomputed. (reanalyze nil :type boolean) ;; some sort of name for the code in this component - (name "" :type simple-string) + (name "" :type t) ;; When I am a child, this is :NO-IR2-YET. ;; In my adulthood, IR2 stores notes to itself here. ;; After I have left the great wheel and am staring into the GC, this @@ -372,7 +386,13 @@ ;; has already been analyzed, but new references have been added by ;; inline expansion. Unlike NEW-FUNCTIONALS, this is not disjoint ;; from COMPONENT-LAMBDAS. - (reanalyze-functionals nil :type list)) + (reanalyze-functionals nil :type list) + (delete-blocks nil :type list) + (nlx-info-generated-p nil :type boolean) + ;; this is filled by physical environment analysis + (dx-lvars nil :type list) + ;; The default LOOP in the component. + (outer-loop (missing-arg) :type cloop)) (defprinter (component :identity t) name #!+sb-show id @@ -419,21 +439,32 @@ ;;; boundaries by requiring that the exit ctrans initially head their ;;; blocks, and then by not merging blocks when there is a cleanup ;;; change. -(defstruct (cleanup (:copier nil)) +(def!struct (cleanup (:copier nil)) ;; the kind of thing that has to be cleaned up (kind (missing-arg) - :type (member :special-bind :catch :unwind-protect :block :tagbody)) + :type (member :special-bind :catch :unwind-protect + :block :tagbody :dynamic-extent)) ;; the node that messes things up. This is the last node in the ;; non-messed-up environment. Null only temporarily. This could be ;; deleted due to unreachability. (mess-up nil :type (or node null)) - ;; a list of all the NLX-INFO structures whose NLX-INFO-CLEANUP is - ;; this cleanup. This is filled in by physical environment analysis. - (nlx-info nil :type list)) + ;; For all kinds, except :DYNAMIC-EXTENT: a list of all the NLX-INFO + ;; structures whose NLX-INFO-CLEANUP is this cleanup. This is filled + ;; in by physical environment analysis. + ;; + ;; For :DYNAMIC-EXTENT: a list of all DX LVARs, preserved by this + ;; cleanup. This is filled when the cleanup is created (now by + ;; locall call analysis) and is rechecked by physical environment + ;; analysis. (For closures this is a list of the allocating node - + ;; during IR1, and a list of the argument LVAR of the allocator - + ;; after physical environment analysis.) + (info nil :type list)) (defprinter (cleanup :identity t) kind mess-up - (nlx-info :test nlx-info)) + (info :test info)) +(defmacro cleanup-nlx-info (cleanup) + `(cleanup-info ,cleanup)) ;;; A PHYSENV represents the result of physical environment analysis. ;;; @@ -457,7 +488,7 @@ ;;; structure is attached to INFO and used to keep track of ;;; associations between these names and less-abstract things (like ;;; TNs, or eventually stack slots and registers). -- WHN 2001-09-29 -(defstruct (physenv (:copier nil)) +(def!struct (physenv (:copier nil)) ;; the function that allocates this physical environment (lambda (missing-arg) :type clambda :read-only t) ;; This ultimately converges to a list of all the LAMBDA-VARs and @@ -491,7 +522,7 @@ ;;; The tail set is somewhat approximate, because it is too early to ;;; be sure which calls will be tail-recursive. Any call that *might* ;;; end up tail-recursive causes TAIL-SET merging. -(defstruct (tail-set) +(def!struct (tail-set) ;; a list of all the LAMBDAs in this tail set (funs nil :type list) ;; our current best guess of the type returned by these functions. @@ -509,37 +540,42 @@ ;;; non-local exits. This is effectively an annotation on the ;;; continuation, although it is accessed by searching in the ;;; PHYSENV-NLX-INFO. -(def!struct (nlx-info (:constructor make-nlx-info - (cleanup exit &aux (lvar (node-lvar exit)))) - (:make-load-form-fun ignore-it)) +(def!struct (nlx-info + (:constructor make-nlx-info (cleanup + exit + &aux + (block (first (block-succ + (node-block exit)))))) + (:make-load-form-fun ignore-it)) ;; the cleanup associated with this exit. In a catch or ;; unwind-protect, this is the :CATCH or :UNWIND-PROTECT cleanup, ;; and not the cleanup for the escape block. The CLEANUP-KIND of ;; this thus provides a good indication of what kind of exit is ;; being done. (cleanup (missing-arg) :type cleanup) - ;; the continuation exited to (the CONT of the EXIT nodes). If this - ;; exit is from an escape function (CATCH or UNWIND-PROTECT), then - ;; physical environment analysis deletes the escape function and - ;; instead has the %NLX-ENTRY use this continuation. + ;; the ``continuation'' exited to (the block, succeeding the EXIT + ;; nodes). If this exit is from an escape function (CATCH or + ;; UNWIND-PROTECT), then physical environment analysis deletes the + ;; escape function and instead has the %NLX-ENTRY use this + ;; continuation. ;; - ;; This slot is primarily an indication of where this exit delivers - ;; its values to (if any), but it is also used as a sort of name to - ;; allow us to find the NLX-INFO that corresponds to a given exit. - ;; For this purpose, the ENTRY must also be used to disambiguate, - ;; since exits to different places may deliver their result to the - ;; same continuation. - (exit (missing-arg) :type exit) - (lvar (missing-arg) :type (or lvar null)) + ;; This slot is used as a sort of name to allow us to find the + ;; NLX-INFO that corresponds to a given exit. For this purpose, the + ;; ENTRY must also be used to disambiguate, since exits to different + ;; places may deliver their result to the same continuation. + (block (missing-arg) :type cblock) ;; the entry stub inserted by physical environment analysis. This is ;; a block containing a call to the %NLX-ENTRY funny function that ;; has the original exit destination as its successor. Null only ;; temporarily. (target nil :type (or cblock null)) + ;; for a lexical exit it determines whether tag existence check is + ;; needed + (safe-p nil :type boolean) ;; some kind of info used by the back end info) (defprinter (nlx-info :identity t) - exit + block target info) @@ -592,6 +628,8 @@ ;; true if there was ever a REF or SET node for this leaf. This may ;; be true when REFS and SETS are null, since code can be deleted. (ever-used nil :type boolean) + ;; is it declared dynamic-extent? + (dynamic-extent nil :type boolean) ;; some kind of info used by the back end (info nil)) @@ -694,18 +732,6 @@ ;; or not, as if it is a valid function name then it can look for an ;; inline expansion. ;; - ;; The value of this slot can be anything, except that it shouldn't - ;; be a legal function name, since otherwise debugging gets - ;; confusing. (If a legal function name is a good name for the - ;; function, it should be in %SOURCE-NAME, and then we shouldn't - ;; need a %DEBUG-NAME.) In SBCL as of 0.pre7.87, it's always a - ;; string unless it's NIL, since that's how CMU CL represented debug - ;; names. However, eventually I (WHN) think it we should start using - ;; list values instead, since they have much nicer print properties - ;; (abbreviation, skipping package prefixes when unneeded, and - ;; renaming package prefixes when we do things like renaming SB!EXT - ;; to SB-EXT). - ;; ;; E.g. for the function which implements (DEFUN FOO ...), we could ;; have ;; %SOURCE-NAME=FOO @@ -713,17 +739,17 @@ ;; for the function which implements the top level form ;; (IN-PACKAGE :FOO) we could have ;; %SOURCE-NAME=NIL - ;; %DEBUG-NAME="top level form (IN-PACKAGE :FOO)" + ;; %DEBUG-NAME=(TOP-LEVEL-FORM (IN-PACKAGE :FOO) ;; for the function which implements FOO in ;; (DEFUN BAR (...) (FLET ((FOO (...) ...)) ...)) ;; we could have ;; %SOURCE-NAME=FOO - ;; %DEBUG-NAME="FLET FOO in BAR" + ;; %DEBUG-NAME=(FLET FOO) ;; and for the function which implements FOO in ;; (DEFMACRO FOO (...) ...) ;; we could have ;; %SOURCE-NAME=FOO (or maybe .ANONYMOUS.?) - ;; %DEBUG-NAME="DEFMACRO FOO" + ;; %DEBUG-NAME=(MACRO-FUNCTION FOO) (%debug-name nil :type (or null (not (satisfies legal-fun-name-p))) :read-only t) @@ -784,9 +810,12 @@ ;; :DELETED ;; This function has been found to be uncallable, and has been ;; marked for deletion. + ;; + ;; :ZOMBIE + ;; Effectless [MV-]LET; has no BIND node. (kind nil :type (member nil :optional :deleted :external :toplevel :escape :cleanup :let :mv-let :assignment - :toplevel-xep)) + :zombie :toplevel-xep)) ;; Is this a function that some external entity (e.g. the fasl dumper) ;; refers to, so that even when it appears to have no references, it ;; shouldn't be deleted? In the old days (before @@ -821,6 +850,9 @@ ;; the original function or macro lambda list, or :UNSPECIFIED if ;; this is a compiler created function (arg-documentation nil :type (or list (member :unspecified))) + ;; Node, allocating closure for this lambda. May be NIL when we are + ;; sure that no closure is needed. + (allocator nil :type (or null combination)) ;; various rare miscellaneous info that drives code generation & stuff (plist () :type list)) (defprinter (functional :identity t) @@ -918,11 +950,15 @@ ;; retain it so that if the LET is deleted (due to a lack of vars), ;; we will still have caller's lexenv to figure out which cleanup is ;; in effect. - (call-lexenv nil :type (or lexenv null))) + (call-lexenv nil :type (or lexenv null)) + ;; list of embedded lambdas + (children nil :type list) + (parent nil :type (or clambda null))) (defprinter (clambda :conc-name lambda- :identity t) %source-name %debug-name #!+sb-show id + kind (type :test (not (eq type *universal-type*))) (where-from :test (not (eq where-from :assumed))) (vars :prin1 (mapcar #'leaf-source-name vars))) @@ -1083,13 +1119,13 @@ ;;; A REF represents a reference to a LEAF. REF-REOPTIMIZE is ;;; initially (and forever) NIL, since REFs don't receive any values ;;; and don't have any IR1 optimizer. -(defstruct (ref (:include valued-node (reoptimize nil)) - (:constructor make-ref - (leaf - &aux (leaf-type (leaf-type leaf)) - (derived-type - (make-single-value-type leaf-type)))) - (:copier nil)) +(def!struct (ref (:include valued-node (reoptimize nil)) + (:constructor make-ref + (leaf + &aux (leaf-type (leaf-type leaf)) + (derived-type + (make-single-value-type leaf-type)))) + (:copier nil)) ;; The leaf referenced. (leaf nil :type leaf)) (defprinter (ref :identity t) @@ -1097,11 +1133,11 @@ leaf) ;;; Naturally, the IF node always appears at the end of a block. -(defstruct (cif (:include node) - (:conc-name if-) - (:predicate if-p) - (:constructor make-if) - (:copier copy-if)) +(def!struct (cif (:include node) + (:conc-name if-) + (:predicate if-p) + (:constructor make-if) + (:copier copy-if)) ;; LVAR for the predicate (test (missing-arg) :type lvar) ;; the blocks that we execute next in true and false case, @@ -1113,13 +1149,13 @@ consequent alternative) -(defstruct (cset (:include valued-node +(def!struct (cset (:include valued-node (derived-type (make-single-value-type *universal-type*))) - (:conc-name set-) - (:predicate set-p) - (:constructor make-set) - (:copier copy-set)) + (:conc-name set-) + (:predicate set-p) + (:constructor make-set) + (:copier copy-set)) ;; descriptor for the variable set (var (missing-arg) :type basic-var) ;; LVAR for the value form @@ -1132,9 +1168,9 @@ ;;; and multiple value combinations. In a let-like function call, this ;;; node appears at the end of its block and the body of the called ;;; function appears as the successor; the NODE-LVAR is null. -(defstruct (basic-combination (:include valued-node) - (:constructor nil) - (:copier nil)) +(def!struct (basic-combination (:include valued-node) + (:constructor nil) + (:copier nil)) ;; LVAR for the function (fun (missing-arg) :type lvar) ;; list of LVARs for the args. In a local call, an argument lvar may @@ -1143,22 +1179,25 @@ (args nil :type list) ;; the kind of function call being made. :LOCAL means that this is a ;; local call to a function in the same component, and that argument - ;; syntax checking has been done, etc. Calls to known global - ;; functions are represented by storing the FUN-INFO for the - ;; function in this slot. :FULL is a call to an (as yet) unknown - ;; function. :ERROR is like :FULL, but means that we have discovered - ;; that the call contains an error, and should not be reconsidered - ;; for optimization. - (kind :full :type (or (member :local :full :error) fun-info)) + ;; syntax checking has been done, etc. Calls to known global + ;; functions are represented by storing :KNOWN in this slot and the + ;; FUN-INFO for that function in the FUN-INFO slot. :FULL is a call + ;; to an (as yet) unknown function, or to a known function declared + ;; NOTINLINE. :ERROR is like :FULL, but means that we have + ;; discovered that the call contains an error, and should not be + ;; reconsidered for optimization. + (kind :full :type (member :local :full :error :known)) + ;; if a call to a known global function, contains the FUN-INFO. + (fun-info nil :type (or fun-info null)) ;; some kind of information attached to this node by the back end (info nil)) ;;; The COMBINATION node represents all normal function calls, ;;; including FUNCALL. This is distinct from BASIC-COMBINATION so that ;;; an MV-COMBINATION isn't COMBINATION-P. -(defstruct (combination (:include basic-combination) - (:constructor make-combination (fun)) - (:copier nil))) +(def!struct (combination (:include basic-combination) + (:constructor make-combination (fun)) + (:copier nil))) (defprinter (combination :identity t) #!+sb-show id (fun :prin1 (lvar-uses fun)) @@ -1168,28 +1207,20 @@ "")) args))) -(defun call-full-like-p (call) - (declare (type combination call)) - (let ((kind (basic-combination-kind call))) - (or (eq kind :full) - (and (fun-info-p kind) - (null (fun-info-templates kind)) - (not (fun-info-ir2-convert kind)))))) - ;;; An MV-COMBINATION is to MULTIPLE-VALUE-CALL as a COMBINATION is to ;;; FUNCALL. This is used to implement all the multiple-value ;;; receiving forms. -(defstruct (mv-combination (:include basic-combination) - (:constructor make-mv-combination (fun)) - (:copier nil))) +(def!struct (mv-combination (:include basic-combination) + (:constructor make-mv-combination (fun)) + (:copier nil))) (defprinter (mv-combination) (fun :prin1 (lvar-uses fun)) (args :prin1 (mapcar #'lvar-uses args))) ;;; The BIND node marks the beginning of a lambda body and represents ;;; the creation and initialization of the variables. -(defstruct (bind (:include node) - (:copier nil)) +(def!struct (bind (:include node) + (:copier nil)) ;; the lambda we are binding variables for. Null when we are ;; creating the LAMBDA during IR1 translation. (lambda nil :type (or clambda null))) @@ -1200,11 +1231,11 @@ ;;; return values and represents the control transfer on return. This ;;; is also where we stick information used for TAIL-SET type ;;; inference. -(defstruct (creturn (:include node) - (:conc-name return-) - (:predicate return-p) - (:constructor make-return) - (:copier copy-return)) +(def!struct (creturn (:include node) + (:conc-name return-) + (:predicate return-p) + (:constructor make-return) + (:copier copy-return)) ;; the lambda we are returning from. Null temporarily during ;; ir1tran. (lambda nil :type (or clambda null)) @@ -1222,8 +1253,8 @@ ;;; The CAST node represents type assertions. The check for ;;; TYPE-TO-CHECK is performed and then the VALUE is declared to be of ;;; type ASSERTED-TYPE. -(defstruct (cast (:include valued-node) - (:constructor %make-cast)) +(def!struct (cast (:include valued-node) + (:constructor %make-cast)) (asserted-type (missing-arg) :type ctype) (type-to-check (missing-arg) :type ctype) ;; an indication of what we have proven about how this type @@ -1232,9 +1263,12 @@ ;; NIL ;; No type check is necessary (VALUE type is a subtype of the TYPE-TO-CHECK.) ;; + ;; :EXTERNAL + ;; Type check will be performed by NODE-DEST. + ;; ;; T ;; A type check is needed. - (%type-check t :type (member t nil)) + (%type-check t :type (member t :external nil)) ;; the lvar which is checked (value (missing-arg) :type lvar)) (defprinter (cast :identity t) @@ -1251,8 +1285,8 @@ ;;; The ENTRY node serves to mark the start of the dynamic extent of a ;;; lexical exit. It is the mess-up node for the corresponding :ENTRY ;;; cleanup. -(defstruct (entry (:include node) - (:copier nil)) +(def!struct (entry (:include node) + (:copier nil)) ;; All of the EXIT nodes for potential non-local exits to this point. (exits nil :type list) ;; The cleanup for this entry. NULL only temporarily. @@ -1265,9 +1299,10 @@ ;;; continuation and the exit continuation's DEST. Instead of using ;;; the returned value being delivered directly to the exit ;;; continuation, it is delivered to our VALUE lvar. The original exit -;;; lvar is the exit node's LVAR. -(defstruct (exit (:include valued-node) - (:copier nil)) +;;; lvar is the exit node's LVAR; physenv analysis also makes it the +;;; lvar of %NLX-ENTRY call. +(def!struct (exit (:include valued-node) + (:copier nil)) ;; the ENTRY node that this is an exit for. If null, this is a ;; degenerate exit. A degenerate exit is used to "fill" an empty ;; block (which isn't allowed in IR1.) In a degenerate exit, Value @@ -1275,7 +1310,8 @@ (entry nil :type (or entry null)) ;; the lvar yielding the value we are to exit with. If NIL, then no ;; value is desired (as in GO). - (value nil :type (or lvar null))) + (value nil :type (or lvar null)) + (nlx-info nil :type (or nlx-info null))) (defprinter (exit :identity t) #!+sb-show id (entry :test entry) @@ -1283,7 +1319,7 @@ ;;;; miscellaneous IR1 structures -(defstruct (undefined-warning +(def!struct (undefined-warning #-no-ansi-print-object (:print-object (lambda (x s) (print-unreadable-object (x s :type t)