1.0.19.7: refactor stack allocation decisions
[sbcl/pkhuong.git] / src / compiler / sparc / alloc.lisp
blob907e2756727cdc4d2f0ede2c71cd4f5a4732ad5e
1 ;;;; allocation VOPs for the Sparc port
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!VM")
14 ;;;; LIST and LIST*
15 (define-vop (list-or-list*)
16 (:args (things :more t))
17 (:temporary (:scs (descriptor-reg) :type list) ptr)
18 (:temporary (:scs (descriptor-reg)) temp)
19 (:temporary (:scs (descriptor-reg) :type list :to (:result 0) :target result)
20 res)
21 (:info num)
22 (:results (result :scs (descriptor-reg)))
23 (:variant-vars star)
24 (:policy :safe)
25 (:node-var node)
26 (:generator 0
27 (cond ((zerop num)
28 (move result null-tn))
29 ((and star (= num 1))
30 (move result (tn-ref-tn things)))
32 (macrolet
33 ((maybe-load (tn)
34 (once-only ((tn tn))
35 `(sc-case ,tn
36 ((any-reg descriptor-reg zero null)
37 ,tn)
38 (control-stack
39 (load-stack-tn temp ,tn)
40 temp)))))
41 (let* ((dx-p (node-stack-allocate-p node))
42 (cons-cells (if star (1- num) num))
43 (alloc (* (pad-data-block cons-size) cons-cells)))
44 (pseudo-atomic (:extra (if dx-p 0 alloc))
45 (let ((allocation-area-tn (if dx-p csp-tn alloc-tn)))
46 (when dx-p
47 (align-csp res))
48 (inst andn res allocation-area-tn lowtag-mask)
49 (inst or res list-pointer-lowtag)
50 (when dx-p
51 (inst add csp-tn csp-tn alloc)))
52 (move ptr res)
53 (dotimes (i (1- cons-cells))
54 (storew (maybe-load (tn-ref-tn things)) ptr
55 cons-car-slot list-pointer-lowtag)
56 (setf things (tn-ref-across things))
57 (inst add ptr ptr (pad-data-block cons-size))
58 (storew ptr ptr
59 (- cons-cdr-slot cons-size)
60 list-pointer-lowtag))
61 (storew (maybe-load (tn-ref-tn things)) ptr
62 cons-car-slot list-pointer-lowtag)
63 (storew (if star
64 (maybe-load (tn-ref-tn (tn-ref-across things)))
65 null-tn)
66 ptr cons-cdr-slot list-pointer-lowtag))
67 (move result res)))))))
69 (define-vop (list list-or-list*)
70 (:variant nil))
72 (define-vop (list* list-or-list*)
73 (:variant t))
76 ;;;; Special purpose inline allocators.
78 (define-vop (allocate-code-object)
79 (:args (boxed-arg :scs (any-reg))
80 (unboxed-arg :scs (any-reg)))
81 (:results (result :scs (descriptor-reg)))
82 (:temporary (:scs (non-descriptor-reg)) ndescr)
83 (:temporary (:scs (any-reg) :from (:argument 0)) boxed)
84 (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) unboxed)
85 (:generator 100
86 (inst add boxed boxed-arg (fixnumize (1+ code-trace-table-offset-slot)))
87 (inst and boxed (lognot lowtag-mask))
88 (inst srl unboxed unboxed-arg word-shift)
89 (inst add unboxed lowtag-mask)
90 (inst and unboxed (lognot lowtag-mask))
91 (pseudo-atomic ()
92 ;; CMUCL Comment:
93 ;; Note: we don't have to subtract off the 4 that was added by
94 ;; pseudo-atomic, because oring in other-pointer-lowtag just adds
95 ;; it right back.
97 ;; This looks like another dreadful type pun. CSR - 2002-02-06
98 (inst or result alloc-tn other-pointer-lowtag)
99 (inst add alloc-tn boxed)
100 (inst add alloc-tn unboxed)
101 (inst sll ndescr boxed (- n-widetag-bits word-shift))
102 (inst or ndescr code-header-widetag)
103 (storew ndescr result 0 other-pointer-lowtag)
104 (storew unboxed result code-code-size-slot other-pointer-lowtag)
105 (storew null-tn result code-entry-points-slot other-pointer-lowtag)
106 (storew null-tn result code-debug-info-slot other-pointer-lowtag))))
108 (define-vop (make-fdefn)
109 (:args (name :scs (descriptor-reg) :to :eval))
110 (:temporary (:scs (non-descriptor-reg)) temp)
111 (:results (result :scs (descriptor-reg) :from :argument))
112 (:policy :fast-safe)
113 (:translate make-fdefn)
114 (:generator 37
115 (with-fixed-allocation (result temp fdefn-widetag fdefn-size)
116 (inst li temp (make-fixup "undefined_tramp" :foreign))
117 (storew name result fdefn-name-slot other-pointer-lowtag)
118 (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
119 (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))))
122 (define-vop (make-closure)
123 (:args (function :to :save :scs (descriptor-reg)))
124 (:info length stack-allocate-p)
125 (:temporary (:scs (non-descriptor-reg)) temp)
126 (:results (result :scs (descriptor-reg)))
127 (:generator 10
128 (let* ((size (+ length closure-info-offset))
129 (alloc-size (pad-data-block size)))
130 (pseudo-atomic (:extra (if stack-allocate-p 0 alloc-size))
131 (cond (stack-allocate-p
132 (align-csp temp)
133 (inst andn result csp-tn lowtag-mask)
134 (inst or result fun-pointer-lowtag)
135 (inst add csp-tn alloc-size))
137 (inst andn result alloc-tn lowtag-mask)
138 (inst or result fun-pointer-lowtag)))
139 (inst li temp (logior (ash (1- size) n-widetag-bits) closure-header-widetag))
140 (storew temp result 0 fun-pointer-lowtag)
141 (storew function result closure-fun-slot fun-pointer-lowtag)))))
143 ;;; The compiler likes to be able to directly make value cells.
144 (define-vop (make-value-cell)
145 (:args (value :to :save :scs (descriptor-reg any-reg)))
146 (:temporary (:scs (non-descriptor-reg)) temp)
147 (:info stack-allocate-p)
148 (:ignore stack-allocate-p)
149 (:results (result :scs (descriptor-reg)))
150 (:generator 10
151 (with-fixed-allocation
152 (result temp value-cell-header-widetag value-cell-size)
153 (storew value result value-cell-value-slot other-pointer-lowtag))))
155 ;;;; Automatic allocators for primitive objects.
157 (define-vop (make-unbound-marker)
158 (:args)
159 (:results (result :scs (any-reg)))
160 (:generator 1
161 (inst li result unbound-marker-widetag)))
163 (define-vop (make-funcallable-instance-tramp)
164 (:args)
165 (:results (result :scs (any-reg)))
166 (:generator 1
167 (inst li result (make-fixup "funcallable_instance_tramp" :foreign))))
169 (define-vop (fixed-alloc)
170 (:args)
171 (:info name words type lowtag stack-allocate-p)
172 (:ignore name stack-allocate-p)
173 (:results (result :scs (descriptor-reg)))
174 (:temporary (:scs (non-descriptor-reg)) temp)
175 (:generator 4
176 (pseudo-atomic (:extra (pad-data-block words))
177 (cond ((logbitp (1- n-lowtag-bits) lowtag)
178 (inst or result alloc-tn lowtag))
180 (inst andn result alloc-tn lowtag-mask)
181 (inst or result lowtag)))
182 (when type
183 (inst li temp (logior (ash (1- words) n-widetag-bits) type))
184 (storew temp result 0 lowtag)))))
186 (define-vop (var-alloc)
187 (:args (extra :scs (any-reg)))
188 (:arg-types positive-fixnum)
189 (:info name words type lowtag)
190 (:ignore name)
191 (:results (result :scs (descriptor-reg)))
192 (:temporary (:scs (any-reg)) bytes)
193 (:temporary (:scs (non-descriptor-reg)) header)
194 (:generator 6
195 (inst add bytes extra (* (1+ words) n-word-bytes))
196 (inst sll header bytes (- n-widetag-bits 2))
197 (inst add header header (+ (ash -2 n-widetag-bits) type))
198 (inst and bytes (lognot lowtag-mask))
199 (pseudo-atomic ()
200 ;; Need to be careful if the lowtag and the pseudo-atomic flag
201 ;; are not compatible.
202 (cond ((logbitp (1- n-lowtag-bits) lowtag)
203 (inst or result alloc-tn lowtag))
205 (inst andn result alloc-tn lowtag-mask)
206 (inst or result lowtag)))
207 (storew header result 0 lowtag)
208 (inst add alloc-tn alloc-tn bytes))))