0.9.17.8:
[sbcl.git] / src / compiler / generic / vm-ir2tran.lisp
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
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.
9
10 (in-package "SB!C")
11
12 (defoptimizer ir2-convert-reffer ((object) node block name offset lowtag)
13   (let* ((lvar (node-lvar node))
14          (locs (lvar-result-tns lvar
15                                         (list *backend-t-primitive-type*)))
16          (res (first locs)))
17     (vop slot node block (lvar-tn node block object)
18          name offset lowtag res)
19     (move-lvar-result node block locs lvar)))
20
21 (defoptimizer ir2-convert-setter ((object value) node block name offset lowtag)
22   (let ((value-tn (lvar-tn node block value)))
23     (vop set-slot node block (lvar-tn node block object) value-tn
24          name offset lowtag)
25     (move-lvar-result node block (list value-tn) (node-lvar node))))
26
27 ;;; FIXME: Isn't there a name for this which looks less like a typo?
28 ;;; (The name IR2-CONVERT-SETTER is used for something else, just above.)
29 (defoptimizer ir2-convert-setfer ((value object) node block name offset lowtag)
30   (let ((value-tn (lvar-tn node block value)))
31     (vop set-slot node block (lvar-tn node block object) value-tn
32          name offset lowtag)
33     (move-lvar-result node block (list value-tn) (node-lvar node))))
34
35 (defun emit-inits (node block name result lowtag inits args)
36   (let ((unbound-marker-tn nil)
37         (funcallable-instance-tramp-tn nil))
38     (dolist (init inits)
39       (let ((kind (car init))
40             (slot (cdr init)))
41         (vop set-slot node block result
42              (ecase kind
43                (:arg
44                 (aver args)
45                 (lvar-tn node block (pop args)))
46                (:unbound
47                 (or unbound-marker-tn
48                     (setf unbound-marker-tn
49                           (let ((tn (make-restricted-tn
50                                      nil
51                                      (sc-number-or-lose 'sb!vm::any-reg))))
52                             (vop make-unbound-marker node block tn)
53                             tn))))
54                (:null
55                 (emit-constant nil))
56                (:funcallable-instance-tramp
57                 (or funcallable-instance-tramp-tn
58                     (setf funcallable-instance-tramp-tn
59                           (let ((tn (make-restricted-tn
60                                      nil
61                                      (sc-number-or-lose 'sb!vm::any-reg))))
62                             (vop make-funcallable-instance-tramp node block tn)
63                             tn)))))
64              name slot lowtag))))
65   (aver (null args)))
66
67 (defun emit-fixed-alloc (node block name words type lowtag result)
68   (vop fixed-alloc node block name words type lowtag result))
69
70 (defoptimizer ir2-convert-fixed-allocation
71               ((&rest args) node block name words type lowtag inits)
72   (let* ((lvar (node-lvar node))
73          (locs (lvar-result-tns lvar (list *backend-t-primitive-type*)))
74          (result (first locs)))
75     (emit-fixed-alloc node block name words type lowtag result)
76     (emit-inits node block name result lowtag inits args)
77     (move-lvar-result node block locs lvar)))
78
79 (defoptimizer ir2-convert-variable-allocation
80               ((extra &rest args) node block name words type lowtag inits)
81   (let* ((lvar (node-lvar node))
82          (locs (lvar-result-tns lvar (list *backend-t-primitive-type*)))
83          (result (first locs)))
84     (if (constant-lvar-p extra)
85         (let ((words (+ (lvar-value extra) words)))
86           (emit-fixed-alloc node block name words type lowtag result))
87         (vop var-alloc node block (lvar-tn node block extra) name words
88              type lowtag result))
89     (emit-inits node block name result lowtag inits args)
90     (move-lvar-result node block locs lvar)))
91
92 ;;; :SET-TRANS (in objdef.lisp DEFINE-PRIMITIVE-OBJECT) doesn't quite
93 ;;; cut it for symbols, where under certain compilation options
94 ;;; (e.g. #!+SB-THREAD) we have to do something complicated, rather
95 ;;; than simply set the slot.  So we build the IR2 converting function
96 ;;; by hand.  -- CSR, 2003-05-08
97 (let ((fun-info (fun-info-or-lose '%set-symbol-value)))
98   (setf (fun-info-ir2-convert fun-info)
99         (lambda (node block)
100           (let ((args (basic-combination-args node)))
101             (destructuring-bind (symbol value) args
102               (let ((value-tn (lvar-tn node block value)))
103                 (vop set node block
104                      (lvar-tn node block symbol) value-tn)
105                 (move-lvar-result
106                  node block (list value-tn) (node-lvar node))))))))