/[cmucl]/src/compiler/ir2tran.lisp
ViewVC logotype

Contents of /src/compiler/ir2tran.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.77 - (show annotations)
Tue Apr 20 17:57:46 2010 UTC (3 years, 11 months ago) by rtoy
Branch: MAIN
CVS Tags: sparc-tramp-assem-base, release-20b-pre1, release-20b-pre2, sparc-tramp-assem-2010-07-19, GIT-CONVERSION, cross-sol-x86-merged, RELEASE_20b, cross-sol-x86-base, snapshot-2010-12, snapshot-2010-11, snapshot-2011-09, snapshot-2011-06, snapshot-2011-07, snapshot-2011-04, snapshot-2011-02, snapshot-2011-03, snapshot-2011-01, snapshot-2010-05, snapshot-2010-07, snapshot-2010-06, snapshot-2010-08, cross-sol-x86-2010-12-20, cross-sparc-branch-base, HEAD
Branch point for: cross-sparc-branch, RELEASE-20B-BRANCH, sparc-tramp-assem-branch, cross-sol-x86-branch
Changes since 1.76: +2 -2 lines
Change uses of _"foo" to (intl:gettext "foo").  This is because slime
may get confused with source locations if the reader macros are
installed.
1 ;;; -*- Package: C; Log: C.Log -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the CMU Common Lisp project at
5 ;;; Carnegie Mellon University, and has been placed in the public domain.
6 ;;;
7 (ext:file-comment
8 "$Header: /tiger/var/lib/cvsroots/cmucl/src/compiler/ir2tran.lisp,v 1.77 2010/04/20 17:57:46 rtoy Rel $")
9 ;;;
10 ;;; **********************************************************************
11 ;;;
12 ;;; This file contains the virtual machine independent parts of the code
13 ;;; which does the actual translation of nodes to VOPs.
14 ;;;
15 ;;; Written by Rob MacLachlan
16 ;;;
17 (in-package "C")
18 (in-package "KERNEL")
19 (intl:textdomain "cmucl")
20
21 (export '(%caller-frame-and-pc))
22 (in-package "C")
23
24 (export '(safe-fdefn-function return-single instance-ref instance-set
25 funcallable-instance-lexenv))
26
27
28 #+(or sparc ppc)
29 (defvar *always-clear-stack* nil
30 _N"Always perform stack clearing if non-NIL, independent of the
31 compilation policy")
32
33 #+(or sparc ppc)
34 (defvar *enable-stack-clearing* t
35 _N"If non-NIL and the compilation policy allows, stack clearing is enabled.")
36
37 (defun ir2-stack-allocate (node)
38 (declare (type node node))
39 (continuation-dynamic-extent (node-cont node)))
40
41
42 ;;;; Moves and type checks:
43
44 ;;; Emit-Move -- Internal
45 ;;;
46 ;;; Move X to Y unless they are EQ.
47 ;;;
48 (defun emit-move (node block x y)
49 (declare (type node node) (type ir2-block block) (type tn x y))
50 (unless (eq x y)
51 (vop move node block x y))
52 (undefined-value))
53
54
55 ;;; Type-Check-Template -- Interface
56 ;;;
57 ;;; If there is any CHECK-xxx template for Type, then return it, otherwise
58 ;;; return NIL.
59 ;;;
60 (defun type-check-template (type)
61 (declare (type ctype type))
62 (multiple-value-bind (check-ptype exact)
63 (primitive-type type)
64 (if exact
65 (primitive-type-check check-ptype)
66 (let ((name (hairy-type-check-template type)))
67 (if name
68 (template-or-lose name *backend*)
69 nil)))))
70
71
72 ;;; Emit-Type-Check -- Internal
73 ;;;
74 ;;; Emit code in Block to check that Value is of the specified Type,
75 ;;; yielding the checked result in Result. Value and result may be of any
76 ;;; primitive type. There must be CHECK-xxx VOP for Type. Any other type
77 ;;; checks should have been converted to an explicit type test.
78 ;;;
79 (defun emit-type-check (node block value result type)
80 (declare (type tn value result) (type node node) (type ir2-block block)
81 (type ctype type))
82 (emit-move-template node block (type-check-template type) value result)
83 (undefined-value))
84
85 ;;; MAKE-VALUE-CELL -- Internal
86 ;;;
87 ;;; Allocate an indirect value cell. Maybe do some clever stack allocation
88 ;;; someday.
89 ;;;
90 (defevent make-value-cell "Allocate heap value cell for lexical var.")
91 (defun do-make-value-cell (node block value res)
92 (event make-value-cell node)
93 (vop make-value-cell node block value res))
94
95
96 ;;;; Leaf reference:
97
98 ;;; Find-In-Environment -- Internal
99 ;;;
100 ;;; Return the TN that holds the value of THING in the environment ENV.
101 ;;;
102 (defun find-in-environment (thing env)
103 (declare (type (or nlx-info lambda-var) thing) (type environment env)
104 (values tn))
105 (or (cdr (assoc thing (ir2-environment-environment (environment-info env))))
106 (etypecase thing
107 (lambda-var
108 (assert (eq env (lambda-environment (lambda-var-home thing))))
109 (leaf-info thing))
110 (nlx-info
111 (assert (eq env (block-environment (nlx-info-target thing))))
112 (ir2-nlx-info-home (nlx-info-info thing))))
113 (error (intl:gettext "~@<~2I~_~S ~_not found in ~_~S~:>") thing env)))
114
115 ;;; Constant-TN -- Internal
116 ;;;
117 ;;; If Leaf already has a constant TN, return that, otherwise make a TN for
118 ;;; it.
119 ;;;
120 (defun constant-tn (leaf)
121 (declare (type constant leaf))
122 (or (leaf-info leaf)
123 (setf (leaf-info leaf)
124 (make-constant-tn leaf))))
125
126
127 ;;; Leaf-TN -- Internal
128 ;;;
129 ;;; Return a TN that represents the value of Leaf, or NIL if Leaf isn't
130 ;;; directly represented by a TN. Env is the environment that the reference is
131 ;;; done in.
132 ;;;
133 (defun leaf-tn (leaf env)
134 (declare (type leaf leaf) (type environment env))
135 (typecase leaf
136 (lambda-var
137 (unless (lambda-var-indirect leaf)
138 (find-in-environment leaf env)))
139 (constant (constant-tn leaf))
140 (t nil)))
141
142
143 ;;; Emit-Constant -- Internal
144 ;;;
145 ;;; Used to conveniently get a handle on a constant TN during IR2
146 ;;; conversion. Returns a constant TN representing the Lisp object Value.
147 ;;;
148 (defun emit-constant (value)
149 (constant-tn (find-constant value)))
150
151
152 ;;; IR2-Convert-Ref -- Internal
153 ;;;
154 ;;; Convert a Ref node. The reference must not be delayed.
155 ;;;
156 (defun ir2-convert-ref (node block)
157 (declare (type ref node) (type ir2-block block))
158 (let* ((cont (node-cont node))
159 (leaf (ref-leaf node))
160 (name (leaf-name leaf))
161 (locs (continuation-result-tns
162 cont (list (primitive-type (leaf-type leaf)))))
163 (res (first locs)))
164 (etypecase leaf
165 (lambda-var
166 (let ((tn (find-in-environment leaf (node-environment node))))
167 (if (lambda-var-indirect leaf)
168 (vop value-cell-ref node block tn res)
169 (emit-move node block tn res))))
170 (constant
171 (if (legal-immediate-constant-p leaf)
172 (emit-move node block (constant-tn leaf) res)
173 (let ((name-tn (emit-constant name)))
174 (if (policy node (zerop safety))
175 (vop fast-symbol-value node block name-tn res)
176 (vop symbol-value node block name-tn res)))))
177 (functional
178 (ir2-convert-closure node block leaf res))
179 (global-var
180 (let ((unsafe (policy node (zerop safety))))
181 (ecase (global-var-kind leaf)
182 ((:special :global :constant)
183 (assert (symbolp name))
184 (let ((name-tn (emit-constant name)))
185 (if unsafe
186 (vop fast-symbol-value node block name-tn res)
187 (vop symbol-value node block name-tn res))))
188 (:global-function
189 (let ((fdefn-tn (make-load-time-constant-tn :fdefinition name)))
190 (if unsafe
191 (vop fdefn-function node block fdefn-tn res)
192 (vop safe-fdefn-function node block fdefn-tn res))))))))
193
194 (move-continuation-result node block locs cont))
195 (undefined-value))
196
197
198 ;;; IR2-Convert-Closure -- Internal
199 ;;;
200 ;;; Emit code to load a function object representing Leaf into Res. This
201 ;;; gets interesting when the referenced function is a closure: we must make
202 ;;; the closure and move the closed over values into it.
203 ;;;
204 ;;; Leaf is either a :TOP-LEVEL-XEP functional or the XEP lambda for the called
205 ;;; function, since local call analysis converts all closure references. If a
206 ;;; TL-XEP, we know it is not a closure.
207 ;;;
208 ;;; If a closed-over lambda-var has no refs (is deleted), then we don't
209 ;;; initialize that slot. This can happen with closures over top-level
210 ;;; variables, where optimization of the closure deleted the variable. Since
211 ;;; we committed to the closure format when we pre-analyzed the top-level code,
212 ;;; we just leva an empty slot.
213 ;;;
214 (defun ir2-convert-closure (node block leaf res)
215 (declare (type ref node) (type ir2-block block)
216 (type functional leaf) (type tn res))
217 (unless (leaf-info leaf)
218 (setf (leaf-info leaf) (make-entry-info)))
219 (let ((entry (make-load-time-constant-tn :entry leaf))
220 (closure (etypecase leaf
221 (clambda
222 (environment-closure (get-lambda-environment leaf)))
223 (functional
224 (assert (eq (functional-kind leaf) :top-level-xep))
225 nil))))
226 (cond (closure
227 (let ((this-env (node-environment node))
228 (dynamic-extent (ir2-stack-allocate node)))
229 (when *dynamic-extent-trace*
230 (format t "~&===> make-closure ~s (~d)~%"
231 dynamic-extent (length closure)))
232 (vop make-closure node block entry (length closure)
233 dynamic-extent res)
234 (loop for what in closure and n from 0 do
235 (unless (and (lambda-var-p what)
236 (null (leaf-refs what)))
237 (vop closure-init node block
238 res
239 (find-in-environment what this-env)
240 n)))))
241 (t
242 (emit-move node block entry res))))
243 (values))
244
245
246 ;;; IR2-Convert-Set -- Internal
247 ;;;
248 ;;; Convert a Set node. If the node's cont is annotated, then we also
249 ;;; deliver the value to that continuation. If the var is a lexical variable
250 ;;; with no refs, then we don't actually set anything, since the variable has
251 ;;; been deleted.
252 ;;;
253 (defun ir2-convert-set (node block)
254 (declare (type cset node) (type ir2-block block))
255 (let* ((cont (node-cont node))
256 (leaf (set-var node))
257 (val (continuation-tn node block (set-value node)))
258 (locs (if (continuation-info cont)
259 (continuation-result-tns
260 cont (list (primitive-type (leaf-type leaf))))
261 nil)))
262 (etypecase leaf
263 (lambda-var
264 (when (leaf-refs leaf)
265 (let ((tn (find-in-environment leaf (node-environment node))))
266 (if (lambda-var-indirect leaf)
267 (vop value-cell-set node block tn val)
268 (emit-move node block val tn)))))
269 (global-var
270 (ecase (global-var-kind leaf)
271 ((:special :global)
272 (assert (symbolp (leaf-name leaf)))
273 (vop set node block (emit-constant (leaf-name leaf)) val)))))
274
275 (when locs
276 (emit-move node block val (first locs))
277 (move-continuation-result node block locs cont)))
278 (undefined-value))
279
280
281 ;;;; Utilities for receiving fixed values:
282
283 ;;; Continuation-TN -- Internal
284 ;;;
285 ;;; Return a TN that can be referenced to get the value of Cont. Cont must
286 ;;; be LTN-Annotated either as a delayed leaf ref or as a fixed, single-value
287 ;;; continuation. If a type check is called for, do it.
288 ;;;
289 ;;; The primitive-type of the result will always be the same as the
290 ;;; ir2-continuation-primitive-type, ensuring that VOPs are always called with
291 ;;; TNs that satisfy the operand primitive-type restriction. We may have to
292 ;;; make a temporary of the desired type and move the actual continuation TN
293 ;;; into it. This happens when we delete a type check in unsafe code or when
294 ;;; we locally know something about the type of an argument variable.
295 ;;;
296 (defun continuation-tn (node block cont)
297 (declare (type node node) (type ir2-block block) (type continuation cont))
298 (let* ((2cont (continuation-info cont))
299 (cont-tn
300 (ecase (ir2-continuation-kind 2cont)
301 (:delayed
302 (let ((ref (continuation-use cont)))
303 (leaf-tn (ref-leaf ref) (node-environment ref))))
304 (:fixed
305 (assert (= (length (ir2-continuation-locs 2cont)) 1))
306 (first (ir2-continuation-locs 2cont)))))
307 (ptype (ir2-continuation-primitive-type 2cont)))
308
309 (cond ((and (eq (continuation-type-check cont) t)
310 (multiple-value-bind (check types)
311 (continuation-check-types cont)
312 (assert (eq check :simple))
313 ;; If the proven type is a subtype of the possibly
314 ;; weakened type check then it's always True and is
315 ;; flushed.
316 (unless (values-subtypep (continuation-proven-type cont)
317 (first types))
318 (let ((temp (make-normal-tn ptype)))
319 (emit-type-check node block cont-tn temp
320 (first types))
321 temp)))))
322 ((eq (tn-primitive-type cont-tn) ptype) cont-tn)
323 (t
324 (let ((temp (make-normal-tn ptype)))
325 (emit-move node block cont-tn temp)
326 temp)))))
327
328
329 ;;; CONTINUATION-TNS -- Internal
330 ;;;
331 ;;; Similar to CONTINUATION-TN, but hacks multiple values. We return
332 ;;; continuations holding the values of Cont with Ptypes as their primitive
333 ;;; types. Cont must be annotated for the same number of fixed values are
334 ;;; there are Ptypes.
335 ;;;
336 ;;; If the continuation has a type check, check the values into temps and
337 ;;; return the temps. When we have more values than assertions, we move the
338 ;;; extra values with no check.
339 ;;;
340 (defun continuation-tns (node block cont ptypes)
341 (declare (type node node) (type ir2-block block)
342 (type continuation cont) (list ptypes))
343 (let* ((locs (ir2-continuation-locs (continuation-info cont)))
344 (nlocs (length locs)))
345 (assert (= nlocs (length ptypes)))
346 (if (eq (continuation-type-check cont) t)
347 (multiple-value-bind (check types)
348 (continuation-check-types cont)
349 (assert (eq check :simple))
350 (let ((ntypes (length types)))
351 (mapcar #'(lambda (from to-type assertion)
352 (let ((temp (make-normal-tn to-type)))
353 (if assertion
354 (emit-type-check node block from temp assertion)
355 (emit-move node block from temp))
356 temp))
357 locs ptypes
358 (if (< ntypes nlocs)
359 (append types (make-list (- nlocs ntypes)
360 :initial-element nil))
361 types))))
362 (mapcar #'(lambda (from to-type)
363 (if (eq (tn-primitive-type from) to-type)
364 from
365 (let ((temp (make-normal-tn to-type)))
366 (emit-move node block from temp)
367 temp)))
368 locs ptypes))))
369
370
371 ;;;; Utilities for delivering values to continuations:
372
373 ;;; Continuation-Result-TNs -- Internal
374 ;;;
375 ;;; Return a list of TNs with the specifier Types that can be used as result
376 ;;; TNs to evaluate an expression into the continuation Cont. This is used
377 ;;; together with Move-Continuation-Result to deliver fixed values to a
378 ;;; continuation.
379 ;;;
380 ;;; If the continuation isn't annotated (meaning the values are discarded)
381 ;;; or is unknown-values, the then we make temporaries for each supplied value,
382 ;;; providing a place to compute the result in until we decide what to do with
383 ;;; it (if anything.)
384 ;;;
385 ;;; If the continuation is fixed-values, and wants the same number of values
386 ;;; as the user wants to deliver, then we just return the
387 ;;; IR2-Continuation-Locs. Otherwise we make a new list padded as necessary by
388 ;;; discarded TNs. We always return a TN of the specified type, using the
389 ;;; continuation locs only when they are of the correct type.
390 ;;;
391 (defun continuation-result-tns (cont types)
392 (declare (type continuation cont) (type list types))
393 (let ((2cont (continuation-info cont)))
394 (if (not 2cont)
395 (mapcar #'make-normal-tn types)
396 (ecase (ir2-continuation-kind 2cont)
397 (:fixed
398 (let* ((locs (ir2-continuation-locs 2cont))
399 (nlocs (length locs))
400 (ntypes (length types)))
401 (if (and (= nlocs ntypes)
402 (do ((loc locs (cdr loc))
403 (type types (cdr type)))
404 ((null loc) t)
405 (unless (eq (tn-primitive-type (car loc)) (car type))
406 (return nil))))
407 locs
408 (mapcar #'(lambda (loc type)
409 (if (eq (tn-primitive-type loc) type)
410 loc
411 (make-normal-tn type)))
412 (if (< nlocs ntypes)
413 (append locs
414 (mapcar #'make-normal-tn
415 (subseq types nlocs)))
416 locs)
417 types))))
418 (:unknown
419 (mapcar #'make-normal-tn types))))))
420
421
422 ;;; Make-Standard-Value-Tns -- Internal
423 ;;;
424 ;;; Make the first N standard value TNs, returning them in a list.
425 ;;;
426 (defun make-standard-value-tns (n)
427 (declare (type unsigned-byte n))
428 (collect ((res))
429 (dotimes (i n)
430 (res (standard-argument-location i)))
431 (res)))
432
433
434 ;;; Standard-Result-TNs -- Internal
435 ;;;
436 ;;; Return a list of TNs wired to the standard value passing conventions
437 ;;; that can be used to receive values according to the unknown-values
438 ;;; convention. This is used with together Move-Continuation-Result for
439 ;;; delivering unknown values to a fixed values continuation.
440 ;;;
441 ;;; If the continuation isn't annotated, then we treat as 0-values,
442 ;;; returning an empty list of temporaries.
443 ;;;
444 ;;; If the continuation is annotated, then it must be :Fixed.
445 ;;;
446 (defun standard-result-tns (cont)
447 (declare (type continuation cont))
448 (let ((2cont (continuation-info cont)))
449 (if 2cont
450 (ecase (ir2-continuation-kind 2cont)
451 (:fixed
452 (make-standard-value-tns (length (ir2-continuation-locs 2cont)))))
453 ())))
454
455
456 ;;; Move-Results-Coerced -- Internal
457 ;;;
458 ;;; Just move each Src TN into the corresponding Dest TN, defaulting any
459 ;;; unsupplied source values to NIL. We let Emit-Move worry about doing the
460 ;;; appropriate coercions.
461 ;;;
462 (defun move-results-coerced (node block src dest)
463 (declare (type node node) (type ir2-block block) (list src dest))
464 (let ((nsrc (length src))
465 (ndest (length dest)))
466 (mapc #'(lambda (from to)
467 (unless (eq from to)
468 (emit-move node block from to)))
469 (if (> ndest nsrc)
470 (append src (make-list (- ndest nsrc)
471 :initial-element (emit-constant nil)))
472 src)
473 dest))
474 (undefined-value))
475
476
477 ;;; Move-Continuation-Result -- Internal
478 ;;;
479 ;;; If necessary, emit coercion code needed to deliver the
480 ;;; Results to the specified continuation. Node and block provide context for
481 ;;; emitting code. Although usually obtained from Standard-Result-TNs or
482 ;;; Continuation-Result-TNs, Results my be a list of any type or number of TNs.
483 ;;;
484 ;;; If the continuation is fixed values, then move the results into the
485 ;;; continuation locations. If the continuation is unknown values, then do the
486 ;;; moves into the standard value locations, and use Push-Values to put the
487 ;;; values on the stack.
488 ;;;
489 (defun move-continuation-result (node block results cont)
490 (declare (type node node) (type ir2-block block)
491 (list results) (type continuation cont))
492 (let* ((2cont (continuation-info cont)))
493 (when 2cont
494 (ecase (ir2-continuation-kind 2cont)
495 (:fixed
496 (let ((locs (ir2-continuation-locs 2cont)))
497 (unless (eq locs results)
498 (move-results-coerced node block results locs))))
499 (:unknown
500 (let* ((nvals (length results))
501 (locs (make-standard-value-tns nvals)))
502 (move-results-coerced node block results locs)
503 (vop* push-values node block
504 ((reference-tn-list locs nil))
505 ((reference-tn-list (ir2-continuation-locs 2cont) t))
506 nvals))))))
507 (undefined-value))
508
509
510 ;;;; Template conversion:
511
512
513 ;;; Reference-Arguments -- Internal
514 ;;;
515 ;;; Build a TN-Refs list that represents access to the values of the
516 ;;; specified list of continuations Args for Template. Any :CONSTANT arguments
517 ;;; are returned in the second value as a list rather than being accessed as a
518 ;;; normal argument. Node and Block provide the context for emitting any
519 ;;; necessary type-checking code.
520 ;;;
521 (defun reference-arguments (node block args template)
522 (declare (type node node) (type ir2-block block) (list args)
523 (type template template))
524 (collect ((info-args))
525 (let ((last nil)
526 (first nil))
527 (do ((args args (cdr args))
528 (types (template-arg-types template) (cdr types)))
529 ((null args))
530 (let ((type (first types))
531 (arg (first args)))
532 (if (and (consp type) (eq (car type) ':constant))
533 (info-args (continuation-value arg))
534 (let ((ref (reference-tn (continuation-tn node block arg) nil)))
535 (if last
536 (setf (tn-ref-across last) ref)
537 (setf first ref))
538 (setq last ref)))))
539
540 (values (the (or tn-ref null) first) (info-args)))))
541
542
543 ;;; IR2-Convert-Conditional -- Internal
544 ;;;
545 ;;; Convert a conditional template. We try to exploit any drop-through, but
546 ;;; emit an unconditional branch afterward if we fail. Not-P is true if the
547 ;;; sense of the Template's test should be negated.
548 ;;;
549 (defun ir2-convert-conditional (node block template args info-args if not-p)
550 (declare (type node node) (type ir2-block block)
551 (type template template) (type (or tn-ref null) args)
552 (list info-args) (type cif if) (type boolean not-p))
553 (assert (= (template-info-arg-count template) (+ (length info-args) 2)))
554 (let ((consequent (if-consequent if))
555 (alternative (if-alternative if)))
556 (cond ((drop-thru-p if consequent)
557 (emit-template node block template args nil
558 (list* (block-label alternative) (not not-p)
559 info-args)))
560 (t
561 (emit-template node block template args nil
562 (list* (block-label consequent) not-p info-args))
563 (unless (drop-thru-p if alternative)
564 (vop branch node block (block-label alternative)))))))
565
566
567 ;;; IR2-Convert-IF -- Internal
568 ;;;
569 ;;; Convert an IF that isn't the DEST of a conditional template.
570 ;;;
571 (defun ir2-convert-if (node block)
572 (declare (type ir2-block block) (type cif node))
573 (let* ((test (if-test node))
574 (test-ref (reference-tn (continuation-tn node block test) nil))
575 (nil-ref (reference-tn (emit-constant nil) nil)))
576 (setf (tn-ref-across test-ref) nil-ref)
577 (ir2-convert-conditional node block (template-or-lose 'if-eq *backend*)
578 test-ref () node t)))
579
580
581 ;;; FIND-TEMPLATE-RESULT-TYPES -- Internal
582 ;;;
583 ;;; Return a list of primitive-types that we can pass to
584 ;;; CONTINUATION-RESULT-TNS describing the result types we want for a template
585 ;;; call. We duplicate here the determination of output type that was done in
586 ;;; initially selecting the template, so we know that the types we find are
587 ;;; allowed by the template output type restrictions.
588 ;;;
589 (defun find-template-result-types (call cont template rtypes)
590 (declare (type combination call) (type continuation cont)
591 (type template template) (list rtypes))
592 (let* ((dtype (node-derived-type call))
593 (type (if (and (or (eq (template-policy template) :safe)
594 (policy call (= safety 0)))
595 (continuation-type-check cont))
596 (values-type-intersection
597 dtype
598 (continuation-asserted-type cont))
599 dtype))
600 (types (mapcar #'primitive-type
601 (if (values-type-p type)
602 (append (values-type-required type)
603 (values-type-optional type))
604 (list type)))))
605 (let ((nvals (length rtypes))
606 (ntypes (length types)))
607 (cond ((< ntypes nvals)
608 (append types
609 (make-list (- nvals ntypes)
610 :initial-element
611 (backend-any-primitive-type *backend*))))
612 ((> ntypes nvals)
613 (subseq types 0 nvals))
614 (t
615 types)))))
616
617
618 ;;; MAKE-TEMPLATE-RESULT-TNS -- Internal
619 ;;;
620 ;;; Return a list of TNs usable in a Call to Template delivering values to
621 ;;; Cont. As an efficiency hack, we pick off the common case where the
622 ;;; continuation is fixed values and has locations that satisfy the result
623 ;;; restrictions. This can fail when there is a type check or a values count
624 ;;; mismatch.
625 ;;;
626 (defun make-template-result-tns (call cont template rtypes)
627 (declare (type combination call) (type continuation cont)
628 (type template template) (list rtypes))
629 (let ((2cont (continuation-info cont)))
630 (if (and 2cont (eq (ir2-continuation-kind 2cont) :fixed))
631 (let ((locs (ir2-continuation-locs 2cont)))
632 (if (and (= (length rtypes) (length locs))
633 (do ((loc locs (cdr loc))
634 (rtype rtypes (cdr rtype)))
635 ((null loc) t)
636 (unless (operand-restriction-ok
637 (car rtype)
638 (tn-primitive-type (car loc))
639 :t-ok nil)
640 (return nil))))
641 locs
642 (continuation-result-tns
643 cont
644 (find-template-result-types call cont template rtypes))))
645 (continuation-result-tns
646 cont
647 (find-template-result-types call cont template rtypes)))))
648
649
650 ;;; IR2-Convert-Template -- Internal
651 ;;;
652 ;;; Get the operands into TNs, make TN-Refs for them, and then call the
653 ;;; template emit function.
654 ;;;
655 (defun ir2-convert-template (call block)
656 (declare (type combination call) (type ir2-block block))
657 (let* ((template (combination-info call))
658 (cont (node-cont call))
659 (rtypes (template-result-types template)))
660 (multiple-value-bind
661 (args info-args)
662 (reference-arguments call block (combination-args call) template)
663 (assert (not (template-more-results-type template)))
664 (if (eq rtypes :conditional)
665 (ir2-convert-conditional call block template args info-args
666 (continuation-dest cont) nil)
667 (let* ((results (make-template-result-tns call cont template rtypes))
668 (r-refs (reference-tn-list results t)))
669 (assert (= (length info-args)
670 (template-info-arg-count template)))
671 (if info-args
672 (emit-template call block template args r-refs info-args)
673 (emit-template call block template args r-refs))
674 (move-continuation-result call block results cont)))))
675 (undefined-value))
676
677
678 ;;; %%Primitive IR2 Convert -- Internal
679 ;;;
680 ;;; We don't have to do much because operand count checking is done by IR1
681 ;;; conversion. The only difference between this and the function case of
682 ;;; IR2-Convert-Template is that there can be codegen-info arguments.
683 ;;;
684 (defoptimizer (%%primitive ir2-convert) ((template info &rest args) call block)
685 (let* ((template (continuation-value template))
686 (info (continuation-value info))
687 (cont (node-cont call))
688 (rtypes (template-result-types template))
689 (results (make-template-result-tns call cont template rtypes))
690 (r-refs (reference-tn-list results t)))
691 (multiple-value-bind
692 (args info-args)
693 (reference-arguments call block (cddr (combination-args call))
694 template)
695 (assert (not (template-more-results-type template)))
696 (assert (not (eq rtypes :conditional)))
697 (assert (null info-args))
698
699 (if info
700 (emit-template call block template args r-refs info)
701 (emit-template call block template args r-refs))
702
703 (move-continuation-result call block results cont)))
704 (undefined-value))
705
706
707 ;;;; Local call:
708
709 ;;; IR2-Convert-Let -- Internal
710 ;;;
711 ;;; Convert a let by moving the argument values into the variables. Since a
712 ;;; a let doesn't have any passing locations, we move the arguments directly
713 ;;; into the variables. We must also allocate any indirect value cells, since
714 ;;; there is no function prologue to do this.
715 ;;;
716 (defun ir2-convert-let (node block fun)
717 (declare (type combination node) (type ir2-block block) (type clambda fun))
718 (loop for var in (lambda-vars fun)
719 and arg in (basic-combination-args node)
720 when arg do
721 (let ((src (continuation-tn node block arg))
722 (dest (leaf-info var)))
723 (if (lambda-var-indirect var)
724 (do-make-value-cell node block src dest)
725 (emit-move node block src dest))))
726 (values))
727
728
729 ;;; EMIT-PSETQ-MOVES -- Internal
730 ;;;
731 ;;; Emit any necessary moves into assignment temps for a local call to Fun.
732 ;;; We return two lists of TNs: TNs holding the actual argument values, and
733 ;;; (possibly EQ) TNs that are the actual destination of the arguments. When
734 ;;; necessary, we allocate temporaries for arguments to preserve paralell
735 ;;; assignment semantics. These lists exclude unused arguments and include
736 ;;; implicit environment arguments, i.e. they exactly correspond to the
737 ;;; arguments passed.
738 ;;;
739 ;;; OLD-FP is the TN currently holding the value we want to pass as OLD-FP. If
740 ;;; null, then the call is to the same environment (an :ASSIGNMENT), so we
741 ;;; only move the arguments, and leave the environment alone.
742 ;;;
743 (defun emit-psetq-moves (node block fun old-fp)
744 (declare (type combination node) (type ir2-block block) (type clambda fun)
745 (type (or tn null) old-fp))
746 (let* ((called-env (environment-info (lambda-environment fun)))
747 (this-1env (node-environment node))
748 (actuals (mapcar #'(lambda (x)
749 (when x
750 (continuation-tn node block x)))
751 (combination-args node))))
752 (collect ((temps)
753 (locs))
754 (dolist (var (lambda-vars fun))
755 (let ((actual (pop actuals))
756 (loc (leaf-info var)))
757 (when actual
758 (cond
759 ((lambda-var-indirect var)
760 (let ((temp
761 (make-normal-tn (backend-any-primitive-type *backend*))))
762 (do-make-value-cell node block actual temp)
763 (temps temp)))
764 ((member actual (locs))
765 (let ((temp (make-normal-tn (tn-primitive-type loc))))
766 (emit-move node block actual temp)
767 (temps temp)))
768 (t
769 (temps actual)))
770 (locs loc))))
771
772 (when old-fp
773 (dolist (thing (ir2-environment-environment called-env))
774 (temps (find-in-environment (car thing) this-1env))
775 (locs (cdr thing)))
776
777 (temps old-fp)
778 (locs (ir2-environment-old-fp called-env)))
779
780 (values (temps) (locs)))))
781
782
783 ;;; IR2-Convert-Tail-Local-Call -- Internal
784 ;;;
785 ;;; A tail-recursive local call is done by emitting moves of stuff into the
786 ;;; appropriate passing locations. After setting up the args and environment,
787 ;;; we just move our return-pc into the called function's passing
788 ;;; location.
789 ;;;
790 (defun ir2-convert-tail-local-call (node block fun)
791 (declare (type combination node) (type ir2-block block) (type clambda fun))
792 (let ((this-env (environment-info (node-environment node))))
793 (multiple-value-bind
794 (temps locs)
795 (emit-psetq-moves node block fun (ir2-environment-old-fp this-env))
796
797 (mapc #'(lambda (temp loc)
798 (emit-move node block temp loc))
799 temps locs))
800
801 (emit-move node block
802 (ir2-environment-return-pc this-env)
803 (ir2-environment-return-pc-pass
804 (environment-info
805 (lambda-environment fun)))))
806
807 (undefined-value))
808
809
810 ;;; IR2-CONVERT-ASSIGNMENT -- Internal
811 ;;;
812 ;;; Convert an :ASSIGNMENT call. This is just like a tail local call,
813 ;;; except that the caller and callee environment are the same, so we don't
814 ;;; need to mess with the environment locations, return PC, etc.
815 ;;;
816 (defun ir2-convert-assignment (node block fun)
817 (declare (type combination node) (type ir2-block block) (type clambda fun))
818 (multiple-value-bind
819 (temps locs)
820 (emit-psetq-moves node block fun nil)
821
822 (mapc #'(lambda (temp loc)
823 (emit-move node block temp loc))
824 temps locs))
825 (undefined-value))
826
827
828 ;;; IR2-CONVERT-LOCAL-CALL-ARGS -- Internal
829 ;;;
830 ;;; Do stuff to set up the arguments to a non-tail local call (including
831 ;;; implicit environment args.) We allocate a frame (returning the FP and
832 ;;; NFP), and also compute the TN-Refs list for the values to pass and the list
833 ;;; of passing location TNs.
834 ;;;
835 (defun ir2-convert-local-call-args (node block fun)
836 (declare (type combination node) (type ir2-block block) (type clambda fun))
837 (let ((fp (make-stack-pointer-tn))
838 (nfp (make-number-stack-pointer-tn))
839 (old-fp (make-stack-pointer-tn)))
840 (multiple-value-bind (temps locs)
841 (emit-psetq-moves node block fun old-fp)
842 (vop current-fp node block old-fp)
843 (vop allocate-frame node block
844 (environment-info (lambda-environment fun))
845 #+(or sparc ppc)
846 (or *always-clear-stack*
847 (and *enable-stack-clearing*
848 (policy node (= speed 3) (>= space 2))))
849 fp nfp)
850 (values fp nfp temps (mapcar #'make-alias-tn locs)))))
851
852
853 ;;; IR2-Convert-Local-Known-Call -- Internal
854 ;;;
855 ;;; Handle a non-TR known-values local call. We Emit the call, then move
856 ;;; the results to the continuation's destination.
857 ;;;
858 (defun ir2-convert-local-known-call (node block fun returns cont start)
859 (declare (type node node) (type ir2-block block) (type clambda fun)
860 (type return-info returns) (type continuation cont)
861 (type label start))
862 (multiple-value-bind (fp nfp temps arg-locs)
863 (ir2-convert-local-call-args node block fun)
864 (let ((locs (return-info-locations returns)))
865 (vop* known-call-local node block
866 (fp nfp (reference-tn-list temps nil))
867 ((reference-tn-list locs t))
868 arg-locs (environment-info (lambda-environment fun)) start)
869 (move-continuation-result node block locs cont)))
870 (undefined-value))
871
872
873 ;;; IR2-Convert-Local-Unknown-Call -- Internal
874 ;;;
875 ;;; Handle a non-TR unknown-values local call. We do different things
876 ;;; depending on what kind of values the continuation wants.
877 ;;;
878 ;;; If Cont is :Unknown, then we use the "Multiple-" variant, directly
879 ;;; specifying the continuation's Locs as the VOP results so that we don't have
880 ;;; to do anything after the call.
881 ;;;
882 ;;; Otherwise, we use Standard-Result-Tns to get wired result TNs, and
883 ;;; then call Move-Continuation-Result to do any necessary type checks or
884 ;;; coercions.
885 ;;;
886 (defun ir2-convert-local-unknown-call (node block fun cont start)
887 (declare (type node node) (type ir2-block block) (type clambda fun)
888 (type continuation cont) (type label start))
889 (multiple-value-bind (fp nfp temps arg-locs)
890 (ir2-convert-local-call-args node block fun)
891 (let ((2cont (continuation-info cont))
892 (env (environment-info (lambda-environment fun)))
893 (temp-refs (reference-tn-list temps nil)))
894 (if (and 2cont (eq (ir2-continuation-kind 2cont) :unknown))
895 (vop* multiple-call-local node block (fp nfp temp-refs)
896 ((reference-tn-list (ir2-continuation-locs 2cont) t))
897 arg-locs env start)
898 (let ((locs (standard-result-tns cont)))
899 (vop* call-local node block
900 (fp nfp temp-refs)
901 ((reference-tn-list locs t))
902 arg-locs env start (length locs))
903 (move-continuation-result node block locs cont)))))
904 (undefined-value))
905
906
907 ;;; IR2-Convert-Local-Call -- Internal
908 ;;;
909 ;;; Dispatch to the appropriate function, depending on whether we have a
910 ;;; let, tail or normal call. If the function doesn't return, call it using
911 ;;; the unknown-value convention. We could compile it as a tail call, but that
912 ;;; might seem confusing in the debugger.
913 ;;;
914 (defun ir2-convert-local-call (node block)
915 (declare (type combination node) (type ir2-block block))
916 (let* ((fun (ref-leaf (continuation-use (basic-combination-fun node))))
917 (kind (functional-kind fun)))
918 (cond ((eq kind :let)
919 (ir2-convert-let node block fun))
920 ((eq kind :assignment)
921 (ir2-convert-assignment node block fun))
922 ((node-tail-p node)
923 (ir2-convert-tail-local-call node block fun))
924 (t
925 (let ((start (block-label (node-block (lambda-bind fun))))
926 (returns (tail-set-info (lambda-tail-set fun)))
927 (cont (node-cont node)))
928 (ecase (if returns
929 (return-info-kind returns)
930 :unknown)
931 (:unknown
932 (ir2-convert-local-unknown-call node block fun cont start))
933 (:fixed
934 (ir2-convert-local-known-call node block fun returns
935 cont start)))))))
936 (undefined-value))
937
938
939 ;;;; Full call:
940
941
942 ;;; Function-Continuation-TN -- Internal
943 ;;;
944 ;;; Given a function continuation Fun, return as values a TN holding the
945 ;;; thing that we call and true if the thing is named (false if it is a
946 ;;; function). There are two interesting non-named cases:
947 ;;; -- Known to be a function, no check needed: return the continuation loc.
948 ;;; -- Not known what it is.
949 ;;;
950 (defun function-continuation-tn (node block cont)
951 (declare (type continuation cont))
952 (let ((2cont (continuation-info cont)))
953 (if (eq (ir2-continuation-kind 2cont) :delayed)
954 (let ((name (continuation-function-name cont t)))
955 (assert name)
956 (values (make-load-time-constant-tn :fdefinition name) t))
957 (let* ((locs (ir2-continuation-locs 2cont))
958 (loc (first locs))
959 (check (continuation-type-check cont))
960 (function-ptype (primitive-type-or-lose 'function *backend*)))
961 (assert (and (eq (ir2-continuation-kind 2cont) :fixed)
962 (= (length locs) 1)))
963 (cond ((eq (tn-primitive-type loc) function-ptype)
964 (assert (not (eq check t)))
965 (values loc nil))
966 (t
967 (let ((temp (make-normal-tn function-ptype)))
968 (assert (and (eq (ir2-continuation-primitive-type 2cont)
969 function-ptype)
970 (eq check t)))
971 (emit-type-check node block loc temp
972 (specifier-type 'function))
973 (values temp nil))))))))
974
975
976 ;;; MOVE-TAIL-FULL-CALL-ARGS -- Internal
977 ;;;
978 ;;; Set up the args to Node in the current frame, and return a tn-ref list
979 ;;; for the passing locations.
980 ;;;
981 (defun move-tail-full-call-args (node block)
982 (declare (type combination node) (type ir2-block block))
983 (let ((args (basic-combination-args node))
984 (last nil)
985 (first nil))
986 (dotimes (num (length args))
987 (let ((loc (standard-argument-location num)))
988 (emit-move node block (continuation-tn node block (elt args num)) loc)
989 (let ((ref (reference-tn loc nil)))
990 (if last
991 (setf (tn-ref-across last) ref)
992 (setf first ref))
993 (setq last ref))))
994 first))
995
996
997 ;;; IR2-Convert-Tail-Full-Call -- Internal
998 ;;;
999 ;;; Move the arguments into the passing locations and do a (possibly named)
1000 ;;; tail call.
1001 ;;;
1002 (defun ir2-convert-tail-full-call (node block)
1003 (declare (type combination node) (type ir2-block block))
1004 (let* ((env (environment-info (node-environment node)))
1005 (args (basic-combination-args node))
1006 (nargs (length args))
1007 (pass-refs (move-tail-full-call-args node block))
1008 (old-fp (ir2-environment-old-fp env))
1009 (return-pc (ir2-environment-return-pc env)))
1010
1011 (multiple-value-bind
1012 (fun-tn named)
1013 (function-continuation-tn node block (basic-combination-fun node))
1014 (if named
1015 (vop* tail-call-named node block
1016 (fun-tn old-fp return-pc pass-refs)
1017 (nil)
1018 nargs)
1019 (vop* tail-call node block
1020 (fun-tn old-fp return-pc pass-refs)
1021 (nil)
1022 nargs))))
1023
1024 (undefined-value))
1025
1026
1027 ;;; IR2-CONVERT-FULL-CALL-ARGS -- Internal
1028 ;;;
1029 ;;; Like IR2-CONVERT-LOCAL-CALL-ARGS, only different.
1030 ;;;
1031 (defun ir2-convert-full-call-args (node block)
1032 (declare (type combination node) (type ir2-block block))
1033 (let* ((args (basic-combination-args node))
1034 (fp (make-stack-pointer-tn))
1035 (nargs (length args)))
1036 (vop allocate-full-call-frame node block nargs fp)
1037 (collect ((locs))
1038 (let ((last nil)
1039 (first nil))
1040 (dotimes (num nargs)
1041 (locs (standard-argument-location num))
1042 (let ((ref (reference-tn (continuation-tn node block (elt args num))
1043 nil)))
1044 (if last
1045 (setf (tn-ref-across last) ref)
1046 (setf first ref))
1047 (setq last ref)))
1048
1049 (values fp first (locs) nargs)))))
1050
1051
1052 ;;; IR2-Convert-Fixed-Full-Call -- Internal
1053 ;;;
1054 ;;; Do full call when a fixed number of values are desired. We make
1055 ;;; Standard-Result-TNs for our continuation, then deliver the result using
1056 ;;; Move-Continuation-Result. We do named or normal call, as appropriate.
1057 ;;;
1058 (defun ir2-convert-fixed-full-call (node block)
1059 (declare (type combination node) (type ir2-block block))
1060 (multiple-value-bind (fp args arg-locs nargs)
1061 (ir2-convert-full-call-args node block)
1062 (let* ((cont (node-cont node))
1063 (locs (standard-result-tns cont))
1064 (loc-refs (reference-tn-list locs t))
1065 (nvals (length locs)))
1066 (multiple-value-bind
1067 (fun-tn named)
1068 (function-continuation-tn node block (basic-combination-fun node))
1069 (if named
1070 (vop* call-named node block (fp fun-tn args) (loc-refs)
1071 arg-locs nargs nvals)
1072 (vop* call node block (fp fun-tn args) (loc-refs)
1073 arg-locs nargs nvals))
1074 (move-continuation-result node block locs cont))))
1075 (undefined-value))
1076
1077
1078 ;;; IR2-Convert-Multiple-Full-Call -- Internal
1079 ;;;
1080 ;;; Do full call when unknown values are desired.
1081 ;;;
1082 (defun ir2-convert-multiple-full-call (node block)
1083 (declare (type combination node) (type ir2-block block))
1084 (multiple-value-bind (fp args arg-locs nargs)
1085 (ir2-convert-full-call-args node block)
1086 (let* ((cont (node-cont node))
1087 (locs (ir2-continuation-locs (continuation-info cont)))
1088 (loc-refs (reference-tn-list locs t)))
1089 (multiple-value-bind
1090 (fun-tn named)
1091 (function-continuation-tn node block (basic-combination-fun node))
1092 (if named
1093 (vop* multiple-call-named node block (fp fun-tn args) (loc-refs)
1094 arg-locs nargs)
1095 (vop* multiple-call node block (fp fun-tn args) (loc-refs)
1096 arg-locs nargs)))))
1097 (undefined-value))
1098
1099
1100 ;;; IR2-Convert-Full-Call -- Internal
1101 ;;;
1102 ;;; If the call is in a TR position and the return convention is standard,
1103 ;;; then do a tail full call. If one or fewer values are desired, then use a
1104 ;;; single-value call, otherwise use a multiple-values call.
1105 ;;;
1106 (defun ir2-convert-full-call (node block)
1107 (declare (type combination node) (type ir2-block block))
1108 (let ((2cont (continuation-info (node-cont node))))
1109 (cond ((node-tail-p node)
1110 (ir2-convert-tail-full-call node block))
1111 ((and 2cont
1112 (eq (ir2-continuation-kind 2cont) :unknown))
1113 (ir2-convert-multiple-full-call node block))
1114 (t
1115 (ir2-convert-fixed-full-call node block))))
1116 (undefined-value))
1117
1118
1119 ;;;; Function entry:
1120
1121 ;;; Init-XEP-Environment -- Internal
1122 ;;;
1123 ;;; Do all the stuff that needs to be done on XEP entry:
1124 ;;; -- Create frame
1125 ;;; -- Copy any more arg
1126 ;;; -- Set up the environment, accessing any closure variables
1127 ;;; -- Move args from the standard passing locations to their internal
1128 ;;; locations.
1129 ;;;
1130 (defun init-xep-environment (node block fun)
1131 (declare (type bind node) (type ir2-block block) (type clambda fun))
1132 (let ((start-label (entry-info-offset (leaf-info fun)))
1133 (env (environment-info (node-environment node))))
1134 (let ((ef (functional-entry-function fun)))
1135 (cond ((and (optional-dispatch-p ef) (optional-dispatch-more-entry ef))
1136 ;; Special case the xep-allocate-frame + copy-more-arg case.
1137 (vop xep-allocate-frame node block start-label t
1138 #+(or sparc ppc)
1139 (or *always-clear-stack*
1140 (and *enable-stack-clearing*
1141 (policy node (= speed 3) (>= space 2)))))
1142 (vop copy-more-arg node block (optional-dispatch-max-args ef)))
1143 (t
1144 ;; No more args, so normal entry.
1145 (vop xep-allocate-frame node block start-label nil
1146 #+(or sparc ppc)
1147 (or *always-clear-stack*
1148 (and *enable-stack-clearing*
1149 (policy node (>= space 2) (= speed 3)))))))
1150 (if (ir2-environment-environment env)
1151 (let ((closure
1152 (make-normal-tn (backend-any-primitive-type *backend*))))
1153 (vop setup-closure-environment node block start-label closure)
1154 (when (getf (functional-plist ef) :fin-function)
1155 (vop funcallable-instance-lexenv node block closure closure))
1156 (let ((n -1))
1157 (dolist (loc (ir2-environment-environment env))
1158 (vop closure-ref node block closure (incf n) (cdr loc)))))
1159 (vop setup-environment node block start-label)))
1160
1161 (unless (eq (functional-kind fun) :top-level)
1162 (let ((vars (lambda-vars fun))
1163 (n 0))
1164 (when (leaf-refs (first vars))
1165 (emit-move node block (make-argument-count-location)
1166 (leaf-info (first vars))))
1167 (dolist (arg (rest vars))
1168 (when (leaf-refs arg)
1169 (let ((pass (standard-argument-location n))
1170 (home (leaf-info arg)))
1171 (if (lambda-var-indirect arg)
1172 (do-make-value-cell node block pass home)
1173 (emit-move node block pass home))))
1174 (incf n))))
1175
1176 (emit-move node block (make-old-fp-passing-location t)
1177 (ir2-environment-old-fp env)))
1178
1179 (undefined-value))
1180
1181
1182 ;;; IR2-Convert-Bind -- Internal
1183 ;;;
1184 ;;; Emit function prolog code. This is only called on bind nodes for
1185 ;;; functions that allocate environments. All semantics of let calls are
1186 ;;; handled by IR2-Convert-Let.
1187 ;;;
1188 ;;; If not an XEP, all we do is move the return PC from its passing
1189 ;;; location, since in a local call, the caller allocates the frame and sets up
1190 ;;; the arguments.
1191 ;;;
1192 (defun ir2-convert-bind (node block)
1193 (declare (type bind node) (type ir2-block block))
1194 (let* ((fun (bind-lambda node))
1195 (env (environment-info (lambda-environment fun))))
1196 (assert (member (functional-kind fun)
1197 '(nil :external :optional :top-level :cleanup)))
1198
1199 (when (external-entry-point-p fun)
1200 (init-xep-environment node block fun)
1201 (when *collect-dynamic-statistics*
1202 (vop count-me node block *dynamic-counts-tn*
1203 (block-number (ir2-block-block block)))))
1204
1205 (emit-move node block (ir2-environment-return-pc-pass env)
1206 (ir2-environment-return-pc env))
1207
1208 (let ((lab (gen-label)))
1209 (setf (ir2-environment-environment-start env) lab)
1210 (vop note-environment-start node block lab)))
1211
1212 (undefined-value))
1213
1214
1215 ;;;; Function return:
1216
1217 ;;; IR2-Convert-Return -- Internal
1218 ;;;
1219 ;;; Do stuff to return from a function with the specified values and
1220 ;;; convention. If the return convention is :Fixed and we aren't returning
1221 ;;; from an XEP, then we do a known return (letting representation selection
1222 ;;; insert the correct move-arg VOPs.) Otherwise, we use the unknown-values
1223 ;;; convention. If there is a fixed number of return values, then use Return,
1224 ;;; otherwise use Return-Multiple.
1225 ;;;
1226 (defun ir2-convert-return (node block)
1227 (declare (type creturn node) (type ir2-block block))
1228 (let* ((cont (return-result node))
1229 (2cont (continuation-info cont))
1230 (cont-kind (ir2-continuation-kind 2cont))
1231 (fun (return-lambda node))
1232 (env (environment-info (lambda-environment fun)))
1233 (old-fp (ir2-environment-old-fp env))
1234 (return-pc (ir2-environment-return-pc env))
1235 (returns (tail-set-info (lambda-tail-set fun))))
1236 (cond
1237 ((and (eq (return-info-kind returns) :fixed)
1238 (not (external-entry-point-p fun)))
1239 (let ((locs (continuation-tns node block cont
1240 (return-info-types returns))))
1241 (vop* known-return node block
1242 (old-fp return-pc (reference-tn-list locs nil))
1243 (nil)
1244 (return-info-locations returns))))
1245 ((eq cont-kind :fixed)
1246 (let* ((types (mapcar #'tn-primitive-type (ir2-continuation-locs 2cont)))
1247 (cont-locs (continuation-tns node block cont types))
1248 (nvals (length cont-locs))
1249 (locs (make-standard-value-tns nvals)))
1250 (mapc #'(lambda (val loc)
1251 (emit-move node block val loc))
1252 cont-locs
1253 locs)
1254 (if (= nvals 1)
1255 (vop return-single node block old-fp return-pc (car locs))
1256 (vop* return node block
1257 (old-fp return-pc (reference-tn-list locs nil))
1258 (nil)
1259 nvals))))
1260 (t
1261 (assert (eq cont-kind :unknown))
1262 (vop* return-multiple node block
1263 (old-fp return-pc
1264 (reference-tn-list (ir2-continuation-locs 2cont) nil))
1265 (nil)))))
1266
1267 (undefined-value))
1268
1269
1270 ;;;; Debugger hooks:
1271
1272 ;;; This is used by the debugger to find the top function on the stack. It
1273 ;;; returns the OLD-FP and RETURN-PC for the current function as multiple
1274 ;;; values.
1275 ;;;
1276 (defoptimizer (kernel:%caller-frame-and-pc ir2-convert) (() node block)
1277 (let ((env (environment-info (node-environment node))))
1278 (move-continuation-result node block
1279 (list (ir2-environment-old-fp env)
1280 (ir2-environment-return-pc env))
1281 (node-cont node))))
1282
1283
1284 ;;;; Multiple values:
1285
1286 ;;; IR2-Convert-MV-Bind -- Internal
1287 ;;;
1288 ;;; Almost identical to IR2-Convert-Let. Since LTN annotates the
1289 ;;; continuation for the correct number of values (with the continuation user
1290 ;;; responsible for defaulting), we can just pick them up from the
1291 ;;; continuation.
1292 ;;;
1293 (defun ir2-convert-mv-bind (node block)
1294 (declare (type mv-combination node) (type ir2-block block))
1295 (let* ((cont (first (basic-combination-args node)))
1296 (fun (ref-leaf (continuation-use (basic-combination-fun node))))
1297 (vars (lambda-vars fun)))
1298 (assert (eq (functional-kind fun) :mv-let))
1299 (mapc #'(lambda (src var)
1300 (when (leaf-refs var)
1301 (let ((dest (leaf-info var)))
1302 (if (lambda-var-indirect var)
1303 (do-make-value-cell node block src dest)
1304 (emit-move node block src dest)))))
1305 (continuation-tns node block cont
1306 (mapcar #'(lambda (x)
1307 (primitive-type (leaf-type x)))
1308 vars))
1309 vars))
1310 (undefined-value))
1311
1312
1313 ;;; IR2-Convert-MV-Call -- Internal
1314 ;;;
1315 ;;; Emit the appropriate fixed value, unknown value or tail variant of
1316 ;;; Call-Variable. Note that we only need to pass the values start for the
1317 ;;; first argument: all the other argument continuation TNs are ignored. This
1318 ;;; is because we require all of the values globs to be contiguous and on stack
1319 ;;; top.
1320 ;;;
1321 (defun ir2-convert-mv-call (node block)
1322 (declare (type mv-combination node) (type ir2-block block))
1323 (assert (basic-combination-args node))
1324 (let* ((start-cont (continuation-info (first (basic-combination-args node))))
1325 (start (first (ir2-continuation-locs start-cont)))
1326 (tails (and (node-tail-p node)
1327 (lambda-tail-set (node-home-lambda node))))
1328 (cont (node-cont node))
1329 (2cont (continuation-info cont)))
1330 (multiple-value-bind
1331 (fun named)
1332 (function-continuation-tn node block (basic-combination-fun node))
1333 (assert (and (not named)
1334 (eq (ir2-continuation-kind start-cont) :unknown)))
1335 (cond
1336 (tails
1337 (let ((env (environment-info (node-environment node))))
1338 (vop tail-call-variable node block start fun
1339 (ir2-environment-old-fp env)
1340 (ir2-environment-return-pc env))))
1341 ((and 2cont
1342 (eq (ir2-continuation-kind 2cont) :unknown))
1343 (vop* multiple-call-variable node block (start fun nil)
1344 ((reference-tn-list (ir2-continuation-locs 2cont) t))))
1345 (t
1346 (let ((locs (standard-result-tns cont)))
1347 (vop* call-variable node block (start fun nil)
1348 ((reference-tn-list locs t)) (length locs))
1349 (move-continuation-result node block locs cont)))))))
1350
1351
1352 ;;; %Pop-Values IR2 convert -- Internal
1353 ;;;
1354 ;;; Reset the stack pointer to the start of the specified unknown-values
1355 ;;; continuation (discarding it and all values globs on top of it.)
1356 ;;;
1357 (defoptimizer (%pop-values ir2-convert) ((continuation) node block)
1358 (let ((2cont (continuation-info (continuation-value continuation))))
1359 (assert (eq (ir2-continuation-kind 2cont) :unknown))
1360 (vop reset-stack-pointer node block
1361 (first (ir2-continuation-locs 2cont)))))
1362
1363
1364 ;;; Values IR2 convert -- Internal
1365 ;;;
1366 ;;; Deliver the values TNs to Cont using Move-Continuation-Result.
1367 ;;;
1368 (defoptimizer (values ir2-convert) ((&rest values) node block)
1369 (let ((tns (mapcar #'(lambda (x)
1370 (continuation-tn node block x))
1371 values)))
1372 (move-continuation-result node block tns (node-cont node))))
1373
1374
1375 ;;; Values-List IR2 convert -- Internal
1376 ;;;
1377 ;;; In the normal case where unknown values are desired, we use the
1378 ;;; Values-List VOP. In the relatively unimportant case of Values-List for a
1379 ;;; fixed number of values, we punt by doing a full call to the Values-List
1380 ;;; function. This gets the full call VOP to deal with defaulting any
1381 ;;; unsupplied values. It seems unworthwhile to optimize this case.
1382 ;;;
1383 (defoptimizer (values-list ir2-convert) ((list) node block)
1384 (let* ((cont (node-cont node))
1385 (2cont (continuation-info cont)))
1386 (when 2cont
1387 (ecase (ir2-continuation-kind 2cont)
1388 (:fixed (ir2-convert-full-call node block))
1389 (:unknown
1390 (let ((locs (ir2-continuation-locs 2cont)))
1391 (vop* values-list node block
1392 ((continuation-tn node block list) nil)
1393 ((reference-tn-list locs t)))))))))
1394
1395
1396 (defoptimizer (%more-arg-values ir2-convert) ((context start count) node block)
1397 (let* ((cont (node-cont node))
1398 (2cont (continuation-info cont)))
1399 (when 2cont
1400 (ecase (ir2-continuation-kind 2cont)
1401 (:fixed (ir2-convert-full-call node block))
1402 (:unknown
1403 (let ((locs (ir2-continuation-locs 2cont)))
1404 (vop* %more-arg-values node block
1405 ((continuation-tn node block context)
1406 (continuation-tn node block start)
1407 (continuation-tn node block count)
1408 nil)
1409 ((reference-tn-list locs t)))))))))
1410
1411
1412 ;;;; Dynamic-Extent
1413
1414 (defoptimizer (%dynamic-extent ir2-convert) ((kind sp) node block)
1415 node block sp kind)
1416
1417 (defoptimizer (%dynamic-extent-start ir2-convert) (() node block)
1418 (let ((tn (environment-live-tn (make-stack-pointer-tn)
1419 (node-environment node)))
1420 (2cont (continuation-info (node-cont node))))
1421 (setf (ir2-continuation-locs 2cont) (list tn))
1422 (when *dynamic-extent-trace*
1423 (format t "~&===> %dynamic-extent-start ~s ~s~%" tn
1424 (node-cont node)))
1425 (vop %dynamic-extent-start node block tn)))
1426
1427 (defoptimizer (%dynamic-extent-end ir2-convert) ((kind sp) node block)
1428 (let* ((sp (continuation-value sp))
1429 (tn (first (ir2-continuation-locs (continuation-info sp)))))
1430 (when *dynamic-extent-trace*
1431 (format t "~&===> %dynamic-extent-end ~s ~s ~s~%"
1432 (continuation-value kind) sp tn))
1433 (vop %dynamic-extent-end node block tn)))
1434
1435
1436 ;;;; Special binding:
1437
1438 ;;; %Special-Bind, %Special-Unbind IR2 convert -- Internal
1439 ;;;
1440 ;;; Trivial, given our assumption of a shallow-binding implementation.
1441 ;;;
1442 (defoptimizer (%special-bind ir2-convert) ((var value) node block)
1443 (let ((name (leaf-name (continuation-value var))))
1444 (vop bind node block (continuation-tn node block value)
1445 (emit-constant name))))
1446 ;;;
1447 (defoptimizer (%special-unbind ir2-convert) ((var) node block)
1448 (vop unbind node block))
1449
1450
1451 ;;; PROGV IR1 convert -- Internal
1452 ;;;
1453 ;;; ### Not clear that this really belongs in this file, or should really be
1454 ;;; done this way, but this is the least violation of abstraction in the
1455 ;;; current setup. We don't want to wire shallow-binding assumptions into
1456 ;;; IR1tran.
1457 ;;;
1458 (def-ir1-translator progv ((vars vals &body body) start cont)
1459 (ir1-convert
1460 start cont
1461 (if (or *converting-for-interpreter* (byte-compiling))
1462 `(%progv ,vars ,vals #'(lambda () ,@body))
1463 (let ((bind (gensym "BIND"))
1464 (unbind (gensym "UNBIND")))
1465 (once-only ((n-save-bs '(%primitive current-binding-pointer)))
1466 `(unwind-protect
1467 (progn
1468 (labels ((,unbind (vars)
1469 (declare (optimize (speed 2) (debug 0)))
1470 (dolist (var vars)
1471 (%primitive bind nil var)
1472 (makunbound var)))
1473 (,bind (vars vals)
1474 (declare (optimize (speed 2) (debug 0)))
1475 (cond ((null vars))
1476 ((null vals) (,unbind vars))
1477 (t (%primitive bind (car vals) (car vars))
1478 (,bind (cdr vars) (cdr vals))))))
1479 (,bind ,vars ,vals))
1480 nil
1481 ,@body)
1482 (%primitive unbind-to-here ,n-save-bs)))))))
1483
1484
1485 ;;;; Non-local exit:
1486
1487 ;;; IR2-Convert-Exit -- Internal
1488 ;;;
1489 ;;; Convert a non-local lexical exit. First find the NLX-Info in our
1490 ;;; environment. Note that this is never called on the escape exits for Catch
1491 ;;; and Unwind-Protect, since the escape functions aren't IR2 converted.
1492 ;;;
1493 (defun ir2-convert-exit (node block)
1494 (declare (type exit node) (type ir2-block block))
1495 (let ((loc (find-in-environment (find-nlx-info (exit-entry node)
1496 (node-cont node))
1497 (node-environment node)))
1498 (temp (make-stack-pointer-tn))
1499 (value (exit-value node)))
1500 (vop value-cell-ref node block loc temp)
1501 (if value
1502 (let ((locs (ir2-continuation-locs (continuation-info value))))
1503 (vop unwind node block temp (first locs) (second locs)))
1504 (let ((0-tn (emit-constant 0)))
1505 (vop unwind node block temp 0-tn 0-tn))))
1506
1507 (undefined-value))
1508
1509
1510 ;;; Cleanup-point doesn't to anything except prevent the body from being
1511 ;;; entirely deleted.
1512 ;;;
1513 (defoptimizer (%cleanup-point ir2-convert) (() node block) node block)
1514
1515
1516 ;;; This function invalidates a lexical exit on exiting from the dynamic
1517 ;;; extent. This is done by storing 0 into the indirect value cell that holds
1518 ;;; the closed unwind block.
1519 ;;;
1520 (defoptimizer (%lexical-exit-breakup ir2-convert) ((info) node block)
1521 (vop value-cell-set node block
1522 (find-in-environment (continuation-value info) (node-environment node))
1523 (emit-constant 0)))
1524
1525
1526 ;;; IR2-Convert-Throw -- Internal
1527 ;;;
1528 ;;; We have to do a spurious move of no values to the result continuation so
1529 ;;; that lifetime analysis won't get confused.
1530 ;;;
1531 (defun ir2-convert-throw (node block)
1532 (declare (type mv-combination node) (type ir2-block block))
1533 (let ((args (basic-combination-args node)))
1534 (vop* throw node block
1535 ((continuation-tn node block (first args))
1536 (reference-tn-list
1537 (ir2-continuation-locs (continuation-info (second args)))
1538 nil))
1539 (nil)))
1540
1541 (move-continuation-result node block () (node-cont node))
1542 (undefined-value))
1543
1544
1545 ;;; Emit-NLX-Start -- Internal
1546 ;;;
1547 ;;; Emit code to set up a non-local-exit. Info is the NLX-Info for the
1548 ;;; exit, and Tag is the continuation for the catch tag (if any.) We get at
1549 ;;; the target PC by passing in the label to the vop. The vop is responsible
1550 ;;; for building a return-PC object.
1551 ;;;
1552 (defun emit-nlx-start (node block info tag)
1553 (declare (type node node) (type ir2-block block) (type nlx-info info)
1554 (type (or continuation null) tag))
1555 (let* ((2info (nlx-info-info info))
1556 (kind (cleanup-kind (nlx-info-cleanup info)))
1557 (block-tn (environment-live-tn
1558 (make-normal-tn (primitive-type-or-lose 'catch-block
1559 *backend*))
1560 (node-environment node)))
1561 (res (make-stack-pointer-tn))
1562 (target-label (ir2-nlx-info-target 2info)))
1563
1564 (vop current-binding-pointer node block
1565 (car (ir2-nlx-info-dynamic-state 2info)))
1566 (vop* save-dynamic-state node block
1567 (nil)
1568 ((reference-tn-list (cdr (ir2-nlx-info-dynamic-state 2info)) t)))
1569 (vop current-stack-pointer node block (ir2-nlx-info-save-sp 2info))
1570
1571 (ecase kind
1572 (:catch
1573 (vop make-catch-block node block block-tn
1574 (continuation-tn node block tag) target-label res))
1575 ((:unwind-protect :block :tagbody)
1576 (vop make-unwind-block node block block-tn target-label res)))
1577
1578 (ecase kind
1579 ((:block :tagbody)
1580 (do-make-value-cell node block res (ir2-nlx-info-home 2info)))
1581 (:unwind-protect
1582 (vop set-unwind-protect node block block-tn))
1583 (:catch)))
1584
1585 (undefined-value))
1586
1587
1588 ;;; IR2-Convert-Entry -- Internal
1589 ;;;
1590 ;;; Scan each of Entry's exits, setting up the exit for each lexical exit.
1591 ;;;
1592 (defun ir2-convert-entry (node block)
1593 (declare (type entry node) (type ir2-block block))
1594 (dolist (exit (entry-exits node))
1595 (let ((info (find-nlx-info node (node-cont exit))))
1596 (when (and info
1597 (member (cleanup-kind (nlx-info-cleanup info))
1598 '(:block :tagbody)))
1599 (emit-nlx-start node block info nil))))
1600 (undefined-value))
1601
1602
1603 ;;; %Catch, %Unwind-Protect IR2 convert -- Internal
1604 ;;;
1605 ;;; Set up the unwind block for these guys.
1606 ;;;
1607 (defoptimizer (%catch ir2-convert) ((info-cont tag) node block)
1608 (emit-nlx-start node block (continuation-value info-cont) tag))
1609 ;;;
1610 (defoptimizer (%unwind-protect ir2-convert) ((info-cont cleanup) node block)
1611 (emit-nlx-start node block (continuation-value info-cont) nil))
1612
1613
1614 ;;; %NLX-Entry IR2 convert -- Internal
1615 ;;;
1616 ;;; Emit the entry code for a non-local exit. We receive values and restore
1617 ;;; dynamic state.
1618 ;;;
1619 ;;; In the case of a lexical exit or Catch, we look at the exit continuation's
1620 ;;; kind to determine which flavor of entry VOP to emit. If unknown values,
1621 ;;; emit the xxx-MULTIPLE variant to the continuation locs. If fixed values,
1622 ;;; make the appropriate number of temps in the standard values locations and
1623 ;;; use the other variant, delivering the temps to the continuation using
1624 ;;; Move-Continuation-Result.
1625 ;;;
1626 ;;; In the Unwind-Protect case, we deliver the first register argument, the
1627 ;;; argument count and the argument pointer to our continuation as multiple
1628 ;;; values. These values are the block exited to and the values start and
1629 ;;; count.
1630 ;;;
1631 ;;; After receiving values, we restore dynamic state. Except in the
1632 ;;; Unwind-Protect case, the values receiving restores the stack pointer. In
1633 ;;; an Unwind-Protect cleanup, we want to leave the stack pointer alone, since
1634 ;;; the thrown values are still out there.
1635 ;;;
1636 (defoptimizer (%nlx-entry ir2-convert) ((info-cont) node block)
1637 (let* ((info (continuation-value info-cont))
1638 (cont (nlx-info-continuation info))
1639 (2cont (continuation-info cont))
1640 (2info (nlx-info-info info))
1641 (top-loc (ir2-nlx-info-save-sp 2info))
1642 (start-loc (make-nlx-entry-argument-start-location))
1643 (count-loc (make-argument-count-location))
1644 (target (ir2-nlx-info-target 2info)))
1645
1646 (ecase (cleanup-kind (nlx-info-cleanup info))
1647 ((:catch :block :tagbody)
1648 (if (and 2cont (eq (ir2-continuation-kind 2cont) :unknown))
1649 (vop* nlx-entry-multiple node block
1650 (top-loc start-loc count-loc nil)
1651 ((reference-tn-list (ir2-continuation-locs 2cont) t))
1652 target)
1653 (let ((locs (standard-result-tns cont)))
1654 (vop* nlx-entry node block
1655 (top-loc start-loc count-loc nil)
1656 ((reference-tn-list locs t))
1657 target
1658 (length locs))
1659 (move-continuation-result node block locs cont))))
1660 (:unwind-protect
1661 (let ((block-loc (standard-argument-location 0)))
1662 (vop uwp-entry node block target block-loc start-loc count-loc)
1663 (move-continuation-result
1664 node block
1665 (list block-loc start-loc count-loc)
1666 cont))))
1667
1668 (when *collect-dynamic-statistics*
1669 (vop count-me node block *dynamic-counts-tn*
1670 (block-number (ir2-block-block block))))
1671
1672 (vop* restore-dynamic-state node block
1673 ((reference-tn-list (cdr (ir2-nlx-info-dynamic-state 2info)) nil))
1674 (nil))
1675 (vop unbind-to-here node block
1676 (car (ir2-nlx-info-dynamic-state 2info)))))
1677
1678
1679 ;;;; N-arg functions:
1680
1681 (macrolet ((frob (name)
1682 `(defoptimizer (,name ir2-convert) ((&rest args) node block)
1683 (let* ((refs (move-tail-full-call-args node block))
1684 (cont (node-cont node))
1685 (res (continuation-result-tns
1686 cont
1687 (list (primitive-type (specifier-type 'list)))))
1688 (dynamic-extent (ir2-stack-allocate node)))
1689 (when (and dynamic-extent *dynamic-extent-trace*)
1690 (format t "~&===> list/list* ~d~%" (length args)))
1691 (vop* ,name node block (refs) ((first res) nil)
1692 (length args) dynamic-extent)
1693 (move-continuation-result node block res cont)))))
1694 (frob list)
1695 (frob list*))
1696
1697
1698 ;;;; Structure accessors:
1699 ;;;
1700 ;;; These guys have to bizarrely determine the slot offset by looking at the
1701 ;;; called function.
1702
1703 (defoptimizer (%slot-accessor ir2-convert) ((str) node block)
1704 (let* ((cont (node-cont node))
1705 (res (continuation-result-tns cont
1706 (list (backend-any-primitive-type
1707 *backend*)))))
1708 (vop instance-ref node block
1709 (continuation-tn node block str)
1710 (dsd-index
1711 (slot-accessor-slot
1712 (ref-leaf
1713 (continuation-use
1714 (combination-fun node)))))
1715 (first res))
1716 (move-continuation-result node block res cont)))
1717
1718 (defoptimizer (%slot-setter ir2-convert) ((value str) node block)
1719 (let ((val (continuation-tn node block value)))
1720 (vop instance-set node block
1721 (continuation-tn node block str)
1722 val
1723 (dsd-index
1724 (slot-accessor-slot
1725 (ref-leaf
1726 (continuation-use
1727 (combination-fun node))))))
1728
1729 (move-continuation-result node block (list val) (node-cont node))))
1730
1731
1732 ;;; IR2-Convert -- Interface
1733 ;;;
1734 ;;; Convert the code in a component into VOPs.
1735 ;;;
1736 (defun ir2-convert (component)
1737 (declare (type component component))
1738 (let ((*dynamic-counts-tn*
1739 (when *collect-dynamic-statistics*
1740 (let* ((blocks
1741 (block-number (block-next (component-head component))))
1742 (counts (make-array blocks
1743 :element-type '(unsigned-byte 32)
1744 :initial-element 0))
1745 (info (make-dyncount-info
1746 :for (component-name component)
1747 :costs (make-array blocks
1748 :element-type '(unsigned-byte 32)
1749 :initial-element 0)
1750 :counts counts)))
1751 (setf (ir2-component-dyncount-info (component-info component))
1752 info)
1753 (emit-constant info)
1754 (emit-constant counts)))))
1755 (let ((num 0))
1756 (declare (type index num))
1757 (do-ir2-blocks (2block component)
1758 (let ((block (ir2-block-block 2block)))
1759 (when (block-start block)
1760 (setf (block-number block) num)
1761 (when *collect-dynamic-statistics*
1762 (let ((first-node (continuation-next (block-start block))))
1763 (unless (or (and (bind-p first-node)
1764 (external-entry-point-p
1765 (bind-lambda first-node)))
1766 (eq (continuation-function-name
1767 (node-cont first-node))
1768 '%nlx-entry))
1769 (vop count-me first-node 2block *dynamic-counts-tn* num))))
1770 (ir2-convert-block block)
1771 (incf num))))))
1772 (undefined-value))
1773
1774
1775 ;;; Finish-IR2-Block -- Internal
1776 ;;;
1777 ;;; If necessary, emit a terminal unconditional branch to go to the
1778 ;;; successor block. If the successor is the component tail, then there isn't
1779 ;;; really any successor, but if the end is an unknown, non-tail call, then we
1780 ;;; emit an error trap just in case the function really does return.
1781 ;;;
1782 (defun finish-ir2-block (block)
1783 (declare (type cblock block))
1784 (let* ((2block (block-info block))
1785 (last (block-last block))
1786 (succ (block-succ block)))
1787 (unless (if-p last)
1788 (assert (and succ (null (rest succ))))
1789 (let ((target (first succ)))
1790 (cond ((eq target (component-tail (block-component block)))
1791 (when (and (basic-combination-p last)
1792 (eq (basic-combination-kind last) :full))
1793 (let* ((fun (basic-combination-fun last))
1794 (use (continuation-use fun))
1795 (name (and (ref-p use) (leaf-name (ref-leaf use)))))
1796 (unless (or (node-tail-p last)
1797 (info function info name)
1798 (policy last (zerop safety)))
1799 (vop nil-function-returned-error last 2block
1800 (if name
1801 (emit-constant name)
1802 (multiple-value-bind
1803 (tn named)
1804 (function-continuation-tn last 2block fun)
1805 (assert (not named))
1806 tn)))))))
1807 ((not (eq (ir2-block-next 2block) (block-info target)))
1808 (vop branch last 2block (block-label target)))))))
1809 (values))
1810
1811
1812 ;;; IR2-Convert-Block -- Internal
1813 ;;;
1814 ;;; Convert the code in a block into VOPs.
1815 ;;;
1816 (defun ir2-convert-block (block)
1817 (declare (type cblock block))
1818 (let ((2block (block-info block)))
1819 (do-nodes (node cont block)
1820 (etypecase node
1821 (ref
1822 (let ((2cont (continuation-info cont)))
1823 (when (and 2cont
1824 (not (eq (ir2-continuation-kind 2cont) :delayed)))
1825 (ir2-convert-ref node 2block))))
1826 (combination
1827 (let ((kind (basic-combination-kind node)))
1828 (case kind
1829 (:local
1830 (ir2-convert-local-call node 2block))
1831 (:full
1832 (ir2-convert-full-call node 2block))
1833 (t
1834 (let ((fun (function-info-ir2-convert kind)))
1835 (cond (fun
1836 (funcall fun node 2block))
1837 ((eq (basic-combination-info node) :full)
1838 (ir2-convert-full-call node 2block))
1839 (t
1840 (ir2-convert-template node 2block))))))))
1841 (cif
1842 (when (continuation-info (if-test node))
1843 (ir2-convert-if node 2block)))
1844 (bind
1845 (let ((fun (bind-lambda node)))
1846 (when (eq (lambda-home fun) fun)
1847 (ir2-convert-bind node 2block))))
1848 (creturn
1849 (ir2-convert-return node 2block))
1850 (cset
1851 (ir2-convert-set node 2block))
1852 (mv-combination
1853 (cond
1854 ((eq (basic-combination-kind node) :local)
1855 (ir2-convert-mv-bind node 2block))
1856 ((eq (continuation-function-name (basic-combination-fun node))
1857 '%throw)
1858 (ir2-convert-throw node 2block))
1859 (t
1860 (ir2-convert-mv-call node 2block))))
1861 (exit
1862 (when (exit-entry node)
1863 (ir2-convert-exit node 2block)))
1864 (entry
1865 (ir2-convert-entry node 2block))))
1866
1867 (finish-ir2-block block)
1868 (values)))
1869
1870 ;;; End of file.

  ViewVC Help
Powered by ViewVC 1.1.5