]> git.saurik.com Git - apple/javascriptcore.git/blame - dfg/DFGValueSource.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGValueSource.h
CommitLineData
93a37866 1/*
ed1e77d3 2 * Copyright (C) 2011, 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 DFGValueSource_h
27#define DFGValueSource_h
28
93a37866
A
29#if ENABLE(DFG_JIT)
30
31#include "DFGCommon.h"
81345200 32#include "DFGFlushFormat.h"
93a37866
A
33#include "DFGMinifiedID.h"
34#include "DataFormat.h"
35#include "SpeculatedType.h"
36#include "ValueRecovery.h"
37
38namespace JSC { namespace DFG {
39
40enum ValueSourceKind {
41 SourceNotSet,
42 ValueInJSStack,
43 Int32InJSStack,
81345200 44 Int52InJSStack,
93a37866
A
45 CellInJSStack,
46 BooleanInJSStack,
47 DoubleInJSStack,
93a37866
A
48 SourceIsDead,
49 HaveNode
50};
51
52static inline ValueSourceKind dataFormatToValueSourceKind(DataFormat dataFormat)
53{
54 switch (dataFormat) {
81345200 55 case DataFormatInt32:
93a37866 56 return Int32InJSStack;
81345200
A
57 case DataFormatInt52:
58 return Int52InJSStack;
93a37866
A
59 case DataFormatDouble:
60 return DoubleInJSStack;
61 case DataFormatBoolean:
62 return BooleanInJSStack;
63 case DataFormatCell:
64 return CellInJSStack;
65 case DataFormatDead:
66 return SourceIsDead;
93a37866
A
67 default:
68 RELEASE_ASSERT(dataFormat & DataFormatJS);
69 return ValueInJSStack;
70 }
71}
72
73static inline DataFormat valueSourceKindToDataFormat(ValueSourceKind kind)
74{
75 switch (kind) {
76 case ValueInJSStack:
77 return DataFormatJS;
78 case Int32InJSStack:
81345200
A
79 return DataFormatInt32;
80 case Int52InJSStack:
81 return DataFormatInt52;
93a37866
A
82 case CellInJSStack:
83 return DataFormatCell;
84 case BooleanInJSStack:
85 return DataFormatBoolean;
86 case DoubleInJSStack:
87 return DataFormatDouble;
93a37866
A
88 case SourceIsDead:
89 return DataFormatDead;
90 default:
91 return DataFormatNone;
92 }
93}
94
95static 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?
103static inline bool isTriviallyRecoverable(ValueSourceKind kind)
104{
105 return valueSourceKindToDataFormat(kind) != DataFormatNone;
106}
107
108class ValueSource {
109public:
110 ValueSource()
81345200 111 : m_kind(SourceNotSet)
93a37866
A
112 {
113 }
114
115 explicit ValueSource(ValueSourceKind valueSourceKind)
81345200 116 : m_kind(valueSourceKind)
93a37866 117 {
ed1e77d3 118 ASSERT(kind() == SourceIsDead);
93a37866
A
119 }
120
121 explicit ValueSource(MinifiedID id)
81345200
A
122 : m_kind(HaveNode)
123 , m_value(id.bits())
93a37866
A
124 {
125 ASSERT(!!id);
126 ASSERT(kind() == HaveNode);
127 }
128
81345200
A
129 ValueSource(ValueSourceKind valueSourceKind, VirtualRegister where)
130 : m_kind(valueSourceKind)
131 , m_value(static_cast<intptr_t>(where.offset()))
93a37866 132 {
81345200
A
133 ASSERT(kind() != SourceNotSet);
134 ASSERT(kind() != HaveNode);
93a37866
A
135 }
136
81345200 137 static ValueSource forFlushFormat(VirtualRegister where, FlushFormat format)
93a37866 138 {
81345200
A
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);
81345200
A
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);
93a37866
A
163 }
164
165 bool isSet() const
166 {
81345200 167 return kind() != SourceNotSet;
93a37866
A
168 }
169
81345200
A
170 bool operator!() const { return !isSet(); }
171
93a37866
A
172 ValueSourceKind kind() const
173 {
81345200 174 return m_kind;
93a37866
A
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()) {
93a37866
A
189 case SourceIsDead:
190 return ValueRecovery::constant(jsUndefined());
191
93a37866 192 default:
81345200 193 return ValueRecovery::displacedInJSStack(virtualRegister(), dataFormat());
93a37866
A
194 }
195 }
196
197 MinifiedID id() const
198 {
199 ASSERT(kind() == HaveNode);
81345200 200 return MinifiedID::fromBits(m_value);
93a37866
A
201 }
202
81345200 203 VirtualRegister virtualRegister() const
93a37866 204 {
81345200
A
205 ASSERT(isInJSStack());
206 return VirtualRegister(m_value);
93a37866
A
207 }
208
81345200
A
209 void dump(PrintStream&) const;
210 void dumpInContext(PrintStream&, DumpContext*) const;
93a37866 211
81345200
A
212private:
213 ValueSourceKind m_kind;
214 uintptr_t m_value;
93a37866
A
215};
216
217} } // namespace JSC::DFG
218
219#endif // ENABLE(DFG_JIT)
220
221#endif // DFGValueSource_h
222