| 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 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1758 } else { | 1758 } else { |
| 1759 next = HInstruction::cast(use); | 1759 next = HInstruction::cast(use); |
| 1760 } | 1760 } |
| 1761 | 1761 |
| 1762 // For constants we try to make the representation change at compile | 1762 // For constants we try to make the representation change at compile |
| 1763 // time. When a representation change is not possible without loss of | 1763 // time. When a representation change is not possible without loss of |
| 1764 // information we treat constants like normal instructions and insert the | 1764 // information we treat constants like normal instructions and insert the |
| 1765 // change instructions for them. | 1765 // change instructions for them. |
| 1766 HInstruction* new_value = NULL; | 1766 HInstruction* new_value = NULL; |
| 1767 bool is_truncating = use->CheckFlag(HValue::kTruncatingToInt32); | 1767 bool is_truncating = use->CheckFlag(HValue::kTruncatingToInt32); |
| 1768 bool deoptimize_on_undefined = use->CheckFlag(HValue::kDeoptimizeOnUndefined); |
| 1768 if (value->IsConstant()) { | 1769 if (value->IsConstant()) { |
| 1769 HConstant* constant = HConstant::cast(value); | 1770 HConstant* constant = HConstant::cast(value); |
| 1770 // Try to create a new copy of the constant with the new representation. | 1771 // Try to create a new copy of the constant with the new representation. |
| 1771 new_value = is_truncating | 1772 new_value = is_truncating |
| 1772 ? constant->CopyToTruncatedInt32() | 1773 ? constant->CopyToTruncatedInt32() |
| 1773 : constant->CopyToRepresentation(to); | 1774 : constant->CopyToRepresentation(to); |
| 1774 } | 1775 } |
| 1775 | 1776 |
| 1776 if (new_value == NULL) { | 1777 if (new_value == NULL) { |
| 1777 new_value = | 1778 new_value = new(zone()) HChange(value, value->representation(), to, |
| 1778 new(zone()) HChange(value, value->representation(), to, is_truncating); | 1779 is_truncating, deoptimize_on_undefined); |
| 1779 } | 1780 } |
| 1780 | 1781 |
| 1781 new_value->InsertBefore(next); | 1782 new_value->InsertBefore(next); |
| 1782 value->ReplaceFirstAtUse(use, new_value, to); | 1783 value->ReplaceFirstAtUse(use, new_value, to); |
| 1783 } | 1784 } |
| 1784 | 1785 |
| 1785 | 1786 |
| 1786 int CompareConversionUses(HValue* a, | 1787 int CompareConversionUses(HValue* a, |
| 1787 HValue* b, | 1788 HValue* b, |
| 1788 Representation a_rep, | 1789 Representation a_rep, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1909 // Process normal instructions. | 1910 // Process normal instructions. |
| 1910 HInstruction* current = blocks_[i]->first(); | 1911 HInstruction* current = blocks_[i]->first(); |
| 1911 while (current != NULL) { | 1912 while (current != NULL) { |
| 1912 InsertRepresentationChangesForValue(current, &value_list, &rep_list); | 1913 InsertRepresentationChangesForValue(current, &value_list, &rep_list); |
| 1913 current = current->next(); | 1914 current = current->next(); |
| 1914 } | 1915 } |
| 1915 } | 1916 } |
| 1916 } | 1917 } |
| 1917 | 1918 |
| 1918 | 1919 |
| 1920 void HGraph::RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi* phi) { |
| 1921 if (phi->CheckFlag(HValue::kDeoptimizeOnUndefined)) return; |
| 1922 phi->SetFlag(HValue::kDeoptimizeOnUndefined); |
| 1923 for (int i = 0; i < phi->OperandCount(); ++i) { |
| 1924 HValue* input = phi->OperandAt(i); |
| 1925 if (input->IsPhi()) { |
| 1926 RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi::cast(input)); |
| 1927 } |
| 1928 } |
| 1929 } |
| 1930 |
| 1931 |
| 1932 void HGraph::MarkDeoptimizeOnUndefined() { |
| 1933 HPhase phase("MarkDeoptimizeOnUndefined", this); |
| 1934 // Compute DeoptimizeOnUndefined flag for phis. |
| 1935 // Any phi that can reach a use with DeoptimizeOnUndefined set must |
| 1936 // have DeoptimizeOnUndefined set. Currently only HCompare, with |
| 1937 // double input representation, has this flag set. |
| 1938 // The flag is used by HChange tagged->double, which must deoptimize |
| 1939 // if one of its uses has this flag set. |
| 1940 for (int i = 0; i < phi_list()->length(); i++) { |
| 1941 HPhi* phi = phi_list()->at(i); |
| 1942 if (phi->representation().IsDouble()) { |
| 1943 for (int j = 0; j < phi->uses()->length(); j++) { |
| 1944 HValue* use = phi->uses()->at(j); |
| 1945 if (use->CheckFlag(HValue::kDeoptimizeOnUndefined)) { |
| 1946 RecursivelyMarkPhiDeoptimizeOnUndefined(phi); |
| 1947 break; |
| 1948 } |
| 1949 } |
| 1950 } |
| 1951 } |
| 1952 } |
| 1953 |
| 1954 |
| 1919 void HGraph::ComputeMinusZeroChecks() { | 1955 void HGraph::ComputeMinusZeroChecks() { |
| 1920 BitVector visited(GetMaximumValueID()); | 1956 BitVector visited(GetMaximumValueID()); |
| 1921 for (int i = 0; i < blocks_.length(); ++i) { | 1957 for (int i = 0; i < blocks_.length(); ++i) { |
| 1922 for (HInstruction* current = blocks_[i]->first(); | 1958 for (HInstruction* current = blocks_[i]->first(); |
| 1923 current != NULL; | 1959 current != NULL; |
| 1924 current = current->next()) { | 1960 current = current->next()) { |
| 1925 if (current->IsChange()) { | 1961 if (current->IsChange()) { |
| 1926 HChange* change = HChange::cast(current); | 1962 HChange* change = HChange::cast(current); |
| 1927 // Propagate flags for negative zero checks upwards from conversions | 1963 // Propagate flags for negative zero checks upwards from conversions |
| 1928 // int32-to-tagged and int32-to-double. | 1964 // int32-to-tagged and int32-to-double. |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2227 HInferRepresentation rep(graph()); | 2263 HInferRepresentation rep(graph()); |
| 2228 rep.Analyze(); | 2264 rep.Analyze(); |
| 2229 | 2265 |
| 2230 if (FLAG_use_range) { | 2266 if (FLAG_use_range) { |
| 2231 HRangeAnalysis rangeAnalysis(graph()); | 2267 HRangeAnalysis rangeAnalysis(graph()); |
| 2232 rangeAnalysis.Analyze(); | 2268 rangeAnalysis.Analyze(); |
| 2233 } | 2269 } |
| 2234 | 2270 |
| 2235 graph()->InitializeInferredTypes(); | 2271 graph()->InitializeInferredTypes(); |
| 2236 graph()->Canonicalize(); | 2272 graph()->Canonicalize(); |
| 2273 graph()->MarkDeoptimizeOnUndefined(); |
| 2237 graph()->InsertRepresentationChanges(); | 2274 graph()->InsertRepresentationChanges(); |
| 2238 graph()->ComputeMinusZeroChecks(); | 2275 graph()->ComputeMinusZeroChecks(); |
| 2239 | 2276 |
| 2240 // Eliminate redundant stack checks on backwards branches. | 2277 // Eliminate redundant stack checks on backwards branches. |
| 2241 HStackCheckEliminator sce(graph()); | 2278 HStackCheckEliminator sce(graph()); |
| 2242 sce.Process(); | 2279 sce.Process(); |
| 2243 | 2280 |
| 2244 // Perform common subexpression elimination and loop-invariant code motion. | 2281 // Perform common subexpression elimination and loop-invariant code motion. |
| 2245 if (FLAG_use_gvn) { | 2282 if (FLAG_use_gvn) { |
| 2246 HPhase phase("Global value numbering", graph()); | 2283 HPhase phase("Global value numbering", graph()); |
| (...skipping 3790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6037 } | 6074 } |
| 6038 } | 6075 } |
| 6039 | 6076 |
| 6040 #ifdef DEBUG | 6077 #ifdef DEBUG |
| 6041 if (graph_ != NULL) graph_->Verify(); | 6078 if (graph_ != NULL) graph_->Verify(); |
| 6042 if (allocator_ != NULL) allocator_->Verify(); | 6079 if (allocator_ != NULL) allocator_->Verify(); |
| 6043 #endif | 6080 #endif |
| 6044 } | 6081 } |
| 6045 | 6082 |
| 6046 } } // namespace v8::internal | 6083 } } // namespace v8::internal |
| OLD | NEW |