]> git.saurik.com Git - apple/javascriptcore.git/blame - dfg/DFGUseKind.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGUseKind.h
CommitLineData
93a37866 1/*
ed1e77d3 2 * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
93a37866
A
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
93a37866
A
29#if ENABLE(DFG_JIT)
30
81345200 31#include "DFGNodeFlags.h"
93a37866
A
32#include "SpeculatedType.h"
33#include <wtf/PrintStream.h>
34
35namespace JSC { namespace DFG {
36
37enum UseKind {
ed1e77d3
A
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).
93a37866
A
45 Int32Use,
46 KnownInt32Use,
81345200 47 MachineIntUse,
93a37866 48 NumberUse,
ed1e77d3 49 RealNumberUse,
93a37866
A
50 BooleanUse,
51 CellUse,
52 KnownCellUse,
53 ObjectUse,
ed1e77d3 54 FunctionUse,
81345200 55 FinalObjectUse,
93a37866 56 ObjectOrOtherUse,
81345200 57 StringIdentUse,
93a37866
A
58 StringUse,
59 KnownStringUse,
60 StringObjectUse,
61 StringOrStringObjectUse,
81345200 62 NotStringVarUse,
93a37866
A
63 NotCellUse,
64 OtherUse,
81345200 65 MiscUse,
ed1e77d3
A
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
93a37866
A
77 LastUseKind // Must always be the last entry in the enum, as it is used to denote the number of enum elements.
78};
79
81345200 80inline SpeculatedType typeFilterFor(UseKind useKind)
93a37866
A
81{
82 switch (useKind) {
83 case UntypedUse:
81345200 84 return SpecFullTop;
93a37866
A
85 case Int32Use:
86 case KnownInt32Use:
87 return SpecInt32;
81345200
A
88 case Int52RepUse:
89 return SpecMachineInt;
90 case MachineIntUse:
91 return SpecInt32 | SpecInt52AsDouble;
93a37866 92 case NumberUse:
81345200 93 return SpecBytecodeNumber;
ed1e77d3
A
94 case RealNumberUse:
95 return SpecBytecodeRealNumber;
81345200
A
96 case DoubleRepUse:
97 return SpecFullDouble;
98 case DoubleRepRealUse:
99 return SpecDoubleReal;
100 case DoubleRepMachineIntUse:
101 return SpecInt52AsDouble;
93a37866
A
102 case BooleanUse:
103 return SpecBoolean;
104 case CellUse:
105 case KnownCellUse:
106 return SpecCell;
107 case ObjectUse:
108 return SpecObject;
ed1e77d3
A
109 case FunctionUse:
110 return SpecFunction;
81345200
A
111 case FinalObjectUse:
112 return SpecFinalObject;
93a37866
A
113 case ObjectOrOtherUse:
114 return SpecObject | SpecOther;
81345200
A
115 case StringIdentUse:
116 return SpecStringIdent;
93a37866
A
117 case StringUse:
118 case KnownStringUse:
119 return SpecString;
120 case StringObjectUse:
121 return SpecStringObject;
122 case StringOrStringObjectUse:
123 return SpecString | SpecStringObject;
81345200
A
124 case NotStringVarUse:
125 return ~SpecStringVar;
93a37866
A
126 case NotCellUse:
127 return ~SpecCell;
128 case OtherUse:
129 return SpecOther;
81345200
A
130 case MiscUse:
131 return SpecMisc;
93a37866
A
132 default:
133 RELEASE_ASSERT_NOT_REACHED();
81345200 134 return SpecFullTop;
93a37866
A
135 }
136}
137
81345200
A
138inline 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
153inline bool mayHaveTypeCheck(UseKind kind)
154{
155 return !shouldNotHaveTypeCheck(kind);
156}
157
158inline bool isNumerical(UseKind kind)
93a37866
A
159{
160 switch (kind) {
161 case Int32Use:
162 case KnownInt32Use:
93a37866 163 case NumberUse:
ed1e77d3 164 case RealNumberUse:
81345200
A
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
176inline 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
188inline bool isCell(UseKind kind)
189{
190 switch (kind) {
191 case CellUse:
192 case KnownCellUse:
193 case ObjectUse:
ed1e77d3 194 case FunctionUse:
81345200
A
195 case FinalObjectUse:
196 case StringIdentUse:
197 case StringUse:
198 case KnownStringUse:
199 case StringObjectUse:
200 case StringOrStringObjectUse:
93a37866
A
201 return true;
202 default:
203 return false;
204 }
205}
206
81345200
A
207// Returns true if it uses structure in a way that could be clobbered by
208// things that change the structure.
209inline 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
ed1e77d3
A
220// Returns true if we've already guaranteed the type
221inline 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
81345200
A
231inline 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
93a37866
A
244} } // namespace JSC::DFG
245
246namespace WTF {
247
248void printInternal(PrintStream&, JSC::DFG::UseKind);
249
250} // namespace WTF
251
252#endif // ENABLE(DFG_JIT)
253
254#endif // DFGUseKind_h
255