Chromium Code Reviews| 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 1646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1657 Instruction* Instruction::Canonicalize(FlowGraphOptimizer* optimizer) { | 1657 Instruction* Instruction::Canonicalize(FlowGraphOptimizer* optimizer) { |
| 1658 return this; | 1658 return this; |
| 1659 } | 1659 } |
| 1660 | 1660 |
| 1661 | 1661 |
| 1662 Definition* Definition::Canonicalize(FlowGraphOptimizer* optimizer) { | 1662 Definition* Definition::Canonicalize(FlowGraphOptimizer* optimizer) { |
| 1663 return this; | 1663 return this; |
| 1664 } | 1664 } |
| 1665 | 1665 |
| 1666 | 1666 |
| 1667 bool LoadFieldInstr::IsImmutableLengthLoad() const { | |
| 1668 switch (recognized_kind()) { | |
| 1669 case MethodRecognizer::kObjectArrayLength: | |
| 1670 case MethodRecognizer::kImmutableArrayLength: | |
| 1671 case MethodRecognizer::kByteArrayBaseLength: | |
| 1672 case MethodRecognizer::kStringBaseLength: | |
|
srdjan
2013/02/01 19:01:28
Why not add the byte arrays as well?
Florian Schneider
2013/02/06 13:08:19
Byte arrays are handled by kByteArrayBaseLength ab
| |
| 1673 return true; | |
| 1674 default: | |
| 1675 return false; | |
| 1676 } | |
| 1677 } | |
| 1678 | |
| 1679 | |
| 1680 MethodRecognizer::Kind LoadFieldInstr::RecognizedKindFromArrayCid( | |
| 1681 intptr_t cid) { | |
| 1682 switch (cid) { | |
| 1683 case kArrayCid: | |
| 1684 return MethodRecognizer::kObjectArrayLength; | |
| 1685 case kImmutableArrayCid: | |
| 1686 return MethodRecognizer::kImmutableArrayLength; | |
| 1687 case kGrowableObjectArrayCid: | |
| 1688 return MethodRecognizer::kGrowableArrayLength; | |
| 1689 case kInt8ArrayCid: | |
| 1690 case kUint8ArrayCid: | |
| 1691 case kUint8ClampedArrayCid: | |
| 1692 case kExternalUint8ArrayCid: | |
| 1693 case kInt16ArrayCid: | |
| 1694 case kUint16ArrayCid: | |
| 1695 case kInt32ArrayCid: | |
| 1696 case kUint32ArrayCid: | |
| 1697 case kInt64ArrayCid: | |
| 1698 case kUint64ArrayCid: | |
| 1699 case kFloat32ArrayCid: | |
| 1700 case kFloat64ArrayCid: | |
| 1701 return MethodRecognizer::kByteArrayBaseLength; | |
| 1702 default: | |
| 1703 UNREACHABLE(); | |
| 1704 return MethodRecognizer::kUnknown; | |
| 1705 } | |
| 1706 } | |
| 1707 | |
| 1708 | |
| 1709 Definition* LoadFieldInstr::Canonicalize(FlowGraphOptimizer* optimizer) { | |
| 1710 if (!IsImmutableLengthLoad()) return this; | |
| 1711 | |
| 1712 // For fixed length arrays if the array is the result of a known constructor | |
| 1713 // call we can replace the length load with the length argument passed to | |
| 1714 // the constructor. | |
| 1715 StaticCallInstr* call = value()->definition()->AsStaticCall(); | |
| 1716 if (call != NULL && | |
| 1717 call->is_known_constructor() && | |
| 1718 call->ResultCid() == kArrayCid) { | |
| 1719 return call->ArgumentAt(1)->value()->definition(); | |
| 1720 } | |
| 1721 return this; | |
| 1722 } | |
| 1723 | |
| 1724 | |
| 1667 Definition* AssertBooleanInstr::Canonicalize(FlowGraphOptimizer* optimizer) { | 1725 Definition* AssertBooleanInstr::Canonicalize(FlowGraphOptimizer* optimizer) { |
| 1668 const intptr_t value_cid = value()->ResultCid(); | 1726 const intptr_t value_cid = value()->ResultCid(); |
| 1669 return (value_cid == kBoolCid) ? value()->definition() : this; | 1727 return (value_cid == kBoolCid) ? value()->definition() : this; |
| 1670 } | 1728 } |
| 1671 | 1729 |
| 1672 | 1730 |
| 1673 Definition* AssertAssignableInstr::Canonicalize(FlowGraphOptimizer* optimizer) { | 1731 Definition* AssertAssignableInstr::Canonicalize(FlowGraphOptimizer* optimizer) { |
| 1674 // (1) Replace the assert with its input if the input has a known compatible | 1732 // (1) Replace the assert with its input if the input has a known compatible |
| 1675 // class-id. The class-ids handled here are those that are known to be | 1733 // class-id. The class-ids handled here are those that are known to be |
| 1676 // results of IL instructions. | 1734 // results of IL instructions. |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2504 | 2562 |
| 2505 *result = RangeBoundary::FromDefinition(b.symbol(), offset); | 2563 *result = RangeBoundary::FromDefinition(b.symbol(), offset); |
| 2506 return true; | 2564 return true; |
| 2507 } | 2565 } |
| 2508 return false; | 2566 return false; |
| 2509 } | 2567 } |
| 2510 | 2568 |
| 2511 | 2569 |
| 2512 static bool IsArrayLength(Definition* defn) { | 2570 static bool IsArrayLength(Definition* defn) { |
| 2513 LoadFieldInstr* load = defn->AsLoadField(); | 2571 LoadFieldInstr* load = defn->AsLoadField(); |
| 2514 return (load != NULL) && | 2572 return (load != NULL) && load->IsImmutableLengthLoad(); |
| 2515 ((load->recognized_kind() == MethodRecognizer::kObjectArrayLength) || | |
| 2516 (load->recognized_kind() == MethodRecognizer::kImmutableArrayLength)); | |
| 2517 } | 2573 } |
| 2518 | 2574 |
| 2519 | 2575 |
| 2520 void BinarySmiOpInstr::InferRange() { | 2576 void BinarySmiOpInstr::InferRange() { |
| 2521 // TODO(vegorov): canonicalize BinarySmiOp to always have constant on the | 2577 // TODO(vegorov): canonicalize BinarySmiOp to always have constant on the |
| 2522 // right and a non-constant on the left. | 2578 // right and a non-constant on the left. |
| 2523 Definition* left_defn = left()->definition(); | 2579 Definition* left_defn = left()->definition(); |
| 2524 | 2580 |
| 2525 Range* left_range = left_defn->range(); | 2581 Range* left_range = left_defn->range(); |
| 2526 Range* right_range = right()->definition()->range(); | 2582 Range* right_range = right()->definition()->range(); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2769 default: | 2825 default: |
| 2770 UNREACHABLE(); | 2826 UNREACHABLE(); |
| 2771 } | 2827 } |
| 2772 return kPowRuntimeEntry; | 2828 return kPowRuntimeEntry; |
| 2773 } | 2829 } |
| 2774 | 2830 |
| 2775 | 2831 |
| 2776 #undef __ | 2832 #undef __ |
| 2777 | 2833 |
| 2778 } // namespace dart | 2834 } // namespace dart |
| OLD | NEW |