Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1505 HBasicBlock* dominator, | 1505 HBasicBlock* dominator, |
| 1506 HBasicBlock* dominated); | 1506 HBasicBlock* dominated); |
| 1507 void AnalyzeGraph(); | 1507 void AnalyzeGraph(); |
| 1508 void ComputeBlockSideEffects(); | 1508 void ComputeBlockSideEffects(); |
| 1509 void LoopInvariantCodeMotion(); | 1509 void LoopInvariantCodeMotion(); |
| 1510 void ProcessLoopBlock(HBasicBlock* block, | 1510 void ProcessLoopBlock(HBasicBlock* block, |
| 1511 HBasicBlock* before_loop, | 1511 HBasicBlock* before_loop, |
| 1512 GVNFlagSet loop_kills, | 1512 GVNFlagSet loop_kills, |
| 1513 GVNFlagSet* accumulated_first_time_depends, | 1513 GVNFlagSet* accumulated_first_time_depends, |
| 1514 GVNFlagSet* accumulated_first_time_changes); | 1514 GVNFlagSet* accumulated_first_time_changes); |
| 1515 void PostProcessLoopPreHeader(HBasicBlock* pre_header); | |
| 1515 bool AllowCodeMotion(); | 1516 bool AllowCodeMotion(); |
| 1516 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); | 1517 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); |
| 1517 | 1518 |
| 1518 HGraph* graph() { return graph_; } | 1519 HGraph* graph() { return graph_; } |
| 1519 CompilationInfo* info() { return info_; } | 1520 CompilationInfo* info() { return info_; } |
| 1520 Zone* zone() const { return graph_->zone(); } | 1521 Zone* zone() const { return graph_->zone(); } |
| 1521 | 1522 |
| 1522 HGraph* graph_; | 1523 HGraph* graph_; |
| 1523 CompilationInfo* info_; | 1524 CompilationInfo* info_; |
| 1524 bool removed_side_effects_; | 1525 bool removed_side_effects_; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1684 GVNFlagSet accumulated_first_time_depends; | 1685 GVNFlagSet accumulated_first_time_depends; |
| 1685 GVNFlagSet accumulated_first_time_changes; | 1686 GVNFlagSet accumulated_first_time_changes; |
| 1686 HBasicBlock* last = block->loop_information()->GetLastBackEdge(); | 1687 HBasicBlock* last = block->loop_information()->GetLastBackEdge(); |
| 1687 for (int j = block->block_id(); j <= last->block_id(); ++j) { | 1688 for (int j = block->block_id(); j <= last->block_id(); ++j) { |
| 1688 ProcessLoopBlock(graph_->blocks()->at(j), block, side_effects, | 1689 ProcessLoopBlock(graph_->blocks()->at(j), block, side_effects, |
| 1689 &accumulated_first_time_depends, | 1690 &accumulated_first_time_depends, |
| 1690 &accumulated_first_time_changes); | 1691 &accumulated_first_time_changes); |
| 1691 } | 1692 } |
| 1692 } | 1693 } |
| 1693 } | 1694 } |
| 1695 for (int i = graph_->blocks()->length() - 1; i >= 0; --i) { | |
| 1696 HBasicBlock* block = graph_->blocks()->at(i); | |
| 1697 if (block->IsLoopHeader()) { | |
| 1698 PostProcessLoopPreHeader(block->predecessors()->at(0)); | |
| 1699 } | |
| 1700 } | |
| 1694 } | 1701 } |
| 1695 | 1702 |
| 1696 | 1703 |
| 1697 void HGlobalValueNumberer::ProcessLoopBlock( | 1704 void HGlobalValueNumberer::ProcessLoopBlock( |
| 1698 HBasicBlock* block, | 1705 HBasicBlock* block, |
| 1699 HBasicBlock* loop_header, | 1706 HBasicBlock* loop_header, |
| 1700 GVNFlagSet loop_kills, | 1707 GVNFlagSet loop_kills, |
| 1701 GVNFlagSet* first_time_depends, | 1708 GVNFlagSet* first_time_depends, |
| 1702 GVNFlagSet* first_time_changes) { | 1709 GVNFlagSet* first_time_changes) { |
| 1703 HBasicBlock* pre_header = loop_header->predecessors()->at(0); | 1710 HBasicBlock* pre_header = loop_header->predecessors()->at(0); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1794 } | 1801 } |
| 1795 if (!(previous_changes == *first_time_changes)) { | 1802 if (!(previous_changes == *first_time_changes)) { |
| 1796 TRACE_GVN_1("Updated first-time accumulated %s\n", | 1803 TRACE_GVN_1("Updated first-time accumulated %s\n", |
| 1797 *GetGVNFlagsString(*first_time_changes)); | 1804 *GetGVNFlagsString(*first_time_changes)); |
| 1798 } | 1805 } |
| 1799 } | 1806 } |
| 1800 instr = next; | 1807 instr = next; |
| 1801 } | 1808 } |
| 1802 } | 1809 } |
| 1803 | 1810 |
| 1811 void HGlobalValueNumberer::PostProcessLoopPreHeader(HBasicBlock* pre_header) { | |
| 1812 HInstruction* instr = pre_header->first(); | |
| 1813 while (instr != NULL) { | |
| 1814 HInstruction* next = instr->next(); | |
| 1815 if (instr->IsTransitionElementsKind()) { | |
| 1816 HValue* old_elems = instr->OperandAt(0), *new_elems = instr; | |
| 1817 HInstruction* current = next; | |
| 1818 while (current != NULL) { | |
| 1819 for (int i = 0; i < current->OperandCount(); ++i) { | |
| 1820 if (current->OperandAt(i) == old_elems) { | |
| 1821 current->SetOperandAt(i, new_elems); | |
| 1822 } | |
| 1823 } | |
| 1824 current = current->next(); | |
| 1825 } | |
| 1826 } | |
|
danno
2012/06/19 15:45:05
This is potentially a n^2 algorithm with respect t
| |
| 1827 instr = next; | |
| 1828 } | |
| 1829 } | |
| 1830 | |
| 1804 | 1831 |
| 1805 bool HGlobalValueNumberer::AllowCodeMotion() { | 1832 bool HGlobalValueNumberer::AllowCodeMotion() { |
| 1806 return info()->shared_info()->opt_count() + 1 < Compiler::kDefaultMaxOptCount; | 1833 return info()->shared_info()->opt_count() + 1 < Compiler::kDefaultMaxOptCount; |
| 1807 } | 1834 } |
| 1808 | 1835 |
| 1809 | 1836 |
| 1810 bool HGlobalValueNumberer::ShouldMove(HInstruction* instr, | 1837 bool HGlobalValueNumberer::ShouldMove(HInstruction* instr, |
| 1811 HBasicBlock* loop_header) { | 1838 HBasicBlock* loop_header) { |
| 1812 // If we've disabled code motion or we're in a block that unconditionally | 1839 // If we've disabled code motion or we're in a block that unconditionally |
| 1813 // deoptimizes, don't move any instructions. | 1840 // deoptimizes, don't move any instructions. |
| (...skipping 7375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9189 } | 9216 } |
| 9190 } | 9217 } |
| 9191 | 9218 |
| 9192 #ifdef DEBUG | 9219 #ifdef DEBUG |
| 9193 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 9220 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 9194 if (allocator_ != NULL) allocator_->Verify(); | 9221 if (allocator_ != NULL) allocator_->Verify(); |
| 9195 #endif | 9222 #endif |
| 9196 } | 9223 } |
| 9197 | 9224 |
| 9198 } } // namespace v8::internal | 9225 } } // namespace v8::internal |
| OLD | NEW |