| 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 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 21 matching lines...) Expand all Loading... |
| 32 R visitInvokeDynamicGetter(HInvokeDynamicGetter node); | 32 R visitInvokeDynamicGetter(HInvokeDynamicGetter node); |
| 33 R visitInvokeDynamicMethod(HInvokeDynamicMethod node); | 33 R visitInvokeDynamicMethod(HInvokeDynamicMethod node); |
| 34 R visitInvokeDynamicSetter(HInvokeDynamicSetter node); | 34 R visitInvokeDynamicSetter(HInvokeDynamicSetter node); |
| 35 R visitInvokeInterceptor(HInvokeInterceptor node); | 35 R visitInvokeInterceptor(HInvokeInterceptor node); |
| 36 R visitInvokeStatic(HInvokeStatic node); | 36 R visitInvokeStatic(HInvokeStatic node); |
| 37 R visitInvokeSuper(HInvokeSuper node); | 37 R visitInvokeSuper(HInvokeSuper node); |
| 38 R visitIs(HIs node); | 38 R visitIs(HIs node); |
| 39 R visitLess(HLess node); | 39 R visitLess(HLess node); |
| 40 R visitLessEqual(HLessEqual node); | 40 R visitLessEqual(HLessEqual node); |
| 41 R visitLiteralList(HLiteralList node); | 41 R visitLiteralList(HLiteralList node); |
| 42 R visitLocalGet(HLocalGet node); |
| 43 R visitLocalSet(HLocalSet node); |
| 44 R visitLocalValue(HLocalValue node); |
| 42 R visitLoopBranch(HLoopBranch node); | 45 R visitLoopBranch(HLoopBranch node); |
| 43 R visitModulo(HModulo node); | 46 R visitModulo(HModulo node); |
| 44 R visitMultiply(HMultiply node); | 47 R visitMultiply(HMultiply node); |
| 45 R visitNegate(HNegate node); | 48 R visitNegate(HNegate node); |
| 46 R visitNot(HNot node); | 49 R visitNot(HNot node); |
| 47 R visitParameterValue(HParameterValue node); | 50 R visitParameterValue(HParameterValue node); |
| 48 R visitPhi(HPhi node); | 51 R visitPhi(HPhi node); |
| 49 R visitReturn(HReturn node); | 52 R visitReturn(HReturn node); |
| 50 R visitShiftLeft(HShiftLeft node); | 53 R visitShiftLeft(HShiftLeft node); |
| 51 R visitShiftRight(HShiftRight node); | 54 R visitShiftRight(HShiftRight node); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 245 |
| 243 visitBinaryArithmetic(HBinaryArithmetic node) => visitInvokeBinary(node); | 246 visitBinaryArithmetic(HBinaryArithmetic node) => visitInvokeBinary(node); |
| 244 visitBinaryBitOp(HBinaryBitOp node) => visitBinaryArithmetic(node); | 247 visitBinaryBitOp(HBinaryBitOp node) => visitBinaryArithmetic(node); |
| 245 visitInvoke(HInvoke node) => visitInstruction(node); | 248 visitInvoke(HInvoke node) => visitInstruction(node); |
| 246 visitInvokeBinary(HInvokeBinary node) => visitInvokeStatic(node); | 249 visitInvokeBinary(HInvokeBinary node) => visitInvokeStatic(node); |
| 247 visitInvokeDynamic(HInvokeDynamic node) => visitInvoke(node); | 250 visitInvokeDynamic(HInvokeDynamic node) => visitInvoke(node); |
| 248 visitInvokeDynamicField(HInvokeDynamicField node) => visitInvokeDynamic(node); | 251 visitInvokeDynamicField(HInvokeDynamicField node) => visitInvokeDynamic(node); |
| 249 visitInvokeUnary(HInvokeUnary node) => visitInvokeStatic(node); | 252 visitInvokeUnary(HInvokeUnary node) => visitInvokeStatic(node); |
| 250 visitConditionalBranch(HConditionalBranch node) => visitControlFlow(node); | 253 visitConditionalBranch(HConditionalBranch node) => visitControlFlow(node); |
| 251 visitControlFlow(HControlFlow node) => visitInstruction(node); | 254 visitControlFlow(HControlFlow node) => visitInstruction(node); |
| 255 visitFieldAccess(HFieldAccess node) => visitInstruction(node); |
| 252 visitRelational(HRelational node) => visitInvokeBinary(node); | 256 visitRelational(HRelational node) => visitInvokeBinary(node); |
| 253 | 257 |
| 254 visitAdd(HAdd node) => visitBinaryArithmetic(node); | 258 visitAdd(HAdd node) => visitBinaryArithmetic(node); |
| 255 visitBitAnd(HBitAnd node) => visitBinaryBitOp(node); | 259 visitBitAnd(HBitAnd node) => visitBinaryBitOp(node); |
| 256 visitBitNot(HBitNot node) => visitInvokeUnary(node); | 260 visitBitNot(HBitNot node) => visitInvokeUnary(node); |
| 257 visitBitOr(HBitOr node) => visitBinaryBitOp(node); | 261 visitBitOr(HBitOr node) => visitBinaryBitOp(node); |
| 258 visitBitXor(HBitXor node) => visitBinaryBitOp(node); | 262 visitBitXor(HBitXor node) => visitBinaryBitOp(node); |
| 259 visitBoolify(HBoolify node) => visitInstruction(node); | 263 visitBoolify(HBoolify node) => visitInstruction(node); |
| 260 visitBoundsCheck(HBoundsCheck node) => visitCheck(node); | 264 visitBoundsCheck(HBoundsCheck node) => visitCheck(node); |
| 261 visitBreak(HBreak node) => visitJump(node); | 265 visitBreak(HBreak node) => visitJump(node); |
| 262 visitContinue(HContinue node) => visitJump(node); | 266 visitContinue(HContinue node) => visitJump(node); |
| 263 visitCheck(HCheck node) => visitInstruction(node); | 267 visitCheck(HCheck node) => visitInstruction(node); |
| 264 visitConstant(HConstant node) => visitInstruction(node); | 268 visitConstant(HConstant node) => visitInstruction(node); |
| 265 visitDivide(HDivide node) => visitBinaryArithmetic(node); | 269 visitDivide(HDivide node) => visitBinaryArithmetic(node); |
| 266 visitEquals(HEquals node) => visitRelational(node); | 270 visitEquals(HEquals node) => visitRelational(node); |
| 267 visitExit(HExit node) => visitControlFlow(node); | 271 visitExit(HExit node) => visitControlFlow(node); |
| 268 visitFieldGet(HFieldGet node) => visitInstruction(node); | 272 visitFieldGet(HFieldGet node) => visitFieldAccess(node); |
| 269 visitFieldSet(HFieldSet node) => visitInstruction(node); | 273 visitFieldSet(HFieldSet node) => visitFieldAccess(node); |
| 270 visitForeign(HForeign node) => visitInstruction(node); | 274 visitForeign(HForeign node) => visitInstruction(node); |
| 271 visitForeignNew(HForeignNew node) => visitForeign(node); | 275 visitForeignNew(HForeignNew node) => visitForeign(node); |
| 272 visitGoto(HGoto node) => visitControlFlow(node); | 276 visitGoto(HGoto node) => visitControlFlow(node); |
| 273 visitGreater(HGreater node) => visitRelational(node); | 277 visitGreater(HGreater node) => visitRelational(node); |
| 274 visitGreaterEqual(HGreaterEqual node) => visitRelational(node); | 278 visitGreaterEqual(HGreaterEqual node) => visitRelational(node); |
| 275 visitIdentity(HIdentity node) => visitRelational(node); | 279 visitIdentity(HIdentity node) => visitRelational(node); |
| 276 visitIf(HIf node) => visitConditionalBranch(node); | 280 visitIf(HIf node) => visitConditionalBranch(node); |
| 277 visitIndex(HIndex node) => visitInvokeStatic(node); | 281 visitIndex(HIndex node) => visitInvokeStatic(node); |
| 278 visitIndexAssign(HIndexAssign node) => visitInvokeStatic(node); | 282 visitIndexAssign(HIndexAssign node) => visitInvokeStatic(node); |
| 279 visitIntegerCheck(HIntegerCheck node) => visitCheck(node); | 283 visitIntegerCheck(HIntegerCheck node) => visitCheck(node); |
| 280 visitInvokeClosure(HInvokeClosure node) | 284 visitInvokeClosure(HInvokeClosure node) |
| 281 => visitInvokeDynamic(node); | 285 => visitInvokeDynamic(node); |
| 282 visitInvokeDynamicMethod(HInvokeDynamicMethod node) | 286 visitInvokeDynamicMethod(HInvokeDynamicMethod node) |
| 283 => visitInvokeDynamic(node); | 287 => visitInvokeDynamic(node); |
| 284 visitInvokeDynamicGetter(HInvokeDynamicGetter node) | 288 visitInvokeDynamicGetter(HInvokeDynamicGetter node) |
| 285 => visitInvokeDynamicField(node); | 289 => visitInvokeDynamicField(node); |
| 286 visitInvokeDynamicSetter(HInvokeDynamicSetter node) | 290 visitInvokeDynamicSetter(HInvokeDynamicSetter node) |
| 287 => visitInvokeDynamicField(node); | 291 => visitInvokeDynamicField(node); |
| 288 visitInvokeInterceptor(HInvokeInterceptor node) | 292 visitInvokeInterceptor(HInvokeInterceptor node) |
| 289 => visitInvokeStatic(node); | 293 => visitInvokeStatic(node); |
| 290 visitInvokeStatic(HInvokeStatic node) => visitInvoke(node); | 294 visitInvokeStatic(HInvokeStatic node) => visitInvoke(node); |
| 291 visitInvokeSuper(HInvokeSuper node) => visitInvoke(node); | 295 visitInvokeSuper(HInvokeSuper node) => visitInvoke(node); |
| 292 visitJump(HJump node) => visitControlFlow(node); | 296 visitJump(HJump node) => visitControlFlow(node); |
| 293 visitLess(HLess node) => visitRelational(node); | 297 visitLess(HLess node) => visitRelational(node); |
| 294 visitLessEqual(HLessEqual node) => visitRelational(node); | 298 visitLessEqual(HLessEqual node) => visitRelational(node); |
| 295 visitLiteralList(HLiteralList node) => visitInstruction(node); | 299 visitLiteralList(HLiteralList node) => visitInstruction(node); |
| 300 visitLocalGet(HLocalGet node) => visitFieldGet(node); |
| 301 visitLocalSet(HLocalSet node) => visitFieldSet(node); |
| 302 visitLocalValue(HLocalValue node) => visitInstruction(node); |
| 296 visitLoopBranch(HLoopBranch node) => visitConditionalBranch(node); | 303 visitLoopBranch(HLoopBranch node) => visitConditionalBranch(node); |
| 297 visitModulo(HModulo node) => visitBinaryArithmetic(node); | 304 visitModulo(HModulo node) => visitBinaryArithmetic(node); |
| 298 visitNegate(HNegate node) => visitInvokeUnary(node); | 305 visitNegate(HNegate node) => visitInvokeUnary(node); |
| 299 visitNot(HNot node) => visitInstruction(node); | 306 visitNot(HNot node) => visitInstruction(node); |
| 300 visitPhi(HPhi node) => visitInstruction(node); | 307 visitPhi(HPhi node) => visitInstruction(node); |
| 301 visitMultiply(HMultiply node) => visitBinaryArithmetic(node); | 308 visitMultiply(HMultiply node) => visitBinaryArithmetic(node); |
| 302 visitParameterValue(HParameterValue node) => visitInstruction(node); | 309 visitParameterValue(HParameterValue node) => visitLocalValue(node); |
| 303 visitReturn(HReturn node) => visitControlFlow(node); | 310 visitReturn(HReturn node) => visitControlFlow(node); |
| 304 visitShiftRight(HShiftRight node) => visitBinaryBitOp(node); | 311 visitShiftRight(HShiftRight node) => visitBinaryBitOp(node); |
| 305 visitShiftLeft(HShiftLeft node) => visitBinaryBitOp(node); | 312 visitShiftLeft(HShiftLeft node) => visitBinaryBitOp(node); |
| 306 visitSubtract(HSubtract node) => visitBinaryArithmetic(node); | 313 visitSubtract(HSubtract node) => visitBinaryArithmetic(node); |
| 307 visitSwitch(HSwitch node) => visitControlFlow(node); | 314 visitSwitch(HSwitch node) => visitControlFlow(node); |
| 308 visitStatic(HStatic node) => visitInstruction(node); | 315 visitStatic(HStatic node) => visitInstruction(node); |
| 309 visitStaticStore(HStaticStore node) => visitInstruction(node); | 316 visitStaticStore(HStaticStore node) => visitInstruction(node); |
| 310 visitStringConcat(HStringConcat node) => visitInstruction(node); | 317 visitStringConcat(HStringConcat node) => visitInstruction(node); |
| 311 visitThis(HThis node) => visitParameterValue(node); | 318 visitThis(HThis node) => visitParameterValue(node); |
| 312 visitThrow(HThrow node) => visitControlFlow(node); | 319 visitThrow(HThrow node) => visitControlFlow(node); |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 HFieldSet(Element element, HInstruction receiver, HInstruction value) | 1287 HFieldSet(Element element, HInstruction receiver, HInstruction value) |
| 1281 : super(element, <HInstruction>[receiver, value]); | 1288 : super(element, <HInstruction>[receiver, value]); |
| 1282 HFieldSet.fromActivation(receiver, value) | 1289 HFieldSet.fromActivation(receiver, value) |
| 1283 : this(null, receiver, value); | 1290 : this(null, receiver, value); |
| 1284 | 1291 |
| 1285 HInstruction get receiver() => inputs.length == 2 ? inputs[0] : null; | 1292 HInstruction get receiver() => inputs.length == 2 ? inputs[0] : null; |
| 1286 HInstruction get value() => inputs.length == 2 ? inputs[1] : inputs[0]; | 1293 HInstruction get value() => inputs.length == 2 ? inputs[1] : inputs[0]; |
| 1287 accept(HVisitor visitor) => visitor.visitFieldSet(this); | 1294 accept(HVisitor visitor) => visitor.visitFieldSet(this); |
| 1288 | 1295 |
| 1289 void prepareGvn() { | 1296 void prepareGvn() { |
| 1290 // TODO(ngeoffray): implement more fine grain side effects. | 1297 // TODO(ngeoffray): implement more fine grained side effects. |
| 1291 setAllSideEffects(); | 1298 setAllSideEffects(); |
| 1292 } | 1299 } |
| 1293 | 1300 |
| 1294 bool isStatement() => true; | 1301 bool isStatement() => true; |
| 1295 } | 1302 } |
| 1296 | 1303 |
| 1304 class HLocalGet extends HFieldGet { |
| 1305 HLocalGet(Element element, HLocalValue local) : super(element, local); |
| 1306 |
| 1307 accept(HVisitor visitor) => visitor.visitLocalGet(this); |
| 1308 |
| 1309 HLocalValue get local() => inputs[0]; |
| 1310 |
| 1311 void prepareGvn() { |
| 1312 setUseGvn(); |
| 1313 // TODO(floitsch): if the variable is not captured then it only depends |
| 1314 // on assignments to the same variable. Otherwise we need to see if the |
| 1315 // variable is mutated inside closures. |
| 1316 setDependsOnSomething(); |
| 1317 } |
| 1318 } |
| 1319 |
| 1320 class HLocalSet extends HFieldSet { |
| 1321 HLocalSet(Element element, HLocalValue local, HInstruction value) |
| 1322 : super(element, local, value); |
| 1323 |
| 1324 accept(HVisitor visitor) => visitor.visitLocalSet(this); |
| 1325 |
| 1326 HLocalValue get local() => inputs[0]; |
| 1327 |
| 1328 void prepareGvn() { |
| 1329 // TODO(floitsch): implement more fine grained side effects. |
| 1330 setAllSideEffects(); |
| 1331 } |
| 1332 } |
| 1333 |
| 1297 class HForeign extends HInstruction { | 1334 class HForeign extends HInstruction { |
| 1298 final DartString code; | 1335 final DartString code; |
| 1299 final HType foreignType; | 1336 final HType foreignType; |
| 1300 HForeign(this.code, DartString declaredType, List<HInstruction> inputs) | 1337 HForeign(this.code, DartString declaredType, List<HInstruction> inputs) |
| 1301 : foreignType = computeTypeFromDeclaredType(declaredType), | 1338 : foreignType = computeTypeFromDeclaredType(declaredType), |
| 1302 super(inputs); | 1339 super(inputs); |
| 1303 accept(HVisitor visitor) => visitor.visitForeign(this); | 1340 accept(HVisitor visitor) => visitor.visitForeign(this); |
| 1304 | 1341 |
| 1305 static HType computeTypeFromDeclaredType(DartString declaredType) { | 1342 static HType computeTypeFromDeclaredType(DartString declaredType) { |
| 1306 if (declaredType.slowToString() == 'bool') return HType.BOOLEAN; | 1343 if (declaredType.slowToString() == 'bool') return HType.BOOLEAN; |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1814 | 1851 |
| 1815 // 'Not' only works on booleans. That's what we want as input. | 1852 // 'Not' only works on booleans. That's what we want as input. |
| 1816 HType computeDesiredTypeForInput(HInstruction input) => HType.BOOLEAN; | 1853 HType computeDesiredTypeForInput(HInstruction input) => HType.BOOLEAN; |
| 1817 | 1854 |
| 1818 accept(HVisitor visitor) => visitor.visitNot(this); | 1855 accept(HVisitor visitor) => visitor.visitNot(this); |
| 1819 int typeCode() => 18; | 1856 int typeCode() => 18; |
| 1820 bool typeEquals(other) => other is HNot; | 1857 bool typeEquals(other) => other is HNot; |
| 1821 bool dataEquals(HInstruction other) => true; | 1858 bool dataEquals(HInstruction other) => true; |
| 1822 } | 1859 } |
| 1823 | 1860 |
| 1824 class HParameterValue extends HInstruction { | 1861 /** |
| 1825 HParameterValue(element) : super(<HInstruction>[]) { | 1862 * An [HLocalValue] represents a local. Unlike [HParameterValue]s its |
| 1863 * first use must be in an HLocalSet. That is, [HParameterValue]s have a |
| 1864 * value from the start, whereas [HLocalValue]s need to be initialized first. |
| 1865 */ |
| 1866 class HLocalValue extends HInstruction { |
| 1867 HLocalValue(element) : super(<HInstruction>[]) { |
| 1826 sourceElement = element; | 1868 sourceElement = element; |
| 1827 } | 1869 } |
| 1828 | 1870 |
| 1829 void prepareGvn() { | 1871 void prepareGvn() { |
| 1830 assert(!hasSideEffects()); | 1872 assert(!hasSideEffects()); |
| 1831 } | 1873 } |
| 1832 toString() => 'parameter ${sourceElement.name}'; | 1874 toString() => 'local ${sourceElement.name}'; |
| 1833 accept(HVisitor visitor) => visitor.visitParameterValue(this); | 1875 accept(HVisitor visitor) => visitor.visitLocalValue(this); |
| 1834 bool isCodeMotionInvariant() => true; | 1876 bool isCodeMotionInvariant() => true; |
| 1835 } | 1877 } |
| 1836 | 1878 |
| 1879 class HParameterValue extends HLocalValue { |
| 1880 HParameterValue(element) : super(element); |
| 1881 |
| 1882 toString() => 'parameter ${sourceElement.name}'; |
| 1883 accept(HVisitor visitor) => visitor.visitParameterValue(this); |
| 1884 } |
| 1885 |
| 1837 class HThis extends HParameterValue { | 1886 class HThis extends HParameterValue { |
| 1838 HThis([HType type = HType.UNKNOWN]) : super(null) { | 1887 HThis([HType type = HType.UNKNOWN]) : super(null) { |
| 1839 guaranteedType = type; | 1888 guaranteedType = type; |
| 1840 } | 1889 } |
| 1841 toString() => 'this'; | 1890 toString() => 'this'; |
| 1842 accept(HVisitor visitor) => visitor.visitThis(this); | 1891 accept(HVisitor visitor) => visitor.visitThis(this); |
| 1843 } | 1892 } |
| 1844 | 1893 |
| 1845 class HPhi extends HInstruction { | 1894 class HPhi extends HInstruction { |
| 1846 static final IS_NOT_LOGICAL_OPERATOR = 0; | 1895 static final IS_NOT_LOGICAL_OPERATOR = 0; |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2582 HBasicBlock get start() => expression.start; | 2631 HBasicBlock get start() => expression.start; |
| 2583 HBasicBlock get end() { | 2632 HBasicBlock get end() { |
| 2584 // We don't create a switch block if there are no cases. | 2633 // We don't create a switch block if there are no cases. |
| 2585 assert(!statements.isEmpty()); | 2634 assert(!statements.isEmpty()); |
| 2586 return statements.last().end; | 2635 return statements.last().end; |
| 2587 } | 2636 } |
| 2588 | 2637 |
| 2589 bool accept(HStatementInformationVisitor visitor) => | 2638 bool accept(HStatementInformationVisitor visitor) => |
| 2590 visitor.visitSwitchInfo(this); | 2639 visitor.visitSwitchInfo(this); |
| 2591 } | 2640 } |
| OLD | NEW |