]>
git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGEdge.h
2 * Copyright (C) 2011, 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.
29 #include <wtf/Platform.h>
33 #include "DFGCommon.h"
34 #include "DFGUseKind.h"
36 namespace JSC
{ namespace DFG
{
42 explicit Edge(Node
* node
= 0, UseKind useKind
= UntypedUse
, ProofStatus proofStatus
= NeedsCheck
)
44 : m_encodedWord(makeWord(node
, useKind
, proofStatus
))
47 , m_encodedWord(makeWord(useKind
, proofStatus
))
53 Node
* node() const { return bitwise_cast
<Node
*>(m_encodedWord
>> shift()); }
55 Node
* node() const { return m_node
; }
58 Node
& operator*() const { return *node(); }
59 Node
* operator->() const { return node(); }
61 void setNode(Node
* node
)
64 m_encodedWord
= makeWord(node
, useKind(), proofStatus());
70 UseKind
useKindUnchecked() const
73 unsigned masked
= m_encodedWord
& (((1 << shift()) - 1));
74 unsigned shifted
= masked
>> 1;
76 unsigned shifted
= static_cast<UseKind
>(m_encodedWord
) >> 1;
78 ASSERT(shifted
< static_cast<unsigned>(LastUseKind
));
79 UseKind result
= static_cast<UseKind
>(shifted
);
80 ASSERT(node() || result
== UntypedUse
);
83 UseKind
useKind() const
86 return useKindUnchecked();
88 void setUseKind(UseKind useKind
)
92 m_encodedWord
= makeWord(node(), useKind
, proofStatus());
94 m_encodedWord
= makeWord(useKind
, proofStatus());
98 ProofStatus
proofStatusUnchecked() const
100 return proofStatusForIsProved(m_encodedWord
& 1);
102 ProofStatus
proofStatus() const
105 return proofStatusUnchecked();
107 void setProofStatus(ProofStatus proofStatus
)
111 m_encodedWord
= makeWord(node(), useKind(), proofStatus
);
113 m_encodedWord
= makeWord(useKind(), proofStatus
);
116 bool isProved() const
118 return proofStatus() == IsProved
;
120 bool needsCheck() const
122 return proofStatus() == NeedsCheck
;
125 bool isSet() const { return !!node(); }
127 typedef void* Edge::*UnspecifiedBoolType
;
128 operator UnspecifiedBoolType
*() const { return reinterpret_cast<UnspecifiedBoolType
*>(isSet()); }
130 bool operator!() const { return !isSet(); }
132 bool operator==(Edge other
) const
135 return m_encodedWord
== other
.m_encodedWord
;
137 return m_node
== other
.m_node
&& m_encodedWord
== other
.m_encodedWord
;
140 bool operator!=(Edge other
) const
142 return !(*this == other
);
145 void dump(PrintStream
&) const;
148 friend class AdjacencyList
;
151 static uint32_t shift() { return 6; }
153 static uintptr_t makeWord(Node
* node
, UseKind useKind
, ProofStatus proofStatus
)
155 ASSERT(sizeof(node
) == 8);
156 uintptr_t shiftedValue
= bitwise_cast
<uintptr_t>(node
) << shift();
157 ASSERT((shiftedValue
>> shift()) == bitwise_cast
<uintptr_t>(node
));
158 ASSERT(useKind
>= 0 && useKind
< LastUseKind
);
159 ASSERT((static_cast<uintptr_t>(LastUseKind
) << 1) <= (static_cast<uintptr_t>(1) << shift()));
160 return shiftedValue
| (static_cast<uintptr_t>(useKind
) << 1) | DFG::isProved(proofStatus
);
164 static uintptr_t makeWord(UseKind useKind
, ProofStatus proofStatus
)
166 return (static_cast<uintptr_t>(useKind
) << 1) | DFG::isProved(proofStatus
);
171 // On 64-bit this holds both the pointer and the use kind, while on 32-bit
172 // this just holds the use kind. In both cases this may be hijacked by
173 // AdjacencyList for storing firstChild and numChildren.
174 uintptr_t m_encodedWord
;
177 inline bool operator==(Edge edge
, Node
* node
)
179 return edge
.node() == node
;
181 inline bool operator==(Node
* node
, Edge edge
)
183 return edge
.node() == node
;
185 inline bool operator!=(Edge edge
, Node
* node
)
187 return edge
.node() != node
;
189 inline bool operator!=(Node
* node
, Edge edge
)
191 return edge
.node() != node
;
194 } } // namespace JSC::DFG
196 #endif // ENABLE(DFG_JIT)