| 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 import '../common.dart'; | 5 import '../common.dart'; |
| 6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 7 import '../common/tasks.dart' show CompilerTask; | 7 import '../common/tasks.dart' show CompilerTask; |
| 8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
| 9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| (...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 use(node.inputs[0]); | 1489 use(node.inputs[0]); |
| 1490 js.Expression test = pop(); | 1490 js.Expression test = pop(); |
| 1491 | 1491 |
| 1492 HStatementInformation thenGraph = info.thenGraph; | 1492 HStatementInformation thenGraph = info.thenGraph; |
| 1493 HStatementInformation elseGraph = info.elseGraph; | 1493 HStatementInformation elseGraph = info.elseGraph; |
| 1494 js.Statement thenPart = | 1494 js.Statement thenPart = |
| 1495 unwrapStatement(generateStatementsInNewBlock(thenGraph)); | 1495 unwrapStatement(generateStatementsInNewBlock(thenGraph)); |
| 1496 js.Statement elsePart = | 1496 js.Statement elsePart = |
| 1497 unwrapStatement(generateStatementsInNewBlock(elseGraph)); | 1497 unwrapStatement(generateStatementsInNewBlock(elseGraph)); |
| 1498 | 1498 |
| 1499 pushStatement(new js.If(test, thenPart, elsePart) | 1499 js.Statement code; |
| 1500 .withSourceInformation(node.sourceInformation)); | 1500 // Peephole rewrites: |
| 1501 // |
| 1502 // if (e); else S; --> if(!e) S; |
| 1503 // |
| 1504 // if (e); --> e; |
| 1505 // |
| 1506 // TODO(sra): This peephole optimization would be better done as an SSA |
| 1507 // optimization. |
| 1508 if (thenPart is js.EmptyStatement) { |
| 1509 if (elsePart is js.EmptyStatement) { |
| 1510 code = new js.ExpressionStatement(test); |
| 1511 } else { |
| 1512 code = new js.If.noElse(new js.Prefix('!', test), elsePart); |
| 1513 } |
| 1514 } else { |
| 1515 code = new js.If(test, thenPart, elsePart); |
| 1516 } |
| 1517 pushStatement(code.withSourceInformation(node.sourceInformation)); |
| 1501 } | 1518 } |
| 1502 | 1519 |
| 1503 visitIf(HIf node) { | 1520 visitIf(HIf node) { |
| 1504 if (tryControlFlowOperation(node)) return; | 1521 if (tryControlFlowOperation(node)) return; |
| 1505 | 1522 |
| 1506 HInstruction condition = node.inputs[0]; | 1523 HInstruction condition = node.inputs[0]; |
| 1507 HIfBlockInformation info = node.blockInformation.body; | 1524 HIfBlockInformation info = node.blockInformation.body; |
| 1508 | 1525 |
| 1509 if (condition.isConstant()) { | 1526 if (condition.isConstant()) { |
| 1510 HConstant constant = condition; | 1527 HConstant constant = condition; |
| (...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2896 registry.registerStaticUse(new StaticUse.staticInvoke( | 2913 registry.registerStaticUse(new StaticUse.staticInvoke( |
| 2897 helper, new CallStructure.unnamed(argumentCount))); | 2914 helper, new CallStructure.unnamed(argumentCount))); |
| 2898 return backend.emitter.staticFunctionAccess(helper); | 2915 return backend.emitter.staticFunctionAccess(helper); |
| 2899 } | 2916 } |
| 2900 | 2917 |
| 2901 @override | 2918 @override |
| 2902 void visitRef(HRef node) { | 2919 void visitRef(HRef node) { |
| 2903 visit(node.value); | 2920 visit(node.value); |
| 2904 } | 2921 } |
| 2905 } | 2922 } |
| OLD | NEW |