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 part of ssa; | 5 part of ssa; |
6 | 6 |
7 class SsaCodeGeneratorTask extends CompilerTask { | 7 class SsaCodeGeneratorTask extends CompilerTask { |
8 | 8 |
9 final JavaScriptBackend backend; | 9 final JavaScriptBackend backend; |
10 | 10 |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 List<js.SwitchClause> cases = <js.SwitchClause>[]; | 649 List<js.SwitchClause> cases = <js.SwitchClause>[]; |
650 HSwitch switchInstruction = info.expression.end.last; | 650 HSwitch switchInstruction = info.expression.end.last; |
651 List<HInstruction> inputs = switchInstruction.inputs; | 651 List<HInstruction> inputs = switchInstruction.inputs; |
652 List<HBasicBlock> successors = switchInstruction.block.successors; | 652 List<HBasicBlock> successors = switchInstruction.block.successors; |
653 | 653 |
654 js.Block oldContainer = currentContainer; | 654 js.Block oldContainer = currentContainer; |
655 for (int inputIndex = 1, statementIndex = 0; | 655 for (int inputIndex = 1, statementIndex = 0; |
656 inputIndex < inputs.length; | 656 inputIndex < inputs.length; |
657 statementIndex++) { | 657 statementIndex++) { |
658 HBasicBlock successor = successors[inputIndex - 1]; | 658 HBasicBlock successor = successors[inputIndex - 1]; |
659 do { | 659 // If liveness analysis has figured out that this case is dead, |
660 visit(inputs[inputIndex]); | 660 // omit the code for it. |
661 currentContainer = new js.Block.empty(); | 661 if (successor.isLive) { |
662 cases.add(new js.Case(pop(), currentContainer)); | 662 do { |
663 inputIndex++; | 663 visit(inputs[inputIndex]); |
664 } while ((successors[inputIndex - 1] == successor) | 664 currentContainer = new js.Block.empty(); |
665 && (inputIndex < inputs.length)); | 665 cases.add(new js.Case(pop(), currentContainer)); |
| 666 inputIndex++; |
| 667 } while ((successors[inputIndex - 1] == successor) |
| 668 && (inputIndex < inputs.length)); |
666 | 669 |
667 generateStatements(info.statements[statementIndex]); | 670 generateStatements(info.statements[statementIndex]); |
| 671 } else { |
| 672 // Skip all the case statements that belong to this |
| 673 // block. |
| 674 while ((successors[inputIndex - 1] == successor) |
| 675 && (inputIndex < inputs.length)) { |
| 676 ++inputIndex; |
| 677 } |
| 678 } |
668 } | 679 } |
669 | 680 |
670 currentContainer = new js.Block.empty(); | 681 // If the default case is dead, we omit it. Likewise, if it is an |
671 cases.add(new js.Default(currentContainer)); | 682 // empty block, we omit it, too. |
672 generateStatements(info.statements.last); | 683 if (info.statements.last.start.isLive) { |
| 684 currentContainer = new js.Block.empty(); |
| 685 generateStatements(info.statements.last); |
| 686 if (currentContainer.statements.isNotEmpty) { |
| 687 cases.add(new js.Default(currentContainer)); |
| 688 } |
| 689 } |
673 | 690 |
674 currentContainer = oldContainer; | 691 currentContainer = oldContainer; |
675 | 692 |
676 js.Statement result = new js.Switch(key, cases); | 693 js.Statement result = new js.Switch(key, cases); |
677 pushStatement(wrapIntoLabels(result, info.labels)); | 694 pushStatement(wrapIntoLabels(result, info.labels)); |
678 return true; | 695 return true; |
679 } | 696 } |
680 | 697 |
681 bool visitSequenceInfo(HStatementSequenceInformation info) { | 698 bool visitSequenceInfo(HStatementSequenceInformation info) { |
682 return false; | 699 return false; |
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2661 if (left.isConstantNull() || right.isConstantNull() || | 2678 if (left.isConstantNull() || right.isConstantNull() || |
2662 (left.isPrimitive(compiler) && | 2679 (left.isPrimitive(compiler) && |
2663 left.instructionType == right.instructionType)) { | 2680 left.instructionType == right.instructionType)) { |
2664 return '=='; | 2681 return '=='; |
2665 } | 2682 } |
2666 return null; | 2683 return null; |
2667 } else { | 2684 } else { |
2668 return '==='; | 2685 return '==='; |
2669 } | 2686 } |
2670 } | 2687 } |
OLD | NEW |