Add MAKE-DUMMY-FDEFN function.
[sbcl.git] / src / compiler / backend.lisp
blob2a61159e2d67e3d07a45b4b9f8315887bae558af
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.
8 ;;;;
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.
15 ;;;;
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.
22 (in-package "SB!C")
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
38 ;;; references.
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
51 (defvar *backend-sc-names* (make-hash-table :test 'eq))
52 (declaim (type hash-table *backend-sc-names*))
54 ;;; translations from primitive type names to the corresponding
55 ;;; primitive-type structure.
56 (defvar *backend-primitive-type-names*
57 (make-hash-table :test 'eq))
58 (declaim (type hash-table *backend-primitive-type-names*))
60 ;;; This establishes a convenient handle on primitive type unions, or
61 ;;; whatever. These names can only be used as the :ARG-TYPES or
62 ;;; :RESULT-TYPES for VOPs and can map to anything else that can be
63 ;;; used as :ARG-TYPES or :RESULT-TYPES (e.g. :OR, :CONSTANT).
64 (defvar *backend-primitive-type-aliases* nil)
65 (declaim (type list *backend-primitive-type-aliases*))
67 ;;; The primitive type T is somewhat magical, in that it is the only
68 ;;; primitive type that overlaps with other primitive types. An object
69 ;;; of primitive-type T is in the canonical descriptor (boxed or pointer)
70 ;;; representation.
71 ;;;
72 ;;; The T primitive-type is kept in this variable so that people who
73 ;;; have to special-case it can get at it conveniently. This variable
74 ;;; has to be set by the machine-specific VM definition, since the
75 ;;; !DEF-PRIMITIVE-TYPE for T must specify the SCs that boxed objects
76 ;;; can be allocated in.
77 (defvar *backend-t-primitive-type*)
78 (declaim (type primitive-type *backend-t-primitive-type*))
80 ;;; a hashtable translating from VOP names to the corresponding VOP-PARSE
81 ;;; structures. This information is only used at meta-compile time.
82 (defvar *backend-parsed-vops* (make-hash-table :test 'eq))
83 (declaim (type hash-table *backend-parsed-vops*))
85 ;;; mappings between CTYPE structures and the corresponding predicate.
86 ;;; The type->predicate mapping is implemented as an alist because
87 ;;; there is no such thing as a TYPE= hash table.
88 (defvar *backend-predicate-types* (make-hash-table :test 'eq))
89 (defvar *backend-type-predicates* nil)
90 (declaim (type hash-table *backend-predicate-types*))
91 (declaim (type list *backend-type-predicates*))
93 ;;;; VM support routines which backends need to implement
95 ;;; from vm.lisp
96 ;;; immediate-constant-sc
97 ;;; location-print-name
98 ;;; combination-implementation-style
99 ;;; convert-conditional-move-p
100 ;;; boxed-immediate-sc-p
102 ;;; from c-call.lisp
103 ;;; make-call-out-tns
105 ;;; from call.lisp
106 ;;; make-return-pc-passing-location
107 ;;; make-old-fp-passing-location
108 ;;; make-old-fp-save-location
109 ;;; make-return-pc-save-location
110 ;;; make-arg-count-location
112 ;;; from nlx.lisp
113 ;;; make-nlx-entry-arg-start-location
115 ;;; from pred.lisp
116 ;;; convert-conditional-move-p
118 ;;; from support.lisp
119 ;;; generate-call-sequence
120 ;;; generate-return-sequence
122 ;;; for use with scheduler
123 ;;; emit-nop
124 ;;; location-number
127 ;;;; This is a prototype interface to support Christophe Rhodes' new
128 ;;;; (sbcl-0.pre7.57) VOP :GUARD clauses for implementations which
129 ;;;; depend on CPU variants, e.g. the differences between I486,
130 ;;;; Pentium, and Pentium Pro, or the differences between different
131 ;;;; SPARC versions.
133 ;;;; Christophe Rhodes' longer explanation (cut and pasted
134 ;;;; from CLiki SBCL internals site 2001-10-12):
136 In CMUCL, the :guard argument to VOPs provided a way of disallowing
137 the use of a particular VOP in compiled code. As an example, from the
138 SPARC code in CMUCL,
140 (DEFINE-VOP? (FAST-V8-TRUNCATE/SIGNED=>SIGNED? FAST-SAFE-ARITH-OP?)
141 (:TRANSLATE TRUNCATE?)
143 (:GUARD (OR (BACKEND-FEATUREP :SPARC-V8)
144 (AND (BACKEND-FEATUREP :SPARC-V9)
145 (NOT (BACKEND-FEATUREP :SPARC-64)))))
146 ...)
148 and at the IR2 translation stage, the function #'`(LAMBDA () ,GUARD) would be called.
150 Until SBCL-0.7pre57, this is translated as
151 (:GUARD #!+(OR :SPARC-V8 (AND :SPARC-V9 (NOT :SPARC-64))) T
152 #!-(OR :SPARC-V8 (AND :SPARC-V9 (NOT :SPARC-64))) NIL)
153 which means that whether this VOP will ever be used is determined at
154 compiler compile-time depending on the contents of
155 *SHEBANG-FEATURES*?.
157 As of SBCL-0.7pre57, a new special variable,
158 SB-C:*BACKEND-SUBFEATURES*?, is introduced. As of that version, only
159 VOPs translating %log1p? query it, and :PENTIUM-STYLE-FYL2XP1 is the
160 only useful value to be pushed onto that list, for x86. This is not
161 yet an ideal interface, but it does allow for compile-time
162 conditionalization.
165 ;;; The default value of NIL means use only unguarded VOPs. The
166 ;;; initial value is customizeable via
167 ;;; customize-backend-subfeatures.lisp
168 (defvar *backend-subfeatures*
169 '#.(sort (copy-list sb-cold:*shebang-backend-subfeatures*) #'string<))
171 ;;; possible *BACKEND-SUBFEATURES* values:
173 ;;; :PENTIUM-STYLE-FYL2XP1 is a useful value for x86 SBCLs to have on
174 ;;; SB-C:*BACKEND-SUBFEATURES*?; it enables the use of the
175 ;;; %flog1p-pentium? VOP rather than the %flog1p? VOP, which is a few
176 ;;; instructions longer.