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
32 #include "SpeculatedType.h"
33 #include "DumpContext.h"
34 #include "StructureSet.h"
36 namespace JSC
{ namespace DFG
{
38 class StructureAbstractValue
{
40 StructureAbstractValue()
45 StructureAbstractValue(Structure
* structure
)
46 : m_structure(structure
)
50 StructureAbstractValue(const StructureSet
& set
)
62 m_structure
= topValue();
74 m_structure
= topValue();
77 static StructureAbstractValue
top()
79 StructureAbstractValue value
;
84 void add(Structure
* structure
)
86 ASSERT(!contains(structure
) && !isTop());
90 m_structure
= structure
;
93 bool addAll(const StructureSet
& other
)
95 if (isTop() || !other
.size())
97 if (other
.size() > 1) {
102 m_structure
= other
[0];
105 if (m_structure
== other
[0])
111 bool addAll(const StructureAbstractValue
& other
)
113 if (!other
.m_structure
)
122 if (m_structure
== other
.m_structure
)
127 m_structure
= other
.m_structure
;
131 bool contains(Structure
* structure
) const
135 if (m_structure
== structure
)
140 bool isSubsetOf(const StructureSet
& other
) const
146 return other
.contains(m_structure
);
149 bool doesNotContainAnyOtherThan(Structure
* structure
) const
155 return m_structure
== structure
;
158 bool isSupersetOf(const StructureSet
& other
) const
164 if (other
.size() > 1)
166 return m_structure
== other
[0];
169 bool isSubsetOf(const StructureAbstractValue
& other
) const
176 if (other
.m_structure
)
177 return m_structure
== other
.m_structure
;
183 bool isSupersetOf(const StructureAbstractValue
& other
) const
185 return other
.isSubsetOf(*this);
188 void filter(const StructureSet
& other
)
194 switch (other
.size()) {
200 m_structure
= other
[0];
208 if (other
.contains(m_structure
))
214 void filter(const StructureAbstractValue
& other
)
217 m_structure
= other
.m_structure
;
220 if (m_structure
== other
.m_structure
)
227 void filter(SpeculatedType other
)
229 if (!(other
& SpecCell
)) {
237 if (!(speculationFromStructure(m_structure
) & other
))
246 bool isTop() const { return m_structure
== topValue(); }
248 bool isClearOrTop() const { return m_structure
<= topValue(); }
249 bool isNeitherClearNorTop() const { return !isClearOrTop(); }
254 return !!m_structure
;
257 Structure
* at(size_t i
) const
261 ASSERT_UNUSED(i
, !i
);
265 Structure
* operator[](size_t i
) const
270 Structure
* last() const
275 SpeculatedType
speculationFromStructures() const
281 return speculationFromStructure(m_structure
);
284 bool isValidOffset(PropertyOffset offset
)
290 return m_structure
->isValidOffset(offset
);
293 bool hasSingleton() const
295 return isNeitherClearNorTop();
298 Structure
* singleton() const
300 ASSERT(isNeitherClearNorTop());
304 bool operator==(const StructureAbstractValue
& other
) const
306 return m_structure
== other
.m_structure
;
309 void dumpInContext(PrintStream
& out
, DumpContext
* context
) const
318 out
.print(inContext(*m_structure
, context
));
322 void dump(PrintStream
& out
) const
324 dumpInContext(out
, 0);
328 static Structure
* topValue() { return reinterpret_cast<Structure
*>(1); }
330 // NB. This must have a trivial destructor.
332 // This can only remember one structure at a time.
333 Structure
* m_structure
;
336 } } // namespace JSC::DFG
338 #endif // ENABLE(DFG_JIT)
340 #endif // DFGStructureAbstractValue_h