]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGValueSource.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGValueSource.h
1 /*
2 * Copyright (C) 2011, 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 DFGValueSource_h
27 #define DFGValueSource_h
28
29 #if ENABLE(DFG_JIT)
30
31 #include "DFGCommon.h"
32 #include "DFGFlushFormat.h"
33 #include "DFGMinifiedID.h"
34 #include "DataFormat.h"
35 #include "SpeculatedType.h"
36 #include "ValueRecovery.h"
37
38 namespace JSC { namespace DFG {
39
40 enum ValueSourceKind {
41 SourceNotSet,
42 ValueInJSStack,
43 Int32InJSStack,
44 Int52InJSStack,
45 CellInJSStack,
46 BooleanInJSStack,
47 DoubleInJSStack,
48 SourceIsDead,
49 HaveNode
50 };
51
52 static inline ValueSourceKind dataFormatToValueSourceKind(DataFormat dataFormat)
53 {
54 switch (dataFormat) {
55 case DataFormatInt32:
56 return Int32InJSStack;
57 case DataFormatInt52:
58 return Int52InJSStack;
59 case DataFormatDouble:
60 return DoubleInJSStack;
61 case DataFormatBoolean:
62 return BooleanInJSStack;
63 case DataFormatCell:
64 return CellInJSStack;
65 case DataFormatDead:
66 return SourceIsDead;
67 default:
68 RELEASE_ASSERT(dataFormat & DataFormatJS);
69 return ValueInJSStack;
70 }
71 }
72
73 static inline DataFormat valueSourceKindToDataFormat(ValueSourceKind kind)
74 {
75 switch (kind) {
76 case ValueInJSStack:
77 return DataFormatJS;
78 case Int32InJSStack:
79 return DataFormatInt32;
80 case Int52InJSStack:
81 return DataFormatInt52;
82 case CellInJSStack:
83 return DataFormatCell;
84 case BooleanInJSStack:
85 return DataFormatBoolean;
86 case DoubleInJSStack:
87 return DataFormatDouble;
88 case SourceIsDead:
89 return DataFormatDead;
90 default:
91 return DataFormatNone;
92 }
93 }
94
95 static inline bool isInJSStack(ValueSourceKind kind)
96 {
97 DataFormat format = valueSourceKindToDataFormat(kind);
98 return format != DataFormatNone && format < DataFormatOSRMarker;
99 }
100
101 // Can this value be recovered without having to look at register allocation state or
102 // DFG node liveness?
103 static inline bool isTriviallyRecoverable(ValueSourceKind kind)
104 {
105 return valueSourceKindToDataFormat(kind) != DataFormatNone;
106 }
107
108 class ValueSource {
109 public:
110 ValueSource()
111 : m_kind(SourceNotSet)
112 {
113 }
114
115 explicit ValueSource(ValueSourceKind valueSourceKind)
116 : m_kind(valueSourceKind)
117 {
118 ASSERT(kind() == SourceIsDead);
119 }
120
121 explicit ValueSource(MinifiedID id)
122 : m_kind(HaveNode)
123 , m_value(id.bits())
124 {
125 ASSERT(!!id);
126 ASSERT(kind() == HaveNode);
127 }
128
129 ValueSource(ValueSourceKind valueSourceKind, VirtualRegister where)
130 : m_kind(valueSourceKind)
131 , m_value(static_cast<intptr_t>(where.offset()))
132 {
133 ASSERT(kind() != SourceNotSet);
134 ASSERT(kind() != HaveNode);
135 }
136
137 static ValueSource forFlushFormat(VirtualRegister where, FlushFormat format)
138 {
139 switch (format) {
140 case DeadFlush:
141 case ConflictingFlush:
142 return ValueSource(SourceIsDead);
143 case FlushedJSValue:
144 return ValueSource(ValueInJSStack, where);
145 case FlushedDouble:
146 return ValueSource(DoubleInJSStack, where);
147 case FlushedInt32:
148 return ValueSource(Int32InJSStack, where);
149 case FlushedInt52:
150 return ValueSource(Int52InJSStack, where);
151 case FlushedCell:
152 return ValueSource(CellInJSStack, where);
153 case FlushedBoolean:
154 return ValueSource(BooleanInJSStack, where);
155 }
156 RELEASE_ASSERT_NOT_REACHED();
157 return ValueSource();
158 }
159
160 static ValueSource forDataFormat(VirtualRegister where, DataFormat dataFormat)
161 {
162 return ValueSource(dataFormatToValueSourceKind(dataFormat), where);
163 }
164
165 bool isSet() const
166 {
167 return kind() != SourceNotSet;
168 }
169
170 bool operator!() const { return !isSet(); }
171
172 ValueSourceKind kind() const
173 {
174 return m_kind;
175 }
176
177 bool isInJSStack() const { return JSC::DFG::isInJSStack(kind()); }
178 bool isTriviallyRecoverable() const { return JSC::DFG::isTriviallyRecoverable(kind()); }
179
180 DataFormat dataFormat() const
181 {
182 return valueSourceKindToDataFormat(kind());
183 }
184
185 ValueRecovery valueRecovery() const
186 {
187 ASSERT(isTriviallyRecoverable());
188 switch (kind()) {
189 case SourceIsDead:
190 return ValueRecovery::constant(jsUndefined());
191
192 default:
193 return ValueRecovery::displacedInJSStack(virtualRegister(), dataFormat());
194 }
195 }
196
197 MinifiedID id() const
198 {
199 ASSERT(kind() == HaveNode);
200 return MinifiedID::fromBits(m_value);
201 }
202
203 VirtualRegister virtualRegister() const
204 {
205 ASSERT(isInJSStack());
206 return VirtualRegister(m_value);
207 }
208
209 void dump(PrintStream&) const;
210 void dumpInContext(PrintStream&, DumpContext*) const;
211
212 private:
213 ValueSourceKind m_kind;
214 uintptr_t m_value;
215 };
216
217 } } // namespace JSC::DFG
218
219 #endif // ENABLE(DFG_JIT)
220
221 #endif // DFGValueSource_h
222