Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: src/compiler/scheduler.cc

Issue 931623002: [turbofan] Optimize certain chains of Branch into a Switch. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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/scheduler.h" 5 #include "src/compiler/scheduler.h"
6 6
7 #include "src/bit-vector.h" 7 #include "src/bit-vector.h"
8 #include "src/compiler/common-operator.h" 8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/control-equivalence.h" 9 #include "src/compiler/control-equivalence.h"
10 #include "src/compiler/graph.h" 10 #include "src/compiler/graph.h"
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 void BuildBlocksForSuccessors(Node* node) { 366 void BuildBlocksForSuccessors(Node* node) {
367 size_t const successor_count = node->op()->ControlOutputCount(); 367 size_t const successor_count = node->op()->ControlOutputCount();
368 Node** successors = zone_->NewArray<Node*>(successor_count); 368 Node** successors = zone_->NewArray<Node*>(successor_count);
369 CollectSuccessorProjections(node, successors, successor_count); 369 CollectSuccessorProjections(node, successors, successor_count);
370 for (size_t index = 0; index < successor_count; ++index) { 370 for (size_t index = 0; index < successor_count; ++index) {
371 BuildBlockForNode(successors[index]); 371 BuildBlockForNode(successors[index]);
372 } 372 }
373 } 373 }
374 374
375 // Collect the branch-related projections from a node, such as IfTrue, 375 // Collect the branch-related projections from a node, such as IfTrue,
376 // IfFalse, and Case. 376 // IfFalse, Case and Default.
377 void CollectSuccessorProjections(Node* node, Node** successors, 377 void CollectSuccessorProjections(Node* node, Node** successors,
378 size_t successor_count) { 378 size_t successor_count) {
379 #ifdef DEBUG 379 #ifdef DEBUG
380 DCHECK_EQ(static_cast<int>(successor_count), node->UseCount()); 380 DCHECK_EQ(static_cast<int>(successor_count), node->UseCount());
381 std::memset(successors, 0, sizeof(*successors) * successor_count); 381 std::memset(successors, 0, sizeof(*successors) * successor_count);
382 #endif 382 #endif
383 size_t const kDefaultIndex = successor_count - 1;
384 size_t const kIfFalseIndex = 1;
Michael Starzinger 2015/02/17 12:23:35 Can we just inline these values below as it was be
Benedikt Meurer 2015/02/17 12:30:38 Done.
385 size_t const kIfTrueIndex = 0;
386 size_t if_value_index = 0;
383 for (Node* const use : node->uses()) { 387 for (Node* const use : node->uses()) {
384 size_t index; 388 size_t index;
385 switch (use->opcode()) { 389 switch (use->opcode()) {
386 default: 390 default:
387 UNREACHABLE(); 391 UNREACHABLE();
388 // Fall through. 392 // Fall through.
389 case IrOpcode::kIfTrue: 393 case IrOpcode::kIfTrue:
390 DCHECK_EQ(IrOpcode::kBranch, node->opcode()); 394 DCHECK_EQ(IrOpcode::kBranch, node->opcode());
391 index = 0; 395 index = kIfTrueIndex;
392 break; 396 break;
393 case IrOpcode::kIfFalse: 397 case IrOpcode::kIfFalse:
394 DCHECK_EQ(IrOpcode::kBranch, node->opcode()); 398 DCHECK_EQ(IrOpcode::kBranch, node->opcode());
395 index = 1; 399 index = kIfFalseIndex;
396 break; 400 break;
397 case IrOpcode::kCase: 401 case IrOpcode::kIfValue:
398 DCHECK_EQ(IrOpcode::kSwitch, node->opcode()); 402 DCHECK_EQ(IrOpcode::kSwitch, node->opcode());
399 index = CaseIndexOf(use->op()); 403 DCHECK_LT(if_value_index, kDefaultIndex);
404 index = if_value_index++;
405 break;
406 case IrOpcode::kIfDefault:
407 DCHECK_EQ(IrOpcode::kSwitch, node->opcode());
408 index = kDefaultIndex;
400 break; 409 break;
401 } 410 }
402 DCHECK_LT(index, successor_count); 411 DCHECK_LT(index, successor_count);
403 DCHECK(successors[index] == nullptr); 412 DCHECK_NULL(successors[index]);
404 successors[index] = use; 413 successors[index] = use;
405 } 414 }
406 #ifdef DEBUG 415 #ifdef DEBUG
407 for (size_t index = 0; index < successor_count; ++index) { 416 for (size_t index = 0; index < successor_count; ++index) {
408 DCHECK_NOT_NULL(successors[index]); 417 DCHECK_NOT_NULL(successors[index]);
409 } 418 }
410 #endif 419 #endif
411 } 420 }
412 421
413 void CollectSuccessorBlocks(Node* node, BasicBlock** successor_blocks, 422 void CollectSuccessorBlocks(Node* node, BasicBlock** successor_blocks,
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 for (Node* const node : *nodes) { 1657 for (Node* const node : *nodes) {
1649 schedule_->SetBlockForNode(to, node); 1658 schedule_->SetBlockForNode(to, node);
1650 scheduled_nodes_[to->id().ToSize()].push_back(node); 1659 scheduled_nodes_[to->id().ToSize()].push_back(node);
1651 } 1660 }
1652 nodes->clear(); 1661 nodes->clear();
1653 } 1662 }
1654 1663
1655 } // namespace compiler 1664 } // namespace compiler
1656 } // namespace internal 1665 } // namespace internal
1657 } // namespace v8 1666 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698