| 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/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 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 index->Copy(), | 1282 index->Copy(), |
| 1283 cid, | 1283 cid, |
| 1284 call), | 1284 call), |
| 1285 call->env(), | 1285 call->env(), |
| 1286 Definition::kEffect); | 1286 Definition::kEffect); |
| 1287 } | 1287 } |
| 1288 return new LoadIndexedInstr(str, index, cid); | 1288 return new LoadIndexedInstr(str, index, cid); |
| 1289 } | 1289 } |
| 1290 | 1290 |
| 1291 | 1291 |
| 1292 void FlowGraphOptimizer::ReplaceWithMathCFunction( | |
| 1293 InstanceCallInstr* call, | |
| 1294 MethodRecognizer::Kind recognized_kind) { | |
| 1295 AddCheckClass(call, call->ArgumentAt(0)->value()->Copy()); | |
| 1296 ZoneGrowableArray<Value*>* args = | |
| 1297 new ZoneGrowableArray<Value*>(call->ArgumentCount()); | |
| 1298 for (intptr_t i = 0; i < call->ArgumentCount(); i++) { | |
| 1299 args->Add(call->ArgumentAt(i)->value()); | |
| 1300 } | |
| 1301 InvokeMathCFunctionInstr* invoke = | |
| 1302 new InvokeMathCFunctionInstr(args, call, recognized_kind); | |
| 1303 call->ReplaceWith(invoke, current_iterator()); | |
| 1304 RemovePushArguments(call); | |
| 1305 } | |
| 1306 | |
| 1307 | |
| 1308 // Inline only simple, frequently called core library methods. | 1292 // Inline only simple, frequently called core library methods. |
| 1309 bool FlowGraphOptimizer::TryInlineInstanceMethod(InstanceCallInstr* call) { | 1293 bool FlowGraphOptimizer::TryInlineInstanceMethod(InstanceCallInstr* call) { |
| 1310 ASSERT(call->HasICData()); | 1294 ASSERT(call->HasICData()); |
| 1311 const ICData& ic_data = *call->ic_data(); | 1295 const ICData& ic_data = *call->ic_data(); |
| 1312 if ((ic_data.NumberOfChecks() == 0) || !ic_data.HasOneTarget()) { | 1296 if ((ic_data.NumberOfChecks() == 0) || !ic_data.HasOneTarget()) { |
| 1313 // No type feedback collected or multiple targets found. | 1297 // No type feedback collected or multiple targets found. |
| 1314 return false; | 1298 return false; |
| 1315 } | 1299 } |
| 1316 Function& target = Function::Handle(); | 1300 Function& target = Function::Handle(); |
| 1317 GrowableArray<intptr_t> class_ids; | 1301 GrowableArray<intptr_t> class_ids; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1345 if ((recognized_kind == MethodRecognizer::kIntegerToDouble) && | 1329 if ((recognized_kind == MethodRecognizer::kIntegerToDouble) && |
| 1346 (class_ids[0] == kSmiCid)) { | 1330 (class_ids[0] == kSmiCid)) { |
| 1347 SmiToDoubleInstr* s2d_instr = new SmiToDoubleInstr(call); | 1331 SmiToDoubleInstr* s2d_instr = new SmiToDoubleInstr(call); |
| 1348 call->ReplaceWith(s2d_instr, current_iterator()); | 1332 call->ReplaceWith(s2d_instr, current_iterator()); |
| 1349 // Pushed arguments are not removed because SmiToDouble is implemented | 1333 // Pushed arguments are not removed because SmiToDouble is implemented |
| 1350 // as a call. | 1334 // as a call. |
| 1351 return true; | 1335 return true; |
| 1352 } | 1336 } |
| 1353 | 1337 |
| 1354 if (class_ids[0] == kDoubleCid) { | 1338 if (class_ids[0] == kDoubleCid) { |
| 1355 switch (recognized_kind) { | 1339 if (recognized_kind == MethodRecognizer::kDoubleToInteger) { |
| 1356 case MethodRecognizer::kDoubleToInteger: { | 1340 AddCheckClass(call, call->ArgumentAt(0)->value()->Copy()); |
| 1357 AddCheckClass(call, call->ArgumentAt(0)->value()->Copy()); | 1341 ASSERT(call->HasICData()); |
| 1358 ASSERT(call->HasICData()); | 1342 const ICData& ic_data = *call->ic_data(); |
| 1359 const ICData& ic_data = *call->ic_data(); | 1343 Definition* d2i_instr = NULL; |
| 1360 Definition* d2i_instr = NULL; | 1344 if (ic_data.deopt_reason() == kDeoptDoubleToSmi) { |
| 1361 if (ic_data.deopt_reason() == kDeoptDoubleToSmi) { | 1345 // Do not repeatedly deoptimize because result didn't fit into Smi. |
| 1362 // Do not repeatedly deoptimize because result didn't fit into Smi. | 1346 d2i_instr = new DoubleToIntegerInstr(call->ArgumentAt(0)->value(), |
| 1363 d2i_instr = new DoubleToIntegerInstr(call->ArgumentAt(0)->value(), | 1347 call); |
| 1364 call); | 1348 } else { |
| 1365 } else { | 1349 // Optimistically assume result fits into Smi. |
| 1366 // Optimistically assume result fits into Smi. | 1350 d2i_instr = new DoubleToSmiInstr(call->ArgumentAt(0)->value(), call); |
| 1367 d2i_instr = new DoubleToSmiInstr(call->ArgumentAt(0)->value(), call); | |
| 1368 } | |
| 1369 call->ReplaceWith(d2i_instr, current_iterator()); | |
| 1370 RemovePushArguments(call); | |
| 1371 return true; | |
| 1372 } | 1351 } |
| 1373 case MethodRecognizer::kDoublePow: | 1352 call->ReplaceWith(d2i_instr, current_iterator()); |
| 1374 ReplaceWithMathCFunction(call, recognized_kind); | 1353 RemovePushArguments(call); |
| 1375 return true; | 1354 return true; |
| 1376 case MethodRecognizer::kDoubleTruncate: | 1355 } |
| 1377 case MethodRecognizer::kDoubleRound: | 1356 if ((recognized_kind == MethodRecognizer::kDoubleTruncate) || |
| 1378 case MethodRecognizer::kDoubleFloor: | 1357 (recognized_kind == MethodRecognizer::kDoubleRound) || |
| 1379 case MethodRecognizer::kDoubleCeil: | 1358 (recognized_kind == MethodRecognizer::kDoubleFloor) || |
| 1380 if (!CPUFeatures::double_truncate_round_supported()) { | 1359 (recognized_kind == MethodRecognizer::kDoubleCeil)) { |
| 1381 ReplaceWithMathCFunction(call, recognized_kind); | 1360 if (!CPUFeatures::double_truncate_round_supported()) { |
| 1382 } else { | |
| 1383 AddCheckClass(call, call->ArgumentAt(0)->value()->Copy()); | |
| 1384 DoubleToDoubleInstr* d2d_instr = | |
| 1385 new DoubleToDoubleInstr(call->ArgumentAt(0)->value(), | |
| 1386 call, | |
| 1387 recognized_kind); | |
| 1388 call->ReplaceWith(d2d_instr, current_iterator()); | |
| 1389 RemovePushArguments(call); | |
| 1390 } | |
| 1391 return true; | |
| 1392 default: | |
| 1393 // Unsupported method. | |
| 1394 return false; | 1361 return false; |
| 1362 } |
| 1363 AddCheckClass(call, call->ArgumentAt(0)->value()->Copy()); |
| 1364 DoubleToDoubleInstr* d2d_instr = |
| 1365 new DoubleToDoubleInstr(call->ArgumentAt(0)->value(), |
| 1366 call, |
| 1367 recognized_kind); |
| 1368 call->ReplaceWith(d2d_instr, current_iterator()); |
| 1369 RemovePushArguments(call); |
| 1370 return true; |
| 1395 } | 1371 } |
| 1396 } | 1372 } |
| 1397 | 1373 |
| 1398 return false; | 1374 return false; |
| 1399 } | 1375 } |
| 1400 | 1376 |
| 1401 | 1377 |
| 1402 // Returns a Boolean constant if all classes in ic_data yield the same type-test | 1378 // Returns a Boolean constant if all classes in ic_data yield the same type-test |
| 1403 // result and the type tests do not depend on type arguments. Otherwise return | 1379 // result and the type tests do not depend on type arguments. Otherwise return |
| 1404 // Bool::null(). | 1380 // Bool::null(). |
| (...skipping 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4367 SetValue(instr, non_constant_); | 4343 SetValue(instr, non_constant_); |
| 4368 } | 4344 } |
| 4369 | 4345 |
| 4370 | 4346 |
| 4371 void ConstantPropagator::VisitDoubleToDouble(DoubleToDoubleInstr* instr) { | 4347 void ConstantPropagator::VisitDoubleToDouble(DoubleToDoubleInstr* instr) { |
| 4372 // TODO(kmillikin): Handle conversion. | 4348 // TODO(kmillikin): Handle conversion. |
| 4373 SetValue(instr, non_constant_); | 4349 SetValue(instr, non_constant_); |
| 4374 } | 4350 } |
| 4375 | 4351 |
| 4376 | 4352 |
| 4377 void ConstantPropagator::VisitInvokeMathCFunction( | |
| 4378 InvokeMathCFunctionInstr* instr) { | |
| 4379 // TODO(kmillikin): Handle conversion. | |
| 4380 SetValue(instr, non_constant_); | |
| 4381 } | |
| 4382 | |
| 4383 void ConstantPropagator::VisitConstant(ConstantInstr* instr) { | 4353 void ConstantPropagator::VisitConstant(ConstantInstr* instr) { |
| 4384 SetValue(instr, instr->value()); | 4354 SetValue(instr, instr->value()); |
| 4385 } | 4355 } |
| 4386 | 4356 |
| 4387 | 4357 |
| 4388 void ConstantPropagator::VisitConstraint(ConstraintInstr* instr) { | 4358 void ConstantPropagator::VisitConstraint(ConstraintInstr* instr) { |
| 4389 // Should not be used outside of range analysis. | 4359 // Should not be used outside of range analysis. |
| 4390 UNREACHABLE(); | 4360 UNREACHABLE(); |
| 4391 } | 4361 } |
| 4392 | 4362 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4600 | 4570 |
| 4601 if (FLAG_trace_constant_propagation) { | 4571 if (FLAG_trace_constant_propagation) { |
| 4602 OS::Print("\n==== After constant propagation ====\n"); | 4572 OS::Print("\n==== After constant propagation ====\n"); |
| 4603 FlowGraphPrinter printer(*graph_); | 4573 FlowGraphPrinter printer(*graph_); |
| 4604 printer.PrintBlocks(); | 4574 printer.PrintBlocks(); |
| 4605 } | 4575 } |
| 4606 } | 4576 } |
| 4607 | 4577 |
| 4608 | 4578 |
| 4609 } // namespace dart | 4579 } // namespace dart |
| OLD | NEW |