| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/flow_graph_builder.h" | 10 #include "vm/flow_graph_builder.h" |
| (...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 callee_receiver->IsParameter() && | 1563 callee_receiver->IsParameter() && |
| 1564 (callee_receiver->AsParameter()->index() == 0)) { | 1564 (callee_receiver->AsParameter()->index() == 0)) { |
| 1565 const String& field_name = | 1565 const String& field_name = |
| 1566 String::Handle(Field::NameFromGetter(call->function_name())); | 1566 String::Handle(Field::NameFromGetter(call->function_name())); |
| 1567 return CHA::HasOverride(Class::Handle(function.Owner()), field_name); | 1567 return CHA::HasOverride(Class::Handle(function.Owner()), field_name); |
| 1568 } | 1568 } |
| 1569 return true; | 1569 return true; |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 | 1572 |
| 1573 void FlowGraphOptimizer::AddToGuardedFields(const Field& field) { | |
| 1574 if ((field.guarded_cid() == kDynamicCid) || | |
| 1575 (field.guarded_cid() == kIllegalCid)) { | |
| 1576 return; | |
| 1577 } | |
| 1578 for (intptr_t j = 0; j < guarded_fields_->length(); j++) { | |
| 1579 if ((*guarded_fields_)[j]->raw() == field.raw()) { | |
| 1580 return; | |
| 1581 } | |
| 1582 } | |
| 1583 guarded_fields_->Add(&field); | |
| 1584 } | |
| 1585 | |
| 1586 | |
| 1587 void FlowGraphOptimizer::InlineImplicitInstanceGetter(InstanceCallInstr* call) { | 1573 void FlowGraphOptimizer::InlineImplicitInstanceGetter(InstanceCallInstr* call) { |
| 1588 ASSERT(call->HasICData()); | 1574 ASSERT(call->HasICData()); |
| 1589 const ICData& ic_data = *call->ic_data(); | 1575 const ICData& ic_data = *call->ic_data(); |
| 1590 Function& target = Function::Handle(); | 1576 Function& target = Function::Handle(); |
| 1591 GrowableArray<intptr_t> class_ids; | 1577 GrowableArray<intptr_t> class_ids; |
| 1592 ic_data.GetCheckAt(0, &class_ids, &target); | 1578 ic_data.GetCheckAt(0, &class_ids, &target); |
| 1593 ASSERT(class_ids.length() == 1); | 1579 ASSERT(class_ids.length() == 1); |
| 1594 // Inline implicit instance getter. | 1580 // Inline implicit instance getter. |
| 1595 const String& field_name = | 1581 const String& field_name = |
| 1596 String::Handle(Field::NameFromGetter(call->function_name())); | 1582 String::Handle(Field::NameFromGetter(call->function_name())); |
| 1597 const Field& field = Field::ZoneHandle(GetField(class_ids[0], field_name)); | 1583 const Field& field = Field::ZoneHandle(GetField(class_ids[0], field_name)); |
| 1598 ASSERT(!field.IsNull()); | 1584 ASSERT(!field.IsNull()); |
| 1599 | 1585 |
| 1600 if (InstanceCallNeedsClassCheck(call)) { | 1586 if (InstanceCallNeedsClassCheck(call)) { |
| 1601 AddReceiverCheck(call); | 1587 AddReceiverCheck(call); |
| 1602 } | 1588 } |
| 1603 LoadFieldInstr* load = new LoadFieldInstr( | 1589 LoadFieldInstr* load = new LoadFieldInstr( |
| 1604 new Value(call->ArgumentAt(0)), | 1590 new Value(call->ArgumentAt(0)), |
| 1605 field.Offset(), | 1591 field.Offset(), |
| 1606 AbstractType::ZoneHandle(field.type()), | 1592 AbstractType::ZoneHandle(field.type()), |
| 1607 field.is_final()); | 1593 field.is_final()); |
| 1608 load->set_field(&field); | 1594 load->set_field(&field); |
| 1609 if (field.guarded_cid() != kIllegalCid) { | 1595 if (field.guarded_cid() != kIllegalCid) { |
| 1610 if (!field.is_nullable() || (field.guarded_cid() == kNullCid)) { | 1596 if (!field.is_nullable() || (field.guarded_cid() == kNullCid)) { |
| 1611 load->set_result_cid(field.guarded_cid()); | 1597 load->set_result_cid(field.guarded_cid()); |
| 1612 } | 1598 } |
| 1613 AddToGuardedFields(field); | 1599 flow_graph_->builder().AddToGuardedFields(field); |
| 1614 } | 1600 } |
| 1615 | 1601 |
| 1616 // Discard the environment from the original instruction because the load | 1602 // Discard the environment from the original instruction because the load |
| 1617 // can't deoptimize. | 1603 // can't deoptimize. |
| 1618 call->RemoveEnvironment(); | 1604 call->RemoveEnvironment(); |
| 1619 ReplaceCall(call, load); | 1605 ReplaceCall(call, load); |
| 1620 | 1606 |
| 1621 if (load->result_cid() != kDynamicCid) { | 1607 if (load->result_cid() != kDynamicCid) { |
| 1622 // Reset value types if guarded_cid was used. | 1608 // Reset value types if guarded_cid was used. |
| 1623 for (Value::Iterator it(load->input_use_list()); | 1609 for (Value::Iterator it(load->input_use_list()); |
| (...skipping 6047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7671 } | 7657 } |
| 7672 | 7658 |
| 7673 // Insert materializations at environment uses. | 7659 // Insert materializations at environment uses. |
| 7674 for (intptr_t i = 0; i < exits.length(); i++) { | 7660 for (intptr_t i = 0; i < exits.length(); i++) { |
| 7675 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); | 7661 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); |
| 7676 } | 7662 } |
| 7677 } | 7663 } |
| 7678 | 7664 |
| 7679 | 7665 |
| 7680 } // namespace dart | 7666 } // namespace dart |
| OLD | NEW |