]> git.saurik.com Git - apple/javascriptcore.git/blame - dfg/DFGHeapLocation.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGHeapLocation.h
CommitLineData
ed1e77d3
A
1/*
2 * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#ifndef DFGHeapLocation_h
27#define DFGHeapLocation_h
28
29#if ENABLE(DFG_JIT)
30
31#include "DFGAbstractHeap.h"
32#include "DFGLazyNode.h"
33#include "DFGNode.h"
34
35namespace JSC { namespace DFG {
36
37enum LocationKind {
38 InvalidLocationKind,
39
40 ArrayLengthLoc,
41 ButterflyLoc,
42 CheckHasInstanceLoc,
43 ClosureVariableLoc,
44 DirectArgumentsLoc,
45 GetterLoc,
46 GlobalVariableLoc,
47 HasIndexedPropertyLoc,
48 IndexedPropertyLoc,
49 IndexedPropertyStorageLoc,
50 InstanceOfLoc,
51 InvalidationPointLoc,
52 IsFunctionLoc,
53 IsObjectOrNullLoc,
54 NamedPropertyLoc,
55 SetterLoc,
56 StructureLoc,
57 TypedArrayByteOffsetLoc,
58 VarInjectionWatchpointLoc,
59 StackLoc,
60 StackPayloadLoc
61};
62
63class HeapLocation {
64public:
65 HeapLocation(
66 LocationKind kind = InvalidLocationKind,
67 AbstractHeap heap = AbstractHeap(),
68 Node* base = nullptr, LazyNode index = LazyNode())
69 : m_kind(kind)
70 , m_heap(heap)
71 , m_base(base)
72 , m_index(index)
73 {
74 ASSERT((kind == InvalidLocationKind) == !heap);
75 ASSERT(!!m_heap || !m_base);
76 ASSERT(m_base || !m_index);
77 }
78
79 HeapLocation(LocationKind kind, AbstractHeap heap, Node* base, Node* index)
80 : HeapLocation(kind, heap, base, LazyNode(index))
81 {
82 }
83
84 HeapLocation(LocationKind kind, AbstractHeap heap, Edge base, Edge index = Edge())
85 : HeapLocation(kind, heap, base.node(), index.node())
86 {
87 }
88
89 HeapLocation(WTF::HashTableDeletedValueType)
90 : m_kind(InvalidLocationKind)
91 , m_heap(WTF::HashTableDeletedValue)
92 , m_base(nullptr)
93 , m_index(nullptr)
94 {
95 }
96
97 bool operator!() const { return !m_heap; }
98
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; }
103
104 unsigned hash() const
105 {
106 return m_kind + m_heap.hash() + m_index.hash() + m_kind;
107 }
108
109 bool operator==(const HeapLocation& other) const
110 {
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;
115 }
116
117 bool isHashTableDeletedValue() const
118 {
119 return m_heap.isHashTableDeletedValue();
120 }
121
122 void dump(PrintStream& out) const;
123
124private:
125 LocationKind m_kind;
126 AbstractHeap m_heap;
127 Node* m_base;
128 LazyNode m_index;
129};
130
131struct 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;
135};
136
137} } // namespace JSC::DFG
138
139namespace WTF {
140
141void printInternal(PrintStream&, JSC::DFG::LocationKind);
142
143template<typename T> struct DefaultHash;
144template<> struct DefaultHash<JSC::DFG::HeapLocation> {
145 typedef JSC::DFG::HeapLocationHash Hash;
146};
147
148template<typename T> struct HashTraits;
149template<> struct HashTraits<JSC::DFG::HeapLocation> : SimpleClassHashTraits<JSC::DFG::HeapLocation> {
150 static const bool emptyValueIsZero = false;
151};
152
153} // namespace WTF
154
155namespace JSC { namespace DFG {
156
157typedef HashMap<HeapLocation, LazyNode> ImpureMap;
158
159} } // namespace JSC::DFG
160
161#endif // ENABLE(DFG_JIT)
162
163#endif // DFGHeapLocation_h
164