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