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

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

Issue 10829270: Continue work on type propagation in optimizing compiler (still WIP). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/il_printer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 542
543 543
544 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { 544 void FlowGraphOptimizer::VisitBind(BindInstr* instr) {
545 instr->computation()->Accept(this, instr); 545 instr->computation()->Accept(this, instr);
546 } 546 }
547 547
548 548
549 void FlowGraphTypePropagator::VisitAssertAssignable(AssertAssignableComp* comp, 549 void FlowGraphTypePropagator::VisitAssertAssignable(AssertAssignableComp* comp,
550 BindInstr* instr) { 550 BindInstr* instr) {
551 if (FLAG_eliminate_type_checks && 551 if (FLAG_eliminate_type_checks &&
552 (comp->value() != NULL) && 552 !comp->IsEliminated() &&
553 !comp->dst_type().IsMalformed() && 553 !comp->dst_type().IsMalformed() &&
554 comp->value()->StaticTypeIsMoreSpecificThan(comp->dst_type())) { 554 comp->value()->CompileTypeIsMoreSpecificThan(comp->dst_type())) {
555 // TODO(regis): Eliminate type check by removing comp node from graph. 555 comp->Eliminate();
556 if (FLAG_trace_type_check_elimination) { 556 if (FLAG_trace_type_check_elimination) {
557 FlowGraphPrinter::PrintTypeCheck(parsed_function(), 557 FlowGraphPrinter::PrintTypeCheck(parsed_function(),
558 comp->token_pos(), 558 comp->token_pos(),
559 comp->value(), 559 comp->value(),
560 comp->dst_type(), 560 comp->dst_type(),
561 comp->dst_name(), 561 comp->dst_name(),
562 /*eliminated*/ true); 562 comp->IsEliminated());
563 } 563 }
564 } 564 }
565 } 565 }
566 566
567 567
568 void FlowGraphTypePropagator::VisitBind(BindInstr* instr) { 568 void FlowGraphTypePropagator::VisitGraphEntry(GraphEntryInstr* graph_entry) {
569 instr->computation()->Accept(this, instr); 569 if (graph_entry->start_env() == NULL) {
570 return;
571 }
572 // Visit incoming parameters.
573 for (intptr_t i = 0; i < graph_entry->start_env()->values().length(); i++) {
574 Value* val = graph_entry->start_env()->values()[i];
575 if (val->IsUse()) {
576 ParameterInstr* param = val->AsUse()->definition()->AsParameter();
577 if (param != NULL) {
578 VisitParameter(param);
579 }
580 }
581 }
582 }
583
584
585 void FlowGraphTypePropagator::VisitJoinEntry(JoinEntryInstr* join_entry) {
586 if (join_entry->phis() != NULL) {
587 for (intptr_t i = 0; i < join_entry->phis()->length(); ++i) {
588 PhiInstr* phi = (*join_entry->phis())[i];
589 if (phi != NULL) {
590 VisitPhi(phi);
591 }
592 }
593 }
594 }
595
596
597 void FlowGraphTypePropagator::VisitBind(BindInstr* bind) {
598 // No need to propagate the input types of the bound computation, as long as
599 // PhiInstr's are handled as part of JoinEntryInstr.
600 // Visit computation and possibly eliminate type check.
601 bind->computation()->Accept(this, bind);
602 // Cache propagated computation type.
603 AbstractType& type = AbstractType::Handle(bind->computation()->CompileType());
604 bool changed = bind->SetPropagatedType(type);
605 if (changed) {
606 still_changing_ = true;
607 }
608 }
609
610
611 void FlowGraphTypePropagator::VisitPhi(PhiInstr* phi) {
612 // We could set the propagated type of the phi to the least upper bound of its
613 // input propagated types. However, keeping all propagated types allows us to
614 // optimize method dispatch.
615 // TODO(regis): Support a set of propagated types. For now, we compute the
616 // least specific of the input propagated types.
617 AbstractType& type = AbstractType::Handle(phi->LeastSpecificInputType());
618 bool changed = phi->SetPropagatedType(type);
619 if (changed) {
620 still_changing_ = true;
621 }
622 }
623
624
625 void FlowGraphTypePropagator::VisitParameter(ParameterInstr* param) {
626 // TODO(regis): Once we inline functions, the propagated type of the formal
627 // parameter will reflect the compile type of the passed-in argument.
628 // For now, we do not known anything about this type and therefore set it to
629 // the DynamicType.
630 bool changed = param->SetPropagatedType(Type::Handle(Type::DynamicType()));
631 if (changed) {
632 still_changing_ = true;
633 }
634 }
635
636
637 void FlowGraphTypePropagator::PropagateTypes() {
638 // TODO(regis): Is there a way to make this more efficient, e.g. by visiting
639 // only blocks depending on blocks that have changed and not the whole graph.
640 do {
641 still_changing_ = false;
642 VisitBlocks();
643 } while (still_changing_);
570 } 644 }
571 645
572 646
573 void FlowGraphAnalyzer::Analyze() { 647 void FlowGraphAnalyzer::Analyze() {
574 is_leaf_ = true; 648 is_leaf_ = true;
575 for (intptr_t i = 0; i < blocks_.length(); ++i) { 649 for (intptr_t i = 0; i < blocks_.length(); ++i) {
576 BlockEntryInstr* entry = blocks_[i]; 650 BlockEntryInstr* entry = blocks_[i];
577 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { 651 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) {
578 LocationSummary* locs = it.Current()->locs(); 652 LocationSummary* locs = it.Current()->locs();
579 if ((locs != NULL) && locs->is_call()) { 653 if ((locs != NULL) && locs->is_call()) {
580 is_leaf_ = false; 654 is_leaf_ = false;
581 return; 655 return;
582 } 656 }
583 } 657 }
584 } 658 }
585 } 659 }
586 660
587
588 void FlowGraphTypePropagator::PropagateTypes() {
589 VisitBlocks();
590 }
591
592 } // namespace dart 661 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/il_printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698