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 1633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 case kUnboxedUint32: // Only truncating Uint32 arithmetic is supported. | 1644 case kUnboxedUint32: // Only truncating Uint32 arithmetic is supported. |
1645 default: | 1645 default: |
1646 UNREACHABLE(); | 1646 UNREACHABLE(); |
1647 } | 1647 } |
1648 | 1648 |
1649 return false; | 1649 return false; |
1650 } | 1650 } |
1651 | 1651 |
1652 | 1652 |
1653 RawInteger* UnaryIntegerOpInstr::Evaluate(const Integer& value) const { | 1653 RawInteger* UnaryIntegerOpInstr::Evaluate(const Integer& value) const { |
1654 Thread* thread = Thread::Current(); | 1654 Integer& result = Integer::Handle(); |
1655 Zone* zone = thread->zone(); | |
1656 Integer& result = Integer::Handle(zone); | |
1657 | 1655 |
1658 switch (op_kind()) { | 1656 switch (op_kind()) { |
1659 case Token::kNEGATE: | 1657 case Token::kNEGATE: |
1660 result = value.ArithmeticOp(Token::kMUL, | 1658 result = value.ArithmeticOp(Token::kMUL, |
1661 Smi::Handle(zone, Smi::New(-1)), | 1659 Smi::Handle(Smi::New(-1)), |
1662 Heap::kOld); | 1660 Heap::kOld); |
1663 break; | 1661 break; |
1664 | 1662 |
1665 case Token::kBIT_NOT: | 1663 case Token::kBIT_NOT: |
1666 if (value.IsSmi()) { | 1664 if (value.IsSmi()) { |
1667 result = Integer::New(~Smi::Cast(value).Value()); | 1665 result = Integer::New(~Smi::Cast(value).Value()); |
1668 } else if (value.IsMint()) { | 1666 } else if (value.IsMint()) { |
1669 result = Integer::New(~Mint::Cast(value).value()); | 1667 result = Integer::New(~Mint::Cast(value).value()); |
1670 } | 1668 } |
1671 break; | 1669 break; |
1672 | 1670 |
1673 default: | 1671 default: |
1674 UNREACHABLE(); | 1672 UNREACHABLE(); |
1675 } | 1673 } |
1676 | 1674 |
1677 if (!result.IsNull()) { | 1675 if (!result.IsNull()) { |
1678 if (!IsRepresentable(result, representation())) { | 1676 if (!IsRepresentable(result, representation())) { |
1679 // If this operation is not truncating it would deoptimize on overflow. | 1677 // If this operation is not truncating it would deoptimize on overflow. |
1680 // Check that we match this behavior and don't produce a value that is | 1678 // Check that we match this behavior and don't produce a value that is |
1681 // larger than something this operation can produce. We could have | 1679 // larger than something this operation can produce. We could have |
1682 // specialized instructions that use this value under this assumption. | 1680 // specialized instructions that use this value under this assumption. |
1683 return Integer::null(); | 1681 return Integer::null(); |
1684 } | 1682 } |
1685 result ^= result.CheckAndCanonicalize(thread, NULL); | 1683 result ^= result.CheckAndCanonicalize(NULL); |
1686 } | 1684 } |
1687 | 1685 |
1688 return result.raw(); | 1686 return result.raw(); |
1689 } | 1687 } |
1690 | 1688 |
1691 | 1689 |
1692 RawInteger* BinaryIntegerOpInstr::Evaluate(const Integer& left, | 1690 RawInteger* BinaryIntegerOpInstr::Evaluate(const Integer& left, |
1693 const Integer& right) const { | 1691 const Integer& right) const { |
1694 Thread* thread = Thread::Current(); | 1692 Integer& result = Integer::Handle(); |
1695 Zone* zone = thread->zone(); | |
1696 Integer& result = Integer::Handle(zone); | |
1697 | 1693 |
1698 switch (op_kind()) { | 1694 switch (op_kind()) { |
1699 case Token::kTRUNCDIV: | 1695 case Token::kTRUNCDIV: |
1700 case Token::kMOD: | 1696 case Token::kMOD: |
1701 // Check right value for zero. | 1697 // Check right value for zero. |
1702 if (right.IsSmi() && right.AsInt64Value() == 0) { | 1698 if (right.IsSmi() && right.AsInt64Value() == 0) { |
1703 break; // Will throw. | 1699 break; // Will throw. |
1704 } | 1700 } |
1705 // Fall through. | 1701 // Fall through. |
1706 case Token::kADD: | 1702 case Token::kADD: |
(...skipping 28 matching lines...) Expand all Loading... |
1735 truncated &= RepresentationMask(representation()); | 1731 truncated &= RepresentationMask(representation()); |
1736 result = Integer::New(truncated); | 1732 result = Integer::New(truncated); |
1737 ASSERT(IsRepresentable(result, representation())); | 1733 ASSERT(IsRepresentable(result, representation())); |
1738 } else if (!IsRepresentable(result, representation())) { | 1734 } else if (!IsRepresentable(result, representation())) { |
1739 // If this operation is not truncating it would deoptimize on overflow. | 1735 // If this operation is not truncating it would deoptimize on overflow. |
1740 // Check that we match this behavior and don't produce a value that is | 1736 // Check that we match this behavior and don't produce a value that is |
1741 // larger than something this operation can produce. We could have | 1737 // larger than something this operation can produce. We could have |
1742 // specialized instructions that use this value under this assumption. | 1738 // specialized instructions that use this value under this assumption. |
1743 return Integer::null(); | 1739 return Integer::null(); |
1744 } | 1740 } |
1745 result ^= result.CheckAndCanonicalize(thread, NULL); | 1741 result ^= result.CheckAndCanonicalize(NULL); |
1746 } | 1742 } |
1747 | 1743 |
1748 return result.raw(); | 1744 return result.raw(); |
1749 } | 1745 } |
1750 | 1746 |
1751 | 1747 |
1752 Definition* BinaryIntegerOpInstr::CreateConstantResult(FlowGraph* flow_graph, | 1748 Definition* BinaryIntegerOpInstr::CreateConstantResult(FlowGraph* flow_graph, |
1753 const Integer& result) { | 1749 const Integer& result) { |
1754 Definition* result_defn = flow_graph->GetConstant(result); | 1750 Definition* result_defn = flow_graph->GetConstant(result); |
1755 if (representation() != kTagged) { | 1751 if (representation() != kTagged) { |
(...skipping 2001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3757 set_native_c_function(native_function); | 3753 set_native_c_function(native_function); |
3758 function().SetIsNativeAutoSetupScope(auto_setup_scope); | 3754 function().SetIsNativeAutoSetupScope(auto_setup_scope); |
3759 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); | 3755 Dart_NativeEntryResolver resolver = library.native_entry_resolver(); |
3760 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver); | 3756 bool is_bootstrap_native = Bootstrap::IsBootstapResolver(resolver); |
3761 set_is_bootstrap_native(is_bootstrap_native); | 3757 set_is_bootstrap_native(is_bootstrap_native); |
3762 } | 3758 } |
3763 | 3759 |
3764 #undef __ | 3760 #undef __ |
3765 | 3761 |
3766 } // namespace dart | 3762 } // namespace dart |
OLD | NEW |