2 * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef DFGValueSource_h
27 #define DFGValueSource_h
29 #include <wtf/Platform.h>
33 #include "DFGCommon.h"
34 #include "DFGMinifiedID.h"
35 #include "DataFormat.h"
36 #include "SpeculatedType.h"
37 #include "ValueRecovery.h"
39 namespace JSC
{ namespace DFG
{
41 enum ValueSourceKind
{
53 static inline ValueSourceKind
dataFormatToValueSourceKind(DataFormat dataFormat
)
56 case DataFormatInteger
:
57 return Int32InJSStack
;
58 case DataFormatDouble
:
59 return DoubleInJSStack
;
60 case DataFormatBoolean
:
61 return BooleanInJSStack
;
66 case DataFormatArguments
:
67 return ArgumentsSource
;
69 RELEASE_ASSERT(dataFormat
& DataFormatJS
);
70 return ValueInJSStack
;
74 static inline DataFormat
valueSourceKindToDataFormat(ValueSourceKind kind
)
80 return DataFormatInteger
;
82 return DataFormatCell
;
83 case BooleanInJSStack
:
84 return DataFormatBoolean
;
86 return DataFormatDouble
;
88 return DataFormatArguments
;
90 return DataFormatDead
;
92 return DataFormatNone
;
96 static inline bool isInJSStack(ValueSourceKind kind
)
98 DataFormat format
= valueSourceKindToDataFormat(kind
);
99 return format
!= DataFormatNone
&& format
< DataFormatOSRMarker
;
102 // Can this value be recovered without having to look at register allocation state or
103 // DFG node liveness?
104 static inline bool isTriviallyRecoverable(ValueSourceKind kind
)
106 return valueSourceKindToDataFormat(kind
) != DataFormatNone
;
112 : m_value(idFromKind(SourceNotSet
))
116 explicit ValueSource(ValueSourceKind valueSourceKind
)
117 : m_value(idFromKind(valueSourceKind
))
119 ASSERT(kind() != SourceNotSet
);
120 ASSERT(kind() != HaveNode
);
123 explicit ValueSource(MinifiedID id
)
127 ASSERT(kind() == HaveNode
);
130 static ValueSource
forSpeculation(SpeculatedType prediction
)
132 if (isInt32Speculation(prediction
))
133 return ValueSource(Int32InJSStack
);
134 if (isArraySpeculation(prediction
) || isCellSpeculation(prediction
))
135 return ValueSource(CellInJSStack
);
136 if (isBooleanSpeculation(prediction
))
137 return ValueSource(BooleanInJSStack
);
138 return ValueSource(ValueInJSStack
);
141 static ValueSource
forDataFormat(DataFormat dataFormat
)
143 return ValueSource(dataFormatToValueSourceKind(dataFormat
));
148 return kindFromID(m_value
) != SourceNotSet
;
151 ValueSourceKind
kind() const
153 return kindFromID(m_value
);
156 bool isInJSStack() const { return JSC::DFG::isInJSStack(kind()); }
157 bool isTriviallyRecoverable() const { return JSC::DFG::isTriviallyRecoverable(kind()); }
159 DataFormat
dataFormat() const
161 return valueSourceKindToDataFormat(kind());
164 ValueRecovery
valueRecovery() const
166 ASSERT(isTriviallyRecoverable());
169 return ValueRecovery::alreadyInJSStack();
172 return ValueRecovery::alreadyInJSStackAsUnboxedInt32();
175 return ValueRecovery::alreadyInJSStackAsUnboxedCell();
177 case BooleanInJSStack
:
178 return ValueRecovery::alreadyInJSStackAsUnboxedBoolean();
180 case DoubleInJSStack
:
181 return ValueRecovery::alreadyInJSStackAsUnboxedDouble();
184 return ValueRecovery::constant(jsUndefined());
186 case ArgumentsSource
:
187 return ValueRecovery::argumentsThatWereNotCreated();
190 RELEASE_ASSERT_NOT_REACHED();
191 return ValueRecovery();
195 MinifiedID
id() const
197 ASSERT(kind() == HaveNode
);
201 void dump(PrintStream
&) const;
204 static MinifiedID
idFromKind(ValueSourceKind kind
)
206 ASSERT(kind
>= SourceNotSet
&& kind
< HaveNode
);
207 return MinifiedID::fromBits(MinifiedID::invalidID() - kind
);
210 static ValueSourceKind
kindFromID(MinifiedID id
)
212 uintptr_t kind
= static_cast<uintptr_t>(MinifiedID::invalidID() - id
.m_id
);
213 if (kind
>= static_cast<uintptr_t>(HaveNode
))
215 return static_cast<ValueSourceKind
>(kind
);
221 } } // namespace JSC::DFG
223 #endif // ENABLE(DFG_JIT)
225 #endif // DFGValueSource_h