2 * Copyright (C) 2011, 2013-2015 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
31 #include "DFGCommon.h"
32 #include "DFGFlushFormat.h"
33 #include "DFGMinifiedID.h"
34 #include "DataFormat.h"
35 #include "SpeculatedType.h"
36 #include "ValueRecovery.h"
38 namespace JSC
{ namespace DFG
{
40 enum ValueSourceKind
{
52 static inline ValueSourceKind
dataFormatToValueSourceKind(DataFormat dataFormat
)
56 return Int32InJSStack
;
58 return Int52InJSStack
;
59 case DataFormatDouble
:
60 return DoubleInJSStack
;
61 case DataFormatBoolean
:
62 return BooleanInJSStack
;
68 RELEASE_ASSERT(dataFormat
& DataFormatJS
);
69 return ValueInJSStack
;
73 static inline DataFormat
valueSourceKindToDataFormat(ValueSourceKind kind
)
79 return DataFormatInt32
;
81 return DataFormatInt52
;
83 return DataFormatCell
;
84 case BooleanInJSStack
:
85 return DataFormatBoolean
;
87 return DataFormatDouble
;
89 return DataFormatDead
;
91 return DataFormatNone
;
95 static inline bool isInJSStack(ValueSourceKind kind
)
97 DataFormat format
= valueSourceKindToDataFormat(kind
);
98 return format
!= DataFormatNone
&& format
< DataFormatOSRMarker
;
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
)
105 return valueSourceKindToDataFormat(kind
) != DataFormatNone
;
111 : m_kind(SourceNotSet
)
115 explicit ValueSource(ValueSourceKind valueSourceKind
)
116 : m_kind(valueSourceKind
)
118 ASSERT(kind() == SourceIsDead
);
121 explicit ValueSource(MinifiedID id
)
126 ASSERT(kind() == HaveNode
);
129 ValueSource(ValueSourceKind valueSourceKind
, VirtualRegister where
)
130 : m_kind(valueSourceKind
)
131 , m_value(static_cast<intptr_t>(where
.offset()))
133 ASSERT(kind() != SourceNotSet
);
134 ASSERT(kind() != HaveNode
);
137 static ValueSource
forFlushFormat(VirtualRegister where
, FlushFormat format
)
141 case ConflictingFlush
:
142 return ValueSource(SourceIsDead
);
144 return ValueSource(ValueInJSStack
, where
);
146 return ValueSource(DoubleInJSStack
, where
);
148 return ValueSource(Int32InJSStack
, where
);
150 return ValueSource(Int52InJSStack
, where
);
152 return ValueSource(CellInJSStack
, where
);
154 return ValueSource(BooleanInJSStack
, where
);
156 RELEASE_ASSERT_NOT_REACHED();
157 return ValueSource();
160 static ValueSource
forDataFormat(VirtualRegister where
, DataFormat dataFormat
)
162 return ValueSource(dataFormatToValueSourceKind(dataFormat
), where
);
167 return kind() != SourceNotSet
;
170 bool operator!() const { return !isSet(); }
172 ValueSourceKind
kind() const
177 bool isInJSStack() const { return JSC::DFG::isInJSStack(kind()); }
178 bool isTriviallyRecoverable() const { return JSC::DFG::isTriviallyRecoverable(kind()); }
180 DataFormat
dataFormat() const
182 return valueSourceKindToDataFormat(kind());
185 ValueRecovery
valueRecovery() const
187 ASSERT(isTriviallyRecoverable());
190 return ValueRecovery::constant(jsUndefined());
193 return ValueRecovery::displacedInJSStack(virtualRegister(), dataFormat());
197 MinifiedID
id() const
199 ASSERT(kind() == HaveNode
);
200 return MinifiedID::fromBits(m_value
);
203 VirtualRegister
virtualRegister() const
205 ASSERT(isInJSStack());
206 return VirtualRegister(m_value
);
209 void dump(PrintStream
&) const;
210 void dumpInContext(PrintStream
&, DumpContext
*) const;
213 ValueSourceKind m_kind
;
217 } } // namespace JSC::DFG
219 #endif // ENABLE(DFG_JIT)
221 #endif // DFGValueSource_h