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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 TRACE_GVN_2("Analyzing block B%d%s\n", | 769 TRACE_GVN_2("Analyzing block B%d%s\n", |
770 block->block_id(), | 770 block->block_id(), |
771 block->IsLoopHeader() ? " (loop header)" : ""); | 771 block->IsLoopHeader() ? " (loop header)" : ""); |
772 | 772 |
773 // If this is a loop header kill everything killed by the loop. | 773 // If this is a loop header kill everything killed by the loop. |
774 if (block->IsLoopHeader()) { | 774 if (block->IsLoopHeader()) { |
775 map->Kill(loop_side_effects_[block->block_id()]); | 775 map->Kill(loop_side_effects_[block->block_id()]); |
776 } | 776 } |
777 | 777 |
778 // Go through all instructions of the current block. | 778 // Go through all instructions of the current block. |
779 HInstruction* instr = block->first(); | 779 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { |
780 while (instr != NULL) { | 780 HInstruction* instr = it.Current(); |
781 HInstruction* next = instr->next(); | 781 if (instr->CheckFlag(HValue::kTrackSideEffectDominators)) { |
| 782 for (int i = 0; i < kNumberOfTrackedSideEffects; i++) { |
| 783 HValue* other = dominators->at(i); |
| 784 GVNFlag changes_flag = HValue::ChangesFlagFromInt(i); |
| 785 GVNFlag depends_on_flag = HValue::DependsOnFlagFromInt(i); |
| 786 if (instr->DependsOnFlags().Contains(depends_on_flag) && |
| 787 (other != NULL)) { |
| 788 TRACE_GVN_5("Side-effect #%d in %d (%s) is dominated by %d (%s)\n", |
| 789 i, |
| 790 instr->id(), |
| 791 instr->Mnemonic(), |
| 792 other->id(), |
| 793 other->Mnemonic()); |
| 794 instr->HandleSideEffectDominator(changes_flag, other); |
| 795 } |
| 796 } |
| 797 } |
| 798 // Instruction was unlinked during graph traversal. |
| 799 if (!instr->IsLinked()) continue; |
| 800 |
782 GVNFlagSet flags = instr->ChangesFlags(); | 801 GVNFlagSet flags = instr->ChangesFlags(); |
783 if (!flags.IsEmpty()) { | 802 if (!flags.IsEmpty()) { |
784 // Clear all instructions in the map that are affected by side effects. | 803 // Clear all instructions in the map that are affected by side effects. |
785 // Store instruction as the dominating one for tracked side effects. | 804 // Store instruction as the dominating one for tracked side effects. |
786 map->Kill(flags); | 805 map->Kill(flags); |
787 dominators->Store(flags, instr); | 806 dominators->Store(flags, instr); |
788 TRACE_GVN_2("Instruction %d %s\n", instr->id(), | 807 TRACE_GVN_2("Instruction %d %s\n", instr->id(), |
789 *GetGVNFlagsString(flags)); | 808 *GetGVNFlagsString(flags)); |
790 } | 809 } |
791 if (instr->CheckFlag(HValue::kUseGVN)) { | 810 if (instr->CheckFlag(HValue::kUseGVN)) { |
792 ASSERT(!instr->HasObservableSideEffects()); | 811 ASSERT(!instr->HasObservableSideEffects()); |
793 HValue* other = map->Lookup(instr); | 812 HValue* other = map->Lookup(instr); |
794 if (other != NULL) { | 813 if (other != NULL) { |
795 ASSERT(instr->Equals(other) && other->Equals(instr)); | 814 ASSERT(instr->Equals(other) && other->Equals(instr)); |
796 TRACE_GVN_4("Replacing value %d (%s) with value %d (%s)\n", | 815 TRACE_GVN_4("Replacing value %d (%s) with value %d (%s)\n", |
797 instr->id(), | 816 instr->id(), |
798 instr->Mnemonic(), | 817 instr->Mnemonic(), |
799 other->id(), | 818 other->id(), |
800 other->Mnemonic()); | 819 other->Mnemonic()); |
801 if (instr->HasSideEffects()) removed_side_effects_ = true; | 820 if (instr->HasSideEffects()) removed_side_effects_ = true; |
802 instr->DeleteAndReplaceWith(other); | 821 instr->DeleteAndReplaceWith(other); |
803 } else { | 822 } else { |
804 map->Add(instr, zone()); | 823 map->Add(instr, zone()); |
805 } | 824 } |
806 } | 825 } |
807 if (instr->IsLinked() && | |
808 instr->CheckFlag(HValue::kTrackSideEffectDominators)) { | |
809 for (int i = 0; i < kNumberOfTrackedSideEffects; i++) { | |
810 HValue* other = dominators->at(i); | |
811 GVNFlag changes_flag = HValue::ChangesFlagFromInt(i); | |
812 GVNFlag depends_on_flag = HValue::DependsOnFlagFromInt(i); | |
813 if (instr->DependsOnFlags().Contains(depends_on_flag) && | |
814 (other != NULL)) { | |
815 TRACE_GVN_5("Side-effect #%d in %d (%s) is dominated by %d (%s)\n", | |
816 i, | |
817 instr->id(), | |
818 instr->Mnemonic(), | |
819 other->id(), | |
820 other->Mnemonic()); | |
821 instr->SetSideEffectDominator(changes_flag, other); | |
822 } | |
823 } | |
824 } | |
825 instr = next; | |
826 } | 826 } |
827 | 827 |
828 HBasicBlock* dominator_block; | 828 HBasicBlock* dominator_block; |
829 GvnBasicBlockState* next = | 829 GvnBasicBlockState* next = |
830 current->next_in_dominator_tree_traversal(zone(), | 830 current->next_in_dominator_tree_traversal(zone(), |
831 &dominator_block); | 831 &dominator_block); |
832 | 832 |
833 if (next != NULL) { | 833 if (next != NULL) { |
834 HBasicBlock* dominated = next->block(); | 834 HBasicBlock* dominated = next->block(); |
835 HValueMap* successor_map = next->map(); | 835 HValueMap* successor_map = next->map(); |
(...skipping 12 matching lines...) Expand all Loading... |
848 dominated); | 848 dominated); |
849 successor_map->Kill(side_effects_on_all_paths); | 849 successor_map->Kill(side_effects_on_all_paths); |
850 successor_dominators->Kill(side_effects_on_all_paths); | 850 successor_dominators->Kill(side_effects_on_all_paths); |
851 } | 851 } |
852 } | 852 } |
853 current = next; | 853 current = next; |
854 } | 854 } |
855 } | 855 } |
856 | 856 |
857 } } // namespace v8::internal | 857 } } // namespace v8::internal |
OLD | NEW |