2 * Copyright (C) 2014, 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 DFGHeapLocation_h
27 #define DFGHeapLocation_h
31 #include "DFGAbstractHeap.h"
32 #include "DFGLazyNode.h"
35 namespace JSC
{ namespace DFG
{
47 HasIndexedPropertyLoc
,
49 IndexedPropertyStorageLoc
,
57 TypedArrayByteOffsetLoc
,
58 VarInjectionWatchpointLoc
,
66 LocationKind kind
= InvalidLocationKind
,
67 AbstractHeap heap
= AbstractHeap(),
68 Node
* base
= nullptr, LazyNode index
= LazyNode())
74 ASSERT((kind
== InvalidLocationKind
) == !heap
);
75 ASSERT(!!m_heap
|| !m_base
);
76 ASSERT(m_base
|| !m_index
);
79 HeapLocation(LocationKind kind
, AbstractHeap heap
, Node
* base
, Node
* index
)
80 : HeapLocation(kind
, heap
, base
, LazyNode(index
))
84 HeapLocation(LocationKind kind
, AbstractHeap heap
, Edge base
, Edge index
= Edge())
85 : HeapLocation(kind
, heap
, base
.node(), index
.node())
89 HeapLocation(WTF::HashTableDeletedValueType
)
90 : m_kind(InvalidLocationKind
)
91 , m_heap(WTF::HashTableDeletedValue
)
97 bool operator!() const { return !m_heap
; }
99 LocationKind
kind() const { return m_kind
; }
100 AbstractHeap
heap() const { return m_heap
; }
101 Node
* base() const { return m_base
; }
102 LazyNode
index() const { return m_index
; }
104 unsigned hash() const
106 return m_kind
+ m_heap
.hash() + m_index
.hash() + m_kind
;
109 bool operator==(const HeapLocation
& other
) const
111 return m_kind
== other
.m_kind
112 && m_heap
== other
.m_heap
113 && m_base
== other
.m_base
114 && m_index
== other
.m_index
;
117 bool isHashTableDeletedValue() const
119 return m_heap
.isHashTableDeletedValue();
122 void dump(PrintStream
& out
) const;
131 struct HeapLocationHash
{
132 static unsigned hash(const HeapLocation
& key
) { return key
.hash(); }
133 static bool equal(const HeapLocation
& a
, const HeapLocation
& b
) { return a
== b
; }
134 static const bool safeToCompareToEmptyOrDeleted
= true;
137 } } // namespace JSC::DFG
141 void printInternal(PrintStream
&, JSC::DFG::LocationKind
);
143 template<typename T
> struct DefaultHash
;
144 template<> struct DefaultHash
<JSC::DFG::HeapLocation
> {
145 typedef JSC::DFG::HeapLocationHash Hash
;
148 template<typename T
> struct HashTraits
;
149 template<> struct HashTraits
<JSC::DFG::HeapLocation
> : SimpleClassHashTraits
<JSC::DFG::HeapLocation
> {
150 static const bool emptyValueIsZero
= false;
155 namespace JSC
{ namespace DFG
{
157 typedef HashMap
<HeapLocation
, LazyNode
> ImpureMap
;
159 } } // namespace JSC::DFG
161 #endif // ENABLE(DFG_JIT)
163 #endif // DFGHeapLocation_h