| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 current_iterator_ = NULL; | 94 current_iterator_ = NULL; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 // Attempt to build ICData for call using propagated class-ids. | 99 // Attempt to build ICData for call using propagated class-ids. |
| 100 bool FlowGraphOptimizer::TryCreateICData(InstanceCallInstr* call) { | 100 bool FlowGraphOptimizer::TryCreateICData(InstanceCallInstr* call) { |
| 101 ASSERT(call->HasICData()); | 101 ASSERT(call->HasICData()); |
| 102 if (call->ic_data()->NumberOfChecks() > 0) { | 102 if (call->ic_data()->NumberOfChecks() > 0) { |
| 103 // This occurs when an instance call has too many checks. | 103 // This occurs when an instance call has too many checks. |
| 104 // TODO(srdjan): Replace IC call with megamorphic call. | |
| 105 return false; | 104 return false; |
| 106 } | 105 } |
| 107 GrowableArray<intptr_t> class_ids(call->ic_data()->num_args_tested()); | 106 GrowableArray<intptr_t> class_ids(call->ic_data()->num_args_tested()); |
| 108 ASSERT(call->ic_data()->num_args_tested() <= call->ArgumentCount()); | 107 ASSERT(call->ic_data()->num_args_tested() <= call->ArgumentCount()); |
| 109 for (intptr_t i = 0; i < call->ic_data()->num_args_tested(); i++) { | 108 for (intptr_t i = 0; i < call->ic_data()->num_args_tested(); i++) { |
| 110 intptr_t cid = call->PushArgumentAt(i)->value()->Type()->ToCid(); | 109 intptr_t cid = call->PushArgumentAt(i)->value()->Type()->ToCid(); |
| 111 class_ids.Add(cid); | 110 class_ids.Add(cid); |
| 112 } | 111 } |
| 113 if (class_ids[0] != kDynamicCid) { | 112 |
| 114 ArgumentsDescriptor args_desc( | 113 for (intptr_t i = 0; i < class_ids.length(); i++) { |
| 115 Array::Handle(ArgumentsDescriptor::New(call->ArgumentCount(), | 114 if (class_ids[i] == kDynamicCid) { |
| 116 call->argument_names()))); | 115 // Not all cid-s known. |
| 117 const Class& receiver_class = Class::Handle( | |
| 118 Isolate::Current()->class_table()->At(class_ids[0])); | |
| 119 const Function& function = Function::Handle( | |
| 120 Resolver::ResolveDynamicForReceiverClass( | |
| 121 receiver_class, | |
| 122 call->function_name(), | |
| 123 args_desc)); | |
| 124 if (function.IsNull()) { | |
| 125 return false; | 116 return false; |
| 126 } | 117 } |
| 127 // Create new ICData, do not modify the one attached to the instruction | |
| 128 // since it is attached to the assembly instruction itself. | |
| 129 // TODO(srdjan): Prevent modification of ICData object that is | |
| 130 // referenced in assembly code. | |
| 131 ICData& ic_data = ICData::ZoneHandle(ICData::New( | |
| 132 flow_graph_->parsed_function().function(), | |
| 133 call->function_name(), | |
| 134 Object::empty_array(), // Dummy argument descriptor. | |
| 135 call->deopt_id(), | |
| 136 class_ids.length())); | |
| 137 if (class_ids.length() > 1) { | |
| 138 ic_data.AddCheck(class_ids, function); | |
| 139 } else { | |
| 140 ASSERT(class_ids.length() == 1); | |
| 141 ic_data.AddReceiverCheck(class_ids[0], function); | |
| 142 } | |
| 143 call->set_ic_data(&ic_data); | |
| 144 return true; | |
| 145 } | 118 } |
| 146 return false; | 119 |
| 120 ArgumentsDescriptor args_desc( |
| 121 Array::Handle(ArgumentsDescriptor::New(call->ArgumentCount(), |
| 122 call->argument_names()))); |
| 123 const Class& receiver_class = Class::Handle( |
| 124 Isolate::Current()->class_table()->At(class_ids[0])); |
| 125 const Function& function = Function::Handle( |
| 126 Resolver::ResolveDynamicForReceiverClass( |
| 127 receiver_class, |
| 128 call->function_name(), |
| 129 args_desc)); |
| 130 if (function.IsNull()) { |
| 131 return false; |
| 132 } |
| 133 // Create new ICData, do not modify the one attached to the instruction |
| 134 // since it is attached to the assembly instruction itself. |
| 135 // TODO(srdjan): Prevent modification of ICData object that is |
| 136 // referenced in assembly code. |
| 137 ICData& ic_data = ICData::ZoneHandle(ICData::New( |
| 138 flow_graph_->parsed_function().function(), |
| 139 call->function_name(), |
| 140 Object::empty_array(), // Dummy argument descriptor. |
| 141 call->deopt_id(), |
| 142 class_ids.length())); |
| 143 if (class_ids.length() > 1) { |
| 144 ic_data.AddCheck(class_ids, function); |
| 145 } else { |
| 146 ASSERT(class_ids.length() == 1); |
| 147 ic_data.AddReceiverCheck(class_ids[0], function); |
| 148 } |
| 149 call->set_ic_data(&ic_data); |
| 150 return true; |
| 147 } | 151 } |
| 148 | 152 |
| 149 | 153 |
| 150 static const ICData& SpecializeICData(const ICData& ic_data, intptr_t cid) { | 154 static const ICData& SpecializeICData(const ICData& ic_data, intptr_t cid) { |
| 151 ASSERT(ic_data.num_args_tested() == 1); | 155 ASSERT(ic_data.num_args_tested() == 1); |
| 152 | 156 |
| 153 if ((ic_data.NumberOfChecks() == 1) && | 157 if ((ic_data.NumberOfChecks() == 1) && |
| 154 (ic_data.GetReceiverClassIdAt(0) == cid)) { | 158 (ic_data.GetReceiverClassIdAt(0) == cid)) { |
| 155 return ic_data; // Nothing to do | 159 return ic_data; // Nothing to do |
| 156 } | 160 } |
| (...skipping 6742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6899 SetValue(instr, non_constant_); | 6903 SetValue(instr, non_constant_); |
| 6900 } | 6904 } |
| 6901 | 6905 |
| 6902 | 6906 |
| 6903 void ConstantPropagator::VisitUnboxInteger(UnboxIntegerInstr* instr) { | 6907 void ConstantPropagator::VisitUnboxInteger(UnboxIntegerInstr* instr) { |
| 6904 // TODO(kmillikin): Handle unbox operation. | 6908 // TODO(kmillikin): Handle unbox operation. |
| 6905 SetValue(instr, non_constant_); | 6909 SetValue(instr, non_constant_); |
| 6906 } | 6910 } |
| 6907 | 6911 |
| 6908 | 6912 |
| 6909 void ConstantPropagator::VisitBinaryMintOp( | 6913 void ConstantPropagator::VisitBinaryMintOp(BinaryMintOpInstr* instr) { |
| 6910 BinaryMintOpInstr* instr) { | |
| 6911 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right()); | 6914 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right()); |
| 6912 } | 6915 } |
| 6913 | 6916 |
| 6914 | 6917 |
| 6915 void ConstantPropagator::VisitShiftMintOp( | 6918 void ConstantPropagator::VisitShiftMintOp(ShiftMintOpInstr* instr) { |
| 6916 ShiftMintOpInstr* instr) { | |
| 6917 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right()); | 6919 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right()); |
| 6918 } | 6920 } |
| 6919 | 6921 |
| 6920 | 6922 |
| 6921 void ConstantPropagator::VisitUnaryMintOp( | 6923 void ConstantPropagator::VisitUnaryMintOp(UnaryMintOpInstr* instr) { |
| 6922 UnaryMintOpInstr* instr) { | |
| 6923 // TODO(kmillikin): Handle unary operations. | 6924 // TODO(kmillikin): Handle unary operations. |
| 6924 SetValue(instr, non_constant_); | 6925 SetValue(instr, non_constant_); |
| 6925 } | 6926 } |
| 6926 | 6927 |
| 6927 | 6928 |
| 6928 void ConstantPropagator::VisitUnarySmiOp(UnarySmiOpInstr* instr) { | 6929 void ConstantPropagator::VisitUnarySmiOp(UnarySmiOpInstr* instr) { |
| 6929 const Object& value = instr->value()->definition()->constant_value(); | 6930 const Object& value = instr->value()->definition()->constant_value(); |
| 6930 if (IsNonConstant(value)) { | 6931 if (IsNonConstant(value)) { |
| 6931 SetValue(instr, non_constant_); | 6932 SetValue(instr, non_constant_); |
| 6932 } else if (IsConstant(value)) { | 6933 } else if (IsConstant(value)) { |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8046 } | 8047 } |
| 8047 | 8048 |
| 8048 // Insert materializations at environment uses. | 8049 // Insert materializations at environment uses. |
| 8049 for (intptr_t i = 0; i < exits.length(); i++) { | 8050 for (intptr_t i = 0; i < exits.length(); i++) { |
| 8050 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); | 8051 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); |
| 8051 } | 8052 } |
| 8052 } | 8053 } |
| 8053 | 8054 |
| 8054 | 8055 |
| 8055 } // namespace dart | 8056 } // namespace dart |
| OLD | NEW |