| 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/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| (...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 if ((ic_data.NumberOfChecks() == 0) || !ic_data.HasOneTarget()) { | 1074 if ((ic_data.NumberOfChecks() == 0) || !ic_data.HasOneTarget()) { |
| 1075 // No type feedback collected or multiple targets found. | 1075 // No type feedback collected or multiple targets found. |
| 1076 return false; | 1076 return false; |
| 1077 } | 1077 } |
| 1078 Function& target = Function::Handle(); | 1078 Function& target = Function::Handle(); |
| 1079 GrowableArray<intptr_t> class_ids; | 1079 GrowableArray<intptr_t> class_ids; |
| 1080 ic_data.GetCheckAt(0, &class_ids, &target); | 1080 ic_data.GetCheckAt(0, &class_ids, &target); |
| 1081 MethodRecognizer::Kind recognized_kind = | 1081 MethodRecognizer::Kind recognized_kind = |
| 1082 MethodRecognizer::RecognizeKind(target); | 1082 MethodRecognizer::RecognizeKind(target); |
| 1083 | 1083 |
| 1084 if ((recognized_kind == MethodRecognizer::kDoubleToDouble) && | |
| 1085 (class_ids[0] == kDoubleCid)) { | |
| 1086 DoubleToDoubleInstr* d2d_instr = | |
| 1087 new DoubleToDoubleInstr(call->ArgumentAt(0)->value(), call); | |
| 1088 call->ReplaceWith(d2d_instr, current_iterator()); | |
| 1089 RemovePushArguments(call); | |
| 1090 return true; | |
| 1091 } | |
| 1092 | |
| 1093 if ((recognized_kind == MethodRecognizer::kIntegerToDouble) && | 1084 if ((recognized_kind == MethodRecognizer::kIntegerToDouble) && |
| 1094 (class_ids[0] == kSmiCid)) { | 1085 (class_ids[0] == kSmiCid)) { |
| 1095 SmiToDoubleInstr* s2d_instr = new SmiToDoubleInstr(call); | 1086 SmiToDoubleInstr* s2d_instr = new SmiToDoubleInstr(call); |
| 1096 call->ReplaceWith(s2d_instr, current_iterator()); | 1087 call->ReplaceWith(s2d_instr, current_iterator()); |
| 1097 // Pushed arguments are not removed because SmiToDouble is implemented | 1088 // Pushed arguments are not removed because SmiToDouble is implemented |
| 1098 // as a call. | 1089 // as a call. |
| 1099 return true; | 1090 return true; |
| 1100 } | 1091 } |
| 1101 | 1092 |
| 1102 const intptr_t cid0 = class_ids[0]; | |
| 1103 if ((recognized_kind == MethodRecognizer::kIntegerToInteger) && | |
| 1104 ((cid0 == kSmiCid) || (cid0 == kMintCid) || (cid0 == kBigintCid))) { | |
| 1105 // TODO(srdjan): implement also for mixed integer cids. | |
| 1106 InsertBefore(call, | |
| 1107 new CheckSmiInstr(call->ArgumentAt(0)->value()->Copy(), | |
| 1108 call->deopt_id()), | |
| 1109 call->env(), | |
| 1110 Definition::kEffect); | |
| 1111 call->ReplaceUsesWith(call->ArgumentAt(0)); | |
| 1112 RemovePushArguments(call); | |
| 1113 call->RemoveFromGraph(); | |
| 1114 return true; | |
| 1115 } | |
| 1116 | |
| 1117 if ((recognized_kind == MethodRecognizer::kDoubleToInteger) && | 1093 if ((recognized_kind == MethodRecognizer::kDoubleToInteger) && |
| 1118 (class_ids[0] == kDoubleCid)) { | 1094 (class_ids[0] == kDoubleCid)) { |
| 1119 AddCheckClass(call, call->ArgumentAt(0)->value()->Copy()); | 1095 AddCheckClass(call, call->ArgumentAt(0)->value()->Copy()); |
| 1120 DoubleToIntegerInstr* d2int_instr = | 1096 DoubleToIntegerInstr* d2int_instr = |
| 1121 new DoubleToIntegerInstr(call->ArgumentAt(0)->value(), call); | 1097 new DoubleToIntegerInstr(call->ArgumentAt(0)->value(), call); |
| 1122 call->ReplaceWith(d2int_instr, current_iterator()); | 1098 call->ReplaceWith(d2int_instr, current_iterator()); |
| 1123 RemovePushArguments(call); | 1099 RemovePushArguments(call); |
| 1124 return true; | 1100 return true; |
| 1125 } | 1101 } |
| 1126 | 1102 |
| (...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3301 const Object& value = instr->value()->definition()->constant_value(); | 3277 const Object& value = instr->value()->definition()->constant_value(); |
| 3302 if (IsNonConstant(value)) { | 3278 if (IsNonConstant(value)) { |
| 3303 SetValue(instr, non_constant_); | 3279 SetValue(instr, non_constant_); |
| 3304 } else if (IsConstant(value)) { | 3280 } else if (IsConstant(value)) { |
| 3305 // TODO(kmillikin): Handle unary operations. | 3281 // TODO(kmillikin): Handle unary operations. |
| 3306 SetValue(instr, non_constant_); | 3282 SetValue(instr, non_constant_); |
| 3307 } | 3283 } |
| 3308 } | 3284 } |
| 3309 | 3285 |
| 3310 | 3286 |
| 3311 void ConstantPropagator::VisitDoubleToDouble(DoubleToDoubleInstr* instr) { | |
| 3312 const Object& value = instr->value()->definition()->constant_value(); | |
| 3313 if (IsNonConstant(value)) { | |
| 3314 SetValue(instr, non_constant_); | |
| 3315 } else if (IsConstant(value)) { | |
| 3316 // TODO(kmillikin): Handle conversion. | |
| 3317 SetValue(instr, non_constant_); | |
| 3318 } | |
| 3319 } | |
| 3320 | |
| 3321 | |
| 3322 void ConstantPropagator::VisitSmiToDouble(SmiToDoubleInstr* instr) { | 3287 void ConstantPropagator::VisitSmiToDouble(SmiToDoubleInstr* instr) { |
| 3323 // TODO(kmillikin): Handle conversion. | 3288 // TODO(kmillikin): Handle conversion. |
| 3324 SetValue(instr, non_constant_); | 3289 SetValue(instr, non_constant_); |
| 3325 } | 3290 } |
| 3326 | 3291 |
| 3327 | 3292 |
| 3328 void ConstantPropagator::VisitDoubleToInteger(DoubleToIntegerInstr* instr) { | 3293 void ConstantPropagator::VisitDoubleToInteger(DoubleToIntegerInstr* instr) { |
| 3329 // TODO(kmillikin): Handle conversion. | 3294 // TODO(kmillikin): Handle conversion. |
| 3330 SetValue(instr, non_constant_); | 3295 SetValue(instr, non_constant_); |
| 3331 } | 3296 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3539 | 3504 |
| 3540 if (FLAG_trace_constant_propagation) { | 3505 if (FLAG_trace_constant_propagation) { |
| 3541 OS::Print("\n==== After constant propagation ====\n"); | 3506 OS::Print("\n==== After constant propagation ====\n"); |
| 3542 FlowGraphPrinter printer(*graph_); | 3507 FlowGraphPrinter printer(*graph_); |
| 3543 printer.PrintBlocks(); | 3508 printer.PrintBlocks(); |
| 3544 } | 3509 } |
| 3545 } | 3510 } |
| 3546 | 3511 |
| 3547 | 3512 |
| 3548 } // namespace dart | 3513 } // namespace dart |
| OLD | NEW |