| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 interface HVisitor<R> { | 5 interface HVisitor<R> { |
| 6 R visitAdd(HAdd node); | 6 R visitAdd(HAdd node); |
| 7 R visitBitAnd(HBitAnd node); | 7 R visitBitAnd(HBitAnd node); |
| 8 R visitBitNot(HBitNot node); | 8 R visitBitNot(HBitNot node); |
| 9 R visitBitOr(HBitOr node); | 9 R visitBitOr(HBitOr node); |
| 10 R visitBitXor(HBitXor node); | 10 R visitBitXor(HBitXor node); |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 if (flag === BOOLEAN.flag) return BOOLEAN; | 750 if (flag === BOOLEAN.flag) return BOOLEAN; |
| 751 if (flag === INTEGER.flag) return INTEGER; | 751 if (flag === INTEGER.flag) return INTEGER; |
| 752 if (flag === DOUBLE.flag) return DOUBLE; | 752 if (flag === DOUBLE.flag) return DOUBLE; |
| 753 if (flag === STRING.flag) return STRING; | 753 if (flag === STRING.flag) return STRING; |
| 754 if (flag === ARRAY.flag) return ARRAY; | 754 if (flag === ARRAY.flag) return ARRAY; |
| 755 if (flag === NUMBER.flag) return NUMBER; | 755 if (flag === NUMBER.flag) return NUMBER; |
| 756 if (flag === STRING_OR_ARRAY.flag) return STRING_OR_ARRAY; | 756 if (flag === STRING_OR_ARRAY.flag) return STRING_OR_ARRAY; |
| 757 assert(false); | 757 assert(false); |
| 758 } | 758 } |
| 759 | 759 |
| 760 String toString() { |
| 761 if (isConflicting()) return 'conflicting'; |
| 762 if (isUnknown()) return 'unknown'; |
| 763 if (isBoolean()) return 'boolean'; |
| 764 if (isInteger()) return 'integer'; |
| 765 if (isDouble()) return 'double'; |
| 766 if (isString()) return 'string'; |
| 767 if (isArray()) return 'array'; |
| 768 if (isNumber()) return 'number'; |
| 769 if (isStringOrArray()) return 'string or array'; |
| 770 unreachable(); |
| 771 } |
| 772 |
| 760 HType combine(HType other) { | 773 HType combine(HType other) { |
| 761 if (isUnknown()) return other; | 774 if (isUnknown()) return other; |
| 762 if (other.isUnknown()) return this; | 775 if (other.isUnknown()) return this; |
| 763 return getTypeFromFlag(this.flag & other.flag); | 776 return getTypeFromFlag(this.flag & other.flag); |
| 764 } | 777 } |
| 765 } | 778 } |
| 766 | 779 |
| 767 class HInstruction implements Hashable { | 780 class HInstruction implements Hashable { |
| 768 final int id; | 781 final int id; |
| 769 static int idCounter; | 782 static int idCounter; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 return candidateType; | 848 return candidateType; |
| 836 } | 849 } |
| 837 | 850 |
| 838 HType computeDesiredInputType(HInstruction input) => HType.UNKNOWN; | 851 HType computeDesiredInputType(HInstruction input) => HType.UNKNOWN; |
| 839 | 852 |
| 840 // Returns whether the instruction does produce the type it claims. | 853 // Returns whether the instruction does produce the type it claims. |
| 841 // For most instructions, this returns false. A type guard will be | 854 // For most instructions, this returns false. A type guard will be |
| 842 // inserted to make sure the users get the right type in. | 855 // inserted to make sure the users get the right type in. |
| 843 bool hasExpectedType() => false; | 856 bool hasExpectedType() => false; |
| 844 | 857 |
| 845 // Re-compute and update the type of the instruction. Returns | |
| 846 // whether or not the type was changed. | |
| 847 bool updateType() { | |
| 848 if (type.isConflicting()) return false; | |
| 849 HType newType = computeType(); | |
| 850 HType desiredType = computeDesiredType(); | |
| 851 HType combined = newType.combine(desiredType); | |
| 852 if (combined.isKnown()) newType = combined; | |
| 853 | |
| 854 bool changed = (type != newType); | |
| 855 if (type.isUnknown()) { | |
| 856 type = newType; | |
| 857 return changed; | |
| 858 } else if (changed) { | |
| 859 type = type.combine(newType); | |
| 860 return changed; | |
| 861 } | |
| 862 return false; | |
| 863 } | |
| 864 | |
| 865 bool isInBasicBlock() => block !== null; | 858 bool isInBasicBlock() => block !== null; |
| 866 | 859 |
| 867 String inputsToString() { | 860 String inputsToString() { |
| 868 void addAsCommaSeparated(StringBuffer buffer, List<HInstruction> list) { | 861 void addAsCommaSeparated(StringBuffer buffer, List<HInstruction> list) { |
| 869 for (int i = 0; i < list.length; i++) { | 862 for (int i = 0; i < list.length; i++) { |
| 870 if (i != 0) buffer.add(', '); | 863 if (i != 0) buffer.add(', '); |
| 871 buffer.add("@${list[i].id}"); | 864 buffer.add("@${list[i].id}"); |
| 872 } | 865 } |
| 873 } | 866 } |
| 874 | 867 |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1680 } | 1673 } |
| 1681 | 1674 |
| 1682 void prepareGvn() { | 1675 void prepareGvn() { |
| 1683 assert(!hasSideEffects()); | 1676 assert(!hasSideEffects()); |
| 1684 } | 1677 } |
| 1685 | 1678 |
| 1686 toString() => 'literal: $constant'; | 1679 toString() => 'literal: $constant'; |
| 1687 accept(HVisitor visitor) => visitor.visitConstant(this); | 1680 accept(HVisitor visitor) => visitor.visitConstant(this); |
| 1688 HType computeType() => type; | 1681 HType computeType() => type; |
| 1689 | 1682 |
| 1690 // Literals have the type they have. It can't be changed. | |
| 1691 bool updateType() => false; | |
| 1692 | |
| 1693 bool hasExpectedType() => true; | 1683 bool hasExpectedType() => true; |
| 1694 | 1684 |
| 1695 bool isConstant() => true; | 1685 bool isConstant() => true; |
| 1696 bool isConstantBoolean() => constant.isBool(); | 1686 bool isConstantBoolean() => constant.isBool(); |
| 1697 bool isConstantNull() => constant.isNull(); | 1687 bool isConstantNull() => constant.isNull(); |
| 1698 bool isConstantNumber() => constant.isNum(); | 1688 bool isConstantNumber() => constant.isNum(); |
| 1699 bool isConstantString() => constant.isString(); | 1689 bool isConstantString() => constant.isString(); |
| 1700 | 1690 |
| 1701 // Maybe avoid this if the literal is big? | 1691 // Maybe avoid this if the literal is big? |
| 1702 bool isCodeMotionInvariant() => true; | 1692 bool isCodeMotionInvariant() => true; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1793 return type; | 1783 return type; |
| 1794 } | 1784 } |
| 1795 | 1785 |
| 1796 bool hasExpectedType() { | 1786 bool hasExpectedType() { |
| 1797 for (int i = 0; i < inputs.length; i++) { | 1787 for (int i = 0; i < inputs.length; i++) { |
| 1798 if (type.combine(inputs[i].type).isConflicting()) return false; | 1788 if (type.combine(inputs[i].type).isConflicting()) return false; |
| 1799 } | 1789 } |
| 1800 return true; | 1790 return true; |
| 1801 } | 1791 } |
| 1802 | 1792 |
| 1803 void setInitialTypeForLoopPhi() { | |
| 1804 assert(block.isLoopHeader()); | |
| 1805 assert(type.isUnknown()); | |
| 1806 type = inputs[0].type; | |
| 1807 } | |
| 1808 | |
| 1809 bool isLogicalOperator() => logicalOperatorType != IS_NOT_LOGICAL_OPERATOR; | 1793 bool isLogicalOperator() => logicalOperatorType != IS_NOT_LOGICAL_OPERATOR; |
| 1810 | 1794 |
| 1811 String logicalOperator() { | 1795 String logicalOperator() { |
| 1812 assert(isLogicalOperator()); | 1796 assert(isLogicalOperator()); |
| 1813 if (logicalOperatorType == IS_AND) return "&&"; | 1797 if (logicalOperatorType == IS_AND) return "&&"; |
| 1814 assert(logicalOperatorType == IS_OR); | 1798 assert(logicalOperatorType == IS_OR); |
| 1815 return "||"; | 1799 return "||"; |
| 1816 } | 1800 } |
| 1817 | 1801 |
| 1818 toString() => 'phi'; | 1802 toString() => 'phi'; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2074 class HIfBlockInformation { | 2058 class HIfBlockInformation { |
| 2075 final HIf branch; | 2059 final HIf branch; |
| 2076 final SubGraph thenGraph; | 2060 final SubGraph thenGraph; |
| 2077 final SubGraph elseGraph; | 2061 final SubGraph elseGraph; |
| 2078 final HBasicBlock joinBlock; | 2062 final HBasicBlock joinBlock; |
| 2079 HIfBlockInformation(this.branch, | 2063 HIfBlockInformation(this.branch, |
| 2080 this.thenGraph, | 2064 this.thenGraph, |
| 2081 this.elseGraph, | 2065 this.elseGraph, |
| 2082 this.joinBlock); | 2066 this.joinBlock); |
| 2083 } | 2067 } |
| OLD | NEW |