]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2011, 2013, 2014 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 DFGEdge_h | |
27 | #define DFGEdge_h | |
28 | ||
29 | #if ENABLE(DFG_JIT) | |
30 | ||
31 | #include "DFGCommon.h" | |
32 | #include "DFGUseKind.h" | |
33 | ||
34 | namespace JSC { namespace DFG { | |
35 | ||
36 | class AdjacencyList; | |
37 | ||
38 | class Edge { | |
39 | public: | |
40 | explicit Edge(Node* node = 0, UseKind useKind = UntypedUse, ProofStatus proofStatus = NeedsCheck, KillStatus killStatus = DoesNotKill) | |
41 | #if USE(JSVALUE64) | |
42 | : m_encodedWord(makeWord(node, useKind, proofStatus, killStatus)) | |
43 | #else | |
44 | : m_node(node) | |
45 | , m_encodedWord(makeWord(useKind, proofStatus, killStatus)) | |
46 | #endif | |
47 | { | |
48 | } | |
49 | ||
50 | #if USE(JSVALUE64) | |
51 | Node* node() const { return bitwise_cast<Node*>(m_encodedWord >> shift()); } | |
52 | #else | |
53 | Node* node() const { return m_node; } | |
54 | #endif | |
55 | ||
56 | Node& operator*() const { return *node(); } | |
57 | Node* operator->() const { return node(); } | |
58 | ||
59 | void setNode(Node* node) | |
60 | { | |
61 | #if USE(JSVALUE64) | |
62 | m_encodedWord = makeWord(node, useKind(), proofStatus(), killStatus()); | |
63 | #else | |
64 | m_node = node; | |
65 | #endif | |
66 | } | |
67 | ||
68 | UseKind useKindUnchecked() const | |
69 | { | |
70 | #if USE(JSVALUE64) | |
71 | unsigned masked = m_encodedWord & (((1 << shift()) - 1)); | |
72 | unsigned shifted = masked >> 2; | |
73 | #else | |
74 | unsigned shifted = static_cast<UseKind>(m_encodedWord) >> 2; | |
75 | #endif | |
76 | ASSERT(shifted < static_cast<unsigned>(LastUseKind)); | |
77 | UseKind result = static_cast<UseKind>(shifted); | |
78 | ASSERT(node() || result == UntypedUse); | |
79 | return result; | |
80 | } | |
81 | UseKind useKind() const | |
82 | { | |
83 | ASSERT(node()); | |
84 | return useKindUnchecked(); | |
85 | } | |
86 | void setUseKind(UseKind useKind) | |
87 | { | |
88 | ASSERT(node()); | |
89 | #if USE(JSVALUE64) | |
90 | m_encodedWord = makeWord(node(), useKind, proofStatus(), killStatus()); | |
91 | #else | |
92 | m_encodedWord = makeWord(useKind, proofStatus(), killStatus()); | |
93 | #endif | |
94 | } | |
95 | ||
96 | ProofStatus proofStatusUnchecked() const | |
97 | { | |
98 | return proofStatusForIsProved(m_encodedWord & 1); | |
99 | } | |
100 | ProofStatus proofStatus() const | |
101 | { | |
102 | ASSERT(node()); | |
103 | return proofStatusUnchecked(); | |
104 | } | |
105 | void setProofStatus(ProofStatus proofStatus) | |
106 | { | |
107 | ASSERT(node()); | |
108 | #if USE(JSVALUE64) | |
109 | m_encodedWord = makeWord(node(), useKind(), proofStatus, killStatus()); | |
110 | #else | |
111 | m_encodedWord = makeWord(useKind(), proofStatus, killStatus()); | |
112 | #endif | |
113 | } | |
114 | bool isProved() const | |
115 | { | |
116 | return proofStatus() == IsProved; | |
117 | } | |
118 | ||
119 | bool willNotHaveCheck() const | |
120 | { | |
121 | return isProved() || shouldNotHaveTypeCheck(useKind()); | |
122 | } | |
123 | bool willHaveCheck() const | |
124 | { | |
125 | return !willNotHaveCheck(); | |
126 | } | |
127 | ||
128 | KillStatus killStatusUnchecked() const | |
129 | { | |
130 | return killStatusForDoesKill(m_encodedWord & 2); | |
131 | } | |
132 | KillStatus killStatus() const | |
133 | { | |
134 | ASSERT(node()); | |
135 | return killStatusUnchecked(); | |
136 | } | |
137 | void setKillStatus(KillStatus killStatus) | |
138 | { | |
139 | ASSERT(node()); | |
140 | #if USE(JSVALUE64) | |
141 | m_encodedWord = makeWord(node(), useKind(), proofStatus(), killStatus); | |
142 | #else | |
143 | m_encodedWord = makeWord(useKind(), proofStatus(), killStatus); | |
144 | #endif | |
145 | } | |
146 | bool doesKill() const { return DFG::doesKill(killStatus()); } | |
147 | bool doesNotKill() const { return !doesKill(); } | |
148 | ||
149 | bool isSet() const { return !!node(); } | |
150 | ||
151 | Edge sanitized() const | |
152 | { | |
153 | Edge result = *this; | |
154 | #if USE(JSVALUE64) | |
155 | result.m_encodedWord = makeWord(node(), useKindUnchecked(), NeedsCheck, DoesNotKill); | |
156 | #else | |
157 | result.m_encodedWord = makeWord(useKindUnchecked(), NeedsCheck, DoesNotKill); | |
158 | #endif | |
159 | return result; | |
160 | } | |
161 | ||
162 | typedef void* Edge::*UnspecifiedBoolType; | |
163 | operator UnspecifiedBoolType*() const { return reinterpret_cast<UnspecifiedBoolType*>(isSet()); } | |
164 | ||
165 | bool operator!() const { return !isSet(); } | |
166 | ||
167 | bool operator==(Edge other) const | |
168 | { | |
169 | #if USE(JSVALUE64) | |
170 | return m_encodedWord == other.m_encodedWord; | |
171 | #else | |
172 | return m_node == other.m_node && m_encodedWord == other.m_encodedWord; | |
173 | #endif | |
174 | } | |
175 | bool operator!=(Edge other) const | |
176 | { | |
177 | return !(*this == other); | |
178 | } | |
179 | ||
180 | void dump(PrintStream&) const; | |
181 | ||
182 | unsigned hash() const | |
183 | { | |
184 | #if USE(JSVALUE64) | |
185 | return IntHash<uintptr_t>::hash(m_encodedWord); | |
186 | #else | |
187 | return PtrHash<Node*>::hash(m_node) + m_encodedWord; | |
188 | #endif | |
189 | } | |
190 | ||
191 | private: | |
192 | friend class AdjacencyList; | |
193 | ||
194 | #if USE(JSVALUE64) | |
195 | static uint32_t shift() { return 7; } | |
196 | ||
197 | static uintptr_t makeWord(Node* node, UseKind useKind, ProofStatus proofStatus, KillStatus killStatus) | |
198 | { | |
199 | ASSERT(sizeof(node) == 8); | |
200 | uintptr_t shiftedValue = bitwise_cast<uintptr_t>(node) << shift(); | |
201 | ASSERT((shiftedValue >> shift()) == bitwise_cast<uintptr_t>(node)); | |
202 | ASSERT(useKind >= 0 && useKind < LastUseKind); | |
203 | ASSERT((static_cast<uintptr_t>(LastUseKind) << 2) <= (static_cast<uintptr_t>(2) << shift())); | |
204 | return shiftedValue | (static_cast<uintptr_t>(useKind) << 2) | (DFG::doesKill(killStatus) << 1) | static_cast<uintptr_t>(DFG::isProved(proofStatus)); | |
205 | } | |
206 | ||
207 | #else | |
208 | static uintptr_t makeWord(UseKind useKind, ProofStatus proofStatus, KillStatus killStatus) | |
209 | { | |
210 | return (static_cast<uintptr_t>(useKind) << 2) | (DFG::doesKill(killStatus) << 1) | static_cast<uintptr_t>(DFG::isProved(proofStatus)); | |
211 | } | |
212 | ||
213 | Node* m_node; | |
214 | #endif | |
215 | // On 64-bit this holds both the pointer and the use kind, while on 32-bit | |
216 | // this just holds the use kind. In both cases this may be hijacked by | |
217 | // AdjacencyList for storing firstChild and numChildren. | |
218 | uintptr_t m_encodedWord; | |
219 | }; | |
220 | ||
221 | inline bool operator==(Edge edge, Node* node) | |
222 | { | |
223 | return edge.node() == node; | |
224 | } | |
225 | inline bool operator==(Node* node, Edge edge) | |
226 | { | |
227 | return edge.node() == node; | |
228 | } | |
229 | inline bool operator!=(Edge edge, Node* node) | |
230 | { | |
231 | return edge.node() != node; | |
232 | } | |
233 | inline bool operator!=(Node* node, Edge edge) | |
234 | { | |
235 | return edge.node() != node; | |
236 | } | |
237 | ||
238 | } } // namespace JSC::DFG | |
239 | ||
240 | #endif // ENABLE(DFG_JIT) | |
241 | ||
242 | #endif // DFGEdge_h | |
243 |