| 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 namespace v8 { | 7 namespace v8 { |
| 8 namespace internal { | 8 namespace internal { |
| 9 namespace compiler { | 9 namespace compiler { |
| 10 | 10 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } else { | 166 } else { |
| 167 return GetValuesNodeFromCache(&(buffer->front()), count); | 167 return GetValuesNodeFromCache(&(buffer->front()), count); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 | 171 |
| 172 Node* StateValuesCache::GetNodeForValues(Node** values, size_t count) { | 172 Node* StateValuesCache::GetNodeForValues(Node** values, size_t count) { |
| 173 #if DEBUG | 173 #if DEBUG |
| 174 for (size_t i = 0; i < count; i++) { | 174 for (size_t i = 0; i < count; i++) { |
| 175 DCHECK_NE(values[i]->opcode(), IrOpcode::kStateValues); | 175 DCHECK_NE(values[i]->opcode(), IrOpcode::kStateValues); |
| 176 DCHECK_NE(values[i]->opcode(), IrOpcode::kTypedStateValues); |
| 176 } | 177 } |
| 177 #endif | 178 #endif |
| 178 if (count == 0) { | 179 if (count == 0) { |
| 179 return GetEmptyStateValues(); | 180 return GetEmptyStateValues(); |
| 180 } | 181 } |
| 181 size_t height = 0; | 182 size_t height = 0; |
| 182 size_t max_nodes = 1; | 183 size_t max_nodes = 1; |
| 183 while (count > max_nodes) { | 184 while (count > max_nodes) { |
| 184 height++; | 185 height++; |
| 185 max_nodes *= kMaxInputCount; | 186 max_nodes *= kMaxInputCount; |
| 186 } | 187 } |
| 187 | 188 |
| 188 ValueArrayIterator it(values, count); | 189 ValueArrayIterator it(values, count); |
| 189 | 190 |
| 190 Node* tree = BuildTree(&it, height); | 191 Node* tree = BuildTree(&it, height); |
| 191 | 192 |
| 192 // If the 'tree' is a single node, equip it with a StateValues wrapper. | 193 // If the 'tree' is a single node, equip it with a StateValues wrapper. |
| 193 if (tree->opcode() != IrOpcode::kStateValues) { | 194 if (tree->opcode() != IrOpcode::kStateValues && |
| 195 tree->opcode() != IrOpcode::kTypedStateValues) { |
| 194 tree = GetValuesNodeFromCache(&tree, 1); | 196 tree = GetValuesNodeFromCache(&tree, 1); |
| 195 } | 197 } |
| 196 | 198 |
| 197 return tree; | 199 return tree; |
| 198 } | 200 } |
| 199 | 201 |
| 200 | 202 |
| 201 StateValuesAccess::iterator::iterator(Node* node) : current_depth_(0) { | 203 StateValuesAccess::iterator::iterator(Node* node) : current_depth_(0) { |
| 202 // A hacky way initialize - just set the index before the node we want | 204 // A hacky way initialize - just set the index before the node we want |
| 203 // to process and then advance to it. | 205 // to process and then advance to it. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 int index = Top()->index; | 244 int index = Top()->index; |
| 243 | 245 |
| 244 if (index >= node->InputCount()) { | 246 if (index >= node->InputCount()) { |
| 245 // Pop stack and move to the next sibling. | 247 // Pop stack and move to the next sibling. |
| 246 Pop(); | 248 Pop(); |
| 247 if (done()) { | 249 if (done()) { |
| 248 // Stack is exhausted, we have reached the end. | 250 // Stack is exhausted, we have reached the end. |
| 249 return; | 251 return; |
| 250 } | 252 } |
| 251 Top()->index++; | 253 Top()->index++; |
| 252 } else if (node->InputAt(index)->opcode() == IrOpcode::kStateValues) { | 254 } else if (node->InputAt(index)->opcode() == IrOpcode::kStateValues || |
| 255 node->InputAt(index)->opcode() == IrOpcode::kTypedStateValues) { |
| 253 // Nested state, we need to push to the stack. | 256 // Nested state, we need to push to the stack. |
| 254 Push(node->InputAt(index)); | 257 Push(node->InputAt(index)); |
| 255 } else { | 258 } else { |
| 256 // We are on a valid node, we can stop the iteration. | 259 // We are on a valid node, we can stop the iteration. |
| 257 return; | 260 return; |
| 258 } | 261 } |
| 259 } | 262 } |
| 260 } | 263 } |
| 261 | 264 |
| 262 | 265 |
| 263 Node* StateValuesAccess::iterator::node() { | 266 Node* StateValuesAccess::iterator::node() { |
| 264 return Top()->node->InputAt(Top()->index); | 267 return Top()->node->InputAt(Top()->index); |
| 265 } | 268 } |
| 266 | 269 |
| 267 | 270 |
| 271 MachineType StateValuesAccess::iterator::type() { |
| 272 Node* state = Top()->node; |
| 273 if (state->opcode() == IrOpcode::kStateValues) { |
| 274 return kMachAnyTagged; |
| 275 } else { |
| 276 DCHECK_EQ(IrOpcode::kTypedStateValues, state->opcode()); |
| 277 ZoneVector<MachineType>* types = |
| 278 OpParameter<ZoneVector<MachineType>*>(state); |
| 279 return (*types)[Top()->index]; |
| 280 } |
| 281 } |
| 282 |
| 283 |
| 268 bool StateValuesAccess::iterator::operator!=(iterator& other) { | 284 bool StateValuesAccess::iterator::operator!=(iterator& other) { |
| 269 // We only allow comparison with end(). | 285 // We only allow comparison with end(). |
| 270 CHECK(other.done()); | 286 CHECK(other.done()); |
| 271 return !done(); | 287 return !done(); |
| 272 } | 288 } |
| 273 | 289 |
| 274 | 290 |
| 275 StateValuesAccess::iterator& StateValuesAccess::iterator::operator++() { | 291 StateValuesAccess::iterator& StateValuesAccess::iterator::operator++() { |
| 276 Advance(); | 292 Advance(); |
| 277 return *this; | 293 return *this; |
| 278 } | 294 } |
| 279 | 295 |
| 280 | 296 |
| 281 Node* StateValuesAccess::iterator::operator*() { return node(); } | 297 StateValuesAccess::TypedNode StateValuesAccess::iterator::operator*() { |
| 298 return TypedNode(node(), type()); |
| 299 } |
| 282 | 300 |
| 283 | 301 |
| 284 size_t StateValuesAccess::size() { | 302 size_t StateValuesAccess::size() { |
| 285 size_t count = 0; | 303 size_t count = 0; |
| 286 for (int i = 0; i < node_->InputCount(); i++) { | 304 for (int i = 0; i < node_->InputCount(); i++) { |
| 287 if (node_->InputAt(i)->opcode() == IrOpcode::kStateValues) { | 305 if (node_->InputAt(i)->opcode() == IrOpcode::kStateValues || |
| 306 node_->InputAt(i)->opcode() == IrOpcode::kTypedStateValues) { |
| 288 count += StateValuesAccess(node_->InputAt(i)).size(); | 307 count += StateValuesAccess(node_->InputAt(i)).size(); |
| 289 } else { | 308 } else { |
| 290 count++; | 309 count++; |
| 291 } | 310 } |
| 292 } | 311 } |
| 293 return count; | 312 return count; |
| 294 } | 313 } |
| 295 | 314 |
| 296 } // namespace compiler | 315 } // namespace compiler |
| 297 } // namespace internal | 316 } // namespace internal |
| 298 } // namespace v8 | 317 } // namespace v8 |
| OLD | NEW |