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