1 ;;;; This file contains backend-specific data. The original intent, in
2 ;;;; CMU CL, was to allow compilation using different backends, as a
3 ;;;; way of mutating a running CMU CL into a hybrid system which could
4 ;;;; emit code for a different architecture. In SBCL, this is not
5 ;;;; needed, since we have a cross-compiler which runs as an ordinary
6 ;;;; Lisp program under SBCL or other Lisps. However, it still seems
7 ;;;; reasonable to have all backendish things here in a single file.
9 ;;;; FIXME: Perhaps someday the vmdef.lisp and/or meta-vmdef.lisp stuff can
10 ;;;; merged into this file, and/or the metaness can go away or at least be
11 ;;;; radically simplified.
13 ;;;; This software is part of the SBCL system. See the README file for
14 ;;;; more information.
16 ;;;; This software is derived from the CMU CL system, which was
17 ;;;; written at Carnegie Mellon University and released into the
18 ;;;; public domain. The software is in the public domain and is
19 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
20 ;;;; files for more information.
24 ;;;; miscellaneous backend properties
26 ;;; the number of references that a TN must have to offset the
27 ;;; overhead of saving the TN across a call
28 (defvar *backend-register-save-penalty* 0)
29 (declaim (type index *backend-register-save-penalty*))
31 ;;; the byte order of the target machine. :BIG-ENDIAN has the MSB first (e.g.
32 ;;; IBM RT), :LITTLE-ENDIAN has the MSB last (e.g. DEC VAX).
33 (defvar *backend-byte-order*)
34 (declaim (type (member nil :little-endian :big-endian) *backend-byte-order*))
36 ;;; translation from SC numbers to SC info structures. SC numbers are always
37 ;;; used instead of names at run time, so changing this vector changes all the
39 (defvar *backend-sc-numbers* (make-array sc-number-limit :initial-element nil))
40 (declaim (type sc-vector *backend-sc-numbers*))
42 ;;; a list of all the SBs defined, so that we can easily iterate over them
43 (defvar *backend-sb-list* ())
44 (declaim (type list *backend-sb-list*))
46 ;;; translation from template names to template structures
47 (defvar *backend-template-names* (make-hash-table :test 'eq))
48 (declaim (type hash-table *backend-template-names*))
50 ;;; hashtables mapping from SC and SB names to the corresponding structures
53 ;;; The META versions are only used at meta-compile and load times,
54 ;;; so the defining macros can change these at meta-compile time
55 ;;; without breaking the compiler.
56 ;;; FIXME: Couldn't the META versions go away in SBCL now that we don't
57 ;;; have to worry about metacompiling and breaking the compiler?
58 (defvar *backend-sc-names* (make-hash-table :test 'eq))
59 (defvar *backend-sb-names* (make-hash-table :test 'eq))
60 (defvar *backend-meta-sc-names* (make-hash-table :test 'eq))
61 (defvar *backend-meta-sb-names* (make-hash-table :test 'eq))
62 (declaim (type hash-table
65 *backend-meta-sc-names*
66 *backend-meta-sb-names*))
69 ;;; like *SC-NUMBERS*, but updated at meta-compile time
71 ;;; FIXME: As per *BACKEND-META-SC-NAMES* and *BACKEND-META-SB-NAMES*,
72 ;;; couldn't we get rid of this in SBCL?
73 (defvar *backend-meta-sc-numbers*
74 (make-array sc-number-limit :initial-element nil))
75 (declaim (type sc-vector *backend-meta-sc-numbers*))
77 ;;; translations from primitive type names to the corresponding
78 ;;; primitive-type structure.
79 (defvar *backend-primitive-type-names*
80 (make-hash-table :test 'eq))
81 (declaim (type hash-table *backend-primitive-type-names*))
83 ;;; This establishes a convenient handle on primitive type unions, or
84 ;;; whatever. These names can only be used as the :ARG-TYPES or
85 ;;; :RESULT-TYPES for VOPs and can map to anything else that can be
86 ;;; used as :ARG-TYPES or :RESULT-TYPES (e.g. :OR, :CONSTANT).
87 (defvar *backend-primitive-type-aliases* (make-hash-table :test 'eq))
88 (declaim (type hash-table *backend-primitive-type-aliases*))
90 ;;; meta-compile time translation from names to primitive types
92 ;;; FIXME: As per *BACKEND-META-SC-NAMES* and *BACKEND-META-SB-NAMES*,
93 ;;; couldn't we get rid of this in SBCL?
94 (defvar *backend-meta-primitive-type-names* (make-hash-table :test 'eq))
95 (declaim (type hash-table *meta-primitive-type-names*))
97 ;;; The primitive type T is somewhat magical, in that it is the only
98 ;;; primitive type that overlaps with other primitive types. An object
99 ;;; of primitive-type T is in the canonical descriptor (boxed or pointer)
102 ;;; The T primitive-type is kept in this variable so that people who
103 ;;; have to special-case it can get at it conveniently. This variable
104 ;;; has to be set by the machine-specific VM definition, since the
105 ;;; !DEF-PRIMITIVE-TYPE for T must specify the SCs that boxed objects
106 ;;; can be allocated in.
107 (defvar *backend-t-primitive-type*)
108 (declaim (type primitive-type *backend-t-primitive-type*))
110 ;;; a hashtable translating from VOP names to the corresponding VOP-PARSE
111 ;;; structures. This information is only used at meta-compile time.
112 (defvar *backend-parsed-vops* (make-hash-table :test 'eq))
113 (declaim (type hash-table *backend-parsed-vops*))
115 ;;; support for the assembler
116 (defvar *backend-instruction-formats* (make-hash-table :test 'eq))
117 (defvar *backend-instruction-flavors* (make-hash-table :test 'equal))
118 (defvar *backend-special-arg-types* (make-hash-table :test 'eq))
119 (declaim (type hash-table
120 *backend-instruction-formats*
121 *backend-instruction-flavors*
122 *backend-special-arg-types*))
124 ;;; mappings between CTYPE structures and the corresponding predicate.
125 ;;; The type->predicate mapping is implemented as an alist because
126 ;;; there is no such thing as a TYPE= hash table.
127 (defvar *backend-predicate-types* (make-hash-table :test 'eq))
128 (defvar *backend-type-predicates* nil)
129 (declaim (type hash-table *backend-predicate-types*))
130 (declaim (type list *backend-type-predicates*))
132 ;;; a vector of the internal errors defined for this backend, or NIL if
133 ;;; they haven't been installed yet
134 (defvar *backend-internal-errors* nil)
135 (declaim (type (or simple-vector null) *backend-internal-errors*))
137 ;;;; VM support routines
139 ;;; FIXME: Do we need this kind of indirection for the VM support
140 ;;; routines any more?
142 ;;; forward declaration
143 (defvar *backend-support-routines*)
145 (macrolet ((def-vm-support-routines (&rest routines)
147 (eval-when (:compile-toplevel :load-toplevel :execute)
148 (defparameter *vm-support-routines* ',routines))
149 (defstruct (vm-support-routines (:copier nil))
150 ,@(mapcar (lambda (routine)
151 `(,routine nil :type (or function null)))
155 `(defun ,name (&rest args)
156 (apply (or (,(symbolicate "VM-SUPPORT-ROUTINES-"
158 *backend-support-routines*)
159 (error "machine-specific support ~S ~
165 (def-vm-support-routines
168 immediate-constant-sc
170 combination-implementation-style
172 ;; from primtype.lisp
180 standard-arg-location
181 make-return-pc-passing-location
182 make-old-fp-passing-location
183 make-old-fp-save-location
184 make-return-pc-save-location
185 make-arg-count-location
187 make-stack-pointer-tn
188 make-number-stack-pointer-tn
189 make-unknown-values-locations
190 select-component-format
194 make-dynamic-state-tns
195 make-nlx-entry-arg-start-location
198 convert-conditional-move-p
201 generate-call-sequence
202 generate-return-sequence
204 ;; for use with scheduler
208 (defprinter (vm-support-routines))
210 (defmacro !def-vm-support-routine (name ll &body body)
211 (unless (member (intern (string name) (find-package "SB!C"))
212 *vm-support-routines*)
213 (warn "unknown VM support routine: ~A" name))
214 (let ((local-name (symbolicate "IMPL-OF-VM-SUPPORT-ROUTINE-" name)))
216 (defun ,local-name ,ll ,@body)
217 (setf (,(intern (concatenate 'simple-string
218 "VM-SUPPORT-ROUTINES-"
220 (find-package "SB!C"))
221 *backend-support-routines*)
224 ;;; the VM support routines
225 (defvar *backend-support-routines* (make-vm-support-routines))
226 (declaim (type vm-support-routines *backend-support-routines*))
228 ;;;; This is a prototype interface to support Christophe Rhodes' new
229 ;;;; (sbcl-0.pre7.57) VOP :GUARD clauses for implementations which
230 ;;;; depend on CPU variants, e.g. the differences between I486,
231 ;;;; Pentium, and Pentium Pro, or the differences between different
234 ;;;; Christophe Rhodes' longer explanation (cut and pasted
235 ;;;; from CLiki SBCL internals site 2001-10-12):
237 In CMUCL, the :guard argument to VOPs provided a way of disallowing
238 the use of a particular VOP in compiled code. As an example, from the
241 (DEFINE-VOP? (FAST-V8-TRUNCATE/SIGNED=>SIGNED? FAST-SAFE-ARITH-OP?)
242 (:TRANSLATE TRUNCATE?)
244 (:GUARD (OR (BACKEND-FEATUREP :SPARC-V8)
245 (AND (BACKEND-FEATUREP :SPARC-V9)
246 (NOT (BACKEND-FEATUREP :SPARC-64)))))
249 and at the IR2 translation stage, the function #'`(LAMBDA () ,GUARD) would be called.
251 Until SBCL-0.7pre57, this is translated as
252 (:GUARD #!+(OR :SPARC-V8 (AND :SPARC-V9 (NOT :SPARC-64))) T
253 #!-(OR :SPARC-V8 (AND :SPARC-V9 (NOT :SPARC-64))) NIL)
254 which means that whether this VOP will ever be used is determined at
255 compiler compile-time depending on the contents of
258 As of SBCL-0.7pre57, a new special variable,
259 SB-C:*BACKEND-SUBFEATURES*?, is introduced. As of that version, only
260 VOPs translating %log1p? query it, and :PENTIUM-STYLE-FYL2XP1 is the
261 only useful value to be pushed onto that list, for x86. This is not
262 yet an ideal interface, but it does allow for compile-time
266 ;;; The default value of NIL means use only unguarded VOPs. The
267 ;;; initial value is customizeable via
268 ;;; customize-backend-subfeatures.lisp
269 (defvar *backend-subfeatures* '#.sb-cold:*shebang-backend-subfeatures*)
271 ;;; possible *BACKEND-SUBFEATURES* values:
273 ;;; :PENTIUM-STYLE-FYL2XP1 is a useful value for x86 SBCLs to have on
274 ;;; SB-C:*BACKEND-SUBFEATURES*?; it enables the use of the
275 ;;; %flog1p-pentium? VOP rather than the %flog1p? VOP, which is a few
276 ;;; instructions longer.