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
171 ;; from primtype.lisp
179 standard-arg-location
180 make-return-pc-passing-location
181 make-old-fp-passing-location
182 make-old-fp-save-location
183 make-return-pc-save-location
184 make-arg-count-location
186 make-stack-pointer-tn
187 make-number-stack-pointer-tn
188 make-unknown-values-locations
189 select-component-format
193 make-dynamic-state-tns
194 make-nlx-entry-arg-start-location
197 generate-call-sequence
198 generate-return-sequence
200 ;; for use with scheduler
204 (defprinter (vm-support-routines))
206 (defmacro !def-vm-support-routine (name ll &body body)
207 (unless (member (intern (string name) (find-package "SB!C"))
208 *vm-support-routines*)
209 (warn "unknown VM support routine: ~A" name))
210 (let ((local-name (symbolicate "IMPL-OF-VM-SUPPORT-ROUTINE-" name)))
212 (defun ,local-name ,ll ,@body)
213 (setf (,(intern (concatenate 'simple-string
214 "VM-SUPPORT-ROUTINES-"
216 (find-package "SB!C"))
217 *backend-support-routines*)
220 ;;; the VM support routines
221 (defvar *backend-support-routines* (make-vm-support-routines))
222 (declaim (type vm-support-routines *backend-support-routines*))
224 ;;;; This is a prototype interface to support Christophe Rhodes' new
225 ;;;; (sbcl-0.pre7.57) VOP :GUARD clauses for implementations which
226 ;;;; depend on CPU variants, e.g. the differences between I486,
227 ;;;; Pentium, and Pentium Pro, or the differences between different
230 ;;;; Christophe Rhodes' longer explanation (cut and pasted
231 ;;;; from CLiki SBCL internals site 2001-10-12):
233 In CMUCL, the :guard argument to VOPs provided a way of disallowing
234 the use of a particular VOP in compiled code. As an example, from the
237 (DEFINE-VOP? (FAST-V8-TRUNCATE/SIGNED=>SIGNED? FAST-SAFE-ARITH-OP?)
238 (:TRANSLATE TRUNCATE?)
240 (:GUARD (OR (BACKEND-FEATUREP :SPARC-V8)
241 (AND (BACKEND-FEATUREP :SPARC-V9)
242 (NOT (BACKEND-FEATUREP :SPARC-64)))))
245 and at the IR2 translation stage, the function #'`(LAMBDA () ,GUARD) would be called.
247 Until SBCL-0.7pre57, this is translated as
248 (:GUARD #!+(OR :SPARC-V8 (AND :SPARC-V9 (NOT :SPARC-64))) T
249 #!-(OR :SPARC-V8 (AND :SPARC-V9 (NOT :SPARC-64))) NIL)
250 which means that whether this VOP will ever be used is determined at
251 compiler compile-time depending on the contents of
254 As of SBCL-0.7pre57, a new special variable,
255 SB-C:*BACKEND-SUBFEATURES*?, is introduced. As of that version, only
256 VOPs translating %log1p? query it, and :PENTIUM-STYLE-FYL2XP1 is the
257 only useful value to be pushed onto that list, for x86. This is not
258 yet an ideal interface, but it does allow for compile-time
262 ;;; The default value of NIL means use only unguarded VOPs. The
263 ;;; initial value is customizeable via
264 ;;; customize-backend-subfeatures.lisp
265 (defvar *backend-subfeatures* '#.sb-cold:*shebang-backend-subfeatures*)
267 ;;; possible *BACKEND-SUBFEATURES* values:
269 ;;; :PENTIUM-STYLE-FYL2XP1 is a useful value for x86 SBCLs to have on
270 ;;; SB-C:*BACKEND-SUBFEATURES*?; it enables the use of the
271 ;;; %flog1p-pentium? VOP rather than the %flog1p? VOP, which is a few
272 ;;; instructions longer.