1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
12 (defoptimizer ir2-convert-reffer ((object) node block name offset lowtag)
13 (let* ((cont (node-cont node))
14 (locs (continuation-result-tns cont
15 (list *backend-t-primitive-type*)))
17 (vop slot node block (continuation-tn node block object)
18 name offset lowtag res)
19 (move-continuation-result node block locs cont)))
22 (defun needs-remembering (cont)
23 (if (csubtypep (continuation-type cont)
24 (load-time-value (specifier-type '(or fixnum character
29 (defoptimizer ir2-convert-setter ((object value) node block name offset lowtag)
30 (let ((value-tn (continuation-tn node block value)))
31 (vop set-slot node block (continuation-tn node block object) value-tn
32 name offset lowtag #!+gengc (needs-remembering value))
33 (move-continuation-result node block (list value-tn) (node-cont node))))
35 (defoptimizer ir2-convert-setfer ((value object) node block name offset lowtag)
36 (let ((value-tn (continuation-tn node block value)))
37 (vop set-slot node block (continuation-tn node block object) value-tn
38 name offset lowtag #!+gengc (needs-remembering value))
39 (move-continuation-result node block (list value-tn) (node-cont node))))
41 (defun do-inits (node block name result lowtag inits args)
42 (let ((unbound-marker-tn nil))
44 (let ((kind (car init))
46 (vop set-slot node block result
50 (continuation-tn node block (pop args)))
53 (setf unbound-marker-tn
54 (let ((tn (make-restricted-tn
56 (sc-number-or-lose 'sb!vm::any-reg))))
57 (vop make-unbound-marker node block tn)
61 name slot lowtag #!+gengc nil))))
64 (defun do-fixed-alloc (node block name words type lowtag result)
66 (vop fixed-alloc node block name words type lowtag result)
68 (if (>= words sb!vm:large-object-cutoff)
69 (vop large-alloc node block (emit-constant (logandc2 (1+ words) 1))
70 (emit-constant lowtag) (emit-constant type) (emit-constant 0) name
72 (vop fixed-alloc node block name words type lowtag result)))
74 (defoptimizer ir2-convert-fixed-allocation
75 ((&rest args) node block name words type lowtag inits)
76 (let* ((cont (node-cont node))
77 (locs (continuation-result-tns cont
78 (list *backend-t-primitive-type*)))
79 (result (first locs)))
80 (do-fixed-alloc node block name words type lowtag result)
81 (do-inits node block name result lowtag inits args)
82 (move-continuation-result node block locs cont)))
84 (defoptimizer ir2-convert-variable-allocation
85 ((extra &rest args) node block name words type lowtag inits)
86 (let* ((cont (node-cont node))
87 (locs (continuation-result-tns cont
88 (list *backend-t-primitive-type*)))
89 (result (first locs)))
90 (if (constant-continuation-p extra)
91 (let ((words (+ (continuation-value extra) words)))
92 (do-fixed-alloc node block name words type lowtag result))
93 (vop var-alloc node block (continuation-tn node block extra) name words
95 (do-inits node block name result lowtag inits args)
96 (move-continuation-result node block locs cont)))
100 ;;;; other allocation support
103 (defoptimizer (make-array-header ir2-convert) ((type rank) node block)
104 (let* ((cont (node-cont node))
105 (locs (continuation-result-tns cont
106 (list *backend-t-primitive-type*)))
107 (result (first locs)))
108 (if (and (constant-continuation-p type)
109 (constant-continuation-p rank))
110 (do-fixed-alloc node block 'make-array-header
111 (+ (continuation-value rank)
112 sb!vm:array-dimensions-offset)
113 (continuation-value type)
114 sb!vm:other-pointer-type result)
115 (vop make-array-header node block (continuation-tn node block type)
116 (continuation-tn node block rank) result))
117 (move-continuation-result node block locs cont)))
119 ;;;; replacements for stuff in ir2tran to make gengc work
122 (defun ir2-convert-closure (node block leaf res)
123 (declare (type ref node) (type ir2-block block)
124 (type functional leaf) (type tn res))
125 (unless (leaf-info leaf)
126 (setf (leaf-info leaf) (make-entry-info)))
127 (let ((entry (make-load-time-constant-tn :entry leaf))
128 (closure (etypecase leaf
130 (environment-closure (get-lambda-environment leaf)))
132 (aver (eq (functional-kind leaf) :top-level-xep))
135 (let ((this-env (node-environment node)))
136 #!+gengc (let ((temp (make-normal-tn *backend-t-primitive-type*)))
137 (do-fixed-alloc node block 'make-closure
139 sb!vm:closure-info-offset)
140 sb!vm:closure-header-type
141 sb!vm:function-pointer-type
143 (emit-move node block entry temp)
144 (vop %set-function-self node block temp res temp))
145 ;; KLUDGE: #!-GENGC nested inside #!+GENGC doesn't make much sense;
146 ;; it's just a literal translation of the CMU CL distinction between
147 ;; host and backend. If GENGC code is ever revived, this should be
149 #!-gengc (vop make-closure node block entry (length closure) res)
150 (loop for what in closure and n from 0 do
151 (unless (and (lambda-var-p what)
152 (null (leaf-refs what)))
153 (vop closure-init node block
155 (find-in-environment what this-env)
158 (emit-move node block entry res)))
162 (defun ir2-convert-set (node block)
163 (declare (type cset node) (type ir2-block block))
164 (let* ((cont (node-cont node))
165 (leaf (set-var node))
166 (value (set-value node))
167 (val-tn (continuation-tn node block value))
168 (locs (if (continuation-info cont)
169 (continuation-result-tns
170 cont (list (primitive-type (leaf-type leaf))))
174 (when (leaf-refs leaf)
175 (let ((tn (find-in-environment leaf (node-environment node))))
176 (if (lambda-var-indirect leaf)
177 (vop value-cell-set node block tn val-tn
178 (needs-remembering value))
179 (emit-move node block val-tn tn)))))
181 (ecase (global-var-kind leaf)
183 (aver (symbolp (leaf-name leaf)))
184 (vop set node block (emit-constant (leaf-name leaf)) val-tn
185 (needs-remembering value))))))
188 (emit-move node block val-tn (first locs))
189 (move-continuation-result node block locs cont)))
193 (defoptimizer (%lexical-exit-breakup ir2-convert) ((info) node block)
194 (vop value-cell-set node block
195 (find-in-environment (continuation-value info) (node-environment node))
200 (defoptimizer (%slot-setter ir2-convert) ((value str) node block)
201 (let ((val (continuation-tn node block value)))
202 (vop instance-set node block
203 (continuation-tn node block str)
209 (combination-fun node)))))
210 (needs-remembering value))
212 (move-continuation-result node block (list val) (node-cont node))))