OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 class SsaCodeGeneratorTask extends CompilerTask { | 5 class SsaCodeGeneratorTask extends CompilerTask { |
6 final JavaScriptBackend backend; | 6 final JavaScriptBackend backend; |
7 SsaCodeGeneratorTask(JavaScriptBackend backend) | 7 SsaCodeGeneratorTask(JavaScriptBackend backend) |
8 : this.backend = backend, | 8 : this.backend = backend, |
9 super(backend.compiler); | 9 super(backend.compiler); |
10 String get name() => 'SSA code generator'; | 10 String get name() => 'SSA code generator'; |
(...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 use(node.receiver, JSPrecedence.MEMBER_PRECEDENCE); | 1826 use(node.receiver, JSPrecedence.MEMBER_PRECEDENCE); |
1827 buffer.add('.'); | 1827 buffer.add('.'); |
1828 buffer.add(name); | 1828 buffer.add(name); |
1829 beginExpression(JSPrecedence.MEMBER_PRECEDENCE); | 1829 beginExpression(JSPrecedence.MEMBER_PRECEDENCE); |
1830 Type type = node.receiver.propagatedType.computeType(compiler); | 1830 Type type = node.receiver.propagatedType.computeType(compiler); |
1831 if (type != null) { | 1831 if (type != null) { |
1832 world.registerFieldGetter(node.element.name, type); | 1832 world.registerFieldGetter(node.element.name, type); |
1833 } | 1833 } |
1834 } | 1834 } |
1835 | 1835 |
| 1836 // Determine if an instruction is a simple number computation |
| 1837 // involving only things with guaranteed number types and a given |
| 1838 // field. |
| 1839 bool isSimpleFieldNumberComputation(HInstruction value, HFieldSet node) { |
| 1840 if (value.guaranteedType.union(HType.NUMBER) == HType.NUMBER) return true; |
| 1841 if (value is HBinaryArithmetic) { |
| 1842 return (isSimpleFieldNumberComputation(value.left, node) && |
| 1843 isSimpleFieldNumberComputation(value.right, node)); |
| 1844 } |
| 1845 if (value is HFieldGet) return value.element == node.element; |
| 1846 return false; |
| 1847 } |
| 1848 |
1836 visitFieldSet(HFieldSet node) { | 1849 visitFieldSet(HFieldSet node) { |
1837 if (work.element.isGenerativeConstructorBody() && | 1850 if (work.element.isGenerativeConstructorBody() && |
1838 node.element.enclosingElement.isClass() && | 1851 node.element.enclosingElement.isClass() && |
1839 node.value.hasGuaranteedType() && | 1852 node.value.hasGuaranteedType() && |
1840 node.block.dominates(currentGraph.exit)) { | 1853 node.block.dominates(currentGraph.exit)) { |
1841 backend.updateFieldConstructorSetters(node.element, | 1854 backend.updateFieldConstructorSetters(node.element, |
1842 node.value.guaranteedType); | 1855 node.value.guaranteedType); |
1843 } | 1856 } |
1844 String name = compiler.namer.getName(node.element); | 1857 String name = compiler.namer.getName(node.element); |
1845 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); | 1858 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); |
1846 use(node.receiver, JSPrecedence.MEMBER_PRECEDENCE); | 1859 use(node.receiver, JSPrecedence.MEMBER_PRECEDENCE); |
1847 buffer.add('.'); | 1860 buffer.add('.'); |
1848 buffer.add(name); | 1861 buffer.add(name); |
1849 Type type = node.receiver.propagatedType.computeType(compiler); | 1862 Type type = node.receiver.propagatedType.computeType(compiler); |
1850 if (type != null) { | 1863 if (type != null) { |
1851 if (!work.element.isGenerativeConstructorBody()) { | 1864 if (!work.element.isGenerativeConstructorBody()) { |
1852 world.registerFieldSetter(node.element.name, type); | 1865 world.registerFieldSetter(node.element.name, type); |
1853 } | 1866 } |
1854 backend.updateFieldSetters(node.element, | 1867 // Determine the types seen so far for the field. If only number |
1855 node.value.propagatedType); | 1868 // types have been seen and the value of the field set is a |
| 1869 // simple number computation only depending on that field, we |
| 1870 // can safely keep the number type for the field. |
| 1871 HType fieldSettersType = backend.fieldSettersTypeSoFar(node.element); |
| 1872 HType initializersType = backend.typeFromInitializersSoFar(node.element); |
| 1873 HType fieldType = fieldSettersType.union(initializersType); |
| 1874 if (HType.NUMBER.union(fieldType) == HType.NUMBER && |
| 1875 isSimpleFieldNumberComputation(node.value, node)) { |
| 1876 backend.updateFieldSetters(node.element, HType.NUMBER); |
| 1877 } else { |
| 1878 backend.updateFieldSetters(node.element, |
| 1879 node.value.propagatedType); |
| 1880 } |
1856 } | 1881 } |
1857 buffer.add(' = '); | 1882 buffer.add(' = '); |
1858 use(node.value, JSPrecedence.ASSIGNMENT_PRECEDENCE); | 1883 use(node.value, JSPrecedence.ASSIGNMENT_PRECEDENCE); |
1859 endExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); | 1884 endExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); |
1860 } | 1885 } |
1861 | 1886 |
1862 visitLocalGet(HLocalGet node) { | 1887 visitLocalGet(HLocalGet node) { |
1863 use(node.receiver, JSPrecedence.EXPRESSION_PRECEDENCE); | 1888 use(node.receiver, JSPrecedence.EXPRESSION_PRECEDENCE); |
1864 } | 1889 } |
1865 | 1890 |
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3111 if (leftType.canBeNull() && rightType.canBeNull()) { | 3136 if (leftType.canBeNull() && rightType.canBeNull()) { |
3112 if (left.isConstantNull() || right.isConstantNull() || | 3137 if (left.isConstantNull() || right.isConstantNull() || |
3113 (leftType.isPrimitive() && leftType == rightType)) { | 3138 (leftType.isPrimitive() && leftType == rightType)) { |
3114 return '=='; | 3139 return '=='; |
3115 } | 3140 } |
3116 return null; | 3141 return null; |
3117 } else { | 3142 } else { |
3118 return '==='; | 3143 return '==='; |
3119 } | 3144 } |
3120 } | 3145 } |
OLD | NEW |