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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 data_[i] = instr; | 358 data_[i] = instr; |
359 } | 359 } |
360 } | 360 } |
361 } | 361 } |
362 | 362 |
363 | 363 |
364 HGlobalValueNumberer::HGlobalValueNumberer(HGraph* graph, CompilationInfo* info) | 364 HGlobalValueNumberer::HGlobalValueNumberer(HGraph* graph, CompilationInfo* info) |
365 : graph_(graph), | 365 : graph_(graph), |
366 info_(info), | 366 info_(info), |
367 removed_side_effects_(false), | 367 removed_side_effects_(false), |
368 block_side_effects_(graph->blocks()->length(), graph->zone()), | 368 phase_zone_(info->phase_zone()), |
369 loop_side_effects_(graph->blocks()->length(), graph->zone()), | 369 phase_zone_scope_(phase_zone_, DELETE_ON_EXIT), |
370 visited_on_paths_(graph->zone(), graph->blocks()->length()) { | 370 block_side_effects_(graph->blocks()->length(), phase_zone_), |
| 371 loop_side_effects_(graph->blocks()->length(), phase_zone_), |
| 372 visited_on_paths_(phase_zone_, graph->blocks()->length()) { |
371 ASSERT(!AllowHandleAllocation::IsAllowed()); | 373 ASSERT(!AllowHandleAllocation::IsAllowed()); |
372 block_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(), | 374 block_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(), |
373 graph_->zone()); | 375 phase_zone_); |
374 loop_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(), | 376 loop_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(), |
375 graph_->zone()); | 377 phase_zone_); |
376 } | 378 } |
377 | 379 |
378 bool HGlobalValueNumberer::Analyze() { | 380 bool HGlobalValueNumberer::Analyze() { |
379 removed_side_effects_ = false; | 381 removed_side_effects_ = false; |
380 ComputeBlockSideEffects(); | 382 ComputeBlockSideEffects(); |
381 if (FLAG_loop_invariant_code_motion) { | 383 if (FLAG_loop_invariant_code_motion) { |
382 LoopInvariantCodeMotion(); | 384 LoopInvariantCodeMotion(); |
383 } | 385 } |
384 AnalyzeGraph(); | 386 AnalyzeGraph(); |
385 return removed_side_effects_; | 387 return removed_side_effects_; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 int dominated_index_; | 751 int dominated_index_; |
750 int length_; | 752 int length_; |
751 }; | 753 }; |
752 | 754 |
753 // This is a recursive traversal of the dominator tree but it has been turned | 755 // This is a recursive traversal of the dominator tree but it has been turned |
754 // into a loop to avoid stack overflows. | 756 // into a loop to avoid stack overflows. |
755 // The logical "stack frames" of the recursion are kept in a list of | 757 // The logical "stack frames" of the recursion are kept in a list of |
756 // GvnBasicBlockState instances. | 758 // GvnBasicBlockState instances. |
757 void HGlobalValueNumberer::AnalyzeGraph() { | 759 void HGlobalValueNumberer::AnalyzeGraph() { |
758 HBasicBlock* entry_block = graph_->entry_block(); | 760 HBasicBlock* entry_block = graph_->entry_block(); |
759 HValueMap* entry_map = new(zone()) HValueMap(zone()); | 761 HValueMap* entry_map = new(phase_zone()) HValueMap(phase_zone()); |
760 GvnBasicBlockState* current = | 762 GvnBasicBlockState* current = |
761 GvnBasicBlockState::CreateEntry(zone(), entry_block, entry_map); | 763 GvnBasicBlockState::CreateEntry(phase_zone(), entry_block, entry_map); |
762 | 764 |
763 while (current != NULL) { | 765 while (current != NULL) { |
764 HBasicBlock* block = current->block(); | 766 HBasicBlock* block = current->block(); |
765 HValueMap* map = current->map(); | 767 HValueMap* map = current->map(); |
766 HSideEffectMap* dominators = current->dominators(); | 768 HSideEffectMap* dominators = current->dominators(); |
767 | 769 |
768 TRACE_GVN_2("Analyzing block B%d%s\n", | 770 TRACE_GVN_2("Analyzing block B%d%s\n", |
769 block->block_id(), | 771 block->block_id(), |
770 block->IsLoopHeader() ? " (loop header)" : ""); | 772 block->IsLoopHeader() ? " (loop header)" : ""); |
771 | 773 |
(...skipping 21 matching lines...) Expand all Loading... |
793 if (other != NULL) { | 795 if (other != NULL) { |
794 ASSERT(instr->Equals(other) && other->Equals(instr)); | 796 ASSERT(instr->Equals(other) && other->Equals(instr)); |
795 TRACE_GVN_4("Replacing value %d (%s) with value %d (%s)\n", | 797 TRACE_GVN_4("Replacing value %d (%s) with value %d (%s)\n", |
796 instr->id(), | 798 instr->id(), |
797 instr->Mnemonic(), | 799 instr->Mnemonic(), |
798 other->id(), | 800 other->id(), |
799 other->Mnemonic()); | 801 other->Mnemonic()); |
800 if (instr->HasSideEffects()) removed_side_effects_ = true; | 802 if (instr->HasSideEffects()) removed_side_effects_ = true; |
801 instr->DeleteAndReplaceWith(other); | 803 instr->DeleteAndReplaceWith(other); |
802 } else { | 804 } else { |
803 map->Add(instr, zone()); | 805 map->Add(instr, phase_zone()); |
804 } | 806 } |
805 } | 807 } |
806 if (instr->IsLinked() && | 808 if (instr->IsLinked() && |
807 instr->CheckFlag(HValue::kTrackSideEffectDominators)) { | 809 instr->CheckFlag(HValue::kTrackSideEffectDominators)) { |
808 for (int i = 0; i < kNumberOfTrackedSideEffects; i++) { | 810 for (int i = 0; i < kNumberOfTrackedSideEffects; i++) { |
809 HValue* other = dominators->at(i); | 811 HValue* other = dominators->at(i); |
810 GVNFlag changes_flag = HValue::ChangesFlagFromInt(i); | 812 GVNFlag changes_flag = HValue::ChangesFlagFromInt(i); |
811 GVNFlag depends_on_flag = HValue::DependsOnFlagFromInt(i); | 813 GVNFlag depends_on_flag = HValue::DependsOnFlagFromInt(i); |
812 if (instr->DependsOnFlags().Contains(depends_on_flag) && | 814 if (instr->DependsOnFlags().Contains(depends_on_flag) && |
813 (other != NULL)) { | 815 (other != NULL)) { |
814 TRACE_GVN_5("Side-effect #%d in %d (%s) is dominated by %d (%s)\n", | 816 TRACE_GVN_5("Side-effect #%d in %d (%s) is dominated by %d (%s)\n", |
815 i, | 817 i, |
816 instr->id(), | 818 instr->id(), |
817 instr->Mnemonic(), | 819 instr->Mnemonic(), |
818 other->id(), | 820 other->id(), |
819 other->Mnemonic()); | 821 other->Mnemonic()); |
820 instr->SetSideEffectDominator(changes_flag, other); | 822 instr->SetSideEffectDominator(changes_flag, other); |
821 } | 823 } |
822 } | 824 } |
823 } | 825 } |
824 instr = next; | 826 instr = next; |
825 } | 827 } |
826 | 828 |
827 HBasicBlock* dominator_block; | 829 HBasicBlock* dominator_block; |
828 GvnBasicBlockState* next = | 830 GvnBasicBlockState* next = |
829 current->next_in_dominator_tree_traversal(zone(), &dominator_block); | 831 current->next_in_dominator_tree_traversal(phase_zone(), |
| 832 &dominator_block); |
830 | 833 |
831 if (next != NULL) { | 834 if (next != NULL) { |
832 HBasicBlock* dominated = next->block(); | 835 HBasicBlock* dominated = next->block(); |
833 HValueMap* successor_map = next->map(); | 836 HValueMap* successor_map = next->map(); |
834 HSideEffectMap* successor_dominators = next->dominators(); | 837 HSideEffectMap* successor_dominators = next->dominators(); |
835 | 838 |
836 // Kill everything killed on any path between this block and the | 839 // Kill everything killed on any path between this block and the |
837 // dominated block. We don't have to traverse these paths if the | 840 // dominated block. We don't have to traverse these paths if the |
838 // value map and the dominators list is already empty. If the range | 841 // value map and the dominators list is already empty. If the range |
839 // of block ids (block_id, dominated_id) is empty there are no such | 842 // of block ids (block_id, dominated_id) is empty there are no such |
840 // paths. | 843 // paths. |
841 if ((!successor_map->IsEmpty() || !successor_dominators->IsEmpty()) && | 844 if ((!successor_map->IsEmpty() || !successor_dominators->IsEmpty()) && |
842 dominator_block->block_id() + 1 < dominated->block_id()) { | 845 dominator_block->block_id() + 1 < dominated->block_id()) { |
843 visited_on_paths_.Clear(); | 846 visited_on_paths_.Clear(); |
844 GVNFlagSet side_effects_on_all_paths = | 847 GVNFlagSet side_effects_on_all_paths = |
845 CollectSideEffectsOnPathsToDominatedBlock(dominator_block, | 848 CollectSideEffectsOnPathsToDominatedBlock(dominator_block, |
846 dominated); | 849 dominated); |
847 successor_map->Kill(side_effects_on_all_paths); | 850 successor_map->Kill(side_effects_on_all_paths); |
848 successor_dominators->Kill(side_effects_on_all_paths); | 851 successor_dominators->Kill(side_effects_on_all_paths); |
849 } | 852 } |
850 } | 853 } |
851 current = next; | 854 current = next; |
852 } | 855 } |
853 } | 856 } |
854 | 857 |
855 } } // namespace v8::internal | 858 } } // namespace v8::internal |
OLD | NEW |