| OLD | NEW |
| 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 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 DECLARE_FLAG(bool, eliminate_type_checks); |
| 13 DECLARE_FLAG(bool, enable_type_checks); | 14 DECLARE_FLAG(bool, enable_type_checks); |
| 14 DECLARE_FLAG(bool, trace_optimization); | 15 DECLARE_FLAG(bool, trace_optimization); |
| 16 DECLARE_FLAG(bool, trace_type_check_elimination); |
| 15 | 17 |
| 16 void FlowGraphOptimizer::ApplyICData() { | 18 void FlowGraphOptimizer::ApplyICData() { |
| 17 VisitBlocks(); | 19 VisitBlocks(); |
| 18 } | 20 } |
| 19 | 21 |
| 20 | 22 |
| 21 static bool ICDataHasReceiverClassId(const ICData& ic_data, intptr_t class_id) { | 23 static bool ICDataHasReceiverClassId(const ICData& ic_data, intptr_t class_id) { |
| 22 ASSERT(ic_data.num_args_tested() > 0); | 24 ASSERT(ic_data.num_args_tested() > 0); |
| 23 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { | 25 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { |
| 24 const intptr_t test_class_id = ic_data.GetReceiverClassIdAt(i); | 26 const intptr_t test_class_id = ic_data.GetReceiverClassIdAt(i); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 return false; | 358 return false; |
| 357 } | 359 } |
| 358 ToDoubleComp* coerce = new ToDoubleComp( | 360 ToDoubleComp* coerce = new ToDoubleComp( |
| 359 comp->ArgumentAt(0)->value(), from_kind, comp); | 361 comp->ArgumentAt(0)->value(), from_kind, comp); |
| 360 instr->set_computation(coerce); | 362 instr->set_computation(coerce); |
| 361 RemovePushArguments(comp); | 363 RemovePushArguments(comp); |
| 362 return true; | 364 return true; |
| 363 } | 365 } |
| 364 | 366 |
| 365 | 367 |
| 366 | |
| 367 | |
| 368 void FlowGraphOptimizer::VisitInstanceCall(InstanceCallComp* comp, | 368 void FlowGraphOptimizer::VisitInstanceCall(InstanceCallComp* comp, |
| 369 BindInstr* instr) { | 369 BindInstr* instr) { |
| 370 if (comp->HasICData() && (comp->ic_data()->NumberOfChecks() > 0)) { | 370 if (comp->HasICData() && (comp->ic_data()->NumberOfChecks() > 0)) { |
| 371 const Token::Kind op_kind = comp->token_kind(); | 371 const Token::Kind op_kind = comp->token_kind(); |
| 372 if (Token::IsBinaryToken(op_kind) && | 372 if (Token::IsBinaryToken(op_kind) && |
| 373 TryReplaceWithBinaryOp(instr, comp, op_kind)) { | 373 TryReplaceWithBinaryOp(instr, comp, op_kind)) { |
| 374 return; | 374 return; |
| 375 } | 375 } |
| 376 if (Token::IsUnaryToken(op_kind) && | 376 if (Token::IsUnaryToken(op_kind) && |
| 377 TryReplaceWithUnaryOp(instr, comp, op_kind)) { | 377 TryReplaceWithUnaryOp(instr, comp, op_kind)) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 field, | 434 field, |
| 435 comp->InputAt(0), | 435 comp->InputAt(0), |
| 436 comp->InputAt(1), | 436 comp->InputAt(1), |
| 437 comp); | 437 comp); |
| 438 store->set_ic_data(comp->ic_data()); | 438 store->set_ic_data(comp->ic_data()); |
| 439 instr->set_computation(store); | 439 instr->set_computation(store); |
| 440 return true; | 440 return true; |
| 441 } | 441 } |
| 442 | 442 |
| 443 | 443 |
| 444 | |
| 445 void FlowGraphOptimizer::VisitInstanceSetter(InstanceSetterComp* comp, | 444 void FlowGraphOptimizer::VisitInstanceSetter(InstanceSetterComp* comp, |
| 446 BindInstr* instr) { | 445 BindInstr* instr) { |
| 447 // TODO(srdjan): Add assignable check node if --enable_type_checks. | 446 // TODO(srdjan): Add assignable check node if --enable_type_checks. |
| 448 if (comp->HasICData() && !FLAG_enable_type_checks) { | 447 if (comp->HasICData() && !FLAG_enable_type_checks) { |
| 449 if (TryInlineInstanceSetter(instr, comp)) { | 448 if (TryInlineInstanceSetter(instr, comp)) { |
| 450 return; | 449 return; |
| 451 } | 450 } |
| 452 } | 451 } |
| 453 // TODO(srdjan): Polymorphic dispatch to setters or deoptimize. | 452 // TODO(srdjan): Polymorphic dispatch to setters or deoptimize. |
| 454 } | 453 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 } | 536 } |
| 538 } | 537 } |
| 539 } | 538 } |
| 540 | 539 |
| 541 | 540 |
| 542 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { | 541 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { |
| 543 instr->computation()->Accept(this, instr); | 542 instr->computation()->Accept(this, instr); |
| 544 } | 543 } |
| 545 | 544 |
| 546 | 545 |
| 546 void FlowGraphTypePropagator::VisitAssertAssignable(AssertAssignableComp* comp, |
| 547 BindInstr* instr) { |
| 548 if (FLAG_eliminate_type_checks && |
| 549 (comp->value() != NULL) && |
| 550 !comp->dst_type().IsMalformed() && |
| 551 comp->value()->StaticTypeIsMoreSpecificThan(comp->dst_type())) { |
| 552 // TODO(regis): Eliminate type check by removing comp node from graph. |
| 553 if (FLAG_trace_type_check_elimination) { |
| 554 FlowGraphPrinter::PrintTypeCheck(parsed_function(), |
| 555 comp->token_pos(), |
| 556 comp->value(), |
| 557 comp->dst_type(), |
| 558 comp->dst_name(), |
| 559 /*eliminated*/ true); |
| 560 } |
| 561 } |
| 562 } |
| 563 |
| 564 |
| 565 void FlowGraphTypePropagator::VisitBind(BindInstr* instr) { |
| 566 instr->computation()->Accept(this, instr); |
| 567 } |
| 568 |
| 547 | 569 |
| 548 void FlowGraphAnalyzer::Analyze() { | 570 void FlowGraphAnalyzer::Analyze() { |
| 549 is_leaf_ = true; | 571 is_leaf_ = true; |
| 550 for (intptr_t i = 0; i < blocks_.length(); ++i) { | 572 for (intptr_t i = 0; i < blocks_.length(); ++i) { |
| 551 BlockEntryInstr* entry = blocks_[i]; | 573 BlockEntryInstr* entry = blocks_[i]; |
| 552 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 574 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
| 553 LocationSummary* locs = it.Current()->locs(); | 575 LocationSummary* locs = it.Current()->locs(); |
| 554 if ((locs != NULL) && locs->is_call()) { | 576 if ((locs != NULL) && locs->is_call()) { |
| 555 is_leaf_ = false; | 577 is_leaf_ = false; |
| 556 return; | 578 return; |
| 557 } | 579 } |
| 558 } | 580 } |
| 559 } | 581 } |
| 560 } | 582 } |
| 561 | 583 |
| 584 |
| 585 void FlowGraphTypePropagator::PropagateTypes() { |
| 586 VisitBlocks(); |
| 587 } |
| 588 |
| 562 } // namespace dart | 589 } // namespace dart |
| OLD | NEW |