OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/state-values-utils.h" | 5 #include "src/compiler/state-values-utils.h" |
6 | 6 |
7 #include "src/bit-vector.h" | |
8 | |
7 namespace v8 { | 9 namespace v8 { |
8 namespace internal { | 10 namespace internal { |
9 namespace compiler { | 11 namespace compiler { |
10 | 12 |
13 // A (Typed)StateValues node's has a bitmask specifying if its inputs are | |
14 // represented sparsely. If the bitmask value is 0, then the inputs are not | |
15 // sparse; otherwise, they should be interpreted as follows: | |
Jarin
2016/12/08 07:59:43
This explanation should probably be in common-oper
Leszek Swirski
2016/12/08 15:44:31
Done.
| |
16 // | |
17 // * The bitmask represents which values are live, with 1 for live values | |
18 // and 0 for dead (optimized out) values. | |
19 // * The inputs to the node are the live values, in the order of the 1s from | |
20 // least- to most-significant | |
21 // * The top bit of the bitmask is a guard indicating the end of the values, | |
22 // whether live or dead (and is not representative of a live node) | |
Jarin (Google)
2016/12/07 15:16:44
If really want to use such a complex encoding sche
Leszek Swirski
2016/12/08 15:44:30
Done.
| |
23 // | |
24 // So, for N 1s in the bitmask, there are N - 1 inputs into the node. | |
25 | |
11 StateValuesCache::StateValuesCache(JSGraph* js_graph) | 26 StateValuesCache::StateValuesCache(JSGraph* js_graph) |
12 : js_graph_(js_graph), | 27 : js_graph_(js_graph), |
13 hash_map_(AreKeysEqual, ZoneHashMap::kDefaultHashMapCapacity, | 28 hash_map_(AreKeysEqual, ZoneHashMap::kDefaultHashMapCapacity, |
14 ZoneAllocationPolicy(zone())), | 29 ZoneAllocationPolicy(zone())), |
15 working_space_(zone()), | 30 working_space_(zone()), |
16 empty_state_values_(nullptr) {} | 31 empty_state_values_(nullptr) {} |
17 | 32 |
18 | 33 |
19 // static | 34 // static |
20 bool StateValuesCache::AreKeysEqual(void* key1, void* key2) { | 35 bool StateValuesCache::AreKeysEqual(void* key1, void* key2) { |
(...skipping 19 matching lines...) Expand all Loading... | |
40 } | 55 } |
41 UNREACHABLE(); | 56 UNREACHABLE(); |
42 } | 57 } |
43 | 58 |
44 | 59 |
45 // static | 60 // static |
46 bool StateValuesCache::IsKeysEqualToNode(StateValuesKey* key, Node* node) { | 61 bool StateValuesCache::IsKeysEqualToNode(StateValuesKey* key, Node* node) { |
47 if (key->count != static_cast<size_t>(node->InputCount())) { | 62 if (key->count != static_cast<size_t>(node->InputCount())) { |
48 return false; | 63 return false; |
49 } | 64 } |
65 | |
66 DCHECK(node->opcode() == IrOpcode::kStateValues); | |
67 uint32_t node_mask = OpParameter<uint32_t>(node); | |
Jarin (Google)
2016/12/07 15:16:44
No OpParameter, please!
Leszek Swirski
2016/12/08 15:44:30
Done.
| |
68 | |
69 if (node_mask != key->mask) { | |
70 return false; | |
71 } | |
72 | |
50 for (size_t i = 0; i < key->count; i++) { | 73 for (size_t i = 0; i < key->count; i++) { |
51 if (key->values[i] != node->InputAt(static_cast<int>(i))) { | 74 if (key->values[i] != node->InputAt(static_cast<int>(i))) { |
52 return false; | 75 return false; |
53 } | 76 } |
54 } | 77 } |
55 return true; | 78 return true; |
56 } | 79 } |
57 | 80 |
58 | 81 |
59 // static | 82 // static |
60 bool StateValuesCache::AreValueKeysEqual(StateValuesKey* key1, | 83 bool StateValuesCache::AreValueKeysEqual(StateValuesKey* key1, |
61 StateValuesKey* key2) { | 84 StateValuesKey* key2) { |
62 if (key1->count != key2->count) { | 85 if (key1->count != key2->count) { |
63 return false; | 86 return false; |
64 } | 87 } |
88 if (key1->mask != key2->mask) { | |
89 return false; | |
90 } | |
65 for (size_t i = 0; i < key1->count; i++) { | 91 for (size_t i = 0; i < key1->count; i++) { |
66 if (key1->values[i] != key2->values[i]) { | 92 if (key1->values[i] != key2->values[i]) { |
67 return false; | 93 return false; |
68 } | 94 } |
69 } | 95 } |
70 return true; | 96 return true; |
71 } | 97 } |
72 | 98 |
73 | 99 |
74 Node* StateValuesCache::GetEmptyStateValues() { | 100 Node* StateValuesCache::GetEmptyStateValues() { |
75 if (empty_state_values_ == nullptr) { | 101 if (empty_state_values_ == nullptr) { |
76 empty_state_values_ = graph()->NewNode(common()->StateValues(0)); | 102 empty_state_values_ = graph()->NewNode(common()->StateValues(0, 0u)); |
77 } | 103 } |
78 return empty_state_values_; | 104 return empty_state_values_; |
79 } | 105 } |
80 | 106 |
81 | 107 StateValuesCache::WorkingBuffer& StateValuesCache::GetWorkingSpace( |
82 NodeVector* StateValuesCache::GetWorkingSpace(size_t level) { | 108 size_t level) { |
83 while (working_space_.size() <= level) { | 109 if (working_space_.size() <= level) { |
84 void* space = zone()->New(sizeof(NodeVector)); | 110 working_space_.resize(level + 1); |
85 working_space_.push_back(new (space) | |
86 NodeVector(kMaxInputCount, nullptr, zone())); | |
87 } | 111 } |
88 return working_space_[level]; | 112 return working_space_[level]; |
89 } | 113 } |
90 | 114 |
91 namespace { | 115 namespace { |
92 | 116 |
93 int StateValuesHashKey(Node** nodes, size_t count) { | 117 int StateValuesHashKey(Node** nodes, size_t count) { |
94 size_t hash = count; | 118 size_t hash = count; |
95 for (size_t i = 0; i < count; i++) { | 119 for (size_t i = 0; i < count; i++) { |
96 hash = hash * 23 + nodes[i]->id(); | 120 hash = hash * 23 + (nodes[i] == nullptr ? 0 : nodes[i]->id()); |
97 } | 121 } |
98 return static_cast<int>(hash & 0x7fffffff); | 122 return static_cast<int>(hash & 0x7fffffff); |
99 } | 123 } |
100 | 124 |
101 } // namespace | 125 } // namespace |
102 | 126 |
103 | 127 Node* StateValuesCache::GetValuesNodeFromCache(Node** nodes, size_t count, |
104 Node* StateValuesCache::GetValuesNodeFromCache(Node** nodes, size_t count) { | 128 uint32_t mask) { |
105 StateValuesKey key(count, nodes); | 129 StateValuesKey key(count, mask, nodes); |
106 int hash = StateValuesHashKey(nodes, count); | 130 int hash = StateValuesHashKey(nodes, count); |
107 ZoneHashMap::Entry* lookup = | 131 ZoneHashMap::Entry* lookup = |
108 hash_map_.LookupOrInsert(&key, hash, ZoneAllocationPolicy(zone())); | 132 hash_map_.LookupOrInsert(&key, hash, ZoneAllocationPolicy(zone())); |
109 DCHECK_NOT_NULL(lookup); | 133 DCHECK_NOT_NULL(lookup); |
110 Node* node; | 134 Node* node; |
111 if (lookup->value == nullptr) { | 135 if (lookup->value == nullptr) { |
112 int input_count = static_cast<int>(count); | 136 int input_count = static_cast<int>(count); |
113 node = graph()->NewNode(common()->StateValues(input_count), input_count, | 137 node = graph()->NewNode(common()->StateValues(input_count, mask), |
114 nodes); | 138 input_count, nodes); |
115 NodeKey* new_key = new (zone()->New(sizeof(NodeKey))) NodeKey(node); | 139 NodeKey* new_key = new (zone()->New(sizeof(NodeKey))) NodeKey(node); |
116 lookup->key = new_key; | 140 lookup->key = new_key; |
117 lookup->value = node; | 141 lookup->value = node; |
118 } else { | 142 } else { |
119 node = reinterpret_cast<Node*>(lookup->value); | 143 node = reinterpret_cast<Node*>(lookup->value); |
120 } | 144 } |
121 return node; | 145 return node; |
122 } | 146 } |
123 | 147 |
148 Node* StateValuesCache::BuildTree(size_t& idx, Node** values, size_t count, | |
149 const BitVector* liveness, size_t level) { | |
150 WorkingBuffer& input_buffer = GetWorkingSpace(level); | |
151 size_t input_count = 0; | |
152 bool use_mask = false; | |
153 uint32_t mask = 0; | |
124 | 154 |
125 class StateValuesCache::ValueArrayIterator { | 155 if (level == 0) { |
126 public: | 156 // Virtual inputs are the live inputs plus the implicit dead inputs, which |
127 ValueArrayIterator(Node** values, size_t count) | 157 // are implied by the liveness mask. |
128 : values_(values), count_(count), current_(0) {} | 158 size_t virtual_input_count = 0; |
159 while (idx < count && input_count < kMaxInputCount && | |
160 (!use_mask || virtual_input_count < 31)) { | |
Jarin (Google)
2016/12/07 15:16:44
Magic constants (31) defined at the top of the fun
Leszek Swirski
2016/12/08 15:44:31
Done (moved into the new sparse input mask type).
| |
161 DCHECK_LE(idx, static_cast<size_t>(INT_MAX)); | |
162 if (liveness == nullptr || liveness->Contains(static_cast<int>(idx))) { | |
163 mask |= 1 << virtual_input_count; | |
164 input_buffer[input_count++] = values[idx]; | |
165 } else { | |
166 use_mask = true; | |
Jarin (Google)
2016/12/07 15:16:44
What improvement do you see from special casing th
Leszek Swirski
2016/12/08 15:44:31
I haven't measured it, but I've removed it since t
| |
167 } | |
168 virtual_input_count++; | |
129 | 169 |
130 void Advance() { | 170 idx++; |
131 if (!done()) { | 171 } |
132 current_++; | 172 |
173 if (use_mask) { | |
174 DCHECK(virtual_input_count < 32); | |
175 mask |= 1 << virtual_input_count; | |
176 } else { | |
177 mask = 0; | |
178 } | |
179 } else { | |
180 while (idx < count && input_count < kMaxInputCount) { | |
181 if (count - idx < kMaxInputCount - input_count) { | |
182 // If we have fewer values remaining than inputs remaining, dump the | |
183 // remaining values into this node. | |
184 | |
185 // TODO(leszeks): We could optimise this further by counting remaining | |
186 // live nodes, though this gets complicated with the 31 bit limit on the | |
187 // mask. | |
Jarin (Google)
2016/12/07 15:16:44
Maybe the remove the comment, the complexity budge
Leszek Swirski
2016/12/08 15:44:30
Kept the comment (shortened it a bit), after refac
| |
188 | |
189 // All previous inputs are live. | |
190 mask = ((1 << input_count) - 1); | |
191 | |
192 // Add the remaining values as inputs. | |
193 size_t virtual_input_count = input_count; | |
194 while (idx < count) { | |
195 DCHECK_LE(input_count, kMaxInputCount); | |
196 DCHECK_LE(idx, static_cast<size_t>(INT_MAX)); | |
197 DCHECK(!use_mask || virtual_input_count < 31); | |
198 | |
199 if (liveness == nullptr || | |
200 liveness->Contains(static_cast<int>(idx))) { | |
Jarin (Google)
2016/12/07 15:16:44
This looks very similar to the code above, perhaps
Leszek Swirski
2016/12/08 15:44:30
Done, I had a TODO for it at some point anyway.
| |
201 mask |= 1 << virtual_input_count; | |
202 input_buffer[input_count++] = values[idx]; | |
203 } else { | |
204 use_mask = true; | |
205 } | |
206 virtual_input_count++; | |
207 | |
208 idx++; | |
209 } | |
210 | |
211 if (use_mask) { | |
212 DCHECK(virtual_input_count < 32); | |
213 mask |= 1 << virtual_input_count; | |
214 } else { | |
215 mask = 0; | |
216 } | |
217 } else { | |
218 // Otherwise, add the values to a subtree and add that as an input. | |
219 Node* subtree = BuildTree(idx, values, count, liveness, level - 1); | |
220 input_buffer[input_count++] = subtree; | |
221 } | |
133 } | 222 } |
134 } | 223 } |
135 | 224 |
136 bool done() { return current_ >= count_; } | 225 if (input_count == 1 && !use_mask) { |
137 | 226 // Elide the StateValue node if there is only one input. |
138 Node* node() { | 227 return input_buffer[0]; |
139 DCHECK(!done()); | |
140 return values_[current_]; | |
141 } | |
142 | |
143 private: | |
144 Node** values_; | |
145 size_t count_; | |
146 size_t current_; | |
147 }; | |
148 | |
149 | |
150 Node* StateValuesCache::BuildTree(ValueArrayIterator* it, size_t max_height) { | |
151 if (max_height == 0) { | |
152 Node* node = it->node(); | |
153 it->Advance(); | |
154 return node; | |
155 } | |
156 DCHECK(!it->done()); | |
157 | |
158 NodeVector* buffer = GetWorkingSpace(max_height); | |
159 size_t count = 0; | |
160 for (; count < kMaxInputCount; count++) { | |
161 if (it->done()) break; | |
162 (*buffer)[count] = BuildTree(it, max_height - 1); | |
163 } | |
164 if (count == 1) { | |
165 return (*buffer)[0]; | |
166 } else { | 228 } else { |
167 return GetValuesNodeFromCache(&(buffer->front()), count); | 229 return GetValuesNodeFromCache(input_buffer.data(), input_count, mask); |
168 } | 230 } |
169 } | 231 } |
170 | 232 |
171 | 233 Node* StateValuesCache::GetNodeForValues(Node** values, size_t count, |
172 Node* StateValuesCache::GetNodeForValues(Node** values, size_t count) { | 234 const BitVector* liveness) { |
173 #if DEBUG | 235 #if DEBUG |
174 for (size_t i = 0; i < count; i++) { | 236 for (size_t i = 0; i < count; i++) { |
175 DCHECK_NE(values[i]->opcode(), IrOpcode::kStateValues); | 237 if (values[i] != nullptr) { |
176 DCHECK_NE(values[i]->opcode(), IrOpcode::kTypedStateValues); | 238 DCHECK_NE(values[i]->opcode(), IrOpcode::kStateValues); |
239 DCHECK_NE(values[i]->opcode(), IrOpcode::kTypedStateValues); | |
240 } | |
241 } | |
242 if (liveness != nullptr) { | |
243 // Liveness can have extra bits for the stack or accumulator, which we | |
244 // ignore here. | |
245 DCHECK_LE(count, static_cast<size_t>(liveness->length())); | |
246 | |
247 for (size_t i = 0; i < count; i++) { | |
248 if (liveness->Contains(static_cast<int>(i))) { | |
249 DCHECK_NOT_NULL(values[i]); | |
250 } | |
251 } | |
177 } | 252 } |
178 #endif | 253 #endif |
179 if (count == 0) { | 254 if (count == 0) { |
180 return GetEmptyStateValues(); | 255 return GetEmptyStateValues(); |
181 } | 256 } |
257 | |
258 // This is a worst-case tree height estimate, assuming that all values are | |
259 // live. We could get a better estimate by counting zeroes in the liveness | |
260 // vector, but there's no point -- any excess height in the tree will be | |
261 // collapsed by the single-input elision at the end of BuildTree. | |
182 size_t height = 0; | 262 size_t height = 0; |
183 size_t max_nodes = 1; | 263 size_t max_inputs = kMaxInputCount; |
184 while (count > max_nodes) { | 264 while (count > max_inputs) { |
185 height++; | 265 height++; |
186 max_nodes *= kMaxInputCount; | 266 max_inputs *= kMaxInputCount; |
187 } | 267 } |
188 | 268 |
189 ValueArrayIterator it(values, count); | 269 size_t idx = 0; |
190 | 270 Node* tree = BuildTree(idx, values, count, liveness, height); |
191 Node* tree = BuildTree(&it, height); | |
192 | 271 |
193 // If the 'tree' is a single node, equip it with a StateValues wrapper. | 272 // If the 'tree' is a single node, equip it with a StateValues wrapper. |
194 if (tree->opcode() != IrOpcode::kStateValues && | 273 if (tree->opcode() != IrOpcode::kStateValues) { |
195 tree->opcode() != IrOpcode::kTypedStateValues) { | 274 tree = GetValuesNodeFromCache(&tree, 1, 0u); |
196 tree = GetValuesNodeFromCache(&tree, 1); | |
197 } | 275 } |
198 | 276 |
277 #if DEBUG | |
278 { | |
279 DCHECK_EQ(count, StateValuesAccess(tree).size()); | |
280 int i; | |
281 auto access = StateValuesAccess(tree); | |
282 auto it = access.begin(); | |
283 auto itend = access.end(); | |
284 for (i = 0; it != itend; ++it, ++i) { | |
285 if (liveness == nullptr || liveness->Contains(i)) { | |
286 DCHECK((*it).node == values[i]); | |
287 } else { | |
288 DCHECK((*it).node == nullptr); | |
289 } | |
290 } | |
291 DCHECK_EQ(static_cast<size_t>(i), count); | |
292 } | |
293 #endif | |
294 | |
199 return tree; | 295 return tree; |
200 } | 296 } |
201 | 297 |
298 namespace { | |
299 | |
300 uint32_t GetStateValueMask(Node* node) { | |
Jarin (Google)
2016/12/07 15:16:44
This should live somewhere in common-operator.h
Leszek Swirski
2016/12/08 15:44:30
Done.
| |
301 if (node->opcode() == IrOpcode::kStateValues) { | |
302 return OpParameter<uint32_t>(node); | |
303 } else { | |
304 DCHECK_EQ(node->opcode(), IrOpcode::kTypedStateValues); | |
305 return OpParameter<TypedStateValueInfo>(node).mask(); | |
306 } | |
307 } | |
308 | |
309 } // namespace | |
202 | 310 |
203 StateValuesAccess::iterator::iterator(Node* node) : current_depth_(0) { | 311 StateValuesAccess::iterator::iterator(Node* node) : current_depth_(0) { |
204 // A hacky way initialize - just set the index before the node we want | |
205 // to process and then advance to it. | |
206 stack_[current_depth_].node = node; | 312 stack_[current_depth_].node = node; |
207 stack_[current_depth_].index = -1; | 313 stack_[current_depth_].index = 0; |
208 Advance(); | 314 stack_[current_depth_].mask = GetStateValueMask(node); |
315 | |
316 EnsureValid(); | |
209 } | 317 } |
210 | 318 |
211 | 319 |
212 StateValuesAccess::iterator::StatePos* StateValuesAccess::iterator::Top() { | 320 StateValuesAccess::iterator::StatePos* StateValuesAccess::iterator::Top() { |
213 DCHECK(current_depth_ >= 0); | 321 DCHECK(current_depth_ >= 0); |
214 DCHECK(current_depth_ < kMaxInlineDepth); | 322 DCHECK(current_depth_ < kMaxInlineDepth); |
215 return &(stack_[current_depth_]); | 323 return &(stack_[current_depth_]); |
216 } | 324 } |
217 | 325 |
218 | 326 void StateValuesAccess::iterator::Push(Node* node, uint32_t mask) { |
219 void StateValuesAccess::iterator::Push(Node* node) { | |
220 current_depth_++; | 327 current_depth_++; |
221 CHECK(current_depth_ < kMaxInlineDepth); | 328 CHECK(current_depth_ < kMaxInlineDepth); |
222 stack_[current_depth_].node = node; | 329 stack_[current_depth_].node = node; |
330 stack_[current_depth_].mask = mask; | |
223 stack_[current_depth_].index = 0; | 331 stack_[current_depth_].index = 0; |
224 } | 332 } |
225 | 333 |
226 | 334 |
227 void StateValuesAccess::iterator::Pop() { | 335 void StateValuesAccess::iterator::Pop() { |
228 DCHECK(current_depth_ >= 0); | 336 DCHECK(current_depth_ >= 0); |
229 current_depth_--; | 337 current_depth_--; |
230 } | 338 } |
231 | 339 |
232 | 340 |
233 bool StateValuesAccess::iterator::done() { return current_depth_ < 0; } | 341 bool StateValuesAccess::iterator::done() { return current_depth_ < 0; } |
234 | 342 |
235 | 343 |
236 void StateValuesAccess::iterator::Advance() { | 344 void StateValuesAccess::iterator::Advance() { |
237 // Advance the current index. | 345 MoveToNextSibling(); |
238 Top()->index++; | 346 EnsureValid(); |
347 } | |
239 | 348 |
240 // Fix up the position to point to a valid node. | 349 void StateValuesAccess::iterator::MoveToNextSibling() { |
350 int mask = Top()->mask; | |
351 if (mask == 0 || (mask & 0x1) == 1) { | |
Jarin (Google)
2016/12/07 15:16:44
Nit: Why 0x1? On line 446, you say mask & 1. Perha
Leszek Swirski
2016/12/08 15:44:31
Completely refactored out into sparse input iterat
| |
352 Top()->index++; | |
353 } | |
354 Top()->mask >>= 1; | |
355 } | |
356 | |
357 void StateValuesAccess::iterator::EnsureValid() { | |
241 while (true) { | 358 while (true) { |
242 // TODO(jarin): Factor to a separate method. | 359 uint32_t mask = Top()->mask; |
360 int index = Top()->index; | |
243 Node* node = Top()->node; | 361 Node* node = Top()->node; |
244 int index = Top()->index; | |
245 | 362 |
246 if (index >= node->InputCount()) { | 363 if (mask != 0 && (mask & 0x1) == 0) { |
247 // Pop stack and move to the next sibling. | 364 // We are on a valid (dead) node. |
Jarin (Google)
2016/12/07 15:16:44
dead -> optimized_out here and elsewhere
Leszek Swirski
2016/12/08 15:44:30
Done.
| |
365 return; | |
366 } | |
367 | |
368 if (mask == 1 || (mask == 0 && index >= node->InputCount())) { | |
369 // We have hit the guard bit or exhausted our inputs. Pop the stack and | |
370 // move to the next sibling. | |
248 Pop(); | 371 Pop(); |
249 if (done()) { | 372 if (done()) { |
250 // Stack is exhausted, we have reached the end. | 373 // Stack is exhausted, we have reached the end. |
251 return; | 374 return; |
252 } | 375 } |
253 Top()->index++; | 376 MoveToNextSibling(); |
254 } else if (node->InputAt(index)->opcode() == IrOpcode::kStateValues || | 377 continue; |
255 node->InputAt(index)->opcode() == IrOpcode::kTypedStateValues) { | 378 } |
379 | |
380 // At this point the value is known to be live and within our input nodes. | |
381 Node* value_node = node->InputAt(Top()->index); | |
382 | |
383 if (value_node->opcode() == IrOpcode::kStateValues || | |
384 value_node->opcode() == IrOpcode::kTypedStateValues) { | |
256 // Nested state, we need to push to the stack. | 385 // Nested state, we need to push to the stack. |
257 Push(node->InputAt(index)); | 386 Push(node->InputAt(index), GetStateValueMask(node->InputAt(index))); |
258 } else { | 387 continue; |
259 // We are on a valid node, we can stop the iteration. | |
260 return; | |
261 } | 388 } |
389 | |
390 // We are on a valid node, we can stop the iteration. | |
391 return; | |
262 } | 392 } |
263 } | 393 } |
264 | 394 |
265 | 395 |
266 Node* StateValuesAccess::iterator::node() { | 396 Node* StateValuesAccess::iterator::node() { |
267 return Top()->node->InputAt(Top()->index); | 397 if (Top()->mask != 0 && (Top()->mask & 0x1) == 0) { |
398 return nullptr; | |
399 } else { | |
400 return Top()->node->InputAt(Top()->index); | |
401 } | |
268 } | 402 } |
269 | 403 |
270 | 404 |
271 MachineType StateValuesAccess::iterator::type() { | 405 MachineType StateValuesAccess::iterator::type() { |
272 Node* state = Top()->node; | 406 Node* state = Top()->node; |
273 if (state->opcode() == IrOpcode::kStateValues) { | 407 if (state->opcode() == IrOpcode::kStateValues) { |
274 return MachineType::AnyTagged(); | 408 return MachineType::AnyTagged(); |
275 } else { | 409 } else { |
276 DCHECK_EQ(IrOpcode::kTypedStateValues, state->opcode()); | 410 DCHECK_EQ(IrOpcode::kTypedStateValues, state->opcode()); |
277 ZoneVector<MachineType> const* types = MachineTypesOf(state->op()); | 411 |
278 return (*types)[Top()->index]; | 412 if (Top()->mask != 0 && (Top()->mask & 0x1) == 0) { |
413 return MachineType::None(); | |
414 } else { | |
415 ZoneVector<MachineType> const* types = MachineTypesOf(state->op()); | |
416 return (*types)[Top()->index]; | |
417 } | |
279 } | 418 } |
280 } | 419 } |
281 | 420 |
282 | 421 |
283 bool StateValuesAccess::iterator::operator!=(iterator& other) { | 422 bool StateValuesAccess::iterator::operator!=(iterator& other) { |
284 // We only allow comparison with end(). | 423 // We only allow comparison with end(). |
285 CHECK(other.done()); | 424 CHECK(other.done()); |
286 return !done(); | 425 return !done(); |
287 } | 426 } |
288 | 427 |
289 | 428 |
290 StateValuesAccess::iterator& StateValuesAccess::iterator::operator++() { | 429 StateValuesAccess::iterator& StateValuesAccess::iterator::operator++() { |
291 Advance(); | 430 Advance(); |
292 return *this; | 431 return *this; |
293 } | 432 } |
294 | 433 |
295 | 434 |
296 StateValuesAccess::TypedNode StateValuesAccess::iterator::operator*() { | 435 StateValuesAccess::TypedNode StateValuesAccess::iterator::operator*() { |
297 return TypedNode(node(), type()); | 436 return TypedNode(node(), type()); |
298 } | 437 } |
299 | 438 |
300 | 439 |
301 size_t StateValuesAccess::size() { | 440 size_t StateValuesAccess::size() { |
302 size_t count = 0; | 441 size_t count = 0; |
303 for (int i = 0; i < node_->InputCount(); i++) { | 442 uint32_t mask = GetStateValueMask(node_); |
304 if (node_->InputAt(i)->opcode() == IrOpcode::kStateValues || | 443 |
305 node_->InputAt(i)->opcode() == IrOpcode::kTypedStateValues) { | 444 int i = 0; |
306 count += StateValuesAccess(node_->InputAt(i)).size(); | 445 while ((mask == 0 && i < node_->InputCount()) || (mask != 0 && mask != 1)) { |
446 if (mask != 0 && (mask & 1) == 0) { | |
447 count++; | |
307 } else { | 448 } else { |
308 count++; | 449 if (node_->InputAt(i)->opcode() == IrOpcode::kStateValues || |
450 node_->InputAt(i)->opcode() == IrOpcode::kTypedStateValues) { | |
451 count += StateValuesAccess(node_->InputAt(i)).size(); | |
452 } else { | |
453 count++; | |
454 } | |
455 i++; | |
309 } | 456 } |
457 mask >>= 1; | |
310 } | 458 } |
459 | |
311 return count; | 460 return count; |
312 } | 461 } |
313 | 462 |
314 } // namespace compiler | 463 } // namespace compiler |
315 } // namespace internal | 464 } // namespace internal |
316 } // namespace v8 | 465 } // namespace v8 |
OLD | NEW |