Chromium Code Reviews| 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 2621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2632 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2632 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 2633 } | 2633 } |
| 2634 } | 2634 } |
| 2635 | 2635 |
| 2636 class SsaUnoptimizedCodeGenerator extends SsaCodeGenerator { | 2636 class SsaUnoptimizedCodeGenerator extends SsaCodeGenerator { |
| 2637 | 2637 |
| 2638 final StringBuffer setup; | 2638 final StringBuffer setup; |
| 2639 final StringBuffer newParameters; | 2639 final StringBuffer newParameters; |
| 2640 final List<String> labels; | 2640 final List<String> labels; |
| 2641 int labelId = 0; | 2641 int labelId = 0; |
| 2642 int maxBailoutParameters = 0; | |
| 2643 | 2642 |
| 2644 SsaBailoutPropagator propagator; | 2643 SsaBailoutPropagator propagator; |
| 2645 HInstruction savedFirstInstruction; | 2644 HInstruction savedFirstInstruction; |
| 2646 | 2645 |
| 2647 SsaUnoptimizedCodeGenerator(backend, work, parameters, parameterNames) | 2646 SsaUnoptimizedCodeGenerator(backend, work, parameters, parameterNames) |
| 2648 : super(backend, work, parameters, parameterNames), | 2647 : super(backend, work, parameters, parameterNames), |
| 2649 setup = new StringBuffer(), | 2648 setup = new StringBuffer(), |
| 2650 newParameters = new StringBuffer(), | 2649 newParameters = new StringBuffer(), |
| 2651 labels = <String>[]; | 2650 labels = <String>[]; |
| 2652 | 2651 |
| 2653 String pushLabel() { | 2652 String pushLabel() { |
| 2654 String label = 'L${labelId++}'; | 2653 String label = 'L${labelId++}'; |
| 2655 labels.addLast(label); | 2654 labels.addLast(label); |
| 2656 return label; | 2655 return label; |
| 2657 } | 2656 } |
| 2658 | 2657 |
| 2659 String popLabel() { | 2658 String popLabel() { |
| 2660 return labels.removeLast(); | 2659 return labels.removeLast(); |
| 2661 } | 2660 } |
| 2662 | 2661 |
| 2663 String currentLabel() { | 2662 String currentLabel() { |
| 2664 return labels.last(); | 2663 return labels.last(); |
| 2665 } | 2664 } |
| 2666 | 2665 |
| 2667 HBasicBlock beginGraph(HGraph graph) { | 2666 HBasicBlock beginGraph(HGraph graph) { |
| 2668 propagator = new SsaBailoutPropagator(compiler, generateAtUseSite); | 2667 propagator = new SsaBailoutPropagator(compiler, generateAtUseSite); |
| 2669 propagator.visitGraph(graph); | 2668 propagator.visitGraph(graph); |
| 2669 // TODO(ngeoffray): We could avoid generating the state at the | |
| 2670 // call site for non-complex bailout methods. | |
| 2671 newParameters.add('state'); | |
| 2670 | 2672 |
| 2671 if (propagator.hasComplexTypeGuards) { | 2673 if (propagator.hasComplexTypeGuards) { |
| 2672 startBailoutSwitch(); | 2674 startBailoutSwitch(); |
| 2675 | |
| 2676 // Use generic parameters that will be assign to | |
|
floitsch
2012/06/14 15:29:39
assigned
ngeoffray
2012/06/14 15:31:47
Done.
| |
| 2677 // the right variables in the setup phase. | |
| 2678 for (int i = 0; i < propagator.maxBailoutParameters; i++) { | |
| 2679 String name = 'env$i'; | |
| 2680 declaredVariables.add(name); | |
| 2681 newParameters.add(', $name'); | |
| 2682 } | |
| 2673 | 2683 |
| 2674 // The setup phase of a bailout function sets up the environment for | 2684 // The setup phase of a bailout function sets up the environment for |
| 2675 // each bailout target. Each bailout target will populate this | 2685 // each bailout target. Each bailout target will populate this |
| 2676 // setup phase. It is put at the beginning of the function. | 2686 // setup phase. It is put at the beginning of the function. |
| 2677 setup.add(' switch (state) {\n'); | 2687 setup.add(' switch (state) {\n'); |
| 2678 return graph.entry; | 2688 return graph.entry; |
| 2679 } else { | 2689 } else { |
| 2690 // We have a simple type guard, so we can reuse the names that | |
| 2691 // the type guard expects. | |
| 2692 for (HInstruction input in propagator.firstTypeGuard.inputs) { | |
| 2693 input = unwrap(input); | |
| 2694 String name = variableNames.getName(input); | |
| 2695 declaredVariables.add(name); | |
| 2696 newParameters.add(', $name'); | |
| 2697 } | |
| 2698 | |
| 2680 // We change the first instruction of the first guard to be the | 2699 // We change the first instruction of the first guard to be the |
| 2681 // guard. We will change it back in the call to [endGraph]. | 2700 // guard. We will change it back in the call to [endGraph]. |
| 2682 HBasicBlock block = propagator.firstTypeGuard.block; | 2701 HBasicBlock block = propagator.firstTypeGuard.block; |
| 2683 savedFirstInstruction = block.first; | 2702 savedFirstInstruction = block.first; |
| 2684 block.first = propagator.firstTypeGuard; | 2703 block.first = propagator.firstTypeGuard; |
| 2685 return block; | 2704 return block; |
| 2686 } | 2705 } |
| 2687 } | 2706 } |
| 2688 | 2707 |
| 2689 // If argument is a [HCheck] and it does not have a name, we try to | 2708 // If argument is a [HCheck] and it does not have a name, we try to |
| 2690 // find the name of its checked input. Note that there must be a | 2709 // find the name of its checked input. Note that there must be a |
| 2691 // name, otherwise the instruction would not be in the live | 2710 // name, otherwise the instruction would not be in the live |
| 2692 // environment. | 2711 // environment. |
| 2693 HInstruction unwrap(HInstruction argument) { | 2712 HInstruction unwrap(HInstruction argument) { |
| 2694 while (argument is HCheck && !variableNames.hasName(argument)) { | 2713 while (argument is HCheck && !variableNames.hasName(argument)) { |
| 2695 argument = argument.checkedInput; | 2714 argument = argument.checkedInput; |
| 2696 } | 2715 } |
| 2697 assert(variableNames.hasName(argument)); | 2716 assert(variableNames.hasName(argument)); |
| 2698 return argument; | 2717 return argument; |
| 2699 } | 2718 } |
| 2700 | 2719 |
| 2701 void endGraph(HGraph graph) { | 2720 void endGraph(HGraph graph) { |
| 2702 // TODO(ngeoffray): We could avoid generating the state at the | 2721 if (propagator.hasComplexTypeGuards) { |
| 2703 // call site for non-complex bailout methods. | |
| 2704 newParameters.add('state'); | |
| 2705 | |
| 2706 // TODO(ngeoffray): We should declare the parameters in | |
| 2707 // beginGraph, to avoid potentially redeclaring them with 'var' | |
| 2708 // in the method body. | |
| 2709 if (!propagator.hasComplexTypeGuards) { | |
| 2710 propagator.firstTypeGuard.block.first = savedFirstInstruction; | |
| 2711 for (HInstruction input in propagator.firstTypeGuard.inputs) { | |
| 2712 input = unwrap(input); | |
| 2713 newParameters.add(', ${variableNames.getName(input)}'); | |
| 2714 } | |
| 2715 } else { | |
| 2716 for (int i = 0; i < maxBailoutParameters; i++) { | |
| 2717 newParameters.add(', env$i'); | |
| 2718 } | |
| 2719 indent--; // Close original case. | 2722 indent--; // Close original case. |
| 2720 indent--; | 2723 indent--; |
| 2721 addIndented('}\n'); // Close 'switch'. | 2724 addIndented('}\n'); // Close 'switch'. |
| 2722 setup.add(' }\n'); | 2725 setup.add(' }\n'); |
| 2726 } else { | |
| 2727 // Put back the original first instruction of the block. | |
| 2728 propagator.firstTypeGuard.block.first = savedFirstInstruction; | |
| 2723 } | 2729 } |
| 2724 } | 2730 } |
| 2725 | 2731 |
| 2726 bool visitAndOrInfo(HAndOrBlockInformation info) => false; | 2732 bool visitAndOrInfo(HAndOrBlockInformation info) => false; |
| 2727 | 2733 |
| 2728 bool visitIfInfo(HIfBlockInformation info) { | 2734 bool visitIfInfo(HIfBlockInformation info) { |
| 2729 if (info.thenGraph.start.hasGuards()) return false; | 2735 if (info.thenGraph.start.hasGuards()) return false; |
| 2730 if (info.elseGraph.start.hasGuards()) return false; | 2736 if (info.elseGraph.start.hasGuards()) return false; |
| 2731 return super.visitIfInfo(info); | 2737 return super.visitIfInfo(info); |
| 2732 } | 2738 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2754 input = unwrap(input); | 2760 input = unwrap(input); |
| 2755 String name = variableNames.getName(input); | 2761 String name = variableNames.getName(input); |
| 2756 setup.add(' '); | 2762 setup.add(' '); |
| 2757 if (!isVariableDeclared(name)) { | 2763 if (!isVariableDeclared(name)) { |
| 2758 declaredVariables.add(name); | 2764 declaredVariables.add(name); |
| 2759 setup.add('var '); | 2765 setup.add('var '); |
| 2760 } | 2766 } |
| 2761 setup.add('$name = env$i;\n'); | 2767 setup.add('$name = env$i;\n'); |
| 2762 i++; | 2768 i++; |
| 2763 } | 2769 } |
| 2764 if (i > maxBailoutParameters) maxBailoutParameters = i; | |
| 2765 setup.add(' break;\n'); | 2770 setup.add(' break;\n'); |
| 2766 } | 2771 } |
| 2767 | 2772 |
| 2768 void startBailoutCase(List<HTypeGuard> bailouts1, | 2773 void startBailoutCase(List<HTypeGuard> bailouts1, |
| 2769 List<HTypeGuard> bailouts2) { | 2774 List<HTypeGuard> bailouts2) { |
| 2770 indent--; | 2775 indent--; |
| 2771 handleBailoutCase(bailouts1); | 2776 handleBailoutCase(bailouts1); |
| 2772 handleBailoutCase(bailouts2); | 2777 handleBailoutCase(bailouts2); |
| 2773 indent++; | 2778 indent++; |
| 2774 } | 2779 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2894 startBailoutSwitch(); | 2899 startBailoutSwitch(); |
| 2895 } | 2900 } |
| 2896 } | 2901 } |
| 2897 | 2902 |
| 2898 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2903 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 2899 if (labeledBlockInfo.body.start.hasGuards()) { | 2904 if (labeledBlockInfo.body.start.hasGuards()) { |
| 2900 endBailoutSwitch(); | 2905 endBailoutSwitch(); |
| 2901 } | 2906 } |
| 2902 } | 2907 } |
| 2903 } | 2908 } |
| OLD | NEW |