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

Side by Side Diff: runtime/vm/flow_graph_optimizer.cc

Issue 10802025: Fuse compare with branch at graph building time. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/flow_graph_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/flow_graph_builder.h" 7 #include "vm/flow_graph_builder.h"
8 #include "vm/il_printer.h" 8 #include "vm/il_printer.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 10
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 484
485 const intptr_t class_id = ReceiverClassId(comp); 485 const intptr_t class_id = ReceiverClassId(comp);
486 switch (class_id) { 486 switch (class_id) {
487 case kArray: 487 case kArray:
488 case kGrowableObjectArray: 488 case kGrowableObjectArray:
489 comp->set_receiver_type(static_cast<ObjectKind>(class_id)); 489 comp->set_receiver_type(static_cast<ObjectKind>(class_id));
490 } 490 }
491 } 491 }
492 492
493 493
494 static void TryFuseComparisonWithBranch(BindInstr* instr,
495 ComparisonComp* comp) {
496 Instruction* next_instr = instr->next();
497 if ((next_instr != NULL) && next_instr->IsBranch()) {
498 BranchInstr* branch = next_instr->AsBranch();
499 UseVal* use = branch->value()->AsUse();
500 if (instr == use->definition()) {
501 comp->MarkFusedWithBranch(branch);
502 branch->MarkFusedWithComparison(comp);
503
504 // Remove comparison from the graph.
505 branch->set_previous(instr->previous());
506 instr->previous()->set_next(branch);
507 return;
508 }
509 }
510 if ((next_instr != NULL) && next_instr->IsBind()) {
511 Computation* next_comp = next_instr->AsBind()->computation();
512 if (next_comp->IsBooleanNegate()) {
513 Instruction* next_next_instr = next_instr->next();
514 if ((next_next_instr != NULL) && next_next_instr->IsBranch()) {
515 BooleanNegateComp* negate = next_comp->AsBooleanNegate();
516 BranchInstr* branch = next_next_instr->AsBranch();
517 if ((branch->value()->AsUse()->definition() == next_instr) &&
518 (negate->value()->AsUse()->definition() == instr)) {
519 comp->MarkFusedWithBranch(branch);
520 branch->MarkFusedWithComparison(comp);
521 branch->set_is_negated(true);
522
523 // Remove comparison and boolean negation from the graph.
524 branch->set_previous(instr->previous());
525 instr->previous()->set_next(branch);
526 return;
527 }
528 }
529 }
530 }
531 }
532
533
534 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpComp* comp, 494 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpComp* comp,
535 BindInstr* instr) { 495 BindInstr* instr) {
536 if (!comp->HasICData()) return; 496 if (!comp->HasICData()) return;
537 497
538 const ICData& ic_data = *comp->ic_data(); 498 const ICData& ic_data = *comp->ic_data();
539 if (ic_data.NumberOfChecks() == 0) return; 499 if (ic_data.NumberOfChecks() == 0) return;
540 // TODO(srdjan): Add multiple receiver type support. 500 // TODO(srdjan): Add multiple receiver type support.
541 if (ic_data.NumberOfChecks() != 1) return; 501 if (ic_data.NumberOfChecks() != 1) return;
542 ASSERT(HasOneTarget(ic_data)); 502 ASSERT(HasOneTarget(ic_data));
543 503
544 if (HasOnlyTwoSmi(ic_data)) { 504 if (HasOnlyTwoSmi(ic_data)) {
545 comp->set_operands_class_id(kSmi); 505 comp->set_operands_class_id(kSmi);
546 } else if (HasOnlyTwoDouble(ic_data)) { 506 } else if (HasOnlyTwoDouble(ic_data)) {
547 comp->set_operands_class_id(kDouble); 507 comp->set_operands_class_id(kDouble);
548 } else { 508 } else {
549 return; 509 return;
550 } 510 }
551
552 // For smi and double comparisons if the next instruction is a conditional
553 // branch that uses the value of this comparison mark them as fused together
554 // to avoid materializing a boolean value.
555 TryFuseComparisonWithBranch(instr, comp);
556 }
557
558
559 void FlowGraphOptimizer::VisitStrictCompare(StrictCompareComp* comp,
560 BindInstr* instr) {
561 TryFuseComparisonWithBranch(instr, comp);
562 } 511 }
563 512
564 513
565 void FlowGraphOptimizer::VisitEqualityCompare(EqualityCompareComp* comp, 514 void FlowGraphOptimizer::VisitEqualityCompare(EqualityCompareComp* comp,
566 BindInstr* instr) { 515 BindInstr* instr) {
567 if (comp->HasICData() && (comp->ic_data()->NumberOfChecks() == 1)) { 516 if (comp->HasICData() && (comp->ic_data()->NumberOfChecks() == 1)) {
568 ASSERT(comp->ic_data()->num_args_tested() == 2); 517 ASSERT(comp->ic_data()->num_args_tested() == 2);
569 GrowableArray<intptr_t> class_ids; 518 GrowableArray<intptr_t> class_ids;
570 Function& target = Function::Handle(); 519 Function& target = Function::Handle();
571 comp->ic_data()->GetCheckAt(0, &class_ids, &target); 520 comp->ic_data()->GetCheckAt(0, &class_ids, &target);
572 // TODO(srdjan): allow for mixed mode comparison. 521 // TODO(srdjan): allow for mixed mode comparison.
573 if ((class_ids[0] == kSmi) && (class_ids[1] == kSmi)) { 522 if ((class_ids[0] == kSmi) && (class_ids[1] == kSmi)) {
574 comp->set_receiver_class_id(kSmi); 523 comp->set_receiver_class_id(kSmi);
575 } else if ((class_ids[0] == kDouble) && (class_ids[1] == kDouble)) { 524 } else if ((class_ids[0] == kDouble) && (class_ids[1] == kDouble)) {
576 comp->set_receiver_class_id(kDouble); 525 comp->set_receiver_class_id(kDouble);
577 } 526 }
578 } 527 }
579 TryFuseComparisonWithBranch(instr, comp);
580 } 528 }
581 529
582 530
583 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { 531 void FlowGraphOptimizer::VisitBind(BindInstr* instr) {
584 instr->computation()->Accept(this, instr); 532 instr->computation()->Accept(this, instr);
585 } 533 }
586 534
587 535
588 536
589 void FlowGraphAnalyzer::Analyze() { 537 void FlowGraphAnalyzer::Analyze() {
590 is_leaf_ = true; 538 is_leaf_ = true;
591 for (intptr_t i = 0; i < blocks_.length(); ++i) { 539 for (intptr_t i = 0; i < blocks_.length(); ++i) {
592 BlockEntryInstr* entry = blocks_[i]; 540 BlockEntryInstr* entry = blocks_[i];
593 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { 541 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) {
594 LocationSummary* locs = it.Current()->locs(); 542 LocationSummary* locs = it.Current()->locs();
595 if ((locs != NULL) && locs->is_call()) { 543 if ((locs != NULL) && locs->is_call()) {
596 is_leaf_ = false; 544 is_leaf_ = false;
597 return; 545 return;
598 } 546 }
599 } 547 }
600 } 548 }
601 } 549 }
602 550
603 } // namespace dart 551 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698