| 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/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/flow_graph_allocator.h" | 9 #include "vm/flow_graph_allocator.h" |
| 10 #include "vm/flow_graph_builder.h" | 10 #include "vm/flow_graph_builder.h" |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 // Search downwards, bubbling up intermediate predecessors. | 753 // Search downwards, bubbling up intermediate predecessors. |
| 754 for (; new_index > 0; --new_index) { | 754 for (; new_index > 0; --new_index) { |
| 755 if (join->predecessors_[new_index - 1]->block_id() < new_id) break; | 755 if (join->predecessors_[new_index - 1]->block_id() < new_id) break; |
| 756 join->predecessors_[new_index] = join->predecessors_[new_index - 1]; | 756 join->predecessors_[new_index] = join->predecessors_[new_index - 1]; |
| 757 } | 757 } |
| 758 } | 758 } |
| 759 join->predecessors_[new_index] = new_block; | 759 join->predecessors_[new_index] = new_block; |
| 760 // If the new and old predecessor index match there is nothing to update. | 760 // If the new and old predecessor index match there is nothing to update. |
| 761 if ((join->phis() == NULL) || (old_index == new_index)) return; | 761 if ((join->phis() == NULL) || (old_index == new_index)) return; |
| 762 // Otherwise, reorder the predecessor uses in each phi. | 762 // Otherwise, reorder the predecessor uses in each phi. |
| 763 for (intptr_t i = 0; i < join->phis()->length(); ++i) { | 763 for (PhiIterator it(join); !it.Done(); it.Advance()) { |
| 764 PhiInstr* phi = (*join->phis())[i]; | 764 PhiInstr* phi = it.Current(); |
| 765 if (phi == NULL) continue; | 765 ASSERT(phi != NULL); |
| 766 ASSERT(pred_count == phi->InputCount()); | 766 ASSERT(pred_count == phi->InputCount()); |
| 767 // Save the predecessor use. | 767 // Save the predecessor use. |
| 768 Value* pred_use = phi->InputAt(old_index); | 768 Value* pred_use = phi->InputAt(old_index); |
| 769 // Move uses between old and new. | 769 // Move uses between old and new. |
| 770 intptr_t step = (old_index < new_index) ? 1 : -1; | 770 intptr_t step = (old_index < new_index) ? 1 : -1; |
| 771 for (intptr_t use_idx = old_index; | 771 for (intptr_t use_idx = old_index; |
| 772 use_idx != new_index; | 772 use_idx != new_index; |
| 773 use_idx += step) { | 773 use_idx += step) { |
| 774 phi->SetInputAt(use_idx, phi->InputAt(use_idx + step)); | 774 phi->SetInputAt(use_idx, phi->InputAt(use_idx + step)); |
| 775 } | 775 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 786 // for variable with index i at position i. | 786 // for variable with index i at position i. |
| 787 // TODO(fschneider): Store phis in a more compact way. | 787 // TODO(fschneider): Store phis in a more compact way. |
| 788 if (phis_ == NULL) { | 788 if (phis_ == NULL) { |
| 789 phis_ = new ZoneGrowableArray<PhiInstr*>(var_count); | 789 phis_ = new ZoneGrowableArray<PhiInstr*>(var_count); |
| 790 for (intptr_t i = 0; i < var_count; i++) { | 790 for (intptr_t i = 0; i < var_count; i++) { |
| 791 phis_->Add(NULL); | 791 phis_->Add(NULL); |
| 792 } | 792 } |
| 793 } | 793 } |
| 794 ASSERT((*phis_)[var_index] == NULL); | 794 ASSERT((*phis_)[var_index] == NULL); |
| 795 (*phis_)[var_index] = new PhiInstr(this, PredecessorCount()); | 795 (*phis_)[var_index] = new PhiInstr(this, PredecessorCount()); |
| 796 phi_count_++; | |
| 797 } | 796 } |
| 798 | 797 |
| 799 | 798 |
| 800 void JoinEntryInstr::InsertPhi(PhiInstr* phi) { | 799 void JoinEntryInstr::InsertPhi(PhiInstr* phi) { |
| 801 // Lazily initialize the array of phis. | 800 // Lazily initialize the array of phis. |
| 802 if (phis_ == NULL) { | 801 if (phis_ == NULL) { |
| 803 phis_ = new ZoneGrowableArray<PhiInstr*>(1); | 802 phis_ = new ZoneGrowableArray<PhiInstr*>(1); |
| 804 } | 803 } |
| 805 phis_->Add(phi); | 804 phis_->Add(phi); |
| 806 phi_count_++; | |
| 807 } | 805 } |
| 808 | 806 |
| 809 | 807 |
| 810 void JoinEntryInstr::RemoveDeadPhis() { | 808 void JoinEntryInstr::RemoveDeadPhis(Definition* replacement) { |
| 811 if (phis_ == NULL) return; | 809 if (phis_ == NULL) return; |
| 812 | 810 |
| 813 for (intptr_t i = 0; i < phis_->length(); i++) { | 811 intptr_t to_index = 0; |
| 814 PhiInstr* phi = (*phis_)[i]; | 812 for (intptr_t from_index = 0; from_index < phis_->length(); ++from_index) { |
| 815 if ((phi != NULL) && !phi->is_alive()) { | 813 PhiInstr* phi = (*phis_)[from_index]; |
| 816 (*phis_)[i] = NULL; | 814 if (phi != NULL) { |
| 817 phi_count_--; | 815 if (phi->is_alive()) { |
| 816 (*phis_)[to_index++] = phi; |
| 817 for (intptr_t i = phi->InputCount() - 1; i >= 0; --i) { |
| 818 Value* input = phi->InputAt(i); |
| 819 input->definition()->AddInputUse(input); |
| 820 } |
| 821 } else { |
| 822 phi->ReplaceUsesWith(replacement); |
| 823 } |
| 818 } | 824 } |
| 819 } | 825 } |
| 820 | 826 if (to_index == 0) { |
| 821 // Check if we removed all phis. | 827 phis_ = NULL; |
| 822 if (phi_count_ == 0) phis_ = NULL; | 828 } else { |
| 829 phis_->TruncateTo(to_index); |
| 830 } |
| 823 } | 831 } |
| 824 | 832 |
| 825 | 833 |
| 826 intptr_t Instruction::SuccessorCount() const { | 834 intptr_t Instruction::SuccessorCount() const { |
| 827 return 0; | 835 return 0; |
| 828 } | 836 } |
| 829 | 837 |
| 830 | 838 |
| 831 BlockEntryInstr* Instruction::SuccessorAt(intptr_t index) const { | 839 BlockEntryInstr* Instruction::SuccessorAt(intptr_t index) const { |
| 832 // Called only if index is in range. Only control-transfer instructions | 840 // Called only if index is in range. Only control-transfer instructions |
| (...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2259 default: | 2267 default: |
| 2260 UNREACHABLE(); | 2268 UNREACHABLE(); |
| 2261 } | 2269 } |
| 2262 return kPowRuntimeEntry; | 2270 return kPowRuntimeEntry; |
| 2263 } | 2271 } |
| 2264 | 2272 |
| 2265 | 2273 |
| 2266 #undef __ | 2274 #undef __ |
| 2267 | 2275 |
| 2268 } // namespace dart | 2276 } // namespace dart |
| OLD | NEW |