]> git.saurik.com Git - apple/javascriptcore.git/blame - dfg/DFGEdge.h
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / dfg / DFGEdge.h
CommitLineData
6fe7ccc8
A
1/*
2 * Copyright (C) 2011 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#include <wtf/Platform.h>
30
31#if ENABLE(DFG_JIT)
32
33#include "DFGCommon.h"
34
35namespace JSC { namespace DFG {
36
37class AdjacencyList;
38
39class Edge {
40public:
41 Edge()
42 : m_encodedWord(makeWord(NoNode, UntypedUse))
43 {
44 }
45
46 explicit Edge(NodeIndex nodeIndex)
47 : m_encodedWord(makeWord(nodeIndex, UntypedUse))
48 {
49 }
50
51 Edge(NodeIndex nodeIndex, UseKind useKind)
52 : m_encodedWord(makeWord(nodeIndex, useKind))
53 {
54 }
55
56 NodeIndex indexUnchecked() const { return m_encodedWord >> shift(); }
57 NodeIndex index() const
58 {
59 ASSERT(isSet());
60 return m_encodedWord >> shift();
61 }
62 void setIndex(NodeIndex nodeIndex)
63 {
64 m_encodedWord = makeWord(nodeIndex, useKind());
65 }
66
67 UseKind useKind() const
68 {
69 ASSERT(isSet());
70 unsigned masked = m_encodedWord & (((1 << shift()) - 1));
71 ASSERT(masked < LastUseKind);
72 return static_cast<UseKind>(masked);
73 }
74 void setUseKind(UseKind useKind)
75 {
76 ASSERT(isSet());
77 m_encodedWord = makeWord(index(), useKind);
78 }
79
80 bool isSet() const { return indexUnchecked() != NoNode; }
81 bool operator!() const { return !isSet(); }
82
83 bool operator==(Edge other) const
84 {
85 return m_encodedWord == other.m_encodedWord;
86 }
87 bool operator!=(Edge other) const
88 {
89 return m_encodedWord != other.m_encodedWord;
90 }
91
92private:
93 friend class AdjacencyList;
94
95 static uint32_t shift() { return 4; }
96
97 static int32_t makeWord(NodeIndex nodeIndex, UseKind useKind)
98 {
99 ASSERT(static_cast<uint32_t>(((static_cast<int32_t>(nodeIndex) << shift()) >> shift())) == nodeIndex);
100 ASSERT(useKind >= 0 && useKind < LastUseKind);
101 ASSERT(LastUseKind <= (1 << shift()));
102 return (nodeIndex << shift()) | useKind;
103 }
104
105 int32_t m_encodedWord;
106};
107
108inline bool operator==(Edge nodeUse, NodeIndex nodeIndex)
109{
110 return nodeUse.indexUnchecked() == nodeIndex;
111}
112inline bool operator==(NodeIndex nodeIndex, Edge nodeUse)
113{
114 return nodeUse.indexUnchecked() == nodeIndex;
115}
116inline bool operator!=(Edge nodeUse, NodeIndex nodeIndex)
117{
118 return nodeUse.indexUnchecked() != nodeIndex;
119}
120inline bool operator!=(NodeIndex nodeIndex, Edge nodeUse)
121{
122 return nodeUse.indexUnchecked() != nodeIndex;
123}
124
125} } // namespace JSC::DFG
126
127#endif // ENABLE(DFG_JIT)
128
129#endif // DFGEdge_h
130