| 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 2848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2859 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2859 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 2860 } | 2860 } |
| 2861 } | 2861 } |
| 2862 | 2862 |
| 2863 class SsaUnoptimizedCodeGenerator extends SsaCodeGenerator { | 2863 class SsaUnoptimizedCodeGenerator extends SsaCodeGenerator { |
| 2864 | 2864 |
| 2865 final CodeBuffer setup; | 2865 final CodeBuffer setup; |
| 2866 final CodeBuffer newParameters; | 2866 final CodeBuffer newParameters; |
| 2867 final List<String> labels; | 2867 final List<String> labels; |
| 2868 int labelId = 0; | 2868 int labelId = 0; |
| 2869 /** |
| 2870 * Keeps track if a bailout switch already used its [:default::] clause. New |
| 2871 * bailout-switches just push [:false:] on the stack and replace it when |
| 2872 * they used the [:default::] clause. |
| 2873 */ |
| 2874 final List<bool> defaultClauseUsedInBailoutStack; |
| 2869 | 2875 |
| 2870 SsaBailoutPropagator propagator; | 2876 SsaBailoutPropagator propagator; |
| 2871 HInstruction savedFirstInstruction; | 2877 HInstruction savedFirstInstruction; |
| 2872 | 2878 |
| 2873 SsaUnoptimizedCodeGenerator(backend, work, parameters, parameterNames) | 2879 SsaUnoptimizedCodeGenerator(backend, work, parameters, parameterNames) |
| 2874 : super(backend, work, parameters, parameterNames), | 2880 : super(backend, work, parameters, parameterNames), |
| 2875 setup = new CodeBuffer(), | 2881 setup = new CodeBuffer(), |
| 2876 newParameters = new CodeBuffer(), | 2882 newParameters = new CodeBuffer(), |
| 2877 labels = <String>[]; | 2883 labels = <String>[], |
| 2884 defaultClauseUsedInBailoutStack = <bool>[]; |
| 2878 | 2885 |
| 2879 String pushLabel() { | 2886 String pushLabel() { |
| 2880 String label = 'L${labelId++}'; | 2887 String label = 'L${labelId++}'; |
| 2881 labels.addLast(label); | 2888 labels.addLast(label); |
| 2882 return label; | 2889 return label; |
| 2883 } | 2890 } |
| 2884 | 2891 |
| 2885 String popLabel() { | 2892 String popLabel() { |
| 2886 return labels.removeLast(); | 2893 return labels.removeLast(); |
| 2887 } | 2894 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2993 } | 3000 } |
| 2994 setup.add('$name = env$i;\n'); | 3001 setup.add('$name = env$i;\n'); |
| 2995 i++; | 3002 i++; |
| 2996 } | 3003 } |
| 2997 setup.add(' break;\n'); | 3004 setup.add(' break;\n'); |
| 2998 } | 3005 } |
| 2999 | 3006 |
| 3000 void startBailoutCase(List<HTypeGuard> bailouts1, | 3007 void startBailoutCase(List<HTypeGuard> bailouts1, |
| 3001 List<HTypeGuard> bailouts2) { | 3008 List<HTypeGuard> bailouts2) { |
| 3002 indent--; | 3009 indent--; |
| 3003 handleBailoutCase(bailouts1); | 3010 if (!defaultClauseUsedInBailoutStack.last() && |
| 3004 handleBailoutCase(bailouts2); | 3011 bailouts1.length + bailouts2.length >= 2) { |
| 3012 addIndented('default:\n'); |
| 3013 int len = defaultClauseUsedInBailoutStack.length; |
| 3014 defaultClauseUsedInBailoutStack[len - 1] = true; |
| 3015 } else { |
| 3016 handleBailoutCase(bailouts1); |
| 3017 handleBailoutCase(bailouts2); |
| 3018 } |
| 3005 indent++; | 3019 indent++; |
| 3006 } | 3020 } |
| 3007 | 3021 |
| 3008 void handleBailoutCase(List<HTypeGuard> guards) { | 3022 void handleBailoutCase(List<HTypeGuard> guards) { |
| 3009 for (int i = 0, len = guards.length; i < len; i++) { | 3023 if (!defaultClauseUsedInBailoutStack.last() && guards.length >= 2) { |
| 3010 addIndented('case ${guards[i].state}:\n'); | 3024 addIndented('default:\n'); |
| 3025 int len = defaultClauseUsedInBailoutStack.length; |
| 3026 defaultClauseUsedInBailoutStack[len - 1] = true; |
| 3027 } else { |
| 3028 for (int i = 0, len = guards.length; i < len; i++) { |
| 3029 addIndented('case ${guards[i].state}:\n'); |
| 3030 } |
| 3011 } | 3031 } |
| 3012 } | 3032 } |
| 3013 | 3033 |
| 3014 void startBailoutSwitch() { | 3034 void startBailoutSwitch() { |
| 3035 defaultClauseUsedInBailoutStack.add(false); |
| 3015 addIndented('switch (state) {\n'); | 3036 addIndented('switch (state) {\n'); |
| 3016 indent++; | 3037 indent++; |
| 3017 addIndented('case 0:\n'); | 3038 addIndented('case 0:\n'); |
| 3018 indent++; | 3039 indent++; |
| 3019 } | 3040 } |
| 3020 | 3041 |
| 3021 void endBailoutSwitch() { | 3042 void endBailoutSwitch() { |
| 3022 indent--; // Close 'case'. | 3043 indent--; // Close 'case'. |
| 3023 indent--; | 3044 indent--; |
| 3024 addIndented('}\n'); // Close 'switch'. | 3045 addIndented('}\n'); // Close 'switch'. |
| 3046 defaultClauseUsedInBailoutStack.removeLast(); |
| 3025 } | 3047 } |
| 3026 | 3048 |
| 3027 void beginLoop(HBasicBlock block) { | 3049 void beginLoop(HBasicBlock block) { |
| 3028 String newLabel = pushLabel(); | 3050 String newLabel = pushLabel(); |
| 3029 if (block.hasGuards()) { | 3051 if (block.hasGuards()) { |
| 3030 startBailoutCase(block.guards, const <HTypeGuard>[]); | 3052 startBailoutCase(block.guards, const <HTypeGuard>[]); |
| 3031 } | 3053 } |
| 3032 | 3054 |
| 3033 addIndentation(); | 3055 addIndentation(); |
| 3034 HLoopInformation loopInformation = block.loopInformation; | 3056 HLoopInformation loopInformation = block.loopInformation; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3142 if (leftType.canBeNull() && rightType.canBeNull()) { | 3164 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 3143 if (left.isConstantNull() || right.isConstantNull() || | 3165 if (left.isConstantNull() || right.isConstantNull() || |
| 3144 (leftType.isPrimitive() && leftType == rightType)) { | 3166 (leftType.isPrimitive() && leftType == rightType)) { |
| 3145 return '=='; | 3167 return '=='; |
| 3146 } | 3168 } |
| 3147 return null; | 3169 return null; |
| 3148 } else { | 3170 } else { |
| 3149 return '==='; | 3171 return '==='; |
| 3150 } | 3172 } |
| 3151 } | 3173 } |
| OLD | NEW |