1 ;;;; structures for the first intermediate representation in the
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
15 ;;; The front-end data structure (IR1) is composed of nodes,
16 ;;; representing actual evaluations. Linear sequences of nodes in
17 ;;; control-flow order are combined into blocks (but see
18 ;;; JOIN-SUCCESSOR-IF-POSSIBLE for precise conditions); control
19 ;;; transfers inside a block are represented with CTRANs and between
20 ;;; blocks -- with BLOCK-SUCC/BLOCK-PRED lists; data transfers are
21 ;;; represented with LVARs.
23 ;;; "Lead-in" Control TRANsfer [to some node]
25 (:make-load-form-fun ignore-it)
26 (:constructor make-ctran))
27 ;; an indication of the way that this continuation is currently used
30 ;; A continuation for which all control-related slots have the
31 ;; default values. A continuation is unused during IR1 conversion
32 ;; until it is assigned a block, and may be also be temporarily
33 ;; unused during later manipulations of IR1. In a consistent
34 ;; state there should never be any mention of :UNUSED
35 ;; continuations. NEXT can have a non-null value if the next node
36 ;; has already been determined.
39 ;; The continuation that is the START of BLOCK.
42 ;; A continuation that is the NEXT of some node in BLOCK.
43 (kind :unused :type (member :unused :inside-block :block-start))
44 ;; A NODE which is to be evaluated next. Null only temporary.
45 (next nil :type (or node null))
46 ;; the node where this CTRAN is used, if unique. This is always null
47 ;; in :UNUSED and :BLOCK-START CTRANs, and is never null in
48 ;; :INSIDE-BLOCK continuations.
49 (use nil :type (or node null))
50 ;; the basic block this continuation is in. This is null only in
51 ;; :UNUSED continuations.
52 (block nil :type (or cblock null)))
54 (def!method print-object ((x ctran) stream)
55 (print-unreadable-object (x stream :type t :identity t)
56 (format stream " #~D" (cont-num x))))
58 ;;; Linear VARiable. Multiple-value (possibly of unknown number)
61 (:make-load-form-fun ignore-it)
62 (:constructor make-lvar (&optional dest)))
63 ;; The node which receives this value. NIL only temporarily.
64 (dest nil :type (or node null))
65 ;; cached type of this lvar's value. If NIL, then this must be
66 ;; recomputed: see LVAR-DERIVED-TYPE.
67 (%derived-type nil :type (or ctype null))
68 ;; the node (if unique) or a list of nodes where this lvar is used.
69 (uses nil :type (or node list))
70 ;; set to true when something about this lvar's value has
71 ;; changed. See REOPTIMIZE-LVAR. This provides a way for IR1
72 ;; optimize to determine which operands to a node have changed. If
73 ;; the optimizer for this node type doesn't care, it can elect not
74 ;; to clear this flag.
75 (reoptimize t :type boolean)
76 ;; Cached type which is checked by DEST. If NIL, then this must be
77 ;; recomputed: see LVAR-EXTERNALLY-CHECKABLE-TYPE.
78 (%externally-checkable-type nil :type (or null ctype))
79 ;; if the LVAR value is DYNAMIC-EXTENT, CLEANUP protecting it.
80 (dynamic-extent nil :type (or null cleanup))
81 ;; something or other that the back end annotates this lvar with
84 (def!method print-object ((x lvar) stream)
85 (print-unreadable-object (x stream :type t :identity t)
86 (format stream " #~D" (cont-num x))))
88 (def!struct (node (:constructor nil)
90 ;; unique ID for debugging
91 #!+sb-show (id (new-object-id) :read-only t)
92 ;; True if this node needs to be optimized. This is set to true
93 ;; whenever something changes about the value of an lvar whose DEST
95 (reoptimize t :type boolean)
96 ;; the ctran indicating what we do controlwise after evaluating this
97 ;; node. This is null if the node is the last in its block.
98 (next nil :type (or ctran null))
99 ;; the ctran that this node is the NEXT of. This is null during IR1
100 ;; conversion when we haven't linked the node in yet or in nodes
101 ;; that have been deleted from the IR1 by UNLINK-NODE.
102 (prev nil :type (or ctran null))
103 ;; the lexical environment this node was converted in
104 (lexenv *lexenv* :type lexenv)
105 ;; a representation of the source code responsible for generating
108 ;; For a form introduced by compilation (does not appear in the
109 ;; original source), the path begins with a list of all the
110 ;; enclosing introduced forms. This list is from the inside out,
111 ;; with the form immediately responsible for this node at the head
114 ;; Following the introduced forms is a representation of the
115 ;; location of the enclosing original source form. This transition
116 ;; is indicated by the magic ORIGINAL-SOURCE-START marker. The first
117 ;; element of the original source is the "form number", which is the
118 ;; ordinal number of this form in a depth-first, left-to-right walk
119 ;; of the truly-top-level form in which this appears.
121 ;; Following is a list of integers describing the path taken through
122 ;; the source to get to this point:
123 ;; (K L M ...) => (NTH K (NTH L (NTH M ...)))
125 ;; The last element in the list is the top level form number, which
126 ;; is the ordinal number (in this call to the compiler) of the truly
127 ;; top level form containing the original source.
128 (source-path *current-path* :type list)
129 ;; If this node is in a tail-recursive position, then this is set to
130 ;; T. At the end of IR1 (in physical environment analysis) this is
131 ;; computed for all nodes (after cleanup code has been emitted).
132 ;; Before then, a non-null value indicates that IR1 optimization has
133 ;; converted a tail local call to a direct transfer.
135 ;; If the back-end breaks tail-recursion for some reason, then it
136 ;; can null out this slot.
137 (tail-p nil :type boolean))
139 (def!struct (valued-node (:conc-name node-)
143 ;; the bottom-up derived type for this node.
144 (derived-type *wild-type* :type ctype)
145 ;; Lvar, receiving the values, produced by this node. May be NIL if
146 ;; the value is unused.
147 (lvar nil :type (or lvar null)))
149 ;;; Flags that are used to indicate various things about a block, such
150 ;;; as what optimizations need to be done on it:
151 ;;; -- REOPTIMIZE is set when something interesting happens the uses of a
152 ;;; lvar whose DEST is in this block. This indicates that the
153 ;;; value-driven (forward) IR1 optimizations should be done on this block.
154 ;;; -- FLUSH-P is set when code in this block becomes potentially flushable,
155 ;;; usually due to an lvar's DEST becoming null.
156 ;;; -- TYPE-CHECK is true when the type check phase should be run on this
157 ;;; block. IR1 optimize can introduce new blocks after type check has
158 ;;; already run. We need to check these blocks, but there is no point in
159 ;;; checking blocks we have already checked.
160 ;;; -- DELETE-P is true when this block is used to indicate that this block
161 ;;; has been determined to be unreachable and should be deleted. IR1
162 ;;; phases should not attempt to examine or modify blocks with DELETE-P
163 ;;; set, since they may:
164 ;;; - be in the process of being deleted, or
165 ;;; - have no successors.
166 ;;; -- TYPE-ASSERTED, TEST-MODIFIED
167 ;;; These flags are used to indicate that something in this block
168 ;;; might be of interest to constraint propagation. TYPE-ASSERTED
169 ;;; is set when an lvar type assertion is strengthened.
170 ;;; TEST-MODIFIED is set whenever the test for the ending IF has
171 ;;; changed (may be true when there is no IF.)
172 (!def-boolean-attribute block
173 reoptimize flush-p type-check delete-p type-asserted test-modified)
175 ;;; FIXME: Tweak so that definitions of e.g. BLOCK-DELETE-P is
176 ;;; findable by grep for 'def.*block-delete-p'.
177 (macrolet ((frob (slot)
178 `(defmacro ,(symbolicate "BLOCK-" slot) (block)
179 `(block-attributep (block-flags ,block) ,',slot))))
185 (frob test-modified))
187 ;;; The CBLOCK structure represents a basic block. We include
188 ;;; SSET-ELEMENT so that we can have sets of blocks. Initially the
189 ;;; SSET-ELEMENT-NUMBER is null, DFO analysis numbers in reverse DFO.
190 ;;; During IR2 conversion, IR1 blocks are re-numbered in forward emit
191 ;;; order. This latter numbering also forms the basis of the block
192 ;;; numbering in the debug-info (though that is relative to the start
193 ;;; of the function.)
194 (def!struct (cblock (:include sset-element)
195 (:constructor make-block (start))
196 (:constructor make-block-key)
198 (:predicate block-p))
199 ;; a list of all the blocks that are predecessors/successors of this
200 ;; block. In well-formed IR1, most blocks will have one successor.
201 ;; The only exceptions are:
202 ;; 1. component head blocks (any number)
203 ;; 2. blocks ending in an IF (1 or 2)
204 ;; 3. blocks with DELETE-P set (zero)
205 (pred nil :type list)
206 (succ nil :type list)
207 ;; the ctran which heads this block (a :BLOCK-START), or NIL when we
208 ;; haven't made the start ctran yet (and in the dummy component head
210 (start nil :type (or ctran null))
211 ;; the last node in this block. This is NIL when we are in the
212 ;; process of building a block (and in the dummy component head and
214 (last nil :type (or node null))
215 ;; the forward and backward links in the depth-first ordering of the
216 ;; blocks. These slots are NIL at beginning/end.
217 (next nil :type (or null cblock))
218 (prev nil :type (or null cblock))
219 ;; This block's attributes: see above.
220 (flags (block-attributes reoptimize flush-p type-check type-asserted
223 ;; in constraint propagation: list of LAMBDA-VARs killed in this block
224 ;; in copy propagation: list of killed TNs
226 ;; other sets used in constraint propagation and/or copy propagation
230 ;; the component this block is in, or NIL temporarily during IR1
231 ;; conversion and in deleted blocks
233 (aver-live-component *current-component*)
235 :type (or component null))
236 ;; a flag used by various graph-walking code to determine whether
237 ;; this block has been processed already or what. We make this
238 ;; initially NIL so that FIND-INITIAL-DFO doesn't have to scan the
239 ;; entire initial component just to clear the flags.
241 ;; some kind of info used by the back end
243 ;; constraints that hold in this block and its successors by merit
244 ;; of being tested by its IF predecessors.
245 (test-constraint nil :type (or sset null)))
246 (def!method print-object ((cblock cblock) stream)
247 (print-unreadable-object (cblock stream :type t :identity t)
248 (format stream "~W :START c~W"
249 (block-number cblock)
250 (cont-num (block-start cblock)))))
252 ;;; The BLOCK-ANNOTATION class is inherited (via :INCLUDE) by
253 ;;; different BLOCK-INFO annotation structures so that code
254 ;;; (specifically control analysis) can be shared.
255 (def!struct (block-annotation (:constructor nil)
257 ;; The IR1 block that this block is in the INFO for.
258 (block (missing-arg) :type cblock)
259 ;; the next and previous block in emission order (not DFO). This
260 ;; determines which block we drop though to, and is also used to
261 ;; chain together overflow blocks that result from splitting of IR2
262 ;; blocks in lifetime analysis.
263 (next nil :type (or block-annotation null))
264 (prev nil :type (or block-annotation null)))
266 ;;; A COMPONENT structure provides a handle on a connected piece of
267 ;;; the flow graph. Most of the passes in the compiler operate on
268 ;;; COMPONENTs rather than on the entire flow graph.
270 ;;; According to the CMU CL internals/front.tex, the reason for
271 ;;; separating compilation into COMPONENTs is
272 ;;; to increase the efficiency of large block compilations. In
273 ;;; addition to improving locality of reference and reducing the
274 ;;; size of flow analysis problems, this allows back-end data
275 ;;; structures to be reclaimed after the compilation of each
277 (def!struct (component (:copier nil)
279 make-component (head tail &aux (last-block tail))))
280 ;; unique ID for debugging
281 #!+sb-show (id (new-object-id) :read-only t)
282 ;; the kind of component
284 ;; (The terminology here is left over from before
285 ;; sbcl-0.pre7.34.flaky5.2, when there was no such thing as
286 ;; FUNCTIONAL-HAS-EXTERNAL-REFERENCES-P, so that Python was
287 ;; incapable of building standalone :EXTERNAL functions, but instead
288 ;; had to implement things like #'CL:COMPILE as FUNCALL of a little
289 ;; toplevel stub whose sole purpose was to return an :EXTERNAL
292 ;; The possibilities are:
294 ;; an ordinary component, containing non-top-level code
296 ;; a component containing only load-time code
298 ;; In the old system, before FUNCTIONAL-HAS-EXTERNAL-REFERENCES-P
299 ;; was defined, this was necessarily a component containing both
300 ;; top level and run-time code. Now this state is also used for
301 ;; a component with HAS-EXTERNAL-REFERENCES-P functionals in it.
303 ;; the result of initial IR1 conversion, on which component
304 ;; analysis has not been done
306 ;; debris left over from component analysis
308 ;; See also COMPONENT-TOPLEVELISH-P.
309 (kind nil :type (member nil :toplevel :complex-toplevel :initial :deleted))
310 ;; the blocks that are the dummy head and tail of the DFO
312 ;; Entry/exit points have these blocks as their
313 ;; predecessors/successors. The start and return from each
314 ;; non-deleted function is linked to the component head and
315 ;; tail. Until physical environment analysis links NLX entry stubs
316 ;; to the component head, every successor of the head is a function
317 ;; start (i.e. begins with a BIND node.)
318 (head (missing-arg) :type cblock)
319 (tail (missing-arg) :type cblock)
320 ;; New blocks are inserted before this.
321 (last-block (missing-arg) :type cblock)
322 ;; This becomes a list of the CLAMBDA structures for all functions
323 ;; in this component. OPTIONAL-DISPATCHes are represented only by
324 ;; their XEP and other associated lambdas. This doesn't contain any
325 ;; deleted or LET lambdas.
327 ;; Note that logical associations between CLAMBDAs and COMPONENTs
328 ;; seem to exist for a while before this is initialized. See e.g.
329 ;; the NEW-FUNCTIONALS slot. In particular, I got burned by writing
330 ;; some code to use this value to decide which components need
331 ;; LOCALL-ANALYZE-COMPONENT, when it turns out that
332 ;; LOCALL-ANALYZE-COMPONENT had a role in initializing this value
333 ;; (and DFO stuff does too, maybe). Also, even after it's
334 ;; initialized, it might change as CLAMBDAs are deleted or merged.
336 (lambdas () :type list)
337 ;; a list of FUNCTIONALs for functions that are newly converted, and
338 ;; haven't been local-call analyzed yet. Initially functions are not
339 ;; in the LAMBDAS list. Local call analysis moves them there
340 ;; (possibly as LETs, or implicitly as XEPs if an OPTIONAL-DISPATCH.)
341 ;; Between runs of local call analysis there may be some debris of
342 ;; converted or even deleted functions in this list.
343 (new-functionals () :type list)
344 ;; If this is true, then there is stuff in this component that could
345 ;; benefit from further IR1 optimization.
346 (reoptimize t :type boolean)
347 ;; If this is true, then the control flow in this component was
348 ;; messed up by IR1 optimizations, so the DFO should be recomputed.
349 (reanalyze nil :type boolean)
350 ;; some sort of name for the code in this component
351 (name "<unknown>" :type simple-string)
352 ;; When I am a child, this is :NO-IR2-YET.
353 ;; In my adulthood, IR2 stores notes to itself here.
354 ;; After I have left the great wheel and am staring into the GC, this
355 ;; is set to :DEAD to indicate that it's a gruesome error to operate
356 ;; on me (e.g. by using me as *CURRENT-COMPONENT*, or by pushing
357 ;; LAMBDAs onto my NEW-FUNCTIONALS, as in sbcl-0.pre7.115).
358 (info :no-ir2-yet :type (or ir2-component (member :no-ir2-yet :dead)))
359 ;; the SOURCE-INFO structure describing where this component was
361 (source-info *source-info* :type source-info)
362 ;; count of the number of inline expansions we have done while
363 ;; compiling this component, to detect infinite or exponential
365 (inline-expansions 0 :type index)
366 ;; a map from combination nodes to things describing how an
367 ;; optimization of the node failed. The description is an alist
368 ;; (TRANSFORM . ARGS), where TRANSFORM is the structure describing
369 ;; the transform that failed, and ARGS is either a list of format
370 ;; arguments for the note, or the FUN-TYPE that would have
371 ;; enabled the transformation but failed to match.
372 (failed-optimizations (make-hash-table :test 'eq) :type hash-table)
373 ;; This is similar to NEW-FUNCTIONALS, but is used when a function
374 ;; has already been analyzed, but new references have been added by
375 ;; inline expansion. Unlike NEW-FUNCTIONALS, this is not disjoint
376 ;; from COMPONENT-LAMBDAS.
377 (reanalyze-functionals nil :type list)
378 (delete-blocks nil :type list)
379 (nlx-info-generated-p nil :type boolean)
380 ;; this is filled by physical environment analysis
381 (dx-lvars nil :type list))
382 (defprinter (component :identity t)
385 (reanalyze :test reanalyze))
387 ;;; Check that COMPONENT is suitable for roles which involve adding
388 ;;; new code. (gotta love imperative programming with lotso in-place
390 (defun aver-live-component (component)
391 ;; FIXME: As of sbcl-0.pre7.115, we're asserting that
392 ;; COMPILE-COMPONENT hasn't happened yet. Might it be even better
393 ;; (certainly stricter, possibly also correct...) to assert that
394 ;; IR1-FINALIZE hasn't happened yet?
395 (aver (not (eql (component-info component) :dead))))
397 ;;; Before sbcl-0.7.0, there were :TOPLEVEL things which were magical
398 ;;; in multiple ways. That's since been refactored into the orthogonal
399 ;;; properties "optimized for locall with no arguments" and "externally
400 ;;; visible/referenced (so don't delete it)". The code <0.7.0 did a lot
401 ;;; of tests a la (EQ KIND :TOP_LEVEL) in the "don't delete it?" sense;
402 ;;; this function is a sort of literal translation of those tests into
405 ;;; FIXME: After things settle down, bare :TOPLEVEL might go away, at
406 ;;; which time it might be possible to replace the COMPONENT-KIND
407 ;;; :TOPLEVEL mess with a flag COMPONENT-HAS-EXTERNAL-REFERENCES-P
408 ;;; along the lines of FUNCTIONAL-HAS-EXTERNAL-REFERENCES-P.
409 (defun lambda-toplevelish-p (clambda)
410 (or (eql (lambda-kind clambda) :toplevel)
411 (lambda-has-external-references-p clambda)))
412 (defun component-toplevelish-p (component)
413 (member (component-kind component)
414 '(:toplevel :complex-toplevel)))
416 ;;; A CLEANUP structure represents some dynamic binding action. Blocks
417 ;;; are annotated with the current CLEANUP so that dynamic bindings
418 ;;; can be removed when control is transferred out of the binding
419 ;;; environment. We arrange for changes in dynamic bindings to happen
420 ;;; at block boundaries, so that cleanup code may easily be inserted.
421 ;;; The "mess-up" action is explicitly represented by a funny function
422 ;;; call or ENTRY node.
424 ;;; We guarantee that CLEANUPs only need to be done at block
425 ;;; boundaries by requiring that the exit ctrans initially head their
426 ;;; blocks, and then by not merging blocks when there is a cleanup
428 (def!struct (cleanup (:copier nil))
429 ;; the kind of thing that has to be cleaned up
431 :type (member :special-bind :catch :unwind-protect
432 :block :tagbody :dynamic-extent))
433 ;; the node that messes things up. This is the last node in the
434 ;; non-messed-up environment. Null only temporarily. This could be
435 ;; deleted due to unreachability.
436 (mess-up nil :type (or node null))
437 ;; For all kinds, except :DYNAMIC-EXTENT: a list of all the NLX-INFO
438 ;; structures whose NLX-INFO-CLEANUP is this cleanup. This is filled
439 ;; in by physical environment analysis.
441 ;; For :DYNAMIC-EXTENT: a list of all DX LVARs, preserved by this
442 ;; cleanup. This is filled when the cleanup is created (now by
443 ;; locall call analysis) and is rechecked by physical environment
445 (info nil :type list))
446 (defprinter (cleanup :identity t)
450 (defmacro cleanup-nlx-info (cleanup)
451 `(cleanup-info ,cleanup))
453 ;;; A PHYSENV represents the result of physical environment analysis.
455 ;;; As far as I can tell from reverse engineering, this IR1 structure
456 ;;; represents the physical environment (which is probably not the
457 ;;; standard Lispy term for this concept, but I dunno what is the
458 ;;; standard term): those things in the lexical environment which a
459 ;;; LAMBDA actually interacts with. Thus in
460 ;;; (DEFUN FROB-THINGS (THINGS)
461 ;;; (DOLIST (THING THINGS)
462 ;;; (BLOCK FROBBING-ONE-THING
463 ;;; (MAPCAR (LAMBDA (PATTERN)
464 ;;; (WHEN (FITS-P THING PATTERN)
465 ;;; (RETURN-FROM FROB-THINGS (LIST :FIT THING PATTERN))))
467 ;;; the variables THINGS, THING, and PATTERN and the block names
468 ;;; FROB-THINGS and FROBBING-ONE-THING are all in the inner LAMBDA's
469 ;;; lexical environment, but of those only THING, PATTERN, and
470 ;;; FROB-THINGS are in its physical environment. In IR1, we largely
471 ;;; just collect the names of these things; in IR2 an IR2-PHYSENV
472 ;;; structure is attached to INFO and used to keep track of
473 ;;; associations between these names and less-abstract things (like
474 ;;; TNs, or eventually stack slots and registers). -- WHN 2001-09-29
475 (def!struct (physenv (:copier nil))
476 ;; the function that allocates this physical environment
477 (lambda (missing-arg) :type clambda :read-only t)
478 ;; This ultimately converges to a list of all the LAMBDA-VARs and
479 ;; NLX-INFOs needed from enclosing environments by code in this
480 ;; physical environment. In the meantime, it may be
481 ;; * NIL at object creation time
482 ;; * a superset of the correct result, generated somewhat later
483 ;; * smaller and smaller sets converging to the correct result as
484 ;; we notice and delete unused elements in the superset
485 (closure nil :type list)
486 ;; a list of NLX-INFO structures describing all the non-local exits
487 ;; into this physical environment
488 (nlx-info nil :type list)
489 ;; some kind of info used by the back end
491 (defprinter (physenv :identity t)
493 (closure :test closure)
494 (nlx-info :test nlx-info))
496 ;;; An TAIL-SET structure is used to accumulate information about
497 ;;; tail-recursive local calls. The "tail set" is effectively the
498 ;;; transitive closure of the "is called tail-recursively by"
501 ;;; All functions in the same tail set share the same TAIL-SET
502 ;;; structure. Initially each function has its own TAIL-SET, but when
503 ;;; IR1-OPTIMIZE-RETURN notices a tail local call, it joins the tail
504 ;;; sets of the called function and the calling function.
506 ;;; The tail set is somewhat approximate, because it is too early to
507 ;;; be sure which calls will be tail-recursive. Any call that *might*
508 ;;; end up tail-recursive causes TAIL-SET merging.
509 (def!struct (tail-set)
510 ;; a list of all the LAMBDAs in this tail set
511 (funs nil :type list)
512 ;; our current best guess of the type returned by these functions.
513 ;; This is the union across all the functions of the return node's
514 ;; RESULT-TYPE, excluding local calls.
515 (type *wild-type* :type ctype)
516 ;; some info used by the back end
518 (defprinter (tail-set :identity t)
523 ;;; An NLX-INFO structure is used to collect various information about
524 ;;; non-local exits. This is effectively an annotation on the
525 ;;; continuation, although it is accessed by searching in the
526 ;;; PHYSENV-NLX-INFO.
527 (def!struct (nlx-info (:constructor make-nlx-info
528 (cleanup exit &aux (lvar (node-lvar exit))))
529 (:make-load-form-fun ignore-it))
530 ;; the cleanup associated with this exit. In a catch or
531 ;; unwind-protect, this is the :CATCH or :UNWIND-PROTECT cleanup,
532 ;; and not the cleanup for the escape block. The CLEANUP-KIND of
533 ;; this thus provides a good indication of what kind of exit is
535 (cleanup (missing-arg) :type cleanup)
536 ;; the continuation exited to (the CONT of the EXIT nodes). If this
537 ;; exit is from an escape function (CATCH or UNWIND-PROTECT), then
538 ;; physical environment analysis deletes the escape function and
539 ;; instead has the %NLX-ENTRY use this continuation.
541 ;; This slot is primarily an indication of where this exit delivers
542 ;; its values to (if any), but it is also used as a sort of name to
543 ;; allow us to find the NLX-INFO that corresponds to a given exit.
544 ;; For this purpose, the ENTRY must also be used to disambiguate,
545 ;; since exits to different places may deliver their result to the
546 ;; same continuation.
547 (exit (missing-arg) :type exit)
548 (lvar (missing-arg) :type (or lvar null))
549 ;; the entry stub inserted by physical environment analysis. This is
550 ;; a block containing a call to the %NLX-ENTRY funny function that
551 ;; has the original exit destination as its successor. Null only
553 (target nil :type (or cblock null))
554 ;; some kind of info used by the back end
556 (defprinter (nlx-info :identity t)
563 ;;; Variables, constants and functions are all represented by LEAF
564 ;;; structures. A reference to a LEAF is indicated by a REF node. This
565 ;;; allows us to easily substitute one for the other without actually
566 ;;; hacking the flow graph.
567 (def!struct (leaf (:make-load-form-fun ignore-it)
569 ;; unique ID for debugging
570 #!+sb-show (id (new-object-id) :read-only t)
571 ;; (For public access to this slot, use LEAF-SOURCE-NAME.)
573 ;; the name of LEAF as it appears in the source, e.g. 'FOO or '(SETF
574 ;; FOO) or 'N or '*Z*, or the special .ANONYMOUS. value if there's
575 ;; no name for this thing in the source (as can happen for
576 ;; FUNCTIONALs, e.g. for anonymous LAMBDAs or for functions for
577 ;; top-level forms; and can also happen for anonymous constants) or
578 ;; perhaps also if the match between the name and the thing is
579 ;; skewed enough (e.g. for macro functions or method functions) that
580 ;; we don't want to have that name affect compilation
582 ;; (We use .ANONYMOUS. here more or less the way we'd ordinarily use
583 ;; NIL, but we're afraid to use NIL because it's a symbol which could
584 ;; be the name of a leaf, if only the constant named NIL.)
586 ;; The value of this slot in can affect ordinary runtime behavior,
587 ;; e.g. of special variables and known functions, not just debugging.
589 ;; See also the LEAF-DEBUG-NAME function and the
590 ;; FUNCTIONAL-%DEBUG-NAME slot.
591 (%source-name (missing-arg)
592 :type (or symbol (and cons (satisfies legal-fun-name-p)))
594 ;; the type which values of this leaf must have
595 (type *universal-type* :type ctype)
596 ;; where the TYPE information came from:
597 ;; :DECLARED, from a declaration.
598 ;; :ASSUMED, from uses of the object.
599 ;; :DEFINED, from examination of the definition.
600 ;; FIXME: This should be a named type. (LEAF-WHERE-FROM? Or
601 ;; perhaps just WHERE-FROM, since it's not just used in LEAF,
602 ;; but also in various DEFINE-INFO-TYPEs in globaldb.lisp,
603 ;; and very likely elsewhere too.)
604 (where-from :assumed :type (member :declared :assumed :defined))
605 ;; list of the REF nodes for this leaf
607 ;; true if there was ever a REF or SET node for this leaf. This may
608 ;; be true when REFS and SETS are null, since code can be deleted.
609 (ever-used nil :type boolean)
610 ;; is it declared dynamic-extent?
611 (dynamic-extent nil :type boolean)
612 ;; some kind of info used by the back end
615 ;;; LEAF name operations
617 ;;; KLUDGE: wants CLOS..
618 (defun leaf-has-source-name-p (leaf)
619 (not (eq (leaf-%source-name leaf)
621 (defun leaf-source-name (leaf)
622 (aver (leaf-has-source-name-p leaf))
623 (leaf-%source-name leaf))
624 (defun leaf-debug-name (leaf)
625 (if (functional-p leaf)
626 ;; FUNCTIONALs have additional %DEBUG-NAME behavior.
627 (functional-debug-name leaf)
628 ;; Other objects just use their source name.
630 ;; (As of sbcl-0.pre7.85, there are a few non-FUNCTIONAL
631 ;; anonymous objects, (anonymous constants..) and those would
632 ;; fail here if we ever tried to get debug names from them, but
633 ;; it looks as though it's never interesting to get debug names
634 ;; from them, so it's moot. -- WHN)
635 (leaf-source-name leaf)))
637 ;;; The CONSTANT structure is used to represent known constant values.
638 ;;; If NAME is not null, then it is the name of the named constant
639 ;;; which this leaf corresponds to, otherwise this is an anonymous
641 (def!struct (constant (:include leaf))
642 ;; the value of the constant
644 (defprinter (constant :identity t)
645 (%source-name :test %source-name)
648 ;;; The BASIC-VAR structure represents information common to all
649 ;;; variables which don't correspond to known local functions.
650 (def!struct (basic-var (:include leaf)
652 ;; Lists of the set nodes for this variable.
653 (sets () :type list))
655 ;;; The GLOBAL-VAR structure represents a value hung off of the symbol
657 (def!struct (global-var (:include basic-var))
658 ;; kind of variable described
660 :type (member :special :global-function :global)))
661 (defprinter (global-var :identity t)
664 (type :test (not (eq type *universal-type*)))
665 (where-from :test (not (eq where-from :assumed)))
668 ;;; A DEFINED-FUN represents a function that is defined in the same
669 ;;; compilation block, or that has an inline expansion, or that has a
670 ;;; non-NIL INLINEP value. Whenever we change the INLINEP state (i.e.
671 ;;; an inline proclamation) we copy the structure so that former
672 ;;; INLINEP values are preserved.
673 (def!struct (defined-fun (:include global-var
674 (where-from :defined)
675 (kind :global-function)))
676 ;; The values of INLINEP and INLINE-EXPANSION initialized from the
677 ;; global environment.
678 (inlinep nil :type inlinep)
679 (inline-expansion nil :type (or cons null))
680 ;; the block-local definition of this function (either because it
681 ;; was semi-inline, or because it was defined in this block). If
682 ;; this function is not an entry point, then this may be deleted or
683 ;; LET-converted. Null if we haven't converted the expansion yet.
684 (functional nil :type (or functional null)))
685 (defprinter (defined-fun :identity t)
689 (functional :test functional))
693 ;;; We default the WHERE-FROM and TYPE slots to :DEFINED and FUNCTION.
694 ;;; We don't normally manipulate function types for defined functions,
695 ;;; but if someone wants to know, an approximation is there.
696 (def!struct (functional (:include leaf
697 (%source-name '.anonymous.)
698 (where-from :defined)
699 (type (specifier-type 'function))))
700 ;; (For public access to this slot, use LEAF-DEBUG-NAME.)
702 ;; the name of FUNCTIONAL for debugging purposes, or NIL if we
703 ;; should just let the SOURCE-NAME fall through
705 ;; Unlike the SOURCE-NAME slot, this slot's value should never
706 ;; affect ordinary code behavior, only debugging/diagnostic behavior.
708 ;; Ha. Ah, the starry-eyed idealism of the writer of the above
709 ;; paragraph. FUNCTION-LAMBDA-EXPRESSION's behaviour, as of
710 ;; sbcl-0.7.11.x, differs if the name of the a function is a string
711 ;; or not, as if it is a valid function name then it can look for an
714 ;; The value of this slot can be anything, except that it shouldn't
715 ;; be a legal function name, since otherwise debugging gets
716 ;; confusing. (If a legal function name is a good name for the
717 ;; function, it should be in %SOURCE-NAME, and then we shouldn't
718 ;; need a %DEBUG-NAME.) In SBCL as of 0.pre7.87, it's always a
719 ;; string unless it's NIL, since that's how CMU CL represented debug
720 ;; names. However, eventually I (WHN) think it we should start using
721 ;; list values instead, since they have much nicer print properties
722 ;; (abbreviation, skipping package prefixes when unneeded, and
723 ;; renaming package prefixes when we do things like renaming SB!EXT
726 ;; E.g. for the function which implements (DEFUN FOO ...), we could
730 ;; for the function which implements the top level form
731 ;; (IN-PACKAGE :FOO) we could have
733 ;; %DEBUG-NAME="top level form (IN-PACKAGE :FOO)"
734 ;; for the function which implements FOO in
735 ;; (DEFUN BAR (...) (FLET ((FOO (...) ...)) ...))
738 ;; %DEBUG-NAME="FLET FOO in BAR"
739 ;; and for the function which implements FOO in
740 ;; (DEFMACRO FOO (...) ...)
742 ;; %SOURCE-NAME=FOO (or maybe .ANONYMOUS.?)
743 ;; %DEBUG-NAME="DEFMACRO FOO"
745 :type (or null (not (satisfies legal-fun-name-p)))
747 ;; some information about how this function is used. These values
751 ;; an ordinary function, callable using local call
754 ;; a lambda that is used in only one local call, and has in
755 ;; effect been substituted directly inline. The return node is
756 ;; deleted, and the result is computed with the actual result
757 ;; lvar for the call.
760 ;; Similar to :LET (as per FUNCTIONAL-LETLIKE-P), but the call
764 ;; similar to a LET (as per FUNCTIONAL-SOMEWHAT-LETLIKE-P), but
765 ;; can have other than one call as long as there is at most
766 ;; one non-tail call.
769 ;; a lambda that is an entry point for an OPTIONAL-DISPATCH.
770 ;; Similar to NIL, but requires greater caution, since local call
771 ;; analysis may create new references to this function. Also, the
772 ;; function cannot be deleted even if it has *no* references. The
773 ;; OPTIONAL-DISPATCH is in the LAMDBA-OPTIONAL-DISPATCH.
776 ;; an external entry point lambda. The function it is an entry
777 ;; for is in the ENTRY-FUN slot.
780 ;; a top level lambda, holding a compiled top level form.
781 ;; Compiled very much like NIL, but provides an indication of
782 ;; top level context. A :TOPLEVEL lambda should have *no*
783 ;; references. Its ENTRY-FUN is a self-pointer.
786 ;; After a component is compiled, we clobber any top level code
787 ;; references to its non-closure XEPs with dummy FUNCTIONAL
788 ;; structures having this kind. This prevents the retained
789 ;; top level code from holding onto the IR for the code it
794 ;; special functions used internally by CATCH and UNWIND-PROTECT.
795 ;; These are pretty much like a normal function (NIL), but are
796 ;; treated specially by local call analysis and stuff. Neither
797 ;; kind should ever be given an XEP even though they appear as
798 ;; args to funny functions. An :ESCAPE function is never actually
799 ;; called, and thus doesn't need to have code generated for it.
802 ;; This function has been found to be uncallable, and has been
803 ;; marked for deletion.
806 ;; Effectless [MV-]LET; has no BIND node.
807 (kind nil :type (member nil :optional :deleted :external :toplevel
808 :escape :cleanup :let :mv-let :assignment
809 :zombie :toplevel-xep))
810 ;; Is this a function that some external entity (e.g. the fasl dumper)
811 ;; refers to, so that even when it appears to have no references, it
812 ;; shouldn't be deleted? In the old days (before
813 ;; sbcl-0.pre7.37.flaky5.2) this was sort of implicitly true when
814 ;; KIND was :TOPLEVEL. Now it must be set explicitly, both for
815 ;; :TOPLEVEL functions and for any other kind of functions that we
816 ;; want to dump or return from #'CL:COMPILE or whatever.
817 (has-external-references-p nil)
818 ;; In a normal function, this is the external entry point (XEP)
819 ;; lambda for this function, if any. Each function that is used
820 ;; other than in a local call has an XEP, and all of the
821 ;; non-local-call references are replaced with references to the
824 ;; In an XEP lambda (indicated by the :EXTERNAL kind), this is the
825 ;; function that the XEP is an entry-point for. The body contains
826 ;; local calls to all the actual entry points in the function. In a
827 ;; :TOPLEVEL lambda (which is its own XEP) this is a self-pointer.
829 ;; With all other kinds, this is null.
830 (entry-fun nil :type (or functional null))
831 ;; the value of any inline/notinline declaration for a local
832 ;; function (or NIL in any case if no inline expansion is available)
833 (inlinep nil :type inlinep)
834 ;; If we have a lambda that can be used as in inline expansion for
835 ;; this function, then this is it. If there is no source-level
836 ;; lambda corresponding to this function then this is null (but then
837 ;; INLINEP will always be NIL as well.)
838 (inline-expansion nil :type list)
839 ;; the lexical environment that the INLINE-EXPANSION should be converted in
840 (lexenv *lexenv* :type lexenv)
841 ;; the original function or macro lambda list, or :UNSPECIFIED if
842 ;; this is a compiler created function
843 (arg-documentation nil :type (or list (member :unspecified)))
844 ;; various rare miscellaneous info that drives code generation & stuff
845 (plist () :type list))
846 (defprinter (functional :identity t)
851 ;;; Is FUNCTIONAL LET-converted? (where we're indifferent to whether
852 ;;; it returns one value or multiple values)
853 (defun functional-letlike-p (functional)
854 (member (functional-kind functional)
857 ;;; Is FUNCTIONAL sorta LET-converted? (where even an :ASSIGNMENT counts)
859 ;;; FIXME: I (WHN) don't understand this one well enough to give a good
860 ;;; definition or even a good function name, it's just a literal copy
861 ;;; of a CMU CL idiom. Does anyone have a better name or explanation?
862 (defun functional-somewhat-letlike-p (functional)
863 (or (functional-letlike-p functional)
864 (eql (functional-kind functional) :assignment)))
866 ;;; FUNCTIONAL name operations
867 (defun functional-debug-name (functional)
868 ;; FUNCTIONAL-%DEBUG-NAME takes precedence over FUNCTIONAL-SOURCE-NAME
869 ;; here because we want different debug names for the functions in
870 ;; DEFUN FOO and FLET FOO even though they have the same source name.
871 (or (functional-%debug-name functional)
872 ;; Note that this will cause an error if the function is
873 ;; anonymous. In SBCL (as opposed to CMU CL) we make all
874 ;; FUNCTIONALs have debug names. The CMU CL code didn't bother
875 ;; in many FUNCTIONALs, especially those which were likely to be
876 ;; optimized away before the user saw them. However, getting
877 ;; that right requires a global understanding of the code,
878 ;; which seems bad, so we just require names for everything.
879 (leaf-source-name functional)))
881 ;;; The CLAMBDA only deals with required lexical arguments. Special,
882 ;;; optional, keyword and rest arguments are handled by transforming
883 ;;; into simpler stuff.
884 (def!struct (clambda (:include functional)
886 (:predicate lambda-p)
887 (:constructor make-lambda)
888 (:copier copy-lambda))
889 ;; list of LAMBDA-VAR descriptors for arguments
890 (vars nil :type list :read-only t)
891 ;; If this function was ever a :OPTIONAL function (an entry-point
892 ;; for an OPTIONAL-DISPATCH), then this is that OPTIONAL-DISPATCH.
893 ;; The optional dispatch will be :DELETED if this function is no
895 (optional-dispatch nil :type (or optional-dispatch null))
896 ;; the BIND node for this LAMBDA. This node marks the beginning of
897 ;; the lambda, and serves to explicitly represent the lambda binding
898 ;; semantics within the flow graph representation. This is null in
899 ;; deleted functions, and also in LETs where we deleted the call and
900 ;; bind (because there are no variables left), but have not yet
901 ;; actually deleted the LAMBDA yet.
902 (bind nil :type (or bind null))
903 ;; the RETURN node for this LAMBDA, or NIL if it has been
904 ;; deleted. This marks the end of the lambda, receiving the result
905 ;; of the body. In a LET, the return node is deleted, and the body
906 ;; delivers the value to the actual lvar. The return may also be
907 ;; deleted if it is unreachable.
908 (return nil :type (or creturn null))
909 ;; If this CLAMBDA is a LET, then this slot holds the LAMBDA whose
910 ;; LETS list we are in, otherwise it is a self-pointer.
911 (home nil :type (or clambda null))
912 ;; all the lambdas that have been LET-substituted in this lambda.
913 ;; This is only non-null in lambdas that aren't LETs.
914 (lets nil :type list)
915 ;; all the ENTRY nodes in this function and its LETs, or null in a LET
916 (entries nil :type list)
917 ;; CLAMBDAs which are locally called by this lambda, and other
918 ;; objects (closed-over LAMBDA-VARs and XEPs) which this lambda
919 ;; depends on in such a way that DFO shouldn't put them in separate
921 (calls-or-closes nil :type list)
922 ;; the TAIL-SET that this LAMBDA is in. This is null during creation.
924 ;; In CMU CL, and old SBCL, this was also NILed out when LET
925 ;; conversion happened. That caused some problems, so as of
926 ;; sbcl-0.pre7.37.flaky5.2 when I was trying to get the compiler to
927 ;; emit :EXTERNAL functions directly, and so now the value
928 ;; is no longer NILed out in LET conversion, but instead copied
929 ;; (so that any further optimizations on the rest of the tail
930 ;; set won't modify the value) if necessary.
931 (tail-set nil :type (or tail-set null))
932 ;; the structure which represents the phsical environment that this
933 ;; function's variables are allocated in. This is filled in by
934 ;; physical environment analysis. In a LET, this is EQ to our home's
935 ;; physical environment.
936 (physenv nil :type (or physenv null))
937 ;; In a LET, this is the NODE-LEXENV of the combination node. We
938 ;; retain it so that if the LET is deleted (due to a lack of vars),
939 ;; we will still have caller's lexenv to figure out which cleanup is
941 (call-lexenv nil :type (or lexenv null))
942 ;; list of embedded lambdas
943 (children nil :type list)
944 (parent nil :type (or clambda null)))
945 (defprinter (clambda :conc-name lambda- :identity t)
950 (type :test (not (eq type *universal-type*)))
951 (where-from :test (not (eq where-from :assumed)))
952 (vars :prin1 (mapcar #'leaf-source-name vars)))
954 ;;; The OPTIONAL-DISPATCH leaf is used to represent hairy lambdas. It
955 ;;; is a FUNCTIONAL, like LAMBDA. Each legal number of arguments has a
956 ;;; function which is called when that number of arguments is passed.
957 ;;; The function is called with all the arguments actually passed. If
958 ;;; additional arguments are legal, then the LEXPR style MORE-ENTRY
959 ;;; handles them. The value returned by the function is the value
960 ;;; which results from calling the OPTIONAL-DISPATCH.
962 ;;; The theory is that each entry-point function calls the next entry
963 ;;; point tail-recursively, passing all the arguments passed in and
964 ;;; the default for the argument the entry point is for. The last
965 ;;; entry point calls the real body of the function. In the presence
966 ;;; of SUPPLIED-P args and other hair, things are more complicated. In
967 ;;; general, there is a distinct internal function that takes the
968 ;;; SUPPLIED-P args as parameters. The preceding entry point calls
969 ;;; this function with NIL filled in for the SUPPLIED-P args, while
970 ;;; the current entry point calls it with T in the SUPPLIED-P
973 ;;; Note that it is easy to turn a call with a known number of
974 ;;; arguments into a direct call to the appropriate entry-point
975 ;;; function, so functions that are compiled together can avoid doing
977 (def!struct (optional-dispatch (:include functional))
978 ;; the original parsed argument list, for anyone who cares
979 (arglist nil :type list)
980 ;; true if &ALLOW-OTHER-KEYS was supplied
981 (allowp nil :type boolean)
982 ;; true if &KEY was specified (which doesn't necessarily mean that
983 ;; there are any &KEY arguments..)
984 (keyp nil :type boolean)
985 ;; the number of required arguments. This is the smallest legal
986 ;; number of arguments.
987 (min-args 0 :type unsigned-byte)
988 ;; the total number of required and optional arguments. Args at
989 ;; positions >= to this are &REST, &KEY or illegal args.
990 (max-args 0 :type unsigned-byte)
991 ;; list of the (maybe delayed) LAMBDAs which are the entry points
992 ;; for non-rest, non-key calls. The entry for MIN-ARGS is first,
993 ;; MIN-ARGS+1 second, ... MAX-ARGS last. The last entry-point always
994 ;; calls the main entry; in simple cases it may be the main entry.
995 (entry-points nil :type list)
996 ;; an entry point which takes MAX-ARGS fixed arguments followed by
997 ;; an argument context pointer and an argument count. This entry
998 ;; point deals with listifying rest args and parsing keywords. This
999 ;; is null when extra arguments aren't legal.
1000 (more-entry nil :type (or clambda null))
1001 ;; the main entry-point into the function, which takes all arguments
1002 ;; including keywords as fixed arguments. The format of the
1003 ;; arguments must be determined by examining the arglist. This may
1004 ;; be used by callers that supply at least MAX-ARGS arguments and
1005 ;; know what they are doing.
1006 (main-entry nil :type (or clambda null)))
1007 (defprinter (optional-dispatch :identity t)
1011 (type :test (not (eq type *universal-type*)))
1012 (where-from :test (not (eq where-from :assumed)))
1018 (entry-points :test entry-points)
1019 (more-entry :test more-entry)
1022 ;;; The ARG-INFO structure allows us to tack various information onto
1023 ;;; LAMBDA-VARs during IR1 conversion. If we use one of these things,
1024 ;;; then the var will have to be massaged a bit before it is simple
1026 (def!struct arg-info
1027 ;; true if this arg is to be specially bound
1028 (specialp nil :type boolean)
1029 ;; the kind of argument being described. Required args only have arg
1030 ;; info structures if they are special.
1032 :type (member :required :optional :keyword :rest
1033 :more-context :more-count))
1034 ;; If true, this is the VAR for SUPPLIED-P variable of a keyword or
1035 ;; optional arg. This is true for keywords with non-constant
1036 ;; defaults even when there is no user-specified supplied-p var.
1037 (supplied-p nil :type (or lambda-var null))
1038 ;; the default for a keyword or optional, represented as the
1039 ;; original Lisp code. This is set to NIL in &KEY arguments that are
1040 ;; defaulted using the SUPPLIED-P arg.
1041 (default nil :type t)
1042 ;; the actual key for a &KEY argument. Note that in ANSI CL this is
1043 ;; not necessarily a keyword: (DEFUN FOO (&KEY ((BAR BAR))) ...).
1044 (key nil :type symbol))
1045 (defprinter (arg-info :identity t)
1046 (specialp :test specialp)
1048 (supplied-p :test supplied-p)
1049 (default :test default)
1052 ;;; The LAMBDA-VAR structure represents a lexical lambda variable.
1053 ;;; This structure is also used during IR1 conversion to describe
1054 ;;; lambda arguments which may ultimately turn out not to be simple
1057 ;;; LAMBDA-VARs with no REFs are considered to be deleted; physical
1058 ;;; environment analysis isn't done on these variables, so the back
1059 ;;; end must check for and ignore unreferenced variables. Note that a
1060 ;;; deleted LAMBDA-VAR may have sets; in this case the back end is
1061 ;;; still responsible for propagating the SET-VALUE to the set's CONT.
1062 (!def-boolean-attribute lambda-var
1063 ;; true if this variable has been declared IGNORE
1065 ;; This is set by physical environment analysis if it chooses an
1066 ;; indirect (value cell) representation for this variable because it
1067 ;; is both set and closed over.
1070 (def!struct (lambda-var (:include basic-var))
1071 (flags (lambda-var-attributes)
1073 ;; the CLAMBDA that this var belongs to. This may be null when we are
1074 ;; building a lambda during IR1 conversion.
1075 (home nil :type (or null clambda))
1076 ;; The following two slots are only meaningful during IR1 conversion
1077 ;; of hairy lambda vars:
1079 ;; The ARG-INFO structure which holds information obtained from
1080 ;; &keyword parsing.
1081 (arg-info nil :type (or arg-info null))
1082 ;; if true, the GLOBAL-VAR structure for the special variable which
1083 ;; is to be bound to the value of this argument
1084 (specvar nil :type (or global-var null))
1085 ;; Set of the CONSTRAINTs on this variable. Used by constraint
1086 ;; propagation. This is left null by the lambda pre-pass if it
1087 ;; determine that this is a set closure variable, and is thus not a
1088 ;; good subject for flow analysis.
1089 (constraints nil :type (or sset null)))
1090 (defprinter (lambda-var :identity t)
1093 (type :test (not (eq type *universal-type*)))
1094 (where-from :test (not (eq where-from :assumed)))
1095 (flags :test (not (zerop flags))
1096 :prin1 (decode-lambda-var-attributes flags))
1097 (arg-info :test arg-info)
1098 (specvar :test specvar))
1100 (defmacro lambda-var-ignorep (var)
1101 `(lambda-var-attributep (lambda-var-flags ,var) ignore))
1102 (defmacro lambda-var-indirect (var)
1103 `(lambda-var-attributep (lambda-var-flags ,var) indirect))
1105 ;;;; basic node types
1107 ;;; A REF represents a reference to a LEAF. REF-REOPTIMIZE is
1108 ;;; initially (and forever) NIL, since REFs don't receive any values
1109 ;;; and don't have any IR1 optimizer.
1110 (def!struct (ref (:include valued-node (reoptimize nil))
1111 (:constructor make-ref
1113 &aux (leaf-type (leaf-type leaf))
1115 (make-single-value-type leaf-type))))
1117 ;; The leaf referenced.
1118 (leaf nil :type leaf))
1119 (defprinter (ref :identity t)
1123 ;;; Naturally, the IF node always appears at the end of a block.
1124 (def!struct (cif (:include node)
1127 (:constructor make-if)
1129 ;; LVAR for the predicate
1130 (test (missing-arg) :type lvar)
1131 ;; the blocks that we execute next in true and false case,
1132 ;; respectively (may be the same)
1133 (consequent (missing-arg) :type cblock)
1134 (alternative (missing-arg) :type cblock))
1135 (defprinter (cif :conc-name if- :identity t)
1136 (test :prin1 (lvar-uses test))
1140 (def!struct (cset (:include valued-node
1141 (derived-type (make-single-value-type
1145 (:constructor make-set)
1147 ;; descriptor for the variable set
1148 (var (missing-arg) :type basic-var)
1149 ;; LVAR for the value form
1150 (value (missing-arg) :type lvar))
1151 (defprinter (cset :conc-name set- :identity t)
1153 (value :prin1 (lvar-uses value)))
1155 ;;; The BASIC-COMBINATION structure is used to represent both normal
1156 ;;; and multiple value combinations. In a let-like function call, this
1157 ;;; node appears at the end of its block and the body of the called
1158 ;;; function appears as the successor; the NODE-LVAR is null.
1159 (def!struct (basic-combination (:include valued-node)
1162 ;; LVAR for the function
1163 (fun (missing-arg) :type lvar)
1164 ;; list of LVARs for the args. In a local call, an argument lvar may
1165 ;; be replaced with NIL to indicate that the corresponding variable
1166 ;; is unreferenced, and thus no argument value need be passed.
1167 (args nil :type list)
1168 ;; the kind of function call being made. :LOCAL means that this is a
1169 ;; local call to a function in the same component, and that argument
1170 ;; syntax checking has been done, etc. Calls to known global
1171 ;; functions are represented by storing :KNOWN in this slot and the
1172 ;; FUN-INFO for that function in the FUN-INFO slot. :FULL is a call
1173 ;; to an (as yet) unknown function, or to a known function declared
1174 ;; NOTINLINE. :ERROR is like :FULL, but means that we have
1175 ;; discovered that the call contains an error, and should not be
1176 ;; reconsidered for optimization.
1177 (kind :full :type (member :local :full :error :known))
1178 ;; if a call to a known global function, contains the FUN-INFO.
1179 (fun-info nil :type (or fun-info null))
1180 ;; some kind of information attached to this node by the back end
1183 ;;; The COMBINATION node represents all normal function calls,
1184 ;;; including FUNCALL. This is distinct from BASIC-COMBINATION so that
1185 ;;; an MV-COMBINATION isn't COMBINATION-P.
1186 (def!struct (combination (:include basic-combination)
1187 (:constructor make-combination (fun))
1189 (defprinter (combination :identity t)
1191 (fun :prin1 (lvar-uses fun))
1192 (args :prin1 (mapcar (lambda (x)
1198 ;;; An MV-COMBINATION is to MULTIPLE-VALUE-CALL as a COMBINATION is to
1199 ;;; FUNCALL. This is used to implement all the multiple-value
1200 ;;; receiving forms.
1201 (def!struct (mv-combination (:include basic-combination)
1202 (:constructor make-mv-combination (fun))
1204 (defprinter (mv-combination)
1205 (fun :prin1 (lvar-uses fun))
1206 (args :prin1 (mapcar #'lvar-uses args)))
1208 ;;; The BIND node marks the beginning of a lambda body and represents
1209 ;;; the creation and initialization of the variables.
1210 (def!struct (bind (:include node)
1212 ;; the lambda we are binding variables for. Null when we are
1213 ;; creating the LAMBDA during IR1 translation.
1214 (lambda nil :type (or clambda null)))
1218 ;;; The RETURN node marks the end of a lambda body. It collects the
1219 ;;; return values and represents the control transfer on return. This
1220 ;;; is also where we stick information used for TAIL-SET type
1222 (def!struct (creturn (:include node)
1223 (:conc-name return-)
1224 (:predicate return-p)
1225 (:constructor make-return)
1226 (:copier copy-return))
1227 ;; the lambda we are returning from. Null temporarily during
1229 (lambda nil :type (or clambda null))
1230 ;; the lvar which yields the value of the lambda
1231 (result (missing-arg) :type lvar)
1232 ;; the union of the node-derived-type of all uses of the result
1233 ;; other than by a local call, intersected with the result's
1234 ;; asserted-type. If there are no non-call uses, this is
1236 (result-type *wild-type* :type ctype))
1237 (defprinter (creturn :conc-name return- :identity t)
1241 ;;; The CAST node represents type assertions. The check for
1242 ;;; TYPE-TO-CHECK is performed and then the VALUE is declared to be of
1243 ;;; type ASSERTED-TYPE.
1244 (def!struct (cast (:include valued-node)
1245 (:constructor %make-cast))
1246 (asserted-type (missing-arg) :type ctype)
1247 (type-to-check (missing-arg) :type ctype)
1248 ;; an indication of what we have proven about how this type
1249 ;; assertion is satisfied:
1252 ;; No type check is necessary (VALUE type is a subtype of the TYPE-TO-CHECK.)
1255 ;; Type check will be performed by NODE-DEST.
1258 ;; A type check is needed.
1259 (%type-check t :type (member t :external nil))
1260 ;; the lvar which is checked
1261 (value (missing-arg) :type lvar))
1262 (defprinter (cast :identity t)
1268 ;;;; non-local exit support
1270 ;;;; In IR1, we insert special nodes to mark potentially non-local
1273 ;;; The ENTRY node serves to mark the start of the dynamic extent of a
1274 ;;; lexical exit. It is the mess-up node for the corresponding :ENTRY
1276 (def!struct (entry (:include node)
1278 ;; All of the EXIT nodes for potential non-local exits to this point.
1279 (exits nil :type list)
1280 ;; The cleanup for this entry. NULL only temporarily.
1281 (cleanup nil :type (or cleanup null)))
1282 (defprinter (entry :identity t)
1285 ;;; The EXIT node marks the place at which exit code would be emitted,
1286 ;;; if necessary. This is interposed between the uses of the exit
1287 ;;; continuation and the exit continuation's DEST. Instead of using
1288 ;;; the returned value being delivered directly to the exit
1289 ;;; continuation, it is delivered to our VALUE lvar. The original exit
1290 ;;; lvar is the exit node's LVAR; physenv analysis also makes it the
1291 ;;; lvar of %NLX-ENTRY call.
1292 (def!struct (exit (:include valued-node)
1294 ;; the ENTRY node that this is an exit for. If null, this is a
1295 ;; degenerate exit. A degenerate exit is used to "fill" an empty
1296 ;; block (which isn't allowed in IR1.) In a degenerate exit, Value
1297 ;; is always also null.
1298 (entry nil :type (or entry null))
1299 ;; the lvar yielding the value we are to exit with. If NIL, then no
1300 ;; value is desired (as in GO).
1301 (value nil :type (or lvar null)))
1302 (defprinter (exit :identity t)
1305 (value :test value))
1307 ;;;; miscellaneous IR1 structures
1309 (def!struct (undefined-warning
1310 #-no-ansi-print-object
1311 (:print-object (lambda (x s)
1312 (print-unreadable-object (x s :type t)
1313 (prin1 (undefined-warning-name x) s))))
1315 ;; the name of the unknown thing
1316 (name nil :type (or symbol list))
1317 ;; the kind of reference to NAME
1318 (kind (missing-arg) :type (member :function :type :variable))
1319 ;; the number of times this thing was used
1320 (count 0 :type unsigned-byte)
1321 ;; a list of COMPILER-ERROR-CONTEXT structures describing places
1322 ;; where this thing was used. Note that we only record the first
1323 ;; *UNDEFINED-WARNING-LIMIT* calls.
1324 (warnings () :type list))
1326 ;;; a helper for the POLICY macro, defined late here so that the
1327 ;;; various type tests can be inlined
1328 (declaim (ftype (function ((or list lexenv node functional)) list)
1330 (defun %coerce-to-policy (thing)
1331 (let ((result (etypecase thing
1333 (lexenv (lexenv-policy thing))
1334 (node (lexenv-policy (node-lexenv thing)))
1335 (functional (lexenv-policy (functional-lexenv thing))))))
1336 ;; Test the first element of the list as a rudimentary sanity
1337 ;; that it really does look like a valid policy.
1338 (aver (or (null result) (policy-quality-name-p (caar result))))
1342 ;;;; Freeze some structure types to speed type testing.
1345 (declaim (freeze-type node leaf lexenv ctran lvar cblock component cleanup
1346 physenv tail-set nlx-info))