Don't emit "sub rsp, 0"
[sbcl.git] / src / compiler / fun-info.lisp
blob055a817e6ad9b88dce6cb335742ff9c8b0c9c1db
1 ;;;; Define IR1 boolean attributes and the FUN-INFO structure
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!C")
14 ;;; IR1 boolean function attributes
15 ;;;
16 ;;; There are a number of boolean attributes of known functions which
17 ;;; we like to have in IR1. This information is mostly side effect
18 ;;; information of a sort, but it is different from the kind of
19 ;;; information we want in IR2. We aren't interested in a fine
20 ;;; breakdown of side effects, since we do very little code motion on
21 ;;; IR1. We are interested in some deeper semantic properties such as
22 ;;; whether it is safe to pass stack closures to.
23 ;;;
24 ;;; FIXME: This whole notion of "bad" explicit attributes is bad for
25 ;;; maintenance. How confident are we that we have no defknowns for functions
26 ;;; with functional arguments that are missing the CALL attribute? Much better
27 ;;; to have NO-CALLS, as it is much less likely to break accidentally.
28 (!def-boolean-attribute ir1
29 ;; may call functions that are passed as arguments. In order to
30 ;; determine what other effects are present, we must find the
31 ;; effects of all arguments that may be functions.
32 call
33 ;; may fail to return during correct execution. Errors are O.K.
34 ;; UNUSED, BEWARE OF BITROT.
35 unwind
36 ;; the (default) worst case. Includes all the other bad things, plus
37 ;; any other possible bad thing. If this is present, the above bad
38 ;; attributes will be explicitly present as well.
39 any
40 ;; all arguments are safe for dynamic extent.
41 ;; (We used to have an UNSAFE attribute, which was basically the inverse
42 ;; of this, but it was unused and bitrotted, so when we started making
43 ;; use of the information we flipped the name and meaning the safe way
44 ;; around.)
45 dx-safe
46 ;; may be constant-folded. The function has no side effects, but may
47 ;; be affected by side effects on the arguments. e.g. SVREF, MAPC.
48 ;; Functions that side-effect their arguments are not considered to
49 ;; be foldable. Although it would be "legal" to constant fold them
50 ;; (since it "is an error" to modify a constant), we choose not to
51 ;; mark these functions as foldable in this database.
52 foldable
53 ;; may be eliminated if value is unused. The function has no side
54 ;; effects except possibly cons. If a function might signal errors,
55 ;; then it is not flushable even if it is movable, foldable or
56 ;; unsafely-flushable. Implies UNSAFELY-FLUSHABLE. (In safe code
57 ;; type checking of arguments is always performed by the caller, so
58 ;; a function which SHOULD signal an error if arguments are not of
59 ;; declared types may be FLUSHABLE.)
60 flushable
61 ;; unsafe call may be eliminated if value is unused. The function
62 ;; has no side effects except possibly cons and signalling an error
63 ;; in the safe code. If a function MUST signal errors, then it is
64 ;; not unsafely-flushable even if it is movable or foldable.
65 unsafely-flushable
66 ;; return value is important, and ignoring it is probably a mistake.
67 ;; Unlike the other attributes, this is used only for style
68 ;; warnings and has no effect on optimization.
69 important-result
70 ;; may be moved with impunity. Has no side effects except possibly
71 ;; consing, and is affected only by its arguments.
72 ;; UNUSED, BEWARE OF BITROT.
73 movable
74 ;; The function is a true predicate likely to be open-coded. Convert
75 ;; any non-conditional uses into (IF <pred> T NIL). Not usually
76 ;; specified to DEFKNOWN, since this is implementation dependent,
77 ;; and is usually automatically set by the DEFINE-VOP :CONDITIONAL
78 ;; option.
79 predicate
80 ;; Inhibit any warning for compiling a recursive definition.
81 ;; (Normally the compiler warns when compiling a recursive
82 ;; definition for a known function, since it might be a botched
83 ;; interpreter stub.)
84 recursive
85 ;; The function should always be translated by a VOP (i.e. it should
86 ;; should never be converted into a full call). This is used strictly
87 ;; as a consistency checking mechanism inside the compiler during IR2
88 ;; transformation.
89 always-translatable
90 ;; If a function is called with two arguments and the first one is a
91 ;; constant, then the arguments will be swapped.
92 commutative)
94 (defstruct (fun-info #-sb-xc-host (:pure t)
95 (:copier nil))
96 ;; boolean attributes of this function.
97 (attributes (missing-arg) :type attributes)
98 ;; TRANSFORM structures describing transforms for this function
99 (transforms () :type list)
100 ;; a function which computes the derived type for a call to this
101 ;; function by examining the arguments. This is null when there is
102 ;; no special method for this function.
103 (derive-type nil :type (or function null))
104 ;; a function that does various unspecified code transformations by
105 ;; directly hacking the IR. Returns true if further optimizations of
106 ;; the call shouldn't be attempted.
108 ;; KLUDGE: This return convention (non-NIL if you shouldn't do
109 ;; further optimiz'ns) is backwards from the return convention for
110 ;; transforms. -- WHN 19990917
111 (optimizer nil :type (or function null))
112 ;; a function computing the constant or literal arguments which are
113 ;; destructively modified by the call.
114 (destroyed-constant-args nil :type (or function null))
115 ;; If true, a special-case LTN annotation method that is used in
116 ;; place of the standard type/policy template selection. It may use
117 ;; arbitrary code to choose a template, decide to do a full call, or
118 ;; conspire with the IR2-CONVERT method to do almost anything. The
119 ;; COMBINATION node is passed as the argument.
120 (ltn-annotate nil :type (or function null))
121 ;; If true, the special-case IR2 conversion method for this
122 ;; function. This deals with funny functions, and anything else that
123 ;; can't be handled using the template mechanism. The COMBINATION
124 ;; node and the IR2-BLOCK are passed as arguments.
125 (ir2-convert nil :type (or function null))
126 ;; Called before IR2 conversion, just like IR2-CONVERT above
127 ;; Currently used for issuing warnings so that it doesn't intefere
128 ;; with things like CALL-FULL-LIKE-P due to IR2-CONVERT.
129 (ir2-hook nil :type (or function null))
130 ;; If true, the function can stack-allocate the result. The
131 ;; COMBINATION node is passed as an argument.
132 (stack-allocate-result nil :type (or function null))
133 ;; If true, the function can add flow-sensitive type information
134 ;; about the state of the world after its execution. The COMBINATION
135 ;; node is passed as an argument, along with the current set of
136 ;; active constraints for the block. The function returns a
137 ;; sequence of constraints; a constraint is a triplet of a
138 ;; constraint kind (a symbol, see (defstruct (constraint ...)) in
139 ;; constraint.lisp) and arguments, either LVARs, LAMBDA-VARs, or
140 ;; CTYPEs. If any of these arguments is NIL, the constraint is
141 ;; skipped. This simplifies integration with OK-LVAR-LAMBDA-VAR,
142 ;; which maps LVARs to LAMBDA-VARs. An optional fourth value in
143 ;; each constraint flips the meaning of the constraint if it is
144 ;; non-NIL.
145 (constraint-propagate nil :type (or function null))
146 ;; If true, the function can add flow-sensitive type information
147 ;; depending on the truthiness of its return value. Returns two
148 ;; values, a LVAR and a CTYPE. The LVAR is of that CTYPE iff the
149 ;; function returns true.
150 ;; It may also return additional third and fourth values. Each is
151 ;; a sequence of constraints (see CONSTRAINT-PROPAGATE), for the
152 ;; consequent and alternative branches, respectively.
153 (constraint-propagate-if nil :type (or function null))
154 ;; all the templates that could be used to translate this function
155 ;; into IR2, sorted by increasing cost.
156 (templates nil :type list)
157 ;; If non-null, then this function is a unary type predicate for
158 ;; this type.
159 (predicate-type nil :type (or ctype null))
160 ;; If non-null, the index of the argument which becomes the result
161 ;; of the function.
162 (result-arg nil :type (or index null))
163 ;; A function that maps over callable arguments,
164 ;; Used by MAP-CALLABLE-ARGUMENTS
165 (callable-map nil :type (or function null))
166 ;; Customizing behavior of ASSERT-CALL-TYPE
167 (call-type-deriver nil :type (or function null)))
169 (defprinter (fun-info)
170 (attributes :test (not (zerop attributes))
171 :prin1 (decode-ir1-attributes attributes))
172 (transforms :test transforms)
173 (derive-type :test derive-type)
174 (optimizer :test optimizer)
175 (ltn-annotate :test ltn-annotate)
176 (ir2-convert :test ir2-convert)
177 (templates :test templates)
178 (predicate-type :test predicate-type))