| 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/cha.h" | 7 #include "vm/cha.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/hash_map.h" | 9 #include "vm/hash_map.h" |
| 10 #include "vm/il_printer.h" | 10 #include "vm/il_printer.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 if (!HasOneTarget(ic_data)) { | 360 if (!HasOneTarget(ic_data)) { |
| 361 // TODO(srdjan): Implement for mutiple targets. | 361 // TODO(srdjan): Implement for mutiple targets. |
| 362 return false; | 362 return false; |
| 363 } | 363 } |
| 364 // Inline implicit instance getter. | 364 // Inline implicit instance getter. |
| 365 const String& field_name = | 365 const String& field_name = |
| 366 String::Handle(Field::NameFromGetter(comp->function_name())); | 366 String::Handle(Field::NameFromGetter(comp->function_name())); |
| 367 const Field& field = Field::Handle(GetField(class_ids[0], field_name)); | 367 const Field& field = Field::Handle(GetField(class_ids[0], field_name)); |
| 368 ASSERT(!field.IsNull()); | 368 ASSERT(!field.IsNull()); |
| 369 | 369 |
| 370 LoadInstanceFieldComp* load; | 370 // Type propagation has not run yet, we cannot eliminate the check. |
| 371 // TODO(fschneider): Avoid generating redundant checks by checking the | |
| 372 // result-cid of the value. | |
| 373 CheckClassComp* check = | 371 CheckClassComp* check = |
| 374 new CheckClassComp(comp->ArgumentAt(0)->value(), comp); | 372 new CheckClassComp(comp->ArgumentAt(0)->value(), comp); |
| 375 const ICData& unary_checks = | 373 const ICData& unary_checks = |
| 376 ICData::ZoneHandle(comp->ic_data()->AsUnaryClassChecks()); | 374 ICData::ZoneHandle(comp->ic_data()->AsUnaryClassChecks()); |
| 377 check->set_ic_data(&unary_checks); | 375 check->set_ic_data(&unary_checks); |
| 378 BindInstr* check_instr = new BindInstr(BindInstr::kUnused, check); | 376 BindInstr* check_instr = new BindInstr(BindInstr::kUnused, check); |
| 379 ASSERT(instr->env() != NULL); // Always the case with SSA. | 377 ASSERT(instr->env() != NULL); // Always the case with SSA. |
| 380 // Attach the original environment to the check instruction. | 378 // Attach the original environment to the check instruction. |
| 381 check_instr->set_env(instr->env()); | 379 check_instr->set_env(instr->env()); |
| 382 instr->set_env(NULL); | 380 instr->set_env(NULL); |
| 383 check_instr->InsertBefore(instr); | 381 check_instr->InsertBefore(instr); |
| 384 load = new LoadInstanceFieldComp(field, | 382 LoadInstanceFieldComp* load = |
| 385 comp->ArgumentAt(0)->value(), | 383 new LoadInstanceFieldComp(field, |
| 386 NULL, | 384 comp->ArgumentAt(0)->value(), |
| 387 false); // Can not deoptimize. | 385 NULL); // Can not deoptimize. |
| 388 instr->set_computation(load); | 386 instr->set_computation(load); |
| 389 RemovePushArguments(comp); | 387 RemovePushArguments(comp); |
| 390 return true; | 388 return true; |
| 391 } | 389 } |
| 392 | 390 |
| 393 // Not an implicit getter. | 391 // Not an implicit getter. |
| 394 MethodRecognizer::Kind recognized_kind = | 392 MethodRecognizer::Kind recognized_kind = |
| 395 MethodRecognizer::RecognizeKind(target); | 393 MethodRecognizer::RecognizeKind(target); |
| 396 | 394 |
| 397 // VM objects length getter. | 395 // VM objects length getter. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 if (target.kind() != RawFunction::kImplicitSetter) { | 550 if (target.kind() != RawFunction::kImplicitSetter) { |
| 553 // Not an implicit setter. | 551 // Not an implicit setter. |
| 554 // TODO(srdjan): Inline special setters. | 552 // TODO(srdjan): Inline special setters. |
| 555 return false; | 553 return false; |
| 556 } | 554 } |
| 557 // Inline implicit instance setter. | 555 // Inline implicit instance setter. |
| 558 const String& field_name = | 556 const String& field_name = |
| 559 String::Handle(Field::NameFromSetter(comp->function_name())); | 557 String::Handle(Field::NameFromSetter(comp->function_name())); |
| 560 const Field& field = Field::Handle(GetField(class_id, field_name)); | 558 const Field& field = Field::Handle(GetField(class_id, field_name)); |
| 561 ASSERT(!field.IsNull()); | 559 ASSERT(!field.IsNull()); |
| 560 |
| 561 // Type propagation has not run yet, we cannot eliminate the check. |
| 562 CheckClassComp* check = |
| 563 new CheckClassComp(comp->ArgumentAt(0)->value(), comp); |
| 564 const ICData& unary_checks = |
| 565 ICData::ZoneHandle(comp->ic_data()->AsUnaryClassChecks()); |
| 566 check->set_ic_data(&unary_checks); |
| 567 BindInstr* check_instr = new BindInstr(BindInstr::kUnused, check); |
| 568 ASSERT(instr->env() != NULL); // Always the case with SSA. |
| 569 // Attach the original environment to the check instruction. |
| 570 check_instr->set_env(instr->env()); |
| 571 instr->set_env(NULL); |
| 572 check_instr->InsertBefore(instr); |
| 562 StoreInstanceFieldComp* store = new StoreInstanceFieldComp( | 573 StoreInstanceFieldComp* store = new StoreInstanceFieldComp( |
| 563 field, | 574 field, |
| 564 comp->ArgumentAt(0)->value(), | 575 comp->ArgumentAt(0)->value(), |
| 565 comp->ArgumentAt(1)->value(), | 576 comp->ArgumentAt(1)->value(), |
| 566 comp); | 577 NULL); // Can not deoptimize. |
| 567 store->set_ic_data(comp->ic_data()); | |
| 568 instr->set_computation(store); | 578 instr->set_computation(store); |
| 569 RemovePushArguments(comp); | 579 RemovePushArguments(comp); |
| 570 return true; | 580 return true; |
| 571 } | 581 } |
| 572 | 582 |
| 573 | 583 |
| 574 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpComp* comp, | 584 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpComp* comp, |
| 575 BindInstr* instr) { | 585 BindInstr* instr) { |
| 576 if (!comp->HasICData()) return; | 586 if (!comp->HasICData()) return; |
| 577 | 587 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 OS::Print("Replacing v%d with v%d\n", | 949 OS::Print("Replacing v%d with v%d\n", |
| 940 instr->ssa_temp_index(), | 950 instr->ssa_temp_index(), |
| 941 result->ssa_temp_index()); | 951 result->ssa_temp_index()); |
| 942 } | 952 } |
| 943 } | 953 } |
| 944 } | 954 } |
| 945 } | 955 } |
| 946 | 956 |
| 947 | 957 |
| 948 } // namespace dart | 958 } // namespace dart |
| OLD | NEW |