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 which backends need to implement
140 ;;; immediate-constant-sc
141 ;;; location-print-name
142 ;;; combination-implementation-style
143 ;;; convert-conditional-move-p
144 ;;; boxed-immediate-sc-p
146 ;;; from primtype.lisp
147 ;;; primitive-type-of
151 ;;; make-call-out-tns
154 ;;; standard-arg-location
155 ;;; make-return-pc-passing-location
156 ;;; make-old-fp-passing-location
157 ;;; make-old-fp-save-location
158 ;;; make-return-pc-save-location
159 ;;; make-arg-count-location
161 ;;; make-stack-pointer-tn
162 ;;; make-number-stack-pointer-tn
163 ;;; make-unknown-values-locations
164 ;;; select-component-format
168 ;;; make-dynamic-state-tns
169 ;;; make-nlx-entry-arg-start-location
172 ;;; convert-conditional-move-p
174 ;;; from support.lisp
175 ;;; generate-call-sequence
176 ;;; generate-return-sequence
178 ;;; for use with scheduler
183 ;;;; This is a prototype interface to support Christophe Rhodes' new
184 ;;;; (sbcl-0.pre7.57) VOP :GUARD clauses for implementations which
185 ;;;; depend on CPU variants, e.g. the differences between I486,
186 ;;;; Pentium, and Pentium Pro, or the differences between different
189 ;;;; Christophe Rhodes' longer explanation (cut and pasted
190 ;;;; from CLiki SBCL internals site 2001-10-12):
192 In CMUCL, the :guard argument to VOPs provided a way of disallowing
193 the use of a particular VOP in compiled code. As an example, from the
196 (DEFINE-VOP? (FAST-V8-TRUNCATE/SIGNED=>SIGNED? FAST-SAFE-ARITH-OP?)
197 (:TRANSLATE TRUNCATE?)
199 (:GUARD (OR (BACKEND-FEATUREP :SPARC-V8)
200 (AND (BACKEND-FEATUREP :SPARC-V9)
201 (NOT (BACKEND-FEATUREP :SPARC-64)))))
204 and at the IR2 translation stage, the function #'`(LAMBDA () ,GUARD) would be called.
206 Until SBCL-0.7pre57, this is translated as
207 (:GUARD #!+(OR :SPARC-V8 (AND :SPARC-V9 (NOT :SPARC-64))) T
208 #!-(OR :SPARC-V8 (AND :SPARC-V9 (NOT :SPARC-64))) NIL)
209 which means that whether this VOP will ever be used is determined at
210 compiler compile-time depending on the contents of
213 As of SBCL-0.7pre57, a new special variable,
214 SB-C:*BACKEND-SUBFEATURES*?, is introduced. As of that version, only
215 VOPs translating %log1p? query it, and :PENTIUM-STYLE-FYL2XP1 is the
216 only useful value to be pushed onto that list, for x86. This is not
217 yet an ideal interface, but it does allow for compile-time
221 ;;; The default value of NIL means use only unguarded VOPs. The
222 ;;; initial value is customizeable via
223 ;;; customize-backend-subfeatures.lisp
224 (defvar *backend-subfeatures*
225 '#.(sort (copy-list sb-cold:*shebang-backend-subfeatures*) #'string<))
227 ;;; possible *BACKEND-SUBFEATURES* values:
229 ;;; :PENTIUM-STYLE-FYL2XP1 is a useful value for x86 SBCLs to have on
230 ;;; SB-C:*BACKEND-SUBFEATURES*?; it enables the use of the
231 ;;; %flog1p-pentium? VOP rather than the %flog1p? VOP, which is a few
232 ;;; instructions longer.