]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGUseKind.h
ebf99dae600c8825d22cbac63822d15b5560035a
[apple/javascriptcore.git] / dfg / DFGUseKind.h
1 /*
2 * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef DFGUseKind_h
27 #define DFGUseKind_h
28
29 #if ENABLE(DFG_JIT)
30
31 #include "DFGNodeFlags.h"
32 #include "SpeculatedType.h"
33 #include <wtf/PrintStream.h>
34
35 namespace JSC { namespace DFG {
36
37 enum UseKind {
38 // The DFG has 3 representations of values used:
39
40 // 1. The JSValue representation for a JSValue that must be stored in a GP
41 // register (or a GP register pair), and follows rules for boxing and unboxing
42 // that allow the JSValue to be stored as either fully boxed JSValues, or
43 // unboxed Int32, Booleans, Cells, etc. in 32-bit as appropriate.
44 UntypedUse, // UntypedUse must come first (value 0).
45 Int32Use,
46 KnownInt32Use,
47 MachineIntUse,
48 NumberUse,
49 RealNumberUse,
50 BooleanUse,
51 CellUse,
52 KnownCellUse,
53 ObjectUse,
54 FunctionUse,
55 FinalObjectUse,
56 ObjectOrOtherUse,
57 StringIdentUse,
58 StringUse,
59 KnownStringUse,
60 StringObjectUse,
61 StringOrStringObjectUse,
62 NotStringVarUse,
63 NotCellUse,
64 OtherUse,
65 MiscUse,
66
67 // 2. The Double representation for an unboxed double value that must be stored
68 // in an FP register.
69 DoubleRepUse,
70 DoubleRepRealUse,
71 DoubleRepMachineIntUse,
72
73 // 3. The Int52 representation for an unboxed integer value that must be stored
74 // in a GP register.
75 Int52RepUse,
76
77 LastUseKind // Must always be the last entry in the enum, as it is used to denote the number of enum elements.
78 };
79
80 inline SpeculatedType typeFilterFor(UseKind useKind)
81 {
82 switch (useKind) {
83 case UntypedUse:
84 return SpecFullTop;
85 case Int32Use:
86 case KnownInt32Use:
87 return SpecInt32;
88 case Int52RepUse:
89 return SpecMachineInt;
90 case MachineIntUse:
91 return SpecInt32 | SpecInt52AsDouble;
92 case NumberUse:
93 return SpecBytecodeNumber;
94 case RealNumberUse:
95 return SpecBytecodeRealNumber;
96 case DoubleRepUse:
97 return SpecFullDouble;
98 case DoubleRepRealUse:
99 return SpecDoubleReal;
100 case DoubleRepMachineIntUse:
101 return SpecInt52AsDouble;
102 case BooleanUse:
103 return SpecBoolean;
104 case CellUse:
105 case KnownCellUse:
106 return SpecCell;
107 case ObjectUse:
108 return SpecObject;
109 case FunctionUse:
110 return SpecFunction;
111 case FinalObjectUse:
112 return SpecFinalObject;
113 case ObjectOrOtherUse:
114 return SpecObject | SpecOther;
115 case StringIdentUse:
116 return SpecStringIdent;
117 case StringUse:
118 case KnownStringUse:
119 return SpecString;
120 case StringObjectUse:
121 return SpecStringObject;
122 case StringOrStringObjectUse:
123 return SpecString | SpecStringObject;
124 case NotStringVarUse:
125 return ~SpecStringVar;
126 case NotCellUse:
127 return ~SpecCell;
128 case OtherUse:
129 return SpecOther;
130 case MiscUse:
131 return SpecMisc;
132 default:
133 RELEASE_ASSERT_NOT_REACHED();
134 return SpecFullTop;
135 }
136 }
137
138 inline bool shouldNotHaveTypeCheck(UseKind kind)
139 {
140 switch (kind) {
141 case UntypedUse:
142 case KnownInt32Use:
143 case KnownCellUse:
144 case KnownStringUse:
145 case Int52RepUse:
146 case DoubleRepUse:
147 return true;
148 default:
149 return false;
150 }
151 }
152
153 inline bool mayHaveTypeCheck(UseKind kind)
154 {
155 return !shouldNotHaveTypeCheck(kind);
156 }
157
158 inline bool isNumerical(UseKind kind)
159 {
160 switch (kind) {
161 case Int32Use:
162 case KnownInt32Use:
163 case NumberUse:
164 case RealNumberUse:
165 case Int52RepUse:
166 case DoubleRepUse:
167 case DoubleRepRealUse:
168 case MachineIntUse:
169 case DoubleRepMachineIntUse:
170 return true;
171 default:
172 return false;
173 }
174 }
175
176 inline bool isDouble(UseKind kind)
177 {
178 switch (kind) {
179 case DoubleRepUse:
180 case DoubleRepRealUse:
181 case DoubleRepMachineIntUse:
182 return true;
183 default:
184 return false;
185 }
186 }
187
188 inline bool isCell(UseKind kind)
189 {
190 switch (kind) {
191 case CellUse:
192 case KnownCellUse:
193 case ObjectUse:
194 case FunctionUse:
195 case FinalObjectUse:
196 case StringIdentUse:
197 case StringUse:
198 case KnownStringUse:
199 case StringObjectUse:
200 case StringOrStringObjectUse:
201 return true;
202 default:
203 return false;
204 }
205 }
206
207 // Returns true if it uses structure in a way that could be clobbered by
208 // things that change the structure.
209 inline bool usesStructure(UseKind kind)
210 {
211 switch (kind) {
212 case StringObjectUse:
213 case StringOrStringObjectUse:
214 return true;
215 default:
216 return false;
217 }
218 }
219
220 // Returns true if we've already guaranteed the type
221 inline bool alreadyChecked(UseKind kind, SpeculatedType type)
222 {
223 // If the check involves the structure then we need to know more than just the type to be sure
224 // that the check is done.
225 if (usesStructure(kind))
226 return false;
227
228 return !(type & ~typeFilterFor(kind));
229 }
230
231 inline UseKind useKindForResult(NodeFlags result)
232 {
233 ASSERT(!(result & ~NodeResultMask));
234 switch (result) {
235 case NodeResultInt52:
236 return Int52RepUse;
237 case NodeResultDouble:
238 return DoubleRepUse;
239 default:
240 return UntypedUse;
241 }
242 }
243
244 } } // namespace JSC::DFG
245
246 namespace WTF {
247
248 void printInternal(PrintStream&, JSC::DFG::UseKind);
249
250 } // namespace WTF
251
252 #endif // ENABLE(DFG_JIT)
253
254 #endif // DFGUseKind_h
255