| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/verifier.h" | 5 #include "src/compiler/verifier.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "src/compiler/generic-algorithm.h" | 10 #include "src/compiler/generic-algorithm.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 264 } |
| 265 block = block->dominator_; | 265 block = block->dominator_; |
| 266 if (block == NULL) break; | 266 if (block == NULL) break; |
| 267 use_pos = static_cast<int>(block->nodes_.size()) - 1; | 267 use_pos = static_cast<int>(block->nodes_.size()) - 1; |
| 268 if (node == block->control_input_) return true; | 268 if (node == block->control_input_) return true; |
| 269 } | 269 } |
| 270 return false; | 270 return false; |
| 271 } | 271 } |
| 272 | 272 |
| 273 | 273 |
| 274 static bool Dominates(Schedule* schedule, Node* dominator, Node* dominatee) { |
| 275 BasicBlock* dom = schedule->block(dominator); |
| 276 BasicBlock* sub = schedule->block(dominatee); |
| 277 while (sub != NULL) { |
| 278 if (sub == dom) { |
| 279 return true; |
| 280 } |
| 281 sub = sub->dominator_; |
| 282 } |
| 283 return false; |
| 284 } |
| 285 |
| 286 |
| 274 static void CheckInputsDominate(Schedule* schedule, BasicBlock* block, | 287 static void CheckInputsDominate(Schedule* schedule, BasicBlock* block, |
| 275 Node* node, int use_pos) { | 288 Node* node, int use_pos) { |
| 276 for (int j = OperatorProperties::GetValueInputCount(node->op()) - 1; j >= 0; | 289 for (int j = OperatorProperties::GetValueInputCount(node->op()) - 1; j >= 0; |
| 277 j--) { | 290 j--) { |
| 278 BasicBlock* use_block = block; | 291 BasicBlock* use_block = block; |
| 279 if (node->opcode() == IrOpcode::kPhi) { | 292 if (node->opcode() == IrOpcode::kPhi) { |
| 280 use_block = use_block->PredecessorAt(j); | 293 use_block = use_block->PredecessorAt(j); |
| 281 use_pos = static_cast<int>(use_block->nodes_.size()) - 1; | 294 use_pos = static_cast<int>(use_block->nodes_.size()) - 1; |
| 282 } | 295 } |
| 283 Node* input = node->InputAt(j); | 296 Node* input = node->InputAt(j); |
| 284 if (!HasDominatingDef(schedule, node->InputAt(j), block, use_block, | 297 if (!HasDominatingDef(schedule, node->InputAt(j), block, use_block, |
| 285 use_pos)) { | 298 use_pos)) { |
| 286 V8_Fatal(__FILE__, __LINE__, | 299 V8_Fatal(__FILE__, __LINE__, |
| 287 "Node #%d:%s in B%d is not dominated by input@%d #%d:%s", | 300 "Node #%d:%s in B%d is not dominated by input@%d #%d:%s", |
| 288 node->id(), node->op()->mnemonic(), block->id(), j, input->id(), | 301 node->id(), node->op()->mnemonic(), block->id(), j, input->id(), |
| 289 input->op()->mnemonic()); | 302 input->op()->mnemonic()); |
| 290 } | 303 } |
| 291 } | 304 } |
| 305 // Ensure that nodes are dominated by their control inputs; |
| 306 // kEnd is an exception, as unreachable blocks resulting from kMerge |
| 307 // are not in the RPO. |
| 308 if (OperatorProperties::GetControlInputCount(node->op()) == 1 && |
| 309 node->opcode() != IrOpcode::kEnd) { |
| 310 Node* ctl = NodeProperties::GetControlInput(node); |
| 311 if (!Dominates(schedule, ctl, node)) { |
| 312 V8_Fatal(__FILE__, __LINE__, |
| 313 "Node #%d:%s in B%d is not dominated by control input #%d:%s", |
| 314 node->id(), node->op()->mnemonic(), block->id(), ctl->id(), |
| 315 ctl->op()->mnemonic()); |
| 316 } |
| 317 } |
| 292 } | 318 } |
| 293 | 319 |
| 294 | 320 |
| 295 void ScheduleVerifier::Run(Schedule* schedule) { | 321 void ScheduleVerifier::Run(Schedule* schedule) { |
| 296 const int count = schedule->BasicBlockCount(); | 322 const int count = schedule->BasicBlockCount(); |
| 297 Zone tmp_zone(schedule->zone()->isolate()); | 323 Zone tmp_zone(schedule->zone()->isolate()); |
| 298 Zone* zone = &tmp_zone; | 324 Zone* zone = &tmp_zone; |
| 299 BasicBlock* start = schedule->start(); | 325 BasicBlock* start = schedule->start(); |
| 300 BasicBlockVector* rpo_order = schedule->rpo_order(); | 326 BasicBlockVector* rpo_order = schedule->rpo_order(); |
| 301 | 327 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 // Check inputs for all nodes in the block. | 472 // Check inputs for all nodes in the block. |
| 447 for (size_t i = 0; i < block->nodes_.size(); i++) { | 473 for (size_t i = 0; i < block->nodes_.size(); i++) { |
| 448 Node* node = block->nodes_[i]; | 474 Node* node = block->nodes_[i]; |
| 449 CheckInputsDominate(schedule, block, node, static_cast<int>(i) - 1); | 475 CheckInputsDominate(schedule, block, node, static_cast<int>(i) - 1); |
| 450 } | 476 } |
| 451 } | 477 } |
| 452 } | 478 } |
| 453 } | 479 } |
| 454 } | 480 } |
| 455 } // namespace v8::internal::compiler | 481 } // namespace v8::internal::compiler |
| OLD | NEW |