| 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 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1834 } else { | 1834 } else { |
| 1835 next = HInstruction::cast(use_value); | 1835 next = HInstruction::cast(use_value); |
| 1836 } | 1836 } |
| 1837 | 1837 |
| 1838 // For constants we try to make the representation change at compile | 1838 // For constants we try to make the representation change at compile |
| 1839 // time. When a representation change is not possible without loss of | 1839 // time. When a representation change is not possible without loss of |
| 1840 // information we treat constants like normal instructions and insert the | 1840 // information we treat constants like normal instructions and insert the |
| 1841 // change instructions for them. | 1841 // change instructions for them. |
| 1842 HInstruction* new_value = NULL; | 1842 HInstruction* new_value = NULL; |
| 1843 bool is_truncating = use_value->CheckFlag(HValue::kTruncatingToInt32); | 1843 bool is_truncating = use_value->CheckFlag(HValue::kTruncatingToInt32); |
| 1844 bool deoptimize_on_undefined = |
| 1845 use_value->CheckFlag(HValue::kDeoptimizeOnUndefined); |
| 1844 if (value->IsConstant()) { | 1846 if (value->IsConstant()) { |
| 1845 HConstant* constant = HConstant::cast(value); | 1847 HConstant* constant = HConstant::cast(value); |
| 1846 // Try to create a new copy of the constant with the new representation. | 1848 // Try to create a new copy of the constant with the new representation. |
| 1847 new_value = is_truncating | 1849 new_value = is_truncating |
| 1848 ? constant->CopyToTruncatedInt32() | 1850 ? constant->CopyToTruncatedInt32() |
| 1849 : constant->CopyToRepresentation(to); | 1851 : constant->CopyToRepresentation(to); |
| 1850 } | 1852 } |
| 1851 | 1853 |
| 1852 if (new_value == NULL) { | 1854 if (new_value == NULL) { |
| 1853 new_value = | 1855 new_value = new(zone()) HChange(value, value->representation(), to, |
| 1854 new(zone()) HChange(value, value->representation(), to, is_truncating); | 1856 is_truncating, deoptimize_on_undefined); |
| 1855 } | 1857 } |
| 1856 | 1858 |
| 1857 new_value->InsertBefore(next); | 1859 new_value->InsertBefore(next); |
| 1858 use_value->SetOperandAt(use_index, new_value); | 1860 use_value->SetOperandAt(use_index, new_value); |
| 1859 } | 1861 } |
| 1860 | 1862 |
| 1861 | 1863 |
| 1862 void HGraph::InsertRepresentationChangesForValue(HValue* value) { | 1864 void HGraph::InsertRepresentationChangesForValue(HValue* value) { |
| 1863 Representation r = value->representation(); | 1865 Representation r = value->representation(); |
| 1864 if (r.IsNone()) return; | 1866 if (r.IsNone()) return; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1926 // Process normal instructions. | 1928 // Process normal instructions. |
| 1927 HInstruction* current = blocks_[i]->first(); | 1929 HInstruction* current = blocks_[i]->first(); |
| 1928 while (current != NULL) { | 1930 while (current != NULL) { |
| 1929 InsertRepresentationChangesForValue(current); | 1931 InsertRepresentationChangesForValue(current); |
| 1930 current = current->next(); | 1932 current = current->next(); |
| 1931 } | 1933 } |
| 1932 } | 1934 } |
| 1933 } | 1935 } |
| 1934 | 1936 |
| 1935 | 1937 |
| 1938 void HGraph::RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi* phi) { |
| 1939 if (phi->CheckFlag(HValue::kDeoptimizeOnUndefined)) return; |
| 1940 phi->SetFlag(HValue::kDeoptimizeOnUndefined); |
| 1941 for (int i = 0; i < phi->OperandCount(); ++i) { |
| 1942 HValue* input = phi->OperandAt(i); |
| 1943 if (input->IsPhi()) { |
| 1944 RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi::cast(input)); |
| 1945 } |
| 1946 } |
| 1947 } |
| 1948 |
| 1949 |
| 1950 void HGraph::MarkDeoptimizeOnUndefined() { |
| 1951 HPhase phase("MarkDeoptimizeOnUndefined", this); |
| 1952 // Compute DeoptimizeOnUndefined flag for phis. |
| 1953 // Any phi that can reach a use with DeoptimizeOnUndefined set must |
| 1954 // have DeoptimizeOnUndefined set. Currently only HCompare, with |
| 1955 // double input representation, has this flag set. |
| 1956 // The flag is used by HChange tagged->double, which must deoptimize |
| 1957 // if one of its uses has this flag set. |
| 1958 for (int i = 0; i < phi_list()->length(); i++) { |
| 1959 HPhi* phi = phi_list()->at(i); |
| 1960 if (phi->representation().IsDouble()) { |
| 1961 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { |
| 1962 if (it.value()->CheckFlag(HValue::kDeoptimizeOnUndefined)) { |
| 1963 RecursivelyMarkPhiDeoptimizeOnUndefined(phi); |
| 1964 break; |
| 1965 } |
| 1966 } |
| 1967 } |
| 1968 } |
| 1969 } |
| 1970 |
| 1971 |
| 1936 void HGraph::ComputeMinusZeroChecks() { | 1972 void HGraph::ComputeMinusZeroChecks() { |
| 1937 BitVector visited(GetMaximumValueID()); | 1973 BitVector visited(GetMaximumValueID()); |
| 1938 for (int i = 0; i < blocks_.length(); ++i) { | 1974 for (int i = 0; i < blocks_.length(); ++i) { |
| 1939 for (HInstruction* current = blocks_[i]->first(); | 1975 for (HInstruction* current = blocks_[i]->first(); |
| 1940 current != NULL; | 1976 current != NULL; |
| 1941 current = current->next()) { | 1977 current = current->next()) { |
| 1942 if (current->IsChange()) { | 1978 if (current->IsChange()) { |
| 1943 HChange* change = HChange::cast(current); | 1979 HChange* change = HChange::cast(current); |
| 1944 // Propagate flags for negative zero checks upwards from conversions | 1980 // Propagate flags for negative zero checks upwards from conversions |
| 1945 // int32-to-tagged and int32-to-double. | 1981 // int32-to-tagged and int32-to-double. |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2232 HInferRepresentation rep(graph()); | 2268 HInferRepresentation rep(graph()); |
| 2233 rep.Analyze(); | 2269 rep.Analyze(); |
| 2234 | 2270 |
| 2235 if (FLAG_use_range) { | 2271 if (FLAG_use_range) { |
| 2236 HRangeAnalysis rangeAnalysis(graph()); | 2272 HRangeAnalysis rangeAnalysis(graph()); |
| 2237 rangeAnalysis.Analyze(); | 2273 rangeAnalysis.Analyze(); |
| 2238 } | 2274 } |
| 2239 | 2275 |
| 2240 graph()->InitializeInferredTypes(); | 2276 graph()->InitializeInferredTypes(); |
| 2241 graph()->Canonicalize(); | 2277 graph()->Canonicalize(); |
| 2278 graph()->MarkDeoptimizeOnUndefined(); |
| 2242 graph()->InsertRepresentationChanges(); | 2279 graph()->InsertRepresentationChanges(); |
| 2243 graph()->ComputeMinusZeroChecks(); | 2280 graph()->ComputeMinusZeroChecks(); |
| 2244 | 2281 |
| 2245 // Eliminate redundant stack checks on backwards branches. | 2282 // Eliminate redundant stack checks on backwards branches. |
| 2246 HStackCheckEliminator sce(graph()); | 2283 HStackCheckEliminator sce(graph()); |
| 2247 sce.Process(); | 2284 sce.Process(); |
| 2248 | 2285 |
| 2249 // Perform common subexpression elimination and loop-invariant code motion. | 2286 // Perform common subexpression elimination and loop-invariant code motion. |
| 2250 if (FLAG_use_gvn) { | 2287 if (FLAG_use_gvn) { |
| 2251 HPhase phase("Global value numbering", graph()); | 2288 HPhase phase("Global value numbering", graph()); |
| (...skipping 4006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6258 } | 6295 } |
| 6259 } | 6296 } |
| 6260 | 6297 |
| 6261 #ifdef DEBUG | 6298 #ifdef DEBUG |
| 6262 if (graph_ != NULL) graph_->Verify(); | 6299 if (graph_ != NULL) graph_->Verify(); |
| 6263 if (allocator_ != NULL) allocator_->Verify(); | 6300 if (allocator_ != NULL) allocator_->Verify(); |
| 6264 #endif | 6301 #endif |
| 6265 } | 6302 } |
| 6266 | 6303 |
| 6267 } } // namespace v8::internal | 6304 } } // namespace v8::internal |
| OLD | NEW |