]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | /* |
2 | * Copyright (C) 2013 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 DFGAvailability_h | |
27 | #define DFGAvailability_h | |
28 | ||
29 | #if ENABLE(DFG_JIT) | |
30 | ||
31 | #include "DFGFlushedAt.h" | |
32 | #include "DFGVariableAccessData.h" | |
33 | ||
34 | namespace JSC { namespace DFG { | |
35 | ||
36 | struct Node; | |
37 | ||
38 | class Availability { | |
39 | public: | |
40 | Availability() | |
41 | : m_node(0) | |
42 | , m_flushedAt(DeadFlush) | |
43 | { | |
44 | } | |
45 | ||
46 | explicit Availability(Node* node) | |
47 | : m_node(node) | |
48 | , m_flushedAt(ConflictingFlush) | |
49 | { | |
50 | } | |
51 | ||
52 | explicit Availability(FlushedAt flushedAt) | |
53 | : m_node(unavailableMarker()) | |
54 | , m_flushedAt(flushedAt) | |
55 | { | |
56 | } | |
57 | ||
58 | Availability(Node* node, FlushedAt flushedAt) | |
59 | : m_node(node) | |
60 | , m_flushedAt(flushedAt) | |
61 | { | |
62 | } | |
63 | ||
64 | static Availability unavailable() | |
65 | { | |
66 | return Availability(unavailableMarker(), FlushedAt(ConflictingFlush)); | |
67 | } | |
68 | ||
69 | Availability withFlush(FlushedAt flush) const | |
70 | { | |
71 | return Availability(m_node, flush); | |
72 | } | |
73 | ||
74 | Availability withNode(Node* node) const | |
75 | { | |
76 | return Availability(node, m_flushedAt); | |
77 | } | |
78 | ||
79 | Availability withUnavailableNode() const | |
80 | { | |
81 | return withNode(unavailableMarker()); | |
82 | } | |
83 | ||
ed1e77d3 A |
84 | void setFlush(FlushedAt flushedAt) |
85 | { | |
86 | m_flushedAt = flushedAt; | |
87 | } | |
88 | ||
89 | void setNode(Node* node) | |
90 | { | |
91 | m_node = node; | |
92 | } | |
93 | ||
94 | void setNodeUnavailable() | |
95 | { | |
96 | m_node = unavailableMarker(); | |
97 | } | |
98 | ||
81345200 A |
99 | bool nodeIsUndecided() const { return !m_node; } |
100 | bool nodeIsUnavailable() const { return m_node == unavailableMarker(); } | |
101 | ||
102 | bool hasNode() const { return !nodeIsUndecided() && !nodeIsUnavailable(); } | |
ed1e77d3 | 103 | bool shouldUseNode() const { return !isFlushUseful() && hasNode(); } |
81345200 A |
104 | |
105 | Node* node() const | |
106 | { | |
107 | ASSERT(!nodeIsUndecided()); | |
108 | ASSERT(!nodeIsUnavailable()); | |
109 | return m_node; | |
110 | } | |
111 | ||
112 | FlushedAt flushedAt() const { return m_flushedAt; } | |
ed1e77d3 A |
113 | bool isFlushUseful() const |
114 | { | |
115 | return flushedAt().format() != DeadFlush && flushedAt().format() != ConflictingFlush; | |
116 | } | |
117 | ||
118 | bool isDead() const { return !isFlushUseful() && !hasNode(); } | |
81345200 A |
119 | |
120 | bool operator!() const { return nodeIsUnavailable() && flushedAt().format() == ConflictingFlush; } | |
121 | ||
122 | bool operator==(const Availability& other) const | |
123 | { | |
124 | return m_node == other.m_node | |
125 | && m_flushedAt == other.m_flushedAt; | |
126 | } | |
127 | ||
ed1e77d3 A |
128 | bool operator!=(const Availability& other) const |
129 | { | |
130 | return !(*this == other); | |
131 | } | |
132 | ||
81345200 A |
133 | Availability merge(const Availability& other) const |
134 | { | |
135 | return Availability( | |
136 | mergeNodes(m_node, other.m_node), | |
137 | m_flushedAt.merge(other.m_flushedAt)); | |
138 | } | |
139 | ||
140 | void dump(PrintStream&) const; | |
141 | void dumpInContext(PrintStream&, DumpContext*) const; | |
142 | ||
143 | private: | |
144 | static Node* mergeNodes(Node* a, Node* b) | |
145 | { | |
146 | if (!a) | |
147 | return b; | |
148 | if (!b) | |
149 | return a; | |
150 | if (a == b) | |
151 | return a; | |
152 | return unavailableMarker(); | |
153 | } | |
154 | ||
155 | static Node* unavailableMarker() | |
156 | { | |
157 | return bitwise_cast<Node*>(static_cast<intptr_t>(1)); | |
158 | } | |
159 | ||
160 | Node* m_node; | |
161 | FlushedAt m_flushedAt; | |
162 | }; | |
163 | ||
164 | } } // namespace JSC::DFG | |
165 | ||
166 | #endif // ENABLE(DFG_JIT) | |
167 | ||
168 | #endif // DFGAvailability_h | |
169 |