- ((extra &rest args) node block name words type lowtag inits)
- (let* ((cont (node-cont node))
- (locs (continuation-result-tns cont
- (list *backend-t-primitive-type*)))
- (result (first locs)))
- (if (constant-continuation-p extra)
- (let ((words (+ (continuation-value extra) words)))
- (do-fixed-alloc node block name words type lowtag result))
- (vop var-alloc node block (continuation-tn node block extra) name words
- type lowtag result))
- (do-inits node block name result lowtag inits args)
- (move-continuation-result node block locs cont)))
-
-
-\f
-;;;; other allocation support
-
-#!+gengc
-(defoptimizer (make-array-header ir2-convert) ((type rank) node block)
- (let* ((cont (node-cont node))
- (locs (continuation-result-tns cont
- (list *backend-t-primitive-type*)))
- (result (first locs)))
- (if (and (constant-continuation-p type)
- (constant-continuation-p rank))
- (do-fixed-alloc node block 'make-array-header
- (+ (continuation-value rank)
- sb!vm:array-dimensions-offset)
- (continuation-value type)
- sb!vm:other-pointer-type result)
- (vop make-array-header node block (continuation-tn node block type)
- (continuation-tn node block rank) result))
- (move-continuation-result node block locs cont)))
-\f
-;;;; replacements for stuff in ir2tran to make gengc work
-
-#!+gengc
-(defun ir2-convert-closure (node block leaf res)
- (declare (type ref node) (type ir2-block block)
- (type functional leaf) (type tn res))
- (unless (leaf-info leaf)
- (setf (leaf-info leaf) (make-entry-info)))
- (let ((entry (make-load-time-constant-tn :entry leaf))
- (closure (etypecase leaf
- (clambda
- (environment-closure (get-lambda-environment leaf)))
- (functional
- (aver (eq (functional-kind leaf) :top-level-xep))
- nil))))
- (if closure
- (let ((this-env (node-environment node)))
- #!+gengc (let ((temp (make-normal-tn *backend-t-primitive-type*)))
- (do-fixed-alloc node block 'make-closure
- (+ (length closure)
- sb!vm:closure-info-offset)
- sb!vm:closure-header-type
- sb!vm:function-pointer-type
- res)
- (emit-move node block entry temp)
- (vop %set-function-self node block temp res temp))
- ;; KLUDGE: #!-GENGC nested inside #!+GENGC doesn't make much sense;
- ;; it's just a literal translation of the CMU CL distinction between
- ;; host and backend. If GENGC code is ever revived, this should be
- ;; cleaned up.
- #!-gengc (vop make-closure node block entry (length closure) res)
- (loop for what in closure and n from 0 do
- (unless (and (lambda-var-p what)
- (null (leaf-refs what)))
- (vop closure-init node block
- res
- (find-in-environment what this-env)
- n
- nil))))
- (emit-move node block entry res)))
- (values))
-
-#!+gengc
-(defun ir2-convert-set (node block)
- (declare (type cset node) (type ir2-block block))
- (let* ((cont (node-cont node))
- (leaf (set-var node))
- (value (set-value node))
- (val-tn (continuation-tn node block value))
- (locs (if (continuation-info cont)
- (continuation-result-tns
- cont (list (primitive-type (leaf-type leaf))))
- nil)))
- (etypecase leaf
- (lambda-var
- (when (leaf-refs leaf)
- (let ((tn (find-in-environment leaf (node-environment node))))
- (if (lambda-var-indirect leaf)
- (vop value-cell-set node block tn val-tn
- (needs-remembering value))
- (emit-move node block val-tn tn)))))
- (global-var
- (ecase (global-var-kind leaf)
- ((:special :global)
- (aver (symbolp (leaf-name leaf)))
- (vop set node block (emit-constant (leaf-name leaf)) val-tn
- (needs-remembering value))))))
-
- (when locs
- (emit-move node block val-tn (first locs))
- (move-continuation-result node block locs cont)))
- (values))
-
-#!+gengc
-(defoptimizer (%lexical-exit-breakup ir2-convert) ((info) node block)
- (vop value-cell-set node block
- (find-in-environment (continuation-value info) (node-environment node))
- (emit-constant 0)
- nil))
-
-#!+gengc
-(defoptimizer (%slot-setter ir2-convert) ((value str) node block)
- (let ((val (continuation-tn node block value)))
- (vop instance-set node block
- (continuation-tn node block str)
- val
- (dsd-index
- (slot-accessor-slot
- (ref-leaf
- (continuation-use
- (combination-fun node)))))
- (needs-remembering value))
-
- (move-continuation-result node block (list val) (node-cont node))))
+ ((extra &rest args) node block name words type lowtag inits)
+ (let* ((lvar (node-lvar node))
+ (locs (lvar-result-tns lvar (list *backend-t-primitive-type*)))
+ (result (first locs)))
+ (if (constant-lvar-p extra)
+ (let ((words (+ (lvar-value extra) words)))
+ (emit-fixed-alloc node block name words type lowtag result lvar))
+ (vop var-alloc node block (lvar-tn node block extra) name words
+ type lowtag result))
+ (emit-inits node block name result lowtag nil inits args)
+ (move-lvar-result node block locs lvar)))
+
+(defoptimizer ir2-convert-structure-allocation
+ ((dd slot-specs &rest args) node block name words type lowtag inits)
+ (let* ((lvar (node-lvar node))
+ (locs (lvar-result-tns lvar (list *backend-t-primitive-type*)))
+ (result (first locs)))
+ (aver (constant-lvar-p dd))
+ (aver (constant-lvar-p slot-specs))
+ (let* ((c-dd (lvar-value dd))
+ (c-slot-specs (lvar-value slot-specs))
+ (words (+ (sb!kernel::dd-instance-length c-dd) words)))
+ (emit-fixed-alloc node block name words type lowtag result lvar)
+ (emit-inits node block name result lowtag words `((:dd . ,c-dd) ,@c-slot-specs) args)
+ (move-lvar-result node block locs lvar))))
+
+(defoptimizer (initialize-vector ir2-convert)
+ ((vector &rest initial-contents) node block)
+ (let* ((vector-ctype (lvar-type vector))
+ (elt-ctype (if (array-type-p vector-ctype)
+ (array-type-specialized-element-type vector-ctype)
+ (bug "Unknow vector type in IR2 conversion for ~S."
+ 'initialize-vector)))
+ (saetp (find-saetp-by-ctype elt-ctype))
+ (lvar (node-lvar node))
+ (locs (lvar-result-tns lvar (list (primitive-type vector-ctype))))
+ (result (first locs))
+ (elt-ptype (primitive-type elt-ctype))
+ (tmp (make-normal-tn elt-ptype)))
+ (emit-move node block (lvar-tn node block vector) result)
+ (flet ((compute-setter ()
+ (macrolet
+ ((frob ()
+ (let ((*package* (find-package :sb!vm))
+ (clauses nil))
+ (map nil (lambda (s)
+ (when (sb!vm:saetp-specifier s)
+ (push
+ `(,(sb!vm:saetp-typecode s)
+ (lambda (index tn)
+ #!+(or x86 x86-64)
+ (vop ,(symbolicate "DATA-VECTOR-SET-WITH-OFFSET/"
+ (sb!vm:saetp-primitive-type-name s))
+ node block result index tn 0 tn)
+ #!-(or x86 x86-64)
+ (vop ,(symbolicate "DATA-VECTOR-SET/"
+ (sb!vm:saetp-primitive-type-name s))
+ node block result index tn tn)))
+ clauses)))
+ sb!vm:*specialized-array-element-type-properties*)
+ `(ecase (sb!vm:saetp-typecode saetp)
+ ,@(nreverse clauses)))))
+ (frob)))
+ (tnify (index)
+ (constant-tn (find-constant index))))
+ (let ((setter (compute-setter))
+ (length (length initial-contents)))
+ (dotimes (i length)
+ (emit-move node block (lvar-tn node block (pop initial-contents)) tmp)
+ (funcall setter (tnify i) tmp))))
+ (move-lvar-result node block locs lvar)))
+
+;;; :SET-TRANS (in objdef.lisp DEFINE-PRIMITIVE-OBJECT) doesn't quite
+;;; cut it for symbols, where under certain compilation options
+;;; (e.g. #!+SB-THREAD) we have to do something complicated, rather
+;;; than simply set the slot. So we build the IR2 converting function
+;;; by hand. -- CSR, 2003-05-08
+(let ((fun-info (fun-info-or-lose '%set-symbol-value)))
+ (setf (fun-info-ir2-convert fun-info)
+ (lambda (node block)
+ (let ((args (basic-combination-args node)))
+ (destructuring-bind (symbol value) args
+ (let ((value-tn (lvar-tn node block value)))
+ (vop set node block
+ (lvar-tn node block symbol) value-tn)
+ (move-lvar-result
+ node block (list value-tn) (node-lvar node))))))))
+
+;;; Stack allocation optimizers per platform support
+#!+stack-allocatable-vectors
+(progn
+ (defoptimizer (allocate-vector stack-allocate-result)
+ ((type length words) node dx)
+ (or (eq dx :truly)
+ (zerop (policy node safety))
+ ;; a vector object should fit in one page -- otherwise it might go past
+ ;; stack guard pages.
+ (values-subtypep (lvar-derived-type words)
+ (load-time-value
+ (specifier-type `(integer 0 ,(- (/ sb!vm::*backend-page-bytes*
+ sb!vm:n-word-bytes)
+ sb!vm:vector-data-offset)))))))
+
+ (defoptimizer (allocate-vector ltn-annotate) ((type length words) call ltn-policy)
+ (let ((args (basic-combination-args call))
+ (template (template-or-lose (if (awhen (node-lvar call)
+ (lvar-dynamic-extent it))
+ 'sb!vm::allocate-vector-on-stack
+ 'sb!vm::allocate-vector-on-heap))))
+ (dolist (arg args)
+ (setf (lvar-info arg)
+ (make-ir2-lvar (primitive-type (lvar-type arg)))))
+ (unless (is-ok-template-use template call (ltn-policy-safe-p ltn-policy))
+ (ltn-default-call call)
+ (return-from allocate-vector-ltn-annotate-optimizer (values)))
+ (setf (basic-combination-info call) template)
+ (setf (node-tail-p call) nil)
+
+ (dolist (arg args)
+ (annotate-1-value-lvar arg)))))
+
+;;; ...lists
+#!+stack-allocatable-lists
+(progn
+ (defoptimizer (list stack-allocate-result) ((&rest args) node dx)
+ (declare (ignore node dx))
+ (not (null args)))
+ (defoptimizer (list* stack-allocate-result) ((&rest args) node dx)
+ (declare (ignore node dx))
+ (not (null (rest args))))
+ (defoptimizer (%listify-rest-args stack-allocate-result) ((&rest args) node dx)
+ (declare (ignore node dx))
+ t))
+
+;;; ...conses
+#!+stack-allocatable-fixed-objects
+(progn
+ (defoptimizer (cons stack-allocate-result) ((&rest args) node dx)
+ t)
+ (defoptimizer (%make-complex stack-allocate-result) ((&rest args) node dx)
+ t))