| 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 Definition* right_def = curr_instr->right()->definition(); | 347 Definition* right_def = curr_instr->right()->definition(); |
| 348 for (intptr_t k = i + 1; k < merge_candidates->length(); k++) { | 348 for (intptr_t k = i + 1; k < merge_candidates->length(); k++) { |
| 349 BinarySmiOpInstr* other_binop = (*merge_candidates)[k]; | 349 BinarySmiOpInstr* other_binop = (*merge_candidates)[k]; |
| 350 // 'other_binop' can be NULL if it was already merged. | 350 // 'other_binop' can be NULL if it was already merged. |
| 351 if ((other_binop != NULL) && | 351 if ((other_binop != NULL) && |
| 352 (other_binop->op_kind() == other_kind) && | 352 (other_binop->op_kind() == other_kind) && |
| 353 (other_binop->left()->definition() == left_def) && | 353 (other_binop->left()->definition() == left_def) && |
| 354 (other_binop->right()->definition() == right_def)) { | 354 (other_binop->right()->definition() == right_def)) { |
| 355 (*merge_candidates)[k] = NULL; // Clear it. | 355 (*merge_candidates)[k] = NULL; // Clear it. |
| 356 // Append a LoadIndexed behind TRUNC_DIV and MOD. | 356 // Append a LoadIndexed behind TRUNC_DIV and MOD. |
| 357 ASSERT(curr_instr->HasUses()); |
| 357 AppendLoadIndexedForMerged( | 358 AppendLoadIndexedForMerged( |
| 358 curr_instr, | 359 curr_instr, |
| 359 MergedMathInstr::ResultIndexOf(curr_instr->op_kind()), | 360 MergedMathInstr::ResultIndexOf(curr_instr->op_kind()), |
| 360 kArrayCid); | 361 kArrayCid); |
| 362 ASSERT(other_binop->HasUses()); |
| 361 AppendLoadIndexedForMerged( | 363 AppendLoadIndexedForMerged( |
| 362 other_binop, | 364 other_binop, |
| 363 MergedMathInstr::ResultIndexOf(other_binop->op_kind()), | 365 MergedMathInstr::ResultIndexOf(other_binop->op_kind()), |
| 364 kArrayCid); | 366 kArrayCid); |
| 365 | 367 |
| 366 ZoneGrowableArray<Value*>* args = new ZoneGrowableArray<Value*>(2); | 368 ZoneGrowableArray<Value*>* args = new ZoneGrowableArray<Value*>(2); |
| 367 args->Add(new Value(curr_instr->left()->definition())); | 369 args->Add(new Value(curr_instr->left()->definition())); |
| 368 args->Add(new Value(curr_instr->right()->definition())); | 370 args->Add(new Value(curr_instr->right()->definition())); |
| 369 | 371 |
| 370 // Replace with TruncDivMod. | 372 // Replace with TruncDivMod. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 (curr_instr->kind() == MethodRecognizer::kMathSin) ? | 409 (curr_instr->kind() == MethodRecognizer::kMathSin) ? |
| 408 MethodRecognizer::kMathCos : MethodRecognizer::kMathSin; | 410 MethodRecognizer::kMathCos : MethodRecognizer::kMathSin; |
| 409 Definition* def = curr_instr->value()->definition(); | 411 Definition* def = curr_instr->value()->definition(); |
| 410 for (intptr_t k = i + 1; k < merge_candidates->length(); k++) { | 412 for (intptr_t k = i + 1; k < merge_candidates->length(); k++) { |
| 411 MathUnaryInstr* other_op = (*merge_candidates)[k]; | 413 MathUnaryInstr* other_op = (*merge_candidates)[k]; |
| 412 // 'other_op' can be NULL if it was already merged. | 414 // 'other_op' can be NULL if it was already merged. |
| 413 if ((other_op != NULL) && (other_op->kind() == other_kind) && | 415 if ((other_op != NULL) && (other_op->kind() == other_kind) && |
| 414 (other_op->value()->definition() == def)) { | 416 (other_op->value()->definition() == def)) { |
| 415 (*merge_candidates)[k] = NULL; // Clear it. | 417 (*merge_candidates)[k] = NULL; // Clear it. |
| 416 // Append a LoadIndexed behind SIN and COS. | 418 // Append a LoadIndexed behind SIN and COS. |
| 419 ASSERT(curr_instr->HasUses()); |
| 417 AppendLoadIndexedForMerged( | 420 AppendLoadIndexedForMerged( |
| 418 curr_instr, | 421 curr_instr, |
| 419 MergedMathInstr::ResultIndexOf(curr_instr->kind()), | 422 MergedMathInstr::ResultIndexOf(curr_instr->kind()), |
| 420 kTypedDataFloat64ArrayCid); | 423 kTypedDataFloat64ArrayCid); |
| 424 ASSERT(other_op->HasUses()); |
| 421 AppendLoadIndexedForMerged( | 425 AppendLoadIndexedForMerged( |
| 422 other_op, | 426 other_op, |
| 423 MergedMathInstr::ResultIndexOf(other_op->kind()), | 427 MergedMathInstr::ResultIndexOf(other_op->kind()), |
| 424 kTypedDataFloat64ArrayCid); | 428 kTypedDataFloat64ArrayCid); |
| 425 ZoneGrowableArray<Value*>* args = new ZoneGrowableArray<Value*>(1); | 429 ZoneGrowableArray<Value*>* args = new ZoneGrowableArray<Value*>(1); |
| 426 args->Add(new Value(curr_instr->value()->definition())); | 430 args->Add(new Value(curr_instr->value()->definition())); |
| 427 | 431 |
| 428 // Replace with SinCos. | 432 // Replace with SinCos. |
| 429 MergedMathInstr* sin_cos = new MergedMathInstr( | 433 MergedMathInstr* sin_cos = new MergedMathInstr( |
| 430 args, | 434 args, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 460 current_iterator_ = ⁢ | 464 current_iterator_ = ⁢ |
| 461 for (; !it.Done(); it.Advance()) { | 465 for (; !it.Done(); it.Advance()) { |
| 462 if (it.Current()->IsBinarySmiOp()) { | 466 if (it.Current()->IsBinarySmiOp()) { |
| 463 BinarySmiOpInstr* binop = it.Current()->AsBinarySmiOp(); | 467 BinarySmiOpInstr* binop = it.Current()->AsBinarySmiOp(); |
| 464 if (binop->op_kind() == Token::kBIT_AND) { | 468 if (binop->op_kind() == Token::kBIT_AND) { |
| 465 OptimizeLeftShiftBitAndSmiOp(binop, | 469 OptimizeLeftShiftBitAndSmiOp(binop, |
| 466 binop->left()->definition(), | 470 binop->left()->definition(), |
| 467 binop->right()->definition()); | 471 binop->right()->definition()); |
| 468 } else if ((binop->op_kind() == Token::kTRUNCDIV) || | 472 } else if ((binop->op_kind() == Token::kTRUNCDIV) || |
| 469 (binop->op_kind() == Token::kMOD)) { | 473 (binop->op_kind() == Token::kMOD)) { |
| 470 div_mod_merge.Add(binop); | 474 if (binop->HasUses()) { |
| 475 div_mod_merge.Add(binop); |
| 476 } |
| 471 } | 477 } |
| 472 } else if (it.Current()->IsBinaryMintOp()) { | 478 } else if (it.Current()->IsBinaryMintOp()) { |
| 473 BinaryMintOpInstr* mintop = it.Current()->AsBinaryMintOp(); | 479 BinaryMintOpInstr* mintop = it.Current()->AsBinaryMintOp(); |
| 474 if (mintop->op_kind() == Token::kBIT_AND) { | 480 if (mintop->op_kind() == Token::kBIT_AND) { |
| 475 OptimizeLeftShiftBitAndSmiOp(mintop, | 481 OptimizeLeftShiftBitAndSmiOp(mintop, |
| 476 mintop->left()->definition(), | 482 mintop->left()->definition(), |
| 477 mintop->right()->definition()); | 483 mintop->right()->definition()); |
| 478 } | 484 } |
| 479 } else if (it.Current()->IsMathUnary()) { | 485 } else if (it.Current()->IsMathUnary()) { |
| 480 MathUnaryInstr* math_unary = it.Current()->AsMathUnary(); | 486 MathUnaryInstr* math_unary = it.Current()->AsMathUnary(); |
| 481 if ((math_unary->kind() == MethodRecognizer::kMathSin) || | 487 if ((math_unary->kind() == MethodRecognizer::kMathSin) || |
| 482 (math_unary->kind() == MethodRecognizer::kMathCos)) { | 488 (math_unary->kind() == MethodRecognizer::kMathCos)) { |
| 483 sin_cos_merge.Add(math_unary); | 489 if (math_unary->HasUses()) { |
| 490 sin_cos_merge.Add(math_unary); |
| 491 } |
| 484 } | 492 } |
| 485 } | 493 } |
| 486 } | 494 } |
| 487 TryMergeTruncDivMod(&div_mod_merge); | 495 TryMergeTruncDivMod(&div_mod_merge); |
| 488 TryMergeMathUnary(&sin_cos_merge); | 496 TryMergeMathUnary(&sin_cos_merge); |
| 489 current_iterator_ = NULL; | 497 current_iterator_ = NULL; |
| 490 } | 498 } |
| 491 } | 499 } |
| 492 | 500 |
| 493 | 501 |
| (...skipping 7978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8472 } | 8480 } |
| 8473 | 8481 |
| 8474 // Insert materializations at environment uses. | 8482 // Insert materializations at environment uses. |
| 8475 for (intptr_t i = 0; i < exits.length(); i++) { | 8483 for (intptr_t i = 0; i < exits.length(); i++) { |
| 8476 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); | 8484 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); |
| 8477 } | 8485 } |
| 8478 } | 8486 } |
| 8479 | 8487 |
| 8480 | 8488 |
| 8481 } // namespace dart | 8489 } // namespace dart |
| OLD | NEW |