OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 bool a_truncate = a->CheckFlag(HValue::kTruncatingToInt32); | 1768 bool a_truncate = a->CheckFlag(HValue::kTruncatingToInt32); |
1769 bool b_truncate = b->CheckFlag(HValue::kTruncatingToInt32); | 1769 bool b_truncate = b->CheckFlag(HValue::kTruncatingToInt32); |
1770 if (a_truncate != b_truncate) { | 1770 if (a_truncate != b_truncate) { |
1771 return a_truncate ? -1 : 1; | 1771 return a_truncate ? -1 : 1; |
1772 } | 1772 } |
1773 // Sort by increasing block ID. | 1773 // Sort by increasing block ID. |
1774 return a->block()->block_id() - b->block()->block_id(); | 1774 return a->block()->block_id() - b->block()->block_id(); |
1775 } | 1775 } |
1776 | 1776 |
1777 | 1777 |
1778 void HGraph::InsertRepresentationChanges(HValue* current) { | 1778 void HGraph::InsertRepresentationChangesForValue( |
| 1779 HValue* current, |
| 1780 ZoneList<HValue*>* to_convert, |
| 1781 ZoneList<Representation>* to_convert_reps) { |
1779 Representation r = current->representation(); | 1782 Representation r = current->representation(); |
1780 if (r.IsNone()) return; | 1783 if (r.IsNone()) return; |
1781 if (current->uses()->length() == 0) return; | 1784 if (current->uses()->length() == 0) return; |
1782 | 1785 |
1783 // Collect the representation changes in a sorted list. This allows | 1786 // Collect the representation changes in a sorted list. This allows |
1784 // us to avoid duplicate changes without searching the list. | 1787 // us to avoid duplicate changes without searching the list. |
1785 ZoneList<HValue*> to_convert(2); | 1788 ASSERT(to_convert->is_empty()); |
1786 ZoneList<Representation> to_convert_reps(2); | 1789 ASSERT(to_convert_reps->is_empty()); |
1787 for (int i = 0; i < current->uses()->length(); ++i) { | 1790 for (int i = 0; i < current->uses()->length(); ++i) { |
1788 HValue* use = current->uses()->at(i); | 1791 HValue* use = current->uses()->at(i); |
1789 // The occurrences index means the index within the operand array of "use" | 1792 // The occurrences index means the index within the operand array of "use" |
1790 // at which "current" is used. While iterating through the use array we | 1793 // at which "current" is used. While iterating through the use array we |
1791 // also have to iterate over the different occurrence indices. | 1794 // also have to iterate over the different occurrence indices. |
1792 int occurrence_index = 0; | 1795 int occurrence_index = 0; |
1793 if (use->UsesMultipleTimes(current)) { | 1796 if (use->UsesMultipleTimes(current)) { |
1794 occurrence_index = current->uses()->CountOccurrences(use, 0, i - 1); | 1797 occurrence_index = current->uses()->CountOccurrences(use, 0, i - 1); |
1795 if (FLAG_trace_representation) { | 1798 if (FLAG_trace_representation) { |
1796 PrintF("Instruction %d is used multiple times at %d; occurrence=%d\n", | 1799 PrintF("Instruction %d is used multiple times at %d; occurrence=%d\n", |
1797 current->id(), | 1800 current->id(), |
1798 use->id(), | 1801 use->id(), |
1799 occurrence_index); | 1802 occurrence_index); |
1800 } | 1803 } |
1801 } | 1804 } |
1802 int operand_index = use->LookupOperandIndex(occurrence_index, current); | 1805 int operand_index = use->LookupOperandIndex(occurrence_index, current); |
1803 Representation req = use->RequiredInputRepresentation(operand_index); | 1806 Representation req = use->RequiredInputRepresentation(operand_index); |
1804 if (req.IsNone() || req.Equals(r)) continue; | 1807 if (req.IsNone() || req.Equals(r)) continue; |
1805 int index = 0; | 1808 int index = 0; |
1806 while (to_convert.length() > index && | 1809 while (index < to_convert->length() && |
1807 CompareConversionUses(to_convert[index], | 1810 CompareConversionUses(to_convert->at(index), |
1808 use, | 1811 use, |
1809 to_convert_reps[index], | 1812 to_convert_reps->at(index), |
1810 req) < 0) { | 1813 req) < 0) { |
1811 ++index; | 1814 ++index; |
1812 } | 1815 } |
1813 if (FLAG_trace_representation) { | 1816 if (FLAG_trace_representation) { |
1814 PrintF("Inserting a representation change to %s of %d for use at %d\n", | 1817 PrintF("Inserting a representation change to %s of %d for use at %d\n", |
1815 req.Mnemonic(), | 1818 req.Mnemonic(), |
1816 current->id(), | 1819 current->id(), |
1817 use->id()); | 1820 use->id()); |
1818 } | 1821 } |
1819 to_convert.InsertAt(index, use); | 1822 to_convert->InsertAt(index, use); |
1820 to_convert_reps.InsertAt(index, req); | 1823 to_convert_reps->InsertAt(index, req); |
1821 } | 1824 } |
1822 | 1825 |
1823 for (int i = 0; i < to_convert.length(); ++i) { | 1826 for (int i = 0; i < to_convert->length(); ++i) { |
1824 HValue* use = to_convert[i]; | 1827 HValue* use = to_convert->at(i); |
1825 Representation r_to = to_convert_reps[i]; | 1828 Representation r_to = to_convert_reps->at(i); |
1826 InsertRepresentationChangeForUse(current, use, r_to); | 1829 InsertRepresentationChangeForUse(current, use, r_to); |
1827 } | 1830 } |
1828 | 1831 |
1829 if (current->uses()->is_empty()) { | 1832 if (current->uses()->is_empty()) { |
1830 ASSERT(current->IsConstant()); | 1833 ASSERT(current->IsConstant()); |
1831 current->Delete(); | 1834 current->Delete(); |
1832 } | 1835 } |
| 1836 to_convert->Rewind(0); |
| 1837 to_convert_reps->Rewind(0); |
1833 } | 1838 } |
1834 | 1839 |
1835 | 1840 |
1836 void HGraph::InsertRepresentationChanges() { | 1841 void HGraph::InsertRepresentationChanges() { |
1837 HPhase phase("Insert representation changes", this); | 1842 HPhase phase("Insert representation changes", this); |
1838 | 1843 |
1839 | 1844 |
1840 // Compute truncation flag for phis: Initially assume that all | 1845 // Compute truncation flag for phis: Initially assume that all |
1841 // int32-phis allow truncation and iteratively remove the ones that | 1846 // int32-phis allow truncation and iteratively remove the ones that |
1842 // are used in an operation that does not allow a truncating | 1847 // are used in an operation that does not allow a truncating |
(...skipping 15 matching lines...) Expand all Loading... |
1858 HValue* use = phi->uses()->at(j); | 1863 HValue* use = phi->uses()->at(j); |
1859 if (!use->CheckFlag(HValue::kTruncatingToInt32)) { | 1864 if (!use->CheckFlag(HValue::kTruncatingToInt32)) { |
1860 phi->ClearFlag(HValue::kTruncatingToInt32); | 1865 phi->ClearFlag(HValue::kTruncatingToInt32); |
1861 change = true; | 1866 change = true; |
1862 break; | 1867 break; |
1863 } | 1868 } |
1864 } | 1869 } |
1865 } | 1870 } |
1866 } | 1871 } |
1867 | 1872 |
| 1873 ZoneList<HValue*> value_list(4); |
| 1874 ZoneList<Representation> rep_list(4); |
1868 for (int i = 0; i < blocks_.length(); ++i) { | 1875 for (int i = 0; i < blocks_.length(); ++i) { |
1869 // Process phi instructions first. | 1876 // Process phi instructions first. |
1870 for (int j = 0; j < blocks_[i]->phis()->length(); j++) { | 1877 for (int j = 0; j < blocks_[i]->phis()->length(); j++) { |
1871 HPhi* phi = blocks_[i]->phis()->at(j); | 1878 HPhi* phi = blocks_[i]->phis()->at(j); |
1872 InsertRepresentationChanges(phi); | 1879 InsertRepresentationChangesForValue(phi, &value_list, &rep_list); |
1873 } | 1880 } |
1874 | 1881 |
1875 // Process normal instructions. | 1882 // Process normal instructions. |
1876 HInstruction* current = blocks_[i]->first(); | 1883 HInstruction* current = blocks_[i]->first(); |
1877 while (current != NULL) { | 1884 while (current != NULL) { |
1878 InsertRepresentationChanges(current); | 1885 InsertRepresentationChangesForValue(current, &value_list, &rep_list); |
1879 current = current->next(); | 1886 current = current->next(); |
1880 } | 1887 } |
1881 } | 1888 } |
1882 } | 1889 } |
1883 | 1890 |
1884 | 1891 |
1885 void HGraph::ComputeMinusZeroChecks() { | 1892 void HGraph::ComputeMinusZeroChecks() { |
1886 BitVector visited(GetMaximumValueID()); | 1893 BitVector visited(GetMaximumValueID()); |
1887 for (int i = 0; i < blocks_.length(); ++i) { | 1894 for (int i = 0; i < blocks_.length(); ++i) { |
1888 for (HInstruction* current = blocks_[i]->first(); | 1895 for (HInstruction* current = blocks_[i]->first(); |
(...skipping 4095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5984 } | 5991 } |
5985 } | 5992 } |
5986 | 5993 |
5987 #ifdef DEBUG | 5994 #ifdef DEBUG |
5988 if (graph_ != NULL) graph_->Verify(); | 5995 if (graph_ != NULL) graph_->Verify(); |
5989 if (allocator_ != NULL) allocator_->Verify(); | 5996 if (allocator_ != NULL) allocator_->Verify(); |
5990 #endif | 5997 #endif |
5991 } | 5998 } |
5992 | 5999 |
5993 } } // namespace v8::internal | 6000 } } // namespace v8::internal |
OLD | NEW |