| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 510 |
| 511 void HGlobalValueNumberingPhase::LoopInvariantCodeMotion() { | 511 void HGlobalValueNumberingPhase::LoopInvariantCodeMotion() { |
| 512 TRACE_GVN_1("Using optimistic loop invariant code motion: %s\n", | 512 TRACE_GVN_1("Using optimistic loop invariant code motion: %s\n", |
| 513 graph()->use_optimistic_licm() ? "yes" : "no"); | 513 graph()->use_optimistic_licm() ? "yes" : "no"); |
| 514 for (int i = graph()->blocks()->length() - 1; i >= 0; --i) { | 514 for (int i = graph()->blocks()->length() - 1; i >= 0; --i) { |
| 515 HBasicBlock* block = graph()->blocks()->at(i); | 515 HBasicBlock* block = graph()->blocks()->at(i); |
| 516 if (block->IsLoopHeader()) { | 516 if (block->IsLoopHeader()) { |
| 517 GVNFlagSet side_effects = loop_side_effects_[block->block_id()]; | 517 GVNFlagSet side_effects = loop_side_effects_[block->block_id()]; |
| 518 TRACE_GVN_2("Try loop invariant motion for block B%d %s\n", | 518 TRACE_GVN_2("Try loop invariant motion for block B%d %s\n", |
| 519 block->block_id(), | 519 block->block_id(), |
| 520 *GetGVNFlagsString(side_effects)); | 520 GetGVNFlagsString(side_effects).get()); |
| 521 | 521 |
| 522 GVNFlagSet accumulated_first_time_depends; | 522 GVNFlagSet accumulated_first_time_depends; |
| 523 GVNFlagSet accumulated_first_time_changes; | 523 GVNFlagSet accumulated_first_time_changes; |
| 524 HBasicBlock* last = block->loop_information()->GetLastBackEdge(); | 524 HBasicBlock* last = block->loop_information()->GetLastBackEdge(); |
| 525 for (int j = block->block_id(); j <= last->block_id(); ++j) { | 525 for (int j = block->block_id(); j <= last->block_id(); ++j) { |
| 526 ProcessLoopBlock(graph()->blocks()->at(j), block, side_effects, | 526 ProcessLoopBlock(graph()->blocks()->at(j), block, side_effects, |
| 527 &accumulated_first_time_depends, | 527 &accumulated_first_time_depends, |
| 528 &accumulated_first_time_changes); | 528 &accumulated_first_time_changes); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 | 533 |
| 534 | 534 |
| 535 void HGlobalValueNumberingPhase::ProcessLoopBlock( | 535 void HGlobalValueNumberingPhase::ProcessLoopBlock( |
| 536 HBasicBlock* block, | 536 HBasicBlock* block, |
| 537 HBasicBlock* loop_header, | 537 HBasicBlock* loop_header, |
| 538 GVNFlagSet loop_kills, | 538 GVNFlagSet loop_kills, |
| 539 GVNFlagSet* first_time_depends, | 539 GVNFlagSet* first_time_depends, |
| 540 GVNFlagSet* first_time_changes) { | 540 GVNFlagSet* first_time_changes) { |
| 541 HBasicBlock* pre_header = loop_header->predecessors()->at(0); | 541 HBasicBlock* pre_header = loop_header->predecessors()->at(0); |
| 542 GVNFlagSet depends_flags = HValue::ConvertChangesToDependsFlags(loop_kills); | 542 GVNFlagSet depends_flags = HValue::ConvertChangesToDependsFlags(loop_kills); |
| 543 TRACE_GVN_2("Loop invariant motion for B%d %s\n", | 543 TRACE_GVN_2("Loop invariant motion for B%d %s\n", |
| 544 block->block_id(), | 544 block->block_id(), |
| 545 *GetGVNFlagsString(depends_flags)); | 545 GetGVNFlagsString(depends_flags).get()); |
| 546 HInstruction* instr = block->first(); | 546 HInstruction* instr = block->first(); |
| 547 while (instr != NULL) { | 547 while (instr != NULL) { |
| 548 HInstruction* next = instr->next(); | 548 HInstruction* next = instr->next(); |
| 549 bool hoisted = false; | 549 bool hoisted = false; |
| 550 if (instr->CheckFlag(HValue::kUseGVN)) { | 550 if (instr->CheckFlag(HValue::kUseGVN)) { |
| 551 TRACE_GVN_4("Checking instruction %d (%s) %s. Loop %s\n", | 551 TRACE_GVN_4("Checking instruction %d (%s) %s. Loop %s\n", |
| 552 instr->id(), | 552 instr->id(), |
| 553 instr->Mnemonic(), | 553 instr->Mnemonic(), |
| 554 *GetGVNFlagsString(instr->gvn_flags()), | 554 GetGVNFlagsString(instr->gvn_flags()).get(), |
| 555 *GetGVNFlagsString(loop_kills)); | 555 GetGVNFlagsString(loop_kills).get()); |
| 556 bool can_hoist = !instr->gvn_flags().ContainsAnyOf(depends_flags); | 556 bool can_hoist = !instr->gvn_flags().ContainsAnyOf(depends_flags); |
| 557 if (can_hoist && !graph()->use_optimistic_licm()) { | 557 if (can_hoist && !graph()->use_optimistic_licm()) { |
| 558 can_hoist = block->IsLoopSuccessorDominator(); | 558 can_hoist = block->IsLoopSuccessorDominator(); |
| 559 } | 559 } |
| 560 | 560 |
| 561 if (can_hoist) { | 561 if (can_hoist) { |
| 562 bool inputs_loop_invariant = true; | 562 bool inputs_loop_invariant = true; |
| 563 for (int i = 0; i < instr->OperandCount(); ++i) { | 563 for (int i = 0; i < instr->OperandCount(); ++i) { |
| 564 if (instr->OperandAt(i)->IsDefinedAfter(pre_header)) { | 564 if (instr->OperandAt(i)->IsDefinedAfter(pre_header)) { |
| 565 inputs_loop_invariant = false; | 565 inputs_loop_invariant = false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 578 } | 578 } |
| 579 if (!hoisted) { | 579 if (!hoisted) { |
| 580 // If an instruction is not hoisted, we have to account for its side | 580 // If an instruction is not hoisted, we have to account for its side |
| 581 // effects when hoisting later HTransitionElementsKind instructions. | 581 // effects when hoisting later HTransitionElementsKind instructions. |
| 582 GVNFlagSet previous_depends = *first_time_depends; | 582 GVNFlagSet previous_depends = *first_time_depends; |
| 583 GVNFlagSet previous_changes = *first_time_changes; | 583 GVNFlagSet previous_changes = *first_time_changes; |
| 584 first_time_depends->Add(instr->DependsOnFlags()); | 584 first_time_depends->Add(instr->DependsOnFlags()); |
| 585 first_time_changes->Add(instr->ChangesFlags()); | 585 first_time_changes->Add(instr->ChangesFlags()); |
| 586 if (!(previous_depends == *first_time_depends)) { | 586 if (!(previous_depends == *first_time_depends)) { |
| 587 TRACE_GVN_1("Updated first-time accumulated %s\n", | 587 TRACE_GVN_1("Updated first-time accumulated %s\n", |
| 588 *GetGVNFlagsString(*first_time_depends)); | 588 GetGVNFlagsString(*first_time_depends).get()); |
| 589 } | 589 } |
| 590 if (!(previous_changes == *first_time_changes)) { | 590 if (!(previous_changes == *first_time_changes)) { |
| 591 TRACE_GVN_1("Updated first-time accumulated %s\n", | 591 TRACE_GVN_1("Updated first-time accumulated %s\n", |
| 592 *GetGVNFlagsString(*first_time_changes)); | 592 GetGVNFlagsString(*first_time_changes).get()); |
| 593 } | 593 } |
| 594 } | 594 } |
| 595 instr = next; | 595 instr = next; |
| 596 } | 596 } |
| 597 } | 597 } |
| 598 | 598 |
| 599 | 599 |
| 600 bool HGlobalValueNumberingPhase::AllowCodeMotion() { | 600 bool HGlobalValueNumberingPhase::AllowCodeMotion() { |
| 601 return info()->IsStub() || info()->opt_count() + 1 < FLAG_max_opt_count; | 601 return info()->IsStub() || info()->opt_count() + 1 < FLAG_max_opt_count; |
| 602 } | 602 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 // Instruction was unlinked during graph traversal. | 794 // Instruction was unlinked during graph traversal. |
| 795 if (!instr->IsLinked()) continue; | 795 if (!instr->IsLinked()) continue; |
| 796 | 796 |
| 797 GVNFlagSet flags = instr->ChangesFlags(); | 797 GVNFlagSet flags = instr->ChangesFlags(); |
| 798 if (!flags.IsEmpty()) { | 798 if (!flags.IsEmpty()) { |
| 799 // Clear all instructions in the map that are affected by side effects. | 799 // Clear all instructions in the map that are affected by side effects. |
| 800 // Store instruction as the dominating one for tracked side effects. | 800 // Store instruction as the dominating one for tracked side effects. |
| 801 map->Kill(flags); | 801 map->Kill(flags); |
| 802 dominators->Store(flags, instr); | 802 dominators->Store(flags, instr); |
| 803 TRACE_GVN_2("Instruction %d %s\n", instr->id(), | 803 TRACE_GVN_2("Instruction %d %s\n", instr->id(), |
| 804 *GetGVNFlagsString(flags)); | 804 GetGVNFlagsString(flags).get()); |
| 805 } | 805 } |
| 806 if (instr->CheckFlag(HValue::kUseGVN)) { | 806 if (instr->CheckFlag(HValue::kUseGVN)) { |
| 807 ASSERT(!instr->HasObservableSideEffects()); | 807 ASSERT(!instr->HasObservableSideEffects()); |
| 808 HValue* other = map->Lookup(instr); | 808 HValue* other = map->Lookup(instr); |
| 809 if (other != NULL) { | 809 if (other != NULL) { |
| 810 ASSERT(instr->Equals(other) && other->Equals(instr)); | 810 ASSERT(instr->Equals(other) && other->Equals(instr)); |
| 811 TRACE_GVN_4("Replacing value %d (%s) with value %d (%s)\n", | 811 TRACE_GVN_4("Replacing value %d (%s) with value %d (%s)\n", |
| 812 instr->id(), | 812 instr->id(), |
| 813 instr->Mnemonic(), | 813 instr->Mnemonic(), |
| 814 other->id(), | 814 other->id(), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 844 dominated); | 844 dominated); |
| 845 successor_map->Kill(side_effects_on_all_paths); | 845 successor_map->Kill(side_effects_on_all_paths); |
| 846 successor_dominators->Kill(side_effects_on_all_paths); | 846 successor_dominators->Kill(side_effects_on_all_paths); |
| 847 } | 847 } |
| 848 } | 848 } |
| 849 current = next; | 849 current = next; |
| 850 } | 850 } |
| 851 } | 851 } |
| 852 | 852 |
| 853 } } // namespace v8::internal | 853 } } // namespace v8::internal |
| OLD | NEW |