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/bootstrap.h" | 8 #include "vm/bootstrap.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/constant_propagator.h" | 10 #include "vm/constant_propagator.h" |
(...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 // specialized instructions that use this value under this assumption. | 1728 // specialized instructions that use this value under this assumption. |
1729 return Integer::null(); | 1729 return Integer::null(); |
1730 } | 1730 } |
1731 result ^= result.CheckAndCanonicalize(NULL); | 1731 result ^= result.CheckAndCanonicalize(NULL); |
1732 } | 1732 } |
1733 | 1733 |
1734 return result.raw(); | 1734 return result.raw(); |
1735 } | 1735 } |
1736 | 1736 |
1737 | 1737 |
| 1738 Definition* BinaryIntegerOpInstr::CreateConstantResult(FlowGraph* flow_graph, |
| 1739 const Integer& result) { |
| 1740 Definition* result_defn = flow_graph->GetConstant(result); |
| 1741 if (representation() != kTagged) { |
| 1742 result_defn = UnboxInstr::Create(representation(), |
| 1743 new Value(result_defn), |
| 1744 GetDeoptId()); |
| 1745 flow_graph->InsertBefore(this, result_defn, env(), FlowGraph::kValue); |
| 1746 } |
| 1747 return result_defn; |
| 1748 } |
| 1749 |
| 1750 |
1738 Definition* BinaryIntegerOpInstr::Canonicalize(FlowGraph* flow_graph) { | 1751 Definition* BinaryIntegerOpInstr::Canonicalize(FlowGraph* flow_graph) { |
1739 // If both operands are constants evaluate this expression. Might | 1752 // If both operands are constants evaluate this expression. Might |
1740 // occur due to load forwarding after constant propagation pass | 1753 // occur due to load forwarding after constant propagation pass |
1741 // have already been run. | 1754 // have already been run. |
1742 if (left()->BindsToConstant() && | 1755 if (left()->BindsToConstant() && |
1743 left()->BoundConstant().IsInteger() && | 1756 left()->BoundConstant().IsInteger() && |
1744 right()->BindsToConstant() && | 1757 right()->BindsToConstant() && |
1745 right()->BoundConstant().IsInteger()) { | 1758 right()->BoundConstant().IsInteger()) { |
1746 const Integer& result = Integer::Handle( | 1759 const Integer& result = Integer::Handle( |
1747 Evaluate(Integer::Cast(left()->BoundConstant()), | 1760 Evaluate(Integer::Cast(left()->BoundConstant()), |
1748 Integer::Cast(right()->BoundConstant()))); | 1761 Integer::Cast(right()->BoundConstant()))); |
1749 if (!result.IsNull()) { | 1762 if (!result.IsNull()) { |
1750 return flow_graph->GetConstant(result); | 1763 return CreateConstantResult(flow_graph, result); |
1751 } | 1764 } |
1752 } | 1765 } |
1753 | 1766 |
1754 if (left()->BindsToConstant() && | 1767 if (left()->BindsToConstant() && |
1755 !right()->BindsToConstant() && | 1768 !right()->BindsToConstant() && |
1756 IsCommutative(op_kind())) { | 1769 IsCommutative(op_kind())) { |
1757 Value* l = left(); | 1770 Value* l = left(); |
1758 Value* r = right(); | 1771 Value* r = right(); |
1759 SetInputAt(0, r); | 1772 SetInputAt(0, r); |
1760 SetInputAt(1, l); | 1773 SetInputAt(1, l); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1865 } | 1878 } |
1866 break; | 1879 break; |
1867 | 1880 |
1868 case Token::kSHR: | 1881 case Token::kSHR: |
1869 if (rhs == 0) { | 1882 if (rhs == 0) { |
1870 return left()->definition(); | 1883 return left()->definition(); |
1871 } else if (rhs < 0) { | 1884 } else if (rhs < 0) { |
1872 DeoptimizeInstr* deopt = | 1885 DeoptimizeInstr* deopt = |
1873 new DeoptimizeInstr(ICData::kDeoptBinarySmiOp, GetDeoptId()); | 1886 new DeoptimizeInstr(ICData::kDeoptBinarySmiOp, GetDeoptId()); |
1874 flow_graph->InsertBefore(this, deopt, env(), FlowGraph::kEffect); | 1887 flow_graph->InsertBefore(this, deopt, env(), FlowGraph::kEffect); |
1875 return flow_graph->GetConstant(Smi::Handle(Smi::New(0))); | 1888 return CreateConstantResult(flow_graph, Integer::Handle(Smi::New(0))); |
1876 } | 1889 } |
1877 break; | 1890 break; |
1878 | 1891 |
1879 case Token::kSHL: { | 1892 case Token::kSHL: { |
1880 const intptr_t kMaxShift = RepresentationBits(representation()) - 1; | 1893 const intptr_t kMaxShift = RepresentationBits(representation()) - 1; |
1881 if (rhs == 0) { | 1894 if (rhs == 0) { |
1882 return left()->definition(); | 1895 return left()->definition(); |
1883 } else if ((rhs < 0) || (rhs >= kMaxShift)) { | 1896 } else if ((rhs < 0) || (rhs >= kMaxShift)) { |
1884 if ((rhs < 0) || !is_truncating()) { | 1897 if ((rhs < 0) || !is_truncating()) { |
1885 DeoptimizeInstr* deopt = | 1898 DeoptimizeInstr* deopt = |
1886 new DeoptimizeInstr(ICData::kDeoptBinarySmiOp, GetDeoptId()); | 1899 new DeoptimizeInstr(ICData::kDeoptBinarySmiOp, GetDeoptId()); |
1887 flow_graph->InsertBefore(this, deopt, env(), FlowGraph::kEffect); | 1900 flow_graph->InsertBefore(this, deopt, env(), FlowGraph::kEffect); |
1888 } | 1901 } |
1889 return flow_graph->GetConstant(Smi::Handle(Smi::New(0))); | 1902 return CreateConstantResult(flow_graph, Integer::Handle(Smi::New(0))); |
1890 } | 1903 } |
1891 break; | 1904 break; |
1892 } | 1905 } |
1893 | 1906 |
1894 default: | 1907 default: |
1895 break; | 1908 break; |
1896 } | 1909 } |
1897 | 1910 |
1898 return this; | 1911 return this; |
1899 } | 1912 } |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 return this; | 2208 return this; |
2196 } | 2209 } |
2197 | 2210 |
2198 | 2211 |
2199 Definition* UnboxIntegerInstr::Canonicalize(FlowGraph* flow_graph) { | 2212 Definition* UnboxIntegerInstr::Canonicalize(FlowGraph* flow_graph) { |
2200 if (!HasUses() && !CanDeoptimize()) return NULL; | 2213 if (!HasUses() && !CanDeoptimize()) return NULL; |
2201 | 2214 |
2202 // Fold away UnboxInteger<rep_to>(BoxInteger<rep_from>(v)). | 2215 // Fold away UnboxInteger<rep_to>(BoxInteger<rep_from>(v)). |
2203 BoxIntegerInstr* box_defn = value()->definition()->AsBoxInteger(); | 2216 BoxIntegerInstr* box_defn = value()->definition()->AsBoxInteger(); |
2204 if (box_defn != NULL) { | 2217 if (box_defn != NULL) { |
2205 if (box_defn->value()->definition()->representation() == representation()) { | 2218 Representation from_representation = |
| 2219 box_defn->value()->definition()->representation(); |
| 2220 if (from_representation == representation()) { |
2206 return box_defn->value()->definition(); | 2221 return box_defn->value()->definition(); |
2207 } else { | 2222 } else { |
2208 UnboxedIntConverterInstr* converter = new UnboxedIntConverterInstr( | 2223 UnboxedIntConverterInstr* converter = new UnboxedIntConverterInstr( |
2209 box_defn->value()->definition()->representation(), | 2224 from_representation, |
2210 representation(), | 2225 representation(), |
2211 box_defn->value()->CopyWithType(), | 2226 box_defn->value()->CopyWithType(), |
2212 (representation() == kUnboxedInt32) ? | 2227 (representation() == kUnboxedInt32) ? |
2213 GetDeoptId() : Thread::kNoDeoptId); | 2228 GetDeoptId() : Thread::kNoDeoptId); |
2214 // TODO(vegorov): marking resulting converter as truncating when | 2229 // TODO(vegorov): marking resulting converter as truncating when |
2215 // unboxing can't deoptimize is a workaround for the missing | 2230 // unboxing can't deoptimize is a workaround for the missing |
2216 // deoptimization environment when we insert converter after | 2231 // deoptimization environment when we insert converter after |
2217 // EliminateEnvironments and there is a mismatch between predicates | 2232 // EliminateEnvironments and there is a mismatch between predicates |
2218 // UnboxIntConverterInstr::CanDeoptimize and UnboxInt32::CanDeoptimize. | 2233 // UnboxIntConverterInstr::CanDeoptimize and UnboxInt32::CanDeoptimize. |
2219 if ((representation() == kUnboxedInt32) && | 2234 if ((representation() == kUnboxedInt32) && |
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3678 set_native_c_function(native_function); | 3693 set_native_c_function(native_function); |
3679 function().SetIsNativeAutoSetupScope(auto_setup_scope); | 3694 function().SetIsNativeAutoSetupScope(auto_setup_scope); |
3680 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); | 3695 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); |
3681 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver); | 3696 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver); |
3682 set_is_bootstrap_native(is_bootstrap_native); | 3697 set_is_bootstrap_native(is_bootstrap_native); |
3683 } | 3698 } |
3684 | 3699 |
3685 #undef __ | 3700 #undef __ |
3686 | 3701 |
3687 } // namespace dart | 3702 } // namespace dart |
OLD | NEW |