| 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 10 matching lines...) Expand all Loading... |
| 21 namespace dart { | 21 namespace dart { |
| 22 | 22 |
| 23 DEFINE_FLAG(bool, new_identity_spec, true, | 23 DEFINE_FLAG(bool, new_identity_spec, true, |
| 24 "Use new identity check rules for numbers."); | 24 "Use new identity check rules for numbers."); |
| 25 DEFINE_FLAG(bool, propagate_ic_data, true, | 25 DEFINE_FLAG(bool, propagate_ic_data, true, |
| 26 "Propagate IC data from unoptimized to optimized IC calls."); | 26 "Propagate IC data from unoptimized to optimized IC calls."); |
| 27 DECLARE_FLAG(bool, enable_type_checks); | 27 DECLARE_FLAG(bool, enable_type_checks); |
| 28 DECLARE_FLAG(bool, eliminate_type_checks); | 28 DECLARE_FLAG(bool, eliminate_type_checks); |
| 29 DECLARE_FLAG(int, max_polymorphic_checks); | 29 DECLARE_FLAG(int, max_polymorphic_checks); |
| 30 DECLARE_FLAG(bool, trace_optimization); | 30 DECLARE_FLAG(bool, trace_optimization); |
| 31 DECLARE_FLAG(bool, trace_constant_propagation); |
| 31 | 32 |
| 32 Definition::Definition() | 33 Definition::Definition() |
| 33 : range_(NULL), | 34 : range_(NULL), |
| 34 type_(NULL), | 35 type_(NULL), |
| 35 temp_index_(-1), | 36 temp_index_(-1), |
| 36 ssa_temp_index_(-1), | 37 ssa_temp_index_(-1), |
| 37 input_use_list_(NULL), | 38 input_use_list_(NULL), |
| 38 env_use_list_(NULL), | 39 env_use_list_(NULL), |
| 39 use_kind_(kValue), // Phis and parameters rely on this default. | 40 use_kind_(kValue), // Phis and parameters rely on this default. |
| 40 constant_value_(Object::ZoneHandle(ConstantPropagator::Unknown())) { | 41 constant_value_(Object::ZoneHandle(ConstantPropagator::Unknown())) { |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 UnuseAllInputs(); | 602 UnuseAllInputs(); |
| 602 } | 603 } |
| 603 set_previous(NULL); | 604 set_previous(NULL); |
| 604 set_next(NULL); | 605 set_next(NULL); |
| 605 } | 606 } |
| 606 | 607 |
| 607 | 608 |
| 608 BranchInstr::BranchInstr(ComparisonInstr* comparison, bool is_checked) | 609 BranchInstr::BranchInstr(ComparisonInstr* comparison, bool is_checked) |
| 609 : comparison_(comparison), | 610 : comparison_(comparison), |
| 610 is_checked_(is_checked), | 611 is_checked_(is_checked), |
| 611 constrained_type_(NULL) { | 612 constrained_type_(NULL), |
| 613 constant_target_(NULL) { |
| 612 for (intptr_t i = comparison->InputCount() - 1; i >= 0; --i) { | 614 for (intptr_t i = comparison->InputCount() - 1; i >= 0; --i) { |
| 613 comparison->InputAt(i)->set_instruction(this); | 615 comparison->InputAt(i)->set_instruction(this); |
| 614 } | 616 } |
| 615 } | 617 } |
| 616 | 618 |
| 617 | 619 |
| 618 void BranchInstr::RawSetInputAt(intptr_t i, Value* value) { | 620 void BranchInstr::RawSetInputAt(intptr_t i, Value* value) { |
| 619 comparison()->RawSetInputAt(i, value); | 621 comparison()->RawSetInputAt(i, value); |
| 620 } | 622 } |
| 621 | 623 |
| (...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1950 CanonicalizeMaxBoundary(&canonical_b)); | 1952 CanonicalizeMaxBoundary(&canonical_b)); |
| 1951 } | 1953 } |
| 1952 | 1954 |
| 1953 if (max.IsUnknown()) { | 1955 if (max.IsUnknown()) { |
| 1954 max = RangeBoundary::Min(Range::ConstantMax(value_range), | 1956 max = RangeBoundary::Min(Range::ConstantMax(value_range), |
| 1955 Range::ConstantMax(constraint())); | 1957 Range::ConstantMax(constraint())); |
| 1956 } | 1958 } |
| 1957 } | 1959 } |
| 1958 | 1960 |
| 1959 range_ = new Range(min, max); | 1961 range_ = new Range(min, max); |
| 1962 |
| 1963 // Mark branches that generate unsatisfiable constraints as constant. |
| 1964 if (target() != NULL && range_->IsUnsatisfiable()) { |
| 1965 BranchInstr* branch = |
| 1966 target()->PredecessorAt(0)->last_instruction()->AsBranch(); |
| 1967 if (target() == branch->true_successor()) { |
| 1968 // True unreachable. |
| 1969 if (FLAG_trace_constant_propagation) { |
| 1970 OS::Print("Range analysis: True unreachable (B%"Pd")\n", |
| 1971 branch->true_successor()->block_id()); |
| 1972 } |
| 1973 branch->set_constant_target(branch->false_successor()); |
| 1974 } else { |
| 1975 ASSERT(target() == branch->false_successor()); |
| 1976 // False unreachable. |
| 1977 if (FLAG_trace_constant_propagation) { |
| 1978 OS::Print("Range analysis: False unreachable (B%"Pd")\n", |
| 1979 branch->false_successor()->block_id()); |
| 1980 } |
| 1981 branch->set_constant_target(branch->true_successor()); |
| 1982 } |
| 1983 } |
| 1960 } | 1984 } |
| 1961 | 1985 |
| 1962 | 1986 |
| 1963 void LoadFieldInstr::InferRange() { | 1987 void LoadFieldInstr::InferRange() { |
| 1964 if ((range_ == NULL) && | 1988 if ((range_ == NULL) && |
| 1965 ((recognized_kind() == MethodRecognizer::kObjectArrayLength) || | 1989 ((recognized_kind() == MethodRecognizer::kObjectArrayLength) || |
| 1966 (recognized_kind() == MethodRecognizer::kImmutableArrayLength))) { | 1990 (recognized_kind() == MethodRecognizer::kImmutableArrayLength))) { |
| 1967 range_ = new Range(RangeBoundary::FromConstant(0), | 1991 range_ = new Range(RangeBoundary::FromConstant(0), |
| 1968 RangeBoundary::FromConstant(Array::kMaxElements)); | 1992 RangeBoundary::FromConstant(Array::kMaxElements)); |
| 1969 return; | 1993 return; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2185 | 2209 |
| 2186 | 2210 |
| 2187 // Inclusive. | 2211 // Inclusive. |
| 2188 bool Range::IsWithin(intptr_t min_int, intptr_t max_int) const { | 2212 bool Range::IsWithin(intptr_t min_int, intptr_t max_int) const { |
| 2189 if (min().LowerBound().value() < min_int) return false; | 2213 if (min().LowerBound().value() < min_int) return false; |
| 2190 if (max().UpperBound().value() > max_int) return false; | 2214 if (max().UpperBound().value() > max_int) return false; |
| 2191 return true; | 2215 return true; |
| 2192 } | 2216 } |
| 2193 | 2217 |
| 2194 | 2218 |
| 2219 bool Range::IsUnsatisfiable() const { |
| 2220 // Constant case: For example [0, -1]. |
| 2221 if (Range::ConstantMin(this).value() > Range::ConstantMax(this).value()) { |
| 2222 return true; |
| 2223 } |
| 2224 // Symbol case: For example [v+1, v]. |
| 2225 if (DependOnSameSymbol(min(), max()) && min().offset() > max().offset()) { |
| 2226 return true; |
| 2227 } |
| 2228 return false; |
| 2229 } |
| 2230 |
| 2231 |
| 2195 bool CheckArrayBoundInstr::IsFixedLengthArrayType(intptr_t cid) { | 2232 bool CheckArrayBoundInstr::IsFixedLengthArrayType(intptr_t cid) { |
| 2196 return LoadFieldInstr::IsFixedLengthArrayCid(cid); | 2233 return LoadFieldInstr::IsFixedLengthArrayCid(cid); |
| 2197 } | 2234 } |
| 2198 | 2235 |
| 2199 | 2236 |
| 2200 bool CheckArrayBoundInstr::IsRedundant(RangeBoundary length) { | 2237 bool CheckArrayBoundInstr::IsRedundant(RangeBoundary length) { |
| 2201 // Check that array has an immutable length. | 2238 // Check that array has an immutable length. |
| 2202 if (!IsFixedLengthArrayType(array_type())) { | 2239 if (!IsFixedLengthArrayType(array_type())) { |
| 2203 return false; | 2240 return false; |
| 2204 } | 2241 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2340 default: | 2377 default: |
| 2341 UNREACHABLE(); | 2378 UNREACHABLE(); |
| 2342 } | 2379 } |
| 2343 return kPowRuntimeEntry; | 2380 return kPowRuntimeEntry; |
| 2344 } | 2381 } |
| 2345 | 2382 |
| 2346 | 2383 |
| 2347 #undef __ | 2384 #undef __ |
| 2348 | 2385 |
| 2349 } // namespace dart | 2386 } // namespace dart |
| OLD | NEW |