2 * Copyright (C) 2011, 2012, 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 DFGStructureAbstractValue_h
27 #define DFGStructureAbstractValue_h
29 #include <wtf/Platform.h>
34 #include "SpeculatedType.h"
35 #include "StructureSet.h"
37 namespace JSC
{ namespace DFG
{
39 class StructureAbstractValue
{
41 StructureAbstractValue()
46 StructureAbstractValue(Structure
* structure
)
47 : m_structure(structure
)
51 StructureAbstractValue(const StructureSet
& set
)
63 m_structure
= topValue();
75 m_structure
= topValue();
78 static StructureAbstractValue
top()
80 StructureAbstractValue value
;
85 void add(Structure
* structure
)
87 ASSERT(!contains(structure
) && !isTop());
91 m_structure
= structure
;
94 bool addAll(const StructureSet
& other
)
96 if (isTop() || !other
.size())
98 if (other
.size() > 1) {
103 m_structure
= other
[0];
106 if (m_structure
== other
[0])
112 bool addAll(const StructureAbstractValue
& other
)
114 if (!other
.m_structure
)
123 if (m_structure
== other
.m_structure
)
128 m_structure
= other
.m_structure
;
132 bool contains(Structure
* structure
) const
136 if (m_structure
== structure
)
141 bool isSubsetOf(const StructureSet
& other
) const
147 return other
.contains(m_structure
);
150 bool doesNotContainAnyOtherThan(Structure
* structure
) const
156 return m_structure
== structure
;
159 bool isSupersetOf(const StructureSet
& other
) const
165 if (other
.size() > 1)
167 return m_structure
== other
[0];
170 bool isSubsetOf(const StructureAbstractValue
& other
) const
177 if (other
.m_structure
)
178 return m_structure
== other
.m_structure
;
184 bool isSupersetOf(const StructureAbstractValue
& other
) const
186 return other
.isSubsetOf(*this);
189 void filter(const StructureSet
& other
)
195 switch (other
.size()) {
201 m_structure
= other
[0];
209 if (other
.contains(m_structure
))
215 void filter(const StructureAbstractValue
& other
)
218 m_structure
= other
.m_structure
;
221 if (m_structure
== other
.m_structure
)
228 void filter(SpeculatedType other
)
230 if (!(other
& SpecCell
)) {
238 if (!(speculationFromStructure(m_structure
) & other
))
247 bool isTop() const { return m_structure
== topValue(); }
249 bool isClearOrTop() const { return m_structure
<= topValue(); }
250 bool isNeitherClearNorTop() const { return !isClearOrTop(); }
255 return !!m_structure
;
258 Structure
* at(size_t i
) const
262 ASSERT_UNUSED(i
, !i
);
266 Structure
* operator[](size_t i
) const
271 Structure
* last() const
276 SpeculatedType
speculationFromStructures() const
282 return speculationFromStructure(m_structure
);
285 bool hasSingleton() const
287 return isNeitherClearNorTop();
290 Structure
* singleton() const
292 ASSERT(isNeitherClearNorTop());
296 bool operator==(const StructureAbstractValue
& other
) const
298 return m_structure
== other
.m_structure
;
301 void dump(PrintStream
& out
) const
310 out
.print(RawPointer(m_structure
), "(", m_structure
->classInfo()->className
, ")");
315 static Structure
* topValue() { return reinterpret_cast<Structure
*>(1); }
317 // NB. This must have a trivial destructor.
319 // This can only remember one structure at a time.
320 Structure
* m_structure
;
323 } } // namespace JSC::DFG
325 #endif // ENABLE(DFG_JIT)
327 #endif // DFGStructureAbstractValue_h